@wooksjs/event-core 0.5.5 → 0.5.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/index.cjs +5 -10
- package/dist/index.d.ts +13 -12
- package/dist/index.mjs +5 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -71,17 +71,17 @@ function createAsyncEventContext(data) {
|
|
|
71
71
|
if (result instanceof Promise) {
|
|
72
72
|
result
|
|
73
73
|
.then(r => {
|
|
74
|
-
|
|
74
|
+
fireEndEvent(r);
|
|
75
75
|
return r;
|
|
76
76
|
})
|
|
77
77
|
.catch(error => {
|
|
78
|
-
|
|
78
|
+
fireEndEvent(error);
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
|
-
|
|
82
|
+
fireEndEvent(result);
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function fireEndEvent(output) {
|
|
85
85
|
if (!newContext._ended) {
|
|
86
86
|
if (output instanceof Error) {
|
|
87
87
|
asyncStorage.run(newContext, () => {
|
|
@@ -194,12 +194,6 @@ function _getCtxHelpers(cc) {
|
|
|
194
194
|
const hasParentCtx = () => !!cc.parentCtx;
|
|
195
195
|
return {
|
|
196
196
|
getCtx,
|
|
197
|
-
endEvent: (abortReason) => {
|
|
198
|
-
if (cc && !cc._ended) {
|
|
199
|
-
cc._ended = true;
|
|
200
|
-
eventContextHooks.fireEndEvent(cc.event.type, abortReason);
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
197
|
store,
|
|
204
198
|
getStore: get,
|
|
205
199
|
setStore: set,
|
|
@@ -267,6 +261,7 @@ function useRouteParams() {
|
|
|
267
261
|
}
|
|
268
262
|
|
|
269
263
|
exports.EventLogger = EventLogger;
|
|
264
|
+
exports.Hookable = Hookable;
|
|
270
265
|
exports.asyncStorage = asyncStorage;
|
|
271
266
|
exports.attachHook = attachHook;
|
|
272
267
|
exports.createAsyncEventContext = createAsyncEventContext;
|
package/dist/index.d.ts
CHANGED
|
@@ -35,7 +35,6 @@ declare const asyncStorage: AsyncLocalStorage<unknown>;
|
|
|
35
35
|
declare function createAsyncEventContext<S = TEmpty, EventTypeToCreate = TEmpty>(data: S & TGenericContextStore<EventTypeToCreate>): <T>(cb: (...a: any[]) => T) => T;
|
|
36
36
|
declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTypes?: string | string[]): {
|
|
37
37
|
getCtx: () => S & TGenericContextStore<EventType>;
|
|
38
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
39
38
|
store: <K extends keyof S | keyof TGenericContextStore<EventType>>(key: K) => {
|
|
40
39
|
value: (S & TGenericContextStore<EventType>)[K];
|
|
41
40
|
hook: <K2 extends keyof Required<S & TGenericContextStore<EventType>>[K]>(key2: K2) => {
|
|
@@ -56,7 +55,6 @@ declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTy
|
|
|
56
55
|
hasParentCtx: () => boolean;
|
|
57
56
|
getParentCtx: <T2 = S & TGenericContextStore<EventType>>() => {
|
|
58
57
|
getCtx: () => T2;
|
|
59
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
60
58
|
store: <K_3 extends keyof T2>(key: K_3) => {
|
|
61
59
|
value: T2[K_3];
|
|
62
60
|
hook: <K2_6 extends keyof Required<T2>[K_3]>(key2: K2_6) => {
|
|
@@ -77,7 +75,6 @@ declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTy
|
|
|
77
75
|
hasParentCtx: () => boolean;
|
|
78
76
|
getParentCtx: <T2_1 = T2>() => {
|
|
79
77
|
getCtx: () => T2_1;
|
|
80
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
81
78
|
store: <K_6 extends keyof T2_1>(key: K_6) => {
|
|
82
79
|
value: T2_1[K_6];
|
|
83
80
|
hook: <K2_12 extends keyof Required<T2_1>[K_6]>(key2: K2_12) => {
|
|
@@ -98,7 +95,6 @@ declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTy
|
|
|
98
95
|
hasParentCtx: () => boolean;
|
|
99
96
|
getParentCtx: <T2_2 = T2_1>() => {
|
|
100
97
|
getCtx: () => T2_2;
|
|
101
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
102
98
|
store: <K_9 extends keyof T2_2>(key: K_9) => {
|
|
103
99
|
value: T2_2[K_9];
|
|
104
100
|
hook: <K2_18 extends keyof Required<T2_2>[K_9]>(key2: K2_18) => {
|
|
@@ -119,7 +115,6 @@ declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTy
|
|
|
119
115
|
hasParentCtx: () => boolean;
|
|
120
116
|
getParentCtx: <T2_3 = T2_2>() => {
|
|
121
117
|
getCtx: () => T2_3;
|
|
122
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
123
118
|
store: <K_12 extends keyof T2_3>(key: K_12) => {
|
|
124
119
|
value: T2_3[K_12];
|
|
125
120
|
hook: <K2_24 extends keyof Required<T2_3>[K_12]>(key2: K2_24) => {
|
|
@@ -140,7 +135,6 @@ declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTy
|
|
|
140
135
|
hasParentCtx: () => boolean;
|
|
141
136
|
getParentCtx: <T2_4 = T2_3>() => {
|
|
142
137
|
getCtx: () => T2_4;
|
|
143
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
144
138
|
store: <K_15 extends keyof T2_4>(key: K_15) => {
|
|
145
139
|
value: T2_4[K_15];
|
|
146
140
|
hook: <K2_30 extends keyof Required<T2_4>[K_15]>(key2: K2_30) => {
|
|
@@ -161,7 +155,6 @@ declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTy
|
|
|
161
155
|
hasParentCtx: () => boolean;
|
|
162
156
|
getParentCtx: <T2_5 = T2_4>() => {
|
|
163
157
|
getCtx: () => T2_5;
|
|
164
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
165
158
|
store: <K_18 extends keyof T2_5>(key: K_18) => {
|
|
166
159
|
value: T2_5[K_18];
|
|
167
160
|
hook: <K2_36 extends keyof Required<T2_5>[K_18]>(key2: K2_36) => {
|
|
@@ -182,7 +175,6 @@ declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTy
|
|
|
182
175
|
hasParentCtx: () => boolean;
|
|
183
176
|
getParentCtx: <T2_6 = T2_5>() => {
|
|
184
177
|
getCtx: () => T2_6;
|
|
185
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
186
178
|
store: <K_21 extends keyof T2_6>(key: K_21) => {
|
|
187
179
|
value: T2_6[K_21];
|
|
188
180
|
hook: <K2_42 extends keyof Required<T2_6>[K_21]>(key2: K2_42) => {
|
|
@@ -203,7 +195,6 @@ declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTy
|
|
|
203
195
|
hasParentCtx: () => boolean;
|
|
204
196
|
getParentCtx: <T2_7 = T2_6>() => {
|
|
205
197
|
getCtx: () => T2_7;
|
|
206
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
207
198
|
store: <K_24 extends keyof T2_7>(key: K_24) => {
|
|
208
199
|
value: T2_7[K_24];
|
|
209
200
|
hook: <K2_48 extends keyof Required<T2_7>[K_24]>(key2: K2_48) => {
|
|
@@ -224,7 +215,6 @@ declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTy
|
|
|
224
215
|
hasParentCtx: () => boolean;
|
|
225
216
|
getParentCtx: <T2_8 = T2_7>() => {
|
|
226
217
|
getCtx: () => T2_8;
|
|
227
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
228
218
|
store: <K_27 extends keyof T2_8>(key: K_27) => {
|
|
229
219
|
value: T2_8[K_27];
|
|
230
220
|
hook: <K2_54 extends keyof Required<T2_8>[K_27]>(key2: K2_54) => {
|
|
@@ -245,7 +235,6 @@ declare function useAsyncEventContext<S = TEmpty, EventType = TEmpty>(expectedTy
|
|
|
245
235
|
hasParentCtx: () => boolean;
|
|
246
236
|
getParentCtx: <T2_9 = T2_8>() => {
|
|
247
237
|
getCtx: () => T2_9;
|
|
248
|
-
endEvent: (abortReason?: string | undefined) => void;
|
|
249
238
|
store: <K_30 extends keyof T2_9>(key: K_30) => {
|
|
250
239
|
value: T2_9[K_30];
|
|
251
240
|
hook: <K2_60 extends keyof Required<T2_9>[K_30]>(key2: K2_60) => {
|
|
@@ -315,9 +304,21 @@ declare class Hookable {
|
|
|
315
304
|
}
|
|
316
305
|
|
|
317
306
|
declare class EventContextHooks extends Hookable {
|
|
307
|
+
/**
|
|
308
|
+
* SHould be fired right after a new context is created
|
|
309
|
+
*/
|
|
318
310
|
fireStartEvent(eventType: string): void;
|
|
311
|
+
/**
|
|
312
|
+
* Should be fired at the very end of event processing
|
|
313
|
+
*/
|
|
319
314
|
fireEndEvent(eventType: string, abortReason?: string): void;
|
|
315
|
+
/**
|
|
316
|
+
* Fires when a new context was just created
|
|
317
|
+
*/
|
|
320
318
|
onStartEvent(cb: (eventType: string) => void): () => void;
|
|
319
|
+
/**
|
|
320
|
+
* Fires when event was processed
|
|
321
|
+
*/
|
|
321
322
|
onEndEvent(cb: (eventType: string, abortReason?: string) => void): () => void;
|
|
322
323
|
}
|
|
323
324
|
declare const eventContextHooks: EventContextHooks;
|
|
@@ -330,4 +331,4 @@ type THook<T = string, K extends PropertyKey = 'value'> = {
|
|
|
330
331
|
[key in K]: T;
|
|
331
332
|
};
|
|
332
333
|
|
|
333
|
-
export { EventLogger, type TEmpty, type TEventLoggerData, type TEventOptions, type TGenericContextStore, type TGenericEvent, type THook, asyncStorage, attachHook, createAsyncEventContext, eventContextHooks, useAsyncEventContext, useEventId, useEventLogger, useRouteParams };
|
|
334
|
+
export { EventLogger, Hookable, type TEmpty, type TEventLoggerData, type TEventOptions, type TGenericContextStore, type TGenericEvent, type THook, asyncStorage, attachHook, createAsyncEventContext, eventContextHooks, useAsyncEventContext, useEventId, useEventLogger, useRouteParams };
|
package/dist/index.mjs
CHANGED
|
@@ -69,17 +69,17 @@ function createAsyncEventContext(data) {
|
|
|
69
69
|
if (result instanceof Promise) {
|
|
70
70
|
result
|
|
71
71
|
.then(r => {
|
|
72
|
-
|
|
72
|
+
fireEndEvent(r);
|
|
73
73
|
return r;
|
|
74
74
|
})
|
|
75
75
|
.catch(error => {
|
|
76
|
-
|
|
76
|
+
fireEndEvent(error);
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
else {
|
|
80
|
-
|
|
80
|
+
fireEndEvent(result);
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function fireEndEvent(output) {
|
|
83
83
|
if (!newContext._ended) {
|
|
84
84
|
if (output instanceof Error) {
|
|
85
85
|
asyncStorage.run(newContext, () => {
|
|
@@ -192,12 +192,6 @@ function _getCtxHelpers(cc) {
|
|
|
192
192
|
const hasParentCtx = () => !!cc.parentCtx;
|
|
193
193
|
return {
|
|
194
194
|
getCtx,
|
|
195
|
-
endEvent: (abortReason) => {
|
|
196
|
-
if (cc && !cc._ended) {
|
|
197
|
-
cc._ended = true;
|
|
198
|
-
eventContextHooks.fireEndEvent(cc.event.type, abortReason);
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
195
|
store,
|
|
202
196
|
getStore: get,
|
|
203
197
|
setStore: set,
|
|
@@ -264,4 +258,4 @@ function useRouteParams() {
|
|
|
264
258
|
};
|
|
265
259
|
}
|
|
266
260
|
|
|
267
|
-
export { EventLogger, asyncStorage, attachHook, createAsyncEventContext, eventContextHooks, useAsyncEventContext, useEventId, useEventLogger, useRouteParams };
|
|
261
|
+
export { EventLogger, Hookable, asyncStorage, attachHook, createAsyncEventContext, eventContextHooks, useAsyncEventContext, useEventId, useEventLogger, useRouteParams };
|