@futdevpro/nts-dynamo 1.10.10 → 1.10.12
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/build/_collections/global-settings.const.d.ts.map +1 -1
- package/build/_collections/global-settings.const.js +1 -0
- package/build/_collections/global-settings.const.js.map +1 -1
- package/build/_models/control-models/api-call-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/api-call-params.control-model.js +1 -2
- package/build/_models/control-models/api-call-params.control-model.js.map +1 -1
- package/build/_models/control-models/app-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/app-params.control-model.js +6 -1
- package/build/_models/control-models/app-params.control-model.js.map +1 -1
- package/build/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/endpoint-params.control-model.js +1 -2
- package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/build/_models/interfaces/global-settings.interface.d.ts +4 -0
- package/build/_models/interfaces/global-settings.interface.d.ts.map +1 -1
- package/build/_modules/mock/data-model.mock.spec.js +2 -2
- package/build/_modules/mock/data-model.mock.spec.js.map +1 -1
- package/build/_modules/server/error/error.controller.d.ts +36 -0
- package/build/_modules/server/error/error.controller.d.ts.map +1 -0
- package/build/_modules/server/error/error.controller.js +178 -0
- package/build/_modules/server/error/error.controller.js.map +1 -0
- package/build/_modules/server/error/error.data-service.d.ts +13 -0
- package/build/_modules/server/error/error.data-service.d.ts.map +1 -0
- package/build/_modules/server/error/error.data-service.js +249 -0
- package/build/_modules/server/error/error.data-service.js.map +1 -0
- package/build/_modules/server/index.d.ts +5 -0
- package/build/_modules/server/index.d.ts.map +1 -0
- package/build/_modules/server/index.js +10 -0
- package/build/_modules/server/index.js.map +1 -0
- package/build/_modules/server/server-status/server-status.control-service.d.ts +24 -0
- package/build/_modules/server/server-status/server-status.control-service.d.ts.map +1 -0
- package/build/_modules/server/server-status/server-status.control-service.js +102 -0
- package/build/_modules/server/server-status/server-status.control-service.js.map +1 -0
- package/build/_modules/server/server-status/server-status.controller.d.ts +23 -0
- package/build/_modules/server/server-status/server-status.controller.d.ts.map +1 -0
- package/build/_modules/server/server-status/server-status.controller.js +74 -0
- package/build/_modules/server/server-status/server-status.controller.js.map +1 -0
- package/build/_modules/socket/_services/socket-server.service.d.ts.map +1 -1
- package/build/_modules/socket/_services/socket-server.service.js.map +1 -1
- package/build/_modules/socket/index.d.ts +1 -0
- package/build/_modules/socket/index.d.ts.map +1 -1
- package/build/_modules/socket/index.js +1 -0
- package/build/_modules/socket/index.js.map +1 -1
- package/build/_services/base/data.service.d.ts +1 -0
- package/build/_services/base/data.service.d.ts.map +1 -1
- package/build/_services/base/data.service.js +15 -0
- package/build/_services/base/data.service.js.map +1 -1
- package/build/_services/base/db.service.d.ts +1 -0
- package/build/_services/base/db.service.d.ts.map +1 -1
- package/build/_services/base/db.service.js +13 -0
- package/build/_services/base/db.service.js.map +1 -1
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +8 -2
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +6 -1
- package/build/_services/server/app.server.js.map +1 -1
- package/build/index.d.ts +0 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +0 -1
- package/build/index.js.map +1 -1
- package/nodemon.json +2 -0
- package/package.json +11 -4
- package/src/_collections/global-settings.const.ts +1 -0
- package/src/_models/control-models/api-call-params.control-model.ts +2 -3
- package/src/_models/control-models/app-params.control-model.ts +9 -1
- package/src/_models/control-models/endpoint-params.control-model.ts +3 -3
- package/src/_models/interfaces/global-settings.interface.ts +5 -0
- package/src/_modules/mock/data-model.mock.spec.ts +2 -2
- package/src/_modules/server/error/error.controller.ts +233 -0
- package/src/_modules/server/error/error.data-service.ts +337 -0
- package/src/_modules/server/index.ts +11 -0
- package/src/_modules/server/server-status/server-status.control-service.ts +217 -0
- package/src/_modules/server/server-status/server-status.controller.ts +105 -0
- package/src/_modules/socket/_services/socket-server.service.ts +0 -1
- package/src/_modules/socket/index.ts +1 -1
- package/src/_services/base/data.service.ts +18 -0
- package/src/_services/base/db.service.ts +19 -0
- package/src/_services/core/global.service.ts +12 -5
- package/src/_services/server/app.server.ts +8 -4
- package/src/index.ts +0 -1
- package/tsconfig.json +1 -1
- package/build/_collections/stack.util.d.ts +0 -7
- package/build/_collections/stack.util.d.ts.map +0 -1
- package/build/_collections/stack.util.js +0 -31
- package/build/_collections/stack.util.js.map +0 -1
- package/build/_collections/stack.util.test.d.ts +0 -2
- package/build/_collections/stack.util.test.d.ts.map +0 -1
- package/build/_collections/stack.util.test.js +0 -96
- package/build/_collections/stack.util.test.js.map +0 -1
- package/src/_collections/stack.util.test.ts +0 -111
- package/src/_collections/stack.util.ts +0 -33
|
@@ -268,6 +268,24 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
async getDataListByIds(ids: string[], dontSetToService?: boolean): Promise<T[]> {
|
|
272
|
+
try {
|
|
273
|
+
const dataList: T[] = await this.dataDBService.getDataListByIds(ids);
|
|
274
|
+
|
|
275
|
+
if (!dontSetToService) {
|
|
276
|
+
this.dataList = dataList;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return dataList;
|
|
280
|
+
} catch (error) {
|
|
281
|
+
throw new DyFM_Error({
|
|
282
|
+
...this._getDefaultErrorSettings('getDataListByIds', error),
|
|
283
|
+
|
|
284
|
+
errorCode: 'NTS-DS0-GIL0',
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
271
289
|
private getDependencyIdsFilter(
|
|
272
290
|
dependencyIds?: string | { [key: string]: string }
|
|
273
291
|
): { [key: string]: string } {
|
|
@@ -240,6 +240,25 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
|
240
240
|
return this.stringifyDataId(data, 'getDataByDependencyId');
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
async getDataListByIds(ids: string[]): Promise<T[]> {
|
|
244
|
+
const dataList: T[] = await this.dataModel
|
|
245
|
+
.find({ _id: { $in: ids } })
|
|
246
|
+
.then((res): T[] => res as T[] ?? [])
|
|
247
|
+
.catch((error): void => {
|
|
248
|
+
throw new DyFM_Error({
|
|
249
|
+
...this._getDefaultErrorSettings('getDataListByIds', error),
|
|
250
|
+
errorCode: 'NTS-DBS-GDL0',
|
|
251
|
+
additionalContent: { ids },
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
return dataList.filter(
|
|
256
|
+
(data: T): boolean => !data._deleted
|
|
257
|
+
).map(
|
|
258
|
+
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyId')
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
243
262
|
/**
|
|
244
263
|
* get data by dependency data id,
|
|
245
264
|
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLD2)
|
|
@@ -235,11 +235,18 @@ export class DyNTS_GlobalService extends DyNTS_SingletonService {
|
|
|
235
235
|
);
|
|
236
236
|
}
|
|
237
237
|
} catch (error) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
238
|
+
if (error instanceof DyFM_Error) {
|
|
239
|
+
error.logSimple(
|
|
240
|
+
`NTS GLOBAL MULTILEVEL ERROR: ` +
|
|
241
|
+
`\nFailed to handle error on globalErrorHandler.`,
|
|
242
|
+
);
|
|
243
|
+
} else {
|
|
244
|
+
DyFM_Log.error(
|
|
245
|
+
`NTS GLOBAL MULTILEVEL ERROR: ` +
|
|
246
|
+
`\nFailed to handle error on globalErrorHandler.`,
|
|
247
|
+
(error as DyFM_Error)?.getErrorSimplified?.() ?? error
|
|
248
|
+
);
|
|
249
|
+
}
|
|
243
250
|
}
|
|
244
251
|
});
|
|
245
252
|
} catch (error) {
|
|
@@ -310,10 +310,14 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
310
310
|
if (error instanceof DyFM_Error) {
|
|
311
311
|
if (error.additionalContent?.constructErrors?.length) {
|
|
312
312
|
error.additionalContent.constructErrors.forEach((errorItem: DyFM_Error): void => {
|
|
313
|
-
errorItem
|
|
314
|
-
`(constructor asyncConstruct.catch)
|
|
315
|
-
|
|
316
|
-
|
|
313
|
+
if (errorItem instanceof DyFM_Error) {
|
|
314
|
+
errorItem.logSimple(`(constructor asyncConstruct.catch) error:\n`);
|
|
315
|
+
} else {
|
|
316
|
+
DyFM_Log.H_warn(
|
|
317
|
+
'(constructor asyncConstruct.catch) additional error content:\n',
|
|
318
|
+
errorItem
|
|
319
|
+
);
|
|
320
|
+
}
|
|
317
321
|
});
|
|
318
322
|
} else {
|
|
319
323
|
DyFM_Log.H_warn(
|
package/src/index.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the stack location of the constructor call
|
|
3
|
-
* use it in the constructor of a class to get the stack location of the constructor call
|
|
4
|
-
* @returns The stack location of the constructor call
|
|
5
|
-
*/
|
|
6
|
-
export declare function DyNTS_getStackLocation(): string;
|
|
7
|
-
//# sourceMappingURL=stack.util.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stack.util.d.ts","sourceRoot":"","sources":["../../src/_collections/stack.util.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAyB/C"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DyNTS_getStackLocation = void 0;
|
|
4
|
-
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
5
|
-
/**
|
|
6
|
-
* Get the stack location of the constructor call
|
|
7
|
-
* use it in the constructor of a class to get the stack location of the constructor call
|
|
8
|
-
* @returns The stack location of the constructor call
|
|
9
|
-
*/
|
|
10
|
-
function DyNTS_getStackLocation() {
|
|
11
|
-
let stack = new Error().stack;
|
|
12
|
-
// Split the stack into lines and remove the first line (Error:)
|
|
13
|
-
const stackLines = stack?.split('\n')?.slice(1);
|
|
14
|
-
// Find the line that contains the constructor call
|
|
15
|
-
// It will be the FIRST line that doesn't contain 'getStackLocation'
|
|
16
|
-
let constructorLine = stackLines?.find(line => !line.includes('getStackLocation') &&
|
|
17
|
-
!line.includes('at new'));
|
|
18
|
-
if (!constructorLine) {
|
|
19
|
-
fsm_dynamo_1.DyFM_Log.warn('No constructor line found');
|
|
20
|
-
return '';
|
|
21
|
-
}
|
|
22
|
-
// Remove the 'constructorLine at ... (' and the ')'
|
|
23
|
-
constructorLine = constructorLine.split('(')[1]?.split(')')[0];
|
|
24
|
-
if (!constructorLine) {
|
|
25
|
-
fsm_dynamo_1.DyFM_Log.warn('No constructor line found');
|
|
26
|
-
return '';
|
|
27
|
-
}
|
|
28
|
-
return constructorLine;
|
|
29
|
-
}
|
|
30
|
-
exports.DyNTS_getStackLocation = DyNTS_getStackLocation;
|
|
31
|
-
//# sourceMappingURL=stack.util.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stack.util.js","sourceRoot":"","sources":["../../src/_collections/stack.util.ts"],"names":[],"mappings":";;;AAAA,sDAAiD;AAEjD;;;;GAIG;AACH,SAAgB,sBAAsB;IACpC,IAAI,KAAK,GAAW,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC;IAEtC,gEAAgE;IAChE,MAAM,UAAU,GAAG,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAEhD,mDAAmD;IACnD,oEAAoE;IACpE,IAAI,eAAe,GAAG,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAC5C,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC;QAClC,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACzB,CAAC;IACF,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,qBAAQ,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC3C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,wDAAwD;IACxD,eAAe,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,qBAAQ,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC3C,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAzBD,wDAyBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stack.util.test.d.ts","sourceRoot":"","sources":["../../src/_collections/stack.util.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const stack_util_1 = require("./stack.util");
|
|
4
|
-
describe('stack.util.ts', () => {
|
|
5
|
-
describe('DyNTS_getStackLocation', () => {
|
|
6
|
-
// Test class for basic functionality
|
|
7
|
-
class TestClass {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.location = (0, stack_util_1.DyNTS_getStackLocation)();
|
|
10
|
-
}
|
|
11
|
-
location;
|
|
12
|
-
}
|
|
13
|
-
// Test class for nested instantiation
|
|
14
|
-
class NestedTestClass {
|
|
15
|
-
constructor() {
|
|
16
|
-
this.location = (0, stack_util_1.DyNTS_getStackLocation)();
|
|
17
|
-
}
|
|
18
|
-
location;
|
|
19
|
-
}
|
|
20
|
-
// Test class with parameters
|
|
21
|
-
class ParamTestClass {
|
|
22
|
-
constructor(param) {
|
|
23
|
-
this.location = (0, stack_util_1.DyNTS_getStackLocation)();
|
|
24
|
-
}
|
|
25
|
-
location;
|
|
26
|
-
}
|
|
27
|
-
// Test class for async instantiation
|
|
28
|
-
class AsyncTestClass {
|
|
29
|
-
constructor() {
|
|
30
|
-
this.location = (0, stack_util_1.DyNTS_getStackLocation)();
|
|
31
|
-
}
|
|
32
|
-
location;
|
|
33
|
-
}
|
|
34
|
-
describe('format validation', () => {
|
|
35
|
-
it('should return location in correct file:line:column format', () => {
|
|
36
|
-
const instance = new TestClass();
|
|
37
|
-
const [file, line, column] = instance.location.split(':');
|
|
38
|
-
expect(file).toBeTruthy();
|
|
39
|
-
expect(parseInt(line)).toBeGreaterThan(0);
|
|
40
|
-
expect(parseInt(column)).toBeGreaterThan(0);
|
|
41
|
-
expect(instance.location).toMatch(/^[^:]+:\d+:\d+$/);
|
|
42
|
-
});
|
|
43
|
-
it('should include the correct file path', () => {
|
|
44
|
-
const instance = new TestClass();
|
|
45
|
-
expect(instance.location).toContain('stack.util.test.ts');
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe('location uniqueness', () => {
|
|
49
|
-
it('should return different locations for different instantiation points', () => {
|
|
50
|
-
const instance1 = new TestClass();
|
|
51
|
-
const instance2 = new TestClass();
|
|
52
|
-
expect(instance1.location).not.toBe(instance2.location);
|
|
53
|
-
});
|
|
54
|
-
it('should return different locations for different classes', () => {
|
|
55
|
-
const instance1 = new TestClass();
|
|
56
|
-
const instance2 = new NestedTestClass();
|
|
57
|
-
expect(instance1.location).not.toBe(instance2.location);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe('class instantiation variations', () => {
|
|
61
|
-
it('should work with nested class instantiation', () => {
|
|
62
|
-
const instance = new NestedTestClass();
|
|
63
|
-
expect(instance.location).toContain('NestedTestClass');
|
|
64
|
-
});
|
|
65
|
-
it('should handle class instantiation with parameters', () => {
|
|
66
|
-
const instance = new ParamTestClass('test');
|
|
67
|
-
expect(instance.location).toMatch(/^[^:]+:\d+:\d+$/);
|
|
68
|
-
});
|
|
69
|
-
it('should work with async class instantiation', async () => {
|
|
70
|
-
const instance = new AsyncTestClass();
|
|
71
|
-
expect(instance.location).toMatch(/^[^:]+:\d+:\d+$/);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
describe('error handling', () => {
|
|
75
|
-
it('should handle invalid stack trace gracefully', () => {
|
|
76
|
-
// Mock Error.stack to be undefined
|
|
77
|
-
const originalStack = Error.prototype.stack;
|
|
78
|
-
Error.prototype.stack = undefined;
|
|
79
|
-
const instance = new TestClass();
|
|
80
|
-
expect(instance.location).toBe('');
|
|
81
|
-
// Restore original stack
|
|
82
|
-
Error.prototype.stack = originalStack;
|
|
83
|
-
});
|
|
84
|
-
it('should handle malformed stack trace gracefully', () => {
|
|
85
|
-
// Mock Error.stack to be malformed
|
|
86
|
-
const originalStack = Error.prototype.stack;
|
|
87
|
-
Error.prototype.stack = 'Invalid stack trace';
|
|
88
|
-
const instance = new TestClass();
|
|
89
|
-
expect(instance.location).toBe('');
|
|
90
|
-
// Restore original stack
|
|
91
|
-
Error.prototype.stack = originalStack;
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
//# sourceMappingURL=stack.util.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stack.util.test.js","sourceRoot":"","sources":["../../src/_collections/stack.util.test.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AAEtD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,qCAAqC;QACrC,MAAM,SAAS;YACb;gBACE,IAAI,CAAC,QAAQ,GAAG,IAAA,mCAAsB,GAAE,CAAC;YAC3C,CAAC;YACD,QAAQ,CAAS;SAClB;QAED,sCAAsC;QACtC,MAAM,eAAe;YACnB;gBACE,IAAI,CAAC,QAAQ,GAAG,IAAA,mCAAsB,GAAE,CAAC;YAC3C,CAAC;YACD,QAAQ,CAAS;SAClB;QAED,6BAA6B;QAC7B,MAAM,cAAc;YAClB,Y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E,GAAG,EAAE;gBACtD,mCAAmC;gBACnC,MAAM,aAAa,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;gBAC5C,KAAK,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC;gBAElC,MAAM,QAAQ,GAAG,IAAI,SAAS,EAAE,CAAC;gBACjC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAEnC,yBAAyB;gBACzB,KAAK,CAAC,SAAS,CAAC,KAAK,GAAG,aAAa,CAAC;YACxC,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;gBACxD,mCAAmC;gBACnC,MAAM,aAAa,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC;gBAC5C,KAAK,CAAC,SAAS,CAAC,KAAK,GAAG,qBAAqB,CAAC;gBAE9C,MAAM,QAAQ,GAAG,IAAI,SAAS,EAAE,CAAC;gBACjC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAEnC,yBAAyB;gBACzB,KAAK,CAAC,SAAS,CAAC,KAAK,GAAG,aAAa,CAAC;YACxC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { DyNTS_getStackLocation } from './stack.util';
|
|
2
|
-
|
|
3
|
-
describe('stack.util.ts', () => {
|
|
4
|
-
describe('DyNTS_getStackLocation', () => {
|
|
5
|
-
// Test class for basic functionality
|
|
6
|
-
class TestClass {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.location = DyNTS_getStackLocation();
|
|
9
|
-
}
|
|
10
|
-
location: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Test class for nested instantiation
|
|
14
|
-
class NestedTestClass {
|
|
15
|
-
constructor() {
|
|
16
|
-
this.location = DyNTS_getStackLocation();
|
|
17
|
-
}
|
|
18
|
-
location: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Test class with parameters
|
|
22
|
-
class ParamTestClass {
|
|
23
|
-
constructor(param: string) {
|
|
24
|
-
this.location = DyNTS_getStackLocation();
|
|
25
|
-
}
|
|
26
|
-
location: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Test class for async instantiation
|
|
30
|
-
class AsyncTestClass {
|
|
31
|
-
constructor() {
|
|
32
|
-
this.location = DyNTS_getStackLocation();
|
|
33
|
-
}
|
|
34
|
-
location: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe('format validation', () => {
|
|
38
|
-
it('should return location in correct file:line:column format', () => {
|
|
39
|
-
const instance = new TestClass();
|
|
40
|
-
const [file, line, column] = instance.location.split(':');
|
|
41
|
-
|
|
42
|
-
expect(file).toBeTruthy();
|
|
43
|
-
expect(parseInt(line)).toBeGreaterThan(0);
|
|
44
|
-
expect(parseInt(column)).toBeGreaterThan(0);
|
|
45
|
-
expect(instance.location).toMatch(/^[^:]+:\d+:\d+$/);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should include the correct file path', () => {
|
|
49
|
-
const instance = new TestClass();
|
|
50
|
-
expect(instance.location).toContain('stack.util.test.ts');
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('location uniqueness', () => {
|
|
55
|
-
it('should return different locations for different instantiation points', () => {
|
|
56
|
-
const instance1 = new TestClass();
|
|
57
|
-
const instance2 = new TestClass();
|
|
58
|
-
expect(instance1.location).not.toBe(instance2.location);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should return different locations for different classes', () => {
|
|
62
|
-
const instance1 = new TestClass();
|
|
63
|
-
const instance2 = new NestedTestClass();
|
|
64
|
-
expect(instance1.location).not.toBe(instance2.location);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('class instantiation variations', () => {
|
|
69
|
-
it('should work with nested class instantiation', () => {
|
|
70
|
-
const instance = new NestedTestClass();
|
|
71
|
-
expect(instance.location).toContain('NestedTestClass');
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should handle class instantiation with parameters', () => {
|
|
75
|
-
const instance = new ParamTestClass('test');
|
|
76
|
-
expect(instance.location).toMatch(/^[^:]+:\d+:\d+$/);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should work with async class instantiation', async () => {
|
|
80
|
-
const instance = new AsyncTestClass();
|
|
81
|
-
expect(instance.location).toMatch(/^[^:]+:\d+:\d+$/);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('error handling', () => {
|
|
86
|
-
it('should handle invalid stack trace gracefully', () => {
|
|
87
|
-
// Mock Error.stack to be undefined
|
|
88
|
-
const originalStack = Error.prototype.stack;
|
|
89
|
-
Error.prototype.stack = undefined;
|
|
90
|
-
|
|
91
|
-
const instance = new TestClass();
|
|
92
|
-
expect(instance.location).toBe('');
|
|
93
|
-
|
|
94
|
-
// Restore original stack
|
|
95
|
-
Error.prototype.stack = originalStack;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should handle malformed stack trace gracefully', () => {
|
|
99
|
-
// Mock Error.stack to be malformed
|
|
100
|
-
const originalStack = Error.prototype.stack;
|
|
101
|
-
Error.prototype.stack = 'Invalid stack trace';
|
|
102
|
-
|
|
103
|
-
const instance = new TestClass();
|
|
104
|
-
expect(instance.location).toBe('');
|
|
105
|
-
|
|
106
|
-
// Restore original stack
|
|
107
|
-
Error.prototype.stack = originalStack;
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { DyFM_Log } from '@futdevpro/fsm-dynamo';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Get the stack location of the constructor call
|
|
5
|
-
* use it in the constructor of a class to get the stack location of the constructor call
|
|
6
|
-
* @returns The stack location of the constructor call
|
|
7
|
-
*/
|
|
8
|
-
export function DyNTS_getStackLocation(): string {
|
|
9
|
-
let stack: string = new Error().stack;
|
|
10
|
-
|
|
11
|
-
// Split the stack into lines and remove the first line (Error:)
|
|
12
|
-
const stackLines = stack?.split('\n')?.slice(1);
|
|
13
|
-
|
|
14
|
-
// Find the line that contains the constructor call
|
|
15
|
-
// It will be the FIRST line that doesn't contain 'getStackLocation'
|
|
16
|
-
let constructorLine = stackLines?.find(line =>
|
|
17
|
-
!line.includes('getStackLocation') &&
|
|
18
|
-
!line.includes('at new')
|
|
19
|
-
);
|
|
20
|
-
if (!constructorLine) {
|
|
21
|
-
DyFM_Log.warn('No constructor line found');
|
|
22
|
-
return '';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Remove the 'constructorLine at ... (' and the ')'
|
|
26
|
-
constructorLine = constructorLine.split('(')[1]?.split(')')[0];
|
|
27
|
-
if (!constructorLine) {
|
|
28
|
-
DyFM_Log.warn('No constructor line found');
|
|
29
|
-
return '';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return constructorLine;
|
|
33
|
-
}
|