@mondart/nestjs-common-module 1.1.46 → 1.1.47
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/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/lib/caching/caching.interface.d.ts +17 -0
- package/dist/lib/caching/caching.interface.js +4 -0
- package/dist/lib/caching/caching.module.d.ts +10 -0
- package/dist/lib/caching/caching.module.js +94 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/saga/decorators/saga.decorator.d.ts +1 -1
- package/dist/lib/saga/decorators/saga.decorator.js +2 -2
- package/dist/lib/saga/helpers/saga-exception-converter.helper.d.ts +1 -1
- package/dist/lib/saga/helpers/saga-exception-converter.helper.js +4 -4
- package/dist/lib/saga/saga.module.d.ts +1 -1
- package/dist/lib/saga/saga.module.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/caching/caching.module.d.ts +0 -2
- package/dist/caching/caching.module.js +0 -40
- /package/dist/{caching → lib/caching}/caching.service.d.ts +0 -0
- /package/dist/{caching → lib/caching}/caching.service.js +0 -0
- /package/dist/{caching → lib/caching}/index.d.ts +0 -0
- /package/dist/{caching → lib/caching}/index.js +0 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
require("reflect-metadata");
|
|
18
|
-
__exportStar(require("./caching"), exports);
|
|
19
18
|
__exportStar(require("./constants"), exports);
|
|
20
19
|
__exportStar(require("./controllers"), exports);
|
|
21
20
|
__exportStar(require("./decorators"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
export declare const CACHING_MODULE_OPTIONS = "CACHING_MODULE_OPTIONS";
|
|
3
|
+
export interface CachingModuleOptions {
|
|
4
|
+
ttl: number;
|
|
5
|
+
host: string;
|
|
6
|
+
port: string;
|
|
7
|
+
password: string;
|
|
8
|
+
}
|
|
9
|
+
export interface CachingModuleFactory {
|
|
10
|
+
createModuleOptions: () => Promise<CachingModuleOptions> | CachingModuleOptions;
|
|
11
|
+
}
|
|
12
|
+
export interface CachingModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
13
|
+
inject?: any[];
|
|
14
|
+
useClass?: Type<CachingModuleFactory>;
|
|
15
|
+
useExisting?: Type<CachingModuleFactory>;
|
|
16
|
+
useFactory?: (...args: any[]) => Promise<CachingModuleOptions> | CachingModuleOptions;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { CachingModuleAsyncOptions, CachingModuleOptions } from './caching.interface';
|
|
3
|
+
export declare class CachingModule {
|
|
4
|
+
static forRoot(options: CachingModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: CachingModuleAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncProviders;
|
|
7
|
+
private static createProviders;
|
|
8
|
+
private static createAsyncOptionsProvider;
|
|
9
|
+
private static createOptionsProvider;
|
|
10
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var CachingModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.CachingModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const caching_service_1 = require("./caching.service");
|
|
13
|
+
const cache_manager_1 = require("@nestjs/cache-manager");
|
|
14
|
+
const caching_interface_1 = require("./caching.interface");
|
|
15
|
+
const kafka_interface_1 = require("../kafka/kafka.interface");
|
|
16
|
+
const redisStore = require("cache-manager-redis-store");
|
|
17
|
+
let CachingModule = CachingModule_1 = class CachingModule {
|
|
18
|
+
static forRoot(options) {
|
|
19
|
+
return {
|
|
20
|
+
module: CachingModule_1,
|
|
21
|
+
imports: [
|
|
22
|
+
cache_manager_1.CacheModule.register({
|
|
23
|
+
isGlobal: true,
|
|
24
|
+
useFactory: async (options) => ({
|
|
25
|
+
store: redisStore,
|
|
26
|
+
ttl: options.ttl,
|
|
27
|
+
host: options.host,
|
|
28
|
+
port: options.port,
|
|
29
|
+
password: options.password,
|
|
30
|
+
max: 10000,
|
|
31
|
+
isGlobal: true,
|
|
32
|
+
}),
|
|
33
|
+
inject: [caching_interface_1.CACHING_MODULE_OPTIONS],
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
36
|
+
providers: [
|
|
37
|
+
{
|
|
38
|
+
provide: caching_interface_1.CACHING_MODULE_OPTIONS,
|
|
39
|
+
useValue: options,
|
|
40
|
+
},
|
|
41
|
+
caching_service_1.CachingService,
|
|
42
|
+
],
|
|
43
|
+
exports: [caching_service_1.CachingService],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
static forRootAsync(options) {
|
|
47
|
+
return {
|
|
48
|
+
module: CachingModule_1,
|
|
49
|
+
imports: [...options.imports],
|
|
50
|
+
providers: [...this.createAsyncProviders(options), caching_service_1.CachingService],
|
|
51
|
+
exports: [...this.createAsyncProviders(options), caching_service_1.CachingService],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
static createAsyncProviders(options) {
|
|
55
|
+
if (options.useExisting || options.useFactory) {
|
|
56
|
+
return [this.createAsyncOptionsProvider(options)];
|
|
57
|
+
}
|
|
58
|
+
return [
|
|
59
|
+
this.createAsyncOptionsProvider(options),
|
|
60
|
+
{
|
|
61
|
+
provide: options.useClass,
|
|
62
|
+
useClass: options.useClass,
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
static createProviders(options) {
|
|
67
|
+
return [this.createOptionsProvider(options)];
|
|
68
|
+
}
|
|
69
|
+
static createAsyncOptionsProvider(options) {
|
|
70
|
+
if (options.useFactory) {
|
|
71
|
+
return {
|
|
72
|
+
provide: caching_interface_1.CACHING_MODULE_OPTIONS,
|
|
73
|
+
useFactory: options.useFactory,
|
|
74
|
+
inject: options.inject || [],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
provide: caching_interface_1.CACHING_MODULE_OPTIONS,
|
|
79
|
+
useFactory: async (optionsFactory) => await optionsFactory.createModuleOptions(),
|
|
80
|
+
inject: [options.useExisting || options.useClass],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
static createOptionsProvider(options) {
|
|
84
|
+
return {
|
|
85
|
+
provide: kafka_interface_1.KAFKA_MODULE_OPTIONS,
|
|
86
|
+
useFactory: async (optionsFactory) => await optionsFactory.createModuleOptions(),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
exports.CachingModule = CachingModule;
|
|
91
|
+
exports.CachingModule = CachingModule = CachingModule_1 = __decorate([
|
|
92
|
+
(0, common_1.Global)(),
|
|
93
|
+
(0, common_1.Module)({})
|
|
94
|
+
], CachingModule);
|
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./kafka"), exports);
|
|
18
18
|
__exportStar(require("./saga"), exports);
|
|
19
|
+
__exportStar(require("./caching"), exports);
|
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Saga = Saga;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
|
-
const
|
|
6
|
+
const constant_1 = require("../constant");
|
|
7
7
|
function Saga(command) {
|
|
8
8
|
return (target) => {
|
|
9
9
|
target.prototype.execute = function execute(cmd) {
|
|
10
10
|
return this.saga.execute(cmd);
|
|
11
11
|
};
|
|
12
|
-
Reflect.defineMetadata(
|
|
12
|
+
Reflect.defineMetadata(constant_1.__SAGA_HANDLER__, command, target);
|
|
13
13
|
return (0, common_1.Injectable)({ scope: common_1.Scope.REQUEST })(target);
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -4,11 +4,11 @@ exports.SagaExceptionConverterHelper = void 0;
|
|
|
4
4
|
const exceptions = require("@nestjs/common/exceptions");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
class SagaExceptionConverterHelper {
|
|
7
|
-
static toHttpException(
|
|
8
|
-
if (exceptions[
|
|
9
|
-
throw new exceptions[
|
|
7
|
+
static toHttpException(exception) {
|
|
8
|
+
if (exceptions[exception?.name])
|
|
9
|
+
throw new exceptions[exception?.name](exception?.response);
|
|
10
10
|
else
|
|
11
|
-
throw new common_1.InternalServerErrorException(exception);
|
|
11
|
+
throw new common_1.InternalServerErrorException(exception?.response);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.SagaExceptionConverterHelper = SagaExceptionConverterHelper;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { SagaModuleRegisterParams } from './interfaces
|
|
2
|
+
import { SagaModuleRegisterParams } from './interfaces';
|
|
3
3
|
export declare class SagaModule {
|
|
4
4
|
static register(params: SagaModuleRegisterParams): DynamicModule;
|
|
5
5
|
}
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.SagaModule = void 0;
|
|
13
13
|
const cqrs_1 = require("@nestjs/cqrs");
|
|
14
14
|
const core_1 = require("@nestjs/core");
|
|
15
|
-
const
|
|
15
|
+
const constant_1 = require("./constant");
|
|
16
16
|
class SagaModule {
|
|
17
17
|
static register(params) {
|
|
18
18
|
return {
|
|
@@ -21,7 +21,7 @@ class SagaModule {
|
|
|
21
21
|
providers: [
|
|
22
22
|
...(params.providers || []),
|
|
23
23
|
...params.sagas.flatMap((saga) => {
|
|
24
|
-
const cmdType = Reflect.getMetadata(
|
|
24
|
+
const cmdType = Reflect.getMetadata(constant_1.__SAGA_HANDLER__, saga);
|
|
25
25
|
let SagaCommandHandler = class SagaCommandHandler {
|
|
26
26
|
constructor(moduleRef) {
|
|
27
27
|
this.moduleRef = moduleRef;
|