@mondart/nestjs-common-module 1.1.46 → 1.1.48
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 +7 -0
- package/dist/lib/caching/caching.module.js +83 -0
- package/dist/{caching → lib/caching}/caching.service.d.ts +1 -1
- package/dist/{caching → lib/caching}/caching.service.js +3 -3
- 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}/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,7 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { CachingModuleAsyncOptions, CachingModuleOptions } from './caching.interface';
|
|
3
|
+
export declare class CachingModule {
|
|
4
|
+
static register(options: CachingModuleOptions): DynamicModule;
|
|
5
|
+
static registerAsync(options: CachingModuleAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncProviders;
|
|
7
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 redisStore = require("cache-manager-redis-store");
|
|
16
|
+
let CachingModule = CachingModule_1 = class CachingModule {
|
|
17
|
+
static register(options) {
|
|
18
|
+
const cacheModuleOptions = {
|
|
19
|
+
isGlobal: true,
|
|
20
|
+
store: redisStore,
|
|
21
|
+
ttl: options.ttl,
|
|
22
|
+
host: options.host,
|
|
23
|
+
port: options.port,
|
|
24
|
+
password: options.password,
|
|
25
|
+
max: 10000,
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
module: CachingModule_1,
|
|
29
|
+
imports: [cache_manager_1.CacheModule.register(cacheModuleOptions)],
|
|
30
|
+
providers: [
|
|
31
|
+
{
|
|
32
|
+
provide: caching_interface_1.CACHING_MODULE_OPTIONS,
|
|
33
|
+
useValue: options,
|
|
34
|
+
},
|
|
35
|
+
caching_service_1.CachingService,
|
|
36
|
+
],
|
|
37
|
+
exports: [caching_service_1.CachingService],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
static registerAsync(options) {
|
|
41
|
+
return {
|
|
42
|
+
module: CachingModule_1,
|
|
43
|
+
imports: [...options.imports],
|
|
44
|
+
providers: [...this.createAsyncProviders(options), caching_service_1.CachingService],
|
|
45
|
+
exports: [...this.createAsyncProviders(options), caching_service_1.CachingService],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
static createAsyncProviders(options) {
|
|
49
|
+
if (options.useFactory) {
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
provide: caching_interface_1.CACHING_MODULE_OPTIONS,
|
|
53
|
+
useFactory: options.useFactory,
|
|
54
|
+
inject: options.inject || [],
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
const useClass = options.useClass || options.useExisting;
|
|
59
|
+
if (useClass) {
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
provide: caching_interface_1.CACHING_MODULE_OPTIONS,
|
|
63
|
+
useFactory: async (optionsFactory) => await optionsFactory.createModuleOptions(),
|
|
64
|
+
inject: [options.useExisting || options.useClass],
|
|
65
|
+
},
|
|
66
|
+
...(options.useClass
|
|
67
|
+
? [
|
|
68
|
+
{
|
|
69
|
+
provide: options.useClass,
|
|
70
|
+
useClass: options.useClass,
|
|
71
|
+
},
|
|
72
|
+
]
|
|
73
|
+
: []),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
throw new Error('Invalid CachingModuleAsyncOptions');
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.CachingModule = CachingModule;
|
|
80
|
+
exports.CachingModule = CachingModule = CachingModule_1 = __decorate([
|
|
81
|
+
(0, common_1.Global)(),
|
|
82
|
+
(0, common_1.Module)({})
|
|
83
|
+
], CachingModule);
|
|
@@ -3,7 +3,7 @@ export declare class CachingService {
|
|
|
3
3
|
private cacheManager;
|
|
4
4
|
constructor(cacheManager: Cache);
|
|
5
5
|
getRedisClient(): import("cache-manager").Store;
|
|
6
|
-
get<T>(key: string): Promise<T>;
|
|
6
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
7
7
|
set<T>(key: string, value: T, ttlSeconds: number): Promise<void>;
|
|
8
8
|
del(key: string): Promise<void>;
|
|
9
9
|
}
|
|
@@ -27,13 +27,13 @@ let CachingService = class CachingService {
|
|
|
27
27
|
if (result) {
|
|
28
28
|
return JSON.parse(result);
|
|
29
29
|
}
|
|
30
|
-
return
|
|
30
|
+
return undefined;
|
|
31
31
|
}
|
|
32
32
|
async set(key, value, ttlSeconds) {
|
|
33
|
-
|
|
33
|
+
await this.cacheManager.set(key, JSON.stringify(value), ttlSeconds);
|
|
34
34
|
}
|
|
35
35
|
async del(key) {
|
|
36
|
-
|
|
36
|
+
await this.cacheManager.del(key);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
exports.CachingService = CachingService;
|
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;
|