@postxl/generator 0.44.2 → 0.44.4
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 +8 -9
- package/dist/generators/enums/react.generator.js +1 -1
- package/dist/generators/indices/businesslogic-update-module.generator.js +1 -1
- package/dist/generators/indices/businesslogic-view-module.generator.js +1 -1
- package/dist/generators/indices/data-types.generator.js +4 -3
- package/dist/generators/indices/datamock-module.generator.js +3 -3
- package/dist/generators/indices/datamocker.generator.js +5 -4
- package/dist/generators/indices/datamodule.generator.js +3 -3
- package/dist/generators/indices/dataservice.generator.js +5 -4
- package/dist/generators/indices/dispatcher-service.generator.js +4 -3
- package/dist/generators/indices/importexport-convert-import-functions.generator.js +29 -24
- package/dist/generators/indices/importexport-exporter-class.generator.js +4 -3
- package/dist/generators/indices/importexport-import-service.generator.js +27 -12
- package/dist/generators/indices/importexport-types.generator.js +9 -4
- package/dist/generators/indices/stubs.generator.js +2 -2
- package/dist/generators/indices/testdata-service.generator.js +5 -2
- package/dist/generators/models/businesslogic-update.generator.js +11 -10
- package/dist/generators/models/businesslogic-view.generator.js +4 -3
- package/dist/generators/models/importexport-decoder.generator.d.ts +2 -1
- package/dist/generators/models/importexport-decoder.generator.js +20 -19
- package/dist/generators/models/react.generator/context.generator.js +1 -1
- package/dist/generators/models/react.generator/library.generator.js +1 -1
- package/dist/generators/models/react.generator/lookup.generator.js +1 -1
- package/dist/generators/models/react.generator/modals.generator.js +4 -4
- package/dist/generators/models/repository.generator.js +26 -17
- package/dist/generators/models/route.generator.js +3 -2
- package/dist/generators/models/seed.generator.js +5 -4
- package/dist/generators/models/stub.generator.js +7 -2
- package/dist/generators/models/types.generator.js +7 -3
- package/dist/lib/exports.d.ts +2 -2
- package/dist/lib/imports.d.ts +12 -3
- package/dist/lib/imports.js +47 -15
- package/dist/lib/meta.d.ts +163 -88
- package/dist/lib/meta.js +68 -23
- package/dist/lib/schema/schema.d.ts +12 -16
- package/dist/lib/schema/types.d.ts +35 -5
- package/dist/lib/schema/types.js +20 -2
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/types.js +1 -1
- package/dist/lib/utils/string.d.ts +4 -0
- package/dist/lib/utils/string.js +13 -3
- package/dist/prisma/parse.js +3 -0
- package/package.json +1 -1
package/dist/lib/meta.js
CHANGED
|
@@ -31,11 +31,51 @@ const string_1 = require("./utils/string");
|
|
|
31
31
|
*/
|
|
32
32
|
function getSchemaMetadata({ config }) {
|
|
33
33
|
return {
|
|
34
|
+
backendModules: {
|
|
35
|
+
common: {
|
|
36
|
+
importPath: Types.toBackendModulePath(`@backend/common`),
|
|
37
|
+
functions: {
|
|
38
|
+
format: Types.toFunctionName(`format`),
|
|
39
|
+
pluralize: Types.toFunctionName(`pluralize`),
|
|
40
|
+
uncapitalizeKeys: Types.toFunctionName(`uncapitalizeKeys`),
|
|
41
|
+
capitalizeKeys: Types.toFunctionName(`capitalizeKeys`),
|
|
42
|
+
nullOrBlankDecoder: Types.toFunctionName(`nullOrBlankDecoder`),
|
|
43
|
+
excelStringNullableDecoder: Types.toFunctionName(`excelStringNullableDecoder`),
|
|
44
|
+
excelStringDecoder: Types.toFunctionName(`excelStringDecoder`),
|
|
45
|
+
excelDateNullableDecoder: Types.toFunctionName(`excelDateNullableDecoder`),
|
|
46
|
+
excelDateDecoder: Types.toFunctionName(`excelDateDecoder`),
|
|
47
|
+
excelBooleanDecoder: Types.toFunctionName(`excelBooleanDecoder`),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
auth: {
|
|
51
|
+
importPath: Types.toBackendModulePath(`@backend/auth`),
|
|
52
|
+
},
|
|
53
|
+
db: {
|
|
54
|
+
importPath: Types.toBackendModulePath(`@backend/db`),
|
|
55
|
+
dbService: {
|
|
56
|
+
name: Types.toClassName(`DbService`),
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
http: {
|
|
60
|
+
importPath: Types.toBackendModulePath(`@backend/http`),
|
|
61
|
+
},
|
|
62
|
+
i18n: {
|
|
63
|
+
importPath: Types.toBackendModulePath(`@backend/i18n`),
|
|
64
|
+
},
|
|
65
|
+
s3: {
|
|
66
|
+
importPath: Types.toBackendModulePath(`@backend/s3`),
|
|
67
|
+
},
|
|
68
|
+
upload: {
|
|
69
|
+
importPath: Types.toBackendModulePath(`@backend/upload`),
|
|
70
|
+
},
|
|
71
|
+
xlport: {
|
|
72
|
+
importPath: Types.toBackendModulePath(`@backend/xlport`),
|
|
73
|
+
},
|
|
74
|
+
},
|
|
34
75
|
actions: {
|
|
35
76
|
moduleName: Types.toClassName(`ActionModule`),
|
|
36
|
-
importPath: Types.
|
|
77
|
+
importPath: Types.toBackendModulePath(`@backend/actions`),
|
|
37
78
|
actionExecution: {
|
|
38
|
-
filePath: Types.toPath(`@${config.project}/actions/actionExecution.class`),
|
|
39
79
|
interface: Types.toClassName(`IActionExecution`),
|
|
40
80
|
class: Types.toClassName(`ActionExecution`),
|
|
41
81
|
mock: Types.toClassName(`MockActionExecution`),
|
|
@@ -47,12 +87,12 @@ function getSchemaMetadata({ config }) {
|
|
|
47
87
|
},
|
|
48
88
|
businessLogic: {
|
|
49
89
|
moduleName: Types.toClassName(`BusinessLogicModule`),
|
|
50
|
-
importPath: Types.
|
|
90
|
+
importPath: Types.toBackendModulePath(`@backend/business-logic`),
|
|
51
91
|
indexFilePath: Types.toPath(`${config.paths.businessLogicPath}index`),
|
|
52
92
|
moduleFilePath: Types.toPath(`${config.paths.businessLogicPath}business-logic.module`),
|
|
53
93
|
view: {
|
|
54
94
|
moduleName: Types.toClassName(`ViewModule`),
|
|
55
|
-
importPath: Types.
|
|
95
|
+
importPath: Types.toBackendModulePath(`@backend/business-logic/view`),
|
|
56
96
|
indexFilePath: Types.toPath(`${config.paths.businessLogicPath}view/index`),
|
|
57
97
|
moduleFilePath: Types.toPath(`${config.paths.businessLogicPath}view/view.module`),
|
|
58
98
|
serviceClassName: Types.toClassName(`ViewService`),
|
|
@@ -60,7 +100,7 @@ function getSchemaMetadata({ config }) {
|
|
|
60
100
|
},
|
|
61
101
|
update: {
|
|
62
102
|
moduleName: Types.toClassName(`UpdateModule`),
|
|
63
|
-
importPath: Types.
|
|
103
|
+
importPath: Types.toBackendModulePath(`@backend/business-logic/update`),
|
|
64
104
|
indexFilePath: Types.toPath(`${config.paths.businessLogicPath}update/index`),
|
|
65
105
|
moduleFilePath: Types.toPath(`${config.paths.businessLogicPath}update/update.module`),
|
|
66
106
|
serviceClassName: Types.toClassName(`UpdateService`),
|
|
@@ -70,7 +110,7 @@ function getSchemaMetadata({ config }) {
|
|
|
70
110
|
},
|
|
71
111
|
data: {
|
|
72
112
|
moduleName: Types.toClassName(`DataModule`),
|
|
73
|
-
importPath: Types.
|
|
113
|
+
importPath: Types.toBackendModulePath(`@backend/data`),
|
|
74
114
|
dataModuleFilePath: Types.toPath(`${config.paths.dataLibPath}data.module`),
|
|
75
115
|
dataMockModuleFilePath: Types.toPath(`${config.paths.dataLibPath}data.mock.module`),
|
|
76
116
|
repository: {
|
|
@@ -90,17 +130,21 @@ function getSchemaMetadata({ config }) {
|
|
|
90
130
|
executeBulkMutations: Types.toFunctionName(`executeBulkMutations`),
|
|
91
131
|
executeBulkMutation: Types.toFunctionName(`executeBulkMutation`),
|
|
92
132
|
},
|
|
93
|
-
dataMockerFilePath: Types.toPath(`${config.paths.cypressPath}support/data-mocker.class`),
|
|
94
|
-
dataMockerStubImportPath: Types.toPath(`${config.paths.cypressPath}support/stubs`),
|
|
95
|
-
dataMockerStubIndexFilePath: Types.toPath(`${config.paths.cypressPath}support/stubs/index`),
|
|
96
133
|
stubIndexFilePath: Types.toPath(`${config.paths.dataLibPath}stubs/index`),
|
|
97
|
-
selectorsFilePath: Types.toPath(`${config.paths.cypressPath}support/selectors`),
|
|
98
134
|
testDataServiceFilePath: Types.toPath(`${config.paths.e2eLibPath}test-data.service`),
|
|
99
135
|
dataMockModuleName: Types.toClassName(`DataMockModule`),
|
|
100
136
|
dataMockDataType: Types.toTypeName(`MockData`),
|
|
101
137
|
},
|
|
138
|
+
e2e: {
|
|
139
|
+
dataMocker: {
|
|
140
|
+
filePath: Types.toPath(`${config.paths.cypressPath}support/data-mocker.class`),
|
|
141
|
+
stubImportPath: Types.toPath(`${config.paths.cypressPath}support/stubs`),
|
|
142
|
+
stubIndexFilePath: Types.toPath(`${config.paths.cypressPath}support/stubs/index`),
|
|
143
|
+
},
|
|
144
|
+
selectorsFilePath: Types.toPath(`${config.paths.cypressPath}support/selectors`),
|
|
145
|
+
},
|
|
102
146
|
importExport: {
|
|
103
|
-
importPath: Types.
|
|
147
|
+
importPath: Types.toBackendModulePath(`@backend/import-export`),
|
|
104
148
|
decoder: {
|
|
105
149
|
indexFilePath: Types.toPath(`${config.paths.importExportPath}decoders/index`),
|
|
106
150
|
fullDecoderFilePath: Types.toPath(`${config.paths.importExportPath}decoders/data.decoder`),
|
|
@@ -183,21 +227,21 @@ function getSchemaMetadata({ config }) {
|
|
|
183
227
|
},
|
|
184
228
|
},
|
|
185
229
|
seedData: {
|
|
186
|
-
importPath: Types.
|
|
230
|
+
importPath: Types.toBackendModulePath(`@backend/seed-data`),
|
|
187
231
|
initialMigrationFilePath: Types.toPath(`${config.paths.seedDataPath}001-base-data/001-seed.migration`),
|
|
188
232
|
templateExcelFilePath: Types.toPath(`${config.paths.seedDataPath}002-excel-example/template.xlsx`),
|
|
189
233
|
},
|
|
190
234
|
seed: {
|
|
191
235
|
serviceClassName: Types.toClassName(`SeedService`),
|
|
192
|
-
importPath: Types.
|
|
236
|
+
importPath: Types.toBackendModulePath(`@backend/seed`),
|
|
193
237
|
},
|
|
194
238
|
trpc: {
|
|
195
239
|
routesFilePath: Types.toPath(`${config.paths.trpcRoutesFolderPath}index`),
|
|
196
|
-
importPath: Types.
|
|
240
|
+
importPath: Types.toBackendModulePath(`@backend/trpc`),
|
|
197
241
|
},
|
|
198
242
|
types: {
|
|
199
243
|
indexFilePath: Types.toPath(`${config.paths.modelTypeDefinitionsPath}index`),
|
|
200
|
-
importPath: Types.
|
|
244
|
+
importPath: Types.toBackendModulePath(`@backend/types`),
|
|
201
245
|
dto: {
|
|
202
246
|
path: Types.toPath(`${config.paths.modelTypeDefinitionsPath}dto.types`),
|
|
203
247
|
genericModel: Types.toTypeName(`GenericModel`),
|
|
@@ -229,7 +273,7 @@ function getModelMetadata({ model }) {
|
|
|
229
273
|
actionScopeConstType: Types.toTypeName(`${camelCase}`),
|
|
230
274
|
},
|
|
231
275
|
data: {
|
|
232
|
-
importPath: Types.
|
|
276
|
+
importPath: Types.toBackendModulePath(`@backend/data`),
|
|
233
277
|
mockDataPropertyName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
234
278
|
repository: {
|
|
235
279
|
fileName: Types.toFileName(`${camelCase}.repository`),
|
|
@@ -243,13 +287,15 @@ function getModelMetadata({ model }) {
|
|
|
243
287
|
filePath: Types.toPath(`${config.paths.dataLibPath}repositories/mock/${camelCase}.mock.repository`),
|
|
244
288
|
className: Types.toClassName(`Mock${PascalCase}Repository`),
|
|
245
289
|
},
|
|
246
|
-
dataMockerStubFilePath: Types.toPath(`${config.paths.cypressPath}support/stubs/${camelCase}.stub`),
|
|
247
290
|
stubFilePath: Types.toPath(`${config.paths.dataLibPath}stubs/${camelCase}.stub`),
|
|
248
291
|
stubGenerationFnName: Types.toFunctionName(`stub${PascalCase}`),
|
|
249
292
|
defaultStubConstantName: Types.toVariableName(`${camelCase}DefaultStub`),
|
|
250
293
|
dataServiceName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
251
294
|
dataServiceIdName: Types.toVariableName(`${uncapitalized}`),
|
|
252
295
|
},
|
|
296
|
+
e2e: {
|
|
297
|
+
dataMockerStubFilePath: Types.toPath(`${config.paths.cypressPath}support/stubs/${camelCase}.stub`),
|
|
298
|
+
},
|
|
253
299
|
importExport: {
|
|
254
300
|
exportDataPropertyName: Types.toVariableName(`${capitalizedPlural}`),
|
|
255
301
|
exportDataFullPropertyName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
@@ -269,7 +315,7 @@ function getModelMetadata({ model }) {
|
|
|
269
315
|
},
|
|
270
316
|
businessLogic: {
|
|
271
317
|
scopeName: Types.toVariableName(`${camelCase}`),
|
|
272
|
-
importPath: Types.
|
|
318
|
+
importPath: Types.toBackendModulePath(`@backend/business-logic`),
|
|
273
319
|
view: {
|
|
274
320
|
serviceClassName: Types.toClassName(`${PascalCase}ViewService`),
|
|
275
321
|
serviceVariableName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
@@ -299,7 +345,7 @@ function getModelMetadata({ model }) {
|
|
|
299
345
|
seed: {
|
|
300
346
|
filePath: Types.toPath(`${config.paths.seedDataPath}001-base-data/${uncapitalizedPlural}.seed`),
|
|
301
347
|
constantName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
302
|
-
importPath: Types.
|
|
348
|
+
importPath: Types.toBackendModulePath(`@backend/seed`),
|
|
303
349
|
},
|
|
304
350
|
react: {
|
|
305
351
|
folderName: Types.toFolderName(`${PascalCase}`),
|
|
@@ -331,7 +377,6 @@ function getModelMetadata({ model }) {
|
|
|
331
377
|
trpc: {
|
|
332
378
|
routerFilePath: Types.toPath(`${config.paths.trpcRoutesFolderPath}${camelCase}.router`),
|
|
333
379
|
routerName: Types.toVariableName(uncapitalizedPlural),
|
|
334
|
-
importPath: Types.toPath(`@${config.project}${camelCase}.router`),
|
|
335
380
|
getMap: {
|
|
336
381
|
methodName: Types.toVariableName('getMap'),
|
|
337
382
|
reactQueryMethod: Types.toFunctionName(`${uncapitalizedPlural}.getMap`),
|
|
@@ -350,7 +395,7 @@ function getModelMetadata({ model }) {
|
|
|
350
395
|
},
|
|
351
396
|
},
|
|
352
397
|
types: {
|
|
353
|
-
importPath: Types.
|
|
398
|
+
importPath: Types.toBackendModulePath(`@backend/types`),
|
|
354
399
|
filePath: Types.toPath(`${config.paths.modelTypeDefinitionsPath}${camelCase}.type`),
|
|
355
400
|
brandedIdType: Types.toTypeName(`${PascalCase}Id`),
|
|
356
401
|
toBrandedIdTypeFnName: Types.toFunctionName(`to${PascalCase}Id`),
|
|
@@ -413,7 +458,7 @@ function getEnumMetadata({ enumerator: { name, schemaConfig: config }, }) {
|
|
|
413
458
|
react: {
|
|
414
459
|
folderName: Types.toFolderName((0, string_1.toPascalCase)(name)),
|
|
415
460
|
folderPath: Types.toPath(`${config.paths.reactFolderPath}/enums/${(0, string_1.toPascalCase)(name)}`),
|
|
416
|
-
importPath: Types.
|
|
461
|
+
importPath: Types.toBackendModulePath(`@backend/react/enums/${(0, string_1.toPascalCase)(name)}`),
|
|
417
462
|
selectInputName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}SelectInput`),
|
|
418
463
|
selectFieldName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}SelectField`),
|
|
419
464
|
switcherInputName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}SwitcherInput`),
|
|
@@ -425,7 +470,7 @@ function getEnumMetadata({ enumerator: { name, schemaConfig: config }, }) {
|
|
|
425
470
|
membersList: Types.toVariableName(`${(0, string_1.toCamelCase)(name)}Members`),
|
|
426
471
|
membersMap: Types.toVariableName(`${(0, string_1.toCamelCase)(name)}`),
|
|
427
472
|
filePath: Types.toPath(`${config.paths.modelTypeDefinitionsPath}${(0, string_1.toCamelCase)(name)}.enum`),
|
|
428
|
-
importPath: Types.
|
|
473
|
+
importPath: Types.toBackendModulePath(`@backend/types`),
|
|
429
474
|
sourceName: name,
|
|
430
475
|
},
|
|
431
476
|
};
|
|
@@ -7,10 +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
|
-
* Project scope to use in TypeScript imports (e.g. `mca` for `@mca/types`).
|
|
12
|
-
*/
|
|
13
|
-
project: string;
|
|
14
10
|
/**
|
|
15
11
|
* Indicates whether the generator should be ignored
|
|
16
12
|
*/
|
|
@@ -55,72 +51,72 @@ export type SchemaConfig = {
|
|
|
55
51
|
* NOTE: Metadata assumes that project is set up so that certain parts of the code
|
|
56
52
|
* may reference actions using `@project/actions` import.
|
|
57
53
|
*/
|
|
58
|
-
actionsPath: Types.
|
|
54
|
+
actionsPath: Types.FilePath;
|
|
59
55
|
/**
|
|
60
56
|
* Path to the directory containing business logic.
|
|
61
57
|
*
|
|
62
58
|
* NOTE: Metadata assumes that project is set up so that certain parts of the code
|
|
63
59
|
* may reference mock data using `@project/business-logic` import.
|
|
64
60
|
*/
|
|
65
|
-
businessLogicPath: Types.
|
|
61
|
+
businessLogicPath: Types.FilePath;
|
|
66
62
|
/**
|
|
67
63
|
* Path to the directory containing Cypress project.
|
|
68
64
|
*/
|
|
69
|
-
cypressPath: Types.
|
|
65
|
+
cypressPath: Types.FilePath;
|
|
70
66
|
/**
|
|
71
67
|
* Path to the directory containing e2e tests.
|
|
72
68
|
*/
|
|
73
|
-
e2eLibPath: Types.
|
|
69
|
+
e2eLibPath: Types.FilePath;
|
|
74
70
|
/**
|
|
75
71
|
* Path to the directory containing data library definitions.
|
|
76
72
|
*
|
|
77
73
|
* NOTE: Metadata assumes that project is set up so that certain parts of the code
|
|
78
74
|
* may reference data library using `@project/data` import.
|
|
79
75
|
*/
|
|
80
|
-
dataLibPath: Types.
|
|
76
|
+
dataLibPath: Types.FilePath;
|
|
81
77
|
/**
|
|
82
78
|
* Path to the directory containing import-export module.
|
|
83
79
|
*
|
|
84
80
|
* NOTE: Metadata assumes that project is set up so that certain parts of the code
|
|
85
81
|
* may reference import-export using `@project/import-export` import.
|
|
86
82
|
*/
|
|
87
|
-
importExportPath: Types.
|
|
83
|
+
importExportPath: Types.FilePath;
|
|
88
84
|
/**
|
|
89
85
|
* Path to the directory containing Prisma migrations.
|
|
90
86
|
*/
|
|
91
|
-
migrationsFolderPath: Types.
|
|
87
|
+
migrationsFolderPath: Types.FilePath;
|
|
92
88
|
/**
|
|
93
89
|
* Path to the directory containing model type definitions.
|
|
94
90
|
*
|
|
95
91
|
* NOTE: Metadata assumes that project is set up so that certain parts of the code
|
|
96
92
|
* may reference type definitions using `@project/types` import.
|
|
97
93
|
*/
|
|
98
|
-
modelTypeDefinitionsPath: Types.
|
|
94
|
+
modelTypeDefinitionsPath: Types.FilePath;
|
|
99
95
|
/**
|
|
100
96
|
* Path to the directory containing React components.
|
|
101
97
|
*
|
|
102
98
|
* NOTE: Metadata assumes that the project is set up so that React components
|
|
103
99
|
* may be referenced using `@project/react` import.
|
|
104
100
|
*/
|
|
105
|
-
reactFolderPath: Types.
|
|
101
|
+
reactFolderPath: Types.FilePath;
|
|
106
102
|
/**
|
|
107
103
|
* Path to the directory containing seed module.
|
|
108
104
|
*
|
|
109
105
|
* NOTE: Metadata assumes that project is set up so that certain parts of the code
|
|
110
106
|
* may reference mock data using `@project/seed` import.
|
|
111
107
|
*/
|
|
112
|
-
seedLibPath: Types.
|
|
108
|
+
seedLibPath: Types.FilePath;
|
|
113
109
|
/**
|
|
114
110
|
* Path to the directory containing mock data samples.
|
|
115
111
|
*
|
|
116
112
|
* NOTE: Metadata assumes that project is set up so that certain parts of the code
|
|
117
113
|
* may reference mock data using `@project/seed-data` import.
|
|
118
114
|
*/
|
|
119
|
-
seedDataPath: Types.
|
|
115
|
+
seedDataPath: Types.FilePath;
|
|
120
116
|
/**
|
|
121
117
|
* Path to the directory containing trpc routes.
|
|
122
118
|
*/
|
|
123
|
-
trpcRoutesFolderPath: Types.
|
|
119
|
+
trpcRoutesFolderPath: Types.FilePath;
|
|
124
120
|
};
|
|
125
121
|
/**
|
|
126
122
|
* Whether the generator should overwrite existing files.
|
|
@@ -49,6 +49,22 @@ export type TypeName = string & {
|
|
|
49
49
|
* Brands a raw string to a TypeScript Type identifier.
|
|
50
50
|
*/
|
|
51
51
|
export declare const toTypeName: (t: string) => TypeName;
|
|
52
|
+
/**
|
|
53
|
+
* A TypeName that is annotated with the kind of the type.
|
|
54
|
+
* Note: This is used when distinguishing between kinds is required at runtime.
|
|
55
|
+
*/
|
|
56
|
+
export type AnnotatedTypeName = {
|
|
57
|
+
typeName: TypeName;
|
|
58
|
+
kind: 'TypeName';
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Converts a branded string to a branded TypeName.
|
|
62
|
+
*/
|
|
63
|
+
export declare const toAnnotatedTypeName: (name: TypeName) => AnnotatedTypeName;
|
|
64
|
+
/**
|
|
65
|
+
* Type guard to check if a given type is an AnnotatedTypeName.
|
|
66
|
+
*/
|
|
67
|
+
export declare const isAnnotatedTypeName: (t: string | AnnotatedTypeName) => t is AnnotatedTypeName;
|
|
52
68
|
/**
|
|
53
69
|
* The name of a model field, e.g. "name".
|
|
54
70
|
*/
|
|
@@ -114,14 +130,28 @@ export declare const toFolderName: (t: string) => FolderName;
|
|
|
114
130
|
/**
|
|
115
131
|
* A relative or absolute path to a file or folder.
|
|
116
132
|
*/
|
|
117
|
-
export type
|
|
118
|
-
readonly ___type: '
|
|
133
|
+
export type FilePath = string & {
|
|
134
|
+
readonly ___type: 'FilePath';
|
|
119
135
|
};
|
|
120
136
|
/**
|
|
121
|
-
* Converts a string to a branded
|
|
137
|
+
* Converts a string to a branded BackendModulePath.
|
|
122
138
|
*/
|
|
123
|
-
export declare const
|
|
139
|
+
export declare const toBackendModulePath: (t: `@backend/${string}`) => BackendModulePath;
|
|
140
|
+
/**
|
|
141
|
+
* A relative or absolute path to a backend file or folder.
|
|
142
|
+
*/
|
|
143
|
+
export type BackendModulePath = `@backend/${string}` & {
|
|
144
|
+
readonly ___type: 'BackendModulePath';
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Converts a string to a branded PAth.
|
|
148
|
+
*/
|
|
149
|
+
export declare const toPath: (t: string) => FilePath;
|
|
124
150
|
/**
|
|
125
151
|
* Branded string values that can be used as import statement values in the generators
|
|
126
152
|
*/
|
|
127
|
-
export type ImportableTypes = FunctionName | ClassName |
|
|
153
|
+
export type ImportableTypes = FunctionName | ClassName | AnnotatedTypeName | VariableName;
|
|
154
|
+
/**
|
|
155
|
+
* Branded string values that can be used as paths in import statements
|
|
156
|
+
*/
|
|
157
|
+
export type ImportPaths = BackendModulePath | FilePath;
|
package/dist/lib/schema/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// MARK: - Generated content related types
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.toPath = exports.toFolderName = exports.toFileName = exports.toVariableName = exports.toFunctionName = exports.toEnumName = exports.toFieldName = exports.toTypeName = exports.toModelName = exports.toDiscriminantName = exports.toClassName = void 0;
|
|
4
|
+
exports.toPath = exports.toBackendModulePath = exports.toFolderName = exports.toFileName = exports.toVariableName = exports.toFunctionName = exports.toEnumName = exports.toFieldName = exports.isAnnotatedTypeName = exports.toAnnotatedTypeName = exports.toTypeName = exports.toModelName = exports.toDiscriminantName = exports.toClassName = void 0;
|
|
5
5
|
/**
|
|
6
6
|
* Converts a raw string to a branded ClassName.
|
|
7
7
|
*/
|
|
@@ -22,6 +22,19 @@ exports.toModelName = toModelName;
|
|
|
22
22
|
*/
|
|
23
23
|
const toTypeName = (t) => t;
|
|
24
24
|
exports.toTypeName = toTypeName;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a branded string to a branded TypeName.
|
|
27
|
+
*/
|
|
28
|
+
const toAnnotatedTypeName = (name) => ({
|
|
29
|
+
typeName: name,
|
|
30
|
+
kind: 'TypeName',
|
|
31
|
+
});
|
|
32
|
+
exports.toAnnotatedTypeName = toAnnotatedTypeName;
|
|
33
|
+
/**
|
|
34
|
+
* Type guard to check if a given type is an AnnotatedTypeName.
|
|
35
|
+
*/
|
|
36
|
+
const isAnnotatedTypeName = (t) => typeof t === 'object' && t.kind === 'TypeName';
|
|
37
|
+
exports.isAnnotatedTypeName = isAnnotatedTypeName;
|
|
25
38
|
/**
|
|
26
39
|
* Brands a raw string to a FieldName identifier.
|
|
27
40
|
*/
|
|
@@ -55,7 +68,12 @@ exports.toFileName = toFileName;
|
|
|
55
68
|
const toFolderName = (t) => t;
|
|
56
69
|
exports.toFolderName = toFolderName;
|
|
57
70
|
/**
|
|
58
|
-
* Converts a string to a branded
|
|
71
|
+
* Converts a string to a branded BackendModulePath.
|
|
72
|
+
*/
|
|
73
|
+
const toBackendModulePath = (t) => t;
|
|
74
|
+
exports.toBackendModulePath = toBackendModulePath;
|
|
75
|
+
/**
|
|
76
|
+
* Converts a string to a branded PAth.
|
|
59
77
|
*/
|
|
60
78
|
const toPath = (t) => t;
|
|
61
79
|
exports.toPath = toPath;
|
package/dist/lib/types.d.ts
CHANGED
package/dist/lib/types.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ExhaustiveSwitchCheck = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Makes a type check that is only valid when all cases of a switch
|
|
6
|
-
* statement have been
|
|
6
|
+
* statement have been covered.
|
|
7
7
|
*/
|
|
8
8
|
class ExhaustiveSwitchCheck extends Error {
|
|
9
9
|
constructor(val) {
|
|
@@ -18,6 +18,10 @@ export declare const toPascalCase: (str: string) => string;
|
|
|
18
18
|
* Returns a pluralized version of the given string based on the count.
|
|
19
19
|
*/
|
|
20
20
|
export declare const pluralize: (s: string, count?: number) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Returns true if the given string is already pluralized.
|
|
23
|
+
*/
|
|
24
|
+
export declare const isPlural: (s: string) => boolean;
|
|
21
25
|
/**
|
|
22
26
|
* Converts each line of a string to a commented line
|
|
23
27
|
*/
|
package/dist/lib/utils/string.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.conjugateNames = exports.commentLines = exports.pluralize = exports.toPascalCase = exports.toCamelCase = exports.capitalize = exports.uncapitalize = void 0;
|
|
3
|
+
exports.conjugateNames = exports.commentLines = exports.isPlural = exports.pluralize = exports.toPascalCase = exports.toCamelCase = exports.capitalize = exports.uncapitalize = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Returns the same string with a lowercase first letter.
|
|
6
6
|
*/
|
|
@@ -47,6 +47,7 @@ const IRREGULAR_PLURALS = Object.entries({
|
|
|
47
47
|
axis: 'axes',
|
|
48
48
|
basis: 'bases',
|
|
49
49
|
child: 'children',
|
|
50
|
+
children: 'children',
|
|
50
51
|
crisis: 'crises',
|
|
51
52
|
criterion: 'criteria',
|
|
52
53
|
data: 'data',
|
|
@@ -64,6 +65,7 @@ const IRREGULAR_PLURALS = Object.entries({
|
|
|
64
65
|
phenomenon: 'phenomena',
|
|
65
66
|
prognosis: 'prognoses',
|
|
66
67
|
radius: 'radii',
|
|
68
|
+
status: 'statuses',
|
|
67
69
|
suffix: 'suffixes',
|
|
68
70
|
syllabus: 'syllabi',
|
|
69
71
|
synopsis: 'synopses',
|
|
@@ -73,14 +75,14 @@ const IRREGULAR_PLURALS = Object.entries({
|
|
|
73
75
|
* Returns a pluralized version of the given string based on the count.
|
|
74
76
|
*/
|
|
75
77
|
const pluralize = (s, count = 2) => {
|
|
76
|
-
// NOTE: If there's one of something we simply use the
|
|
78
|
+
// NOTE: If there's one of something we simply use the singular form.
|
|
77
79
|
if (count === 1) {
|
|
78
80
|
return s;
|
|
79
81
|
}
|
|
80
82
|
// NOTE: For plural forms, we first check whether a word is irregular.
|
|
81
83
|
const lower = s.toLowerCase();
|
|
82
84
|
for (const [singular, plural] of IRREGULAR_PLURALS) {
|
|
83
|
-
// NOTE: We check that items *end with* a given word
|
|
85
|
+
// NOTE: We check that items *end with* a given word because we use combined words
|
|
84
86
|
// like `UserHistory` as input values of this function.
|
|
85
87
|
if (lower.endsWith(singular)) {
|
|
86
88
|
return s.slice(0, -singular.length + 1) + plural.slice(1);
|
|
@@ -100,6 +102,14 @@ const pluralize = (s, count = 2) => {
|
|
|
100
102
|
return s + 's';
|
|
101
103
|
};
|
|
102
104
|
exports.pluralize = pluralize;
|
|
105
|
+
/**
|
|
106
|
+
* Returns true if the given string is already pluralized.
|
|
107
|
+
*/
|
|
108
|
+
const isPlural = (s) => {
|
|
109
|
+
const plural = (0, exports.pluralize)(s);
|
|
110
|
+
return plural === s;
|
|
111
|
+
};
|
|
112
|
+
exports.isPlural = isPlural;
|
|
103
113
|
/**
|
|
104
114
|
* Converts each line of a string to a commented line
|
|
105
115
|
*/
|
package/dist/prisma/parse.js
CHANGED
|
@@ -60,6 +60,9 @@ function isModelNotIgnored(model) {
|
|
|
60
60
|
* Parses the core properties of a model without fields.
|
|
61
61
|
*/
|
|
62
62
|
function parseModelCore({ dmmfModel, config, }) {
|
|
63
|
+
if ((0, string_1.isPlural)(dmmfModel.name)) {
|
|
64
|
+
(0, error_1.throwError)(`Model ${dmmfModel.name} is plural. Please use singular names for models.`);
|
|
65
|
+
}
|
|
63
66
|
const attributes = (0, attributes_1.getModelAttributes)(dmmfModel);
|
|
64
67
|
return {
|
|
65
68
|
name: Types.toModelName((0, string_1.toPascalCase)(dmmfModel.name)),
|