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
|
@@ -9,8 +9,11 @@ import {
|
|
|
9
9
|
Account,
|
|
10
10
|
AnonymousJazzAgent,
|
|
11
11
|
CoValueClassOrSchema,
|
|
12
|
+
CoValueLoadingState,
|
|
13
|
+
NotLoadedCoValueState,
|
|
12
14
|
type Group,
|
|
13
15
|
Loaded,
|
|
16
|
+
MaybeLoaded,
|
|
14
17
|
RefsToResolve,
|
|
15
18
|
RefsToResolveStrict,
|
|
16
19
|
RegisteredSchemas,
|
|
@@ -20,6 +23,7 @@ import {
|
|
|
20
23
|
SubscriptionScope,
|
|
21
24
|
type SubscriptionValue,
|
|
22
25
|
TypeSym,
|
|
26
|
+
NotLoaded,
|
|
23
27
|
activeAccountContext,
|
|
24
28
|
coValueClassFromCoValueClassOrSchema,
|
|
25
29
|
getSubscriptionScope,
|
|
@@ -49,6 +53,8 @@ export interface CoValue {
|
|
|
49
53
|
$jazz: {
|
|
50
54
|
/** @category Content */
|
|
51
55
|
readonly id: ID<CoValue>;
|
|
56
|
+
/** @category Content */
|
|
57
|
+
loadingState: typeof CoValueLoadingState.LOADED;
|
|
52
58
|
/** @category Collaboration */
|
|
53
59
|
owner?: Group;
|
|
54
60
|
/** @internal */
|
|
@@ -61,6 +67,11 @@ export interface CoValue {
|
|
|
61
67
|
branchName: string | undefined;
|
|
62
68
|
unstable_merge: () => void;
|
|
63
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Whether the CoValue is loaded. Can be used to distinguish between loaded and {@link NotLoaded} CoValues.
|
|
72
|
+
* For more information about the CoValue's loading state, use {@link $jazz.loadingState}.
|
|
73
|
+
*/
|
|
74
|
+
$isLoaded: true;
|
|
64
75
|
|
|
65
76
|
/** @category Stringifying & Inspection */
|
|
66
77
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -96,9 +107,19 @@ export function isCoValueClass<V extends CoValue>(
|
|
|
96
107
|
*/
|
|
97
108
|
export type ID<T> = string;
|
|
98
109
|
|
|
110
|
+
export function createUnloadedCoValue<T extends CoValue>(
|
|
111
|
+
id: ID<T>,
|
|
112
|
+
loadingState: NotLoadedCoValueState,
|
|
113
|
+
): NotLoaded<T> {
|
|
114
|
+
return {
|
|
115
|
+
$jazz: { id, loadingState },
|
|
116
|
+
$isLoaded: false,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
99
120
|
export function loadCoValueWithoutMe<
|
|
100
121
|
V extends CoValue,
|
|
101
|
-
const R extends RefsToResolve<V
|
|
122
|
+
const R extends RefsToResolve<V> = true,
|
|
102
123
|
>(
|
|
103
124
|
cls: CoValueClass<V>,
|
|
104
125
|
id: ID<CoValue>,
|
|
@@ -108,7 +129,7 @@ export function loadCoValueWithoutMe<
|
|
|
108
129
|
skipRetry?: boolean;
|
|
109
130
|
unstable_branch?: BranchDefinition;
|
|
110
131
|
},
|
|
111
|
-
): Promise<Resolved<V, R
|
|
132
|
+
): Promise<MaybeLoaded<Resolved<V, R>>> {
|
|
112
133
|
return loadCoValue(cls, id, {
|
|
113
134
|
...options,
|
|
114
135
|
loadAs: options?.loadAs ?? activeAccountContext.get(),
|
|
@@ -128,7 +149,7 @@ export function loadCoValue<
|
|
|
128
149
|
skipRetry?: boolean;
|
|
129
150
|
unstable_branch?: BranchDefinition;
|
|
130
151
|
},
|
|
131
|
-
): Promise<Resolved<V, R
|
|
152
|
+
): Promise<MaybeLoaded<Resolved<V, R>>> {
|
|
132
153
|
return new Promise((resolve) => {
|
|
133
154
|
subscribeToCoValue<V, R>(
|
|
134
155
|
cls,
|
|
@@ -139,10 +160,10 @@ export function loadCoValue<
|
|
|
139
160
|
syncResolution: true,
|
|
140
161
|
skipRetry: options.skipRetry,
|
|
141
162
|
onUnavailable: () => {
|
|
142
|
-
resolve(
|
|
163
|
+
resolve(createUnloadedCoValue(id, CoValueLoadingState.UNAVAILABLE));
|
|
143
164
|
},
|
|
144
165
|
onUnauthorized: () => {
|
|
145
|
-
resolve(
|
|
166
|
+
resolve(createUnloadedCoValue(id, CoValueLoadingState.UNAUTHORIZED));
|
|
146
167
|
},
|
|
147
168
|
unstable_branch: options.unstable_branch,
|
|
148
169
|
},
|
|
@@ -176,7 +197,7 @@ export async function ensureCoValueLoaded<
|
|
|
176
197
|
},
|
|
177
198
|
);
|
|
178
199
|
|
|
179
|
-
if (!response) {
|
|
200
|
+
if (!response.$isLoaded) {
|
|
180
201
|
throw new Error("Failed to deeply load CoValue " + existing.$jazz.id);
|
|
181
202
|
}
|
|
182
203
|
|
|
@@ -242,7 +263,7 @@ export function parseSubscribeRestArgs<
|
|
|
242
263
|
|
|
243
264
|
export function subscribeToCoValueWithoutMe<
|
|
244
265
|
V extends CoValue,
|
|
245
|
-
const R extends RefsToResolve<V
|
|
266
|
+
const R extends RefsToResolve<V> = true,
|
|
246
267
|
>(
|
|
247
268
|
cls: CoValueClass<V>,
|
|
248
269
|
id: ID<CoValue>,
|
|
@@ -262,7 +283,7 @@ export function subscribeToCoValueWithoutMe<
|
|
|
262
283
|
|
|
263
284
|
export function subscribeToCoValue<
|
|
264
285
|
V extends CoValue,
|
|
265
|
-
const R extends RefsToResolve<V
|
|
286
|
+
const R extends RefsToResolve<V> = true,
|
|
266
287
|
>(
|
|
267
288
|
cls: CoValueClass<V>,
|
|
268
289
|
id: ID<CoValue>,
|
|
@@ -300,18 +321,18 @@ export function subscribeToCoValue<
|
|
|
300
321
|
const handleUpdate = (value: SubscriptionValue<V, any>) => {
|
|
301
322
|
if (unsubscribed) return;
|
|
302
323
|
|
|
303
|
-
if (value.type ===
|
|
324
|
+
if (value.type === CoValueLoadingState.UNAVAILABLE) {
|
|
304
325
|
options.onUnavailable?.();
|
|
305
326
|
|
|
306
327
|
// Don't log unavailable errors when `loadUnique` or `upsertUnique` are used
|
|
307
328
|
if (!options.skipRetry) {
|
|
308
329
|
console.error(value.toString());
|
|
309
330
|
}
|
|
310
|
-
} else if (value.type ===
|
|
331
|
+
} else if (value.type === CoValueLoadingState.UNAUTHORIZED) {
|
|
311
332
|
options.onUnauthorized?.();
|
|
312
333
|
|
|
313
334
|
console.error(value.toString());
|
|
314
|
-
} else if (value.type ===
|
|
335
|
+
} else if (value.type === CoValueLoadingState.LOADED) {
|
|
315
336
|
listener(value.value as Resolved<V, R>, unsubscribe);
|
|
316
337
|
}
|
|
317
338
|
};
|
|
@@ -472,7 +493,7 @@ export async function unstable_loadUnique<
|
|
|
472
493
|
owner: Account | Group;
|
|
473
494
|
resolve?: ResolveQueryStrict<S, R>;
|
|
474
495
|
},
|
|
475
|
-
): Promise<Loaded<S, R
|
|
496
|
+
): Promise<MaybeLoaded<Loaded<S, R>>> {
|
|
476
497
|
const cls = coValueClassFromCoValueClassOrSchema(schema);
|
|
477
498
|
|
|
478
499
|
if (
|
|
@@ -484,15 +505,14 @@ export async function unstable_loadUnique<
|
|
|
484
505
|
|
|
485
506
|
const header = cls._getUniqueHeader(options.unique, options.owner.$jazz.id);
|
|
486
507
|
|
|
508
|
+
// @ts-expect-error the CoValue class is too generic for TS to infer its instances are CoValues
|
|
487
509
|
return internalLoadUnique(cls, {
|
|
488
510
|
header,
|
|
489
511
|
onCreateWhenMissing: options.onCreateWhenMissing,
|
|
490
|
-
// @ts-expect-error loaded is not compatible with Resolved at type level, but they are the same thing
|
|
491
512
|
onUpdateWhenFound: options.onUpdateWhenFound,
|
|
492
513
|
owner: options.owner,
|
|
493
|
-
// @ts-expect-error loaded is not compatible with Resolved at type level, but they are the same thing
|
|
494
514
|
resolve: options.resolve,
|
|
495
|
-
}) as unknown as Loaded<S, R
|
|
515
|
+
}) as unknown as MaybeLoaded<Loaded<S, R>>;
|
|
496
516
|
}
|
|
497
517
|
|
|
498
518
|
export async function internalLoadUnique<
|
|
@@ -507,7 +527,7 @@ export async function internalLoadUnique<
|
|
|
507
527
|
owner: Account | Group;
|
|
508
528
|
resolve?: RefsToResolveStrict<V, R>;
|
|
509
529
|
},
|
|
510
|
-
): Promise<Resolved<V, R
|
|
530
|
+
): Promise<MaybeLoaded<Resolved<V, R>>> {
|
|
511
531
|
const loadAs = options.owner.$jazz.loadedAs;
|
|
512
532
|
|
|
513
533
|
const node =
|
|
@@ -519,7 +539,7 @@ export async function internalLoadUnique<
|
|
|
519
539
|
// retrying failures
|
|
520
540
|
// This way when we want to upsert we are sure that, if the load failed
|
|
521
541
|
// it failed because the unique value was missing
|
|
522
|
-
await loadCoValueWithoutMe(cls, id, {
|
|
542
|
+
const maybeLoadedCoValue = await loadCoValueWithoutMe(cls, id, {
|
|
523
543
|
skipRetry: true,
|
|
524
544
|
loadAs,
|
|
525
545
|
});
|
|
@@ -539,7 +559,9 @@ export async function internalLoadUnique<
|
|
|
539
559
|
}
|
|
540
560
|
|
|
541
561
|
if (!isAvailable) {
|
|
542
|
-
|
|
562
|
+
// @ts-expect-error the resolve query of the loaded values is not necessarily the same,
|
|
563
|
+
// but we're only returning not-loaded values
|
|
564
|
+
return maybeLoadedCoValue;
|
|
543
565
|
}
|
|
544
566
|
|
|
545
567
|
if (options.onUpdateWhenFound) {
|
|
@@ -549,7 +571,7 @@ export async function internalLoadUnique<
|
|
|
549
571
|
resolve: options.resolve,
|
|
550
572
|
});
|
|
551
573
|
|
|
552
|
-
if (loaded) {
|
|
574
|
+
if (loaded.$isLoaded) {
|
|
553
575
|
// we don't return the update result because
|
|
554
576
|
// we want to run another load to backfill any possible partially loaded
|
|
555
577
|
// values that have been set in the update
|
|
@@ -642,13 +664,13 @@ export async function exportCoValue<
|
|
|
642
664
|
|
|
643
665
|
const value = await new Promise<Loaded<S, R> | null>((resolve) => {
|
|
644
666
|
rootNode.setListener((value) => {
|
|
645
|
-
if (value.type ===
|
|
667
|
+
if (value.type === CoValueLoadingState.UNAVAILABLE) {
|
|
646
668
|
resolve(null);
|
|
647
669
|
console.error(value.toString());
|
|
648
|
-
} else if (value.type ===
|
|
670
|
+
} else if (value.type === CoValueLoadingState.UNAUTHORIZED) {
|
|
649
671
|
resolve(null);
|
|
650
672
|
console.error(value.toString());
|
|
651
|
-
} else if (value.type ===
|
|
673
|
+
} else if (value.type === CoValueLoadingState.LOADED) {
|
|
652
674
|
resolve(value.value as Loaded<S, R>);
|
|
653
675
|
}
|
|
654
676
|
|
|
@@ -679,10 +701,10 @@ function loadContentPiecesFromSubscription(
|
|
|
679
701
|
|
|
680
702
|
valuesExported.add(subscription.id);
|
|
681
703
|
|
|
682
|
-
const
|
|
683
|
-
.core as AvailableCoValueCore;
|
|
704
|
+
const currentValue = subscription.getCurrentValue();
|
|
684
705
|
|
|
685
|
-
if (
|
|
706
|
+
if (typeof currentValue !== "string") {
|
|
707
|
+
const core = currentValue.$jazz.raw.core as AvailableCoValueCore;
|
|
686
708
|
loadContentPiecesFromCoValue(core, valuesExported, contentPieces);
|
|
687
709
|
}
|
|
688
710
|
|
|
@@ -742,7 +764,7 @@ export function unstable_mergeBranch(
|
|
|
742
764
|
}
|
|
743
765
|
|
|
744
766
|
function handleMerge(subscriptionNode: SubscriptionScope<CoValue>) {
|
|
745
|
-
if (subscriptionNode.value.type ===
|
|
767
|
+
if (subscriptionNode.value.type === CoValueLoadingState.LOADED) {
|
|
746
768
|
subscriptionNode.value.value.$jazz.raw.core.mergeBranch();
|
|
747
769
|
}
|
|
748
770
|
|
|
@@ -762,7 +784,7 @@ export async function unstable_mergeBranchWithResolve<
|
|
|
762
784
|
id: ID<CoValue>,
|
|
763
785
|
options: {
|
|
764
786
|
resolve?: ResolveQueryStrict<S, R>;
|
|
765
|
-
loadAs
|
|
787
|
+
loadAs?: Account | AnonymousJazzAgent;
|
|
766
788
|
branch: BranchDefinition;
|
|
767
789
|
},
|
|
768
790
|
) {
|
|
@@ -786,11 +808,11 @@ export async function unstable_mergeBranchWithResolve<
|
|
|
786
808
|
|
|
787
809
|
await new Promise<void>((resolve, reject) => {
|
|
788
810
|
rootNode.setListener((value) => {
|
|
789
|
-
if (value.type ===
|
|
811
|
+
if (value.type === CoValueLoadingState.UNAVAILABLE) {
|
|
790
812
|
reject(new Error("Unable to load the branch. " + value.toString()));
|
|
791
|
-
} else if (value.type ===
|
|
813
|
+
} else if (value.type === CoValueLoadingState.UNAUTHORIZED) {
|
|
792
814
|
reject(new Error("Unable to load the branch. " + value.toString()));
|
|
793
|
-
} else if (value.type ===
|
|
815
|
+
} else if (value.type === CoValueLoadingState.LOADED) {
|
|
794
816
|
resolve();
|
|
795
817
|
}
|
|
796
818
|
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
CoMapSchemaInit,
|
|
15
15
|
CoValueClass,
|
|
16
16
|
CoreCoMapSchema,
|
|
17
|
+
CoValueLoadingState,
|
|
18
|
+
createUnloadedCoValue,
|
|
17
19
|
Group,
|
|
18
20
|
Loaded,
|
|
19
21
|
ResolveQuery,
|
|
@@ -25,7 +27,7 @@ import {
|
|
|
25
27
|
importContentPieces,
|
|
26
28
|
loadCoValue,
|
|
27
29
|
} from "../internal.js";
|
|
28
|
-
import { isCoValueId } from "../lib/
|
|
30
|
+
import { isCoValueId } from "../lib/utils.js";
|
|
29
31
|
import { Account } from "./account.js";
|
|
30
32
|
|
|
31
33
|
type MessageShape = Record<string, AnyZodOrCoValueSchema>;
|
|
@@ -289,7 +291,7 @@ async function handleMessagePayload({
|
|
|
289
291
|
loadAs,
|
|
290
292
|
});
|
|
291
293
|
|
|
292
|
-
if (!madeBy) {
|
|
294
|
+
if (!madeBy.$isLoaded) {
|
|
293
295
|
throw new JazzRequestError("Creator account not found", 400);
|
|
294
296
|
}
|
|
295
297
|
|
|
@@ -301,7 +303,7 @@ async function handleMessagePayload({
|
|
|
301
303
|
loadAs,
|
|
302
304
|
});
|
|
303
305
|
|
|
304
|
-
if (!value) {
|
|
306
|
+
if (!value.$isLoaded) {
|
|
305
307
|
throw new JazzRequestError("Value not found", 400);
|
|
306
308
|
}
|
|
307
309
|
|
|
@@ -375,7 +377,7 @@ export class HttpRoute<
|
|
|
375
377
|
const as = options?.owner ?? Account.getMe();
|
|
376
378
|
|
|
377
379
|
const target = await loadWorkerAccountOrGroup(this.workerId, as);
|
|
378
|
-
if (!target) {
|
|
380
|
+
if (!target.$isLoaded) {
|
|
379
381
|
throw new JazzRequestError("Worker account not found", 400);
|
|
380
382
|
}
|
|
381
383
|
|
|
@@ -619,7 +621,7 @@ async function loadWorkerAccountOrGroup(id: string, loadAs: Account) {
|
|
|
619
621
|
const coValue = await node.loadCoValueCore(id as `co_z${string}`);
|
|
620
622
|
|
|
621
623
|
if (!coValue.isAvailable()) {
|
|
622
|
-
return
|
|
624
|
+
return createUnloadedCoValue(id, CoValueLoadingState.UNAVAILABLE);
|
|
623
625
|
}
|
|
624
626
|
|
|
625
627
|
const content = coValue.getCurrentContent();
|
|
@@ -782,7 +784,7 @@ export async function parseAuthToken(
|
|
|
782
784
|
|
|
783
785
|
const account = await Account.load(id, { loadAs: options?.loadAs });
|
|
784
786
|
|
|
785
|
-
if (!account) {
|
|
787
|
+
if (!account.$isLoaded) {
|
|
786
788
|
return {
|
|
787
789
|
error: {
|
|
788
790
|
message: "Failed to load account",
|
|
@@ -10,6 +10,9 @@ import {
|
|
|
10
10
|
CoValueJazzApi,
|
|
11
11
|
Group,
|
|
12
12
|
ID,
|
|
13
|
+
MaybeLoaded,
|
|
14
|
+
RefsToResolve,
|
|
15
|
+
RefsToResolveStrict,
|
|
13
16
|
Resolved,
|
|
14
17
|
Simplify,
|
|
15
18
|
SubscribeListenerOptions,
|
|
@@ -149,18 +152,17 @@ export abstract class SchemaUnion extends CoValueBase implements CoValue {
|
|
|
149
152
|
/**
|
|
150
153
|
* Load a `SchemaUnion` with a given ID, as a given account.
|
|
151
154
|
*
|
|
152
|
-
* Note: The `resolve` option is not supported for `SchemaUnion`s due to https://github.com/garden-co/jazz/issues/2639
|
|
153
|
-
*
|
|
154
155
|
* @category Subscription & Loading
|
|
155
156
|
*/
|
|
156
|
-
static load<M extends SchemaUnion>(
|
|
157
|
+
static load<M extends SchemaUnion, const R extends RefsToResolve<M> = true>(
|
|
157
158
|
this: CoValueClass<M>,
|
|
158
159
|
id: ID<M>,
|
|
159
160
|
options?: {
|
|
161
|
+
resolve?: RefsToResolveStrict<M, R>;
|
|
160
162
|
loadAs?: Account | AnonymousJazzAgent;
|
|
161
163
|
skipRetry?: boolean;
|
|
162
164
|
},
|
|
163
|
-
): Promise<Resolved<M,
|
|
165
|
+
): Promise<MaybeLoaded<Resolved<M, R>>> {
|
|
164
166
|
return loadCoValueWithoutMe(this, id, options);
|
|
165
167
|
}
|
|
166
168
|
|
|
@@ -173,27 +175,31 @@ export abstract class SchemaUnion extends CoValueBase implements CoValue {
|
|
|
173
175
|
*
|
|
174
176
|
* Also see the `useCoState` hook to reactively subscribe to a CoValue in a React component.
|
|
175
177
|
*
|
|
176
|
-
* Note: The `resolve` option is not supported for `SchemaUnion`s due to https://github.com/garden-co/jazz/issues/2639
|
|
177
|
-
*
|
|
178
178
|
* @category Subscription & Loading
|
|
179
179
|
*/
|
|
180
|
-
static subscribe<
|
|
180
|
+
static subscribe<
|
|
181
|
+
M extends SchemaUnion,
|
|
182
|
+
const R extends RefsToResolve<M> = true,
|
|
183
|
+
>(
|
|
181
184
|
this: CoValueClass<M>,
|
|
182
185
|
id: ID<M>,
|
|
183
|
-
listener: (value: Resolved<M,
|
|
186
|
+
listener: (value: Resolved<M, R>, unsubscribe: () => void) => void,
|
|
184
187
|
): () => void;
|
|
185
|
-
static subscribe<
|
|
188
|
+
static subscribe<
|
|
189
|
+
M extends SchemaUnion,
|
|
190
|
+
const R extends RefsToResolve<M> = true,
|
|
191
|
+
>(
|
|
186
192
|
this: CoValueClass<M>,
|
|
187
193
|
id: ID<M>,
|
|
188
|
-
options: SubscribeListenerOptions<M,
|
|
189
|
-
listener: (value: Resolved<M,
|
|
194
|
+
options: SubscribeListenerOptions<M, R>,
|
|
195
|
+
listener: (value: Resolved<M, R>, unsubscribe: () => void) => void,
|
|
190
196
|
): () => void;
|
|
191
|
-
static subscribe<M extends SchemaUnion
|
|
197
|
+
static subscribe<M extends SchemaUnion, const R extends RefsToResolve<M>>(
|
|
192
198
|
this: CoValueClass<M>,
|
|
193
199
|
id: ID<M>,
|
|
194
|
-
...args: SubscribeRestArgs<M,
|
|
200
|
+
...args: SubscribeRestArgs<M, R>
|
|
195
201
|
): () => void {
|
|
196
202
|
const { options, listener } = parseSubscribeRestArgs(args);
|
|
197
|
-
return subscribeToCoValueWithoutMe<M,
|
|
203
|
+
return subscribeToCoValueWithoutMe<M, R>(this, id, options, listener);
|
|
198
204
|
}
|
|
199
205
|
}
|
package/src/tools/exports.ts
CHANGED
|
@@ -31,6 +31,9 @@ export type {
|
|
|
31
31
|
RefsToResolve,
|
|
32
32
|
RefsToResolveStrict,
|
|
33
33
|
CoMapInit_DEPRECATED as CoMapInit,
|
|
34
|
+
CoMapEdit,
|
|
35
|
+
CoMapEdits,
|
|
36
|
+
LastAndAllCoMapEdits,
|
|
34
37
|
CoFeedEntry,
|
|
35
38
|
SingleCoFeedEntry,
|
|
36
39
|
TextPos,
|
|
@@ -49,6 +52,8 @@ export {
|
|
|
49
52
|
CoPlainText,
|
|
50
53
|
CoRichText,
|
|
51
54
|
Account,
|
|
55
|
+
assertLoaded,
|
|
56
|
+
getLoadedOrUndefined,
|
|
52
57
|
isControlledAccount,
|
|
53
58
|
loadCoValue,
|
|
54
59
|
subscribeToCoValue,
|
|
@@ -57,6 +62,7 @@ export {
|
|
|
57
62
|
exportCoValue,
|
|
58
63
|
importContentPieces,
|
|
59
64
|
Ref,
|
|
65
|
+
createUnloadedCoValue,
|
|
60
66
|
unstable_loadUnique,
|
|
61
67
|
} from "./internal.js";
|
|
62
68
|
|
|
@@ -104,8 +110,12 @@ export type * from "./types.js";
|
|
|
104
110
|
export {
|
|
105
111
|
coValueClassFromCoValueClassOrSchema,
|
|
106
112
|
type InstanceOfSchema,
|
|
107
|
-
type
|
|
113
|
+
type InstanceOfSchemaCoValuesMaybeLoaded,
|
|
114
|
+
type SchemaResolveQuery,
|
|
108
115
|
type CoValueClassOrSchema,
|
|
116
|
+
CoValueLoadingState,
|
|
117
|
+
type MaybeLoaded,
|
|
118
|
+
type NotLoaded,
|
|
109
119
|
type Loaded,
|
|
110
120
|
type BaseAccountShape,
|
|
111
121
|
type DefaultAccountShape,
|
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
ID,
|
|
6
6
|
RefEncoded,
|
|
7
7
|
SubscriptionScope,
|
|
8
|
-
|
|
9
|
-
import {
|
|
8
|
+
LoadedAndRequired,
|
|
10
9
|
accessChildById,
|
|
10
|
+
CoValueLoadingState,
|
|
11
11
|
getSubscriptionScope,
|
|
12
12
|
isRefEncoded,
|
|
13
|
+
createUnloadedCoValue,
|
|
14
|
+
MaybeLoaded,
|
|
13
15
|
} from "../internal.js";
|
|
14
16
|
|
|
15
17
|
export class Ref<out V extends CoValue> {
|
|
@@ -24,10 +26,10 @@ export class Ref<out V extends CoValue> {
|
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
async load(): Promise<V
|
|
29
|
+
async load(): Promise<MaybeLoaded<V>> {
|
|
28
30
|
const subscriptionScope = getSubscriptionScope(this.parent);
|
|
29
31
|
|
|
30
|
-
let node: SubscriptionScope<CoValue> | undefined
|
|
32
|
+
let node: SubscriptionScope<CoValue> | undefined;
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
35
|
* If the parent subscription scope is closed, we can't use it
|
|
@@ -51,25 +53,29 @@ export class Ref<out V extends CoValue> {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
if (!node) {
|
|
54
|
-
return
|
|
56
|
+
return createUnloadedCoValue(this.id, CoValueLoadingState.LOADING);
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
const value = node.value;
|
|
58
60
|
|
|
59
|
-
if (value?.type ===
|
|
61
|
+
if (value?.type === CoValueLoadingState.LOADED) {
|
|
60
62
|
return value.value as V;
|
|
61
63
|
} else {
|
|
62
64
|
return new Promise((resolve) => {
|
|
63
65
|
const unsubscribe = node.subscribe((value) => {
|
|
64
|
-
if (value?.type ===
|
|
66
|
+
if (value?.type === CoValueLoadingState.LOADED) {
|
|
65
67
|
unsubscribe();
|
|
66
68
|
resolve(value.value as V);
|
|
67
|
-
} else if (value?.type ===
|
|
69
|
+
} else if (value?.type === CoValueLoadingState.UNAVAILABLE) {
|
|
68
70
|
unsubscribe();
|
|
69
|
-
resolve(
|
|
70
|
-
|
|
71
|
+
resolve(
|
|
72
|
+
createUnloadedCoValue(this.id, CoValueLoadingState.UNAVAILABLE),
|
|
73
|
+
);
|
|
74
|
+
} else if (value?.type === CoValueLoadingState.UNAUTHORIZED) {
|
|
71
75
|
unsubscribe();
|
|
72
|
-
resolve(
|
|
76
|
+
resolve(
|
|
77
|
+
createUnloadedCoValue(this.id, CoValueLoadingState.UNAUTHORIZED),
|
|
78
|
+
);
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
if (subscriptionScope.closed) {
|
|
@@ -144,6 +150,6 @@ export function makeRefs<Keys extends string | number>(
|
|
|
144
150
|
});
|
|
145
151
|
}
|
|
146
152
|
|
|
147
|
-
export type RefIfCoValue<V> =
|
|
148
|
-
? Ref<
|
|
153
|
+
export type RefIfCoValue<V> = LoadedAndRequired<V> extends CoValue
|
|
154
|
+
? Ref<LoadedAndRequired<V>>
|
|
149
155
|
: never;
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
CoValueFromRaw,
|
|
8
8
|
Group,
|
|
9
9
|
ItemsSym,
|
|
10
|
+
LoadedAndRequired,
|
|
10
11
|
SchemaInit,
|
|
11
12
|
isCoValueClass,
|
|
12
13
|
} from "../internal.js";
|
|
@@ -182,11 +183,11 @@ export function instantiateRefEncodedWithInit<V extends CoValue>(
|
|
|
182
183
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
183
184
|
export type Schema = JsonEncoded | RefEncoded<CoValue> | EncodedAs<any>;
|
|
184
185
|
|
|
185
|
-
export type SchemaFor<Field> =
|
|
186
|
-
? RefEncoded<
|
|
187
|
-
:
|
|
186
|
+
export type SchemaFor<Field> = LoadedAndRequired<Field> extends CoValue
|
|
187
|
+
? RefEncoded<LoadedAndRequired<Field>>
|
|
188
|
+
: LoadedAndRequired<Field> extends JsonValue
|
|
188
189
|
? JsonEncoded
|
|
189
|
-
: EncodedAs<
|
|
190
|
+
: EncodedAs<LoadedAndRequired<Field>>;
|
|
190
191
|
|
|
191
192
|
export type Encoder<V> = {
|
|
192
193
|
encode: (value: V) => JsonValue;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CoreResolveQuery } from "./zodSchema/schemaTypes/CoValueSchema";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Remove getters from an object
|
|
3
5
|
*
|
|
@@ -16,3 +18,16 @@ export function removeGetters<T extends object>(obj: T): Partial<T> {
|
|
|
16
18
|
|
|
17
19
|
return result;
|
|
18
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Adds a CoValue schema's resolve query to a load options object
|
|
24
|
+
* if no resolve query is provided.
|
|
25
|
+
*/
|
|
26
|
+
export function withSchemaResolveQuery<
|
|
27
|
+
const T extends { resolve?: CoreResolveQuery },
|
|
28
|
+
>(loadOptions: T | undefined, schemaResolveQuery: CoreResolveQuery): T {
|
|
29
|
+
const newOptions: CoreResolveQuery = loadOptions ? { ...loadOptions } : {};
|
|
30
|
+
// TODO merge the schema resolve query with the user-provided resolve query
|
|
31
|
+
newOptions.resolve ||= schemaResolveQuery;
|
|
32
|
+
return newOptions as T;
|
|
33
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { RawCoList, RawCoMap } from "cojson";
|
|
2
2
|
import {
|
|
3
3
|
Account,
|
|
4
|
+
AccountSchema,
|
|
4
5
|
CoDiscriminatedUnionSchema,
|
|
5
6
|
CoFeed,
|
|
6
7
|
CoFeedSchema,
|
|
7
8
|
CoList,
|
|
8
9
|
CoListSchema,
|
|
9
10
|
CoMap,
|
|
11
|
+
CoMapSchema,
|
|
10
12
|
CoPlainText,
|
|
11
13
|
CoRichText,
|
|
12
14
|
CoValueClass,
|
|
@@ -15,8 +17,6 @@ import {
|
|
|
15
17
|
CoVectorSchema,
|
|
16
18
|
PlainTextSchema,
|
|
17
19
|
SchemaUnion,
|
|
18
|
-
enrichAccountSchema,
|
|
19
|
-
enrichCoMapSchema,
|
|
20
20
|
isCoValueClass,
|
|
21
21
|
Group,
|
|
22
22
|
CoVector,
|
|
@@ -98,8 +98,8 @@ export function hydrateCoreCoValueSchema<S extends AnyCoreCoValueSchema>(
|
|
|
98
98
|
|
|
99
99
|
const coValueSchema =
|
|
100
100
|
ClassToExtend === Account
|
|
101
|
-
?
|
|
102
|
-
:
|
|
101
|
+
? new AccountSchema(schema as any, coValueClass as any)
|
|
102
|
+
: new CoMapSchema(schema as any, coValueClass as any);
|
|
103
103
|
|
|
104
104
|
return coValueSchema as unknown as CoValueSchemaFromCoreSchema<S>;
|
|
105
105
|
} else if (schema.builtin === "CoList") {
|