fastevent 2.2.8 → 2.2.10
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/eventbus/index.d.mts +59 -83
- package/dist/eventbus/index.d.ts +59 -83
- package/dist/eventbus/index.js +1 -1
- package/dist/eventbus/index.js.map +1 -1
- package/dist/eventbus/index.mjs +1 -1
- package/dist/eventbus/index.mjs.map +1 -1
- package/dist/executors/index.d.mts +2 -2
- package/dist/executors/index.d.ts +2 -2
- package/dist/index.d.mts +58 -82
- package/dist/index.d.ts +58 -82
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/pipes/index.d.mts +2 -2
- package/dist/pipes/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -2,13 +2,13 @@ interface FastEventMeta {
|
|
|
2
2
|
}
|
|
3
3
|
interface FastEventMessageExtends {
|
|
4
4
|
}
|
|
5
|
-
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
5
|
+
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
6
6
|
[K in keyof Events]: {
|
|
7
7
|
type: Exclude<K, number | symbol>;
|
|
8
8
|
payload: Events[K];
|
|
9
9
|
meta: FastEventMeta & M & Record<string, any>;
|
|
10
10
|
};
|
|
11
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
11
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
12
12
|
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<{
|
|
13
13
|
[K in T]: P;
|
|
14
14
|
}, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
@@ -2,13 +2,13 @@ interface FastEventMeta {
|
|
|
2
2
|
}
|
|
3
3
|
interface FastEventMessageExtends {
|
|
4
4
|
}
|
|
5
|
-
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
5
|
+
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
6
6
|
[K in keyof Events]: {
|
|
7
7
|
type: Exclude<K, number | symbol>;
|
|
8
8
|
payload: Events[K];
|
|
9
9
|
meta: FastEventMeta & M & Record<string, any>;
|
|
10
10
|
};
|
|
11
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
11
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
12
12
|
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<{
|
|
13
13
|
[K in T]: P;
|
|
14
14
|
}, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
type FastListenerPipe = (listener: TypedFastEventListener) => TypedFastEventListener;
|
|
2
2
|
|
|
3
|
+
type MergeUnion<T> = (T extends any ? (x: T) => void : never) extends (x: infer U) => void ? {
|
|
4
|
+
[K in keyof U]: U[K];
|
|
5
|
+
} : never;
|
|
6
|
+
type Split<S extends string, Delimiter extends string = '/'> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : [S];
|
|
7
|
+
type MatchSegment<Input extends string, Pattern extends string> = Pattern extends '*' ? true : Pattern extends '**' ? true : Input extends Pattern ? true : false;
|
|
8
|
+
type MatchPatternArray<InputArr extends string[], PatternArr extends string[]> = InputArr extends [infer InputHead extends string, ...infer InputTail extends string[]] ? PatternArr extends [infer PatternHead extends string, ...infer PatternTail extends string[]] ? PatternHead extends '**' ? MatchPatternArray<InputTail, PatternTail> extends true ? true : MatchPatternArray<InputTail, PatternArr> extends true ? true : MatchPatternArray<InputArr, PatternTail> extends true ? true : false : MatchSegment<InputHead, PatternHead> extends true ? MatchPatternArray<InputTail, PatternTail> : false : false : PatternArr extends [infer PatternHead extends string, ...infer PatternTail extends string[]] ? PatternHead extends '**' ? MatchPatternArray<InputArr, PatternTail> : false : true;
|
|
9
|
+
type MatchPattern<T extends string, Pattern extends string> = MatchPatternArray<Split<T>, Split<Pattern>> extends true ? {
|
|
10
|
+
[K in Pattern]: any;
|
|
11
|
+
} : never;
|
|
12
|
+
type Fallback$1<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
13
|
+
type MatchEventType<T extends string, Events extends Record<string, any>> = MergeUnion<Fallback$1<{
|
|
14
|
+
[K in keyof Events]: MatchPattern<T, K & string> extends never ? never : {
|
|
15
|
+
[P in K]: Events[K];
|
|
16
|
+
};
|
|
17
|
+
}[keyof Events] extends infer Result ? Result extends Record<string, any> ? Result : any : any, {
|
|
18
|
+
[K in T]: any;
|
|
19
|
+
}>>;
|
|
20
|
+
|
|
3
21
|
interface FastEventMeta {
|
|
4
22
|
}
|
|
5
23
|
interface FastEventMessageExtends {
|
|
@@ -9,34 +27,34 @@ type FastEventMessage<P = any, M extends Record<string, any> = Record<string, an
|
|
|
9
27
|
payload: P;
|
|
10
28
|
meta?: M & Partial<FastEventMeta>;
|
|
11
29
|
} & FastEventMessageExtends;
|
|
12
|
-
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
30
|
+
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
13
31
|
[K in keyof Events]: {
|
|
14
32
|
type: Exclude<K, number | symbol>;
|
|
15
33
|
payload: Events[K];
|
|
16
34
|
meta: FastEventMeta & M & Record<string, any>;
|
|
17
35
|
};
|
|
18
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
19
|
-
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
36
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
37
|
+
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
20
38
|
[K in keyof Events]: {
|
|
21
39
|
type: Exclude<K, number | symbol>;
|
|
22
40
|
payload: Events[K];
|
|
23
41
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
24
42
|
};
|
|
25
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
26
|
-
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
43
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
44
|
+
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
27
45
|
[K in keyof Events]: {
|
|
28
46
|
type: Exclude<K, number | symbol>;
|
|
29
47
|
payload?: Events[K];
|
|
30
48
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
31
49
|
};
|
|
32
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
50
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
33
51
|
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<{
|
|
34
52
|
[K in T]: P;
|
|
35
53
|
}, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
36
54
|
type TypedFastEventAnyListener<Events extends Record<string, any> = Record<string, any>, Meta = never, Context = any> = (this: Context, message: TypedFastEventMessage<Events, Meta>, args: FastEventListenerArgs<Meta>) => any | Promise<any>;
|
|
37
|
-
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> =
|
|
55
|
+
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> = {
|
|
38
56
|
[K in keyof Events]: TypedFastEventListener<Exclude<K, number | symbol>, Events[K], M, C>;
|
|
39
|
-
}
|
|
57
|
+
};
|
|
40
58
|
type FastEventListener<P = any, M extends Record<string, any> = Record<string, any>, T extends string = string> = (message: FastEventMessage<P, M, T>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
41
59
|
/**
|
|
42
60
|
* [
|
|
@@ -96,7 +114,7 @@ type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
|
96
114
|
onAddListener?: (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, Meta>) => boolean | FastEventSubscriber | void;
|
|
97
115
|
onRemoveListener?: (type: string, listener: TypedFastEventListener) => void;
|
|
98
116
|
onClearListeners?: () => void;
|
|
99
|
-
onListenerError?: (
|
|
117
|
+
onListenerError?: (error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta> | undefined) => void;
|
|
100
118
|
onBeforeExecuteListener?: (message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta>) => boolean | void | any[];
|
|
101
119
|
onAfterExecuteListener?: (message: TypedFastEventMessage<any, Meta>, returns: any[], listeners: FastListenerNode[]) => void;
|
|
102
120
|
/**
|
|
@@ -158,9 +176,7 @@ type OptionalItems<T, K extends keyof T> = Expand<Omit<T, K> & {
|
|
|
158
176
|
type DeepPartial<T> = {
|
|
159
177
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
160
178
|
};
|
|
161
|
-
type Fallback<T, F> = [
|
|
162
|
-
T
|
|
163
|
-
] extends [never] ? F : T extends undefined ? F : T;
|
|
179
|
+
type Fallback<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
164
180
|
type ChangeFieldType<Record, Name extends string, Type = any> = Expand<Omit<Record, Name> & {
|
|
165
181
|
[K in Name]: Type;
|
|
166
182
|
}>;
|
|
@@ -189,16 +205,7 @@ type Overloads<T> = Unique<T extends {
|
|
|
189
205
|
(...args: infer A6): infer R6;
|
|
190
206
|
(...args: infer A7): infer R7;
|
|
191
207
|
(...args: infer A8): infer R8;
|
|
192
|
-
} ? [
|
|
193
|
-
(...args: A1) => R1,
|
|
194
|
-
((...args: A2) => R2),
|
|
195
|
-
((...args: A3) => R3),
|
|
196
|
-
((...args: A4) => R4),
|
|
197
|
-
((...args: A5) => R5),
|
|
198
|
-
((...args: A6) => R6),
|
|
199
|
-
((...args: A7) => R7),
|
|
200
|
-
((...args: A8) => R8)
|
|
201
|
-
] : T extends {
|
|
208
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6, (...args: A7) => R7, (...args: A8) => R8] : T extends {
|
|
202
209
|
(...args: infer A1): infer R1;
|
|
203
210
|
(...args: infer A2): infer R2;
|
|
204
211
|
(...args: infer A3): infer R3;
|
|
@@ -206,76 +213,44 @@ type Overloads<T> = Unique<T extends {
|
|
|
206
213
|
(...args: infer A5): infer R5;
|
|
207
214
|
(...args: infer A6): infer R6;
|
|
208
215
|
(...args: infer A7): infer R7;
|
|
209
|
-
} ? [
|
|
210
|
-
(...args: A1) => R1,
|
|
211
|
-
((...args: A2) => R2),
|
|
212
|
-
((...args: A3) => R3),
|
|
213
|
-
((...args: A4) => R4),
|
|
214
|
-
((...args: A5) => R5),
|
|
215
|
-
((...args: A6) => R6),
|
|
216
|
-
((...args: A7) => R7)
|
|
217
|
-
] : T extends {
|
|
216
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6, (...args: A7) => R7] : T extends {
|
|
218
217
|
(...args: infer A1): infer R1;
|
|
219
218
|
(...args: infer A2): infer R2;
|
|
220
219
|
(...args: infer A3): infer R3;
|
|
221
220
|
(...args: infer A4): infer R4;
|
|
222
221
|
(...args: infer A5): infer R5;
|
|
223
222
|
(...args: infer A6): infer R6;
|
|
224
|
-
} ? [
|
|
225
|
-
(...args: A1) => R1,
|
|
226
|
-
((...args: A2) => R2),
|
|
227
|
-
((...args: A3) => R3),
|
|
228
|
-
((...args: A4) => R4),
|
|
229
|
-
((...args: A5) => R5),
|
|
230
|
-
((...args: A6) => R6)
|
|
231
|
-
] : T extends {
|
|
223
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6] : T extends {
|
|
232
224
|
(...args: infer A1): infer R1;
|
|
233
225
|
(...args: infer A2): infer R2;
|
|
234
226
|
(...args: infer A3): infer R3;
|
|
235
227
|
(...args: infer A4): infer R4;
|
|
236
228
|
(...args: infer A5): infer R5;
|
|
237
|
-
} ? [
|
|
238
|
-
(...args: A1) => R1,
|
|
239
|
-
((...args: A2) => R2),
|
|
240
|
-
((...args: A3) => R3),
|
|
241
|
-
((...args: A4) => R4),
|
|
242
|
-
((...args: A5) => R5)
|
|
243
|
-
] : T extends {
|
|
229
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T extends {
|
|
244
230
|
(...args: infer A1): infer R1;
|
|
245
231
|
(...args: infer A2): infer R2;
|
|
246
232
|
(...args: infer A3): infer R3;
|
|
247
233
|
(...args: infer A4): infer R4;
|
|
248
|
-
} ? [
|
|
249
|
-
(...args: A1) => R1,
|
|
250
|
-
((...args: A2) => R2),
|
|
251
|
-
((...args: A3) => R3),
|
|
252
|
-
((...args: A4) => R4)
|
|
253
|
-
] : T extends {
|
|
234
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4] : T extends {
|
|
254
235
|
(...args: infer A1): infer R1;
|
|
255
236
|
(...args: infer A2): infer R2;
|
|
256
237
|
(...args: infer A3): infer R3;
|
|
257
|
-
} ? [
|
|
258
|
-
((...args: A1) => R1),
|
|
259
|
-
((...args: A2) => R2),
|
|
260
|
-
((...args: A3) => R3)
|
|
261
|
-
] : T extends {
|
|
238
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3] : T extends {
|
|
262
239
|
(...args: infer A1): infer R1;
|
|
263
240
|
(...args: infer A2): infer R2;
|
|
264
|
-
} ? [
|
|
265
|
-
((...args: A1) => R1),
|
|
266
|
-
((...args: A2) => R2)
|
|
267
|
-
] : T extends {
|
|
241
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2] : T extends {
|
|
268
242
|
(...args: infer A1): infer R1;
|
|
269
|
-
} ? [
|
|
270
|
-
(...args: A1) => R1
|
|
271
|
-
] : [
|
|
272
|
-
T
|
|
273
|
-
]>;
|
|
243
|
+
} ? [(...args: A1) => R1] : [T]>;
|
|
274
244
|
type Dict<V = any> = Record<Exclude<string, number | symbol>, V>;
|
|
275
245
|
type Union<T> = T extends infer O ? {
|
|
276
246
|
[K in keyof O]: O[K];
|
|
277
247
|
} : never;
|
|
278
248
|
|
|
249
|
+
type RecordValues<R extends Record<string, any>> = R[keyof R];
|
|
250
|
+
type RecordPrefix<P extends string, R extends Record<string, any>> = {
|
|
251
|
+
[K in keyof R as K extends `${P}/${infer S}` ? S : never]: R[K];
|
|
252
|
+
};
|
|
253
|
+
|
|
279
254
|
type FastListenerExecutor = (listeners: FastListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (listener: TypedFastEventListener, message: TypedFastEventMessage, args: FastEventListenerArgs, catchErrors?: boolean) => Promise<any> | any) => Promise<any[]> | any[];
|
|
280
255
|
|
|
281
256
|
type FastEventScopeOptions<Meta = Record<string, any>, Context = never> = {
|
|
@@ -327,7 +302,7 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
327
302
|
on<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
328
303
|
on(type: '**', options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
329
304
|
on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
330
|
-
on<T extends string>(type: T, listener: TypedFastEventListener<
|
|
305
|
+
on<T extends string>(type: T, listener: TypedFastEventListener<Exclude<keyof MatchEventType<T, Events>, number | symbol>, RecordValues<MatchEventType<T, Events>>, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
331
306
|
on(type: '**', listener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
332
307
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
333
308
|
once<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
@@ -347,17 +322,17 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
347
322
|
emit(type: Types, directive: symbol): void;
|
|
348
323
|
emit(type: string, directive: symbol): void;
|
|
349
324
|
emit<R = any, T extends Types = Types>(type: T, payload?: Events[T], retain?: boolean): R[];
|
|
350
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
325
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, retain?: boolean): R[];
|
|
351
326
|
emit<R = any>(type: Types, payload?: Events[Types], options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
352
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
327
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
353
328
|
emit<R = any>(message: FastEventEmitMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
354
329
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
355
330
|
[K in T]: K extends Types ? Events[K] : any;
|
|
356
331
|
}, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
357
|
-
emitAsync<R = any>(type:
|
|
358
|
-
emitAsync<R = any>(type:
|
|
359
|
-
emitAsync<R = any>(type:
|
|
360
|
-
emitAsync<R = any>(type:
|
|
332
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: Events[T], retain?: boolean): Promise<[R | Error][]>;
|
|
333
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : any, retain?: boolean): Promise<[R | Error][]>;
|
|
334
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: Events[T], options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
335
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : any, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
361
336
|
emitAsync<R = any>(message: TypedFastEventMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
362
337
|
waitFor<T extends Types>(type: T, timeout?: number): Promise<TypedFastEventMessage<{
|
|
363
338
|
[key in T]: Events[T];
|
|
@@ -523,7 +498,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
523
498
|
on<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
524
499
|
on(type: '**', options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
525
500
|
on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
526
|
-
on<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
501
|
+
on<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
527
502
|
on(type: '**', listener: TypedFastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
528
503
|
/**
|
|
529
504
|
* 注册一次性事件监听器
|
|
@@ -549,7 +524,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
549
524
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
550
525
|
once<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
551
526
|
once<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
552
|
-
once<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
527
|
+
once<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
553
528
|
/**
|
|
554
529
|
* 注册一个监听器,用于监听所有事件
|
|
555
530
|
* @param listener 事件监听器函数,可以接收任意类型的事件数据
|
|
@@ -738,13 +713,13 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
738
713
|
emit<T extends Types = Types>(type: T, directive: symbol): any[];
|
|
739
714
|
emit(type: string, directive: symbol): any[];
|
|
740
715
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], retain?: boolean): R[];
|
|
741
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
716
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, retain?: boolean): R[];
|
|
742
717
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
743
718
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
744
719
|
}, Meta>, retain?: boolean): R[];
|
|
745
720
|
emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): R[];
|
|
746
721
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], options?: FastEventListenerArgs<Meta>): R[];
|
|
747
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
722
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, options?: FastEventListenerArgs<Meta>): R[];
|
|
748
723
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
749
724
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
750
725
|
}, Meta>, options?: FastEventListenerArgs<Meta>): R[];
|
|
@@ -785,14 +760,14 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
785
760
|
* });
|
|
786
761
|
* ```
|
|
787
762
|
*/
|
|
788
|
-
emitAsync<R = any>(type:
|
|
789
|
-
emitAsync<R = any>(type:
|
|
763
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], retain?: boolean): Promise<[R | Error][]>;
|
|
764
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : any, retain?: boolean): Promise<[R | Error][]>;
|
|
790
765
|
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
791
766
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
792
767
|
}, Meta>, retain?: boolean): Promise<[R | Error][]>;
|
|
793
768
|
emitAsync<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): Promise<[R | Error][]>;
|
|
794
|
-
emitAsync<R = any>(type:
|
|
795
|
-
emitAsync<R = any>(type:
|
|
769
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : any, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
770
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
796
771
|
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
797
772
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
798
773
|
}, Meta>, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
@@ -877,6 +852,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
877
852
|
* userEvents.offAll(); // 清理 'user' 前缀下的所有事件
|
|
878
853
|
* ```
|
|
879
854
|
*/
|
|
855
|
+
scope<P extends string>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta, Context>>): FastEventScope<ScopeEvents<AllEvents, P>, Meta, Context>;
|
|
880
856
|
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>;
|
|
881
857
|
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context, ScopeObject extends FastEventScope<any, any, any> = FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>>(prefix: P, scopeObj: ScopeObject, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): ScopeObject;
|
|
882
858
|
}
|
|
@@ -978,4 +954,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
978
954
|
|
|
979
955
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
980
956
|
|
|
981
|
-
export { AbortError, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventDirectives, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListenerMeta, type FastListenerNode, type FastListeners, type Merge, type ObjectKeys, type OptionalItems, type Overloads, type OverrideOptions, type PickScopeEvents, QueueOverflowError, type RequiredItems, type ScopeEvents, TimeoutError, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, UnboundError, type Union, type Unique, __FastEventScope__, __FastEvent__, __expandable__, expandable, isClass, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
|
|
957
|
+
export { AbortError, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventDirectives, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListenerMeta, type FastListenerNode, type FastListeners, type MatchEventType, type Merge, type MergeUnion, type ObjectKeys, type OptionalItems, type Overloads, type OverrideOptions, type PickScopeEvents, QueueOverflowError, type RecordPrefix, type RecordValues, type RequiredItems, type ScopeEvents, TimeoutError, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, UnboundError, type Union, type Unique, __FastEventScope__, __FastEvent__, __expandable__, expandable, isClass, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
type FastListenerPipe = (listener: TypedFastEventListener) => TypedFastEventListener;
|
|
2
2
|
|
|
3
|
+
type MergeUnion<T> = (T extends any ? (x: T) => void : never) extends (x: infer U) => void ? {
|
|
4
|
+
[K in keyof U]: U[K];
|
|
5
|
+
} : never;
|
|
6
|
+
type Split<S extends string, Delimiter extends string = '/'> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : [S];
|
|
7
|
+
type MatchSegment<Input extends string, Pattern extends string> = Pattern extends '*' ? true : Pattern extends '**' ? true : Input extends Pattern ? true : false;
|
|
8
|
+
type MatchPatternArray<InputArr extends string[], PatternArr extends string[]> = InputArr extends [infer InputHead extends string, ...infer InputTail extends string[]] ? PatternArr extends [infer PatternHead extends string, ...infer PatternTail extends string[]] ? PatternHead extends '**' ? MatchPatternArray<InputTail, PatternTail> extends true ? true : MatchPatternArray<InputTail, PatternArr> extends true ? true : MatchPatternArray<InputArr, PatternTail> extends true ? true : false : MatchSegment<InputHead, PatternHead> extends true ? MatchPatternArray<InputTail, PatternTail> : false : false : PatternArr extends [infer PatternHead extends string, ...infer PatternTail extends string[]] ? PatternHead extends '**' ? MatchPatternArray<InputArr, PatternTail> : false : true;
|
|
9
|
+
type MatchPattern<T extends string, Pattern extends string> = MatchPatternArray<Split<T>, Split<Pattern>> extends true ? {
|
|
10
|
+
[K in Pattern]: any;
|
|
11
|
+
} : never;
|
|
12
|
+
type Fallback$1<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
13
|
+
type MatchEventType<T extends string, Events extends Record<string, any>> = MergeUnion<Fallback$1<{
|
|
14
|
+
[K in keyof Events]: MatchPattern<T, K & string> extends never ? never : {
|
|
15
|
+
[P in K]: Events[K];
|
|
16
|
+
};
|
|
17
|
+
}[keyof Events] extends infer Result ? Result extends Record<string, any> ? Result : any : any, {
|
|
18
|
+
[K in T]: any;
|
|
19
|
+
}>>;
|
|
20
|
+
|
|
3
21
|
interface FastEventMeta {
|
|
4
22
|
}
|
|
5
23
|
interface FastEventMessageExtends {
|
|
@@ -9,34 +27,34 @@ type FastEventMessage<P = any, M extends Record<string, any> = Record<string, an
|
|
|
9
27
|
payload: P;
|
|
10
28
|
meta?: M & Partial<FastEventMeta>;
|
|
11
29
|
} & FastEventMessageExtends;
|
|
12
|
-
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
30
|
+
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
13
31
|
[K in keyof Events]: {
|
|
14
32
|
type: Exclude<K, number | symbol>;
|
|
15
33
|
payload: Events[K];
|
|
16
34
|
meta: FastEventMeta & M & Record<string, any>;
|
|
17
35
|
};
|
|
18
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
19
|
-
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
36
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
37
|
+
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
20
38
|
[K in keyof Events]: {
|
|
21
39
|
type: Exclude<K, number | symbol>;
|
|
22
40
|
payload: Events[K];
|
|
23
41
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
24
42
|
};
|
|
25
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
26
|
-
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
43
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
44
|
+
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
27
45
|
[K in keyof Events]: {
|
|
28
46
|
type: Exclude<K, number | symbol>;
|
|
29
47
|
payload?: Events[K];
|
|
30
48
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
31
49
|
};
|
|
32
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
50
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
33
51
|
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<{
|
|
34
52
|
[K in T]: P;
|
|
35
53
|
}, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
36
54
|
type TypedFastEventAnyListener<Events extends Record<string, any> = Record<string, any>, Meta = never, Context = any> = (this: Context, message: TypedFastEventMessage<Events, Meta>, args: FastEventListenerArgs<Meta>) => any | Promise<any>;
|
|
37
|
-
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> =
|
|
55
|
+
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> = {
|
|
38
56
|
[K in keyof Events]: TypedFastEventListener<Exclude<K, number | symbol>, Events[K], M, C>;
|
|
39
|
-
}
|
|
57
|
+
};
|
|
40
58
|
type FastEventListener<P = any, M extends Record<string, any> = Record<string, any>, T extends string = string> = (message: FastEventMessage<P, M, T>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
41
59
|
/**
|
|
42
60
|
* [
|
|
@@ -96,7 +114,7 @@ type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
|
96
114
|
onAddListener?: (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, Meta>) => boolean | FastEventSubscriber | void;
|
|
97
115
|
onRemoveListener?: (type: string, listener: TypedFastEventListener) => void;
|
|
98
116
|
onClearListeners?: () => void;
|
|
99
|
-
onListenerError?: (
|
|
117
|
+
onListenerError?: (error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta> | undefined) => void;
|
|
100
118
|
onBeforeExecuteListener?: (message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta>) => boolean | void | any[];
|
|
101
119
|
onAfterExecuteListener?: (message: TypedFastEventMessage<any, Meta>, returns: any[], listeners: FastListenerNode[]) => void;
|
|
102
120
|
/**
|
|
@@ -158,9 +176,7 @@ type OptionalItems<T, K extends keyof T> = Expand<Omit<T, K> & {
|
|
|
158
176
|
type DeepPartial<T> = {
|
|
159
177
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
160
178
|
};
|
|
161
|
-
type Fallback<T, F> = [
|
|
162
|
-
T
|
|
163
|
-
] extends [never] ? F : T extends undefined ? F : T;
|
|
179
|
+
type Fallback<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
164
180
|
type ChangeFieldType<Record, Name extends string, Type = any> = Expand<Omit<Record, Name> & {
|
|
165
181
|
[K in Name]: Type;
|
|
166
182
|
}>;
|
|
@@ -189,16 +205,7 @@ type Overloads<T> = Unique<T extends {
|
|
|
189
205
|
(...args: infer A6): infer R6;
|
|
190
206
|
(...args: infer A7): infer R7;
|
|
191
207
|
(...args: infer A8): infer R8;
|
|
192
|
-
} ? [
|
|
193
|
-
(...args: A1) => R1,
|
|
194
|
-
((...args: A2) => R2),
|
|
195
|
-
((...args: A3) => R3),
|
|
196
|
-
((...args: A4) => R4),
|
|
197
|
-
((...args: A5) => R5),
|
|
198
|
-
((...args: A6) => R6),
|
|
199
|
-
((...args: A7) => R7),
|
|
200
|
-
((...args: A8) => R8)
|
|
201
|
-
] : T extends {
|
|
208
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6, (...args: A7) => R7, (...args: A8) => R8] : T extends {
|
|
202
209
|
(...args: infer A1): infer R1;
|
|
203
210
|
(...args: infer A2): infer R2;
|
|
204
211
|
(...args: infer A3): infer R3;
|
|
@@ -206,76 +213,44 @@ type Overloads<T> = Unique<T extends {
|
|
|
206
213
|
(...args: infer A5): infer R5;
|
|
207
214
|
(...args: infer A6): infer R6;
|
|
208
215
|
(...args: infer A7): infer R7;
|
|
209
|
-
} ? [
|
|
210
|
-
(...args: A1) => R1,
|
|
211
|
-
((...args: A2) => R2),
|
|
212
|
-
((...args: A3) => R3),
|
|
213
|
-
((...args: A4) => R4),
|
|
214
|
-
((...args: A5) => R5),
|
|
215
|
-
((...args: A6) => R6),
|
|
216
|
-
((...args: A7) => R7)
|
|
217
|
-
] : T extends {
|
|
216
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6, (...args: A7) => R7] : T extends {
|
|
218
217
|
(...args: infer A1): infer R1;
|
|
219
218
|
(...args: infer A2): infer R2;
|
|
220
219
|
(...args: infer A3): infer R3;
|
|
221
220
|
(...args: infer A4): infer R4;
|
|
222
221
|
(...args: infer A5): infer R5;
|
|
223
222
|
(...args: infer A6): infer R6;
|
|
224
|
-
} ? [
|
|
225
|
-
(...args: A1) => R1,
|
|
226
|
-
((...args: A2) => R2),
|
|
227
|
-
((...args: A3) => R3),
|
|
228
|
-
((...args: A4) => R4),
|
|
229
|
-
((...args: A5) => R5),
|
|
230
|
-
((...args: A6) => R6)
|
|
231
|
-
] : T extends {
|
|
223
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6] : T extends {
|
|
232
224
|
(...args: infer A1): infer R1;
|
|
233
225
|
(...args: infer A2): infer R2;
|
|
234
226
|
(...args: infer A3): infer R3;
|
|
235
227
|
(...args: infer A4): infer R4;
|
|
236
228
|
(...args: infer A5): infer R5;
|
|
237
|
-
} ? [
|
|
238
|
-
(...args: A1) => R1,
|
|
239
|
-
((...args: A2) => R2),
|
|
240
|
-
((...args: A3) => R3),
|
|
241
|
-
((...args: A4) => R4),
|
|
242
|
-
((...args: A5) => R5)
|
|
243
|
-
] : T extends {
|
|
229
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T extends {
|
|
244
230
|
(...args: infer A1): infer R1;
|
|
245
231
|
(...args: infer A2): infer R2;
|
|
246
232
|
(...args: infer A3): infer R3;
|
|
247
233
|
(...args: infer A4): infer R4;
|
|
248
|
-
} ? [
|
|
249
|
-
(...args: A1) => R1,
|
|
250
|
-
((...args: A2) => R2),
|
|
251
|
-
((...args: A3) => R3),
|
|
252
|
-
((...args: A4) => R4)
|
|
253
|
-
] : T extends {
|
|
234
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4] : T extends {
|
|
254
235
|
(...args: infer A1): infer R1;
|
|
255
236
|
(...args: infer A2): infer R2;
|
|
256
237
|
(...args: infer A3): infer R3;
|
|
257
|
-
} ? [
|
|
258
|
-
((...args: A1) => R1),
|
|
259
|
-
((...args: A2) => R2),
|
|
260
|
-
((...args: A3) => R3)
|
|
261
|
-
] : T extends {
|
|
238
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3] : T extends {
|
|
262
239
|
(...args: infer A1): infer R1;
|
|
263
240
|
(...args: infer A2): infer R2;
|
|
264
|
-
} ? [
|
|
265
|
-
((...args: A1) => R1),
|
|
266
|
-
((...args: A2) => R2)
|
|
267
|
-
] : T extends {
|
|
241
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2] : T extends {
|
|
268
242
|
(...args: infer A1): infer R1;
|
|
269
|
-
} ? [
|
|
270
|
-
(...args: A1) => R1
|
|
271
|
-
] : [
|
|
272
|
-
T
|
|
273
|
-
]>;
|
|
243
|
+
} ? [(...args: A1) => R1] : [T]>;
|
|
274
244
|
type Dict<V = any> = Record<Exclude<string, number | symbol>, V>;
|
|
275
245
|
type Union<T> = T extends infer O ? {
|
|
276
246
|
[K in keyof O]: O[K];
|
|
277
247
|
} : never;
|
|
278
248
|
|
|
249
|
+
type RecordValues<R extends Record<string, any>> = R[keyof R];
|
|
250
|
+
type RecordPrefix<P extends string, R extends Record<string, any>> = {
|
|
251
|
+
[K in keyof R as K extends `${P}/${infer S}` ? S : never]: R[K];
|
|
252
|
+
};
|
|
253
|
+
|
|
279
254
|
type FastListenerExecutor = (listeners: FastListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (listener: TypedFastEventListener, message: TypedFastEventMessage, args: FastEventListenerArgs, catchErrors?: boolean) => Promise<any> | any) => Promise<any[]> | any[];
|
|
280
255
|
|
|
281
256
|
type FastEventScopeOptions<Meta = Record<string, any>, Context = never> = {
|
|
@@ -327,7 +302,7 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
327
302
|
on<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
328
303
|
on(type: '**', options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
329
304
|
on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
330
|
-
on<T extends string>(type: T, listener: TypedFastEventListener<
|
|
305
|
+
on<T extends string>(type: T, listener: TypedFastEventListener<Exclude<keyof MatchEventType<T, Events>, number | symbol>, RecordValues<MatchEventType<T, Events>>, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
331
306
|
on(type: '**', listener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
332
307
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
333
308
|
once<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
@@ -347,17 +322,17 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
347
322
|
emit(type: Types, directive: symbol): void;
|
|
348
323
|
emit(type: string, directive: symbol): void;
|
|
349
324
|
emit<R = any, T extends Types = Types>(type: T, payload?: Events[T], retain?: boolean): R[];
|
|
350
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
325
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, retain?: boolean): R[];
|
|
351
326
|
emit<R = any>(type: Types, payload?: Events[Types], options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
352
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
327
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
353
328
|
emit<R = any>(message: FastEventEmitMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
354
329
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
355
330
|
[K in T]: K extends Types ? Events[K] : any;
|
|
356
331
|
}, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
357
|
-
emitAsync<R = any>(type:
|
|
358
|
-
emitAsync<R = any>(type:
|
|
359
|
-
emitAsync<R = any>(type:
|
|
360
|
-
emitAsync<R = any>(type:
|
|
332
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: Events[T], retain?: boolean): Promise<[R | Error][]>;
|
|
333
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : any, retain?: boolean): Promise<[R | Error][]>;
|
|
334
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: Events[T], options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
335
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : any, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
361
336
|
emitAsync<R = any>(message: TypedFastEventMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
362
337
|
waitFor<T extends Types>(type: T, timeout?: number): Promise<TypedFastEventMessage<{
|
|
363
338
|
[key in T]: Events[T];
|
|
@@ -523,7 +498,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
523
498
|
on<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
524
499
|
on(type: '**', options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
525
500
|
on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
526
|
-
on<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
501
|
+
on<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
527
502
|
on(type: '**', listener: TypedFastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
528
503
|
/**
|
|
529
504
|
* 注册一次性事件监听器
|
|
@@ -549,7 +524,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
549
524
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
550
525
|
once<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
551
526
|
once<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
552
|
-
once<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
527
|
+
once<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
553
528
|
/**
|
|
554
529
|
* 注册一个监听器,用于监听所有事件
|
|
555
530
|
* @param listener 事件监听器函数,可以接收任意类型的事件数据
|
|
@@ -738,13 +713,13 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
738
713
|
emit<T extends Types = Types>(type: T, directive: symbol): any[];
|
|
739
714
|
emit(type: string, directive: symbol): any[];
|
|
740
715
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], retain?: boolean): R[];
|
|
741
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
716
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, retain?: boolean): R[];
|
|
742
717
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
743
718
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
744
719
|
}, Meta>, retain?: boolean): R[];
|
|
745
720
|
emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): R[];
|
|
746
721
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], options?: FastEventListenerArgs<Meta>): R[];
|
|
747
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
722
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, options?: FastEventListenerArgs<Meta>): R[];
|
|
748
723
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
749
724
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
750
725
|
}, Meta>, options?: FastEventListenerArgs<Meta>): R[];
|
|
@@ -785,14 +760,14 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
785
760
|
* });
|
|
786
761
|
* ```
|
|
787
762
|
*/
|
|
788
|
-
emitAsync<R = any>(type:
|
|
789
|
-
emitAsync<R = any>(type:
|
|
763
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], retain?: boolean): Promise<[R | Error][]>;
|
|
764
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : any, retain?: boolean): Promise<[R | Error][]>;
|
|
790
765
|
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
791
766
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
792
767
|
}, Meta>, retain?: boolean): Promise<[R | Error][]>;
|
|
793
768
|
emitAsync<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): Promise<[R | Error][]>;
|
|
794
|
-
emitAsync<R = any>(type:
|
|
795
|
-
emitAsync<R = any>(type:
|
|
769
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : any, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
770
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
796
771
|
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
797
772
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
798
773
|
}, Meta>, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
@@ -877,6 +852,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
877
852
|
* userEvents.offAll(); // 清理 'user' 前缀下的所有事件
|
|
878
853
|
* ```
|
|
879
854
|
*/
|
|
855
|
+
scope<P extends string>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta, Context>>): FastEventScope<ScopeEvents<AllEvents, P>, Meta, Context>;
|
|
880
856
|
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>;
|
|
881
857
|
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context, ScopeObject extends FastEventScope<any, any, any> = FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>>(prefix: P, scopeObj: ScopeObject, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): ScopeObject;
|
|
882
858
|
}
|
|
@@ -978,4 +954,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
978
954
|
|
|
979
955
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
980
956
|
|
|
981
|
-
export { AbortError, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventDirectives, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListenerMeta, type FastListenerNode, type FastListeners, type Merge, type ObjectKeys, type OptionalItems, type Overloads, type OverrideOptions, type PickScopeEvents, QueueOverflowError, type RequiredItems, type ScopeEvents, TimeoutError, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, UnboundError, type Union, type Unique, __FastEventScope__, __FastEvent__, __expandable__, expandable, isClass, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
|
|
957
|
+
export { AbortError, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventDirectives, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListenerMeta, type FastListenerNode, type FastListeners, type MatchEventType, type Merge, type MergeUnion, type ObjectKeys, type OptionalItems, type Overloads, type OverrideOptions, type PickScopeEvents, QueueOverflowError, type RecordPrefix, type RecordValues, type RequiredItems, type ScopeEvents, TimeoutError, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, UnboundError, type Union, type Unique, __FastEventScope__, __FastEvent__, __expandable__, expandable, isClass, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
|