jazz-tools 0.14.28 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.svelte-kit/__package__/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 +26 -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-VBDJM6Z5.js +4938 -0
- package/dist/chunk-VBDJM6Z5.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 +2053 -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-open-inspector.d.ts +2 -0
- package/dist/inspector/viewer/use-open-inspector.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 +698 -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 +3 -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 +653 -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 +377 -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 +625 -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 +116 -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 +64 -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 +15 -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 +47 -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 +172 -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-open-inspector.ts +18 -0
- package/src/inspector/viewer/use-page-path.ts +65 -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 +79 -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 +981 -0
- package/src/tools/coValues/coMap.ts +929 -0
- package/src/tools/coValues/interfaces.ts +464 -0
- package/src/tools/exports.ts +117 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +188 -0
- package/src/tools/implementation/zodSchema/zodCo.ts +370 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/subscribe/CoValueCoreSubscription.ts +74 -0
- package/src/tools/subscribe/SubscriptionScope.ts +626 -0
- package/src/tools/testing.ts +301 -0
- package/src/tools/tests/coFeed.test.ts +840 -0
- package/src/tools/tests/coMap.test.ts +2113 -0
- package/src/tools/tests/fixtures.ts +2050 -0
- package/src/tools/tests/load.test.ts +117 -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-AUQIX4E7.js +0 -4827
- package/dist/chunk-AUQIX4E7.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 -368
- package/dist/coValues/coFeed.d.ts.map +0 -1
- package/dist/coValues/coList.d.ts.map +0 -1
- package/dist/coValues/coMap.d.ts +0 -529
- 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 +0 -113
- 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 +0 -52
- 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 +0 -14
- package/dist/subscribe/CoValueCoreSubscription.d.ts.map +0 -1
- package/dist/subscribe/JazzError.d.ts.map +0 -1
- package/dist/subscribe/SubscriptionScope.d.ts +0 -46
- 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 -943
- package/src/coValues/coMap.ts +0 -825
- package/src/coValues/interfaces.ts +0 -454
- package/src/exports.ts +0 -108
- package/src/implementation/zodSchema/schemaTypes/CoMapSchema.ts +0 -150
- package/src/implementation/zodSchema/zodCo.ts +0 -364
- package/src/subscribe/CoValueCoreSubscription.ts +0 -71
- package/src/subscribe/SubscriptionScope.ts +0 -614
- package/src/tests/coFeed.test.ts +0 -771
- package/src/tests/coMap.test.ts +0 -1637
- package/src/tests/load.test.ts +0 -116
- /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}/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}/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/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}/JazzError.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}/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}/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/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/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}/JazzError.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}/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}/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
@@ -0,0 +1,2113 @@
|
|
1
|
+
import { cojsonInternals } from "cojson";
|
2
|
+
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
3
|
+
import {
|
4
|
+
assert,
|
5
|
+
beforeEach,
|
6
|
+
describe,
|
7
|
+
expect,
|
8
|
+
expectTypeOf,
|
9
|
+
it,
|
10
|
+
test,
|
11
|
+
vi,
|
12
|
+
} from "vitest";
|
13
|
+
import { Group, co, subscribeToCoValue, z } from "../exports.js";
|
14
|
+
import { Account } from "../index.js";
|
15
|
+
import { ID, Loaded, zodSchemaToCoSchema } from "../internal.js";
|
16
|
+
import {
|
17
|
+
createJazzTestAccount,
|
18
|
+
getPeerConnectedToTestSyncServer,
|
19
|
+
setupJazzTestSync,
|
20
|
+
} from "../testing.js";
|
21
|
+
import { setupTwoNodes, waitFor } from "./utils.js";
|
22
|
+
|
23
|
+
const Crypto = await WasmCrypto.create();
|
24
|
+
|
25
|
+
beforeEach(async () => {
|
26
|
+
cojsonInternals.CO_VALUE_LOADING_CONFIG.RETRY_DELAY = 1000;
|
27
|
+
|
28
|
+
await setupJazzTestSync();
|
29
|
+
|
30
|
+
await createJazzTestAccount({
|
31
|
+
isCurrentActiveAccount: true,
|
32
|
+
creationProps: { name: "Hermes Puggington" },
|
33
|
+
});
|
34
|
+
});
|
35
|
+
|
36
|
+
describe("CoMap", async () => {
|
37
|
+
describe("init", () => {
|
38
|
+
test("create a CoMap with basic property access", () => {
|
39
|
+
const Person = co.map({
|
40
|
+
color: z.string(),
|
41
|
+
_height: z.number(),
|
42
|
+
birthday: z.date(),
|
43
|
+
name: z.string(),
|
44
|
+
enum: z.enum(["a", "b", "c"]),
|
45
|
+
enumMap: z.enum({ a: 1, b: 2, c: 3 }),
|
46
|
+
// nullable: z.optional.encoded<string | undefined>({
|
47
|
+
// encode: (value: string | undefined) => value || null,
|
48
|
+
// decode: (value: unknown) => (value as string) || undefined,
|
49
|
+
// })
|
50
|
+
optionalDate: z.date().optional(),
|
51
|
+
});
|
52
|
+
|
53
|
+
const birthday = new Date("1989-11-27");
|
54
|
+
|
55
|
+
const john = Person.create({
|
56
|
+
color: "red",
|
57
|
+
_height: 10,
|
58
|
+
birthday,
|
59
|
+
name: "John",
|
60
|
+
enum: "a",
|
61
|
+
enumMap: 1,
|
62
|
+
});
|
63
|
+
|
64
|
+
expect(john.color).toEqual("red");
|
65
|
+
expect(john._height).toEqual(10);
|
66
|
+
expect(john.birthday).toEqual(birthday);
|
67
|
+
expect(john._raw.get("birthday")).toEqual(birthday.toISOString());
|
68
|
+
expect(Object.keys(john)).toEqual([
|
69
|
+
"color",
|
70
|
+
"_height",
|
71
|
+
"birthday",
|
72
|
+
"name",
|
73
|
+
"enum",
|
74
|
+
"enumMap",
|
75
|
+
]);
|
76
|
+
expect(john.enum).toEqual("a");
|
77
|
+
expect(john.enumMap).toEqual(1);
|
78
|
+
});
|
79
|
+
|
80
|
+
test("property existence", () => {
|
81
|
+
const Person = co.map({
|
82
|
+
name: z.string(),
|
83
|
+
});
|
84
|
+
|
85
|
+
const john = Person.create({ name: "John" });
|
86
|
+
|
87
|
+
expect("name" in john).toEqual(true);
|
88
|
+
expect("age" in john).toEqual(false);
|
89
|
+
});
|
90
|
+
|
91
|
+
test("create a CoMap with an account as owner", () => {
|
92
|
+
const Person = co.map({
|
93
|
+
name: z.string(),
|
94
|
+
});
|
95
|
+
|
96
|
+
const john = Person.create({ name: "John" }, Account.getMe());
|
97
|
+
|
98
|
+
expect(john.name).toEqual("John");
|
99
|
+
expect(john._raw.get("name")).toEqual("John");
|
100
|
+
});
|
101
|
+
|
102
|
+
test("create a CoMap with a group as owner", () => {
|
103
|
+
const Person = co.map({
|
104
|
+
name: z.string(),
|
105
|
+
});
|
106
|
+
|
107
|
+
const john = Person.create({ name: "John" }, Group.create());
|
108
|
+
|
109
|
+
expect(john.name).toEqual("John");
|
110
|
+
expect(john._raw.get("name")).toEqual("John");
|
111
|
+
});
|
112
|
+
|
113
|
+
test("Empty schema", () => {
|
114
|
+
const emptyMap = co.map({}).create({});
|
115
|
+
|
116
|
+
// @ts-expect-error
|
117
|
+
expect(emptyMap.color).toEqual(undefined);
|
118
|
+
});
|
119
|
+
|
120
|
+
test("CoMap with reference", () => {
|
121
|
+
const Dog = co.map({
|
122
|
+
name: z.string(),
|
123
|
+
breed: z.string(),
|
124
|
+
});
|
125
|
+
|
126
|
+
const Person = co.map({
|
127
|
+
name: z.string(),
|
128
|
+
age: z.number(),
|
129
|
+
dog: Dog,
|
130
|
+
});
|
131
|
+
|
132
|
+
const person = Person.create({
|
133
|
+
name: "John",
|
134
|
+
age: 20,
|
135
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }),
|
136
|
+
});
|
137
|
+
|
138
|
+
expect(person.dog?.name).toEqual("Rex");
|
139
|
+
expect(person.dog?.breed).toEqual("Labrador");
|
140
|
+
});
|
141
|
+
|
142
|
+
test("CoMap with self reference", () => {
|
143
|
+
const Person = co.map({
|
144
|
+
name: z.string(),
|
145
|
+
age: z.number(),
|
146
|
+
// TODO: would be nice if this didn't need a type annotation
|
147
|
+
get friend(): z.ZodOptional<typeof Person> {
|
148
|
+
return z.optional(Person);
|
149
|
+
},
|
150
|
+
});
|
151
|
+
|
152
|
+
const person = Person.create({
|
153
|
+
name: "John",
|
154
|
+
age: 20,
|
155
|
+
friend: Person.create({ name: "Jane", age: 21 }),
|
156
|
+
});
|
157
|
+
|
158
|
+
expect(person.friend?.name).toEqual("Jane");
|
159
|
+
expect(person.friend?.age).toEqual(21);
|
160
|
+
});
|
161
|
+
|
162
|
+
test("toJSON should not fail when there is a key in the raw value not represented in the schema", () => {
|
163
|
+
const Person = co.map({
|
164
|
+
name: z.string(),
|
165
|
+
age: z.number(),
|
166
|
+
});
|
167
|
+
|
168
|
+
const person = Person.create({ name: "John", age: 20 });
|
169
|
+
|
170
|
+
person._raw.set("extra", "extra");
|
171
|
+
|
172
|
+
expect(person.toJSON()).toEqual({
|
173
|
+
_type: "CoMap",
|
174
|
+
id: person.id,
|
175
|
+
name: "John",
|
176
|
+
age: 20,
|
177
|
+
});
|
178
|
+
});
|
179
|
+
|
180
|
+
test("toJSON should handle references", () => {
|
181
|
+
const Person = co.map({
|
182
|
+
name: z.string(),
|
183
|
+
age: z.number(),
|
184
|
+
get friend(): z.ZodOptional<typeof Person> {
|
185
|
+
return z.optional(Person);
|
186
|
+
},
|
187
|
+
});
|
188
|
+
|
189
|
+
const person = Person.create({
|
190
|
+
name: "John",
|
191
|
+
age: 20,
|
192
|
+
friend: Person.create({ name: "Jane", age: 21 }),
|
193
|
+
});
|
194
|
+
|
195
|
+
expect(person.toJSON()).toEqual({
|
196
|
+
_type: "CoMap",
|
197
|
+
id: person.id,
|
198
|
+
name: "John",
|
199
|
+
age: 20,
|
200
|
+
friend: {
|
201
|
+
_type: "CoMap",
|
202
|
+
id: person.friend?.id,
|
203
|
+
name: "Jane",
|
204
|
+
age: 21,
|
205
|
+
},
|
206
|
+
});
|
207
|
+
});
|
208
|
+
|
209
|
+
test("toJSON should handle circular references", () => {
|
210
|
+
const Person = co.map({
|
211
|
+
name: z.string(),
|
212
|
+
age: z.number(),
|
213
|
+
get friend(): z.ZodOptional<typeof Person> {
|
214
|
+
return z.optional(Person);
|
215
|
+
},
|
216
|
+
});
|
217
|
+
|
218
|
+
const person = Person.create({
|
219
|
+
name: "John",
|
220
|
+
age: 20,
|
221
|
+
});
|
222
|
+
|
223
|
+
person.friend = person;
|
224
|
+
|
225
|
+
expect(person.toJSON()).toEqual({
|
226
|
+
_type: "CoMap",
|
227
|
+
id: person.id,
|
228
|
+
name: "John",
|
229
|
+
age: 20,
|
230
|
+
friend: {
|
231
|
+
_circular: person.id,
|
232
|
+
},
|
233
|
+
});
|
234
|
+
});
|
235
|
+
|
236
|
+
test("testing toJSON on a CoMap with a Date field", () => {
|
237
|
+
const Person = co.map({
|
238
|
+
name: z.string(),
|
239
|
+
age: z.number(),
|
240
|
+
birthday: z.date(),
|
241
|
+
});
|
242
|
+
|
243
|
+
const birthday = new Date();
|
244
|
+
|
245
|
+
const john = Person.create({
|
246
|
+
name: "John",
|
247
|
+
age: 20,
|
248
|
+
birthday,
|
249
|
+
});
|
250
|
+
|
251
|
+
expect(john.toJSON()).toMatchObject({
|
252
|
+
name: "John",
|
253
|
+
age: 20,
|
254
|
+
birthday: birthday.toISOString(),
|
255
|
+
_type: "CoMap",
|
256
|
+
id: john.id,
|
257
|
+
});
|
258
|
+
});
|
259
|
+
|
260
|
+
test("setting optional date as undefined should not throw", () => {
|
261
|
+
const Person = co.map({
|
262
|
+
name: z.string(),
|
263
|
+
age: z.number(),
|
264
|
+
birthday: z.date().optional(),
|
265
|
+
});
|
266
|
+
|
267
|
+
const john = Person.create({
|
268
|
+
name: "John",
|
269
|
+
age: 20,
|
270
|
+
});
|
271
|
+
|
272
|
+
expect(john.toJSON()).toMatchObject({
|
273
|
+
name: "John",
|
274
|
+
age: 20,
|
275
|
+
});
|
276
|
+
});
|
277
|
+
|
278
|
+
it("should disallow extra properties", () => {
|
279
|
+
const Person = co.map({
|
280
|
+
name: z.string(),
|
281
|
+
age: z.number(),
|
282
|
+
});
|
283
|
+
|
284
|
+
// @ts-expect-error - x is not a valid property
|
285
|
+
const john = Person.create({ name: "John", age: 30, x: 1 });
|
286
|
+
|
287
|
+
expect(john.toJSON()).toEqual({
|
288
|
+
_type: "CoMap",
|
289
|
+
id: john.id,
|
290
|
+
name: "John",
|
291
|
+
age: 30,
|
292
|
+
});
|
293
|
+
});
|
294
|
+
});
|
295
|
+
|
296
|
+
describe("Mutation", () => {
|
297
|
+
test("change a primitive value", () => {
|
298
|
+
const Person = co.map({
|
299
|
+
name: z.string(),
|
300
|
+
age: z.number(),
|
301
|
+
});
|
302
|
+
|
303
|
+
const john = Person.create({ name: "John", age: 20 });
|
304
|
+
|
305
|
+
john.name = "Jane";
|
306
|
+
|
307
|
+
expect(john.name).toEqual("Jane");
|
308
|
+
expect(john.age).toEqual(20);
|
309
|
+
});
|
310
|
+
|
311
|
+
test("delete an optional value", () => {
|
312
|
+
const Person = co.map({
|
313
|
+
name: z.string(),
|
314
|
+
age: z.number().optional(),
|
315
|
+
});
|
316
|
+
|
317
|
+
const john = Person.create({ name: "John", age: 20 });
|
318
|
+
|
319
|
+
delete john.age;
|
320
|
+
|
321
|
+
expect(john.name).toEqual("John");
|
322
|
+
expect(john.age).toEqual(undefined);
|
323
|
+
|
324
|
+
expect(john.toJSON()).toEqual({
|
325
|
+
_type: "CoMap",
|
326
|
+
id: john.id,
|
327
|
+
name: "John",
|
328
|
+
});
|
329
|
+
});
|
330
|
+
|
331
|
+
test("update a reference", () => {
|
332
|
+
const Dog = co.map({
|
333
|
+
name: z.string(),
|
334
|
+
});
|
335
|
+
|
336
|
+
const Person = co.map({
|
337
|
+
name: z.string(),
|
338
|
+
age: z.number(),
|
339
|
+
dog: Dog,
|
340
|
+
});
|
341
|
+
|
342
|
+
const john = Person.create({
|
343
|
+
name: "John",
|
344
|
+
age: 20,
|
345
|
+
dog: Dog.create({ name: "Rex" }),
|
346
|
+
});
|
347
|
+
|
348
|
+
john.dog = Dog.create({ name: "Fido" });
|
349
|
+
|
350
|
+
expect(john.dog?.name).toEqual("Fido");
|
351
|
+
});
|
352
|
+
|
353
|
+
test("changes should be listed in _edits", () => {
|
354
|
+
const Person = co.map({
|
355
|
+
name: z.string(),
|
356
|
+
age: z.number(),
|
357
|
+
});
|
358
|
+
|
359
|
+
const john = Person.create({ name: "John", age: 20 });
|
360
|
+
|
361
|
+
const me = Account.getMe();
|
362
|
+
|
363
|
+
john.age = 21;
|
364
|
+
|
365
|
+
expect(john._edits.age?.all).toEqual([
|
366
|
+
expect.objectContaining({
|
367
|
+
value: 20,
|
368
|
+
key: "age",
|
369
|
+
ref: undefined,
|
370
|
+
madeAt: expect.any(Date),
|
371
|
+
}),
|
372
|
+
expect.objectContaining({
|
373
|
+
value: 21,
|
374
|
+
key: "age",
|
375
|
+
ref: undefined,
|
376
|
+
madeAt: expect.any(Date),
|
377
|
+
}),
|
378
|
+
]);
|
379
|
+
expect(john._edits.age?.all[0]?.by).toMatchObject({
|
380
|
+
_type: "Account",
|
381
|
+
id: me.id,
|
382
|
+
});
|
383
|
+
expect(john._edits.age?.all[1]?.by).toMatchObject({
|
384
|
+
_type: "Account",
|
385
|
+
id: me.id,
|
386
|
+
});
|
387
|
+
});
|
388
|
+
});
|
389
|
+
|
390
|
+
test("Enum of maps", () => {
|
391
|
+
const ChildA = co.map({
|
392
|
+
type: z.literal("a"),
|
393
|
+
value: z.number(),
|
394
|
+
});
|
395
|
+
|
396
|
+
const ChildB = co.map({
|
397
|
+
type: z.literal("b"),
|
398
|
+
value: z.string(),
|
399
|
+
});
|
400
|
+
|
401
|
+
const MapWithEnumOfMaps = co.map({
|
402
|
+
name: z.string(),
|
403
|
+
child: z.discriminatedUnion("type", [ChildA, ChildB]),
|
404
|
+
});
|
405
|
+
|
406
|
+
const mapWithEnum = MapWithEnumOfMaps.create({
|
407
|
+
name: "enum",
|
408
|
+
child: ChildA.create({
|
409
|
+
type: "a",
|
410
|
+
value: 5,
|
411
|
+
}),
|
412
|
+
});
|
413
|
+
|
414
|
+
expect(mapWithEnum.name).toEqual("enum");
|
415
|
+
expect(mapWithEnum.child?.type).toEqual("a");
|
416
|
+
expect(mapWithEnum.child?.value).toEqual(5);
|
417
|
+
expect(mapWithEnum.child?.id).toBeDefined();
|
418
|
+
|
419
|
+
// TODO: properly support narrowing once we get rid of the coField marker
|
420
|
+
// if (mapWithEnum.child?.type === "a") {
|
421
|
+
// expectTypeOf(mapWithEnum.child).toEqualTypeOf<Loaded<typeof ChildA>>();
|
422
|
+
// }
|
423
|
+
});
|
424
|
+
});
|
425
|
+
|
426
|
+
describe("CoMap resolution", async () => {
|
427
|
+
test("loading a locally available map with deep resolve", async () => {
|
428
|
+
const Dog = co.map({
|
429
|
+
name: z.string(),
|
430
|
+
breed: z.string(),
|
431
|
+
});
|
432
|
+
|
433
|
+
const Person = co.map({
|
434
|
+
name: z.string(),
|
435
|
+
age: z.number(),
|
436
|
+
dog: Dog,
|
437
|
+
});
|
438
|
+
|
439
|
+
const person = Person.create({
|
440
|
+
name: "John",
|
441
|
+
age: 20,
|
442
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }),
|
443
|
+
});
|
444
|
+
|
445
|
+
const loadedPerson = await Person.load(person.id, {
|
446
|
+
resolve: {
|
447
|
+
dog: true,
|
448
|
+
},
|
449
|
+
});
|
450
|
+
|
451
|
+
assert(loadedPerson);
|
452
|
+
expect(loadedPerson.dog.name).toEqual("Rex");
|
453
|
+
});
|
454
|
+
|
455
|
+
test("loading a locally available map using autoload for the refs", async () => {
|
456
|
+
const Dog = co.map({
|
457
|
+
name: z.string(),
|
458
|
+
breed: z.string(),
|
459
|
+
});
|
460
|
+
|
461
|
+
const Person = co.map({
|
462
|
+
name: z.string(),
|
463
|
+
age: z.number(),
|
464
|
+
dog: Dog,
|
465
|
+
});
|
466
|
+
|
467
|
+
const person = Person.create({
|
468
|
+
name: "John",
|
469
|
+
age: 20,
|
470
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }),
|
471
|
+
});
|
472
|
+
|
473
|
+
const loadedPerson = await Person.load(person.id);
|
474
|
+
|
475
|
+
assert(loadedPerson);
|
476
|
+
expect(loadedPerson.dog?.name).toEqual("Rex");
|
477
|
+
});
|
478
|
+
|
479
|
+
test("loading a remotely available map with deep resolve", async () => {
|
480
|
+
const Dog = co.map({
|
481
|
+
name: z.string(),
|
482
|
+
breed: z.string(),
|
483
|
+
});
|
484
|
+
|
485
|
+
const Person = co.map({
|
486
|
+
name: z.string(),
|
487
|
+
age: z.number(),
|
488
|
+
dog: Dog,
|
489
|
+
});
|
490
|
+
|
491
|
+
const group = Group.create();
|
492
|
+
group.addMember("everyone", "writer");
|
493
|
+
|
494
|
+
const person = Person.create(
|
495
|
+
{
|
496
|
+
name: "John",
|
497
|
+
age: 20,
|
498
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }, group),
|
499
|
+
},
|
500
|
+
group,
|
501
|
+
);
|
502
|
+
|
503
|
+
const userB = await createJazzTestAccount();
|
504
|
+
|
505
|
+
const loadedPerson = await Person.load(person.id, {
|
506
|
+
resolve: {
|
507
|
+
dog: true,
|
508
|
+
},
|
509
|
+
loadAs: userB,
|
510
|
+
});
|
511
|
+
|
512
|
+
assert(loadedPerson);
|
513
|
+
expect(loadedPerson.dog.name).toEqual("Rex");
|
514
|
+
});
|
515
|
+
|
516
|
+
test("loading a remotely available map using autoload for the refs", async () => {
|
517
|
+
const Dog = co.map({
|
518
|
+
name: z.string(),
|
519
|
+
breed: z.string(),
|
520
|
+
});
|
521
|
+
|
522
|
+
const Person = co.map({
|
523
|
+
name: z.string(),
|
524
|
+
age: z.number(),
|
525
|
+
dog: Dog,
|
526
|
+
});
|
527
|
+
|
528
|
+
const group = Group.create();
|
529
|
+
group.addMember("everyone", "writer");
|
530
|
+
|
531
|
+
const person = Person.create(
|
532
|
+
{
|
533
|
+
name: "John",
|
534
|
+
age: 20,
|
535
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }, group),
|
536
|
+
},
|
537
|
+
group,
|
538
|
+
);
|
539
|
+
|
540
|
+
const userB = await createJazzTestAccount();
|
541
|
+
const loadedPerson = await Person.load(person.id, {
|
542
|
+
loadAs: userB,
|
543
|
+
});
|
544
|
+
|
545
|
+
assert(loadedPerson);
|
546
|
+
expect(loadedPerson.dog).toBe(null);
|
547
|
+
|
548
|
+
await waitFor(() => expect(loadedPerson.dog).toBeTruthy());
|
549
|
+
|
550
|
+
expect(loadedPerson.dog?.name).toEqual("Rex");
|
551
|
+
});
|
552
|
+
|
553
|
+
test("loading a remotely available map with skipRetry set to true", async () => {
|
554
|
+
// Make the retry delay extra long to ensure that it's not used
|
555
|
+
cojsonInternals.CO_VALUE_LOADING_CONFIG.RETRY_DELAY = 100_000_000;
|
556
|
+
|
557
|
+
const Dog = co.map({
|
558
|
+
name: z.string(),
|
559
|
+
breed: z.string(),
|
560
|
+
});
|
561
|
+
|
562
|
+
const Person = co.map({
|
563
|
+
name: z.string(),
|
564
|
+
age: z.number(),
|
565
|
+
dog: Dog,
|
566
|
+
});
|
567
|
+
|
568
|
+
const currentAccount = Account.getMe();
|
569
|
+
|
570
|
+
// Disconnect the current account
|
571
|
+
currentAccount._raw.core.node.syncManager.getPeers().forEach((peer) => {
|
572
|
+
peer.gracefulShutdown();
|
573
|
+
});
|
574
|
+
|
575
|
+
const group = Group.create();
|
576
|
+
group.addMember("everyone", "writer");
|
577
|
+
|
578
|
+
const person = Person.create(
|
579
|
+
{
|
580
|
+
name: "John",
|
581
|
+
age: 20,
|
582
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }, group),
|
583
|
+
},
|
584
|
+
group,
|
585
|
+
);
|
586
|
+
|
587
|
+
const userB = await createJazzTestAccount();
|
588
|
+
|
589
|
+
// We expect that the test doesn't hang here and immediately returns null
|
590
|
+
const loadedPerson = await Person.load(person.id, {
|
591
|
+
loadAs: userB,
|
592
|
+
skipRetry: true,
|
593
|
+
});
|
594
|
+
|
595
|
+
expect(loadedPerson).toBeNull();
|
596
|
+
});
|
597
|
+
|
598
|
+
test("loading a remotely available map with skipRetry set to false", async () => {
|
599
|
+
// Make the retry delay extra long to avoid flakyness in the resolved checks
|
600
|
+
cojsonInternals.CO_VALUE_LOADING_CONFIG.RETRY_DELAY = 100_000_000;
|
601
|
+
|
602
|
+
const Dog = co.map({
|
603
|
+
name: z.string(),
|
604
|
+
breed: z.string(),
|
605
|
+
});
|
606
|
+
|
607
|
+
const Person = co.map({
|
608
|
+
name: z.string(),
|
609
|
+
age: z.number(),
|
610
|
+
dog: Dog,
|
611
|
+
});
|
612
|
+
|
613
|
+
const currentAccount = Account.getMe();
|
614
|
+
|
615
|
+
// Disconnect the current account
|
616
|
+
currentAccount._raw.core.node.syncManager.getPeers().forEach((peer) => {
|
617
|
+
peer.gracefulShutdown();
|
618
|
+
});
|
619
|
+
|
620
|
+
const group = Group.create();
|
621
|
+
group.addMember("everyone", "writer");
|
622
|
+
|
623
|
+
const person = Person.create(
|
624
|
+
{
|
625
|
+
name: "John",
|
626
|
+
age: 20,
|
627
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }, group),
|
628
|
+
},
|
629
|
+
group,
|
630
|
+
);
|
631
|
+
|
632
|
+
const userB = await createJazzTestAccount();
|
633
|
+
let resolved = false;
|
634
|
+
const promise = Person.load(person.id, {
|
635
|
+
loadAs: userB,
|
636
|
+
skipRetry: false,
|
637
|
+
});
|
638
|
+
promise.then(() => {
|
639
|
+
resolved = true;
|
640
|
+
});
|
641
|
+
|
642
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
643
|
+
|
644
|
+
expect(resolved).toBe(false);
|
645
|
+
|
646
|
+
// Reconnect the current account
|
647
|
+
currentAccount._raw.core.node.syncManager.addPeer(
|
648
|
+
getPeerConnectedToTestSyncServer(),
|
649
|
+
);
|
650
|
+
|
651
|
+
const loadedPerson = await promise;
|
652
|
+
|
653
|
+
expect(resolved).toBe(true);
|
654
|
+
assert(loadedPerson);
|
655
|
+
expect(loadedPerson.dog).toBe(null);
|
656
|
+
|
657
|
+
await waitFor(() => expect(loadedPerson.dog).toBeTruthy());
|
658
|
+
|
659
|
+
expect(loadedPerson.dog?.name).toEqual("Rex");
|
660
|
+
});
|
661
|
+
|
662
|
+
test("accessing the value refs", async () => {
|
663
|
+
const Dog = co.map({
|
664
|
+
name: z.string(),
|
665
|
+
breed: z.string(),
|
666
|
+
});
|
667
|
+
|
668
|
+
const Person = co.map({
|
669
|
+
name: z.string(),
|
670
|
+
age: z.number(),
|
671
|
+
dog: Dog,
|
672
|
+
});
|
673
|
+
|
674
|
+
const group = Group.create();
|
675
|
+
group.addMember("everyone", "writer");
|
676
|
+
|
677
|
+
const person = Person.create(
|
678
|
+
{
|
679
|
+
name: "John",
|
680
|
+
age: 20,
|
681
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }, group),
|
682
|
+
},
|
683
|
+
group,
|
684
|
+
);
|
685
|
+
|
686
|
+
const userB = await createJazzTestAccount();
|
687
|
+
const loadedPerson = await Person.load(person.id, {
|
688
|
+
loadAs: userB,
|
689
|
+
});
|
690
|
+
|
691
|
+
assert(loadedPerson);
|
692
|
+
|
693
|
+
expect(loadedPerson._refs.dog?.id).toBe(person.dog!.id);
|
694
|
+
|
695
|
+
const dog = await loadedPerson._refs.dog?.load();
|
696
|
+
|
697
|
+
assert(dog);
|
698
|
+
|
699
|
+
expect(dog.name).toEqual("Rex");
|
700
|
+
});
|
701
|
+
|
702
|
+
test("subscription on a locally available map with deep resolve", async () => {
|
703
|
+
const Dog = co.map({
|
704
|
+
name: z.string(),
|
705
|
+
breed: z.string(),
|
706
|
+
});
|
707
|
+
|
708
|
+
const Person = co.map({
|
709
|
+
name: z.string(),
|
710
|
+
age: z.number(),
|
711
|
+
dog: Dog,
|
712
|
+
});
|
713
|
+
|
714
|
+
const person = Person.create({
|
715
|
+
name: "John",
|
716
|
+
age: 20,
|
717
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }),
|
718
|
+
});
|
719
|
+
|
720
|
+
const updates: Loaded<typeof Person, { dog: true }>[] = [];
|
721
|
+
const spy = vi.fn((person) => updates.push(person));
|
722
|
+
|
723
|
+
Person.subscribe(
|
724
|
+
person.id,
|
725
|
+
{
|
726
|
+
resolve: {
|
727
|
+
dog: true,
|
728
|
+
},
|
729
|
+
},
|
730
|
+
spy,
|
731
|
+
);
|
732
|
+
|
733
|
+
expect(spy).not.toHaveBeenCalled();
|
734
|
+
|
735
|
+
await waitFor(() => expect(spy).toHaveBeenCalled());
|
736
|
+
|
737
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
738
|
+
|
739
|
+
expect(updates[0]?.dog.name).toEqual("Rex");
|
740
|
+
|
741
|
+
person.dog!.name = "Fido";
|
742
|
+
|
743
|
+
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
744
|
+
|
745
|
+
expect(updates[1]?.dog.name).toEqual("Fido");
|
746
|
+
|
747
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
748
|
+
});
|
749
|
+
|
750
|
+
test("subscription on a locally available map with autoload", async () => {
|
751
|
+
const Dog = co.map({
|
752
|
+
name: z.string(),
|
753
|
+
breed: z.string(),
|
754
|
+
});
|
755
|
+
|
756
|
+
const Person = co.map({
|
757
|
+
name: z.string(),
|
758
|
+
age: z.number(),
|
759
|
+
dog: Dog,
|
760
|
+
});
|
761
|
+
|
762
|
+
const person = Person.create({
|
763
|
+
name: "John",
|
764
|
+
age: 20,
|
765
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }),
|
766
|
+
});
|
767
|
+
|
768
|
+
const updates: Loaded<typeof Person>[] = [];
|
769
|
+
const spy = vi.fn((person) => updates.push(person));
|
770
|
+
|
771
|
+
Person.subscribe(person.id, {}, spy);
|
772
|
+
|
773
|
+
expect(spy).not.toHaveBeenCalled();
|
774
|
+
|
775
|
+
await waitFor(() => expect(spy).toHaveBeenCalled());
|
776
|
+
|
777
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
778
|
+
|
779
|
+
expect(updates[0]?.dog?.name).toEqual("Rex");
|
780
|
+
|
781
|
+
person.dog!.name = "Fido";
|
782
|
+
|
783
|
+
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
784
|
+
|
785
|
+
expect(updates[1]?.dog?.name).toEqual("Fido");
|
786
|
+
|
787
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
788
|
+
});
|
789
|
+
|
790
|
+
test("subscription on a locally available map with syncResolution", async () => {
|
791
|
+
const Dog = co.map({
|
792
|
+
name: z.string(),
|
793
|
+
breed: z.string(),
|
794
|
+
});
|
795
|
+
|
796
|
+
const Person = co.map({
|
797
|
+
name: z.string(),
|
798
|
+
age: z.number(),
|
799
|
+
dog: Dog,
|
800
|
+
});
|
801
|
+
|
802
|
+
const person = Person.create({
|
803
|
+
name: "John",
|
804
|
+
age: 20,
|
805
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }),
|
806
|
+
});
|
807
|
+
|
808
|
+
const updates: Loaded<typeof Person>[] = [];
|
809
|
+
const spy = vi.fn((person) => updates.push(person));
|
810
|
+
|
811
|
+
subscribeToCoValue(
|
812
|
+
zodSchemaToCoSchema(Person), // TODO: we should get rid of the conversion in the future
|
813
|
+
person.id,
|
814
|
+
{
|
815
|
+
syncResolution: true,
|
816
|
+
loadAs: Account.getMe(),
|
817
|
+
},
|
818
|
+
spy,
|
819
|
+
);
|
820
|
+
|
821
|
+
expect(spy).toHaveBeenCalled();
|
822
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
823
|
+
|
824
|
+
expect(updates[0]?.dog?.name).toEqual("Rex");
|
825
|
+
|
826
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
827
|
+
|
828
|
+
person.dog!.name = "Fido";
|
829
|
+
|
830
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
831
|
+
|
832
|
+
expect(updates[1]?.dog?.name).toEqual("Fido");
|
833
|
+
|
834
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
835
|
+
});
|
836
|
+
|
837
|
+
test("subscription on a remotely available map with deep resolve", async () => {
|
838
|
+
const Dog = co.map({
|
839
|
+
name: z.string(),
|
840
|
+
breed: z.string(),
|
841
|
+
});
|
842
|
+
|
843
|
+
const Person = co.map({
|
844
|
+
name: z.string(),
|
845
|
+
age: z.number(),
|
846
|
+
dog: Dog,
|
847
|
+
});
|
848
|
+
|
849
|
+
const group = Group.create();
|
850
|
+
group.addMember("everyone", "writer");
|
851
|
+
|
852
|
+
const person = Person.create(
|
853
|
+
{
|
854
|
+
name: "John",
|
855
|
+
age: 20,
|
856
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }, group),
|
857
|
+
},
|
858
|
+
group,
|
859
|
+
);
|
860
|
+
|
861
|
+
const userB = await createJazzTestAccount();
|
862
|
+
|
863
|
+
const updates: Loaded<typeof Person, { dog: true }>[] = [];
|
864
|
+
const spy = vi.fn((person) => updates.push(person));
|
865
|
+
|
866
|
+
Person.subscribe(
|
867
|
+
person.id,
|
868
|
+
{
|
869
|
+
resolve: {
|
870
|
+
dog: true,
|
871
|
+
},
|
872
|
+
loadAs: userB,
|
873
|
+
},
|
874
|
+
spy,
|
875
|
+
);
|
876
|
+
|
877
|
+
expect(spy).not.toHaveBeenCalled();
|
878
|
+
|
879
|
+
await waitFor(() => expect(spy).toHaveBeenCalled());
|
880
|
+
|
881
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
882
|
+
|
883
|
+
expect(updates[0]?.dog.name).toEqual("Rex");
|
884
|
+
|
885
|
+
person.dog!.name = "Fido";
|
886
|
+
|
887
|
+
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
888
|
+
|
889
|
+
expect(updates[1]?.dog.name).toEqual("Fido");
|
890
|
+
|
891
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
892
|
+
});
|
893
|
+
|
894
|
+
test("subscription on a remotely available map with autoload", async () => {
|
895
|
+
const Dog = co.map({
|
896
|
+
name: z.string(),
|
897
|
+
breed: z.string(),
|
898
|
+
});
|
899
|
+
|
900
|
+
const Person = co.map({
|
901
|
+
name: z.string(),
|
902
|
+
age: z.number(),
|
903
|
+
dog: Dog,
|
904
|
+
});
|
905
|
+
|
906
|
+
const group = Group.create();
|
907
|
+
group.addMember("everyone", "writer");
|
908
|
+
|
909
|
+
const person = Person.create(
|
910
|
+
{
|
911
|
+
name: "John",
|
912
|
+
age: 20,
|
913
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }, group),
|
914
|
+
},
|
915
|
+
group,
|
916
|
+
);
|
917
|
+
|
918
|
+
const updates: Loaded<typeof Person>[] = [];
|
919
|
+
const spy = vi.fn((person) => updates.push(person));
|
920
|
+
|
921
|
+
const userB = await createJazzTestAccount();
|
922
|
+
|
923
|
+
Person.subscribe(
|
924
|
+
person.id,
|
925
|
+
{
|
926
|
+
loadAs: userB,
|
927
|
+
},
|
928
|
+
spy,
|
929
|
+
);
|
930
|
+
|
931
|
+
expect(spy).not.toHaveBeenCalled();
|
932
|
+
|
933
|
+
await waitFor(() => expect(spy).toHaveBeenCalled());
|
934
|
+
|
935
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
936
|
+
|
937
|
+
expect(updates[0]?.dog?.name).toEqual("Rex");
|
938
|
+
|
939
|
+
person.dog!.name = "Fido";
|
940
|
+
|
941
|
+
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
942
|
+
|
943
|
+
expect(updates[1]?.dog?.name).toEqual("Fido");
|
944
|
+
|
945
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
946
|
+
});
|
947
|
+
|
948
|
+
test("replacing nested object triggers updates", async () => {
|
949
|
+
const Dog = co.map({
|
950
|
+
name: z.string(),
|
951
|
+
breed: z.string(),
|
952
|
+
});
|
953
|
+
|
954
|
+
const Person = co.map({
|
955
|
+
name: z.string(),
|
956
|
+
age: z.number(),
|
957
|
+
dog: Dog,
|
958
|
+
});
|
959
|
+
|
960
|
+
const person = Person.create({
|
961
|
+
name: "John",
|
962
|
+
age: 20,
|
963
|
+
dog: Dog.create({ name: "Rex", breed: "Labrador" }),
|
964
|
+
});
|
965
|
+
|
966
|
+
const updates: Loaded<typeof Person, { dog: true }>[] = [];
|
967
|
+
const spy = vi.fn((person) => updates.push(person));
|
968
|
+
|
969
|
+
Person.subscribe(
|
970
|
+
person.id,
|
971
|
+
{
|
972
|
+
resolve: {
|
973
|
+
dog: true,
|
974
|
+
},
|
975
|
+
},
|
976
|
+
spy,
|
977
|
+
);
|
978
|
+
|
979
|
+
expect(spy).not.toHaveBeenCalled();
|
980
|
+
|
981
|
+
await waitFor(() => expect(spy).toHaveBeenCalled());
|
982
|
+
|
983
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
984
|
+
|
985
|
+
expect(updates[0]?.dog.name).toEqual("Rex");
|
986
|
+
|
987
|
+
person.dog!.name = "Fido";
|
988
|
+
|
989
|
+
await waitFor(() => expect(spy).toHaveBeenCalledTimes(2));
|
990
|
+
|
991
|
+
expect(updates[1]?.dog.name).toEqual("Fido");
|
992
|
+
|
993
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
994
|
+
});
|
995
|
+
});
|
996
|
+
|
997
|
+
describe("CoMap applyDiff", async () => {
|
998
|
+
const me = await Account.create({
|
999
|
+
creationProps: { name: "Tester McTesterson" },
|
1000
|
+
crypto: Crypto,
|
1001
|
+
});
|
1002
|
+
|
1003
|
+
const NestedMap = co.map({
|
1004
|
+
value: z.string(),
|
1005
|
+
});
|
1006
|
+
|
1007
|
+
const TestMap = co.map({
|
1008
|
+
name: z.string(),
|
1009
|
+
age: z.number(),
|
1010
|
+
isActive: z.boolean(),
|
1011
|
+
birthday: z.date(),
|
1012
|
+
nested: NestedMap,
|
1013
|
+
optionalField: z.string().optional(),
|
1014
|
+
optionalNested: z.optional(NestedMap),
|
1015
|
+
});
|
1016
|
+
|
1017
|
+
test("Basic applyDiff", () => {
|
1018
|
+
const map = TestMap.create(
|
1019
|
+
{
|
1020
|
+
name: "Alice",
|
1021
|
+
age: 30,
|
1022
|
+
isActive: true,
|
1023
|
+
birthday: new Date("1990-01-01"),
|
1024
|
+
nested: NestedMap.create({ value: "original" }, { owner: me }),
|
1025
|
+
},
|
1026
|
+
{ owner: me },
|
1027
|
+
);
|
1028
|
+
|
1029
|
+
const newValues = {
|
1030
|
+
name: "Bob",
|
1031
|
+
age: 35,
|
1032
|
+
isActive: false,
|
1033
|
+
};
|
1034
|
+
|
1035
|
+
map.applyDiff(newValues);
|
1036
|
+
|
1037
|
+
expect(map.name).toEqual("Bob");
|
1038
|
+
expect(map.age).toEqual(35);
|
1039
|
+
expect(map.isActive).toEqual(false);
|
1040
|
+
expect(map.birthday).toEqual(new Date("1990-01-01"));
|
1041
|
+
expect(map.nested?.value).toEqual("original");
|
1042
|
+
});
|
1043
|
+
|
1044
|
+
test("applyDiff with nested changes", () => {
|
1045
|
+
const map = TestMap.create(
|
1046
|
+
{
|
1047
|
+
name: "Charlie",
|
1048
|
+
age: 25,
|
1049
|
+
isActive: true,
|
1050
|
+
birthday: new Date("1995-01-01"),
|
1051
|
+
nested: NestedMap.create({ value: "original" }, { owner: me }),
|
1052
|
+
},
|
1053
|
+
{ owner: me },
|
1054
|
+
);
|
1055
|
+
|
1056
|
+
const newValues = {
|
1057
|
+
name: "David",
|
1058
|
+
nested: NestedMap.create({ value: "updated" }, { owner: me }),
|
1059
|
+
};
|
1060
|
+
|
1061
|
+
map.applyDiff(newValues);
|
1062
|
+
|
1063
|
+
expect(map.name).toEqual("David");
|
1064
|
+
expect(map.age).toEqual(25);
|
1065
|
+
expect(map.nested?.value).toEqual("updated");
|
1066
|
+
});
|
1067
|
+
|
1068
|
+
test("applyDiff with encoded fields", () => {
|
1069
|
+
const map = TestMap.create(
|
1070
|
+
{
|
1071
|
+
name: "Eve",
|
1072
|
+
age: 28,
|
1073
|
+
isActive: true,
|
1074
|
+
birthday: new Date("1993-01-01"),
|
1075
|
+
nested: NestedMap.create({ value: "original" }, { owner: me }),
|
1076
|
+
},
|
1077
|
+
{ owner: me },
|
1078
|
+
);
|
1079
|
+
|
1080
|
+
const newValues = {
|
1081
|
+
birthday: new Date("1993-06-15"),
|
1082
|
+
};
|
1083
|
+
|
1084
|
+
map.applyDiff(newValues);
|
1085
|
+
|
1086
|
+
expect(map.birthday).toEqual(new Date("1993-06-15"));
|
1087
|
+
});
|
1088
|
+
|
1089
|
+
test("applyDiff with optional fields", () => {
|
1090
|
+
const map = TestMap.create(
|
1091
|
+
{
|
1092
|
+
name: "Frank",
|
1093
|
+
age: 40,
|
1094
|
+
isActive: true,
|
1095
|
+
birthday: new Date("1980-01-01"),
|
1096
|
+
nested: NestedMap.create({ value: "original" }, { owner: me }),
|
1097
|
+
},
|
1098
|
+
{ owner: me },
|
1099
|
+
);
|
1100
|
+
|
1101
|
+
const newValues = {
|
1102
|
+
optionalField: "New optional value",
|
1103
|
+
};
|
1104
|
+
|
1105
|
+
map.applyDiff(newValues);
|
1106
|
+
|
1107
|
+
expect(map.optionalField).toEqual("New optional value");
|
1108
|
+
|
1109
|
+
map.applyDiff({ optionalField: undefined });
|
1110
|
+
|
1111
|
+
expect(map.optionalField).toBeUndefined();
|
1112
|
+
});
|
1113
|
+
|
1114
|
+
test("applyDiff with no changes", () => {
|
1115
|
+
const map = TestMap.create(
|
1116
|
+
{
|
1117
|
+
name: "Grace",
|
1118
|
+
age: 35,
|
1119
|
+
isActive: true,
|
1120
|
+
birthday: new Date("1985-01-01"),
|
1121
|
+
nested: NestedMap.create({ value: "original" }, { owner: me }),
|
1122
|
+
},
|
1123
|
+
{ owner: me },
|
1124
|
+
);
|
1125
|
+
|
1126
|
+
const originalJSON = map.toJSON();
|
1127
|
+
|
1128
|
+
map.applyDiff({});
|
1129
|
+
|
1130
|
+
expect(map.toJSON()).toEqual(originalJSON);
|
1131
|
+
});
|
1132
|
+
|
1133
|
+
test("applyDiff with invalid field", () => {
|
1134
|
+
const map = TestMap.create(
|
1135
|
+
{
|
1136
|
+
name: "Henry",
|
1137
|
+
age: 45,
|
1138
|
+
isActive: false,
|
1139
|
+
birthday: new Date("1975-01-01"),
|
1140
|
+
nested: NestedMap.create({ value: "original" }, { owner: me }),
|
1141
|
+
},
|
1142
|
+
{ owner: me },
|
1143
|
+
);
|
1144
|
+
|
1145
|
+
const newValues = {
|
1146
|
+
name: "Ian",
|
1147
|
+
invalidField: "This should be ignored",
|
1148
|
+
};
|
1149
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1150
|
+
map.applyDiff(newValues as any);
|
1151
|
+
|
1152
|
+
expect(map.name).toEqual("Ian");
|
1153
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1154
|
+
expect((map as any).invalidField).toBeUndefined();
|
1155
|
+
});
|
1156
|
+
|
1157
|
+
test("applyDiff with optional reference set to undefined", () => {
|
1158
|
+
const map = TestMap.create(
|
1159
|
+
{
|
1160
|
+
name: "Jack",
|
1161
|
+
age: 50,
|
1162
|
+
isActive: true,
|
1163
|
+
birthday: new Date("1970-01-01"),
|
1164
|
+
nested: NestedMap.create({ value: "original" }, { owner: me }),
|
1165
|
+
optionalNested: NestedMap.create({ value: "optional" }, { owner: me }),
|
1166
|
+
},
|
1167
|
+
{ owner: me },
|
1168
|
+
);
|
1169
|
+
|
1170
|
+
const newValues = {
|
1171
|
+
optionalNested: undefined,
|
1172
|
+
};
|
1173
|
+
|
1174
|
+
map.applyDiff(newValues);
|
1175
|
+
|
1176
|
+
expect(map.optionalNested).toBeUndefined();
|
1177
|
+
});
|
1178
|
+
|
1179
|
+
test("applyDiff with required reference set to undefined should throw", () => {
|
1180
|
+
const map = TestMap.create(
|
1181
|
+
{
|
1182
|
+
name: "Kate",
|
1183
|
+
age: 55,
|
1184
|
+
isActive: true,
|
1185
|
+
birthday: new Date("1965-01-01"),
|
1186
|
+
nested: NestedMap.create({ value: "original" }, { owner: me }),
|
1187
|
+
},
|
1188
|
+
{ owner: me },
|
1189
|
+
);
|
1190
|
+
|
1191
|
+
const newValues = {
|
1192
|
+
nested: undefined,
|
1193
|
+
};
|
1194
|
+
|
1195
|
+
expect(() => map.applyDiff(newValues)).toThrowError(
|
1196
|
+
"Cannot set required reference nested to undefined",
|
1197
|
+
);
|
1198
|
+
});
|
1199
|
+
});
|
1200
|
+
|
1201
|
+
describe("CoMap Typescript validation", async () => {
|
1202
|
+
const me = await Account.create({
|
1203
|
+
creationProps: { name: "Hermes Puggington" },
|
1204
|
+
crypto: Crypto,
|
1205
|
+
});
|
1206
|
+
|
1207
|
+
test("Is not ok to pass null into a required ref", () => {
|
1208
|
+
const NestedMap = co.map({
|
1209
|
+
value: z.string(),
|
1210
|
+
});
|
1211
|
+
|
1212
|
+
const TestMap = co.map({
|
1213
|
+
required: NestedMap,
|
1214
|
+
optional: NestedMap.optional(),
|
1215
|
+
});
|
1216
|
+
|
1217
|
+
expectTypeOf<typeof TestMap.create>().toBeCallableWith(
|
1218
|
+
{
|
1219
|
+
optional: NestedMap.create({ value: "" }, { owner: me }),
|
1220
|
+
// @ts-expect-error null can't be passed to a non-optional field
|
1221
|
+
required: null,
|
1222
|
+
},
|
1223
|
+
{ owner: me },
|
1224
|
+
);
|
1225
|
+
});
|
1226
|
+
|
1227
|
+
test("Is not ok if a required ref is omitted", () => {
|
1228
|
+
const NestedMap = co.map({
|
1229
|
+
value: z.string(),
|
1230
|
+
});
|
1231
|
+
|
1232
|
+
const TestMap = co.map({
|
1233
|
+
required: NestedMap,
|
1234
|
+
optional: NestedMap.optional(),
|
1235
|
+
});
|
1236
|
+
|
1237
|
+
expectTypeOf<typeof TestMap.create>().toBeCallableWith(
|
1238
|
+
// @ts-expect-error non-optional fields can't be omitted
|
1239
|
+
{},
|
1240
|
+
{ owner: me },
|
1241
|
+
);
|
1242
|
+
});
|
1243
|
+
|
1244
|
+
test("Is ok to omit optional fields", () => {
|
1245
|
+
const NestedMap = co.map({
|
1246
|
+
value: z.string(),
|
1247
|
+
});
|
1248
|
+
|
1249
|
+
const TestMap = co.map({
|
1250
|
+
required: NestedMap,
|
1251
|
+
optional: NestedMap.optional(),
|
1252
|
+
});
|
1253
|
+
|
1254
|
+
expectTypeOf<typeof TestMap.create>().toBeCallableWith(
|
1255
|
+
{
|
1256
|
+
required: NestedMap.create({ value: "" }, { owner: me }),
|
1257
|
+
},
|
1258
|
+
{ owner: me },
|
1259
|
+
);
|
1260
|
+
|
1261
|
+
expectTypeOf<typeof TestMap.create>().toBeCallableWith(
|
1262
|
+
{
|
1263
|
+
required: NestedMap.create({ value: "" }, { owner: me }),
|
1264
|
+
optional: undefined, // TODO: should we allow null here? zod is stricter about this than we were before
|
1265
|
+
},
|
1266
|
+
{ owner: me },
|
1267
|
+
);
|
1268
|
+
});
|
1269
|
+
|
1270
|
+
test("waitForSync should resolve when the value is uploaded", async () => {
|
1271
|
+
const TestMap = co.map({
|
1272
|
+
name: z.string(),
|
1273
|
+
});
|
1274
|
+
|
1275
|
+
const { clientNode, serverNode, clientAccount } = await setupTwoNodes();
|
1276
|
+
|
1277
|
+
const map = TestMap.create(
|
1278
|
+
{
|
1279
|
+
name: "Alice",
|
1280
|
+
},
|
1281
|
+
{ owner: clientAccount },
|
1282
|
+
);
|
1283
|
+
|
1284
|
+
await map.waitForSync({ timeout: 1000 });
|
1285
|
+
|
1286
|
+
// Killing the client node so the serverNode can't load the map from it
|
1287
|
+
clientNode.gracefulShutdown();
|
1288
|
+
|
1289
|
+
const loadedMap = await serverNode.load(map._raw.id);
|
1290
|
+
|
1291
|
+
expect(loadedMap).not.toBe("unavailable");
|
1292
|
+
});
|
1293
|
+
});
|
1294
|
+
|
1295
|
+
describe("Creating and finding unique CoMaps", async () => {
|
1296
|
+
test("Creating and finding unique CoMaps", async () => {
|
1297
|
+
const group = Group.create();
|
1298
|
+
|
1299
|
+
const Person = co.map({
|
1300
|
+
name: z.string(),
|
1301
|
+
_height: z.number(),
|
1302
|
+
birthday: z.date(),
|
1303
|
+
color: z.string(),
|
1304
|
+
});
|
1305
|
+
|
1306
|
+
const alice = Person.create(
|
1307
|
+
{
|
1308
|
+
name: "Alice",
|
1309
|
+
_height: 100,
|
1310
|
+
birthday: new Date("1990-01-01"),
|
1311
|
+
color: "red",
|
1312
|
+
},
|
1313
|
+
{ owner: group, unique: { name: "Alice" } },
|
1314
|
+
);
|
1315
|
+
|
1316
|
+
const foundAlice = await Person.loadUnique({ name: "Alice" }, group.id);
|
1317
|
+
expect(foundAlice).toEqual(alice);
|
1318
|
+
});
|
1319
|
+
|
1320
|
+
test("manual upserting pattern", async () => {
|
1321
|
+
// Schema
|
1322
|
+
const Event = co.map({
|
1323
|
+
title: z.string(),
|
1324
|
+
identifier: z.string(),
|
1325
|
+
external_id: z.string(),
|
1326
|
+
});
|
1327
|
+
|
1328
|
+
// Data
|
1329
|
+
const sourceData = {
|
1330
|
+
title: "Test Event Title",
|
1331
|
+
identifier: "test-event-identifier",
|
1332
|
+
_id: "test-event-external-id",
|
1333
|
+
};
|
1334
|
+
const workspace = Group.create();
|
1335
|
+
|
1336
|
+
// Pattern
|
1337
|
+
let activeEvent = await Event.loadUnique(
|
1338
|
+
{ identifier: sourceData.identifier },
|
1339
|
+
workspace.id,
|
1340
|
+
);
|
1341
|
+
if (!activeEvent) {
|
1342
|
+
activeEvent = Event.create(
|
1343
|
+
{
|
1344
|
+
title: sourceData.title,
|
1345
|
+
identifier: sourceData.identifier,
|
1346
|
+
external_id: sourceData._id,
|
1347
|
+
},
|
1348
|
+
workspace,
|
1349
|
+
);
|
1350
|
+
} else {
|
1351
|
+
activeEvent.applyDiff({
|
1352
|
+
title: sourceData.title,
|
1353
|
+
identifier: sourceData.identifier,
|
1354
|
+
external_id: sourceData._id,
|
1355
|
+
});
|
1356
|
+
}
|
1357
|
+
expect(activeEvent).toEqual({
|
1358
|
+
title: sourceData.title,
|
1359
|
+
identifier: sourceData.identifier,
|
1360
|
+
external_id: sourceData._id,
|
1361
|
+
});
|
1362
|
+
});
|
1363
|
+
|
1364
|
+
test("upserting a non-existent value", async () => {
|
1365
|
+
// Schema
|
1366
|
+
const Event = co.map({
|
1367
|
+
title: z.string(),
|
1368
|
+
identifier: z.string(),
|
1369
|
+
external_id: z.string(),
|
1370
|
+
});
|
1371
|
+
|
1372
|
+
// Data
|
1373
|
+
const sourceData = {
|
1374
|
+
title: "Test Event Title",
|
1375
|
+
identifier: "test-event-identifier",
|
1376
|
+
_id: "test-event-external-id",
|
1377
|
+
};
|
1378
|
+
const workspace = Group.create();
|
1379
|
+
|
1380
|
+
// Upserting
|
1381
|
+
const activeEvent = await Event.upsertUnique({
|
1382
|
+
value: {
|
1383
|
+
title: sourceData.title,
|
1384
|
+
identifier: sourceData.identifier,
|
1385
|
+
external_id: sourceData._id,
|
1386
|
+
},
|
1387
|
+
unique: sourceData.identifier,
|
1388
|
+
owner: workspace,
|
1389
|
+
});
|
1390
|
+
expect(activeEvent).toEqual({
|
1391
|
+
title: sourceData.title,
|
1392
|
+
identifier: sourceData.identifier,
|
1393
|
+
external_id: sourceData._id,
|
1394
|
+
});
|
1395
|
+
});
|
1396
|
+
|
1397
|
+
test("upserting an existing value", async () => {
|
1398
|
+
// Schema
|
1399
|
+
const Event = co.map({
|
1400
|
+
title: z.string(),
|
1401
|
+
identifier: z.string(),
|
1402
|
+
external_id: z.string(),
|
1403
|
+
});
|
1404
|
+
|
1405
|
+
// Data
|
1406
|
+
const oldSourceData = {
|
1407
|
+
title: "Old Event Title",
|
1408
|
+
identifier: "test-event-identifier",
|
1409
|
+
_id: "test-event-external-id",
|
1410
|
+
};
|
1411
|
+
const newSourceData = {
|
1412
|
+
title: "New Event Title",
|
1413
|
+
identifier: "test-event-identifier",
|
1414
|
+
_id: "test-event-external-id",
|
1415
|
+
};
|
1416
|
+
expect(oldSourceData.identifier).toEqual(newSourceData.identifier);
|
1417
|
+
const workspace = Group.create();
|
1418
|
+
const oldActiveEvent = Event.create(
|
1419
|
+
{
|
1420
|
+
title: oldSourceData.title,
|
1421
|
+
identifier: oldSourceData.identifier,
|
1422
|
+
external_id: oldSourceData._id,
|
1423
|
+
},
|
1424
|
+
workspace,
|
1425
|
+
);
|
1426
|
+
|
1427
|
+
// Upserting
|
1428
|
+
const activeEvent = await Event.upsertUnique({
|
1429
|
+
value: {
|
1430
|
+
title: newSourceData.title,
|
1431
|
+
identifier: newSourceData.identifier,
|
1432
|
+
external_id: newSourceData._id,
|
1433
|
+
},
|
1434
|
+
unique: newSourceData.identifier,
|
1435
|
+
owner: workspace,
|
1436
|
+
});
|
1437
|
+
expect(activeEvent).toEqual({
|
1438
|
+
title: newSourceData.title,
|
1439
|
+
identifier: newSourceData.identifier,
|
1440
|
+
external_id: newSourceData._id,
|
1441
|
+
});
|
1442
|
+
expect(activeEvent).not.toEqual(oldActiveEvent);
|
1443
|
+
});
|
1444
|
+
|
1445
|
+
test("upserting a non-existent value with resolve", async () => {
|
1446
|
+
const Project = co.map({
|
1447
|
+
name: z.string(),
|
1448
|
+
});
|
1449
|
+
const Organisation = co.map({
|
1450
|
+
name: z.string(),
|
1451
|
+
projects: co.list(Project),
|
1452
|
+
});
|
1453
|
+
const workspace = Group.create();
|
1454
|
+
|
1455
|
+
const myOrg = await Organisation.upsertUnique({
|
1456
|
+
value: {
|
1457
|
+
name: "My organisation",
|
1458
|
+
projects: co.list(Project).create(
|
1459
|
+
[
|
1460
|
+
Project.create(
|
1461
|
+
{
|
1462
|
+
name: "My project",
|
1463
|
+
},
|
1464
|
+
workspace,
|
1465
|
+
),
|
1466
|
+
],
|
1467
|
+
workspace,
|
1468
|
+
),
|
1469
|
+
},
|
1470
|
+
unique: { name: "My organisation" },
|
1471
|
+
owner: workspace,
|
1472
|
+
resolve: {
|
1473
|
+
projects: {
|
1474
|
+
$each: true,
|
1475
|
+
},
|
1476
|
+
},
|
1477
|
+
});
|
1478
|
+
assert(myOrg);
|
1479
|
+
expect(myOrg).not.toBeNull();
|
1480
|
+
expect(myOrg.name).toEqual("My organisation");
|
1481
|
+
expect(myOrg.projects.length).toBe(1);
|
1482
|
+
expect(myOrg.projects[0]).toMatchObject({
|
1483
|
+
name: "My project",
|
1484
|
+
});
|
1485
|
+
});
|
1486
|
+
|
1487
|
+
test("upserting an existing value with resolve", async () => {
|
1488
|
+
const Project = co.map({
|
1489
|
+
name: z.string(),
|
1490
|
+
});
|
1491
|
+
const Organisation = co.map({
|
1492
|
+
name: z.string(),
|
1493
|
+
projects: co.list(Project),
|
1494
|
+
});
|
1495
|
+
const workspace = Group.create();
|
1496
|
+
const initialProject = await Project.upsertUnique({
|
1497
|
+
value: {
|
1498
|
+
name: "My project",
|
1499
|
+
},
|
1500
|
+
unique: { unique: "First project" },
|
1501
|
+
owner: workspace,
|
1502
|
+
});
|
1503
|
+
assert(initialProject);
|
1504
|
+
expect(initialProject).not.toBeNull();
|
1505
|
+
expect(initialProject.name).toEqual("My project");
|
1506
|
+
|
1507
|
+
const myOrg = await Organisation.upsertUnique({
|
1508
|
+
value: {
|
1509
|
+
name: "My organisation",
|
1510
|
+
projects: co.list(Project).create([initialProject], workspace),
|
1511
|
+
},
|
1512
|
+
unique: { name: "My organisation" },
|
1513
|
+
owner: workspace,
|
1514
|
+
resolve: {
|
1515
|
+
projects: {
|
1516
|
+
$each: true,
|
1517
|
+
},
|
1518
|
+
},
|
1519
|
+
});
|
1520
|
+
assert(myOrg);
|
1521
|
+
expect(myOrg).not.toBeNull();
|
1522
|
+
expect(myOrg.name).toEqual("My organisation");
|
1523
|
+
expect(myOrg.projects.length).toBe(1);
|
1524
|
+
expect(myOrg.projects.at(0)?.name).toEqual("My project");
|
1525
|
+
|
1526
|
+
const updatedProject = await Project.upsertUnique({
|
1527
|
+
value: {
|
1528
|
+
name: "My updated project",
|
1529
|
+
},
|
1530
|
+
unique: { unique: "First project" },
|
1531
|
+
owner: workspace,
|
1532
|
+
});
|
1533
|
+
|
1534
|
+
assert(updatedProject);
|
1535
|
+
expect(updatedProject).not.toBeNull();
|
1536
|
+
expect(updatedProject).toEqual(initialProject);
|
1537
|
+
expect(updatedProject.name).toEqual("My updated project");
|
1538
|
+
expect(myOrg.projects.length).toBe(1);
|
1539
|
+
expect(myOrg.projects.at(0)?.name).toEqual("My updated project");
|
1540
|
+
});
|
1541
|
+
|
1542
|
+
test("upserting a partially loaded value on an new value with resolve", async () => {
|
1543
|
+
const Project = co.map({
|
1544
|
+
name: z.string(),
|
1545
|
+
});
|
1546
|
+
const Organisation = co.map({
|
1547
|
+
name: z.string(),
|
1548
|
+
projects: co.list(Project),
|
1549
|
+
});
|
1550
|
+
const publicAccess = Group.create();
|
1551
|
+
publicAccess.addMember("everyone", "writer");
|
1552
|
+
|
1553
|
+
const initialProject = await Project.upsertUnique({
|
1554
|
+
value: {
|
1555
|
+
name: "My project",
|
1556
|
+
},
|
1557
|
+
unique: { unique: "First project" },
|
1558
|
+
owner: publicAccess,
|
1559
|
+
});
|
1560
|
+
assert(initialProject);
|
1561
|
+
expect(initialProject).not.toBeNull();
|
1562
|
+
expect(initialProject.name).toEqual("My project");
|
1563
|
+
|
1564
|
+
const fullProjectList = co
|
1565
|
+
.list(Project)
|
1566
|
+
.create([initialProject], publicAccess);
|
1567
|
+
|
1568
|
+
const account = await createJazzTestAccount({
|
1569
|
+
isCurrentActiveAccount: true,
|
1570
|
+
});
|
1571
|
+
|
1572
|
+
const shallowProjectList = await co.list(Project).load(fullProjectList.id, {
|
1573
|
+
loadAs: account,
|
1574
|
+
});
|
1575
|
+
assert(shallowProjectList);
|
1576
|
+
|
1577
|
+
const publicAccessAsNewAccount = await Group.load(publicAccess.id, {
|
1578
|
+
loadAs: account,
|
1579
|
+
});
|
1580
|
+
assert(publicAccessAsNewAccount);
|
1581
|
+
|
1582
|
+
const updatedOrg = await Organisation.upsertUnique({
|
1583
|
+
value: {
|
1584
|
+
name: "My organisation",
|
1585
|
+
projects: shallowProjectList,
|
1586
|
+
},
|
1587
|
+
unique: { name: "My organisation" },
|
1588
|
+
owner: publicAccessAsNewAccount,
|
1589
|
+
resolve: {
|
1590
|
+
projects: {
|
1591
|
+
$each: true,
|
1592
|
+
},
|
1593
|
+
},
|
1594
|
+
});
|
1595
|
+
|
1596
|
+
assert(updatedOrg);
|
1597
|
+
|
1598
|
+
expect(updatedOrg.projects.id).toEqual(fullProjectList.id);
|
1599
|
+
expect(updatedOrg.projects.length).toBe(1);
|
1600
|
+
expect(updatedOrg.projects.at(0)?.name).toEqual("My project");
|
1601
|
+
});
|
1602
|
+
|
1603
|
+
test("upserting a partially loaded value on an existing value with resolve", async () => {
|
1604
|
+
const Project = co.map({
|
1605
|
+
name: z.string(),
|
1606
|
+
});
|
1607
|
+
const Organisation = co.map({
|
1608
|
+
name: z.string(),
|
1609
|
+
projects: co.list(Project),
|
1610
|
+
});
|
1611
|
+
const publicAccess = Group.create();
|
1612
|
+
publicAccess.addMember("everyone", "writer");
|
1613
|
+
|
1614
|
+
const initialProject = await Project.upsertUnique({
|
1615
|
+
value: {
|
1616
|
+
name: "My project",
|
1617
|
+
},
|
1618
|
+
unique: { unique: "First project" },
|
1619
|
+
owner: publicAccess,
|
1620
|
+
});
|
1621
|
+
assert(initialProject);
|
1622
|
+
expect(initialProject).not.toBeNull();
|
1623
|
+
expect(initialProject.name).toEqual("My project");
|
1624
|
+
|
1625
|
+
const myOrg = await Organisation.upsertUnique({
|
1626
|
+
value: {
|
1627
|
+
name: "My organisation",
|
1628
|
+
projects: co.list(Project).create([], publicAccess),
|
1629
|
+
},
|
1630
|
+
unique: { name: "My organisation" },
|
1631
|
+
owner: publicAccess,
|
1632
|
+
resolve: {
|
1633
|
+
projects: {
|
1634
|
+
$each: true,
|
1635
|
+
},
|
1636
|
+
},
|
1637
|
+
});
|
1638
|
+
assert(myOrg);
|
1639
|
+
|
1640
|
+
const fullProjectList = co
|
1641
|
+
.list(Project)
|
1642
|
+
.create([initialProject], publicAccess);
|
1643
|
+
|
1644
|
+
const account = await createJazzTestAccount({
|
1645
|
+
isCurrentActiveAccount: true,
|
1646
|
+
});
|
1647
|
+
|
1648
|
+
const shallowProjectList = await co.list(Project).load(fullProjectList.id, {
|
1649
|
+
loadAs: account,
|
1650
|
+
});
|
1651
|
+
assert(shallowProjectList);
|
1652
|
+
|
1653
|
+
const publicAccessAsNewAccount = await Group.load(publicAccess.id, {
|
1654
|
+
loadAs: account,
|
1655
|
+
});
|
1656
|
+
assert(publicAccessAsNewAccount);
|
1657
|
+
|
1658
|
+
const updatedOrg = await Organisation.upsertUnique({
|
1659
|
+
value: {
|
1660
|
+
name: "My organisation",
|
1661
|
+
projects: shallowProjectList,
|
1662
|
+
},
|
1663
|
+
unique: { name: "My organisation" },
|
1664
|
+
owner: publicAccessAsNewAccount,
|
1665
|
+
resolve: {
|
1666
|
+
projects: {
|
1667
|
+
$each: true,
|
1668
|
+
},
|
1669
|
+
},
|
1670
|
+
});
|
1671
|
+
|
1672
|
+
assert(updatedOrg);
|
1673
|
+
|
1674
|
+
expect(updatedOrg.projects.id).toEqual(fullProjectList.id);
|
1675
|
+
expect(updatedOrg.projects.length).toBe(1);
|
1676
|
+
expect(updatedOrg.projects.at(0)?.name).toEqual("My project");
|
1677
|
+
expect(updatedOrg.id).toEqual(myOrg.id);
|
1678
|
+
});
|
1679
|
+
|
1680
|
+
test("complex discriminated union", () => {
|
1681
|
+
const StringTag = co.map({
|
1682
|
+
type: z.literal("string"),
|
1683
|
+
stringValue: z.string(),
|
1684
|
+
});
|
1685
|
+
|
1686
|
+
const DateTag = co.map({
|
1687
|
+
type: z.literal("date"),
|
1688
|
+
dateValue: z.date(),
|
1689
|
+
repeat: z.optional(
|
1690
|
+
z.literal("daily").or(z.literal("weekly")).or(z.literal("monthly")),
|
1691
|
+
),
|
1692
|
+
});
|
1693
|
+
|
1694
|
+
const StringAttributeValue = co.map({
|
1695
|
+
type: z.literal(["somethingElse", "string"]),
|
1696
|
+
stringValue: z.string(),
|
1697
|
+
});
|
1698
|
+
|
1699
|
+
const NumberAttributeValue = co.map({
|
1700
|
+
type: z.literal("number"),
|
1701
|
+
numberValue: z.number(),
|
1702
|
+
});
|
1703
|
+
|
1704
|
+
const DateAttributeValue = co.map({
|
1705
|
+
type: z.literal("date"),
|
1706
|
+
dateValue: z.date(),
|
1707
|
+
});
|
1708
|
+
|
1709
|
+
const AttributeValue = z.discriminatedUnion("type", [
|
1710
|
+
StringAttributeValue,
|
1711
|
+
NumberAttributeValue,
|
1712
|
+
DateAttributeValue,
|
1713
|
+
]);
|
1714
|
+
|
1715
|
+
const AttributeTagKey = co.map({
|
1716
|
+
key: z.string(),
|
1717
|
+
});
|
1718
|
+
|
1719
|
+
const AttributeTag = co.map({
|
1720
|
+
type: z.literal("attribute"),
|
1721
|
+
key: AttributeTagKey, // this is a covalue so that it can be referenced uniquely by other tags
|
1722
|
+
attributeValue: AttributeValue,
|
1723
|
+
});
|
1724
|
+
|
1725
|
+
const Tag = z.discriminatedUnion("type", [
|
1726
|
+
AttributeTag,
|
1727
|
+
StringTag,
|
1728
|
+
DateTag,
|
1729
|
+
]);
|
1730
|
+
|
1731
|
+
const Wrapper = co.map({
|
1732
|
+
tag: Tag,
|
1733
|
+
});
|
1734
|
+
|
1735
|
+
const wrapper = Wrapper.create({
|
1736
|
+
tag: AttributeTag.create({
|
1737
|
+
type: "attribute",
|
1738
|
+
key: AttributeTagKey.create({ key: "name" }),
|
1739
|
+
attributeValue: StringAttributeValue.create({
|
1740
|
+
type: "string",
|
1741
|
+
stringValue: "Alice",
|
1742
|
+
}),
|
1743
|
+
}),
|
1744
|
+
});
|
1745
|
+
|
1746
|
+
if (wrapper.tag.type === "attribute") {
|
1747
|
+
expect(wrapper.tag.key.key).toEqual("name");
|
1748
|
+
if (wrapper.tag.attributeValue.type === "string") {
|
1749
|
+
expect(wrapper.tag.attributeValue.stringValue).toEqual("Alice");
|
1750
|
+
}
|
1751
|
+
}
|
1752
|
+
});
|
1753
|
+
|
1754
|
+
test("complex discriminated union with numeric discriminator value", () => {
|
1755
|
+
const HttpError = co.map({
|
1756
|
+
code: z.number(),
|
1757
|
+
message: z.string(),
|
1758
|
+
});
|
1759
|
+
|
1760
|
+
const ClientError = co.map({
|
1761
|
+
type: z.literal(400),
|
1762
|
+
error: HttpError,
|
1763
|
+
});
|
1764
|
+
|
1765
|
+
const ServerError = co.map({
|
1766
|
+
type: z.literal(500),
|
1767
|
+
error: HttpError,
|
1768
|
+
});
|
1769
|
+
|
1770
|
+
const NetworkError = co.map({
|
1771
|
+
type: z.literal(0),
|
1772
|
+
error: HttpError,
|
1773
|
+
});
|
1774
|
+
|
1775
|
+
const ErrorResponse = z.discriminatedUnion("type", [
|
1776
|
+
ClientError,
|
1777
|
+
ServerError,
|
1778
|
+
NetworkError,
|
1779
|
+
]);
|
1780
|
+
|
1781
|
+
const ErrorWrapper = co.map({
|
1782
|
+
response: ErrorResponse,
|
1783
|
+
});
|
1784
|
+
|
1785
|
+
const wrapper = ErrorWrapper.create({
|
1786
|
+
response: ClientError.create({
|
1787
|
+
type: 400,
|
1788
|
+
error: HttpError.create({
|
1789
|
+
code: 400,
|
1790
|
+
message: "Bad Request",
|
1791
|
+
}),
|
1792
|
+
}),
|
1793
|
+
});
|
1794
|
+
|
1795
|
+
if (wrapper.response.type === 400) {
|
1796
|
+
expect(wrapper.response.error.code).toEqual(400);
|
1797
|
+
expect(wrapper.response.error.message).toEqual("Bad Request");
|
1798
|
+
}
|
1799
|
+
|
1800
|
+
const serverErrorWrapper = ErrorWrapper.create({
|
1801
|
+
response: ServerError.create({
|
1802
|
+
type: 500,
|
1803
|
+
error: HttpError.create({
|
1804
|
+
code: 500,
|
1805
|
+
message: "Internal Server Error",
|
1806
|
+
}),
|
1807
|
+
}),
|
1808
|
+
});
|
1809
|
+
|
1810
|
+
if (serverErrorWrapper.response.type === 500) {
|
1811
|
+
expect(serverErrorWrapper.response.error.code).toEqual(500);
|
1812
|
+
expect(serverErrorWrapper.response.error.message).toEqual(
|
1813
|
+
"Internal Server Error",
|
1814
|
+
);
|
1815
|
+
}
|
1816
|
+
|
1817
|
+
const networkErrorWrapper = ErrorWrapper.create({
|
1818
|
+
response: NetworkError.create({
|
1819
|
+
type: 0,
|
1820
|
+
error: HttpError.create({
|
1821
|
+
code: 0,
|
1822
|
+
message: "Network Error",
|
1823
|
+
}),
|
1824
|
+
}),
|
1825
|
+
});
|
1826
|
+
|
1827
|
+
if (networkErrorWrapper.response.type === 0) {
|
1828
|
+
expect(networkErrorWrapper.response.error.code).toEqual(0);
|
1829
|
+
expect(networkErrorWrapper.response.error.message).toEqual(
|
1830
|
+
"Network Error",
|
1831
|
+
);
|
1832
|
+
}
|
1833
|
+
});
|
1834
|
+
});
|
1835
|
+
|
1836
|
+
describe("castAs", () => {
|
1837
|
+
test("should cast a co.map type", () => {
|
1838
|
+
const Person = co.map({
|
1839
|
+
name: z.string(),
|
1840
|
+
});
|
1841
|
+
|
1842
|
+
const PersonWithAge = co.map({
|
1843
|
+
name: z.string(),
|
1844
|
+
age: z.number().optional(),
|
1845
|
+
});
|
1846
|
+
|
1847
|
+
const person = Person.create({
|
1848
|
+
name: "Alice",
|
1849
|
+
});
|
1850
|
+
|
1851
|
+
const personWithAge = person.castAs(PersonWithAge);
|
1852
|
+
|
1853
|
+
personWithAge.age = 20;
|
1854
|
+
|
1855
|
+
expect(personWithAge.age).toEqual(20);
|
1856
|
+
});
|
1857
|
+
|
1858
|
+
test("should still be able to autoload in-memory deps", () => {
|
1859
|
+
const Dog = co.map({
|
1860
|
+
name: z.string(),
|
1861
|
+
});
|
1862
|
+
|
1863
|
+
const Person = co.map({
|
1864
|
+
name: z.string(),
|
1865
|
+
dog: Dog,
|
1866
|
+
});
|
1867
|
+
|
1868
|
+
const PersonWithAge = co.map({
|
1869
|
+
name: z.string(),
|
1870
|
+
age: z.number().optional(),
|
1871
|
+
dog: Dog,
|
1872
|
+
});
|
1873
|
+
|
1874
|
+
const person = Person.create({
|
1875
|
+
name: "Alice",
|
1876
|
+
dog: Dog.create({ name: "Rex" }),
|
1877
|
+
});
|
1878
|
+
|
1879
|
+
const personWithAge = person.castAs(PersonWithAge);
|
1880
|
+
|
1881
|
+
personWithAge.age = 20;
|
1882
|
+
|
1883
|
+
expect(personWithAge.age).toEqual(20);
|
1884
|
+
expect(personWithAge.dog?.name).toEqual("Rex");
|
1885
|
+
});
|
1886
|
+
});
|
1887
|
+
|
1888
|
+
describe("CoMap migration", () => {
|
1889
|
+
test("should run on load", async () => {
|
1890
|
+
const PersonV1 = co.map({
|
1891
|
+
name: z.string(),
|
1892
|
+
version: z.literal(1),
|
1893
|
+
});
|
1894
|
+
|
1895
|
+
const Person = co
|
1896
|
+
.map({
|
1897
|
+
name: z.string(),
|
1898
|
+
age: z.number(),
|
1899
|
+
version: z.literal([1, 2]),
|
1900
|
+
})
|
1901
|
+
.withMigration((person) => {
|
1902
|
+
if (person.version === 1) {
|
1903
|
+
person.age = 20;
|
1904
|
+
person.version = 2;
|
1905
|
+
}
|
1906
|
+
});
|
1907
|
+
|
1908
|
+
const person = PersonV1.create({
|
1909
|
+
name: "Bob",
|
1910
|
+
version: 1,
|
1911
|
+
});
|
1912
|
+
|
1913
|
+
expect(person?.name).toEqual("Bob");
|
1914
|
+
expect(person?.version).toEqual(1);
|
1915
|
+
|
1916
|
+
const loadedPerson = await Person.load(person.id);
|
1917
|
+
|
1918
|
+
expect(loadedPerson?.name).toEqual("Bob");
|
1919
|
+
expect(loadedPerson?.age).toEqual(20);
|
1920
|
+
expect(loadedPerson?.version).toEqual(2);
|
1921
|
+
});
|
1922
|
+
|
1923
|
+
test("should handle group updates", async () => {
|
1924
|
+
const Person = co
|
1925
|
+
.map({
|
1926
|
+
name: z.string(),
|
1927
|
+
version: z.literal([1, 2]),
|
1928
|
+
})
|
1929
|
+
.withMigration((person) => {
|
1930
|
+
if (person.version === 1) {
|
1931
|
+
person.version = 2;
|
1932
|
+
|
1933
|
+
person._owner.castAs(Group).addMember("everyone", "reader");
|
1934
|
+
}
|
1935
|
+
});
|
1936
|
+
|
1937
|
+
const person = Person.create({
|
1938
|
+
name: "Bob",
|
1939
|
+
version: 1,
|
1940
|
+
});
|
1941
|
+
|
1942
|
+
expect(person?.name).toEqual("Bob");
|
1943
|
+
expect(person?.version).toEqual(1);
|
1944
|
+
|
1945
|
+
const loadedPerson = await Person.load(person.id);
|
1946
|
+
|
1947
|
+
expect(loadedPerson?.name).toEqual("Bob");
|
1948
|
+
expect(loadedPerson?.version).toEqual(2);
|
1949
|
+
|
1950
|
+
const anotherAccount = await createJazzTestAccount();
|
1951
|
+
|
1952
|
+
const loadedPersonFromAnotherAccount = await Person.load(person.id, {
|
1953
|
+
loadAs: anotherAccount,
|
1954
|
+
});
|
1955
|
+
|
1956
|
+
expect(loadedPersonFromAnotherAccount?.name).toEqual("Bob");
|
1957
|
+
});
|
1958
|
+
|
1959
|
+
test("should throw an error if a migration is async", async () => {
|
1960
|
+
const Person = co
|
1961
|
+
.map({
|
1962
|
+
name: z.string(),
|
1963
|
+
version: z.number(),
|
1964
|
+
})
|
1965
|
+
// @ts-expect-error async function
|
1966
|
+
.withMigration(async () => {});
|
1967
|
+
|
1968
|
+
const person = Person.create({
|
1969
|
+
name: "Bob",
|
1970
|
+
version: 1,
|
1971
|
+
});
|
1972
|
+
|
1973
|
+
await expect(Person.load(person.id)).rejects.toThrow(
|
1974
|
+
"Migration function cannot be async",
|
1975
|
+
);
|
1976
|
+
});
|
1977
|
+
|
1978
|
+
test("should run only once", async () => {
|
1979
|
+
const spy = vi.fn();
|
1980
|
+
const Person = co
|
1981
|
+
.map({
|
1982
|
+
name: z.string(),
|
1983
|
+
version: z.number(),
|
1984
|
+
})
|
1985
|
+
.withMigration((person) => {
|
1986
|
+
spy(person);
|
1987
|
+
});
|
1988
|
+
|
1989
|
+
const person = Person.create({
|
1990
|
+
name: "Bob",
|
1991
|
+
version: 1,
|
1992
|
+
});
|
1993
|
+
|
1994
|
+
await Person.load(person.id);
|
1995
|
+
await Person.load(person.id);
|
1996
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
1997
|
+
});
|
1998
|
+
|
1999
|
+
test("should not break recursive schemas", async () => {
|
2000
|
+
const PersonV1 = co.map({
|
2001
|
+
name: z.string(),
|
2002
|
+
version: z.literal(1),
|
2003
|
+
get friend() {
|
2004
|
+
return PersonV1.optional();
|
2005
|
+
},
|
2006
|
+
});
|
2007
|
+
|
2008
|
+
const Person = co
|
2009
|
+
.map({
|
2010
|
+
name: z.string(),
|
2011
|
+
age: z.number(),
|
2012
|
+
get friend() {
|
2013
|
+
return Person.optional();
|
2014
|
+
},
|
2015
|
+
version: z.literal([1, 2]),
|
2016
|
+
})
|
2017
|
+
.withMigration((person) => {
|
2018
|
+
if (person.version === 1) {
|
2019
|
+
person.age = 20;
|
2020
|
+
person.version = 2;
|
2021
|
+
}
|
2022
|
+
});
|
2023
|
+
|
2024
|
+
const charlie = PersonV1.create({
|
2025
|
+
name: "Charlie",
|
2026
|
+
version: 1,
|
2027
|
+
});
|
2028
|
+
|
2029
|
+
const bob = PersonV1.create({
|
2030
|
+
name: "Bob",
|
2031
|
+
version: 1,
|
2032
|
+
friend: charlie,
|
2033
|
+
});
|
2034
|
+
|
2035
|
+
const loaded = await Person.load(bob.id, {
|
2036
|
+
resolve: {
|
2037
|
+
friend: true,
|
2038
|
+
},
|
2039
|
+
});
|
2040
|
+
|
2041
|
+
// Migration should run on both the person and their friend
|
2042
|
+
expect(loaded?.name).toEqual("Bob");
|
2043
|
+
expect(loaded?.age).toEqual(20);
|
2044
|
+
expect(loaded?.version).toEqual(2);
|
2045
|
+
expect(loaded?.friend?.name).toEqual("Charlie");
|
2046
|
+
expect(loaded?.friend?.version).toEqual(2);
|
2047
|
+
});
|
2048
|
+
describe("Time", () => {
|
2049
|
+
test("empty map created time", () => {
|
2050
|
+
const currentTimestampInSeconds = Math.floor(Date.now() / 1000);
|
2051
|
+
const emptyMap = co.map({}).create({});
|
2052
|
+
const createdAtInSeconds = Math.floor(emptyMap._createdAt / 1000);
|
2053
|
+
|
2054
|
+
expect(createdAtInSeconds).toEqual(currentTimestampInSeconds);
|
2055
|
+
expect(emptyMap._lastUpdatedAt).toEqual(emptyMap._createdAt);
|
2056
|
+
});
|
2057
|
+
|
2058
|
+
test("created time and last updated time", async () => {
|
2059
|
+
const Person = co.map({
|
2060
|
+
name: z.string(),
|
2061
|
+
});
|
2062
|
+
|
2063
|
+
let currentTimestampInSeconds = Math.floor(Date.now() / 1000);
|
2064
|
+
const person = Person.create({ name: "John" });
|
2065
|
+
|
2066
|
+
const createdAt = person._createdAt;
|
2067
|
+
const createdAtInSeconds = Math.floor(createdAt / 1000);
|
2068
|
+
expect(createdAtInSeconds).toEqual(currentTimestampInSeconds);
|
2069
|
+
expect(person._lastUpdatedAt).toEqual(createdAt);
|
2070
|
+
|
2071
|
+
await new Promise((r) => setTimeout(r, 1000));
|
2072
|
+
currentTimestampInSeconds = Math.floor(Date.now() / 1000);
|
2073
|
+
person.name = "Jane";
|
2074
|
+
|
2075
|
+
const lastUpdatedAtInSeconds = Math.floor(person._lastUpdatedAt / 1000);
|
2076
|
+
expect(lastUpdatedAtInSeconds).toEqual(currentTimestampInSeconds);
|
2077
|
+
expect(person._createdAt).toEqual(createdAt);
|
2078
|
+
expect(person._lastUpdatedAt).not.toEqual(createdAt);
|
2079
|
+
});
|
2080
|
+
|
2081
|
+
test("comap with custom uniqueness", () => {
|
2082
|
+
const Person = co.map({
|
2083
|
+
name: z.string(),
|
2084
|
+
});
|
2085
|
+
|
2086
|
+
let currentTimestampInSeconds = Math.floor(Date.now() / 1000);
|
2087
|
+
const person = Person.create(
|
2088
|
+
{ name: "John" },
|
2089
|
+
{ unique: "name", owner: Account.getMe() },
|
2090
|
+
);
|
2091
|
+
|
2092
|
+
const createdAt = person._createdAt;
|
2093
|
+
const createdAtInSeconds = Math.floor(createdAt / 1000);
|
2094
|
+
expect(createdAtInSeconds).toEqual(currentTimestampInSeconds);
|
2095
|
+
});
|
2096
|
+
|
2097
|
+
test("empty comap with custom uniqueness", () => {
|
2098
|
+
const Person = co.map({
|
2099
|
+
name: z.optional(z.string()),
|
2100
|
+
});
|
2101
|
+
|
2102
|
+
let currentTimestampInSeconds = Math.floor(Date.now() / 1000);
|
2103
|
+
const person = Person.create(
|
2104
|
+
{},
|
2105
|
+
{ unique: "name", owner: Account.getMe() },
|
2106
|
+
);
|
2107
|
+
|
2108
|
+
const createdAt = person._createdAt;
|
2109
|
+
const createdAtInSeconds = Math.floor(createdAt / 1000);
|
2110
|
+
expect(createdAtInSeconds).toEqual(currentTimestampInSeconds);
|
2111
|
+
});
|
2112
|
+
});
|
2113
|
+
});
|