@cascateer/core 2.3.40 → 2.3.41

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/serializable.ts +12 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.3.40",
3
+ "version": "2.3.41",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cascateer/core.git"
@@ -1,6 +1,7 @@
1
- import { Dictionary, get } from "lodash";
1
+ import { Dictionary, isString } from "lodash";
2
2
  import { Brand, identity } from "ts-brand";
3
3
  import { v4 } from "uuid";
4
+ import * as module from ".";
4
5
 
5
6
  interface SerializerResult<O> {
6
7
  value: O;
@@ -30,13 +31,13 @@ export abstract class Serializable<O> {
30
31
  const { $ref, value }: SerializerResult<O> = JSON.parse(json),
31
32
  [url, pointer] = $ref.split(/#\/?/);
32
33
 
33
- if (url === import.meta.url && pointer != null) {
34
- const path = pointer.split("/");
34
+ if (url === import.meta.url) {
35
+ const [a, b, c] = pointer?.split("/") ?? [];
35
36
 
36
- if (path[0] === Serializable.name) {
37
- return (
38
- get(Serializable, path.slice(1)) as SerializableConstructor<T, O>
39
- ).fromObject(value);
37
+ if (a === "Serializable" && b === "importMap" && isString(c)) {
38
+ return (module[a][b][c] as SerializableConstructor<T, O>).fromObject(
39
+ value,
40
+ );
40
41
  }
41
42
  }
42
43
  } catch {}
@@ -48,14 +49,14 @@ export abstract class Serializable<O> {
48
49
  ctor: SerializableConstructor<T, O>,
49
50
  value: Serializable<O>,
50
51
  ): BrandedSerializer<O> {
51
- const importMap = "importMap" satisfies keyof typeof Serializable;
52
- const id = v4();
52
+ const IMPORT_MAP = "importMap",
53
+ UUID = v4();
53
54
 
54
- this[importMap][id] = ctor;
55
+ this[IMPORT_MAP][UUID] = ctor;
55
56
 
56
57
  return identity<BrandedSerializer<O>>(() => ({
57
58
  value: value.toObject(),
58
- $ref: [`${import.meta.url}#`, this.name, importMap, id].join("/"),
59
+ $ref: `${import.meta.url}#${[this.name, IMPORT_MAP, UUID].join("/")}`,
59
60
  }));
60
61
  }
61
62