source: trip-planner-front/node_modules/tapable/tapable.d.ts@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.3 KB
Line 
1type FixedSizeArray<T extends number, U> = T extends 0
2 ? void[]
3 : ReadonlyArray<U> & {
4 0: U;
5 length: T;
6 };
7type Measure<T extends number> = T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
8 ? T
9 : never;
10type Append<T extends any[], U> = {
11 0: [U];
12 1: [T[0], U];
13 2: [T[0], T[1], U];
14 3: [T[0], T[1], T[2], U];
15 4: [T[0], T[1], T[2], T[3], U];
16 5: [T[0], T[1], T[2], T[3], T[4], U];
17 6: [T[0], T[1], T[2], T[3], T[4], T[5], U];
18 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], U];
19 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], U];
20}[Measure<T["length"]>];
21type AsArray<T> = T extends any[] ? T : [T];
22
23declare class UnsetAdditionalOptions {
24 _UnsetAdditionalOptions: true
25}
26type IfSet<X> = X extends UnsetAdditionalOptions ? {} : X;
27
28type Callback<E, T> = (error: E | null, result?: T) => void;
29type InnerCallback<E, T> = (error?: E | null | false, result?: T) => void;
30
31type FullTap = Tap & {
32 type: "sync" | "async" | "promise",
33 fn: Function
34}
35
36type Tap = TapOptions & {
37 name: string;
38};
39
40type TapOptions = {
41 before?: string;
42 stage?: number;
43};
44
45interface HookInterceptor<T, R, AdditionalOptions = UnsetAdditionalOptions> {
46 name?: string;
47 tap?: (tap: FullTap & IfSet<AdditionalOptions>) => void;
48 call?: (...args: any[]) => void;
49 loop?: (...args: any[]) => void;
50 error?: (err: Error) => void;
51 result?: (result: R) => void;
52 done?: () => void;
53 register?: (tap: FullTap & IfSet<AdditionalOptions>) => FullTap & IfSet<AdditionalOptions>;
54}
55
56type ArgumentNames<T extends any[]> = FixedSizeArray<T["length"], string>;
57
58declare class Hook<T, R, AdditionalOptions = UnsetAdditionalOptions> {
59 constructor(args?: ArgumentNames<AsArray<T>>, name?: string);
60 name: string | undefined;
61 taps: FullTap[];
62 intercept(interceptor: HookInterceptor<T, R, AdditionalOptions>): void;
63 isUsed(): boolean;
64 callAsync(...args: Append<AsArray<T>, Callback<Error, R>>): void;
65 promise(...args: AsArray<T>): Promise<R>;
66 tap(options: string | Tap & IfSet<AdditionalOptions>, fn: (...args: AsArray<T>) => R): void;
67 withOptions(options: TapOptions & IfSet<AdditionalOptions>): Omit<this, "call" | "callAsync" | "promise">;
68}
69
70export class SyncHook<T, R = void, AdditionalOptions = UnsetAdditionalOptions> extends Hook<T, R, AdditionalOptions> {
71 call(...args: AsArray<T>): R;
72}
73
74export class SyncBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, R, AdditionalOptions> {}
75export class SyncLoopHook<T, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, void, AdditionalOptions> {}
76export class SyncWaterfallHook<T, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, AsArray<T>[0], AdditionalOptions> {}
77
78declare class AsyncHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends Hook<T, R, AdditionalOptions> {
79 tapAsync(
80 options: string | Tap & IfSet<AdditionalOptions>,
81 fn: (...args: Append<AsArray<T>, InnerCallback<Error, R>>) => void
82 ): void;
83 tapPromise(
84 options: string | Tap & IfSet<AdditionalOptions>,
85 fn: (...args: AsArray<T>) => Promise<R>
86 ): void;
87}
88
89export class AsyncParallelHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {}
90export class AsyncParallelBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, R, AdditionalOptions> {}
91export class AsyncSeriesHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {}
92export class AsyncSeriesBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, R, AdditionalOptions> {}
93export class AsyncSeriesLoopHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {}
94export class AsyncSeriesWaterfallHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, AsArray<T>[0], AdditionalOptions> {}
95
96type HookFactory<H> = (key: any, hook?: H) => H;
97
98interface HookMapInterceptor<H> {
99 factory?: HookFactory<H>;
100}
101
102export class HookMap<H> {
103 constructor(factory: HookFactory<H>, name?: string);
104 name: string | undefined;
105 get(key: any): H | undefined;
106 for(key: any): H;
107 intercept(interceptor: HookMapInterceptor<H>): void;
108}
109
110export class MultiHook<H> {
111 constructor(hooks: H[], name?: string);
112 name: string | undefined;
113 tap(options: string | Tap, fn?: Function): void;
114 tapAsync(options: string | Tap, fn?: Function): void;
115 tapPromise(options: string | Tap, fn?: Function): void;
116}
Note: See TracBrowser for help on using the repository browser.