@nest-yalc-2/app 2.2.2 → 2.2.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/package.json +5 -3
- package/src/__tests__/app-bootstrap-base.helper.spec.ts +86 -38
- package/src/__tests__/app-bootstrap-standalone.helper.spec.ts +35 -35
- package/src/__tests__/app-bootstrap.helper.spec.ts +162 -98
- package/src/__tests__/app-config.service.spec.ts +55 -55
- package/src/__tests__/app-context.service.spec.ts +28 -28
- package/src/__tests__/app.events.spec.ts +12 -12
- package/src/__tests__/app.helper.spec.ts +71 -204
- package/src/__tests__/base-app-module.helper.spec.ts +295 -231
- package/src/__tests__/base-app.controller.spec.ts +90 -90
- package/src/__tests__/base-app.service.spec.ts +39 -39
- package/src/__tests__/cls.module.spec.ts +33 -33
- package/src/__tests__/life-cycle-handler.service.spec.ts +57 -48
- package/src/__tests__/unwrap-result.interceptor.spec.ts +52 -52
- package/src/app-bootstrap-base.helper.ts +206 -206
- package/src/app-bootstrap-standalone.helper.ts +67 -67
- package/src/app-bootstrap.helper.js +9 -9
- package/src/app-bootstrap.helper.ts +279 -279
- package/src/app-config.service.ts +61 -61
- package/src/app-context.module.ts +6 -6
- package/src/app-context.service.ts +16 -16
- package/src/app-imports.factory.js +2 -2
- package/src/app-imports.factory.js.map +1 -1
- package/src/app-imports.factory.ts +321 -321
- package/src/app.events.ts +8 -8
- package/src/app.helper.ts +73 -73
- package/src/base-app-module.helper.d.ts +2 -2
- package/src/base-app-module.helper.js +8 -5
- package/src/base-app-module.helper.js.map +1 -1
- package/src/base-app-module.helper.ts +457 -453
- package/src/base-app.controller.ts +51 -51
- package/src/base-app.interface.ts +55 -55
- package/src/base-app.service.ts +33 -33
- package/src/cls.module.d.ts +2 -1
- package/src/cls.module.js.map +1 -1
- package/src/cls.module.ts +76 -75
- package/src/conf.type.ts +22 -22
- package/src/def.const.ts +33 -33
- package/src/global.enum.ts +6 -6
- package/src/life-cycle-handler.service.ts +66 -66
- package/src/unwrap-result.interceptor.ts +32 -32
- package/src/yalc-controller.interface.ts +6 -6
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { type ImprovedLoggerService } from '@node-yalc/logger/logger-abstract.service.js';
|
|
2
|
-
import {
|
|
3
|
-
Injectable,
|
|
4
|
-
Inject,
|
|
5
|
-
OnModuleInit,
|
|
6
|
-
OnModuleDestroy,
|
|
7
|
-
} from '@nestjs/common';
|
|
8
|
-
import { type IYalcBaseAppOptions } from './base-app.interface.js';
|
|
9
|
-
import {
|
|
10
|
-
APP_LOGGER_SERVICE,
|
|
11
|
-
MODULE_ALIAS_TOKEN,
|
|
12
|
-
MODULE_OPTION_TOKEN,
|
|
13
|
-
} from './def.const.js';
|
|
14
|
-
/* istanbul ignore file */
|
|
15
|
-
import { AppContextService } from './app-context.service.js';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* This class is used to handle the lifecycle of the app
|
|
19
|
-
* and apply some common logic and checks to all apps
|
|
20
|
-
*/
|
|
21
|
-
/* istanbul ignore next */
|
|
22
|
-
@Injectable()
|
|
23
|
-
export class LifeCycleHandler implements OnModuleDestroy, OnModuleInit {
|
|
24
|
-
/**
|
|
25
|
-
* We do this in the constructor since onModuleInit doesn't seem to be called
|
|
26
|
-
* when we use 'useFactory' to create the provider
|
|
27
|
-
* @todo: investigate why onModuleInit is not called
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
constructor(
|
|
31
|
-
/* istanbul ignore next */
|
|
32
|
-
@Inject(APP_LOGGER_SERVICE) private readonly logger: ImprovedLoggerService,
|
|
33
|
-
/* istanbul ignore next */
|
|
34
|
-
@Inject(MODULE_ALIAS_TOKEN) private readonly moduleAlias: string,
|
|
35
|
-
/* istanbul ignore next */
|
|
36
|
-
@Inject(AppContextService)
|
|
37
|
-
/* istanbul ignore next */
|
|
38
|
-
private readonly appContextService: AppContextService,
|
|
39
|
-
/* istanbul ignore next */
|
|
40
|
-
@Inject(MODULE_OPTION_TOKEN)
|
|
41
|
-
/* istanbul ignore next */
|
|
42
|
-
private readonly options?: IYalcBaseAppOptions,
|
|
43
|
-
) {
|
|
44
|
-
this.logger.debug?.(
|
|
45
|
-
`====================== Init ${this.moduleAlias} ======================`,
|
|
46
|
-
);
|
|
47
|
-
if (
|
|
48
|
-
this.options?.skipDuplicateAppCheck !== true &&
|
|
49
|
-
this.appContextService.initializedApps.has(this.moduleAlias)
|
|
50
|
-
) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`Cannot initialize the same app (${this.moduleAlias}) twice`,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
this.appContextService.initializedApps.add(this.moduleAlias);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
onModuleInit() {}
|
|
59
|
-
|
|
60
|
-
onModuleDestroy() {
|
|
61
|
-
this.logger.debug?.(
|
|
62
|
-
`====================== Close ${this.moduleAlias} ======================`,
|
|
63
|
-
);
|
|
64
|
-
this.appContextService.initializedApps.delete(this.moduleAlias);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
1
|
+
import { type ImprovedLoggerService } from '@node-yalc/logger/logger-abstract.service.js';
|
|
2
|
+
import {
|
|
3
|
+
Injectable,
|
|
4
|
+
Inject,
|
|
5
|
+
OnModuleInit,
|
|
6
|
+
OnModuleDestroy,
|
|
7
|
+
} from '@nestjs/common';
|
|
8
|
+
import { type IYalcBaseAppOptions } from './base-app.interface.js';
|
|
9
|
+
import {
|
|
10
|
+
APP_LOGGER_SERVICE,
|
|
11
|
+
MODULE_ALIAS_TOKEN,
|
|
12
|
+
MODULE_OPTION_TOKEN,
|
|
13
|
+
} from './def.const.js';
|
|
14
|
+
/* istanbul ignore file */
|
|
15
|
+
import { AppContextService } from './app-context.service.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This class is used to handle the lifecycle of the app
|
|
19
|
+
* and apply some common logic and checks to all apps
|
|
20
|
+
*/
|
|
21
|
+
/* istanbul ignore next */
|
|
22
|
+
@Injectable()
|
|
23
|
+
export class LifeCycleHandler implements OnModuleDestroy, OnModuleInit {
|
|
24
|
+
/**
|
|
25
|
+
* We do this in the constructor since onModuleInit doesn't seem to be called
|
|
26
|
+
* when we use 'useFactory' to create the provider
|
|
27
|
+
* @todo: investigate why onModuleInit is not called
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
constructor(
|
|
31
|
+
/* istanbul ignore next */
|
|
32
|
+
@Inject(APP_LOGGER_SERVICE) private readonly logger: ImprovedLoggerService,
|
|
33
|
+
/* istanbul ignore next */
|
|
34
|
+
@Inject(MODULE_ALIAS_TOKEN) private readonly moduleAlias: string,
|
|
35
|
+
/* istanbul ignore next */
|
|
36
|
+
@Inject(AppContextService)
|
|
37
|
+
/* istanbul ignore next */
|
|
38
|
+
private readonly appContextService: AppContextService,
|
|
39
|
+
/* istanbul ignore next */
|
|
40
|
+
@Inject(MODULE_OPTION_TOKEN)
|
|
41
|
+
/* istanbul ignore next */
|
|
42
|
+
private readonly options?: IYalcBaseAppOptions,
|
|
43
|
+
) {
|
|
44
|
+
this.logger.debug?.(
|
|
45
|
+
`====================== Init ${this.moduleAlias} ======================`,
|
|
46
|
+
);
|
|
47
|
+
if (
|
|
48
|
+
this.options?.skipDuplicateAppCheck !== true &&
|
|
49
|
+
this.appContextService.initializedApps.has(this.moduleAlias)
|
|
50
|
+
) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Cannot initialize the same app (${this.moduleAlias}) twice`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
this.appContextService.initializedApps.add(this.moduleAlias);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
onModuleInit() {}
|
|
59
|
+
|
|
60
|
+
onModuleDestroy() {
|
|
61
|
+
this.logger.debug?.(
|
|
62
|
+
`====================== Close ${this.moduleAlias} ======================`,
|
|
63
|
+
);
|
|
64
|
+
this.appContextService.initializedApps.delete(this.moduleAlias);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CallHandler,
|
|
3
|
-
ExecutionContext,
|
|
4
|
-
Injectable,
|
|
5
|
-
NestInterceptor,
|
|
6
|
-
} from '@nestjs/common';
|
|
7
|
-
import { ResultAsync } from 'neverthrow';
|
|
8
|
-
import { map, Observable } from 'rxjs';
|
|
9
|
-
|
|
10
|
-
@Injectable()
|
|
11
|
-
export class UnwrapResultInterceptor implements NestInterceptor {
|
|
12
|
-
intercept(_: ExecutionContext, next: CallHandler): Observable<any> {
|
|
13
|
-
return next.handle().pipe(
|
|
14
|
-
map((result) => {
|
|
15
|
-
if (
|
|
16
|
-
result instanceof ResultAsync ||
|
|
17
|
-
(!!result &&
|
|
18
|
-
typeof result === 'object' &&
|
|
19
|
-
typeof result.isOk === 'function' &&
|
|
20
|
-
typeof result.isErr === 'function')
|
|
21
|
-
) {
|
|
22
|
-
if (result.isOk()) {
|
|
23
|
-
return result.value;
|
|
24
|
-
} else {
|
|
25
|
-
throw result.error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}),
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
CallHandler,
|
|
3
|
+
ExecutionContext,
|
|
4
|
+
Injectable,
|
|
5
|
+
NestInterceptor,
|
|
6
|
+
} from '@nestjs/common';
|
|
7
|
+
import { ResultAsync } from 'neverthrow';
|
|
8
|
+
import { map, Observable } from 'rxjs';
|
|
9
|
+
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class UnwrapResultInterceptor implements NestInterceptor {
|
|
12
|
+
intercept(_: ExecutionContext, next: CallHandler): Observable<any> {
|
|
13
|
+
return next.handle().pipe(
|
|
14
|
+
map((result) => {
|
|
15
|
+
if (
|
|
16
|
+
result instanceof ResultAsync ||
|
|
17
|
+
(!!result &&
|
|
18
|
+
typeof result === 'object' &&
|
|
19
|
+
typeof result.isOk === 'function' &&
|
|
20
|
+
typeof result.isErr === 'function')
|
|
21
|
+
) {
|
|
22
|
+
if (result.isOk()) {
|
|
23
|
+
return result.value;
|
|
24
|
+
} else {
|
|
25
|
+
throw result.error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export interface IYalcControllerStaticInterface {
|
|
2
|
-
/**
|
|
3
|
-
* This property is initialized by the base-app-module.helper
|
|
4
|
-
*/
|
|
5
|
-
_appAlias?: string;
|
|
6
|
-
}
|
|
1
|
+
export interface IYalcControllerStaticInterface {
|
|
2
|
+
/**
|
|
3
|
+
* This property is initialized by the base-app-module.helper
|
|
4
|
+
*/
|
|
5
|
+
_appAlias?: string;
|
|
6
|
+
}
|