@geekmidas/schema 10.0.0-alpha.98 → 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/dist/parser.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.mts","names":[],"sources":["../src/parser.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"parser.d.mts","names":[],"sources":["../src/parser.ts"],"sourcesContent":[],"mappings":";;;;;;;AAUA;;;;;AAA6E,iBAA7D,QAA6D,CAAA,UAA1C,gBAA0C,CAAA,CAAA,MAAA,EAAhB,CAAgB,EAAA,IAAA,EAAA,OAAA,CAAA,EAAA,gBAAA,CAAA,MAAA,CAAA,OAAA,CAAA,GAAA,OAAA,CAAA,gBAAA,CAAA,MAAA,CAAA,OAAA,CAAA,CAAA;AAAA,iBAIvD,WAJuD,CAAA,UAIjC,gBAJiC,CAAA,CAAA,MAAA,EAKpE,CALoE,EAAA,IAAA,EAAA,OAAA,CAAA,EAO1E,OAP0E,CAOlE,mBAPkE,CAO9C,CAP8C,CAAA,CAAA;AAAA"}
|
package/dist/parser.mjs
CHANGED
|
@@ -10,12 +10,12 @@ function validate(schema, data) {
|
|
|
10
10
|
return schema["~standard"].validate(data);
|
|
11
11
|
}
|
|
12
12
|
async function parseSchema(schema, data) {
|
|
13
|
-
if (!schema) return;
|
|
13
|
+
if (!schema) return void 0;
|
|
14
14
|
const parsed = await validate(schema, data);
|
|
15
15
|
if (parsed.issues) throw parsed.issues;
|
|
16
16
|
return parsed.value;
|
|
17
17
|
}
|
|
18
|
+
|
|
18
19
|
//#endregion
|
|
19
20
|
export { parseSchema, validate };
|
|
20
|
-
|
|
21
21
|
//# sourceMappingURL=parser.mjs.map
|
package/dist/parser.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.mjs","names":[],"sources":["../src/parser.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { InferStandardSchema } from './types';\n\n/**\n * Validates data against a StandardSchema.\n *\n * @param schema - The StandardSchema to validate against\n * @param data - The data to validate\n * @returns Validation result with value or issues\n */\nexport function validate<T extends StandardSchemaV1>(schema: T, data: unknown) {\n\treturn schema['~standard'].validate(data);\n}\n\nexport async function parseSchema<T extends StandardSchemaV1>(\n\tschema: T,\n\tdata: unknown,\n): Promise<InferStandardSchema<T>> {\n\tif (!schema) {\n\t\treturn undefined as InferStandardSchema<T>;\n\t}\n\n\tconst parsed = await validate(schema as unknown as StandardSchemaV1, data);\n\n\tif (parsed.issues) {\n\t\tthrow parsed.issues;\n\t}\n\n\treturn parsed.value as InferStandardSchema<T>;\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,
|
|
1
|
+
{"version":3,"file":"parser.mjs","names":["schema: T","data: unknown"],"sources":["../src/parser.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { InferStandardSchema } from './types';\n\n/**\n * Validates data against a StandardSchema.\n *\n * @param schema - The StandardSchema to validate against\n * @param data - The data to validate\n * @returns Validation result with value or issues\n */\nexport function validate<T extends StandardSchemaV1>(schema: T, data: unknown) {\n\treturn schema['~standard'].validate(data);\n}\n\nexport async function parseSchema<T extends StandardSchemaV1>(\n\tschema: T,\n\tdata: unknown,\n): Promise<InferStandardSchema<T>> {\n\tif (!schema) {\n\t\treturn undefined as InferStandardSchema<T>;\n\t}\n\n\tconst parsed = await validate(schema as unknown as StandardSchemaV1, data);\n\n\tif (parsed.issues) {\n\t\tthrow parsed.issues;\n\t}\n\n\treturn parsed.value as InferStandardSchema<T>;\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,SAAqCA,QAAWC,MAAe;AAC9E,QAAO,OAAO,aAAa,SAAS,KAAK;AACzC;AAED,eAAsB,YACrBD,QACAC,MACkC;AAClC,MAAK,OACJ;CAGD,MAAM,SAAS,MAAM,SAAS,QAAuC,KAAK;AAE1E,KAAI,OAAO,OACV,OAAM,OAAO;AAGd,QAAO,OAAO;AACd"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type InferStandardSchema<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : never;
|
|
5
|
+
/**
|
|
6
|
+
* The *input* type a Standard Schema accepts (before any transform/coercion),
|
|
7
|
+
* as opposed to {@link InferStandardSchema} which is the output type.
|
|
8
|
+
*
|
|
9
|
+
* Use this for the value a producer must HAND TO the schema (e.g. an endpoint
|
|
10
|
+
* handler's return that will be parsed by its output schema): the schema may
|
|
11
|
+
* coerce it (a `Date` → an ISO `string`, a default applied, etc.), so the
|
|
12
|
+
* producer should be allowed to supply the looser input type while consumers
|
|
13
|
+
* still see the narrower output type.
|
|
14
|
+
*/
|
|
15
|
+
type InferStandardSchemaInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : never;
|
|
16
|
+
type ComposableStandardSchema = StandardSchemaV1 | {
|
|
17
|
+
[key: string]: StandardSchemaV1 | undefined;
|
|
18
|
+
};
|
|
19
|
+
type InferComposableStandardSchema<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : T extends {
|
|
20
|
+
[key: string]: StandardSchemaV1 | undefined;
|
|
21
|
+
} ? { [K in keyof T as T[K] extends StandardSchemaV1 ? K : never]: T[K] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T[K]> : never } : {};
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput };
|
|
26
|
+
//# sourceMappingURL=types-Bm3VhqVE.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-Bm3VhqVE.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;KAEY,yBAAyB,UAAU,mBAC5C,gBAAA,CAAiB,YAAY;;AADhC;;;;;;AAC+B;AAa/B;;AAA0C,KAA9B,wBAA8B,CAAA,CAAA,CAAA,GAAA,CAAA,SAAU,gBAAV,GACvC,gBAAA,CAAiB,UADsB,CACX,CADW,CAAA,GAAA,KAAA;AAAU,KAIxC,wBAAA,GACT,gBALiD,GAAA;EAAgB,CAAA,GACrC,EAAA,MAAA,CAAA,EAMb,gBANa,GAAA,SAAA;CAAC;AAAF,KASlB,6BATkB,CAAA,CAAA,CAAA,GASiB,CATjB,SAS2B,gBAT3B,GAU3B,gBAAA,CAAiB,WAVU,CAUE,CAVF,CAAA,GAW3B,CAX2B,SAAA;EAGlB,CAAA,GAAA,EAAA,MAAA,CAAA,EAQkB,gBARM,GAAA,SAAA;CAAA,GAAA,QACjC,MASa,CATb,IASkB,CATlB,CASoB,CATpB,CAAA,SAS+B,gBAT/B,GAUI,CAVJ,GAAA,KAAA,GAWY,CAXZ,CAWc,CAXd,CAAA,SAWyB,gBAXzB,GAYI,gBAAA,CAAiB,WAZrB,CAYiC,CAZjC,CAYmC,CAZnC,CAAA,CAAA,GAAA,KAAA,EAAgB,GAAA,CAAA,CAAA;AAEe"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type InferStandardSchema<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : never;
|
|
5
|
+
/**
|
|
6
|
+
* The *input* type a Standard Schema accepts (before any transform/coercion),
|
|
7
|
+
* as opposed to {@link InferStandardSchema} which is the output type.
|
|
8
|
+
*
|
|
9
|
+
* Use this for the value a producer must HAND TO the schema (e.g. an endpoint
|
|
10
|
+
* handler's return that will be parsed by its output schema): the schema may
|
|
11
|
+
* coerce it (a `Date` → an ISO `string`, a default applied, etc.), so the
|
|
12
|
+
* producer should be allowed to supply the looser input type while consumers
|
|
13
|
+
* still see the narrower output type.
|
|
14
|
+
*/
|
|
15
|
+
type InferStandardSchemaInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : never;
|
|
16
|
+
type ComposableStandardSchema = StandardSchemaV1 | {
|
|
17
|
+
[key: string]: StandardSchemaV1 | undefined;
|
|
18
|
+
};
|
|
19
|
+
type InferComposableStandardSchema<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : T extends {
|
|
20
|
+
[key: string]: StandardSchemaV1 | undefined;
|
|
21
|
+
} ? { [K in keyof T as T[K] extends StandardSchemaV1 ? K : never]: T[K] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T[K]> : never } : {};
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput };
|
|
26
|
+
//# sourceMappingURL=types-xm7EGhin.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-xm7EGhin.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;KAEY,yBAAyB,UAAU,mBAC5C,gBAAA,CAAiB,YAAY;;AADhC;;;;;;AAC+B;AAa/B;;AAA0C,KAA9B,wBAA8B,CAAA,CAAA,CAAA,GAAA,CAAA,SAAU,gBAAV,GACvC,gBAAA,CAAiB,UADsB,CACX,CADW,CAAA,GAAA,KAAA;AAAU,KAIxC,wBAAA,GACT,gBALiD,GAAA;EAAgB,CAAA,GACrC,EAAA,MAAA,CAAA,EAMb,gBANa,GAAA,SAAA;CAAC;AAAF,KASlB,6BATkB,CAAA,CAAA,CAAA,GASiB,CATjB,SAS2B,gBAT3B,GAU3B,gBAAA,CAAiB,WAVU,CAUE,CAVF,CAAA,GAW3B,CAX2B,SAAA;EAGlB,CAAA,GAAA,EAAA,MAAA,CAAA,EAQkB,gBARM,GAAA,SAAA;CAAA,GAAA,QACjC,MASa,CATb,IASkB,CATlB,CASoB,CATpB,CAAA,SAS+B,gBAT/B,GAUI,CAVJ,GAAA,KAAA,GAWY,CAXZ,CAWc,CAXd,CAAA,SAWyB,gBAXzB,GAYI,gBAAA,CAAiB,WAZrB,CAYiC,CAZjC,CAYmC,CAZnC,CAAA,CAAA,GAAA,KAAA,EAAgB,GAAA,CAAA,CAAA;AAEe"}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export type InferStandardSchema<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : never;
|
|
4
|
-
/**
|
|
5
|
-
* The *input* type a Standard Schema accepts (before any transform/coercion),
|
|
6
|
-
* as opposed to {@link InferStandardSchema} which is the output type.
|
|
7
|
-
*
|
|
8
|
-
* Use this for the value a producer must HAND TO the schema (e.g. an endpoint
|
|
9
|
-
* handler's return that will be parsed by its output schema): the schema may
|
|
10
|
-
* coerce it (a `Date` → an ISO `string`, a default applied, etc.), so the
|
|
11
|
-
* producer should be allowed to supply the looser input type while consumers
|
|
12
|
-
* still see the narrower output type.
|
|
13
|
-
*/
|
|
14
|
-
export type InferStandardSchemaInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : never;
|
|
15
|
-
export type ComposableStandardSchema = StandardSchemaV1 | {
|
|
16
|
-
[key: string]: StandardSchemaV1 | undefined;
|
|
17
|
-
};
|
|
18
|
-
export type InferComposableStandardSchema<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : T extends {
|
|
19
|
-
[key: string]: StandardSchemaV1 | undefined;
|
|
20
|
-
} ? { [K in keyof T as T[K] extends StandardSchemaV1 ? K : never]: T[K] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T[K]> : never; } : {};
|
|
21
|
-
//#endregion
|
|
22
|
-
//# sourceMappingURL=types.d.cts.map
|
|
1
|
+
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput } from "./types-Bm3VhqVE.cjs";
|
|
2
|
+
export { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export type InferStandardSchema<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : never;
|
|
4
|
-
/**
|
|
5
|
-
* The *input* type a Standard Schema accepts (before any transform/coercion),
|
|
6
|
-
* as opposed to {@link InferStandardSchema} which is the output type.
|
|
7
|
-
*
|
|
8
|
-
* Use this for the value a producer must HAND TO the schema (e.g. an endpoint
|
|
9
|
-
* handler's return that will be parsed by its output schema): the schema may
|
|
10
|
-
* coerce it (a `Date` → an ISO `string`, a default applied, etc.), so the
|
|
11
|
-
* producer should be allowed to supply the looser input type while consumers
|
|
12
|
-
* still see the narrower output type.
|
|
13
|
-
*/
|
|
14
|
-
export type InferStandardSchemaInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : never;
|
|
15
|
-
export type ComposableStandardSchema = StandardSchemaV1 | {
|
|
16
|
-
[key: string]: StandardSchemaV1 | undefined;
|
|
17
|
-
};
|
|
18
|
-
export type InferComposableStandardSchema<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : T extends {
|
|
19
|
-
[key: string]: StandardSchemaV1 | undefined;
|
|
20
|
-
} ? { [K in keyof T as T[K] extends StandardSchemaV1 ? K : never]: T[K] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T[K]> : never; } : {};
|
|
21
|
-
//#endregion
|
|
22
|
-
//# sourceMappingURL=types.d.mts.map
|
|
1
|
+
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput } from "./types-xm7EGhin.mjs";
|
|
2
|
+
export { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema, InferStandardSchemaInput };
|
package/dist/types.mjs
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/schema",
|
|
3
|
-
"version": "10.0.0
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -44,9 +44,6 @@
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
-
"files": [
|
|
48
|
-
"dist"
|
|
49
|
-
],
|
|
50
47
|
"repository": {
|
|
51
48
|
"type": "git",
|
|
52
49
|
"url": "https://github.com/geekmidas/toolbox"
|
|
@@ -56,20 +53,16 @@
|
|
|
56
53
|
"access": "public"
|
|
57
54
|
},
|
|
58
55
|
"dependencies": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
},
|
|
62
|
-
"devDependencies": {
|
|
63
|
-
"@valibot/to-json-schema": "~1.8.0",
|
|
64
|
-
"valibot": "~1.5.0"
|
|
56
|
+
"openapi-types": "~12.1.3",
|
|
57
|
+
"@standard-schema/spec": "~1.0.0"
|
|
65
58
|
},
|
|
59
|
+
"devDependencies": {},
|
|
66
60
|
"peerDependencies": {
|
|
67
|
-
"@valibot/to-json-schema": ">=1.
|
|
68
|
-
"zod": "
|
|
69
|
-
"zod
|
|
61
|
+
"@valibot/to-json-schema": ">=1.3.0",
|
|
62
|
+
"zod-to-json-schema": "~3.25.1",
|
|
63
|
+
"zod": "~4.1.13"
|
|
70
64
|
},
|
|
71
65
|
"scripts": {
|
|
72
|
-
"ts": "tsc --noEmit --skipLibCheck src/**/*.ts"
|
|
73
|
-
"build": "tsdown --config ../../tsdown.config.ts --filter ."
|
|
66
|
+
"ts": "tsc --noEmit --skipLibCheck src/**/*.ts"
|
|
74
67
|
}
|
|
75
68
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { bench, describe } from 'vitest';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { convertStandardSchemaToJsonSchema } from '../conversion';
|
|
4
|
+
|
|
5
|
+
describe('Schema Conversion - Simple', () => {
|
|
6
|
+
const simpleSchema = z.object({
|
|
7
|
+
id: z.string(),
|
|
8
|
+
name: z.string(),
|
|
9
|
+
email: z.string().email(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
bench('simple object schema', async () => {
|
|
13
|
+
await convertStandardSchemaToJsonSchema(simpleSchema);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const primitiveSchema = z.string();
|
|
17
|
+
bench('primitive string schema', async () => {
|
|
18
|
+
await convertStandardSchemaToJsonSchema(primitiveSchema);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const arraySchema = z.array(z.string());
|
|
22
|
+
bench('array of strings schema', async () => {
|
|
23
|
+
await convertStandardSchemaToJsonSchema(arraySchema);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('Schema Conversion - Complex', () => {
|
|
28
|
+
const nestedSchema = z.object({
|
|
29
|
+
user: z.object({
|
|
30
|
+
profile: z.object({
|
|
31
|
+
name: z.string(),
|
|
32
|
+
bio: z.string().optional(),
|
|
33
|
+
settings: z.record(z.string(), z.unknown()),
|
|
34
|
+
}),
|
|
35
|
+
contacts: z.array(
|
|
36
|
+
z.object({
|
|
37
|
+
type: z.enum(['email', 'phone']),
|
|
38
|
+
value: z.string(),
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
41
|
+
}),
|
|
42
|
+
metadata: z.object({
|
|
43
|
+
createdAt: z.string(),
|
|
44
|
+
updatedAt: z.string(),
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
bench('deeply nested schema', async () => {
|
|
49
|
+
await convertStandardSchemaToJsonSchema(nestedSchema);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const unionSchema = z.discriminatedUnion('type', [
|
|
53
|
+
z.object({ type: z.literal('text'), content: z.string() }),
|
|
54
|
+
z.object({ type: z.literal('image'), url: z.string() }),
|
|
55
|
+
z.object({
|
|
56
|
+
type: z.literal('video'),
|
|
57
|
+
url: z.string(),
|
|
58
|
+
duration: z.number(),
|
|
59
|
+
}),
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
bench('discriminated union schema', async () => {
|
|
63
|
+
await convertStandardSchemaToJsonSchema(unionSchema);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const largeSchema = z.object(
|
|
67
|
+
Object.fromEntries(
|
|
68
|
+
Array.from({ length: 50 }, (_, i) => [`field${i}`, z.string()]),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
bench('large object (50 fields)', async () => {
|
|
73
|
+
await convertStandardSchemaToJsonSchema(largeSchema);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('Schema Conversion - With Refinements', () => {
|
|
78
|
+
const refinedSchema = z.object({
|
|
79
|
+
age: z.number().min(0).max(150),
|
|
80
|
+
email: z.string().email(),
|
|
81
|
+
url: z.string().url(),
|
|
82
|
+
uuid: z.string().uuid(),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
bench('schema with refinements', async () => {
|
|
86
|
+
await convertStandardSchemaToJsonSchema(refinedSchema);
|
|
87
|
+
});
|
|
88
|
+
});
|