@temporary-name/server 1.9.3-alpha.82e5e55517330d6049913c9b2f19e60239cd25d9 → 1.9.3-alpha.843e52d0b7b6ee25c0e3e090fefb2f73878bc139
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/dist/adapters/aws-lambda/index.d.mts +4 -6
- package/dist/adapters/aws-lambda/index.d.ts +4 -6
- package/dist/adapters/aws-lambda/index.mjs +5 -7
- package/dist/adapters/fetch/index.d.mts +8 -86
- package/dist/adapters/fetch/index.d.ts +8 -86
- package/dist/adapters/fetch/index.mjs +17 -158
- package/dist/adapters/node/index.d.mts +8 -63
- package/dist/adapters/node/index.d.ts +8 -63
- package/dist/adapters/node/index.mjs +15 -123
- package/dist/adapters/standard/index.d.mts +20 -33
- package/dist/adapters/standard/index.d.ts +20 -33
- package/dist/adapters/standard/index.mjs +5 -7
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +128 -487
- package/dist/index.d.ts +128 -487
- package/dist/index.mjs +224 -458
- package/dist/openapi/index.d.mts +12 -28
- package/dist/openapi/index.d.ts +12 -28
- package/dist/openapi/index.mjs +67 -154
- package/dist/shared/server.1ES3rTdy.d.ts +41 -0
- package/dist/shared/server.7SKDzhNs.d.mts +381 -0
- package/dist/shared/server.7SKDzhNs.d.ts +381 -0
- package/dist/shared/server.BbWZx2r6.d.mts +41 -0
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/server.CQIFwyhc.mjs +40 -0
- package/dist/shared/server.CYa9puL2.mjs +403 -0
- package/dist/shared/server.ChOv1yG3.mjs +319 -0
- package/dist/shared/server.Cza0RB3u.mjs +160 -0
- package/dist/shared/server.YUvuxHty.mjs +48 -0
- package/package.json +10 -27
- package/dist/plugins/index.d.mts +0 -160
- package/dist/plugins/index.d.ts +0 -160
- package/dist/plugins/index.mjs +0 -288
- package/dist/shared/server.BEHw7Eyx.mjs +0 -247
- package/dist/shared/server.BKSOrA6h.d.mts +0 -192
- package/dist/shared/server.BKSOrA6h.d.ts +0 -192
- package/dist/shared/server.BKh8I1Ny.mjs +0 -239
- package/dist/shared/server.BeuTpcmO.d.mts +0 -23
- package/dist/shared/server.C1fnTLq0.d.mts +0 -57
- package/dist/shared/server.CQyYNJ1H.d.ts +0 -57
- package/dist/shared/server.DLsti1Pv.mjs +0 -293
- package/dist/shared/server.SLLuK6_v.d.ts +0 -23
package/dist/openapi/index.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
1
|
+
import { Contract } from '@temporary-name/server';
|
|
2
|
+
import { OpenAPI, Promisable, Value, HTTPPath, HTTPMethod } from '@temporary-name/shared';
|
|
3
|
+
export { OpenAPI } from '@temporary-name/shared';
|
|
4
|
+
import { d as AnySchema, b as Contract$1, a9 as TraverseContractProcedureCallbackOptions, $ as ContractRouter, u as AnyRouter } from '../shared/server.7SKDzhNs.mjs';
|
|
5
5
|
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
6
|
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
|
+
import '@temporary-name/zod';
|
|
7
8
|
|
|
8
|
-
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure:
|
|
9
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
|
|
9
10
|
/**
|
|
10
11
|
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
11
12
|
*
|
|
@@ -13,7 +14,7 @@ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: Open
|
|
|
13
14
|
*/
|
|
14
15
|
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
15
16
|
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
16
|
-
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract:
|
|
17
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: Contract): OpenAPI.OperationObject;
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @internal
|
|
@@ -55,7 +56,7 @@ interface SchemaConvertOptions {
|
|
|
55
56
|
minStructureDepthForRef?: number;
|
|
56
57
|
}
|
|
57
58
|
interface SchemaConverter {
|
|
58
|
-
convert(
|
|
59
|
+
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
60
|
}
|
|
60
61
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
62
|
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
@@ -76,7 +77,7 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
|
|
|
76
77
|
* @deprecated Use `filter` option instead.
|
|
77
78
|
* @default () => false
|
|
78
79
|
*/
|
|
79
|
-
exclude?: (procedure:
|
|
80
|
+
exclude?: (procedure: Contract$1, path: readonly string[]) => boolean;
|
|
80
81
|
/**
|
|
81
82
|
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
82
83
|
*
|
|
@@ -129,7 +130,7 @@ declare class OpenAPIGenerator {
|
|
|
129
130
|
*
|
|
130
131
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
131
132
|
*/
|
|
132
|
-
generate(router:
|
|
133
|
+
generate(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
/**
|
|
@@ -162,23 +163,6 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
|
|
|
162
163
|
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
163
164
|
declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
|
|
164
165
|
|
|
165
|
-
type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends null ? T : T extends undefined ? T : T extends Array<unknown> ? JsonifiedArray<T> : T extends Record<string, unknown> ? {
|
|
166
|
-
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
167
|
-
} : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
|
|
168
|
-
type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [
|
|
169
|
-
U extends undefined ? null : JsonifiedValue<U>,
|
|
170
|
-
...JsonifiedArray<V>
|
|
171
|
-
] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
172
|
-
/**
|
|
173
|
-
* Convert types that JSON not support to corresponding json types
|
|
174
|
-
*
|
|
175
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
|
|
176
|
-
*/
|
|
177
|
-
type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, UError extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : UError> : {
|
|
178
|
-
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
179
|
-
};
|
|
180
|
-
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
181
|
-
|
|
182
166
|
/**
|
|
183
167
|
*@internal
|
|
184
168
|
*/
|
|
@@ -216,5 +200,5 @@ declare const oo: {
|
|
|
216
200
|
spec: typeof customOpenAPIOperation;
|
|
217
201
|
};
|
|
218
202
|
|
|
219
|
-
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema,
|
|
220
|
-
export type { ConditionalSchemaConverter, FileSchema,
|
|
203
|
+
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
204
|
+
export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
1
|
+
import { Contract } from '@temporary-name/server';
|
|
2
|
+
import { OpenAPI, Promisable, Value, HTTPPath, HTTPMethod } from '@temporary-name/shared';
|
|
3
|
+
export { OpenAPI } from '@temporary-name/shared';
|
|
4
|
+
import { d as AnySchema, b as Contract$1, a9 as TraverseContractProcedureCallbackOptions, $ as ContractRouter, u as AnyRouter } from '../shared/server.7SKDzhNs.js';
|
|
5
5
|
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
6
|
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
|
+
import '@temporary-name/zod';
|
|
7
8
|
|
|
8
|
-
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure:
|
|
9
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: Contract) => OpenAPI.OperationObject);
|
|
9
10
|
/**
|
|
10
11
|
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
11
12
|
*
|
|
@@ -13,7 +14,7 @@ type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: Open
|
|
|
13
14
|
*/
|
|
14
15
|
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
15
16
|
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
16
|
-
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract:
|
|
17
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: Contract): OpenAPI.OperationObject;
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @internal
|
|
@@ -55,7 +56,7 @@ interface SchemaConvertOptions {
|
|
|
55
56
|
minStructureDepthForRef?: number;
|
|
56
57
|
}
|
|
57
58
|
interface SchemaConverter {
|
|
58
|
-
convert(
|
|
59
|
+
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
60
|
}
|
|
60
61
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
62
|
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
@@ -76,7 +77,7 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
|
|
|
76
77
|
* @deprecated Use `filter` option instead.
|
|
77
78
|
* @default () => false
|
|
78
79
|
*/
|
|
79
|
-
exclude?: (procedure:
|
|
80
|
+
exclude?: (procedure: Contract$1, path: readonly string[]) => boolean;
|
|
80
81
|
/**
|
|
81
82
|
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
82
83
|
*
|
|
@@ -129,7 +130,7 @@ declare class OpenAPIGenerator {
|
|
|
129
130
|
*
|
|
130
131
|
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
131
132
|
*/
|
|
132
|
-
generate(router:
|
|
133
|
+
generate(router: ContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
/**
|
|
@@ -162,23 +163,6 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
|
|
|
162
163
|
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
163
164
|
declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
|
|
164
165
|
|
|
165
|
-
type JsonifiedValue<T> = T extends string ? T : T extends number ? T : T extends boolean ? T : T extends null ? T : T extends undefined ? T : T extends Array<unknown> ? JsonifiedArray<T> : T extends Record<string, unknown> ? {
|
|
166
|
-
[K in keyof T]: JsonifiedValue<T[K]>;
|
|
167
|
-
} : T extends Date ? string : T extends bigint ? string : T extends File ? File : T extends Blob ? Blob : T extends RegExp ? string : T extends URL ? string : T extends Map<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends Set<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown;
|
|
168
|
-
type JsonifiedArray<T extends Array<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [
|
|
169
|
-
U extends undefined ? null : JsonifiedValue<U>,
|
|
170
|
-
...JsonifiedArray<V>
|
|
171
|
-
] : T extends Array<infer U> ? Array<JsonifiedValue<U>> : unknown;
|
|
172
|
-
/**
|
|
173
|
-
* Convert types that JSON not support to corresponding json types
|
|
174
|
-
*
|
|
175
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/client/openapi-link OpenAPI Link Docs}
|
|
176
|
-
*/
|
|
177
|
-
type JsonifiedClient<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, UError extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : UError> : {
|
|
178
|
-
[K in keyof T]: T[K] extends NestedClient<any> ? JsonifiedClient<T[K]> : T[K];
|
|
179
|
-
};
|
|
180
|
-
declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
|
|
181
|
-
|
|
182
166
|
/**
|
|
183
167
|
*@internal
|
|
184
168
|
*/
|
|
@@ -216,5 +200,5 @@ declare const oo: {
|
|
|
216
200
|
spec: typeof customOpenAPIOperation;
|
|
217
201
|
};
|
|
218
202
|
|
|
219
|
-
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema,
|
|
220
|
-
export type { ConditionalSchemaConverter, FileSchema,
|
|
203
|
+
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
204
|
+
export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
|
package/dist/openapi/index.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus, fallbackORPCErrorStatus, fallbackORPCErrorMessage, resolveMaybeOptionalOptions, createORPCErrorFromJson } from '@temporary-name/shared';
|
|
4
|
-
import { a as standardizeHTTPPath, j as jsonSerialize, g as getDynamicParams, d as deserialize, s as serialize } from '../shared/server.BEHw7Eyx.mjs';
|
|
1
|
+
import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, fallbackContractConfig, toHttpPath, isORPCErrorStatus } from '@temporary-name/shared';
|
|
2
|
+
import { j as jsonSerialize } from '../shared/server.CQIFwyhc.mjs';
|
|
5
3
|
import '@temporary-name/standard-server';
|
|
4
|
+
import { g as getEventIteratorSchemaDetails } from '../shared/server.YUvuxHty.mjs';
|
|
5
|
+
import { s as standardizeHTTPPath, r as resolveContractProcedures, g as getDynamicParams } from '../shared/server.ChOv1yG3.mjs';
|
|
6
6
|
import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
7
|
export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
8
|
+
import '@temporary-name/zod';
|
|
8
9
|
|
|
9
10
|
const OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
|
10
11
|
function customOpenAPIOperation(o, extend) {
|
|
@@ -22,20 +23,12 @@ function getCustomOpenAPIOperation(o) {
|
|
|
22
23
|
}
|
|
23
24
|
function applyCustomOpenAPIOperation(operation, contract) {
|
|
24
25
|
const operationCustoms = [];
|
|
25
|
-
for (const
|
|
26
|
-
const maybeExtender =
|
|
26
|
+
for (const middleware of contract["~orpc"].middlewares) {
|
|
27
|
+
const maybeExtender = getCustomOpenAPIOperation(middleware);
|
|
27
28
|
if (maybeExtender) {
|
|
28
29
|
operationCustoms.push(maybeExtender);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
if (isProcedure(contract)) {
|
|
32
|
-
for (const middleware of contract["~orpc"].middlewares) {
|
|
33
|
-
const maybeExtender = getCustomOpenAPIOperation(middleware);
|
|
34
|
-
if (maybeExtender) {
|
|
35
|
-
operationCustoms.push(maybeExtender);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
32
|
let currentOperation = operation;
|
|
40
33
|
for (const custom of operationCustoms) {
|
|
41
34
|
if (typeof custom === "function") {
|
|
@@ -401,10 +394,7 @@ class OpenAPIGenerator {
|
|
|
401
394
|
filter: void 0,
|
|
402
395
|
commonSchemas: void 0
|
|
403
396
|
};
|
|
404
|
-
const { baseSchemaConvertOptions
|
|
405
|
-
doc,
|
|
406
|
-
options.commonSchemas
|
|
407
|
-
);
|
|
397
|
+
const { baseSchemaConvertOptions } = await this.#resolveCommonSchemas(doc, options.commonSchemas);
|
|
408
398
|
const contracts = [];
|
|
409
399
|
await resolveContractProcedures({ path: [], router }, (traverseOptions) => {
|
|
410
400
|
if (!value(filter, traverseOptions)) {
|
|
@@ -432,12 +422,6 @@ class OpenAPIGenerator {
|
|
|
432
422
|
};
|
|
433
423
|
await this.#request(doc, operationObjectRef, def, baseSchemaConvertOptions);
|
|
434
424
|
await this.#successResponse(doc, operationObjectRef, def, baseSchemaConvertOptions);
|
|
435
|
-
await this.#errorResponse(
|
|
436
|
-
operationObjectRef,
|
|
437
|
-
def,
|
|
438
|
-
baseSchemaConvertOptions,
|
|
439
|
-
undefinedErrorJsonSchema
|
|
440
|
-
);
|
|
441
425
|
}
|
|
442
426
|
if (typeof def.route.spec === "function") {
|
|
443
427
|
operationObjectRef = def.route.spec(operationObjectRef);
|
|
@@ -530,94 +514,77 @@ ${errors.join("\n\n")}`
|
|
|
530
514
|
}
|
|
531
515
|
async #request(doc, ref, def, baseSchemaConvertOptions) {
|
|
532
516
|
const method = fallbackContractConfig("defaultMethod", def.route.method);
|
|
533
|
-
const details = getEventIteratorSchemaDetails(def.inputSchema);
|
|
534
|
-
if (details) {
|
|
535
|
-
ref.requestBody = {
|
|
536
|
-
required: true,
|
|
537
|
-
content: toOpenAPIEventIteratorContent(
|
|
538
|
-
await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
|
|
539
|
-
await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
|
|
540
|
-
)
|
|
541
|
-
};
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
517
|
const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
|
|
545
|
-
const
|
|
546
|
-
let [required, schema] = await this.converter.convert(def.inputSchema, {
|
|
518
|
+
const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
|
|
547
519
|
...baseSchemaConvertOptions,
|
|
548
520
|
strategy: "input",
|
|
549
|
-
minStructureDepthForRef:
|
|
521
|
+
minStructureDepthForRef: 1
|
|
550
522
|
});
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
);
|
|
559
|
-
if (!isObjectSchema(schema)) {
|
|
560
|
-
throw error2;
|
|
561
|
-
}
|
|
562
|
-
const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
|
|
563
|
-
schema = rest;
|
|
564
|
-
required = rest.required ? rest.required.length !== 0 : false;
|
|
565
|
-
if (!checkParamsSchema(paramsSchema, dynamicParams)) {
|
|
566
|
-
throw error2;
|
|
567
|
-
}
|
|
568
|
-
ref.parameters ??= [];
|
|
569
|
-
ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
|
|
523
|
+
if (dynamicParams?.length) {
|
|
524
|
+
const error = new OpenAPIGeneratorError(
|
|
525
|
+
// TODO: fix this error
|
|
526
|
+
'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
|
|
527
|
+
);
|
|
528
|
+
if (!isObjectSchema(pathSchema)) {
|
|
529
|
+
throw error;
|
|
570
530
|
}
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
531
|
+
if (!checkParamsSchema(pathSchema, dynamicParams)) {
|
|
532
|
+
throw error;
|
|
533
|
+
}
|
|
534
|
+
ref.parameters ??= [];
|
|
535
|
+
ref.parameters.push(...toOpenAPIParameters(pathSchema, "path"));
|
|
536
|
+
} else {
|
|
537
|
+
const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
|
|
538
|
+
if (!isObjectSchema(pathSchema)) {
|
|
539
|
+
console.log("FOO", pathSchema);
|
|
540
|
+
throw error;
|
|
541
|
+
}
|
|
542
|
+
if (!checkParamsSchema(pathSchema, [])) {
|
|
543
|
+
console.log("BAR", pathSchema);
|
|
544
|
+
throw error;
|
|
585
545
|
}
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
const error = new OpenAPIGeneratorError(
|
|
589
|
-
'When input structure is "detailed", input schema must satisfy: { params?: Record<string, unknown>, query?: Record<string, unknown>, headers?: Record<string, unknown>, body?: unknown }'
|
|
590
|
-
);
|
|
591
|
-
if (!isObjectSchema(schema)) {
|
|
592
|
-
throw error;
|
|
593
546
|
}
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
547
|
+
const [_queryRequired, querySchema] = await this.converter.convert(def.schemas.querySchema, {
|
|
548
|
+
...baseSchemaConvertOptions,
|
|
549
|
+
strategy: "input",
|
|
550
|
+
minStructureDepthForRef: 0
|
|
551
|
+
});
|
|
552
|
+
if (!isAnySchema(querySchema)) {
|
|
553
|
+
const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, querySchema);
|
|
554
|
+
if (!isObjectSchema(resolvedSchema)) {
|
|
555
|
+
throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
|
|
556
|
+
}
|
|
557
|
+
ref.parameters ??= [];
|
|
558
|
+
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
|
|
599
559
|
}
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
if (
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
560
|
+
if (method !== "GET") {
|
|
561
|
+
const details = getEventIteratorSchemaDetails(def.schemas.bodySchema);
|
|
562
|
+
if (details) {
|
|
563
|
+
ref.requestBody = {
|
|
564
|
+
required: true,
|
|
565
|
+
content: toOpenAPIEventIteratorContent(
|
|
566
|
+
await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
|
|
567
|
+
await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
|
|
568
|
+
)
|
|
569
|
+
};
|
|
570
|
+
} else {
|
|
571
|
+
const [bodyRequired, bodySchema] = await this.converter.convert(def.schemas.bodySchema, {
|
|
572
|
+
...baseSchemaConvertOptions,
|
|
573
|
+
strategy: "input",
|
|
574
|
+
minStructureDepthForRef: 0
|
|
575
|
+
});
|
|
576
|
+
if (isAnySchema(bodySchema)) {
|
|
577
|
+
return;
|
|
606
578
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
579
|
+
ref.requestBody = {
|
|
580
|
+
required: bodyRequired,
|
|
581
|
+
content: toOpenAPIContent(bodySchema)
|
|
582
|
+
};
|
|
610
583
|
}
|
|
611
584
|
}
|
|
612
|
-
if (schema.properties?.body !== void 0) {
|
|
613
|
-
ref.requestBody = {
|
|
614
|
-
required: schema.required?.includes("body"),
|
|
615
|
-
content: toOpenAPIContent(schema.properties.body)
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
585
|
}
|
|
619
586
|
async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
|
|
620
|
-
const outputSchema = def.outputSchema;
|
|
587
|
+
const outputSchema = def.schemas.outputSchema;
|
|
621
588
|
const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
|
|
622
589
|
const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
|
|
623
590
|
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
|
|
@@ -713,64 +680,10 @@ ${errors.join("\n\n")}`
|
|
|
713
680
|
}
|
|
714
681
|
}
|
|
715
682
|
}
|
|
716
|
-
async #errorResponse(ref, def, baseSchemaConvertOptions, undefinedErrorSchema) {
|
|
717
|
-
const errorMap = def.errorMap;
|
|
718
|
-
const errors = {};
|
|
719
|
-
for (const code in errorMap) {
|
|
720
|
-
const config = errorMap[code];
|
|
721
|
-
if (!config) {
|
|
722
|
-
continue;
|
|
723
|
-
}
|
|
724
|
-
const status = fallbackORPCErrorStatus(code, config.status);
|
|
725
|
-
const message = fallbackORPCErrorMessage(code, config.message);
|
|
726
|
-
const [dataRequired, dataSchema] = await this.converter.convert(config.data, {
|
|
727
|
-
...baseSchemaConvertOptions,
|
|
728
|
-
strategy: "output"
|
|
729
|
-
});
|
|
730
|
-
errors[status] ??= [];
|
|
731
|
-
errors[status].push({
|
|
732
|
-
type: "object",
|
|
733
|
-
properties: {
|
|
734
|
-
defined: { const: true },
|
|
735
|
-
code: { const: code },
|
|
736
|
-
status: { const: status },
|
|
737
|
-
message: { type: "string", default: message },
|
|
738
|
-
data: dataSchema
|
|
739
|
-
},
|
|
740
|
-
required: dataRequired ? ["defined", "code", "status", "message", "data"] : ["defined", "code", "status", "message"]
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
ref.responses ??= {};
|
|
744
|
-
for (const status in errors) {
|
|
745
|
-
const schemas = errors[status];
|
|
746
|
-
ref.responses[status] = {
|
|
747
|
-
description: status,
|
|
748
|
-
content: toOpenAPIContent({
|
|
749
|
-
oneOf: [...schemas, undefinedErrorSchema]
|
|
750
|
-
})
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
function createJsonifiedRouterClient(router, ...rest) {
|
|
757
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
758
|
-
options.interceptors ??= [];
|
|
759
|
-
options.interceptors.unshift(async (options2) => {
|
|
760
|
-
try {
|
|
761
|
-
return deserialize(serialize(await options2.next()));
|
|
762
|
-
} catch (e) {
|
|
763
|
-
if (e instanceof ORPCError) {
|
|
764
|
-
throw createORPCErrorFromJson(deserialize(serialize(e.toJSON(), { outputFormat: "plain" })));
|
|
765
|
-
}
|
|
766
|
-
throw e;
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
return createRouterClient(router, options);
|
|
770
683
|
}
|
|
771
684
|
|
|
772
685
|
const oo = {
|
|
773
686
|
spec: customOpenAPIOperation
|
|
774
687
|
};
|
|
775
688
|
|
|
776
|
-
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema,
|
|
689
|
+
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HTTPPath, StandardResponse, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
+
import { C as Context, l as Router } from './server.7SKDzhNs.js';
|
|
3
|
+
|
|
4
|
+
interface StandardHandleOptions<T extends Context> {
|
|
5
|
+
prefix?: HTTPPath;
|
|
6
|
+
context: T;
|
|
7
|
+
}
|
|
8
|
+
type StandardHandleResult = {
|
|
9
|
+
matched: true;
|
|
10
|
+
response: StandardResponse;
|
|
11
|
+
} | {
|
|
12
|
+
matched: false;
|
|
13
|
+
response: undefined;
|
|
14
|
+
};
|
|
15
|
+
interface StandardHandlerOptions<_TContext extends Context> {
|
|
16
|
+
}
|
|
17
|
+
declare class StandardHandler<T extends Context> {
|
|
18
|
+
private readonly matcher;
|
|
19
|
+
constructor(router: Router<T>, _options: NoInfer<StandardHandlerOptions<T>>);
|
|
20
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (object extends T ? {
|
|
24
|
+
context?: T;
|
|
25
|
+
} : {
|
|
26
|
+
context: T;
|
|
27
|
+
});
|
|
28
|
+
declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
|
|
29
|
+
/**
|
|
30
|
+
* {@link https://github.com/unjs/rou3}
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare function toRou3Pattern(path: HTTPPath): string;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
39
|
+
|
|
40
|
+
export { StandardHandler as c, decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
|
41
|
+
export type { FriendlyStandardHandleOptions as F, StandardHandleOptions as S, StandardHandleResult as a, StandardHandlerOptions as b };
|