@postxl/generator 0.59.0 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generators/indices/businesslogic-update-module.generator.js +8 -36
- package/dist/generators/indices/businesslogic-view-module.generator.js +8 -37
- package/dist/generators/indices/datamock-module.generator.js +5 -9
- package/dist/generators/indices/datamodule.generator.js +7 -50
- package/dist/generators/indices/dispatcher-service.generator.js +3 -3
- package/dist/generators/indices/testdata-service.generator.js +6 -6
- package/dist/generators/models/repository.generator.js +2 -2
- package/dist/lib/meta.d.ts +1 -1
- package/dist/lib/meta.js +2 -2
- package/package.json +1 -1
|
@@ -11,7 +11,6 @@ function generateBusinessLogicUpdateModule({ models, meta }) {
|
|
|
11
11
|
.map((model) => ({ model, meta: (0, meta_1.getModelMetadata)({ model }) }))
|
|
12
12
|
.sort((a, b) => a.meta.businessLogic.update.serviceClassName.localeCompare(b.meta.businessLogic.update.serviceClassName));
|
|
13
13
|
const imports = imports_1.ImportsGenerator.from(meta.businessLogic.update.moduleFilePath).addImports({
|
|
14
|
-
[meta.data.importPath]: meta.data.moduleName,
|
|
15
14
|
[meta.businessLogic.update.serviceFilePath]: meta.businessLogic.update.serviceClassName,
|
|
16
15
|
[meta.businessLogic.view.importPath]: meta.businessLogic.view.moduleName,
|
|
17
16
|
});
|
|
@@ -25,45 +24,18 @@ function generateBusinessLogicUpdateModule({ models, meta }) {
|
|
|
25
24
|
}
|
|
26
25
|
const moduleName = meta.businessLogic.update.moduleName;
|
|
27
26
|
return /* ts */ `
|
|
28
|
-
import {
|
|
27
|
+
import { Module } from '@nestjs/common'
|
|
29
28
|
|
|
30
29
|
${imports.generate()}
|
|
31
30
|
|
|
31
|
+
const providers = [${providers.join(', ')}]
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* The getInstance method should be called by any module that needs the module.
|
|
41
|
-
*/
|
|
42
|
-
static getInstance(): DynamicModule {
|
|
43
|
-
if (!${moduleName}.cachedModule) {
|
|
44
|
-
throw new Error('${moduleName} must be called via .forRoot first!')
|
|
45
|
-
}
|
|
46
|
-
return ${moduleName}.cachedModule
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The forRoot method should only be called once by the root module.
|
|
51
|
-
*/
|
|
52
|
-
static forRoot(): DynamicModule {
|
|
53
|
-
if (${moduleName}.cachedModule) {
|
|
54
|
-
throw new Error('${moduleName} is already instantiated, please call .forRoot only once from root...')
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const providers = [${providers.join(', ')}]
|
|
58
|
-
${moduleName}.cachedModule = {
|
|
59
|
-
module: ${moduleName},
|
|
60
|
-
providers,
|
|
61
|
-
imports: [${meta.data.moduleName}.getInstance(), ${meta.businessLogic.view.moduleName}.getInstance()],
|
|
62
|
-
exports: providers,
|
|
63
|
-
}
|
|
64
|
-
return ${moduleName}.cachedModule
|
|
65
|
-
}
|
|
66
|
-
}
|
|
33
|
+
@Module({
|
|
34
|
+
imports: [ViewModule],
|
|
35
|
+
providers,
|
|
36
|
+
exports: providers,
|
|
37
|
+
})
|
|
38
|
+
export class ${moduleName} {}
|
|
67
39
|
`;
|
|
68
40
|
}
|
|
69
41
|
exports.generateBusinessLogicUpdateModule = generateBusinessLogicUpdateModule;
|
|
@@ -11,7 +11,6 @@ function generateBusinessLogicViewModule({ models, meta }) {
|
|
|
11
11
|
.map((model) => ({ model, meta: (0, meta_1.getModelMetadata)({ model }) }))
|
|
12
12
|
.sort((a, b) => a.meta.businessLogic.view.serviceClassName.localeCompare(b.meta.businessLogic.view.serviceClassName));
|
|
13
13
|
const imports = imports_1.ImportsGenerator.from(meta.businessLogic.view.moduleFilePath).addImports({
|
|
14
|
-
[meta.data.importPath]: meta.data.moduleName,
|
|
15
14
|
[meta.businessLogic.view.serviceFilePath]: meta.businessLogic.view.serviceClassName,
|
|
16
15
|
});
|
|
17
16
|
const providers = [meta.businessLogic.view.serviceClassName];
|
|
@@ -24,45 +23,17 @@ function generateBusinessLogicViewModule({ models, meta }) {
|
|
|
24
23
|
}
|
|
25
24
|
const moduleName = meta.businessLogic.view.moduleName;
|
|
26
25
|
return /* ts */ `
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
${imports.generate()}
|
|
26
|
+
import { Module } from '@nestjs/common'
|
|
30
27
|
|
|
28
|
+
${imports.generate()}
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Internal cache for the module instance.
|
|
35
|
-
*/
|
|
36
|
-
private static cachedModule: DynamicModule | undefined = undefined
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The getInstance method should be called by any module that needs the module.
|
|
40
|
-
*/
|
|
41
|
-
static getInstance(): DynamicModule {
|
|
42
|
-
if (!${moduleName}.cachedModule) {
|
|
43
|
-
throw new Error('${moduleName} must be called via .forRoot first!')
|
|
44
|
-
}
|
|
45
|
-
return ${moduleName}.cachedModule
|
|
46
|
-
}
|
|
30
|
+
const providers = [${providers.join(', ')}]
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
throw new Error('${moduleName} is already instantiated, please call .forRoot only once from root...')
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const providers = [${providers.join(', ')}]
|
|
57
|
-
${moduleName}.cachedModule = {
|
|
58
|
-
module: ${moduleName},
|
|
59
|
-
providers,
|
|
60
|
-
imports: [${meta.data.moduleName}.getInstance()],
|
|
61
|
-
exports: providers,
|
|
62
|
-
}
|
|
63
|
-
return ${moduleName}.cachedModule
|
|
64
|
-
}
|
|
65
|
-
}
|
|
32
|
+
@Module({
|
|
33
|
+
providers,
|
|
34
|
+
exports: providers,
|
|
35
|
+
})
|
|
36
|
+
export class ${moduleName} {}
|
|
66
37
|
`;
|
|
67
38
|
}
|
|
68
39
|
exports.generateBusinessLogicViewModule = generateBusinessLogicViewModule;
|
|
@@ -56,8 +56,8 @@ function generateDataMockModule({ models, meta }) {
|
|
|
56
56
|
}`)
|
|
57
57
|
.join(', ');
|
|
58
58
|
return /* ts */ `
|
|
59
|
-
import { DynamicModule } from '@
|
|
60
|
-
import {
|
|
59
|
+
import { DynamicModule } from '@nestjs/common'
|
|
60
|
+
import { DatabaseModule } from '@backend/db'
|
|
61
61
|
|
|
62
62
|
${imports.generate()}
|
|
63
63
|
|
|
@@ -70,17 +70,13 @@ export class ${meta.data.dataMockModuleName} {
|
|
|
70
70
|
${providers}
|
|
71
71
|
]
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
return {
|
|
74
74
|
module: ${meta.data.moduleName},
|
|
75
|
-
imports: [
|
|
75
|
+
imports: [DatabaseModule.provideMock()],
|
|
76
76
|
providers,
|
|
77
77
|
exports: providers,
|
|
78
78
|
global: true,
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
${meta.data.moduleName}._storeMockModule(cachedModule)
|
|
82
|
-
|
|
83
|
-
return cachedModule
|
|
79
|
+
}
|
|
84
80
|
}
|
|
85
81
|
}
|
|
86
82
|
|
|
@@ -10,7 +10,6 @@ function generateDataModule({ models, meta }) {
|
|
|
10
10
|
const mm = models.map((model) => ({ model, meta: (0, meta_1.getModelMetadata)({ model }) }));
|
|
11
11
|
const imports = imports_1.ImportsGenerator.from(meta.data.dataModuleFilePath).addImports({
|
|
12
12
|
[meta.data.dataService.filePath]: [meta.data.dataService.class],
|
|
13
|
-
[meta.data.dataMockModuleFilePath]: [meta.data.dataMockModuleName],
|
|
14
13
|
});
|
|
15
14
|
for (const { meta } of mm) {
|
|
16
15
|
imports.addImport({
|
|
@@ -20,57 +19,17 @@ function generateDataModule({ models, meta }) {
|
|
|
20
19
|
}
|
|
21
20
|
const moduleName = meta.data.moduleName;
|
|
22
21
|
return /* ts */ `
|
|
23
|
-
import { FactoryProvider } from '@nestjs/common'
|
|
24
|
-
|
|
25
|
-
import { DynamicModule } from '@backend/common'
|
|
26
|
-
import { DbModule, DbService } from '@backend/db'
|
|
27
|
-
import { E2EConfig } from '@backend/e2e'
|
|
22
|
+
import { DynamicModule, FactoryProvider } from '@nestjs/common'
|
|
23
|
+
import { DatabaseModule, DatabaseService } from '@backend/db'
|
|
28
24
|
|
|
29
25
|
${imports.generate()}
|
|
30
26
|
|
|
31
27
|
export class ${moduleName} {
|
|
32
|
-
|
|
33
|
-
* Internal cache for the module instance.
|
|
34
|
-
*/
|
|
35
|
-
private static cachedModule: DynamicModule | undefined = undefined
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The getInstance method should be called by any module that needs the module.
|
|
39
|
-
*/
|
|
40
|
-
static getInstance(): DynamicModule {
|
|
41
|
-
if (!${moduleName}.cachedModule) {
|
|
42
|
-
throw new Error('${moduleName} must be called via .forRoot first!')
|
|
43
|
-
}
|
|
44
|
-
return ${moduleName}.cachedModule
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Stores another module instance in the cache.
|
|
49
|
-
* Note: This should only be used for testing purposes.
|
|
50
|
-
*/
|
|
51
|
-
static _storeMockModule(module: DynamicModule): void {
|
|
52
|
-
${moduleName}.cachedModule = module
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The forRoot method should only be called once by the root module.
|
|
57
|
-
*/
|
|
58
|
-
static forRoot(options: E2EConfig): DynamicModule {
|
|
59
|
-
if (${moduleName}.cachedModule) {
|
|
60
|
-
throw new Error('${moduleName} is already instantiated, please call .forRoot only once from root...')
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (options.isE2ETest && !options.useDatabaseForE2E) {
|
|
64
|
-
return ${meta.data.dataMockModuleName}.mock()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// We need to initialize the user repository right at the beginning,
|
|
68
|
-
// so that we have the rootUser available for the other modules - including
|
|
69
|
-
// the action and seed modules which will ensure that seed data is created.
|
|
28
|
+
public static forRoot(): DynamicModule {
|
|
70
29
|
const userRepositoryProvider: FactoryProvider<UserRepository> = {
|
|
71
30
|
provide: UserRepository,
|
|
72
|
-
inject: [
|
|
73
|
-
useFactory: async (dbService:
|
|
31
|
+
inject: [DatabaseService],
|
|
32
|
+
useFactory: async (dbService: DatabaseService) => {
|
|
74
33
|
const repository = new UserRepository(dbService)
|
|
75
34
|
await repository.init()
|
|
76
35
|
return repository
|
|
@@ -88,15 +47,13 @@ export class ${moduleName} {
|
|
|
88
47
|
.join(',')}
|
|
89
48
|
]
|
|
90
49
|
|
|
91
|
-
|
|
50
|
+
return {
|
|
92
51
|
module: ${moduleName},
|
|
93
52
|
global: true,
|
|
94
|
-
imports: [
|
|
53
|
+
imports: [DatabaseModule],
|
|
95
54
|
providers,
|
|
96
55
|
exports: providers,
|
|
97
56
|
}
|
|
98
|
-
|
|
99
|
-
return ${moduleName}.cachedModule
|
|
100
57
|
}
|
|
101
58
|
}`;
|
|
102
59
|
}
|
|
@@ -23,7 +23,7 @@ function generateActionsDispatcherService({ models, meta }) {
|
|
|
23
23
|
import { Injectable } from '@nestjs/common'
|
|
24
24
|
|
|
25
25
|
import { ExhaustiveSwitchCheck } from '@backend/common'
|
|
26
|
-
import {
|
|
26
|
+
import { DatabaseService } from '@backend/db'
|
|
27
27
|
|
|
28
28
|
${imports.generate()}
|
|
29
29
|
|
|
@@ -43,7 +43,7 @@ export class ${meta.actions.dispatcher.class} {
|
|
|
43
43
|
|
|
44
44
|
constructor(
|
|
45
45
|
private readonly updateService: ${meta.businessLogic.update.serviceClassName},
|
|
46
|
-
private readonly
|
|
46
|
+
private readonly databaseService: DatabaseService,
|
|
47
47
|
private readonly actionExecutionFactory: ActionExecutionFactory,
|
|
48
48
|
) {}
|
|
49
49
|
|
|
@@ -51,7 +51,7 @@ export class ${meta.actions.dispatcher.class} {
|
|
|
51
51
|
action: A;
|
|
52
52
|
user: ${meta.config.userType}
|
|
53
53
|
}): Promise<ResultOfAction<A>> {
|
|
54
|
-
const execution = await this.actionExecutionFactory.create({ action,
|
|
54
|
+
const execution = await this.actionExecutionFactory.create({ action, databaseService: this.databaseService, user })
|
|
55
55
|
|
|
56
56
|
try {
|
|
57
57
|
const result = await this.execute({ action, execution })
|
|
@@ -32,7 +32,7 @@ function generateTestDataService({ models, meta: schemaMeta, }) {
|
|
|
32
32
|
return /* ts */ `
|
|
33
33
|
import { Injectable, Logger } from '@nestjs/common'
|
|
34
34
|
|
|
35
|
-
import {
|
|
35
|
+
import { DatabaseService } from '@backend/db'
|
|
36
36
|
${imports.generate()}
|
|
37
37
|
|
|
38
38
|
@Injectable()
|
|
@@ -40,14 +40,14 @@ export class TestDataService {
|
|
|
40
40
|
private logger = new Logger(TestDataService.name)
|
|
41
41
|
|
|
42
42
|
constructor(
|
|
43
|
-
private
|
|
44
|
-
private dataService: ${schemaMeta.data.dataService.class},
|
|
45
|
-
private actionExecutionFactory: ActionExecutionFactory,
|
|
43
|
+
private readonly databaseService: DatabaseService,
|
|
44
|
+
private readonly dataService: ${schemaMeta.data.dataService.class},
|
|
45
|
+
private readonly actionExecutionFactory: ActionExecutionFactory,
|
|
46
46
|
) {}
|
|
47
47
|
|
|
48
48
|
public async resetTestData(data: MockData) {
|
|
49
49
|
this.logger.log('💥 Emptying test data')
|
|
50
|
-
await this.
|
|
50
|
+
await this.databaseService.WIPE_ENTIRE_DATABASE()
|
|
51
51
|
|
|
52
52
|
// We need to init the user repository first so the root user is created
|
|
53
53
|
this.logger.log('✍ Setting test data')
|
|
@@ -65,7 +65,7 @@ export class TestDataService {
|
|
|
65
65
|
order: 0,
|
|
66
66
|
payload: []
|
|
67
67
|
},
|
|
68
|
-
|
|
68
|
+
databaseService: this.databaseService,
|
|
69
69
|
user: this.dataService.users.rootUser,
|
|
70
70
|
})
|
|
71
71
|
|
|
@@ -466,7 +466,7 @@ function generateMainBuildingBlocks_InDatabase({ model, meta, schemaMeta, import
|
|
|
466
466
|
imports.addImports({
|
|
467
467
|
[meta.types.importPath]: [meta.types.zodDecoderFnNames.fromDatabase],
|
|
468
468
|
[schemaMeta.backendModules.db.importPath]: [
|
|
469
|
-
schemaMeta.backendModules.db.
|
|
469
|
+
schemaMeta.backendModules.db.databaseService.name,
|
|
470
470
|
(0, types_1.toAnnotatedTypeName)((0, types_1.toTypeName)(`${model.sourceName} as DbType`)),
|
|
471
471
|
],
|
|
472
472
|
[schemaMeta.backendModules.common.importPath]: [
|
|
@@ -481,7 +481,7 @@ function generateMainBuildingBlocks_InDatabase({ model, meta, schemaMeta, import
|
|
|
481
481
|
const methodTypeSignatures = getRepositoryMethodsTypeSignatures({ model, meta });
|
|
482
482
|
const userRepositorySpecificBlocks = generateUserRepositorySpecificBlocks_InDatabase({ model, meta, imports });
|
|
483
483
|
return {
|
|
484
|
-
constructorCode: `constructor(protected db:
|
|
484
|
+
constructorCode: `constructor(protected db: ${schemaMeta.backendModules.db.databaseService.name}) {}`,
|
|
485
485
|
userRepositorySpecificBlocks,
|
|
486
486
|
initCode: `
|
|
487
487
|
public async init() {
|
package/dist/lib/meta.d.ts
CHANGED
package/dist/lib/meta.js
CHANGED
|
@@ -58,8 +58,8 @@ function getSchemaMetadata({ config }) {
|
|
|
58
58
|
},
|
|
59
59
|
db: {
|
|
60
60
|
importPath: Types.toBackendModulePath(`@backend/db`),
|
|
61
|
-
|
|
62
|
-
name: Types.toClassName(`
|
|
61
|
+
databaseService: {
|
|
62
|
+
name: Types.toClassName(`DatabaseService`),
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
65
|
http: {
|