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.
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-CBV4bg-0.js → arktype-CzTltPwP.js} +9 -17
  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-CB9GJ7qa.js → cli-71Np9i5L.js} +6 -9
  16. package/dist/{effect-D9pvwi_6.js → effect-Dj8qARFi.js} +21 -22
  17. package/dist/effect.d.ts +3 -5
  18. package/dist/effect.js +1 -1
  19. package/dist/{helper-S7SSsYwh.js → helper-WSNbEQKr.js} +1344 -52
  20. package/dist/{index-G7UqNQ4w.d.ts → index-DLVjyrKu.d.ts} +0 -14
  21. package/dist/{index-EK43HM_z.d.ts → index-DU2Nd8eI.d.ts} +1 -5
  22. package/dist/index.d.ts +2 -20
  23. package/dist/index.js +9 -9
  24. package/dist/{parser-CyJ2auea.js → parser-RBrkz7ZL.js} +2 -4
  25. package/dist/{typebox-DGGKJLdP.js → typebox-RAJnIZwI.js} +9 -17
  26. package/dist/typebox.d.ts +3 -5
  27. package/dist/typebox.js +1 -1
  28. package/dist/{valibot-B6y4VQFF.js → valibot-CLUhG6tp.js} +12 -21
  29. package/dist/valibot.d.ts +3 -5
  30. package/dist/valibot.js +1 -1
  31. package/dist/{yup-DuqQwHUv.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-CXo9NFuF.js → zod-BhYAQ3iW.js} +12 -22
  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
package/README.md CHANGED
@@ -81,7 +81,7 @@ import { Schema } from 'effect'
81
81
  export const User = Schema.Struct({
82
82
  name: Schema.String,
83
83
  email: Schema.String.check(Schema.isPattern(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/)),
84
- age: Schema.optional(Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0))),
84
+ age: Schema.optionalKey(Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0))),
85
85
  })
86
86
  ```
87
87
 
@@ -1,5 +1,5 @@
1
- import { c as normalizeTypes, s as makeSafeKey } from "./utils-Bky98UmP.js";
2
- //#region src/generator/ajv/integer.ts
1
+ import { _t as makeSafeKey, s as sanitizeSchema, vt as normalizeTypes } from "./helper-WSNbEQKr.js";
2
+ // src/generator/ajv/integer.ts
3
3
  /**
4
4
  * Reconstruct a draft-07 integer schema. `minimum` is the only numeric keyword
5
5
  * in this slice; `maximum`, `exclusiveMinimum` and `multipleOf` are dropped.
@@ -9,8 +9,7 @@ function integer(schema) {
9
9
  if (typeof schema.minimum === "number") parts.push(`minimum:${schema.minimum}`);
10
10
  return `{${parts.join(",")}}`;
11
11
  }
12
- //#endregion
13
- //#region src/generator/ajv/number.ts
12
+ // src/generator/ajv/number.ts
14
13
  /**
15
14
  * Reconstruct a draft-07 number schema. `minimum` is the only numeric keyword
16
15
  * in this slice; `maximum`, `exclusiveMinimum` and `multipleOf` are dropped.
@@ -20,8 +19,7 @@ function number(schema) {
20
19
  if (typeof schema.minimum === "number") parts.push(`minimum:${schema.minimum}`);
21
20
  return `{${parts.join(",")}}`;
22
21
  }
23
- //#endregion
24
- //#region src/generator/ajv/object.ts
22
+ // src/generator/ajv/object.ts
25
23
  /**
26
24
  * Reconstruct a draft-07 object schema from `type`, `properties` and `required`.
27
25
  * Property values recurse through {@link ajv}; other object keywords are dropped.
@@ -38,8 +36,7 @@ function object(schema) {
38
36
  }
39
37
  return `{${parts.join(",")}}`;
40
38
  }
41
- //#endregion
42
- //#region src/generator/ajv/string.ts
39
+ // src/generator/ajv/string.ts
43
40
  /**
44
41
  * Reconstruct a draft-07 string schema. `format` is emitted only for `email`
45
42
  * (the first-slice format); every other string keyword is dropped.
@@ -49,8 +46,7 @@ function string(schema) {
49
46
  if (schema.format === "email") parts.push(`format:'email'`);
50
47
  return `{${parts.join(",")}}`;
51
48
  }
52
- //#endregion
53
- //#region src/generator/ajv/ajv.ts
49
+ // src/generator/ajv/ajv.ts
54
50
  /**
55
51
  * One schema node to one Ajv draft-07 schema-object expression.
56
52
  *
@@ -72,8 +68,7 @@ function ajv(schema) {
72
68
  if (types.includes("object")) return object(schema);
73
69
  return "{}";
74
70
  }
75
- //#endregion
76
- //#region src/generator/ajv/index.ts
71
+ // src/generator/ajv/index.ts
77
72
  /**
78
73
  * Convert a JSON Schema document to Ajv TypeScript: a reconstructed draft-07
79
74
  * schema object and `ajv.compile(...)`.
@@ -92,7 +87,7 @@ function ajv(schema) {
92
87
  * @returns Generated TypeScript/Ajv code string
93
88
  */
94
89
  function schemaToAjv(schema, options) {
95
- const expression = ajv(schema);
90
+ const expression = ajv(sanitizeSchema(schema));
96
91
  const withFormats = expression.includes("format:'email'");
97
92
  return [
98
93
  withFormats ? `import Ajv from 'ajv'\nimport addFormats from 'ajv-formats'` : `import Ajv from 'ajv'`,
@@ -101,5 +96,4 @@ function schemaToAjv(schema, options) {
101
96
  `export const validate = ajv.compile(schema)`
102
97
  ].join("\n\n");
103
98
  }
104
- //#endregion
105
99
  export { ajv as n, schemaToAjv as t };
package/dist/ajv.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { r as JSONSchema } from "./index-G7UqNQ4w.js";
2
- //#region src/generator/ajv/index.d.ts
1
+ import { r as JSONSchema } from "./index-DLVjyrKu.js";
3
2
  /**
4
3
  * Convert a JSON Schema document to Ajv TypeScript: a reconstructed draft-07
5
4
  * schema object and `ajv.compile(...)`.
@@ -20,5 +19,4 @@ import { r as JSONSchema } from "./index-G7UqNQ4w.js";
20
19
  export declare function schemaToAjv(schema: JSONSchema, options?: {
21
20
  exportType?: boolean;
22
21
  readonly?: boolean;
23
- }): string;
24
- //#endregion
22
+ }): string;
package/dist/ajv.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToAjv } from "./ajv-DS9gtNZC.js";
1
+ export { t as schemaToAjv } from "./ajv-DejgT2o1.js";
@@ -1,6 +1,5 @@
1
- import { $ as DEFINITION_REF_PREFIXES, At as UNSAFE_GENERATED_MARKER, B as isSchemaObject, D as isComposite, E as isArktypeDefinition, H as isStringWireLocation, I as isQuoted, M as isNullable, N as isObjectPrototypeProperty, O as isDeepLocalPointer, R as isRootRef, S as hasFixedLength, St as QUOTE_OR_BACKSLASH_PATTERN, V as isShapelessMember, X as DEFAULT_ROOT_NAME, at as INTEGER_TEXT_PATTERN, c as normalizeTypes, j as isNullTypeMember, l as resolveOpenAPIRef, o as issueMessageExpression, pt as NUMBER_RANGES, s as makeSafeKey, x as hasFixedItemCount, y as hasCombinator } from "./utils-Bky98UmP.js";
2
- import { $ as callbackReturn, A as wireNullText, B as emitOptionsOf, C as isPrimitiveUnion, D as stringboolTruthyPattern, E as stringboolPattern, G as schemaNamer, H as planDocument, K as discriminatedMembers, M as formatPattern, N as regexSource, O as unionPrimitiveTypes, Q as arktypeWrap, S as isNullTextRead, T as ownProperties, V as missingDefinitionComment, W as rootNameOf, X as itemsSchemaOf, Z as arktypePreprocess, at as foldAllOfMembers, b as integerWirePattern, c as withPolymorphicBases, ct as regexLiteral, d as propertyEmitOptions, et as callbackType, f as withoutParameterSerialization, g as hoistNestedRefs, h as valueListLiteral, i as isEvaluatedKeyExpression, it as constraintPredicate, j as wireNumericKind, k as wireArrayOnce, l as hasParameterSerialization, m as notPredicate, ot as isKeywordOnlyMember, p as isBigintFormat, r as evaluatedProperties, rt as constraintMessage, tt as findCodeExtensionKeysInSchema, u as parameterReaders, w as numberWirePattern, x as isNullMatchedFirst, y as impliedWireType, z as definitionsOf } from "./helper-S7SSsYwh.js";
3
- //#region src/generator/arktype/number.ts
1
+ import { $ as arktypePreprocess, A as wireArrayOnce, At as hasFixedLength, Bt as isObjectPrototypeProperty, C as isNullTextRead, D as stringboolPattern, Dt as hasCombinator, E as ownProperties, Ft as isComposite, Gt as isRootRef, H as emitOptionsOf, In as UNSAFE_GENERATED_MARKER, It as isDeepLocalPointer, J as discriminatedMembers, Jt as isStringWireLocation, K as rootNameOf, Kt as isSchemaObject, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, On as QUOTE_OR_BACKSLASH_PATTERN, P as regexSource, Pt as isArktypeDefinition, Q as itemsSchemaOf, Rt as isNullTypeMember, S as isNullMatchedFirst, T as numberWirePattern, U as missingDefinitionComment, Ut as isQuoted, V as definitionsOf, W as planDocument, _ as hoistNestedRefs, _t as makeSafeKey, an as DEFINITION_REF_PREFIXES, at as constraintMessage, b as impliedWireType, ct as isKeywordOnlyMember, d as parameterReaders, dn as INTEGER_TEXT_PATTERN, et as arktypeWrap, f as propertyEmitOptions, g as valueListLiteral, gt as issueMessageExpression, h as notPredicate, i as isEvaluatedKeyExpression, j as wireNullText, k as unionPrimitiveTypes, kt as hasFixedItemCount, l as withPolymorphicBases, m as isBigintFormat, nn as DEFAULT_ROOT_NAME, nt as callbackType, ot as constraintPredicate, p as withoutParameterSerialization, q as schemaNamer, qt as isShapelessMember, r as evaluatedProperties, rt as findCodeExtensionKeysInSchema, s as sanitizeSchema, st as foldAllOfMembers, tt as callbackReturn, u as hasParameterSerialization, ut as regexLiteral, vt as normalizeTypes, w as isPrimitiveUnion, x as integerWirePattern, yn as NUMBER_RANGES, yt as resolveOpenAPIRef, zt as isNullable } from "./helper-WSNbEQKr.js";
2
+ // src/generator/arktype/number.ts
4
3
  /** The comparators of a numeric node: `>= 1`, `< 5`, `% 2`. */
5
4
  function numericConstraints(schema) {
6
5
  return [
@@ -149,8 +148,7 @@ function number(schema) {
149
148
  function boundMethod(bound) {
150
149
  return `.${bound.op === ">=" ? "atLeast" : bound.op === ">" ? "moreThan" : bound.op === "<=" ? "atMost" : bound.op === "<" ? "lessThan" : "divisibleBy"}(${bound.value})`;
151
150
  }
152
- //#endregion
153
- //#region src/generator/arktype/integer.ts
151
+ // src/generator/arktype/integer.ts
154
152
  /** Whether a node is a 64-bit integer: a value beyond 2^53 that is read as a bigint. */
155
153
  function isInt64(schema) {
156
154
  return schema.format === "int64" || schema.format === "uint64";
@@ -201,8 +199,7 @@ function integer(schema, options) {
201
199
  if (errorMessage) return `type(${definition})${describe}`;
202
200
  return definition;
203
201
  }
204
- //#endregion
205
- //#region src/generator/arktype/enum.ts
202
+ // src/generator/arktype/enum.ts
206
203
  function lit(v, isBigint) {
207
204
  if (v === null) return "null";
208
205
  if (typeof v === "string") return `'${v}'`;
@@ -234,8 +231,7 @@ function _enum(schema) {
234
231
  if (errorMessage) return `type(${expr})${describe}`;
235
232
  return expr;
236
233
  }
237
- //#endregion
238
- //#region src/generator/arktype/object.ts
234
+ // src/generator/arktype/object.ts
239
235
  /**
240
236
  * An object definition with its narrows. Inside a scope they stay in definition syntax
241
237
  * (`[def, ":", fn]`), which the scope resolves; outside, they chain on `type(def)`.
@@ -363,8 +359,7 @@ function object(schema, rootName, isArktype, options) {
363
359
  const hasInheritedName = Object.keys(properties).some(isObjectPrototypeProperty);
364
360
  return isStringWireLocation(options?.paramIn) && hasInheritedName ? `${arktypePreprocess([ownProperties("data")], described, "object")}.pipe((data) => ({ ...data }))` : described;
365
361
  }
366
- //#endregion
367
- //#region src/generator/arktype/string.ts
362
+ // src/generator/arktype/string.ts
368
363
  /** The formats ArkType checks with a keyword of its own, keyed by the lower-cased format. */
369
364
  const FORMAT_KEYWORD = {
370
365
  email: "string.email",
@@ -467,8 +462,7 @@ function string(schema) {
467
462
  if (narrows.length === 0 && !errorMessage) return patterned;
468
463
  return `${isQuoted(patterned) ? `type(${patterned})` : patterned}${narrows.join("")}${describe}`;
469
464
  }
470
- //#endregion
471
- //#region src/generator/arktype/arktype.ts
465
+ // src/generator/arktype/arktype.ts
472
466
  /**
473
467
  * Combine two ArkType expressions.
474
468
  *
@@ -787,15 +781,14 @@ function node(schema, rootName, isArktype, options) {
787
781
  if (typeof schema.additionalProperties === "object") return readonly(arktypeWrap$1(object(schema, rootName, isArktype, options), schema));
788
782
  return arktypeWrap$1("\"unknown\"", schema);
789
783
  }
790
- //#endregion
791
- //#region src/generator/arktype/index.ts
784
+ // src/generator/arktype/index.ts
792
785
  /**
793
786
  * A whole JSON Schema document as an ArkType module. A document with definitions becomes
794
787
  * a `scope({...}).export()` so members can name one another; one without is a bare
795
788
  * `type(...)` export.
796
789
  */
797
790
  function schemaToArktype(input, options) {
798
- const schema = withPolymorphicBases(hoistNestedRefs(input));
791
+ const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
799
792
  const exportType = options?.exportType ?? true;
800
793
  const baseOptions = emitOptionsOf(options);
801
794
  const prefix = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0 ? [UNSAFE_GENERATED_MARKER] : [];
@@ -846,5 +839,4 @@ function schemaToArktype(input, options) {
846
839
  ...exportType ? [`export type ${rootName} = typeof ${rootName}.infer`] : []
847
840
  ].filter(Boolean).join("\n\n");
848
841
  }
849
- //#endregion
850
842
  export { arktype as n, schemaToArktype as t };
package/dist/arktype.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import { r as JSONSchema } from "./index-G7UqNQ4w.js";
2
- import { n as GenerateOptions } from "./index-EK43HM_z.js";
3
- //#region src/generator/arktype/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 an ArkType module. A document with definitions becomes
6
5
  * a `scope({...}).export()` so members can name one another; one without is a bare
7
6
  * `type(...)` export.
8
7
  */
9
- export declare function schemaToArktype(input: JSONSchema, options?: GenerateOptions): string;
10
- //#endregion
8
+ export declare function schemaToArktype(input: JSONSchema, options?: GenerateOptions): string;
package/dist/arktype.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToArktype } from "./arktype-CBV4bg-0.js";
1
+ export { t as schemaToArktype } from "./arktype-CzTltPwP.js";
package/dist/cli/ajv.js CHANGED
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToAjv } from "../ajv-DS9gtNZC.js";
3
- import { n as version, t as cli } from "../cli-CB9GJ7qa.js";
2
+ import { t as schemaToAjv } from "../ajv-DejgT2o1.js";
3
+ import { n as version, t as cli } from "../cli-71Np9i5L.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";
7
- //#region src/ajv.ts
7
+ // src/ajv.ts
8
8
  NodeRuntime.runMain(cli({
9
9
  name: "schema-truth-ajv",
10
10
  generator: schemaToAjv,
11
11
  description: "Generate Ajv schemas from a JSON Schema document",
12
12
  version
13
13
  }).pipe(Effect.provide(NodeServices.layer)));
14
- //#endregion
15
14
  export {};
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToArktype } from "../arktype-CBV4bg-0.js";
3
- import { n as version, t as cli } from "../cli-CB9GJ7qa.js";
2
+ import { t as schemaToArktype } from "../arktype-CzTltPwP.js";
3
+ import { n as version, t as cli } from "../cli-71Np9i5L.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";
7
- //#region src/arktype.ts
7
+ // src/arktype.ts
8
8
  NodeRuntime.runMain(cli({
9
9
  name: "schema-truth-arktype",
10
10
  generator: schemaToArktype,
11
11
  description: "Generate ArkType schemas from a JSON Schema document",
12
12
  version
13
13
  }).pipe(Effect.provide(NodeServices.layer)));
14
- //#endregion
15
14
  export {};
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToEffect } from "../effect-D9pvwi_6.js";
3
- import { n as version, t as cli } from "../cli-CB9GJ7qa.js";
2
+ import { t as schemaToEffect } from "../effect-Dj8qARFi.js";
3
+ import { n as version, t as cli } from "../cli-71Np9i5L.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";
7
- //#region src/effect.ts
7
+ // src/effect.ts
8
8
  NodeRuntime.runMain(cli({
9
9
  name: "schema-truth-effect",
10
10
  generator: schemaToEffect,
11
11
  description: "Generate Effect Schema code from a JSON Schema document",
12
12
  version
13
13
  }).pipe(Effect.provide(NodeServices.layer)));
14
- //#endregion
15
14
  export {};
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToTypebox } from "../typebox-DGGKJLdP.js";
3
- import { n as version, t as cli } from "../cli-CB9GJ7qa.js";
2
+ import { t as schemaToTypebox } from "../typebox-RAJnIZwI.js";
3
+ import { n as version, t as cli } from "../cli-71Np9i5L.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";
7
- //#region src/typebox.ts
7
+ // src/typebox.ts
8
8
  NodeRuntime.runMain(cli({
9
9
  name: "schema-truth-typebox",
10
10
  generator: schemaToTypebox,
11
11
  description: "Generate TypeBox schemas from a JSON Schema document",
12
12
  version
13
13
  }).pipe(Effect.provide(NodeServices.layer)));
14
- //#endregion
15
14
  export {};
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToValibot } from "../valibot-B6y4VQFF.js";
3
- import { n as version, t as cli } from "../cli-CB9GJ7qa.js";
2
+ import { t as schemaToValibot } from "../valibot-CLUhG6tp.js";
3
+ import { n as version, t as cli } from "../cli-71Np9i5L.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";
7
- //#region src/valibot.ts
7
+ // src/valibot.ts
8
8
  NodeRuntime.runMain(cli({
9
9
  name: "schema-truth-valibot",
10
10
  generator: schemaToValibot,
11
11
  description: "Generate Valibot schemas from a JSON Schema document",
12
12
  version
13
13
  }).pipe(Effect.provide(NodeServices.layer)));
14
- //#endregion
15
14
  export {};
package/dist/cli/yup.js CHANGED
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToYup } from "../yup-DuqQwHUv.js";
3
- import { n as version, t as cli } from "../cli-CB9GJ7qa.js";
2
+ import { t as schemaToYup } from "../yup-DfE_ofEu.js";
3
+ import { n as version, t as cli } from "../cli-71Np9i5L.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";
7
- //#region src/yup.ts
7
+ // src/yup.ts
8
8
  NodeRuntime.runMain(cli({
9
9
  name: "schema-truth-yup",
10
10
  generator: schemaToYup,
11
11
  description: "Generate Yup schemas from a JSON Schema document",
12
12
  version
13
13
  }).pipe(Effect.provide(NodeServices.layer)));
14
- //#endregion
15
14
  export {};
package/dist/cli/zod.js CHANGED
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToZod } from "../zod-CXo9NFuF.js";
3
- import { n as version, t as cli } from "../cli-CB9GJ7qa.js";
2
+ import { t as schemaToZod } from "../zod-BhYAQ3iW.js";
3
+ import { n as version, t as cli } from "../cli-71Np9i5L.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";
7
- //#region src/zod.ts
7
+ // src/zod.ts
8
8
  NodeRuntime.runMain(cli({
9
9
  name: "schema-truth-zod",
10
10
  generator: schemaToZod,
11
11
  description: "Generate Zod schemas from a JSON Schema document",
12
12
  version
13
13
  }).pipe(Effect.provide(NodeServices.layer)));
14
- //#endregion
15
14
  export {};
@@ -1,5 +1,5 @@
1
- import { L as isRecord } from "./utils-Bky98UmP.js";
2
- import { i as fmt, n as parseSchemaFile } from "./parser-CyJ2auea.js";
1
+ import { Wt as isRecord } from "./helper-WSNbEQKr.js";
2
+ import { i as fmt, n as parseSchemaFile } from "./parser-RBrkz7ZL.js";
3
3
  import * as Effect from "effect/Effect";
4
4
  import path from "node:path";
5
5
  import { Argument, CliError, Command, Flag } from "effect/cli";
@@ -8,10 +8,9 @@ import * as Schema from "effect/Schema";
8
8
  import * as Stdio from "effect/Stdio";
9
9
  import "@effect/platform-node/NodeFileSystem";
10
10
  import * as FileSystem from "effect/FileSystem";
11
- //#region package.json
12
- var version = "0.8.2";
13
- //#endregion
14
- //#region src/file/index.ts
11
+ // package.json
12
+ var version = "0.8.3";
13
+ // src/file/index.ts
15
14
  /** Creates the directory and its parents. An existing directory is not an error. */
16
15
  function mkdir(dir) {
17
16
  return Effect.gen(function* () {
@@ -31,8 +30,7 @@ function writeFile(path, data) {
31
30
  yield* fs.writeFileString(path, data);
32
31
  });
33
32
  }
34
- //#endregion
35
- //#region src/cli/index.ts
33
+ // src/cli/index.ts
36
34
  const InputPathSchema = Schema.String.pipe(Schema.refine(Schema.is(Schema.TemplateLiteral([Schema.String, Schema.Literals([".json", ".yaml"])])), { message: "a JSON Schema document ending in .json or .yaml" }));
37
35
  const OutputPathSchema = Schema.String.pipe(Schema.refine(Schema.is(Schema.TemplateLiteral([Schema.String, ".ts"])), { message: "a TypeScript file path ending in .ts" }));
38
36
  /**
@@ -120,5 +118,4 @@ function cli(options) {
120
118
  return yield* runCli(options, yield* (yield* Stdio.Stdio).args);
121
119
  });
122
120
  }
123
- //#endregion
124
121
  export { version as n, cli as t };
@@ -1,6 +1,5 @@
1
- import { At as UNSAFE_GENERATED_MARKER, B as isSchemaObject, H as isStringWireLocation, M as isNullable, N as isObjectPrototypeProperty, S as hasFixedLength, T as hasType, V as isShapelessMember, X as DEFAULT_ROOT_NAME, at as INTEGER_TEXT_PATTERN, b as hasConditional, c as normalizeTypes, i as effectMessage, j as isNullTypeMember, k as isDefaultOnlyMember, n as effectError, pt as NUMBER_RANGES, r as effectErrorPart, s as makeSafeKey, x as hasFixedItemCount, y as hasCombinator } from "./utils-Bky98UmP.js";
2
- import { B as emitOptionsOf, C as isPrimitiveUnion, D as stringboolTruthyPattern, E as stringboolPattern, F as jsLiteral, G as schemaNamer, H as planDocument, J as hasRootSelfReference, K as discriminatedMembers, M as formatPattern, N as regexSource, O as unionPrimitiveTypes, S as isNullTextRead, T as ownProperties, U as renderDefinitions, W as rootNameOf, X as itemsSchemaOf, _ as effectPreprocess, at as foldAllOfMembers, b as integerWirePattern, c as withPolymorphicBases, ct as regexLiteral, d as propertyEmitOptions, f as withoutParameterSerialization, g as hoistNestedRefs, h as valueListLiteral, i as isEvaluatedKeyExpression, it as constraintPredicate, j as wireNumericKind, k as wireArrayOnce, l as hasParameterSerialization, m as notPredicate, o as typeDeclaration, ot as isKeywordOnlyMember, p as isBigintFormat, r as evaluatedProperties, rt as constraintMessage, s as refTarget, tt as findCodeExtensionKeysInSchema, u as parameterReaders, v as effectWrap, w as numberWirePattern, y as impliedWireType, z as definitionsOf } from "./helper-S7SSsYwh.js";
3
- //#region src/generator/effect/number.ts
1
+ import { A as wireArrayOnce, At as hasFixedLength, Bt as isObjectPrototypeProperty, C as isNullTextRead, D as stringboolPattern, Dt as hasCombinator, E as ownProperties, Ft as isComposite, G as renderDefinitions, H as emitOptionsOf, 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, T as numberWirePattern, V as definitionsOf, W as planDocument, X as hasRootSelfReference, _ 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, ft as effectError, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, k as unionPrimitiveTypes, kt as hasFixedItemCount, l as withPolymorphicBases, m as isBigintFormat, mt as effectMessage, nn as DEFAULT_ROOT_NAME, o as typeDeclaration, ot as constraintPredicate, p as withoutParameterSerialization, pt as effectErrorPart, q as schemaNamer, qt as isShapelessMember, r as evaluatedProperties, rt as findCodeExtensionKeysInSchema, s as sanitizeSchema, st as foldAllOfMembers, u as hasParameterSerialization, ut as regexLiteral, v as effectPreprocess, vt as normalizeTypes, w as isPrimitiveUnion, x as integerWirePattern, y as effectWrap, yn as NUMBER_RANGES, zt as isNullable } from "./helper-WSNbEQKr.js";
2
+ // src/generator/effect/number.ts
4
3
  /** The bound and `multipleOf` checks of a numeric node. */
5
4
  function numberChecks(schema, lit = (n) => `${n}`, suffix = "") {
6
5
  const minimumMessage = schema["x-minimum-message"];
@@ -50,8 +49,7 @@ function number(schema, options) {
50
49
  const base = checks.length > 0 ? `${input}.check(${checks.join(",")})` : input;
51
50
  return errorMessage ? `${base}.annotate(${effectError(errorMessage)})` : base;
52
51
  }
53
- //#endregion
54
- //#region src/generator/effect/integer.ts
52
+ // src/generator/effect/integer.ts
55
53
  /** Whether a node is a 64-bit integer: a value beyond 2^53 that is read as a bigint. */
56
54
  function isInt64(schema) {
57
55
  return schema.format === "int64" || schema.format === "uint64";
@@ -90,8 +88,7 @@ function integer(schema, options) {
90
88
  const checks = [schema.format === "int32" || schema.format === "uint32" ? `Schema.${schema.format === "uint32" ? "isUint32" : "isInt32"}(${errorMessage ? effectError(errorMessage) : ""})` : errorMessage ? `Schema.isInt(${effectError(errorMessage)})` : "Schema.isInt()", ...numberChecks(schema)];
91
89
  return `${isWire ? wireNumericInput("integer") : "Schema.Number"}.check(${checks.join(",")})`;
92
90
  }
93
- //#endregion
94
- //#region src/generator/effect/enum.ts
91
+ // src/generator/effect/enum.ts
95
92
  function literal(v, isBigint) {
96
93
  if (v === null) return "null";
97
94
  if (typeof v === "string") return `"${v}"`;
@@ -100,6 +97,13 @@ function literal(v, isBigint) {
100
97
  return JSON.stringify(v) ?? "null";
101
98
  }
102
99
  /**
100
+ * A schema of JSON values compared by deep equality: `Schema.Literal` takes only a
101
+ * primitive, so an object or array value is matched by a guard.
102
+ */
103
+ function deepEqualSchema(values) {
104
+ return `Schema.declare((input: unknown): input is ${values.map((v) => JSON.stringify(v) ?? "null").join("|")} => ${values.map((v) => `(${deepEqualExpression(v, "input")})`).join("||")})`;
105
+ }
106
+ /**
103
107
  * Generates an Effect Schema enum. Multi-value scalar enums map to
104
108
  * `Schema.Literals([...])` (v4 dropped the variadic `Schema.Literal(a, b)`
105
109
  * overload), array enums to `Schema.Tuple` or `Schema.Union`, single values to
@@ -127,12 +131,12 @@ function _enum(schema) {
127
131
  if (hasType(schema, "number") || hasType(schema, "integer") || hasType(schema, "boolean")) return annotate(literals(schema.enum));
128
132
  if (hasType(schema, "array")) {
129
133
  if (schema.enum.length === 1 && Array.isArray(schema.enum[0])) return annotate(tuple(schema.enum[0]));
130
- return annotate(`Schema.Union([${schema.enum.map((v) => Array.isArray(v) ? tuple(v) : `Schema.Literal(${lit(v)})`).join(",")}])`);
134
+ return annotate(`Schema.Union([${schema.enum.map((v) => Array.isArray(v) ? tuple(v) : isComposite(v) ? deepEqualSchema([v]) : `Schema.Literal(${lit(v)})`).join(",")}])`);
131
135
  }
136
+ if (schema.enum.some(isComposite)) return annotate(deepEqualSchema(schema.enum));
132
137
  return annotate(literals(schema.enum));
133
138
  }
134
- //#endregion
135
- //#region src/generator/effect/object.ts
139
+ // src/generator/effect/object.ts
136
140
  /**
137
141
  * Generate an Effect Schema object node.
138
142
  *
@@ -198,7 +202,7 @@ function object(schema, rootName, isEffect, options) {
198
202
  const safeKey = makeSafeKey(key);
199
203
  const isRequired = required.has(key);
200
204
  const hasDecodingDefault = parsed.includes("Schema.withDecodingDefault");
201
- return isRequired || hasDecodingDefault ? `${safeKey}:${parsed}` : `${safeKey}:Schema.optional(${parsed})`;
205
+ return isRequired || hasDecodingDefault ? `${safeKey}:${parsed}` : `${safeKey}:Schema.optionalKey(${parsed})`;
202
206
  }).filter((p) => p !== null);
203
207
  const readsUndeclaredKeys = hasConditional(schema) || schema.patternProperties !== void 0 || schema.propertyNames !== void 0 || schema.minProperties !== void 0 || schema.maxProperties !== void 0 || schema.dependentRequired !== void 0 || checksKeys;
204
208
  const struct = `Schema.Struct({${props.join(",")}})`;
@@ -254,8 +258,7 @@ function object(schema, rootName, isEffect, options) {
254
258
  const hasInheritedName = Object.keys(properties).some(isObjectPrototypeProperty);
255
259
  return isStringWireLocation(options?.paramIn) && hasInheritedName ? effectPreprocess([ownProperties("input")], objectExpr) : objectExpr;
256
260
  }
257
- //#endregion
258
- //#region src/generator/effect/string.ts
261
+ // src/generator/effect/string.ts
259
262
  /**
260
263
  * Formats whose Effect Schema v4 equivalent is a check on `Schema.String`.
261
264
  * v3 shipped `Schema.UUID` / `Schema.ULID` schemas; v4 expresses both as
@@ -352,8 +355,7 @@ function string(schema) {
352
355
  const base = stringBase(schema, formatName === void 0 ? void 0 : TRANSFORM_FORMATS[formatName]);
353
356
  return annotate(checks.length > 0 ? `${base}.check(${checks.join(",")})` : base);
354
357
  }
355
- //#endregion
356
- //#region src/generator/effect/effect.ts
358
+ // src/generator/effect/effect.ts
357
359
  /**
358
360
  * The boolean spellings of the wire, read into a boolean as `z.stringbool()` reads them:
359
361
  * `true` / `1` / `yes` / `on` / `y` / `enabled` and their opposites, in any case. v3
@@ -535,7 +537,7 @@ function node(schema, rootName, isEffect, options) {
535
537
  }
536
538
  if (schema.const !== void 0) {
537
539
  const constMessage = schema["x-const-message"] ?? schema["x-error-message"];
538
- const literalCode = typeof schema.const === "number" && isInt64(schema) ? `Schema.Literal(${schema.const}n)` : `Schema.Literal(${JSON.stringify(schema.const)})`;
540
+ const literalCode = typeof schema.const === "number" && isInt64(schema) ? `Schema.Literal(${schema.const}n)` : isComposite(schema.const) ? deepEqualSchema([schema.const]) : `Schema.Literal(${JSON.stringify(schema.const)})`;
539
541
  const withMessage = constMessage ? `${literalCode}.annotate(${effectError(constMessage)})` : literalCode;
540
542
  const input = literalInput([schema.const]);
541
543
  return effectWrap$1(input ? `${input}.pipe(Schema.decodeTo(${withMessage}))` : withMessage, schema);
@@ -642,8 +644,7 @@ function node(schema, rootName, isEffect, options) {
642
644
  if (typeof schema.additionalProperties === "object") return effectWrap$1(object(schema, rootName, isEffect, options), schema);
643
645
  return effectWrap$1("Schema.Unknown", schema);
644
646
  }
645
- //#endregion
646
- //#region src/generator/effect/type.ts
647
+ // src/generator/effect/type.ts
647
648
  /**
648
649
  * The TypeScript type declared beside a recursive Effect schema: its decoded `Type`, whose
649
650
  * arrays and properties are `readonly` as `Schema.Struct` and `Schema.Array` decode them.
@@ -654,8 +655,7 @@ function type(schema, rootName = DEFAULT_ROOT_NAME) {
654
655
  readonly: true
655
656
  }, rootName);
656
657
  }
657
- //#endregion
658
- //#region src/generator/effect/index.ts
658
+ // src/generator/effect/index.ts
659
659
  /** The root name when the document has none, or when its title would shadow the import. */
660
660
  const EFFECT_ROOT_FALLBACK = `${DEFAULT_ROOT_NAME}_`;
661
661
  /**
@@ -666,7 +666,7 @@ const EFFECT_ROOT_FALLBACK = `${DEFAULT_ROOT_NAME}_`;
666
666
  * `Schema.Array` are already readonly at the type level.
667
667
  */
668
668
  function schemaToEffect(input, options) {
669
- const schema = withPolymorphicBases(hoistNestedRefs(input));
669
+ const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
670
670
  const exportType = options?.exportType ?? true;
671
671
  const baseOptions = emitOptionsOf(options);
672
672
  const codeExtensionsPresent = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0;
@@ -701,5 +701,4 @@ function schemaToEffect(input, options) {
701
701
  ...exportType ? [`export type ${rootName} = typeof ${rootName}.Type`] : []
702
702
  ].filter(Boolean).join("\n\n");
703
703
  }
704
- //#endregion
705
704
  export { effect as n, wholeValueMessage as r, schemaToEffect as t };
package/dist/effect.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { r as JSONSchema } from "./index-G7UqNQ4w.js";
2
- import { n as GenerateOptions } from "./index-EK43HM_z.js";
3
- //#region src/generator/effect/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 an Effect Schema module: imports, `$defs` in
6
5
  * dependency order, the root export, and the inferred type.
@@ -8,5 +7,4 @@ import { n as GenerateOptions } from "./index-EK43HM_z.js";
8
7
  * `options.readonly` is accepted for API symmetry and is a no-op: `Schema.Struct` and
9
8
  * `Schema.Array` are already readonly at the type level.
10
9
  */
11
- export declare function schemaToEffect(input: JSONSchema, options?: GenerateOptions): string;
12
- //#endregion
10
+ export declare function schemaToEffect(input: JSONSchema, options?: GenerateOptions): string;
package/dist/effect.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToEffect } from "./effect-D9pvwi_6.js";
1
+ export { t as schemaToEffect } from "./effect-Dj8qARFi.js";