@nxgt/openapi-httpyz 0.2.0 → 0.3.0
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 +26 -10
- package/dist/client/create-openapi-client.d.ts.map +1 -1
- package/dist/client/types.d.ts +10 -3
- package/dist/client/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -289,7 +289,7 @@ Calls the operation at a method and a path, as the spec writes it:
|
|
|
289
289
|
`api.get('/employees/{id}', { param: { id } })`. The client types only the
|
|
290
290
|
methods in [`MethodsOf<Routes>`](#methodsof), each taking only its
|
|
291
291
|
[`PathsOf`](#pathsof). The arguments, reply and errors are those of
|
|
292
|
-
[`op`](#op); a path with no operation for the method rejects with
|
|
292
|
+
[`op`](#op); a path with no operation for the method rejects with a `ClientError`.
|
|
293
293
|
|
|
294
294
|
#### stream
|
|
295
295
|
|
|
@@ -332,6 +332,17 @@ readonly page.signal: AbortSignal;
|
|
|
332
332
|
Aborts on the next `cancel()`: for work of your own that ends with the
|
|
333
333
|
group's calls. It is a new signal after each `cancel()`.
|
|
334
334
|
|
|
335
|
+
#### use
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
api.use(...middlewares: Middleware[]): this;
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Adds middleware to the core client, in place, as its
|
|
342
|
+
[`http.use()`](https://www.npmjs.com/package/@nxgt/httpyz#middleware) does, and
|
|
343
|
+
returns this client: `api.use(timing)`. Every client bound to the same core
|
|
344
|
+
client goes through it. On a group, it is the group's alone.
|
|
345
|
+
|
|
335
346
|
#### operations
|
|
336
347
|
|
|
337
348
|
```ts
|
|
@@ -347,21 +358,25 @@ built over it that reads the spec as the client does, such as
|
|
|
347
358
|
#### OpenApiClient
|
|
348
359
|
|
|
349
360
|
```ts
|
|
350
|
-
type OpenApiClient<Ops extends OperationsShape<Ops>, Routes = RoutesOf<Ops>, Decoded extends boolean =
|
|
361
|
+
type OpenApiClient<Ops extends OperationsShape<Ops>, Routes = RoutesOf<Ops>, Decoded extends boolean = true> = {
|
|
351
362
|
op: …; // see op
|
|
352
363
|
stream: …; // see stream
|
|
353
364
|
group(): OpenApiGroup<Ops, Routes, Decoded>;
|
|
365
|
+
use(...middlewares: Middleware[]): this;
|
|
354
366
|
readonly operations: OperationTable<Ops>;
|
|
355
367
|
} & PathMethods<Ops, Routes, Decoded>;
|
|
356
368
|
```
|
|
357
369
|
|
|
358
370
|
What `createOpenApiClient()` returns: the members are under
|
|
359
|
-
[The client](#the-client).
|
|
371
|
+
[The client](#the-client). In the declarations, the members but the path
|
|
372
|
+
methods are an interface, `ClientMembers<Ops, Routes, Decoded>`, intersected
|
|
373
|
+
with [`PathMethods`](#pathmethods): its `use()` returns `this`, which a type
|
|
374
|
+
alias cannot declare.
|
|
360
375
|
|
|
361
376
|
#### OpenApiGroup
|
|
362
377
|
|
|
363
378
|
```ts
|
|
364
|
-
type OpenApiGroup<Ops, Routes = RoutesOf<Ops>, Decoded extends boolean =
|
|
379
|
+
type OpenApiGroup<Ops, Routes = RoutesOf<Ops>, Decoded extends boolean = true> =
|
|
365
380
|
OpenApiClient<Ops, Routes, Decoded> & {
|
|
366
381
|
cancel(reason?: unknown): void;
|
|
367
382
|
readonly signal: AbortSignal;
|
|
@@ -374,7 +389,7 @@ What [`group()`](#group) returns: the client, with
|
|
|
374
389
|
#### PathMethods
|
|
375
390
|
|
|
376
391
|
```ts
|
|
377
|
-
type PathMethods<Ops, Routes = RoutesOf<Ops>, Decoded extends boolean =
|
|
392
|
+
type PathMethods<Ops, Routes = RoutesOf<Ops>, Decoded extends boolean = true> = {
|
|
378
393
|
readonly [M in MethodsOf<Routes>]: <P extends PathsOf<Routes, M>>(
|
|
379
394
|
path: P,
|
|
380
395
|
...args: Args<Ops, IdOf<Ops, Routes, M, P>>
|
|
@@ -583,11 +598,12 @@ A media type of a `RuntimeOperation`'s `body` or `responses`.
|
|
|
583
598
|
the spec does not declare are dropped, unless the spec was generated to
|
|
584
599
|
keep them, and a reply the spec refuses throws a `ValidationError`, even
|
|
585
600
|
with `validate: false`. `decode: false` takes the reply at its word.
|
|
586
|
-
- **An error reply is checked too.** A
|
|
587
|
-
|
|
588
|
-
`@nxgt/openapi-hono
|
|
589
|
-
|
|
590
|
-
|
|
601
|
+
- **An error reply is checked too.** A reply whose body the spec does not
|
|
602
|
+
describe throws a `ValidationError` instead of returning. The 400 that
|
|
603
|
+
`@nxgt/openapi-hono` answers a refused request with is declared by
|
|
604
|
+
`@nxgt/openapi-codegen`, as `ValidationErrorBody`, unless it ran with
|
|
605
|
+
`validationErrors: false`. Any other body the server sends, declare it, or
|
|
606
|
+
pass `decode: false` and `validate: { response: false }`.
|
|
591
607
|
- **With `decode: false`, a reply is typed as JSON carries it**: with
|
|
592
608
|
`dates: 'date'`, a date-time is a string.
|
|
593
609
|
- **A request is typed as JSON carries it, whatever `decode` says.** With
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-openapi-client.d.ts","sourceRoot":"","sources":["../../src/client/create-openapi-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAGN,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"create-openapi-client.d.ts","sourceRoot":"","sources":["../../src/client/create-openapi-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAGN,KAAK,UAAU,EAIf,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EACX,WAAW,EACX,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,EACd,QAAQ,EAIR,MAAM,SAAS,CAAC;AA6DjB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAClC,GAAG,SAAS,eAAe,CAAC,GAAG,CAAC,EAChC,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,EAEtB,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,cAAc,CAAC,GAAG,CAAC,EAC/B,OAAO,EAAE,cAAc,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAA;CAAE,GAClD,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AACrC,wBAAgB,mBAAmB,CAClC,GAAG,SAAS,eAAe,CAAC,GAAG,CAAC,EAChC,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,EACtB,OAAO,SAAS,OAAO,GAAG,IAAI,EAE9B,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,cAAc,CAAC,GAAG,CAAC,EAC/B,GAAG,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAC9B,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
package/dist/client/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* `OperationsByRoute`), so a call costs TypeScript the same whether the spec
|
|
5
5
|
* has five operations or five hundred.
|
|
6
6
|
*/
|
|
7
|
-
import type { CallOptions, EventStream, Method, ReconnectOptions, ServerEvent, StandardSchemaV1, Stream, WithResponse } from '@nxgt/httpyz';
|
|
7
|
+
import type { CallOptions, EventStream, Method, Middleware, ReconnectOptions, ServerEvent, StandardSchemaV1, Stream, WithResponse } from '@nxgt/httpyz';
|
|
8
8
|
/** What the binding reads of an entry of the generated `ClientOperations`. */
|
|
9
9
|
export interface ClientOperation {
|
|
10
10
|
readonly method: Method;
|
|
@@ -162,7 +162,9 @@ export type PathsOf<Routes, M extends Method> = keyof Routes extends infer Route
|
|
|
162
162
|
export type MethodsOf<Routes> = keyof Routes extends infer Route ? Route extends `${infer M extends Method} ${string}` ? M : never : never;
|
|
163
163
|
/** The `operationId` of the operation at `M P`. */
|
|
164
164
|
export type IdOf<Ops, Routes, M extends Method, P extends string> = Routes[`${M} ${P}` & keyof Routes] & keyof Ops;
|
|
165
|
-
export type OpenApiClient<Ops extends OperationsShape<Ops>, Routes = RoutesOf<Ops>, Decoded extends boolean = true> =
|
|
165
|
+
export type OpenApiClient<Ops extends OperationsShape<Ops>, Routes = RoutesOf<Ops>, Decoded extends boolean = true> = ClientMembers<Ops, Routes, Decoded> & PathMethods<Ops, Routes, Decoded>;
|
|
166
|
+
/** The client's members but its path methods: an interface, for `use()`'s `this`. */
|
|
167
|
+
export interface ClientMembers<Ops extends OperationsShape<Ops>, Routes, Decoded extends boolean> {
|
|
166
168
|
/** Calls an operation by its `operationId`. */
|
|
167
169
|
op<K extends keyof Ops & string>(id: K, ...args: Args<Ops, K>): Promise<WithResponse<OperationReply<Ops, K, Decoded>>>;
|
|
168
170
|
/**
|
|
@@ -176,13 +178,18 @@ export type OpenApiClient<Ops extends OperationsShape<Ops>, Routes = RoutesOf<Op
|
|
|
176
178
|
* also end on `cancel()`, a page's or a component's together.
|
|
177
179
|
*/
|
|
178
180
|
group(): OpenApiGroup<Ops, Routes, Decoded>;
|
|
181
|
+
/**
|
|
182
|
+
* Adds middleware to the core client, in place, as its `use()` does, and
|
|
183
|
+
* returns this client. On a group, to the group's alone.
|
|
184
|
+
*/
|
|
185
|
+
use(...middlewares: Middleware[]): this;
|
|
179
186
|
/**
|
|
180
187
|
* The generated `operations` the client was bound to: for a package built
|
|
181
188
|
* over it, such as `@nxgt/httpyz-query/openapi`, which reads the spec as
|
|
182
189
|
* the client does.
|
|
183
190
|
*/
|
|
184
191
|
readonly operations: OperationTable<Ops>;
|
|
185
|
-
}
|
|
192
|
+
}
|
|
186
193
|
/**
|
|
187
194
|
* A method per HTTP method the spec has an operation for, which calls the
|
|
188
195
|
* operation at a path: `api.get('/employees/{id}', { param: { id } })`. For
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACX,WAAW,EACX,WAAW,EACX,MAAM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,SAAS,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,EAC/D,IAAI,EAAE,CAAC,EACP,GAAG,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,KACvC,OAAO,CACX,YAAY,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CACnE;CACD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { createOpenApiClient } from './client/create-openapi-client';
|
|
2
|
-
export type { Args, ClientOperation, IdOf, MethodsOf, OpenApiArgs, OpenApiClient, OpenApiGroup, OpenApiOptions, OperationInit, OperationReply, OperationStream, OperationStreamOf, OperationsShape, OperationTable, PathMethods, PathsOf, RoutesOf, RuntimeMedia, RuntimeOperation, RuntimeParameter, StreamArgs, StreamIds, StreamInit, } from './client/types';
|
|
2
|
+
export type { Args, ClientMembers, ClientOperation, IdOf, MethodsOf, OpenApiArgs, OpenApiClient, OpenApiGroup, OpenApiOptions, OperationInit, OperationReply, OperationStream, OperationStreamOf, OperationsShape, OperationTable, PathMethods, PathsOf, RoutesOf, RuntimeMedia, RuntimeOperation, RuntimeParameter, StreamArgs, StreamIds, StreamInit, } from './client/types';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,YAAY,EACX,IAAI,EACJ,eAAe,EACf,IAAI,EACJ,SAAS,EACT,WAAW,EACX,aAAa,EACb,YAAY,EACZ,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,WAAW,EACX,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,UAAU,GACV,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,YAAY,EACX,IAAI,EACJ,aAAa,EACb,eAAe,EACf,IAAI,EACJ,SAAS,EACT,WAAW,EACX,aAAa,EACb,YAAY,EACZ,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,WAAW,EACX,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,UAAU,GACV,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -269,6 +269,10 @@ function bind(http, operations, options, scope) {
|
|
|
269
269
|
operations,
|
|
270
270
|
op: (id, ...args) => call(id, args),
|
|
271
271
|
stream: (id, ...args) => stream(id, args),
|
|
272
|
+
use: (...middlewares) => {
|
|
273
|
+
http.use(...middlewares);
|
|
274
|
+
return client;
|
|
275
|
+
},
|
|
272
276
|
group: () => {
|
|
273
277
|
const group = http.group();
|
|
274
278
|
const bound = bind(group, operations, options, () => group.signal);
|
|
@@ -296,5 +300,5 @@ export {
|
|
|
296
300
|
createOpenApiClient
|
|
297
301
|
};
|
|
298
302
|
|
|
299
|
-
//# debugId=
|
|
303
|
+
//# debugId=29C6B7090A61DA2A64756E2164756E21
|
|
300
304
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/client/create-openapi-client.ts", "../src/request/check-request.ts", "../src/request/to-request.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * `createOpenApiClient`: the operations `@nxgt/openapi-codegen` generates,\n * bound onto a client of `createHttpClient`. The client sends; the binding\n * adds what the spec knows: how each parameter and body is written, the\n * replies each operation declares, and checks by the server's own schemas.\n */\nimport {\n\tClientError,\n\ttype EventStream,\n\ttype HttpClient,\n\ttype Responses,\n\tValidationError,\n} from '@nxgt/httpyz';\nimport { METHODS } from '@nxgt/httpyz/integration';\nimport { checkRequest } from '../request/check-request';\nimport { type Input, toRequest } from '../request/to-request';\nimport type {\n\tOpenApiArgs,\n\tOpenApiClient,\n\tOpenApiOptions,\n\tOperationsShape,\n\tOperationTable,\n\tRoutesOf,\n\tRuntimeMedia,\n\tRuntimeOperation,\n\tStreamInit,\n} from './types';\n\n/** An operation's replies as the core client declares them. */\nconst toResponses = (operation: RuntimeOperation): Responses =>\n\tObject.fromEntries(\n\t\tObject.entries(operation.responses).map(([status, content]) => [\n\t\t\tstatus,\n\t\t\tObject.keys(content).length === 0\n\t\t\t\t? null\n\t\t\t\t: Object.fromEntries(\n\t\t\t\t\t\tObject.entries(content).map(([type, media]) => [\n\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\tmedia.schema ?? null,\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t]),\n\t);\n\n/** The stream an operation replies with, and its media type: the first of its 2xx replies. */\nfunction streamOf(\n\toperation: RuntimeOperation,\n): [type: string, media: RuntimeMedia] | undefined {\n\tfor (const [status, content] of Object.entries(operation.responses)) {\n\t\tconst code = Number(status);\n\t\tif (code < 200 || code > 299) continue;\n\t\tfor (const [type, media] of Object.entries(content)) {\n\t\t\tif (media.kind === 'sse' || media.kind === 'jsonl') return [type, media];\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * `open()`'s stream, opened once `check` passes on the first read: a request\n * the spec refuses is never sent, and throws where the stream is read.\n */\nfunction checkedFirst<T>(\n\topen: () => EventStream<T>,\n\tcheck: () => Promise<void>,\n): EventStream<T> {\n\tlet inner: EventStream<T> | undefined;\n\tlet closed = false;\n\treturn {\n\t\tget lastEventId() {\n\t\t\treturn inner?.lastEventId;\n\t\t},\n\t\tclose() {\n\t\t\tclosed = true;\n\t\t\tinner?.close();\n\t\t},\n\t\tasync *[Symbol.asyncIterator]() {\n\t\t\tif (!inner) {\n\t\t\t\tawait check();\n\t\t\t\tif (closed) return;\n\t\t\t\tinner = open();\n\t\t\t}\n\t\t\tyield* inner;\n\t\t},\n\t};\n}\n\n/**\n * A client for a spec, bound to the `operations` table of the generated\n * `operations.ts`, which carries the spec's types: nothing else to import.\n *\n * ```ts\n * const http = createHttpClient({ baseUrl: 'https://api.example.com' });\n * const api = createOpenApiClient(http, operations);\n * const reply = await api.get('/employees/{id}', { param: { id } });\n * if (reply.status === 200) reply.data.name;\n * ```\n *\n * It checks the request and the reply, and returns each reply as its schema\n * outputs it, typed so. `decode: false` returns it as JSON carries it. The\n * types may also be given: `createOpenApiClient<ClientOperations,\n * OperationsByRoute, false>`, whose `false` then requires `decode: false`.\n */\nexport function createOpenApiClient<\n\tOps extends OperationsShape<Ops>,\n\tRoutes = RoutesOf<Ops>,\n>(\n\thttp: HttpClient,\n\toperations: OperationTable<Ops>,\n\toptions: OpenApiOptions & { readonly decode: false },\n): OpenApiClient<Ops, Routes, false>;\nexport function createOpenApiClient<\n\tOps extends OperationsShape<Ops>,\n\tRoutes = RoutesOf<Ops>,\n\tDecoded extends boolean = true,\n>(\n\thttp: HttpClient,\n\toperations: OperationTable<Ops>,\n\t...[given]: OpenApiArgs<Decoded>\n): OpenApiClient<Ops, Routes, Decoded>;\nexport function createOpenApiClient<\n\tOps extends OperationsShape<Ops>,\n\tRoutes,\n\tDecoded extends boolean,\n>(\n\thttp: HttpClient,\n\toperations: OperationTable<Ops>,\n\tgiven?: OpenApiOptions & { readonly decode?: boolean },\n): OpenApiClient<Ops, Routes, Decoded> {\n\treturn bind(http, operations, given ?? {}, () => undefined);\n}\n\n/** Both signals: a call ends on either. */\nconst joined = (\n\tgiven: AbortSignal | null | undefined,\n\tscope: AbortSignal | undefined,\n): AbortSignal | null | undefined =>\n\tscope === undefined ? given : given ? AbortSignal.any([given, scope]) : scope;\n\n/**\n * The client, whose calls also end on `scope()`'s signal, read as each call\n * is made: a call checked before it is sent reaches the core client later,\n * after a `cancel()` of its group may already have swapped the signal.\n */\nfunction bind<\n\tOps extends OperationsShape<Ops>,\n\tRoutes,\n\tDecoded extends boolean,\n>(\n\thttp: HttpClient,\n\toperations: OperationTable<Ops>,\n\toptions: OpenApiOptions & { readonly decode?: boolean },\n\tscope: () => AbortSignal | undefined,\n): OpenApiClient<Ops, Routes, Decoded> {\n\tconst { validate = true } = options;\n\tconst decode = options.decode !== false;\n\tconst checks = {\n\t\trequest:\n\t\t\tvalidate === true ||\n\t\t\t(typeof validate === 'object' && validate.request === true),\n\t\tresponse:\n\t\t\tdecode ||\n\t\t\tvalidate === true ||\n\t\t\t(typeof validate === 'object' && validate.response === true),\n\t};\n\tconst table = operations as unknown as {\n\t\treadonly [id: string]: RuntimeOperation;\n\t};\n\tconst byRoute = new Map<string, string>();\n\tconst responses = new Map<string, Responses>();\n\tfor (const [id, operation] of Object.entries(table)) {\n\t\tbyRoute.set(`${operation.method} ${operation.path}`, id);\n\t\tresponses.set(id, toResponses(operation));\n\t}\n\n\t/** The operation, and its arguments: the input, then the init. */\n\tconst read = (id: string, args: readonly unknown[]) => {\n\t\tconst operation = table[id];\n\t\tif (!operation) throw new Error(`${id} is not an operationId of the spec`);\n\t\t// An operation that takes nothing has no input: its first argument is the init.\n\t\tconst takes =\n\t\t\toperation.parameters.length > 0 ||\n\t\t\tObject.keys(operation.body?.content ?? {}).length > 0;\n\t\tconst input = (takes ? args[0] : undefined) as Input | undefined;\n\t\tconst given = ((takes ? args[1] : args[0]) ?? {}) as StreamInit;\n\t\tconst signal = joined(given.signal, scope());\n\t\tconst init = signal ? { ...given, signal } : given;\n\t\treturn { operation, input, init };\n\t};\n\n\t/** Throws what the server would refuse, before anything is sent. */\n\tconst check = async (\n\t\tid: string,\n\t\toperation: RuntimeOperation,\n\t\tinput: Input | undefined,\n\t): Promise<void> => {\n\t\tif (!checks.request) return;\n\t\tconst issues = await checkRequest(operation, input);\n\t\tif (issues.length === 0) return;\n\t\tconst context = {\n\t\t\toperationId: id,\n\t\t\tmethod: operation.method,\n\t\t\tpath: operation.path,\n\t\t};\n\t\tthrow new ValidationError(context, {\n\t\t\tkind: 'request',\n\t\t\t...context,\n\t\t\tissues,\n\t\t});\n\t};\n\n\t/** The core client's options for the input, written as the server reads it. */\n\tconst written = (\n\t\tid: string,\n\t\toperation: RuntimeOperation,\n\t\tinput: Input | undefined,\n\t\tinit: object & { headers?: HeadersInit },\n\t) => {\n\t\tconst headers = new Headers(init.headers);\n\t\tconst { query, body } = toRequest(operation, input, headers);\n\t\treturn {\n\t\t\t...init,\n\t\t\t...body,\n\t\t\tparam: input?.param,\n\t\t\tquery,\n\t\t\theaders,\n\t\t\toperationId: id,\n\t\t};\n\t};\n\n\tconst call = async (\n\t\tid: string,\n\t\targs: readonly unknown[],\n\t): Promise<unknown> => {\n\t\tconst { operation, input, init } = read(id, args);\n\t\tawait check(id, operation, input);\n\t\tconst request = http.request as (\n\t\t\tmethod: string,\n\t\t\tpath: string,\n\t\t\toptions: object,\n\t\t) => Promise<unknown>;\n\t\treturn request(operation.method, operation.path, {\n\t\t\t...written(id, operation, input, init),\n\t\t\tresponses: responses.get(id),\n\t\t\tvalidate: checks.response,\n\t\t\tdecode,\n\t\t});\n\t};\n\n\tconst stream = (id: string, args: readonly unknown[]) => {\n\t\tconst { operation, input, init } = read(id, args);\n\t\tconst found = streamOf(operation);\n\t\tif (!found) throw new Error(`${id} does not reply with a stream`);\n\t\tconst [type, media] = found;\n\t\tconst { reconnect, lastEventId, onUnknownEvent, ...rest } = init;\n\t\tconst open = () => {\n\t\t\tconst request = written(id, operation, input, rest);\n\t\t\t// The media type the spec declares, which may not be the core client's default.\n\t\t\tif (!request.headers.has('accept')) request.headers.set('accept', type);\n\t\t\tconst common = {\n\t\t\t\t...request,\n\t\t\t\tmethod: operation.method,\n\t\t\t\tvalidate: checks.response,\n\t\t\t\tdecode,\n\t\t\t};\n\t\t\tconst openStream = (media.kind === 'sse' ? http.events : http.lines) as (\n\t\t\t\tpath: string,\n\t\t\t\toptions: object,\n\t\t\t) => EventStream<unknown>;\n\t\t\treturn openStream(\n\t\t\t\toperation.path,\n\t\t\t\tmedia.kind === 'sse'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t...common,\n\t\t\t\t\t\t\tevents: media.events,\n\t\t\t\t\t\t\treconnect,\n\t\t\t\t\t\t\tlastEventId,\n\t\t\t\t\t\t\tonUnknownEvent,\n\t\t\t\t\t\t}\n\t\t\t\t\t: { ...common, item: media.item },\n\t\t\t);\n\t\t};\n\t\treturn checks.request\n\t\t\t? checkedFirst(open, () => check(id, operation, input))\n\t\t\t: open();\n\t};\n\n\tconst client: Record<string, unknown> = {\n\t\toperations,\n\t\top: (id: string, ...args: unknown[]) => call(id, args),\n\t\tstream: (id: string, ...args: unknown[]) => stream(id, args),\n\t\tgroup: () => {\n\t\t\tconst group = http.group();\n\t\t\tconst bound = bind<Ops, Routes, Decoded>(\n\t\t\t\tgroup,\n\t\t\t\toperations,\n\t\t\t\toptions,\n\t\t\t\t() => group.signal,\n\t\t\t);\n\t\t\treturn Object.defineProperties(bound, {\n\t\t\t\tcancel: { enumerable: true, value: group.cancel },\n\t\t\t\tsignal: { enumerable: true, get: () => group.signal },\n\t\t\t});\n\t\t},\n\t};\n\t// Only the spec's methods, as the types have them: no `trace` without a TRACE operation.\n\tconst methods = new Set(Object.values(table).map(({ method }) => method));\n\tfor (const method of METHODS) {\n\t\tif (!methods.has(method)) continue;\n\t\tclient[method] = (path: string, ...args: unknown[]) => {\n\t\t\tconst id = byRoute.get(`${method} ${path}`);\n\t\t\tif (id === undefined) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew ClientError({ method, path }, 'the spec has no operation at it'),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn call(id, args);\n\t\t};\n\t}\n\treturn client as unknown as OpenApiClient<Ops, Routes, Decoded>;\n}\n",
|
|
5
|
+
"/**\n * `createOpenApiClient`: the operations `@nxgt/openapi-codegen` generates,\n * bound onto a client of `createHttpClient`. The client sends; the binding\n * adds what the spec knows: how each parameter and body is written, the\n * replies each operation declares, and checks by the server's own schemas.\n */\nimport {\n\tClientError,\n\ttype EventStream,\n\ttype HttpClient,\n\ttype Middleware,\n\ttype Responses,\n\tValidationError,\n} from '@nxgt/httpyz';\nimport { METHODS } from '@nxgt/httpyz/integration';\nimport { checkRequest } from '../request/check-request';\nimport { type Input, toRequest } from '../request/to-request';\nimport type {\n\tOpenApiArgs,\n\tOpenApiClient,\n\tOpenApiOptions,\n\tOperationsShape,\n\tOperationTable,\n\tRoutesOf,\n\tRuntimeMedia,\n\tRuntimeOperation,\n\tStreamInit,\n} from './types';\n\n/** An operation's replies as the core client declares them. */\nconst toResponses = (operation: RuntimeOperation): Responses =>\n\tObject.fromEntries(\n\t\tObject.entries(operation.responses).map(([status, content]) => [\n\t\t\tstatus,\n\t\t\tObject.keys(content).length === 0\n\t\t\t\t? null\n\t\t\t\t: Object.fromEntries(\n\t\t\t\t\t\tObject.entries(content).map(([type, media]) => [\n\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\tmedia.schema ?? null,\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t]),\n\t);\n\n/** The stream an operation replies with, and its media type: the first of its 2xx replies. */\nfunction streamOf(\n\toperation: RuntimeOperation,\n): [type: string, media: RuntimeMedia] | undefined {\n\tfor (const [status, content] of Object.entries(operation.responses)) {\n\t\tconst code = Number(status);\n\t\tif (code < 200 || code > 299) continue;\n\t\tfor (const [type, media] of Object.entries(content)) {\n\t\t\tif (media.kind === 'sse' || media.kind === 'jsonl') return [type, media];\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * `open()`'s stream, opened once `check` passes on the first read: a request\n * the spec refuses is never sent, and throws where the stream is read.\n */\nfunction checkedFirst<T>(\n\topen: () => EventStream<T>,\n\tcheck: () => Promise<void>,\n): EventStream<T> {\n\tlet inner: EventStream<T> | undefined;\n\tlet closed = false;\n\treturn {\n\t\tget lastEventId() {\n\t\t\treturn inner?.lastEventId;\n\t\t},\n\t\tclose() {\n\t\t\tclosed = true;\n\t\t\tinner?.close();\n\t\t},\n\t\tasync *[Symbol.asyncIterator]() {\n\t\t\tif (!inner) {\n\t\t\t\tawait check();\n\t\t\t\tif (closed) return;\n\t\t\t\tinner = open();\n\t\t\t}\n\t\t\tyield* inner;\n\t\t},\n\t};\n}\n\n/**\n * A client for a spec, bound to the `operations` table of the generated\n * `operations.ts`, which carries the spec's types: nothing else to import.\n *\n * ```ts\n * const http = createHttpClient({ baseUrl: 'https://api.example.com' });\n * const api = createOpenApiClient(http, operations);\n * const reply = await api.get('/employees/{id}', { param: { id } });\n * if (reply.status === 200) reply.data.name;\n * ```\n *\n * It checks the request and the reply, and returns each reply as its schema\n * outputs it, typed so. `decode: false` returns it as JSON carries it. The\n * types may also be given: `createOpenApiClient<ClientOperations,\n * OperationsByRoute, false>`, whose `false` then requires `decode: false`.\n */\nexport function createOpenApiClient<\n\tOps extends OperationsShape<Ops>,\n\tRoutes = RoutesOf<Ops>,\n>(\n\thttp: HttpClient,\n\toperations: OperationTable<Ops>,\n\toptions: OpenApiOptions & { readonly decode: false },\n): OpenApiClient<Ops, Routes, false>;\nexport function createOpenApiClient<\n\tOps extends OperationsShape<Ops>,\n\tRoutes = RoutesOf<Ops>,\n\tDecoded extends boolean = true,\n>(\n\thttp: HttpClient,\n\toperations: OperationTable<Ops>,\n\t...[given]: OpenApiArgs<Decoded>\n): OpenApiClient<Ops, Routes, Decoded>;\nexport function createOpenApiClient<\n\tOps extends OperationsShape<Ops>,\n\tRoutes,\n\tDecoded extends boolean,\n>(\n\thttp: HttpClient,\n\toperations: OperationTable<Ops>,\n\tgiven?: OpenApiOptions & { readonly decode?: boolean },\n): OpenApiClient<Ops, Routes, Decoded> {\n\treturn bind(http, operations, given ?? {}, () => undefined);\n}\n\n/** Both signals: a call ends on either. */\nconst joined = (\n\tgiven: AbortSignal | null | undefined,\n\tscope: AbortSignal | undefined,\n): AbortSignal | null | undefined =>\n\tscope === undefined ? given : given ? AbortSignal.any([given, scope]) : scope;\n\n/**\n * The client, whose calls also end on `scope()`'s signal, read as each call\n * is made: a call checked before it is sent reaches the core client later,\n * after a `cancel()` of its group may already have swapped the signal.\n */\nfunction bind<\n\tOps extends OperationsShape<Ops>,\n\tRoutes,\n\tDecoded extends boolean,\n>(\n\thttp: HttpClient,\n\toperations: OperationTable<Ops>,\n\toptions: OpenApiOptions & { readonly decode?: boolean },\n\tscope: () => AbortSignal | undefined,\n): OpenApiClient<Ops, Routes, Decoded> {\n\tconst { validate = true } = options;\n\tconst decode = options.decode !== false;\n\tconst checks = {\n\t\trequest:\n\t\t\tvalidate === true ||\n\t\t\t(typeof validate === 'object' && validate.request === true),\n\t\tresponse:\n\t\t\tdecode ||\n\t\t\tvalidate === true ||\n\t\t\t(typeof validate === 'object' && validate.response === true),\n\t};\n\tconst table = operations as unknown as {\n\t\treadonly [id: string]: RuntimeOperation;\n\t};\n\tconst byRoute = new Map<string, string>();\n\tconst responses = new Map<string, Responses>();\n\tfor (const [id, operation] of Object.entries(table)) {\n\t\tbyRoute.set(`${operation.method} ${operation.path}`, id);\n\t\tresponses.set(id, toResponses(operation));\n\t}\n\n\t/** The operation, and its arguments: the input, then the init. */\n\tconst read = (id: string, args: readonly unknown[]) => {\n\t\tconst operation = table[id];\n\t\tif (!operation) throw new Error(`${id} is not an operationId of the spec`);\n\t\t// An operation that takes nothing has no input: its first argument is the init.\n\t\tconst takes =\n\t\t\toperation.parameters.length > 0 ||\n\t\t\tObject.keys(operation.body?.content ?? {}).length > 0;\n\t\tconst input = (takes ? args[0] : undefined) as Input | undefined;\n\t\tconst given = ((takes ? args[1] : args[0]) ?? {}) as StreamInit;\n\t\tconst signal = joined(given.signal, scope());\n\t\tconst init = signal ? { ...given, signal } : given;\n\t\treturn { operation, input, init };\n\t};\n\n\t/** Throws what the server would refuse, before anything is sent. */\n\tconst check = async (\n\t\tid: string,\n\t\toperation: RuntimeOperation,\n\t\tinput: Input | undefined,\n\t): Promise<void> => {\n\t\tif (!checks.request) return;\n\t\tconst issues = await checkRequest(operation, input);\n\t\tif (issues.length === 0) return;\n\t\tconst context = {\n\t\t\toperationId: id,\n\t\t\tmethod: operation.method,\n\t\t\tpath: operation.path,\n\t\t};\n\t\tthrow new ValidationError(context, {\n\t\t\tkind: 'request',\n\t\t\t...context,\n\t\t\tissues,\n\t\t});\n\t};\n\n\t/** The core client's options for the input, written as the server reads it. */\n\tconst written = (\n\t\tid: string,\n\t\toperation: RuntimeOperation,\n\t\tinput: Input | undefined,\n\t\tinit: object & { headers?: HeadersInit },\n\t) => {\n\t\tconst headers = new Headers(init.headers);\n\t\tconst { query, body } = toRequest(operation, input, headers);\n\t\treturn {\n\t\t\t...init,\n\t\t\t...body,\n\t\t\tparam: input?.param,\n\t\t\tquery,\n\t\t\theaders,\n\t\t\toperationId: id,\n\t\t};\n\t};\n\n\tconst call = async (\n\t\tid: string,\n\t\targs: readonly unknown[],\n\t): Promise<unknown> => {\n\t\tconst { operation, input, init } = read(id, args);\n\t\tawait check(id, operation, input);\n\t\tconst request = http.request as (\n\t\t\tmethod: string,\n\t\t\tpath: string,\n\t\t\toptions: object,\n\t\t) => Promise<unknown>;\n\t\treturn request(operation.method, operation.path, {\n\t\t\t...written(id, operation, input, init),\n\t\t\tresponses: responses.get(id),\n\t\t\tvalidate: checks.response,\n\t\t\tdecode,\n\t\t});\n\t};\n\n\tconst stream = (id: string, args: readonly unknown[]) => {\n\t\tconst { operation, input, init } = read(id, args);\n\t\tconst found = streamOf(operation);\n\t\tif (!found) throw new Error(`${id} does not reply with a stream`);\n\t\tconst [type, media] = found;\n\t\tconst { reconnect, lastEventId, onUnknownEvent, ...rest } = init;\n\t\tconst open = () => {\n\t\t\tconst request = written(id, operation, input, rest);\n\t\t\t// The media type the spec declares, which may not be the core client's default.\n\t\t\tif (!request.headers.has('accept')) request.headers.set('accept', type);\n\t\t\tconst common = {\n\t\t\t\t...request,\n\t\t\t\tmethod: operation.method,\n\t\t\t\tvalidate: checks.response,\n\t\t\t\tdecode,\n\t\t\t};\n\t\t\tconst openStream = (media.kind === 'sse' ? http.events : http.lines) as (\n\t\t\t\tpath: string,\n\t\t\t\toptions: object,\n\t\t\t) => EventStream<unknown>;\n\t\t\treturn openStream(\n\t\t\t\toperation.path,\n\t\t\t\tmedia.kind === 'sse'\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t...common,\n\t\t\t\t\t\t\tevents: media.events,\n\t\t\t\t\t\t\treconnect,\n\t\t\t\t\t\t\tlastEventId,\n\t\t\t\t\t\t\tonUnknownEvent,\n\t\t\t\t\t\t}\n\t\t\t\t\t: { ...common, item: media.item },\n\t\t\t);\n\t\t};\n\t\treturn checks.request\n\t\t\t? checkedFirst(open, () => check(id, operation, input))\n\t\t\t: open();\n\t};\n\n\tconst client: Record<string, unknown> = {\n\t\toperations,\n\t\top: (id: string, ...args: unknown[]) => call(id, args),\n\t\tstream: (id: string, ...args: unknown[]) => stream(id, args),\n\t\tuse: (...middlewares: Middleware[]) => {\n\t\t\thttp.use(...middlewares);\n\t\t\treturn client;\n\t\t},\n\t\tgroup: () => {\n\t\t\tconst group = http.group();\n\t\t\tconst bound = bind<Ops, Routes, Decoded>(\n\t\t\t\tgroup,\n\t\t\t\toperations,\n\t\t\t\toptions,\n\t\t\t\t() => group.signal,\n\t\t\t);\n\t\t\treturn Object.defineProperties(bound, {\n\t\t\t\tcancel: { enumerable: true, value: group.cancel },\n\t\t\t\tsignal: { enumerable: true, get: () => group.signal },\n\t\t\t});\n\t\t},\n\t};\n\t// Only the spec's methods, as the types have them: no `trace` without a TRACE operation.\n\tconst methods = new Set(Object.values(table).map(({ method }) => method));\n\tfor (const method of METHODS) {\n\t\tif (!methods.has(method)) continue;\n\t\tclient[method] = (path: string, ...args: unknown[]) => {\n\t\t\tconst id = byRoute.get(`${method} ${path}`);\n\t\t\tif (id === undefined) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew ClientError({ method, path }, 'the spec has no operation at it'),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn call(id, args);\n\t\t};\n\t}\n\treturn client as unknown as OpenApiClient<Ops, Routes, Decoded>;\n}\n",
|
|
6
6
|
"/**\n * A request checked before it is sent, by the validators the server runs, on\n * what `@nxgt/openapi-hono` will read from it: each parameter as the\n * text it travels as, the JSON as it parses, a form as its fields. What the\n * server would refuse is refused here with the same issues, and nothing is\n * sent.\n */\nimport type { StandardSchemaV1, ValidationIssue } from '@nxgt/httpyz';\nimport { absent, check, fields, text } from '@nxgt/httpyz/integration';\nimport type { RuntimeMedia, RuntimeOperation } from '../client/types';\nimport type { Input } from './to-request';\n\nexport async function checkRequest(\n\toperation: RuntimeOperation,\n\tinput: Input | undefined,\n): Promise<ValidationIssue[]> {\n\tconst issues: ValidationIssue[] = [];\n\tconst run = async (\n\t\ttarget: ValidationIssue['target'],\n\t\tschema: StandardSchemaV1 | undefined,\n\t\tvalue: unknown,\n\t): Promise<void> => {\n\t\tif (!schema) return;\n\t\tconst result = await check(schema, value, target);\n\t\tif (!result.ok) issues.push(...result.issues);\n\t};\n\tconst { param, query, header } = readParameters(operation, input);\n\t// In the server's order, so the issues come out in the same one.\n\tawait run('param', operation.param, param);\n\tawait run('query', operation.query, query);\n\tawait run('header', operation.header, header);\n\tconst content = Object.values(operation.body?.content ?? {});\n\tconst schemaOf = (kind: RuntimeMedia['kind']) =>\n\t\tcontent.find((media) => media.kind === kind)?.schema;\n\tif (input?.json !== undefined) {\n\t\tconst sent = JSON.stringify(input.json);\n\t\tawait run(\n\t\t\t'json',\n\t\t\tschemaOf('json'),\n\t\t\tsent === undefined ? undefined : JSON.parse(sent),\n\t\t);\n\t} else if (input?.form !== undefined) {\n\t\tawait run('form', schemaOf('form'), formFields(input.form));\n\t} else if (input?.text !== undefined) {\n\t\tawait run('body', schemaOf('text'), input.text);\n\t}\n\treturn issues;\n}\n\n/** The parameters as the engine reads them: strings, a list as every value. */\nfunction readParameters(\n\toperation: RuntimeOperation,\n\tinput: Input | undefined,\n): Record<'param' | 'query' | 'header', Record<string, unknown>> {\n\tconst read = { param: {}, query: {}, header: {} } as Record<\n\t\t'param' | 'query' | 'header',\n\t\tRecord<string, unknown>\n\t>;\n\tfor (const parameter of operation.parameters) {\n\t\tconst { name, list } = parameter;\n\t\tif (parameter.in === 'path') {\n\t\t\tconst value = input?.param?.[name];\n\t\t\tif (!absent(value)) read.param[name] = text(value);\n\t\t\tcontinue;\n\t\t}\n\t\tconst value =\n\t\t\tparameter.in === 'query'\n\t\t\t\t? input?.query?.[name]\n\t\t\t\t: input?.header?.[name.toLowerCase()];\n\t\tif (absent(value)) continue;\n\t\tconst values = Array.isArray(value) ? value.map(text) : [text(value)];\n\t\tif (parameter.in === 'header') {\n\t\t\t// Headers trims what it holds.\n\t\t\tconst sent = values.join(',').trim();\n\t\t\tread.header[name.toLowerCase()] = list\n\t\t\t\t? sent.split(',').map((item) => item.trim())\n\t\t\t\t: sent;\n\t\t} else if (list) {\n\t\t\tread.query[name] = parameter.explode\n\t\t\t\t? values\n\t\t\t\t: values.join(',').split(',');\n\t\t} else read.query[name] = values.join(',');\n\t}\n\treturn read;\n}\n\n/**\n * A form as Hono's `parseBody({ all: true })` reads it: a field sent once is\n * its value, one sent again or named `x[]` a list, and a `Blob` a `File`.\n */\nfunction formFields(\n\tform: Readonly<Record<string, unknown>>,\n): Record<string, unknown> {\n\tconst read: Record<string, unknown> = {};\n\tfor (const [name, value] of fields(form)) {\n\t\tconst item =\n\t\t\tvalue instanceof Blob && !(value instanceof File)\n\t\t\t\t? new File([value], 'blob', { type: value.type })\n\t\t\t\t: value;\n\t\tconst held = read[name];\n\t\tread[name] =\n\t\t\theld === undefined\n\t\t\t\t? name.endsWith('[]')\n\t\t\t\t\t? [item]\n\t\t\t\t\t: item\n\t\t\t\t: Array.isArray(held)\n\t\t\t\t\t? [...held, item]\n\t\t\t\t\t: [held, item];\n\t}\n\treturn read;\n}\n",
|
|
7
7
|
"/**\n * An operation's input as a call of the core client, written the way\n * `@nxgt/openapi-hono` reads it back: a query list as a repeated key,\n * or joined with commas when the spec says `explode: false`; a header list\n * joined with commas; the body as the media type the spec declares for its\n * kind.\n */\nimport type { BodyInput } from '@nxgt/httpyz';\nimport {\n\tabsent,\n\ttext,\n\ttoFormData,\n\ttoSearchParams,\n} from '@nxgt/httpyz/integration';\nimport type {\n\tRuntimeMedia,\n\tRuntimeOperation,\n\tRuntimeParameter,\n} from '../client/types';\n\n/** What an input may hold, as `ClientOperations` types it. */\nexport interface Input {\n\treadonly param?: Readonly<Record<string, unknown>>;\n\treadonly query?: Readonly<Record<string, unknown>>;\n\t/** Keyed by lowercased name. */\n\treadonly header?: Readonly<Record<string, unknown>>;\n\treadonly json?: unknown;\n\treadonly form?: Readonly<Record<string, unknown>>;\n\treadonly text?: string;\n\treadonly body?: Blob | ArrayBuffer | Uint8Array;\n}\n\n/** What to send as `Content-Type` for a declared media type, which may be a range. */\nconst concrete = (type: string | undefined, fallback: string): string =>\n\ttype === undefined || type.includes('*') ? fallback : type;\n\n/** The query and the body; the header parameters and the body's type go onto `headers`. */\nexport function toRequest(\n\toperation: RuntimeOperation,\n\tinput: Input | undefined,\n\theaders: Headers,\n): { query: URLSearchParams; body: BodyInput } {\n\tconst query = new URLSearchParams();\n\tfor (const param of operation.parameters) {\n\t\tif (param.in === 'query') {\n\t\t\tappendQuery(query, param, input?.query?.[param.name]);\n\t\t} else if (param.in === 'header') {\n\t\t\tconst value = input?.header?.[param.name.toLowerCase()];\n\t\t\tif (absent(value)) continue;\n\t\t\theaders.set(\n\t\t\t\tparam.name,\n\t\t\t\tArray.isArray(value) ? value.map(text).join(',') : text(value),\n\t\t\t);\n\t\t}\n\t}\n\treturn { query, body: toBody(operation, input, headers) };\n}\n\nfunction appendQuery(\n\tsearch: URLSearchParams,\n\tparam: RuntimeParameter,\n\tvalue: unknown,\n): void {\n\tif (absent(value)) return;\n\tif (!Array.isArray(value)) search.append(param.name, text(value));\n\telse if (param.explode) {\n\t\tfor (const item of value) search.append(param.name, text(item));\n\t} else search.append(param.name, value.map(text).join(','));\n}\n\nfunction toBody(\n\toperation: RuntimeOperation,\n\tinput: Input | undefined,\n\theaders: Headers,\n): BodyInput {\n\tif (input === undefined) return {};\n\tconst content = Object.entries(operation.body?.content ?? {});\n\tconst declared = (kind: RuntimeMedia['kind']): string | undefined =>\n\t\tcontent.find(([, media]) => media.kind === kind)?.[0];\n\tif (input.json !== undefined) {\n\t\theaders.set('content-type', concrete(declared('json'), 'application/json'));\n\t\treturn { json: input.json };\n\t}\n\tif (input.form !== undefined) {\n\t\treturn {\n\t\t\tform:\n\t\t\t\tdeclared('form') === 'application/x-www-form-urlencoded'\n\t\t\t\t\t? toSearchParams(input.form)\n\t\t\t\t\t: toFormData(input.form),\n\t\t};\n\t}\n\tif (input.text !== undefined) {\n\t\theaders.set('content-type', concrete(declared('text'), 'text/plain'));\n\t\treturn { text: input.text };\n\t}\n\tif (input.body !== undefined) {\n\t\theaders.set(\n\t\t\t'content-type',\n\t\t\tconcrete(declared('binary'), 'application/octet-stream'),\n\t\t);\n\t\treturn { body: input.body };\n\t}\n\treturn {};\n}\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": ";AAMA;AAAA;AAAA;AAAA;
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";AAMA;AAAA;AAAA;AAAA;AAQA;;;ACNA;AAIA,eAAsB,YAAY,CACjC,WACA,OAC6B;AAAA,EAC7B,MAAM,SAA4B,CAAC;AAAA,EACnC,MAAM,MAAM,OACX,QACA,QACA,UACmB;AAAA,IACnB,IAAI,CAAC;AAAA,MAAQ;AAAA,IACb,MAAM,SAAS,MAAM,MAAM,QAAQ,O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