@miroir-framework/jzod-ts 0.5.3 → 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 +177 -334
- package/dist/bundle.js +43 -257
- package/dist/out-tsc/dts/src/JzodToTs.d.ts +17 -0
- package/dist/out-tsc/dts/src/generated_jzodBootstrapElementSchema.d.ts +246 -0
- package/dist/out-tsc/dts/src/index.d.ts +3 -0
- package/dist/out-tsc/dts/src/preBuild.d.ts +1 -0
- package/dist/out-tsc/dts/src/tools.d.ts +4 -0
- package/dist/src/JzodToTs.d.ts +2 -2
- package/dist/src/generated_jzodBootstrapElementSchema.d.ts +249 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/preBuild.d.ts +1 -0
- package/package.json +40 -38
- package/src/JzodToTs.ts +118 -109
- package/src/generated_jzodBootstrapElementSchema.ts +252 -0
- package/src/index.ts +60 -60
- package/src/preBuild.ts +54 -0
- package/tests/jzod-ts.test.ts +107 -108
- package/tests/resources/tsTypeGeneration-testJzodSchema1 - reference.ts +5 -5
- package/tests/resources/tsTypeGeneration-testJzodSchema2 - reference.ts +11 -11
- package/tests/resources/tsTypeGeneration-testJzodSchema3 - reference.ts +19 -19
- package/tests/resources/tsTypeGeneration-testJzodSchema4 - reference.ts +253 -250
- package/tsconfig.json +25 -25
- package/dist/src/JzodTsInterface.d.ts +0 -397
- package/src/JzodTsInterface.ts +0 -450
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
+
|
|
3
|
+
export type JzodBaseObject = {
|
|
4
|
+
optional?: boolean | undefined;
|
|
5
|
+
nullable?: boolean | undefined;
|
|
6
|
+
extra?: {
|
|
7
|
+
[x: string]: any;
|
|
8
|
+
} | undefined;
|
|
9
|
+
};
|
|
10
|
+
export type JzodArray = {
|
|
11
|
+
optional?: boolean | undefined;
|
|
12
|
+
nullable?: boolean | undefined;
|
|
13
|
+
extra?: {
|
|
14
|
+
[x: string]: any;
|
|
15
|
+
} | undefined;
|
|
16
|
+
type: "array";
|
|
17
|
+
definition: JzodElement;
|
|
18
|
+
};
|
|
19
|
+
export type JzodAttribute = {
|
|
20
|
+
optional?: boolean | undefined;
|
|
21
|
+
nullable?: boolean | undefined;
|
|
22
|
+
extra?: {
|
|
23
|
+
[x: string]: any;
|
|
24
|
+
} | undefined;
|
|
25
|
+
type: "simpleType";
|
|
26
|
+
coerce?: boolean | undefined;
|
|
27
|
+
definition: JzodEnumAttributeTypes;
|
|
28
|
+
};
|
|
29
|
+
export type JzodAttributeDateValidations = {
|
|
30
|
+
extra?: {
|
|
31
|
+
[x: string]: any;
|
|
32
|
+
} | undefined;
|
|
33
|
+
type: "min" | "max";
|
|
34
|
+
parameter?: any;
|
|
35
|
+
};
|
|
36
|
+
export type JzodAttributeDateWithValidations = {
|
|
37
|
+
optional?: boolean | undefined;
|
|
38
|
+
nullable?: boolean | undefined;
|
|
39
|
+
extra?: {
|
|
40
|
+
[x: string]: any;
|
|
41
|
+
} | undefined;
|
|
42
|
+
type: "simpleType";
|
|
43
|
+
definition: "date";
|
|
44
|
+
coerce?: boolean | undefined;
|
|
45
|
+
validations: JzodAttributeDateValidations[];
|
|
46
|
+
};
|
|
47
|
+
export type JzodAttributeNumberValidations = {
|
|
48
|
+
extra?: {
|
|
49
|
+
[x: string]: any;
|
|
50
|
+
} | undefined;
|
|
51
|
+
type: "gt" | "gte" | "lt" | "lte" | "int" | "positive" | "nonpositive" | "negative" | "nonnegative" | "multipleOf" | "finite" | "safe";
|
|
52
|
+
parameter?: any;
|
|
53
|
+
};
|
|
54
|
+
export type JzodAttributeNumberWithValidations = {
|
|
55
|
+
optional?: boolean | undefined;
|
|
56
|
+
nullable?: boolean | undefined;
|
|
57
|
+
extra?: {
|
|
58
|
+
[x: string]: any;
|
|
59
|
+
} | undefined;
|
|
60
|
+
type: "simpleType";
|
|
61
|
+
definition: "number";
|
|
62
|
+
coerce?: boolean | undefined;
|
|
63
|
+
validations: JzodAttributeNumberValidations[];
|
|
64
|
+
};
|
|
65
|
+
export type JzodAttributeStringValidations = {
|
|
66
|
+
extra?: {
|
|
67
|
+
[x: string]: any;
|
|
68
|
+
} | undefined;
|
|
69
|
+
type: "max" | "min" | "length" | "email" | "url" | "emoji" | "uuid" | "cuid" | "cuid2" | "ulid" | "regex" | "includes" | "startsWith" | "endsWith" | "datetime" | "ip";
|
|
70
|
+
parameter?: any;
|
|
71
|
+
};
|
|
72
|
+
export type JzodAttributeStringWithValidations = {
|
|
73
|
+
optional?: boolean | undefined;
|
|
74
|
+
nullable?: boolean | undefined;
|
|
75
|
+
extra?: {
|
|
76
|
+
[x: string]: any;
|
|
77
|
+
} | undefined;
|
|
78
|
+
type: "simpleType";
|
|
79
|
+
definition: "string";
|
|
80
|
+
coerce?: boolean | undefined;
|
|
81
|
+
validations: JzodAttributeStringValidations[];
|
|
82
|
+
};
|
|
83
|
+
export type JzodElement = JzodArray | JzodAttribute | JzodAttributeDateWithValidations | JzodAttributeNumberWithValidations | JzodAttributeStringWithValidations | JzodEnum | JzodFunction | JzodLazy | JzodLiteral | JzodIntersection | JzodMap | JzodObject | JzodPromise | JzodRecord | JzodReference | JzodSet | JzodTuple | JzodUnion;
|
|
84
|
+
export type JzodEnum = {
|
|
85
|
+
optional?: boolean | undefined;
|
|
86
|
+
nullable?: boolean | undefined;
|
|
87
|
+
extra?: {
|
|
88
|
+
[x: string]: any;
|
|
89
|
+
} | undefined;
|
|
90
|
+
type: "enum";
|
|
91
|
+
definition: string[];
|
|
92
|
+
};
|
|
93
|
+
export type JzodEnumAttributeTypes = "any" | "bigint" | "boolean" | "date" | "never" | "null" | "number" | "string" | "uuid" | "undefined" | "unknown" | "void";
|
|
94
|
+
export type JzodEnumElementTypes = "array" | "enum" | "function" | "lazy" | "literal" | "intersection" | "map" | "object" | "promise" | "record" | "schemaReference" | "set" | "simpleType" | "tuple" | "union";
|
|
95
|
+
export type JzodFunction = {
|
|
96
|
+
optional?: boolean | undefined;
|
|
97
|
+
nullable?: boolean | undefined;
|
|
98
|
+
extra?: {
|
|
99
|
+
[x: string]: any;
|
|
100
|
+
} | undefined;
|
|
101
|
+
type: "function";
|
|
102
|
+
definition: {
|
|
103
|
+
args: JzodElement[];
|
|
104
|
+
returns?: JzodElement | undefined;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
export type JzodLazy = {
|
|
108
|
+
optional?: boolean | undefined;
|
|
109
|
+
nullable?: boolean | undefined;
|
|
110
|
+
extra?: {
|
|
111
|
+
[x: string]: any;
|
|
112
|
+
} | undefined;
|
|
113
|
+
type: "lazy";
|
|
114
|
+
definition: JzodFunction;
|
|
115
|
+
};
|
|
116
|
+
export type JzodLiteral = {
|
|
117
|
+
optional?: boolean | undefined;
|
|
118
|
+
nullable?: boolean | undefined;
|
|
119
|
+
extra?: {
|
|
120
|
+
[x: string]: any;
|
|
121
|
+
} | undefined;
|
|
122
|
+
type: "literal";
|
|
123
|
+
definition: string;
|
|
124
|
+
};
|
|
125
|
+
export type JzodIntersection = {
|
|
126
|
+
optional?: boolean | undefined;
|
|
127
|
+
nullable?: boolean | undefined;
|
|
128
|
+
extra?: {
|
|
129
|
+
[x: string]: any;
|
|
130
|
+
} | undefined;
|
|
131
|
+
type: "intersection";
|
|
132
|
+
definition: {
|
|
133
|
+
left: JzodElement;
|
|
134
|
+
right: JzodElement;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
export type JzodMap = {
|
|
138
|
+
optional?: boolean | undefined;
|
|
139
|
+
nullable?: boolean | undefined;
|
|
140
|
+
extra?: {
|
|
141
|
+
[x: string]: any;
|
|
142
|
+
} | undefined;
|
|
143
|
+
type: "map";
|
|
144
|
+
definition: [
|
|
145
|
+
JzodElement,
|
|
146
|
+
JzodElement
|
|
147
|
+
];
|
|
148
|
+
};
|
|
149
|
+
export type JzodObject = {
|
|
150
|
+
optional?: boolean | undefined;
|
|
151
|
+
nullable?: boolean | undefined;
|
|
152
|
+
extra?: {
|
|
153
|
+
[x: string]: any;
|
|
154
|
+
} | undefined;
|
|
155
|
+
extend?: (JzodReference | JzodObject) | undefined;
|
|
156
|
+
type: "object";
|
|
157
|
+
nonStrict?: boolean | undefined;
|
|
158
|
+
definition: {
|
|
159
|
+
[x: string]: JzodElement;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
export type JzodPromise = {
|
|
163
|
+
optional?: boolean | undefined;
|
|
164
|
+
nullable?: boolean | undefined;
|
|
165
|
+
extra?: {
|
|
166
|
+
[x: string]: any;
|
|
167
|
+
} | undefined;
|
|
168
|
+
type: "promise";
|
|
169
|
+
definition: JzodElement;
|
|
170
|
+
};
|
|
171
|
+
export type JzodRecord = {
|
|
172
|
+
optional?: boolean | undefined;
|
|
173
|
+
nullable?: boolean | undefined;
|
|
174
|
+
extra?: {
|
|
175
|
+
[x: string]: any;
|
|
176
|
+
} | undefined;
|
|
177
|
+
type: "record";
|
|
178
|
+
definition: JzodElement;
|
|
179
|
+
};
|
|
180
|
+
export type JzodReference = {
|
|
181
|
+
optional?: boolean | undefined;
|
|
182
|
+
nullable?: boolean | undefined;
|
|
183
|
+
extra?: {
|
|
184
|
+
[x: string]: any;
|
|
185
|
+
} | undefined;
|
|
186
|
+
type: "schemaReference";
|
|
187
|
+
context?: {
|
|
188
|
+
[x: string]: JzodElement;
|
|
189
|
+
} | undefined;
|
|
190
|
+
definition: {
|
|
191
|
+
eager?: boolean | undefined;
|
|
192
|
+
relativePath?: string | undefined;
|
|
193
|
+
absolutePath?: string | undefined;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
export type JzodSet = {
|
|
197
|
+
optional?: boolean | undefined;
|
|
198
|
+
nullable?: boolean | undefined;
|
|
199
|
+
extra?: {
|
|
200
|
+
[x: string]: any;
|
|
201
|
+
} | undefined;
|
|
202
|
+
type: "set";
|
|
203
|
+
definition: JzodElement;
|
|
204
|
+
};
|
|
205
|
+
export type JzodTuple = {
|
|
206
|
+
optional?: boolean | undefined;
|
|
207
|
+
nullable?: boolean | undefined;
|
|
208
|
+
extra?: {
|
|
209
|
+
[x: string]: any;
|
|
210
|
+
} | undefined;
|
|
211
|
+
type: "tuple";
|
|
212
|
+
definition: JzodElement[];
|
|
213
|
+
};
|
|
214
|
+
export type JzodUnion = {
|
|
215
|
+
optional?: boolean | undefined;
|
|
216
|
+
nullable?: boolean | undefined;
|
|
217
|
+
extra?: {
|
|
218
|
+
[x: string]: any;
|
|
219
|
+
} | undefined;
|
|
220
|
+
type: "union";
|
|
221
|
+
discriminator?: string | undefined;
|
|
222
|
+
definition: JzodElement[];
|
|
223
|
+
};
|
|
224
|
+
export type JzodBootstrapElementSchema = JzodElement;
|
|
225
|
+
|
|
226
|
+
export const jzodBaseObject: z.ZodType<JzodBaseObject> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict();
|
|
227
|
+
export const jzodArray: z.ZodType<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();
|
|
228
|
+
export const jzodAttribute: z.ZodType<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();
|
|
229
|
+
export const jzodAttributeDateValidations: z.ZodType<JzodAttributeDateValidations> = z.object({extra:z.record(z.string(),z.any()).optional(), type:z.enum(["min","max"]), parameter:z.any()}).strict();
|
|
230
|
+
export const jzodAttributeDateWithValidations: z.ZodType<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();
|
|
231
|
+
export const jzodAttributeNumberValidations: z.ZodType<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();
|
|
232
|
+
export const jzodAttributeNumberWithValidations: z.ZodType<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();
|
|
233
|
+
export const jzodAttributeStringValidations: z.ZodType<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();
|
|
234
|
+
export const jzodAttributeStringWithValidations: z.ZodType<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();
|
|
235
|
+
export const jzodElement: z.ZodType<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)]);
|
|
236
|
+
export const jzodEnum: z.ZodType<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();
|
|
237
|
+
export const jzodEnumAttributeTypes: z.ZodType<JzodEnumAttributeTypes> = z.enum(["any","bigint","boolean","date","never","null","number","string","uuid","undefined","unknown","void"]);
|
|
238
|
+
export const jzodEnumElementTypes: z.ZodType<JzodEnumElementTypes> = z.enum(["array","enum","function","lazy","literal","intersection","map","object","promise","record","schemaReference","set","simpleType","tuple","union"]);
|
|
239
|
+
export const jzodFunction: z.ZodType<JzodFunction> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("function"), definition:z.object({args:z.array(z.lazy(() =>jzodElement)), returns:z.lazy(() =>jzodElement).optional()}).strict()}).strict();
|
|
240
|
+
export const jzodLazy: z.ZodType<JzodLazy> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("lazy"), definition:z.lazy(() =>jzodFunction)}).strict();
|
|
241
|
+
export const jzodLiteral: z.ZodType<JzodLiteral> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("literal"), definition:z.string()}).strict();
|
|
242
|
+
export const jzodIntersection: z.ZodType<JzodIntersection> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("intersection"), definition:z.object({left:z.lazy(() =>jzodElement), right:z.lazy(() =>jzodElement)}).strict()}).strict();
|
|
243
|
+
export const jzodMap: z.ZodType<JzodMap> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("map"), definition:z.tuple([z.lazy(() =>jzodElement), z.lazy(() =>jzodElement)])}).strict();
|
|
244
|
+
export const jzodObject: z.ZodType<JzodObject> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({extend:z.union([z.lazy(() =>jzodReference), z.lazy(() =>jzodObject)]).optional(), type:z.literal("object"), nonStrict:z.boolean().optional(), definition:z.record(z.string(),z.lazy(() =>jzodElement))}).strict();
|
|
245
|
+
export const jzodPromise: z.ZodType<JzodPromise> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("promise"), definition:z.lazy(() =>jzodElement)}).strict();
|
|
246
|
+
export const jzodRecord: z.ZodType<JzodRecord> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("record"), definition:z.lazy(() =>jzodElement)}).strict();
|
|
247
|
+
export const jzodReference: z.ZodType<JzodReference> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("schemaReference"), context:z.record(z.string(),z.lazy(() =>jzodElement)).optional(), definition:z.object({eager:z.boolean().optional(), relativePath:z.string().optional(), absolutePath:z.string().optional()}).strict()}).strict();
|
|
248
|
+
export const jzodSet: z.ZodType<JzodSet> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("set"), definition:z.lazy(() =>jzodElement)}).strict();
|
|
249
|
+
export const jzodTuple: z.ZodType<JzodTuple> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("tuple"), definition:z.array(z.lazy(() =>jzodElement))}).strict();
|
|
250
|
+
export const jzodUnion: z.ZodType<JzodUnion> = z.object({optional:z.boolean().optional(), nullable:z.boolean().optional(), extra:z.record(z.string(),z.any()).optional()}).strict().extend({type:z.literal("union"), discriminator:z.string().optional(), definition:z.array(z.lazy(() =>jzodElement))}).strict();
|
|
251
|
+
export const jzodBootstrapElementSchema = z.lazy(() =>jzodElement);
|
|
252
|
+
|
package/src/index.ts
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
export {
|
|
2
|
-
jzodToTsCode,
|
|
3
|
-
jzodToTsTypeAliasesAndZodText,
|
|
4
|
-
TsTypeAliasesAndZodText as JzodTypeAliasesAndZodText,
|
|
5
|
-
TsTypeAliases,
|
|
6
|
-
} from "./JzodToTs";
|
|
7
|
-
export { printTsTypeAlias, printTsTypeAliases } from "./tools";
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
// SCHEMAS (const)
|
|
11
|
-
jzodArray,
|
|
12
|
-
jzodAttribute,
|
|
13
|
-
jzodAttributeDateValidations,
|
|
14
|
-
jzodAttributeDateWithValidations,
|
|
15
|
-
jzodAttributeNumberValidations,
|
|
16
|
-
jzodAttributeNumberWithValidations,
|
|
17
|
-
jzodAttributeStringValidations,
|
|
18
|
-
jzodAttributeStringWithValidations,
|
|
19
|
-
jzodElement,
|
|
20
|
-
jzodEnumAttributeTypes,
|
|
21
|
-
jzodEnumElementTypes,
|
|
22
|
-
jzodEnum,
|
|
23
|
-
jzodFunction,
|
|
24
|
-
jzodIntersection,
|
|
25
|
-
jzodLazy,
|
|
26
|
-
jzodLiteral,
|
|
27
|
-
|
|
28
|
-
jzodObject,
|
|
29
|
-
jzodPromise,
|
|
30
|
-
jzodRecord,
|
|
31
|
-
jzodReference,
|
|
32
|
-
jzodSet,
|
|
33
|
-
jzodTuple,
|
|
34
|
-
jzodUnion,
|
|
35
|
-
// TYPES
|
|
36
|
-
JzodArray,
|
|
37
|
-
JzodAttribute,
|
|
38
|
-
JzodAttributeDateValidations,
|
|
39
|
-
JzodAttributeDateWithValidations,
|
|
40
|
-
JzodAttributeNumberValidations,
|
|
41
|
-
JzodAttributeNumberWithValidations,
|
|
42
|
-
JzodAttributeStringValidations,
|
|
43
|
-
JzodAttributeStringWithValidations,
|
|
44
|
-
JzodElement,
|
|
45
|
-
JzodEnum,
|
|
46
|
-
|
|
47
|
-
JzodFunction,
|
|
48
|
-
JzodEnumElementTypes,
|
|
49
|
-
JzodIntersection,
|
|
50
|
-
JzodLazy,
|
|
51
|
-
JzodLiteral,
|
|
52
|
-
JzodMap,
|
|
53
|
-
JzodObject,
|
|
54
|
-
JzodPromise,
|
|
55
|
-
JzodRecord,
|
|
56
|
-
JzodReference,
|
|
57
|
-
JzodSet,
|
|
58
|
-
JzodUnion,
|
|
59
|
-
JzodTuple,
|
|
60
|
-
} from "./
|
|
1
|
+
export {
|
|
2
|
+
jzodToTsCode,
|
|
3
|
+
jzodToTsTypeAliasesAndZodText,
|
|
4
|
+
TsTypeAliasesAndZodText as JzodTypeAliasesAndZodText,
|
|
5
|
+
TsTypeAliases,
|
|
6
|
+
} from "./JzodToTs";
|
|
7
|
+
export { printTsTypeAlias, printTsTypeAliases } from "./tools";
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
// SCHEMAS (const)
|
|
11
|
+
jzodArray,
|
|
12
|
+
jzodAttribute,
|
|
13
|
+
jzodAttributeDateValidations,
|
|
14
|
+
jzodAttributeDateWithValidations,
|
|
15
|
+
jzodAttributeNumberValidations,
|
|
16
|
+
jzodAttributeNumberWithValidations,
|
|
17
|
+
jzodAttributeStringValidations,
|
|
18
|
+
jzodAttributeStringWithValidations,
|
|
19
|
+
jzodElement,
|
|
20
|
+
jzodEnumAttributeTypes,
|
|
21
|
+
jzodEnumElementTypes,
|
|
22
|
+
jzodEnum,
|
|
23
|
+
jzodFunction,
|
|
24
|
+
jzodIntersection,
|
|
25
|
+
jzodLazy,
|
|
26
|
+
jzodLiteral,
|
|
27
|
+
jzodMap,
|
|
28
|
+
jzodObject,
|
|
29
|
+
jzodPromise,
|
|
30
|
+
jzodRecord,
|
|
31
|
+
jzodReference,
|
|
32
|
+
jzodSet,
|
|
33
|
+
jzodTuple,
|
|
34
|
+
jzodUnion,
|
|
35
|
+
// TYPES
|
|
36
|
+
JzodArray,
|
|
37
|
+
JzodAttribute,
|
|
38
|
+
JzodAttributeDateValidations,
|
|
39
|
+
JzodAttributeDateWithValidations,
|
|
40
|
+
JzodAttributeNumberValidations,
|
|
41
|
+
JzodAttributeNumberWithValidations,
|
|
42
|
+
JzodAttributeStringValidations,
|
|
43
|
+
JzodAttributeStringWithValidations,
|
|
44
|
+
JzodElement,
|
|
45
|
+
JzodEnum,
|
|
46
|
+
JzodEnumAttributeTypes,
|
|
47
|
+
JzodFunction,
|
|
48
|
+
JzodEnumElementTypes,
|
|
49
|
+
JzodIntersection,
|
|
50
|
+
JzodLazy,
|
|
51
|
+
JzodLiteral,
|
|
52
|
+
JzodMap,
|
|
53
|
+
JzodObject,
|
|
54
|
+
JzodPromise,
|
|
55
|
+
JzodRecord,
|
|
56
|
+
JzodReference,
|
|
57
|
+
JzodSet,
|
|
58
|
+
JzodUnion,
|
|
59
|
+
JzodTuple,
|
|
60
|
+
} from "./generated_jzodBootstrapElementSchema";
|
package/src/preBuild.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { jzodBootstrapElementSchema } from '@miroir-framework/jzod';
|
|
3
|
+
|
|
4
|
+
import { jzodToTsCode } from './JzodToTs.js';
|
|
5
|
+
|
|
6
|
+
export function generateZodSchemaFileFromJzodSchema(
|
|
7
|
+
jzodElement: any, //JzodElement,
|
|
8
|
+
targetFileName: string,
|
|
9
|
+
jzodSchemaVariableName:string,
|
|
10
|
+
) {
|
|
11
|
+
// console.log("generateZodSchemaFileFromJzodSchema called!");
|
|
12
|
+
|
|
13
|
+
const newFileContentsNotFormated = jzodToTsCode(jzodElement, true, jzodSchemaVariableName,Object.keys(jzodElement.context))
|
|
14
|
+
// const newFileContents = `import { JzodObject, jzodObject } from "@miroir-framework/jzod-ts";
|
|
15
|
+
const newFileContents = `${newFileContentsNotFormated}
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
if (targetFileName && existsSync(targetFileName)) {
|
|
19
|
+
const oldFileContents = readFileSync(targetFileName).toString()
|
|
20
|
+
if (newFileContents != oldFileContents) {
|
|
21
|
+
// console.log("generateZodSchemaFileFromJzodSchema newFileContents",newFileContents);
|
|
22
|
+
writeFileSync(targetFileName,newFileContents);
|
|
23
|
+
} else {
|
|
24
|
+
console.log("generateZodSchemaFileFromJzodSchema entityDefinitionReport old contents equal new contents, no file generation needed.");
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
writeFileSync(targetFileName,newFileContents);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ################################################################################################
|
|
32
|
+
const jzodSchemaConversion
|
|
33
|
+
: {
|
|
34
|
+
jzodElement: any,
|
|
35
|
+
targetFileName: string,
|
|
36
|
+
jzodSchemaVariableName:string,
|
|
37
|
+
}[]
|
|
38
|
+
= [
|
|
39
|
+
{
|
|
40
|
+
jzodElement: jzodBootstrapElementSchema,
|
|
41
|
+
targetFileName: "./src/generated_jzodBootstrapElementSchema.ts",
|
|
42
|
+
jzodSchemaVariableName: "jzodBootstrapElementSchema",
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
for (const schema of jzodSchemaConversion) {
|
|
48
|
+
generateZodSchemaFileFromJzodSchema(schema.jzodElement,schema.targetFileName,schema.jzodSchemaVariableName)
|
|
49
|
+
console.info("GENERATED",schema.targetFileName);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error("could not generate TS files from Jzod schemas", error);
|
|
54
|
+
}
|
package/tests/jzod-ts.test.ts
CHANGED
|
@@ -1,108 +1,107 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
|
|
4
|
-
import { jzodBootstrapElementSchema } from "@miroir-framework/jzod";
|
|
5
|
-
import { jzodToTsCode } from "../src/JzodToTs";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"tsTypeGeneration-testJzodSchema1
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"tsTypeGeneration-testJzodSchema2
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
type: "
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"tsTypeGeneration-testJzodSchema4
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
|
|
4
|
+
import { jzodBootstrapElementSchema } from "@miroir-framework/jzod";
|
|
5
|
+
import { jzodToTsCode } from "../src/JzodToTs";
|
|
6
|
+
|
|
7
|
+
const refsPath = "./tests/resources"
|
|
8
|
+
const tmpPath = "./tests/tmp";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const testJzodToTs = (
|
|
12
|
+
// testDirectory: string,
|
|
13
|
+
referenceFileName: string,
|
|
14
|
+
testFileName: string,
|
|
15
|
+
testJzodSchema: any, //JzodElement,
|
|
16
|
+
exportPrefix: boolean,
|
|
17
|
+
typeName: string
|
|
18
|
+
) => {
|
|
19
|
+
console.log("testJzodToTs:", typeName);
|
|
20
|
+
|
|
21
|
+
const testResultSchemaFilePath = path.join(tmpPath,testFileName);
|
|
22
|
+
const expectedSchemaFilePath = path.join(refsPath,referenceFileName);
|
|
23
|
+
|
|
24
|
+
const result = jzodToTsCode(testJzodSchema,exportPrefix,typeName)
|
|
25
|
+
fs.writeFileSync(testResultSchemaFilePath,result);
|
|
26
|
+
|
|
27
|
+
const resultContents = result.replace(/(\r\n|\n|\r)/gm, "");
|
|
28
|
+
// console.log("ts Type generation resultContents", resultContents);
|
|
29
|
+
|
|
30
|
+
const expectedFileContents = fs.readFileSync(expectedSchemaFilePath).toString().replace(/(\r\n|\n|\r)/gm, "")
|
|
31
|
+
expect(resultContents).toEqual(expectedFileContents);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
describe(
|
|
36
|
+
'Jzod-Ts',
|
|
37
|
+
() => {
|
|
38
|
+
// ############################################################################################
|
|
39
|
+
it(
|
|
40
|
+
"Jzod to TS Type",
|
|
41
|
+
async() => {
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// ########################################################################################
|
|
45
|
+
const testJzodSchema1: any /**JzodElement*/ = { type: "simpleType", definition: "string" };
|
|
46
|
+
|
|
47
|
+
testJzodToTs(
|
|
48
|
+
"tsTypeGeneration-testJzodSchema1 - reference.ts",
|
|
49
|
+
"tsTypeGeneration-testJzodSchema1.ts",
|
|
50
|
+
testJzodSchema1,
|
|
51
|
+
true,
|
|
52
|
+
"testJzodSchema1"
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// ########################################################################################
|
|
56
|
+
const testJzodSchema2: any /**JzodElement*/ = {
|
|
57
|
+
type: "schemaReference",
|
|
58
|
+
context: {
|
|
59
|
+
a: { type: "simpleType", definition: "string" },
|
|
60
|
+
b: {
|
|
61
|
+
type: "object",
|
|
62
|
+
definition: {
|
|
63
|
+
test: { type: "schemaReference", definition: { relativePath: "a" } }
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
definition: { relativePath: "b" },
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
testJzodToTs(
|
|
71
|
+
"tsTypeGeneration-testJzodSchema2 - reference.ts",
|
|
72
|
+
"tsTypeGeneration-testJzodSchema2.ts",
|
|
73
|
+
testJzodSchema2,
|
|
74
|
+
true,
|
|
75
|
+
"testJzodSchema2"
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// ########################################################################################
|
|
79
|
+
const testJzodSchema4: any /**JzodElement*/ =
|
|
80
|
+
{
|
|
81
|
+
type: "schemaReference",
|
|
82
|
+
context: {
|
|
83
|
+
...jzodBootstrapElementSchema.context,
|
|
84
|
+
a: {
|
|
85
|
+
type: "array",
|
|
86
|
+
definition: { type: "schemaReference", definition: {relativePath: "jzodArray"} }
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
definition: {
|
|
90
|
+
relativePath: "a"
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
testJzodToTs(
|
|
95
|
+
"tsTypeGeneration-testJzodSchema4 - reference.ts",
|
|
96
|
+
"tsTypeGeneration-testJzodSchema4.ts",
|
|
97
|
+
testJzodSchema4,
|
|
98
|
+
true,
|
|
99
|
+
"testJzodSchema4"
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
-
|
|
3
|
-
export type TestJzodSchema1 = string;
|
|
4
|
-
|
|
5
|
-
export const testJzodSchema1
|
|
1
|
+
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
+
|
|
3
|
+
export type TestJzodSchema1 = string;
|
|
4
|
+
|
|
5
|
+
export const testJzodSchema1 = z.string();
|