jazz-tools 0.18.38 → 0.19.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.d.ts +8 -8
- package/.svelte-kit/__package__/jazz.class.svelte.d.ts.map +1 -1
- package/.svelte-kit/__package__/jazz.class.svelte.js +39 -14
- package/.svelte-kit/__package__/media/image.svelte +6 -5
- package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
- package/.svelte-kit/__package__/tests/AccountCoState.svelte.test-d.d.ts +2 -0
- package/.svelte-kit/__package__/tests/AccountCoState.svelte.test-d.d.ts.map +1 -0
- package/.svelte-kit/__package__/tests/AccountCoState.svelte.test-d.js +19 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test-d.d.ts +2 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test-d.d.ts.map +1 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test-d.js +16 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test.d.ts +2 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test.d.ts.map +1 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test.js +42 -0
- package/.svelte-kit/__package__/tests/TestCoStateWrapper.svelte +23 -0
- package/.svelte-kit/__package__/tests/TestCoStateWrapper.svelte.d.ts +12 -0
- package/.svelte-kit/__package__/tests/TestCoStateWrapper.svelte.d.ts.map +1 -0
- package/.turbo/turbo-build.log +62 -62
- package/CHANGELOG.md +32 -0
- package/dist/better-auth/database-adapter/index.js +14 -11
- package/dist/better-auth/database-adapter/index.js.map +1 -1
- package/dist/better-auth/database-adapter/repository/generic.d.ts +1 -1
- package/dist/better-auth/database-adapter/repository/generic.d.ts.map +1 -1
- package/dist/better-auth/database-adapter/repository/user.d.ts.map +1 -1
- package/dist/{chunk-OSQ7S47Q.js → chunk-NCNM6UDZ.js} +563 -252
- package/dist/chunk-NCNM6UDZ.js.map +1 -0
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/media/{chunk-K6GCHLQU.js → chunk-3LKBM3G3.js} +23 -15
- package/dist/media/chunk-3LKBM3G3.js.map +1 -0
- package/dist/media/create-image/browser.d.ts +2 -2
- package/dist/media/create-image/react-native.d.ts +2 -2
- package/dist/media/create-image/server.d.ts +2 -2
- package/dist/media/create-image-factory.d.ts +2 -2
- package/dist/media/index.browser.js +1 -1
- package/dist/media/index.js +1 -1
- package/dist/media/index.native.js +1 -1
- package/dist/media/index.server.js +1 -1
- package/dist/media/utils.d.ts.map +1 -1
- package/dist/react/hooks.d.ts +1 -1
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +31 -15
- package/dist/react/index.js.map +1 -1
- package/dist/react/media/image.d.ts.map +1 -1
- package/dist/react-core/hooks.d.ts +126 -224
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +65 -63
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/subscription-provider.d.ts.map +1 -1
- package/dist/react-core/tests/createCoValueSubscriptionContext.test.d.ts +2 -0
- package/dist/react-core/tests/createCoValueSubscriptionContext.test.d.ts.map +1 -0
- package/dist/react-core/tests/useAccount.selector.test.d.ts +2 -0
- package/dist/react-core/tests/useAccount.selector.test.d.ts.map +1 -0
- package/dist/react-core/tests/useCoState.selector.test.d.ts +2 -0
- package/dist/react-core/tests/useCoState.selector.test.d.ts.map +1 -0
- package/dist/react-native-core/hooks.d.ts +1 -1
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-core/index.js +7 -5
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/react-native-core/media/image.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.d.ts +8 -8
- package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +39 -14
- package/dist/svelte/media/image.svelte +6 -5
- package/dist/svelte/media/image.svelte.d.ts.map +1 -1
- package/dist/svelte/tests/AccountCoState.svelte.test-d.d.ts +2 -0
- package/dist/svelte/tests/AccountCoState.svelte.test-d.d.ts.map +1 -0
- package/dist/svelte/tests/AccountCoState.svelte.test-d.js +19 -0
- package/dist/svelte/tests/CoState.svelte.test-d.d.ts +2 -0
- package/dist/svelte/tests/CoState.svelte.test-d.d.ts.map +1 -0
- package/dist/svelte/tests/CoState.svelte.test-d.js +16 -0
- package/dist/svelte/tests/CoState.svelte.test.d.ts +2 -0
- package/dist/svelte/tests/CoState.svelte.test.d.ts.map +1 -0
- package/dist/svelte/tests/CoState.svelte.test.js +42 -0
- package/dist/svelte/tests/TestCoStateWrapper.svelte +23 -0
- package/dist/svelte/tests/TestCoStateWrapper.svelte.d.ts +12 -0
- package/dist/svelte/tests/TestCoStateWrapper.svelte.d.ts.map +1 -0
- package/dist/testing.js +3 -1
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/CoValueBase.d.ts +4 -1
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
- package/dist/tools/coValues/account.d.ts +6 -6
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts +5 -5
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts +9 -8
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts +17 -17
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/coPlainText.d.ts +3 -3
- package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
- package/dist/tools/coValues/coVector.d.ts +3 -3
- package/dist/tools/coValues/coVector.d.ts.map +1 -1
- package/dist/tools/coValues/deepLoading.d.ts +71 -40
- package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
- package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
- package/dist/tools/coValues/extensions/imageDef.d.ts.map +1 -1
- package/dist/tools/coValues/group.d.ts +2 -2
- 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 +17 -9
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/request.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +6 -9
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +3 -3
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/refs.d.ts +3 -3
- package/dist/tools/implementation/refs.d.ts.map +1 -1
- package/dist/tools/implementation/schema.d.ts +2 -2
- package/dist/tools/implementation/schema.d.ts.map +1 -1
- package/dist/tools/implementation/schemaUtils.d.ts +8 -0
- package/dist/tools/implementation/schemaUtils.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +33 -18
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +19 -7
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +23 -12
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +29 -18
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +39 -22
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +30 -19
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts +5 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +6 -5
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +3 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +3 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +3 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +3 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +3 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.d.ts +22 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +4 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.d.ts +9 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts +7 -6
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +3 -3
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/lib/utils.d.ts +14 -0
- package/dist/tools/lib/utils.d.ts.map +1 -0
- package/dist/tools/lib/utils.test.d.ts +2 -0
- package/dist/tools/lib/utils.test.d.ts.map +1 -0
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +3 -2
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
- package/dist/tools/subscribe/JazzError.d.ts +4 -3
- package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts +7 -5
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/index.d.ts.map +1 -1
- package/dist/tools/subscribe/types.d.ts +23 -3
- package/dist/tools/subscribe/types.d.ts.map +1 -1
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts +3 -2
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/schema.resolved.test.d.ts +2 -0
- package/dist/tools/tests/schema.resolved.test.d.ts.map +1 -0
- package/dist/tools/tests/utils.d.ts +2 -1
- package/dist/tools/tests/utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/better-auth/database-adapter/index.ts +2 -2
- package/src/better-auth/database-adapter/repository/account.ts +3 -3
- package/src/better-auth/database-adapter/repository/generic.ts +9 -6
- package/src/better-auth/database-adapter/repository/user.ts +6 -2
- package/src/better-auth/database-adapter/schema.ts +1 -1
- package/src/better-auth/database-adapter/tests/index.test.ts +3 -4
- package/src/inspector/tests/viewer/history-view.test.tsx +6 -2
- package/src/media/utils.test.ts +5 -0
- package/src/media/utils.ts +25 -16
- package/src/react/hooks.tsx +2 -2
- package/src/react/index.ts +2 -2
- package/src/react/media/image.tsx +10 -2
- package/src/react/tests/useAcceptInvite.test.ts +3 -1
- package/src/react-core/hooks.ts +226 -304
- package/src/react-core/subscription-provider.tsx +14 -7
- package/src/react-core/tests/createCoValueSubscriptionContext.test.tsx +233 -0
- package/src/react-core/tests/subscription.bench.tsx +32 -15
- package/src/react-core/tests/{useAccountWithSelector.test.ts → useAccount.selector.test.ts} +72 -24
- package/src/react-core/tests/useAccount.test.ts +92 -106
- package/src/react-core/tests/{useCoStateWithSelector.test.ts → useCoState.selector.test.ts} +23 -8
- package/src/react-core/tests/useCoState.test.ts +173 -49
- package/src/react-core/tests/useInboxSender.test.ts +3 -1
- package/src/react-core/tests/usePassPhraseAuth.test.ts +11 -82
- package/src/react-core/tests/useSubscriptionSelector.test.ts +48 -14
- package/src/react-native-core/hooks.tsx +2 -2
- package/src/react-native-core/media/image.tsx +3 -1
- package/src/svelte/jazz.class.svelte.ts +103 -27
- package/src/svelte/media/image.svelte +6 -5
- package/src/svelte/tests/AccountCoState.svelte.test-d.ts +23 -0
- package/src/svelte/tests/CoState.svelte.test-d.ts +20 -0
- package/src/svelte/tests/CoState.svelte.test.ts +57 -0
- package/src/svelte/tests/TestCoStateWrapper.svelte +23 -0
- package/src/tools/coValues/CoValueBase.ts +12 -0
- package/src/tools/coValues/account.ts +17 -12
- package/src/tools/coValues/coFeed.ts +38 -15
- package/src/tools/coValues/coList.ts +17 -12
- package/src/tools/coValues/coMap.ts +15 -14
- package/src/tools/coValues/coPlainText.ts +6 -3
- package/src/tools/coValues/coVector.ts +6 -5
- package/src/tools/coValues/deepLoading.ts +147 -86
- package/src/tools/coValues/group.ts +3 -2
- package/src/tools/coValues/inbox.ts +11 -10
- package/src/tools/coValues/interfaces.ts +52 -30
- package/src/tools/coValues/request.ts +8 -6
- package/src/tools/coValues/schemaUnion.ts +20 -14
- package/src/tools/exports.ts +11 -1
- package/src/tools/implementation/refs.ts +19 -13
- package/src/tools/implementation/schema.ts +5 -4
- package/src/tools/implementation/schemaUtils.ts +15 -0
- package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +4 -4
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +131 -95
- package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +86 -16
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +73 -22
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +86 -28
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +204 -148
- package/src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts +1 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +71 -27
- package/src/tools/implementation/zodSchema/schemaTypes/CoValueSchema.ts +7 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +8 -6
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +4 -1
- package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +4 -1
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +4 -1
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +4 -1
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +3 -0
- package/src/tools/implementation/zodSchema/typeConverters/{InstanceOfSchemaCoValuesNullable.ts → InstanceOfSchemaCoValuesMaybeLoaded.ts} +47 -39
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +4 -0
- package/src/tools/implementation/zodSchema/typeConverters/{InstanceOrPrimitiveOfSchemaCoValuesNullable.ts → InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.ts} +7 -3
- package/src/tools/implementation/zodSchema/unionUtils.ts +35 -4
- package/src/tools/implementation/zodSchema/zodSchema.ts +15 -7
- package/src/tools/internal.ts +3 -3
- package/src/tools/lib/utils.test.ts +56 -0
- package/src/tools/lib/utils.ts +32 -0
- package/src/tools/subscribe/CoValueCoreSubscription.ts +13 -8
- package/src/tools/subscribe/JazzError.ts +8 -2
- package/src/tools/subscribe/SubscriptionScope.ts +57 -57
- package/src/tools/subscribe/index.ts +12 -4
- package/src/tools/subscribe/types.ts +36 -2
- package/src/tools/subscribe/utils.ts +2 -1
- package/src/tools/testing.ts +5 -0
- package/src/tools/tests/CoValueCoreSubscription.test.ts +10 -4
- package/src/tools/tests/ContextManager.test.ts +12 -5
- package/src/tools/tests/account.test.ts +22 -12
- package/src/tools/tests/coDiscriminatedUnion.test.ts +354 -8
- package/src/tools/tests/coFeed.branch.test.ts +48 -32
- package/src/tools/tests/coFeed.test-d.ts +17 -10
- package/src/tools/tests/coFeed.test.ts +52 -30
- package/src/tools/tests/coList.branch.test.ts +21 -21
- package/src/tools/tests/coList.test-d.ts +39 -23
- package/src/tools/tests/coList.test.ts +51 -25
- package/src/tools/tests/coList.unique.test.ts +34 -29
- package/src/tools/tests/coMap.branch.test.ts +20 -21
- package/src/tools/tests/coMap.record.test-d.ts +28 -26
- package/src/tools/tests/coMap.record.test.ts +30 -20
- package/src/tools/tests/coMap.test-d.ts +31 -29
- package/src/tools/tests/coMap.test.ts +67 -40
- package/src/tools/tests/coMap.unique.test.ts +25 -24
- package/src/tools/tests/coVector.test.ts +29 -15
- package/src/tools/tests/createContext.test.ts +5 -3
- package/src/tools/tests/deepLoading.test.ts +369 -176
- package/src/tools/tests/exportImport.test.ts +16 -15
- package/src/tools/tests/groupsAndAccounts.test.ts +39 -16
- package/src/tools/tests/inbox.test.ts +3 -1
- package/src/tools/tests/load.test.ts +29 -23
- package/src/tools/tests/patterns/quest.test.ts +3 -2
- package/src/tools/tests/patterns/requestToJoin.test.ts +17 -17
- package/src/tools/tests/request.test.ts +12 -2
- package/src/tools/tests/schema.resolved.test.ts +792 -0
- package/src/tools/tests/schemaUnion.test.ts +7 -3
- package/src/tools/tests/subscribe.test.ts +39 -21
- package/src/tools/tests/testing.test.ts +3 -2
- package/src/tools/tests/utils.ts +15 -2
- package/dist/chunk-OSQ7S47Q.js.map +0 -1
- package/dist/media/chunk-K6GCHLQU.js.map +0 -1
- package/dist/react-core/tests/useAccountWithSelector.test.d.ts +0 -2
- package/dist/react-core/tests/useAccountWithSelector.test.d.ts.map +0 -1
- package/dist/react-core/tests/useCoStateWithSelector.test.d.ts +0 -2
- package/dist/react-core/tests/useCoStateWithSelector.test.d.ts.map +0 -1
- package/dist/tools/implementation/errors.d.ts +0 -2
- package/dist/tools/implementation/errors.d.ts.map +0 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +0 -19
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +0 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +0 -5
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +0 -1
- package/dist/tools/lib/id.d.ts +0 -2
- package/dist/tools/lib/id.d.ts.map +0 -1
- package/src/tools/implementation/errors.ts +0 -1
- package/src/tools/lib/id.ts +0 -3
|
@@ -3,7 +3,7 @@ import { assert, beforeEach, describe, expect, test, vi } from "vitest";
|
|
|
3
3
|
import { Group, co, z } from "../exports.js";
|
|
4
4
|
|
|
5
5
|
import { createJazzTestAccount, setupJazzTestSync } from "../testing.js";
|
|
6
|
-
import { waitFor } from "./utils.js";
|
|
6
|
+
import { assertLoaded, waitFor } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
beforeEach(async () => {
|
|
9
9
|
cojsonInternals.CO_VALUE_LOADING_CONFIG.RETRY_DELAY = 1000;
|
|
@@ -36,7 +36,7 @@ describe("CoList Branching", async () => {
|
|
|
36
36
|
unstable_branch: { name: "feature-branch" },
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
assertLoaded(branchList);
|
|
40
40
|
|
|
41
41
|
// Edit the branch
|
|
42
42
|
branchList.$jazz.set(0, "Buy organic groceries");
|
|
@@ -83,7 +83,7 @@ describe("CoList Branching", async () => {
|
|
|
83
83
|
unstable_branch: { name: "feature-branch" },
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
assertLoaded(branchList);
|
|
87
87
|
|
|
88
88
|
// Edit the branch
|
|
89
89
|
branchList.$jazz.set(0, "Buy organic groceries");
|
|
@@ -130,7 +130,7 @@ describe("CoList Branching", async () => {
|
|
|
130
130
|
unstable_branch: { name: "no-changes-branch" },
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
assertLoaded(branchList);
|
|
134
134
|
|
|
135
135
|
// Verify branch has same values as original
|
|
136
136
|
expect(branchList[0]).toBe("Buy groceries");
|
|
@@ -164,7 +164,7 @@ describe("CoList Branching", async () => {
|
|
|
164
164
|
unstable_branch: { name: "shared-branch" },
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
assertLoaded(branch1);
|
|
168
168
|
|
|
169
169
|
branch1.$jazz.set(0, "Buy organic groceries");
|
|
170
170
|
branch1.$jazz.push("Call mom");
|
|
@@ -174,7 +174,7 @@ describe("CoList Branching", async () => {
|
|
|
174
174
|
unstable_branch: { name: "shared-branch" },
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
assertLoaded(branch2);
|
|
178
178
|
|
|
179
179
|
// Both branches should have the same changes
|
|
180
180
|
expect(branch1[0]).toBe("Buy organic groceries");
|
|
@@ -219,7 +219,7 @@ describe("CoList Branching", async () => {
|
|
|
219
219
|
loadAs: alice,
|
|
220
220
|
});
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
assertLoaded(branch1);
|
|
223
223
|
|
|
224
224
|
originalList.$jazz.set(0, "Buy organic groceries");
|
|
225
225
|
originalList.$jazz.push("Call mom");
|
|
@@ -230,7 +230,7 @@ describe("CoList Branching", async () => {
|
|
|
230
230
|
loadAs: bob,
|
|
231
231
|
});
|
|
232
232
|
|
|
233
|
-
|
|
233
|
+
assertLoaded(branch2);
|
|
234
234
|
|
|
235
235
|
// Both branches should have the same changes
|
|
236
236
|
expect(branch1[0]).toBe("Buy groceries");
|
|
@@ -280,7 +280,7 @@ describe("CoList Branching", async () => {
|
|
|
280
280
|
unstable_branch: { name: "double-merge-branch" },
|
|
281
281
|
});
|
|
282
282
|
|
|
283
|
-
|
|
283
|
+
assertLoaded(branch);
|
|
284
284
|
|
|
285
285
|
branch.$jazz.set(0, "Buy organic groceries");
|
|
286
286
|
branch.$jazz.push("Call mom");
|
|
@@ -324,7 +324,7 @@ describe("CoList Branching", async () => {
|
|
|
324
324
|
loadAs: alice,
|
|
325
325
|
});
|
|
326
326
|
|
|
327
|
-
|
|
327
|
+
assertLoaded(branch1);
|
|
328
328
|
|
|
329
329
|
branch1.$jazz.set(0, "Buy organic groceries");
|
|
330
330
|
|
|
@@ -334,7 +334,7 @@ describe("CoList Branching", async () => {
|
|
|
334
334
|
loadAs: bob,
|
|
335
335
|
});
|
|
336
336
|
|
|
337
|
-
|
|
337
|
+
assertLoaded(branch2);
|
|
338
338
|
|
|
339
339
|
branch2.$jazz.set(1, "Walk the cat");
|
|
340
340
|
branch2.$jazz.push("Schedule dentist");
|
|
@@ -385,7 +385,7 @@ describe("CoList Branching", async () => {
|
|
|
385
385
|
unstable_branch: { name: "load-by-id-branch" },
|
|
386
386
|
});
|
|
387
387
|
|
|
388
|
-
|
|
388
|
+
assertLoaded(branch);
|
|
389
389
|
|
|
390
390
|
expect(branch.$jazz.id).toBe(originalList.$jazz.id);
|
|
391
391
|
});
|
|
@@ -406,7 +406,7 @@ describe("CoList Branching", async () => {
|
|
|
406
406
|
unstable_branch: { name: "conflict-branch" },
|
|
407
407
|
});
|
|
408
408
|
|
|
409
|
-
|
|
409
|
+
assertLoaded(branch);
|
|
410
410
|
|
|
411
411
|
branch.$jazz.set(0, "Buy organic groceries");
|
|
412
412
|
branch.$jazz.set(1, "Walk the cat");
|
|
@@ -445,7 +445,7 @@ describe("CoList Branching", async () => {
|
|
|
445
445
|
unstable_branch: { name: "align-branch" },
|
|
446
446
|
});
|
|
447
447
|
|
|
448
|
-
|
|
448
|
+
assertLoaded(branch);
|
|
449
449
|
|
|
450
450
|
branch.$jazz.set(0, "Buy organic groceries");
|
|
451
451
|
|
|
@@ -463,7 +463,7 @@ describe("CoList Branching", async () => {
|
|
|
463
463
|
unstable_branch: { name: "align-branch" },
|
|
464
464
|
});
|
|
465
465
|
|
|
466
|
-
|
|
466
|
+
assertLoaded(loadedBranch);
|
|
467
467
|
|
|
468
468
|
expect(loadedBranch[0]).toBe("Buy organic groceries");
|
|
469
469
|
expect(loadedBranch[1]).toBe("Walk the dog");
|
|
@@ -503,7 +503,7 @@ describe("CoList Branching", async () => {
|
|
|
503
503
|
unstable_branch: { name: "task-list-edit" },
|
|
504
504
|
});
|
|
505
505
|
|
|
506
|
-
|
|
506
|
+
assertLoaded(branch);
|
|
507
507
|
|
|
508
508
|
// Make extensive changes to the branch
|
|
509
509
|
branch.$jazz.set(0, {
|
|
@@ -529,7 +529,7 @@ describe("CoList Branching", async () => {
|
|
|
529
529
|
},
|
|
530
530
|
});
|
|
531
531
|
|
|
532
|
-
|
|
532
|
+
assertLoaded(loadedTaskList);
|
|
533
533
|
|
|
534
534
|
// Verify original is unchanged
|
|
535
535
|
expect(loadedTaskList[0]!.title).toBe("Buy groceries");
|
|
@@ -592,7 +592,7 @@ describe("CoList Branching", async () => {
|
|
|
592
592
|
unstable_branch: { name: "subscribe-branch" },
|
|
593
593
|
});
|
|
594
594
|
|
|
595
|
-
|
|
595
|
+
assertLoaded(branch);
|
|
596
596
|
|
|
597
597
|
const spy = vi.fn();
|
|
598
598
|
branch.$jazz.subscribe(
|
|
@@ -666,7 +666,7 @@ describe("CoList Branching", async () => {
|
|
|
666
666
|
unstable_branch: { name: "ensure-loaded-branch" },
|
|
667
667
|
});
|
|
668
668
|
|
|
669
|
-
|
|
669
|
+
assertLoaded(branch);
|
|
670
670
|
|
|
671
671
|
branch.$jazz.set(0, {
|
|
672
672
|
title: "Buy organic groceries",
|
|
@@ -737,7 +737,7 @@ describe("CoList Branching", async () => {
|
|
|
737
737
|
unstable_branch: { name: "schema-subscribe-branch" },
|
|
738
738
|
});
|
|
739
739
|
|
|
740
|
-
|
|
740
|
+
assertLoaded(branch);
|
|
741
741
|
|
|
742
742
|
branch.$jazz.set(0, {
|
|
743
743
|
title: "Buy organic groceries",
|
|
@@ -751,7 +751,7 @@ describe("CoList Branching", async () => {
|
|
|
751
751
|
});
|
|
752
752
|
|
|
753
753
|
// Subscribe using Schema.subscribe with branch
|
|
754
|
-
const updates: co.loaded<typeof TaskList, true>[] = [];
|
|
754
|
+
const updates: co.loaded<typeof TaskList, { $each: true }>[] = [];
|
|
755
755
|
const unsubscribe = TaskList.subscribe(
|
|
756
756
|
originalTaskList.$jazz.id,
|
|
757
757
|
{
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { assert, describe, expectTypeOf, test } from "vitest";
|
|
2
2
|
import { Group, co, z } from "../exports.js";
|
|
3
3
|
import { Account } from "../index.js";
|
|
4
|
-
import { CoList, CoMap, Loaded } from "../internal.js";
|
|
4
|
+
import { CoList, CoMap, Loaded, MaybeLoaded } from "../internal.js";
|
|
5
|
+
import { assertLoaded } from "./utils.js";
|
|
5
6
|
|
|
6
7
|
describe("CoList", () => {
|
|
7
8
|
describe("init", () => {
|
|
@@ -199,7 +200,7 @@ describe("CoList", () => {
|
|
|
199
200
|
},
|
|
200
201
|
});
|
|
201
202
|
|
|
202
|
-
type ExpectedType = ReadonlyArray<Loaded<typeof Dog
|
|
203
|
+
type ExpectedType = MaybeLoaded<ReadonlyArray<Loaded<typeof Dog>>>;
|
|
203
204
|
|
|
204
205
|
function matches(value: ExpectedType) {
|
|
205
206
|
return value;
|
|
@@ -207,7 +208,7 @@ describe("CoList", () => {
|
|
|
207
208
|
|
|
208
209
|
matches(loadedList);
|
|
209
210
|
|
|
210
|
-
|
|
211
|
+
assertLoaded(loadedList);
|
|
211
212
|
const firstDog = loadedList[0];
|
|
212
213
|
assert(firstDog);
|
|
213
214
|
expectTypeOf(firstDog.name).toEqualTypeOf<string>();
|
|
@@ -228,11 +229,13 @@ describe("CoList", () => {
|
|
|
228
229
|
|
|
229
230
|
const loadedList = await DogList.load(list.$jazz.id, {
|
|
230
231
|
resolve: {
|
|
231
|
-
$each: { $onError:
|
|
232
|
+
$each: { $onError: "catch" },
|
|
232
233
|
},
|
|
233
234
|
});
|
|
234
235
|
|
|
235
|
-
type ExpectedType =
|
|
236
|
+
type ExpectedType = MaybeLoaded<
|
|
237
|
+
ReadonlyArray<MaybeLoaded<Loaded<typeof Dog>>>
|
|
238
|
+
>;
|
|
236
239
|
|
|
237
240
|
function matches(value: ExpectedType) {
|
|
238
241
|
return value;
|
|
@@ -265,9 +268,9 @@ describe("CoList", () => {
|
|
|
265
268
|
},
|
|
266
269
|
});
|
|
267
270
|
|
|
268
|
-
type ExpectedType =
|
|
269
|
-
ReadonlyArray<Loaded<typeof Dog
|
|
270
|
-
|
|
271
|
+
type ExpectedType = MaybeLoaded<
|
|
272
|
+
ReadonlyArray<ReadonlyArray<Loaded<typeof Dog>>>
|
|
273
|
+
>;
|
|
271
274
|
|
|
272
275
|
function matches(value: ExpectedType) {
|
|
273
276
|
return value;
|
|
@@ -275,7 +278,7 @@ describe("CoList", () => {
|
|
|
275
278
|
|
|
276
279
|
matches(loadedList);
|
|
277
280
|
|
|
278
|
-
|
|
281
|
+
assertLoaded(loadedList);
|
|
279
282
|
const firstList = loadedList[0];
|
|
280
283
|
assert(firstList);
|
|
281
284
|
const firstDog = firstList[0];
|
|
@@ -305,22 +308,23 @@ describe("CoList", () => {
|
|
|
305
308
|
});
|
|
306
309
|
|
|
307
310
|
const loadedPerson = await Person.load(person.$jazz.id, {
|
|
308
|
-
resolve: { dogs: { $onError:
|
|
311
|
+
resolve: { dogs: { $onError: "catch" } },
|
|
309
312
|
});
|
|
310
313
|
|
|
311
|
-
type ExpectedType =
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
>
|
|
322
|
-
|
|
323
|
-
|
|
314
|
+
type ExpectedType = MaybeLoaded<
|
|
315
|
+
{
|
|
316
|
+
name: string;
|
|
317
|
+
age: number;
|
|
318
|
+
dogs: MaybeLoaded<
|
|
319
|
+
CoList<
|
|
320
|
+
{
|
|
321
|
+
name: string;
|
|
322
|
+
breed: string;
|
|
323
|
+
} & CoMap
|
|
324
|
+
>
|
|
325
|
+
>;
|
|
326
|
+
} & CoMap
|
|
327
|
+
>;
|
|
324
328
|
|
|
325
329
|
function matches(value: ExpectedType) {
|
|
326
330
|
return value;
|
|
@@ -328,5 +332,17 @@ describe("CoList", () => {
|
|
|
328
332
|
|
|
329
333
|
matches(loadedPerson);
|
|
330
334
|
});
|
|
335
|
+
|
|
336
|
+
test("cannot use $each is resolve queries of CoLists that contains non-collaborative values", () => {
|
|
337
|
+
const ListOfNumbers = co.list(z.number());
|
|
338
|
+
ListOfNumbers.load("list-id", {
|
|
339
|
+
resolve: {
|
|
340
|
+
// @ts-expect-error `$each` is not allowd
|
|
341
|
+
$each: true,
|
|
342
|
+
// `$onError` is allowed
|
|
343
|
+
$onError: "catch",
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
});
|
|
331
347
|
});
|
|
332
348
|
});
|
|
@@ -6,13 +6,14 @@ import {
|
|
|
6
6
|
activeAccountContext,
|
|
7
7
|
co,
|
|
8
8
|
coValueClassFromCoValueClassOrSchema,
|
|
9
|
+
CoValueLoadingState,
|
|
9
10
|
} from "../internal.js";
|
|
10
11
|
import {
|
|
11
12
|
createJazzTestAccount,
|
|
12
13
|
runWithoutActiveAccount,
|
|
13
14
|
setupJazzTestSync,
|
|
14
15
|
} from "../testing.js";
|
|
15
|
-
import { setupTwoNodes, waitFor } from "./utils.js";
|
|
16
|
+
import { assertLoaded, setupTwoNodes, waitFor } from "./utils.js";
|
|
16
17
|
|
|
17
18
|
const Crypto = await WasmCrypto.create();
|
|
18
19
|
|
|
@@ -275,8 +276,8 @@ describe("Simple CoList operations", async () => {
|
|
|
275
276
|
resolve: { $each: { title: true } },
|
|
276
277
|
});
|
|
277
278
|
|
|
278
|
-
|
|
279
|
-
|
|
279
|
+
assertLoaded(loadedTask);
|
|
280
|
+
assertLoaded(loadedTaskList);
|
|
280
281
|
// @ts-expect-error loadedTask may not have its `title` loaded
|
|
281
282
|
loadedTaskList.$jazz.push(loadedTask);
|
|
282
283
|
// In this case the title is loaded, so the assertion passes
|
|
@@ -467,7 +468,7 @@ describe("Simple CoList operations", async () => {
|
|
|
467
468
|
const onion = list[2];
|
|
468
469
|
|
|
469
470
|
const shallowlyLoadedList = await NestedList.load(list.$jazz.id);
|
|
470
|
-
|
|
471
|
+
assertLoaded(shallowlyLoadedList);
|
|
471
472
|
|
|
472
473
|
const loadedList = await shallowlyLoadedList.$jazz.ensureLoaded({
|
|
473
474
|
resolve: { $each: true },
|
|
@@ -771,16 +772,15 @@ describe("CoList resolution", async () => {
|
|
|
771
772
|
loadAs: userB,
|
|
772
773
|
});
|
|
773
774
|
|
|
774
|
-
|
|
775
|
+
assertLoaded(loadedPets);
|
|
775
776
|
|
|
776
777
|
const petReference = loadedPets.$jazz.refs[0];
|
|
777
|
-
|
|
778
|
-
expect(petReference
|
|
778
|
+
assert(petReference);
|
|
779
|
+
expect(petReference.id).toBe(pets[0]?.$jazz.id);
|
|
779
780
|
|
|
780
|
-
const dog = await petReference
|
|
781
|
-
|
|
782
|
-
assert(dog);
|
|
781
|
+
const dog = await petReference.load();
|
|
783
782
|
|
|
783
|
+
assertLoaded(dog);
|
|
784
784
|
expect(dog.name).toEqual("Rex");
|
|
785
785
|
});
|
|
786
786
|
|
|
@@ -798,7 +798,7 @@ describe("CoList resolution", async () => {
|
|
|
798
798
|
|
|
799
799
|
const loadedMap = await serverNode.load(list.$jazz.raw.id);
|
|
800
800
|
|
|
801
|
-
expect(loadedMap).not.toBe(
|
|
801
|
+
expect(loadedMap).not.toBe(CoValueLoadingState.UNAVAILABLE);
|
|
802
802
|
});
|
|
803
803
|
});
|
|
804
804
|
|
|
@@ -870,15 +870,23 @@ describe("CoList subscription", async () => {
|
|
|
870
870
|
|
|
871
871
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
872
872
|
|
|
873
|
-
|
|
873
|
+
assert(updates[0]?.[0]);
|
|
874
|
+
assertLoaded(updates[0][0]);
|
|
875
|
+
expect(updates[0][0].name).toEqual("Item 1");
|
|
876
|
+
assert(updates[0]?.[1]);
|
|
877
|
+
assertLoaded(updates[0][1]);
|
|
874
878
|
expect(updates[0]?.[1]?.name).toEqual("Item 2");
|
|
875
879
|
|
|
876
880
|
list[0]!.$jazz.set("name", "Updated Item 1");
|
|
877
881
|
|
|
878
882
|
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
|
879
883
|
|
|
880
|
-
|
|
881
|
-
|
|
884
|
+
assert(updates[1]?.[0]);
|
|
885
|
+
assertLoaded(updates[1][0]);
|
|
886
|
+
expect(updates[1][0].name).toEqual("Updated Item 1");
|
|
887
|
+
assert(updates[1]?.[1]);
|
|
888
|
+
assertLoaded(updates[1][1]);
|
|
889
|
+
expect(updates[1][1].name).toEqual("Item 2");
|
|
882
890
|
|
|
883
891
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
884
892
|
});
|
|
@@ -911,8 +919,12 @@ describe("CoList subscription", async () => {
|
|
|
911
919
|
expect(spy).toHaveBeenCalled();
|
|
912
920
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
913
921
|
|
|
914
|
-
|
|
915
|
-
|
|
922
|
+
assert(updates[0]?.[0]);
|
|
923
|
+
assertLoaded(updates[0][0]);
|
|
924
|
+
expect(updates[0][0].name).toEqual("Item 1");
|
|
925
|
+
assert(updates[0]?.[1]);
|
|
926
|
+
assertLoaded(updates[0][1]);
|
|
927
|
+
expect(updates[0][1].name).toEqual("Item 2");
|
|
916
928
|
|
|
917
929
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
918
930
|
|
|
@@ -920,8 +932,12 @@ describe("CoList subscription", async () => {
|
|
|
920
932
|
|
|
921
933
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
922
934
|
|
|
923
|
-
|
|
924
|
-
|
|
935
|
+
assert(updates[1]?.[0]);
|
|
936
|
+
assertLoaded(updates[1][0]);
|
|
937
|
+
expect(updates[1][0].name).toEqual("Updated Item 1");
|
|
938
|
+
assert(updates[1]?.[1]);
|
|
939
|
+
assertLoaded(updates[1][1]);
|
|
940
|
+
expect(updates[1][1].name).toEqual("Item 2");
|
|
925
941
|
|
|
926
942
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
927
943
|
});
|
|
@@ -1017,16 +1033,24 @@ describe("CoList subscription", async () => {
|
|
|
1017
1033
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
1018
1034
|
|
|
1019
1035
|
await waitFor(() => {
|
|
1020
|
-
|
|
1021
|
-
|
|
1036
|
+
assert(updates[0]?.[0]);
|
|
1037
|
+
assertLoaded(updates[0][0]);
|
|
1038
|
+
expect(updates[0][0].name).toEqual("Item 1");
|
|
1039
|
+
assert(updates[0]?.[1]);
|
|
1040
|
+
assertLoaded(updates[0][1]);
|
|
1041
|
+
expect(updates[0][1].name).toEqual("Item 2");
|
|
1022
1042
|
});
|
|
1023
1043
|
|
|
1024
1044
|
list[0]!.$jazz.set("name", "Updated Item 1");
|
|
1025
1045
|
|
|
1026
1046
|
await waitFor(() => expect(spy).toHaveBeenCalledTimes(4));
|
|
1027
1047
|
|
|
1028
|
-
|
|
1029
|
-
|
|
1048
|
+
assert(updates[1]?.[0]);
|
|
1049
|
+
assertLoaded(updates[1][0]);
|
|
1050
|
+
expect(updates[1][0].name).toEqual("Updated Item 1");
|
|
1051
|
+
assert(updates[1]?.[1]);
|
|
1052
|
+
assertLoaded(updates[1][1]);
|
|
1053
|
+
expect(updates[1][1].name).toEqual("Item 2");
|
|
1030
1054
|
|
|
1031
1055
|
expect(spy).toHaveBeenCalledTimes(4);
|
|
1032
1056
|
});
|
|
@@ -1154,13 +1178,15 @@ describe("CoList subscription", async () => {
|
|
|
1154
1178
|
const bob = await createJazzTestAccount();
|
|
1155
1179
|
|
|
1156
1180
|
const loadedPerson = await Person.load(person.$jazz.id, {
|
|
1157
|
-
resolve: { dogs: { $onError:
|
|
1181
|
+
resolve: { dogs: { $onError: "catch" } },
|
|
1158
1182
|
loadAs: bob,
|
|
1159
1183
|
});
|
|
1160
1184
|
|
|
1161
|
-
|
|
1185
|
+
assertLoaded(loadedPerson);
|
|
1162
1186
|
expect(loadedPerson.name).toBe("John");
|
|
1163
|
-
expect(loadedPerson.dogs).
|
|
1187
|
+
expect(loadedPerson.dogs.$jazz.loadingState).toBe(
|
|
1188
|
+
CoValueLoadingState.UNAUTHORIZED,
|
|
1189
|
+
);
|
|
1164
1190
|
});
|
|
1165
1191
|
});
|
|
1166
1192
|
|
|
@@ -2,12 +2,14 @@ import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
|
|
2
2
|
import { assert, beforeEach, describe, expect, test, vi } from "vitest";
|
|
3
3
|
import { Account, Group, subscribeToCoValue, z } from "../index.js";
|
|
4
4
|
import {
|
|
5
|
+
CoValueLoadingState,
|
|
5
6
|
Loaded,
|
|
6
7
|
activeAccountContext,
|
|
7
8
|
co,
|
|
8
9
|
coValueClassFromCoValueClassOrSchema,
|
|
9
10
|
} from "../internal.js";
|
|
10
11
|
import {
|
|
12
|
+
assertLoaded,
|
|
11
13
|
createJazzTestAccount,
|
|
12
14
|
runWithoutActiveAccount,
|
|
13
15
|
setupJazzTestSync,
|
|
@@ -41,17 +43,18 @@ describe("CoList unique methods", () => {
|
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
const foundList = await ItemList.loadUnique("test-list", group.$jazz.id);
|
|
46
|
+
assertLoaded(foundList);
|
|
44
47
|
expect(foundList).toEqual(originalList);
|
|
45
48
|
expect(foundList?.length).toBe(3);
|
|
46
49
|
expect(foundList?.[0]).toBe("item1");
|
|
47
50
|
});
|
|
48
51
|
|
|
49
|
-
test("loadUnique returns
|
|
52
|
+
test("loadUnique returns 'unavailable' for non-existent list", async () => {
|
|
50
53
|
const ItemList = co.list(z.string());
|
|
51
54
|
const group = Group.create();
|
|
52
55
|
|
|
53
56
|
const foundList = await ItemList.loadUnique("non-existent", group.$jazz.id);
|
|
54
|
-
expect(foundList).
|
|
57
|
+
expect(foundList.$jazz.loadingState).toBe(CoValueLoadingState.UNAVAILABLE);
|
|
55
58
|
});
|
|
56
59
|
|
|
57
60
|
test("upsertUnique creates new list when none exists", async () => {
|
|
@@ -66,11 +69,11 @@ describe("CoList unique methods", () => {
|
|
|
66
69
|
owner: group,
|
|
67
70
|
});
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
expect(result
|
|
71
|
-
expect(result
|
|
72
|
-
expect(result
|
|
73
|
-
expect(result
|
|
72
|
+
assertLoaded(result);
|
|
73
|
+
expect(result.length).toBe(3);
|
|
74
|
+
expect(result[0]).toBe("item1");
|
|
75
|
+
expect(result[1]).toBe("item2");
|
|
76
|
+
expect(result[2]).toBe("item3");
|
|
74
77
|
});
|
|
75
78
|
|
|
76
79
|
test("upsertUnique without an active account", async () => {
|
|
@@ -87,13 +90,13 @@ describe("CoList unique methods", () => {
|
|
|
87
90
|
});
|
|
88
91
|
});
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
expect(result
|
|
92
|
-
expect(result
|
|
93
|
-
expect(result
|
|
94
|
-
expect(result
|
|
93
|
+
assertLoaded(result);
|
|
94
|
+
expect(result.length).toBe(3);
|
|
95
|
+
expect(result[0]).toBe("item1");
|
|
96
|
+
expect(result[1]).toBe("item2");
|
|
97
|
+
expect(result[2]).toBe("item3");
|
|
95
98
|
|
|
96
|
-
expect(result
|
|
99
|
+
expect(result.$jazz.owner).toEqual(account);
|
|
97
100
|
});
|
|
98
101
|
|
|
99
102
|
test("upsertUnique updates existing list", async () => {
|
|
@@ -113,11 +116,12 @@ describe("CoList unique methods", () => {
|
|
|
113
116
|
owner: group,
|
|
114
117
|
});
|
|
115
118
|
|
|
119
|
+
assertLoaded(updatedList);
|
|
116
120
|
expect(updatedList).toEqual(originalList); // Should be the same instance
|
|
117
|
-
expect(updatedList
|
|
118
|
-
expect(updatedList
|
|
119
|
-
expect(updatedList
|
|
120
|
-
expect(updatedList
|
|
121
|
+
expect(updatedList.length).toBe(3);
|
|
122
|
+
expect(updatedList[0]).toBe("updated1");
|
|
123
|
+
expect(updatedList[1]).toBe("updated2");
|
|
124
|
+
expect(updatedList[2]).toBe("updated3");
|
|
121
125
|
});
|
|
122
126
|
|
|
123
127
|
test("upsertUnique with CoValue items", async () => {
|
|
@@ -140,10 +144,10 @@ describe("CoList unique methods", () => {
|
|
|
140
144
|
resolve: { $each: true },
|
|
141
145
|
});
|
|
142
146
|
|
|
143
|
-
|
|
144
|
-
expect(result
|
|
145
|
-
expect(result
|
|
146
|
-
expect(result
|
|
147
|
+
assertLoaded(result);
|
|
148
|
+
expect(result.length).toBe(2);
|
|
149
|
+
expect(result[0]?.name).toBe("First");
|
|
150
|
+
expect(result[1]?.name).toBe("Second");
|
|
147
151
|
});
|
|
148
152
|
|
|
149
153
|
test("upsertUnique updates list with CoValue items", async () => {
|
|
@@ -174,10 +178,11 @@ describe("CoList unique methods", () => {
|
|
|
174
178
|
resolve: { $each: true },
|
|
175
179
|
});
|
|
176
180
|
|
|
181
|
+
assertLoaded(updatedList);
|
|
177
182
|
expect(updatedList).toEqual(originalList); // Should be the same instance
|
|
178
|
-
expect(updatedList
|
|
179
|
-
expect(updatedList
|
|
180
|
-
expect(updatedList
|
|
183
|
+
expect(updatedList.length).toBe(2);
|
|
184
|
+
expect(updatedList[0]?.name).toBe("Updated");
|
|
185
|
+
expect(updatedList[1]?.name).toBe("Added");
|
|
181
186
|
});
|
|
182
187
|
|
|
183
188
|
test("findUnique returns correct ID", async () => {
|
|
@@ -213,10 +218,10 @@ describe("CoList unique methods", () => {
|
|
|
213
218
|
resolve: { $each: { category: true } },
|
|
214
219
|
});
|
|
215
220
|
|
|
216
|
-
|
|
217
|
-
expect(result
|
|
218
|
-
expect(result
|
|
219
|
-
expect(result
|
|
221
|
+
assertLoaded(result);
|
|
222
|
+
expect(result.length).toBe(1);
|
|
223
|
+
expect(result[0]?.name).toBe("Item 1");
|
|
224
|
+
expect(result[0]?.category?.title).toBe("Category 1");
|
|
220
225
|
});
|
|
221
226
|
|
|
222
227
|
test("concurrently upserting the same value", async () => {
|
|
@@ -235,7 +240,7 @@ describe("CoList unique methods", () => {
|
|
|
235
240
|
await Promise.all(promises);
|
|
236
241
|
|
|
237
242
|
const result = await ItemList.loadUnique("concurrent", owner.$jazz.id);
|
|
238
|
-
|
|
243
|
+
assertLoaded(result);
|
|
239
244
|
|
|
240
245
|
expect(result.length).toBe(2);
|
|
241
246
|
expect(result[0]).toBe(`Item 2`);
|