@postxl/generator 0.54.0 → 0.56.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/generator.js +1 -1
- package/dist/generators/indices/businesslogic-actiontypes.generator.js +18 -7
- package/dist/generators/indices/businesslogic-update-index.generator.js +3 -1
- package/dist/generators/indices/dispatcher-service.generator.js +2 -2
- package/dist/generators/indices/importexport-exporter-class.generator.js +41 -4
- package/dist/generators/indices/importexport-import-service.generator.js +2 -2
- package/dist/generators/indices/seed-migration.generator.js +9 -7
- package/dist/generators/indices/testdata-service.generator.js +9 -3
- package/dist/generators/models/businesslogic-update.generator.js +162 -218
- package/dist/generators/models/businesslogic-view.generator.js +47 -10
- package/dist/generators/models/route.generator.js +28 -31
- package/dist/generators/models/types.generator.js +18 -99
- package/dist/lib/exports.d.ts +4 -0
- package/dist/lib/exports.js +38 -8
- package/dist/lib/meta.d.ts +15 -52
- package/dist/lib/meta.js +6 -15
- package/dist/lib/schema/schema.d.ts +10 -6
- package/dist/lib/schema/types.d.ts +5 -5
- package/dist/lib/utils/jsdoc.d.ts +5 -0
- package/dist/lib/utils/jsdoc.js +22 -1
- package/dist/prisma/parse.js +49 -25
- package/package.json +1 -1
package/dist/prisma/parse.js
CHANGED
|
@@ -136,34 +136,43 @@ function parseModel({ dmmfModel, enums, models, config, }) {
|
|
|
136
136
|
if (core.attributes.ignore) {
|
|
137
137
|
return undefined;
|
|
138
138
|
}
|
|
139
|
-
// NOTE: We assume that each relation may only reference one field.
|
|
140
|
-
// we can "relate" a given relation to a scalar field
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
|
|
139
|
+
// NOTE: We assume that each relation may only reference one field.
|
|
140
|
+
// Because of this, we can "relate" a given relation to a scalar field
|
|
141
|
+
// used as a foreign key.
|
|
142
|
+
//
|
|
143
|
+
// Since Prisma doesn't mark foreign-key fields as relations,
|
|
144
|
+
// we need to preprocess relations and then figure out which scalar
|
|
145
|
+
// fields are actually foreign-keys.
|
|
146
|
+
const referencedModels = {};
|
|
147
|
+
/**
|
|
148
|
+
* A map of models that are referenced in any way in the relations.
|
|
149
|
+
*/
|
|
150
|
+
const relatedModels = {};
|
|
144
151
|
for (const dmmfField of dmmfModel.fields) {
|
|
145
|
-
if (dmmfField.kind !== 'object' ||
|
|
146
|
-
!dmmfField.relationName ||
|
|
147
|
-
!dmmfField.relationFromFields ||
|
|
148
|
-
!dmmfField.relationToFields) {
|
|
152
|
+
if (dmmfField.kind !== 'object' || !dmmfField.relationName) {
|
|
149
153
|
continue;
|
|
150
154
|
}
|
|
151
|
-
if (dmmfField.relationFromFields.length > 1) {
|
|
152
|
-
(0, error_1.throwError)(`Field ${highlight(`${dmmfModel.name}.${dmmfField.relationName}`)} has more than one "from" field`);
|
|
153
|
-
}
|
|
154
155
|
const referencedModel = models.find((m) => m.sourceName === dmmfField.type);
|
|
155
156
|
if (!referencedModel) {
|
|
156
157
|
(0, error_1.throwError)(`Field ${highlight(`${dmmfModel.name}.${dmmfField.name}`)} references unknown model ${highlight(dmmfField.type)}.`);
|
|
157
158
|
}
|
|
159
|
+
if (!dmmfField.relationFromFields || dmmfField.relationFromFields.length === 0) {
|
|
160
|
+
// NOTE: This field has no foreign-key values in this model so it must be a back-relation.
|
|
161
|
+
relatedModels[dmmfField.type] = referencedModel;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (dmmfField.relationFromFields.length > 1) {
|
|
165
|
+
(0, error_1.throwError)(`Field ${highlight(`${dmmfModel.name}.${dmmfField.relationName}`)} has more than one "from" field`);
|
|
166
|
+
}
|
|
158
167
|
if (dmmfField.relationOnDelete && dmmfField.relationOnDelete !== 'NoAction') {
|
|
159
168
|
(0, error_1.throwError)(`Investigate model ${highlight(dmmfModel.name)}: "onDelete" attribute for relationship ${highlight(dmmfField.relationName)} must be "NoAction": any deletes must be handled in the application layer, e.g. to update repository and search caches!`);
|
|
160
169
|
}
|
|
161
170
|
// NOTE: At this point, we only have the `ModelCore`. After all models are parsed, we need to updated
|
|
162
171
|
// the relations with the full `Model`. This is done in the `linkModels` function.
|
|
163
|
-
|
|
172
|
+
referencedModels[dmmfField.relationFromFields[0]] = referencedModel;
|
|
164
173
|
}
|
|
165
174
|
const relationFields = dmmfModel.fields
|
|
166
|
-
.filter((f) => f.kind === 'object' && f.relationToFields
|
|
175
|
+
.filter((f) => { var _a; return f.kind === 'object' && ((_a = f.relationToFields) === null || _a === void 0 ? void 0 : _a.length) === 1; })
|
|
167
176
|
.reduce((acc, f) => {
|
|
168
177
|
if (f.relationFromFields && f.relationFromFields[0]) {
|
|
169
178
|
acc[f.relationFromFields[0]] = f;
|
|
@@ -171,9 +180,14 @@ function parseModel({ dmmfModel, enums, models, config, }) {
|
|
|
171
180
|
return acc;
|
|
172
181
|
}, {});
|
|
173
182
|
const fields = dmmfModel.fields
|
|
174
|
-
.filter((dmmfField) =>
|
|
175
|
-
|
|
176
|
-
|
|
183
|
+
.filter((dmmfField) => {
|
|
184
|
+
// NOTE: This is a relation field that we'll handle when we process its foreign-key. If it's a back relation
|
|
185
|
+
// then it won't have a foreign-key and we simply ignore it.
|
|
186
|
+
if (dmmfField.kind === 'object') {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
return true;
|
|
190
|
+
})
|
|
177
191
|
.map((dmmfField) => {
|
|
178
192
|
const attributes = (0, attributes_1.getFieldAttributes)(dmmfField);
|
|
179
193
|
const fieldName = highlight(`${dmmfModel.name}.${dmmfField.name}`);
|
|
@@ -187,17 +201,19 @@ function parseModel({ dmmfModel, enums, models, config, }) {
|
|
|
187
201
|
schemaType: dmmfField.type,
|
|
188
202
|
};
|
|
189
203
|
// NOTE: We mark scalar fields which are used in relations as relation fields by Purple Schema standards.
|
|
190
|
-
if (dmmfField.name in
|
|
191
|
-
const refModel =
|
|
204
|
+
if (dmmfField.name in referencedModels) {
|
|
205
|
+
const refModel = referencedModels[dmmfField.name];
|
|
192
206
|
const refField = relationFields[dmmfField.name];
|
|
193
207
|
if (!refField) {
|
|
194
208
|
(0, error_1.throwError)(`${fieldName}: Relation field ${highlight(dmmfField.name)} not found.`);
|
|
195
209
|
}
|
|
196
|
-
|
|
210
|
+
const _field = Object.assign(Object.assign({ kind: 'relation' }, shared), { relationFieldName: Types.toFieldName(refField.name), unbrandedTypeName: getTsTypeForId(dmmfField), relationToModel: refModel });
|
|
211
|
+
return _field;
|
|
197
212
|
}
|
|
198
213
|
if (dmmfField.isId) {
|
|
199
214
|
const isGeneratedField = isAutoIncrementField(dmmfField) || isUUIDField(dmmfField);
|
|
200
|
-
|
|
215
|
+
const _field = Object.assign(Object.assign({ kind: 'id' }, shared), { isUnique: isUniqueField(dmmfField), isGenerated: isGeneratedField, unbrandedTypeName: getTsTypeForId(dmmfField), model: core });
|
|
216
|
+
return _field;
|
|
201
217
|
}
|
|
202
218
|
if (dmmfField.kind === 'scalar') {
|
|
203
219
|
let validation = undefined;
|
|
@@ -210,14 +226,16 @@ function parseModel({ dmmfModel, enums, models, config, }) {
|
|
|
210
226
|
if (dmmfField.type === 'Float') {
|
|
211
227
|
validation = { type: 'float' };
|
|
212
228
|
}
|
|
213
|
-
|
|
229
|
+
const _field = Object.assign(Object.assign({ kind: 'scalar', validation }, shared), { isUnique: isUniqueField(dmmfField), isGenerated: isAutoIncrementField(dmmfField), tsTypeName: getTsTypeForScalar(dmmfField) });
|
|
230
|
+
return _field;
|
|
214
231
|
}
|
|
215
232
|
if (dmmfField.kind === 'enum') {
|
|
216
233
|
const fieldEnumDef = enums.find((e) => e.sourceName === dmmfField.type);
|
|
217
234
|
if (!fieldEnumDef) {
|
|
218
235
|
(0, error_1.throwError)(`${fieldName}: Field references unknown enum ${highlight(dmmfField.type)}.`);
|
|
219
236
|
}
|
|
220
|
-
|
|
237
|
+
const _field = Object.assign(Object.assign({ kind: 'enum' }, shared), { typeName: getTsTypeForEnum(dmmfField), enumerator: fieldEnumDef });
|
|
238
|
+
return _field;
|
|
221
239
|
}
|
|
222
240
|
(0, error_1.throwError)(`${fieldName} is not scalar, enum nor relation.`);
|
|
223
241
|
})
|
|
@@ -228,7 +246,7 @@ function parseModel({ dmmfModel, enums, models, config, }) {
|
|
|
228
246
|
nameField,
|
|
229
247
|
fields,
|
|
230
248
|
createdAtField,
|
|
231
|
-
updatedAtField });
|
|
249
|
+
updatedAtField, relatedModels: Object.values(relatedModels) });
|
|
232
250
|
}
|
|
233
251
|
/**
|
|
234
252
|
* Checks that there is exactly one id field and that there is at most one default field.
|
|
@@ -290,7 +308,13 @@ function validateFields({ fields, model: { name } }) {
|
|
|
290
308
|
if (!idField) {
|
|
291
309
|
(0, error_1.throwError)(`Model ${highlight(name)} does not have an id field`);
|
|
292
310
|
}
|
|
293
|
-
return {
|
|
311
|
+
return {
|
|
312
|
+
idField,
|
|
313
|
+
defaultField,
|
|
314
|
+
nameField: (_a = labelField !== null && labelField !== void 0 ? labelField : nameField) !== null && _a !== void 0 ? _a : idField,
|
|
315
|
+
createdAtField,
|
|
316
|
+
updatedAtField,
|
|
317
|
+
};
|
|
294
318
|
}
|
|
295
319
|
function isAutoIncrementField(fieldDmmf) {
|
|
296
320
|
if (fieldDmmf.default === undefined) {
|