jazz-tools 0.18.38 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.svelte-kit/__package__/jazz.class.svelte.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 +57 -57
- package/CHANGELOG.md +22 -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-P3YLNFN4.js} +504 -232
- package/dist/chunk-P3YLNFN4.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 +66 -36
- 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 +14 -6
- 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 +2 -2
- 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 +5 -4
- 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/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 +6 -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 +16 -11
- 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 +98 -51
- package/src/tools/coValues/group.ts +3 -2
- package/src/tools/coValues/inbox.ts +11 -10
- package/src/tools/coValues/interfaces.ts +49 -27
- package/src/tools/coValues/request.ts +8 -6
- package/src/tools/coValues/schemaUnion.ts +2 -1
- 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 +19 -9
- 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/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 +55 -44
- 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 +8 -4
- 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 +314 -117
- 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 +723 -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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
|
|
3
3
|
import { cojsonInternals } from "cojson";
|
|
4
|
-
import { co, z } from "jazz-tools";
|
|
4
|
+
import { co, z, CoValueLoadingState } from "jazz-tools";
|
|
5
|
+
import { assertLoaded } from "jazz-tools/testing";
|
|
5
6
|
import { beforeEach, describe, expect, expectTypeOf, it } from "vitest";
|
|
6
7
|
import {
|
|
7
8
|
useCoValueSubscription,
|
|
@@ -47,7 +48,8 @@ describe("useSubscriptionSelector", () => {
|
|
|
47
48
|
return useSubscriptionSelector(subscription);
|
|
48
49
|
});
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
assertLoaded(result.current);
|
|
52
|
+
expect(result.current.value).toBe("123");
|
|
51
53
|
});
|
|
52
54
|
|
|
53
55
|
it("should resolve nested coValues", () => {
|
|
@@ -72,10 +74,12 @@ describe("useSubscriptionSelector", () => {
|
|
|
72
74
|
return useSubscriptionSelector(subscription);
|
|
73
75
|
});
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
assertLoaded(result.current);
|
|
78
|
+
assertLoaded(result.current.nested);
|
|
79
|
+
expect(result.current.nested.content).toBe("456");
|
|
76
80
|
});
|
|
77
81
|
|
|
78
|
-
it("should return
|
|
82
|
+
it("should return 'unavailable' on invalid coValue id", async () => {
|
|
79
83
|
const TestMap = co.map({
|
|
80
84
|
value: z.string(),
|
|
81
85
|
});
|
|
@@ -85,10 +89,12 @@ describe("useSubscriptionSelector", () => {
|
|
|
85
89
|
return useSubscriptionSelector(subscription);
|
|
86
90
|
});
|
|
87
91
|
|
|
88
|
-
expect(result.current).
|
|
92
|
+
expect(result.current.$jazz.loadingState).toBe(CoValueLoadingState.LOADING);
|
|
89
93
|
|
|
90
94
|
await waitFor(() => {
|
|
91
|
-
expect(result.current).
|
|
95
|
+
expect(result.current.$jazz.loadingState).toBe(
|
|
96
|
+
CoValueLoadingState.UNAVAILABLE,
|
|
97
|
+
);
|
|
92
98
|
});
|
|
93
99
|
});
|
|
94
100
|
|
|
@@ -120,7 +126,12 @@ describe("useSubscriptionSelector", () => {
|
|
|
120
126
|
const { result } = renderHook(() => {
|
|
121
127
|
const subscription = useCoValueSubscription(TestMap, map.$jazz.id);
|
|
122
128
|
return useSubscriptionSelector(subscription, {
|
|
123
|
-
select: (v) =>
|
|
129
|
+
select: (v) => {
|
|
130
|
+
if (!v.$isLoaded) {
|
|
131
|
+
return "Loading...";
|
|
132
|
+
}
|
|
133
|
+
return v.value;
|
|
134
|
+
},
|
|
124
135
|
});
|
|
125
136
|
});
|
|
126
137
|
|
|
@@ -134,9 +145,18 @@ describe("useSubscriptionSelector", () => {
|
|
|
134
145
|
|
|
135
146
|
const { result } = renderHook(
|
|
136
147
|
() => {
|
|
137
|
-
const subscription = useAccountSubscription(co.account()
|
|
148
|
+
const subscription = useAccountSubscription(co.account(), {
|
|
149
|
+
resolve: {
|
|
150
|
+
profile: true,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
138
153
|
return useSubscriptionSelector(subscription, {
|
|
139
|
-
select: (v) =>
|
|
154
|
+
select: (v) => {
|
|
155
|
+
if (!v.$isLoaded) {
|
|
156
|
+
return "Loading...";
|
|
157
|
+
}
|
|
158
|
+
return v.profile.name;
|
|
159
|
+
},
|
|
140
160
|
});
|
|
141
161
|
},
|
|
142
162
|
{
|
|
@@ -159,7 +179,12 @@ describe("useSubscriptionSelector", () => {
|
|
|
159
179
|
const { result } = renderHook(() => {
|
|
160
180
|
const subscription = useCoValueSubscription(TestMap, map.$jazz.id);
|
|
161
181
|
return useSubscriptionSelector(subscription, {
|
|
162
|
-
select: (v) =>
|
|
182
|
+
select: (v) => {
|
|
183
|
+
if (!v.$isLoaded) {
|
|
184
|
+
return "Loading...";
|
|
185
|
+
}
|
|
186
|
+
return v.value;
|
|
187
|
+
},
|
|
163
188
|
});
|
|
164
189
|
});
|
|
165
190
|
|
|
@@ -187,7 +212,12 @@ describe("useSubscriptionSelector", () => {
|
|
|
187
212
|
useRenderCount(() => {
|
|
188
213
|
const subscription = useCoValueSubscription(TestMap, map.$jazz.id);
|
|
189
214
|
return useSubscriptionSelector(subscription, {
|
|
190
|
-
select: (v) =>
|
|
215
|
+
select: (v) => {
|
|
216
|
+
if (!v.$isLoaded) {
|
|
217
|
+
return "Loading...";
|
|
218
|
+
}
|
|
219
|
+
return v.value;
|
|
220
|
+
},
|
|
191
221
|
});
|
|
192
222
|
}),
|
|
193
223
|
);
|
|
@@ -218,10 +248,14 @@ describe("useSubscriptionSelector", () => {
|
|
|
218
248
|
useRenderCount(() => {
|
|
219
249
|
const subscription = useCoValueSubscription(TestMap, map.$jazz.id);
|
|
220
250
|
return useSubscriptionSelector(subscription, {
|
|
221
|
-
select: (v) =>
|
|
222
|
-
v
|
|
251
|
+
select: (v) => {
|
|
252
|
+
if (!v.$isLoaded) {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
return v
|
|
223
256
|
? [Math.floor(v.value / 5), Math.floor(v.other / 5)].toSorted()
|
|
224
|
-
: []
|
|
257
|
+
: [];
|
|
258
|
+
},
|
|
225
259
|
equalityFn: (a, b) => a.every((v, i) => v === b[i]),
|
|
226
260
|
});
|
|
227
261
|
}),
|
|
@@ -76,7 +76,9 @@ export const Image = forwardRef<RNImage, ImageProps>(function Image(
|
|
|
76
76
|
{ imageId, width, height, placeholder, ...props },
|
|
77
77
|
ref,
|
|
78
78
|
) {
|
|
79
|
-
const image = useCoState(ImageDefinition, imageId
|
|
79
|
+
const image = useCoState(ImageDefinition, imageId, {
|
|
80
|
+
select: (image) => (image.$isLoaded ? image : null),
|
|
81
|
+
});
|
|
80
82
|
const [src, setSrc] = useState<string | undefined>(
|
|
81
83
|
image?.placeholderDataURL ??
|
|
82
84
|
"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",
|
|
@@ -3,24 +3,33 @@ import type {
|
|
|
3
3
|
AccountClass,
|
|
4
4
|
AnyAccountSchema,
|
|
5
5
|
BranchDefinition,
|
|
6
|
+
CoValue,
|
|
6
7
|
CoValueClassOrSchema,
|
|
7
8
|
CoValueFromRaw,
|
|
9
|
+
SchemaResolveQuery,
|
|
8
10
|
InstanceOfSchema,
|
|
9
11
|
Loaded,
|
|
12
|
+
MaybeLoaded,
|
|
13
|
+
NotLoaded,
|
|
10
14
|
ResolveQuery,
|
|
11
15
|
ResolveQueryStrict,
|
|
12
16
|
} from "jazz-tools";
|
|
13
17
|
import {
|
|
14
18
|
coValueClassFromCoValueClassOrSchema,
|
|
15
19
|
subscribeToCoValue,
|
|
20
|
+
createUnloadedCoValue,
|
|
21
|
+
CoValueLoadingState,
|
|
16
22
|
} from "jazz-tools";
|
|
17
23
|
import { untrack } from "svelte";
|
|
18
24
|
import { createSubscriber } from "svelte/reactivity";
|
|
19
25
|
import { useIsAuthenticated } from "./auth/useIsAuthenticated.svelte.js";
|
|
20
26
|
import { getJazzContext } from "./jazz.svelte";
|
|
21
27
|
|
|
22
|
-
type CoStateOptions<
|
|
23
|
-
|
|
28
|
+
type CoStateOptions<
|
|
29
|
+
V extends CoValueClassOrSchema,
|
|
30
|
+
R extends ResolveQuery<V>,
|
|
31
|
+
> = {
|
|
32
|
+
resolve?: ResolveQueryStrict<V, R>;
|
|
24
33
|
/**
|
|
25
34
|
* Create or load a branch for isolated editing.
|
|
26
35
|
*
|
|
@@ -35,17 +44,22 @@ type CoStateOptions<V extends CoValueClassOrSchema, R extends ResolveQuery<V>> =
|
|
|
35
44
|
* the branch. If not provided, the branch is owned by the current user.
|
|
36
45
|
*
|
|
37
46
|
* For more info see the [branching](https://jazz.tools/docs/svelte/using-covalues/version-control) documentation.
|
|
38
|
-
|
|
39
|
-
unstable_branch?: BranchDefinition
|
|
47
|
+
*/
|
|
48
|
+
unstable_branch?: BranchDefinition;
|
|
40
49
|
};
|
|
41
50
|
|
|
42
51
|
type CoStateId = string | undefined | null;
|
|
43
52
|
|
|
44
53
|
export class CoState<
|
|
45
54
|
V extends CoValueClassOrSchema,
|
|
46
|
-
|
|
55
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
56
|
+
R extends ResolveQuery<V> = SchemaResolveQuery<V>,
|
|
47
57
|
> {
|
|
48
|
-
#value: Loaded<V, R
|
|
58
|
+
#value: MaybeLoaded<Loaded<V, R>> = createUnloadedCoValue(
|
|
59
|
+
"",
|
|
60
|
+
CoValueLoadingState.LOADING,
|
|
61
|
+
);
|
|
62
|
+
#previousValue: MaybeLoaded<CoValue> | undefined = undefined;
|
|
49
63
|
#ctx = getJazzContext<InstanceOfSchema<AccountClass<Account>>>();
|
|
50
64
|
#id: CoStateId;
|
|
51
65
|
#subscribe: () => void;
|
|
@@ -58,7 +72,9 @@ export class CoState<
|
|
|
58
72
|
options?: CoStateOptions<V, R> | (() => CoStateOptions<V, R>),
|
|
59
73
|
) {
|
|
60
74
|
this.#id = $derived.by(typeof id === "function" ? id : () => id);
|
|
61
|
-
this.#options = $derived.by(
|
|
75
|
+
this.#options = $derived.by(
|
|
76
|
+
typeof options === "function" ? options : () => options,
|
|
77
|
+
);
|
|
62
78
|
|
|
63
79
|
this.#subscribe = createSubscriber((update) => {
|
|
64
80
|
this.#update = update;
|
|
@@ -71,22 +87,29 @@ export class CoState<
|
|
|
71
87
|
|
|
72
88
|
return untrack(() => {
|
|
73
89
|
if (!ctx || !id) {
|
|
74
|
-
return this.update(
|
|
90
|
+
return this.update(
|
|
91
|
+
createUnloadedCoValue(id ?? "", CoValueLoadingState.UNAVAILABLE),
|
|
92
|
+
);
|
|
75
93
|
}
|
|
76
94
|
const agent = "me" in ctx ? ctx.me : ctx.guest;
|
|
95
|
+
const resolve = getResolveQuery(Schema, options?.resolve);
|
|
77
96
|
|
|
78
97
|
const unsubscribe = subscribeToCoValue(
|
|
79
98
|
coValueClassFromCoValueClassOrSchema(Schema),
|
|
80
99
|
id,
|
|
81
100
|
{
|
|
82
101
|
// @ts-expect-error The resolve query type isn't compatible with the coValueClassFromCoValueClassOrSchema conversion
|
|
83
|
-
resolve
|
|
102
|
+
resolve,
|
|
84
103
|
loadAs: agent,
|
|
85
104
|
onUnavailable: () => {
|
|
86
|
-
this.update(
|
|
105
|
+
this.update(
|
|
106
|
+
createUnloadedCoValue(id, CoValueLoadingState.UNAVAILABLE),
|
|
107
|
+
);
|
|
87
108
|
},
|
|
88
109
|
onUnauthorized: () => {
|
|
89
|
-
this.update(
|
|
110
|
+
this.update(
|
|
111
|
+
createUnloadedCoValue(id, CoValueLoadingState.UNAUTHORIZED),
|
|
112
|
+
);
|
|
90
113
|
},
|
|
91
114
|
syncResolution: true,
|
|
92
115
|
unstable_branch: options?.unstable_branch,
|
|
@@ -103,8 +126,11 @@ export class CoState<
|
|
|
103
126
|
});
|
|
104
127
|
}
|
|
105
128
|
|
|
106
|
-
update(value: Loaded<V, R
|
|
107
|
-
if (this.#value
|
|
129
|
+
update(value: MaybeLoaded<Loaded<V, R>>) {
|
|
130
|
+
if (shouldSkipUpdate(value, this.#value)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this.#previousValue = value;
|
|
108
134
|
this.#value = value;
|
|
109
135
|
this.#update();
|
|
110
136
|
}
|
|
@@ -117,18 +143,27 @@ export class CoState<
|
|
|
117
143
|
|
|
118
144
|
export class AccountCoState<
|
|
119
145
|
A extends
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
146
|
+
| (AccountClass<Account> & CoValueFromRaw<Account>)
|
|
147
|
+
| AnyAccountSchema,
|
|
148
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
149
|
+
R extends ResolveQuery<A> = SchemaResolveQuery<A>,
|
|
123
150
|
> {
|
|
124
|
-
#value: Loaded<A, R
|
|
151
|
+
#value: MaybeLoaded<Loaded<A, R>> = createUnloadedCoValue(
|
|
152
|
+
"",
|
|
153
|
+
CoValueLoadingState.LOADING,
|
|
154
|
+
);
|
|
125
155
|
#ctx = getJazzContext<InstanceOfSchema<A>>();
|
|
126
156
|
#subscribe: () => void;
|
|
127
157
|
#options: CoStateOptions<A, R> | undefined;
|
|
128
|
-
#update = () => {
|
|
158
|
+
#update = () => {};
|
|
129
159
|
|
|
130
|
-
constructor(
|
|
131
|
-
|
|
160
|
+
constructor(
|
|
161
|
+
Schema: A,
|
|
162
|
+
options?: CoStateOptions<A, R> | (() => CoStateOptions<A, R>),
|
|
163
|
+
) {
|
|
164
|
+
this.#options = $derived.by(
|
|
165
|
+
typeof options === "function" ? options : () => options,
|
|
166
|
+
);
|
|
132
167
|
|
|
133
168
|
this.#subscribe = createSubscriber((update) => {
|
|
134
169
|
this.#update = update;
|
|
@@ -140,23 +175,35 @@ export class AccountCoState<
|
|
|
140
175
|
|
|
141
176
|
return untrack(() => {
|
|
142
177
|
if (!ctx || !("me" in ctx)) {
|
|
143
|
-
return this.update(
|
|
178
|
+
return this.update(
|
|
179
|
+
createUnloadedCoValue("", CoValueLoadingState.UNAVAILABLE),
|
|
180
|
+
);
|
|
144
181
|
}
|
|
145
182
|
|
|
146
183
|
const me = ctx.me;
|
|
184
|
+
const resolve = getResolveQuery(Schema, options?.resolve);
|
|
147
185
|
|
|
148
186
|
const unsubscribe = subscribeToCoValue(
|
|
149
187
|
coValueClassFromCoValueClassOrSchema(Schema),
|
|
150
188
|
me.$jazz.id,
|
|
151
189
|
{
|
|
152
|
-
|
|
153
|
-
resolve: options?.resolve,
|
|
190
|
+
resolve,
|
|
154
191
|
loadAs: me,
|
|
155
192
|
onUnavailable: () => {
|
|
156
|
-
this.update(
|
|
193
|
+
this.update(
|
|
194
|
+
createUnloadedCoValue(
|
|
195
|
+
me.$jazz.id,
|
|
196
|
+
CoValueLoadingState.UNAVAILABLE,
|
|
197
|
+
),
|
|
198
|
+
);
|
|
157
199
|
},
|
|
158
200
|
onUnauthorized: () => {
|
|
159
|
-
this.update(
|
|
201
|
+
this.update(
|
|
202
|
+
createUnloadedCoValue(
|
|
203
|
+
me.$jazz.id,
|
|
204
|
+
CoValueLoadingState.UNAUTHORIZED,
|
|
205
|
+
),
|
|
206
|
+
);
|
|
160
207
|
},
|
|
161
208
|
syncResolution: true,
|
|
162
209
|
unstable_branch: options?.unstable_branch,
|
|
@@ -173,8 +220,8 @@ export class AccountCoState<
|
|
|
173
220
|
});
|
|
174
221
|
}
|
|
175
222
|
|
|
176
|
-
update(value: Loaded<A, R
|
|
177
|
-
if (this.#value
|
|
223
|
+
update(value: MaybeLoaded<Loaded<A, R>>) {
|
|
224
|
+
if (shouldSkipUpdate(value, this.#value)) return;
|
|
178
225
|
this.#value = value;
|
|
179
226
|
this.#update();
|
|
180
227
|
}
|
|
@@ -206,6 +253,20 @@ export class AccountCoState<
|
|
|
206
253
|
}
|
|
207
254
|
}
|
|
208
255
|
|
|
256
|
+
function shouldSkipUpdate(
|
|
257
|
+
newValue: MaybeLoaded<CoValue>,
|
|
258
|
+
previousValue: MaybeLoaded<CoValue>,
|
|
259
|
+
) {
|
|
260
|
+
if (previousValue === newValue) return true;
|
|
261
|
+
// Avoid re-renders if the value is not loaded and didn't change
|
|
262
|
+
return (
|
|
263
|
+
previousValue.$jazz.id === newValue.$jazz.id &&
|
|
264
|
+
!previousValue.$isLoaded &&
|
|
265
|
+
!newValue.$isLoaded &&
|
|
266
|
+
previousValue.$jazz.loadingState === newValue.$jazz.loadingState
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
209
270
|
/**
|
|
210
271
|
* Class that provides the current connection status to the Jazz sync server.
|
|
211
272
|
*
|
|
@@ -249,3 +310,18 @@ export class SyncConnectionStatus {
|
|
|
249
310
|
return this.#ctx.current?.connected() ?? false;
|
|
250
311
|
}
|
|
251
312
|
}
|
|
313
|
+
|
|
314
|
+
function getResolveQuery(
|
|
315
|
+
Schema: CoValueClassOrSchema,
|
|
316
|
+
// We don't need type validation here, since this is an internal API
|
|
317
|
+
resolveQuery?: ResolveQuery<any>,
|
|
318
|
+
): ResolveQuery<any> {
|
|
319
|
+
if (resolveQuery) {
|
|
320
|
+
return resolveQuery;
|
|
321
|
+
}
|
|
322
|
+
// Check the schema is a CoValue schema (and not a CoValue class)
|
|
323
|
+
if ("resolveQuery" in Schema) {
|
|
324
|
+
return Schema.resolveQuery;
|
|
325
|
+
}
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { ImageDefinition } from "jazz-tools";
|
|
2
|
+
import { CoValueLoadingState, ImageDefinition } from "jazz-tools";
|
|
3
3
|
import { highestResAvailable } from "jazz-tools/media";
|
|
4
4
|
import { onDestroy } from "svelte";
|
|
5
5
|
import { CoState } from "../jazz.class.svelte";
|
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
width: number | undefined;
|
|
26
26
|
height: number | undefined;
|
|
27
27
|
}>(() => {
|
|
28
|
-
const
|
|
29
|
-
const
|
|
28
|
+
const originalSize = imageState.current.$isLoaded ? imageState.current.originalSize : undefined;
|
|
29
|
+
const originalWidth = originalSize?.[0];
|
|
30
|
+
const originalHeight = originalSize?.[1];
|
|
30
31
|
|
|
31
32
|
// Both width and height are "original"
|
|
32
33
|
if (width === "original" && height === "original") {
|
|
@@ -68,13 +69,13 @@
|
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
const image = imageState.current;
|
|
71
|
-
if (image ===
|
|
72
|
+
if (image.$jazz.loadingState === CoValueLoadingState.LOADING)
|
|
72
73
|
return (
|
|
73
74
|
placeholder ??
|
|
74
75
|
"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
|
|
75
76
|
);
|
|
76
77
|
|
|
77
|
-
if (!image) return undefined;
|
|
78
|
+
if (!image.$isLoaded) return undefined;
|
|
78
79
|
|
|
79
80
|
const bestImage = highestResAvailable(
|
|
80
81
|
image,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { co, CoPlainText } from "jazz-tools";
|
|
2
|
+
import { assertLoaded, createJazzTestAccount, setupJazzTestSync } from "jazz-tools/testing";
|
|
3
|
+
import { beforeEach, describe, expectTypeOf, test } from "vitest";
|
|
4
|
+
import { AccountCoState } from "../jazz.class.svelte";
|
|
5
|
+
|
|
6
|
+
describe("AccountCoState", () => {
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
await setupJazzTestSync();
|
|
9
|
+
await createJazzTestAccount({
|
|
10
|
+
isCurrentActiveAccount: true,
|
|
11
|
+
creationProps: { name: "Hermes Puggington" },
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("should use the schema's resolve query if no resolve query is provided", async () => {
|
|
16
|
+
const AccountWithProfile = co.account().resolved({ profile: true });
|
|
17
|
+
|
|
18
|
+
const loadedAccount = new AccountCoState(AccountWithProfile);
|
|
19
|
+
|
|
20
|
+
assertLoaded(loadedAccount.current);
|
|
21
|
+
expectTypeOf<typeof loadedAccount.current.profile.name>().toEqualTypeOf<string>();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { co, CoPlainText } from "jazz-tools";
|
|
2
|
+
import { assertLoaded } from "jazz-tools/testing";
|
|
3
|
+
import { describe, expectTypeOf, test } from "vitest";
|
|
4
|
+
import { CoState } from "../jazz.class.svelte";
|
|
5
|
+
|
|
6
|
+
describe("CoState", () => {
|
|
7
|
+
test("should use the schema's resolve query if no resolve query is provided", async () => {
|
|
8
|
+
const Person = co.map({
|
|
9
|
+
name: co.plainText(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const PersonWithName = Person.resolved({ name: true });
|
|
13
|
+
const person = Person.create({ name: "John Doe" });
|
|
14
|
+
|
|
15
|
+
const loadedPerson = new CoState(PersonWithName, person.$jazz.id);
|
|
16
|
+
|
|
17
|
+
assertLoaded(loadedPerson.current);
|
|
18
|
+
expectTypeOf<typeof loadedPerson.current.name>().toEqualTypeOf<CoPlainText>();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { co, Account, CoValueLoadingState, Group } from "jazz-tools";
|
|
4
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { createJazzTestAccount, setupJazzTestSync } from "../testing";
|
|
6
|
+
import { render, screen, waitFor } from "./testUtils";
|
|
7
|
+
import TestCoStateWrapper from "./TestCoStateWrapper.svelte";
|
|
8
|
+
|
|
9
|
+
describe("CoState", () => {
|
|
10
|
+
let serverAccount: Account;
|
|
11
|
+
let clientAccount: Account;
|
|
12
|
+
let publicGroup: Group;
|
|
13
|
+
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
await setupJazzTestSync();
|
|
16
|
+
await createJazzTestAccount({
|
|
17
|
+
creationProps: { name: "Server" },
|
|
18
|
+
isCurrentActiveAccount: true,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
serverAccount = Account.getMe();
|
|
22
|
+
clientAccount = await createJazzTestAccount({
|
|
23
|
+
creationProps: { name: "Client" },
|
|
24
|
+
});
|
|
25
|
+
publicGroup = Group.create(serverAccount).makePublic("reader");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should use the schema's resolve query if no resolve query is provided", async () => {
|
|
29
|
+
const Person = co.map({
|
|
30
|
+
name: co.plainText(),
|
|
31
|
+
});
|
|
32
|
+
const PersonWithName = Person.resolved({ name: true });
|
|
33
|
+
const person = Person.create({ name: "John Doe" }, publicGroup);
|
|
34
|
+
|
|
35
|
+
render(
|
|
36
|
+
TestCoStateWrapper,
|
|
37
|
+
{
|
|
38
|
+
Schema: PersonWithName,
|
|
39
|
+
id: person.$jazz.id,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
account: clientAccount,
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
await waitFor(() => {
|
|
47
|
+
expect(screen.getByTestId("loading-state").textContent).toBe(
|
|
48
|
+
CoValueLoadingState.LOADED,
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
expect(screen.getByTestId("is-loaded").textContent).toBe("true");
|
|
52
|
+
const stateValue = JSON.parse(
|
|
53
|
+
screen.getByTestId("state-value").textContent ?? "",
|
|
54
|
+
);
|
|
55
|
+
expect(stateValue.name).toBe("John Doe");
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { CoValueClassOrSchema, ResolveQuery } from 'jazz-tools';
|
|
3
|
+
import { CoState } from '../jazz.class.svelte';
|
|
4
|
+
|
|
5
|
+
type Props<V extends CoValueClassOrSchema, R extends ResolveQuery<V>> = {
|
|
6
|
+
Schema: V;
|
|
7
|
+
id: string;
|
|
8
|
+
options?: { resolve?: R };
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
let { Schema, id, options }: Props<any, any> = $props();
|
|
12
|
+
|
|
13
|
+
const state = new CoState(Schema, id, options);
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<div data-testid="costate-wrapper">
|
|
17
|
+
<div data-testid="loading-state">{state.current.$jazz.loadingState}</div>
|
|
18
|
+
<div data-testid="is-loaded">{state.current.$isLoaded ? 'true' : 'false'}</div>
|
|
19
|
+
{#if state.current.$isLoaded}
|
|
20
|
+
<div data-testid="state-value">{JSON.stringify(state.current.toJSON())}</div>
|
|
21
|
+
{/if}
|
|
22
|
+
</div>
|
|
23
|
+
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
AnonymousJazzAgent,
|
|
4
4
|
CoValue,
|
|
5
5
|
CoValueClass,
|
|
6
|
+
CoValueLoadingState,
|
|
6
7
|
ID,
|
|
7
8
|
RegisteredSchemas,
|
|
8
9
|
type SubscriptionScope,
|
|
@@ -18,6 +19,13 @@ export abstract class CoValueBase implements CoValue {
|
|
|
18
19
|
declare [TypeSym]: string;
|
|
19
20
|
|
|
20
21
|
declare abstract $jazz: CoValueJazzApi<this>;
|
|
22
|
+
declare $isLoaded: true;
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
Object.defineProperties(this, {
|
|
26
|
+
$isLoaded: { value: true, enumerable: false },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
21
29
|
|
|
22
30
|
/** @category Internals */
|
|
23
31
|
static fromRaw<V extends CoValue>(this: CoValueClass<V>, raw: RawCoValue): V {
|
|
@@ -60,6 +68,10 @@ export abstract class CoValueJazzApi<V extends CoValue> {
|
|
|
60
68
|
return this.raw.id;
|
|
61
69
|
}
|
|
62
70
|
|
|
71
|
+
get loadingState(): typeof CoValueLoadingState.LOADED {
|
|
72
|
+
return CoValueLoadingState.LOADED;
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
abstract get raw(): RawCoValue;
|
|
64
76
|
abstract get owner(): Group | undefined;
|
|
65
77
|
|