schema-truth 0.8.2 → 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.
- package/README.md +1 -1
- 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.js +3 -4
- package/dist/cli/arktype.js +3 -4
- package/dist/cli/effect.js +3 -4
- package/dist/cli/typebox.js +3 -4
- package/dist/cli/valibot.js +3 -4
- package/dist/cli/yup.js +3 -4
- package/dist/cli/zod.js +3 -4
- package/dist/{cli-CB9GJ7qa.js → cli-71Np9i5L.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 +5 -5
- package/dist/utils-Bky98UmP.js +0 -1146
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
|
-
//#region src/constants/index.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* The values the generators agree on: every list of literals, every prefix and every
|
|
5
4
|
* pattern that more than one module reads. Types that mirror a list are derived from it in
|
|
@@ -178,8 +177,6 @@ declare const ANCHOR_REF_PATTERN: RegExp;
|
|
|
178
177
|
* @see https://www.iso.org/iso-4217-currency-codes.html
|
|
179
178
|
*/
|
|
180
179
|
declare const ISO_4217_CURRENCY_CODES: readonly ['AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', 'CAD', 'CDF', 'CHE', 'CHF', 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU', 'MUR', 'MVR', 'MWK', 'MXN', 'MXV', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLE', 'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'USN', 'UYI', 'UYU', 'UYW', 'UZS', 'VED', 'VES', 'VND', 'VUV', 'WST', 'XAF', 'XAG', 'XAU', 'XBA', 'XBB', 'XBC', 'XBD', 'XCD', 'XCG', 'XDR', 'XOF', 'XPD', 'XPF', 'XPT', 'XSU', 'XTS', 'XUA', 'XXX', 'YER', 'ZAR', 'ZMW', 'ZWG'];
|
|
181
|
-
//#endregion
|
|
182
|
-
//#region src/parser/json.d.ts
|
|
183
180
|
/**
|
|
184
181
|
* A JSON value, as `enum`, `const`, `default` and `examples` carry one. A document read
|
|
185
182
|
* from disk holds nothing else, so an `undefined` or a function never reaches a generator.
|
|
@@ -187,8 +184,6 @@ declare const ISO_4217_CURRENCY_CODES: readonly ['AED', 'AFN', 'ALL', 'AMD', 'AN
|
|
|
187
184
|
type JSONValue = string | number | boolean | null | readonly JSONValue[] | {
|
|
188
185
|
readonly [k: string]: JSONValue;
|
|
189
186
|
};
|
|
190
|
-
//#endregion
|
|
191
|
-
//#region src/parser/x-ext/code.d.ts
|
|
192
187
|
/**
|
|
193
188
|
* C 層: Code-emitting vendor extensions (escape hatch).
|
|
194
189
|
*
|
|
@@ -222,8 +217,6 @@ type XExtCode = {
|
|
|
222
217
|
/** Arktype-only: `.morph(...)` fragment appended verbatim */
|
|
223
218
|
readonly 'x-morph'?: string;
|
|
224
219
|
};
|
|
225
|
-
//#endregion
|
|
226
|
-
//#region src/parser/x-ext/messages.d.ts
|
|
227
220
|
type XExtMessages = {
|
|
228
221
|
readonly 'x-error-message'?: string;
|
|
229
222
|
readonly 'x-length-message'?: string;
|
|
@@ -278,8 +271,6 @@ type XExtMessages = {
|
|
|
278
271
|
readonly 'x-then-message'?: string;
|
|
279
272
|
readonly 'x-else-message'?: string;
|
|
280
273
|
};
|
|
281
|
-
//#endregion
|
|
282
|
-
//#region src/parser/x-ext/param.d.ts
|
|
283
274
|
/**
|
|
284
275
|
* OpenAPI parameter location, or `formData` for a field of a form body
|
|
285
276
|
* (`application/x-www-form-urlencoded`, `multipart/form-data`).
|
|
@@ -319,8 +310,6 @@ type XExtParam = {
|
|
|
319
310
|
* @see https://spec.openapis.org/oas/v3.2.0.html#style-values
|
|
320
311
|
*/
|
|
321
312
|
type ParamStyle = (typeof PARAM_STYLES)[number];
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region src/parser/x-ext/transform.d.ts
|
|
324
313
|
/**
|
|
325
314
|
* B 層: 振る舞い・transform 系 vendor extensions.
|
|
326
315
|
*
|
|
@@ -406,8 +395,6 @@ type XExtTransform = {
|
|
|
406
395
|
/** Branded type tag — emitted as Zod `.brand<"Tag">()` etc. */
|
|
407
396
|
readonly 'x-brand'?: string;
|
|
408
397
|
};
|
|
409
|
-
//#endregion
|
|
410
|
-
//#region src/parser/index.d.ts
|
|
411
398
|
declare const ParseError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
412
399
|
readonly _tag: "ParseError";
|
|
413
400
|
} & Readonly<A>;
|
|
@@ -599,5 +586,4 @@ type JSONSchemaCore = {
|
|
|
599
586
|
readonly name?: string;
|
|
600
587
|
};
|
|
601
588
|
type JSONSchema = JSONSchemaCore & XExtMessages & XExtTransform & XExtCode & XExtParam;
|
|
602
|
-
//#endregion
|
|
603
589
|
export { QUOTE_OR_BACKSLASH_PATTERN as $, DEFINITION_REF_PREFIXES as A, MISSING_DEFINITION_PREFIX as B, ARROW_FUNCTION_PATTERN as C, DEFAULT_ROOT_NAME as D, DATE_PATTERN_SOURCE as E, INPUT_EXTENSIONS as F, NUMBER_WIRE_PATTERN as G, NOT_KEYWORD_UNSUPPORTED_MARKER as H, INTEGER_TEXT_PATTERN as I, OFFSET_PATTERN_SOURCE as J, NUMERIC_KEYWORDS as K, INTEGER_WIRE_PATTERN as L, FORMAT_PATTERNS as M, IDENTIFIER_PATTERN as N, DEFINITION_KEYWORDS as O, IF_THEN_ELSE_UNSUPPORTED_MARKER as P, PARAM_STYLES as Q, ISO_4217_CURRENCY_CODES as R, ARKTYPE_CODE_EXTENSION_KEYS as S, CONTENT_ENCODINGS as T, NUMBER_FORMATS as U, NON_IDENTIFIER_CHARACTER_PATTERN as V, NUMBER_RANGES as W, OUTPUT_EXTENSION as X, OPENAPI_COMPONENT_SUFFIX_MAP as Y, PARAM_LOCATIONS as Z, XExtMessages as _, JSONSchemaNumberFormat as a, STRING_WIRE_LOCATIONS as at, ALL_CODE_EXTENSION_KEYS as b, JSONSchemaTypes as c, VALIBOT_CODE_EXTENSION_KEYS as ct, Ref as d, ROOT_REFS as et, parseSchemaFile as f, XExtParam as g, ParamStyle as h, JSONSchemaFormat as i, STRING_KEYWORDS as it, EFFECT_CODE_EXTENSION_KEYS as j, DEFINITION_POINTER_PATTERN as k, LocalRef as l, WIRE_PRIMITIVE_ORDER as lt, ParamIn as m, ExternalRef as n, STRINGBOOL_TRUTHY_PATTERN as nt, JSONSchemaStringFormat as o, UNICODE_ESCAPE_PATTERN as ot, XExtTransform as p, OBJECT_PROTOTYPE_PROPERTIES as q, JSONSchema as r, STRING_FORMATS as rt, JSONSchemaType as s, UNSAFE_GENERATED_MARKER as st, ContentEncoding as t, STRINGBOOL_PATTERN as tt, ParseError as u, ZOD_CODE_EXTENSION_KEYS as ut, XExtCode as v, COMPONENT_SCHEMA_REF_PREFIX as w, ANCHOR_REF_PATTERN as x, JSONValue as y, JSON_SCHEMA_TYPES as z };
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { h as ParamStyle, m as ParamIn, r as JSONSchema } from "./index-
|
|
2
|
-
//#region src/helper/schema.d.ts
|
|
1
|
+
import { h as ParamStyle, m as ParamIn, r as JSONSchema } from "./index-DLVjyrKu.js";
|
|
3
2
|
/** Named schemas a `default` beside a `$ref` is reconciled against. */
|
|
4
3
|
type SchemaDefinitions = {
|
|
5
4
|
readonly [name: string]: JSONSchema;
|
|
6
5
|
};
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/options/index.d.ts
|
|
9
6
|
/** The options every `schemaTo<Library>` document generator accepts. */
|
|
10
7
|
type GenerateOptions = {
|
|
11
8
|
/** Also export the inferred TypeScript type. Default: `true`. */
|
|
@@ -65,5 +62,4 @@ type GenerateOptions = {
|
|
|
65
62
|
};
|
|
66
63
|
/** The options threaded through every node emitter: `GenerateOptions` without `exportType`. */
|
|
67
64
|
type EmitOptions = Omit<GenerateOptions, 'exportType'>;
|
|
68
|
-
//#endregion
|
|
69
65
|
export { GenerateOptions as n, SchemaDefinitions as r, EmitOptions as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { $ as QUOTE_OR_BACKSLASH_PATTERN, A as DEFINITION_REF_PREFIXES, B as MISSING_DEFINITION_PREFIX, C as ARROW_FUNCTION_PATTERN, D as DEFAULT_ROOT_NAME, E as DATE_PATTERN_SOURCE, F as INPUT_EXTENSIONS, G as NUMBER_WIRE_PATTERN, H as NOT_KEYWORD_UNSUPPORTED_MARKER, I as INTEGER_TEXT_PATTERN, J as OFFSET_PATTERN_SOURCE, K as NUMERIC_KEYWORDS, L as INTEGER_WIRE_PATTERN, M as FORMAT_PATTERNS, N as IDENTIFIER_PATTERN, O as DEFINITION_KEYWORDS, P as IF_THEN_ELSE_UNSUPPORTED_MARKER, Q as PARAM_STYLES, R as ISO_4217_CURRENCY_CODES, S as ARKTYPE_CODE_EXTENSION_KEYS, T as CONTENT_ENCODINGS, U as NUMBER_FORMATS, V as NON_IDENTIFIER_CHARACTER_PATTERN, W as NUMBER_RANGES, X as OUTPUT_EXTENSION, Y as OPENAPI_COMPONENT_SUFFIX_MAP, Z as PARAM_LOCATIONS, _ as XExtMessages, a as JSONSchemaNumberFormat, at as STRING_WIRE_LOCATIONS, b as ALL_CODE_EXTENSION_KEYS, c as JSONSchemaTypes, ct as VALIBOT_CODE_EXTENSION_KEYS, d as Ref, et as ROOT_REFS, f as parseSchemaFile, g as XExtParam, h as ParamStyle, i as JSONSchemaFormat, it as STRING_KEYWORDS, j as EFFECT_CODE_EXTENSION_KEYS, k as DEFINITION_POINTER_PATTERN, l as LocalRef, lt as WIRE_PRIMITIVE_ORDER, m as ParamIn, n as ExternalRef, nt as STRINGBOOL_TRUTHY_PATTERN, o as JSONSchemaStringFormat, ot as UNICODE_ESCAPE_PATTERN, p as XExtTransform, q as OBJECT_PROTOTYPE_PROPERTIES, r as JSONSchema, rt as STRING_FORMATS, s as JSONSchemaType, st as UNSAFE_GENERATED_MARKER, t as ContentEncoding, tt as STRINGBOOL_PATTERN, u as ParseError, ut as ZOD_CODE_EXTENSION_KEYS, v as XExtCode, w as COMPONENT_SCHEMA_REF_PREFIX, x as ANCHOR_REF_PATTERN, y as JSONValue, z as JSON_SCHEMA_TYPES } from "./index-
|
|
1
|
+
import { $ as QUOTE_OR_BACKSLASH_PATTERN, A as DEFINITION_REF_PREFIXES, B as MISSING_DEFINITION_PREFIX, C as ARROW_FUNCTION_PATTERN, D as DEFAULT_ROOT_NAME, E as DATE_PATTERN_SOURCE, F as INPUT_EXTENSIONS, G as NUMBER_WIRE_PATTERN, H as NOT_KEYWORD_UNSUPPORTED_MARKER, I as INTEGER_TEXT_PATTERN, J as OFFSET_PATTERN_SOURCE, K as NUMERIC_KEYWORDS, L as INTEGER_WIRE_PATTERN, M as FORMAT_PATTERNS, N as IDENTIFIER_PATTERN, O as DEFINITION_KEYWORDS, P as IF_THEN_ELSE_UNSUPPORTED_MARKER, Q as PARAM_STYLES, R as ISO_4217_CURRENCY_CODES, S as ARKTYPE_CODE_EXTENSION_KEYS, T as CONTENT_ENCODINGS, U as NUMBER_FORMATS, V as NON_IDENTIFIER_CHARACTER_PATTERN, W as NUMBER_RANGES, X as OUTPUT_EXTENSION, Y as OPENAPI_COMPONENT_SUFFIX_MAP, Z as PARAM_LOCATIONS, _ as XExtMessages, a as JSONSchemaNumberFormat, at as STRING_WIRE_LOCATIONS, b as ALL_CODE_EXTENSION_KEYS, c as JSONSchemaTypes, ct as VALIBOT_CODE_EXTENSION_KEYS, d as Ref, et as ROOT_REFS, f as parseSchemaFile, g as XExtParam, h as ParamStyle, i as JSONSchemaFormat, it as STRING_KEYWORDS, j as EFFECT_CODE_EXTENSION_KEYS, k as DEFINITION_POINTER_PATTERN, l as LocalRef, lt as WIRE_PRIMITIVE_ORDER, m as ParamIn, n as ExternalRef, nt as STRINGBOOL_TRUTHY_PATTERN, o as JSONSchemaStringFormat, ot as UNICODE_ESCAPE_PATTERN, p as XExtTransform, q as OBJECT_PROTOTYPE_PROPERTIES, r as JSONSchema, rt as STRING_FORMATS, s as JSONSchemaType, st as UNSAFE_GENERATED_MARKER, t as ContentEncoding, tt as STRINGBOOL_PATTERN, u as ParseError, ut as ZOD_CODE_EXTENSION_KEYS, v as XExtCode, w as COMPONENT_SCHEMA_REF_PREFIX, x as ANCHOR_REF_PATTERN, y as JSONValue, z as JSON_SCHEMA_TYPES } from "./index-DLVjyrKu.js";
|
|
2
2
|
import { schemaToAjv } from "./ajv.js";
|
|
3
|
-
import { n as GenerateOptions, r as SchemaDefinitions, t as EmitOptions } from "./index-
|
|
3
|
+
import { n as GenerateOptions, r as SchemaDefinitions, t as EmitOptions } from "./index-DU2Nd8eI.js";
|
|
4
4
|
import { schemaToArktype } from "./arktype.js";
|
|
5
5
|
import { schemaToEffect } from "./effect.js";
|
|
6
6
|
import { TypeboxGenerateOptions, schemaToTypebox } from "./typebox.js";
|
|
@@ -8,7 +8,6 @@ import { schemaToValibot } from "./valibot.js";
|
|
|
8
8
|
import { schemaToYup } from "./yup.js";
|
|
9
9
|
import { schemaToZod } from "./zod.js";
|
|
10
10
|
import * as Effect from "effect/Effect";
|
|
11
|
-
//#region src/format/index.d.ts
|
|
12
11
|
declare const FormatError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
13
12
|
readonly _tag: "FormatError";
|
|
14
13
|
} & Readonly<A>;
|
|
@@ -18,8 +17,6 @@ export declare class FormatError extends FormatError_base<{
|
|
|
18
17
|
}> {}
|
|
19
18
|
/** Formats generated TypeScript. Failures land in the error channel. */
|
|
20
19
|
export declare function fmt(input: string): Effect.Effect<string, FormatError, never>;
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/generator/ajv/ajv.d.ts
|
|
23
20
|
/**
|
|
24
21
|
* One schema node to one Ajv draft-07 schema-object expression.
|
|
25
22
|
*
|
|
@@ -33,8 +30,6 @@ export declare function fmt(input: string): Effect.Effect<string, FormatError, n
|
|
|
33
30
|
* ```
|
|
34
31
|
*/
|
|
35
32
|
export declare function ajv(schema: JSONSchema): string;
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/generator/arktype/arktype.d.ts
|
|
38
33
|
/**
|
|
39
34
|
* Generate ArkType schema code from JSON Schema.
|
|
40
35
|
*
|
|
@@ -44,8 +39,6 @@ export declare function ajv(schema: JSONSchema): string;
|
|
|
44
39
|
* ```
|
|
45
40
|
*/
|
|
46
41
|
export declare function arktype(schema: JSONSchema, rootName?: string, isArktype?: boolean, options?: EmitOptions): string;
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/generator/effect/effect.d.ts
|
|
49
42
|
/**
|
|
50
43
|
* Replace every decoding failure of `inner` with a single message.
|
|
51
44
|
*
|
|
@@ -67,8 +60,6 @@ export declare function wholeValueMessage(inner: string, message: string): strin
|
|
|
67
60
|
* has no separate runtime "readonly" wrapper.
|
|
68
61
|
*/
|
|
69
62
|
export declare function effect(schema: JSONSchema, rootName?: string, isEffect?: boolean, options?: EmitOptions): string;
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/generator/typebox/typebox.d.ts
|
|
72
63
|
/**
|
|
73
64
|
* Generation options threaded through every TypeBox emitter.
|
|
74
65
|
*
|
|
@@ -96,8 +87,6 @@ export type TypeboxOptions = {
|
|
|
96
87
|
*/
|
|
97
88
|
export declare function nestedTypeboxOptions(options?: TypeboxOptions): TypeboxOptions | undefined;
|
|
98
89
|
export declare function typebox(schema: JSONSchema, rootName?: string, isTypebox?: boolean, options?: TypeboxOptions): string;
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region src/generator/valibot/valibot.d.ts
|
|
101
90
|
/**
|
|
102
91
|
* Generate Valibot schema code from JSON Schema.
|
|
103
92
|
*
|
|
@@ -107,8 +96,6 @@ export declare function typebox(schema: JSONSchema, rootName?: string, isTypebox
|
|
|
107
96
|
* ```
|
|
108
97
|
*/
|
|
109
98
|
export declare function valibot(schema: JSONSchema, rootName?: string, isValibot?: boolean, options?: EmitOptions): string;
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region src/generator/yup/yup.d.ts
|
|
112
99
|
/**
|
|
113
100
|
* Generate a Yup expression from one JSON Schema node.
|
|
114
101
|
*
|
|
@@ -121,8 +108,6 @@ export declare function valibot(schema: JSONSchema, rootName?: string, isValibot
|
|
|
121
108
|
* ```
|
|
122
109
|
*/
|
|
123
110
|
export declare function yup(schema: JSONSchema): string;
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/generator/zod/zod.d.ts
|
|
126
111
|
/**
|
|
127
112
|
* Re-push `issue` into `ctx` with `message`. Each issue code is narrowed first: the union of
|
|
128
113
|
* parsed issues does not type-check as a raw issue, while each member does.
|
|
@@ -139,8 +124,6 @@ export declare function nestedIssueMessageWrap(inner: string, msg: string): stri
|
|
|
139
124
|
* ```
|
|
140
125
|
*/
|
|
141
126
|
export declare function zod(schema: JSONSchema, rootName?: string, isZod?: boolean, options?: EmitOptions): string;
|
|
142
|
-
//#endregion
|
|
143
|
-
//#region src/utils/index.d.ts
|
|
144
127
|
/**
|
|
145
128
|
* Convert string to PascalCase (first character uppercase).
|
|
146
129
|
*
|
|
@@ -337,5 +320,4 @@ export declare function resolveOpenAPIRef($ref: string): string | null;
|
|
|
337
320
|
* ```
|
|
338
321
|
*/
|
|
339
322
|
export declare function makeSafeKey(key: string): string;
|
|
340
|
-
//#endregion
|
|
341
323
|
export { ALL_CODE_EXTENSION_KEYS, ANCHOR_REF_PATTERN, ARKTYPE_CODE_EXTENSION_KEYS, ARROW_FUNCTION_PATTERN, COMPONENT_SCHEMA_REF_PREFIX, CONTENT_ENCODINGS, ContentEncoding, DATE_PATTERN_SOURCE, DEFAULT_ROOT_NAME, DEFINITION_KEYWORDS, DEFINITION_POINTER_PATTERN, DEFINITION_REF_PREFIXES, EFFECT_CODE_EXTENSION_KEYS, type EmitOptions, ExternalRef, FORMAT_PATTERNS, type GenerateOptions, IDENTIFIER_PATTERN, IF_THEN_ELSE_UNSUPPORTED_MARKER, INPUT_EXTENSIONS, INTEGER_TEXT_PATTERN, INTEGER_WIRE_PATTERN, ISO_4217_CURRENCY_CODES, JSONSchema, JSONSchemaFormat, JSONSchemaNumberFormat, JSONSchemaStringFormat, JSONSchemaType, JSONSchemaTypes, type JSONValue, JSON_SCHEMA_TYPES, LocalRef, MISSING_DEFINITION_PREFIX, NON_IDENTIFIER_CHARACTER_PATTERN, NOT_KEYWORD_UNSUPPORTED_MARKER, NUMBER_FORMATS, NUMBER_RANGES, NUMBER_WIRE_PATTERN, NUMERIC_KEYWORDS, OBJECT_PROTOTYPE_PROPERTIES, OFFSET_PATTERN_SOURCE, OPENAPI_COMPONENT_SUFFIX_MAP, OUTPUT_EXTENSION, PARAM_LOCATIONS, PARAM_STYLES, type ParamIn, type ParamStyle, ParseError, QUOTE_OR_BACKSLASH_PATTERN, ROOT_REFS, Ref, STRINGBOOL_PATTERN, STRINGBOOL_TRUTHY_PATTERN, STRING_FORMATS, STRING_KEYWORDS, STRING_WIRE_LOCATIONS, TypeboxGenerateOptions, UNICODE_ESCAPE_PATTERN, UNSAFE_GENERATED_MARKER, VALIBOT_CODE_EXTENSION_KEYS, WIRE_PRIMITIVE_ORDER, type XExtCode, type XExtMessages, type XExtParam, type XExtTransform, ZOD_CODE_EXTENSION_KEYS, parseSchemaFile, schemaToAjv, schemaToArktype, schemaToEffect, schemaToTypebox, schemaToValibot, schemaToYup, schemaToZod };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { i as fmt, n as parseSchemaFile, r as FormatError, t as ParseError } from "./parser-
|
|
3
|
-
import { n as ajv, t as schemaToAjv } from "./ajv-
|
|
4
|
-
import { n as arktype, t as schemaToArktype } from "./arktype-
|
|
5
|
-
import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-
|
|
6
|
-
import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-
|
|
7
|
-
import { n as valibot, t as schemaToValibot } from "./valibot-
|
|
8
|
-
import { n as yup, t as schemaToYup } from "./yup-
|
|
9
|
-
import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-
|
|
1
|
+
import { $t as COMPONENT_SCHEMA_REF_PREFIX, An as STRINGBOOL_PATTERN, Cn as OFFSET_PATTERN_SOURCE, Ct as valibotErrorPart, Dn as PARAM_STYLES, En as PARAM_LOCATIONS, Et as zodErrorPart, Fn as UNICODE_ESCAPE_PATTERN, In as UNSAFE_GENERATED_MARKER, Ln as VALIBOT_CODE_EXTENSION_KEYS, Mn as STRING_FORMATS, Nn as STRING_KEYWORDS, On as QUOTE_OR_BACKSLASH_PATTERN, Pn as STRING_WIRE_LOCATIONS, Qt as ARROW_FUNCTION_PATTERN, Rn as WIRE_PRIMITIVE_ORDER, Sn as OBJECT_PROTOTYPE_PROPERTIES, St as valibotError, Tn as OUTPUT_EXTENSION, Tt as zodError, Xt as ANCHOR_REF_PATTERN, Yt as ALL_CODE_EXTENSION_KEYS, Zt as ARKTYPE_CODE_EXTENSION_KEYS, _n as NOT_KEYWORD_UNSUPPORTED_MARKER, _t as makeSafeKey, an as DEFINITION_REF_PREFIXES, bn as NUMBER_WIRE_PATTERN, bt as toIdentifierPascalCase, cn as IDENTIFIER_PATTERN, dn as INTEGER_TEXT_PATTERN, dt as coerceDefault, en as CONTENT_ENCODINGS, fn as INTEGER_WIRE_PATTERN, ft as effectError, gn as NON_IDENTIFIER_CHARACTER_PATTERN, gt as issueMessageExpression, hn as MISSING_DEFINITION_PREFIX, ht as encodeNonAscii, in as DEFINITION_POINTER_PATTERN, jn as STRINGBOOL_TRUTHY_PATTERN, kn as ROOT_REFS, ln as IF_THEN_ELSE_UNSUPPORTED_MARKER, mn as JSON_SCHEMA_TYPES, mt as effectMessage, nn as DEFAULT_ROOT_NAME, on as EFFECT_CODE_EXTENSION_KEYS, pn as ISO_4217_CURRENCY_CODES, pt as effectErrorPart, rn as DEFINITION_KEYWORDS, sn as FORMAT_PATTERNS, tn as DATE_PATTERN_SOURCE, un as INPUT_EXTENSIONS, vn as NUMBER_FORMATS, vt as normalizeTypes, wn as OPENAPI_COMPONENT_SUFFIX_MAP, wt as zodBaseError, xn as NUMERIC_KEYWORDS, xt as toPascalCase, yn as NUMBER_RANGES, yt as resolveOpenAPIRef, zn as ZOD_CODE_EXTENSION_KEYS } from "./helper-WSNbEQKr.js";
|
|
2
|
+
import { i as fmt, n as parseSchemaFile, r as FormatError, t as ParseError } from "./parser-RBrkz7ZL.js";
|
|
3
|
+
import { n as ajv, t as schemaToAjv } from "./ajv-DejgT2o1.js";
|
|
4
|
+
import { n as arktype, t as schemaToArktype } from "./arktype-CzTltPwP.js";
|
|
5
|
+
import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-Dj8qARFi.js";
|
|
6
|
+
import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-RAJnIZwI.js";
|
|
7
|
+
import { n as valibot, t as schemaToValibot } from "./valibot-CLUhG6tp.js";
|
|
8
|
+
import { n as yup, t as schemaToYup } from "./yup-DfE_ofEu.js";
|
|
9
|
+
import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-BhYAQ3iW.js";
|
|
10
10
|
export { ALL_CODE_EXTENSION_KEYS, ANCHOR_REF_PATTERN, ARKTYPE_CODE_EXTENSION_KEYS, ARROW_FUNCTION_PATTERN, COMPONENT_SCHEMA_REF_PREFIX, CONTENT_ENCODINGS, DATE_PATTERN_SOURCE, DEFAULT_ROOT_NAME, DEFINITION_KEYWORDS, DEFINITION_POINTER_PATTERN, DEFINITION_REF_PREFIXES, EFFECT_CODE_EXTENSION_KEYS, FORMAT_PATTERNS, FormatError, IDENTIFIER_PATTERN, IF_THEN_ELSE_UNSUPPORTED_MARKER, INPUT_EXTENSIONS, INTEGER_TEXT_PATTERN, INTEGER_WIRE_PATTERN, ISO_4217_CURRENCY_CODES, JSON_SCHEMA_TYPES, MISSING_DEFINITION_PREFIX, NON_IDENTIFIER_CHARACTER_PATTERN, NOT_KEYWORD_UNSUPPORTED_MARKER, NUMBER_FORMATS, NUMBER_RANGES, NUMBER_WIRE_PATTERN, NUMERIC_KEYWORDS, OBJECT_PROTOTYPE_PROPERTIES, OFFSET_PATTERN_SOURCE, OPENAPI_COMPONENT_SUFFIX_MAP, OUTPUT_EXTENSION, PARAM_LOCATIONS, PARAM_STYLES, ParseError, QUOTE_OR_BACKSLASH_PATTERN, ROOT_REFS, STRINGBOOL_PATTERN, STRINGBOOL_TRUTHY_PATTERN, STRING_FORMATS, STRING_KEYWORDS, STRING_WIRE_LOCATIONS, UNICODE_ESCAPE_PATTERN, UNSAFE_GENERATED_MARKER, VALIBOT_CODE_EXTENSION_KEYS, WIRE_PRIMITIVE_ORDER, ZOD_CODE_EXTENSION_KEYS, ajv, arktype, coerceDefault, effect, effectError, effectErrorPart, effectMessage, encodeNonAscii, fmt, forwardIssue, issueMessageExpression, makeSafeKey, nestedIssueMessageWrap, nestedTypeboxOptions, normalizeTypes, parseSchemaFile, resolveOpenAPIRef, schemaToAjv, schemaToArktype, schemaToEffect, schemaToTypebox, schemaToValibot, schemaToYup, schemaToZod, toIdentifierPascalCase, toPascalCase, typebox, valibot, valibotError, valibotErrorPart, wholeValueMessage, yup, zod, zodBaseError, zodError, zodErrorPart };
|
|
@@ -2,7 +2,7 @@ import * as Data from "effect/Data";
|
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import { format } from "oxfmt";
|
|
4
4
|
import { bundle } from "@apidevtools/json-schema-ref-parser";
|
|
5
|
-
|
|
5
|
+
// src/format/index.ts
|
|
6
6
|
/** oxfmt rejected the source it was handed. */
|
|
7
7
|
var FormatError = class extends Data.TaggedError("FormatError") {};
|
|
8
8
|
const FMT_OPTIONS = {
|
|
@@ -21,8 +21,7 @@ function fmt(input) {
|
|
|
21
21
|
return code;
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
//#region src/parser/index.ts
|
|
24
|
+
// src/parser/index.ts
|
|
26
25
|
/** The document could not be bundled as a JSON Schema. */
|
|
27
26
|
var ParseError = class extends Data.TaggedError("ParseError") {};
|
|
28
27
|
/** The bundled document at `input`. Failures land in the error channel. */
|
|
@@ -32,5 +31,4 @@ function parseSchemaFile(input) {
|
|
|
32
31
|
catch: (error) => new ParseError({ message: `Failed to parse schema: ${error instanceof Error ? error.message : String(error)}` })
|
|
33
32
|
});
|
|
34
33
|
}
|
|
35
|
-
//#endregion
|
|
36
34
|
export { fmt as i, parseSchemaFile as n, FormatError as r, ParseError as t };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/generator/typebox/enum.ts
|
|
1
|
+
import { At as hasFixedLength, B as typeboxRefOpt, D as stringboolPattern, Dt as hasCombinator, Ft as isComposite, G as renderDefinitions, Gt as isRootRef, H as emitOptionsOf, It as isDeepLocalPointer, J as discriminatedMembers, Jt as isStringWireLocation, K as rootNameOf, Lt as isDefaultOnlyMember, Mt as hasStringKeyword, O as stringboolTruthyPattern, Q as itemsSchemaOf, R as typeboxDefaultOpt, Rt as isNullTypeMember, T as numberWirePattern, U as missingDefinitionComment, V as definitionsOf, W as planDocument, X as hasRootSelfReference, Y as cyclicDefinitionNames, Z as isOptionalByDefault, _ as hoistNestedRefs, _n as NOT_KEYWORD_UNSUPPORTED_MARKER, _t as makeSafeKey, a as typeboxWrap, an as DEFINITION_REF_PREFIXES, ct as isKeywordOnlyMember, it as hasNotKeyword, jt as hasNumericKeyword, l as withPolymorphicBases, lt as patternSource, nn as DEFAULT_ROOT_NAME, q as schemaNamer, qt as isShapelessMember, s as sanitizeSchema, st as foldAllOfMembers, vt as normalizeTypes, x as integerWirePattern, yt as resolveOpenAPIRef, z as typeboxMetaOpts, zt as isNullable } from "./helper-WSNbEQKr.js";
|
|
2
|
+
// src/generator/typebox/enum.ts
|
|
4
3
|
function lit(v) {
|
|
5
4
|
if (v === null) return "null";
|
|
6
5
|
if (typeof v === "string") return JSON.stringify(v);
|
|
@@ -29,8 +28,7 @@ function _enum(schema, ref) {
|
|
|
29
28
|
if (schema.enum.length === 1) return schema.enum[0] === null ? `Type.Null(${optsParts.length > 0 ? `{${optsParts.join(",")}}` : ""})` : `Type.Literal(${lit(schema.enum[0])}${optsTrailer})`;
|
|
30
29
|
return `Type.Union([${schema.enum.map(member).join(",")}]${optsTrailer})`;
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
//#region src/generator/typebox/integer.ts
|
|
31
|
+
// src/generator/typebox/integer.ts
|
|
34
32
|
function integer(schema, ref) {
|
|
35
33
|
const errorMessage = schema["x-error-message"];
|
|
36
34
|
const requiredMessage = schema["x-required-message"];
|
|
@@ -72,8 +70,7 @@ function integer(schema, ref) {
|
|
|
72
70
|
if (opts.length > 0) return `Type.Integer({${opts.join(",")}})`;
|
|
73
71
|
return "Type.Integer()";
|
|
74
72
|
}
|
|
75
|
-
|
|
76
|
-
//#region src/generator/typebox/number.ts
|
|
73
|
+
// src/generator/typebox/number.ts
|
|
77
74
|
function number(schema, ref) {
|
|
78
75
|
const errorMessage = schema["x-error-message"];
|
|
79
76
|
const requiredMessage = schema["x-required-message"];
|
|
@@ -104,8 +101,7 @@ function number(schema, ref) {
|
|
|
104
101
|
if (opts.length > 0) return `Type.Number({${opts.join(",")}})`;
|
|
105
102
|
return "Type.Number()";
|
|
106
103
|
}
|
|
107
|
-
|
|
108
|
-
//#region src/generator/typebox/object.ts
|
|
104
|
+
// src/generator/typebox/object.ts
|
|
109
105
|
/**
|
|
110
106
|
* Generate a TypeBox object schema for a JSON Schema object node.
|
|
111
107
|
*
|
|
@@ -226,8 +222,7 @@ function buildAdvancedOpts(schema, rootName, isTypebox, options) {
|
|
|
226
222
|
unevaluatedOpt
|
|
227
223
|
];
|
|
228
224
|
}
|
|
229
|
-
|
|
230
|
-
//#region src/generator/typebox/string.ts
|
|
225
|
+
// src/generator/typebox/string.ts
|
|
231
226
|
const FORMAT_MAP = {
|
|
232
227
|
email: "email",
|
|
233
228
|
uuid: "uuid",
|
|
@@ -283,8 +278,7 @@ function string(schema, ref) {
|
|
|
283
278
|
if (transforms.length > 0) return `Codec(${stringExpr}).Decode((value: string) => value${transforms.join("")}).Encode((value: string) => value)`;
|
|
284
279
|
return stringExpr;
|
|
285
280
|
}
|
|
286
|
-
|
|
287
|
-
//#region src/generator/typebox/typebox.ts
|
|
281
|
+
// src/generator/typebox/typebox.ts
|
|
288
282
|
/**
|
|
289
283
|
* Options for a nested TypeBox node: the same as `options` but without a
|
|
290
284
|
* host `ref`, so only the outermost factory of a declaration receives it.
|
|
@@ -521,8 +515,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
521
515
|
if (typeof schema.additionalProperties === "object") return readonly(typeboxWrap(object(schema, rootName, isTypebox, options), schema));
|
|
522
516
|
return typeboxWrap(tbPrim("Type.Any", schema, [], hostRef), schema);
|
|
523
517
|
}
|
|
524
|
-
|
|
525
|
-
//#region src/generator/typebox/index.ts
|
|
518
|
+
// src/generator/typebox/index.ts
|
|
526
519
|
/** The import line, carrying `Codec` only when the emitted source calls it. */
|
|
527
520
|
function importLine(emitted) {
|
|
528
521
|
return `import { ${emitted.includes("Codec(") ? "Codec, " : ""}Type, type Static } from 'typebox'`;
|
|
@@ -533,7 +526,7 @@ function importLine(emitted) {
|
|
|
533
526
|
* `Type.Cyclic($defs, root)` map instead.
|
|
534
527
|
*/
|
|
535
528
|
function schemaToTypebox(input, options) {
|
|
536
|
-
const schema = withPolymorphicBases(hoistNestedRefs(input));
|
|
529
|
+
const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
|
|
537
530
|
const exportType = options?.exportType ?? true;
|
|
538
531
|
const openapi = options?.openapi ?? false;
|
|
539
532
|
const hostRef = options?.ref;
|
|
@@ -580,5 +573,4 @@ function schemaToTypebox(input, options) {
|
|
|
580
573
|
...exportType ? [`export type ${rootName} = Static<typeof ${rootName}>`] : []
|
|
581
574
|
].filter(Boolean).join("\n\n");
|
|
582
575
|
}
|
|
583
|
-
//#endregion
|
|
584
576
|
export { nestedTypeboxOptions as n, typebox as r, schemaToTypebox as t };
|
package/dist/typebox.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { r as JSONSchema } from "./index-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
3
|
-
//#region src/generator/typebox/index.d.ts
|
|
1
|
+
import { r as JSONSchema } from "./index-DLVjyrKu.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-DU2Nd8eI.js";
|
|
4
3
|
/** The options of `schemaToTypebox`: the common ones, plus a host `$ref` name. */
|
|
5
4
|
export type TypeboxGenerateOptions = Omit<GenerateOptions, 'unsafeCodeExtensions'> & {
|
|
6
5
|
/**
|
|
@@ -17,5 +16,4 @@ export type TypeboxGenerateOptions = Omit<GenerateOptions, 'unsafeCodeExtensions
|
|
|
17
16
|
* with plain `const` declarations, so a cyclic document becomes one
|
|
18
17
|
* `Type.Cyclic($defs, root)` map instead.
|
|
19
18
|
*/
|
|
20
|
-
export declare function schemaToTypebox(input: JSONSchema, options?: TypeboxGenerateOptions): string;
|
|
21
|
-
//#endregion
|
|
19
|
+
export declare function schemaToTypebox(input: JSONSchema, options?: TypeboxGenerateOptions): string;
|
package/dist/typebox.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToTypebox } from "./typebox-
|
|
1
|
+
export { t as schemaToTypebox } from "./typebox-RAJnIZwI.js";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { At as
|
|
2
|
-
|
|
3
|
-
//#region src/generator/valibot/type.ts
|
|
1
|
+
import { A as wireArrayOnce, At as hasFixedLength, Bt as isObjectPrototypeProperty, C as isNullTextRead, Ct as valibotErrorPart, D as stringboolPattern, Dt as hasCombinator, E as ownProperties, G as renderDefinitions, H as emitOptionsOf, Ht as isPrimitive, I as deepEqualExpression, In as UNSAFE_GENERATED_MARKER, J as discriminatedMembers, Jt as isStringWireLocation, K as rootNameOf, Kt as isSchemaObject, L as jsLiteral, Lt as isDefaultOnlyMember, M as wireNumericKind, N as formatPattern, Nt as hasType, O as stringboolTruthyPattern, Ot as hasConditional, P as regexSource, Q as itemsSchemaOf, Rt as isNullTypeMember, St as valibotError, T as numberWirePattern, V as definitionsOf, W as planDocument, X as hasRootSelfReference, Z as isOptionalByDefault, _ as hoistNestedRefs, _t as makeSafeKey, at as constraintMessage, b as impliedWireType, c as refTarget, ct as isKeywordOnlyMember, d as parameterReaders, dn as INTEGER_TEXT_PATTERN, f as propertyEmitOptions, g as valueListLiteral, gt as issueMessageExpression, h as notPredicate, i as isEvaluatedKeyExpression, k as unionPrimitiveTypes, kt as hasFixedItemCount, l as withPolymorphicBases, m as isBigintFormat, n as valibotWrap, nn as DEFAULT_ROOT_NAME, o as typeDeclaration, ot as constraintPredicate, p as withoutParameterSerialization, q as schemaNamer, qt as isShapelessMember, r as evaluatedProperties, rt as findCodeExtensionKeysInSchema, s as sanitizeSchema, st as foldAllOfMembers, u as hasParameterSerialization, ut as regexLiteral, vt as normalizeTypes, w as isPrimitiveUnion, x as integerWirePattern, yn as NUMBER_RANGES, zt as isNullable } from "./helper-WSNbEQKr.js";
|
|
2
|
+
// src/generator/valibot/type.ts
|
|
4
3
|
/** The TypeScript type declared beside a recursive Valibot schema: its output type. */
|
|
5
4
|
function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
6
5
|
return typeDeclaration(schema, {
|
|
@@ -8,8 +7,7 @@ function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
|
8
7
|
readonly: false
|
|
9
8
|
}, rootName);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
//#region src/generator/valibot/number.ts
|
|
10
|
+
// src/generator/valibot/number.ts
|
|
13
11
|
/** The `v.minValue` / `v.maxValue` / `v.gtValue` / `v.ltValue` / `v.multipleOf` actions of a numeric node. */
|
|
14
12
|
function numberActions(schema, lit = (n) => `${n}`) {
|
|
15
13
|
const minimumMessage = schema["x-minimum-message"];
|
|
@@ -63,8 +61,7 @@ function number(schema, options) {
|
|
|
63
61
|
if (actions.length > 0) return `v.pipe(${base},${actions.join(",")})`;
|
|
64
62
|
return errorMessage ? base : "v.number()";
|
|
65
63
|
}
|
|
66
|
-
|
|
67
|
-
//#region src/generator/valibot/integer.ts
|
|
64
|
+
// src/generator/valibot/integer.ts
|
|
68
65
|
/** Whether a node is a 64-bit integer: a value beyond 2^53 that is read as a bigint. */
|
|
69
66
|
function isInt64(schema) {
|
|
70
67
|
return schema.format === "int64" || schema.format === "uint64";
|
|
@@ -126,8 +123,7 @@ function integer(schema, options) {
|
|
|
126
123
|
...actions
|
|
127
124
|
].join(",")})`;
|
|
128
125
|
}
|
|
129
|
-
|
|
130
|
-
//#region src/generator/valibot/enum.ts
|
|
126
|
+
// src/generator/valibot/enum.ts
|
|
131
127
|
function lit(v, isBigint) {
|
|
132
128
|
if (v === null) return "null";
|
|
133
129
|
if (typeof v === "string") return `'${v.replaceAll("'", "\\'")}'`;
|
|
@@ -159,7 +155,7 @@ function _enum(schema) {
|
|
|
159
155
|
const litSchema = (v, errPart) => {
|
|
160
156
|
if (v === null) return `v.null(${errPart.replace(/^,/, "")})`;
|
|
161
157
|
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") return `v.literal(${lit(v, isBigint)}${errPart})`;
|
|
162
|
-
return `v.custom<${JSON.stringify(v)}>((input) =>
|
|
158
|
+
return `v.custom<${JSON.stringify(v)}>((input) => ${deepEqualExpression(v, "input")}${errPart})`;
|
|
163
159
|
};
|
|
164
160
|
const innerLit = (v) => litSchema(v, "");
|
|
165
161
|
const outerLit = (v) => litSchema(v, errorArg);
|
|
@@ -177,8 +173,7 @@ function _enum(schema) {
|
|
|
177
173
|
if (schema.enum.length > 1) return `v.union([${schema.enum.map(innerLit).join(",")}]${errorArg})`;
|
|
178
174
|
return outerLit(schema.enum[0]);
|
|
179
175
|
}
|
|
180
|
-
|
|
181
|
-
//#region src/generator/valibot/object.ts
|
|
176
|
+
// src/generator/valibot/object.ts
|
|
182
177
|
/**
|
|
183
178
|
* Generate a Valibot object schema for a JSON Schema object node.
|
|
184
179
|
*
|
|
@@ -310,8 +305,7 @@ function object(schema, rootName, isValibot, options) {
|
|
|
310
305
|
const hasInheritedName = Object.keys(properties).some(isObjectPrototypeProperty);
|
|
311
306
|
return isStringWireLocation(options?.paramIn) && hasInheritedName ? `v.pipe(v.unknown(),v.transform(${ownProperties("input")}),${objectExpr})` : objectExpr;
|
|
312
307
|
}
|
|
313
|
-
|
|
314
|
-
//#region src/generator/valibot/string.ts
|
|
308
|
+
// src/generator/valibot/string.ts
|
|
315
309
|
/** The formats Valibot checks with an action of its own, keyed by the lower-cased format. */
|
|
316
310
|
const FORMAT_ACTION = {
|
|
317
311
|
email: "v.email()",
|
|
@@ -389,8 +383,7 @@ function string(schema) {
|
|
|
389
383
|
if (actions.length > 0) return `v.pipe(v.string(${baseErrorArg}),${actions.join(",")})`;
|
|
390
384
|
return errorMessage ? `v.string(${baseErrorArg})` : "v.string()";
|
|
391
385
|
}
|
|
392
|
-
|
|
393
|
-
//#region src/generator/valibot/valibot.ts
|
|
386
|
+
// src/generator/valibot/valibot.ts
|
|
394
387
|
/** `inner` with `prefix` ahead of it in one pipe: an existing pipe is opened, not nested. */
|
|
395
388
|
function prependPipe(prefix, inner) {
|
|
396
389
|
if (inner.startsWith("v.pipe(") && inner.endsWith(")")) {
|
|
@@ -582,7 +575,7 @@ function node(schema, rootName, isValibot, options) {
|
|
|
582
575
|
const msgArg = constMessage ? valibotError(constMessage) : "";
|
|
583
576
|
const errorPart = msgArg ? `,${msgArg}` : "";
|
|
584
577
|
if (value === null) return valibotWrap$1(`v.null(${msgArg})`, schema);
|
|
585
|
-
const literal = typeof value === "number" && isInt64(schema) ? `v.literal(${value}n${errorPart})` : isPrimitive(value) ? `v.literal(${JSON.stringify(value)}${errorPart})` : `v.custom<${JSON.stringify(value)}>((input) =>
|
|
578
|
+
const literal = typeof value === "number" && isInt64(schema) ? `v.literal(${value}n${errorPart})` : isPrimitive(value) ? `v.literal(${JSON.stringify(value)}${errorPart})` : `v.custom<${JSON.stringify(value)}>((input) => ${deepEqualExpression(value, "input")}${errorPart})`;
|
|
586
579
|
const input = literalInput([value]);
|
|
587
580
|
return valibotWrap$1(input ? prependPipe(input, literal) : literal, schema);
|
|
588
581
|
}
|
|
@@ -688,8 +681,7 @@ function node(schema, rootName, isValibot, options) {
|
|
|
688
681
|
if (typeof schema.additionalProperties === "object") return readonly(valibotWrap$1(object(schema, rootName, isValibot, options), schema));
|
|
689
682
|
return valibotWrap$1("v.any()", schema);
|
|
690
683
|
}
|
|
691
|
-
|
|
692
|
-
//#region src/generator/valibot/index.ts
|
|
684
|
+
// src/generator/valibot/index.ts
|
|
693
685
|
/**
|
|
694
686
|
* A recursive declaration needs an explicit annotation, since the schema is referenced
|
|
695
687
|
* inside its own initializer. `GenericSchema<TInput, TOutput>` pins the input to the
|
|
@@ -705,7 +697,7 @@ function annotation(name) {
|
|
|
705
697
|
* order, the root export, and the inferred output type.
|
|
706
698
|
*/
|
|
707
699
|
function schemaToValibot(input, options) {
|
|
708
|
-
const schema = withPolymorphicBases(hoistNestedRefs(input));
|
|
700
|
+
const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
|
|
709
701
|
const exportType = options?.exportType ?? true;
|
|
710
702
|
const baseOptions = emitOptionsOf(options);
|
|
711
703
|
const codeExtensionsPresent = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0;
|
|
@@ -731,5 +723,4 @@ function schemaToValibot(input, options) {
|
|
|
731
723
|
...exportType ? [`export type ${rootName}Output = v.InferOutput<typeof ${rootName}>`] : []
|
|
732
724
|
].filter(Boolean).join("\n\n");
|
|
733
725
|
}
|
|
734
|
-
//#endregion
|
|
735
726
|
export { valibot as n, schemaToValibot as t };
|
package/dist/valibot.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { r as JSONSchema } from "./index-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
3
|
-
//#region src/generator/valibot/index.d.ts
|
|
1
|
+
import { r as JSONSchema } from "./index-DLVjyrKu.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-DU2Nd8eI.js";
|
|
4
3
|
/**
|
|
5
4
|
* A whole JSON Schema document as a Valibot module: imports, `$defs` in dependency
|
|
6
5
|
* order, the root export, and the inferred output type.
|
|
7
6
|
*/
|
|
8
|
-
export declare function schemaToValibot(input: JSONSchema, options?: GenerateOptions): string;
|
|
9
|
-
//#endregion
|
|
7
|
+
export declare function schemaToValibot(input: JSONSchema, options?: GenerateOptions): string;
|
package/dist/valibot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToValibot } from "./valibot-
|
|
1
|
+
export { t as schemaToValibot } from "./valibot-CLUhG6tp.js";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/generator/yup/integer.ts
|
|
1
|
+
import { K as rootNameOf, _t as makeSafeKey, q as schemaNamer, s as sanitizeSchema, vt as normalizeTypes } from "./helper-WSNbEQKr.js";
|
|
2
|
+
// src/generator/yup/integer.ts
|
|
4
3
|
/**
|
|
5
4
|
* Generate a Yup integer schema as `yup.number().integer()`, with `minimum`
|
|
6
5
|
* as `.min(...)`. Other numeric keywords are silent no-ops in this slice.
|
|
@@ -8,8 +7,7 @@ import { G as schemaNamer, W as rootNameOf } from "./helper-S7SSsYwh.js";
|
|
|
8
7
|
function integer(schema) {
|
|
9
8
|
return `yup.number().integer()${typeof schema.minimum === "number" ? `.min(${schema.minimum})` : ""}`;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
//#region src/generator/yup/number.ts
|
|
10
|
+
// src/generator/yup/number.ts
|
|
13
11
|
/**
|
|
14
12
|
* Generate a Yup number schema. `minimum` becomes `.min(...)`; other numeric
|
|
15
13
|
* keywords are silent no-ops in this slice.
|
|
@@ -17,8 +15,7 @@ function integer(schema) {
|
|
|
17
15
|
function number(schema) {
|
|
18
16
|
return `yup.number()${typeof schema.minimum === "number" ? `.min(${schema.minimum})` : ""}`;
|
|
19
17
|
}
|
|
20
|
-
|
|
21
|
-
//#region src/generator/yup/object.ts
|
|
18
|
+
// src/generator/yup/object.ts
|
|
22
19
|
/**
|
|
23
20
|
* Generate a Yup object schema for a JSON Schema object node.
|
|
24
21
|
*
|
|
@@ -34,8 +31,7 @@ function object(schema) {
|
|
|
34
31
|
return `${makeSafeKey(key)}:${parsed}${suffix}`;
|
|
35
32
|
}).join(",")}})`;
|
|
36
33
|
}
|
|
37
|
-
|
|
38
|
-
//#region src/generator/yup/string.ts
|
|
34
|
+
// src/generator/yup/string.ts
|
|
39
35
|
/**
|
|
40
36
|
* Generate a Yup string schema. `format: email` becomes `.email()`; every
|
|
41
37
|
* other string keyword is a silent no-op in this slice.
|
|
@@ -43,8 +39,7 @@ function object(schema) {
|
|
|
43
39
|
function string(schema) {
|
|
44
40
|
return schema.format === "email" ? "yup.string().email()" : "yup.string()";
|
|
45
41
|
}
|
|
46
|
-
|
|
47
|
-
//#region src/generator/yup/yup.ts
|
|
42
|
+
// src/generator/yup/yup.ts
|
|
48
43
|
/**
|
|
49
44
|
* Generate a Yup expression from one JSON Schema node.
|
|
50
45
|
*
|
|
@@ -65,8 +60,7 @@ function yup(schema) {
|
|
|
65
60
|
if (types.includes("object")) return object(schema);
|
|
66
61
|
return "yup.mixed()";
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
//#region src/generator/yup/index.ts
|
|
63
|
+
// src/generator/yup/index.ts
|
|
70
64
|
/**
|
|
71
65
|
* Convert a JSON Schema document to Yup schema source.
|
|
72
66
|
*
|
|
@@ -79,7 +73,8 @@ function yup(schema) {
|
|
|
79
73
|
* @param options.openapi - Enable OpenAPI component-aware naming (default: false)
|
|
80
74
|
* @returns Generated TypeScript/Yup code string
|
|
81
75
|
*/
|
|
82
|
-
function schemaToYup(
|
|
76
|
+
function schemaToYup(input, options) {
|
|
77
|
+
const schema = sanitizeSchema(input);
|
|
83
78
|
const exportType = options?.exportType ?? true;
|
|
84
79
|
const rootName = rootNameOf(schema, schemaNamer(options?.openapi));
|
|
85
80
|
return [
|
|
@@ -88,5 +83,4 @@ function schemaToYup(schema, options) {
|
|
|
88
83
|
...exportType ? [`export type ${rootName} = yup.InferType<typeof ${rootName}>`] : []
|
|
89
84
|
].join("\n\n");
|
|
90
85
|
}
|
|
91
|
-
//#endregion
|
|
92
86
|
export { yup as n, schemaToYup as t };
|
package/dist/yup.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { r as JSONSchema } from "./index-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
3
|
-
//#region src/generator/yup/index.d.ts
|
|
1
|
+
import { r as JSONSchema } from "./index-DLVjyrKu.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-DU2Nd8eI.js";
|
|
4
3
|
/**
|
|
5
4
|
* Convert a JSON Schema document to Yup schema source.
|
|
6
5
|
*
|
|
@@ -13,5 +12,4 @@ import { n as GenerateOptions } from "./index-EK43HM_z.js";
|
|
|
13
12
|
* @param options.openapi - Enable OpenAPI component-aware naming (default: false)
|
|
14
13
|
* @returns Generated TypeScript/Yup code string
|
|
15
14
|
*/
|
|
16
|
-
export declare function schemaToYup(
|
|
17
|
-
//#endregion
|
|
15
|
+
export declare function schemaToYup(input: JSONSchema, options?: GenerateOptions): string;
|
package/dist/yup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToYup } from "./yup-
|
|
1
|
+
export { t as schemaToYup } from "./yup-DfE_ofEu.js";
|