schema-truth 0.8.1 → 0.8.3

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.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/dist/{ajv-DS9gtNZC.js → ajv-DejgT2o1.js} +8 -14
  3. package/dist/ajv.d.ts +2 -4
  4. package/dist/ajv.js +1 -1
  5. package/dist/{arktype-CRZ8vXZ5.js → arktype-CzTltPwP.js} +94 -55
  6. package/dist/arktype.d.ts +3 -5
  7. package/dist/arktype.js +1 -1
  8. package/dist/cli/ajv.js +3 -4
  9. package/dist/cli/arktype.js +3 -4
  10. package/dist/cli/effect.js +3 -4
  11. package/dist/cli/typebox.js +3 -4
  12. package/dist/cli/valibot.js +3 -4
  13. package/dist/cli/yup.js +3 -4
  14. package/dist/cli/zod.js +3 -4
  15. package/dist/{cli-eAY8LqwP.js → cli-71Np9i5L.js} +6 -9
  16. package/dist/{effect-BkWovUi3.js → effect-Dj8qARFi.js} +70 -44
  17. package/dist/effect.d.ts +3 -5
  18. package/dist/effect.js +1 -1
  19. package/dist/{helper-CbeedY35.js → helper-WSNbEQKr.js} +1398 -52
  20. package/dist/{index-G7UqNQ4w.d.ts → index-DLVjyrKu.d.ts} +0 -14
  21. package/dist/{index-DYzAccyT.d.ts → index-DU2Nd8eI.d.ts} +2 -6
  22. package/dist/index.d.ts +11 -20
  23. package/dist/index.js +10 -10
  24. package/dist/{parser-CyJ2auea.js → parser-RBrkz7ZL.js} +2 -4
  25. package/dist/{typebox-wYeJqy7T.js → typebox-RAJnIZwI.js} +60 -47
  26. package/dist/typebox.d.ts +3 -5
  27. package/dist/typebox.js +1 -1
  28. package/dist/{valibot-DQUEDYKt.js → valibot-CLUhG6tp.js} +66 -45
  29. package/dist/valibot.d.ts +3 -5
  30. package/dist/valibot.js +1 -1
  31. package/dist/{yup-BMpa9Co1.js → yup-DfE_ofEu.js} +9 -15
  32. package/dist/yup.d.ts +3 -5
  33. package/dist/yup.js +1 -1
  34. package/dist/{zod-Dq9LtqPL.js → zod-BhYAQ3iW.js} +84 -56
  35. package/dist/zod.d.ts +3 -5
  36. package/dist/zod.js +1 -1
  37. package/package.json +5 -5
  38. package/dist/utils-Bky98UmP.js +0 -1146
@@ -1,5 +1,4 @@
1
1
  import * as Effect from "effect/Effect";
2
- //#region src/constants/index.d.ts
3
2
  /**
4
3
  * The values the generators agree on: every list of literals, every prefix and every
5
4
  * pattern that more than one module reads. Types that mirror a list are derived from it in
@@ -178,8 +177,6 @@ declare const ANCHOR_REF_PATTERN: RegExp;
178
177
  * @see https://www.iso.org/iso-4217-currency-codes.html
179
178
  */
180
179
  declare const ISO_4217_CURRENCY_CODES: readonly ['AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', 'CAD', 'CDF', 'CHE', 'CHF', 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU', 'MUR', 'MVR', 'MWK', 'MXN', 'MXV', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLE', 'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'USN', 'UYI', 'UYU', 'UYW', 'UZS', 'VED', 'VES', 'VND', 'VUV', 'WST', 'XAF', 'XAG', 'XAU', 'XBA', 'XBB', 'XBC', 'XBD', 'XCD', 'XCG', 'XDR', 'XOF', 'XPD', 'XPF', 'XPT', 'XSU', 'XTS', 'XUA', 'XXX', 'YER', 'ZAR', 'ZMW', 'ZWG'];
181
- //#endregion
182
- //#region src/parser/json.d.ts
183
180
  /**
184
181
  * A JSON value, as `enum`, `const`, `default` and `examples` carry one. A document read
185
182
  * from disk holds nothing else, so an `undefined` or a function never reaches a generator.
@@ -187,8 +184,6 @@ declare const ISO_4217_CURRENCY_CODES: readonly ['AED', 'AFN', 'ALL', 'AMD', 'AN
187
184
  type JSONValue = string | number | boolean | null | readonly JSONValue[] | {
188
185
  readonly [k: string]: JSONValue;
189
186
  };
190
- //#endregion
191
- //#region src/parser/x-ext/code.d.ts
192
187
  /**
193
188
  * C 層: Code-emitting vendor extensions (escape hatch).
194
189
  *
@@ -222,8 +217,6 @@ type XExtCode = {
222
217
  /** Arktype-only: `.morph(...)` fragment appended verbatim */
223
218
  readonly 'x-morph'?: string;
224
219
  };
225
- //#endregion
226
- //#region src/parser/x-ext/messages.d.ts
227
220
  type XExtMessages = {
228
221
  readonly 'x-error-message'?: string;
229
222
  readonly 'x-length-message'?: string;
@@ -278,8 +271,6 @@ type XExtMessages = {
278
271
  readonly 'x-then-message'?: string;
279
272
  readonly 'x-else-message'?: string;
280
273
  };
281
- //#endregion
282
- //#region src/parser/x-ext/param.d.ts
283
274
  /**
284
275
  * OpenAPI parameter location, or `formData` for a field of a form body
285
276
  * (`application/x-www-form-urlencoded`, `multipart/form-data`).
@@ -319,8 +310,6 @@ type XExtParam = {
319
310
  * @see https://spec.openapis.org/oas/v3.2.0.html#style-values
320
311
  */
321
312
  type ParamStyle = (typeof PARAM_STYLES)[number];
322
- //#endregion
323
- //#region src/parser/x-ext/transform.d.ts
324
313
  /**
325
314
  * B 層: 振る舞い・transform 系 vendor extensions.
326
315
  *
@@ -406,8 +395,6 @@ type XExtTransform = {
406
395
  /** Branded type tag — emitted as Zod `.brand<"Tag">()` etc. */
407
396
  readonly 'x-brand'?: string;
408
397
  };
409
- //#endregion
410
- //#region src/parser/index.d.ts
411
398
  declare const ParseError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
412
399
  readonly _tag: "ParseError";
413
400
  } & Readonly<A>;
@@ -599,5 +586,4 @@ type JSONSchemaCore = {
599
586
  readonly name?: string;
600
587
  };
601
588
  type JSONSchema = JSONSchemaCore & XExtMessages & XExtTransform & XExtCode & XExtParam;
602
- //#endregion
603
589
  export { QUOTE_OR_BACKSLASH_PATTERN as $, DEFINITION_REF_PREFIXES as A, MISSING_DEFINITION_PREFIX as B, ARROW_FUNCTION_PATTERN as C, DEFAULT_ROOT_NAME as D, DATE_PATTERN_SOURCE as E, INPUT_EXTENSIONS as F, NUMBER_WIRE_PATTERN as G, NOT_KEYWORD_UNSUPPORTED_MARKER as H, INTEGER_TEXT_PATTERN as I, OFFSET_PATTERN_SOURCE as J, NUMERIC_KEYWORDS as K, INTEGER_WIRE_PATTERN as L, FORMAT_PATTERNS as M, IDENTIFIER_PATTERN as N, DEFINITION_KEYWORDS as O, IF_THEN_ELSE_UNSUPPORTED_MARKER as P, PARAM_STYLES as Q, ISO_4217_CURRENCY_CODES as R, ARKTYPE_CODE_EXTENSION_KEYS as S, CONTENT_ENCODINGS as T, NUMBER_FORMATS as U, NON_IDENTIFIER_CHARACTER_PATTERN as V, NUMBER_RANGES as W, OUTPUT_EXTENSION as X, OPENAPI_COMPONENT_SUFFIX_MAP as Y, PARAM_LOCATIONS as Z, XExtMessages as _, JSONSchemaNumberFormat as a, STRING_WIRE_LOCATIONS as at, ALL_CODE_EXTENSION_KEYS as b, JSONSchemaTypes as c, VALIBOT_CODE_EXTENSION_KEYS as ct, Ref as d, ROOT_REFS as et, parseSchemaFile as f, XExtParam as g, ParamStyle as h, JSONSchemaFormat as i, STRING_KEYWORDS as it, EFFECT_CODE_EXTENSION_KEYS as j, DEFINITION_POINTER_PATTERN as k, LocalRef as l, WIRE_PRIMITIVE_ORDER as lt, ParamIn as m, ExternalRef as n, STRINGBOOL_TRUTHY_PATTERN as nt, JSONSchemaStringFormat as o, UNICODE_ESCAPE_PATTERN as ot, XExtTransform as p, OBJECT_PROTOTYPE_PROPERTIES as q, JSONSchema as r, STRING_FORMATS as rt, JSONSchemaType as s, UNSAFE_GENERATED_MARKER as st, ContentEncoding as t, STRINGBOOL_PATTERN as tt, ParseError as u, ZOD_CODE_EXTENSION_KEYS as ut, XExtCode as v, COMPONENT_SCHEMA_REF_PREFIX as w, ANCHOR_REF_PATTERN as x, JSONValue as y, JSON_SCHEMA_TYPES as z };
@@ -1,11 +1,8 @@
1
- import { h as ParamStyle, m as ParamIn, r as JSONSchema } from "./index-G7UqNQ4w.js";
2
- //#region src/helper/schema.d.ts
1
+ import { h as ParamStyle, m as ParamIn, r as JSONSchema } from "./index-DLVjyrKu.js";
3
2
  /** Named schemas a `default` beside a `$ref` is reconciled against. */
4
3
  type SchemaDefinitions = {
5
4
  readonly [name: string]: JSONSchema;
6
5
  };
7
- //#endregion
8
- //#region src/options/index.d.ts
9
6
  /** The options every `schemaTo<Library>` document generator accepts. */
10
7
  type GenerateOptions = {
11
8
  /** Also export the inferred TypeScript type. Default: `true`. */
@@ -65,5 +62,4 @@ type GenerateOptions = {
65
62
  };
66
63
  /** The options threaded through every node emitter: `GenerateOptions` without `exportType`. */
67
64
  type EmitOptions = Omit<GenerateOptions, 'exportType'>;
68
- //#endregion
69
- export { GenerateOptions as n, EmitOptions as t };
65
+ export { GenerateOptions as n, SchemaDefinitions as r, EmitOptions as t };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { $ as QUOTE_OR_BACKSLASH_PATTERN, A as DEFINITION_REF_PREFIXES, B as MISSING_DEFINITION_PREFIX, C as ARROW_FUNCTION_PATTERN, D as DEFAULT_ROOT_NAME, E as DATE_PATTERN_SOURCE, F as INPUT_EXTENSIONS, G as NUMBER_WIRE_PATTERN, H as NOT_KEYWORD_UNSUPPORTED_MARKER, I as INTEGER_TEXT_PATTERN, J as OFFSET_PATTERN_SOURCE, K as NUMERIC_KEYWORDS, L as INTEGER_WIRE_PATTERN, M as FORMAT_PATTERNS, N as IDENTIFIER_PATTERN, O as DEFINITION_KEYWORDS, P as IF_THEN_ELSE_UNSUPPORTED_MARKER, Q as PARAM_STYLES, R as ISO_4217_CURRENCY_CODES, S as ARKTYPE_CODE_EXTENSION_KEYS, T as CONTENT_ENCODINGS, U as NUMBER_FORMATS, V as NON_IDENTIFIER_CHARACTER_PATTERN, W as NUMBER_RANGES, X as OUTPUT_EXTENSION, Y as OPENAPI_COMPONENT_SUFFIX_MAP, Z as PARAM_LOCATIONS, _ as XExtMessages, a as JSONSchemaNumberFormat, at as STRING_WIRE_LOCATIONS, b as ALL_CODE_EXTENSION_KEYS, c as JSONSchemaTypes, ct as VALIBOT_CODE_EXTENSION_KEYS, d as Ref, et as ROOT_REFS, f as parseSchemaFile, g as XExtParam, h as ParamStyle, i as JSONSchemaFormat, it as STRING_KEYWORDS, j as EFFECT_CODE_EXTENSION_KEYS, k as DEFINITION_POINTER_PATTERN, l as LocalRef, lt as WIRE_PRIMITIVE_ORDER, m as ParamIn, n as ExternalRef, nt as STRINGBOOL_TRUTHY_PATTERN, o as JSONSchemaStringFormat, ot as UNICODE_ESCAPE_PATTERN, p as XExtTransform, q as OBJECT_PROTOTYPE_PROPERTIES, r as JSONSchema, rt as STRING_FORMATS, s as JSONSchemaType, st as UNSAFE_GENERATED_MARKER, t as ContentEncoding, tt as STRINGBOOL_PATTERN, u as ParseError, ut as ZOD_CODE_EXTENSION_KEYS, v as XExtCode, w as COMPONENT_SCHEMA_REF_PREFIX, x as ANCHOR_REF_PATTERN, y as JSONValue, z as JSON_SCHEMA_TYPES } from "./index-G7UqNQ4w.js";
1
+ import { $ as QUOTE_OR_BACKSLASH_PATTERN, A as DEFINITION_REF_PREFIXES, B as MISSING_DEFINITION_PREFIX, C as ARROW_FUNCTION_PATTERN, D as DEFAULT_ROOT_NAME, E as DATE_PATTERN_SOURCE, F as INPUT_EXTENSIONS, G as NUMBER_WIRE_PATTERN, H as NOT_KEYWORD_UNSUPPORTED_MARKER, I as INTEGER_TEXT_PATTERN, J as OFFSET_PATTERN_SOURCE, K as NUMERIC_KEYWORDS, L as INTEGER_WIRE_PATTERN, M as FORMAT_PATTERNS, N as IDENTIFIER_PATTERN, O as DEFINITION_KEYWORDS, P as IF_THEN_ELSE_UNSUPPORTED_MARKER, Q as PARAM_STYLES, R as ISO_4217_CURRENCY_CODES, S as ARKTYPE_CODE_EXTENSION_KEYS, T as CONTENT_ENCODINGS, U as NUMBER_FORMATS, V as NON_IDENTIFIER_CHARACTER_PATTERN, W as NUMBER_RANGES, X as OUTPUT_EXTENSION, Y as OPENAPI_COMPONENT_SUFFIX_MAP, Z as PARAM_LOCATIONS, _ as XExtMessages, a as JSONSchemaNumberFormat, at as STRING_WIRE_LOCATIONS, b as ALL_CODE_EXTENSION_KEYS, c as JSONSchemaTypes, ct as VALIBOT_CODE_EXTENSION_KEYS, d as Ref, et as ROOT_REFS, f as parseSchemaFile, g as XExtParam, h as ParamStyle, i as JSONSchemaFormat, it as STRING_KEYWORDS, j as EFFECT_CODE_EXTENSION_KEYS, k as DEFINITION_POINTER_PATTERN, l as LocalRef, lt as WIRE_PRIMITIVE_ORDER, m as ParamIn, n as ExternalRef, nt as STRINGBOOL_TRUTHY_PATTERN, o as JSONSchemaStringFormat, ot as UNICODE_ESCAPE_PATTERN, p as XExtTransform, q as OBJECT_PROTOTYPE_PROPERTIES, r as JSONSchema, rt as STRING_FORMATS, s as JSONSchemaType, st as UNSAFE_GENERATED_MARKER, t as ContentEncoding, tt as STRINGBOOL_PATTERN, u as ParseError, ut as ZOD_CODE_EXTENSION_KEYS, v as XExtCode, w as COMPONENT_SCHEMA_REF_PREFIX, x as ANCHOR_REF_PATTERN, y as JSONValue, z as JSON_SCHEMA_TYPES } from "./index-DLVjyrKu.js";
2
2
  import { schemaToAjv } from "./ajv.js";
3
- import { n as GenerateOptions, t as EmitOptions } from "./index-DYzAccyT.js";
3
+ import { n as GenerateOptions, r as SchemaDefinitions, t as EmitOptions } from "./index-DU2Nd8eI.js";
4
4
  import { schemaToArktype } from "./arktype.js";
5
5
  import { schemaToEffect } from "./effect.js";
6
6
  import { TypeboxGenerateOptions, schemaToTypebox } from "./typebox.js";
@@ -8,7 +8,6 @@ import { schemaToValibot } from "./valibot.js";
8
8
  import { schemaToYup } from "./yup.js";
9
9
  import { schemaToZod } from "./zod.js";
10
10
  import * as Effect from "effect/Effect";
11
- //#region src/format/index.d.ts
12
11
  declare const FormatError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
13
12
  readonly _tag: "FormatError";
14
13
  } & Readonly<A>;
@@ -18,8 +17,6 @@ export declare class FormatError extends FormatError_base<{
18
17
  }> {}
19
18
  /** Formats generated TypeScript. Failures land in the error channel. */
20
19
  export declare function fmt(input: string): Effect.Effect<string, FormatError, never>;
21
- //#endregion
22
- //#region src/generator/ajv/ajv.d.ts
23
20
  /**
24
21
  * One schema node to one Ajv draft-07 schema-object expression.
25
22
  *
@@ -33,8 +30,6 @@ export declare function fmt(input: string): Effect.Effect<string, FormatError, n
33
30
  * ```
34
31
  */
35
32
  export declare function ajv(schema: JSONSchema): string;
36
- //#endregion
37
- //#region src/generator/arktype/arktype.d.ts
38
33
  /**
39
34
  * Generate ArkType schema code from JSON Schema.
40
35
  *
@@ -44,8 +39,6 @@ export declare function ajv(schema: JSONSchema): string;
44
39
  * ```
45
40
  */
46
41
  export declare function arktype(schema: JSONSchema, rootName?: string, isArktype?: boolean, options?: EmitOptions): string;
47
- //#endregion
48
- //#region src/generator/effect/effect.d.ts
49
42
  /**
50
43
  * Replace every decoding failure of `inner` with a single message.
51
44
  *
@@ -67,8 +60,6 @@ export declare function wholeValueMessage(inner: string, message: string): strin
67
60
  * has no separate runtime "readonly" wrapper.
68
61
  */
69
62
  export declare function effect(schema: JSONSchema, rootName?: string, isEffect?: boolean, options?: EmitOptions): string;
70
- //#endregion
71
- //#region src/generator/typebox/typebox.d.ts
72
63
  /**
73
64
  * Generation options threaded through every TypeBox emitter.
74
65
  *
@@ -87,6 +78,8 @@ export type TypeboxOptions = {
87
78
  readonly paramIn?: ParamIn;
88
79
  readonly cyclicRefs?: ReadonlySet<string>;
89
80
  readonly ref?: string;
81
+ /** Definitions a `default` beside a `$ref` is checked against. */
82
+ readonly definitions?: SchemaDefinitions;
90
83
  };
91
84
  /**
92
85
  * Options for a nested TypeBox node: the same as `options` but without a
@@ -94,8 +87,6 @@ export type TypeboxOptions = {
94
87
  */
95
88
  export declare function nestedTypeboxOptions(options?: TypeboxOptions): TypeboxOptions | undefined;
96
89
  export declare function typebox(schema: JSONSchema, rootName?: string, isTypebox?: boolean, options?: TypeboxOptions): string;
97
- //#endregion
98
- //#region src/generator/valibot/valibot.d.ts
99
90
  /**
100
91
  * Generate Valibot schema code from JSON Schema.
101
92
  *
@@ -105,8 +96,6 @@ export declare function typebox(schema: JSONSchema, rootName?: string, isTypebox
105
96
  * ```
106
97
  */
107
98
  export declare function valibot(schema: JSONSchema, rootName?: string, isValibot?: boolean, options?: EmitOptions): string;
108
- //#endregion
109
- //#region src/generator/yup/yup.d.ts
110
99
  /**
111
100
  * Generate a Yup expression from one JSON Schema node.
112
101
  *
@@ -119,8 +108,13 @@ export declare function valibot(schema: JSONSchema, rootName?: string, isValibot
119
108
  * ```
120
109
  */
121
110
  export declare function yup(schema: JSONSchema): string;
122
- //#endregion
123
- //#region src/generator/zod/zod.d.ts
111
+ /**
112
+ * Re-push `issue` into `ctx` with `message`. Each issue code is narrowed first: the union of
113
+ * parsed issues does not type-check as a raw issue, while each member does.
114
+ */
115
+ export declare function forwardIssue(message: string): string;
116
+ /** A message for the issues under the value (with a path); the root's own issues keep theirs. */
117
+ export declare function nestedIssueMessageWrap(inner: string, msg: string): string;
124
118
  /**
125
119
  * Generate Zod schema code from JSON Schema.
126
120
  *
@@ -130,8 +124,6 @@ export declare function yup(schema: JSONSchema): string;
130
124
  * ```
131
125
  */
132
126
  export declare function zod(schema: JSONSchema, rootName?: string, isZod?: boolean, options?: EmitOptions): string;
133
- //#endregion
134
- //#region src/utils/index.d.ts
135
127
  /**
136
128
  * Convert string to PascalCase (first character uppercase).
137
129
  *
@@ -328,5 +320,4 @@ export declare function resolveOpenAPIRef($ref: string): string | null;
328
320
  * ```
329
321
  */
330
322
  export declare function makeSafeKey(key: string): string;
331
- //#endregion
332
323
  export { ALL_CODE_EXTENSION_KEYS, ANCHOR_REF_PATTERN, ARKTYPE_CODE_EXTENSION_KEYS, ARROW_FUNCTION_PATTERN, COMPONENT_SCHEMA_REF_PREFIX, CONTENT_ENCODINGS, ContentEncoding, DATE_PATTERN_SOURCE, DEFAULT_ROOT_NAME, DEFINITION_KEYWORDS, DEFINITION_POINTER_PATTERN, DEFINITION_REF_PREFIXES, EFFECT_CODE_EXTENSION_KEYS, type EmitOptions, ExternalRef, FORMAT_PATTERNS, type GenerateOptions, IDENTIFIER_PATTERN, IF_THEN_ELSE_UNSUPPORTED_MARKER, INPUT_EXTENSIONS, INTEGER_TEXT_PATTERN, INTEGER_WIRE_PATTERN, ISO_4217_CURRENCY_CODES, JSONSchema, JSONSchemaFormat, JSONSchemaNumberFormat, JSONSchemaStringFormat, JSONSchemaType, JSONSchemaTypes, type JSONValue, JSON_SCHEMA_TYPES, LocalRef, MISSING_DEFINITION_PREFIX, NON_IDENTIFIER_CHARACTER_PATTERN, NOT_KEYWORD_UNSUPPORTED_MARKER, NUMBER_FORMATS, NUMBER_RANGES, NUMBER_WIRE_PATTERN, NUMERIC_KEYWORDS, OBJECT_PROTOTYPE_PROPERTIES, OFFSET_PATTERN_SOURCE, OPENAPI_COMPONENT_SUFFIX_MAP, OUTPUT_EXTENSION, PARAM_LOCATIONS, PARAM_STYLES, type ParamIn, type ParamStyle, ParseError, QUOTE_OR_BACKSLASH_PATTERN, ROOT_REFS, Ref, STRINGBOOL_PATTERN, STRINGBOOL_TRUTHY_PATTERN, STRING_FORMATS, STRING_KEYWORDS, STRING_WIRE_LOCATIONS, TypeboxGenerateOptions, UNICODE_ESCAPE_PATTERN, UNSAFE_GENERATED_MARKER, VALIBOT_CODE_EXTENSION_KEYS, WIRE_PRIMITIVE_ORDER, type XExtCode, type XExtMessages, type XExtParam, type XExtTransform, ZOD_CODE_EXTENSION_KEYS, parseSchemaFile, schemaToAjv, schemaToArktype, schemaToEffect, schemaToTypebox, schemaToValibot, schemaToYup, schemaToZod };
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { $ as DEFINITION_REF_PREFIXES, At as UNSAFE_GENERATED_MARKER, Ct as ROOT_REFS, Dt as STRING_KEYWORDS, Et as STRING_FORMATS, G as ARKTYPE_CODE_EXTENSION_KEYS, J as CONTENT_ENCODINGS, K as ARROW_FUNCTION_PATTERN, Mt as WIRE_PRIMITIVE_ORDER, Nt as ZOD_CODE_EXTENSION_KEYS, Ot as STRING_WIRE_LOCATIONS, Q as DEFINITION_POINTER_PATTERN, St as QUOTE_OR_BACKSLASH_PATTERN, Tt as STRINGBOOL_TRUTHY_PATTERN, U as ALL_CODE_EXTENSION_KEYS, W as ANCHOR_REF_PATTERN, X as DEFAULT_ROOT_NAME, Y as DATE_PATTERN_SOURCE, Z as DEFINITION_KEYWORDS, _t as OFFSET_PATTERN_SOURCE, a as encodeNonAscii, at as INTEGER_TEXT_PATTERN, bt as PARAM_LOCATIONS, c as normalizeTypes, ct as JSON_SCHEMA_TYPES, d as toPascalCase, dt as NOT_KEYWORD_UNSUPPORTED_MARKER, et as EFFECT_CODE_EXTENSION_KEYS, f as valibotError, ft as NUMBER_FORMATS, g as zodErrorPart, gt as OBJECT_PROTOTYPE_PROPERTIES, h as zodError, ht as NUMERIC_KEYWORDS, i as effectMessage, it as INPUT_EXTENSIONS, jt as VALIBOT_CODE_EXTENSION_KEYS, kt as UNICODE_ESCAPE_PATTERN, l as resolveOpenAPIRef, lt as MISSING_DEFINITION_PREFIX, m as zodBaseError, mt as NUMBER_WIRE_PATTERN, n as effectError, nt as IDENTIFIER_PATTERN, o as issueMessageExpression, ot as INTEGER_WIRE_PATTERN, p as valibotErrorPart, pt as NUMBER_RANGES, q as COMPONENT_SCHEMA_REF_PREFIX, r as effectErrorPart, rt as IF_THEN_ELSE_UNSUPPORTED_MARKER, s as makeSafeKey, st as ISO_4217_CURRENCY_CODES, t as coerceDefault, tt as FORMAT_PATTERNS, u as toIdentifierPascalCase, ut as NON_IDENTIFIER_CHARACTER_PATTERN, vt as OPENAPI_COMPONENT_SUFFIX_MAP, wt as STRINGBOOL_PATTERN, xt as PARAM_STYLES, yt as OUTPUT_EXTENSION } from "./utils-Bky98UmP.js";
2
- import { i as fmt, n as parseSchemaFile, r as FormatError, t as ParseError } from "./parser-CyJ2auea.js";
3
- import { n as ajv, t as schemaToAjv } from "./ajv-DS9gtNZC.js";
4
- import { n as arktype, t as schemaToArktype } from "./arktype-CRZ8vXZ5.js";
5
- import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-BkWovUi3.js";
6
- import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-wYeJqy7T.js";
7
- import { n as valibot, t as schemaToValibot } from "./valibot-DQUEDYKt.js";
8
- import { n as yup, t as schemaToYup } from "./yup-BMpa9Co1.js";
9
- import { n as zod, t as schemaToZod } from "./zod-Dq9LtqPL.js";
10
- export { ALL_CODE_EXTENSION_KEYS, ANCHOR_REF_PATTERN, ARKTYPE_CODE_EXTENSION_KEYS, ARROW_FUNCTION_PATTERN, COMPONENT_SCHEMA_REF_PREFIX, CONTENT_ENCODINGS, DATE_PATTERN_SOURCE, DEFAULT_ROOT_NAME, DEFINITION_KEYWORDS, DEFINITION_POINTER_PATTERN, DEFINITION_REF_PREFIXES, EFFECT_CODE_EXTENSION_KEYS, FORMAT_PATTERNS, FormatError, IDENTIFIER_PATTERN, IF_THEN_ELSE_UNSUPPORTED_MARKER, INPUT_EXTENSIONS, INTEGER_TEXT_PATTERN, INTEGER_WIRE_PATTERN, ISO_4217_CURRENCY_CODES, JSON_SCHEMA_TYPES, MISSING_DEFINITION_PREFIX, NON_IDENTIFIER_CHARACTER_PATTERN, NOT_KEYWORD_UNSUPPORTED_MARKER, NUMBER_FORMATS, NUMBER_RANGES, NUMBER_WIRE_PATTERN, NUMERIC_KEYWORDS, OBJECT_PROTOTYPE_PROPERTIES, OFFSET_PATTERN_SOURCE, OPENAPI_COMPONENT_SUFFIX_MAP, OUTPUT_EXTENSION, PARAM_LOCATIONS, PARAM_STYLES, ParseError, QUOTE_OR_BACKSLASH_PATTERN, ROOT_REFS, STRINGBOOL_PATTERN, STRINGBOOL_TRUTHY_PATTERN, STRING_FORMATS, STRING_KEYWORDS, STRING_WIRE_LOCATIONS, UNICODE_ESCAPE_PATTERN, UNSAFE_GENERATED_MARKER, VALIBOT_CODE_EXTENSION_KEYS, WIRE_PRIMITIVE_ORDER, ZOD_CODE_EXTENSION_KEYS, ajv, arktype, coerceDefault, effect, effectError, effectErrorPart, effectMessage, encodeNonAscii, fmt, issueMessageExpression, makeSafeKey, nestedTypeboxOptions, normalizeTypes, parseSchemaFile, resolveOpenAPIRef, schemaToAjv, schemaToArktype, schemaToEffect, schemaToTypebox, schemaToValibot, schemaToYup, schemaToZod, toIdentifierPascalCase, toPascalCase, typebox, valibot, valibotError, valibotErrorPart, wholeValueMessage, yup, zod, zodBaseError, zodError, zodErrorPart };
1
+ import { $t as COMPONENT_SCHEMA_REF_PREFIX, An as STRINGBOOL_PATTERN, Cn as OFFSET_PATTERN_SOURCE, Ct as valibotErrorPart, Dn as PARAM_STYLES, En as PARAM_LOCATIONS, Et as zodErrorPart, Fn as UNICODE_ESCAPE_PATTERN, In as UNSAFE_GENERATED_MARKER, Ln as VALIBOT_CODE_EXTENSION_KEYS, Mn as STRING_FORMATS, Nn as STRING_KEYWORDS, On as QUOTE_OR_BACKSLASH_PATTERN, Pn as STRING_WIRE_LOCATIONS, Qt as ARROW_FUNCTION_PATTERN, Rn as WIRE_PRIMITIVE_ORDER, Sn as OBJECT_PROTOTYPE_PROPERTIES, St as valibotError, Tn as OUTPUT_EXTENSION, Tt as zodError, Xt as ANCHOR_REF_PATTERN, Yt as ALL_CODE_EXTENSION_KEYS, Zt as ARKTYPE_CODE_EXTENSION_KEYS, _n as NOT_KEYWORD_UNSUPPORTED_MARKER, _t as makeSafeKey, an as DEFINITION_REF_PREFIXES, bn as NUMBER_WIRE_PATTERN, bt as toIdentifierPascalCase, cn as IDENTIFIER_PATTERN, dn as INTEGER_TEXT_PATTERN, dt as coerceDefault, en as CONTENT_ENCODINGS, fn as INTEGER_WIRE_PATTERN, ft as effectError, gn as NON_IDENTIFIER_CHARACTER_PATTERN, gt as issueMessageExpression, hn as MISSING_DEFINITION_PREFIX, ht as encodeNonAscii, in as DEFINITION_POINTER_PATTERN, jn as STRINGBOOL_TRUTHY_PATTERN, kn as ROOT_REFS, ln as IF_THEN_ELSE_UNSUPPORTED_MARKER, mn as JSON_SCHEMA_TYPES, mt as effectMessage, nn as DEFAULT_ROOT_NAME, on as EFFECT_CODE_EXTENSION_KEYS, pn as ISO_4217_CURRENCY_CODES, pt as effectErrorPart, rn as DEFINITION_KEYWORDS, sn as FORMAT_PATTERNS, tn as DATE_PATTERN_SOURCE, un as INPUT_EXTENSIONS, vn as NUMBER_FORMATS, vt as normalizeTypes, wn as OPENAPI_COMPONENT_SUFFIX_MAP, wt as zodBaseError, xn as NUMERIC_KEYWORDS, xt as toPascalCase, yn as NUMBER_RANGES, yt as resolveOpenAPIRef, zn as ZOD_CODE_EXTENSION_KEYS } from "./helper-WSNbEQKr.js";
2
+ import { i as fmt, n as parseSchemaFile, r as FormatError, t as ParseError } from "./parser-RBrkz7ZL.js";
3
+ import { n as ajv, t as schemaToAjv } from "./ajv-DejgT2o1.js";
4
+ import { n as arktype, t as schemaToArktype } from "./arktype-CzTltPwP.js";
5
+ import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-Dj8qARFi.js";
6
+ import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-RAJnIZwI.js";
7
+ import { n as valibot, t as schemaToValibot } from "./valibot-CLUhG6tp.js";
8
+ import { n as yup, t as schemaToYup } from "./yup-DfE_ofEu.js";
9
+ import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-BhYAQ3iW.js";
10
+ export { ALL_CODE_EXTENSION_KEYS, ANCHOR_REF_PATTERN, ARKTYPE_CODE_EXTENSION_KEYS, ARROW_FUNCTION_PATTERN, COMPONENT_SCHEMA_REF_PREFIX, CONTENT_ENCODINGS, DATE_PATTERN_SOURCE, DEFAULT_ROOT_NAME, DEFINITION_KEYWORDS, DEFINITION_POINTER_PATTERN, DEFINITION_REF_PREFIXES, EFFECT_CODE_EXTENSION_KEYS, FORMAT_PATTERNS, FormatError, IDENTIFIER_PATTERN, IF_THEN_ELSE_UNSUPPORTED_MARKER, INPUT_EXTENSIONS, INTEGER_TEXT_PATTERN, INTEGER_WIRE_PATTERN, ISO_4217_CURRENCY_CODES, JSON_SCHEMA_TYPES, MISSING_DEFINITION_PREFIX, NON_IDENTIFIER_CHARACTER_PATTERN, NOT_KEYWORD_UNSUPPORTED_MARKER, NUMBER_FORMATS, NUMBER_RANGES, NUMBER_WIRE_PATTERN, NUMERIC_KEYWORDS, OBJECT_PROTOTYPE_PROPERTIES, OFFSET_PATTERN_SOURCE, OPENAPI_COMPONENT_SUFFIX_MAP, OUTPUT_EXTENSION, PARAM_LOCATIONS, PARAM_STYLES, ParseError, QUOTE_OR_BACKSLASH_PATTERN, ROOT_REFS, STRINGBOOL_PATTERN, STRINGBOOL_TRUTHY_PATTERN, STRING_FORMATS, STRING_KEYWORDS, STRING_WIRE_LOCATIONS, UNICODE_ESCAPE_PATTERN, UNSAFE_GENERATED_MARKER, VALIBOT_CODE_EXTENSION_KEYS, WIRE_PRIMITIVE_ORDER, ZOD_CODE_EXTENSION_KEYS, ajv, arktype, coerceDefault, effect, effectError, effectErrorPart, effectMessage, encodeNonAscii, fmt, forwardIssue, issueMessageExpression, makeSafeKey, nestedIssueMessageWrap, nestedTypeboxOptions, normalizeTypes, parseSchemaFile, resolveOpenAPIRef, schemaToAjv, schemaToArktype, schemaToEffect, schemaToTypebox, schemaToValibot, schemaToYup, schemaToZod, toIdentifierPascalCase, toPascalCase, typebox, valibot, valibotError, valibotErrorPart, wholeValueMessage, yup, zod, zodBaseError, zodError, zodErrorPart };
@@ -2,7 +2,7 @@ import * as Data from "effect/Data";
2
2
  import * as Effect from "effect/Effect";
3
3
  import { format } from "oxfmt";
4
4
  import { bundle } from "@apidevtools/json-schema-ref-parser";
5
- //#region src/format/index.ts
5
+ // src/format/index.ts
6
6
  /** oxfmt rejected the source it was handed. */
7
7
  var FormatError = class extends Data.TaggedError("FormatError") {};
8
8
  const FMT_OPTIONS = {
@@ -21,8 +21,7 @@ function fmt(input) {
21
21
  return code;
22
22
  });
23
23
  }
24
- //#endregion
25
- //#region src/parser/index.ts
24
+ // src/parser/index.ts
26
25
  /** The document could not be bundled as a JSON Schema. */
27
26
  var ParseError = class extends Data.TaggedError("ParseError") {};
28
27
  /** The bundled document at `input`. Failures land in the error channel. */
@@ -32,5 +31,4 @@ function parseSchemaFile(input) {
32
31
  catch: (error) => new ParseError({ message: `Failed to parse schema: ${error instanceof Error ? error.message : String(error)}` })
33
32
  });
34
33
  }
35
- //#endregion
36
34
  export { fmt as i, parseSchemaFile as n, FormatError as r, ParseError as t };
@@ -1,6 +1,5 @@
1
- import { $ as DEFINITION_REF_PREFIXES, C as hasNumericKeyword, D as isComposite, H as isStringWireLocation, M as isNullable, O as isDeepLocalPointer, R as isRootRef, S as hasFixedLength, V as isShapelessMember, X as DEFAULT_ROOT_NAME, c as normalizeTypes, dt as NOT_KEYWORD_UNSUPPORTED_MARKER, j as isNullTypeMember, k as isDefaultOnlyMember, l as resolveOpenAPIRef, s as makeSafeKey, w as hasStringKeyword, y as hasCombinator } from "./utils-Bky98UmP.js";
2
- import { $ as hasNotKeyword, D as stringboolTruthyPattern, E as stringboolPattern, G as schemaNamer, H as planDocument, I as typeboxDefaultOpt, J as isOptionalByDefault, K as cyclicDefinitionNames, L as typeboxMetaOpts, R as typeboxRefOpt, U as renderDefinitions, V as missingDefinitionComment, W as rootNameOf, Y as itemsSchemaOf, a as typeboxWrap, b as integerWirePattern, c as withPolymorphicBases, g as hoistNestedRefs, it as patternSource, nt as foldAllOfMembers, q as hasRootSelfReference, rt as isKeywordOnlyMember, w as numberWirePattern } from "./helper-CbeedY35.js";
3
- //#region src/generator/typebox/enum.ts
1
+ import { At as hasFixedLength, B as typeboxRefOpt, D as stringboolPattern, Dt as hasCombinator, Ft as isComposite, G as renderDefinitions, Gt as isRootRef, H as emitOptionsOf, It as isDeepLocalPointer, J as discriminatedMembers, Jt as isStringWireLocation, K as rootNameOf, Lt as isDefaultOnlyMember, Mt as hasStringKeyword, O as stringboolTruthyPattern, Q as itemsSchemaOf, R as typeboxDefaultOpt, Rt as isNullTypeMember, T as numberWirePattern, U as missingDefinitionComment, V as definitionsOf, W as planDocument, X as hasRootSelfReference, Y as cyclicDefinitionNames, Z as isOptionalByDefault, _ as hoistNestedRefs, _n as NOT_KEYWORD_UNSUPPORTED_MARKER, _t as makeSafeKey, a as typeboxWrap, an as DEFINITION_REF_PREFIXES, ct as isKeywordOnlyMember, it as hasNotKeyword, jt as hasNumericKeyword, l as withPolymorphicBases, lt as patternSource, nn as DEFAULT_ROOT_NAME, q as schemaNamer, qt as isShapelessMember, s as sanitizeSchema, st as foldAllOfMembers, vt as normalizeTypes, x as integerWirePattern, yt as resolveOpenAPIRef, z as typeboxMetaOpts, zt as isNullable } from "./helper-WSNbEQKr.js";
2
+ // src/generator/typebox/enum.ts
4
3
  function lit(v) {
5
4
  if (v === null) return "null";
6
5
  if (typeof v === "string") return JSON.stringify(v);
@@ -29,8 +28,7 @@ function _enum(schema, ref) {
29
28
  if (schema.enum.length === 1) return schema.enum[0] === null ? `Type.Null(${optsParts.length > 0 ? `{${optsParts.join(",")}}` : ""})` : `Type.Literal(${lit(schema.enum[0])}${optsTrailer})`;
30
29
  return `Type.Union([${schema.enum.map(member).join(",")}]${optsTrailer})`;
31
30
  }
32
- //#endregion
33
- //#region src/generator/typebox/integer.ts
31
+ // src/generator/typebox/integer.ts
34
32
  function integer(schema, ref) {
35
33
  const errorMessage = schema["x-error-message"];
36
34
  const requiredMessage = schema["x-required-message"];
@@ -72,8 +70,7 @@ function integer(schema, ref) {
72
70
  if (opts.length > 0) return `Type.Integer({${opts.join(",")}})`;
73
71
  return "Type.Integer()";
74
72
  }
75
- //#endregion
76
- //#region src/generator/typebox/number.ts
73
+ // src/generator/typebox/number.ts
77
74
  function number(schema, ref) {
78
75
  const errorMessage = schema["x-error-message"];
79
76
  const requiredMessage = schema["x-required-message"];
@@ -104,8 +101,7 @@ function number(schema, ref) {
104
101
  if (opts.length > 0) return `Type.Number({${opts.join(",")}})`;
105
102
  return "Type.Number()";
106
103
  }
107
- //#endregion
108
- //#region src/generator/typebox/object.ts
104
+ // src/generator/typebox/object.ts
109
105
  /**
110
106
  * Generate a TypeBox object schema for a JSON Schema object node.
111
107
  *
@@ -123,7 +119,7 @@ function number(schema, ref) {
123
119
  function object(schema, rootName, isTypebox, options) {
124
120
  const childOptions = nestedTypeboxOptions(options);
125
121
  if (hasCombinator(schema)) return typebox(schema, rootName, isTypebox, options);
126
- if (typeof schema.additionalProperties === "object") {
122
+ if (typeof schema.additionalProperties === "object" && schema.properties === void 0 && schema.patternProperties === void 0) {
127
123
  const value = typebox(schema.additionalProperties, rootName, isTypebox, childOptions);
128
124
  const recordOpts = [
129
125
  ...typeboxRefOpt(options?.ref),
@@ -144,6 +140,7 @@ function object(schema, rootName, isTypebox, options) {
144
140
  }
145
141
  const emptyOpts = [
146
142
  ...typeboxRefOpt(options?.ref),
143
+ schema.additionalProperties === false ? "additionalProperties:false" : typeof schema.additionalProperties === "object" ? `additionalProperties:${typebox(schema.additionalProperties, rootName, isTypebox, childOptions)}` : void 0,
147
144
  ...buildAdvancedOpts(schema, rootName, isTypebox, childOptions),
148
145
  ...typeboxMetaOpts(schema),
149
146
  ...typeboxDefaultOpt(schema)
@@ -151,12 +148,13 @@ function object(schema, rootName, isTypebox, options) {
151
148
  return emptyOpts.length === 0 ? "Type.Object({})" : `Type.Object({},{${emptyOpts.join(",")}})`;
152
149
  }
153
150
  const required = new Set(schema.required);
154
- const props = Object.entries(schema.properties).map(([key, propSchema]) => {
151
+ const undeclaredRequired = (schema.required ?? []).filter((key) => !Object.hasOwn(schema.properties ?? {}, key)).map((key) => `${makeSafeKey(key)}:Type.Unknown()`);
152
+ const props = [...Object.entries(schema.properties).map(([key, propSchema]) => {
155
153
  const parsed = typebox(propSchema, rootName, isTypebox, childOptions);
156
154
  if (!parsed) return null;
157
155
  const safeKey = makeSafeKey(key);
158
- return required.has(key) || isOptionalByDefault(propSchema) ? `${safeKey}:${parsed}` : `${safeKey}:Type.Optional(${parsed})`;
159
- }).filter((p) => p !== null);
156
+ return required.has(key) || isOptionalByDefault(propSchema, options?.definitions) ? `${safeKey}:${parsed}` : `${safeKey}:Type.Optional(${parsed})`;
157
+ }).filter((p) => p !== null), ...undeclaredRequired];
160
158
  const objectErrorMessageEntries = [];
161
159
  const objectErrorMessage = schema["x-error-message"];
162
160
  if (objectErrorMessage) objectErrorMessageEntries.push(`type:${JSON.stringify(objectErrorMessage)}`);
@@ -188,7 +186,7 @@ function object(schema, rootName, isTypebox, options) {
188
186
  const objectErrorMessageField = objectErrorMessageEntries.length > 0 ? `errorMessage:{${objectErrorMessageEntries.join(",")}}` : void 0;
189
187
  const optParts = [
190
188
  ...typeboxRefOpt(options?.ref),
191
- schema.additionalProperties === false ? "additionalProperties:false" : void 0,
189
+ schema.additionalProperties === false ? "additionalProperties:false" : typeof schema.additionalProperties === "object" ? `additionalProperties:${typebox(schema.additionalProperties, rootName, isTypebox, childOptions)}` : void 0,
192
190
  ...buildAdvancedOpts(schema, rootName, isTypebox, childOptions),
193
191
  objectErrorMessageField,
194
192
  ...typeboxMetaOpts(schema),
@@ -209,6 +207,8 @@ function buildAdvancedOpts(schema, rootName, isTypebox, options) {
209
207
  const thenOpt = schema.then ? `then:${typebox(schema.then, rootName, isTypebox, options)}` : void 0;
210
208
  const elseOpt = schema.else ? `else:${typebox(schema.else, rootName, isTypebox, options)}` : void 0;
211
209
  const requiredOpt = !schema.properties && Array.isArray(schema.required) && schema.required.length > 0 ? `required:${JSON.stringify(schema.required)}` : void 0;
210
+ const unevaluated = schema.unevaluatedProperties;
211
+ const unevaluatedOpt = unevaluated === false ? "unevaluatedProperties:false" : typeof unevaluated === "object" ? `unevaluatedProperties:${typebox(unevaluated, rootName, isTypebox, options)}` : void 0;
212
212
  return [
213
213
  typeof schema.minProperties === "number" ? `minProperties:${schema.minProperties}` : void 0,
214
214
  typeof schema.maxProperties === "number" ? `maxProperties:${schema.maxProperties}` : void 0,
@@ -218,11 +218,11 @@ function buildAdvancedOpts(schema, rootName, isTypebox, options) {
218
218
  ifOpt,
219
219
  thenOpt,
220
220
  elseOpt,
221
- requiredOpt
221
+ requiredOpt,
222
+ unevaluatedOpt
222
223
  ];
223
224
  }
224
- //#endregion
225
- //#region src/generator/typebox/string.ts
225
+ // src/generator/typebox/string.ts
226
226
  const FORMAT_MAP = {
227
227
  email: "email",
228
228
  uuid: "uuid",
@@ -278,8 +278,7 @@ function string(schema, ref) {
278
278
  if (transforms.length > 0) return `Codec(${stringExpr}).Decode((value: string) => value${transforms.join("")}).Encode((value: string) => value)`;
279
279
  return stringExpr;
280
280
  }
281
- //#endregion
282
- //#region src/generator/typebox/typebox.ts
281
+ // src/generator/typebox/typebox.ts
283
282
  /**
284
283
  * Options for a nested TypeBox node: the same as `options` but without a
285
284
  * host `ref`, so only the outermost factory of a declaration receives it.
@@ -290,7 +289,8 @@ function nestedTypeboxOptions(options) {
290
289
  ...options.openapi !== void 0 && { openapi: options.openapi },
291
290
  ...options.readonly !== void 0 && { readonly: options.readonly },
292
291
  ...options.paramIn !== void 0 && { paramIn: options.paramIn },
293
- ...options.cyclicRefs !== void 0 && { cyclicRefs: options.cyclicRefs }
292
+ ...options.cyclicRefs !== void 0 && { cyclicRefs: options.cyclicRefs },
293
+ ...options.definitions !== void 0 && { definitions: options.definitions }
294
294
  };
295
295
  }
296
296
  /**
@@ -358,6 +358,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
358
358
  const readonly = (v) => options?.readonly ? `Type.Readonly(${v})` : v;
359
359
  const hostRef = options?.ref;
360
360
  const childOptions = nestedTypeboxOptions(options);
361
+ const definitions = options?.definitions;
361
362
  const named = (name, s) => options?.cyclicRefs?.has(name) ? byName(name, s) : name;
362
363
  if (schema.$ref) {
363
364
  const ref = (s) => {
@@ -380,13 +381,27 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
380
381
  }
381
382
  return "Type.Any()";
382
383
  };
384
+ const withDefault = (s) => {
385
+ const defaultOpt = typeboxDefaultOpt(s, false, definitions);
386
+ const target = ref(s);
387
+ const inner = defaultOpt.length === 0 ? target : `Type.Intersect([${target}],{${defaultOpt.join(",")}})`;
388
+ return typeboxWrap(inner, s, definitions);
389
+ };
383
390
  const items = itemsSchemaOf(schema.items);
384
- if (schema.type === "array" && items?.$ref) return `Type.Array(${typeboxWrap(ref(items), items)})`;
385
- return typeboxWrap(ref(schema), schema);
391
+ if (schema.type === "array" && items?.$ref) return `Type.Array(${withDefault(items)})`;
392
+ return withDefault(schema);
386
393
  }
387
394
  if (schema.oneOf) {
388
395
  if (schema.oneOf.length === 0) return typeboxWrap(tbPrim("Type.Any", schema, [], hostRef), schema);
389
- const schemas = schema.oneOf.map((s) => typebox(s, rootName, isTypebox, childOptions));
396
+ const discriminated = discriminatedMembers(schema, schema.oneOf);
397
+ const schemas = schema.oneOf.map((s, i) => {
398
+ const member = typebox(s, rootName, isTypebox, childOptions);
399
+ const values = discriminated?.members[i]?.values;
400
+ if (discriminated === void 0 || values === void 0) return member;
401
+ const literals = values.map((value) => `Type.Literal(${JSON.stringify(value)})`);
402
+ const literal = literals.length === 1 ? literals[0] : `Type.Union([${literals.join(",")}])`;
403
+ return `Type.Intersect([${member},Type.Object({${makeSafeKey(discriminated.propertyName)}:${literal}})])`;
404
+ });
390
405
  return typeboxWrap(tbComp("Type.Union", `[${schemas.join(",")}]`, schema, messageOpt(schema["x-oneOf-message"]), hostRef), schema);
391
406
  }
392
407
  if (schema.anyOf) {
@@ -405,22 +420,20 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
405
420
  nullable
406
421
  });
407
422
  const unevaluated = schema.unevaluatedProperties;
408
- const unevaluatedOpt = unevaluated === false ? ["unevaluatedProperties:false"] : typeof unevaluated === "object" && unevaluated !== null ? [`unevaluatedProperties:${typebox(unevaluated, rootName, isTypebox, childOptions)}`] : [];
409
- const baseResult = schemas.length === 1 && unevaluatedOpt.length === 0 ? schemas[0] : tbComp("Type.Intersect", `[${schemas.join(",")}]`, schema, [...messageOpt(schema["x-allOf-message"]), ...unevaluatedOpt], hostRef);
410
- if (defaultValue !== void 0) {
411
- const formatLiteral = typeof defaultValue === "boolean" || typeof defaultValue === "number" ? `${defaultValue}` : JSON.stringify(defaultValue);
412
- const intersectOpts = [
413
- ...typeboxRefOpt(hostRef),
414
- ...messageOpt(schema["x-allOf-message"]),
415
- `default:${formatLiteral}`
416
- ];
417
- const withDefault = `Type.Optional(${`Type.Intersect([${schemas.join(",")}],{${intersectOpts.join(",")}})`})`;
418
- return nullable ? `Type.Union([${withDefault},Type.Null()])` : withDefault;
419
- }
420
- return typeboxWrap(baseResult, {
421
- ...schema,
422
- nullable
423
- });
423
+ const unevaluatedOpt = [...schema.patternProperties === void 0 ? [] : [`patternProperties:{${Object.entries(schema.patternProperties).map(([pattern, propSchema]) => `${JSON.stringify(pattern)}:${typebox(propSchema, rootName, isTypebox, childOptions)}`).join(",")}}`], ...unevaluated === false ? ["unevaluatedProperties:false"] : typeof unevaluated === "object" && unevaluated !== null ? [`unevaluatedProperties:${typebox(unevaluated, rootName, isTypebox, childOptions)}`] : []];
424
+ const { default: ownDefault, ...withoutDefault } = schema;
425
+ const withMergedDefault = {
426
+ ...withoutDefault,
427
+ nullable,
428
+ ...defaultValue !== void 0 ? { default: defaultValue } : ownDefault !== void 0 && { default: ownDefault }
429
+ };
430
+ const defaultOpt = typeboxDefaultOpt(withMergedDefault, false, definitions);
431
+ const baseResult = schemas.length === 1 && unevaluatedOpt.length === 0 && defaultOpt.length === 0 ? schemas[0] : tbComp("Type.Intersect", `[${schemas.join(",")}]`, withoutDefault, [
432
+ ...messageOpt(schema["x-allOf-message"]),
433
+ ...unevaluatedOpt,
434
+ ...defaultOpt
435
+ ], hostRef);
436
+ return typeboxWrap(baseResult, withMergedDefault, definitions);
424
437
  }
425
438
  if (schema.not) return typeboxWrap(tbPrim("Type.Any", schema, messageOpt(schema["x-not-message"]), hostRef), schema);
426
439
  if (schema.const !== void 0) {
@@ -502,8 +515,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
502
515
  if (typeof schema.additionalProperties === "object") return readonly(typeboxWrap(object(schema, rootName, isTypebox, options), schema));
503
516
  return typeboxWrap(tbPrim("Type.Any", schema, [], hostRef), schema);
504
517
  }
505
- //#endregion
506
- //#region src/generator/typebox/index.ts
518
+ // src/generator/typebox/index.ts
507
519
  /** The import line, carrying `Codec` only when the emitted source calls it. */
508
520
  function importLine(emitted) {
509
521
  return `import { ${emitted.includes("Codec(") ? "Codec, " : ""}Type, type Static } from 'typebox'`;
@@ -514,23 +526,25 @@ function importLine(emitted) {
514
526
  * `Type.Cyclic($defs, root)` map instead.
515
527
  */
516
528
  function schemaToTypebox(input, options) {
517
- const schema = withPolymorphicBases(hoistNestedRefs(input));
529
+ const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
518
530
  const exportType = options?.exportType ?? true;
519
531
  const openapi = options?.openapi ?? false;
520
532
  const hostRef = options?.ref;
533
+ const toName = schemaNamer(openapi);
534
+ const plan = planDocument(schema, rootNameOf(schema, toName));
535
+ const { rootName } = plan;
536
+ const definitions = definitionsOf(emitOptionsOf(options), plan.definitions);
521
537
  const genOptions = {
522
538
  openapi,
523
539
  readonly: options?.readonly ?? false,
524
- ...options?.paramIn !== void 0 && { paramIn: options.paramIn }
540
+ ...options?.paramIn !== void 0 && { paramIn: options.paramIn },
541
+ ...definitions !== void 0 && { definitions }
525
542
  };
526
543
  const rootOptions = hostRef === void 0 ? genOptions : {
527
544
  ...genOptions,
528
545
  ref: hostRef
529
546
  };
530
547
  const notKeywordPresent = hasNotKeyword(schema);
531
- const toName = schemaNamer(openapi);
532
- const plan = planDocument(schema, rootNameOf(schema, toName));
533
- const { rootName } = plan;
534
548
  if (hasRootSelfReference(plan.root, (ref) => isRootRef(ref) || openapi && resolveOpenAPIRef(ref) === rootName) || cyclicDefinitionNames(schema).size > 0) {
535
549
  const cyclicRefs = /* @__PURE__ */ new Set([...plan.orderedNames.map(toName), rootName]);
536
550
  const cyclicOptions = {
@@ -559,5 +573,4 @@ function schemaToTypebox(input, options) {
559
573
  ...exportType ? [`export type ${rootName} = Static<typeof ${rootName}>`] : []
560
574
  ].filter(Boolean).join("\n\n");
561
575
  }
562
- //#endregion
563
576
  export { nestedTypeboxOptions as n, typebox as r, schemaToTypebox as t };
package/dist/typebox.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { r as JSONSchema } from "./index-G7UqNQ4w.js";
2
- import { n as GenerateOptions } from "./index-DYzAccyT.js";
3
- //#region src/generator/typebox/index.d.ts
1
+ import { r as JSONSchema } from "./index-DLVjyrKu.js";
2
+ import { n as GenerateOptions } from "./index-DU2Nd8eI.js";
4
3
  /** The options of `schemaToTypebox`: the common ones, plus a host `$ref` name. */
5
4
  export type TypeboxGenerateOptions = Omit<GenerateOptions, 'unsafeCodeExtensions'> & {
6
5
  /**
@@ -17,5 +16,4 @@ export type TypeboxGenerateOptions = Omit<GenerateOptions, 'unsafeCodeExtensions
17
16
  * with plain `const` declarations, so a cyclic document becomes one
18
17
  * `Type.Cyclic($defs, root)` map instead.
19
18
  */
20
- export declare function schemaToTypebox(input: JSONSchema, options?: TypeboxGenerateOptions): string;
21
- //#endregion
19
+ export declare function schemaToTypebox(input: JSONSchema, options?: TypeboxGenerateOptions): string;
package/dist/typebox.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToTypebox } from "./typebox-wYeJqy7T.js";
1
+ export { t as schemaToTypebox } from "./typebox-RAJnIZwI.js";