@cascateer/core 2.3.39 → 2.3.40

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.3.39",
3
+ "version": "2.3.40",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cascateer/core.git"
@@ -25,31 +25,23 @@ export abstract class Serializable<O> {
25
25
  SerializableConstructor<unknown, unknown>
26
26
  > = {};
27
27
 
28
- static async fromJSON<T, O>(json: string): Promise<T> {
29
- console.warn("fromJSON", this);
30
-
31
- const { $ref, value }: SerializerResult<O> = JSON.parse(json),
32
- [url, path] = $ref.split(/#\/?/);
33
-
34
- console.warn("fromJSON", url, this);
35
-
36
- if (url != null && path != null) {
37
- console.log(
38
- Object.entries(
39
- import.meta.glob("/node_modules/@cascateer/core/src/*.ts"),
40
- ),
41
- );
42
- return import(url).then(
43
- (module) => (
44
- console.warn("FOOBAR", module, path.split("/")),
45
- (
46
- get(module, path.split("/")) as SerializableConstructor<T, O>
47
- ).fromObject(value)
48
- ),
49
- );
50
- }
28
+ static fromJSON<T, O>(json: string): T {
29
+ try {
30
+ const { $ref, value }: SerializerResult<O> = JSON.parse(json),
31
+ [url, pointer] = $ref.split(/#\/?/);
32
+
33
+ if (url === import.meta.url && pointer != null) {
34
+ const path = pointer.split("/");
35
+
36
+ if (path[0] === Serializable.name) {
37
+ return (
38
+ get(Serializable, path.slice(1)) as SerializableConstructor<T, O>
39
+ ).fromObject(value);
40
+ }
41
+ }
42
+ } catch {}
51
43
 
52
- throw new Error(`${json} deserialization failed`);
44
+ return JSON.parse(json);
53
45
  }
54
46
 
55
47
  static toJSON<T, O>(
@@ -61,42 +53,15 @@ export abstract class Serializable<O> {
61
53
 
62
54
  this[importMap][id] = ctor;
63
55
 
64
- console.log("toJSON", import.meta.url, this);
65
-
66
56
  return identity<BrandedSerializer<O>>(() => ({
67
57
  value: value.toObject(),
68
58
  $ref: [`${import.meta.url}#`, this.name, importMap, id].join("/"),
69
59
  }));
70
60
  }
71
61
 
72
- static async parse(text: string) {
73
- const nodes: { key: string; value: any; parent?: any }[] = [];
74
- const obj = JSON.parse(text, (key, value) => {
75
- for (const node of nodes) {
76
- if (value[node.key] === node.value) {
77
- node.parent = value;
78
- }
79
- }
80
-
81
- nodes.push({ key, value });
82
-
83
- return value;
84
- });
85
-
86
- return nodes.reduce(
87
- (value, node) =>
88
- value.then(() =>
89
- Serializable.fromJSON(JSON.stringify(node.value))
90
- .catch((error) => (console.error(error), node.value))
91
- .then((value) => {
92
- if (node.parent != null) {
93
- node.parent[node.key] = value;
94
- }
95
-
96
- return value;
97
- }),
98
- ),
99
- Promise.resolve(obj),
62
+ static parse(text: string) {
63
+ return JSON.parse(text, (_, value) =>
64
+ Serializable.fromJSON(JSON.stringify(value)),
100
65
  );
101
66
  }
102
67
 
package/src/store.ts CHANGED
@@ -171,15 +171,14 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
171
171
  >();
172
172
  const seedActions: Observable<MulticastAction<Data, "seedAction">> =
173
173
  actions.pipe(
174
- mergeMap(async (event) =>
174
+ flatMap((event) =>
175
175
  event.type === "seedAction"
176
176
  ? {
177
177
  ...event,
178
- predicate: constant(await Serializable.parse(event.data.seed)),
178
+ predicate: constant(Serializable.parse(event.data.seed)),
179
179
  }
180
180
  : [],
181
181
  ),
182
- flatMap(identity),
183
182
  );
184
183
 
185
184
  const callbacks = new Map<string, UnaryFunction<unknown, void>>();
@@ -213,7 +212,7 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
213
212
  return {
214
213
  ...event,
215
214
  predicate: transform(
216
- await Serializable.parse(event.data.args ?? null),
215
+ Serializable.parse(event.data.args ?? null),
217
216
  ),
218
217
  callback: callbacks.get(event.id),
219
218
  };