schema-truth 0.8.1 → 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-CRZ8vXZ5.js → arktype-CzTltPwP.js} +94 -55
  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-eAY8LqwP.js → cli-71Np9i5L.js} +6 -9
  16. package/dist/{effect-BkWovUi3.js → effect-Dj8qARFi.js} +70 -44
  17. package/dist/effect.d.ts +3 -5
  18. package/dist/effect.js +1 -1
  19. package/dist/{helper-CbeedY35.js → helper-WSNbEQKr.js} +1398 -52
  20. package/dist/{index-G7UqNQ4w.d.ts → index-DLVjyrKu.d.ts} +0 -14
  21. package/dist/{index-DYzAccyT.d.ts → index-DU2Nd8eI.d.ts} +2 -6
  22. package/dist/index.d.ts +11 -20
  23. package/dist/index.js +10 -10
  24. package/dist/{parser-CyJ2auea.js → parser-RBrkz7ZL.js} +2 -4
  25. package/dist/{typebox-wYeJqy7T.js → typebox-RAJnIZwI.js} +60 -47
  26. package/dist/typebox.d.ts +3 -5
  27. package/dist/typebox.js +1 -1
  28. package/dist/{valibot-DQUEDYKt.js → valibot-CLUhG6tp.js} +66 -45
  29. package/dist/valibot.d.ts +3 -5
  30. package/dist/valibot.js +1 -1
  31. package/dist/{yup-BMpa9Co1.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-Dq9LtqPL.js → zod-BhYAQ3iW.js} +84 -56
  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
@@ -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, M as formatPattern, N as regexSource, O as unionPrimitiveTypes, Q as findCodeExtensionKeysInSchema, S as isNullTextRead, T as ownProperties, U as renderDefinitions, W as rootNameOf, Y as itemsSchemaOf, _ as effectPreprocess, at as regexLiteral, b as integerWirePattern, c as withPolymorphicBases, d as propertyEmitOptions, et as constraintMessage, f as withoutParameterSerialization, g as hoistNestedRefs, h as valueListLiteral, i as isEvaluatedKeyExpression, j as wireNumericKind, k as wireArrayOnce, l as hasParameterSerialization, m as notPredicate, nt as foldAllOfMembers, o as typeDeclaration, p as isBigintFormat, q as hasRootSelfReference, r as evaluatedProperties, rt as isKeywordOnlyMember, s as refTarget, tt as constraintPredicate, u as parameterReaders, v as effectWrap, w as numberWirePattern, y as impliedWireType, z as definitionsOf } from "./helper-CbeedY35.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
  *
@@ -168,14 +172,21 @@ function object(schema, rootName, isEffect, options) {
168
172
  };
169
173
  const patternPropertiesFilters = () => schema.patternProperties ? Object.entries(schema.patternProperties).map(([pattern, propSchema]) => {
170
174
  const s = effect(propSchema, rootName, isEffect, options);
171
- return `Schema.makeFilter((input)=>Object.entries(input).every(([key,value])=>!new RegExp(${JSON.stringify(pattern)}).test(key)||Schema.is(${s})(value))${patternErrorArg})`;
175
+ return `Schema.makeFilter((input)=>Object.entries(input).every(([key,value])=>!new RegExp(${JSON.stringify(pattern)}).test(key)||Schema.is(Schema.toEncoded(${s}))(value))${patternErrorArg})`;
172
176
  }) : [];
173
- if (typeof schema.additionalProperties === "object") {
177
+ if (typeof schema.additionalProperties === "object" && schema.properties === void 0 && schema.patternProperties === void 0) {
174
178
  const record = `Schema.Record(Schema.String,${effect(schema.additionalProperties, rootName, isEffect, options)})`;
175
- const checks = [propertyNamesFilter(), ...patternPropertiesFilters()].filter((a) => a !== "");
179
+ const checks = [propertyNamesFilter()].filter((a) => a !== "");
176
180
  return checks.length > 0 ? `${record}.check(${checks.join(",")})` : record;
177
181
  }
178
- if (!schema.properties) {
182
+ const properties = schema.properties ?? {};
183
+ const undeclaredRequired = (schema.required ?? []).filter((key) => !Object.hasOwn(properties, key));
184
+ const unevaluated = schema.unevaluatedProperties;
185
+ const closed = schema.additionalProperties === false || unevaluated === false;
186
+ const extraSchema = typeof schema.additionalProperties === "object" ? schema.additionalProperties : typeof unevaluated === "object" ? unevaluated : void 0;
187
+ const extraMessage = typeof schema.additionalProperties === "object" ? schema["x-additionalProperties-message"] : schema["x-unevaluatedProperties-message"];
188
+ const checksKeys = undeclaredRequired.length > 0 || extraSchema !== void 0 || closed;
189
+ if (!schema.properties && !checksKeys) {
179
190
  if (schema.patternProperties) {
180
191
  const record = "Schema.Record(Schema.String,Schema.Unknown)";
181
192
  const checks = [propertyNamesFilter(), ...patternPropertiesFilters()].filter((a) => a !== "");
@@ -185,17 +196,17 @@ function object(schema, rootName, isEffect, options) {
185
196
  return "Schema.Struct({})";
186
197
  }
187
198
  const required = new Set(schema.required);
188
- const props = Object.entries(schema.properties).map(([key, propSchema]) => {
199
+ const props = Object.entries(properties).map(([key, propSchema]) => {
189
200
  const parsed = effect(propSchema, rootName, isEffect, propertyEmitOptions(key, propSchema, options) ?? options);
190
201
  if (!parsed) return null;
191
202
  const safeKey = makeSafeKey(key);
192
203
  const isRequired = required.has(key);
193
204
  const hasDecodingDefault = parsed.includes("Schema.withDecodingDefault");
194
- return isRequired || hasDecodingDefault ? `${safeKey}:${parsed}` : `${safeKey}:Schema.optional(${parsed})`;
205
+ return isRequired || hasDecodingDefault ? `${safeKey}:${parsed}` : `${safeKey}:Schema.optionalKey(${parsed})`;
195
206
  }).filter((p) => p !== null);
196
- const conditionalKeysReferenced = hasConditional(schema);
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;
197
208
  const struct = `Schema.Struct({${props.join(",")}})`;
198
- const rawBase = conditionalKeysReferenced ? `Schema.StructWithRest(${struct},[Schema.Record(Schema.String,Schema.Unknown)])` : struct;
209
+ const rawBase = readsUndeclaredKeys ? `Schema.StructWithRest(${struct},[Schema.Record(Schema.String,Schema.Unknown)])` : struct;
199
210
  const propsMessage = schema["x-properties-message"];
200
211
  const partialBase = propsMessage ? wholeValueMessage(rawBase, propsMessage) : rawBase;
201
212
  const minPropertiesFilter = typeof schema.minProperties === "number" ? `Schema.makeFilter((input)=>Object.keys(input).length>=${schema.minProperties}${minErrorArg})` : "";
@@ -206,7 +217,12 @@ function object(schema, rootName, isEffect, options) {
206
217
  const dependentSchemasFilters = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, subSchema]) => {
207
218
  return `Schema.makeFilter((input)=>!('${key}' in input)||Schema.is(${effect(subSchema, rootName, isEffect, options)})(input)${depSchErrorArg})`;
208
219
  }) : [];
209
- const strictExtrasAnnotation = schema.additionalProperties === false || schema.unevaluatedProperties === false ? strictExtrasMessage ? `.annotate({parseOptions:{onExcessProperty:"error"},messageUnexpectedKey:${JSON.stringify(strictExtrasMessage)}})` : `.annotate({parseOptions:{onExcessProperty:"error"}})` : "";
220
+ const requiredPresentFilter = undeclaredRequired.length > 0 ? `Schema.makeFilter((input)=>${JSON.stringify(undeclaredRequired)}.every((key)=>key in input)${errorArg})` : "";
221
+ const isEvaluated = isEvaluatedKeyExpression({
222
+ names: Object.keys(properties),
223
+ patterns: Object.keys(schema.patternProperties ?? {})
224
+ }, "key");
225
+ const unevaluatedKeysFilter = closed ? `Schema.makeFilter((input)=>Object.keys(input).every((key)=>${isEvaluated})${effectErrorPart(strictExtrasMessage ?? errorMessage)})` : extraSchema !== void 0 ? `Schema.makeFilter((input)=>Object.entries(input).every(([key,value])=>${isEvaluated}||Schema.is(Schema.toEncoded(${effect(extraSchema, rootName, isEffect, options)}))(value))${effectErrorPart(extraMessage ?? errorMessage)})` : "";
210
226
  const ifThenElseFilters = (() => {
211
227
  if (!schema.if) return [];
212
228
  const ifSchema = effect(schema.if, rootName, isEffect, options);
@@ -232,16 +248,17 @@ function object(schema, rootName, isEffect, options) {
232
248
  maxPropertiesFilter,
233
249
  propertyNamesFilter(),
234
250
  ...patternPropertiesFilters(),
251
+ requiredPresentFilter,
252
+ unevaluatedKeysFilter,
235
253
  ...dependentRequiredFilters,
236
254
  ...dependentSchemasFilters,
237
255
  ...ifThenElseFilters
238
256
  ].filter((a) => a !== "");
239
- const objectExpr = `${checks.length > 0 ? `${partialBase}.check(${checks.join(",")})` : partialBase}${strictExtrasAnnotation}`;
240
- const hasInheritedName = Object.keys(schema.properties).some(isObjectPrototypeProperty);
257
+ const objectExpr = checks.length > 0 ? `${partialBase}.check(${checks.join(",")})` : partialBase;
258
+ const hasInheritedName = Object.keys(properties).some(isObjectPrototypeProperty);
241
259
  return isStringWireLocation(options?.paramIn) && hasInheritedName ? effectPreprocess([ownProperties("input")], objectExpr) : objectExpr;
242
260
  }
243
- //#endregion
244
- //#region src/generator/effect/string.ts
261
+ // src/generator/effect/string.ts
245
262
  /**
246
263
  * Formats whose Effect Schema v4 equivalent is a check on `Schema.String`.
247
264
  * v3 shipped `Schema.UUID` / `Schema.ULID` schemas; v4 expresses both as
@@ -338,8 +355,7 @@ function string(schema) {
338
355
  const base = stringBase(schema, formatName === void 0 ? void 0 : TRANSFORM_FORMATS[formatName]);
339
356
  return annotate(checks.length > 0 ? `${base}.check(${checks.join(",")})` : base);
340
357
  }
341
- //#endregion
342
- //#region src/generator/effect/effect.ts
358
+ // src/generator/effect/effect.ts
343
359
  /**
344
360
  * The boolean spellings of the wire, read into a boolean as `z.stringbool()` reads them:
345
361
  * `true` / `1` / `yes` / `on` / `y` / `enabled` and their opposites, in any case. v3
@@ -370,7 +386,7 @@ function intersect(schemas) {
370
386
  const [first, ...rest] = schemas;
371
387
  if (first === void 0) return "Schema.Unknown";
372
388
  if (schemas.every(isStructExpr)) return `Schema.Struct({${schemas.map((s) => `...${s}.fields`).join(",")}})`;
373
- if (schemas.some((s) => s.startsWith("Schema.suspend("))) return `(()=>{${schemas.map((s, i) => `const M${i}=${s}`).join(";")};return Schema.Unknown.pipe(Schema.refine((input):input is ${schemas.map((_, i) => `typeof M${i}.Type`).join("&")}=>${schemas.map((_, i) => `Schema.is(Schema.toEncoded(M${i}))(input)`).join("&&")}))})()`;
389
+ if (schemas.some((s) => s.startsWith("Schema.suspend("))) return `(()=>{${schemas.map((s, i) => `const M${i}=${s}`).join(";")};const isAll=(input:unknown):input is ${schemas.map((_, i) => `typeof M${i}.Type`).join("&")}=>${schemas.map((_, i) => `Schema.is(M${i})(input)`).join("&&")};return Schema.Unknown.pipe(Schema.decodeTo(Schema.declare(isAll),{decode:${`SchemaGetter.transformEffect((input)=>Effect.all([${schemas.map((_, i) => `Schema.decodeUnknownEffect(M${i})(input)`).join(",")}]).pipe(Effect.mapError((error)=>error.issue),Effect.flatMap((values)=>{const merged=values.every((value)=>typeof value==='object'&&value!==null&&!Array.isArray(value))?Object.assign({},...values):values[0];return isAll(merged)?Effect.succeed(merged):Effect.fail(new SchemaIssue.InvalidValue(undefined,merged))})))`},encode:SchemaGetter.passthrough({strict:false})}))})()`;
374
390
  return `${first}.check(${rest.map((s) => `Schema.makeFilter((input)=>Schema.is(${s})(input))`).join(",")})`;
375
391
  }
376
392
  /**
@@ -387,16 +403,20 @@ function wholeValueMessage(inner, message) {
387
403
  return `Schema.Unknown.check(Schema.makeFilter((input)=>Schema.is(${inner})(input),${effectError(message)})).pipe(Schema.decodeTo(${inner}))`;
388
404
  }
389
405
  /**
390
- * An `allOf` with `unevaluatedProperties` beside it: the members' structs strip what they
391
- * do not declare, so the keys no member evaluates are checked on the input before it is
392
- * decoded. `inner` as given when the keyword is absent or every key is evaluated.
406
+ * An `allOf` with `patternProperties` or `unevaluatedProperties` beside it: the members'
407
+ * structs strip what they do not declare, so the keys are checked on the input before it is
408
+ * decoded — a key a pattern matches against that pattern's schema, a key no member
409
+ * evaluates against `unevaluatedProperties`. `inner` as given when there is nothing to check.
393
410
  */
394
- function unevaluatedPropertiesCheck(inner, schema, rootName, isEffect, options) {
411
+ function objectKeysCheck(inner, schema, rootName, isEffect, options) {
412
+ const patterns = Object.entries(schema.patternProperties ?? {});
395
413
  const unevaluated = schema.unevaluatedProperties;
396
- if (unevaluated !== false && (typeof unevaluated !== "object" || unevaluated === null)) return inner;
397
- const evaluated = evaluatedProperties(schema, options?.definitions);
398
- if (evaluated === void 0) return inner;
399
- return `Schema.Unknown.check(Schema.makeFilter(${`(input)=>typeof input!=='object'||input===null||Array.isArray(input)||Object.entries(input).every(([k,v])=>${isEvaluatedKeyExpression(evaluated, "k")}||${unevaluated === false ? "false" : `Schema.is(${effect(unevaluated, rootName, isEffect, options)})(v)`})`}${effectErrorPart(schema["x-unevaluatedProperties-message"])})).pipe(Schema.decodeTo(${inner}))`;
414
+ const unevaluatedSchema = typeof unevaluated === "object" ? unevaluated : void 0;
415
+ const evaluated = unevaluated === false || unevaluatedSchema !== void 0 ? evaluatedProperties(schema, options?.definitions) : void 0;
416
+ const accepts = (s) => `Schema.is(Schema.toEncoded(${effect(s, rootName, isEffect, options)}))(v)`;
417
+ const filters = [...patterns.map(([pattern, propSchema]) => `Schema.makeFilter((input)=>typeof input!=='object'||input===null||Array.isArray(input)||Object.entries(input).every(([k,v])=>!new RegExp(${JSON.stringify(pattern)}).test(k)||${accepts(propSchema)})${effectErrorPart(schema["x-patternProperties-message"])})`), ...evaluated === void 0 ? [] : [`Schema.makeFilter((input)=>typeof input!=='object'||input===null||Array.isArray(input)||Object.entries(input).every(([k,v])=>${isEvaluatedKeyExpression(evaluated, "k")}||${unevaluatedSchema === void 0 ? "false" : accepts(unevaluatedSchema)})${effectErrorPart(schema["x-unevaluatedProperties-message"])})`]];
418
+ if (filters.length === 0) return inner;
419
+ return `Schema.Unknown.check(${filters.join(",")}).pipe(Schema.decodeTo(${inner}))`;
400
420
  }
401
421
  /**
402
422
  * Generate Effect Schema code from a JSON Schema.
@@ -460,7 +480,14 @@ function node(schema, rootName, isEffect, options) {
460
480
  }, rootName, isEffect, options);
461
481
  if (schema.oneOf) {
462
482
  if (schema.oneOf.length === 0) return effectWrap$1("Schema.Unknown", schema);
463
- const schemas = schema.oneOf.map((s) => effect(s, rootName, isEffect, options));
483
+ const discriminated = discriminatedMembers(schema, schema.oneOf);
484
+ const schemas = schema.oneOf.map((s, i) => {
485
+ const member = effect(s, rootName, isEffect, options);
486
+ const values = discriminated?.members[i]?.values;
487
+ if (discriminated === void 0 || values === void 0) return member;
488
+ const literal = values.length === 1 ? `Schema.Literal(${JSON.stringify(values[0])})` : `Schema.Literals(${JSON.stringify(values)})`;
489
+ return intersect([member, `Schema.Struct({${makeSafeKey(discriminated.propertyName)}:${literal}})`]);
490
+ });
464
491
  const oneOfMessage = schema["x-oneOf-message"];
465
492
  const expr = `Schema.Union([${schemas.join(",")}])`;
466
493
  return effectWrap$1(oneOfMessage ? `${expr}.annotate(${effectError(oneOfMessage)})` : expr, schema);
@@ -483,7 +510,7 @@ function node(schema, rootName, isEffect, options) {
483
510
  });
484
511
  const intersected = schemas.length === 1 ? schemas[0] : intersect(schemas);
485
512
  const allOfMessage = schema["x-allOf-message"];
486
- const baseResult = unevaluatedPropertiesCheck(allOfMessage ? wholeValueMessage(intersected, allOfMessage) : intersected, schema, rootName, isEffect, options);
513
+ const baseResult = objectKeysCheck(allOfMessage ? wholeValueMessage(intersected, allOfMessage) : intersected, schema, rootName, isEffect, options);
487
514
  if (defaultValue !== void 0) return `${nullable ? `Schema.NullOr(${baseResult})` : baseResult}.pipe(${isWireCoerced ? "Schema.withDecodingDefaultType" : "Schema.withDecodingDefault"}(Effect.succeed(${jsLiteral(defaultValue)})))`;
488
515
  return effectWrap$1(baseResult, {
489
516
  ...schema,
@@ -510,7 +537,7 @@ function node(schema, rootName, isEffect, options) {
510
537
  }
511
538
  if (schema.const !== void 0) {
512
539
  const constMessage = schema["x-const-message"] ?? schema["x-error-message"];
513
- 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)})`;
514
541
  const withMessage = constMessage ? `${literalCode}.annotate(${effectError(constMessage)})` : literalCode;
515
542
  const input = literalInput([schema.const]);
516
543
  return effectWrap$1(input ? `${input}.pipe(Schema.decodeTo(${withMessage}))` : withMessage, schema);
@@ -617,8 +644,7 @@ function node(schema, rootName, isEffect, options) {
617
644
  if (typeof schema.additionalProperties === "object") return effectWrap$1(object(schema, rootName, isEffect, options), schema);
618
645
  return effectWrap$1("Schema.Unknown", schema);
619
646
  }
620
- //#endregion
621
- //#region src/generator/effect/type.ts
647
+ // src/generator/effect/type.ts
622
648
  /**
623
649
  * The TypeScript type declared beside a recursive Effect schema: its decoded `Type`, whose
624
650
  * arrays and properties are `readonly` as `Schema.Struct` and `Schema.Array` decode them.
@@ -629,8 +655,7 @@ function type(schema, rootName = DEFAULT_ROOT_NAME) {
629
655
  readonly: true
630
656
  }, rootName);
631
657
  }
632
- //#endregion
633
- //#region src/generator/effect/index.ts
658
+ // src/generator/effect/index.ts
634
659
  /** The root name when the document has none, or when its title would shadow the import. */
635
660
  const EFFECT_ROOT_FALLBACK = `${DEFAULT_ROOT_NAME}_`;
636
661
  /**
@@ -641,7 +666,7 @@ const EFFECT_ROOT_FALLBACK = `${DEFAULT_ROOT_NAME}_`;
641
666
  * `Schema.Array` are already readonly at the type level.
642
667
  */
643
668
  function schemaToEffect(input, options) {
644
- const schema = withPolymorphicBases(hoistNestedRefs(input));
669
+ const schema = withPolymorphicBases(hoistNestedRefs(sanitizeSchema(input)));
645
670
  const exportType = options?.exportType ?? true;
646
671
  const baseOptions = emitOptionsOf(options);
647
672
  const codeExtensionsPresent = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0;
@@ -661,8 +686,10 @@ function schemaToEffect(input, options) {
661
686
  const rootExport = needsTypeDef ? `export const ${rootName}: Schema.Schema<_${rootName}> = ${rootSchema}` : `export const ${rootName} = ${rootSchema}`;
662
687
  const emitted = `${schemaDefsCode}\n${rootExport}`;
663
688
  const importLine = `import { ${[
664
- ...emitted.includes("Effect.succeed(") ? ["Effect"] : [],
689
+ .../(?<![\w.])Effect\./u.test(emitted) ? ["Effect"] : [],
665
690
  "Schema",
691
+ ...emitted.includes("SchemaGetter.") ? ["SchemaGetter"] : [],
692
+ ...emitted.includes("SchemaIssue.") ? ["SchemaIssue"] : [],
666
693
  ...emitted.includes("SchemaTransformation.") ? ["SchemaTransformation"] : []
667
694
  ].join(", ")} } from "effect"`;
668
695
  return [
@@ -674,5 +701,4 @@ function schemaToEffect(input, options) {
674
701
  ...exportType ? [`export type ${rootName} = typeof ${rootName}.Type`] : []
675
702
  ].filter(Boolean).join("\n\n");
676
703
  }
677
- //#endregion
678
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-DYzAccyT.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-DYzAccyT.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-BkWovUi3.js";
1
+ export { t as schemaToEffect } from "./effect-Dj8qARFi.js";