@e22m4u/ts-rest-router 0.0.6 → 0.1.0
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/README-ru.md +227 -0
- package/README.md +227 -0
- package/dist/cjs/index.cjs +448 -153
- package/dist/esm/controller-registry.d.ts +53 -11
- package/dist/esm/controller-registry.js +242 -104
- package/dist/esm/debuggable-service.js +1 -1
- package/dist/esm/decorators/action/action-decorator.d.ts +7 -8
- package/dist/esm/decorators/action/action-decorator.js +1 -5
- package/dist/esm/decorators/action/action-decorator.spec.js +16 -16
- package/dist/esm/decorators/action/action-metadata.d.ts +0 -1
- package/dist/esm/decorators/after/after-decorator.d.ts +9 -0
- package/dist/esm/decorators/after/after-decorator.js +22 -0
- package/dist/esm/decorators/after/after-decorator.spec.d.ts +1 -0
- package/dist/esm/decorators/after/after-decorator.spec.js +115 -0
- package/dist/esm/decorators/after/after-metadata.d.ts +13 -0
- package/dist/esm/decorators/after/after-metadata.js +5 -0
- package/dist/esm/decorators/after/after-reflector.d.ts +22 -0
- package/dist/esm/decorators/after/after-reflector.js +29 -0
- package/dist/esm/decorators/after/after-reflector.spec.d.ts +1 -0
- package/dist/esm/decorators/after/after-reflector.spec.js +102 -0
- package/dist/esm/decorators/after/index.d.ts +3 -0
- package/dist/esm/decorators/after/index.js +3 -0
- package/dist/esm/decorators/before/before-decorator.d.ts +9 -0
- package/dist/esm/decorators/before/before-decorator.js +22 -0
- package/dist/esm/decorators/before/before-decorator.spec.d.ts +1 -0
- package/dist/esm/decorators/before/before-decorator.spec.js +115 -0
- package/dist/esm/decorators/before/before-metadata.d.ts +13 -0
- package/dist/esm/decorators/before/before-metadata.js +5 -0
- package/dist/esm/decorators/before/before-reflector.d.ts +22 -0
- package/dist/esm/decorators/before/before-reflector.js +29 -0
- package/dist/esm/decorators/before/before-reflector.spec.d.ts +1 -0
- package/dist/esm/decorators/before/before-reflector.spec.js +102 -0
- package/dist/esm/decorators/before/index.d.ts +3 -0
- package/dist/esm/decorators/before/index.js +3 -0
- package/dist/esm/decorators/controller/controller-decorator.d.ts +2 -1
- package/dist/esm/decorators/controller/controller-decorator.js +27 -6
- package/dist/esm/decorators/controller/controller-decorator.spec.js +37 -15
- package/dist/esm/decorators/controller/controller-metadata.d.ts +0 -1
- package/dist/esm/decorators/index.d.ts +2 -0
- package/dist/esm/decorators/index.js +2 -0
- package/dist/esm/decorators/request-context/request-context-decorator.d.ts +2 -3
- package/dist/esm/decorators/request-context/request-context-decorator.js +3 -6
- package/dist/esm/decorators/request-context/request-context-decorator.spec.js +2 -17
- package/dist/esm/decorators/request-context/request-context-metadata.d.ts +0 -1
- package/dist/esm/decorators/request-data/request-data-decorator.d.ts +7 -3
- package/dist/esm/decorators/request-data/request-data-decorator.js +16 -16
- package/dist/esm/decorators/request-data/request-data-decorator.spec.js +12 -10
- package/dist/esm/decorators/request-data/request-data-metadata.d.ts +0 -1
- package/dist/esm/utils/create-debugger.d.ts +35 -2
- package/dist/esm/utils/create-debugger.js +71 -5
- package/package.json +17 -17
- package/src/controller-registry.spec.ts +601 -275
- package/src/controller-registry.ts +263 -128
- package/src/debuggable-service.ts +1 -1
- package/src/decorators/action/action-decorator.spec.ts +16 -16
- package/src/decorators/action/action-decorator.ts +10 -12
- package/src/decorators/action/action-metadata.ts +0 -1
- package/src/decorators/after/after-decorator.spec.ts +92 -0
- package/src/decorators/after/after-decorator.ts +40 -0
- package/src/decorators/after/after-metadata.ts +17 -0
- package/src/decorators/after/after-reflector.spec.ts +107 -0
- package/src/decorators/after/after-reflector.ts +45 -0
- package/src/decorators/after/index.ts +3 -0
- package/src/decorators/before/before-decorator.spec.ts +92 -0
- package/src/decorators/before/before-decorator.ts +40 -0
- package/src/decorators/before/before-metadata.ts +17 -0
- package/src/decorators/before/before-reflector.spec.ts +111 -0
- package/src/decorators/before/before-reflector.ts +50 -0
- package/src/decorators/before/index.ts +3 -0
- package/src/decorators/controller/controller-decorator.spec.ts +33 -16
- package/src/decorators/controller/controller-decorator.ts +33 -6
- package/src/decorators/controller/controller-metadata.ts +0 -1
- package/src/decorators/index.ts +2 -0
- package/src/decorators/request-context/request-context-decorator.spec.ts +2 -15
- package/src/decorators/request-context/request-context-decorator.ts +3 -8
- package/src/decorators/request-context/request-context-metadata.ts +0 -1
- package/src/decorators/request-data/request-data-decorator.spec.ts +12 -11
- package/src/decorators/request-data/request-data-decorator.ts +41 -16
- package/src/decorators/request-data/request-data-metadata.ts +0 -1
- package/src/utils/create-debugger.ts +84 -7
@@ -1,15 +1,81 @@
|
|
1
|
-
import
|
1
|
+
import { inspect } from 'util';
|
2
|
+
import DebugModule from 'debug';
|
2
3
|
import { format } from '@e22m4u/js-format';
|
4
|
+
/**
|
5
|
+
* Colorize string.
|
6
|
+
*
|
7
|
+
* @param input
|
8
|
+
*/
|
9
|
+
function colorizeString(input) {
|
10
|
+
const c = Number(DebugModule['selectColor'](input));
|
11
|
+
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
12
|
+
return `${colorCode};1m${input}\u001B[0m`;
|
13
|
+
}
|
3
14
|
/**
|
4
15
|
* Create debugger.
|
5
16
|
*
|
17
|
+
* Base usage:
|
18
|
+
* ```ts
|
19
|
+
* const debug = createDebugger('myService');
|
20
|
+
* debug('Service created.');
|
21
|
+
* // ujut:myService Service created.
|
22
|
+
* ```
|
23
|
+
*
|
24
|
+
* Nested namespaces:
|
25
|
+
* ```ts
|
26
|
+
* const debug1 = debug.bind('namespace1');
|
27
|
+
* const debug2 = debug.bind('namespace2');
|
28
|
+
* debug1('Application started'); // ujut:myService [namespace1] Application started
|
29
|
+
* debug2('Connection established'); // ujut:myService [namespace2] Connection established
|
30
|
+
* ```
|
31
|
+
*
|
32
|
+
* Value inspection:
|
33
|
+
* ```ts
|
34
|
+
* debug({foo: 'lorem', bar: 'ipsum'})
|
35
|
+
* // ujut:myService {
|
36
|
+
* // ujut:myService "foo": "lorem",
|
37
|
+
* // ujut:myService "bar": "ipsum"
|
38
|
+
* // ujut:myService }
|
39
|
+
* ```
|
40
|
+
*
|
41
|
+
* Titled inspection output:
|
42
|
+
* ```ts
|
43
|
+
* debug({foo: 'lorem', bar: 'ipsum'}, 'My awesome output:')
|
44
|
+
* // ujut:myService My awesome output:
|
45
|
+
* // ujut:myService {
|
46
|
+
* // ujut:myService "foo": "lorem",
|
47
|
+
* // ujut:myService "bar": "ipsum"
|
48
|
+
* // ujut:myService }
|
49
|
+
* ```
|
50
|
+
*
|
6
51
|
* @param name
|
7
52
|
*/
|
8
53
|
export function createDebugger(name) {
|
9
|
-
const
|
54
|
+
const debuggerName = `tsRestRouter:${name}`;
|
55
|
+
// включить вывод логов можно принудительно
|
56
|
+
// if (!process.env.DEBUG) DebugModule.enable('ujut*');
|
57
|
+
const debug = DebugModule(debuggerName);
|
58
|
+
return function (messageOrData,
|
10
59
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
11
|
-
|
12
|
-
|
13
|
-
|
60
|
+
...args) {
|
61
|
+
let prefix = '';
|
62
|
+
if (typeof this === 'string') {
|
63
|
+
const isDebugUsesColors = debug.useColors;
|
64
|
+
prefix = isDebugUsesColors ? colorizeString(`[${this}] `) : `[${this}] `;
|
65
|
+
}
|
66
|
+
if (typeof messageOrData === 'string') {
|
67
|
+
const interpolatedMessage = format(messageOrData, ...args);
|
68
|
+
return debug(prefix + interpolatedMessage);
|
69
|
+
}
|
70
|
+
const inspectOptions = {
|
71
|
+
showHidden: false,
|
72
|
+
depth: null,
|
73
|
+
colors: true,
|
74
|
+
compact: false,
|
75
|
+
};
|
76
|
+
const multiString = inspect(messageOrData, inspectOptions);
|
77
|
+
const rows = multiString.split('\n');
|
78
|
+
const colorizedDebuggerName = colorizeString(debuggerName);
|
79
|
+
[...args, ...rows].forEach(v => console.log(` ${colorizedDebuggerName} ${prefix}${v}`));
|
14
80
|
};
|
15
81
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@e22m4u/ts-rest-router",
|
3
|
-
"version": "0.0
|
3
|
+
"version": "0.1.0",
|
4
4
|
"description": "Controllers-based REST router implementation for TypeScript",
|
5
5
|
"author": "e22m4u <e22m4u@yandex.ru>",
|
6
6
|
"keywords": [
|
@@ -40,37 +40,37 @@
|
|
40
40
|
"prepare": "husky"
|
41
41
|
},
|
42
42
|
"dependencies": {
|
43
|
-
"@e22m4u/js-format": "0.1.
|
44
|
-
"@e22m4u/js-service": "0.2.
|
45
|
-
"@e22m4u/js-trie-router": "0.0.
|
46
|
-
"@e22m4u/ts-data-schema": "0.0.
|
47
|
-
"@e22m4u/ts-reflector": "0.1.
|
48
|
-
"debug": "~4.
|
43
|
+
"@e22m4u/js-format": "~0.1.0",
|
44
|
+
"@e22m4u/js-service": "~0.2.0",
|
45
|
+
"@e22m4u/js-trie-router": "~0.0.1",
|
46
|
+
"@e22m4u/ts-data-schema": "~0.0.1",
|
47
|
+
"@e22m4u/ts-reflector": "~0.1.0",
|
48
|
+
"debug": "~4.4.0",
|
49
49
|
"http-errors": "~2.0.0"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
52
|
-
"@commitlint/cli": "~19.6.
|
52
|
+
"@commitlint/cli": "~19.6.1",
|
53
53
|
"@commitlint/config-conventional": "~19.6.0",
|
54
|
-
"@eslint/js": "~9.
|
54
|
+
"@eslint/js": "~9.17.0",
|
55
55
|
"@types/chai": "~5.0.1",
|
56
56
|
"@types/debug": "~4.1.12",
|
57
57
|
"@types/http-errors": "~2.0.4",
|
58
58
|
"@types/mocha": "~10.0.10",
|
59
|
-
"@types/node": "~22.
|
60
|
-
"c8": "~10.1.
|
59
|
+
"@types/node": "~22.10.2",
|
60
|
+
"c8": "~10.1.3",
|
61
61
|
"chai": "~5.1.2",
|
62
|
-
"esbuild": "~0.24.
|
63
|
-
"eslint": "~9.
|
62
|
+
"esbuild": "~0.24.2",
|
63
|
+
"eslint": "~9.17.0",
|
64
64
|
"eslint-config-prettier": "~9.1.0",
|
65
65
|
"eslint-plugin-chai-expect": "~3.1.0",
|
66
66
|
"eslint-plugin-mocha": "~10.5.0",
|
67
67
|
"husky": "~9.1.7",
|
68
|
-
"mocha": "~
|
69
|
-
"prettier": "~3.
|
68
|
+
"mocha": "~11.0.1",
|
69
|
+
"prettier": "~3.4.2",
|
70
70
|
"rimraf": "~6.0.1",
|
71
71
|
"tsx": "~4.19.2",
|
72
|
-
"typescript": "~5.
|
73
|
-
"typescript-eslint": "~8.
|
72
|
+
"typescript": "~5.7.2",
|
73
|
+
"typescript-eslint": "~8.18.2"
|
74
74
|
},
|
75
75
|
"license": "MIT"
|
76
76
|
}
|