@postxl/generator 0.37.0 → 0.38.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/dist/generator.js +45 -20
- package/dist/generators/indices/datamocker.generator.js +1 -1
- package/dist/generators/indices/dataservice.generator.js +5 -4
- package/dist/generators/models/businesslogic-view.generator.js +7 -7
- package/dist/generators/models/repository.generator.js +27 -27
- package/dist/generators/models/route.generator.js +1 -1
- package/dist/lib/vfs.d.ts +1 -1
- package/package.json +2 -1
package/dist/generator.js
CHANGED
|
@@ -34,20 +34,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
34
34
|
};
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.generate = void 0;
|
|
37
|
-
const lock_1 = require("@postxl/lock");
|
|
38
37
|
const generator_helper_1 = require("@prisma/generator-helper");
|
|
39
38
|
const internals_1 = require("@prisma/internals");
|
|
40
39
|
const prettier = __importStar(require("prettier"));
|
|
41
40
|
const zod_1 = require("zod");
|
|
41
|
+
const lock_1 = require("@postxl/lock");
|
|
42
42
|
const react_generator_1 = require("./generators/enums/react.generator");
|
|
43
43
|
const types_generator_1 = require("./generators/enums/types.generator");
|
|
44
|
+
const businesslogic_actiontypes_generator_1 = require("./generators/indices/businesslogic-actiontypes.generator");
|
|
45
|
+
const businesslogic_update_index_generator_1 = require("./generators/indices/businesslogic-update-index.generator");
|
|
46
|
+
const businesslogic_update_module_generator_1 = require("./generators/indices/businesslogic-update-module.generator");
|
|
47
|
+
const businesslogic_update_service_generator_1 = require("./generators/indices/businesslogic-update-service.generator");
|
|
48
|
+
const businesslogic_view_index_generator_1 = require("./generators/indices/businesslogic-view-index.generator");
|
|
49
|
+
const businesslogic_view_module_generator_1 = require("./generators/indices/businesslogic-view-module.generator");
|
|
50
|
+
const businesslogic_view_service_generator_1 = require("./generators/indices/businesslogic-view-service.generator");
|
|
44
51
|
const datamock_module_generator_1 = require("./generators/indices/datamock-module.generator");
|
|
52
|
+
const datamocker_generator_1 = require("./generators/indices/datamocker.generator");
|
|
45
53
|
const datamodule_generator_1 = require("./generators/indices/datamodule.generator");
|
|
46
54
|
const dataservice_generator_1 = require("./generators/indices/dataservice.generator");
|
|
55
|
+
const dispatcher_service_generator_1 = require("./generators/indices/dispatcher-service.generator");
|
|
47
56
|
const emptydatabasemigration_generator_1 = require("./generators/indices/emptydatabasemigration.generator");
|
|
48
57
|
const repositories_generator_1 = require("./generators/indices/repositories.generator");
|
|
58
|
+
const seed_migration_generator_1 = require("./generators/indices/seed-migration.generator");
|
|
59
|
+
const seed_service_generator_1 = require("./generators/indices/seed-service.generator");
|
|
60
|
+
const seed_template_generator_1 = require("./generators/indices/seed-template.generator");
|
|
61
|
+
const seed_template_decoder_generator_1 = require("./generators/indices/seed-template-decoder.generator");
|
|
62
|
+
const seeddata_type_generator_1 = require("./generators/indices/seeddata-type.generator");
|
|
49
63
|
const stubs_generator_1 = require("./generators/indices/stubs.generator");
|
|
50
64
|
const types_generator_2 = require("./generators/indices/types.generator");
|
|
65
|
+
const businesslogic_update_generator_1 = require("./generators/models/businesslogic-update.generator");
|
|
66
|
+
const businesslogic_view_generator_1 = require("./generators/models/businesslogic-view.generator");
|
|
51
67
|
const react_generator_2 = require("./generators/models/react.generator");
|
|
52
68
|
const repository_generator_1 = require("./generators/models/repository.generator");
|
|
53
69
|
const route_generator_1 = require("./generators/models/route.generator");
|
|
@@ -57,22 +73,6 @@ const types_generator_3 = require("./generators/models/types.generator");
|
|
|
57
73
|
const meta_1 = require("./lib/meta");
|
|
58
74
|
const types_1 = require("./lib/schema/types");
|
|
59
75
|
const vfs_1 = require("./lib/vfs");
|
|
60
|
-
const businesslogic_actiontypes_generator_1 = require("./generators/indices/businesslogic-actiontypes.generator");
|
|
61
|
-
const businesslogic_update_index_generator_1 = require("./generators/indices/businesslogic-update-index.generator");
|
|
62
|
-
const businesslogic_update_module_generator_1 = require("./generators/indices/businesslogic-update-module.generator");
|
|
63
|
-
const businesslogic_update_service_generator_1 = require("./generators/indices/businesslogic-update-service.generator");
|
|
64
|
-
const businesslogic_view_index_generator_1 = require("./generators/indices/businesslogic-view-index.generator");
|
|
65
|
-
const businesslogic_view_module_generator_1 = require("./generators/indices/businesslogic-view-module.generator");
|
|
66
|
-
const businesslogic_view_service_generator_1 = require("./generators/indices/businesslogic-view-service.generator");
|
|
67
|
-
const datamocker_generator_1 = require("./generators/indices/datamocker.generator");
|
|
68
|
-
const dispatcher_service_generator_1 = require("./generators/indices/dispatcher-service.generator");
|
|
69
|
-
const seed_migration_generator_1 = require("./generators/indices/seed-migration.generator");
|
|
70
|
-
const seed_service_generator_1 = require("./generators/indices/seed-service.generator");
|
|
71
|
-
const seed_template_decoder_generator_1 = require("./generators/indices/seed-template-decoder.generator");
|
|
72
|
-
const seed_template_generator_1 = require("./generators/indices/seed-template.generator");
|
|
73
|
-
const seeddata_type_generator_1 = require("./generators/indices/seeddata-type.generator");
|
|
74
|
-
const businesslogic_update_generator_1 = require("./generators/models/businesslogic-update.generator");
|
|
75
|
-
const businesslogic_view_generator_1 = require("./generators/models/businesslogic-view.generator");
|
|
76
76
|
const client_path_1 = require("./prisma/client-path");
|
|
77
77
|
const parse_1 = require("./prisma/parse");
|
|
78
78
|
const CONFIG_SCHEMA = zod_1.z
|
|
@@ -249,9 +249,7 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
249
249
|
}
|
|
250
250
|
// -------------------------------------------------------------------------
|
|
251
251
|
// Add disclaimer and format.
|
|
252
|
-
const prettierConfig = yield prettier.resolveConfig(process.cwd());
|
|
253
252
|
yield generated.transformUTF8Files((path, content) => `${DISCLAIMER}\n${content}`);
|
|
254
|
-
yield generated.formatUTF8Files(prettierConfig);
|
|
255
253
|
const lintResult = yield generated.lintUTF8Files({
|
|
256
254
|
fix: true,
|
|
257
255
|
useEslintrc: false,
|
|
@@ -260,7 +258,7 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
260
258
|
overrideConfig: {
|
|
261
259
|
parser: '@typescript-eslint/parser',
|
|
262
260
|
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
|
|
263
|
-
plugins: ['@typescript-eslint'],
|
|
261
|
+
plugins: ['@typescript-eslint', 'simple-import-sort'],
|
|
264
262
|
parserOptions: {
|
|
265
263
|
sourceType: 'module',
|
|
266
264
|
ecmaVersion: 'latest',
|
|
@@ -273,6 +271,31 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
273
271
|
// The "curly" rule ensures that all if, else if, else, for, while, or do blocks are followed by a block in braces, even if it is only a single line.
|
|
274
272
|
// This will flag `if(condition) return x` and expect it to be written as `if (condition) { return x }`
|
|
275
273
|
curly: ['error', 'all'],
|
|
274
|
+
// NOTE: Make sure this matches the definition in the template root .eslintrc.cjs file!
|
|
275
|
+
'simple-import-sort/imports': [
|
|
276
|
+
'error',
|
|
277
|
+
{
|
|
278
|
+
groups: [
|
|
279
|
+
// Node.js builtins. You could also generate this regex if you use a `.js` config
|
|
280
|
+
// (e.g. `^(${require("module").builtinModules.join("|")})(/|$)`)
|
|
281
|
+
[
|
|
282
|
+
'^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)',
|
|
283
|
+
],
|
|
284
|
+
// Side effect imports.
|
|
285
|
+
['^\\u0000'],
|
|
286
|
+
// Any packages that starts with an @ but not libraries we defined in tsconfig.json:
|
|
287
|
+
['^@(?!(pxl|postxl|assets|hooks|components|i18n|lib))'],
|
|
288
|
+
// Any other package.
|
|
289
|
+
['^'],
|
|
290
|
+
// Internal PXL packages.
|
|
291
|
+
['^(@pxl|@postxl|@assets|@hooks|@components|@i18n|@lib)(/.*|$)'],
|
|
292
|
+
// Parent imports. Put `..` last.
|
|
293
|
+
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
|
|
294
|
+
// Other relative imports. Put same-folder imports and `.` last.
|
|
295
|
+
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
],
|
|
276
299
|
},
|
|
277
300
|
},
|
|
278
301
|
});
|
|
@@ -292,6 +315,8 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
292
315
|
if (unfixedWarningCount === 0 && unfixableErrorCount === 0) {
|
|
293
316
|
console.log(`LINT: All files linted successfully without warnings and errors!`);
|
|
294
317
|
}
|
|
318
|
+
const prettierConfig = yield prettier.resolveConfig(process.cwd());
|
|
319
|
+
yield generated.formatUTF8Files(prettierConfig);
|
|
295
320
|
// -------------------------------------------------------------------------
|
|
296
321
|
// Merge with existing files.
|
|
297
322
|
yield vfs.copy(generated, './');
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateDataMocker = void 0;
|
|
4
|
+
const imports_1 = require("../../lib/imports");
|
|
4
5
|
const meta_1 = require("../../lib/meta");
|
|
5
6
|
const schema_1 = require("../../lib/schema/schema");
|
|
6
|
-
const imports_1 = require("../../lib/imports");
|
|
7
7
|
/**
|
|
8
8
|
* Generates a generic data mocker class.
|
|
9
9
|
*/
|
|
@@ -20,11 +20,12 @@ function generateDataService({ models, meta }) {
|
|
|
20
20
|
.join(',\n');
|
|
21
21
|
const initializer = mm.map(({ meta }) => `await this.${meta.data.dataServiceName}.init()`).join('\n');
|
|
22
22
|
const excelExports = mm
|
|
23
|
-
.map(({ meta }) => `${meta.data.excelExportTableName}: mapValues(this.${meta.data.dataServiceName}.getAll()),`)
|
|
23
|
+
.map(({ meta }) => `${meta.data.excelExportTableName}: mapValues(await this.${meta.data.dataServiceName}.getAll()),`)
|
|
24
24
|
.join('\n');
|
|
25
|
-
const isEmptyChecks = mm.map(({ meta }) => `this.${meta.data.dataServiceName}.count() === 0`).join(' &&');
|
|
25
|
+
const isEmptyChecks = mm.map(({ meta }) => `(await this.${meta.data.dataServiceName}.count()) === 0`).join(' &&');
|
|
26
26
|
return `
|
|
27
27
|
import { Injectable } from '@nestjs/common'
|
|
28
|
+
|
|
28
29
|
import { mapValues } from '@pxl/common'
|
|
29
30
|
|
|
30
31
|
${imports.generate()}
|
|
@@ -33,7 +34,7 @@ ${imports.generate()}
|
|
|
33
34
|
export class DataService {
|
|
34
35
|
constructor(${constructor}) {}
|
|
35
36
|
|
|
36
|
-
public prepareExcelExport() {
|
|
37
|
+
public async prepareExcelExport() {
|
|
37
38
|
return {
|
|
38
39
|
${excelExports}
|
|
39
40
|
}
|
|
@@ -43,7 +44,7 @@ export class DataService {
|
|
|
43
44
|
${initializer}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
public isEmpty(): boolean {
|
|
47
|
+
public async isEmpty(): Promise<boolean> {
|
|
47
48
|
return (
|
|
48
49
|
${isEmptyChecks}
|
|
49
50
|
)
|
|
@@ -41,7 +41,7 @@ function generateModelBusinessLogicView({ model, meta }) {
|
|
|
41
41
|
for (const relation of (0, fields_1.getRelationFields)(model)) {
|
|
42
42
|
const refModel = relation.relationToModel;
|
|
43
43
|
const refMeta = (0, meta_1.getModelMetadata)({ model: refModel });
|
|
44
|
-
const variableGetter = `this.${viewServiceClassName}.${refMeta.businessLogic.view.serviceVariableName}.get(itemRaw.${relation.name})`;
|
|
44
|
+
const variableGetter = `await this.${viewServiceClassName}.${refMeta.businessLogic.view.serviceVariableName}.get(itemRaw.${relation.name})`;
|
|
45
45
|
const variablePresenceCheck = `
|
|
46
46
|
if (!${relation.relatedModelBacklinkFieldName}) {
|
|
47
47
|
throw new Error(\`Could not find ${refMeta.types.typeName} with id \${itemRaw.${relation.name}} for ${model.typeName}.${relation.name}!\`)
|
|
@@ -66,8 +66,8 @@ function generateModelBusinessLogicView({ model, meta }) {
|
|
|
66
66
|
* Returns the linked ${meta.userFriendlyName} with the given id or null if it does not exist.
|
|
67
67
|
* Linked: The ${meta.userFriendlyName} contains the linked (raw) items themselves, not only the ids.
|
|
68
68
|
*/
|
|
69
|
-
public getLinkedItem(id: ${model.brandedIdType}):
|
|
70
|
-
const itemRaw = this.${modelRepositoryVariableName}.get(id)
|
|
69
|
+
public async getLinkedItem(id: ${model.brandedIdType}): Promise<${meta.types.linkedTypeName} | null> {
|
|
70
|
+
const itemRaw = await this.${modelRepositoryVariableName}.get(id)
|
|
71
71
|
if (!itemRaw) {
|
|
72
72
|
return null
|
|
73
73
|
}
|
|
@@ -107,7 +107,7 @@ export class ${meta.businessLogic.view.serviceClassName} {
|
|
|
107
107
|
* Returns the raw ${meta.userFriendlyName} with the given id or null if it does not exist.
|
|
108
108
|
* Raw: The ${meta.userFriendlyName} only contains linked Ids, not the linked items themselves.
|
|
109
109
|
*/
|
|
110
|
-
public get(id: ${model.brandedIdType}):
|
|
110
|
+
public async get(id: ${model.brandedIdType}): Promise<${meta.types.typeName} | null> {
|
|
111
111
|
return this.${modelRepositoryVariableName}.get(id)
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -116,14 +116,14 @@ export class ${meta.businessLogic.view.serviceClassName} {
|
|
|
116
116
|
/**
|
|
117
117
|
* Returns a map of all ${meta.userFriendlyNamePlural}.
|
|
118
118
|
*/
|
|
119
|
-
public getAll(): Map<${meta.types.brandedIdType}, ${model.typeName}
|
|
119
|
+
public async getAll(): Promise<Map<${meta.types.brandedIdType}, ${model.typeName}>> {
|
|
120
120
|
return this.${modelRepositoryVariableName}.getAll()
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
124
|
* Returns a list of filtered, sorted and paginated ${meta.userFriendlyNamePlural}.
|
|
125
125
|
*/
|
|
126
|
-
public getList({
|
|
126
|
+
public async getList({
|
|
127
127
|
filter,
|
|
128
128
|
sort,
|
|
129
129
|
cursor,
|
|
@@ -132,7 +132,7 @@ export class ${meta.businessLogic.view.serviceClassName} {
|
|
|
132
132
|
sort?: { field: keyof ${model.typeName}; ascending: boolean }
|
|
133
133
|
cursor?: { startRow: number; endRow: number }
|
|
134
134
|
}) {
|
|
135
|
-
const items = this.data.getAllAsArray()
|
|
135
|
+
const items = await this.data.getAllAsArray()
|
|
136
136
|
const filtered = !filter
|
|
137
137
|
? items
|
|
138
138
|
: items.filter((item) => filterFn(item, filter.field, filter.operator, filter.value))
|
|
@@ -109,33 +109,33 @@ export class ${meta.data.repositoryClassName} implements Repository<${model.type
|
|
|
109
109
|
|
|
110
110
|
${mainBlocks.deleteAllCode}
|
|
111
111
|
|
|
112
|
-
public get(id: ${model.brandedIdType} | null):
|
|
112
|
+
public async get(id: ${model.brandedIdType} | null): Promise<${model.typeName} | null> {
|
|
113
113
|
if (id === null) {
|
|
114
|
-
return null
|
|
114
|
+
return Promise.resolve(null)
|
|
115
115
|
}
|
|
116
|
-
return this.data.get(id) ?? null
|
|
116
|
+
return Promise.resolve(this.data.get(id) ?? null)
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
public getAll(): Map<${model.brandedIdType}, ${model.typeName}
|
|
120
|
-
return new Map(this.data)
|
|
119
|
+
public async getAll(): Promise<Map<${model.brandedIdType}, ${model.typeName}>> {
|
|
120
|
+
return Promise.resolve(new Map(this.data))
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
public getAllAsArray():
|
|
124
|
-
return Array.from(this.data.values())
|
|
123
|
+
public async getAllAsArray(): Promise<${model.typeName}[]> {
|
|
124
|
+
return Promise.resolve(Array.from(this.data.values()))
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
${indexBlocks.getterFunctions.join('\n')}
|
|
128
128
|
|
|
129
|
-
public filter(predicate: (item: ${model.typeName}) => boolean):
|
|
130
|
-
return this.getAllAsArray().filter(predicate)
|
|
129
|
+
public async filter(predicate: (item: ${model.typeName}) => boolean): Promise<${model.typeName}[]> {
|
|
130
|
+
return (await this.getAllAsArray()).filter(predicate)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
public findFirst(predicate: (item: ${model.typeName}) => boolean):
|
|
134
|
-
return this.getAllAsArray().find(predicate) ?? null
|
|
133
|
+
public async findFirst(predicate: (item: ${model.typeName}) => boolean): Promise<${model.typeName} | null> {
|
|
134
|
+
return (await this.getAllAsArray()).find(predicate) ?? null
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
public count(): number {
|
|
138
|
-
return this.data.size
|
|
137
|
+
public async count(): Promise<number> {
|
|
138
|
+
return Promise.resolve(this.data.size)
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
${mainBlocks.createCode}
|
|
@@ -313,7 +313,7 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, blocks, }) {
|
|
|
313
313
|
public async update(
|
|
314
314
|
{ item, execution }: ${methodTypeSignatures.update.parameters[0]}
|
|
315
315
|
): ${methodTypeSignatures.update.returnType} {
|
|
316
|
-
const existingItem = this.get(item.id)
|
|
316
|
+
const existingItem = await this.get(item.id)
|
|
317
317
|
|
|
318
318
|
if (!existingItem) {
|
|
319
319
|
throw new Error(\`Could not update ${meta.userFriendlyName} with id \${item.id}. Not found!\`)
|
|
@@ -363,7 +363,7 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, blocks, }) {
|
|
|
363
363
|
public async upsert(
|
|
364
364
|
{ item, execution }: ${methodTypeSignatures.upsert.parameters[0]}
|
|
365
365
|
): ${methodTypeSignatures.upsert.returnType} {
|
|
366
|
-
const existingItem = item.${model.idField.name} ? this.get(item.${model.idField.name}) : null
|
|
366
|
+
const existingItem = item.${model.idField.name} ? (await this.get(item.${model.idField.name})) : null
|
|
367
367
|
if (existingItem) {
|
|
368
368
|
return this.update({ item: item as ${meta.types.dto.update}, execution })
|
|
369
369
|
} else {
|
|
@@ -391,7 +391,7 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, blocks, }) {
|
|
|
391
391
|
public async delete(
|
|
392
392
|
{ id, execution }: ${methodTypeSignatures.delete.parameters[0]}
|
|
393
393
|
): ${methodTypeSignatures.delete.returnType} {
|
|
394
|
-
const existingItem = this.get(id)
|
|
394
|
+
const existingItem = await this.get(id)
|
|
395
395
|
if (!existingItem) {
|
|
396
396
|
throw new Error(\`Could not delete ${model.typeName} with id \${id}. Not found!\`)
|
|
397
397
|
}
|
|
@@ -599,7 +599,7 @@ function generateMainBuildingBlocks_InDatabase({ model, meta, imports, blocks, }
|
|
|
599
599
|
public async update(
|
|
600
600
|
{ item, execution }: ${methodTypeSignatures.update.parameters[0]}
|
|
601
601
|
): ${methodTypeSignatures.update.returnType} {
|
|
602
|
-
const existingItem = this.get(item.${idField.name})
|
|
602
|
+
const existingItem = await this.get(item.${idField.name})
|
|
603
603
|
if (!existingItem) {
|
|
604
604
|
throw new Error(\`Could not update ${meta.userFriendlyName} with id \${item.id}. Not found!\`)
|
|
605
605
|
}
|
|
@@ -662,7 +662,7 @@ function generateMainBuildingBlocks_InDatabase({ model, meta, imports, blocks, }
|
|
|
662
662
|
public async upsert(
|
|
663
663
|
{ item, execution }: ${methodTypeSignatures.upsert.parameters[0]}
|
|
664
664
|
): ${methodTypeSignatures.upsert.returnType} {
|
|
665
|
-
const existingItem = item.${model.idField.name} ? this.get(item.${model.idField.name}) : null
|
|
665
|
+
const existingItem = item.${model.idField.name} ? (await this.get(item.${model.idField.name})) : null
|
|
666
666
|
if (existingItem) {
|
|
667
667
|
return this.update({ item: item as ${meta.types.dto.update}, execution })
|
|
668
668
|
} else {
|
|
@@ -690,7 +690,7 @@ function generateMainBuildingBlocks_InDatabase({ model, meta, imports, blocks, }
|
|
|
690
690
|
public async delete(
|
|
691
691
|
{ id, execution }: ${methodTypeSignatures.delete.parameters[0]}
|
|
692
692
|
): ${methodTypeSignatures.delete.returnType} {
|
|
693
|
-
const existingItem = this.get(id)
|
|
693
|
+
const existingItem = await this.get(id)
|
|
694
694
|
if (!existingItem) {
|
|
695
695
|
throw new Error(\`Could not delete ${model.typeName} with id \${id}. Not found!\`)
|
|
696
696
|
}
|
|
@@ -1098,28 +1098,28 @@ function generateRelationsBlocks({ model, imports, }) {
|
|
|
1098
1098
|
/**
|
|
1099
1099
|
* Function to retrieve all ${(0, string_1.pluralize)(model.name)} that are related to a ${r.name}
|
|
1100
1100
|
*/
|
|
1101
|
-
public ${fieldMeta.getByForeignKeyMethodFnName}(
|
|
1101
|
+
public async ${fieldMeta.getByForeignKeyMethodFnName}(
|
|
1102
1102
|
id: ${relationModelMeta.types.brandedIdType}
|
|
1103
|
-
): Map<${model.brandedIdType}, ${model.typeName}
|
|
1103
|
+
): Promise<Map<${model.brandedIdType}, ${model.typeName}>> {
|
|
1104
1104
|
const result = this.${r.name}Map.get(id)
|
|
1105
1105
|
if (!result) {
|
|
1106
|
-
return new Map()
|
|
1106
|
+
return Promise.resolve(new Map<${model.brandedIdType}, ${model.typeName}>())
|
|
1107
1107
|
}
|
|
1108
|
-
return new Map(result)
|
|
1108
|
+
return Promise.resolve(new Map(result))
|
|
1109
1109
|
}
|
|
1110
1110
|
|
|
1111
1111
|
/**
|
|
1112
1112
|
* Function to retrieve all ${model.brandedIdType}s that are related to a ${r.name}
|
|
1113
1113
|
*/
|
|
1114
|
-
public ${fieldMeta.getByForeignKeyIdsMethodFnName}(
|
|
1114
|
+
public async ${fieldMeta.getByForeignKeyIdsMethodFnName}(
|
|
1115
1115
|
id: ${relationModelMeta.types.brandedIdType}
|
|
1116
|
-
):
|
|
1116
|
+
): Promise<${model.brandedIdType}[]> {
|
|
1117
1117
|
const s = this.${r.name}Map.get(id)
|
|
1118
1118
|
if (!s) {
|
|
1119
|
-
return []
|
|
1119
|
+
return Promise.resolve([])
|
|
1120
1120
|
}
|
|
1121
1121
|
|
|
1122
|
-
return Array.from(s.keys())
|
|
1122
|
+
return Promise.resolve(Array.from(s.keys()))
|
|
1123
1123
|
}`);
|
|
1124
1124
|
result.setCode.push(`
|
|
1125
1125
|
${!r.isRequired ? `if (item.${r.name}) {` : ''}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateRoutesIndex = exports.generateRoute = void 0;
|
|
4
|
-
const meta_1 = require("../../lib/meta");
|
|
5
4
|
const imports_1 = require("../../lib/imports");
|
|
5
|
+
const meta_1 = require("../../lib/meta");
|
|
6
6
|
/**
|
|
7
7
|
* Generates TRPC route for a given model.
|
|
8
8
|
*/
|
package/dist/lib/vfs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ESLint } from 'eslint';
|
|
2
2
|
import * as prettier from 'prettier';
|
|
3
|
-
import { VirtualFS as BaseVirtualFS
|
|
3
|
+
import { PathUtils, VirtualFS as BaseVirtualFS } from '@postxl/lock';
|
|
4
4
|
type FileLintResult = {
|
|
5
5
|
fixableErrorCount: number;
|
|
6
6
|
errorCount: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postxl/generator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.1",
|
|
4
4
|
"main": "./dist/generator.js",
|
|
5
5
|
"typings": "./dist/generator.d.ts",
|
|
6
6
|
"bin": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"@typescript-eslint/parser": "^6.10.0",
|
|
22
22
|
"@typescript-eslint/utils": "^6.10.0",
|
|
23
23
|
"eslint": "^8.53.0",
|
|
24
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
24
25
|
"exceljs": "^4.3.0",
|
|
25
26
|
"fast-glob": "^3.2.12",
|
|
26
27
|
"prettier": "^3.0.3",
|