@postxl/generators 2.0.0 → 2.1.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/dist/backend-core/backend.generator.js +9 -9
- package/dist/backend-database-prisma/generators/prisma-schema.generator.js +20 -0
- package/dist/backend-database-prisma/generators/prisma-schema.generator.js.map +1 -1
- package/dist/backend-database-prisma/prisma.generator.js +4 -4
- package/dist/backend-mail/mail.generator.js +1 -1
- package/dist/backend-mail/mail.generator.js.map +1 -1
- package/dist/backend-repositories/generators/model-repository.generator.js +50 -20
- package/dist/backend-repositories/generators/model-repository.generator.js.map +1 -1
- package/dist/backend-repositories/model.types.d.ts +2 -2
- package/dist/backend-router-trpc/router-trpc.generator.js +3 -2
- package/dist/backend-router-trpc/router-trpc.generator.js.map +1 -1
- package/dist/backend-s3/s3.generator.js +1 -1
- package/dist/backend-s3/s3.generator.js.map +1 -1
- package/dist/base/base.generator.js +9 -9
- package/dist/base/base.generator.js.map +1 -1
- package/dist/devops/generators/e2e-yml.generator.js +1 -1
- package/dist/e2e/template/e2e/Dockerfile +1 -1
- package/dist/e2e/template/e2e/package.json +5 -5
- package/dist/frontend-actions/generators/command-palette-action.generator.js +49 -0
- package/dist/frontend-actions/generators/command-palette-action.generator.js.map +1 -1
- package/dist/frontend-actions/generators/command-palette.generator.js +34 -3
- package/dist/frontend-actions/generators/command-palette.generator.js.map +1 -1
- package/dist/frontend-core/frontend.generator.js +22 -22
- package/dist/frontend-core/frontend.generator.js.map +1 -1
- package/dist/frontend-forms/forms.generator.js +1 -1
- package/dist/frontend-trpc-client/trpc-client.generator.js +1 -1
- package/dist/frontend-trpc-client/trpc-client.generator.js.map +1 -1
- package/package.json +6 -6
- package/dist/decoders/discriminated-union.decoder.generator.d.ts +0 -12
- package/dist/decoders/discriminated-union.decoder.generator.js +0 -297
- package/dist/decoders/discriminated-union.decoder.generator.js.map +0 -1
- package/dist/frontend-forms/generators/discriminated-union/fields.generator.d.ts +0 -11
- package/dist/frontend-forms/generators/discriminated-union/fields.generator.js +0 -315
- package/dist/frontend-forms/generators/discriminated-union/fields.generator.js.map +0 -1
- package/dist/frontend-forms/generators/discriminated-union/inputs.generator.d.ts +0 -7
- package/dist/frontend-forms/generators/discriminated-union/inputs.generator.js +0 -69
- package/dist/frontend-forms/generators/discriminated-union/inputs.generator.js.map +0 -1
- package/dist/types/generators/discriminated-union.generator.d.ts +0 -6
- package/dist/types/generators/discriminated-union.generator.js +0 -86
- package/dist/types/generators/discriminated-union.generator.js.map +0 -1
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.generateDiscriminatedUnionDecoder = generateDiscriminatedUnionDecoder;
|
|
37
|
-
const Generator = __importStar(require("@postxl/generator"));
|
|
38
|
-
const FlattenedFieldHelper = __importStar(require("./excel-field-decoder.helper"));
|
|
39
|
-
const FieldDecoder = __importStar(require("./field-decoder.helper"));
|
|
40
|
-
/**
|
|
41
|
-
* Checks if a discriminated union has any relation fields (in common fields or any member).
|
|
42
|
-
*/
|
|
43
|
-
function hasRelationFields(field) {
|
|
44
|
-
// Check common fields
|
|
45
|
-
for (const f of field.commonFields.values()) {
|
|
46
|
-
if (f.kind === 'relation') {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Check member fields
|
|
51
|
-
for (const member of field.members.values()) {
|
|
52
|
-
for (const f of member.fields.values()) {
|
|
53
|
-
if (f.kind === 'relation') {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
function generateDiscriminatedUnionDecoder({ context, model, discriminatedUnion, }) {
|
|
61
|
-
const imports = Generator.ImportGenerator.from(model.decoder.decoder.zodDecoder.location);
|
|
62
|
-
const params = { context, model, discriminatedUnion, field: discriminatedUnion.field, imports };
|
|
63
|
-
// We cannot inline below definitions, as we need to add the imports before
|
|
64
|
-
const decoder = getDecoder(params);
|
|
65
|
-
const flattenedParams = {
|
|
66
|
-
...params,
|
|
67
|
-
toName: (f) => f.databaseName,
|
|
68
|
-
codecDefinition: discriminatedUnion.flattened,
|
|
69
|
-
};
|
|
70
|
-
const flattenedType = getFlattenedType(flattenedParams);
|
|
71
|
-
const flattenedEncoder = getFlattenedEncoder(flattenedParams);
|
|
72
|
-
const flattenedDecoder = getFlattenedDecoder(flattenedParams);
|
|
73
|
-
const excelParams = {
|
|
74
|
-
...params,
|
|
75
|
-
toName: (f) => f.excelName,
|
|
76
|
-
codecDefinition: discriminatedUnion.excel,
|
|
77
|
-
isExcel: true,
|
|
78
|
-
};
|
|
79
|
-
const excelType = getFlattenedType(excelParams);
|
|
80
|
-
const excelEncoder = getFlattenedEncoder(excelParams);
|
|
81
|
-
const excelDecoder = getFlattenedDecoder(excelParams);
|
|
82
|
-
return /* ts */ `
|
|
83
|
-
import * as z from 'zod'
|
|
84
|
-
${imports.generate()}
|
|
85
|
-
|
|
86
|
-
${decoder}
|
|
87
|
-
|
|
88
|
-
${flattenedType}
|
|
89
|
-
|
|
90
|
-
${flattenedEncoder}
|
|
91
|
-
|
|
92
|
-
${flattenedDecoder}
|
|
93
|
-
|
|
94
|
-
${excelType}
|
|
95
|
-
|
|
96
|
-
${excelEncoder}
|
|
97
|
-
|
|
98
|
-
${excelDecoder}`;
|
|
99
|
-
}
|
|
100
|
-
function getDecoder({ context, model, discriminatedUnion, field, imports }) {
|
|
101
|
-
imports.addTypeImport({ from: context.types.location, items: [field.type] });
|
|
102
|
-
const sharedFields = [];
|
|
103
|
-
for (const f of field.commonFields.values()) {
|
|
104
|
-
sharedFields.push(FieldDecoder.getFieldDecoder({ context, model, field: f, imports }));
|
|
105
|
-
}
|
|
106
|
-
const members = [];
|
|
107
|
-
for (const member of field.members.values()) {
|
|
108
|
-
const memberFields = [`type: z.literal('${member.type}')`, ...sharedFields];
|
|
109
|
-
for (const f of member.fields.values()) {
|
|
110
|
-
memberFields.push(FieldDecoder.getFieldDecoder({ context, model, field: f, imports }));
|
|
111
|
-
}
|
|
112
|
-
members.push(`z.object({ ${memberFields.join(', ')}})`);
|
|
113
|
-
}
|
|
114
|
-
return `
|
|
115
|
-
export const ${discriminatedUnion.decoder.zodDecoder.name} = z.discriminatedUnion('type', [
|
|
116
|
-
${members.join(',\n')}
|
|
117
|
-
])
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Decoder to ensure that the input is a valid ${field.type}.
|
|
121
|
-
*/
|
|
122
|
-
export function ${discriminatedUnion.decoder.parseFunction.name}(item: ${field.type}): ${field.type} {
|
|
123
|
-
return ${discriminatedUnion.decoder.zodDecoder.name}.parse(item)
|
|
124
|
-
}
|
|
125
|
-
`;
|
|
126
|
-
}
|
|
127
|
-
function getFlattenedType({ codecDefinition, field }) {
|
|
128
|
-
return `/**
|
|
129
|
-
* The ${field.type} discriminated union type flattened to a column structure.
|
|
130
|
-
*/
|
|
131
|
-
export type ${codecDefinition.decoder.rawInputType.name} = z.infer<typeof ${codecDefinition.decoder.rawInputValidation.name}>
|
|
132
|
-
`;
|
|
133
|
-
}
|
|
134
|
-
function getFlattenedEncoder({ context, field, imports, toName, codecDefinition }) {
|
|
135
|
-
const hasRelations = hasRelationFields(field);
|
|
136
|
-
// If there are relation fields, we need the lookup maps type
|
|
137
|
-
if (hasRelations) {
|
|
138
|
-
imports.addTypeImport({
|
|
139
|
-
from: Generator.toBackendModuleLocation('@decoders/data-model.decoder'),
|
|
140
|
-
items: [Generator.toTypeName('IdToKeyLookupMaps')],
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
const encoderFields = getEncoderFields({ field, context, hasRelations, toName });
|
|
144
|
-
if (hasRelations) {
|
|
145
|
-
return `
|
|
146
|
-
/**
|
|
147
|
-
* Encodes a ${field.type} discriminated union to a flattened object.
|
|
148
|
-
* When lookupMaps is provided, relation IDs are resolved to human-readable keyField values.
|
|
149
|
-
* When lookupMaps is not provided, IDs are output directly.
|
|
150
|
-
*/
|
|
151
|
-
export function ${codecDefinition.encoder.name}(item: ${field.type}, lookupMaps?: IdToKeyLookupMaps) {
|
|
152
|
-
return {
|
|
153
|
-
${encoderFields.join(',\n')}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
`;
|
|
157
|
-
}
|
|
158
|
-
return `
|
|
159
|
-
/**
|
|
160
|
-
* Encodes a ${field.type} discriminated union to a flattened object, where each
|
|
161
|
-
* nested field is mapped to a top-level field. This allows serialization to a column structure.
|
|
162
|
-
*/
|
|
163
|
-
export function ${codecDefinition.encoder.name}(item: ${field.type}) {
|
|
164
|
-
return {
|
|
165
|
-
${encoderFields.join(',\n')}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
`;
|
|
169
|
-
}
|
|
170
|
-
function getEncoderFields({ field, context, hasRelations, toName, }) {
|
|
171
|
-
const result = [];
|
|
172
|
-
result.push(`"${toName(field)}": item.type`);
|
|
173
|
-
for (const f of field.commonFields.values()) {
|
|
174
|
-
result.push(getEncoderFieldValue({ f, context, hasRelations, memberType: null, toName }));
|
|
175
|
-
}
|
|
176
|
-
for (const member of field.members.values()) {
|
|
177
|
-
for (const f of member.fields.values()) {
|
|
178
|
-
result.push(getEncoderFieldValue({ f, context, hasRelations, memberType: member.type, toName }));
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return result;
|
|
182
|
-
}
|
|
183
|
-
function getEncoderFieldValue({ f, context, hasRelations, memberType, toName, }) {
|
|
184
|
-
const key = `"${toName(f)}"`;
|
|
185
|
-
const valueExpr = memberType ? `item.type === '${memberType}' ? item.${f.name} : null` : `item.${f.name}`;
|
|
186
|
-
if (f.kind === 'relation' && hasRelations) {
|
|
187
|
-
const referencedModel = context.models.get(f.referencedModelName);
|
|
188
|
-
const lookupExpr = `lookupMaps?.${referencedModel.decoder.dataModelEntry}.get(item.${f.name})`;
|
|
189
|
-
if (memberType) {
|
|
190
|
-
// Member-specific field: check type first, then resolve ID to key
|
|
191
|
-
if (f.isRequired) {
|
|
192
|
-
return `${key}: item.type === '${memberType}' ? (${lookupExpr} ?? item.${f.name}) : null`;
|
|
193
|
-
}
|
|
194
|
-
return `${key}: item.type === '${memberType}' ? (item.${f.name} === null ? null : (${lookupExpr} ?? item.${f.name})) : null`;
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
// Common field: always present
|
|
198
|
-
if (f.isRequired) {
|
|
199
|
-
return `${key}: ${lookupExpr} ?? item.${f.name}`;
|
|
200
|
-
}
|
|
201
|
-
return `${key}: item.${f.name} === null ? null : (${lookupExpr} ?? item.${f.name})`;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return `${key}: ${valueExpr}`;
|
|
205
|
-
}
|
|
206
|
-
function getFlattenedDecoder({ context, model, field, imports, toName, codecDefinition, }) {
|
|
207
|
-
imports.addTypeImport({ from: context.types.location, items: [field.type] });
|
|
208
|
-
const discriminatorKey = toName(field);
|
|
209
|
-
const enumDecoder = `z.enum([${Array.from(field.members.values())
|
|
210
|
-
.map((f) => `'${f.type}'`)
|
|
211
|
-
.join(',')}]).transform((v) => v as string).nullable()`;
|
|
212
|
-
const fieldRawDecoders = [
|
|
213
|
-
`"${discriminatorKey}": z.preprocess((x) => (typeof x === 'string' && x === '') ? null : x, ${enumDecoder})`,
|
|
214
|
-
];
|
|
215
|
-
const commonFieldRequiredChecks = [`nullCheck('${discriminatorKey}')`];
|
|
216
|
-
const commonFieldTransformers = [];
|
|
217
|
-
const transformerSwitchCases = [];
|
|
218
|
-
for (const f of field.commonFields.values()) {
|
|
219
|
-
const { rawDecoder, transformer = FieldDecoder.defaultTransformer } = FlattenedFieldHelper.getFieldElements({
|
|
220
|
-
field: f,
|
|
221
|
-
context,
|
|
222
|
-
model,
|
|
223
|
-
imports,
|
|
224
|
-
// All fields are mode nullable even if required within a discriminated union, as the DU itself might be nullable!
|
|
225
|
-
enforceNullable: true,
|
|
226
|
-
});
|
|
227
|
-
const key = toName(f);
|
|
228
|
-
fieldRawDecoders.push(`"${key}": ${rawDecoder}`);
|
|
229
|
-
if (field.isRequired) {
|
|
230
|
-
commonFieldRequiredChecks.push(`if (item["${key}"] === null) {
|
|
231
|
-
ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Field ${key} is required but null!', path: ['${key}'] })
|
|
232
|
-
return z.NEVER
|
|
233
|
-
}`);
|
|
234
|
-
}
|
|
235
|
-
commonFieldTransformers.push(`${f.name}: ${transformer('item["' + key + '"]' + (f.isRequired ? '!' : ''))}`);
|
|
236
|
-
}
|
|
237
|
-
for (const member of field.members.values()) {
|
|
238
|
-
const memberTransformers = [`type: '${member.type}'`, ...commonFieldTransformers];
|
|
239
|
-
const memberFieldRequiredChecks = [];
|
|
240
|
-
for (const f of member.fields.values()) {
|
|
241
|
-
const { rawDecoder, transformer = FieldDecoder.defaultTransformer } = FlattenedFieldHelper.getFieldElements({
|
|
242
|
-
field: f,
|
|
243
|
-
context,
|
|
244
|
-
model,
|
|
245
|
-
imports,
|
|
246
|
-
enforceNullable: true,
|
|
247
|
-
});
|
|
248
|
-
const key = toName(f);
|
|
249
|
-
fieldRawDecoders.push(`"${key}": ${rawDecoder}`);
|
|
250
|
-
if (f.isRequired) {
|
|
251
|
-
memberFieldRequiredChecks.push(`nullCheck('${key}')`);
|
|
252
|
-
}
|
|
253
|
-
memberTransformers.push(`${f.name}: ${transformer('item["' + key + '"]' + (f.isRequired ? '!' : ''))}`);
|
|
254
|
-
}
|
|
255
|
-
transformerSwitchCases.push(`case '${member.type}': {
|
|
256
|
-
${memberFieldRequiredChecks.join('\n')}
|
|
257
|
-
return {
|
|
258
|
-
${memberTransformers.join(',\n')}
|
|
259
|
-
}
|
|
260
|
-
}`);
|
|
261
|
-
}
|
|
262
|
-
return `
|
|
263
|
-
export const ${codecDefinition.decoder.rawInputValidation.name} = z.object({
|
|
264
|
-
${fieldRawDecoders.join(',\n')}
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
export function ${codecDefinition.decoder.transformer.name}(item: ${codecDefinition.decoder.rawInputType.name}, ctx: z.RefinementCtx): ${field.type} {
|
|
268
|
-
try {
|
|
269
|
-
const nullCheck = (fieldName: keyof ${codecDefinition.decoder.rawInputType.name}) => {
|
|
270
|
-
if (item[fieldName] === null) {
|
|
271
|
-
const message = \`Field \${fieldName} is required but null!\`
|
|
272
|
-
ctx.addIssue({ code: z.ZodIssueCode.custom, message, path: [fieldName] })
|
|
273
|
-
throw new Error(message)
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
${commonFieldRequiredChecks.join('\n')}
|
|
278
|
-
switch (item["${discriminatorKey}"]) {
|
|
279
|
-
${transformerSwitchCases.join('\n')}
|
|
280
|
-
default: {
|
|
281
|
-
const message = \`Field ${field.name} is not a valid enum value!\`
|
|
282
|
-
ctx.addIssue({ code: z.ZodIssueCode.custom, message, path: ['${field.name}'] })
|
|
283
|
-
throw new Error(message)
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
} catch {
|
|
287
|
-
return z.NEVER
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Decoder that parses the flattened object and transforms it to the ${field.type} discriminated union.
|
|
293
|
-
*/
|
|
294
|
-
export const ${codecDefinition.decoder.zodDecoder.name} = ${codecDefinition.decoder.rawInputValidation.name}.transform(${codecDefinition.decoder.transformer.name})
|
|
295
|
-
`;
|
|
296
|
-
}
|
|
297
|
-
//# sourceMappingURL=discriminated-union.decoder.generator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"discriminated-union.decoder.generator.js","sourceRoot":"","sources":["../../src/decoders/discriminated-union.decoder.generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,8EAgDC;AAhGD,6DAA8C;AAU9C,mFAAoE;AACpE,qEAAsD;AAgBtD;;GAEG;AACH,SAAS,iBAAiB,CAAC,KAAqC;IAC9D,sBAAsB;IACtB,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;QAC5C,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC1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M,CAAC,IAAI;UAC1C,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC;;UAEpC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC;;MAElC,CAAC,CAAA;IACL,CAAC;IAED,OAAO;eACM,eAAe,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI;MACxD,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC;;;kBAGhB,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,UAAU,eAAe,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,4BAA4B,KAAK,CAAC,IAAI;;0CAEzG,eAAe,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI;;;;;;;;MAQ7E,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC;oBACtB,gBAAgB;QAC5B,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC;;kCAEP,KAAK,CAAC,IAAI;uEAC2B,KAAK,CAAC,IAAI;;;;;;;;;;uEAUV,KAAK,CAAC,IAAI;;eAElE,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,MAAM,eAAe,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,cAAc,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI;CAChK,CAAA;AACD,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { FieldDiscriminatedUnion } from '@postxl/schema';
|
|
2
|
-
import { DiscriminatedUnionType } from '../../../types';
|
|
3
|
-
import { ContextResult } from '../../forms.generator';
|
|
4
|
-
export type GenerateDiscriminatedUnionFieldsArguments = {
|
|
5
|
-
discriminatedUnion: {
|
|
6
|
-
type: DiscriminatedUnionType;
|
|
7
|
-
field: FieldDiscriminatedUnion;
|
|
8
|
-
};
|
|
9
|
-
context: ContextResult;
|
|
10
|
-
};
|
|
11
|
-
export declare function generateDiscriminatedUnionFields({ discriminatedUnion, context, }: GenerateDiscriminatedUnionFieldsArguments): string;
|
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateDiscriminatedUnionFields = generateDiscriminatedUnionFields;
|
|
4
|
-
const generator_1 = require("@postxl/generator");
|
|
5
|
-
const utils_1 = require("@postxl/utils");
|
|
6
|
-
// Tanstack form has this notion of 'nested' forms that might be worth
|
|
7
|
-
// exploring in the future:
|
|
8
|
-
//
|
|
9
|
-
// https://tanstack.com/form/latest/docs/framework/react/guides/form-composition#breaking-big-forms-into-smaller-pieces
|
|
10
|
-
//
|
|
11
|
-
// The way the docs talk about this makes it seem like its a requirement to use
|
|
12
|
-
// their `createFormHook` utility but I don't have time to work out how that works
|
|
13
|
-
// so for now we're just using the standard `useForm` hook.
|
|
14
|
-
function generateDiscriminatedUnionFields({ discriminatedUnion, context, }) {
|
|
15
|
-
const imports = new generator_1.ImportGenerator({ path: '' });
|
|
16
|
-
imports.addImports({
|
|
17
|
-
[(0, generator_1.toPackageName)('@tanstack/react-form')]: [(0, generator_1.toFunctionName)('useForm')],
|
|
18
|
-
[(0, generator_1.toPackageName)('react')]: [(0, generator_1.toFunctionName)('useState')],
|
|
19
|
-
[(0, generator_1.toPackageName)('zod')]: [(0, generator_1.toFunctionName)('z')],
|
|
20
|
-
[discriminatedUnion.type.type.location]: [discriminatedUnion.type.type.name],
|
|
21
|
-
[(0, generator_1.toPackageName)('@postxl/ui-components')]: [
|
|
22
|
-
(0, generator_1.toClassName)('Field'),
|
|
23
|
-
(0, generator_1.toClassName)('FieldError'),
|
|
24
|
-
(0, generator_1.toClassName)('FieldGroup'),
|
|
25
|
-
(0, generator_1.toClassName)('FieldLabel'),
|
|
26
|
-
(0, generator_1.toClassName)('FieldLegend'),
|
|
27
|
-
(0, generator_1.toClassName)('FieldSet'),
|
|
28
|
-
(0, generator_1.toClassName)('Select'),
|
|
29
|
-
(0, generator_1.toClassName)('SelectContent'),
|
|
30
|
-
(0, generator_1.toClassName)('SelectItem'),
|
|
31
|
-
(0, generator_1.toClassName)('SelectTrigger'),
|
|
32
|
-
(0, generator_1.toClassName)('SelectValue'),
|
|
33
|
-
],
|
|
34
|
-
});
|
|
35
|
-
const commonFields = Array.from(discriminatedUnion.field.commonFields.values().map((field) => generateFormField({ context, imports, field })));
|
|
36
|
-
const discriminatedFields = new Map(discriminatedUnion.field.members
|
|
37
|
-
.entries()
|
|
38
|
-
.map(([discriminant, member]) => [
|
|
39
|
-
discriminant,
|
|
40
|
-
Array.from(member.fields.values().map((field) => generateFormField({ context, imports, field }))),
|
|
41
|
-
]));
|
|
42
|
-
return `
|
|
43
|
-
${imports.generate()}
|
|
44
|
-
|
|
45
|
-
export type ${discriminatedUnion.type.type.name}FieldProps = Readonly<{
|
|
46
|
-
value: ${discriminatedUnion.type.type.name}FieldInput | null;
|
|
47
|
-
onChange: (value: ${discriminatedUnion.type.type.name} ) => void;
|
|
48
|
-
label: string
|
|
49
|
-
}>
|
|
50
|
-
|
|
51
|
-
const zCommonFields = {
|
|
52
|
-
${commonFields.map((field) => `${field.key}: ${field.schema},`).join('\n ')}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const schema = z.discriminatedUnion("${discriminatedUnion.field.discriminatorFieldName}", [
|
|
56
|
-
${Array.from(discriminatedFields.entries())
|
|
57
|
-
.map(([discriminant, fields]) => `z.object({ ...zCommonFields,
|
|
58
|
-
${discriminatedUnion.field.discriminatorFieldName}: z.literal('${discriminant}'),
|
|
59
|
-
${fields.map((field) => `${field.key}: ${field.schema},`).join('\n ')}
|
|
60
|
-
})`)
|
|
61
|
-
.join(',\n ')}
|
|
62
|
-
])
|
|
63
|
-
|
|
64
|
-
export const z${discriminatedUnion.type.type.name}Field = schema
|
|
65
|
-
|
|
66
|
-
type ${discriminatedUnion.type.type.name}FieldInput = z.input<typeof schema>
|
|
67
|
-
|
|
68
|
-
const defaultValues = {
|
|
69
|
-
${[
|
|
70
|
-
...commonFields,
|
|
71
|
-
{
|
|
72
|
-
key: discriminatedUnion.field.discriminatorFieldName,
|
|
73
|
-
defaultValue: `'${Array.from(discriminatedUnion.field.members.keys())[0]}'`,
|
|
74
|
-
},
|
|
75
|
-
...Array.from(discriminatedFields.values())[0],
|
|
76
|
-
]
|
|
77
|
-
.map((field) => `${field.key}: ${field.defaultValue},`)
|
|
78
|
-
.join('\n ')}
|
|
79
|
-
} as ${discriminatedUnion.type.type.name}FieldInput
|
|
80
|
-
|
|
81
|
-
export const z${discriminatedUnion.type.type.name}DefaultValues = defaultValues
|
|
82
|
-
|
|
83
|
-
export function ${discriminatedUnion.type.type.name}Field(
|
|
84
|
-
{ value, onChange, label }: ${discriminatedUnion.type.type.name}FieldProps
|
|
85
|
-
) {
|
|
86
|
-
const [${discriminatedUnion.field.discriminatorFieldName}, set${(0, utils_1.toPascalCase)(discriminatedUnion.field.discriminatorFieldName)}] =
|
|
87
|
-
useState(value?.${discriminatedUnion.field.discriminatorFieldName} ?? null)
|
|
88
|
-
|
|
89
|
-
const form = useForm({
|
|
90
|
-
defaultValues: value ?? defaultValues,
|
|
91
|
-
validators: {
|
|
92
|
-
// This first validator is the actual zod schema validation for the fieldset.
|
|
93
|
-
onChange: schema,
|
|
94
|
-
onChangeAsyncDebounceMs: 50,
|
|
95
|
-
// This second 'async' validator actually just notifies the parent form
|
|
96
|
-
// of changes. This is actually a hack really, we should work out proper
|
|
97
|
-
// nested forms as per the tanstack form docs.
|
|
98
|
-
onChangeAsync: ({ value }) => {
|
|
99
|
-
onChange(schema.parse(value))
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<FieldSet>
|
|
106
|
-
<FieldLegend>{label}</FieldLegend>
|
|
107
|
-
<FieldGroup>
|
|
108
|
-
${commonFields.map((field) => field.formField).join('\n ')}
|
|
109
|
-
</FieldGroup>
|
|
110
|
-
|
|
111
|
-
<Select value={${discriminatedUnion.field.discriminatorFieldName} ?? undefined} onValueChange={(value: ${discriminatedUnion.type.type.name}['${discriminatedUnion.field.discriminatorFieldName}']) => {
|
|
112
|
-
set${(0, utils_1.toPascalCase)(discriminatedUnion.field.discriminatorFieldName)}(value)
|
|
113
|
-
form.setFieldValue('${discriminatedUnion.field.discriminatorFieldName}', value)
|
|
114
|
-
}}>
|
|
115
|
-
<SelectTrigger>
|
|
116
|
-
{${discriminatedUnion.field.discriminatorFieldName} ?? <SelectValue />}
|
|
117
|
-
</SelectTrigger>
|
|
118
|
-
|
|
119
|
-
<SelectContent>
|
|
120
|
-
${Array.from(discriminatedUnion.field.members.keys())
|
|
121
|
-
.map((discriminant) => `
|
|
122
|
-
<SelectItem key="${discriminant}" value="${discriminant}">
|
|
123
|
-
${discriminant}
|
|
124
|
-
</SelectItem>
|
|
125
|
-
`)
|
|
126
|
-
.join('')}
|
|
127
|
-
</SelectContent>
|
|
128
|
-
</Select>
|
|
129
|
-
|
|
130
|
-
{(() => {
|
|
131
|
-
switch (${discriminatedUnion.field.discriminatorFieldName}) {
|
|
132
|
-
${Array.from(discriminatedFields.entries())
|
|
133
|
-
.map(([discriminant, fields]) => `
|
|
134
|
-
case '${discriminant}':
|
|
135
|
-
return ${fields.length === 0
|
|
136
|
-
? 'null'
|
|
137
|
-
: `(<FieldGroup>${fields.map((field) => field.formField).join('\n')}</FieldGroup>)`}
|
|
138
|
-
`)
|
|
139
|
-
.join('')}
|
|
140
|
-
|
|
141
|
-
default:
|
|
142
|
-
return null
|
|
143
|
-
}
|
|
144
|
-
})()}
|
|
145
|
-
</FieldSet>
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
`;
|
|
149
|
-
}
|
|
150
|
-
function generateFormFieldCode(field, input) {
|
|
151
|
-
return `
|
|
152
|
-
<form.Field name="${field.name}">
|
|
153
|
-
{(field) => {
|
|
154
|
-
const isInvalid = field.state.meta.isTouched && !field.state.meta.isValid
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
<Field data-invalid={isInvalid}>
|
|
158
|
-
<FieldLabel htmlFor={field.name}>
|
|
159
|
-
${field.label}
|
|
160
|
-
</FieldLabel>
|
|
161
|
-
|
|
162
|
-
${input}
|
|
163
|
-
|
|
164
|
-
{isInvalid && <FieldError errors={field.state.meta.errors} />}
|
|
165
|
-
</Field>
|
|
166
|
-
)
|
|
167
|
-
}}
|
|
168
|
-
</form.Field>
|
|
169
|
-
`;
|
|
170
|
-
}
|
|
171
|
-
function generateFormField({ context, imports, field, }) {
|
|
172
|
-
switch (field.kind) {
|
|
173
|
-
case 'id':
|
|
174
|
-
throw new Error('Unreachable');
|
|
175
|
-
case 'scalar':
|
|
176
|
-
return generateFormField_Scalar({ context, imports, field });
|
|
177
|
-
case 'enum':
|
|
178
|
-
return generateFormField_Enum({ context, imports, field });
|
|
179
|
-
case 'relation':
|
|
180
|
-
return generateFormField_Relation({ context, imports, field });
|
|
181
|
-
case 'json':
|
|
182
|
-
return generateFormField_Json(field);
|
|
183
|
-
default:
|
|
184
|
-
throw new utils_1.ExhaustiveSwitchCheck(field);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function generateFormField_Json(_field) {
|
|
188
|
-
throw new Error('JSON fields in discriminated unions are not supported yet.');
|
|
189
|
-
}
|
|
190
|
-
function generateFormField_Scalar({ imports, field, }) {
|
|
191
|
-
switch (field.type) {
|
|
192
|
-
case 'string':
|
|
193
|
-
imports.addImport({
|
|
194
|
-
from: (0, generator_1.toPackageName)('@postxl/ui-components'),
|
|
195
|
-
items: [(0, generator_1.toClassName)('Input')],
|
|
196
|
-
});
|
|
197
|
-
return {
|
|
198
|
-
key: field.name,
|
|
199
|
-
schema: `z.string()${field.isRequired ? '' : '.nullable()'}`,
|
|
200
|
-
defaultValue: field.defaultValue !== undefined ? JSON.stringify(field.defaultValue) : `''`,
|
|
201
|
-
formField: generateFormFieldCode(field, `
|
|
202
|
-
<Input
|
|
203
|
-
id={field.name}
|
|
204
|
-
name={field.name}
|
|
205
|
-
value={${field.isRequired ? 'field.state.value' : 'field.state.value ?? ""'}}
|
|
206
|
-
onBlur={field.handleBlur}
|
|
207
|
-
onChange={(e) => field.handleChange(e.target.value)}
|
|
208
|
-
aria-invalid={isInvalid}
|
|
209
|
-
autoComplete="off"
|
|
210
|
-
/>
|
|
211
|
-
`),
|
|
212
|
-
};
|
|
213
|
-
case 'number':
|
|
214
|
-
imports.addImport({
|
|
215
|
-
from: (0, generator_1.toPackageName)('@postxl/ui-components'),
|
|
216
|
-
items: [(0, generator_1.toClassName)('Input')],
|
|
217
|
-
});
|
|
218
|
-
return {
|
|
219
|
-
key: field.name,
|
|
220
|
-
schema: `z.number()${field.isRequired ? '' : '.nullable()'}`,
|
|
221
|
-
defaultValue: field.defaultValue !== undefined ? `${field.defaultValue}` : `0`,
|
|
222
|
-
formField: generateFormFieldCode(field, `
|
|
223
|
-
<Input
|
|
224
|
-
type="number"
|
|
225
|
-
id={field.name}
|
|
226
|
-
name={field.name}
|
|
227
|
-
value={${field.isRequired ? 'field.state.value' : 'field.state.value ?? ""'}}
|
|
228
|
-
onBlur={field.handleBlur}
|
|
229
|
-
onChange={(e) => field.handleChange(e.target.valueAsNumber)}
|
|
230
|
-
aria-invalid={isInvalid}
|
|
231
|
-
autoComplete="off"
|
|
232
|
-
/>
|
|
233
|
-
`),
|
|
234
|
-
};
|
|
235
|
-
case 'boolean':
|
|
236
|
-
imports.addImport({
|
|
237
|
-
from: (0, generator_1.toPackageName)('@postxl/ui-components'),
|
|
238
|
-
items: [(0, generator_1.toClassName)('Checkbox')],
|
|
239
|
-
});
|
|
240
|
-
return {
|
|
241
|
-
key: field.name,
|
|
242
|
-
schema: `z.boolean()${field.isRequired ? '' : '.nullable()'}`,
|
|
243
|
-
defaultValue: field.defaultValue !== undefined ? `${field.defaultValue}` : `false`,
|
|
244
|
-
formField: generateFormFieldCode(field, `
|
|
245
|
-
<Checkbox
|
|
246
|
-
id={field.name}
|
|
247
|
-
name={field.name}
|
|
248
|
-
checked={${field.isRequired ? 'field.state.value' : '!!field.state.value'}}
|
|
249
|
-
onBlur={field.handleBlur}
|
|
250
|
-
onCheckedChange={(checked) => field.handleChange(!!checked)}
|
|
251
|
-
aria-invalid={isInvalid}
|
|
252
|
-
/>
|
|
253
|
-
`),
|
|
254
|
-
};
|
|
255
|
-
case 'Date':
|
|
256
|
-
return {
|
|
257
|
-
key: field.name,
|
|
258
|
-
schema: `z.date()${field.isRequired ? '' : '.nullable()'}`,
|
|
259
|
-
defaultValue: field.defaultValue !== undefined
|
|
260
|
-
? `new Date(${JSON.stringify(field.defaultValue)})`
|
|
261
|
-
: `${field.isRequired ? 'new Date()' : 'null'}`,
|
|
262
|
-
formField: generateFormFieldCode(field, `
|
|
263
|
-
Not implemented yet
|
|
264
|
-
`),
|
|
265
|
-
};
|
|
266
|
-
default:
|
|
267
|
-
throw new utils_1.ExhaustiveSwitchCheck(field);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
function generateFormField_Enum({ context, imports, field, }) {
|
|
271
|
-
const enum_ = context.enums.get(field.enumName);
|
|
272
|
-
imports.add(enum_.inputs.select);
|
|
273
|
-
return {
|
|
274
|
-
key: field.name,
|
|
275
|
-
schema: `z.enum([${Array.from(enum_.members.values())
|
|
276
|
-
.map((v) => `'${v.value}'`)
|
|
277
|
-
.join(', ')}])${field.isRequired ? '' : '.nullable()'}`,
|
|
278
|
-
defaultValue: field.isRequired ? `'${Array.from(enum_.members.values())[0]?.value ?? 'null'}'` : `null`,
|
|
279
|
-
formField: generateFormFieldCode(field, `
|
|
280
|
-
<${enum_.inputs.select.name}
|
|
281
|
-
name={field.name}
|
|
282
|
-
value={field.state.value}
|
|
283
|
-
onValueChange={(value) => {
|
|
284
|
-
field.handleBlur()
|
|
285
|
-
field.handleChange(value)}
|
|
286
|
-
}
|
|
287
|
-
aria-invalid={isInvalid}
|
|
288
|
-
/>
|
|
289
|
-
`),
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
function generateFormField_Relation({ context, imports, field, }) {
|
|
293
|
-
const model = context.models.get(field.referencedModelName);
|
|
294
|
-
imports.add(model.forms.inputs.select).add(model.types.id.toBranded).add(model.types.id.decoder);
|
|
295
|
-
return {
|
|
296
|
-
key: field.name,
|
|
297
|
-
schema: `${model.types.id.decoder.name}${field.isRequired ? '' : '.nullable()'}`,
|
|
298
|
-
defaultValue: field.isRequired ? `''` : `null`,
|
|
299
|
-
formField: generateFormFieldCode(field, `
|
|
300
|
-
<${model.forms.inputs.select.name}
|
|
301
|
-
name={field.name}
|
|
302
|
-
value={${field.isRequired
|
|
303
|
-
? `${model.types.id.toBranded.name}(field.state.value)`
|
|
304
|
-
: `field.state.value === null ? null : ${model.types.id.toBranded.name}(field.state.value)`}}
|
|
305
|
-
label={(item) => ${model.labelField.isRequired ? `item.${model.labelField.name}` : `String(item.${model.labelField.name} ?? '')`}}
|
|
306
|
-
onValueChange={(value) => {
|
|
307
|
-
field.handleBlur()
|
|
308
|
-
field.handleChange(value.id)}
|
|
309
|
-
}
|
|
310
|
-
aria-invalid={isInvalid}
|
|
311
|
-
/>
|
|
312
|
-
`),
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
//# sourceMappingURL=fields.generator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fields.generator.js","sourceRoot":"","sources":["../../../../src/frontend-forms/generators/discriminated-union/fields.generator.ts"],"names":[],"mappings":";;AA6BA,4EA0JC;AAvLD,iDAA+F;AAU/F,yCAAmE;AAUnE,sEAAsE;AACtE,2BAA2B;AAC3B,EAAE;AACF,yHAAyH;AACzH,EAAE;AACF,+EAA+E;AAC/E,kFAAkF;AAClF,2DAA2D;AAE3D,SAAgB,gCAAgC,CAAC,EAC/C,kBAAkB,EAClB,OAAO,GACmC;IAC1C,MAAM,OAAO,GAAG,IAAI,2BAAe,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAA;IAEjD,OAAO,CAAC,UAAU,CAAC;QACjB,CAAC,IAAA,yBAAa,EAAC,sBAAsB,CAAC,CAAC,EA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ateDiscriminatedUnionInputsArguments = {
|
|
4
|
-
type: DiscriminatedUnionType;
|
|
5
|
-
field: FieldDiscriminatedUnion;
|
|
6
|
-
};
|
|
7
|
-
export declare function generateDiscriminatedUnionInputs({ type, field }: GenerateDiscriminatedUnionInputsArguments): string;
|