xcally-nest-library 0.0.35 → 0.0.37-XM3778-bae91
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/.jest/jestEnv.js +3 -0
- package/.nvmrc +1 -1
- package/.prettierrc +18 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +61 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/src/core/application/__tests__/cached-base.service.spec.d.ts +1 -0
- package/dist/src/core/application/__tests__/cached-base.service.spec.js +224 -0
- package/dist/src/core/application/__tests__/cached-base.service.spec.js.map +1 -0
- package/dist/src/core/application/__tests__/mock-types.d.ts +66 -0
- package/dist/src/core/application/__tests__/mock-types.js +9 -0
- package/dist/src/core/application/__tests__/mock-types.js.map +1 -0
- package/dist/src/core/application/__tests__/mocks/paginated-query.mock.d.ts +2 -0
- package/dist/src/core/application/__tests__/mocks/paginated-query.mock.js +12 -0
- package/dist/src/core/application/__tests__/mocks/paginated-query.mock.js.map +1 -0
- package/dist/src/core/application/__tests__/mocks/paginated-result.mock.d.ts +31 -0
- package/dist/src/core/application/__tests__/mocks/paginated-result.mock.js +169 -0
- package/dist/src/core/application/__tests__/mocks/paginated-result.mock.js.map +1 -0
- package/dist/src/core/application/base.interface.d.ts +4 -4
- package/dist/src/core/application/base.mongo.interface.d.ts +16 -0
- package/dist/src/core/application/base.mongo.interface.js +3 -0
- package/dist/src/core/application/base.mongo.interface.js.map +1 -0
- package/dist/src/core/application/base.mongo.service.d.ts +23 -0
- package/dist/src/core/application/base.mongo.service.js +91 -0
- package/dist/src/core/application/base.mongo.service.js.map +1 -0
- package/dist/src/core/application/base.service.d.ts +2 -2
- package/dist/src/core/application/cached-base.service.d.ts +26 -0
- package/dist/src/core/application/cached-base.service.js +52 -0
- package/dist/src/core/application/cached-base.service.js.map +1 -0
- package/dist/src/core/application/cached.service.d.ts +13 -0
- package/dist/src/core/application/cached.service.js +55 -0
- package/dist/src/core/application/cached.service.js.map +1 -0
- package/dist/src/core/domain/interfaces/base.mongo.repository.interface.d.ts +12 -0
- package/dist/src/core/domain/interfaces/base.mongo.repository.interface.js +3 -0
- package/dist/src/core/domain/interfaces/base.mongo.repository.interface.js.map +1 -0
- package/dist/src/core/domain/interfaces/cache-configuration.interface.d.ts +8 -0
- package/dist/src/core/domain/interfaces/cache-configuration.interface.js +11 -0
- package/dist/src/core/domain/interfaces/cache-configuration.interface.js.map +1 -0
- package/dist/src/core/infrastracture/databases/base.mongo.entity.d.ts +14 -0
- package/dist/src/core/infrastracture/databases/base.mongo.entity.interface.d.ts +10 -0
- package/dist/src/core/infrastracture/databases/base.mongo.entity.interface.js +3 -0
- package/dist/src/core/infrastracture/databases/base.mongo.entity.interface.js.map +1 -0
- package/dist/src/core/infrastracture/databases/base.mongo.entity.js +66 -0
- package/dist/src/core/infrastracture/databases/base.mongo.entity.js.map +1 -0
- package/dist/src/core/infrastracture/databases/base.mongo.repository.d.ts +20 -0
- package/dist/src/core/infrastracture/databases/base.mongo.repository.js +275 -0
- package/dist/src/core/infrastracture/databases/base.mongo.repository.js.map +1 -0
- package/dist/src/core/infrastracture/databases/base.repository.d.ts +1 -1
- package/dist/src/modules/logger/pino/logger.module.js +1 -1
- package/dist/src/modules/logger/pino/logger.module.js.map +1 -1
- package/dist/src/modules/logger/pino/logger.service.js +1 -1
- package/dist/src/modules/logger/pino/logger.service.js.map +1 -1
- package/dist/tsconfig.json +38 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.mjs +49 -0
- package/index.ts +9 -0
- package/jest.config.ts +219 -0
- package/package.json +34 -21
- package/scripts/publish-feat.sh +67 -0
- package/src/core/application/__tests__/cached-base.service.spec.ts +367 -0
- package/src/core/application/__tests__/mock-types.ts +73 -0
- package/src/core/application/__tests__/mocks/paginated-query.mock.ts +10 -0
- package/src/core/application/__tests__/mocks/paginated-result.mock.ts +166 -0
- package/src/core/application/base.interface.ts +4 -5
- package/src/core/application/base.mongo.interface.ts +15 -0
- package/src/core/application/base.mongo.service.ts +170 -0
- package/src/core/application/base.service.ts +2 -2
- package/src/core/application/cached-base.service.ts +119 -0
- package/src/core/application/cached.service.ts +96 -0
- package/src/core/domain/interfaces/base.mongo.repository.interface.ts +14 -0
- package/src/core/domain/interfaces/base.repository.interface.ts +1 -0
- package/src/core/domain/interfaces/cache-configuration.interface.ts +10 -0
- package/src/core/infrastracture/databases/base.mongo.entity.interface.ts +12 -0
- package/src/core/infrastracture/databases/base.mongo.entity.ts +65 -0
- package/src/core/infrastracture/databases/base.mongo.repository.ts +371 -0
- package/src/core/infrastracture/databases/base.repository.ts +1 -1
- package/src/modules/logger/pino/logger.module.ts +1 -1
- package/src/modules/logger/pino/logger.service.ts +1 -1
- package/tsconfig.json +1 -0
- package/dist/src/modules/db-hooks-subscriber/db-hooks-subscriber.module.d.ts +0 -2
- package/dist/src/modules/db-hooks-subscriber/db-hooks-subscriber.module.js +0 -22
- package/dist/src/modules/db-hooks-subscriber/db-hooks-subscriber.module.js.map +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paginatedResultMock = exports.dataResultMock = void 0;
|
|
4
|
+
exports.dataResultMock = [
|
|
5
|
+
{
|
|
6
|
+
"id": 1,
|
|
7
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
8
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
9
|
+
"name": "CHOICE",
|
|
10
|
+
"description": "variable for menu auto generated"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"id": 2,
|
|
14
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
15
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
16
|
+
"name": "ORDERNUM",
|
|
17
|
+
"description": "variable for order auto generated"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": 3,
|
|
21
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
22
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
23
|
+
"name": "DBRESULT",
|
|
24
|
+
"description": "variable for db query result auto generated"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": 4,
|
|
28
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
29
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
30
|
+
"name": "RATE",
|
|
31
|
+
"description": "variable for rate call auto generated"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": 5,
|
|
35
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
36
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
37
|
+
"name": "CALLERID(dnid)",
|
|
38
|
+
"description": "variable dialed number identifier auto generated"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"id": 6,
|
|
42
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
43
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
44
|
+
"name": "CALLERID(name)",
|
|
45
|
+
"description": "variable name of the caller auto generated"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"id": 7,
|
|
49
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
50
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
51
|
+
"name": "CALLERID(num)",
|
|
52
|
+
"description": "variable number of the caller auto generated"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": 8,
|
|
56
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
57
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
58
|
+
"name": "CHANNEL(language)",
|
|
59
|
+
"description": "variable select a natural language file when available auto generated"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"id": 9,
|
|
63
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
64
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
65
|
+
"name": "COUNTER",
|
|
66
|
+
"description": "variable auto generated"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"id": 10,
|
|
70
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
71
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
72
|
+
"name": "EMAIL",
|
|
73
|
+
"description": "variable auto generated"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"id": 11,
|
|
77
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
78
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
79
|
+
"name": "EXTRAVAR",
|
|
80
|
+
"description": "variable useful for agent popup auto generated"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"id": 12,
|
|
84
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
85
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
86
|
+
"name": "FIRSTNAME",
|
|
87
|
+
"description": "variable auto generated"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"id": 13,
|
|
91
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
92
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
93
|
+
"name": "LASTNAME",
|
|
94
|
+
"description": "variable auto generated"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"id": 14,
|
|
98
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
99
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
100
|
+
"name": "INPUT",
|
|
101
|
+
"description": "variable auto generated"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"id": 15,
|
|
105
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
106
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
107
|
+
"name": "OPTION",
|
|
108
|
+
"description": "variable auto generated"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"id": 16,
|
|
112
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
113
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
114
|
+
"name": "ORDER",
|
|
115
|
+
"description": "variable auto generated"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"id": 17,
|
|
119
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
120
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
121
|
+
"name": "PHONE",
|
|
122
|
+
"description": "variable auto generated"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"id": 18,
|
|
126
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
127
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
128
|
+
"name": "RESULT",
|
|
129
|
+
"description": "variable auto generated"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"id": 19,
|
|
133
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
134
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
135
|
+
"name": "UNIQUEID",
|
|
136
|
+
"description": "variable current call unique identifier auto generated"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"id": 20,
|
|
140
|
+
"createdAt": "2023-02-06T10:57:24.000Z",
|
|
141
|
+
"updatedAt": "2023-02-06T10:57:24.000Z",
|
|
142
|
+
"name": "VAR1",
|
|
143
|
+
"description": "generic variable auto generated"
|
|
144
|
+
}
|
|
145
|
+
];
|
|
146
|
+
exports.paginatedResultMock = {
|
|
147
|
+
"meta": {
|
|
148
|
+
"itemsPerPage": 20,
|
|
149
|
+
"totalItems": 25,
|
|
150
|
+
"currentPage": 1,
|
|
151
|
+
"totalPages": 2,
|
|
152
|
+
"sortBy": [
|
|
153
|
+
[
|
|
154
|
+
"id",
|
|
155
|
+
"ASC"
|
|
156
|
+
]
|
|
157
|
+
],
|
|
158
|
+
"searchBy": "",
|
|
159
|
+
"search": "",
|
|
160
|
+
"select": "",
|
|
161
|
+
},
|
|
162
|
+
"links": {
|
|
163
|
+
"current": "/api/v2/variables?page=1&limit=20&sortBy=id:ASC",
|
|
164
|
+
"next": "/api/v2/variables?page=2&limit=20&sortBy=id:ASC",
|
|
165
|
+
"last": "/api/v2/variables?page=2&limit=20&sortBy=id:ASC"
|
|
166
|
+
},
|
|
167
|
+
"data": exports.dataResultMock,
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=paginated-result.mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginated-result.mock.js","sourceRoot":"","sources":["../../../../../../src/core/application/__tests__/mocks/paginated-result.mock.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG;IAC1B;QACI,IAAI,EAAE,CAAC;QACP,WAAW,EAAE,0BAA0B;QACvC,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAAE,QAAQ;QAChB,aAAa,EAAE,kCAAkC;KACpD;IACD;QACI,IAAI,EAAE,CAAC;QACP,WAAW,EAAE,0BAA0B;QACvC,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAAE,UAAU;QAClB,aAAa,EAAE,mCAAmC;KACrD;IACD;QACI,IAAI,EAAE,CAAC;QACP,WAAW,EAAE,0BAA0B;QACvC,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAAE,UAAU;QAClB,aAAa,EAAE,6CAA6C;KAC/D;IACD;QACI,IAAI,EAAE,CAAC;QACP,WAAW,EAAE,0BAA0B;QACvC,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAAE,MAAM;QACd,aAAa,EAAE,uCAAuC;KACzD;IACD;QACI,IAAI,EAAE,CAAC;QACP,WAAW,EAAE,0BAA0B;QACvC,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAAE,gBAAgB;QACxB,aAAa,EAAE,kDAAkD;KACpE;IACD;QACI,IAAI,EAAE,CAAC;QACP,WAAW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15 @@
|
|
|
1
1
|
import { Paginated, PaginateQuery } from 'nestjs-paginate';
|
|
2
|
-
export interface IBaseService<
|
|
3
|
-
id: number;
|
|
2
|
+
export interface IBaseService<CreateMessage, UpdateMessage extends {
|
|
3
|
+
id: number | string;
|
|
4
4
|
}, Message> {
|
|
5
|
-
findOne(id: number): Promise<Message>;
|
|
5
|
+
findOne(id: number | string): Promise<Message>;
|
|
6
6
|
findAll(): Promise<{
|
|
7
7
|
data: Message[];
|
|
8
8
|
}>;
|
|
9
9
|
getMany(query?: PaginateQuery): Promise<Paginated<Message>>;
|
|
10
10
|
create(createDTO: CreateMessage): Promise<Message>;
|
|
11
11
|
update(updateDTO: UpdateMessage): Promise<Message>;
|
|
12
|
-
remove(id: number): Promise<void>;
|
|
12
|
+
remove(id: number | string): Promise<void>;
|
|
13
13
|
count(options?: any): Promise<{
|
|
14
14
|
count: number;
|
|
15
15
|
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Paginated, PaginateQuery } from 'nestjs-paginate';
|
|
2
|
+
export interface IBaseMongoService<CreateMessage, UpdateMessage extends {
|
|
3
|
+
id: string;
|
|
4
|
+
}, Message> {
|
|
5
|
+
findOne(id: string): Promise<Message>;
|
|
6
|
+
findAll(): Promise<{
|
|
7
|
+
data: Message[];
|
|
8
|
+
}>;
|
|
9
|
+
getMany(query?: PaginateQuery): Promise<Paginated<Message>>;
|
|
10
|
+
create(createDTO: CreateMessage): Promise<Message>;
|
|
11
|
+
update(updateDTO: UpdateMessage): Promise<Message>;
|
|
12
|
+
remove(id: string): Promise<void>;
|
|
13
|
+
count(options?: any): Promise<{
|
|
14
|
+
count: number;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.mongo.interface.js","sourceRoot":"","sources":["../../../../src/core/application/base.mongo.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Paginated, PaginateQuery } from 'nestjs-paginate';
|
|
2
|
+
import { IBaseMongoRepository } from '@/core/domain/interfaces/base.mongo.repository.interface';
|
|
3
|
+
import { BaseMongoEntity } from '../infrastracture/databases/base.mongo.entity';
|
|
4
|
+
import { IBaseService } from './base.interface';
|
|
5
|
+
export declare class BaseMongoService<Entity, CreateMessage, UpdateMessage extends {
|
|
6
|
+
id: string;
|
|
7
|
+
}, Message> implements IBaseService<CreateMessage, UpdateMessage, Message> {
|
|
8
|
+
private readonly repository;
|
|
9
|
+
constructor(repository: IBaseMongoRepository<Entity>);
|
|
10
|
+
findOne(id: string): Promise<Message>;
|
|
11
|
+
findAll(): Promise<{
|
|
12
|
+
data: Message[];
|
|
13
|
+
}>;
|
|
14
|
+
getMany(query?: PaginateQuery): Promise<Paginated<Message>>;
|
|
15
|
+
protected transformMongoEntityToMessage(entity: BaseMongoEntity): Message;
|
|
16
|
+
transformPaginatedMongoEntityToPaginatedMessage(paginatedEntities: Paginated<BaseMongoEntity>): Paginated<Message>;
|
|
17
|
+
create(createDTO: CreateMessage): Promise<Message>;
|
|
18
|
+
update(updateDTO: UpdateMessage): Promise<Message>;
|
|
19
|
+
remove(id: string): Promise<void>;
|
|
20
|
+
count(options?: any): Promise<{
|
|
21
|
+
count: number;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseMongoService = void 0;
|
|
4
|
+
const nestjs_grpc_exceptions_1 = require("nestjs-grpc-exceptions");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const mongodb_1 = require("mongodb");
|
|
7
|
+
class BaseMongoService {
|
|
8
|
+
constructor(repository) {
|
|
9
|
+
this.repository = repository;
|
|
10
|
+
}
|
|
11
|
+
async findOne(id) {
|
|
12
|
+
const entity = (await this.repository.findById(id));
|
|
13
|
+
const message = this.transformMongoEntityToMessage(entity);
|
|
14
|
+
if (!entity) {
|
|
15
|
+
throw new nestjs_grpc_exceptions_1.GrpcNotFoundException(`${this.constructor.name.replace('Service', '')} not found`);
|
|
16
|
+
}
|
|
17
|
+
return message;
|
|
18
|
+
}
|
|
19
|
+
async findAll() {
|
|
20
|
+
const entities = await this.repository.find();
|
|
21
|
+
return {
|
|
22
|
+
data: entities,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async getMany(query) {
|
|
26
|
+
if (!query)
|
|
27
|
+
return this.transformPaginatedMongoEntityToPaginatedMessage((await this.repository.getMany({ path: '' })));
|
|
28
|
+
const modifiedQuery = { ...query };
|
|
29
|
+
if (Array.isArray(modifiedQuery.select)) {
|
|
30
|
+
modifiedQuery.select = modifiedQuery.select.map(f => (f === 'id' ? '_id' : f));
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(modifiedQuery.sortBy)) {
|
|
33
|
+
modifiedQuery.sortBy = modifiedQuery.sortBy.map(([field, dir]) => [field === 'id' ? '_id' : field, dir]);
|
|
34
|
+
}
|
|
35
|
+
if (modifiedQuery.filter && typeof modifiedQuery.filter === 'object') {
|
|
36
|
+
const newFilter = {};
|
|
37
|
+
for (const [key, val] of Object.entries(modifiedQuery.filter)) {
|
|
38
|
+
const newKey = key.startsWith('id') ? key.replace(/^id\b/, '_id') : key === 'id' ? '_id' : key;
|
|
39
|
+
newFilter[newKey] = val;
|
|
40
|
+
}
|
|
41
|
+
modifiedQuery.filter = newFilter;
|
|
42
|
+
}
|
|
43
|
+
if (modifiedQuery.cursorColumn === 'id') {
|
|
44
|
+
modifiedQuery.cursorColumn = '_id';
|
|
45
|
+
}
|
|
46
|
+
const entities = (await this.repository.getMany(modifiedQuery));
|
|
47
|
+
return this.transformPaginatedMongoEntityToPaginatedMessage(entities);
|
|
48
|
+
}
|
|
49
|
+
transformMongoEntityToMessage(entity) {
|
|
50
|
+
return { ...entity, id: entity._id.toString() };
|
|
51
|
+
}
|
|
52
|
+
transformPaginatedMongoEntityToPaginatedMessage(paginatedEntities) {
|
|
53
|
+
const transformedData = paginatedEntities.data.map(entity => {
|
|
54
|
+
return this.transformMongoEntityToMessage(entity);
|
|
55
|
+
});
|
|
56
|
+
const paginatedMessages = {
|
|
57
|
+
links: { ...paginatedEntities.links },
|
|
58
|
+
meta: { ...paginatedEntities.meta },
|
|
59
|
+
data: transformedData,
|
|
60
|
+
};
|
|
61
|
+
return paginatedMessages;
|
|
62
|
+
}
|
|
63
|
+
async create(createDTO) {
|
|
64
|
+
const entity = this.repository.create(createDTO);
|
|
65
|
+
for (const key of this.repository.paginateConfig.dateColumns) {
|
|
66
|
+
entity[key] = createDTO[key] ? new Date(createDTO[key]) : null;
|
|
67
|
+
}
|
|
68
|
+
const savedEntity = await this.repository.save(entity);
|
|
69
|
+
return this.transformMongoEntityToMessage(savedEntity);
|
|
70
|
+
}
|
|
71
|
+
async update(updateDTO) {
|
|
72
|
+
const entity = await this.repository.findById(updateDTO.id);
|
|
73
|
+
if (!entity) {
|
|
74
|
+
throw new nestjs_grpc_exceptions_1.GrpcNotFoundException(`${this.constructor.name.replace('Service', '')} not found`);
|
|
75
|
+
}
|
|
76
|
+
const objectId = new mongodb_1.ObjectId(updateDTO.id);
|
|
77
|
+
await this.repository.update(objectId, (0, class_transformer_1.instanceToPlain)(updateDTO));
|
|
78
|
+
const updatedEntity = await this.repository.findById(updateDTO.id);
|
|
79
|
+
return this.transformMongoEntityToMessage(updatedEntity);
|
|
80
|
+
}
|
|
81
|
+
async remove(id) {
|
|
82
|
+
const objectId = new mongodb_1.ObjectId(id);
|
|
83
|
+
await this.repository.delete(objectId);
|
|
84
|
+
}
|
|
85
|
+
async count(options) {
|
|
86
|
+
const count = await this.repository.count(options || {});
|
|
87
|
+
return { count };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.BaseMongoService = BaseMongoService;
|
|
91
|
+
//# sourceMappingURL=base.mongo.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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AAE,CAAC;YACZ,MAAM,IAAI,8CAAqB,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC;QAC/F,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,kBAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAC5C,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAe,EAAE,IAAA,mCAAe,EAAC,SAAS,CAAQ,CAAC,CAAC;QACjF,MAAM,aAAa,GAAW,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC,6BAA6B,CAAC,aAA2C,CAAC,CAAC;IACzF,CAAC;IAOD,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,MAAM,QAAQ,GAAG,IAAI,kBAAQ,CAAC,EAAE,CAAC,CAAC;QAClC,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAe,CAAC,CAAC;IAChD,CAAC;IAOD,KAAK,CAAC,KAAK,CAAC,OAAa;QACvB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;QACzD,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;CACF;AAjKD,4CAiKC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Paginated, PaginateQuery } from 'nestjs-paginate';
|
|
2
|
-
import { IBaseRepository } from '
|
|
2
|
+
import { IBaseRepository } from '@/core/domain/interfaces/base.repository.interface';
|
|
3
3
|
import { IBaseService } from './base.interface';
|
|
4
4
|
export declare class BaseService<Entity, CreateMessage extends Partial<Entity>, UpdateMessage extends Partial<Entity> & {
|
|
5
5
|
id: number;
|
|
6
|
-
}, Message> implements IBaseService<
|
|
6
|
+
}, Message> implements IBaseService<CreateMessage, UpdateMessage, Message> {
|
|
7
7
|
private readonly repository;
|
|
8
8
|
constructor(repository: IBaseRepository<Entity>);
|
|
9
9
|
findOne(id: number): Promise<Message>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LoggerService } from '@/modules/logger/pino/logger.service';
|
|
2
|
+
import { Cache } from '@nestjs/cache-manager';
|
|
3
|
+
import { Paginated, PaginateQuery } from 'nestjs-paginate';
|
|
4
|
+
import { CacheConfiguration } from '../domain/interfaces/cache-configuration.interface';
|
|
5
|
+
import { IBaseService } from './base.interface';
|
|
6
|
+
import { CachedService } from './cached.service';
|
|
7
|
+
export declare class CachedBaseService<Entity, CreateMessage, UpdateMessage extends {
|
|
8
|
+
id: number | string;
|
|
9
|
+
}, Message> extends CachedService implements IBaseService<CreateMessage, UpdateMessage, Message> {
|
|
10
|
+
protected readonly logger: LoggerService;
|
|
11
|
+
protected readonly service: IBaseService<CreateMessage, UpdateMessage, Message>;
|
|
12
|
+
protected readonly cacheManager: Cache;
|
|
13
|
+
protected readonly cacheConfig: CacheConfiguration;
|
|
14
|
+
constructor(logger: LoggerService, service: IBaseService<CreateMessage, UpdateMessage, Message>, cacheManager: Cache, cacheConfig: CacheConfiguration);
|
|
15
|
+
findOne(id: number | string): Promise<Message>;
|
|
16
|
+
findAll(): Promise<{
|
|
17
|
+
data: Message[];
|
|
18
|
+
}>;
|
|
19
|
+
getMany(query?: PaginateQuery): Promise<Paginated<Message>>;
|
|
20
|
+
create(createDTO: CreateMessage): Promise<Message>;
|
|
21
|
+
update(updateDTO: UpdateMessage): Promise<Message>;
|
|
22
|
+
remove(id: number | string): Promise<void>;
|
|
23
|
+
count(options?: any): Promise<{
|
|
24
|
+
count: number;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CachedBaseService = void 0;
|
|
4
|
+
const cache_configuration_interface_1 = require("../domain/interfaces/cache-configuration.interface");
|
|
5
|
+
const cached_service_1 = require("./cached.service");
|
|
6
|
+
class CachedBaseService extends cached_service_1.CachedService {
|
|
7
|
+
constructor(logger, service, cacheManager, cacheConfig) {
|
|
8
|
+
super(logger, cacheManager, cacheConfig);
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.service = service;
|
|
11
|
+
this.cacheManager = cacheManager;
|
|
12
|
+
this.cacheConfig = cacheConfig;
|
|
13
|
+
}
|
|
14
|
+
async findOne(id) {
|
|
15
|
+
const cacheKey = this.generateCacheKey('findOne', { id });
|
|
16
|
+
return await this.getOrSetCache(cacheKey, async () => await this.service.findOne(id));
|
|
17
|
+
}
|
|
18
|
+
async findAll() {
|
|
19
|
+
const cacheKey = this.generateCacheKey('findAll');
|
|
20
|
+
return await this.getOrSetCache(cacheKey, async () => await this.service.findAll());
|
|
21
|
+
}
|
|
22
|
+
async getMany(query) {
|
|
23
|
+
const cacheKey = this.generateCacheKey('getMany', query);
|
|
24
|
+
return await this.getOrSetCache(cacheKey, async () => await this.service.getMany(query));
|
|
25
|
+
}
|
|
26
|
+
async create(createDTO) {
|
|
27
|
+
const result = await this.service.create(createDTO);
|
|
28
|
+
if (this.cacheConfig.invalidationStrategy === cache_configuration_interface_1.InvalidationStrategy.OnChange) {
|
|
29
|
+
await this.invalidateCache();
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
async update(updateDTO) {
|
|
34
|
+
const result = await this.service.update(updateDTO);
|
|
35
|
+
if (this.cacheConfig.invalidationStrategy === cache_configuration_interface_1.InvalidationStrategy.OnChange) {
|
|
36
|
+
await this.invalidateCache();
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
async remove(id) {
|
|
41
|
+
await this.service.remove(id);
|
|
42
|
+
if (this.cacheConfig.invalidationStrategy === cache_configuration_interface_1.InvalidationStrategy.OnChange) {
|
|
43
|
+
await this.invalidateCache();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async count(options) {
|
|
47
|
+
const cacheKey = this.generateCacheKey('count', options);
|
|
48
|
+
return await this.getOrSetCache(cacheKey, async () => await this.service.count(options));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.CachedBaseService = CachedBaseService;
|
|
52
|
+
//# sourceMappingURL=cached-base.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cached-base.service.js","sourceRoot":"","sources":["../../../../src/core/application/cached-base.service.ts"],"names":[],"mappings":";;;AAGA,sGAA8G;AAE9G,qDAAiD;AAKjD,MAAa,iBAKX,SAAQ,8BAAa;IAUrB,YACqB,MAAqB,EACrB,OAA4D,EAC5D,YAAmB,EACnB,WAA+B;QAElD,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;QALtB,WAAM,GAAN,MAAM,CAAe;QACrB,YAAO,GAAP,OAAO,CAAqD;QAC5D,iBAAY,GAAZ,YAAY,CAAO;QACnB,gBAAW,GAAX,WAAW,CAAoB;IAGnD,CAAC;IAQF,KAAK,CAAC,OAAO,CAAC,EAAmB;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1D,OAAO,MAAM,IAAI,CAAC,aAAa,CAAU,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACjG,CAAC;IAOD,KAAK,CAAC,OAAO;QACX,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAClD,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACtF,CAAC;IASD,KAAK,CAAC,OAAO,CAAC,KAAqB;QACj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AAC,aAAa,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3F,CAAC;CACF;AA5GD,8CA4GC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LoggerService } from '@/modules/logger/pino/logger.service';
|
|
2
|
+
import { Cache } from '@nestjs/cache-manager';
|
|
3
|
+
import { CacheConfiguration } from '../domain/interfaces/cache-configuration.interface';
|
|
4
|
+
export declare class CachedService {
|
|
5
|
+
protected readonly logger: LoggerService;
|
|
6
|
+
protected readonly cacheManager: Cache;
|
|
7
|
+
protected readonly cacheConfig: CacheConfiguration;
|
|
8
|
+
protected readonly serviceName: string;
|
|
9
|
+
constructor(logger: LoggerService, cacheManager: Cache, cacheConfig: CacheConfiguration);
|
|
10
|
+
protected generateCacheKey(method: string, params?: any): string;
|
|
11
|
+
protected getOrSetCache<T>(key: string, fn: () => Promise<T>): Promise<T>;
|
|
12
|
+
protected invalidateCache(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CachedService = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
class CachedService {
|
|
6
|
+
constructor(logger, cacheManager, cacheConfig) {
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
this.cacheManager = cacheManager;
|
|
9
|
+
this.cacheConfig = cacheConfig;
|
|
10
|
+
this.serviceName = this.constructor.name.toLowerCase().replace('service', '');
|
|
11
|
+
}
|
|
12
|
+
generateCacheKey(method, params) {
|
|
13
|
+
const paramsHash = params ? (0, crypto_1.createHash)('md5').update(JSON.stringify(params)).digest('hex') : 'all';
|
|
14
|
+
return `${this.serviceName}:${method}:${paramsHash}`;
|
|
15
|
+
}
|
|
16
|
+
async getOrSetCache(key, fn) {
|
|
17
|
+
try {
|
|
18
|
+
const cached = await this.cacheManager.get(key);
|
|
19
|
+
if (cached) {
|
|
20
|
+
this.logger.debug(`Cache hit for key: ${key}`);
|
|
21
|
+
return JSON.parse(cached);
|
|
22
|
+
}
|
|
23
|
+
this.logger.debug(`Cache miss for key: ${key}`);
|
|
24
|
+
const result = await fn();
|
|
25
|
+
await this.cacheManager.set(key, JSON.stringify(result));
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
this.logger.error(`An error occurred while fetching cache for key: ${key}`);
|
|
30
|
+
this.logger.error(error);
|
|
31
|
+
return await fn();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async invalidateCache() {
|
|
35
|
+
try {
|
|
36
|
+
this.logger.debug(`Invalidating cache for service: ${this.serviceName}`);
|
|
37
|
+
const storeIterator = this.cacheManager.stores[0].iterator;
|
|
38
|
+
const keys = [];
|
|
39
|
+
if (storeIterator) {
|
|
40
|
+
for await (const [key, value] of storeIterator('namespace')) {
|
|
41
|
+
if (key.split(':')[0] === this.serviceName) {
|
|
42
|
+
keys.push(key);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
await this.cacheManager.mdel(keys);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
this.logger.error(`An error occurred while invalidating cache for service: ${this.serviceName}`);
|
|
50
|
+
this.logger.error(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.CachedService = CachedService;
|
|
55
|
+
//# sourceMappingURL=cached.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cached.service.js","sourceRoot":"","sources":["../../../../src/core/application/cached.service.ts"],"names":[],"mappings":";;;AAEA,mCAAoC;AAMpC,MAAa,aAAa;IAWxB,YACqB,MAAqB,EACrB,YAAmB,EACnB,WAA+B;QAF/B,WAAM,GAAN,MAAM,CAAe;QACrB,iBAAY,GAAZ,YAAY,CAA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CAAC,CAAC;YAEzB,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;IAOS,KAAK,CAAC,eAAe;QAC7B,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;YACzE,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YAC3D,MAAM,IAAI,GAAkB,EAAE,CAAC;YAC/B,IAAI,aAAa,EAAE,CAAC;gBAClB,IAAI,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;oBAC5D,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;wBAC3C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACjB,CAAC;gBACH,CAAC;gBACD,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAEf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2DAA2D,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;YACjG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;CACF;AAvFD,sCAuFC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PaginateQuery, Paginated } from 'nestjs-paginate';
|
|
2
|
+
import { MongoRepository } from 'typeorm';
|
|
3
|
+
import { ObjectId } from 'mongodb';
|
|
4
|
+
import { ExtendedPaginateConfig } from 'index';
|
|
5
|
+
export interface IBaseMongoId {
|
|
6
|
+
_id: ObjectId;
|
|
7
|
+
}
|
|
8
|
+
export interface IBaseMongoRepository<E> extends MongoRepository<E> {
|
|
9
|
+
getMany(query: PaginateQuery): Promise<Paginated<E>>;
|
|
10
|
+
findById(id: string | ObjectId): Promise<E>;
|
|
11
|
+
paginateConfig: ExtendedPaginateConfig<E>;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.mongo.repository.interface.js","sourceRoot":"","sources":["../../../../../src/core/domain/interfaces/base.mongo.repository.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidationStrategy = exports.CACHE_CONF = void 0;
|
|
4
|
+
exports.CACHE_CONF = Symbol('CACHE_CONF');
|
|
5
|
+
var InvalidationStrategy;
|
|
6
|
+
(function (InvalidationStrategy) {
|
|
7
|
+
InvalidationStrategy["TTL"] = "TTL";
|
|
8
|
+
InvalidationStrategy["OnChange"] = "OnChange";
|
|
9
|
+
})(InvalidationStrategy || (exports.InvalidationStrategy = InvalidationStrategy = {}));
|
|
10
|
+
;
|
|
11
|
+
//# sourceMappingURL=cache-configuration.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-configuration.interface.js","sourceRoot":"","sources":["../../../../../src/core/domain/interfaces/cache-configuration.interface.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAE/C,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,mCAAW,CAAA;IACX,6CAAqB,CAAA;AACvB,CAAC,EAHW,oBAAoB,oCAApB,oBAAoB,QAG/B;AAAA,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { EntitySubscriberInterface, InsertEvent, UpdateEvent } from 'typeorm';
|
|
3
|
+
import { ExtendedPaginateConfig, IBaseMongoEntity } from './base.mongo.entity.interface';
|
|
4
|
+
export declare class BaseMongoEntity implements IBaseMongoEntity {
|
|
5
|
+
_id: ObjectId;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
updatedAt: Date;
|
|
8
|
+
}
|
|
9
|
+
export declare class BaseMongoEntitySubscriber implements EntitySubscriberInterface<BaseMongoEntity> {
|
|
10
|
+
listenTo(): typeof BaseMongoEntity;
|
|
11
|
+
beforeInsert(event: InsertEvent<BaseMongoEntity>): void;
|
|
12
|
+
beforeUpdate(event: UpdateEvent<BaseMongoEntity>): void | Promise<any>;
|
|
13
|
+
}
|
|
14
|
+
export declare const paginationConfig: ExtendedPaginateConfig<BaseMongoEntity>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { PaginateConfig } from 'nestjs-paginate/lib/paginate';
|
|
3
|
+
export interface IBaseMongoEntity {
|
|
4
|
+
_id: ObjectId;
|
|
5
|
+
createdAt: Date;
|
|
6
|
+
updatedAt: Date;
|
|
7
|
+
}
|
|
8
|
+
export interface ExtendedPaginateConfig<E> extends PaginateConfig<E> {
|
|
9
|
+
dateColumns?: string[];
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.mongo.entity.interface.js","sourceRoot":"","sources":["../../../../../src/core/infrastracture/databases/base.mongo.entity.interface.ts"],"names":[],"mappings":""}
|