@miroir-framework/jzod-ts 0.6.0 → 0.6.1

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 CHANGED
@@ -35,6 +35,7 @@ type JzodAttributeDateWithValidations = {
35
35
  } | undefined;
36
36
  type: "simpleType";
37
37
  definition: "date";
38
+ coerce?: boolean | undefined;
38
39
  validations: JzodAttributeDateValidations[];
39
40
  };
40
41
  type JzodAttributeNumberValidations = {
@@ -52,6 +53,7 @@ type JzodAttributeNumberWithValidations = {
52
53
  } | undefined;
53
54
  type: "simpleType";
54
55
  definition: "number";
56
+ coerce?: boolean | undefined;
55
57
  validations: JzodAttributeNumberValidations[];
56
58
  };
57
59
  type JzodAttributeStringValidations = {
@@ -69,6 +71,7 @@ type JzodAttributeStringWithValidations = {
69
71
  } | undefined;
70
72
  type: "simpleType";
71
73
  definition: "string";
74
+ coerce?: boolean | undefined;
72
75
  validations: JzodAttributeStringValidations[];
73
76
  };
74
77
  type JzodElement = JzodArray | JzodAttribute | JzodAttributeDateWithValidations | JzodAttributeNumberWithValidations | JzodAttributeStringWithValidations | JzodEnum | JzodFunction | JzodLazy | JzodLiteral | JzodIntersection | JzodMap | JzodObject | JzodPromise | JzodRecord | JzodReference | JzodSet | JzodTuple | JzodUnion;
@@ -251,7 +254,7 @@ interface TsTypeAliasesAndZodText {
251
254
  mainZodText: string;
252
255
  }
253
256
  declare function jzodToTsTypeAliasesAndZodText(element: JzodElement, typeName?: string): TsTypeAliasesAndZodText;
254
- declare function jzodToTsCode(jzodElement: JzodElement, exportPrefix?: boolean, typeName?: string, typeSchema?: boolean): string;
257
+ declare function jzodToTsCode(jzodElement: JzodElement, exportPrefix?: boolean, typeName?: string, typeAnotationForSchema?: string[]): string;
255
258
 
256
259
  declare function printTsTypeAlias(typeAlias: ts.TypeAliasDeclaration, exportPrefix?: boolean): string;
257
260
  declare function printTsTypeAliases(typeAliases: TsTypeAliases, exportPrefix?: boolean): string;
package/dist/bundle.js CHANGED
@@ -17,7 +17,7 @@ function jzodToTsTypeAliasesAndZodText(element, typeName) {
17
17
  var _a, _b;
18
18
  const elementZodSchemaAndDescription = jzodElementSchemaToZodSchemaAndDescription(element, () => ({}), () => ({}), (innerReference, relativeReference) => withGetType(innerReference, (ts) => {
19
19
  const actualTypeName = relativeReference ? relativeReference.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
20
- return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(actualTypeName ? actualTypeName : "RELATIVEPATH_NOT_DEFINED"), undefined);
20
+ return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(actualTypeName !== null && actualTypeName !== void 0 ? actualTypeName : "RELATIVEPATH_NOT_DEFINED"), undefined);
21
21
  }));
22
22
  const contextTsTypesString = Object.fromEntries(Object.entries((_a = elementZodSchemaAndDescription.contextZodSchema) !== null && _a !== void 0 ? _a : {}).map((curr) => {
23
23
  const actualTypeName = curr[0] ? curr[0].replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
@@ -34,22 +34,23 @@ function jzodToTsTypeAliasesAndZodText(element, typeName) {
34
34
  mainTsTypeAlias: tsTypeStringTypeAlias,
35
35
  };
36
36
  }
37
- function jzodToTsCode(jzodElement, exportPrefix = true, typeName, typeSchema = false) {
37
+ function jzodToTsCode(jzodElement, exportPrefix = true, typeName, typeAnotationForSchema = []) {
38
38
  const schemaName = typeName ? typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toLowerCase() + c) : "";
39
39
  const actualTypeName = typeName ? typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
40
40
  const header = `import { ZodType, ZodTypeAny, z } from "zod";`;
41
41
  const typeAliasesAndZodText = jzodToTsTypeAliasesAndZodText(jzodElement, actualTypeName);
42
- const bodyJsCode = typeSchema
42
+ const bodyJsCode = typeAnotationForSchema.includes(schemaName !== null && schemaName !== void 0 ? schemaName : "")
43
43
  ? `export const ${schemaName}: z.ZodType<${actualTypeName}> = ${typeAliasesAndZodText.mainZodText};`
44
44
  : `export const ${schemaName} = ${typeAliasesAndZodText.mainZodText};`;
45
45
  const contextTsTypesString = printTsTypeAliases(typeAliasesAndZodText.contextTsTypeAliases, exportPrefix);
46
46
  const contextJsCode = typeAliasesAndZodText.contextZodText
47
47
  ? Object.entries(typeAliasesAndZodText.contextZodText).reduce((acc, curr) => {
48
48
  const contextTypeName = curr[0] ? curr[0].replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
49
- return typeSchema ?
50
- `${acc}
51
- export const ${curr[0]}: z.ZodType<${contextTypeName}> = ${curr[1]};` :
49
+ return typeAnotationForSchema.includes(curr[0]) ?
52
50
  `${acc}
51
+ export const ${curr[0]}: z.ZodType<${contextTypeName}> = ${curr[1]};`
52
+ :
53
+ `${acc}
53
54
  export const ${curr[0]} = ${curr[1]};`;
54
55
  }, "")
55
56
  : "";
@@ -66,11 +67,11 @@ z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), e
66
67
  const jzodArray = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.record(z.string(), z.any()).optional() }).strict().extend({ type: z.literal("array"), definition: z.lazy(() => jzodElement) }).strict();
67
68
  const jzodAttribute = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.record(z.string(), z.any()).optional() }).strict().extend({ type: z.literal("simpleType"), coerce: z.boolean().optional(), definition: z.lazy(() => jzodEnumAttributeTypes) }).strict();
68
69
  const jzodAttributeDateValidations = z.object({ extra: z.record(z.string(), z.any()).optional(), type: z.enum(["min", "max"]), parameter: z.any() }).strict();
69
- const jzodAttributeDateWithValidations = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.record(z.string(), z.any()).optional() }).strict().extend({ type: z.literal("simpleType"), definition: z.literal("date"), validations: z.array(z.lazy(() => jzodAttributeDateValidations)) }).strict();
70
+ const jzodAttributeDateWithValidations = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.record(z.string(), z.any()).optional() }).strict().extend({ type: z.literal("simpleType"), definition: z.literal("date"), coerce: z.boolean().optional(), validations: z.array(z.lazy(() => jzodAttributeDateValidations)) }).strict();
70
71
  const jzodAttributeNumberValidations = z.object({ extra: z.record(z.string(), z.any()).optional(), type: z.enum(["gt", "gte", "lt", "lte", "int", "positive", "nonpositive", "negative", "nonnegative", "multipleOf", "finite", "safe"]), parameter: z.any() }).strict();
71
- const jzodAttributeNumberWithValidations = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.record(z.string(), z.any()).optional() }).strict().extend({ type: z.literal("simpleType"), definition: z.literal("number"), validations: z.array(z.lazy(() => jzodAttributeNumberValidations)) }).strict();
72
+ const jzodAttributeNumberWithValidations = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.record(z.string(), z.any()).optional() }).strict().extend({ type: z.literal("simpleType"), definition: z.literal("number"), coerce: z.boolean().optional(), validations: z.array(z.lazy(() => jzodAttributeNumberValidations)) }).strict();
72
73
  const jzodAttributeStringValidations = z.object({ extra: z.record(z.string(), z.any()).optional(), type: z.enum(["max", "min", "length", "email", "url", "emoji", "uuid", "cuid", "cuid2", "ulid", "regex", "includes", "startsWith", "endsWith", "datetime", "ip"]), parameter: z.any() }).strict();
73
- const jzodAttributeStringWithValidations = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.record(z.string(), z.any()).optional() }).strict().extend({ type: z.literal("simpleType"), definition: z.literal("string"), validations: z.array(z.lazy(() => jzodAttributeStringValidations)) }).strict();
74
+ const jzodAttributeStringWithValidations = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.record(z.string(), z.any()).optional() }).strict().extend({ type: z.literal("simpleType"), definition: z.literal("string"), coerce: z.boolean().optional(), validations: z.array(z.lazy(() => jzodAttributeStringValidations)) }).strict();
74
75
  const jzodElement = z.union([z.lazy(() => jzodArray), z.lazy(() => jzodAttribute), z.lazy(() => jzodAttributeDateWithValidations), z.lazy(() => jzodAttributeNumberWithValidations), z.lazy(() => jzodAttributeStringWithValidations), z.lazy(() => jzodEnum), z.lazy(() => jzodFunction), z.lazy(() => jzodLazy), z.lazy(() => jzodLiteral), z.lazy(() => jzodIntersection), z.lazy(() => jzodMap), z.lazy(() => jzodObject), z.lazy(() => jzodPromise), z.lazy(() => jzodRecord), z.lazy(() => jzodReference), z.lazy(() => jzodSet), z.lazy(() => jzodTuple), z.lazy(() => jzodUnion)]);
75
76
  const jzodEnum = z.object({ optional: z.boolean().optional(), nullable: z.boolean().optional(), extra: z.record(z.string(), z.any()).optional() }).strict().extend({ type: z.literal("enum"), definition: z.array(z.string()) }).strict();
76
77
  const jzodEnumAttributeTypes = z.enum(["any", "bigint", "boolean", "date", "never", "null", "number", "string", "uuid", "undefined", "unknown", "void"]);
@@ -1,5 +1,5 @@
1
1
  import ts from "typescript";
2
- import { JzodElement } from "./JzodTsInterface";
2
+ import { JzodElement } from "./generated_jzodBootstrapElementSchema";
3
3
  export type TsTypeAliases = {
4
4
  [k: string]: ts.TypeAliasDeclaration;
5
5
  };
@@ -14,4 +14,4 @@ export interface TsTypeAliasesAndZodText {
14
14
  mainZodText: string;
15
15
  }
16
16
  export declare function jzodToTsTypeAliasesAndZodText(element: JzodElement, typeName?: string): TsTypeAliasesAndZodText;
17
- export declare function jzodToTsCode(jzodElement: JzodElement, exportPrefix?: boolean, typeName?: string): string;
17
+ export declare function jzodToTsCode(jzodElement: JzodElement, exportPrefix?: boolean, typeName?: string, typeAnotationForSchema?: string[]): string;
@@ -0,0 +1,246 @@
1
+ import { z } from "zod";
2
+ export type JzodBaseObject = {
3
+ optional?: boolean | undefined;
4
+ nullable?: boolean | undefined;
5
+ extra?: {
6
+ [x: string]: any;
7
+ } | undefined;
8
+ };
9
+ export type JzodArray = {
10
+ optional?: boolean | undefined;
11
+ nullable?: boolean | undefined;
12
+ extra?: {
13
+ [x: string]: any;
14
+ } | undefined;
15
+ type: "array";
16
+ definition: JzodElement;
17
+ };
18
+ export type JzodAttribute = {
19
+ optional?: boolean | undefined;
20
+ nullable?: boolean | undefined;
21
+ extra?: {
22
+ [x: string]: any;
23
+ } | undefined;
24
+ type: "simpleType";
25
+ coerce?: boolean | undefined;
26
+ definition: JzodEnumAttributeTypes;
27
+ };
28
+ export type JzodAttributeDateValidations = {
29
+ extra?: {
30
+ [x: string]: any;
31
+ } | undefined;
32
+ type: "min" | "max";
33
+ parameter?: any;
34
+ };
35
+ export type JzodAttributeDateWithValidations = {
36
+ optional?: boolean | undefined;
37
+ nullable?: boolean | undefined;
38
+ extra?: {
39
+ [x: string]: any;
40
+ } | undefined;
41
+ type: "simpleType";
42
+ definition: "date";
43
+ validations: JzodAttributeDateValidations[];
44
+ };
45
+ export type JzodAttributeNumberValidations = {
46
+ extra?: {
47
+ [x: string]: any;
48
+ } | undefined;
49
+ type: "gt" | "gte" | "lt" | "lte" | "int" | "positive" | "nonpositive" | "negative" | "nonnegative" | "multipleOf" | "finite" | "safe";
50
+ parameter?: any;
51
+ };
52
+ export type JzodAttributeNumberWithValidations = {
53
+ optional?: boolean | undefined;
54
+ nullable?: boolean | undefined;
55
+ extra?: {
56
+ [x: string]: any;
57
+ } | undefined;
58
+ type: "simpleType";
59
+ definition: "number";
60
+ validations: JzodAttributeNumberValidations[];
61
+ };
62
+ export type JzodAttributeStringValidations = {
63
+ extra?: {
64
+ [x: string]: any;
65
+ } | undefined;
66
+ type: "max" | "min" | "length" | "email" | "url" | "emoji" | "uuid" | "cuid" | "cuid2" | "ulid" | "regex" | "includes" | "startsWith" | "endsWith" | "datetime" | "ip";
67
+ parameter?: any;
68
+ };
69
+ export type JzodAttributeStringWithValidations = {
70
+ optional?: boolean | undefined;
71
+ nullable?: boolean | undefined;
72
+ extra?: {
73
+ [x: string]: any;
74
+ } | undefined;
75
+ type: "simpleType";
76
+ definition: "string";
77
+ validations: JzodAttributeStringValidations[];
78
+ };
79
+ export type JzodElement = JzodArray | JzodAttribute | JzodAttributeDateWithValidations | JzodAttributeNumberWithValidations | JzodAttributeStringWithValidations | JzodEnum | JzodFunction | JzodLazy | JzodLiteral | JzodIntersection | JzodMap | JzodObject | JzodPromise | JzodRecord | JzodReference | JzodSet | JzodTuple | JzodUnion;
80
+ export type JzodEnum = {
81
+ optional?: boolean | undefined;
82
+ nullable?: boolean | undefined;
83
+ extra?: {
84
+ [x: string]: any;
85
+ } | undefined;
86
+ type: "enum";
87
+ definition: string[];
88
+ };
89
+ export type JzodEnumAttributeTypes = "any" | "bigint" | "boolean" | "date" | "never" | "null" | "number" | "string" | "uuid" | "undefined" | "unknown" | "void";
90
+ export type JzodEnumElementTypes = "array" | "enum" | "function" | "lazy" | "literal" | "intersection" | "map" | "object" | "promise" | "record" | "schemaReference" | "set" | "simpleType" | "tuple" | "union";
91
+ export type JzodFunction = {
92
+ optional?: boolean | undefined;
93
+ nullable?: boolean | undefined;
94
+ extra?: {
95
+ [x: string]: any;
96
+ } | undefined;
97
+ type: "function";
98
+ definition: {
99
+ args: JzodElement[];
100
+ returns?: JzodElement | undefined;
101
+ };
102
+ };
103
+ export type JzodLazy = {
104
+ optional?: boolean | undefined;
105
+ nullable?: boolean | undefined;
106
+ extra?: {
107
+ [x: string]: any;
108
+ } | undefined;
109
+ type: "lazy";
110
+ definition: JzodFunction;
111
+ };
112
+ export type JzodLiteral = {
113
+ optional?: boolean | undefined;
114
+ nullable?: boolean | undefined;
115
+ extra?: {
116
+ [x: string]: any;
117
+ } | undefined;
118
+ type: "literal";
119
+ definition: string;
120
+ };
121
+ export type JzodIntersection = {
122
+ optional?: boolean | undefined;
123
+ nullable?: boolean | undefined;
124
+ extra?: {
125
+ [x: string]: any;
126
+ } | undefined;
127
+ type: "intersection";
128
+ definition: {
129
+ left: JzodElement;
130
+ right: JzodElement;
131
+ };
132
+ };
133
+ export type JzodMap = {
134
+ optional?: boolean | undefined;
135
+ nullable?: boolean | undefined;
136
+ extra?: {
137
+ [x: string]: any;
138
+ } | undefined;
139
+ type: "map";
140
+ definition: [
141
+ JzodElement,
142
+ JzodElement
143
+ ];
144
+ };
145
+ export type JzodObject = {
146
+ optional?: boolean | undefined;
147
+ nullable?: boolean | undefined;
148
+ extra?: {
149
+ [x: string]: any;
150
+ } | undefined;
151
+ extend?: (JzodReference | JzodObject) | undefined;
152
+ type: "object";
153
+ nonStrict?: boolean | undefined;
154
+ definition: {
155
+ [x: string]: JzodElement;
156
+ };
157
+ };
158
+ export type JzodPromise = {
159
+ optional?: boolean | undefined;
160
+ nullable?: boolean | undefined;
161
+ extra?: {
162
+ [x: string]: any;
163
+ } | undefined;
164
+ type: "promise";
165
+ definition: JzodElement;
166
+ };
167
+ export type JzodRecord = {
168
+ optional?: boolean | undefined;
169
+ nullable?: boolean | undefined;
170
+ extra?: {
171
+ [x: string]: any;
172
+ } | undefined;
173
+ type: "record";
174
+ definition: JzodElement;
175
+ };
176
+ export type JzodReference = {
177
+ optional?: boolean | undefined;
178
+ nullable?: boolean | undefined;
179
+ extra?: {
180
+ [x: string]: any;
181
+ } | undefined;
182
+ type: "schemaReference";
183
+ context?: {
184
+ [x: string]: JzodElement;
185
+ } | undefined;
186
+ definition: {
187
+ eager?: boolean | undefined;
188
+ relativePath?: string | undefined;
189
+ absolutePath?: string | undefined;
190
+ };
191
+ };
192
+ export type JzodSet = {
193
+ optional?: boolean | undefined;
194
+ nullable?: boolean | undefined;
195
+ extra?: {
196
+ [x: string]: any;
197
+ } | undefined;
198
+ type: "set";
199
+ definition: JzodElement;
200
+ };
201
+ export type JzodTuple = {
202
+ optional?: boolean | undefined;
203
+ nullable?: boolean | undefined;
204
+ extra?: {
205
+ [x: string]: any;
206
+ } | undefined;
207
+ type: "tuple";
208
+ definition: JzodElement[];
209
+ };
210
+ export type JzodUnion = {
211
+ optional?: boolean | undefined;
212
+ nullable?: boolean | undefined;
213
+ extra?: {
214
+ [x: string]: any;
215
+ } | undefined;
216
+ type: "union";
217
+ discriminator?: string | undefined;
218
+ definition: JzodElement[];
219
+ };
220
+ export type JzodBootstrapElementSchema = JzodElement;
221
+ export declare const jzodBaseObject: z.ZodType<JzodBaseObject>;
222
+ export declare const jzodArray: z.ZodType<JzodArray>;
223
+ export declare const jzodAttribute: z.ZodType<JzodAttribute>;
224
+ export declare const jzodAttributeDateValidations: z.ZodType<JzodAttributeDateValidations>;
225
+ export declare const jzodAttributeDateWithValidations: z.ZodType<JzodAttributeDateWithValidations>;
226
+ export declare const jzodAttributeNumberValidations: z.ZodType<JzodAttributeNumberValidations>;
227
+ export declare const jzodAttributeNumberWithValidations: z.ZodType<JzodAttributeNumberWithValidations>;
228
+ export declare const jzodAttributeStringValidations: z.ZodType<JzodAttributeStringValidations>;
229
+ export declare const jzodAttributeStringWithValidations: z.ZodType<JzodAttributeStringWithValidations>;
230
+ export declare const jzodElement: z.ZodType<JzodElement>;
231
+ export declare const jzodEnum: z.ZodType<JzodEnum>;
232
+ export declare const jzodEnumAttributeTypes: z.ZodType<JzodEnumAttributeTypes>;
233
+ export declare const jzodEnumElementTypes: z.ZodType<JzodEnumElementTypes>;
234
+ export declare const jzodFunction: z.ZodType<JzodFunction>;
235
+ export declare const jzodLazy: z.ZodType<JzodLazy>;
236
+ export declare const jzodLiteral: z.ZodType<JzodLiteral>;
237
+ export declare const jzodIntersection: z.ZodType<JzodIntersection>;
238
+ export declare const jzodMap: z.ZodType<JzodMap>;
239
+ export declare const jzodObject: z.ZodType<JzodObject>;
240
+ export declare const jzodPromise: z.ZodType<JzodPromise>;
241
+ export declare const jzodRecord: z.ZodType<JzodRecord>;
242
+ export declare const jzodReference: z.ZodType<JzodReference>;
243
+ export declare const jzodSet: z.ZodType<JzodSet>;
244
+ export declare const jzodTuple: z.ZodType<JzodTuple>;
245
+ export declare const jzodUnion: z.ZodType<JzodUnion>;
246
+ export declare const jzodBootstrapElementSchema: z.ZodType<JzodBootstrapElementSchema>;
@@ -1,3 +1,3 @@
1
1
  export { jzodToTsCode, jzodToTsTypeAliasesAndZodText, TsTypeAliasesAndZodText as JzodTypeAliasesAndZodText, TsTypeAliases, } from "./JzodToTs";
2
2
  export { printTsTypeAlias, printTsTypeAliases } from "./tools";
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";
3
+ export { jzodArray, jzodAttribute, jzodAttributeDateValidations, jzodAttributeDateWithValidations, jzodAttributeNumberValidations, jzodAttributeNumberWithValidations, jzodAttributeStringValidations, jzodAttributeStringWithValidations, jzodElement, jzodEnumAttributeTypes, jzodEnumElementTypes, jzodEnum, jzodFunction, jzodIntersection, jzodLazy, jzodLiteral, jzodMap, jzodObject, jzodPromise, jzodRecord, jzodReference, jzodSet, jzodTuple, jzodUnion, JzodArray, JzodAttribute, JzodAttributeDateValidations, JzodAttributeDateWithValidations, JzodAttributeNumberValidations, JzodAttributeNumberWithValidations, JzodAttributeStringValidations, JzodAttributeStringWithValidations, JzodElement, JzodEnum, JzodEnumAttributeTypes, JzodFunction, JzodEnumElementTypes, JzodIntersection, JzodLazy, JzodLiteral, JzodMap, JzodObject, JzodPromise, JzodRecord, JzodReference, JzodSet, JzodUnion, JzodTuple, } from "./generated_jzodBootstrapElementSchema";
@@ -14,4 +14,4 @@ export interface TsTypeAliasesAndZodText {
14
14
  mainZodText: string;
15
15
  }
16
16
  export declare function jzodToTsTypeAliasesAndZodText(element: JzodElement, typeName?: string): TsTypeAliasesAndZodText;
17
- export declare function jzodToTsCode(jzodElement: JzodElement, exportPrefix?: boolean, typeName?: string, typeSchema?: boolean): string;
17
+ export declare function jzodToTsCode(jzodElement: JzodElement, exportPrefix?: boolean, typeName?: string, typeAnotationForSchema?: string[]): string;
@@ -1,4 +1,4 @@
1
- import { z } from "zod";
1
+ import { ZodType, z } from "zod";
2
2
  export type JzodBaseObject = {
3
3
  optional?: boolean | undefined;
4
4
  nullable?: boolean | undefined;
@@ -40,6 +40,7 @@ export type JzodAttributeDateWithValidations = {
40
40
  } | undefined;
41
41
  type: "simpleType";
42
42
  definition: "date";
43
+ coerce?: boolean | undefined;
43
44
  validations: JzodAttributeDateValidations[];
44
45
  };
45
46
  export type JzodAttributeNumberValidations = {
@@ -57,6 +58,7 @@ export type JzodAttributeNumberWithValidations = {
57
58
  } | undefined;
58
59
  type: "simpleType";
59
60
  definition: "number";
61
+ coerce?: boolean | undefined;
60
62
  validations: JzodAttributeNumberValidations[];
61
63
  };
62
64
  export type JzodAttributeStringValidations = {
@@ -74,6 +76,7 @@ export type JzodAttributeStringWithValidations = {
74
76
  } | undefined;
75
77
  type: "simpleType";
76
78
  definition: "string";
79
+ coerce?: boolean | undefined;
77
80
  validations: JzodAttributeStringValidations[];
78
81
  };
79
82
  export type JzodElement = JzodArray | JzodAttribute | JzodAttributeDateWithValidations | JzodAttributeNumberWithValidations | JzodAttributeStringWithValidations | JzodEnum | JzodFunction | JzodLazy | JzodLiteral | JzodIntersection | JzodMap | JzodObject | JzodPromise | JzodRecord | JzodReference | JzodSet | JzodTuple | JzodUnion;
@@ -243,4 +246,4 @@ export declare const jzodReference: z.ZodType<JzodReference>;
243
246
  export declare const jzodSet: z.ZodType<JzodSet>;
244
247
  export declare const jzodTuple: z.ZodType<JzodTuple>;
245
248
  export declare const jzodUnion: z.ZodType<JzodUnion>;
246
- export declare const jzodBootstrapElementSchema: z.ZodType<JzodBootstrapElementSchema>;
249
+ export declare const jzodBootstrapElementSchema: z.ZodLazy<ZodType<JzodElement, z.ZodTypeDef, JzodElement>>;
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "@miroir-framework/jzod-ts",
3
3
  "private": false,
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "description": "The Typescript-related functionalities of Jzod.",
6
6
  "main": "dist/bundle.js",
7
7
  "types": "dist/bundle.d.ts",
8
8
  "type": "module",
9
9
  "scripts": {
10
- "preBuild": "npm run-script ./dist/out-tsc/src/preBuild.js",
10
+ "preBuild": "tsc --rootDir . --baseUrl . --module ESnext --target ES2017 --moduleResolution node --allowSyntheticDefaultImports --outdir ./tmp/ || node ./tmp/src/preBuild.js",
11
11
  "compile": "npx tsc",
12
12
  "build": "rollup --config",
13
13
  "test": "cross-env NODE_ENV=test jest --verbose --silent=false -t"
14
14
  },
15
- "author": "Arnaud Bailly <miroir-framework@protonmail.com>",
15
+ "author": "Miroir Framework <miroir-framework@protonmail.com>",
16
16
  "homepage": "https://github.com/miroir-framework/jzod/#readme",
17
17
  "bugs": "https://github.com/miroir-framework/jzod/issues",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@miroir-framework/jzod": "0.6.0",
20
+ "@miroir-framework/jzod": "0.6.1",
21
21
  "zod": "^3.22.2",
22
22
  "zod-to-ts": "^1.2.0"
23
23
  },
package/src/JzodToTs.ts CHANGED
@@ -34,7 +34,7 @@ export function jzodToTsTypeAliasesAndZodText(
34
34
  withGetType(innerReference, (ts:any) => {
35
35
  const actualTypeName = relativeReference?relativeReference.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
36
36
  return ts.factory.createTypeReferenceNode(
37
- ts.factory.createIdentifier(actualTypeName ? actualTypeName : "RELATIVEPATH_NOT_DEFINED"),
37
+ ts.factory.createIdentifier(actualTypeName ?? "RELATIVEPATH_NOT_DEFINED"),
38
38
  undefined
39
39
  );
40
40
  }
@@ -67,7 +67,8 @@ export function jzodToTsCode (
67
67
  jzodElement: JzodElement,
68
68
  exportPrefix: boolean = true,
69
69
  typeName?: string,
70
- typeSchema: boolean = false,
70
+ // typeSchema: boolean = false,
71
+ typeAnotationForSchema: string[] = [],
71
72
  ): string {
72
73
  // console.log(
73
74
  // "################################### jzodToTsCode ",
@@ -77,13 +78,14 @@ export function jzodToTsCode (
77
78
 
78
79
  const schemaName = typeName?typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toLowerCase() + c):"";
79
80
  const actualTypeName = typeName?typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
80
- // console.log("jzodToTsCode convertedJsonZodSchema", bodyJsCode);
81
+
82
+ // console.log("jzodToTsCode typeAnotationForSchema", typeAnotationForSchema);
81
83
 
82
84
  const header = `import { ZodType, ZodTypeAny, z } from "zod";`;
83
85
 
84
86
  const typeAliasesAndZodText = jzodToTsTypeAliasesAndZodText(jzodElement, actualTypeName);
85
87
 
86
- const bodyJsCode = typeSchema
88
+ const bodyJsCode = typeAnotationForSchema.includes(schemaName??"")
87
89
  ? `export const ${schemaName}: z.ZodType<${actualTypeName}> = ${typeAliasesAndZodText.mainZodText};`
88
90
  : `export const ${schemaName} = ${typeAliasesAndZodText.mainZodText};`;
89
91
 
@@ -93,12 +95,14 @@ export function jzodToTsCode (
93
95
  const contextJsCode = typeAliasesAndZodText.contextZodText
94
96
  ? Object.entries(typeAliasesAndZodText.contextZodText).reduce((acc, curr) => {
95
97
  const contextTypeName = curr[0]?curr[0].replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c):"";
96
- return typeSchema?
98
+ return typeAnotationForSchema.includes(curr[0])?
97
99
  `${acc}
98
- export const ${curr[0]}: z.ZodType<${contextTypeName}> = ${curr[1]};`:
100
+ export const ${curr[0]}: z.ZodType<${contextTypeName}> = ${curr[1]};`
101
+ :
99
102
  `${acc}
100
- export const ${curr[0]} = ${curr[1]};`;
101
- }, "")
103
+ export const ${curr[0]} = ${curr[1]};`
104
+ ;
105
+ }, "")
102
106
  : ""
103
107
  ;
104
108