@cascateer/core 2.3.15 → 2.3.16
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/package.json +1 -1
- package/src/serializable.ts +28 -0
- package/src/store.ts +12 -10
- package/src/types.ts +0 -2
package/package.json
CHANGED
package/src/serializable.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Dictionary, get } from "lodash";
|
|
2
|
+
import { concatAll, defer, endWith, from, lastValueFrom } from "rxjs";
|
|
2
3
|
import { Brand, identity } from "ts-brand";
|
|
3
4
|
import { v4 } from "uuid";
|
|
4
5
|
|
|
@@ -56,6 +57,33 @@ export abstract class Serializable<O> {
|
|
|
56
57
|
}));
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
static async parse(text: string) {
|
|
61
|
+
const nodes: { key: string; value: any; parent?: any }[] = [];
|
|
62
|
+
const obj = JSON.parse(text, (key, value) => {
|
|
63
|
+
for (const node of nodes) {
|
|
64
|
+
if (node.key && value[node.key] === node.value) {
|
|
65
|
+
node.parent = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
nodes.unshift({ key, value });
|
|
70
|
+
|
|
71
|
+
return value;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return lastValueFrom(
|
|
75
|
+
from(
|
|
76
|
+
nodes.toReversed().map((node) =>
|
|
77
|
+
defer(() =>
|
|
78
|
+
Serializable.fromJSON(JSON.stringify(node.value))
|
|
79
|
+
.catch(() => node.value)
|
|
80
|
+
.then((value) => node.key && (node.parent[node.key] = value)),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
).pipe(concatAll(), endWith(obj)),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
59
87
|
abstract toObject(): O;
|
|
60
88
|
abstract toJSON: BrandedSerializer<O>;
|
|
61
89
|
}
|
package/src/store.ts
CHANGED
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
MulticastSubject,
|
|
17
17
|
sequence,
|
|
18
18
|
} from "./operators";
|
|
19
|
-
import {
|
|
19
|
+
import { Serializable } from "./serializable";
|
|
20
|
+
import { Action, Transform } from "./types";
|
|
20
21
|
|
|
21
22
|
export type StoreEffect<Result> = () => Signal<Result>;
|
|
22
23
|
|
|
@@ -69,7 +70,7 @@ export class ExtendableStoreAdapter<
|
|
|
69
70
|
},
|
|
70
71
|
void
|
|
71
72
|
>;
|
|
72
|
-
register: UnaryFunction<(args: any) =>
|
|
73
|
+
register: UnaryFunction<(args: any) => Transform<any>, void>;
|
|
73
74
|
}
|
|
74
75
|
>;
|
|
75
76
|
},
|
|
@@ -114,7 +115,7 @@ export class ExtendableStoreAdapter<
|
|
|
114
115
|
? T
|
|
115
116
|
: never,
|
|
116
117
|
>(
|
|
117
|
-
predicate: UnaryFunction<Args,
|
|
118
|
+
predicate: UnaryFunction<Args, Transform<T>>,
|
|
118
119
|
config?: { sameOrigin?: boolean },
|
|
119
120
|
) => Action<Args, any>;
|
|
120
121
|
};
|
|
@@ -141,8 +142,8 @@ export class ExtendableStoreAdapter<
|
|
|
141
142
|
(signal) => ({
|
|
142
143
|
update: (predicate, config = {}) =>
|
|
143
144
|
thru(this.context.transform(key), (transform) => {
|
|
144
|
-
transform.register(
|
|
145
|
-
signal.reflector.predicate(
|
|
145
|
+
transform.register((args) =>
|
|
146
|
+
signal.reflector.predicate(predicate(args)),
|
|
146
147
|
);
|
|
147
148
|
|
|
148
149
|
return (args) =>
|
|
@@ -170,14 +171,15 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
|
|
|
170
171
|
>();
|
|
171
172
|
const seedActions: Observable<MulticastAction<Data, "seedAction">> =
|
|
172
173
|
actions.pipe(
|
|
173
|
-
|
|
174
|
+
mergeMap(async (event) =>
|
|
174
175
|
event.type === "seedAction"
|
|
175
176
|
? {
|
|
176
177
|
...event,
|
|
177
|
-
predicate: constant(
|
|
178
|
+
predicate: constant(await Serializable.parse(event.data.seed)),
|
|
178
179
|
}
|
|
179
|
-
: [],
|
|
180
|
+
: Promise.resolve([]),
|
|
180
181
|
),
|
|
182
|
+
flatMap(identity),
|
|
181
183
|
);
|
|
182
184
|
|
|
183
185
|
const callbacks = new Map<string, UnaryFunction<unknown, void>>();
|
|
@@ -210,8 +212,8 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
|
|
|
210
212
|
) {
|
|
211
213
|
return {
|
|
212
214
|
...event,
|
|
213
|
-
predicate:
|
|
214
|
-
|
|
215
|
+
predicate: transform(
|
|
216
|
+
await Serializable.parse(event.data.args ?? null),
|
|
215
217
|
),
|
|
216
218
|
callback: callbacks.get(event.id),
|
|
217
219
|
};
|
package/src/types.ts
CHANGED
|
@@ -68,8 +68,6 @@ export interface Action<Args, Result> extends UnaryFunction<
|
|
|
68
68
|
|
|
69
69
|
export type MaybeArray<T> = T | T[];
|
|
70
70
|
|
|
71
|
-
export type MaybePromise<T> = T | Promise<T>;
|
|
72
|
-
|
|
73
71
|
export type MaybeObservable<T> = T | Observable<T>;
|
|
74
72
|
|
|
75
73
|
export type MaybeObservableInput<T> = T | ObservableInput<T>;
|