@geekmidas/schema 10.0.0-alpha.99 → 10.0.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 +65 -0
- package/README.md +6 -6
- package/dist/conversion-CIBtqJkS.mjs +106 -0
- package/dist/conversion-CIBtqJkS.mjs.map +1 -0
- package/dist/conversion-Cf9R-jGc.cjs +148 -0
- package/dist/conversion-Cf9R-jGc.cjs.map +1 -0
- package/dist/conversion-JY1Wixil.d.cts +39 -0
- package/dist/conversion-JY1Wixil.d.cts.map +1 -0
- package/dist/conversion-e4k9rTxy.d.mts +39 -0
- package/dist/conversion-e4k9rTxy.d.mts.map +1 -0
- package/dist/conversion.cjs +8 -106
- package/dist/conversion.d.cts +2 -37
- package/dist/conversion.d.mts +2 -37
- package/dist/conversion.mjs +2 -99
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -3
- package/dist/openapi-Aeb_1e9T.d.cts +28 -0
- package/dist/openapi-Aeb_1e9T.d.cts.map +1 -0
- package/dist/openapi-DH5yCqKh.mjs +46 -0
- package/dist/openapi-DH5yCqKh.mjs.map +1 -0
- package/dist/openapi-DVvLYx-8.cjs +58 -0
- package/dist/openapi-DVvLYx-8.cjs.map +1 -0
- package/dist/openapi-Dxc4FuMP.d.mts +28 -0
- package/dist/openapi-Dxc4FuMP.d.mts.map +1 -0
- package/dist/openapi.cjs +3 -56
- package/dist/openapi.d.cts +2 -27
- package/dist/openapi.d.mts +2 -27
- package/dist/openapi.mjs +2 -54
- package/dist/parser.cjs +3 -3
- package/dist/parser.cjs.map +1 -1
- package/dist/parser.d.cts +8 -3
- package/dist/parser.d.cts.map +1 -1
- package/dist/parser.d.mts +8 -3
- package/dist/parser.d.mts.map +1 -1
- package/dist/parser.mjs +2 -2
- package/dist/parser.mjs.map +1 -1
- package/dist/types-Bm3VhqVE.d.cts +26 -0
- package/dist/types-Bm3VhqVE.d.cts.map +1 -0
- package/dist/types-xm7EGhin.d.mts +26 -0
- package/dist/types-xm7EGhin.d.mts.map +1 -0
- package/dist/types.d.cts +2 -22
- package/dist/types.d.mts +2 -22
- package/dist/types.mjs +0 -1
- package/package.json +8 -15
- package/src/__benchmarks__/conversion.bench.ts +88 -0
- package/src/__tests__/conversion.spec.ts +502 -0
- package/src/__tests__/openapi.spec.ts +396 -0
- package/src/__tests__/parser.spec.ts +236 -0
- package/src/conversion.ts +220 -0
- package/src/index.ts +15 -0
- package/src/openapi.ts +75 -0
- package/src/parser.ts +30 -0
- package/src/types.ts +37 -0
- package/tsconfig.json +9 -0
- package/tsdown.config.ts +5 -0
- package/dist/conversion.cjs.map +0 -1
- package/dist/conversion.d.cts.map +0 -1
- package/dist/conversion.d.mts.map +0 -1
- package/dist/conversion.mjs.map +0 -1
- package/dist/openapi.cjs.map +0 -1
- package/dist/openapi.d.cts.map +0 -1
- package/dist/openapi.d.mts.map +0 -1
- package/dist/openapi.mjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @geekmidas/schema
|
|
2
|
+
|
|
3
|
+
## 10.0.0
|
|
4
|
+
|
|
5
|
+
## 9.0.2
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#12](https://github.com/geekmidas/toolbox/pull/12) [`d53863a`](https://github.com/geekmidas/toolbox/commit/d53863a84db2e4ab5420e08f79128b637043fc42) Thanks [@geekmidas](https://github.com/geekmidas)! - Align every published package on a single version and keep them in step.
|
|
10
|
+
|
|
11
|
+
All packages now share one version, enforced by a changesets `fixed` group. The
|
|
12
|
+
baseline is 9.0.1 — @geekmidas/client's published version — so nothing moves
|
|
13
|
+
backwards; this release takes the whole set to 9.0.2 together.
|
|
14
|
+
|
|
15
|
+
Independent versions made "which version of the docs applies to me"
|
|
16
|
+
unanswerable: a reader on constructs@7 and cli@2 was on no version at all. One
|
|
17
|
+
number per release makes versioned documentation possible, and lets 9 freeze as
|
|
18
|
+
the current paradigm while the constructs rework is developed against it.
|
|
19
|
+
|
|
20
|
+
Every release now publishes every package, and a major anywhere is a major
|
|
21
|
+
everywhere. Peer ranges get simpler in return.
|
|
22
|
+
|
|
23
|
+
## 1.0.4
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 🐛 [#11](https://github.com/geekmidas/toolbox/pull/11) [`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309) Thanks [@geekmidas](https://github.com/geekmidas)! - Patch release across all packages to realign published versions with the
|
|
28
|
+
registry. The previous release only published the four packages that had
|
|
29
|
+
version bumps; the remaining packages failed with "cannot publish over the
|
|
30
|
+
previously published versions" because their versions were unchanged.
|
|
31
|
+
|
|
32
|
+
## 1.0.3
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- [#7](https://github.com/geekmidas/toolbox/pull/7) [`e0d06b3`](https://github.com/geekmidas/toolbox/commit/e0d06b38dfd275758f7955f5754900ab78779302) Thanks [@geekmidas](https://github.com/geekmidas)! - feat(constructs): allow endpoint handlers to return the output schema's input type
|
|
37
|
+
|
|
38
|
+
Endpoint handlers previously had to return the output schema's _parsed_ type
|
|
39
|
+
(`InferStandardSchema`). When an output schema coerces its value (e.g. a `Date`
|
|
40
|
+
serialized to an ISO `string`, or an applied default), that forced handlers to
|
|
41
|
+
pre-coerce values themselves even though the schema would do it on the way out.
|
|
42
|
+
|
|
43
|
+
A new `InferStandardSchemaInput` type is added to `@geekmidas/schema`, exposing a
|
|
44
|
+
Standard Schema's _input_ type (`StandardSchemaV1.InferInput`). `Endpoint`'s
|
|
45
|
+
handler return type now uses it, so handlers may return the looser pre-coercion
|
|
46
|
+
input while consumers (`EndpointOutput` and the generated client) still see the
|
|
47
|
+
narrower parsed output type.
|
|
48
|
+
|
|
49
|
+
## 1.0.2
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- 🐛 [`d70c6c0`](https://github.com/geekmidas/toolbox/commit/d70c6c0aeb8a79da2473ac77dbd8255a4a2f5651) Thanks [@geekmidas](https://github.com/geekmidas)! - Fix `package.json` exports so TypeScript declarations resolve correctly under NodeNext/Bundler module resolution. Each subpath export now nests `types` inside its `import`/`require` condition, pointing at the `.d.mts` and `.d.cts` files that `tsdown` actually emits (previously the exports referenced non-existent `.d.ts` files, causing type-resolution failures for consumers). Both ESM (`.mjs`) and CJS (`.cjs`) runtime entry points are preserved. Additionally, `@geekmidas/ui` had `import` paths pointing at `.js` files that were never emitted — those are corrected to `.mjs`.
|
|
54
|
+
|
|
55
|
+
## 1.0.1
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- 🐛 [`aeba918`](https://github.com/geekmidas/toolbox/commit/aeba918fc258f6ccdb96b8273b2bc01bd2190553) Thanks [@geekmidas](https://github.com/geekmidas)! - Fix schema, openapi generation and events testkit
|
|
60
|
+
|
|
61
|
+
## 1.0.0
|
|
62
|
+
|
|
63
|
+
### Major Changes
|
|
64
|
+
|
|
65
|
+
- [`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8) Thanks [@geekmidas](https://github.com/geekmidas)! - Version 1 Stable release
|
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ import { z } from 'zod';
|
|
|
73
73
|
// Define a schema
|
|
74
74
|
const userSchema = z.object({
|
|
75
75
|
id: z.string(),
|
|
76
|
-
email: z.email(),
|
|
76
|
+
email: z.string().email(),
|
|
77
77
|
age: z.number().min(18),
|
|
78
78
|
role: z.enum(['admin', 'user'])
|
|
79
79
|
});
|
|
@@ -130,7 +130,7 @@ import { z } from 'zod';
|
|
|
130
130
|
const schemas = {
|
|
131
131
|
user: z.object({
|
|
132
132
|
id: z.string(),
|
|
133
|
-
email: z.email()
|
|
133
|
+
email: z.string().email()
|
|
134
134
|
}),
|
|
135
135
|
post: z.object({
|
|
136
136
|
id: z.string(),
|
|
@@ -237,7 +237,7 @@ import { z } from 'zod';
|
|
|
237
237
|
const createUserEndpoint = {
|
|
238
238
|
body: z.object({
|
|
239
239
|
name: z.string().min(1),
|
|
240
|
-
email: z.email(),
|
|
240
|
+
email: z.string().email(),
|
|
241
241
|
age: z.number().int().min(18)
|
|
242
242
|
}),
|
|
243
243
|
response: z.object({
|
|
@@ -272,7 +272,7 @@ import { z } from 'zod';
|
|
|
272
272
|
|
|
273
273
|
const userSchema = z.object({
|
|
274
274
|
id: z.string(),
|
|
275
|
-
email: z.email()
|
|
275
|
+
email: z.string().email()
|
|
276
276
|
});
|
|
277
277
|
|
|
278
278
|
type User = InferStandardSchema<typeof userSchema>;
|
|
@@ -296,11 +296,11 @@ if (isUser(data)) {
|
|
|
296
296
|
This package is used internally by `@geekmidas/constructs` for type-safe endpoint validation:
|
|
297
297
|
|
|
298
298
|
```typescript
|
|
299
|
-
import {
|
|
299
|
+
import { e } from '@geekmidas/constructs/endpoints';
|
|
300
300
|
import { z } from 'zod';
|
|
301
301
|
|
|
302
302
|
// The constructs package uses InferStandardSchema internally
|
|
303
|
-
const endpoint =
|
|
303
|
+
const endpoint = e
|
|
304
304
|
.post('/users')
|
|
305
305
|
.body(z.object({ name: z.string() }))
|
|
306
306
|
.output(z.object({ id: z.string() }))
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//#region src/conversion.ts
|
|
2
|
+
let SchemaVendor = /* @__PURE__ */ function(SchemaVendor$1) {
|
|
3
|
+
SchemaVendor$1["zod"] = "zod";
|
|
4
|
+
SchemaVendor$1["valibot"] = "valibot";
|
|
5
|
+
return SchemaVendor$1;
|
|
6
|
+
}({});
|
|
7
|
+
function isSchemaVendor(vendor) {
|
|
8
|
+
if (!vendor) return false;
|
|
9
|
+
return Object.values(SchemaVendor).includes(vendor);
|
|
10
|
+
}
|
|
11
|
+
const StandardSchemaJsonSchema = {
|
|
12
|
+
zod: async (schema) => {
|
|
13
|
+
try {
|
|
14
|
+
const { z } = await import("zod/v4").catch(() => ({ z: {} }));
|
|
15
|
+
if ("toJSONSchema" in z && typeof z.toJSONSchema === "function") return z.toJSONSchema(schema);
|
|
16
|
+
const { zodToJsonSchema } = await import("zod-to-json-schema");
|
|
17
|
+
const result = zodToJsonSchema(schema, { removeAdditionalStrategy: "strict" });
|
|
18
|
+
return result;
|
|
19
|
+
} catch {
|
|
20
|
+
return { type: "object" };
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
valibot: async (schema) => {
|
|
24
|
+
const { toJsonSchema } = await import("@valibot/to-json-schema");
|
|
25
|
+
return toJsonSchema(schema);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
function extractAndConvertDefs(jsonSchema, componentCollector) {
|
|
29
|
+
if (!jsonSchema || typeof jsonSchema !== "object") return jsonSchema;
|
|
30
|
+
const processSchema = (schema) => {
|
|
31
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
32
|
+
if (schema.$ref && typeof schema.$ref === "string") {
|
|
33
|
+
if (schema.$ref.startsWith("#/$defs/")) {
|
|
34
|
+
const refName = schema.$ref.replace("#/$defs/", "");
|
|
35
|
+
return componentCollector ? componentCollector.getReference(refName) : schema;
|
|
36
|
+
}
|
|
37
|
+
return schema;
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(schema)) return schema.map(processSchema);
|
|
40
|
+
const processed = {};
|
|
41
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
42
|
+
if (key === "$defs") continue;
|
|
43
|
+
processed[key] = processSchema(value);
|
|
44
|
+
}
|
|
45
|
+
return processed;
|
|
46
|
+
};
|
|
47
|
+
if (jsonSchema.$defs && componentCollector) for (const [defName, defSchema] of Object.entries(jsonSchema.$defs)) {
|
|
48
|
+
const processedDefSchema = processSchema(defSchema);
|
|
49
|
+
componentCollector.addSchema(defName, processedDefSchema);
|
|
50
|
+
}
|
|
51
|
+
const { $defs,...schemaWithoutDefs } = jsonSchema;
|
|
52
|
+
return processSchema(schemaWithoutDefs);
|
|
53
|
+
}
|
|
54
|
+
async function convertStandardSchemaToJsonSchema(schema, componentCollector) {
|
|
55
|
+
if (!schema) return void 0;
|
|
56
|
+
const vendor = schema["~standard"]?.vendor;
|
|
57
|
+
if (!isSchemaVendor(vendor)) throw new Error(`Unsupported or missing vendor "${vendor}" for Standard Schema. Supported vendors are: ${Object.keys(StandardSchemaJsonSchema).join(", ")}`);
|
|
58
|
+
const toJSONSchema = StandardSchemaJsonSchema[vendor];
|
|
59
|
+
const jsonSchema = await toJSONSchema(schema);
|
|
60
|
+
return extractAndConvertDefs(jsonSchema, componentCollector);
|
|
61
|
+
}
|
|
62
|
+
async function getZodMetadata(schema) {
|
|
63
|
+
const { ZodObject } = await import("zod/v4");
|
|
64
|
+
if (schema instanceof ZodObject) return schema.meta();
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Return JSON Schema for every schema registered in zod v4's global registry
|
|
69
|
+
* via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or
|
|
70
|
+
* no schemas are registered.
|
|
71
|
+
*
|
|
72
|
+
* `unrepresentable: 'any'` keeps a single unrepresentable schema from
|
|
73
|
+
* collapsing the whole result.
|
|
74
|
+
*/
|
|
75
|
+
async function getRegisteredZodJsonSchemas() {
|
|
76
|
+
try {
|
|
77
|
+
const { z } = await import("zod/v4").catch(() => ({ z: null }));
|
|
78
|
+
if (!z?.toJSONSchema || !z.globalRegistry) return {};
|
|
79
|
+
const result = z.toJSONSchema(z.globalRegistry, { unrepresentable: "any" });
|
|
80
|
+
return result?.schemas ?? {};
|
|
81
|
+
} catch {
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function getSchemaMetadata(schema) {
|
|
86
|
+
const vendor = schema["~standard"]?.vendor;
|
|
87
|
+
if (vendor === "zod") return getZodMetadata(schema);
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
async function convertSchemaWithComponents(schema, componentCollector) {
|
|
91
|
+
if (!schema) return void 0;
|
|
92
|
+
const jsonSchema = await convertStandardSchemaToJsonSchema(schema, componentCollector);
|
|
93
|
+
if (!componentCollector) return jsonSchema;
|
|
94
|
+
const metadata = await getSchemaMetadata(schema);
|
|
95
|
+
const schemaId = metadata?.id || jsonSchema?.id;
|
|
96
|
+
if (schemaId) {
|
|
97
|
+
const { id,...schemaWithoutId } = jsonSchema;
|
|
98
|
+
componentCollector.addSchema(schemaId, schemaWithoutId);
|
|
99
|
+
return componentCollector.getReference(schemaId);
|
|
100
|
+
}
|
|
101
|
+
return jsonSchema;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
export { SchemaVendor, StandardSchemaJsonSchema, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata };
|
|
106
|
+
//# sourceMappingURL=conversion-CIBtqJkS.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion-CIBtqJkS.mjs","names":["vendor?: string","StandardSchemaJsonSchema: VendorConvertors","jsonSchema: any","componentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t}","schema: any","processed: any","schema?: StandardSchemaV1","schema: StandardSchemaV1","schema: StandardSchemaV1 | undefined"],"sources":["../src/conversion.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\n\nexport enum SchemaVendor {\n\tzod = 'zod',\n\tvalibot = 'valibot',\n}\n\nexport type VendorConvertor = (schema: any) => Promise<any>;\nexport type VendorConvertors = Record<SchemaVendor, VendorConvertor>;\n\nfunction isSchemaVendor(vendor?: string): vendor is SchemaVendor {\n\tif (!vendor) {\n\t\treturn false;\n\t}\n\n\treturn Object.values(SchemaVendor).includes(vendor as SchemaVendor);\n}\n\nexport const StandardSchemaJsonSchema: VendorConvertors = {\n\tzod: async (schema): Promise<any> => {\n\t\ttry {\n\t\t\tconst { z } = await import('zod/v4').catch(() => ({ z: {} }));\n\n\t\t\tif ('toJSONSchema' in z && typeof z.toJSONSchema === 'function') {\n\t\t\t\treturn z.toJSONSchema(schema);\n\t\t\t}\n\t\t\tconst { zodToJsonSchema } = await import('zod-to-json-schema');\n\n\t\t\tconst result = zodToJsonSchema(schema, {\n\t\t\t\tremoveAdditionalStrategy: 'strict',\n\t\t\t});\n\n\t\t\treturn result;\n\t\t} catch {\n\t\t\t// Fallback to basic conversion if zod-to-json-schema is not available\n\t\t\treturn { type: 'object' };\n\t\t}\n\t},\n\tvalibot: async (schema): Promise<any> => {\n\t\tconst { toJsonSchema } = await import('@valibot/to-json-schema');\n\t\treturn toJsonSchema(schema as any);\n\t},\n};\n\nfunction extractAndConvertDefs(\n\tjsonSchema: any,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): any {\n\tif (!jsonSchema || typeof jsonSchema !== 'object') {\n\t\treturn jsonSchema;\n\t}\n\n\t// Process the schema recursively to update references\n\tconst processSchema = (schema: any): any => {\n\t\tif (!schema || typeof schema !== 'object') {\n\t\t\treturn schema;\n\t\t}\n\n\t\t// Handle $ref\n\t\tif (schema.$ref && typeof schema.$ref === 'string') {\n\t\t\t// Convert #/$defs/X to #/components/schemas/X\n\t\t\tif (schema.$ref.startsWith('#/$defs/')) {\n\t\t\t\tconst refName = schema.$ref.replace('#/$defs/', '');\n\t\t\t\treturn componentCollector\n\t\t\t\t\t? componentCollector.getReference(refName)\n\t\t\t\t\t: schema;\n\t\t\t}\n\t\t\treturn schema;\n\t\t}\n\n\t\t// Handle arrays\n\t\tif (Array.isArray(schema)) {\n\t\t\treturn schema.map(processSchema);\n\t\t}\n\n\t\t// Process all properties recursively\n\t\tconst processed: any = {};\n\t\tfor (const [key, value] of Object.entries(schema)) {\n\t\t\tif (key === '$defs') {\n\t\t\t\t// Skip $defs as they've been extracted\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tprocessed[key] = processSchema(value);\n\t\t}\n\t\treturn processed;\n\t};\n\n\t// Extract $defs if present\n\tif (jsonSchema.$defs && componentCollector) {\n\t\tfor (const [defName, defSchema] of Object.entries(jsonSchema.$defs)) {\n\t\t\t// Process the definition recursively to handle nested $refs\n\t\t\tconst processedDefSchema = processSchema(defSchema);\n\t\t\t// Add each definition to the component collector\n\t\t\tcomponentCollector.addSchema(defName, processedDefSchema);\n\t\t}\n\t}\n\n\t// Process the schema and remove $defs\n\tconst { $defs, ...schemaWithoutDefs } = jsonSchema;\n\treturn processSchema(schemaWithoutDefs);\n}\n\nexport async function convertStandardSchemaToJsonSchema(\n\tschema?: StandardSchemaV1,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): Promise<any> {\n\tif (!schema) {\n\t\treturn undefined;\n\t}\n\n\tconst vendor = schema['~standard']?.vendor;\n\tif (!isSchemaVendor(vendor)) {\n\t\tthrow new Error(\n\t\t\t`Unsupported or missing vendor \"${vendor}\" for Standard Schema. Supported vendors are: ${Object.keys(StandardSchemaJsonSchema).join(', ')}`,\n\t\t);\n\t}\n\n\tconst toJSONSchema = StandardSchemaJsonSchema[vendor];\n\tconst jsonSchema = await toJSONSchema(schema);\n\n\t// Extract and convert $defs to components\n\treturn extractAndConvertDefs(jsonSchema, componentCollector);\n}\n\nexport async function getZodMetadata(\n\tschema: StandardSchemaV1,\n): Promise<SchemaMeta | undefined> {\n\tconst { ZodObject } = await import('zod/v4');\n\n\tif (schema instanceof ZodObject) {\n\t\treturn schema.meta();\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Return JSON Schema for every schema registered in zod v4's global registry\n * via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or\n * no schemas are registered.\n *\n * `unrepresentable: 'any'` keeps a single unrepresentable schema from\n * collapsing the whole result.\n */\nexport async function getRegisteredZodJsonSchemas(): Promise<\n\tRecord<string, any>\n> {\n\ttry {\n\t\tconst { z } = await import('zod/v4').catch(() => ({ z: null as any }));\n\t\tif (!z?.toJSONSchema || !z.globalRegistry) {\n\t\t\treturn {};\n\t\t}\n\t\tconst result = z.toJSONSchema(z.globalRegistry, {\n\t\t\tunrepresentable: 'any',\n\t\t});\n\t\treturn (result?.schemas ?? {}) as Record<string, any>;\n\t} catch {\n\t\treturn {};\n\t}\n}\n\nexport async function getSchemaMetadata(\n\tschema: StandardSchemaV1,\n): Promise<SchemaMeta | undefined> {\n\tconst vendor = schema['~standard']?.vendor;\n\n\tif (vendor === 'zod') {\n\t\treturn getZodMetadata(schema);\n\t}\n\n\treturn undefined;\n}\n\ninterface SchemaMeta {\n\tid?: string;\n}\n\nexport async function convertSchemaWithComponents(\n\tschema: StandardSchemaV1 | undefined,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): Promise<any> {\n\tif (!schema) {\n\t\treturn undefined;\n\t}\n\n\t// Convert to JSON Schema with component collector to handle $defs\n\tconst jsonSchema = await convertStandardSchemaToJsonSchema(\n\t\tschema,\n\t\tcomponentCollector,\n\t);\n\n\tif (!componentCollector) {\n\t\treturn jsonSchema;\n\t}\n\n\t// Check if this schema has metadata with an ID\n\tconst metadata = await getSchemaMetadata(schema);\n\n\t// Also check if the JSON Schema itself has an id field (from Zod's meta)\n\tconst schemaId = metadata?.id || jsonSchema?.id;\n\n\tif (schemaId) {\n\t\t// Remove the id from the schema before adding to components\n\t\tconst { id, ...schemaWithoutId } = jsonSchema;\n\t\t// Add this schema to components and return a reference\n\t\tcomponentCollector.addSchema(schemaId, schemaWithoutId);\n\t\treturn componentCollector.getReference(schemaId);\n\t}\n\n\treturn jsonSchema;\n}\n"],"mappings":";AAEA,IAAY,wDAAL;AACN;AACA;;AACA;AAKD,SAAS,eAAeA,QAAyC;AAChE,MAA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Eb,MAAM,EAAE,GAAI,GAAG,iBAAiB,GAAG;AAEnC,qBAAmB,UAAU,UAAU,gBAAgB;AACvD,SAAO,mBAAmB,aAAa,SAAS;CAChD;AAED,QAAO;AACP"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/conversion.ts
|
|
3
|
+
let SchemaVendor = /* @__PURE__ */ function(SchemaVendor$1) {
|
|
4
|
+
SchemaVendor$1["zod"] = "zod";
|
|
5
|
+
SchemaVendor$1["valibot"] = "valibot";
|
|
6
|
+
return SchemaVendor$1;
|
|
7
|
+
}({});
|
|
8
|
+
function isSchemaVendor(vendor) {
|
|
9
|
+
if (!vendor) return false;
|
|
10
|
+
return Object.values(SchemaVendor).includes(vendor);
|
|
11
|
+
}
|
|
12
|
+
const StandardSchemaJsonSchema = {
|
|
13
|
+
zod: async (schema) => {
|
|
14
|
+
try {
|
|
15
|
+
const { z } = await import("zod/v4").catch(() => ({ z: {} }));
|
|
16
|
+
if ("toJSONSchema" in z && typeof z.toJSONSchema === "function") return z.toJSONSchema(schema);
|
|
17
|
+
const { zodToJsonSchema } = await import("zod-to-json-schema");
|
|
18
|
+
const result = zodToJsonSchema(schema, { removeAdditionalStrategy: "strict" });
|
|
19
|
+
return result;
|
|
20
|
+
} catch {
|
|
21
|
+
return { type: "object" };
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
valibot: async (schema) => {
|
|
25
|
+
const { toJsonSchema } = await import("@valibot/to-json-schema");
|
|
26
|
+
return toJsonSchema(schema);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function extractAndConvertDefs(jsonSchema, componentCollector) {
|
|
30
|
+
if (!jsonSchema || typeof jsonSchema !== "object") return jsonSchema;
|
|
31
|
+
const processSchema = (schema) => {
|
|
32
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
33
|
+
if (schema.$ref && typeof schema.$ref === "string") {
|
|
34
|
+
if (schema.$ref.startsWith("#/$defs/")) {
|
|
35
|
+
const refName = schema.$ref.replace("#/$defs/", "");
|
|
36
|
+
return componentCollector ? componentCollector.getReference(refName) : schema;
|
|
37
|
+
}
|
|
38
|
+
return schema;
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(schema)) return schema.map(processSchema);
|
|
41
|
+
const processed = {};
|
|
42
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
43
|
+
if (key === "$defs") continue;
|
|
44
|
+
processed[key] = processSchema(value);
|
|
45
|
+
}
|
|
46
|
+
return processed;
|
|
47
|
+
};
|
|
48
|
+
if (jsonSchema.$defs && componentCollector) for (const [defName, defSchema] of Object.entries(jsonSchema.$defs)) {
|
|
49
|
+
const processedDefSchema = processSchema(defSchema);
|
|
50
|
+
componentCollector.addSchema(defName, processedDefSchema);
|
|
51
|
+
}
|
|
52
|
+
const { $defs,...schemaWithoutDefs } = jsonSchema;
|
|
53
|
+
return processSchema(schemaWithoutDefs);
|
|
54
|
+
}
|
|
55
|
+
async function convertStandardSchemaToJsonSchema(schema, componentCollector) {
|
|
56
|
+
if (!schema) return void 0;
|
|
57
|
+
const vendor = schema["~standard"]?.vendor;
|
|
58
|
+
if (!isSchemaVendor(vendor)) throw new Error(`Unsupported or missing vendor "${vendor}" for Standard Schema. Supported vendors are: ${Object.keys(StandardSchemaJsonSchema).join(", ")}`);
|
|
59
|
+
const toJSONSchema = StandardSchemaJsonSchema[vendor];
|
|
60
|
+
const jsonSchema = await toJSONSchema(schema);
|
|
61
|
+
return extractAndConvertDefs(jsonSchema, componentCollector);
|
|
62
|
+
}
|
|
63
|
+
async function getZodMetadata(schema) {
|
|
64
|
+
const { ZodObject } = await import("zod/v4");
|
|
65
|
+
if (schema instanceof ZodObject) return schema.meta();
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Return JSON Schema for every schema registered in zod v4's global registry
|
|
70
|
+
* via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or
|
|
71
|
+
* no schemas are registered.
|
|
72
|
+
*
|
|
73
|
+
* `unrepresentable: 'any'` keeps a single unrepresentable schema from
|
|
74
|
+
* collapsing the whole result.
|
|
75
|
+
*/
|
|
76
|
+
async function getRegisteredZodJsonSchemas() {
|
|
77
|
+
try {
|
|
78
|
+
const { z } = await import("zod/v4").catch(() => ({ z: null }));
|
|
79
|
+
if (!z?.toJSONSchema || !z.globalRegistry) return {};
|
|
80
|
+
const result = z.toJSONSchema(z.globalRegistry, { unrepresentable: "any" });
|
|
81
|
+
return result?.schemas ?? {};
|
|
82
|
+
} catch {
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function getSchemaMetadata(schema) {
|
|
87
|
+
const vendor = schema["~standard"]?.vendor;
|
|
88
|
+
if (vendor === "zod") return getZodMetadata(schema);
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
async function convertSchemaWithComponents(schema, componentCollector) {
|
|
92
|
+
if (!schema) return void 0;
|
|
93
|
+
const jsonSchema = await convertStandardSchemaToJsonSchema(schema, componentCollector);
|
|
94
|
+
if (!componentCollector) return jsonSchema;
|
|
95
|
+
const metadata = await getSchemaMetadata(schema);
|
|
96
|
+
const schemaId = metadata?.id || jsonSchema?.id;
|
|
97
|
+
if (schemaId) {
|
|
98
|
+
const { id,...schemaWithoutId } = jsonSchema;
|
|
99
|
+
componentCollector.addSchema(schemaId, schemaWithoutId);
|
|
100
|
+
return componentCollector.getReference(schemaId);
|
|
101
|
+
}
|
|
102
|
+
return jsonSchema;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
Object.defineProperty(exports, 'SchemaVendor', {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function () {
|
|
109
|
+
return SchemaVendor;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Object.defineProperty(exports, 'StandardSchemaJsonSchema', {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function () {
|
|
115
|
+
return StandardSchemaJsonSchema;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
Object.defineProperty(exports, 'convertSchemaWithComponents', {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
get: function () {
|
|
121
|
+
return convertSchemaWithComponents;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
Object.defineProperty(exports, 'convertStandardSchemaToJsonSchema', {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function () {
|
|
127
|
+
return convertStandardSchemaToJsonSchema;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(exports, 'getRegisteredZodJsonSchemas', {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
get: function () {
|
|
133
|
+
return getRegisteredZodJsonSchemas;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
Object.defineProperty(exports, 'getSchemaMetadata', {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
get: function () {
|
|
139
|
+
return getSchemaMetadata;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
Object.defineProperty(exports, 'getZodMetadata', {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function () {
|
|
145
|
+
return getZodMetadata;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
//# sourceMappingURL=conversion-Cf9R-jGc.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion-Cf9R-jGc.cjs","names":["vendor?: string","StandardSchemaJsonSchema: VendorConvertors","jsonSchema: any","componentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t}","schema: any","processed: any","schema?: StandardSchemaV1","schema: StandardSchemaV1","schema: StandardSchemaV1 | undefined"],"sources":["../src/conversion.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\n\nexport enum SchemaVendor {\n\tzod = 'zod',\n\tvalibot = 'valibot',\n}\n\nexport type VendorConvertor = (schema: any) => Promise<any>;\nexport type VendorConvertors = Record<SchemaVendor, VendorConvertor>;\n\nfunction isSchemaVendor(vendor?: string): vendor is SchemaVendor {\n\tif (!vendor) {\n\t\treturn false;\n\t}\n\n\treturn Object.values(SchemaVendor).includes(vendor as SchemaVendor);\n}\n\nexport const StandardSchemaJsonSchema: VendorConvertors = {\n\tzod: async (schema): Promise<any> => {\n\t\ttry {\n\t\t\tconst { z } = await import('zod/v4').catch(() => ({ z: {} }));\n\n\t\t\tif ('toJSONSchema' in z && typeof z.toJSONSchema === 'function') {\n\t\t\t\treturn z.toJSONSchema(schema);\n\t\t\t}\n\t\t\tconst { zodToJsonSchema } = await import('zod-to-json-schema');\n\n\t\t\tconst result = zodToJsonSchema(schema, {\n\t\t\t\tremoveAdditionalStrategy: 'strict',\n\t\t\t});\n\n\t\t\treturn result;\n\t\t} catch {\n\t\t\t// Fallback to basic conversion if zod-to-json-schema is not available\n\t\t\treturn { type: 'object' };\n\t\t}\n\t},\n\tvalibot: async (schema): Promise<any> => {\n\t\tconst { toJsonSchema } = await import('@valibot/to-json-schema');\n\t\treturn toJsonSchema(schema as any);\n\t},\n};\n\nfunction extractAndConvertDefs(\n\tjsonSchema: any,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): any {\n\tif (!jsonSchema || typeof jsonSchema !== 'object') {\n\t\treturn jsonSchema;\n\t}\n\n\t// Process the schema recursively to update references\n\tconst processSchema = (schema: any): any => {\n\t\tif (!schema || typeof schema !== 'object') {\n\t\t\treturn schema;\n\t\t}\n\n\t\t// Handle $ref\n\t\tif (schema.$ref && typeof schema.$ref === 'string') {\n\t\t\t// Convert #/$defs/X to #/components/schemas/X\n\t\t\tif (schema.$ref.startsWith('#/$defs/')) {\n\t\t\t\tconst refName = schema.$ref.replace('#/$defs/', '');\n\t\t\t\treturn componentCollector\n\t\t\t\t\t? componentCollector.getReference(refName)\n\t\t\t\t\t: schema;\n\t\t\t}\n\t\t\treturn schema;\n\t\t}\n\n\t\t// Handle arrays\n\t\tif (Array.isArray(schema)) {\n\t\t\treturn schema.map(processSchema);\n\t\t}\n\n\t\t// Process all properties recursively\n\t\tconst processed: any = {};\n\t\tfor (const [key, value] of Object.entries(schema)) {\n\t\t\tif (key === '$defs') {\n\t\t\t\t// Skip $defs as they've been extracted\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tprocessed[key] = processSchema(value);\n\t\t}\n\t\treturn processed;\n\t};\n\n\t// Extract $defs if present\n\tif (jsonSchema.$defs && componentCollector) {\n\t\tfor (const [defName, defSchema] of Object.entries(jsonSchema.$defs)) {\n\t\t\t// Process the definition recursively to handle nested $refs\n\t\t\tconst processedDefSchema = processSchema(defSchema);\n\t\t\t// Add each definition to the component collector\n\t\t\tcomponentCollector.addSchema(defName, processedDefSchema);\n\t\t}\n\t}\n\n\t// Process the schema and remove $defs\n\tconst { $defs, ...schemaWithoutDefs } = jsonSchema;\n\treturn processSchema(schemaWithoutDefs);\n}\n\nexport async function convertStandardSchemaToJsonSchema(\n\tschema?: StandardSchemaV1,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): Promise<any> {\n\tif (!schema) {\n\t\treturn undefined;\n\t}\n\n\tconst vendor = schema['~standard']?.vendor;\n\tif (!isSchemaVendor(vendor)) {\n\t\tthrow new Error(\n\t\t\t`Unsupported or missing vendor \"${vendor}\" for Standard Schema. Supported vendors are: ${Object.keys(StandardSchemaJsonSchema).join(', ')}`,\n\t\t);\n\t}\n\n\tconst toJSONSchema = StandardSchemaJsonSchema[vendor];\n\tconst jsonSchema = await toJSONSchema(schema);\n\n\t// Extract and convert $defs to components\n\treturn extractAndConvertDefs(jsonSchema, componentCollector);\n}\n\nexport async function getZodMetadata(\n\tschema: StandardSchemaV1,\n): Promise<SchemaMeta | undefined> {\n\tconst { ZodObject } = await import('zod/v4');\n\n\tif (schema instanceof ZodObject) {\n\t\treturn schema.meta();\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Return JSON Schema for every schema registered in zod v4's global registry\n * via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or\n * no schemas are registered.\n *\n * `unrepresentable: 'any'` keeps a single unrepresentable schema from\n * collapsing the whole result.\n */\nexport async function getRegisteredZodJsonSchemas(): Promise<\n\tRecord<string, any>\n> {\n\ttry {\n\t\tconst { z } = await import('zod/v4').catch(() => ({ z: null as any }));\n\t\tif (!z?.toJSONSchema || !z.globalRegistry) {\n\t\t\treturn {};\n\t\t}\n\t\tconst result = z.toJSONSchema(z.globalRegistry, {\n\t\t\tunrepresentable: 'any',\n\t\t});\n\t\treturn (result?.schemas ?? {}) as Record<string, any>;\n\t} catch {\n\t\treturn {};\n\t}\n}\n\nexport async function getSchemaMetadata(\n\tschema: StandardSchemaV1,\n): Promise<SchemaMeta | undefined> {\n\tconst vendor = schema['~standard']?.vendor;\n\n\tif (vendor === 'zod') {\n\t\treturn getZodMetadata(schema);\n\t}\n\n\treturn undefined;\n}\n\ninterface SchemaMeta {\n\tid?: string;\n}\n\nexport async function convertSchemaWithComponents(\n\tschema: StandardSchemaV1 | undefined,\n\tcomponentCollector?: {\n\t\taddSchema(id: string, schema: any): void;\n\t\tgetReference(id: string): { $ref: string };\n\t},\n): Promise<any> {\n\tif (!schema) {\n\t\treturn undefined;\n\t}\n\n\t// Convert to JSON Schema with component collector to handle $defs\n\tconst jsonSchema = await convertStandardSchemaToJsonSchema(\n\t\tschema,\n\t\tcomponentCollector,\n\t);\n\n\tif (!componentCollector) {\n\t\treturn jsonSchema;\n\t}\n\n\t// Check if this schema has metadata with an ID\n\tconst metadata = await getSchemaMetadata(schema);\n\n\t// Also check if the JSON Schema itself has an id field (from Zod's meta)\n\tconst schemaId = metadata?.id || jsonSchema?.id;\n\n\tif (schemaId) {\n\t\t// Remove the id from the schema before adding to components\n\t\tconst { id, ...schemaWithoutId } = jsonSchema;\n\t\t// Add this schema to components and return a reference\n\t\tcomponentCollector.addSchema(schemaId, schema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,MAAM,kCACxB,QACA,mBACA;AAED,MAAK,mBACJ,QAAO;CAIR,MAAM,WAAW,MAAM,kBAAkB,OAAO;CAGhD,MAAM,WAAW,UAAU,MAAM,YAAY;AAE7C,KAAI,UAAU;EAEb,MAAM,EAAE,GAAI,GAAG,iBAAiB,GAAG;AAEnC,qBAAmB,UAAU,UAAU,gBAAgB;AACvD,SAAO,mBAAmB,aAAa,SAAS;CAChD;AAED,QAAO;AACP"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/conversion.d.ts
|
|
4
|
+
declare enum SchemaVendor {
|
|
5
|
+
zod = "zod",
|
|
6
|
+
valibot = "valibot",
|
|
7
|
+
}
|
|
8
|
+
type VendorConvertor = (schema: any) => Promise<any>;
|
|
9
|
+
type VendorConvertors = Record<SchemaVendor, VendorConvertor>;
|
|
10
|
+
declare const StandardSchemaJsonSchema: VendorConvertors;
|
|
11
|
+
declare function convertStandardSchemaToJsonSchema(schema?: StandardSchemaV1, componentCollector?: {
|
|
12
|
+
addSchema(id: string, schema: any): void;
|
|
13
|
+
getReference(id: string): {
|
|
14
|
+
$ref: string;
|
|
15
|
+
};
|
|
16
|
+
}): Promise<any>;
|
|
17
|
+
declare function getZodMetadata(schema: StandardSchemaV1): Promise<SchemaMeta | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Return JSON Schema for every schema registered in zod v4's global registry
|
|
20
|
+
* via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or
|
|
21
|
+
* no schemas are registered.
|
|
22
|
+
*
|
|
23
|
+
* `unrepresentable: 'any'` keeps a single unrepresentable schema from
|
|
24
|
+
* collapsing the whole result.
|
|
25
|
+
*/
|
|
26
|
+
declare function getRegisteredZodJsonSchemas(): Promise<Record<string, any>>;
|
|
27
|
+
declare function getSchemaMetadata(schema: StandardSchemaV1): Promise<SchemaMeta | undefined>;
|
|
28
|
+
interface SchemaMeta {
|
|
29
|
+
id?: string;
|
|
30
|
+
}
|
|
31
|
+
declare function convertSchemaWithComponents(schema: StandardSchemaV1 | undefined, componentCollector?: {
|
|
32
|
+
addSchema(id: string, schema: any): void;
|
|
33
|
+
getReference(id: string): {
|
|
34
|
+
$ref: string;
|
|
35
|
+
};
|
|
36
|
+
}): Promise<any>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { SchemaVendor, StandardSchemaJsonSchema, VendorConvertor, VendorConvertors, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata };
|
|
39
|
+
//# sourceMappingURL=conversion-JY1Wixil.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion-JY1Wixil.d.cts","names":[],"sources":["../src/conversion.ts"],"sourcesContent":[],"mappings":";;;aAEY,YAAA;;EAAA,OAAA,GAAA,SAAY;AAKxB;AACY,KADA,eAAA,GACgB,CAAA,MAAA,EAAA,GAAA,EAAA,GADmB,OACnB,CAAA,GAAA,CAAA;AAAA,KAAhB,gBAAA,GAAmB,MAAH,CAAU,YAAV,EAAwB,eAAxB,CAAA;AAAU,cAUzB,wBAVyB,EAUC,gBAVD;AAAc,iBAiG9B,iCAAA,CAjG8B,MAAA,CAAA,EAkG1C,gBAlG0C,EAAA,kBAiGG,CAjGH,EAAA;EAAe,SAApC,CAAA,EAAA,EAAA,MAAA,EAAA,MAAA,EAAA,GAAA,CAAA,EAAA,IAAA;EAAM,YAAA,CAAA,EAAA,EAAA,MAAA,CAAA,EAAA;IAUxB,IAAA,EAAA,MAAA;EAuFS,CAAA;CAAiC,CAAA,EAMpD,OANoD,CAAA,GAAA,CAAA;AAC7C,iBAwBY,cAAA,CAxBZ,MAAA,EAyBD,gBAzBC,CAAA,EA0BP,OA1BO,CA0BC,UA1BD,GAAA,SAAA,CAAA;;AAKA;AAmBV;;;;;AAEU;AAkBY,iBAAA,2BAAA,CAAA,CAA2B,EAAI,OAAJ,CAChD,MADgD,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA;AAAA,iBAiB3B,iBAAA,CAjB2B,MAAA,EAkBxC,gBAlBwC,CAAA,EAmB9C,OAnB8C,CAmBtC,UAnBsC,GAAA,SAAA,CAAA;UA6BvC,UAAA,CA5BT;EAAM,EAAA,CAD8C,EAAA,MAAA;AAAO;AAiBtC,iBAgBA,2BAAA,CAhBiB,MAAA,EAiB9B,gBAjB8B,GAAA,SAAA,EAAA,kBAE7B,CAF6B,EAAA;EAAA,SAAA,CAAA,EAAA,EAAA,MAAA,EAAA,MAAA,EAAA,GAAA,CAAA,EAAA,IAAA;EAAA,YAC9B,CAAA,EAAA,EAAA,MAAA,CAAA,EAAA;IACE,IAAA,EAAA,MAAA;EAAU,CAAA;AAAX,CAAA,CAAA,EAoBP,OApBO,CAAA,GAAA,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/conversion.d.ts
|
|
4
|
+
declare enum SchemaVendor {
|
|
5
|
+
zod = "zod",
|
|
6
|
+
valibot = "valibot",
|
|
7
|
+
}
|
|
8
|
+
type VendorConvertor = (schema: any) => Promise<any>;
|
|
9
|
+
type VendorConvertors = Record<SchemaVendor, VendorConvertor>;
|
|
10
|
+
declare const StandardSchemaJsonSchema: VendorConvertors;
|
|
11
|
+
declare function convertStandardSchemaToJsonSchema(schema?: StandardSchemaV1, componentCollector?: {
|
|
12
|
+
addSchema(id: string, schema: any): void;
|
|
13
|
+
getReference(id: string): {
|
|
14
|
+
$ref: string;
|
|
15
|
+
};
|
|
16
|
+
}): Promise<any>;
|
|
17
|
+
declare function getZodMetadata(schema: StandardSchemaV1): Promise<SchemaMeta | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Return JSON Schema for every schema registered in zod v4's global registry
|
|
20
|
+
* via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or
|
|
21
|
+
* no schemas are registered.
|
|
22
|
+
*
|
|
23
|
+
* `unrepresentable: 'any'` keeps a single unrepresentable schema from
|
|
24
|
+
* collapsing the whole result.
|
|
25
|
+
*/
|
|
26
|
+
declare function getRegisteredZodJsonSchemas(): Promise<Record<string, any>>;
|
|
27
|
+
declare function getSchemaMetadata(schema: StandardSchemaV1): Promise<SchemaMeta | undefined>;
|
|
28
|
+
interface SchemaMeta {
|
|
29
|
+
id?: string;
|
|
30
|
+
}
|
|
31
|
+
declare function convertSchemaWithComponents(schema: StandardSchemaV1 | undefined, componentCollector?: {
|
|
32
|
+
addSchema(id: string, schema: any): void;
|
|
33
|
+
getReference(id: string): {
|
|
34
|
+
$ref: string;
|
|
35
|
+
};
|
|
36
|
+
}): Promise<any>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { SchemaVendor, StandardSchemaJsonSchema, VendorConvertor, VendorConvertors, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata };
|
|
39
|
+
//# sourceMappingURL=conversion-e4k9rTxy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversion-e4k9rTxy.d.mts","names":[],"sources":["../src/conversion.ts"],"sourcesContent":[],"mappings":";;;aAEY,YAAA;;EAAA,OAAA,GAAA,SAAY;AAKxB;AACY,KADA,eAAA,GACgB,CAAA,MAAA,EAAA,GAAA,EAAA,GADmB,OACnB,CAAA,GAAA,CAAA;AAAA,KAAhB,gBAAA,GAAmB,MAAH,CAAU,YAAV,EAAwB,eAAxB,CAAA;AAAU,cAUzB,wBAVyB,EAUC,gBAVD;AAAc,iBAiG9B,iCAAA,CAjG8B,MAAA,CAAA,EAkG1C,gBAlG0C,EAAA,kBAiGG,CAjGH,EAAA;EAAe,SAApC,CAAA,EAAA,EAAA,MAAA,EAAA,MAAA,EAAA,GAAA,CAAA,EAAA,IAAA;EAAM,YAAA,CAAA,EAAA,EAAA,MAAA,CAAA,EAAA;IAUxB,IAAA,EAAA,MAAA;EAuFS,CAAA;CAAiC,CAAA,EAMpD,OANoD,CAAA,GAAA,CAAA;AAC7C,iBAwBY,cAAA,CAxBZ,MAAA,EAyBD,gBAzBC,CAAA,EA0BP,OA1BO,CA0BC,UA1BD,GAAA,SAAA,CAAA;;AAKA;AAmBV;;;;;AAEU;AAkBY,iBAAA,2BAAA,CAAA,CAA2B,EAAI,OAAJ,CAChD,MADgD,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA;AAAA,iBAiB3B,iBAAA,CAjB2B,MAAA,EAkBxC,gBAlBwC,CAAA,EAmB9C,OAnB8C,CAmBtC,UAnBsC,GAAA,SAAA,CAAA;UA6BvC,UAAA,CA5BT;EAAM,EAAA,CAD8C,EAAA,MAAA;AAAO;AAiBtC,iBAgBA,2BAAA,CAhBiB,MAAA,EAiB9B,gBAjB8B,GAAA,SAAA,EAAA,kBAE7B,CAF6B,EAAA;EAAA,SAAA,CAAA,EAAA,EAAA,MAAA,EAAA,MAAA,EAAA,GAAA,CAAA,EAAA,IAAA;EAAA,YAC9B,CAAA,EAAA,EAAA,MAAA,CAAA,EAAA;IACE,IAAA,EAAA,MAAA;EAAU,CAAA;AAAX,CAAA,CAAA,EAoBP,OApBO,CAAA,GAAA,CAAA"}
|
package/dist/conversion.cjs
CHANGED
|
@@ -1,107 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/conversion.ts
|
|
3
|
-
let SchemaVendor = /* @__PURE__ */ function(SchemaVendor) {
|
|
4
|
-
SchemaVendor["zod"] = "zod";
|
|
5
|
-
SchemaVendor["valibot"] = "valibot";
|
|
6
|
-
return SchemaVendor;
|
|
7
|
-
}({});
|
|
8
|
-
function isSchemaVendor(vendor) {
|
|
9
|
-
if (!vendor) return false;
|
|
10
|
-
return Object.values(SchemaVendor).includes(vendor);
|
|
11
|
-
}
|
|
12
|
-
const StandardSchemaJsonSchema = {
|
|
13
|
-
zod: async (schema) => {
|
|
14
|
-
try {
|
|
15
|
-
const { z } = await import("zod/v4").catch(() => ({ z: {} }));
|
|
16
|
-
if ("toJSONSchema" in z && typeof z.toJSONSchema === "function") return z.toJSONSchema(schema);
|
|
17
|
-
const { zodToJsonSchema } = await import("zod-to-json-schema");
|
|
18
|
-
return zodToJsonSchema(schema, { removeAdditionalStrategy: "strict" });
|
|
19
|
-
} catch {
|
|
20
|
-
return { type: "object" };
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
valibot: async (schema) => {
|
|
24
|
-
const { toJsonSchema } = await import("@valibot/to-json-schema");
|
|
25
|
-
return toJsonSchema(schema);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
function extractAndConvertDefs(jsonSchema, componentCollector) {
|
|
29
|
-
if (!jsonSchema || typeof jsonSchema !== "object") return jsonSchema;
|
|
30
|
-
const processSchema = (schema) => {
|
|
31
|
-
if (!schema || typeof schema !== "object") return schema;
|
|
32
|
-
if (schema.$ref && typeof schema.$ref === "string") {
|
|
33
|
-
if (schema.$ref.startsWith("#/$defs/")) {
|
|
34
|
-
const refName = schema.$ref.replace("#/$defs/", "");
|
|
35
|
-
return componentCollector ? componentCollector.getReference(refName) : schema;
|
|
36
|
-
}
|
|
37
|
-
return schema;
|
|
38
|
-
}
|
|
39
|
-
if (Array.isArray(schema)) return schema.map(processSchema);
|
|
40
|
-
const processed = {};
|
|
41
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
42
|
-
if (key === "$defs" || key === "$schema") continue;
|
|
43
|
-
processed[key] = processSchema(value);
|
|
44
|
-
}
|
|
45
|
-
return processed;
|
|
46
|
-
};
|
|
47
|
-
if (jsonSchema.$defs && componentCollector) for (const [defName, defSchema] of Object.entries(jsonSchema.$defs)) {
|
|
48
|
-
const processedDefSchema = processSchema(defSchema);
|
|
49
|
-
componentCollector.addSchema(defName, processedDefSchema);
|
|
50
|
-
}
|
|
51
|
-
const { $defs, ...schemaWithoutDefs } = jsonSchema;
|
|
52
|
-
return processSchema(schemaWithoutDefs);
|
|
53
|
-
}
|
|
54
|
-
async function convertStandardSchemaToJsonSchema(schema, componentCollector) {
|
|
55
|
-
if (!schema) return;
|
|
56
|
-
const vendor = schema["~standard"]?.vendor;
|
|
57
|
-
if (!isSchemaVendor(vendor)) throw new Error(`Unsupported or missing vendor "${vendor}" for Standard Schema. Supported vendors are: ${Object.keys(StandardSchemaJsonSchema).join(", ")}`);
|
|
58
|
-
const toJSONSchema = StandardSchemaJsonSchema[vendor];
|
|
59
|
-
return extractAndConvertDefs(await toJSONSchema(schema), componentCollector);
|
|
60
|
-
}
|
|
61
|
-
async function getZodMetadata(schema) {
|
|
62
|
-
const { ZodObject } = await import("zod/v4");
|
|
63
|
-
if (schema instanceof ZodObject) return schema.meta();
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Return JSON Schema for every schema registered in zod v4's global registry
|
|
67
|
-
* via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or
|
|
68
|
-
* no schemas are registered.
|
|
69
|
-
*
|
|
70
|
-
* `unrepresentable: 'any'` keeps a single unrepresentable schema from
|
|
71
|
-
* collapsing the whole result.
|
|
72
|
-
*/
|
|
73
|
-
async function getRegisteredZodJsonSchemas() {
|
|
74
|
-
try {
|
|
75
|
-
const { z } = await import("zod/v4").catch(() => ({ z: null }));
|
|
76
|
-
if (!z?.toJSONSchema || !z.globalRegistry) return {};
|
|
77
|
-
return z.toJSONSchema(z.globalRegistry, { unrepresentable: "any" })?.schemas ?? {};
|
|
78
|
-
} catch {
|
|
79
|
-
return {};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async function getSchemaMetadata(schema) {
|
|
83
|
-
if (schema["~standard"]?.vendor === "zod") return getZodMetadata(schema);
|
|
84
|
-
}
|
|
85
|
-
async function convertSchemaWithComponents(schema, componentCollector) {
|
|
86
|
-
if (!schema) return;
|
|
87
|
-
const jsonSchema = await convertStandardSchemaToJsonSchema(schema, componentCollector);
|
|
88
|
-
if (!componentCollector) return jsonSchema;
|
|
89
|
-
const schemaId = (await getSchemaMetadata(schema))?.id || jsonSchema?.id;
|
|
90
|
-
if (schemaId) {
|
|
91
|
-
if (typeof jsonSchema?.$ref === "string") return componentCollector.getReference(schemaId);
|
|
92
|
-
const { id, ...schemaWithoutId } = jsonSchema;
|
|
93
|
-
componentCollector.addSchema(schemaId, schemaWithoutId);
|
|
94
|
-
return componentCollector.getReference(schemaId);
|
|
95
|
-
}
|
|
96
|
-
return jsonSchema;
|
|
97
|
-
}
|
|
98
|
-
//#endregion
|
|
99
|
-
exports.SchemaVendor = SchemaVendor;
|
|
100
|
-
exports.StandardSchemaJsonSchema = StandardSchemaJsonSchema;
|
|
101
|
-
exports.convertSchemaWithComponents = convertSchemaWithComponents;
|
|
102
|
-
exports.convertStandardSchemaToJsonSchema = convertStandardSchemaToJsonSchema;
|
|
103
|
-
exports.getRegisteredZodJsonSchemas = getRegisteredZodJsonSchemas;
|
|
104
|
-
exports.getSchemaMetadata = getSchemaMetadata;
|
|
105
|
-
exports.getZodMetadata = getZodMetadata;
|
|
1
|
+
const require_conversion = require('./conversion-Cf9R-jGc.cjs');
|
|
106
2
|
|
|
107
|
-
|
|
3
|
+
exports.SchemaVendor = require_conversion.SchemaVendor;
|
|
4
|
+
exports.StandardSchemaJsonSchema = require_conversion.StandardSchemaJsonSchema;
|
|
5
|
+
exports.convertSchemaWithComponents = require_conversion.convertSchemaWithComponents;
|
|
6
|
+
exports.convertStandardSchemaToJsonSchema = require_conversion.convertStandardSchemaToJsonSchema;
|
|
7
|
+
exports.getRegisteredZodJsonSchemas = require_conversion.getRegisteredZodJsonSchemas;
|
|
8
|
+
exports.getSchemaMetadata = require_conversion.getSchemaMetadata;
|
|
9
|
+
exports.getZodMetadata = require_conversion.getZodMetadata;
|
package/dist/conversion.d.cts
CHANGED
|
@@ -1,37 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare enum SchemaVendor {
|
|
4
|
-
zod = "zod",
|
|
5
|
-
valibot = "valibot"
|
|
6
|
-
}
|
|
7
|
-
export type VendorConvertor = (schema: any) => Promise<any>;
|
|
8
|
-
export type VendorConvertors = Record<SchemaVendor, VendorConvertor>;
|
|
9
|
-
export declare const StandardSchemaJsonSchema: VendorConvertors;
|
|
10
|
-
export declare function convertStandardSchemaToJsonSchema(schema?: StandardSchemaV1, componentCollector?: {
|
|
11
|
-
addSchema(id: string, schema: any): void;
|
|
12
|
-
getReference(id: string): {
|
|
13
|
-
$ref: string;
|
|
14
|
-
};
|
|
15
|
-
}): Promise<any>;
|
|
16
|
-
export declare function getZodMetadata(schema: StandardSchemaV1): Promise<SchemaMeta | undefined>;
|
|
17
|
-
/**
|
|
18
|
-
* Return JSON Schema for every schema registered in zod v4's global registry
|
|
19
|
-
* via `.meta({ id })`. Returns an empty object when zod v4 is unavailable or
|
|
20
|
-
* no schemas are registered.
|
|
21
|
-
*
|
|
22
|
-
* `unrepresentable: 'any'` keeps a single unrepresentable schema from
|
|
23
|
-
* collapsing the whole result.
|
|
24
|
-
*/
|
|
25
|
-
export declare function getRegisteredZodJsonSchemas(): Promise<Record<string, any>>;
|
|
26
|
-
export declare function getSchemaMetadata(schema: StandardSchemaV1): Promise<SchemaMeta | undefined>;
|
|
27
|
-
interface SchemaMeta {
|
|
28
|
-
id?: string;
|
|
29
|
-
}
|
|
30
|
-
export declare function convertSchemaWithComponents(schema: StandardSchemaV1 | undefined, componentCollector?: {
|
|
31
|
-
addSchema(id: string, schema: any): void;
|
|
32
|
-
getReference(id: string): {
|
|
33
|
-
$ref: string;
|
|
34
|
-
};
|
|
35
|
-
}): Promise<any>;
|
|
36
|
-
//#endregion
|
|
37
|
-
//# sourceMappingURL=conversion.d.cts.map
|
|
1
|
+
import { SchemaVendor, StandardSchemaJsonSchema, VendorConvertor, VendorConvertors, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata } from "./conversion-JY1Wixil.cjs";
|
|
2
|
+
export { SchemaVendor, StandardSchemaJsonSchema, VendorConvertor, VendorConvertors, convertSchemaWithComponents, convertStandardSchemaToJsonSchema, getRegisteredZodJsonSchemas, getSchemaMetadata, getZodMetadata };
|