jazz-tools 0.19.8 → 0.19.11
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 +56 -50
- package/CHANGELOG.md +30 -3
- package/dist/{chunk-2S3Z2CN6.js → chunk-HX5S6W5E.js} +372 -103
- package/dist/chunk-HX5S6W5E.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/inspector/account-switcher.d.ts +4 -0
- package/dist/inspector/account-switcher.d.ts.map +1 -0
- package/dist/inspector/chunk-C6BJPHBQ.js +4096 -0
- package/dist/inspector/chunk-C6BJPHBQ.js.map +1 -0
- package/dist/inspector/contexts/node.d.ts +19 -0
- package/dist/inspector/contexts/node.d.ts.map +1 -0
- package/dist/inspector/{custom-element-P76EIWEV.js → custom-element-GJVBPZES.js} +1011 -884
- package/dist/inspector/custom-element-GJVBPZES.js.map +1 -0
- package/dist/inspector/{viewer/new-app.d.ts → in-app.d.ts} +3 -3
- package/dist/inspector/in-app.d.ts.map +1 -0
- package/dist/inspector/index.d.ts +0 -11
- package/dist/inspector/index.d.ts.map +1 -1
- package/dist/inspector/index.js +56 -3910
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/pages/home.d.ts +2 -0
- package/dist/inspector/pages/home.d.ts.map +1 -0
- package/dist/inspector/register-custom-element.js +1 -1
- package/dist/inspector/router/context.d.ts +12 -0
- package/dist/inspector/router/context.d.ts.map +1 -0
- package/dist/inspector/router/hash-router.d.ts +7 -0
- package/dist/inspector/router/hash-router.d.ts.map +1 -0
- package/dist/inspector/router/in-memory-router.d.ts +7 -0
- package/dist/inspector/router/in-memory-router.d.ts.map +1 -0
- package/dist/inspector/router/index.d.ts +5 -0
- package/dist/inspector/router/index.d.ts.map +1 -0
- package/dist/inspector/standalone.d.ts +6 -0
- package/dist/inspector/standalone.d.ts.map +1 -0
- package/dist/inspector/standalone.js +420 -0
- package/dist/inspector/standalone.js.map +1 -0
- package/dist/inspector/tests/router/hash-router.test.d.ts +2 -0
- package/dist/inspector/tests/router/hash-router.test.d.ts.map +1 -0
- package/dist/inspector/tests/router/in-memory-router.test.d.ts +2 -0
- package/dist/inspector/tests/router/in-memory-router.test.d.ts.map +1 -0
- package/dist/inspector/ui/modal.d.ts +1 -0
- package/dist/inspector/ui/modal.d.ts.map +1 -1
- package/dist/inspector/viewer/breadcrumbs.d.ts +1 -7
- package/dist/inspector/viewer/breadcrumbs.d.ts.map +1 -1
- package/dist/inspector/viewer/header.d.ts +7 -0
- package/dist/inspector/viewer/header.d.ts.map +1 -0
- package/dist/inspector/viewer/page-stack.d.ts +4 -13
- package/dist/inspector/viewer/page-stack.d.ts.map +1 -1
- package/dist/inspector/viewer/page.d.ts.map +1 -1
- package/dist/react/hooks.d.ts +1 -1
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts +59 -0
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +124 -36
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/tests/testUtils.d.ts +1 -0
- package/dist/react-core/tests/testUtils.d.ts.map +1 -1
- package/dist/react-core/tests/useSuspenseAccount.test.d.ts +2 -0
- package/dist/react-core/tests/useSuspenseAccount.test.d.ts.map +1 -0
- package/dist/react-core/tests/useSuspenseCoState.test.d.ts +2 -0
- package/dist/react-core/tests/useSuspenseCoState.test.d.ts.map +1 -0
- package/dist/react-core/use.d.ts +3 -0
- package/dist/react-core/use.d.ts.map +1 -0
- package/dist/react-native/index.js +5 -1
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native-core/crypto/RNCrypto.d.ts +2 -0
- package/dist/react-native-core/crypto/RNCrypto.d.ts.map +1 -0
- package/dist/react-native-core/crypto/RNCrypto.js +3 -0
- package/dist/react-native-core/crypto/RNCrypto.js.map +1 -0
- package/dist/react-native-core/hooks.d.ts +1 -1
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-core/index.js +5 -1
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/react-native-core/platform.d.ts +2 -1
- package/dist/react-native-core/platform.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/account.d.ts +7 -1
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +1 -1
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/implementation/ContextManager.d.ts +3 -0
- package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +8 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +8 -22
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionCache.d.ts +51 -0
- package/dist/tools/subscribe/SubscriptionCache.d.ts.map +1 -0
- package/dist/tools/subscribe/SubscriptionScope.d.ts +17 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/utils.d.ts +9 -1
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts +2 -2
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/SubscriptionCache.test.d.ts +2 -0
- package/dist/tools/tests/SubscriptionCache.test.d.ts.map +1 -0
- package/package.json +18 -6
- package/src/inspector/account-switcher.tsx +440 -0
- package/src/inspector/contexts/node.tsx +129 -0
- package/src/inspector/custom-element.tsx +2 -2
- package/src/inspector/in-app.tsx +61 -0
- package/src/inspector/index.tsx +2 -22
- package/src/inspector/pages/home.tsx +77 -0
- package/src/inspector/router/context.ts +21 -0
- package/src/inspector/router/hash-router.tsx +128 -0
- package/src/inspector/{viewer/use-page-path.ts → router/in-memory-router.tsx} +31 -29
- package/src/inspector/router/index.ts +4 -0
- package/src/inspector/standalone.tsx +60 -0
- package/src/inspector/tests/router/hash-router.test.tsx +847 -0
- package/src/inspector/tests/router/in-memory-router.test.tsx +724 -0
- package/src/inspector/ui/modal.tsx +5 -2
- package/src/inspector/viewer/breadcrumbs.tsx +5 -11
- package/src/inspector/viewer/header.tsx +67 -0
- package/src/inspector/viewer/page-stack.tsx +18 -26
- package/src/inspector/viewer/page.tsx +0 -1
- package/src/react/hooks.tsx +2 -0
- package/src/react/index.ts +1 -14
- package/src/react-core/hooks.ts +167 -18
- package/src/react-core/tests/createCoValueSubscriptionContext.test.tsx +18 -8
- package/src/react-core/tests/testUtils.tsx +67 -5
- package/src/react-core/tests/useCoState.test.ts +3 -7
- package/src/react-core/tests/useSubscriptionSelector.test.ts +3 -7
- package/src/react-core/tests/useSuspenseAccount.test.tsx +343 -0
- package/src/react-core/tests/useSuspenseCoState.test.tsx +1182 -0
- package/src/react-core/use.ts +46 -0
- package/src/react-native-core/crypto/RNCrypto.ts +1 -0
- package/src/react-native-core/hooks.tsx +2 -0
- package/src/react-native-core/platform.ts +2 -1
- package/src/tools/coValues/account.ts +13 -2
- package/src/tools/coValues/interfaces.ts +2 -3
- package/src/tools/implementation/ContextManager.ts +13 -0
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +8 -1
- package/src/tools/subscribe/CoValueCoreSubscription.ts +71 -100
- package/src/tools/subscribe/SubscriptionCache.ts +272 -0
- package/src/tools/subscribe/SubscriptionScope.ts +113 -7
- package/src/tools/subscribe/utils.ts +77 -0
- package/src/tools/testing.ts +0 -3
- package/src/tools/tests/CoValueCoreSubscription.test.ts +46 -12
- package/src/tools/tests/ContextManager.test.ts +85 -0
- package/src/tools/tests/SubscriptionCache.test.ts +237 -0
- package/src/tools/tests/account.test.ts +11 -4
- package/src/tools/tests/coMap.test.ts +5 -7
- package/src/tools/tests/schema.resolved.test.ts +3 -3
- package/tsup.config.ts +2 -0
- package/dist/chunk-2S3Z2CN6.js.map +0 -1
- package/dist/inspector/custom-element-P76EIWEV.js.map +0 -1
- package/dist/inspector/viewer/new-app.d.ts.map +0 -1
- package/dist/inspector/viewer/use-page-path.d.ts +0 -10
- package/dist/inspector/viewer/use-page-path.d.ts.map +0 -1
- package/src/inspector/viewer/new-app.tsx +0 -156
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
getPeerConnectedToTestSyncServer,
|
|
34
34
|
setupJazzTestSync,
|
|
35
35
|
} from "../testing";
|
|
36
|
+
import { SubscriptionCache } from "../subscribe/SubscriptionCache";
|
|
36
37
|
import { createAsyncStorage, getDbPath } from "./testStorage";
|
|
37
38
|
|
|
38
39
|
const Crypto = await WasmCrypto.create();
|
|
@@ -809,4 +810,88 @@ describe("ContextManager", () => {
|
|
|
809
810
|
);
|
|
810
811
|
});
|
|
811
812
|
});
|
|
813
|
+
|
|
814
|
+
describe("SubscriptionCache integration", () => {
|
|
815
|
+
test("initializes cache on construction", () => {
|
|
816
|
+
const newManager = new TestJazzContextManager<Account>();
|
|
817
|
+
const cache = newManager.getSubscriptionScopeCache();
|
|
818
|
+
|
|
819
|
+
expect(cache).toBeDefined();
|
|
820
|
+
expect(cache).toBeInstanceOf(SubscriptionCache);
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
test("getSubscriptionScopeCache returns the cache instance", () => {
|
|
824
|
+
const cache1 = manager.getSubscriptionScopeCache();
|
|
825
|
+
const cache2 = manager.getSubscriptionScopeCache();
|
|
826
|
+
|
|
827
|
+
expect(cache1).toBe(cache2);
|
|
828
|
+
expect(cache1).toBeDefined();
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
test("updateContext clears the cache", async () => {
|
|
832
|
+
await manager.createContext({});
|
|
833
|
+
|
|
834
|
+
const cache = manager.getSubscriptionScopeCache();
|
|
835
|
+
const node = getCurrentValue().node;
|
|
836
|
+
const Person = co.map({ name: z.string() });
|
|
837
|
+
const person = Person.create({ name: "Test" });
|
|
838
|
+
|
|
839
|
+
// Create a subscription in the cache
|
|
840
|
+
const scope = cache.getOrCreate(
|
|
841
|
+
node,
|
|
842
|
+
Person,
|
|
843
|
+
person.$jazz.id,
|
|
844
|
+
true,
|
|
845
|
+
false,
|
|
846
|
+
false,
|
|
847
|
+
);
|
|
848
|
+
|
|
849
|
+
// Verify it's in the cache
|
|
850
|
+
const idSet = (cache as any).cache.get(person.$jazz.id);
|
|
851
|
+
expect(idSet).toBeDefined();
|
|
852
|
+
expect(idSet).toBeInstanceOf(Set);
|
|
853
|
+
expect(idSet.size).toBeGreaterThan(0);
|
|
854
|
+
|
|
855
|
+
// Update context - should clear cache
|
|
856
|
+
await manager.createContext({});
|
|
857
|
+
|
|
858
|
+
// Verify cache was cleared
|
|
859
|
+
const idSetAfter = (cache as any).cache.get(person.$jazz.id);
|
|
860
|
+
expect(idSetAfter).toBeUndefined();
|
|
861
|
+
expect(scope.closed).toBe(true);
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
test("logOut clears the cache", async () => {
|
|
865
|
+
await manager.createContext({});
|
|
866
|
+
|
|
867
|
+
const cache = manager.getSubscriptionScopeCache();
|
|
868
|
+
const node = getCurrentValue().node;
|
|
869
|
+
const Person = co.map({ name: z.string() });
|
|
870
|
+
const person = Person.create({ name: "Test" });
|
|
871
|
+
|
|
872
|
+
// Create a subscription in the cache
|
|
873
|
+
const scope = cache.getOrCreate(
|
|
874
|
+
node,
|
|
875
|
+
Person,
|
|
876
|
+
person.$jazz.id,
|
|
877
|
+
true,
|
|
878
|
+
false,
|
|
879
|
+
false,
|
|
880
|
+
);
|
|
881
|
+
|
|
882
|
+
// Verify it's in the cache
|
|
883
|
+
const scopeSet = (cache as any).cache.get(person.$jazz.id);
|
|
884
|
+
expect(scopeSet).toBeDefined();
|
|
885
|
+
expect(scopeSet).toBeInstanceOf(Set);
|
|
886
|
+
expect(scopeSet.size).toBeGreaterThan(0);
|
|
887
|
+
|
|
888
|
+
// Logout - should clear cache
|
|
889
|
+
await manager.logOut();
|
|
890
|
+
|
|
891
|
+
// Verify cache was cleared
|
|
892
|
+
const scopeSetAfter = (cache as any).cache.get(person.$jazz.id);
|
|
893
|
+
expect(scopeSetAfter).toBeUndefined();
|
|
894
|
+
expect(scope.closed).toBe(true);
|
|
895
|
+
});
|
|
896
|
+
});
|
|
812
897
|
});
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { Account, Group, co, z } from "../exports.js";
|
|
3
|
+
import { SubscriptionCache } from "../subscribe/SubscriptionCache.js";
|
|
4
|
+
import { createJazzTestAccount, setupJazzTestSync } from "../testing.js";
|
|
5
|
+
|
|
6
|
+
describe("SubscriptionCache", () => {
|
|
7
|
+
const Person = co.map({
|
|
8
|
+
name: co.plainText(),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
await setupJazzTestSync();
|
|
13
|
+
await createJazzTestAccount({
|
|
14
|
+
isCurrentActiveAccount: true,
|
|
15
|
+
creationProps: { name: "Hermes Puggington" },
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("cache key comparison logic", () => {
|
|
20
|
+
it("matches entries with identical schema, id, resolve, and branch", () => {
|
|
21
|
+
const person = Person.create({ name: "John" });
|
|
22
|
+
const node = person.$jazz.raw.core.node;
|
|
23
|
+
const id = person.$jazz.id;
|
|
24
|
+
const cache = new SubscriptionCache();
|
|
25
|
+
|
|
26
|
+
const scope1 = cache.getOrCreate(node, Person, id, true, false, false);
|
|
27
|
+
const scope2 = cache.getOrCreate(node, Person, id, true, false, false);
|
|
28
|
+
|
|
29
|
+
expect(scope1).toBe(scope2);
|
|
30
|
+
cache.clear();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("creates different entries for different resolve queries", () => {
|
|
34
|
+
const person = Person.create({ name: "John" });
|
|
35
|
+
const node = person.$jazz.raw.core.node;
|
|
36
|
+
const id = person.$jazz.id;
|
|
37
|
+
const cache = new SubscriptionCache();
|
|
38
|
+
|
|
39
|
+
const scope1 = cache.getOrCreate(node, Person, id, true, false, false);
|
|
40
|
+
const scope2 = cache.getOrCreate(
|
|
41
|
+
node,
|
|
42
|
+
Person,
|
|
43
|
+
id,
|
|
44
|
+
{ name: true },
|
|
45
|
+
false,
|
|
46
|
+
false,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
expect(scope1).not.toBe(scope2);
|
|
50
|
+
cache.clear();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("creates different entries for different branch definitions", () => {
|
|
54
|
+
const person = Person.create({ name: "John" });
|
|
55
|
+
const group = Group.create();
|
|
56
|
+
const node = person.$jazz.raw.core.node;
|
|
57
|
+
const id = person.$jazz.id;
|
|
58
|
+
const cache = new SubscriptionCache();
|
|
59
|
+
|
|
60
|
+
const scope1 = cache.getOrCreate(node, Person, id, true, false, false, {
|
|
61
|
+
name: "branch1",
|
|
62
|
+
owner: group,
|
|
63
|
+
});
|
|
64
|
+
const scope2 = cache.getOrCreate(node, Person, id, true, false, false, {
|
|
65
|
+
name: "branch2",
|
|
66
|
+
owner: group,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(scope1).not.toBe(scope2);
|
|
70
|
+
cache.clear();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("matches entries with same branch name but different owner references", () => {
|
|
74
|
+
const person = Person.create({ name: "John" });
|
|
75
|
+
const group1 = Group.create();
|
|
76
|
+
const group2 = Group.create();
|
|
77
|
+
const node = person.$jazz.raw.core.node;
|
|
78
|
+
const id = person.$jazz.id;
|
|
79
|
+
const cache = new SubscriptionCache();
|
|
80
|
+
|
|
81
|
+
const scope1 = cache.getOrCreate(node, Person, id, true, false, false, {
|
|
82
|
+
name: "branch",
|
|
83
|
+
owner: group1,
|
|
84
|
+
});
|
|
85
|
+
const scope2 = cache.getOrCreate(node, Person, id, true, false, false, {
|
|
86
|
+
name: "branch",
|
|
87
|
+
owner: group2,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(scope1).not.toBe(scope2);
|
|
91
|
+
cache.clear();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("subscriber count tracking", () => {
|
|
96
|
+
it("tracks subscriber count changes via onSubscriberChange", () => {
|
|
97
|
+
const person = Person.create({ name: "John" });
|
|
98
|
+
const node = person.$jazz.raw.core.node;
|
|
99
|
+
const id = person.$jazz.id;
|
|
100
|
+
const cache = new SubscriptionCache();
|
|
101
|
+
|
|
102
|
+
const scope = cache.getOrCreate(node, Person, id, true, false, false);
|
|
103
|
+
|
|
104
|
+
expect(scope.subscribers.size).toBe(0);
|
|
105
|
+
|
|
106
|
+
const unsubscribe1 = scope.subscribe(() => {});
|
|
107
|
+
expect(scope.subscribers.size).toBe(1);
|
|
108
|
+
|
|
109
|
+
const unsubscribe2 = scope.subscribe(() => {});
|
|
110
|
+
expect(scope.subscribers.size).toBe(2);
|
|
111
|
+
|
|
112
|
+
unsubscribe1();
|
|
113
|
+
expect(scope.subscribers.size).toBe(1);
|
|
114
|
+
|
|
115
|
+
unsubscribe2();
|
|
116
|
+
expect(scope.subscribers.size).toBe(0);
|
|
117
|
+
|
|
118
|
+
cache.clear();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("cleanup lifecycle", () => {
|
|
123
|
+
it("schedules cleanup when subscriber count reaches zero", async () => {
|
|
124
|
+
vi.useFakeTimers();
|
|
125
|
+
const person = Person.create({ name: "John" });
|
|
126
|
+
const node = person.$jazz.raw.core.node;
|
|
127
|
+
const id = person.$jazz.id;
|
|
128
|
+
const cache = new SubscriptionCache(100); // 100ms timeout
|
|
129
|
+
|
|
130
|
+
const scope = cache.getOrCreate(node, Person, id, true, false, false);
|
|
131
|
+
|
|
132
|
+
const unsubscribe = scope.subscribe(() => {});
|
|
133
|
+
unsubscribe();
|
|
134
|
+
|
|
135
|
+
await vi.advanceTimersByTimeAsync(110);
|
|
136
|
+
|
|
137
|
+
expect(scope.closed).toBe(true);
|
|
138
|
+
|
|
139
|
+
cache.clear();
|
|
140
|
+
vi.useRealTimers();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("cancels cleanup when new subscription arrives during pending cleanup", async () => {
|
|
144
|
+
vi.useFakeTimers();
|
|
145
|
+
const person = Person.create({ name: "John" });
|
|
146
|
+
const node = person.$jazz.raw.core.node;
|
|
147
|
+
const id = person.$jazz.id;
|
|
148
|
+
const cache = new SubscriptionCache(100); // 100ms timeout
|
|
149
|
+
|
|
150
|
+
const scope1 = cache.getOrCreate(node, Person, id, true, false, false);
|
|
151
|
+
|
|
152
|
+
const unsubscribe = scope1.subscribe(() => {});
|
|
153
|
+
unsubscribe();
|
|
154
|
+
|
|
155
|
+
await vi.advanceTimersByTimeAsync(50);
|
|
156
|
+
|
|
157
|
+
// Request again before cleanup
|
|
158
|
+
const scope2 = cache.getOrCreate(node, Person, id, true, false, false);
|
|
159
|
+
|
|
160
|
+
expect(scope2).toBe(scope1);
|
|
161
|
+
await vi.advanceTimersByTimeAsync(60);
|
|
162
|
+
|
|
163
|
+
cache.clear();
|
|
164
|
+
vi.useRealTimers();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("executes cleanup after timeout", async () => {
|
|
168
|
+
vi.useFakeTimers();
|
|
169
|
+
const person = Person.create({ name: "John" });
|
|
170
|
+
const node = person.$jazz.raw.core.node;
|
|
171
|
+
const id = person.$jazz.id;
|
|
172
|
+
const cache = new SubscriptionCache(100); // 100ms timeout
|
|
173
|
+
|
|
174
|
+
const scope = cache.getOrCreate(node, Person, id, true, false, false);
|
|
175
|
+
|
|
176
|
+
const unsubscribe = scope.subscribe(() => {});
|
|
177
|
+
unsubscribe();
|
|
178
|
+
|
|
179
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
180
|
+
|
|
181
|
+
const idSet = (cache as any).cache.get(id);
|
|
182
|
+
expect(idSet).toBeUndefined();
|
|
183
|
+
|
|
184
|
+
cache.clear();
|
|
185
|
+
vi.useRealTimers();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("clear method", () => {
|
|
190
|
+
it("destroys all entries", () => {
|
|
191
|
+
const person1 = Person.create({ name: "John" });
|
|
192
|
+
const person2 = Person.create({ name: "Jane" });
|
|
193
|
+
const node = person1.$jazz.raw.core.node;
|
|
194
|
+
const cache = new SubscriptionCache();
|
|
195
|
+
|
|
196
|
+
const scope1 = cache.getOrCreate(
|
|
197
|
+
node,
|
|
198
|
+
Person,
|
|
199
|
+
person1.$jazz.id,
|
|
200
|
+
true,
|
|
201
|
+
false,
|
|
202
|
+
false,
|
|
203
|
+
);
|
|
204
|
+
const scope2 = cache.getOrCreate(
|
|
205
|
+
node,
|
|
206
|
+
Person,
|
|
207
|
+
person2.$jazz.id,
|
|
208
|
+
true,
|
|
209
|
+
false,
|
|
210
|
+
false,
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
cache.clear();
|
|
214
|
+
|
|
215
|
+
expect(scope1.closed).toBe(true);
|
|
216
|
+
expect(scope2.closed).toBe(true);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe("edge cases", () => {
|
|
221
|
+
it("throws error for null/undefined id", () => {
|
|
222
|
+
const person = Person.create({ name: "John" });
|
|
223
|
+
const node = person.$jazz.raw.core.node;
|
|
224
|
+
const cache = new SubscriptionCache();
|
|
225
|
+
|
|
226
|
+
expect(() => {
|
|
227
|
+
cache.getOrCreate(node, Person, null as any, true, false, false);
|
|
228
|
+
}).toThrow("Cannot create subscription with undefined or null id");
|
|
229
|
+
|
|
230
|
+
expect(() => {
|
|
231
|
+
cache.getOrCreate(node, Person, undefined as any, true, false, false);
|
|
232
|
+
}).toThrow("Cannot create subscription with undefined or null id");
|
|
233
|
+
|
|
234
|
+
cache.clear();
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -467,7 +467,7 @@ describe("createAs", () => {
|
|
|
467
467
|
{ owner: worker },
|
|
468
468
|
);
|
|
469
469
|
|
|
470
|
-
const
|
|
470
|
+
const created = await CustomAccount.createAs(worker, {
|
|
471
471
|
creationProps: { name: "Test Account" },
|
|
472
472
|
onCreate: async (account, loadedWorker) => {
|
|
473
473
|
executionOrder.push("onCreate");
|
|
@@ -490,11 +490,18 @@ describe("createAs", () => {
|
|
|
490
490
|
},
|
|
491
491
|
});
|
|
492
492
|
|
|
493
|
-
assertLoaded(
|
|
494
|
-
assertLoaded(
|
|
493
|
+
assertLoaded(created.account);
|
|
494
|
+
assertLoaded(created.account.root);
|
|
495
|
+
|
|
496
|
+
expect(created.credentials.accountID).toBe(created.account.$jazz.id);
|
|
497
|
+
// ensure we get the created, not the creat*ing* account credentials
|
|
498
|
+
expect(created.credentials.accountID).not.toBe(worker.$jazz.id);
|
|
499
|
+
expect(created.credentials.accountSecret).not.toBe(
|
|
500
|
+
worker.$jazz.localNode.getCurrentAgent().agentSecret,
|
|
501
|
+
);
|
|
495
502
|
|
|
496
503
|
// Verify onCreate was called and root was set from worker
|
|
497
|
-
expect(
|
|
504
|
+
expect(created.account.root.value).toBe("worker-root");
|
|
498
505
|
|
|
499
506
|
// Verify execution order
|
|
500
507
|
expect(executionOrder).toEqual(["migration", "onCreate"]);
|
|
@@ -1098,6 +1098,7 @@ describe("CoMap resolution", async () => {
|
|
|
1098
1098
|
});
|
|
1099
1099
|
|
|
1100
1100
|
test("loading a remotely available map with skipRetry set to false", async () => {
|
|
1101
|
+
disableJazzTestSync();
|
|
1101
1102
|
// Make the retry delay extra long to avoid flakyness in the resolved checks
|
|
1102
1103
|
cojsonInternals.CO_VALUE_LOADING_CONFIG.RETRY_DELAY = 100_000_000;
|
|
1103
1104
|
|
|
@@ -1114,13 +1115,6 @@ describe("CoMap resolution", async () => {
|
|
|
1114
1115
|
|
|
1115
1116
|
const currentAccount = Account.getMe();
|
|
1116
1117
|
|
|
1117
|
-
// Disconnect the current account
|
|
1118
|
-
currentAccount.$jazz.localNode.syncManager
|
|
1119
|
-
.getServerPeers(currentAccount.$jazz.raw.id)
|
|
1120
|
-
.forEach((peer) => {
|
|
1121
|
-
peer.gracefulShutdown();
|
|
1122
|
-
});
|
|
1123
|
-
|
|
1124
1118
|
const group = Group.create();
|
|
1125
1119
|
group.addMember("everyone", "writer");
|
|
1126
1120
|
|
|
@@ -1133,6 +1127,10 @@ describe("CoMap resolution", async () => {
|
|
|
1133
1127
|
group,
|
|
1134
1128
|
);
|
|
1135
1129
|
|
|
1130
|
+
await setupJazzTestSync({
|
|
1131
|
+
asyncPeers: true,
|
|
1132
|
+
});
|
|
1133
|
+
|
|
1136
1134
|
const userB = await createJazzTestAccount();
|
|
1137
1135
|
let resolved = false;
|
|
1138
1136
|
const promise = Person.load(person.$jazz.id, {
|
|
@@ -246,7 +246,7 @@ describe("Schema.resolved()", () => {
|
|
|
246
246
|
profile: true,
|
|
247
247
|
});
|
|
248
248
|
|
|
249
|
-
const account = await AccountWithProfile.createAs(serverAccount, {
|
|
249
|
+
const { account } = await AccountWithProfile.createAs(serverAccount, {
|
|
250
250
|
creationProps: { name: "Hermes Puggington" },
|
|
251
251
|
onCreate: async (account) => {
|
|
252
252
|
account.$jazz.set(
|
|
@@ -405,7 +405,7 @@ describe("Schema.resolved()", () => {
|
|
|
405
405
|
test("for Account", async () => {
|
|
406
406
|
const AccountWithProfile = co.account().resolved({ profile: true });
|
|
407
407
|
|
|
408
|
-
const account = await AccountWithProfile.createAs(serverAccount, {
|
|
408
|
+
const { account } = await AccountWithProfile.createAs(serverAccount, {
|
|
409
409
|
creationProps: { name: "Hermes Puggington" },
|
|
410
410
|
onCreate: async (account) => {
|
|
411
411
|
account.$jazz.set(
|
|
@@ -561,7 +561,7 @@ describe("Schema.resolved()", () => {
|
|
|
561
561
|
.list(TestAccount)
|
|
562
562
|
.resolved({ $each: TestAccount.resolveQuery });
|
|
563
563
|
|
|
564
|
-
const account = await TestAccount.createAs(serverAccount, {
|
|
564
|
+
const { account } = await TestAccount.createAs(serverAccount, {
|
|
565
565
|
creationProps: { name: "Hermes Puggington" },
|
|
566
566
|
onCreate: async (account) => {
|
|
567
567
|
account.$jazz.set(
|
package/tsup.config.ts
CHANGED
|
@@ -58,6 +58,7 @@ export default defineConfig([
|
|
|
58
58
|
...cfg,
|
|
59
59
|
entry: {
|
|
60
60
|
index: "src/inspector/index.tsx",
|
|
61
|
+
standalone: "src/inspector/standalone.tsx",
|
|
61
62
|
},
|
|
62
63
|
outDir: "dist/inspector",
|
|
63
64
|
esbuildOptions: (options) => {
|
|
@@ -132,6 +133,7 @@ export default defineConfig([
|
|
|
132
133
|
index: "src/react-native-core/index.ts",
|
|
133
134
|
testing: "src/react-native-core/testing.tsx",
|
|
134
135
|
crypto: "src/react-native-core/crypto/index.ts",
|
|
136
|
+
"crypto/RNCrypto": "src/react-native-core/crypto/RNCrypto.ts",
|
|
135
137
|
},
|
|
136
138
|
outDir: "dist/react-native-core",
|
|
137
139
|
},
|