schema-truth 0.0.0-stage → 0.8.1

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 (45) hide show
  1. package/README.md +143 -2
  2. package/dist/ajv-DS9gtNZC.js +105 -0
  3. package/dist/ajv.d.ts +24 -0
  4. package/dist/ajv.js +1 -0
  5. package/dist/arktype-CRZ8vXZ5.js +803 -0
  6. package/dist/arktype.d.ts +10 -0
  7. package/dist/arktype.js +1 -0
  8. package/dist/cli/ajv.d.ts +1 -0
  9. package/dist/cli/ajv.js +15 -0
  10. package/dist/cli/arktype.d.ts +1 -0
  11. package/dist/cli/arktype.js +15 -0
  12. package/dist/cli/effect.d.ts +1 -0
  13. package/dist/cli/effect.js +15 -0
  14. package/dist/cli/typebox.d.ts +1 -0
  15. package/dist/cli/typebox.js +15 -0
  16. package/dist/cli/valibot.d.ts +1 -0
  17. package/dist/cli/valibot.js +15 -0
  18. package/dist/cli/yup.d.ts +1 -0
  19. package/dist/cli/yup.js +15 -0
  20. package/dist/cli/zod.d.ts +1 -0
  21. package/dist/cli/zod.js +15 -0
  22. package/dist/cli-eAY8LqwP.js +124 -0
  23. package/dist/effect-BkWovUi3.js +678 -0
  24. package/dist/effect.d.ts +12 -0
  25. package/dist/effect.js +1 -0
  26. package/dist/helper-CbeedY35.js +1798 -0
  27. package/dist/index-DYzAccyT.d.ts +69 -0
  28. package/dist/index-G7UqNQ4w.d.ts +603 -0
  29. package/dist/index.d.ts +332 -0
  30. package/dist/index.js +10 -0
  31. package/dist/parser-CyJ2auea.js +36 -0
  32. package/dist/typebox-wYeJqy7T.js +563 -0
  33. package/dist/typebox.d.ts +21 -0
  34. package/dist/typebox.js +1 -0
  35. package/dist/utils-Bky98UmP.js +1146 -0
  36. package/dist/valibot-DQUEDYKt.js +705 -0
  37. package/dist/valibot.d.ts +9 -0
  38. package/dist/valibot.js +1 -0
  39. package/dist/yup-BMpa9Co1.js +92 -0
  40. package/dist/yup.d.ts +17 -0
  41. package/dist/yup.js +1 -0
  42. package/dist/zod-Dq9LtqPL.js +816 -0
  43. package/dist/zod.d.ts +9 -0
  44. package/dist/zod.js +1 -0
  45. package/package.json +112 -4
@@ -0,0 +1,9 @@
1
+ import { r as JSONSchema } from "./index-G7UqNQ4w.js";
2
+ import { n as GenerateOptions } from "./index-DYzAccyT.js";
3
+ //#region src/generator/valibot/index.d.ts
4
+ /**
5
+ * A whole JSON Schema document as a Valibot module: imports, `$defs` in dependency
6
+ * order, the root export, and the inferred output type.
7
+ */
8
+ export declare function schemaToValibot(input: JSONSchema, options?: GenerateOptions): string;
9
+ //#endregion
@@ -0,0 +1 @@
1
+ export { t as schemaToValibot } from "./valibot-DQUEDYKt.js";
@@ -0,0 +1,92 @@
1
+ import { c as normalizeTypes, s as makeSafeKey } from "./utils-Bky98UmP.js";
2
+ import { G as schemaNamer, W as rootNameOf } from "./helper-CbeedY35.js";
3
+ //#region src/generator/yup/integer.ts
4
+ /**
5
+ * Generate a Yup integer schema as `yup.number().integer()`, with `minimum`
6
+ * as `.min(...)`. Other numeric keywords are silent no-ops in this slice.
7
+ */
8
+ function integer(schema) {
9
+ return `yup.number().integer()${typeof schema.minimum === "number" ? `.min(${schema.minimum})` : ""}`;
10
+ }
11
+ //#endregion
12
+ //#region src/generator/yup/number.ts
13
+ /**
14
+ * Generate a Yup number schema. `minimum` becomes `.min(...)`; other numeric
15
+ * keywords are silent no-ops in this slice.
16
+ */
17
+ function number(schema) {
18
+ return `yup.number()${typeof schema.minimum === "number" ? `.min(${schema.minimum})` : ""}`;
19
+ }
20
+ //#endregion
21
+ //#region src/generator/yup/object.ts
22
+ /**
23
+ * Generate a Yup object schema for a JSON Schema object node.
24
+ *
25
+ * Required properties get `.required()`; Yup 1.x object fields are optional
26
+ * unless that is chained. Unsupported object keywords are silent no-ops.
27
+ */
28
+ function object(schema) {
29
+ if (!schema.properties) return "yup.object({})";
30
+ const required = Array.isArray(schema.required) ? schema.required : [];
31
+ return `yup.object({${Object.entries(schema.properties).map(([key, propSchema]) => {
32
+ const parsed = yup(propSchema);
33
+ const suffix = required.includes(key) ? ".required()" : "";
34
+ return `${makeSafeKey(key)}:${parsed}${suffix}`;
35
+ }).join(",")}})`;
36
+ }
37
+ //#endregion
38
+ //#region src/generator/yup/string.ts
39
+ /**
40
+ * Generate a Yup string schema. `format: email` becomes `.email()`; every
41
+ * other string keyword is a silent no-op in this slice.
42
+ */
43
+ function string(schema) {
44
+ return schema.format === "email" ? "yup.string().email()" : "yup.string()";
45
+ }
46
+ //#endregion
47
+ //#region src/generator/yup/yup.ts
48
+ /**
49
+ * Generate a Yup expression from one JSON Schema node.
50
+ *
51
+ * Unsupported keywords, combinators, `$ref` and `x-*` extensions are silent
52
+ * no-ops. Unknown nodes fall back to `yup.mixed()`.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * yup({ type: 'string' }) // 'yup.string()'
57
+ * ```
58
+ */
59
+ function yup(schema) {
60
+ if (schema.properties !== void 0) return object(schema);
61
+ const types = normalizeTypes(schema.type);
62
+ if (types.includes("string")) return string(schema);
63
+ if (types.includes("number")) return number(schema);
64
+ if (types.includes("integer")) return integer(schema);
65
+ if (types.includes("object")) return object(schema);
66
+ return "yup.mixed()";
67
+ }
68
+ //#endregion
69
+ //#region src/generator/yup/index.ts
70
+ /**
71
+ * Convert a JSON Schema document to Yup schema source.
72
+ *
73
+ * First slice: objects, strings, numbers and integers. Combinators, `$ref` /
74
+ * `$defs`, cycles and `x-*` extensions are silent no-ops.
75
+ *
76
+ * @param schema - JSON Schema object to convert
77
+ * @param options - Generation options
78
+ * @param options.exportType - Whether to include type export (default: true)
79
+ * @param options.openapi - Enable OpenAPI component-aware naming (default: false)
80
+ * @returns Generated TypeScript/Yup code string
81
+ */
82
+ function schemaToYup(schema, options) {
83
+ const exportType = options?.exportType ?? true;
84
+ const rootName = rootNameOf(schema, schemaNamer(options?.openapi));
85
+ return [
86
+ `import * as yup from 'yup'`,
87
+ `export const ${rootName} = ${yup(schema)}`,
88
+ ...exportType ? [`export type ${rootName} = yup.InferType<typeof ${rootName}>`] : []
89
+ ].join("\n\n");
90
+ }
91
+ //#endregion
92
+ export { yup as n, schemaToYup as t };
package/dist/yup.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { r as JSONSchema } from "./index-G7UqNQ4w.js";
2
+ import { n as GenerateOptions } from "./index-DYzAccyT.js";
3
+ //#region src/generator/yup/index.d.ts
4
+ /**
5
+ * Convert a JSON Schema document to Yup schema source.
6
+ *
7
+ * First slice: objects, strings, numbers and integers. Combinators, `$ref` /
8
+ * `$defs`, cycles and `x-*` extensions are silent no-ops.
9
+ *
10
+ * @param schema - JSON Schema object to convert
11
+ * @param options - Generation options
12
+ * @param options.exportType - Whether to include type export (default: true)
13
+ * @param options.openapi - Enable OpenAPI component-aware naming (default: false)
14
+ * @returns Generated TypeScript/Yup code string
15
+ */
16
+ export declare function schemaToYup(schema: JSONSchema, options?: GenerateOptions): string;
17
+ //#endregion
package/dist/yup.js ADDED
@@ -0,0 +1 @@
1
+ export { t as schemaToYup } from "./yup-BMpa9Co1.js";