jazz-tools 0.19.22 → 0.20.1
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__/react.d.ts.map +1 -1
- package/.svelte-kit/__package__/react.tsx +5 -2
- package/.turbo/turbo-build.log +71 -83
- package/CHANGELOG.md +80 -0
- package/dist/better-auth/auth/react.d.ts.map +1 -1
- package/dist/better-auth/auth/react.js +5 -2
- package/dist/better-auth/auth/react.js.map +1 -1
- package/dist/browser/createBrowserContext.d.ts +1 -2
- package/dist/browser/createBrowserContext.d.ts.map +1 -1
- package/dist/browser/index.js +1 -8
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/provideBrowserLockSession/SessionIDStorage.d.ts +1 -1
- package/dist/{chunk-QCTQH5RS.js → chunk-2OPP7KWV.js} +382 -174
- package/dist/chunk-2OPP7KWV.js.map +1 -0
- package/dist/{chunk-M2HGBOXS.js → chunk-K4D7IMFM.js} +3 -3
- package/dist/chunk-K4D7IMFM.js.map +1 -0
- package/dist/chunk-ZQWSQH6L.js +20 -0
- package/dist/expo/auth/clerk/index.d.ts.map +1 -1
- package/dist/expo/index.js +5 -2
- package/dist/expo/index.js.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/inspector/{chunk-YQNK5Y7B.js → chunk-MCTB5ZJC.js} +1 -1
- package/dist/inspector/chunk-MCTB5ZJC.js.map +1 -0
- package/dist/inspector/contexts/node.d.ts.map +1 -1
- package/dist/inspector/{custom-element-KYV64IOC.js → custom-element-5YWVZBWA.js} +1 -1
- package/dist/inspector/{custom-element-KYV64IOC.js.map → custom-element-5YWVZBWA.js.map} +1 -1
- package/dist/inspector/index.js +3 -3
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/register-custom-element.js +1 -1
- package/dist/inspector/standalone.js +1 -1
- package/dist/react/auth/Clerk.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.js +61 -47
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/ssr.js +2 -2
- package/dist/react/ssr.js.map +1 -1
- package/dist/react-core/chunk-UOYH6JFJ.js +10 -0
- package/dist/react-core/chunk-UOYH6JFJ.js.map +1 -0
- package/dist/react-core/hooks.d.ts +3 -3
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +27 -25
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/provider.d.ts +2 -3
- package/dist/react-core/provider.d.ts.map +1 -1
- package/dist/react-core/testing.d.ts.map +1 -1
- package/dist/react-core/testing.js +4 -10
- package/dist/react-core/testing.js.map +1 -1
- package/dist/react-native/index.js +61 -53
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native-core/ReactNativeContextManager.d.ts +0 -1
- package/dist/react-native-core/ReactNativeContextManager.d.ts.map +1 -1
- 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 +58 -50
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/react-native-core/platform.d.ts +0 -4
- package/dist/react-native-core/platform.d.ts.map +1 -1
- package/dist/react-native-core/provider.d.ts +2 -1
- package/dist/react-native-core/provider.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +2 -8
- package/dist/svelte/tests/AccountCoState.svelte.test.d.ts +2 -0
- package/dist/svelte/tests/AccountCoState.svelte.test.d.ts.map +1 -0
- package/dist/svelte/tests/AccountCoState.svelte.test.js +59 -0
- package/dist/svelte/tests/CoState.svelte.test.js +23 -0
- package/dist/svelte/tests/TestAccountCoStateWrapper.svelte +24 -0
- package/dist/svelte/tests/TestAccountCoStateWrapper.svelte.d.ts +11 -0
- package/dist/svelte/tests/TestAccountCoStateWrapper.svelte.d.ts.map +1 -0
- package/dist/testing.js +7 -7
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/coList.d.ts +2 -2
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts +2 -2
- package/dist/tools/coValues/deepLoading.d.ts +2 -2
- package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +32 -0
- package/dist/tools/coValues/interfaces.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/ContextManager.d.ts.map +1 -1
- package/dist/tools/implementation/createContext.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +3 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +3 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +5 -4
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +5 -3
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +7 -3
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +3 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +3 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +6 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/ssr.js +2 -2
- package/dist/tools/subscribe/JazzError.d.ts +3 -3
- package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/types.d.ts +5 -1
- package/dist/tools/subscribe/types.d.ts.map +1 -1
- package/dist/tools/testing.d.ts +3 -3
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/deleteCoValues.test.d.ts +2 -0
- package/dist/tools/tests/deleteCoValues.test.d.ts.map +1 -0
- package/dist/tools/tests/deletedState.test.d.ts +2 -0
- package/dist/tools/tests/deletedState.test.d.ts.map +1 -0
- package/dist/worker/edge-wasm.js +2 -1
- package/dist/worker/edge-wasm.js.map +1 -1
- package/dist/worker/wasm.d.ts +2 -0
- package/dist/worker/wasm.d.ts.map +1 -0
- package/package.json +9 -28
- package/src/better-auth/auth/react.tsx +5 -2
- package/src/browser/createBrowserContext.ts +2 -5
- package/src/expo/auth/clerk/index.tsx +5 -2
- package/src/inspector/contexts/node.tsx +1 -2
- package/src/inspector/index.tsx +2 -2
- package/src/react/auth/Clerk.tsx +5 -2
- package/src/react/auth/PasskeyAuth.tsx +2 -2
- package/src/react/hooks.tsx +3 -2
- package/src/react/provider.tsx +45 -41
- package/src/react-core/auth/DemoAuth.tsx +2 -2
- package/src/react-core/auth/PassphraseAuth.tsx +2 -2
- package/src/react-core/hooks.ts +26 -27
- package/src/react-core/provider.tsx +1 -5
- package/src/react-core/testing.tsx +3 -11
- package/src/react-core/tests/useAccount.selector.test.ts +2 -3
- package/src/react-core/tests/useAccount.test.ts +57 -7
- package/src/react-core/tests/useCoState.test.ts +37 -0
- package/src/react-core/tests/useInboxSender.test.ts +2 -5
- package/src/react-core/tests/useSuspenseAccount.test.tsx +68 -0
- package/src/react-core/tests/useSuspenseCoState.test.tsx +44 -0
- package/src/react-native-core/ReactNativeContextManager.ts +0 -3
- package/src/react-native-core/auth/usePasskeyAuth.tsx +2 -2
- package/src/react-native-core/hooks.tsx +3 -3
- package/src/react-native-core/platform.ts +2 -6
- package/src/react-native-core/provider.tsx +47 -43
- package/src/svelte/jazz.class.svelte.ts +2 -8
- package/src/svelte/tests/AccountCoState.svelte.test.ts +79 -0
- package/src/svelte/tests/CoState.svelte.test.ts +36 -0
- package/src/svelte/tests/TestAccountCoStateWrapper.svelte +24 -0
- package/src/tools/coValues/coList.ts +73 -37
- package/src/tools/coValues/deepLoading.ts +2 -0
- package/src/tools/coValues/interfaces.ts +170 -32
- package/src/tools/exports.ts +1 -0
- package/src/tools/implementation/ContextManager.ts +2 -2
- package/src/tools/implementation/createContext.ts +4 -0
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +30 -8
- package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +55 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +38 -16
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +40 -8
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +40 -16
- package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +6 -2
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +6 -2
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +5 -2
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +9 -2
- package/src/tools/ssr/ssr.ts +2 -2
- package/src/tools/subscribe/CoValueCoreSubscription.ts +1 -0
- package/src/tools/subscribe/JazzError.ts +4 -1
- package/src/tools/subscribe/SubscriptionScope.ts +23 -0
- package/src/tools/subscribe/types.ts +5 -0
- package/src/tools/testing.ts +5 -5
- package/src/tools/tests/PassphraseAuth.test.ts +5 -5
- package/src/tools/tests/coList.test.ts +262 -0
- package/src/tools/tests/deleteCoValues.test.ts +231 -0
- package/src/tools/tests/deletedState.test.ts +110 -0
- package/src/tools/tests/request.test.ts +15 -2
- package/src/tools/tests/schema.withPermissions.test.ts +27 -4
- package/src/worker/edge-wasm.ts +2 -1
- package/src/worker/wasm.ts +1 -0
- package/tsup.config.ts +0 -4
- package/dist/browser/storageOptions.d.ts +0 -8
- package/dist/browser/storageOptions.d.ts.map +0 -1
- package/dist/browser/tests/storageOptions.test.d.ts +0 -2
- package/dist/browser/tests/storageOptions.test.d.ts.map +0 -1
- package/dist/chunk-M2HGBOXS.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-QCTQH5RS.js.map +0 -1
- package/dist/expo/crypto.d.ts +0 -2
- package/dist/expo/crypto.d.ts.map +0 -1
- package/dist/expo/crypto.js +0 -6
- package/dist/expo/crypto.js.map +0 -1
- package/dist/inspector/chunk-YQNK5Y7B.js.map +0 -1
- package/dist/react-core/chunk-7DYMJ74I.js +0 -12
- package/dist/react-core/chunk-7DYMJ74I.js.map +0 -1
- package/dist/react-native/chunk-DGUM43GV.js +0 -11
- package/dist/react-native/chunk-DGUM43GV.js.map +0 -1
- package/dist/react-native/crypto.d.ts +0 -2
- package/dist/react-native/crypto.d.ts.map +0 -1
- package/dist/react-native/crypto.js +0 -8
- package/dist/react-native/crypto.js.map +0 -1
- package/dist/react-native-core/chunk-DGUM43GV.js +0 -11
- package/dist/react-native-core/chunk-DGUM43GV.js.map +0 -1
- package/dist/react-native-core/crypto/RNCrypto.d.ts +0 -2
- package/dist/react-native-core/crypto/RNCrypto.d.ts.map +0 -1
- package/dist/react-native-core/crypto/RNCrypto.js +0 -3
- package/dist/react-native-core/crypto/RNCrypto.js.map +0 -1
- package/dist/react-native-core/crypto/RNQuickCrypto.d.ts +0 -17
- package/dist/react-native-core/crypto/RNQuickCrypto.d.ts.map +0 -1
- package/dist/react-native-core/crypto/index.d.ts +0 -2
- package/dist/react-native-core/crypto/index.d.ts.map +0 -1
- package/dist/react-native-core/crypto.js +0 -89
- package/dist/react-native-core/crypto.js.map +0 -1
- package/src/browser/storageOptions.ts +0 -17
- package/src/browser/tests/storageOptions.test.ts +0 -33
- package/src/expo/crypto.ts +0 -1
- package/src/react-native/crypto.ts +0 -1
- package/src/react-native-core/crypto/RNCrypto.ts +0 -1
- package/src/react-native-core/crypto/RNQuickCrypto.ts +0 -122
- package/src/react-native-core/crypto/index.ts +0 -1
- /package/dist/{chunk-PZ5AY32C.js.map → chunk-ZQWSQH6L.js.map} +0 -0
|
@@ -1225,3 +1225,265 @@ describe("lastUpdatedAt", () => {
|
|
|
1225
1225
|
expect(list.$jazz.lastUpdatedAt).not.toEqual(updatedAt);
|
|
1226
1226
|
});
|
|
1227
1227
|
});
|
|
1228
|
+
|
|
1229
|
+
describe("CoList proxy traps", () => {
|
|
1230
|
+
test(".values() returns the same values as Object.values()", () => {
|
|
1231
|
+
const TestList = co.list(z.string());
|
|
1232
|
+
const list = TestList.create([]);
|
|
1233
|
+
list.$jazz.push("bread");
|
|
1234
|
+
list.$jazz.push("butter");
|
|
1235
|
+
list.$jazz.push("onion");
|
|
1236
|
+
|
|
1237
|
+
const valuesFromMethod = [...list.values()];
|
|
1238
|
+
const valuesFromObject = Object.values(list);
|
|
1239
|
+
expect(valuesFromMethod).toEqual(valuesFromObject);
|
|
1240
|
+
expect(valuesFromMethod).toEqual(["bread", "butter", "onion"]);
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
test(".values().map() returns the same values as .map()", () => {
|
|
1244
|
+
const TestList = co.list(z.string());
|
|
1245
|
+
const list = TestList.create([]);
|
|
1246
|
+
list.$jazz.push("bread");
|
|
1247
|
+
list.$jazz.push("butter");
|
|
1248
|
+
list.$jazz.push("onion");
|
|
1249
|
+
|
|
1250
|
+
const valuesFromMethod = [...list.values().map((v) => v.toUpperCase())];
|
|
1251
|
+
const valuesFromObject = list.map((v) => v.toUpperCase());
|
|
1252
|
+
|
|
1253
|
+
expect(valuesFromMethod).toEqual(valuesFromObject);
|
|
1254
|
+
expect(valuesFromMethod).toEqual(["BREAD", "BUTTER", "ONION"]);
|
|
1255
|
+
});
|
|
1256
|
+
|
|
1257
|
+
test(".keys() returns numeric indices", () => {
|
|
1258
|
+
const TestList = co.list(z.string());
|
|
1259
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
|
1260
|
+
|
|
1261
|
+
const keys = [...list.keys()];
|
|
1262
|
+
|
|
1263
|
+
expect(keys).toEqual([0, 1, 2]);
|
|
1264
|
+
});
|
|
1265
|
+
|
|
1266
|
+
test(".entries() returns index-value pairs", () => {
|
|
1267
|
+
const TestList = co.list(z.string());
|
|
1268
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
|
1269
|
+
|
|
1270
|
+
const entries = [...list.entries()];
|
|
1271
|
+
|
|
1272
|
+
expect(entries).toEqual([
|
|
1273
|
+
[0, "bread"],
|
|
1274
|
+
[1, "butter"],
|
|
1275
|
+
[2, "onion"],
|
|
1276
|
+
]);
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
test("for...of iteration works correctly", () => {
|
|
1280
|
+
const TestList = co.list(z.string());
|
|
1281
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
|
1282
|
+
|
|
1283
|
+
const items: string[] = [];
|
|
1284
|
+
for (const item of list) {
|
|
1285
|
+
items.push(item);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
expect(items).toEqual(["bread", "butter", "onion"]);
|
|
1289
|
+
});
|
|
1290
|
+
|
|
1291
|
+
test("spread operator works correctly", () => {
|
|
1292
|
+
const TestList = co.list(z.string());
|
|
1293
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
|
1294
|
+
|
|
1295
|
+
const items = [...list];
|
|
1296
|
+
|
|
1297
|
+
expect(items).toEqual(["bread", "butter", "onion"]);
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
test("Array.from works correctly", () => {
|
|
1301
|
+
const TestList = co.list(z.string());
|
|
1302
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
|
1303
|
+
|
|
1304
|
+
const items = Array.from(list);
|
|
1305
|
+
|
|
1306
|
+
expect(items).toEqual(["bread", "butter", "onion"]);
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1309
|
+
test(".values() works with CoValue references", () => {
|
|
1310
|
+
const Dog = co.map({
|
|
1311
|
+
name: z.string(),
|
|
1312
|
+
});
|
|
1313
|
+
const DogList = co.list(Dog);
|
|
1314
|
+
|
|
1315
|
+
const list = DogList.create([
|
|
1316
|
+
{ name: "Rex" },
|
|
1317
|
+
{ name: "Fido" },
|
|
1318
|
+
{ name: "Buddy" },
|
|
1319
|
+
]);
|
|
1320
|
+
|
|
1321
|
+
const valuesFromMethod = [...list.values()];
|
|
1322
|
+
const valuesFromObject = Object.values(list);
|
|
1323
|
+
|
|
1324
|
+
expect(valuesFromMethod.length).toBe(3);
|
|
1325
|
+
expect(valuesFromMethod.map((d) => d?.name)).toEqual([
|
|
1326
|
+
"Rex",
|
|
1327
|
+
"Fido",
|
|
1328
|
+
"Buddy",
|
|
1329
|
+
]);
|
|
1330
|
+
expect(valuesFromMethod).toEqual(valuesFromObject);
|
|
1331
|
+
});
|
|
1332
|
+
|
|
1333
|
+
test(".values() works after ensureLoaded", async () => {
|
|
1334
|
+
const Task = co.map({
|
|
1335
|
+
title: z.string(),
|
|
1336
|
+
});
|
|
1337
|
+
const TaskList = co.list(Task);
|
|
1338
|
+
|
|
1339
|
+
const list = TaskList.create([
|
|
1340
|
+
{ title: "Task 1" },
|
|
1341
|
+
{ title: "Task 2" },
|
|
1342
|
+
{ title: "Task 3" },
|
|
1343
|
+
]);
|
|
1344
|
+
|
|
1345
|
+
const loadedList = await list.$jazz.ensureLoaded({
|
|
1346
|
+
resolve: { $each: true },
|
|
1347
|
+
});
|
|
1348
|
+
|
|
1349
|
+
const valuesFromMethod = [...loadedList.values()];
|
|
1350
|
+
const valuesFromObject = Object.values(loadedList);
|
|
1351
|
+
|
|
1352
|
+
expect(valuesFromMethod.length).toBe(3);
|
|
1353
|
+
expect(valuesFromMethod.map((t) => t.title)).toEqual([
|
|
1354
|
+
"Task 1",
|
|
1355
|
+
"Task 2",
|
|
1356
|
+
"Task 3",
|
|
1357
|
+
]);
|
|
1358
|
+
expect(valuesFromMethod.map((t) => t.$jazz.id)).toEqual(
|
|
1359
|
+
valuesFromObject.map((t) => t.$jazz.id),
|
|
1360
|
+
);
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
test(".values() works on remotely loaded list", async () => {
|
|
1364
|
+
const Task = co.map({
|
|
1365
|
+
title: z.string(),
|
|
1366
|
+
});
|
|
1367
|
+
const TaskList = co.list(Task);
|
|
1368
|
+
|
|
1369
|
+
const group = Group.create();
|
|
1370
|
+
group.addMember("everyone", "writer");
|
|
1371
|
+
|
|
1372
|
+
const list = TaskList.create(
|
|
1373
|
+
[{ title: "Task 1" }, { title: "Task 2" }, { title: "Task 3" }],
|
|
1374
|
+
group,
|
|
1375
|
+
);
|
|
1376
|
+
|
|
1377
|
+
const userB = await createJazzTestAccount();
|
|
1378
|
+
|
|
1379
|
+
const loadedList = await TaskList.load(list.$jazz.id, {
|
|
1380
|
+
resolve: { $each: true },
|
|
1381
|
+
loadAs: userB,
|
|
1382
|
+
});
|
|
1383
|
+
|
|
1384
|
+
assertLoaded(loadedList);
|
|
1385
|
+
|
|
1386
|
+
const valuesFromMethod = [...loadedList.values()];
|
|
1387
|
+
const valuesFromObject = Object.values(loadedList);
|
|
1388
|
+
|
|
1389
|
+
expect(valuesFromMethod.length).toBe(3);
|
|
1390
|
+
expect(valuesFromMethod.map((t) => t.title)).toEqual([
|
|
1391
|
+
"Task 1",
|
|
1392
|
+
"Task 2",
|
|
1393
|
+
"Task 3",
|
|
1394
|
+
]);
|
|
1395
|
+
expect(valuesFromMethod.map((t) => t.$jazz.id)).toEqual(
|
|
1396
|
+
valuesFromObject.map((t) => t.$jazz.id),
|
|
1397
|
+
);
|
|
1398
|
+
});
|
|
1399
|
+
|
|
1400
|
+
test("iterator methods work on empty list", () => {
|
|
1401
|
+
const TestList = co.list(z.string());
|
|
1402
|
+
const list = TestList.create([]);
|
|
1403
|
+
|
|
1404
|
+
expect([...list.values()]).toEqual([]);
|
|
1405
|
+
expect([...list.keys()]).toEqual([]);
|
|
1406
|
+
expect([...list.entries()]).toEqual([]);
|
|
1407
|
+
expect([...list]).toEqual([]);
|
|
1408
|
+
});
|
|
1409
|
+
|
|
1410
|
+
test("Object.getOwnPropertyDescriptors returns correct descriptors", () => {
|
|
1411
|
+
const TestList = co.list(z.string());
|
|
1412
|
+
const list = TestList.create(["a", "b", "c"]);
|
|
1413
|
+
|
|
1414
|
+
const descriptors = Object.getOwnPropertyDescriptors(list);
|
|
1415
|
+
|
|
1416
|
+
// Check numeric index descriptors
|
|
1417
|
+
expect(descriptors["0"]).toEqual({
|
|
1418
|
+
enumerable: true,
|
|
1419
|
+
configurable: true,
|
|
1420
|
+
writable: false,
|
|
1421
|
+
value: "a",
|
|
1422
|
+
});
|
|
1423
|
+
expect(descriptors["1"]).toEqual({
|
|
1424
|
+
enumerable: true,
|
|
1425
|
+
configurable: true,
|
|
1426
|
+
writable: false,
|
|
1427
|
+
value: "b",
|
|
1428
|
+
});
|
|
1429
|
+
expect(descriptors["2"]).toEqual({
|
|
1430
|
+
enumerable: true,
|
|
1431
|
+
configurable: true,
|
|
1432
|
+
writable: false,
|
|
1433
|
+
value: "c",
|
|
1434
|
+
});
|
|
1435
|
+
|
|
1436
|
+
// Check length descriptor
|
|
1437
|
+
expect(descriptors["length"]).toEqual({
|
|
1438
|
+
enumerable: false,
|
|
1439
|
+
configurable: false,
|
|
1440
|
+
writable: true,
|
|
1441
|
+
value: 3,
|
|
1442
|
+
});
|
|
1443
|
+
|
|
1444
|
+
// Verify only expected enumerable keys
|
|
1445
|
+
const enumerableKeys = Object.keys(descriptors).filter(
|
|
1446
|
+
(key) => descriptors[key]?.enumerable,
|
|
1447
|
+
);
|
|
1448
|
+
expect(enumerableKeys.sort()).toEqual(["0", "1", "2"]);
|
|
1449
|
+
});
|
|
1450
|
+
|
|
1451
|
+
test("Object.getOwnPropertyDescriptors returns the resolved references", () => {
|
|
1452
|
+
const TestList = co.list(co.map({ name: z.string() }));
|
|
1453
|
+
const list = TestList.create([{ name: "a" }, { name: "b" }, { name: "c" }]);
|
|
1454
|
+
|
|
1455
|
+
const descriptors = Object.getOwnPropertyDescriptors(list);
|
|
1456
|
+
|
|
1457
|
+
// Check numeric index descriptors
|
|
1458
|
+
expect(descriptors["0"]).toEqual({
|
|
1459
|
+
enumerable: true,
|
|
1460
|
+
configurable: true,
|
|
1461
|
+
writable: false,
|
|
1462
|
+
value: list[0],
|
|
1463
|
+
});
|
|
1464
|
+
expect(descriptors["1"]).toEqual({
|
|
1465
|
+
enumerable: true,
|
|
1466
|
+
configurable: true,
|
|
1467
|
+
writable: false,
|
|
1468
|
+
value: list[1],
|
|
1469
|
+
});
|
|
1470
|
+
expect(descriptors["2"]).toEqual({
|
|
1471
|
+
enumerable: true,
|
|
1472
|
+
configurable: true,
|
|
1473
|
+
writable: false,
|
|
1474
|
+
value: list[2],
|
|
1475
|
+
});
|
|
1476
|
+
});
|
|
1477
|
+
|
|
1478
|
+
test("setting the lenght to 0 has no effect", () => {
|
|
1479
|
+
const TestList = co.list(z.string());
|
|
1480
|
+
const list = TestList.create(["a", "b", "c"]);
|
|
1481
|
+
|
|
1482
|
+
list.length = 0;
|
|
1483
|
+
|
|
1484
|
+
expect(list.length).toBe(3);
|
|
1485
|
+
expect(list[0]).toBe("a");
|
|
1486
|
+
expect(list[1]).toBe("b");
|
|
1487
|
+
expect(list[2]).toBe("c");
|
|
1488
|
+
});
|
|
1489
|
+
});
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
Account,
|
|
4
|
+
CoValueLoadingState,
|
|
5
|
+
Group,
|
|
6
|
+
co,
|
|
7
|
+
deleteCoValues,
|
|
8
|
+
z,
|
|
9
|
+
} from "../exports.js";
|
|
10
|
+
import { createJazzTestAccount, setupJazzTestSync } from "../testing.js";
|
|
11
|
+
import { assertLoaded, waitFor } from "./utils.js";
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
await setupJazzTestSync();
|
|
15
|
+
await createJazzTestAccount({
|
|
16
|
+
isCurrentActiveAccount: true,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("deleteCoValues", () => {
|
|
21
|
+
test("deletes a resolved graph (tombstones) and loads as DELETED", async () => {
|
|
22
|
+
const Meta = co.map({
|
|
23
|
+
tag: z.string(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const Note = co.map({
|
|
27
|
+
text: co.plainText(),
|
|
28
|
+
meta: Meta,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const owner = Account.getMe();
|
|
32
|
+
const group = Group.create(owner).makePublic("reader");
|
|
33
|
+
|
|
34
|
+
const note = Note.create(
|
|
35
|
+
{
|
|
36
|
+
text: "hello",
|
|
37
|
+
meta: { tag: "t1" },
|
|
38
|
+
},
|
|
39
|
+
group,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const text = note.text;
|
|
43
|
+
const meta = note.meta;
|
|
44
|
+
|
|
45
|
+
await note.$jazz.raw.core.waitForSync();
|
|
46
|
+
|
|
47
|
+
await deleteCoValues(Note, note.$jazz.id, {
|
|
48
|
+
loadAs: owner,
|
|
49
|
+
resolve: { text: true, meta: true },
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
expect(note.$jazz.raw.core.isDeleted).toBe(true);
|
|
53
|
+
expect(text.$jazz.raw.core.isDeleted).toBe(true);
|
|
54
|
+
expect(meta.$jazz.raw.core.isDeleted).toBe(true);
|
|
55
|
+
|
|
56
|
+
const viewer = await createJazzTestAccount();
|
|
57
|
+
const loaded = await Note.load(note.$jazz.id, {
|
|
58
|
+
loadAs: viewer,
|
|
59
|
+
skipRetry: true,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
expect(loaded.$isLoaded).toBe(false);
|
|
63
|
+
expect(loaded.$jazz.loadingState).toBe(CoValueLoadingState.DELETED);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("rejects deletion for non-admin on a group-owned value", async () => {
|
|
67
|
+
const Meta = co.map({
|
|
68
|
+
tag: z.string(),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const Note = co.map({
|
|
72
|
+
meta: Meta,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const owner = Account.getMe();
|
|
76
|
+
const writer = await createJazzTestAccount();
|
|
77
|
+
|
|
78
|
+
const group = Group.create(owner);
|
|
79
|
+
group.addMember(writer, "writer");
|
|
80
|
+
|
|
81
|
+
const note = Note.create({ meta: { tag: "t1" } }, group);
|
|
82
|
+
await note.$jazz.raw.core.waitForSync();
|
|
83
|
+
|
|
84
|
+
await expect(
|
|
85
|
+
deleteCoValues(Note, note.$jazz.id, {
|
|
86
|
+
loadAs: writer,
|
|
87
|
+
resolve: { meta: true },
|
|
88
|
+
}),
|
|
89
|
+
).rejects.toThrow(/admin permissions/i);
|
|
90
|
+
|
|
91
|
+
expect(note.$jazz.raw.core.isDeleted).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("rejects deletion when a resolved child is not deletable (error includes path)", async () => {
|
|
95
|
+
const Child = co.map({
|
|
96
|
+
value: z.string(),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const Root = co.map({
|
|
100
|
+
child: Child,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const owner = Account.getMe();
|
|
104
|
+
const otherOwner = await createJazzTestAccount();
|
|
105
|
+
|
|
106
|
+
const groupA = Group.create(owner).makePublic("reader");
|
|
107
|
+
const groupB = Group.create({ owner: otherOwner }).makePublic("reader");
|
|
108
|
+
|
|
109
|
+
const child = Child.create({ value: "child" }, groupB);
|
|
110
|
+
await child.$jazz.raw.core.waitForSync();
|
|
111
|
+
|
|
112
|
+
const root = Root.create({ child }, groupA);
|
|
113
|
+
await root.$jazz.raw.core.waitForSync();
|
|
114
|
+
|
|
115
|
+
await expect(
|
|
116
|
+
deleteCoValues(Root, root.$jazz.id, {
|
|
117
|
+
loadAs: owner,
|
|
118
|
+
resolve: { child: true },
|
|
119
|
+
}),
|
|
120
|
+
).rejects.toThrow(
|
|
121
|
+
new RegExp(
|
|
122
|
+
`Subscription starts from ${root.$jazz.id}.*path ${child.$jazz.id}`,
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(root.$jazz.raw.core.isDeleted).toBe(false);
|
|
127
|
+
expect(child.$jazz.raw.core.isDeleted).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("rejects deletion when the value cannot be loaded", async () => {
|
|
131
|
+
const Root = co.map({
|
|
132
|
+
value: z.string(),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const owner = Account.getMe();
|
|
136
|
+
const otherOwner = await createJazzTestAccount();
|
|
137
|
+
const root = Root.create(
|
|
138
|
+
{ value: "root" },
|
|
139
|
+
Group.create({ owner: otherOwner }),
|
|
140
|
+
);
|
|
141
|
+
await root.$jazz.raw.core.waitForSync();
|
|
142
|
+
|
|
143
|
+
await expect(
|
|
144
|
+
deleteCoValues(Root, root.$jazz.id, {
|
|
145
|
+
loadAs: owner,
|
|
146
|
+
}),
|
|
147
|
+
).rejects.toThrow(new RegExp(`Jazz Authorization Error`));
|
|
148
|
+
|
|
149
|
+
expect(root.$jazz.raw.core.isDeleted).toBe(false);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("rejects deletion when a child could not be loaded", async () => {
|
|
153
|
+
const Child = co.map({
|
|
154
|
+
value: z.string(),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const Root = co.map({
|
|
158
|
+
child: Child,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const owner = Account.getMe();
|
|
162
|
+
const otherOwner = await createJazzTestAccount();
|
|
163
|
+
|
|
164
|
+
const groupA = Group.create(owner).makePublic("reader");
|
|
165
|
+
const groupB = Group.create({ owner: otherOwner });
|
|
166
|
+
|
|
167
|
+
const child = Child.create({ value: "child" }, groupB);
|
|
168
|
+
await child.$jazz.raw.core.waitForSync();
|
|
169
|
+
|
|
170
|
+
const root = Root.create({ child }, groupA);
|
|
171
|
+
await root.$jazz.raw.core.waitForSync();
|
|
172
|
+
|
|
173
|
+
await expect(
|
|
174
|
+
deleteCoValues(Root, root.$jazz.id, {
|
|
175
|
+
loadAs: owner,
|
|
176
|
+
resolve: { child: true },
|
|
177
|
+
}),
|
|
178
|
+
).rejects.toThrow(new RegExp(`Jazz Authorization Error`));
|
|
179
|
+
|
|
180
|
+
expect(root.$jazz.raw.core.isDeleted).toBe(false);
|
|
181
|
+
expect(child.$jazz.raw.core.isDeleted).toBe(false);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("delete the CoValue when the child cannot be loaded but is marked with $onError", async () => {
|
|
185
|
+
const Child = co.map({
|
|
186
|
+
value: z.string(),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const Root = co.map({
|
|
190
|
+
child: Child,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const owner = Account.getMe();
|
|
194
|
+
const otherOwner = await createJazzTestAccount();
|
|
195
|
+
|
|
196
|
+
const groupA = Group.create(owner).makePublic("reader");
|
|
197
|
+
const groupB = Group.create({ owner: otherOwner });
|
|
198
|
+
|
|
199
|
+
const child = Child.create({ value: "child" }, groupB);
|
|
200
|
+
await child.$jazz.raw.core.waitForSync();
|
|
201
|
+
|
|
202
|
+
const root = Root.create({ child }, groupA);
|
|
203
|
+
await root.$jazz.raw.core.waitForSync();
|
|
204
|
+
|
|
205
|
+
await deleteCoValues(Root, root.$jazz.id, {
|
|
206
|
+
loadAs: owner,
|
|
207
|
+
resolve: { child: { $onError: "catch" } },
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
expect(root.$jazz.raw.core.isDeleted).toBe(true);
|
|
211
|
+
expect(child.$jazz.raw.core.isDeleted).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("skips Account and Group CoValues", async () => {
|
|
215
|
+
const me = Account.getMe();
|
|
216
|
+
|
|
217
|
+
await deleteCoValues(Account, me.$jazz.id, {
|
|
218
|
+
loadAs: me,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
expect(me.$jazz.raw.core.isDeleted).toBe(false);
|
|
222
|
+
|
|
223
|
+
const group = Group.create(me).makePublic("reader");
|
|
224
|
+
|
|
225
|
+
await deleteCoValues(Group, group.$jazz.id, {
|
|
226
|
+
loadAs: me,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
expect(group.$jazz.raw.core.isDeleted).toBe(false);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, onTestFinished, vi } from "vitest";
|
|
2
|
+
import { cojsonInternals } from "cojson";
|
|
3
|
+
|
|
4
|
+
import { Account, Group, z } from "../index.js";
|
|
5
|
+
import {
|
|
6
|
+
CoValueLoadingState,
|
|
7
|
+
co,
|
|
8
|
+
coValueClassFromCoValueClassOrSchema,
|
|
9
|
+
subscribeToCoValue,
|
|
10
|
+
} from "../internal.js";
|
|
11
|
+
import { loadCoValue } from "../exports.js";
|
|
12
|
+
import { createJazzTestAccount, setupJazzTestSync } from "../testing.js";
|
|
13
|
+
import { setupAccount, waitFor } from "./utils.js";
|
|
14
|
+
|
|
15
|
+
cojsonInternals.setCoValueLoadingRetryDelay(50);
|
|
16
|
+
|
|
17
|
+
describe("deleted loading state", () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
// Keep these tests snappy and deterministic.
|
|
20
|
+
cojsonInternals.CO_VALUE_LOADING_CONFIG.MAX_RETRIES = 1;
|
|
21
|
+
cojsonInternals.CO_VALUE_LOADING_CONFIG.TIMEOUT = 50;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("subscribeToCoValue calls onError and stops emitting loaded updates", async () => {
|
|
25
|
+
const TestMap = co.map({
|
|
26
|
+
value: z.string(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const { me, meOnSecondPeer } = await setupAccount();
|
|
30
|
+
|
|
31
|
+
const map = TestMap.create({ value: "hello" }, me);
|
|
32
|
+
|
|
33
|
+
const onLoaded = vi.fn();
|
|
34
|
+
const onError = vi.fn();
|
|
35
|
+
const onUnavailable = vi.fn();
|
|
36
|
+
const onUnauthorized = vi.fn();
|
|
37
|
+
|
|
38
|
+
const unsubscribe = subscribeToCoValue(
|
|
39
|
+
coValueClassFromCoValueClassOrSchema(TestMap),
|
|
40
|
+
map.$jazz.id,
|
|
41
|
+
{
|
|
42
|
+
loadAs: meOnSecondPeer,
|
|
43
|
+
onError,
|
|
44
|
+
onUnavailable,
|
|
45
|
+
onUnauthorized,
|
|
46
|
+
},
|
|
47
|
+
onLoaded,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
onTestFinished(unsubscribe);
|
|
51
|
+
|
|
52
|
+
await waitFor(() => {
|
|
53
|
+
expect(onLoaded).toHaveBeenCalled();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const loadedCallCountBeforeDelete = onLoaded.mock.calls.length;
|
|
57
|
+
|
|
58
|
+
map.$jazz.raw.core.deleteCoValue();
|
|
59
|
+
await map.$jazz.raw.core.waitForSync();
|
|
60
|
+
|
|
61
|
+
await waitFor(() => {
|
|
62
|
+
expect(onError).toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const deletedValue = onError.mock.calls[0]?.[0];
|
|
66
|
+
expect(deletedValue?.$isLoaded).toBe(false);
|
|
67
|
+
expect(deletedValue?.$jazz.loadingState).toBe(CoValueLoadingState.DELETED);
|
|
68
|
+
|
|
69
|
+
// Give the system a moment; we should not emit additional loaded updates after deletion.
|
|
70
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
71
|
+
expect(onLoaded).toHaveBeenCalledTimes(loadedCallCountBeforeDelete);
|
|
72
|
+
expect(onUnavailable).not.toHaveBeenCalled();
|
|
73
|
+
expect(onUnauthorized).not.toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("loadCoValue resolves a NotLoaded(DELETED) value for deleted coValues", async () => {
|
|
77
|
+
await setupJazzTestSync();
|
|
78
|
+
|
|
79
|
+
const TestMap = co.map({
|
|
80
|
+
value: z.string(),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const owner = await createJazzTestAccount({
|
|
84
|
+
isCurrentActiveAccount: true,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const group = Group.create(owner).makePublic("reader");
|
|
88
|
+
const map = TestMap.create({ value: "hello" }, group);
|
|
89
|
+
|
|
90
|
+
// Ensure the value exists on storage/peers before deleting.
|
|
91
|
+
await map.$jazz.raw.core.waitForSync();
|
|
92
|
+
|
|
93
|
+
map.$jazz.raw.core.deleteCoValue();
|
|
94
|
+
await map.$jazz.raw.core.waitForSync();
|
|
95
|
+
|
|
96
|
+
const viewer = await createJazzTestAccount();
|
|
97
|
+
|
|
98
|
+
const loaded = await loadCoValue(
|
|
99
|
+
coValueClassFromCoValueClassOrSchema(TestMap),
|
|
100
|
+
map.$jazz.id,
|
|
101
|
+
{
|
|
102
|
+
loadAs: viewer,
|
|
103
|
+
skipRetry: true,
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
expect(loaded.$isLoaded).toBe(false);
|
|
108
|
+
expect(loaded.$jazz.loadingState).toBe(CoValueLoadingState.DELETED);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -20,7 +20,18 @@ import { createJazzTestAccount, linkAccounts } from "../testing.js";
|
|
|
20
20
|
|
|
21
21
|
const server = setupServer();
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const ignoreWasmRequests = (request: Request, print: any) => {
|
|
24
|
+
if (request.url.includes("application/wasm")) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
print.warning();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
beforeAll(() =>
|
|
31
|
+
server.listen({
|
|
32
|
+
onUnhandledRequest: ignoreWasmRequests,
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
24
35
|
afterEach(() => server.resetHandlers());
|
|
25
36
|
afterEach(() => vi.restoreAllMocks());
|
|
26
37
|
afterAll(() => server.close());
|
|
@@ -877,7 +888,9 @@ describe("JazzRequestError handling", () => {
|
|
|
877
888
|
),
|
|
878
889
|
).rejects.toThrow("fetch failed");
|
|
879
890
|
|
|
880
|
-
server.listen(
|
|
891
|
+
server.listen({
|
|
892
|
+
onUnhandledRequest: ignoreWasmRequests,
|
|
893
|
+
});
|
|
881
894
|
});
|
|
882
895
|
});
|
|
883
896
|
|
|
@@ -843,7 +843,7 @@ describe("setDefaultSchemaPermissions", () => {
|
|
|
843
843
|
expect(childOwner.getRoleOf(anotherAccount.$jazz.id)).toEqual("reader");
|
|
844
844
|
});
|
|
845
845
|
|
|
846
|
-
test("
|
|
846
|
+
test("modifies default permissions for existing schemas", () => {
|
|
847
847
|
const ExistingMap = co.map({
|
|
848
848
|
name: co.plainText(),
|
|
849
849
|
});
|
|
@@ -852,8 +852,31 @@ describe("setDefaultSchemaPermissions", () => {
|
|
|
852
852
|
});
|
|
853
853
|
|
|
854
854
|
const map = ExistingMap.create({ name: "Hello" });
|
|
855
|
-
expect(
|
|
856
|
-
|
|
857
|
-
|
|
855
|
+
expect(map.name.$jazz.owner.$jazz.id).toContain(map.$jazz.owner.$jazz.id);
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
test("modifies default permissions for copied schemas", async () => {
|
|
859
|
+
const anotherAccount = await createJazzTestAccount();
|
|
860
|
+
|
|
861
|
+
const ExistingMap = co.map({
|
|
862
|
+
name: co.plainText(),
|
|
863
|
+
});
|
|
864
|
+
setDefaultSchemaPermissions({
|
|
865
|
+
onCreate() {
|
|
866
|
+
// Do nothing
|
|
867
|
+
},
|
|
868
|
+
});
|
|
869
|
+
const CopiedMap = ExistingMap.resolved({ name: true });
|
|
870
|
+
setDefaultSchemaPermissions({
|
|
871
|
+
onCreate(newGroup) {
|
|
872
|
+
newGroup.addMember(anotherAccount, "reader");
|
|
873
|
+
},
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
const map = CopiedMap.create({ name: "Hello" });
|
|
877
|
+
await map.$jazz.waitForSync();
|
|
878
|
+
|
|
879
|
+
const mapOwner = map.$jazz.owner;
|
|
880
|
+
expect(mapOwner.getRoleOf(anotherAccount.$jazz.id)).toEqual("reader");
|
|
858
881
|
});
|
|
859
882
|
});
|
package/src/worker/edge-wasm.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// InitWasm allow to load the wasm code in edge runtimes (ex. cloudflare worker and vercel edge functions)
|
|
2
|
-
import { init as InitWasm } from "cojson/crypto/WasmCrypto/edge";
|
|
2
|
+
import { init as InitWasm, initSync } from "cojson/crypto/WasmCrypto/edge";
|
|
3
3
|
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
|
4
4
|
|
|
5
5
|
WasmCrypto.setInit(InitWasm);
|
|
6
|
+
WasmCrypto.setInitSync(initSync);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { initWasmCrypto as initWasm } from "cojson/crypto/WasmCrypto";
|