Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/uppercase-api-methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@typesensekit/cli": patch
"@typesensekit/mcp": patch
---

Allow `api.call` to accept uppercase HTTP methods.
27 changes: 27 additions & 0 deletions packages/core/src/operations/api.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
6 changes: 5 additions & 1 deletion packages/core/src/operations/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -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(),
Expand Down
Loading