@dxyl/utils 1.1.7 → 1.2.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.
@@ -0,0 +1,190 @@
1
+ import { Action, UnknownAction } from './actions';
2
+ import { Reducer } from './reducers';
3
+ /**
4
+ * A *dispatching function* (or simply *dispatch function*) is a function that
5
+ * accepts an action or an async action; it then may or may not dispatch one
6
+ * or more actions to the store.
7
+ *
8
+ * We must distinguish between dispatching functions in general and the base
9
+ * `dispatch` function provided by the store instance without any middleware.
10
+ *
11
+ * The base dispatch function *always* synchronously sends an action to the
12
+ * store's reducer, along with the previous state returned by the store, to
13
+ * calculate a new state. It expects actions to be plain objects ready to be
14
+ * consumed by the reducer.
15
+ *
16
+ * Middleware wraps the base dispatch function. It allows the dispatch
17
+ * function to handle async actions in addition to actions. Middleware may
18
+ * transform, delay, ignore, or otherwise interpret actions or async actions
19
+ * before passing them to the next middleware.
20
+ *
21
+ * @template A The type of things (actions or otherwise) which may be
22
+ * dispatched.
23
+ */
24
+ export interface Dispatch<A extends Action = UnknownAction> {
25
+ <T extends A>(action: T, ...extraArgs: any[]): T;
26
+ }
27
+ /**
28
+ * Function to remove listener added by `Store.subscribe()`.
29
+ */
30
+ export interface Unsubscribe {
31
+ (): void;
32
+ }
33
+ export type ListenerCallback = () => void;
34
+ declare global {
35
+ interface SymbolConstructor {
36
+ readonly observable: symbol;
37
+ }
38
+ }
39
+ /**
40
+ * A minimal observable of state changes.
41
+ * For more information, see the observable proposal:
42
+ * https://github.com/tc39/proposal-observable
43
+ */
44
+ export type Observable<T> = {
45
+ /**
46
+ * The minimal observable subscription method.
47
+ * @param {Object} observer Any object that can be used as an observer.
48
+ * The observer object should have a `next` method.
49
+ * @returns {subscription} An object with an `unsubscribe` method that can
50
+ * be used to unsubscribe the observable from the store, and prevent further
51
+ * emission of values from the observable.
52
+ */
53
+ subscribe: (observer: Observer<T>) => {
54
+ unsubscribe: Unsubscribe;
55
+ };
56
+ [Symbol.observable](): Observable<T>;
57
+ };
58
+ /**
59
+ * An Observer is used to receive data from an Observable, and is supplied as
60
+ * an argument to subscribe.
61
+ */
62
+ export type Observer<T> = {
63
+ next?(value: T): void;
64
+ };
65
+ /**
66
+ * A store is an object that holds the application's state tree.
67
+ * There should only be a single store in a Redux app, as the composition
68
+ * happens on the reducer level.
69
+ *
70
+ * @template S The type of state held by this store.
71
+ * @template A the type of actions which may be dispatched by this store.
72
+ * @template StateExt any extension to state from store enhancers
73
+ */
74
+ export interface Store<S = any, A extends Action = UnknownAction, StateExt extends unknown = unknown> {
75
+ /**
76
+ * Dispatches an action. It is the only way to trigger a state change.
77
+ *
78
+ * The `reducer` function, used to create the store, will be called with the
79
+ * current state tree and the given `action`. Its return value will be
80
+ * considered the **next** state of the tree, and the change listeners will
81
+ * be notified.
82
+ *
83
+ * The base implementation only supports plain object actions. If you want
84
+ * to dispatch a Promise, an Observable, a thunk, or something else, you
85
+ * need to wrap your store creating function into the corresponding
86
+ * middleware. For example, see the documentation for the `redux-thunk`
87
+ * package. Even the middleware will eventually dispatch plain object
88
+ * actions using this method.
89
+ *
90
+ * @param action A plain object representing “what changed”. It is a good
91
+ * idea to keep actions serializable so you can record and replay user
92
+ * sessions, or use the time travelling `redux-devtools`. An action must
93
+ * have a `type` property which may not be `undefined`. It is a good idea
94
+ * to use string constants for action types.
95
+ *
96
+ * @returns For convenience, the same action object you dispatched.
97
+ *
98
+ * Note that, if you use a custom middleware, it may wrap `dispatch()` to
99
+ * return something else (for example, a Promise you can await).
100
+ */
101
+ dispatch: Dispatch<A>;
102
+ /**
103
+ * Reads the state tree managed by the store.
104
+ *
105
+ * @returns The current state tree of your application.
106
+ */
107
+ getState(): S & StateExt;
108
+ /**
109
+ * Adds a change listener. It will be called any time an action is
110
+ * dispatched, and some part of the state tree may potentially have changed.
111
+ * You may then call `getState()` to read the current state tree inside the
112
+ * callback.
113
+ *
114
+ * You may call `dispatch()` from a change listener, with the following
115
+ * caveats:
116
+ *
117
+ * 1. The subscriptions are snapshotted just before every `dispatch()` call.
118
+ * If you subscribe or unsubscribe while the listeners are being invoked,
119
+ * this will not have any effect on the `dispatch()` that is currently in
120
+ * progress. However, the next `dispatch()` call, whether nested or not,
121
+ * will use a more recent snapshot of the subscription list.
122
+ *
123
+ * 2. The listener should not expect to see all states changes, as the state
124
+ * might have been updated multiple times during a nested `dispatch()` before
125
+ * the listener is called. It is, however, guaranteed that all subscribers
126
+ * registered before the `dispatch()` started will be called with the latest
127
+ * state by the time it exits.
128
+ *
129
+ * @param listener A callback to be invoked on every dispatch.
130
+ * @returns A function to remove this change listener.
131
+ */
132
+ subscribe(listener: ListenerCallback): Unsubscribe;
133
+ /**
134
+ * Replaces the reducer currently used by the store to calculate the state.
135
+ *
136
+ * You might need this if your app implements code splitting and you want to
137
+ * load some of the reducers dynamically. You might also need this if you
138
+ * implement a hot reloading mechanism for Redux.
139
+ *
140
+ * @param nextReducer The reducer for the store to use instead.
141
+ */
142
+ replaceReducer(nextReducer: Reducer<S, A>): void;
143
+ /**
144
+ * Interoperability point for observable/reactive libraries.
145
+ * @returns {observable} A minimal observable of state changes.
146
+ * For more information, see the observable proposal:
147
+ * https://github.com/tc39/proposal-observable
148
+ */
149
+ [Symbol.observable](): Observable<S & StateExt>;
150
+ }
151
+ export type UnknownIfNonSpecific<T> = {} extends T ? unknown : T;
152
+ /**
153
+ * A store creator is a function that creates a Redux store. Like with
154
+ * dispatching function, we must distinguish the base store creator,
155
+ * `createStore(reducer, preloadedState)` exported from the Redux package, from
156
+ * store creators that are returned from the store enhancers.
157
+ *
158
+ * @template S The type of state to be held by the store.
159
+ * @template A The type of actions which may be dispatched.
160
+ * @template PreloadedState The initial state that is passed into the reducer.
161
+ * @template Ext Store extension that is mixed in to the Store type.
162
+ * @template StateExt State extension that is mixed into the state type.
163
+ */
164
+ export interface StoreCreator {
165
+ <S, A extends Action, Ext extends {} = {}, StateExt extends {} = {}>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<Ext, StateExt>): Store<S, A, UnknownIfNonSpecific<StateExt>> & Ext;
166
+ <S, A extends Action, Ext extends {} = {}, StateExt extends {} = {}, PreloadedState = S>(reducer: Reducer<S, A, PreloadedState>, preloadedState?: PreloadedState | undefined, enhancer?: StoreEnhancer<Ext>): Store<S, A, UnknownIfNonSpecific<StateExt>> & Ext;
167
+ }
168
+ /**
169
+ * A store enhancer is a higher-order function that composes a store creator
170
+ * to return a new, enhanced store creator. This is similar to middleware in
171
+ * that it allows you to alter the store interface in a composable way.
172
+ *
173
+ * Store enhancers are much the same concept as higher-order components in
174
+ * React, which are also occasionally called “component enhancers”.
175
+ *
176
+ * Because a store is not an instance, but rather a plain-object collection of
177
+ * functions, copies can be easily created and modified without mutating the
178
+ * original store. There is an example in `compose` documentation
179
+ * demonstrating that.
180
+ *
181
+ * Most likely you'll never write a store enhancer, but you may use the one
182
+ * provided by the developer tools. It is what makes time travel possible
183
+ * without the app being aware it is happening. Amusingly, the Redux
184
+ * middleware implementation is itself a store enhancer.
185
+ *
186
+ * @template Ext Store extension that is mixed into the Store type.
187
+ * @template StateExt State extension that is mixed into the state type.
188
+ */
189
+ export type StoreEnhancer<Ext extends {} = {}, StateExt extends {} = {}> = <NextExt extends {}, NextStateExt extends {}>(next: StoreEnhancerStoreCreator<NextExt, NextStateExt>) => StoreEnhancerStoreCreator<NextExt & Ext, NextStateExt & StateExt>;
190
+ export type StoreEnhancerStoreCreator<Ext extends {} = {}, StateExt extends {} = {}> = <S, A extends Action, PreloadedState>(reducer: Reducer<S, A, PreloadedState>, preloadedState?: PreloadedState | undefined) => Store<S, A, StateExt> & Ext;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * These are private action types reserved by Redux.
3
+ * For any unknown actions, you must return the current state.
4
+ * If the current state is undefined, you must return the initial state.
5
+ * Do not reference these action types directly in your code.
6
+ */
7
+ declare const ActionTypes: {
8
+ INIT: string;
9
+ REPLACE: string;
10
+ PROBE_UNKNOWN_ACTION: () => string;
11
+ };
12
+ export default ActionTypes;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js
3
+ *
4
+ * Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes
5
+ * during build.
6
+ * @param {number} code
7
+ */
8
+ export declare function formatProdErrorMessage(code: number): string;
@@ -0,0 +1,2 @@
1
+ import { Action } from '../types/actions';
2
+ export default function isAction(action: unknown): action is Action<string>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @param obj The object to inspect.
3
+ * @returns True if the argument appears to be a plain object.
4
+ */
5
+ export default function isPlainObject(obj: any): obj is object;
@@ -0,0 +1,2 @@
1
+ export declare function miniKindOf(val: any): string;
2
+ export declare function kindOf(val: any): string;
@@ -0,0 +1,7 @@
1
+ declare global {
2
+ interface SymbolConstructor {
3
+ readonly observable: symbol;
4
+ }
5
+ }
6
+ declare const $$observable: string | typeof Symbol.observable;
7
+ export default $$observable;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Prints a warning in the console if it exists.
3
+ *
4
+ * @param message The warning message.
5
+ */
6
+ export default function warning(message: string): void;
@@ -1,28 +1,161 @@
1
- export function merge(...sources: any[]): Observable;
2
- export function combineLatest(...sources: any[]): Observable;
3
- export function zip(...sources: any[]): Observable;
4
- export class Observable {
5
- [x: number]: () => this;
6
- static from(x: any): Observable;
7
- static of(...items: any[]): Observable;
8
- constructor(subscriber: any);
9
- _subscriber: any;
10
- subscribe(observer: any, ...args: any[]): Subscription;
11
- forEach(fn: any): Promise<any>;
12
- map(fn: any): any;
13
- filter(fn: any): any;
14
- reduce(fn: any, ...args: any[]): any;
15
- all(): Promise<any[]>;
16
- concat(...sources: any[]): any;
17
- flatMap(fn: any): any;
18
- }
19
- declare class Subscription {
20
- constructor(observer: any, subscriber: any);
21
- _cleanup: any;
22
- _observer: any;
23
- _queue: any;
24
- _state: string;
25
- get closed(): boolean;
26
- unsubscribe(): void;
27
- }
28
- export {};
1
+ declare global {
2
+ interface SymbolConstructor {
3
+ readonly observable: symbol;
4
+ }
5
+
6
+ namespace ZenObservable {
7
+ interface SubscriptionObserver<T> {
8
+ closed: boolean;
9
+ next(value: T): void;
10
+ error(errorValue: any): void;
11
+ complete(): void;
12
+ }
13
+
14
+ interface Subscription {
15
+ closed: boolean;
16
+ unsubscribe(): void;
17
+ }
18
+
19
+ interface Observer<T> {
20
+ start?(subscription: Subscription): any;
21
+ next?(value: T): void;
22
+ error?(errorValue: any): void;
23
+ complete?(): void;
24
+ }
25
+
26
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
27
+ type Subscriber<T> = (observer: SubscriptionObserver<T>) => void | (() => void) | Subscription;
28
+
29
+ interface ObservableLike<T> {
30
+ subscribe?: Subscriber<T> | undefined;
31
+ [Symbol.observable](): Observable<T> | ObservableLike<T>;
32
+ }
33
+ }
34
+ }
35
+
36
+ declare class Observable<T> {
37
+ constructor(subscriber: ZenObservable.Subscriber<T>);
38
+
39
+ subscribe(observer: ZenObservable.Observer<T>): ZenObservable.Subscription;
40
+ subscribe(
41
+ onNext: (value: T) => void,
42
+ onError?: (error: any) => void,
43
+ onComplete?: () => void,
44
+ ): ZenObservable.Subscription;
45
+
46
+ [Symbol.observable](): Observable<T>;
47
+
48
+ forEach(callback: (value: T) => void): Promise<void>;
49
+ map<R>(callback: (value: T) => R): Observable<R>;
50
+ filter<S extends T>(callback: (value: T) => value is S): Observable<S>;
51
+ filter(callback: (value: T) => boolean): Observable<T>;
52
+ reduce(callback: (previousValue: T, currentValue: T) => T, initialValue?: T): Observable<T>;
53
+ reduce<R>(callback: (previousValue: R, currentValue: T) => R, initialValue?: R): Observable<R>;
54
+ flatMap<R>(callback: (value: T) => ZenObservable.ObservableLike<R>): Observable<R>;
55
+ concat<R>(...observable: Array<Observable<R>>): Observable<R>;
56
+
57
+ static from<R>(observable: Observable<R> | ZenObservable.ObservableLike<R> | ArrayLike<R>): Observable<R>;
58
+ static of<R>(...items: R[]): Observable<R>;
59
+ }
60
+
61
+ declare namespace Observable {}
62
+
63
+
64
+ export function merge(): Observable<never>;
65
+ export function merge<A>(a: ZenObservable.ObservableLike<A>): Observable<A>;
66
+ export function merge<A, B>(a: ZenObservable.ObservableLike<A>, b: ZenObservable.ObservableLike<B>): Observable<A | B>;
67
+ export function merge<A, B, C>(
68
+ a: ZenObservable.ObservableLike<A>,
69
+ b: ZenObservable.ObservableLike<B>,
70
+ c: ZenObservable.ObservableLike<C>,
71
+ ): Observable<A | B | C>;
72
+ export function merge<A, B, C, D>(
73
+ a: ZenObservable.ObservableLike<A>,
74
+ b: ZenObservable.ObservableLike<B>,
75
+ c: ZenObservable.ObservableLike<C>,
76
+ d: ZenObservable.ObservableLike<D>,
77
+ ): Observable<A | B | C | D>;
78
+ export function merge<A, B, C, D, E>(
79
+ a: ZenObservable.ObservableLike<A>,
80
+ b: ZenObservable.ObservableLike<B>,
81
+ c: ZenObservable.ObservableLike<C>,
82
+ d: ZenObservable.ObservableLike<D>,
83
+ e: ZenObservable.ObservableLike<E>,
84
+ ): Observable<A | B | C | D | E>;
85
+ export function merge<A, B, C, D, E, F>(
86
+ a: ZenObservable.ObservableLike<A>,
87
+ b: ZenObservable.ObservableLike<B>,
88
+ c: ZenObservable.ObservableLike<C>,
89
+ d: ZenObservable.ObservableLike<D>,
90
+ e: ZenObservable.ObservableLike<E>,
91
+ f: ZenObservable.ObservableLike<F>,
92
+ ): Observable<A | B | C | D | E | F>;
93
+ export function merge<T>(...observables: Array<ZenObservable.ObservableLike<T>>): Observable<T>;
94
+
95
+ export function combineLatest(): Observable<never>;
96
+ export function combineLatest<A>(a: ZenObservable.ObservableLike<A>): Observable<[A]>;
97
+ export function combineLatest<A, B>(
98
+ a: ZenObservable.ObservableLike<A>,
99
+ b: ZenObservable.ObservableLike<B>,
100
+ ): Observable<[A, B]>;
101
+ export function combineLatest<A, B, C>(
102
+ a: ZenObservable.ObservableLike<A>,
103
+ b: ZenObservable.ObservableLike<B>,
104
+ c: ZenObservable.ObservableLike<C>,
105
+ ): Observable<[A, B, C]>;
106
+ export function combineLatest<A, B, C, D>(
107
+ a: ZenObservable.ObservableLike<A>,
108
+ b: ZenObservable.ObservableLike<B>,
109
+ c: ZenObservable.ObservableLike<C>,
110
+ d: ZenObservable.ObservableLike<D>,
111
+ ): Observable<[A, B, C, D]>;
112
+ export function combineLatest<A, B, C, D, E>(
113
+ a: ZenObservable.ObservableLike<A>,
114
+ b: ZenObservable.ObservableLike<B>,
115
+ c: ZenObservable.ObservableLike<C>,
116
+ d: ZenObservable.ObservableLike<D>,
117
+ e: ZenObservable.ObservableLike<E>,
118
+ ): Observable<[A, B, C, D, E]>;
119
+ export function combineLatest<A, B, C, D, E, F>(
120
+ a: ZenObservable.ObservableLike<A>,
121
+ b: ZenObservable.ObservableLike<B>,
122
+ c: ZenObservable.ObservableLike<C>,
123
+ d: ZenObservable.ObservableLike<D>,
124
+ e: ZenObservable.ObservableLike<E>,
125
+ f: ZenObservable.ObservableLike<F>,
126
+ ): Observable<[A, B, C, D, E, F]>;
127
+ export function combineLatest<T>(...observables: Array<ZenObservable.ObservableLike<T>>): Observable<T[]>;
128
+
129
+ export function zip(): Observable<never>;
130
+ export function zip<A>(a: ZenObservable.ObservableLike<A>): Observable<[A]>;
131
+ export function zip<A, B>(a: ZenObservable.ObservableLike<A>, b: ZenObservable.ObservableLike<B>): Observable<[A, B]>;
132
+ export function zip<A, B, C>(
133
+ a: ZenObservable.ObservableLike<A>,
134
+ b: ZenObservable.ObservableLike<B>,
135
+ c: ZenObservable.ObservableLike<C>,
136
+ ): Observable<[A, B, C]>;
137
+ export function zip<A, B, C, D>(
138
+ a: ZenObservable.ObservableLike<A>,
139
+ b: ZenObservable.ObservableLike<B>,
140
+ c: ZenObservable.ObservableLike<C>,
141
+ d: ZenObservable.ObservableLike<D>,
142
+ ): Observable<[A, B, C, D]>;
143
+ export function zip<A, B, C, D, E>(
144
+ a: ZenObservable.ObservableLike<A>,
145
+ b: ZenObservable.ObservableLike<B>,
146
+ c: ZenObservable.ObservableLike<C>,
147
+ d: ZenObservable.ObservableLike<D>,
148
+ e: ZenObservable.ObservableLike<E>,
149
+ ): Observable<[A, B, C, D, E]>;
150
+ export function zip<A, B, C, D, E, F>(
151
+ a: ZenObservable.ObservableLike<A>,
152
+ b: ZenObservable.ObservableLike<B>,
153
+ c: ZenObservable.ObservableLike<C>,
154
+ d: ZenObservable.ObservableLike<D>,
155
+ e: ZenObservable.ObservableLike<E>,
156
+ f: ZenObservable.ObservableLike<F>,
157
+ ): Observable<[A, B, C, D, E, F]>;
158
+ export function zip<T>(...observables: Array<ZenObservable.ObservableLike<T>>): Observable<T[]>;
159
+ export {
160
+ Observable
161
+ };
@@ -0,0 +1,18 @@
1
+ type HandleContext = {
2
+ stop: () => void;
3
+ remove: () => void;
4
+ };
5
+ type Handle<T extends any[]> = (...args: [...T, context: HandleContext]) => void;
6
+ type Options = {
7
+ stage?: number;
8
+ once?: boolean;
9
+ };
10
+ type Unsubscribe = () => void;
11
+ interface Signals<T extends any[]> {
12
+ add(handle: Handle<T>, options?: Options): Unsubscribe;
13
+ remove(handle: Handle<T>): void;
14
+ dispatch(...args: T): void;
15
+ clear(): void;
16
+ }
17
+ export declare function Signals<T extends any[]>(): Signals<T>;
18
+ export {};
@@ -45,7 +45,7 @@ export interface EventTarget<Events extends Record<string, any> = {}> {
45
45
  emit<K extends Extract<keyof Events, string>>(e: Event<Events[K], K>): void;
46
46
  }
47
47
  export declare class EventTarget<Events extends Record<string, any> = {}> {
48
- parentNode: EventTarget | null;
48
+ parent: EventTarget | null;
49
49
  private _bubble_emitter;
50
50
  private _capture_emitter;
51
51
  addEventListener<K extends keyof Events>(type: K, fn: EventCallback<Events[K]>, options?: EventOptions | boolean): void;
package/types/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export * from './events/eventemitter3';
3
3
  export * from './events/mitt';
4
4
  export { EventEmitter4, Emitter4Event } from './events/eventmitter';
5
5
  export { default as mitt } from './events/mitt';
6
+ export * as observable from './events/Observable';
7
+ export { Signals } from './events/Signals';
6
8
  export * from './callbacks';
7
9
  export * from './ismobilejs';
8
10
  export * from './priority_queue';
@@ -15,8 +17,13 @@ export * as immer from './data/immer';
15
17
  export * as Immutable from './data/immutable';
16
18
  export * as reactivity from './data/reactivity';
17
19
  export * as signals from './data/signals';
20
+ export * as redux from './data/redux';
21
+ export * as mobx from './data/mobx';
22
+ export * as tapable from './tapable';
18
23
  export { Options } from './Options';
24
+ export { default as compose } from './compose';
19
25
  export type { OptionsProperties, OptionConfig } from './Options';
20
26
  export { default as deepmerge } from './deepmerge';
21
27
  export { default as fastDeepEqual } from './fast-deep-equal';
22
28
  export * from './Color';
29
+ export * as colord from './color/colord/src';
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Checks if `value` is equal to `check` if `check` is a string or in `check` if check is an Array
3
+ *
4
+ * @param value - the value being searched for
5
+ * @param check - the values to check against
6
+ * @returns `boolean`
7
+ */
8
+ export declare function equalToOrIn(value: string, check: string | Array<string>): boolean;
9
+ export type Interceptor<Args extends any[], ReturnType, ContextType> = {
10
+ /** An optional name for the interceptor */
11
+ name?: string;
12
+ /** Callback for each loop when used by the hook */
13
+ loop?: (...args: Args) => void;
14
+ /** Callback when an error occurs during the hook's call */
15
+ error?: (err: Error) => void;
16
+ /** Callback when a result is found for a hook's invocation */
17
+ result?: (r: ReturnType extends Promise<infer AwaitedValue> ? AwaitedValue : ReturnType) => void;
18
+ /** Callback when a hook's call is complete */
19
+ done?: () => void;
20
+ /** Callback when a hook is tapped */
21
+ tap?: (tap: Tap<Args, ReturnType, ContextType>) => void;
22
+ } & ({
23
+ /** If context should be omitted from the 'call'. This is the default */
24
+ context?: false;
25
+ /** Callback when the hook is tapped without context */
26
+ call?: (...args: Args) => void;
27
+ } | {
28
+ /** If context should be included in the 'call' */
29
+ context: true;
30
+ /** Callback when the hook is tapped with context */
31
+ call?: (context: ContextType, ...args: Args) => void;
32
+ });
33
+ export type Tap<Args extends any[], ReturnType, ContextType = unknown> = {
34
+ key: symbol;
35
+ name: string;
36
+ before?: string | Array<string>;
37
+ } & ({
38
+ context: false;
39
+ callback: (...args: Args) => ReturnType;
40
+ } | {
41
+ context: true;
42
+ callback: (context: ContextType, ...args: Args) => ReturnType;
43
+ });
44
+ type BasicTap<Args extends any[], ReturnType, ContextType> = (name: string, callback: (...args: Args) => ReturnType, before?: string | Array<string>) => Tap<Args, ReturnType, ContextType>;
45
+ type TapWithContext<Args extends any[], ReturnType, ContextType> = ((options: {
46
+ name: string;
47
+ context?: false;
48
+ before?: string | Array<string>;
49
+ }, callback: (...args: Args) => ReturnType) => Tap<Args, ReturnType>) | ((options: {
50
+ name: string;
51
+ context: true;
52
+ before?: string | Array<string>;
53
+ }, callback: (context: ContextType, ...args: Args) => ReturnType) => Tap<Args, ReturnType>);
54
+ interface SyncBaseHookType<Args extends any[], ReturnType, ContextType> {
55
+ tap: BasicTap<Args, ReturnType, ContextType> | TapWithContext<Args, ReturnType, ContextType>;
56
+ call(...args: Args): void;
57
+ untap(key: Tap<Args, ReturnType>): void;
58
+ isUsed(): boolean;
59
+ intercept(int: Interceptor<Args, ReturnType, ContextType>): void;
60
+ }
61
+ /** A manager for all intercepts inside of a tap */
62
+ declare class InterceptionManager<Args extends any[], ReturnType, ContextType = Record<string, any>> {
63
+ protected interceptions: Array<Interceptor<Args, ReturnType, ContextType>>;
64
+ private interceptionKeySet;
65
+ constructor();
66
+ isUsed(): boolean;
67
+ intercept(int: Interceptor<Args, ReturnType, ContextType>): void;
68
+ tap(tap: Tap<Args, ReturnType, ContextType>): void;
69
+ call(ctx: ContextType, ...args: Args): void;
70
+ loop(...args: Args): void;
71
+ error(err: unknown): void;
72
+ result(r: ReturnType extends Promise<infer AwaitedValue> ? AwaitedValue : ReturnType): void;
73
+ done(): void;
74
+ }
75
+ declare abstract class Hook<Args extends any[], ReturnType, ContextType = Record<string, any>> implements SyncBaseHookType<Args, ReturnType, ContextType> {
76
+ protected taps: Array<Tap<Args, ReturnType, ContextType>>;
77
+ protected interceptions: InterceptionManager<Args, ReturnType, ContextType>;
78
+ constructor();
79
+ tap(options: {
80
+ name: string;
81
+ context?: false;
82
+ before?: string | Array<string>;
83
+ }, callback: (...args: Args) => ReturnType): Tap<Args, ReturnType, ContextType>;
84
+ tap(options: {
85
+ name: string;
86
+ context: true;
87
+ before?: string | Array<string>;
88
+ }, callback: (ctx: ContextType, ...args: Args) => ReturnType): Tap<Args, ReturnType, ContextType>;
89
+ tap(name: string, callback: (...args: Args) => ReturnType): Tap<Args, ReturnType, ContextType>;
90
+ abstract call(...args: Args): ReturnType;
91
+ untap(tap: Tap<Args, ReturnType, ContextType>): void;
92
+ isUsed(): boolean;
93
+ intercept(int: Interceptor<Args, ReturnType, ContextType>): void;
94
+ }
95
+ export declare class SyncHook<Args extends any[], ContextType = Record<string, any>> extends Hook<Args, void, ContextType> {
96
+ call(...args: Args): void;
97
+ }
98
+ export declare class SyncBailHook<Args extends any[], ReturnType, ContextType = Record<string, any>> extends Hook<Args, ReturnType | undefined | null, ContextType> {
99
+ call(...args: Args): ReturnType | undefined | null;
100
+ }
101
+ export declare class SyncWaterfallHook<Args extends any[], ContextType = Record<string, any>> extends Hook<Args, Args[0], ContextType> {
102
+ call(...args: Args): Args[0];
103
+ }
104
+ export declare class SyncLoopHook<Args extends any[], ContextType = Record<string, any>> extends Hook<Args, void, ContextType> {
105
+ call(...args: Args): void;
106
+ }
107
+ export declare class AsyncParallelHook<Args extends any[], ContextType = Record<string, any>> extends Hook<Args, Promise<void>, ContextType> {
108
+ call(...args: Args): Promise<void>;
109
+ }
110
+ export declare class AsyncParallelBailHook<Args extends any[], ReturnType, ContextType = Record<string, any>> extends Hook<Args, Promise<ReturnType>, ContextType> {
111
+ call(...args: Args): Promise<ReturnType>;
112
+ }
113
+ export declare class AsyncSeriesHook<Args extends any[], ContextType = Record<string, any>> extends Hook<Args, Promise<void>, ContextType> {
114
+ call(...args: Args): Promise<void>;
115
+ }
116
+ export declare class AsyncSeriesBailHook<Args extends any[], ReturnType, ContextType = Record<string, any>> extends Hook<Args, Promise<ReturnType | undefined | null>, ContextType> {
117
+ call(...args: Args): Promise<ReturnType | undefined | null>;
118
+ }
119
+ export declare class AsyncSeriesWaterfallHook<Args extends any[], ContextType = Record<string, any>> extends Hook<Args, Promise<Args[0]>, ContextType> {
120
+ call(...args: Args): Promise<Args[0]>;
121
+ }
122
+ export declare class AsyncSeriesLoopHook<Args extends any[], ContextType = Record<string, any>> extends Hook<Args, Promise<void>, ContextType> {
123
+ call(...args: Args): Promise<void>;
124
+ }
125
+ export {};