UNPKG

1.97 kBTypeScriptView Raw
1export declare function invariant(condition: boolean, message: () => string): void;
2export declare class Context {
3 private commands;
4 constructor();
5 get isEquals(): (x: any, y: any) => boolean;
6 set isEquals(value: (x: any, y: any) => boolean);
7 extend<T>(directive: string, fn: (param: any, old: T) => T): void;
8 update<T, C extends CustomCommands<object> = never>(object: T, $spec: Spec<T, C>): T;
9}
10export declare const isEquals: any;
11export declare const extend: <T>(directive: string, fn: (param: any, old: T) => T) => void;
12declare const _default: <T, C extends CustomCommands<object> = never>(object: T, $spec: Spec<T, C>) => T;
13export default _default;
14export declare type CustomCommands<T> = T & {
15 __noInferenceCustomCommandsBrand: any;
16};
17export declare type Spec<T, C extends CustomCommands<object> = never> = (T extends (Array<infer U> | ReadonlyArray<infer U>) ? ArraySpec<U, C> : T extends (Map<infer K, infer V> | ReadonlyMap<infer K, infer V>) ? MapSpec<K, V, C> : T extends (Set<infer X> | ReadonlySet<infer X>) ? SetSpec<X> : T extends object ? ObjectSpec<T, C> : never) | {
18 $set: T;
19} | {
20 $apply: (v: T) => T;
21} | ((v: T) => T) | (C extends CustomCommands<infer O> ? O : never);
22declare type ArraySpec<T, C extends CustomCommands<object>> = {
23 $push: ReadonlyArray<T>;
24} | {
25 $unshift: ReadonlyArray<T>;
26} | {
27 $splice: ReadonlyArray<[number, number?] | [number, number, ...T[]]>;
28} | {
29 [index: string]: Spec<T, C>;
30};
31declare type MapSpec<K, V, C extends CustomCommands<object>> = {
32 $add: ReadonlyArray<[K, V]>;
33} | {
34 $remove: ReadonlyArray<K>;
35} | {
36 [key: string]: Spec<V, C>;
37};
38declare type SetSpec<T> = {
39 $add: ReadonlyArray<T>;
40} | {
41 $remove: ReadonlyArray<T>;
42};
43declare type ObjectSpec<T, C extends CustomCommands<object>> = {
44 $toggle: ReadonlyArray<keyof T>;
45} | {
46 $unset: ReadonlyArray<keyof T>;
47} | {
48 $merge: Partial<T>;
49} | {
50 [K in keyof T]?: Spec<T[K], C>;
51};
52
\No newline at end of file