jazz-tools 0.13.23 → 0.13.26
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 +13 -0
- package/dist/{chunk-K7VKB2XQ.js → chunk-E4PALNK7.js} +5 -6
- package/dist/chunk-E4PALNK7.js.map +1 -0
- package/dist/coValues/coPlainText.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/subscribe/utils.d.ts.map +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/subscribe/SubscriptionScope.ts +3 -3
- package/src/subscribe/utils.ts +3 -3
- package/src/tests/account.test.ts +42 -1
- package/src/tests/load.test.ts +116 -0
- package/dist/chunk-K7VKB2XQ.js.map +0 -1
@@ -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
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/subscribe/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/subscribe/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAyB,MAAM,gBAAgB,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,UAAU,mEAQnD;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,EAC7C,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,EAClB,GAAG,EAAE,UAAU,EACf,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC;;;;EAgBxC"}
|
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.26",
|
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) {
|
@@ -72,12 +72,12 @@ export class SubscriptionScope<D extends CoValue> {
|
|
72
72
|
return;
|
73
73
|
}
|
74
74
|
|
75
|
-
const owner = getOwnerFromRawValue(update);
|
76
|
-
|
77
75
|
const ruleset = update.core.verified.header.ruleset;
|
78
76
|
|
79
77
|
// Groups and accounts are accessible by everyone, for the other coValues we use the role to check access
|
80
|
-
const hasAccess =
|
78
|
+
const hasAccess =
|
79
|
+
ruleset.type !== "ownedByGroup" ||
|
80
|
+
getOwnerFromRawValue(update).myRole() !== undefined;
|
81
81
|
|
82
82
|
if (!hasAccess) {
|
83
83
|
if (this.value.type !== "unauthorized") {
|
package/src/subscribe/utils.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
import { RawAccount, RawCoValue
|
1
|
+
import { RawAccount, RawCoValue } from "cojson";
|
2
2
|
import { RegisteredSchemas } from "../coValues/registeredSchemas.js";
|
3
3
|
import { CoValue, RefEncoded, instantiateRefEncoded } from "../internal.js";
|
4
4
|
import { coValuesCache } from "../lib/cache.js";
|
5
5
|
import { SubscriptionScope } from "./SubscriptionScope.js";
|
6
6
|
|
7
7
|
export function getOwnerFromRawValue(raw: RawCoValue) {
|
8
|
-
|
8
|
+
const owner = raw.group;
|
9
9
|
|
10
|
-
return coValuesCache.get(owner
|
10
|
+
return coValuesCache.get(owner, () =>
|
11
11
|
owner instanceof RawAccount
|
12
12
|
? RegisteredSchemas["Account"].fromRaw(owner)
|
13
13
|
: RegisteredSchemas["Group"].fromRaw(owner as any),
|
@@ -1,12 +1,18 @@
|
|
1
|
-
import {
|
1
|
+
import { LocalNode } from "cojson";
|
2
|
+
import { assert, beforeEach, expect, test } from "vitest";
|
2
3
|
import { Account, CoMap, Group, co } from "../exports.js";
|
3
4
|
import {
|
4
5
|
createJazzTestAccount,
|
5
6
|
linkAccounts,
|
6
7
|
setActiveAccount,
|
8
|
+
setupJazzTestSync,
|
7
9
|
} from "../testing.js";
|
8
10
|
import { setupTwoNodes } from "./utils.js";
|
9
11
|
|
12
|
+
beforeEach(async () => {
|
13
|
+
await setupJazzTestSync();
|
14
|
+
});
|
15
|
+
|
10
16
|
test("waitForAllCoValuesSync should resolve when all the values are synced", async () => {
|
11
17
|
class TestMap extends CoMap {
|
12
18
|
name = co.string;
|
@@ -98,3 +104,38 @@ test("accounts should sync correctly", async () => {
|
|
98
104
|
expect(members[0]?.account.profile!.name).toBe("test 1");
|
99
105
|
expect(members[1]?.account.profile!.name).toBe("test 2");
|
100
106
|
});
|
107
|
+
|
108
|
+
test("loading accounts should work", async () => {
|
109
|
+
const account = await createJazzTestAccount({
|
110
|
+
creationProps: {
|
111
|
+
name: "test 1",
|
112
|
+
},
|
113
|
+
});
|
114
|
+
|
115
|
+
const otherAccount = await createJazzTestAccount();
|
116
|
+
|
117
|
+
const loadedAccount = await Account.load(account.id, {
|
118
|
+
loadAs: otherAccount,
|
119
|
+
resolve: {
|
120
|
+
profile: true,
|
121
|
+
},
|
122
|
+
});
|
123
|
+
|
124
|
+
assert(loadedAccount);
|
125
|
+
expect(loadedAccount.profile.name).toBe("test 1");
|
126
|
+
});
|
127
|
+
|
128
|
+
test("loading raw accounts should work", async () => {
|
129
|
+
const account = await createJazzTestAccount({
|
130
|
+
creationProps: {
|
131
|
+
name: "test 1",
|
132
|
+
},
|
133
|
+
});
|
134
|
+
|
135
|
+
const loadedAccount = await Account.load(account.id, {
|
136
|
+
loadAs: account,
|
137
|
+
});
|
138
|
+
|
139
|
+
assert(loadedAccount);
|
140
|
+
expect(loadedAccount.profile!.name).toBe("test 1");
|
141
|
+
});
|
@@ -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
|
+
});
|