rxfy 0.1.2 → 0.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.
- package/README.md +14 -0
- package/dist/index.cjs +4987 -2
- package/dist/index.d.cts +96 -2
- package/dist/index.d.ts +96 -2
- package/dist/index.js +4946 -2
- package/package.json +18 -6
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
import { Observable, BehaviorSubject } from 'rxjs';
|
|
2
|
+
import PQueue from 'p-queue';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
type IAtom<T> = Observable<T> & {
|
|
5
|
+
get: () => T;
|
|
6
|
+
set: (val: T) => void;
|
|
7
|
+
modify: (fn: (val: T) => T) => void;
|
|
8
|
+
};
|
|
9
|
+
declare class Atom<T> extends Observable<T> implements IAtom<T> {
|
|
10
|
+
readonly subject$: BehaviorSubject<T>;
|
|
11
|
+
constructor(value: T);
|
|
12
|
+
get: () => T;
|
|
13
|
+
set: (val: T) => void;
|
|
14
|
+
modify: (fn: (val: T) => T) => void;
|
|
15
|
+
}
|
|
16
|
+
declare function createAtom<T>(value: T): Atom<T>;
|
|
17
|
+
|
|
18
|
+
declare enum StatusEnum {
|
|
19
|
+
IDLE = "IDLE",
|
|
20
|
+
PENDING = "PENDING",
|
|
21
|
+
FULFILLED = "FULFILLED",
|
|
22
|
+
REJECTED = "REJECTED"
|
|
23
|
+
}
|
|
24
|
+
type IWrapped<Result, K extends StatusEnum = StatusEnum> = {
|
|
25
|
+
[StatusEnum.IDLE]: {
|
|
26
|
+
type: StatusEnum.IDLE;
|
|
27
|
+
};
|
|
28
|
+
[StatusEnum.PENDING]: {
|
|
29
|
+
type: StatusEnum.PENDING;
|
|
30
|
+
};
|
|
31
|
+
[StatusEnum.FULFILLED]: {
|
|
32
|
+
type: StatusEnum.FULFILLED;
|
|
33
|
+
value: Result;
|
|
34
|
+
};
|
|
35
|
+
[StatusEnum.REJECTED]: {
|
|
36
|
+
type: StatusEnum.REJECTED;
|
|
37
|
+
error: unknown;
|
|
38
|
+
};
|
|
39
|
+
}[K] & {
|
|
40
|
+
type: K;
|
|
41
|
+
};
|
|
42
|
+
declare function createIdle<Result>(): IWrapped<Result, StatusEnum.IDLE>;
|
|
43
|
+
declare function createPending<Result>(): IWrapped<Result, StatusEnum.PENDING>;
|
|
44
|
+
declare function createFulfilled<Result>(value: Result): IWrapped<Result, StatusEnum.FULFILLED>;
|
|
45
|
+
declare function createRejected<Result>(error: unknown): IWrapped<Result, StatusEnum.REJECTED>;
|
|
46
|
+
|
|
47
|
+
type IBranded<TBrand, TData> = {
|
|
48
|
+
brand: TBrand;
|
|
49
|
+
value: TData;
|
|
50
|
+
};
|
|
51
|
+
declare function toBranded<TBrand extends string, TData>(brand: TBrand, value: TData): IBranded<TBrand, TData>;
|
|
52
|
+
declare function isBranded<TBrand extends string, TData>(brand: TBrand, val: any): val is IBranded<TBrand, TData>;
|
|
53
|
+
type IEdgeState<TData> = IWrapped<TData>;
|
|
54
|
+
type IEdgeJS<TData> = IBranded<"edge", IEdgeState<TData>>;
|
|
55
|
+
type IEdge<TData> = {
|
|
56
|
+
subject$: IAtom<IEdgeState<TData>>;
|
|
57
|
+
toObservable: () => Observable<TData>;
|
|
58
|
+
next: () => Promise<IWrapped<TData, StatusEnum.FULFILLED | StatusEnum.REJECTED>>;
|
|
59
|
+
};
|
|
60
|
+
declare function createEdge<TData>(state$: IAtom<IEdgeState<TData>>, queue: PQueue, loader: () => Observable<TData>): IEdge<TData>;
|
|
61
|
+
|
|
62
|
+
type IMapJS = IBranded<"map", {
|
|
63
|
+
[K in string]: IMapJS | IEdgeJS<unknown>;
|
|
64
|
+
}>;
|
|
65
|
+
type IStoreState = {
|
|
66
|
+
[K in string]: IStoreStateJS | IMapJS | IEdgeJS<unknown>;
|
|
67
|
+
};
|
|
68
|
+
type IStoreStateJS = IBranded<"store", IStoreState>;
|
|
69
|
+
type IFactory<TData> = {
|
|
70
|
+
get: (key: string) => IEdge<TData>;
|
|
71
|
+
};
|
|
72
|
+
type IStore<TState extends IStoreStateJS> = {
|
|
73
|
+
state$: IAtom<TState>;
|
|
74
|
+
collect: () => Promise<void>;
|
|
75
|
+
node: (name: string) => IStore<IStoreStateJS>;
|
|
76
|
+
factoryBatch: <TData>(name: string, batch: (key: string[]) => Observable<Record<string, TData>>) => IFactory<TData>;
|
|
77
|
+
};
|
|
78
|
+
declare function createState(val: IStoreState): IStoreStateJS;
|
|
79
|
+
declare function createStore<TState extends IStoreStateJS>(queue: PQueue, state$: IAtom<TState>): IStore<TState>;
|
|
80
|
+
|
|
81
|
+
type ILens<TSource, TTarget> = {
|
|
82
|
+
get: (source: TSource) => TTarget;
|
|
83
|
+
set: (current: TTarget, source: TSource) => TSource;
|
|
84
|
+
};
|
|
85
|
+
declare class Lens<TSource, TTarget> extends Observable<TTarget> implements IAtom<TTarget> {
|
|
86
|
+
private subject$;
|
|
87
|
+
private sub;
|
|
88
|
+
private subCount;
|
|
89
|
+
constructor(source$: IAtom<TSource>, lens: ILens<TSource, TTarget>);
|
|
90
|
+
set: (value: TTarget) => void;
|
|
91
|
+
get: () => TTarget;
|
|
92
|
+
modify: (fn: (val: TTarget) => TTarget) => void;
|
|
93
|
+
}
|
|
94
|
+
declare function createLens<TSource, TTarget>(source$: IAtom<TSource>, lens: ILens<TSource, TTarget>): Lens<TSource, TTarget>;
|
|
95
|
+
declare function keyLens<TSource, TTarget extends keyof TSource>(key: TTarget): ILens<TSource, TSource[TTarget]>;
|
|
96
|
+
|
|
97
|
+
export { Atom, type IAtom, type IBranded, type IEdge, type IEdgeJS, type IEdgeState, type ILens, type IWrapped, Lens, StatusEnum, createAtom, createEdge, createFulfilled, createIdle, createLens, createPending, createRejected, createState, createStore, isBranded, keyLens, toBranded };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
import { Observable, BehaviorSubject } from 'rxjs';
|
|
2
|
+
import PQueue from 'p-queue';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
type IAtom<T> = Observable<T> & {
|
|
5
|
+
get: () => T;
|
|
6
|
+
set: (val: T) => void;
|
|
7
|
+
modify: (fn: (val: T) => T) => void;
|
|
8
|
+
};
|
|
9
|
+
declare class Atom<T> extends Observable<T> implements IAtom<T> {
|
|
10
|
+
readonly subject$: BehaviorSubject<T>;
|
|
11
|
+
constructor(value: T);
|
|
12
|
+
get: () => T;
|
|
13
|
+
set: (val: T) => void;
|
|
14
|
+
modify: (fn: (val: T) => T) => void;
|
|
15
|
+
}
|
|
16
|
+
declare function createAtom<T>(value: T): Atom<T>;
|
|
17
|
+
|
|
18
|
+
declare enum StatusEnum {
|
|
19
|
+
IDLE = "IDLE",
|
|
20
|
+
PENDING = "PENDING",
|
|
21
|
+
FULFILLED = "FULFILLED",
|
|
22
|
+
REJECTED = "REJECTED"
|
|
23
|
+
}
|
|
24
|
+
type IWrapped<Result, K extends StatusEnum = StatusEnum> = {
|
|
25
|
+
[StatusEnum.IDLE]: {
|
|
26
|
+
type: StatusEnum.IDLE;
|
|
27
|
+
};
|
|
28
|
+
[StatusEnum.PENDING]: {
|
|
29
|
+
type: StatusEnum.PENDING;
|
|
30
|
+
};
|
|
31
|
+
[StatusEnum.FULFILLED]: {
|
|
32
|
+
type: StatusEnum.FULFILLED;
|
|
33
|
+
value: Result;
|
|
34
|
+
};
|
|
35
|
+
[StatusEnum.REJECTED]: {
|
|
36
|
+
type: StatusEnum.REJECTED;
|
|
37
|
+
error: unknown;
|
|
38
|
+
};
|
|
39
|
+
}[K] & {
|
|
40
|
+
type: K;
|
|
41
|
+
};
|
|
42
|
+
declare function createIdle<Result>(): IWrapped<Result, StatusEnum.IDLE>;
|
|
43
|
+
declare function createPending<Result>(): IWrapped<Result, StatusEnum.PENDING>;
|
|
44
|
+
declare function createFulfilled<Result>(value: Result): IWrapped<Result, StatusEnum.FULFILLED>;
|
|
45
|
+
declare function createRejected<Result>(error: unknown): IWrapped<Result, StatusEnum.REJECTED>;
|
|
46
|
+
|
|
47
|
+
type IBranded<TBrand, TData> = {
|
|
48
|
+
brand: TBrand;
|
|
49
|
+
value: TData;
|
|
50
|
+
};
|
|
51
|
+
declare function toBranded<TBrand extends string, TData>(brand: TBrand, value: TData): IBranded<TBrand, TData>;
|
|
52
|
+
declare function isBranded<TBrand extends string, TData>(brand: TBrand, val: any): val is IBranded<TBrand, TData>;
|
|
53
|
+
type IEdgeState<TData> = IWrapped<TData>;
|
|
54
|
+
type IEdgeJS<TData> = IBranded<"edge", IEdgeState<TData>>;
|
|
55
|
+
type IEdge<TData> = {
|
|
56
|
+
subject$: IAtom<IEdgeState<TData>>;
|
|
57
|
+
toObservable: () => Observable<TData>;
|
|
58
|
+
next: () => Promise<IWrapped<TData, StatusEnum.FULFILLED | StatusEnum.REJECTED>>;
|
|
59
|
+
};
|
|
60
|
+
declare function createEdge<TData>(state$: IAtom<IEdgeState<TData>>, queue: PQueue, loader: () => Observable<TData>): IEdge<TData>;
|
|
61
|
+
|
|
62
|
+
type IMapJS = IBranded<"map", {
|
|
63
|
+
[K in string]: IMapJS | IEdgeJS<unknown>;
|
|
64
|
+
}>;
|
|
65
|
+
type IStoreState = {
|
|
66
|
+
[K in string]: IStoreStateJS | IMapJS | IEdgeJS<unknown>;
|
|
67
|
+
};
|
|
68
|
+
type IStoreStateJS = IBranded<"store", IStoreState>;
|
|
69
|
+
type IFactory<TData> = {
|
|
70
|
+
get: (key: string) => IEdge<TData>;
|
|
71
|
+
};
|
|
72
|
+
type IStore<TState extends IStoreStateJS> = {
|
|
73
|
+
state$: IAtom<TState>;
|
|
74
|
+
collect: () => Promise<void>;
|
|
75
|
+
node: (name: string) => IStore<IStoreStateJS>;
|
|
76
|
+
factoryBatch: <TData>(name: string, batch: (key: string[]) => Observable<Record<string, TData>>) => IFactory<TData>;
|
|
77
|
+
};
|
|
78
|
+
declare function createState(val: IStoreState): IStoreStateJS;
|
|
79
|
+
declare function createStore<TState extends IStoreStateJS>(queue: PQueue, state$: IAtom<TState>): IStore<TState>;
|
|
80
|
+
|
|
81
|
+
type ILens<TSource, TTarget> = {
|
|
82
|
+
get: (source: TSource) => TTarget;
|
|
83
|
+
set: (current: TTarget, source: TSource) => TSource;
|
|
84
|
+
};
|
|
85
|
+
declare class Lens<TSource, TTarget> extends Observable<TTarget> implements IAtom<TTarget> {
|
|
86
|
+
private subject$;
|
|
87
|
+
private sub;
|
|
88
|
+
private subCount;
|
|
89
|
+
constructor(source$: IAtom<TSource>, lens: ILens<TSource, TTarget>);
|
|
90
|
+
set: (value: TTarget) => void;
|
|
91
|
+
get: () => TTarget;
|
|
92
|
+
modify: (fn: (val: TTarget) => TTarget) => void;
|
|
93
|
+
}
|
|
94
|
+
declare function createLens<TSource, TTarget>(source$: IAtom<TSource>, lens: ILens<TSource, TTarget>): Lens<TSource, TTarget>;
|
|
95
|
+
declare function keyLens<TSource, TTarget extends keyof TSource>(key: TTarget): ILens<TSource, TSource[TTarget]>;
|
|
96
|
+
|
|
97
|
+
export { Atom, type IAtom, type IBranded, type IEdge, type IEdgeJS, type IEdgeState, type ILens, type IWrapped, Lens, StatusEnum, createAtom, createEdge, createFulfilled, createIdle, createLens, createPending, createRejected, createState, createStore, isBranded, keyLens, toBranded };
|