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,1146 +0,0 @@
1
- //#region 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
- //#endregion
595
- //#region src/guard/index.ts
596
- /**
597
- * Whether a value is a non-null object — the shape every schema walk descends into.
598
- *
599
- * `typeof null === 'object'` is the one case worth spelling out; arrays pass, which is
600
- * what the walkers want, since a combinator list is an array of schemas.
601
- */
602
- function isRecord(value) {
603
- return typeof value === "object" && value !== null;
604
- }
605
- /**
606
- * A non-array object. Distinct from {@link isRecord}: an enum member that is an array
607
- * needs a tuple matcher, and one that is a plain object needs an object matcher, so the
608
- * two are told apart here rather than lumped together.
609
- */
610
- function isPlainObject(value) {
611
- return typeof value === "object" && value !== null && !Array.isArray(value);
612
- }
613
- /** A JSON scalar: what a `literal` matcher can take as is. */
614
- function isPrimitive(value) {
615
- return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
616
- }
617
- /** An array or object value: one that needs a structural matcher rather than a literal. */
618
- function isComposite(value) {
619
- return typeof value === "object" && value !== null;
620
- }
621
- /** Whether a key can be written bare in an object literal or as a member access. */
622
- function isValidIdentifier(name) {
623
- return IDENTIFIER_PATTERN.test(name);
624
- }
625
- /**
626
- * Whether a configured message is source text for an arrow function rather than a
627
- * literal sentence.
628
- *
629
- * The `x-*-message` extensions accept either, and a library that takes a callback
630
- * (Zod's `error`, Valibot's message argument) gets the source through unquoted.
631
- */
632
- function isArrowExpression(source) {
633
- return ARROW_FUNCTION_PATTERN.test(source);
634
- }
635
- /** Whether a key holds a document's named definitions (`$defs` or `definitions`). */
636
- function isDefinitionKeyword(key) {
637
- return DEFINITION_KEYWORDS.some((keyword) => keyword === key);
638
- }
639
- /** Whether a parameter location delivers its values as strings that have to be coerced. */
640
- function isStringWireLocation(paramIn) {
641
- return STRING_WIRE_LOCATIONS.some((location) => location === paramIn);
642
- }
643
- /**
644
- * Whether a property name is one every plain object inherits (`constructor`, `toString`,
645
- * ...), so reading it off a parameter object that never carried it finds a function.
646
- */
647
- function isObjectPrototypeProperty(name) {
648
- return OBJECT_PROTOTYPE_PROPERTIES.some((property) => property === name);
649
- }
650
- /** Whether a `$ref` names the whole document — the schema being emitted refers to itself. */
651
- function isRootRef(ref) {
652
- return ROOT_REFS.some((root) => root === ref);
653
- }
654
- /**
655
- * True for a local JSON Pointer `$ref` that points *into* a component
656
- * sub-schema (e.g. `#/components/schemas/X/properties/Y`) rather than at a
657
- * top-level component (`#/components/schemas/X`). Such pointers have no
658
- * generated declaration, so generators emit an `unknown` schema for them
659
- * instead of referencing an undeclared identifier.
660
- *
661
- * @example
662
- * ```ts
663
- * isDeepLocalPointer('#/components/schemas/User') // false
664
- * isDeepLocalPointer('#/components/schemas/User/properties/x') // true
665
- * ```
666
- */
667
- function isDeepLocalPointer($ref) {
668
- if (!$ref.startsWith("#/")) return false;
669
- const fragment = $ref.slice(2);
670
- const matched = [
671
- "components/schemas/",
672
- "definitions/",
673
- "$defs/"
674
- ].find((c) => fragment.startsWith(c));
675
- return matched ? fragment.slice(matched.length).includes("/") : false;
676
- }
677
- /**
678
- * JSON Schema 2020-12 §4.3.2 / §10.3.1.2: `items`, `additionalProperties`,
679
- * `unevaluatedItems` and `unevaluatedProperties` may be an object schema or a boolean
680
- * schema (`true` = pass-through, `false` = reject), and `items` may also be a Draft-04
681
- * tuple. This narrows the union to the single object form so callers can recurse.
682
- */
683
- function isSchemaObject(value) {
684
- return typeof value === "object" && !Array.isArray(value);
685
- }
686
- /** Draft-04's tuple form of `items`: a list of schemas rather than a single one. */
687
- function isSchemaList(value) {
688
- return Array.isArray(value);
689
- }
690
- /** Whether a node admits `null`: OpenAPI 3.0 `nullable`, or `null` among its types. */
691
- function isNullable(schema) {
692
- return schema.nullable === true || hasType(schema, "null");
693
- }
694
- /**
695
- * Whether a node takes `null`: a nullable type, a `null` among its `enum`, a `const: null`
696
- * or a `oneOf` / `anyOf` member that does.
697
- */
698
- function canBeNull(schema) {
699
- if (isNullable(schema)) return true;
700
- if (schema.const === null) return true;
701
- if (schema.enum?.some((value) => value === null)) return true;
702
- return [...schema.oneOf ?? [], ...schema.anyOf ?? []].some(canBeNull);
703
- }
704
- /**
705
- * Whether a node may take a string: a `string` type, a string among its `enum` or `const`,
706
- * a `oneOf` / `anyOf` member that does, or no constraint on the type at all.
707
- */
708
- function canBeString(schema) {
709
- if (hasType(schema, "string")) return true;
710
- if (typeof schema.const === "string") return true;
711
- if (schema.enum !== void 0) return schema.enum.some((value) => typeof value === "string");
712
- const members = [...schema.oneOf ?? [], ...schema.anyOf ?? []];
713
- if (members.length > 0) return members.some(canBeString);
714
- 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;
715
- }
716
- /** Whether a node without a `type` carries a keyword that only applies to a number. */
717
- function hasNumericKeyword(schema) {
718
- return NUMERIC_KEYWORDS.some((keyword) => schema[keyword] !== void 0);
719
- }
720
- /** Whether a node without a `type` carries a keyword that only applies to a string. */
721
- function hasStringKeyword(schema) {
722
- return STRING_KEYWORDS.some((keyword) => schema[keyword] !== void 0);
723
- }
724
- /** Whether `type` names `type`, either alone or as one of a list. */
725
- function hasType(schema, type) {
726
- const types = schema.type;
727
- if (types === void 0) return false;
728
- if (typeof types === "string") return types === type;
729
- return types.some((candidate) => candidate === type);
730
- }
731
- /** Whether a node is composed of other schemas: `oneOf`, `anyOf`, `allOf` or `not`. */
732
- function hasCombinator(schema) {
733
- return schema.oneOf !== void 0 || schema.anyOf !== void 0 || schema.allOf !== void 0 || schema.not !== void 0;
734
- }
735
- /** Whether a node carries a conditional (`if` / `then` / `else`). */
736
- function hasConditional(schema) {
737
- return schema.if !== void 0 || schema.then !== void 0 || schema.else !== void 0;
738
- }
739
- /** Whether `minLength` and `maxLength` pin a string to exactly one length. */
740
- function hasFixedLength(schema) {
741
- return schema.minLength !== void 0 && schema.maxLength !== void 0 && schema.minLength === schema.maxLength;
742
- }
743
- /** Whether `minItems` and `maxItems` pin an array to exactly one length. */
744
- function hasFixedItemCount(schema) {
745
- return typeof schema.minItems === "number" && typeof schema.maxItems === "number" && schema.minItems === schema.maxItems;
746
- }
747
- /**
748
- * An `allOf` member that only says "and it may be null".
749
- *
750
- * OpenAPI 3.0 spells a nullable composition as `allOf: [{...}, { nullable: true }]`, and
751
- * a bare `{ type: 'null' }` is the JSON Schema equivalent. Neither contributes a shape,
752
- * so every generator lifts it out of the intersection and onto the result instead.
753
- */
754
- function isNullTypeMember(schema) {
755
- return schema.type === "null" || schema.nullable === true && Object.keys(schema).length === 1;
756
- }
757
- /**
758
- * An `allOf` member that only carries a `default`.
759
- *
760
- * A default is metadata on the composed value rather than a constraint of its own, so it
761
- * is applied to the intersection rather than intersected into it.
762
- */
763
- function isDefaultOnlyMember(schema) {
764
- return Object.keys(schema).length === 1 && schema.default !== void 0;
765
- }
766
- /**
767
- * An `allOf` member that only carries a `const`.
768
- *
769
- * The other members already describe the shape; a lone `const` would narrow it to a
770
- * single value in a way none of the target libraries express as an intersection, so it is
771
- * dropped rather than emitted.
772
- */
773
- function isConstOnlyMember(schema) {
774
- return Object.keys(schema).length === 1 && schema.const !== void 0;
775
- }
776
- /**
777
- * True for an `allOf` member that carries no shape of its own — the ones every generator
778
- * filters out before intersecting what is left.
779
- */
780
- function isShapelessMember(schema) {
781
- return isNullTypeMember(schema) || isDefaultOnlyMember(schema) || isConstOnlyMember(schema);
782
- }
783
- /** A double-quoted string literal: the ArkType string DSL form of a definition. */
784
- function isQuoted(source) {
785
- return source.startsWith("\"") && source.endsWith("\"");
786
- }
787
- /**
788
- * A bare ArkType definition — a string, object or tuple literal — as opposed to
789
- * an expression that already evaluates to a `Type` and so carries methods.
790
- */
791
- function isArktypeDefinition(source) {
792
- return isQuoted(source) || source.startsWith("{") && source.endsWith("}") || source.startsWith("[") && source.endsWith("]");
793
- }
794
- //#endregion
795
- //#region src/utils/index.ts
796
- /**
797
- * Convert string to PascalCase (first character uppercase).
798
- *
799
- * When the input contains characters that are not valid in a TypeScript
800
- * identifier (whitespace, dots, slashes, etc.) the input is routed through
801
- * {@link toIdentifierPascalCase} so the generated variable name remains
802
- * parseable. Hyphens and underscores are preserved for back-compat with
803
- * upstream titles that already generated working code.
804
- *
805
- * @example
806
- * ```ts
807
- * toPascalCase('animal') // 'Animal'
808
- * toPascalCase('userProfile') // 'UserProfile'
809
- * toPascalCase('Self-Referencing Entities') // 'SelfReferencingEntities'
810
- * ```
811
- */
812
- function toPascalCase(name) {
813
- if (NON_IDENTIFIER_CHARACTER_PATTERN.test(name)) return toIdentifierPascalCase(name);
814
- return name.charAt(0).toUpperCase() + name.slice(1);
815
- }
816
- /**
817
- * Encode non-ASCII characters as `u<hex codepoint>` so they survive identifier
818
- * normalization instead of being stripped (which collapses every non-ASCII name
819
- * to the same `Schema`, producing duplicate declarations). Pure-ASCII input is
820
- * returned unchanged, so identifier generation stays byte-for-byte identical for
821
- * the overwhelming majority of specs.
822
- *
823
- * @example
824
- * ```ts
825
- * encodeNonAscii('User') // 'User'
826
- * encodeNonAscii('日本語') // 'u65e5u672cu8a9e'
827
- * ```
828
- */
829
- function encodeNonAscii(name) {
830
- return [...name].map((ch) => {
831
- const cp = ch.codePointAt(0) ?? 0;
832
- return cp > 127 ? `u${cp.toString(16)}` : ch;
833
- }).join("");
834
- }
835
- /**
836
- * Convert string to a valid PascalCase identifier.
837
- *
838
- * Splits by non-alphanumeric characters and capitalizes each segment.
839
- * Handles hyphens, underscores, dots, spaces, leading numbers, and non-ASCII characters.
840
- *
841
- * @example
842
- * ```ts
843
- * toIdentifierPascalCase('user-name') // 'UserName'
844
- * toIdentifierPascalCase('hello_world') // 'HelloWorld'
845
- * toIdentifierPascalCase('123value') // '_123Value'
846
- * toIdentifierPascalCase('user') // 'User'
847
- * ```
848
- */
849
- function toIdentifierPascalCase(name) {
850
- const parts = encodeNonAscii(name).split(/[^a-zA-Z0-9]+/u).filter(Boolean);
851
- if (parts.length === 0) return DEFAULT_ROOT_NAME;
852
- const result = parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
853
- if (/^[0-9]/u.test(result)) return `_${result}`.replace(/([0-9])([a-z])/u, (_, d, c) => `${d}${c.toUpperCase()}`);
854
- return result;
855
- }
856
- function normalizeTypes(t) {
857
- if (t === void 0) return [];
858
- if (typeof t === "string") return [t];
859
- return [...t];
860
- }
861
- /**
862
- * Reconcile a schema's `default` value with the type the schema actually emits
863
- * so the generated `.default(...)` stays assignable. The default is kept only
864
- * when it is a value of the schema, read the way a document usually writes it:
865
- *
866
- * - `null` is kept only on a nullable schema (or one whose `enum` lists it).
867
- * - an `enum` / `const` takes only what it lists.
868
- * - text that spells a value of the schema's type is read as that value: `'true'`
869
- * for a boolean, `'7'` for a number or an integer; a number or a boolean for a
870
- * string is written as text. Any other scalar of the wrong type is dropped
871
- * (`'null'` for an integer, `'strict'` with the quotes for an enum).
872
- * - an array keeps its items when every one is a value of `items`.
873
- * - an object default drops keys the schema does not declare, when the emitted
874
- * object has no index signature (`additionalProperties` is not `true` or a
875
- * schema, and there are no `patternProperties`), and needs every `required`
876
- * key. A loose or record schema keeps every key.
877
- * - a `$ref`, or an `allOf` the node has no type of its own beside, is read as
878
- * the definition it names when `definitions` has it; a `oneOf` / `anyOf` keeps
879
- * the default when a member takes it, whatever `type` sits beside it.
880
- * - a node with nothing to check against (no `type`, an unknown `$ref`) keeps
881
- * the default as written.
882
- *
883
- * JSON Schema 2020-12 §9.9.4.1 treats `default` as an annotation with no
884
- * validity guarantee, so an invalid one is dropped rather than reported.
885
- *
886
- * @example
887
- * ```ts
888
- * coerceDefault({ type: 'boolean' }, 'true') // { keep: true, value: true }
889
- * coerceDefault({ type: 'number' }, '7') // { keep: true, value: 7 }
890
- * coerceDefault({ type: 'object' }, null) // { keep: false, value: null }
891
- * coerceDefault({ type: 'object', nullable: true }, null) // { keep: true, value: null }
892
- * coerceDefault({ type: 'array' }, 'eval') // { keep: false, value: 'eval' }
893
- * coerceDefault({ enum: ['a', 'b'] }, "'a'") // { keep: false, value: "'a'" }
894
- * ```
895
- */
896
- function coerceDefault(schema, value, definitions) {
897
- return conformDefault(schema, value, definitions, /* @__PURE__ */ new Set());
898
- }
899
- function conformDefault(schema, value, definitions, reading) {
900
- const drop = {
901
- keep: false,
902
- value
903
- };
904
- const asIs = {
905
- keep: true,
906
- value
907
- };
908
- const conform = (s, v, r = reading) => conformDefault(s, v, definitions, r);
909
- if (schema.$ref !== void 0) {
910
- const target = reading.has(schema.$ref) ? void 0 : definitionOf(schema.$ref, definitions);
911
- if (target === void 0) return value === null && schema.nullable !== true ? drop : asIs;
912
- const { $ref, ...beside } = schema;
913
- return conform({
914
- ...target,
915
- ...beside
916
- }, value, /* @__PURE__ */ new Set([...reading, $ref]));
917
- }
918
- const types = normalizeTypes(schema.type);
919
- const isNullable = schema.nullable === true || types.includes("null") || schema.enum?.includes(null) === true || schema.const === null;
920
- if (value === null) {
921
- if (isNullable) return asIs;
922
- return [...schema.oneOf ?? [], ...schema.anyOf ?? []].some((member) => conform(member, null).keep) ? asIs : drop;
923
- }
924
- const members = schema.oneOf ?? schema.anyOf;
925
- if (members !== void 0 && members.length > 0) {
926
- const results = members.map((member) => conform(member, value));
927
- return results.find((result) => result.keep && result.value === value) ?? results.find((result) => result.keep) ?? drop;
928
- }
929
- if (schema.enum !== void 0) return schema.enum.some((member) => member === value) ? asIs : drop;
930
- if (schema.const !== void 0) return JSON.stringify(schema.const) === JSON.stringify(value) ? asIs : drop;
931
- if (types.length === 0 && schema.allOf !== void 0) return schema.allOf.filter((member) => {
932
- const memberTypes = normalizeTypes(member.type);
933
- return memberTypes.length === 0 || memberTypes.some((t) => t !== "null");
934
- }).reduce((result, member) => result.keep ? conform(member, result.value) : result, asIs);
935
- const valueTypes = types.filter((t) => t !== "null");
936
- if (types.length > 0 && valueTypes.length === 0) return drop;
937
- if (valueTypes.length === 0) return schema.properties !== void 0 ? readObject(schema, value, conform) ?? drop : asIs;
938
- const read = (type) => {
939
- if (type === "boolean") {
940
- if (typeof value === "boolean") return asIs;
941
- if (value === "true" || value === "false") return {
942
- keep: true,
943
- value: value === "true"
944
- };
945
- return;
946
- }
947
- if (type === "number" || type === "integer") {
948
- const number = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" && Number.isFinite(Number(value)) ? Number(value) : void 0;
949
- if (number === void 0) return void 0;
950
- if (type === "integer" && !Number.isInteger(number)) return void 0;
951
- return {
952
- keep: true,
953
- value: number
954
- };
955
- }
956
- if (type === "string") {
957
- if (typeof value === "string") return asIs;
958
- if (typeof value === "number" || typeof value === "boolean") return {
959
- keep: true,
960
- value: String(value)
961
- };
962
- return;
963
- }
964
- if (type === "array") {
965
- if (!Array.isArray(value)) return void 0;
966
- const items = schema.items;
967
- if (!isDefaultSchemaObject(items)) return asIs;
968
- const readItems = value.map((item) => conform(items, item));
969
- return readItems.every((item) => item.keep) ? {
970
- keep: true,
971
- value: readItems.map((item) => item.value)
972
- } : void 0;
973
- }
974
- if (type === "object") return readObject(schema, value, conform);
975
- return asIs;
976
- };
977
- const own = valueTypes.find((type) => typeOf(value) === type || type === "number" && typeof value === "number");
978
- return (own === void 0 ? void 0 : read(own)) ?? valueTypes.map(read).find((r) => r !== void 0) ?? drop;
979
- }
980
- /** An object default as a value of the schema, or `undefined` when it is not one. */
981
- function readObject(schema, value, conform) {
982
- if (!isDeclaredObject(value)) return void 0;
983
- if (schema.properties === void 0 || canHoldUndeclaredKeys(schema)) return {
984
- keep: true,
985
- value
986
- };
987
- const declared = schema.properties;
988
- if ((schema.required ?? []).some((key) => !Object.hasOwn(value, key))) return void 0;
989
- const kept = {};
990
- for (const [key, item] of Object.entries(value)) {
991
- if (!Object.hasOwn(declared, key)) continue;
992
- const result = conform(declared[key], item);
993
- if (!result.keep) return void 0;
994
- kept[key] = result.value;
995
- }
996
- return {
997
- keep: true,
998
- value: kept
999
- };
1000
- }
1001
- /** The definition a local `$ref` names, when `definitions` has it. */
1002
- function definitionOf(ref, definitions) {
1003
- if (definitions === void 0) return void 0;
1004
- for (const prefix of DEFINITION_REF_PREFIXES) {
1005
- if (!ref.startsWith(prefix)) continue;
1006
- const rest = ref.slice(prefix.length);
1007
- if (rest === "" || rest.includes("/")) return void 0;
1008
- const name = decodeURIComponent(rest);
1009
- return Object.hasOwn(definitions, name) ? definitions[name] : void 0;
1010
- }
1011
- }
1012
- function typeOf(value) {
1013
- if (typeof value === "boolean") return "boolean";
1014
- if (typeof value === "number") return Number.isInteger(value) ? "integer" : "number";
1015
- if (typeof value === "string") return "string";
1016
- if (Array.isArray(value)) return "array";
1017
- if (isDeclaredObject(value)) return "object";
1018
- }
1019
- function isDefaultSchemaObject(value) {
1020
- return typeof value === "object" && !Array.isArray(value);
1021
- }
1022
- function isDeclaredObject(value) {
1023
- return typeof value === "object" && value !== null && !Array.isArray(value);
1024
- }
1025
- /** Whether a generated object type accepts keys the schema does not name. */
1026
- function canHoldUndeclaredKeys(schema) {
1027
- if (schema.additionalProperties === true || typeof schema.additionalProperties === "object") return true;
1028
- if (schema.patternProperties !== void 0) return true;
1029
- return schema.unevaluatedProperties === true || typeof schema.unevaluatedProperties === "object";
1030
- }
1031
- /**
1032
- * A message as the expression an emitted check evaluates for each issue: an arrow source
1033
- * is applied to the issue, a sentence becomes a string literal.
1034
- *
1035
- * @example
1036
- * ```ts
1037
- * issueMessageExpression('Invalid') // '"Invalid"'
1038
- * issueMessageExpression('(issue) => issue.path[0]') // '((issue) => issue.path[0])(issue)'
1039
- * ```
1040
- */
1041
- function issueMessageExpression(message) {
1042
- return isArrowExpression(message) ? `(${message})(issue)` : JSON.stringify(message);
1043
- }
1044
- /**
1045
- * Format an error message argument using the Zod v4 unified `error` parameter.
1046
- *
1047
- * @example
1048
- * ```ts
1049
- * zodError('Name must be 3-20 characters') // '{error:"Name must be 3-20 characters"}'
1050
- * zodError('(val) => `Expected ${val}`') // '{error:(val) => `Expected ${val}`}'
1051
- * ```
1052
- */
1053
- function zodError(message) {
1054
- return isArrowExpression(message) ? `{error:${message}}` : `{error:${JSON.stringify(message)}}`;
1055
- }
1056
- /** `zodError(message)` as a trailing argument, or nothing when there is no message. */
1057
- function zodErrorPart(message) {
1058
- return message ? `,${zodError(message)}` : "";
1059
- }
1060
- /**
1061
- * Build the base `{error:...}` argument for a Zod v4 schema constructor when
1062
- * `x-error-message` (type / generic) and/or `x-required-message`
1063
- * (`issue.input === undefined`) are present.
1064
- */
1065
- function zodBaseError(typeMessage, requiredMessage) {
1066
- if (typeMessage === void 0 && requiredMessage === void 0) return "";
1067
- if (requiredMessage === void 0 && typeMessage !== void 0) return zodError(typeMessage);
1068
- if (requiredMessage !== void 0 && typeMessage === void 0) return `{error:(issue)=>issue.input===undefined?${JSON.stringify(requiredMessage)}:undefined}`;
1069
- return `{error:(issue)=>issue.input===undefined?${JSON.stringify(requiredMessage)}:${JSON.stringify(typeMessage)}}`;
1070
- }
1071
- /**
1072
- * Format an error message argument for Valibot.
1073
- *
1074
- * @example
1075
- * ```ts
1076
- * valibotError('Must be valid') // '"Must be valid"'
1077
- * valibotError('(issue) => issue.input') // '(issue) => issue.input'
1078
- * ```
1079
- */
1080
- function valibotError(message) {
1081
- return isArrowExpression(message) ? message : JSON.stringify(message);
1082
- }
1083
- /** `valibotError(message)` as a trailing argument, or nothing when there is no message. */
1084
- function valibotErrorPart(message) {
1085
- return message ? `,${valibotError(message)}` : "";
1086
- }
1087
- /**
1088
- * Format an error message annotation for Effect Schema.
1089
- *
1090
- * Effect Schema v4 types the `message` annotation as a plain `string` (v3 took
1091
- * a `() => string` thunk), so an arrow-expression message has no place to go
1092
- * and is emitted as its source text — see {@link effectMessage}.
1093
- *
1094
- * @example
1095
- * ```ts
1096
- * effectError('Required') // '{message:"Required"}'
1097
- * ```
1098
- */
1099
- function effectError(message) {
1100
- return `{message:${effectMessage(message)}}`;
1101
- }
1102
- /** `effectError(message)` as a trailing argument, or nothing when there is no message. */
1103
- function effectErrorPart(message) {
1104
- return message ? `,${effectError(message)}` : "";
1105
- }
1106
- /**
1107
- * The `message` annotation value for Effect Schema v4: a string literal.
1108
- *
1109
- * @example
1110
- * ```ts
1111
- * effectMessage('Required') // '"Required"'
1112
- * ```
1113
- */
1114
- function effectMessage(message) {
1115
- return JSON.stringify(message);
1116
- }
1117
- /**
1118
- * Resolve an OpenAPI $ref string to a variable name with the appropriate suffix
1119
- *
1120
- * @example
1121
- * ```ts
1122
- * resolveOpenAPIRef('#/components/schemas/User') // 'UserSchema'
1123
- * resolveOpenAPIRef('#/components/parameters/UserId') // 'UserIdParamsSchema'
1124
- * resolveOpenAPIRef('#/definitions/Address') // null
1125
- * ```
1126
- */
1127
- function resolveOpenAPIRef($ref) {
1128
- for (const { prefix, suffix } of OPENAPI_COMPONENT_SUFFIX_MAP) if ($ref.startsWith(prefix)) return toIdentifierPascalCase(decodeURIComponent($ref.slice(prefix.length))) + suffix;
1129
- return null;
1130
- }
1131
- /**
1132
- * Encode a property key safely for object literal output.
1133
- * Bare identifiers stay unquoted; everything else is JSON-encoded.
1134
- *
1135
- * @example
1136
- * ```ts
1137
- * makeSafeKey('foo') // 'foo'
1138
- * makeSafeKey('foo-bar') // '"foo-bar"'
1139
- * makeSafeKey('123') // '"123"'
1140
- * ```
1141
- */
1142
- function makeSafeKey(key) {
1143
- return isValidIdentifier(key) ? key : JSON.stringify(key);
1144
- }
1145
- //#endregion
1146
- export { DEFINITION_REF_PREFIXES as $, isDefinitionKeyword as A, UNSAFE_GENERATED_MARKER as At, isSchemaObject as B, hasNumericKeyword as C, ROOT_REFS as Ct, isComposite as D, STRING_KEYWORDS as Dt, isArktypeDefinition as E, STRING_FORMATS as Et, isPrimitive as F, ARKTYPE_CODE_EXTENSION_KEYS as G, isStringWireLocation as H, isQuoted as I, CONTENT_ENCODINGS as J, ARROW_FUNCTION_PATTERN as K, isRecord as L, isNullable as M, WIRE_PRIMITIVE_ORDER as Mt, isObjectPrototypeProperty as N, ZOD_CODE_EXTENSION_KEYS as Nt, isDeepLocalPointer as O, STRING_WIRE_LOCATIONS as Ot, isPlainObject as P, DEFINITION_POINTER_PATTERN as Q, isRootRef as R, hasFixedLength as S, QUOTE_OR_BACKSLASH_PATTERN as St, hasType as T, STRINGBOOL_TRUTHY_PATTERN as Tt, ALL_CODE_EXTENSION_KEYS as U, isShapelessMember as V, ANCHOR_REF_PATTERN as W, DEFAULT_ROOT_NAME as X, DATE_PATTERN_SOURCE as Y, DEFINITION_KEYWORDS as Z, canBeNull as _, OFFSET_PATTERN_SOURCE as _t, encodeNonAscii as a, INTEGER_TEXT_PATTERN as at, hasConditional as b, PARAM_LOCATIONS as bt, normalizeTypes as c, JSON_SCHEMA_TYPES as ct, toPascalCase as d, NOT_KEYWORD_UNSUPPORTED_MARKER as dt, EFFECT_CODE_EXTENSION_KEYS as et, valibotError as f, NUMBER_FORMATS as ft, zodErrorPart as g, OBJECT_PROTOTYPE_PROPERTIES as gt, zodError as h, NUMERIC_KEYWORDS as ht, effectMessage as i, INPUT_EXTENSIONS as it, isNullTypeMember as j, VALIBOT_CODE_EXTENSION_KEYS as jt, isDefaultOnlyMember as k, UNICODE_ESCAPE_PATTERN as kt, resolveOpenAPIRef as l, MISSING_DEFINITION_PREFIX as lt, zodBaseError as m, NUMBER_WIRE_PATTERN as mt, effectError as n, IDENTIFIER_PATTERN as nt, issueMessageExpression as o, INTEGER_WIRE_PATTERN as ot, valibotErrorPart as p, NUMBER_RANGES as pt, COMPONENT_SCHEMA_REF_PREFIX as q, effectErrorPart as r, IF_THEN_ELSE_UNSUPPORTED_MARKER as rt, makeSafeKey as s, ISO_4217_CURRENCY_CODES as st, coerceDefault as t, FORMAT_PATTERNS as tt, toIdentifierPascalCase as u, NON_IDENTIFIER_CHARACTER_PATTERN as ut, canBeString as v, OPENAPI_COMPONENT_SUFFIX_MAP as vt, hasStringKeyword as w, STRINGBOOL_PATTERN as wt, hasFixedItemCount as x, PARAM_STYLES as xt, hasCombinator as y, OUTPUT_EXTENSION as yt, isSchemaList as z };