@samet-it/be-base-common 1.0.1
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/LICENSE +24 -0
- package/README.md +106 -0
- package/dist/assets/.gitkeep +0 -0
- package/dist/config/base-common.config.d.ts +2 -0
- package/dist/config/base-common.config.js +9 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +18 -0
- package/dist/config/index.types.d.ts +12 -0
- package/dist/config/index.types.js +2 -0
- package/dist/error/base.exception.d.ts +7 -0
- package/dist/error/base.exception.js +11 -0
- package/dist/error/error.handler.d.ts +2 -0
- package/dist/error/error.handler.js +217 -0
- package/dist/error/index.d.ts +8 -0
- package/dist/error/index.js +24 -0
- package/dist/error/index.types.d.ts +31 -0
- package/dist/error/index.types.js +2 -0
- package/dist/error/initialization.exception.d.ts +4 -0
- package/dist/error/initialization.exception.js +11 -0
- package/dist/error/page-not-found.exception.d.ts +4 -0
- package/dist/error/page-not-found.exception.js +10 -0
- package/dist/error/record-duplicated.exception.d.ts +4 -0
- package/dist/error/record-duplicated.exception.js +18 -0
- package/dist/error/record-not-found.exception.d.ts +4 -0
- package/dist/error/record-not-found.exception.js +13 -0
- package/dist/error/validation.exception.d.ts +4 -0
- package/dist/error/validation.exception.js +23 -0
- package/dist/exit/exit-handler.impl.d.ts +2 -0
- package/dist/exit/exit-handler.impl.js +13 -0
- package/dist/exit/index.d.ts +2 -0
- package/dist/exit/index.js +18 -0
- package/dist/exit/index.types.d.ts +4 -0
- package/dist/exit/index.types.js +2 -0
- package/dist/generator/generator.d.ts +2 -0
- package/dist/generator/generator.js +417 -0
- package/dist/generator/index.d.ts +2 -0
- package/dist/generator/index.js +18 -0
- package/dist/generator/index.types.d.ts +616 -0
- package/dist/generator/index.types.js +2 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +17 -0
- package/dist/shared/index.types.d.ts +11 -0
- package/dist/shared/index.types.js +2 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Samet Global
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
Web: https://sametglobal.com
|
|
24
|
+
Responsible: Mustafa Yelmer (mustafay@samet.com.tr)
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Samet Digital : Base Common [Component]
|
|
2
|
+
```
|
|
3
|
+
▗▄▄▖ ▗▄▖ ▗▄▄▖▗▄▄▄▖ ▗▄▄▖ ▗▄▖ ▗▖ ▗▖▗▖ ▗▖ ▗▄▖ ▗▖ ▗▖
|
|
4
|
+
▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌ ▐▌ ▐▌ ▐▌▐▛▚▞▜▌▐▛▚▞▜▌▐▌ ▐▌▐▛▚▖▐▌
|
|
5
|
+
▐▛▀▚▖▐▛▀▜▌ ▝▀▚▖▐▛▀▀▘ ▐▌ ▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▐▌ ▝▜▌
|
|
6
|
+
▐▙▄▞▘▐▌ ▐▌▗▄▄▞▘▐▙▄▄▖ ▝▚▄▄▖▝▚▄▞▘▐▌ ▐▌▐▌ ▐▌▝▚▄▞▘▐▌ ▐▌
|
|
7
|
+
```
|
|
8
|
+
- `EN`: It's base component
|
|
9
|
+
- `TR`: Nodejs projeleri için temel bileşen
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
- `EN`: How to add into your project?
|
|
13
|
+
- `TR`: Projene nasıl eklersin?
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
npm i @samet-it/be-base-common
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Environments
|
|
20
|
+
>
|
|
21
|
+
| Name | Type | Default | Options |
|
|
22
|
+
|-------------|------|---------|-------------------------------------------------|
|
|
23
|
+
| `NODE_ENV` | enum | _local_ | [local, development, test, staging, production] |
|
|
24
|
+
| `LOG_LEVEL` | enum | _debug_ | [debug, info, warn, error] |
|
|
25
|
+
|
|
26
|
+
## Contents
|
|
27
|
+
- [errorHandler](./src/error/error.handler.ts) : error handler
|
|
28
|
+
- [generator](./src/generator/generator.ts) : mock data generator
|
|
29
|
+
|
|
30
|
+
## Development
|
|
31
|
+
> You can start to develop on it
|
|
32
|
+
>
|
|
33
|
+
### Step 1
|
|
34
|
+
- `EN`: Go to your project folder
|
|
35
|
+
- `TR`: Bilgisayarında proje klasörüne git
|
|
36
|
+
```shell
|
|
37
|
+
# Windows
|
|
38
|
+
cd C:\\projects\samet-digital
|
|
39
|
+
```
|
|
40
|
+
```shell
|
|
41
|
+
# Mac
|
|
42
|
+
cd /Users/{user}/projects/samet-digital
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Step 2
|
|
46
|
+
- `EN`: Clone the project
|
|
47
|
+
- `TR`: Projeyi bilgisiyarına çek
|
|
48
|
+
```shell
|
|
49
|
+
git clone https://github.com/samet-digital/be-base-common.git -b development
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Dependencies
|
|
53
|
+
- ~~Nothing~~
|
|
54
|
+
|
|
55
|
+
## Commands
|
|
56
|
+
```shell
|
|
57
|
+
# Collects all dependencies
|
|
58
|
+
npm i
|
|
59
|
+
|
|
60
|
+
# Builds project dist (TS -> JS, src -> dist)
|
|
61
|
+
npm run build
|
|
62
|
+
|
|
63
|
+
# Publishes component on http://npmjs.com/
|
|
64
|
+
npm run publish:public
|
|
65
|
+
|
|
66
|
+
# Clears `dist` and `coverage` folders
|
|
67
|
+
npm run clear
|
|
68
|
+
|
|
69
|
+
# Clear `node_modules` folder
|
|
70
|
+
npm run clear:nm
|
|
71
|
+
|
|
72
|
+
# Validates lint for only errors @see (./eslint.config.mjs) for rules
|
|
73
|
+
npm run lint
|
|
74
|
+
|
|
75
|
+
# Validates lint with warnings
|
|
76
|
+
npm run lint:verbose
|
|
77
|
+
|
|
78
|
+
# Runs test cases
|
|
79
|
+
npm run test
|
|
80
|
+
|
|
81
|
+
# Exports coverage report, @see (./coverage/lcov-report/index.html)
|
|
82
|
+
npm run coverage
|
|
83
|
+
|
|
84
|
+
# Finds outdated/legacy dependencies
|
|
85
|
+
npm outdated
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Standards
|
|
89
|
+
```diff
|
|
90
|
+
+ language: TS
|
|
91
|
+
+ lint: eslint
|
|
92
|
+
+ inspections: intelli-j code inspections
|
|
93
|
+
+ ddd: domain driven development
|
|
94
|
+
+ edd: exception driven development
|
|
95
|
+
! tdd: test driven development
|
|
96
|
+
+ ldd: log driven development
|
|
97
|
+
+ ddd: document driven development
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## History
|
|
101
|
+
| Date | Developer | Info | Ticket |
|
|
102
|
+
|------------|----------------|--------------|----------------|
|
|
103
|
+
| 2025-04-27 | Mustafa Yelmer | _Created_ | ~~[none](./)~~ |
|
|
104
|
+
| 2025-08-12 | Mustafa Yelmer | _Refactored_ | ~~[none](./)~~ |
|
|
105
|
+
| 2025-08-14 | Mustafa Yelmer | _Documented_ | ~~[none](./)~~ |
|
|
106
|
+
| 2026-01-08 | Mustafa Yelmer | _Documented_ | ~~[none](./)~~ |
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.baseCommonConfig = void 0;
|
|
4
|
+
const env_1 = require("@leyyo/env");
|
|
5
|
+
const common_1 = require("@leyyo/common");
|
|
6
|
+
// noinspection JSUnusedGlobalSymbols
|
|
7
|
+
exports.baseCommonConfig = env_1.envCore.scope('BaseCommon')
|
|
8
|
+
.field('NODE_ENV').literal(common_1.EnvironmentItems).required().def('development').end()
|
|
9
|
+
.field('LOG_LEVEL').literal(common_1.LogLevelItems).required().def('info').end();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./base-common.config"), exports);
|
|
18
|
+
__exportStar(require("./index.types"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EnvBase } from "@leyyo/env";
|
|
2
|
+
import { Environment, LogLevel } from "@leyyo/common";
|
|
3
|
+
export declare namespace NodeJS {
|
|
4
|
+
interface ProcessEnv extends BaseCommonConf {
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export interface BaseCommonConf extends EnvBase {
|
|
8
|
+
readonly NODE_ENV: Environment;
|
|
9
|
+
readonly LOG_LEVEL: LogLevel;
|
|
10
|
+
readonly npm_package_name: string;
|
|
11
|
+
readonly npm_package_version: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ErrorStackLine, ExceptionLike } from "../error";
|
|
2
|
+
export declare class BaseException extends Error implements ExceptionLike {
|
|
3
|
+
status: number;
|
|
4
|
+
params: Record<string, unknown>;
|
|
5
|
+
stackTrace: Array<ErrorStackLine>;
|
|
6
|
+
constructor(message: string, params: Record<string, unknown>, status?: number);
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseException = void 0;
|
|
4
|
+
class BaseException extends Error {
|
|
5
|
+
constructor(message, params, status) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.params = params !== null && params !== void 0 ? params : {};
|
|
8
|
+
this.status = Number.isInteger(status) ? status : 499;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.BaseException = BaseException;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.errorHandler = void 0;
|
|
37
|
+
const stackTraceParser = __importStar(require("stacktrace-parser"));
|
|
38
|
+
const base_exception_1 = require("./base.exception");
|
|
39
|
+
const KNOWN_GROUPS = {
|
|
40
|
+
'@samet-digital': 's',
|
|
41
|
+
'@leyyo': 'l',
|
|
42
|
+
'@nestjs': 'n',
|
|
43
|
+
};
|
|
44
|
+
const IGNORED_KEYS = ['constructor', 'prototype', 'message', 'stack', 'name'];
|
|
45
|
+
class ErrorHandler {
|
|
46
|
+
item(value, set) {
|
|
47
|
+
var _a;
|
|
48
|
+
if (value === null || value === undefined) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
switch (typeof value) {
|
|
52
|
+
case "string":
|
|
53
|
+
case "boolean":
|
|
54
|
+
case "number":
|
|
55
|
+
case "bigint":
|
|
56
|
+
return value;
|
|
57
|
+
case "object": {
|
|
58
|
+
if (set.has(value)) {
|
|
59
|
+
return `#ref: circular dependency: ${(_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.name}`;
|
|
60
|
+
}
|
|
61
|
+
set.add(value);
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
return value
|
|
64
|
+
.map(item => this.item(item, set));
|
|
65
|
+
}
|
|
66
|
+
else if (value instanceof Set) {
|
|
67
|
+
return Array.from(value.values())
|
|
68
|
+
.map(item => this.item(item, set));
|
|
69
|
+
}
|
|
70
|
+
else if (value instanceof Map) {
|
|
71
|
+
const result = {};
|
|
72
|
+
for (const [k, v] of value.entries()) {
|
|
73
|
+
if (typeof k === 'symbol') {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
result[k] = this.item(v, set);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
const result = {};
|
|
81
|
+
for (const [k, v] of Object.entries(value)) {
|
|
82
|
+
if (typeof k === 'symbol') {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
result[k] = this.item(v, set);
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
case "function":
|
|
90
|
+
return `#ref: function: ${value === null || value === void 0 ? void 0 : value.name}`;
|
|
91
|
+
case "symbol":
|
|
92
|
+
return `#ref: symbol: ${value === null || value === void 0 ? void 0 : value.description}`;
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
checkParams(exception) {
|
|
97
|
+
const set = new WeakSet();
|
|
98
|
+
set.add(exception);
|
|
99
|
+
exception.params = this.item(exception.params, set);
|
|
100
|
+
}
|
|
101
|
+
export(exception) {
|
|
102
|
+
var _a;
|
|
103
|
+
const result = {};
|
|
104
|
+
this.checkParams(exception);
|
|
105
|
+
const all = Object.assign({}, exception);
|
|
106
|
+
if (all.params) {
|
|
107
|
+
if (typeof all.params['$name'] === 'string') {
|
|
108
|
+
result.name = all.params['$name'];
|
|
109
|
+
delete all.params['$name'];
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
result.name = all.name;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (all.name && result.name !== all.name && all.name !== 'BaseException') {
|
|
116
|
+
if (!all.params) {
|
|
117
|
+
all.params = {};
|
|
118
|
+
}
|
|
119
|
+
all.params['$name'] = all.name;
|
|
120
|
+
}
|
|
121
|
+
delete all.name;
|
|
122
|
+
result.message = (_a = all.message) !== null && _a !== void 0 ? _a : result.name;
|
|
123
|
+
delete all.message;
|
|
124
|
+
if (all.params !== undefined) {
|
|
125
|
+
if (Object.keys(all.params).length > 0) {
|
|
126
|
+
result.params = Object.assign({}, all.params);
|
|
127
|
+
}
|
|
128
|
+
delete all.params;
|
|
129
|
+
}
|
|
130
|
+
if (all.stackTrace !== undefined) {
|
|
131
|
+
result.stackTrace = [...all.stackTrace];
|
|
132
|
+
delete all.stackTrace;
|
|
133
|
+
delete all.stack;
|
|
134
|
+
}
|
|
135
|
+
if (all.stack !== undefined) {
|
|
136
|
+
delete all.stack;
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
cast(error, p1, p2) {
|
|
141
|
+
let fnc;
|
|
142
|
+
let status;
|
|
143
|
+
switch (typeof p1) {
|
|
144
|
+
case "function":
|
|
145
|
+
fnc = p1;
|
|
146
|
+
break;
|
|
147
|
+
case "number":
|
|
148
|
+
status = p1;
|
|
149
|
+
if (typeof p2 === 'function') {
|
|
150
|
+
fnc = p2;
|
|
151
|
+
}
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
if (!fnc) {
|
|
155
|
+
fnc = base_exception_1.BaseException;
|
|
156
|
+
}
|
|
157
|
+
const exc = new fnc(error.message, {}, status);
|
|
158
|
+
exc.params['$name'] = error.name;
|
|
159
|
+
let now = Date.now();
|
|
160
|
+
for (const [key, value] of Object.entries(error)) {
|
|
161
|
+
if (typeof key === 'symbol' || value === undefined || IGNORED_KEYS.includes(key)) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (exc.params[key] === undefined) {
|
|
165
|
+
exc.params[key] = value;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
now++;
|
|
169
|
+
exc.params[`$${key}__${now}`] = value;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return exc;
|
|
173
|
+
}
|
|
174
|
+
stack(source, causedBy) {
|
|
175
|
+
var _a;
|
|
176
|
+
source.stackTrace = [];
|
|
177
|
+
try {
|
|
178
|
+
const original = (_a = causedBy.stack) !== null && _a !== void 0 ? _a : source.stack;
|
|
179
|
+
if (original) {
|
|
180
|
+
const frames = stackTraceParser.parse(original);
|
|
181
|
+
if (Array.isArray(frames)) {
|
|
182
|
+
frames.forEach(frame => {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
if (['<unknown>', 'Object.<anonymous>'].includes(frame.methodName)) {
|
|
185
|
+
frame.methodName = undefined;
|
|
186
|
+
}
|
|
187
|
+
if (frame.file) {
|
|
188
|
+
if (frame.file.startsWith('node:')) {
|
|
189
|
+
frame.file = `@` + frame.file.substring(5);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
for (const [pck, short] of Object.entries(KNOWN_GROUPS)) {
|
|
193
|
+
const index = frame.file.indexOf(pck);
|
|
194
|
+
if (index >= 0) {
|
|
195
|
+
frame.file = `#${short}` + frame.file.substring(index);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (frame.file.endsWith('.js') || frame.file.endsWith('.ts')) {
|
|
200
|
+
frame.file.substring(0, frame.file.length - 3);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
source.stackTrace.push({
|
|
204
|
+
file: frame.file,
|
|
205
|
+
method: frame.methodName,
|
|
206
|
+
pos: `${(_a = frame.lineNumber) !== null && _a !== void 0 ? _a : ''}:${(_b = frame.column) !== null && _b !== void 0 ? _b : ''}`
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch (e) {
|
|
213
|
+
// none
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.errorHandler = new ErrorHandler();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './base.exception';
|
|
2
|
+
export * from './error.handler';
|
|
3
|
+
export * from './index.types';
|
|
4
|
+
export * from './initialization.exception';
|
|
5
|
+
export * from './page-not-found.exception';
|
|
6
|
+
export * from './record-duplicated.exception';
|
|
7
|
+
export * from './record-not-found.exception';
|
|
8
|
+
export * from './validation.exception';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./base.exception"), exports);
|
|
18
|
+
__exportStar(require("./error.handler"), exports);
|
|
19
|
+
__exportStar(require("./index.types"), exports);
|
|
20
|
+
__exportStar(require("./initialization.exception"), exports);
|
|
21
|
+
__exportStar(require("./page-not-found.exception"), exports);
|
|
22
|
+
__exportStar(require("./record-duplicated.exception"), exports);
|
|
23
|
+
__exportStar(require("./record-not-found.exception"), exports);
|
|
24
|
+
__exportStar(require("./validation.exception"), exports);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ClassLike } from "../shared";
|
|
2
|
+
/**
|
|
3
|
+
* Stack line
|
|
4
|
+
* */
|
|
5
|
+
export interface ErrorStackLine {
|
|
6
|
+
file: string;
|
|
7
|
+
method?: string;
|
|
8
|
+
pos?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Core exception
|
|
12
|
+
* */
|
|
13
|
+
export interface ExceptionLike extends Error {
|
|
14
|
+
status: number;
|
|
15
|
+
params: Record<string, unknown>;
|
|
16
|
+
stackTrace: Array<ErrorStackLine>;
|
|
17
|
+
}
|
|
18
|
+
export interface ExceptionExported {
|
|
19
|
+
name: string;
|
|
20
|
+
message: string;
|
|
21
|
+
params?: Record<string, unknown>;
|
|
22
|
+
stackTrace?: Array<ErrorStackLine>;
|
|
23
|
+
}
|
|
24
|
+
export type ErrorItem<A, C = ExceptionLike> = A extends ClassLike<infer R> ? (R extends ExceptionLike ? C : never) : never;
|
|
25
|
+
export interface ErrorHandlerLike {
|
|
26
|
+
checkParams(exception: ExceptionLike): void;
|
|
27
|
+
export(exception: ExceptionLike): ExceptionExported;
|
|
28
|
+
cast<F extends ClassLike<ExceptionLike>>(error: Error, fnc?: F): ErrorItem<F>;
|
|
29
|
+
cast<F extends ClassLike<ExceptionLike>>(error: Error, status: number, fnc?: F): ErrorItem<F>;
|
|
30
|
+
stack(source: ExceptionLike, causedBy?: Error): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InitializationException = void 0;
|
|
4
|
+
// noinspection JSUnusedGlobalSymbols
|
|
5
|
+
const base_exception_1 = require("./base.exception");
|
|
6
|
+
class InitializationException extends base_exception_1.BaseException {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message, {}, 500);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.InitializationException = InitializationException;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PageNotFoundException = void 0;
|
|
4
|
+
const base_exception_1 = require("./base.exception");
|
|
5
|
+
class PageNotFoundException extends base_exception_1.BaseException {
|
|
6
|
+
constructor(path) {
|
|
7
|
+
super(`Path: ${path} is not found`, { path }, 404);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.PageNotFoundException = PageNotFoundException;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecordDuplicatedException = void 0;
|
|
4
|
+
const base_exception_1 = require("./base.exception");
|
|
5
|
+
// noinspection JSUnusedGlobalSymbols
|
|
6
|
+
class RecordDuplicatedException extends base_exception_1.BaseException {
|
|
7
|
+
constructor(domain, value, id) {
|
|
8
|
+
let valueJson;
|
|
9
|
+
try {
|
|
10
|
+
valueJson = JSON.stringify(value);
|
|
11
|
+
}
|
|
12
|
+
catch (_e) {
|
|
13
|
+
//
|
|
14
|
+
}
|
|
15
|
+
super(`${domain} is duplicated with values: ${valueJson}, existing:${id}`, { domain, id, value }, 409);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.RecordDuplicatedException = RecordDuplicatedException;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecordNotFoundException = void 0;
|
|
4
|
+
const base_exception_1 = require("./base.exception");
|
|
5
|
+
// noinspection JSUnusedGlobalSymbols
|
|
6
|
+
class RecordNotFoundException extends base_exception_1.BaseException {
|
|
7
|
+
constructor(domain, key, value) {
|
|
8
|
+
super(`Record could not be found`, {
|
|
9
|
+
domain, key, value
|
|
10
|
+
}, 404);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.RecordNotFoundException = RecordNotFoundException;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationException = void 0;
|
|
4
|
+
const base_exception_1 = require("./base.exception");
|
|
5
|
+
// noinspection JSUnusedGlobalSymbols
|
|
6
|
+
class ValidationException extends base_exception_1.BaseException {
|
|
7
|
+
constructor(domain, key, value, params) {
|
|
8
|
+
try {
|
|
9
|
+
value = JSON.parse(JSON.stringify(value));
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
value = undefined;
|
|
13
|
+
}
|
|
14
|
+
if (!params) {
|
|
15
|
+
params = { domain, key, value };
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
params = Object.assign(Object.assign({}, params), { domain, key, value });
|
|
19
|
+
}
|
|
20
|
+
super(`${domain} -> ${key} is invalid`, params, 409);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.ValidationException = ValidationException;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exitHandler = void 0;
|
|
4
|
+
class ExitHandlerImpl {
|
|
5
|
+
register(fn) {
|
|
6
|
+
['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGKILL'].forEach(event => {
|
|
7
|
+
process.on(event, () => {
|
|
8
|
+
fn(`${event} event received`);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.exitHandler = new ExitHandlerImpl();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./exit-handler.impl"), exports);
|
|
18
|
+
__exportStar(require("./index.types"), exports);
|