-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrickyard.d.ts
134 lines (134 loc) · 3.66 KB
/
brickyard.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* @description
* ### How to use:
* #### Minimal example:
* ```ts
* // bricks.ts
* import { some_fn } from "./some_fn.ts";
* import { another_fn } from "./another_fn.ts";
*
* export const bircks = Brickyard
* .init(Brickyard.pre_init().complete())
* .enroll({ some_fn, another_fn });
*
* // main.ts
* import { bricks } from "./bricks.ts";
*
* bricks.some_fn();
* ```
*
* > but actualy example above works exactly as a simple reexport.
*
* #### Usefull example:
*
* ```ts
* // bricks.ts
* import { some_fn } from "./some_fn.ts";
* import { another_fn } from "./another_fn.ts";
*
* const interceptor = Brickyard
* .intercept('some_fn', { fn: () => 'intercepted some_fn' })
* .pre_init()
* .complete();
*
* export const bircks = Brickyard
* .init(interceptor)
* .enroll({ some_fn, another_fn });
*
* // main.ts
* import { bricks } from "./bricks.ts";
*
* bricks.some_fn();
* ```
*
* #### Advanced example:
* > the same as above except the interceptor is placed in the separate file and ignored by git.
* > but you can change the implementation of `some_fn` and `another_fn` without changing the code.
*
* ```ts
* // .interceptor.ts
* import { some_fn } from "./some_fn.ts";
* import { another_fn } from "./another_fn.ts";
*
* export const interceptor = Brickyard
* .intercept('some_fn', { fn: () => 'intercepted some_fn' })
* .pre_init()
* .complete();
*
* // bricks.ts
* import { interceptor } from "./.interceptor.ts";
*
* export const bircks = Brickyard
* .init(interceptor)
* .enroll({ some_fn, another_fn });
*
* // main.ts
* import { bricks } from "./bricks.ts";
*
* bricks.some_fn();
* ```
*
* #### P.S. if you hide your interceptor file with `.gitignore` you should create this file manually (even if you don't want to do interceptions)
* > so it can be as possible simple:
*
* ```ts
* // .interceptor.ts, ignored by git
* export const interceptor = Brickyard.pre_init().complete();
* ```
*/
export declare class Brickyard {
#private;
private constructor();
/**
* @description
* To start register your interceptors
*/
static pre_init(): {
intercept: Brickyard["intercept"];
complete: () => BricksInterceptor;
};
/**
* @description
* To start register your functions for reexport
*/
static init(interceptor: BricksInterceptor): Pick<Brickyard, "enroll">;
/**
* @description
* Register interceptor for the function with `id`.
* (will be ignored if no such `id` and throw error if `id` is already the member of interceptor)
*/
intercept<T extends Fn>(id: string, interceptor: InterceptorType<T>): {
intercept: Brickyard["intercept"];
complete: () => BricksInterceptor;
};
/**
* @description
* Pass the object with functions to enroll them.
* And use returned result as reexport of the original stuff for your project.
*/
enroll<T extends Record<string, Fn>>(candidates: T): T;
private _enroll;
}
type InterceptorType<T extends Fn = Fn> = {
fn: T;
args?: never;
args_strategy?: never;
} | {
fn?: T;
args: Parameters<T>;
args_strategy: "merge" | "replace";
};
type Fn = (...args: any[]) => any;
/**
* @description
* This is mostly util-helper class.
* So it is a kind of a trick to make you call pre_init() method before init() method.
* It's purpose is to enforce you place it into the Brickyard.init() method.
* But because of to get it your should first call Brickyard.pre_init() method.
*/
declare class BricksInterceptor {
brickyard: Brickyard;
constructor(brickyard: Brickyard);
}
export {};
//# sourceMappingURL=brickyard.d.ts.map