jazz-tools 0.13.25 → 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/dist/index.js CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  parseInviteLink,
35
35
  randomSessionProvider,
36
36
  subscribeToCoValue
37
- } from "./chunk-Z6IXFGH3.js";
37
+ } from "./chunk-E4PALNK7.js";
38
38
 
39
39
  // src/index.ts
40
40
  import { MAX_RECOMMENDED_TX_SIZE, cojsonInternals } from "cojson";
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/subscribe/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAY,MAAM,QAAQ,CAAC;AAE1D,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"}
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
@@ -5,7 +5,7 @@ import {
5
5
  createAnonymousJazzContext,
6
6
  createJazzContext,
7
7
  randomSessionProvider
8
- } from "./chunk-Z6IXFGH3.js";
8
+ } from "./chunk-E4PALNK7.js";
9
9
 
10
10
  // src/testing.ts
11
11
  import { LocalNode } from "cojson";
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "type": "module",
19
19
  "license": "MIT",
20
- "version": "0.13.25",
20
+ "version": "0.13.26",
21
21
  "dependencies": {
22
22
  "@scure/bip39": "^1.3.0",
23
23
  "fast-myers-diff": "^3.2.0",
@@ -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 = ruleset.type === "group" || owner.myRole() !== undefined;
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") {
@@ -1,13 +1,13 @@
1
- import { RawAccount, RawCoValue, RawGroup } from "cojson";
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
- let owner = raw instanceof RawGroup ? raw : raw.group;
8
+ const owner = raw.group;
9
9
 
10
- return coValuesCache.get(owner as any, () =>
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 { expect, test } from "vitest";
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
+ });