jazz-tools 0.18.38 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.svelte-kit/__package__/jazz.class.svelte.d.ts +8 -8
- package/.svelte-kit/__package__/jazz.class.svelte.d.ts.map +1 -1
- package/.svelte-kit/__package__/jazz.class.svelte.js +39 -14
- package/.svelte-kit/__package__/media/image.svelte +6 -5
- package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
- package/.svelte-kit/__package__/tests/AccountCoState.svelte.test-d.d.ts +2 -0
- package/.svelte-kit/__package__/tests/AccountCoState.svelte.test-d.d.ts.map +1 -0
- package/.svelte-kit/__package__/tests/AccountCoState.svelte.test-d.js +19 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test-d.d.ts +2 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test-d.d.ts.map +1 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test-d.js +16 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test.d.ts +2 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test.d.ts.map +1 -0
- package/.svelte-kit/__package__/tests/CoState.svelte.test.js +42 -0
- package/.svelte-kit/__package__/tests/TestCoStateWrapper.svelte +23 -0
- package/.svelte-kit/__package__/tests/TestCoStateWrapper.svelte.d.ts +12 -0
- package/.svelte-kit/__package__/tests/TestCoStateWrapper.svelte.d.ts.map +1 -0
- package/.turbo/turbo-build.log +57 -57
- package/CHANGELOG.md +22 -0
- package/dist/better-auth/database-adapter/index.js +14 -11
- package/dist/better-auth/database-adapter/index.js.map +1 -1
- package/dist/better-auth/database-adapter/repository/generic.d.ts +1 -1
- package/dist/better-auth/database-adapter/repository/generic.d.ts.map +1 -1
- package/dist/better-auth/database-adapter/repository/user.d.ts.map +1 -1
- package/dist/{chunk-OSQ7S47Q.js → chunk-P3YLNFN4.js} +504 -232
- package/dist/chunk-P3YLNFN4.js.map +1 -0
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/media/{chunk-K6GCHLQU.js → chunk-3LKBM3G3.js} +23 -15
- package/dist/media/chunk-3LKBM3G3.js.map +1 -0
- package/dist/media/create-image/browser.d.ts +2 -2
- package/dist/media/create-image/react-native.d.ts +2 -2
- package/dist/media/create-image/server.d.ts +2 -2
- package/dist/media/create-image-factory.d.ts +2 -2
- package/dist/media/index.browser.js +1 -1
- package/dist/media/index.js +1 -1
- package/dist/media/index.native.js +1 -1
- package/dist/media/index.server.js +1 -1
- package/dist/media/utils.d.ts.map +1 -1
- package/dist/react/hooks.d.ts +1 -1
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +31 -15
- package/dist/react/index.js.map +1 -1
- package/dist/react/media/image.d.ts.map +1 -1
- package/dist/react-core/hooks.d.ts +126 -224
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +65 -63
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/subscription-provider.d.ts.map +1 -1
- package/dist/react-core/tests/createCoValueSubscriptionContext.test.d.ts +2 -0
- package/dist/react-core/tests/createCoValueSubscriptionContext.test.d.ts.map +1 -0
- package/dist/react-core/tests/useAccount.selector.test.d.ts +2 -0
- package/dist/react-core/tests/useAccount.selector.test.d.ts.map +1 -0
- package/dist/react-core/tests/useCoState.selector.test.d.ts +2 -0
- package/dist/react-core/tests/useCoState.selector.test.d.ts.map +1 -0
- package/dist/react-native-core/hooks.d.ts +1 -1
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-core/index.js +7 -5
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/react-native-core/media/image.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.d.ts +8 -8
- package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +39 -14
- package/dist/svelte/media/image.svelte +6 -5
- package/dist/svelte/media/image.svelte.d.ts.map +1 -1
- package/dist/svelte/tests/AccountCoState.svelte.test-d.d.ts +2 -0
- package/dist/svelte/tests/AccountCoState.svelte.test-d.d.ts.map +1 -0
- package/dist/svelte/tests/AccountCoState.svelte.test-d.js +19 -0
- package/dist/svelte/tests/CoState.svelte.test-d.d.ts +2 -0
- package/dist/svelte/tests/CoState.svelte.test-d.d.ts.map +1 -0
- package/dist/svelte/tests/CoState.svelte.test-d.js +16 -0
- package/dist/svelte/tests/CoState.svelte.test.d.ts +2 -0
- package/dist/svelte/tests/CoState.svelte.test.d.ts.map +1 -0
- package/dist/svelte/tests/CoState.svelte.test.js +42 -0
- package/dist/svelte/tests/TestCoStateWrapper.svelte +23 -0
- package/dist/svelte/tests/TestCoStateWrapper.svelte.d.ts +12 -0
- package/dist/svelte/tests/TestCoStateWrapper.svelte.d.ts.map +1 -0
- package/dist/testing.js +3 -1
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/CoValueBase.d.ts +4 -1
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
- package/dist/tools/coValues/account.d.ts +6 -6
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts +5 -5
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts +9 -8
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts +17 -17
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/coPlainText.d.ts +3 -3
- package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
- package/dist/tools/coValues/coVector.d.ts +3 -3
- package/dist/tools/coValues/coVector.d.ts.map +1 -1
- package/dist/tools/coValues/deepLoading.d.ts +66 -36
- package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
- package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
- package/dist/tools/coValues/extensions/imageDef.d.ts.map +1 -1
- package/dist/tools/coValues/group.d.ts +2 -2
- package/dist/tools/coValues/group.d.ts.map +1 -1
- package/dist/tools/coValues/inbox.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +14 -6
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/request.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +2 -2
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +3 -3
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/refs.d.ts +3 -3
- package/dist/tools/implementation/refs.d.ts.map +1 -1
- package/dist/tools/implementation/schema.d.ts +2 -2
- package/dist/tools/implementation/schema.d.ts.map +1 -1
- package/dist/tools/implementation/schemaUtils.d.ts +8 -0
- package/dist/tools/implementation/schemaUtils.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +33 -18
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +5 -4
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +23 -12
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +29 -18
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +39 -22
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +30 -19
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts +5 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +6 -5
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +3 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +3 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +3 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +3 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +3 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.d.ts +22 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +4 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.d.ts +9 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts +7 -6
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +3 -3
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/lib/utils.d.ts +14 -0
- package/dist/tools/lib/utils.d.ts.map +1 -0
- package/dist/tools/lib/utils.test.d.ts +2 -0
- package/dist/tools/lib/utils.test.d.ts.map +1 -0
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +3 -2
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
- package/dist/tools/subscribe/JazzError.d.ts +4 -3
- package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts +6 -5
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/index.d.ts.map +1 -1
- package/dist/tools/subscribe/types.d.ts +23 -3
- package/dist/tools/subscribe/types.d.ts.map +1 -1
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts +3 -2
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/schema.resolved.test.d.ts +2 -0
- package/dist/tools/tests/schema.resolved.test.d.ts.map +1 -0
- package/dist/tools/tests/utils.d.ts +2 -1
- package/dist/tools/tests/utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/better-auth/database-adapter/index.ts +2 -2
- package/src/better-auth/database-adapter/repository/account.ts +3 -3
- package/src/better-auth/database-adapter/repository/generic.ts +9 -6
- package/src/better-auth/database-adapter/repository/user.ts +6 -2
- package/src/better-auth/database-adapter/schema.ts +1 -1
- package/src/better-auth/database-adapter/tests/index.test.ts +3 -4
- package/src/inspector/tests/viewer/history-view.test.tsx +6 -2
- package/src/media/utils.test.ts +5 -0
- package/src/media/utils.ts +25 -16
- package/src/react/hooks.tsx +2 -2
- package/src/react/index.ts +2 -2
- package/src/react/media/image.tsx +10 -2
- package/src/react/tests/useAcceptInvite.test.ts +3 -1
- package/src/react-core/hooks.ts +226 -304
- package/src/react-core/subscription-provider.tsx +14 -7
- package/src/react-core/tests/createCoValueSubscriptionContext.test.tsx +233 -0
- package/src/react-core/tests/subscription.bench.tsx +32 -15
- package/src/react-core/tests/{useAccountWithSelector.test.ts → useAccount.selector.test.ts} +72 -24
- package/src/react-core/tests/useAccount.test.ts +92 -106
- package/src/react-core/tests/{useCoStateWithSelector.test.ts → useCoState.selector.test.ts} +23 -8
- package/src/react-core/tests/useCoState.test.ts +173 -49
- package/src/react-core/tests/useInboxSender.test.ts +3 -1
- package/src/react-core/tests/usePassPhraseAuth.test.ts +11 -82
- package/src/react-core/tests/useSubscriptionSelector.test.ts +48 -14
- package/src/react-native-core/hooks.tsx +2 -2
- package/src/react-native-core/media/image.tsx +3 -1
- package/src/svelte/jazz.class.svelte.ts +103 -27
- package/src/svelte/media/image.svelte +6 -5
- package/src/svelte/tests/AccountCoState.svelte.test-d.ts +23 -0
- package/src/svelte/tests/CoState.svelte.test-d.ts +20 -0
- package/src/svelte/tests/CoState.svelte.test.ts +57 -0
- package/src/svelte/tests/TestCoStateWrapper.svelte +23 -0
- package/src/tools/coValues/CoValueBase.ts +12 -0
- package/src/tools/coValues/account.ts +17 -12
- package/src/tools/coValues/coFeed.ts +38 -15
- package/src/tools/coValues/coList.ts +16 -11
- package/src/tools/coValues/coMap.ts +15 -14
- package/src/tools/coValues/coPlainText.ts +6 -3
- package/src/tools/coValues/coVector.ts +6 -5
- package/src/tools/coValues/deepLoading.ts +98 -51
- package/src/tools/coValues/group.ts +3 -2
- package/src/tools/coValues/inbox.ts +11 -10
- package/src/tools/coValues/interfaces.ts +49 -27
- package/src/tools/coValues/request.ts +8 -6
- package/src/tools/coValues/schemaUnion.ts +2 -1
- package/src/tools/exports.ts +11 -1
- package/src/tools/implementation/refs.ts +19 -13
- package/src/tools/implementation/schema.ts +5 -4
- package/src/tools/implementation/schemaUtils.ts +15 -0
- package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +4 -4
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +131 -95
- package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +19 -9
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +73 -22
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +86 -28
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +204 -148
- package/src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts +1 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +71 -27
- package/src/tools/implementation/zodSchema/schemaTypes/CoValueSchema.ts +7 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +8 -6
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +4 -1
- package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +4 -1
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +4 -1
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +4 -1
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +3 -0
- package/src/tools/implementation/zodSchema/typeConverters/{InstanceOfSchemaCoValuesNullable.ts → InstanceOfSchemaCoValuesMaybeLoaded.ts} +47 -39
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +4 -0
- package/src/tools/implementation/zodSchema/typeConverters/{InstanceOrPrimitiveOfSchemaCoValuesNullable.ts → InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.ts} +7 -3
- package/src/tools/implementation/zodSchema/zodSchema.ts +15 -7
- package/src/tools/internal.ts +3 -3
- package/src/tools/lib/utils.test.ts +56 -0
- package/src/tools/lib/utils.ts +32 -0
- package/src/tools/subscribe/CoValueCoreSubscription.ts +13 -8
- package/src/tools/subscribe/JazzError.ts +8 -2
- package/src/tools/subscribe/SubscriptionScope.ts +55 -44
- package/src/tools/subscribe/index.ts +12 -4
- package/src/tools/subscribe/types.ts +36 -2
- package/src/tools/subscribe/utils.ts +2 -1
- package/src/tools/testing.ts +5 -0
- package/src/tools/tests/CoValueCoreSubscription.test.ts +10 -4
- package/src/tools/tests/ContextManager.test.ts +12 -5
- package/src/tools/tests/account.test.ts +22 -12
- package/src/tools/tests/coDiscriminatedUnion.test.ts +8 -4
- package/src/tools/tests/coFeed.branch.test.ts +48 -32
- package/src/tools/tests/coFeed.test-d.ts +17 -10
- package/src/tools/tests/coFeed.test.ts +52 -30
- package/src/tools/tests/coList.branch.test.ts +21 -21
- package/src/tools/tests/coList.test-d.ts +39 -23
- package/src/tools/tests/coList.test.ts +51 -25
- package/src/tools/tests/coList.unique.test.ts +34 -29
- package/src/tools/tests/coMap.branch.test.ts +20 -21
- package/src/tools/tests/coMap.record.test-d.ts +28 -26
- package/src/tools/tests/coMap.record.test.ts +30 -20
- package/src/tools/tests/coMap.test-d.ts +31 -29
- package/src/tools/tests/coMap.test.ts +67 -40
- package/src/tools/tests/coMap.unique.test.ts +25 -24
- package/src/tools/tests/coVector.test.ts +29 -15
- package/src/tools/tests/createContext.test.ts +5 -3
- package/src/tools/tests/deepLoading.test.ts +314 -117
- package/src/tools/tests/exportImport.test.ts +16 -15
- package/src/tools/tests/groupsAndAccounts.test.ts +39 -16
- package/src/tools/tests/inbox.test.ts +3 -1
- package/src/tools/tests/load.test.ts +29 -23
- package/src/tools/tests/patterns/quest.test.ts +3 -2
- package/src/tools/tests/patterns/requestToJoin.test.ts +17 -17
- package/src/tools/tests/request.test.ts +12 -2
- package/src/tools/tests/schema.resolved.test.ts +723 -0
- package/src/tools/tests/schemaUnion.test.ts +7 -3
- package/src/tools/tests/subscribe.test.ts +39 -21
- package/src/tools/tests/testing.test.ts +3 -2
- package/src/tools/tests/utils.ts +15 -2
- package/dist/chunk-OSQ7S47Q.js.map +0 -1
- package/dist/media/chunk-K6GCHLQU.js.map +0 -1
- package/dist/react-core/tests/useAccountWithSelector.test.d.ts +0 -2
- package/dist/react-core/tests/useAccountWithSelector.test.d.ts.map +0 -1
- package/dist/react-core/tests/useCoStateWithSelector.test.d.ts +0 -2
- package/dist/react-core/tests/useCoStateWithSelector.test.d.ts.map +0 -1
- package/dist/tools/implementation/errors.d.ts +0 -2
- package/dist/tools/implementation/errors.d.ts.map +0 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +0 -19
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +0 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +0 -5
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +0 -1
- package/dist/tools/lib/id.d.ts +0 -2
- package/dist/tools/lib/id.d.ts.map +0 -1
- package/src/tools/implementation/errors.ts +0 -1
- package/src/tools/lib/id.ts +0 -3
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
DiscriminableCoValueSchemaDefinition,
|
|
7
7
|
DiscriminableCoreCoValueSchema,
|
|
8
8
|
Group,
|
|
9
|
+
MaybeLoaded,
|
|
9
10
|
RefsToResolve,
|
|
10
11
|
RefsToResolveStrict,
|
|
11
12
|
Resolved,
|
|
@@ -18,20 +19,44 @@ import {
|
|
|
18
19
|
unstable_mergeBranchWithResolve,
|
|
19
20
|
} from "../../../internal.js";
|
|
20
21
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
|
21
|
-
import { removeGetters } from "../../schemaUtils.js";
|
|
22
|
+
import { removeGetters, withSchemaResolveQuery } from "../../schemaUtils.js";
|
|
22
23
|
import { CoMapSchemaInit } from "../typeConverters/CoFieldSchemaInit.js";
|
|
23
24
|
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
|
24
|
-
import {
|
|
25
|
+
import { InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.js";
|
|
25
26
|
import { z } from "../zodReExport.js";
|
|
26
27
|
import { AnyZodOrCoValueSchema, AnyZodSchema } from "../zodSchema.js";
|
|
27
28
|
import { CoOptionalSchema } from "./CoOptionalSchema.js";
|
|
28
|
-
import { CoreCoValueSchema } from "./CoValueSchema.js";
|
|
29
|
+
import { CoreCoValueSchema, CoreResolveQuery } from "./CoValueSchema.js";
|
|
29
30
|
|
|
30
|
-
export
|
|
31
|
+
export class CoMapSchema<
|
|
31
32
|
Shape extends z.core.$ZodLooseShape,
|
|
32
33
|
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
|
33
34
|
Owner extends Account | Group = Account | Group,
|
|
34
|
-
|
|
35
|
+
DefaultResolveQuery extends CoreResolveQuery = true,
|
|
36
|
+
> implements CoreCoMapSchema<Shape, CatchAll>
|
|
37
|
+
{
|
|
38
|
+
collaborative = true as const;
|
|
39
|
+
builtin = "CoMap" as const;
|
|
40
|
+
shape: Shape;
|
|
41
|
+
catchAll?: CatchAll;
|
|
42
|
+
getDefinition: () => CoMapSchemaDefinition;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Default resolve query to be used when loading instances of this schema.
|
|
46
|
+
* This resolve query will be used when no resolve query is provided to the load method.
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
resolveQuery: DefaultResolveQuery = true as DefaultResolveQuery;
|
|
50
|
+
|
|
51
|
+
constructor(
|
|
52
|
+
coreSchema: CoreCoMapSchema<Shape, CatchAll>,
|
|
53
|
+
private coValueClass: typeof CoMap,
|
|
54
|
+
) {
|
|
55
|
+
this.shape = coreSchema.shape;
|
|
56
|
+
this.catchAll = coreSchema.catchAll;
|
|
57
|
+
this.getDefinition = coreSchema.getDefinition;
|
|
58
|
+
}
|
|
59
|
+
|
|
35
60
|
create(
|
|
36
61
|
init: CoMapSchemaInit<Shape>,
|
|
37
62
|
options?:
|
|
@@ -51,107 +76,155 @@ export interface CoMapSchema<
|
|
|
51
76
|
}
|
|
52
77
|
| Owner,
|
|
53
78
|
): CoMapInstanceShape<Shape, CatchAll> & CoMap;
|
|
79
|
+
create(...args: [any, ...any[]]) {
|
|
80
|
+
return this.coValueClass.create(...args);
|
|
81
|
+
}
|
|
54
82
|
|
|
55
83
|
load<
|
|
56
84
|
const R extends RefsToResolve<
|
|
57
|
-
Simplify<
|
|
58
|
-
|
|
85
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap
|
|
86
|
+
// @ts-expect-error
|
|
87
|
+
> = DefaultResolveQuery,
|
|
59
88
|
>(
|
|
60
89
|
id: string,
|
|
61
90
|
options?: {
|
|
62
91
|
resolve?: RefsToResolveStrict<
|
|
63
|
-
Simplify<
|
|
92
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
|
|
64
93
|
R
|
|
65
94
|
>;
|
|
66
95
|
loadAs?: Account | AnonymousJazzAgent;
|
|
67
96
|
skipRetry?: boolean;
|
|
68
97
|
unstable_branch?: BranchDefinition;
|
|
69
98
|
},
|
|
70
|
-
): Promise<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
99
|
+
): Promise<
|
|
100
|
+
MaybeLoaded<
|
|
101
|
+
Resolved<Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap, R>
|
|
102
|
+
>
|
|
103
|
+
> {
|
|
104
|
+
// @ts-expect-error
|
|
105
|
+
return this.coValueClass.load(
|
|
106
|
+
id,
|
|
107
|
+
// @ts-expect-error
|
|
108
|
+
withSchemaResolveQuery(options, this.resolveQuery),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
74
111
|
|
|
75
112
|
unstable_merge<
|
|
76
113
|
const R extends RefsToResolve<
|
|
77
|
-
Simplify<
|
|
78
|
-
|
|
114
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap
|
|
115
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
116
|
+
> = DefaultResolveQuery,
|
|
79
117
|
>(
|
|
80
118
|
id: string,
|
|
81
|
-
options
|
|
119
|
+
options: {
|
|
82
120
|
resolve?: RefsToResolveStrict<
|
|
83
|
-
Simplify<
|
|
121
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
|
|
84
122
|
R
|
|
85
123
|
>;
|
|
86
124
|
loadAs?: Account | AnonymousJazzAgent;
|
|
87
125
|
branch: BranchDefinition;
|
|
88
126
|
},
|
|
89
|
-
): Promise<void
|
|
127
|
+
): Promise<void> {
|
|
128
|
+
return unstable_mergeBranchWithResolve(
|
|
129
|
+
this.coValueClass,
|
|
130
|
+
id,
|
|
131
|
+
// @ts-expect-error
|
|
132
|
+
withSchemaResolveQuery(options, this.resolveQuery),
|
|
133
|
+
);
|
|
134
|
+
}
|
|
90
135
|
|
|
91
136
|
subscribe<
|
|
92
137
|
const R extends RefsToResolve<
|
|
93
|
-
Simplify<
|
|
94
|
-
|
|
138
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap
|
|
139
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
140
|
+
> = DefaultResolveQuery,
|
|
95
141
|
>(
|
|
96
142
|
id: string,
|
|
97
143
|
options: SubscribeListenerOptions<
|
|
98
|
-
Simplify<
|
|
144
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
|
|
99
145
|
R
|
|
100
146
|
>,
|
|
101
147
|
listener: (
|
|
102
148
|
value: Resolved<
|
|
103
|
-
Simplify<
|
|
149
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
|
|
104
150
|
R
|
|
105
151
|
>,
|
|
106
152
|
unsubscribe: () => void,
|
|
107
153
|
) => void,
|
|
108
|
-
): () => void
|
|
154
|
+
): () => void {
|
|
155
|
+
// @ts-expect-error
|
|
156
|
+
return this.coValueClass.subscribe(
|
|
157
|
+
id,
|
|
158
|
+
withSchemaResolveQuery(options, this.resolveQuery),
|
|
159
|
+
listener,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
109
162
|
|
|
110
163
|
/** @deprecated Use `CoMap.upsertUnique` and `CoMap.loadUnique` instead. */
|
|
111
164
|
findUnique(
|
|
112
165
|
unique: CoValueUniqueness["uniqueness"],
|
|
113
166
|
ownerID: string,
|
|
114
167
|
as?: Account | Group | AnonymousJazzAgent,
|
|
115
|
-
): string
|
|
168
|
+
): string {
|
|
169
|
+
return this.coValueClass.findUnique(unique, ownerID, as);
|
|
170
|
+
}
|
|
116
171
|
|
|
117
|
-
upsertUnique
|
|
172
|
+
upsertUnique<
|
|
118
173
|
const R extends RefsToResolve<
|
|
119
|
-
Simplify<
|
|
120
|
-
|
|
174
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap
|
|
175
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
176
|
+
> = DefaultResolveQuery,
|
|
121
177
|
>(options: {
|
|
122
178
|
value: Simplify<CoMapSchemaInit<Shape>>;
|
|
123
179
|
unique: CoValueUniqueness["uniqueness"];
|
|
124
180
|
owner: Owner;
|
|
125
181
|
resolve?: RefsToResolveStrict<
|
|
126
|
-
Simplify<
|
|
182
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
|
|
127
183
|
R
|
|
128
184
|
>;
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
185
|
+
}): Promise<
|
|
186
|
+
MaybeLoaded<
|
|
187
|
+
Resolved<Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap, R>
|
|
188
|
+
>
|
|
189
|
+
> {
|
|
190
|
+
// @ts-expect-error
|
|
191
|
+
return this.coValueClass.upsertUnique(
|
|
192
|
+
// @ts-expect-error
|
|
193
|
+
withSchemaResolveQuery(options, this.resolveQuery),
|
|
194
|
+
);
|
|
195
|
+
}
|
|
133
196
|
|
|
134
197
|
loadUnique<
|
|
135
198
|
const R extends RefsToResolve<
|
|
136
|
-
Simplify<
|
|
137
|
-
|
|
199
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap
|
|
200
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
201
|
+
> = DefaultResolveQuery,
|
|
138
202
|
>(
|
|
139
203
|
unique: CoValueUniqueness["uniqueness"],
|
|
140
204
|
ownerID: string,
|
|
141
205
|
options?: {
|
|
142
206
|
resolve?: RefsToResolveStrict<
|
|
143
|
-
Simplify<
|
|
207
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
|
|
144
208
|
R
|
|
145
209
|
>;
|
|
146
210
|
loadAs?: Account | AnonymousJazzAgent;
|
|
147
211
|
},
|
|
148
|
-
): Promise<
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
212
|
+
): Promise<
|
|
213
|
+
MaybeLoaded<
|
|
214
|
+
Resolved<Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap, R>
|
|
215
|
+
>
|
|
216
|
+
> {
|
|
217
|
+
// @ts-expect-error
|
|
218
|
+
return this.coValueClass.loadUnique(
|
|
219
|
+
unique,
|
|
220
|
+
ownerID,
|
|
221
|
+
// @ts-expect-error
|
|
222
|
+
withSchemaResolveQuery(options, this.resolveQuery),
|
|
223
|
+
);
|
|
224
|
+
}
|
|
152
225
|
|
|
153
226
|
/**
|
|
154
|
-
* @deprecated
|
|
227
|
+
* @deprecated `co.map().catchall` will be removed in an upcoming version.
|
|
155
228
|
*
|
|
156
229
|
* Use a `co.record` nested inside a `co.map` if you need to store key-value properties.
|
|
157
230
|
*
|
|
@@ -169,20 +242,31 @@ export interface CoMapSchema<
|
|
|
169
242
|
* });
|
|
170
243
|
* ```
|
|
171
244
|
*/
|
|
172
|
-
catchall<T extends AnyZodOrCoValueSchema>(schema: T): CoMapSchema<Shape, T
|
|
245
|
+
catchall<T extends AnyZodOrCoValueSchema>(schema: T): CoMapSchema<Shape, T> {
|
|
246
|
+
const schemaWithCatchAll = createCoreCoMapSchema(this.shape, schema);
|
|
247
|
+
return hydrateCoreCoValueSchema(schemaWithCatchAll);
|
|
248
|
+
}
|
|
173
249
|
|
|
174
250
|
withMigration(
|
|
175
251
|
migration: (
|
|
176
252
|
value: Resolved<
|
|
177
|
-
Simplify<
|
|
253
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
|
|
178
254
|
true
|
|
179
255
|
>,
|
|
180
256
|
) => undefined,
|
|
181
|
-
): CoMapSchema<Shape, CatchAll, Owner
|
|
257
|
+
): CoMapSchema<Shape, CatchAll, Owner, DefaultResolveQuery> {
|
|
258
|
+
// @ts-expect-error
|
|
259
|
+
this.coValueClass.prototype.migrate = migration;
|
|
260
|
+
return this;
|
|
261
|
+
}
|
|
182
262
|
|
|
183
|
-
getCoValueClass
|
|
263
|
+
getCoValueClass(): typeof CoMap {
|
|
264
|
+
return this.coValueClass;
|
|
265
|
+
}
|
|
184
266
|
|
|
185
|
-
optional(): CoOptionalSchema<this
|
|
267
|
+
optional(): CoOptionalSchema<this> {
|
|
268
|
+
return coOptionalDefiner(this);
|
|
269
|
+
}
|
|
186
270
|
|
|
187
271
|
/**
|
|
188
272
|
* Creates a new CoMap schema by picking the specified keys from the original schema.
|
|
@@ -192,7 +276,19 @@ export interface CoMapSchema<
|
|
|
192
276
|
*/
|
|
193
277
|
pick<Keys extends keyof Shape>(
|
|
194
278
|
keys: { [key in Keys]: true },
|
|
195
|
-
): CoMapSchema<Simplify<Pick<Shape, Keys>>, unknown, Owner
|
|
279
|
+
): CoMapSchema<Simplify<Pick<Shape, Keys>>, unknown, Owner> {
|
|
280
|
+
const keysSet = new Set(Object.keys(keys));
|
|
281
|
+
const pickedShape: Record<string, AnyZodOrCoValueSchema> = {};
|
|
282
|
+
|
|
283
|
+
for (const [key, value] of Object.entries(this.shape)) {
|
|
284
|
+
if (keysSet.has(key)) {
|
|
285
|
+
pickedShape[key] = value;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// @ts-expect-error the picked shape contains all required keys
|
|
290
|
+
return coMapDefiner(pickedShape);
|
|
291
|
+
}
|
|
196
292
|
|
|
197
293
|
/**
|
|
198
294
|
* Creates a new CoMap schema by making all fields optional.
|
|
@@ -200,8 +296,61 @@ export interface CoMapSchema<
|
|
|
200
296
|
* @returns A new CoMap schema with all fields optional.
|
|
201
297
|
*/
|
|
202
298
|
partial<Keys extends keyof Shape = keyof Shape>(
|
|
203
|
-
keys?: {
|
|
204
|
-
|
|
299
|
+
keys?: {
|
|
300
|
+
[key in Keys]: true;
|
|
301
|
+
},
|
|
302
|
+
): CoMapSchema<PartialShape<Shape, Keys>, CatchAll, Owner> {
|
|
303
|
+
const partialShape: Record<string, AnyZodOrCoValueSchema> = {};
|
|
304
|
+
|
|
305
|
+
for (const [key, value] of Object.entries(this.shape)) {
|
|
306
|
+
if (keys && !keys[key as Keys]) {
|
|
307
|
+
partialShape[key] = value;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (isAnyCoValueSchema(value)) {
|
|
312
|
+
partialShape[key] = coOptionalDefiner(value);
|
|
313
|
+
} else {
|
|
314
|
+
partialShape[key] = z.optional(this.shape[key]);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const partialCoMapSchema = coMapDefiner(partialShape);
|
|
319
|
+
if (this.catchAll) {
|
|
320
|
+
// @ts-expect-error the partial shape contains all required keys
|
|
321
|
+
return partialCoMapSchema.catchall(
|
|
322
|
+
this.catchAll as unknown as AnyZodOrCoValueSchema,
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
// @ts-expect-error the partial shape contains all required keys
|
|
326
|
+
return partialCoMapSchema;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Adds a default resolve query to be used when loading instances of this schema.
|
|
331
|
+
* This resolve query will be used when no resolve query is provided to the load method.
|
|
332
|
+
*/
|
|
333
|
+
resolved<
|
|
334
|
+
const R extends RefsToResolve<
|
|
335
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap
|
|
336
|
+
> = true,
|
|
337
|
+
>(
|
|
338
|
+
resolveQuery: RefsToResolveStrict<
|
|
339
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
|
|
340
|
+
R
|
|
341
|
+
>,
|
|
342
|
+
): CoMapSchema<Shape, CatchAll, Owner, R> {
|
|
343
|
+
const coreSchema: CoreCoMapSchema<Shape, CatchAll> = createCoreCoMapSchema(
|
|
344
|
+
this.shape,
|
|
345
|
+
this.catchAll,
|
|
346
|
+
);
|
|
347
|
+
const copy = new CoMapSchema<Shape, CatchAll, Owner, R>(
|
|
348
|
+
coreSchema,
|
|
349
|
+
this.coValueClass,
|
|
350
|
+
);
|
|
351
|
+
copy.resolveQuery = resolveQuery as R;
|
|
352
|
+
return copy;
|
|
353
|
+
}
|
|
205
354
|
}
|
|
206
355
|
|
|
207
356
|
export function createCoreCoMapSchema<
|
|
@@ -238,104 +387,10 @@ export function createCoreCoMapSchema<
|
|
|
238
387
|
return propValues;
|
|
239
388
|
},
|
|
240
389
|
}),
|
|
390
|
+
resolveQuery: true as const,
|
|
241
391
|
};
|
|
242
392
|
}
|
|
243
393
|
|
|
244
|
-
export function enrichCoMapSchema<
|
|
245
|
-
Shape extends z.core.$ZodLooseShape,
|
|
246
|
-
CatchAll extends AnyZodOrCoValueSchema | unknown,
|
|
247
|
-
>(
|
|
248
|
-
schema: CoreCoMapSchema<Shape, CatchAll>,
|
|
249
|
-
coValueClass: typeof CoMap,
|
|
250
|
-
): CoMapSchema<Shape, CatchAll> {
|
|
251
|
-
const coValueSchema = Object.assign(schema, {
|
|
252
|
-
create: (...args: [any, ...any[]]) => {
|
|
253
|
-
return coValueClass.create(...args);
|
|
254
|
-
},
|
|
255
|
-
load: (...args: [any, ...any[]]) => {
|
|
256
|
-
return coValueClass.load(...args);
|
|
257
|
-
},
|
|
258
|
-
subscribe: (...args: [any, ...any[]]) => {
|
|
259
|
-
// @ts-expect-error
|
|
260
|
-
return coValueClass.subscribe(...args);
|
|
261
|
-
},
|
|
262
|
-
findUnique: (...args: [any, ...any[]]) => {
|
|
263
|
-
// @ts-expect-error
|
|
264
|
-
return coValueClass.findUnique(...args);
|
|
265
|
-
},
|
|
266
|
-
upsertUnique: (...args: [any, ...any[]]) => {
|
|
267
|
-
// @ts-expect-error
|
|
268
|
-
return coValueClass.upsertUnique(...args);
|
|
269
|
-
},
|
|
270
|
-
loadUnique: (...args: [any, ...any[]]) => {
|
|
271
|
-
// @ts-expect-error
|
|
272
|
-
return coValueClass.loadUnique(...args);
|
|
273
|
-
},
|
|
274
|
-
unstable_merge: (...args: any[]) => {
|
|
275
|
-
// @ts-expect-error
|
|
276
|
-
return unstable_mergeBranchWithResolve(coValueClass, ...args);
|
|
277
|
-
},
|
|
278
|
-
catchall: (catchAll: AnyZodOrCoValueSchema) => {
|
|
279
|
-
const schemaWithCatchAll = createCoreCoMapSchema(
|
|
280
|
-
coValueSchema.getDefinition().shape,
|
|
281
|
-
catchAll,
|
|
282
|
-
);
|
|
283
|
-
return hydrateCoreCoValueSchema(schemaWithCatchAll);
|
|
284
|
-
},
|
|
285
|
-
withMigration: (migration: (value: any) => undefined) => {
|
|
286
|
-
// @ts-expect-error TODO check
|
|
287
|
-
coValueClass.prototype.migrate = migration;
|
|
288
|
-
|
|
289
|
-
return coValueSchema;
|
|
290
|
-
},
|
|
291
|
-
getCoValueClass: () => {
|
|
292
|
-
return coValueClass;
|
|
293
|
-
},
|
|
294
|
-
optional: () => {
|
|
295
|
-
return coOptionalDefiner(coValueSchema);
|
|
296
|
-
},
|
|
297
|
-
pick: <Keys extends keyof Shape>(keys: { [key in Keys]: true }) => {
|
|
298
|
-
const keysSet = new Set(Object.keys(keys));
|
|
299
|
-
const pickedShape: Record<string, AnyZodOrCoValueSchema> = {};
|
|
300
|
-
|
|
301
|
-
for (const [key, value] of Object.entries(coValueSchema.shape)) {
|
|
302
|
-
if (keysSet.has(key)) {
|
|
303
|
-
pickedShape[key] = value;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return coMapDefiner(pickedShape);
|
|
308
|
-
},
|
|
309
|
-
partial: <Keys extends keyof Shape = keyof Shape>(
|
|
310
|
-
keys?: { [key in Keys]: true },
|
|
311
|
-
) => {
|
|
312
|
-
const partialShape: Record<string, AnyZodOrCoValueSchema> = {};
|
|
313
|
-
|
|
314
|
-
for (const [key, value] of Object.entries(coValueSchema.shape)) {
|
|
315
|
-
if (keys && !keys[key as Keys]) {
|
|
316
|
-
partialShape[key] = value;
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
if (isAnyCoValueSchema(value)) {
|
|
321
|
-
partialShape[key] = coOptionalDefiner(value);
|
|
322
|
-
} else {
|
|
323
|
-
partialShape[key] = z.optional(coValueSchema.shape[key]);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const partialCoMapSchema = coMapDefiner(partialShape);
|
|
328
|
-
if (coValueSchema.catchAll) {
|
|
329
|
-
return partialCoMapSchema.catchall(
|
|
330
|
-
coValueSchema.catchAll as unknown as AnyZodOrCoValueSchema,
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
return partialCoMapSchema;
|
|
334
|
-
},
|
|
335
|
-
}) as unknown as CoMapSchema<Shape, CatchAll>;
|
|
336
|
-
return coValueSchema;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
394
|
export interface CoMapSchemaDefinition<
|
|
340
395
|
Shape extends z.core.$ZodLooseShape = z.core.$ZodLooseShape,
|
|
341
396
|
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
|
@@ -366,12 +421,13 @@ export type CoMapInstanceShape<
|
|
|
366
421
|
}
|
|
367
422
|
: {});
|
|
368
423
|
|
|
369
|
-
export type
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
424
|
+
export type CoMapInstanceCoValuesMaybeLoaded<
|
|
425
|
+
Shape extends z.core.$ZodLooseShape,
|
|
426
|
+
> = {
|
|
427
|
+
readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded<
|
|
428
|
+
Shape[key]
|
|
429
|
+
>;
|
|
430
|
+
};
|
|
375
431
|
|
|
376
432
|
export type PartialShape<
|
|
377
433
|
Shape extends z.core.$ZodLooseShape,
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
CoMapSchemaDefinition,
|
|
7
7
|
Group,
|
|
8
8
|
ID,
|
|
9
|
+
MaybeLoaded,
|
|
9
10
|
RefsToResolve,
|
|
10
11
|
RefsToResolveStrict,
|
|
11
12
|
Resolved,
|
|
@@ -15,11 +16,11 @@ import {
|
|
|
15
16
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
|
16
17
|
import { CoFieldSchemaInit } from "../typeConverters/CoFieldSchemaInit.js";
|
|
17
18
|
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
|
18
|
-
import {
|
|
19
|
+
import { InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.js";
|
|
19
20
|
import { z } from "../zodReExport.js";
|
|
20
21
|
import { AnyZodOrCoValueSchema } from "../zodSchema.js";
|
|
21
22
|
import { CoOptionalSchema } from "./CoOptionalSchema.js";
|
|
22
|
-
import { CoreCoValueSchema } from "./CoValueSchema.js";
|
|
23
|
+
import { CoreCoValueSchema, CoreResolveQuery } from "./CoValueSchema.js";
|
|
23
24
|
|
|
24
25
|
type CoRecordInit<
|
|
25
26
|
K extends z.core.$ZodString<string>,
|
|
@@ -31,6 +32,7 @@ type CoRecordInit<
|
|
|
31
32
|
export interface CoRecordSchema<
|
|
32
33
|
K extends z.core.$ZodString<string>,
|
|
33
34
|
V extends AnyZodOrCoValueSchema,
|
|
35
|
+
DefaultResolveQuery extends CoreResolveQuery = true,
|
|
34
36
|
> extends CoreCoRecordSchema<K, V> {
|
|
35
37
|
create(
|
|
36
38
|
init: Simplify<CoRecordInit<K, V>>,
|
|
@@ -49,25 +51,35 @@ export interface CoRecordSchema<
|
|
|
49
51
|
|
|
50
52
|
load<
|
|
51
53
|
const R extends RefsToResolve<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>
|
|
55
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
56
|
+
> = DefaultResolveQuery,
|
|
54
57
|
>(
|
|
55
|
-
id: ID<
|
|
58
|
+
id: ID<CoRecordInstanceCoValuesMaybeLoaded<K, V>>,
|
|
56
59
|
options?: {
|
|
57
|
-
resolve?: RefsToResolveStrict<
|
|
60
|
+
resolve?: RefsToResolveStrict<
|
|
61
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>,
|
|
62
|
+
R
|
|
63
|
+
>;
|
|
58
64
|
loadAs?: Account | AnonymousJazzAgent;
|
|
59
65
|
unstable_branch?: BranchDefinition;
|
|
60
66
|
},
|
|
61
|
-
): Promise<
|
|
67
|
+
): Promise<
|
|
68
|
+
MaybeLoaded<Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>>
|
|
69
|
+
>;
|
|
62
70
|
|
|
63
71
|
unstable_merge<
|
|
64
72
|
const R extends RefsToResolve<
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>
|
|
74
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
75
|
+
> = DefaultResolveQuery,
|
|
67
76
|
>(
|
|
68
77
|
id: string,
|
|
69
|
-
options
|
|
70
|
-
resolve?: RefsToResolveStrict<
|
|
78
|
+
options: {
|
|
79
|
+
resolve?: RefsToResolveStrict<
|
|
80
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>,
|
|
81
|
+
R
|
|
82
|
+
>;
|
|
71
83
|
loadAs?: Account | AnonymousJazzAgent;
|
|
72
84
|
branch: BranchDefinition;
|
|
73
85
|
},
|
|
@@ -75,16 +87,17 @@ export interface CoRecordSchema<
|
|
|
75
87
|
|
|
76
88
|
subscribe<
|
|
77
89
|
const R extends RefsToResolve<
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>
|
|
91
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
92
|
+
> = DefaultResolveQuery,
|
|
80
93
|
>(
|
|
81
|
-
id: ID<
|
|
94
|
+
id: ID<CoRecordInstanceCoValuesMaybeLoaded<K, V>>,
|
|
82
95
|
options: SubscribeListenerOptions<
|
|
83
|
-
|
|
96
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>,
|
|
84
97
|
R
|
|
85
98
|
>,
|
|
86
99
|
listener: (
|
|
87
|
-
value: Resolved<
|
|
100
|
+
value: Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>,
|
|
88
101
|
unsubscribe: () => void,
|
|
89
102
|
) => void,
|
|
90
103
|
): () => void;
|
|
@@ -94,35 +107,66 @@ export interface CoRecordSchema<
|
|
|
94
107
|
unique: CoValueUniqueness["uniqueness"],
|
|
95
108
|
ownerID: ID<Account> | ID<Group>,
|
|
96
109
|
as?: Account | Group | AnonymousJazzAgent,
|
|
97
|
-
): ID<
|
|
110
|
+
): ID<CoRecordInstanceCoValuesMaybeLoaded<K, V>>;
|
|
98
111
|
|
|
99
112
|
upsertUnique<
|
|
100
113
|
const R extends RefsToResolve<
|
|
101
|
-
|
|
102
|
-
|
|
114
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>
|
|
115
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
116
|
+
> = DefaultResolveQuery,
|
|
103
117
|
>(options: {
|
|
104
118
|
value: Simplify<CoRecordInit<K, V>>;
|
|
105
119
|
unique: CoValueUniqueness["uniqueness"];
|
|
106
120
|
owner: Account | Group;
|
|
107
|
-
resolve?: RefsToResolveStrict<
|
|
108
|
-
}): Promise<
|
|
121
|
+
resolve?: RefsToResolveStrict<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>;
|
|
122
|
+
}): Promise<
|
|
123
|
+
MaybeLoaded<Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>>
|
|
124
|
+
>;
|
|
109
125
|
|
|
110
126
|
loadUnique<
|
|
111
127
|
const R extends RefsToResolve<
|
|
112
|
-
|
|
113
|
-
|
|
128
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>
|
|
129
|
+
// @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
|
|
130
|
+
> = DefaultResolveQuery,
|
|
114
131
|
>(
|
|
115
132
|
unique: CoValueUniqueness["uniqueness"],
|
|
116
133
|
ownerID: ID<Account> | ID<Group>,
|
|
117
134
|
options?: {
|
|
118
|
-
resolve?: RefsToResolveStrict<
|
|
135
|
+
resolve?: RefsToResolveStrict<
|
|
136
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>,
|
|
137
|
+
R
|
|
138
|
+
>;
|
|
119
139
|
loadAs?: Account | AnonymousJazzAgent;
|
|
120
140
|
},
|
|
121
|
-
): Promise<
|
|
141
|
+
): Promise<
|
|
142
|
+
MaybeLoaded<Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>>
|
|
143
|
+
>;
|
|
122
144
|
|
|
123
145
|
getCoValueClass: () => typeof CoMap;
|
|
124
146
|
|
|
125
147
|
optional(): CoOptionalSchema<this>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Default resolve query to be used when loading instances of this schema.
|
|
151
|
+
* This resolve query will be used when no resolve query is provided to the load method.
|
|
152
|
+
* @default true
|
|
153
|
+
*/
|
|
154
|
+
resolveQuery: DefaultResolveQuery;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Adds a default resolve query to be used when loading instances of this schema.
|
|
158
|
+
* This resolve query will be used when no resolve query is provided to the load method.
|
|
159
|
+
*/
|
|
160
|
+
resolved<
|
|
161
|
+
const R extends RefsToResolve<
|
|
162
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>
|
|
163
|
+
> = true,
|
|
164
|
+
>(
|
|
165
|
+
resolveQuery: RefsToResolveStrict<
|
|
166
|
+
CoRecordInstanceCoValuesMaybeLoaded<K, V>,
|
|
167
|
+
R
|
|
168
|
+
>,
|
|
169
|
+
): CoRecordSchema<K, V, R>;
|
|
126
170
|
}
|
|
127
171
|
|
|
128
172
|
type CoRecordSchemaDefinition<
|
|
@@ -149,11 +193,11 @@ export type CoRecordInstance<
|
|
|
149
193
|
[key in z.output<K>]: InstanceOrPrimitiveOfSchema<V>;
|
|
150
194
|
} & CoMap;
|
|
151
195
|
|
|
152
|
-
export type
|
|
196
|
+
export type CoRecordInstanceCoValuesMaybeLoaded<
|
|
153
197
|
K extends z.core.$ZodString<string>,
|
|
154
198
|
V extends AnyZodOrCoValueSchema,
|
|
155
199
|
> = {
|
|
156
|
-
readonly [key in z.output<K>]:
|
|
200
|
+
readonly [key in z.output<K>]: InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded<V>;
|
|
157
201
|
} & CoMap;
|
|
158
202
|
|
|
159
203
|
export type CoRecordInstanceShape<
|