@lapis-notes/api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE.md +4 -0
- package/README.md +43 -0
- package/dist/__tests__/data-adapter-conformance.js +205 -0
- package/dist/__tests__/lapis-runtime-manifest.js +32 -0
- package/dist/__tests__/svelte-internal-client.d.ts +3 -0
- package/dist/agent-result-views.d.ts +52 -0
- package/dist/agent-result-views.js +89 -0
- package/dist/agent-skills.d.ts +99 -0
- package/dist/agent-skills.js +182 -0
- package/dist/agent-tools.d.ts +92 -0
- package/dist/agent-tools.js +139 -0
- package/dist/app-database-host.d.ts +4 -0
- package/dist/app-database-host.js +4 -0
- package/dist/app-shell-plugin-persistence.d.ts +15 -0
- package/dist/app-shell-plugin-persistence.js +34 -0
- package/dist/app-url.d.ts +54 -0
- package/dist/app-url.js +269 -0
- package/dist/application-compatibility.d.ts +31 -0
- package/dist/application-compatibility.js +64 -0
- package/dist/application-state.svelte.d.ts +14 -0
- package/dist/application-state.svelte.js +30 -0
- package/dist/assets/lapis-logo.svg +471 -0
- package/dist/bases.d.ts +281 -0
- package/dist/bases.js +475 -0
- package/dist/cache.svelte.d.ts +569 -0
- package/dist/cache.svelte.js +1433 -0
- package/dist/command.svelte.d.ts +337 -0
- package/dist/command.svelte.js +571 -0
- package/dist/compat.d.ts +29 -0
- package/dist/compat.js +30 -0
- package/dist/components/configuration/configuration.css +199 -0
- package/dist/components/configuration/date-setting.svelte +71 -0
- package/dist/components/configuration/date-setting.svelte.d.ts +8 -0
- package/dist/components/configuration/list-setting.svelte +128 -0
- package/dist/components/configuration/list-setting.svelte.d.ts +13 -0
- package/dist/components/configuration/object-array-row-grip.svelte +78 -0
- package/dist/components/configuration/object-array-row-grip.svelte.d.ts +9 -0
- package/dist/components/configuration/object-array-row.svelte +163 -0
- package/dist/components/configuration/object-array-row.svelte.d.ts +19 -0
- package/dist/components/configuration/object-array-setting.svelte +196 -0
- package/dist/components/configuration/object-array-setting.svelte.d.ts +15 -0
- package/dist/components/configuration/object-array-table-dnd.d.ts +8 -0
- package/dist/components/configuration/object-array-table-dnd.js +10 -0
- package/dist/components/configuration/object-array-utils.d.ts +11 -0
- package/dist/components/configuration/object-array-utils.js +103 -0
- package/dist/components/configuration/object-grid-setting.svelte +79 -0
- package/dist/components/configuration/object-grid-setting.svelte.d.ts +10 -0
- package/dist/components/configuration/object-map-row.svelte +147 -0
- package/dist/components/configuration/object-map-row.svelte.d.ts +15 -0
- package/dist/components/configuration/object-map-setting.svelte +137 -0
- package/dist/components/configuration/object-map-setting.svelte.d.ts +14 -0
- package/dist/components/configuration/object-map-types.d.ts +5 -0
- package/dist/components/configuration/object-map-types.js +1 -0
- package/dist/components/configuration/options-combobox-setting.svelte +129 -0
- package/dist/components/configuration/options-combobox-setting.svelte.d.ts +12 -0
- package/dist/components/copy-button/button.svelte +93 -0
- package/dist/components/copy-button/button.svelte.d.ts +13 -0
- package/dist/components/copy-button/index.d.ts +2 -0
- package/dist/components/copy-button/index.js +2 -0
- package/dist/components/editor/editor.css +565 -0
- package/dist/components/editor/editor.d.ts +33 -0
- package/dist/components/editor/editor.js +132 -0
- package/dist/components/editor/editor.svelte +176 -0
- package/dist/components/editor/editor.svelte.d.ts +15 -0
- package/dist/components/editor/embedded-editor-surface.d.ts +12 -0
- package/dist/components/editor/embedded-editor-surface.js +22 -0
- package/dist/components/editor/embedded-editor-surface.svelte +115 -0
- package/dist/components/editor/embedded-editor-surface.svelte.d.ts +17 -0
- package/dist/components/editor/extensions/autocomplete/index.d.ts +2 -0
- package/dist/components/editor/extensions/autocomplete/index.js +2 -0
- package/dist/components/editor/extensions/autocomplete/lapis-code-mirror-autocomplete.d.ts +16 -0
- package/dist/components/editor/extensions/autocomplete/lapis-code-mirror-autocomplete.js +34 -0
- package/dist/components/editor/extensions/autocomplete/vault-completion-sources.d.ts +27 -0
- package/dist/components/editor/extensions/autocomplete/vault-completion-sources.js +55 -0
- package/dist/components/editor/extensions/class-highlighter/index.d.ts +1 -0
- package/dist/components/editor/extensions/class-highlighter/index.js +47 -0
- package/dist/components/editor/extensions/fold-gutter/index.d.ts +8 -0
- package/dist/components/editor/extensions/fold-gutter/index.js +40 -0
- package/dist/components/editor/extensions/gutter-line-style-sync/index.d.ts +2 -0
- package/dist/components/editor/extensions/gutter-line-style-sync/index.js +118 -0
- package/dist/components/editor/extensions/lint/index.d.ts +4 -0
- package/dist/components/editor/extensions/lint/index.js +4 -0
- package/dist/components/editor/extensions/lint/lapis-code-mirror-lint.d.ts +26 -0
- package/dist/components/editor/extensions/lint/lapis-code-mirror-lint.js +101 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic-helpers.d.ts +8 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic-helpers.js +7 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic.d.ts +20 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic.js +47 -0
- package/dist/components/editor/extensions/lint/lapis-lint-hover-tooltip.d.ts +9 -0
- package/dist/components/editor/extensions/lint/lapis-lint-hover-tooltip.js +373 -0
- package/dist/components/editor/extensions/lint/lapis-lint-inline-widget.d.ts +31 -0
- package/dist/components/editor/extensions/lint/lapis-lint-inline-widget.js +191 -0
- package/dist/components/editor/extensions/lint/lapis-lint-tooltip.svelte +176 -0
- package/dist/components/editor/extensions/lint/lapis-lint-tooltip.svelte.d.ts +15 -0
- package/dist/components/editor/extensions/lint/lint-tooltip-actions.d.ts +11 -0
- package/dist/components/editor/extensions/lint/lint-tooltip-actions.js +21 -0
- package/dist/components/editor/extensions/lint/mount-lint-tooltip.d.ts +16 -0
- package/dist/components/editor/extensions/lint/mount-lint-tooltip.js +60 -0
- package/dist/components/editor/extensions/search/dom.d.ts +2 -0
- package/dist/components/editor/extensions/search/dom.js +6 -0
- package/dist/components/editor/extensions/search/index.d.ts +35 -0
- package/dist/components/editor/extensions/search/index.js +44 -0
- package/dist/components/editor/extensions/search/search.svelte +335 -0
- package/dist/components/editor/extensions/search/search.svelte.d.ts +8 -0
- package/dist/components/editor/index.d.ts +9 -0
- package/dist/components/editor/index.js +9 -0
- package/dist/components/editor/language-service/dom.d.ts +1 -0
- package/dist/components/editor/language-service/dom.js +6 -0
- package/dist/components/editor/language-service/index.d.ts +28 -0
- package/dist/components/editor/language-service/index.js +342 -0
- package/dist/components/empty-view/empty-view.css +39 -0
- package/dist/components/empty-view/empty-view.svelte +26 -0
- package/dist/components/empty-view/empty-view.svelte.d.ts +9 -0
- package/dist/components/empty-view/index.d.ts +2 -0
- package/dist/components/empty-view/index.js +2 -0
- package/dist/components/icon/icon-list.css +74 -0
- package/dist/components/icon/icon-list.svelte +213 -0
- package/dist/components/icon/icon-list.svelte.d.ts +11 -0
- package/dist/components/icon/icon.svelte +15 -0
- package/dist/components/icon/icon.svelte.d.ts +7 -0
- package/dist/components/icon/index.d.ts +3 -0
- package/dist/components/icon/index.js +3 -0
- package/dist/components/menu/context-menu.svelte +89 -0
- package/dist/components/menu/context-menu.svelte.d.ts +11 -0
- package/dist/components/menu/drawer-menu.svelte +83 -0
- package/dist/components/menu/drawer-menu.svelte.d.ts +8 -0
- package/dist/components/menu/dropdown-menu.svelte +89 -0
- package/dist/components/menu/dropdown-menu.svelte.d.ts +11 -0
- package/dist/components/menu/index.d.ts +6 -0
- package/dist/components/menu/index.js +6 -0
- package/dist/components/menu/menu.css +139 -0
- package/dist/components/menu/menu.svelte +37 -0
- package/dist/components/menu/menu.svelte.d.ts +11 -0
- package/dist/components/menu/mobile-menu-query.svelte.d.ts +3 -0
- package/dist/components/menu/mobile-menu-query.svelte.js +21 -0
- package/dist/components/menu/popover-menu.svelte +90 -0
- package/dist/components/menu/popover-menu.svelte.d.ts +10 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/index.js +2 -0
- package/dist/components/select/select.svelte +72 -0
- package/dist/components/select/select.svelte.d.ts +25 -0
- package/dist/configuration-option-source-providers.d.ts +17 -0
- package/dist/configuration-option-source-providers.js +59 -0
- package/dist/configuration-option-source-registry.d.ts +59 -0
- package/dist/configuration-option-source-registry.js +123 -0
- package/dist/configuration.svelte.d.ts +258 -0
- package/dist/configuration.svelte.js +887 -0
- package/dist/context-keys.svelte.d.ts +42 -0
- package/dist/context-keys.svelte.js +278 -0
- package/dist/context.svelte.d.ts +247 -0
- package/dist/context.svelte.js +540 -0
- package/dist/daily-document-provider.d.ts +38 -0
- package/dist/daily-document-provider.js +176 -0
- package/dist/design-core-button-types.d.ts +7 -0
- package/dist/design-core-button-types.js +1 -0
- package/dist/diagnostics.d.ts +93 -0
- package/dist/diagnostics.js +84 -0
- package/dist/dialog-portal.d.ts +3 -0
- package/dist/dialog-portal.js +3 -0
- package/dist/docs-api.d.ts +44 -0
- package/dist/docs-api.js +29 -0
- package/dist/editor-view-registry.d.ts +35 -0
- package/dist/editor-view-registry.js +112 -0
- package/dist/editor.svelte.d.ts +126 -0
- package/dist/editor.svelte.js +454 -0
- package/dist/embed-registry.d.ts +15 -0
- package/dist/embed-registry.js +16 -0
- package/dist/enhance.d.ts +111 -0
- package/dist/enhance.js +309 -0
- package/dist/events.d.ts +28 -0
- package/dist/events.js +49 -0
- package/dist/file-manager.d.ts +90 -0
- package/dist/file-manager.js +289 -0
- package/dist/file-tools/app-tools.d.ts +3 -0
- package/dist/file-tools/app-tools.js +242 -0
- package/dist/file-tools/index.d.ts +3 -0
- package/dist/file-tools/index.js +3 -0
- package/dist/file-tools/paths.d.ts +14 -0
- package/dist/file-tools/paths.js +33 -0
- package/dist/file-tools/vault-operations.d.ts +3 -0
- package/dist/file-tools/vault-operations.js +60 -0
- package/dist/generated/plugin-host-modules.schema.generated.d.ts +371 -0
- package/dist/generated/plugin-host-modules.schema.generated.js +374 -0
- package/dist/glob.d.ts +15 -0
- package/dist/glob.js +68 -0
- package/dist/history.svelte.d.ts +24 -0
- package/dist/history.svelte.js +74 -0
- package/dist/hooks/createVirtualizer.svelte.d.ts +7 -0
- package/dist/hooks/createVirtualizer.svelte.js +70 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/is-mobile.svelte.d.ts +5 -0
- package/dist/hooks/is-mobile.svelte.js +23 -0
- package/dist/hooks/mountComponent.svelte.d.ts +7 -0
- package/dist/hooks/mountComponent.svelte.js +16 -0
- package/dist/hooks/use-text-highlight.d.ts +17 -0
- package/dist/hooks/use-text-highlight.js +82 -0
- package/dist/hooks/useBoundingRect.svelte.d.ts +11 -0
- package/dist/hooks/useBoundingRect.svelte.js +46 -0
- package/dist/icons/index.d.ts +57 -0
- package/dist/icons/index.js +288 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +87 -0
- package/dist/language-service/index.d.ts +9 -0
- package/dist/language-service/index.js +7 -0
- package/dist/language-service/manager.d.ts +47 -0
- package/dist/language-service/manager.js +404 -0
- package/dist/language-service/types.d.ts +92 -0
- package/dist/language-service/types.js +1 -0
- package/dist/language-service/virtual-document.d.ts +11 -0
- package/dist/language-service/virtual-document.js +45 -0
- package/dist/language-service/worker-protocol.d.ts +63 -0
- package/dist/language-service/worker-protocol.js +1 -0
- package/dist/language-service/worker-provider.d.ts +9 -0
- package/dist/language-service/worker-provider.js +38 -0
- package/dist/lapis-extension.d.ts +244 -0
- package/dist/lapis-extension.js +591 -0
- package/dist/links.d.ts +34 -0
- package/dist/links.js +191 -0
- package/dist/loaders.d.ts +9 -0
- package/dist/loaders.js +59 -0
- package/dist/localization-manager.svelte.d.ts +56 -0
- package/dist/localization-manager.svelte.js +157 -0
- package/dist/logging.d.ts +172 -0
- package/dist/logging.js +352 -0
- package/dist/markdown-extension-registry.d.ts +31 -0
- package/dist/markdown-extension-registry.js +31 -0
- package/dist/markdown-file-surface-registry.d.ts +25 -0
- package/dist/markdown-file-surface-registry.js +23 -0
- package/dist/markdown.d.ts +205 -0
- package/dist/markdown.js +147 -0
- package/dist/menu-utils.d.ts +1 -0
- package/dist/menu-utils.js +47 -0
- package/dist/menu.svelte.d.ts +121 -0
- package/dist/menu.svelte.js +295 -0
- package/dist/metadata-value.d.ts +10 -0
- package/dist/metadata-value.js +173 -0
- package/dist/metadata.svelte.d.ts +106 -0
- package/dist/metadata.svelte.js +608 -0
- package/dist/notifications.d.ts +209 -0
- package/dist/notifications.js +338 -0
- package/dist/open-file.d.ts +23 -0
- package/dist/open-file.js +102 -0
- package/dist/platform.d.ts +86 -0
- package/dist/platform.js +86 -0
- package/dist/plugin-asset-server.d.ts +60 -0
- package/dist/plugin-asset-server.js +222 -0
- package/dist/plugin-assets.d.ts +4 -0
- package/dist/plugin-assets.js +3 -0
- package/dist/plugin-capability-facade.d.ts +104 -0
- package/dist/plugin-capability-facade.js +61 -0
- package/dist/plugin-dependency-resolver.d.ts +36 -0
- package/dist/plugin-dependency-resolver.js +54 -0
- package/dist/plugin-dependency-scanner.d.ts +9 -0
- package/dist/plugin-dependency-scanner.js +274 -0
- package/dist/plugin-distribution/canonical-json.d.ts +1 -0
- package/dist/plugin-distribution/canonical-json.js +40 -0
- package/dist/plugin-distribution/compatibility.d.ts +5 -0
- package/dist/plugin-distribution/compatibility.js +38 -0
- package/dist/plugin-distribution/errors.d.ts +11 -0
- package/dist/plugin-distribution/errors.js +13 -0
- package/dist/plugin-distribution/hashes.d.ts +2 -0
- package/dist/plugin-distribution/hashes.js +17 -0
- package/dist/plugin-distribution/index.d.ts +18 -0
- package/dist/plugin-distribution/index.js +18 -0
- package/dist/plugin-distribution/installed-plugin-state.d.ts +20 -0
- package/dist/plugin-distribution/installed-plugin-state.js +73 -0
- package/dist/plugin-distribution/installer.d.ts +89 -0
- package/dist/plugin-distribution/installer.js +395 -0
- package/dist/plugin-distribution/manager.d.ts +128 -0
- package/dist/plugin-distribution/manager.js +358 -0
- package/dist/plugin-distribution/path-safety.d.ts +2 -0
- package/dist/plugin-distribution/path-safety.js +20 -0
- package/dist/plugin-distribution/plugin-bundle-verifier.d.ts +28 -0
- package/dist/plugin-distribution/plugin-bundle-verifier.js +96 -0
- package/dist/plugin-distribution/plugin-bundle-worker.d.ts +34 -0
- package/dist/plugin-distribution/plugin-bundle-worker.js +99 -0
- package/dist/plugin-distribution/plugin-bundle.d.ts +16 -0
- package/dist/plugin-distribution/plugin-bundle.js +244 -0
- package/dist/plugin-distribution/plugin-bundle.worker.d.ts +1 -0
- package/dist/plugin-distribution/plugin-bundle.worker.js +38 -0
- package/dist/plugin-distribution/registry-cache.d.ts +26 -0
- package/dist/plugin-distribution/registry-cache.js +85 -0
- package/dist/plugin-distribution/registry-client.d.ts +36 -0
- package/dist/plugin-distribution/registry-client.js +115 -0
- package/dist/plugin-distribution/reserved-ids.d.ts +4 -0
- package/dist/plugin-distribution/reserved-ids.js +10 -0
- package/dist/plugin-distribution/runtime-validation.d.ts +14 -0
- package/dist/plugin-distribution/runtime-validation.js +388 -0
- package/dist/plugin-distribution/schemas.d.ts +4895 -0
- package/dist/plugin-distribution/schemas.js +299 -0
- package/dist/plugin-distribution/signing.d.ts +5 -0
- package/dist/plugin-distribution/signing.js +38 -0
- package/dist/plugin-distribution/types.d.ts +217 -0
- package/dist/plugin-distribution/types.js +1 -0
- package/dist/plugin-install-progress.d.ts +15 -0
- package/dist/plugin-install-progress.js +86 -0
- package/dist/plugin-manager.d.ts +306 -0
- package/dist/plugin-manager.js +2848 -0
- package/dist/plugin-runtime-entry.d.ts +19 -0
- package/dist/plugin-runtime-entry.js +135 -0
- package/dist/plugin.d.ts +350 -0
- package/dist/plugin.js +754 -0
- package/dist/popover.d.ts +20 -0
- package/dist/popover.js +32 -0
- package/dist/promise-worker.d.ts +22 -0
- package/dist/promise-worker.js +65 -0
- package/dist/prompt-confirm.d.ts +9 -0
- package/dist/prompt-confirm.js +33 -0
- package/dist/search-document-provider.d.ts +45 -0
- package/dist/search-document-provider.js +54 -0
- package/dist/search-query/index.d.ts +78 -0
- package/dist/search-query/index.js +426 -0
- package/dist/search-query/parser.d.ts +3 -0
- package/dist/search-query/parser.js +16 -0
- package/dist/search-query/parser.terms.js +26 -0
- package/dist/search-query/search-query.grammar +128 -0
- package/dist/search.d.ts +19 -0
- package/dist/search.js +104 -0
- package/dist/setting-section-layout.d.ts +19 -0
- package/dist/setting-section-layout.js +194 -0
- package/dist/settings.svelte.d.ts +474 -0
- package/dist/settings.svelte.js +1421 -0
- package/dist/source-text-file-view.d.ts +25 -0
- package/dist/source-text-file-view.js +78 -0
- package/dist/status-bar.svelte.d.ts +29 -0
- package/dist/status-bar.svelte.js +72 -0
- package/dist/storage/app-database.d.ts +860 -0
- package/dist/storage/app-database.js +2372 -0
- package/dist/storage/blob-store.d.ts +12 -0
- package/dist/storage/blob-store.js +1 -0
- package/dist/storage/browser-app-database-coordination.d.ts +35 -0
- package/dist/storage/browser-app-database-coordination.js +207 -0
- package/dist/storage/browser-coordinated-app-database.d.ts +109 -0
- package/dist/storage/browser-coordinated-app-database.js +704 -0
- package/dist/storage/browser.d.ts +153 -0
- package/dist/storage/browser.js +794 -0
- package/dist/storage/desktop-native.d.ts +184 -0
- package/dist/storage/desktop-native.js +415 -0
- package/dist/storage/fs.d.ts +188 -0
- package/dist/storage/fs.js +307 -0
- package/dist/storage/index-projection.d.ts +236 -0
- package/dist/storage/index-projection.js +402 -0
- package/dist/storage/index.d.ts +17 -0
- package/dist/storage/index.js +17 -0
- package/dist/storage/keyval.d.ts +94 -0
- package/dist/storage/keyval.js +199 -0
- package/dist/storage/memory-vault-adapter.d.ts +44 -0
- package/dist/storage/memory-vault-adapter.js +351 -0
- package/dist/storage/native-vault-bootstrap-kv.d.ts +22 -0
- package/dist/storage/native-vault-bootstrap-kv.js +96 -0
- package/dist/storage/path.d.ts +22 -0
- package/dist/storage/path.js +110 -0
- package/dist/storage/search-embedding-provider.d.ts +75 -0
- package/dist/storage/search-embedding-provider.js +446 -0
- package/dist/storage/search-embedding-worker.d.ts +1 -0
- package/dist/storage/search-embedding-worker.js +63 -0
- package/dist/storage/search-query-evaluator.d.ts +14 -0
- package/dist/storage/search-query-evaluator.js +678 -0
- package/dist/storage/task-projection.d.ts +152 -0
- package/dist/storage/task-projection.js +154 -0
- package/dist/storage/turso-app-database.d.ts +150 -0
- package/dist/storage/turso-app-database.js +2671 -0
- package/dist/storage/vault-session.d.ts +37 -0
- package/dist/storage/vault-session.js +196 -0
- package/dist/storage/vault-state.d.ts +74 -0
- package/dist/storage/vault-state.js +181 -0
- package/dist/storage/vault.svelte.d.ts +257 -0
- package/dist/storage/vault.svelte.js +661 -0
- package/dist/suggest.d.ts +193 -0
- package/dist/suggest.js +391 -0
- package/dist/tasks.d.ts +7 -0
- package/dist/tasks.js +18 -0
- package/dist/telemetry.d.ts +116 -0
- package/dist/telemetry.js +103 -0
- package/dist/utils.d.ts +55 -0
- package/dist/utils.js +314 -0
- package/dist/vault-api.d.ts +5 -0
- package/dist/vault-api.js +3 -0
- package/dist/vault-maintenance-commands.d.ts +5 -0
- package/dist/vault-maintenance-commands.js +32 -0
- package/dist/view.svelte.d.ts +215 -0
- package/dist/view.svelte.js +381 -0
- package/dist/vite-env.d.ts +2 -0
- package/dist/workspace-host-internal.d.ts +7 -0
- package/dist/workspace-host-internal.js +7 -0
- package/dist/workspace-host.d.ts +10 -0
- package/dist/workspace-host.js +14 -0
- package/dist/workspace-layout-commands.d.ts +3 -0
- package/dist/workspace-layout-commands.js +72 -0
- package/dist/workspace-layout-normalizer.d.ts +92 -0
- package/dist/workspace-layout-normalizer.js +301 -0
- package/dist/workspace-layouts.d.ts +7 -0
- package/dist/workspace-layouts.js +23 -0
- package/dist/workspace-trust.d.ts +32 -0
- package/dist/workspace-trust.js +72 -0
- package/dist/workspace.svelte.d.ts +796 -0
- package/dist/workspace.svelte.js +4380 -0
- package/package.json +240 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type AppDatabase, type AppDatabaseCapabilities, type AppDatabaseDescriptor, type AppDatabaseProvider, type RuntimeTarget } from "./app-database";
|
|
2
|
+
import type { VaultAdapter } from "./fs";
|
|
3
|
+
import { type VaultProfile } from "./vault-state";
|
|
4
|
+
export type VaultSessionAppDatabaseStatus = "ready" | "blocked";
|
|
5
|
+
/** @deprecated Read providerId, role, transport, and capabilities instead. */
|
|
6
|
+
export type VaultSessionAppDatabaseMode = "turso-owner" | "turso-native" | "turso-proxy" | "turso-blocked" | "memory-test";
|
|
7
|
+
export interface VaultSessionAppDatabaseState {
|
|
8
|
+
status: VaultSessionAppDatabaseStatus;
|
|
9
|
+
/** @deprecated Compatibility summary derived from the provider descriptor. */
|
|
10
|
+
mode: VaultSessionAppDatabaseMode;
|
|
11
|
+
providerId: string;
|
|
12
|
+
role: AppDatabaseDescriptor["role"];
|
|
13
|
+
transport: AppDatabaseDescriptor["transport"];
|
|
14
|
+
capabilities: AppDatabaseCapabilities;
|
|
15
|
+
lockSupported: boolean;
|
|
16
|
+
message?: string;
|
|
17
|
+
ownerId?: string;
|
|
18
|
+
heartbeatAt?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface VaultSession {
|
|
21
|
+
runtime: RuntimeTarget;
|
|
22
|
+
profile?: VaultProfile;
|
|
23
|
+
vaultAdapter: VaultAdapter;
|
|
24
|
+
appDatabase?: AppDatabase;
|
|
25
|
+
appDatabaseState: VaultSessionAppDatabaseState;
|
|
26
|
+
awaitAppDatabase?: (options?: {
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}) => Promise<VaultSession>;
|
|
29
|
+
close: () => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export declare function createVaultSession(vaultAdapter: VaultAdapter, options?: Partial<{
|
|
32
|
+
runtime: RuntimeTarget;
|
|
33
|
+
profile: VaultProfile;
|
|
34
|
+
appDatabase: AppDatabase;
|
|
35
|
+
appDatabaseProvider: AppDatabaseProvider;
|
|
36
|
+
}>): Promise<VaultSession>;
|
|
37
|
+
export declare function getVaultSessionId(session: VaultSession): string;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { EMPTY_APP_DATABASE_CAPABILITIES, MemoryAppDatabase, } from "./app-database";
|
|
2
|
+
import { BrowserCoordinatedAppDatabase } from "./browser-coordinated-app-database";
|
|
3
|
+
import { BrowserAppDatabaseCoordinator } from "./browser-app-database-coordination";
|
|
4
|
+
import { TursoWasmAppDatabaseProvider, canUseTursoWasmDatabase, } from "./turso-app-database";
|
|
5
|
+
import { getAdapterVaultId } from "./vault-state";
|
|
6
|
+
function compatibilityMode(descriptor) {
|
|
7
|
+
if (descriptor.engine === "memory")
|
|
8
|
+
return "memory-test";
|
|
9
|
+
if (descriptor.role === "owner")
|
|
10
|
+
return "turso-owner";
|
|
11
|
+
if (descriptor.role === "proxy")
|
|
12
|
+
return "turso-proxy";
|
|
13
|
+
if (descriptor.transport === "native")
|
|
14
|
+
return "turso-native";
|
|
15
|
+
return "turso-owner";
|
|
16
|
+
}
|
|
17
|
+
function readyState(database, lockSupported, details = {}) {
|
|
18
|
+
const descriptor = database.descriptor;
|
|
19
|
+
return {
|
|
20
|
+
status: "ready",
|
|
21
|
+
mode: compatibilityMode(descriptor),
|
|
22
|
+
providerId: descriptor.providerId,
|
|
23
|
+
role: descriptor.role,
|
|
24
|
+
transport: descriptor.transport,
|
|
25
|
+
capabilities: descriptor.capabilities,
|
|
26
|
+
lockSupported,
|
|
27
|
+
...details,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function blockedState(message, lockSupported, details = {}) {
|
|
31
|
+
return {
|
|
32
|
+
status: "blocked",
|
|
33
|
+
mode: "turso-blocked",
|
|
34
|
+
providerId: "turso-wasm-local",
|
|
35
|
+
role: "blocked",
|
|
36
|
+
transport: "wasm-worker",
|
|
37
|
+
capabilities: {
|
|
38
|
+
...EMPTY_APP_DATABASE_CAPABILITIES,
|
|
39
|
+
localEmbeddings: true,
|
|
40
|
+
crossTabCoordination: lockSupported,
|
|
41
|
+
},
|
|
42
|
+
lockSupported,
|
|
43
|
+
message,
|
|
44
|
+
...details,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function holdBrowserAppDatabaseOwnership(database, coordinator) {
|
|
48
|
+
const close = database.close.bind(database);
|
|
49
|
+
let released = false;
|
|
50
|
+
database.close = async () => {
|
|
51
|
+
try {
|
|
52
|
+
await close();
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
if (released)
|
|
56
|
+
return;
|
|
57
|
+
released = true;
|
|
58
|
+
coordinator.close();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
return database;
|
|
62
|
+
}
|
|
63
|
+
async function openOwnedBrowserAppDatabase(vaultId, coordinator, provider) {
|
|
64
|
+
const database = new BrowserCoordinatedAppDatabase(vaultId, coordinator, true, provider);
|
|
65
|
+
await database.open();
|
|
66
|
+
return {
|
|
67
|
+
appDatabase: holdBrowserAppDatabaseOwnership(database, coordinator),
|
|
68
|
+
state: readyState(database, true, {
|
|
69
|
+
mode: "turso-owner",
|
|
70
|
+
role: "owner",
|
|
71
|
+
ownerId: coordinator.ownerId,
|
|
72
|
+
heartbeatAt: Date.now(),
|
|
73
|
+
}),
|
|
74
|
+
coordinator,
|
|
75
|
+
provider,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async function createBrowserAppDatabase(vaultId, provider) {
|
|
79
|
+
const lockSupported = BrowserAppDatabaseCoordinator.hasLockApi();
|
|
80
|
+
if (!canUseTursoWasmDatabase()) {
|
|
81
|
+
return {
|
|
82
|
+
state: blockedState("Turso requires OPFS and cross-origin isolation in this browser.", lockSupported),
|
|
83
|
+
provider,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (!lockSupported) {
|
|
87
|
+
return {
|
|
88
|
+
state: blockedState("Turso requires the Web Locks API to protect this vault database.", false),
|
|
89
|
+
provider,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const coordinator = new BrowserAppDatabaseCoordinator(vaultId);
|
|
93
|
+
const acquired = await coordinator.tryAcquireOwnership();
|
|
94
|
+
if (acquired) {
|
|
95
|
+
return openOwnedBrowserAppDatabase(vaultId, coordinator, provider);
|
|
96
|
+
}
|
|
97
|
+
if (typeof BroadcastChannel === "undefined") {
|
|
98
|
+
return {
|
|
99
|
+
state: blockedState("App database already open in another tab.", true, {
|
|
100
|
+
ownerId: coordinator.observedOwnerId ?? undefined,
|
|
101
|
+
heartbeatAt: coordinator.observedHeartbeatAt ?? undefined,
|
|
102
|
+
}),
|
|
103
|
+
coordinator,
|
|
104
|
+
provider,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const database = new BrowserCoordinatedAppDatabase(vaultId, coordinator, false, provider);
|
|
108
|
+
await database.open();
|
|
109
|
+
return {
|
|
110
|
+
appDatabase: database,
|
|
111
|
+
state: readyState(database, true, {
|
|
112
|
+
mode: "turso-proxy",
|
|
113
|
+
role: "proxy",
|
|
114
|
+
message: "App database requests are being delegated to another tab.",
|
|
115
|
+
ownerId: coordinator.observedOwnerId ?? undefined,
|
|
116
|
+
heartbeatAt: coordinator.observedHeartbeatAt ?? undefined,
|
|
117
|
+
}),
|
|
118
|
+
coordinator,
|
|
119
|
+
provider,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async function createPreferredAppDatabase(vaultId, runtime, provider) {
|
|
123
|
+
if (runtime === "test") {
|
|
124
|
+
const database = provider
|
|
125
|
+
? await provider.open({ vaultId, runtime, role: "test" })
|
|
126
|
+
: new MemoryAppDatabase(vaultId);
|
|
127
|
+
if (!provider)
|
|
128
|
+
await database.open();
|
|
129
|
+
return { appDatabase: database, state: readyState(database, false) };
|
|
130
|
+
}
|
|
131
|
+
if (runtime === "deno-desktop") {
|
|
132
|
+
const database = provider
|
|
133
|
+
? await provider.open({ vaultId, runtime, role: "direct" })
|
|
134
|
+
: await new TursoWasmAppDatabaseProvider().open({
|
|
135
|
+
vaultId,
|
|
136
|
+
runtime,
|
|
137
|
+
role: "direct",
|
|
138
|
+
});
|
|
139
|
+
return { appDatabase: database, state: readyState(database, false) };
|
|
140
|
+
}
|
|
141
|
+
if (runtime === "web-pwa") {
|
|
142
|
+
return createBrowserAppDatabase(vaultId, provider ?? new TursoWasmAppDatabaseProvider());
|
|
143
|
+
}
|
|
144
|
+
throw new Error(`Unsupported application database runtime: ${runtime}`);
|
|
145
|
+
}
|
|
146
|
+
function createVaultSessionFactory(vaultAdapter, runtime, profile, vaultId) {
|
|
147
|
+
const createFromResolution = (resolution) => ({
|
|
148
|
+
runtime,
|
|
149
|
+
profile,
|
|
150
|
+
vaultAdapter,
|
|
151
|
+
appDatabase: resolution.appDatabase,
|
|
152
|
+
appDatabaseState: resolution.state,
|
|
153
|
+
awaitAppDatabase: resolution.state.status === "blocked" &&
|
|
154
|
+
resolution.coordinator &&
|
|
155
|
+
resolution.provider
|
|
156
|
+
? async (awaitOptions = {}) => {
|
|
157
|
+
const acquired = await resolution.coordinator.waitForOwnership(awaitOptions);
|
|
158
|
+
if (!acquired) {
|
|
159
|
+
return createFromResolution({
|
|
160
|
+
...resolution,
|
|
161
|
+
state: {
|
|
162
|
+
...resolution.state,
|
|
163
|
+
ownerId: resolution.coordinator?.observedOwnerId ?? undefined,
|
|
164
|
+
heartbeatAt: resolution.coordinator?.observedHeartbeatAt ?? undefined,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return createFromResolution(await openOwnedBrowserAppDatabase(vaultId, resolution.coordinator, resolution.provider));
|
|
169
|
+
}
|
|
170
|
+
: undefined,
|
|
171
|
+
close: async () => {
|
|
172
|
+
await resolution.appDatabase?.close();
|
|
173
|
+
resolution.coordinator?.close();
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
return createFromResolution;
|
|
177
|
+
}
|
|
178
|
+
export async function createVaultSession(vaultAdapter, options = {}) {
|
|
179
|
+
const vaultId = getAdapterVaultId(vaultAdapter);
|
|
180
|
+
const runtime = options.runtime ?? "web-pwa";
|
|
181
|
+
const createFromResolution = createVaultSessionFactory(vaultAdapter, runtime, options.profile, vaultId);
|
|
182
|
+
if (options.appDatabase) {
|
|
183
|
+
await options.appDatabase.open();
|
|
184
|
+
return createFromResolution({
|
|
185
|
+
appDatabase: options.appDatabase,
|
|
186
|
+
state: readyState(options.appDatabase, false),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return createFromResolution(await createPreferredAppDatabase(vaultId, runtime, options.appDatabaseProvider));
|
|
190
|
+
}
|
|
191
|
+
export function getVaultSessionId(session) {
|
|
192
|
+
const adapter = session.vaultAdapter;
|
|
193
|
+
return (adapter.getVaultId?.() ??
|
|
194
|
+
session.appDatabase?.vaultId ??
|
|
195
|
+
session.vaultAdapter.getName());
|
|
196
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { DataAdapter } from "./fs";
|
|
2
|
+
import { type UseStore } from "./keyval";
|
|
3
|
+
export type VaultStorageKind = "opfs" | "file-system-access" | "desktop-folder";
|
|
4
|
+
export type BootstrapAppearanceMode = "dark" | "light" | "system";
|
|
5
|
+
export interface VaultProfileDemoMetadata {
|
|
6
|
+
source: "e2e-vault";
|
|
7
|
+
fixtureVersion: string;
|
|
8
|
+
}
|
|
9
|
+
export interface VaultProfile {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
kind: VaultStorageKind;
|
|
13
|
+
createdAt: number;
|
|
14
|
+
updatedAt: number;
|
|
15
|
+
handle?: unknown;
|
|
16
|
+
demo?: VaultProfileDemoMetadata;
|
|
17
|
+
}
|
|
18
|
+
export interface KeyValueStore {
|
|
19
|
+
get<T = unknown>(key: IDBValidKey): Promise<T | undefined>;
|
|
20
|
+
set(key: IDBValidKey, value: unknown): Promise<void>;
|
|
21
|
+
setMany(entries: [IDBValidKey, unknown][]): Promise<void>;
|
|
22
|
+
getMany<T = unknown>(keys: IDBValidKey[]): Promise<T[]>;
|
|
23
|
+
del(key: IDBValidKey): Promise<void>;
|
|
24
|
+
keys(): Promise<IDBValidKey[]>;
|
|
25
|
+
}
|
|
26
|
+
export declare class IndexedDbKeyValueStore implements KeyValueStore {
|
|
27
|
+
readonly dbName: string;
|
|
28
|
+
readonly storeName: string;
|
|
29
|
+
readonly store: UseStore;
|
|
30
|
+
constructor(dbName?: string, storeName?: string, store?: UseStore);
|
|
31
|
+
get<T = unknown>(key: IDBValidKey): Promise<T | undefined>;
|
|
32
|
+
set(key: IDBValidKey, value: unknown): Promise<void>;
|
|
33
|
+
setMany(entries: [IDBValidKey, unknown][]): Promise<void>;
|
|
34
|
+
getMany<T = unknown>(items: IDBValidKey[]): Promise<T[]>;
|
|
35
|
+
del(key: IDBValidKey): Promise<void>;
|
|
36
|
+
keys(): Promise<IDBValidKey[]>;
|
|
37
|
+
}
|
|
38
|
+
export declare class MemoryKeyValueStore implements KeyValueStore {
|
|
39
|
+
private values;
|
|
40
|
+
get<T = unknown>(key: IDBValidKey): Promise<T | undefined>;
|
|
41
|
+
set(key: IDBValidKey, value: unknown): Promise<void>;
|
|
42
|
+
setMany(entries: [IDBValidKey, unknown][]): Promise<void>;
|
|
43
|
+
getMany<T = unknown>(keys: IDBValidKey[]): Promise<T[]>;
|
|
44
|
+
del(key: IDBValidKey): Promise<void>;
|
|
45
|
+
keys(): Promise<IDBValidKey[]>;
|
|
46
|
+
}
|
|
47
|
+
export declare function getDefaultVaultStateStore(): KeyValueStore;
|
|
48
|
+
export declare function setDefaultVaultStateStore(store: KeyValueStore | null): void;
|
|
49
|
+
export declare class ScopedVaultStore {
|
|
50
|
+
readonly vaultId: string;
|
|
51
|
+
readonly namespace: string;
|
|
52
|
+
readonly store: KeyValueStore;
|
|
53
|
+
constructor(vaultId: string, namespace: string, store?: KeyValueStore);
|
|
54
|
+
private key;
|
|
55
|
+
get<T = unknown>(key: IDBValidKey): Promise<T | undefined>;
|
|
56
|
+
set(key: IDBValidKey, value: unknown): Promise<void>;
|
|
57
|
+
setMany(entries: [IDBValidKey, unknown][]): Promise<void>;
|
|
58
|
+
getMany<T = unknown>(items: IDBValidKey[]): Promise<T[]>;
|
|
59
|
+
del(key: IDBValidKey): Promise<void>;
|
|
60
|
+
keys(): Promise<string[]>;
|
|
61
|
+
}
|
|
62
|
+
export declare function getAdapterVaultId(adapter: DataAdapter): string;
|
|
63
|
+
export declare function saveVaultProfile(profile: VaultProfile, store?: KeyValueStore): Promise<void>;
|
|
64
|
+
export declare function replaceVaultProfile(previousId: string, profile: VaultProfile, store?: KeyValueStore): Promise<void>;
|
|
65
|
+
export declare function deleteVaultProfile(id: string, store?: KeyValueStore): Promise<void>;
|
|
66
|
+
export declare function clearVaultScopedState(vaultId: string, store?: KeyValueStore): Promise<void>;
|
|
67
|
+
export declare function getVaultProfile(id: string, store?: KeyValueStore): Promise<VaultProfile | undefined>;
|
|
68
|
+
export declare function getCurrentVaultProfile(store?: KeyValueStore): Promise<VaultProfile | undefined>;
|
|
69
|
+
export declare function clearCurrentVaultProfile(store?: KeyValueStore): Promise<void>;
|
|
70
|
+
export declare function listVaultProfiles(store?: KeyValueStore): Promise<VaultProfile[]>;
|
|
71
|
+
export declare function getBootstrapAppearanceMode(store?: KeyValueStore): Promise<BootstrapAppearanceMode>;
|
|
72
|
+
export declare function saveBootstrapAppearanceMode(mode: BootstrapAppearanceMode, store?: KeyValueStore): Promise<void>;
|
|
73
|
+
export type BrowserVaultIdPrefix = "opfs";
|
|
74
|
+
export declare function generateBrowserVaultId(prefix: BrowserVaultIdPrefix, name: string): string;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { createStore, del, get, getMany, keys, set, setMany, } from "./keyval";
|
|
2
|
+
export class IndexedDbKeyValueStore {
|
|
3
|
+
dbName;
|
|
4
|
+
storeName;
|
|
5
|
+
store;
|
|
6
|
+
constructor(dbName = "lapis-notes-vault-state", storeName = "state", store = createStore(dbName, storeName)) {
|
|
7
|
+
this.dbName = dbName;
|
|
8
|
+
this.storeName = storeName;
|
|
9
|
+
this.store = store;
|
|
10
|
+
}
|
|
11
|
+
get(key) {
|
|
12
|
+
return get(key, this.store);
|
|
13
|
+
}
|
|
14
|
+
set(key, value) {
|
|
15
|
+
return set(key, value, this.store);
|
|
16
|
+
}
|
|
17
|
+
setMany(entries) {
|
|
18
|
+
return setMany(entries, this.store);
|
|
19
|
+
}
|
|
20
|
+
getMany(items) {
|
|
21
|
+
return getMany(items, this.store);
|
|
22
|
+
}
|
|
23
|
+
del(key) {
|
|
24
|
+
return del(key, this.store);
|
|
25
|
+
}
|
|
26
|
+
keys() {
|
|
27
|
+
return keys(this.store);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export class MemoryKeyValueStore {
|
|
31
|
+
values = new Map();
|
|
32
|
+
async get(key) {
|
|
33
|
+
return this.values.get(key);
|
|
34
|
+
}
|
|
35
|
+
async set(key, value) {
|
|
36
|
+
this.values.set(key, value);
|
|
37
|
+
}
|
|
38
|
+
async setMany(entries) {
|
|
39
|
+
entries.forEach(([key, value]) => this.values.set(key, value));
|
|
40
|
+
}
|
|
41
|
+
async getMany(keys) {
|
|
42
|
+
return keys.map((key) => this.values.get(key));
|
|
43
|
+
}
|
|
44
|
+
async del(key) {
|
|
45
|
+
this.values.delete(key);
|
|
46
|
+
}
|
|
47
|
+
async keys() {
|
|
48
|
+
return [...this.values.keys()];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let defaultStore = null;
|
|
52
|
+
export function getDefaultVaultStateStore() {
|
|
53
|
+
defaultStore ||= new IndexedDbKeyValueStore();
|
|
54
|
+
return defaultStore;
|
|
55
|
+
}
|
|
56
|
+
export function setDefaultVaultStateStore(store) {
|
|
57
|
+
defaultStore = store;
|
|
58
|
+
}
|
|
59
|
+
export class ScopedVaultStore {
|
|
60
|
+
vaultId;
|
|
61
|
+
namespace;
|
|
62
|
+
store;
|
|
63
|
+
constructor(vaultId, namespace, store = getDefaultVaultStateStore()) {
|
|
64
|
+
this.vaultId = vaultId;
|
|
65
|
+
this.namespace = namespace;
|
|
66
|
+
this.store = store;
|
|
67
|
+
}
|
|
68
|
+
key(key) {
|
|
69
|
+
return `vault:${this.vaultId}:${this.namespace}:${String(key)}`;
|
|
70
|
+
}
|
|
71
|
+
get(key) {
|
|
72
|
+
return this.store.get(this.key(key));
|
|
73
|
+
}
|
|
74
|
+
set(key, value) {
|
|
75
|
+
return this.store.set(this.key(key), value);
|
|
76
|
+
}
|
|
77
|
+
setMany(entries) {
|
|
78
|
+
return this.store.setMany(entries.map(([key, value]) => [this.key(key), value]));
|
|
79
|
+
}
|
|
80
|
+
getMany(items) {
|
|
81
|
+
return this.store.getMany(items.map((key) => this.key(key)));
|
|
82
|
+
}
|
|
83
|
+
del(key) {
|
|
84
|
+
return this.store.del(this.key(key));
|
|
85
|
+
}
|
|
86
|
+
async keys() {
|
|
87
|
+
const prefix = this.key("");
|
|
88
|
+
return (await this.store.keys())
|
|
89
|
+
.map(String)
|
|
90
|
+
.filter((key) => key.startsWith(prefix))
|
|
91
|
+
.map((key) => key.slice(prefix.length));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function getAdapterVaultId(adapter) {
|
|
95
|
+
const candidate = adapter;
|
|
96
|
+
return candidate.getVaultId?.() ?? `adapter:${adapter.getName()}`;
|
|
97
|
+
}
|
|
98
|
+
const CURRENT_PROFILE_KEY = "profile:current";
|
|
99
|
+
const PROFILE_PREFIX = "profile:";
|
|
100
|
+
const BOOTSTRAP_APPEARANCE_MODE_KEY = "bootstrap:appearance:baseColorSchema";
|
|
101
|
+
function profileKey(id) {
|
|
102
|
+
return `${PROFILE_PREFIX}${id}`;
|
|
103
|
+
}
|
|
104
|
+
function isBootstrapAppearanceMode(value) {
|
|
105
|
+
return value === "dark" || value === "light" || value === "system";
|
|
106
|
+
}
|
|
107
|
+
export async function saveVaultProfile(profile, store = getDefaultVaultStateStore()) {
|
|
108
|
+
await store.setMany([
|
|
109
|
+
[profileKey(profile.id), profile],
|
|
110
|
+
[CURRENT_PROFILE_KEY, profile.id],
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
export async function replaceVaultProfile(previousId, profile, store = getDefaultVaultStateStore()) {
|
|
114
|
+
const currentId = await store.get(CURRENT_PROFILE_KEY);
|
|
115
|
+
if (previousId !== profile.id) {
|
|
116
|
+
await store.del(profileKey(previousId));
|
|
117
|
+
}
|
|
118
|
+
await store.set(profileKey(profile.id), profile);
|
|
119
|
+
if (currentId === previousId || currentId === profile.id) {
|
|
120
|
+
await store.set(CURRENT_PROFILE_KEY, profile.id);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export async function deleteVaultProfile(id, store = getDefaultVaultStateStore()) {
|
|
124
|
+
const currentId = await store.get(CURRENT_PROFILE_KEY);
|
|
125
|
+
await store.del(profileKey(id));
|
|
126
|
+
if (currentId === id) {
|
|
127
|
+
await store.del(CURRENT_PROFILE_KEY);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export async function clearVaultScopedState(vaultId, store = getDefaultVaultStateStore()) {
|
|
131
|
+
const prefix = `vault:${vaultId}:`;
|
|
132
|
+
const keysToDelete = (await store.keys())
|
|
133
|
+
.map(String)
|
|
134
|
+
.filter((key) => key.startsWith(prefix));
|
|
135
|
+
await Promise.all(keysToDelete.map((key) => store.del(key)));
|
|
136
|
+
}
|
|
137
|
+
export async function getVaultProfile(id, store = getDefaultVaultStateStore()) {
|
|
138
|
+
return store.get(profileKey(id));
|
|
139
|
+
}
|
|
140
|
+
export async function getCurrentVaultProfile(store = getDefaultVaultStateStore()) {
|
|
141
|
+
const id = await store.get(CURRENT_PROFILE_KEY);
|
|
142
|
+
return id ? getVaultProfile(id, store) : undefined;
|
|
143
|
+
}
|
|
144
|
+
export async function clearCurrentVaultProfile(store = getDefaultVaultStateStore()) {
|
|
145
|
+
await store.del(CURRENT_PROFILE_KEY);
|
|
146
|
+
}
|
|
147
|
+
export async function listVaultProfiles(store = getDefaultVaultStateStore()) {
|
|
148
|
+
const profileKeys = (await store.keys())
|
|
149
|
+
.map(String)
|
|
150
|
+
.filter((key) => key.startsWith(PROFILE_PREFIX) && key !== CURRENT_PROFILE_KEY);
|
|
151
|
+
return (await store.getMany(profileKeys))
|
|
152
|
+
.filter(Boolean)
|
|
153
|
+
.sort((left, right) => {
|
|
154
|
+
const updatedDelta = (right.updatedAt ?? 0) - (left.updatedAt ?? 0);
|
|
155
|
+
if (updatedDelta !== 0) {
|
|
156
|
+
return updatedDelta;
|
|
157
|
+
}
|
|
158
|
+
const createdDelta = (right.createdAt ?? 0) - (left.createdAt ?? 0);
|
|
159
|
+
if (createdDelta !== 0) {
|
|
160
|
+
return createdDelta;
|
|
161
|
+
}
|
|
162
|
+
return left.name.localeCompare(right.name);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
export async function getBootstrapAppearanceMode(store = getDefaultVaultStateStore()) {
|
|
166
|
+
const stored = await store.get(BOOTSTRAP_APPEARANCE_MODE_KEY);
|
|
167
|
+
return isBootstrapAppearanceMode(stored) ? stored : "system";
|
|
168
|
+
}
|
|
169
|
+
export async function saveBootstrapAppearanceMode(mode, store = getDefaultVaultStateStore()) {
|
|
170
|
+
await store.set(BOOTSTRAP_APPEARANCE_MODE_KEY, mode);
|
|
171
|
+
}
|
|
172
|
+
export function generateBrowserVaultId(prefix, name) {
|
|
173
|
+
const slug = name
|
|
174
|
+
.trim()
|
|
175
|
+
.toLowerCase()
|
|
176
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
177
|
+
.replace(/^-+|-+$/g, "")
|
|
178
|
+
.slice(0, 32) || "vault";
|
|
179
|
+
const suffix = Math.random().toString(36).slice(2, 6);
|
|
180
|
+
return `${prefix}-${slug}-${suffix}`;
|
|
181
|
+
}
|