1 |
|
2 |
|
3 | export const NOOP = () => {};
|
4 |
|
5 |
|
6 | export type Constructable<T> = {
|
7 | new (...args: Array<any>): T
|
8 | };
|
9 |
|
10 | export type IneedaKey<T> = keyof T | keyof IneedaProxy<T> | keyof Object | keyof Function;
|
11 |
|
12 | export type IneedaInterceptorToken = {};
|
13 | export type IneedaInterceptorFunction<T, K extends keyof T> = (value?: T[K], key?: K, values?: Partial<T>, target?: T) => any;
|
14 | export type IneedaInterceptor<T> = IneedaInterceptorFunction<T, keyof T> | Partial<T>;
|
15 | export type IneedaInterceptorOrToken<T> = IneedaInterceptor<T> | IneedaInterceptorToken;
|
16 |
|
17 | export interface IneedaProxy<T> {
|
18 | hasOwnProperty (): boolean;
|
19 | intercept (interceptor: IneedaInterceptorOrToken<T>): T;
|
20 | reset (): T;
|
21 | toJSON (): Partial<T>;
|
22 | toString (): string;
|
23 | }
|
24 |
|
25 | export interface IneedaFactory <T> {
|
26 | instances?: Array<T & IneedaProxy<T>>;
|
27 | (): T & IneedaProxy<T>;
|
28 | getLatest? (): T & IneedaProxy<T>;
|
29 | }
|
30 |
|
31 | export interface IneedaApi {
|
32 | <T> (values?: Partial<T>): T & IneedaProxy<T>;
|
33 | factory <T> (values?: Partial<T>): IneedaFactory<T & IneedaProxy<T>>;
|
34 | instanceof <T> (constructor: Constructable<T>, values?: Partial<T>): T & IneedaProxy<T>;
|
35 | intercept <T> (interceptorOrToken: IneedaInterceptorOrToken<T>, interceptor?: IneedaInterceptor<T>): void;
|
36 | reset (): void;
|
37 | }
|