jazz-tools 0.17.14 → 0.18.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__/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 +60 -46
- package/CHANGELOG.md +41 -0
- package/dist/better-auth/auth/client.d.ts +29 -0
- package/dist/better-auth/auth/client.d.ts.map +1 -0
- package/dist/better-auth/auth/client.js +127 -0
- package/dist/better-auth/auth/client.js.map +1 -0
- package/dist/better-auth/auth/react.d.ts +2170 -0
- package/dist/better-auth/auth/react.d.ts.map +1 -0
- package/dist/better-auth/auth/react.js +40 -0
- package/dist/better-auth/auth/react.js.map +1 -0
- package/dist/better-auth/auth/server.d.ts +14 -0
- package/dist/better-auth/auth/server.d.ts.map +1 -0
- package/dist/better-auth/auth/server.js +198 -0
- package/dist/better-auth/auth/server.js.map +1 -0
- package/dist/better-auth/auth/tests/client.test.d.ts +2 -0
- package/dist/better-auth/auth/tests/client.test.d.ts.map +1 -0
- package/dist/better-auth/auth/tests/server.test.d.ts +2 -0
- package/dist/better-auth/auth/tests/server.test.d.ts.map +1 -0
- package/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/{chunk-LZOF6WP5.js → chunk-IERUTUXB.js} +1336 -1017
- package/dist/chunk-IERUTUXB.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 +4675 -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 +101 -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 +210 -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 +3 -3
- 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 +23 -4
- package/src/better-auth/auth/client.ts +169 -0
- package/src/better-auth/auth/react.tsx +105 -0
- package/src/better-auth/auth/server.ts +250 -0
- package/src/better-auth/auth/tests/client.test.ts +249 -0
- package/src/better-auth/auth/tests/server.test.ts +226 -0
- 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 +311 -232
- package/src/tools/coValues/coFeed.ts +185 -153
- package/src/tools/coValues/coList.ts +507 -334
- package/src/tools/coValues/coMap.ts +434 -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 +3 -3
- 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 +70 -59
- package/src/tools/tests/PassphraseAuth.test.ts +2 -2
- package/src/tools/tests/account.test.ts +188 -67
- 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 +459 -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 +7 -7
- 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 +7 -11
- 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/tsup.config.ts +9 -0
- 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
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
runWithoutActiveAccount,
|
13
13
|
setupJazzTestSync,
|
14
14
|
} from "../testing.js";
|
15
|
-
import { waitFor } from "./utils.js";
|
15
|
+
import { setupTwoNodes, waitFor } from "./utils.js";
|
16
16
|
|
17
17
|
const Crypto = await WasmCrypto.create();
|
18
18
|
|
@@ -39,7 +39,7 @@ describe("Simple CoList operations", async () => {
|
|
39
39
|
expect(list[0]).toBe("bread");
|
40
40
|
expect(list[1]).toBe("butter");
|
41
41
|
expect(list[2]).toBe("onion");
|
42
|
-
expect(list.
|
42
|
+
expect(list.$jazz.raw.asArray()).toEqual(["bread", "butter", "onion"]);
|
43
43
|
expect(list.length).toBe(3);
|
44
44
|
expect(list.map((item) => item.toUpperCase())).toEqual([
|
45
45
|
"BREAD",
|
@@ -127,12 +127,12 @@ describe("Simple CoList operations", async () => {
|
|
127
127
|
const list = TestList.create(["bread", "butter", "onion"], {
|
128
128
|
owner: me,
|
129
129
|
});
|
130
|
-
list
|
131
|
-
expect(list.
|
130
|
+
list.$jazz.set(1, "margarine");
|
131
|
+
expect(list.$jazz.raw.asArray()).toEqual(["bread", "margarine", "onion"]);
|
132
132
|
expect(list[1]).toBe("margarine");
|
133
133
|
});
|
134
134
|
|
135
|
-
test("assignment with ref", () => {
|
135
|
+
test("assignment with ref using CoValue", () => {
|
136
136
|
const Ingredient = co.map({
|
137
137
|
name: z.string(),
|
138
138
|
});
|
@@ -147,9 +147,11 @@ describe("Simple CoList operations", async () => {
|
|
147
147
|
],
|
148
148
|
{ owner: me },
|
149
149
|
);
|
150
|
+
const originalIngredient = recipe[1];
|
150
151
|
|
151
|
-
recipe
|
152
|
+
recipe.$jazz.set(1, Ingredient.create({ name: "margarine" }, me));
|
152
153
|
expect(recipe[1]?.name).toBe("margarine");
|
154
|
+
expect(recipe[1]?.$jazz.id).not.toBe(originalIngredient?.$jazz.id);
|
153
155
|
});
|
154
156
|
|
155
157
|
test("assign undefined on a required ref", () => {
|
@@ -169,7 +171,7 @@ describe("Simple CoList operations", async () => {
|
|
169
171
|
);
|
170
172
|
|
171
173
|
expect(() => {
|
172
|
-
recipe
|
174
|
+
recipe.$jazz.set(1, undefined as unknown as Loaded<typeof Ingredient>);
|
173
175
|
}).toThrow("Cannot set required reference 1 to undefined");
|
174
176
|
|
175
177
|
expect(recipe[1]?.name).toBe("butter");
|
@@ -191,54 +193,104 @@ describe("Simple CoList operations", async () => {
|
|
191
193
|
{ owner: me },
|
192
194
|
);
|
193
195
|
|
194
|
-
recipe
|
196
|
+
recipe.$jazz.set(1, undefined);
|
195
197
|
expect(recipe[1]).toBe(undefined);
|
196
198
|
});
|
197
199
|
|
198
|
-
test("
|
199
|
-
const
|
200
|
-
|
200
|
+
test("assignment with ref using JSON", () => {
|
201
|
+
const Ingredient = co.map({
|
202
|
+
name: z.string(),
|
201
203
|
});
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
"butter",
|
207
|
-
|
208
|
-
|
209
|
-
]
|
204
|
+
|
205
|
+
const Recipe = co.list(Ingredient);
|
206
|
+
|
207
|
+
const recipe = Recipe.create(
|
208
|
+
[{ name: "bread" }, { name: "butter" }, { name: "onion" }],
|
209
|
+
{ owner: me },
|
210
|
+
);
|
211
|
+
const originalIngredient = recipe[1];
|
212
|
+
|
213
|
+
recipe.$jazz.set(1, { name: "margarine" });
|
214
|
+
expect(recipe[1]?.name).toBe("margarine");
|
215
|
+
expect(recipe[1]?.$jazz.id).not.toBe(originalIngredient?.$jazz.id);
|
210
216
|
});
|
211
217
|
|
212
|
-
|
213
|
-
|
214
|
-
|
218
|
+
describe("push", () => {
|
219
|
+
test("push into CoList of non-collaborative values", () => {
|
220
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
221
|
+
owner: me,
|
222
|
+
});
|
223
|
+
list.$jazz.push("cheese");
|
224
|
+
expect(list[3]).toBe("cheese");
|
225
|
+
expect(list.$jazz.raw.asArray()).toEqual([
|
226
|
+
"bread",
|
227
|
+
"butter",
|
228
|
+
"onion",
|
229
|
+
"cheese",
|
230
|
+
]);
|
231
|
+
});
|
232
|
+
|
233
|
+
test("push CoValue into list of CoValues", () => {
|
234
|
+
const Schema = co.list(co.plainText());
|
235
|
+
const list = Schema.create(["bread", "butter", "onion"]);
|
236
|
+
list.$jazz.push(Schema.element.create("cheese"));
|
237
|
+
expect(list[3]?.toString()).toBe("cheese");
|
238
|
+
});
|
239
|
+
|
240
|
+
test("push JSON into list of CoValues", () => {
|
241
|
+
const Schema = co.list(co.plainText());
|
242
|
+
const list = Schema.create(["bread", "butter", "onion"]);
|
243
|
+
list.$jazz.push("cheese");
|
244
|
+
expect(list[3]?.toString()).toBe("cheese");
|
245
|
+
});
|
246
|
+
});
|
247
|
+
|
248
|
+
describe("unshift", () => {
|
249
|
+
test("add non-collaborative element at the beginning of the list", () => {
|
250
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
251
|
+
owner: me,
|
252
|
+
});
|
253
|
+
list.$jazz.unshift("lettuce");
|
254
|
+
expect(list[0]).toBe("lettuce");
|
255
|
+
expect(list.$jazz.raw.asArray()).toEqual([
|
256
|
+
"lettuce",
|
257
|
+
"bread",
|
258
|
+
"butter",
|
259
|
+
"onion",
|
260
|
+
]);
|
261
|
+
});
|
262
|
+
|
263
|
+
test("add CoValue at the beginning of a CoValue CoList", () => {
|
264
|
+
const Schema = co.list(co.plainText());
|
265
|
+
const list = Schema.create(["bread", "butter", "onion"]);
|
266
|
+
list.$jazz.unshift(Schema.element.create("lettuce"));
|
267
|
+
expect(list[0]?.toString()).toBe("lettuce");
|
268
|
+
});
|
269
|
+
|
270
|
+
test("add JSON at the beginning of a CoValue CoList", () => {
|
271
|
+
const Schema = co.list(co.plainText());
|
272
|
+
const list = Schema.create(["bread", "butter", "onion"]);
|
273
|
+
list.$jazz.unshift("lettuce");
|
274
|
+
expect(list[0]?.toString()).toBe("lettuce");
|
215
275
|
});
|
216
|
-
list.unshift("lettuce");
|
217
|
-
expect(list[0]).toBe("lettuce");
|
218
|
-
expect(list._raw.asArray()).toEqual([
|
219
|
-
"lettuce",
|
220
|
-
"bread",
|
221
|
-
"butter",
|
222
|
-
"onion",
|
223
|
-
]);
|
224
276
|
});
|
225
277
|
|
226
278
|
test("pop", () => {
|
227
279
|
const list = TestList.create(["bread", "butter", "onion"], {
|
228
280
|
owner: me,
|
229
281
|
});
|
230
|
-
expect(list.pop()).toBe("onion");
|
282
|
+
expect(list.$jazz.pop()).toBe("onion");
|
231
283
|
expect(list.length).toBe(2);
|
232
|
-
expect(list.
|
284
|
+
expect(list.$jazz.raw.asArray()).toEqual(["bread", "butter"]);
|
233
285
|
});
|
234
286
|
|
235
287
|
test("shift", () => {
|
236
288
|
const list = TestList.create(["bread", "butter", "onion"], {
|
237
289
|
owner: me,
|
238
290
|
});
|
239
|
-
expect(list.shift()).toBe("bread");
|
291
|
+
expect(list.$jazz.shift()).toBe("bread");
|
240
292
|
expect(list.length).toBe(2);
|
241
|
-
expect(list.
|
293
|
+
expect(list.$jazz.raw.asArray()).toEqual(["butter", "onion"]);
|
242
294
|
});
|
243
295
|
|
244
296
|
describe("splice", () => {
|
@@ -246,9 +298,9 @@ describe("Simple CoList operations", async () => {
|
|
246
298
|
const list = TestList.create(["bread", "butter", "onion"], {
|
247
299
|
owner: me,
|
248
300
|
});
|
249
|
-
list.splice(1, 1, "salt", "pepper");
|
301
|
+
list.$jazz.splice(1, 1, "salt", "pepper");
|
250
302
|
expect(list.length).toBe(4);
|
251
|
-
expect(list.
|
303
|
+
expect(list.$jazz.raw.asArray()).toEqual([
|
252
304
|
"bread",
|
253
305
|
"salt",
|
254
306
|
"pepper",
|
@@ -260,9 +312,9 @@ describe("Simple CoList operations", async () => {
|
|
260
312
|
const list = TestList.create(["bread", "butter", "onion"], {
|
261
313
|
owner: me,
|
262
314
|
});
|
263
|
-
list.splice(0, 0, "salt", "pepper");
|
315
|
+
list.$jazz.splice(0, 0, "salt", "pepper");
|
264
316
|
expect(list.length).toBe(5);
|
265
|
-
expect(list.
|
317
|
+
expect(list.$jazz.raw.asArray()).toEqual([
|
266
318
|
"salt",
|
267
319
|
"pepper",
|
268
320
|
"bread",
|
@@ -275,9 +327,9 @@ describe("Simple CoList operations", async () => {
|
|
275
327
|
const list = TestList.create(["bread", "butter", "onion"], {
|
276
328
|
owner: me,
|
277
329
|
});
|
278
|
-
list.splice(1, 0, "salt", "pepper");
|
330
|
+
list.$jazz.splice(1, 0, "salt", "pepper");
|
279
331
|
expect(list.length).toBe(5);
|
280
|
-
expect(list.
|
332
|
+
expect(list.$jazz.raw.asArray()).toEqual([
|
281
333
|
"bread",
|
282
334
|
"salt",
|
283
335
|
"pepper",
|
@@ -290,9 +342,9 @@ describe("Simple CoList operations", async () => {
|
|
290
342
|
const list = TestList.create(["bread", "butter", "onion"], {
|
291
343
|
owner: me,
|
292
344
|
});
|
293
|
-
list.splice(2, 0, "salt", "pepper");
|
345
|
+
list.$jazz.splice(2, 0, "salt", "pepper");
|
294
346
|
expect(list.length).toBe(5);
|
295
|
-
expect(list.
|
347
|
+
expect(list.$jazz.raw.asArray()).toEqual([
|
296
348
|
"bread",
|
297
349
|
"butter",
|
298
350
|
"salt",
|
@@ -300,76 +352,117 @@ describe("Simple CoList operations", async () => {
|
|
300
352
|
"onion",
|
301
353
|
]);
|
302
354
|
});
|
303
|
-
});
|
304
355
|
|
305
|
-
|
306
|
-
|
307
|
-
["
|
308
|
-
|
309
|
-
|
356
|
+
test("insert CoValue into a CoValue CoList", () => {
|
357
|
+
const Schema = co.list(co.plainText());
|
358
|
+
const list = Schema.create(["bread", "butter", "onion"]);
|
359
|
+
list.$jazz.splice(1, 0, Schema.element.create("lettuce"));
|
360
|
+
expect(list[1]?.toString()).toBe("lettuce");
|
361
|
+
});
|
310
362
|
|
311
|
-
|
312
|
-
|
313
|
-
"
|
314
|
-
"
|
315
|
-
"
|
316
|
-
|
317
|
-
]);
|
318
|
-
|
319
|
-
list.sort((a, b) => b.localeCompare(a));
|
320
|
-
expect(list._raw.asArray()).toEqual([
|
321
|
-
"iguana",
|
322
|
-
"hedgehog",
|
323
|
-
"giraffe",
|
324
|
-
"flamingo",
|
325
|
-
]);
|
363
|
+
test("insert JSON into a CoValue CoList", () => {
|
364
|
+
const Schema = co.list(co.plainText());
|
365
|
+
const list = Schema.create(["bread", "butter", "onion"]);
|
366
|
+
list.$jazz.splice(1, 0, "lettuce");
|
367
|
+
expect(list[1]?.toString()).toBe("lettuce");
|
368
|
+
});
|
326
369
|
});
|
327
370
|
|
328
|
-
|
329
|
-
|
330
|
-
|
371
|
+
describe("remove", () => {
|
372
|
+
describe("remove by index", () => {
|
373
|
+
test("remove one item", () => {
|
374
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
375
|
+
|
376
|
+
expect(list.$jazz.remove(1)).toEqual(["butter"]);
|
377
|
+
expect(list.$jazz.raw.asArray()).toEqual(["bread", "onion"]);
|
378
|
+
});
|
379
|
+
|
380
|
+
test("remove multiple items", () => {
|
381
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
382
|
+
|
383
|
+
expect(list.$jazz.remove(0, 2)).toEqual(["bread", "onion"]);
|
384
|
+
expect(list.$jazz.raw.asArray()).toEqual(["butter"]);
|
385
|
+
});
|
386
|
+
|
387
|
+
test("ignores out-of-bound indices", () => {
|
388
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
389
|
+
|
390
|
+
expect(list.$jazz.remove(4, -1, 1)).toEqual(["butter"]);
|
391
|
+
expect(list.$jazz.raw.asArray()).toEqual(["bread", "onion"]);
|
392
|
+
});
|
331
393
|
});
|
332
394
|
|
333
|
-
|
395
|
+
describe("remove by predicate", () => {
|
396
|
+
test("removes elements matching the predicate", () => {
|
397
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
334
398
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
{ owner: me },
|
341
|
-
);
|
399
|
+
expect(list.$jazz.remove((item) => item === "butter")).toEqual([
|
400
|
+
"butter",
|
401
|
+
]);
|
402
|
+
expect(list.$jazz.raw.asArray()).toEqual(["bread", "onion"]);
|
403
|
+
});
|
342
404
|
|
343
|
-
|
344
|
-
|
405
|
+
test("the predicate is called with the item, index and the coList", () => {
|
406
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
345
407
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
408
|
+
expect(
|
409
|
+
list.$jazz.remove(
|
410
|
+
(item, index, coList) => index > 0 && index < coList.length - 1,
|
411
|
+
),
|
412
|
+
).toEqual(["butter"]);
|
413
|
+
expect(list.$jazz.raw.asArray()).toEqual(["bread", "onion"]);
|
414
|
+
});
|
415
|
+
});
|
416
|
+
|
417
|
+
// CoListItem's type was being incorrectly inferred as nullable when using ensureLoaded
|
418
|
+
// on loaded CoLists. Keeping this test to ensure it doesn't regress.
|
419
|
+
test("removes elements from loaded CoLists", async () => {
|
420
|
+
const NestedList = co.list(co.map({ title: z.string() }));
|
421
|
+
const list = NestedList.create([
|
422
|
+
{ title: "bread" },
|
423
|
+
{ title: "butter" },
|
424
|
+
{ title: "onion" },
|
425
|
+
]);
|
426
|
+
const bread = list[0];
|
427
|
+
const butter = list[1];
|
428
|
+
const onion = list[2];
|
429
|
+
|
430
|
+
const shallowlyLoadedList = await NestedList.load(list.$jazz.id);
|
431
|
+
assert(shallowlyLoadedList);
|
432
|
+
|
433
|
+
const loadedList = await shallowlyLoadedList.$jazz.ensureLoaded({
|
434
|
+
resolve: { $each: true },
|
435
|
+
});
|
436
|
+
|
437
|
+
expect(
|
438
|
+
loadedList.$jazz.remove((item) => item.title === "butter"),
|
439
|
+
).toEqual([butter]);
|
440
|
+
expect(shallowlyLoadedList[0]).toEqual(bread);
|
441
|
+
expect(shallowlyLoadedList[1]).toEqual(onion);
|
442
|
+
});
|
353
443
|
});
|
354
444
|
|
355
|
-
|
356
|
-
|
357
|
-
|
445
|
+
describe("retain", () => {
|
446
|
+
test("retains elements matching the predicate", () => {
|
447
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
448
|
+
|
449
|
+
expect(list.$jazz.retain((item) => item === "butter")).toEqual([
|
450
|
+
"bread",
|
451
|
+
"onion",
|
452
|
+
]);
|
453
|
+
expect(list.$jazz.raw.asArray()).toEqual(["butter"]);
|
454
|
+
});
|
455
|
+
|
456
|
+
test("the predicate is called with the item, index and the coList", () => {
|
457
|
+
const list = TestList.create(["bread", "butter", "onion"]);
|
458
|
+
|
459
|
+
expect(
|
460
|
+
list.$jazz.retain(
|
461
|
+
(item, index, coList) => index > 0 && index < coList.length - 1,
|
462
|
+
),
|
463
|
+
).toEqual(["bread", "onion"]);
|
464
|
+
expect(list.$jazz.raw.asArray()).toEqual(["butter"]);
|
358
465
|
});
|
359
|
-
// replace
|
360
|
-
list.applyDiff(["bread", "margarine", "onion"]);
|
361
|
-
expect(list._raw.asArray()).toEqual(["bread", "margarine", "onion"]);
|
362
|
-
// delete
|
363
|
-
list.applyDiff(["bread", "onion"]);
|
364
|
-
expect(list._raw.asArray()).toEqual(["bread", "onion"]);
|
365
|
-
// insert multiple
|
366
|
-
list.applyDiff(["bread", "margarine", "onion", "cheese"]);
|
367
|
-
expect(list._raw.asArray()).toEqual([
|
368
|
-
"bread",
|
369
|
-
"margarine",
|
370
|
-
"onion",
|
371
|
-
"cheese",
|
372
|
-
]);
|
373
466
|
});
|
374
467
|
|
375
468
|
test("filter + assign to coMap", () => {
|
@@ -386,12 +479,12 @@ describe("Simple CoList operations", async () => {
|
|
386
479
|
{ owner: me },
|
387
480
|
);
|
388
481
|
|
389
|
-
|
390
|
-
|
391
|
-
map.list
|
392
|
-
|
482
|
+
map.$jazz.set(
|
483
|
+
"list",
|
484
|
+
map.list?.filter((item) => item !== "butter"),
|
485
|
+
);
|
393
486
|
|
394
|
-
expect(map.list
|
487
|
+
expect(map.list?.$jazz.raw.asArray()).toEqual(["bread", "onion"]);
|
395
488
|
});
|
396
489
|
|
397
490
|
test("filter + assign to CoList", () => {
|
@@ -406,12 +499,9 @@ describe("Simple CoList operations", async () => {
|
|
406
499
|
{ owner: me },
|
407
500
|
);
|
408
501
|
|
409
|
-
|
410
|
-
// @ts-expect-error
|
411
|
-
list[0] = list[0]?.filter((item) => item !== "butter");
|
412
|
-
}).toThrow("Cannot set reference 0 to a non-CoValue. Got bread,onion");
|
502
|
+
list.$jazz.set(0, list[0]?.filter((item) => item !== "butter") ?? []);
|
413
503
|
|
414
|
-
expect(list[0]
|
504
|
+
expect(list[0]?.$jazz.raw.asArray()).toEqual(["bread", "onion"]);
|
415
505
|
});
|
416
506
|
});
|
417
507
|
});
|
@@ -422,52 +512,99 @@ describe("CoList applyDiff operations", async () => {
|
|
422
512
|
const list = StringList.create(["a", "b", "c"], { owner: me });
|
423
513
|
|
424
514
|
// Test adding items
|
425
|
-
list.applyDiff(["a", "b", "c", "d", "e"]);
|
426
|
-
expect(list.
|
515
|
+
list.$jazz.applyDiff(["a", "b", "c", "d", "e"]);
|
516
|
+
expect(list.$jazz.raw.asArray()).toEqual(["a", "b", "c", "d", "e"]);
|
427
517
|
|
428
518
|
// Test removing items
|
429
|
-
list.applyDiff(["a", "c", "e"]);
|
430
|
-
expect(list.
|
519
|
+
list.$jazz.applyDiff(["a", "c", "e"]);
|
520
|
+
expect(list.$jazz.raw.asArray()).toEqual(["a", "c", "e"]);
|
431
521
|
|
432
522
|
// Test replacing items
|
433
|
-
list.applyDiff(["x", "y", "z"]);
|
434
|
-
expect(list.
|
523
|
+
list.$jazz.applyDiff(["x", "y", "z"]);
|
524
|
+
expect(list.$jazz.raw.asArray()).toEqual(["x", "y", "z"]);
|
435
525
|
|
436
526
|
// Test empty list
|
437
|
-
list.applyDiff([]);
|
438
|
-
expect(list.
|
527
|
+
list.$jazz.applyDiff([]);
|
528
|
+
expect(list.$jazz.raw.asArray()).toEqual([]);
|
439
529
|
});
|
440
530
|
|
441
|
-
test("applyDiff with reference values", () => {
|
442
|
-
const
|
443
|
-
const
|
531
|
+
test("applyDiff with reference values using CoValues", () => {
|
532
|
+
const TicTacToeRow = co.list(z.string());
|
533
|
+
const TicTacToeBoard = co.list(TicTacToeRow);
|
444
534
|
|
445
|
-
const
|
446
|
-
const
|
447
|
-
const
|
448
|
-
const
|
535
|
+
const row1 = TicTacToeRow.create(["X", "O", ""], { owner: me });
|
536
|
+
const row2 = TicTacToeRow.create(["", "X", "O"], { owner: me });
|
537
|
+
const row3 = TicTacToeRow.create(["O", "O", ""], { owner: me });
|
538
|
+
const winningRow = TicTacToeRow.create(["O", "O", "X"], { owner: me });
|
449
539
|
|
450
|
-
const list =
|
540
|
+
const list = TicTacToeBoard.create([row1, row2], { owner: me });
|
451
541
|
|
452
542
|
// Test adding reference items
|
453
|
-
list.applyDiff([
|
543
|
+
list.$jazz.applyDiff([row1, row2, row3]);
|
544
|
+
expect(list.length).toBe(3);
|
545
|
+
expect(list[2]?.toJSON()).toEqual(["O", "O", ""]);
|
546
|
+
|
547
|
+
// Test replacing reference items
|
548
|
+
list.$jazz.applyDiff([row1, row2, winningRow]);
|
454
549
|
expect(list.length).toBe(3);
|
455
|
-
expect(list[2]?.
|
550
|
+
expect(list[2]?.toJSON()).toEqual(["O", "O", "X"]);
|
551
|
+
// Only elements with different $jazz.id are replaced
|
552
|
+
expect(list[0]?.$jazz.id).toBe(row1?.$jazz.id);
|
553
|
+
expect(list[1]?.$jazz.id).toBe(row2?.$jazz.id);
|
554
|
+
expect(list[2]?.$jazz.id).not.toBe(row3?.$jazz.id);
|
456
555
|
|
457
556
|
// Test removing reference items
|
458
|
-
list.applyDiff([
|
557
|
+
list.$jazz.applyDiff([row1, row3]);
|
459
558
|
expect(list.length).toBe(2);
|
460
|
-
expect(list[0]?.
|
461
|
-
expect(list[
|
559
|
+
expect(list[0]?.toJSON()).toEqual(["X", "O", ""]);
|
560
|
+
expect(list[0]?.$jazz.id).toBe(row1?.$jazz.id);
|
561
|
+
expect(list[1]?.toJSON()).toEqual(["O", "O", ""]);
|
562
|
+
expect(list[1]?.$jazz.id).not.toBe(row2?.$jazz.id);
|
563
|
+
|
564
|
+
// Test empty list
|
565
|
+
list.$jazz.applyDiff([]);
|
566
|
+
expect(list.$jazz.raw.asArray()).toEqual([]);
|
567
|
+
});
|
568
|
+
|
569
|
+
test("applyDiff with reference values using JSON", () => {
|
570
|
+
const TicTacToeRow = co.list(z.string());
|
571
|
+
const TicTacToeBoard = co.list(TicTacToeRow);
|
572
|
+
|
573
|
+
const row1 = ["X", "O", ""];
|
574
|
+
const row2 = ["", "X", "O"];
|
575
|
+
const row3 = ["O", "O", ""];
|
576
|
+
const winningRow = ["O", "O", "X"];
|
577
|
+
|
578
|
+
const list = TicTacToeBoard.create([row1, row2], { owner: me });
|
579
|
+
const originalRow1 = list[0];
|
580
|
+
const originalRow2 = list[1];
|
581
|
+
const originalRow3 = list[2];
|
582
|
+
|
583
|
+
// Test adding reference items
|
584
|
+
list.$jazz.applyDiff([row1, row2, row3]);
|
585
|
+
expect(list.length).toBe(3);
|
586
|
+
expect(list[2]?.toJSON()).toEqual(["O", "O", ""]);
|
462
587
|
|
463
588
|
// Test replacing reference items
|
464
|
-
list.applyDiff([
|
465
|
-
expect(list.length).toBe(
|
466
|
-
expect(list[
|
589
|
+
list.$jazz.applyDiff([row1, row2, winningRow]);
|
590
|
+
expect(list.length).toBe(3);
|
591
|
+
expect(list[2]?.toJSON()).toEqual(["O", "O", "X"]);
|
592
|
+
// All elements are replaced because new JSON values are set
|
593
|
+
expect(list[0]?.$jazz.id).not.toBe(originalRow1?.$jazz.id);
|
594
|
+
expect(list[1]?.$jazz.id).not.toBe(originalRow2?.$jazz.id);
|
595
|
+
expect(list[2]?.$jazz.id).not.toBe(originalRow3?.$jazz.id);
|
596
|
+
|
597
|
+
// Test removing reference items
|
598
|
+
list.$jazz.applyDiff([row1, row3]);
|
599
|
+
expect(list.length).toBe(2);
|
600
|
+
expect(list[0]?.toJSON()).toEqual(["X", "O", ""]);
|
601
|
+
expect(list[0]?.$jazz.id).not.toBe(originalRow1?.$jazz.id);
|
602
|
+
expect(list[1]?.toJSON()).toEqual(["O", "O", ""]);
|
603
|
+
expect(list[1]?.$jazz.id).not.toBe(originalRow2?.$jazz.id);
|
467
604
|
|
468
605
|
// Test empty list
|
469
|
-
list.applyDiff([]);
|
470
|
-
expect(list.
|
606
|
+
list.$jazz.applyDiff([]);
|
607
|
+
expect(list.$jazz.raw.asArray()).toEqual([]);
|
471
608
|
});
|
472
609
|
|
473
610
|
test("applyDiff with refs + filter", () => {
|
@@ -483,9 +620,9 @@ describe("CoList applyDiff operations", async () => {
|
|
483
620
|
|
484
621
|
const list = TestList.create([bread, butter, onion], me);
|
485
622
|
|
486
|
-
list.applyDiff(list.filter((item) => item?.type !== "butter"));
|
623
|
+
list.$jazz.applyDiff(list.filter((item) => item?.type !== "butter"));
|
487
624
|
|
488
|
-
expect(list.
|
625
|
+
expect(list.$jazz.raw.asArray()).toEqual([bread.$jazz.id, onion.$jazz.id]);
|
489
626
|
});
|
490
627
|
|
491
628
|
test("applyDiff with mixed operations", () => {
|
@@ -493,16 +630,16 @@ describe("CoList applyDiff operations", async () => {
|
|
493
630
|
const list = StringList.create(["a", "b", "c", "d", "e"], { owner: me });
|
494
631
|
|
495
632
|
// Test multiple operations at once
|
496
|
-
list.applyDiff(["a", "x", "c", "y", "e"]);
|
497
|
-
expect(list.
|
633
|
+
list.$jazz.applyDiff(["a", "x", "c", "y", "e"]);
|
634
|
+
expect(list.$jazz.raw.asArray()).toEqual(["a", "x", "c", "y", "e"]);
|
498
635
|
|
499
636
|
// Test reordering
|
500
|
-
list.applyDiff(["e", "c", "a", "y", "x"]);
|
501
|
-
expect(list.
|
637
|
+
list.$jazz.applyDiff(["e", "c", "a", "y", "x"]);
|
638
|
+
expect(list.$jazz.raw.asArray()).toEqual(["e", "c", "a", "y", "x"]);
|
502
639
|
|
503
640
|
// Test partial update
|
504
|
-
list.applyDiff(["e", "c", "new", "y", "x"]);
|
505
|
-
expect(list.
|
641
|
+
list.$jazz.applyDiff(["e", "c", "new", "y", "x"]);
|
642
|
+
expect(list.$jazz.raw.asArray()).toEqual(["e", "c", "new", "y", "x"]);
|
506
643
|
});
|
507
644
|
});
|
508
645
|
|
@@ -539,9 +676,57 @@ describe("CoList resolution", async () => {
|
|
539
676
|
|
540
677
|
expect(list[0]?.[0]?.[0]).toBe("a");
|
541
678
|
expect(list[0]?.[0]?.join(",")).toBe("a,b");
|
542
|
-
expect(list[0]?.[0]
|
679
|
+
expect(list[0]?.[0]?.$jazz.id).toBeDefined();
|
543
680
|
expect(list[1]?.[0]?.[0]).toBe("c");
|
544
681
|
});
|
682
|
+
|
683
|
+
test("accessing the value refs", async () => {
|
684
|
+
const Dog = co.map({
|
685
|
+
name: z.string(),
|
686
|
+
breed: z.string(),
|
687
|
+
});
|
688
|
+
|
689
|
+
const Pets = co.list(Dog);
|
690
|
+
|
691
|
+
const group = Group.create();
|
692
|
+
group.addMember("everyone", "writer");
|
693
|
+
|
694
|
+
const pets = Pets.create([{ name: "Rex", breed: "Labrador" }], group);
|
695
|
+
|
696
|
+
const userB = await createJazzTestAccount();
|
697
|
+
const loadedPets = await Pets.load(pets.$jazz.id, {
|
698
|
+
loadAs: userB,
|
699
|
+
});
|
700
|
+
|
701
|
+
assert(loadedPets);
|
702
|
+
|
703
|
+
const petReference = loadedPets.$jazz.refs[0];
|
704
|
+
expect(petReference).toBeDefined();
|
705
|
+
expect(petReference?.id).toBe(pets[0]?.$jazz.id);
|
706
|
+
|
707
|
+
const dog = await petReference?.load();
|
708
|
+
|
709
|
+
assert(dog);
|
710
|
+
|
711
|
+
expect(dog.name).toEqual("Rex");
|
712
|
+
});
|
713
|
+
|
714
|
+
test("waitForSync should resolve when the value is uploaded", async () => {
|
715
|
+
const TestList = co.list(z.number());
|
716
|
+
|
717
|
+
const { clientNode, serverNode, clientAccount } = await setupTwoNodes();
|
718
|
+
|
719
|
+
const list = TestList.create([1, 2, 3], { owner: clientAccount });
|
720
|
+
|
721
|
+
await list.$jazz.waitForSync({ timeout: 1000 });
|
722
|
+
|
723
|
+
// Killing the client node so the serverNode can't load the list from it
|
724
|
+
clientNode.gracefulShutdown();
|
725
|
+
|
726
|
+
const loadedMap = await serverNode.load(list.$jazz.raw.id);
|
727
|
+
|
728
|
+
expect(loadedMap).not.toBe("unavailable");
|
729
|
+
});
|
545
730
|
});
|
546
731
|
|
547
732
|
describe("CoList subscription", async () => {
|
@@ -561,7 +746,7 @@ describe("CoList subscription", async () => {
|
|
561
746
|
const spy = vi.fn((list) => updates.push(list));
|
562
747
|
|
563
748
|
TestList.subscribe(
|
564
|
-
list.id,
|
749
|
+
list.$jazz.id,
|
565
750
|
{
|
566
751
|
resolve: {
|
567
752
|
$each: true,
|
@@ -579,7 +764,7 @@ describe("CoList subscription", async () => {
|
|
579
764
|
expect(updates[0]?.[0]?.name).toEqual("Item 1");
|
580
765
|
expect(updates[0]?.[1]?.name).toEqual("Item 2");
|
581
766
|
|
582
|
-
list[0]
|
767
|
+
list[0]!.$jazz.set("name", "Updated Item 1");
|
583
768
|
|
584
769
|
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
585
770
|
|
@@ -604,7 +789,7 @@ describe("CoList subscription", async () => {
|
|
604
789
|
const updates: Loaded<typeof TestList>[] = [];
|
605
790
|
const spy = vi.fn((list) => updates.push(list));
|
606
791
|
|
607
|
-
TestList.subscribe(list.id, {}, spy);
|
792
|
+
TestList.subscribe(list.$jazz.id, {}, spy);
|
608
793
|
|
609
794
|
expect(spy).not.toHaveBeenCalled();
|
610
795
|
|
@@ -615,7 +800,7 @@ describe("CoList subscription", async () => {
|
|
615
800
|
expect(updates[0]?.[0]?.name).toEqual("Item 1");
|
616
801
|
expect(updates[0]?.[1]?.name).toEqual("Item 2");
|
617
802
|
|
618
|
-
list[0]
|
803
|
+
list[0]!.$jazz.set("name", "Updated Item 1");
|
619
804
|
|
620
805
|
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
621
806
|
|
@@ -642,7 +827,7 @@ describe("CoList subscription", async () => {
|
|
642
827
|
|
643
828
|
subscribeToCoValue(
|
644
829
|
coValueClassFromCoValueClassOrSchema(TestList),
|
645
|
-
list.id,
|
830
|
+
list.$jazz.id,
|
646
831
|
{
|
647
832
|
syncResolution: true,
|
648
833
|
loadAs: Account.getMe(),
|
@@ -658,7 +843,7 @@ describe("CoList subscription", async () => {
|
|
658
843
|
|
659
844
|
expect(spy).toHaveBeenCalledTimes(1);
|
660
845
|
|
661
|
-
list[0]
|
846
|
+
list[0]!.$jazz.set("name", "Updated Item 1");
|
662
847
|
|
663
848
|
expect(spy).toHaveBeenCalledTimes(2);
|
664
849
|
|
@@ -692,7 +877,7 @@ describe("CoList subscription", async () => {
|
|
692
877
|
const spy = vi.fn((list) => updates.push(list));
|
693
878
|
|
694
879
|
TestList.subscribe(
|
695
|
-
list.id,
|
880
|
+
list.$jazz.id,
|
696
881
|
{
|
697
882
|
resolve: {
|
698
883
|
$each: true,
|
@@ -711,7 +896,7 @@ describe("CoList subscription", async () => {
|
|
711
896
|
expect(updates[0]?.[0]?.name).toEqual("Item 1");
|
712
897
|
expect(updates[0]?.[1]?.name).toEqual("Item 2");
|
713
898
|
|
714
|
-
list[0]
|
899
|
+
list[0]!.$jazz.set("name", "Updated Item 1");
|
715
900
|
|
716
901
|
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
717
902
|
|
@@ -745,7 +930,7 @@ describe("CoList subscription", async () => {
|
|
745
930
|
const userB = await createJazzTestAccount();
|
746
931
|
|
747
932
|
TestList.subscribe(
|
748
|
-
list.id,
|
933
|
+
list.$jazz.id,
|
749
934
|
{
|
750
935
|
loadAs: userB,
|
751
936
|
},
|
@@ -761,7 +946,7 @@ describe("CoList subscription", async () => {
|
|
761
946
|
expect(updates[0]?.[0]?.name).toEqual("Item 1");
|
762
947
|
expect(updates[0]?.[1]?.name).toEqual("Item 2");
|
763
948
|
|
764
|
-
list[0]
|
949
|
+
list[0]!.$jazz.set("name", "Updated Item 1");
|
765
950
|
|
766
951
|
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
767
952
|
|
@@ -787,7 +972,7 @@ describe("CoList subscription", async () => {
|
|
787
972
|
const spy = vi.fn((list) => updates.push(list));
|
788
973
|
|
789
974
|
TestList.subscribe(
|
790
|
-
list.id,
|
975
|
+
list.$jazz.id,
|
791
976
|
{
|
792
977
|
resolve: {
|
793
978
|
$each: true,
|
@@ -805,7 +990,7 @@ describe("CoList subscription", async () => {
|
|
805
990
|
expect(updates[0]?.[0]?.name).toEqual("Item 1");
|
806
991
|
expect(updates[0]?.[1]?.name).toEqual("Item 2");
|
807
992
|
|
808
|
-
list
|
993
|
+
list.$jazz.set(0, Item.create({ name: "New Item 1" }));
|
809
994
|
|
810
995
|
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
811
996
|
|
@@ -839,7 +1024,7 @@ describe("CoList subscription", async () => {
|
|
839
1024
|
const userB = await createJazzTestAccount();
|
840
1025
|
|
841
1026
|
TestList.subscribe(
|
842
|
-
list.id,
|
1027
|
+
list.$jazz.id,
|
843
1028
|
{
|
844
1029
|
loadAs: userB,
|
845
1030
|
resolve: {
|
@@ -860,7 +1045,7 @@ describe("CoList subscription", async () => {
|
|
860
1045
|
|
861
1046
|
expect(spy).toHaveBeenCalledTimes(1);
|
862
1047
|
|
863
|
-
list.push(Item.create({ name: "Item 3" }, group));
|
1048
|
+
list.$jazz.push(Item.create({ name: "Item 3" }, group));
|
864
1049
|
|
865
1050
|
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
866
1051
|
|
@@ -893,7 +1078,7 @@ describe("CoList subscription", async () => {
|
|
893
1078
|
|
894
1079
|
const bob = await createJazzTestAccount();
|
895
1080
|
|
896
|
-
const loadedPerson = await Person.load(person.id, {
|
1081
|
+
const loadedPerson = await Person.load(person.$jazz.id, {
|
897
1082
|
resolve: { dogs: { $onError: null } },
|
898
1083
|
loadAs: bob,
|
899
1084
|
});
|
@@ -914,7 +1099,7 @@ describe("CoList unique methods", () => {
|
|
914
1099
|
unique: "test-list",
|
915
1100
|
});
|
916
1101
|
|
917
|
-
const foundList = await ItemList.loadUnique("test-list", group.id);
|
1102
|
+
const foundList = await ItemList.loadUnique("test-list", group.$jazz.id);
|
918
1103
|
expect(foundList).toEqual(originalList);
|
919
1104
|
expect(foundList?.length).toBe(3);
|
920
1105
|
expect(foundList?.[0]).toBe("item1");
|
@@ -924,7 +1109,7 @@ describe("CoList unique methods", () => {
|
|
924
1109
|
const ItemList = co.list(z.string());
|
925
1110
|
const group = Group.create();
|
926
1111
|
|
927
|
-
const foundList = await ItemList.loadUnique("non-existent", group.id);
|
1112
|
+
const foundList = await ItemList.loadUnique("non-existent", group.$jazz.id);
|
928
1113
|
expect(foundList).toBeNull();
|
929
1114
|
});
|
930
1115
|
|
@@ -967,7 +1152,7 @@ describe("CoList unique methods", () => {
|
|
967
1152
|
expect(result?.[1]).toBe("item2");
|
968
1153
|
expect(result?.[2]).toBe("item3");
|
969
1154
|
|
970
|
-
expect(result
|
1155
|
+
expect(result?.$jazz.owner).toEqual(account);
|
971
1156
|
});
|
972
1157
|
|
973
1158
|
test("upsertUnique updates existing list", async () => {
|
@@ -1063,8 +1248,8 @@ describe("CoList unique methods", () => {
|
|
1063
1248
|
unique: "find-test",
|
1064
1249
|
});
|
1065
1250
|
|
1066
|
-
const foundId = ItemList.findUnique("find-test", group.id);
|
1067
|
-
expect(foundId).toBe(originalList.id);
|
1251
|
+
const foundId = ItemList.findUnique("find-test", group.$jazz.id);
|
1252
|
+
expect(foundId).toBe(originalList.$jazz.id);
|
1068
1253
|
});
|
1069
1254
|
|
1070
1255
|
test("upsertUnique with resolve options", async () => {
|