@nmtjs/core 0.12.5 → 0.12.6
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/dist/constants.d.ts +20 -0
- package/dist/constants.js +10 -12
- package/dist/container.d.ts +46 -0
- package/dist/container.js +310 -277
- package/dist/enums.d.ts +18 -0
- package/dist/enums.js +20 -22
- package/dist/hooks.d.ts +19 -0
- package/dist/hooks.js +39 -35
- package/dist/index.d.ts +11 -0
- package/dist/index.js +3 -2
- package/dist/injectables.d.ts +115 -0
- package/dist/injectables.js +194 -179
- package/dist/logger.d.ts +9 -0
- package/dist/logger.js +54 -58
- package/dist/metadata.d.ts +13 -0
- package/dist/metadata.js +10 -15
- package/dist/plugin.d.ts +12 -0
- package/dist/plugin.js +1 -7
- package/dist/registry.d.ts +19 -0
- package/dist/registry.js +17 -18
- package/dist/types.d.ts +11 -0
- package/dist/types.js +0 -2
- package/dist/utils/functions.d.ts +6 -0
- package/dist/utils/functions.js +30 -32
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +0 -2
- package/dist/utils/pool.d.ts +18 -0
- package/dist/utils/pool.js +103 -90
- package/dist/utils/semaphore.d.ts +13 -0
- package/dist/utils/semaphore.js +53 -46
- package/package.json +9 -8
- package/src/hooks.ts +1 -3
- package/src/index.ts +4 -0
- package/src/injectables.ts +2 -2
- package/src/logger.ts +1 -0
- package/src/plugin.ts +1 -1
- package/src/utils/pool.ts +1 -1
- package/src/utils/semaphore.ts +1 -1
- package/dist/constants.js.map +0 -1
- package/dist/container.js.map +0 -1
- package/dist/enums.js.map +0 -1
- package/dist/hooks.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/injectables.js.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/metadata.js.map +0 -1
- package/dist/plugin.js.map +0 -1
- package/dist/registry.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/functions.js.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/pool.js.map +0 -1
- package/dist/utils/semaphore.js.map +0 -1
package/dist/injectables.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { tryCaptureStackTrace } from
|
|
2
|
-
import { kClassInjectable, kFactoryInjectable, kHookCollection, kInjectable, kLazyInjectable, kOptionalDependency, kValueInjectable } from "./constants.js";
|
|
1
|
+
import { tryCaptureStackTrace, } from '@nmtjs/common';
|
|
2
|
+
import { kClassInjectable, kFactoryInjectable, kHookCollection, kInjectable, kLazyInjectable, kOptionalDependency, kValueInjectable, } from "./constants.js";
|
|
3
3
|
import { Scope } from "./enums.js";
|
|
4
4
|
import { Hooks } from "./hooks.js";
|
|
5
5
|
const ScopeStrictness = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
[Scope.Transient]: Number.NaN, // this should make it always fail to compare with other scopes
|
|
7
|
+
[Scope.Global]: 1,
|
|
8
|
+
[Scope.Connection]: 2,
|
|
9
|
+
[Scope.Call]: 3,
|
|
10
10
|
};
|
|
11
11
|
export const isLazyInjectable = (injectable) => injectable[kLazyInjectable];
|
|
12
12
|
export const isFactoryInjectable = (injectable) => injectable[kFactoryInjectable];
|
|
@@ -15,201 +15,216 @@ export const isValueInjectable = (injectable) => injectable[kValueInjectable];
|
|
|
15
15
|
export const isInjectable = (injectable) => injectable[kInjectable];
|
|
16
16
|
export const isOptionalInjectable = (injectable) => injectable[kOptionalDependency];
|
|
17
17
|
export function getInjectableScope(injectable) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
let scope = injectable.scope;
|
|
19
|
+
const deps = injectable.dependencies;
|
|
20
|
+
for (const key in deps) {
|
|
21
|
+
const dependency = deps[key];
|
|
22
|
+
const injectable = getDepedencencyInjectable(dependency);
|
|
23
|
+
const dependencyScope = getInjectableScope(injectable);
|
|
24
|
+
if (dependencyScope !== Scope.Transient &&
|
|
25
|
+
scope !== Scope.Transient &&
|
|
26
|
+
compareScope(dependencyScope, '>', scope)) {
|
|
27
|
+
scope = dependencyScope;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return scope;
|
|
29
31
|
}
|
|
30
32
|
export function getDepedencencyInjectable(dependency) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
if (kOptionalDependency in dependency) {
|
|
34
|
+
return dependency.injectable;
|
|
35
|
+
}
|
|
36
|
+
return dependency;
|
|
35
37
|
}
|
|
36
38
|
export function createOptionalInjectable(injectable) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
return Object.freeze({
|
|
40
|
+
[kOptionalDependency]: true,
|
|
41
|
+
injectable,
|
|
42
|
+
});
|
|
41
43
|
}
|
|
42
44
|
export function createLazyInjectable(scope = Scope.Global, label, stackTraceDepth = 0) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
scope,
|
|
47
|
+
dependencies: {},
|
|
48
|
+
label,
|
|
49
|
+
stack: tryCaptureStackTrace(stackTraceDepth),
|
|
50
|
+
[kInjectable]: true,
|
|
51
|
+
[kLazyInjectable]: true,
|
|
52
|
+
});
|
|
51
53
|
}
|
|
52
54
|
export function createValueInjectable(value, label, stackTraceDepth = 0) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
return Object.freeze({
|
|
56
|
+
value,
|
|
57
|
+
scope: Scope.Global,
|
|
58
|
+
dependencies: {},
|
|
59
|
+
label,
|
|
60
|
+
stack: tryCaptureStackTrace(stackTraceDepth),
|
|
61
|
+
[kInjectable]: true,
|
|
62
|
+
[kValueInjectable]: true,
|
|
63
|
+
});
|
|
62
64
|
}
|
|
63
65
|
export function createFactoryInjectable(paramsOrFactory, label, stackTraceDepth = 0) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
const isFactory = typeof paramsOrFactory === 'function';
|
|
67
|
+
const params = isFactory ? { factory: paramsOrFactory } : paramsOrFactory;
|
|
68
|
+
const injectable = {
|
|
69
|
+
dependencies: (params.dependencies ?? {}),
|
|
70
|
+
scope: (params.scope ?? Scope.Global),
|
|
71
|
+
factory: params.factory,
|
|
72
|
+
dispose: params.dispose,
|
|
73
|
+
pick: params.pick ?? ((instance) => instance),
|
|
74
|
+
label,
|
|
75
|
+
stack: tryCaptureStackTrace(stackTraceDepth),
|
|
76
|
+
[kInjectable]: true,
|
|
77
|
+
[kFactoryInjectable]: true,
|
|
78
|
+
};
|
|
79
|
+
injectable.scope = resolveInjectableScope(typeof params.scope === 'undefined', injectable);
|
|
80
|
+
return Object.freeze(injectable);
|
|
79
81
|
}
|
|
80
82
|
export const createClassInjectable = (dependencies = {}, scope, stackTraceDepth = 0) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
const InjectableClass = class {
|
|
84
|
+
$context;
|
|
85
|
+
static dependencies = dependencies;
|
|
86
|
+
static scope = (scope ?? Scope.Global);
|
|
87
|
+
static stack = tryCaptureStackTrace(stackTraceDepth + 2);
|
|
88
|
+
static [kInjectable] = true;
|
|
89
|
+
static [kClassInjectable] = true;
|
|
90
|
+
static get label() {
|
|
91
|
+
// biome-ignore lint/complexity/noThisInStatic: ok
|
|
92
|
+
return this.name;
|
|
93
|
+
}
|
|
94
|
+
constructor($context) {
|
|
95
|
+
this.$context = $context;
|
|
96
|
+
}
|
|
97
|
+
async $onCreate() { }
|
|
98
|
+
async $onDispose() { }
|
|
99
|
+
};
|
|
100
|
+
InjectableClass.scope = resolveInjectableScope(typeof scope === 'undefined', InjectableClass);
|
|
101
|
+
return InjectableClass;
|
|
98
102
|
};
|
|
99
103
|
export function createExtendableClassInjectable(baseClass, dependencies = {}, scope, stackTraceDepth = 0) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
104
|
+
if (isClassInjectable(baseClass)) {
|
|
105
|
+
if (scope && compareScope(baseClass.scope, '>', scope)) {
|
|
106
|
+
throw new Error(`Invalid scope ${scope} for an extendable class injectable: base class have stricter scope - ${baseClass.scope}`);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
scope = scope ?? baseClass.scope;
|
|
110
|
+
}
|
|
111
|
+
dependencies = Object.assign({}, baseClass.dependencies, dependencies);
|
|
112
|
+
}
|
|
113
|
+
const InjectableClass = class extends baseClass {
|
|
114
|
+
static dependencies = dependencies;
|
|
115
|
+
static scope = (scope ?? Scope.Global);
|
|
116
|
+
static stack = tryCaptureStackTrace(stackTraceDepth);
|
|
117
|
+
static [kInjectable] = true;
|
|
118
|
+
static [kClassInjectable] = true;
|
|
119
|
+
static get label() {
|
|
120
|
+
// biome-ignore lint/complexity/noThisInStatic: ok
|
|
121
|
+
return this.name;
|
|
122
|
+
}
|
|
123
|
+
$context;
|
|
124
|
+
constructor(...args) {
|
|
125
|
+
const [$context, ...baseClassArgs] = args;
|
|
126
|
+
if (isClassInjectable(baseClass)) {
|
|
127
|
+
super($context);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
super(...baseClassArgs);
|
|
131
|
+
}
|
|
132
|
+
this.$context = $context;
|
|
133
|
+
}
|
|
134
|
+
async $onCreate() {
|
|
135
|
+
await super.$onCreate?.();
|
|
136
|
+
}
|
|
137
|
+
async $onDispose() {
|
|
138
|
+
await super.$onDispose?.();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
InjectableClass.scope = resolveInjectableScope(typeof scope === 'undefined', InjectableClass);
|
|
142
|
+
// @ts-expect-error
|
|
143
|
+
return InjectableClass;
|
|
136
144
|
}
|
|
137
145
|
export function substitute(injectable, substitution, stackTraceDepth = 0) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
146
|
+
const dependencies = { ...injectable.dependencies };
|
|
147
|
+
const depth = stackTraceDepth + 1;
|
|
148
|
+
for (const key in substitution) {
|
|
149
|
+
const value = substitution[key];
|
|
150
|
+
if (key in dependencies) {
|
|
151
|
+
const original = dependencies[key];
|
|
152
|
+
if (isInjectable(value)) {
|
|
153
|
+
dependencies[key] = value;
|
|
154
|
+
}
|
|
155
|
+
else if (isClassInjectable(original) || isFactoryInjectable(original)) {
|
|
156
|
+
dependencies[key] = substitute(original, value, depth);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (isClassInjectable(injectable)) {
|
|
161
|
+
// @ts-expect-error
|
|
162
|
+
return createExtendableClassInjectable(injectable, dependencies, injectable.scope, depth);
|
|
163
|
+
}
|
|
164
|
+
else if (isFactoryInjectable(injectable)) {
|
|
165
|
+
// @ts-expect-error
|
|
166
|
+
return createFactoryInjectable({
|
|
167
|
+
...injectable,
|
|
168
|
+
dependencies,
|
|
169
|
+
}, injectable.label, depth);
|
|
170
|
+
}
|
|
171
|
+
throw new Error('Invalid injectable type');
|
|
160
172
|
}
|
|
161
173
|
export function compareScope(left, operator, right) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
const leftScope = ScopeStrictness[left];
|
|
175
|
+
const rightScope = ScopeStrictness[right];
|
|
176
|
+
switch (operator) {
|
|
177
|
+
case '=':
|
|
178
|
+
return leftScope === rightScope;
|
|
179
|
+
case '!=':
|
|
180
|
+
return leftScope !== rightScope;
|
|
181
|
+
case '>':
|
|
182
|
+
return leftScope > rightScope;
|
|
183
|
+
case '<':
|
|
184
|
+
return leftScope < rightScope;
|
|
185
|
+
case '>=':
|
|
186
|
+
return leftScope >= rightScope;
|
|
187
|
+
case '<=':
|
|
188
|
+
return leftScope <= rightScope;
|
|
189
|
+
default:
|
|
190
|
+
throw new Error('Invalid operator');
|
|
191
|
+
}
|
|
173
192
|
}
|
|
174
|
-
const logger = createLazyInjectable(Scope.Global,
|
|
175
|
-
const registry = createLazyInjectable(Scope.Global,
|
|
176
|
-
const inject = createLazyInjectable(Scope.Global,
|
|
177
|
-
const dispose = createLazyInjectable(Scope.Global,
|
|
193
|
+
const logger = createLazyInjectable(Scope.Global, 'Logger');
|
|
194
|
+
const registry = createLazyInjectable(Scope.Global, 'Registry');
|
|
195
|
+
const inject = createLazyInjectable(Scope.Global, 'Inject function');
|
|
196
|
+
const dispose = createLazyInjectable(Scope.Global, 'Dispose function');
|
|
178
197
|
const hook = createFactoryInjectable({
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
hooks.clear();
|
|
200
|
-
}
|
|
198
|
+
scope: Scope.Transient,
|
|
199
|
+
dependencies: { registry },
|
|
200
|
+
factory: ({ registry }) => {
|
|
201
|
+
const hooks = new Hooks();
|
|
202
|
+
const on = (name, callback) => {
|
|
203
|
+
hooks.add(name, callback);
|
|
204
|
+
return registry.hooks.add(name, callback);
|
|
205
|
+
};
|
|
206
|
+
return { hooks, on };
|
|
207
|
+
},
|
|
208
|
+
pick: ({ on }) => on,
|
|
209
|
+
dispose: ({ hooks }, { registry }) => {
|
|
210
|
+
for (const [hook, callbacks] of hooks[kHookCollection].entries()) {
|
|
211
|
+
for (const callback of callbacks) {
|
|
212
|
+
registry.hooks.remove(hook, callback);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
hooks.clear();
|
|
216
|
+
},
|
|
201
217
|
});
|
|
202
218
|
function resolveInjectableScope(isDefaultScope, injectable) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
219
|
+
const actualScope = getInjectableScope(injectable);
|
|
220
|
+
if (!isDefaultScope && compareScope(actualScope, '>', injectable.scope))
|
|
221
|
+
throw new Error(`Invalid scope ${injectable.scope} for an injectable: dependencies have stricter scope - ${actualScope}`);
|
|
222
|
+
return actualScope;
|
|
206
223
|
}
|
|
207
224
|
export const CoreInjectables = {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
225
|
+
logger,
|
|
226
|
+
registry,
|
|
227
|
+
inject,
|
|
228
|
+
dispose,
|
|
229
|
+
hook,
|
|
213
230
|
};
|
|
214
|
-
|
|
215
|
-
//# sourceMappingURL=injectables.js.map
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type DestinationStream, type Level, type Logger as PinoLogger, pino, type StreamEntry } from 'pino';
|
|
2
|
+
export type { StreamEntry } from 'pino';
|
|
3
|
+
export type Logger = PinoLogger;
|
|
4
|
+
export type LoggingOptions = {
|
|
5
|
+
destinations?: Array<DestinationStream | StreamEntry<Level>>;
|
|
6
|
+
pinoOptions?: any;
|
|
7
|
+
};
|
|
8
|
+
export declare const createLogger: (options: LoggingOptions | undefined, $group: string) => pino.Logger<never, boolean>;
|
|
9
|
+
export declare const createConsolePrettyDestination: (level: Level, sync?: boolean) => StreamEntry;
|
package/dist/logger.js
CHANGED
|
@@ -1,70 +1,66 @@
|
|
|
1
|
-
import { threadId } from
|
|
2
|
-
import { pino, stdTimeFunctions } from
|
|
3
|
-
import { build as pretty } from
|
|
1
|
+
import { threadId } from 'node:worker_threads';
|
|
2
|
+
import { pino, stdTimeFunctions, } from 'pino';
|
|
3
|
+
import { build as pretty } from 'pino-pretty';
|
|
4
|
+
// TODO: use node:util inspect
|
|
4
5
|
const bg = (value, color) => `\x1b[${color}m${value}\x1b[0m`;
|
|
5
6
|
const fg = (value, color) => `\x1b[38;5;${color}m${value}\x1b[0m`;
|
|
6
7
|
const levelColors = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
10: 100,
|
|
9
|
+
20: 102,
|
|
10
|
+
30: 106,
|
|
11
|
+
40: 104,
|
|
12
|
+
50: 101,
|
|
13
|
+
60: 105,
|
|
14
|
+
[Number.POSITIVE_INFINITY]: 0,
|
|
14
15
|
};
|
|
15
16
|
const messageColors = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
10: 0,
|
|
18
|
+
20: 2,
|
|
19
|
+
30: 6,
|
|
20
|
+
40: 4,
|
|
21
|
+
50: 1,
|
|
22
|
+
60: 5,
|
|
23
|
+
[Number.POSITIVE_INFINITY]: 0,
|
|
23
24
|
};
|
|
24
25
|
const levelLabels = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
10: ' TRACE ',
|
|
27
|
+
20: ' DEBUG ',
|
|
28
|
+
30: ' INFO ',
|
|
29
|
+
40: ' WARN ',
|
|
30
|
+
50: ' ERROR ',
|
|
31
|
+
60: ' FATAL ',
|
|
32
|
+
[Number.POSITIVE_INFINITY]: 'SILENT',
|
|
32
33
|
};
|
|
33
34
|
export const createLogger = (options = {}, $group) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
35
|
+
let { destinations, pinoOptions } = options;
|
|
36
|
+
if (!destinations || !destinations?.length) {
|
|
37
|
+
destinations = [createConsolePrettyDestination('info')];
|
|
38
|
+
}
|
|
39
|
+
const lowestLevelValue = destinations.reduce((acc, destination) => Math.min(acc, 'stream' in destination
|
|
40
|
+
? pino.levels.values[destination.level]
|
|
41
|
+
: Number.POSITIVE_INFINITY), Number.POSITIVE_INFINITY);
|
|
42
|
+
const level = pino.levels.labels[lowestLevelValue];
|
|
43
|
+
return pino({
|
|
44
|
+
timestamp: stdTimeFunctions.isoTime,
|
|
45
|
+
...pinoOptions,
|
|
46
|
+
level,
|
|
47
|
+
}, pino.multistream(destinations)).child({ $group, $threadId: threadId });
|
|
48
48
|
};
|
|
49
49
|
export const createConsolePrettyDestination = (level, sync = true) => ({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
sync
|
|
67
|
-
})
|
|
50
|
+
level,
|
|
51
|
+
stream: pretty({
|
|
52
|
+
colorize: true,
|
|
53
|
+
ignore: 'hostname,$group,$threadId',
|
|
54
|
+
errorLikeObjectKeys: ['err', 'error', 'cause'],
|
|
55
|
+
messageFormat: (log, messageKey) => {
|
|
56
|
+
const group = fg(`[${log.$group}]`, 11);
|
|
57
|
+
const msg = fg(log[messageKey], messageColors[log.level]);
|
|
58
|
+
const thread = fg(`(Thread-${log.$threadId})`, 89);
|
|
59
|
+
return `\x1b[0m${thread} ${group} ${msg}`;
|
|
60
|
+
},
|
|
61
|
+
customPrettifiers: {
|
|
62
|
+
level: (level) => bg(levelLabels[level], levelColors[level]),
|
|
63
|
+
},
|
|
64
|
+
sync,
|
|
65
|
+
}),
|
|
68
66
|
});
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { kMetadata } from './constants.ts';
|
|
2
|
+
export type Metadata<T = any> = {
|
|
3
|
+
key: MetadataKey<T>;
|
|
4
|
+
value: T;
|
|
5
|
+
};
|
|
6
|
+
export type MetadataKey<T = any> = {
|
|
7
|
+
[kMetadata]: string;
|
|
8
|
+
as(value: T): Metadata<T>;
|
|
9
|
+
};
|
|
10
|
+
export declare const createMetadataKey: <T>(key: string) => MetadataKey<T>;
|
|
11
|
+
export declare class MetadataStore extends Map<MetadataKey, Metadata> {
|
|
12
|
+
get<T>(key: MetadataKey<T>): T | undefined;
|
|
13
|
+
}
|
package/dist/metadata.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import { kMetadata } from "./constants.js";
|
|
2
2
|
export const createMetadataKey = (key) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
return metadataKey;
|
|
3
|
+
const metadataKey = {
|
|
4
|
+
[kMetadata]: key,
|
|
5
|
+
as(value) {
|
|
6
|
+
return { key: metadataKey, value };
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
return metadataKey;
|
|
13
10
|
};
|
|
14
11
|
export class MetadataStore extends Map {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
get(key) {
|
|
13
|
+
return super.get(key);
|
|
14
|
+
}
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=metadata.js.map
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Async } from '@nmtjs/common';
|
|
2
|
+
import { kPlugin } from './constants.ts';
|
|
3
|
+
import type { PluginContext } from './types.ts';
|
|
4
|
+
export interface BasePlugin<Type = any, Options = unknown, Context extends PluginContext = PluginContext> {
|
|
5
|
+
name: string;
|
|
6
|
+
init: (context: Context, options: Options) => Async<Type>;
|
|
7
|
+
}
|
|
8
|
+
export interface Plugin<Type = void, Options = unknown, Context extends PluginContext = PluginContext> extends BasePlugin<Type, Options, Context> {
|
|
9
|
+
[kPlugin]: any;
|
|
10
|
+
}
|
|
11
|
+
export declare const createPlugin: <Options = unknown, Type = void>(name: string, init: Plugin<Type, Options>["init"]) => Plugin<Type, Options>;
|
|
12
|
+
export declare const isPlugin: (value: any) => value is Plugin;
|
package/dist/plugin.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import { kPlugin } from "./constants.js";
|
|
2
|
-
export const createPlugin = (name, init) => ({
|
|
3
|
-
name,
|
|
4
|
-
init,
|
|
5
|
-
[kPlugin]: true
|
|
6
|
-
});
|
|
2
|
+
export const createPlugin = (name, init) => ({ name, init, [kPlugin]: true });
|
|
7
3
|
export const isPlugin = (value) => kPlugin in value;
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Hook, Scope } from './enums.ts';
|
|
2
|
+
import { Hooks, type HookType } from './hooks.ts';
|
|
3
|
+
import { type AnyInjectable, type Dependant } from './injectables.ts';
|
|
4
|
+
import type { Logger } from './logger.ts';
|
|
5
|
+
export declare class Registry {
|
|
6
|
+
protected readonly application: {
|
|
7
|
+
logger: Logger;
|
|
8
|
+
};
|
|
9
|
+
readonly hooks: Hooks;
|
|
10
|
+
constructor(application: {
|
|
11
|
+
logger: Logger;
|
|
12
|
+
});
|
|
13
|
+
registerHooks<T extends Hooks>(hooks: T): void;
|
|
14
|
+
registerHook<T extends Hook>(name: T, callback: HookType[T]): void;
|
|
15
|
+
getDependants(): Generator<Dependant>;
|
|
16
|
+
clear(): void;
|
|
17
|
+
}
|
|
18
|
+
export declare const scopeErrorMessage: (name: any, scope?: Scope) => string;
|
|
19
|
+
export declare function hasInvalidScopeDeps(injectables: AnyInjectable[], scope?: Scope): boolean;
|