@miroir-framework/jzod-ts 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +36 -36
- package/dist/bundle.js +85 -81
- package/dist/src/JzodTsInterface.d.ts +35 -35
- package/dist/src/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/JzodToTs.ts +10 -5
- package/src/JzodTsInterface.ts +89 -89
- package/src/index.ts +23 -23
- package/tests/jzod-ts.test.ts +2 -2
- package/tests/resources/tsTypeGeneration-testJzodSchema1 - reference.ts +2 -2
- package/tests/resources/tsTypeGeneration-testJzodSchema2 - reference.ts +7 -7
- package/tests/resources/tsTypeGeneration-testJzodSchema3 - reference.ts +6 -6
- package/tests/resources/tsTypeGeneration-testJzodSchema4 - reference.ts +74 -74
|
@@ -7,10 +7,10 @@ declare const jzodRootSchema: z.ZodObject<{
|
|
|
7
7
|
optional?: boolean | undefined;
|
|
8
8
|
}>;
|
|
9
9
|
type JzodRoot = z.infer<typeof jzodRootSchema>;
|
|
10
|
-
export declare const
|
|
11
|
-
export type JzodEnumTypes = z.infer<typeof
|
|
12
|
-
export declare const
|
|
13
|
-
export type JzodEnumElementTypes = z.infer<typeof
|
|
10
|
+
export declare const jzodEnumAttributeTypes: z.ZodEnum<["any", "bigint", "boolean", "date", "never", "null", "number", "string", "uuid", "undefined", "unknown", "void"]>;
|
|
11
|
+
export type JzodEnumTypes = z.infer<typeof jzodEnumAttributeTypes>;
|
|
12
|
+
export declare const jzodEnumElementTypes: z.ZodEnum<["array", "enum", "function", "lazy", "literal", "intersection", "map", "object", "promise", "record", "schemaReference", "set", "simpleType", "tuple", "union"]>;
|
|
13
|
+
export type JzodEnumElementTypes = z.infer<typeof jzodEnumElementTypes>;
|
|
14
14
|
export interface JzodArray extends JzodRoot {
|
|
15
15
|
optional?: boolean;
|
|
16
16
|
nullable?: boolean;
|
|
@@ -20,8 +20,8 @@ export interface JzodArray extends JzodRoot {
|
|
|
20
20
|
type: 'array';
|
|
21
21
|
definition: JzodElement;
|
|
22
22
|
}
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
23
|
+
export declare const jzodArray: z.ZodType<JzodArray>;
|
|
24
|
+
export declare const jzodAttributeDateValidations: z.ZodObject<{
|
|
25
25
|
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
26
26
|
type: z.ZodEnum<["min", "max"]>;
|
|
27
27
|
parameter: z.ZodAny;
|
|
@@ -34,8 +34,8 @@ export declare const jzodAttributeDateValidationsSchema: z.ZodObject<{
|
|
|
34
34
|
extra?: Record<string, any> | undefined;
|
|
35
35
|
parameter?: any;
|
|
36
36
|
}>;
|
|
37
|
-
export type JzodAttributeDateValidations = z.infer<typeof
|
|
38
|
-
export declare const
|
|
37
|
+
export type JzodAttributeDateValidations = z.infer<typeof jzodAttributeDateValidations>;
|
|
38
|
+
export declare const jzodAttributeNumberValidations: z.ZodObject<{
|
|
39
39
|
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
40
40
|
type: z.ZodEnum<["gt", "gte", "lt", "lte", "int", "positive", "nonpositive", "negative", "nonnegative", "multipleOf", "finite", "safe"]>;
|
|
41
41
|
parameter: z.ZodAny;
|
|
@@ -48,8 +48,8 @@ export declare const jzodAttributeNumberValidationsSchema: z.ZodObject<{
|
|
|
48
48
|
extra?: Record<string, any> | undefined;
|
|
49
49
|
parameter?: any;
|
|
50
50
|
}>;
|
|
51
|
-
export type JzodAttributeNumberValidations = z.infer<typeof
|
|
52
|
-
export declare const
|
|
51
|
+
export type JzodAttributeNumberValidations = z.infer<typeof jzodAttributeNumberValidations>;
|
|
52
|
+
export declare const jzodAttributeStringValidations: z.ZodObject<{
|
|
53
53
|
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
54
54
|
type: z.ZodEnum<["max", "min", "length", "email", "url", "emoji", "uuid", "cuid", "cuid2", "ulid", "regex", "includes", "startsWith", "endsWith", "datetime", "ip"]>;
|
|
55
55
|
parameter: z.ZodAny;
|
|
@@ -62,8 +62,8 @@ export declare const jzodAttributeStringValidationsSchema: z.ZodObject<{
|
|
|
62
62
|
extra?: Record<string, any> | undefined;
|
|
63
63
|
parameter?: any;
|
|
64
64
|
}>;
|
|
65
|
-
export type JzodAttributeStringValidations = z.infer<typeof
|
|
66
|
-
export declare const
|
|
65
|
+
export type JzodAttributeStringValidations = z.infer<typeof jzodAttributeStringValidations>;
|
|
66
|
+
export declare const jzodAttributeDateWithValidations: z.ZodObject<{
|
|
67
67
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
68
68
|
nullable: z.ZodOptional<z.ZodBoolean>;
|
|
69
69
|
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
@@ -108,8 +108,8 @@ export declare const jzodAttributeDateWithValidationsSchema: z.ZodObject<{
|
|
|
108
108
|
extra?: Record<string, any> | undefined;
|
|
109
109
|
coerce?: boolean | undefined;
|
|
110
110
|
}>;
|
|
111
|
-
export type JzodAttributeDateWithValidations = z.infer<typeof
|
|
112
|
-
export declare const
|
|
111
|
+
export type JzodAttributeDateWithValidations = z.infer<typeof jzodAttributeDateWithValidations>;
|
|
112
|
+
export declare const jzodAttributeNumberWithValidations: z.ZodObject<{
|
|
113
113
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
114
114
|
nullable: z.ZodOptional<z.ZodBoolean>;
|
|
115
115
|
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
@@ -154,8 +154,8 @@ export declare const jzodAttributeNumberWithValidationsSchema: z.ZodObject<{
|
|
|
154
154
|
extra?: Record<string, any> | undefined;
|
|
155
155
|
coerce?: boolean | undefined;
|
|
156
156
|
}>;
|
|
157
|
-
export type JzodAttributeNumberWithValidations = z.infer<typeof
|
|
158
|
-
export declare const
|
|
157
|
+
export type JzodAttributeNumberWithValidations = z.infer<typeof jzodAttributeNumberWithValidations>;
|
|
158
|
+
export declare const jzodAttributeStringWithValidations: z.ZodObject<{
|
|
159
159
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
160
160
|
nullable: z.ZodOptional<z.ZodBoolean>;
|
|
161
161
|
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
@@ -200,8 +200,8 @@ export declare const jzodAttributeStringWithValidationsSchema: z.ZodObject<{
|
|
|
200
200
|
extra?: Record<string, any> | undefined;
|
|
201
201
|
coerce?: boolean | undefined;
|
|
202
202
|
}>;
|
|
203
|
-
export type JzodAttributeStringWithValidations = z.infer<typeof
|
|
204
|
-
export declare const
|
|
203
|
+
export type JzodAttributeStringWithValidations = z.infer<typeof jzodAttributeStringWithValidations>;
|
|
204
|
+
export declare const jzodAttribute: z.ZodObject<{
|
|
205
205
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
206
206
|
nullable: z.ZodOptional<z.ZodBoolean>;
|
|
207
207
|
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
@@ -223,10 +223,10 @@ export declare const jzodAttributeSchema: z.ZodObject<{
|
|
|
223
223
|
extra?: Record<string, any> | undefined;
|
|
224
224
|
coerce?: boolean | undefined;
|
|
225
225
|
}>;
|
|
226
|
-
export type JzodAttribute = z.infer<typeof
|
|
226
|
+
export type JzodAttribute = z.infer<typeof jzodAttribute>;
|
|
227
227
|
export type JzodElement = JzodArray | JzodAttribute | JzodAttributeDateWithValidations | JzodAttributeNumberWithValidations | JzodAttributeStringWithValidations | JzodEnum | JzodFunction | JzodLazy | JzodLiteral | JzodIntersection | JzodMap | JzodRecord | JzodObject | JzodPromise | JzodReference | JzodSet | JzodTuple | JzodUnion;
|
|
228
|
-
export declare const
|
|
229
|
-
export declare const
|
|
228
|
+
export declare const jzodElement: z.ZodType<JzodElement>;
|
|
229
|
+
export declare const jzodEnum: z.ZodObject<{
|
|
230
230
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
231
231
|
nullable: z.ZodOptional<z.ZodBoolean>;
|
|
232
232
|
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
@@ -245,7 +245,7 @@ export declare const jzodEnumSchema: z.ZodObject<{
|
|
|
245
245
|
nullable?: boolean | undefined;
|
|
246
246
|
extra?: Record<string, any> | undefined;
|
|
247
247
|
}>;
|
|
248
|
-
export type JzodEnum = z.infer<typeof
|
|
248
|
+
export type JzodEnum = z.infer<typeof jzodEnum>;
|
|
249
249
|
export interface JzodFunction {
|
|
250
250
|
extra?: {
|
|
251
251
|
[k: string]: any;
|
|
@@ -256,8 +256,8 @@ export interface JzodFunction {
|
|
|
256
256
|
returns?: JzodElement;
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
|
-
export declare const
|
|
260
|
-
export declare const
|
|
259
|
+
export declare const jzodFunction: ZodType<JzodFunction>;
|
|
260
|
+
export declare const jzodLazy: z.ZodObject<{
|
|
261
261
|
type: z.ZodLiteral<"lazy">;
|
|
262
262
|
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
263
263
|
definition: ZodType<JzodFunction, z.ZodTypeDef, JzodFunction>;
|
|
@@ -270,8 +270,8 @@ export declare const jzodLazySchema: z.ZodObject<{
|
|
|
270
270
|
definition: JzodFunction;
|
|
271
271
|
extra?: Record<string, any> | undefined;
|
|
272
272
|
}>;
|
|
273
|
-
export type JzodLazy = z.infer<typeof
|
|
274
|
-
export declare const
|
|
273
|
+
export type JzodLazy = z.infer<typeof jzodLazy>;
|
|
274
|
+
export declare const jzodLiteral: z.ZodObject<{
|
|
275
275
|
optional: z.ZodOptional<z.ZodBoolean>;
|
|
276
276
|
nullable: z.ZodOptional<z.ZodBoolean>;
|
|
277
277
|
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
@@ -290,7 +290,7 @@ export declare const jzodLiteralSchema: z.ZodObject<{
|
|
|
290
290
|
nullable?: boolean | undefined;
|
|
291
291
|
extra?: Record<string, any> | undefined;
|
|
292
292
|
}>;
|
|
293
|
-
export type JzodLiteral = z.infer<typeof
|
|
293
|
+
export type JzodLiteral = z.infer<typeof jzodLiteral>;
|
|
294
294
|
export interface JzodIntersection {
|
|
295
295
|
optional?: boolean;
|
|
296
296
|
nullable?: boolean;
|
|
@@ -303,7 +303,7 @@ export interface JzodIntersection {
|
|
|
303
303
|
right: JzodElement;
|
|
304
304
|
};
|
|
305
305
|
}
|
|
306
|
-
export declare const
|
|
306
|
+
export declare const jzodIntersection: z.ZodType<JzodIntersection>;
|
|
307
307
|
export interface JzodMap extends JzodRoot {
|
|
308
308
|
optional?: boolean;
|
|
309
309
|
nullable?: boolean;
|
|
@@ -327,7 +327,7 @@ export interface JzodObject extends JzodRoot {
|
|
|
327
327
|
[attributeName: string]: JzodElement;
|
|
328
328
|
};
|
|
329
329
|
}
|
|
330
|
-
export declare const
|
|
330
|
+
export declare const jzodObject: z.ZodType<JzodObject>;
|
|
331
331
|
export interface JzodPromise extends JzodRoot {
|
|
332
332
|
extra?: {
|
|
333
333
|
[k: string]: any;
|
|
@@ -335,7 +335,7 @@ export interface JzodPromise extends JzodRoot {
|
|
|
335
335
|
type: 'promise';
|
|
336
336
|
definition: JzodElement;
|
|
337
337
|
}
|
|
338
|
-
export declare const
|
|
338
|
+
export declare const jzodPromise: z.ZodType<JzodPromise>;
|
|
339
339
|
export interface JzodRecord {
|
|
340
340
|
optional?: boolean;
|
|
341
341
|
nullable?: boolean;
|
|
@@ -345,7 +345,7 @@ export interface JzodRecord {
|
|
|
345
345
|
type: 'record';
|
|
346
346
|
definition: JzodElement;
|
|
347
347
|
}
|
|
348
|
-
export declare const
|
|
348
|
+
export declare const jzodRecord: z.ZodType<JzodRecord>;
|
|
349
349
|
export interface JzodReference {
|
|
350
350
|
optional?: boolean;
|
|
351
351
|
nullable?: boolean;
|
|
@@ -362,7 +362,7 @@ export interface JzodReference {
|
|
|
362
362
|
absolutePath?: string;
|
|
363
363
|
};
|
|
364
364
|
}
|
|
365
|
-
export declare const
|
|
365
|
+
export declare const jzodReference: ZodType<JzodReference>;
|
|
366
366
|
export interface JzodSet extends JzodRoot {
|
|
367
367
|
optional?: boolean;
|
|
368
368
|
nullable?: boolean;
|
|
@@ -372,7 +372,7 @@ export interface JzodSet extends JzodRoot {
|
|
|
372
372
|
type: 'set';
|
|
373
373
|
definition: JzodElement;
|
|
374
374
|
}
|
|
375
|
-
export declare const
|
|
375
|
+
export declare const jzodSet: z.ZodType<JzodSet>;
|
|
376
376
|
export interface JzodTuple {
|
|
377
377
|
optional?: boolean;
|
|
378
378
|
nullable?: boolean;
|
|
@@ -382,7 +382,7 @@ export interface JzodTuple {
|
|
|
382
382
|
type: 'tuple';
|
|
383
383
|
definition: JzodElement[];
|
|
384
384
|
}
|
|
385
|
-
export declare const
|
|
385
|
+
export declare const jzodTuple: z.ZodType<JzodTuple>;
|
|
386
386
|
export interface JzodUnion {
|
|
387
387
|
optional?: boolean;
|
|
388
388
|
nullable?: boolean;
|
|
@@ -393,5 +393,5 @@ export interface JzodUnion {
|
|
|
393
393
|
discriminator?: string;
|
|
394
394
|
definition: JzodElement[];
|
|
395
395
|
}
|
|
396
|
-
export declare const
|
|
396
|
+
export declare const jzodUnion: z.ZodType<JzodUnion>;
|
|
397
397
|
export {};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { jzodToTsCode, jzodToTsTypeAliasesAndZodText, TsTypeAliasesAndZodText as JzodTypeAliasesAndZodText, TsTypeAliases, } from "./JzodToTs";
|
|
2
2
|
export { printTsTypeAlias, printTsTypeAliases } from "./tools";
|
|
3
|
-
export {
|
|
3
|
+
export { jzodArray, jzodAttribute, jzodAttributeDateValidations, jzodAttributeDateWithValidations, jzodAttributeNumberValidations, jzodAttributeNumberWithValidations, jzodAttributeStringValidations, jzodAttributeStringWithValidations, jzodElement, jzodEnumAttributeTypes, jzodEnumElementTypes, jzodEnum, jzodFunction, jzodIntersection, jzodLazy, jzodLiteral, jzodMapSchema, jzodObject, jzodPromise, jzodRecord, jzodReference, jzodSet, jzodTuple, jzodUnion, JzodArray, JzodAttribute, JzodAttributeDateValidations, JzodAttributeDateWithValidations, JzodAttributeNumberValidations, JzodAttributeNumberWithValidations, JzodAttributeStringValidations, JzodAttributeStringWithValidations, JzodElement, JzodEnum, JzodEnumTypes, JzodFunction, JzodEnumElementTypes, JzodIntersection, JzodLazy, JzodLiteral, JzodMap, JzodObject, JzodPromise, JzodRecord, JzodReference, JzodSet, JzodUnion, JzodTuple, } from "./JzodTsInterface";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miroir-framework/jzod-ts",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.3",
|
|
5
5
|
"description": "The Typescript-related functionalities of Jzod.",
|
|
6
6
|
"main": "dist/bundle.js",
|
|
7
7
|
"types": "dist/bundle.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"bugs": "https://github.com/miroir-framework/jzod/issues",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@miroir-framework/jzod": "0.5.
|
|
18
|
+
"@miroir-framework/jzod": "0.5.3",
|
|
19
19
|
"zod": "^3.22.2",
|
|
20
20
|
"zod-to-ts": "^1.2.0"
|
|
21
21
|
},
|
package/src/JzodToTs.ts
CHANGED
|
@@ -32,8 +32,10 @@ export function jzodToTsTypeAliasesAndZodText(
|
|
|
32
32
|
() => ({}),
|
|
33
33
|
(innerReference: ZodLazy<any>, relativeReference: string | undefined) =>
|
|
34
34
|
withGetType(innerReference, (ts) => {
|
|
35
|
+
const actualTypeName = relativeReference?relativeReference.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
|
|
35
36
|
return ts.factory.createTypeReferenceNode(
|
|
36
|
-
|
|
37
|
+
|
|
38
|
+
ts.factory.createIdentifier(actualTypeName ? actualTypeName : "RELATIVEPATH_NOT_DEFINED")
|
|
37
39
|
);
|
|
38
40
|
}
|
|
39
41
|
)
|
|
@@ -41,9 +43,10 @@ export function jzodToTsTypeAliasesAndZodText(
|
|
|
41
43
|
|
|
42
44
|
const contextTsTypesString = Object.fromEntries(
|
|
43
45
|
Object.entries(elementZodSchemaAndDescription.contextZodSchema ?? {}).map((curr) => {
|
|
46
|
+
const actualTypeName = curr[0]?curr[0].replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
|
|
44
47
|
// console.log("getTsCodeCorrespondingToZodSchemaAndDescription ", JSON.stringify(curr));
|
|
45
48
|
const tsNode = zodToTs(curr[1], typeName).node;
|
|
46
|
-
const typeAlias = createTypeAlias(tsNode,
|
|
49
|
+
const typeAlias = createTypeAlias(tsNode, actualTypeName);
|
|
47
50
|
return [curr[0], typeAlias];
|
|
48
51
|
})
|
|
49
52
|
);
|
|
@@ -73,21 +76,23 @@ export function jzodToTsCode (
|
|
|
73
76
|
// );
|
|
74
77
|
|
|
75
78
|
const schemaName = typeName?typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toLowerCase() + c):"";
|
|
79
|
+
const actualTypeName = typeName?typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
|
|
76
80
|
// console.log("getTsCodeCorrespondingToZodSchemaAndDescription convertedJsonZodSchema", bodyJsCode);
|
|
77
81
|
|
|
78
82
|
const header = `import { ZodType, ZodTypeAny, z } from "zod";`;
|
|
79
83
|
|
|
80
|
-
const typeAliasesAndZodText = jzodToTsTypeAliasesAndZodText(jzodElement,
|
|
84
|
+
const typeAliasesAndZodText = jzodToTsTypeAliasesAndZodText(jzodElement, actualTypeName);
|
|
81
85
|
|
|
82
|
-
const bodyJsCode = `export const ${schemaName}: z.ZodType<${
|
|
86
|
+
const bodyJsCode = `export const ${schemaName}: z.ZodType<${actualTypeName}> = ${typeAliasesAndZodText.mainZodText};`;
|
|
83
87
|
|
|
84
88
|
const contextTsTypesString = printTsTypeAliases(typeAliasesAndZodText.contextTsTypeAliases, exportPrefix);
|
|
85
89
|
// console.log("getTsCodeCorrespondingToZodSchemaAndDescription contextTsTypesString",contextTsTypesString);
|
|
86
90
|
|
|
87
91
|
const contextJsCode = typeAliasesAndZodText.contextZodText
|
|
88
92
|
? Object.entries(typeAliasesAndZodText.contextZodText).reduce((acc, curr) => {
|
|
93
|
+
const contextTypeName = curr[0]?curr[0].replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
|
|
89
94
|
return `${acc}
|
|
90
|
-
export const ${curr[0]}:z.ZodType<${
|
|
95
|
+
export const ${curr[0]}:z.ZodType<${contextTypeName}> = ${curr[1]};`;
|
|
91
96
|
}, "")
|
|
92
97
|
: ""
|
|
93
98
|
;
|