jazz-tools 0.18.37 → 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 +53 -53
- package/CHANGELOG.md +33 -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/inspector/{custom-element-SUVJ7CPN.js → custom-element-QESCMFY7.js} +13 -3
- package/dist/inspector/{custom-element-SUVJ7CPN.js.map → custom-element-QESCMFY7.js.map} +1 -1
- package/dist/inspector/index.js +12 -2
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/register-custom-element.js +1 -1
- package/dist/inspector/viewer/history-view.d.ts.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 +74 -10
- package/src/inspector/viewer/history-view.tsx +14 -5
- 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
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
CoMap,
|
|
6
6
|
type CoValue,
|
|
7
7
|
type ID,
|
|
8
|
+
MaybeLoaded,
|
|
8
9
|
type RefEncoded,
|
|
9
10
|
type RefsToResolve,
|
|
10
11
|
TypeSym,
|
|
@@ -14,7 +15,12 @@ import {
|
|
|
14
15
|
import { applyCoValueMigrations } from "../lib/migration.js";
|
|
15
16
|
import { CoValueCoreSubscription } from "./CoValueCoreSubscription.js";
|
|
16
17
|
import { JazzError, type JazzErrorIssue } from "./JazzError.js";
|
|
17
|
-
import type {
|
|
18
|
+
import type {
|
|
19
|
+
BranchDefinition,
|
|
20
|
+
SubscriptionValue,
|
|
21
|
+
SubscriptionValueLoading,
|
|
22
|
+
} from "./types.js";
|
|
23
|
+
import { CoValueLoadingState, NotLoadedCoValueState } from "./types.js";
|
|
18
24
|
import { createCoValue, myRoleForRawValue } from "./utils.js";
|
|
19
25
|
|
|
20
26
|
export class SubscriptionScope<D extends CoValue> {
|
|
@@ -31,7 +37,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
31
37
|
* Autoloaded child ids that are unloaded
|
|
32
38
|
*/
|
|
33
39
|
pendingAutoloadedChildren: Set<string> = new Set();
|
|
34
|
-
value: SubscriptionValue<D, any> |
|
|
40
|
+
value: SubscriptionValue<D, any> | SubscriptionValueLoading;
|
|
35
41
|
childErrors: Map<string, JazzError> = new Map();
|
|
36
42
|
validationErrors: Map<string, JazzError> = new Map();
|
|
37
43
|
errorFromChildren: JazzError | undefined;
|
|
@@ -59,16 +65,19 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
59
65
|
public unstable_branch?: BranchDefinition,
|
|
60
66
|
) {
|
|
61
67
|
this.resolve = resolve;
|
|
62
|
-
this.value = { type:
|
|
68
|
+
this.value = { type: CoValueLoadingState.LOADING, id };
|
|
63
69
|
|
|
64
|
-
let lastUpdate:
|
|
70
|
+
let lastUpdate:
|
|
71
|
+
| RawCoValue
|
|
72
|
+
| typeof CoValueLoadingState.UNAVAILABLE
|
|
73
|
+
| undefined;
|
|
65
74
|
this.subscription = new CoValueCoreSubscription(
|
|
66
75
|
node,
|
|
67
76
|
id,
|
|
68
77
|
(value) => {
|
|
69
78
|
lastUpdate = value;
|
|
70
79
|
|
|
71
|
-
if (skipRetry && value ===
|
|
80
|
+
if (skipRetry && value === CoValueLoadingState.UNAVAILABLE) {
|
|
72
81
|
this.handleUpdate(value);
|
|
73
82
|
return;
|
|
74
83
|
}
|
|
@@ -79,7 +88,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
79
88
|
// - Run the migration only once
|
|
80
89
|
// - Skip all the updates until the migration is done
|
|
81
90
|
// - Trigger handleUpdate only with the final value
|
|
82
|
-
if (!this.migrated && value !==
|
|
91
|
+
if (!this.migrated && value !== CoValueLoadingState.UNAVAILABLE) {
|
|
83
92
|
if (this.migrating) {
|
|
84
93
|
return;
|
|
85
94
|
}
|
|
@@ -107,13 +116,13 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
107
116
|
this.dirty = true;
|
|
108
117
|
}
|
|
109
118
|
|
|
110
|
-
handleUpdate(update: RawCoValue |
|
|
111
|
-
if (update ===
|
|
112
|
-
if (this.value.type ===
|
|
119
|
+
handleUpdate(update: RawCoValue | typeof CoValueLoadingState.UNAVAILABLE) {
|
|
120
|
+
if (update === CoValueLoadingState.UNAVAILABLE) {
|
|
121
|
+
if (this.value.type === CoValueLoadingState.LOADING) {
|
|
113
122
|
this.updateValue(
|
|
114
|
-
new JazzError(this.id,
|
|
123
|
+
new JazzError(this.id, CoValueLoadingState.UNAVAILABLE, [
|
|
115
124
|
{
|
|
116
|
-
code:
|
|
125
|
+
code: CoValueLoadingState.UNAVAILABLE,
|
|
117
126
|
message: "The value is unavailable",
|
|
118
127
|
params: {
|
|
119
128
|
id: this.id,
|
|
@@ -135,11 +144,11 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
135
144
|
myRoleForRawValue(update) !== undefined;
|
|
136
145
|
|
|
137
146
|
if (!hasAccess) {
|
|
138
|
-
if (this.value.type !==
|
|
147
|
+
if (this.value.type !== CoValueLoadingState.UNAUTHORIZED) {
|
|
139
148
|
this.updateValue(
|
|
140
|
-
new JazzError(this.id,
|
|
149
|
+
new JazzError(this.id, CoValueLoadingState.UNAUTHORIZED, [
|
|
141
150
|
{
|
|
142
|
-
code:
|
|
151
|
+
code: CoValueLoadingState.UNAUTHORIZED,
|
|
143
152
|
message: `The current user (${this.node.getCurrentAgent().id}) is not authorized to access this value`,
|
|
144
153
|
params: {
|
|
145
154
|
id: this.id,
|
|
@@ -157,7 +166,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
157
166
|
// after loading all the children, not one per children
|
|
158
167
|
this.silenceUpdates = true;
|
|
159
168
|
|
|
160
|
-
if (this.value.type !==
|
|
169
|
+
if (this.value.type !== CoValueLoadingState.LOADED) {
|
|
161
170
|
this.updateValue(createCoValue(this.schema, update, this));
|
|
162
171
|
this.loadChildren();
|
|
163
172
|
} else {
|
|
@@ -182,7 +191,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
182
191
|
|
|
183
192
|
computeChildErrors() {
|
|
184
193
|
let issues: JazzErrorIssue[] = [];
|
|
185
|
-
let errorType: JazzError["type"] =
|
|
194
|
+
let errorType: JazzError["type"] = CoValueLoadingState.UNAVAILABLE;
|
|
186
195
|
|
|
187
196
|
if (this.childErrors.size === 0 && this.validationErrors.size === 0) {
|
|
188
197
|
return undefined;
|
|
@@ -228,10 +237,10 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
228
237
|
|
|
229
238
|
handleChildUpdate = (
|
|
230
239
|
id: string,
|
|
231
|
-
value: SubscriptionValue<any, any> |
|
|
240
|
+
value: SubscriptionValue<any, any> | SubscriptionValueLoading,
|
|
232
241
|
key?: string,
|
|
233
242
|
) => {
|
|
234
|
-
if (value.type ===
|
|
243
|
+
if (value.type === CoValueLoadingState.LOADING) {
|
|
235
244
|
return;
|
|
236
245
|
}
|
|
237
246
|
|
|
@@ -239,7 +248,10 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
239
248
|
this.pendingAutoloadedChildren.delete(id);
|
|
240
249
|
this.childValues.set(id, value);
|
|
241
250
|
|
|
242
|
-
if (
|
|
251
|
+
if (
|
|
252
|
+
value.type === CoValueLoadingState.UNAVAILABLE ||
|
|
253
|
+
value.type === CoValueLoadingState.UNAUTHORIZED
|
|
254
|
+
) {
|
|
243
255
|
this.childErrors.set(id, value.prependPath(key ?? id));
|
|
244
256
|
|
|
245
257
|
this.errorFromChildren = this.computeChildErrors();
|
|
@@ -250,7 +262,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
250
262
|
}
|
|
251
263
|
|
|
252
264
|
if (this.shouldSendUpdates()) {
|
|
253
|
-
if (this.value.type ===
|
|
265
|
+
if (this.value.type === CoValueLoadingState.LOADED) {
|
|
254
266
|
// On child updates, we re-create the value instance to make the updates
|
|
255
267
|
// seamless-immutable and so be compatible with React and the React compiler
|
|
256
268
|
this.updateValue(
|
|
@@ -263,37 +275,37 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
263
275
|
};
|
|
264
276
|
|
|
265
277
|
shouldSendUpdates() {
|
|
266
|
-
if (this.value.type ===
|
|
278
|
+
if (this.value.type === CoValueLoadingState.LOADING) return false;
|
|
267
279
|
|
|
268
280
|
// If the value is in error, we send the update regardless of the children statuses
|
|
269
|
-
if (this.value.type !==
|
|
281
|
+
if (this.value.type !== CoValueLoadingState.LOADED) return true;
|
|
270
282
|
|
|
271
283
|
return this.pendingLoadedChildren.size === 0;
|
|
272
284
|
}
|
|
273
285
|
|
|
274
|
-
getCurrentValue() {
|
|
286
|
+
getCurrentValue(): D | NotLoadedCoValueState {
|
|
275
287
|
if (
|
|
276
|
-
this.value.type ===
|
|
277
|
-
this.value.type ===
|
|
288
|
+
this.value.type === CoValueLoadingState.UNAUTHORIZED ||
|
|
289
|
+
this.value.type === CoValueLoadingState.UNAVAILABLE
|
|
278
290
|
) {
|
|
279
291
|
console.error(this.value.toString());
|
|
280
|
-
return
|
|
292
|
+
return this.value.type;
|
|
281
293
|
}
|
|
282
294
|
|
|
283
295
|
if (!this.shouldSendUpdates()) {
|
|
284
|
-
return
|
|
296
|
+
return CoValueLoadingState.LOADING;
|
|
285
297
|
}
|
|
286
298
|
|
|
287
299
|
if (this.errorFromChildren) {
|
|
288
300
|
console.error(this.errorFromChildren.toString());
|
|
289
|
-
return
|
|
301
|
+
return this.errorFromChildren.type;
|
|
290
302
|
}
|
|
291
303
|
|
|
292
|
-
if (this.value.type ===
|
|
304
|
+
if (this.value.type === CoValueLoadingState.LOADED) {
|
|
293
305
|
return this.value.value;
|
|
294
306
|
}
|
|
295
307
|
|
|
296
|
-
return
|
|
308
|
+
return CoValueLoadingState.LOADING;
|
|
297
309
|
}
|
|
298
310
|
|
|
299
311
|
triggerUpdate() {
|
|
@@ -307,7 +319,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
307
319
|
|
|
308
320
|
if (error) {
|
|
309
321
|
this.subscribers.forEach((listener) => listener(error));
|
|
310
|
-
} else if (value.type !==
|
|
322
|
+
} else if (value.type !== CoValueLoadingState.LOADING) {
|
|
311
323
|
this.subscribers.forEach((listener) => listener(value));
|
|
312
324
|
}
|
|
313
325
|
|
|
@@ -333,16 +345,15 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
333
345
|
this.resolve = {};
|
|
334
346
|
}
|
|
335
347
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
348
|
+
const resolve: Record<string, any> = this.resolve;
|
|
349
|
+
if (!resolve.$each && !(key in resolve)) {
|
|
339
350
|
// Adding the key to the resolve object to resolve the key when calling loadChildren
|
|
340
351
|
resolve[key] = true;
|
|
341
352
|
// Track the keys that are autoloaded to flag any id on that key as autoloaded
|
|
342
353
|
this.autoloadedKeys.add(key);
|
|
343
354
|
}
|
|
344
355
|
|
|
345
|
-
if (this.value.type !==
|
|
356
|
+
if (this.value.type !== CoValueLoadingState.LOADED) {
|
|
346
357
|
return;
|
|
347
358
|
}
|
|
348
359
|
|
|
@@ -386,7 +397,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
386
397
|
throw new Error("Cannot pull a non-closed subscription scope");
|
|
387
398
|
}
|
|
388
399
|
|
|
389
|
-
if (this.value.type ===
|
|
400
|
+
if (this.value.type === CoValueLoadingState.LOADED) {
|
|
390
401
|
return;
|
|
391
402
|
}
|
|
392
403
|
|
|
@@ -398,9 +409,9 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
398
409
|
const value = this.getCurrentValue();
|
|
399
410
|
|
|
400
411
|
// If the value is available, trigger the listener
|
|
401
|
-
if (value) {
|
|
412
|
+
if (typeof value !== "string") {
|
|
402
413
|
listener({
|
|
403
|
-
type:
|
|
414
|
+
type: CoValueLoadingState.LOADED,
|
|
404
415
|
value,
|
|
405
416
|
id: this.id,
|
|
406
417
|
});
|
|
@@ -461,7 +472,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
461
472
|
loadChildren() {
|
|
462
473
|
const { resolve } = this;
|
|
463
474
|
|
|
464
|
-
if (this.value.type !==
|
|
475
|
+
if (this.value.type !== CoValueLoadingState.LOADED) {
|
|
465
476
|
return false;
|
|
466
477
|
}
|
|
467
478
|
|
|
@@ -536,7 +547,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
536
547
|
} else if (!descriptor.optional) {
|
|
537
548
|
this.validationErrors.set(
|
|
538
549
|
key,
|
|
539
|
-
new JazzError(undefined,
|
|
550
|
+
new JazzError(undefined, CoValueLoadingState.UNAVAILABLE, [
|
|
540
551
|
{
|
|
541
552
|
code: "validationError",
|
|
542
553
|
message: `The ref on position ${key} requested on ${stream.constructor.name} is missing`,
|
|
@@ -585,7 +596,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
585
596
|
if (!descriptor) {
|
|
586
597
|
this.childErrors.set(
|
|
587
598
|
key,
|
|
588
|
-
new JazzError(undefined,
|
|
599
|
+
new JazzError(undefined, CoValueLoadingState.UNAVAILABLE, [
|
|
589
600
|
{
|
|
590
601
|
code: "validationError",
|
|
591
602
|
message: `The ref ${key} requested on ${map.constructor.name} is not defined in the schema`,
|
|
@@ -606,7 +617,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
606
617
|
} else if (!descriptor.optional) {
|
|
607
618
|
this.validationErrors.set(
|
|
608
619
|
key,
|
|
609
|
-
new JazzError(undefined,
|
|
620
|
+
new JazzError(undefined, CoValueLoadingState.UNAVAILABLE, [
|
|
610
621
|
{
|
|
611
622
|
code: "validationError",
|
|
612
623
|
message: `The ref ${key} requested on ${map.constructor.name} is missing`,
|
|
@@ -645,7 +656,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
645
656
|
} else if (!descriptor.optional) {
|
|
646
657
|
this.validationErrors.set(
|
|
647
658
|
key,
|
|
648
|
-
new JazzError(undefined,
|
|
659
|
+
new JazzError(undefined, CoValueLoadingState.UNAVAILABLE, [
|
|
649
660
|
{
|
|
650
661
|
code: "validationError",
|
|
651
662
|
message: `The ref on position ${key} requested on ${list.constructor.name} is missing`,
|
|
@@ -674,7 +685,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
|
674
685
|
this.autoloaded.add(id);
|
|
675
686
|
}
|
|
676
687
|
|
|
677
|
-
const skipInvalid = typeof query === "object" && query.$onError ===
|
|
688
|
+
const skipInvalid = typeof query === "object" && query.$onError === "catch";
|
|
678
689
|
|
|
679
690
|
if (skipInvalid) {
|
|
680
691
|
if (key) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { CoValue, CoValueClass, RefEncoded } from "../internal.js";
|
|
2
|
+
import { createUnloadedCoValue } from "../internal.js";
|
|
2
3
|
import { SubscriptionScope } from "./SubscriptionScope.js";
|
|
4
|
+
import { CoValueLoadingState } from "./types.js";
|
|
3
5
|
|
|
4
6
|
export function getSubscriptionScope<D extends CoValue>(value: D) {
|
|
5
7
|
const subscriptionScope = value.$jazz._subscriptionScope;
|
|
@@ -56,10 +58,13 @@ export function accessChildByKey<D extends CoValue>(
|
|
|
56
58
|
|
|
57
59
|
const value = subscriptionScope.childValues.get(childId);
|
|
58
60
|
|
|
59
|
-
if (value?.type ===
|
|
61
|
+
if (value?.type === CoValueLoadingState.LOADED) {
|
|
60
62
|
return value.value;
|
|
61
63
|
} else {
|
|
62
|
-
return
|
|
64
|
+
return createUnloadedCoValue(
|
|
65
|
+
childId,
|
|
66
|
+
value?.type ?? CoValueLoadingState.LOADING,
|
|
67
|
+
);
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
|
|
@@ -82,9 +87,12 @@ export function accessChildById<D extends CoValue>(
|
|
|
82
87
|
|
|
83
88
|
const value = subscriptionScope.childValues.get(childId);
|
|
84
89
|
|
|
85
|
-
if (value?.type ===
|
|
90
|
+
if (value?.type === CoValueLoadingState.LOADED) {
|
|
86
91
|
return value.value;
|
|
87
92
|
} else {
|
|
88
|
-
return
|
|
93
|
+
return createUnloadedCoValue(
|
|
94
|
+
childId,
|
|
95
|
+
value?.type ?? CoValueLoadingState.LOADING,
|
|
96
|
+
);
|
|
89
97
|
}
|
|
90
98
|
}
|
|
@@ -7,9 +7,43 @@ import type {
|
|
|
7
7
|
} from "../internal.js";
|
|
8
8
|
import type { JazzError } from "./JazzError.js";
|
|
9
9
|
|
|
10
|
+
export const CoValueLoadingState = {
|
|
11
|
+
/**
|
|
12
|
+
* The coValue is loaded.
|
|
13
|
+
*/
|
|
14
|
+
LOADED: "loaded",
|
|
15
|
+
/**
|
|
16
|
+
* The coValue is being loaded.
|
|
17
|
+
*/
|
|
18
|
+
LOADING: "loading",
|
|
19
|
+
/**
|
|
20
|
+
* The coValue was loaded but the account is not authorized to access it.
|
|
21
|
+
*/
|
|
22
|
+
UNAUTHORIZED: "unauthorized",
|
|
23
|
+
/**
|
|
24
|
+
* Tried to load the coValue but failed.
|
|
25
|
+
*/
|
|
26
|
+
UNAVAILABLE: "unavailable",
|
|
27
|
+
} as const;
|
|
28
|
+
|
|
29
|
+
export type CoValueLoadingState =
|
|
30
|
+
(typeof CoValueLoadingState)[keyof typeof CoValueLoadingState];
|
|
31
|
+
|
|
32
|
+
export type NotLoadedCoValueState =
|
|
33
|
+
| typeof CoValueLoadingState.LOADING
|
|
34
|
+
| typeof CoValueLoadingState.UNAUTHORIZED
|
|
35
|
+
| typeof CoValueLoadingState.UNAVAILABLE;
|
|
36
|
+
|
|
10
37
|
export type SubscriptionValue<D extends CoValue, R extends RefsToResolve<D>> =
|
|
11
|
-
| {
|
|
38
|
+
| {
|
|
39
|
+
type: typeof CoValueLoadingState.LOADED;
|
|
40
|
+
value: Resolved<D, R>;
|
|
41
|
+
id: string;
|
|
42
|
+
}
|
|
12
43
|
| JazzError;
|
|
13
|
-
export type
|
|
44
|
+
export type SubscriptionValueLoading = {
|
|
45
|
+
type: typeof CoValueLoadingState.LOADING;
|
|
46
|
+
id: string;
|
|
47
|
+
};
|
|
14
48
|
|
|
15
49
|
export type BranchDefinition = { name: string; owner?: Group | Account | null };
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "../internal.js";
|
|
9
9
|
import { coValuesCache } from "../lib/cache.js";
|
|
10
10
|
import { SubscriptionScope } from "./SubscriptionScope.js";
|
|
11
|
+
import { CoValueLoadingState } from "./types.js";
|
|
11
12
|
|
|
12
13
|
export function myRoleForRawValue(raw: RawCoValue): Role | undefined {
|
|
13
14
|
const rawOwner = raw.group;
|
|
@@ -36,7 +37,7 @@ export function createCoValue<D extends CoValue>(
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
return {
|
|
39
|
-
type:
|
|
40
|
+
type: CoValueLoadingState.LOADED,
|
|
40
41
|
value: freshValueInstance,
|
|
41
42
|
id: subscriptionScope.id,
|
|
42
43
|
};
|
package/src/tools/testing.ts
CHANGED
|
@@ -16,9 +16,14 @@ import {
|
|
|
16
16
|
coValueClassFromCoValueClassOrSchema,
|
|
17
17
|
createAnonymousJazzContext,
|
|
18
18
|
createJazzContext,
|
|
19
|
+
CoValue,
|
|
20
|
+
LoadedAndRequired,
|
|
21
|
+
MaybeLoaded,
|
|
19
22
|
randomSessionProvider,
|
|
20
23
|
} from "./internal.js";
|
|
21
24
|
|
|
25
|
+
export { assertLoaded } from "./lib/utils.js";
|
|
26
|
+
|
|
22
27
|
const syncServer: { current: LocalNode | null; asyncPeers: boolean } = {
|
|
23
28
|
current: null,
|
|
24
29
|
asyncPeers: false,
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { assert, beforeEach, describe, expect, test, vi } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CoValueLoadingState,
|
|
4
|
+
Group,
|
|
5
|
+
co,
|
|
6
|
+
exportCoValue,
|
|
7
|
+
z,
|
|
8
|
+
} from "../exports.js";
|
|
3
9
|
import { CoValueCoreSubscription } from "../subscribe/CoValueCoreSubscription.js";
|
|
4
10
|
import {
|
|
5
11
|
createJazzTestAccount,
|
|
@@ -462,7 +468,7 @@ describe("CoValueCoreSubscription", async () => {
|
|
|
462
468
|
await waitFor(() => expect(listener).toHaveBeenCalled());
|
|
463
469
|
|
|
464
470
|
// Should report unavailable when loading fails
|
|
465
|
-
expect(lastResult).toBe(
|
|
471
|
+
expect(lastResult).toBe(CoValueLoadingState.UNAVAILABLE);
|
|
466
472
|
|
|
467
473
|
subscription.unsubscribe();
|
|
468
474
|
});
|
|
@@ -493,7 +499,7 @@ describe("CoValueCoreSubscription", async () => {
|
|
|
493
499
|
await waitFor(() => expect(listener).toHaveBeenCalled());
|
|
494
500
|
|
|
495
501
|
// Should report unavailable when loading fails
|
|
496
|
-
expect(lastResult).toBe(
|
|
502
|
+
expect(lastResult).toBe(CoValueLoadingState.UNAVAILABLE);
|
|
497
503
|
|
|
498
504
|
subscription.unsubscribe();
|
|
499
505
|
});
|
|
@@ -542,7 +548,7 @@ describe("CoValueCoreSubscription", async () => {
|
|
|
542
548
|
await waitFor(() => expect(listener).toHaveBeenCalled());
|
|
543
549
|
|
|
544
550
|
// Should report unavailable when loading fails
|
|
545
|
-
expect(lastResult).toBe(
|
|
551
|
+
expect(lastResult).toBe(CoValueLoadingState.UNAVAILABLE);
|
|
546
552
|
|
|
547
553
|
subscription.unsubscribe();
|
|
548
554
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StorageAPI } from "cojson";
|
|
2
2
|
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
|
3
|
-
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
3
|
+
import { assert, beforeEach, describe, expect, test, vi } from "vitest";
|
|
4
4
|
import {
|
|
5
5
|
Account,
|
|
6
6
|
AccountClass,
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
coValueClassFromCoValueClassOrSchema,
|
|
29
29
|
} from "../internal";
|
|
30
30
|
import {
|
|
31
|
+
assertLoaded,
|
|
31
32
|
createJazzTestAccount,
|
|
32
33
|
getPeerConnectedToTestSyncServer,
|
|
33
34
|
setupJazzTestSync,
|
|
@@ -101,7 +102,8 @@ describe("ContextManager", () => {
|
|
|
101
102
|
|
|
102
103
|
const context = getCurrentValue();
|
|
103
104
|
|
|
104
|
-
|
|
105
|
+
assertLoaded(context.me.profile);
|
|
106
|
+
expect(context.me.profile.name).toBe("Anonymous user");
|
|
105
107
|
expect(context.node).toBeDefined();
|
|
106
108
|
expect(manager.getCurrentValue()).toBeDefined();
|
|
107
109
|
});
|
|
@@ -113,7 +115,8 @@ describe("ContextManager", () => {
|
|
|
113
115
|
|
|
114
116
|
const context = getCurrentValue();
|
|
115
117
|
|
|
116
|
-
|
|
118
|
+
assertLoaded(context.me.profile);
|
|
119
|
+
expect(context.me.profile.name).toBe("Test User");
|
|
117
120
|
expect(context.node).toBeDefined();
|
|
118
121
|
expect(manager.getCurrentValue()).toBeDefined();
|
|
119
122
|
});
|
|
@@ -489,7 +492,10 @@ describe("ContextManager", () => {
|
|
|
489
492
|
},
|
|
490
493
|
});
|
|
491
494
|
|
|
492
|
-
|
|
495
|
+
const transferredRoot = me.root.transferredRoot;
|
|
496
|
+
assert(transferredRoot);
|
|
497
|
+
assertLoaded(transferredRoot);
|
|
498
|
+
expect(transferredRoot.value).toBe("Hello");
|
|
493
499
|
});
|
|
494
500
|
|
|
495
501
|
test("handles registration of new account", async () => {
|
|
@@ -501,7 +507,8 @@ describe("ContextManager", () => {
|
|
|
501
507
|
|
|
502
508
|
expect(accountId).toBeDefined();
|
|
503
509
|
const context = getCurrentValue();
|
|
504
|
-
|
|
510
|
+
assertLoaded(context.me.profile);
|
|
511
|
+
expect(context.me.profile.name).toBe("Test User");
|
|
505
512
|
expect(context.me.$jazz.id).toBe(accountId);
|
|
506
513
|
});
|
|
507
514
|
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
setActiveAccount,
|
|
7
7
|
setupJazzTestSync,
|
|
8
8
|
} from "../testing.js";
|
|
9
|
-
import { setupTwoNodes } from "./utils.js";
|
|
9
|
+
import { assertLoaded, setupTwoNodes } from "./utils.js";
|
|
10
|
+
import { CoValueLoadingState } from "../internal.js";
|
|
10
11
|
|
|
11
12
|
beforeEach(async () => {
|
|
12
13
|
await setupJazzTestSync();
|
|
@@ -32,7 +33,7 @@ test("waitForAllCoValuesSync should resolve when all the values are synced", asy
|
|
|
32
33
|
|
|
33
34
|
for (const map of maps) {
|
|
34
35
|
const loadedMap = await serverNode.load(map.$jazz.raw.id);
|
|
35
|
-
expect(loadedMap).not.toBe(
|
|
36
|
+
expect(loadedMap).not.toBe(CoValueLoadingState.UNAVAILABLE);
|
|
36
37
|
}
|
|
37
38
|
});
|
|
38
39
|
|
|
@@ -46,7 +47,7 @@ test("waitForSync should resolve when the value is uploaded", async () => {
|
|
|
46
47
|
|
|
47
48
|
const loadedAccount = await serverNode.load(clientAccount.$jazz.raw.id);
|
|
48
49
|
|
|
49
|
-
expect(loadedAccount).not.toBe(
|
|
50
|
+
expect(loadedAccount).not.toBe(CoValueLoadingState.UNAVAILABLE);
|
|
50
51
|
});
|
|
51
52
|
|
|
52
53
|
test("isMe gets updated correctly when switching accounts", async () => {
|
|
@@ -86,11 +87,13 @@ test("Me gets updated correctly when creating a new account as active", async ()
|
|
|
86
87
|
|
|
87
88
|
test("accounts should sync correctly", async () => {
|
|
88
89
|
const account = await createJazzTestAccount({ isCurrentActiveAccount: true });
|
|
89
|
-
account.profile
|
|
90
|
+
assertLoaded(account.profile);
|
|
91
|
+
account.profile.$jazz.set("name", "test 1");
|
|
90
92
|
const otherAccount = await createJazzTestAccount({
|
|
91
93
|
isCurrentActiveAccount: true,
|
|
92
94
|
});
|
|
93
|
-
otherAccount.profile
|
|
95
|
+
assertLoaded(otherAccount.profile);
|
|
96
|
+
otherAccount.profile.$jazz.set("name", "test 2");
|
|
94
97
|
|
|
95
98
|
await linkAccounts(account, otherAccount);
|
|
96
99
|
|
|
@@ -98,8 +101,14 @@ test("accounts should sync correctly", async () => {
|
|
|
98
101
|
|
|
99
102
|
group.addMember(otherAccount, "writer");
|
|
100
103
|
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
const accountMember = group.members[0]?.account;
|
|
105
|
+
assert(accountMember);
|
|
106
|
+
assertLoaded(accountMember.profile);
|
|
107
|
+
expect(accountMember.profile.name).toBe("test 1");
|
|
108
|
+
const otherAccountMember = group.members[1]?.account;
|
|
109
|
+
assert(otherAccountMember);
|
|
110
|
+
assertLoaded(otherAccountMember.profile);
|
|
111
|
+
expect(otherAccountMember.profile.name).toBe("test 2");
|
|
103
112
|
});
|
|
104
113
|
|
|
105
114
|
test("loading accounts should work", async () => {
|
|
@@ -118,7 +127,7 @@ test("loading accounts should work", async () => {
|
|
|
118
127
|
},
|
|
119
128
|
});
|
|
120
129
|
|
|
121
|
-
|
|
130
|
+
assertLoaded(loadedAccount);
|
|
122
131
|
expect(loadedAccount.profile.name).toBe("test 1");
|
|
123
132
|
});
|
|
124
133
|
|
|
@@ -133,8 +142,9 @@ test("loading raw accounts should work", async () => {
|
|
|
133
142
|
loadAs: account,
|
|
134
143
|
});
|
|
135
144
|
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
assertLoaded(loadedAccount);
|
|
146
|
+
assertLoaded(loadedAccount.profile);
|
|
147
|
+
expect(loadedAccount.profile.name).toBe("test 1");
|
|
138
148
|
});
|
|
139
149
|
|
|
140
150
|
describe("co.profile() schema", () => {
|
|
@@ -221,7 +231,7 @@ test("cannot update account profile properties directly", async () => {
|
|
|
221
231
|
},
|
|
222
232
|
});
|
|
223
233
|
|
|
224
|
-
|
|
234
|
+
assertLoaded(account.profile);
|
|
225
235
|
|
|
226
236
|
// @ts-expect-error - cannot update profile properties directly
|
|
227
237
|
expect(() => (account.profile.name = "test 2")).toThrow(
|
|
@@ -294,7 +304,7 @@ describe("root and profile", () => {
|
|
|
294
304
|
},
|
|
295
305
|
});
|
|
296
306
|
|
|
297
|
-
|
|
307
|
+
assertLoaded(bobAccountLoadedFromAlice);
|
|
298
308
|
|
|
299
309
|
expect(bobAccountLoadedFromAlice.profile.name).toBe("Bob");
|
|
300
310
|
expect(bobAccountLoadedFromAlice.root.name).toBe("Bob");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { CoPlainText, Loaded, co, z } from "../exports.js";
|
|
3
3
|
import { createJazzTestAccount, setupJazzTestSync } from "../testing.js";
|
|
4
|
-
import { waitFor } from "./utils.js";
|
|
4
|
+
import { assertLoaded, waitFor } from "./utils.js";
|
|
5
5
|
|
|
6
6
|
describe("co.discriminatedUnion", () => {
|
|
7
7
|
beforeEach(async () => {
|
|
@@ -277,7 +277,8 @@ describe("co.discriminatedUnion", () => {
|
|
|
277
277
|
|
|
278
278
|
const dog = Dog.create({ type: "dog" });
|
|
279
279
|
const loadedPet = await Pet.load(dog.$jazz.id);
|
|
280
|
-
|
|
280
|
+
assertLoaded(loadedPet);
|
|
281
|
+
expect(loadedPet.type).toEqual("dog");
|
|
281
282
|
});
|
|
282
283
|
|
|
283
284
|
test("subscribe to CoValue instances using the DiscriminatedUnion schema", async () => {
|
|
@@ -343,7 +344,9 @@ describe("co.discriminatedUnion", () => {
|
|
|
343
344
|
|
|
344
345
|
const loadedAnimal = await Animal.load(animal.$jazz.id);
|
|
345
346
|
|
|
346
|
-
|
|
347
|
+
assertLoaded(loadedAnimal);
|
|
348
|
+
assertLoaded(loadedAnimal.breed);
|
|
349
|
+
expect(loadedAnimal.breed.type).toEqual("collie");
|
|
347
350
|
});
|
|
348
351
|
|
|
349
352
|
test("should work with a nested co.discriminatedUnion", async () => {
|
|
@@ -365,6 +368,7 @@ describe("co.discriminatedUnion", () => {
|
|
|
365
368
|
|
|
366
369
|
const loadedAnimal = await Animal.load(animal.$jazz.id);
|
|
367
370
|
|
|
368
|
-
|
|
371
|
+
assertLoaded(loadedAnimal);
|
|
372
|
+
expect(loadedAnimal.type).toEqual("collie");
|
|
369
373
|
});
|
|
370
374
|
});
|