schema-truth 0.7.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ajv-DTP2FXRr.js → ajv-DS9gtNZC.js} +1 -1
- package/dist/ajv.d.ts +1 -1
- package/dist/ajv.js +1 -1
- package/dist/{arktype-BdvvaBQX.js → arktype-CBV4bg-0.js} +179 -75
- package/dist/arktype.d.ts +3 -3
- package/dist/arktype.js +1 -1
- package/dist/cli/ajv.js +2 -2
- package/dist/cli/arktype.js +2 -2
- package/dist/cli/effect.js +2 -2
- package/dist/cli/typebox.js +2 -2
- package/dist/cli/valibot.js +2 -2
- package/dist/cli/yup.js +2 -2
- package/dist/cli/zod.js +2 -2
- package/dist/{cli-CL2mSark.js → cli-CB9GJ7qa.js} +2 -2
- package/dist/{effect-mUknRPv_.js → effect-D9pvwi_6.js} +91 -31
- package/dist/effect.d.ts +3 -3
- package/dist/effect.js +1 -1
- package/dist/{helper-Cfvb5UDq.js → helper-S7SSsYwh.js} +777 -40
- package/dist/{index-C2L8Ty0-.d.ts → index-EK43HM_z.d.ts} +29 -25
- package/dist/{index-DbV3dEmN.d.ts → index-G7UqNQ4w.d.ts} +54 -2
- package/dist/index.d.ts +63 -25
- package/dist/index.js +9 -9
- package/dist/{typebox-BdWJv3ND.js → typebox-DGGKJLdP.js} +82 -42
- package/dist/typebox.d.ts +3 -3
- package/dist/typebox.js +1 -1
- package/dist/{utils-WNBq1HR0.js → utils-Bky98UmP.js} +160 -31
- package/dist/{valibot-CaJIynCH.js → valibot-B6y4VQFF.js} +107 -36
- package/dist/valibot.d.ts +3 -3
- package/dist/valibot.js +1 -1
- package/dist/{yup-CM2TSFig.js → yup-DuqQwHUv.js} +2 -2
- package/dist/yup.d.ts +2 -2
- package/dist/yup.js +1 -1
- package/dist/{zod-BsXLZfwK.js → zod-CXo9NFuF.js} +192 -115
- package/dist/zod.d.ts +3 -3
- package/dist/zod.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as isSchemaObject, H as isStringWireLocation, M as isNullable, N as isObjectPrototypeProperty,
|
|
2
|
-
import {
|
|
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
3
|
//#region src/generator/effect/number.ts
|
|
4
4
|
/** The bound and `multipleOf` checks of a numeric node. */
|
|
5
5
|
function numberChecks(schema, lit = (n) => `${n}`, suffix = "") {
|
|
@@ -32,14 +32,21 @@ function rangeCheck(format, suffix = "") {
|
|
|
32
32
|
return [`Schema.isBetween${suffix}({minimum:${range.minimum},maximum:${range.maximum}})`];
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
* `Schema.FiniteFromString`, which
|
|
37
|
-
|
|
35
|
+
* Wire text checked against the integer or JSON number grammar, then decoded to a finite
|
|
36
|
+
* number. `Schema.FiniteFromString` uses `Number`, which accepts `""`, `" "` and `"0x10"`.
|
|
37
|
+
*/
|
|
38
|
+
function wireNumericInput(kind) {
|
|
39
|
+
return `Schema.String.check(Schema.isPattern(${kind === "integer" ? integerWirePattern() : numberWirePattern()})).pipe(Schema.decodeTo(Schema.Finite,SchemaTransformation.transform({decode:(input)=>Number(input),encode:(output)=>String(output)})))`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The Effect schema of a number node. On the string wire the text has to match the JSON
|
|
43
|
+
* number grammar before it is decoded to a finite number; `float` / `float32` carries
|
|
44
|
+
* its range.
|
|
38
45
|
*/
|
|
39
46
|
function number(schema, options) {
|
|
40
47
|
const errorMessage = schema["x-error-message"] ?? schema["x-required-message"];
|
|
41
48
|
const checks = [...rangeCheck(schema.format === "float" || schema.format === "float32" ? "float32" : void 0), ...numberChecks(schema)];
|
|
42
|
-
const input = options?.wire === true ? "
|
|
49
|
+
const input = options?.wire === true ? wireNumericInput("number") : "Schema.Number";
|
|
43
50
|
const base = checks.length > 0 ? `${input}.check(${checks.join(",")})` : input;
|
|
44
51
|
return errorMessage ? `${base}.annotate(${effectError(errorMessage)})` : base;
|
|
45
52
|
}
|
|
@@ -68,7 +75,7 @@ function int64Range(format) {
|
|
|
68
75
|
/**
|
|
69
76
|
* The Effect schema of an integer node. `int64` / `uint64` are bigints wherever they come
|
|
70
77
|
* from, `bigint` is one too, `int32` / `uint32` are their own filters, and on the string
|
|
71
|
-
* wire the text is
|
|
78
|
+
* wire the text has to match the integer grammar before it is decoded to a finite number.
|
|
72
79
|
*/
|
|
73
80
|
function integer(schema, options) {
|
|
74
81
|
const isWire = options?.wire === true;
|
|
@@ -81,7 +88,7 @@ function integer(schema, options) {
|
|
|
81
88
|
return annotate(checks.length > 0 ? `${input}.check(${checks.join(",")})` : input);
|
|
82
89
|
}
|
|
83
90
|
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)];
|
|
84
|
-
return `${isWire ? "
|
|
91
|
+
return `${isWire ? wireNumericInput("integer") : "Schema.Number"}.check(${checks.join(",")})`;
|
|
85
92
|
}
|
|
86
93
|
//#endregion
|
|
87
94
|
//#region src/generator/effect/enum.ts
|
|
@@ -161,14 +168,21 @@ function object(schema, rootName, isEffect, options) {
|
|
|
161
168
|
};
|
|
162
169
|
const patternPropertiesFilters = () => schema.patternProperties ? Object.entries(schema.patternProperties).map(([pattern, propSchema]) => {
|
|
163
170
|
const s = effect(propSchema, rootName, isEffect, options);
|
|
164
|
-
return `Schema.makeFilter((input)=>Object.entries(input).every(([key,value])=>!new RegExp(${JSON.stringify(pattern)}).test(key)||Schema.is(${s})(value))${patternErrorArg})`;
|
|
171
|
+
return `Schema.makeFilter((input)=>Object.entries(input).every(([key,value])=>!new RegExp(${JSON.stringify(pattern)}).test(key)||Schema.is(Schema.toEncoded(${s}))(value))${patternErrorArg})`;
|
|
165
172
|
}) : [];
|
|
166
|
-
if (typeof schema.additionalProperties === "object") {
|
|
173
|
+
if (typeof schema.additionalProperties === "object" && schema.properties === void 0 && schema.patternProperties === void 0) {
|
|
167
174
|
const record = `Schema.Record(Schema.String,${effect(schema.additionalProperties, rootName, isEffect, options)})`;
|
|
168
|
-
const checks = [propertyNamesFilter()
|
|
175
|
+
const checks = [propertyNamesFilter()].filter((a) => a !== "");
|
|
169
176
|
return checks.length > 0 ? `${record}.check(${checks.join(",")})` : record;
|
|
170
177
|
}
|
|
171
|
-
|
|
178
|
+
const properties = schema.properties ?? {};
|
|
179
|
+
const undeclaredRequired = (schema.required ?? []).filter((key) => !Object.hasOwn(properties, key));
|
|
180
|
+
const unevaluated = schema.unevaluatedProperties;
|
|
181
|
+
const closed = schema.additionalProperties === false || unevaluated === false;
|
|
182
|
+
const extraSchema = typeof schema.additionalProperties === "object" ? schema.additionalProperties : typeof unevaluated === "object" ? unevaluated : void 0;
|
|
183
|
+
const extraMessage = typeof schema.additionalProperties === "object" ? schema["x-additionalProperties-message"] : schema["x-unevaluatedProperties-message"];
|
|
184
|
+
const checksKeys = undeclaredRequired.length > 0 || extraSchema !== void 0 || closed;
|
|
185
|
+
if (!schema.properties && !checksKeys) {
|
|
172
186
|
if (schema.patternProperties) {
|
|
173
187
|
const record = "Schema.Record(Schema.String,Schema.Unknown)";
|
|
174
188
|
const checks = [propertyNamesFilter(), ...patternPropertiesFilters()].filter((a) => a !== "");
|
|
@@ -178,17 +192,17 @@ function object(schema, rootName, isEffect, options) {
|
|
|
178
192
|
return "Schema.Struct({})";
|
|
179
193
|
}
|
|
180
194
|
const required = new Set(schema.required);
|
|
181
|
-
const props = Object.entries(
|
|
182
|
-
const parsed = effect(propSchema, rootName, isEffect, options);
|
|
195
|
+
const props = Object.entries(properties).map(([key, propSchema]) => {
|
|
196
|
+
const parsed = effect(propSchema, rootName, isEffect, propertyEmitOptions(key, propSchema, options) ?? options);
|
|
183
197
|
if (!parsed) return null;
|
|
184
198
|
const safeKey = makeSafeKey(key);
|
|
185
199
|
const isRequired = required.has(key);
|
|
186
200
|
const hasDecodingDefault = parsed.includes("Schema.withDecodingDefault");
|
|
187
201
|
return isRequired || hasDecodingDefault ? `${safeKey}:${parsed}` : `${safeKey}:Schema.optional(${parsed})`;
|
|
188
202
|
}).filter((p) => p !== null);
|
|
189
|
-
const
|
|
203
|
+
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;
|
|
190
204
|
const struct = `Schema.Struct({${props.join(",")}})`;
|
|
191
|
-
const rawBase =
|
|
205
|
+
const rawBase = readsUndeclaredKeys ? `Schema.StructWithRest(${struct},[Schema.Record(Schema.String,Schema.Unknown)])` : struct;
|
|
192
206
|
const propsMessage = schema["x-properties-message"];
|
|
193
207
|
const partialBase = propsMessage ? wholeValueMessage(rawBase, propsMessage) : rawBase;
|
|
194
208
|
const minPropertiesFilter = typeof schema.minProperties === "number" ? `Schema.makeFilter((input)=>Object.keys(input).length>=${schema.minProperties}${minErrorArg})` : "";
|
|
@@ -199,7 +213,12 @@ function object(schema, rootName, isEffect, options) {
|
|
|
199
213
|
const dependentSchemasFilters = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, subSchema]) => {
|
|
200
214
|
return `Schema.makeFilter((input)=>!('${key}' in input)||Schema.is(${effect(subSchema, rootName, isEffect, options)})(input)${depSchErrorArg})`;
|
|
201
215
|
}) : [];
|
|
202
|
-
const
|
|
216
|
+
const requiredPresentFilter = undeclaredRequired.length > 0 ? `Schema.makeFilter((input)=>${JSON.stringify(undeclaredRequired)}.every((key)=>key in input)${errorArg})` : "";
|
|
217
|
+
const isEvaluated = isEvaluatedKeyExpression({
|
|
218
|
+
names: Object.keys(properties),
|
|
219
|
+
patterns: Object.keys(schema.patternProperties ?? {})
|
|
220
|
+
}, "key");
|
|
221
|
+
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)})` : "";
|
|
203
222
|
const ifThenElseFilters = (() => {
|
|
204
223
|
if (!schema.if) return [];
|
|
205
224
|
const ifSchema = effect(schema.if, rootName, isEffect, options);
|
|
@@ -225,12 +244,14 @@ function object(schema, rootName, isEffect, options) {
|
|
|
225
244
|
maxPropertiesFilter,
|
|
226
245
|
propertyNamesFilter(),
|
|
227
246
|
...patternPropertiesFilters(),
|
|
247
|
+
requiredPresentFilter,
|
|
248
|
+
unevaluatedKeysFilter,
|
|
228
249
|
...dependentRequiredFilters,
|
|
229
250
|
...dependentSchemasFilters,
|
|
230
251
|
...ifThenElseFilters
|
|
231
252
|
].filter((a) => a !== "");
|
|
232
|
-
const objectExpr =
|
|
233
|
-
const hasInheritedName = Object.keys(
|
|
253
|
+
const objectExpr = checks.length > 0 ? `${partialBase}.check(${checks.join(",")})` : partialBase;
|
|
254
|
+
const hasInheritedName = Object.keys(properties).some(isObjectPrototypeProperty);
|
|
234
255
|
return isStringWireLocation(options?.paramIn) && hasInheritedName ? effectPreprocess([ownProperties("input")], objectExpr) : objectExpr;
|
|
235
256
|
}
|
|
236
257
|
//#endregion
|
|
@@ -363,6 +384,7 @@ function intersect(schemas) {
|
|
|
363
384
|
const [first, ...rest] = schemas;
|
|
364
385
|
if (first === void 0) return "Schema.Unknown";
|
|
365
386
|
if (schemas.every(isStructExpr)) return `Schema.Struct({${schemas.map((s) => `...${s}.fields`).join(",")}})`;
|
|
387
|
+
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})}))})()`;
|
|
366
388
|
return `${first}.check(${rest.map((s) => `Schema.makeFilter((input)=>Schema.is(${s})(input))`).join(",")})`;
|
|
367
389
|
}
|
|
368
390
|
/**
|
|
@@ -379,6 +401,22 @@ function wholeValueMessage(inner, message) {
|
|
|
379
401
|
return `Schema.Unknown.check(Schema.makeFilter((input)=>Schema.is(${inner})(input),${effectError(message)})).pipe(Schema.decodeTo(${inner}))`;
|
|
380
402
|
}
|
|
381
403
|
/**
|
|
404
|
+
* An `allOf` with `patternProperties` or `unevaluatedProperties` beside it: the members'
|
|
405
|
+
* structs strip what they do not declare, so the keys are checked on the input before it is
|
|
406
|
+
* decoded — a key a pattern matches against that pattern's schema, a key no member
|
|
407
|
+
* evaluates against `unevaluatedProperties`. `inner` as given when there is nothing to check.
|
|
408
|
+
*/
|
|
409
|
+
function objectKeysCheck(inner, schema, rootName, isEffect, options) {
|
|
410
|
+
const patterns = Object.entries(schema.patternProperties ?? {});
|
|
411
|
+
const unevaluated = schema.unevaluatedProperties;
|
|
412
|
+
const unevaluatedSchema = typeof unevaluated === "object" ? unevaluated : void 0;
|
|
413
|
+
const evaluated = unevaluated === false || unevaluatedSchema !== void 0 ? evaluatedProperties(schema, options?.definitions) : void 0;
|
|
414
|
+
const accepts = (s) => `Schema.is(Schema.toEncoded(${effect(s, rootName, isEffect, options)}))(v)`;
|
|
415
|
+
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"])})`]];
|
|
416
|
+
if (filters.length === 0) return inner;
|
|
417
|
+
return `Schema.Unknown.check(${filters.join(",")}).pipe(Schema.decodeTo(${inner}))`;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
382
420
|
* Generate Effect Schema code from a JSON Schema.
|
|
383
421
|
*
|
|
384
422
|
* The `options.readonly` flag is accepted for API symmetry with the other
|
|
@@ -394,6 +432,10 @@ function effect(schema, rootName = DEFAULT_ROOT_NAME, isEffect = false, options)
|
|
|
394
432
|
}
|
|
395
433
|
return node(schema, rootName, isEffect, options);
|
|
396
434
|
}
|
|
435
|
+
/** A keyword-only `allOf` member: the keywords apply when the value has their type. */
|
|
436
|
+
function keywordConstraint(schema) {
|
|
437
|
+
return `Schema.Unknown.check(Schema.makeFilter((input) => ${constraintPredicate(schema, "input")}${effectErrorPart(constraintMessage(schema))}))`;
|
|
438
|
+
}
|
|
397
439
|
function node(schema, rootName, isEffect, options) {
|
|
398
440
|
const isStringWireParam = isStringWireLocation(options?.paramIn);
|
|
399
441
|
const isWireCoerced = isStringWireParam && schema["x-coerce"] !== false;
|
|
@@ -407,13 +449,14 @@ function node(schema, rootName, isEffect, options) {
|
|
|
407
449
|
};
|
|
408
450
|
const effectWrap$1 = (effectStr, s) => effectWrap(effectStr, s, {
|
|
409
451
|
...codeExtOpts,
|
|
410
|
-
...wireOptions(s)
|
|
452
|
+
...wireOptions(s),
|
|
453
|
+
...options?.definitions !== void 0 && { definitions: options.definitions }
|
|
411
454
|
});
|
|
412
455
|
const wireArray = (v) => isStringWireParam ? effectPreprocess([wireArrayOnce("input")], v) : v;
|
|
413
456
|
const literalInput = (values) => {
|
|
414
457
|
if (values.every((v) => typeof v === "number")) {
|
|
415
458
|
if (isInt64(schema)) return int64Input(isWireCoerced);
|
|
416
|
-
if (isWireCoerced) return
|
|
459
|
+
if (isWireCoerced) return wireNumericInput(wireNumericKind(schema, values));
|
|
417
460
|
}
|
|
418
461
|
if (isWireCoerced && values.every((v) => typeof v === "boolean")) return stringbool();
|
|
419
462
|
};
|
|
@@ -435,7 +478,14 @@ function node(schema, rootName, isEffect, options) {
|
|
|
435
478
|
}, rootName, isEffect, options);
|
|
436
479
|
if (schema.oneOf) {
|
|
437
480
|
if (schema.oneOf.length === 0) return effectWrap$1("Schema.Unknown", schema);
|
|
438
|
-
const
|
|
481
|
+
const discriminated = discriminatedMembers(schema, schema.oneOf);
|
|
482
|
+
const schemas = schema.oneOf.map((s, i) => {
|
|
483
|
+
const member = effect(s, rootName, isEffect, options);
|
|
484
|
+
const values = discriminated?.members[i]?.values;
|
|
485
|
+
if (discriminated === void 0 || values === void 0) return member;
|
|
486
|
+
const literal = values.length === 1 ? `Schema.Literal(${JSON.stringify(values[0])})` : `Schema.Literals(${JSON.stringify(values)})`;
|
|
487
|
+
return intersect([member, `Schema.Struct({${makeSafeKey(discriminated.propertyName)}:${literal}})`]);
|
|
488
|
+
});
|
|
439
489
|
const oneOfMessage = schema["x-oneOf-message"];
|
|
440
490
|
const expr = `Schema.Union([${schemas.join(",")}])`;
|
|
441
491
|
return effectWrap$1(oneOfMessage ? `${expr}.annotate(${effectError(oneOfMessage)})` : expr, schema);
|
|
@@ -451,14 +501,14 @@ function node(schema, rootName, isEffect, options) {
|
|
|
451
501
|
if (schema.allOf.length === 0) return effectWrap$1("Schema.Unknown", schema);
|
|
452
502
|
const nullable = isNullable(schema) || schema.allOf.some(isNullTypeMember);
|
|
453
503
|
const defaultValue = schema.allOf.find(isDefaultOnlyMember)?.default;
|
|
454
|
-
const schemas = schema.allOf.filter((s) => !isShapelessMember(s)).map((s) => effect(s, rootName, isEffect, options));
|
|
504
|
+
const schemas = foldAllOfMembers(schema.allOf.filter((s) => !isShapelessMember(s)), isWireCoerced).map((s) => isKeywordOnlyMember(s) ? keywordConstraint(s) : effect(s, rootName, isEffect, options));
|
|
455
505
|
if (schemas.length === 0) return effectWrap$1("Schema.Unknown", {
|
|
456
506
|
...schema,
|
|
457
507
|
nullable
|
|
458
508
|
});
|
|
459
509
|
const intersected = schemas.length === 1 ? schemas[0] : intersect(schemas);
|
|
460
510
|
const allOfMessage = schema["x-allOf-message"];
|
|
461
|
-
const baseResult = allOfMessage ? wholeValueMessage(intersected, allOfMessage) : intersected;
|
|
511
|
+
const baseResult = objectKeysCheck(allOfMessage ? wholeValueMessage(intersected, allOfMessage) : intersected, schema, rootName, isEffect, options);
|
|
462
512
|
if (defaultValue !== void 0) return `${nullable ? `Schema.NullOr(${baseResult})` : baseResult}.pipe(${isWireCoerced ? "Schema.withDecodingDefaultType" : "Schema.withDecodingDefault"}(Effect.succeed(${jsLiteral(defaultValue)})))`;
|
|
463
513
|
return effectWrap$1(baseResult, {
|
|
464
514
|
...schema,
|
|
@@ -471,9 +521,10 @@ function node(schema, rootName, isEffect, options) {
|
|
|
471
521
|
const notMessage = schema["x-not-message"];
|
|
472
522
|
const filterOpts = effectErrorPart(notMessage);
|
|
473
523
|
const predicate = (() => {
|
|
474
|
-
const
|
|
524
|
+
const bigint = isBigintFormat(withoutNot);
|
|
525
|
+
const shared = notPredicate(inner, "input", "input", bigint);
|
|
475
526
|
if (shared !== void 0) return shared;
|
|
476
|
-
if (Array.isArray(inner.enum)) return `(input) => !${
|
|
527
|
+
if (Array.isArray(inner.enum)) return `(input) => !${valueListLiteral(inner.enum, bigint)}.some((item) => item === input)`;
|
|
477
528
|
})();
|
|
478
529
|
if (withoutNot.type !== void 0) {
|
|
479
530
|
const base = effect(withoutNot, rootName, isEffect, options);
|
|
@@ -588,6 +639,7 @@ function node(schema, rootName, isEffect, options) {
|
|
|
588
639
|
return effectWrap$1("Schema.Date", schema);
|
|
589
640
|
}
|
|
590
641
|
if (types.length === 1 && types[0] === "null") return effectWrap$1("Schema.Null", schema);
|
|
642
|
+
if (typeof schema.additionalProperties === "object") return effectWrap$1(object(schema, rootName, isEffect, options), schema);
|
|
591
643
|
return effectWrap$1("Schema.Unknown", schema);
|
|
592
644
|
}
|
|
593
645
|
//#endregion
|
|
@@ -613,13 +665,19 @@ const EFFECT_ROOT_FALLBACK = `${DEFAULT_ROOT_NAME}_`;
|
|
|
613
665
|
* `options.readonly` is accepted for API symmetry and is a no-op: `Schema.Struct` and
|
|
614
666
|
* `Schema.Array` are already readonly at the type level.
|
|
615
667
|
*/
|
|
616
|
-
function schemaToEffect(
|
|
668
|
+
function schemaToEffect(input, options) {
|
|
669
|
+
const schema = withPolymorphicBases(hoistNestedRefs(input));
|
|
617
670
|
const exportType = options?.exportType ?? true;
|
|
618
|
-
const
|
|
619
|
-
const codeExtensionsPresent =
|
|
620
|
-
const toName = schemaNamer(
|
|
671
|
+
const baseOptions = emitOptionsOf(options);
|
|
672
|
+
const codeExtensionsPresent = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0;
|
|
673
|
+
const toName = schemaNamer(baseOptions.openapi);
|
|
621
674
|
const pascalTitle = rootNameOf(schema, toName, EFFECT_ROOT_FALLBACK);
|
|
622
675
|
const plan = planDocument(schema, pascalTitle === "Schema" ? EFFECT_ROOT_FALLBACK : pascalTitle);
|
|
676
|
+
const definitions = definitionsOf(baseOptions, plan.definitions);
|
|
677
|
+
const emitOptions = definitions === void 0 ? baseOptions : {
|
|
678
|
+
...baseOptions,
|
|
679
|
+
definitions
|
|
680
|
+
};
|
|
623
681
|
const { rootName } = plan;
|
|
624
682
|
const needsTypeDef = plan.hasDefinitions || hasRootSelfReference(schema);
|
|
625
683
|
const typeDefsCode = needsTypeDef ? [`type _${rootName} = ${type(plan.root, rootName)}`, renderDefinitions(plan, toName, (def, name) => `type _${name} = ${type(def, name)}`)].filter(Boolean).join("\n\n") : "";
|
|
@@ -628,8 +686,10 @@ function schemaToEffect(schema, options) {
|
|
|
628
686
|
const rootExport = needsTypeDef ? `export const ${rootName}: Schema.Schema<_${rootName}> = ${rootSchema}` : `export const ${rootName} = ${rootSchema}`;
|
|
629
687
|
const emitted = `${schemaDefsCode}\n${rootExport}`;
|
|
630
688
|
const importLine = `import { ${[
|
|
631
|
-
|
|
689
|
+
.../(?<![\w.])Effect\./u.test(emitted) ? ["Effect"] : [],
|
|
632
690
|
"Schema",
|
|
691
|
+
...emitted.includes("SchemaGetter.") ? ["SchemaGetter"] : [],
|
|
692
|
+
...emitted.includes("SchemaIssue.") ? ["SchemaIssue"] : [],
|
|
633
693
|
...emitted.includes("SchemaTransformation.") ? ["SchemaTransformation"] : []
|
|
634
694
|
].join(", ")} } from "effect"`;
|
|
635
695
|
return [
|
package/dist/effect.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as JSONSchema } from "./index-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
1
|
+
import { r as JSONSchema } from "./index-G7UqNQ4w.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-EK43HM_z.js";
|
|
3
3
|
//#region src/generator/effect/index.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* A whole JSON Schema document as an Effect Schema module: imports, `$defs` in
|
|
@@ -8,5 +8,5 @@ import { n as GenerateOptions } from "./index-C2L8Ty0-.js";
|
|
|
8
8
|
* `options.readonly` is accepted for API symmetry and is a no-op: `Schema.Struct` and
|
|
9
9
|
* `Schema.Array` are already readonly at the type level.
|
|
10
10
|
*/
|
|
11
|
-
export declare function schemaToEffect(
|
|
11
|
+
export declare function schemaToEffect(input: JSONSchema, options?: GenerateOptions): string;
|
|
12
12
|
//#endregion
|
package/dist/effect.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToEffect } from "./effect-
|
|
1
|
+
export { t as schemaToEffect } from "./effect-D9pvwi_6.js";
|