@miroir-framework/jzod-ts 0.5.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/README.md +3 -0
- package/babel.config.cjs +13 -0
- package/dist/bundle.d.ts +419 -0
- package/dist/bundle.js +303 -0
- package/dist/src/JzodToTs.d.ts +17 -0
- package/dist/src/JzodTsInterface.d.ts +397 -0
- package/dist/src/facade.d.ts +8 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/tools.d.ts +4 -0
- package/jest.config.js +63 -0
- package/package.json +38 -0
- package/rollup.config.js +36 -0
- package/src/JzodToTs.ts +104 -0
- package/src/JzodTsInterface.ts +450 -0
- package/src/index.ts +60 -0
- package/src/tools.ts +25 -0
- package/tests/jzod-ts.test.ts +108 -0
- package/tests/resources/tsTypeGeneration-testJzodSchema1 - reference.ts +5 -0
- package/tests/resources/tsTypeGeneration-testJzodSchema2 - reference.ts +11 -0
- package/tests/resources/tsTypeGeneration-testJzodSchema3 - reference.ts +19 -0
- package/tests/resources/tsTypeGeneration-testJzodSchema4 - reference.ts +250 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { ZodType, ZodTypeAny, z } from "zod";
|
|
2
|
+
|
|
3
|
+
export type jzodBaseObjectSchema = {
|
|
4
|
+
optional?: boolean | undefined;
|
|
5
|
+
nullable?: boolean | undefined;
|
|
6
|
+
extra?: {
|
|
7
|
+
[x: string]: any;
|
|
8
|
+
} | undefined;
|
|
9
|
+
};
|
|
10
|
+
export type jzodArraySchema = {
|
|
11
|
+
optional?: boolean | undefined;
|
|
12
|
+
nullable?: boolean | undefined;
|
|
13
|
+
extra?: {
|
|
14
|
+
[x: string]: any;
|
|
15
|
+
} | undefined;
|
|
16
|
+
type: "array";
|
|
17
|
+
definition?: jzodElementSchema;
|
|
18
|
+
};
|
|
19
|
+
export type jzodAttributeSchema = {
|
|
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?: jzodEnumAttributeTypesSchema;
|
|
28
|
+
};
|
|
29
|
+
export type jzodAttributeDateValidationsSchema = {
|
|
30
|
+
extra?: {
|
|
31
|
+
[x: string]: any;
|
|
32
|
+
} | undefined;
|
|
33
|
+
type: "min" | "max";
|
|
34
|
+
parameter?: any;
|
|
35
|
+
};
|
|
36
|
+
export type jzodAttributeDateWithValidationsSchema = {
|
|
37
|
+
optional?: boolean | undefined;
|
|
38
|
+
nullable?: boolean | undefined;
|
|
39
|
+
extra?: {
|
|
40
|
+
[x: string]: any;
|
|
41
|
+
} | undefined;
|
|
42
|
+
type: "simpleType";
|
|
43
|
+
definition: "date";
|
|
44
|
+
validations: jzodAttributeDateValidationsSchema[];
|
|
45
|
+
};
|
|
46
|
+
export type jzodAttributeNumberValidationsSchema = {
|
|
47
|
+
extra?: {
|
|
48
|
+
[x: string]: any;
|
|
49
|
+
} | undefined;
|
|
50
|
+
type: "gt" | "gte" | "lt" | "lte" | "int" | "positive" | "nonpositive" | "negative" | "nonnegative" | "multipleOf" | "finite" | "safe";
|
|
51
|
+
parameter?: any;
|
|
52
|
+
};
|
|
53
|
+
export type jzodAttributeNumberWithValidationsSchema = {
|
|
54
|
+
optional?: boolean | undefined;
|
|
55
|
+
nullable?: boolean | undefined;
|
|
56
|
+
extra?: {
|
|
57
|
+
[x: string]: any;
|
|
58
|
+
} | undefined;
|
|
59
|
+
type: "simpleType";
|
|
60
|
+
definition: "number";
|
|
61
|
+
validations: jzodAttributeNumberValidationsSchema[];
|
|
62
|
+
};
|
|
63
|
+
export type jzodAttributeStringValidationsSchema = {
|
|
64
|
+
extra?: {
|
|
65
|
+
[x: string]: any;
|
|
66
|
+
} | undefined;
|
|
67
|
+
type: "max" | "min" | "length" | "email" | "url" | "emoji" | "uuid" | "cuid" | "cuid2" | "ulid" | "regex" | "includes" | "startsWith" | "endsWith" | "datetime" | "ip";
|
|
68
|
+
parameter?: any;
|
|
69
|
+
};
|
|
70
|
+
export type jzodAttributeStringWithValidationsSchema = {
|
|
71
|
+
optional?: boolean | undefined;
|
|
72
|
+
nullable?: boolean | undefined;
|
|
73
|
+
extra?: {
|
|
74
|
+
[x: string]: any;
|
|
75
|
+
} | undefined;
|
|
76
|
+
type: "simpleType";
|
|
77
|
+
definition: "string";
|
|
78
|
+
validations: jzodAttributeStringValidationsSchema[];
|
|
79
|
+
};
|
|
80
|
+
export type jzodElementSchema = jzodArraySchema | jzodAttributeSchema | jzodAttributeDateWithValidationsSchema | jzodAttributeNumberWithValidationsSchema | jzodAttributeStringWithValidationsSchema | jzodEnumSchema | jzodFunctionSchema | jzodLazySchema | jzodLiteralSchema | jzodIntersectionSchema | jzodMapSchema | jzodObjectSchema | jzodPromiseSchema | jzodRecordSchema | jzodReferenceSchema | jzodSetSchema | jzodTupleSchema | jzodUnionSchema;
|
|
81
|
+
export type jzodEnumSchema = {
|
|
82
|
+
optional?: boolean | undefined;
|
|
83
|
+
nullable?: boolean | undefined;
|
|
84
|
+
extra?: {
|
|
85
|
+
[x: string]: any;
|
|
86
|
+
} | undefined;
|
|
87
|
+
type: "enum";
|
|
88
|
+
definition: string[];
|
|
89
|
+
};
|
|
90
|
+
export type jzodEnumAttributeTypesSchema = "any" | "bigint" | "boolean" | "date" | "never" | "null" | "number" | "string" | "uuid" | "undefined" | "unknown" | "void";
|
|
91
|
+
export type jzodEnumElementTypesSchema = "array" | "enum" | "function" | "lazy" | "literal" | "intersection" | "map" | "object" | "promise" | "record" | "schemaReference" | "set" | "simpleType" | "tuple" | "union";
|
|
92
|
+
export type jzodFunctionSchema = {
|
|
93
|
+
optional?: boolean | undefined;
|
|
94
|
+
nullable?: boolean | undefined;
|
|
95
|
+
extra?: {
|
|
96
|
+
[x: string]: any;
|
|
97
|
+
} | undefined;
|
|
98
|
+
type: "function";
|
|
99
|
+
definition: {
|
|
100
|
+
args: jzodElementSchema[];
|
|
101
|
+
returns?: jzodElementSchema;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
export type jzodLazySchema = {
|
|
105
|
+
optional?: boolean | undefined;
|
|
106
|
+
nullable?: boolean | undefined;
|
|
107
|
+
extra?: {
|
|
108
|
+
[x: string]: any;
|
|
109
|
+
} | undefined;
|
|
110
|
+
type: "lazy";
|
|
111
|
+
definition?: jzodFunctionSchema;
|
|
112
|
+
};
|
|
113
|
+
export type jzodLiteralSchema = {
|
|
114
|
+
optional?: boolean | undefined;
|
|
115
|
+
nullable?: boolean | undefined;
|
|
116
|
+
extra?: {
|
|
117
|
+
[x: string]: any;
|
|
118
|
+
} | undefined;
|
|
119
|
+
type: "literal";
|
|
120
|
+
definition: string;
|
|
121
|
+
};
|
|
122
|
+
export type jzodIntersectionSchema = {
|
|
123
|
+
optional?: boolean | undefined;
|
|
124
|
+
nullable?: boolean | undefined;
|
|
125
|
+
extra?: {
|
|
126
|
+
[x: string]: any;
|
|
127
|
+
} | undefined;
|
|
128
|
+
type: "intersection";
|
|
129
|
+
definition: {
|
|
130
|
+
left?: jzodElementSchema;
|
|
131
|
+
right?: jzodElementSchema;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export type jzodMapSchema = {
|
|
135
|
+
optional?: boolean | undefined;
|
|
136
|
+
nullable?: boolean | undefined;
|
|
137
|
+
extra?: {
|
|
138
|
+
[x: string]: any;
|
|
139
|
+
} | undefined;
|
|
140
|
+
type: "map";
|
|
141
|
+
definition: [
|
|
142
|
+
jzodElementSchema,
|
|
143
|
+
jzodElementSchema
|
|
144
|
+
];
|
|
145
|
+
};
|
|
146
|
+
export type jzodObjectSchema = {
|
|
147
|
+
optional?: boolean | undefined;
|
|
148
|
+
nullable?: boolean | undefined;
|
|
149
|
+
extra?: {
|
|
150
|
+
[x: string]: any;
|
|
151
|
+
} | undefined;
|
|
152
|
+
extend?: (jzodReferenceSchema | jzodObjectSchema) | undefined;
|
|
153
|
+
type: "object";
|
|
154
|
+
nonStrict?: boolean | undefined;
|
|
155
|
+
definition: {
|
|
156
|
+
[x: string]: jzodElementSchema;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
export type jzodPromiseSchema = {
|
|
160
|
+
optional?: boolean | undefined;
|
|
161
|
+
nullable?: boolean | undefined;
|
|
162
|
+
extra?: {
|
|
163
|
+
[x: string]: any;
|
|
164
|
+
} | undefined;
|
|
165
|
+
type: "promise";
|
|
166
|
+
definition?: jzodElementSchema;
|
|
167
|
+
};
|
|
168
|
+
export type jzodRecordSchema = {
|
|
169
|
+
optional?: boolean | undefined;
|
|
170
|
+
nullable?: boolean | undefined;
|
|
171
|
+
extra?: {
|
|
172
|
+
[x: string]: any;
|
|
173
|
+
} | undefined;
|
|
174
|
+
type: "record";
|
|
175
|
+
definition?: jzodElementSchema;
|
|
176
|
+
};
|
|
177
|
+
export type jzodReferenceSchema = {
|
|
178
|
+
optional?: boolean | undefined;
|
|
179
|
+
nullable?: boolean | undefined;
|
|
180
|
+
extra?: {
|
|
181
|
+
[x: string]: any;
|
|
182
|
+
} | undefined;
|
|
183
|
+
type: "schemaReference";
|
|
184
|
+
context?: {
|
|
185
|
+
[x: string]: jzodElementSchema;
|
|
186
|
+
} | undefined;
|
|
187
|
+
definition: {
|
|
188
|
+
eager?: boolean | undefined;
|
|
189
|
+
relativePath?: string | undefined;
|
|
190
|
+
absolutePath?: string | undefined;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
export type jzodSetSchema = {
|
|
194
|
+
optional?: boolean | undefined;
|
|
195
|
+
nullable?: boolean | undefined;
|
|
196
|
+
extra?: {
|
|
197
|
+
[x: string]: any;
|
|
198
|
+
} | undefined;
|
|
199
|
+
type: "set";
|
|
200
|
+
definition?: jzodElementSchema;
|
|
201
|
+
};
|
|
202
|
+
export type jzodTupleSchema = {
|
|
203
|
+
optional?: boolean | undefined;
|
|
204
|
+
nullable?: boolean | undefined;
|
|
205
|
+
extra?: {
|
|
206
|
+
[x: string]: any;
|
|
207
|
+
} | undefined;
|
|
208
|
+
type: "tuple";
|
|
209
|
+
definition: jzodElementSchema[];
|
|
210
|
+
};
|
|
211
|
+
export type jzodUnionSchema = {
|
|
212
|
+
optional?: boolean | undefined;
|
|
213
|
+
nullable?: boolean | undefined;
|
|
214
|
+
extra?: {
|
|
215
|
+
[x: string]: any;
|
|
216
|
+
} | undefined;
|
|
217
|
+
type: "union";
|
|
218
|
+
discriminator?: string | undefined;
|
|
219
|
+
definition: jzodElementSchema[];
|
|
220
|
+
};
|
|
221
|
+
export type a = jzodArraySchema[];
|
|
222
|
+
export type testJzodSchema4 = a;
|
|
223
|
+
|
|
224
|
+
export const jzodBaseObjectSchema=z.object({optional:z.boolean().optional(),nullable:z.boolean().optional(),extra:z.record(z.string(),z.any()).optional(),}).strict();
|
|
225
|
+
export const jzodArraySchema=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(() =>jzodElementSchema),}).strict();
|
|
226
|
+
export const jzodAttributeSchema=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(() =>jzodEnumAttributeTypesSchema),}).strict();
|
|
227
|
+
export const jzodAttributeDateValidationsSchema=z.object({extra:z.record(z.string(),z.any()).optional(),type:z.enum(["min","max"] as any),parameter:z.any(),}).strict();
|
|
228
|
+
export const jzodAttributeDateWithValidationsSchema=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(() =>jzodAttributeDateValidationsSchema)),}).strict();
|
|
229
|
+
export const jzodAttributeNumberValidationsSchema=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"] as any),parameter:z.any(),}).strict();
|
|
230
|
+
export const jzodAttributeNumberWithValidationsSchema=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(() =>jzodAttributeNumberValidationsSchema)),}).strict();
|
|
231
|
+
export const jzodAttributeStringValidationsSchema=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"] as any),parameter:z.any(),}).strict();
|
|
232
|
+
export const jzodAttributeStringWithValidationsSchema=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(() =>jzodAttributeStringValidationsSchema)),}).strict();
|
|
233
|
+
export const jzodElementSchema=z.union([z.lazy(() =>jzodArraySchema),z.lazy(() =>jzodAttributeSchema),z.lazy(() =>jzodAttributeDateWithValidationsSchema),z.lazy(() =>jzodAttributeNumberWithValidationsSchema),z.lazy(() =>jzodAttributeStringWithValidationsSchema),z.lazy(() =>jzodEnumSchema),z.lazy(() =>jzodFunctionSchema),z.lazy(() =>jzodLazySchema),z.lazy(() =>jzodLiteralSchema),z.lazy(() =>jzodIntersectionSchema),z.lazy(() =>jzodMapSchema),z.lazy(() =>jzodObjectSchema),z.lazy(() =>jzodPromiseSchema),z.lazy(() =>jzodRecordSchema),z.lazy(() =>jzodReferenceSchema),z.lazy(() =>jzodSetSchema),z.lazy(() =>jzodTupleSchema),z.lazy(() =>jzodUnionSchema),]);
|
|
234
|
+
export const jzodEnumSchema=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();
|
|
235
|
+
export const jzodEnumAttributeTypesSchema=z.enum(["any","bigint","boolean","date","never","null","number","string","uuid","undefined","unknown","void"] as any);
|
|
236
|
+
export const jzodEnumElementTypesSchema=z.enum(["array","enum","function","lazy","literal","intersection","map","object","promise","record","schemaReference","set","simpleType","tuple","union"] as any);
|
|
237
|
+
export const jzodFunctionSchema=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(() =>jzodElementSchema)),returns:z.lazy(() =>jzodElementSchema).optional(),}).strict(),}).strict();
|
|
238
|
+
export const jzodLazySchema=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(() =>jzodFunctionSchema),}).strict();
|
|
239
|
+
export const jzodLiteralSchema=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();
|
|
240
|
+
export const jzodIntersectionSchema=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(() =>jzodElementSchema),right:z.lazy(() =>jzodElementSchema),}).strict(),}).strict();
|
|
241
|
+
export const jzodMapSchema=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(() =>jzodElementSchema)","z.lazy(() =>jzodElementSchema)"] as any),}).strict();
|
|
242
|
+
export const jzodObjectSchema=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(() =>jzodReferenceSchema),z.lazy(() =>jzodObjectSchema),]).optional(),type:z.literal("object"),nonStrict:z.boolean().optional(),definition:z.record(z.string(),z.lazy(() =>jzodElementSchema)),}).strict();
|
|
243
|
+
export const jzodPromiseSchema=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(() =>jzodElementSchema),}).strict();
|
|
244
|
+
export const jzodRecordSchema=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(() =>jzodElementSchema),}).strict();
|
|
245
|
+
export const jzodReferenceSchema=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(() =>jzodElementSchema)).optional(),definition:z.object({eager:z.boolean().optional(),relativePath:z.string().optional(),absolutePath:z.string().optional(),}).strict(),}).strict();
|
|
246
|
+
export const jzodSetSchema=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(() =>jzodElementSchema),}).strict();
|
|
247
|
+
export const jzodTupleSchema=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(() =>jzodElementSchema)),}).strict();
|
|
248
|
+
export const jzodUnionSchema=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(() =>jzodElementSchema)),}).strict();
|
|
249
|
+
export const a=z.array(z.lazy(() =>jzodArraySchema));
|
|
250
|
+
export const testJzodSchema4 = z.lazy(() =>a);
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "dist/out-tsc",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"declarationDir": "dist/out-tsc/dts",
|
|
6
|
+
"rootDir": "./",
|
|
7
|
+
"baseUrl": "./",
|
|
8
|
+
"types": ["node", "jest"],
|
|
9
|
+
"removeComments": true,
|
|
10
|
+
"module": "ESNext",
|
|
11
|
+
"target": "ES2017",
|
|
12
|
+
"jsx": "react-jsx",
|
|
13
|
+
"moduleResolution": "Node",
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"allowSyntheticDefaultImports":true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"lib": ["es6", "dom"],
|
|
18
|
+
"noImplicitAny": true,
|
|
19
|
+
"noImplicitThis": true,
|
|
20
|
+
"strictNullChecks": true,
|
|
21
|
+
"plugins": [
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
"exclude": ["./node_modules/**","./src/**/*.spec.js", "./src/**/*.spec.jsx", "./src/**/*.spec.ts", "./src/**/*.spec.tsx"],
|
|
25
|
+
"include": ["./src/**/*.json", "./src/**/*.js", "./src/**/*.jsx", "./src/**/*.ts", "./src/**/*.tsx"]
|
|
26
|
+
}
|