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
|
@@ -1,26 +1,69 @@
|
|
|
1
1
|
import { SessionID } from "cojson";
|
|
2
|
-
import { ItemsSym, TypeSym } from "../internal.js";
|
|
2
|
+
import { CoValueLoadingState, ItemsSym, TypeSym } from "../internal.js";
|
|
3
3
|
import { type Account } from "./account.js";
|
|
4
4
|
import { CoFeedEntry } from "./coFeed.js";
|
|
5
5
|
import { type CoKeys } from "./coMap.js";
|
|
6
6
|
import { type CoValue, type ID } from "./interfaces.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Returns a boolean for whether the given type is a union.
|
|
10
|
+
*
|
|
11
|
+
* Taken from https://github.com/sindresorhus/type-fest/blob/main/source/is-union.d.ts
|
|
12
|
+
*/
|
|
13
|
+
type IsUnion<T, U = T> = (
|
|
14
|
+
[T] extends [never]
|
|
15
|
+
? false
|
|
16
|
+
: T extends any
|
|
17
|
+
? [U] extends [T]
|
|
18
|
+
? false
|
|
19
|
+
: true
|
|
20
|
+
: never
|
|
21
|
+
) extends infer Result
|
|
22
|
+
? boolean extends Result
|
|
23
|
+
? true
|
|
24
|
+
: Result
|
|
25
|
+
: never;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A CoValue that may or may not be loaded.
|
|
10
29
|
*/
|
|
11
|
-
|
|
30
|
+
// T should extend CoValue. We can't enforce this because it would introduce circularity
|
|
31
|
+
// into the definition of CoValues.
|
|
32
|
+
export type MaybeLoaded<T> = T | NotLoaded<T>;
|
|
12
33
|
|
|
13
34
|
/**
|
|
14
|
-
*
|
|
35
|
+
* A CoValue that is not loaded.
|
|
36
|
+
*/
|
|
37
|
+
export type NotLoaded<T> = {
|
|
38
|
+
$jazz: {
|
|
39
|
+
id: ID<T>;
|
|
40
|
+
loadingState:
|
|
41
|
+
| typeof CoValueLoadingState.LOADING
|
|
42
|
+
| typeof CoValueLoadingState.UNAVAILABLE
|
|
43
|
+
| typeof CoValueLoadingState.UNAUTHORIZED;
|
|
44
|
+
};
|
|
45
|
+
$isLoaded: false;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Narrows a maybe-loaded, optional CoValue to a loaded and required CoValue.
|
|
50
|
+
*/
|
|
51
|
+
export type LoadedAndRequired<T> = Exclude<T, NotLoaded<T> | undefined>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Narrows a maybe-loaded, optional CoValue to a loaded and optional CoValue
|
|
55
|
+
*/
|
|
56
|
+
export type AsLoaded<T> = Exclude<T, NotLoaded<T>>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* By default, if a nested CoValue is not loaded, the parent CoValue will not be loaded either.
|
|
60
|
+
* When `$onError: "catch"` is used, the parent CoValue will always be loaded, and an {@link NotLoaded}
|
|
61
|
+
* value will be returned for the nested CoValue if it cannot be loaded.
|
|
15
62
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
63
|
+
* Use `$onError` to handle cases where some data you have requested is inaccessible,
|
|
64
|
+
* similar to a `try...catch` block in your query.
|
|
18
65
|
*/
|
|
19
|
-
type
|
|
20
|
-
x: U,
|
|
21
|
-
) => void
|
|
22
|
-
? false
|
|
23
|
-
: true;
|
|
66
|
+
type OnError = { $onError?: "catch" };
|
|
24
67
|
|
|
25
68
|
export type RefsToResolve<
|
|
26
69
|
V,
|
|
@@ -31,70 +74,73 @@ export type RefsToResolve<
|
|
|
31
74
|
| (DepthLimit extends CurrentDepth["length"]
|
|
32
75
|
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
76
|
any
|
|
34
|
-
:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
V extends ReadonlyArray<infer Item>
|
|
77
|
+
: // Basically V extends CoList - but if we used that we'd introduce circularity into the definition of CoList itself
|
|
78
|
+
V extends ReadonlyArray<infer Item>
|
|
79
|
+
? LoadedAndRequired<Item> extends CoValue
|
|
38
80
|
?
|
|
39
|
-
| {
|
|
81
|
+
| ({
|
|
40
82
|
$each?: RefsToResolve<
|
|
41
|
-
|
|
83
|
+
AsLoaded<Item>,
|
|
84
|
+
DepthLimit,
|
|
85
|
+
[0, ...CurrentDepth]
|
|
86
|
+
>;
|
|
87
|
+
} & OnError)
|
|
88
|
+
| boolean
|
|
89
|
+
: OnError | boolean
|
|
90
|
+
: // Basically V extends CoMap | Group | Account - but if we used that we'd introduce circularity into the definition of CoMap itself
|
|
91
|
+
V extends { [TypeSym]: "CoMap" | "Group" | "Account" }
|
|
92
|
+
?
|
|
93
|
+
| ({
|
|
94
|
+
[Key in CoKeys<V> as LoadedAndRequired<V[Key]> extends CoValue
|
|
95
|
+
? Key
|
|
96
|
+
: never]?: RefsToResolve<
|
|
97
|
+
LoadedAndRequired<V[Key]>,
|
|
42
98
|
DepthLimit,
|
|
43
99
|
[0, ...CurrentDepth]
|
|
44
100
|
>;
|
|
45
|
-
|
|
46
|
-
|
|
101
|
+
} & OnError)
|
|
102
|
+
| (ItemsSym extends keyof V
|
|
103
|
+
? {
|
|
104
|
+
$each: RefsToResolve<
|
|
105
|
+
LoadedAndRequired<V[ItemsSym]>,
|
|
106
|
+
DepthLimit,
|
|
107
|
+
[0, ...CurrentDepth]
|
|
108
|
+
>;
|
|
109
|
+
} & OnError
|
|
110
|
+
: never)
|
|
47
111
|
| boolean
|
|
48
|
-
:
|
|
49
|
-
|
|
112
|
+
: V extends {
|
|
113
|
+
[TypeSym]: "CoStream";
|
|
114
|
+
byMe: CoFeedEntry<infer Item> | undefined;
|
|
115
|
+
}
|
|
50
116
|
?
|
|
51
117
|
| ({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
: never]?: RefsToResolve<
|
|
55
|
-
NonNullable<V[Key]>,
|
|
118
|
+
$each: RefsToResolve<
|
|
119
|
+
AsLoaded<Item>,
|
|
56
120
|
DepthLimit,
|
|
57
121
|
[0, ...CurrentDepth]
|
|
58
122
|
>;
|
|
59
|
-
} &
|
|
60
|
-
| (ItemsSym extends keyof V
|
|
61
|
-
? {
|
|
62
|
-
$each: RefsToResolve<
|
|
63
|
-
NonNullable<V[ItemsSym]>,
|
|
64
|
-
DepthLimit,
|
|
65
|
-
[0, ...CurrentDepth]
|
|
66
|
-
>;
|
|
67
|
-
$onError?: null;
|
|
68
|
-
}
|
|
69
|
-
: never)
|
|
123
|
+
} & OnError)
|
|
70
124
|
| boolean
|
|
71
|
-
: V extends {
|
|
72
|
-
|
|
73
|
-
byMe: CoFeedEntry<infer Item> | undefined;
|
|
74
|
-
}
|
|
75
|
-
?
|
|
76
|
-
| {
|
|
77
|
-
$each: RefsToResolve<
|
|
78
|
-
NotNull<Item>,
|
|
79
|
-
DepthLimit,
|
|
80
|
-
[0, ...CurrentDepth]
|
|
81
|
-
>;
|
|
82
|
-
$onError?: null;
|
|
83
|
-
}
|
|
84
|
-
| boolean
|
|
125
|
+
: V extends { [TypeSym]: "CoPlainText" | "BinaryCoStream" }
|
|
126
|
+
? boolean | OnError
|
|
85
127
|
: boolean);
|
|
86
128
|
|
|
87
|
-
export type RefsToResolveStrict<T, V> = V extends RefsToResolve<T>
|
|
129
|
+
export type RefsToResolveStrict<T, V> = [V] extends [RefsToResolve<T>]
|
|
88
130
|
? RefsToResolve<T>
|
|
89
131
|
: V;
|
|
90
132
|
|
|
91
133
|
export type Resolved<
|
|
92
134
|
T,
|
|
93
135
|
R extends RefsToResolve<T> | undefined = true,
|
|
94
|
-
> = DeeplyLoaded<T, R
|
|
136
|
+
> = DeeplyLoaded<T, R>;
|
|
95
137
|
|
|
96
|
-
|
|
97
|
-
|
|
138
|
+
/**
|
|
139
|
+
* If the resolve query contains `$onError: "catch"`, we return a not loaded value for this nested CoValue.
|
|
140
|
+
* Otherwise, the whole load operation returns a not-loaded value.
|
|
141
|
+
*/
|
|
142
|
+
type OnErrorResolvedValue<V, Depth> = Depth extends { $onError: "catch" }
|
|
143
|
+
? NotLoaded<V>
|
|
98
144
|
: never;
|
|
99
145
|
|
|
100
146
|
type CoMapLikeLoaded<
|
|
@@ -102,21 +148,32 @@ type CoMapLikeLoaded<
|
|
|
102
148
|
Depth,
|
|
103
149
|
DepthLimit extends number,
|
|
104
150
|
CurrentDepth extends number[],
|
|
105
|
-
> =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
151
|
+
> = IsUnion<LoadedAndRequired<V>> extends true
|
|
152
|
+
? // Trigger conditional type distributivity to deeply resolve each member of the union separately
|
|
153
|
+
// Otherwise, deeply loaded values will resolve to `never`
|
|
154
|
+
V extends V
|
|
155
|
+
? CoMapLikeLoaded<
|
|
156
|
+
V,
|
|
157
|
+
Pick<Depth, keyof V & keyof Depth>,
|
|
158
|
+
DepthLimit,
|
|
159
|
+
CurrentDepth
|
|
160
|
+
>
|
|
161
|
+
: never
|
|
162
|
+
: {
|
|
163
|
+
readonly [Key in keyof Omit<Depth, "$onError">]-?: Key extends CoKeys<V>
|
|
164
|
+
? LoadedAndRequired<V[Key]> extends CoValue
|
|
165
|
+
?
|
|
166
|
+
| DeeplyLoaded<
|
|
167
|
+
LoadedAndRequired<V[Key]>,
|
|
168
|
+
Depth[Key],
|
|
169
|
+
DepthLimit,
|
|
170
|
+
[0, ...CurrentDepth]
|
|
171
|
+
>
|
|
172
|
+
| (undefined extends V[Key] ? undefined : never)
|
|
173
|
+
| OnErrorResolvedValue<V[Key], Depth[Key]>
|
|
174
|
+
: never
|
|
175
|
+
: never;
|
|
176
|
+
} & V;
|
|
120
177
|
|
|
121
178
|
export type DeeplyLoaded<
|
|
122
179
|
V,
|
|
@@ -125,22 +182,23 @@ export type DeeplyLoaded<
|
|
|
125
182
|
CurrentDepth extends number[] = [],
|
|
126
183
|
> = DepthLimit extends CurrentDepth["length"]
|
|
127
184
|
? V
|
|
128
|
-
: Depth extends
|
|
185
|
+
: Depth extends true | undefined
|
|
129
186
|
? V
|
|
130
187
|
: // Basically V extends CoList - but if we used that we'd introduce circularity into the definition of CoList itself
|
|
131
188
|
[V] extends [ReadonlyArray<infer Item>]
|
|
132
|
-
?
|
|
189
|
+
? // `& {}` forces TypeScript to simplify the type before performing the `extends CoValue` check.
|
|
190
|
+
// Without it, the check would fail even when it should succeed.
|
|
191
|
+
AsLoaded<Item & {}> extends CoValue
|
|
133
192
|
? Depth extends { $each: infer ItemDepth }
|
|
134
193
|
? // Deeply loaded CoList
|
|
135
194
|
ReadonlyArray<
|
|
136
|
-
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
| onErrorNullEnabled<Depth["$each"]>
|
|
195
|
+
| DeeplyLoaded<
|
|
196
|
+
AsLoaded<Item>,
|
|
197
|
+
ItemDepth,
|
|
198
|
+
DepthLimit,
|
|
199
|
+
[0, ...CurrentDepth]
|
|
200
|
+
>
|
|
201
|
+
| OnErrorResolvedValue<AsLoaded<Item>, Depth["$each"]>
|
|
144
202
|
> &
|
|
145
203
|
V // the CoList base type needs to be intersected after so that built-in methods return the correct narrowed array type
|
|
146
204
|
: never
|
|
@@ -152,17 +210,20 @@ export type DeeplyLoaded<
|
|
|
152
210
|
? V
|
|
153
211
|
: // 1. Record-like CoMap
|
|
154
212
|
ItemsSym extends keyof V
|
|
155
|
-
? // 1.1. Deeply loaded Record-like CoMap with { $each: true | {$onError:
|
|
213
|
+
? // 1.1. Deeply loaded Record-like CoMap with { $each: true | { $onError: 'catch' } }
|
|
156
214
|
Depth extends { $each: infer ItemDepth }
|
|
157
215
|
? {
|
|
158
216
|
readonly [key: string]:
|
|
159
217
|
| DeeplyLoaded<
|
|
160
|
-
|
|
218
|
+
LoadedAndRequired<V[ItemsSym]>,
|
|
161
219
|
ItemDepth,
|
|
162
220
|
DepthLimit,
|
|
163
221
|
[0, ...CurrentDepth]
|
|
164
222
|
>
|
|
165
|
-
|
|
|
223
|
+
| OnErrorResolvedValue<
|
|
224
|
+
LoadedAndRequired<V[ItemsSym]>,
|
|
225
|
+
Depth["$each"]
|
|
226
|
+
>;
|
|
166
227
|
} & V // same reason as in CoList
|
|
167
228
|
: // 1.2. Deeply loaded Record-like CoMap with { [key: string]: true }
|
|
168
229
|
string extends keyof Depth
|
|
@@ -180,12 +241,12 @@ export type DeeplyLoaded<
|
|
|
180
241
|
]
|
|
181
242
|
? // Deeply loaded CoStream
|
|
182
243
|
{
|
|
183
|
-
byMe?: { value:
|
|
184
|
-
inCurrentSession?: { value:
|
|
244
|
+
byMe?: { value: AsLoaded<Item> };
|
|
245
|
+
inCurrentSession?: { value: AsLoaded<Item> };
|
|
185
246
|
perSession: {
|
|
186
|
-
[key: SessionID]: { value:
|
|
247
|
+
[key: SessionID]: { value: AsLoaded<Item> };
|
|
187
248
|
};
|
|
188
|
-
} & { [key: ID<Account>]: { value:
|
|
249
|
+
} & { [key: ID<Account>]: { value: AsLoaded<Item> } } & V // same reason as in CoList
|
|
189
250
|
: [V] extends [
|
|
190
251
|
{
|
|
191
252
|
[TypeSym]: "BinaryCoStream";
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
CoValue,
|
|
15
15
|
CoValueClass,
|
|
16
16
|
ID,
|
|
17
|
+
MaybeLoaded,
|
|
17
18
|
RefEncoded,
|
|
18
19
|
RefsToResolve,
|
|
19
20
|
RefsToResolveStrict,
|
|
@@ -278,7 +279,7 @@ export class Group extends CoValueBase implements CoValue {
|
|
|
278
279
|
resolve?: RefsToResolveStrict<G, R>;
|
|
279
280
|
loadAs?: Account | AnonymousJazzAgent;
|
|
280
281
|
},
|
|
281
|
-
): Promise<Resolved<G, R
|
|
282
|
+
): Promise<MaybeLoaded<Resolved<G, R>>> {
|
|
282
283
|
return loadCoValueWithoutMe(this, id, options);
|
|
283
284
|
}
|
|
284
285
|
|
|
@@ -323,7 +324,7 @@ export class Group extends CoValueBase implements CoValue {
|
|
|
323
324
|
const group = await loadCoValueWithoutMe(this, id, {
|
|
324
325
|
loadAs: options?.loadAs,
|
|
325
326
|
});
|
|
326
|
-
if (!group) {
|
|
327
|
+
if (!group.$isLoaded) {
|
|
327
328
|
throw new Error(`Group with id ${id} not found`);
|
|
328
329
|
}
|
|
329
330
|
return group.$jazz.createInvite(options?.role ?? "reader");
|
|
@@ -11,13 +11,14 @@ import {
|
|
|
11
11
|
type Account,
|
|
12
12
|
CoValue,
|
|
13
13
|
CoValueClassOrSchema,
|
|
14
|
+
CoValueLoadingState,
|
|
14
15
|
ID,
|
|
15
16
|
InstanceOfSchema,
|
|
16
17
|
activeAccountContext,
|
|
17
18
|
coValueClassFromCoValueClassOrSchema,
|
|
18
19
|
loadCoValue,
|
|
19
20
|
} from "../internal.js";
|
|
20
|
-
import { isCoValueId } from "../lib/
|
|
21
|
+
import { isCoValueId } from "../lib/utils.js";
|
|
21
22
|
|
|
22
23
|
export type InboxInvite = `${CoID<MessagesStream>}/${InviteSecret}`;
|
|
23
24
|
type TxKey = `${SessionID}/${number}`;
|
|
@@ -224,7 +225,7 @@ export class Inbox {
|
|
|
224
225
|
messageId: CoID<InboxMessage<CoValue, any>>,
|
|
225
226
|
) => {
|
|
226
227
|
const message = await node.load(messageId);
|
|
227
|
-
if (message ===
|
|
228
|
+
if (message === CoValueLoadingState.UNAVAILABLE) {
|
|
228
229
|
throw new Error(`Inbox: message ${messageId} is unavailable`);
|
|
229
230
|
}
|
|
230
231
|
|
|
@@ -331,7 +332,7 @@ export class Inbox {
|
|
|
331
332
|
static async load(account: Account) {
|
|
332
333
|
const profile = account.profile;
|
|
333
334
|
|
|
334
|
-
if (!profile) {
|
|
335
|
+
if (!profile.$isLoaded) {
|
|
335
336
|
throw new Error("Account profile should already be loaded");
|
|
336
337
|
}
|
|
337
338
|
|
|
@@ -343,7 +344,7 @@ export class Inbox {
|
|
|
343
344
|
|
|
344
345
|
const root = await node.load(profile.inbox as CoID<InboxRoot>);
|
|
345
346
|
|
|
346
|
-
if (root ===
|
|
347
|
+
if (root === CoValueLoadingState.UNAVAILABLE) {
|
|
347
348
|
throw new Error("Inbox not found");
|
|
348
349
|
}
|
|
349
350
|
|
|
@@ -354,9 +355,9 @@ export class Inbox {
|
|
|
354
355
|
]);
|
|
355
356
|
|
|
356
357
|
if (
|
|
357
|
-
messages ===
|
|
358
|
-
processed ===
|
|
359
|
-
failed ===
|
|
358
|
+
messages === CoValueLoadingState.UNAVAILABLE ||
|
|
359
|
+
processed === CoValueLoadingState.UNAVAILABLE ||
|
|
360
|
+
failed === CoValueLoadingState.UNAVAILABLE
|
|
360
361
|
) {
|
|
361
362
|
throw new Error("Inbox not found");
|
|
362
363
|
}
|
|
@@ -421,13 +422,13 @@ export class InboxSender<I extends CoValue, O extends CoValue | undefined> {
|
|
|
421
422
|
inboxOwnerID as unknown as CoID<RawAccount>,
|
|
422
423
|
);
|
|
423
424
|
|
|
424
|
-
if (inboxOwnerRaw ===
|
|
425
|
+
if (inboxOwnerRaw === CoValueLoadingState.UNAVAILABLE) {
|
|
425
426
|
throw new Error("Failed to load the inbox owner");
|
|
426
427
|
}
|
|
427
428
|
|
|
428
429
|
const inboxOwnerProfileRaw = await node.load(inboxOwnerRaw.get("profile")!);
|
|
429
430
|
|
|
430
|
-
if (inboxOwnerProfileRaw ===
|
|
431
|
+
if (inboxOwnerProfileRaw === CoValueLoadingState.UNAVAILABLE) {
|
|
431
432
|
throw new Error("Failed to load the inbox owner profile");
|
|
432
433
|
}
|
|
433
434
|
|
|
@@ -453,7 +454,7 @@ export class InboxSender<I extends CoValue, O extends CoValue | undefined> {
|
|
|
453
454
|
|
|
454
455
|
const messages = await node.load(id);
|
|
455
456
|
|
|
456
|
-
if (messages ===
|
|
457
|
+
if (messages === CoValueLoadingState.UNAVAILABLE) {
|
|
457
458
|
throw new Error("Inbox not found");
|
|
458
459
|
}
|
|
459
460
|
|