@hg-ts/exception 0.0.15

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.
Files changed (155) hide show
  1. package/.eslintcache +1 -0
  2. package/.eslintrc.json +1 -0
  3. package/.mocharc.cjs +1 -0
  4. package/README.md +1 -0
  5. package/dist/consts.d.ts +2 -0
  6. package/dist/consts.d.ts.map +1 -0
  7. package/dist/consts.js +5 -0
  8. package/dist/consts.js.map +1 -0
  9. package/dist/exceptions/aggregate-error.exception.d.ts +5 -0
  10. package/dist/exceptions/aggregate-error.exception.d.ts.map +1 -0
  11. package/dist/exceptions/aggregate-error.exception.js +24 -0
  12. package/dist/exceptions/aggregate-error.exception.js.map +1 -0
  13. package/dist/exceptions/base.aggregate.exception.d.ts +13 -0
  14. package/dist/exceptions/base.aggregate.exception.d.ts.map +1 -0
  15. package/dist/exceptions/base.aggregate.exception.js +33 -0
  16. package/dist/exceptions/base.aggregate.exception.js.map +1 -0
  17. package/dist/exceptions/base.exception.d.ts +36 -0
  18. package/dist/exceptions/base.exception.d.ts.map +1 -0
  19. package/dist/exceptions/base.exception.js +96 -0
  20. package/dist/exceptions/base.exception.js.map +1 -0
  21. package/dist/exceptions/error.exception.d.ts +5 -0
  22. package/dist/exceptions/error.exception.d.ts.map +1 -0
  23. package/dist/exceptions/error.exception.js +17 -0
  24. package/dist/exceptions/error.exception.js.map +1 -0
  25. package/dist/exceptions/forbidden.exception.d.ts +4 -0
  26. package/dist/exceptions/forbidden.exception.d.ts.map +1 -0
  27. package/dist/exceptions/forbidden.exception.js +8 -0
  28. package/dist/exceptions/forbidden.exception.js.map +1 -0
  29. package/dist/exceptions/index.d.ts +9 -0
  30. package/dist/exceptions/index.d.ts.map +1 -0
  31. package/dist/exceptions/index.js +12 -0
  32. package/dist/exceptions/index.js.map +1 -0
  33. package/dist/exceptions/not-implemented.exception.d.ts +5 -0
  34. package/dist/exceptions/not-implemented.exception.d.ts.map +1 -0
  35. package/dist/exceptions/not-implemented.exception.js +11 -0
  36. package/dist/exceptions/not-implemented.exception.js.map +1 -0
  37. package/dist/exceptions/unknown.exception.d.ts +5 -0
  38. package/dist/exceptions/unknown.exception.d.ts.map +1 -0
  39. package/dist/exceptions/unknown.exception.js +11 -0
  40. package/dist/exceptions/unknown.exception.js.map +1 -0
  41. package/dist/exceptions/will-never-happened.exception.d.ts +5 -0
  42. package/dist/exceptions/will-never-happened.exception.d.ts.map +1 -0
  43. package/dist/exceptions/will-never-happened.exception.js +11 -0
  44. package/dist/exceptions/will-never-happened.exception.js.map +1 -0
  45. package/dist/index.d.ts +3 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +6 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/tests/serialization.test-suite.d.ts +13 -0
  50. package/dist/tests/serialization.test-suite.d.ts.map +1 -0
  51. package/dist/tests/serialization.test-suite.js +142 -0
  52. package/dist/tests/serialization.test-suite.js.map +1 -0
  53. package/dist/tests/test.aggregate-exception.d.ts +5 -0
  54. package/dist/tests/test.aggregate-exception.d.ts.map +1 -0
  55. package/dist/tests/test.aggregate-exception.js +16 -0
  56. package/dist/tests/test.aggregate-exception.js.map +1 -0
  57. package/dist/tests/test.d.ts +6 -0
  58. package/dist/tests/test.d.ts.map +1 -0
  59. package/dist/tests/test.exception.d.ts +5 -0
  60. package/dist/tests/test.exception.d.ts.map +1 -0
  61. package/dist/tests/test.exception.js +11 -0
  62. package/dist/tests/test.exception.js.map +1 -0
  63. package/dist/tests/test.js +22 -0
  64. package/dist/tests/test.js.map +1 -0
  65. package/dist/utils/index.d.ts +2 -0
  66. package/dist/utils/index.d.ts.map +1 -0
  67. package/dist/utils/index.js +5 -0
  68. package/dist/utils/index.js.map +1 -0
  69. package/dist/utils/stack-trace.formatter.d.ts +6 -0
  70. package/dist/utils/stack-trace.formatter.d.ts.map +1 -0
  71. package/dist/utils/stack-trace.formatter.js +30 -0
  72. package/dist/utils/stack-trace.formatter.js.map +1 -0
  73. package/dist-esm/consts.d.ts +2 -0
  74. package/dist-esm/consts.d.ts.map +1 -0
  75. package/dist-esm/consts.js +2 -0
  76. package/dist-esm/consts.js.map +1 -0
  77. package/dist-esm/exceptions/aggregate-error.exception.d.ts +5 -0
  78. package/dist-esm/exceptions/aggregate-error.exception.d.ts.map +1 -0
  79. package/dist-esm/exceptions/aggregate-error.exception.js +20 -0
  80. package/dist-esm/exceptions/aggregate-error.exception.js.map +1 -0
  81. package/dist-esm/exceptions/base.aggregate.exception.d.ts +13 -0
  82. package/dist-esm/exceptions/base.aggregate.exception.d.ts.map +1 -0
  83. package/dist-esm/exceptions/base.aggregate.exception.js +29 -0
  84. package/dist-esm/exceptions/base.aggregate.exception.js.map +1 -0
  85. package/dist-esm/exceptions/base.exception.d.ts +36 -0
  86. package/dist-esm/exceptions/base.exception.d.ts.map +1 -0
  87. package/dist-esm/exceptions/base.exception.js +91 -0
  88. package/dist-esm/exceptions/base.exception.js.map +1 -0
  89. package/dist-esm/exceptions/error.exception.d.ts +5 -0
  90. package/dist-esm/exceptions/error.exception.d.ts.map +1 -0
  91. package/dist-esm/exceptions/error.exception.js +13 -0
  92. package/dist-esm/exceptions/error.exception.js.map +1 -0
  93. package/dist-esm/exceptions/forbidden.exception.d.ts +4 -0
  94. package/dist-esm/exceptions/forbidden.exception.d.ts.map +1 -0
  95. package/dist-esm/exceptions/forbidden.exception.js +4 -0
  96. package/dist-esm/exceptions/forbidden.exception.js.map +1 -0
  97. package/dist-esm/exceptions/index.d.ts +9 -0
  98. package/dist-esm/exceptions/index.d.ts.map +1 -0
  99. package/dist-esm/exceptions/index.js +9 -0
  100. package/dist-esm/exceptions/index.js.map +1 -0
  101. package/dist-esm/exceptions/not-implemented.exception.d.ts +5 -0
  102. package/dist-esm/exceptions/not-implemented.exception.d.ts.map +1 -0
  103. package/dist-esm/exceptions/not-implemented.exception.js +7 -0
  104. package/dist-esm/exceptions/not-implemented.exception.js.map +1 -0
  105. package/dist-esm/exceptions/unknown.exception.d.ts +5 -0
  106. package/dist-esm/exceptions/unknown.exception.d.ts.map +1 -0
  107. package/dist-esm/exceptions/unknown.exception.js +7 -0
  108. package/dist-esm/exceptions/unknown.exception.js.map +1 -0
  109. package/dist-esm/exceptions/will-never-happened.exception.d.ts +5 -0
  110. package/dist-esm/exceptions/will-never-happened.exception.d.ts.map +1 -0
  111. package/dist-esm/exceptions/will-never-happened.exception.js +7 -0
  112. package/dist-esm/exceptions/will-never-happened.exception.js.map +1 -0
  113. package/dist-esm/index.d.ts +3 -0
  114. package/dist-esm/index.d.ts.map +1 -0
  115. package/dist-esm/index.js +3 -0
  116. package/dist-esm/index.js.map +1 -0
  117. package/dist-esm/tests/serialization.test-suite.d.ts +13 -0
  118. package/dist-esm/tests/serialization.test-suite.d.ts.map +1 -0
  119. package/dist-esm/tests/serialization.test-suite.js +139 -0
  120. package/dist-esm/tests/serialization.test-suite.js.map +1 -0
  121. package/dist-esm/tests/test.aggregate-exception.d.ts +5 -0
  122. package/dist-esm/tests/test.aggregate-exception.d.ts.map +1 -0
  123. package/dist-esm/tests/test.aggregate-exception.js +12 -0
  124. package/dist-esm/tests/test.aggregate-exception.js.map +1 -0
  125. package/dist-esm/tests/test.exception.d.ts +5 -0
  126. package/dist-esm/tests/test.exception.d.ts.map +1 -0
  127. package/dist-esm/tests/test.exception.js +7 -0
  128. package/dist-esm/tests/test.exception.js.map +1 -0
  129. package/dist-esm/utils/index.d.ts +2 -0
  130. package/dist-esm/utils/index.d.ts.map +1 -0
  131. package/dist-esm/utils/index.js +2 -0
  132. package/dist-esm/utils/index.js.map +1 -0
  133. package/dist-esm/utils/stack-trace.formatter.d.ts +6 -0
  134. package/dist-esm/utils/stack-trace.formatter.d.ts.map +1 -0
  135. package/dist-esm/utils/stack-trace.formatter.js +25 -0
  136. package/dist-esm/utils/stack-trace.formatter.js.map +1 -0
  137. package/package.json +37 -0
  138. package/src/consts.ts +1 -0
  139. package/src/exceptions/aggregate-error.exception.ts +26 -0
  140. package/src/exceptions/base.aggregate.exception.ts +51 -0
  141. package/src/exceptions/base.exception.ts +138 -0
  142. package/src/exceptions/error.exception.ts +16 -0
  143. package/src/exceptions/forbidden.exception.ts +3 -0
  144. package/src/exceptions/index.ts +11 -0
  145. package/src/exceptions/not-implemented.exception.ts +7 -0
  146. package/src/exceptions/unknown.exception.ts +7 -0
  147. package/src/exceptions/will-never-happened.exception.ts +7 -0
  148. package/src/index.ts +2 -0
  149. package/src/tests/serialization.test-suite.ts +121 -0
  150. package/src/tests/test.aggregate-exception.ts +16 -0
  151. package/src/tests/test.exception.ts +7 -0
  152. package/src/utils/index.ts +1 -0
  153. package/src/utils/stack-trace.formatter.ts +30 -0
  154. package/tsconfig.esm.json +9 -0
  155. package/tsconfig.json +10 -0
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SerializationTestSuite = void 0;
4
+ const tslib_1 = require("tslib");
5
+ require("@hg-ts/types");
6
+ const tests_1 = require("@hg-ts/tests");
7
+ const exceptions_1 = require("../exceptions");
8
+ const test_aggregate_exception_1 = require("./test.aggregate-exception");
9
+ const test_exception_1 = require("./test.exception");
10
+ let SerializationTestSuite = class SerializationTestSuite extends tests_1.TestSuite {
11
+ async commonTest() {
12
+ const message = 'Test message';
13
+ const exception = new test_exception_1.TestException(message);
14
+ (0, tests_1.expect)(exception).toBeInstanceOf(Error);
15
+ (0, tests_1.expect)(exception).toBeInstanceOf(exceptions_1.BaseException);
16
+ (0, tests_1.expect)(exception).toBeInstanceOf(test_exception_1.TestException);
17
+ (0, tests_1.expect)(exception.message).toEqual(message);
18
+ (0, tests_1.expect)(exception.code).toBeNull();
19
+ (0, tests_1.expect)(exception.toJSON().name).toEqual(test_exception_1.TestException.name);
20
+ (0, tests_1.expect)(exception.toJSON().stack).toBeInstanceOf(Array);
21
+ (0, tests_1.expect)(exception.toJSON().stack).not.toEqual([]);
22
+ }
23
+ async baseExceptionFromError() {
24
+ const message = 'Test message';
25
+ const error = new Error(message);
26
+ const exception = exceptions_1.BaseException.fromError(error);
27
+ (0, tests_1.expect)(exception).toBeInstanceOf(Error);
28
+ (0, tests_1.expect)(exception).toBeInstanceOf(exceptions_1.BaseException);
29
+ (0, tests_1.expect)(exception).toBeInstanceOf(exceptions_1.ErrorException);
30
+ (0, tests_1.expect)(exception.message).toEqual(message);
31
+ (0, tests_1.expect)(exception.code).toBeNull();
32
+ (0, tests_1.expect)(exception.toJSON().stack).toBeInstanceOf(Array);
33
+ (0, tests_1.expect)(exception.toJSON().stack).not.toEqual([]);
34
+ }
35
+ async aggregateExceptionTest() {
36
+ const message = 'Test aggregate message';
37
+ const exception = new test_aggregate_exception_1.TestAggregateException(message);
38
+ (0, tests_1.expect)(exception).toBeInstanceOf(Error);
39
+ (0, tests_1.expect)(exception).toBeInstanceOf(exceptions_1.BaseException);
40
+ (0, tests_1.expect)(exception).toBeInstanceOf(exceptions_1.BaseAggregateException);
41
+ (0, tests_1.expect)(exception).toBeInstanceOf(test_aggregate_exception_1.TestAggregateException);
42
+ (0, tests_1.expect)(exception.message).toEqual(message);
43
+ (0, tests_1.expect)(exception.code).toBeNull();
44
+ (0, tests_1.expect)(exception.exceptions).toBeInstanceOf(Array);
45
+ (0, tests_1.expect)(exception.exceptions).toHaveLength(3);
46
+ }
47
+ async syncStackTest() {
48
+ const { stack } = new test_exception_1.TestException('Test message').toJSON();
49
+ (0, tests_1.expect)(stack[0].startsWith('at SerializationTestSuite.syncStackTest')).toBeTruthy();
50
+ }
51
+ async isFromNextTickTest() {
52
+ return new Promise(resolve => {
53
+ process.nextTick(() => {
54
+ const exception = new test_exception_1.TestException('Test message');
55
+ (0, tests_1.expect)(exception.isFromNextTick()).toBeTruthy();
56
+ resolve();
57
+ });
58
+ });
59
+ }
60
+ async isFromImmediateTest() {
61
+ return new Promise(resolve => {
62
+ setImmediate(() => {
63
+ const exception = new test_exception_1.TestException('Test message');
64
+ (0, tests_1.expect)(exception.isFromImmediate()).toBeTruthy();
65
+ resolve();
66
+ });
67
+ });
68
+ }
69
+ async fromTimeoutTest() {
70
+ return new Promise(resolve => {
71
+ setTimeout(() => {
72
+ const exception = new test_exception_1.TestException('Test message');
73
+ (0, tests_1.expect)(exception.isFromTimer()).toBeTruthy();
74
+ resolve();
75
+ }, 0);
76
+ });
77
+ }
78
+ async fromIntervalTest() {
79
+ let interval;
80
+ return new Promise(resolve => {
81
+ interval = setInterval(() => {
82
+ const exception = new test_exception_1.TestException('Test message');
83
+ (0, tests_1.expect)(exception.isFromTimer()).toBeTruthy();
84
+ clearInterval(interval);
85
+ resolve();
86
+ }, 0);
87
+ });
88
+ }
89
+ };
90
+ tslib_1.__decorate([
91
+ (0, tests_1.Test)(),
92
+ tslib_1.__metadata("design:type", Function),
93
+ tslib_1.__metadata("design:paramtypes", []),
94
+ tslib_1.__metadata("design:returntype", Promise)
95
+ ], SerializationTestSuite.prototype, "commonTest", null);
96
+ tslib_1.__decorate([
97
+ (0, tests_1.Test)(),
98
+ tslib_1.__metadata("design:type", Function),
99
+ tslib_1.__metadata("design:paramtypes", []),
100
+ tslib_1.__metadata("design:returntype", Promise)
101
+ ], SerializationTestSuite.prototype, "baseExceptionFromError", null);
102
+ tslib_1.__decorate([
103
+ (0, tests_1.Test)(),
104
+ tslib_1.__metadata("design:type", Function),
105
+ tslib_1.__metadata("design:paramtypes", []),
106
+ tslib_1.__metadata("design:returntype", Promise)
107
+ ], SerializationTestSuite.prototype, "aggregateExceptionTest", null);
108
+ tslib_1.__decorate([
109
+ (0, tests_1.Test)(),
110
+ tslib_1.__metadata("design:type", Function),
111
+ tslib_1.__metadata("design:paramtypes", []),
112
+ tslib_1.__metadata("design:returntype", Promise)
113
+ ], SerializationTestSuite.prototype, "syncStackTest", null);
114
+ tslib_1.__decorate([
115
+ (0, tests_1.Test)(),
116
+ tslib_1.__metadata("design:type", Function),
117
+ tslib_1.__metadata("design:paramtypes", []),
118
+ tslib_1.__metadata("design:returntype", Promise)
119
+ ], SerializationTestSuite.prototype, "isFromNextTickTest", null);
120
+ tslib_1.__decorate([
121
+ (0, tests_1.Test)(),
122
+ tslib_1.__metadata("design:type", Function),
123
+ tslib_1.__metadata("design:paramtypes", []),
124
+ tslib_1.__metadata("design:returntype", Promise)
125
+ ], SerializationTestSuite.prototype, "isFromImmediateTest", null);
126
+ tslib_1.__decorate([
127
+ (0, tests_1.Test)(),
128
+ tslib_1.__metadata("design:type", Function),
129
+ tslib_1.__metadata("design:paramtypes", []),
130
+ tslib_1.__metadata("design:returntype", Promise)
131
+ ], SerializationTestSuite.prototype, "fromTimeoutTest", null);
132
+ tslib_1.__decorate([
133
+ (0, tests_1.Test)(),
134
+ tslib_1.__metadata("design:type", Function),
135
+ tslib_1.__metadata("design:paramtypes", []),
136
+ tslib_1.__metadata("design:returntype", Promise)
137
+ ], SerializationTestSuite.prototype, "fromIntervalTest", null);
138
+ SerializationTestSuite = tslib_1.__decorate([
139
+ (0, tests_1.Describe)()
140
+ ], SerializationTestSuite);
141
+ exports.SerializationTestSuite = SerializationTestSuite;
142
+ //# sourceMappingURL=serialization.test-suite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.test-suite.js","sourceRoot":"","sources":["../../src/tests/serialization.test-suite.ts"],"names":[],"mappings":";;;;AAAA,wBAAsB;AACtB,wCAKsB;AACtB,8CAIuB;AACvB,yEAAoE;AACpE,qDAAiD;AAGjD,IAAa,sBAAsB,GAAnC,MAAa,sBAAuB,SAAQ,iBAAS;IAE7C,KAAK,CAAC,UAAU;QACtB,MAAM,OAAO,GAAG,cAAc,CAAC;QAC/B,MAAM,SAAS,GAAG,IAAI,8BAAa,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAA,cAAM,EAAC,SAAS,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACxC,IAAA,cAAM,EAAC,SAAS,CAAC,CAAC,cAAc,CAAC,0BAAa,CAAC,CAAC;QAChD,IAAA,cAAM,EAAC,SAAS,CAAC,CAAC,cAAc,CAA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AE,CAAC;YACX,CAAC,EAAE,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAtGA;IADC,IAAA,YAAI,GAAE;;;;wDAaN;AAGD;IADC,IAAA,YAAI,GAAE;;;;oEAaN;AAGD;IADC,IAAA,YAAI,GAAE;;;;oEAeN;AAGD;IADC,IAAA,YAAI,GAAE;;;;2DAKN;AAGD;IADC,IAAA,YAAI,GAAE;;;;gEAUN;AAGD;IADC,IAAA,YAAI,GAAE;;;;iEAUN;AAGD;IADC,IAAA,YAAI,GAAE;;;;6DAUN;AAGD;IADC,IAAA,YAAI,GAAE;;;;8DAYN;AAvGW,sBAAsB;IADlC,IAAA,gBAAQ,GAAE;GACE,sBAAsB,CAwGlC;AAxGY,wDAAsB"}
@@ -0,0 +1,5 @@
1
+ import { BaseAggregateException } from '../exceptions';
2
+ export declare class TestAggregateException extends BaseAggregateException {
3
+ constructor(message: string, code?: number);
4
+ }
5
+ //# sourceMappingURL=test.aggregate-exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.aggregate-exception.d.ts","sourceRoot":"","sources":["../../src/tests/test.aggregate-exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAGvD,qBAAa,sBAAuB,SAAQ,sBAAsB;gBAC9C,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAWjD"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestAggregateException = void 0;
4
+ const exceptions_1 = require("../exceptions");
5
+ const test_exception_1 = require("./test.exception");
6
+ class TestAggregateException extends exceptions_1.BaseAggregateException {
7
+ constructor(message, code) {
8
+ super([
9
+ new test_exception_1.TestException('First inner exception'),
10
+ new test_exception_1.TestException('Second inner exception'),
11
+ new test_exception_1.TestException('Third inner exception'),
12
+ ], message, { code });
13
+ }
14
+ }
15
+ exports.TestAggregateException = TestAggregateException;
16
+ //# sourceMappingURL=test.aggregate-exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.aggregate-exception.js","sourceRoot":"","sources":["../../src/tests/test.aggregate-exception.ts"],"names":[],"mappings":";;;AAAA,8CAAuD;AACvD,qDAAiD;AAEjD,MAAa,sBAAuB,SAAQ,mCAAsB;IACjE,YAAmB,OAAe,EAAE,IAAa;QAChD,KAAK,CACJ;YACC,IAAI,8BAAa,CAAC,uBAAuB,CAAC;YAC1C,IAAI,8BAAa,CAAC,wBAAwB,CAAC;YAC3C,IAAI,8BAAa,CAAC,uBAAuB,CAAC;SAC1C,EACD,OAAO,EACP,EAAE,IAAI,EAAE,CACR,CAAC;IACH,CAAC;CACD;AAZD,wDAYC"}
@@ -0,0 +1,6 @@
1
+ import '@hg-ts-utils/types';
2
+ import { TestSuite } from '@hg-ts-utils/tests';
3
+ export declare class ExampleTestSuite extends TestSuite {
4
+ example(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/tests/test.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAEN,SAAS,EAET,MAAM,oBAAoB,CAAC;AAE5B,qBACa,gBAAiB,SAAQ,SAAS;IAEjC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAGrC"}
@@ -0,0 +1,5 @@
1
+ import { BaseException } from '../exceptions';
2
+ export declare class TestException extends BaseException {
3
+ constructor(message: string, code?: number);
4
+ }
5
+ //# sourceMappingURL=test.exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.exception.d.ts","sourceRoot":"","sources":["../../src/tests/test.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,qBAAa,aAAc,SAAQ,aAAa;gBAC5B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAGjD"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestException = void 0;
4
+ const exceptions_1 = require("../exceptions");
5
+ class TestException extends exceptions_1.BaseException {
6
+ constructor(message, code) {
7
+ super(message, { code });
8
+ }
9
+ }
10
+ exports.TestException = TestException;
11
+ //# sourceMappingURL=test.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.exception.js","sourceRoot":"","sources":["../../src/tests/test.exception.ts"],"names":[],"mappings":";;;AAAA,8CAA8C;AAE9C,MAAa,aAAc,SAAQ,0BAAa;IAC/C,YAAmB,OAAe,EAAE,IAAa;QAChD,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1B,CAAC;CACD;AAJD,sCAIC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExampleTestSuite = void 0;
4
+ const tslib_1 = require("tslib");
5
+ require("@hg-ts-utils/types");
6
+ const tests_1 = require("@hg-ts-utils/tests");
7
+ let ExampleTestSuite = class ExampleTestSuite extends tests_1.TestSuite {
8
+ async example() {
9
+ console.log('test');
10
+ }
11
+ };
12
+ tslib_1.__decorate([
13
+ (0, tests_1.Test)({ name: 'mocha:example ' }),
14
+ tslib_1.__metadata("design:type", Function),
15
+ tslib_1.__metadata("design:paramtypes", []),
16
+ tslib_1.__metadata("design:returntype", Promise)
17
+ ], ExampleTestSuite.prototype, "example", null);
18
+ ExampleTestSuite = tslib_1.__decorate([
19
+ (0, tests_1.Describe)()
20
+ ], ExampleTestSuite);
21
+ exports.ExampleTestSuite = ExampleTestSuite;
22
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/tests/test.ts"],"names":[],"mappings":";;;;AAAA,8BAA4B;AAC5B,8CAI4B;AAG5B,IAAa,gBAAgB,GAA7B,MAAa,gBAAiB,SAAQ,iBAAS;IAEvC,KAAK,CAAC,OAAO;QACnB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC;CACD,CAAA;AAHA;IADC,IAAA,YAAI,EAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC;;;;+CAGhC;AAJW,gBAAgB;IAD5B,IAAA,gBAAQ,GAAE;GACE,gBAAgB,CAK5B;AALY,4CAAgB"}
@@ -0,0 +1,2 @@
1
+ export * from './stack-trace.formatter';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./stack-trace.formatter"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC"}
@@ -0,0 +1,6 @@
1
+ export declare class StackTraceFormatter {
2
+ static format(stack: string, exceptionName: string): string[];
3
+ protected static getStackLines(stack: string, exceptionName: string): string[];
4
+ protected static isInternalStackLine(line: string): boolean;
5
+ }
6
+ //# sourceMappingURL=stack-trace.formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack-trace.formatter.d.ts","sourceRoot":"","sources":["../../src/utils/stack-trace.formatter.ts"],"names":[],"mappings":"AAGA,qBAAa,mBAAmB;WACjB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE;IAIpE,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE;IAkB9E,SAAS,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAG3D"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StackTraceFormatter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const os_1 = tslib_1.__importDefault(require("os"));
6
+ const consts_1 = require("../consts");
7
+ class StackTraceFormatter {
8
+ static format(stack, exceptionName) {
9
+ return StackTraceFormatter.getStackLines(stack, exceptionName);
10
+ }
11
+ static getStackLines(stack, exceptionName) {
12
+ let lines = stack.split(os_1.default.EOL)
13
+ .splice(1)
14
+ .filter(stackLine => !StackTraceFormatter.isInternalStackLine(stackLine))
15
+ .map(line => line.trim());
16
+ if (consts_1.SOURCE_MAP_ENABLED) {
17
+ lines = lines.slice(4);
18
+ }
19
+ const lineFromExceptionConstructor = lines.findIndex(line => line.startsWith(`at new ${exceptionName}`));
20
+ if (lineFromExceptionConstructor > -1) {
21
+ return lines.slice(lineFromExceptionConstructor + 1);
22
+ }
23
+ return lines;
24
+ }
25
+ static isInternalStackLine(line) {
26
+ return line.includes('internal/') && !line.includes('processTicksAndRejections');
27
+ }
28
+ }
29
+ exports.StackTraceFormatter = StackTraceFormatter;
30
+ //# sourceMappingURL=stack-trace.formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack-trace.formatter.js","sourceRoot":"","sources":["../../src/utils/stack-trace.formatter.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AACpB,sCAA+C;AAE/C,MAAa,mBAAmB;IACxB,MAAM,CAAC,MAAM,CAAC,KAAa,EAAE,aAAqB;QACxD,OAAO,mBAAmB,CAAC,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChE,CAAC;IAES,MAAM,CAAC,aAAa,CAAC,KAAa,EAAE,aAAqB;QAClE,IAAI,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,YAAE,CAAC,GAAG,CAAC;aAC7B,MAAM,CAAC,CAAC,CAAC;aACT,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;aACxE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAE3B,IAAI,2BAAkB,EAAE;YACvB,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACvB;QACD,MAAM,4BAA4B,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,aAAa,EAAE,CAAC,CAAC,CAAC;QAEzG,IAAI,4BAA4B,GAAG,CAAC,CAAC,EAAE;YACtC,OAAO,KAAK,CAAC,KAAK,CAAC,4BAA4B,GAAG,CAAC,CAAC,CAAC;SACrD;QAED,OAAO,KAAK,CAAC;IACd,CAAC;IAES,MAAM,CAAC,mBAAmB,CAAC,IAAY;QAChD,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAAC;IAClF,CAAC;CACD;AA1BD,kDA0BC"}
@@ -0,0 +1,2 @@
1
+ export declare const SOURCE_MAP_ENABLED: boolean;
2
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,SAAwC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const SOURCE_MAP_ENABLED = !!(new Error().stack?.includes('->'));
2
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { BaseAggregateException } from './base.aggregate.exception';
2
+ export declare class AggregateErrorException extends BaseAggregateException {
3
+ constructor(error: AggregateError);
4
+ }
5
+ //# sourceMappingURL=aggregate-error.exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate-error.exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/aggregate-error.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,qBAAa,uBAAwB,SAAQ,sBAAsB;gBAC/C,KAAK,EAAE,cAAc;CAqBxC"}
@@ -0,0 +1,20 @@
1
+ import { BaseAggregateException } from './base.aggregate.exception';
2
+ import { BaseException } from './base.exception';
3
+ export class AggregateErrorException extends BaseAggregateException {
4
+ constructor(error) {
5
+ const { errors } = error;
6
+ super(errors
7
+ .map(error => {
8
+ if (error instanceof AggregateError) {
9
+ BaseAggregateException.fromError(error);
10
+ }
11
+ if (error instanceof Error) {
12
+ return BaseException.fromError(error);
13
+ }
14
+ return null;
15
+ })
16
+ .filter((exception) => exception !== null), error.message);
17
+ this.stack = error.stack;
18
+ }
19
+ }
20
+ //# sourceMappingURL=aggregate-error.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate-error.exception.js","sourceRoot":"","sources":["../../src/exceptions/aggregate-error.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,uBAAwB,SAAQ,sBAAsB;IAClE,YAAmB,KAAqB;QACvC,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;QAEzB,KAAK,CACJ,MAAM;aACJ,GAAG,CAAC,KAAK,CAAC,EAAE;YACZ,IAAI,KAAK,YAAY,cAAc,EAAE;gBACpC,sBAAsB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;aACxC;YACD,IAAI,KAAK,YAAY,KAAK,EAAE;gBAC3B,OAAO,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;aACtC;YAED,OAAO,IAAI,CAAC;QACb,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,SAAS,EAA8B,EAAE,CAAC,SAAS,KAAK,IAAI,CAAC,EACvE,KAAK,CAAC,OAAO,CACb,CAAC;QAED,IAAY,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IACnC,CAAC;CACD"}
@@ -0,0 +1,13 @@
1
+ import { BaseException, ExceptionOptions, JSONBaseException } from './base.exception';
2
+ export declare type JSONBaseAggregateException = Omit<JSONBaseException, 'cause'> & {
3
+ exceptions: JSONBaseException[];
4
+ };
5
+ export declare type BaseAggregateExceptionOptions = Omit<ExceptionOptions, 'cause'>;
6
+ export declare abstract class BaseAggregateException extends BaseException {
7
+ readonly exceptions: BaseException[];
8
+ protected constructor(exceptions: BaseException[], message: string, options?: BaseAggregateExceptionOptions);
9
+ toJSON(): JSONBaseAggregateException;
10
+ static fromError(error: AggregateError): BaseAggregateException;
11
+ protected injectBeforeStack(padCount: number): string[];
12
+ }
13
+ //# sourceMappingURL=base.aggregate.exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.aggregate.exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/base.aggregate.exception.ts"],"names":[],"mappings":"AACA,OAAO,EACN,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EAEjB,MAAM,kBAAkB,CAAC;AAE1B,oBAAY,0BAA0B,GAAG,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,GAAG;IAC3E,UAAU,EAAE,iBAAiB,EAAE,CAAC;CAChC,CAAC;AAEF,oBAAY,6BAA6B,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAE5E,8BAAsB,sBAAuB,SAAQ,aAAa;IACjE,SAAgB,UAAU,EAAE,aAAa,EAAE,CAAC;IAE5C,SAAS,aACR,UAAU,EAAE,aAAa,EAAE,EAC3B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,6BAA6B;IAOxB,MAAM,IAAI,0BAA0B;WAS7B,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,sBAAsB;cAI5D,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;CAUhE"}
@@ -0,0 +1,29 @@
1
+ import { AggregateErrorException } from './aggregate-error.exception';
2
+ import { BaseException, PAD_COUNT_PER_DEPTH, } from './base.exception';
3
+ export class BaseAggregateException extends BaseException {
4
+ exceptions;
5
+ constructor(exceptions, message, options) {
6
+ super(message, options);
7
+ this.exceptions = exceptions;
8
+ }
9
+ toJSON() {
10
+ const baseJson = super.toJSON();
11
+ return {
12
+ ...baseJson,
13
+ exceptions: this.exceptions.map(exception => exception.toJSON()),
14
+ };
15
+ }
16
+ static fromError(error) {
17
+ return new AggregateErrorException(error);
18
+ }
19
+ injectBeforeStack(padCount) {
20
+ const innerExceptionsInfo = this.exceptions
21
+ .map(exception => exception['getStringifyFirstLine']())
22
+ .map(line => BaseException.padLine(line, padCount));
23
+ return [
24
+ BaseException.padLine('Aggregated exceptions info:', padCount - PAD_COUNT_PER_DEPTH),
25
+ ...innerExceptionsInfo,
26
+ ];
27
+ }
28
+ }
29
+ //# sourceMappingURL=base.aggregate.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.aggregate.exception.js","sourceRoot":"","sources":["../../src/exceptions/base.aggregate.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EACN,aAAa,EAGb,mBAAmB,GACnB,MAAM,kBAAkB,CAAC;AAQ1B,MAAM,OAAgB,sBAAuB,SAAQ,aAAa;IACjD,UAAU,CAAkB;IAE5C,YACC,UAA2B,EAC3B,OAAe,EACf,OAAuC;QAEvC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAExB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;IAEe,MAAM;QACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAEhC,OAAO;YACN,GAAG,QAAQ;YACX,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;SAChE,CAAC;IACH,CAAC;IAEM,MAAM,CAAU,SAAS,CAAC,KAAqB;QACrD,OAAO,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAEkB,iBAAiB,CAAC,QAAgB;QACpD,MAAM,mBAAmB,GAAG,IAAI,CAAC,UAAU;aACzC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,uBAAuB,CAAC,EAAE,CAAC;aACtD,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;QAErD,OAAO;YACN,aAAa,CAAC,OAAO,CAAC,6BAA6B,EAAE,QAAQ,GAAG,mBAAmB,CAAC;YACpF,GAAG,mBAAmB;SACtB,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,36 @@
1
+ /// <reference types="node" />
2
+ import { InspectOptionsStylized, inspect } from 'util';
3
+ export declare type JSONBaseException = {
4
+ name: string;
5
+ code: Nullable<number>;
6
+ message: string;
7
+ stack: string[];
8
+ cause?: JSONBaseException;
9
+ };
10
+ export declare type ExceptionOptions = {
11
+ cause?: BaseException | undefined;
12
+ code?: number | undefined;
13
+ };
14
+ export declare const PAD_COUNT_PER_DEPTH = 4;
15
+ export declare abstract class BaseException extends Error {
16
+ readonly code: Nullable<number>;
17
+ readonly stack: string;
18
+ readonly message: string;
19
+ readonly cause?: BaseException;
20
+ private serialized;
21
+ constructor(message: string, codeOrOptions?: ExceptionOptions);
22
+ get name(): string;
23
+ toJSON(): JSONBaseException;
24
+ toString(padCount?: number): string;
25
+ [inspect.custom](_depth: Nullable<number>, { stylize }: InspectOptionsStylized): string;
26
+ isFromNextTick(): boolean;
27
+ isFromImmediate(): boolean;
28
+ isFromTimer(): boolean;
29
+ static fromError(error: Error): BaseException;
30
+ protected getCtor(): Function;
31
+ protected getStringifyFirstLine(): string;
32
+ protected injectBeforeStack(padCount: number): string[];
33
+ protected static padLine(line: string, padCount: number): string;
34
+ private getLastStackLine;
35
+ }
36
+ //# sourceMappingURL=base.exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/base.exception.ts"],"names":[],"mappings":";AACA,OAAO,EACN,sBAAsB,EACtB,OAAO,EACP,MAAM,MAAM,CAAC;AAKd,oBAAY,iBAAiB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC1B,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC9B,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IAClC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,8BAAsB,aAAc,SAAQ,KAAK;IAChD,SAAgB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAQ;IAC9C,SAAyB,KAAK,EAAE,MAAM,CAAC;IACvC,SAAyB,OAAO,EAAE,MAAM,CAAC;IACzC,SAAyB,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/C,OAAO,CAAC,UAAU,CAAqC;gBAEpC,OAAO,EAAE,MAAM,EAAE,aAAa,GAAE,gBAAqB;IAexE,IAAoB,IAAI,IAAI,MAAM,CAIjC;IAEM,MAAM,IAAI,iBAAiB;IAmBlB,QAAQ,CAAC,QAAQ,SAAsB,GAAG,MAAM;IAazD,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,sBAAsB,GAAG,MAAM;IAIvF,cAAc,IAAI,OAAO;IAMzB,eAAe,IAAI,OAAO;IAM1B,WAAW,IAAI,OAAO;WAMf,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa;IAIpD,SAAS,CAAC,OAAO,IAAI,QAAQ;IAI7B,SAAS,CAAC,qBAAqB,IAAI,MAAM;IAMzC,SAAS,CAAC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;IAQvD,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIhE,OAAO,CAAC,gBAAgB;CAKxB"}
@@ -0,0 +1,91 @@
1
+ import * as os from 'os';
2
+ import { inspect, } from 'util';
3
+ import { StackTraceFormatter } from '../utils';
4
+ import { ErrorException } from './error.exception';
5
+ export const PAD_COUNT_PER_DEPTH = 4;
6
+ export class BaseException extends Error {
7
+ code = null;
8
+ stack;
9
+ message;
10
+ cause;
11
+ serialized = null;
12
+ constructor(message, codeOrOptions = {}) {
13
+ super(message);
14
+ this.message = message;
15
+ if (codeOrOptions.cause) {
16
+ this.cause = codeOrOptions.cause;
17
+ }
18
+ if (codeOrOptions.code) {
19
+ this.code = codeOrOptions.code;
20
+ }
21
+ Error.captureStackTrace(this, this.getCtor());
22
+ }
23
+ get name() {
24
+ const { name } = this.getCtor();
25
+ return name;
26
+ }
27
+ toJSON() {
28
+ if (this.serialized === null) {
29
+ const { name, message, stack, code, cause } = this;
30
+ this.serialized = {
31
+ name,
32
+ code,
33
+ message,
34
+ stack: StackTraceFormatter.format(stack, this.name),
35
+ };
36
+ if (cause) {
37
+ this.serialized.cause = cause.toJSON();
38
+ }
39
+ }
40
+ return this.serialized;
41
+ }
42
+ toString(padCount = PAD_COUNT_PER_DEPTH) {
43
+ const { stack } = this.toJSON();
44
+ const formattedStack = stack.map(line => BaseException.padLine(line, padCount));
45
+ const errorLines = [
46
+ this.getStringifyFirstLine(),
47
+ ...this.injectBeforeStack(padCount + PAD_COUNT_PER_DEPTH),
48
+ ...formattedStack,
49
+ ];
50
+ return errorLines.join(os.EOL);
51
+ }
52
+ [inspect.custom](_depth, { stylize }) {
53
+ return stylize(this.toString(), 'regexp');
54
+ }
55
+ isFromNextTick() {
56
+ const lastLine = this.getLastStackLine();
57
+ return lastLine.includes('processTicksAndRejections');
58
+ }
59
+ isFromImmediate() {
60
+ const lastLine = this.getLastStackLine();
61
+ return lastLine.includes('Immediate._onImmediate');
62
+ }
63
+ isFromTimer() {
64
+ const lastLine = this.getLastStackLine();
65
+ return lastLine.includes('Timeout._onTimeout');
66
+ }
67
+ static fromError(error) {
68
+ return new ErrorException(error);
69
+ }
70
+ getCtor() {
71
+ return Object.getPrototypeOf(this).constructor;
72
+ }
73
+ getStringifyFirstLine() {
74
+ const { name, code, message } = this.toJSON();
75
+ return `${name}${code === null ? '' : ` [code: ${code}]`}: ${message}`;
76
+ }
77
+ injectBeforeStack(padCount) {
78
+ if (this.cause) {
79
+ return [BaseException.padLine(this.cause.getStringifyFirstLine(), padCount)];
80
+ }
81
+ return [];
82
+ }
83
+ static padLine(line, padCount) {
84
+ return `${' '.repeat(padCount)}${line}`;
85
+ }
86
+ getLastStackLine() {
87
+ const { stack } = this.toJSON();
88
+ return stack[stack.length - 1] ?? '';
89
+ }
90
+ }
91
+ //# sourceMappingURL=base.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.exception.js","sourceRoot":"","sources":["../../src/exceptions/base.exception.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAEN,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,KAAK,CAAC,CAAC;IAClC,CAAC;IAES,OAAO;QAChB,OAAO,MAAM,CAAC,cAAc,CAAC,IAAI,CAAE,CAAC,WAAW,CAAC;IACjD,CAAC;IAES,qBAAqB;QAC9B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAE9C,OAAO,GAAG,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC;IACxE,CAAC;IAES,iBAAiB,CAAC,QAAgB;QAC3C,IAAI,IAAI,CAAC,KAAK,EAAE;YACf,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;SAC7E;QAED,OAAO,EAAE,CAAC;IACX,CAAC;IAES,MAAM,CAAC,OAAO,CAAC,IAAY,EAAE,QAAgB;QACtD,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC;IACzC,CAAC;IAEO,gBAAgB;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAEhC,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;CACD"}
@@ -0,0 +1,5 @@
1
+ import { BaseException } from './base.exception';
2
+ export declare class ErrorException extends BaseException {
3
+ constructor(error: Error);
4
+ }
5
+ //# sourceMappingURL=error.exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/error.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qBAAa,cAAe,SAAQ,aAAa;gBAC7B,KAAK,EAAE,KAAK;CAY/B"}
@@ -0,0 +1,13 @@
1
+ import { BaseException } from './base.exception';
2
+ export class ErrorException extends BaseException {
3
+ constructor(error) {
4
+ const { cause } = error;
5
+ super(error.message, {
6
+ cause: cause instanceof Error
7
+ ? new ErrorException(cause)
8
+ : undefined,
9
+ });
10
+ this.stack = error.stack;
11
+ }
12
+ }
13
+ //# sourceMappingURL=error.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.exception.js","sourceRoot":"","sources":["../../src/exceptions/error.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,cAAe,SAAQ,aAAa;IAChD,YAAmB,KAAY;QAC9B,MAAM,EAAE,KAAK,EAAE,GAAG,KAAY,CAAC;QAE/B,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE;YACpB,KAAK,EAAE,KAAK,YAAY,KAAK;gBAC5B,CAAC,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC;gBAE3B,CAAC,CAAC,SAAS;SACZ,CAAC,CAAC;QAEF,IAAY,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IACnC,CAAC;CACD"}
@@ -0,0 +1,4 @@
1
+ import { BaseException } from './base.exception';
2
+ export declare class ForbiddenException extends BaseException {
3
+ }
4
+ //# sourceMappingURL=forbidden.exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forbidden.exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/forbidden.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qBAAa,kBAAmB,SAAQ,aAAa;CAAG"}
@@ -0,0 +1,4 @@
1
+ import { BaseException } from './base.exception';
2
+ export class ForbiddenException extends BaseException {
3
+ }
4
+ //# sourceMappingURL=forbidden.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forbidden.exception.js","sourceRoot":"","sources":["../../src/exceptions/forbidden.exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,OAAO,kBAAmB,SAAQ,aAAa;CAAG"}
@@ -0,0 +1,9 @@
1
+ export * from './error.exception';
2
+ export * from './aggregate-error.exception';
3
+ export * from './base.exception';
4
+ export * from './base.aggregate.exception';
5
+ export * from './unknown.exception';
6
+ export * from './not-implemented.exception';
7
+ export * from './will-never-happened.exception';
8
+ export * from './forbidden.exception';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAE5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC"}