@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,608 @@
|
|
|
1
|
+
import { inferMetadataPropertyType, inferMetadataType, normalizeMetadataValue, } from "./metadata-value";
|
|
2
|
+
import { joinPath, } from "./storage";
|
|
3
|
+
import { debounce, get, has, set, unset } from "lodash-es";
|
|
4
|
+
import { onMount } from "svelte";
|
|
5
|
+
function notifyMetadataTypeError(message) {
|
|
6
|
+
const Notice = globalThis.Notice;
|
|
7
|
+
if (typeof Notice === "function") {
|
|
8
|
+
new Notice(message);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
console.warn(message);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class MetadataTypeManager {
|
|
15
|
+
app;
|
|
16
|
+
types = $state({});
|
|
17
|
+
registeredTypeWidgets = $state({});
|
|
18
|
+
properties = $state({});
|
|
19
|
+
topLevelPropertyNames = $state(new Set());
|
|
20
|
+
propertyValues = $state({});
|
|
21
|
+
propertiesLoading = $state(false);
|
|
22
|
+
queryError = $state(null);
|
|
23
|
+
propertiesGeneration = 0;
|
|
24
|
+
valueGenerations = new Map();
|
|
25
|
+
schedulePropertiesRefresh = debounce(() => void this.updateProperties(), 50);
|
|
26
|
+
constructor(app) {
|
|
27
|
+
this.app = app;
|
|
28
|
+
onMount(() => {
|
|
29
|
+
const handler = this.app.vault.on("load", () => this.load());
|
|
30
|
+
const metadataHandler = this.app.metadataCache.on("loaded", () => void this.updateProperties());
|
|
31
|
+
const indexHandler = this.app.metadataCache.on("index-changed", (change) => {
|
|
32
|
+
if (!change.reset && !change.domains.includes("metadata"))
|
|
33
|
+
return;
|
|
34
|
+
for (const key of Object.keys(this.propertyValues))
|
|
35
|
+
delete this.propertyValues[key];
|
|
36
|
+
this.schedulePropertiesRefresh();
|
|
37
|
+
});
|
|
38
|
+
return () => {
|
|
39
|
+
this.app.vault.offref(handler);
|
|
40
|
+
this.app.metadataCache.offref(metadataHandler);
|
|
41
|
+
this.app.metadataCache.offref(indexHandler);
|
|
42
|
+
this.schedulePropertiesRefresh.cancel();
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
this.load();
|
|
46
|
+
}
|
|
47
|
+
getAllProperties() {
|
|
48
|
+
return { ...this.properties };
|
|
49
|
+
}
|
|
50
|
+
async updateProperties() {
|
|
51
|
+
const generation = ++this.propertiesGeneration;
|
|
52
|
+
this.propertiesLoading = true;
|
|
53
|
+
this.queryError = null;
|
|
54
|
+
let topLevel;
|
|
55
|
+
let paths;
|
|
56
|
+
try {
|
|
57
|
+
[topLevel, paths] = await Promise.all([
|
|
58
|
+
this.app.metadataCache.queryFacets({
|
|
59
|
+
kind: "property-name",
|
|
60
|
+
limit: 10_000,
|
|
61
|
+
}),
|
|
62
|
+
this.app.metadataCache.queryFacets({
|
|
63
|
+
kind: "property-path",
|
|
64
|
+
limit: 20_000,
|
|
65
|
+
}),
|
|
66
|
+
]);
|
|
67
|
+
if (generation !== this.propertiesGeneration)
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (generation === this.propertiesGeneration) {
|
|
72
|
+
this.queryError = error instanceof Error ? error.message : String(error);
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
if (generation === this.propertiesGeneration) {
|
|
78
|
+
this.propertiesLoading = false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const next = new Map();
|
|
82
|
+
for (const row of paths) {
|
|
83
|
+
if (typeof row.value !== "string")
|
|
84
|
+
continue;
|
|
85
|
+
next.set(row.value, this.propertyFromFacet(row));
|
|
86
|
+
}
|
|
87
|
+
for (const row of topLevel) {
|
|
88
|
+
if (typeof row.value !== "string")
|
|
89
|
+
continue;
|
|
90
|
+
next.set(row.value, this.propertyFromFacet(row));
|
|
91
|
+
}
|
|
92
|
+
for (const [name, definition] of Object.entries(this.types)) {
|
|
93
|
+
next.set(name, next.get(name) ?? {
|
|
94
|
+
name,
|
|
95
|
+
type: definition.type,
|
|
96
|
+
count: 0,
|
|
97
|
+
files: new Set(),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
for (const name of Object.keys(this.properties)) {
|
|
101
|
+
if (!next.has(name))
|
|
102
|
+
delete this.properties[name];
|
|
103
|
+
}
|
|
104
|
+
for (const [name, property] of next)
|
|
105
|
+
this.properties[name] = property;
|
|
106
|
+
this.topLevelPropertyNames.clear();
|
|
107
|
+
for (const row of topLevel) {
|
|
108
|
+
if (typeof row.value === "string")
|
|
109
|
+
this.topLevelPropertyNames.add(row.value);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
load() {
|
|
113
|
+
const promises = [];
|
|
114
|
+
const file = this.app.vault.getFileByPath(joinPath(this.app.props.configPath, "../", "types.json"));
|
|
115
|
+
if (file) {
|
|
116
|
+
promises.push(this.app.vault.read(file).then((data) => {
|
|
117
|
+
try {
|
|
118
|
+
const typeData = JSON.parse(data);
|
|
119
|
+
if ("types" in typeData) {
|
|
120
|
+
for (const [key, value] of Object.entries(typeData.types)) {
|
|
121
|
+
this.types[key] = { name: key, type: value };
|
|
122
|
+
this.properties[key] = {
|
|
123
|
+
name: key,
|
|
124
|
+
type: value,
|
|
125
|
+
count: 0,
|
|
126
|
+
files: new Set(),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
notifyMetadataTypeError(`Failed to load types.json: ${e}`);
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
return Promise.all(promises).then(async () => {
|
|
137
|
+
await this.updateProperties();
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
propertyFromFacet(row) {
|
|
141
|
+
const name = String(row.value);
|
|
142
|
+
const observed = new Set((row.metadataTypes ?? []).map((type) => this.normalizeIndexedType(name, type)));
|
|
143
|
+
observed.delete("unknown");
|
|
144
|
+
return {
|
|
145
|
+
name,
|
|
146
|
+
type: this.types[name]?.type ??
|
|
147
|
+
(observed.size === 1 ? [...observed][0] : observed.size > 1 ? "unknown" : "unknown"),
|
|
148
|
+
count: row.count,
|
|
149
|
+
files: new Set(),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
normalizeIndexedType(name, type) {
|
|
153
|
+
const normalizedName = name.toLowerCase();
|
|
154
|
+
if (normalizedName === "tags" || normalizedName === "tag")
|
|
155
|
+
return "tags";
|
|
156
|
+
if (normalizedName === "aliases" || normalizedName === "alias")
|
|
157
|
+
return "aliases";
|
|
158
|
+
if (["text", "number", "array", "object", "date", "datetime", "multitext", "unknown"].includes(type)) {
|
|
159
|
+
return type;
|
|
160
|
+
}
|
|
161
|
+
if (type === "string")
|
|
162
|
+
return "text";
|
|
163
|
+
if (type === "boolean")
|
|
164
|
+
return "checkbox";
|
|
165
|
+
if (type === "null")
|
|
166
|
+
return "unknown";
|
|
167
|
+
return type === "checkbox" ? "checkbox" : "unknown";
|
|
168
|
+
}
|
|
169
|
+
save = debounce(() => {
|
|
170
|
+
const file = this.app.vault.getFileByPath(joinPath(this.app.props.configPath, "../", "types.json"));
|
|
171
|
+
if (file) {
|
|
172
|
+
return this.app.vault.modify(file, JSON.stringify(this.toJSON(), null, 2));
|
|
173
|
+
}
|
|
174
|
+
}, 500);
|
|
175
|
+
toJSON() {
|
|
176
|
+
const types = {};
|
|
177
|
+
Object.values(this.types).forEach((t) => {
|
|
178
|
+
types[t.name] = t.type;
|
|
179
|
+
});
|
|
180
|
+
return {
|
|
181
|
+
types,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
setType(field, type) {
|
|
185
|
+
this.types[field] = { name: field, type };
|
|
186
|
+
this.properties[field] ||= {
|
|
187
|
+
name: field,
|
|
188
|
+
type,
|
|
189
|
+
count: 0,
|
|
190
|
+
files: new Set(),
|
|
191
|
+
};
|
|
192
|
+
if (this.properties[field]) {
|
|
193
|
+
this.properties[field].type = type;
|
|
194
|
+
}
|
|
195
|
+
this.save();
|
|
196
|
+
}
|
|
197
|
+
registerTypeWidget(widget) {
|
|
198
|
+
this.registeredTypeWidgets[widget.type] = widget;
|
|
199
|
+
}
|
|
200
|
+
unregisterTypeWidget(widget) {
|
|
201
|
+
delete this.registeredTypeWidgets[widget.type];
|
|
202
|
+
}
|
|
203
|
+
collectPropertyEntries(value, path, entries, topLevel = false) {
|
|
204
|
+
entries.push({ path, value, topLevel });
|
|
205
|
+
if (Array.isArray(value)) {
|
|
206
|
+
value.forEach((item, index) => {
|
|
207
|
+
this.collectPropertyEntries(item, `${path}[${index}]`, entries);
|
|
208
|
+
});
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!value || typeof value !== "object") {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
for (const [key, child] of Object.entries(value)) {
|
|
215
|
+
this.collectPropertyEntries(child, `${path}.${key}`, entries);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
getEntriesForFrontmatter(frontmatter) {
|
|
219
|
+
const entries = [];
|
|
220
|
+
if (!frontmatter || typeof frontmatter !== "object") {
|
|
221
|
+
return entries;
|
|
222
|
+
}
|
|
223
|
+
for (const [key, value] of Object.entries(frontmatter)) {
|
|
224
|
+
this.collectPropertyEntries(value, key, entries, true);
|
|
225
|
+
}
|
|
226
|
+
return entries;
|
|
227
|
+
}
|
|
228
|
+
getFrontmatterPropertyValue(frontmatter, path) {
|
|
229
|
+
if (!frontmatter || typeof frontmatter !== "object") {
|
|
230
|
+
return { found: false, topLevel: false, value: undefined };
|
|
231
|
+
}
|
|
232
|
+
if (Object.prototype.hasOwnProperty.call(frontmatter, path)) {
|
|
233
|
+
return {
|
|
234
|
+
found: true,
|
|
235
|
+
topLevel: true,
|
|
236
|
+
value: frontmatter[path],
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (has(frontmatter, path)) {
|
|
240
|
+
return {
|
|
241
|
+
found: true,
|
|
242
|
+
topLevel: false,
|
|
243
|
+
value: get(frontmatter, path),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return { found: false, topLevel: false, value: undefined };
|
|
247
|
+
}
|
|
248
|
+
async getFilesForProperty(path) {
|
|
249
|
+
const files = new Set();
|
|
250
|
+
let cursor;
|
|
251
|
+
do {
|
|
252
|
+
const page = await this.app.metadataCache.queryMetadataPage({
|
|
253
|
+
after: cursor,
|
|
254
|
+
limit: 500,
|
|
255
|
+
query: {
|
|
256
|
+
propertyFilters: [{ name: path, op: "exists" }],
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
for (const row of page.rows)
|
|
260
|
+
files.add(row.file.path);
|
|
261
|
+
cursor = page.nextCursor;
|
|
262
|
+
} while (cursor);
|
|
263
|
+
return files;
|
|
264
|
+
}
|
|
265
|
+
reportBulkProgress(options, current, total, path) {
|
|
266
|
+
options?.onProgress?.({ current, total, path });
|
|
267
|
+
}
|
|
268
|
+
throwIfBulkCancelled(options) {
|
|
269
|
+
if (options?.signal?.aborted) {
|
|
270
|
+
throw new Error("Operation cancelled");
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async rename(prevId, newId) {
|
|
274
|
+
if (prevId === newId) {
|
|
275
|
+
return { updatedFiles: [], failedFiles: [] };
|
|
276
|
+
}
|
|
277
|
+
const files = await this.getFilesForProperty(prevId);
|
|
278
|
+
if (!files.size && !this.types[prevId]) {
|
|
279
|
+
throw new Error(`Unable to find property: ${prevId}`);
|
|
280
|
+
}
|
|
281
|
+
return this.renameProperty(files, prevId, newId);
|
|
282
|
+
}
|
|
283
|
+
renameProperty(files, prevId, newId) {
|
|
284
|
+
const updatedFiles = [];
|
|
285
|
+
const failedFiles = [];
|
|
286
|
+
const tasks = [...files].map(async (path) => {
|
|
287
|
+
const file = this.app.vault.getFileByPath(path);
|
|
288
|
+
if (!file) {
|
|
289
|
+
failedFiles.push({ path, message: "File no longer exists" });
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
try {
|
|
293
|
+
await this.app.fileManager.processFrontMatter(file, (frontmatter) => {
|
|
294
|
+
if (!has(frontmatter, prevId)) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (prevId !== newId && has(frontmatter, newId)) {
|
|
298
|
+
throw new Error(`Property \"${newId}\" already exists`);
|
|
299
|
+
}
|
|
300
|
+
const existingValue = get(frontmatter, prevId);
|
|
301
|
+
unset(frontmatter, prevId);
|
|
302
|
+
set(frontmatter, newId, existingValue);
|
|
303
|
+
});
|
|
304
|
+
updatedFiles.push(path);
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
failedFiles.push({
|
|
308
|
+
path,
|
|
309
|
+
message: error instanceof Error ? error.message : String(error),
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
return Promise.all(tasks).then(() => {
|
|
314
|
+
if (!failedFiles.length) {
|
|
315
|
+
if (this.types[prevId]) {
|
|
316
|
+
this.types[newId] = { ...this.types[prevId], name: newId };
|
|
317
|
+
delete this.types[prevId];
|
|
318
|
+
this.save();
|
|
319
|
+
}
|
|
320
|
+
if (this.properties[prevId]) {
|
|
321
|
+
const renamed = this.properties[prevId];
|
|
322
|
+
delete this.properties[prevId];
|
|
323
|
+
this.properties[newId] = {
|
|
324
|
+
name: newId,
|
|
325
|
+
type: this.types[newId]?.type ?? renamed.type,
|
|
326
|
+
count: renamed.count,
|
|
327
|
+
files: new Set(),
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return { updatedFiles, failedFiles };
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
async renameTopLevelProperty(prevId, newId, options) {
|
|
335
|
+
if (prevId === newId) {
|
|
336
|
+
return { updatedFiles: [], failedFiles: [] };
|
|
337
|
+
}
|
|
338
|
+
const files = [...(await this.getFilesForProperty(prevId))];
|
|
339
|
+
if (!files.length && !this.types[prevId]) {
|
|
340
|
+
throw new Error(`Unable to find property: ${prevId}`);
|
|
341
|
+
}
|
|
342
|
+
const updatedFiles = [];
|
|
343
|
+
const failedFiles = [];
|
|
344
|
+
for (let index = 0; index < files.length; index += 1) {
|
|
345
|
+
const path = files[index];
|
|
346
|
+
this.throwIfBulkCancelled(options);
|
|
347
|
+
this.reportBulkProgress(options, index, files.length, path);
|
|
348
|
+
const file = this.app.vault.getFileByPath(path);
|
|
349
|
+
if (!file) {
|
|
350
|
+
failedFiles.push({ path, message: "File no longer exists" });
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
try {
|
|
354
|
+
await this.app.fileManager.processFrontMatter(file, (frontmatter) => {
|
|
355
|
+
if (!Object.prototype.hasOwnProperty.call(frontmatter, prevId)) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (prevId !== newId &&
|
|
359
|
+
Object.prototype.hasOwnProperty.call(frontmatter, newId)) {
|
|
360
|
+
throw new Error(`Property "${newId}" already exists`);
|
|
361
|
+
}
|
|
362
|
+
const existingValue = frontmatter[prevId];
|
|
363
|
+
delete frontmatter[prevId];
|
|
364
|
+
frontmatter[newId] = existingValue;
|
|
365
|
+
});
|
|
366
|
+
updatedFiles.push(path);
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
failedFiles.push({
|
|
370
|
+
path,
|
|
371
|
+
message: error instanceof Error ? error.message : String(error),
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
this.reportBulkProgress(options, files.length, files.length, files.at(-1) ?? prevId);
|
|
376
|
+
if (!failedFiles.length) {
|
|
377
|
+
if (this.types[prevId]) {
|
|
378
|
+
this.types[newId] = { ...this.types[prevId], name: newId };
|
|
379
|
+
delete this.types[prevId];
|
|
380
|
+
this.save();
|
|
381
|
+
}
|
|
382
|
+
this.reload();
|
|
383
|
+
}
|
|
384
|
+
return { updatedFiles, failedFiles };
|
|
385
|
+
}
|
|
386
|
+
async deleteTopLevelProperty(path, options) {
|
|
387
|
+
const files = [...(await this.getFilesForProperty(path))];
|
|
388
|
+
const updatedFiles = [];
|
|
389
|
+
const failedFiles = [];
|
|
390
|
+
for (let index = 0; index < files.length; index += 1) {
|
|
391
|
+
const filePath = files[index];
|
|
392
|
+
this.throwIfBulkCancelled(options);
|
|
393
|
+
this.reportBulkProgress(options, index, files.length, filePath);
|
|
394
|
+
const file = this.app.vault.getFileByPath(filePath);
|
|
395
|
+
if (!file) {
|
|
396
|
+
failedFiles.push({ path: filePath, message: "File no longer exists" });
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
try {
|
|
400
|
+
await this.app.fileManager.processFrontMatter(file, (frontmatter) => {
|
|
401
|
+
if (Object.prototype.hasOwnProperty.call(frontmatter, path)) {
|
|
402
|
+
delete frontmatter[path];
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
updatedFiles.push(filePath);
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
failedFiles.push({
|
|
409
|
+
path: filePath,
|
|
410
|
+
message: error instanceof Error ? error.message : String(error),
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
this.reportBulkProgress(options, files.length, files.length, files.at(-1) ?? path);
|
|
415
|
+
if (!failedFiles.length) {
|
|
416
|
+
delete this.types[path];
|
|
417
|
+
delete this.properties[path];
|
|
418
|
+
this.save();
|
|
419
|
+
this.reload();
|
|
420
|
+
}
|
|
421
|
+
return { updatedFiles, failedFiles };
|
|
422
|
+
}
|
|
423
|
+
async deleteProperty(path, options) {
|
|
424
|
+
const files = [...(await this.getFilesForProperty(path))];
|
|
425
|
+
const updatedFiles = [];
|
|
426
|
+
const failedFiles = [];
|
|
427
|
+
for (let index = 0; index < files.length; index += 1) {
|
|
428
|
+
const filePath = files[index];
|
|
429
|
+
this.throwIfBulkCancelled(options);
|
|
430
|
+
this.reportBulkProgress(options, index, files.length, filePath);
|
|
431
|
+
const file = this.app.vault.getFileByPath(filePath);
|
|
432
|
+
if (!file) {
|
|
433
|
+
failedFiles.push({ path: filePath, message: "File no longer exists" });
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
try {
|
|
437
|
+
await this.app.fileManager.processFrontMatter(file, (frontmatter) => {
|
|
438
|
+
if (has(frontmatter, path)) {
|
|
439
|
+
unset(frontmatter, path);
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
updatedFiles.push(filePath);
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
failedFiles.push({
|
|
446
|
+
path: filePath,
|
|
447
|
+
message: error instanceof Error ? error.message : String(error),
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
this.reportBulkProgress(options, files.length, files.length, files.at(-1) ?? path);
|
|
452
|
+
if (!failedFiles.length) {
|
|
453
|
+
delete this.types[path];
|
|
454
|
+
delete this.properties[path];
|
|
455
|
+
this.save();
|
|
456
|
+
this.reload();
|
|
457
|
+
}
|
|
458
|
+
return { updatedFiles, failedFiles };
|
|
459
|
+
}
|
|
460
|
+
async setTopLevelPropertyType(path, type, options) {
|
|
461
|
+
const files = [...(await this.getFilesForProperty(path))];
|
|
462
|
+
const updatedFiles = [];
|
|
463
|
+
const failedFiles = [];
|
|
464
|
+
this.types[path] = { name: path, type };
|
|
465
|
+
this.properties[path] ||= {
|
|
466
|
+
name: path,
|
|
467
|
+
type,
|
|
468
|
+
count: 0,
|
|
469
|
+
files: new Set(),
|
|
470
|
+
};
|
|
471
|
+
this.properties[path].type = type;
|
|
472
|
+
for (let index = 0; index < files.length; index += 1) {
|
|
473
|
+
const filePath = files[index];
|
|
474
|
+
this.throwIfBulkCancelled(options);
|
|
475
|
+
this.reportBulkProgress(options, index, files.length, filePath);
|
|
476
|
+
const file = this.app.vault.getFileByPath(filePath);
|
|
477
|
+
if (!file) {
|
|
478
|
+
failedFiles.push({ path: filePath, message: "File no longer exists" });
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
try {
|
|
482
|
+
await this.app.fileManager.processFrontMatter(file, (frontmatter) => {
|
|
483
|
+
if (!Object.prototype.hasOwnProperty.call(frontmatter, path)) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
frontmatter[path] = normalizeMetadataValue(type, frontmatter[path]);
|
|
487
|
+
});
|
|
488
|
+
updatedFiles.push(filePath);
|
|
489
|
+
}
|
|
490
|
+
catch (error) {
|
|
491
|
+
failedFiles.push({
|
|
492
|
+
path: filePath,
|
|
493
|
+
message: error instanceof Error ? error.message : String(error),
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
this.reportBulkProgress(options, files.length, files.length, files.at(-1) ?? path);
|
|
498
|
+
this.save();
|
|
499
|
+
this.reload();
|
|
500
|
+
return { updatedFiles, failedFiles };
|
|
501
|
+
}
|
|
502
|
+
async setPropertyType(path, type, options) {
|
|
503
|
+
const files = [...(await this.getFilesForProperty(path))];
|
|
504
|
+
const updatedFiles = [];
|
|
505
|
+
const failedFiles = [];
|
|
506
|
+
this.types[path] = { name: path, type };
|
|
507
|
+
this.properties[path] ||= {
|
|
508
|
+
name: path,
|
|
509
|
+
type,
|
|
510
|
+
count: 0,
|
|
511
|
+
files: new Set(),
|
|
512
|
+
};
|
|
513
|
+
this.properties[path].type = type;
|
|
514
|
+
for (let index = 0; index < files.length; index += 1) {
|
|
515
|
+
const filePath = files[index];
|
|
516
|
+
this.throwIfBulkCancelled(options);
|
|
517
|
+
this.reportBulkProgress(options, index, files.length, filePath);
|
|
518
|
+
const file = this.app.vault.getFileByPath(filePath);
|
|
519
|
+
if (!file) {
|
|
520
|
+
failedFiles.push({ path: filePath, message: "File no longer exists" });
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
try {
|
|
524
|
+
await this.app.fileManager.processFrontMatter(file, (frontmatter) => {
|
|
525
|
+
if (!has(frontmatter, path)) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
set(frontmatter, path, normalizeMetadataValue(type, get(frontmatter, path)));
|
|
529
|
+
});
|
|
530
|
+
updatedFiles.push(filePath);
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
failedFiles.push({
|
|
534
|
+
path: filePath,
|
|
535
|
+
message: error instanceof Error ? error.message : String(error),
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
this.reportBulkProgress(options, files.length, files.length, files.at(-1) ?? path);
|
|
540
|
+
this.save();
|
|
541
|
+
this.reload();
|
|
542
|
+
return { updatedFiles, failedFiles };
|
|
543
|
+
}
|
|
544
|
+
processChange(file, cache) {
|
|
545
|
+
void file;
|
|
546
|
+
void cache;
|
|
547
|
+
this.schedulePropertiesRefresh();
|
|
548
|
+
}
|
|
549
|
+
getValues(key) {
|
|
550
|
+
if (!this.propertyValues[key])
|
|
551
|
+
void this.getValuesAsync(key);
|
|
552
|
+
return [...(this.propertyValues[key] ?? [])];
|
|
553
|
+
}
|
|
554
|
+
async getValuesAsync(key, limit = 1_000) {
|
|
555
|
+
const generation = (this.valueGenerations.get(key) ?? 0) + 1;
|
|
556
|
+
this.valueGenerations.set(key, generation);
|
|
557
|
+
let rows;
|
|
558
|
+
try {
|
|
559
|
+
rows = await this.app.metadataCache.queryFacets({
|
|
560
|
+
kind: "property-value",
|
|
561
|
+
propertyName: key,
|
|
562
|
+
limit,
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
catch (error) {
|
|
566
|
+
if (this.valueGenerations.get(key) === generation) {
|
|
567
|
+
this.queryError = error instanceof Error ? error.message : String(error);
|
|
568
|
+
}
|
|
569
|
+
return [...(this.propertyValues[key] ?? [])];
|
|
570
|
+
}
|
|
571
|
+
if (this.valueGenerations.get(key) !== generation) {
|
|
572
|
+
return [...(this.propertyValues[key] ?? [])];
|
|
573
|
+
}
|
|
574
|
+
const values = rows.map((row) => row.value);
|
|
575
|
+
this.propertyValues[key] = values;
|
|
576
|
+
return [...values];
|
|
577
|
+
}
|
|
578
|
+
processDelete(file) {
|
|
579
|
+
void file;
|
|
580
|
+
this.schedulePropertiesRefresh();
|
|
581
|
+
}
|
|
582
|
+
trackChanges() {
|
|
583
|
+
const indexHandler = this.app.metadataCache.on("index-changed", (change) => {
|
|
584
|
+
if (!change.reset && !change.domains.includes("metadata"))
|
|
585
|
+
return;
|
|
586
|
+
for (const key of Object.keys(this.propertyValues))
|
|
587
|
+
delete this.propertyValues[key];
|
|
588
|
+
this.schedulePropertiesRefresh();
|
|
589
|
+
});
|
|
590
|
+
const loadHandler = this.app.metadataCache.on("loaded", () => {
|
|
591
|
+
this.reload();
|
|
592
|
+
});
|
|
593
|
+
return () => {
|
|
594
|
+
this.app.metadataCache.offref(indexHandler);
|
|
595
|
+
this.app.metadataCache.offref(loadHandler);
|
|
596
|
+
this.schedulePropertiesRefresh.cancel();
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
reload() {
|
|
600
|
+
this.schedulePropertiesRefresh();
|
|
601
|
+
}
|
|
602
|
+
determineType(value) {
|
|
603
|
+
return inferMetadataType(value);
|
|
604
|
+
}
|
|
605
|
+
determinePropertyType(name, value) {
|
|
606
|
+
return inferMetadataPropertyType(name, value);
|
|
607
|
+
}
|
|
608
|
+
}
|