@postxl/generator 0.46.0 → 0.47.1
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/README.md +20 -1
- package/dist/generator.js +66 -101
- package/dist/generators/indices/emptydatabasemigration.generator.js +3 -3
- package/dist/generators/models/react.generator/library.generator.js +4 -1
- package/dist/generators/models/react.generator/lookup.generator.js +94 -11
- package/dist/lib/meta.d.ts +2 -2
- package/dist/lib/meta.js +1 -1
- package/dist/lib/schema/schema.d.ts +1 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
# PXL Generator
|
|
2
2
|
|
|
3
|
-
A utility package that lets you move quickly and generate basic components of your app easily.
|
|
3
|
+
A utility package that lets you move quickly and generate basic components of your app easily.
|
|
4
|
+
|
|
5
|
+
#### Linking Generator to Template
|
|
6
|
+
|
|
7
|
+
To use the latest version of the generator link the local dependency using [`pnpm link`](https://pnpm.io/cli/link) command.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
# /
|
|
11
|
+
pnpm build
|
|
12
|
+
|
|
13
|
+
# /packages/manager/template/
|
|
14
|
+
pnpm link ../../generator/
|
|
15
|
+
|
|
16
|
+
# /
|
|
17
|
+
pnpm prisma generate
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
> If you've correctly linked the generator, you should see a message when running `pnpm i`.
|
|
21
|
+
|
|
22
|
+

|
package/dist/generator.js
CHANGED
|
@@ -93,7 +93,7 @@ const CONFIG_SCHEMA = zod_1.z
|
|
|
93
93
|
pathToTypes: zod_1.z.string().optional(),
|
|
94
94
|
trpcRoutesFolder: zod_1.z.string().optional(),
|
|
95
95
|
reactFolderOutput: zod_1.z.string().optional(),
|
|
96
|
-
|
|
96
|
+
prismaMigrationsFolder: zod_1.z.string().optional(),
|
|
97
97
|
randomSeed: zod_1.z
|
|
98
98
|
.string()
|
|
99
99
|
.optional()
|
|
@@ -106,31 +106,21 @@ const CONFIG_SCHEMA = zod_1.z
|
|
|
106
106
|
.transform((s) => {
|
|
107
107
|
return {
|
|
108
108
|
paths: {
|
|
109
|
-
dataLibPath: (0, types_1.toPath)(s.pathToDataLib || '
|
|
109
|
+
dataLibPath: (0, types_1.toPath)(s.pathToDataLib || './backend/libs/data/src/'),
|
|
110
110
|
cypressPath: (0, types_1.toPath)(s.pathToCypress || './e2e/cypress/'),
|
|
111
|
-
e2eLibPath: (0, types_1.toPath)(s.pathToE2ELib || './e2e/src/'),
|
|
112
|
-
importExportPath: (0, types_1.toPath)(s.pathToImportExport || 'import-export'),
|
|
113
|
-
actionsPath: (0, types_1.toPath)(s.pathToActions || 'actions'),
|
|
114
|
-
businessLogicPath: (0, types_1.toPath)(s.pathToBusinessLogic || 'business-logic'),
|
|
115
|
-
|
|
116
|
-
modelTypeDefinitionsPath: (0, types_1.toPath)(s.pathToTypes || 'types'),
|
|
117
|
-
reactFolderPath: (0, types_1.toPath)(s.reactFolderOutput || '
|
|
118
|
-
seedDataPath: (0, types_1.toPath)(s.pathToSeedData || 'seed-data'),
|
|
119
|
-
seedLibPath: (0, types_1.toPath)(s.pathToSeedLib || 'seed'),
|
|
120
|
-
trpcRoutesFolderPath: (0, types_1.toPath)(s.trpcRoutesFolder || 'trpc'),
|
|
111
|
+
e2eLibPath: (0, types_1.toPath)(s.pathToE2ELib || './backend/libs/e2e/src/'),
|
|
112
|
+
importExportPath: (0, types_1.toPath)(s.pathToImportExport || './backend/libs/import-export/src/'),
|
|
113
|
+
actionsPath: (0, types_1.toPath)(s.pathToActions || './backend/libs/actions/src/'),
|
|
114
|
+
businessLogicPath: (0, types_1.toPath)(s.pathToBusinessLogic || './backend/libs/business-logic/src/'),
|
|
115
|
+
prismaMigrationsFolderPath: (0, types_1.toPath)(s.prismaMigrationsFolder || './migrations'),
|
|
116
|
+
modelTypeDefinitionsPath: (0, types_1.toPath)(s.pathToTypes || './backend/libs/types/src/'),
|
|
117
|
+
reactFolderPath: (0, types_1.toPath)(s.reactFolderOutput || './web/src/components/'),
|
|
118
|
+
seedDataPath: (0, types_1.toPath)(s.pathToSeedData || './backend/seed-data/src/'),
|
|
119
|
+
seedLibPath: (0, types_1.toPath)(s.pathToSeedLib || './backend/libs/seed/src/'),
|
|
120
|
+
trpcRoutesFolderPath: (0, types_1.toPath)(s.trpcRoutesFolder || './backend/libs/trpc/src/routes/'),
|
|
121
121
|
},
|
|
122
122
|
randomSeed: s.randomSeed,
|
|
123
123
|
force: s.force,
|
|
124
|
-
disableGenerators: {
|
|
125
|
-
actions: s.pathToActions === undefined,
|
|
126
|
-
businessLogic: s.pathToBusinessLogic === undefined,
|
|
127
|
-
data: s.pathToDataLib === undefined,
|
|
128
|
-
importExport: s.pathToImportExport === undefined,
|
|
129
|
-
react: s.reactFolderOutput === undefined,
|
|
130
|
-
seed: s.pathToSeedLib === undefined,
|
|
131
|
-
trpc: s.trpcRoutesFolder === undefined,
|
|
132
|
-
types: s.pathToTypes === undefined,
|
|
133
|
-
},
|
|
134
124
|
userType: (0, types_1.toTypeName)(`User`),
|
|
135
125
|
};
|
|
136
126
|
});
|
|
@@ -173,100 +163,75 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
173
163
|
for (const model of models) {
|
|
174
164
|
const meta = (0, meta_1.getModelMetadata)({ model });
|
|
175
165
|
// Types
|
|
176
|
-
|
|
177
|
-
generated.write(`/${meta.types.filePath}.ts`, (0, types_generator_3.generateModelTypes)({ model, meta }));
|
|
178
|
-
}
|
|
166
|
+
generated.write(`/${meta.types.filePath}.ts`, (0, types_generator_3.generateModelTypes)({ model, meta }));
|
|
179
167
|
// Seed
|
|
180
|
-
|
|
181
|
-
generated.write(`/${meta.seed.filePath}.ts`, (0, seed_generator_1.generateSeedModel)({ model, itemCount: 5, meta }));
|
|
182
|
-
}
|
|
168
|
+
generated.write(`/${meta.seed.filePath}.ts`, (0, seed_generator_1.generateSeedModel)({ model, itemCount: 5, meta }));
|
|
183
169
|
// Data
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
generated.write(`/${meta.e2e.dataMockerStubFilePath}.ts`, (0, stub_generator_1.generateStub)({ model, meta }));
|
|
189
|
-
}
|
|
170
|
+
generated.write(`/${meta.data.stubFilePath}.ts`, (0, stub_generator_1.generateStub)({ model, meta }));
|
|
171
|
+
generated.write(`/${meta.data.repository.filePath}.ts`, (0, repository_generator_1.generateRepository)({ model, meta }));
|
|
172
|
+
generated.write(`/${meta.data.mockRepository.filePath}.ts`, (0, repository_generator_1.generateMockRepository)({ model, meta }));
|
|
173
|
+
generated.write(`/${meta.e2e.dataMockerStubFilePath}.ts`, (0, stub_generator_1.generateStub)({ model, meta }));
|
|
190
174
|
// Import-Export
|
|
191
|
-
|
|
192
|
-
generated.write(`/${meta.importExport.decoder.filePath}.ts`, (0, importexport_decoder_generator_1.generateModelImportExportDecoder)({ model, meta, schemaMeta: (0, meta_1.getSchemaMetadata)({ config }) }));
|
|
193
|
-
}
|
|
175
|
+
generated.write(`/${meta.importExport.decoder.filePath}.ts`, (0, importexport_decoder_generator_1.generateModelImportExportDecoder)({ model, meta, schemaMeta: (0, meta_1.getSchemaMetadata)({ config }) }));
|
|
194
176
|
// Business Logic
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
generated.write(`/${meta.businessLogic.update.serviceFilePath}.ts`, (0, businesslogic_update_generator_1.generateModelBusinessLogicUpdate)({ model, meta }));
|
|
198
|
-
}
|
|
177
|
+
generated.write(`/${meta.businessLogic.view.serviceFilePath}.ts`, (0, businesslogic_view_generator_1.generateModelBusinessLogicView)({ model, meta }));
|
|
178
|
+
generated.write(`/${meta.businessLogic.update.serviceFilePath}.ts`, (0, businesslogic_update_generator_1.generateModelBusinessLogicUpdate)({ model, meta }));
|
|
199
179
|
// Routes
|
|
200
|
-
|
|
201
|
-
generated.write(`/${meta.trpc.routerFilePath}.ts`, (0, route_generator_1.generateRoute)({ model, meta }));
|
|
202
|
-
}
|
|
180
|
+
generated.write(`/${meta.trpc.routerFilePath}.ts`, (0, route_generator_1.generateRoute)({ model, meta }));
|
|
203
181
|
// React
|
|
204
|
-
|
|
205
|
-
yield generated.copy((0, react_generator_2.generateReactComponentsForModel)({ model, meta }), meta.react.folderPath);
|
|
206
|
-
}
|
|
182
|
+
yield generated.copy((0, react_generator_2.generateReactComponentsForModel)({ model, meta }), meta.react.folderPath);
|
|
207
183
|
logger.log(`- ${model.name} processed`);
|
|
208
184
|
}
|
|
209
185
|
// Generate Enums
|
|
210
186
|
for (const enumerator of enums.values()) {
|
|
211
187
|
const meta = (0, meta_1.getEnumMetadata)({ enumerator });
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
if (!config.disableGenerators.react) {
|
|
216
|
-
yield generated.copy((0, react_generator_1.generateEnumReactComponents)({ enumerator, meta }), meta.react.folderPath);
|
|
217
|
-
}
|
|
188
|
+
generated.write(`/${meta.types.filePath}.ts`, (0, types_generator_1.generateEnumType)({ enumerator, prismaClientPath, meta }));
|
|
189
|
+
yield generated.copy((0, react_generator_1.generateEnumReactComponents)({ enumerator, meta }), meta.react.folderPath);
|
|
218
190
|
}
|
|
219
191
|
// Generate Index Files and Services
|
|
220
192
|
const meta = (0, meta_1.getSchemaMetadata)({ config });
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (!config.disableGenerators.importExport) {
|
|
241
|
-
generated.write(`/${meta.importExport.types.filePath}.ts`, (0, importexport_types_generator_1.generateImportExportTypes)({ models, meta }));
|
|
242
|
-
generated.write(`/${meta.importExport.exporterClass.filePath}.ts`, (0, importexport_exporter_class_generator_1.generateImportExportExporterClass)({ models, meta }));
|
|
243
|
-
generated.write(`/${meta.importExport.importService.filePath}.ts`, (0, importexport_import_service_generator_1.generateImportExportImportService)({ models, meta }));
|
|
244
|
-
generated.write(`/${meta.importExport.decoder.indexFilePath}.ts`, (0, importexport_decoder_generator_1.generateImportExportDecoderIndex)({ models, meta }));
|
|
245
|
-
generated.write(`/${meta.importExport.decoder.fullDecoderFilePath}.ts`, (0, importexport_decoder_generator_1.generateImportExportDecoder)({ models, meta }));
|
|
246
|
-
generated.write(`/${meta.importExport.converterFunctions.filePath}.ts`, (0, importexport_convert_import_functions_generator_1.generateImportExportConvertImportFunctions)({ models, meta }));
|
|
247
|
-
}
|
|
248
|
-
if (!config.disableGenerators.actions) {
|
|
249
|
-
generated.write(`/${meta.actions.dispatcherService.filePath}.ts`, (0, dispatcher_service_generator_1.generateActionsDispatcherService)({ models, meta }));
|
|
250
|
-
}
|
|
251
|
-
if (!config.disableGenerators.businessLogic) {
|
|
252
|
-
generated.write(`/${meta.businessLogic.view.indexFilePath}.ts`, (0, businesslogic_view_index_generator_1.generateBusinessLogicViewIndex)({ models, meta }));
|
|
253
|
-
generated.write(`/${meta.businessLogic.view.moduleFilePath}.ts`, (0, businesslogic_view_module_generator_1.generateBusinessLogicViewModule)({ models, meta }));
|
|
254
|
-
generated.write(`/${meta.businessLogic.view.serviceFilePath}.ts`, (0, businesslogic_view_service_generator_1.generateBusinessLogicViewService)({ models, meta }));
|
|
255
|
-
generated.write(`/${meta.businessLogic.update.indexFilePath}.ts`, (0, businesslogic_update_index_generator_1.generateBusinessLogicUpdateIndex)({ models, meta }));
|
|
256
|
-
generated.write(`/${meta.businessLogic.update.moduleFilePath}.ts`, (0, businesslogic_update_module_generator_1.generateBusinessLogicUpdateModule)({ models, meta }));
|
|
257
|
-
generated.write(`/${meta.businessLogic.update.serviceFilePath}.ts`, (0, businesslogic_update_service_generator_1.generateBusinessLogicUpdateService)({ models, meta }));
|
|
258
|
-
generated.write(`/${meta.businessLogic.update.actionTypesFilePath}.ts`, (0, businesslogic_actiontypes_generator_1.generateBusinessLogicActionTypes)({ models, meta }));
|
|
259
|
-
}
|
|
260
|
-
if (!config.disableGenerators.seed) {
|
|
261
|
-
generated.write(`/${meta.seedData.initialMigrationFilePath}.ts`, (0, seed_migration_generator_1.generateSeedMigration)({ models, meta }));
|
|
262
|
-
generated.write(`/${meta.seedData.templateExcelFilePath}`, yield (0, seed_template_generator_1.generateSeedExcelTemplate)({ models }));
|
|
263
|
-
}
|
|
264
|
-
if (!config.disableGenerators.trpc) {
|
|
265
|
-
generated.write(`/${meta.trpc.routesFilePath}.ts`, (0, route_generator_1.generateRoutesIndex)({ models, meta }));
|
|
266
|
-
}
|
|
267
|
-
if (!config.disableGenerators.types) {
|
|
268
|
-
generated.write(`/${meta.types.indexFilePath}.ts`, (0, types_generator_2.generateTypesIndex)({ models, enums, meta }));
|
|
193
|
+
// Data
|
|
194
|
+
generated.write(`/${meta.data.dataMockModuleFilePath}.ts`, (0, datamock_module_generator_1.generateDataMockModule)({ models, meta }));
|
|
195
|
+
generated.write(`/${meta.data.dataModuleFilePath}.ts`, (0, datamodule_generator_1.generateDataModule)({ models, meta }));
|
|
196
|
+
generated.write(`/${meta.data.dataService.filePath}.ts`, (0, dataservice_generator_1.generateDataService)({ models, meta }));
|
|
197
|
+
generated.write(`/${meta.data.testDataServiceFilePath}.ts`, (0, testdata_service_generator_1.generateTestDataService)({ models, meta }));
|
|
198
|
+
generated.write(`/${meta.e2e.dataMocker.filePath}.ts`, (0, datamocker_generator_1.generateDataMocker)({ models, meta }));
|
|
199
|
+
generated.write(`/${meta.e2e.selectorsFilePath}.ts`, (0, selectors_generator_1.generateSelectors)());
|
|
200
|
+
generated.write(`/${meta.e2e.dataMocker.stubIndexFilePath}.ts`, (0, stubs_generator_1.generateDataMockerStubsIndex)({ models, meta }));
|
|
201
|
+
generated.write(`/${meta.data.repository.constFilePath}.ts`, (0, repositories_generator_1.generateRepositoriesArray)({ models, meta }));
|
|
202
|
+
generated.write(`/${meta.data.repository.indexFilePath}.ts`, (0, repositories_generator_1.generateRepositoriesIndex)({ models, meta }));
|
|
203
|
+
generated.write(`/${meta.data.stubIndexFilePath}.ts`, (0, stubs_generator_1.generateStubsIndex)({ models, meta }));
|
|
204
|
+
generated.write(`/${meta.data.types.filePath}.ts`, (0, data_types_generator_1.generateDataTypes)({ models, meta }));
|
|
205
|
+
// We only generate the empty database migration if the migration folder already has an existing migration
|
|
206
|
+
// Else we would generate a migration that deletes from tables that have not yet been created in the database
|
|
207
|
+
// We include this check here as the template does not come with any migration - hence this migration should also not be generated
|
|
208
|
+
if ((0, emptydatabasemigration_generator_1.prismaMigrationExists)(meta)) {
|
|
209
|
+
generated.write((0, emptydatabasemigration_generator_1.deriveEmptyDatabaseMigrationFilePath)(meta), (0, emptydatabasemigration_generator_1.generateEmptyDatabaseStoredProcedure)({ models, meta }));
|
|
269
210
|
}
|
|
211
|
+
// Import-Export
|
|
212
|
+
generated.write(`/${meta.importExport.types.filePath}.ts`, (0, importexport_types_generator_1.generateImportExportTypes)({ models, meta }));
|
|
213
|
+
generated.write(`/${meta.importExport.exporterClass.filePath}.ts`, (0, importexport_exporter_class_generator_1.generateImportExportExporterClass)({ models, meta }));
|
|
214
|
+
generated.write(`/${meta.importExport.importService.filePath}.ts`, (0, importexport_import_service_generator_1.generateImportExportImportService)({ models, meta }));
|
|
215
|
+
generated.write(`/${meta.importExport.decoder.indexFilePath}.ts`, (0, importexport_decoder_generator_1.generateImportExportDecoderIndex)({ models, meta }));
|
|
216
|
+
generated.write(`/${meta.importExport.decoder.fullDecoderFilePath}.ts`, (0, importexport_decoder_generator_1.generateImportExportDecoder)({ models, meta }));
|
|
217
|
+
generated.write(`/${meta.importExport.converterFunctions.filePath}.ts`, (0, importexport_convert_import_functions_generator_1.generateImportExportConvertImportFunctions)({ models, meta }));
|
|
218
|
+
// Actions
|
|
219
|
+
generated.write(`/${meta.actions.dispatcherService.filePath}.ts`, (0, dispatcher_service_generator_1.generateActionsDispatcherService)({ models, meta }));
|
|
220
|
+
// Business Logic
|
|
221
|
+
generated.write(`/${meta.businessLogic.view.indexFilePath}.ts`, (0, businesslogic_view_index_generator_1.generateBusinessLogicViewIndex)({ models, meta }));
|
|
222
|
+
generated.write(`/${meta.businessLogic.view.moduleFilePath}.ts`, (0, businesslogic_view_module_generator_1.generateBusinessLogicViewModule)({ models, meta }));
|
|
223
|
+
generated.write(`/${meta.businessLogic.view.serviceFilePath}.ts`, (0, businesslogic_view_service_generator_1.generateBusinessLogicViewService)({ models, meta }));
|
|
224
|
+
generated.write(`/${meta.businessLogic.update.indexFilePath}.ts`, (0, businesslogic_update_index_generator_1.generateBusinessLogicUpdateIndex)({ models, meta }));
|
|
225
|
+
generated.write(`/${meta.businessLogic.update.moduleFilePath}.ts`, (0, businesslogic_update_module_generator_1.generateBusinessLogicUpdateModule)({ models, meta }));
|
|
226
|
+
generated.write(`/${meta.businessLogic.update.serviceFilePath}.ts`, (0, businesslogic_update_service_generator_1.generateBusinessLogicUpdateService)({ models, meta }));
|
|
227
|
+
generated.write(`/${meta.businessLogic.update.actionTypesFilePath}.ts`, (0, businesslogic_actiontypes_generator_1.generateBusinessLogicActionTypes)({ models, meta }));
|
|
228
|
+
// Seed
|
|
229
|
+
generated.write(`/${meta.seedData.initialMigrationFilePath}.ts`, (0, seed_migration_generator_1.generateSeedMigration)({ models, meta }));
|
|
230
|
+
generated.write(`/${meta.seedData.templateExcelFilePath}`, yield (0, seed_template_generator_1.generateSeedExcelTemplate)({ models }));
|
|
231
|
+
// Routes
|
|
232
|
+
generated.write(`/${meta.trpc.routesFilePath}.ts`, (0, route_generator_1.generateRoutesIndex)({ models, meta }));
|
|
233
|
+
// Types
|
|
234
|
+
generated.write(`/${meta.types.indexFilePath}.ts`, (0, types_generator_2.generateTypesIndex)({ models, enums, meta }));
|
|
270
235
|
// -------------------------------------------------------------------------
|
|
271
236
|
// Add disclaimer and format.
|
|
272
237
|
yield generated.transformUTF8Files((path, content) => `${DISCLAIMER}\n${content}`);
|
|
@@ -45,11 +45,11 @@ exports.generateEmptyDatabaseStoredProcedure = generateEmptyDatabaseStoredProced
|
|
|
45
45
|
function deriveEmptyDatabaseMigrationFilePath(meta) {
|
|
46
46
|
const firstMigration = getFirstPrismaMigration(meta);
|
|
47
47
|
if (firstMigration === undefined) {
|
|
48
|
-
throw new Error(`No Prisma migration found in ${meta.
|
|
48
|
+
throw new Error(`No Prisma migration found in ${meta.prismaMigrationsPath}! Please run "prisma migrate dev" first.`);
|
|
49
49
|
}
|
|
50
50
|
const existingTimestamp = firstMigration.split('_')[0];
|
|
51
51
|
const nextTimestamp = (Number.parseInt(existingTimestamp) + 1).toString();
|
|
52
|
-
return `/${meta.
|
|
52
|
+
return `/${meta.prismaMigrationsPath}/${nextTimestamp}_emptyDatabase/migration.sql`;
|
|
53
53
|
}
|
|
54
54
|
exports.deriveEmptyDatabaseMigrationFilePath = deriveEmptyDatabaseMigrationFilePath;
|
|
55
55
|
/**
|
|
@@ -64,7 +64,7 @@ exports.prismaMigrationExists = prismaMigrationExists;
|
|
|
64
64
|
* Returns the first migration in the migrations folder if it exists.
|
|
65
65
|
*/
|
|
66
66
|
function getFirstPrismaMigration(meta) {
|
|
67
|
-
const folder = meta.
|
|
67
|
+
const folder = meta.prismaMigrationsPath;
|
|
68
68
|
try {
|
|
69
69
|
return fs_1.default.readdirSync(folder).find((f) => fs_1.default.statSync(`${folder}/${f}`).isDirectory());
|
|
70
70
|
}
|
|
@@ -10,6 +10,9 @@ const imports_1 = require("../../../lib/imports");
|
|
|
10
10
|
function generateModelLibraryComponents({ model, meta }) {
|
|
11
11
|
const { react: { context, components }, } = meta;
|
|
12
12
|
const selectorCollector = id_collector_1.SelectorCollector.from(meta.seed.constantName + '-card');
|
|
13
|
+
const titleProp = model.nameField.isRequired
|
|
14
|
+
? `title={item.${model.nameField.name}}`
|
|
15
|
+
: `title={item.${model.nameField.name} ?? item.${model.idField.name}}`;
|
|
13
16
|
const imports = imports_1.ImportsGenerator.from(meta.react.folderPath)
|
|
14
17
|
.addTypeImport({
|
|
15
18
|
items: [model.typeName],
|
|
@@ -52,7 +55,7 @@ function generateModelLibraryComponents({ model, meta }) {
|
|
|
52
55
|
<>
|
|
53
56
|
<Card
|
|
54
57
|
ref={forwardedRef}
|
|
55
|
-
|
|
58
|
+
${titleProp}
|
|
56
59
|
actions={[
|
|
57
60
|
{
|
|
58
61
|
label: 'Edit',
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateModelLookupComponents = void 0;
|
|
4
|
+
const id_collector_1 = require("../../../lib/id-collector");
|
|
4
5
|
const imports_1 = require("../../../lib/imports");
|
|
5
6
|
/**
|
|
6
7
|
* Utility generator that generates lookup components for a given model.
|
|
7
8
|
*/
|
|
8
9
|
function generateModelLookupComponents({ model, meta }) {
|
|
9
10
|
const { react: { context, components }, } = meta;
|
|
11
|
+
const selectorCollector = id_collector_1.SelectorCollector.from(meta.seed.constantName + '-formComponents');
|
|
10
12
|
const imports = imports_1.ImportsGenerator.from(meta.react.folderPath)
|
|
11
13
|
.addImport({
|
|
12
14
|
items: [context.hookFnName],
|
|
@@ -18,7 +20,9 @@ function generateModelLookupComponents({ model, meta }) {
|
|
|
18
20
|
});
|
|
19
21
|
const typeName = model.typeName;
|
|
20
22
|
const tsOmittedFields = `'label' | 'options' | 'loading'`;
|
|
21
|
-
const
|
|
23
|
+
const labelProp = model.nameField.isRequired
|
|
24
|
+
? `label={(l) => l.${model.nameField.name}}`
|
|
25
|
+
: `label={(l) => l.${model.nameField.name} ?? l.${model.idField.name}}`;
|
|
22
26
|
let description = '';
|
|
23
27
|
if (model.description) {
|
|
24
28
|
description = `
|
|
@@ -26,7 +30,7 @@ function generateModelLookupComponents({ model, meta }) {
|
|
|
26
30
|
* ${model.description}
|
|
27
31
|
*/`;
|
|
28
32
|
}
|
|
29
|
-
return `
|
|
33
|
+
return /* ts */ `
|
|
30
34
|
import React from 'react'
|
|
31
35
|
|
|
32
36
|
import { MenuSelectInput, MenuSelectField } from '@components/atoms/MenuSelect'
|
|
@@ -46,7 +50,16 @@ export const ${components.forms.selectInputName} = ({
|
|
|
46
50
|
...delegated
|
|
47
51
|
}: UnionOmit<React.ComponentPropsWithoutRef<typeof SelectInput<${typeName}>>, ${tsOmittedFields}>) => {
|
|
48
52
|
const { list, ready } = ${context.hookFnName}()
|
|
49
|
-
return <SelectInput<${typeName}>
|
|
53
|
+
return <SelectInput<${typeName}>
|
|
54
|
+
options={list}
|
|
55
|
+
${labelProp}
|
|
56
|
+
loading={!ready}
|
|
57
|
+
__cypress_field_selector__={
|
|
58
|
+
delegated.__cypress_field_selector__
|
|
59
|
+
?? "${selectorCollector.idFor('', { typePrefix: 'selectInput' })}"
|
|
60
|
+
}
|
|
61
|
+
{...delegated}
|
|
62
|
+
/>
|
|
50
63
|
}
|
|
51
64
|
|
|
52
65
|
${description}
|
|
@@ -54,7 +67,16 @@ export const ${components.forms.selectFieldName} = ({
|
|
|
54
67
|
...delegated
|
|
55
68
|
}: Omit<React.ComponentPropsWithoutRef<typeof SelectField<${typeName}>>, ${tsOmittedFields}>) => {
|
|
56
69
|
const { list, ready } = ${context.hookFnName}()
|
|
57
|
-
return <SelectField<${typeName}>
|
|
70
|
+
return <SelectField<${typeName}>
|
|
71
|
+
options={list}
|
|
72
|
+
${labelProp}
|
|
73
|
+
loading={!ready}
|
|
74
|
+
__cypress_field_selector__={
|
|
75
|
+
delegated.__cypress_field_selector__
|
|
76
|
+
?? "${selectorCollector.idFor('', { typePrefix: 'selectField' })}"
|
|
77
|
+
}
|
|
78
|
+
{...delegated}
|
|
79
|
+
/>
|
|
58
80
|
}
|
|
59
81
|
|
|
60
82
|
// Menu Select
|
|
@@ -64,7 +86,16 @@ export const ${components.forms.menuSelectInputName} = ({
|
|
|
64
86
|
...delegated
|
|
65
87
|
}: UnionOmit<React.ComponentPropsWithoutRef<typeof MenuSelectInput<${typeName}>>, ${tsOmittedFields}>) => {
|
|
66
88
|
const { list, ready } = ${context.hookFnName}()
|
|
67
|
-
return <MenuSelectInput<${typeName}>
|
|
89
|
+
return <MenuSelectInput<${typeName}>
|
|
90
|
+
options={list}
|
|
91
|
+
${labelProp}
|
|
92
|
+
loading={!ready}
|
|
93
|
+
__cypress_options_selector__={
|
|
94
|
+
delegated.__cypress_options_selector__
|
|
95
|
+
?? "${selectorCollector.idFor('', { typePrefix: 'menuSelectInput' })}"
|
|
96
|
+
}
|
|
97
|
+
{...delegated}
|
|
98
|
+
/>
|
|
68
99
|
}
|
|
69
100
|
|
|
70
101
|
${description}
|
|
@@ -72,7 +103,16 @@ export const ${components.forms.menuSelectFieldName} = ({
|
|
|
72
103
|
...delegated
|
|
73
104
|
}: UnionOmit<React.ComponentPropsWithoutRef<typeof MenuSelectField<${typeName}>>, ${tsOmittedFields}>) => {
|
|
74
105
|
const { list, ready } = ${context.hookFnName}()
|
|
75
|
-
return <MenuSelectField<${typeName}>
|
|
106
|
+
return <MenuSelectField<${typeName}>
|
|
107
|
+
options={list}
|
|
108
|
+
${labelProp}
|
|
109
|
+
loading={!ready}
|
|
110
|
+
__cypress_options_selector__={
|
|
111
|
+
delegated.__cypress_options_selector__
|
|
112
|
+
?? "${selectorCollector.idFor('', { typePrefix: 'menuSelectField' })}"
|
|
113
|
+
}
|
|
114
|
+
{...delegated}
|
|
115
|
+
/>
|
|
76
116
|
}
|
|
77
117
|
|
|
78
118
|
// Search
|
|
@@ -82,7 +122,20 @@ export const ${components.forms.searchInputName} = ({
|
|
|
82
122
|
...delegated
|
|
83
123
|
}: UnionOmit<React.ComponentPropsWithoutRef<typeof SearchInput<${typeName}>>, ${tsOmittedFields}>) => {
|
|
84
124
|
const { list, ready } = ${context.hookFnName}()
|
|
85
|
-
return <SearchInput<${typeName}>
|
|
125
|
+
return <SearchInput<${typeName}>
|
|
126
|
+
options={list}
|
|
127
|
+
${labelProp}
|
|
128
|
+
loading={!ready}
|
|
129
|
+
__cypress_combobox_selector__={
|
|
130
|
+
delegated.__cypress_combobox_selector__
|
|
131
|
+
?? "${selectorCollector.idFor('field', { typePrefix: 'searchInput' })}"
|
|
132
|
+
}
|
|
133
|
+
__cypress_options_selector__={
|
|
134
|
+
delegated.__cypress_options_selector__
|
|
135
|
+
?? "${selectorCollector.idFor('options', { typePrefix: 'searchInput' })}"
|
|
136
|
+
}
|
|
137
|
+
{...delegated}
|
|
138
|
+
/>
|
|
86
139
|
}
|
|
87
140
|
|
|
88
141
|
${description}
|
|
@@ -90,17 +143,38 @@ export const ${components.forms.searchFieldName} = ({
|
|
|
90
143
|
...delegated
|
|
91
144
|
}: Omit<React.ComponentPropsWithoutRef<typeof SearchField<${typeName}>>, ${tsOmittedFields}>) => {
|
|
92
145
|
const { list, ready } = ${context.hookFnName}()
|
|
93
|
-
return <SearchField<${typeName}>
|
|
146
|
+
return <SearchField<${typeName}>
|
|
147
|
+
options={list}
|
|
148
|
+
${labelProp}
|
|
149
|
+
loading={!ready}
|
|
150
|
+
__cypress_combobox_selector__={
|
|
151
|
+
delegated.__cypress_combobox_selector__
|
|
152
|
+
?? "${selectorCollector.idFor('field', { typePrefix: 'searchField' })}"
|
|
153
|
+
}
|
|
154
|
+
__cypress_options_selector__={
|
|
155
|
+
delegated.__cypress_options_selector__
|
|
156
|
+
?? "${selectorCollector.idFor('options', { typePrefix: 'searchField' })}"
|
|
157
|
+
}
|
|
158
|
+
{...delegated}
|
|
159
|
+
/>
|
|
94
160
|
}
|
|
95
161
|
|
|
96
162
|
// Table
|
|
97
|
-
|
|
98
163
|
${description}
|
|
99
164
|
export const ${components.forms.tableSelectInputName} = ({
|
|
100
165
|
...delegated
|
|
101
166
|
}: UnionOmit<React.ComponentPropsWithoutRef<typeof TableSelectInput<${typeName}>>, ${tsOmittedFields}>) => {
|
|
102
167
|
const { list, ready } = ${context.hookFnName}()
|
|
103
|
-
return <TableSelectInput<${typeName}>
|
|
168
|
+
return <TableSelectInput<${typeName}>
|
|
169
|
+
options={list}
|
|
170
|
+
${labelProp}
|
|
171
|
+
loading={!ready}
|
|
172
|
+
__cypress_input_field_selector__={
|
|
173
|
+
delegated.__cypress_input_field_selector__
|
|
174
|
+
?? "${selectorCollector.idFor('', { typePrefix: 'tableSelectInput' })}"
|
|
175
|
+
}
|
|
176
|
+
{...delegated}
|
|
177
|
+
/>
|
|
104
178
|
}
|
|
105
179
|
|
|
106
180
|
${description}
|
|
@@ -108,7 +182,16 @@ export const ${components.forms.tableSelectFieldName} = ({
|
|
|
108
182
|
...delegated
|
|
109
183
|
}: UnionOmit<React.ComponentPropsWithoutRef<typeof TableSelectField<${typeName}>>, ${tsOmittedFields}>) => {
|
|
110
184
|
const { list, ready } = ${context.hookFnName}()
|
|
111
|
-
return <TableSelectField<${typeName}>
|
|
185
|
+
return <TableSelectField<${typeName}>
|
|
186
|
+
options={list}
|
|
187
|
+
${labelProp}
|
|
188
|
+
loading={!ready}
|
|
189
|
+
__cypress_input_field_selector__={
|
|
190
|
+
delegated.__cypress_input_field_selector__
|
|
191
|
+
?? "${selectorCollector.idFor('', { typePrefix: 'tableSelectField' })}"
|
|
192
|
+
}
|
|
193
|
+
{...delegated}
|
|
194
|
+
/>
|
|
112
195
|
}
|
|
113
196
|
`;
|
|
114
197
|
}
|
package/dist/lib/meta.d.ts
CHANGED
|
@@ -635,9 +635,9 @@ export type SchemaMetaData = {
|
|
|
635
635
|
selectorsFilePath: Types.FilePath;
|
|
636
636
|
};
|
|
637
637
|
/**
|
|
638
|
-
* Path to the directory containing migrations.
|
|
638
|
+
* Path to the directory containing Prisma migrations.
|
|
639
639
|
*/
|
|
640
|
-
|
|
640
|
+
prismaMigrationsPath: Types.FilePath;
|
|
641
641
|
/**
|
|
642
642
|
* The schema configuration for reference.
|
|
643
643
|
*/
|
package/dist/lib/meta.js
CHANGED
|
@@ -251,7 +251,7 @@ function getSchemaMetadata({ config }) {
|
|
|
251
251
|
upsert: Types.toTypeName(`UpsertDTO`),
|
|
252
252
|
},
|
|
253
253
|
},
|
|
254
|
-
|
|
254
|
+
prismaMigrationsPath: Types.toPath(`${config.paths.prismaMigrationsFolderPath}`),
|
|
255
255
|
config,
|
|
256
256
|
};
|
|
257
257
|
}
|
|
@@ -7,43 +7,6 @@ import * as Types from './types';
|
|
|
7
7
|
* NOTE: This may be accessed in every model, field and enumerator.
|
|
8
8
|
*/
|
|
9
9
|
export type SchemaConfig = {
|
|
10
|
-
/**
|
|
11
|
-
* Indicates whether the generator should be ignored
|
|
12
|
-
*/
|
|
13
|
-
disableGenerators: {
|
|
14
|
-
/**
|
|
15
|
-
* If true, actions module will not be generated.
|
|
16
|
-
*/
|
|
17
|
-
actions: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* If true, business logic module will not be generated.
|
|
20
|
-
*/
|
|
21
|
-
businessLogic: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* If true, data module will not be generated.
|
|
24
|
-
*/
|
|
25
|
-
data: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* If true, import-export module will not be generated.
|
|
28
|
-
*/
|
|
29
|
-
importExport: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* If true, seed data will not be generated.
|
|
32
|
-
*/
|
|
33
|
-
seed: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* If true, React components will not be generated.
|
|
36
|
-
*/
|
|
37
|
-
react: boolean;
|
|
38
|
-
/**
|
|
39
|
-
* If true, trpc routes will not be generated.
|
|
40
|
-
*/
|
|
41
|
-
trpc: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* If true, type definitions for models will not be generated.
|
|
44
|
-
*/
|
|
45
|
-
types: boolean;
|
|
46
|
-
};
|
|
47
10
|
paths: {
|
|
48
11
|
/**
|
|
49
12
|
* Path to the directory containing actions.
|
|
@@ -84,7 +47,7 @@ export type SchemaConfig = {
|
|
|
84
47
|
/**
|
|
85
48
|
* Path to the directory containing Prisma migrations.
|
|
86
49
|
*/
|
|
87
|
-
|
|
50
|
+
prismaMigrationsFolderPath: Types.FilePath;
|
|
88
51
|
/**
|
|
89
52
|
* Path to the directory containing model type definitions.
|
|
90
53
|
*
|