From 7cd060405c69e69adc7577726453cc95352a0416 Mon Sep 17 00:00:00 2001 From: akshitkrnagpal Date: Fri, 22 May 2026 14:19:32 +0400 Subject: [PATCH] Accept uppercase api call methods --- .changeset/uppercase-api-methods.md | 6 ++++++ packages/core/src/operations/api.test.ts | 27 ++++++++++++++++++++++++ packages/core/src/operations/api.ts | 6 +++++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .changeset/uppercase-api-methods.md create mode 100644 packages/core/src/operations/api.test.ts diff --git a/.changeset/uppercase-api-methods.md b/.changeset/uppercase-api-methods.md new file mode 100644 index 0000000..6be3251 --- /dev/null +++ b/.changeset/uppercase-api-methods.md @@ -0,0 +1,6 @@ +--- +"@typesensekit/cli": patch +"@typesensekit/mcp": patch +--- + +Allow `api.call` to accept uppercase HTTP methods. diff --git a/packages/core/src/operations/api.test.ts b/packages/core/src/operations/api.test.ts new file mode 100644 index 0000000..bda0580 --- /dev/null +++ b/packages/core/src/operations/api.test.ts @@ -0,0 +1,27 @@ +import { describe, expect, it, vi } from "vitest"; +import type { TypesenseClient } from "../client.js"; +import { apiOperations } from "./api.js"; + +function getOperation(name: string) { + const operation = apiOperations.find((candidate) => candidate.name === name); + if (!operation) throw new Error(`${name} not found`); + return operation; +} + +describe("api operations", () => { + it("accepts uppercase HTTP methods and normalizes them before dispatch", async () => { + const callOperation = getOperation("api.call"); + const get = vi.fn().mockResolvedValue({ ok: true }); + const client = { apiCall: { get } } as unknown as TypesenseClient; + + await callOperation.execute( + client, + callOperation.input.parse({ + method: "GET", + path: "/synonym_sets", + }), + ); + + expect(get).toHaveBeenCalledWith("/synonym_sets", undefined); + }); +}); diff --git a/packages/core/src/operations/api.ts b/packages/core/src/operations/api.ts index a440e57..2f09fb9 100644 --- a/packages/core/src/operations/api.ts +++ b/packages/core/src/operations/api.ts @@ -3,6 +3,10 @@ import { api } from "./http.js"; import type { Operation } from "./types.js"; const methodSchema = z.enum(["get", "post", "put", "patch", "delete"]); +const normalizedMethodSchema = z.preprocess( + (value) => (typeof value === "string" ? value.toLowerCase() : value), + methodSchema, +); export const apiOperations = [ { @@ -11,7 +15,7 @@ export const apiOperations = [ "Call any Typesense API endpoint not yet covered by a first-class operation", category: "api", input: z.object({ - method: methodSchema, + method: normalizedMethodSchema, path: z.string().startsWith("/"), params: z.record(z.unknown()).optional(), body: z.unknown().optional(),