@miroir-framework/jzod-ts 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle.js CHANGED
@@ -2,302 +2,306 @@ import { printNode, withGetType, zodToTs, createTypeAlias } from 'zod-to-ts';
2
2
  import { jzodElementSchemaToZodSchemaAndDescription } from '@miroir-framework/jzod';
3
3
  import { z } from 'zod';
4
4
 
5
- function printTsTypeAlias(typeAlias, exportPrefix = true) {
6
- return (exportPrefix ? "export " : "") + printNode(typeAlias);
7
- }
8
- function printTsTypeAliases(typeAliases, exportPrefix = true) {
9
- const result = Object.entries(typeAliases).reduce((acc, curr) => {
10
- return `${acc}
11
- ${printTsTypeAlias(curr[1], exportPrefix)}`;
12
- }, "");
13
- return result;
5
+ function printTsTypeAlias(typeAlias, exportPrefix = true) {
6
+ return (exportPrefix ? "export " : "") + printNode(typeAlias);
7
+ }
8
+ function printTsTypeAliases(typeAliases, exportPrefix = true) {
9
+ const result = Object.entries(typeAliases).reduce((acc, curr) => {
10
+ return `${acc}
11
+ ${printTsTypeAlias(curr[1], exportPrefix)}`;
12
+ }, "");
13
+ return result;
14
14
  }
15
15
 
16
- function jzodToTsTypeAliasesAndZodText(element, typeName) {
17
- var _a, _b;
18
- const elementZodSchemaAndDescription = jzodElementSchemaToZodSchemaAndDescription(element, () => ({}), () => ({}), (innerReference, relativeReference) => withGetType(innerReference, (ts) => {
19
- return ts.factory.createTypeReferenceNode(ts.factory.createIdentifier(relativeReference ? relativeReference : "RELATIVEPATH_NOT_DEFINED"));
20
- }));
21
- const contextTsTypesString = Object.fromEntries(Object.entries((_a = elementZodSchemaAndDescription.contextZodSchema) !== null && _a !== void 0 ? _a : {}).map((curr) => {
22
- const tsNode = zodToTs(curr[1], typeName).node;
23
- const typeAlias = createTypeAlias(tsNode, curr[0]);
24
- return [curr[0], typeAlias];
25
- }));
26
- const tsTypeStringNode = zodToTs(elementZodSchemaAndDescription.zodSchema, typeName).node;
27
- const tsTypeStringTypeAlias = createTypeAlias(tsTypeStringNode, typeName !== null && typeName !== void 0 ? typeName : "");
28
- return {
29
- contextTsTypeAliases: contextTsTypesString,
30
- contextZodText: (_b = elementZodSchemaAndDescription.contextZodText) !== null && _b !== void 0 ? _b : {},
31
- mainZodText: elementZodSchemaAndDescription.zodText,
32
- mainTsTypeAlias: tsTypeStringTypeAlias,
33
- };
34
- }
35
- function jzodToTsCode(jzodElement, exportPrefix = true, typeName) {
36
- const schemaName = typeName ? typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toLowerCase() + c) : "";
37
- const header = `import { ZodType, ZodTypeAny, z } from "zod";`;
38
- const typeAliasesAndZodText = jzodToTsTypeAliasesAndZodText(jzodElement, typeName);
39
- const bodyJsCode = `export const ${schemaName}: z.ZodType<${schemaName}> = ${typeAliasesAndZodText.mainZodText};`;
40
- const contextTsTypesString = printTsTypeAliases(typeAliasesAndZodText.contextTsTypeAliases, exportPrefix);
41
- const contextJsCode = typeAliasesAndZodText.contextZodText
42
- ? Object.entries(typeAliasesAndZodText.contextZodText).reduce((acc, curr) => {
43
- return `${acc}
44
- export const ${curr[0]}=${curr[1]};`;
45
- }, "")
46
- : "";
47
- const tsTypesString = (exportPrefix ? "export " : "") + printNode(typeAliasesAndZodText.mainTsTypeAlias);
48
- return `${header}
49
- ${contextTsTypesString}
50
- ${tsTypesString}
51
- ${contextJsCode}
52
- ${bodyJsCode}
53
- `;
16
+ function jzodToTsTypeAliasesAndZodText(element, typeName) {
17
+ var _a, _b;
18
+ const elementZodSchemaAndDescription = jzodElementSchemaToZodSchemaAndDescription(element, () => ({}), () => ({}), (innerReference, relativeReference) => withGetType(innerReference, (ts) => {
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"));
21
+ }));
22
+ const contextTsTypesString = Object.fromEntries(Object.entries((_a = elementZodSchemaAndDescription.contextZodSchema) !== null && _a !== void 0 ? _a : {}).map((curr) => {
23
+ const actualTypeName = curr[0] ? curr[0].replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
24
+ const tsNode = zodToTs(curr[1], typeName).node;
25
+ const typeAlias = createTypeAlias(tsNode, actualTypeName);
26
+ return [curr[0], typeAlias];
27
+ }));
28
+ const tsTypeStringNode = zodToTs(elementZodSchemaAndDescription.zodSchema, typeName).node;
29
+ const tsTypeStringTypeAlias = createTypeAlias(tsTypeStringNode, typeName !== null && typeName !== void 0 ? typeName : "");
30
+ return {
31
+ contextTsTypeAliases: contextTsTypesString,
32
+ contextZodText: (_b = elementZodSchemaAndDescription.contextZodText) !== null && _b !== void 0 ? _b : {},
33
+ mainZodText: elementZodSchemaAndDescription.zodText,
34
+ mainTsTypeAlias: tsTypeStringTypeAlias,
35
+ };
36
+ }
37
+ function jzodToTsCode(jzodElement, exportPrefix = true, typeName) {
38
+ const schemaName = typeName ? typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toLowerCase() + c) : "";
39
+ const actualTypeName = typeName ? typeName.replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
40
+ const header = `import { ZodType, ZodTypeAny, z } from "zod";`;
41
+ const typeAliasesAndZodText = jzodToTsTypeAliasesAndZodText(jzodElement, actualTypeName);
42
+ const bodyJsCode = `export const ${schemaName}: z.ZodType<${actualTypeName}> = ${typeAliasesAndZodText.mainZodText};`;
43
+ const contextTsTypesString = printTsTypeAliases(typeAliasesAndZodText.contextTsTypeAliases, exportPrefix);
44
+ const contextJsCode = typeAliasesAndZodText.contextZodText
45
+ ? Object.entries(typeAliasesAndZodText.contextZodText).reduce((acc, curr) => {
46
+ const contextTypeName = curr[0] ? curr[0].replace(/^(.)(.*)$/, (a, b, c) => b.toUpperCase() + c) : "";
47
+ return `${acc}
48
+ export const ${curr[0]}:z.ZodType<${contextTypeName}> = ${curr[1]};`;
49
+ }, "")
50
+ : "";
51
+ const tsTypesString = (exportPrefix ? "export " : "") + printNode(typeAliasesAndZodText.mainTsTypeAlias);
52
+ return `${header}
53
+ ${contextTsTypesString}
54
+ ${tsTypesString}
55
+ ${contextJsCode}
56
+ ${bodyJsCode}
57
+ `;
54
58
  }
55
59
 
56
- z.object({
57
- optional: z.boolean().optional(),
58
- }).strict();
59
- const jzodEnumAttributeTypesSchema = z.enum([
60
- "any",
61
- "bigint",
62
- "boolean",
63
- "date",
64
- "never",
65
- "null",
66
- "number",
67
- "string",
68
- "uuid",
69
- "undefined",
70
- "unknown",
71
- "void",
72
- ]);
73
- const jzodEnumElementTypesSchema = z.enum([
74
- "array",
75
- "enum",
76
- "function",
77
- "lazy",
78
- "literal",
79
- "intersection",
80
- "map",
81
- "object",
82
- "promise",
83
- "record",
84
- "schemaReference",
85
- "set",
86
- "simpleType",
87
- "tuple",
88
- "union",
89
- ]);
90
- const jzodArraySchema = z.object({
91
- optional: z.boolean().optional(),
92
- nullable: z.boolean().optional(),
93
- extra: z.record(z.string(), z.any()).optional(),
94
- type: z.literal('array'),
95
- definition: z.lazy(() => jzodElementSchema)
96
- }).strict();
97
- const jzodAttributeDateValidationsSchema = z
98
- .object({
99
- extra: z.record(z.string(), z.any()).optional(),
100
- type: z.enum([
101
- "min",
102
- "max",
103
- ]),
104
- parameter: z.any(),
105
- })
106
- .strict();
107
- const jzodAttributeNumberValidationsSchema = z
108
- .object({
109
- extra: z.record(z.string(), z.any()).optional(),
110
- type: z.enum([
111
- "gt",
112
- "gte",
113
- "lt",
114
- "lte",
115
- "int",
116
- "positive",
117
- "nonpositive",
118
- "negative",
119
- "nonnegative",
120
- "multipleOf",
121
- "finite",
122
- "safe",
123
- ]),
124
- parameter: z.any(),
125
- })
126
- .strict();
127
- const jzodAttributeStringValidationsSchema = z
128
- .object({
129
- extra: z.record(z.string(), z.any()).optional(),
130
- type: z.enum([
131
- "max",
132
- "min",
133
- "length",
134
- "email",
135
- "url",
136
- "emoji",
137
- "uuid",
138
- "cuid",
139
- "cuid2",
140
- "ulid",
141
- "regex",
142
- "includes",
143
- "startsWith",
144
- "endsWith",
145
- "datetime",
146
- "ip",
147
- ]),
148
- parameter: z.any(),
149
- })
150
- .strict();
151
- const jzodAttributeDateWithValidationsSchema = z.object({
152
- optional: z.boolean().optional(),
153
- nullable: z.boolean().optional(),
154
- extra: z.record(z.string(), z.any()).optional(),
155
- coerce: z.boolean().optional(),
156
- type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
157
- definition: z.literal(jzodEnumAttributeTypesSchema.enum.date),
158
- validations: z.array(jzodAttributeDateValidationsSchema),
159
- }).strict();
160
- const jzodAttributeNumberWithValidationsSchema = z.object({
161
- optional: z.boolean().optional(),
162
- nullable: z.boolean().optional(),
163
- extra: z.record(z.string(), z.any()).optional(),
164
- coerce: z.boolean().optional(),
165
- type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
166
- definition: z.literal(jzodEnumAttributeTypesSchema.enum.number),
167
- validations: z.array(jzodAttributeNumberValidationsSchema),
168
- }).strict();
169
- const jzodAttributeStringWithValidationsSchema = z.object({
170
- optional: z.boolean().optional(),
171
- nullable: z.boolean().optional(),
172
- extra: z.record(z.string(), z.any()).optional(),
173
- coerce: z.boolean().optional(),
174
- type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
175
- definition: z.literal(jzodEnumAttributeTypesSchema.enum.string),
176
- validations: z.array(jzodAttributeStringValidationsSchema),
177
- }).strict();
178
- const jzodAttributeSchema = z.object({
179
- optional: z.boolean().optional(),
180
- nullable: z.boolean().optional(),
181
- extra: z.record(z.string(), z.any()).optional(),
182
- coerce: z.boolean().optional(),
183
- type: z.literal(jzodEnumElementTypesSchema.enum.simpleType),
184
- definition: z.lazy(() => jzodEnumAttributeTypesSchema),
185
- }).strict();
186
- const jzodElementSchema = z.union([
187
- z.lazy(() => jzodArraySchema),
188
- z.lazy(() => jzodAttributeSchema),
189
- z.lazy(() => jzodAttributeDateWithValidationsSchema),
190
- z.lazy(() => jzodAttributeNumberWithValidationsSchema),
191
- z.lazy(() => jzodAttributeStringWithValidationsSchema),
192
- z.lazy(() => jzodEnumSchema),
193
- z.lazy(() => jzodFunctionSchema),
194
- z.lazy(() => jzodLazySchema),
195
- z.lazy(() => jzodLiteralSchema),
196
- z.lazy(() => jzodIntersectionSchema),
197
- z.lazy(() => jzodMapSchema),
198
- z.lazy(() => jzodObjectSchema),
199
- z.lazy(() => jzodPromiseSchema),
200
- z.lazy(() => jzodRecordSchema),
201
- z.lazy(() => jzodReferenceSchema),
202
- z.lazy(() => jzodSetSchema),
203
- z.lazy(() => jzodTupleSchema),
204
- z.lazy(() => jzodUnionSchema),
205
- ]);
206
- const jzodEnumSchema = z.object({
207
- optional: z.boolean().optional(),
208
- nullable: z.boolean().optional(),
209
- extra: z.record(z.string(), z.any()).optional(),
210
- type: z.literal(jzodEnumElementTypesSchema.enum.enum),
211
- definition: z.array(z.string()),
212
- }).strict();
213
- const jzodFunctionSchema = z.object({
214
- type: z.literal(jzodEnumElementTypesSchema.enum.function),
215
- extra: z.record(z.string(), z.any()).optional(),
216
- definition: z.object({
217
- args: z.array(jzodElementSchema),
218
- returns: jzodElementSchema.optional(),
219
- })
220
- }).strict();
221
- const jzodLazySchema = z.object({
222
- type: z.literal(jzodEnumElementTypesSchema.enum.lazy),
223
- extra: z.record(z.string(), z.any()).optional(),
224
- definition: jzodFunctionSchema,
225
- }).strict();
226
- const jzodLiteralSchema = z.object({
227
- optional: z.boolean().optional(),
228
- nullable: z.boolean().optional(),
229
- extra: z.record(z.string(), z.any()).optional(),
230
- type: z.literal(jzodEnumElementTypesSchema.enum.literal),
231
- definition: z.string(),
232
- }).strict();
233
- const jzodIntersectionSchema = z.object({
234
- optional: z.boolean().optional(),
235
- nullable: z.boolean().optional(),
236
- extra: z.record(z.string(), z.any()).optional(),
237
- type: z.literal(jzodEnumElementTypesSchema.enum.intersection),
238
- definition: z.lazy(() => z.object({ left: jzodElementSchema, right: jzodElementSchema }))
239
- }).strict();
240
- const jzodMapSchema = z.object({
241
- optional: z.boolean().optional(),
242
- nullable: z.boolean().optional(),
243
- extra: z.record(z.string(), z.any()).optional(),
244
- type: z.literal('map'),
245
- definition: z.lazy(() => z.tuple([jzodElementSchema, jzodElementSchema]))
246
- }).strict();
247
- const jzodObjectSchema = z.object({
248
- optional: z.boolean().optional(),
249
- nullable: z.boolean().optional(),
250
- extend: z.lazy(() => z.union([jzodReferenceSchema, jzodObjectSchema])).optional(),
251
- extra: z.record(z.string(), z.any()).optional(),
252
- type: z.literal(jzodEnumElementTypesSchema.enum.object),
253
- nonStrict: z.boolean().optional(),
254
- definition: z.lazy(() => z.record(z.string(), jzodElementSchema)),
255
- }).strict();
256
- const jzodPromiseSchema = z.object({
257
- extra: z.record(z.string(), z.any()).optional(),
258
- type: z.literal('promise'),
259
- definition: z.lazy(() => jzodElementSchema)
260
- }).strict();
261
- const jzodRecordSchema = z.object({
262
- optional: z.boolean().optional(),
263
- nullable: z.boolean().optional(),
264
- extra: z.record(z.string(), z.any()).optional(),
265
- type: z.literal(jzodEnumElementTypesSchema.enum.record),
266
- definition: z.lazy(() => jzodElementSchema)
267
- }).strict();
268
- const jzodReferenceSchema = z.object({
269
- optional: z.boolean().optional(),
270
- nullable: z.boolean().optional(),
271
- extra: z.record(z.string(), z.any()).optional(),
272
- type: z.literal(jzodEnumElementTypesSchema.enum.schemaReference),
273
- context: z.lazy(() => z.record(z.string(), jzodElementSchema)).optional(),
274
- definition: z.object({
275
- eager: z.boolean().optional(),
276
- relativePath: z.string().optional(),
277
- absolutePath: z.string().optional(),
278
- })
279
- }).strict();
280
- const jzodSetSchema = z.object({
281
- optional: z.boolean().optional(),
282
- nullable: z.boolean().optional(),
283
- extra: z.record(z.string(), z.any()).optional(),
284
- type: z.literal('set'),
285
- definition: z.lazy(() => jzodElementSchema)
286
- }).strict();
287
- const jzodTupleSchema = z.object({
288
- optional: z.boolean().optional(),
289
- nullable: z.boolean().optional(),
290
- extra: z.record(z.string(), z.any()).optional(),
291
- type: z.literal(jzodEnumElementTypesSchema.enum.tuple),
292
- definition: z.array(jzodElementSchema),
293
- }).strict();
294
- const jzodUnionSchema = z.object({
295
- optional: z.boolean().optional(),
296
- nullable: z.boolean().optional(),
297
- extra: z.record(z.string(), z.any()).optional(),
298
- type: z.literal(jzodEnumElementTypesSchema.enum.union),
299
- discriminator: z.string().optional(),
300
- definition: z.lazy(() => z.array(jzodElementSchema))
60
+ z.object({
61
+ optional: z.boolean().optional(),
62
+ }).strict();
63
+ const jzodEnumAttributeTypes = z.enum([
64
+ "any",
65
+ "bigint",
66
+ "boolean",
67
+ "date",
68
+ "never",
69
+ "null",
70
+ "number",
71
+ "string",
72
+ "uuid",
73
+ "undefined",
74
+ "unknown",
75
+ "void",
76
+ ]);
77
+ const jzodEnumElementTypes = z.enum([
78
+ "array",
79
+ "enum",
80
+ "function",
81
+ "lazy",
82
+ "literal",
83
+ "intersection",
84
+ "map",
85
+ "object",
86
+ "promise",
87
+ "record",
88
+ "schemaReference",
89
+ "set",
90
+ "simpleType",
91
+ "tuple",
92
+ "union",
93
+ ]);
94
+ const jzodArray = z.object({
95
+ optional: z.boolean().optional(),
96
+ nullable: z.boolean().optional(),
97
+ extra: z.record(z.string(), z.any()).optional(),
98
+ type: z.literal('array'),
99
+ definition: z.lazy(() => jzodElement)
100
+ }).strict();
101
+ const jzodAttributeDateValidations = z
102
+ .object({
103
+ extra: z.record(z.string(), z.any()).optional(),
104
+ type: z.enum([
105
+ "min",
106
+ "max",
107
+ ]),
108
+ parameter: z.any(),
109
+ })
110
+ .strict();
111
+ const jzodAttributeNumberValidations = z
112
+ .object({
113
+ extra: z.record(z.string(), z.any()).optional(),
114
+ type: z.enum([
115
+ "gt",
116
+ "gte",
117
+ "lt",
118
+ "lte",
119
+ "int",
120
+ "positive",
121
+ "nonpositive",
122
+ "negative",
123
+ "nonnegative",
124
+ "multipleOf",
125
+ "finite",
126
+ "safe",
127
+ ]),
128
+ parameter: z.any(),
129
+ })
130
+ .strict();
131
+ const jzodAttributeStringValidations = z
132
+ .object({
133
+ extra: z.record(z.string(), z.any()).optional(),
134
+ type: z.enum([
135
+ "max",
136
+ "min",
137
+ "length",
138
+ "email",
139
+ "url",
140
+ "emoji",
141
+ "uuid",
142
+ "cuid",
143
+ "cuid2",
144
+ "ulid",
145
+ "regex",
146
+ "includes",
147
+ "startsWith",
148
+ "endsWith",
149
+ "datetime",
150
+ "ip",
151
+ ]),
152
+ parameter: z.any(),
153
+ })
154
+ .strict();
155
+ const jzodAttributeDateWithValidations = z.object({
156
+ optional: z.boolean().optional(),
157
+ nullable: z.boolean().optional(),
158
+ extra: z.record(z.string(), z.any()).optional(),
159
+ coerce: z.boolean().optional(),
160
+ type: z.literal(jzodEnumElementTypes.enum.simpleType),
161
+ definition: z.literal(jzodEnumAttributeTypes.enum.date),
162
+ validations: z.array(jzodAttributeDateValidations),
163
+ }).strict();
164
+ const jzodAttributeNumberWithValidations = z.object({
165
+ optional: z.boolean().optional(),
166
+ nullable: z.boolean().optional(),
167
+ extra: z.record(z.string(), z.any()).optional(),
168
+ coerce: z.boolean().optional(),
169
+ type: z.literal(jzodEnumElementTypes.enum.simpleType),
170
+ definition: z.literal(jzodEnumAttributeTypes.enum.number),
171
+ validations: z.array(jzodAttributeNumberValidations),
172
+ }).strict();
173
+ const jzodAttributeStringWithValidations = z.object({
174
+ optional: z.boolean().optional(),
175
+ nullable: z.boolean().optional(),
176
+ extra: z.record(z.string(), z.any()).optional(),
177
+ coerce: z.boolean().optional(),
178
+ type: z.literal(jzodEnumElementTypes.enum.simpleType),
179
+ definition: z.literal(jzodEnumAttributeTypes.enum.string),
180
+ validations: z.array(jzodAttributeStringValidations),
181
+ }).strict();
182
+ const jzodAttribute = z.object({
183
+ optional: z.boolean().optional(),
184
+ nullable: z.boolean().optional(),
185
+ extra: z.record(z.string(), z.any()).optional(),
186
+ coerce: z.boolean().optional(),
187
+ type: z.literal(jzodEnumElementTypes.enum.simpleType),
188
+ definition: z.lazy(() => jzodEnumAttributeTypes),
189
+ }).strict();
190
+ const jzodElement = z.union([
191
+ z.lazy(() => jzodArray),
192
+ z.lazy(() => jzodAttribute),
193
+ z.lazy(() => jzodAttributeDateWithValidations),
194
+ z.lazy(() => jzodAttributeNumberWithValidations),
195
+ z.lazy(() => jzodAttributeStringWithValidations),
196
+ z.lazy(() => jzodEnum),
197
+ z.lazy(() => jzodFunction),
198
+ z.lazy(() => jzodLazy),
199
+ z.lazy(() => jzodLiteral),
200
+ z.lazy(() => jzodIntersection),
201
+ z.lazy(() => jzodMapSchema),
202
+ z.lazy(() => jzodObject),
203
+ z.lazy(() => jzodPromise),
204
+ z.lazy(() => jzodRecord),
205
+ z.lazy(() => jzodReference),
206
+ z.lazy(() => jzodSet),
207
+ z.lazy(() => jzodTuple),
208
+ z.lazy(() => jzodUnion),
209
+ ]);
210
+ const jzodEnum = z.object({
211
+ optional: z.boolean().optional(),
212
+ nullable: z.boolean().optional(),
213
+ extra: z.record(z.string(), z.any()).optional(),
214
+ type: z.literal(jzodEnumElementTypes.enum.enum),
215
+ definition: z.array(z.string()),
216
+ }).strict();
217
+ const jzodFunction = z.object({
218
+ type: z.literal(jzodEnumElementTypes.enum.function),
219
+ extra: z.record(z.string(), z.any()).optional(),
220
+ definition: z.object({
221
+ args: z.array(jzodElement),
222
+ returns: jzodElement.optional(),
223
+ })
224
+ }).strict();
225
+ const jzodLazy = z.object({
226
+ type: z.literal(jzodEnumElementTypes.enum.lazy),
227
+ extra: z.record(z.string(), z.any()).optional(),
228
+ definition: jzodFunction,
229
+ }).strict();
230
+ const jzodLiteral = z.object({
231
+ optional: z.boolean().optional(),
232
+ nullable: z.boolean().optional(),
233
+ extra: z.record(z.string(), z.any()).optional(),
234
+ type: z.literal(jzodEnumElementTypes.enum.literal),
235
+ definition: z.string(),
236
+ }).strict();
237
+ const jzodIntersection = z.object({
238
+ optional: z.boolean().optional(),
239
+ nullable: z.boolean().optional(),
240
+ extra: z.record(z.string(), z.any()).optional(),
241
+ type: z.literal(jzodEnumElementTypes.enum.intersection),
242
+ definition: z.lazy(() => z.object({ left: jzodElement, right: jzodElement }))
243
+ }).strict();
244
+ const jzodMapSchema = z.object({
245
+ optional: z.boolean().optional(),
246
+ nullable: z.boolean().optional(),
247
+ extra: z.record(z.string(), z.any()).optional(),
248
+ type: z.literal('map'),
249
+ definition: z.lazy(() => z.tuple([jzodElement, jzodElement]))
250
+ }).strict();
251
+ const jzodObject = z.object({
252
+ optional: z.boolean().optional(),
253
+ nullable: z.boolean().optional(),
254
+ extend: z.lazy(() => z.union([jzodReference, jzodObject])).optional(),
255
+ extra: z.record(z.string(), z.any()).optional(),
256
+ type: z.literal(jzodEnumElementTypes.enum.object),
257
+ nonStrict: z.boolean().optional(),
258
+ definition: z.lazy(() => z.record(z.string(), jzodElement)),
259
+ }).strict();
260
+ const jzodPromise = z.object({
261
+ extra: z.record(z.string(), z.any()).optional(),
262
+ type: z.literal('promise'),
263
+ definition: z.lazy(() => jzodElement)
264
+ }).strict();
265
+ const jzodRecord = z.object({
266
+ optional: z.boolean().optional(),
267
+ nullable: z.boolean().optional(),
268
+ extra: z.record(z.string(), z.any()).optional(),
269
+ type: z.literal(jzodEnumElementTypes.enum.record),
270
+ definition: z.lazy(() => jzodElement)
271
+ }).strict();
272
+ const jzodReference = z.object({
273
+ optional: z.boolean().optional(),
274
+ nullable: z.boolean().optional(),
275
+ extra: z.record(z.string(), z.any()).optional(),
276
+ type: z.literal(jzodEnumElementTypes.enum.schemaReference),
277
+ context: z.lazy(() => z.record(z.string(), jzodElement)).optional(),
278
+ definition: z.object({
279
+ eager: z.boolean().optional(),
280
+ relativePath: z.string().optional(),
281
+ absolutePath: z.string().optional(),
282
+ })
283
+ }).strict();
284
+ const jzodSet = z.object({
285
+ optional: z.boolean().optional(),
286
+ nullable: z.boolean().optional(),
287
+ extra: z.record(z.string(), z.any()).optional(),
288
+ type: z.literal('set'),
289
+ definition: z.lazy(() => jzodElement)
290
+ }).strict();
291
+ const jzodTuple = z.object({
292
+ optional: z.boolean().optional(),
293
+ nullable: z.boolean().optional(),
294
+ extra: z.record(z.string(), z.any()).optional(),
295
+ type: z.literal(jzodEnumElementTypes.enum.tuple),
296
+ definition: z.array(jzodElement),
297
+ }).strict();
298
+ const jzodUnion = z.object({
299
+ optional: z.boolean().optional(),
300
+ nullable: z.boolean().optional(),
301
+ extra: z.record(z.string(), z.any()).optional(),
302
+ type: z.literal(jzodEnumElementTypes.enum.union),
303
+ discriminator: z.string().optional(),
304
+ definition: z.lazy(() => z.array(jzodElement))
301
305
  }).strict();
302
306
 
303
- export { jzodArraySchema, jzodAttributeDateValidationsSchema, jzodAttributeDateWithValidationsSchema, jzodAttributeNumberValidationsSchema, jzodAttributeNumberWithValidationsSchema, jzodAttributeSchema, jzodAttributeStringValidationsSchema, jzodAttributeStringWithValidationsSchema, jzodElementSchema, jzodEnumAttributeTypesSchema, jzodEnumElementTypesSchema, jzodEnumSchema, jzodFunctionSchema, jzodIntersectionSchema, jzodLazySchema, jzodLiteralSchema, jzodMapSchema, jzodObjectSchema, jzodPromiseSchema, jzodRecordSchema, jzodReferenceSchema, jzodSetSchema, jzodToTsCode, jzodToTsTypeAliasesAndZodText, jzodTupleSchema, jzodUnionSchema, printTsTypeAlias, printTsTypeAliases };
307
+ export { jzodArray, jzodAttribute, jzodAttributeDateValidations, jzodAttributeDateWithValidations, jzodAttributeNumberValidations, jzodAttributeNumberWithValidations, jzodAttributeStringValidations, jzodAttributeStringWithValidations, jzodElement, jzodEnum, jzodEnumAttributeTypes, jzodEnumElementTypes, jzodFunction, jzodIntersection, jzodLazy, jzodLiteral, jzodMapSchema, jzodObject, jzodPromise, jzodRecord, jzodReference, jzodSet, jzodToTsCode, jzodToTsTypeAliasesAndZodText, jzodTuple, jzodUnion, printTsTypeAlias, printTsTypeAliases };
@@ -1,17 +1,17 @@
1
- import ts from "typescript";
2
- import { JzodElement } from "./JzodTsInterface";
3
- export type TsTypeAliases = {
4
- [k: string]: ts.TypeAliasDeclaration;
5
- };
6
- export interface TsTypeAliasesAndZodText {
7
- contextTsTypeAliases: {
8
- [k: string]: ts.TypeAliasDeclaration;
9
- };
10
- contextZodText: {
11
- [k: string]: string;
12
- };
13
- mainTsTypeAlias: ts.TypeAliasDeclaration;
14
- mainZodText: string;
15
- }
16
- export declare function jzodToTsTypeAliasesAndZodText(element: JzodElement, typeName?: string): TsTypeAliasesAndZodText;
17
- export declare function jzodToTsCode(jzodElement: JzodElement, exportPrefix?: boolean, typeName?: string): string;
1
+ import ts from "typescript";
2
+ import { JzodElement } from "./JzodTsInterface";
3
+ export type TsTypeAliases = {
4
+ [k: string]: ts.TypeAliasDeclaration;
5
+ };
6
+ export interface TsTypeAliasesAndZodText {
7
+ contextTsTypeAliases: {
8
+ [k: string]: ts.TypeAliasDeclaration;
9
+ };
10
+ contextZodText: {
11
+ [k: string]: string;
12
+ };
13
+ mainTsTypeAlias: ts.TypeAliasDeclaration;
14
+ mainZodText: string;
15
+ }
16
+ export declare function jzodToTsTypeAliasesAndZodText(element: JzodElement, typeName?: string): TsTypeAliasesAndZodText;
17
+ export declare function jzodToTsCode(jzodElement: JzodElement, exportPrefix?: boolean, typeName?: string): string;