schema-truth 0.8.2 → 0.8.4
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 +2 -2
- package/dist/{ajv-DS9gtNZC.js → ajv-DejgT2o1.js} +8 -14
- package/dist/ajv.d.ts +2 -4
- package/dist/ajv.js +1 -1
- package/dist/{arktype-CBV4bg-0.js → arktype-CzTltPwP.js} +9 -17
- package/dist/arktype.d.ts +3 -5
- package/dist/arktype.js +1 -1
- package/dist/cli/ajv.d.ts +0 -0
- package/dist/cli/ajv.js +3 -4
- package/dist/cli/arktype.d.ts +0 -0
- package/dist/cli/arktype.js +3 -4
- package/dist/cli/effect.d.ts +0 -0
- package/dist/cli/effect.js +3 -4
- package/dist/cli/typebox.d.ts +0 -0
- package/dist/cli/typebox.js +3 -4
- package/dist/cli/valibot.d.ts +0 -0
- package/dist/cli/valibot.js +3 -4
- package/dist/cli/yup.d.ts +0 -0
- package/dist/cli/yup.js +3 -4
- package/dist/cli/zod.d.ts +0 -0
- package/dist/cli/zod.js +3 -4
- package/dist/{cli-CB9GJ7qa.js → cli-CGTme770.js} +6 -9
- package/dist/{effect-D9pvwi_6.js → effect-Dj8qARFi.js} +21 -22
- package/dist/effect.d.ts +3 -5
- package/dist/effect.js +1 -1
- package/dist/{helper-S7SSsYwh.js → helper-WSNbEQKr.js} +1344 -52
- package/dist/{index-G7UqNQ4w.d.ts → index-DLVjyrKu.d.ts} +0 -14
- package/dist/{index-EK43HM_z.d.ts → index-DU2Nd8eI.d.ts} +1 -5
- package/dist/index.d.ts +2 -20
- package/dist/index.js +9 -9
- package/dist/{parser-CyJ2auea.js → parser-RBrkz7ZL.js} +2 -4
- package/dist/{typebox-DGGKJLdP.js → typebox-RAJnIZwI.js} +9 -17
- package/dist/typebox.d.ts +3 -5
- package/dist/typebox.js +1 -1
- package/dist/{valibot-B6y4VQFF.js → valibot-CLUhG6tp.js} +12 -21
- package/dist/valibot.d.ts +3 -5
- package/dist/valibot.js +1 -1
- package/dist/{yup-DuqQwHUv.js → yup-DfE_ofEu.js} +9 -15
- package/dist/yup.d.ts +3 -5
- package/dist/yup.js +1 -1
- package/dist/{zod-CXo9NFuF.js → zod-BhYAQ3iW.js} +12 -22
- package/dist/zod.d.ts +3 -5
- package/dist/zod.js +1 -1
- package/package.json +17 -15
- package/dist/utils-Bky98UmP.js +0 -1146
|
@@ -1,5 +1,1146 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/constants/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* The values the generators agree on: every list of literals, every prefix and every
|
|
4
|
+
* pattern that more than one module reads. Types that mirror a list are derived from it in
|
|
5
|
+
* `parser/index.ts`, so adding a member here is the whole change.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The `type` values a JSON Schema node may carry, in the order the specification lists
|
|
9
|
+
* them. `date` is not a JSON Schema type: it is the extension the generators accept for a
|
|
10
|
+
* `Date`-typed value (Zod `z.date()`, Valibot `v.date()`).
|
|
11
|
+
*
|
|
12
|
+
* @see https://json-schema.org/understanding-json-schema/reference/type
|
|
13
|
+
*/
|
|
14
|
+
const JSON_SCHEMA_TYPES = [
|
|
15
|
+
"string",
|
|
16
|
+
"number",
|
|
17
|
+
"integer",
|
|
18
|
+
"boolean",
|
|
19
|
+
"array",
|
|
20
|
+
"object",
|
|
21
|
+
"null",
|
|
22
|
+
"date"
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* The `format` values a string node may carry: the JSON Schema built-ins, the OpenAPI
|
|
26
|
+
* data-type formats, and the names the target libraries add (`uuidv7`, `cuid2`, `jwt`,
|
|
27
|
+
* `hash`, ...). A format a target has no equivalent for is a no-op there.
|
|
28
|
+
*
|
|
29
|
+
* @see https://json-schema.org/understanding-json-schema/reference/string#built-in-formats
|
|
30
|
+
* @see https://zod.dev/api#strings
|
|
31
|
+
*/
|
|
32
|
+
const STRING_FORMATS = [
|
|
33
|
+
"date-time",
|
|
34
|
+
"date",
|
|
35
|
+
"time",
|
|
36
|
+
"duration",
|
|
37
|
+
"email",
|
|
38
|
+
"idn-email",
|
|
39
|
+
"hostname",
|
|
40
|
+
"idn-hostname",
|
|
41
|
+
"ipv4",
|
|
42
|
+
"ipv6",
|
|
43
|
+
"uri",
|
|
44
|
+
"uri-reference",
|
|
45
|
+
"iri",
|
|
46
|
+
"iri-reference",
|
|
47
|
+
"uuid",
|
|
48
|
+
"uri-template",
|
|
49
|
+
"json-pointer",
|
|
50
|
+
"relative-json-pointer",
|
|
51
|
+
"regex",
|
|
52
|
+
"binary",
|
|
53
|
+
"byte",
|
|
54
|
+
"password",
|
|
55
|
+
"url",
|
|
56
|
+
"httpUrl",
|
|
57
|
+
"uuidv4",
|
|
58
|
+
"uuidv6",
|
|
59
|
+
"uuidv7",
|
|
60
|
+
"guid",
|
|
61
|
+
"emoji",
|
|
62
|
+
"base64",
|
|
63
|
+
"base64url",
|
|
64
|
+
"hex",
|
|
65
|
+
"nanoid",
|
|
66
|
+
"cuid",
|
|
67
|
+
"cuid2",
|
|
68
|
+
"ulid",
|
|
69
|
+
"ksuid",
|
|
70
|
+
"xid",
|
|
71
|
+
"ip",
|
|
72
|
+
"cidrv4",
|
|
73
|
+
"cidrv6",
|
|
74
|
+
"mac",
|
|
75
|
+
"jwt",
|
|
76
|
+
"hash",
|
|
77
|
+
"e164",
|
|
78
|
+
"creditCard",
|
|
79
|
+
"iban",
|
|
80
|
+
"currencyCode",
|
|
81
|
+
"httpurl",
|
|
82
|
+
"creditcard",
|
|
83
|
+
"currencycode",
|
|
84
|
+
"toLowerCase",
|
|
85
|
+
"toUpperCase",
|
|
86
|
+
"trim",
|
|
87
|
+
"slugify"
|
|
88
|
+
];
|
|
89
|
+
/**
|
|
90
|
+
* The `format` values a numeric node may carry: the OpenAPI data-type formats plus the
|
|
91
|
+
* widths the target libraries distinguish (`int32`, `float32`, `bigint`, ...).
|
|
92
|
+
*
|
|
93
|
+
* @see https://spec.openapis.org/oas/v3.1.0#data-types
|
|
94
|
+
*/
|
|
95
|
+
const NUMBER_FORMATS = [
|
|
96
|
+
"int32",
|
|
97
|
+
"uint32",
|
|
98
|
+
"int64",
|
|
99
|
+
"uint64",
|
|
100
|
+
"bigint",
|
|
101
|
+
"float",
|
|
102
|
+
"float32",
|
|
103
|
+
"float64",
|
|
104
|
+
"double",
|
|
105
|
+
"decimal"
|
|
106
|
+
];
|
|
107
|
+
/**
|
|
108
|
+
* The `contentEncoding` values of a string node.
|
|
109
|
+
*
|
|
110
|
+
* @see https://json-schema.org/draft/2020-12/json-schema-validation#section-8.3
|
|
111
|
+
*/
|
|
112
|
+
const CONTENT_ENCODINGS = [
|
|
113
|
+
"base64",
|
|
114
|
+
"base64url",
|
|
115
|
+
"binary",
|
|
116
|
+
"7bit",
|
|
117
|
+
"8bit",
|
|
118
|
+
"quoted-printable"
|
|
119
|
+
];
|
|
120
|
+
/**
|
|
121
|
+
* The OpenAPI parameter locations, plus `formData` for the fields of an
|
|
122
|
+
* `application/x-www-form-urlencoded` or `multipart/form-data` body. Every one of them is
|
|
123
|
+
* string-wire: a primitive schema emitted under one of them is coerced from a string.
|
|
124
|
+
*
|
|
125
|
+
* @see https://spec.openapis.org/oas/v3.2.0.html#parameter-object
|
|
126
|
+
*/
|
|
127
|
+
const PARAM_LOCATIONS = [
|
|
128
|
+
"query",
|
|
129
|
+
"path",
|
|
130
|
+
"header",
|
|
131
|
+
"cookie",
|
|
132
|
+
"formData"
|
|
133
|
+
];
|
|
134
|
+
/** The parameter locations whose values arrive as strings and are coerced. */
|
|
135
|
+
const STRING_WIRE_LOCATIONS = [
|
|
136
|
+
"query",
|
|
137
|
+
"path",
|
|
138
|
+
"header",
|
|
139
|
+
"cookie",
|
|
140
|
+
"formData"
|
|
141
|
+
];
|
|
142
|
+
/**
|
|
143
|
+
* The `type` values a value on the wire is coerced to, in the order a union tries them:
|
|
144
|
+
* the text `1` is an integer before it is a number, and a string last of all.
|
|
145
|
+
*/
|
|
146
|
+
const WIRE_PRIMITIVE_ORDER = [
|
|
147
|
+
"integer",
|
|
148
|
+
"number",
|
|
149
|
+
"boolean",
|
|
150
|
+
"string"
|
|
151
|
+
];
|
|
152
|
+
/**
|
|
153
|
+
* The spellings of a boolean on the wire, as Zod's `z.stringbool()` reads them: `true`,
|
|
154
|
+
* `1`, `yes`, `on`, `y`, `enabled` and their opposites, in any case.
|
|
155
|
+
*/
|
|
156
|
+
const STRINGBOOL_PATTERN = /^(?:true|1|yes|on|y|enabled|false|0|no|off|n|disabled)$/i;
|
|
157
|
+
/** The spellings of {@link STRINGBOOL_PATTERN} that read as `true`. */
|
|
158
|
+
const STRINGBOOL_TRUTHY_PATTERN = /^(?:true|1|yes|on|y|enabled)$/i;
|
|
159
|
+
/** The text of a 64-bit integer: a sign and digits, which `BigInt` reads losslessly. */
|
|
160
|
+
const INTEGER_TEXT_PATTERN = /^-?\d+$/;
|
|
161
|
+
/**
|
|
162
|
+
* Integer text on the string wire. A sign and digits, with no leading zero, no exponent
|
|
163
|
+
* and no fraction: `Number` and `parseInt` both accept more than this (`""`, `" "`,
|
|
164
|
+
* `"0x10"`, `"1e3"`, `"1.9xyz"`).
|
|
165
|
+
*/
|
|
166
|
+
const INTEGER_WIRE_PATTERN = /^-?(?:0|[1-9]\d*)$/;
|
|
167
|
+
/**
|
|
168
|
+
* Number text on the string wire: the JSON number grammar (RFC 8259). An exponent is a
|
|
169
|
+
* number (`1e3`) and is not an integer. Blank, hex and trailing junk are not numbers.
|
|
170
|
+
*/
|
|
171
|
+
const NUMBER_WIRE_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
|
|
172
|
+
/** The range of each fixed-width numeric format, as the literals the generators emit. */
|
|
173
|
+
const NUMBER_RANGES = {
|
|
174
|
+
int32: {
|
|
175
|
+
minimum: "-2147483648",
|
|
176
|
+
maximum: "2147483647"
|
|
177
|
+
},
|
|
178
|
+
uint32: {
|
|
179
|
+
minimum: "0",
|
|
180
|
+
maximum: "4294967295"
|
|
181
|
+
},
|
|
182
|
+
int64: {
|
|
183
|
+
minimum: "-9223372036854775808n",
|
|
184
|
+
maximum: "9223372036854775807n"
|
|
185
|
+
},
|
|
186
|
+
uint64: {
|
|
187
|
+
minimum: "0n",
|
|
188
|
+
maximum: "18446744073709551615n"
|
|
189
|
+
},
|
|
190
|
+
float32: {
|
|
191
|
+
minimum: "-3.4028234663852886e38",
|
|
192
|
+
maximum: "3.4028234663852886e38"
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* The `style` values of an OpenAPI Parameter Object: how the parameter's text maps onto its
|
|
197
|
+
* schema.
|
|
198
|
+
*
|
|
199
|
+
* @see https://spec.openapis.org/oas/v3.2.0.html#style-values
|
|
200
|
+
*/
|
|
201
|
+
const PARAM_STYLES = [
|
|
202
|
+
"matrix",
|
|
203
|
+
"label",
|
|
204
|
+
"simple",
|
|
205
|
+
"form",
|
|
206
|
+
"spaceDelimited",
|
|
207
|
+
"pipeDelimited",
|
|
208
|
+
"deepObject"
|
|
209
|
+
];
|
|
210
|
+
/**
|
|
211
|
+
* The properties every plain object inherits from `Object.prototype`. A parameter object
|
|
212
|
+
* read from a request answers these even when the request did not send them.
|
|
213
|
+
*/
|
|
214
|
+
const OBJECT_PROTOTYPE_PROPERTIES = [
|
|
215
|
+
"__proto__",
|
|
216
|
+
"__defineGetter__",
|
|
217
|
+
"__defineSetter__",
|
|
218
|
+
"__lookupGetter__",
|
|
219
|
+
"__lookupSetter__",
|
|
220
|
+
"constructor",
|
|
221
|
+
"hasOwnProperty",
|
|
222
|
+
"isPrototypeOf",
|
|
223
|
+
"propertyIsEnumerable",
|
|
224
|
+
"toLocaleString",
|
|
225
|
+
"toString",
|
|
226
|
+
"valueOf"
|
|
227
|
+
];
|
|
228
|
+
/**
|
|
229
|
+
* The string formats checked with a regular expression where a target has no validator
|
|
230
|
+
* of its own, keyed by the lower-cased format. The patterns are Zod's, so every target
|
|
231
|
+
* accepts and rejects the same text.
|
|
232
|
+
*
|
|
233
|
+
* @see https://github.com/colinhacks/zod/blob/main/packages/zod/src/v4/core/regexes.ts
|
|
234
|
+
*/
|
|
235
|
+
const FORMAT_PATTERNS = {
|
|
236
|
+
guid: /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,
|
|
237
|
+
cuid: /^[cC][0-9a-z]{6,}$/,
|
|
238
|
+
cuid2: /^[0-9a-z]+$/,
|
|
239
|
+
ulid: /^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,
|
|
240
|
+
xid: /^[0-9a-vA-V]{20}$/,
|
|
241
|
+
ksuid: /^[A-Za-z0-9]{27}$/,
|
|
242
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
243
|
+
duration: /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,
|
|
244
|
+
emoji: /^[\p{Extended_Pictographic}\p{Emoji_Component}]+$/u,
|
|
245
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
246
|
+
ipv6: /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,
|
|
247
|
+
mac: /^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$/,
|
|
248
|
+
cidrv4: /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,
|
|
249
|
+
cidrv6: /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
250
|
+
base64: /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,
|
|
251
|
+
base64url: /^[A-Za-z0-9_-]*$/,
|
|
252
|
+
hostname: /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,
|
|
253
|
+
e164: /^\+[1-9]\d{6,14}$/,
|
|
254
|
+
hex: /^[0-9a-fA-F]*$/
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* The source of an RFC 3339 `full-date` that is a real calendar date: the month decides
|
|
258
|
+
* the days, and February 29 needs a leap year.
|
|
259
|
+
*/
|
|
260
|
+
const DATE_PATTERN_SOURCE = String.raw`(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))`;
|
|
261
|
+
/** The source of a UTC offset: `Z`, or a signed `hh:mm`. */
|
|
262
|
+
const OFFSET_PATTERN_SOURCE = String.raw`(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)`;
|
|
263
|
+
/** The keywords that only constrain a number: on their own they imply `type: number`. */
|
|
264
|
+
const NUMERIC_KEYWORDS = [
|
|
265
|
+
"minimum",
|
|
266
|
+
"maximum",
|
|
267
|
+
"exclusiveMinimum",
|
|
268
|
+
"exclusiveMaximum",
|
|
269
|
+
"multipleOf"
|
|
270
|
+
];
|
|
271
|
+
/** The keywords that only constrain a string: on their own they imply `type: string`. */
|
|
272
|
+
const STRING_KEYWORDS = [
|
|
273
|
+
"minLength",
|
|
274
|
+
"maxLength",
|
|
275
|
+
"pattern"
|
|
276
|
+
];
|
|
277
|
+
/**
|
|
278
|
+
* The keywords that hold a document's named definitions: `$defs` since Draft 2019-09, and
|
|
279
|
+
* `definitions` before it. A document may use both, and the generators read them as one map.
|
|
280
|
+
*/
|
|
281
|
+
const DEFINITION_KEYWORDS = ["definitions", "$defs"];
|
|
282
|
+
/** The `$ref` spellings of the whole document: the schema being emitted refers to itself. */
|
|
283
|
+
const ROOT_REFS = ["#", ""];
|
|
284
|
+
/** The `$ref` prefixes under which a named definition is found. */
|
|
285
|
+
const DEFINITION_REF_PREFIXES = [
|
|
286
|
+
"#/components/schemas/",
|
|
287
|
+
"#/definitions/",
|
|
288
|
+
"#/$defs/"
|
|
289
|
+
];
|
|
290
|
+
/** The `$ref` prefix of an OpenAPI component schema. */
|
|
291
|
+
const COMPONENT_SCHEMA_REF_PREFIX = "#/components/schemas/";
|
|
292
|
+
/**
|
|
293
|
+
* The variable-name suffix of each OpenAPI component kind, by its `$ref` prefix.
|
|
294
|
+
*
|
|
295
|
+
* @see https://swagger.io/docs/specification/v3_0/components/
|
|
296
|
+
*/
|
|
297
|
+
const OPENAPI_COMPONENT_SUFFIX_MAP = [
|
|
298
|
+
{
|
|
299
|
+
prefix: "#/components/schemas/",
|
|
300
|
+
suffix: "Schema"
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
prefix: "#/components/parameters/",
|
|
304
|
+
suffix: "ParamsSchema"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
prefix: "#/components/headers/",
|
|
308
|
+
suffix: "HeaderSchema"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
prefix: "#/components/securitySchemes/",
|
|
312
|
+
suffix: "SecurityScheme"
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
prefix: "#/components/requestBodies/",
|
|
316
|
+
suffix: "RequestBody"
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
prefix: "#/components/responses/",
|
|
320
|
+
suffix: "Response"
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
prefix: "#/components/examples/",
|
|
324
|
+
suffix: "Example"
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
prefix: "#/components/links/",
|
|
328
|
+
suffix: "Link"
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
prefix: "#/components/callbacks/",
|
|
332
|
+
suffix: "Callback"
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
prefix: "#/components/pathItems/",
|
|
336
|
+
suffix: "PathItem"
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
prefix: "#/components/mediaTypes/",
|
|
340
|
+
suffix: "MediaTypeSchema"
|
|
341
|
+
}
|
|
342
|
+
];
|
|
343
|
+
/** The name a root schema is exported under when the document has no `title`. */
|
|
344
|
+
const DEFAULT_ROOT_NAME = "Schema";
|
|
345
|
+
/** The extensions of an input document: a JSON Schema as JSON or YAML. */
|
|
346
|
+
const INPUT_EXTENSIONS = [".json", ".yaml"];
|
|
347
|
+
/** The extension of the generated file. */
|
|
348
|
+
const OUTPUT_EXTENSION = ".ts";
|
|
349
|
+
/** A JavaScript identifier that can be written bare: as a binding, or a key or member access. */
|
|
350
|
+
const IDENTIFIER_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
351
|
+
/**
|
|
352
|
+
* A message option written as an arrow function, `(issue) => ...`, rather than as text.
|
|
353
|
+
* Such a message is spliced into the generated code as an expression instead of a string.
|
|
354
|
+
*/
|
|
355
|
+
const ARROW_FUNCTION_PATTERN = /^\s*\(.*?\)\s*=>/u;
|
|
356
|
+
/**
|
|
357
|
+
* A regular expression that needs the `u` flag: Unicode property escapes (`\p{...}`,
|
|
358
|
+
* `\P{...}`) and brace code points (`\u{...}`), which TypeScript rejects without it (TS1530).
|
|
359
|
+
*/
|
|
360
|
+
const UNICODE_ESCAPE_PATTERN = /\\[pP]\{|\\u\{/u;
|
|
361
|
+
/** A non-ASCII character, which an identifier cannot carry as is. */
|
|
362
|
+
const NON_IDENTIFIER_CHARACTER_PATTERN = /[^A-Za-z0-9_-]/u;
|
|
363
|
+
/** A character that breaks a string-DSL literal and the JS string around it. */
|
|
364
|
+
const QUOTE_OR_BACKSLASH_PATTERN = /['"\\]/u;
|
|
365
|
+
/** The code-emitting extensions each target honours, in the order they are chained. */
|
|
366
|
+
const ZOD_CODE_EXTENSION_KEYS = [
|
|
367
|
+
"x-refine",
|
|
368
|
+
"x-transform",
|
|
369
|
+
"x-pipe",
|
|
370
|
+
"x-codec",
|
|
371
|
+
"x-preprocess"
|
|
372
|
+
];
|
|
373
|
+
const VALIBOT_CODE_EXTENSION_KEYS = [
|
|
374
|
+
"x-check",
|
|
375
|
+
"x-transform",
|
|
376
|
+
"x-pipe"
|
|
377
|
+
];
|
|
378
|
+
const EFFECT_CODE_EXTENSION_KEYS = [
|
|
379
|
+
"x-filter",
|
|
380
|
+
"x-transform",
|
|
381
|
+
"x-pipe"
|
|
382
|
+
];
|
|
383
|
+
const ARKTYPE_CODE_EXTENSION_KEYS = [
|
|
384
|
+
"x-narrow",
|
|
385
|
+
"x-morph",
|
|
386
|
+
"x-pipe"
|
|
387
|
+
];
|
|
388
|
+
/** Every code-emitting extension any target honours, deduplicated and sorted. */
|
|
389
|
+
const ALL_CODE_EXTENSION_KEYS = [.../* @__PURE__ */ new Set([
|
|
390
|
+
...ZOD_CODE_EXTENSION_KEYS,
|
|
391
|
+
...VALIBOT_CODE_EXTENSION_KEYS,
|
|
392
|
+
...EFFECT_CODE_EXTENSION_KEYS,
|
|
393
|
+
...ARKTYPE_CODE_EXTENSION_KEYS
|
|
394
|
+
])].toSorted();
|
|
395
|
+
/** The first line of a file that spliced a caller-supplied code extension into its source. */
|
|
396
|
+
const UNSAFE_GENERATED_MARKER = "// @generated-with-unsafe-code-extensions";
|
|
397
|
+
/** The first line of a file whose generator dropped `if` / `then` / `else`. */
|
|
398
|
+
const IF_THEN_ELSE_UNSUPPORTED_MARKER = "// FIXME: JSON Schema if/then/else is not yet supported by this generator; conditional validation is omitted";
|
|
399
|
+
/** The first line of a TypeBox file whose generator dropped a `not` keyword. */
|
|
400
|
+
const NOT_KEYWORD_UNSUPPORTED_MARKER = "// FIXME: JSON Schema `not` is not enforced by this generator; TypeBox v1 has no runtime `Type.Not` and `Value.Check` ignores the keyword (falls back to `Type.Any()`)";
|
|
401
|
+
/** The comment left where a `$ref` names a definition the document does not hold. */
|
|
402
|
+
const MISSING_DEFINITION_PREFIX = "// ⚠️ missing definition for ";
|
|
403
|
+
/** A JSON Pointer `$ref` to a named definition: `#/$defs/Name` or `#/definitions/Name`. */
|
|
404
|
+
const DEFINITION_POINTER_PATTERN = /^#\/(?:definitions|\$defs)\/(?<name>[^/]+)$/u;
|
|
405
|
+
/** The Draft-04 anchor shorthand for a named definition: `#Name`. */
|
|
406
|
+
const ANCHOR_REF_PATTERN = /^#(?<name>[^/]+)$/u;
|
|
407
|
+
/**
|
|
408
|
+
* The ISO 4217 alphabetic codes in current use, funds and precious-metal codes included:
|
|
409
|
+
* what `format: currencyCode` accepts.
|
|
410
|
+
*
|
|
411
|
+
* @see https://www.iso.org/iso-4217-currency-codes.html
|
|
412
|
+
*/
|
|
413
|
+
const ISO_4217_CURRENCY_CODES = [
|
|
414
|
+
"AED",
|
|
415
|
+
"AFN",
|
|
416
|
+
"ALL",
|
|
417
|
+
"AMD",
|
|
418
|
+
"ANG",
|
|
419
|
+
"AOA",
|
|
420
|
+
"ARS",
|
|
421
|
+
"AUD",
|
|
422
|
+
"AWG",
|
|
423
|
+
"AZN",
|
|
424
|
+
"BAM",
|
|
425
|
+
"BBD",
|
|
426
|
+
"BDT",
|
|
427
|
+
"BGN",
|
|
428
|
+
"BHD",
|
|
429
|
+
"BIF",
|
|
430
|
+
"BMD",
|
|
431
|
+
"BND",
|
|
432
|
+
"BOB",
|
|
433
|
+
"BOV",
|
|
434
|
+
"BRL",
|
|
435
|
+
"BSD",
|
|
436
|
+
"BTN",
|
|
437
|
+
"BWP",
|
|
438
|
+
"BYN",
|
|
439
|
+
"BZD",
|
|
440
|
+
"CAD",
|
|
441
|
+
"CDF",
|
|
442
|
+
"CHE",
|
|
443
|
+
"CHF",
|
|
444
|
+
"CHW",
|
|
445
|
+
"CLF",
|
|
446
|
+
"CLP",
|
|
447
|
+
"CNY",
|
|
448
|
+
"COP",
|
|
449
|
+
"COU",
|
|
450
|
+
"CRC",
|
|
451
|
+
"CUP",
|
|
452
|
+
"CVE",
|
|
453
|
+
"CZK",
|
|
454
|
+
"DJF",
|
|
455
|
+
"DKK",
|
|
456
|
+
"DOP",
|
|
457
|
+
"DZD",
|
|
458
|
+
"EGP",
|
|
459
|
+
"ERN",
|
|
460
|
+
"ETB",
|
|
461
|
+
"EUR",
|
|
462
|
+
"FJD",
|
|
463
|
+
"FKP",
|
|
464
|
+
"GBP",
|
|
465
|
+
"GEL",
|
|
466
|
+
"GHS",
|
|
467
|
+
"GIP",
|
|
468
|
+
"GMD",
|
|
469
|
+
"GNF",
|
|
470
|
+
"GTQ",
|
|
471
|
+
"GYD",
|
|
472
|
+
"HKD",
|
|
473
|
+
"HNL",
|
|
474
|
+
"HTG",
|
|
475
|
+
"HUF",
|
|
476
|
+
"IDR",
|
|
477
|
+
"ILS",
|
|
478
|
+
"INR",
|
|
479
|
+
"IQD",
|
|
480
|
+
"IRR",
|
|
481
|
+
"ISK",
|
|
482
|
+
"JMD",
|
|
483
|
+
"JOD",
|
|
484
|
+
"JPY",
|
|
485
|
+
"KES",
|
|
486
|
+
"KGS",
|
|
487
|
+
"KHR",
|
|
488
|
+
"KMF",
|
|
489
|
+
"KPW",
|
|
490
|
+
"KRW",
|
|
491
|
+
"KWD",
|
|
492
|
+
"KYD",
|
|
493
|
+
"KZT",
|
|
494
|
+
"LAK",
|
|
495
|
+
"LBP",
|
|
496
|
+
"LKR",
|
|
497
|
+
"LRD",
|
|
498
|
+
"LSL",
|
|
499
|
+
"LYD",
|
|
500
|
+
"MAD",
|
|
501
|
+
"MDL",
|
|
502
|
+
"MGA",
|
|
503
|
+
"MKD",
|
|
504
|
+
"MMK",
|
|
505
|
+
"MNT",
|
|
506
|
+
"MOP",
|
|
507
|
+
"MRU",
|
|
508
|
+
"MUR",
|
|
509
|
+
"MVR",
|
|
510
|
+
"MWK",
|
|
511
|
+
"MXN",
|
|
512
|
+
"MXV",
|
|
513
|
+
"MYR",
|
|
514
|
+
"MZN",
|
|
515
|
+
"NAD",
|
|
516
|
+
"NGN",
|
|
517
|
+
"NIO",
|
|
518
|
+
"NOK",
|
|
519
|
+
"NPR",
|
|
520
|
+
"NZD",
|
|
521
|
+
"OMR",
|
|
522
|
+
"PAB",
|
|
523
|
+
"PEN",
|
|
524
|
+
"PGK",
|
|
525
|
+
"PHP",
|
|
526
|
+
"PKR",
|
|
527
|
+
"PLN",
|
|
528
|
+
"PYG",
|
|
529
|
+
"QAR",
|
|
530
|
+
"RON",
|
|
531
|
+
"RSD",
|
|
532
|
+
"RUB",
|
|
533
|
+
"RWF",
|
|
534
|
+
"SAR",
|
|
535
|
+
"SBD",
|
|
536
|
+
"SCR",
|
|
537
|
+
"SDG",
|
|
538
|
+
"SEK",
|
|
539
|
+
"SGD",
|
|
540
|
+
"SHP",
|
|
541
|
+
"SLE",
|
|
542
|
+
"SOS",
|
|
543
|
+
"SRD",
|
|
544
|
+
"SSP",
|
|
545
|
+
"STN",
|
|
546
|
+
"SVC",
|
|
547
|
+
"SYP",
|
|
548
|
+
"SZL",
|
|
549
|
+
"THB",
|
|
550
|
+
"TJS",
|
|
551
|
+
"TMT",
|
|
552
|
+
"TND",
|
|
553
|
+
"TOP",
|
|
554
|
+
"TRY",
|
|
555
|
+
"TTD",
|
|
556
|
+
"TWD",
|
|
557
|
+
"TZS",
|
|
558
|
+
"UAH",
|
|
559
|
+
"UGX",
|
|
560
|
+
"USD",
|
|
561
|
+
"USN",
|
|
562
|
+
"UYI",
|
|
563
|
+
"UYU",
|
|
564
|
+
"UYW",
|
|
565
|
+
"UZS",
|
|
566
|
+
"VED",
|
|
567
|
+
"VES",
|
|
568
|
+
"VND",
|
|
569
|
+
"VUV",
|
|
570
|
+
"WST",
|
|
571
|
+
"XAF",
|
|
572
|
+
"XAG",
|
|
573
|
+
"XAU",
|
|
574
|
+
"XBA",
|
|
575
|
+
"XBB",
|
|
576
|
+
"XBC",
|
|
577
|
+
"XBD",
|
|
578
|
+
"XCD",
|
|
579
|
+
"XCG",
|
|
580
|
+
"XDR",
|
|
581
|
+
"XOF",
|
|
582
|
+
"XPD",
|
|
583
|
+
"XPF",
|
|
584
|
+
"XPT",
|
|
585
|
+
"XSU",
|
|
586
|
+
"XTS",
|
|
587
|
+
"XUA",
|
|
588
|
+
"XXX",
|
|
589
|
+
"YER",
|
|
590
|
+
"ZAR",
|
|
591
|
+
"ZMW",
|
|
592
|
+
"ZWG"
|
|
593
|
+
];
|
|
594
|
+
// src/guard/index.ts
|
|
595
|
+
/**
|
|
596
|
+
* Whether a value is a non-null object — the shape every schema walk descends into.
|
|
597
|
+
*
|
|
598
|
+
* `typeof null === 'object'` is the one case worth spelling out; arrays pass, which is
|
|
599
|
+
* what the walkers want, since a combinator list is an array of schemas.
|
|
600
|
+
*/
|
|
601
|
+
function isRecord(value) {
|
|
602
|
+
return typeof value === "object" && value !== null;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* A non-array object. Distinct from {@link isRecord}: an enum member that is an array
|
|
606
|
+
* needs a tuple matcher, and one that is a plain object needs an object matcher, so the
|
|
607
|
+
* two are told apart here rather than lumped together.
|
|
608
|
+
*/
|
|
609
|
+
function isPlainObject(value) {
|
|
610
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
611
|
+
}
|
|
612
|
+
/** A JSON scalar: what a `literal` matcher can take as is. */
|
|
613
|
+
function isPrimitive(value) {
|
|
614
|
+
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
615
|
+
}
|
|
616
|
+
/** An array or object value: one that needs a structural matcher rather than a literal. */
|
|
617
|
+
function isComposite(value) {
|
|
618
|
+
return typeof value === "object" && value !== null;
|
|
619
|
+
}
|
|
620
|
+
/** Whether a key can be written bare in an object literal or as a member access. */
|
|
621
|
+
function isValidIdentifier(name) {
|
|
622
|
+
return IDENTIFIER_PATTERN.test(name);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Whether a configured message is source text for an arrow function rather than a
|
|
626
|
+
* literal sentence.
|
|
627
|
+
*
|
|
628
|
+
* The `x-*-message` extensions accept either, and a library that takes a callback
|
|
629
|
+
* (Zod's `error`, Valibot's message argument) gets the source through unquoted.
|
|
630
|
+
*/
|
|
631
|
+
function isArrowExpression(source) {
|
|
632
|
+
return ARROW_FUNCTION_PATTERN.test(source);
|
|
633
|
+
}
|
|
634
|
+
/** Whether a key holds a document's named definitions (`$defs` or `definitions`). */
|
|
635
|
+
function isDefinitionKeyword(key) {
|
|
636
|
+
return DEFINITION_KEYWORDS.some((keyword) => keyword === key);
|
|
637
|
+
}
|
|
638
|
+
/** Whether a parameter location delivers its values as strings that have to be coerced. */
|
|
639
|
+
function isStringWireLocation(paramIn) {
|
|
640
|
+
return STRING_WIRE_LOCATIONS.some((location) => location === paramIn);
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Whether a property name is one every plain object inherits (`constructor`, `toString`,
|
|
644
|
+
* ...), so reading it off a parameter object that never carried it finds a function.
|
|
645
|
+
*/
|
|
646
|
+
function isObjectPrototypeProperty(name) {
|
|
647
|
+
return OBJECT_PROTOTYPE_PROPERTIES.some((property) => property === name);
|
|
648
|
+
}
|
|
649
|
+
/** Whether a `$ref` names the whole document — the schema being emitted refers to itself. */
|
|
650
|
+
function isRootRef(ref) {
|
|
651
|
+
return ROOT_REFS.some((root) => root === ref);
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* True for a local JSON Pointer `$ref` that points *into* a component
|
|
655
|
+
* sub-schema (e.g. `#/components/schemas/X/properties/Y`) rather than at a
|
|
656
|
+
* top-level component (`#/components/schemas/X`). Such pointers have no
|
|
657
|
+
* generated declaration, so generators emit an `unknown` schema for them
|
|
658
|
+
* instead of referencing an undeclared identifier.
|
|
659
|
+
*
|
|
660
|
+
* @example
|
|
661
|
+
* ```ts
|
|
662
|
+
* isDeepLocalPointer('#/components/schemas/User') // false
|
|
663
|
+
* isDeepLocalPointer('#/components/schemas/User/properties/x') // true
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
function isDeepLocalPointer($ref) {
|
|
667
|
+
if (!$ref.startsWith("#/")) return false;
|
|
668
|
+
const fragment = $ref.slice(2);
|
|
669
|
+
const matched = [
|
|
670
|
+
"components/schemas/",
|
|
671
|
+
"definitions/",
|
|
672
|
+
"$defs/"
|
|
673
|
+
].find((c) => fragment.startsWith(c));
|
|
674
|
+
return matched ? fragment.slice(matched.length).includes("/") : false;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* JSON Schema 2020-12 §4.3.2 / §10.3.1.2: `items`, `additionalProperties`,
|
|
678
|
+
* `unevaluatedItems` and `unevaluatedProperties` may be an object schema or a boolean
|
|
679
|
+
* schema (`true` = pass-through, `false` = reject), and `items` may also be a Draft-04
|
|
680
|
+
* tuple. This narrows the union to the single object form so callers can recurse.
|
|
681
|
+
*/
|
|
682
|
+
function isSchemaObject(value) {
|
|
683
|
+
return typeof value === "object" && !Array.isArray(value);
|
|
684
|
+
}
|
|
685
|
+
/** Draft-04's tuple form of `items`: a list of schemas rather than a single one. */
|
|
686
|
+
function isSchemaList(value) {
|
|
687
|
+
return Array.isArray(value);
|
|
688
|
+
}
|
|
689
|
+
/** Whether a node admits `null`: OpenAPI 3.0 `nullable`, or `null` among its types. */
|
|
690
|
+
function isNullable(schema) {
|
|
691
|
+
return schema.nullable === true || hasType(schema, "null");
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Whether a node takes `null`: a nullable type, a `null` among its `enum`, a `const: null`
|
|
695
|
+
* or a `oneOf` / `anyOf` member that does.
|
|
696
|
+
*/
|
|
697
|
+
function canBeNull(schema) {
|
|
698
|
+
if (isNullable(schema)) return true;
|
|
699
|
+
if (schema.const === null) return true;
|
|
700
|
+
if (schema.enum?.some((value) => value === null)) return true;
|
|
701
|
+
return [...schema.oneOf ?? [], ...schema.anyOf ?? []].some(canBeNull);
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Whether a node may take a string: a `string` type, a string among its `enum` or `const`,
|
|
705
|
+
* a `oneOf` / `anyOf` member that does, or no constraint on the type at all.
|
|
706
|
+
*/
|
|
707
|
+
function canBeString(schema) {
|
|
708
|
+
if (hasType(schema, "string")) return true;
|
|
709
|
+
if (typeof schema.const === "string") return true;
|
|
710
|
+
if (schema.enum !== void 0) return schema.enum.some((value) => typeof value === "string");
|
|
711
|
+
const members = [...schema.oneOf ?? [], ...schema.anyOf ?? []];
|
|
712
|
+
if (members.length > 0) return members.some(canBeString);
|
|
713
|
+
return schema.type === void 0 && schema.const === void 0 && schema.$ref === void 0 && schema.allOf === void 0 && schema.not === void 0 && schema.properties === void 0;
|
|
714
|
+
}
|
|
715
|
+
/** Whether a node without a `type` carries a keyword that only applies to a number. */
|
|
716
|
+
function hasNumericKeyword(schema) {
|
|
717
|
+
return NUMERIC_KEYWORDS.some((keyword) => schema[keyword] !== void 0);
|
|
718
|
+
}
|
|
719
|
+
/** Whether a node without a `type` carries a keyword that only applies to a string. */
|
|
720
|
+
function hasStringKeyword(schema) {
|
|
721
|
+
return STRING_KEYWORDS.some((keyword) => schema[keyword] !== void 0);
|
|
722
|
+
}
|
|
723
|
+
/** Whether `type` names `type`, either alone or as one of a list. */
|
|
724
|
+
function hasType(schema, type) {
|
|
725
|
+
const types = schema.type;
|
|
726
|
+
if (types === void 0) return false;
|
|
727
|
+
if (typeof types === "string") return types === type;
|
|
728
|
+
return types.some((candidate) => candidate === type);
|
|
729
|
+
}
|
|
730
|
+
/** Whether a node is composed of other schemas: `oneOf`, `anyOf`, `allOf` or `not`. */
|
|
731
|
+
function hasCombinator(schema) {
|
|
732
|
+
return schema.oneOf !== void 0 || schema.anyOf !== void 0 || schema.allOf !== void 0 || schema.not !== void 0;
|
|
733
|
+
}
|
|
734
|
+
/** Whether a node carries a conditional (`if` / `then` / `else`). */
|
|
735
|
+
function hasConditional(schema) {
|
|
736
|
+
return schema.if !== void 0 || schema.then !== void 0 || schema.else !== void 0;
|
|
737
|
+
}
|
|
738
|
+
/** Whether `minLength` and `maxLength` pin a string to exactly one length. */
|
|
739
|
+
function hasFixedLength(schema) {
|
|
740
|
+
return schema.minLength !== void 0 && schema.maxLength !== void 0 && schema.minLength === schema.maxLength;
|
|
741
|
+
}
|
|
742
|
+
/** Whether `minItems` and `maxItems` pin an array to exactly one length. */
|
|
743
|
+
function hasFixedItemCount(schema) {
|
|
744
|
+
return typeof schema.minItems === "number" && typeof schema.maxItems === "number" && schema.minItems === schema.maxItems;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* An `allOf` member that only says "and it may be null".
|
|
748
|
+
*
|
|
749
|
+
* OpenAPI 3.0 spells a nullable composition as `allOf: [{...}, { nullable: true }]`, and
|
|
750
|
+
* a bare `{ type: 'null' }` is the JSON Schema equivalent. Neither contributes a shape,
|
|
751
|
+
* so every generator lifts it out of the intersection and onto the result instead.
|
|
752
|
+
*/
|
|
753
|
+
function isNullTypeMember(schema) {
|
|
754
|
+
return schema.type === "null" || schema.nullable === true && Object.keys(schema).length === 1;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* An `allOf` member that only carries a `default`.
|
|
758
|
+
*
|
|
759
|
+
* A default is metadata on the composed value rather than a constraint of its own, so it
|
|
760
|
+
* is applied to the intersection rather than intersected into it.
|
|
761
|
+
*/
|
|
762
|
+
function isDefaultOnlyMember(schema) {
|
|
763
|
+
return Object.keys(schema).length === 1 && schema.default !== void 0;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* An `allOf` member that only carries a `const`.
|
|
767
|
+
*
|
|
768
|
+
* The other members already describe the shape; a lone `const` would narrow it to a
|
|
769
|
+
* single value in a way none of the target libraries express as an intersection, so it is
|
|
770
|
+
* dropped rather than emitted.
|
|
771
|
+
*/
|
|
772
|
+
function isConstOnlyMember(schema) {
|
|
773
|
+
return Object.keys(schema).length === 1 && schema.const !== void 0;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* True for an `allOf` member that carries no shape of its own — the ones every generator
|
|
777
|
+
* filters out before intersecting what is left.
|
|
778
|
+
*/
|
|
779
|
+
function isShapelessMember(schema) {
|
|
780
|
+
return isNullTypeMember(schema) || isDefaultOnlyMember(schema) || isConstOnlyMember(schema);
|
|
781
|
+
}
|
|
782
|
+
/** A double-quoted string literal: the ArkType string DSL form of a definition. */
|
|
783
|
+
function isQuoted(source) {
|
|
784
|
+
return source.startsWith("\"") && source.endsWith("\"");
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* A bare ArkType definition — a string, object or tuple literal — as opposed to
|
|
788
|
+
* an expression that already evaluates to a `Type` and so carries methods.
|
|
789
|
+
*/
|
|
790
|
+
function isArktypeDefinition(source) {
|
|
791
|
+
return isQuoted(source) || source.startsWith("{") && source.endsWith("}") || source.startsWith("[") && source.endsWith("]");
|
|
792
|
+
}
|
|
793
|
+
// src/utils/index.ts
|
|
794
|
+
/**
|
|
795
|
+
* Convert string to PascalCase (first character uppercase).
|
|
796
|
+
*
|
|
797
|
+
* When the input contains characters that are not valid in a TypeScript
|
|
798
|
+
* identifier (whitespace, dots, slashes, etc.) the input is routed through
|
|
799
|
+
* {@link toIdentifierPascalCase} so the generated variable name remains
|
|
800
|
+
* parseable. Hyphens and underscores are preserved for back-compat with
|
|
801
|
+
* upstream titles that already generated working code.
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* ```ts
|
|
805
|
+
* toPascalCase('animal') // 'Animal'
|
|
806
|
+
* toPascalCase('userProfile') // 'UserProfile'
|
|
807
|
+
* toPascalCase('Self-Referencing Entities') // 'SelfReferencingEntities'
|
|
808
|
+
* ```
|
|
809
|
+
*/
|
|
810
|
+
function toPascalCase(name) {
|
|
811
|
+
if (NON_IDENTIFIER_CHARACTER_PATTERN.test(name)) return toIdentifierPascalCase(name);
|
|
812
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Encode non-ASCII characters as `u<hex codepoint>` so they survive identifier
|
|
816
|
+
* normalization instead of being stripped (which collapses every non-ASCII name
|
|
817
|
+
* to the same `Schema`, producing duplicate declarations). Pure-ASCII input is
|
|
818
|
+
* returned unchanged, so identifier generation stays byte-for-byte identical for
|
|
819
|
+
* the overwhelming majority of specs.
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* ```ts
|
|
823
|
+
* encodeNonAscii('User') // 'User'
|
|
824
|
+
* encodeNonAscii('日本語') // 'u65e5u672cu8a9e'
|
|
825
|
+
* ```
|
|
826
|
+
*/
|
|
827
|
+
function encodeNonAscii(name) {
|
|
828
|
+
return [...name].map((ch) => {
|
|
829
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
830
|
+
return cp > 127 ? `u${cp.toString(16)}` : ch;
|
|
831
|
+
}).join("");
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Convert string to a valid PascalCase identifier.
|
|
835
|
+
*
|
|
836
|
+
* Splits by non-alphanumeric characters and capitalizes each segment.
|
|
837
|
+
* Handles hyphens, underscores, dots, spaces, leading numbers, and non-ASCII characters.
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```ts
|
|
841
|
+
* toIdentifierPascalCase('user-name') // 'UserName'
|
|
842
|
+
* toIdentifierPascalCase('hello_world') // 'HelloWorld'
|
|
843
|
+
* toIdentifierPascalCase('123value') // '_123Value'
|
|
844
|
+
* toIdentifierPascalCase('user') // 'User'
|
|
845
|
+
* ```
|
|
846
|
+
*/
|
|
847
|
+
function toIdentifierPascalCase(name) {
|
|
848
|
+
const parts = encodeNonAscii(name).split(/[^a-zA-Z0-9]+/u).filter(Boolean);
|
|
849
|
+
if (parts.length === 0) return DEFAULT_ROOT_NAME;
|
|
850
|
+
const result = parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
851
|
+
if (/^[0-9]/u.test(result)) return `_${result}`.replace(/([0-9])([a-z])/u, (_, d, c) => `${d}${c.toUpperCase()}`);
|
|
852
|
+
return result;
|
|
853
|
+
}
|
|
854
|
+
function normalizeTypes(t) {
|
|
855
|
+
if (t === void 0) return [];
|
|
856
|
+
if (typeof t === "string") return [t];
|
|
857
|
+
return [...t];
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Reconcile a schema's `default` value with the type the schema actually emits
|
|
861
|
+
* so the generated `.default(...)` stays assignable. The default is kept only
|
|
862
|
+
* when it is a value of the schema, read the way a document usually writes it:
|
|
863
|
+
*
|
|
864
|
+
* - `null` is kept only on a nullable schema (or one whose `enum` lists it).
|
|
865
|
+
* - an `enum` / `const` takes only what it lists.
|
|
866
|
+
* - text that spells a value of the schema's type is read as that value: `'true'`
|
|
867
|
+
* for a boolean, `'7'` for a number or an integer; a number or a boolean for a
|
|
868
|
+
* string is written as text. Any other scalar of the wrong type is dropped
|
|
869
|
+
* (`'null'` for an integer, `'strict'` with the quotes for an enum).
|
|
870
|
+
* - an array keeps its items when every one is a value of `items`.
|
|
871
|
+
* - an object default drops keys the schema does not declare, when the emitted
|
|
872
|
+
* object has no index signature (`additionalProperties` is not `true` or a
|
|
873
|
+
* schema, and there are no `patternProperties`), and needs every `required`
|
|
874
|
+
* key. A loose or record schema keeps every key.
|
|
875
|
+
* - a `$ref`, or an `allOf` the node has no type of its own beside, is read as
|
|
876
|
+
* the definition it names when `definitions` has it; a `oneOf` / `anyOf` keeps
|
|
877
|
+
* the default when a member takes it, whatever `type` sits beside it.
|
|
878
|
+
* - a node with nothing to check against (no `type`, an unknown `$ref`) keeps
|
|
879
|
+
* the default as written.
|
|
880
|
+
*
|
|
881
|
+
* JSON Schema 2020-12 §9.9.4.1 treats `default` as an annotation with no
|
|
882
|
+
* validity guarantee, so an invalid one is dropped rather than reported.
|
|
883
|
+
*
|
|
884
|
+
* @example
|
|
885
|
+
* ```ts
|
|
886
|
+
* coerceDefault({ type: 'boolean' }, 'true') // { keep: true, value: true }
|
|
887
|
+
* coerceDefault({ type: 'number' }, '7') // { keep: true, value: 7 }
|
|
888
|
+
* coerceDefault({ type: 'object' }, null) // { keep: false, value: null }
|
|
889
|
+
* coerceDefault({ type: 'object', nullable: true }, null) // { keep: true, value: null }
|
|
890
|
+
* coerceDefault({ type: 'array' }, 'eval') // { keep: false, value: 'eval' }
|
|
891
|
+
* coerceDefault({ enum: ['a', 'b'] }, "'a'") // { keep: false, value: "'a'" }
|
|
892
|
+
* ```
|
|
893
|
+
*/
|
|
894
|
+
function coerceDefault(schema, value, definitions) {
|
|
895
|
+
return conformDefault(schema, value, definitions, /* @__PURE__ */ new Set());
|
|
896
|
+
}
|
|
897
|
+
function conformDefault(schema, value, definitions, reading) {
|
|
898
|
+
const drop = {
|
|
899
|
+
keep: false,
|
|
900
|
+
value
|
|
901
|
+
};
|
|
902
|
+
const asIs = {
|
|
903
|
+
keep: true,
|
|
904
|
+
value
|
|
905
|
+
};
|
|
906
|
+
const conform = (s, v, r = reading) => conformDefault(s, v, definitions, r);
|
|
907
|
+
if (schema.$ref !== void 0) {
|
|
908
|
+
const target = reading.has(schema.$ref) ? void 0 : definitionOf$1(schema.$ref, definitions);
|
|
909
|
+
if (target === void 0) return value === null && schema.nullable !== true ? drop : asIs;
|
|
910
|
+
const { $ref, ...beside } = schema;
|
|
911
|
+
return conform({
|
|
912
|
+
...target,
|
|
913
|
+
...beside
|
|
914
|
+
}, value, /* @__PURE__ */ new Set([...reading, $ref]));
|
|
915
|
+
}
|
|
916
|
+
const types = normalizeTypes(schema.type);
|
|
917
|
+
const isNullable = schema.nullable === true || types.includes("null") || schema.enum?.includes(null) === true || schema.const === null;
|
|
918
|
+
if (value === null) {
|
|
919
|
+
if (isNullable) return asIs;
|
|
920
|
+
return [...schema.oneOf ?? [], ...schema.anyOf ?? []].some((member) => conform(member, null).keep) ? asIs : drop;
|
|
921
|
+
}
|
|
922
|
+
const members = schema.oneOf ?? schema.anyOf;
|
|
923
|
+
if (members !== void 0 && members.length > 0) {
|
|
924
|
+
const results = members.map((member) => conform(member, value));
|
|
925
|
+
return results.find((result) => result.keep && result.value === value) ?? results.find((result) => result.keep) ?? drop;
|
|
926
|
+
}
|
|
927
|
+
if (schema.enum !== void 0) return schema.enum.some((member) => member === value) ? asIs : drop;
|
|
928
|
+
if (schema.const !== void 0) return JSON.stringify(schema.const) === JSON.stringify(value) ? asIs : drop;
|
|
929
|
+
if (types.length === 0 && schema.allOf !== void 0) return schema.allOf.filter((member) => {
|
|
930
|
+
const memberTypes = normalizeTypes(member.type);
|
|
931
|
+
return memberTypes.length === 0 || memberTypes.some((t) => t !== "null");
|
|
932
|
+
}).reduce((result, member) => result.keep ? conform(member, result.value) : result, asIs);
|
|
933
|
+
const valueTypes = types.filter((t) => t !== "null");
|
|
934
|
+
if (types.length > 0 && valueTypes.length === 0) return drop;
|
|
935
|
+
if (valueTypes.length === 0) return schema.properties !== void 0 ? readObject(schema, value, conform) ?? drop : asIs;
|
|
936
|
+
const read = (type) => {
|
|
937
|
+
if (type === "boolean") {
|
|
938
|
+
if (typeof value === "boolean") return asIs;
|
|
939
|
+
if (value === "true" || value === "false") return {
|
|
940
|
+
keep: true,
|
|
941
|
+
value: value === "true"
|
|
942
|
+
};
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
if (type === "number" || type === "integer") {
|
|
946
|
+
const number = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" && Number.isFinite(Number(value)) ? Number(value) : void 0;
|
|
947
|
+
if (number === void 0) return void 0;
|
|
948
|
+
if (type === "integer" && !Number.isInteger(number)) return void 0;
|
|
949
|
+
return {
|
|
950
|
+
keep: true,
|
|
951
|
+
value: number
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
if (type === "string") {
|
|
955
|
+
if (typeof value === "string") return asIs;
|
|
956
|
+
if (typeof value === "number" || typeof value === "boolean") return {
|
|
957
|
+
keep: true,
|
|
958
|
+
value: String(value)
|
|
959
|
+
};
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
if (type === "array") {
|
|
963
|
+
if (!Array.isArray(value)) return void 0;
|
|
964
|
+
const items = schema.items;
|
|
965
|
+
if (!isDefaultSchemaObject(items)) return asIs;
|
|
966
|
+
const readItems = value.map((item) => conform(items, item));
|
|
967
|
+
return readItems.every((item) => item.keep) ? {
|
|
968
|
+
keep: true,
|
|
969
|
+
value: readItems.map((item) => item.value)
|
|
970
|
+
} : void 0;
|
|
971
|
+
}
|
|
972
|
+
if (type === "object") return readObject(schema, value, conform);
|
|
973
|
+
return asIs;
|
|
974
|
+
};
|
|
975
|
+
const own = valueTypes.find((type) => typeOf(value) === type || type === "number" && typeof value === "number");
|
|
976
|
+
return (own === void 0 ? void 0 : read(own)) ?? valueTypes.map(read).find((r) => r !== void 0) ?? drop;
|
|
977
|
+
}
|
|
978
|
+
/** An object default as a value of the schema, or `undefined` when it is not one. */
|
|
979
|
+
function readObject(schema, value, conform) {
|
|
980
|
+
if (!isDeclaredObject(value)) return void 0;
|
|
981
|
+
if (schema.properties === void 0 || canHoldUndeclaredKeys(schema)) return {
|
|
982
|
+
keep: true,
|
|
983
|
+
value
|
|
984
|
+
};
|
|
985
|
+
const declared = schema.properties;
|
|
986
|
+
if ((schema.required ?? []).some((key) => !Object.hasOwn(value, key))) return void 0;
|
|
987
|
+
const kept = {};
|
|
988
|
+
for (const [key, item] of Object.entries(value)) {
|
|
989
|
+
if (!Object.hasOwn(declared, key)) continue;
|
|
990
|
+
const result = conform(declared[key], item);
|
|
991
|
+
if (!result.keep) return void 0;
|
|
992
|
+
kept[key] = result.value;
|
|
993
|
+
}
|
|
994
|
+
return {
|
|
995
|
+
keep: true,
|
|
996
|
+
value: kept
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
/** The definition a local `$ref` names, when `definitions` has it. */
|
|
1000
|
+
function definitionOf$1(ref, definitions) {
|
|
1001
|
+
if (definitions === void 0) return void 0;
|
|
1002
|
+
for (const prefix of DEFINITION_REF_PREFIXES) {
|
|
1003
|
+
if (!ref.startsWith(prefix)) continue;
|
|
1004
|
+
const rest = ref.slice(prefix.length);
|
|
1005
|
+
if (rest === "" || rest.includes("/")) return void 0;
|
|
1006
|
+
const name = decodeURIComponent(rest);
|
|
1007
|
+
return Object.hasOwn(definitions, name) ? definitions[name] : void 0;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
function typeOf(value) {
|
|
1011
|
+
if (typeof value === "boolean") return "boolean";
|
|
1012
|
+
if (typeof value === "number") return Number.isInteger(value) ? "integer" : "number";
|
|
1013
|
+
if (typeof value === "string") return "string";
|
|
1014
|
+
if (Array.isArray(value)) return "array";
|
|
1015
|
+
if (isDeclaredObject(value)) return "object";
|
|
1016
|
+
}
|
|
1017
|
+
function isDefaultSchemaObject(value) {
|
|
1018
|
+
return typeof value === "object" && !Array.isArray(value);
|
|
1019
|
+
}
|
|
1020
|
+
function isDeclaredObject(value) {
|
|
1021
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1022
|
+
}
|
|
1023
|
+
/** Whether a generated object type accepts keys the schema does not name. */
|
|
1024
|
+
function canHoldUndeclaredKeys(schema) {
|
|
1025
|
+
if (schema.additionalProperties === true || typeof schema.additionalProperties === "object") return true;
|
|
1026
|
+
if (schema.patternProperties !== void 0) return true;
|
|
1027
|
+
return schema.unevaluatedProperties === true || typeof schema.unevaluatedProperties === "object";
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* A message as the expression an emitted check evaluates for each issue: an arrow source
|
|
1031
|
+
* is applied to the issue, a sentence becomes a string literal.
|
|
1032
|
+
*
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```ts
|
|
1035
|
+
* issueMessageExpression('Invalid') // '"Invalid"'
|
|
1036
|
+
* issueMessageExpression('(issue) => issue.path[0]') // '((issue) => issue.path[0])(issue)'
|
|
1037
|
+
* ```
|
|
1038
|
+
*/
|
|
1039
|
+
function issueMessageExpression(message) {
|
|
1040
|
+
return isArrowExpression(message) ? `(${message})(issue)` : JSON.stringify(message);
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Format an error message argument using the Zod v4 unified `error` parameter.
|
|
1044
|
+
*
|
|
1045
|
+
* @example
|
|
1046
|
+
* ```ts
|
|
1047
|
+
* zodError('Name must be 3-20 characters') // '{error:"Name must be 3-20 characters"}'
|
|
1048
|
+
* zodError('(val) => `Expected ${val}`') // '{error:(val) => `Expected ${val}`}'
|
|
1049
|
+
* ```
|
|
1050
|
+
*/
|
|
1051
|
+
function zodError(message) {
|
|
1052
|
+
return isArrowExpression(message) ? `{error:${message}}` : `{error:${JSON.stringify(message)}}`;
|
|
1053
|
+
}
|
|
1054
|
+
/** `zodError(message)` as a trailing argument, or nothing when there is no message. */
|
|
1055
|
+
function zodErrorPart(message) {
|
|
1056
|
+
return message ? `,${zodError(message)}` : "";
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Build the base `{error:...}` argument for a Zod v4 schema constructor when
|
|
1060
|
+
* `x-error-message` (type / generic) and/or `x-required-message`
|
|
1061
|
+
* (`issue.input === undefined`) are present.
|
|
1062
|
+
*/
|
|
1063
|
+
function zodBaseError(typeMessage, requiredMessage) {
|
|
1064
|
+
if (typeMessage === void 0 && requiredMessage === void 0) return "";
|
|
1065
|
+
if (requiredMessage === void 0 && typeMessage !== void 0) return zodError(typeMessage);
|
|
1066
|
+
if (requiredMessage !== void 0 && typeMessage === void 0) return `{error:(issue)=>issue.input===undefined?${JSON.stringify(requiredMessage)}:undefined}`;
|
|
1067
|
+
return `{error:(issue)=>issue.input===undefined?${JSON.stringify(requiredMessage)}:${JSON.stringify(typeMessage)}}`;
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Format an error message argument for Valibot.
|
|
1071
|
+
*
|
|
1072
|
+
* @example
|
|
1073
|
+
* ```ts
|
|
1074
|
+
* valibotError('Must be valid') // '"Must be valid"'
|
|
1075
|
+
* valibotError('(issue) => issue.input') // '(issue) => issue.input'
|
|
1076
|
+
* ```
|
|
1077
|
+
*/
|
|
1078
|
+
function valibotError(message) {
|
|
1079
|
+
return isArrowExpression(message) ? message : JSON.stringify(message);
|
|
1080
|
+
}
|
|
1081
|
+
/** `valibotError(message)` as a trailing argument, or nothing when there is no message. */
|
|
1082
|
+
function valibotErrorPart(message) {
|
|
1083
|
+
return message ? `,${valibotError(message)}` : "";
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Format an error message annotation for Effect Schema.
|
|
1087
|
+
*
|
|
1088
|
+
* Effect Schema v4 types the `message` annotation as a plain `string` (v3 took
|
|
1089
|
+
* a `() => string` thunk), so an arrow-expression message has no place to go
|
|
1090
|
+
* and is emitted as its source text — see {@link effectMessage}.
|
|
1091
|
+
*
|
|
1092
|
+
* @example
|
|
1093
|
+
* ```ts
|
|
1094
|
+
* effectError('Required') // '{message:"Required"}'
|
|
1095
|
+
* ```
|
|
1096
|
+
*/
|
|
1097
|
+
function effectError(message) {
|
|
1098
|
+
return `{message:${effectMessage(message)}}`;
|
|
1099
|
+
}
|
|
1100
|
+
/** `effectError(message)` as a trailing argument, or nothing when there is no message. */
|
|
1101
|
+
function effectErrorPart(message) {
|
|
1102
|
+
return message ? `,${effectError(message)}` : "";
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* The `message` annotation value for Effect Schema v4: a string literal.
|
|
1106
|
+
*
|
|
1107
|
+
* @example
|
|
1108
|
+
* ```ts
|
|
1109
|
+
* effectMessage('Required') // '"Required"'
|
|
1110
|
+
* ```
|
|
1111
|
+
*/
|
|
1112
|
+
function effectMessage(message) {
|
|
1113
|
+
return JSON.stringify(message);
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Resolve an OpenAPI $ref string to a variable name with the appropriate suffix
|
|
1117
|
+
*
|
|
1118
|
+
* @example
|
|
1119
|
+
* ```ts
|
|
1120
|
+
* resolveOpenAPIRef('#/components/schemas/User') // 'UserSchema'
|
|
1121
|
+
* resolveOpenAPIRef('#/components/parameters/UserId') // 'UserIdParamsSchema'
|
|
1122
|
+
* resolveOpenAPIRef('#/definitions/Address') // null
|
|
1123
|
+
* ```
|
|
1124
|
+
*/
|
|
1125
|
+
function resolveOpenAPIRef($ref) {
|
|
1126
|
+
for (const { prefix, suffix } of OPENAPI_COMPONENT_SUFFIX_MAP) if ($ref.startsWith(prefix)) return toIdentifierPascalCase(decodeURIComponent($ref.slice(prefix.length))) + suffix;
|
|
1127
|
+
return null;
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Encode a property key safely for object literal output.
|
|
1131
|
+
* Bare identifiers stay unquoted; everything else is JSON-encoded.
|
|
1132
|
+
*
|
|
1133
|
+
* @example
|
|
1134
|
+
* ```ts
|
|
1135
|
+
* makeSafeKey('foo') // 'foo'
|
|
1136
|
+
* makeSafeKey('foo-bar') // '"foo-bar"'
|
|
1137
|
+
* makeSafeKey('123') // '"123"'
|
|
1138
|
+
* ```
|
|
1139
|
+
*/
|
|
1140
|
+
function makeSafeKey(key) {
|
|
1141
|
+
return isValidIdentifier(key) ? key : JSON.stringify(key);
|
|
1142
|
+
}
|
|
1143
|
+
// src/helper/regex.ts
|
|
3
1144
|
/**
|
|
4
1145
|
* Build a JavaScript regular-expression literal from a JSON Schema `pattern`.
|
|
5
1146
|
*
|
|
@@ -63,8 +1204,7 @@ function rewriteBracedHex(pattern) {
|
|
|
63
1204
|
unicode
|
|
64
1205
|
};
|
|
65
1206
|
}
|
|
66
|
-
|
|
67
|
-
//#region src/helper/all-of.ts
|
|
1207
|
+
// src/helper/all-of.ts
|
|
68
1208
|
/**
|
|
69
1209
|
* An `allOf` member that only carries keywords (`{ minimum: 5 }`, `{ maxLength: 10 }`).
|
|
70
1210
|
*
|
|
@@ -375,8 +1515,7 @@ function stringGuard(schema, param) {
|
|
|
375
1515
|
if (checks.length === 0) return "";
|
|
376
1516
|
return `(typeof ${param} !== 'string' || (${checks.join(" && ")}))`;
|
|
377
1517
|
}
|
|
378
|
-
|
|
379
|
-
//#region src/helper/walk.ts
|
|
1518
|
+
// src/helper/walk.ts
|
|
380
1519
|
/**
|
|
381
1520
|
* Every object node under `root`, depth first, the root first.
|
|
382
1521
|
*
|
|
@@ -421,8 +1560,7 @@ function hasKeyword(root, keywords) {
|
|
|
421
1560
|
function hasNotKeyword(schema) {
|
|
422
1561
|
return hasKeyword(schema, ["not"]);
|
|
423
1562
|
}
|
|
424
|
-
|
|
425
|
-
//#region src/helper/code-extensions.ts
|
|
1563
|
+
// src/helper/code-extensions.ts
|
|
426
1564
|
const CODE_EXTENSION_KEYS = new Set(ALL_CODE_EXTENSION_KEYS);
|
|
427
1565
|
const DENYLIST_PATTERN = new RegExp([
|
|
428
1566
|
"\\b(?:process|require|import|globalThis|eval|Function|constructor|__proto__|",
|
|
@@ -481,8 +1619,7 @@ function readCodeExtension(schema, key, options) {
|
|
|
481
1619
|
if (!isSafeCodeExtension(raw)) return void 0;
|
|
482
1620
|
return raw;
|
|
483
1621
|
}
|
|
484
|
-
|
|
485
|
-
//#region src/helper/arktype-wrap.ts
|
|
1622
|
+
// src/helper/arktype-wrap.ts
|
|
486
1623
|
/**
|
|
487
1624
|
* A definition a callback checks values against at validation time. Inside
|
|
488
1625
|
* `scope({...})` it goes through the scope (bound to `$`), which resolves the aliases
|
|
@@ -544,8 +1681,7 @@ function arktypeWrap(arktypeStr, schema, options) {
|
|
|
544
1681
|
if (inScope && isDefinition(withCodeExts)) return `[${withCodeExts},"@",${text}]`;
|
|
545
1682
|
return `${isDefinition(withCodeExts) ? `type(${withCodeExts})` : withCodeExts}.describe(${text})`;
|
|
546
1683
|
}
|
|
547
|
-
|
|
548
|
-
//#region src/helper/schema.ts
|
|
1684
|
+
// src/helper/schema.ts
|
|
549
1685
|
/** `definitions` and `$defs` read as one map, `$defs` winning on a shared name. */
|
|
550
1686
|
function collectDefinitions(schema) {
|
|
551
1687
|
return {
|
|
@@ -584,8 +1720,7 @@ function hasKeptDefault(schema, definitions) {
|
|
|
584
1720
|
function isOptionalByDefault(schema, definitions) {
|
|
585
1721
|
return hasKeptDefault(schema, definitions) || schema.allOf?.some(isDefaultOnlyMember) === true;
|
|
586
1722
|
}
|
|
587
|
-
|
|
588
|
-
//#region src/helper/cyclic.ts
|
|
1723
|
+
// src/helper/cyclic.ts
|
|
589
1724
|
/**
|
|
590
1725
|
* The definition a local `$ref` names, in any form the generators understand:
|
|
591
1726
|
* `#/definitions/X`, `#/$defs/X` and the bare `#X` shorthand. `undefined` for the
|
|
@@ -676,8 +1811,7 @@ function cyclicDefinitionNames(schema) {
|
|
|
676
1811
|
for (const name of Object.keys(definitions).toSorted()) visit(name);
|
|
677
1812
|
return cyclic;
|
|
678
1813
|
}
|
|
679
|
-
|
|
680
|
-
//#region src/helper/discriminator.ts
|
|
1814
|
+
// src/helper/discriminator.ts
|
|
681
1815
|
function definitionName(ref) {
|
|
682
1816
|
for (const prefix of DEFINITION_REF_PREFIXES) {
|
|
683
1817
|
if (!ref.startsWith(prefix)) continue;
|
|
@@ -712,8 +1846,7 @@ function discriminatedMembers(schema, members) {
|
|
|
712
1846
|
})
|
|
713
1847
|
};
|
|
714
1848
|
}
|
|
715
|
-
|
|
716
|
-
//#region src/helper/resolve-schema-dependencies-from-schema.ts
|
|
1849
|
+
// src/helper/resolve-schema-dependencies-from-schema.ts
|
|
717
1850
|
/** The definition name the fragment of an external `$ref` points at, if it names one. */
|
|
718
1851
|
function fragmentDefinitionName(fragment) {
|
|
719
1852
|
return /^\/(?:definitions|\$defs)\/(?<name>[^/]+)$/u.exec(fragment)?.groups?.name ?? /^\/(?<name>[^/]+)$/u.exec(fragment)?.groups?.name;
|
|
@@ -775,8 +1908,7 @@ function resolveSchemaDependenciesFromSchema(schema) {
|
|
|
775
1908
|
for (const name of Object.keys(definitions).toSorted()) visit(name);
|
|
776
1909
|
return sorted;
|
|
777
1910
|
}
|
|
778
|
-
|
|
779
|
-
//#region src/helper/document.ts
|
|
1911
|
+
// src/helper/document.ts
|
|
780
1912
|
/** The node options of a document generation, with the unset parameter options left out. */
|
|
781
1913
|
function emitOptionsOf(options) {
|
|
782
1914
|
return {
|
|
@@ -847,8 +1979,7 @@ function renderDefinitions(plan, toName, render) {
|
|
|
847
1979
|
return definition === void 0 ? missingDefinitionComment(name) : render(definition, toName(name));
|
|
848
1980
|
}).join("\n\n");
|
|
849
1981
|
}
|
|
850
|
-
|
|
851
|
-
//#region src/helper/meta.ts
|
|
1982
|
+
// src/helper/meta.ts
|
|
852
1983
|
/**
|
|
853
1984
|
* Host `$ref` name for OpenAPI component registration (hono-openapi
|
|
854
1985
|
* `components.schemas`). TypeBox stores this on the schema at construction
|
|
@@ -910,8 +2041,7 @@ function serializeJSValue(value) {
|
|
|
910
2041
|
if (entries.length === 0) return "{}";
|
|
911
2042
|
return `{${entries.map(([k, v]) => `${makeSafeKey(k)}:${serializeJSValue(v)}`).join(",")}}`;
|
|
912
2043
|
}
|
|
913
|
-
|
|
914
|
-
//#region src/helper/value.ts
|
|
2044
|
+
// src/helper/value.ts
|
|
915
2045
|
/**
|
|
916
2046
|
* A JSON value as the TypeScript literal that reproduces it.
|
|
917
2047
|
*
|
|
@@ -924,8 +2054,34 @@ function jsLiteral(value) {
|
|
|
924
2054
|
if (typeof value === "number") return `${value}`;
|
|
925
2055
|
return JSON.stringify(value);
|
|
926
2056
|
}
|
|
927
|
-
|
|
928
|
-
|
|
2057
|
+
/**
|
|
2058
|
+
* A JS expression that is true when `subject` is deep-equal to the JSON `value`, as JSON
|
|
2059
|
+
* Schema's `const` and `enum` compare: an object regardless of its key order, an array
|
|
2060
|
+
* item by item. Written out for the value, so the generated code needs no helper; an
|
|
2061
|
+
* object's members are read with `Reflect.get`, which takes an `object` as it narrows.
|
|
2062
|
+
*/
|
|
2063
|
+
function deepEqualExpression(value, subject) {
|
|
2064
|
+
if (Array.isArray(value)) return [
|
|
2065
|
+
`Array.isArray(${subject})`,
|
|
2066
|
+
`${subject}.length===${value.length}`,
|
|
2067
|
+
...value.map((item, i) => deepEqualExpression(item, `${subject}[${i}]`))
|
|
2068
|
+
].join("&&");
|
|
2069
|
+
if (typeof value === "object" && value !== null) {
|
|
2070
|
+
const entries = Object.entries(value);
|
|
2071
|
+
return [
|
|
2072
|
+
`typeof ${subject}==='object'`,
|
|
2073
|
+
`${subject}!==null`,
|
|
2074
|
+
`!Array.isArray(${subject})`,
|
|
2075
|
+
`Object.keys(${subject}).length===${entries.length}`,
|
|
2076
|
+
...entries.flatMap(([key, member]) => {
|
|
2077
|
+
const k = JSON.stringify(key);
|
|
2078
|
+
return [`Object.hasOwn(${subject},${k})`, deepEqualExpression(member, `Reflect.get(${subject},${k})`)];
|
|
2079
|
+
})
|
|
2080
|
+
].join("&&");
|
|
2081
|
+
}
|
|
2082
|
+
return `${subject}===${value === null ? "null" : jsLiteral(value)}`;
|
|
2083
|
+
}
|
|
2084
|
+
// src/helper/format.ts
|
|
929
2085
|
/** A regular expression as the literal that reproduces it in generated source. */
|
|
930
2086
|
function regexSource(pattern) {
|
|
931
2087
|
return `/${pattern.source}/${pattern.flags}`;
|
|
@@ -1002,8 +2158,7 @@ function formatPattern(schema, format) {
|
|
|
1002
2158
|
const pattern = FORMAT_PATTERNS[format];
|
|
1003
2159
|
return pattern === void 0 ? void 0 : regexSource(pattern);
|
|
1004
2160
|
}
|
|
1005
|
-
|
|
1006
|
-
//#region src/helper/wire.ts
|
|
2161
|
+
// src/helper/wire.ts
|
|
1007
2162
|
/**
|
|
1008
2163
|
* What the generators share about a value read off the string wire — a query, path,
|
|
1009
2164
|
* header, cookie or form field — beyond the coercion each library spells its own way.
|
|
@@ -1097,8 +2252,7 @@ function wireDefaultValue(value) {
|
|
|
1097
2252
|
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return String(value);
|
|
1098
2253
|
return value;
|
|
1099
2254
|
}
|
|
1100
|
-
|
|
1101
|
-
//#region src/helper/effect-wrap.ts
|
|
2255
|
+
// src/helper/effect-wrap.ts
|
|
1102
2256
|
/** `inner` read after `reader`, a `(input) => ...` arrow over the raw value. */
|
|
1103
2257
|
function effectPreprocess(readers, inner) {
|
|
1104
2258
|
if (readers.length === 0) return inner;
|
|
@@ -1154,8 +2308,7 @@ function effectWrap(effectStr, schema, options) {
|
|
|
1154
2308
|
if (Object.keys(ann).length === 0) return withDefault;
|
|
1155
2309
|
return `${withDefault}.annotate(${serializeJSValue(ann)})`;
|
|
1156
2310
|
}
|
|
1157
|
-
|
|
1158
|
-
//#region src/helper/hoist-refs.ts
|
|
2311
|
+
// src/helper/hoist-refs.ts
|
|
1159
2312
|
/** Keywords whose values are data, not schemas: a `$ref` string there is not a reference. */
|
|
1160
2313
|
const DATA_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1161
2314
|
"const",
|
|
@@ -1253,8 +2406,7 @@ function hoistNestedRefs(schema) {
|
|
|
1253
2406
|
}
|
|
1254
2407
|
};
|
|
1255
2408
|
}
|
|
1256
|
-
|
|
1257
|
-
//#region src/helper/not.ts
|
|
2409
|
+
// src/helper/not.ts
|
|
1258
2410
|
/** Whether the schema's values are bigints (`int64`, `uint64`, `bigint`). */
|
|
1259
2411
|
function isBigintFormat(schema) {
|
|
1260
2412
|
return schema.format === "int64" || schema.format === "uint64" || schema.format === "bigint";
|
|
@@ -1305,8 +2457,7 @@ function notPredicate(inner, param, parameter = param, bigint = false) {
|
|
|
1305
2457
|
if (bodies.length > 0) return `(${parameter}) => ${bodies.join(" && ")}`;
|
|
1306
2458
|
}
|
|
1307
2459
|
}
|
|
1308
|
-
|
|
1309
|
-
//#region src/helper/parameter.ts
|
|
2460
|
+
// src/helper/parameter.ts
|
|
1310
2461
|
/**
|
|
1311
2462
|
* How an OpenAPI Parameter Object's text is read into the value its schema describes:
|
|
1312
2463
|
* `allowEmptyValue`, a JSON `content`, or its `style` / `explode`. Every reader is the
|
|
@@ -1437,8 +2588,7 @@ function parameterReaders(schema, options, param) {
|
|
|
1437
2588
|
const reader = isJsonMediaType(options?.contentType) ? jsonReader(param) : style === void 0 ? void 0 : styleReader(param, schema, style, options?.explode ?? style === "form");
|
|
1438
2589
|
return [options?.allowEmptyValue === true ? emptyValueReader(param) : void 0, reader].filter((step) => step !== void 0);
|
|
1439
2590
|
}
|
|
1440
|
-
|
|
1441
|
-
//#region src/helper/polymorphic-base.ts
|
|
2591
|
+
// src/helper/polymorphic-base.ts
|
|
1442
2592
|
/** The definition name a `$ref` names and the prefix it is written with. */
|
|
1443
2593
|
function refParts(ref) {
|
|
1444
2594
|
for (const prefix of DEFINITION_REF_PREFIXES) {
|
|
@@ -1522,8 +2672,7 @@ function withPolymorphicBases(schema) {
|
|
|
1522
2672
|
...definitions !== void 0 && { definitions }
|
|
1523
2673
|
};
|
|
1524
2674
|
}
|
|
1525
|
-
|
|
1526
|
-
//#region src/helper/ref.ts
|
|
2675
|
+
// src/helper/ref.ts
|
|
1527
2676
|
/**
|
|
1528
2677
|
* Resolves a `$ref` for the Zod, Valibot and Effect generators, which name declarations
|
|
1529
2678
|
* alike: a definition is `Name` inside a document (`isDocument`), `NameSchema` when a
|
|
@@ -1578,8 +2727,156 @@ function refTarget(ref, rootName, isDocument, openapi) {
|
|
|
1578
2727
|
}
|
|
1579
2728
|
return { kind: "any" };
|
|
1580
2729
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
2730
|
+
// src/helper/sanitize.ts
|
|
2731
|
+
const SHAPES = {
|
|
2732
|
+
$schema: "string",
|
|
2733
|
+
$id: "string",
|
|
2734
|
+
$ref: "string",
|
|
2735
|
+
$comment: "string",
|
|
2736
|
+
$anchor: "string",
|
|
2737
|
+
$dynamicAnchor: "string",
|
|
2738
|
+
$dynamicRef: "string",
|
|
2739
|
+
$vocabulary: "object",
|
|
2740
|
+
$defs: "schemaMap",
|
|
2741
|
+
definitions: "schemaMap",
|
|
2742
|
+
title: "string",
|
|
2743
|
+
description: "string",
|
|
2744
|
+
examples: "examples",
|
|
2745
|
+
deprecated: "boolean",
|
|
2746
|
+
readOnly: "boolean",
|
|
2747
|
+
writeOnly: "boolean",
|
|
2748
|
+
type: "type",
|
|
2749
|
+
format: "string",
|
|
2750
|
+
enum: "array",
|
|
2751
|
+
minLength: "count",
|
|
2752
|
+
maxLength: "count",
|
|
2753
|
+
pattern: "string",
|
|
2754
|
+
contentMediaType: "string",
|
|
2755
|
+
contentEncoding: "string",
|
|
2756
|
+
contentSchema: "schema",
|
|
2757
|
+
minimum: "number",
|
|
2758
|
+
maximum: "number",
|
|
2759
|
+
exclusiveMinimum: "numberOrBoolean",
|
|
2760
|
+
exclusiveMaximum: "numberOrBoolean",
|
|
2761
|
+
multipleOf: "positive",
|
|
2762
|
+
properties: "schemaMap",
|
|
2763
|
+
required: "stringList",
|
|
2764
|
+
additionalProperties: "schema",
|
|
2765
|
+
patternProperties: "schemaMap",
|
|
2766
|
+
propertyNames: "schema",
|
|
2767
|
+
minProperties: "count",
|
|
2768
|
+
maxProperties: "count",
|
|
2769
|
+
dependentRequired: "dependentRequired",
|
|
2770
|
+
dependentSchemas: "schemaMap",
|
|
2771
|
+
dependencies: "dependencies",
|
|
2772
|
+
unevaluatedProperties: "schema",
|
|
2773
|
+
items: "schemaOrList",
|
|
2774
|
+
additionalItems: "schema",
|
|
2775
|
+
prefixItems: "schemaList",
|
|
2776
|
+
contains: "schema",
|
|
2777
|
+
minItems: "count",
|
|
2778
|
+
maxItems: "count",
|
|
2779
|
+
uniqueItems: "boolean",
|
|
2780
|
+
minContains: "count",
|
|
2781
|
+
maxContains: "count",
|
|
2782
|
+
unevaluatedItems: "schema",
|
|
2783
|
+
allOf: "schemaList",
|
|
2784
|
+
anyOf: "schemaList",
|
|
2785
|
+
oneOf: "schemaList",
|
|
2786
|
+
not: "schema",
|
|
2787
|
+
if: "schema",
|
|
2788
|
+
then: "schema",
|
|
2789
|
+
else: "schema",
|
|
2790
|
+
nullable: "boolean",
|
|
2791
|
+
discriminator: "discriminator",
|
|
2792
|
+
xml: "object",
|
|
2793
|
+
externalDocs: "object"
|
|
2794
|
+
};
|
|
2795
|
+
/** A schema position holds an object or a boolean schema. */
|
|
2796
|
+
function isSchemaValue(value) {
|
|
2797
|
+
return typeof value === "boolean" || isPlainObject(value);
|
|
2798
|
+
}
|
|
2799
|
+
function sanitizeNode(node) {
|
|
2800
|
+
return isPlainObject(node) ? sanitizeObject(node) : node;
|
|
2801
|
+
}
|
|
2802
|
+
function stringMap(value) {
|
|
2803
|
+
if (!isPlainObject(value)) return void 0;
|
|
2804
|
+
return Object.fromEntries(Object.entries(value).flatMap(([k, v]) => typeof v === "string" ? [[k, v]] : []));
|
|
2805
|
+
}
|
|
2806
|
+
/**
|
|
2807
|
+
* `value` as `shape` has it: the value itself, a cleaned copy, or `undefined` when nothing
|
|
2808
|
+
* of it has the shape.
|
|
2809
|
+
*/
|
|
2810
|
+
function conform(shape, value) {
|
|
2811
|
+
switch (shape) {
|
|
2812
|
+
case "string": return typeof value === "string" ? value : void 0;
|
|
2813
|
+
case "boolean": return typeof value === "boolean" ? value : void 0;
|
|
2814
|
+
case "number": return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
2815
|
+
case "count": return Number.isInteger(value) && Number(value) >= 0 ? value : void 0;
|
|
2816
|
+
case "positive": return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
|
|
2817
|
+
case "numberOrBoolean": return typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
2818
|
+
case "type": {
|
|
2819
|
+
if (typeof value === "string") return value;
|
|
2820
|
+
if (!Array.isArray(value)) return void 0;
|
|
2821
|
+
const types = value.filter((t) => typeof t === "string");
|
|
2822
|
+
return types.length > 0 ? types : void 0;
|
|
2823
|
+
}
|
|
2824
|
+
case "stringList": return Array.isArray(value) ? value.flatMap((v) => typeof v === "string" ? [v] : isPlainObject(v) || Array.isArray(v) ? [] : [String(v)]) : void 0;
|
|
2825
|
+
case "array": return Array.isArray(value) ? value : void 0;
|
|
2826
|
+
case "object": return isPlainObject(value) ? value : void 0;
|
|
2827
|
+
case "schema": return isSchemaValue(value) ? sanitizeNode(value) : void 0;
|
|
2828
|
+
case "schemaOrList": return Array.isArray(value) ? conform("schemaList", value) : conform("schema", value);
|
|
2829
|
+
case "schemaList": return Array.isArray(value) ? value.filter(isSchemaValue).map(sanitizeNode) : void 0;
|
|
2830
|
+
case "schemaMap": return isPlainObject(value) ? Object.fromEntries(Object.entries(value).map(([k, v]) => [k, isSchemaValue(v) ? sanitizeNode(v) : {}])) : void 0;
|
|
2831
|
+
case "dependentRequired": return isPlainObject(value) ? Object.fromEntries(Object.entries(value).flatMap(([k, v]) => {
|
|
2832
|
+
const names = conform("stringList", v);
|
|
2833
|
+
return names === void 0 ? [] : [[k, names]];
|
|
2834
|
+
})) : void 0;
|
|
2835
|
+
case "dependencies": return isPlainObject(value) ? Object.fromEntries(Object.entries(value).flatMap(([k, v]) => {
|
|
2836
|
+
const conformed = Array.isArray(v) ? conform("stringList", v) : conform("schema", v);
|
|
2837
|
+
return conformed === void 0 ? [] : [[k, conformed]];
|
|
2838
|
+
})) : void 0;
|
|
2839
|
+
case "discriminator": {
|
|
2840
|
+
if (!isPlainObject(value) || typeof value.propertyName !== "string") return void 0;
|
|
2841
|
+
const { mapping, defaultMapping, ...rest } = value;
|
|
2842
|
+
const strings = stringMap(mapping);
|
|
2843
|
+
return {
|
|
2844
|
+
...rest,
|
|
2845
|
+
...strings !== void 0 && { mapping: strings },
|
|
2846
|
+
...typeof defaultMapping === "string" && { defaultMapping }
|
|
2847
|
+
};
|
|
2848
|
+
}
|
|
2849
|
+
case "examples": {
|
|
2850
|
+
if (Array.isArray(value)) return value;
|
|
2851
|
+
if (!isPlainObject(value)) return void 0;
|
|
2852
|
+
const values = Object.values(value).flatMap((example) => isPlainObject(example) && example.value !== void 0 ? [example.value] : []);
|
|
2853
|
+
return values.length > 0 ? values : void 0;
|
|
2854
|
+
}
|
|
2855
|
+
default: return;
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
function sanitizeObject(schema) {
|
|
2859
|
+
const out = {};
|
|
2860
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
2861
|
+
const shape = Object.hasOwn(SHAPES, key) ? SHAPES[key] : void 0;
|
|
2862
|
+
if (shape === void 0) {
|
|
2863
|
+
out[key] = value;
|
|
2864
|
+
continue;
|
|
2865
|
+
}
|
|
2866
|
+
const conformed = conform(shape, value);
|
|
2867
|
+
if (conformed !== void 0) out[key] = conformed;
|
|
2868
|
+
}
|
|
2869
|
+
return out;
|
|
2870
|
+
}
|
|
2871
|
+
/**
|
|
2872
|
+
* The document with every keyword whose value does not have the keyword's type left out,
|
|
2873
|
+
* at every schema position. Data keywords (`const`, `default`, `enum` members, `example`)
|
|
2874
|
+
* and extensions are kept as they are.
|
|
2875
|
+
*/
|
|
2876
|
+
function sanitizeSchema(schema) {
|
|
2877
|
+
return isPlainObject(schema) ? sanitizeObject(schema) : schema;
|
|
2878
|
+
}
|
|
2879
|
+
// src/helper/type.ts
|
|
1583
2880
|
/** Whether a node is a 64-bit integer, whose number is a bigint. */
|
|
1584
2881
|
function isInt64(schema) {
|
|
1585
2882
|
return schema.format === "int64" || schema.format === "uint64";
|
|
@@ -1657,8 +2954,7 @@ function nonNullType(schema, flavour, rootName) {
|
|
|
1657
2954
|
if (t.length === 1 && t[0] === "null") return "null";
|
|
1658
2955
|
return "unknown";
|
|
1659
2956
|
}
|
|
1660
|
-
|
|
1661
|
-
//#region src/helper/typebox-wrap.ts
|
|
2957
|
+
// src/helper/typebox-wrap.ts
|
|
1662
2958
|
/**
|
|
1663
2959
|
* Wraps a TypeBox schema string with `Type.Union([..., Type.Null()])` (when nullable),
|
|
1664
2960
|
* `Type.Readonly()` (on `x-readonly`) and, outermost, `Type.Optional()` when a `default`
|
|
@@ -1677,8 +2973,7 @@ function typeboxWrap(typeboxStr, schema, definitions) {
|
|
|
1677
2973
|
const withReadonly = schema["x-readonly"] === true ? `Type.Readonly(${withNullable})` : withNullable;
|
|
1678
2974
|
return hasKeptDefault(schema, definitions) ? `Type.Optional(${withReadonly})` : withReadonly;
|
|
1679
2975
|
}
|
|
1680
|
-
|
|
1681
|
-
//#region src/helper/unevaluated.ts
|
|
2976
|
+
// src/helper/unevaluated.ts
|
|
1682
2977
|
function definitionOf(ref, definitions) {
|
|
1683
2978
|
if (definitions === void 0) return void 0;
|
|
1684
2979
|
for (const prefix of DEFINITION_REF_PREFIXES) {
|
|
@@ -1736,8 +3031,7 @@ function evaluatedProperties(schema, definitions, reading = /* @__PURE__ */ new
|
|
|
1736
3031
|
function isEvaluatedKeyExpression(evaluated, key) {
|
|
1737
3032
|
return [`${JSON.stringify(evaluated.names)}.includes(${key})`, ...evaluated.patterns.map((pattern) => `new RegExp(${JSON.stringify(pattern)}).test(${key})`)].join("||");
|
|
1738
3033
|
}
|
|
1739
|
-
|
|
1740
|
-
//#region src/helper/valibot-wrap.ts
|
|
3034
|
+
// src/helper/valibot-wrap.ts
|
|
1741
3035
|
/** A default as the Valibot literal of the schema's input: a bigint for a 64-bit integer. */
|
|
1742
3036
|
function defaultLiteral(schema, value, stringWire) {
|
|
1743
3037
|
if (stringWire) return jsLiteral(wireDefaultValue(value));
|
|
@@ -1794,8 +3088,7 @@ function valibotWrap(valibotStr, schema, options) {
|
|
|
1794
3088
|
if (schema["x-fallback"] !== void 0) return `v.fallback(${piped},${jsLiteral(schema["x-fallback"])})`;
|
|
1795
3089
|
return piped;
|
|
1796
3090
|
}
|
|
1797
|
-
|
|
1798
|
-
//#region src/helper/zod-wrap.ts
|
|
3091
|
+
// src/helper/zod-wrap.ts
|
|
1799
3092
|
/**
|
|
1800
3093
|
* Wraps a Zod schema string with `.default()`, `.nullable()`, `.brand<...>()`
|
|
1801
3094
|
* and a single Zod v4 metadata chain (`.meta({ ... })`) based on the JSON
|
|
@@ -1848,5 +3141,4 @@ function zodWrap(zodStr, schema, options) {
|
|
|
1848
3141
|
if (preprocess) return preprocess;
|
|
1849
3142
|
return withMeta;
|
|
1850
3143
|
}
|
|
1851
|
-
|
|
1852
|
-
export { callbackReturn as $, wireNullText as A, emitOptionsOf as B, isPrimitiveUnion as C, stringboolTruthyPattern as D, stringboolPattern as E, jsLiteral as F, schemaNamer as G, planDocument as H, typeboxDefaultOpt as I, hasRootSelfReference as J, discriminatedMembers as K, typeboxMetaOpts as L, formatPattern as M, regexSource as N, unionPrimitiveTypes as O, timePattern as P, arktypeWrap as Q, typeboxRefOpt as R, isNullTextRead as S, ownProperties as T, renderDefinitions as U, missingDefinitionComment as V, rootNameOf as W, itemsSchemaOf as X, isOptionalByDefault as Y, arktypePreprocess as Z, effectPreprocess as _, typeboxWrap as a, foldAllOfMembers as at, integerWirePattern as b, withPolymorphicBases as c, regexLiteral as ct, propertyEmitOptions as d, callbackType as et, withoutParameterSerialization as f, hoistNestedRefs as g, valueListLiteral as h, isEvaluatedKeyExpression as i, constraintPredicate as it, wireNumericKind as j, wireArrayOnce as k, hasParameterSerialization as l, notPredicate as m, valibotWrap as n, hasNotKeyword as nt, typeDeclaration as o, isKeywordOnlyMember as ot, isBigintFormat as p, cyclicDefinitionNames as q, evaluatedProperties as r, constraintMessage as rt, refTarget as s, patternSource as st, zodWrap as t, findCodeExtensionKeysInSchema as tt, parameterReaders as u, effectWrap as v, numberWirePattern as w, isNullMatchedFirst as x, impliedWireType as y, definitionsOf as z };
|
|
3144
|
+
export { arktypePreprocess as $, COMPONENT_SCHEMA_REF_PREFIX as $t, wireArrayOnce as A, STRINGBOOL_PATTERN as An, hasFixedLength as At, typeboxRefOpt as B, isObjectPrototypeProperty as Bt, isNullTextRead as C, OFFSET_PATTERN_SOURCE as Cn, valibotErrorPart as Ct, stringboolPattern as D, PARAM_STYLES as Dn, hasCombinator as Dt, ownProperties as E, PARAM_LOCATIONS as En, zodErrorPart as Et, timePattern as F, UNICODE_ESCAPE_PATTERN as Fn, isComposite as Ft, renderDefinitions as G, isRootRef as Gt, emitOptionsOf as H, isPrimitive as Ht, deepEqualExpression as I, UNSAFE_GENERATED_MARKER as In, isDeepLocalPointer as It, discriminatedMembers as J, isStringWireLocation as Jt, rootNameOf as K, isSchemaObject as Kt, jsLiteral as L, VALIBOT_CODE_EXTENSION_KEYS as Ln, isDefaultOnlyMember as Lt, wireNumericKind as M, STRING_FORMATS as Mn, hasStringKeyword as Mt, formatPattern as N, STRING_KEYWORDS as Nn, hasType as Nt, stringboolTruthyPattern as O, QUOTE_OR_BACKSLASH_PATTERN as On, hasConditional as Ot, regexSource as P, STRING_WIRE_LOCATIONS as Pn, isArktypeDefinition as Pt, itemsSchemaOf as Q, ARROW_FUNCTION_PATTERN as Qt, typeboxDefaultOpt as R, WIRE_PRIMITIVE_ORDER as Rn, isNullTypeMember as Rt, isNullMatchedFirst as S, OBJECT_PROTOTYPE_PROPERTIES as Sn, valibotError as St, numberWirePattern as T, OUTPUT_EXTENSION as Tn, zodError as Tt, missingDefinitionComment as U, isQuoted as Ut, definitionsOf as V, isPlainObject as Vt, planDocument as W, isRecord as Wt, hasRootSelfReference as X, ANCHOR_REF_PATTERN as Xt, cyclicDefinitionNames as Y, ALL_CODE_EXTENSION_KEYS as Yt, isOptionalByDefault as Z, ARKTYPE_CODE_EXTENSION_KEYS as Zt, hoistNestedRefs as _, NOT_KEYWORD_UNSUPPORTED_MARKER as _n, makeSafeKey as _t, typeboxWrap as a, DEFINITION_REF_PREFIXES as an, constraintMessage as at, impliedWireType as b, NUMBER_WIRE_PATTERN as bn, toIdentifierPascalCase as bt, refTarget as c, IDENTIFIER_PATTERN as cn, isKeywordOnlyMember as ct, parameterReaders as d, INTEGER_TEXT_PATTERN as dn, coerceDefault as dt, CONTENT_ENCODINGS as en, arktypeWrap as et, propertyEmitOptions as f, INTEGER_WIRE_PATTERN as fn, effectError as ft, valueListLiteral as g, NON_IDENTIFIER_CHARACTER_PATTERN as gn, issueMessageExpression as gt, notPredicate as h, MISSING_DEFINITION_PREFIX as hn, encodeNonAscii as ht, isEvaluatedKeyExpression as i, DEFINITION_POINTER_PATTERN as in, hasNotKeyword as it, wireNullText as j, STRINGBOOL_TRUTHY_PATTERN as jn, hasNumericKeyword as jt, unionPrimitiveTypes as k, ROOT_REFS as kn, hasFixedItemCount as kt, withPolymorphicBases as l, IF_THEN_ELSE_UNSUPPORTED_MARKER as ln, patternSource as lt, isBigintFormat as m, JSON_SCHEMA_TYPES as mn, effectMessage as mt, valibotWrap as n, DEFAULT_ROOT_NAME as nn, callbackType as nt, typeDeclaration as o, EFFECT_CODE_EXTENSION_KEYS as on, constraintPredicate as ot, withoutParameterSerialization as p, ISO_4217_CURRENCY_CODES as pn, effectErrorPart as pt, schemaNamer as q, isShapelessMember as qt, evaluatedProperties as r, DEFINITION_KEYWORDS as rn, findCodeExtensionKeysInSchema as rt, sanitizeSchema as s, FORMAT_PATTERNS as sn, foldAllOfMembers as st, zodWrap as t, DATE_PATTERN_SOURCE as tn, callbackReturn as tt, hasParameterSerialization as u, INPUT_EXTENSIONS as un, regexLiteral as ut, effectPreprocess as v, NUMBER_FORMATS as vn, normalizeTypes as vt, isPrimitiveUnion as w, OPENAPI_COMPONENT_SUFFIX_MAP as wn, zodBaseError as wt, integerWirePattern as x, NUMERIC_KEYWORDS as xn, toPascalCase as xt, effectWrap as y, NUMBER_RANGES as yn, resolveOpenAPIRef as yt, typeboxMetaOpts as z, ZOD_CODE_EXTENSION_KEYS as zn, isNullable as zt };
|