@orpc/json-schema 2.0.0-beta.47 → 2.0.0-beta.48

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/index.d.ts DELETED
@@ -1,297 +0,0 @@
1
- import * as OpenAPIV3_2 from '@openapi-spec/types/v3.2';
2
- import { AnySchema, RouterContract } from '@orpc/contract';
3
- export { AnySchema, Schema } from '@orpc/contract';
4
- import { Context } from '@orpc/server';
5
- import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
6
- import { ClientContext } from '@orpc/client';
7
- import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
8
- import { StandardJSONSchemaV1 } from '@standard-schema/spec';
9
-
10
- /**
11
- * A JSON Schema (draft 2020-12) representation used across oRPC's JSON schema tooling.
12
- *
13
- * @remarks
14
- * It is also the OpenAPI 3.2 Schema Object, so converted schemas embed into OpenAPI documents as-is.
15
- *
16
- * @see {@link https://orpc.dev/docs/integrations/standard-schema | Standard Schema Integration}
17
- */
18
- type JsonSchema<Value = any> = OpenAPIV3_2.SchemaObject<Value>;
19
- /**
20
- * The declared JSON Schema keywords, the index signature is filtered out.
21
- */
22
- type JsonSchemaKeywords = keyof {
23
- [K in keyof OpenAPIV3_2.SchemaObjectFields as string extends K ? never : K]: unknown;
24
- };
25
- declare enum JsonSchemaType {
26
- Array = "array",
27
- Boolean = "boolean",
28
- Integer = "integer",
29
- Null = "null",
30
- Number = "number",
31
- Object = "object",
32
- String = "string"
33
- }
34
- declare enum JsonSchemaFormat {
35
- Date = "date",
36
- DateTime = "date-time",
37
- Duration = "duration",
38
- Email = "email",
39
- Hostname = "hostname",
40
- IDNEmail = "idn-email",
41
- IDNHostname = "idn-hostname",
42
- IPv4 = "ipv4",
43
- IPv6 = "ipv6",
44
- IRI = "iri",
45
- IRIReference = "iri-reference",
46
- JSONPointer = "json-pointer",
47
- RegEx = "regex",
48
- RelativeJSONPointer = "relative-json-pointer",
49
- Time = "time",
50
- URI = "uri",
51
- URIReference = "uri-reference",
52
- URITemplate = "uri-template",
53
- UUID = "uuid"
54
- }
55
- declare enum JsonSchemaXNativeType {
56
- BigInt = "bigint",
57
- Date = "date",
58
- Url = "url",
59
- Set = "set",
60
- Map = "map"
61
- }
62
-
63
- interface JsonSchemaCoercerOptions {
64
- /**
65
- * Maximum digits, excluding a leading `-`, of a string coerced to `bigint`. Longer strings are left unchanged.
66
- * `Number.POSITIVE_INFINITY` disables it.
67
- *
68
- * @default 4300
69
- */
70
- maxBigIntDigits?: number | undefined;
71
- /**
72
- * Maximum coercion steps per input value, where a step applies one schema to one value.
73
- * Inputs with fewer than 100 values are budgeted as 100. Past the budget the whole input is left uncoerced,
74
- * so validation still runs and reports any mismatch.
75
- *
76
- * @default 1000
77
- */
78
- maxStepsPerValue?: number | undefined;
79
- }
80
- declare class JsonSchemaCoercer {
81
- private readonly nativeCoerceOptions;
82
- private readonly maxStepsPerValue;
83
- /** Reused between calls, since building a context is slow until V8 warms up. */
84
- private idleContext;
85
- constructor(options?: JsonSchemaCoercerOptions);
86
- coerce([schema, optional]: [schema: JsonSchema, optional: boolean], value: unknown): unknown;
87
- private coerceInternal;
88
- private coerceRef;
89
- private extendBudget;
90
- }
91
-
92
- /**
93
- * These utilities assume the schema has only one root-level `$defs` object
94
- * and exclusively use absolute JSON pointers for `$ref` values.
95
- */
96
-
97
- declare function isJsonPrimitiveSchema(schema: JsonSchema): schema is JsonSchema & object;
98
- type JsonFileSchema = JsonSchema & object & {
99
- type: 'string';
100
- contentMediaType?: string;
101
- };
102
- /**
103
- * Returns true when the schema is a file-like string schema.
104
- */
105
- declare function isJsonFileSchema(schema: JsonSchema): schema is JsonFileSchema;
106
- /**
107
- * Returns true when a file schema appears anywhere in the schema, such as in a property, a composition, or a def.
108
- */
109
- declare function containsJsonFileSchema(schema: JsonSchema): boolean;
110
- type JsonObjectSchema = JsonSchema & object & {
111
- type: 'object';
112
- };
113
- /**
114
- * Returns true when the schema is an object schema.
115
- */
116
- declare function isJsonObjectSchema(schema: JsonSchema): schema is JsonObjectSchema;
117
- type JsonArraySchema = JsonSchema & object & {
118
- type: 'array';
119
- };
120
- /**
121
- * Returns true when the schema is an array schema.
122
- */
123
- declare function isJsonArraySchema(schema: JsonSchema): schema is JsonArraySchema;
124
- /**
125
- * Returns true when the schema does not apply any recognized constraints.
126
- */
127
- declare function isUnconstrainedSchema(schema: JsonSchema): boolean;
128
- /**
129
- * Ensures a JSON Schema is represented as an object schema document.
130
- */
131
- declare function ensureJsonSchemaObject(schema: JsonSchema): Exclude<JsonSchema, boolean>;
132
-
133
- /**
134
- * These utilities assume the schema has only one root-level `$defs` object
135
- * and exclusively use absolute JSON pointers for `$ref` values.
136
- */
137
-
138
- /**
139
- * Combines multiple schemas under the requested composition keyword, promoting branch `$defs` to the root.
140
- */
141
- declare function combineJsonSchemasWithComposition(keyword: 'allOf' | 'anyOf' | 'oneOf', schemas: JsonSchema[]): JsonSchema;
142
- type JsonObjectSchemaEntry = [name: string, schema: JsonSchema, optional: boolean];
143
- /**
144
- * Combines object property entries back into a single object schema.
145
- */
146
- declare function combineJsonObjectSchemaEntries(entries: JsonObjectSchemaEntry[]): JsonObjectSchema;
147
- /**
148
- * Parses an object schema, or a composition of object schemas, into property entries.
149
- */
150
- declare function extractJsonObjectSchemaEntries(schema: JsonSchema): JsonObjectSchemaEntry[] | undefined;
151
- /**
152
- * Returns true when an object can stand for every value the schema describes: the schema constrains objects,
153
- * by `type` or object keywords, composes only such schemas, or is unconstrained, since an object satisfies it.
154
- * Unlike {@link extractJsonObjectSchemaEntries}, an unconstrained schema counts as object-like.
155
- */
156
- declare function isJsonObjectLikeSchema(schema: JsonSchema): boolean;
157
- /**
158
- * Flattens `anyOf` and `oneOf` unions when they are the only active constraints.
159
- */
160
- declare function flattenJsonUnionSchema(schema: JsonSchema): JsonSchema[];
161
- /**
162
- * Matches a union made of a single item schema and its array form.
163
- */
164
- declare function matchArrayableJsonSchema(schema: JsonSchema): undefined | [itemSchema: JsonSchema, arraySchema: JsonArraySchema];
165
- declare function deduplicateJsonSchemas(schemas: JsonSchema[]): JsonSchema[];
166
-
167
- /**
168
- * The conversion direction: `input` targets the schema's input type, `output` targets its output type.
169
- *
170
- * @see {@link https://orpc.dev/docs/integrations/standard-schema | Standard Schema Integration}
171
- */
172
- type JsonSchemaConverterDirection = 'input' | 'output';
173
- /**
174
- * Interface for converting validation schemas into JSON Schema representations,
175
- * used by tools such as the OpenAPI Generator and Smart Coercion plugins.
176
- *
177
- * @see {@link https://orpc.dev/docs/integrations/standard-schema | Standard Schema Integration}
178
- */
179
- interface JsonSchemaConverter {
180
- /**
181
- * Determines whether this converter can handle the given schema.
182
- */
183
- condition(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): boolean;
184
- /**
185
- * Converts an ORPC schema to a JSON Schema representation.
186
- */
187
- convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
188
- }
189
- declare class DelegatingJsonSchemaConverter implements Pick<JsonSchemaConverter, 'convert'> {
190
- private readonly converters;
191
- constructor(converters?: JsonSchemaConverter[]);
192
- convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
193
- }
194
-
195
- /**
196
- * These utilities assume the schema has only one root-level `$defs` object
197
- * and exclusively use absolute JSON pointers for `$ref` values.
198
- */
199
-
200
- /**
201
- * Encodes a JSON Pointer segment according to RFC 6901.
202
- *
203
- * https://datatracker.ietf.org/doc/html/rfc6901
204
- */
205
- declare function encodeJsonPointerSegment(segment: string): string;
206
- /**
207
- * Decodes a JSON Pointer segment according to RFC 6901.
208
- *
209
- * https://datatracker.ietf.org/doc/html/rfc6901
210
- */
211
- declare function decodeJsonPointerSegment(segment: string): string;
212
- /**
213
- * Visits every `$ref` in a schema, traversing the same keywords as {@link mapJsonSchemaRefs}.
214
- * Shared or cyclic object instances are visited once.
215
- */
216
- declare function visitJsonSchemaRefs(value: JsonSchema, visit: (ref: string) => void, schemaLevel?: boolean, seen?: Set<object>): void;
217
- declare function mapJsonSchemaRefs(value: JsonSchema, map: (ref: string, path: Array<string | number>) => string, schemaLevel?: boolean, path?: Array<string | number>): JsonSchema;
218
- /**
219
- * Rewrites recursive root `#` refs by moving the schema body into `$defs`.
220
- */
221
- declare function hoistRecursiveRefToDef(schema: JsonSchema): JsonSchema;
222
- /**
223
- * Resolves a local `$ref` at the **root level** of the given schema, if present.
224
- *
225
- * Only handles refs of the form `#/$defs/<name>` pointing into the provided
226
- * (or schema-embedded) `$defs` map. Nested `$ref`s inside sub-schemas are
227
- * intentionally left untouched.
228
- *
229
- * If the ref cannot be resolved (missing `$defs`, unknown key, etc.) the
230
- * schema is returned as-is. Chained refs are followed until one repeats,
231
- * which is kept.
232
- *
233
- * @param schema - The schema whose root-level `$ref` should be resolved.
234
- * @param $defs - Definition map to resolve against. If omitted, falls back to
235
- * `schema.$defs`. When provided, takes precedence over any `$defs` embedded
236
- * in the schema.
237
- */
238
- declare function resolveJsonSchemaRootLocalRef(schema: JsonSchema, $defs?: Exclude<JsonSchema, boolean>['$defs']): JsonSchema;
239
-
240
- interface SmartCoercionHandlerPluginOptions extends JsonSchemaCoercerOptions {
241
- converters?: JsonSchemaConverter[] | undefined;
242
- }
243
- /**
244
- * Coerces incoming request data to match the expected `.input` schema types before validation,
245
- * based on JSON schemas produced by the configured converters.
246
- *
247
- * @see {@link https://orpc.dev/docs/plugins/smart-coercion | Smart Coercion Plugin}
248
- */
249
- declare class SmartCoercionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
250
- name: string;
251
- private readonly converter;
252
- private readonly coercer;
253
- private readonly cache;
254
- constructor(options?: SmartCoercionHandlerPluginOptions);
255
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
256
- private coerceValue;
257
- }
258
-
259
- interface SmartCoercionLinkPluginOptions extends JsonSchemaCoercerOptions {
260
- converters?: JsonSchemaConverter[] | undefined;
261
- }
262
- /**
263
- * Coerces server responses to match the expected `.output` or `.errors` schema types before validation,
264
- * based on JSON schemas produced by the configured converters.
265
- *
266
- * @see {@link https://orpc.dev/docs/plugins/smart-coercion | Smart Coercion Plugin}
267
- */
268
- declare class SmartCoercionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
269
- private readonly contract;
270
- name: string;
271
- /**
272
- * Output and error values should be coerced before validation.
273
- */
274
- after: string[];
275
- private readonly converter;
276
- private readonly coercer;
277
- private readonly cache;
278
- constructor(contract: RouterContract, options?: SmartCoercionLinkPluginOptions);
279
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
280
- private coerceValue;
281
- }
282
-
283
- /**
284
- * Returns true when the schema accepts `undefined` in the given direction,
285
- * found by validating `undefined` against it. For `output`, the validated value must also be `undefined`.
286
- *
287
- * Returns false when validation throws or is async. An async result is never left as an unhandled rejection.
288
- */
289
- declare function isStandardSchemaOptional(schema: AnySchema, direction: JsonSchemaConverterDirection): boolean;
290
- declare class StandardJsonSchemaConverter implements JsonSchemaConverter {
291
- condition(schema: AnySchema | undefined, _direction: JsonSchemaConverterDirection): boolean;
292
- convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
293
- convertInternal(schema: StandardJSONSchemaV1 & AnySchema, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
294
- }
295
-
296
- export { DelegatingJsonSchemaConverter, JsonSchemaCoercer, JsonSchemaFormat, JsonSchemaType, JsonSchemaXNativeType, SmartCoercionHandlerPlugin, SmartCoercionLinkPlugin, StandardJsonSchemaConverter, combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, containsJsonFileSchema, decodeJsonPointerSegment, deduplicateJsonSchemas, encodeJsonPointerSegment, ensureJsonSchemaObject, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, hoistRecursiveRefToDef, isJsonArraySchema, isJsonFileSchema, isJsonObjectLikeSchema, isJsonObjectSchema, isJsonPrimitiveSchema, isStandardSchemaOptional, isUnconstrainedSchema, mapJsonSchemaRefs, matchArrayableJsonSchema, resolveJsonSchemaRootLocalRef, visitJsonSchemaRefs };
297
- export type { JsonArraySchema, JsonFileSchema, JsonObjectSchema, JsonObjectSchemaEntry, JsonSchema, JsonSchemaCoercerOptions, JsonSchemaConverter, JsonSchemaConverterDirection, JsonSchemaKeywords, SmartCoercionHandlerPluginOptions, SmartCoercionLinkPluginOptions };