schema-truth 0.8.5 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/ajv.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as schemaToAjv } from "../ajv-BjWqjOc9.js";
3
- import { n as version, t as cli } from "../cli-CtOh--vr.js";
3
+ import { n as version, t as cli } from "../cli-CLh6PrSG.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as schemaToArktype } from "../arktype-pHeYh_IG.js";
3
- import { n as version, t as cli } from "../cli-CtOh--vr.js";
3
+ import { n as version, t as cli } from "../cli-CLh6PrSG.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as schemaToEffect } from "../effect-CM1XVqvf.js";
3
- import { n as version, t as cli } from "../cli-CtOh--vr.js";
3
+ import { n as version, t as cli } from "../cli-CLh6PrSG.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToTypebox } from "../typebox-D1GT2WSK.js";
3
- import { n as version, t as cli } from "../cli-CtOh--vr.js";
2
+ import { t as schemaToTypebox } from "../typebox-CnmZohGb.js";
3
+ import { n as version, t as cli } from "../cli-CLh6PrSG.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as schemaToValibot } from "../valibot-1p_Y7fu6.js";
3
- import { n as version, t as cli } from "../cli-CtOh--vr.js";
3
+ import { n as version, t as cli } from "../cli-CLh6PrSG.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
package/dist/cli/yup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as schemaToYup } from "../yup-IOat93gr.js";
3
- import { n as version, t as cli } from "../cli-CtOh--vr.js";
3
+ import { n as version, t as cli } from "../cli-CLh6PrSG.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
package/dist/cli/zod.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToZod } from "../zod-B-mxbHoq.js";
3
- import { n as version, t as cli } from "../cli-CtOh--vr.js";
2
+ import { t as schemaToZod } from "../zod-q9c0XhJO.js";
3
+ import { n as version, t as cli } from "../cli-CLh6PrSG.js";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -9,7 +9,7 @@ import * as Stdio from "effect/Stdio";
9
9
  import "@effect/platform-node/NodeFileSystem";
10
10
  import * as FileSystem from "effect/FileSystem";
11
11
  // package.json
12
- var version = "0.8.5";
12
+ var version = "0.8.7";
13
13
  // src/file/index.ts
14
14
  /** Creates the directory and its parents. An existing directory is not an error. */
15
15
  function mkdir(dir) {
package/dist/index.js CHANGED
@@ -3,8 +3,8 @@ import { i as fmt, n as parseSchemaFile, r as FormatError, t as ParseError } fro
3
3
  import { n as ajv, t as schemaToAjv } from "./ajv-BjWqjOc9.js";
4
4
  import { n as arktype, t as schemaToArktype } from "./arktype-pHeYh_IG.js";
5
5
  import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-CM1XVqvf.js";
6
- import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-D1GT2WSK.js";
6
+ import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-CnmZohGb.js";
7
7
  import { n as valibot, t as schemaToValibot } from "./valibot-1p_Y7fu6.js";
8
8
  import { n as yup, t as schemaToYup } from "./yup-IOat93gr.js";
9
- import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-B-mxbHoq.js";
9
+ import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-q9c0XhJO.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 };
@@ -1,4 +1,4 @@
1
- import { $ as itemsSchemaOf, B as typeboxRefOpt, Bt as isNullable, D as stringboolPattern, G as renderDefinitions, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Lt as isDeepLocalPointer, Mt as hasNumericKeyword, Nt as hasStringKeyword, O as stringboolTruthyPattern, Ot as hasCombinator, Q as isOptionalByDefault, R as typeboxDefaultOpt, Rt as isDefaultOnlyMember, T as numberWirePattern, U as missingDefinitionComment, V as definitionsOf, W as planDocument, X as hasRootSelfReference, Y as cyclicDefinitionNames, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, a as typeboxWrap, at as hasNotKeyword, bt as resolveOpenAPIRef, ct as foldAllOfMembers, jt as hasFixedLength, l as withPolymorphicBases, lt as isKeywordOnlyMember, on as DEFINITION_REF_PREFIXES, q as schemaNamer, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, ut as patternSource, vn as NOT_KEYWORD_UNSUPPORTED_MARKER, vt as makeSafeKey, x as integerWirePattern, yt as normalizeTypes, z as typeboxMetaOpts, zt as isNullTypeMember } from "./helper-1oDB5NHM.js";
1
+ import { $ as itemsSchemaOf, B as typeboxRefOpt, Bt as isNullable, D as stringboolPattern, G as renderDefinitions, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Lt as isDeepLocalPointer, Mt as hasNumericKeyword, Nt as hasStringKeyword, O as stringboolTruthyPattern, Ot as hasCombinator, Q as isOptionalByDefault, R as typeboxDefaultOpt, Rt as isDefaultOnlyMember, U as missingDefinitionComment, V as definitionsOf, W as planDocument, X as hasRootSelfReference, Y as cyclicDefinitionNames, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, a as typeboxWrap, at as hasNotKeyword, bt as resolveOpenAPIRef, ct as foldAllOfMembers, jt as hasFixedLength, l as withPolymorphicBases, lt as isKeywordOnlyMember, on as DEFINITION_REF_PREFIXES, pn as INTEGER_WIRE_PATTERN, q as schemaNamer, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, ut as patternSource, vn as NOT_KEYWORD_UNSUPPORTED_MARKER, vt as makeSafeKey, xn as NUMBER_WIRE_PATTERN, yt as normalizeTypes, z as typeboxMetaOpts, zt as isNullTypeMember } from "./helper-1oDB5NHM.js";
2
2
  // src/generator/typebox/enum.ts
3
3
  function lit(v) {
4
4
  if (v === null) return "null";
@@ -320,6 +320,53 @@ function wireString(schema, ref, pattern) {
320
320
  ];
321
321
  return opts.length > 0 ? `Type.String({${opts.join(",")}})` : "Type.String()";
322
322
  }
323
+ /**
324
+ * A number-from-text wire: the `Type.String` carries its pattern as a string, the
325
+ * JSON Schema form (a `RegExp` serializes as `{}`), and each numeric bound is a
326
+ * `Type.Refine` on the text read as a number, since the decoded value is not checked.
327
+ */
328
+ function numericWire(schema, pattern, ref) {
329
+ return numericBounds(schema).reduce((wire, [check, keyword, message]) => `Type.Refine(${wire},(value)=>${check},()=>${JSON.stringify(schema[`x-${keyword}-message`] ?? schema["x-error-message"] ?? message)})`, wireString(schema, ref, JSON.stringify(pattern.source)));
330
+ }
331
+ /** The checks of the numeric keywords on `Number(value)`, with TypeBox's own messages. */
332
+ function numericBounds(schema) {
333
+ const bounds = [];
334
+ const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf } = schema;
335
+ if (minimum !== void 0) bounds.push(exclusiveMinimum === true ? [
336
+ `Number(value)>${minimum}`,
337
+ "exclusiveMinimum",
338
+ `must be > ${minimum}`
339
+ ] : [
340
+ `Number(value)>=${minimum}`,
341
+ "minimum",
342
+ `must be >= ${minimum}`
343
+ ]);
344
+ if (typeof exclusiveMinimum === "number") bounds.push([
345
+ `Number(value)>${exclusiveMinimum}`,
346
+ "exclusiveMinimum",
347
+ `must be > ${exclusiveMinimum}`
348
+ ]);
349
+ if (maximum !== void 0) bounds.push(exclusiveMaximum === true ? [
350
+ `Number(value)<${maximum}`,
351
+ "exclusiveMaximum",
352
+ `must be < ${maximum}`
353
+ ] : [
354
+ `Number(value)<=${maximum}`,
355
+ "maximum",
356
+ `must be <= ${maximum}`
357
+ ]);
358
+ if (typeof exclusiveMaximum === "number") bounds.push([
359
+ `Number(value)<${exclusiveMaximum}`,
360
+ "exclusiveMaximum",
361
+ `must be < ${exclusiveMaximum}`
362
+ ]);
363
+ if (multipleOf !== void 0) bounds.push([
364
+ `((number)=>(Number.isInteger(number)&&(1/${multipleOf})%1===0)||((remainder)=>Math.min(Math.abs(remainder),Math.abs(remainder-${multipleOf}),Math.abs(remainder+${multipleOf}))<1e-10)(number%${multipleOf}))(Number(value))`,
365
+ "multipleOf",
366
+ `must be multiple of ${multipleOf}`
367
+ ]);
368
+ return bounds;
369
+ }
323
370
  /** A keyword-only `allOf` member. TypeBox has no type-guarded check, so the keyword's type carries it. */
324
371
  function keywordSchema(schema) {
325
372
  if (hasStringKeyword(schema) && !hasNumericKeyword(schema)) return string({
@@ -451,20 +498,18 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
451
498
  const types = normalizeTypes(schema.type);
452
499
  if (types.includes("string")) return typeboxWrap(string(schema, hostRef), schema);
453
500
  if (types.includes("number")) {
454
- const base = number(schema, hostRef);
455
501
  if (isStringWireParam) {
456
- const wire = wireString(schema, hostRef, numberWirePattern());
502
+ const wire = numericWire(schema, NUMBER_WIRE_PATTERN, hostRef);
457
503
  return typeboxWrap(`Codec(${wire}).Decode((value)=>Number(value)).Encode((value)=>String(value))`, schema);
458
504
  }
459
- return typeboxWrap(base, schema);
505
+ return typeboxWrap(number(schema, hostRef), schema);
460
506
  }
461
507
  if (types.includes("integer")) {
462
- const base = integer(schema, hostRef);
463
508
  if (isStringWireParam) {
464
- const wire = wireString(schema, hostRef, integerWirePattern());
509
+ const wire = numericWire(schema, INTEGER_WIRE_PATTERN, hostRef);
465
510
  return typeboxWrap(`Codec(${wire}).Decode((value)=>Number(value)).Encode((value)=>String(value))`, schema);
466
511
  }
467
- return typeboxWrap(base, schema);
512
+ return typeboxWrap(integer(schema, hostRef), schema);
468
513
  }
469
514
  if (types.includes("boolean")) {
470
515
  if (isStringWireParam) {
package/dist/typebox.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToTypebox } from "./typebox-D1GT2WSK.js";
1
+ export { t as schemaToTypebox } from "./typebox-CnmZohGb.js";
@@ -9,11 +9,14 @@ function type(schema, rootName = DEFAULT_ROOT_NAME) {
9
9
  }
10
10
  // src/generator/zod/number.ts
11
11
  /**
12
- * Wire text checked against the integer or JSON number grammar, then read with `Number`.
12
+ * Wire text that matches the integer or JSON number grammar, read with `Number` ahead of
13
+ * `inner`; any other value reaches `inner` as it is and fails its type check.
13
14
  * `z.coerce.number()` uses `Number` on its own, which accepts `""`, `" "` and `"0x10"`.
15
+ * A `z.preprocess` and not a `z.string()` pipe, because `z.toJSONSchema` documents a pipe
16
+ * by its input and a preprocess by `inner`: the parameter stays the spec's number.
14
17
  */
15
- function zodWireNumber(kind, errorArg = "") {
16
- return `z.string().regex(${kind === "integer" ? integerWirePattern() : numberWirePattern()}${errorArg === "" ? "" : `,${errorArg}`}).transform((val)=>Number(val))`;
18
+ function zodWireNumber(kind, inner) {
19
+ return `z.preprocess((val)=>typeof val==='string'&&${kind === "integer" ? integerWirePattern() : numberWirePattern()}.test(val)?Number(val):val,${inner})`;
17
20
  }
18
21
  /**
19
22
  * Generates a Zod schema for number types (number / float32 / float64), with
@@ -67,7 +70,7 @@ function number(schema, options) {
67
70
  maximum,
68
71
  schema.multipleOf !== void 0 ? `.multipleOf(${schema.multipleOf}${multipleOfErrorArg})` : void 0
69
72
  ].filter((v) => v !== void 0).join("");
70
- if (isWire) return `${zodWireNumber("number", baseErrorArg)}.pipe(${innerChain})`;
73
+ if (isWire) return zodWireNumber("number", innerChain);
71
74
  if (isCoerce && (isFloat32 || isFloat64)) return `z.coerce.number(${baseErrorArg}).pipe(${innerChain})`;
72
75
  return innerChain;
73
76
  }
@@ -154,8 +157,7 @@ function integer(schema, options) {
154
157
  ].filter((v) => v !== void 0).join("");
155
158
  if (isWire && !isBigint && !is64) {
156
159
  const intErrorArg = errorMessage ? zodError(errorMessage) : "";
157
- const inner = isInt32 ? innerChain : `z.number(${baseErrorArg}).int(${intErrorArg})${constraints}`;
158
- return `${zodWireNumber("integer", baseErrorArg)}.pipe(${inner})`;
160
+ return zodWireNumber("integer", isInt32 ? innerChain : `z.number(${baseErrorArg}).int(${intErrorArg})${constraints}`);
159
161
  }
160
162
  if (numberChain) return `z.coerce.number(${baseErrorArg}).int(${errorMessage ? zodError(errorMessage) : ""})${constraints}`;
161
163
  if (numberPipe) return `z.coerce.number(${baseErrorArg}).pipe(${innerChain})`;
@@ -620,12 +622,12 @@ function node(schema, rootName, isZod, options) {
620
622
  });
621
623
  const readonly = (v) => options?.readonly ? `${v}.readonly()` : v;
622
624
  const wireArray = (v) => isStringWireParam ? `z.preprocess(${wireArrayOnce("val")},${v})` : v;
623
- const literalInput = (values) => {
625
+ const literalInput = (values, literal) => {
624
626
  if (values.every((v) => typeof v === "number")) {
625
- if (isInt64(schema)) return int64Input(isWireCoerced);
626
- if (isWireCoerced) return zodWireNumber(wireNumericKind(schema, values));
627
+ if (isInt64(schema)) return `${int64Input(isWireCoerced)}.pipe(${literal})`;
628
+ if (isWireCoerced) return zodWireNumber(wireNumericKind(schema, values), literal);
627
629
  }
628
- if (isWireCoerced && values.every((v) => typeof v === "boolean")) return "z.stringbool()";
630
+ if (isWireCoerced && values.every((v) => typeof v === "boolean")) return `z.stringbool().pipe(${literal})`;
629
631
  };
630
632
  const ref = (s, rn, iz) => {
631
633
  if (s.$ref === void 0) return "z.any()";
@@ -707,19 +709,16 @@ function node(schema, rootName, isZod, options) {
707
709
  const constMessage = schema["x-const-message"] ?? schema["x-error-message"];
708
710
  const errorPart = zodErrorPart(constMessage);
709
711
  const literal = typeof value === "number" && isInt64(schema) ? `z.literal(${value}n${errorPart})` : isPrimitive(value) ? `z.literal(${JSON.stringify(value)}${errorPart})` : `z.custom<${JSON.stringify(value)}>((input) => ${deepEqualExpression(value, "input")}${errorPart})`;
710
- const input = literalInput([value]);
711
- return zodWrap$1(input ? `${input}.pipe(${literal})` : literal, schema);
712
+ return zodWrap$1(literalInput([value], literal) ?? literal, schema);
712
713
  }
713
714
  if (schema.enum) {
714
715
  const values = schema.enum.filter((value) => value !== null);
715
- const input = values.length > 0 ? literalInput(values) : void 0;
716
- if (input === void 0) return zodWrap$1(_enum(enumWithoutWrappedNull(schema)), schema);
717
- const hasNull = values.length < schema.enum.length;
718
- const piped = `${input}.pipe(${_enum({
716
+ const piped = values.length > 0 ? literalInput(values, _enum({
719
717
  ...schema,
720
718
  enum: values
721
- })})`;
722
- return zodWrap$1(hasNull && !isNullable(schema) ? `${piped}.nullable()` : piped, schema);
719
+ })) : void 0;
720
+ if (piped === void 0) return zodWrap$1(_enum(enumWithoutWrappedNull(schema)), schema);
721
+ return zodWrap$1(values.length < schema.enum.length && !isNullable(schema) ? `${piped}.nullable()` : piped, schema);
723
722
  }
724
723
  if (schema.properties) return readonly(zodWrap$1(object(schema, rootName, isZod, options), schema));
725
724
  const types = normalizeTypes(schema.type);
package/dist/zod.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToZod } from "./zod-B-mxbHoq.js";
1
+ export { t as schemaToZod } from "./zod-q9c0XhJO.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schema-truth",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "Generate Zod/Valibot/Effect/TypeBox/ArkType/Ajv/Yup schemas from JSON or YAML files",
5
5
  "keywords": [
6
6
  "ajv",