jazz-tools 0.14.27 → 0.15.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__/Provider.svelte +61 -0
- package/.svelte-kit/__package__/Provider.svelte.d.ts +19 -0
- package/.svelte-kit/__package__/Provider.svelte.d.ts.map +1 -0
- package/.svelte-kit/__package__/auth/PasskeyAuth.svelte.d.ts +11 -0
- package/.svelte-kit/__package__/auth/PasskeyAuth.svelte.d.ts.map +1 -0
- package/.svelte-kit/__package__/auth/PasskeyAuth.svelte.js +20 -0
- package/.svelte-kit/__package__/auth/PasskeyAuthBasicUI.svelte +81 -0
- package/.svelte-kit/__package__/auth/PasskeyAuthBasicUI.svelte.d.ts +9 -0
- package/.svelte-kit/__package__/auth/PasskeyAuthBasicUI.svelte.d.ts.map +1 -0
- package/.svelte-kit/__package__/auth/PassphraseAuth.svelte.d.ts +12 -0
- package/.svelte-kit/__package__/auth/PassphraseAuth.svelte.d.ts.map +1 -0
- package/.svelte-kit/__package__/auth/PassphraseAuth.svelte.js +30 -0
- package/.svelte-kit/__package__/auth/index.d.ts +4 -0
- package/.svelte-kit/__package__/auth/index.d.ts.map +1 -0
- package/.svelte-kit/__package__/auth/index.js +3 -0
- package/.svelte-kit/__package__/auth/useIsAuthenticated.svelte.d.ts +6 -0
- package/.svelte-kit/__package__/auth/useIsAuthenticated.svelte.d.ts.map +1 -0
- package/.svelte-kit/__package__/auth/useIsAuthenticated.svelte.js +22 -0
- package/.svelte-kit/__package__/index.d.ts +6 -0
- package/.svelte-kit/__package__/index.d.ts.map +1 -0
- package/.svelte-kit/__package__/index.js +5 -0
- package/.svelte-kit/__package__/jazz.class.svelte.d.ts +21 -0
- package/.svelte-kit/__package__/jazz.class.svelte.d.ts.map +1 -0
- package/.svelte-kit/__package__/jazz.class.svelte.js +117 -0
- package/.svelte-kit/__package__/jazz.svelte.d.ts +39 -0
- package/.svelte-kit/__package__/jazz.svelte.d.ts.map +1 -0
- package/.svelte-kit/__package__/jazz.svelte.js +70 -0
- package/.svelte-kit/__package__/testing.d.ts +10 -0
- package/.svelte-kit/__package__/testing.d.ts.map +1 -0
- package/.svelte-kit/__package__/testing.js +23 -0
- package/.turbo/turbo-build.log +180 -11
- package/CHANGELOG.md +21 -0
- package/README.md +2 -2
- package/dist/browser/BrowserContextManager.d.ts +31 -0
- package/dist/browser/BrowserContextManager.d.ts.map +1 -0
- package/dist/browser/auth/LocalStorageKVStore.d.ts +9 -0
- package/dist/browser/auth/LocalStorageKVStore.d.ts.map +1 -0
- package/dist/browser/auth/PasskeyAuth.d.ts +27 -0
- package/dist/browser/auth/PasskeyAuth.d.ts.map +1 -0
- package/dist/browser/createBrowserContext.d.ts +47 -0
- package/dist/browser/createBrowserContext.d.ts.map +1 -0
- package/dist/browser/index.d.ts +23 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +469 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/storageOptions.d.ts +8 -0
- package/dist/browser/storageOptions.d.ts.map +1 -0
- package/dist/browser/tests/LocalStorageKVStore.test.d.ts +2 -0
- package/dist/browser/tests/LocalStorageKVStore.test.d.ts.map +1 -0
- package/dist/browser/tests/PasskeyAuth.test.d.ts +2 -0
- package/dist/browser/tests/PasskeyAuth.test.d.ts.map +1 -0
- package/dist/browser/tests/createInviteLink.test.d.ts +2 -0
- package/dist/browser/tests/createInviteLink.test.d.ts.map +1 -0
- package/dist/browser/tests/storageOptions.test.d.ts +2 -0
- package/dist/browser/tests/storageOptions.test.d.ts.map +1 -0
- package/dist/browser/tests/utils.d.ts +11 -0
- package/dist/browser/tests/utils.d.ts.map +1 -0
- package/dist/browser/utils/export-account-inspector.d.ts +6 -0
- package/dist/browser/utils/export-account-inspector.d.ts.map +1 -0
- package/dist/browser-media-images/index.d.ts +7 -0
- package/dist/browser-media-images/index.d.ts.map +1 -0
- package/dist/browser-media-images/index.js +70 -0
- package/dist/browser-media-images/index.js.map +1 -0
- package/dist/chunk-FSIM7N33.js +4827 -0
- package/dist/chunk-FSIM7N33.js.map +1 -0
- package/dist/expo/auth/clerk/index.d.ts +7 -0
- package/dist/expo/auth/clerk/index.d.ts.map +1 -0
- package/dist/expo/crypto.d.ts +2 -0
- package/dist/expo/crypto.d.ts.map +1 -0
- package/dist/expo/crypto.js +3 -0
- package/dist/expo/crypto.js.map +1 -0
- package/dist/expo/index.d.ts +6 -0
- package/dist/expo/index.d.ts.map +1 -0
- package/dist/expo/index.js +168 -0
- package/dist/expo/index.js.map +1 -0
- package/dist/expo/provider.d.ts +4 -0
- package/dist/expo/provider.d.ts.map +1 -0
- package/dist/expo/storage/expo-secure-store-adapter.d.ts +8 -0
- package/dist/expo/storage/expo-secure-store-adapter.d.ts.map +1 -0
- package/dist/expo/storage/expo-sqlite-adapter.d.ts +18 -0
- package/dist/expo/storage/expo-sqlite-adapter.d.ts.map +1 -0
- package/dist/expo/testing.d.ts +2 -0
- package/dist/expo/testing.d.ts.map +1 -0
- package/dist/expo/testing.js +3 -0
- package/dist/expo/testing.js.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +172 -6
- package/dist/index.js.map +1 -1
- package/dist/inspector/custom-element-CWW72LEG.js +31971 -0
- package/dist/inspector/custom-element-CWW72LEG.js.map +1 -0
- package/dist/inspector/custom-element.d.ts +13 -0
- package/dist/inspector/custom-element.d.ts.map +1 -0
- package/dist/inspector/index.d.ts +12 -0
- package/dist/inspector/index.d.ts.map +1 -0
- package/dist/inspector/index.js +2027 -0
- package/dist/inspector/index.js.map +1 -0
- package/dist/inspector/register-custom-element.d.ts +2 -0
- package/dist/inspector/register-custom-element.d.ts.map +1 -0
- package/dist/inspector/register-custom-element.js +5 -0
- package/dist/inspector/register-custom-element.js.map +1 -0
- package/dist/inspector/ui/badge.d.ts +4 -0
- package/dist/inspector/ui/badge.d.ts.map +1 -0
- package/dist/inspector/ui/button.d.ts +9 -0
- package/dist/inspector/ui/button.d.ts.map +1 -0
- package/dist/inspector/ui/card.d.ts +10 -0
- package/dist/inspector/ui/card.d.ts.map +1 -0
- package/dist/inspector/ui/global-styles.d.ts +4 -0
- package/dist/inspector/ui/global-styles.d.ts.map +1 -0
- package/dist/inspector/ui/grid.d.ts +4 -0
- package/dist/inspector/ui/grid.d.ts.map +1 -0
- package/dist/inspector/ui/heading.d.ts +4 -0
- package/dist/inspector/ui/heading.d.ts.map +1 -0
- package/dist/inspector/ui/icon.d.ts +30 -0
- package/dist/inspector/ui/icon.d.ts.map +1 -0
- package/dist/inspector/ui/icons/chevron-down-icon.d.ts +2 -0
- package/dist/inspector/ui/icons/chevron-down-icon.d.ts.map +1 -0
- package/dist/inspector/ui/icons/delete-icon.d.ts +2 -0
- package/dist/inspector/ui/icons/delete-icon.d.ts.map +1 -0
- package/dist/inspector/ui/icons/link-icon.d.ts +2 -0
- package/dist/inspector/ui/icons/link-icon.d.ts.map +1 -0
- package/dist/inspector/ui/input.d.ts +11 -0
- package/dist/inspector/ui/input.d.ts.map +1 -0
- package/dist/inspector/ui/select.d.ts +5 -0
- package/dist/inspector/ui/select.d.ts.map +1 -0
- package/dist/inspector/ui/table.d.ts +8 -0
- package/dist/inspector/ui/table.d.ts.map +1 -0
- package/dist/inspector/ui/text.d.ts +10 -0
- package/dist/inspector/ui/text.d.ts.map +1 -0
- package/dist/inspector/viewer/account-or-group-text.d.ts +8 -0
- package/dist/inspector/viewer/account-or-group-text.d.ts.map +1 -0
- package/dist/inspector/viewer/account-view.d.ts +8 -0
- package/dist/inspector/viewer/account-view.d.ts.map +1 -0
- package/dist/inspector/viewer/breadcrumbs.d.ts +9 -0
- package/dist/inspector/viewer/breadcrumbs.d.ts.map +1 -0
- package/dist/inspector/viewer/co-stream-view.d.ts +18 -0
- package/dist/inspector/viewer/co-stream-view.d.ts.map +1 -0
- package/dist/inspector/viewer/grid-view.d.ts +9 -0
- package/dist/inspector/viewer/grid-view.d.ts.map +1 -0
- package/dist/inspector/viewer/group-view.d.ts +8 -0
- package/dist/inspector/viewer/group-view.d.ts.map +1 -0
- package/dist/inspector/viewer/inpsector-button.d.ts +6 -0
- package/dist/inspector/viewer/inpsector-button.d.ts.map +1 -0
- package/dist/inspector/viewer/new-app.d.ts +11 -0
- package/dist/inspector/viewer/new-app.d.ts.map +1 -0
- package/dist/inspector/viewer/page-stack.d.ts +15 -0
- package/dist/inspector/viewer/page-stack.d.ts.map +1 -0
- package/dist/inspector/viewer/page.d.ts +16 -0
- package/dist/inspector/viewer/page.d.ts.map +1 -0
- package/dist/inspector/viewer/raw-data-card.d.ts +5 -0
- package/dist/inspector/viewer/raw-data-card.d.ts.map +1 -0
- package/dist/inspector/viewer/role-display.d.ts +6 -0
- package/dist/inspector/viewer/role-display.d.ts.map +1 -0
- package/dist/inspector/viewer/table-viewer.d.ts +9 -0
- package/dist/inspector/viewer/table-viewer.d.ts.map +1 -0
- package/dist/inspector/viewer/type-icon.d.ts +11 -0
- package/dist/inspector/viewer/type-icon.d.ts.map +1 -0
- package/dist/inspector/viewer/types.d.ts +7 -0
- package/dist/inspector/viewer/types.d.ts.map +1 -0
- package/dist/inspector/viewer/use-page-path.d.ts +10 -0
- package/dist/inspector/viewer/use-page-path.d.ts.map +1 -0
- package/dist/inspector/viewer/use-resolve-covalue.d.ts +67 -0
- package/dist/inspector/viewer/use-resolve-covalue.d.ts.map +1 -0
- package/dist/inspector/viewer/value-renderer.d.ts +12 -0
- package/dist/inspector/viewer/value-renderer.d.ts.map +1 -0
- package/dist/prosemirror/index.d.ts +3 -0
- package/dist/prosemirror/index.d.ts.map +1 -0
- package/dist/prosemirror/index.js +2185 -0
- package/dist/prosemirror/index.js.map +1 -0
- package/dist/prosemirror/lib/converter.d.ts +33 -0
- package/dist/prosemirror/lib/converter.d.ts.map +1 -0
- package/dist/prosemirror/lib/plugin.d.ts +43 -0
- package/dist/prosemirror/lib/plugin.d.ts.map +1 -0
- package/dist/prosemirror/lib/sync.d.ts +35 -0
- package/dist/prosemirror/lib/sync.d.ts.map +1 -0
- package/dist/prosemirror/tests/plugin.test.d.ts +2 -0
- package/dist/prosemirror/tests/plugin.test.d.ts.map +1 -0
- package/dist/react/auth/Clerk.d.ts +7 -0
- package/dist/react/auth/Clerk.d.ts.map +1 -0
- package/dist/react/auth/DemoAuth.d.ts +5 -0
- package/dist/react/auth/DemoAuth.d.ts.map +1 -0
- package/dist/react/auth/PasskeyAuth.d.ts +24 -0
- package/dist/react/auth/PasskeyAuth.d.ts.map +1 -0
- package/dist/react/auth/PassphraseAuth.d.ts +6 -0
- package/dist/react/auth/PassphraseAuth.d.ts.map +1 -0
- package/dist/react/auth/auth.d.ts +6 -0
- package/dist/react/auth/auth.d.ts.map +1 -0
- package/dist/react/hooks.d.ts +9 -0
- package/dist/react/hooks.d.ts.map +1 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +700 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/media.d.ts +24 -0
- package/dist/react/media.d.ts.map +1 -0
- package/dist/react/provider.d.ts +10 -0
- package/dist/react/provider.d.ts.map +1 -0
- package/dist/react/ssr.d.ts +4 -0
- package/dist/react/ssr.d.ts.map +1 -0
- package/dist/react/ssr.js +25 -0
- package/dist/react/ssr.js.map +1 -0
- package/dist/react/testing.d.ts +2 -0
- package/dist/react/testing.d.ts.map +1 -0
- package/dist/react/testing.js +5 -0
- package/dist/react/testing.js.map +1 -0
- package/dist/react/tests/testUtils.d.ts +14 -0
- package/dist/react/tests/testUtils.d.ts.map +1 -0
- package/dist/react/tests/useAcceptInvite.test.d.ts +2 -0
- package/dist/react/tests/useAcceptInvite.test.d.ts.map +1 -0
- package/dist/react-core/auth/DemoAuth.d.ts +17 -0
- package/dist/react-core/auth/DemoAuth.d.ts.map +1 -0
- package/dist/react-core/auth/PassphraseAuth.d.ts +21 -0
- package/dist/react-core/auth/PassphraseAuth.d.ts.map +1 -0
- package/dist/react-core/auth/index.d.ts +3 -0
- package/dist/react-core/auth/index.d.ts.map +1 -0
- package/dist/react-core/chunk-7DYMJ74I.js +12 -0
- package/dist/react-core/chunk-7DYMJ74I.js.map +1 -0
- package/dist/react-core/hooks.d.ts +17 -0
- package/dist/react-core/hooks.d.ts.map +1 -0
- package/dist/react-core/index.d.ts +4 -0
- package/dist/react-core/index.d.ts.map +1 -0
- package/dist/react-core/index.js +302 -0
- package/dist/react-core/index.js.map +1 -0
- package/dist/react-core/provider.d.ts +5 -0
- package/dist/react-core/provider.d.ts.map +1 -0
- package/dist/react-core/testing.d.ts +10 -0
- package/dist/react-core/testing.d.ts.map +1 -0
- package/dist/react-core/testing.js +43 -0
- package/dist/react-core/testing.js.map +1 -0
- package/dist/react-core/tests/fixtures.d.ts.map +1 -0
- package/dist/react-core/tests/testUtils.d.ts +15 -0
- package/dist/react-core/tests/testUtils.d.ts.map +1 -0
- package/dist/react-core/tests/useAccount.test.d.ts +2 -0
- package/dist/react-core/tests/useAccount.test.d.ts.map +1 -0
- package/dist/react-core/tests/useCoState.test.d.ts +2 -0
- package/dist/react-core/tests/useCoState.test.d.ts.map +1 -0
- package/dist/react-core/tests/useInboxSender.test.d.ts +2 -0
- package/dist/react-core/tests/useInboxSender.test.d.ts.map +1 -0
- package/dist/react-core/tests/useIsAuthenticated.test.d.ts +2 -0
- package/dist/react-core/tests/useIsAuthenticated.test.d.ts.map +1 -0
- package/dist/react-core/tests/usePassPhraseAuth.test.d.ts +2 -0
- package/dist/react-core/tests/usePassPhraseAuth.test.d.ts.map +1 -0
- package/dist/react-core/utils.d.ts +4 -0
- package/dist/react-core/utils.d.ts.map +1 -0
- package/dist/react-native/crypto.d.ts +2 -0
- package/dist/react-native/crypto.d.ts.map +1 -0
- package/dist/react-native/crypto.js +3 -0
- package/dist/react-native/crypto.js.map +1 -0
- package/dist/react-native/index.d.ts +5 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +103 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/provider.d.ts +4 -0
- package/dist/react-native/provider.d.ts.map +1 -0
- package/dist/react-native/storage/mmkv-store-adapter.d.ts +8 -0
- package/dist/react-native/storage/mmkv-store-adapter.d.ts.map +1 -0
- package/dist/react-native/storage/op-sqlite-adapter.d.ts +13 -0
- package/dist/react-native/storage/op-sqlite-adapter.d.ts.map +1 -0
- package/dist/react-native/testing.d.ts +2 -0
- package/dist/react-native/testing.d.ts.map +1 -0
- package/dist/react-native/testing.js +3 -0
- package/dist/react-native/testing.js.map +1 -0
- package/dist/react-native-core/ReactNativeContextManager.d.ts +31 -0
- package/dist/react-native-core/ReactNativeContextManager.d.ts.map +1 -0
- package/dist/react-native-core/auth/DemoAuthUI.d.ts +8 -0
- package/dist/react-native-core/auth/DemoAuthUI.d.ts.map +1 -0
- package/dist/react-native-core/auth/auth.d.ts +3 -0
- package/dist/react-native-core/auth/auth.d.ts.map +1 -0
- package/dist/react-native-core/crypto/RNQuickCrypto.d.ts +15 -0
- package/dist/react-native-core/crypto/RNQuickCrypto.d.ts.map +1 -0
- package/dist/react-native-core/crypto/index.d.ts +2 -0
- package/dist/react-native-core/crypto/index.d.ts.map +1 -0
- package/dist/react-native-core/crypto.js +65 -0
- package/dist/react-native-core/crypto.js.map +1 -0
- package/dist/react-native-core/hooks.d.ts +8 -0
- package/dist/react-native-core/hooks.d.ts.map +1 -0
- package/dist/react-native-core/index.d.ts +9 -0
- package/dist/react-native-core/index.d.ts.map +1 -0
- package/dist/react-native-core/index.js +669 -0
- package/dist/react-native-core/index.js.map +1 -0
- package/dist/react-native-core/media.d.ts +24 -0
- package/dist/react-native-core/media.d.ts.map +1 -0
- package/dist/react-native-core/platform.d.ts +45 -0
- package/dist/react-native-core/platform.d.ts.map +1 -0
- package/dist/react-native-core/provider.d.ts +10 -0
- package/dist/react-native-core/provider.d.ts.map +1 -0
- package/dist/react-native-core/storage/kv-store-context.d.ts +17 -0
- package/dist/react-native-core/storage/kv-store-context.d.ts.map +1 -0
- package/dist/react-native-core/storage/sqlite-react-native.d.ts +9 -0
- package/dist/react-native-core/storage/sqlite-react-native.d.ts.map +1 -0
- package/dist/react-native-core/testing.js +3 -0
- package/dist/react-native-core/testing.js.map +1 -0
- package/dist/react-native-media-images/index.d.ts +7 -0
- package/dist/react-native-media-images/index.d.ts.map +1 -0
- package/dist/react-native-media-images/index.js +177 -0
- package/dist/react-native-media-images/index.js.map +1 -0
- package/dist/svelte/Provider.svelte +61 -0
- package/dist/svelte/Provider.svelte.d.ts +19 -0
- package/dist/svelte/Provider.svelte.d.ts.map +1 -0
- package/dist/svelte/auth/PasskeyAuth.svelte.d.ts +11 -0
- package/dist/svelte/auth/PasskeyAuth.svelte.d.ts.map +1 -0
- package/dist/svelte/auth/PasskeyAuth.svelte.js +20 -0
- package/dist/svelte/auth/PasskeyAuthBasicUI.svelte +81 -0
- package/dist/svelte/auth/PasskeyAuthBasicUI.svelte.d.ts +9 -0
- package/dist/svelte/auth/PasskeyAuthBasicUI.svelte.d.ts.map +1 -0
- package/dist/svelte/auth/PassphraseAuth.svelte.d.ts +12 -0
- package/dist/svelte/auth/PassphraseAuth.svelte.d.ts.map +1 -0
- package/dist/svelte/auth/PassphraseAuth.svelte.js +30 -0
- package/dist/svelte/auth/index.d.ts +4 -0
- package/dist/svelte/auth/index.d.ts.map +1 -0
- package/dist/svelte/auth/index.js +3 -0
- package/dist/svelte/auth/useIsAuthenticated.svelte.d.ts +6 -0
- package/dist/svelte/auth/useIsAuthenticated.svelte.d.ts.map +1 -0
- package/dist/svelte/auth/useIsAuthenticated.svelte.js +22 -0
- package/dist/svelte/index.d.ts +6 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +5 -0
- package/dist/svelte/jazz.class.svelte.d.ts +21 -0
- package/dist/svelte/jazz.class.svelte.d.ts.map +1 -0
- package/dist/svelte/jazz.class.svelte.js +117 -0
- package/dist/svelte/jazz.svelte.d.ts +39 -0
- package/dist/svelte/jazz.svelte.d.ts.map +1 -0
- package/dist/svelte/jazz.svelte.js +70 -0
- package/dist/svelte/testing.d.ts +10 -0
- package/dist/svelte/testing.d.ts.map +1 -0
- package/dist/svelte/testing.js +23 -0
- package/dist/testing.d.ts +1 -42
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +2 -2
- package/dist/testing.js.map +1 -1
- package/dist/tiptap/index.d.ts +11 -0
- package/dist/tiptap/index.d.ts.map +1 -0
- package/dist/tiptap/index.js +22 -0
- package/dist/tiptap/index.js.map +1 -0
- package/dist/tools/auth/AuthSecretStorage.d.ts.map +1 -0
- package/dist/tools/auth/DemoAuth.d.ts.map +1 -0
- package/dist/tools/auth/InMemoryKVStore.d.ts.map +1 -0
- package/dist/tools/auth/KvStoreContext.d.ts.map +1 -0
- package/dist/tools/auth/PassphraseAuth.d.ts.map +1 -0
- package/dist/tools/auth/clerk/getClerkUsername.d.ts +3 -0
- package/dist/tools/auth/clerk/getClerkUsername.d.ts.map +1 -0
- package/dist/tools/auth/clerk/index.d.ts +25 -0
- package/dist/tools/auth/clerk/index.d.ts.map +1 -0
- package/dist/tools/auth/clerk/tests/JazzClerkAuth.test.d.ts +2 -0
- package/dist/tools/auth/clerk/tests/JazzClerkAuth.test.d.ts.map +1 -0
- package/dist/tools/auth/clerk/tests/getClerkUsername.test.d.ts +2 -0
- package/dist/tools/auth/clerk/tests/getClerkUsername.test.d.ts.map +1 -0
- package/dist/tools/auth/clerk/tests/types.test.d.ts +2 -0
- package/dist/tools/auth/clerk/tests/types.test.d.ts.map +1 -0
- package/dist/tools/auth/clerk/types.d.ts +32 -0
- package/dist/tools/auth/clerk/types.d.ts.map +1 -0
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -0
- package/dist/tools/coValues/account.d.ts.map +1 -0
- package/dist/tools/coValues/coFeed.d.ts +368 -0
- package/dist/tools/coValues/coFeed.d.ts.map +1 -0
- package/dist/tools/coValues/coList.d.ts.map +1 -0
- package/dist/tools/coValues/coMap.d.ts.map +1 -0
- package/dist/tools/coValues/coPlainText.d.ts.map +1 -0
- package/dist/tools/coValues/coRichText.d.ts.map +1 -0
- package/dist/tools/coValues/deepLoading.d.ts.map +1 -0
- package/dist/tools/coValues/extensions/imageDef.d.ts.map +1 -0
- package/dist/tools/coValues/group.d.ts.map +1 -0
- package/dist/tools/coValues/inbox.d.ts.map +1 -0
- package/dist/tools/coValues/interfaces.d.ts.map +1 -0
- package/dist/tools/coValues/profile.d.ts.map +1 -0
- package/dist/tools/coValues/registeredSchemas.d.ts.map +1 -0
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -0
- package/dist/tools/exports.d.ts +24 -0
- package/dist/tools/exports.d.ts.map +1 -0
- package/dist/tools/implementation/ContextManager.d.ts.map +1 -0
- package/dist/tools/implementation/activeAccountContext.d.ts.map +1 -0
- package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -0
- package/dist/tools/implementation/createContext.d.ts.map +1 -0
- package/dist/tools/implementation/devtoolsFormatters.d.ts.map +1 -0
- package/dist/tools/implementation/errors.d.ts.map +1 -0
- package/dist/tools/implementation/inspect.d.ts.map +1 -0
- package/dist/tools/implementation/invites.d.ts.map +1 -0
- package/dist/tools/implementation/refs.d.ts.map +1 -0
- package/dist/tools/implementation/schema.d.ts.map +1 -0
- package/dist/tools/implementation/symbols.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/zodReExport.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/internal.d.ts.map +1 -0
- package/dist/tools/lib/cache.d.ts.map +1 -0
- package/dist/tools/lib/cache.test.d.ts.map +1 -0
- package/dist/tools/lib/migration.d.ts.map +1 -0
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -0
- package/dist/tools/subscribe/JazzError.d.ts.map +1 -0
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -0
- package/dist/tools/subscribe/index.d.ts.map +1 -0
- package/dist/tools/subscribe/types.d.ts.map +1 -0
- package/dist/tools/subscribe/utils.d.ts.map +1 -0
- package/dist/tools/testing.d.ts +43 -0
- package/dist/tools/testing.d.ts.map +1 -0
- package/dist/tools/tests/AuthSecretStorage.test.d.ts.map +1 -0
- package/dist/tools/tests/ContextManager.test.d.ts.map +1 -0
- package/dist/tools/tests/DemoAuth.test.d.ts.map +1 -0
- package/dist/tools/tests/PassphraseAuth.test.d.ts.map +1 -0
- package/dist/tools/tests/account.test.d.ts.map +1 -0
- package/dist/tools/tests/coFeed.test-d.d.ts.map +1 -0
- package/dist/tools/tests/coFeed.test.d.ts.map +1 -0
- package/dist/tools/tests/coList.test-d.d.ts.map +1 -0
- package/dist/tools/tests/coList.test.d.ts.map +1 -0
- package/dist/tools/tests/coMap.record.test-d.d.ts.map +1 -0
- package/dist/tools/tests/coMap.record.test.d.ts.map +1 -0
- package/dist/tools/tests/coMap.test-d.d.ts.map +1 -0
- package/dist/tools/tests/coMap.test.d.ts.map +1 -0
- package/dist/tools/tests/coPlainText.test.d.ts.map +1 -0
- package/dist/tools/tests/createContext.test.d.ts.map +1 -0
- package/dist/tools/tests/deepLoading.test.d.ts.map +1 -0
- package/dist/tools/tests/fixtures.d.ts +2 -0
- package/dist/tools/tests/fixtures.d.ts.map +1 -0
- package/dist/tools/tests/groupsAndAccounts.test.d.ts.map +1 -0
- package/dist/tools/tests/imageDef.test.d.ts.map +1 -0
- package/dist/tools/tests/inbox.test.d.ts.map +1 -0
- package/dist/tools/tests/interfaces.test.d.ts.map +1 -0
- package/dist/tools/tests/invites.test.d.ts.map +1 -0
- package/dist/tools/tests/load.test.d.ts.map +1 -0
- package/dist/tools/tests/patterns/notifications.test.d.ts.map +1 -0
- package/dist/tools/tests/patterns/requestToJoin.test.d.ts.map +1 -0
- package/dist/tools/tests/schema.test.d.ts.map +1 -0
- package/dist/tools/tests/schemaUnion.test.d.ts.map +1 -0
- package/dist/tools/tests/subscribe.test.d.ts.map +1 -0
- package/dist/tools/tests/testing.test.d.ts.map +1 -0
- package/dist/tools/tests/utils.d.ts.map +1 -0
- package/dist/tools/tests/zod.test.d.ts.map +1 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/worker/index.d.ts +25 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +93 -0
- package/dist/worker/index.js.map +1 -0
- package/package.json +193 -11
- package/src/browser/BrowserContextManager.ts +85 -0
- package/src/browser/auth/LocalStorageKVStore.ts +21 -0
- package/src/browser/auth/PasskeyAuth.ts +175 -0
- package/src/browser/createBrowserContext.ts +326 -0
- package/src/browser/index.ts +72 -0
- package/src/browser/storageOptions.ts +17 -0
- package/src/browser/tests/LocalStorageKVStore.test.ts +67 -0
- package/src/browser/tests/PasskeyAuth.test.ts +242 -0
- package/src/browser/tests/createInviteLink.test.ts +18 -0
- package/src/browser/tests/storageOptions.test.ts +33 -0
- package/src/browser/tests/utils.ts +93 -0
- package/src/browser/utils/export-account-inspector.ts +58 -0
- package/src/browser-media-images/index.ts +130 -0
- package/src/expo/auth/clerk/README.md +44 -0
- package/src/expo/auth/clerk/index.tsx +80 -0
- package/src/expo/crypto.ts +1 -0
- package/src/expo/index.ts +6 -0
- package/src/expo/provider.tsx +29 -0
- package/src/expo/storage/expo-secure-store-adapter.ts +29 -0
- package/src/expo/storage/expo-sqlite-adapter.ts +94 -0
- package/src/expo/testing.ts +1 -0
- package/src/index.ts +1 -3
- package/src/inspector/custom-element.tsx +63 -0
- package/src/inspector/index.ts +23 -0
- package/src/inspector/register-custom-element.ts +3 -0
- package/src/inspector/ui/badge.tsx +20 -0
- package/src/inspector/ui/button.tsx +81 -0
- package/src/inspector/ui/card.tsx +23 -0
- package/src/inspector/ui/global-styles.tsx +74 -0
- package/src/inspector/ui/grid.tsx +48 -0
- package/src/inspector/ui/heading.tsx +15 -0
- package/src/inspector/ui/icon.tsx +71 -0
- package/src/inspector/ui/icons/chevron-down-icon.tsx +16 -0
- package/src/inspector/ui/icons/delete-icon.tsx +19 -0
- package/src/inspector/ui/icons/link-icon.tsx +18 -0
- package/src/inspector/ui/input.tsx +51 -0
- package/src/inspector/ui/select.tsx +73 -0
- package/src/inspector/ui/table.tsx +90 -0
- package/src/inspector/ui/text.tsx +62 -0
- package/src/inspector/viewer/account-or-group-text.tsx +52 -0
- package/src/inspector/viewer/account-view.tsx +34 -0
- package/src/inspector/viewer/breadcrumbs.tsx +52 -0
- package/src/inspector/viewer/co-stream-view.tsx +374 -0
- package/src/inspector/viewer/grid-view.tsx +90 -0
- package/src/inspector/viewer/group-view.tsx +67 -0
- package/src/inspector/viewer/inpsector-button.tsx +89 -0
- package/src/inspector/viewer/new-app.tsx +171 -0
- package/src/inspector/viewer/page-stack.tsx +56 -0
- package/src/inspector/viewer/page.tsx +199 -0
- package/src/inspector/viewer/raw-data-card.tsx +53 -0
- package/src/inspector/viewer/role-display.tsx +28 -0
- package/src/inspector/viewer/table-viewer.tsx +184 -0
- package/src/inspector/viewer/type-icon.tsx +63 -0
- package/src/inspector/viewer/types.ts +11 -0
- package/src/inspector/viewer/use-page-path.ts +52 -0
- package/src/inspector/viewer/use-resolve-covalue.ts +214 -0
- package/src/inspector/viewer/value-renderer.tsx +266 -0
- package/src/prosemirror/index.ts +2 -0
- package/src/prosemirror/lib/converter.ts +50 -0
- package/src/prosemirror/lib/plugin.ts +120 -0
- package/src/prosemirror/lib/sync.ts +96 -0
- package/src/prosemirror/tests/plugin.test.ts +127 -0
- package/src/react/auth/Clerk.tsx +82 -0
- package/src/react/auth/DemoAuth.tsx +121 -0
- package/src/react/auth/PasskeyAuth.tsx +168 -0
- package/src/react/auth/PassphraseAuth.tsx +196 -0
- package/src/react/auth/auth.ts +9 -0
- package/src/react/hooks.tsx +53 -0
- package/src/react/index.ts +16 -0
- package/src/react/media.tsx +74 -0
- package/src/react/provider.tsx +114 -0
- package/src/react/scratch.tsx +50 -0
- package/src/react/ssr.ts +25 -0
- package/src/react/testing.tsx +1 -0
- package/src/react/tests/testUtils.tsx +54 -0
- package/src/react/tests/useAcceptInvite.test.ts +55 -0
- package/src/react-core/auth/DemoAuth.tsx +47 -0
- package/src/react-core/auth/PassphraseAuth.tsx +58 -0
- package/src/react-core/auth/index.ts +2 -0
- package/src/react-core/hooks.ts +310 -0
- package/src/react-core/index.ts +3 -0
- package/src/react-core/provider.tsx +11 -0
- package/src/react-core/testing.tsx +42 -0
- package/src/react-core/tests/testUtils.tsx +65 -0
- package/src/react-core/tests/useAccount.test.ts +238 -0
- package/src/react-core/tests/useCoState.test.ts +553 -0
- package/src/react-core/tests/useDemoAuth.test.tsx +84 -0
- package/src/react-core/tests/useInboxSender.test.ts +58 -0
- package/src/react-core/tests/useIsAuthenticated.test.ts +34 -0
- package/src/react-core/tests/usePassPhraseAuth.test.ts +180 -0
- package/src/react-core/utils.ts +28 -0
- package/src/react-native/crypto.ts +1 -0
- package/src/react-native/index.ts +5 -0
- package/src/react-native/provider.tsx +30 -0
- package/src/react-native/storage/mmkv-store-adapter.ts +24 -0
- package/src/react-native/storage/op-sqlite-adapter.ts +79 -0
- package/src/react-native/testing.ts +1 -0
- package/src/react-native-core/ReactNativeContextManager.ts +84 -0
- package/src/react-native-core/auth/DemoAuthUI.tsx +202 -0
- package/src/react-native-core/auth/auth.ts +14 -0
- package/src/react-native-core/crypto/RNQuickCrypto.ts +92 -0
- package/src/react-native-core/crypto/index.ts +1 -0
- package/src/react-native-core/hooks.tsx +64 -0
- package/src/react-native-core/index.ts +9 -0
- package/src/react-native-core/media.tsx +99 -0
- package/src/react-native-core/platform.ts +250 -0
- package/src/react-native-core/provider.tsx +115 -0
- package/src/react-native-core/storage/sqlite-react-native.ts +19 -0
- package/src/react-native-core/testing.tsx +1 -0
- package/src/react-native-media-images/index.ts +238 -0
- package/src/svelte/Provider.svelte +61 -0
- package/src/svelte/auth/PasskeyAuth.svelte.ts +42 -0
- package/src/svelte/auth/PasskeyAuthBasicUI.svelte +81 -0
- package/src/svelte/auth/PassphraseAuth.svelte.ts +49 -0
- package/src/svelte/auth/index.ts +3 -0
- package/src/svelte/auth/useIsAuthenticated.svelte.ts +28 -0
- package/src/svelte/index.ts +5 -0
- package/src/svelte/jazz.class.svelte.ts +172 -0
- package/src/svelte/jazz.svelte.ts +109 -0
- package/src/svelte/testing.ts +42 -0
- package/src/testing.ts +1 -312
- package/src/tiptap/index.ts +28 -0
- package/src/tools/auth/KvStoreContext.ts +39 -0
- package/src/tools/auth/clerk/getClerkUsername.ts +36 -0
- package/src/tools/auth/clerk/index.ts +174 -0
- package/src/tools/auth/clerk/tests/JazzClerkAuth.test.ts +284 -0
- package/src/tools/auth/clerk/tests/getClerkUsername.test.ts +81 -0
- package/src/tools/auth/clerk/tests/types.test.ts +49 -0
- package/src/tools/auth/clerk/types.ts +56 -0
- package/src/tools/coValues/coFeed.ts +943 -0
- package/src/tools/exports.ts +117 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/testing.ts +301 -0
- package/src/tools/tests/coFeed.test.ts +771 -0
- package/src/tools/tests/fixtures.ts +2050 -0
- package/src/worker/index.ts +127 -0
- package/tsconfig.json +10 -3
- package/tsconfig.svelte.json +6 -0
- package/tsup.config.ts +143 -9
- package/dist/auth/AuthSecretStorage.d.ts.map +0 -1
- package/dist/auth/DemoAuth.d.ts.map +0 -1
- package/dist/auth/InMemoryKVStore.d.ts.map +0 -1
- package/dist/auth/KvStoreContext.d.ts.map +0 -1
- package/dist/auth/PassphraseAuth.d.ts.map +0 -1
- package/dist/chunk-G3QC4FAY.js +0 -4826
- package/dist/chunk-G3QC4FAY.js.map +0 -1
- package/dist/coValues/CoValueBase.d.ts.map +0 -1
- package/dist/coValues/account.d.ts.map +0 -1
- package/dist/coValues/coFeed.d.ts +0 -367
- package/dist/coValues/coFeed.d.ts.map +0 -1
- package/dist/coValues/coList.d.ts.map +0 -1
- package/dist/coValues/coMap.d.ts.map +0 -1
- package/dist/coValues/coPlainText.d.ts.map +0 -1
- package/dist/coValues/coRichText.d.ts.map +0 -1
- package/dist/coValues/deepLoading.d.ts.map +0 -1
- package/dist/coValues/extensions/imageDef.d.ts.map +0 -1
- package/dist/coValues/group.d.ts.map +0 -1
- package/dist/coValues/inbox.d.ts.map +0 -1
- package/dist/coValues/interfaces.d.ts.map +0 -1
- package/dist/coValues/profile.d.ts.map +0 -1
- package/dist/coValues/registeredSchemas.d.ts.map +0 -1
- package/dist/coValues/schemaUnion.d.ts.map +0 -1
- package/dist/exports.d.ts +0 -23
- package/dist/exports.d.ts.map +0 -1
- package/dist/implementation/ContextManager.d.ts.map +0 -1
- package/dist/implementation/activeAccountContext.d.ts.map +0 -1
- package/dist/implementation/anonymousJazzAgent.d.ts.map +0 -1
- package/dist/implementation/createContext.d.ts.map +0 -1
- package/dist/implementation/devtoolsFormatters.d.ts.map +0 -1
- package/dist/implementation/errors.d.ts.map +0 -1
- package/dist/implementation/inspect.d.ts.map +0 -1
- package/dist/implementation/invites.d.ts.map +0 -1
- package/dist/implementation/refs.d.ts.map +0 -1
- package/dist/implementation/schema.d.ts.map +0 -1
- package/dist/implementation/symbols.d.ts.map +0 -1
- package/dist/implementation/zodSchema/coExport.d.ts.map +0 -1
- package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +0 -1
- package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +0 -1
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +0 -1
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +0 -1
- package/dist/implementation/zodSchema/unionUtils.d.ts.map +0 -1
- package/dist/implementation/zodSchema/zodCo.d.ts.map +0 -1
- package/dist/implementation/zodSchema/zodReExport.d.ts.map +0 -1
- package/dist/implementation/zodSchema/zodSchema.d.ts.map +0 -1
- package/dist/internal.d.ts.map +0 -1
- package/dist/lib/cache.d.ts.map +0 -1
- package/dist/lib/cache.test.d.ts.map +0 -1
- package/dist/lib/migration.d.ts.map +0 -1
- package/dist/subscribe/CoValueCoreSubscription.d.ts.map +0 -1
- package/dist/subscribe/JazzError.d.ts.map +0 -1
- package/dist/subscribe/SubscriptionScope.d.ts.map +0 -1
- package/dist/subscribe/index.d.ts.map +0 -1
- package/dist/subscribe/types.d.ts.map +0 -1
- package/dist/subscribe/utils.d.ts.map +0 -1
- package/dist/tests/AuthSecretStorage.test.d.ts.map +0 -1
- package/dist/tests/ContextManager.test.d.ts.map +0 -1
- package/dist/tests/DemoAuth.test.d.ts.map +0 -1
- package/dist/tests/PassphraseAuth.test.d.ts.map +0 -1
- package/dist/tests/account.test.d.ts.map +0 -1
- package/dist/tests/coFeed.test-d.d.ts.map +0 -1
- package/dist/tests/coFeed.test.d.ts.map +0 -1
- package/dist/tests/coList.test-d.d.ts.map +0 -1
- package/dist/tests/coList.test.d.ts.map +0 -1
- package/dist/tests/coMap.record.test-d.d.ts.map +0 -1
- package/dist/tests/coMap.record.test.d.ts.map +0 -1
- package/dist/tests/coMap.test-d.d.ts.map +0 -1
- package/dist/tests/coMap.test.d.ts.map +0 -1
- package/dist/tests/coPlainText.test.d.ts.map +0 -1
- package/dist/tests/createContext.test.d.ts.map +0 -1
- package/dist/tests/deepLoading.test.d.ts.map +0 -1
- package/dist/tests/fixtures.d.ts.map +0 -1
- package/dist/tests/groupsAndAccounts.test.d.ts.map +0 -1
- package/dist/tests/imageDef.test.d.ts.map +0 -1
- package/dist/tests/inbox.test.d.ts.map +0 -1
- package/dist/tests/interfaces.test.d.ts.map +0 -1
- package/dist/tests/invites.test.d.ts.map +0 -1
- package/dist/tests/load.test.d.ts.map +0 -1
- package/dist/tests/patterns/notifications.test.d.ts.map +0 -1
- package/dist/tests/patterns/requestToJoin.test.d.ts.map +0 -1
- package/dist/tests/schema.test.d.ts.map +0 -1
- package/dist/tests/schemaUnion.test.d.ts.map +0 -1
- package/dist/tests/subscribe.test.d.ts.map +0 -1
- package/dist/tests/testing.test.d.ts.map +0 -1
- package/dist/tests/utils.d.ts.map +0 -1
- package/dist/tests/zod.test.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/src/coValues/coFeed.ts +0 -938
- package/src/exports.ts +0 -108
- package/src/tests/coFeed.test.ts +0 -722
- /package/dist/{tests → react-core/tests}/fixtures.d.ts +0 -0
- /package/dist/{auth → tools/auth}/AuthSecretStorage.d.ts +0 -0
- /package/dist/{auth → tools/auth}/DemoAuth.d.ts +0 -0
- /package/dist/{auth → tools/auth}/InMemoryKVStore.d.ts +0 -0
- /package/dist/{auth → tools/auth}/KvStoreContext.d.ts +0 -0
- /package/dist/{auth → tools/auth}/PassphraseAuth.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/CoValueBase.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/account.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/coList.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/coMap.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/coPlainText.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/coRichText.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/deepLoading.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/extensions/imageDef.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/group.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/inbox.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/interfaces.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/profile.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/registeredSchemas.d.ts +0 -0
- /package/dist/{coValues → tools/coValues}/schemaUnion.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/ContextManager.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/activeAccountContext.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/anonymousJazzAgent.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/createContext.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/devtoolsFormatters.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/errors.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/inspect.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/invites.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/refs.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/schema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/symbols.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/coExport.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/schemaTypes/AccountSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/schemaTypes/CoFeedSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/schemaTypes/CoListSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/schemaTypes/CoMapSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/schemaTypes/CoRecordSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/schemaTypes/FileStreamSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/schemaTypes/PlainTextSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/schemaTypes/RichTextSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/typeConverters/InstanceOfSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/unionUtils.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/zodCo.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/zodReExport.d.ts +0 -0
- /package/dist/{implementation → tools/implementation}/zodSchema/zodSchema.d.ts +0 -0
- /package/dist/{internal.d.ts → tools/internal.d.ts} +0 -0
- /package/dist/{lib → tools/lib}/cache.d.ts +0 -0
- /package/dist/{lib → tools/lib}/cache.test.d.ts +0 -0
- /package/dist/{lib → tools/lib}/migration.d.ts +0 -0
- /package/dist/{subscribe → tools/subscribe}/CoValueCoreSubscription.d.ts +0 -0
- /package/dist/{subscribe → tools/subscribe}/JazzError.d.ts +0 -0
- /package/dist/{subscribe → tools/subscribe}/SubscriptionScope.d.ts +0 -0
- /package/dist/{subscribe → tools/subscribe}/index.d.ts +0 -0
- /package/dist/{subscribe → tools/subscribe}/types.d.ts +0 -0
- /package/dist/{subscribe → tools/subscribe}/utils.d.ts +0 -0
- /package/dist/{tests → tools/tests}/AuthSecretStorage.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/ContextManager.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/DemoAuth.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/PassphraseAuth.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/account.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/coFeed.test-d.d.ts +0 -0
- /package/dist/{tests → tools/tests}/coFeed.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/coList.test-d.d.ts +0 -0
- /package/dist/{tests → tools/tests}/coList.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/coMap.record.test-d.d.ts +0 -0
- /package/dist/{tests → tools/tests}/coMap.record.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/coMap.test-d.d.ts +0 -0
- /package/dist/{tests → tools/tests}/coMap.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/coPlainText.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/createContext.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/deepLoading.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/groupsAndAccounts.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/imageDef.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/inbox.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/interfaces.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/invites.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/load.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/patterns/notifications.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/patterns/requestToJoin.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/schema.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/schemaUnion.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/subscribe.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/testing.test.d.ts +0 -0
- /package/dist/{tests → tools/tests}/utils.d.ts +0 -0
- /package/dist/{tests → tools/tests}/zod.test.d.ts +0 -0
- /package/dist/{types.d.ts → tools/types.d.ts} +0 -0
- /package/src/{tests → react-core/tests}/fixtures.ts +0 -0
- /package/src/{auth/KvStoreContext.ts → react-native-core/storage/kv-store-context.ts} +0 -0
- /package/src/{auth → tools/auth}/AuthSecretStorage.ts +0 -0
- /package/src/{auth → tools/auth}/DemoAuth.ts +0 -0
- /package/src/{auth → tools/auth}/InMemoryKVStore.ts +0 -0
- /package/src/{auth → tools/auth}/PassphraseAuth.ts +0 -0
- /package/src/{coValues → tools/coValues}/CoValueBase.ts +0 -0
- /package/src/{coValues → tools/coValues}/account.ts +0 -0
- /package/src/{coValues → tools/coValues}/coList.ts +0 -0
- /package/src/{coValues → tools/coValues}/coMap.ts +0 -0
- /package/src/{coValues → tools/coValues}/coPlainText.ts +0 -0
- /package/src/{coValues → tools/coValues}/coRichText.ts +0 -0
- /package/src/{coValues → tools/coValues}/deepLoading.ts +0 -0
- /package/src/{coValues → tools/coValues}/extensions/imageDef.ts +0 -0
- /package/src/{coValues → tools/coValues}/group.ts +0 -0
- /package/src/{coValues → tools/coValues}/inbox.ts +0 -0
- /package/src/{coValues → tools/coValues}/interfaces.ts +0 -0
- /package/src/{coValues → tools/coValues}/profile.ts +0 -0
- /package/src/{coValues → tools/coValues}/registeredSchemas.ts +0 -0
- /package/src/{coValues → tools/coValues}/schemaUnion.ts +0 -0
- /package/src/{implementation → tools/implementation}/ContextManager.ts +0 -0
- /package/src/{implementation → tools/implementation}/activeAccountContext.ts +0 -0
- /package/src/{implementation → tools/implementation}/anonymousJazzAgent.ts +0 -0
- /package/src/{implementation → tools/implementation}/createContext.ts +0 -0
- /package/src/{implementation → tools/implementation}/devtoolsFormatters.ts +0 -0
- /package/src/{implementation → tools/implementation}/errors.ts +0 -0
- /package/src/{implementation → tools/implementation}/inspect.ts +0 -0
- /package/src/{implementation → tools/implementation}/invites.ts +0 -0
- /package/src/{implementation → tools/implementation}/refs.ts +0 -0
- /package/src/{implementation → tools/implementation}/schema.ts +0 -0
- /package/src/{implementation → tools/implementation}/symbols.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/coExport.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/schemaTypes/AccountSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/schemaTypes/CoFeedSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/schemaTypes/CoListSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/schemaTypes/CoMapSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/schemaTypes/CoRecordSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/schemaTypes/FileStreamSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/schemaTypes/PlainTextSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/schemaTypes/RichTextSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/typeConverters/InstanceOfSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/unionUtils.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/zodCo.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/zodReExport.ts +0 -0
- /package/src/{implementation → tools/implementation}/zodSchema/zodSchema.ts +0 -0
- /package/src/{internal.ts → tools/internal.ts} +0 -0
- /package/src/{lib → tools/lib}/cache.test.ts +0 -0
- /package/src/{lib → tools/lib}/cache.ts +0 -0
- /package/src/{lib → tools/lib}/migration.ts +0 -0
- /package/src/{subscribe → tools/subscribe}/CoValueCoreSubscription.ts +0 -0
- /package/src/{subscribe → tools/subscribe}/JazzError.ts +0 -0
- /package/src/{subscribe → tools/subscribe}/SubscriptionScope.ts +0 -0
- /package/src/{subscribe → tools/subscribe}/index.ts +0 -0
- /package/src/{subscribe → tools/subscribe}/types.ts +0 -0
- /package/src/{subscribe → tools/subscribe}/utils.ts +0 -0
- /package/src/{tests → tools/tests}/AuthSecretStorage.test.ts +0 -0
- /package/src/{tests → tools/tests}/ContextManager.test.ts +0 -0
- /package/src/{tests → tools/tests}/DemoAuth.test.ts +0 -0
- /package/src/{tests → tools/tests}/PassphraseAuth.test.ts +0 -0
- /package/src/{tests → tools/tests}/account.test.ts +0 -0
- /package/src/{tests → tools/tests}/coFeed.test-d.ts +0 -0
- /package/src/{tests → tools/tests}/coList.test-d.ts +0 -0
- /package/src/{tests → tools/tests}/coList.test.ts +0 -0
- /package/src/{tests → tools/tests}/coMap.record.test-d.ts +0 -0
- /package/src/{tests → tools/tests}/coMap.record.test.ts +0 -0
- /package/src/{tests → tools/tests}/coMap.test-d.ts +0 -0
- /package/src/{tests → tools/tests}/coMap.test.ts +0 -0
- /package/src/{tests → tools/tests}/coPlainText.test.ts +0 -0
- /package/src/{tests → tools/tests}/createContext.test.ts +0 -0
- /package/src/{tests → tools/tests}/deepLoading.test.ts +0 -0
- /package/src/{tests → tools/tests}/groupsAndAccounts.test.ts +0 -0
- /package/src/{tests → tools/tests}/imageDef.test.ts +0 -0
- /package/src/{tests → tools/tests}/inbox.test.ts +0 -0
- /package/src/{tests → tools/tests}/interfaces.test.ts +0 -0
- /package/src/{tests → tools/tests}/invites.test.ts +0 -0
- /package/src/{tests → tools/tests}/load.test.ts +0 -0
- /package/src/{tests → tools/tests}/patterns/notifications.test.ts +0 -0
- /package/src/{tests → tools/tests}/patterns/requestToJoin.test.ts +0 -0
- /package/src/{tests → tools/tests}/schema.test.ts +0 -0
- /package/src/{tests → tools/tests}/schemaUnion.test.ts +0 -0
- /package/src/{tests → tools/tests}/subscribe.test.ts +0 -0
- /package/src/{tests → tools/tests}/testing.test.ts +0 -0
- /package/src/{tests → tools/tests}/utils.ts +0 -0
- /package/src/{tests → tools/tests}/zod.test.ts +0 -0
- /package/src/{types.ts → tools/types.ts} +0 -0
package/dist/chunk-G3QC4FAY.js
DELETED
@@ -1,4826 +0,0 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __export = (target, all) => {
|
3
|
-
for (var name in all)
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
5
|
-
};
|
6
|
-
|
7
|
-
// src/implementation/zodSchema/zodReExport.ts
|
8
|
-
var zodReExport_exports = {};
|
9
|
-
__export(zodReExport_exports, {
|
10
|
-
array: () => array,
|
11
|
-
base64: () => base64,
|
12
|
-
base64url: () => base64url,
|
13
|
-
boolean: () => boolean,
|
14
|
-
cidrv4: () => cidrv4,
|
15
|
-
cidrv6: () => cidrv6,
|
16
|
-
cuid: () => cuid,
|
17
|
-
cuid2: () => cuid2,
|
18
|
-
date: () => date,
|
19
|
-
discriminatedUnion: () => discriminatedUnion,
|
20
|
-
email: () => email,
|
21
|
-
emoji: () => emoji,
|
22
|
-
enum: () => enum2,
|
23
|
-
int: () => int,
|
24
|
-
int32: () => int32,
|
25
|
-
ipv4: () => ipv4,
|
26
|
-
ipv6: () => ipv6,
|
27
|
-
iso: () => iso,
|
28
|
-
json: () => json,
|
29
|
-
literal: () => literal,
|
30
|
-
nanoid: () => nanoid,
|
31
|
-
number: () => number,
|
32
|
-
object: () => object,
|
33
|
-
optional: () => optional,
|
34
|
-
strictObject: () => strictObject,
|
35
|
-
string: () => string,
|
36
|
-
templateLiteral: () => templateLiteral,
|
37
|
-
tuple: () => tuple,
|
38
|
-
ulid: () => ulid,
|
39
|
-
union: () => union,
|
40
|
-
url: () => url,
|
41
|
-
uuid: () => uuid,
|
42
|
-
z: () => z
|
43
|
-
});
|
44
|
-
import {
|
45
|
-
string,
|
46
|
-
number,
|
47
|
-
boolean,
|
48
|
-
union,
|
49
|
-
object,
|
50
|
-
array,
|
51
|
-
templateLiteral,
|
52
|
-
json,
|
53
|
-
tuple,
|
54
|
-
date,
|
55
|
-
emoji,
|
56
|
-
base64,
|
57
|
-
base64url,
|
58
|
-
nanoid,
|
59
|
-
cuid,
|
60
|
-
cuid2,
|
61
|
-
ulid,
|
62
|
-
ipv4,
|
63
|
-
ipv6,
|
64
|
-
email,
|
65
|
-
url,
|
66
|
-
uuid,
|
67
|
-
literal,
|
68
|
-
enum as enum2,
|
69
|
-
cidrv4,
|
70
|
-
cidrv6,
|
71
|
-
iso,
|
72
|
-
int32,
|
73
|
-
strictObject,
|
74
|
-
discriminatedUnion,
|
75
|
-
int,
|
76
|
-
optional,
|
77
|
-
z
|
78
|
-
} from "zod/v4";
|
79
|
-
|
80
|
-
// src/coValues/CoValueBase.ts
|
81
|
-
import { ControlledAccount, RawAccount } from "cojson";
|
82
|
-
var CoValueBase = class {
|
83
|
-
get _owner() {
|
84
|
-
const schema = this._raw.group instanceof RawAccount ? RegisteredSchemas["Account"] : RegisteredSchemas["Group"];
|
85
|
-
return accessChildById(this, this._raw.group.id, {
|
86
|
-
ref: schema,
|
87
|
-
optional: false
|
88
|
-
});
|
89
|
-
}
|
90
|
-
/** @private */
|
91
|
-
get _loadedAs() {
|
92
|
-
const agent = this._raw.core.node.getCurrentAgent();
|
93
|
-
if (agent instanceof ControlledAccount) {
|
94
|
-
return coValuesCache.get(
|
95
|
-
agent.account,
|
96
|
-
() => anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(
|
97
|
-
agent.account
|
98
|
-
)
|
99
|
-
);
|
100
|
-
}
|
101
|
-
return new AnonymousJazzAgent(this._raw.core.node);
|
102
|
-
}
|
103
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
104
|
-
constructor(..._args) {
|
105
|
-
Object.defineProperty(this, "_instanceID", {
|
106
|
-
value: `instance-${Math.random().toString(36).slice(2)}`,
|
107
|
-
enumerable: false
|
108
|
-
});
|
109
|
-
}
|
110
|
-
/** @category Internals */
|
111
|
-
static fromRaw(raw) {
|
112
|
-
return new this({ fromRaw: raw });
|
113
|
-
}
|
114
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
115
|
-
toJSON() {
|
116
|
-
return {
|
117
|
-
id: this.id,
|
118
|
-
type: this._type,
|
119
|
-
error: "unknown CoValue class"
|
120
|
-
};
|
121
|
-
}
|
122
|
-
[inspect]() {
|
123
|
-
return this.toJSON();
|
124
|
-
}
|
125
|
-
/** @category Type Helpers */
|
126
|
-
castAs(schema) {
|
127
|
-
const cl = "getCoSchema" in schema ? schema.getCoSchema() : schema;
|
128
|
-
if (this.constructor === cl) {
|
129
|
-
return this;
|
130
|
-
}
|
131
|
-
return cl.fromRaw(this._raw);
|
132
|
-
}
|
133
|
-
};
|
134
|
-
|
135
|
-
// src/implementation/inspect.ts
|
136
|
-
var inspect = Symbol.for("nodejs.util.inspect.custom");
|
137
|
-
|
138
|
-
// src/implementation/symbols.ts
|
139
|
-
var SchemaInit = "$SchemaInit$";
|
140
|
-
var ItemsSym = "$items$";
|
141
|
-
|
142
|
-
// src/coValues/registeredSchemas.ts
|
143
|
-
var RegisteredSchemas = {};
|
144
|
-
|
145
|
-
// src/coValues/coMap.ts
|
146
|
-
import {
|
147
|
-
cojsonInternals
|
148
|
-
} from "cojson";
|
149
|
-
var _CoMap = class _CoMap extends CoValueBase {
|
150
|
-
/** @internal */
|
151
|
-
get _schema() {
|
152
|
-
return this.constructor._schema;
|
153
|
-
}
|
154
|
-
/**
|
155
|
-
* The timestamp of the creation time of the CoMap
|
156
|
-
*/
|
157
|
-
get _createdAt() {
|
158
|
-
return this._raw.earliestTxMadeAt ?? Number.MAX_SAFE_INTEGER;
|
159
|
-
}
|
160
|
-
/**
|
161
|
-
* The timestamp of the last updated time of the CoMap
|
162
|
-
*/
|
163
|
-
get _lastUpdatedAt() {
|
164
|
-
return this._raw.latestTxMadeAt;
|
165
|
-
}
|
166
|
-
/**
|
167
|
-
* If property `prop` is a `coField.ref(...)`, you can use `coMaps._refs.prop` to access
|
168
|
-
* the `Ref` instead of the potentially loaded/null value.
|
169
|
-
*
|
170
|
-
* This allows you to always get the ID or load the value manually.
|
171
|
-
*
|
172
|
-
* @example
|
173
|
-
* ```ts
|
174
|
-
* person._refs.pet.id; // => ID<Animal>
|
175
|
-
* person._refs.pet.value;
|
176
|
-
* // => Animal | null
|
177
|
-
* const pet = await person._refs.pet.load();
|
178
|
-
* ```
|
179
|
-
*
|
180
|
-
* @category Content
|
181
|
-
**/
|
182
|
-
get _refs() {
|
183
|
-
return makeRefs(
|
184
|
-
this,
|
185
|
-
(key) => this._raw.get(key),
|
186
|
-
() => {
|
187
|
-
const keys = this._raw.keys().filter((key) => {
|
188
|
-
const descriptor = this.getDescriptor(key);
|
189
|
-
return descriptor && descriptor !== "json" && isRefEncoded(descriptor);
|
190
|
-
});
|
191
|
-
return keys;
|
192
|
-
},
|
193
|
-
this._loadedAs,
|
194
|
-
(key) => this.getDescriptor(key)
|
195
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
196
|
-
);
|
197
|
-
}
|
198
|
-
/** @internal */
|
199
|
-
getEditFromRaw(target, rawEdit, descriptor, key) {
|
200
|
-
return {
|
201
|
-
value: descriptor === "json" ? rawEdit.value : "encoded" in descriptor ? rawEdit.value === null || rawEdit.value === void 0 ? rawEdit.value : descriptor.encoded.decode(rawEdit.value) : accessChildById(target, rawEdit.value, descriptor),
|
202
|
-
ref: descriptor !== "json" && isRefEncoded(descriptor) ? new Ref(
|
203
|
-
rawEdit.value,
|
204
|
-
target._loadedAs,
|
205
|
-
descriptor,
|
206
|
-
target
|
207
|
-
) : void 0,
|
208
|
-
get by() {
|
209
|
-
return rawEdit.by && accessChildById(target, rawEdit.by, {
|
210
|
-
ref: Account,
|
211
|
-
optional: false
|
212
|
-
});
|
213
|
-
},
|
214
|
-
madeAt: rawEdit.at,
|
215
|
-
key
|
216
|
-
};
|
217
|
-
}
|
218
|
-
/** @category Collaboration */
|
219
|
-
get _edits() {
|
220
|
-
const map = this;
|
221
|
-
return new Proxy(
|
222
|
-
{},
|
223
|
-
{
|
224
|
-
get(_target, key) {
|
225
|
-
const rawEdit = map._raw.lastEditAt(key);
|
226
|
-
if (!rawEdit) return void 0;
|
227
|
-
const descriptor = map.getDescriptor(key);
|
228
|
-
if (!descriptor) return void 0;
|
229
|
-
return {
|
230
|
-
...map.getEditFromRaw(map, rawEdit, descriptor, key),
|
231
|
-
get all() {
|
232
|
-
return [...map._raw.editsAt(key)].map(
|
233
|
-
(rawEdit2) => map.getEditFromRaw(map, rawEdit2, descriptor, key)
|
234
|
-
);
|
235
|
-
}
|
236
|
-
};
|
237
|
-
},
|
238
|
-
ownKeys(_target) {
|
239
|
-
return map._raw.keys();
|
240
|
-
},
|
241
|
-
getOwnPropertyDescriptor(target, key) {
|
242
|
-
return {
|
243
|
-
value: Reflect.get(target, key),
|
244
|
-
writable: false,
|
245
|
-
enumerable: true,
|
246
|
-
configurable: true
|
247
|
-
};
|
248
|
-
}
|
249
|
-
}
|
250
|
-
);
|
251
|
-
}
|
252
|
-
/** @internal */
|
253
|
-
constructor(options) {
|
254
|
-
super();
|
255
|
-
if (options) {
|
256
|
-
if ("fromRaw" in options) {
|
257
|
-
Object.defineProperties(this, {
|
258
|
-
id: {
|
259
|
-
value: options.fromRaw.id,
|
260
|
-
enumerable: false
|
261
|
-
},
|
262
|
-
_raw: { value: options.fromRaw, enumerable: false }
|
263
|
-
});
|
264
|
-
} else {
|
265
|
-
throw new Error("Invalid CoMap constructor arguments");
|
266
|
-
}
|
267
|
-
}
|
268
|
-
return new Proxy(this, CoMapProxyHandler);
|
269
|
-
}
|
270
|
-
/**
|
271
|
-
* Create a new CoMap with the given initial values and owner.
|
272
|
-
*
|
273
|
-
* The owner (a Group or Account) determines access rights to the CoMap.
|
274
|
-
*
|
275
|
-
* The CoMap will immediately be persisted and synced to connected peers.
|
276
|
-
*
|
277
|
-
* @example
|
278
|
-
* ```ts
|
279
|
-
* const person = Person.create({
|
280
|
-
* name: "Alice",
|
281
|
-
* age: 42,
|
282
|
-
* pet: cat,
|
283
|
-
* }, { owner: friendGroup });
|
284
|
-
* ```
|
285
|
-
*
|
286
|
-
* @category Creation
|
287
|
-
**/
|
288
|
-
static create(init, options) {
|
289
|
-
const instance = new this();
|
290
|
-
const { owner, uniqueness } = parseCoValueCreateOptions(options);
|
291
|
-
const raw = instance.rawFromInit(init, owner, uniqueness);
|
292
|
-
Object.defineProperties(instance, {
|
293
|
-
id: {
|
294
|
-
value: raw.id,
|
295
|
-
enumerable: false
|
296
|
-
},
|
297
|
-
_raw: { value: raw, enumerable: false }
|
298
|
-
});
|
299
|
-
return instance;
|
300
|
-
}
|
301
|
-
/**
|
302
|
-
* Return a JSON representation of the `CoMap`
|
303
|
-
* @category Content
|
304
|
-
*/
|
305
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
306
|
-
toJSON(_key, processedValues) {
|
307
|
-
const result = {
|
308
|
-
id: this.id,
|
309
|
-
_type: this._type
|
310
|
-
};
|
311
|
-
for (const key of this._raw.keys()) {
|
312
|
-
const tKey = key;
|
313
|
-
const descriptor = this.getDescriptor(tKey);
|
314
|
-
if (!descriptor) {
|
315
|
-
continue;
|
316
|
-
}
|
317
|
-
if (descriptor == "json" || "encoded" in descriptor) {
|
318
|
-
result[key] = this._raw.get(key);
|
319
|
-
} else if (isRefEncoded(descriptor)) {
|
320
|
-
const id = this._raw.get(key);
|
321
|
-
if (processedValues?.includes(id) || id === this.id) {
|
322
|
-
result[key] = { _circular: id };
|
323
|
-
continue;
|
324
|
-
}
|
325
|
-
const ref2 = this[tKey];
|
326
|
-
if (ref2 && typeof ref2 === "object" && "toJSON" in ref2 && typeof ref2.toJSON === "function") {
|
327
|
-
const jsonedRef = ref2.toJSON(tKey, [
|
328
|
-
...processedValues || [],
|
329
|
-
this.id
|
330
|
-
]);
|
331
|
-
result[key] = jsonedRef;
|
332
|
-
}
|
333
|
-
} else {
|
334
|
-
result[key] = void 0;
|
335
|
-
}
|
336
|
-
}
|
337
|
-
return result;
|
338
|
-
}
|
339
|
-
[inspect]() {
|
340
|
-
return this.toJSON();
|
341
|
-
}
|
342
|
-
/**
|
343
|
-
* Create a new `RawCoMap` from an initialization object
|
344
|
-
* @internal
|
345
|
-
*/
|
346
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
347
|
-
rawFromInit(init, owner, uniqueness) {
|
348
|
-
const rawOwner = owner._raw;
|
349
|
-
const rawInit = {};
|
350
|
-
if (init)
|
351
|
-
for (const key of Object.keys(init)) {
|
352
|
-
const initValue = init[key];
|
353
|
-
const descriptor = this.getDescriptor(key);
|
354
|
-
if (!descriptor) {
|
355
|
-
continue;
|
356
|
-
}
|
357
|
-
if (descriptor === "json") {
|
358
|
-
rawInit[key] = initValue;
|
359
|
-
} else if (isRefEncoded(descriptor)) {
|
360
|
-
if (initValue) {
|
361
|
-
rawInit[key] = initValue.id;
|
362
|
-
}
|
363
|
-
} else if ("encoded" in descriptor) {
|
364
|
-
rawInit[key] = descriptor.encoded.encode(
|
365
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
366
|
-
initValue
|
367
|
-
);
|
368
|
-
}
|
369
|
-
}
|
370
|
-
return rawOwner.createMap(rawInit, null, "private", uniqueness);
|
371
|
-
}
|
372
|
-
getDescriptor(key) {
|
373
|
-
return this._schema?.[key] || this._schema?.[ItemsSym];
|
374
|
-
}
|
375
|
-
/**
|
376
|
-
* Declare a Record-like CoMap schema, by extending `CoMap.Record(...)` and passing the value schema using `co`. Keys are always `string`.
|
377
|
-
*
|
378
|
-
* @example
|
379
|
-
* ```ts
|
380
|
-
* import { coField, CoMap } from "jazz-tools";
|
381
|
-
*
|
382
|
-
* class ColorToFruitMap extends CoMap.Record(
|
383
|
-
* coField.ref(Fruit)
|
384
|
-
* ) {}
|
385
|
-
*
|
386
|
-
* // assume we have map: ColorToFruitMap
|
387
|
-
* // and strawberry: Fruit
|
388
|
-
* map["red"] = strawberry;
|
389
|
-
* ```
|
390
|
-
*
|
391
|
-
* @category Declaration
|
392
|
-
*/
|
393
|
-
static Record(value) {
|
394
|
-
var _a, _b;
|
395
|
-
class RecordLikeCoMap extends (_b = _CoMap, _a = ItemsSym, _b) {
|
396
|
-
constructor() {
|
397
|
-
super(...arguments);
|
398
|
-
this[_a] = value;
|
399
|
-
}
|
400
|
-
}
|
401
|
-
return RecordLikeCoMap;
|
402
|
-
}
|
403
|
-
/**
|
404
|
-
* Load a `CoMap` with a given ID, as a given account.
|
405
|
-
*
|
406
|
-
* `depth` specifies which (if any) fields that reference other CoValues to load as well before resolving.
|
407
|
-
* The `DeeplyLoaded` return type guarantees that corresponding referenced CoValues are loaded to the specified depth.
|
408
|
-
*
|
409
|
-
* You can pass `[]` or `{}` for shallowly loading only this CoMap, or `{ fieldA: depthA, fieldB: depthB }` for recursively loading referenced CoValues.
|
410
|
-
*
|
411
|
-
* Check out the `load` methods on `CoMap`/`CoList`/`CoFeed`/`Group`/`Account` to see which depth structures are valid to nest.
|
412
|
-
*
|
413
|
-
* @example
|
414
|
-
* ```ts
|
415
|
-
* const person = await Person.load(
|
416
|
-
* "co_zdsMhHtfG6VNKt7RqPUPvUtN2Ax",
|
417
|
-
* { pet: {} }
|
418
|
-
* );
|
419
|
-
* ```
|
420
|
-
*
|
421
|
-
* @category Subscription & Loading
|
422
|
-
*/
|
423
|
-
static load(id, options) {
|
424
|
-
return loadCoValueWithoutMe(this, id, options);
|
425
|
-
}
|
426
|
-
static subscribe(id, ...args) {
|
427
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
428
|
-
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
429
|
-
}
|
430
|
-
static findUnique(unique, ownerID, as) {
|
431
|
-
as ||= activeAccountContext.get();
|
432
|
-
const header = {
|
433
|
-
type: "comap",
|
434
|
-
ruleset: {
|
435
|
-
type: "ownedByGroup",
|
436
|
-
group: ownerID
|
437
|
-
},
|
438
|
-
meta: null,
|
439
|
-
uniqueness: unique
|
440
|
-
};
|
441
|
-
const crypto = as._type === "Anonymous" ? as.node.crypto : as._raw.core.node.crypto;
|
442
|
-
return cojsonInternals.idforHeader(header, crypto);
|
443
|
-
}
|
444
|
-
/**
|
445
|
-
* Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth.
|
446
|
-
*
|
447
|
-
* Works like `CoMap.load()`, but you don't need to pass the ID or the account to load as again.
|
448
|
-
*
|
449
|
-
* @category Subscription & Loading
|
450
|
-
*/
|
451
|
-
ensureLoaded(options) {
|
452
|
-
return ensureCoValueLoaded(this, options);
|
453
|
-
}
|
454
|
-
subscribe(...args) {
|
455
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
456
|
-
return subscribeToExistingCoValue(this, options, listener);
|
457
|
-
}
|
458
|
-
applyDiff(newValues) {
|
459
|
-
for (const key in newValues) {
|
460
|
-
if (Object.prototype.hasOwnProperty.call(newValues, key)) {
|
461
|
-
const tKey = key;
|
462
|
-
const descriptor = this.getDescriptor(key);
|
463
|
-
if (!descriptor) continue;
|
464
|
-
const newValue = newValues[tKey];
|
465
|
-
const currentValue = this[tKey];
|
466
|
-
if (descriptor === "json" || "encoded" in descriptor) {
|
467
|
-
if (currentValue !== newValue) {
|
468
|
-
this[tKey] = newValue;
|
469
|
-
}
|
470
|
-
} else if (isRefEncoded(descriptor)) {
|
471
|
-
const currentId = currentValue?.id;
|
472
|
-
const newId = newValue?.id;
|
473
|
-
if (currentId !== newId) {
|
474
|
-
this[tKey] = newValue;
|
475
|
-
}
|
476
|
-
}
|
477
|
-
}
|
478
|
-
}
|
479
|
-
return this;
|
480
|
-
}
|
481
|
-
/**
|
482
|
-
* Wait for the `CoMap` to be uploaded to the other peers.
|
483
|
-
*
|
484
|
-
* @category Subscription & Loading
|
485
|
-
*/
|
486
|
-
waitForSync(options) {
|
487
|
-
return this._raw.core.waitForSync(options);
|
488
|
-
}
|
489
|
-
};
|
490
|
-
_CoMap.prototype._type = "CoMap";
|
491
|
-
var CoMap = _CoMap;
|
492
|
-
var CoMapProxyHandler = {
|
493
|
-
get(target, key, receiver) {
|
494
|
-
if (key === "_schema") {
|
495
|
-
return Reflect.get(target, key);
|
496
|
-
} else if (key in target) {
|
497
|
-
return Reflect.get(target, key, receiver);
|
498
|
-
} else {
|
499
|
-
if (typeof key !== "string") {
|
500
|
-
return void 0;
|
501
|
-
}
|
502
|
-
const descriptor = target.getDescriptor(key);
|
503
|
-
if (!descriptor) {
|
504
|
-
return void 0;
|
505
|
-
}
|
506
|
-
const raw = target._raw.get(key);
|
507
|
-
if (descriptor === "json") {
|
508
|
-
return raw;
|
509
|
-
} else if ("encoded" in descriptor) {
|
510
|
-
return raw === void 0 ? void 0 : descriptor.encoded.decode(raw);
|
511
|
-
} else if (isRefEncoded(descriptor)) {
|
512
|
-
return raw === void 0 || raw === null ? void 0 : accessChildByKey(target, raw, key);
|
513
|
-
}
|
514
|
-
}
|
515
|
-
},
|
516
|
-
set(target, key, value, receiver) {
|
517
|
-
if ((typeof key === "string" || ItemsSym) && typeof value === "object" && value !== null && SchemaInit in value) {
|
518
|
-
target.constructor._schema ||= {};
|
519
|
-
target.constructor._schema[key] = value[SchemaInit];
|
520
|
-
return true;
|
521
|
-
}
|
522
|
-
const descriptor = target.getDescriptor(key);
|
523
|
-
if (!descriptor) return false;
|
524
|
-
if (typeof key === "string") {
|
525
|
-
if (descriptor === "json") {
|
526
|
-
target._raw.set(key, value);
|
527
|
-
} else if ("encoded" in descriptor) {
|
528
|
-
target._raw.set(key, descriptor.encoded.encode(value));
|
529
|
-
} else if (isRefEncoded(descriptor)) {
|
530
|
-
if (value === void 0) {
|
531
|
-
if (descriptor.optional) {
|
532
|
-
target._raw.set(key, null);
|
533
|
-
} else {
|
534
|
-
throw new Error(
|
535
|
-
`Cannot set required reference ${key} to undefined`
|
536
|
-
);
|
537
|
-
}
|
538
|
-
} else if (value?.id) {
|
539
|
-
target._raw.set(key, value.id);
|
540
|
-
} else {
|
541
|
-
throw new Error(
|
542
|
-
`Cannot set reference ${key} to a non-CoValue. Got ${value}`
|
543
|
-
);
|
544
|
-
}
|
545
|
-
}
|
546
|
-
return true;
|
547
|
-
} else {
|
548
|
-
return Reflect.set(target, key, value, receiver);
|
549
|
-
}
|
550
|
-
},
|
551
|
-
defineProperty(target, key, attributes) {
|
552
|
-
if ("value" in attributes && typeof attributes.value === "object" && SchemaInit in attributes.value) {
|
553
|
-
target.constructor._schema ||= {};
|
554
|
-
target.constructor._schema[key] = attributes.value[SchemaInit];
|
555
|
-
return true;
|
556
|
-
} else {
|
557
|
-
return Reflect.defineProperty(target, key, attributes);
|
558
|
-
}
|
559
|
-
},
|
560
|
-
ownKeys(target) {
|
561
|
-
const keys = Reflect.ownKeys(target).filter((k) => k !== ItemsSym);
|
562
|
-
for (const key of target._raw.keys()) {
|
563
|
-
if (!keys.includes(key)) {
|
564
|
-
keys.push(key);
|
565
|
-
}
|
566
|
-
}
|
567
|
-
return keys;
|
568
|
-
},
|
569
|
-
getOwnPropertyDescriptor(target, key) {
|
570
|
-
if (key in target) {
|
571
|
-
return Reflect.getOwnPropertyDescriptor(target, key);
|
572
|
-
} else {
|
573
|
-
const descriptor = target.getDescriptor(key);
|
574
|
-
if (descriptor || key in target._raw.latest) {
|
575
|
-
return {
|
576
|
-
enumerable: true,
|
577
|
-
configurable: true,
|
578
|
-
writable: true
|
579
|
-
};
|
580
|
-
}
|
581
|
-
}
|
582
|
-
},
|
583
|
-
has(target, key) {
|
584
|
-
const descriptor = target.getDescriptor(key);
|
585
|
-
if (target._raw && typeof key === "string" && descriptor) {
|
586
|
-
return target._raw.get(key) !== void 0;
|
587
|
-
} else {
|
588
|
-
return Reflect.has(target, key);
|
589
|
-
}
|
590
|
-
},
|
591
|
-
deleteProperty(target, key) {
|
592
|
-
const descriptor = target.getDescriptor(key);
|
593
|
-
if (typeof key === "string" && descriptor) {
|
594
|
-
target._raw.delete(key);
|
595
|
-
return true;
|
596
|
-
} else {
|
597
|
-
return Reflect.deleteProperty(target, key);
|
598
|
-
}
|
599
|
-
}
|
600
|
-
};
|
601
|
-
RegisteredSchemas["CoMap"] = CoMap;
|
602
|
-
|
603
|
-
// src/coValues/coList.ts
|
604
|
-
import { ControlledAccount as ControlledAccount2, RawAccount as RawAccount2 } from "cojson";
|
605
|
-
import { calcPatch } from "fast-myers-diff";
|
606
|
-
var _CoList = class _CoList extends Array {
|
607
|
-
/**
|
608
|
-
* Declare a `CoList` by subclassing `CoList.Of(...)` and passing the item schema using `co`.
|
609
|
-
*
|
610
|
-
* @example
|
611
|
-
* ```ts
|
612
|
-
* class ColorList extends CoList.Of(
|
613
|
-
* coField.string
|
614
|
-
* ) {}
|
615
|
-
* class AnimalList extends CoList.Of(
|
616
|
-
* coField.ref(Animal)
|
617
|
-
* ) {}
|
618
|
-
* ```
|
619
|
-
*
|
620
|
-
* @category Declaration
|
621
|
-
*/
|
622
|
-
static Of(item) {
|
623
|
-
var _a, _b;
|
624
|
-
return class CoListOf extends (_b = _CoList, _a = coField.items, _b) {
|
625
|
-
constructor() {
|
626
|
-
super(...arguments);
|
627
|
-
this[_a] = item;
|
628
|
-
}
|
629
|
-
};
|
630
|
-
}
|
631
|
-
/**
|
632
|
-
* @ignore
|
633
|
-
* @deprecated Use UPPERCASE `CoList.Of` instead! */
|
634
|
-
static of(..._args) {
|
635
|
-
throw new Error("Can't use Array.of with CoLists");
|
636
|
-
}
|
637
|
-
/** @internal */
|
638
|
-
get _schema() {
|
639
|
-
return this.constructor._schema;
|
640
|
-
}
|
641
|
-
/** @category Collaboration */
|
642
|
-
get _owner() {
|
643
|
-
return this._raw.group instanceof RawAccount2 ? anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(
|
644
|
-
this._raw.group
|
645
|
-
) : RegisteredSchemas["Group"].fromRaw(this._raw.group);
|
646
|
-
}
|
647
|
-
/**
|
648
|
-
* If a `CoList`'s items are a `coField.ref(...)`, you can use `coList._refs[i]` to access
|
649
|
-
* the `Ref` instead of the potentially loaded/null value.
|
650
|
-
*
|
651
|
-
* This allows you to always get the ID or load the value manually.
|
652
|
-
*
|
653
|
-
* @example
|
654
|
-
* ```ts
|
655
|
-
* animals._refs[0].id; // => ID<Animal>
|
656
|
-
* animals._refs[0].value;
|
657
|
-
* // => Animal | null
|
658
|
-
* const animal = await animals._refs[0].load();
|
659
|
-
* ```
|
660
|
-
*
|
661
|
-
* @category Content
|
662
|
-
**/
|
663
|
-
get _refs() {
|
664
|
-
return makeRefs(
|
665
|
-
this,
|
666
|
-
(idx) => this._raw.get(idx),
|
667
|
-
() => Array.from({ length: this._raw.entries().length }, (_, idx) => idx),
|
668
|
-
this._loadedAs,
|
669
|
-
(_idx) => this._schema[ItemsSym]
|
670
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
671
|
-
);
|
672
|
-
}
|
673
|
-
get _edits() {
|
674
|
-
throw new Error("Not implemented");
|
675
|
-
}
|
676
|
-
get _loadedAs() {
|
677
|
-
const agent = this._raw.core.node.getCurrentAgent();
|
678
|
-
if (agent instanceof ControlledAccount2) {
|
679
|
-
return coValuesCache.get(
|
680
|
-
agent.account,
|
681
|
-
() => anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(
|
682
|
-
agent.account
|
683
|
-
)
|
684
|
-
);
|
685
|
-
}
|
686
|
-
return new AnonymousJazzAgent(this._raw.core.node);
|
687
|
-
}
|
688
|
-
static get [(ItemsSym, Symbol.species)]() {
|
689
|
-
return Array;
|
690
|
-
}
|
691
|
-
getItemsDescriptor() {
|
692
|
-
return this._schema?.[ItemsSym];
|
693
|
-
}
|
694
|
-
constructor(options) {
|
695
|
-
super();
|
696
|
-
Object.defineProperty(this, "_instanceID", {
|
697
|
-
value: `instance-${Math.random().toString(36).slice(2)}`,
|
698
|
-
enumerable: false
|
699
|
-
});
|
700
|
-
if (options && "fromRaw" in options) {
|
701
|
-
Object.defineProperties(this, {
|
702
|
-
id: {
|
703
|
-
value: options.fromRaw.id,
|
704
|
-
enumerable: false
|
705
|
-
},
|
706
|
-
_raw: { value: options.fromRaw, enumerable: false }
|
707
|
-
});
|
708
|
-
}
|
709
|
-
return new Proxy(this, CoListProxyHandler);
|
710
|
-
}
|
711
|
-
/**
|
712
|
-
* Create a new CoList with the given initial values and owner.
|
713
|
-
*
|
714
|
-
* The owner (a Group or Account) determines access rights to the CoMap.
|
715
|
-
*
|
716
|
-
* The CoList will immediately be persisted and synced to connected peers.
|
717
|
-
*
|
718
|
-
* @example
|
719
|
-
* ```ts
|
720
|
-
* const colours = ColorList.create(
|
721
|
-
* ["red", "green", "blue"],
|
722
|
-
* { owner: me }
|
723
|
-
* );
|
724
|
-
* const animals = AnimalList.create(
|
725
|
-
* [cat, dog, fish],
|
726
|
-
* { owner: me }
|
727
|
-
* );
|
728
|
-
* ```
|
729
|
-
*
|
730
|
-
* @category Creation
|
731
|
-
**/
|
732
|
-
static create(items, options) {
|
733
|
-
const { owner } = parseCoValueCreateOptions(options);
|
734
|
-
const instance = new this({ init: items, owner });
|
735
|
-
const raw = owner._raw.createList(
|
736
|
-
toRawItems(items, instance._schema[ItemsSym])
|
737
|
-
);
|
738
|
-
Object.defineProperties(instance, {
|
739
|
-
id: {
|
740
|
-
value: raw.id,
|
741
|
-
enumerable: false
|
742
|
-
},
|
743
|
-
_raw: { value: raw, enumerable: false }
|
744
|
-
});
|
745
|
-
return instance;
|
746
|
-
}
|
747
|
-
push(...items) {
|
748
|
-
this._raw.appendItems(
|
749
|
-
toRawItems(items, this._schema[ItemsSym]),
|
750
|
-
void 0,
|
751
|
-
"private"
|
752
|
-
);
|
753
|
-
return this._raw.entries().length;
|
754
|
-
}
|
755
|
-
unshift(...items) {
|
756
|
-
for (const item of toRawItems(items, this._schema[ItemsSym])) {
|
757
|
-
this._raw.prepend(item);
|
758
|
-
}
|
759
|
-
return this._raw.entries().length;
|
760
|
-
}
|
761
|
-
pop() {
|
762
|
-
const last = this[this.length - 1];
|
763
|
-
this._raw.delete(this.length - 1);
|
764
|
-
return last;
|
765
|
-
}
|
766
|
-
shift() {
|
767
|
-
const first = this[0];
|
768
|
-
this._raw.delete(0);
|
769
|
-
return first;
|
770
|
-
}
|
771
|
-
/**
|
772
|
-
* Splice the `CoList` at a given index.
|
773
|
-
*
|
774
|
-
* @param start - The index to start the splice.
|
775
|
-
* @param deleteCount - The number of items to delete.
|
776
|
-
* @param items - The items to insert.
|
777
|
-
*/
|
778
|
-
splice(start, deleteCount, ...items) {
|
779
|
-
const deleted = this.slice(start, start + deleteCount);
|
780
|
-
for (let idxToDelete = start + deleteCount - 1; idxToDelete >= start; idxToDelete--) {
|
781
|
-
this._raw.delete(idxToDelete);
|
782
|
-
}
|
783
|
-
const rawItems = toRawItems(items, this._schema[ItemsSym]);
|
784
|
-
if (rawItems.length === 0) {
|
785
|
-
return deleted;
|
786
|
-
}
|
787
|
-
if (rawItems.length === 1) {
|
788
|
-
const item = rawItems[0];
|
789
|
-
if (item === void 0) return deleted;
|
790
|
-
if (start === 0) {
|
791
|
-
this._raw.prepend(item);
|
792
|
-
} else {
|
793
|
-
this._raw.append(item, Math.max(start - 1, 0));
|
794
|
-
}
|
795
|
-
return deleted;
|
796
|
-
}
|
797
|
-
if (start === 0) {
|
798
|
-
for (let i = rawItems.length - 1; i >= 0; i--) {
|
799
|
-
const item = rawItems[i];
|
800
|
-
if (item === void 0) continue;
|
801
|
-
this._raw.prepend(item);
|
802
|
-
}
|
803
|
-
} else {
|
804
|
-
let appendAfter = Math.max(start - 1, 0);
|
805
|
-
for (const item of rawItems) {
|
806
|
-
if (item === void 0) continue;
|
807
|
-
this._raw.append(item, appendAfter);
|
808
|
-
appendAfter++;
|
809
|
-
}
|
810
|
-
}
|
811
|
-
return deleted;
|
812
|
-
}
|
813
|
-
/**
|
814
|
-
* Modify the `CoList` to match another list, where the changes are managed internally.
|
815
|
-
*
|
816
|
-
* @param result - The resolved list of items.
|
817
|
-
*/
|
818
|
-
applyDiff(result) {
|
819
|
-
const current = this._raw.asArray();
|
820
|
-
const comparator = isRefEncoded(this._schema[ItemsSym]) ? (aIdx, bIdx) => {
|
821
|
-
return current[aIdx]?.id === result[bIdx]?.id;
|
822
|
-
} : void 0;
|
823
|
-
const patches = [...calcPatch(current, result, comparator)];
|
824
|
-
for (const [from, to, insert] of patches.reverse()) {
|
825
|
-
this.splice(from, to - from, ...insert);
|
826
|
-
}
|
827
|
-
}
|
828
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
829
|
-
toJSON(_key, seenAbove) {
|
830
|
-
const itemDescriptor = this._schema[ItemsSym];
|
831
|
-
if (itemDescriptor === "json") {
|
832
|
-
return this._raw.asArray();
|
833
|
-
} else if ("encoded" in itemDescriptor) {
|
834
|
-
return this._raw.asArray().map((e) => itemDescriptor.encoded.encode(e));
|
835
|
-
} else if (isRefEncoded(itemDescriptor)) {
|
836
|
-
return this.map(
|
837
|
-
(item, idx) => seenAbove?.includes(item?.id) ? { _circular: item.id } : item?.toJSON(idx + "", [
|
838
|
-
...seenAbove || [],
|
839
|
-
this.id
|
840
|
-
])
|
841
|
-
);
|
842
|
-
} else {
|
843
|
-
return [];
|
844
|
-
}
|
845
|
-
}
|
846
|
-
[inspect]() {
|
847
|
-
return this.toJSON();
|
848
|
-
}
|
849
|
-
/** @category Internals */
|
850
|
-
static fromRaw(raw) {
|
851
|
-
return new this({ fromRaw: raw });
|
852
|
-
}
|
853
|
-
/** @internal */
|
854
|
-
static schema(def) {
|
855
|
-
this._schema ||= {};
|
856
|
-
Object.assign(this._schema, def);
|
857
|
-
}
|
858
|
-
/**
|
859
|
-
* Load a `CoList` with a given ID, as a given account.
|
860
|
-
*
|
861
|
-
* `depth` specifies if item CoValue references should be loaded as well before resolving.
|
862
|
-
* The `DeeplyLoaded` return type guarantees that corresponding referenced CoValues are loaded to the specified depth.
|
863
|
-
*
|
864
|
-
* You can pass `[]` or for shallowly loading only this CoList, or `[itemDepth]` for recursively loading referenced CoValues.
|
865
|
-
*
|
866
|
-
* Check out the `load` methods on `CoMap`/`CoList`/`CoFeed`/`Group`/`Account` to see which depth structures are valid to nest.
|
867
|
-
*
|
868
|
-
* @example
|
869
|
-
* ```ts
|
870
|
-
* const animalsWithVets =
|
871
|
-
* await ListOfAnimals.load(
|
872
|
-
* "co_zdsMhHtfG6VNKt7RqPUPvUtN2Ax",
|
873
|
-
* me,
|
874
|
-
* [{ vet: {} }]
|
875
|
-
* );
|
876
|
-
* ```
|
877
|
-
*
|
878
|
-
* @category Subscription & Loading
|
879
|
-
*/
|
880
|
-
static load(id, options) {
|
881
|
-
return loadCoValueWithoutMe(this, id, options);
|
882
|
-
}
|
883
|
-
static subscribe(id, ...args) {
|
884
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
885
|
-
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
886
|
-
}
|
887
|
-
/**
|
888
|
-
* Given an already loaded `CoList`, ensure that items are loaded to the specified depth.
|
889
|
-
*
|
890
|
-
* Works like `CoList.load()`, but you don't need to pass the ID or the account to load as again.
|
891
|
-
*
|
892
|
-
* @category Subscription & Loading
|
893
|
-
*/
|
894
|
-
ensureLoaded(options) {
|
895
|
-
return ensureCoValueLoaded(this, options);
|
896
|
-
}
|
897
|
-
subscribe(...args) {
|
898
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
899
|
-
return subscribeToExistingCoValue(this, options, listener);
|
900
|
-
}
|
901
|
-
/** @category Type Helpers */
|
902
|
-
castAs(cl) {
|
903
|
-
return cl.fromRaw(this._raw);
|
904
|
-
}
|
905
|
-
/**
|
906
|
-
* Wait for the `CoList` to be uploaded to the other peers.
|
907
|
-
*
|
908
|
-
* @category Subscription & Loading
|
909
|
-
*/
|
910
|
-
waitForSync(options) {
|
911
|
-
return this._raw.core.waitForSync(options);
|
912
|
-
}
|
913
|
-
};
|
914
|
-
_CoList.prototype._type = "CoList";
|
915
|
-
var CoList = _CoList;
|
916
|
-
function toRawItems(items, itemDescriptor) {
|
917
|
-
const rawItems = itemDescriptor === "json" ? items : "encoded" in itemDescriptor ? items?.map((e) => itemDescriptor.encoded.encode(e)) : isRefEncoded(itemDescriptor) ? items?.map((v) => {
|
918
|
-
if (!v) return null;
|
919
|
-
return v.id;
|
920
|
-
}) : (() => {
|
921
|
-
throw new Error("Invalid element descriptor");
|
922
|
-
})();
|
923
|
-
return rawItems;
|
924
|
-
}
|
925
|
-
var CoListProxyHandler = {
|
926
|
-
get(target, key, receiver) {
|
927
|
-
if (typeof key === "string" && !isNaN(+key)) {
|
928
|
-
const itemDescriptor = target._schema[ItemsSym];
|
929
|
-
const rawValue = target._raw.get(Number(key));
|
930
|
-
if (itemDescriptor === "json") {
|
931
|
-
return rawValue;
|
932
|
-
} else if ("encoded" in itemDescriptor) {
|
933
|
-
return rawValue === void 0 ? void 0 : itemDescriptor.encoded.decode(rawValue);
|
934
|
-
} else if (isRefEncoded(itemDescriptor)) {
|
935
|
-
return rawValue === void 0 || rawValue === null ? void 0 : accessChildByKey(target, rawValue, key);
|
936
|
-
}
|
937
|
-
} else if (key === "length") {
|
938
|
-
return target._raw.entries().length;
|
939
|
-
} else {
|
940
|
-
return Reflect.get(target, key, receiver);
|
941
|
-
}
|
942
|
-
},
|
943
|
-
set(target, key, value, receiver) {
|
944
|
-
if (key === ItemsSym && typeof value === "object" && SchemaInit in value) {
|
945
|
-
target.constructor._schema ||= {};
|
946
|
-
target.constructor._schema[ItemsSym] = value[SchemaInit];
|
947
|
-
return true;
|
948
|
-
}
|
949
|
-
if (typeof key === "string" && !isNaN(+key)) {
|
950
|
-
const itemDescriptor = target._schema[ItemsSym];
|
951
|
-
let rawValue;
|
952
|
-
if (itemDescriptor === "json") {
|
953
|
-
rawValue = value;
|
954
|
-
} else if ("encoded" in itemDescriptor) {
|
955
|
-
rawValue = itemDescriptor.encoded.encode(value);
|
956
|
-
} else if (isRefEncoded(itemDescriptor)) {
|
957
|
-
if (value === void 0) {
|
958
|
-
if (itemDescriptor.optional) {
|
959
|
-
rawValue = null;
|
960
|
-
} else {
|
961
|
-
throw new Error(
|
962
|
-
`Cannot set required reference ${key} to undefined`
|
963
|
-
);
|
964
|
-
}
|
965
|
-
} else if (value?.id) {
|
966
|
-
rawValue = value.id;
|
967
|
-
} else {
|
968
|
-
throw new Error(
|
969
|
-
`Cannot set reference ${key} to a non-CoValue. Got ${value}`
|
970
|
-
);
|
971
|
-
}
|
972
|
-
}
|
973
|
-
target._raw.replace(Number(key), rawValue);
|
974
|
-
return true;
|
975
|
-
} else {
|
976
|
-
return Reflect.set(target, key, value, receiver);
|
977
|
-
}
|
978
|
-
},
|
979
|
-
defineProperty(target, key, descriptor) {
|
980
|
-
if (descriptor.value && key === ItemsSym && typeof descriptor.value === "object" && SchemaInit in descriptor.value) {
|
981
|
-
target.constructor._schema ||= {};
|
982
|
-
target.constructor._schema[ItemsSym] = descriptor.value[SchemaInit];
|
983
|
-
return true;
|
984
|
-
} else {
|
985
|
-
return Reflect.defineProperty(target, key, descriptor);
|
986
|
-
}
|
987
|
-
},
|
988
|
-
has(target, key) {
|
989
|
-
if (typeof key === "string" && !isNaN(+key)) {
|
990
|
-
return Number(key) < target._raw.entries().length;
|
991
|
-
} else {
|
992
|
-
return Reflect.has(target, key);
|
993
|
-
}
|
994
|
-
}
|
995
|
-
};
|
996
|
-
|
997
|
-
// src/coValues/coFeed.ts
|
998
|
-
import { MAX_RECOMMENDED_TX_SIZE, cojsonInternals as cojsonInternals2 } from "cojson";
|
999
|
-
var _CoFeed = class _CoFeed extends CoValueBase {
|
1000
|
-
/**
|
1001
|
-
* Declare a `CoFeed` by subclassing `CoFeed.Of(...)` and passing the item schema using a `co` primitive or a `coField.ref`.
|
1002
|
-
*
|
1003
|
-
* @example
|
1004
|
-
* ```ts
|
1005
|
-
* class ColorFeed extends CoFeed.Of(coField.string) {}
|
1006
|
-
* class AnimalFeed extends CoFeed.Of(coField.ref(Animal)) {}
|
1007
|
-
* ```
|
1008
|
-
*
|
1009
|
-
* @category Declaration
|
1010
|
-
*/
|
1011
|
-
static Of(item) {
|
1012
|
-
var _a, _b;
|
1013
|
-
const cls = class CoFeedOf extends (_b = _CoFeed, _a = coField.items, _b) {
|
1014
|
-
constructor() {
|
1015
|
-
super(...arguments);
|
1016
|
-
this[_a] = item;
|
1017
|
-
}
|
1018
|
-
};
|
1019
|
-
cls._schema ||= {};
|
1020
|
-
cls._schema[ItemsSym] = item[SchemaInit];
|
1021
|
-
return cls;
|
1022
|
-
}
|
1023
|
-
/** @internal */
|
1024
|
-
get _schema() {
|
1025
|
-
return this.constructor._schema;
|
1026
|
-
}
|
1027
|
-
/**
|
1028
|
-
* The current account's view of this `CoFeed`
|
1029
|
-
* @category Content
|
1030
|
-
*/
|
1031
|
-
get byMe() {
|
1032
|
-
if (this._loadedAs._type === "Account") {
|
1033
|
-
return this.perAccount[this._loadedAs.id];
|
1034
|
-
} else {
|
1035
|
-
return void 0;
|
1036
|
-
}
|
1037
|
-
}
|
1038
|
-
/**
|
1039
|
-
* The per-account view of this `CoFeed`
|
1040
|
-
*
|
1041
|
-
* @example
|
1042
|
-
* ```ts
|
1043
|
-
* // Access entries directly by account ID
|
1044
|
-
* const aliceEntries = feed[aliceAccount.id];
|
1045
|
-
* console.log(aliceEntries.value); // Latest value from Alice
|
1046
|
-
*
|
1047
|
-
* // Iterate through all accounts' entries
|
1048
|
-
* for (const [accountId, entries] of Object.entries(feed)) {
|
1049
|
-
* console.log(`Latest entry from ${accountId}:`, entries.value);
|
1050
|
-
*
|
1051
|
-
* // Access all entries from this account
|
1052
|
-
* for (const entry of entries.all) {
|
1053
|
-
* console.log(`Entry made at ${entry.madeAt}:`, entry.value);
|
1054
|
-
* }
|
1055
|
-
* }
|
1056
|
-
* ```
|
1057
|
-
*
|
1058
|
-
* @category Content
|
1059
|
-
*/
|
1060
|
-
get perAccount() {
|
1061
|
-
return new Proxy({}, CoStreamPerAccountProxyHandler(this));
|
1062
|
-
}
|
1063
|
-
/**
|
1064
|
-
* The per-session view of this `CoFeed`
|
1065
|
-
* @category Content
|
1066
|
-
*/
|
1067
|
-
get perSession() {
|
1068
|
-
return new Proxy(
|
1069
|
-
{},
|
1070
|
-
CoStreamPerSessionProxyHandler(this, this)
|
1071
|
-
);
|
1072
|
-
}
|
1073
|
-
/**
|
1074
|
-
* The current session's view of this `CoFeed`
|
1075
|
-
*
|
1076
|
-
* This is a shortcut for `this.perSession` where the session ID is the current session ID.
|
1077
|
-
*
|
1078
|
-
* @category Content
|
1079
|
-
*/
|
1080
|
-
get inCurrentSession() {
|
1081
|
-
if (this._loadedAs._type === "Account") {
|
1082
|
-
return this.perSession[this._loadedAs.sessionID];
|
1083
|
-
} else {
|
1084
|
-
return void 0;
|
1085
|
-
}
|
1086
|
-
}
|
1087
|
-
constructor(options) {
|
1088
|
-
super();
|
1089
|
-
if (options && "fromRaw" in options) {
|
1090
|
-
Object.defineProperties(this, {
|
1091
|
-
id: {
|
1092
|
-
value: options.fromRaw.id,
|
1093
|
-
enumerable: false
|
1094
|
-
},
|
1095
|
-
_raw: { value: options.fromRaw, enumerable: false }
|
1096
|
-
});
|
1097
|
-
}
|
1098
|
-
return this;
|
1099
|
-
}
|
1100
|
-
/**
|
1101
|
-
* Create a new `CoFeed`
|
1102
|
-
* @category Creation
|
1103
|
-
*/
|
1104
|
-
static create(init, options) {
|
1105
|
-
const { owner } = parseCoValueCreateOptions(options);
|
1106
|
-
const instance = new this({ init, owner });
|
1107
|
-
const raw = owner._raw.createStream();
|
1108
|
-
Object.defineProperties(instance, {
|
1109
|
-
id: {
|
1110
|
-
value: raw.id,
|
1111
|
-
enumerable: false
|
1112
|
-
},
|
1113
|
-
_raw: { value: raw, enumerable: false }
|
1114
|
-
});
|
1115
|
-
if (init) {
|
1116
|
-
instance.push(...init);
|
1117
|
-
}
|
1118
|
-
return instance;
|
1119
|
-
}
|
1120
|
-
getItemsDescriptor() {
|
1121
|
-
return this._schema?.[ItemsSym];
|
1122
|
-
}
|
1123
|
-
/**
|
1124
|
-
* Push items to this `CoFeed`
|
1125
|
-
*
|
1126
|
-
* Items are appended to the current session's log. Each session (tab, device, app instance)
|
1127
|
-
* maintains its own append-only log, which is then aggregated into the per-account view.
|
1128
|
-
*
|
1129
|
-
* @example
|
1130
|
-
* ```ts
|
1131
|
-
* // Adds items to current session's log
|
1132
|
-
* feed.push("item1", "item2");
|
1133
|
-
*
|
1134
|
-
* // View items from current session
|
1135
|
-
* console.log(feed.inCurrentSession);
|
1136
|
-
*
|
1137
|
-
* // View aggregated items from all sessions for current account
|
1138
|
-
* console.log(feed.byMe);
|
1139
|
-
* ```
|
1140
|
-
*
|
1141
|
-
* @category Content
|
1142
|
-
*/
|
1143
|
-
push(...items) {
|
1144
|
-
for (const item of items) {
|
1145
|
-
this.pushItem(item);
|
1146
|
-
}
|
1147
|
-
}
|
1148
|
-
pushItem(item) {
|
1149
|
-
const itemDescriptor = this._schema[ItemsSym];
|
1150
|
-
if (itemDescriptor === "json") {
|
1151
|
-
this._raw.push(item);
|
1152
|
-
} else if ("encoded" in itemDescriptor) {
|
1153
|
-
this._raw.push(itemDescriptor.encoded.encode(item));
|
1154
|
-
} else if (isRefEncoded(itemDescriptor)) {
|
1155
|
-
this._raw.push(item.id);
|
1156
|
-
}
|
1157
|
-
}
|
1158
|
-
/**
|
1159
|
-
* Get a JSON representation of the `CoFeed`
|
1160
|
-
* @category
|
1161
|
-
*/
|
1162
|
-
toJSON() {
|
1163
|
-
const itemDescriptor = this._schema[ItemsSym];
|
1164
|
-
const mapper = itemDescriptor === "json" ? (v) => v : "encoded" in itemDescriptor ? itemDescriptor.encoded.encode : (v) => v && v.id;
|
1165
|
-
return {
|
1166
|
-
id: this.id,
|
1167
|
-
_type: this._type,
|
1168
|
-
...Object.fromEntries(
|
1169
|
-
Object.entries(this).map(([account, entry]) => [
|
1170
|
-
account,
|
1171
|
-
mapper(entry.value)
|
1172
|
-
])
|
1173
|
-
),
|
1174
|
-
in: Object.fromEntries(
|
1175
|
-
Object.entries(this.perSession).map(([session, entry]) => [
|
1176
|
-
session,
|
1177
|
-
mapper(entry.value)
|
1178
|
-
])
|
1179
|
-
)
|
1180
|
-
};
|
1181
|
-
}
|
1182
|
-
/** @internal */
|
1183
|
-
[(ItemsSym, inspect)]() {
|
1184
|
-
return this.toJSON();
|
1185
|
-
}
|
1186
|
-
/** @internal */
|
1187
|
-
static schema(def) {
|
1188
|
-
this._schema ||= {};
|
1189
|
-
Object.assign(this._schema, def);
|
1190
|
-
}
|
1191
|
-
/**
|
1192
|
-
* Load a `CoFeed`
|
1193
|
-
* @category Subscription & Loading
|
1194
|
-
*/
|
1195
|
-
static load(id, options) {
|
1196
|
-
return loadCoValueWithoutMe(this, id, options);
|
1197
|
-
}
|
1198
|
-
static subscribe(id, ...args) {
|
1199
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
1200
|
-
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
1201
|
-
}
|
1202
|
-
/**
|
1203
|
-
* Ensure a `CoFeed` is loaded to the specified depth
|
1204
|
-
*
|
1205
|
-
* @returns A new instance of the same CoFeed that's loaded to the specified depth
|
1206
|
-
* @category Subscription & Loading
|
1207
|
-
*/
|
1208
|
-
ensureLoaded(options) {
|
1209
|
-
return ensureCoValueLoaded(this, options);
|
1210
|
-
}
|
1211
|
-
subscribe(...args) {
|
1212
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
1213
|
-
return subscribeToExistingCoValue(this, options, listener);
|
1214
|
-
}
|
1215
|
-
/**
|
1216
|
-
* Wait for the `CoFeed` to be uploaded to the other peers.
|
1217
|
-
*
|
1218
|
-
* @category Subscription & Loading
|
1219
|
-
*/
|
1220
|
-
waitForSync(options) {
|
1221
|
-
return this._raw.core.waitForSync(options);
|
1222
|
-
}
|
1223
|
-
};
|
1224
|
-
_CoFeed.prototype._type = "CoStream";
|
1225
|
-
var CoFeed = _CoFeed;
|
1226
|
-
function entryFromRawEntry(accessFrom, rawEntry, loadedAs, accountID, itemField) {
|
1227
|
-
return {
|
1228
|
-
get value() {
|
1229
|
-
if (itemField === "json") {
|
1230
|
-
return rawEntry.value;
|
1231
|
-
} else if ("encoded" in itemField) {
|
1232
|
-
return itemField.encoded.decode(rawEntry.value);
|
1233
|
-
} else if (isRefEncoded(itemField)) {
|
1234
|
-
return accessChildById(
|
1235
|
-
accessFrom,
|
1236
|
-
rawEntry.value,
|
1237
|
-
itemField
|
1238
|
-
);
|
1239
|
-
} else {
|
1240
|
-
throw new Error("Invalid item field schema");
|
1241
|
-
}
|
1242
|
-
},
|
1243
|
-
get ref() {
|
1244
|
-
if (itemField !== "json" && isRefEncoded(itemField)) {
|
1245
|
-
const rawId = rawEntry.value;
|
1246
|
-
return new Ref(
|
1247
|
-
rawId,
|
1248
|
-
loadedAs,
|
1249
|
-
itemField,
|
1250
|
-
accessFrom
|
1251
|
-
);
|
1252
|
-
} else {
|
1253
|
-
return void 0;
|
1254
|
-
}
|
1255
|
-
},
|
1256
|
-
get by() {
|
1257
|
-
return accountID && accessChildById(accessFrom, accountID, {
|
1258
|
-
ref: Account,
|
1259
|
-
optional: false
|
1260
|
-
});
|
1261
|
-
},
|
1262
|
-
madeAt: rawEntry.at,
|
1263
|
-
tx: rawEntry.tx
|
1264
|
-
};
|
1265
|
-
}
|
1266
|
-
var CoStreamPerAccountProxyHandler = (innerTarget) => ({
|
1267
|
-
get(_target, key, receiver) {
|
1268
|
-
if (typeof key === "string" && key.startsWith("co_")) {
|
1269
|
-
const rawEntry = innerTarget._raw.lastItemBy(key);
|
1270
|
-
if (!rawEntry) return;
|
1271
|
-
const entry = entryFromRawEntry(
|
1272
|
-
receiver,
|
1273
|
-
rawEntry,
|
1274
|
-
innerTarget._loadedAs,
|
1275
|
-
key,
|
1276
|
-
innerTarget._schema[ItemsSym]
|
1277
|
-
);
|
1278
|
-
Object.defineProperty(entry, "all", {
|
1279
|
-
get: () => {
|
1280
|
-
const allRawEntries = innerTarget._raw.itemsBy(key);
|
1281
|
-
return function* () {
|
1282
|
-
while (true) {
|
1283
|
-
const rawEntry2 = allRawEntries.next();
|
1284
|
-
if (rawEntry2.done) return;
|
1285
|
-
yield entryFromRawEntry(
|
1286
|
-
receiver,
|
1287
|
-
rawEntry2.value,
|
1288
|
-
innerTarget._loadedAs,
|
1289
|
-
key,
|
1290
|
-
innerTarget._schema[ItemsSym]
|
1291
|
-
);
|
1292
|
-
}
|
1293
|
-
}();
|
1294
|
-
}
|
1295
|
-
});
|
1296
|
-
return entry;
|
1297
|
-
} else {
|
1298
|
-
return Reflect.get(innerTarget, key, receiver);
|
1299
|
-
}
|
1300
|
-
},
|
1301
|
-
ownKeys(_target) {
|
1302
|
-
return Array.from(innerTarget._raw.accounts());
|
1303
|
-
},
|
1304
|
-
getOwnPropertyDescriptor(_target, key) {
|
1305
|
-
if (typeof key === "string" && key.startsWith("co_")) {
|
1306
|
-
return {
|
1307
|
-
configurable: true,
|
1308
|
-
enumerable: true,
|
1309
|
-
writable: false
|
1310
|
-
};
|
1311
|
-
} else {
|
1312
|
-
return Reflect.getOwnPropertyDescriptor(innerTarget, key);
|
1313
|
-
}
|
1314
|
-
}
|
1315
|
-
});
|
1316
|
-
var CoStreamPerSessionProxyHandler = (innerTarget, accessFrom) => ({
|
1317
|
-
get(_target, key, receiver) {
|
1318
|
-
if (typeof key === "string" && key.includes("session")) {
|
1319
|
-
const sessionID = key;
|
1320
|
-
const rawEntry = innerTarget._raw.lastItemIn(sessionID);
|
1321
|
-
if (!rawEntry) return;
|
1322
|
-
const by = cojsonInternals2.accountOrAgentIDfromSessionID(sessionID);
|
1323
|
-
const entry = entryFromRawEntry(
|
1324
|
-
accessFrom,
|
1325
|
-
rawEntry,
|
1326
|
-
innerTarget._loadedAs,
|
1327
|
-
cojsonInternals2.isAccountID(by) ? by : void 0,
|
1328
|
-
innerTarget._schema[ItemsSym]
|
1329
|
-
);
|
1330
|
-
Object.defineProperty(entry, "all", {
|
1331
|
-
get: () => {
|
1332
|
-
const allRawEntries = innerTarget._raw.itemsIn(sessionID);
|
1333
|
-
return function* () {
|
1334
|
-
while (true) {
|
1335
|
-
const rawEntry2 = allRawEntries.next();
|
1336
|
-
if (rawEntry2.done) return;
|
1337
|
-
yield entryFromRawEntry(
|
1338
|
-
accessFrom,
|
1339
|
-
rawEntry2.value,
|
1340
|
-
innerTarget._loadedAs,
|
1341
|
-
cojsonInternals2.isAccountID(by) ? by : void 0,
|
1342
|
-
innerTarget._schema[ItemsSym]
|
1343
|
-
);
|
1344
|
-
}
|
1345
|
-
}();
|
1346
|
-
}
|
1347
|
-
});
|
1348
|
-
return entry;
|
1349
|
-
} else {
|
1350
|
-
return Reflect.get(innerTarget, key, receiver);
|
1351
|
-
}
|
1352
|
-
},
|
1353
|
-
ownKeys() {
|
1354
|
-
return innerTarget._raw.sessions();
|
1355
|
-
},
|
1356
|
-
getOwnPropertyDescriptor(target, key) {
|
1357
|
-
if (typeof key === "string" && key.startsWith("co_")) {
|
1358
|
-
return {
|
1359
|
-
configurable: true,
|
1360
|
-
enumerable: true,
|
1361
|
-
writable: false
|
1362
|
-
};
|
1363
|
-
} else {
|
1364
|
-
return Reflect.getOwnPropertyDescriptor(target, key);
|
1365
|
-
}
|
1366
|
-
}
|
1367
|
-
});
|
1368
|
-
var FileStream = class extends CoValueBase {
|
1369
|
-
constructor(options) {
|
1370
|
-
super();
|
1371
|
-
let raw;
|
1372
|
-
if ("fromRaw" in options) {
|
1373
|
-
raw = options.fromRaw;
|
1374
|
-
} else {
|
1375
|
-
const rawOwner = options.owner._raw;
|
1376
|
-
raw = rawOwner.createBinaryStream();
|
1377
|
-
}
|
1378
|
-
Object.defineProperties(this, {
|
1379
|
-
id: {
|
1380
|
-
value: raw.id,
|
1381
|
-
enumerable: false
|
1382
|
-
},
|
1383
|
-
_type: { value: "BinaryCoStream", enumerable: false },
|
1384
|
-
_raw: { value: raw, enumerable: false }
|
1385
|
-
});
|
1386
|
-
}
|
1387
|
-
/**
|
1388
|
-
* Create a new empty `FileStream` instance.
|
1389
|
-
*
|
1390
|
-
* @param options - Configuration options for the new FileStream
|
1391
|
-
* @param options.owner - The Account or Group that will own this FileStream and control access rights
|
1392
|
-
*
|
1393
|
-
* @example
|
1394
|
-
* ```typescript
|
1395
|
-
* // Create owned by an account
|
1396
|
-
* const stream = FileStream.create({ owner: myAccount });
|
1397
|
-
*
|
1398
|
-
* // Create owned by a group
|
1399
|
-
* const stream = FileStream.create({ owner: teamGroup });
|
1400
|
-
*
|
1401
|
-
* // Create with implicit owner
|
1402
|
-
* const stream = FileStream.create(myAccount);
|
1403
|
-
* ```
|
1404
|
-
*
|
1405
|
-
* @remarks
|
1406
|
-
* For uploading an existing file or blob, use {@link FileStream.createFromBlob} instead.
|
1407
|
-
*
|
1408
|
-
* @category Creation
|
1409
|
-
*/
|
1410
|
-
static create(options) {
|
1411
|
-
return new this(parseCoValueCreateOptions(options));
|
1412
|
-
}
|
1413
|
-
getMetadata() {
|
1414
|
-
return this._raw.getBinaryStreamInfo();
|
1415
|
-
}
|
1416
|
-
getChunks(options) {
|
1417
|
-
return this._raw.getBinaryChunks(options?.allowUnfinished);
|
1418
|
-
}
|
1419
|
-
isBinaryStreamEnded() {
|
1420
|
-
return this._raw.isBinaryStreamEnded();
|
1421
|
-
}
|
1422
|
-
start(options) {
|
1423
|
-
this._raw.startBinaryStream(options);
|
1424
|
-
}
|
1425
|
-
push(data) {
|
1426
|
-
this._raw.pushBinaryStreamChunk(data);
|
1427
|
-
}
|
1428
|
-
end() {
|
1429
|
-
this._raw.endBinaryStream();
|
1430
|
-
}
|
1431
|
-
toBlob(options) {
|
1432
|
-
const chunks = this.getChunks({
|
1433
|
-
allowUnfinished: options?.allowUnfinished
|
1434
|
-
});
|
1435
|
-
if (!chunks) {
|
1436
|
-
return void 0;
|
1437
|
-
}
|
1438
|
-
return new Blob(chunks.chunks, { type: chunks.mimeType });
|
1439
|
-
}
|
1440
|
-
/**
|
1441
|
-
* Load a `FileStream` as a `Blob`
|
1442
|
-
*
|
1443
|
-
* @category Content
|
1444
|
-
*/
|
1445
|
-
static async loadAsBlob(id, options) {
|
1446
|
-
let stream = await this.load(id, options);
|
1447
|
-
if (!options?.allowUnfinished && !stream?.isBinaryStreamEnded()) {
|
1448
|
-
stream = await new Promise((resolve) => {
|
1449
|
-
subscribeToCoValueWithoutMe(
|
1450
|
-
this,
|
1451
|
-
id,
|
1452
|
-
options || {},
|
1453
|
-
(value, unsubscribe) => {
|
1454
|
-
if (value.isBinaryStreamEnded()) {
|
1455
|
-
unsubscribe();
|
1456
|
-
resolve(value);
|
1457
|
-
}
|
1458
|
-
}
|
1459
|
-
);
|
1460
|
-
});
|
1461
|
-
}
|
1462
|
-
return stream?.toBlob({
|
1463
|
-
allowUnfinished: options?.allowUnfinished
|
1464
|
-
});
|
1465
|
-
}
|
1466
|
-
/**
|
1467
|
-
* Create a `FileStream` from a `Blob` or `File`
|
1468
|
-
*
|
1469
|
-
* @example
|
1470
|
-
* ```ts
|
1471
|
-
* import { coField, FileStream } from "jazz-tools";
|
1472
|
-
*
|
1473
|
-
* const fileStream = await FileStream.createFromBlob(file, {owner: group})
|
1474
|
-
* ```
|
1475
|
-
* @category Content
|
1476
|
-
*/
|
1477
|
-
static async createFromBlob(blob, options) {
|
1478
|
-
const stream = this.create(options);
|
1479
|
-
const onProgress = options && "onProgress" in options ? options.onProgress : void 0;
|
1480
|
-
const start = Date.now();
|
1481
|
-
const data = new Uint8Array(await blob.arrayBuffer());
|
1482
|
-
stream.start({
|
1483
|
-
mimeType: blob.type,
|
1484
|
-
totalSizeBytes: blob.size,
|
1485
|
-
fileName: blob instanceof File ? blob.name : void 0
|
1486
|
-
});
|
1487
|
-
const chunkSize = MAX_RECOMMENDED_TX_SIZE;
|
1488
|
-
let lastProgressUpdate = Date.now();
|
1489
|
-
for (let idx = 0; idx < data.length; idx += chunkSize) {
|
1490
|
-
stream.push(data.slice(idx, idx + chunkSize));
|
1491
|
-
if (Date.now() - lastProgressUpdate > 100) {
|
1492
|
-
onProgress?.(idx / data.length);
|
1493
|
-
lastProgressUpdate = Date.now();
|
1494
|
-
}
|
1495
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
1496
|
-
}
|
1497
|
-
stream.end();
|
1498
|
-
const end = Date.now();
|
1499
|
-
console.debug(
|
1500
|
-
"Finished creating binary stream in",
|
1501
|
-
(end - start) / 1e3,
|
1502
|
-
"s - Throughput in MB/s",
|
1503
|
-
1e3 * (blob.size / (end - start)) / (1024 * 1024)
|
1504
|
-
);
|
1505
|
-
onProgress?.(1);
|
1506
|
-
return stream;
|
1507
|
-
}
|
1508
|
-
/**
|
1509
|
-
* Get a JSON representation of the `FileStream`
|
1510
|
-
* @category Content
|
1511
|
-
*/
|
1512
|
-
toJSON() {
|
1513
|
-
return {
|
1514
|
-
id: this.id,
|
1515
|
-
_type: this._type,
|
1516
|
-
...this.getChunks()
|
1517
|
-
};
|
1518
|
-
}
|
1519
|
-
/** @internal */
|
1520
|
-
[inspect]() {
|
1521
|
-
return this.toJSON();
|
1522
|
-
}
|
1523
|
-
/**
|
1524
|
-
* Load a `FileStream`
|
1525
|
-
* @category Subscription & Loading
|
1526
|
-
*/
|
1527
|
-
static load(id, options) {
|
1528
|
-
return loadCoValueWithoutMe(this, id, options);
|
1529
|
-
}
|
1530
|
-
static subscribe(id, ...args) {
|
1531
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
1532
|
-
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
1533
|
-
}
|
1534
|
-
/**
|
1535
|
-
* An instance method to subscribe to an existing `FileStream`
|
1536
|
-
* @category Subscription & Loading
|
1537
|
-
*/
|
1538
|
-
subscribe(listener) {
|
1539
|
-
return subscribeToExistingCoValue(this, {}, listener);
|
1540
|
-
}
|
1541
|
-
/**
|
1542
|
-
* Wait for the `FileStream` to be uploaded to the other peers.
|
1543
|
-
*
|
1544
|
-
* @category Subscription & Loading
|
1545
|
-
*/
|
1546
|
-
waitForSync(options) {
|
1547
|
-
return this._raw.core.waitForSync(options);
|
1548
|
-
}
|
1549
|
-
};
|
1550
|
-
|
1551
|
-
// src/coValues/account.ts
|
1552
|
-
import {
|
1553
|
-
ControlledAccount as ControlledAccount3,
|
1554
|
-
LocalNode,
|
1555
|
-
cojsonInternals as cojsonInternals3
|
1556
|
-
} from "cojson";
|
1557
|
-
var _Account = class _Account extends CoValueBase {
|
1558
|
-
get _schema() {
|
1559
|
-
return this.constructor._schema;
|
1560
|
-
}
|
1561
|
-
get _owner() {
|
1562
|
-
return this;
|
1563
|
-
}
|
1564
|
-
get _loadedAs() {
|
1565
|
-
if (this.isLocalNodeOwner) return this;
|
1566
|
-
const agent = this._raw.core.node.getCurrentAgent();
|
1567
|
-
if (agent instanceof ControlledAccount3) {
|
1568
|
-
return coValuesCache.get(
|
1569
|
-
agent.account,
|
1570
|
-
() => _Account.fromRaw(agent.account)
|
1571
|
-
);
|
1572
|
-
}
|
1573
|
-
return new AnonymousJazzAgent(this._raw.core.node);
|
1574
|
-
}
|
1575
|
-
getDescriptor(key) {
|
1576
|
-
if (key === "profile") {
|
1577
|
-
return this._schema.profile;
|
1578
|
-
} else if (key === "root") {
|
1579
|
-
return this._schema.root;
|
1580
|
-
}
|
1581
|
-
return void 0;
|
1582
|
-
}
|
1583
|
-
get _refs() {
|
1584
|
-
const profileID = this._raw.get("profile");
|
1585
|
-
const rootID = this._raw.get("root");
|
1586
|
-
return {
|
1587
|
-
profile: profileID ? new Ref(
|
1588
|
-
profileID,
|
1589
|
-
this._loadedAs,
|
1590
|
-
this._schema.profile,
|
1591
|
-
this
|
1592
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1593
|
-
) : void 0,
|
1594
|
-
root: rootID ? new Ref(
|
1595
|
-
rootID,
|
1596
|
-
this._loadedAs,
|
1597
|
-
this._schema.root,
|
1598
|
-
this
|
1599
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1600
|
-
) : void 0
|
1601
|
-
};
|
1602
|
-
}
|
1603
|
-
/**
|
1604
|
-
* Whether this account is the currently active account.
|
1605
|
-
*/
|
1606
|
-
get isMe() {
|
1607
|
-
return activeAccountContext.get().id === this.id;
|
1608
|
-
}
|
1609
|
-
constructor(options) {
|
1610
|
-
super();
|
1611
|
-
if (!("fromRaw" in options)) {
|
1612
|
-
throw new Error("Can only construct account from raw or with .create()");
|
1613
|
-
}
|
1614
|
-
this.isLocalNodeOwner = options.fromRaw.id == options.fromRaw.core.node.getCurrentAgent().id;
|
1615
|
-
Object.defineProperties(this, {
|
1616
|
-
id: {
|
1617
|
-
value: options.fromRaw.id,
|
1618
|
-
enumerable: false
|
1619
|
-
},
|
1620
|
-
_raw: { value: options.fromRaw, enumerable: false },
|
1621
|
-
_type: { value: "Account", enumerable: false }
|
1622
|
-
});
|
1623
|
-
if (this.isLocalNodeOwner) {
|
1624
|
-
this.sessionID = options.fromRaw.core.node.currentSessionID;
|
1625
|
-
}
|
1626
|
-
return new Proxy(this, AccountAndGroupProxyHandler);
|
1627
|
-
}
|
1628
|
-
myRole() {
|
1629
|
-
if (this.isLocalNodeOwner) {
|
1630
|
-
return "admin";
|
1631
|
-
}
|
1632
|
-
}
|
1633
|
-
getRoleOf(member) {
|
1634
|
-
if (member === "me") {
|
1635
|
-
return this.isMe ? "admin" : void 0;
|
1636
|
-
}
|
1637
|
-
if (member === this.id) {
|
1638
|
-
return "admin";
|
1639
|
-
}
|
1640
|
-
return void 0;
|
1641
|
-
}
|
1642
|
-
getParentGroups() {
|
1643
|
-
return [];
|
1644
|
-
}
|
1645
|
-
get members() {
|
1646
|
-
const ref2 = new Ref(
|
1647
|
-
this.id,
|
1648
|
-
this._loadedAs,
|
1649
|
-
{
|
1650
|
-
ref: () => this.constructor,
|
1651
|
-
optional: false
|
1652
|
-
},
|
1653
|
-
this
|
1654
|
-
);
|
1655
|
-
return [{ id: this.id, role: "admin", ref: ref2, account: this }];
|
1656
|
-
}
|
1657
|
-
canRead(value) {
|
1658
|
-
const role = value._owner.getRoleOf(this.id);
|
1659
|
-
return role === "admin" || role === "writer" || role === "reader" || role === "writeOnly";
|
1660
|
-
}
|
1661
|
-
canWrite(value) {
|
1662
|
-
const role = value._owner.getRoleOf(this.id);
|
1663
|
-
return role === "admin" || role === "writer" || role === "writeOnly";
|
1664
|
-
}
|
1665
|
-
canAdmin(value) {
|
1666
|
-
return value._owner.getRoleOf(this.id) === "admin";
|
1667
|
-
}
|
1668
|
-
async acceptInvite(valueID, inviteSecret, coValueClass) {
|
1669
|
-
if (!this.isLocalNodeOwner) {
|
1670
|
-
throw new Error("Only a controlled account can accept invites");
|
1671
|
-
}
|
1672
|
-
await this._raw.core.node.acceptInvite(
|
1673
|
-
valueID,
|
1674
|
-
inviteSecret
|
1675
|
-
);
|
1676
|
-
return loadCoValue(anySchemaToCoSchema(coValueClass), valueID, {
|
1677
|
-
loadAs: this
|
1678
|
-
});
|
1679
|
-
}
|
1680
|
-
/** @private */
|
1681
|
-
static async create(options) {
|
1682
|
-
const { node } = await LocalNode.withNewlyCreatedAccount({
|
1683
|
-
...options,
|
1684
|
-
migration: async (rawAccount, _node, creationProps) => {
|
1685
|
-
const account = new this({
|
1686
|
-
fromRaw: rawAccount
|
1687
|
-
});
|
1688
|
-
await account.applyMigration?.(creationProps);
|
1689
|
-
}
|
1690
|
-
});
|
1691
|
-
return this.fromNode(node);
|
1692
|
-
}
|
1693
|
-
static getMe() {
|
1694
|
-
return activeAccountContext.get();
|
1695
|
-
}
|
1696
|
-
static async createAs(as, options) {
|
1697
|
-
const connectedPeers = cojsonInternals3.connectedPeers(
|
1698
|
-
"creatingAccount",
|
1699
|
-
"createdAccount",
|
1700
|
-
{ peer1role: "server", peer2role: "client" }
|
1701
|
-
);
|
1702
|
-
as._raw.core.node.syncManager.addPeer(connectedPeers[1]);
|
1703
|
-
const account = await this.create({
|
1704
|
-
creationProps: options.creationProps,
|
1705
|
-
crypto: as._raw.core.node.crypto,
|
1706
|
-
peersToLoadFrom: [connectedPeers[0]]
|
1707
|
-
});
|
1708
|
-
await account.waitForAllCoValuesSync();
|
1709
|
-
return account;
|
1710
|
-
}
|
1711
|
-
static fromNode(node) {
|
1712
|
-
return new this({
|
1713
|
-
fromRaw: node.expectCurrentAccount("jazz-tools/Account.fromNode")
|
1714
|
-
});
|
1715
|
-
}
|
1716
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1717
|
-
toJSON() {
|
1718
|
-
return {
|
1719
|
-
id: this.id,
|
1720
|
-
_type: this._type
|
1721
|
-
};
|
1722
|
-
}
|
1723
|
-
[inspect]() {
|
1724
|
-
return this.toJSON();
|
1725
|
-
}
|
1726
|
-
async applyMigration(creationProps) {
|
1727
|
-
await this.migrate(creationProps);
|
1728
|
-
if (this.profile === void 0 && creationProps) {
|
1729
|
-
const profileGroup = RegisteredSchemas["Group"].create({ owner: this });
|
1730
|
-
this.profile = Profile.create({ name: creationProps.name }, profileGroup);
|
1731
|
-
profileGroup.addMember("everyone", "reader");
|
1732
|
-
} else if (this.profile && creationProps) {
|
1733
|
-
if (this.profile._owner._type !== "Group") {
|
1734
|
-
throw new Error("Profile must be owned by a Group", {
|
1735
|
-
cause: `The profile of the account "${this.id}" was created with an Account as owner, which is not allowed.`
|
1736
|
-
});
|
1737
|
-
}
|
1738
|
-
}
|
1739
|
-
const node = this._raw.core.node;
|
1740
|
-
const profile = node.expectCoValueLoaded(this._raw.get("profile")).getCurrentContent();
|
1741
|
-
if (!profile.get("inbox")) {
|
1742
|
-
const inboxRoot = createInboxRoot(this);
|
1743
|
-
profile.set("inbox", inboxRoot.id);
|
1744
|
-
profile.set("inboxInvite", inboxRoot.inviteLink);
|
1745
|
-
}
|
1746
|
-
}
|
1747
|
-
// Placeholder method for subclasses to override
|
1748
|
-
migrate(creationProps) {
|
1749
|
-
creationProps;
|
1750
|
-
}
|
1751
|
-
/** @category Subscription & Loading */
|
1752
|
-
static load(id, options) {
|
1753
|
-
return loadCoValueWithoutMe(this, id, options);
|
1754
|
-
}
|
1755
|
-
static subscribe(id, ...args) {
|
1756
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
1757
|
-
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
1758
|
-
}
|
1759
|
-
/** @category Subscription & Loading */
|
1760
|
-
ensureLoaded(options) {
|
1761
|
-
return ensureCoValueLoaded(this, options);
|
1762
|
-
}
|
1763
|
-
subscribe(...args) {
|
1764
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
1765
|
-
return subscribeToExistingCoValue(this, options, listener);
|
1766
|
-
}
|
1767
|
-
/**
|
1768
|
-
* Wait for the `Account` to be uploaded to the other peers.
|
1769
|
-
*
|
1770
|
-
* @category Subscription & Loading
|
1771
|
-
*/
|
1772
|
-
waitForSync(options) {
|
1773
|
-
return this._raw.core.waitForSync(options);
|
1774
|
-
}
|
1775
|
-
/**
|
1776
|
-
* Wait for all the available `CoValues` to be uploaded to the other peers.
|
1777
|
-
*
|
1778
|
-
* @category Subscription & Loading
|
1779
|
-
*/
|
1780
|
-
waitForAllCoValuesSync(options) {
|
1781
|
-
return this._raw.core.node.syncManager.waitForAllCoValuesSync(
|
1782
|
-
options?.timeout
|
1783
|
-
);
|
1784
|
-
}
|
1785
|
-
};
|
1786
|
-
_Account._schema = {
|
1787
|
-
profile: {
|
1788
|
-
ref: () => Profile,
|
1789
|
-
optional: false
|
1790
|
-
},
|
1791
|
-
root: {
|
1792
|
-
ref: () => RegisteredSchemas["CoMap"],
|
1793
|
-
optional: true
|
1794
|
-
}
|
1795
|
-
};
|
1796
|
-
var Account = _Account;
|
1797
|
-
var AccountAndGroupProxyHandler = {
|
1798
|
-
get(target, key, receiver) {
|
1799
|
-
if (key === "profile" || key === "root") {
|
1800
|
-
const id = target._raw.get(key);
|
1801
|
-
if (id) {
|
1802
|
-
return accessChildByKey(target, id, key);
|
1803
|
-
} else {
|
1804
|
-
return void 0;
|
1805
|
-
}
|
1806
|
-
} else {
|
1807
|
-
return Reflect.get(target, key, receiver);
|
1808
|
-
}
|
1809
|
-
},
|
1810
|
-
set(target, key, value, receiver) {
|
1811
|
-
if ((key === "profile" || key === "root") && typeof value === "object" && SchemaInit in value) {
|
1812
|
-
target.constructor._schema ||= {};
|
1813
|
-
target.constructor._schema[key] = value[SchemaInit];
|
1814
|
-
return true;
|
1815
|
-
} else if (key === "profile") {
|
1816
|
-
if (value) {
|
1817
|
-
target._raw.set(
|
1818
|
-
"profile",
|
1819
|
-
value.id,
|
1820
|
-
"trusting"
|
1821
|
-
);
|
1822
|
-
}
|
1823
|
-
return true;
|
1824
|
-
} else if (key === "root") {
|
1825
|
-
if (value) {
|
1826
|
-
target._raw.set("root", value.id);
|
1827
|
-
}
|
1828
|
-
return true;
|
1829
|
-
} else {
|
1830
|
-
return Reflect.set(target, key, value, receiver);
|
1831
|
-
}
|
1832
|
-
},
|
1833
|
-
defineProperty(target, key, descriptor) {
|
1834
|
-
if ((key === "profile" || key === "root") && typeof descriptor.value === "object" && SchemaInit in descriptor.value) {
|
1835
|
-
target.constructor._schema ||= {};
|
1836
|
-
target.constructor._schema[key] = descriptor.value[SchemaInit];
|
1837
|
-
return true;
|
1838
|
-
} else {
|
1839
|
-
return Reflect.defineProperty(target, key, descriptor);
|
1840
|
-
}
|
1841
|
-
}
|
1842
|
-
};
|
1843
|
-
function isControlledAccount(account) {
|
1844
|
-
return account.isLocalNodeOwner;
|
1845
|
-
}
|
1846
|
-
RegisteredSchemas["Account"] = Account;
|
1847
|
-
|
1848
|
-
// src/coValues/group.ts
|
1849
|
-
var _Group = class _Group extends CoValueBase {
|
1850
|
-
get _schema() {
|
1851
|
-
return this.constructor._schema;
|
1852
|
-
}
|
1853
|
-
get _refs() {
|
1854
|
-
const profileID = this._raw.get("profile");
|
1855
|
-
const rootID = this._raw.get("root");
|
1856
|
-
return {
|
1857
|
-
profile: profileID ? new Ref(
|
1858
|
-
profileID,
|
1859
|
-
this._loadedAs,
|
1860
|
-
this._schema.profile,
|
1861
|
-
this
|
1862
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1863
|
-
) : void 0,
|
1864
|
-
root: rootID ? new Ref(
|
1865
|
-
rootID,
|
1866
|
-
this._loadedAs,
|
1867
|
-
this._schema.root,
|
1868
|
-
this
|
1869
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1870
|
-
) : void 0
|
1871
|
-
};
|
1872
|
-
}
|
1873
|
-
/** @deprecated Don't use constructor directly, use .create */
|
1874
|
-
constructor(options) {
|
1875
|
-
super();
|
1876
|
-
let raw;
|
1877
|
-
if (options && "fromRaw" in options) {
|
1878
|
-
raw = options.fromRaw;
|
1879
|
-
} else {
|
1880
|
-
const initOwner = options.owner;
|
1881
|
-
if (!initOwner) throw new Error("No owner provided");
|
1882
|
-
if (initOwner._type === "Account" && isControlledAccount(initOwner)) {
|
1883
|
-
const rawOwner = initOwner._raw;
|
1884
|
-
raw = rawOwner.core.node.createGroup();
|
1885
|
-
} else {
|
1886
|
-
throw new Error("Can only construct group as a controlled account");
|
1887
|
-
}
|
1888
|
-
}
|
1889
|
-
Object.defineProperties(this, {
|
1890
|
-
id: {
|
1891
|
-
value: raw.id,
|
1892
|
-
enumerable: false
|
1893
|
-
},
|
1894
|
-
_raw: { value: raw, enumerable: false }
|
1895
|
-
});
|
1896
|
-
return new Proxy(this, AccountAndGroupProxyHandler);
|
1897
|
-
}
|
1898
|
-
static create(options) {
|
1899
|
-
return new this(parseGroupCreateOptions(options));
|
1900
|
-
}
|
1901
|
-
myRole() {
|
1902
|
-
return this._raw.myRole();
|
1903
|
-
}
|
1904
|
-
addMember(member, role) {
|
1905
|
-
if (member !== "everyone" && member._type === "Group") {
|
1906
|
-
if (role === "writeOnly")
|
1907
|
-
throw new Error("Cannot add group as member with write-only role");
|
1908
|
-
this._raw.extend(member._raw, role);
|
1909
|
-
} else if (role !== void 0 && role !== "inherit") {
|
1910
|
-
this._raw.addMember(member === "everyone" ? member : member._raw, role);
|
1911
|
-
}
|
1912
|
-
}
|
1913
|
-
removeMember(member) {
|
1914
|
-
if (member !== "everyone" && member._type === "Group") {
|
1915
|
-
return this._raw.revokeExtend(member._raw);
|
1916
|
-
} else {
|
1917
|
-
return this._raw.removeMember(
|
1918
|
-
member === "everyone" ? member : member._raw
|
1919
|
-
);
|
1920
|
-
}
|
1921
|
-
}
|
1922
|
-
get members() {
|
1923
|
-
const members = [];
|
1924
|
-
const refEncodedAccountSchema = {
|
1925
|
-
ref: () => Account,
|
1926
|
-
optional: false
|
1927
|
-
};
|
1928
|
-
for (const accountID of this._raw.getAllMemberKeysSet()) {
|
1929
|
-
if (!isAccountID(accountID)) continue;
|
1930
|
-
const role = this._raw.roleOf(accountID);
|
1931
|
-
if (role === "admin" || role === "writer" || role === "reader" || role === "writeOnly") {
|
1932
|
-
const ref2 = new Ref(
|
1933
|
-
accountID,
|
1934
|
-
this._loadedAs,
|
1935
|
-
refEncodedAccountSchema,
|
1936
|
-
this
|
1937
|
-
);
|
1938
|
-
const group = this;
|
1939
|
-
members.push({
|
1940
|
-
id: accountID,
|
1941
|
-
role,
|
1942
|
-
ref: ref2,
|
1943
|
-
get account() {
|
1944
|
-
return accessChildById(group, accountID, refEncodedAccountSchema);
|
1945
|
-
}
|
1946
|
-
});
|
1947
|
-
}
|
1948
|
-
}
|
1949
|
-
return members;
|
1950
|
-
}
|
1951
|
-
getRoleOf(member) {
|
1952
|
-
if (member === "me") {
|
1953
|
-
return this._raw.roleOf(
|
1954
|
-
activeAccountContext.get().id
|
1955
|
-
);
|
1956
|
-
}
|
1957
|
-
return this._raw.roleOf(
|
1958
|
-
member === "everyone" ? member : member
|
1959
|
-
);
|
1960
|
-
}
|
1961
|
-
/**
|
1962
|
-
* Make the group public, so that everyone can read it.
|
1963
|
-
* Alias for `addMember("everyone", role)`.
|
1964
|
-
*
|
1965
|
-
* @param role - Optional: the role to grant to everyone. Defaults to "reader".
|
1966
|
-
* @returns The group itself.
|
1967
|
-
*/
|
1968
|
-
makePublic(role = "reader") {
|
1969
|
-
this.addMember("everyone", role);
|
1970
|
-
return this;
|
1971
|
-
}
|
1972
|
-
getParentGroups() {
|
1973
|
-
return this._raw.getParentGroups().map((group) => _Group.fromRaw(group));
|
1974
|
-
}
|
1975
|
-
/** @category Identity & Permissions
|
1976
|
-
* Gives members of a parent group membership in this group.
|
1977
|
-
* @deprecated Use `addMember` instead.
|
1978
|
-
* @param parent The group that will gain access to this group.
|
1979
|
-
* @param roleMapping The role all members of the parent group should have in this group.
|
1980
|
-
* @returns This group.
|
1981
|
-
*/
|
1982
|
-
extend(parent, roleMapping) {
|
1983
|
-
this._raw.extend(parent._raw, roleMapping);
|
1984
|
-
return this;
|
1985
|
-
}
|
1986
|
-
/** @category Identity & Permissions
|
1987
|
-
* Revokes membership from members a parent group.
|
1988
|
-
* @deprecated Use `removeMember` instead.
|
1989
|
-
* @param parent The group that will lose access to this group.
|
1990
|
-
* @returns This group.
|
1991
|
-
*/
|
1992
|
-
async revokeExtend(parent) {
|
1993
|
-
await this._raw.revokeExtend(parent._raw);
|
1994
|
-
return this;
|
1995
|
-
}
|
1996
|
-
/** @category Subscription & Loading */
|
1997
|
-
static load(id, options) {
|
1998
|
-
return loadCoValueWithoutMe(this, id, options);
|
1999
|
-
}
|
2000
|
-
static subscribe(id, ...args) {
|
2001
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
2002
|
-
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
2003
|
-
}
|
2004
|
-
/** @category Subscription & Loading */
|
2005
|
-
ensureLoaded(options) {
|
2006
|
-
return ensureCoValueLoaded(this, options);
|
2007
|
-
}
|
2008
|
-
subscribe(...args) {
|
2009
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
2010
|
-
return subscribeToExistingCoValue(this, options, listener);
|
2011
|
-
}
|
2012
|
-
/**
|
2013
|
-
* Wait for the `Group` to be uploaded to the other peers.
|
2014
|
-
*
|
2015
|
-
* @category Subscription & Loading
|
2016
|
-
*/
|
2017
|
-
waitForSync(options) {
|
2018
|
-
return this._raw.core.waitForSync(options);
|
2019
|
-
}
|
2020
|
-
};
|
2021
|
-
_Group.prototype._type = "Group";
|
2022
|
-
_Group._schema = {
|
2023
|
-
profile: "json",
|
2024
|
-
root: "json"
|
2025
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2026
|
-
};
|
2027
|
-
Object.defineProperty(_Group.prototype, "_schema", {
|
2028
|
-
get: () => _Group._schema
|
2029
|
-
});
|
2030
|
-
var Group = _Group;
|
2031
|
-
RegisteredSchemas["Group"] = Group;
|
2032
|
-
function isAccountID(id) {
|
2033
|
-
return id.startsWith("co_");
|
2034
|
-
}
|
2035
|
-
|
2036
|
-
// src/coValues/profile.ts
|
2037
|
-
var Profile = class extends CoMap {
|
2038
|
-
constructor() {
|
2039
|
-
super(...arguments);
|
2040
|
-
this.name = coField.string;
|
2041
|
-
this.inbox = coField.optional.string;
|
2042
|
-
this.inboxInvite = coField.optional.string;
|
2043
|
-
}
|
2044
|
-
/**
|
2045
|
-
* Creates a new profile with the given initial values and owner.
|
2046
|
-
*
|
2047
|
-
* The owner (a Group) determines access rights to the Profile.
|
2048
|
-
*
|
2049
|
-
* @category Creation
|
2050
|
-
*/
|
2051
|
-
static create(init, options) {
|
2052
|
-
const owner = options !== void 0 && "owner" in options ? options.owner : options;
|
2053
|
-
if (owner?._type === "Account") {
|
2054
|
-
throw new Error("Profiles should be owned by a group");
|
2055
|
-
}
|
2056
|
-
return super.create(init, options);
|
2057
|
-
}
|
2058
|
-
};
|
2059
|
-
|
2060
|
-
// src/coValues/inbox.ts
|
2061
|
-
import { RawAccount as RawAccount4 } from "cojson";
|
2062
|
-
function createInboxRoot(account) {
|
2063
|
-
if (!account.isLocalNodeOwner) {
|
2064
|
-
throw new Error("Account is not controlled");
|
2065
|
-
}
|
2066
|
-
const rawAccount = account._raw;
|
2067
|
-
const group = rawAccount.core.node.createGroup();
|
2068
|
-
const messagesFeed = group.createStream();
|
2069
|
-
const inboxRoot = rawAccount.createMap();
|
2070
|
-
const processedFeed = rawAccount.createStream();
|
2071
|
-
const failedFeed = rawAccount.createStream();
|
2072
|
-
const inviteLink = `${messagesFeed.id}/${group.createInvite("writeOnly")}`;
|
2073
|
-
inboxRoot.set("messages", messagesFeed.id);
|
2074
|
-
inboxRoot.set("processed", processedFeed.id);
|
2075
|
-
inboxRoot.set("failed", failedFeed.id);
|
2076
|
-
return {
|
2077
|
-
id: inboxRoot.id,
|
2078
|
-
inviteLink
|
2079
|
-
};
|
2080
|
-
}
|
2081
|
-
async function createInboxMessage(payload, inboxOwner) {
|
2082
|
-
const group = payload._raw.group;
|
2083
|
-
if (group instanceof RawAccount4) {
|
2084
|
-
throw new Error("Inbox messages should be owned by a group");
|
2085
|
-
}
|
2086
|
-
group.addMember(inboxOwner, "writer");
|
2087
|
-
const message = group.createMap({
|
2088
|
-
payload: payload.id,
|
2089
|
-
result: void 0,
|
2090
|
-
processed: false,
|
2091
|
-
error: void 0
|
2092
|
-
});
|
2093
|
-
await payload._raw.core.waitForSync();
|
2094
|
-
await message.core.waitForSync();
|
2095
|
-
return message;
|
2096
|
-
}
|
2097
|
-
var Inbox = class _Inbox {
|
2098
|
-
constructor(account, root, messages, processed, failed) {
|
2099
|
-
this.processing = /* @__PURE__ */ new Set();
|
2100
|
-
this.account = account;
|
2101
|
-
this.root = root;
|
2102
|
-
this.messages = messages;
|
2103
|
-
this.processed = processed;
|
2104
|
-
this.failed = failed;
|
2105
|
-
}
|
2106
|
-
subscribe(Schema, callback, options = {}) {
|
2107
|
-
const processed = /* @__PURE__ */ new Set();
|
2108
|
-
const failed = /* @__PURE__ */ new Map();
|
2109
|
-
const node = this.account._raw.core.node;
|
2110
|
-
this.processed.subscribe((stream) => {
|
2111
|
-
for (const items of Object.values(stream.items)) {
|
2112
|
-
for (const item of items) {
|
2113
|
-
processed.add(item.value);
|
2114
|
-
}
|
2115
|
-
}
|
2116
|
-
});
|
2117
|
-
const { account } = this;
|
2118
|
-
const { retries = 3 } = options;
|
2119
|
-
let failTimer = void 0;
|
2120
|
-
const clearFailTimer = () => {
|
2121
|
-
clearTimeout(failTimer);
|
2122
|
-
failTimer = void 0;
|
2123
|
-
};
|
2124
|
-
const handleNewMessages = (stream) => {
|
2125
|
-
clearFailTimer();
|
2126
|
-
for (const [sessionID, items] of Object.entries(stream.items)) {
|
2127
|
-
const accountID = getAccountIDfromSessionID(sessionID);
|
2128
|
-
if (!accountID) {
|
2129
|
-
console.warn("Received message from unknown account", sessionID);
|
2130
|
-
continue;
|
2131
|
-
}
|
2132
|
-
for (const item of items) {
|
2133
|
-
const txKey = `${sessionID}/${item.tx.txIndex}`;
|
2134
|
-
if (!processed.has(txKey) && !this.processing.has(txKey)) {
|
2135
|
-
this.processing.add(txKey);
|
2136
|
-
const id = item.value;
|
2137
|
-
node.load(id).then((message) => {
|
2138
|
-
if (message === "unavailable") {
|
2139
|
-
return Promise.reject(
|
2140
|
-
new Error("Unable to load inbox message " + id)
|
2141
|
-
);
|
2142
|
-
}
|
2143
|
-
return loadCoValue(
|
2144
|
-
anySchemaToCoSchema(Schema),
|
2145
|
-
message.get("payload"),
|
2146
|
-
{
|
2147
|
-
loadAs: account
|
2148
|
-
}
|
2149
|
-
);
|
2150
|
-
}).then((value) => {
|
2151
|
-
if (!value) {
|
2152
|
-
return Promise.reject(
|
2153
|
-
new Error("Unable to load inbox message " + id)
|
2154
|
-
);
|
2155
|
-
}
|
2156
|
-
return callback(value, accountID);
|
2157
|
-
}).then((result) => {
|
2158
|
-
const inboxMessage = node.expectCoValueLoaded(item.value).getCurrentContent();
|
2159
|
-
if (result) {
|
2160
|
-
inboxMessage.set("result", result.id);
|
2161
|
-
}
|
2162
|
-
inboxMessage.set("processed", true);
|
2163
|
-
this.processed.push(txKey);
|
2164
|
-
this.processing.delete(txKey);
|
2165
|
-
}).catch((error) => {
|
2166
|
-
console.error("Error processing inbox message", error);
|
2167
|
-
this.processing.delete(txKey);
|
2168
|
-
const errors = failed.get(txKey) ?? [];
|
2169
|
-
const stringifiedError = String(error);
|
2170
|
-
errors.push(stringifiedError);
|
2171
|
-
let inboxMessage;
|
2172
|
-
try {
|
2173
|
-
inboxMessage = node.expectCoValueLoaded(item.value).getCurrentContent();
|
2174
|
-
inboxMessage.set("error", stringifiedError);
|
2175
|
-
} catch (error2) {
|
2176
|
-
}
|
2177
|
-
if (errors.length > retries) {
|
2178
|
-
inboxMessage?.set("processed", true);
|
2179
|
-
this.processed.push(txKey);
|
2180
|
-
this.failed.push({ errors, value: item.value });
|
2181
|
-
} else {
|
2182
|
-
failed.set(txKey, errors);
|
2183
|
-
if (!failTimer) {
|
2184
|
-
failTimer = setTimeout(
|
2185
|
-
() => handleNewMessages(stream),
|
2186
|
-
100
|
2187
|
-
);
|
2188
|
-
}
|
2189
|
-
}
|
2190
|
-
});
|
2191
|
-
}
|
2192
|
-
}
|
2193
|
-
}
|
2194
|
-
};
|
2195
|
-
const unsubscribe = this.messages.subscribe(handleNewMessages);
|
2196
|
-
return () => {
|
2197
|
-
unsubscribe();
|
2198
|
-
clearFailTimer();
|
2199
|
-
};
|
2200
|
-
}
|
2201
|
-
static async load(account) {
|
2202
|
-
const profile = account.profile;
|
2203
|
-
if (!profile) {
|
2204
|
-
throw new Error("Account profile should already be loaded");
|
2205
|
-
}
|
2206
|
-
if (!profile.inbox) {
|
2207
|
-
throw new Error("The account has not set up their inbox");
|
2208
|
-
}
|
2209
|
-
const node = account._raw.core.node;
|
2210
|
-
const root = await node.load(profile.inbox);
|
2211
|
-
if (root === "unavailable") {
|
2212
|
-
throw new Error("Inbox not found");
|
2213
|
-
}
|
2214
|
-
const [messages, processed, failed] = await Promise.all([
|
2215
|
-
node.load(root.get("messages")),
|
2216
|
-
node.load(root.get("processed")),
|
2217
|
-
node.load(root.get("failed"))
|
2218
|
-
]);
|
2219
|
-
if (messages === "unavailable" || processed === "unavailable" || failed === "unavailable") {
|
2220
|
-
throw new Error("Inbox not found");
|
2221
|
-
}
|
2222
|
-
return new _Inbox(account, root, messages, processed, failed);
|
2223
|
-
}
|
2224
|
-
};
|
2225
|
-
var InboxSender = class _InboxSender {
|
2226
|
-
constructor(currentAccount, owner, messages) {
|
2227
|
-
this.currentAccount = currentAccount;
|
2228
|
-
this.owner = owner;
|
2229
|
-
this.messages = messages;
|
2230
|
-
}
|
2231
|
-
getOwnerAccount() {
|
2232
|
-
return this.owner;
|
2233
|
-
}
|
2234
|
-
async sendMessage(message) {
|
2235
|
-
const inboxMessage = await createInboxMessage(message, this.owner);
|
2236
|
-
this.messages.push(inboxMessage.id);
|
2237
|
-
return new Promise((resolve, reject) => {
|
2238
|
-
inboxMessage.subscribe((message2) => {
|
2239
|
-
if (message2.get("processed")) {
|
2240
|
-
const error = message2.get("error");
|
2241
|
-
if (error) {
|
2242
|
-
reject(new Error(error));
|
2243
|
-
} else {
|
2244
|
-
resolve(
|
2245
|
-
message2.get("result")
|
2246
|
-
);
|
2247
|
-
}
|
2248
|
-
}
|
2249
|
-
});
|
2250
|
-
});
|
2251
|
-
}
|
2252
|
-
static async load(inboxOwnerID, currentAccount) {
|
2253
|
-
currentAccount ||= activeAccountContext.get();
|
2254
|
-
const node = currentAccount._raw.core.node;
|
2255
|
-
const inboxOwnerRaw = await node.load(
|
2256
|
-
inboxOwnerID
|
2257
|
-
);
|
2258
|
-
if (inboxOwnerRaw === "unavailable") {
|
2259
|
-
throw new Error("Failed to load the inbox owner");
|
2260
|
-
}
|
2261
|
-
const inboxOwnerProfileRaw = await node.load(inboxOwnerRaw.get("profile"));
|
2262
|
-
if (inboxOwnerProfileRaw === "unavailable") {
|
2263
|
-
throw new Error("Failed to load the inbox owner profile");
|
2264
|
-
}
|
2265
|
-
if (inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "reader" && inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "writer" && inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "admin") {
|
2266
|
-
throw new Error(
|
2267
|
-
"Insufficient permissions to access the inbox, make sure its user profile is publicly readable."
|
2268
|
-
);
|
2269
|
-
}
|
2270
|
-
const inboxInvite = inboxOwnerProfileRaw.get("inboxInvite");
|
2271
|
-
if (!inboxInvite) {
|
2272
|
-
throw new Error("The user has not set up their inbox");
|
2273
|
-
}
|
2274
|
-
const id = await acceptInvite(inboxInvite, currentAccount);
|
2275
|
-
const messages = await node.load(id);
|
2276
|
-
if (messages === "unavailable") {
|
2277
|
-
throw new Error("Inbox not found");
|
2278
|
-
}
|
2279
|
-
return new _InboxSender(currentAccount, inboxOwnerRaw, messages);
|
2280
|
-
}
|
2281
|
-
};
|
2282
|
-
async function acceptInvite(invite, account) {
|
2283
|
-
account ||= activeAccountContext.get();
|
2284
|
-
const id = invite.slice(0, invite.indexOf("/"));
|
2285
|
-
const inviteSecret = invite.slice(invite.indexOf("/") + 1);
|
2286
|
-
if (!id?.startsWith("co_z") || !inviteSecret.startsWith("inviteSecret_")) {
|
2287
|
-
throw new Error("Invalid inbox ticket");
|
2288
|
-
}
|
2289
|
-
if (!account.isLocalNodeOwner) {
|
2290
|
-
throw new Error("Account is not controlled");
|
2291
|
-
}
|
2292
|
-
await account._raw.core.node.acceptInvite(id, inviteSecret);
|
2293
|
-
return id;
|
2294
|
-
}
|
2295
|
-
function getAccountIDfromSessionID(sessionID) {
|
2296
|
-
const until = sessionID.indexOf("_session");
|
2297
|
-
const accountID = sessionID.slice(0, until);
|
2298
|
-
if (accountID.startsWith("co_z")) {
|
2299
|
-
return accountID;
|
2300
|
-
}
|
2301
|
-
return;
|
2302
|
-
}
|
2303
|
-
|
2304
|
-
// src/coValues/coPlainText.ts
|
2305
|
-
import {
|
2306
|
-
ControlledAccount as ControlledAccount4,
|
2307
|
-
RawAccount as RawAccount5,
|
2308
|
-
stringifyOpID
|
2309
|
-
} from "cojson";
|
2310
|
-
import { calcPatch as calcPatch2 } from "fast-myers-diff";
|
2311
|
-
|
2312
|
-
// src/lib/cache.ts
|
2313
|
-
var weakMap = /* @__PURE__ */ new WeakMap();
|
2314
|
-
var coValuesCache = {
|
2315
|
-
get: (raw, compute) => {
|
2316
|
-
const cached = weakMap.get(raw);
|
2317
|
-
if (cached) {
|
2318
|
-
return cached;
|
2319
|
-
}
|
2320
|
-
const computed = compute();
|
2321
|
-
weakMap.set(raw, computed);
|
2322
|
-
return computed;
|
2323
|
-
}
|
2324
|
-
};
|
2325
|
-
|
2326
|
-
// src/coValues/coPlainText.ts
|
2327
|
-
var CoPlainText = class extends String {
|
2328
|
-
get _owner() {
|
2329
|
-
return this._raw.group instanceof RawAccount5 ? Account.fromRaw(this._raw.group) : Group.fromRaw(this._raw.group);
|
2330
|
-
}
|
2331
|
-
get _loadedAs() {
|
2332
|
-
const agent = this._raw.core.node.getCurrentAgent();
|
2333
|
-
if (agent instanceof ControlledAccount4) {
|
2334
|
-
return coValuesCache.get(
|
2335
|
-
agent.account,
|
2336
|
-
() => anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(
|
2337
|
-
agent.account
|
2338
|
-
)
|
2339
|
-
);
|
2340
|
-
}
|
2341
|
-
return new AnonymousJazzAgent(this._raw.core.node);
|
2342
|
-
}
|
2343
|
-
/** @internal */
|
2344
|
-
constructor(options) {
|
2345
|
-
if (!options) {
|
2346
|
-
super("");
|
2347
|
-
return;
|
2348
|
-
}
|
2349
|
-
if ("fromRaw" in options) {
|
2350
|
-
super(options.fromRaw.toString());
|
2351
|
-
const raw = options.fromRaw;
|
2352
|
-
Object.defineProperties(this, {
|
2353
|
-
id: { value: raw.id, enumerable: false },
|
2354
|
-
_type: { value: "CoPlainText", enumerable: false },
|
2355
|
-
_raw: { value: raw, enumerable: false }
|
2356
|
-
});
|
2357
|
-
return;
|
2358
|
-
}
|
2359
|
-
if ("text" in options && "owner" in options) {
|
2360
|
-
super(options.text);
|
2361
|
-
const raw = options.owner._raw.createPlainText(options.text);
|
2362
|
-
Object.defineProperties(this, {
|
2363
|
-
id: { value: raw.id, enumerable: false },
|
2364
|
-
_type: { value: "CoPlainText", enumerable: false },
|
2365
|
-
_raw: { value: raw, enumerable: false }
|
2366
|
-
});
|
2367
|
-
return;
|
2368
|
-
}
|
2369
|
-
throw new Error("Invalid constructor arguments");
|
2370
|
-
}
|
2371
|
-
/**
|
2372
|
-
* Create a new `CoPlainText` with the given text and owner.
|
2373
|
-
*
|
2374
|
-
* The owner (a Group or Account) determines access rights to the CoPlainText.
|
2375
|
-
*
|
2376
|
-
* The CoPlainText will immediately be persisted and synced to connected peers.
|
2377
|
-
*
|
2378
|
-
* @example
|
2379
|
-
* ```ts
|
2380
|
-
* const text = CoPlainText.create("Hello, world!", { owner: me });
|
2381
|
-
* ```
|
2382
|
-
*
|
2383
|
-
* @category Creation
|
2384
|
-
*/
|
2385
|
-
static create(text, options) {
|
2386
|
-
const { owner } = parseCoValueCreateOptions(options);
|
2387
|
-
return new this({ text, owner });
|
2388
|
-
}
|
2389
|
-
get length() {
|
2390
|
-
return this._raw.toString().length;
|
2391
|
-
}
|
2392
|
-
toString() {
|
2393
|
-
return this._raw.toString();
|
2394
|
-
}
|
2395
|
-
valueOf() {
|
2396
|
-
return this._raw.toString();
|
2397
|
-
}
|
2398
|
-
toJSON() {
|
2399
|
-
return this._raw.toString();
|
2400
|
-
}
|
2401
|
-
[inspect]() {
|
2402
|
-
return this.toJSON();
|
2403
|
-
}
|
2404
|
-
insertBefore(idx, text) {
|
2405
|
-
this._raw.insertBefore(idx, text);
|
2406
|
-
}
|
2407
|
-
insertAfter(idx, text) {
|
2408
|
-
this._raw.insertAfter(idx, text);
|
2409
|
-
}
|
2410
|
-
deleteRange(range) {
|
2411
|
-
this._raw.deleteRange(range);
|
2412
|
-
}
|
2413
|
-
posBefore(idx) {
|
2414
|
-
return this._raw.mapping.opIDbeforeIdx[idx];
|
2415
|
-
}
|
2416
|
-
posAfter(idx) {
|
2417
|
-
return this._raw.mapping.opIDafterIdx[idx];
|
2418
|
-
}
|
2419
|
-
idxBefore(pos) {
|
2420
|
-
return this._raw.mapping.idxBeforeOpID[stringifyOpID(pos)];
|
2421
|
-
}
|
2422
|
-
idxAfter(pos) {
|
2423
|
-
return this._raw.mapping.idxAfterOpID[stringifyOpID(pos)];
|
2424
|
-
}
|
2425
|
-
static fromRaw(raw) {
|
2426
|
-
return new this({ fromRaw: raw });
|
2427
|
-
}
|
2428
|
-
/**
|
2429
|
-
* Apply text, modifying the text in place. Calculates the diff and applies it to the CoValue.
|
2430
|
-
*
|
2431
|
-
* @category Mutation
|
2432
|
-
*/
|
2433
|
-
applyDiff(other) {
|
2434
|
-
const current = this._raw.toString();
|
2435
|
-
const currentGraphemes = this._raw.toGraphemes(current);
|
2436
|
-
const otherGraphemes = this._raw.toGraphemes(other);
|
2437
|
-
const patches = [...calcPatch2(currentGraphemes, otherGraphemes)];
|
2438
|
-
for (const [from, to, insert] of patches.reverse()) {
|
2439
|
-
if (to > from) {
|
2440
|
-
this.deleteRange({ from, to });
|
2441
|
-
}
|
2442
|
-
if (insert.length > 0) {
|
2443
|
-
this.insertBefore(from, this._raw.fromGraphemes(insert));
|
2444
|
-
}
|
2445
|
-
}
|
2446
|
-
}
|
2447
|
-
/**
|
2448
|
-
* Load a `CoPlainText` with a given ID, as a given account.
|
2449
|
-
*
|
2450
|
-
* @category Subscription & Loading
|
2451
|
-
*/
|
2452
|
-
static load(id, options) {
|
2453
|
-
return loadCoValueWithoutMe(this, id, options);
|
2454
|
-
}
|
2455
|
-
static subscribe(id, ...args) {
|
2456
|
-
const { options, listener } = parseSubscribeRestArgs(args);
|
2457
|
-
return subscribeToCoValueWithoutMe(this, id, options, listener);
|
2458
|
-
}
|
2459
|
-
/**
|
2460
|
-
* Given an already loaded `CoPlainText`, subscribe to updates to the `CoPlainText` and ensure that the specified fields are loaded to the specified depth.
|
2461
|
-
*
|
2462
|
-
* Works like `CoPlainText.subscribe()`, but you don't need to pass the ID or the account to load as again.
|
2463
|
-
*
|
2464
|
-
* Returns an unsubscribe function that you should call when you no longer need updates.
|
2465
|
-
*
|
2466
|
-
* @category Subscription & Loading
|
2467
|
-
**/
|
2468
|
-
subscribe(listener) {
|
2469
|
-
return subscribeToExistingCoValue(this, {}, listener);
|
2470
|
-
}
|
2471
|
-
/**
|
2472
|
-
* Allow CoPlainText to behave like a primitive string in most contexts (e.g.,
|
2473
|
-
* string concatenation, template literals, React rendering, etc.) by implementing
|
2474
|
-
* Symbol.toPrimitive. This eliminates the need to call .toString() explicitly.
|
2475
|
-
*
|
2476
|
-
* The 'hint' parameter indicates the preferred type of conversion:
|
2477
|
-
* - 'string': prefer string conversion
|
2478
|
-
* - 'number': prefer number conversion (attempt to parse the text as a number)
|
2479
|
-
* - 'default': usually treat as string
|
2480
|
-
*/
|
2481
|
-
[Symbol.toPrimitive](hint) {
|
2482
|
-
if (hint === "number") {
|
2483
|
-
return Number(this._raw.toString());
|
2484
|
-
}
|
2485
|
-
return this._raw.toString();
|
2486
|
-
}
|
2487
|
-
};
|
2488
|
-
|
2489
|
-
// src/coValues/coRichText.ts
|
2490
|
-
var CoRichText = class extends CoPlainText {
|
2491
|
-
};
|
2492
|
-
|
2493
|
-
// src/coValues/schemaUnion.ts
|
2494
|
-
var SchemaUnion = class _SchemaUnion extends CoValueBase {
|
2495
|
-
/**
|
2496
|
-
* Create a new union type from a discriminator function.
|
2497
|
-
*
|
2498
|
-
* The discriminator function receives the raw data and should return the appropriate concrete class to use for that data.
|
2499
|
-
*
|
2500
|
-
* When loading a SchemaUnion, the correct subclass will be instantiated based on the discriminator.
|
2501
|
-
*
|
2502
|
-
* @param discriminator - Function that determines which concrete type to use
|
2503
|
-
* @returns A new class that can create/load instances of the union type
|
2504
|
-
*
|
2505
|
-
* @example
|
2506
|
-
* ```ts
|
2507
|
-
* const WidgetUnion = SchemaUnion.Of<BaseWidget>((raw) => {
|
2508
|
-
* switch (raw.get("type")) {
|
2509
|
-
* case "button": return ButtonWidget;
|
2510
|
-
* case "slider": return SliderWidget;
|
2511
|
-
* default: throw new Error("Unknown widget type");
|
2512
|
-
* }
|
2513
|
-
* });
|
2514
|
-
*
|
2515
|
-
* const widget = await loadCoValue(WidgetUnion, id, me, {});
|
2516
|
-
*
|
2517
|
-
* // You can narrow the returned instance to a subclass by using `instanceof`
|
2518
|
-
* if (widget instanceof ButtonWidget) {
|
2519
|
-
* console.log(widget.label);
|
2520
|
-
* } else if (widget instanceof SliderWidget) {
|
2521
|
-
* console.log(widget.min, widget.max);
|
2522
|
-
* }
|
2523
|
-
* ```
|
2524
|
-
*
|
2525
|
-
* @category Declaration
|
2526
|
-
**/
|
2527
|
-
static Of(discriminator) {
|
2528
|
-
return class SchemaUnionClass extends _SchemaUnion {
|
2529
|
-
static fromRaw(raw) {
|
2530
|
-
const ResolvedClass = discriminator(
|
2531
|
-
raw
|
2532
|
-
);
|
2533
|
-
return ResolvedClass.fromRaw(raw);
|
2534
|
-
}
|
2535
|
-
};
|
2536
|
-
}
|
2537
|
-
/**
|
2538
|
-
* Create an instance from raw data. This is called internally and should not be used directly.
|
2539
|
-
* Use {@link SchemaUnion.Of} to create a union type instead.
|
2540
|
-
*
|
2541
|
-
* @internal
|
2542
|
-
*/
|
2543
|
-
// @ts-ignore
|
2544
|
-
static fromRaw(raw) {
|
2545
|
-
throw new Error("Not implemented");
|
2546
|
-
}
|
2547
|
-
};
|
2548
|
-
|
2549
|
-
// src/implementation/anonymousJazzAgent.ts
|
2550
|
-
var AnonymousJazzAgent = class {
|
2551
|
-
constructor(node) {
|
2552
|
-
this.node = node;
|
2553
|
-
this._type = "Anonymous";
|
2554
|
-
}
|
2555
|
-
};
|
2556
|
-
|
2557
|
-
// src/implementation/activeAccountContext.ts
|
2558
|
-
var ActiveAccountContext = class {
|
2559
|
-
constructor() {
|
2560
|
-
this.activeAccount = null;
|
2561
|
-
this.guestMode = false;
|
2562
|
-
}
|
2563
|
-
set(account) {
|
2564
|
-
this.activeAccount = account;
|
2565
|
-
this.guestMode = false;
|
2566
|
-
}
|
2567
|
-
setGuestMode() {
|
2568
|
-
this.activeAccount = null;
|
2569
|
-
this.guestMode = true;
|
2570
|
-
}
|
2571
|
-
maybeGet() {
|
2572
|
-
return this.activeAccount;
|
2573
|
-
}
|
2574
|
-
get() {
|
2575
|
-
if (!this.activeAccount) {
|
2576
|
-
if (this.guestMode) {
|
2577
|
-
throw new Error(
|
2578
|
-
"Something that expects a full active account was called in guest mode."
|
2579
|
-
);
|
2580
|
-
}
|
2581
|
-
throw new Error("No active account");
|
2582
|
-
}
|
2583
|
-
return this.activeAccount;
|
2584
|
-
}
|
2585
|
-
};
|
2586
|
-
var activeAccountContext = new ActiveAccountContext();
|
2587
|
-
|
2588
|
-
// src/implementation/refs.ts
|
2589
|
-
var Ref = class {
|
2590
|
-
constructor(id, controlledAccount, schema, parent) {
|
2591
|
-
this.id = id;
|
2592
|
-
this.controlledAccount = controlledAccount;
|
2593
|
-
this.schema = schema;
|
2594
|
-
this.parent = parent;
|
2595
|
-
if (!isRefEncoded(schema)) {
|
2596
|
-
throw new Error("Ref must be constructed with a ref schema");
|
2597
|
-
}
|
2598
|
-
}
|
2599
|
-
async load() {
|
2600
|
-
const subscriptionScope = getSubscriptionScope(this.parent);
|
2601
|
-
subscriptionScope.subscribeToId(this.id, this.schema);
|
2602
|
-
const node = subscriptionScope.childNodes.get(this.id);
|
2603
|
-
if (!node) {
|
2604
|
-
return null;
|
2605
|
-
}
|
2606
|
-
const value = node.value;
|
2607
|
-
if (value?.type === "loaded") {
|
2608
|
-
return value.value;
|
2609
|
-
} else {
|
2610
|
-
return new Promise((resolve) => {
|
2611
|
-
const unsubscribe = node.subscribe((value2) => {
|
2612
|
-
if (value2?.type === "loaded") {
|
2613
|
-
unsubscribe();
|
2614
|
-
resolve(value2.value);
|
2615
|
-
} else if (value2?.type === "unavailable") {
|
2616
|
-
unsubscribe();
|
2617
|
-
resolve(null);
|
2618
|
-
} else if (value2?.type === "unauthorized") {
|
2619
|
-
unsubscribe();
|
2620
|
-
resolve(null);
|
2621
|
-
}
|
2622
|
-
});
|
2623
|
-
});
|
2624
|
-
}
|
2625
|
-
}
|
2626
|
-
get value() {
|
2627
|
-
return accessChildById(this.parent, this.id, this.schema);
|
2628
|
-
}
|
2629
|
-
};
|
2630
|
-
function makeRefs(parent, getIdForKey, getKeysWithIds, controlledAccount, refSchemaForKey) {
|
2631
|
-
const refs = {};
|
2632
|
-
return new Proxy(refs, {
|
2633
|
-
get(_target, key) {
|
2634
|
-
if (key === Symbol.iterator) {
|
2635
|
-
return function* () {
|
2636
|
-
for (const key2 of getKeysWithIds()) {
|
2637
|
-
yield new Ref(
|
2638
|
-
getIdForKey(key2),
|
2639
|
-
controlledAccount,
|
2640
|
-
refSchemaForKey(key2),
|
2641
|
-
parent
|
2642
|
-
);
|
2643
|
-
}
|
2644
|
-
};
|
2645
|
-
}
|
2646
|
-
if (typeof key === "symbol") return void 0;
|
2647
|
-
if (key === "length") {
|
2648
|
-
return getKeysWithIds().length;
|
2649
|
-
}
|
2650
|
-
const id = getIdForKey(key);
|
2651
|
-
if (!id) return void 0;
|
2652
|
-
return new Ref(
|
2653
|
-
id,
|
2654
|
-
controlledAccount,
|
2655
|
-
refSchemaForKey(key),
|
2656
|
-
parent
|
2657
|
-
);
|
2658
|
-
},
|
2659
|
-
ownKeys() {
|
2660
|
-
return getKeysWithIds().map((key) => key.toString());
|
2661
|
-
},
|
2662
|
-
getOwnPropertyDescriptor(target, key) {
|
2663
|
-
const id = getIdForKey(key);
|
2664
|
-
if (id) {
|
2665
|
-
return {
|
2666
|
-
enumerable: true,
|
2667
|
-
configurable: true,
|
2668
|
-
writable: true
|
2669
|
-
};
|
2670
|
-
} else {
|
2671
|
-
return Reflect.getOwnPropertyDescriptor(target, key);
|
2672
|
-
}
|
2673
|
-
}
|
2674
|
-
});
|
2675
|
-
}
|
2676
|
-
|
2677
|
-
// src/implementation/schema.ts
|
2678
|
-
var Encoders = {
|
2679
|
-
Date: {
|
2680
|
-
encode: (value) => value.toISOString(),
|
2681
|
-
decode: (value) => new Date(value)
|
2682
|
-
},
|
2683
|
-
OptionalDate: {
|
2684
|
-
encode: (value) => value?.toISOString() || null,
|
2685
|
-
decode: (value) => value === null ? void 0 : new Date(value)
|
2686
|
-
}
|
2687
|
-
};
|
2688
|
-
var optional2 = {
|
2689
|
-
ref: optionalRef,
|
2690
|
-
json() {
|
2691
|
-
return { [SchemaInit]: "json" };
|
2692
|
-
},
|
2693
|
-
encoded(arg) {
|
2694
|
-
return { [SchemaInit]: { encoded: arg } };
|
2695
|
-
},
|
2696
|
-
string: {
|
2697
|
-
[SchemaInit]: "json"
|
2698
|
-
},
|
2699
|
-
number: {
|
2700
|
-
[SchemaInit]: "json"
|
2701
|
-
},
|
2702
|
-
boolean: {
|
2703
|
-
[SchemaInit]: "json"
|
2704
|
-
},
|
2705
|
-
null: {
|
2706
|
-
[SchemaInit]: "json"
|
2707
|
-
},
|
2708
|
-
Date: {
|
2709
|
-
[SchemaInit]: { encoded: Encoders.OptionalDate }
|
2710
|
-
},
|
2711
|
-
literal(..._lit) {
|
2712
|
-
return { [SchemaInit]: "json" };
|
2713
|
-
}
|
2714
|
-
};
|
2715
|
-
var coField = {
|
2716
|
-
string: {
|
2717
|
-
[SchemaInit]: "json"
|
2718
|
-
},
|
2719
|
-
number: {
|
2720
|
-
[SchemaInit]: "json"
|
2721
|
-
},
|
2722
|
-
boolean: {
|
2723
|
-
[SchemaInit]: "json"
|
2724
|
-
},
|
2725
|
-
null: {
|
2726
|
-
[SchemaInit]: "json"
|
2727
|
-
},
|
2728
|
-
Date: {
|
2729
|
-
[SchemaInit]: { encoded: Encoders.Date }
|
2730
|
-
},
|
2731
|
-
literal(..._lit) {
|
2732
|
-
return { [SchemaInit]: "json" };
|
2733
|
-
},
|
2734
|
-
json() {
|
2735
|
-
return { [SchemaInit]: "json" };
|
2736
|
-
},
|
2737
|
-
encoded(arg) {
|
2738
|
-
return { [SchemaInit]: { encoded: arg } };
|
2739
|
-
},
|
2740
|
-
ref,
|
2741
|
-
items: ItemsSym,
|
2742
|
-
optional: optional2
|
2743
|
-
};
|
2744
|
-
function optionalRef(arg) {
|
2745
|
-
return ref(arg, { optional: true });
|
2746
|
-
}
|
2747
|
-
function ref(arg, options) {
|
2748
|
-
return {
|
2749
|
-
[SchemaInit]: {
|
2750
|
-
ref: arg,
|
2751
|
-
optional: options?.optional || false
|
2752
|
-
}
|
2753
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2754
|
-
};
|
2755
|
-
}
|
2756
|
-
function isRefEncoded(schema) {
|
2757
|
-
return typeof schema === "object" && "ref" in schema && "optional" in schema && typeof schema.ref === "function";
|
2758
|
-
}
|
2759
|
-
function instantiateRefEncoded(schema, raw) {
|
2760
|
-
return isCoValueClass(schema.ref) ? schema.ref.fromRaw(raw) : schema.ref(
|
2761
|
-
raw
|
2762
|
-
).fromRaw(raw);
|
2763
|
-
}
|
2764
|
-
|
2765
|
-
// src/lib/migration.ts
|
2766
|
-
function applyCoValueMigrations(instance) {
|
2767
|
-
const node = instance._raw.core.node;
|
2768
|
-
const migratedCoValues = node._migratedCoValues ??= /* @__PURE__ */ new Set();
|
2769
|
-
if ("migrate" in instance && typeof instance.migrate === "function" && instance._type !== "Account" && !migratedCoValues.has(instance.id)) {
|
2770
|
-
migratedCoValues.add(instance.id);
|
2771
|
-
const result = instance.migrate?.(instance);
|
2772
|
-
if (result && "then" in result) {
|
2773
|
-
throw new Error("Migration function cannot be async");
|
2774
|
-
}
|
2775
|
-
}
|
2776
|
-
}
|
2777
|
-
|
2778
|
-
// src/subscribe/CoValueCoreSubscription.ts
|
2779
|
-
var CoValueCoreSubscription = class {
|
2780
|
-
constructor(node, id, listener) {
|
2781
|
-
this.node = node;
|
2782
|
-
this.id = id;
|
2783
|
-
this.listener = listener;
|
2784
|
-
this._unsubscribe = () => {
|
2785
|
-
};
|
2786
|
-
this.unsubscribed = false;
|
2787
|
-
const entry = this.node.getCoValue(this.id);
|
2788
|
-
if (entry?.isAvailable()) {
|
2789
|
-
this.subscribe(entry.getCurrentContent());
|
2790
|
-
} else {
|
2791
|
-
this.node.loadCoValueCore(this.id).then((value) => {
|
2792
|
-
if (this.unsubscribed) return;
|
2793
|
-
if (value.isAvailable()) {
|
2794
|
-
this.subscribe(value.getCurrentContent());
|
2795
|
-
} else {
|
2796
|
-
this.listener("unavailable");
|
2797
|
-
this.subscribeToState();
|
2798
|
-
}
|
2799
|
-
});
|
2800
|
-
}
|
2801
|
-
}
|
2802
|
-
subscribeToState() {
|
2803
|
-
const entry = this.node.getCoValue(this.id);
|
2804
|
-
const handleStateChange = (core, unsubFromStateChange2) => {
|
2805
|
-
if (this.unsubscribed) {
|
2806
|
-
unsubFromStateChange2();
|
2807
|
-
return;
|
2808
|
-
}
|
2809
|
-
if (core.isAvailable()) {
|
2810
|
-
this.subscribe(core.getCurrentContent());
|
2811
|
-
unsubFromStateChange2();
|
2812
|
-
}
|
2813
|
-
};
|
2814
|
-
const unsubFromStateChange = entry.subscribe(handleStateChange);
|
2815
|
-
this._unsubscribe = () => {
|
2816
|
-
unsubFromStateChange();
|
2817
|
-
};
|
2818
|
-
}
|
2819
|
-
subscribe(value) {
|
2820
|
-
if (this.unsubscribed) return;
|
2821
|
-
this._unsubscribe = value.subscribe((value2) => {
|
2822
|
-
this.listener(value2);
|
2823
|
-
});
|
2824
|
-
this.listener(value);
|
2825
|
-
}
|
2826
|
-
unsubscribe() {
|
2827
|
-
if (this.unsubscribed) return;
|
2828
|
-
this.unsubscribed = true;
|
2829
|
-
this._unsubscribe();
|
2830
|
-
}
|
2831
|
-
};
|
2832
|
-
|
2833
|
-
// src/subscribe/JazzError.ts
|
2834
|
-
var JazzError = class _JazzError {
|
2835
|
-
constructor(id, type, issues) {
|
2836
|
-
this.id = id;
|
2837
|
-
this.type = type;
|
2838
|
-
this.issues = issues;
|
2839
|
-
}
|
2840
|
-
toString() {
|
2841
|
-
return this.issues.map((issue) => {
|
2842
|
-
let message = `${issue.message}`;
|
2843
|
-
if (this.id) {
|
2844
|
-
message += ` from ${this.id}`;
|
2845
|
-
}
|
2846
|
-
if (issue.path.length > 0) {
|
2847
|
-
message += ` on path ${issue.path.join(".")}`;
|
2848
|
-
}
|
2849
|
-
return message;
|
2850
|
-
}).join("\n");
|
2851
|
-
}
|
2852
|
-
prependPath(item) {
|
2853
|
-
if (this.issues.length === 0) {
|
2854
|
-
return this;
|
2855
|
-
}
|
2856
|
-
const issues = this.issues.map((issue) => {
|
2857
|
-
return {
|
2858
|
-
...issue,
|
2859
|
-
path: [item].concat(issue.path)
|
2860
|
-
};
|
2861
|
-
});
|
2862
|
-
return new _JazzError(this.id, this.type, issues);
|
2863
|
-
}
|
2864
|
-
};
|
2865
|
-
|
2866
|
-
// src/subscribe/utils.ts
|
2867
|
-
import { RawAccount as RawAccount6 } from "cojson";
|
2868
|
-
function getOwnerFromRawValue(raw) {
|
2869
|
-
const owner = raw.group;
|
2870
|
-
return coValuesCache.get(
|
2871
|
-
owner,
|
2872
|
-
() => owner instanceof RawAccount6 ? anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(owner) : RegisteredSchemas["Group"].fromRaw(owner)
|
2873
|
-
);
|
2874
|
-
}
|
2875
|
-
function createCoValue(ref2, raw, subscriptionScope) {
|
2876
|
-
const freshValueInstance = instantiateRefEncoded(ref2, raw);
|
2877
|
-
Object.defineProperty(freshValueInstance, "_subscriptionScope", {
|
2878
|
-
value: subscriptionScope,
|
2879
|
-
writable: false,
|
2880
|
-
enumerable: false,
|
2881
|
-
configurable: false
|
2882
|
-
});
|
2883
|
-
return {
|
2884
|
-
type: "loaded",
|
2885
|
-
value: freshValueInstance,
|
2886
|
-
id: subscriptionScope.id
|
2887
|
-
};
|
2888
|
-
}
|
2889
|
-
|
2890
|
-
// src/subscribe/SubscriptionScope.ts
|
2891
|
-
var SubscriptionScope = class _SubscriptionScope {
|
2892
|
-
constructor(node, resolve, id, schema) {
|
2893
|
-
this.node = node;
|
2894
|
-
this.id = id;
|
2895
|
-
this.schema = schema;
|
2896
|
-
this.childNodes = /* @__PURE__ */ new Map();
|
2897
|
-
this.childValues = /* @__PURE__ */ new Map();
|
2898
|
-
this.childErrors = /* @__PURE__ */ new Map();
|
2899
|
-
this.validationErrors = /* @__PURE__ */ new Map();
|
2900
|
-
this.dirty = false;
|
2901
|
-
this.idsSubscribed = /* @__PURE__ */ new Set();
|
2902
|
-
this.autoloaded = /* @__PURE__ */ new Set();
|
2903
|
-
this.autoloadedKeys = /* @__PURE__ */ new Set();
|
2904
|
-
this.skipInvalidKeys = /* @__PURE__ */ new Set();
|
2905
|
-
this.totalValidTransactions = 0;
|
2906
|
-
this.migrated = false;
|
2907
|
-
this.migrating = false;
|
2908
|
-
this.silenceUpdates = false;
|
2909
|
-
this.handleChildUpdate = (id, value, key) => {
|
2910
|
-
if (value.type === "unloaded") {
|
2911
|
-
return;
|
2912
|
-
}
|
2913
|
-
this.childValues.set(id, value);
|
2914
|
-
if (value.type === "unavailable" || value.type === "unauthorized") {
|
2915
|
-
this.childErrors.set(id, value.prependPath(key ?? id));
|
2916
|
-
this.errorFromChildren = this.computeChildErrors();
|
2917
|
-
} else if (this.errorFromChildren && this.childErrors.has(id)) {
|
2918
|
-
this.childErrors.delete(id);
|
2919
|
-
this.errorFromChildren = this.computeChildErrors();
|
2920
|
-
}
|
2921
|
-
if (this.shouldSendUpdates()) {
|
2922
|
-
if (this.value.type === "loaded") {
|
2923
|
-
this.updateValue(
|
2924
|
-
createCoValue(this.schema, this.value.value._raw, this)
|
2925
|
-
);
|
2926
|
-
}
|
2927
|
-
}
|
2928
|
-
this.triggerUpdate();
|
2929
|
-
};
|
2930
|
-
this.subscribers = /* @__PURE__ */ new Set();
|
2931
|
-
this.resolve = resolve;
|
2932
|
-
this.value = { type: "unloaded", id };
|
2933
|
-
let lastUpdate;
|
2934
|
-
this.subscription = new CoValueCoreSubscription(node, id, (value) => {
|
2935
|
-
lastUpdate = value;
|
2936
|
-
if (!this.migrated && value !== "unavailable") {
|
2937
|
-
if (this.migrating) {
|
2938
|
-
return;
|
2939
|
-
}
|
2940
|
-
this.migrating = true;
|
2941
|
-
applyCoValueMigrations(instantiateRefEncoded(this.schema, value));
|
2942
|
-
this.migrated = true;
|
2943
|
-
this.handleUpdate(lastUpdate);
|
2944
|
-
return;
|
2945
|
-
}
|
2946
|
-
this.handleUpdate(value);
|
2947
|
-
});
|
2948
|
-
}
|
2949
|
-
updateValue(value) {
|
2950
|
-
this.value = value;
|
2951
|
-
this.dirty = true;
|
2952
|
-
}
|
2953
|
-
handleUpdate(update) {
|
2954
|
-
if (update === "unavailable") {
|
2955
|
-
if (this.value.type === "unloaded") {
|
2956
|
-
this.updateValue(
|
2957
|
-
new JazzError(this.id, "unavailable", [
|
2958
|
-
{
|
2959
|
-
code: "unavailable",
|
2960
|
-
message: "The value is unavailable",
|
2961
|
-
params: {
|
2962
|
-
id: this.id
|
2963
|
-
},
|
2964
|
-
path: []
|
2965
|
-
}
|
2966
|
-
])
|
2967
|
-
);
|
2968
|
-
}
|
2969
|
-
this.triggerUpdate();
|
2970
|
-
return;
|
2971
|
-
}
|
2972
|
-
const ruleset = update.core.verified.header.ruleset;
|
2973
|
-
const hasAccess = ruleset.type !== "ownedByGroup" || getOwnerFromRawValue(update).myRole() !== void 0;
|
2974
|
-
if (!hasAccess) {
|
2975
|
-
if (this.value.type !== "unauthorized") {
|
2976
|
-
this.updateValue(
|
2977
|
-
new JazzError(this.id, "unauthorized", [
|
2978
|
-
{
|
2979
|
-
code: "unauthorized",
|
2980
|
-
message: "The current user is not authorized to access this value",
|
2981
|
-
params: {
|
2982
|
-
id: this.id
|
2983
|
-
},
|
2984
|
-
path: []
|
2985
|
-
}
|
2986
|
-
])
|
2987
|
-
);
|
2988
|
-
this.triggerUpdate();
|
2989
|
-
}
|
2990
|
-
return;
|
2991
|
-
}
|
2992
|
-
this.silenceUpdates = true;
|
2993
|
-
if (this.value.type !== "loaded") {
|
2994
|
-
this.updateValue(createCoValue(this.schema, update, this));
|
2995
|
-
this.loadChildren();
|
2996
|
-
} else {
|
2997
|
-
const hasChanged = update.totalValidTransactions !== this.totalValidTransactions || // Checking the identity of the _raw value makes us cover the cases where the group
|
2998
|
-
// has been updated and the coValues that don't update the totalValidTransactions value (e.g. FileStream)
|
2999
|
-
this.value.value._raw !== update;
|
3000
|
-
if (this.loadChildren()) {
|
3001
|
-
this.updateValue(createCoValue(this.schema, update, this));
|
3002
|
-
} else if (hasChanged) {
|
3003
|
-
this.updateValue(createCoValue(this.schema, update, this));
|
3004
|
-
}
|
3005
|
-
}
|
3006
|
-
this.totalValidTransactions = update.totalValidTransactions;
|
3007
|
-
this.silenceUpdates = false;
|
3008
|
-
this.triggerUpdate();
|
3009
|
-
}
|
3010
|
-
computeChildErrors() {
|
3011
|
-
let issues = [];
|
3012
|
-
let errorType = "unavailable";
|
3013
|
-
if (this.childErrors.size === 0 && this.validationErrors.size === 0) {
|
3014
|
-
return void 0;
|
3015
|
-
}
|
3016
|
-
for (const [key, value] of this.childErrors.entries()) {
|
3017
|
-
if (this.autoloaded.has(key)) {
|
3018
|
-
continue;
|
3019
|
-
}
|
3020
|
-
if (this.skipInvalidKeys.has(key)) {
|
3021
|
-
continue;
|
3022
|
-
}
|
3023
|
-
errorType = value.type;
|
3024
|
-
if (value.issues) {
|
3025
|
-
issues.push(...value.issues);
|
3026
|
-
}
|
3027
|
-
}
|
3028
|
-
for (const [key, value] of this.validationErrors.entries()) {
|
3029
|
-
if (this.skipInvalidKeys.has(key)) {
|
3030
|
-
continue;
|
3031
|
-
}
|
3032
|
-
errorType = value.type;
|
3033
|
-
if (value.issues) {
|
3034
|
-
issues.push(...value.issues);
|
3035
|
-
}
|
3036
|
-
}
|
3037
|
-
if (issues.length) {
|
3038
|
-
return new JazzError(this.id, errorType, issues);
|
3039
|
-
}
|
3040
|
-
return void 0;
|
3041
|
-
}
|
3042
|
-
shouldSendUpdates() {
|
3043
|
-
if (this.value.type === "unloaded") return false;
|
3044
|
-
if (this.value.type !== "loaded") return true;
|
3045
|
-
for (const value of this.childValues.values()) {
|
3046
|
-
if (value.type === "unloaded" && !this.autoloaded.has(value.id)) {
|
3047
|
-
return false;
|
3048
|
-
}
|
3049
|
-
}
|
3050
|
-
return true;
|
3051
|
-
}
|
3052
|
-
getCurrentValue() {
|
3053
|
-
if (this.value.type === "unauthorized" || this.value.type === "unavailable") {
|
3054
|
-
console.error(this.value.toString());
|
3055
|
-
return null;
|
3056
|
-
}
|
3057
|
-
if (!this.shouldSendUpdates()) {
|
3058
|
-
return void 0;
|
3059
|
-
}
|
3060
|
-
if (this.errorFromChildren) {
|
3061
|
-
console.error(this.errorFromChildren.toString());
|
3062
|
-
return null;
|
3063
|
-
}
|
3064
|
-
if (this.value.type === "loaded") {
|
3065
|
-
return this.value.value;
|
3066
|
-
}
|
3067
|
-
return void 0;
|
3068
|
-
}
|
3069
|
-
triggerUpdate() {
|
3070
|
-
if (!this.shouldSendUpdates()) return;
|
3071
|
-
if (!this.dirty) return;
|
3072
|
-
if (this.subscribers.size === 0) return;
|
3073
|
-
if (this.silenceUpdates) return;
|
3074
|
-
const error = this.errorFromChildren;
|
3075
|
-
const value = this.value;
|
3076
|
-
if (error) {
|
3077
|
-
this.subscribers.forEach((listener) => listener(error));
|
3078
|
-
} else if (value.type !== "unloaded") {
|
3079
|
-
this.subscribers.forEach((listener) => listener(value));
|
3080
|
-
}
|
3081
|
-
this.dirty = false;
|
3082
|
-
}
|
3083
|
-
subscribe(listener) {
|
3084
|
-
this.subscribers.add(listener);
|
3085
|
-
return () => {
|
3086
|
-
this.subscribers.delete(listener);
|
3087
|
-
};
|
3088
|
-
}
|
3089
|
-
setListener(listener) {
|
3090
|
-
this.subscribers.add(listener);
|
3091
|
-
this.triggerUpdate();
|
3092
|
-
}
|
3093
|
-
subscribeToKey(key) {
|
3094
|
-
if (this.resolve === true || !this.resolve) {
|
3095
|
-
this.resolve = {};
|
3096
|
-
}
|
3097
|
-
if (this.resolve.$each || key in this.resolve) {
|
3098
|
-
return;
|
3099
|
-
}
|
3100
|
-
const resolve = this.resolve;
|
3101
|
-
resolve[key] = true;
|
3102
|
-
this.autoloadedKeys.add(key);
|
3103
|
-
if (this.value.type !== "loaded") {
|
3104
|
-
return;
|
3105
|
-
}
|
3106
|
-
const value = this.value.value;
|
3107
|
-
this.silenceUpdates = true;
|
3108
|
-
if (value._type === "CoMap" || value._type === "Account") {
|
3109
|
-
const map = value;
|
3110
|
-
this.loadCoMapKey(map, key, true);
|
3111
|
-
} else if (value._type === "CoList") {
|
3112
|
-
const list = value;
|
3113
|
-
this.loadCoListKey(list, key, true);
|
3114
|
-
}
|
3115
|
-
this.silenceUpdates = false;
|
3116
|
-
}
|
3117
|
-
subscribeToId(id, descriptor) {
|
3118
|
-
if (this.idsSubscribed.has(id) || this.childValues.has(id)) {
|
3119
|
-
return;
|
3120
|
-
}
|
3121
|
-
this.idsSubscribed.add(id);
|
3122
|
-
this.autoloaded.add(id);
|
3123
|
-
this.silenceUpdates = true;
|
3124
|
-
this.childValues.set(id, { type: "unloaded", id });
|
3125
|
-
const child = new _SubscriptionScope(
|
3126
|
-
this.node,
|
3127
|
-
true,
|
3128
|
-
id,
|
3129
|
-
descriptor
|
3130
|
-
);
|
3131
|
-
this.childNodes.set(id, child);
|
3132
|
-
child.setListener((value) => this.handleChildUpdate(id, value));
|
3133
|
-
this.silenceUpdates = false;
|
3134
|
-
}
|
3135
|
-
loadChildren() {
|
3136
|
-
const { resolve } = this;
|
3137
|
-
if (this.value.type !== "loaded") {
|
3138
|
-
return false;
|
3139
|
-
}
|
3140
|
-
const value = this.value.value;
|
3141
|
-
const depth = typeof resolve !== "object" || resolve === null ? {} : resolve;
|
3142
|
-
let hasChanged = false;
|
3143
|
-
const idsToLoad = new Set(this.idsSubscribed);
|
3144
|
-
const coValueType = value._type;
|
3145
|
-
if (Object.keys(depth).length > 0) {
|
3146
|
-
if (coValueType === "CoMap" || coValueType === "Account") {
|
3147
|
-
const map = value;
|
3148
|
-
const keys = "$each" in depth ? map._raw.keys() : Object.keys(depth);
|
3149
|
-
for (const key of keys) {
|
3150
|
-
const id = this.loadCoMapKey(map, key, depth[key] ?? depth.$each);
|
3151
|
-
if (id) {
|
3152
|
-
idsToLoad.add(id);
|
3153
|
-
}
|
3154
|
-
}
|
3155
|
-
} else if (value._type === "CoList") {
|
3156
|
-
const list = value;
|
3157
|
-
const descriptor = list.getItemsDescriptor();
|
3158
|
-
if (descriptor && isRefEncoded(descriptor)) {
|
3159
|
-
list._raw.processNewTransactions();
|
3160
|
-
const entries = list._raw.entries();
|
3161
|
-
const keys = "$each" in depth ? Object.keys(entries) : Object.keys(depth);
|
3162
|
-
for (const key of keys) {
|
3163
|
-
const id = this.loadCoListKey(list, key, depth[key] ?? depth.$each);
|
3164
|
-
if (id) {
|
3165
|
-
idsToLoad.add(id);
|
3166
|
-
}
|
3167
|
-
}
|
3168
|
-
}
|
3169
|
-
} else if (value._type === "CoStream") {
|
3170
|
-
const stream = value;
|
3171
|
-
const descriptor = stream.getItemsDescriptor();
|
3172
|
-
if (descriptor && isRefEncoded(descriptor)) {
|
3173
|
-
for (const session of stream._raw.sessions()) {
|
3174
|
-
const values = stream._raw.items[session] ?? [];
|
3175
|
-
for (const [i, item] of values.entries()) {
|
3176
|
-
const key = `${session}/${i}`;
|
3177
|
-
if (!depth.$each && !depth[key]) {
|
3178
|
-
continue;
|
3179
|
-
}
|
3180
|
-
const id = item.value;
|
3181
|
-
if (id) {
|
3182
|
-
idsToLoad.add(id);
|
3183
|
-
this.loadChildNode(id, depth[key] ?? depth.$each, descriptor);
|
3184
|
-
this.validationErrors.delete(key);
|
3185
|
-
} else if (!descriptor.optional) {
|
3186
|
-
this.validationErrors.set(
|
3187
|
-
key,
|
3188
|
-
new JazzError(void 0, "unavailable", [
|
3189
|
-
{
|
3190
|
-
code: "validationError",
|
3191
|
-
message: `The ref on position ${key} requested on ${stream.constructor.name} is missing`,
|
3192
|
-
params: {},
|
3193
|
-
path: [key]
|
3194
|
-
}
|
3195
|
-
])
|
3196
|
-
);
|
3197
|
-
}
|
3198
|
-
}
|
3199
|
-
}
|
3200
|
-
}
|
3201
|
-
}
|
3202
|
-
}
|
3203
|
-
this.errorFromChildren = this.computeChildErrors();
|
3204
|
-
for (const id of this.childNodes.keys()) {
|
3205
|
-
if (!idsToLoad.has(id)) {
|
3206
|
-
hasChanged = true;
|
3207
|
-
const childNode = this.childNodes.get(id);
|
3208
|
-
if (childNode) {
|
3209
|
-
childNode.destroy();
|
3210
|
-
}
|
3211
|
-
this.childNodes.delete(id);
|
3212
|
-
this.childValues.delete(id);
|
3213
|
-
}
|
3214
|
-
}
|
3215
|
-
return hasChanged;
|
3216
|
-
}
|
3217
|
-
loadCoMapKey(map, key, depth) {
|
3218
|
-
if (key === "$onError") {
|
3219
|
-
return void 0;
|
3220
|
-
}
|
3221
|
-
const id = map._raw.get(key);
|
3222
|
-
const descriptor = map.getDescriptor(key);
|
3223
|
-
if (!descriptor) {
|
3224
|
-
this.childErrors.set(
|
3225
|
-
key,
|
3226
|
-
new JazzError(void 0, "unavailable", [
|
3227
|
-
{
|
3228
|
-
code: "validationError",
|
3229
|
-
message: `The ref ${key} requested on ${map.constructor.name} is not defined in the schema`,
|
3230
|
-
params: {},
|
3231
|
-
path: [key]
|
3232
|
-
}
|
3233
|
-
])
|
3234
|
-
);
|
3235
|
-
return void 0;
|
3236
|
-
}
|
3237
|
-
if (isRefEncoded(descriptor)) {
|
3238
|
-
if (id) {
|
3239
|
-
this.loadChildNode(id, depth, descriptor, key);
|
3240
|
-
this.validationErrors.delete(key);
|
3241
|
-
return id;
|
3242
|
-
} else if (!descriptor.optional) {
|
3243
|
-
this.validationErrors.set(
|
3244
|
-
key,
|
3245
|
-
new JazzError(void 0, "unavailable", [
|
3246
|
-
{
|
3247
|
-
code: "validationError",
|
3248
|
-
message: `The ref ${key} requested on ${map.constructor.name} is missing`,
|
3249
|
-
params: {},
|
3250
|
-
path: [key]
|
3251
|
-
}
|
3252
|
-
])
|
3253
|
-
);
|
3254
|
-
}
|
3255
|
-
}
|
3256
|
-
return void 0;
|
3257
|
-
}
|
3258
|
-
loadCoListKey(list, key, depth) {
|
3259
|
-
const descriptor = list.getItemsDescriptor();
|
3260
|
-
if (!descriptor || !isRefEncoded(descriptor)) {
|
3261
|
-
return void 0;
|
3262
|
-
}
|
3263
|
-
const entries = list._raw.entries();
|
3264
|
-
const entry = entries[Number(key)];
|
3265
|
-
if (!entry) {
|
3266
|
-
return void 0;
|
3267
|
-
}
|
3268
|
-
const id = entry.value;
|
3269
|
-
if (id) {
|
3270
|
-
this.loadChildNode(id, depth, descriptor, key);
|
3271
|
-
this.validationErrors.delete(key);
|
3272
|
-
return id;
|
3273
|
-
} else if (!descriptor.optional) {
|
3274
|
-
this.validationErrors.set(
|
3275
|
-
key,
|
3276
|
-
new JazzError(void 0, "unavailable", [
|
3277
|
-
{
|
3278
|
-
code: "validationError",
|
3279
|
-
message: `The ref on position ${key} requested on ${list.constructor.name} is missing`,
|
3280
|
-
params: {},
|
3281
|
-
path: [key]
|
3282
|
-
}
|
3283
|
-
])
|
3284
|
-
);
|
3285
|
-
}
|
3286
|
-
return void 0;
|
3287
|
-
}
|
3288
|
-
loadChildNode(id, query, descriptor, key) {
|
3289
|
-
if (this.childValues.has(id)) {
|
3290
|
-
return;
|
3291
|
-
}
|
3292
|
-
if (key && this.autoloadedKeys.has(key)) {
|
3293
|
-
this.autoloaded.add(id);
|
3294
|
-
}
|
3295
|
-
const skipInvalid = typeof query === "object" && query.$onError === null;
|
3296
|
-
if (skipInvalid) {
|
3297
|
-
if (key) {
|
3298
|
-
this.skipInvalidKeys.add(key);
|
3299
|
-
}
|
3300
|
-
this.skipInvalidKeys.add(id);
|
3301
|
-
}
|
3302
|
-
const resolve = typeof query === "object" && query !== null ? { ...query } : query;
|
3303
|
-
this.childValues.set(id, { type: "unloaded", id });
|
3304
|
-
const child = new _SubscriptionScope(
|
3305
|
-
this.node,
|
3306
|
-
resolve,
|
3307
|
-
id,
|
3308
|
-
descriptor
|
3309
|
-
);
|
3310
|
-
this.childNodes.set(id, child);
|
3311
|
-
child.setListener((value) => this.handleChildUpdate(id, value, key));
|
3312
|
-
}
|
3313
|
-
destroy() {
|
3314
|
-
this.subscription.unsubscribe();
|
3315
|
-
this.subscribers.clear();
|
3316
|
-
this.childNodes.forEach((child) => child.destroy());
|
3317
|
-
}
|
3318
|
-
};
|
3319
|
-
|
3320
|
-
// src/subscribe/index.ts
|
3321
|
-
function getSubscriptionScope(value) {
|
3322
|
-
const subscriptionScope = value._subscriptionScope;
|
3323
|
-
if (subscriptionScope) {
|
3324
|
-
return subscriptionScope;
|
3325
|
-
}
|
3326
|
-
const node = value._raw.core.node;
|
3327
|
-
const resolve = true;
|
3328
|
-
const id = value.id;
|
3329
|
-
const newSubscriptionScope = new SubscriptionScope(node, resolve, id, {
|
3330
|
-
ref: value.constructor,
|
3331
|
-
optional: false
|
3332
|
-
});
|
3333
|
-
Object.defineProperty(value, "_subscriptionScope", {
|
3334
|
-
value: subscriptionScope,
|
3335
|
-
writable: false,
|
3336
|
-
enumerable: false,
|
3337
|
-
configurable: false
|
3338
|
-
});
|
3339
|
-
return newSubscriptionScope;
|
3340
|
-
}
|
3341
|
-
function accessChildByKey(parent, childId, key) {
|
3342
|
-
const subscriptionScope = getSubscriptionScope(parent);
|
3343
|
-
if (!subscriptionScope.childValues.has(childId)) {
|
3344
|
-
subscriptionScope.subscribeToKey(key);
|
3345
|
-
}
|
3346
|
-
const value = subscriptionScope.childValues.get(childId);
|
3347
|
-
if (value?.type === "loaded") {
|
3348
|
-
return value.value;
|
3349
|
-
} else {
|
3350
|
-
return null;
|
3351
|
-
}
|
3352
|
-
}
|
3353
|
-
function accessChildById(parent, childId, schema) {
|
3354
|
-
const subscriptionScope = getSubscriptionScope(parent);
|
3355
|
-
subscriptionScope.subscribeToId(childId, schema);
|
3356
|
-
const value = subscriptionScope.childValues.get(childId);
|
3357
|
-
if (value?.type === "loaded") {
|
3358
|
-
return value.value;
|
3359
|
-
} else {
|
3360
|
-
return null;
|
3361
|
-
}
|
3362
|
-
}
|
3363
|
-
|
3364
|
-
// src/implementation/createContext.ts
|
3365
|
-
import {
|
3366
|
-
LocalNode as LocalNode2
|
3367
|
-
} from "cojson";
|
3368
|
-
async function randomSessionProvider(accountID, crypto) {
|
3369
|
-
return {
|
3370
|
-
sessionID: crypto.newRandomSessionID(accountID),
|
3371
|
-
sessionDone: () => {
|
3372
|
-
}
|
3373
|
-
};
|
3374
|
-
}
|
3375
|
-
async function createJazzContextFromExistingCredentials({
|
3376
|
-
credentials,
|
3377
|
-
peersToLoadFrom,
|
3378
|
-
crypto,
|
3379
|
-
AccountSchema: PropsAccountSchema,
|
3380
|
-
sessionProvider,
|
3381
|
-
onLogOut
|
3382
|
-
}) {
|
3383
|
-
const { sessionID, sessionDone } = await sessionProvider(
|
3384
|
-
credentials.accountID,
|
3385
|
-
crypto
|
3386
|
-
);
|
3387
|
-
const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
|
3388
|
-
const AccountClass = anySchemaToCoSchema(CurrentAccountSchema);
|
3389
|
-
const node = await LocalNode2.withLoadedAccount({
|
3390
|
-
accountID: credentials.accountID,
|
3391
|
-
accountSecret: credentials.secret,
|
3392
|
-
sessionID,
|
3393
|
-
peersToLoadFrom,
|
3394
|
-
crypto,
|
3395
|
-
migration: async (rawAccount, _node, creationProps) => {
|
3396
|
-
const account2 = AccountClass.fromRaw(rawAccount);
|
3397
|
-
activeAccountContext.set(account2);
|
3398
|
-
await account2.applyMigration(creationProps);
|
3399
|
-
}
|
3400
|
-
});
|
3401
|
-
const account = AccountClass.fromNode(node);
|
3402
|
-
activeAccountContext.set(account);
|
3403
|
-
return {
|
3404
|
-
node,
|
3405
|
-
account,
|
3406
|
-
done: () => {
|
3407
|
-
node.gracefulShutdown();
|
3408
|
-
sessionDone();
|
3409
|
-
},
|
3410
|
-
logOut: async () => {
|
3411
|
-
node.gracefulShutdown();
|
3412
|
-
sessionDone();
|
3413
|
-
await onLogOut?.();
|
3414
|
-
}
|
3415
|
-
};
|
3416
|
-
}
|
3417
|
-
async function createJazzContextForNewAccount({
|
3418
|
-
creationProps,
|
3419
|
-
initialAgentSecret,
|
3420
|
-
peersToLoadFrom,
|
3421
|
-
crypto,
|
3422
|
-
AccountSchema: PropsAccountSchema,
|
3423
|
-
onLogOut
|
3424
|
-
}) {
|
3425
|
-
const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
|
3426
|
-
const AccountClass = anySchemaToCoSchema(CurrentAccountSchema);
|
3427
|
-
const { node } = await LocalNode2.withNewlyCreatedAccount({
|
3428
|
-
creationProps,
|
3429
|
-
peersToLoadFrom,
|
3430
|
-
crypto,
|
3431
|
-
initialAgentSecret,
|
3432
|
-
migration: async (rawAccount, _node, creationProps2) => {
|
3433
|
-
const account2 = AccountClass.fromRaw(rawAccount);
|
3434
|
-
activeAccountContext.set(account2);
|
3435
|
-
await account2.applyMigration(creationProps2);
|
3436
|
-
}
|
3437
|
-
});
|
3438
|
-
const account = AccountClass.fromNode(node);
|
3439
|
-
activeAccountContext.set(account);
|
3440
|
-
return {
|
3441
|
-
node,
|
3442
|
-
account,
|
3443
|
-
done: () => {
|
3444
|
-
node.gracefulShutdown();
|
3445
|
-
},
|
3446
|
-
logOut: async () => {
|
3447
|
-
node.gracefulShutdown();
|
3448
|
-
await onLogOut?.();
|
3449
|
-
}
|
3450
|
-
};
|
3451
|
-
}
|
3452
|
-
async function createJazzContext(options) {
|
3453
|
-
const crypto = options.crypto;
|
3454
|
-
let context;
|
3455
|
-
const authSecretStorage = options.authSecretStorage;
|
3456
|
-
await authSecretStorage.migrate();
|
3457
|
-
const credentials = options.credentials ?? await authSecretStorage.get();
|
3458
|
-
if (credentials && !options.newAccountProps) {
|
3459
|
-
context = await createJazzContextFromExistingCredentials({
|
3460
|
-
credentials: {
|
3461
|
-
accountID: credentials.accountID,
|
3462
|
-
secret: credentials.accountSecret
|
3463
|
-
},
|
3464
|
-
peersToLoadFrom: options.peersToLoadFrom,
|
3465
|
-
crypto,
|
3466
|
-
AccountSchema: options.AccountSchema,
|
3467
|
-
sessionProvider: options.sessionProvider,
|
3468
|
-
onLogOut: () => {
|
3469
|
-
authSecretStorage.clearWithoutNotify();
|
3470
|
-
}
|
3471
|
-
});
|
3472
|
-
} else {
|
3473
|
-
const secretSeed = options.crypto.newRandomSecretSeed();
|
3474
|
-
const initialAgentSecret = options.newAccountProps?.secret ?? crypto.agentSecretFromSecretSeed(secretSeed);
|
3475
|
-
const creationProps = options.newAccountProps?.creationProps ?? {
|
3476
|
-
name: options.defaultProfileName ?? "Anonymous user"
|
3477
|
-
};
|
3478
|
-
context = await createJazzContextForNewAccount({
|
3479
|
-
creationProps,
|
3480
|
-
initialAgentSecret,
|
3481
|
-
peersToLoadFrom: options.peersToLoadFrom,
|
3482
|
-
crypto,
|
3483
|
-
AccountSchema: options.AccountSchema,
|
3484
|
-
onLogOut: async () => {
|
3485
|
-
await authSecretStorage.clearWithoutNotify();
|
3486
|
-
}
|
3487
|
-
});
|
3488
|
-
if (!options.newAccountProps) {
|
3489
|
-
await authSecretStorage.setWithoutNotify({
|
3490
|
-
accountID: context.account.id,
|
3491
|
-
secretSeed,
|
3492
|
-
accountSecret: context.node.getCurrentAgent().agentSecret,
|
3493
|
-
provider: "anonymous"
|
3494
|
-
});
|
3495
|
-
}
|
3496
|
-
}
|
3497
|
-
return {
|
3498
|
-
...context,
|
3499
|
-
authSecretStorage
|
3500
|
-
};
|
3501
|
-
}
|
3502
|
-
function createAnonymousJazzContext({
|
3503
|
-
peersToLoadFrom,
|
3504
|
-
crypto
|
3505
|
-
}) {
|
3506
|
-
const agentSecret = crypto.newRandomAgentSecret();
|
3507
|
-
const node = new LocalNode2(
|
3508
|
-
agentSecret,
|
3509
|
-
crypto.newRandomSessionID(crypto.getAgentID(agentSecret)),
|
3510
|
-
crypto
|
3511
|
-
);
|
3512
|
-
for (const peer of peersToLoadFrom) {
|
3513
|
-
node.syncManager.addPeer(peer);
|
3514
|
-
}
|
3515
|
-
activeAccountContext.setGuestMode();
|
3516
|
-
return {
|
3517
|
-
agent: new AnonymousJazzAgent(node),
|
3518
|
-
done: () => {
|
3519
|
-
},
|
3520
|
-
logOut: async () => {
|
3521
|
-
}
|
3522
|
-
};
|
3523
|
-
}
|
3524
|
-
|
3525
|
-
// src/implementation/zodSchema/zodSchema.ts
|
3526
|
-
function isZodObject(schema) {
|
3527
|
-
return schema.def?.type === "object";
|
3528
|
-
}
|
3529
|
-
function isZodArray(schema) {
|
3530
|
-
return schema.def?.type === "array";
|
3531
|
-
}
|
3532
|
-
function isZodCustom(schema) {
|
3533
|
-
return schema.def?.type === "custom";
|
3534
|
-
}
|
3535
|
-
function getDef(schema) {
|
3536
|
-
return schema.def;
|
3537
|
-
}
|
3538
|
-
|
3539
|
-
// src/implementation/zodSchema/zodCo.ts
|
3540
|
-
function enrichCoMapSchema(schema) {
|
3541
|
-
const baseCatchall = schema.catchall;
|
3542
|
-
const enrichedSchema = Object.assign(schema, {
|
3543
|
-
collaborative: true,
|
3544
|
-
create: (...args) => {
|
3545
|
-
return coSchema.create(...args);
|
3546
|
-
},
|
3547
|
-
load: (...args) => {
|
3548
|
-
return coSchema.load(...args);
|
3549
|
-
},
|
3550
|
-
subscribe: (...args) => {
|
3551
|
-
return coSchema.subscribe(...args);
|
3552
|
-
},
|
3553
|
-
findUnique: (...args) => {
|
3554
|
-
return coSchema.findUnique(...args);
|
3555
|
-
},
|
3556
|
-
catchall: (index) => {
|
3557
|
-
return enrichCoMapSchema(baseCatchall(index));
|
3558
|
-
},
|
3559
|
-
withHelpers: (helpers) => {
|
3560
|
-
return Object.assign(schema, helpers(schema));
|
3561
|
-
},
|
3562
|
-
withMigration: (migration) => {
|
3563
|
-
coSchema.prototype.migrate = migration;
|
3564
|
-
return enrichedSchema;
|
3565
|
-
},
|
3566
|
-
getCoSchema: () => {
|
3567
|
-
return coSchema;
|
3568
|
-
}
|
3569
|
-
});
|
3570
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3571
|
-
return enrichedSchema;
|
3572
|
-
}
|
3573
|
-
var coMapDefiner = (shape) => {
|
3574
|
-
const objectSchema = z.object(shape).meta({
|
3575
|
-
collaborative: true
|
3576
|
-
});
|
3577
|
-
return enrichCoMapSchema(objectSchema);
|
3578
|
-
};
|
3579
|
-
function enrichAccountSchema(schema) {
|
3580
|
-
const enrichedSchema = Object.assign(schema, {
|
3581
|
-
collaborative: true,
|
3582
|
-
builtin: "Account",
|
3583
|
-
create: (...args) => {
|
3584
|
-
return coSchema.create(...args);
|
3585
|
-
},
|
3586
|
-
createAs: (...args) => {
|
3587
|
-
return coSchema.createAs(...args);
|
3588
|
-
},
|
3589
|
-
getMe: (...args) => {
|
3590
|
-
return coSchema.getMe(...args);
|
3591
|
-
},
|
3592
|
-
load: (...args) => {
|
3593
|
-
return coSchema.load(...args);
|
3594
|
-
},
|
3595
|
-
subscribe: (...args) => {
|
3596
|
-
return coSchema.subscribe(...args);
|
3597
|
-
},
|
3598
|
-
withHelpers: (helpers) => {
|
3599
|
-
return Object.assign(schema, helpers(schema));
|
3600
|
-
},
|
3601
|
-
fromRaw: (...args) => {
|
3602
|
-
return coSchema.fromRaw(...args);
|
3603
|
-
},
|
3604
|
-
withMigration: (migration) => {
|
3605
|
-
coSchema.prototype.migrate = async function(creationProps) {
|
3606
|
-
await migration(this, creationProps);
|
3607
|
-
};
|
3608
|
-
return enrichedSchema;
|
3609
|
-
},
|
3610
|
-
getCoSchema: () => {
|
3611
|
-
return coSchema;
|
3612
|
-
}
|
3613
|
-
});
|
3614
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3615
|
-
return enrichedSchema;
|
3616
|
-
}
|
3617
|
-
var coAccountDefiner = (shape = {
|
3618
|
-
profile: coMapDefiner({
|
3619
|
-
name: z.string(),
|
3620
|
-
inbox: z.optional(z.string()),
|
3621
|
-
inboxInvite: z.optional(z.string())
|
3622
|
-
}),
|
3623
|
-
root: coMapDefiner({})
|
3624
|
-
}) => {
|
3625
|
-
const objectSchema = z.object(shape).meta({
|
3626
|
-
collaborative: true
|
3627
|
-
});
|
3628
|
-
return enrichAccountSchema(objectSchema);
|
3629
|
-
};
|
3630
|
-
var coRecordDefiner = (_keyType, valueType) => {
|
3631
|
-
return coMapDefiner({}).catchall(valueType);
|
3632
|
-
};
|
3633
|
-
function enrichCoListSchema(schema) {
|
3634
|
-
const enrichedSchema = Object.assign(schema, {
|
3635
|
-
collaborative: true,
|
3636
|
-
create: (...args) => {
|
3637
|
-
return coSchema.create(...args);
|
3638
|
-
},
|
3639
|
-
load: (...args) => {
|
3640
|
-
return coSchema.load(...args);
|
3641
|
-
},
|
3642
|
-
subscribe: (...args) => {
|
3643
|
-
return coSchema.subscribe(...args);
|
3644
|
-
},
|
3645
|
-
withHelpers: (helpers) => {
|
3646
|
-
return Object.assign(schema, helpers(schema));
|
3647
|
-
},
|
3648
|
-
getCoSchema: () => {
|
3649
|
-
return coSchema;
|
3650
|
-
}
|
3651
|
-
});
|
3652
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3653
|
-
return enrichedSchema;
|
3654
|
-
}
|
3655
|
-
var coListDefiner = (element) => {
|
3656
|
-
const arraySchema = z.array(element).meta({
|
3657
|
-
collaborative: true
|
3658
|
-
});
|
3659
|
-
return enrichCoListSchema(arraySchema);
|
3660
|
-
};
|
3661
|
-
var coProfileDefiner = (shape = {}) => {
|
3662
|
-
const ehnancedShape = Object.assign(shape ?? {}, {
|
3663
|
-
name: z.string(),
|
3664
|
-
inbox: z.optional(z.string()),
|
3665
|
-
inboxInvite: z.optional(z.string())
|
3666
|
-
});
|
3667
|
-
return coMapDefiner(ehnancedShape);
|
3668
|
-
};
|
3669
|
-
function enrichCoFeedSchema(schema, element) {
|
3670
|
-
const enrichedSchema = Object.assign(schema, {
|
3671
|
-
collaborative: true,
|
3672
|
-
builtin: "CoFeed",
|
3673
|
-
element,
|
3674
|
-
create: (...args) => {
|
3675
|
-
return coSchema.create(...args);
|
3676
|
-
},
|
3677
|
-
load: (...args) => {
|
3678
|
-
return coSchema.load(...args);
|
3679
|
-
},
|
3680
|
-
subscribe: (...args) => {
|
3681
|
-
return coSchema.subscribe(...args);
|
3682
|
-
},
|
3683
|
-
withHelpers: (helpers) => {
|
3684
|
-
return Object.assign(schema, helpers(schema));
|
3685
|
-
},
|
3686
|
-
getCoSchema: () => {
|
3687
|
-
return coSchema;
|
3688
|
-
}
|
3689
|
-
});
|
3690
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3691
|
-
return enrichedSchema;
|
3692
|
-
}
|
3693
|
-
var coFeedDefiner = (element) => {
|
3694
|
-
return enrichCoFeedSchema(z.instanceof(CoFeed), element);
|
3695
|
-
};
|
3696
|
-
function enrichFileStreamSchema(schema) {
|
3697
|
-
const enrichedSchema = Object.assign(schema, {
|
3698
|
-
collaborative: true,
|
3699
|
-
builtin: "FileStream",
|
3700
|
-
create: (...args) => {
|
3701
|
-
return coSchema.create(...args);
|
3702
|
-
},
|
3703
|
-
createFromBlob: (...args) => {
|
3704
|
-
return coSchema.createFromBlob(...args);
|
3705
|
-
},
|
3706
|
-
load: (...args) => {
|
3707
|
-
return coSchema.load(...args);
|
3708
|
-
},
|
3709
|
-
loadAsBlob: (...args) => {
|
3710
|
-
return coSchema.loadAsBlob(...args);
|
3711
|
-
},
|
3712
|
-
subscribe: (...args) => {
|
3713
|
-
return coSchema.subscribe(...args);
|
3714
|
-
},
|
3715
|
-
getCoSchema: () => {
|
3716
|
-
return coSchema;
|
3717
|
-
}
|
3718
|
-
});
|
3719
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3720
|
-
return enrichedSchema;
|
3721
|
-
}
|
3722
|
-
var coFileStreamDefiner = () => {
|
3723
|
-
return enrichFileStreamSchema(z.instanceof(FileStream));
|
3724
|
-
};
|
3725
|
-
function enrichPlainTextSchema(schema) {
|
3726
|
-
const enrichedSchema = Object.assign(schema, {
|
3727
|
-
collaborative: true,
|
3728
|
-
builtin: "CoPlainText",
|
3729
|
-
create: (...args) => {
|
3730
|
-
return coSchema.create(...args);
|
3731
|
-
},
|
3732
|
-
load: (...args) => {
|
3733
|
-
return coSchema.load(...args);
|
3734
|
-
},
|
3735
|
-
subscribe: (...args) => {
|
3736
|
-
return coSchema.subscribe(...args);
|
3737
|
-
},
|
3738
|
-
fromRaw: (...args) => {
|
3739
|
-
return coSchema.fromRaw(...args);
|
3740
|
-
},
|
3741
|
-
getCoSchema: () => {
|
3742
|
-
return coSchema;
|
3743
|
-
}
|
3744
|
-
});
|
3745
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3746
|
-
return enrichedSchema;
|
3747
|
-
}
|
3748
|
-
var coPlainTextDefiner = () => {
|
3749
|
-
return enrichPlainTextSchema(z.instanceof(CoPlainText));
|
3750
|
-
};
|
3751
|
-
function enrichRichTextSchema(schema) {
|
3752
|
-
const enrichedSchema = Object.assign(schema, {
|
3753
|
-
collaborative: true,
|
3754
|
-
builtin: "CoRichText",
|
3755
|
-
create: (...args) => {
|
3756
|
-
return coSchema.create(...args);
|
3757
|
-
},
|
3758
|
-
load: (...args) => {
|
3759
|
-
return coSchema.load(...args);
|
3760
|
-
},
|
3761
|
-
subscribe: (...args) => {
|
3762
|
-
return coSchema.subscribe(...args);
|
3763
|
-
},
|
3764
|
-
getCoSchema: () => {
|
3765
|
-
return coSchema;
|
3766
|
-
}
|
3767
|
-
});
|
3768
|
-
const coSchema = zodSchemaToCoSchema2(enrichedSchema);
|
3769
|
-
return enrichedSchema;
|
3770
|
-
}
|
3771
|
-
var coRichTextDefiner = () => {
|
3772
|
-
return enrichRichTextSchema(z.instanceof(CoRichText));
|
3773
|
-
};
|
3774
|
-
var coImageDefiner = () => {
|
3775
|
-
return ImageDefinition;
|
3776
|
-
};
|
3777
|
-
|
3778
|
-
// src/implementation/zodSchema/coExport.ts
|
3779
|
-
var coExport_exports = {};
|
3780
|
-
__export(coExport_exports, {
|
3781
|
-
account: () => coAccountDefiner,
|
3782
|
-
feed: () => coFeedDefiner,
|
3783
|
-
fileStream: () => coFileStreamDefiner,
|
3784
|
-
image: () => coImageDefiner,
|
3785
|
-
list: () => coListDefiner,
|
3786
|
-
map: () => coMapDefiner,
|
3787
|
-
plainText: () => coPlainTextDefiner,
|
3788
|
-
profile: () => coProfileDefiner,
|
3789
|
-
record: () => coRecordDefiner,
|
3790
|
-
richText: () => coRichTextDefiner
|
3791
|
-
});
|
3792
|
-
|
3793
|
-
// src/implementation/zodSchema/unionUtils.ts
|
3794
|
-
import { RawCoList } from "cojson";
|
3795
|
-
function schemaUnionDiscriminatorFor(schema) {
|
3796
|
-
if (isUnionOfCoMapsDeeply(schema)) {
|
3797
|
-
if (!schema._zod.disc || schema._zod.disc.size == 0) {
|
3798
|
-
throw new Error(
|
3799
|
-
"z.union() of collaborative types is not supported, use z.discriminatedUnion() instead"
|
3800
|
-
);
|
3801
|
-
}
|
3802
|
-
const discriminator = schema._zod.def.discriminator;
|
3803
|
-
const field = schema._zod.disc.get(discriminator);
|
3804
|
-
if (!field) {
|
3805
|
-
throw new Error(
|
3806
|
-
"z.discriminatedUnion() of collaborative types with non-existent discriminator key is not supported"
|
3807
|
-
);
|
3808
|
-
}
|
3809
|
-
for (const value of field.values) {
|
3810
|
-
if (typeof value !== "string" && typeof value !== "number") {
|
3811
|
-
throw new Error(
|
3812
|
-
"z.discriminatedUnion() of collaborative types with non-string or non-number discriminator value is not supported"
|
3813
|
-
);
|
3814
|
-
}
|
3815
|
-
}
|
3816
|
-
const availableOptions = [];
|
3817
|
-
for (const option of schema._zod.def.options) {
|
3818
|
-
if (option._zod.def.type === "object") {
|
3819
|
-
availableOptions.push(option);
|
3820
|
-
} else if (option._zod.def.type === "union") {
|
3821
|
-
for (const subOption of option._zod.def.options) {
|
3822
|
-
if (subOption._zod.def.type === "object") {
|
3823
|
-
availableOptions.push(subOption);
|
3824
|
-
}
|
3825
|
-
}
|
3826
|
-
} else {
|
3827
|
-
throw new Error(
|
3828
|
-
"Unsupported zod type in z.discriminatedUnion() of collaborative types"
|
3829
|
-
);
|
3830
|
-
}
|
3831
|
-
}
|
3832
|
-
const determineSchema = (_raw) => {
|
3833
|
-
if (_raw instanceof RawCoList) {
|
3834
|
-
throw new Error(
|
3835
|
-
"z.discriminatedUnion() of collaborative types is not supported for CoLists"
|
3836
|
-
);
|
3837
|
-
}
|
3838
|
-
for (const option of availableOptions) {
|
3839
|
-
let match = true;
|
3840
|
-
for (const key of schema._zod.disc.keys()) {
|
3841
|
-
const discriminatorDef = option._zod.def.shape[key];
|
3842
|
-
const discriminatorValue = _raw.get(key);
|
3843
|
-
if (discriminatorValue && typeof discriminatorValue === "object") {
|
3844
|
-
throw new Error("Discriminator must be a primitive value");
|
3845
|
-
}
|
3846
|
-
if (!discriminatorDef) {
|
3847
|
-
if (key === discriminator) {
|
3848
|
-
match = false;
|
3849
|
-
break;
|
3850
|
-
} else {
|
3851
|
-
continue;
|
3852
|
-
}
|
3853
|
-
}
|
3854
|
-
if (discriminatorDef._zod.def.type !== "literal") {
|
3855
|
-
break;
|
3856
|
-
}
|
3857
|
-
const literalDef = discriminatorDef._zod.def;
|
3858
|
-
if (!Array.from(literalDef.values).includes(discriminatorValue)) {
|
3859
|
-
match = false;
|
3860
|
-
break;
|
3861
|
-
}
|
3862
|
-
}
|
3863
|
-
if (match) {
|
3864
|
-
return zodSchemaToCoSchema2(option);
|
3865
|
-
}
|
3866
|
-
}
|
3867
|
-
throw new Error(
|
3868
|
-
"z.discriminatedUnion() of collaborative types with no matching discriminator value found"
|
3869
|
-
);
|
3870
|
-
};
|
3871
|
-
return determineSchema;
|
3872
|
-
} else {
|
3873
|
-
throw new Error(
|
3874
|
-
"z.discriminatedUnion() of non-collaborative types is not supported"
|
3875
|
-
);
|
3876
|
-
}
|
3877
|
-
}
|
3878
|
-
function isUnionOfCoMapsDeeply(schema) {
|
3879
|
-
if (schema instanceof z.core.$ZodUnion) {
|
3880
|
-
return schema._zod.def.options.every(isCoMapOrUnionOfCoMapsDeeply);
|
3881
|
-
} else {
|
3882
|
-
return false;
|
3883
|
-
}
|
3884
|
-
}
|
3885
|
-
function isCoMapOrUnionOfCoMapsDeeply(schema) {
|
3886
|
-
if (schema instanceof z.core.$ZodObject && "collaborative" in schema && schema.collaborative) {
|
3887
|
-
return true;
|
3888
|
-
} else if (schema instanceof z.core.$ZodUnion) {
|
3889
|
-
return schema._zod.def.options.every(isCoMapOrUnionOfCoMapsDeeply);
|
3890
|
-
} else {
|
3891
|
-
return false;
|
3892
|
-
}
|
3893
|
-
}
|
3894
|
-
function isUnionOfPrimitivesDeeply(schema) {
|
3895
|
-
if (schema instanceof z.core.$ZodUnion) {
|
3896
|
-
return schema._zod.def.options.every(isUnionOfPrimitivesDeeply);
|
3897
|
-
} else {
|
3898
|
-
return !("collaborative" in schema);
|
3899
|
-
}
|
3900
|
-
}
|
3901
|
-
|
3902
|
-
// src/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts
|
3903
|
-
function zodFieldToCoFieldDef(schema) {
|
3904
|
-
if (isCoValueClass(schema)) {
|
3905
|
-
return coField.ref(schema);
|
3906
|
-
} else {
|
3907
|
-
if ("_zod" in schema) {
|
3908
|
-
if (schema._zod.def.type === "optional") {
|
3909
|
-
const inner = zodSchemaToCoSchemaOrKeepPrimitive(
|
3910
|
-
schema._zod.def.innerType
|
3911
|
-
);
|
3912
|
-
if (isCoValueClass(inner)) {
|
3913
|
-
return coField.ref(inner, { optional: true });
|
3914
|
-
} else {
|
3915
|
-
return zodFieldToCoFieldDef(inner);
|
3916
|
-
}
|
3917
|
-
} else if (schema._zod.def.type === "string") {
|
3918
|
-
return coField.string;
|
3919
|
-
} else if (schema._zod.def.type === "number") {
|
3920
|
-
return coField.number;
|
3921
|
-
} else if (schema._zod.def.type === "boolean") {
|
3922
|
-
return coField.boolean;
|
3923
|
-
} else if (schema._zod.def.type === "null") {
|
3924
|
-
return coField.null;
|
3925
|
-
} else if (schema._zod.def.type === "enum") {
|
3926
|
-
return coField.string;
|
3927
|
-
} else if (schema._zod.def.type === "readonly") {
|
3928
|
-
return zodFieldToCoFieldDef(
|
3929
|
-
schema.def.innerType
|
3930
|
-
);
|
3931
|
-
} else if (schema._zod.def.type === "date") {
|
3932
|
-
return coField.optional.Date;
|
3933
|
-
} else if (schema._zod.def.type === "template_literal") {
|
3934
|
-
return coField.string;
|
3935
|
-
} else if (schema._zod.def.type === "lazy") {
|
3936
|
-
return zodFieldToCoFieldDef(
|
3937
|
-
schema.unwrap()
|
3938
|
-
);
|
3939
|
-
} else if (schema._zod.def.type === "default" || schema._zod.def.type === "catch") {
|
3940
|
-
console.warn(
|
3941
|
-
"z.default()/z.catch() are not supported in collaborative schemas. They will be ignored."
|
3942
|
-
);
|
3943
|
-
return zodFieldToCoFieldDef(
|
3944
|
-
schema.def.innerType
|
3945
|
-
);
|
3946
|
-
} else if (schema._zod.def.type === "literal") {
|
3947
|
-
if (schema._zod.def.values.some(
|
3948
|
-
(literal2) => typeof literal2 === "undefined"
|
3949
|
-
)) {
|
3950
|
-
throw new Error("z.literal() with undefined is not supported");
|
3951
|
-
}
|
3952
|
-
if (schema._zod.def.values.some((literal2) => literal2 === null)) {
|
3953
|
-
throw new Error("z.literal() with null is not supported");
|
3954
|
-
}
|
3955
|
-
if (schema._zod.def.values.some((literal2) => typeof literal2 === "bigint")) {
|
3956
|
-
throw new Error("z.literal() with bigint is not supported");
|
3957
|
-
}
|
3958
|
-
return coField.literal(
|
3959
|
-
...schema._zod.def.values
|
3960
|
-
);
|
3961
|
-
} else if (schema._zod.def.type === "object" || schema._zod.def.type === "array" || schema._zod.def.type === "tuple") {
|
3962
|
-
return coField.json();
|
3963
|
-
} else if (schema._zod.def.type === "custom") {
|
3964
|
-
if ("builtin" in schema) {
|
3965
|
-
return zodFieldToCoFieldDef(schema.builtin);
|
3966
|
-
} else {
|
3967
|
-
throw new Error(`Unsupported custom zod type`);
|
3968
|
-
}
|
3969
|
-
} else if (schema._zod.def.type === "union") {
|
3970
|
-
if (isUnionOfPrimitivesDeeply(schema)) {
|
3971
|
-
return coField.json();
|
3972
|
-
} else if (isUnionOfCoMapsDeeply(schema)) {
|
3973
|
-
return coField.ref(
|
3974
|
-
schemaUnionDiscriminatorFor(schema)
|
3975
|
-
);
|
3976
|
-
} else {
|
3977
|
-
throw new Error(
|
3978
|
-
"z.union()/z.discriminatedUnion() of mixed collaborative and non-collaborative types is not supported"
|
3979
|
-
);
|
3980
|
-
}
|
3981
|
-
} else {
|
3982
|
-
throw new Error(
|
3983
|
-
`Unsupported zod type: ${schema._zod?.def?.type || JSON.stringify(schema)}`
|
3984
|
-
);
|
3985
|
-
}
|
3986
|
-
} else {
|
3987
|
-
throw new Error(`Unsupported zod type: ${schema}`);
|
3988
|
-
}
|
3989
|
-
}
|
3990
|
-
}
|
3991
|
-
|
3992
|
-
// src/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts
|
3993
|
-
var coSchemasForZodSchemas = /* @__PURE__ */ new Map();
|
3994
|
-
function tryZodSchemaToCoSchema(schema) {
|
3995
|
-
if ("collaborative" in schema && schema.collaborative) {
|
3996
|
-
if (coSchemasForZodSchemas.has(schema)) {
|
3997
|
-
return coSchemasForZodSchemas.get(schema);
|
3998
|
-
}
|
3999
|
-
if (isZodObject(schema)) {
|
4000
|
-
const def = getDef(schema);
|
4001
|
-
const ClassToExtend = "builtin" in schema && schema.builtin === "Account" ? Account : CoMap;
|
4002
|
-
const coSchema = class ZCoMap extends ClassToExtend {
|
4003
|
-
constructor(options) {
|
4004
|
-
super(options);
|
4005
|
-
for (const [field, fieldType] of Object.entries(
|
4006
|
-
def.shape
|
4007
|
-
)) {
|
4008
|
-
this[field] = zodFieldToCoFieldDef(
|
4009
|
-
zodSchemaToCoSchemaOrKeepPrimitive(fieldType)
|
4010
|
-
);
|
4011
|
-
}
|
4012
|
-
if (def.catchall) {
|
4013
|
-
this[coField.items] = zodFieldToCoFieldDef(
|
4014
|
-
zodSchemaToCoSchemaOrKeepPrimitive(def.catchall)
|
4015
|
-
);
|
4016
|
-
}
|
4017
|
-
}
|
4018
|
-
};
|
4019
|
-
coSchemasForZodSchemas.set(schema, coSchema);
|
4020
|
-
return coSchema;
|
4021
|
-
} else if (isZodArray(schema)) {
|
4022
|
-
const def = getDef(schema);
|
4023
|
-
const coSchema = class ZCoList extends CoList {
|
4024
|
-
constructor(options) {
|
4025
|
-
super(options);
|
4026
|
-
this[coField.items] = zodFieldToCoFieldDef(
|
4027
|
-
zodSchemaToCoSchemaOrKeepPrimitive(def.element)
|
4028
|
-
);
|
4029
|
-
}
|
4030
|
-
};
|
4031
|
-
coSchemasForZodSchemas.set(schema, coSchema);
|
4032
|
-
return coSchema;
|
4033
|
-
} else if (isZodCustom(schema)) {
|
4034
|
-
if ("builtin" in schema) {
|
4035
|
-
if (schema.builtin === "CoFeed" && "element" in schema) {
|
4036
|
-
return CoFeed.Of(
|
4037
|
-
zodFieldToCoFieldDef(
|
4038
|
-
zodSchemaToCoSchemaOrKeepPrimitive(
|
4039
|
-
schema.element
|
4040
|
-
)
|
4041
|
-
)
|
4042
|
-
);
|
4043
|
-
} else if (schema.builtin === "FileStream") {
|
4044
|
-
return FileStream;
|
4045
|
-
} else if (schema.builtin === "CoPlainText") {
|
4046
|
-
return CoPlainText;
|
4047
|
-
} else if (schema.builtin === "CoRichText") {
|
4048
|
-
return CoRichText;
|
4049
|
-
} else {
|
4050
|
-
throw new Error(`Unsupported builtin type: ${schema.builtin}`);
|
4051
|
-
}
|
4052
|
-
} else {
|
4053
|
-
throw new Error(`Unsupported custom zod type`);
|
4054
|
-
}
|
4055
|
-
} else {
|
4056
|
-
throw new Error(
|
4057
|
-
`Unsupported zod CoValue type for top-level schema: ${schema._zod?.def?.type || JSON.stringify(schema, void 0, 2)}`
|
4058
|
-
);
|
4059
|
-
}
|
4060
|
-
} else if (schema instanceof z.core.$ZodDiscriminatedUnion) {
|
4061
|
-
if (isUnionOfCoMapsDeeply(schema)) {
|
4062
|
-
return SchemaUnion.Of(
|
4063
|
-
schemaUnionDiscriminatorFor(schema)
|
4064
|
-
);
|
4065
|
-
} else {
|
4066
|
-
throw new Error(
|
4067
|
-
"z.discriminatedUnion() of non-collaborative types is not supported as a top-level schema"
|
4068
|
-
);
|
4069
|
-
}
|
4070
|
-
} else {
|
4071
|
-
return null;
|
4072
|
-
}
|
4073
|
-
}
|
4074
|
-
function zodSchemaToCoSchema2(schema) {
|
4075
|
-
const coSchema = tryZodSchemaToCoSchema(schema);
|
4076
|
-
if (!coSchema) {
|
4077
|
-
throw new Error(
|
4078
|
-
`Unsupported zod type: ${schema._zod?.def?.type || JSON.stringify(schema)}`
|
4079
|
-
);
|
4080
|
-
}
|
4081
|
-
return coSchema;
|
4082
|
-
}
|
4083
|
-
function anySchemaToCoSchema(schema) {
|
4084
|
-
if (isCoValueClass(schema)) {
|
4085
|
-
return schema;
|
4086
|
-
} else if ("getCoSchema" in schema) {
|
4087
|
-
return schema.getCoSchema();
|
4088
|
-
} else if ("def" in schema) {
|
4089
|
-
const coSchema = tryZodSchemaToCoSchema(schema);
|
4090
|
-
if (!coSchema) {
|
4091
|
-
throw new Error(
|
4092
|
-
`Unsupported zod type: ${schema.def?.type || JSON.stringify(schema)}`
|
4093
|
-
);
|
4094
|
-
}
|
4095
|
-
return coSchema;
|
4096
|
-
}
|
4097
|
-
throw new Error(`Unsupported schema: ${JSON.stringify(schema)}`);
|
4098
|
-
}
|
4099
|
-
function zodSchemaToCoSchemaOrKeepPrimitive(schema) {
|
4100
|
-
const coSchema = tryZodSchemaToCoSchema(schema);
|
4101
|
-
if (!coSchema) {
|
4102
|
-
return schema;
|
4103
|
-
}
|
4104
|
-
return coSchema;
|
4105
|
-
}
|
4106
|
-
|
4107
|
-
// src/coValues/extensions/imageDef.ts
|
4108
|
-
var ImageDefinitionBase = coMapDefiner({
|
4109
|
-
originalSize: z.tuple([z.number(), z.number()]),
|
4110
|
-
placeholderDataURL: z.string().optional()
|
4111
|
-
}).catchall(coFileStreamDefiner());
|
4112
|
-
var ImageDefinition = ImageDefinitionBase.withHelpers((Self) => ({
|
4113
|
-
highestResAvailable(imageDef, options) {
|
4114
|
-
const resolutions = Object.keys(imageDef).filter(
|
4115
|
-
(key) => key.match(/^\d+x\d+$/)
|
4116
|
-
);
|
4117
|
-
let maxWidth = options?.maxWidth;
|
4118
|
-
if (options?.targetWidth) {
|
4119
|
-
const targetWidth = options.targetWidth;
|
4120
|
-
const widths = resolutions.map((res) => Number(res.split("x")[0]));
|
4121
|
-
maxWidth = Math.min(...widths.filter((w) => w >= targetWidth));
|
4122
|
-
}
|
4123
|
-
const validResolutions = resolutions.filter(
|
4124
|
-
(key) => maxWidth === void 0 || Number(key.split("x")[0]) <= maxWidth
|
4125
|
-
);
|
4126
|
-
validResolutions.sort((a, b) => {
|
4127
|
-
const aWidth = Number(a.split("x")[0]);
|
4128
|
-
const bWidth = Number(b.split("x")[0]);
|
4129
|
-
return aWidth - bWidth;
|
4130
|
-
});
|
4131
|
-
let highestAvailableResolution;
|
4132
|
-
for (const resolution of validResolutions) {
|
4133
|
-
if (imageDef[resolution] && imageDef[resolution]?.getChunks()) {
|
4134
|
-
highestAvailableResolution = resolution;
|
4135
|
-
}
|
4136
|
-
}
|
4137
|
-
return highestAvailableResolution && {
|
4138
|
-
res: highestAvailableResolution,
|
4139
|
-
stream: imageDef[highestAvailableResolution]
|
4140
|
-
};
|
4141
|
-
}
|
4142
|
-
}));
|
4143
|
-
|
4144
|
-
// src/implementation/ContextManager.ts
|
4145
|
-
import { cojsonInternals as cojsonInternals4 } from "cojson";
|
4146
|
-
import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
|
4147
|
-
|
4148
|
-
// src/auth/KvStoreContext.ts
|
4149
|
-
var KvStoreContext = class _KvStoreContext {
|
4150
|
-
constructor() {
|
4151
|
-
this.storageInstance = null;
|
4152
|
-
}
|
4153
|
-
static getInstance() {
|
4154
|
-
if (!_KvStoreContext.instance) {
|
4155
|
-
_KvStoreContext.instance = new _KvStoreContext();
|
4156
|
-
}
|
4157
|
-
return _KvStoreContext.instance;
|
4158
|
-
}
|
4159
|
-
isInitialized() {
|
4160
|
-
return this.storageInstance !== null;
|
4161
|
-
}
|
4162
|
-
initialize(store) {
|
4163
|
-
if (!this.storageInstance) {
|
4164
|
-
this.storageInstance = store;
|
4165
|
-
}
|
4166
|
-
}
|
4167
|
-
getStorage() {
|
4168
|
-
if (!this.storageInstance) {
|
4169
|
-
throw new Error("Storage instance is not initialized.");
|
4170
|
-
}
|
4171
|
-
return this.storageInstance;
|
4172
|
-
}
|
4173
|
-
};
|
4174
|
-
var KvStoreContext_default = KvStoreContext;
|
4175
|
-
|
4176
|
-
// src/auth/AuthSecretStorage.ts
|
4177
|
-
var STORAGE_KEY = "jazz-logged-in-secret";
|
4178
|
-
var AuthSecretStorage = class {
|
4179
|
-
constructor() {
|
4180
|
-
this.listeners = /* @__PURE__ */ new Set();
|
4181
|
-
this.isAuthenticated = false;
|
4182
|
-
}
|
4183
|
-
async migrate() {
|
4184
|
-
const kvStore = KvStoreContext_default.getInstance().getStorage();
|
4185
|
-
if (!await kvStore.get(STORAGE_KEY)) {
|
4186
|
-
const demoAuthSecret = await kvStore.get("demo-auth-logged-in-secret");
|
4187
|
-
if (demoAuthSecret) {
|
4188
|
-
const parsed = JSON.parse(demoAuthSecret);
|
4189
|
-
await kvStore.set(
|
4190
|
-
STORAGE_KEY,
|
4191
|
-
JSON.stringify({
|
4192
|
-
accountID: parsed.accountID,
|
4193
|
-
accountSecret: parsed.accountSecret,
|
4194
|
-
provider: "demo"
|
4195
|
-
})
|
4196
|
-
);
|
4197
|
-
await kvStore.delete("demo-auth-logged-in-secret");
|
4198
|
-
}
|
4199
|
-
const clerkAuthSecret = await kvStore.get("jazz-clerk-auth");
|
4200
|
-
if (clerkAuthSecret) {
|
4201
|
-
const parsed = JSON.parse(clerkAuthSecret);
|
4202
|
-
await kvStore.set(
|
4203
|
-
STORAGE_KEY,
|
4204
|
-
JSON.stringify({
|
4205
|
-
accountID: parsed.accountID,
|
4206
|
-
accountSecret: parsed.secret,
|
4207
|
-
provider: "clerk"
|
4208
|
-
})
|
4209
|
-
);
|
4210
|
-
await kvStore.delete("jazz-clerk-auth");
|
4211
|
-
}
|
4212
|
-
}
|
4213
|
-
const value = await kvStore.get(STORAGE_KEY);
|
4214
|
-
if (value) {
|
4215
|
-
const parsed = JSON.parse(value);
|
4216
|
-
if ("secret" in parsed) {
|
4217
|
-
await kvStore.set(
|
4218
|
-
STORAGE_KEY,
|
4219
|
-
JSON.stringify({
|
4220
|
-
accountID: parsed.accountID,
|
4221
|
-
secretSeed: parsed.secretSeed,
|
4222
|
-
accountSecret: parsed.secret,
|
4223
|
-
provider: parsed.provider
|
4224
|
-
})
|
4225
|
-
);
|
4226
|
-
}
|
4227
|
-
}
|
4228
|
-
}
|
4229
|
-
async get() {
|
4230
|
-
const kvStore = KvStoreContext_default.getInstance().getStorage();
|
4231
|
-
const data = await kvStore.get(STORAGE_KEY);
|
4232
|
-
if (!data) return null;
|
4233
|
-
const parsed = JSON.parse(data);
|
4234
|
-
if (!parsed.accountID || !parsed.accountSecret) {
|
4235
|
-
throw new Error("Invalid auth secret storage data");
|
4236
|
-
}
|
4237
|
-
return {
|
4238
|
-
accountID: parsed.accountID,
|
4239
|
-
secretSeed: parsed.secretSeed ? new Uint8Array(parsed.secretSeed) : void 0,
|
4240
|
-
accountSecret: parsed.accountSecret,
|
4241
|
-
provider: parsed.provider
|
4242
|
-
};
|
4243
|
-
}
|
4244
|
-
async setWithoutNotify(payload) {
|
4245
|
-
const kvStore = KvStoreContext_default.getInstance().getStorage();
|
4246
|
-
await kvStore.set(
|
4247
|
-
STORAGE_KEY,
|
4248
|
-
JSON.stringify({
|
4249
|
-
accountID: payload.accountID,
|
4250
|
-
secretSeed: payload.secretSeed ? Array.from(payload.secretSeed) : void 0,
|
4251
|
-
accountSecret: payload.accountSecret,
|
4252
|
-
provider: payload.provider
|
4253
|
-
})
|
4254
|
-
);
|
4255
|
-
}
|
4256
|
-
async set(payload) {
|
4257
|
-
this.setWithoutNotify(payload);
|
4258
|
-
this.emitUpdate(payload);
|
4259
|
-
}
|
4260
|
-
getIsAuthenticated(data) {
|
4261
|
-
if (!data) return false;
|
4262
|
-
return data.provider !== "anonymous";
|
4263
|
-
}
|
4264
|
-
onUpdate(handler) {
|
4265
|
-
this.listeners.add(handler);
|
4266
|
-
return () => {
|
4267
|
-
this.listeners.delete(handler);
|
4268
|
-
};
|
4269
|
-
}
|
4270
|
-
emitUpdate(data) {
|
4271
|
-
const isAuthenticated = this.getIsAuthenticated(data);
|
4272
|
-
if (this.isAuthenticated === isAuthenticated) return;
|
4273
|
-
this.isAuthenticated = isAuthenticated;
|
4274
|
-
for (const listener of this.listeners) {
|
4275
|
-
listener(this.isAuthenticated);
|
4276
|
-
}
|
4277
|
-
}
|
4278
|
-
async clearWithoutNotify() {
|
4279
|
-
const kvStore = KvStoreContext_default.getInstance().getStorage();
|
4280
|
-
await kvStore.delete(STORAGE_KEY);
|
4281
|
-
}
|
4282
|
-
async clear() {
|
4283
|
-
await this.clearWithoutNotify();
|
4284
|
-
this.emitUpdate(null);
|
4285
|
-
}
|
4286
|
-
};
|
4287
|
-
|
4288
|
-
// src/auth/InMemoryKVStore.ts
|
4289
|
-
var InMemoryKVStore = class {
|
4290
|
-
constructor() {
|
4291
|
-
this.store = {};
|
4292
|
-
}
|
4293
|
-
async get(key) {
|
4294
|
-
const data = this.store[key];
|
4295
|
-
if (!data) return null;
|
4296
|
-
return data;
|
4297
|
-
}
|
4298
|
-
async set(key, value) {
|
4299
|
-
this.store[key] = value;
|
4300
|
-
}
|
4301
|
-
async delete(key) {
|
4302
|
-
delete this.store[key];
|
4303
|
-
}
|
4304
|
-
async clearAll() {
|
4305
|
-
this.store = {};
|
4306
|
-
}
|
4307
|
-
};
|
4308
|
-
|
4309
|
-
// src/implementation/ContextManager.ts
|
4310
|
-
function getAnonymousFallback() {
|
4311
|
-
const context = createAnonymousJazzContext({
|
4312
|
-
peersToLoadFrom: [],
|
4313
|
-
crypto: new PureJSCrypto()
|
4314
|
-
});
|
4315
|
-
return {
|
4316
|
-
guest: context.agent,
|
4317
|
-
node: context.agent.node,
|
4318
|
-
done: () => {
|
4319
|
-
},
|
4320
|
-
logOut: async () => {
|
4321
|
-
},
|
4322
|
-
isAuthenticated: false,
|
4323
|
-
authenticate: async () => {
|
4324
|
-
},
|
4325
|
-
register: async () => {
|
4326
|
-
throw new Error("Not implemented");
|
4327
|
-
}
|
4328
|
-
};
|
4329
|
-
}
|
4330
|
-
var JazzContextManager = class {
|
4331
|
-
constructor(opts) {
|
4332
|
-
this.authSecretStorage = new AuthSecretStorage();
|
4333
|
-
this.keepContextOpen = false;
|
4334
|
-
this.logOut = async () => {
|
4335
|
-
if (!this.context || !this.props) {
|
4336
|
-
return;
|
4337
|
-
}
|
4338
|
-
await this.props.onLogOut?.();
|
4339
|
-
if (this.props.logOutReplacement) {
|
4340
|
-
await this.props.logOutReplacement();
|
4341
|
-
} else {
|
4342
|
-
await this.context.logOut();
|
4343
|
-
return this.createContext(this.props);
|
4344
|
-
}
|
4345
|
-
};
|
4346
|
-
this.done = () => {
|
4347
|
-
if (!this.context) {
|
4348
|
-
return;
|
4349
|
-
}
|
4350
|
-
this.context.done();
|
4351
|
-
};
|
4352
|
-
this.shouldMigrateAnonymousAccount = async () => {
|
4353
|
-
if (!this.props?.onAnonymousAccountDiscarded) {
|
4354
|
-
return false;
|
4355
|
-
}
|
4356
|
-
const prevCredentials = await this.authSecretStorage.get();
|
4357
|
-
const wasAnonymous = this.authSecretStorage.getIsAuthenticated(prevCredentials) === false;
|
4358
|
-
return wasAnonymous;
|
4359
|
-
};
|
4360
|
-
/**
|
4361
|
-
* Authenticates the user with the given credentials
|
4362
|
-
*/
|
4363
|
-
this.authenticate = async (credentials) => {
|
4364
|
-
if (!this.props) {
|
4365
|
-
throw new Error("Props required");
|
4366
|
-
}
|
4367
|
-
const prevContext = this.context;
|
4368
|
-
const migratingAnonymousAccount = await this.shouldMigrateAnonymousAccount();
|
4369
|
-
this.keepContextOpen = migratingAnonymousAccount;
|
4370
|
-
await this.createContext(this.props, { credentials }).finally(() => {
|
4371
|
-
this.keepContextOpen = false;
|
4372
|
-
});
|
4373
|
-
if (migratingAnonymousAccount) {
|
4374
|
-
await this.handleAnonymousAccountMigration(prevContext);
|
4375
|
-
}
|
4376
|
-
};
|
4377
|
-
this.register = async (accountSecret, creationProps) => {
|
4378
|
-
if (!this.props) {
|
4379
|
-
throw new Error("Props required");
|
4380
|
-
}
|
4381
|
-
const prevContext = this.context;
|
4382
|
-
const migratingAnonymousAccount = await this.shouldMigrateAnonymousAccount();
|
4383
|
-
this.keepContextOpen = migratingAnonymousAccount;
|
4384
|
-
await this.createContext(this.props, {
|
4385
|
-
newAccountProps: {
|
4386
|
-
secret: accountSecret,
|
4387
|
-
creationProps
|
4388
|
-
}
|
4389
|
-
}).finally(() => {
|
4390
|
-
this.keepContextOpen = false;
|
4391
|
-
});
|
4392
|
-
if (migratingAnonymousAccount) {
|
4393
|
-
await this.handleAnonymousAccountMigration(prevContext);
|
4394
|
-
}
|
4395
|
-
if (this.context && "me" in this.context) {
|
4396
|
-
return this.context.me.id;
|
4397
|
-
}
|
4398
|
-
throw new Error("The registration hasn't created a new account");
|
4399
|
-
};
|
4400
|
-
this.listeners = /* @__PURE__ */ new Set();
|
4401
|
-
this.subscribe = (callback) => {
|
4402
|
-
this.listeners.add(callback);
|
4403
|
-
return () => {
|
4404
|
-
this.listeners.delete(callback);
|
4405
|
-
};
|
4406
|
-
};
|
4407
|
-
KvStoreContext.getInstance().initialize(this.getKvStore());
|
4408
|
-
if (opts?.useAnonymousFallback) {
|
4409
|
-
this.value = getAnonymousFallback();
|
4410
|
-
}
|
4411
|
-
}
|
4412
|
-
getKvStore() {
|
4413
|
-
return new InMemoryKVStore();
|
4414
|
-
}
|
4415
|
-
async createContext(props, authProps) {
|
4416
|
-
this.props = props;
|
4417
|
-
const { promise, resolve } = createResolvablePromise();
|
4418
|
-
const prevPromise = this.contextPromise;
|
4419
|
-
this.contextPromise = promise;
|
4420
|
-
await prevPromise;
|
4421
|
-
try {
|
4422
|
-
const result = await this.getNewContext(props, authProps);
|
4423
|
-
await this.updateContext(props, result, authProps);
|
4424
|
-
resolve();
|
4425
|
-
} catch (error) {
|
4426
|
-
resolve();
|
4427
|
-
throw error;
|
4428
|
-
}
|
4429
|
-
}
|
4430
|
-
async getNewContext(props, authProps) {
|
4431
|
-
props;
|
4432
|
-
authProps;
|
4433
|
-
throw new Error("Not implemented");
|
4434
|
-
}
|
4435
|
-
async updateContext(props, context, authProps) {
|
4436
|
-
if (!this.keepContextOpen) {
|
4437
|
-
this.context?.done();
|
4438
|
-
}
|
4439
|
-
this.context = context;
|
4440
|
-
this.props = props;
|
4441
|
-
this.value = {
|
4442
|
-
...context,
|
4443
|
-
node: context.node,
|
4444
|
-
authenticate: this.authenticate,
|
4445
|
-
register: this.register,
|
4446
|
-
logOut: this.logOut
|
4447
|
-
};
|
4448
|
-
if (authProps?.credentials) {
|
4449
|
-
this.authSecretStorage.emitUpdate(authProps.credentials);
|
4450
|
-
} else {
|
4451
|
-
this.authSecretStorage.emitUpdate(await this.authSecretStorage.get());
|
4452
|
-
}
|
4453
|
-
this.notify();
|
4454
|
-
}
|
4455
|
-
propsChanged(props) {
|
4456
|
-
props;
|
4457
|
-
throw new Error("Not implemented");
|
4458
|
-
}
|
4459
|
-
getCurrentValue() {
|
4460
|
-
return this.value;
|
4461
|
-
}
|
4462
|
-
setCurrentValue(value) {
|
4463
|
-
this.value = value;
|
4464
|
-
}
|
4465
|
-
getAuthSecretStorage() {
|
4466
|
-
return this.authSecretStorage;
|
4467
|
-
}
|
4468
|
-
async handleAnonymousAccountMigration(prevContext) {
|
4469
|
-
if (!this.props) {
|
4470
|
-
throw new Error("Props required");
|
4471
|
-
}
|
4472
|
-
const currentContext = this.context;
|
4473
|
-
if (prevContext && currentContext && "me" in prevContext && "me" in currentContext) {
|
4474
|
-
const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals4.connectedPeers(
|
4475
|
-
prevContext.me.id,
|
4476
|
-
currentContext.me.id,
|
4477
|
-
{
|
4478
|
-
peer1role: "client",
|
4479
|
-
peer2role: "server"
|
4480
|
-
}
|
4481
|
-
);
|
4482
|
-
prevContext.node.syncManager.addPeer(currentAccountAsPeer);
|
4483
|
-
currentContext.node.syncManager.addPeer(prevAccountAsPeer);
|
4484
|
-
try {
|
4485
|
-
await this.props.onAnonymousAccountDiscarded?.(prevContext.me);
|
4486
|
-
await prevContext.me.waitForAllCoValuesSync();
|
4487
|
-
} catch (error) {
|
4488
|
-
console.error("Error onAnonymousAccountDiscarded", error);
|
4489
|
-
}
|
4490
|
-
prevAccountAsPeer.outgoing.close();
|
4491
|
-
currentAccountAsPeer.outgoing.close();
|
4492
|
-
}
|
4493
|
-
prevContext?.done();
|
4494
|
-
}
|
4495
|
-
notify() {
|
4496
|
-
for (const listener of this.listeners) {
|
4497
|
-
listener();
|
4498
|
-
}
|
4499
|
-
}
|
4500
|
-
};
|
4501
|
-
function createResolvablePromise() {
|
4502
|
-
let resolve;
|
4503
|
-
const promise = new Promise((res) => {
|
4504
|
-
resolve = res;
|
4505
|
-
});
|
4506
|
-
return { promise, resolve };
|
4507
|
-
}
|
4508
|
-
|
4509
|
-
// src/implementation/devtoolsFormatters.ts
|
4510
|
-
globalThis.devtoolsFormatters = [
|
4511
|
-
{
|
4512
|
-
header: (object2) => {
|
4513
|
-
if (object2._type === "CoMap") {
|
4514
|
-
return ["div", {}, ["span", {}, object2.constructor.name]];
|
4515
|
-
} else if (object2._type === "CoList") {
|
4516
|
-
return [
|
4517
|
-
"div",
|
4518
|
-
{},
|
4519
|
-
["span", {}, object2.constructor.name + "(" + object2.length + ") "]
|
4520
|
-
];
|
4521
|
-
} else if (object2._type === "Account") {
|
4522
|
-
return [
|
4523
|
-
"div",
|
4524
|
-
{},
|
4525
|
-
[
|
4526
|
-
"span",
|
4527
|
-
{},
|
4528
|
-
object2.constructor.name + "(" + object2._refs.profile.value?.name + (object2.isMe ? " ME" : "") + ")"
|
4529
|
-
]
|
4530
|
-
];
|
4531
|
-
} else {
|
4532
|
-
return null;
|
4533
|
-
}
|
4534
|
-
},
|
4535
|
-
hasBody: function() {
|
4536
|
-
return true;
|
4537
|
-
},
|
4538
|
-
body: function(object2) {
|
4539
|
-
if (object2._type === "CoMap" || object2._type === "Account") {
|
4540
|
-
return [
|
4541
|
-
"div",
|
4542
|
-
{ style: "margin-left: 15px" },
|
4543
|
-
["div", "id: ", ["object", { object: object2.id }]],
|
4544
|
-
...Object.entries(object2).map(([k, v]) => [
|
4545
|
-
"div",
|
4546
|
-
{ style: "white-space: nowrap;" },
|
4547
|
-
["span", { style: "font-weight: bold; opacity: 0.6" }, k, ": "],
|
4548
|
-
["object", { object: v }],
|
4549
|
-
...typeof object2._schema[k] === "function" ? v === null ? [
|
4550
|
-
[
|
4551
|
-
"span",
|
4552
|
-
{ style: "opacity: 0.5" },
|
4553
|
-
` (pending ${object2._schema[k].name} `,
|
4554
|
-
["object", { object: object2._refs[k] }],
|
4555
|
-
")"
|
4556
|
-
]
|
4557
|
-
] : [] : []
|
4558
|
-
])
|
4559
|
-
];
|
4560
|
-
} else if (object2._type === "CoList") {
|
4561
|
-
return [
|
4562
|
-
"div",
|
4563
|
-
{ style: "margin-left: 15px" },
|
4564
|
-
["div", "id: ", ["object", { object: object2.id }]],
|
4565
|
-
...object2.map((v, i) => [
|
4566
|
-
"div",
|
4567
|
-
{ style: "white-space: nowrap;" },
|
4568
|
-
["span", { style: "font-weight: bold; opacity: 0.6" }, i, ": "],
|
4569
|
-
["object", { object: v }],
|
4570
|
-
...typeof object2._schema[ItemsSym] === "function" ? v === null ? [
|
4571
|
-
[
|
4572
|
-
"span",
|
4573
|
-
{ style: "opacity: 0.5" },
|
4574
|
-
` (pending ${object2._schema[ItemsSym].name} `,
|
4575
|
-
["object", { object: object2._refs[i] }],
|
4576
|
-
")"
|
4577
|
-
]
|
4578
|
-
] : [] : []
|
4579
|
-
])
|
4580
|
-
];
|
4581
|
-
}
|
4582
|
-
}
|
4583
|
-
}
|
4584
|
-
];
|
4585
|
-
|
4586
|
-
// src/coValues/interfaces.ts
|
4587
|
-
function isCoValueClass(value) {
|
4588
|
-
return typeof value === "function" && value.fromRaw !== void 0;
|
4589
|
-
}
|
4590
|
-
function loadCoValueWithoutMe(cls, id, options) {
|
4591
|
-
return loadCoValue(cls, id, {
|
4592
|
-
...options,
|
4593
|
-
loadAs: options?.loadAs ?? activeAccountContext.get()
|
4594
|
-
});
|
4595
|
-
}
|
4596
|
-
function loadCoValue(cls, id, options) {
|
4597
|
-
return new Promise((resolve) => {
|
4598
|
-
subscribeToCoValue(
|
4599
|
-
cls,
|
4600
|
-
id,
|
4601
|
-
{
|
4602
|
-
resolve: options.resolve,
|
4603
|
-
loadAs: options.loadAs,
|
4604
|
-
syncResolution: true,
|
4605
|
-
onUnavailable: () => {
|
4606
|
-
resolve(null);
|
4607
|
-
},
|
4608
|
-
onUnauthorized: () => {
|
4609
|
-
resolve(null);
|
4610
|
-
}
|
4611
|
-
},
|
4612
|
-
(value, unsubscribe) => {
|
4613
|
-
resolve(value);
|
4614
|
-
unsubscribe();
|
4615
|
-
}
|
4616
|
-
);
|
4617
|
-
});
|
4618
|
-
}
|
4619
|
-
async function ensureCoValueLoaded(existing, options) {
|
4620
|
-
const response = await loadCoValue(
|
4621
|
-
existing.constructor,
|
4622
|
-
existing.id,
|
4623
|
-
{
|
4624
|
-
loadAs: existing._loadedAs,
|
4625
|
-
resolve: options?.resolve
|
4626
|
-
}
|
4627
|
-
);
|
4628
|
-
if (!response) {
|
4629
|
-
throw new Error("Failed to deeply load CoValue " + existing.id);
|
4630
|
-
}
|
4631
|
-
return response;
|
4632
|
-
}
|
4633
|
-
function parseSubscribeRestArgs(args) {
|
4634
|
-
if (args.length === 2) {
|
4635
|
-
if (typeof args[0] === "object" && args[0] && typeof args[1] === "function") {
|
4636
|
-
return {
|
4637
|
-
options: {
|
4638
|
-
resolve: args[0].resolve,
|
4639
|
-
loadAs: args[0].loadAs,
|
4640
|
-
onUnauthorized: args[0].onUnauthorized,
|
4641
|
-
onUnavailable: args[0].onUnavailable
|
4642
|
-
},
|
4643
|
-
listener: args[1]
|
4644
|
-
};
|
4645
|
-
} else {
|
4646
|
-
throw new Error("Invalid arguments");
|
4647
|
-
}
|
4648
|
-
} else {
|
4649
|
-
if (typeof args[0] === "function") {
|
4650
|
-
return { options: {}, listener: args[0] };
|
4651
|
-
} else {
|
4652
|
-
throw new Error("Invalid arguments");
|
4653
|
-
}
|
4654
|
-
}
|
4655
|
-
}
|
4656
|
-
function subscribeToCoValueWithoutMe(cls, id, options, listener) {
|
4657
|
-
return subscribeToCoValue(
|
4658
|
-
cls,
|
4659
|
-
id,
|
4660
|
-
{
|
4661
|
-
...options,
|
4662
|
-
loadAs: options.loadAs ?? activeAccountContext.get()
|
4663
|
-
},
|
4664
|
-
listener
|
4665
|
-
);
|
4666
|
-
}
|
4667
|
-
function subscribeToCoValue(cls, id, options, listener) {
|
4668
|
-
const loadAs = options.loadAs ?? activeAccountContext.get();
|
4669
|
-
const node = "node" in loadAs ? loadAs.node : loadAs._raw.core.node;
|
4670
|
-
const resolve = options.resolve ?? true;
|
4671
|
-
let unsubscribed = false;
|
4672
|
-
const rootNode = new SubscriptionScope(node, resolve, id, {
|
4673
|
-
ref: cls,
|
4674
|
-
optional: false
|
4675
|
-
});
|
4676
|
-
const handleUpdate = (value) => {
|
4677
|
-
if (unsubscribed) return;
|
4678
|
-
if (value.type === "unavailable") {
|
4679
|
-
options.onUnavailable?.();
|
4680
|
-
console.error(value.toString());
|
4681
|
-
} else if (value.type === "unauthorized") {
|
4682
|
-
options.onUnauthorized?.();
|
4683
|
-
console.error(value.toString());
|
4684
|
-
} else if (value.type === "loaded") {
|
4685
|
-
listener(value.value, unsubscribe);
|
4686
|
-
}
|
4687
|
-
};
|
4688
|
-
let shouldDefer = !options.syncResolution;
|
4689
|
-
rootNode.setListener((value) => {
|
4690
|
-
if (shouldDefer) {
|
4691
|
-
shouldDefer = false;
|
4692
|
-
Promise.resolve().then(() => {
|
4693
|
-
handleUpdate(value);
|
4694
|
-
});
|
4695
|
-
} else {
|
4696
|
-
handleUpdate(value);
|
4697
|
-
}
|
4698
|
-
});
|
4699
|
-
function unsubscribe() {
|
4700
|
-
unsubscribed = true;
|
4701
|
-
rootNode.destroy();
|
4702
|
-
}
|
4703
|
-
return unsubscribe;
|
4704
|
-
}
|
4705
|
-
function createCoValueObservable(initialValue = void 0) {
|
4706
|
-
let currentValue = initialValue;
|
4707
|
-
let subscriberCount = 0;
|
4708
|
-
function subscribe(cls, id, options, listener) {
|
4709
|
-
subscriberCount++;
|
4710
|
-
const unsubscribe = subscribeToCoValue(
|
4711
|
-
anySchemaToCoSchema(cls),
|
4712
|
-
id,
|
4713
|
-
{
|
4714
|
-
loadAs: options.loadAs,
|
4715
|
-
resolve: options.resolve,
|
4716
|
-
onUnavailable: () => {
|
4717
|
-
currentValue = null;
|
4718
|
-
options.onUnavailable?.();
|
4719
|
-
},
|
4720
|
-
onUnauthorized: () => {
|
4721
|
-
currentValue = null;
|
4722
|
-
options.onUnauthorized?.();
|
4723
|
-
},
|
4724
|
-
syncResolution: options.syncResolution
|
4725
|
-
},
|
4726
|
-
(value) => {
|
4727
|
-
currentValue = value;
|
4728
|
-
listener();
|
4729
|
-
}
|
4730
|
-
);
|
4731
|
-
return () => {
|
4732
|
-
unsubscribe();
|
4733
|
-
subscriberCount--;
|
4734
|
-
if (subscriberCount === 0) {
|
4735
|
-
currentValue = void 0;
|
4736
|
-
}
|
4737
|
-
};
|
4738
|
-
}
|
4739
|
-
const observable = {
|
4740
|
-
getCurrentValue: () => currentValue,
|
4741
|
-
subscribe
|
4742
|
-
};
|
4743
|
-
return observable;
|
4744
|
-
}
|
4745
|
-
function subscribeToExistingCoValue(existing, options, listener) {
|
4746
|
-
return subscribeToCoValue(
|
4747
|
-
existing.constructor,
|
4748
|
-
existing.id,
|
4749
|
-
{
|
4750
|
-
loadAs: existing._loadedAs,
|
4751
|
-
resolve: options?.resolve,
|
4752
|
-
onUnavailable: options?.onUnavailable,
|
4753
|
-
onUnauthorized: options?.onUnauthorized
|
4754
|
-
},
|
4755
|
-
listener
|
4756
|
-
);
|
4757
|
-
}
|
4758
|
-
function isAccountInstance(instance) {
|
4759
|
-
if (typeof instance !== "object" || instance === null) {
|
4760
|
-
return false;
|
4761
|
-
}
|
4762
|
-
return "_type" in instance && instance._type === "Account";
|
4763
|
-
}
|
4764
|
-
function parseCoValueCreateOptions(options) {
|
4765
|
-
const Group3 = RegisteredSchemas["Group"];
|
4766
|
-
if (!options) {
|
4767
|
-
return { owner: Group3.create(), uniqueness: void 0 };
|
4768
|
-
}
|
4769
|
-
if ("_type" in options) {
|
4770
|
-
if (options._type === "Account" || options._type === "Group") {
|
4771
|
-
return { owner: options, uniqueness: void 0 };
|
4772
|
-
}
|
4773
|
-
}
|
4774
|
-
const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
|
4775
|
-
return {
|
4776
|
-
owner: options.owner ?? Group3.create(),
|
4777
|
-
uniqueness
|
4778
|
-
};
|
4779
|
-
}
|
4780
|
-
function parseGroupCreateOptions(options) {
|
4781
|
-
if (!options) {
|
4782
|
-
return { owner: activeAccountContext.get() };
|
4783
|
-
}
|
4784
|
-
return "_type" in options && isAccountInstance(options) ? { owner: options } : { owner: options.owner ?? activeAccountContext.get() };
|
4785
|
-
}
|
4786
|
-
|
4787
|
-
export {
|
4788
|
-
zodReExport_exports,
|
4789
|
-
loadCoValue,
|
4790
|
-
subscribeToCoValue,
|
4791
|
-
createCoValueObservable,
|
4792
|
-
CoValueBase,
|
4793
|
-
CoMap,
|
4794
|
-
CoList,
|
4795
|
-
CoFeed,
|
4796
|
-
FileStream,
|
4797
|
-
Account,
|
4798
|
-
isControlledAccount,
|
4799
|
-
Group,
|
4800
|
-
Profile,
|
4801
|
-
Inbox,
|
4802
|
-
InboxSender,
|
4803
|
-
CoPlainText,
|
4804
|
-
CoRichText,
|
4805
|
-
SchemaUnion,
|
4806
|
-
AnonymousJazzAgent,
|
4807
|
-
activeAccountContext,
|
4808
|
-
Encoders,
|
4809
|
-
coField,
|
4810
|
-
SubscriptionScope,
|
4811
|
-
randomSessionProvider,
|
4812
|
-
createJazzContextFromExistingCredentials,
|
4813
|
-
createJazzContextForNewAccount,
|
4814
|
-
createJazzContext,
|
4815
|
-
createAnonymousJazzContext,
|
4816
|
-
coExport_exports,
|
4817
|
-
zodSchemaToCoSchema2 as zodSchemaToCoSchema,
|
4818
|
-
anySchemaToCoSchema,
|
4819
|
-
ImageDefinition,
|
4820
|
-
KvStoreContext,
|
4821
|
-
AuthSecretStorage,
|
4822
|
-
InMemoryKVStore,
|
4823
|
-
JazzContextManager
|
4824
|
-
};
|
4825
|
-
/* istanbul ignore file -- @preserve */
|
4826
|
-
//# sourceMappingURL=chunk-G3QC4FAY.js.map
|