@koalarx/nest 4.0.2 → 4.0.3
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/cli/utils/patch-infra-module.js +68 -48
- package/package.json +1 -1
|
@@ -1,61 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let patched = content.replace("import { ILoggingService } from '@/domain/common/ilogging.service';", `import { ICacheService } from '@/domain/common/icache.service';
|
|
7
|
-
import { ILoggingService } from '@/domain/common/ilogging.service';
|
|
8
|
-
import { IRedLockService } from '@/domain/common/ired-lock.service';`).replace("import { LoggingService } from '@/infra/common/logging.service';", `import { CacheServiceProvider } from '@/infra/common/cache-service.provider';
|
|
9
|
-
import { LoggingService } from '@/infra/common/logging.service';
|
|
10
|
-
import { RedLockService } from '@/infra/common/red-lock.service';`).replace(` providers: [
|
|
11
|
-
{ provide: ILoggingService, useClass: LoggingService },`, ` providers: [
|
|
12
|
-
CacheServiceProvider,
|
|
13
|
-
{ provide: ICacheService, useExisting: CacheServiceProvider },
|
|
14
|
-
{ provide: ILoggingService, useClass: LoggingService },
|
|
15
|
-
{ provide: IRedLockService, useClass: RedLockService },`);
|
|
16
|
-
if (withAuth) {
|
|
17
|
-
return patched.replace(" exports: [RepositoryModule, ILoggingService, ILoggedUserInfoService],", ` exports: [
|
|
18
|
-
RepositoryModule,
|
|
19
|
-
ICacheService,
|
|
20
|
-
ILoggingService,
|
|
21
|
-
IRedLockService,
|
|
22
|
-
ILoggedUserInfoService,
|
|
23
|
-
],`);
|
|
24
|
-
}
|
|
25
|
-
return patched.replace(" exports: [RepositoryModule, ILoggingService],", ` exports: [
|
|
26
|
-
RepositoryModule,
|
|
27
|
-
ICacheService,
|
|
28
|
-
ILoggingService,
|
|
29
|
-
IRedLockService,
|
|
30
|
-
],`);
|
|
1
|
+
function hasCacheProviders(content) {
|
|
2
|
+
return content.includes("{ provide: ICacheService, useExisting: CacheServiceProvider }");
|
|
3
|
+
}
|
|
4
|
+
function hasAuthProviders(content) {
|
|
5
|
+
return content.includes("{ provide: ILoggedUserInfoService, useClass: LoggedUserInfoService }");
|
|
31
6
|
}
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
7
|
+
export function buildInfraModule({ cache, auth }) {
|
|
8
|
+
const importLines = [
|
|
9
|
+
...cache ? ["import { ICacheService } from '@/domain/common/icache.service';"] : [],
|
|
10
|
+
"import { ILoggingService } from '@/domain/common/ilogging.service';",
|
|
11
|
+
...auth ? [
|
|
12
|
+
"import { ILoggedUserInfoService } from '@/domain/services/ilogged-user-info.service';"
|
|
13
|
+
] : [],
|
|
14
|
+
...cache ? ["import { IRedLockService } from '@/domain/common/ired-lock.service';"] : [],
|
|
15
|
+
"import { Module } from '@nestjs/common';",
|
|
16
|
+
...cache ? [
|
|
17
|
+
"import { CacheServiceProvider } from '@/infra/common/cache-service.provider';"
|
|
18
|
+
] : [],
|
|
19
|
+
"import { LoggingService } from '@/infra/common/logging.service';",
|
|
20
|
+
...auth ? [
|
|
21
|
+
"import { LoggedUserInfoService } from '@/infra/services/logged-user-info.service';"
|
|
22
|
+
] : [],
|
|
23
|
+
...cache ? ["import { RedLockService } from '@/infra/common/red-lock.service';"] : [],
|
|
24
|
+
"import { RepositoryModule } from '@/infra/repositories/repository.module';"
|
|
25
|
+
];
|
|
26
|
+
const providerLines = [
|
|
27
|
+
...cache ? [
|
|
28
|
+
" CacheServiceProvider,",
|
|
29
|
+
" { provide: ICacheService, useExisting: CacheServiceProvider },"
|
|
30
|
+
] : [],
|
|
31
|
+
" { provide: ILoggingService, useClass: LoggingService },",
|
|
32
|
+
...cache ? [" { provide: IRedLockService, useClass: RedLockService },"] : [],
|
|
33
|
+
...auth ? [
|
|
34
|
+
" { provide: ILoggedUserInfoService, useClass: LoggedUserInfoService },"
|
|
35
|
+
] : []
|
|
36
|
+
];
|
|
37
|
+
const exportLines = [
|
|
38
|
+
" RepositoryModule,",
|
|
39
|
+
...cache ? [" ICacheService,"] : [],
|
|
40
|
+
" ILoggingService,",
|
|
41
|
+
...cache ? [" IRedLockService,"] : [],
|
|
42
|
+
...auth ? [" ILoggedUserInfoService,"] : []
|
|
43
|
+
];
|
|
44
|
+
return `${importLines.join(`
|
|
45
|
+
`)}
|
|
36
46
|
|
|
37
47
|
@Module({
|
|
38
48
|
imports: [RepositoryModule],
|
|
39
|
-
providers: [
|
|
40
|
-
|
|
49
|
+
providers: [
|
|
50
|
+
${providerLines.join(`
|
|
51
|
+
`)}
|
|
52
|
+
],
|
|
53
|
+
exports: [
|
|
54
|
+
${exportLines.join(`
|
|
55
|
+
`)}
|
|
56
|
+
],
|
|
41
57
|
})
|
|
42
58
|
export class InfraModule {}
|
|
43
59
|
`;
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
}
|
|
61
|
+
export function patchInfraModuleForCache(content) {
|
|
62
|
+
if (hasCacheProviders(content)) {
|
|
46
63
|
return content;
|
|
47
64
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
return buildInfraModule({
|
|
66
|
+
cache: true,
|
|
67
|
+
auth: hasAuthProviders(content) || content.includes("ILoggedUserInfoService")
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export const SLIM_INFRA_MODULE = buildInfraModule({ cache: false, auth: false });
|
|
71
|
+
export function patchInfraModuleForAuth(content) {
|
|
72
|
+
if (hasAuthProviders(content)) {
|
|
73
|
+
return content;
|
|
57
74
|
}
|
|
58
|
-
return
|
|
75
|
+
return buildInfraModule({
|
|
76
|
+
cache: hasCacheProviders(content) || content.includes("ICacheService"),
|
|
77
|
+
auth: true
|
|
78
|
+
});
|
|
59
79
|
}
|
|
60
80
|
export function stripInfraModuleCache(_content) {
|
|
61
81
|
return SLIM_INFRA_MODULE;
|