jazz-tools 0.17.14 → 0.18.0
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/.svelte-kit/__package__/jazz.class.svelte.js +1 -1
- package/.svelte-kit/__package__/media/image.svelte +3 -9
- package/.svelte-kit/__package__/media/image.svelte.d.ts +1 -6
- package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
- package/.svelte-kit/__package__/media/image.types.d.ts +7 -0
- package/.svelte-kit/__package__/media/image.types.d.ts.map +1 -0
- package/.svelte-kit/__package__/media/image.types.js +1 -0
- package/.svelte-kit/__package__/tests/media/image.svelte.test.js +31 -31
- package/.turbo/turbo-build.log +50 -50
- package/CHANGELOG.md +31 -0
- package/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/{chunk-LZOF6WP5.js → chunk-HJ3GTGY7.js} +1320 -1018
- package/dist/chunk-HJ3GTGY7.js.map +1 -0
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/dist/inspector/{custom-element-ZSNTCECD.js → custom-element-WCY6D3QJ.js} +3 -3
- package/dist/inspector/{custom-element-ZSNTCECD.js.map → custom-element-WCY6D3QJ.js.map} +1 -1
- package/dist/inspector/index.js +1 -1
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/register-custom-element.js +1 -1
- package/dist/media/{chunk-E5J3WLQW.js → chunk-KR2V6X2N.js} +14 -9
- package/dist/media/chunk-KR2V6X2N.js.map +1 -0
- package/dist/media/create-image.d.ts +6 -6
- package/dist/media/index.browser.d.ts +6 -6
- package/dist/media/index.browser.js +1 -1
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +1 -1
- package/dist/media/index.native.d.ts +6 -6
- package/dist/media/index.native.js +1 -1
- package/dist/media/utils.d.ts.map +1 -1
- package/dist/prosemirror/index.js +2 -2
- package/dist/prosemirror/index.js.map +1 -1
- package/dist/react/index.js +7 -5
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +4658 -23
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-native-core/index.js +1 -1
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +1 -1
- package/dist/svelte/media/image.svelte +3 -9
- package/dist/svelte/media/image.svelte.d.ts +1 -6
- package/dist/svelte/media/image.svelte.d.ts.map +1 -1
- package/dist/svelte/media/image.types.d.ts +7 -0
- package/dist/svelte/media/image.types.d.ts.map +1 -0
- package/dist/svelte/media/image.types.js +1 -0
- package/dist/svelte/tests/media/image.svelte.test.js +31 -31
- package/dist/testing.js +18 -14
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/CoFieldInit.d.ts +13 -0
- package/dist/tools/coValues/CoFieldInit.d.ts.map +1 -0
- package/dist/tools/coValues/CoValueBase.d.ts +18 -15
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
- package/dist/tools/coValues/account.d.ts +100 -46
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts +78 -62
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts +212 -99
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts +200 -192
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/coPlainText.d.ts +30 -22
- package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
- package/dist/tools/coValues/deepLoading.d.ts +13 -13
- package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
- package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
- package/dist/tools/coValues/group.d.ts +32 -32
- package/dist/tools/coValues/group.d.ts.map +1 -1
- package/dist/tools/coValues/inbox.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +18 -17
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/profile.d.ts +6 -5
- package/dist/tools/coValues/profile.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +3 -3
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +1 -1
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/anonymousJazzAgent.d.ts +2 -1
- package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
- package/dist/tools/implementation/schema.d.ts +5 -5
- package/dist/tools/implementation/schema.d.ts.map +1 -1
- package/dist/tools/implementation/symbols.d.ts +2 -0
- package/dist/tools/implementation/symbols.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +6 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +8 -3
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +12 -7
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +13 -7
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +11 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +4 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +4 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/{CoFieldInit.d.ts → CoFieldSchemaInit.d.ts} +7 -7
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts +2 -2
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +2 -1
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/lib/migration.d.ts +1 -1
- package/dist/tools/lib/migration.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/index.d.ts +1 -1
- package/dist/tools/subscribe/index.d.ts.map +1 -1
- package/dist/tools/subscribe/utils.d.ts +2 -2
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/utils.d.ts +2 -6
- package/dist/tools/tests/utils.d.ts.map +1 -1
- package/dist/worker/index.js +3 -3
- package/dist/worker/index.js.map +1 -1
- package/package.json +4 -4
- package/src/browser/auth/PasskeyAuth.ts +2 -2
- package/src/browser/createBrowserContext.ts +2 -2
- package/src/browser/tests/PasskeyAuth.test.ts +2 -2
- package/src/inspector/custom-element.tsx +2 -2
- package/src/inspector/viewer/new-app.tsx +1 -1
- package/src/media/create-image.test.ts +7 -7
- package/src/media/create-image.ts +5 -3
- package/src/media/index.ts +1 -1
- package/src/media/utils.test.ts +72 -66
- package/src/media/utils.ts +9 -6
- package/src/prosemirror/lib/plugin.ts +1 -1
- package/src/prosemirror/lib/sync.ts +1 -1
- package/src/prosemirror/tests/plugin.test.ts +4 -4
- package/src/react/media/image.tsx +2 -2
- package/src/react/tests/media/image.test.tsx +52 -32
- package/src/react-core/hooks.ts +11 -5
- package/src/react-core/tests/useAccount.test.ts +16 -22
- package/src/react-core/tests/useCoState.test.ts +19 -19
- package/src/react-core/tests/useInboxSender.test.ts +5 -2
- package/src/react-core/tests/usePassPhraseAuth.test.ts +6 -6
- package/src/react-native-core/media/image.tsx +1 -1
- package/src/svelte/jazz.class.svelte.ts +1 -1
- package/src/svelte/media/image.svelte +3 -9
- package/src/svelte/media/image.types.ts +7 -0
- package/src/svelte/tests/media/image.svelte.test.ts +34 -32
- package/src/tools/auth/DemoAuth.ts +2 -2
- package/src/tools/auth/PassphraseAuth.ts +2 -2
- package/src/tools/auth/clerk/index.ts +2 -2
- package/src/tools/auth/clerk/tests/JazzClerkAuth.test.ts +1 -1
- package/src/tools/coValues/CoFieldInit.ts +20 -0
- package/src/tools/coValues/CoValueBase.ts +40 -60
- package/src/tools/coValues/account.ts +306 -232
- package/src/tools/coValues/coFeed.ts +185 -153
- package/src/tools/coValues/coList.ts +507 -334
- package/src/tools/coValues/coMap.ts +420 -286
- package/src/tools/coValues/coPlainText.ts +94 -110
- package/src/tools/coValues/deepLoading.ts +13 -13
- package/src/tools/coValues/group.ts +100 -114
- package/src/tools/coValues/inbox.ts +16 -14
- package/src/tools/coValues/interfaces.ts +49 -31
- package/src/tools/coValues/profile.ts +8 -6
- package/src/tools/coValues/request.ts +9 -9
- package/src/tools/coValues/schemaUnion.ts +11 -5
- package/src/tools/exports.ts +1 -1
- package/src/tools/implementation/ContextManager.ts +4 -4
- package/src/tools/implementation/anonymousJazzAgent.ts +2 -1
- package/src/tools/implementation/createContext.ts +1 -1
- package/src/tools/implementation/devtoolsFormatters.ts +9 -9
- package/src/tools/implementation/invites.ts +2 -2
- package/src/tools/implementation/schema.ts +7 -7
- package/src/tools/implementation/symbols.ts +3 -0
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +11 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +18 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +17 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +20 -11
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +19 -2
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +6 -0
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +6 -0
- package/src/tools/implementation/zodSchema/typeConverters/{CoFieldInit.ts → CoFieldSchemaInit.ts} +11 -11
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +4 -4
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +4 -4
- package/src/tools/implementation/zodSchema/zodCo.ts +2 -2
- package/src/tools/internal.ts +2 -1
- package/src/tools/lib/migration.ts +5 -5
- package/src/tools/subscribe/SubscriptionScope.ts +32 -24
- package/src/tools/subscribe/index.ts +4 -4
- package/src/tools/subscribe/utils.ts +11 -11
- package/src/tools/testing.ts +17 -13
- package/src/tools/tests/ContextManager.test.ts +68 -57
- package/src/tools/tests/PassphraseAuth.test.ts +2 -2
- package/src/tools/tests/account.test.ts +139 -69
- package/src/tools/tests/coDiscriminatedUnion.test-d.ts +12 -6
- package/src/tools/tests/coDiscriminatedUnion.test.ts +26 -17
- package/src/tools/tests/coFeed.test-d.ts +18 -17
- package/src/tools/tests/coFeed.test.ts +108 -97
- package/src/tools/tests/coList.test-d.ts +18 -23
- package/src/tools/tests/coList.test.ts +350 -165
- package/src/tools/tests/coMap.record.test-d.ts +9 -13
- package/src/tools/tests/coMap.record.test.ts +37 -23
- package/src/tools/tests/coMap.test-d.ts +43 -21
- package/src/tools/tests/coMap.test.ts +360 -182
- package/src/tools/tests/coOptional.test.ts +28 -13
- package/src/tools/tests/coPlainText.test.ts +15 -15
- package/src/tools/tests/createContext.test.ts +14 -14
- package/src/tools/tests/deepLoading.test.ts +95 -94
- package/src/tools/tests/exportImport.test.ts +61 -41
- package/src/tools/tests/groupsAndAccounts.test.ts +333 -116
- package/src/tools/tests/inbox.test.ts +22 -17
- package/src/tools/tests/interfaces.test.ts +12 -11
- package/src/tools/tests/invites.test.ts +6 -4
- package/src/tools/tests/load.test.ts +20 -18
- package/src/tools/tests/patterns/notifications.test.ts +6 -6
- package/src/tools/tests/patterns/quest.test.ts +3 -3
- package/src/tools/tests/patterns/requestToJoin.test.ts +22 -22
- package/src/tools/tests/request.test.ts +38 -39
- package/src/tools/tests/schemaUnion.test.ts +64 -10
- package/src/tools/tests/subscribe.test.ts +64 -64
- package/src/tools/tests/testing.test.ts +5 -9
- package/src/tools/tests/utils.ts +3 -3
- package/src/tools/tests/zod.test.ts +3 -3
- package/src/worker/index.ts +3 -3
- package/dist/chunk-LZOF6WP5.js.map +0 -1
- package/dist/media/chunk-E5J3WLQW.js.map +0 -1
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts.map +0 -1
@@ -125,15 +125,15 @@ describe("ContextManager", () => {
|
|
125
125
|
await manager.createContext({});
|
126
126
|
|
127
127
|
const credentials = {
|
128
|
-
accountID: account.id,
|
129
|
-
accountSecret: account.
|
128
|
+
accountID: account.$jazz.id,
|
129
|
+
accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
130
130
|
provider: "test",
|
131
131
|
};
|
132
132
|
|
133
133
|
// Authenticate with those credentials
|
134
134
|
await manager.authenticate(credentials);
|
135
135
|
|
136
|
-
expect(getCurrentValue().me.id).toBe(credentials.accountID);
|
136
|
+
expect(getCurrentValue().me.$jazz.id).toBe(credentials.accountID);
|
137
137
|
});
|
138
138
|
|
139
139
|
test("handles race conditions on the context creation", async () => {
|
@@ -142,15 +142,15 @@ describe("ContextManager", () => {
|
|
142
142
|
manager.createContext({});
|
143
143
|
|
144
144
|
const credentials = {
|
145
|
-
accountID: account.id,
|
146
|
-
accountSecret: account.
|
145
|
+
accountID: account.$jazz.id,
|
146
|
+
accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
147
147
|
provider: "test",
|
148
148
|
};
|
149
149
|
|
150
150
|
// Authenticate without waiting for the previous context to be created
|
151
151
|
await manager.authenticate(credentials);
|
152
152
|
|
153
|
-
expect(getCurrentValue().me.id).toBe(credentials.accountID);
|
153
|
+
expect(getCurrentValue().me.$jazz.id).toBe(credentials.accountID);
|
154
154
|
});
|
155
155
|
|
156
156
|
test("calls onLogOut callback when logging out", async () => {
|
@@ -205,8 +205,8 @@ describe("ContextManager", () => {
|
|
205
205
|
|
206
206
|
// Authenticate with credentials
|
207
207
|
await manager.authenticate({
|
208
|
-
accountID: account.id,
|
209
|
-
accountSecret: account.
|
208
|
+
accountID: account.$jazz.id,
|
209
|
+
accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
210
210
|
provider: "test",
|
211
211
|
});
|
212
212
|
|
@@ -219,8 +219,8 @@ describe("ContextManager", () => {
|
|
219
219
|
const account = await createJazzTestAccount();
|
220
220
|
|
221
221
|
await manager.getAuthSecretStorage().set({
|
222
|
-
accountID: account.id,
|
223
|
-
accountSecret: account.
|
222
|
+
accountID: account.$jazz.id,
|
223
|
+
accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
224
224
|
provider: "test",
|
225
225
|
});
|
226
226
|
|
@@ -229,8 +229,8 @@ describe("ContextManager", () => {
|
|
229
229
|
|
230
230
|
// Authenticate with same credentials
|
231
231
|
await manager.authenticate({
|
232
|
-
accountID: account.id,
|
233
|
-
accountSecret: account.
|
232
|
+
accountID: account.$jazz.id,
|
233
|
+
accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
234
234
|
provider: "test",
|
235
235
|
});
|
236
236
|
|
@@ -256,11 +256,14 @@ describe("ContextManager", () => {
|
|
256
256
|
profile: co.profile(),
|
257
257
|
})
|
258
258
|
.withMigration(async (account) => {
|
259
|
-
account.
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
259
|
+
account.$jazz.set(
|
260
|
+
"root",
|
261
|
+
AccountRoot.create(
|
262
|
+
{
|
263
|
+
value: "Hello",
|
264
|
+
},
|
265
|
+
Group.create(this).makePublic(),
|
266
|
+
),
|
264
267
|
);
|
265
268
|
});
|
266
269
|
|
@@ -272,15 +275,16 @@ describe("ContextManager", () => {
|
|
272
275
|
AccountSchema: coValueClassFromCoValueClassOrSchema(CustomAccount),
|
273
276
|
storage: dbFilename,
|
274
277
|
onAnonymousAccountDiscarded: async (anonymousAccount) => {
|
275
|
-
const anonymousAccountWithRoot =
|
276
|
-
|
277
|
-
|
278
|
+
const anonymousAccountWithRoot =
|
279
|
+
await anonymousAccount.$jazz.ensureLoaded({
|
280
|
+
resolve: { root: true },
|
281
|
+
});
|
278
282
|
|
279
|
-
const me = await CustomAccount.getMe().ensureLoaded({
|
283
|
+
const me = await CustomAccount.getMe().$jazz.ensureLoaded({
|
280
284
|
resolve: { root: true },
|
281
285
|
});
|
282
286
|
|
283
|
-
me.root.transferredRoot
|
287
|
+
me.root.$jazz.set("transferredRoot", anonymousAccountWithRoot.root);
|
284
288
|
},
|
285
289
|
});
|
286
290
|
|
@@ -295,15 +299,15 @@ describe("ContextManager", () => {
|
|
295
299
|
).me;
|
296
300
|
|
297
301
|
await customManager.authenticate({
|
298
|
-
accountID: account.id,
|
299
|
-
accountSecret: account.
|
302
|
+
accountID: account.$jazz.id,
|
303
|
+
accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
300
304
|
provider: "test",
|
301
305
|
});
|
302
306
|
|
303
307
|
// The storage should be closed and set to undefined
|
304
308
|
expect(prevContextNode.storage).toBeUndefined();
|
305
309
|
|
306
|
-
const me = await CustomAccount.getMe().ensureLoaded({
|
310
|
+
const me = await CustomAccount.getMe().$jazz.ensureLoaded({
|
307
311
|
resolve: { root: { transferredRoot: true } },
|
308
312
|
});
|
309
313
|
|
@@ -322,11 +326,11 @@ describe("ContextManager", () => {
|
|
322
326
|
root: AccountRoot,
|
323
327
|
profile: co.profile(),
|
324
328
|
})
|
325
|
-
.withMigration(async (account) => {
|
326
|
-
account.root
|
329
|
+
.withMigration(async (account: Account) => {
|
330
|
+
account.$jazz.set("root", {
|
327
331
|
value: "Hello",
|
328
332
|
});
|
329
|
-
lastRootId = account.root.id;
|
333
|
+
lastRootId = account.root!.$jazz.id;
|
330
334
|
});
|
331
335
|
|
332
336
|
const customManager = new TestJazzContextManager<
|
@@ -345,16 +349,16 @@ describe("ContextManager", () => {
|
|
345
349
|
).me;
|
346
350
|
|
347
351
|
await customManager.authenticate({
|
348
|
-
accountID: account.id,
|
349
|
-
accountSecret: account.
|
352
|
+
accountID: account.$jazz.id,
|
353
|
+
accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
350
354
|
provider: "test",
|
351
355
|
});
|
352
356
|
|
353
|
-
const me = await CustomAccount.getMe().ensureLoaded({
|
357
|
+
const me = await CustomAccount.getMe().$jazz.ensureLoaded({
|
354
358
|
resolve: { root: true },
|
355
359
|
});
|
356
360
|
|
357
|
-
expect(me.root.id).toBe(lastRootId);
|
361
|
+
expect(me.root.$jazz.id).toBe(lastRootId);
|
358
362
|
});
|
359
363
|
|
360
364
|
test("the migration should be applied correctly on existing accounts (2)", async () => {
|
@@ -369,15 +373,18 @@ describe("ContextManager", () => {
|
|
369
373
|
})
|
370
374
|
.withMigration(async (account) => {
|
371
375
|
if (account.root === undefined) {
|
372
|
-
account.
|
373
|
-
|
374
|
-
|
376
|
+
account.$jazz.set(
|
377
|
+
"root",
|
378
|
+
AccountRoot.create({
|
379
|
+
value: 1,
|
380
|
+
}),
|
381
|
+
);
|
375
382
|
} else {
|
376
|
-
const { root } = await account.ensureLoaded({
|
383
|
+
const { root } = await account.$jazz.ensureLoaded({
|
377
384
|
resolve: { root: true },
|
378
385
|
});
|
379
386
|
|
380
|
-
root.value
|
387
|
+
root.$jazz.set("value", 2);
|
381
388
|
}
|
382
389
|
});
|
383
390
|
const customManager = new TestJazzContextManager<
|
@@ -396,12 +403,12 @@ describe("ContextManager", () => {
|
|
396
403
|
).me;
|
397
404
|
|
398
405
|
await customManager.authenticate({
|
399
|
-
accountID: account.id,
|
400
|
-
accountSecret: account.
|
406
|
+
accountID: account.$jazz.id,
|
407
|
+
accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
401
408
|
provider: "test",
|
402
409
|
});
|
403
410
|
|
404
|
-
const me = await CustomAccount.getMe().ensureLoaded({
|
411
|
+
const me = await CustomAccount.getMe().$jazz.ensureLoaded({
|
405
412
|
resolve: { root: true },
|
406
413
|
});
|
407
414
|
|
@@ -423,22 +430,26 @@ describe("ContextManager", () => {
|
|
423
430
|
})
|
424
431
|
.withMigration(async (account) => {
|
425
432
|
if (account.root === undefined) {
|
426
|
-
account.
|
427
|
-
|
428
|
-
|
433
|
+
account.$jazz.set(
|
434
|
+
"root",
|
435
|
+
AccountRoot.create({
|
436
|
+
value: "Hello",
|
437
|
+
}),
|
438
|
+
);
|
429
439
|
}
|
430
440
|
});
|
431
441
|
|
432
442
|
const onAnonymousAccountDiscarded = async (
|
433
443
|
anonymousAccount: Loaded<typeof CustomAccount, { root: true }>,
|
434
444
|
) => {
|
435
|
-
const anonymousAccountWithRoot =
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
445
|
+
const anonymousAccountWithRoot =
|
446
|
+
await anonymousAccount.$jazz.ensureLoaded({
|
447
|
+
resolve: {
|
448
|
+
root: true,
|
449
|
+
},
|
450
|
+
});
|
440
451
|
|
441
|
-
const meWithRoot = await CustomAccount.getMe().ensureLoaded({
|
452
|
+
const meWithRoot = await CustomAccount.getMe().$jazz.ensureLoaded({
|
442
453
|
resolve: {
|
443
454
|
root: true,
|
444
455
|
},
|
@@ -446,9 +457,9 @@ describe("ContextManager", () => {
|
|
446
457
|
|
447
458
|
const rootToTransfer = anonymousAccountWithRoot.root;
|
448
459
|
|
449
|
-
await rootToTransfer.
|
460
|
+
await rootToTransfer.$jazz.owner.addMember(meWithRoot, "admin");
|
450
461
|
|
451
|
-
meWithRoot.root.transferredRoot
|
462
|
+
meWithRoot.root.$jazz.set("transferredRoot", rootToTransfer);
|
452
463
|
};
|
453
464
|
|
454
465
|
const customManager = new TestJazzContextManager<
|
@@ -467,12 +478,12 @@ describe("ContextManager", () => {
|
|
467
478
|
});
|
468
479
|
|
469
480
|
await customManager.authenticate({
|
470
|
-
accountID: account.id,
|
471
|
-
accountSecret: account.
|
481
|
+
accountID: account.$jazz.id,
|
482
|
+
accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
472
483
|
provider: "test",
|
473
484
|
});
|
474
485
|
|
475
|
-
const me = await CustomAccount.getMe().ensureLoaded({
|
486
|
+
const me = await CustomAccount.getMe().$jazz.ensureLoaded({
|
476
487
|
resolve: {
|
477
488
|
root: true,
|
478
489
|
},
|
@@ -491,7 +502,7 @@ describe("ContextManager", () => {
|
|
491
502
|
expect(accountId).toBeDefined();
|
492
503
|
const context = getCurrentValue();
|
493
504
|
expect(context.me.profile?.name).toBe("Test User");
|
494
|
-
expect(context.me.id).toBe(accountId);
|
505
|
+
expect(context.me.$jazz.id).toBe(accountId);
|
495
506
|
});
|
496
507
|
|
497
508
|
test("calls onAnonymousAccountDiscarded when registering from anonymous user", async () => {
|
@@ -510,8 +521,8 @@ describe("ContextManager", () => {
|
|
510
521
|
const account = await createJazzTestAccount();
|
511
522
|
|
512
523
|
await manager.getAuthSecretStorage().set({
|
513
|
-
accountID: account.id,
|
514
|
-
accountSecret: account.
|
524
|
+
accountID: account.$jazz.id,
|
525
|
+
accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
|
515
526
|
provider: "test",
|
516
527
|
});
|
517
528
|
|
@@ -151,7 +151,7 @@ describe("PassphraseAuth", () => {
|
|
151
151
|
await passphraseAuth.signUp(testName);
|
152
152
|
|
153
153
|
// Verify the account name was set
|
154
|
-
const { profile } = await account.ensureLoaded({
|
154
|
+
const { profile } = await account.$jazz.ensureLoaded({
|
155
155
|
resolve: {
|
156
156
|
profile: true,
|
157
157
|
},
|
@@ -315,7 +315,7 @@ describe("PassphraseAuth with TestJazzContextManager", () => {
|
|
315
315
|
const context = contextManager.getCurrentValue();
|
316
316
|
|
317
317
|
assert(context && "me" in context);
|
318
|
-
expect(context.me.id).toBe(accountId);
|
318
|
+
expect(context.me.$jazz.id).toBe(accountId);
|
319
319
|
expect(context.me.profile?.name).toBe("Test User");
|
320
320
|
|
321
321
|
expect(authSecretStorage.isAuthenticated).toBe(true);
|
@@ -23,7 +23,7 @@ test("waitForAllCoValuesSync should resolve when all the values are synced", asy
|
|
23
23
|
TestMap.create({ name: "Alice" }, { owner: clientAccount }),
|
24
24
|
);
|
25
25
|
|
26
|
-
await clientAccount.waitForAllCoValuesSync({
|
26
|
+
await clientAccount.$jazz.waitForAllCoValuesSync({
|
27
27
|
timeout: 1000,
|
28
28
|
});
|
29
29
|
|
@@ -31,7 +31,7 @@ test("waitForAllCoValuesSync should resolve when all the values are synced", asy
|
|
31
31
|
clientNode.gracefulShutdown();
|
32
32
|
|
33
33
|
for (const map of maps) {
|
34
|
-
const loadedMap = await serverNode.load(map.
|
34
|
+
const loadedMap = await serverNode.load(map.$jazz.raw.id);
|
35
35
|
expect(loadedMap).not.toBe("unavailable");
|
36
36
|
}
|
37
37
|
});
|
@@ -39,12 +39,12 @@ test("waitForAllCoValuesSync should resolve when all the values are synced", asy
|
|
39
39
|
test("waitForSync should resolve when the value is uploaded", async () => {
|
40
40
|
const { clientNode, serverNode, clientAccount } = await setupTwoNodes();
|
41
41
|
|
42
|
-
await clientAccount.waitForSync({ timeout: 1000 });
|
42
|
+
await clientAccount.$jazz.waitForSync({ timeout: 1000 });
|
43
43
|
|
44
44
|
// Killing the client node so the serverNode can't load the map from it
|
45
45
|
clientNode.gracefulShutdown();
|
46
46
|
|
47
|
-
const loadedAccount = await serverNode.load(clientAccount.
|
47
|
+
const loadedAccount = await serverNode.load(clientAccount.$jazz.raw.id);
|
48
48
|
|
49
49
|
expect(loadedAccount).not.toBe("unavailable");
|
50
50
|
});
|
@@ -86,11 +86,11 @@ test("Me gets updated correctly when creating a new account as active", async ()
|
|
86
86
|
|
87
87
|
test("accounts should sync correctly", async () => {
|
88
88
|
const account = await createJazzTestAccount({ isCurrentActiveAccount: true });
|
89
|
-
account.profile
|
89
|
+
account.profile!.$jazz.set("name", "test 1");
|
90
90
|
const otherAccount = await createJazzTestAccount({
|
91
91
|
isCurrentActiveAccount: true,
|
92
92
|
});
|
93
|
-
otherAccount.profile
|
93
|
+
otherAccount.profile!.$jazz.set("name", "test 2");
|
94
94
|
|
95
95
|
await linkAccounts(account, otherAccount);
|
96
96
|
|
@@ -111,7 +111,7 @@ test("loading accounts should work", async () => {
|
|
111
111
|
|
112
112
|
const otherAccount = await createJazzTestAccount();
|
113
113
|
|
114
|
-
const loadedAccount = await Account.load(account.id, {
|
114
|
+
const loadedAccount = await Account.load(account.$jazz.id, {
|
115
115
|
loadAs: otherAccount,
|
116
116
|
resolve: {
|
117
117
|
profile: true,
|
@@ -129,7 +129,7 @@ test("loading raw accounts should work", async () => {
|
|
129
129
|
},
|
130
130
|
});
|
131
131
|
|
132
|
-
const loadedAccount = await Account.load(account.id, {
|
132
|
+
const loadedAccount = await Account.load(account.$jazz.id, {
|
133
133
|
loadAs: account,
|
134
134
|
});
|
135
135
|
|
@@ -180,21 +180,24 @@ test("should support recursive props on co.profile", async () => {
|
|
180
180
|
if (me.profile === undefined) {
|
181
181
|
const group = Group.create({ owner: me });
|
182
182
|
group.addMember("everyone", "reader");
|
183
|
-
me.
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
183
|
+
me.$jazz.set(
|
184
|
+
"profile",
|
185
|
+
User.create(
|
186
|
+
{
|
187
|
+
name: "test 1",
|
188
|
+
created: new Date(),
|
189
|
+
updated: new Date(),
|
190
|
+
anonymous: false,
|
191
|
+
following: co.list(User).create([], group),
|
192
|
+
followers: co.list(User).create([], group),
|
193
|
+
},
|
194
|
+
group,
|
195
|
+
),
|
193
196
|
);
|
194
197
|
}
|
195
198
|
|
196
199
|
if (me.root === undefined) {
|
197
|
-
me.root
|
200
|
+
me.$jazz.set("root", {});
|
198
201
|
}
|
199
202
|
});
|
200
203
|
|
@@ -211,64 +214,131 @@ test("should support recursive props on co.profile", async () => {
|
|
211
214
|
expect(account.profile.followers.length).toBe(0);
|
212
215
|
});
|
213
216
|
|
214
|
-
test("
|
215
|
-
const
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
}),
|
221
|
-
})
|
222
|
-
.withMigration((me, creationProps) => {
|
223
|
-
const group = Group.create({ owner: me }).makePublic();
|
217
|
+
test("cannot update account profile properties directly", async () => {
|
218
|
+
const account = await createJazzTestAccount({
|
219
|
+
creationProps: {
|
220
|
+
name: "test 1",
|
221
|
+
},
|
222
|
+
});
|
224
223
|
|
225
|
-
|
226
|
-
me.profile = co.profile().create(
|
227
|
-
{
|
228
|
-
name: creationProps?.name ?? "Anonymous",
|
229
|
-
},
|
230
|
-
group,
|
231
|
-
);
|
232
|
-
}
|
224
|
+
assert(account.profile);
|
233
225
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
226
|
+
// @ts-expect-error - cannot update profile properties directly
|
227
|
+
expect(() => (account.profile.name = "test 2")).toThrow(
|
228
|
+
"Cannot update a CoMap directly. Use `$jazz.set` instead.",
|
229
|
+
);
|
230
|
+
account.profile.$jazz.set("name", "test 3");
|
231
|
+
expect(account.profile.name).toBe("test 3");
|
232
|
+
});
|
233
|
+
|
234
|
+
describe("root and profile", () => {
|
235
|
+
test("root and profile should be trusting by default", async () => {
|
236
|
+
const AccountSchema = co
|
237
|
+
.account({
|
238
|
+
profile: co.profile(),
|
239
|
+
root: co.map({
|
240
|
+
name: z.string(),
|
241
|
+
}),
|
242
|
+
})
|
243
|
+
.withMigration((me, creationProps) => {
|
244
|
+
const group = Group.create({ owner: me }).makePublic();
|
245
|
+
|
246
|
+
if (me.profile === undefined) {
|
247
|
+
me.$jazz.set(
|
248
|
+
"profile",
|
249
|
+
co.profile().create(
|
250
|
+
{
|
251
|
+
name: creationProps?.name ?? "Anonymous",
|
252
|
+
},
|
253
|
+
group,
|
254
|
+
),
|
244
255
|
);
|
245
|
-
|
256
|
+
}
|
257
|
+
|
258
|
+
if (me.root === undefined) {
|
259
|
+
me.$jazz.set(
|
260
|
+
"root",
|
261
|
+
co
|
262
|
+
.map({
|
263
|
+
name: z.string(),
|
264
|
+
})
|
265
|
+
.create(
|
266
|
+
{
|
267
|
+
name: creationProps?.name ?? "Anonymous",
|
268
|
+
},
|
269
|
+
group,
|
270
|
+
),
|
271
|
+
);
|
272
|
+
}
|
273
|
+
});
|
274
|
+
|
275
|
+
const bob = await createJazzTestAccount({
|
276
|
+
AccountSchema,
|
277
|
+
creationProps: {
|
278
|
+
name: "Bob",
|
279
|
+
},
|
246
280
|
});
|
247
281
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
282
|
+
const alice = await createJazzTestAccount({
|
283
|
+
AccountSchema,
|
284
|
+
creationProps: {
|
285
|
+
name: "Alice",
|
286
|
+
},
|
287
|
+
});
|
254
288
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
289
|
+
const bobAccountLoadedFromAlice = await AccountSchema.load(bob.$jazz.id, {
|
290
|
+
loadAs: alice,
|
291
|
+
resolve: {
|
292
|
+
profile: true,
|
293
|
+
root: true,
|
294
|
+
},
|
295
|
+
});
|
261
296
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
root: true,
|
267
|
-
},
|
297
|
+
assert(bobAccountLoadedFromAlice);
|
298
|
+
|
299
|
+
expect(bobAccountLoadedFromAlice.profile.name).toBe("Bob");
|
300
|
+
expect(bobAccountLoadedFromAlice.root.name).toBe("Bob");
|
268
301
|
});
|
269
302
|
|
270
|
-
|
303
|
+
test("can be initialized using JSON objects", async () => {
|
304
|
+
const Avatar = co.map({
|
305
|
+
url: z.string(),
|
306
|
+
});
|
307
|
+
const CustomProfile = co.profile({
|
308
|
+
avatar: Avatar,
|
309
|
+
});
|
310
|
+
const CustomRoot = co.map({
|
311
|
+
name: z.string(),
|
312
|
+
});
|
313
|
+
const AccountSchema = co
|
314
|
+
.account({
|
315
|
+
profile: CustomProfile,
|
316
|
+
root: CustomRoot,
|
317
|
+
})
|
318
|
+
.withMigration((me, creationProps) => {
|
319
|
+
if (me.profile === undefined) {
|
320
|
+
me.$jazz.set("profile", {
|
321
|
+
name: creationProps?.name ?? "Anonymous",
|
322
|
+
avatar: {
|
323
|
+
url: "https://example.com/avatar.png",
|
324
|
+
},
|
325
|
+
});
|
326
|
+
}
|
327
|
+
|
328
|
+
if (me.root === undefined) {
|
329
|
+
me.$jazz.set("root", { name: creationProps?.name ?? "Anonymous" });
|
330
|
+
}
|
331
|
+
});
|
332
|
+
|
333
|
+
const account = await createJazzTestAccount({
|
334
|
+
AccountSchema,
|
335
|
+
creationProps: {
|
336
|
+
name: "test 1",
|
337
|
+
},
|
338
|
+
});
|
271
339
|
|
272
|
-
|
273
|
-
|
340
|
+
expect(account.profile.name).toBe("test 1");
|
341
|
+
expect(account.profile.avatar.url).toBe("https://example.com/avatar.png");
|
342
|
+
expect(account.root.name).toBe("test 1");
|
343
|
+
});
|
274
344
|
});
|
@@ -29,9 +29,12 @@ describe("co.discriminatedUnion", () => {
|
|
29
29
|
}),
|
30
30
|
});
|
31
31
|
|
32
|
-
person.
|
33
|
-
|
34
|
-
|
32
|
+
person.$jazz.set(
|
33
|
+
"pet",
|
34
|
+
Cat.create({
|
35
|
+
type: "cat",
|
36
|
+
}),
|
37
|
+
);
|
35
38
|
|
36
39
|
type ExpectedType = {
|
37
40
|
pet: Loaded<typeof Dog> | Loaded<typeof Cat>;
|
@@ -67,9 +70,12 @@ describe("co.discriminatedUnion", () => {
|
|
67
70
|
}),
|
68
71
|
});
|
69
72
|
|
70
|
-
pallino.
|
71
|
-
|
72
|
-
|
73
|
+
pallino.$jazz.set(
|
74
|
+
"friend",
|
75
|
+
Cat.create({
|
76
|
+
type: "cat",
|
77
|
+
}),
|
78
|
+
);
|
73
79
|
|
74
80
|
type ExpectedType = {
|
75
81
|
friend: Loaded<typeof Dog> | Loaded<typeof Cat> | undefined;
|