@temporary-name/server 1.9.3-alpha.021f5c8fe9793dff332b025dce560e804c45a7b1
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/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/adapters/aws-lambda/index.d.mts +30 -0
- package/dist/adapters/aws-lambda/index.d.ts +30 -0
- package/dist/adapters/aws-lambda/index.mjs +30 -0
- package/dist/adapters/fetch/index.d.mts +108 -0
- package/dist/adapters/fetch/index.d.ts +108 -0
- package/dist/adapters/fetch/index.mjs +171 -0
- package/dist/adapters/node/index.d.mts +83 -0
- package/dist/adapters/node/index.d.ts +83 -0
- package/dist/adapters/node/index.mjs +136 -0
- package/dist/adapters/standard/index.d.mts +42 -0
- package/dist/adapters/standard/index.d.ts +42 -0
- package/dist/adapters/standard/index.mjs +8 -0
- package/dist/helpers/index.d.mts +149 -0
- package/dist/helpers/index.d.ts +149 -0
- package/dist/helpers/index.mjs +168 -0
- package/dist/index.d.mts +1324 -0
- package/dist/index.d.ts +1324 -0
- package/dist/index.mjs +2199 -0
- package/dist/openapi/index.d.mts +220 -0
- package/dist/openapi/index.d.ts +220 -0
- package/dist/openapi/index.mjs +776 -0
- package/dist/plugins/index.d.mts +160 -0
- package/dist/plugins/index.d.ts +160 -0
- package/dist/plugins/index.mjs +288 -0
- package/dist/shared/server.BEHw7Eyx.mjs +247 -0
- package/dist/shared/server.BKSOrA6h.d.mts +192 -0
- package/dist/shared/server.BKSOrA6h.d.ts +192 -0
- package/dist/shared/server.BZtKt8i8.mjs +201 -0
- package/dist/shared/server.BeuTpcmO.d.mts +23 -0
- package/dist/shared/server.C1fnTLq0.d.mts +57 -0
- package/dist/shared/server.CMTfy2UB.mjs +293 -0
- package/dist/shared/server.CQyYNJ1H.d.ts +57 -0
- package/dist/shared/server.SLLuK6_v.d.ts +23 -0
- package/package.json +95 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { OpenAPI, AnyContractProcedure, AnySchema, AnyContractRouter } from '@temporary-name/contract';
|
|
2
|
+
export { OpenAPI } from '@temporary-name/contract';
|
|
3
|
+
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter, ORPCError, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@temporary-name/server';
|
|
4
|
+
import { Promisable, Value, HTTPPath, HTTPMethod, NestedClient, Client, MaybeOptionalOptions } from '@temporary-name/shared';
|
|
5
|
+
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
|
+
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
|
+
|
|
8
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
|
9
|
+
/**
|
|
10
|
+
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
|
|
13
|
+
*/
|
|
14
|
+
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
15
|
+
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
16
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
type ObjectSchema = JSONSchema & {
|
|
22
|
+
type: 'object';
|
|
23
|
+
} & object;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
type FileSchema = JSONSchema & {
|
|
28
|
+
type: 'string';
|
|
29
|
+
contentMediaType: string;
|
|
30
|
+
} & object;
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare const LOGIC_KEYWORDS: string[];
|
|
35
|
+
|
|
36
|
+
interface SchemaConverterComponent {
|
|
37
|
+
allowedStrategies: readonly SchemaConvertOptions['strategy'][];
|
|
38
|
+
schema: AnySchema;
|
|
39
|
+
required: boolean;
|
|
40
|
+
ref: string;
|
|
41
|
+
}
|
|
42
|
+
interface SchemaConvertOptions {
|
|
43
|
+
strategy: 'input' | 'output';
|
|
44
|
+
/**
|
|
45
|
+
* Common components should use `$ref` to represent themselves if matched.
|
|
46
|
+
*/
|
|
47
|
+
components?: readonly SchemaConverterComponent[];
|
|
48
|
+
/**
|
|
49
|
+
* Minimum schema structure depth required before using `$ref` for components.
|
|
50
|
+
*
|
|
51
|
+
* For example, if set to 2, `$ref` will only be used for schemas nested at depth 2 or greater.
|
|
52
|
+
*
|
|
53
|
+
* @default 0 - No depth limit;
|
|
54
|
+
*/
|
|
55
|
+
minStructureDepthForRef?: number;
|
|
56
|
+
}
|
|
57
|
+
interface SchemaConverter {
|
|
58
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
|
+
}
|
|
60
|
+
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
62
|
+
}
|
|
63
|
+
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
64
|
+
private readonly converters;
|
|
65
|
+
constructor(converters: readonly ConditionalSchemaConverter[]);
|
|
66
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface OpenAPIGeneratorOptions {
|
|
70
|
+
schemaConverters?: ConditionalSchemaConverter[];
|
|
71
|
+
}
|
|
72
|
+
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
|
|
73
|
+
/**
|
|
74
|
+
* Exclude procedures from the OpenAPI specification.
|
|
75
|
+
*
|
|
76
|
+
* @deprecated Use `filter` option instead.
|
|
77
|
+
* @default () => false
|
|
78
|
+
*/
|
|
79
|
+
exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
82
|
+
*
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
|
86
|
+
/**
|
|
87
|
+
* Common schemas to be used for $ref resolution.
|
|
88
|
+
*/
|
|
89
|
+
commonSchemas?: Record<string, {
|
|
90
|
+
/**
|
|
91
|
+
* Determines which schema definition to use when input and output schemas differ.
|
|
92
|
+
* This is needed because some schemas transform data differently between input and output,
|
|
93
|
+
* making it impossible to use a single $ref for both cases.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* // This schema transforms a string input into a number output
|
|
98
|
+
* const Schema = z.string()
|
|
99
|
+
* .transform(v => Number(v))
|
|
100
|
+
* .pipe(z.number())
|
|
101
|
+
*
|
|
102
|
+
* // Input schema: { type: 'string' }
|
|
103
|
+
* // Output schema: { type: 'number' }
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* When schemas differ between input and output, you must explicitly choose
|
|
107
|
+
* which version to use for the OpenAPI specification.
|
|
108
|
+
*
|
|
109
|
+
* @default 'input' - Uses the input schema definition by default
|
|
110
|
+
*/
|
|
111
|
+
strategy?: SchemaConvertOptions['strategy'];
|
|
112
|
+
schema: AnySchema;
|
|
113
|
+
} | {
|
|
114
|
+
error: 'UndefinedError';
|
|
115
|
+
schema?: never;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
|
120
|
+
*
|
|
121
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
122
|
+
*/
|
|
123
|
+
declare class OpenAPIGenerator {
|
|
124
|
+
#private;
|
|
125
|
+
private readonly converter;
|
|
126
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
|
127
|
+
/**
|
|
128
|
+
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
129
|
+
*
|
|
130
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
131
|
+
*/
|
|
132
|
+
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
declare function toOpenAPIPath(path: HTTPPath): string;
|
|
139
|
+
/**
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
|
|
147
|
+
/**
|
|
148
|
+
* @internal
|
|
149
|
+
*/
|
|
150
|
+
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
163
|
+
declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
|
|
164
|
+
|
|
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
|
+
/**
|
|
183
|
+
*@internal
|
|
184
|
+
*/
|
|
185
|
+
declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
|
|
186
|
+
/**
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
|
|
190
|
+
/**
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
declare function isAnySchema(schema: JSONSchema): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* @internal
|
|
196
|
+
*/
|
|
197
|
+
declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
|
198
|
+
/**
|
|
199
|
+
* @internal
|
|
200
|
+
*/
|
|
201
|
+
declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
|
|
202
|
+
declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
|
|
203
|
+
/**
|
|
204
|
+
* Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
|
|
205
|
+
* recursively expands it into an array of its constituent, non-union base schemas.
|
|
206
|
+
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
|
207
|
+
*/
|
|
208
|
+
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
|
209
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
|
210
|
+
type: 'array';
|
|
211
|
+
items?: JSONSchema;
|
|
212
|
+
}];
|
|
213
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
|
214
|
+
|
|
215
|
+
declare const oo: {
|
|
216
|
+
spec: typeof customOpenAPIOperation;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
220
|
+
export type { ConditionalSchemaConverter, FileSchema, JsonifiedArray, JsonifiedClient, JsonifiedValue, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { OpenAPI, AnyContractProcedure, AnySchema, AnyContractRouter } from '@temporary-name/contract';
|
|
2
|
+
export { OpenAPI } from '@temporary-name/contract';
|
|
3
|
+
import { AnyProcedure, TraverseContractProcedureCallbackOptions, AnyRouter, ORPCError, ClientContext, Lazyable, CreateProcedureClientOptions, InferRouterInitialContext, Schema, ErrorMap, Meta, RouterClient } from '@temporary-name/server';
|
|
4
|
+
import { Promisable, Value, HTTPPath, HTTPMethod, NestedClient, Client, MaybeOptionalOptions } from '@temporary-name/shared';
|
|
5
|
+
import { JSONSchema } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
6
|
+
export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
|
+
|
|
8
|
+
type OverrideOperationValue = Partial<OpenAPI.OperationObject> | ((current: OpenAPI.OperationObject, procedure: AnyContractProcedure) => OpenAPI.OperationObject);
|
|
9
|
+
/**
|
|
10
|
+
* Customize The Operation Object by proxy an error map item or a middleware.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
|
|
13
|
+
*/
|
|
14
|
+
declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
|
|
15
|
+
declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
|
|
16
|
+
declare function applyCustomOpenAPIOperation(operation: OpenAPI.OperationObject, contract: AnyContractProcedure): OpenAPI.OperationObject;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
type ObjectSchema = JSONSchema & {
|
|
22
|
+
type: 'object';
|
|
23
|
+
} & object;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
type FileSchema = JSONSchema & {
|
|
28
|
+
type: 'string';
|
|
29
|
+
contentMediaType: string;
|
|
30
|
+
} & object;
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare const LOGIC_KEYWORDS: string[];
|
|
35
|
+
|
|
36
|
+
interface SchemaConverterComponent {
|
|
37
|
+
allowedStrategies: readonly SchemaConvertOptions['strategy'][];
|
|
38
|
+
schema: AnySchema;
|
|
39
|
+
required: boolean;
|
|
40
|
+
ref: string;
|
|
41
|
+
}
|
|
42
|
+
interface SchemaConvertOptions {
|
|
43
|
+
strategy: 'input' | 'output';
|
|
44
|
+
/**
|
|
45
|
+
* Common components should use `$ref` to represent themselves if matched.
|
|
46
|
+
*/
|
|
47
|
+
components?: readonly SchemaConverterComponent[];
|
|
48
|
+
/**
|
|
49
|
+
* Minimum schema structure depth required before using `$ref` for components.
|
|
50
|
+
*
|
|
51
|
+
* For example, if set to 2, `$ref` will only be used for schemas nested at depth 2 or greater.
|
|
52
|
+
*
|
|
53
|
+
* @default 0 - No depth limit;
|
|
54
|
+
*/
|
|
55
|
+
minStructureDepthForRef?: number;
|
|
56
|
+
}
|
|
57
|
+
interface SchemaConverter {
|
|
58
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
|
+
}
|
|
60
|
+
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
|
+
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
|
62
|
+
}
|
|
63
|
+
declare class CompositeSchemaConverter implements SchemaConverter {
|
|
64
|
+
private readonly converters;
|
|
65
|
+
constructor(converters: readonly ConditionalSchemaConverter[]);
|
|
66
|
+
convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface OpenAPIGeneratorOptions {
|
|
70
|
+
schemaConverters?: ConditionalSchemaConverter[];
|
|
71
|
+
}
|
|
72
|
+
interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document, 'openapi'>> {
|
|
73
|
+
/**
|
|
74
|
+
* Exclude procedures from the OpenAPI specification.
|
|
75
|
+
*
|
|
76
|
+
* @deprecated Use `filter` option instead.
|
|
77
|
+
* @default () => false
|
|
78
|
+
*/
|
|
79
|
+
exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Filter procedures. Return `false` to exclude a procedure from the OpenAPI specification.
|
|
82
|
+
*
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
filter?: Value<boolean, [options: TraverseContractProcedureCallbackOptions]>;
|
|
86
|
+
/**
|
|
87
|
+
* Common schemas to be used for $ref resolution.
|
|
88
|
+
*/
|
|
89
|
+
commonSchemas?: Record<string, {
|
|
90
|
+
/**
|
|
91
|
+
* Determines which schema definition to use when input and output schemas differ.
|
|
92
|
+
* This is needed because some schemas transform data differently between input and output,
|
|
93
|
+
* making it impossible to use a single $ref for both cases.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* // This schema transforms a string input into a number output
|
|
98
|
+
* const Schema = z.string()
|
|
99
|
+
* .transform(v => Number(v))
|
|
100
|
+
* .pipe(z.number())
|
|
101
|
+
*
|
|
102
|
+
* // Input schema: { type: 'string' }
|
|
103
|
+
* // Output schema: { type: 'number' }
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* When schemas differ between input and output, you must explicitly choose
|
|
107
|
+
* which version to use for the OpenAPI specification.
|
|
108
|
+
*
|
|
109
|
+
* @default 'input' - Uses the input schema definition by default
|
|
110
|
+
*/
|
|
111
|
+
strategy?: SchemaConvertOptions['strategy'];
|
|
112
|
+
schema: AnySchema;
|
|
113
|
+
} | {
|
|
114
|
+
error: 'UndefinedError';
|
|
115
|
+
schema?: never;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
|
120
|
+
*
|
|
121
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
122
|
+
*/
|
|
123
|
+
declare class OpenAPIGenerator {
|
|
124
|
+
#private;
|
|
125
|
+
private readonly converter;
|
|
126
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
|
127
|
+
/**
|
|
128
|
+
* Generates OpenAPI specifications from oRPC routers/contracts.
|
|
129
|
+
*
|
|
130
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
|
|
131
|
+
*/
|
|
132
|
+
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
declare function toOpenAPIPath(path: HTTPPath): string;
|
|
139
|
+
/**
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
declare function toOpenAPIMethod(method: HTTPMethod): Lowercase<HTTPMethod>;
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
declare function toOpenAPIContent(schema: JSONSchema): Record<string, OpenAPI.MediaTypeObject>;
|
|
147
|
+
/**
|
|
148
|
+
* @internal
|
|
149
|
+
*/
|
|
150
|
+
declare function toOpenAPIEventIteratorContent([yieldsRequired, yieldsSchema]: [boolean, JSONSchema], [returnsRequired, returnsSchema]: [boolean, JSONSchema]): Record<string, OpenAPI.MediaTypeObject>;
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
declare function toOpenAPIParameters(schema: ObjectSchema, parameterIn: 'path' | 'query' | 'header' | 'cookie'): OpenAPI.ParameterObject[];
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
declare function checkParamsSchema(schema: ObjectSchema, params: string[]): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
|
|
163
|
+
declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
|
|
164
|
+
|
|
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
|
+
/**
|
|
183
|
+
*@internal
|
|
184
|
+
*/
|
|
185
|
+
declare function isFileSchema(schema: JSONSchema): schema is FileSchema;
|
|
186
|
+
/**
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
declare function isObjectSchema(schema: JSONSchema): schema is ObjectSchema;
|
|
190
|
+
/**
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
declare function isAnySchema(schema: JSONSchema): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* @internal
|
|
196
|
+
*/
|
|
197
|
+
declare function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema];
|
|
198
|
+
/**
|
|
199
|
+
* @internal
|
|
200
|
+
*/
|
|
201
|
+
declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
|
|
202
|
+
declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
|
|
203
|
+
/**
|
|
204
|
+
* Takes a JSON schema and, if it's primarily a union type (anyOf, oneOf),
|
|
205
|
+
* recursively expands it into an array of its constituent, non-union base schemas.
|
|
206
|
+
* If the schema is not a simple union or is a base type, it's returned as a single-element array.
|
|
207
|
+
*/
|
|
208
|
+
declare function expandUnionSchema(schema: JSONSchema): JSONSchema[];
|
|
209
|
+
declare function expandArrayableSchema(schema: JSONSchema): undefined | [items: JSONSchema, array: JSONSchema & {
|
|
210
|
+
type: 'array';
|
|
211
|
+
items?: JSONSchema;
|
|
212
|
+
}];
|
|
213
|
+
declare function isPrimitiveSchema(schema: JSONSchema): boolean;
|
|
214
|
+
|
|
215
|
+
declare const oo: {
|
|
216
|
+
spec: typeof customOpenAPIOperation;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|
|
220
|
+
export type { ConditionalSchemaConverter, FileSchema, JsonifiedArray, JsonifiedClient, JsonifiedValue, ObjectSchema, OpenAPIGeneratorGenerateOptions, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter, SchemaConverterComponent };
|