@postxl/generator 0.44.4 → 0.44.5
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/generators/models/react.generator/index.js +2 -8
- package/dist/generators/models/react.generator/library.generator.d.ts +0 -2
- package/dist/generators/models/react.generator/library.generator.js +2 -4
- package/dist/generators/models/react.generator/lookup.generator.js +2 -5
- package/dist/lib/schema/schema.d.ts +3 -2
- package/dist/prisma/parse.js +7 -9
- package/package.json +1 -1
|
@@ -23,14 +23,8 @@ function generateReactComponentsForModel({ model, meta }) {
|
|
|
23
23
|
vfs.write(`/EditModal.tsx`, (0, modals_generator_1.generateEditModalModelComponent)({ model, meta }));
|
|
24
24
|
vfs.write(`/DeleteModal.tsx`, (0, modals_generator_1.generateDeleteModalModelComponent)({ model, meta }));
|
|
25
25
|
vfs.write(`/Form.tsx`, (0, lookup_generator_1.generateModelLookupComponents)({ model, meta }));
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// component without checking that a model has a name field.
|
|
29
|
-
const hasNameField = model.nameField != null;
|
|
30
|
-
if (hasNameField) {
|
|
31
|
-
vfs.write(`/Library.tsx`, (0, library_generator_1.generateModelLibraryComponents)({ model, meta }));
|
|
32
|
-
exports.exportEverythingFromFile('./Library');
|
|
33
|
-
}
|
|
26
|
+
vfs.write(`/Library.tsx`, (0, library_generator_1.generateModelLibraryComponents)({ model, meta }));
|
|
27
|
+
exports.exportEverythingFromFile('./Library');
|
|
34
28
|
vfs.write(`/index.ts`, exports.generate());
|
|
35
29
|
return vfs;
|
|
36
30
|
}
|
|
@@ -3,8 +3,6 @@ import { Model } from '../../../lib/schema/schema';
|
|
|
3
3
|
/**
|
|
4
4
|
* Generates components that may be used to list all entries of a given data type.
|
|
5
5
|
*
|
|
6
|
-
* NOTE: Library expects that the model has a `name` field. Make sure that you don't make a dependency on
|
|
7
|
-
* this component without checking that a model has a name field.
|
|
8
6
|
*/
|
|
9
7
|
export declare function generateModelLibraryComponents({ model, meta }: {
|
|
10
8
|
model: Model;
|
|
@@ -6,8 +6,6 @@ const imports_1 = require("../../../lib/imports");
|
|
|
6
6
|
/**
|
|
7
7
|
* Generates components that may be used to list all entries of a given data type.
|
|
8
8
|
*
|
|
9
|
-
* NOTE: Library expects that the model has a `name` field. Make sure that you don't make a dependency on
|
|
10
|
-
* this component without checking that a model has a name field.
|
|
11
9
|
*/
|
|
12
10
|
function generateModelLibraryComponents({ model, meta }) {
|
|
13
11
|
const { react: { context, components }, } = meta;
|
|
@@ -21,7 +19,7 @@ function generateModelLibraryComponents({ model, meta }) {
|
|
|
21
19
|
items: [context.hookFnName, components.modals.editComponentName, components.modals.deleteComponentName],
|
|
22
20
|
from: meta.react.folderPath,
|
|
23
21
|
});
|
|
24
|
-
return `
|
|
22
|
+
return /* ts */ `
|
|
25
23
|
import React, { useState } from 'react'
|
|
26
24
|
|
|
27
25
|
import { Card } from '@components/atoms/Card'
|
|
@@ -54,7 +52,7 @@ function generateModelLibraryComponents({ model, meta }) {
|
|
|
54
52
|
<>
|
|
55
53
|
<Card
|
|
56
54
|
ref={forwardedRef}
|
|
57
|
-
title={item.name}
|
|
55
|
+
title={item.${model.nameField.name}}
|
|
58
56
|
actions={[
|
|
59
57
|
{
|
|
60
58
|
label: 'Edit',
|
|
@@ -17,11 +17,8 @@ function generateModelLookupComponents({ model, meta }) {
|
|
|
17
17
|
from: meta.types.importPath,
|
|
18
18
|
});
|
|
19
19
|
const typeName = model.typeName;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const hasNameField = model.nameField != null;
|
|
23
|
-
const tsOmittedFields = hasNameField ? `'label' | 'options' | 'loading'` : `'options' | 'loading'`;
|
|
24
|
-
const reactLabelField = hasNameField ? `label={(l) => l.name}` : '';
|
|
20
|
+
const tsOmittedFields = `'label' | 'options' | 'loading'`;
|
|
21
|
+
const reactLabelField = `label={(l) => l.${model.nameField.name}}`;
|
|
25
22
|
let description = '';
|
|
26
23
|
if (model.description) {
|
|
27
24
|
description = `
|
|
@@ -192,9 +192,10 @@ export type ModelFields = {
|
|
|
192
192
|
/**
|
|
193
193
|
* The property of the model that is used to define the name/label
|
|
194
194
|
*
|
|
195
|
-
* By default, this is maps to the `name` field
|
|
195
|
+
* By default, this is maps to the `name` field (with `id` field used as fallback in case no `name` field exists).
|
|
196
|
+
* Using the `@@Label()` attribute, other fields can be used.
|
|
196
197
|
*/
|
|
197
|
-
nameField
|
|
198
|
+
nameField: Field;
|
|
198
199
|
/**
|
|
199
200
|
* All fields of the model
|
|
200
201
|
*/
|
package/dist/prisma/parse.js
CHANGED
|
@@ -180,17 +180,18 @@ function parseModel({ dmmfModel, enums, models, config, }) {
|
|
|
180
180
|
* Checks that there is exactly one id field and that there is at most one default field.
|
|
181
181
|
*/
|
|
182
182
|
function validateFields({ fields, model: { name } }) {
|
|
183
|
+
var _a;
|
|
183
184
|
let idField = undefined;
|
|
184
185
|
let createdAtField = undefined;
|
|
185
186
|
let updatedAtField = undefined;
|
|
187
|
+
let labelField = undefined;
|
|
186
188
|
let nameField = undefined;
|
|
187
|
-
let nameFieldFallback = undefined;
|
|
188
189
|
let defaultField = undefined;
|
|
189
190
|
for (const field of fields) {
|
|
190
191
|
switch (field.kind) {
|
|
191
192
|
case 'scalar':
|
|
192
193
|
if (field.name === 'name') {
|
|
193
|
-
|
|
194
|
+
nameField = field;
|
|
194
195
|
}
|
|
195
196
|
if (field.attributes.isCreatedAt) {
|
|
196
197
|
if (createdAtField) {
|
|
@@ -224,20 +225,17 @@ function validateFields({ fields, model: { name } }) {
|
|
|
224
225
|
defaultField = field;
|
|
225
226
|
}
|
|
226
227
|
//handle name field
|
|
227
|
-
if (field.attributes.isLabel
|
|
228
|
-
if (
|
|
228
|
+
if (field.attributes.isLabel) {
|
|
229
|
+
if (labelField !== undefined) {
|
|
229
230
|
throw new Error(`❌❌❌ Model ${name} has multiple name fields`);
|
|
230
231
|
}
|
|
231
|
-
|
|
232
|
+
labelField = field;
|
|
232
233
|
}
|
|
233
234
|
}
|
|
234
235
|
if (!idField) {
|
|
235
236
|
throw new Error(`❌❌❌ Model ${name} does not have an id field`);
|
|
236
237
|
}
|
|
237
|
-
|
|
238
|
-
nameField = nameFieldFallback;
|
|
239
|
-
}
|
|
240
|
-
return { idField, defaultField, nameField, createdAtField, updatedAtField };
|
|
238
|
+
return { idField, defaultField, nameField: (_a = labelField !== null && labelField !== void 0 ? labelField : nameField) !== null && _a !== void 0 ? _a : idField, createdAtField, updatedAtField };
|
|
241
239
|
}
|
|
242
240
|
function isAutoIncrementField(fieldDmmf) {
|
|
243
241
|
if (fieldDmmf.default === undefined) {
|