jazz-tools 0.13.23 → 0.13.25
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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +7 -0
- package/dist/{chunk-K7VKB2XQ.js → chunk-Z6IXFGH3.js} +2 -2
- package/dist/{chunk-K7VKB2XQ.js.map → chunk-Z6IXFGH3.js.map} +1 -1
- package/dist/coValues/coPlainText.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/testing.js +1 -1
- package/dist/tests/load.test.d.ts +2 -0
- package/dist/tests/load.test.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/coValues/coPlainText.ts +1 -1
- package/src/tests/load.test.ts +116 -0
@@ -96,7 +96,7 @@ export declare class CoPlainText extends String implements CoValue {
|
|
96
96
|
*
|
97
97
|
* The 'hint' parameter indicates the preferred type of conversion:
|
98
98
|
* - 'string': prefer string conversion
|
99
|
-
* - 'number': prefer number conversion (
|
99
|
+
* - 'number': prefer number conversion (attempt to parse the text as a number)
|
100
100
|
* - 'default': usually treat as string
|
101
101
|
*/
|
102
102
|
[Symbol.toPrimitive](hint: string): string | number;
|
package/dist/index.js
CHANGED
package/dist/testing.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"load.test.d.ts","sourceRoot":"","sources":["../../src/tests/load.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
@@ -17,11 +17,11 @@
|
|
17
17
|
},
|
18
18
|
"type": "module",
|
19
19
|
"license": "MIT",
|
20
|
-
"version": "0.13.
|
20
|
+
"version": "0.13.25",
|
21
21
|
"dependencies": {
|
22
22
|
"@scure/bip39": "^1.3.0",
|
23
23
|
"fast-myers-diff": "^3.2.0",
|
24
|
-
"cojson": "0.13.
|
24
|
+
"cojson": "0.13.25"
|
25
25
|
},
|
26
26
|
"devDependencies": {
|
27
27
|
"tsup": "8.3.5",
|
@@ -268,7 +268,7 @@ export class CoPlainText extends String implements CoValue {
|
|
268
268
|
*
|
269
269
|
* The 'hint' parameter indicates the preferred type of conversion:
|
270
270
|
* - 'string': prefer string conversion
|
271
|
-
* - 'number': prefer number conversion (
|
271
|
+
* - 'number': prefer number conversion (attempt to parse the text as a number)
|
272
272
|
* - 'default': usually treat as string
|
273
273
|
*/
|
274
274
|
[Symbol.toPrimitive](hint: string) {
|
@@ -0,0 +1,116 @@
|
|
1
|
+
import { cojsonInternals } from "cojson";
|
2
|
+
import { beforeEach, expect, test } from "vitest";
|
3
|
+
import { Account, CoMap, Group, co } from "../exports.js";
|
4
|
+
import {
|
5
|
+
createJazzTestAccount,
|
6
|
+
getPeerConnectedToTestSyncServer,
|
7
|
+
setupJazzTestSync,
|
8
|
+
} from "../testing.js";
|
9
|
+
|
10
|
+
beforeEach(async () => {
|
11
|
+
await setupJazzTestSync();
|
12
|
+
await createJazzTestAccount({
|
13
|
+
isCurrentActiveAccount: true,
|
14
|
+
});
|
15
|
+
});
|
16
|
+
|
17
|
+
test("load a value", async () => {
|
18
|
+
class Person extends CoMap {
|
19
|
+
name = co.string;
|
20
|
+
}
|
21
|
+
|
22
|
+
const group = Group.create();
|
23
|
+
const map = Person.create({ name: "John" }, group);
|
24
|
+
group.addMember("everyone", "reader");
|
25
|
+
|
26
|
+
const alice = await createJazzTestAccount();
|
27
|
+
|
28
|
+
const john = await Person.load(map.id, { loadAs: alice });
|
29
|
+
expect(john).not.toBeNull();
|
30
|
+
expect(john?.name).toBe("John");
|
31
|
+
});
|
32
|
+
|
33
|
+
test("retry an unavailable a value", async () => {
|
34
|
+
class Person extends CoMap {
|
35
|
+
name = co.string;
|
36
|
+
}
|
37
|
+
|
38
|
+
const currentAccount = Account.getMe();
|
39
|
+
|
40
|
+
// Disconnect the current account
|
41
|
+
currentAccount._raw.core.node.syncManager.getPeers().forEach((peer) => {
|
42
|
+
peer.gracefulShutdown();
|
43
|
+
});
|
44
|
+
|
45
|
+
const group = Group.create();
|
46
|
+
const map = Person.create({ name: "John" }, group);
|
47
|
+
group.addMember("everyone", "reader");
|
48
|
+
|
49
|
+
const alice = await createJazzTestAccount();
|
50
|
+
|
51
|
+
let resolved = false;
|
52
|
+
const promise = Person.load(map.id, { loadAs: alice });
|
53
|
+
promise.then(() => {
|
54
|
+
resolved = true;
|
55
|
+
});
|
56
|
+
|
57
|
+
await new Promise((resolve) =>
|
58
|
+
setTimeout(
|
59
|
+
resolve,
|
60
|
+
cojsonInternals.CO_VALUE_LOADING_CONFIG.RETRY_DELAY - 100,
|
61
|
+
),
|
62
|
+
);
|
63
|
+
|
64
|
+
expect(resolved).toBe(false);
|
65
|
+
|
66
|
+
// Reconnect the current account
|
67
|
+
currentAccount._raw.core.node.syncManager.addPeer(
|
68
|
+
getPeerConnectedToTestSyncServer(),
|
69
|
+
);
|
70
|
+
|
71
|
+
const john = await promise;
|
72
|
+
expect(john).not.toBeNull();
|
73
|
+
expect(john?.name).toBe("John");
|
74
|
+
});
|
75
|
+
|
76
|
+
test("returns null if the value is unavailable after retries", async () => {
|
77
|
+
class Person extends CoMap {
|
78
|
+
name = co.string;
|
79
|
+
}
|
80
|
+
|
81
|
+
const currentAccount = Account.getMe();
|
82
|
+
|
83
|
+
// Disconnect the current account
|
84
|
+
currentAccount._raw.core.node.syncManager.getPeers().forEach((peer) => {
|
85
|
+
peer.gracefulShutdown();
|
86
|
+
});
|
87
|
+
|
88
|
+
const group = Group.create();
|
89
|
+
const map = Person.create({ name: "John" }, group);
|
90
|
+
group.addMember("everyone", "reader");
|
91
|
+
|
92
|
+
const alice = await createJazzTestAccount();
|
93
|
+
|
94
|
+
let resolved = false;
|
95
|
+
const promise = Person.load(map.id, { loadAs: alice });
|
96
|
+
promise.then(() => {
|
97
|
+
resolved = true;
|
98
|
+
});
|
99
|
+
|
100
|
+
await new Promise((resolve) =>
|
101
|
+
setTimeout(
|
102
|
+
resolve,
|
103
|
+
cojsonInternals.CO_VALUE_LOADING_CONFIG.RETRY_DELAY + 100,
|
104
|
+
),
|
105
|
+
);
|
106
|
+
|
107
|
+
expect(resolved).toBe(true);
|
108
|
+
|
109
|
+
// Reconnect the current account
|
110
|
+
currentAccount._raw.core.node.syncManager.addPeer(
|
111
|
+
getPeerConnectedToTestSyncServer(),
|
112
|
+
);
|
113
|
+
|
114
|
+
const john = await promise;
|
115
|
+
expect(john).toBeNull();
|
116
|
+
});
|