schema-truth 0.8.7 → 0.8.9

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.
@@ -1,4 +1,4 @@
1
- import { s as sanitizeSchema, vt as makeSafeKey, yt as normalizeTypes } from "./helper-1oDB5NHM.js";
1
+ import { s as sanitizeSchema, vt as makeSafeKey, yt as normalizeTypes } from "./helper-OCkRyx4U.js";
2
2
  // src/generator/ajv/integer.ts
3
3
  /**
4
4
  * Reconstruct a draft-07 integer schema. `minimum` is the only numeric keyword
package/dist/ajv.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToAjv } from "./ajv-BjWqjOc9.js";
1
+ export { t as schemaToAjv } from "./ajv-Oz83L2oz.js";
@@ -1,42 +1,27 @@
1
- import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, D as stringboolPattern, E as ownProperties, Ft as isArktypeDefinition, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Ln as UNSAFE_GENERATED_MARKER, Lt as isDeepLocalPointer, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, S as isNullMatchedFirst, T as numberWirePattern, U as missingDefinitionComment, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, Wt as isQuoted, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, bn as NUMBER_RANGES, bt as resolveOpenAPIRef, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, et as arktypePreprocess, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, j as wireNullText, jt as hasFixedLength, k as unionPrimitiveTypes, kn as QUOTE_OR_BACKSLASH_PATTERN, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, nt as callbackReturn, on as DEFINITION_REF_PREFIXES, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, rt as callbackType, s as sanitizeSchema, st as constraintPredicate, tt as arktypeWrap, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-1oDB5NHM.js";
1
+ import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, D as stringboolPattern, E as ownProperties, Ft as isArktypeDefinition, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Ln as UNSAFE_GENERATED_MARKER, Lt as isDeepLocalPointer, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, S as isNullMatchedFirst, T as numberWirePattern, U as missingDefinitionComment, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, Wt as isQuoted, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, bn as NUMBER_RANGES, bt as resolveOpenAPIRef, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, et as arktypePreprocess, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, j as wireNullText, jt as hasFixedLength, k as unionPrimitiveTypes, kn as QUOTE_OR_BACKSLASH_PATTERN, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, nt as callbackReturn, on as DEFINITION_REF_PREFIXES, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, rt as callbackType, s as sanitizeSchema, st as constraintPredicate, tt as arktypeWrap, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-OCkRyx4U.js";
2
2
  // src/generator/arktype/number.ts
3
3
  /** The comparators of a numeric node: `>= 1`, `< 5`, `% 2`. */
4
4
  function numericConstraints(schema) {
5
5
  return [
6
- (() => {
7
- if (schema.minimum !== void 0) return schema.exclusiveMinimum === true ? {
8
- op: ">",
9
- value: String(schema.minimum)
10
- } : {
11
- op: ">=",
12
- value: String(schema.minimum)
13
- };
14
- if (typeof schema.exclusiveMinimum === "number") return {
15
- op: ">",
16
- value: String(schema.exclusiveMinimum)
17
- };
18
- })(),
19
- (() => {
20
- if (schema.maximum !== void 0) return schema.exclusiveMaximum === true ? {
21
- op: "<",
22
- value: String(schema.maximum)
23
- } : {
24
- op: "<=",
25
- value: String(schema.maximum)
26
- };
27
- if (typeof schema.exclusiveMaximum === "number") return {
28
- op: "<",
29
- value: String(schema.exclusiveMaximum)
30
- };
31
- })(),
6
+ schema.minimum !== void 0 ? {
7
+ op: schema.exclusiveMinimum === true ? ">" : ">=",
8
+ value: String(schema.minimum)
9
+ } : typeof schema.exclusiveMinimum === "number" ? {
10
+ op: ">",
11
+ value: String(schema.exclusiveMinimum)
12
+ } : void 0,
13
+ schema.maximum !== void 0 ? {
14
+ op: schema.exclusiveMaximum === true ? "<" : "<=",
15
+ value: String(schema.maximum)
16
+ } : typeof schema.exclusiveMaximum === "number" ? {
17
+ op: "<",
18
+ value: String(schema.exclusiveMaximum)
19
+ } : void 0,
32
20
  schema.multipleOf !== void 0 ? {
33
21
  op: "%",
34
22
  value: String(schema.multipleOf)
35
23
  } : void 0
36
- ].filter(isNumericBound);
37
- }
38
- function isNumericBound(bound) {
39
- return bound !== void 0;
24
+ ].filter((bound) => bound !== void 0);
40
25
  }
41
26
  /** The range comparators of a fixed-width numeric `format`, if it has one. */
42
27
  function rangeConstraints(format) {
@@ -316,19 +301,19 @@ function object(schema, rootName, isArktype, options) {
316
301
  const minPropertiesNarrow = typeof schema.minProperties === "number" ? narrowPredicate(`Object.keys(data).length >= ${schema.minProperties}`, minimumMessage) : "";
317
302
  const maxPropertiesNarrow = typeof schema.maxProperties === "number" ? narrowPredicate(`Object.keys(data).length <= ${schema.maxProperties}`, maximumMessage) : "";
318
303
  const dependentRequiredNarrows = schema.dependentRequired ? Object.entries(schema.dependentRequired).map(([key, deps]) => {
319
- return narrowPredicate(`!('${key}' in data) || (${deps.map((d) => `'${d}' in data`).join(" && ")})`, depReqMessage);
304
+ return narrowPredicate(`!('${key}' in data) || (${deps.map((dependency) => `'${dependency}' in data`).join(" && ")})`, depReqMessage);
320
305
  }) : [];
321
306
  const dependentSchemasNarrows = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, subSchema]) => {
322
307
  return narrowPredicate(`!('${key}' in data) || ${callbackType(arktype(subSchema, rootName, isArktype, options), isArktype)}.allows(data)`, depSchMessage);
323
308
  }) : [];
324
309
  const additionalPropertiesNarrow = schema.additionalProperties === false && (addlPropsMessage !== void 0 || schema.patternProperties !== void 0) ? narrowPredicate(`Object.keys(data).every((key) => ${isEvaluated})`, addlPropsMessage) : "";
325
310
  const unevaluatedPropertiesNarrow = (() => {
326
- const u = typeof schema.additionalProperties === "object" ? schema.additionalProperties : schema.unevaluatedProperties;
327
- if (u === void 0 || u === true) return "";
311
+ const restSchema = typeof schema.additionalProperties === "object" ? schema.additionalProperties : schema.unevaluatedProperties;
312
+ if (restSchema === void 0 || restSchema === true) return "";
328
313
  const message = typeof schema.additionalProperties === "object" ? addlPropsMessage : unevalPropsRawMessage;
329
- if (u === false) return narrowPredicate(`Object.keys(data).every((key) => ${isEvaluated})`, message);
330
- if (typeof u === "object") {
331
- const s = callbackType(arktype(u, rootName, isArktype, options), isArktype);
314
+ if (restSchema === false) return narrowPredicate(`Object.keys(data).every((key) => ${isEvaluated})`, message);
315
+ if (typeof restSchema === "object") {
316
+ const s = callbackType(arktype(restSchema, rootName, isArktype, options), isArktype);
332
317
  return narrowPredicate(`Object.entries(data).every(([key, value]) => ${isEvaluated} || ${s}.allows(value))`, message);
333
318
  }
334
319
  return "";
@@ -434,7 +419,7 @@ function string(schema) {
434
419
  schema["x-toLowerCase"] === true || transformFormat === "string.lower" ? "string.lower" : void 0,
435
420
  schema["x-toUpperCase"] === true || transformFormat === "string.upper" ? "string.upper" : void 0,
436
421
  typeof schema["x-normalize"] === "string" ? `string.normalize.${schema["x-normalize"]}` : void 0
437
- ].filter((t) => t !== void 0);
422
+ ].filter((transform) => transform !== void 0);
438
423
  const format = formatDefinition(schema, transformFormat === void 0 ? formatName : void 0);
439
424
  const hasMorph = transforms.length > 0;
440
425
  const constrain = (expr, pattern) => hasMorph ? `${expr}.to(${pattern})` : `${expr}.and(${pattern})`;
@@ -465,7 +450,7 @@ function string(schema) {
465
450
  const sub = schema["x-includes"];
466
451
  narrows.push(`.narrow((data: string, ctx) => data.includes(${JSON.stringify(sub)}) || ctx.mustBe(${JSON.stringify(`must include ${JSON.stringify(sub)}`)}))`);
467
452
  }
468
- const morphed = transforms.reduce((acc, t) => acc === void 0 ? `type("${t}")` : `${acc}.to("${t}")`, void 0);
453
+ const morphed = transforms.reduce((acc, transform) => acc === void 0 ? `type("${transform}")` : `${acc}.to("${transform}")`, void 0);
469
454
  const based = morphed === void 0 ? format : format === "\"string\"" ? morphed : validateWith(morphed, format);
470
455
  const patterned = schema.pattern && !patternMessage ? constrain(isQuoted(based) ? `type(${based})` : based, regexLiteral(schema.pattern)) : based;
471
456
  if (narrows.length === 0 && !errorMessage) return patterned;
@@ -661,10 +646,10 @@ function node(schema, rootName, isArktype, options) {
661
646
  const definitions = members.map((s) => s.type === "integer" ? integer(s) : number(s));
662
647
  const isInteger = members.some((s) => s.type === "integer");
663
648
  return arktypeWrap$1(wireNumeric(isInteger ? numberMorph("isSafeInteger", "an integer") : numberMorph("isFinite", "a number"), definitions.every(isQuoted) ? (() => {
664
- const parts = definitions.map((d) => d.slice(1, -1)).filter((d) => d !== "number" && d !== "number.integer");
649
+ const parts = definitions.map((definition) => definition.slice(1, -1)).filter((definition) => definition !== "number" && definition !== "number.integer");
665
650
  if (parts.length === 0) return isInteger ? "\"number.integer\"" : "\"number\"";
666
651
  return `"${parts.join(" & ")}"`;
667
- })() : definitions.length === 1 ? definitions[0] : intersectionStr(definitions, isArktype)), {
652
+ })() : definitions.length === 1 && definitions[0] !== void 0 ? definitions[0] : intersectionStr(definitions, isArktype)), {
668
653
  ...schema,
669
654
  nullable
670
655
  });
@@ -675,7 +660,7 @@ function node(schema, rootName, isArktype, options) {
675
660
  nullable
676
661
  });
677
662
  const intersected = [...schemas, ...objectKeysMembers(schema, rootName, isArktype, options)];
678
- return arktypeWrap$1(intersected.length === 1 ? intersected[0] : intersectionStr(intersected, isArktype), {
663
+ return arktypeWrap$1(intersected.length === 1 && intersected[0] !== void 0 ? intersected[0] : intersectionStr(intersected, isArktype), {
679
664
  ...schema,
680
665
  nullable
681
666
  });
@@ -726,42 +711,42 @@ function node(schema, rootName, isArktype, options) {
726
711
  }
727
712
  if (schema.properties) return readonly(arktypeWrap$1(object(schema, rootName, isArktype, options), schema));
728
713
  const types = normalizeTypes(schema.type);
729
- const primitive = (t) => {
730
- if (t === "string") return string(schema);
731
- if (t === "number") {
714
+ const primitive = (primitiveType) => {
715
+ if (primitiveType === "string") return string(schema);
716
+ if (primitiveType === "number") {
732
717
  const definition = number(schema);
733
718
  return isWireCoerced ? wireNumeric(numberMorph("isFinite", "a number"), definition) : definition;
734
719
  }
735
- if (t === "integer") {
720
+ if (primitiveType === "integer") {
736
721
  if (isInt64(schema) || schema.format === "bigint") return integer(schema, { wire: isWireCoerced });
737
722
  const definition = integer(schema);
738
723
  return isWireCoerced ? wireNumeric(numberMorph("isSafeInteger", "an integer"), definition) : definition;
739
724
  }
740
- if (t !== "boolean") return void 0;
725
+ if (primitiveType !== "boolean") return void 0;
741
726
  return isWireCoerced ? stringbool() : "\"boolean\"";
742
727
  };
743
728
  if (isPrimitiveUnion(types, isWireCoerced)) return arktypeWrap$1(unionOf(unionPrimitiveTypes(types, isWireCoerced).map(primitive).filter((m) => m !== void 0), void 0), schema);
744
- for (const t of [
729
+ for (const primitiveType of [
745
730
  "string",
746
731
  "number",
747
732
  "integer",
748
733
  "boolean"
749
734
  ]) {
750
- if (!types.includes(t)) continue;
751
- const expression = primitive(t);
735
+ if (!types.includes(primitiveType)) continue;
736
+ const expression = primitive(primitiveType);
752
737
  if (expression !== void 0) return arktypeWrap$1(expression, schema);
753
738
  }
754
739
  if (types.includes("array")) {
755
- if (schema.prefixItems?.length) {
740
+ if (schema.prefixItems !== void 0 && schema.prefixItems.length > 0) {
756
741
  const items = schema.prefixItems.map((s) => arktype(s, rootName, isArktype, options));
757
- const u = schema.unevaluatedItems;
758
- const baseTuple = arktypeWrap$1(wireArray(describeWithMessage(isSchemaObject(u) ? (() => {
759
- const rest = arktype(u, rootName, isArktype, options);
742
+ const unevaluatedItems = schema.unevaluatedItems;
743
+ const baseTuple = arktypeWrap$1(wireArray(describeWithMessage(isSchemaObject(unevaluatedItems) ? (() => {
744
+ const rest = arktype(unevaluatedItems, rootName, isArktype, options);
760
745
  const restInner = isQuoted(rest) ? rest.slice(1, -1) : rest;
761
746
  return `type([${items.join(",")},"...","${restInner}[]"])`;
762
747
  })() : `type([${items.join(",")}])`, schema["x-prefixItems-message"])), schema);
763
748
  const unevalItemsMessage = schema["x-unevaluatedItems-message"];
764
- return u === false && unevalItemsMessage ? `${baseTuple}.describe(${JSON.stringify(unevalItemsMessage)})` : baseTuple;
749
+ return unevaluatedItems === false && unevalItemsMessage ? `${baseTuple}.describe(${JSON.stringify(unevalItemsMessage)})` : baseTuple;
765
750
  }
766
751
  const itemSchema = itemsSchemaOf(schema.items);
767
752
  const items = itemSchema ? arktype(itemSchema, rootName, isArktype, options) : "\"unknown\"";
@@ -785,7 +770,7 @@ function node(schema, rootName, isArktype, options) {
785
770
  maxContainsMessage
786
771
  ].some(Boolean);
787
772
  const andWith = (a, b) => isArktype && isArktypeDefinition(a) ? `[${a},"&",${b}]` : `type(${a}).and(type(${b}))`;
788
- const narrowWith = (a, fn) => isArktype && isArktypeDefinition(a) ? `[${a},":",${fn}]` : `${isArktypeDefinition(a) ? `type(${a})` : a}.narrow(${fn})`;
773
+ const narrowWith = (a, narrowing) => isArktype && isArktypeDefinition(a) ? `[${a},":",${narrowing}]` : `${isArktypeDefinition(a) ? `type(${a})` : a}.narrow(${narrowing})`;
789
774
  const lengthExpr = isFixedLength ? hasArrayMessage ? narrowWith(base, `(data: unknown[], ctx) => data.length === ${minItems} || ctx.mustBe(${JSON.stringify(fixedItemsMessage ?? `must contain exactly ${minItems} items`)})`) : andWith(base, `"unknown[] == ${minItems}"`) : typeof minItems === "number" && typeof maxItems === "number" ? hasArrayMessage ? narrowWith(narrowWith(base, `(data: unknown[], ctx) => data.length >= ${minItems} || ctx.mustBe(${JSON.stringify(minItemsMessage ?? `must contain at least ${minItems} items`)})`), `(data: unknown[], ctx) => data.length <= ${maxItems} || ctx.mustBe(${JSON.stringify(maxItemsMessage ?? `must contain at most ${maxItems} items`)})`) : andWith(base, `"${minItems} <= unknown[] <= ${maxItems}"`) : typeof minItems === "number" ? hasArrayMessage ? narrowWith(base, `(data: unknown[], ctx) => data.length >= ${minItems} || ctx.mustBe(${JSON.stringify(minItemsMessage ?? `must contain at least ${minItems} items`)})`) : andWith(base, `"unknown[] >= ${minItems}"`) : typeof maxItems === "number" ? hasArrayMessage ? narrowWith(base, `(data: unknown[], ctx) => data.length <= ${maxItems} || ctx.mustBe(${JSON.stringify(maxItemsMessage ?? `must contain at most ${maxItems} items`)})`) : andWith(base, `"unknown[] <= ${maxItems}"`) : base;
790
775
  const uniqueExpr = schema.uniqueItems === true ? narrowWith(lengthExpr, `(data: unknown[], ctx) => new Set(data).size === data.length${uniqueItemsMessage ? ` || ctx.mustBe(${JSON.stringify(uniqueItemsMessage)})` : ""}`) : lengthExpr;
791
776
  return arktypeWrap$1(wireArray(describeWithMessage((() => {
@@ -817,7 +802,7 @@ function schemaToArktype(input, options) {
817
802
  const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
818
803
  const exportType = options?.exportType ?? true;
819
804
  const baseOptions = emitOptionsOf(options);
820
- const prefix = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0 ? [UNSAFE_GENERATED_MARKER] : [];
805
+ const prefix = baseOptions.unsafeCodeExtensions && findCodeExtensionKeysInSchema(schema).length > 0 ? [UNSAFE_GENERATED_MARKER] : [];
821
806
  const toName = schemaNamer(baseOptions.openapi);
822
807
  const plan = planDocument(schema, rootNameOf(schema, toName));
823
808
  const definitions = definitionsOf(baseOptions, plan.definitions);
package/dist/arktype.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToArktype } from "./arktype-pHeYh_IG.js";
1
+ export { t as schemaToArktype } from "./arktype-DDbxpolC.js";
package/dist/cli/ajv.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as schemaToAjv } from "../ajv-BjWqjOc9.js";
3
- import { n as version, t as cli } from "../cli-CLh6PrSG.js";
2
+ import { t as schemaToAjv } from "../ajv-Oz83L2oz.js";
3
+ import { n as version, t as cli } from "../cli-PNyg10lA.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 schemaToArktype } from "../arktype-pHeYh_IG.js";
3
- import { n as version, t as cli } from "../cli-CLh6PrSG.js";
2
+ import { t as schemaToArktype } from "../arktype-DDbxpolC.js";
3
+ import { n as version, t as cli } from "../cli-PNyg10lA.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 schemaToEffect } from "../effect-CM1XVqvf.js";
3
- import { n as version, t as cli } from "../cli-CLh6PrSG.js";
2
+ import { t as schemaToEffect } from "../effect-CHLS1Yit.js";
3
+ import { n as version, t as cli } from "../cli-PNyg10lA.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-CnmZohGb.js";
3
- import { n as version, t as cli } from "../cli-CLh6PrSG.js";
2
+ import { t as schemaToTypebox } from "../typebox-fUy-Ywxw.js";
3
+ import { n as version, t as cli } from "../cli-PNyg10lA.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 schemaToValibot } from "../valibot-1p_Y7fu6.js";
3
- import { n as version, t as cli } from "../cli-CLh6PrSG.js";
2
+ import { t as schemaToValibot } from "../valibot-Vj1GeCcx.js";
3
+ import { n as version, t as cli } from "../cli-PNyg10lA.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
- import { t as schemaToYup } from "../yup-IOat93gr.js";
3
- import { n as version, t as cli } from "../cli-CLh6PrSG.js";
2
+ import { t as schemaToYup } from "../yup-DKlaai37.js";
3
+ import { n as version, t as cli } from "../cli-PNyg10lA.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-q9c0XhJO.js";
3
- import { n as version, t as cli } from "../cli-CLh6PrSG.js";
2
+ import { t as schemaToZod } from "../zod-04J51AMt.js";
3
+ import { n as version, t as cli } from "../cli-PNyg10lA.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,4 +1,4 @@
1
- import { Gt as isRecord } from "./helper-1oDB5NHM.js";
1
+ import { Gt as isRecord } from "./helper-OCkRyx4U.js";
2
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";
@@ -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.7";
12
+ var version = "0.8.9";
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) {
@@ -23,11 +23,11 @@ function mkdir(dir) {
23
23
  * Skipping the identical write keeps a no-op generation from changing mtime. An
24
24
  * unreadable existing file falls through to the write rather than failing here.
25
25
  */
26
- function writeFile(path, data) {
26
+ function writeFile(path, content) {
27
27
  return Effect.gen(function* () {
28
28
  const fs = yield* FileSystem.FileSystem;
29
- if ((yield* fs.readFileString(path).pipe(Effect.orElseSucceed(() => null))) === data) return;
30
- yield* fs.writeFileString(path, data);
29
+ if ((yield* fs.readFileString(path).pipe(Effect.orElseSucceed(() => null))) === content) return;
30
+ yield* fs.writeFileString(path, content);
31
31
  });
32
32
  }
33
33
  // src/cli/index.ts
@@ -70,8 +70,8 @@ function platformCause(error) {
70
70
  * `mapError` at the end is where all of it turns into rendered CLI output. The
71
71
  * `FileSystem` it writes through comes from the environment the caller provides.
72
72
  */
73
- function generate(generator) {
74
- return (args) => Effect.gen(function* () {
73
+ function generate(generator, args) {
74
+ return Effect.gen(function* () {
75
75
  const schema = yield* parseSchemaFile(args.input);
76
76
  const source = yield* fmt(generator(schema, {
77
77
  exportType: args.exportType,
@@ -93,7 +93,7 @@ function generate(generator) {
93
93
  * from one definition rather than one copy per target that can drift apart.
94
94
  */
95
95
  function makeCli(options) {
96
- return Command.make(options.name, commandLine, generate(options.generator)).pipe(Command.withDescription(options.description), Command.withExamples([
96
+ return Command.make(options.name, commandLine, (args) => generate(options.generator, args)).pipe(Command.withDescription(options.description), Command.withExamples([
97
97
  {
98
98
  command: `${options.name} schema.json -o src/schema.ts`,
99
99
  description: "Generate a schema file"
@@ -1,4 +1,4 @@
1
- import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, D as stringboolPattern, E as ownProperties, G as renderDefinitions, H as emitOptionsOf, I as deepEqualExpression, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, L as jsLiteral, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, Pt as hasType, Rt as isDefaultOnlyMember, T as numberWirePattern, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, b as impliedWireType, bn as NUMBER_RANGES, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, ht as effectMessage, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, mt as effectErrorPart, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, pt as effectError, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, u as hasParameterSerialization, v as effectPreprocess, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, y as effectWrap, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-1oDB5NHM.js";
1
+ import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, D as stringboolPattern, E as ownProperties, G as renderDefinitions, H as emitOptionsOf, I as deepEqualExpression, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, L as jsLiteral, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, Pt as hasType, Rt as isDefaultOnlyMember, T as numberWirePattern, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, b as impliedWireType, bn as NUMBER_RANGES, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, ht as effectMessage, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, mt as effectErrorPart, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, pt as effectError, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, u as hasParameterSerialization, v as effectPreprocess, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, y as effectWrap, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-OCkRyx4U.js";
2
2
  // src/generator/effect/number.ts
3
3
  /** The bound and `multipleOf` checks of a numeric node. */
4
4
  function numberChecks(schema, lit = (n) => `${n}`, suffix = "") {
@@ -126,7 +126,7 @@ function _enum(schema) {
126
126
  const lit = (v) => literal(v, isBigint);
127
127
  const errorMessage = schema["x-enum-message"] ?? schema["x-error-message"];
128
128
  const annotate = (code) => errorMessage ? `${code}.annotate(${effectError(errorMessage)})` : code;
129
- const tuple = (arr) => `Schema.Tuple([${arr.map((i) => `Schema.Literal(${lit(i)})`).join(",")}])`;
129
+ const tuple = (members) => `Schema.Tuple([${members.map((i) => `Schema.Literal(${lit(i)})`).join(",")}])`;
130
130
  const literals = (values) => {
131
131
  const nonNull = values.filter((v) => v !== null);
132
132
  if (nonNull.length === 0) return "Schema.Null";
@@ -217,7 +217,7 @@ function object(schema, rootName, isEffect, options) {
217
217
  const minPropertiesFilter = typeof schema.minProperties === "number" ? `Schema.makeFilter((input)=>Object.keys(input).length>=${schema.minProperties}${minErrorArg})` : "";
218
218
  const maxPropertiesFilter = typeof schema.maxProperties === "number" ? `Schema.makeFilter((input)=>Object.keys(input).length<=${schema.maxProperties}${maxErrorArg})` : "";
219
219
  const dependentRequiredFilters = schema.dependentRequired ? Object.entries(schema.dependentRequired).map(([key, deps]) => {
220
- return `Schema.makeFilter((input)=>!('${key}' in input)||(${deps.map((d) => `'${d}' in input`).join("&&")})${depReqErrorArg})`;
220
+ return `Schema.makeFilter((input)=>!('${key}' in input)||(${deps.map((dependency) => `'${dependency}' in input`).join("&&")})${depReqErrorArg})`;
221
221
  }) : [];
222
222
  const dependentSchemasFilters = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, subSchema]) => {
223
223
  return `Schema.makeFilter((input)=>!('${key}' in input)||Schema.is(${effect(subSchema, rootName, isEffect, options)})(input)${depSchErrorArg})`;
@@ -514,7 +514,7 @@ function node(schema, rootName, isEffect, options) {
514
514
  ...schema,
515
515
  nullable
516
516
  });
517
- const intersected = schemas.length === 1 ? schemas[0] : intersect(schemas);
517
+ const intersected = schemas.length === 1 && schemas[0] !== void 0 ? schemas[0] : intersect(schemas);
518
518
  const allOfMessage = schema["x-allOf-message"];
519
519
  const baseResult = objectKeysCheck(allOfMessage ? wholeValueMessage(intersected, allOfMessage) : intersected, schema, rootName, isEffect, options);
520
520
  if (defaultValue !== void 0) return `${nullable ? `Schema.NullOr(${baseResult})` : baseResult}.pipe(${isWireCoerced ? "Schema.withDecodingDefaultType" : "Schema.withDecodingDefault"}(Effect.succeed(${jsLiteral(defaultValue)})))`;
@@ -561,33 +561,33 @@ function node(schema, rootName, isEffect, options) {
561
561
  }
562
562
  if (schema.properties) return effectWrap$1(object(schema, rootName, isEffect, options), schema);
563
563
  const types = normalizeTypes(schema.type);
564
- const primitive = (t) => {
565
- if (t === "string") return string(schema);
566
- if (t === "number") return number(schema, { wire: isWireCoerced });
567
- if (t === "integer") return integer(schema, { wire: isWireCoerced });
568
- if (t !== "boolean") return void 0;
564
+ const primitive = (primitiveType) => {
565
+ if (primitiveType === "string") return string(schema);
566
+ if (primitiveType === "number") return number(schema, { wire: isWireCoerced });
567
+ if (primitiveType === "integer") return integer(schema, { wire: isWireCoerced });
568
+ if (primitiveType !== "boolean") return void 0;
569
569
  const errorMessage = schema["x-error-message"];
570
570
  const base = isWireCoerced ? stringbool() : "Schema.Boolean";
571
571
  return errorMessage ? `${base}.annotate(${effectError(errorMessage)})` : base;
572
572
  };
573
573
  if (isPrimitiveUnion(types, isWireCoerced)) return effectWrap$1(`Schema.Union([${unionPrimitiveTypes(types, isWireCoerced).map(primitive).filter((m) => m !== void 0).join(",")}])`, schema);
574
- for (const t of [
574
+ for (const primitiveType of [
575
575
  "string",
576
576
  "number",
577
577
  "integer",
578
578
  "boolean"
579
579
  ]) {
580
- if (!types.includes(t)) continue;
581
- const expression = primitive(t);
580
+ if (!types.includes(primitiveType)) continue;
581
+ const expression = primitive(primitiveType);
582
582
  if (expression !== void 0) return effectWrap$1(expression, schema);
583
583
  }
584
584
  if (types.includes("array")) {
585
585
  const elementMessageWrap = wholeValueMessage;
586
- if (schema.prefixItems?.length) {
586
+ if (schema.prefixItems !== void 0 && schema.prefixItems.length > 0) {
587
587
  const items = schema.prefixItems.map((s) => effect(s, rootName, isEffect, options));
588
- const u = schema.unevaluatedItems;
588
+ const unevaluatedItems = schema.unevaluatedItems;
589
589
  const tuple = `Schema.Tuple([${items.join(",")}])`;
590
- const tupleExpr = isSchemaObject(u) ? `Schema.TupleWithRest(${tuple},[${effect(u, rootName, isEffect, options)}])` : tuple;
590
+ const tupleExpr = isSchemaObject(unevaluatedItems) ? `Schema.TupleWithRest(${tuple},[${effect(unevaluatedItems, rootName, isEffect, options)}])` : tuple;
591
591
  const prefixItemsMessage = schema["x-prefixItems-message"];
592
592
  return effectWrap$1(wireArray(prefixItemsMessage ? elementMessageWrap(tupleExpr, prefixItemsMessage) : tupleExpr), schema);
593
593
  }
@@ -606,9 +606,9 @@ function node(schema, rootName, isEffect, options) {
606
606
  const uniqueItemsMessage = schema["x-uniqueItems-message"];
607
607
  const uniqueArg = effectErrorPart(uniqueItemsMessage);
608
608
  const containsChecks = (() => {
609
- const c = schema.contains;
610
- if (!c) return [];
611
- const containsSchema = effect(c, rootName, isEffect, options);
609
+ const contains = schema.contains;
610
+ if (!contains) return [];
611
+ const containsSchema = effect(contains, rootName, isEffect, options);
612
612
  const minC = schema.minContains;
613
613
  const maxC = schema.maxContains;
614
614
  const errorMessage = schema["x-error-message"];
@@ -675,7 +675,7 @@ function schemaToEffect(input, options) {
675
675
  const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
676
676
  const exportType = options?.exportType ?? true;
677
677
  const baseOptions = emitOptionsOf(options);
678
- const codeExtensionsPresent = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0;
678
+ const codeExtensionsPresent = baseOptions.unsafeCodeExtensions && findCodeExtensionKeysInSchema(schema).length > 0;
679
679
  const toName = schemaNamer(baseOptions.openapi);
680
680
  const pascalTitle = rootNameOf(schema, toName, EFFECT_ROOT_FALLBACK);
681
681
  const plan = planDocument(schema, pascalTitle === "Schema" ? EFFECT_ROOT_FALLBACK : pascalTitle);
package/dist/effect.js CHANGED
@@ -1 +1 @@
1
- export { t as schemaToEffect } from "./effect-CM1XVqvf.js";
1
+ export { t as schemaToEffect } from "./effect-CHLS1Yit.js";