@forinda/kickjs-client 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/index.d.ts +39 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -28,4 +28,10 @@ const created = await api.post('/tasks', { body: { title: 'Ship it' } })
|
|
|
28
28
|
- **Injectable fetch**: pass `{ fetch: app.fetch }` from `@forinda/kickjs/web`
|
|
29
29
|
for network-free integration tests.
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
## Documentation
|
|
32
|
+
|
|
33
|
+
[kickjs.app/guide/typed-client](https://kickjs.app/guide/typed-client)
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* frontends installing this client must never need the server package.
|
|
7
7
|
* Keep the field list in sync with `RouteShape` in kickjs http/context.ts.
|
|
8
8
|
*/
|
|
9
|
-
interface RouteShapeLike {
|
|
9
|
+
export interface RouteShapeLike {
|
|
10
10
|
params: unknown;
|
|
11
11
|
body: unknown;
|
|
12
12
|
query: unknown;
|
|
@@ -14,16 +14,16 @@ interface RouteShapeLike {
|
|
|
14
14
|
}
|
|
15
15
|
type ApiMap = object;
|
|
16
16
|
/** HTTP verbs the route decorators produce. */
|
|
17
|
-
type ClientMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
17
|
+
export type ClientMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
18
18
|
/** Paths in the map registered under a given verb. */
|
|
19
|
-
type PathsFor<Api extends ApiMap, M extends ClientMethod> = { [K in keyof Api]: K extends `${M} ${infer P}` ? P : never }[keyof Api];
|
|
19
|
+
type PathsFor<Api extends ApiMap, M extends ClientMethod> = { [K in keyof Api]: K extends `${M} ${infer P}` ? P : never; }[keyof Api];
|
|
20
20
|
type ShapeOf<Api extends ApiMap, M extends ClientMethod, P extends string> = `${M} ${P}` extends keyof Api ? Api[`${M} ${P}`] extends RouteShapeLike ? Api[`${M} ${P}`] : never : never;
|
|
21
21
|
type SsePayloadOf<S> = S extends object ? '__sse' extends keyof S ? NonNullable<S['__sse']> : never : never;
|
|
22
22
|
/** GET paths whose response is an SSE stream (`return ctx.sse<T>()`). */
|
|
23
|
-
type StreamPathsFor<Api extends ApiMap> = { [K in keyof Api]: K extends `GET ${infer P}` ? Api[K] extends RouteShapeLike ? [SsePayloadOf<Api[K]['response']>] extends [never] ? never : P : never : never }[keyof Api];
|
|
23
|
+
type StreamPathsFor<Api extends ApiMap> = { [K in keyof Api]: K extends `GET ${infer P}` ? Api[K] extends RouteShapeLike ? [SsePayloadOf<Api[K]['response']>] extends [never] ? never : P : never : never; }[keyof Api];
|
|
24
24
|
type ArgsFor<S extends RouteShapeLike, M extends ClientMethod> = Record<string, never> extends RequestOptions<S, M> ? [options?: RequestOptions<S, M>] : [options: RequestOptions<S, M>];
|
|
25
25
|
/** One parsed server-sent event. */
|
|
26
|
-
interface SseEvent<T = unknown> {
|
|
26
|
+
export interface SseEvent<T = unknown> {
|
|
27
27
|
/** JSON-parsed `data:` payload (raw string when not valid JSON). */
|
|
28
28
|
data: T;
|
|
29
29
|
/** The `event:` name, when the server sent one. */
|
|
@@ -32,7 +32,7 @@ interface SseEvent<T = unknown> {
|
|
|
32
32
|
id?: string;
|
|
33
33
|
}
|
|
34
34
|
/** Typed async-iterable SSE connection — `for await`, then `close()`. */
|
|
35
|
-
interface SseStream<T = unknown> extends AsyncIterable<SseEvent<T>> {
|
|
35
|
+
export interface SseStream<T = unknown> extends AsyncIterable<SseEvent<T>> {
|
|
36
36
|
/** Abort the underlying request and end iteration. */
|
|
37
37
|
close(): void;
|
|
38
38
|
}
|
|
@@ -57,11 +57,13 @@ type QueryField<T> = unknown extends T ? {
|
|
|
57
57
|
} : {
|
|
58
58
|
query?: T;
|
|
59
59
|
};
|
|
60
|
-
type RequestOptions<S extends RouteShapeLike, M extends ClientMethod = ClientMethod> = {
|
|
61
|
-
/** Extra headers merged over the client-level ones. */
|
|
60
|
+
export type RequestOptions<S extends RouteShapeLike, M extends ClientMethod = ClientMethod> = {
|
|
61
|
+
/** Extra headers merged over the client-level ones. */
|
|
62
|
+
headers?: Record<string, string>;
|
|
63
|
+
/** AbortSignal for cancellation. */
|
|
62
64
|
signal?: AbortSignal;
|
|
63
65
|
} & ParamsField<S['params']> & BodyField<S['body'], M> & QueryField<S['query']>;
|
|
64
|
-
interface ClientOptions {
|
|
66
|
+
export interface ClientOptions {
|
|
65
67
|
/**
|
|
66
68
|
* Base URL INCLUDING the mount prefix + version the server adds at
|
|
67
69
|
* bootstrap (default `/api/v1`) — `KickRoutes.Api` keys are module-mount
|
|
@@ -77,13 +79,13 @@ interface ClientOptions {
|
|
|
77
79
|
fetch?: (request: Request) => Promise<Response>;
|
|
78
80
|
}
|
|
79
81
|
/** Non-2xx responses throw this — carries the parsed body (RFC 9457 problem details when the server used `ctx.problem`). */
|
|
80
|
-
declare class KickClientError extends Error {
|
|
82
|
+
export declare class KickClientError extends Error {
|
|
81
83
|
readonly status: number;
|
|
82
84
|
readonly body: unknown;
|
|
83
85
|
readonly response: Response;
|
|
84
86
|
constructor(status: number, body: unknown, response: Response);
|
|
85
87
|
}
|
|
86
|
-
interface KickClient<Api extends ApiMap> {
|
|
88
|
+
export interface KickClient<Api extends ApiMap> {
|
|
87
89
|
get<P extends PathsFor<Api, 'GET'> & string>(path: P, ...args: ArgsFor<ShapeOf<Api, 'GET', P>, 'GET'>): Promise<ShapeOf<Api, 'GET', P>['response']>;
|
|
88
90
|
/**
|
|
89
91
|
* Open a typed SSE connection to a route whose handler
|
|
@@ -104,9 +106,9 @@ interface KickClient<Api extends ApiMap> {
|
|
|
104
106
|
* Create a typed client over a `KickRoutes.Api`-shaped map.
|
|
105
107
|
* Generic-only consumption — no runtime dependency on the generated file.
|
|
106
108
|
*/
|
|
107
|
-
declare function createClient<Api extends ApiMap>(options: ClientOptions): KickClient<Api>;
|
|
109
|
+
export declare function createClient<Api extends ApiMap>(options: ClientOptions): KickClient<Api>;
|
|
108
110
|
/** Anything with a web-standard fetch — a `createWebApp()` result, a Worker, a mock. */
|
|
109
|
-
interface FetchLike {
|
|
111
|
+
export interface FetchLike {
|
|
110
112
|
fetch(request: Request): Promise<Response>;
|
|
111
113
|
}
|
|
112
114
|
/**
|
|
@@ -121,9 +123,31 @@ interface FetchLike {
|
|
|
121
123
|
* `baseUrl` defaults to `http://test/api/v1` (the bootstrap default prefix);
|
|
122
124
|
* override it when the server uses a custom `apiPrefix`/version.
|
|
123
125
|
*/
|
|
124
|
-
declare function createTestClient<Api extends ApiMap>(app: FetchLike, options?: Omit<ClientOptions, 'fetch' | 'baseUrl'> & {
|
|
126
|
+
export declare function createTestClient<Api extends ApiMap>(app: FetchLike, options?: Omit<ClientOptions, 'fetch' | 'baseUrl'> & {
|
|
125
127
|
baseUrl?: string;
|
|
126
128
|
}): KickClient<Api>;
|
|
129
|
+
/** Shape of the generated `kickRpc` manifest. */
|
|
130
|
+
export type RpcManifest = Record<string, Record<string, string>>;
|
|
131
|
+
type RpcMethod<Api extends ApiMap, K> = K extends `${infer V} ${infer P}` ? V extends ClientMethod ? [SsePayloadOf<ShapeOf<Api, V, P>['response']>] extends [never] ? (...args: ArgsFor<ShapeOf<Api, V, P>, V>) => Promise<ShapeOf<Api, V, P>['response']> : never : never : never;
|
|
132
|
+
/** The typed RPC surface derived from a manifest + the Api map. */
|
|
133
|
+
export type KickRpc<Api extends ApiMap, M extends RpcManifest> = { [C in keyof M]: { [F in keyof M[C]]: RpcMethod<Api, M[C][F]>; }; };
|
|
134
|
+
/**
|
|
135
|
+
* tRPC-style sugar over a typed client:
|
|
136
|
+
*
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { kickRpc } from './.kickjs/types/kick__routes'
|
|
139
|
+
*
|
|
140
|
+
* const rpc = createRpc(api, kickRpc)
|
|
141
|
+
* const task = await rpc.tasks.get({ params: { id: '42' } })
|
|
142
|
+
* const made = await rpc.tasks.create({ body: { title: 'Ship' } })
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* A plain nested object built eagerly from the manifest — every call
|
|
146
|
+
* delegates to the corresponding `api.<verb>()` with the manifest's path,
|
|
147
|
+
* so behavior (headers, errors, query serialization) is identical to the
|
|
148
|
+
* path-keyed surface. SSE routes are typed `never` here — open those with
|
|
149
|
+
* `api.stream(path)`.
|
|
150
|
+
*/
|
|
151
|
+
export declare function createRpc<Api extends ApiMap, const M extends RpcManifest>(api: KickClient<Api>, manifest: M): KickRpc<Api, M>;
|
|
127
152
|
//#endregion
|
|
128
|
-
export { ClientMethod, ClientOptions, FetchLike, KickClient, KickClientError, RequestOptions, RouteShapeLike, SseEvent, SseStream, createClient, createTestClient };
|
|
129
153
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;iBAuBiB;EACf;EACA;EACA;EACA;;KAOG;;YAGO;;KAGP,SAAS,YAAY,QAAQ,UAAU,mBACzC,WAAW,MAAM,aAAa,WAAW,MAAM,mBAC1C;KAKH,QACH,YAAY,QACZ,UAAU,cACV,uBACK,KAAK,kBAAkB,MAC1B,OAAO,KAAK,aAAa,iBACvB,OAAO,KAAK;KAUb,aAAa,KAAK,yCACG,IACpB,YAAY;;KAKb,eAAe,YAAY,aAC7B,WAAW,MAAM,uBAAuB,MACrC,IAAI,WAAW,kBACZ,aAAa,IAAI,2CAEhB,2BAGF;KAKH,QAAQ,UAAU,gBAAgB,UAAU,gBAC/C,8BAA8B,eAAe,GAAG,MAC3C,UA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A6DnB,aAAa,YAAY,QAAQ,SAAS,gBAAgB,WAAW;;iBA0GpE;EACf,MAAM,SAAS,UAAU,QAAQ;;;;;;;;;;;;;;wBAenB,iBAAiB,YAAY,QAC3C,KAAK,WACL,UAAS,KAAK;EAAwC;IACrD,WAAW;;YAiBF,cAAc,eAAe;KAEpC,UAAU,YAAY,QAAQ,KAAK,mBAAmB,WAAW,MAClE,UAAU,gBACP,aAAa,QAAQ,KAAK,GAAG,uCACxB,MAAM,QAAQ,QAAQ,KAAK,GAAG,IAAI,OAAO,QAAQ,QAAQ,KAAK,GAAG;;YAMjE,QAAQ,YAAY,QAAQ,UAAU,kBAC/C,WAAW,OAAO,WAAW,EAAE,KAAK,UAAU,KAAK,EAAE,GAAG;;;;;;;;;;;;;;;;;;wBAoB3C,UAAU,YAAY,cAAc,UAAU,aAC5D,KAAK,WAAW,MAChB,UAAU,IACT,QAAQ,KAAK"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs-client v0.
|
|
2
|
+
* @forinda/kickjs-client v0.3.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -10,5 +10,5 @@
|
|
|
10
10
|
*/
|
|
11
11
|
var KickClientError=class extends Error{status;body;response;constructor(status,body,response){super(typeof body==`object`&&body&&`detail`in body?String(body.detail):typeof body==`object`&&body&&`error`in body?String(body.error):`Request failed with status ${status}`),this.status=status,this.body=body,this.response=response,this.name=`KickClientError`}};function fillPath(path,params){return path.replace(/:([A-Za-z0-9_]+)/g,(_,name)=>{let value=params?.[name];if(value===void 0)throw Error(`@forinda/kickjs-client: missing path param ':${name}' for '${path}'`);return encodeURIComponent(String(value))})}function parseSseBlock(block){let event,id,dataLines=[];for(let line of block.split(`
|
|
12
12
|
`))line.startsWith(`:`)||(line.startsWith(`data:`)?dataLines.push(line.slice(5).trimStart()):line.startsWith(`event:`)?event=line.slice(6).trim():line.startsWith(`id:`)&&(id=line.slice(3).trim()));if(dataLines.length===0)return null;let raw=dataLines.join(`
|
|
13
|
-
`),data=raw;try{data=JSON.parse(raw)}catch{}return{data,...event?{event}:{},...id?{id}:{}}}function buildQuery(query){if(!query)return``;let qs=new URLSearchParams;for(let[key,value]of Object.entries(query))if(value!=null)if(Array.isArray(value))for(let v of value)qs.append(key,String(v));else qs.append(key,String(value))
|
|
13
|
+
`),data=raw;try{data=JSON.parse(raw)}catch{}return{data,...event?{event}:{},...id?{id}:{}}}function buildQuery(query){if(!query)return``;let qs=new URLSearchParams;for(let[key,value]of Object.entries(query))if(value!=null){if(Array.isArray(value))for(let v of value)qs.append(key,String(v));else qs.append(key,String(value))}let s=qs.toString();return s?`?${s}`:``}function createClient(options){let baseUrl=options.baseUrl.replace(/\/$/,``),doFetch=options.fetch??(req=>fetch(req));async function buildRequest(method,path,opts){let clientHeaders=typeof options.headers==`function`?await options.headers():options.headers??{},headers=new Headers({...clientHeaders,...opts.headers}),hasBody=method!==`GET`&&opts.body!==void 0;hasBody&&!headers.has(`content-type`)&&headers.set(`content-type`,`application/json`);let url=`${baseUrl}${fillPath(path,opts.params)}${buildQuery(opts.query)}`;return new Request(url,{method,headers,body:hasBody?JSON.stringify(opts.body):void 0,signal:opts.signal})}async function run(method,path,opts={}){let request=await buildRequest(method,path,opts),response=await doFetch(request),contentType=response.headers.get(`content-type`)??``,body=response.status===204?void 0:contentType.includes(`json`)?await response.json().catch(()=>void 0):await response.text();if(!response.ok)throw new KickClientError(response.status,body,response);return body}async function openStream(path,opts={}){let controller=new AbortController;opts.signal?.addEventListener(`abort`,()=>controller.abort(),{once:!0});let request=await buildRequest(`GET`,path,{...opts,signal:controller.signal,headers:{accept:`text/event-stream`,...opts.headers}}),response=await doFetch(request);if(!response.ok||!response.body){let body=(response.headers.get(`content-type`)??``).includes(`json`)?await response.json().catch(()=>void 0):await response.text().catch(()=>void 0);throw new KickClientError(response.status,body,response)}let reader=response.body.getReader(),decoder=new TextDecoder;async function*events(){let buffer=``;try{for(;;){let{done,value}=await reader.read();if(done)break;buffer+=decoder.decode(value,{stream:!0});let blocks=buffer.split(/\n\n/);buffer=blocks.pop()??``;for(let block of blocks){let ev=parseSseBlock(block);ev&&(yield ev)}}}finally{controller.abort(),reader.releaseLock()}}return{[Symbol.asyncIterator]:events,close:()=>controller.abort()}}return{get:(path,opts)=>run(`GET`,path,opts),stream:(path,opts)=>openStream(path,opts??{}),post:(path,opts)=>run(`POST`,path,opts),put:(path,opts)=>run(`PUT`,path,opts),delete:(path,opts)=>run(`DELETE`,path,opts),patch:(path,opts)=>run(`PATCH`,path,opts)}}function createTestClient(app,options={}){return createClient({...options,baseUrl:options.baseUrl??`http://test/api/v1`,fetch:request=>app.fetch(request)})}function createRpc(api,manifest){let rpc={};for(let[controller,methods]of Object.entries(manifest)){let ns={};for(let[fn,key]of Object.entries(methods)){let space=key.indexOf(` `),verb=key.slice(0,space).toLowerCase(),path=key.slice(space+1);ns[fn]=opts=>api[verb](path,opts)}rpc[controller]=ns}return rpc}export{KickClientError,createClient,createRpc,createTestClient};
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// @forinda/kickjs-client — typed fetch client for KickJS APIs.\n//\n// Consumes the flat `KickRoutes.Api` map that `kick typegen` emits\n// (response-inference-design.md R3): keys are `'METHOD /path'`, values are\n// the route shapes (`params` / `body` / `query` / `response`). The client is\n// a ~150-line fetch wrapper — every type below exists so the CALL SITE\n// infers exactly:\n//\n// ```ts\n// const api = createClient<KickRoutes.Api>({ baseUrl: 'https://x/api/v1' })\n// const task = await api.post('/tasks/:id', { params: { id }, body })\n// // ^ the handler's actual response type\n// ```\n//\n// Runtime-neutral: fetch/URL/Headers only — browsers, node ≥ 20, Bun, Deno,\n// and edge workers (pairs with `@forinda/kickjs/web` on the server side).\n\n/**\n * The per-route shape `kick typegen` emits into `KickRoutes.Api`.\n * Deliberately re-declares (NOT imports) @forinda/kickjs's `RouteShape`:\n * frontends installing this client must never need the server package.\n * Keep the field list in sync with `RouteShape` in kickjs http/context.ts.\n */\nexport interface RouteShapeLike {\n params: unknown\n body: unknown\n query: unknown\n response: unknown\n}\n\n// `object`, not `Record<string, RouteShapeLike>`: the generated\n// `KickRoutes.Api` is an INTERFACE, which has no string index signature and\n// would fail a Record constraint. Key/value conformance is guaranteed by the\n// generator; PathsFor/ShapeOf only rely on `keyof Api`.\ntype ApiMap = object\n\n/** HTTP verbs the route decorators produce. */\nexport type ClientMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'\n\n/** Paths in the map registered under a given verb. */\ntype PathsFor<Api extends ApiMap, M extends ClientMethod> = {\n [K in keyof Api]: K extends `${M} ${infer P}` ? P : never\n}[keyof Api]\n\n// Fallback is `never` ON PURPOSE: P is already constrained to PathsFor, so a\n// failed key lookup means the map and the client's key math drifted — that\n// must fail loudly at the call site, not silently degrade to unknown.\ntype ShapeOf<\n Api extends ApiMap,\n M extends ClientMethod,\n P extends string,\n> = `${M} ${P}` extends keyof Api\n ? Api[`${M} ${P}`] extends RouteShapeLike\n ? Api[`${M} ${P}`]\n : never\n : never\n\n// ── SSE typing ────────────────────────────────────────────────────────\n// Server handlers that `return ctx.sse<T>()` put an `SseHandler<T>` into the\n// map's response slot; its phantom `__sse` property carries T structurally,\n// so the client detects SSE routes without importing server types. The\n// optional-property check must be non-vacuous — `'__sse' extends keyof S`,\n// NOT `S extends { __sse?: … }` (every object vacuously extends the latter).\ntype SsePayloadOf<S> = S extends object\n ? '__sse' extends keyof S\n ? NonNullable<S['__sse']>\n : never\n : never\n\n/** GET paths whose response is an SSE stream (`return ctx.sse<T>()`). */\ntype StreamPathsFor<Api extends ApiMap> = {\n [K in keyof Api]: K extends `GET ${infer P}`\n ? Api[K] extends RouteShapeLike\n ? [SsePayloadOf<Api[K]['response']>] extends [never]\n ? never\n : P\n : never\n : never\n}[keyof Api]\n\n// Options argument is OPTIONAL only when the shape requires nothing\n// (no concrete params, no required body) — otherwise omitting it must be\n// a compile error, not a runtime missing-param throw.\ntype ArgsFor<S extends RouteShapeLike, M extends ClientMethod> =\n Record<string, never> extends RequestOptions<S, M>\n ? [options?: RequestOptions<S, M>]\n : [options: RequestOptions<S, M>]\n\n/** One parsed server-sent event. */\nexport interface SseEvent<T = unknown> {\n /** JSON-parsed `data:` payload (raw string when not valid JSON). */\n data: T\n /** The `event:` name, when the server sent one. */\n event?: string\n /** The `id:` field, when the server sent one. */\n id?: string\n}\n\n/** Typed async-iterable SSE connection — `for await`, then `close()`. */\nexport interface SseStream<T = unknown> extends AsyncIterable<SseEvent<T>> {\n /** Abort the underlying request and end iteration. */\n close(): void\n}\n\n// Paramless routes emit `params: {}` and unschema'd bodies emit\n// `body: unknown` — both become OPTIONAL fields; a concrete shape is\n// required so forgetting `params` on `/users/:id` is a type error.\ntype ParamsField<T> = unknown extends T\n ? { params?: Record<string, string | number> }\n : Record<string, never> extends T\n ? { params?: T }\n : { params: T }\n\n// GET requests must not carry a body — `new Request(url, { method: 'GET',\n// body })` throws at runtime, so the type forbids it up front.\ntype BodyField<T, M extends ClientMethod> = M extends 'GET'\n ? { body?: never }\n : unknown extends T\n ? { body?: unknown }\n : { body: T }\n\n/** Loose fallback for routes without a statically-known query shape. */\ntype LooseQuery = Record<string, string | number | boolean | Array<string | number>>\n\n// Routes with a typegen-known query shape (Zod schema or the\n// @ApiQueryParams-derived filter/sort/q/page/limit object) constrain\n// `query` — sort fields autocomplete as '-createdAt' | 'createdAt' | …\ntype QueryField<T> = unknown extends T ? { query?: LooseQuery } : { query?: T }\n\nexport type RequestOptions<S extends RouteShapeLike, M extends ClientMethod = ClientMethod> = {\n /** Extra headers merged over the client-level ones. */\n headers?: Record<string, string>\n /** AbortSignal for cancellation. */\n signal?: AbortSignal\n} & ParamsField<S['params']> &\n BodyField<S['body'], M> &\n QueryField<S['query']>\n\nexport interface ClientOptions {\n /**\n * Base URL INCLUDING the mount prefix + version the server adds at\n * bootstrap (default `/api/v1`) — `KickRoutes.Api` keys are module-mount\n * relative: `'GET /users/:id'` + baseUrl `https://x/api/v1`.\n */\n baseUrl: string\n /** Static headers, or a factory invoked per request (auth tokens). */\n headers?:\n | Record<string, string>\n | (() => Record<string, string> | Promise<Record<string, string>>)\n /**\n * Custom fetch — inject a platform fetch, a mock, or a KickJS web app's\n * own handler for network-free tests: `{ fetch: app.fetch }`.\n */\n fetch?: (request: Request) => Promise<Response>\n}\n\n/** Non-2xx responses throw this — carries the parsed body (RFC 9457 problem details when the server used `ctx.problem`). */\nexport class KickClientError extends Error {\n constructor(\n readonly status: number,\n readonly body: unknown,\n readonly response: Response,\n ) {\n super(\n typeof body === 'object' && body !== null && 'detail' in body\n ? String((body as { detail: unknown }).detail)\n : typeof body === 'object' && body !== null && 'error' in body\n ? String((body as { error: unknown }).error)\n : `Request failed with status ${status}`,\n )\n this.name = 'KickClientError'\n }\n}\n\nexport interface KickClient<Api extends ApiMap> {\n get<P extends PathsFor<Api, 'GET'> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'GET', P>, 'GET'>\n ): Promise<ShapeOf<Api, 'GET', P>['response']>\n /**\n * Open a typed SSE connection to a route whose handler\n * `return ctx.sse<T>()` — events arrive as `SseEvent<T>`:\n *\n * ```ts\n * const stream = await api.stream('/events')\n * for await (const ev of stream) console.log(ev.data) // ev.data: T\n * ```\n */\n stream<P extends StreamPathsFor<Api> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'GET', P>, 'GET'>\n ): Promise<SseStream<SsePayloadOf<ShapeOf<Api, 'GET', P>['response']>>>\n post<P extends PathsFor<Api, 'POST'> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'POST', P>, 'POST'>\n ): Promise<ShapeOf<Api, 'POST', P>['response']>\n put<P extends PathsFor<Api, 'PUT'> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'PUT', P>, 'PUT'>\n ): Promise<ShapeOf<Api, 'PUT', P>['response']>\n delete<P extends PathsFor<Api, 'DELETE'> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'DELETE', P>, 'DELETE'>\n ): Promise<ShapeOf<Api, 'DELETE', P>['response']>\n patch<P extends PathsFor<Api, 'PATCH'> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'PATCH', P>, 'PATCH'>\n ): Promise<ShapeOf<Api, 'PATCH', P>['response']>\n}\n\ninterface AnyRequestOptions {\n headers?: Record<string, string>\n signal?: AbortSignal\n query?: Record<string, unknown>\n params?: Record<string, string | number>\n body?: unknown\n}\n\n/** Substitute `:param` segments; throw on any left unfilled. */\nfunction fillPath(path: string, params?: Record<string, string | number>): string {\n const filled = path.replace(/:([A-Za-z0-9_]+)/g, (_, name: string) => {\n const value = params?.[name]\n if (value === undefined) {\n throw new Error(`@forinda/kickjs-client: missing path param ':${name}' for '${path}'`)\n }\n return encodeURIComponent(String(value))\n })\n return filled\n}\n\n/** Parse one SSE block (lines until a blank line) into an event. */\nfunction parseSseBlock(block: string): SseEvent | null {\n let event: string | undefined\n let id: string | undefined\n const dataLines: string[] = []\n for (const line of block.split('\\n')) {\n if (line.startsWith(':')) continue // comment / keep-alive\n if (line.startsWith('data:')) dataLines.push(line.slice(5).trimStart())\n else if (line.startsWith('event:')) event = line.slice(6).trim()\n else if (line.startsWith('id:')) id = line.slice(3).trim()\n }\n if (dataLines.length === 0) return null\n const raw = dataLines.join('\\n')\n let data: unknown = raw\n try {\n data = JSON.parse(raw)\n } catch {\n // Non-JSON payloads pass through as the raw string.\n }\n return { data, ...(event ? { event } : {}), ...(id ? { id } : {}) }\n}\n\nfunction buildQuery(query?: Record<string, unknown>): string {\n if (!query) return ''\n const qs = new URLSearchParams()\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue\n if (Array.isArray(value)) for (const v of value) qs.append(key, String(v))\n else qs.append(key, String(value))\n }\n const s = qs.toString()\n return s ? `?${s}` : ''\n}\n\n/**\n * Create a typed client over a `KickRoutes.Api`-shaped map.\n * Generic-only consumption — no runtime dependency on the generated file.\n */\nexport function createClient<Api extends ApiMap>(options: ClientOptions): KickClient<Api> {\n const baseUrl = options.baseUrl.replace(/\\/$/, '')\n const doFetch = options.fetch ?? ((req: Request) => fetch(req))\n\n async function buildRequest(\n method: ClientMethod,\n path: string,\n opts: AnyRequestOptions,\n ): Promise<Request> {\n const clientHeaders =\n typeof options.headers === 'function' ? await options.headers() : (options.headers ?? {})\n const headers = new Headers({ ...clientHeaders, ...opts.headers })\n // Defensive: fetch's Request constructor throws on GET-with-body; the\n // types already forbid it, but casts can smuggle one through.\n const hasBody = method !== 'GET' && opts.body !== undefined\n if (hasBody && !headers.has('content-type')) {\n headers.set('content-type', 'application/json')\n }\n\n const url = `${baseUrl}${fillPath(path, opts.params)}${buildQuery(opts.query)}`\n return new Request(url, {\n method,\n headers,\n body: hasBody ? JSON.stringify(opts.body) : undefined,\n signal: opts.signal,\n })\n }\n\n async function run(method: ClientMethod, path: string, opts: AnyRequestOptions = {}) {\n const request = await buildRequest(method, path, opts)\n\n const response = await doFetch(request)\n const contentType = response.headers.get('content-type') ?? ''\n const body =\n response.status === 204\n ? undefined\n : contentType.includes('json')\n ? await response.json().catch(() => undefined)\n : await response.text()\n\n if (!response.ok) throw new KickClientError(response.status, body, response)\n return body\n }\n\n async function openStream(path: string, opts: AnyRequestOptions = {}): Promise<SseStream> {\n // Own controller so close() works even without a caller-provided signal;\n // chain the caller's signal into it when present.\n const controller = new AbortController()\n opts.signal?.addEventListener('abort', () => controller.abort(), { once: true })\n const request = await buildRequest('GET', path, {\n ...opts,\n signal: controller.signal,\n headers: { accept: 'text/event-stream', ...opts.headers },\n })\n\n const response = await doFetch(request)\n if (!response.ok || !response.body) {\n const contentType = response.headers.get('content-type') ?? ''\n const body = contentType.includes('json')\n ? await response.json().catch(() => undefined)\n : await response.text().catch(() => undefined)\n throw new KickClientError(response.status, body, response)\n }\n\n const reader = response.body.getReader()\n const decoder = new TextDecoder()\n\n async function* events(): AsyncGenerator<SseEvent> {\n let buffer = ''\n try {\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n buffer += decoder.decode(value, { stream: true })\n // Events are separated by a blank line; keep the trailing partial.\n const blocks = buffer.split(/\\n\\n/)\n buffer = blocks.pop() ?? ''\n for (const block of blocks) {\n const ev = parseSseBlock(block)\n if (ev) yield ev\n }\n }\n } finally {\n controller.abort()\n reader.releaseLock()\n }\n }\n\n return {\n [Symbol.asyncIterator]: events,\n close: () => controller.abort(),\n }\n }\n\n return {\n get: (path: string, opts?: unknown) => run('GET', path, opts as AnyRequestOptions),\n stream: (path: string, opts?: unknown) =>\n openStream(path, (opts ?? {}) as AnyRequestOptions) as never,\n post: (path: string, opts?: unknown) => run('POST', path, opts as AnyRequestOptions),\n put: (path: string, opts?: unknown) => run('PUT', path, opts as AnyRequestOptions),\n delete: (path: string, opts?: unknown) => run('DELETE', path, opts as AnyRequestOptions),\n patch: (path: string, opts?: unknown) => run('PATCH', path, opts as AnyRequestOptions),\n } as unknown as KickClient<Api>\n}\n\n/** Anything with a web-standard fetch — a `createWebApp()` result, a Worker, a mock. */\nexport interface FetchLike {\n fetch(request: Request): Promise<Response>\n}\n\n/**\n * Typed client over an in-process app — network-free full-stack tests:\n *\n * ```ts\n * const app = createWebApp({ h3, modules })\n * const api = createTestClient<KickRoutes.Api>(app)\n * expect(await api.get('/tasks/:id', { params: { id: '1' } })).toEqual(...)\n * ```\n *\n * `baseUrl` defaults to `http://test/api/v1` (the bootstrap default prefix);\n * override it when the server uses a custom `apiPrefix`/version.\n */\nexport function createTestClient<Api extends ApiMap>(\n app: FetchLike,\n options: Omit<ClientOptions, 'fetch' | 'baseUrl'> & { baseUrl?: string } = {},\n): KickClient<Api> {\n return createClient<Api>({\n ...options,\n // AFTER the spread — an explicit `baseUrl: undefined` key in options\n // must not clobber the default (spread copies undefined-valued keys).\n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,EACjB,OAAO,YAAY,CACrB,CACF,CAEA,MAAO,EACJ,OAAO,eAAgB,OACxB,UAAa,WAAW,MAAM,CAChC,CACF,CAEA,MAAO,CACL,KAAM,KAAc,OAAmB,IAAI,MAAO,KAAM,IAAyB,EACjF,QAAS,KAAc,OACrB,WAAW,KAAO,MAAQ,CAAC,CAAuB,EACpD,MAAO,KAAc,OAAmB,IAAI,OAAQ,KAAM,IAAyB,EACnF,KAAM,KAAc,OAAmB,IAAI,MAAO,KAAM,IAAyB,EACjF,QAAS,KAAc,OAAmB,IAAI,SAAU,KAAM,IAAyB,EACvF,OAAQ,KAAc,OAAmB,IAAI,QAAS,KAAM,IAAyB,CACvF,CACF,CAmBA,SAAgB,iBACd,IACA,QAA2E,CAAC,EAC3D,CACjB,OAAO,aAAkB,CACvB,GAAG,QAGH,QAAS,QAAQ,SAAW,qBAC5B,MAAQ,SAAY,IAAI,MAAM,OAAO,CACvC,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// @forinda/kickjs-client — typed fetch client for KickJS APIs.\n//\n// Consumes the flat `KickRoutes.Api` map that `kick typegen` emits:\n// keys are `'METHOD /path'`, values are\n// the route shapes (`params` / `body` / `query` / `response`). The client is\n// a ~150-line fetch wrapper — every type below exists so the CALL SITE\n// infers exactly:\n//\n// ```ts\n// const api = createClient<KickRoutes.Api>({ baseUrl: 'https://x/api/v1' })\n// const task = await api.post('/tasks/:id', { params: { id }, body })\n// // ^ the handler's actual response type\n// ```\n//\n// Runtime-neutral: fetch/URL/Headers only — browsers, node ≥ 20, Bun, Deno,\n// and edge workers (pairs with `@forinda/kickjs/web` on the server side).\n\n/**\n * The per-route shape `kick typegen` emits into `KickRoutes.Api`.\n * Deliberately re-declares (NOT imports) @forinda/kickjs's `RouteShape`:\n * frontends installing this client must never need the server package.\n * Keep the field list in sync with `RouteShape` in kickjs http/context.ts.\n */\nexport interface RouteShapeLike {\n params: unknown\n body: unknown\n query: unknown\n response: unknown\n}\n\n// `object`, not `Record<string, RouteShapeLike>`: the generated\n// `KickRoutes.Api` is an INTERFACE, which has no string index signature and\n// would fail a Record constraint. Key/value conformance is guaranteed by the\n// generator; PathsFor/ShapeOf only rely on `keyof Api`.\ntype ApiMap = object\n\n/** HTTP verbs the route decorators produce. */\nexport type ClientMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'\n\n/** Paths in the map registered under a given verb. */\ntype PathsFor<Api extends ApiMap, M extends ClientMethod> = {\n [K in keyof Api]: K extends `${M} ${infer P}` ? P : never\n}[keyof Api]\n\n// Fallback is `never` ON PURPOSE: P is already constrained to PathsFor, so a\n// failed key lookup means the map and the client's key math drifted — that\n// must fail loudly at the call site, not silently degrade to unknown.\ntype ShapeOf<\n Api extends ApiMap,\n M extends ClientMethod,\n P extends string,\n> = `${M} ${P}` extends keyof Api\n ? Api[`${M} ${P}`] extends RouteShapeLike\n ? Api[`${M} ${P}`]\n : never\n : never\n\n// ── SSE typing ────────────────────────────────────────────────────────\n// Server handlers that `return ctx.sse<T>()` put an `SseHandler<T>` into the\n// map's response slot; its phantom `__sse` property carries T structurally,\n// so the client detects SSE routes without importing server types. The\n// optional-property check must be non-vacuous — `'__sse' extends keyof S`,\n// NOT `S extends { __sse?: … }` (every object vacuously extends the latter).\ntype SsePayloadOf<S> = S extends object\n ? '__sse' extends keyof S\n ? NonNullable<S['__sse']>\n : never\n : never\n\n/** GET paths whose response is an SSE stream (`return ctx.sse<T>()`). */\ntype StreamPathsFor<Api extends ApiMap> = {\n [K in keyof Api]: K extends `GET ${infer P}`\n ? Api[K] extends RouteShapeLike\n ? [SsePayloadOf<Api[K]['response']>] extends [never]\n ? never\n : P\n : never\n : never\n}[keyof Api]\n\n// Options argument is OPTIONAL only when the shape requires nothing\n// (no concrete params, no required body) — otherwise omitting it must be\n// a compile error, not a runtime missing-param throw.\ntype ArgsFor<S extends RouteShapeLike, M extends ClientMethod> =\n Record<string, never> extends RequestOptions<S, M>\n ? [options?: RequestOptions<S, M>]\n : [options: RequestOptions<S, M>]\n\n/** One parsed server-sent event. */\nexport interface SseEvent<T = unknown> {\n /** JSON-parsed `data:` payload (raw string when not valid JSON). */\n data: T\n /** The `event:` name, when the server sent one. */\n event?: string\n /** The `id:` field, when the server sent one. */\n id?: string\n}\n\n/** Typed async-iterable SSE connection — `for await`, then `close()`. */\nexport interface SseStream<T = unknown> extends AsyncIterable<SseEvent<T>> {\n /** Abort the underlying request and end iteration. */\n close(): void\n}\n\n// Paramless routes emit `params: {}` and unschema'd bodies emit\n// `body: unknown` — both become OPTIONAL fields; a concrete shape is\n// required so forgetting `params` on `/users/:id` is a type error.\ntype ParamsField<T> = unknown extends T\n ? { params?: Record<string, string | number> }\n : Record<string, never> extends T\n ? { params?: T }\n : { params: T }\n\n// GET requests must not carry a body — `new Request(url, { method: 'GET',\n// body })` throws at runtime, so the type forbids it up front.\ntype BodyField<T, M extends ClientMethod> = M extends 'GET'\n ? { body?: never }\n : unknown extends T\n ? { body?: unknown }\n : { body: T }\n\n/** Loose fallback for routes without a statically-known query shape. */\ntype LooseQuery = Record<string, string | number | boolean | Array<string | number>>\n\n// Routes with a typegen-known query shape (Zod schema or the\n// @ApiQueryParams-derived filter/sort/q/page/limit object) constrain\n// `query` — sort fields autocomplete as '-createdAt' | 'createdAt' | …\ntype QueryField<T> = unknown extends T ? { query?: LooseQuery } : { query?: T }\n\nexport type RequestOptions<S extends RouteShapeLike, M extends ClientMethod = ClientMethod> = {\n /** Extra headers merged over the client-level ones. */\n headers?: Record<string, string>\n /** AbortSignal for cancellation. */\n signal?: AbortSignal\n} & ParamsField<S['params']> &\n BodyField<S['body'], M> &\n QueryField<S['query']>\n\nexport interface ClientOptions {\n /**\n * Base URL INCLUDING the mount prefix + version the server adds at\n * bootstrap (default `/api/v1`) — `KickRoutes.Api` keys are module-mount\n * relative: `'GET /users/:id'` + baseUrl `https://x/api/v1`.\n */\n baseUrl: string\n /** Static headers, or a factory invoked per request (auth tokens). */\n headers?:\n | Record<string, string>\n | (() => Record<string, string> | Promise<Record<string, string>>)\n /**\n * Custom fetch — inject a platform fetch, a mock, or a KickJS web app's\n * own handler for network-free tests: `{ fetch: app.fetch }`.\n */\n fetch?: (request: Request) => Promise<Response>\n}\n\n/** Non-2xx responses throw this — carries the parsed body (RFC 9457 problem details when the server used `ctx.problem`). */\nexport class KickClientError extends Error {\n constructor(\n readonly status: number,\n readonly body: unknown,\n readonly response: Response,\n ) {\n super(\n typeof body === 'object' && body !== null && 'detail' in body\n ? String((body as { detail: unknown }).detail)\n : typeof body === 'object' && body !== null && 'error' in body\n ? String((body as { error: unknown }).error)\n : `Request failed with status ${status}`,\n )\n this.name = 'KickClientError'\n }\n}\n\nexport interface KickClient<Api extends ApiMap> {\n get<P extends PathsFor<Api, 'GET'> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'GET', P>, 'GET'>\n ): Promise<ShapeOf<Api, 'GET', P>['response']>\n /**\n * Open a typed SSE connection to a route whose handler\n * `return ctx.sse<T>()` — events arrive as `SseEvent<T>`:\n *\n * ```ts\n * const stream = await api.stream('/events')\n * for await (const ev of stream) console.log(ev.data) // ev.data: T\n * ```\n */\n stream<P extends StreamPathsFor<Api> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'GET', P>, 'GET'>\n ): Promise<SseStream<SsePayloadOf<ShapeOf<Api, 'GET', P>['response']>>>\n post<P extends PathsFor<Api, 'POST'> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'POST', P>, 'POST'>\n ): Promise<ShapeOf<Api, 'POST', P>['response']>\n put<P extends PathsFor<Api, 'PUT'> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'PUT', P>, 'PUT'>\n ): Promise<ShapeOf<Api, 'PUT', P>['response']>\n delete<P extends PathsFor<Api, 'DELETE'> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'DELETE', P>, 'DELETE'>\n ): Promise<ShapeOf<Api, 'DELETE', P>['response']>\n patch<P extends PathsFor<Api, 'PATCH'> & string>(\n path: P,\n ...args: ArgsFor<ShapeOf<Api, 'PATCH', P>, 'PATCH'>\n ): Promise<ShapeOf<Api, 'PATCH', P>['response']>\n}\n\ninterface AnyRequestOptions {\n headers?: Record<string, string>\n signal?: AbortSignal\n query?: Record<string, unknown>\n params?: Record<string, string | number>\n body?: unknown\n}\n\n/** Substitute `:param` segments; throw on any left unfilled. */\nfunction fillPath(path: string, params?: Record<string, string | number>): string {\n const filled = path.replace(/:([A-Za-z0-9_]+)/g, (_, name: string) => {\n const value = params?.[name]\n if (value === undefined) {\n throw new Error(`@forinda/kickjs-client: missing path param ':${name}' for '${path}'`)\n }\n return encodeURIComponent(String(value))\n })\n return filled\n}\n\n/** Parse one SSE block (lines until a blank line) into an event. */\nfunction parseSseBlock(block: string): SseEvent | null {\n let event: string | undefined\n let id: string | undefined\n const dataLines: string[] = []\n for (const line of block.split('\\n')) {\n if (line.startsWith(':')) continue // comment / keep-alive\n if (line.startsWith('data:')) dataLines.push(line.slice(5).trimStart())\n else if (line.startsWith('event:')) event = line.slice(6).trim()\n else if (line.startsWith('id:')) id = line.slice(3).trim()\n }\n if (dataLines.length === 0) return null\n const raw = dataLines.join('\\n')\n let data: unknown = raw\n try {\n data = JSON.parse(raw)\n } catch {\n // Non-JSON payloads pass through as the raw string.\n }\n return { data, ...(event ? { event } : {}), ...(id ? { id } : {}) }\n}\n\nfunction buildQuery(query?: Record<string, unknown>): string {\n if (!query) return ''\n const qs = new URLSearchParams()\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue\n if (Array.isArray(value)) for (const v of value) qs.append(key, String(v))\n else qs.append(key, String(value))\n }\n const s = qs.toString()\n return s ? `?${s}` : ''\n}\n\n/**\n * Create a typed client over a `KickRoutes.Api`-shaped map.\n * Generic-only consumption — no runtime dependency on the generated file.\n */\nexport function createClient<Api extends ApiMap>(options: ClientOptions): KickClient<Api> {\n const baseUrl = options.baseUrl.replace(/\\/$/, '')\n const doFetch = options.fetch ?? ((req: Request) => fetch(req))\n\n async function buildRequest(\n method: ClientMethod,\n path: string,\n opts: AnyRequestOptions,\n ): Promise<Request> {\n const clientHeaders =\n typeof options.headers === 'function' ? await options.headers() : (options.headers ?? {})\n const headers = new Headers({ ...clientHeaders, ...opts.headers })\n // Defensive: fetch's Request constructor throws on GET-with-body; the\n // types already forbid it, but casts can smuggle one through.\n const hasBody = method !== 'GET' && opts.body !== undefined\n if (hasBody && !headers.has('content-type')) {\n headers.set('content-type', 'application/json')\n }\n\n const url = `${baseUrl}${fillPath(path, opts.params)}${buildQuery(opts.query)}`\n return new Request(url, {\n method,\n headers,\n body: hasBody ? JSON.stringify(opts.body) : undefined,\n signal: opts.signal,\n })\n }\n\n async function run(method: ClientMethod, path: string, opts: AnyRequestOptions = {}) {\n const request = await buildRequest(method, path, opts)\n\n const response = await doFetch(request)\n const contentType = response.headers.get('content-type') ?? ''\n const body =\n response.status === 204\n ? undefined\n : contentType.includes('json')\n ? await response.json().catch(() => undefined)\n : await response.text()\n\n if (!response.ok) throw new KickClientError(response.status, body, response)\n return body\n }\n\n async function openStream(path: string, opts: AnyRequestOptions = {}): Promise<SseStream> {\n // Own controller so close() works even without a caller-provided signal;\n // chain the caller's signal into it when present.\n const controller = new AbortController()\n opts.signal?.addEventListener('abort', () => controller.abort(), { once: true })\n const request = await buildRequest('GET', path, {\n ...opts,\n signal: controller.signal,\n headers: { accept: 'text/event-stream', ...opts.headers },\n })\n\n const response = await doFetch(request)\n if (!response.ok || !response.body) {\n const contentType = response.headers.get('content-type') ?? ''\n const body = contentType.includes('json')\n ? await response.json().catch(() => undefined)\n : await response.text().catch(() => undefined)\n throw new KickClientError(response.status, body, response)\n }\n\n const reader = response.body.getReader()\n const decoder = new TextDecoder()\n\n async function* events(): AsyncGenerator<SseEvent> {\n let buffer = ''\n try {\n for (;;) {\n const { done, value } = await reader.read()\n if (done) break\n buffer += decoder.decode(value, { stream: true })\n // Events are separated by a blank line; keep the trailing partial.\n const blocks = buffer.split(/\\n\\n/)\n buffer = blocks.pop() ?? ''\n for (const block of blocks) {\n const ev = parseSseBlock(block)\n if (ev) yield ev\n }\n }\n } finally {\n controller.abort()\n reader.releaseLock()\n }\n }\n\n return {\n [Symbol.asyncIterator]: events,\n close: () => controller.abort(),\n }\n }\n\n return {\n get: (path: string, opts?: unknown) => run('GET', path, opts as AnyRequestOptions),\n stream: (path: string, opts?: unknown) =>\n openStream(path, (opts ?? {}) as AnyRequestOptions) as never,\n post: (path: string, opts?: unknown) => run('POST', path, opts as AnyRequestOptions),\n put: (path: string, opts?: unknown) => run('PUT', path, opts as AnyRequestOptions),\n delete: (path: string, opts?: unknown) => run('DELETE', path, opts as AnyRequestOptions),\n patch: (path: string, opts?: unknown) => run('PATCH', path, opts as AnyRequestOptions),\n } as unknown as KickClient<Api>\n}\n\n/** Anything with a web-standard fetch — a `createWebApp()` result, a Worker, a mock. */\nexport interface FetchLike {\n fetch(request: Request): Promise<Response>\n}\n\n/**\n * Typed client over an in-process app — network-free full-stack tests:\n *\n * ```ts\n * const app = createWebApp({ h3, modules })\n * const api = createTestClient<KickRoutes.Api>(app)\n * expect(await api.get('/tasks/:id', { params: { id: '1' } })).toEqual(...)\n * ```\n *\n * `baseUrl` defaults to `http://test/api/v1` (the bootstrap default prefix);\n * override it when the server uses a custom `apiPrefix`/version.\n */\nexport function createTestClient<Api extends ApiMap>(\n app: FetchLike,\n options: Omit<ClientOptions, 'fetch' | 'baseUrl'> & { baseUrl?: string } = {},\n): KickClient<Api> {\n return createClient<Api>({\n ...options,\n // AFTER the spread — an explicit `baseUrl: undefined` key in options\n // must not clobber the default (spread copies undefined-valued keys).\n baseUrl: options.baseUrl ?? 'http://test/api/v1',\n fetch: (request) => app.fetch(request),\n })\n}\n\n// ── RPC sugar ─────────────────────────────────────────────────────────\n// tRPC-style call shape over the SAME path-keyed map — no new inference,\n// no Proxy magic. `kick typegen` emits the runtime manifest (`kickRpc` in\n// kick__routes.ts): controller.method → 'VERB /mounted/path'; the types\n// below re-derive everything from KickApi via ShapeOf/ArgsFor.\n\n/** Shape of the generated `kickRpc` manifest. */\nexport type RpcManifest = Record<string, Record<string, string>>\n\ntype RpcMethod<Api extends ApiMap, K> = K extends `${infer V} ${infer P}`\n ? V extends ClientMethod\n ? [SsePayloadOf<ShapeOf<Api, V, P>['response']>] extends [never]\n ? (...args: ArgsFor<ShapeOf<Api, V, P>, V>) => Promise<ShapeOf<Api, V, P>['response']>\n : never // SSE routes stay explicit — use api.stream(path)\n : never\n : never\n\n/** The typed RPC surface derived from a manifest + the Api map. */\nexport type KickRpc<Api extends ApiMap, M extends RpcManifest> = {\n [C in keyof M]: { [F in keyof M[C]]: RpcMethod<Api, M[C][F]> }\n}\n\n/**\n * tRPC-style sugar over a typed client:\n *\n * ```ts\n * import { kickRpc } from './.kickjs/types/kick__routes'\n *\n * const rpc = createRpc(api, kickRpc)\n * const task = await rpc.tasks.get({ params: { id: '42' } })\n * const made = await rpc.tasks.create({ body: { title: 'Ship' } })\n * ```\n *\n * A plain nested object built eagerly from the manifest — every call\n * delegates to the corresponding `api.<verb>()` with the manifest's path,\n * so behavior (headers, errors, query serialization) is identical to the\n * path-keyed surface. SSE routes are typed `never` here — open those with\n * `api.stream(path)`.\n */\nexport function createRpc<Api extends ApiMap, const M extends RpcManifest>(\n api: KickClient<Api>,\n manifest: M,\n): KickRpc<Api, M> {\n const rpc: Record<string, Record<string, unknown>> = {}\n for (const [controller, methods] of Object.entries(manifest)) {\n const ns: Record<string, unknown> = {}\n for (const [fn, key] of Object.entries(methods)) {\n const space = key.indexOf(' ')\n const verb = key.slice(0, space).toLowerCase() as Lowercase<ClientMethod>\n const path = key.slice(space + 1)\n ns[fn] = (opts?: unknown) =>\n (api[verb] as (p: string, o?: unknown) => Promise<unknown>)(path, opts)\n }\n rpc[controller] = ns\n }\n return rpc as KickRpc<Api, M>\n}\n"],"mappings":";;;;;;;;;;AA6JA,IAAa,gBAAb,cAA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MAAO,CACL,KAAM,KAAc,OAAmB,IAAI,MAAO,KAAM,IAAyB,EACjF,QAAS,KAAc,OACrB,WAAW,KAAO,MAAQ,CAAC,CAAuB,EACpD,MAAO,KAAc,OAAmB,IAAI,OAAQ,KAAM,IAAyB,EACnF,KAAM,KAAc,OAAmB,IAAI,MAAO,KAAM,IAAyB,EACjF,QAAS,KAAc,OAAmB,IAAI,SAAU,KAAM,IAAyB,EACvF,OAAQ,KAAc,OAAmB,IAAI,QAAS,KAAM,IAAyB,CACvF,CACF,CAmBA,SAAgB,iBACd,IACA,QAA2E,CAAC,EAC3D,CACjB,OAAO,aAAkB,CACvB,GAAG,QAGH,QAAS,QAAQ,SAAW,qBAC5B,MAAQ,SAAY,IAAI,MAAM,OAAO,CACvC,CAAC,CACH,CAyCA,SAAgB,UACd,IACA,SACiB,CACjB,IAAM,IAA+C,CAAC,EACtD,IAAK,GAAM,CAAC,WAAY,WAAY,OAAO,QAAQ,QAAQ,EAAG,CAC5D,IAAM,GAA8B,CAAC,EACrC,IAAK,GAAM,CAAC,GAAI,OAAQ,OAAO,QAAQ,OAAO,EAAG,CAC/C,IAAM,MAAQ,IAAI,QAAQ,GAAG,EACvB,KAAO,IAAI,MAAM,EAAG,KAAK,CAAC,CAAC,YAAY,EACvC,KAAO,IAAI,MAAM,MAAQ,CAAC,EAChC,GAAG,IAAO,MACP,IAAI,KAAK,CAAkD,KAAM,IAAI,CAC1E,CACA,IAAI,YAAc,EACpB,CACA,OAAO,GACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forinda/kickjs-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Typed fetch client for KickJS APIs — end-to-end response types from the kick typegen KickRoutes augmentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kickjs",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"h3-v2": "npm:h3@2.0.1-rc.22",
|
|
28
28
|
"reflect-metadata": "^0.2.2",
|
|
29
|
-
"typescript": "^
|
|
30
|
-
"vitest": "^
|
|
31
|
-
"@forinda/kickjs": "
|
|
29
|
+
"typescript": "^7.0.2",
|
|
30
|
+
"vitest": "^5.0.1",
|
|
31
|
+
"@forinda/kickjs": "9.0.1"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"build": "tsdown",
|
|
52
52
|
"dev": "tsdown --watch",
|
|
53
53
|
"test": "vitest run --passWithNoTests",
|
|
54
|
-
"typecheck": "
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
55
|
"clean": "rm -rf dist .wireit"
|
|
56
56
|
}
|
|
57
57
|
}
|