@korix/zod-schema 0.1.0-20250713.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mitz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,76 @@
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") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const __korix_kori = __toESM(require("@korix/kori"));
25
+ const zod_v4 = __toESM(require("zod/v4"));
26
+ const fast_json_stringify = __toESM(require("fast-json-stringify"));
27
+
28
+ //#region src/fast-json.ts
29
+ function zodToFastSerializer(schema) {
30
+ if (!isKoriZodSchema(schema)) return void 0;
31
+ try {
32
+ const jsonSchema = zod_v4.z.toJSONSchema(schema.def);
33
+ return (0, fast_json_stringify.default)(jsonSchema);
34
+ } catch {
35
+ return void 0;
36
+ }
37
+ }
38
+
39
+ //#endregion
40
+ //#region src/zod-schema.ts
41
+ const ZodSchemaBrand = Symbol("zod-schema-brand");
42
+ const provider = {
43
+ __provider: "zod",
44
+ toFastSerializer: zodToFastSerializer
45
+ };
46
+ const createKoriZodSchema = (schema) => {
47
+ return (0, __korix_kori.createKoriSchema)(ZodSchemaBrand, schema, provider);
48
+ };
49
+ function isKoriZodSchema(value) {
50
+ if (!(0, __korix_kori.isKoriSchema)(value)) return false;
51
+ return (0, __korix_kori.getKoriSchemaBrand)(value) === ZodSchemaBrand;
52
+ }
53
+
54
+ //#endregion
55
+ //#region src/zod-request-schema.ts
56
+ function zodRequestSchema(input) {
57
+ const result = {};
58
+ if (input.params) result.params = createKoriZodSchema(input.params);
59
+ if (input.headers) result.headers = createKoriZodSchema(input.headers);
60
+ if (input.queries) result.queries = createKoriZodSchema(input.queries);
61
+ if (input.body) result.body = createKoriZodSchema(input.body);
62
+ return result;
63
+ }
64
+
65
+ //#endregion
66
+ //#region src/zod-response-schema.ts
67
+ function zodResponseSchema(schema) {
68
+ return schema;
69
+ }
70
+
71
+ //#endregion
72
+ exports.createKoriZodSchema = createKoriZodSchema;
73
+ exports.isKoriZodSchema = isKoriZodSchema;
74
+ exports.zodRequestSchema = zodRequestSchema;
75
+ exports.zodResponseSchema = zodResponseSchema;
76
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["schema: KoriSchemaDefault","schema: T","value: unknown","input: {\n params?: TParams;\n headers?: THeaders;\n queries?: TQueries;\n body?: TBody;\n}","result: Record<string, KoriZodSchema<z.ZodType>>","schema: KoriResponseSchemaStructure<S>"],"sources":["../src/fast-json.ts","../src/zod-schema.ts","../src/zod-request-schema.ts","../src/zod-response-schema.ts"],"sourcesContent":["import { type KoriSchemaDefault } from '@korix/kori';\nimport fastJson from 'fast-json-stringify';\nimport { z } from 'zod/v4';\n\nimport { isKoriZodSchema } from './zod-schema.js';\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function zodToFastSerializer(schema: KoriSchemaDefault) {\n if (!isKoriZodSchema(schema)) return undefined;\n try {\n const jsonSchema = z.toJSONSchema(schema.def as unknown as z.ZodType);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n return fastJson(jsonSchema as any);\n } catch {\n return undefined;\n }\n}\n","import {\n type KoriSchema,\n type KoriSchemaProvider,\n createKoriSchema,\n isKoriSchema,\n getKoriSchemaBrand,\n} from '@korix/kori';\nimport { type z } from 'zod/v4';\n\nimport { zodToFastSerializer } from './fast-json.js';\n\nconst ZodSchemaBrand = Symbol('zod-schema-brand');\n\nexport type KoriZodSchemaProvider = KoriSchemaProvider<'zod'>;\n\nexport type KoriZodSchema<T extends z.ZodType> = KoriSchema<T, z.output<T>>;\n\nexport type KoriZodSchemaDefault = KoriZodSchema<z.ZodType>;\n\nconst provider = {\n __provider: 'zod',\n toFastSerializer: zodToFastSerializer,\n} as const;\n\nexport const createKoriZodSchema = <T extends z.ZodType>(schema: T): KoriZodSchema<T> => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return createKoriSchema(ZodSchemaBrand, schema, provider as any);\n};\n\nexport function isKoriZodSchema(value: unknown): value is KoriZodSchemaDefault {\n if (!isKoriSchema(value)) return false;\n return getKoriSchemaBrand(value) === ZodSchemaBrand;\n}\n","import {\n type KoriRequestSchema,\n type KoriRequestSchemaStructure,\n type KoriRequestSchemaContent,\n type KoriRequestSchemaBody,\n} from '@korix/kori';\nimport { type z } from 'zod/v4';\n\nimport { type KoriZodSchema, type KoriZodSchemaProvider, createKoriZodSchema } from './zod-schema.js';\n\nexport type KoriZodRequestSchema<\n Params extends KoriZodSchema<z.ZodType> = never,\n Headers extends KoriZodSchema<z.ZodType> = never,\n Queries extends KoriZodSchema<z.ZodType> = never,\n Body extends KoriZodSchema<z.ZodType> = never,\n> = KoriRequestSchema<KoriZodSchemaProvider, Params, Headers, Queries, Body>;\n\nexport type KoriZodRequestParts = KoriRequestSchemaStructure<\n KoriZodSchema<z.ZodType>,\n KoriZodSchema<z.ZodType>,\n KoriZodSchema<z.ZodType>,\n KoriZodSchema<z.ZodType>\n>;\n\nexport type KoriZodRequestBodySchema =\n | KoriZodSchema<z.ZodType>\n | KoriRequestSchemaContent<KoriZodSchema<z.ZodType>>\n | KoriRequestSchemaBody<KoriZodSchema<z.ZodType>>;\n\ntype ToKoriZodSchema<T extends z.ZodType> = KoriZodSchema<T>;\n\nexport function zodRequestSchema<\n TParams extends z.ZodType | undefined = undefined,\n THeaders extends z.ZodType | undefined = undefined,\n TQueries extends z.ZodType | undefined = undefined,\n TBody extends z.ZodType | undefined = undefined,\n>(input: {\n params?: TParams;\n headers?: THeaders;\n queries?: TQueries;\n body?: TBody;\n}): KoriZodRequestSchema<\n TParams extends z.ZodType ? ToKoriZodSchema<TParams> : never,\n THeaders extends z.ZodType ? ToKoriZodSchema<THeaders> : never,\n TQueries extends z.ZodType ? ToKoriZodSchema<TQueries> : never,\n TBody extends z.ZodType ? ToKoriZodSchema<TBody> : never\n> {\n const result: Record<string, KoriZodSchema<z.ZodType>> = {};\n\n if (input.params) {\n result.params = createKoriZodSchema(input.params);\n }\n\n if (input.headers) {\n result.headers = createKoriZodSchema(input.headers);\n }\n\n if (input.queries) {\n result.queries = createKoriZodSchema(input.queries);\n }\n\n if (input.body) {\n result.body = createKoriZodSchema(input.body);\n }\n\n return result;\n}\n","import { type KoriResponseSchema, type KoriResponseSchemaStructure } from '@korix/kori';\nimport { type z } from 'zod/v4';\n\nimport { type KoriZodSchema, type KoriZodSchemaProvider } from './zod-schema.js';\n\nexport type KoriZodResponseSchema<S extends KoriZodSchema<z.ZodType>> = KoriResponseSchema<KoriZodSchemaProvider, S>;\n\nexport function zodResponseSchema<S extends KoriZodSchema<z.ZodType>>(\n schema: KoriResponseSchemaStructure<S>,\n): KoriZodResponseSchema<S> {\n return schema;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAAgB,oBAAoBA,QAA2B;AAC7D,MAAK,gBAAgB,OAAO,CAAE;AAC9B,KAAI;EACF,MAAM,aAAa,SAAE,aAAa,OAAO,IAA4B;AAGrE,SAAO,iCAAS,WAAkB;CACnC,QAAO;AACN;CACD;AACF;;;;ACND,MAAM,iBAAiB,OAAO,mBAAmB;AAQjD,MAAM,WAAW;CACf,YAAY;CACZ,kBAAkB;AACnB;AAED,MAAa,sBAAsB,CAAsBC,WAAgC;AAEvF,QAAO,mCAAiB,gBAAgB,QAAQ,SAAgB;AACjE;AAED,SAAgB,gBAAgBC,OAA+C;AAC7E,MAAK,+BAAa,MAAM,CAAE,QAAO;AACjC,QAAO,qCAAmB,MAAM,KAAK;AACtC;;;;ACDD,SAAgB,iBAKdC,OAUA;CACA,MAAMC,SAAmD,CAAE;AAE3D,KAAI,MAAM,OACR,QAAO,SAAS,oBAAoB,MAAM,OAAO;AAGnD,KAAI,MAAM,QACR,QAAO,UAAU,oBAAoB,MAAM,QAAQ;AAGrD,KAAI,MAAM,QACR,QAAO,UAAU,oBAAoB,MAAM,QAAQ;AAGrD,KAAI,MAAM,KACR,QAAO,OAAO,oBAAoB,MAAM,KAAK;AAG/C,QAAO;AACR;;;;AC3DD,SAAgB,kBACdC,QAC0B;AAC1B,QAAO;AACR"}
@@ -0,0 +1,30 @@
1
+ import { KoriRequestSchema, KoriRequestSchemaStructure, KoriResponseSchema, KoriResponseSchemaStructure, KoriSchema, KoriSchemaProvider } from "@korix/kori";
2
+ import { z } from "zod/v4";
3
+
4
+ //#region src/zod-schema.d.ts
5
+ type KoriZodSchemaProvider = KoriSchemaProvider<'zod'>;
6
+ type KoriZodSchema<T extends z.ZodType> = KoriSchema<T, z.output<T>>;
7
+ type KoriZodSchemaDefault = KoriZodSchema<z.ZodType>;
8
+ declare const createKoriZodSchema: <T extends z.ZodType>(schema: T) => KoriZodSchema<T>;
9
+ declare function isKoriZodSchema(value: unknown): value is KoriZodSchemaDefault;
10
+ //# sourceMappingURL=zod-schema.d.ts.map
11
+ //#endregion
12
+ //#region src/zod-request-schema.d.ts
13
+ type KoriZodRequestSchema<Params extends KoriZodSchema<z.ZodType> = never, Headers extends KoriZodSchema<z.ZodType> = never, Queries extends KoriZodSchema<z.ZodType> = never, Body extends KoriZodSchema<z.ZodType> = never> = KoriRequestSchema<KoriZodSchemaProvider, Params, Headers, Queries, Body>;
14
+ type KoriZodRequestParts = KoriRequestSchemaStructure<KoriZodSchema<z.ZodType>, KoriZodSchema<z.ZodType>, KoriZodSchema<z.ZodType>, KoriZodSchema<z.ZodType>>;
15
+ type ToKoriZodSchema<T extends z.ZodType> = KoriZodSchema<T>;
16
+ declare function zodRequestSchema<TParams extends z.ZodType | undefined = undefined, THeaders extends z.ZodType | undefined = undefined, TQueries extends z.ZodType | undefined = undefined, TBody extends z.ZodType | undefined = undefined>(input: {
17
+ params?: TParams;
18
+ headers?: THeaders;
19
+ queries?: TQueries;
20
+ body?: TBody;
21
+ }): KoriZodRequestSchema<TParams extends z.ZodType ? ToKoriZodSchema<TParams> : never, THeaders extends z.ZodType ? ToKoriZodSchema<THeaders> : never, TQueries extends z.ZodType ? ToKoriZodSchema<TQueries> : never, TBody extends z.ZodType ? ToKoriZodSchema<TBody> : never>;
22
+ //#endregion
23
+ //#region src/zod-response-schema.d.ts
24
+ type KoriZodResponseSchema<S extends KoriZodSchema<z.ZodType>> = KoriResponseSchema<KoriZodSchemaProvider, S>;
25
+ declare function zodResponseSchema<S extends KoriZodSchema<z.ZodType>>(schema: KoriResponseSchemaStructure<S>): KoriZodResponseSchema<S>;
26
+ //# sourceMappingURL=zod-response-schema.d.ts.map
27
+
28
+ //#endregion
29
+ export { KoriZodRequestParts, KoriZodRequestSchema, KoriZodResponseSchema, KoriZodSchema, KoriZodSchemaDefault, KoriZodSchemaProvider, createKoriZodSchema, isKoriZodSchema, zodRequestSchema, zodResponseSchema };
30
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/zod-schema.ts","../src/zod-request-schema.ts","../src/zod-response-schema.ts"],"sourcesContent":[],"mappings":";;;;KAaY,qBAAA,GAAwB;KAExB,wBAAwB,CAAA,CAAE,WAAW,WAAW,GAAG,CAAA,CAAE,OAAO;AAF5D,KAIA,oBAAA,GAAuB,aAJC,CAIa,CAAA,CAAE,OAJG,CAAA;AAE1C,cASC,mBATY,EAAA,CAAA,UASqB,CAAA,CAAE,OATvB,CAAA,CAAA,MAAA,EASwC,CATxC,EAAA,GAS4C,aAT5C,CAS0D,CAT1D,CAAA;AAAA,iBAcT,eAAA,CAdS,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IAciC,oBAdjC;;;;KCLb,oCACK,cAAc,CAAA,CAAE,kCACf,cAAc,CAAA,CAAE,kCAChB,cAAc,CAAA,CAAE,+BACnB,cAAc,CAAA,CAAE,oBAC3B,kBAAkB,uBAAuB,QAAQ,SAAS,SAAS;ADF3D,KCIA,mBAAA,GA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AAA,UENQ,aFMU,CENI,CAAA,CAAE,OFMN,CAAA,CAAA,CAAA,MAAA,EEL5C,2BFK4C,CELhB,CFKgB,CAAA,CAAA,EEJnD,qBFImD,CEJ7B,CFI6B,CAAA;AAEtD"}
@@ -0,0 +1,30 @@
1
+ import { KoriRequestSchema, KoriRequestSchemaStructure, KoriResponseSchema, KoriResponseSchemaStructure, KoriSchema, KoriSchemaProvider } from "@korix/kori";
2
+ import { z } from "zod/v4";
3
+
4
+ //#region src/zod-schema.d.ts
5
+ type KoriZodSchemaProvider = KoriSchemaProvider<'zod'>;
6
+ type KoriZodSchema<T extends z.ZodType> = KoriSchema<T, z.output<T>>;
7
+ type KoriZodSchemaDefault = KoriZodSchema<z.ZodType>;
8
+ declare const createKoriZodSchema: <T extends z.ZodType>(schema: T) => KoriZodSchema<T>;
9
+ declare function isKoriZodSchema(value: unknown): value is KoriZodSchemaDefault;
10
+ //# sourceMappingURL=zod-schema.d.ts.map
11
+ //#endregion
12
+ //#region src/zod-request-schema.d.ts
13
+ type KoriZodRequestSchema<Params extends KoriZodSchema<z.ZodType> = never, Headers extends KoriZodSchema<z.ZodType> = never, Queries extends KoriZodSchema<z.ZodType> = never, Body extends KoriZodSchema<z.ZodType> = never> = KoriRequestSchema<KoriZodSchemaProvider, Params, Headers, Queries, Body>;
14
+ type KoriZodRequestParts = KoriRequestSchemaStructure<KoriZodSchema<z.ZodType>, KoriZodSchema<z.ZodType>, KoriZodSchema<z.ZodType>, KoriZodSchema<z.ZodType>>;
15
+ type ToKoriZodSchema<T extends z.ZodType> = KoriZodSchema<T>;
16
+ declare function zodRequestSchema<TParams extends z.ZodType | undefined = undefined, THeaders extends z.ZodType | undefined = undefined, TQueries extends z.ZodType | undefined = undefined, TBody extends z.ZodType | undefined = undefined>(input: {
17
+ params?: TParams;
18
+ headers?: THeaders;
19
+ queries?: TQueries;
20
+ body?: TBody;
21
+ }): KoriZodRequestSchema<TParams extends z.ZodType ? ToKoriZodSchema<TParams> : never, THeaders extends z.ZodType ? ToKoriZodSchema<THeaders> : never, TQueries extends z.ZodType ? ToKoriZodSchema<TQueries> : never, TBody extends z.ZodType ? ToKoriZodSchema<TBody> : never>;
22
+ //#endregion
23
+ //#region src/zod-response-schema.d.ts
24
+ type KoriZodResponseSchema<S extends KoriZodSchema<z.ZodType>> = KoriResponseSchema<KoriZodSchemaProvider, S>;
25
+ declare function zodResponseSchema<S extends KoriZodSchema<z.ZodType>>(schema: KoriResponseSchemaStructure<S>): KoriZodResponseSchema<S>;
26
+ //# sourceMappingURL=zod-response-schema.d.ts.map
27
+
28
+ //#endregion
29
+ export { KoriZodRequestParts, KoriZodRequestSchema, KoriZodResponseSchema, KoriZodSchema, KoriZodSchemaDefault, KoriZodSchemaProvider, createKoriZodSchema, isKoriZodSchema, zodRequestSchema, zodResponseSchema };
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/zod-schema.ts","../src/zod-request-schema.ts","../src/zod-response-schema.ts"],"sourcesContent":[],"mappings":";;;;KAaY,qBAAA,GAAwB;KAExB,wBAAwB,CAAA,CAAE,WAAW,WAAW,GAAG,CAAA,CAAE,OAAO;AAF5D,KAIA,oBAAA,GAAuB,aAJC,CAIa,CAAA,CAAE,OAJG,CAAA;AAE1C,cASC,mBATY,EAAA,CAAA,UASqB,CAAA,CAAE,OATvB,CAAA,CAAA,MAAA,EASwC,CATxC,EAAA,GAS4C,aAT5C,CAS0D,CAT1D,CAAA;AAAA,iBAcT,eAAA,CAdS,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IAciC,oBAdjC;;;;KCLb,oCACK,cAAc,CAAA,CAAE,kCACf,cAAc,CAAA,CAAE,kCAChB,cAAc,CAAA,CAAE,+BACnB,cAAc,CAAA,CAAE,oBAC3B,kBAAkB,uBAAuB,QAAQ,SAAS,SAAS;ADF3D,KCIA,mBAAA,GAAsB,0BDJoB,CCKpD,aDLoD,CCKtC,CAAA,CA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A,CAAA,CAAA,MAAA,EEL5C,2BFK4C,CELhB,CFKgB,CAAA,CAAA,EEJnD,qBFImD,CEJ7B,CFI6B,CAAA;AAEtD"}
package/dist/index.js ADDED
@@ -0,0 +1,50 @@
1
+ import { createKoriSchema, getKoriSchemaBrand, isKoriSchema } from "@korix/kori";
2
+ import { z } from "zod/v4";
3
+ import fastJson from "fast-json-stringify";
4
+
5
+ //#region src/fast-json.ts
6
+ function zodToFastSerializer(schema) {
7
+ if (!isKoriZodSchema(schema)) return void 0;
8
+ try {
9
+ const jsonSchema = z.toJSONSchema(schema.def);
10
+ return fastJson(jsonSchema);
11
+ } catch {
12
+ return void 0;
13
+ }
14
+ }
15
+
16
+ //#endregion
17
+ //#region src/zod-schema.ts
18
+ const ZodSchemaBrand = Symbol("zod-schema-brand");
19
+ const provider = {
20
+ __provider: "zod",
21
+ toFastSerializer: zodToFastSerializer
22
+ };
23
+ const createKoriZodSchema = (schema) => {
24
+ return createKoriSchema(ZodSchemaBrand, schema, provider);
25
+ };
26
+ function isKoriZodSchema(value) {
27
+ if (!isKoriSchema(value)) return false;
28
+ return getKoriSchemaBrand(value) === ZodSchemaBrand;
29
+ }
30
+
31
+ //#endregion
32
+ //#region src/zod-request-schema.ts
33
+ function zodRequestSchema(input) {
34
+ const result = {};
35
+ if (input.params) result.params = createKoriZodSchema(input.params);
36
+ if (input.headers) result.headers = createKoriZodSchema(input.headers);
37
+ if (input.queries) result.queries = createKoriZodSchema(input.queries);
38
+ if (input.body) result.body = createKoriZodSchema(input.body);
39
+ return result;
40
+ }
41
+
42
+ //#endregion
43
+ //#region src/zod-response-schema.ts
44
+ function zodResponseSchema(schema) {
45
+ return schema;
46
+ }
47
+
48
+ //#endregion
49
+ export { createKoriZodSchema, isKoriZodSchema, zodRequestSchema, zodResponseSchema };
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["schema: KoriSchemaDefault","schema: T","value: unknown","input: {\n params?: TParams;\n headers?: THeaders;\n queries?: TQueries;\n body?: TBody;\n}","result: Record<string, KoriZodSchema<z.ZodType>>","schema: KoriResponseSchemaStructure<S>"],"sources":["../src/fast-json.ts","../src/zod-schema.ts","../src/zod-request-schema.ts","../src/zod-response-schema.ts"],"sourcesContent":["import { type KoriSchemaDefault } from '@korix/kori';\nimport fastJson from 'fast-json-stringify';\nimport { z } from 'zod/v4';\n\nimport { isKoriZodSchema } from './zod-schema.js';\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function zodToFastSerializer(schema: KoriSchemaDefault) {\n if (!isKoriZodSchema(schema)) return undefined;\n try {\n const jsonSchema = z.toJSONSchema(schema.def as unknown as z.ZodType);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n return fastJson(jsonSchema as any);\n } catch {\n return undefined;\n }\n}\n","import {\n type KoriSchema,\n type KoriSchemaProvider,\n createKoriSchema,\n isKoriSchema,\n getKoriSchemaBrand,\n} from '@korix/kori';\nimport { type z } from 'zod/v4';\n\nimport { zodToFastSerializer } from './fast-json.js';\n\nconst ZodSchemaBrand = Symbol('zod-schema-brand');\n\nexport type KoriZodSchemaProvider = KoriSchemaProvider<'zod'>;\n\nexport type KoriZodSchema<T extends z.ZodType> = KoriSchema<T, z.output<T>>;\n\nexport type KoriZodSchemaDefault = KoriZodSchema<z.ZodType>;\n\nconst provider = {\n __provider: 'zod',\n toFastSerializer: zodToFastSerializer,\n} as const;\n\nexport const createKoriZodSchema = <T extends z.ZodType>(schema: T): KoriZodSchema<T> => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return createKoriSchema(ZodSchemaBrand, schema, provider as any);\n};\n\nexport function isKoriZodSchema(value: unknown): value is KoriZodSchemaDefault {\n if (!isKoriSchema(value)) return false;\n return getKoriSchemaBrand(value) === ZodSchemaBrand;\n}\n","import {\n type KoriRequestSchema,\n type KoriRequestSchemaStructure,\n type KoriRequestSchemaContent,\n type KoriRequestSchemaBody,\n} from '@korix/kori';\nimport { type z } from 'zod/v4';\n\nimport { type KoriZodSchema, type KoriZodSchemaProvider, createKoriZodSchema } from './zod-schema.js';\n\nexport type KoriZodRequestSchema<\n Params extends KoriZodSchema<z.ZodType> = never,\n Headers extends KoriZodSchema<z.ZodType> = never,\n Queries extends KoriZodSchema<z.ZodType> = never,\n Body extends KoriZodSchema<z.ZodType> = never,\n> = KoriRequestSchema<KoriZodSchemaProvider, Params, Headers, Queries, Body>;\n\nexport type KoriZodRequestParts = KoriRequestSchemaStructure<\n KoriZodSchema<z.ZodType>,\n KoriZodSchema<z.ZodType>,\n KoriZodSchema<z.ZodType>,\n KoriZodSchema<z.ZodType>\n>;\n\nexport type KoriZodRequestBodySchema =\n | KoriZodSchema<z.ZodType>\n | KoriRequestSchemaContent<KoriZodSchema<z.ZodType>>\n | KoriRequestSchemaBody<KoriZodSchema<z.ZodType>>;\n\ntype ToKoriZodSchema<T extends z.ZodType> = KoriZodSchema<T>;\n\nexport function zodRequestSchema<\n TParams extends z.ZodType | undefined = undefined,\n THeaders extends z.ZodType | undefined = undefined,\n TQueries extends z.ZodType | undefined = undefined,\n TBody extends z.ZodType | undefined = undefined,\n>(input: {\n params?: TParams;\n headers?: THeaders;\n queries?: TQueries;\n body?: TBody;\n}): KoriZodRequestSchema<\n TParams extends z.ZodType ? ToKoriZodSchema<TParams> : never,\n THeaders extends z.ZodType ? ToKoriZodSchema<THeaders> : never,\n TQueries extends z.ZodType ? ToKoriZodSchema<TQueries> : never,\n TBody extends z.ZodType ? ToKoriZodSchema<TBody> : never\n> {\n const result: Record<string, KoriZodSchema<z.ZodType>> = {};\n\n if (input.params) {\n result.params = createKoriZodSchema(input.params);\n }\n\n if (input.headers) {\n result.headers = createKoriZodSchema(input.headers);\n }\n\n if (input.queries) {\n result.queries = createKoriZodSchema(input.queries);\n }\n\n if (input.body) {\n result.body = createKoriZodSchema(input.body);\n }\n\n return result;\n}\n","import { type KoriResponseSchema, type KoriResponseSchemaStructure } from '@korix/kori';\nimport { type z } from 'zod/v4';\n\nimport { type KoriZodSchema, type KoriZodSchemaProvider } from './zod-schema.js';\n\nexport type KoriZodResponseSchema<S extends KoriZodSchema<z.ZodType>> = KoriResponseSchema<KoriZodSchemaProvider, S>;\n\nexport function zodResponseSchema<S extends KoriZodSchema<z.ZodType>>(\n schema: KoriResponseSchemaStructure<S>,\n): KoriZodResponseSchema<S> {\n return schema;\n}\n"],"mappings":";;;;;AAOA,SAAgB,oBAAoBA,QAA2B;AAC7D,MAAK,gBAAgB,OAAO,CAAE;AAC9B,KAAI;EACF,MAAM,aAAa,EAAE,aAAa,OAAO,IAA4B;AAGrE,SAAO,SAAS,WAAkB;CACnC,QAAO;AACN;CACD;AACF;;;;ACND,MAAM,iBAAiB,OAAO,mBAAmB;AAQjD,MAAM,WAAW;CACf,YAAY;CACZ,kBAAkB;AACnB;AAED,MAAa,sBAAsB,CAAsBC,WAAgC;AAEvF,QAAO,iBAAiB,gBAAgB,QAAQ,SAAgB;AACjE;AAED,SAAgB,gBAAgBC,OAA+C;AAC7E,MAAK,aAAa,MAAM,CAAE,QAAO;AACjC,QAAO,mBAAmB,MAAM,KAAK;AACtC;;;;ACDD,SAAgB,iBAKdC,OAUA;CACA,MAAMC,SAAmD,CAAE;AAE3D,KAAI,MAAM,OACR,QAAO,SAAS,oBAAoB,MAAM,OAAO;AAGnD,KAAI,MAAM,QACR,QAAO,UAAU,oBAAoB,MAAM,QAAQ;AAGrD,KAAI,MAAM,QACR,QAAO,UAAU,oBAAoB,MAAM,QAAQ;AAGrD,KAAI,MAAM,KACR,QAAO,OAAO,oBAAoB,MAAM,KAAK;AAG/C,QAAO;AACR;;;;AC3DD,SAAgB,kBACdC,QAC0B;AAC1B,QAAO;AACR"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@korix/zod-schema",
3
+ "version": "0.1.0-20250713.0",
4
+ "description": "Zod schema integration for Kori framework",
5
+ "type": "module",
6
+ "author": "mitz (@bufferings)",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/bufferings/kori"
11
+ },
12
+ "homepage": "https://github.com/bufferings/kori",
13
+ "bugs": "https://github.com/bufferings/kori/issues",
14
+ "engines": {
15
+ "node": ">=18.0.0"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "import": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "require": {
30
+ "types": "./dist/index.d.cts",
31
+ "default": "./dist/index.cjs"
32
+ }
33
+ }
34
+ },
35
+ "dependencies": {
36
+ "fast-json-stringify": "^6.0.0"
37
+ },
38
+ "peerDependencies": {
39
+ "zod": "^3.25.0",
40
+ "@korix/kori": "0.1.0-20250713.11"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "20.11.17",
44
+ "eslint": "9.16.0",
45
+ "rimraf": "6.0.1",
46
+ "tsdown": "0.12.9",
47
+ "typescript": "5.8.3",
48
+ "vitest": "2.1.9",
49
+ "zod": "3.25.67",
50
+ "@korix/kori": "0.1.0-20250713.11",
51
+ "@korix/eslint-config": "0.1.0-alpha.0"
52
+ },
53
+ "scripts": {
54
+ "clean": "rimraf dist *.tsbuildinfo .turbo .tsup",
55
+ "typecheck": "tsc --noEmit",
56
+ "lint": "eslint .",
57
+ "lint:fix": "eslint . --fix",
58
+ "build": "tsdown --tsconfig tsconfig.build.json",
59
+ "test": "vitest run",
60
+ "test:watch": "vitest"
61
+ }
62
+ }