nanoeffects 0.5.0 → 0.6.0

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.
Files changed (36) hide show
  1. package/dist/{action-creator-DOWcbXpy.d.ts → action-creator-c292nK7v.d.ts} +115 -33
  2. package/dist/actions.d.ts +18 -4
  3. package/dist/actions.js +1 -1
  4. package/dist/{notrace/context-plugin-B0sLWOxR.d.ts → context-plugin-1pYmSQEG.d.ts} +1 -1
  5. package/dist/dev.d.ts +2 -2
  6. package/dist/effects.d.ts +3 -202
  7. package/dist/index.d.ts +2 -2
  8. package/dist/{module-DCJl-qfi.d.ts → module-BlF2KSgy.d.ts} +19 -4
  9. package/dist/notrace/{action-creator-DOWcbXpy.d.ts → action-creator-DKG_sIia.d.ts} +115 -33
  10. package/dist/notrace/actions.d.ts +45 -5
  11. package/dist/notrace/actions.js +1 -1
  12. package/dist/{context-plugin-B0sLWOxR.d.ts → notrace/context-plugin-Dt1IgVo8.d.ts} +1 -1
  13. package/dist/notrace/effects.d.ts +3 -202
  14. package/dist/notrace/index.d.ts +2 -2
  15. package/dist/notrace/plugin-B0AXKusc.d.ts +207 -0
  16. package/dist/notrace/policies.d.ts +1 -1
  17. package/dist/notrace/redux.d.ts +1 -1
  18. package/dist/observable.d.ts +1 -1
  19. package/dist/plugin-CCYlC0XS.d.ts +207 -0
  20. package/dist/policies.d.ts +1 -1
  21. package/dist/react.d.ts +1 -1
  22. package/dist/redux.d.ts +1 -1
  23. package/dist/scope-key-B7l7mUS5.js +1 -0
  24. package/dist/scope.d.ts +58 -0
  25. package/dist/scope.js +1 -0
  26. package/dist/trace.d.ts +1 -1
  27. package/dist/types-mLaAx-EZ.d.ts +15 -0
  28. package/docs/actions.md +24 -0
  29. package/docs/context.md +2 -0
  30. package/docs/effects.md +3 -2
  31. package/docs/guide.md +22 -0
  32. package/docs/package.md +1 -0
  33. package/docs/scope.md +226 -0
  34. package/llms-full.txt +282 -2
  35. package/llms.txt +1 -0
  36. package/package.json +11 -2
@@ -1,3 +1,29 @@
1
+ //#region src/core/types.d.ts
2
+ type PayloadOf<P> = undefined extends P ? [payload?: P] : [payload: P];
3
+ type EventMap = Record<string, unknown>;
4
+ type Keys<E> = keyof E & string;
5
+ type Task<P, E extends EventMap, R = unknown> = (payload: P, ctx: Context<E>) => R;
6
+ type EffectName = "every" | "latest" | "leading" | "debounce" | "throttle" | "run" | "all" | "race" | "retry" | "timeout" | "poll" | "take" | "queue" | "allSettled" | "command";
7
+ type Phase = "start" | "done" | "error" | "cancel" | "drop";
8
+ type TraceEvent<E = Record<string, unknown>> = { [K in Keys<E>]: {
9
+ id: number;
10
+ parent?: number;
11
+ type: K;
12
+ effect: EffectName;
13
+ phase: Phase;
14
+ payload: E[K];
15
+ error?: unknown;
16
+ }; }[Keys<E>];
17
+ /**
18
+ * The contract of every trace logger: receives each task phase of a bus.
19
+ * Adapters in `nanoeffects/trace` are factories that return one; pass it
20
+ * through `createTracer` to `createBus({ trace })`.
21
+ */
22
+ type TraceLogger<E = Record<string, unknown>> = (event: TraceEvent<E>) => void;
23
+ /** One logger or several; a throwing logger never breaks the task or the others. */
24
+ type Trace<E = Record<string, unknown>> = TraceLogger<E> | readonly TraceLogger<E>[];
25
+ type UnsubscribeCallback = () => void;
26
+ //#endregion
1
27
  //#region src/core/store.d.ts
2
28
  declare const anyEventType = "*";
3
29
  //#endregion
@@ -83,14 +109,21 @@ type Emit<E extends EventMap> = {
83
109
  <K extends EventKey<E>>(event: K, ...payload: PayloadOf<E[K]>): void;
84
110
  /** Before Handler: a command is callable too, and must return its result type. */
85
111
  <P, R>(command: Command<P, R>, ...payload: PayloadOf<P>): R;
86
- <P, R>(call: CommandCall<P, R>): R;
112
+ /** A scope as the second argument replaces context fields for the tasks of this emit; see `scopePlugin`. */
113
+ <P, R, F>(call: CommandCall<P, R> & WithScope<F>, scope?: EmitScope<E, F>): R;
114
+ <P, R>(call: CommandCall<P, R>, scope?: EmitScope<E>): R;
87
115
  <K extends EventKey<E>, R>(event: Handler<E, R, K>, ...payload: PayloadOf<E[K]>): R;
88
- (event: EventLike<E>): void;
116
+ <F>(event: EventLike<E> & WithScope<F>, scope?: EmitScope<E, F>): void;
117
+ (event: EventLike<E>, scope?: EmitScope<E>): void;
89
118
  };
90
119
  type On<E extends EventMap> = {
91
120
  (event: AnyEvent, fn: Task<EventPayload<E>, E>): UnsubscribeCallback;
92
121
  <K extends EventKey<E>>(event: K, fn: Task<E[K], E>): UnsubscribeCallback;
93
122
  /** An action creator without a payload type: the payload comes from the event map. */
123
+ /** The creators and commands that carry a scope come first: the handler sees their fields. */
124
+ <K extends EventKey<E>, F>(creator: FreeActionCreator<K, F> & WithScope<F>, fn: Task<E[K], WithFields<E, F>>): UnsubscribeCallback;
125
+ <P, F>(creator: ActionCreator<P, string, PayloadOf<P>, F> & WithScope<F>, fn: Task<P, WithFields<E, F>>): UnsubscribeCallback;
126
+ <P, F>(command: Command<P, unknown> & WithScope<F>, fn: Task<P, WithFields<E, F>>): UnsubscribeCallback;
94
127
  <K extends EventKey<E>>(creator: FreeActionCreator<K>, fn: Task<E[K], E>): UnsubscribeCallback;
95
128
  /** An action creator: the payload comes from it, so an event map is not needed. */
96
129
  <P>(creator: ActionCreator<P>, fn: Task<P, E>): UnsubscribeCallback;
@@ -191,6 +224,10 @@ interface Bus<E extends EventMap> {
191
224
  readonly trace?: Tracer | undefined;
192
225
  /** Called with every new task context to add fields to it, for what needs the task, like `effectsPlugin`. Chain to the previous one. */
193
226
  addContext?: ((ctx: object) => void) | undefined;
227
+ /** Puts the fields of a module's scope on the context of one of its tasks; `scopePlugin` sets it. Without it a module's scope is ignored. */
228
+ applyScope?: ((ctx: object, scope: Scope) => void) | undefined;
229
+ /** Wraps a handler so it runs with the fields of a module's scope; `scopePlugin` sets it. */
230
+ fitScope?: ((scope: Scope, fn: (payload: never, ctx: never) => unknown) => unknown) | undefined;
194
231
  }
195
232
  type BusOptions<E extends EventMap> = {
196
233
  /** Tracing of every task phase; make it with `createTracer` from `nanoeffects/trace`. */
@@ -228,31 +265,76 @@ type BusOptions<E extends EventMap> = {
228
265
  };
229
266
  declare const createBus: <Events extends EventMap>(options?: BusOptions<Events>) => Bus<Events>;
230
267
  //#endregion
231
- //#region src/core/types.d.ts
232
- type PayloadOf<P> = undefined extends P ? [payload?: P] : [payload: P];
233
- type EventMap = Record<string, unknown>;
234
- type Keys<E> = keyof E & string;
235
- type Task<P, E extends EventMap, R = unknown> = (payload: P, ctx: Context<E>) => R;
236
- type EffectName = "every" | "latest" | "leading" | "debounce" | "throttle" | "run" | "all" | "race" | "retry" | "timeout" | "poll" | "take" | "queue" | "allSettled" | "command";
237
- type Phase = "start" | "done" | "error" | "cancel" | "drop";
238
- type TraceEvent<E = Record<string, unknown>> = { [K in Keys<E>]: {
239
- id: number;
240
- parent?: number;
241
- type: K;
242
- effect: EffectName;
243
- phase: Phase;
244
- payload: E[K];
245
- error?: unknown;
246
- }; }[Keys<E>];
268
+ //#region src/core/effect-types.d.ts
269
+ /** What an effect needs of the task it runs for: its signal. A task context fits, and so does `{ signal }`. */
270
+ type Signaled = {
271
+ signal: AbortSignal;
272
+ };
273
+ /** An effect: a function whose first parameter takes `{ signal }`, like `retry(ctx, fn)`. */
274
+ type SignalFirst = (ctx: Signaled, ...args: never[]) => unknown;
275
+ /** The effects of a scope or of `effectsPlugin`, by the name they get on the context. */
276
+ type Effects = Record<string, SignalFirst>;
277
+ declare const bound: unique symbol;
247
278
  /**
248
- * The contract of every trace logger: receives each task phase of a bus.
249
- * Adapters in `nanoeffects/trace` are factories that return one; pass it
250
- * through `createTracer` to `createBus({ trace })`.
279
+ * An effect that says what it looks like once it is bound to a task (without
280
+ * the `ctx` parameter). A plain effect has its first parameter removed, which
281
+ * erases its generics; this type keeps them, because `F` is carried as it is.
282
+ * It changes the checker only: the function is the same at run time.
283
+ *
284
+ * @example
285
+ * ```ts
286
+ * type First = <T>(items: T[]) => T; // how a handler calls it
287
+ * const first: Effect<First> = (ctx, items) => items[0];
288
+ * ```
251
289
  */
252
- type TraceLogger<E = Record<string, unknown>> = (event: TraceEvent<E>) => void;
253
- /** One logger or several; a throwing logger never breaks the task or the others. */
254
- type Trace<E = Record<string, unknown>> = TraceLogger<E> | readonly TraceLogger<E>[];
255
- type UnsubscribeCallback = () => void;
290
+ type Effect<F extends (...args: never[]) => unknown> = ((ctx: Signaled, ...args: Parameters<F>) => ReturnType<F>) & {
291
+ readonly [bound]?: F;
292
+ };
293
+ /** The bound form of a plain effect: the first parameter is gone, and so are its generics. */
294
+ type Strip<F> = F extends ((ctx: never, ...args: infer A) => infer R) ? (...args: A) => R : never;
295
+ /** The bound type an `Effect<F>` carries, or `Strip` of a plain function. */
296
+ type BoundForm<F> = typeof bound extends keyof F ? NonNullable<F[typeof bound & keyof F]> : Strip<F>;
297
+ //#endregion
298
+ //#region src/core/scope-types.d.ts
299
+ declare const scopeFields: unique symbol;
300
+ /** What an action creator, a command or a call knows of the scope it was made with: its fields, for the checker. */
301
+ type WithScope<F> = {
302
+ readonly [scopeFields]: F;
303
+ };
304
+ /** `X`, marked with the scope fields `F` it carries; `X` itself when there are none, so unscoped types stay as they were. */
305
+ type Carrying<X, F> = X & ([unknown] extends [F] ? unknown : WithScope<F>);
306
+ /**
307
+ * What a task gets on top of the context of its bus, for one place: every key
308
+ * is a context value and goes on `ctx` as it is, except `effects`, whose
309
+ * functions (each takes `{ signal }` first) are bound to the task. Made work by
310
+ * `scopePlugin` from `nanoeffects/scope`; without it a scope is ignored.
311
+ *
312
+ * @example
313
+ * ```ts
314
+ * const scope = { cache, effects: { race } }; // ctx.cache, and ctx.race bound to the task
315
+ * ```
316
+ */
317
+ type Scope = {
318
+ readonly effects?: Effects;
319
+ readonly [field: string]: unknown;
320
+ };
321
+ /**
322
+ * What a call may replace of what it already has: the fields of the bus and
323
+ * those of its own scope, and its effects. The types must match the ones they
324
+ * replace; a field that neither declares has no type to check against, so it is
325
+ * an error.
326
+ */
327
+ type EmitScope<E extends EventMap, F = unknown> = ([unknown] extends [ContextOf<E> & F] ? unknown : Partial<ContextOf<E> & F>) & {
328
+ effects?: Partial<Effects>;
329
+ };
330
+ /** `A` with the fields of `B` replacing those of the same name, not intersected with them. */
331
+ type Merge<A, B> = Omit<A, keyof B> & B;
332
+ /**
333
+ * The event map `E` with the fields `F` of a scope on top of its context
334
+ * fields; `E` itself when there are none. A field of the scope replaces the
335
+ * one of the bus in the type too.
336
+ */
337
+ type WithFields<E extends EventMap, F> = [unknown] extends [F] ? E : Omit<E, keyof WithContext<object>> & WithContext<Merge<ContextOf<E>, F>>;
256
338
  //#endregion
257
339
  //#region src/core/action-creator.d.ts
258
340
  type WithPayload<E extends EventMap, K extends Keys<E>> = undefined extends E[K] ? {
@@ -271,15 +353,15 @@ type Free = typeof free;
271
353
  * it is given, and the bus checks it against its event map, so
272
354
  * `createAction("user/loaded")` needs no generics and keeps its literal type.
273
355
  */
274
- interface FreeActionCreator<T extends string> {
275
- (): {
356
+ interface FreeActionCreator<T extends string, F = unknown> {
357
+ (): Carrying<{
276
358
  type: T;
277
359
  payload: undefined;
278
- };
279
- <P>(payload: P): {
360
+ }, F>;
361
+ <P>(payload: P): Carrying<{
280
362
  type: T;
281
363
  payload: P;
282
- };
364
+ }, F>;
283
365
  readonly type: T;
284
366
  /** Tells whether an action is one of this creator. */
285
367
  match(action: {
@@ -295,8 +377,8 @@ interface FreeActionCreator<T extends string> {
295
377
  * Makes actions of one type. It also works as the event of that type:
296
378
  * `bus.on(creator, fn)` and `bus.emit(creator(payload))`.
297
379
  */
298
- interface ActionCreator<P = void, T extends string = string, A extends unknown[] = PayloadOf<P>> {
299
- (...args: A): Made<P, T>;
380
+ interface ActionCreator<P = void, T extends string = string, A extends unknown[] = PayloadOf<P>, F = unknown> {
381
+ (...args: A): Carrying<Made<P, T>, F>;
300
382
  readonly type: T;
301
383
  /** Tells whether an action is one of this creator, and narrows its type. */
302
384
  match(action: {
@@ -306,4 +388,4 @@ interface ActionCreator<P = void, T extends string = string, A extends unknown[]
306
388
  toString(): T;
307
389
  }
308
390
  //#endregion
309
- export { EventsOf as A, anyEventType as B, ContextOf as C, EventKey as D, Emittable as E, WithContext as F, WithType as I, commandCall as L, HandlerRef as M, Off as N, EventLike as O, On as P, createBus as R, Context as S, Emit as T, Bus as _, EffectName as a, CommandCall as b, PayloadOf as c, Trace as d, TraceEvent as f, AnyEvent as g, Action as h, WithPayload as i, Handler as j, EventPayload as k, Phase as l, UnsubscribeCallback as m, Free as n, EventMap as o, TraceLogger as p, FreeActionCreator as r, Keys as s, ActionCreator as t, Task as u, BusOptions as v, ContextOption as w, Commands as x, Command as y, Tracer as z };
391
+ export { On as A, PayloadOf as B, EventKey as C, Handler as D, EventsOf as E, Tracer as F, TraceLogger as G, Task as H, anyEventType as I, UnsubscribeCallback as K, EffectName as L, WithType as M, commandCall as N, HandlerRef as O, createBus as P, EventMap as R, Emittable as S, EventPayload as T, Trace as U, Phase as V, TraceEvent as W, Commands as _, Scope as a, ContextOption as b, BoundForm as c, Action as d, AnyEvent as f, CommandCall as g, Command as h, WithPayload as i, WithContext as j, Off as k, Effect as l, BusOptions as m, Free as n, WithFields as o, Bus as p, FreeActionCreator as r, WithScope as s, ActionCreator as t, Effects as u, Context as v, EventLike as w, Emit as x, ContextOf as y, Keys as z };
@@ -1,5 +1,19 @@
1
- import { D as EventKey, S as Context, _ as Bus, c as PayloadOf, m as UnsubscribeCallback, n as Free, o as EventMap, r as FreeActionCreator, t as ActionCreator, u as Task, y as Command } from "./action-creator-DOWcbXpy.js";
1
+ import { B as PayloadOf, C as EventKey, H as Task, K as UnsubscribeCallback, R as EventMap, a as Scope, g as CommandCall, h as Command, n as Free, o as WithFields, p as Bus, r as FreeActionCreator, s as WithScope, t as ActionCreator, u as Effects, v as Context } from "./action-creator-DKG_sIia.js";
2
+ import { t as BoundOf } from "./plugin-B0AXKusc.js";
3
+ //#region src/scope/types.d.ts
4
+ type BoundEffects<E extends EventMap, S extends Scope> = S extends {
5
+ effects: infer H extends Effects;
6
+ } ? BoundOf<H, E> : unknown;
7
+ /** The fields a scope gives a task: its values as they are and its `effects` bound; `unknown` for an empty scope. */
8
+ type FieldsOfScope<E extends EventMap, S extends Scope> = [keyof S] extends [never] ? unknown : Omit<S, "effects"> & BoundEffects<E, S>;
9
+ /**
10
+ * The event map `E` with the fields of a scope on top of its context fields.
11
+ * A field the scope sets replaces the one of the bus in the type too.
12
+ */
13
+ type Scoped<E extends EventMap, S extends Scope> = WithFields<E, FieldsOfScope<E, S>>;
14
+ //#endregion
2
15
  //#region src/actions/action.d.ts
16
+ type ScopedCreator<P, T extends string, F> = [P] extends [Free] ? FreeActionCreator<T, F> & WithScope<F> : ActionCreator<P, T, PayloadOf<P>, F> & WithScope<F>;
3
17
  /**
4
18
  * Creates an action creator, as in Redux Toolkit.
5
19
  *
@@ -12,6 +26,9 @@ import { D as EventKey, S as Context, _ as Bus, c as PayloadOf, m as Unsubscribe
12
26
  * generic: `createAction<User, "user/loaded">("user/loaded")`.
13
27
  * - With `prepare` the arguments of the creator can differ from the payload,
14
28
  * and both types are inferred.
29
+ * - A scope as the last argument, `{ cache, effects: { race } }`, gives the
30
+ * listeners of its calls those context fields; it works on a bus that uses `scopePlugin`
31
+ * from `nanoeffects/scope` and is ignored on any other.
15
32
  *
16
33
  * @example
17
34
  * ```ts
@@ -32,6 +49,10 @@ export declare function createAction<P = Free, T extends string = string>(type:
32
49
  export declare function createAction<A extends unknown[], P, T extends string = string>(type: T, prepare: (...args: A) => {
33
50
  payload: P;
34
51
  }): ActionCreator<P, T, A>;
52
+ export declare function createAction<P = Free, T extends string = string, S extends Scope = Record<never, never>>(type: T, scope: S): ScopedCreator<P, T, FieldsOfScope<EventMap, S>>;
53
+ export declare function createAction<A extends unknown[], P, T extends string, S extends Scope>(type: T, prepare: (...args: A) => {
54
+ payload: P;
55
+ }, scope: S): ActionCreator<P, T, A, FieldsOfScope<EventMap, S>> & WithScope<FieldsOfScope<EventMap, S>>;
35
56
  //#endregion
36
57
  //#region src/actions/command.d.ts
37
58
  /** What `createCommand` returns: a command that also tells whether an action is of its type. */
@@ -46,6 +67,10 @@ type MadeCommand<P, R, T extends string> = Command<P, R> & {
46
67
  payload: P;
47
68
  };
48
69
  };
70
+ /** `Made`, called so that its calls carry the scope fields `F`; `Made` itself when there are none. */
71
+ type CarryingCalls<Made, P, R, F> = [unknown] extends [F] ? Made : ((payload: P) => CommandCall<P, R> & WithScope<F>) & Made & WithScope<F>;
72
+ /** A command made with a scope: its calls carry the fields of that scope, for the checker. */
73
+ type ScopedCommand<P, R, T extends string, F> = ((payload: P) => CommandCall<P, R> & WithScope<F>) & MadeCommand<P, R, T> & WithScope<F>;
49
74
  /**
50
75
  * Creates a command: a typed request for a result. Calling it builds
51
76
  * `{ type, payload }` like `createAction`. `bus.emit(command(payload))` (or
@@ -62,6 +87,11 @@ type MadeCommand<P, R, T extends string> = Command<P, R> & {
62
87
  * `command.match(action)` tells whether an action has the type of the command,
63
88
  * as it does for an action creator.
64
89
  *
90
+ * A scope as the third argument, `{ cache, effects: { race } }`, puts those fields on
91
+ * the context of the handler and of the listeners of the command; the handler
92
+ * sees them typed. It works on a bus that uses `scopePlugin` from
93
+ * `nanoeffects/scope` and is ignored on any other.
94
+ *
65
95
  * @example
66
96
  * ```ts
67
97
  * const getUser = createCommand("user/get", (id: string, { signal }) =>
@@ -76,7 +106,8 @@ type MadeCommand<P, R, T extends string> = Command<P, R> & {
76
106
  * commands.handle(getUser, async () => fakeUser); // in a test
77
107
  * ```
78
108
  */
79
- export declare const createCommand: <P = void, R = void, T extends string = string, E extends EventMap = EventMap>(type: T, handler?: Task<P, E, R>) => MadeCommand<P, R, T>;
109
+ export declare function createCommand<P = void, R = void, T extends string = string, E extends EventMap = EventMap>(type: T, handler?: Task<P, E, R>): MadeCommand<P, R, T>;
110
+ export declare function createCommand<P, R, T extends string, S extends Scope = Record<never, never>>(type: T, handler: Task<P, Scoped<EventMap, S>, R>, scope: S): ScopedCommand<P, R, T, FieldsOfScope<EventMap, S>>;
80
111
  /** A command (or its type) with the handler to bind to it; `bindHandler` makes one. */
81
112
  type Binding<E extends EventMap = EventMap> = readonly [Command<never, unknown> | string, Task<never, E, unknown>];
82
113
  /**
@@ -177,6 +208,9 @@ type Job<P, R, T extends string, S extends Outcome, F extends Outcome> = MadeCom
177
208
  * effect. It returns the command, with the two actions on it: `job.success` and
178
209
  * `job.fail`.
179
210
  *
211
+ * A scope as the last argument, `{ cache, effects: { race } }`, gives the handler
212
+ * and the listeners of the outcome those context fields; see `scopePlugin`.
213
+ *
180
214
  * `success` and `fail` are a type string, from which the job makes an action
181
215
  * creator with `createAction`, or an action creator that exists already, which
182
216
  * is used and returned as it is. A missing one is made with the type
@@ -201,12 +235,14 @@ type Job<P, R, T extends string, S extends Outcome, F extends Outcome> = MadeCom
201
235
  * bus.emit(loadUser("1")); // loadUser.success(user) or loadUser.fail(error) comes later
202
236
  * ```
203
237
  */
204
- export declare const createJob: <P = void, R = void, T extends string = string, E extends EventMap = EventMap, S extends Outcome = `${T}/success`, F extends Outcome = `${T}/fail`>(type: T, handler?: Task<P, E, R>, outcomes?: {
238
+ export declare const createJob: <P = void, R = void, T extends string = string, E extends EventMap = EventMap, S extends Outcome = `${T}/success`, F extends Outcome = `${T}/fail`, X extends Scope = Record<never, never>>(type: T, handler?: Task<P, Scoped<E, X>, R>, outcomes?: {
205
239
  /** Gets the result when the handler succeeds: a type to make an action creator of, or an action creator. */
206
240
  success?: S;
207
241
  /** Gets the error when the handler fails: a type to make an action creator of, or an action creator. */
208
242
  fail?: F;
209
- }) => Job<P, R, T, S, F>;
243
+ },
244
+ /** Context values and `effects` for the handler and for the listeners of the outcome; see `scopePlugin`. */
245
+ scope?: X) => CarryingCalls<Job<P, R, T, S, F>, P, Promise<Awaited<R> | undefined>, FieldsOfScope<E, X>>;
210
246
  //#endregion
211
247
  //#region src/actions/module.d.ts
212
248
  /**
@@ -241,6 +277,8 @@ type ModuleContext<E extends EventMap = EventMap> = Context<E> & {
241
277
  type Module<E extends EventMap = EventMap> = {
242
278
  readonly name: string;
243
279
  readonly setup: (m: ModuleContext<E>) => void;
280
+ /** Fields for everything the module owns; see `scopePlugin`. */
281
+ readonly scope?: Scope;
244
282
  };
245
283
  /**
246
284
  * Describes one domain of an app: the commands it handles, the events it
@@ -261,7 +299,8 @@ type Module<E extends EventMap = EventMap> = {
261
299
  * });
262
300
  * ```
263
301
  */
264
- export declare const createModule: <E extends EventMap = EventMap>(name: string, setup: (m: ModuleContext<E>) => void) => Module<E>;
302
+ export declare function createModule<E extends EventMap = EventMap>(name: string, setup: (m: ModuleContext<E>) => void): Module<E>;
303
+ export declare function createModule<E extends EventMap, S extends Scope = Record<never, never>>(name: string, setup: (m: ModuleContext<Scoped<E, S>>) => void, scope: S): Module<E>;
265
304
  type Registry<E extends EventMap> = ReturnType<ReturnType<typeof commandsPlugin<E>>>;
266
305
  /** What `modulePlugin` returns. */
267
306
  type ModuleApi<E extends EventMap = EventMap> = {
@@ -279,6 +318,7 @@ type ModuleApi<E extends EventMap = EventMap> = {
279
318
  * mounted, with no link to this bus.
280
319
  */
281
320
  createModule(name: string, setup: (m: ModuleContext<E>) => void): Module<E>;
321
+ createModule<S extends Scope = Record<never, never>>(name: string, setup: (m: ModuleContext<Scoped<E, S>>) => void, scope: S): Module<E>;
282
322
  };
283
323
  /**
284
324
  * The plugin that assembles an app from modules: `bus.use(modulePlugin(modules))`
@@ -1 +1 @@
1
- import{i as e,n as t,s as n}from"./context-CctVmHLC.js";import{a as r,r as i}from"./bus-Bdk0YyFQ.js";function a(e,t){return Object.assign((...n)=>({type:e,payload:t?t(...n).payload:n[0]}),{type:e,match:t=>t.type===e,toString:()=>e})}var o=class extends Error{};const s=(e,t)=>{let n=t=>t.type===e;function r(n,r){if(typeof r==`object`){if(!t)throw new o(`No handler for command "${e}"`);return t(n,r)}return i(a,e,n)}let a=Object.assign(r,{type:e,match:n});return a},c=(e,t)=>[e,t],l=(e=[])=>t=>{let n=/* @__PURE__ */ new Map,i=(e,t)=>{let r={fn:t};return n.set(e,[...n.get(e)??[],r]),()=>{let t=(n.get(e)??[]).filter(e=>e!==r);t.length>0?n.set(e,t):n.delete(e)}};function a(e,t){if(t)return i(r(e),t);let n=e.map(([e,t])=>i(r(e),t));return()=>{for(let e of n)e()}}a(e);let o={run:(e,t,r)=>{let i=(n.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,r])},handle:a};return t.commands=o,o},u=()=>e=>{function t(t){return(...n)=>{let r=t(...n);e.emit(r)}}return Object.assign(e,{emitter:t})},d=e=>typeof e==`string`?a(e):e,f=(e,t,n)=>{let r=e.emit;r(Reflect.apply(t,null,[n]))},p=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof o)throw e;return Promise.reject(e)}},m=(e,t,n={})=>{let r=s(e,t),a=d(n.success??`${e}/success`),o=d(n.fail??`${e}/fail`),c=(e,t,n)=>{let r=n;return p(()=>Reflect.apply(e,null,[t,n])).then(e=>(f(r,a,e),e),e=>{f(r,o,e)})},l=e=>(t,n)=>c(e,t,n);function u(t,n){return typeof n==`object`?c(r,t,n):i(m,e,t)}let m=Object.assign(u,{type:e,match:r.match,wrap:l,success:a,fail:o});return m},h=(e,t)=>({name:e,setup:t}),g=(r=[])=>i=>{let a=i.commands??l()(i),o={handle:(...e)=>{if(!a.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(a.handle,null,e)}},s=t({event:{type:`app`,payload:void 0},bus:i,tracer:i.trace}),c=t=>{let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;return{mount:a=>{let s=r.get(a);if(s)return s;let l=i.get(a.name);l&&r.get(l)?.();let u=e(t,a.name),d=u.ctx,f=c(d),p=()=>{r.delete(a),i.get(a.name)===a&&i.delete(a.name),d.abort(),u.unlink()};r.set(a,p),i.set(a.name,a);let m=(e,t)=>{let r=Reflect.apply(o.handle,null,[e,t]);return n(d,r),r},h=(...e)=>{let t=e.map(e=>typeof e==`function`?m(e,e):f.mount(e));return()=>{for(let e of t)e()}},g=(e,...t)=>{d.run(e,...t).catch(e=>{if(!d.signal.aborted)throw e})};try{a.setup(Object.assign(d,{handle:m,use:h,spawn:g}))}catch(e){throw p(),e}return p},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},u=c(s.ctx);for(let e of r)u.mount(e);return{commands:a,mount:e=>(s.ctx.signal.throwIfAborted(),u.mount(e)),unmount:u.unmount,isMounted:u.isMounted,dispose:()=>s.ctx.abort(),createModule:h}};export{c as bindHandler,l as commandsPlugin,a as createAction,s as createCommand,m as createJob,h as createModule,u as emitterPlugin,g as modulePlugin};
1
+ import{i as e,n as t,s as n}from"./context-CctVmHLC.js";import{a as r,r as i}from"./bus-Bdk0YyFQ.js";const a=Symbol.for(`nanoeffects.scope`),o=(e,t)=>(t&&Object.defineProperty(e,a,{value:t}),e);function s(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(o((...t)=>o({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var c=class extends Error{};function l(e,t,n){let r=t=>t.type===e;function a(r,a){if(typeof a==`object`){if(!t)throw new c(`No handler for command "${e}"`);return t(r,a)}return o(i(l,e,r),n)}let s=Object.assign(a,{type:e,match:r}),l=o(s,n);return l}const u=(e,t)=>[e,t],d=(e=[])=>t=>{let n=/* @__PURE__ */ new Map,i=(e,t)=>{let r={fn:t};return n.set(e,[...n.get(e)??[],r]),()=>{let t=(n.get(e)??[]).filter(e=>e!==r);t.length>0?n.set(e,t):n.delete(e)}};function a(e,t){if(t)return i(r(e),t);let n=e.map(([e,t])=>i(r(e),t));return()=>{for(let e of n)e()}}a(e);let o={run:(e,t,r)=>{let i=(n.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,r])},handle:a};return t.commands=o,o},f=()=>e=>{function t(t){return(...n)=>{let r=t(...n);e.emit(r)}}return Object.assign(e,{emitter:t})},p=e=>typeof e==`string`?s(e):e,m=(e,t,n,r)=>{let i=e.emit;i(Reflect.apply(t,null,[n]),r)},h=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof c)throw e;return Promise.reject(e)}},g=(e,t,n={},r)=>{let a=l(e,t),s=p(n.success??`${e}/success`),c=p(n.fail??`${e}/fail`),u=(e,t,n)=>{let i=n;return h(()=>Reflect.apply(e,null,[t,n])).then(e=>(m(i,s,e,r),e),e=>{m(i,c,e,r)})},d=e=>(t,n)=>u(e,t,n);function f(t,n){return typeof n==`object`?u(a,t,n):o(i(_,e,t),r)}let g=Object.assign(f,{type:e,match:a.match,wrap:d,success:s,fail:c}),_=o(g,r);return _};function _(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const v=(e,t)=>n=>t&&typeof n==`function`?e.fitScope?.(t,n)??n:n,y=(e,t,n)=>{n&&e.applyScope?.(t,n)},b=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],x=(e,t)=>{let n=e.on;return(...e)=>{let[r,i]=e;return Reflect.apply(n,null,[r,t(i)])}},S=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},C=(r=[])=>i=>{let a=i.commands??d()(i),o={handle:(...e)=>{if(!a.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(a.handle,null,e)}},s=t({event:{type:`app`,payload:void 0},bus:i,tracer:i.trace}),c=t=>{let r=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;return{mount:s=>{let l=r.get(s);if(l)return l;let u=a.get(s.name);u&&r.get(u)?.();let d=e(t,s.name),f=d.ctx,p=c(f),m=()=>{r.delete(s),a.get(s.name)===s&&a.delete(s.name),f.abort(),d.unlink()};r.set(s,m),a.set(s.name,s);let h=s.scope,g=v(i,h),_=(e,t)=>{let r=Reflect.apply(o.handle,null,b(g,e,t));return n(f,r),r},C=(...e)=>{let t=e.map(e=>typeof e==`function`?_(e,e):p.mount(e));return()=>{for(let e of t)e()}},w=S(f),T=x(f,g);try{y(i,f,h),s.setup(Object.assign(f,{handle:_,use:C,spawn:w,on:T}))}catch(e){throw m(),e}return m},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},l=c(s.ctx);for(let e of r)l.mount(e);return{commands:a,mount:e=>(s.ctx.signal.throwIfAborted(),l.mount(e)),unmount:l.unmount,isMounted:l.isMounted,dispose:()=>s.ctx.abort(),createModule:_}};export{u as bindHandler,d as commandsPlugin,s as createAction,l as createCommand,g as createJob,_ as createModule,f as emitterPlugin,C as modulePlugin};
@@ -1,4 +1,4 @@
1
- import { C as ContextOf, F as WithContext, _ as Bus, o as EventMap } from "./action-creator-DOWcbXpy.js";
1
+ import { R as EventMap, j as WithContext, p as Bus, y as ContextOf } from "./action-creator-DKG_sIia.js";
2
2
  //#region src/core/context-plugin.d.ts
3
3
  /** What a function that makes the fields of a task gets to see. */
4
4
  type ContextTask = {
@@ -1,91 +1,10 @@
1
- import { F as WithContext, S as Context, _ as Bus, o as EventMap, s as Keys, u as Task } from "./action-creator-DOWcbXpy.js";
2
- import { n as NoClash } from "./context-plugin-B0sLWOxR.js";
3
- //#region src/utils/delay.d.ts
4
- /**
5
- * Resolves after `ms`, or rejects early if `ctx.signal` aborts. `ms` can be a
6
- * function that returns the number of ms, called once when the delay starts:
7
- * handy for a random pause (jitter).
8
- *
9
- * @example
10
- * ```ts
11
- * await delay({}, 500);
12
- *
13
- * // 200 to 400 ms
14
- * await delay({}, () => 200 + Math.random() * 200);
15
- *
16
- * // inside a task: stops waiting when the task is aborted
17
- * bus.on("retry", async (_, ctx) => {
18
- * await delay(ctx, 1000);
19
- * await load();
20
- * });
21
- * ```
22
- */
23
- export declare const delay: (ctx: {
24
- signal?: AbortSignal | undefined;
25
- }, ms: number | (() => number)) => Promise<void>;
26
- //#endregion
1
+ import { H as Task, R as EventMap, l as Effect } from "./action-creator-DKG_sIia.js";
2
+ import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-B0AXKusc.js";
27
3
  //#region src/utils/onAbort.d.ts
28
4
  export declare const onAbort: (ctx: {
29
5
  signal?: AbortSignal | undefined;
30
6
  }, fn: (reason: unknown) => void) => (() => void);
31
7
  //#endregion
32
- //#region src/effects/run.d.ts
33
- /** Context passed into `race` / `all` effect starters. */
34
- type EffectContext = {
35
- signal: AbortSignal;
36
- abort: (reason?: unknown) => void;
37
- };
38
- type Starter<T> = (ctx: EffectContext) => T | PromiseLike<T>;
39
- //#endregion
40
- //#region src/effects/all.d.ts
41
- /**
42
- * Runs all starters; waits for every result. On failure or parent abort, cancels the rest.
43
- *
44
- * @example
45
- * ```ts
46
- * bus.on("load", async (id, ctx) => {
47
- * const { user, posts } = await all(ctx, {
48
- * user: ({ signal }) => fetchUser(id, { signal }),
49
- * posts: ({ signal }) => fetchPosts(id, { signal }),
50
- * });
51
- *
52
- * // arrays work too: const [user, posts] = await all(ctx, [getUser, getPosts]);
53
- * });
54
- * ```
55
- */
56
- export declare function all<T extends Record<string, Starter<unknown>>>(ctx: {
57
- signal?: AbortSignal;
58
- }, effects: T): Promise<{ [K in keyof T]: Awaited<ReturnType<T[K]>>; }>;
59
- export declare function all<const T extends readonly Starter<unknown>[]>(ctx: {
60
- signal?: AbortSignal;
61
- }, effects: T): Promise<{ -readonly [K in keyof T]: Awaited<ReturnType<T[K]>>; }>;
62
- //#endregion
63
- //#region src/effects/allSettled.d.ts
64
- /**
65
- * Runs all starters and waits for every one to settle, whether it succeeds or
66
- * fails: nothing is cancelled when a starter fails. The result has, for each
67
- * starter, `{ status: "fulfilled", value }` or `{ status: "rejected", reason }`.
68
- * Only an abort of `ctx` rejects it, with the abort reason.
69
- *
70
- * @example
71
- * ```ts
72
- * bus.on("load", async (id, ctx) => {
73
- * const { user, posts } = await allSettled(ctx, {
74
- * user: ({ signal }) => fetchUser(id, { signal }),
75
- * posts: ({ signal }) => fetchPosts(id, { signal }),
76
- * });
77
- *
78
- * if (user.status === "fulfilled") render(user.value);
79
- * });
80
- * ```
81
- */
82
- export declare function allSettled<T extends Record<string, Starter<unknown>>>(ctx: {
83
- signal?: AbortSignal;
84
- }, effects: T): Promise<{ [K in keyof T]: PromiseSettledResult<Awaited<ReturnType<T[K]>>>; }>;
85
- export declare function allSettled<const T extends readonly Starter<unknown>[]>(ctx: {
86
- signal?: AbortSignal;
87
- }, effects: T): Promise<{ -readonly [K in keyof T]: PromiseSettledResult<Awaited<ReturnType<T[K]>>>; }>;
88
- //#endregion
89
8
  //#region src/effects/backoff.d.ts
90
9
  type BackoffOptions = {
91
10
  /** Pause before the second attempt, in ms. Default 100. */
@@ -151,124 +70,6 @@ export declare const cancellable: <T = void>(ctx: {
151
70
  signal: AbortSignal;
152
71
  }, executor: CancellableExecutor<T>) => Promise<T>;
153
72
  //#endregion
154
- //#region src/effects/race.d.ts
155
- type RaceStarter<T> = Starter<T>;
156
- /**
157
- * Runs all starters; first to settle wins, losers are cancelled via `ctx.abort`.
158
- * The result holds only the winner's value, under its key or index.
159
- *
160
- * @example
161
- * ```ts
162
- * bus.on("load", async (id, ctx) => {
163
- * const result = await race(ctx, {
164
- * data: ({ signal }) => fetchData(id, { signal }),
165
- * timeout: ({ signal }) => delay({ signal }, 5000),
166
- * });
167
- *
168
- * if ("timeout" in result) throw new Error("timed out");
169
- * render(result.data);
170
- * });
171
- * ```
172
- */
173
- export declare function race<T extends Record<string, RaceStarter<unknown>>>(ctx: {
174
- signal?: AbortSignal;
175
- }, effects: T): Promise<{ [K in keyof T]?: Awaited<ReturnType<T[K]>>; }>;
176
- export declare function race<const T extends readonly RaceStarter<unknown>[]>(ctx: {
177
- signal?: AbortSignal;
178
- }, effects: T): Promise<{ -readonly [K in keyof T]?: Awaited<ReturnType<T[K]>>; }>;
179
- //#endregion
180
- //#region src/effects/take.d.ts
181
- type TakeOptions<P> = {
182
- /**
183
- * Wait for the first payload this accepts; others are skipped. A type guard
184
- * (`(payload): payload is T`) narrows the type of the result to `T`.
185
- */
186
- predicate?: (payload: P) => boolean;
187
- /** Stop waiting when this aborts, e.g. the signal of a `race` starter. */
188
- signal?: AbortSignal | undefined;
189
- };
190
- /**
191
- * Waits for the next `event` on the bus and resolves with its payload. It sees
192
- * only events emitted after the call, takes only one, and unsubscribes when it
193
- * is done. If `ctx` (or `options.signal`) aborts first, it unsubscribes and
194
- * rejects with the abort reason.
195
- *
196
- * @example
197
- * ```ts
198
- * bus.on("login", async (user, ctx) => {
199
- * const reason = await take(ctx, "logout");
200
- * cleanup(user, reason);
201
- * });
202
- *
203
- * // wait for a matching event, but not longer than 5 s
204
- * const done = await timeout(ctx, 5000, ({ signal }) =>
205
- * take(ctx, "saved", { signal, predicate: (id) => id === draftId }),
206
- * );
207
- *
208
- * // a type guard narrows the result: `failed` is `{ ok: false }`
209
- * const failed = await take(ctx, "result", {
210
- * predicate: (result): result is { ok: false } => !result.ok,
211
- * });
212
- * ```
213
- */
214
- export declare function take<E extends EventMap, K extends Keys<E>, T extends E[K]>(ctx: Context<E>, event: K, options: TakeOptions<E[K]> & {
215
- predicate: (payload: E[K]) => payload is T;
216
- }): Promise<T>;
217
- export declare function take<E extends EventMap, K extends Keys<E>>(ctx: Context<E>, event: K, options?: TakeOptions<E[K]>): Promise<E[K]>;
218
- //#endregion
219
- //#region src/effects/plugin.d.ts
220
- /** The effects that `effectsPlugin` can put on `ctx`. */
221
- type Supported = {
222
- race: typeof race;
223
- all: typeof all;
224
- allSettled: typeof allSettled;
225
- take: typeof take;
226
- delay: typeof delay;
227
- };
228
- type Results = Record<string, Starter<unknown>>;
229
- type List = readonly Starter<unknown>[];
230
- /** Each supported effect without its leading `ctx` argument. `take` knows the events of the bus. */
231
- type Bound<E extends EventMap> = {
232
- race: {
233
- <T extends Results>(effects: T): Promise<{ [K in keyof T]?: Awaited<ReturnType<T[K]>>; }>;
234
- <const T extends List>(effects: T): Promise<{ -readonly [K in keyof T]?: Awaited<ReturnType<T[K]>>; }>;
235
- };
236
- all: {
237
- <T extends Results>(effects: T): Promise<{ [K in keyof T]: Awaited<ReturnType<T[K]>>; }>;
238
- <const T extends List>(effects: T): Promise<{ -readonly [K in keyof T]: Awaited<ReturnType<T[K]>>; }>;
239
- };
240
- allSettled: {
241
- <T extends Results>(effects: T): Promise<{ [K in keyof T]: PromiseSettledResult<Awaited<ReturnType<T[K]>>>; }>;
242
- <const T extends List>(effects: T): Promise<{ -readonly [K in keyof T]: PromiseSettledResult<Awaited<ReturnType<T[K]>>>; }>;
243
- };
244
- take: <K extends Keys<E>>(event: K, options?: TakeOptions<E[K]>) => Promise<E[K]>;
245
- delay: (ms: number | (() => number)) => Promise<void>;
246
- };
247
- type Helpers = Partial<Supported>;
248
- type BoundOf<H extends Helpers, E extends EventMap> = { [K in keyof H & keyof Bound<E>]: Bound<E>[K]; };
249
- /**
250
- * Puts the effects you pass on the context of every task of the bus, bound to
251
- * that task, so a handler can write `({ race })` instead of `race(ctx, …)`.
252
- * The key is the name of the effect: `race`, `all`, `allSettled`, `take`,
253
- * `delay`. Returns the same bus, typed with the new fields.
254
- *
255
- * @example
256
- * ```ts
257
- * import { createBus } from "nanoeffects";
258
- * import { all, delay, effectsPlugin, race } from "nanoeffects/effects";
259
- *
260
- * const bus = createBus().use(effectsPlugin({ race, delay }));
261
- *
262
- * bus.on("load", async (id, { race, delay }) => {
263
- * const result = await race({
264
- * data: ({ signal }) => fetchData(id, { signal }),
265
- * timeout: () => delay(5000),
266
- * });
267
- * });
268
- * ```
269
- */
270
- export declare const effectsPlugin: <H extends Helpers>(helpers: H) => <E extends EventMap>(bus: Bus<E> & NoClash<BoundOf<H, E>, E>) => Bus<E & WithContext<BoundOf<H, E>>>;
271
- //#endregion
272
73
  //#region src/effects/poll.d.ts
273
74
  type PollOptions = {
274
75
  /** Also call `fn` at once, not only after the first `ms`. Default `false`. */
@@ -378,4 +179,4 @@ export declare function timeout<T>(ctx: {
378
179
  signal?: AbortSignal;
379
180
  }, ms: number, starter: Starter<T>): Promise<T>;
380
181
  //#endregion
381
- export type { BackoffOptions, CancellableExecutor, CancellableHandle, EffectContext, PollOptions, RaceStarter, RetryOptions, TakeOptions };
182
+ export { type BackoffOptions, type CancellableExecutor, type CancellableHandle, type Effect, type EffectContext, type PollOptions, type RaceStarter, type RetryOptions, type TakeOptions, all, allSettled, delay, effectsPlugin, race, take };
@@ -1,3 +1,3 @@
1
- import { A as EventsOf, B as anyEventType, C as ContextOf, D as EventKey, E as Emittable, F as WithContext, I as WithType, L as commandCall, M as HandlerRef, N as Off, O as EventLike, P as On, R as createBus, S as Context, T as Emit, _ as Bus, a as EffectName, b as CommandCall, c as PayloadOf, d as Trace, f as TraceEvent, g as AnyEvent, h as Action, i as WithPayload, j as Handler, k as EventPayload, l as Phase, m as UnsubscribeCallback, o as EventMap, p as TraceLogger, s as Keys, u as Task, v as BusOptions, w as ContextOption, x as Commands, y as Command, z as Tracer } from "./action-creator-DOWcbXpy.js";
2
- import { n as NoClash, r as contextPlugin, t as ContextTask } from "./context-plugin-B0sLWOxR.js";
1
+ import { A as On, B as PayloadOf, C as EventKey, D as Handler, E as EventsOf, F as Tracer, G as TraceLogger, H as Task, I as anyEventType, K as UnsubscribeCallback, L as EffectName, M as WithType, N as commandCall, O as HandlerRef, P as createBus, R as EventMap, S as Emittable, T as EventPayload, U as Trace, V as Phase, W as TraceEvent, _ as Commands, b as ContextOption, d as Action, f as AnyEvent, g as CommandCall, h as Command, i as WithPayload, j as WithContext, k as Off, m as BusOptions, p as Bus, v as Context, w as EventLike, x as Emit, y as ContextOf, z as Keys } from "./action-creator-DKG_sIia.js";
2
+ import { n as NoClash, r as contextPlugin, t as ContextTask } from "./context-plugin-Dt1IgVo8.js";
3
3
  export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type ContextTask, type EffectName, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type NoClash, type Off, type On, type PayloadOf, type Phase, type Task, type Trace, type TraceEvent, type TraceLogger, type Tracer, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, anyEventType, commandCall, contextPlugin, createBus };