@orpc/json-schema 2.0.0-beta.49 → 2.0.0-beta.50

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/constants.js CHANGED
@@ -1,66 +1,67 @@
1
- export const JSON_SCHEMA_LOGIC_KEYWORDS =
2
- /* @__PURE__ */ new Set([
3
- '$dynamicRef',
4
- '$ref',
5
- 'additionalItems',
6
- 'additionalProperties',
7
- 'allOf',
8
- 'anyOf',
9
- 'const',
10
- 'contains',
11
- 'contentEncoding',
12
- 'contentMediaType',
13
- 'contentSchema',
14
- 'dependencies',
15
- 'dependentRequired',
16
- 'dependentSchemas',
17
- 'else',
18
- 'enum',
19
- 'exclusiveMaximum',
20
- 'exclusiveMinimum',
21
- 'format',
22
- 'if',
23
- 'items',
24
- 'maxContains',
25
- 'maximum',
26
- 'maxItems',
27
- 'maxLength',
28
- 'maxProperties',
29
- 'minContains',
30
- 'minimum',
31
- 'minItems',
32
- 'minLength',
33
- 'minProperties',
34
- 'multipleOf',
35
- 'not',
36
- 'oneOf',
37
- 'pattern',
38
- 'patternProperties',
39
- 'prefixItems',
40
- 'properties',
41
- 'propertyNames',
42
- 'required',
43
- 'then',
44
- 'type',
45
- 'unevaluatedItems',
46
- 'unevaluatedProperties',
47
- 'uniqueItems',
1
+ // src/constants.ts
2
+ const JSON_SCHEMA_LOGIC_KEYWORDS = /* @__PURE__ */ new Set([
3
+ "$dynamicRef",
4
+ "$ref",
5
+ "additionalItems",
6
+ "additionalProperties",
7
+ "allOf",
8
+ "anyOf",
9
+ "const",
10
+ "contains",
11
+ "contentEncoding",
12
+ "contentMediaType",
13
+ "contentSchema",
14
+ "dependencies",
15
+ "dependentRequired",
16
+ "dependentSchemas",
17
+ "else",
18
+ "enum",
19
+ "exclusiveMaximum",
20
+ "exclusiveMinimum",
21
+ "format",
22
+ "if",
23
+ "items",
24
+ "maxContains",
25
+ "maximum",
26
+ "maxItems",
27
+ "maxLength",
28
+ "maxProperties",
29
+ "minContains",
30
+ "minimum",
31
+ "minItems",
32
+ "minLength",
33
+ "minProperties",
34
+ "multipleOf",
35
+ "not",
36
+ "oneOf",
37
+ "pattern",
38
+ "patternProperties",
39
+ "prefixItems",
40
+ "properties",
41
+ "propertyNames",
42
+ "required",
43
+ "then",
44
+ "type",
45
+ "unevaluatedItems",
46
+ "unevaluatedProperties",
47
+ "uniqueItems"
48
48
  ]);
49
- export const JSON_SCHEMA_PRIMITIVE_TYPES = /* @__PURE__ */ new Set([
50
- 'string',
51
- 'number',
52
- 'integer',
53
- 'boolean',
54
- 'null',
49
+ const JSON_SCHEMA_PRIMITIVE_TYPES = /* @__PURE__ */ new Set([
50
+ "string",
51
+ "number",
52
+ "integer",
53
+ "boolean",
54
+ "null"
55
55
  ]);
56
- export const JSON_SCHEMA_RECORD_KEYWORDS = /* @__PURE__ */ new Set([
57
- 'properties',
58
- 'patternProperties',
59
- 'dependentSchemas',
60
- 'dependencies',
61
- '$defs',
56
+ const JSON_SCHEMA_RECORD_KEYWORDS = /* @__PURE__ */ new Set([
57
+ "properties",
58
+ "patternProperties",
59
+ "dependentSchemas",
60
+ "dependencies",
61
+ "$defs"
62
62
  ]);
63
63
  /**
64
- * Keywords whose values are literal instance data, never subschemas.
65
- */
66
- export const JSON_SCHEMA_LITERAL_KEYWORDS = /* @__PURE__ */ new Set(['const', 'enum']);
64
+ * Keywords whose values are literal instance data, never subschemas.
65
+ */
66
+ const JSON_SCHEMA_LITERAL_KEYWORDS = /* @__PURE__ */ new Set(["const", "enum"]);
67
+ export { JSON_SCHEMA_LITERAL_KEYWORDS, JSON_SCHEMA_LOGIC_KEYWORDS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_RECORD_KEYWORDS };
package/dist/convert.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { AnySchema } from '@orpc/contract';
2
- import type { JsonSchema } from './types.ts';
1
+ import { JsonSchema } from "./types.js";
2
+ import { AnySchema } from "@orpc/contract";
3
3
  /**
4
4
  * The conversion direction: `input` targets the schema's input type, `output` targets its output type.
5
5
  *
6
6
  * @see {@link https://orpc.dev/docs/integrations/standard-schema | Standard Schema Integration}
7
7
  */
8
- export type JsonSchemaConverterDirection = 'input' | 'output';
8
+ export type JsonSchemaConverterDirection = "input" | "output";
9
9
  /**
10
10
  * Interface for converting validation schemas into JSON Schema representations,
11
11
  * used by tools such as the OpenAPI Generator and Smart Coercion plugins.
@@ -13,17 +13,17 @@ export type JsonSchemaConverterDirection = 'input' | 'output';
13
13
  * @see {@link https://orpc.dev/docs/integrations/standard-schema | Standard Schema Integration}
14
14
  */
15
15
  export interface JsonSchemaConverter {
16
- /**
17
- * Determines whether this converter can handle the given schema.
18
- */
19
- condition(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): boolean;
20
- /**
21
- * Converts an ORPC schema to a JSON Schema representation.
22
- */
23
- convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
24
- }
25
- export declare class DelegatingJsonSchemaConverter implements Pick<JsonSchemaConverter, 'convert'> {
26
- private readonly converters;
27
- constructor(converters?: JsonSchemaConverter[]);
28
- convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
16
+ /**
17
+ * Determines whether this converter can handle the given schema.
18
+ */
19
+ condition(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): boolean;
20
+ /**
21
+ * Converts an ORPC schema to a JSON Schema representation.
22
+ */
23
+ convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
29
24
  }
25
+ export declare class DelegatingJsonSchemaConverter implements Pick<JsonSchemaConverter, "convert"> {
26
+ private readonly converters;
27
+ constructor(converters?: JsonSchemaConverter[]);
28
+ convert(schema: AnySchema | undefined, direction: JsonSchemaConverterDirection): [jsonSchema: JsonSchema, optional: boolean];
29
+ }
package/dist/convert.js CHANGED
@@ -1,14 +1,12 @@
1
- export class DelegatingJsonSchemaConverter {
2
- converters;
3
- constructor(converters = []) {
4
- this.converters = converters;
5
- }
6
- convert(schema, direction) {
7
- for (const converter of this.converters) {
8
- if (converter.condition(schema, direction)) {
9
- return converter.convert(schema, direction);
10
- }
11
- }
12
- return [{}, true];
13
- }
14
- }
1
+ // src/convert.ts
2
+ var DelegatingJsonSchemaConverter = class {
3
+ converters;
4
+ constructor(converters = []) {
5
+ this.converters = converters;
6
+ }
7
+ convert(schema, direction) {
8
+ for (const converter of this.converters) if (converter.condition(schema, direction)) return converter.convert(schema, direction);
9
+ return [{}, true];
10
+ }
11
+ };
12
+ export { DelegatingJsonSchemaConverter };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- export * from './coercer.ts';
2
- export * from './composition-utils.ts';
3
- export * from './convert.ts';
4
- export * from './ref-utils.ts';
5
- export * from './smart-coercion-handler-plugin.ts';
6
- export * from './smart-coercion-link-plugin.ts';
7
- export * from './standard-json-schema-converter.ts';
8
- export * from './types.ts';
9
- export * from './utils.ts';
10
- export type { AnySchema, Schema } from '@orpc/contract';
1
+ import { JsonSchemaCoercer, JsonSchemaCoercerOptions } from "./coercer.js";
2
+ import { JsonObjectSchemaEntry, combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, deduplicateJsonSchemas, extractJsonObjectSchemaAdditionalProperties, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, isJsonObjectLikeSchema, matchArrayableJsonSchema } from "./composition-utils.js";
3
+ import { DelegatingJsonSchemaConverter, JsonSchemaConverter, JsonSchemaConverterDirection } from "./convert.js";
4
+ import { JsonSchemaKeywordKind, decodeJsonPointerSegment, encodeJsonPointerSegment, getJsonSchemaKeywordKind, hoistRecursiveRefToDef, mapJsonSchemaRefs, resolveJsonSchemaLocalPointer, resolveJsonSchemaRootLocalRef, visitJsonSchemaRefs } from "./ref-utils.js";
5
+ import { SmartCoercionHandlerPlugin, SmartCoercionHandlerPluginOptions } from "./smart-coercion-handler-plugin.js";
6
+ import { SmartCoercionLinkPlugin, SmartCoercionLinkPluginOptions } from "./smart-coercion-link-plugin.js";
7
+ import { StandardJsonSchemaConverter, isStandardSchemaOptional } from "./standard-json-schema-converter.js";
8
+ import { JsonSchema, JsonSchemaFormat, JsonSchemaKeywords, JsonSchemaType, JsonSchemaXNativeType } from "./types.js";
9
+ import { JsonArraySchema, JsonFileSchema, JsonObjectSchema, containsJsonFileSchema, ensureJsonSchemaObject, isJsonArraySchema, isJsonFileSchema, isJsonObjectSchema, isJsonPrimitiveSchema, isUnconstrainedSchema } from "./utils.js";
10
+ import { AnySchema, Schema } from "@orpc/contract";
11
+ export { type AnySchema, DelegatingJsonSchemaConverter, JsonArraySchema, JsonFileSchema, JsonObjectSchema, JsonObjectSchemaEntry, JsonSchema, JsonSchemaCoercer, JsonSchemaCoercerOptions, JsonSchemaConverter, JsonSchemaConverterDirection, JsonSchemaFormat, JsonSchemaKeywordKind, JsonSchemaKeywords, JsonSchemaType, JsonSchemaXNativeType, type Schema, SmartCoercionHandlerPlugin, SmartCoercionHandlerPluginOptions, SmartCoercionLinkPlugin, SmartCoercionLinkPluginOptions, StandardJsonSchemaConverter, combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, containsJsonFileSchema, decodeJsonPointerSegment, deduplicateJsonSchemas, encodeJsonPointerSegment, ensureJsonSchemaObject, extractJsonObjectSchemaAdditionalProperties, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, getJsonSchemaKeywordKind, hoistRecursiveRefToDef, isJsonArraySchema, isJsonFileSchema, isJsonObjectLikeSchema, isJsonObjectSchema, isJsonPrimitiveSchema, isStandardSchemaOptional, isUnconstrainedSchema, mapJsonSchemaRefs, matchArrayableJsonSchema, resolveJsonSchemaLocalPointer, resolveJsonSchemaRootLocalRef, visitJsonSchemaRefs };
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- export * from './coercer.js';
2
- export * from './composition-utils.js';
3
- export * from './convert.js';
4
- export * from './ref-utils.js';
5
- export * from './smart-coercion-handler-plugin.js';
6
- export * from './smart-coercion-link-plugin.js';
7
- export * from './standard-json-schema-converter.js';
8
- export * from './types.js';
9
- export * from './utils.js';
1
+ export { JsonSchemaCoercer } from "./coercer.js";
2
+ export { combineJsonObjectSchemaEntries, combineJsonSchemasWithComposition, deduplicateJsonSchemas, extractJsonObjectSchemaAdditionalProperties, extractJsonObjectSchemaEntries, flattenJsonUnionSchema, isJsonObjectLikeSchema, matchArrayableJsonSchema } from "./composition-utils.js";
3
+ export { DelegatingJsonSchemaConverter } from "./convert.js";
4
+ export { decodeJsonPointerSegment, encodeJsonPointerSegment, getJsonSchemaKeywordKind, hoistRecursiveRefToDef, mapJsonSchemaRefs, resolveJsonSchemaLocalPointer, resolveJsonSchemaRootLocalRef, visitJsonSchemaRefs } from "./ref-utils.js";
5
+ export { SmartCoercionHandlerPlugin } from "./smart-coercion-handler-plugin.js";
6
+ export { SmartCoercionLinkPlugin } from "./smart-coercion-link-plugin.js";
7
+ export { StandardJsonSchemaConverter, isStandardSchemaOptional } from "./standard-json-schema-converter.js";
8
+ export { JsonSchemaFormat, JsonSchemaType, JsonSchemaXNativeType } from "./types.js";
9
+ export { containsJsonFileSchema, ensureJsonSchemaObject, isJsonArraySchema, isJsonFileSchema, isJsonObjectSchema, isJsonPrimitiveSchema, isUnconstrainedSchema } from "./utils.js";
@@ -1,8 +1,4 @@
1
- /**
2
- * These utilities assume the schema has only one root-level `$defs` object
3
- * and exclusively use absolute JSON pointers for `$ref` values.
4
- */
5
- import type { JsonSchema } from './types.ts';
1
+ import { JsonSchema } from "./types.js";
6
2
  /**
7
3
  * Encodes a JSON Pointer segment according to RFC 6901.
8
4
  *
@@ -20,7 +16,7 @@ export declare function decodeJsonPointerSegment(segment: string): string;
20
16
  * Returns `undefined` for non-local refs and missing targets.
21
17
  */
22
18
  export declare function resolveJsonSchemaLocalPointer(root: JsonSchema, ref: string): JsonSchema | undefined;
23
- export type JsonSchemaKeywordKind = 'ref' | 'discriminator' | 'schema' | 'schema-record' | 'data';
19
+ export type JsonSchemaKeywordKind = "ref" | "discriminator" | "schema" | "schema-record" | "data";
24
20
  /**
25
21
  * Classifies `value` under `key` in a schema object, as traversed by {@link visitJsonSchemaRefs}
26
22
  * and {@link mapJsonSchemaRefs}: a `$ref` string, an OpenAPI `discriminator`, a subschema (or list
@@ -56,4 +52,4 @@ export declare function hoistRecursiveRefToDef(schema: JsonSchema): JsonSchema;
56
52
  * `schema.$defs`. When provided, takes precedence over any `$defs` embedded
57
53
  * in the schema.
58
54
  */
59
- export declare function resolveJsonSchemaRootLocalRef(schema: JsonSchema, $defs?: Exclude<JsonSchema, boolean>['$defs']): JsonSchema;
55
+ export declare function resolveJsonSchemaRootLocalRef(schema: JsonSchema, $defs?: Exclude<JsonSchema, boolean>["$defs"]): JsonSchema;