@powerlines/schema 0.11.40 → 0.11.42
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/bundle.cjs +0 -1
- package/dist/codegen.cjs +12 -19
- package/dist/codegen.d.cts +7 -2
- package/dist/codegen.d.cts.map +1 -1
- package/dist/codegen.d.mts +7 -2
- package/dist/codegen.d.mts.map +1 -1
- package/dist/codegen.mjs +13 -18
- package/dist/codegen.mjs.map +1 -1
- package/dist/constants.cjs +0 -2
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.mts +1 -1
- package/dist/constants.mjs +0 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/extract.cjs +23 -9
- package/dist/extract.d.cts +2 -3
- package/dist/extract.d.cts.map +1 -1
- package/dist/extract.d.mts +2 -3
- package/dist/extract.d.mts.map +1 -1
- package/dist/extract.mjs +28 -12
- package/dist/extract.mjs.map +1 -1
- package/dist/helpers.cjs +0 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +30 -4
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +30 -4
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -3
- package/dist/metadata.cjs +1 -2
- package/dist/metadata.d.cts.map +1 -1
- package/dist/metadata.d.mts.map +1 -1
- package/dist/metadata.mjs +1 -1
- package/dist/metadata.mjs.map +1 -1
- package/dist/persistence.cjs +0 -1
- package/dist/reflection.cjs +0 -1
- package/dist/resolve.cjs +0 -1
- package/dist/type-checks.cjs +27 -2
- package/dist/type-checks.d.cts +17 -1
- package/dist/type-checks.d.cts.map +1 -1
- package/dist/type-checks.d.mts +17 -1
- package/dist/type-checks.d.mts.map +1 -1
- package/dist/type-checks.mjs +25 -1
- package/dist/type-checks.mjs.map +1 -1
- package/dist/types.d.cts +43 -28
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +44 -29
- package/dist/types.d.mts.map +1 -1
- package/dist/validate.cjs +27 -0
- package/dist/validate.mjs +25 -0
- package/dist/validate.mjs.map +1 -0
- package/package.json +20 -49
- package/dist/types.cjs +0 -0
- package/dist/types.mjs +0 -1
package/dist/bundle.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
1
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
let _powerlines_core_lib_unplugin = require("@powerlines/core/lib/unplugin");
|
|
4
3
|
let _powerlines_unplugin_rolldown = require("@powerlines/unplugin/rolldown");
|
package/dist/codegen.cjs
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
1
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_metadata = require('./metadata.cjs');
|
|
4
3
|
const require_type_checks = require('./type-checks.cjs');
|
|
5
4
|
const require_helpers = require('./helpers.cjs');
|
|
5
|
+
const require_validate = require('./validate.cjs');
|
|
6
6
|
let _stryke_convert_to_bool = require("@stryke/convert/to-bool");
|
|
7
7
|
let _stryke_type_checks_is_boolean = require("@stryke/type-checks/is-boolean");
|
|
8
8
|
let _stryke_type_checks_is_null = require("@stryke/type-checks/is-null");
|
|
9
9
|
let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
|
|
10
10
|
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
11
11
|
let _stryke_type_checks_is_undefined = require("@stryke/type-checks/is-undefined");
|
|
12
|
-
let ajv = require("ajv");
|
|
13
|
-
ajv = require_runtime.__toESM(ajv, 1);
|
|
14
|
-
let ajv_formats_dist_formats_js = require("ajv-formats/dist/formats.js");
|
|
15
|
-
let ajv_dist_compile_codegen_index_js = require("ajv/dist/compile/codegen/index.js");
|
|
16
12
|
let ajv_dist_standalone_index_js = require("ajv/dist/standalone/index.js");
|
|
17
13
|
ajv_dist_standalone_index_js = require_runtime.__toESM(ajv_dist_standalone_index_js, 1);
|
|
18
14
|
|
|
@@ -34,14 +30,14 @@ function stringifyType(schema) {
|
|
|
34
30
|
if (primaryType === "integer" || primaryType === "number") return "number";
|
|
35
31
|
return primaryType;
|
|
36
32
|
}
|
|
37
|
-
if (Array.isArray(schema.enum)) return schema.enum.map((value) => JSON.stringify(value)).join(" | ");
|
|
33
|
+
if (schema.type === "array" && Array.isArray(schema.enum)) return schema.enum.map((value) => JSON.stringify(value)).join(" | ");
|
|
38
34
|
if (schema.const !== void 0) return JSON.stringify(schema.const);
|
|
39
35
|
if (schema.type === "array" || schema.items) return `${stringifyType(Array.isArray(schema.items) ? schema.items[0] : schema.items)}[]`;
|
|
40
36
|
if (schema.type === "object" || schema.properties || schema.additionalProperties) {
|
|
41
|
-
if (
|
|
37
|
+
if (require_type_checks.isJsonSchema(schema.additionalProperties)) return `{ [key: string]: ${stringifyType(schema.additionalProperties)} }`;
|
|
42
38
|
if (require_type_checks.isJsonSchemaObject(schema)) return `{ ${require_helpers.getPropertiesList(schema).map((property) => {
|
|
43
|
-
const suffix = property.
|
|
44
|
-
return `${property.
|
|
39
|
+
const suffix = schema.required?.includes(property.name) || property.nullable ? `${property.optional ? "?" : ""}${property.nullable ? " | null" : ""}` : "";
|
|
40
|
+
return `${property.name}${suffix}: ${stringifyType(property)}`;
|
|
45
41
|
}).join(";\n")} }`;
|
|
46
42
|
}
|
|
47
43
|
if (schema.oneOf || schema.anyOf) return (schema.oneOf ?? schema.anyOf ?? []).map((branch) => stringifyType(branch)).join(" | ");
|
|
@@ -52,17 +48,14 @@ function stringifyType(schema) {
|
|
|
52
48
|
* Generates standalone JSON Schema validation code using Ajv.
|
|
53
49
|
*/
|
|
54
50
|
async function generateCode(schemas, refsOrFuncts) {
|
|
55
|
-
|
|
56
|
-
schemas,
|
|
57
|
-
code: {
|
|
58
|
-
source: true,
|
|
59
|
-
esm: true
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
ajv$1.opts.code.formats ??= ajv_dist_compile_codegen_index_js._`await import("ajv-formats/dist/formats").${new ajv_dist_compile_codegen_index_js.Name("fullFormats")}`;
|
|
63
|
-
for (const formatName of ajv_formats_dist_formats_js.formatNames) ajv$1.addFormat(formatName, ajv_formats_dist_formats_js.fullFormats[formatName]);
|
|
64
|
-
return (0, ajv_dist_standalone_index_js.default)(ajv$1, refsOrFuncts);
|
|
51
|
+
return (0, ajv_dist_standalone_index_js.default)(require_validate.getValidator(schemas), refsOrFuncts);
|
|
65
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* A helper function to determine if a JSON Schema fragment is nullable, for use in code generation.
|
|
55
|
+
*
|
|
56
|
+
* @param schema - The JSON Schema fragment to check.
|
|
57
|
+
* @returns `true` if the schema is nullable, otherwise `false`. A schema is considered nullable if it has `nullable: true` or if its `type` includes `"null"`.
|
|
58
|
+
*/
|
|
66
59
|
function isNullableSchema(schema) {
|
|
67
60
|
return require_metadata.isSchemaNullable(schema);
|
|
68
61
|
}
|
package/dist/codegen.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { JsonSchema, JsonSchemaPrimitiveType } from "./types.cjs";
|
|
2
|
-
import { Options } from "ajv";
|
|
3
2
|
import standaloneCode from "ajv/dist/standalone/index.js";
|
|
4
3
|
|
|
5
4
|
//#region src/codegen.d.ts
|
|
@@ -14,7 +13,13 @@ declare function stringifyType<T = unknown>(schema?: JsonSchema<T>): string;
|
|
|
14
13
|
/**
|
|
15
14
|
* Generates standalone JSON Schema validation code using Ajv.
|
|
16
15
|
*/
|
|
17
|
-
declare function generateCode(schemas:
|
|
16
|
+
declare function generateCode<T = unknown>(schemas: JsonSchema<T>, refsOrFuncts?: Parameters<typeof standaloneCode>[1]): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* A helper function to determine if a JSON Schema fragment is nullable, for use in code generation.
|
|
19
|
+
*
|
|
20
|
+
* @param schema - The JSON Schema fragment to check.
|
|
21
|
+
* @returns `true` if the schema is nullable, otherwise `false`. A schema is considered nullable if it has `nullable: true` or if its `type` includes `"null"`.
|
|
22
|
+
*/
|
|
18
23
|
declare function isNullableSchema(schema?: JsonSchema): boolean;
|
|
19
24
|
//#endregion
|
|
20
25
|
export { generateCode, isNullableSchema, stringifyType, stringifyValue };
|
package/dist/codegen.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.cts","names":[],"sources":["../src/codegen.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"codegen.d.cts","names":[],"sources":["../src/codegen.ts"],"mappings":";;;;;;AAkCA;iBAAgB,cAAA,CACd,KAAA,YACA,IAAA,GAAO,uBAAuB;;;;iBAoBhB,aAAA,aAAA,CAA2B,MAAA,GAAS,UAAU,CAAC,CAAA;;;AApBtB;iBA6FnB,YAAA,aAAA,CACpB,OAAA,EAAS,UAAA,CAAW,CAAA,GACpB,YAAA,GAAe,UAAA,QAAkB,cAAA,OAAkB,OAAA;;;;;;;iBAarC,gBAAA,CAAiB,MAAmB,GAAV,UAAU"}
|
package/dist/codegen.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { JsonSchema, JsonSchemaPrimitiveType } from "./types.mjs";
|
|
2
|
-
import { Options } from "ajv";
|
|
3
2
|
import standaloneCode from "ajv/dist/standalone/index.js";
|
|
4
3
|
|
|
5
4
|
//#region src/codegen.d.ts
|
|
@@ -14,7 +13,13 @@ declare function stringifyType<T = unknown>(schema?: JsonSchema<T>): string;
|
|
|
14
13
|
/**
|
|
15
14
|
* Generates standalone JSON Schema validation code using Ajv.
|
|
16
15
|
*/
|
|
17
|
-
declare function generateCode(schemas:
|
|
16
|
+
declare function generateCode<T = unknown>(schemas: JsonSchema<T>, refsOrFuncts?: Parameters<typeof standaloneCode>[1]): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* A helper function to determine if a JSON Schema fragment is nullable, for use in code generation.
|
|
19
|
+
*
|
|
20
|
+
* @param schema - The JSON Schema fragment to check.
|
|
21
|
+
* @returns `true` if the schema is nullable, otherwise `false`. A schema is considered nullable if it has `nullable: true` or if its `type` includes `"null"`.
|
|
22
|
+
*/
|
|
18
23
|
declare function isNullableSchema(schema?: JsonSchema): boolean;
|
|
19
24
|
//#endregion
|
|
20
25
|
export { generateCode, isNullableSchema, stringifyType, stringifyValue };
|
package/dist/codegen.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.mts","names":[],"sources":["../src/codegen.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"codegen.d.mts","names":[],"sources":["../src/codegen.ts"],"mappings":";;;;;;AAkCA;iBAAgB,cAAA,CACd,KAAA,YACA,IAAA,GAAO,uBAAuB;;;;iBAoBhB,aAAA,aAAA,CAA2B,MAAA,GAAS,UAAU,CAAC,CAAA;;;AApBtB;iBA6FnB,YAAA,aAAA,CACpB,OAAA,EAAS,UAAA,CAAW,CAAA,GACpB,YAAA,GAAe,UAAA,QAAkB,cAAA,OAAkB,OAAA;;;;;;;iBAarC,gBAAA,CAAiB,MAAmB,GAAV,UAAU"}
|
package/dist/codegen.mjs
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { getPrimarySchemaType, isSchemaNullable } from "./metadata.mjs";
|
|
2
|
-
import { isJsonSchemaObject } from "./type-checks.mjs";
|
|
2
|
+
import { isJsonSchema, isJsonSchemaObject } from "./type-checks.mjs";
|
|
3
3
|
import { getPropertiesList } from "./helpers.mjs";
|
|
4
|
+
import { getValidator } from "./validate.mjs";
|
|
4
5
|
import { toBool } from "@stryke/convert/to-bool";
|
|
5
6
|
import { isBoolean } from "@stryke/type-checks/is-boolean";
|
|
6
7
|
import { isNull } from "@stryke/type-checks/is-null";
|
|
7
8
|
import { isNumber } from "@stryke/type-checks/is-number";
|
|
8
9
|
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
9
10
|
import { isUndefined } from "@stryke/type-checks/is-undefined";
|
|
10
|
-
import Ajv from "ajv";
|
|
11
|
-
import { formatNames, fullFormats } from "ajv-formats/dist/formats.js";
|
|
12
|
-
import { Name, _ } from "ajv/dist/compile/codegen/index.js";
|
|
13
11
|
import standaloneCode from "ajv/dist/standalone/index.js";
|
|
14
12
|
|
|
15
13
|
//#region src/codegen.ts
|
|
@@ -30,14 +28,14 @@ function stringifyType(schema) {
|
|
|
30
28
|
if (primaryType === "integer" || primaryType === "number") return "number";
|
|
31
29
|
return primaryType;
|
|
32
30
|
}
|
|
33
|
-
if (Array.isArray(schema.enum)) return schema.enum.map((value) => JSON.stringify(value)).join(" | ");
|
|
31
|
+
if (schema.type === "array" && Array.isArray(schema.enum)) return schema.enum.map((value) => JSON.stringify(value)).join(" | ");
|
|
34
32
|
if (schema.const !== void 0) return JSON.stringify(schema.const);
|
|
35
33
|
if (schema.type === "array" || schema.items) return `${stringifyType(Array.isArray(schema.items) ? schema.items[0] : schema.items)}[]`;
|
|
36
34
|
if (schema.type === "object" || schema.properties || schema.additionalProperties) {
|
|
37
|
-
if (schema.additionalProperties
|
|
35
|
+
if (isJsonSchema(schema.additionalProperties)) return `{ [key: string]: ${stringifyType(schema.additionalProperties)} }`;
|
|
38
36
|
if (isJsonSchemaObject(schema)) return `{ ${getPropertiesList(schema).map((property) => {
|
|
39
|
-
const suffix = property.
|
|
40
|
-
return `${property.
|
|
37
|
+
const suffix = schema.required?.includes(property.name) || property.nullable ? `${property.optional ? "?" : ""}${property.nullable ? " | null" : ""}` : "";
|
|
38
|
+
return `${property.name}${suffix}: ${stringifyType(property)}`;
|
|
41
39
|
}).join(";\n")} }`;
|
|
42
40
|
}
|
|
43
41
|
if (schema.oneOf || schema.anyOf) return (schema.oneOf ?? schema.anyOf ?? []).map((branch) => stringifyType(branch)).join(" | ");
|
|
@@ -48,17 +46,14 @@ function stringifyType(schema) {
|
|
|
48
46
|
* Generates standalone JSON Schema validation code using Ajv.
|
|
49
47
|
*/
|
|
50
48
|
async function generateCode(schemas, refsOrFuncts) {
|
|
51
|
-
|
|
52
|
-
schemas,
|
|
53
|
-
code: {
|
|
54
|
-
source: true,
|
|
55
|
-
esm: true
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
ajv.opts.code.formats ??= _`await import("ajv-formats/dist/formats").${new Name("fullFormats")}`;
|
|
59
|
-
for (const formatName of formatNames) ajv.addFormat(formatName, fullFormats[formatName]);
|
|
60
|
-
return standaloneCode(ajv, refsOrFuncts);
|
|
49
|
+
return standaloneCode(getValidator(schemas), refsOrFuncts);
|
|
61
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* A helper function to determine if a JSON Schema fragment is nullable, for use in code generation.
|
|
53
|
+
*
|
|
54
|
+
* @param schema - The JSON Schema fragment to check.
|
|
55
|
+
* @returns `true` if the schema is nullable, otherwise `false`. A schema is considered nullable if it has `nullable: true` or if its `type` includes `"null"`.
|
|
56
|
+
*/
|
|
62
57
|
function isNullableSchema(schema) {
|
|
63
58
|
return isSchemaNullable(schema);
|
|
64
59
|
}
|
package/dist/codegen.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.mjs","names":[],"sources":["../src/codegen.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toBool } from \"@stryke/convert/to-bool\";\nimport { isBoolean } from \"@stryke/type-checks/is-boolean\";\nimport { isNull } from \"@stryke/type-checks/is-null\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport
|
|
1
|
+
{"version":3,"file":"codegen.mjs","names":[],"sources":["../src/codegen.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toBool } from \"@stryke/convert/to-bool\";\nimport { isBoolean } from \"@stryke/type-checks/is-boolean\";\nimport { isNull } from \"@stryke/type-checks/is-null\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport standaloneCode from \"ajv/dist/standalone\";\nimport { getPropertiesList } from \"./helpers\";\nimport { getPrimarySchemaType, isSchemaNullable } from \"./metadata\";\nimport { isJsonSchema, isJsonSchemaObject } from \"./type-checks\";\nimport { JsonSchema, JsonSchemaPrimitiveType } from \"./types\";\nimport { getValidator } from \"./validate\";\n\n/**\n * Stringifies a value for generated TypeScript code.\n */\nexport function stringifyValue(\n value?: unknown,\n type?: JsonSchemaPrimitiveType | string\n): string {\n return isUndefined(value)\n ? \"undefined\"\n : isNull(value)\n ? \"null\"\n : type === \"boolean\" || isBoolean(value)\n ? String(toBool(value))\n : type === \"number\" || isNumber(value)\n ? Number.parseFloat(String(value)).toLocaleString(undefined, {\n maximumFractionDigits: 20\n })\n : type === \"integer\"\n ? Number.parseInt(String(value)).toLocaleString()\n : JSON.stringify(value);\n}\n\n/**\n * Stringifies a JSON Schema fragment into a TypeScript-like type string.\n */\nexport function stringifyType<T = unknown>(schema?: JsonSchema<T>): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (isSetString(schema.$ref)) {\n const match = /^#\\/(?:definitions|\\$defs)\\/(.+)$/.exec(schema.$ref);\n\n return match?.[1] ?? schema.$ref;\n }\n\n const primaryType = getPrimarySchemaType(schema);\n if (primaryType) {\n if (primaryType === \"integer\" || primaryType === \"number\") {\n return \"number\";\n }\n\n return primaryType;\n }\n\n if (schema.type === \"array\" && Array.isArray(schema.enum)) {\n return schema.enum.map(value => JSON.stringify(value)).join(\" | \");\n }\n\n if (schema.const !== undefined) {\n return JSON.stringify(schema.const);\n }\n\n if (schema.type === \"array\" || schema.items) {\n const items = Array.isArray(schema.items) ? schema.items[0] : schema.items;\n\n return `${stringifyType(items)}[]`;\n }\n\n if (\n schema.type === \"object\" ||\n schema.properties ||\n schema.additionalProperties\n ) {\n if (isJsonSchema(schema.additionalProperties)) {\n return `{ [key: string]: ${stringifyType(schema.additionalProperties)} }`;\n }\n\n if (isJsonSchemaObject(schema)) {\n return `{ ${getPropertiesList(schema as JsonSchema<Record<string, any>>)\n .map(property => {\n const suffix =\n schema.required?.includes(property.name) || property.nullable\n ? `${property.optional ? \"?\" : \"\"}${property.nullable ? \" | null\" : \"\"}`\n : \"\";\n\n return `${property.name}${suffix}: ${stringifyType(property)}`;\n })\n .join(\";\\n\")} }`;\n }\n }\n\n if (schema.oneOf || schema.anyOf) {\n return ((schema.oneOf ?? schema.anyOf ?? []) as JsonSchema<T>[])\n .map(branch => stringifyType(branch))\n .join(\" | \");\n }\n\n if (schema.allOf) {\n return \"object\";\n }\n\n return \"unknown\";\n}\n\n/**\n * Generates standalone JSON Schema validation code using Ajv.\n */\nexport async function generateCode<T = unknown>(\n schemas: JsonSchema<T>,\n refsOrFuncts?: Parameters<typeof standaloneCode>[1]\n) {\n const ajv = getValidator(schemas);\n\n return standaloneCode(ajv, refsOrFuncts);\n}\n\n/**\n * A helper function to determine if a JSON Schema fragment is nullable, for use in code generation.\n *\n * @param schema - The JSON Schema fragment to check.\n * @returns `true` if the schema is nullable, otherwise `false`. A schema is considered nullable if it has `nullable: true` or if its `type` includes `\"null\"`.\n */\nexport function isNullableSchema(schema?: JsonSchema): boolean {\n return isSchemaNullable(schema);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAgB,eACd,OACA,MACQ;CACR,OAAO,YAAY,KAAK,IACpB,cACA,OAAO,KAAK,IACV,SACA,SAAS,aAAa,UAAU,KAAK,IACnC,OAAO,OAAO,KAAK,CAAC,IACpB,SAAS,YAAY,SAAS,KAAK,IACjC,OAAO,WAAW,OAAO,KAAK,CAAC,EAAE,eAAe,QAAW,EACzD,uBAAuB,GACzB,CAAC,IACD,SAAS,YACP,OAAO,SAAS,OAAO,KAAK,CAAC,EAAE,eAAe,IAC9C,KAAK,UAAU,KAAK;AAClC;;;;AAKA,SAAgB,cAA2B,QAAgC;CACzE,IAAI,CAAC,QACH,OAAO;CAGT,IAAI,YAAY,OAAO,IAAI,GAGzB,OAFc,oCAAoC,KAAK,OAAO,IAEnD,IAAI,MAAM,OAAO;CAG9B,MAAM,cAAc,qBAAqB,MAAM;CAC/C,IAAI,aAAa;EACf,IAAI,gBAAgB,aAAa,gBAAgB,UAC/C,OAAO;EAGT,OAAO;CACT;CAEA,IAAI,OAAO,SAAS,WAAW,MAAM,QAAQ,OAAO,IAAI,GACtD,OAAO,OAAO,KAAK,KAAI,UAAS,KAAK,UAAU,KAAK,CAAC,EAAE,KAAK,KAAK;CAGnE,IAAI,OAAO,UAAU,QACnB,OAAO,KAAK,UAAU,OAAO,KAAK;CAGpC,IAAI,OAAO,SAAS,WAAW,OAAO,OAGpC,OAAO,GAAG,cAFI,MAAM,QAAQ,OAAO,KAAK,IAAI,OAAO,MAAM,KAAK,OAAO,KAExC,EAAE;CAGjC,IACE,OAAO,SAAS,YAChB,OAAO,cACP,OAAO,sBACP;EACA,IAAI,aAAa,OAAO,oBAAoB,GAC1C,OAAO,oBAAoB,cAAc,OAAO,oBAAoB,EAAE;EAGxE,IAAI,mBAAmB,MAAM,GAC3B,OAAO,KAAK,kBAAkB,MAAyC,EACpE,KAAI,aAAY;GACf,MAAM,SACJ,OAAO,UAAU,SAAS,SAAS,IAAI,KAAK,SAAS,WACjD,GAAG,SAAS,WAAW,MAAM,KAAK,SAAS,WAAW,YAAY,OAClE;GAEN,OAAO,GAAG,SAAS,OAAO,OAAO,IAAI,cAAc,QAAQ;EAC7D,CAAC,EACA,KAAK,KAAK,EAAE;CAEnB;CAEA,IAAI,OAAO,SAAS,OAAO,OACzB,QAAS,OAAO,SAAS,OAAO,SAAS,CAAC,GACvC,KAAI,WAAU,cAAc,MAAM,CAAC,EACnC,KAAK,KAAK;CAGf,IAAI,OAAO,OACT,OAAO;CAGT,OAAO;AACT;;;;AAKA,eAAsB,aACpB,SACA,cACA;CAGA,OAAO,eAFK,aAAa,OAED,GAAG,YAAY;AACzC;;;;;;;AAQA,SAAgB,iBAAiB,QAA8B;CAC7D,OAAO,iBAAiB,MAAM;AAChC"}
|
package/dist/constants.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
1
|
|
|
3
2
|
//#region src/constants.ts
|
|
4
3
|
const JsonSchemaTypes = {
|
|
@@ -25,7 +24,6 @@ const JSON_SCHEMA_METADATA_KEYS = [
|
|
|
25
24
|
"title",
|
|
26
25
|
"description",
|
|
27
26
|
"examples",
|
|
28
|
-
"visibility",
|
|
29
27
|
"hidden",
|
|
30
28
|
"ignore",
|
|
31
29
|
"internal",
|
package/dist/constants.d.cts
CHANGED
|
@@ -9,7 +9,7 @@ declare const JsonSchemaTypes: {
|
|
|
9
9
|
readonly ARRAY: "array";
|
|
10
10
|
};
|
|
11
11
|
declare const JSON_SCHEMA_DATA_TYPES: readonly ["string", "number", "integer", "boolean", "array", "object", "null"];
|
|
12
|
-
declare const JSON_SCHEMA_METADATA_KEYS: ("title" | "description" | "docs" | "examples" | "alias" | "tags" | "
|
|
12
|
+
declare const JSON_SCHEMA_METADATA_KEYS: ("title" | "description" | "docs" | "examples" | "alias" | "tags" | "deprecated" | "hidden" | "ignore" | "internal" | "runtime" | "readOnly" | "writeOnly")[];
|
|
13
13
|
//#endregion
|
|
14
14
|
export { JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchemaTypes };
|
|
15
15
|
//# sourceMappingURL=constants.d.cts.map
|
package/dist/constants.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ declare const JsonSchemaTypes: {
|
|
|
9
9
|
readonly ARRAY: "array";
|
|
10
10
|
};
|
|
11
11
|
declare const JSON_SCHEMA_DATA_TYPES: readonly ["string", "number", "integer", "boolean", "array", "object", "null"];
|
|
12
|
-
declare const JSON_SCHEMA_METADATA_KEYS: ("title" | "description" | "docs" | "examples" | "alias" | "tags" | "
|
|
12
|
+
declare const JSON_SCHEMA_METADATA_KEYS: ("title" | "description" | "docs" | "examples" | "alias" | "tags" | "deprecated" | "hidden" | "ignore" | "internal" | "runtime" | "readOnly" | "writeOnly")[];
|
|
13
13
|
//#endregion
|
|
14
14
|
export { JSON_SCHEMA_DATA_TYPES, JSON_SCHEMA_METADATA_KEYS, JsonSchemaTypes };
|
|
15
15
|
//# sourceMappingURL=constants.d.mts.map
|
package/dist/constants.mjs
CHANGED
package/dist/constants.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { SchemaMetadata } from \"./types\";\n\nexport const JsonSchemaTypes = {\n STRING: \"string\",\n NUMBER: \"number\",\n INTEGER: \"integer\",\n BOOLEAN: \"boolean\",\n NULL: \"null\",\n OBJECT: \"object\",\n ARRAY: \"array\"\n} as const;\n\nexport const JSON_SCHEMA_DATA_TYPES = [\n JsonSchemaTypes.STRING,\n JsonSchemaTypes.NUMBER,\n JsonSchemaTypes.INTEGER,\n JsonSchemaTypes.BOOLEAN,\n JsonSchemaTypes.ARRAY,\n JsonSchemaTypes.OBJECT,\n JsonSchemaTypes.NULL\n] as const;\n\nexport const JSON_SCHEMA_METADATA_KEYS = [\n \"docs\",\n \"deprecated\",\n \"title\",\n \"description\",\n \"examples\",\n \"
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { SchemaMetadata } from \"./types\";\n\nexport const JsonSchemaTypes = {\n STRING: \"string\",\n NUMBER: \"number\",\n INTEGER: \"integer\",\n BOOLEAN: \"boolean\",\n NULL: \"null\",\n OBJECT: \"object\",\n ARRAY: \"array\"\n} as const;\n\nexport const JSON_SCHEMA_DATA_TYPES = [\n JsonSchemaTypes.STRING,\n JsonSchemaTypes.NUMBER,\n JsonSchemaTypes.INTEGER,\n JsonSchemaTypes.BOOLEAN,\n JsonSchemaTypes.ARRAY,\n JsonSchemaTypes.OBJECT,\n JsonSchemaTypes.NULL\n] as const;\n\nexport const JSON_SCHEMA_METADATA_KEYS = [\n \"docs\",\n \"deprecated\",\n \"title\",\n \"description\",\n \"examples\",\n \"hidden\",\n \"ignore\",\n \"internal\",\n \"runtime\",\n \"readOnly\",\n \"writeOnly\",\n \"alias\",\n \"tags\"\n] satisfies ReadonlyArray<keyof SchemaMetadata>;\n"],"mappings":";AAoBA,MAAa,kBAAkB;CAC7B,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,SAAS;CACT,MAAM;CACN,QAAQ;CACR,OAAO;AACT;AAEA,MAAa,yBAAyB;CACpC,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;AAClB;AAEA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
package/dist/extract.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
1
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
const require_type_checks = require('./type-checks.cjs');
|
|
4
3
|
const require_persistence = require('./persistence.cjs');
|
|
@@ -15,6 +14,7 @@ let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type")
|
|
|
15
14
|
let _stryke_hash = require("@stryke/hash");
|
|
16
15
|
let _stryke_path_join = require("@stryke/path/join");
|
|
17
16
|
let _stryke_zod = require("@stryke/zod");
|
|
17
|
+
let _valibot_to_json_schema = require("@valibot/to-json-schema");
|
|
18
18
|
|
|
19
19
|
//#region src/extract.ts
|
|
20
20
|
function convertNestedUntypedSchema(value) {
|
|
@@ -30,6 +30,9 @@ function convertNestedUntypedSchemaArray(value) {
|
|
|
30
30
|
if (!Array.isArray(value)) return value;
|
|
31
31
|
return value.map((item) => convertNestedUntypedSchema(item));
|
|
32
32
|
}
|
|
33
|
+
function convertValibotSchemaToJsonSchema(schema) {
|
|
34
|
+
return (0, _valibot_to_json_schema.toJsonSchema)(schema, { target: "draft-07" });
|
|
35
|
+
}
|
|
33
36
|
function convertUntypedSchemaToJsonSchema(schema) {
|
|
34
37
|
const source = schema;
|
|
35
38
|
const jsonSchema = {};
|
|
@@ -77,6 +80,7 @@ function convertUntypedInputToJsonSchema(input) {
|
|
|
77
80
|
}
|
|
78
81
|
if (require_type_checks.isUntypedSchema(value)) properties[key] = convertUntypedSchemaToJsonSchema(value);
|
|
79
82
|
}
|
|
83
|
+
if (!require_type_checks.isJsonSchemaObject(base)) throw new Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);
|
|
80
84
|
const mergedProperties = {
|
|
81
85
|
...(0, _stryke_type_checks_is_set_object.isSetObject)(base.properties) ? base.properties : {},
|
|
82
86
|
...properties
|
|
@@ -108,6 +112,10 @@ function extractHash(variant, input) {
|
|
|
108
112
|
variant,
|
|
109
113
|
input
|
|
110
114
|
});
|
|
115
|
+
else if (require_type_checks.isValibotSchema(input)) return (0, _stryke_hash.murmurhash)({
|
|
116
|
+
variant,
|
|
117
|
+
input: convertValibotSchemaToJsonSchema(input)
|
|
118
|
+
});
|
|
111
119
|
else if (require_type_checks.isUntypedInput(input)) return (0, _stryke_hash.murmurhash)({
|
|
112
120
|
variant,
|
|
113
121
|
input: convertUntypedInputToJsonSchema(input)
|
|
@@ -121,7 +129,7 @@ function extractHash(variant, input) {
|
|
|
121
129
|
input: (0, _powerlines_deepkit_vendor_type.stringifyType)(input)
|
|
122
130
|
});
|
|
123
131
|
}
|
|
124
|
-
throw new Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object.`);
|
|
132
|
+
throw new Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`);
|
|
125
133
|
}
|
|
126
134
|
/**
|
|
127
135
|
* Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-07) representation.
|
|
@@ -131,15 +139,16 @@ function extractReflection(reflection) {
|
|
|
131
139
|
return require_reflection.reflectionToJsonSchema(reflection);
|
|
132
140
|
}
|
|
133
141
|
/**
|
|
134
|
-
* Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
|
|
142
|
+
* Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
|
|
135
143
|
*/
|
|
136
144
|
function extractJsonSchema(schema) {
|
|
137
|
-
if ((0, _stryke_type_checks_is_set_object.isSetObject)(schema)
|
|
145
|
+
if ((0, _stryke_type_checks_is_set_object.isSetObject)(schema)) {
|
|
138
146
|
if ((0, _stryke_zod.isZod3Type)(schema)) return (0, _stryke_zod.extractJsonSchema)(schema);
|
|
139
147
|
if ((0, _stryke_json.isStandardJsonSchema)(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
|
|
148
|
+
if (require_type_checks.isValibotSchema(schema)) return convertValibotSchemaToJsonSchema(schema);
|
|
140
149
|
if (require_type_checks.isUntypedInput(schema)) return convertUntypedInputToJsonSchema(schema);
|
|
141
150
|
if (require_type_checks.isUntypedSchema(schema)) return convertUntypedSchemaToJsonSchema(schema);
|
|
142
|
-
return schema;
|
|
151
|
+
if (require_type_checks.isJsonSchema(schema)) return schema;
|
|
143
152
|
}
|
|
144
153
|
}
|
|
145
154
|
function extractResolvedVariant(input) {
|
|
@@ -147,10 +156,11 @@ function extractResolvedVariant(input) {
|
|
|
147
156
|
if ((0, _stryke_zod.isZod3Type)(input)) return "zod3";
|
|
148
157
|
else if ((0, _stryke_json.isStandardJsonSchema)(input)) return "standard-schema";
|
|
149
158
|
else if (require_type_checks.isJsonSchema(input)) return "json-schema";
|
|
159
|
+
else if (require_type_checks.isValibotSchema(input)) return "valibot";
|
|
150
160
|
else if ((0, _powerlines_deepkit_vendor_type.isType)(input)) return "reflection";
|
|
151
161
|
else if (require_type_checks.isUntypedInput(input) || require_type_checks.isUntypedSchema(input)) return "untyped";
|
|
152
162
|
}
|
|
153
|
-
throw new Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema.`);
|
|
163
|
+
throw new Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`);
|
|
154
164
|
}
|
|
155
165
|
function extractVariant(input) {
|
|
156
166
|
if ((0, _stryke_type_checks.isSetString)(input) || (0, _powerlines_core.isTypeDefinition)(input)) return "type-definition";
|
|
@@ -160,10 +170,10 @@ async function extractSchemaSchema(input, variant) {
|
|
|
160
170
|
if (require_type_checks.isExtractedSchema(input)) return input.schema;
|
|
161
171
|
const resolvedVariant = variant ?? extractResolvedVariant(input);
|
|
162
172
|
let schema;
|
|
163
|
-
if (resolvedVariant === "zod3" || resolvedVariant === "json-schema" || resolvedVariant === "standard-schema" || resolvedVariant === "untyped") schema = extractJsonSchema(input);
|
|
173
|
+
if (resolvedVariant === "zod3" || resolvedVariant === "json-schema" || resolvedVariant === "standard-schema" || resolvedVariant === "untyped" || resolvedVariant === "valibot") schema = extractJsonSchema(input);
|
|
164
174
|
else if (resolvedVariant === "reflection") schema = extractReflection(input);
|
|
165
175
|
if (schema) return schema;
|
|
166
|
-
throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);
|
|
176
|
+
throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`);
|
|
167
177
|
}
|
|
168
178
|
function extractSource(variant, input) {
|
|
169
179
|
if (variant === "zod3") return {
|
|
@@ -186,6 +196,11 @@ function extractSource(variant, input) {
|
|
|
186
196
|
variant: "json-schema",
|
|
187
197
|
schema: input
|
|
188
198
|
};
|
|
199
|
+
else if (variant === "valibot") return {
|
|
200
|
+
hash: extractHash(variant, input),
|
|
201
|
+
variant: "valibot",
|
|
202
|
+
schema: input
|
|
203
|
+
};
|
|
189
204
|
else if (variant === "reflection") return {
|
|
190
205
|
hash: extractHash(variant, input),
|
|
191
206
|
variant: "reflection",
|
|
@@ -309,6 +324,5 @@ exports.extractJsonSchema = extractJsonSchema;
|
|
|
309
324
|
exports.extractReflection = extractReflection;
|
|
310
325
|
exports.extractResolvedVariant = extractResolvedVariant;
|
|
311
326
|
exports.extractSchema = extractSchema;
|
|
312
|
-
exports.extractSchemaSchema = extractSchemaSchema;
|
|
313
327
|
exports.extractSource = extractSource;
|
|
314
328
|
exports.extractVariant = extractVariant;
|
package/dist/extract.d.cts
CHANGED
|
@@ -13,12 +13,11 @@ declare function extractHash<T = unknown>(variant: SchemaInputVariant, input: Sc
|
|
|
13
13
|
*/
|
|
14
14
|
declare function extractReflection<T = unknown>(reflection: Type): JsonSchema<T> | undefined;
|
|
15
15
|
/**
|
|
16
|
-
* Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
|
|
16
|
+
* Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
|
|
17
17
|
*/
|
|
18
18
|
declare function extractJsonSchema<T = unknown>(schema: unknown): JsonSchema<T> | undefined;
|
|
19
19
|
declare function extractResolvedVariant(input: SchemaSourceInput): SchemaSourceVariant;
|
|
20
20
|
declare function extractVariant<T = unknown>(input: SchemaInput<T>): SchemaInputVariant;
|
|
21
|
-
declare function extractSchemaSchema<T = unknown>(input: SchemaSourceInput, variant?: SchemaInputVariant): Promise<JsonSchema<T>>;
|
|
22
21
|
declare function extractSource(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource;
|
|
23
22
|
/**
|
|
24
23
|
* Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.
|
|
@@ -78,5 +77,5 @@ declare function extractSchema<T = unknown>(context: Context, input: SchemaInput
|
|
|
78
77
|
*/
|
|
79
78
|
declare function extract<T = unknown>(context: Context, input: SchemaInput, options?: Partial<BuildOptions>): Promise<Schema<T>>;
|
|
80
79
|
//#endregion
|
|
81
|
-
export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema,
|
|
80
|
+
export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant };
|
|
82
81
|
//# sourceMappingURL=extract.d.cts.map
|
package/dist/extract.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"extract.d.cts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AAqOA;iBAAgB,WAAA,aAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA;;;;iBAuCL,iBAAA,aAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAA,CAAW,CAAA;;;;iBAWE,iBAAA,aAAA,CACd,MAAA,YACC,UAAU,CAAC,CAAA;AAAA,iBA2BE,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAmB;AAAA,iBAsBN,cAAA,aAAA,CACd,KAAA,EAAO,WAAA,CAAY,CAAA,IAClB,kBAAA;AAAA,iBAwCa,aAAA,CACd,OAAA,EAAS,mBAAA,EACT,KAAA,EAAO,iBAAA,GACN,YAAA;;;AAtJoB;AAuCvB;;;;;;;;;;;;;;AAEe;AAWf;;;;;;;;iBAwKsB,aAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,eAAA,CAAgB,CAAA;AA1KZ;AA2Bf;;;;;;;;AAEsB;AAsBtB;;;;;;;;;;;;;;AAEqB;AAwCrB;;;;AA7Fe,iBAqQO,OAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,MAAA,CAAO,CAAA"}
|
package/dist/extract.d.mts
CHANGED
|
@@ -13,12 +13,11 @@ declare function extractHash<T = unknown>(variant: SchemaInputVariant, input: Sc
|
|
|
13
13
|
*/
|
|
14
14
|
declare function extractReflection<T = unknown>(reflection: Type): JsonSchema<T> | undefined;
|
|
15
15
|
/**
|
|
16
|
-
* Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
|
|
16
|
+
* Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
|
|
17
17
|
*/
|
|
18
18
|
declare function extractJsonSchema<T = unknown>(schema: unknown): JsonSchema<T> | undefined;
|
|
19
19
|
declare function extractResolvedVariant(input: SchemaSourceInput): SchemaSourceVariant;
|
|
20
20
|
declare function extractVariant<T = unknown>(input: SchemaInput<T>): SchemaInputVariant;
|
|
21
|
-
declare function extractSchemaSchema<T = unknown>(input: SchemaSourceInput, variant?: SchemaInputVariant): Promise<JsonSchema<T>>;
|
|
22
21
|
declare function extractSource(variant: SchemaSourceVariant, input: SchemaSourceInput): SchemaSource;
|
|
23
22
|
/**
|
|
24
23
|
* Extracts a JSON Schema from a given schema definition input, which can be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object. If the input is a type definition reference (e.g. a file path with an export), it will be resolved and bundled using ESBuild to obtain the actual schema definition before extraction.
|
|
@@ -78,5 +77,5 @@ declare function extractSchema<T = unknown>(context: Context, input: SchemaInput
|
|
|
78
77
|
*/
|
|
79
78
|
declare function extract<T = unknown>(context: Context, input: SchemaInput, options?: Partial<BuildOptions>): Promise<Schema<T>>;
|
|
80
79
|
//#endregion
|
|
81
|
-
export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema,
|
|
80
|
+
export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant };
|
|
82
81
|
//# sourceMappingURL=extract.d.mts.map
|
package/dist/extract.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"extract.d.mts","names":[],"sources":["../src/extract.ts"],"mappings":";;;;;;;;AAqOA;iBAAgB,WAAA,aAAA,CACd,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,WAAA,CAAY,CAAA;;;;iBAuCL,iBAAA,aAAA,CACd,UAAA,EAAY,IAAA,GACX,UAAA,CAAW,CAAA;;;;iBAWE,iBAAA,aAAA,CACd,MAAA,YACC,UAAU,CAAC,CAAA;AAAA,iBA2BE,sBAAA,CACd,KAAA,EAAO,iBAAA,GACN,mBAAmB;AAAA,iBAsBN,cAAA,aAAA,CACd,KAAA,EAAO,WAAA,CAAY,CAAA,IAClB,kBAAA;AAAA,iBAwCa,aAAA,CACd,OAAA,EAAS,mBAAA,EACT,KAAA,EAAO,iBAAA,GACN,YAAA;;;AAtJoB;AAuCvB;;;;;;;;;;;;;;AAEe;AAWf;;;;;;;;iBAwKsB,aAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,eAAA,CAAgB,CAAA;AA1KZ;AA2Bf;;;;;;;;AAEsB;AAsBtB;;;;;;;;;;;;;;AAEqB;AAwCrB;;;;AA7Fe,iBAqQO,OAAA,aAAA,CACpB,OAAA,EAAS,OAAA,EACT,KAAA,EAAO,WAAA,EACP,OAAA,GAAS,OAAA,CAAQ,YAAA,IAChB,OAAA,CAAQ,MAAA,CAAO,CAAA"}
|
package/dist/extract.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isExtractedSchema, isJsonSchema, isSchema, isUntypedInput, isUntypedSchema } from "./type-checks.mjs";
|
|
1
|
+
import { isExtractedSchema, isJsonSchema, isJsonSchemaObject, isSchema, isUntypedInput, isUntypedSchema, isValibotSchema } from "./type-checks.mjs";
|
|
2
2
|
import { getCacheDirectory, writeSchema } from "./persistence.mjs";
|
|
3
3
|
import { reflectionToJsonSchema } from "./reflection.mjs";
|
|
4
4
|
import { resolve } from "./resolve.mjs";
|
|
@@ -11,7 +11,8 @@ import { rolldownPlugin } from "@powerlines/deepkit/rolldown-plugin";
|
|
|
11
11
|
import { isType, stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
12
12
|
import { murmurhash } from "@stryke/hash";
|
|
13
13
|
import { joinPaths } from "@stryke/path/join";
|
|
14
|
-
import { extractJsonSchema
|
|
14
|
+
import { extractJsonSchema, isZod3Type } from "@stryke/zod";
|
|
15
|
+
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
15
16
|
|
|
16
17
|
//#region src/extract.ts
|
|
17
18
|
function convertNestedUntypedSchema(value) {
|
|
@@ -27,6 +28,9 @@ function convertNestedUntypedSchemaArray(value) {
|
|
|
27
28
|
if (!Array.isArray(value)) return value;
|
|
28
29
|
return value.map((item) => convertNestedUntypedSchema(item));
|
|
29
30
|
}
|
|
31
|
+
function convertValibotSchemaToJsonSchema(schema) {
|
|
32
|
+
return toJsonSchema(schema, { target: "draft-07" });
|
|
33
|
+
}
|
|
30
34
|
function convertUntypedSchemaToJsonSchema(schema) {
|
|
31
35
|
const source = schema;
|
|
32
36
|
const jsonSchema = {};
|
|
@@ -74,6 +78,7 @@ function convertUntypedInputToJsonSchema(input) {
|
|
|
74
78
|
}
|
|
75
79
|
if (isUntypedSchema(value)) properties[key] = convertUntypedSchemaToJsonSchema(value);
|
|
76
80
|
}
|
|
81
|
+
if (!isJsonSchemaObject(base)) throw new Error(`Failed to convert untyped input to JSON Schema. The base schema must be a valid JSON Schema object.`);
|
|
77
82
|
const mergedProperties = {
|
|
78
83
|
...isSetObject$1(base.properties) ? base.properties : {},
|
|
79
84
|
...properties
|
|
@@ -105,6 +110,10 @@ function extractHash(variant, input) {
|
|
|
105
110
|
variant,
|
|
106
111
|
input
|
|
107
112
|
});
|
|
113
|
+
else if (isValibotSchema(input)) return murmurhash({
|
|
114
|
+
variant,
|
|
115
|
+
input: convertValibotSchemaToJsonSchema(input)
|
|
116
|
+
});
|
|
108
117
|
else if (isUntypedInput(input)) return murmurhash({
|
|
109
118
|
variant,
|
|
110
119
|
input: convertUntypedInputToJsonSchema(input)
|
|
@@ -118,7 +127,7 @@ function extractHash(variant, input) {
|
|
|
118
127
|
input: stringifyType(input)
|
|
119
128
|
});
|
|
120
129
|
}
|
|
121
|
-
throw new Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, or a reflected Deepkit Type object.`);
|
|
130
|
+
throw new Error(`Failed to create an input hash for the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, or a reflected Deepkit Type object.`);
|
|
122
131
|
}
|
|
123
132
|
/**
|
|
124
133
|
* Converts a reflected Deepkit {@link Type} into a JSON Schema (draft-07) representation.
|
|
@@ -128,15 +137,16 @@ function extractReflection(reflection) {
|
|
|
128
137
|
return reflectionToJsonSchema(reflection);
|
|
129
138
|
}
|
|
130
139
|
/**
|
|
131
|
-
* Extracts a JSON Schema from Zod, Standard Schema, untyped, or JSON Schema inputs.
|
|
140
|
+
* Extracts a JSON Schema from Zod, Standard Schema, Valibot, untyped, or JSON Schema inputs.
|
|
132
141
|
*/
|
|
133
|
-
function extractJsonSchema(schema) {
|
|
134
|
-
if (isSetObject$1(schema)
|
|
135
|
-
if (isZod3Type(schema)) return extractJsonSchema
|
|
142
|
+
function extractJsonSchema$1(schema) {
|
|
143
|
+
if (isSetObject$1(schema)) {
|
|
144
|
+
if (isZod3Type(schema)) return extractJsonSchema(schema);
|
|
136
145
|
if (isStandardJsonSchema(schema)) return schema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
|
|
146
|
+
if (isValibotSchema(schema)) return convertValibotSchemaToJsonSchema(schema);
|
|
137
147
|
if (isUntypedInput(schema)) return convertUntypedInputToJsonSchema(schema);
|
|
138
148
|
if (isUntypedSchema(schema)) return convertUntypedSchemaToJsonSchema(schema);
|
|
139
|
-
return schema;
|
|
149
|
+
if (isJsonSchema(schema)) return schema;
|
|
140
150
|
}
|
|
141
151
|
}
|
|
142
152
|
function extractResolvedVariant(input) {
|
|
@@ -144,10 +154,11 @@ function extractResolvedVariant(input) {
|
|
|
144
154
|
if (isZod3Type(input)) return "zod3";
|
|
145
155
|
else if (isStandardJsonSchema(input)) return "standard-schema";
|
|
146
156
|
else if (isJsonSchema(input)) return "json-schema";
|
|
157
|
+
else if (isValibotSchema(input)) return "valibot";
|
|
147
158
|
else if (isType(input)) return "reflection";
|
|
148
159
|
else if (isUntypedInput(input) || isUntypedSchema(input)) return "untyped";
|
|
149
160
|
}
|
|
150
|
-
throw new Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a reflected Deepkit Type object, or an Untyped schema.`);
|
|
161
|
+
throw new Error(`Failed to determine the variant of the provided schema definition input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, a reflected Deepkit Type object, or an Untyped schema.`);
|
|
151
162
|
}
|
|
152
163
|
function extractVariant(input) {
|
|
153
164
|
if (isSetString(input) || isTypeDefinition(input)) return "type-definition";
|
|
@@ -157,10 +168,10 @@ async function extractSchemaSchema(input, variant) {
|
|
|
157
168
|
if (isExtractedSchema(input)) return input.schema;
|
|
158
169
|
const resolvedVariant = variant ?? extractResolvedVariant(input);
|
|
159
170
|
let schema;
|
|
160
|
-
if (resolvedVariant === "zod3" || resolvedVariant === "json-schema" || resolvedVariant === "standard-schema" || resolvedVariant === "untyped") schema = extractJsonSchema(input);
|
|
171
|
+
if (resolvedVariant === "zod3" || resolvedVariant === "json-schema" || resolvedVariant === "standard-schema" || resolvedVariant === "untyped" || resolvedVariant === "valibot") schema = extractJsonSchema$1(input);
|
|
161
172
|
else if (resolvedVariant === "reflection") schema = extractReflection(input);
|
|
162
173
|
if (schema) return schema;
|
|
163
|
-
throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);
|
|
174
|
+
throw new Error(`Failed to extract a valid schema from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, a Valibot BaseSchema, an untyped schema, or a reflected Deepkit Type object.`);
|
|
164
175
|
}
|
|
165
176
|
function extractSource(variant, input) {
|
|
166
177
|
if (variant === "zod3") return {
|
|
@@ -183,6 +194,11 @@ function extractSource(variant, input) {
|
|
|
183
194
|
variant: "json-schema",
|
|
184
195
|
schema: input
|
|
185
196
|
};
|
|
197
|
+
else if (variant === "valibot") return {
|
|
198
|
+
hash: extractHash(variant, input),
|
|
199
|
+
variant: "valibot",
|
|
200
|
+
schema: input
|
|
201
|
+
};
|
|
186
202
|
else if (variant === "reflection") return {
|
|
187
203
|
hash: extractHash(variant, input),
|
|
188
204
|
variant: "reflection",
|
|
@@ -300,5 +316,5 @@ async function extract(context, input, options = {}) {
|
|
|
300
316
|
}
|
|
301
317
|
|
|
302
318
|
//#endregion
|
|
303
|
-
export { extract, extractHash, extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema,
|
|
319
|
+
export { extract, extractHash, extractJsonSchema$1 as extractJsonSchema, extractReflection, extractResolvedVariant, extractSchema, extractSource, extractVariant };
|
|
304
320
|
//# sourceMappingURL=extract.mjs.map
|