@wooksjs/event-core 0.5.7 → 0.5.9
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/index.cjs +3 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.mjs +3 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -9,6 +9,8 @@ class ContextInjector {
|
|
|
9
9
|
const fn = typeof attributes === 'function' ? attributes : cb;
|
|
10
10
|
return fn();
|
|
11
11
|
}
|
|
12
|
+
hook(name, route) {
|
|
13
|
+
}
|
|
12
14
|
}
|
|
13
15
|
let ci = new ContextInjector();
|
|
14
16
|
function getContextInjector() {
|
|
@@ -30,7 +32,7 @@ const asyncStorage = new node_async_hooks.AsyncLocalStorage();
|
|
|
30
32
|
function createAsyncEventContext(data) {
|
|
31
33
|
const newContext = { ...data };
|
|
32
34
|
const ci = getContextInjector();
|
|
33
|
-
return (cb) => asyncStorage.run(newContext, () => ci.with(
|
|
35
|
+
return (cb) => asyncStorage.run(newContext, () => ci.with('Event:start', { eventType: newContext.event.type }, cb));
|
|
34
36
|
}
|
|
35
37
|
function useAsyncEventContext(expectedTypes) {
|
|
36
38
|
let cc = asyncStorage.getStore();
|
package/dist/index.d.ts
CHANGED
|
@@ -286,13 +286,15 @@ declare function useRouteParams<T extends object = Record<string, string | strin
|
|
|
286
286
|
* Provides a way to inject context
|
|
287
287
|
* Usefull when working with opentelemetry spans
|
|
288
288
|
*/
|
|
289
|
-
declare class ContextInjector {
|
|
290
|
-
with<T>(name:
|
|
291
|
-
with<T>(name:
|
|
289
|
+
declare class ContextInjector<N> {
|
|
290
|
+
with<T>(name: N, attributes: Record<string, string | number | boolean>, cb: TContextInjectorCallback<T>): T;
|
|
291
|
+
with<T>(name: N, cb: TContextInjectorCallback<T>): T;
|
|
292
|
+
hook(name: 'Handler:not_found' | 'Handler:routed', route?: string): void;
|
|
292
293
|
}
|
|
293
294
|
type TContextInjectorCallback<T> = () => T;
|
|
294
|
-
declare function getContextInjector(): ContextInjector
|
|
295
|
-
declare function replaceContextInjector(newCi: ContextInjector): void;
|
|
295
|
+
declare function getContextInjector<N = TContextInjectorHooks>(): ContextInjector<N>;
|
|
296
|
+
declare function replaceContextInjector(newCi: ContextInjector<string>): void;
|
|
297
|
+
type TContextInjectorHooks = 'Event:start';
|
|
296
298
|
|
|
297
299
|
declare function attachHook<V = unknown, T extends object | Function = object, P extends PropertyKey = 'value'>(target: T, opts: {
|
|
298
300
|
get: () => V | undefined;
|
|
@@ -302,4 +304,4 @@ type THook<T = string, K extends PropertyKey = 'value'> = {
|
|
|
302
304
|
[key in K]: T;
|
|
303
305
|
};
|
|
304
306
|
|
|
305
|
-
export { ContextInjector, EventLogger, type TEmpty, type TEventLoggerData, type TEventOptions, type TGenericContextStore, type TGenericEvent, type THook, asyncStorage, attachHook, createAsyncEventContext, getContextInjector, replaceContextInjector, useAsyncEventContext, useEventId, useEventLogger, useRouteParams };
|
|
307
|
+
export { ContextInjector, EventLogger, type TContextInjectorHooks, type TEmpty, type TEventLoggerData, type TEventOptions, type TGenericContextStore, type TGenericEvent, type THook, asyncStorage, attachHook, createAsyncEventContext, getContextInjector, replaceContextInjector, useAsyncEventContext, useEventId, useEventLogger, useRouteParams };
|
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,8 @@ class ContextInjector {
|
|
|
7
7
|
const fn = typeof attributes === 'function' ? attributes : cb;
|
|
8
8
|
return fn();
|
|
9
9
|
}
|
|
10
|
+
hook(name, route) {
|
|
11
|
+
}
|
|
10
12
|
}
|
|
11
13
|
let ci = new ContextInjector();
|
|
12
14
|
function getContextInjector() {
|
|
@@ -28,7 +30,7 @@ const asyncStorage = new AsyncLocalStorage();
|
|
|
28
30
|
function createAsyncEventContext(data) {
|
|
29
31
|
const newContext = { ...data };
|
|
30
32
|
const ci = getContextInjector();
|
|
31
|
-
return (cb) => asyncStorage.run(newContext, () => ci.with(
|
|
33
|
+
return (cb) => asyncStorage.run(newContext, () => ci.with('Event:start', { eventType: newContext.event.type }, cb));
|
|
32
34
|
}
|
|
33
35
|
function useAsyncEventContext(expectedTypes) {
|
|
34
36
|
let cc = asyncStorage.getStore();
|