@orpc/json-schema 2.0.0-beta.4 → 2.0.0-beta.40

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 CHANGED
@@ -1,19 +1,59 @@
1
- import * as Draft2020 from 'json-schema-typed/draft-2020-12';
2
- export { Format as JsonSchemaFormat, TypeName as JsonSchemaType } from 'json-schema-typed/draft-2020-12';
1
+ import { OpenAPIV3_2 } from '@openapi-spec/types';
3
2
  import { AnySchema, RouterContract } from '@orpc/contract';
4
3
  export { AnySchema, Schema } from '@orpc/contract';
5
- import { Promisable } from '@orpc/shared';
6
4
  import { Context } from '@orpc/server';
7
5
  import { StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
8
6
  import { ClientContext } from '@orpc/client';
9
7
  import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
10
8
  import { StandardJSONSchemaV1 } from '@standard-schema/spec';
11
9
 
12
- type JsonSchema = Draft2020.JSONSchema;
13
- type JsonSchemaKeywords = typeof Draft2020.keywords[number];
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
+ }
14
55
  declare enum JsonSchemaXNativeType {
15
56
  BigInt = "bigint",
16
- RegExp = "regexp",
17
57
  Date = "date",
18
58
  Url = "url",
19
59
  Set = "set",
@@ -90,21 +130,32 @@ declare function flattenJsonUnionSchema(schema: JsonSchema): JsonSchema[];
90
130
  declare function matchArrayableJsonSchema(schema: JsonSchema): undefined | [itemSchema: JsonSchema, arraySchema: JsonArraySchema];
91
131
  declare function deduplicateJsonSchemas(schemas: JsonSchema[]): JsonSchema[];
92
132
 
133
+ /**
134
+ * The conversion direction: `input` targets the schema's input type, `output` targets its output type.
135
+ *
136
+ * @see {@link https://orpc.dev/docs/integrations/standard-schema | Standard Schema Integration}
137
+ */
93
138
  type JsonSchemaConverterDirection = 'input' | 'output';
139
+ /**
140
+ * Interface for converting validation schemas into JSON Schema representations,
141
+ * used by tools such as the OpenAPI Generator and Smart Coercion plugins.
142
+ *
143
+ * @see {@link https://orpc.dev/docs/integrations/standard-schema | Standard Schema Integration}
144
+ */
94
145
  interface JsonSchemaConverter {
95
146
  /**
96
147
  * Determines whether this converter can handle the given schema.
97
148
  */
98
- condition(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): Promisable<boolean>;
149
+ condition(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): boolean;
99
150
  /**
100
151
  * Converts an ORPC schema to a JSON Schema representation.
101
152
  */
102
- convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): Promisable<[jsonSchema: JsonSchema, optional: boolean]>;
153
+ convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
103
154
  }
104
155
  declare class DelegatingJsonSchemaConverter implements Pick<JsonSchemaConverter, 'convert'> {
105
156
  private readonly converters;
106
157
  constructor(converters?: JsonSchemaConverter[]);
107
- convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): Promise<[jsonSchema: JsonSchema, optional: boolean]>;
158
+ convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
108
159
  }
109
160
 
110
161
  /**
@@ -124,6 +175,11 @@ declare function encodeJsonPointerSegment(segment: string): string;
124
175
  * https://datatracker.ietf.org/doc/html/rfc6901
125
176
  */
126
177
  declare function decodeJsonPointerSegment(segment: string): string;
178
+ /**
179
+ * Visits every `$ref` in a schema, traversing the same keywords as {@link mapJsonSchemaRefs}.
180
+ * Shared or cyclic object instances are visited once.
181
+ */
182
+ declare function visitJsonSchemaRefs(value: JsonSchema, visit: (ref: string) => void, schemaLevel?: boolean, seen?: Set<object>): void;
127
183
  declare function mapJsonSchemaRefs(value: JsonSchema, map: (ref: string, path: Array<string | number>) => string, schemaLevel?: boolean, path?: Array<string | number>): JsonSchema;
128
184
  /**
129
185
  * Rewrites recursive root `#` refs by moving the schema body into `$defs`.
@@ -149,6 +205,12 @@ declare function resolveJsonSchemaRootLocalRef(schema: JsonSchema, $defs?: Exclu
149
205
  interface SmartCoercionHandlerPluginOptions {
150
206
  converters?: undefined | JsonSchemaConverter[];
151
207
  }
208
+ /**
209
+ * Coerces incoming request data to match the expected `.input` schema types before validation,
210
+ * based on JSON schemas produced by the configured converters.
211
+ *
212
+ * @see {@link https://orpc.dev/docs/plugins/smart-coercion | Smart Coercion Plugin}
213
+ */
152
214
  declare class SmartCoercionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
153
215
  name: string;
154
216
  private readonly converter;
@@ -162,6 +224,12 @@ declare class SmartCoercionHandlerPlugin<T extends Context> implements StandardH
162
224
  interface SmartCoercionLinkPluginOptions {
163
225
  converters?: undefined | JsonSchemaConverter[];
164
226
  }
227
+ /**
228
+ * Coerces server responses to match the expected `.output` or `.errors` schema types before validation,
229
+ * based on JSON schemas produced by the configured converters.
230
+ *
231
+ * @see {@link https://orpc.dev/docs/plugins/smart-coercion | Smart Coercion Plugin}
232
+ */
165
233
  declare class SmartCoercionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
166
234
  private readonly contract;
167
235
  name: string;
@@ -183,5 +251,5 @@ declare class StandardJsonSchemaConverter implements JsonSchemaConverter {
183
251
  convertInternal(schema: StandardJSONSchemaV1 & AnySchema, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
184
252
  }
185
253
 
186
- export { DelegatingJsonSchemaConverter, JsonSchemaCoercer, JsonSchemaXNativeType, SmartCoercionHandlerPlugin, SmartCoercionLinkPlugin, StandardJsonSchemaConverter, combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, decodeJsonPointerSegment, deduplicateJsonSchemas, encodeJsonPointerSegment, ensureJsonSchemaObject, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, hoistRecursiveRefToDef, isJsonArraySchema, isJsonFileSchema, isJsonObjectSchema, isJsonPrimitiveSchema, isUnconstrainedSchema, mapJsonSchemaRefs, matchArrayableJsonSchema, resolveJsonSchemaRootLocalRef };
254
+ export { DelegatingJsonSchemaConverter, JsonSchemaCoercer, JsonSchemaFormat, JsonSchemaType, JsonSchemaXNativeType, SmartCoercionHandlerPlugin, SmartCoercionLinkPlugin, StandardJsonSchemaConverter, combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, decodeJsonPointerSegment, deduplicateJsonSchemas, encodeJsonPointerSegment, ensureJsonSchemaObject, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, hoistRecursiveRefToDef, isJsonArraySchema, isJsonFileSchema, isJsonObjectSchema, isJsonPrimitiveSchema, isUnconstrainedSchema, mapJsonSchemaRefs, matchArrayableJsonSchema, resolveJsonSchemaRootLocalRef, visitJsonSchemaRefs };
187
255
  export type { JsonArraySchema, JsonFileSchema, JsonObjectSchema, JsonObjectSchemaEntry, JsonSchema, JsonSchemaConverter, JsonSchemaConverterDirection, JsonSchemaKeywords, SmartCoercionHandlerPluginOptions, SmartCoercionLinkPluginOptions };