schema-truth 0.8.6 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/ajv.js +1 -1
- package/dist/cli/arktype.js +1 -1
- package/dist/cli/effect.js +1 -1
- package/dist/cli/typebox.js +2 -2
- package/dist/cli/valibot.js +1 -1
- package/dist/cli/yup.js +1 -1
- package/dist/cli/zod.js +1 -1
- package/dist/{cli-Btq8M8tP.js → cli-CLh6PrSG.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/{typebox-D1GT2WSK.js → typebox-CnmZohGb.js} +52 -7
- package/dist/typebox.js +1 -1
- package/package.json +1 -1
package/dist/cli/ajv.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as schemaToAjv } from "../ajv-BjWqjOc9.js";
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
3
|
+
import { n as version, t as cli } from "../cli-CLh6PrSG.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/arktype.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as schemaToArktype } from "../arktype-pHeYh_IG.js";
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
3
|
+
import { n as version, t as cli } from "../cli-CLh6PrSG.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/effect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as schemaToEffect } from "../effect-CM1XVqvf.js";
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
3
|
+
import { n as version, t as cli } from "../cli-CLh6PrSG.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/typebox.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToTypebox } from "../typebox-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToTypebox } from "../typebox-CnmZohGb.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-CLh6PrSG.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/valibot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as schemaToValibot } from "../valibot-1p_Y7fu6.js";
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
3
|
+
import { n as version, t as cli } from "../cli-CLh6PrSG.js";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
6
6
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
package/dist/cli/yup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as schemaToYup } from "../yup-IOat93gr.js";
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
3
|
+
import { n as version, t as cli } from "../cli-CLh6PrSG.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
2
|
import { t as schemaToZod } from "../zod-q9c0XhJO.js";
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
3
|
+
import { n as version, t as cli } from "../cli-CLh6PrSG.js";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
6
6
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
@@ -9,7 +9,7 @@ import * as Stdio from "effect/Stdio";
|
|
|
9
9
|
import "@effect/platform-node/NodeFileSystem";
|
|
10
10
|
import * as FileSystem from "effect/FileSystem";
|
|
11
11
|
// package.json
|
|
12
|
-
var version = "0.8.
|
|
12
|
+
var version = "0.8.7";
|
|
13
13
|
// src/file/index.ts
|
|
14
14
|
/** Creates the directory and its parents. An existing directory is not an error. */
|
|
15
15
|
function mkdir(dir) {
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { i as fmt, n as parseSchemaFile, r as FormatError, t as ParseError } fro
|
|
|
3
3
|
import { n as ajv, t as schemaToAjv } from "./ajv-BjWqjOc9.js";
|
|
4
4
|
import { n as arktype, t as schemaToArktype } from "./arktype-pHeYh_IG.js";
|
|
5
5
|
import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-CM1XVqvf.js";
|
|
6
|
-
import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-
|
|
6
|
+
import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-CnmZohGb.js";
|
|
7
7
|
import { n as valibot, t as schemaToValibot } from "./valibot-1p_Y7fu6.js";
|
|
8
8
|
import { n as yup, t as schemaToYup } from "./yup-IOat93gr.js";
|
|
9
9
|
import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-q9c0XhJO.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as itemsSchemaOf, B as typeboxRefOpt, Bt as isNullable, D as stringboolPattern, G as renderDefinitions, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Lt as isDeepLocalPointer, Mt as hasNumericKeyword, Nt as hasStringKeyword, O as stringboolTruthyPattern, Ot as hasCombinator, Q as isOptionalByDefault, R as typeboxDefaultOpt, Rt as isDefaultOnlyMember,
|
|
1
|
+
import { $ as itemsSchemaOf, B as typeboxRefOpt, Bt as isNullable, D as stringboolPattern, G as renderDefinitions, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Lt as isDeepLocalPointer, Mt as hasNumericKeyword, Nt as hasStringKeyword, O as stringboolTruthyPattern, Ot as hasCombinator, Q as isOptionalByDefault, R as typeboxDefaultOpt, Rt as isDefaultOnlyMember, U as missingDefinitionComment, V as definitionsOf, W as planDocument, X as hasRootSelfReference, Y as cyclicDefinitionNames, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, a as typeboxWrap, at as hasNotKeyword, bt as resolveOpenAPIRef, ct as foldAllOfMembers, jt as hasFixedLength, l as withPolymorphicBases, lt as isKeywordOnlyMember, on as DEFINITION_REF_PREFIXES, pn as INTEGER_WIRE_PATTERN, q as schemaNamer, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, ut as patternSource, vn as NOT_KEYWORD_UNSUPPORTED_MARKER, vt as makeSafeKey, xn as NUMBER_WIRE_PATTERN, yt as normalizeTypes, z as typeboxMetaOpts, zt as isNullTypeMember } from "./helper-1oDB5NHM.js";
|
|
2
2
|
// src/generator/typebox/enum.ts
|
|
3
3
|
function lit(v) {
|
|
4
4
|
if (v === null) return "null";
|
|
@@ -320,6 +320,53 @@ function wireString(schema, ref, pattern) {
|
|
|
320
320
|
];
|
|
321
321
|
return opts.length > 0 ? `Type.String({${opts.join(",")}})` : "Type.String()";
|
|
322
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* A number-from-text wire: the `Type.String` carries its pattern as a string, the
|
|
325
|
+
* JSON Schema form (a `RegExp` serializes as `{}`), and each numeric bound is a
|
|
326
|
+
* `Type.Refine` on the text read as a number, since the decoded value is not checked.
|
|
327
|
+
*/
|
|
328
|
+
function numericWire(schema, pattern, ref) {
|
|
329
|
+
return numericBounds(schema).reduce((wire, [check, keyword, message]) => `Type.Refine(${wire},(value)=>${check},()=>${JSON.stringify(schema[`x-${keyword}-message`] ?? schema["x-error-message"] ?? message)})`, wireString(schema, ref, JSON.stringify(pattern.source)));
|
|
330
|
+
}
|
|
331
|
+
/** The checks of the numeric keywords on `Number(value)`, with TypeBox's own messages. */
|
|
332
|
+
function numericBounds(schema) {
|
|
333
|
+
const bounds = [];
|
|
334
|
+
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf } = schema;
|
|
335
|
+
if (minimum !== void 0) bounds.push(exclusiveMinimum === true ? [
|
|
336
|
+
`Number(value)>${minimum}`,
|
|
337
|
+
"exclusiveMinimum",
|
|
338
|
+
`must be > ${minimum}`
|
|
339
|
+
] : [
|
|
340
|
+
`Number(value)>=${minimum}`,
|
|
341
|
+
"minimum",
|
|
342
|
+
`must be >= ${minimum}`
|
|
343
|
+
]);
|
|
344
|
+
if (typeof exclusiveMinimum === "number") bounds.push([
|
|
345
|
+
`Number(value)>${exclusiveMinimum}`,
|
|
346
|
+
"exclusiveMinimum",
|
|
347
|
+
`must be > ${exclusiveMinimum}`
|
|
348
|
+
]);
|
|
349
|
+
if (maximum !== void 0) bounds.push(exclusiveMaximum === true ? [
|
|
350
|
+
`Number(value)<${maximum}`,
|
|
351
|
+
"exclusiveMaximum",
|
|
352
|
+
`must be < ${maximum}`
|
|
353
|
+
] : [
|
|
354
|
+
`Number(value)<=${maximum}`,
|
|
355
|
+
"maximum",
|
|
356
|
+
`must be <= ${maximum}`
|
|
357
|
+
]);
|
|
358
|
+
if (typeof exclusiveMaximum === "number") bounds.push([
|
|
359
|
+
`Number(value)<${exclusiveMaximum}`,
|
|
360
|
+
"exclusiveMaximum",
|
|
361
|
+
`must be < ${exclusiveMaximum}`
|
|
362
|
+
]);
|
|
363
|
+
if (multipleOf !== void 0) bounds.push([
|
|
364
|
+
`((number)=>(Number.isInteger(number)&&(1/${multipleOf})%1===0)||((remainder)=>Math.min(Math.abs(remainder),Math.abs(remainder-${multipleOf}),Math.abs(remainder+${multipleOf}))<1e-10)(number%${multipleOf}))(Number(value))`,
|
|
365
|
+
"multipleOf",
|
|
366
|
+
`must be multiple of ${multipleOf}`
|
|
367
|
+
]);
|
|
368
|
+
return bounds;
|
|
369
|
+
}
|
|
323
370
|
/** A keyword-only `allOf` member. TypeBox has no type-guarded check, so the keyword's type carries it. */
|
|
324
371
|
function keywordSchema(schema) {
|
|
325
372
|
if (hasStringKeyword(schema) && !hasNumericKeyword(schema)) return string({
|
|
@@ -451,20 +498,18 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
451
498
|
const types = normalizeTypes(schema.type);
|
|
452
499
|
if (types.includes("string")) return typeboxWrap(string(schema, hostRef), schema);
|
|
453
500
|
if (types.includes("number")) {
|
|
454
|
-
const base = number(schema, hostRef);
|
|
455
501
|
if (isStringWireParam) {
|
|
456
|
-
const wire =
|
|
502
|
+
const wire = numericWire(schema, NUMBER_WIRE_PATTERN, hostRef);
|
|
457
503
|
return typeboxWrap(`Codec(${wire}).Decode((value)=>Number(value)).Encode((value)=>String(value))`, schema);
|
|
458
504
|
}
|
|
459
|
-
return typeboxWrap(
|
|
505
|
+
return typeboxWrap(number(schema, hostRef), schema);
|
|
460
506
|
}
|
|
461
507
|
if (types.includes("integer")) {
|
|
462
|
-
const base = integer(schema, hostRef);
|
|
463
508
|
if (isStringWireParam) {
|
|
464
|
-
const wire =
|
|
509
|
+
const wire = numericWire(schema, INTEGER_WIRE_PATTERN, hostRef);
|
|
465
510
|
return typeboxWrap(`Codec(${wire}).Decode((value)=>Number(value)).Encode((value)=>String(value))`, schema);
|
|
466
511
|
}
|
|
467
|
-
return typeboxWrap(
|
|
512
|
+
return typeboxWrap(integer(schema, hostRef), schema);
|
|
468
513
|
}
|
|
469
514
|
if (types.includes("boolean")) {
|
|
470
515
|
if (isStringWireParam) {
|
package/dist/typebox.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToTypebox } from "./typebox-
|
|
1
|
+
export { t as schemaToTypebox } from "./typebox-CnmZohGb.js";
|