schema-truth 0.8.5 → 0.8.6

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-Btq8M8tP.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-Btq8M8tP.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-Btq8M8tP.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 schemaToTypebox } from "../typebox-D1GT2WSK.js";
3
- import { n as version, t as cli } from "../cli-CtOh--vr.js";
3
+ import { n as version, t as cli } from "../cli-Btq8M8tP.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-Btq8M8tP.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-Btq8M8tP.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-Btq8M8tP.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.6";
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
@@ -6,5 +6,5 @@ import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effe
6
6
  import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-D1GT2WSK.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 };
@@ -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.6",
4
4
  "description": "Generate Zod/Valibot/Effect/TypeBox/ArkType/Ajv/Yup schemas from JSON or YAML files",
5
5
  "keywords": [
6
6
  "ajv",