@cascateer/core 2.3.40 → 2.3.42
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 +5 -3
- package/src/observable/Signal.test.ts +12 -0
- package/src/serializable.ts +14 -11
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cascateer/core",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.42",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/cascateer/core.git"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"patch": "npm version patch && git push origin main --tags"
|
|
9
|
+
"patch": "npm version patch && git push origin main --tags",
|
|
10
|
+
"test": "vitest"
|
|
10
11
|
},
|
|
11
12
|
"exports": {
|
|
12
13
|
".": "./src/index.ts",
|
|
@@ -20,7 +21,8 @@
|
|
|
20
21
|
"@types/object-hash": "^3.0.6",
|
|
21
22
|
"@types/react": "^19.2.14",
|
|
22
23
|
"typescript": "~5.8.3",
|
|
23
|
-
"vite": "^8.0.7"
|
|
24
|
+
"vite": "^8.0.7",
|
|
25
|
+
"vitest": "^4.1.7"
|
|
24
26
|
},
|
|
25
27
|
"dependencies": {
|
|
26
28
|
"lodash": "^4.17.21",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { lastValueFrom, of, toArray } from "rxjs";
|
|
2
|
+
import { expect, test } from "vitest";
|
|
3
|
+
import { ComputedSignal } from "./Signal";
|
|
4
|
+
|
|
5
|
+
test("projects", () =>
|
|
6
|
+
lastValueFrom(
|
|
7
|
+
new ComputedSignal({
|
|
8
|
+
value: of({ number: 1 }, { number: 2 }, { number: 3 }),
|
|
9
|
+
})
|
|
10
|
+
.property("number")
|
|
11
|
+
.pipe(toArray()),
|
|
12
|
+
).then((numbers) => expect(numbers).toEqual([1, 2, 3])));
|
package/src/serializable.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Dictionary,
|
|
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,15 @@ 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
|
|
34
|
-
const
|
|
34
|
+
if (url === import.meta.url) {
|
|
35
|
+
const [a, b, c] = pointer?.split("/") ?? [];
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
).fromObject(
|
|
37
|
+
console.log(module, a, b, c);
|
|
38
|
+
|
|
39
|
+
if (a === "Serializable" && b === "importMap" && isString(c)) {
|
|
40
|
+
return (module[a][b][c] as SerializableConstructor<T, O>).fromObject(
|
|
41
|
+
value,
|
|
42
|
+
);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
} catch {}
|
|
@@ -48,14 +51,14 @@ export abstract class Serializable<O> {
|
|
|
48
51
|
ctor: SerializableConstructor<T, O>,
|
|
49
52
|
value: Serializable<O>,
|
|
50
53
|
): BrandedSerializer<O> {
|
|
51
|
-
const
|
|
52
|
-
|
|
54
|
+
const IMPORT_MAP = "importMap",
|
|
55
|
+
UUID = v4();
|
|
53
56
|
|
|
54
|
-
this[
|
|
57
|
+
this[IMPORT_MAP][UUID] = ctor;
|
|
55
58
|
|
|
56
59
|
return identity<BrandedSerializer<O>>(() => ({
|
|
57
60
|
value: value.toObject(),
|
|
58
|
-
$ref:
|
|
61
|
+
$ref: `${import.meta.url}#${[this.name, IMPORT_MAP, UUID].join("/")}`,
|
|
59
62
|
}));
|
|
60
63
|
}
|
|
61
64
|
|