jazz-tools 0.19.12 → 0.19.13
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 +50 -50
- package/CHANGELOG.md +10 -0
- package/dist/browser/createBrowserContext.d.ts +1 -5
- package/dist/browser/createBrowserContext.d.ts.map +1 -1
- package/dist/browser/index.js +124 -47
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/provideBrowserLockSession/BrowserSessionProvider.d.ts +12 -0
- package/dist/browser/provideBrowserLockSession/BrowserSessionProvider.d.ts.map +1 -0
- package/dist/browser/provideBrowserLockSession/BrowserSessionProvider.test.d.ts +2 -0
- package/dist/browser/provideBrowserLockSession/BrowserSessionProvider.test.d.ts.map +1 -0
- package/dist/browser/provideBrowserLockSession/SessionIDStorage.d.ts +6 -0
- package/dist/browser/provideBrowserLockSession/SessionIDStorage.d.ts.map +1 -0
- package/dist/browser/provideBrowserLockSession/index.d.ts +4 -0
- package/dist/browser/provideBrowserLockSession/index.d.ts.map +1 -0
- package/dist/{chunk-AGF4HEDH.js → chunk-GAPMDNJY.js} +437 -82
- package/dist/chunk-GAPMDNJY.js.map +1 -0
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/react-native/index.js +41 -12
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native-core/ReactNativeSessionProvider.d.ts +11 -0
- package/dist/react-native-core/ReactNativeSessionProvider.d.ts.map +1 -0
- package/dist/react-native-core/index.js +41 -12
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/react-native-core/platform.d.ts +2 -8
- package/dist/react-native-core/platform.d.ts.map +1 -1
- package/dist/react-native-core/tests/ReactNativeSessionProvider.test.d.ts +2 -0
- package/dist/react-native-core/tests/ReactNativeSessionProvider.test.d.ts.map +1 -0
- package/dist/testing.js +4 -3
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts +2 -2
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts +1 -2
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/coVector.d.ts.map +1 -1
- package/dist/tools/coValues/group.d.ts +5 -1
- package/dist/tools/coValues/group.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +2 -1
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +2 -2
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/createContext.d.ts +21 -11
- package/dist/tools/implementation/createContext.d.ts.map +1 -1
- package/dist/tools/implementation/schema.d.ts +14 -6
- package/dist/tools/implementation/schema.d.ts.map +1 -1
- package/dist/tools/implementation/schemaUtils.d.ts +1 -1
- package/dist/tools/implementation/schemaUtils.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaPermissions.d.ts +99 -0
- package/dist/tools/implementation/zodSchema/schemaPermissions.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +11 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +11 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +15 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +10 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +9 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +13 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +10 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +6 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts +12 -1
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +1 -0
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/schema.withPermissions.test.d.ts +2 -0
- package/dist/tools/tests/schema.withPermissions.test.d.ts.map +1 -0
- package/dist/worker/index.js +2 -2
- package/dist/worker/index.js.map +1 -1
- package/package.json +4 -4
- package/src/browser/createBrowserContext.ts +3 -62
- package/src/browser/provideBrowserLockSession/BrowserSessionProvider.test.ts +406 -0
- package/src/browser/provideBrowserLockSession/BrowserSessionProvider.ts +132 -0
- package/src/browser/provideBrowserLockSession/SessionIDStorage.ts +33 -0
- package/src/browser/provideBrowserLockSession/index.ts +11 -0
- package/src/react-native-core/ReactNativeSessionProvider.ts +52 -0
- package/src/react-native-core/platform.ts +5 -30
- package/src/react-native-core/tests/ReactNativeSessionProvider.test.ts +124 -0
- package/src/tools/coValues/account.ts +4 -0
- package/src/tools/coValues/coFeed.ts +8 -3
- package/src/tools/coValues/coList.ts +6 -3
- package/src/tools/coValues/coMap.ts +10 -0
- package/src/tools/coValues/coVector.ts +2 -1
- package/src/tools/coValues/group.ts +6 -4
- package/src/tools/coValues/interfaces.ts +19 -7
- package/src/tools/exports.ts +3 -1
- package/src/tools/implementation/createContext.ts +43 -15
- package/src/tools/implementation/schema.ts +23 -13
- package/src/tools/implementation/schemaUtils.ts +1 -1
- package/src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts +105 -4
- package/src/tools/implementation/zodSchema/schemaPermissions.ts +188 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +46 -3
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +46 -3
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +50 -13
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +14 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +24 -1
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +51 -4
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +25 -1
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +21 -1
- package/src/tools/implementation/zodSchema/unionUtils.ts +72 -20
- package/src/tools/internal.ts +1 -0
- package/src/tools/testing.ts +3 -1
- package/src/tools/tests/ContextManager.test.ts +2 -1
- package/src/tools/tests/coPlainText.test.ts +2 -2
- package/src/tools/tests/createContext.test.ts +79 -1
- package/src/tools/tests/deepLoading.test.ts +25 -2
- package/src/tools/tests/schema.resolved.test.ts +10 -0
- package/src/tools/tests/schema.withPermissions.test.ts +859 -0
- package/src/tools/tests/utils.ts +2 -2
- package/src/worker/index.ts +2 -2
- package/dist/chunk-AGF4HEDH.js.map +0 -1
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
createJazzContext,
|
|
16
16
|
createJazzContextForNewAccount,
|
|
17
17
|
createJazzContextFromExistingCredentials,
|
|
18
|
-
|
|
18
|
+
MockSessionProvider,
|
|
19
19
|
} from "../exports";
|
|
20
20
|
import { activeAccountContext } from "../implementation/activeAccountContext";
|
|
21
21
|
import {
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
import { assertLoaded, loadCoValueOrFail } from "./utils";
|
|
27
27
|
const Crypto = await WasmCrypto.create();
|
|
28
28
|
|
|
29
|
+
let randomSessionProvider = new MockSessionProvider();
|
|
29
30
|
KvStoreContext.getInstance().initialize(new InMemoryKVStore());
|
|
30
31
|
|
|
31
32
|
describe("createContext methods", () => {
|
|
@@ -35,6 +36,9 @@ describe("createContext methods", () => {
|
|
|
35
36
|
authSecretStorage = new AuthSecretStorage();
|
|
36
37
|
authSecretStorage.clear();
|
|
37
38
|
await setupJazzTestSync();
|
|
39
|
+
randomSessionProvider = new MockSessionProvider();
|
|
40
|
+
vi.spyOn(randomSessionProvider, "acquireSession");
|
|
41
|
+
vi.spyOn(randomSessionProvider, "persistSession");
|
|
38
42
|
});
|
|
39
43
|
|
|
40
44
|
describe("createJazzContextFromExistingCredentials", () => {
|
|
@@ -49,6 +53,13 @@ describe("createContext methods", () => {
|
|
|
49
53
|
secret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
|
50
54
|
};
|
|
51
55
|
|
|
56
|
+
const sessionID = Crypto.newRandomSessionID(account.$jazz.raw.id);
|
|
57
|
+
|
|
58
|
+
vi.spyOn(randomSessionProvider, "acquireSession").mockResolvedValue({
|
|
59
|
+
sessionID: sessionID,
|
|
60
|
+
sessionDone: () => {},
|
|
61
|
+
});
|
|
62
|
+
|
|
52
63
|
const context = await createJazzContextFromExistingCredentials({
|
|
53
64
|
credentials,
|
|
54
65
|
peers: [getPeerConnectedToTestSyncServer()],
|
|
@@ -60,10 +71,47 @@ describe("createContext methods", () => {
|
|
|
60
71
|
expect(context.node).toBeDefined();
|
|
61
72
|
expect(context.account).toBeDefined();
|
|
62
73
|
expect(context.account.$jazz.id).toBe(credentials.accountID);
|
|
74
|
+
expect(context.node.currentSessionID).toBe(sessionID);
|
|
63
75
|
expect(typeof context.done).toBe("function");
|
|
64
76
|
expect(typeof context.logOut).toBe("function");
|
|
65
77
|
});
|
|
66
78
|
|
|
79
|
+
test("releasese the session when the context is done", async () => {
|
|
80
|
+
const spy = vi.fn();
|
|
81
|
+
|
|
82
|
+
// Create an account first to get valid credentials
|
|
83
|
+
const account = await createJazzTestAccount({
|
|
84
|
+
isCurrentActiveAccount: true,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const credentials: Credentials = {
|
|
88
|
+
accountID: account.$jazz.id,
|
|
89
|
+
secret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const sessionID = Crypto.newRandomSessionID(account.$jazz.raw.id);
|
|
93
|
+
|
|
94
|
+
vi.spyOn(randomSessionProvider, "acquireSession").mockResolvedValue({
|
|
95
|
+
sessionID: sessionID,
|
|
96
|
+
sessionDone: spy,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const context = await createJazzContextFromExistingCredentials({
|
|
100
|
+
credentials,
|
|
101
|
+
peers: [getPeerConnectedToTestSyncServer()],
|
|
102
|
+
crypto: Crypto,
|
|
103
|
+
sessionProvider: randomSessionProvider,
|
|
104
|
+
asActiveAccount: true,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(randomSessionProvider.acquireSession).toHaveBeenCalled();
|
|
108
|
+
expect(spy).not.toHaveBeenCalled();
|
|
109
|
+
|
|
110
|
+
context.done();
|
|
111
|
+
|
|
112
|
+
expect(spy).toHaveBeenCalled();
|
|
113
|
+
});
|
|
114
|
+
|
|
67
115
|
test("handles custom account schema", async () => {
|
|
68
116
|
const CustomAccount = co
|
|
69
117
|
.account({
|
|
@@ -187,6 +235,7 @@ describe("createContext methods", () => {
|
|
|
187
235
|
creationProps: { name: "New User" },
|
|
188
236
|
peers: [],
|
|
189
237
|
crypto: Crypto,
|
|
238
|
+
sessionProvider: randomSessionProvider,
|
|
190
239
|
});
|
|
191
240
|
|
|
192
241
|
expect(context.account).toBeDefined();
|
|
@@ -202,11 +251,38 @@ describe("createContext methods", () => {
|
|
|
202
251
|
initialAgentSecret: initialSecret,
|
|
203
252
|
peers: [],
|
|
204
253
|
crypto: Crypto,
|
|
254
|
+
sessionProvider: randomSessionProvider,
|
|
205
255
|
});
|
|
206
256
|
|
|
257
|
+
expect(randomSessionProvider.persistSession).toHaveBeenCalledWith(
|
|
258
|
+
context.account.$jazz.id,
|
|
259
|
+
context.node.currentSessionID,
|
|
260
|
+
);
|
|
261
|
+
expect(randomSessionProvider.acquireSession).not.toHaveBeenCalled();
|
|
207
262
|
expect(context.node.getCurrentAgent().agentSecret).toBe(initialSecret);
|
|
208
263
|
});
|
|
209
264
|
|
|
265
|
+
test("releasese the session when the context is done", async () => {
|
|
266
|
+
const spy = vi.fn();
|
|
267
|
+
vi.spyOn(randomSessionProvider, "persistSession").mockResolvedValue({
|
|
268
|
+
sessionDone: spy,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const context = await createJazzContextForNewAccount({
|
|
272
|
+
creationProps: { name: "New User" },
|
|
273
|
+
peers: [],
|
|
274
|
+
crypto: Crypto,
|
|
275
|
+
sessionProvider: randomSessionProvider,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
expect(randomSessionProvider.persistSession).toHaveBeenCalled();
|
|
279
|
+
expect(spy).not.toHaveBeenCalled();
|
|
280
|
+
|
|
281
|
+
context.done();
|
|
282
|
+
|
|
283
|
+
expect(spy).toHaveBeenCalled();
|
|
284
|
+
});
|
|
285
|
+
|
|
210
286
|
test("handles custom account schema", async () => {
|
|
211
287
|
const CustomAccount = co
|
|
212
288
|
.account({
|
|
@@ -220,6 +296,7 @@ describe("createContext methods", () => {
|
|
|
220
296
|
peers: [],
|
|
221
297
|
crypto: Crypto,
|
|
222
298
|
AccountSchema: CustomAccount,
|
|
299
|
+
sessionProvider: randomSessionProvider,
|
|
223
300
|
});
|
|
224
301
|
|
|
225
302
|
expect(context.account).toBeInstanceOf(
|
|
@@ -232,6 +309,7 @@ describe("createContext methods", () => {
|
|
|
232
309
|
creationProps: { name: "New User" },
|
|
233
310
|
peers: [],
|
|
234
311
|
crypto: Crypto,
|
|
312
|
+
sessionProvider: randomSessionProvider,
|
|
235
313
|
});
|
|
236
314
|
expect(activeAccountContext.get()).toBe(context.account);
|
|
237
315
|
});
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
MaybeLoaded,
|
|
24
24
|
Settled,
|
|
25
25
|
co,
|
|
26
|
-
|
|
26
|
+
MockSessionProvider,
|
|
27
27
|
CoValueLoadingState,
|
|
28
28
|
CoValueErrorState,
|
|
29
29
|
} from "../internal.js";
|
|
@@ -33,7 +33,7 @@ import { setCustomErrorReporter } from "../config.js";
|
|
|
33
33
|
|
|
34
34
|
const Crypto = await WasmCrypto.create();
|
|
35
35
|
const { connectedPeers } = cojsonInternals;
|
|
36
|
-
|
|
36
|
+
const randomSessionProvider = new MockSessionProvider();
|
|
37
37
|
const InnermostMap = co.map({
|
|
38
38
|
value: z.string(),
|
|
39
39
|
});
|
|
@@ -1192,6 +1192,29 @@ test("should not throw when calling ensureLoaded a record with a non-existent ke
|
|
|
1192
1192
|
expect(loadedPerson.pet1).toBeUndefined();
|
|
1193
1193
|
});
|
|
1194
1194
|
|
|
1195
|
+
test("should load a record with a non-existent key if there's a catch block", async () => {
|
|
1196
|
+
const Person = co.record(
|
|
1197
|
+
z.string(),
|
|
1198
|
+
co.map({
|
|
1199
|
+
name: z.string(),
|
|
1200
|
+
breed: z.string(),
|
|
1201
|
+
}),
|
|
1202
|
+
);
|
|
1203
|
+
|
|
1204
|
+
const person = Person.create({});
|
|
1205
|
+
|
|
1206
|
+
const loadedPerson = await Person.load(person.$jazz.id, {
|
|
1207
|
+
resolve: {
|
|
1208
|
+
pet1: {
|
|
1209
|
+
$onError: "catch",
|
|
1210
|
+
},
|
|
1211
|
+
},
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
assertLoaded(loadedPerson);
|
|
1215
|
+
expect(loadedPerson.pet1).toBeUndefined();
|
|
1216
|
+
});
|
|
1217
|
+
|
|
1195
1218
|
// This was a regression that ocurred when we migrated `DeeplyLoaded` to use explicit loading states.
|
|
1196
1219
|
// Keeping this test to prevent it from happening again.
|
|
1197
1220
|
test("deep loaded CoList nested inside another CoValue can be iterated over", async () => {
|
|
@@ -796,4 +796,14 @@ describe("Schema.resolved()", () => {
|
|
|
796
796
|
expect(loadedPerson.friends[0]?.friends.$isLoaded).toBe(false);
|
|
797
797
|
});
|
|
798
798
|
});
|
|
799
|
+
|
|
800
|
+
test("resolved() does not override previous schema configuration", () => {
|
|
801
|
+
const TestMap = co
|
|
802
|
+
.map({ name: co.plainText() })
|
|
803
|
+
.withPermissions({ onInlineCreate: "sameAsContainer" });
|
|
804
|
+
const TestMapWithName = TestMap.resolved({ name: true });
|
|
805
|
+
expect(TestMapWithName.permissions).toEqual({
|
|
806
|
+
onInlineCreate: "sameAsContainer",
|
|
807
|
+
});
|
|
808
|
+
});
|
|
799
809
|
});
|