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,6 +2,24 @@ type FastListenerExecutor = (listeners: FastListenerMeta[], message: TypedFastEv
|
|
|
2
2
|
|
|
3
3
|
type FastListenerPipe = (listener: TypedFastEventListener) => TypedFastEventListener;
|
|
4
4
|
|
|
5
|
+
type MergeUnion<T> = (T extends any ? (x: T) => void : never) extends (x: infer U) => void ? {
|
|
6
|
+
[K in keyof U]: U[K];
|
|
7
|
+
} : never;
|
|
8
|
+
type Split<S extends string, Delimiter extends string = '/'> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : [S];
|
|
9
|
+
type MatchSegment<Input extends string, Pattern extends string> = Pattern extends '*' ? true : Pattern extends '**' ? true : Input extends Pattern ? true : false;
|
|
10
|
+
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;
|
|
11
|
+
type MatchPattern<T extends string, Pattern extends string> = MatchPatternArray<Split<T>, Split<Pattern>> extends true ? {
|
|
12
|
+
[K in Pattern]: any;
|
|
13
|
+
} : never;
|
|
14
|
+
type Fallback$1<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
15
|
+
type MatchEventType<T extends string, Events extends Record<string, any>> = MergeUnion<Fallback$1<{
|
|
16
|
+
[K in keyof Events]: MatchPattern<T, K & string> extends never ? never : {
|
|
17
|
+
[P in K]: Events[K];
|
|
18
|
+
};
|
|
19
|
+
}[keyof Events] extends infer Result ? Result extends Record<string, any> ? Result : any : any, {
|
|
20
|
+
[K in T]: any;
|
|
21
|
+
}>>;
|
|
22
|
+
|
|
5
23
|
interface FastEventMeta {
|
|
6
24
|
}
|
|
7
25
|
interface FastEventMessageExtends {
|
|
@@ -11,34 +29,34 @@ type FastEventMessage<P = any, M extends Record<string, any> = Record<string, an
|
|
|
11
29
|
payload: P;
|
|
12
30
|
meta?: M & Partial<FastEventMeta>;
|
|
13
31
|
} & FastEventMessageExtends;
|
|
14
|
-
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
32
|
+
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
15
33
|
[K in keyof Events]: {
|
|
16
34
|
type: Exclude<K, number | symbol>;
|
|
17
35
|
payload: Events[K];
|
|
18
36
|
meta: FastEventMeta & M & Record<string, any>;
|
|
19
37
|
};
|
|
20
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
21
|
-
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
38
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
39
|
+
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
22
40
|
[K in keyof Events]: {
|
|
23
41
|
type: Exclude<K, number | symbol>;
|
|
24
42
|
payload: Events[K];
|
|
25
43
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
26
44
|
};
|
|
27
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
28
|
-
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
45
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
46
|
+
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
29
47
|
[K in keyof Events]: {
|
|
30
48
|
type: Exclude<K, number | symbol>;
|
|
31
49
|
payload?: Events[K];
|
|
32
50
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
33
51
|
};
|
|
34
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
52
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
35
53
|
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<{
|
|
36
54
|
[K in T]: P;
|
|
37
55
|
}, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
38
56
|
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>;
|
|
39
|
-
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> =
|
|
57
|
+
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> = {
|
|
40
58
|
[K in keyof Events]: TypedFastEventListener<Exclude<K, number | symbol>, Events[K], M, C>;
|
|
41
|
-
}
|
|
59
|
+
};
|
|
42
60
|
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>;
|
|
43
61
|
/**
|
|
44
62
|
* [
|
|
@@ -98,7 +116,7 @@ type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
|
98
116
|
onAddListener?: (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, Meta>) => boolean | FastEventSubscriber | void;
|
|
99
117
|
onRemoveListener?: (type: string, listener: TypedFastEventListener) => void;
|
|
100
118
|
onClearListeners?: () => void;
|
|
101
|
-
onListenerError?: (
|
|
119
|
+
onListenerError?: (error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta> | undefined) => void;
|
|
102
120
|
onBeforeExecuteListener?: (message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta>) => boolean | void | any[];
|
|
103
121
|
onAfterExecuteListener?: (message: TypedFastEventMessage<any, Meta>, returns: any[], listeners: FastListenerNode[]) => void;
|
|
104
122
|
/**
|
|
@@ -160,9 +178,7 @@ type OptionalItems<T, K extends keyof T> = Expand<Omit<T, K> & {
|
|
|
160
178
|
type DeepPartial<T> = {
|
|
161
179
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
162
180
|
};
|
|
163
|
-
type Fallback<T, F> = [
|
|
164
|
-
T
|
|
165
|
-
] extends [never] ? F : T extends undefined ? F : T;
|
|
181
|
+
type Fallback<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
166
182
|
type ChangeFieldType<Record, Name extends string, Type = any> = Expand<Omit<Record, Name> & {
|
|
167
183
|
[K in Name]: Type;
|
|
168
184
|
}>;
|
|
@@ -191,16 +207,7 @@ type Overloads<T> = Unique<T extends {
|
|
|
191
207
|
(...args: infer A6): infer R6;
|
|
192
208
|
(...args: infer A7): infer R7;
|
|
193
209
|
(...args: infer A8): infer R8;
|
|
194
|
-
} ? [
|
|
195
|
-
(...args: A1) => R1,
|
|
196
|
-
((...args: A2) => R2),
|
|
197
|
-
((...args: A3) => R3),
|
|
198
|
-
((...args: A4) => R4),
|
|
199
|
-
((...args: A5) => R5),
|
|
200
|
-
((...args: A6) => R6),
|
|
201
|
-
((...args: A7) => R7),
|
|
202
|
-
((...args: A8) => R8)
|
|
203
|
-
] : T extends {
|
|
210
|
+
} ? [(...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 {
|
|
204
211
|
(...args: infer A1): infer R1;
|
|
205
212
|
(...args: infer A2): infer R2;
|
|
206
213
|
(...args: infer A3): infer R3;
|
|
@@ -208,76 +215,44 @@ type Overloads<T> = Unique<T extends {
|
|
|
208
215
|
(...args: infer A5): infer R5;
|
|
209
216
|
(...args: infer A6): infer R6;
|
|
210
217
|
(...args: infer A7): infer R7;
|
|
211
|
-
} ? [
|
|
212
|
-
(...args: A1) => R1,
|
|
213
|
-
((...args: A2) => R2),
|
|
214
|
-
((...args: A3) => R3),
|
|
215
|
-
((...args: A4) => R4),
|
|
216
|
-
((...args: A5) => R5),
|
|
217
|
-
((...args: A6) => R6),
|
|
218
|
-
((...args: A7) => R7)
|
|
219
|
-
] : T extends {
|
|
218
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6, (...args: A7) => R7] : T extends {
|
|
220
219
|
(...args: infer A1): infer R1;
|
|
221
220
|
(...args: infer A2): infer R2;
|
|
222
221
|
(...args: infer A3): infer R3;
|
|
223
222
|
(...args: infer A4): infer R4;
|
|
224
223
|
(...args: infer A5): infer R5;
|
|
225
224
|
(...args: infer A6): infer R6;
|
|
226
|
-
} ? [
|
|
227
|
-
(...args: A1) => R1,
|
|
228
|
-
((...args: A2) => R2),
|
|
229
|
-
((...args: A3) => R3),
|
|
230
|
-
((...args: A4) => R4),
|
|
231
|
-
((...args: A5) => R5),
|
|
232
|
-
((...args: A6) => R6)
|
|
233
|
-
] : T extends {
|
|
225
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6] : T extends {
|
|
234
226
|
(...args: infer A1): infer R1;
|
|
235
227
|
(...args: infer A2): infer R2;
|
|
236
228
|
(...args: infer A3): infer R3;
|
|
237
229
|
(...args: infer A4): infer R4;
|
|
238
230
|
(...args: infer A5): infer R5;
|
|
239
|
-
} ? [
|
|
240
|
-
(...args: A1) => R1,
|
|
241
|
-
((...args: A2) => R2),
|
|
242
|
-
((...args: A3) => R3),
|
|
243
|
-
((...args: A4) => R4),
|
|
244
|
-
((...args: A5) => R5)
|
|
245
|
-
] : T extends {
|
|
231
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T extends {
|
|
246
232
|
(...args: infer A1): infer R1;
|
|
247
233
|
(...args: infer A2): infer R2;
|
|
248
234
|
(...args: infer A3): infer R3;
|
|
249
235
|
(...args: infer A4): infer R4;
|
|
250
|
-
} ? [
|
|
251
|
-
(...args: A1) => R1,
|
|
252
|
-
((...args: A2) => R2),
|
|
253
|
-
((...args: A3) => R3),
|
|
254
|
-
((...args: A4) => R4)
|
|
255
|
-
] : T extends {
|
|
236
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4] : T extends {
|
|
256
237
|
(...args: infer A1): infer R1;
|
|
257
238
|
(...args: infer A2): infer R2;
|
|
258
239
|
(...args: infer A3): infer R3;
|
|
259
|
-
} ? [
|
|
260
|
-
((...args: A1) => R1),
|
|
261
|
-
((...args: A2) => R2),
|
|
262
|
-
((...args: A3) => R3)
|
|
263
|
-
] : T extends {
|
|
240
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3] : T extends {
|
|
264
241
|
(...args: infer A1): infer R1;
|
|
265
242
|
(...args: infer A2): infer R2;
|
|
266
|
-
} ? [
|
|
267
|
-
((...args: A1) => R1),
|
|
268
|
-
((...args: A2) => R2)
|
|
269
|
-
] : T extends {
|
|
243
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2] : T extends {
|
|
270
244
|
(...args: infer A1): infer R1;
|
|
271
|
-
} ? [
|
|
272
|
-
(...args: A1) => R1
|
|
273
|
-
] : [
|
|
274
|
-
T
|
|
275
|
-
]>;
|
|
245
|
+
} ? [(...args: A1) => R1] : [T]>;
|
|
276
246
|
type Dict<V = any> = Record<Exclude<string, number | symbol>, V>;
|
|
277
247
|
type Union<T> = T extends infer O ? {
|
|
278
248
|
[K in keyof O]: O[K];
|
|
279
249
|
} : never;
|
|
280
250
|
|
|
251
|
+
type RecordValues<R extends Record<string, any>> = R[keyof R];
|
|
252
|
+
type RecordPrefix<P extends string, R extends Record<string, any>> = {
|
|
253
|
+
[K in keyof R as K extends `${P}/${infer S}` ? S : never]: R[K];
|
|
254
|
+
};
|
|
255
|
+
|
|
281
256
|
type FastEventBusMessage<Events extends Record<string, any> = Record<string, any>, M = any> = FastEventEmitMessage<Events, M> & {
|
|
282
257
|
from?: string;
|
|
283
258
|
to?: string;
|
|
@@ -342,7 +317,7 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
342
317
|
on<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
343
318
|
on(type: '**', options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
344
319
|
on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
345
|
-
on<T extends string>(type: T, listener: TypedFastEventListener<
|
|
320
|
+
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;
|
|
346
321
|
on(type: '**', listener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
347
322
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
348
323
|
once<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
@@ -362,17 +337,17 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
362
337
|
emit(type: Types, directive: symbol): void;
|
|
363
338
|
emit(type: string, directive: symbol): void;
|
|
364
339
|
emit<R = any, T extends Types = Types>(type: T, payload?: Events[T], retain?: boolean): R[];
|
|
365
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
340
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, retain?: boolean): R[];
|
|
366
341
|
emit<R = any>(type: Types, payload?: Events[Types], options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
367
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
342
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
368
343
|
emit<R = any>(message: FastEventEmitMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
369
344
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
370
345
|
[K in T]: K extends Types ? Events[K] : any;
|
|
371
346
|
}, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
372
|
-
emitAsync<R = any>(type:
|
|
373
|
-
emitAsync<R = any>(type:
|
|
374
|
-
emitAsync<R = any>(type:
|
|
375
|
-
emitAsync<R = any>(type:
|
|
347
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: Events[T], retain?: boolean): Promise<[R | Error][]>;
|
|
348
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : any, retain?: boolean): Promise<[R | Error][]>;
|
|
349
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: Events[T], options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
350
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : any, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
376
351
|
emitAsync<R = any>(message: TypedFastEventMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
377
352
|
waitFor<T extends Types>(type: T, timeout?: number): Promise<TypedFastEventMessage<{
|
|
378
353
|
[key in T]: Events[T];
|
|
@@ -538,7 +513,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
538
513
|
on<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
539
514
|
on(type: '**', options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
540
515
|
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;
|
|
541
|
-
on<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
516
|
+
on<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
542
517
|
on(type: '**', listener: TypedFastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
543
518
|
/**
|
|
544
519
|
* 注册一次性事件监听器
|
|
@@ -564,7 +539,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
564
539
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
565
540
|
once<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
566
541
|
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;
|
|
567
|
-
once<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
542
|
+
once<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
568
543
|
/**
|
|
569
544
|
* 注册一个监听器,用于监听所有事件
|
|
570
545
|
* @param listener 事件监听器函数,可以接收任意类型的事件数据
|
|
@@ -753,13 +728,13 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
753
728
|
emit<T extends Types = Types>(type: T, directive: symbol): any[];
|
|
754
729
|
emit(type: string, directive: symbol): any[];
|
|
755
730
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], retain?: boolean): R[];
|
|
756
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
731
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, retain?: boolean): R[];
|
|
757
732
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
758
733
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
759
734
|
}, Meta>, retain?: boolean): R[];
|
|
760
735
|
emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): R[];
|
|
761
736
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], options?: FastEventListenerArgs<Meta>): R[];
|
|
762
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
737
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, options?: FastEventListenerArgs<Meta>): R[];
|
|
763
738
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
764
739
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
765
740
|
}, Meta>, options?: FastEventListenerArgs<Meta>): R[];
|
|
@@ -800,14 +775,14 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
800
775
|
* });
|
|
801
776
|
* ```
|
|
802
777
|
*/
|
|
803
|
-
emitAsync<R = any>(type:
|
|
804
|
-
emitAsync<R = any>(type:
|
|
778
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], retain?: boolean): Promise<[R | Error][]>;
|
|
779
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : any, retain?: boolean): Promise<[R | Error][]>;
|
|
805
780
|
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
806
781
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
807
782
|
}, Meta>, retain?: boolean): Promise<[R | Error][]>;
|
|
808
783
|
emitAsync<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): Promise<[R | Error][]>;
|
|
809
|
-
emitAsync<R = any>(type:
|
|
810
|
-
emitAsync<R = any>(type:
|
|
784
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : any, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
785
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
811
786
|
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
812
787
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
813
788
|
}, Meta>, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
@@ -892,6 +867,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
892
867
|
* userEvents.offAll(); // 清理 'user' 前缀下的所有事件
|
|
893
868
|
* ```
|
|
894
869
|
*/
|
|
870
|
+
scope<P extends string>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta, Context>>): FastEventScope<ScopeEvents<AllEvents, P>, Meta, Context>;
|
|
895
871
|
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>;
|
|
896
872
|
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;
|
|
897
873
|
}
|
|
@@ -924,7 +900,7 @@ declare class FastEventBusNode<Events extends Record<string, any> = Record<strin
|
|
|
924
900
|
* 加入事件总线
|
|
925
901
|
* @param eventBus 要加入的事件总线
|
|
926
902
|
*/
|
|
927
|
-
connect(eventbus: FastEventBus<any>): void;
|
|
903
|
+
connect(eventbus: FastEventBus<any, any, any>): void;
|
|
928
904
|
disconnect(): void;
|
|
929
905
|
/**
|
|
930
906
|
*
|
|
@@ -1152,4 +1128,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
1152
1128
|
|
|
1153
1129
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
1154
1130
|
|
|
1155
|
-
export { AbortError, BroadcastEvent, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventBus, type FastEventBusEventTypes, type FastEventBusEvents, type FastEventBusMessage, FastEventBusNode, type FastEventBusNodeIds, type FastEventBusNodeOptions, type FastEventBusNodes, type FastEventBusOptions, 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, NamespaceDelimiter, NodeDataEvent, 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 };
|
|
1131
|
+
export { AbortError, BroadcastEvent, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventBus, type FastEventBusEventTypes, type FastEventBusEvents, type FastEventBusMessage, FastEventBusNode, type FastEventBusNodeIds, type FastEventBusNodeOptions, type FastEventBusNodes, type FastEventBusOptions, 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, NamespaceDelimiter, NodeDataEvent, 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/eventbus/index.d.ts
CHANGED
|
@@ -2,6 +2,24 @@ type FastListenerExecutor = (listeners: FastListenerMeta[], message: TypedFastEv
|
|
|
2
2
|
|
|
3
3
|
type FastListenerPipe = (listener: TypedFastEventListener) => TypedFastEventListener;
|
|
4
4
|
|
|
5
|
+
type MergeUnion<T> = (T extends any ? (x: T) => void : never) extends (x: infer U) => void ? {
|
|
6
|
+
[K in keyof U]: U[K];
|
|
7
|
+
} : never;
|
|
8
|
+
type Split<S extends string, Delimiter extends string = '/'> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : [S];
|
|
9
|
+
type MatchSegment<Input extends string, Pattern extends string> = Pattern extends '*' ? true : Pattern extends '**' ? true : Input extends Pattern ? true : false;
|
|
10
|
+
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;
|
|
11
|
+
type MatchPattern<T extends string, Pattern extends string> = MatchPatternArray<Split<T>, Split<Pattern>> extends true ? {
|
|
12
|
+
[K in Pattern]: any;
|
|
13
|
+
} : never;
|
|
14
|
+
type Fallback$1<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
15
|
+
type MatchEventType<T extends string, Events extends Record<string, any>> = MergeUnion<Fallback$1<{
|
|
16
|
+
[K in keyof Events]: MatchPattern<T, K & string> extends never ? never : {
|
|
17
|
+
[P in K]: Events[K];
|
|
18
|
+
};
|
|
19
|
+
}[keyof Events] extends infer Result ? Result extends Record<string, any> ? Result : any : any, {
|
|
20
|
+
[K in T]: any;
|
|
21
|
+
}>>;
|
|
22
|
+
|
|
5
23
|
interface FastEventMeta {
|
|
6
24
|
}
|
|
7
25
|
interface FastEventMessageExtends {
|
|
@@ -11,34 +29,34 @@ type FastEventMessage<P = any, M extends Record<string, any> = Record<string, an
|
|
|
11
29
|
payload: P;
|
|
12
30
|
meta?: M & Partial<FastEventMeta>;
|
|
13
31
|
} & FastEventMessageExtends;
|
|
14
|
-
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
32
|
+
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
15
33
|
[K in keyof Events]: {
|
|
16
34
|
type: Exclude<K, number | symbol>;
|
|
17
35
|
payload: Events[K];
|
|
18
36
|
meta: FastEventMeta & M & Record<string, any>;
|
|
19
37
|
};
|
|
20
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
21
|
-
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
38
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
39
|
+
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
22
40
|
[K in keyof Events]: {
|
|
23
41
|
type: Exclude<K, number | symbol>;
|
|
24
42
|
payload: Events[K];
|
|
25
43
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
26
44
|
};
|
|
27
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
28
|
-
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
45
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
46
|
+
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
29
47
|
[K in keyof Events]: {
|
|
30
48
|
type: Exclude<K, number | symbol>;
|
|
31
49
|
payload?: Events[K];
|
|
32
50
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
33
51
|
};
|
|
34
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
52
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
35
53
|
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<{
|
|
36
54
|
[K in T]: P;
|
|
37
55
|
}, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
38
56
|
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>;
|
|
39
|
-
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> =
|
|
57
|
+
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> = {
|
|
40
58
|
[K in keyof Events]: TypedFastEventListener<Exclude<K, number | symbol>, Events[K], M, C>;
|
|
41
|
-
}
|
|
59
|
+
};
|
|
42
60
|
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>;
|
|
43
61
|
/**
|
|
44
62
|
* [
|
|
@@ -98,7 +116,7 @@ type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
|
98
116
|
onAddListener?: (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, Meta>) => boolean | FastEventSubscriber | void;
|
|
99
117
|
onRemoveListener?: (type: string, listener: TypedFastEventListener) => void;
|
|
100
118
|
onClearListeners?: () => void;
|
|
101
|
-
onListenerError?: (
|
|
119
|
+
onListenerError?: (error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta> | undefined) => void;
|
|
102
120
|
onBeforeExecuteListener?: (message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta>) => boolean | void | any[];
|
|
103
121
|
onAfterExecuteListener?: (message: TypedFastEventMessage<any, Meta>, returns: any[], listeners: FastListenerNode[]) => void;
|
|
104
122
|
/**
|
|
@@ -160,9 +178,7 @@ type OptionalItems<T, K extends keyof T> = Expand<Omit<T, K> & {
|
|
|
160
178
|
type DeepPartial<T> = {
|
|
161
179
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
162
180
|
};
|
|
163
|
-
type Fallback<T, F> = [
|
|
164
|
-
T
|
|
165
|
-
] extends [never] ? F : T extends undefined ? F : T;
|
|
181
|
+
type Fallback<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
166
182
|
type ChangeFieldType<Record, Name extends string, Type = any> = Expand<Omit<Record, Name> & {
|
|
167
183
|
[K in Name]: Type;
|
|
168
184
|
}>;
|
|
@@ -191,16 +207,7 @@ type Overloads<T> = Unique<T extends {
|
|
|
191
207
|
(...args: infer A6): infer R6;
|
|
192
208
|
(...args: infer A7): infer R7;
|
|
193
209
|
(...args: infer A8): infer R8;
|
|
194
|
-
} ? [
|
|
195
|
-
(...args: A1) => R1,
|
|
196
|
-
((...args: A2) => R2),
|
|
197
|
-
((...args: A3) => R3),
|
|
198
|
-
((...args: A4) => R4),
|
|
199
|
-
((...args: A5) => R5),
|
|
200
|
-
((...args: A6) => R6),
|
|
201
|
-
((...args: A7) => R7),
|
|
202
|
-
((...args: A8) => R8)
|
|
203
|
-
] : T extends {
|
|
210
|
+
} ? [(...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 {
|
|
204
211
|
(...args: infer A1): infer R1;
|
|
205
212
|
(...args: infer A2): infer R2;
|
|
206
213
|
(...args: infer A3): infer R3;
|
|
@@ -208,76 +215,44 @@ type Overloads<T> = Unique<T extends {
|
|
|
208
215
|
(...args: infer A5): infer R5;
|
|
209
216
|
(...args: infer A6): infer R6;
|
|
210
217
|
(...args: infer A7): infer R7;
|
|
211
|
-
} ? [
|
|
212
|
-
(...args: A1) => R1,
|
|
213
|
-
((...args: A2) => R2),
|
|
214
|
-
((...args: A3) => R3),
|
|
215
|
-
((...args: A4) => R4),
|
|
216
|
-
((...args: A5) => R5),
|
|
217
|
-
((...args: A6) => R6),
|
|
218
|
-
((...args: A7) => R7)
|
|
219
|
-
] : T extends {
|
|
218
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6, (...args: A7) => R7] : T extends {
|
|
220
219
|
(...args: infer A1): infer R1;
|
|
221
220
|
(...args: infer A2): infer R2;
|
|
222
221
|
(...args: infer A3): infer R3;
|
|
223
222
|
(...args: infer A4): infer R4;
|
|
224
223
|
(...args: infer A5): infer R5;
|
|
225
224
|
(...args: infer A6): infer R6;
|
|
226
|
-
} ? [
|
|
227
|
-
(...args: A1) => R1,
|
|
228
|
-
((...args: A2) => R2),
|
|
229
|
-
((...args: A3) => R3),
|
|
230
|
-
((...args: A4) => R4),
|
|
231
|
-
((...args: A5) => R5),
|
|
232
|
-
((...args: A6) => R6)
|
|
233
|
-
] : T extends {
|
|
225
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6] : T extends {
|
|
234
226
|
(...args: infer A1): infer R1;
|
|
235
227
|
(...args: infer A2): infer R2;
|
|
236
228
|
(...args: infer A3): infer R3;
|
|
237
229
|
(...args: infer A4): infer R4;
|
|
238
230
|
(...args: infer A5): infer R5;
|
|
239
|
-
} ? [
|
|
240
|
-
(...args: A1) => R1,
|
|
241
|
-
((...args: A2) => R2),
|
|
242
|
-
((...args: A3) => R3),
|
|
243
|
-
((...args: A4) => R4),
|
|
244
|
-
((...args: A5) => R5)
|
|
245
|
-
] : T extends {
|
|
231
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T extends {
|
|
246
232
|
(...args: infer A1): infer R1;
|
|
247
233
|
(...args: infer A2): infer R2;
|
|
248
234
|
(...args: infer A3): infer R3;
|
|
249
235
|
(...args: infer A4): infer R4;
|
|
250
|
-
} ? [
|
|
251
|
-
(...args: A1) => R1,
|
|
252
|
-
((...args: A2) => R2),
|
|
253
|
-
((...args: A3) => R3),
|
|
254
|
-
((...args: A4) => R4)
|
|
255
|
-
] : T extends {
|
|
236
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4] : T extends {
|
|
256
237
|
(...args: infer A1): infer R1;
|
|
257
238
|
(...args: infer A2): infer R2;
|
|
258
239
|
(...args: infer A3): infer R3;
|
|
259
|
-
} ? [
|
|
260
|
-
((...args: A1) => R1),
|
|
261
|
-
((...args: A2) => R2),
|
|
262
|
-
((...args: A3) => R3)
|
|
263
|
-
] : T extends {
|
|
240
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3] : T extends {
|
|
264
241
|
(...args: infer A1): infer R1;
|
|
265
242
|
(...args: infer A2): infer R2;
|
|
266
|
-
} ? [
|
|
267
|
-
((...args: A1) => R1),
|
|
268
|
-
((...args: A2) => R2)
|
|
269
|
-
] : T extends {
|
|
243
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2] : T extends {
|
|
270
244
|
(...args: infer A1): infer R1;
|
|
271
|
-
} ? [
|
|
272
|
-
(...args: A1) => R1
|
|
273
|
-
] : [
|
|
274
|
-
T
|
|
275
|
-
]>;
|
|
245
|
+
} ? [(...args: A1) => R1] : [T]>;
|
|
276
246
|
type Dict<V = any> = Record<Exclude<string, number | symbol>, V>;
|
|
277
247
|
type Union<T> = T extends infer O ? {
|
|
278
248
|
[K in keyof O]: O[K];
|
|
279
249
|
} : never;
|
|
280
250
|
|
|
251
|
+
type RecordValues<R extends Record<string, any>> = R[keyof R];
|
|
252
|
+
type RecordPrefix<P extends string, R extends Record<string, any>> = {
|
|
253
|
+
[K in keyof R as K extends `${P}/${infer S}` ? S : never]: R[K];
|
|
254
|
+
};
|
|
255
|
+
|
|
281
256
|
type FastEventBusMessage<Events extends Record<string, any> = Record<string, any>, M = any> = FastEventEmitMessage<Events, M> & {
|
|
282
257
|
from?: string;
|
|
283
258
|
to?: string;
|
|
@@ -342,7 +317,7 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
342
317
|
on<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
343
318
|
on(type: '**', options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
344
319
|
on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
345
|
-
on<T extends string>(type: T, listener: TypedFastEventListener<
|
|
320
|
+
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;
|
|
346
321
|
on(type: '**', listener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
347
322
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
348
323
|
once<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
@@ -362,17 +337,17 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
362
337
|
emit(type: Types, directive: symbol): void;
|
|
363
338
|
emit(type: string, directive: symbol): void;
|
|
364
339
|
emit<R = any, T extends Types = Types>(type: T, payload?: Events[T], retain?: boolean): R[];
|
|
365
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
340
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, retain?: boolean): R[];
|
|
366
341
|
emit<R = any>(type: Types, payload?: Events[Types], options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
367
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
342
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
368
343
|
emit<R = any>(message: FastEventEmitMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
369
344
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
370
345
|
[K in T]: K extends Types ? Events[K] : any;
|
|
371
346
|
}, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
372
|
-
emitAsync<R = any>(type:
|
|
373
|
-
emitAsync<R = any>(type:
|
|
374
|
-
emitAsync<R = any>(type:
|
|
375
|
-
emitAsync<R = any>(type:
|
|
347
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: Events[T], retain?: boolean): Promise<[R | Error][]>;
|
|
348
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : any, retain?: boolean): Promise<[R | Error][]>;
|
|
349
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: Events[T], options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
350
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : any, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
376
351
|
emitAsync<R = any>(message: TypedFastEventMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
377
352
|
waitFor<T extends Types>(type: T, timeout?: number): Promise<TypedFastEventMessage<{
|
|
378
353
|
[key in T]: Events[T];
|
|
@@ -538,7 +513,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
538
513
|
on<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
539
514
|
on(type: '**', options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
540
515
|
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;
|
|
541
|
-
on<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
516
|
+
on<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
542
517
|
on(type: '**', listener: TypedFastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
543
518
|
/**
|
|
544
519
|
* 注册一次性事件监听器
|
|
@@ -564,7 +539,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
564
539
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
565
540
|
once<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
566
541
|
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;
|
|
567
|
-
once<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
542
|
+
once<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
568
543
|
/**
|
|
569
544
|
* 注册一个监听器,用于监听所有事件
|
|
570
545
|
* @param listener 事件监听器函数,可以接收任意类型的事件数据
|
|
@@ -753,13 +728,13 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
753
728
|
emit<T extends Types = Types>(type: T, directive: symbol): any[];
|
|
754
729
|
emit(type: string, directive: symbol): any[];
|
|
755
730
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], retain?: boolean): R[];
|
|
756
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
731
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, retain?: boolean): R[];
|
|
757
732
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
758
733
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
759
734
|
}, Meta>, retain?: boolean): R[];
|
|
760
735
|
emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): R[];
|
|
761
736
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], options?: FastEventListenerArgs<Meta>): R[];
|
|
762
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
737
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, options?: FastEventListenerArgs<Meta>): R[];
|
|
763
738
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
764
739
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
765
740
|
}, Meta>, options?: FastEventListenerArgs<Meta>): R[];
|
|
@@ -800,14 +775,14 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
800
775
|
* });
|
|
801
776
|
* ```
|
|
802
777
|
*/
|
|
803
|
-
emitAsync<R = any>(type:
|
|
804
|
-
emitAsync<R = any>(type:
|
|
778
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], retain?: boolean): Promise<[R | Error][]>;
|
|
779
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : any, retain?: boolean): Promise<[R | Error][]>;
|
|
805
780
|
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
806
781
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
807
782
|
}, Meta>, retain?: boolean): Promise<[R | Error][]>;
|
|
808
783
|
emitAsync<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): Promise<[R | Error][]>;
|
|
809
|
-
emitAsync<R = any>(type:
|
|
810
|
-
emitAsync<R = any>(type:
|
|
784
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : any, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
785
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
811
786
|
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
812
787
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
813
788
|
}, Meta>, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
@@ -892,6 +867,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
892
867
|
* userEvents.offAll(); // 清理 'user' 前缀下的所有事件
|
|
893
868
|
* ```
|
|
894
869
|
*/
|
|
870
|
+
scope<P extends string>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta, Context>>): FastEventScope<ScopeEvents<AllEvents, P>, Meta, Context>;
|
|
895
871
|
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>;
|
|
896
872
|
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;
|
|
897
873
|
}
|
|
@@ -924,7 +900,7 @@ declare class FastEventBusNode<Events extends Record<string, any> = Record<strin
|
|
|
924
900
|
* 加入事件总线
|
|
925
901
|
* @param eventBus 要加入的事件总线
|
|
926
902
|
*/
|
|
927
|
-
connect(eventbus: FastEventBus<any>): void;
|
|
903
|
+
connect(eventbus: FastEventBus<any, any, any>): void;
|
|
928
904
|
disconnect(): void;
|
|
929
905
|
/**
|
|
930
906
|
*
|
|
@@ -1152,4 +1128,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
1152
1128
|
|
|
1153
1129
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
1154
1130
|
|
|
1155
|
-
export { AbortError, BroadcastEvent, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventBus, type FastEventBusEventTypes, type FastEventBusEvents, type FastEventBusMessage, FastEventBusNode, type FastEventBusNodeIds, type FastEventBusNodeOptions, type FastEventBusNodes, type FastEventBusOptions, 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, NamespaceDelimiter, NodeDataEvent, 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 };
|
|
1131
|
+
export { AbortError, BroadcastEvent, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventBus, type FastEventBusEventTypes, type FastEventBusEvents, type FastEventBusMessage, FastEventBusNode, type FastEventBusNodeIds, type FastEventBusNodeOptions, type FastEventBusNodes, type FastEventBusOptions, 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, NamespaceDelimiter, NodeDataEvent, 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 };
|