@stryke/zod 0.1.0 → 0.2.0
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/CHANGELOG.md +23 -0
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -3
- package/dist/is-zod-type-B-jL80F-.mjs +197 -0
- package/dist/is-zod-type-B-jL80F-.mjs.map +1 -0
- package/dist/is-zod-type-CDtbhw8L.d.mts +30 -0
- package/dist/is-zod-type-CDtbhw8L.d.mts.map +1 -0
- package/dist/is-zod-type-RGE-O0aK.cjs +214 -0
- package/dist/is-zod-type-x0dit7lA.d.cts +30 -0
- package/dist/is-zod-type-x0dit7lA.d.cts.map +1 -0
- package/dist/is-zod-type.cjs +4 -34
- package/dist/is-zod-type.d.cts +2 -30
- package/dist/is-zod-type.d.mts +3 -30
- package/dist/is-zod-type.mjs +2 -33
- package/dist/schema-B6usLZOz.mjs +44 -0
- package/dist/schema-B6usLZOz.mjs.map +1 -0
- package/dist/schema-DQPkBDAQ.d.mts +32 -0
- package/dist/schema-DQPkBDAQ.d.mts.map +1 -0
- package/dist/schema-s8jVY_-l.d.cts +32 -0
- package/dist/schema-s8jVY_-l.d.cts.map +1 -0
- package/dist/schema-wGX9lE9h.cjs +82 -0
- package/dist/schema.cjs +3 -32
- package/dist/schema.d.cts +2 -22
- package/dist/schema.d.mts +3 -22
- package/dist/schema.mjs +2 -31
- package/dist/types-4nTrnOUu.d.cts +20 -0
- package/dist/types-4nTrnOUu.d.cts.map +1 -0
- package/dist/types-UlEWkGXF.d.mts +20 -0
- package/dist/types-UlEWkGXF.d.mts.map +1 -0
- package/dist/types.d.cts +2 -20
- package/dist/types.d.mts +2 -20
- package/dist/types.mjs +0 -1
- package/package.json +50 -8
- package/dist/_virtual/rolldown_runtime.cjs +0 -29
- package/dist/is-zod-type.d.cts.map +0 -1
- package/dist/is-zod-type.d.mts.map +0 -1
- package/dist/is-zod-type.mjs.map +0 -1
- package/dist/schema.d.cts.map +0 -1
- package/dist/schema.d.mts.map +0 -1
- package/dist/schema.mjs.map +0 -1
- package/dist/type-checks/src/get-object-tag.cjs +0 -15
- package/dist/type-checks/src/get-object-tag.mjs +0 -15
- package/dist/type-checks/src/get-object-tag.mjs.map +0 -1
- package/dist/type-checks/src/is-empty.cjs +0 -20
- package/dist/type-checks/src/is-empty.mjs +0 -21
- package/dist/type-checks/src/is-empty.mjs.map +0 -1
- package/dist/type-checks/src/is-non-null-object.cjs +0 -16
- package/dist/type-checks/src/is-non-null-object.mjs +0 -17
- package/dist/type-checks/src/is-non-null-object.mjs.map +0 -1
- package/dist/type-checks/src/is-null.cjs +0 -12
- package/dist/type-checks/src/is-null.mjs +0 -12
- package/dist/type-checks/src/is-null.mjs.map +0 -1
- package/dist/type-checks/src/is-object.cjs +0 -19
- package/dist/type-checks/src/is-object.mjs +0 -20
- package/dist/type-checks/src/is-object.mjs.map +0 -1
- package/dist/type-checks/src/is-plain-object.cjs +0 -63
- package/dist/type-checks/src/is-plain-object.mjs +0 -64
- package/dist/type-checks/src/is-plain-object.mjs.map +0 -1
- package/dist/type-checks/src/is-set-object.cjs +0 -19
- package/dist/type-checks/src/is-set-object.mjs +0 -20
- package/dist/type-checks/src/is-set-object.mjs.map +0 -1
- package/dist/type-checks/src/is-set.cjs +0 -19
- package/dist/type-checks/src/is-set.mjs +0 -20
- package/dist/type-checks/src/is-set.mjs.map +0 -1
- package/dist/type-checks/src/is-undefined.cjs +0 -8
- package/dist/type-checks/src/is-undefined.mjs +0 -8
- package/dist/type-checks/src/is-undefined.mjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
package/dist/is-zod-type.d.mts
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
//#region src/is-zod-type.d.ts
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Type guard to check if a given value is a Zod schema of version 3.
|
|
9
|
-
*
|
|
10
|
-
* @param type - The value to check.
|
|
11
|
-
* @returns True if the value is a Zod schema, false otherwise.
|
|
12
|
-
*/
|
|
13
|
-
declare function isZod3Type(type: unknown): type is z3.ZodTypeAny;
|
|
14
|
-
/**
|
|
15
|
-
* Type guard to check if a given value is a Zod schema of version 4.
|
|
16
|
-
*
|
|
17
|
-
* @param type - The value to check.
|
|
18
|
-
* @returns True if the value is a Zod v4 schema, false otherwise.
|
|
19
|
-
*/
|
|
20
|
-
declare function isZod4Type(type: unknown): type is z4.$ZodType;
|
|
21
|
-
/**
|
|
22
|
-
* Type guard to check if a given value is a Zod schema of either version 3 or 4.
|
|
23
|
-
*
|
|
24
|
-
* @param type - The value to check.
|
|
25
|
-
* @returns True if the value is a Zod schema, false otherwise.
|
|
26
|
-
*/
|
|
27
|
-
declare function isZodType(type: unknown): type is ZodType;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { isZod3Type, isZod4Type, isZodType };
|
|
30
|
-
//# sourceMappingURL=is-zod-type.d.mts.map
|
|
1
|
+
import "./types-UlEWkGXF.mjs";
|
|
2
|
+
import { n as isZod4Type, r as isZodType, t as isZod3Type } from "./is-zod-type-CDtbhw8L.mjs";
|
|
3
|
+
export { isZod3Type, isZod4Type, isZodType };
|
package/dist/is-zod-type.mjs
CHANGED
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as isZod4Type, r as isZodType, t as isZod3Type } from "./is-zod-type-B-jL80F-.mjs";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Type guard to check if a given value is a Zod schema of version 3.
|
|
6
|
-
*
|
|
7
|
-
* @param type - The value to check.
|
|
8
|
-
* @returns True if the value is a Zod schema, false otherwise.
|
|
9
|
-
*/
|
|
10
|
-
function isZod3Type(type) {
|
|
11
|
-
return isSetObject(type) && "_def" in type && "typeName" in type._def;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Type guard to check if a given value is a Zod schema of version 4.
|
|
15
|
-
*
|
|
16
|
-
* @param type - The value to check.
|
|
17
|
-
* @returns True if the value is a Zod v4 schema, false otherwise.
|
|
18
|
-
*/
|
|
19
|
-
function isZod4Type(type) {
|
|
20
|
-
return isSetObject(type) && "_zod" in type && "def" in type._zod;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Type guard to check if a given value is a Zod schema of either version 3 or 4.
|
|
24
|
-
*
|
|
25
|
-
* @param type - The value to check.
|
|
26
|
-
* @returns True if the value is a Zod schema, false otherwise.
|
|
27
|
-
*/
|
|
28
|
-
function isZodType(type) {
|
|
29
|
-
return isZod3Type(type) || isZod4Type(type);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
export { isZod3Type, isZod4Type, isZodType };
|
|
34
|
-
//# sourceMappingURL=is-zod-type.mjs.map
|
|
3
|
+
export { isZod3Type, isZod4Type, isZodType };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { n as isZod4Type, t as isZod3Type } from "./is-zod-type-B-jL80F-.mjs";
|
|
2
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
|
+
import * as z4 from "zod/v4/core";
|
|
4
|
+
|
|
5
|
+
//#region src/schema.ts
|
|
6
|
+
/**
|
|
7
|
+
* Extracts a JSON Schema from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
8
|
+
*
|
|
9
|
+
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
10
|
+
* @param target - The JSON Schema draft version to target. Defaults to "draft-07".
|
|
11
|
+
* @returns The extracted JSON Schema.
|
|
12
|
+
*/
|
|
13
|
+
function extractJsonSchema(type, target = "draft-07") {
|
|
14
|
+
if (isZod3Type(type)) {
|
|
15
|
+
const result = zodToJsonSchema(type, {
|
|
16
|
+
$refStrategy: "root",
|
|
17
|
+
definitionPath: "$defs",
|
|
18
|
+
target: target === "draft-07" ? "jsonSchema7" : "jsonSchema2019-09"
|
|
19
|
+
});
|
|
20
|
+
if (!result) throw new Error("Failed to extract JSON Schema from Zod v3 schema");
|
|
21
|
+
return result;
|
|
22
|
+
} else if (isZod4Type(type)) return z4.toJSONSchema(type, {
|
|
23
|
+
target: target === "draft-07" ? "draft-07" : "draft-2020-12",
|
|
24
|
+
unrepresentable: "any",
|
|
25
|
+
reused: "ref"
|
|
26
|
+
});
|
|
27
|
+
else throw new Error("Unsupported Zod schema version");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extracts a JSON Schema (draft-07) from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* This function is a convenience wrapper around `extractJsonSchema` that defaults to targeting the JSON Schema draft-07 specification.
|
|
34
|
+
*
|
|
35
|
+
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
36
|
+
* @returns The extracted JSON Schema.
|
|
37
|
+
*/
|
|
38
|
+
function extractJsonSchema7(type) {
|
|
39
|
+
return extractJsonSchema(type, "draft-07");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { extractJsonSchema7 as n, extractJsonSchema as t };
|
|
44
|
+
//# sourceMappingURL=schema-B6usLZOz.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-B6usLZOz.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { JsonSchema7Type } from \"zod-to-json-schema\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport * as z4 from \"zod/v4/core\";\nimport { isZod3Type, isZod4Type } from \"./is-zod-type\";\nimport type { ZodType } from \"./types\";\n\n/**\n * Extracts a JSON Schema from a given Zod schema, supporting both version 3 and version 4 of Zod.\n *\n * @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.\n * @param target - The JSON Schema draft version to target. Defaults to \"draft-07\".\n * @returns The extracted JSON Schema.\n */\nexport function extractJsonSchema(\n type: ZodType,\n target: \"draft-07\" | \"draft-2020-12\" = \"draft-07\"\n) {\n if (isZod3Type(type)) {\n const result = zodToJsonSchema(type, {\n $refStrategy: \"root\",\n definitionPath: \"$defs\",\n target: target === \"draft-07\" ? \"jsonSchema7\" : \"jsonSchema2019-09\"\n });\n if (!result) {\n throw new Error(\"Failed to extract JSON Schema from Zod v3 schema\");\n }\n\n return result;\n } else if (isZod4Type(type)) {\n return z4.toJSONSchema(type, {\n target: target === \"draft-07\" ? \"draft-07\" : \"draft-2020-12\",\n // eslint-disable-next-line @cspell/spellchecker\n unrepresentable: \"any\",\n reused: \"ref\"\n });\n } else {\n throw new Error(\"Unsupported Zod schema version\");\n }\n}\n\n/**\n * Extracts a JSON Schema (draft-07) from a given Zod schema, supporting both version 3 and version 4 of Zod.\n *\n * @remarks\n * This function is a convenience wrapper around `extractJsonSchema` that defaults to targeting the JSON Schema draft-07 specification.\n *\n * @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.\n * @returns The extracted JSON Schema.\n */\nexport function extractJsonSchema7(type: ZodType) {\n return extractJsonSchema(type, \"draft-07\") as JsonSchema7Type;\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,SAAgB,kBACd,MACA,SAAuC,YACvC;AACA,KAAI,WAAW,KAAK,EAAE;EACpB,MAAM,SAAS,gBAAgB,MAAM;GACnC,cAAc;GACd,gBAAgB;GAChB,QAAQ,WAAW,aAAa,gBAAgB;GACjD,CAAC;AACF,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,mDAAmD;AAGrE,SAAO;YACE,WAAW,KAAK,CACzB,QAAO,GAAG,aAAa,MAAM;EAC3B,QAAQ,WAAW,aAAa,aAAa;EAE7C,iBAAiB;EACjB,QAAQ;EACT,CAAC;KAEF,OAAM,IAAI,MAAM,iCAAiC;;;;;;;;;;;AAarD,SAAgB,mBAAmB,MAAe;AAChD,QAAO,kBAAkB,MAAM,WAAW"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { t as ZodType } from "./types-UlEWkGXF.mjs";
|
|
2
|
+
import { JsonSchema7Type } from "zod-to-json-schema";
|
|
3
|
+
import * as z4 from "zod/v4/core";
|
|
4
|
+
|
|
5
|
+
//#region src/schema.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Extracts a JSON Schema from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
9
|
+
*
|
|
10
|
+
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
11
|
+
* @param target - The JSON Schema draft version to target. Defaults to "draft-07".
|
|
12
|
+
* @returns The extracted JSON Schema.
|
|
13
|
+
*/
|
|
14
|
+
declare function extractJsonSchema(type: ZodType, target?: "draft-07" | "draft-2020-12"): (object & {
|
|
15
|
+
$schema?: string | undefined;
|
|
16
|
+
definitions?: {
|
|
17
|
+
[key: string]: JsonSchema7Type;
|
|
18
|
+
} | undefined;
|
|
19
|
+
}) | z4.ZodStandardJSONSchemaPayload<z4.$ZodType<unknown, unknown, z4.$ZodTypeInternals<unknown, unknown>>>;
|
|
20
|
+
/**
|
|
21
|
+
* Extracts a JSON Schema (draft-07) from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This function is a convenience wrapper around `extractJsonSchema` that defaults to targeting the JSON Schema draft-07 specification.
|
|
25
|
+
*
|
|
26
|
+
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
27
|
+
* @returns The extracted JSON Schema.
|
|
28
|
+
*/
|
|
29
|
+
declare function extractJsonSchema7(type: ZodType): JsonSchema7Type;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { extractJsonSchema7 as n, extractJsonSchema as t };
|
|
32
|
+
//# sourceMappingURL=schema-DQPkBDAQ.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-DQPkBDAQ.d.mts","names":[],"sources":["../src/schema.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA+BA;;;;;iBAAgB,iBAAA,OACR;;EAmCQ,WAAA,CAAA,EAAA;;;;;;;;;;;;;iBAAA,kBAAA,OAAyB,UACO"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { t as ZodType } from "./types-4nTrnOUu.cjs";
|
|
2
|
+
import * as z4 from "zod/v4/core";
|
|
3
|
+
import { JsonSchema7Type } from "zod-to-json-schema";
|
|
4
|
+
|
|
5
|
+
//#region src/schema.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Extracts a JSON Schema from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
9
|
+
*
|
|
10
|
+
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
11
|
+
* @param target - The JSON Schema draft version to target. Defaults to "draft-07".
|
|
12
|
+
* @returns The extracted JSON Schema.
|
|
13
|
+
*/
|
|
14
|
+
declare function extractJsonSchema(type: ZodType, target?: "draft-07" | "draft-2020-12"): (object & {
|
|
15
|
+
$schema?: string | undefined;
|
|
16
|
+
definitions?: {
|
|
17
|
+
[key: string]: JsonSchema7Type;
|
|
18
|
+
} | undefined;
|
|
19
|
+
}) | z4.ZodStandardJSONSchemaPayload<z4.$ZodType<unknown, unknown, z4.$ZodTypeInternals<unknown, unknown>>>;
|
|
20
|
+
/**
|
|
21
|
+
* Extracts a JSON Schema (draft-07) from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This function is a convenience wrapper around `extractJsonSchema` that defaults to targeting the JSON Schema draft-07 specification.
|
|
25
|
+
*
|
|
26
|
+
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
27
|
+
* @returns The extracted JSON Schema.
|
|
28
|
+
*/
|
|
29
|
+
declare function extractJsonSchema7(type: ZodType): JsonSchema7Type;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { extractJsonSchema7 as n, extractJsonSchema as t };
|
|
32
|
+
//# sourceMappingURL=schema-s8jVY_-l.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-s8jVY_-l.d.cts","names":[],"sources":["../src/schema.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA+BA;;;;;iBAAgB,iBAAA,OACR;;EAmCQ,WAAA,CAAA,EAAA;;;;;;;;;;;;;iBAAA,kBAAA,OAAyB,UACO"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
const require_is_zod_type = require('./is-zod-type-RGE-O0aK.cjs');
|
|
29
|
+
let zod_to_json_schema = require("zod-to-json-schema");
|
|
30
|
+
let zod_v4_core = require("zod/v4/core");
|
|
31
|
+
zod_v4_core = __toESM(zod_v4_core);
|
|
32
|
+
|
|
33
|
+
//#region src/schema.ts
|
|
34
|
+
/**
|
|
35
|
+
* Extracts a JSON Schema from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
36
|
+
*
|
|
37
|
+
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
38
|
+
* @param target - The JSON Schema draft version to target. Defaults to "draft-07".
|
|
39
|
+
* @returns The extracted JSON Schema.
|
|
40
|
+
*/
|
|
41
|
+
function extractJsonSchema(type, target = "draft-07") {
|
|
42
|
+
if (require_is_zod_type.isZod3Type(type)) {
|
|
43
|
+
const result = (0, zod_to_json_schema.zodToJsonSchema)(type, {
|
|
44
|
+
$refStrategy: "root",
|
|
45
|
+
definitionPath: "$defs",
|
|
46
|
+
target: target === "draft-07" ? "jsonSchema7" : "jsonSchema2019-09"
|
|
47
|
+
});
|
|
48
|
+
if (!result) throw new Error("Failed to extract JSON Schema from Zod v3 schema");
|
|
49
|
+
return result;
|
|
50
|
+
} else if (require_is_zod_type.isZod4Type(type)) return zod_v4_core.toJSONSchema(type, {
|
|
51
|
+
target: target === "draft-07" ? "draft-07" : "draft-2020-12",
|
|
52
|
+
unrepresentable: "any",
|
|
53
|
+
reused: "ref"
|
|
54
|
+
});
|
|
55
|
+
else throw new Error("Unsupported Zod schema version");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Extracts a JSON Schema (draft-07) from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* This function is a convenience wrapper around `extractJsonSchema` that defaults to targeting the JSON Schema draft-07 specification.
|
|
62
|
+
*
|
|
63
|
+
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
64
|
+
* @returns The extracted JSON Schema.
|
|
65
|
+
*/
|
|
66
|
+
function extractJsonSchema7(type) {
|
|
67
|
+
return extractJsonSchema(type, "draft-07");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
Object.defineProperty(exports, 'extractJsonSchema', {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function () {
|
|
74
|
+
return extractJsonSchema;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(exports, 'extractJsonSchema7', {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () {
|
|
80
|
+
return extractJsonSchema7;
|
|
81
|
+
}
|
|
82
|
+
});
|
package/dist/schema.cjs
CHANGED
|
@@ -1,33 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_is_zod_type = require('./is-zod-type.cjs');
|
|
3
|
-
let zod_to_json_schema = require("zod-to-json-schema");
|
|
4
|
-
let zod_v4_core = require("zod/v4/core");
|
|
5
|
-
zod_v4_core = require_rolldown_runtime.__toESM(zod_v4_core);
|
|
1
|
+
const require_schema = require('./schema-wGX9lE9h.cjs');
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Extracts a JSON Schema from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
10
|
-
*
|
|
11
|
-
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
12
|
-
* @param target - The JSON Schema draft version to target. Defaults to "draft-07".
|
|
13
|
-
* @returns The extracted JSON Schema.
|
|
14
|
-
*/
|
|
15
|
-
function extractJsonSchema(type, target = "draft-07") {
|
|
16
|
-
if (require_is_zod_type.isZod3Type(type)) {
|
|
17
|
-
const result = (0, zod_to_json_schema.zodToJsonSchema)(type, {
|
|
18
|
-
$refStrategy: "root",
|
|
19
|
-
definitionPath: "$defs",
|
|
20
|
-
target: target === "draft-07" ? "jsonSchema7" : "jsonSchema2019-09"
|
|
21
|
-
});
|
|
22
|
-
if (!result) throw new Error("Failed to extract JSON Schema from Zod v3 schema");
|
|
23
|
-
return result;
|
|
24
|
-
} else if (require_is_zod_type.isZod4Type(type)) return zod_v4_core.toJSONSchema(type, {
|
|
25
|
-
target: target === "draft-07" ? "draft-07" : "draft-2020-12",
|
|
26
|
-
unrepresentable: "any",
|
|
27
|
-
reused: "ref"
|
|
28
|
-
});
|
|
29
|
-
else throw new Error("Unsupported Zod schema version");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
exports.extractJsonSchema = extractJsonSchema;
|
|
3
|
+
exports.extractJsonSchema = require_schema.extractJsonSchema;
|
|
4
|
+
exports.extractJsonSchema7 = require_schema.extractJsonSchema7;
|
package/dist/schema.d.cts
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import * as zod_to_json_schema0 from "zod-to-json-schema";
|
|
4
|
-
|
|
5
|
-
//#region src/schema.d.ts
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Extracts a JSON Schema from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
9
|
-
*
|
|
10
|
-
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
11
|
-
* @param target - The JSON Schema draft version to target. Defaults to "draft-07".
|
|
12
|
-
* @returns The extracted JSON Schema.
|
|
13
|
-
*/
|
|
14
|
-
declare function extractJsonSchema(type: ZodType, target?: "draft-07" | "draft-2020-12"): (object & {
|
|
15
|
-
$schema?: string | undefined;
|
|
16
|
-
definitions?: {
|
|
17
|
-
[key: string]: zod_to_json_schema0.JsonSchema7Type;
|
|
18
|
-
} | undefined;
|
|
19
|
-
}) | z4.ZodStandardJSONSchemaPayload<z4.$ZodType<unknown, unknown, z4.$ZodTypeInternals<unknown, unknown>>>;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { extractJsonSchema };
|
|
22
|
-
//# sourceMappingURL=schema.d.cts.map
|
|
1
|
+
import { n as extractJsonSchema7, t as extractJsonSchema } from "./schema-s8jVY_-l.cjs";
|
|
2
|
+
export { extractJsonSchema, extractJsonSchema7 };
|
package/dist/schema.d.mts
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
//#region src/schema.d.ts
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Extracts a JSON Schema from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
9
|
-
*
|
|
10
|
-
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
11
|
-
* @param target - The JSON Schema draft version to target. Defaults to "draft-07".
|
|
12
|
-
* @returns The extracted JSON Schema.
|
|
13
|
-
*/
|
|
14
|
-
declare function extractJsonSchema(type: ZodType, target?: "draft-07" | "draft-2020-12"): (object & {
|
|
15
|
-
$schema?: string | undefined;
|
|
16
|
-
definitions?: {
|
|
17
|
-
[key: string]: zod_to_json_schema0.JsonSchema7Type;
|
|
18
|
-
} | undefined;
|
|
19
|
-
}) | z4.ZodStandardJSONSchemaPayload<z4.$ZodType<unknown, unknown, z4.$ZodTypeInternals<unknown, unknown>>>;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { extractJsonSchema };
|
|
22
|
-
//# sourceMappingURL=schema.d.mts.map
|
|
1
|
+
import "./types-UlEWkGXF.mjs";
|
|
2
|
+
import { n as extractJsonSchema7, t as extractJsonSchema } from "./schema-DQPkBDAQ.mjs";
|
|
3
|
+
export { extractJsonSchema, extractJsonSchema7 };
|
package/dist/schema.mjs
CHANGED
|
@@ -1,32 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
|
-
import * as z4 from "zod/v4/core";
|
|
1
|
+
import { n as extractJsonSchema7, t as extractJsonSchema } from "./schema-B6usLZOz.mjs";
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Extracts a JSON Schema from a given Zod schema, supporting both version 3 and version 4 of Zod.
|
|
8
|
-
*
|
|
9
|
-
* @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.
|
|
10
|
-
* @param target - The JSON Schema draft version to target. Defaults to "draft-07".
|
|
11
|
-
* @returns The extracted JSON Schema.
|
|
12
|
-
*/
|
|
13
|
-
function extractJsonSchema(type, target = "draft-07") {
|
|
14
|
-
if (isZod3Type(type)) {
|
|
15
|
-
const result = zodToJsonSchema(type, {
|
|
16
|
-
$refStrategy: "root",
|
|
17
|
-
definitionPath: "$defs",
|
|
18
|
-
target: target === "draft-07" ? "jsonSchema7" : "jsonSchema2019-09"
|
|
19
|
-
});
|
|
20
|
-
if (!result) throw new Error("Failed to extract JSON Schema from Zod v3 schema");
|
|
21
|
-
return result;
|
|
22
|
-
} else if (isZod4Type(type)) return z4.toJSONSchema(type, {
|
|
23
|
-
target: target === "draft-07" ? "draft-07" : "draft-2020-12",
|
|
24
|
-
unrepresentable: "any",
|
|
25
|
-
reused: "ref"
|
|
26
|
-
});
|
|
27
|
-
else throw new Error("Unsupported Zod schema version");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
|
-
export { extractJsonSchema };
|
|
32
|
-
//# sourceMappingURL=schema.mjs.map
|
|
3
|
+
export { extractJsonSchema, extractJsonSchema7 };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as z3 from "zod/v3";
|
|
2
|
+
import * as z4 from "zod/v4/core";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type ZodType = z3.ZodTypeAny | z4.$ZodType;
|
|
6
|
+
type ZodTypeKind = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "date" | "array" | "null" | "void" | "any" | "unknown" | "union" | "intersection";
|
|
7
|
+
/**
|
|
8
|
+
* Extracted metadata from a Zod schema.
|
|
9
|
+
*/
|
|
10
|
+
interface ZodTypeInfo {
|
|
11
|
+
kind: ZodTypeKind;
|
|
12
|
+
optional: boolean;
|
|
13
|
+
defaultValue?: unknown;
|
|
14
|
+
description?: string;
|
|
15
|
+
variadic: boolean;
|
|
16
|
+
choices?: (string | number)[];
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ZodTypeInfo as n, ZodTypeKind as r, ZodType as t };
|
|
20
|
+
//# sourceMappingURL=types-4nTrnOUu.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-4nTrnOUu.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;KAqBY,OAAA,GAAU,EAAA,CAAG,aAAa,EAAA,CAAG;KAE7B,WAAA;AAFZ;AAEA;AAqBA;UAAiB,WAAA;QACT"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as z4 from "zod/v4/core";
|
|
2
|
+
import * as z3 from "zod/v3";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type ZodType = z3.ZodTypeAny | z4.$ZodType;
|
|
6
|
+
type ZodTypeKind = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "date" | "array" | "null" | "void" | "any" | "unknown" | "union" | "intersection";
|
|
7
|
+
/**
|
|
8
|
+
* Extracted metadata from a Zod schema.
|
|
9
|
+
*/
|
|
10
|
+
interface ZodTypeInfo {
|
|
11
|
+
kind: ZodTypeKind;
|
|
12
|
+
optional: boolean;
|
|
13
|
+
defaultValue?: unknown;
|
|
14
|
+
description?: string;
|
|
15
|
+
variadic: boolean;
|
|
16
|
+
choices?: (string | number)[];
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ZodTypeInfo as n, ZodTypeKind as r, ZodType as t };
|
|
20
|
+
//# sourceMappingURL=types-UlEWkGXF.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-UlEWkGXF.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;KAqBY,OAAA,GAAU,EAAA,CAAG,aAAa,EAAA,CAAG;KAE7B,WAAA;AAFZ;AAEA;AAqBA;UAAiB,WAAA;QACT"}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
type ZodType = z3.ZodTypeAny | z4.$ZodType;
|
|
6
|
-
type ZodTypeKind = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "date" | "array" | "null" | "void" | "any" | "unknown" | "union" | "intersection";
|
|
7
|
-
/**
|
|
8
|
-
* Extracted metadata from a Zod schema.
|
|
9
|
-
*/
|
|
10
|
-
interface ZodTypeInfo {
|
|
11
|
-
kind: ZodTypeKind;
|
|
12
|
-
optional: boolean;
|
|
13
|
-
defaultValue?: unknown;
|
|
14
|
-
description?: string;
|
|
15
|
-
variadic: boolean;
|
|
16
|
-
choices?: (string | number)[];
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
export { ZodType, ZodTypeInfo, ZodTypeKind };
|
|
20
|
-
//# sourceMappingURL=types.d.cts.map
|
|
1
|
+
import { n as ZodTypeInfo, r as ZodTypeKind, t as ZodType } from "./types-4nTrnOUu.cjs";
|
|
2
|
+
export { ZodType, ZodTypeInfo, ZodTypeKind };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
type ZodType = z3.ZodTypeAny | z4.$ZodType;
|
|
6
|
-
type ZodTypeKind = "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "date" | "array" | "null" | "void" | "any" | "unknown" | "union" | "intersection";
|
|
7
|
-
/**
|
|
8
|
-
* Extracted metadata from a Zod schema.
|
|
9
|
-
*/
|
|
10
|
-
interface ZodTypeInfo {
|
|
11
|
-
kind: ZodTypeKind;
|
|
12
|
-
optional: boolean;
|
|
13
|
-
defaultValue?: unknown;
|
|
14
|
-
description?: string;
|
|
15
|
-
variadic: boolean;
|
|
16
|
-
choices?: (string | number)[];
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
export { ZodType, ZodTypeInfo, ZodTypeKind };
|
|
20
|
-
//# sourceMappingURL=types.d.mts.map
|
|
1
|
+
import { n as ZodTypeInfo, r as ZodTypeKind, t as ZodType } from "./types-UlEWkGXF.mjs";
|
|
2
|
+
export { ZodType, ZodTypeInfo, ZodTypeKind };
|
package/dist/types.mjs
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/zod",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing helper utilities for working with zod schemas.",
|
|
6
6
|
"repository": {
|
|
@@ -21,17 +21,59 @@
|
|
|
21
21
|
"module": "./dist/index.mjs",
|
|
22
22
|
"types": "./dist/index.d.cts",
|
|
23
23
|
"exports": {
|
|
24
|
-
".": {
|
|
24
|
+
".": {
|
|
25
|
+
"require": {
|
|
26
|
+
"type": "./dist/index.d.cts",
|
|
27
|
+
"default": "./dist/index.cjs"
|
|
28
|
+
},
|
|
29
|
+
"import": { "type": "./dist/index.d.mts", "default": "./dist/index.mjs" },
|
|
30
|
+
"default": { "type": "./dist/index.d.mts", "default": "./dist/index.mjs" }
|
|
31
|
+
},
|
|
32
|
+
"./index": {
|
|
33
|
+
"require": {
|
|
34
|
+
"type": "./dist/index.d.cts",
|
|
35
|
+
"default": "./dist/index.cjs"
|
|
36
|
+
},
|
|
37
|
+
"import": { "type": "./dist/index.d.mts", "default": "./dist/index.mjs" },
|
|
38
|
+
"default": { "type": "./dist/index.d.mts", "default": "./dist/index.mjs" }
|
|
39
|
+
},
|
|
25
40
|
"./is-zod-type": {
|
|
26
|
-
"require":
|
|
27
|
-
|
|
41
|
+
"require": {
|
|
42
|
+
"type": "./dist/is-zod-type.d.cts",
|
|
43
|
+
"default": "./dist/is-zod-type.cjs"
|
|
44
|
+
},
|
|
45
|
+
"import": {
|
|
46
|
+
"type": "./dist/is-zod-type.d.mts",
|
|
47
|
+
"default": "./dist/is-zod-type.mjs"
|
|
48
|
+
},
|
|
49
|
+
"default": {
|
|
50
|
+
"type": "./dist/is-zod-type.d.mts",
|
|
51
|
+
"default": "./dist/is-zod-type.mjs"
|
|
52
|
+
}
|
|
28
53
|
},
|
|
29
54
|
"./schema": {
|
|
30
|
-
"require":
|
|
31
|
-
|
|
55
|
+
"require": {
|
|
56
|
+
"type": "./dist/schema.d.cts",
|
|
57
|
+
"default": "./dist/schema.cjs"
|
|
58
|
+
},
|
|
59
|
+
"import": {
|
|
60
|
+
"type": "./dist/schema.d.mts",
|
|
61
|
+
"default": "./dist/schema.mjs"
|
|
62
|
+
},
|
|
63
|
+
"default": {
|
|
64
|
+
"type": "./dist/schema.d.mts",
|
|
65
|
+
"default": "./dist/schema.mjs"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"./types": {
|
|
69
|
+
"require": {
|
|
70
|
+
"type": "./dist/types.d.cts",
|
|
71
|
+
"default": "./dist/types.cjs"
|
|
72
|
+
},
|
|
73
|
+
"import": { "type": "./dist/types.d.mts", "default": "./dist/types.mjs" },
|
|
74
|
+
"default": { "type": "./dist/types.d.mts", "default": "./dist/types.mjs" }
|
|
32
75
|
},
|
|
33
|
-
"./types": { "require": "./dist/types.cjs", "import": "./dist/types.mjs" },
|
|
34
76
|
"./*": "./*"
|
|
35
77
|
},
|
|
36
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "58d349e5252a30dee23b0d66257f447b6fe38058"
|
|
37
79
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
|
|
29
|
-
exports.__toESM = __toESM;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-zod-type.d.cts","names":[],"sources":["../src/is-zod-type.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA8BA;AAcA;AAYA;;iBA1BgB,UAAA,yBAAmC,EAAA,CAAG;;;;;;;iBActC,UAAA,yBAAmC,EAAA,CAAG;;;;;;;iBAYtC,SAAA,yBAAkC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-zod-type.d.mts","names":[],"sources":["../src/is-zod-type.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA8BA;AAcA;AAYA;;iBA1BgB,UAAA,yBAAmC,EAAA,CAAG;;;;;;;iBActC,UAAA,yBAAmC,EAAA,CAAG;;;;;;;iBAYtC,SAAA,yBAAkC"}
|
package/dist/is-zod-type.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-zod-type.mjs","names":[],"sources":["../src/is-zod-type.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type * as z3 from \"zod/v3\";\nimport type * as z4 from \"zod/v4/core\";\n\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type { ZodType } from \"./types\";\n\n/**\n * Type guard to check if a given value is a Zod schema of version 3.\n *\n * @param type - The value to check.\n * @returns True if the value is a Zod schema, false otherwise.\n */\nexport function isZod3Type(type: unknown): type is z3.ZodTypeAny {\n return (\n isSetObject(type) &&\n \"_def\" in type &&\n \"typeName\" in (type as z3.ZodTypeAny)._def\n );\n}\n\n/**\n * Type guard to check if a given value is a Zod schema of version 4.\n *\n * @param type - The value to check.\n * @returns True if the value is a Zod v4 schema, false otherwise.\n */\nexport function isZod4Type(type: unknown): type is z4.$ZodType {\n return (\n isSetObject(type) && \"_zod\" in type && \"def\" in (type as z4.$ZodType)._zod\n );\n}\n\n/**\n * Type guard to check if a given value is a Zod schema of either version 3 or 4.\n *\n * @param type - The value to check.\n * @returns True if the value is a Zod schema, false otherwise.\n */\nexport function isZodType(type: unknown): type is ZodType {\n return isZod3Type(type) || isZod4Type(type);\n}\n"],"mappings":";;;;;;;;;AA8BA,SAAgB,WAAW,MAAsC;AAC/D,QACE,YAAY,KAAK,IACjB,UAAU,QACV,cAAe,KAAuB;;;;;;;;AAU1C,SAAgB,WAAW,MAAoC;AAC7D,QACE,YAAY,KAAK,IAAI,UAAU,QAAQ,SAAU,KAAqB;;;;;;;;AAU1E,SAAgB,UAAU,MAAgC;AACxD,QAAO,WAAW,KAAK,IAAI,WAAW,KAAK"}
|
package/dist/schema.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.cts","names":[],"sources":["../src/schema.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AA8BA;;;;iBAAgB,iBAAA,OACR;;;mBAAO,mBAAA,CAAA"}
|
package/dist/schema.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.mts","names":[],"sources":["../src/schema.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AA8BA;;;;iBAAgB,iBAAA,OACR;;;mBAAO,mBAAA,CAAA"}
|
package/dist/schema.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport * as z4 from \"zod/v4/core\";\nimport { isZod3Type, isZod4Type } from \"./is-zod-type\";\nimport type { ZodType } from \"./types\";\n\n/**\n * Extracts a JSON Schema from a given Zod schema, supporting both version 3 and version 4 of Zod.\n *\n * @param type - The Zod schema to extract the JSON Schema from. Can be either a Zod v3 or v4 schema.\n * @param target - The JSON Schema draft version to target. Defaults to \"draft-07\".\n * @returns The extracted JSON Schema.\n */\nexport function extractJsonSchema(\n type: ZodType,\n target: \"draft-07\" | \"draft-2020-12\" = \"draft-07\"\n) {\n if (isZod3Type(type)) {\n const result = zodToJsonSchema(type, {\n $refStrategy: \"root\",\n definitionPath: \"$defs\",\n target: target === \"draft-07\" ? \"jsonSchema7\" : \"jsonSchema2019-09\"\n });\n if (!result) {\n throw new Error(\"Failed to extract JSON Schema from Zod v3 schema\");\n }\n\n return result;\n } else if (isZod4Type(type)) {\n return z4.toJSONSchema(type, {\n target: target === \"draft-07\" ? \"draft-07\" : \"draft-2020-12\",\n // eslint-disable-next-line @cspell/spellchecker\n unrepresentable: \"any\",\n reused: \"ref\"\n });\n } else {\n throw new Error(\"Unsupported Zod schema version\");\n }\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,SAAgB,kBACd,MACA,SAAuC,YACvC;AACA,KAAI,WAAW,KAAK,EAAE;EACpB,MAAM,SAAS,gBAAgB,MAAM;GACnC,cAAc;GACd,gBAAgB;GAChB,QAAQ,WAAW,aAAa,gBAAgB;GACjD,CAAC;AACF,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,mDAAmD;AAGrE,SAAO;YACE,WAAW,KAAK,CACzB,QAAO,GAAG,aAAa,MAAM;EAC3B,QAAQ,WAAW,aAAa,aAAa;EAE7C,iBAAiB;EACjB,QAAQ;EACT,CAAC;KAEF,OAAM,IAAI,MAAM,iCAAiC"}
|