@miroir-framework/jzod-ts 0.5.0 → 0.5.2

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.
@@ -1,450 +1,450 @@
1
- import { ZodType, z } from "zod";
2
-
3
- const jzodRootSchema = z.object({
4
- optional: z.boolean().optional(),
5
- }).strict();
6
- type JzodRoot = z.infer<typeof jzodRootSchema>;
7
-
8
- // ##############################################################################################################
9
- export const jzodEnumAttributeTypesSchema = z.enum([
10
- "any",
11
- "bigint",
12
- "boolean",
13
- "date",
14
- "never",
15
- "null",
16
- "number",
17
- "string",
18
- "uuid",
19
- "undefined",
20
- "unknown",
21
- "void",
22
- ])
23
-
24
- export type JzodEnumTypes = z.infer<typeof jzodEnumAttributeTypesSchema>;
25
-
26
- // ##############################################################################################################
27
- export const jzodEnumElementTypesSchema = z.enum([
28
- "array",
29
- "enum",
30
- "function",
31
- "lazy",
32
- "literal",
33
- "intersection",
34
- "map",
35
- "object",
36
- "promise",
37
- "record",
38
- "schemaReference",
39
- "set",
40
- "simpleType",
41
- "tuple",
42
- "union",
43
- ])
44
-
45
- export type JzodEnumElementTypes = z.infer<typeof jzodEnumElementTypesSchema>;
46
-
47
-
48
- // ##############################################################################################################
49
- export interface JzodArray extends JzodRoot {
50
- optional?: boolean,
51
- nullable?: boolean,
52
- extra?: {[k:string]:any},
53
- type: 'array',
54
- definition: JzodElement
55
- }
56
-
57
- export const jzodArraySchema: z.ZodType<JzodArray> = z.object({ // issue with JsonSchema conversion when using extend from ZodRootSchema, although the 2 are functionnaly equivalent
58
- optional: z.boolean().optional(),
59
- nullable: z.boolean().optional(),
60
- extra: z.record(z.string(),z.any()).optional(),
61
- type: z.literal('array'),
62
- definition: z.lazy(()=>jzodElementSchema)
63
- }).strict();
64
-
65
- // ##############################################################################################################
66
- export const jzodAttributeDateValidationsSchema = z
67
- .object({
68
- extra: z.record(z.string(), z.any()).optional(),
69
- type: z.enum([
70
- "min",
71
- "max",
72
- ]),
73
- parameter: z.any(),
74
- })
75
- .strict();
76
-
77
- export type JzodAttributeDateValidations = z.infer<typeof jzodAttributeDateValidationsSchema>;
78
-
79
- // ##############################################################################################################
80
- export const jzodAttributeNumberValidationsSchema = z
81
- .object({
82
- extra: z.record(z.string(), z.any()).optional(),
83
- type: z.enum([
84
- "gt",
85
- "gte",
86
- "lt",
87
- "lte",
88
- "int",
89
- "positive",
90
- "nonpositive",
91
- "negative",
92
- "nonnegative",
93
- "multipleOf",
94
- "finite",
95
- "safe",
96
- ]),
97
- parameter: z.any(),
98
- })
99
- .strict();
100
-
101
- export type JzodAttributeNumberValidations = z.infer<typeof jzodAttributeNumberValidationsSchema>;
102
-
103
- // ##############################################################################################################
104
- export const jzodAttributeStringValidationsSchema = z
105
- .object({
106
- extra: z.record(z.string(), z.any()).optional(),
107
- type: z.enum([
108
- "max",
109
- "min",
110
- "length",
111
- "email",
112
- "url",
113
- "emoji",
114
- "uuid",
115
- "cuid",
116
- "cuid2",
117
- "ulid",
118
- "regex",
119
- "includes",
120
- "startsWith",
121
- "endsWith",
122
- "datetime",
123
- "ip",
124
- ]),
125
- parameter: z.any(),
126
- })
127
- .strict();
128
-
129
- export type JzodAttributeStringValidations = z.infer<typeof jzodAttributeStringValidationsSchema>;
130
-
131
- // ##############################################################################################################
132
- export const jzodAttributeDateWithValidationsSchema = z.object({
133
- optional: z.boolean().optional(),
134
- nullable: z.boolean().optional(),
135
- extra: z.record(z.string(),z.any()).optional(),
136
- coerce: z.boolean().optional(),
137
- type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
138
- definition: z.literal(jzodEnumAttributeTypesSchema.enum.date),
139
- validations: z.array(jzodAttributeDateValidationsSchema),
140
- }).strict();
141
-
142
- export type JzodAttributeDateWithValidations = z.infer<typeof jzodAttributeDateWithValidationsSchema>;
143
-
144
- // ##############################################################################################################
145
- export const jzodAttributeNumberWithValidationsSchema = z.object({
146
- optional: z.boolean().optional(),
147
- nullable: z.boolean().optional(),
148
- extra: z.record(z.string(),z.any()).optional(),
149
- coerce: z.boolean().optional(),
150
- type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
151
- definition: z.literal(jzodEnumAttributeTypesSchema.enum.number),
152
- validations: z.array(jzodAttributeNumberValidationsSchema),
153
- }).strict();
154
-
155
- export type JzodAttributeNumberWithValidations = z.infer<typeof jzodAttributeNumberWithValidationsSchema>;
156
-
157
- // ##############################################################################################################
158
- export const jzodAttributeStringWithValidationsSchema = z.object({
159
- optional: z.boolean().optional(),
160
- nullable: z.boolean().optional(),
161
- extra: z.record(z.string(),z.any()).optional(),
162
- coerce: z.boolean().optional(),
163
- type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
164
- definition: z.literal(jzodEnumAttributeTypesSchema.enum.string),
165
- validations: z.array(jzodAttributeStringValidationsSchema),
166
- }).strict();
167
-
168
- export type JzodAttributeStringWithValidations = z.infer<typeof jzodAttributeStringWithValidationsSchema>;
169
-
170
- // ##############################################################################################################
171
- export const jzodAttributeSchema = z.object({
172
- optional: z.boolean().optional(),
173
- nullable: z.boolean().optional(),
174
- extra: z.record(z.string(),z.any()).optional(),
175
- coerce: z.boolean().optional(),
176
- type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
177
- definition: z.lazy(()=>jzodEnumAttributeTypesSchema),
178
- }).strict();
179
-
180
- export type JzodAttribute = z.infer<typeof jzodAttributeSchema>;
181
-
182
-
183
- // ##############################################################################################################
184
- export type JzodElement =
185
- | JzodArray
186
- | JzodAttribute
187
- | JzodAttributeDateWithValidations
188
- | JzodAttributeNumberWithValidations
189
- | JzodAttributeStringWithValidations
190
- | JzodEnum
191
- | JzodFunction
192
- | JzodLazy
193
- | JzodLiteral
194
- | JzodIntersection
195
- | JzodMap
196
- | JzodRecord
197
- | JzodObject
198
- | JzodPromise
199
- | JzodReference
200
- | JzodSet
201
- | JzodTuple
202
- | JzodUnion
203
- ;
204
-
205
- export const jzodElementSchema: z.ZodType<JzodElement> = z.union([
206
- z.lazy(()=>jzodArraySchema),
207
- z.lazy(()=>jzodAttributeSchema),
208
- z.lazy(()=>jzodAttributeDateWithValidationsSchema),
209
- z.lazy(()=>jzodAttributeNumberWithValidationsSchema),
210
- z.lazy(()=>jzodAttributeStringWithValidationsSchema),
211
- z.lazy(()=>jzodEnumSchema),
212
- z.lazy(()=>jzodFunctionSchema),
213
- z.lazy(()=>jzodLazySchema),
214
- z.lazy(()=>jzodLiteralSchema),
215
- z.lazy(()=>jzodIntersectionSchema),
216
- z.lazy(()=>jzodMapSchema),
217
- z.lazy(()=>jzodObjectSchema),
218
- z.lazy(()=>jzodPromiseSchema),
219
- z.lazy(()=>jzodRecordSchema),
220
- z.lazy(()=>jzodReferenceSchema),
221
- z.lazy(()=>jzodSetSchema),
222
- z.lazy(()=>jzodTupleSchema),
223
- z.lazy(()=>jzodUnionSchema),
224
- ])
225
-
226
- // // ##############################################################################################################
227
- // export const jzodElementSetSchema = z.record(z.string(),jzodElementSchema);
228
- // export type JzodElementSet = z.infer<typeof jzodElementSetSchema>;
229
-
230
- // ##############################################################################################################
231
- export const jzodEnumSchema = z.object({
232
- optional: z.boolean().optional(),
233
- nullable: z.boolean().optional(),
234
- extra: z.record(z.string(),z.any()).optional(),
235
- type: z.literal(jzodEnumElementTypesSchema.enum.enum),
236
- definition: z.array(z.string()),
237
- }).strict();
238
-
239
- export type JzodEnum = z.infer<typeof jzodEnumSchema>;
240
-
241
- // ##############################################################################################################
242
- export interface JzodFunction {
243
- // optional?: boolean,
244
- // nullable?: boolean,
245
- extra?: {[k:string]:any},
246
- type: 'function',
247
- definition: {args: JzodElement[], returns?: JzodElement},
248
- }
249
- export const jzodFunctionSchema: ZodType<JzodFunction> = z.object({
250
- type: z.literal(jzodEnumElementTypesSchema.enum.function),
251
- extra: z.record(z.string(),z.any()).optional(),
252
- // anyway, arg and returns types are not use upon validation to check the function's interface. Suffices for it to be a function, it is then valid.
253
- definition: z.object({
254
- args:z.array(jzodElementSchema),
255
- returns: jzodElementSchema.optional(),
256
- })
257
- }).strict();
258
-
259
- // ##############################################################################################################
260
- export const jzodLazySchema = z.object({
261
- type: z.literal(jzodEnumElementTypesSchema.enum.lazy),
262
- extra: z.record(z.string(),z.any()).optional(),
263
- definition: jzodFunctionSchema,
264
- }).strict();
265
-
266
- export type JzodLazy = z.infer<typeof jzodLazySchema>;
267
-
268
- // ##############################################################################################################
269
- export const jzodLiteralSchema = z.object({
270
- optional: z.boolean().optional(),
271
- nullable: z.boolean().optional(),
272
- extra: z.record(z.string(),z.any()).optional(),
273
- type: z.literal(jzodEnumElementTypesSchema.enum.literal),
274
- definition: z.string(),
275
- }).strict();
276
-
277
- export type JzodLiteral = z.infer<typeof jzodLiteralSchema>;
278
-
279
- // ##############################################################################################################
280
- export interface JzodIntersection {
281
- optional?: boolean,
282
- nullable?: boolean,
283
- extra?: {[k:string]:any},
284
- type: 'intersection',
285
- definition: {left: JzodElement, right: JzodElement},
286
- }
287
-
288
- export const jzodIntersectionSchema: z.ZodType<JzodIntersection> = z.object({
289
- optional: z.boolean().optional(),
290
- nullable: z.boolean().optional(),
291
- extra: z.record(z.string(),z.any()).optional(),
292
- type: z.literal(jzodEnumElementTypesSchema.enum.intersection),
293
- definition: z.lazy(()=>z.object({left: jzodElementSchema, right: jzodElementSchema}))
294
- }).strict();
295
-
296
- // ##############################################################################################################
297
- export interface JzodMap extends JzodRoot {
298
- optional?: boolean,
299
- nullable?: boolean,
300
- extra?: {[k:string]:any},
301
- type: 'map',
302
- definition: [JzodElement,JzodElement]
303
- }
304
-
305
- export const jzodMapSchema: z.ZodType<JzodMap> = z.object({ // issue with JsonSchema conversion when using extend from ZodRootSchema, although the 2 are functionnaly equivalent
306
- optional: z.boolean().optional(),
307
- nullable: z.boolean().optional(),
308
- extra: z.record(z.string(),z.any()).optional(),
309
- type: z.literal('map'),
310
- definition: z.lazy(()=>z.tuple([jzodElementSchema, jzodElementSchema]))
311
- }).strict();
312
-
313
- // ##############################################################################################################
314
- export interface JzodObject extends JzodRoot {
315
- optional?: boolean,
316
- nullable?: boolean,
317
- extend?: JzodReference | JzodObject,
318
- extra?: {[k:string]:any},
319
- type: "object",
320
- nonStrict?: boolean,
321
- // context?: {[attributeName:string]: JzodElement},
322
- definition: {[attributeName:string]: JzodElement}
323
- }
324
-
325
- export const jzodObjectSchema: z.ZodType<JzodObject> = z.object({
326
- optional: z.boolean().optional(),
327
- nullable: z.boolean().optional(),
328
- extend: z.lazy(()=>z.union([jzodReferenceSchema,jzodObjectSchema])).optional(),
329
- extra: z.record(z.string(),z.any()).optional(),
330
- type: z.literal(jzodEnumElementTypesSchema.enum.object),
331
- nonStrict: z.boolean().optional(),
332
- definition: z.lazy(()=>z.record(z.string(),jzodElementSchema)),
333
- }).strict();
334
-
335
- // ##############################################################################################################
336
- export interface JzodPromise extends JzodRoot {
337
- // optional?: boolean,
338
- // nullable?: boolean,
339
- extra?: {[k:string]:any},
340
- type: 'promise',
341
- definition: JzodElement
342
- }
343
-
344
- export const jzodPromiseSchema: z.ZodType<JzodPromise> = z.object({ // issue with JsonSchema conversion when using extend from ZodRootSchema, although the 2 are functionnaly equivalent
345
- // optional: z.boolean().optional(),
346
- // nullable: z.boolean().optional(),
347
- extra: z.record(z.string(),z.any()).optional(),
348
- type: z.literal('promise'),
349
- definition: z.lazy(()=>jzodElementSchema)
350
- }).strict();
351
-
352
-
353
- // ##############################################################################################################
354
- export interface JzodRecord {
355
- optional?: boolean,
356
- nullable?: boolean,
357
- extra?: {[k:string]:any},
358
- type: 'record',
359
- definition: JzodElement,
360
- }
361
-
362
- export const jzodRecordSchema: z.ZodType<JzodRecord> = z.object({
363
- optional: z.boolean().optional(),
364
- nullable: z.boolean().optional(),
365
- extra: z.record(z.string(),z.any()).optional(),
366
- type: z.literal(jzodEnumElementTypesSchema.enum.record),
367
- definition: z.lazy(()=>jzodElementSchema)
368
- }).strict();
369
-
370
- // ##############################################################################################################
371
- export interface JzodReference {
372
- optional?: boolean,
373
- nullable?: boolean,
374
- extra?: {[k:string]:any},
375
- context?: {[attributeName:string]: JzodElement},
376
- type: 'schemaReference',
377
- definition: {
378
- eager?: boolean,
379
- relativePath?: string,
380
- absolutePath?: string,
381
- },
382
- }
383
-
384
- export const jzodReferenceSchema: ZodType<JzodReference> = z.object({ // inheritance from ZodRootSchema leads to a different JsonSchema thus invalidates tests, although it is semantically equivalent
385
- optional: z.boolean().optional(),
386
- nullable: z.boolean().optional(),
387
- extra: z.record(z.string(),z.any()).optional(),
388
- type: z.literal(jzodEnumElementTypesSchema.enum.schemaReference),
389
- context: z.lazy(()=>z.record(z.string(),jzodElementSchema)).optional(),
390
- definition: z.object({
391
- eager: z.boolean().optional(),
392
- relativePath: z.string().optional(),
393
- absolutePath: z.string().optional(),
394
- })
395
- }).strict()
396
-
397
- // export type JzodReference = z.infer<typeof jzodReferenceSchema>;
398
-
399
- // ##############################################################################################################
400
- export interface JzodSet extends JzodRoot {
401
- optional?: boolean,
402
- nullable?: boolean,
403
- extra?: {[k:string]:any},
404
- type: 'set',
405
- definition: JzodElement
406
- }
407
-
408
- export const jzodSetSchema: z.ZodType<JzodSet> = z.object({ // issue with JsonSchema conversion when using extend from ZodRootSchema, although the 2 are functionnaly equivalent
409
- optional: z.boolean().optional(),
410
- nullable: z.boolean().optional(),
411
- extra: z.record(z.string(),z.any()).optional(),
412
- type: z.literal('set'),
413
- definition: z.lazy(()=>jzodElementSchema)
414
- }).strict();
415
-
416
- // ##############################################################################################################
417
- export interface JzodTuple {
418
- optional?: boolean,
419
- nullable?: boolean,
420
- extra?: {[k:string]:any},
421
- type: 'tuple',
422
- definition: JzodElement[],
423
- }
424
-
425
- export const jzodTupleSchema: z.ZodType<JzodTuple> = z.object({
426
- optional: z.boolean().optional(),
427
- nullable: z.boolean().optional(),
428
- extra: z.record(z.string(),z.any()).optional(),
429
- type: z.literal(jzodEnumElementTypesSchema.enum.tuple),
430
- definition: z.array(jzodElementSchema),
431
- }).strict();
432
-
433
- // ##############################################################################################################
434
- export interface JzodUnion {
435
- optional?: boolean,
436
- nullable?: boolean,
437
- extra?: {[k:string]:any},
438
- type: "union",
439
- discriminator?: string,
440
- definition: JzodElement[],
441
- }
442
- export const jzodUnionSchema: z.ZodType<JzodUnion> = z.object({
443
- optional: z.boolean().optional(),
444
- nullable: z.boolean().optional(),
445
- extra: z.record(z.string(),z.any()).optional(),
446
- type: z.literal(jzodEnumElementTypesSchema.enum.union),
447
- discriminator: z.string().optional(),
448
- definition: z.lazy(()=>z.array(jzodElementSchema))
449
- }).strict();
450
-
1
+ import { ZodType, z } from "zod";
2
+
3
+ const jzodRootSchema = z.object({
4
+ optional: z.boolean().optional(),
5
+ }).strict();
6
+ type JzodRoot = z.infer<typeof jzodRootSchema>;
7
+
8
+ // ##############################################################################################################
9
+ export const jzodEnumAttributeTypesSchema = z.enum([
10
+ "any",
11
+ "bigint",
12
+ "boolean",
13
+ "date",
14
+ "never",
15
+ "null",
16
+ "number",
17
+ "string",
18
+ "uuid",
19
+ "undefined",
20
+ "unknown",
21
+ "void",
22
+ ])
23
+
24
+ export type JzodEnumTypes = z.infer<typeof jzodEnumAttributeTypesSchema>;
25
+
26
+ // ##############################################################################################################
27
+ export const jzodEnumElementTypesSchema = z.enum([
28
+ "array",
29
+ "enum",
30
+ "function",
31
+ "lazy",
32
+ "literal",
33
+ "intersection",
34
+ "map",
35
+ "object",
36
+ "promise",
37
+ "record",
38
+ "schemaReference",
39
+ "set",
40
+ "simpleType",
41
+ "tuple",
42
+ "union",
43
+ ])
44
+
45
+ export type JzodEnumElementTypes = z.infer<typeof jzodEnumElementTypesSchema>;
46
+
47
+
48
+ // ##############################################################################################################
49
+ export interface JzodArray extends JzodRoot {
50
+ optional?: boolean,
51
+ nullable?: boolean,
52
+ extra?: {[k:string]:any},
53
+ type: 'array',
54
+ definition: JzodElement
55
+ }
56
+
57
+ export const jzodArraySchema: z.ZodType<JzodArray> = z.object({ // issue with JsonSchema conversion when using extend from ZodRootSchema, although the 2 are functionnaly equivalent
58
+ optional: z.boolean().optional(),
59
+ nullable: z.boolean().optional(),
60
+ extra: z.record(z.string(),z.any()).optional(),
61
+ type: z.literal('array'),
62
+ definition: z.lazy(()=>jzodElementSchema)
63
+ }).strict();
64
+
65
+ // ##############################################################################################################
66
+ export const jzodAttributeDateValidationsSchema = z
67
+ .object({
68
+ extra: z.record(z.string(), z.any()).optional(),
69
+ type: z.enum([
70
+ "min",
71
+ "max",
72
+ ]),
73
+ parameter: z.any(),
74
+ })
75
+ .strict();
76
+
77
+ export type JzodAttributeDateValidations = z.infer<typeof jzodAttributeDateValidationsSchema>;
78
+
79
+ // ##############################################################################################################
80
+ export const jzodAttributeNumberValidationsSchema = z
81
+ .object({
82
+ extra: z.record(z.string(), z.any()).optional(),
83
+ type: z.enum([
84
+ "gt",
85
+ "gte",
86
+ "lt",
87
+ "lte",
88
+ "int",
89
+ "positive",
90
+ "nonpositive",
91
+ "negative",
92
+ "nonnegative",
93
+ "multipleOf",
94
+ "finite",
95
+ "safe",
96
+ ]),
97
+ parameter: z.any(),
98
+ })
99
+ .strict();
100
+
101
+ export type JzodAttributeNumberValidations = z.infer<typeof jzodAttributeNumberValidationsSchema>;
102
+
103
+ // ##############################################################################################################
104
+ export const jzodAttributeStringValidationsSchema = z
105
+ .object({
106
+ extra: z.record(z.string(), z.any()).optional(),
107
+ type: z.enum([
108
+ "max",
109
+ "min",
110
+ "length",
111
+ "email",
112
+ "url",
113
+ "emoji",
114
+ "uuid",
115
+ "cuid",
116
+ "cuid2",
117
+ "ulid",
118
+ "regex",
119
+ "includes",
120
+ "startsWith",
121
+ "endsWith",
122
+ "datetime",
123
+ "ip",
124
+ ]),
125
+ parameter: z.any(),
126
+ })
127
+ .strict();
128
+
129
+ export type JzodAttributeStringValidations = z.infer<typeof jzodAttributeStringValidationsSchema>;
130
+
131
+ // ##############################################################################################################
132
+ export const jzodAttributeDateWithValidationsSchema = z.object({
133
+ optional: z.boolean().optional(),
134
+ nullable: z.boolean().optional(),
135
+ extra: z.record(z.string(),z.any()).optional(),
136
+ coerce: z.boolean().optional(),
137
+ type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
138
+ definition: z.literal(jzodEnumAttributeTypesSchema.enum.date),
139
+ validations: z.array(jzodAttributeDateValidationsSchema),
140
+ }).strict();
141
+
142
+ export type JzodAttributeDateWithValidations = z.infer<typeof jzodAttributeDateWithValidationsSchema>;
143
+
144
+ // ##############################################################################################################
145
+ export const jzodAttributeNumberWithValidationsSchema = z.object({
146
+ optional: z.boolean().optional(),
147
+ nullable: z.boolean().optional(),
148
+ extra: z.record(z.string(),z.any()).optional(),
149
+ coerce: z.boolean().optional(),
150
+ type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
151
+ definition: z.literal(jzodEnumAttributeTypesSchema.enum.number),
152
+ validations: z.array(jzodAttributeNumberValidationsSchema),
153
+ }).strict();
154
+
155
+ export type JzodAttributeNumberWithValidations = z.infer<typeof jzodAttributeNumberWithValidationsSchema>;
156
+
157
+ // ##############################################################################################################
158
+ export const jzodAttributeStringWithValidationsSchema = z.object({
159
+ optional: z.boolean().optional(),
160
+ nullable: z.boolean().optional(),
161
+ extra: z.record(z.string(),z.any()).optional(),
162
+ coerce: z.boolean().optional(),
163
+ type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
164
+ definition: z.literal(jzodEnumAttributeTypesSchema.enum.string),
165
+ validations: z.array(jzodAttributeStringValidationsSchema),
166
+ }).strict();
167
+
168
+ export type JzodAttributeStringWithValidations = z.infer<typeof jzodAttributeStringWithValidationsSchema>;
169
+
170
+ // ##############################################################################################################
171
+ export const jzodAttributeSchema = z.object({
172
+ optional: z.boolean().optional(),
173
+ nullable: z.boolean().optional(),
174
+ extra: z.record(z.string(),z.any()).optional(),
175
+ coerce: z.boolean().optional(),
176
+ type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
177
+ definition: z.lazy(()=>jzodEnumAttributeTypesSchema),
178
+ }).strict();
179
+
180
+ export type JzodAttribute = z.infer<typeof jzodAttributeSchema>;
181
+
182
+
183
+ // ##############################################################################################################
184
+ export type JzodElement =
185
+ | JzodArray
186
+ | JzodAttribute
187
+ | JzodAttributeDateWithValidations
188
+ | JzodAttributeNumberWithValidations
189
+ | JzodAttributeStringWithValidations
190
+ | JzodEnum
191
+ | JzodFunction
192
+ | JzodLazy
193
+ | JzodLiteral
194
+ | JzodIntersection
195
+ | JzodMap
196
+ | JzodRecord
197
+ | JzodObject
198
+ | JzodPromise
199
+ | JzodReference
200
+ | JzodSet
201
+ | JzodTuple
202
+ | JzodUnion
203
+ ;
204
+
205
+ export const jzodElementSchema: z.ZodType<JzodElement> = z.union([
206
+ z.lazy(()=>jzodArraySchema),
207
+ z.lazy(()=>jzodAttributeSchema),
208
+ z.lazy(()=>jzodAttributeDateWithValidationsSchema),
209
+ z.lazy(()=>jzodAttributeNumberWithValidationsSchema),
210
+ z.lazy(()=>jzodAttributeStringWithValidationsSchema),
211
+ z.lazy(()=>jzodEnumSchema),
212
+ z.lazy(()=>jzodFunctionSchema),
213
+ z.lazy(()=>jzodLazySchema),
214
+ z.lazy(()=>jzodLiteralSchema),
215
+ z.lazy(()=>jzodIntersectionSchema),
216
+ z.lazy(()=>jzodMapSchema),
217
+ z.lazy(()=>jzodObjectSchema),
218
+ z.lazy(()=>jzodPromiseSchema),
219
+ z.lazy(()=>jzodRecordSchema),
220
+ z.lazy(()=>jzodReferenceSchema),
221
+ z.lazy(()=>jzodSetSchema),
222
+ z.lazy(()=>jzodTupleSchema),
223
+ z.lazy(()=>jzodUnionSchema),
224
+ ])
225
+
226
+ // // ##############################################################################################################
227
+ // export const jzodElementSetSchema = z.record(z.string(),jzodElementSchema);
228
+ // export type JzodElementSet = z.infer<typeof jzodElementSetSchema>;
229
+
230
+ // ##############################################################################################################
231
+ export const jzodEnumSchema = z.object({
232
+ optional: z.boolean().optional(),
233
+ nullable: z.boolean().optional(),
234
+ extra: z.record(z.string(),z.any()).optional(),
235
+ type: z.literal(jzodEnumElementTypesSchema.enum.enum),
236
+ definition: z.array(z.string()),
237
+ }).strict();
238
+
239
+ export type JzodEnum = z.infer<typeof jzodEnumSchema>;
240
+
241
+ // ##############################################################################################################
242
+ export interface JzodFunction {
243
+ // optional?: boolean,
244
+ // nullable?: boolean,
245
+ extra?: {[k:string]:any},
246
+ type: 'function',
247
+ definition: {args: JzodElement[], returns?: JzodElement},
248
+ }
249
+ export const jzodFunctionSchema: ZodType<JzodFunction> = z.object({
250
+ type: z.literal(jzodEnumElementTypesSchema.enum.function),
251
+ extra: z.record(z.string(),z.any()).optional(),
252
+ // anyway, arg and returns types are not use upon validation to check the function's interface. Suffices for it to be a function, it is then valid.
253
+ definition: z.object({
254
+ args:z.array(jzodElementSchema),
255
+ returns: jzodElementSchema.optional(),
256
+ })
257
+ }).strict();
258
+
259
+ // ##############################################################################################################
260
+ export const jzodLazySchema = z.object({
261
+ type: z.literal(jzodEnumElementTypesSchema.enum.lazy),
262
+ extra: z.record(z.string(),z.any()).optional(),
263
+ definition: jzodFunctionSchema,
264
+ }).strict();
265
+
266
+ export type JzodLazy = z.infer<typeof jzodLazySchema>;
267
+
268
+ // ##############################################################################################################
269
+ export const jzodLiteralSchema = z.object({
270
+ optional: z.boolean().optional(),
271
+ nullable: z.boolean().optional(),
272
+ extra: z.record(z.string(),z.any()).optional(),
273
+ type: z.literal(jzodEnumElementTypesSchema.enum.literal),
274
+ definition: z.string(),
275
+ }).strict();
276
+
277
+ export type JzodLiteral = z.infer<typeof jzodLiteralSchema>;
278
+
279
+ // ##############################################################################################################
280
+ export interface JzodIntersection {
281
+ optional?: boolean,
282
+ nullable?: boolean,
283
+ extra?: {[k:string]:any},
284
+ type: 'intersection',
285
+ definition: {left: JzodElement, right: JzodElement},
286
+ }
287
+
288
+ export const jzodIntersectionSchema: z.ZodType<JzodIntersection> = z.object({
289
+ optional: z.boolean().optional(),
290
+ nullable: z.boolean().optional(),
291
+ extra: z.record(z.string(),z.any()).optional(),
292
+ type: z.literal(jzodEnumElementTypesSchema.enum.intersection),
293
+ definition: z.lazy(()=>z.object({left: jzodElementSchema, right: jzodElementSchema}))
294
+ }).strict();
295
+
296
+ // ##############################################################################################################
297
+ export interface JzodMap extends JzodRoot {
298
+ optional?: boolean,
299
+ nullable?: boolean,
300
+ extra?: {[k:string]:any},
301
+ type: 'map',
302
+ definition: [JzodElement,JzodElement]
303
+ }
304
+
305
+ export const jzodMapSchema: z.ZodType<JzodMap> = z.object({ // issue with JsonSchema conversion when using extend from ZodRootSchema, although the 2 are functionnaly equivalent
306
+ optional: z.boolean().optional(),
307
+ nullable: z.boolean().optional(),
308
+ extra: z.record(z.string(),z.any()).optional(),
309
+ type: z.literal('map'),
310
+ definition: z.lazy(()=>z.tuple([jzodElementSchema, jzodElementSchema]))
311
+ }).strict();
312
+
313
+ // ##############################################################################################################
314
+ export interface JzodObject extends JzodRoot {
315
+ optional?: boolean,
316
+ nullable?: boolean,
317
+ extend?: JzodReference | JzodObject,
318
+ extra?: {[k:string]:any},
319
+ type: "object",
320
+ nonStrict?: boolean,
321
+ // context?: {[attributeName:string]: JzodElement},
322
+ definition: {[attributeName:string]: JzodElement}
323
+ }
324
+
325
+ export const jzodObjectSchema: z.ZodType<JzodObject> = z.object({
326
+ optional: z.boolean().optional(),
327
+ nullable: z.boolean().optional(),
328
+ extend: z.lazy(()=>z.union([jzodReferenceSchema,jzodObjectSchema])).optional(),
329
+ extra: z.record(z.string(),z.any()).optional(),
330
+ type: z.literal(jzodEnumElementTypesSchema.enum.object),
331
+ nonStrict: z.boolean().optional(),
332
+ definition: z.lazy(()=>z.record(z.string(),jzodElementSchema)),
333
+ }).strict();
334
+
335
+ // ##############################################################################################################
336
+ export interface JzodPromise extends JzodRoot {
337
+ // optional?: boolean,
338
+ // nullable?: boolean,
339
+ extra?: {[k:string]:any},
340
+ type: 'promise',
341
+ definition: JzodElement
342
+ }
343
+
344
+ export const jzodPromiseSchema: z.ZodType<JzodPromise> = z.object({ // issue with JsonSchema conversion when using extend from ZodRootSchema, although the 2 are functionnaly equivalent
345
+ // optional: z.boolean().optional(),
346
+ // nullable: z.boolean().optional(),
347
+ extra: z.record(z.string(),z.any()).optional(),
348
+ type: z.literal('promise'),
349
+ definition: z.lazy(()=>jzodElementSchema)
350
+ }).strict();
351
+
352
+
353
+ // ##############################################################################################################
354
+ export interface JzodRecord {
355
+ optional?: boolean,
356
+ nullable?: boolean,
357
+ extra?: {[k:string]:any},
358
+ type: 'record',
359
+ definition: JzodElement,
360
+ }
361
+
362
+ export const jzodRecordSchema: z.ZodType<JzodRecord> = z.object({
363
+ optional: z.boolean().optional(),
364
+ nullable: z.boolean().optional(),
365
+ extra: z.record(z.string(),z.any()).optional(),
366
+ type: z.literal(jzodEnumElementTypesSchema.enum.record),
367
+ definition: z.lazy(()=>jzodElementSchema)
368
+ }).strict();
369
+
370
+ // ##############################################################################################################
371
+ export interface JzodReference {
372
+ optional?: boolean,
373
+ nullable?: boolean,
374
+ extra?: {[k:string]:any},
375
+ context?: {[attributeName:string]: JzodElement},
376
+ type: 'schemaReference',
377
+ definition: {
378
+ eager?: boolean,
379
+ relativePath?: string,
380
+ absolutePath?: string,
381
+ },
382
+ }
383
+
384
+ export const jzodReferenceSchema: ZodType<JzodReference> = z.object({ // inheritance from ZodRootSchema leads to a different JsonSchema thus invalidates tests, although it is semantically equivalent
385
+ optional: z.boolean().optional(),
386
+ nullable: z.boolean().optional(),
387
+ extra: z.record(z.string(),z.any()).optional(),
388
+ type: z.literal(jzodEnumElementTypesSchema.enum.schemaReference),
389
+ context: z.lazy(()=>z.record(z.string(),jzodElementSchema)).optional(),
390
+ definition: z.object({
391
+ eager: z.boolean().optional(),
392
+ relativePath: z.string().optional(),
393
+ absolutePath: z.string().optional(),
394
+ })
395
+ }).strict()
396
+
397
+ // export type JzodReference = z.infer<typeof jzodReferenceSchema>;
398
+
399
+ // ##############################################################################################################
400
+ export interface JzodSet extends JzodRoot {
401
+ optional?: boolean,
402
+ nullable?: boolean,
403
+ extra?: {[k:string]:any},
404
+ type: 'set',
405
+ definition: JzodElement
406
+ }
407
+
408
+ export const jzodSetSchema: z.ZodType<JzodSet> = z.object({ // issue with JsonSchema conversion when using extend from ZodRootSchema, although the 2 are functionnaly equivalent
409
+ optional: z.boolean().optional(),
410
+ nullable: z.boolean().optional(),
411
+ extra: z.record(z.string(),z.any()).optional(),
412
+ type: z.literal('set'),
413
+ definition: z.lazy(()=>jzodElementSchema)
414
+ }).strict();
415
+
416
+ // ##############################################################################################################
417
+ export interface JzodTuple {
418
+ optional?: boolean,
419
+ nullable?: boolean,
420
+ extra?: {[k:string]:any},
421
+ type: 'tuple',
422
+ definition: JzodElement[],
423
+ }
424
+
425
+ export const jzodTupleSchema: z.ZodType<JzodTuple> = z.object({
426
+ optional: z.boolean().optional(),
427
+ nullable: z.boolean().optional(),
428
+ extra: z.record(z.string(),z.any()).optional(),
429
+ type: z.literal(jzodEnumElementTypesSchema.enum.tuple),
430
+ definition: z.array(jzodElementSchema),
431
+ }).strict();
432
+
433
+ // ##############################################################################################################
434
+ export interface JzodUnion {
435
+ optional?: boolean,
436
+ nullable?: boolean,
437
+ extra?: {[k:string]:any},
438
+ type: "union",
439
+ discriminator?: string,
440
+ definition: JzodElement[],
441
+ }
442
+ export const jzodUnionSchema: z.ZodType<JzodUnion> = z.object({
443
+ optional: z.boolean().optional(),
444
+ nullable: z.boolean().optional(),
445
+ extra: z.record(z.string(),z.any()).optional(),
446
+ type: z.literal(jzodEnumElementTypesSchema.enum.union),
447
+ discriminator: z.string().optional(),
448
+ definition: z.lazy(()=>z.array(jzodElementSchema))
449
+ }).strict();
450
+