@postxl/generator 0.44.3 → 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.
Files changed (43) hide show
  1. package/dist/generator.js +8 -9
  2. package/dist/generators/enums/react.generator.js +1 -1
  3. package/dist/generators/indices/businesslogic-update-module.generator.js +1 -1
  4. package/dist/generators/indices/businesslogic-view-module.generator.js +1 -1
  5. package/dist/generators/indices/data-types.generator.js +4 -3
  6. package/dist/generators/indices/datamock-module.generator.js +3 -3
  7. package/dist/generators/indices/datamocker.generator.js +5 -4
  8. package/dist/generators/indices/datamodule.generator.js +3 -3
  9. package/dist/generators/indices/dataservice.generator.js +5 -4
  10. package/dist/generators/indices/dispatcher-service.generator.js +4 -3
  11. package/dist/generators/indices/importexport-convert-import-functions.generator.js +29 -24
  12. package/dist/generators/indices/importexport-exporter-class.generator.js +4 -3
  13. package/dist/generators/indices/importexport-import-service.generator.js +27 -12
  14. package/dist/generators/indices/importexport-types.generator.js +9 -4
  15. package/dist/generators/indices/stubs.generator.js +2 -2
  16. package/dist/generators/indices/testdata-service.generator.js +5 -2
  17. package/dist/generators/models/businesslogic-update.generator.js +11 -10
  18. package/dist/generators/models/businesslogic-view.generator.js +4 -3
  19. package/dist/generators/models/importexport-decoder.generator.d.ts +2 -1
  20. package/dist/generators/models/importexport-decoder.generator.js +20 -19
  21. package/dist/generators/models/react.generator/context.generator.js +1 -1
  22. package/dist/generators/models/react.generator/index.js +2 -8
  23. package/dist/generators/models/react.generator/library.generator.d.ts +0 -2
  24. package/dist/generators/models/react.generator/library.generator.js +3 -5
  25. package/dist/generators/models/react.generator/lookup.generator.js +3 -6
  26. package/dist/generators/models/react.generator/modals.generator.js +4 -4
  27. package/dist/generators/models/repository.generator.js +26 -17
  28. package/dist/generators/models/route.generator.js +3 -2
  29. package/dist/generators/models/seed.generator.js +5 -4
  30. package/dist/generators/models/stub.generator.js +7 -2
  31. package/dist/generators/models/types.generator.js +7 -3
  32. package/dist/lib/exports.d.ts +2 -2
  33. package/dist/lib/imports.d.ts +12 -3
  34. package/dist/lib/imports.js +47 -15
  35. package/dist/lib/meta.d.ts +163 -88
  36. package/dist/lib/meta.js +68 -23
  37. package/dist/lib/schema/schema.d.ts +15 -18
  38. package/dist/lib/schema/types.d.ts +35 -5
  39. package/dist/lib/schema/types.js +20 -2
  40. package/dist/lib/types.d.ts +1 -1
  41. package/dist/lib/types.js +1 -1
  42. package/dist/prisma/parse.js +7 -9
  43. 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.toPath(`@${config.project}/actions`),
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.toPath(`@${config.project}/business-logic`),
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.toPath(`@${config.project}/business-logic/view`),
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.toPath(`@${config.project}/business-logic/update`),
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.toPath(`@${config.project}/data`),
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.toPath(`@${config.project}/import-export`),
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.toPath(`@${config.project}/seed-data`),
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.toPath(`@${config.project}/seed`),
236
+ importPath: Types.toBackendModulePath(`@backend/seed`),
193
237
  },
194
238
  trpc: {
195
239
  routesFilePath: Types.toPath(`${config.paths.trpcRoutesFolderPath}index`),
196
- importPath: Types.toPath(`@${config.project}/trpc`),
240
+ importPath: Types.toBackendModulePath(`@backend/trpc`),
197
241
  },
198
242
  types: {
199
243
  indexFilePath: Types.toPath(`${config.paths.modelTypeDefinitionsPath}index`),
200
- importPath: Types.toPath(`@${config.project}/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.toPath(`@${config.project}/data`),
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.toPath(`@${config.project}/business-logic`),
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.toPath(`@${config.project}/seed`),
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.toPath(`@${config.project}/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.toPath(`@${config.project}/react/enums/${(0, string_1.toPascalCase)(name)}`),
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.toPath(`@${config.project}/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.Path;
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.Path;
61
+ businessLogicPath: Types.FilePath;
66
62
  /**
67
63
  * Path to the directory containing Cypress project.
68
64
  */
69
- cypressPath: Types.Path;
65
+ cypressPath: Types.FilePath;
70
66
  /**
71
67
  * Path to the directory containing e2e tests.
72
68
  */
73
- e2eLibPath: Types.Path;
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.Path;
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.Path;
83
+ importExportPath: Types.FilePath;
88
84
  /**
89
85
  * Path to the directory containing Prisma migrations.
90
86
  */
91
- migrationsFolderPath: Types.Path;
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.Path;
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.Path;
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.Path;
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.Path;
115
+ seedDataPath: Types.FilePath;
120
116
  /**
121
117
  * Path to the directory containing trpc routes.
122
118
  */
123
- trpcRoutesFolderPath: Types.Path;
119
+ trpcRoutesFolderPath: Types.FilePath;
124
120
  };
125
121
  /**
126
122
  * Whether the generator should overwrite existing files.
@@ -196,9 +192,10 @@ export type ModelFields = {
196
192
  /**
197
193
  * The property of the model that is used to define the name/label
198
194
  *
199
- * By default, this is maps to the `name` field - but using the `@label` attribute, other fields can be used.
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.
200
197
  */
201
- nameField?: FieldScalar;
198
+ nameField: Field;
202
199
  /**
203
200
  * All fields of the model
204
201
  */
@@ -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 Path = string & {
118
- readonly ___type: 'FileName';
133
+ export type FilePath = string & {
134
+ readonly ___type: 'FilePath';
119
135
  };
120
136
  /**
121
- * Converts a string to a branded FileName.
137
+ * Converts a string to a branded BackendModulePath.
122
138
  */
123
- export declare const toPath: (t: string) => Path;
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 | TypeName | VariableName;
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;
@@ -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 FileName.
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;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Makes a type check that is only valid when all cases of a switch
3
- * statement have been convered.
3
+ * statement have been covered.
4
4
  */
5
5
  export declare class ExhaustiveSwitchCheck extends Error {
6
6
  constructor(val: never);
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 convered.
6
+ * statement have been covered.
7
7
  */
8
8
  class ExhaustiveSwitchCheck extends Error {
9
9
  constructor(val) {
@@ -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
- nameFieldFallback = field;
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 && field.kind === 'scalar') {
228
- if (nameField !== undefined) {
228
+ if (field.attributes.isLabel) {
229
+ if (labelField !== undefined) {
229
230
  throw new Error(`❌❌❌ Model ${name} has multiple name fields`);
230
231
  }
231
- nameField = field;
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
- if (!nameField && nameFieldFallback) {
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/generator",
3
- "version": "0.44.3",
3
+ "version": "0.44.5",
4
4
  "main": "./dist/generator.js",
5
5
  "typings": "./dist/generator.d.ts",
6
6
  "bin": {