@futdevpro/nts-dynamo 1.6.55 → 1.6.59
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/lib/_constants/global-settings.const.d.ts.map +1 -1
- package/lib/_constants/global-settings.const.js +4 -1
- package/lib/_constants/global-settings.const.js.map +1 -1
- package/lib/_enums/http/socket-event-type.enum.d.ts +1 -0
- package/lib/_enums/http/socket-event-type.enum.d.ts.map +1 -1
- package/lib/_enums/http/socket-event-type.enum.js +1 -0
- package/lib/_enums/http/socket-event-type.enum.js.map +1 -1
- package/lib/_models/control-models/app-params.control-model.d.ts +12 -27
- package/lib/_models/control-models/app-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/app-params.control-model.js +2 -1
- package/lib/_models/control-models/app-params.control-model.js.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.d.ts +5 -0
- package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +32 -12
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.js +2 -1
- package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js +4 -2
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_models/interfaces/global-settings.interface.d.ts +17 -1
- package/lib/_models/interfaces/global-settings.interface.d.ts.map +1 -1
- package/lib/_services/base/data.service.d.ts +2 -0
- package/lib/_services/base/data.service.d.ts.map +1 -1
- package/lib/_services/base/data.service.js +48 -0
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/base/db.service.d.ts +1 -0
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +34 -29
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/core/api.service.d.ts.map +1 -1
- package/lib/_services/core/api.service.js +42 -20
- package/lib/_services/core/api.service.js.map +1 -1
- package/lib/_services/core/global.service.d.ts +1 -1
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +3 -1
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.js +2 -2
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app.server.d.ts +2 -1
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +23 -15
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +1 -1
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +11 -8
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/_constants/global-settings.const.ts +4 -1
- package/src/_enums/http/socket-event-type.enum.ts +2 -0
- package/src/_models/control-models/app-params.control-model.ts +13 -27
- package/src/_models/control-models/endpoint-params.control-model.ts +36 -7
- package/src/_models/control-models/socket-event.control-model.ts +4 -1
- package/src/_models/control-models/socket-presence.control-model.ts +8 -2
- package/src/_models/interfaces/global-settings.interface.ts +17 -1
- package/src/_services/base/data.service.ts +79 -0
- package/src/_services/base/db.service.ts +47 -28
- package/src/_services/core/api.service.ts +38 -14
- package/src/_services/core/global.service.ts +4 -2
- package/src/_services/server/app-extended.server.ts +2 -2
- package/src/_services/server/app.server.ts +30 -13
- package/src/_services/socket/socket-server.service.ts +7 -4
|
@@ -18,5 +18,8 @@ export const dynamoNTS_globalSettings: DynamoNTS_GlobalSettings = {
|
|
|
18
18
|
logMainSocketEvents: true,
|
|
19
19
|
logSocketEventContent: false,
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
logApiEvents: true,
|
|
22
|
+
logApiRequestContents: false,
|
|
23
|
+
logApiRequestSettings: false,
|
|
24
|
+
logApiResponseContents: false,
|
|
22
25
|
};
|
|
@@ -10,50 +10,36 @@ export class DynamoNTS_AppParams {
|
|
|
10
10
|
/**
|
|
11
11
|
* title will be shown on the start of the application
|
|
12
12
|
*/
|
|
13
|
-
title
|
|
13
|
+
title?: string;
|
|
14
14
|
/**
|
|
15
15
|
* version of the application
|
|
16
|
+
* you should set the version,
|
|
17
|
+
* probably, you should set from the package.json as follows:
|
|
18
|
+
* import { version } from '../package.json';
|
|
16
19
|
*/
|
|
17
20
|
version: string;
|
|
18
21
|
/**
|
|
19
22
|
* name of your MongoDB table
|
|
23
|
+
* by default, its: `mongodb://localhost:27017/${this.dbName}`
|
|
20
24
|
*/
|
|
21
|
-
dbUri
|
|
25
|
+
dbUri?: string;
|
|
22
26
|
/**
|
|
23
|
-
*
|
|
27
|
+
* name of your MongoDB table
|
|
24
28
|
*/
|
|
25
29
|
dbName: string;
|
|
30
|
+
/**
|
|
31
|
+
* name of the system, by default, its: this.name.replace(' ', '-')
|
|
32
|
+
*/
|
|
33
|
+
systemName?: string;
|
|
26
34
|
|
|
27
35
|
constructor(
|
|
28
|
-
set:
|
|
29
|
-
/**
|
|
30
|
-
* name the application
|
|
31
|
-
*/
|
|
32
|
-
name: string,
|
|
33
|
-
/**
|
|
34
|
-
* you can set a big f*in title to show on the start of the application
|
|
35
|
-
*/
|
|
36
|
-
title?: string,
|
|
37
|
-
/**
|
|
38
|
-
* you should set the version,
|
|
39
|
-
* probably, you should set from the package.json as follows:
|
|
40
|
-
* import { version } from '../package.json';
|
|
41
|
-
*/
|
|
42
|
-
version: string,
|
|
43
|
-
/**
|
|
44
|
-
* You need to name your MongoDB table
|
|
45
|
-
*/
|
|
46
|
-
dbName: string,
|
|
47
|
-
/**
|
|
48
|
-
* you can change the mongoDB uri here. by default, its: `mongodb://localhost:27017/${this.dbName}`
|
|
49
|
-
*/
|
|
50
|
-
dbUri?: string,
|
|
51
|
-
}
|
|
36
|
+
set: DynamoNTS_AppParams
|
|
52
37
|
) {
|
|
53
38
|
this.name = set.name;
|
|
54
39
|
this.title = set.title ?? '';
|
|
55
40
|
this.version = set.version;
|
|
56
41
|
this.dbName = set.dbName;
|
|
57
42
|
this.dbUri = set.dbUri ?? `mongodb://localhost:27017/${this.dbName}`;
|
|
43
|
+
this.systemName = set.systemName ?? this.name.replace(' ', '-');
|
|
58
44
|
}
|
|
59
45
|
}
|
|
@@ -26,6 +26,7 @@ export class DynamoNTS_EndpointParams{
|
|
|
26
26
|
private tasks: ((req: Request, res: Response, issuer?: string) => Promise<void>)[];
|
|
27
27
|
|
|
28
28
|
private logRequest: boolean;
|
|
29
|
+
private logRequestsParams: boolean;
|
|
29
30
|
private logRequestsContent: boolean;
|
|
30
31
|
private logResponseContent: boolean;
|
|
31
32
|
|
|
@@ -68,6 +69,10 @@ export class DynamoNTS_EndpointParams{
|
|
|
68
69
|
* this flag will enable the debug logs on this endpoint
|
|
69
70
|
*/
|
|
70
71
|
logRequest?: boolean,
|
|
72
|
+
/**
|
|
73
|
+
* this flag will enable the debug logs on this endpoint's requests
|
|
74
|
+
*/
|
|
75
|
+
logRequestsParams?: boolean,
|
|
71
76
|
/**
|
|
72
77
|
* this flag will enable the debug logs on this endpoint's requests
|
|
73
78
|
*/
|
|
@@ -104,11 +109,15 @@ export class DynamoNTS_EndpointParams{
|
|
|
104
109
|
this.tasks = set.tasks;
|
|
105
110
|
|
|
106
111
|
this.logRequest = set.logRequest ?? dynamoNTS_globalSettings.logRequest;
|
|
112
|
+
this.logRequestsParams = set.logRequestsParams ?? dynamoNTS_globalSettings.logRequestsParams;
|
|
107
113
|
this.logRequestsContent = set.logRequestsContent ?? dynamoNTS_globalSettings.logRequestsContent;
|
|
108
|
-
|
|
114
|
+
this.logResponseContent = set.logResponseContent ?? dynamoNTS_globalSettings.logResponseContent;
|
|
109
115
|
} catch (error) {
|
|
110
116
|
Dynamo_Log.error(
|
|
111
|
-
`\nEndpoint params setup failed: name: '${set.name}' (security: ${set.security}) endpoint: ${set.endpoint}
|
|
117
|
+
`\nEndpoint params setup failed: name: '${set.name}' (security: ${set.security}) endpoint: ${set.endpoint}` +
|
|
118
|
+
`\nERROR:` +
|
|
119
|
+
`\n`, error
|
|
120
|
+
);
|
|
112
121
|
throw error;
|
|
113
122
|
}
|
|
114
123
|
}
|
|
@@ -120,17 +129,37 @@ export class DynamoNTS_EndpointParams{
|
|
|
120
129
|
private async preLog(req: Request, res: Response, issuer: string): Promise<void> {
|
|
121
130
|
try {
|
|
122
131
|
if (this.logRequest) {
|
|
123
|
-
|
|
132
|
+
let msg: string = `===> incoming ${this.name} request... (issuer: ${issuer})`;
|
|
133
|
+
|
|
134
|
+
if (this.logRequestsParams) {
|
|
135
|
+
const params = this.getPathParamsLogContent(req);
|
|
136
|
+
msg += `\npathParams: ${params}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (this.logRequestsContent && req.body && 0 < Object.keys(req.body).length) {
|
|
140
|
+
Dynamo_Log.info(msg + `\nbody:`, req.body);
|
|
141
|
+
} else {
|
|
142
|
+
Dynamo_Log.info(msg);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* if (this.logRequestsContent) {
|
|
124
146
|
const params = this.getPathParamsLogContent(req);
|
|
125
147
|
|
|
126
148
|
if (req.body && 0 < Object.keys(req.body).length) {
|
|
127
|
-
console.log(
|
|
149
|
+
console.log(
|
|
150
|
+
`===> incoming ${this.name} request... (issuer: ${issuer})` +
|
|
151
|
+
`\npathParams: ${params}` +
|
|
152
|
+
`\nbody:`, req.body
|
|
153
|
+
);
|
|
128
154
|
} else {
|
|
129
|
-
console.log(
|
|
155
|
+
console.log(
|
|
156
|
+
`===> incoming ${this.name} request... (issuer: ${issuer})` +
|
|
157
|
+
`\npathParams: ${params}`
|
|
158
|
+
);
|
|
130
159
|
}
|
|
131
160
|
} else {
|
|
132
|
-
console.log(`===>
|
|
133
|
-
}
|
|
161
|
+
console.log(`===> incoming ${this.name} request...`);
|
|
162
|
+
} */
|
|
134
163
|
}
|
|
135
164
|
|
|
136
165
|
} catch (error) {
|
|
@@ -96,7 +96,10 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
96
96
|
private async getPreLog(content: T, issuer?: string): Promise<void> {
|
|
97
97
|
try {
|
|
98
98
|
if (this.logEventContent && this.eventKey !== DynamoNTS_SocketEventKey.connection) {
|
|
99
|
-
Dynamo_Log.log(
|
|
99
|
+
Dynamo_Log.log(
|
|
100
|
+
`---> incoming socket(${this.serviceName}) event: ${this.eventKey};
|
|
101
|
+
\ncontent:`, content
|
|
102
|
+
);
|
|
100
103
|
} else {
|
|
101
104
|
Dynamo_Log.log(`---> incoming socket(${this.serviceName}) event: ${this.eventKey}...`);
|
|
102
105
|
}
|
|
@@ -53,7 +53,10 @@ export class DynamoNTS_SocketPresence {
|
|
|
53
53
|
|
|
54
54
|
this.sockets.forEach((socket: SocketIO.Socket, index: number) => {
|
|
55
55
|
if (!socket.connected) {
|
|
56
|
-
Dynamo_Log.
|
|
56
|
+
Dynamo_Log.warn(
|
|
57
|
+
`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!` +
|
|
58
|
+
`\nERROR: socket[${socket.id}] is not connected! (it will be removed...)`
|
|
59
|
+
);
|
|
57
60
|
|
|
58
61
|
/* errors.push(
|
|
59
62
|
new Dynamo_Error({
|
|
@@ -74,7 +77,10 @@ export class DynamoNTS_SocketPresence {
|
|
|
74
77
|
|
|
75
78
|
this.sockets.forEach((socket: SocketIO.Socket, index: number) => {
|
|
76
79
|
const success: boolean = socket.emit(event, content, error => {
|
|
77
|
-
Dynamo_Log.error(
|
|
80
|
+
Dynamo_Log.error(
|
|
81
|
+
`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!(0)` +
|
|
82
|
+
`\nerror:`, error
|
|
83
|
+
);
|
|
78
84
|
errors.push(error);
|
|
79
85
|
});
|
|
80
86
|
|
|
@@ -33,6 +33,10 @@ export interface DynamoNTS_GlobalSettings {
|
|
|
33
33
|
* this is an application wide default setting for route debug logs
|
|
34
34
|
*/
|
|
35
35
|
logRequest?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* this is an application wide default setting for route debug logs
|
|
38
|
+
*/
|
|
39
|
+
logRequestsParams?: boolean;
|
|
36
40
|
/**
|
|
37
41
|
* this is an application wide default setting for route debug logs
|
|
38
42
|
*/
|
|
@@ -58,5 +62,17 @@ export interface DynamoNTS_GlobalSettings {
|
|
|
58
62
|
/**
|
|
59
63
|
* this is an application wide default setting for api debug logs
|
|
60
64
|
*/
|
|
61
|
-
|
|
65
|
+
logApiEvents?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* this is an application wide default setting for api debug logs
|
|
68
|
+
*/
|
|
69
|
+
logApiRequestContents?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* this is an application wide default setting for api debug logs
|
|
72
|
+
*/
|
|
73
|
+
logApiRequestSettings?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* this is an application wide default setting for api debug logs
|
|
76
|
+
*/
|
|
77
|
+
logApiResponseContents?: boolean;
|
|
62
78
|
}
|
|
@@ -148,6 +148,38 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
+
|
|
152
|
+
async getDataByIds(ids: string[], dontSetToService?: boolean): Promise<T[]> {
|
|
153
|
+
try {
|
|
154
|
+
if (!ids) {
|
|
155
|
+
throw new Dynamo_Error({
|
|
156
|
+
...this._getDefaultErrorSettings(
|
|
157
|
+
'getDataByIds',
|
|
158
|
+
new Error(`getDataByIds failed, ids is missing! (${this.dataParams.dataName})`)
|
|
159
|
+
),
|
|
160
|
+
|
|
161
|
+
errorCode: 'NTS-DS0-GIS1',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (ids.length === 0) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const datas: T[] = await this.dataDBService.find({ _id: { $in: ids, }, });
|
|
170
|
+
if (!dontSetToService) {
|
|
171
|
+
this.dataList = datas;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return datas;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
throw new Dynamo_Error({
|
|
177
|
+
...this._getDefaultErrorSettings('getDataByIds', error),
|
|
178
|
+
|
|
179
|
+
errorCode: 'NTS-DS0-GIS0',
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
151
183
|
|
|
152
184
|
/**
|
|
153
185
|
* returns data from database by dependencyId to the service
|
|
@@ -203,6 +235,53 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
203
235
|
}
|
|
204
236
|
}
|
|
205
237
|
}
|
|
238
|
+
|
|
239
|
+
async getDatasByDependencyIds(dependencyIds: string[], dontSetToService?: boolean): Promise<T[]> {
|
|
240
|
+
try {
|
|
241
|
+
if (!this.depKey) {
|
|
242
|
+
throw new Dynamo_Error({
|
|
243
|
+
...this._getDefaultErrorSettings(
|
|
244
|
+
'getDatasByDependencyIds',
|
|
245
|
+
new Error(`getDatasByDependencyIds failed, dependencyKey is missing from service! (${this.dataParams.dataName})`)
|
|
246
|
+
),
|
|
247
|
+
|
|
248
|
+
errorCode: 'NTS-DS0-GDS1',
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (!dependencyIds) {
|
|
253
|
+
throw new Dynamo_Error({
|
|
254
|
+
...this._getDefaultErrorSettings(
|
|
255
|
+
'getDatasByDependencyIds',
|
|
256
|
+
new Error(`getDatasByDependencyIds failed, dependencyIds is missing! (${this.dataParams.dataName})`)
|
|
257
|
+
),
|
|
258
|
+
|
|
259
|
+
errorCode: 'NTS-DS0-GDS2',
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (dependencyIds.length === 0) {
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const datas: T[] = await this.dataDBService.getDatasByDependencyIds(dependencyIds);
|
|
268
|
+
if (!dontSetToService) {
|
|
269
|
+
this.dataList = datas;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return datas;
|
|
273
|
+
} catch (error) {
|
|
274
|
+
if ([ 'NTS-DS0-GDS1', 'NTS-DS0-GDS2' ].includes(error?.errorCode)) {
|
|
275
|
+
throw error;
|
|
276
|
+
} else {
|
|
277
|
+
throw new Dynamo_Error({
|
|
278
|
+
...this._getDefaultErrorSettings('getDatasByDependencyIds', error),
|
|
279
|
+
|
|
280
|
+
errorCode: 'NTS-DS0-GDS0',
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
206
285
|
|
|
207
286
|
/**
|
|
208
287
|
* returns dataList from database by dependencyId to the service
|
|
@@ -244,12 +244,41 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
244
244
|
});
|
|
245
245
|
});
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
247
|
+
dataList.forEach((data: T) => {
|
|
248
|
+
data = this.stringifyDataId(data, 'getDataListByDependencyId');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return dataList;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async getDatasByDependencyIds(dependencyIds: string[]): Promise<T[]> {
|
|
255
|
+
if (!this.depDataName) {
|
|
256
|
+
throw new Dynamo_Error({
|
|
257
|
+
...this._getDefaultErrorSettings(
|
|
258
|
+
'getDatasByDependencyIds',
|
|
259
|
+
new Error(`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`)
|
|
260
|
+
),
|
|
261
|
+
|
|
262
|
+
status: 501,
|
|
263
|
+
errorCode: 'NTS-DBS-GLDS0',
|
|
250
264
|
});
|
|
251
265
|
}
|
|
252
266
|
|
|
267
|
+
let dataList: T[] = await this.dataModel.find({ [this.depDataName]: { $in: dependencyIds }}).then(res => {
|
|
268
|
+
return res as T[] ?? [];
|
|
269
|
+
}).catch(error => {
|
|
270
|
+
throw new Dynamo_Error({
|
|
271
|
+
...this._getDefaultErrorSettings('getDatasByDependencyIds', error),
|
|
272
|
+
|
|
273
|
+
errorCode: 'NTS-DBS-GLDS1',
|
|
274
|
+
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
dataList.forEach((data: T) => {
|
|
279
|
+
data = this.stringifyDataId(data, 'getDatasByDependencyIds');
|
|
280
|
+
});
|
|
281
|
+
|
|
253
282
|
return dataList;
|
|
254
283
|
}
|
|
255
284
|
|
|
@@ -284,11 +313,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
284
313
|
});
|
|
285
314
|
});
|
|
286
315
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
});
|
|
291
|
-
}
|
|
316
|
+
dataList.forEach((data: T) => {
|
|
317
|
+
data = this.stringifyDataId(data, 'getDataListByDependencyIds');
|
|
318
|
+
});
|
|
292
319
|
|
|
293
320
|
return dataList;
|
|
294
321
|
}
|
|
@@ -312,11 +339,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
312
339
|
});
|
|
313
340
|
});
|
|
314
341
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
});
|
|
319
|
-
}
|
|
342
|
+
dataList.forEach((data: T) => {
|
|
343
|
+
data = this.stringifyDataId(data, 'getAll');
|
|
344
|
+
});
|
|
320
345
|
|
|
321
346
|
return dataList as T[];
|
|
322
347
|
}
|
|
@@ -449,11 +474,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
449
474
|
});
|
|
450
475
|
});
|
|
451
476
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
});
|
|
456
|
-
}
|
|
477
|
+
dataList.forEach((data: T) => {
|
|
478
|
+
data = this.stringifyDataId(data, 'searchData');
|
|
479
|
+
});
|
|
457
480
|
|
|
458
481
|
return dataList;
|
|
459
482
|
}
|
|
@@ -546,11 +569,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
546
569
|
});
|
|
547
570
|
});
|
|
548
571
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
});
|
|
553
|
-
}
|
|
572
|
+
dataList.forEach((data: T) => {
|
|
573
|
+
data = this.stringifyDataId(data, 'find');
|
|
574
|
+
});
|
|
554
575
|
|
|
555
576
|
return dataList as T[];
|
|
556
577
|
}
|
|
@@ -603,11 +624,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
603
624
|
});
|
|
604
625
|
});
|
|
605
626
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
});
|
|
610
|
-
}
|
|
627
|
+
dataList.forEach((data: T) => {
|
|
628
|
+
data = this.stringifyDataId(data, 'findWithPaging');
|
|
629
|
+
});
|
|
611
630
|
|
|
612
631
|
return dataList;
|
|
613
632
|
}
|
|
@@ -101,6 +101,21 @@ export class DynamoNTS_ApiService {
|
|
|
101
101
|
callParams.httpOptions.params = httpParams;
|
|
102
102
|
} */
|
|
103
103
|
|
|
104
|
+
if (dynamoNTS_globalSettings.logApiEvents) {
|
|
105
|
+
if (dynamoNTS_globalSettings.logApiRequestContents) {
|
|
106
|
+
Dynamo_Log.log(`< outgoing API call: ${url} \nbody:`, inputParams?.body);
|
|
107
|
+
} else {
|
|
108
|
+
Dynamo_Log.log(`< outgoing API call: ${url}`);
|
|
109
|
+
}
|
|
110
|
+
if (dynamoNTS_globalSettings.logApiRequestSettings) {
|
|
111
|
+
Dynamo_Log.log(`callParams:`, callParams);
|
|
112
|
+
Dynamo_Log.log('inputParams:', {
|
|
113
|
+
pathParams: inputParams.pathParams ?? {},
|
|
114
|
+
body: inputParams.body ?? null
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
104
119
|
switch (callParams.type) {
|
|
105
120
|
case DynamoNTS_HttpCallType.get:
|
|
106
121
|
if (inputParams?.body) {
|
|
@@ -113,10 +128,12 @@ export class DynamoNTS_ApiService {
|
|
|
113
128
|
a = res.data;
|
|
114
129
|
}
|
|
115
130
|
|
|
116
|
-
if (dynamoNTS_globalSettings.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
131
|
+
if (dynamoNTS_globalSettings.logApiEvents) {
|
|
132
|
+
if (dynamoNTS_globalSettings.logApiResponseContents) {
|
|
133
|
+
Dynamo_Log.success(`${callParams.name} was successful`, res.data);
|
|
134
|
+
} else {
|
|
135
|
+
Dynamo_Log.success(`${callParams.name} was successful`);
|
|
136
|
+
}
|
|
120
137
|
}
|
|
121
138
|
});
|
|
122
139
|
break;
|
|
@@ -129,10 +146,12 @@ export class DynamoNTS_ApiService {
|
|
|
129
146
|
a = res;
|
|
130
147
|
}
|
|
131
148
|
|
|
132
|
-
if (dynamoNTS_globalSettings.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
149
|
+
if (dynamoNTS_globalSettings.logApiEvents) {
|
|
150
|
+
if (dynamoNTS_globalSettings.logApiResponseContents) {
|
|
151
|
+
Dynamo_Log.success(`${callParams.name} was successful`, res.data);
|
|
152
|
+
} else {
|
|
153
|
+
Dynamo_Log.success(`${callParams.name} was successful`);
|
|
154
|
+
}
|
|
136
155
|
}
|
|
137
156
|
});
|
|
138
157
|
break;
|
|
@@ -152,10 +171,12 @@ export class DynamoNTS_ApiService {
|
|
|
152
171
|
a = res.data;
|
|
153
172
|
}
|
|
154
173
|
|
|
155
|
-
if (dynamoNTS_globalSettings.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
174
|
+
if (dynamoNTS_globalSettings.logApiEvents) {
|
|
175
|
+
if (dynamoNTS_globalSettings.logApiResponseContents) {
|
|
176
|
+
Dynamo_Log.success(`> ${callParams.name} api call was successful`, res.data);
|
|
177
|
+
} else {
|
|
178
|
+
Dynamo_Log.success(`> ${callParams.name} api call was successful`);
|
|
179
|
+
}
|
|
159
180
|
}
|
|
160
181
|
});
|
|
161
182
|
break;
|
|
@@ -170,8 +191,11 @@ export class DynamoNTS_ApiService {
|
|
|
170
191
|
return a as T;
|
|
171
192
|
}
|
|
172
193
|
} catch (error) {
|
|
173
|
-
Dynamo_Log.error(
|
|
174
|
-
|
|
194
|
+
Dynamo_Log.error(
|
|
195
|
+
`\n> API ERROR: ${callParams?.name} failed...` +
|
|
196
|
+
`\n${callParams?.baseUrl}${callParams?.endPoint}` +
|
|
197
|
+
`\ncallParams:`, callParams
|
|
198
|
+
);
|
|
175
199
|
|
|
176
200
|
if (callParams?.httpOptions?.responseType === DynamoNTS_HttpResponseType.text) {
|
|
177
201
|
error.error = JSON.parse(error.error);
|
|
@@ -37,8 +37,10 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
37
37
|
dbServiceCollection: DynamoNTS_ServiceCollection<DynamoNTS_DBService<any>>; // DynamoNTS_DBServiceCollection;
|
|
38
38
|
emailServiceCollection: DynamoNTS_ServiceCollection<DynamoNTS_EmailService>; // DynamoNTS_EmailServiceCollection;
|
|
39
39
|
|
|
40
|
-
private static _globalErrorHandler?: (err: any, req
|
|
41
|
-
static get globalErrorHandler(): (err: any, req
|
|
40
|
+
private static _globalErrorHandler?: (err: any, req?: Request, res?: Response, issuer?: string) => Promise<void>;
|
|
41
|
+
static get globalErrorHandler(): (err: any, req?: Request, res?: Response, issuer?: string) => Promise<void> {
|
|
42
|
+
return this._globalErrorHandler;
|
|
43
|
+
}
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
46
|
* You need to setup global Services through this function
|
|
@@ -166,7 +166,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
166
166
|
console.log(this.params.title);
|
|
167
167
|
console.log(`Version: ${this.params.version}`);
|
|
168
168
|
}
|
|
169
|
-
Dynamo_Log.
|
|
169
|
+
Dynamo_Log.H_success(`${this.params.name} started successfully.`);
|
|
170
170
|
|
|
171
171
|
} catch (error) {
|
|
172
172
|
Dynamo_Log.error(`\nExtended Application: ${this.params?.name} start failed.\n`, error, '\n');
|
|
@@ -300,7 +300,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
300
300
|
this.systemControlsExt.httpSocketServer.init = false;
|
|
301
301
|
this.systemControlsExt.httpsSocketServer.init = false;
|
|
302
302
|
|
|
303
|
-
Dynamo_Log.
|
|
303
|
+
Dynamo_Log.H_info(`${this.params.name} stopped successfully.`);
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
|
|
@@ -223,6 +223,26 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
223
223
|
|
|
224
224
|
constructor(extended?: boolean){
|
|
225
225
|
super();
|
|
226
|
+
|
|
227
|
+
process.on('unhandledRejection', (reason: object, p: any) => {
|
|
228
|
+
Dynamo_Log.highlightedError(
|
|
229
|
+
'Unhandled Rejection at: ', p,
|
|
230
|
+
'\nRejection reason:', reason
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
DynamoNTS_GlobalService.globalErrorHandler?.(
|
|
235
|
+
new Dynamo_Error({
|
|
236
|
+
errorCode: 'NTS-AS0-BASE-UR',
|
|
237
|
+
message: 'Unhandled Rejection!',
|
|
238
|
+
error: new Error(p),
|
|
239
|
+
})
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
} catch (error) {
|
|
243
|
+
Dynamo_Log.error('getGlobalErrorHandler ERROR:', error);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
226
246
|
|
|
227
247
|
this.asyncConstruct(extended).catch((error: any) => {
|
|
228
248
|
Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
|
|
@@ -234,11 +254,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
234
254
|
try {
|
|
235
255
|
this.systemControls.app.init = true;
|
|
236
256
|
this._params = this.getAppParams();
|
|
237
|
-
|
|
257
|
+
|
|
258
|
+
dynamo_error_default.issuerSystem = this._params.systemName;
|
|
238
259
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
260
|
+
this.overrideDynamoNTSGlobalSettings?.();
|
|
261
|
+
|
|
242
262
|
this.logSetup = dynamoNTS_globalSettings.logSetup;
|
|
243
263
|
|
|
244
264
|
this.globalService = DynamoNTS_GlobalService.getInstance();
|
|
@@ -258,9 +278,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
258
278
|
this._routingModules = this.getRoutingModules();
|
|
259
279
|
}
|
|
260
280
|
|
|
261
|
-
|
|
262
|
-
await this.createEntries();
|
|
263
|
-
}
|
|
281
|
+
await this.createEntries?.();
|
|
264
282
|
|
|
265
283
|
console.log(`\n\n\nStarting ${this._params.name}... `);
|
|
266
284
|
|
|
@@ -288,9 +306,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
288
306
|
this._rootServices = await this.getRootServices();
|
|
289
307
|
}
|
|
290
308
|
|
|
291
|
-
|
|
292
|
-
await this.postProcess();
|
|
293
|
-
}
|
|
309
|
+
await this.postProcess?.();
|
|
294
310
|
|
|
295
311
|
|
|
296
312
|
if (!extended) {
|
|
@@ -300,7 +316,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
300
316
|
console.log(this.params.title);
|
|
301
317
|
console.log(`Version: ${this.params.version}`);
|
|
302
318
|
}
|
|
303
|
-
Dynamo_Log.
|
|
319
|
+
Dynamo_Log.H_success(`${this.params.name} started successfully.`);
|
|
304
320
|
}
|
|
305
321
|
} catch (error) {
|
|
306
322
|
this.constructErrors.push(error);
|
|
@@ -455,7 +471,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
455
471
|
}
|
|
456
472
|
|
|
457
473
|
if (!dontLog) {
|
|
458
|
-
Dynamo_Log.
|
|
474
|
+
Dynamo_Log.H_log(`${this._params.name} stopped successfully.`);
|
|
459
475
|
}
|
|
460
476
|
}
|
|
461
477
|
}
|
|
@@ -885,6 +901,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
885
901
|
|
|
886
902
|
/**
|
|
887
903
|
* MISSING Description (TODO)
|
|
904
|
+
* only implemented for endpoints and global Unhandled Rejection
|
|
888
905
|
*/
|
|
889
|
-
getGlobalErrorHandler?(): (err: any, req
|
|
906
|
+
getGlobalErrorHandler?(): (err: any, req?: Request, res?: Response, issuer?: string) => Promise<void>;
|
|
890
907
|
}
|