@workflowai/api
Advanced tools
Comparing version 1.3.2 to 1.3.3
@@ -1,5 +0,8 @@ | ||
import { MaybeOptionalInit } from 'openapi-fetch'; | ||
import type { GetValueWithDefault, PathsWithMethod } from 'openapi-typescript-helpers'; | ||
import { MaybeOptionalInit, PathMethods } from 'openapi-fetch'; | ||
import type { GetValueWithDefault, HasRequiredKeys, PathsWithMethod } from 'openapi-typescript-helpers'; | ||
import type { paths } from './generated/openapi'; | ||
import type { Middleware } from './middlewares'; | ||
type Init<P extends PathMethods, M extends keyof P, I = MaybeOptionalInit<P, M>> = HasRequiredKeys<I> extends never ? I & { | ||
[key: string]: unknown; | ||
} : I; | ||
type CreateHttpClientConfig = { | ||
@@ -29,17 +32,7 @@ url: string; | ||
}; | ||
GET: <P extends PathsWithMethod<paths, "get">>(path: P) => (init: MaybeOptionalInit<paths[P], 'get'>) => Promise<import("openapi-fetch").FetchResponse<paths[P]["get"], MaybeOptionalInit<paths[P], "get"> & { | ||
parseAs: "json"; | ||
}, "application/json">>; | ||
POST: <P_1 extends PathsWithMethod<paths, "post">>(path: P_1) => (init: MaybeOptionalInit<paths[P_1], "post">) => Promise<import("openapi-fetch").FetchResponse<paths[P_1]["post"], MaybeOptionalInit<paths[P_1], "post"> & { | ||
parseAs: "json"; | ||
}, "application/json">>; | ||
PUT: <P_2 extends "/tasks/{task_id}/schemas/{task_schema_id}/evaluators/{evaluator_id}">(path: P_2) => (init: MaybeOptionalInit<paths[P_2], "put">) => Promise<import("openapi-fetch").FetchResponse<paths[P_2]["put"], MaybeOptionalInit<paths[P_2], "put"> & { | ||
parseAs: "json"; | ||
}, "application/json">>; | ||
PATCH: <P_3 extends PathsWithMethod<paths, "patch">>(path: P_3) => (init: MaybeOptionalInit<paths[P_3], "patch">) => Promise<import("openapi-fetch").FetchResponse<paths[P_3]["patch"], MaybeOptionalInit<paths[P_3], "patch"> & { | ||
parseAs: "json"; | ||
}, "application/json">>; | ||
DELETE: <P_4 extends PathsWithMethod<paths, "delete">>(path: P_4) => (init: MaybeOptionalInit<paths[P_4], "delete">) => Promise<import("openapi-fetch").FetchResponse<paths[P_4]["delete"], MaybeOptionalInit<paths[P_4], "delete"> & { | ||
parseAs: "json"; | ||
}, "application/json">>; | ||
GET: <P extends PathsWithMethod<paths, "get">>(path: P) => (init: Init<paths[P], 'get'>) => Promise<import("openapi-fetch").FetchResponse<paths[P]["get"], Init<paths[P], "get", MaybeOptionalInit<paths[P], "get">>, "application/json">>; | ||
POST: <P_1 extends PathsWithMethod<paths, "post">>(path: P_1) => (init: Init<paths[P_1], "post", MaybeOptionalInit<paths[P_1], "post">>) => Promise<import("openapi-fetch").FetchResponse<paths[P_1]["post"], Init<paths[P_1], "post", MaybeOptionalInit<paths[P_1], "post">>, "application/json">>; | ||
PUT: <P_2 extends PathsWithMethod<paths, "put">>(path: P_2) => <I = Init<paths[P_2], "put", MaybeOptionalInit<paths[P_2], "put">>>(init: I) => Promise<import("openapi-fetch").FetchResponse<paths[P_2]["put"], MaybeOptionalInit<paths[P_2], "put">, "application/json">>; | ||
PATCH: <P_3 extends PathsWithMethod<paths, "patch">>(path: P_3) => (init: Init<paths[P_3], "patch", MaybeOptionalInit<paths[P_3], "patch">>) => Promise<import("openapi-fetch").FetchResponse<paths[P_3]["patch"], Init<paths[P_3], "patch", MaybeOptionalInit<paths[P_3], "patch">>, "application/json">>; | ||
DELETE: <P_4 extends PathsWithMethod<paths, "delete">>(path: P_4) => (init: Init<paths[P_4], "delete", MaybeOptionalInit<paths[P_4], "delete">>) => Promise<import("openapi-fetch").FetchResponse<paths[P_4]["delete"], Init<paths[P_4], "delete", MaybeOptionalInit<paths[P_4], "delete">>, "application/json">>; | ||
}; | ||
@@ -65,3 +58,3 @@ /** | ||
}; | ||
POST: <P extends PathsWithMethod<paths, "post">>(path: P) => (init: MaybeOptionalInit<paths[P], 'post'>) => Promise<{ | ||
POST: <P extends PathsWithMethod<paths, "post">>(path: P) => (init: Init<paths[P], 'post'>) => Promise<{ | ||
response: Response; | ||
@@ -68,0 +61,0 @@ stream: AsyncIterableIterator<{ |
@@ -10,2 +10,10 @@ "use strict"; | ||
const wrapAsyncIterator_1 = require("./utils/wrapAsyncIterator"); | ||
function extender(extension) { | ||
return function extend(o) { | ||
return { ...o, ...extension }; | ||
}; | ||
} | ||
function forceParseAs(parseAs) { | ||
return extender({ parseAs }); | ||
} | ||
/** | ||
@@ -36,7 +44,10 @@ * Get a low-level openapi client for a specific return content-type | ||
const jsonClient = getClient(config); | ||
const GET = (path) => (init) => jsonClient.GET(path, { ...init, parseAs: 'json' }); | ||
const PUT = (path) => (init) => jsonClient.PUT(path, { ...init, parseAs: 'json' }); | ||
const POST = (path) => (init) => jsonClient.POST(path, { ...init, parseAs: 'json' }); | ||
const PATCH = (path) => (init) => jsonClient.PATCH(path, { ...init, parseAs: 'json' }); | ||
const DELETE = (path) => (init) => jsonClient.DELETE(path, { ...init, parseAs: 'json' }); | ||
const cleanInit = forceParseAs('json'); | ||
const GET = (path) => (init) => jsonClient.GET(path, cleanInit(init)); | ||
const PUT = (path) => (init) => jsonClient.PUT(path, | ||
// @ts-expect-error For some obscure TS reason, PUT gives an error 🤷 | ||
cleanInit(init)); | ||
const POST = (path) => (init) => jsonClient.POST(path, cleanInit(init)); | ||
const PATCH = (path) => (init) => jsonClient.PATCH(path, cleanInit(init)); | ||
const DELETE = (path) => (init) => jsonClient.DELETE(path, cleanInit(init)); | ||
return { | ||
@@ -60,8 +71,5 @@ client: jsonClient, | ||
const streamClient = getClient(config); | ||
const cleanInit = forceParseAs('stream'); | ||
const POST = (path) => async (init) => { | ||
const { response } = await streamClient.POST(path, { | ||
...init, | ||
// Make sure to interpret responses as streams | ||
parseAs: 'stream', | ||
}); | ||
const { response } = await streamClient.POST(path, cleanInit(init)); | ||
return { | ||
@@ -68,0 +76,0 @@ response, |
import { events as asServerSentEvents } from 'fetch-event-stream'; | ||
import createClient from 'openapi-fetch'; | ||
import { wrapAsyncIterator } from './utils/wrapAsyncIterator'; | ||
function extender(extension) { | ||
return function extend(o) { | ||
return { ...o, ...extension }; | ||
}; | ||
} | ||
function forceParseAs(parseAs) { | ||
return extender({ parseAs }); | ||
} | ||
/** | ||
@@ -29,7 +37,10 @@ * Get a low-level openapi client for a specific return content-type | ||
const jsonClient = getClient(config); | ||
const GET = (path) => (init) => jsonClient.GET(path, { ...init, parseAs: 'json' }); | ||
const PUT = (path) => (init) => jsonClient.PUT(path, { ...init, parseAs: 'json' }); | ||
const POST = (path) => (init) => jsonClient.POST(path, { ...init, parseAs: 'json' }); | ||
const PATCH = (path) => (init) => jsonClient.PATCH(path, { ...init, parseAs: 'json' }); | ||
const DELETE = (path) => (init) => jsonClient.DELETE(path, { ...init, parseAs: 'json' }); | ||
const cleanInit = forceParseAs('json'); | ||
const GET = (path) => (init) => jsonClient.GET(path, cleanInit(init)); | ||
const PUT = (path) => (init) => jsonClient.PUT(path, | ||
// @ts-expect-error For some obscure TS reason, PUT gives an error 🤷 | ||
cleanInit(init)); | ||
const POST = (path) => (init) => jsonClient.POST(path, cleanInit(init)); | ||
const PATCH = (path) => (init) => jsonClient.PATCH(path, cleanInit(init)); | ||
const DELETE = (path) => (init) => jsonClient.DELETE(path, cleanInit(init)); | ||
return { | ||
@@ -52,8 +63,5 @@ client: jsonClient, | ||
const streamClient = getClient(config); | ||
const cleanInit = forceParseAs('stream'); | ||
const POST = (path) => async (init) => { | ||
const { response } = await streamClient.POST(path, { | ||
...init, | ||
// Make sure to interpret responses as streams | ||
parseAs: 'stream', | ||
}); | ||
const { response } = await streamClient.POST(path, cleanInit(init)); | ||
return { | ||
@@ -60,0 +68,0 @@ response, |
@@ -1,5 +0,8 @@ | ||
import { MaybeOptionalInit } from 'openapi-fetch'; | ||
import type { GetValueWithDefault, PathsWithMethod } from 'openapi-typescript-helpers'; | ||
import { MaybeOptionalInit, PathMethods } from 'openapi-fetch'; | ||
import type { GetValueWithDefault, HasRequiredKeys, PathsWithMethod } from 'openapi-typescript-helpers'; | ||
import type { paths } from './generated/openapi'; | ||
import type { Middleware } from './middlewares'; | ||
type Init<P extends PathMethods, M extends keyof P, I = MaybeOptionalInit<P, M>> = HasRequiredKeys<I> extends never ? I & { | ||
[key: string]: unknown; | ||
} : I; | ||
type CreateHttpClientConfig = { | ||
@@ -29,17 +32,7 @@ url: string; | ||
}; | ||
GET: <P extends PathsWithMethod<paths, "get">>(path: P) => (init: MaybeOptionalInit<paths[P], 'get'>) => Promise<import("openapi-fetch").FetchResponse<paths[P]["get"], MaybeOptionalInit<paths[P], "get"> & { | ||
parseAs: "json"; | ||
}, "application/json">>; | ||
POST: <P_1 extends PathsWithMethod<paths, "post">>(path: P_1) => (init: MaybeOptionalInit<paths[P_1], "post">) => Promise<import("openapi-fetch").FetchResponse<paths[P_1]["post"], MaybeOptionalInit<paths[P_1], "post"> & { | ||
parseAs: "json"; | ||
}, "application/json">>; | ||
PUT: <P_2 extends "/tasks/{task_id}/schemas/{task_schema_id}/evaluators/{evaluator_id}">(path: P_2) => (init: MaybeOptionalInit<paths[P_2], "put">) => Promise<import("openapi-fetch").FetchResponse<paths[P_2]["put"], MaybeOptionalInit<paths[P_2], "put"> & { | ||
parseAs: "json"; | ||
}, "application/json">>; | ||
PATCH: <P_3 extends PathsWithMethod<paths, "patch">>(path: P_3) => (init: MaybeOptionalInit<paths[P_3], "patch">) => Promise<import("openapi-fetch").FetchResponse<paths[P_3]["patch"], MaybeOptionalInit<paths[P_3], "patch"> & { | ||
parseAs: "json"; | ||
}, "application/json">>; | ||
DELETE: <P_4 extends PathsWithMethod<paths, "delete">>(path: P_4) => (init: MaybeOptionalInit<paths[P_4], "delete">) => Promise<import("openapi-fetch").FetchResponse<paths[P_4]["delete"], MaybeOptionalInit<paths[P_4], "delete"> & { | ||
parseAs: "json"; | ||
}, "application/json">>; | ||
GET: <P extends PathsWithMethod<paths, "get">>(path: P) => (init: Init<paths[P], 'get'>) => Promise<import("openapi-fetch").FetchResponse<paths[P]["get"], Init<paths[P], "get", MaybeOptionalInit<paths[P], "get">>, "application/json">>; | ||
POST: <P_1 extends PathsWithMethod<paths, "post">>(path: P_1) => (init: Init<paths[P_1], "post", MaybeOptionalInit<paths[P_1], "post">>) => Promise<import("openapi-fetch").FetchResponse<paths[P_1]["post"], Init<paths[P_1], "post", MaybeOptionalInit<paths[P_1], "post">>, "application/json">>; | ||
PUT: <P_2 extends PathsWithMethod<paths, "put">>(path: P_2) => <I = Init<paths[P_2], "put", MaybeOptionalInit<paths[P_2], "put">>>(init: I) => Promise<import("openapi-fetch").FetchResponse<paths[P_2]["put"], MaybeOptionalInit<paths[P_2], "put">, "application/json">>; | ||
PATCH: <P_3 extends PathsWithMethod<paths, "patch">>(path: P_3) => (init: Init<paths[P_3], "patch", MaybeOptionalInit<paths[P_3], "patch">>) => Promise<import("openapi-fetch").FetchResponse<paths[P_3]["patch"], Init<paths[P_3], "patch", MaybeOptionalInit<paths[P_3], "patch">>, "application/json">>; | ||
DELETE: <P_4 extends PathsWithMethod<paths, "delete">>(path: P_4) => (init: Init<paths[P_4], "delete", MaybeOptionalInit<paths[P_4], "delete">>) => Promise<import("openapi-fetch").FetchResponse<paths[P_4]["delete"], Init<paths[P_4], "delete", MaybeOptionalInit<paths[P_4], "delete">>, "application/json">>; | ||
}; | ||
@@ -65,3 +58,3 @@ /** | ||
}; | ||
POST: <P extends PathsWithMethod<paths, "post">>(path: P) => (init: MaybeOptionalInit<paths[P], 'post'>) => Promise<{ | ||
POST: <P extends PathsWithMethod<paths, "post">>(path: P) => (init: Init<paths[P], 'post'>) => Promise<{ | ||
response: Response; | ||
@@ -68,0 +61,0 @@ stream: AsyncIterableIterator<{ |
{ | ||
"name": "@workflowai/api", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "WorkflowAI typed API client", | ||
@@ -51,9 +51,9 @@ "author": "WorkflowAI", | ||
"devDependencies": { | ||
"openapi-typescript": "^6.7.5", | ||
"zod": "^3.23.6" | ||
"openapi-typescript": "^6.7.6", | ||
"zod": "^3.23.8" | ||
}, | ||
"dependencies": { | ||
"fetch-event-stream": "^0.1.5", | ||
"openapi-fetch": "^0.9.5" | ||
"openapi-fetch": "^0.9.7" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
2067902
37419
Updatedopenapi-fetch@^0.9.7