@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,678 @@
|
|
|
1
|
+
import { parseSearchQueryAst, } from "../search-query";
|
|
2
|
+
const EMPTY_TEXT_EVALUATION = {
|
|
3
|
+
matched: false,
|
|
4
|
+
score: 0,
|
|
5
|
+
ranges: [],
|
|
6
|
+
};
|
|
7
|
+
const EMPTY_DOCUMENT_EVALUATION = {
|
|
8
|
+
matched: false,
|
|
9
|
+
score: 0,
|
|
10
|
+
ranges: {},
|
|
11
|
+
};
|
|
12
|
+
const FIELD_WEIGHTS = {
|
|
13
|
+
name: 35,
|
|
14
|
+
path: 30,
|
|
15
|
+
tags: 25,
|
|
16
|
+
metadata: 18,
|
|
17
|
+
content: 12,
|
|
18
|
+
};
|
|
19
|
+
export function isStructuredSearchQuery(query) {
|
|
20
|
+
const ast = parseSearchQueryAst(query);
|
|
21
|
+
if (ast.diagnostics.length > 0) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return containsStructuredExpression(ast.expression);
|
|
25
|
+
}
|
|
26
|
+
export function evaluateSearchQueryForDocument(document, query, properties = [], options = {}) {
|
|
27
|
+
const ast = parseSearchQueryAst(query);
|
|
28
|
+
if (ast.diagnostics.length > 0) {
|
|
29
|
+
return evaluateLegacyTerms(document, query, options);
|
|
30
|
+
}
|
|
31
|
+
const evaluation = evaluateDocumentExpression(ast.expression, document, properties, options);
|
|
32
|
+
return {
|
|
33
|
+
matched: evaluation.matched,
|
|
34
|
+
score: evaluation.score,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function findSearchQueryRangesInText(text, query, options = {}) {
|
|
38
|
+
const ast = parseSearchQueryAst(query);
|
|
39
|
+
if (ast.diagnostics.length > 0) {
|
|
40
|
+
return mergeRanges(legacyTerms(query).flatMap((term) => findLiteralRanges(text, term, options)));
|
|
41
|
+
}
|
|
42
|
+
return mergeRanges(evaluateTextExpression(ast.expression, text, options).ranges);
|
|
43
|
+
}
|
|
44
|
+
function containsStructuredExpression(expression) {
|
|
45
|
+
if (!expression)
|
|
46
|
+
return false;
|
|
47
|
+
switch (expression.type) {
|
|
48
|
+
case "literal":
|
|
49
|
+
return expression.kind === "regex" || expression.kind === "null";
|
|
50
|
+
case "group":
|
|
51
|
+
return containsStructuredExpression(expression.expression);
|
|
52
|
+
case "and":
|
|
53
|
+
case "or":
|
|
54
|
+
return (expression.type === "or" ||
|
|
55
|
+
expression.clauses.some(containsStructuredExpression));
|
|
56
|
+
default:
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function evaluateDocumentExpression(expression, document, properties, options) {
|
|
61
|
+
if (!expression)
|
|
62
|
+
return { matched: true, score: 0, ranges: {} };
|
|
63
|
+
switch (expression.type) {
|
|
64
|
+
case "literal":
|
|
65
|
+
return evaluateLiteralAcrossDocument(expression, document, options);
|
|
66
|
+
case "group":
|
|
67
|
+
return evaluateDocumentExpression(expression.expression, document, properties, options);
|
|
68
|
+
case "and":
|
|
69
|
+
return combineDocumentAnd(expression.clauses.map((clause) => evaluateDocumentExpression(clause, document, properties, options)));
|
|
70
|
+
case "or":
|
|
71
|
+
return combineDocumentOr(expression.clauses.map((clause) => evaluateDocumentExpression(clause, document, properties, options)));
|
|
72
|
+
case "not": {
|
|
73
|
+
const operand = evaluateDocumentExpression(expression.operand, document, properties, options);
|
|
74
|
+
return operand.matched
|
|
75
|
+
? EMPTY_DOCUMENT_EVALUATION
|
|
76
|
+
: { matched: true, score: 1, ranges: {} };
|
|
77
|
+
}
|
|
78
|
+
case "field":
|
|
79
|
+
return evaluateFieldExpression(expression, document, properties, options);
|
|
80
|
+
case "property":
|
|
81
|
+
return evaluatePropertyExpression(expression, properties, document, options);
|
|
82
|
+
case "comparison":
|
|
83
|
+
return EMPTY_DOCUMENT_EVALUATION;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function evaluateTextExpression(expression, text, options) {
|
|
87
|
+
if (!expression)
|
|
88
|
+
return { matched: true, score: 0, ranges: [] };
|
|
89
|
+
switch (expression.type) {
|
|
90
|
+
case "literal": {
|
|
91
|
+
const ranges = literalRanges(text, expression, options);
|
|
92
|
+
return {
|
|
93
|
+
matched: ranges.length > 0,
|
|
94
|
+
score: ranges.length * literalScore(expression),
|
|
95
|
+
ranges,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
case "group":
|
|
99
|
+
return evaluateTextExpression(expression.expression, text, options);
|
|
100
|
+
case "and":
|
|
101
|
+
return combineTextAnd(expression.clauses.map((clause) => evaluateTextExpression(clause, text, options)));
|
|
102
|
+
case "or":
|
|
103
|
+
return combineTextOr(expression.clauses.map((clause) => evaluateTextExpression(clause, text, options)));
|
|
104
|
+
case "not": {
|
|
105
|
+
const operand = evaluateTextExpression(expression.operand, text, options);
|
|
106
|
+
return operand.matched
|
|
107
|
+
? EMPTY_TEXT_EVALUATION
|
|
108
|
+
: { matched: true, score: 1, ranges: [] };
|
|
109
|
+
}
|
|
110
|
+
case "field":
|
|
111
|
+
return evaluateTextFieldExpression(expression, text, options);
|
|
112
|
+
case "property":
|
|
113
|
+
return evaluateTextPropertyExpression(expression, text, options);
|
|
114
|
+
case "comparison":
|
|
115
|
+
return EMPTY_TEXT_EVALUATION;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function evaluateLiteralAcrossDocument(literal, document, options) {
|
|
119
|
+
const evaluations = documentFields(document).map(([field, text]) => {
|
|
120
|
+
const ranges = literalRanges(text, literal, { ...options, field });
|
|
121
|
+
return {
|
|
122
|
+
field,
|
|
123
|
+
ranges,
|
|
124
|
+
score: ranges.length ? ranges.length * FIELD_WEIGHTS[field] : 0,
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
const matches = evaluations.filter((entry) => entry.ranges.length > 0);
|
|
128
|
+
if (!matches.length)
|
|
129
|
+
return EMPTY_DOCUMENT_EVALUATION;
|
|
130
|
+
return {
|
|
131
|
+
matched: true,
|
|
132
|
+
score: matches.reduce((total, entry) => total + entry.score, 0),
|
|
133
|
+
ranges: Object.fromEntries(matches.map((entry) => [entry.field, entry.ranges])),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function evaluateFieldExpression(field, document, properties, options) {
|
|
137
|
+
const name = field.name.toLowerCase();
|
|
138
|
+
if (name === "match-case") {
|
|
139
|
+
return evaluateDocumentExpression(field.value, document, properties, {
|
|
140
|
+
...options,
|
|
141
|
+
caseSensitive: true,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (name === "ignore-case") {
|
|
145
|
+
return evaluateDocumentExpression(field.value, document, properties, {
|
|
146
|
+
...options,
|
|
147
|
+
caseSensitive: false,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const mappedField = fieldNameToSearchField(name);
|
|
151
|
+
if (mappedField) {
|
|
152
|
+
const text = documentFieldText(document, mappedField);
|
|
153
|
+
const evaluation = evaluateTextExpression(field.value, text, {
|
|
154
|
+
...options,
|
|
155
|
+
field: mappedField,
|
|
156
|
+
});
|
|
157
|
+
if (!evaluation.matched)
|
|
158
|
+
return EMPTY_DOCUMENT_EVALUATION;
|
|
159
|
+
return {
|
|
160
|
+
matched: true,
|
|
161
|
+
score: Math.max(1, evaluation.score) + FIELD_WEIGHTS[mappedField],
|
|
162
|
+
ranges: { [mappedField]: evaluation.ranges },
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (name === "line") {
|
|
166
|
+
return evaluateContentScopes(lineScopes(document.content), field.value, options);
|
|
167
|
+
}
|
|
168
|
+
if (name === "block") {
|
|
169
|
+
return evaluateContentScopes(blockScopes(document.content), field.value, options);
|
|
170
|
+
}
|
|
171
|
+
if (name === "section") {
|
|
172
|
+
return evaluateContentScopes(sectionScopes(document.content), field.value, options);
|
|
173
|
+
}
|
|
174
|
+
if (name === "task" || name === "task-todo" || name === "task-done") {
|
|
175
|
+
const status = name === "task-todo" ? "todo" : name === "task-done" ? "done" : "any";
|
|
176
|
+
return evaluateContentScopes(taskScopes(document.content, status), field.value, options);
|
|
177
|
+
}
|
|
178
|
+
return EMPTY_DOCUMENT_EVALUATION;
|
|
179
|
+
}
|
|
180
|
+
function evaluateTextFieldExpression(field, text, options) {
|
|
181
|
+
const name = field.name.toLowerCase();
|
|
182
|
+
if (name === "match-case") {
|
|
183
|
+
return evaluateTextExpression(field.value, text, {
|
|
184
|
+
...options,
|
|
185
|
+
caseSensitive: true,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (name === "ignore-case") {
|
|
189
|
+
return evaluateTextExpression(field.value, text, {
|
|
190
|
+
...options,
|
|
191
|
+
caseSensitive: false,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const mappedField = fieldNameToSearchField(name);
|
|
195
|
+
if (mappedField) {
|
|
196
|
+
if (options.field !== mappedField)
|
|
197
|
+
return EMPTY_TEXT_EVALUATION;
|
|
198
|
+
return evaluateTextExpression(field.value, text, options);
|
|
199
|
+
}
|
|
200
|
+
if (options.field === "content" &&
|
|
201
|
+
(name === "line" ||
|
|
202
|
+
name === "block" ||
|
|
203
|
+
name === "section" ||
|
|
204
|
+
name === "task" ||
|
|
205
|
+
name === "task-todo" ||
|
|
206
|
+
name === "task-done")) {
|
|
207
|
+
const scopes = name === "line"
|
|
208
|
+
? lineScopes(text)
|
|
209
|
+
: name === "block"
|
|
210
|
+
? blockScopes(text)
|
|
211
|
+
: name === "section"
|
|
212
|
+
? sectionScopes(text)
|
|
213
|
+
: taskScopes(text, name === "task-todo"
|
|
214
|
+
? "todo"
|
|
215
|
+
: name === "task-done"
|
|
216
|
+
? "done"
|
|
217
|
+
: "any");
|
|
218
|
+
return evaluateTextScopes(scopes, field.value, options);
|
|
219
|
+
}
|
|
220
|
+
return EMPTY_TEXT_EVALUATION;
|
|
221
|
+
}
|
|
222
|
+
function evaluatePropertyExpression(property, properties, document, options) {
|
|
223
|
+
const record = resolvePropertyRecord(property.name, properties);
|
|
224
|
+
if (!record)
|
|
225
|
+
return EMPTY_DOCUMENT_EVALUATION;
|
|
226
|
+
const metadataRanges = propertyNameMetadataRanges(document.metadataText ?? "", property.name, options);
|
|
227
|
+
if (!property.value) {
|
|
228
|
+
return {
|
|
229
|
+
matched: true,
|
|
230
|
+
score: 30,
|
|
231
|
+
ranges: { metadata: metadataRanges },
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (property.value.type === "comparison") {
|
|
235
|
+
const matched = comparePropertyValue(record.value, property.value);
|
|
236
|
+
return matched
|
|
237
|
+
? { matched: true, score: 35, ranges: { metadata: metadataRanges } }
|
|
238
|
+
: EMPTY_DOCUMENT_EVALUATION;
|
|
239
|
+
}
|
|
240
|
+
if (property.value.type === "literal" && property.value.kind === "null") {
|
|
241
|
+
const matched = isNullishPropertyValue(record.value);
|
|
242
|
+
return matched
|
|
243
|
+
? { matched: true, score: 35, ranges: { metadata: metadataRanges } }
|
|
244
|
+
: EMPTY_DOCUMENT_EVALUATION;
|
|
245
|
+
}
|
|
246
|
+
const values = propertyValueTexts(record.value);
|
|
247
|
+
const valueEvaluation = combineTextOr(values.map((value) => evaluateTextExpression(property.value, value, options)));
|
|
248
|
+
if (!valueEvaluation.matched)
|
|
249
|
+
return EMPTY_DOCUMENT_EVALUATION;
|
|
250
|
+
return {
|
|
251
|
+
matched: true,
|
|
252
|
+
score: valueEvaluation.score + 30,
|
|
253
|
+
ranges: {
|
|
254
|
+
metadata: mergeRanges([
|
|
255
|
+
...metadataRanges,
|
|
256
|
+
...values.flatMap((value) => findSearchQueryRangesInText(document.metadataText ?? "", value, {
|
|
257
|
+
...options,
|
|
258
|
+
field: "metadata",
|
|
259
|
+
})),
|
|
260
|
+
]),
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function evaluateTextPropertyExpression(property, text, options) {
|
|
265
|
+
if (options.field !== "metadata")
|
|
266
|
+
return EMPTY_TEXT_EVALUATION;
|
|
267
|
+
const nameRanges = propertyNameMetadataRanges(text, property.name, options);
|
|
268
|
+
if (!nameRanges.length)
|
|
269
|
+
return EMPTY_TEXT_EVALUATION;
|
|
270
|
+
if (!property.value) {
|
|
271
|
+
return {
|
|
272
|
+
matched: true,
|
|
273
|
+
score: nameRanges.length * FIELD_WEIGHTS.metadata,
|
|
274
|
+
ranges: nameRanges,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
const valueEvaluation = evaluateTextExpression(property.value, text, options);
|
|
278
|
+
if (!valueEvaluation.matched)
|
|
279
|
+
return EMPTY_TEXT_EVALUATION;
|
|
280
|
+
return {
|
|
281
|
+
matched: true,
|
|
282
|
+
score: valueEvaluation.score + FIELD_WEIGHTS.metadata,
|
|
283
|
+
ranges: mergeRanges([...nameRanges, ...valueEvaluation.ranges]),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function evaluateContentScopes(scopes, expression, options) {
|
|
287
|
+
const evaluation = evaluateTextScopes(scopes, expression, {
|
|
288
|
+
...options,
|
|
289
|
+
field: "content",
|
|
290
|
+
});
|
|
291
|
+
if (!evaluation.matched)
|
|
292
|
+
return EMPTY_DOCUMENT_EVALUATION;
|
|
293
|
+
return {
|
|
294
|
+
matched: true,
|
|
295
|
+
score: evaluation.score + FIELD_WEIGHTS.content,
|
|
296
|
+
ranges: { content: evaluation.ranges },
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function evaluateTextScopes(scopes, expression, options) {
|
|
300
|
+
const matches = scopes
|
|
301
|
+
.map((scope) => {
|
|
302
|
+
const evaluation = evaluateTextExpression(expression, scope.text, options);
|
|
303
|
+
return {
|
|
304
|
+
...evaluation,
|
|
305
|
+
ranges: evaluation.ranges.map((range) => ({
|
|
306
|
+
start: scope.offset + range.start,
|
|
307
|
+
end: scope.offset + range.end,
|
|
308
|
+
})),
|
|
309
|
+
};
|
|
310
|
+
})
|
|
311
|
+
.filter((evaluation) => evaluation.matched);
|
|
312
|
+
if (!matches.length)
|
|
313
|
+
return EMPTY_TEXT_EVALUATION;
|
|
314
|
+
return {
|
|
315
|
+
matched: true,
|
|
316
|
+
score: matches.reduce((total, entry) => total + Math.max(1, entry.score), 0),
|
|
317
|
+
ranges: mergeRanges(matches.flatMap((entry) => entry.ranges)),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function evaluateLegacyTerms(document, query, options) {
|
|
321
|
+
const terms = legacyTerms(query);
|
|
322
|
+
if (!terms.length)
|
|
323
|
+
return { matched: true, score: 0 };
|
|
324
|
+
let score = 0;
|
|
325
|
+
const fields = documentFields(document);
|
|
326
|
+
for (const term of terms) {
|
|
327
|
+
let matched = false;
|
|
328
|
+
for (const [field, text] of fields) {
|
|
329
|
+
const ranges = findLiteralRanges(text, term, { ...options, field });
|
|
330
|
+
if (ranges.length) {
|
|
331
|
+
matched = true;
|
|
332
|
+
score += ranges.length * FIELD_WEIGHTS[field];
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (!matched)
|
|
336
|
+
return { matched: false, score: 0 };
|
|
337
|
+
}
|
|
338
|
+
return { matched: true, score };
|
|
339
|
+
}
|
|
340
|
+
function combineDocumentAnd(items) {
|
|
341
|
+
if (items.some((item) => !item.matched))
|
|
342
|
+
return EMPTY_DOCUMENT_EVALUATION;
|
|
343
|
+
return {
|
|
344
|
+
matched: true,
|
|
345
|
+
score: items.reduce((total, item) => total + item.score, 0),
|
|
346
|
+
ranges: mergeFieldRanges(items.map((item) => item.ranges)),
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function combineDocumentOr(items) {
|
|
350
|
+
const matches = items.filter((item) => item.matched);
|
|
351
|
+
if (!matches.length)
|
|
352
|
+
return EMPTY_DOCUMENT_EVALUATION;
|
|
353
|
+
return {
|
|
354
|
+
matched: true,
|
|
355
|
+
score: matches.reduce((total, item) => total + item.score, 0),
|
|
356
|
+
ranges: mergeFieldRanges(matches.map((item) => item.ranges)),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function combineTextAnd(items) {
|
|
360
|
+
if (items.some((item) => !item.matched))
|
|
361
|
+
return EMPTY_TEXT_EVALUATION;
|
|
362
|
+
return {
|
|
363
|
+
matched: true,
|
|
364
|
+
score: items.reduce((total, item) => total + item.score, 0),
|
|
365
|
+
ranges: mergeRanges(items.flatMap((item) => item.ranges)),
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function combineTextOr(items) {
|
|
369
|
+
const matches = items.filter((item) => item.matched);
|
|
370
|
+
if (!matches.length)
|
|
371
|
+
return EMPTY_TEXT_EVALUATION;
|
|
372
|
+
return {
|
|
373
|
+
matched: true,
|
|
374
|
+
score: matches.reduce((total, item) => total + item.score, 0),
|
|
375
|
+
ranges: mergeRanges(matches.flatMap((item) => item.ranges)),
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function literalRanges(text, literal, options) {
|
|
379
|
+
if (literal.kind === "null" || literal.value === null)
|
|
380
|
+
return [];
|
|
381
|
+
if (literal.kind === "regex") {
|
|
382
|
+
return findRegexRanges(text, literal.value, options);
|
|
383
|
+
}
|
|
384
|
+
return findLiteralRanges(text, literal.value, options);
|
|
385
|
+
}
|
|
386
|
+
function literalScore(literal) {
|
|
387
|
+
return literal.kind === "regex"
|
|
388
|
+
? 20
|
|
389
|
+
: Math.max(1, literal.value?.length ?? 1);
|
|
390
|
+
}
|
|
391
|
+
function findLiteralRanges(text, term, options) {
|
|
392
|
+
const needle = options.caseSensitive ? term : term.toLowerCase();
|
|
393
|
+
const haystack = options.caseSensitive ? text : text.toLowerCase();
|
|
394
|
+
if (!needle.length)
|
|
395
|
+
return [];
|
|
396
|
+
const ranges = [];
|
|
397
|
+
let cursor = 0;
|
|
398
|
+
while (cursor < haystack.length) {
|
|
399
|
+
const index = haystack.indexOf(needle, cursor);
|
|
400
|
+
if (index === -1)
|
|
401
|
+
break;
|
|
402
|
+
ranges.push({ start: index, end: index + term.length });
|
|
403
|
+
cursor = index + Math.max(1, term.length);
|
|
404
|
+
if (ranges.length >= 64)
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
return ranges;
|
|
408
|
+
}
|
|
409
|
+
function findRegexRanges(text, source, options) {
|
|
410
|
+
try {
|
|
411
|
+
const flags = options.caseSensitive ? "gu" : "giu";
|
|
412
|
+
const regex = new RegExp(source, flags);
|
|
413
|
+
const ranges = [];
|
|
414
|
+
for (const match of text.matchAll(regex)) {
|
|
415
|
+
const start = match.index ?? 0;
|
|
416
|
+
const end = start + match[0].length;
|
|
417
|
+
if (end > start) {
|
|
418
|
+
ranges.push({ start, end });
|
|
419
|
+
}
|
|
420
|
+
if (ranges.length >= 64)
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
return ranges;
|
|
424
|
+
}
|
|
425
|
+
catch {
|
|
426
|
+
return [];
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function fieldNameToSearchField(name) {
|
|
430
|
+
switch (name) {
|
|
431
|
+
case "file":
|
|
432
|
+
return "name";
|
|
433
|
+
case "path":
|
|
434
|
+
return "path";
|
|
435
|
+
case "content":
|
|
436
|
+
return "content";
|
|
437
|
+
case "tag":
|
|
438
|
+
return "tags";
|
|
439
|
+
default:
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
function documentFields(document) {
|
|
444
|
+
return [
|
|
445
|
+
["name", document.name],
|
|
446
|
+
["path", document.path],
|
|
447
|
+
[
|
|
448
|
+
"content",
|
|
449
|
+
document.chunks?.map((chunk) => chunk.text).join("\n") ||
|
|
450
|
+
document.content,
|
|
451
|
+
],
|
|
452
|
+
["tags", documentFieldText(document, "tags")],
|
|
453
|
+
["metadata", document.metadataText ?? ""],
|
|
454
|
+
];
|
|
455
|
+
}
|
|
456
|
+
function documentFieldText(document, field) {
|
|
457
|
+
switch (field) {
|
|
458
|
+
case "name":
|
|
459
|
+
return document.name;
|
|
460
|
+
case "path":
|
|
461
|
+
return document.path;
|
|
462
|
+
case "content":
|
|
463
|
+
return document.content;
|
|
464
|
+
case "tags":
|
|
465
|
+
return [
|
|
466
|
+
...document.tags,
|
|
467
|
+
...document.tags.map((tag) => `#${tag}`),
|
|
468
|
+
...document.tagParts,
|
|
469
|
+
...document.tagHierarchy,
|
|
470
|
+
].join(" ");
|
|
471
|
+
case "metadata":
|
|
472
|
+
return document.metadataText ?? "";
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function resolvePropertyRecord(name, properties) {
|
|
476
|
+
const exact = properties.find((entry) => entry.name.toLowerCase() === name.toLowerCase());
|
|
477
|
+
if (exact) {
|
|
478
|
+
return exact;
|
|
479
|
+
}
|
|
480
|
+
const segments = nestedPropertySegments(name);
|
|
481
|
+
if (segments.length < 2) {
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
const [root, ...path] = segments;
|
|
485
|
+
const rootRecord = properties.find((entry) => entry.name.toLowerCase() === root.toLowerCase());
|
|
486
|
+
if (!rootRecord) {
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
const values = resolveNestedPropertyValues(rootRecord.value, path);
|
|
490
|
+
if (!values.length) {
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
name,
|
|
495
|
+
value: values.length === 1 ? values[0] : values,
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function nestedPropertySegments(name) {
|
|
499
|
+
return name
|
|
500
|
+
.replace(/\[\]/gu, "")
|
|
501
|
+
.split(".")
|
|
502
|
+
.map((segment) => segment.trim())
|
|
503
|
+
.filter(Boolean);
|
|
504
|
+
}
|
|
505
|
+
function resolveNestedPropertyValues(value, segments) {
|
|
506
|
+
if (!segments.length) {
|
|
507
|
+
return [value];
|
|
508
|
+
}
|
|
509
|
+
if (Array.isArray(value)) {
|
|
510
|
+
return value.flatMap((item) => resolveNestedPropertyValues(item, segments));
|
|
511
|
+
}
|
|
512
|
+
if (!value || typeof value !== "object") {
|
|
513
|
+
return [];
|
|
514
|
+
}
|
|
515
|
+
const segment = segments[0];
|
|
516
|
+
const rest = segments.slice(1);
|
|
517
|
+
if (!Object.prototype.hasOwnProperty.call(value, segment)) {
|
|
518
|
+
return [];
|
|
519
|
+
}
|
|
520
|
+
return resolveNestedPropertyValues(value[segment], rest);
|
|
521
|
+
}
|
|
522
|
+
function propertyNameMetadataRanges(text, name, options) {
|
|
523
|
+
const exact = findLiteralRanges(text, name, {
|
|
524
|
+
...options,
|
|
525
|
+
field: "metadata",
|
|
526
|
+
});
|
|
527
|
+
if (exact.length) {
|
|
528
|
+
return exact;
|
|
529
|
+
}
|
|
530
|
+
const segments = nestedPropertySegments(name);
|
|
531
|
+
if (segments.length < 2) {
|
|
532
|
+
return exact;
|
|
533
|
+
}
|
|
534
|
+
return mergeRanges(segments.flatMap((segment) => findLiteralRanges(text, segment, {
|
|
535
|
+
...options,
|
|
536
|
+
field: "metadata",
|
|
537
|
+
})));
|
|
538
|
+
}
|
|
539
|
+
function propertyValueTexts(value) {
|
|
540
|
+
if (Array.isArray(value)) {
|
|
541
|
+
return value.flatMap((item) => propertyValueTexts(item));
|
|
542
|
+
}
|
|
543
|
+
if (value && typeof value === "object") {
|
|
544
|
+
return [JSON.stringify(value)];
|
|
545
|
+
}
|
|
546
|
+
if (value === null || value === undefined) {
|
|
547
|
+
return [""];
|
|
548
|
+
}
|
|
549
|
+
return [String(value)];
|
|
550
|
+
}
|
|
551
|
+
function comparePropertyValue(propertyValue, comparison) {
|
|
552
|
+
const values = propertyValueComparisonValues(propertyValue);
|
|
553
|
+
return values.some((value) => compareSinglePropertyValue(value, comparison));
|
|
554
|
+
}
|
|
555
|
+
function propertyValueComparisonValues(value) {
|
|
556
|
+
if (Array.isArray(value)) {
|
|
557
|
+
return value.flatMap((item) => propertyValueComparisonValues(item));
|
|
558
|
+
}
|
|
559
|
+
return [value];
|
|
560
|
+
}
|
|
561
|
+
function compareSinglePropertyValue(propertyValue, comparison) {
|
|
562
|
+
const target = comparison.value?.value;
|
|
563
|
+
if (target === null || target === undefined)
|
|
564
|
+
return false;
|
|
565
|
+
const leftNumber = Number(propertyValue);
|
|
566
|
+
const rightNumber = Number(target);
|
|
567
|
+
let order;
|
|
568
|
+
if (Number.isFinite(leftNumber) && Number.isFinite(rightNumber)) {
|
|
569
|
+
order = leftNumber - rightNumber;
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
const leftDate = Date.parse(String(propertyValue));
|
|
573
|
+
const rightDate = Date.parse(String(target));
|
|
574
|
+
if (Number.isFinite(leftDate) && Number.isFinite(rightDate)) {
|
|
575
|
+
order = leftDate - rightDate;
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
order = String(propertyValue).localeCompare(String(target));
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
switch (comparison.operator) {
|
|
582
|
+
case "<":
|
|
583
|
+
return order < 0;
|
|
584
|
+
case "<=":
|
|
585
|
+
return order <= 0;
|
|
586
|
+
case ">":
|
|
587
|
+
return order > 0;
|
|
588
|
+
case ">=":
|
|
589
|
+
return order >= 0;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function isNullishPropertyValue(value) {
|
|
593
|
+
if (value === null || value === undefined)
|
|
594
|
+
return true;
|
|
595
|
+
if (typeof value === "string")
|
|
596
|
+
return value.trim().length === 0;
|
|
597
|
+
if (Array.isArray(value)) {
|
|
598
|
+
return value.length === 0 || value.some(isNullishPropertyValue);
|
|
599
|
+
}
|
|
600
|
+
return false;
|
|
601
|
+
}
|
|
602
|
+
function lineScopes(text) {
|
|
603
|
+
const scopes = [];
|
|
604
|
+
let offset = 0;
|
|
605
|
+
for (const line of text.split(/\n/)) {
|
|
606
|
+
scopes.push({ text: line, offset });
|
|
607
|
+
offset += line.length + 1;
|
|
608
|
+
}
|
|
609
|
+
return scopes;
|
|
610
|
+
}
|
|
611
|
+
function blockScopes(text) {
|
|
612
|
+
const scopes = [];
|
|
613
|
+
const pattern = /\S(?:.|\n)*?(?=\n\s*\n|$)/g;
|
|
614
|
+
for (const match of text.matchAll(pattern)) {
|
|
615
|
+
scopes.push({ text: match[0], offset: match.index ?? 0 });
|
|
616
|
+
}
|
|
617
|
+
return scopes.length ? scopes : [{ text, offset: 0 }];
|
|
618
|
+
}
|
|
619
|
+
function sectionScopes(text) {
|
|
620
|
+
const headings = [...text.matchAll(/^#{1,6}\s+.*$/gm)].map((match) => ({
|
|
621
|
+
offset: match.index ?? 0,
|
|
622
|
+
level: match[0].match(/^#+/)?.[0].length ?? 1,
|
|
623
|
+
}));
|
|
624
|
+
if (!headings.length)
|
|
625
|
+
return [{ text, offset: 0 }];
|
|
626
|
+
return headings.map((heading, index) => {
|
|
627
|
+
const next = headings
|
|
628
|
+
.slice(index + 1)
|
|
629
|
+
.find((candidate) => candidate.level <= heading.level);
|
|
630
|
+
const end = next?.offset ?? text.length;
|
|
631
|
+
return {
|
|
632
|
+
text: text.slice(heading.offset, end),
|
|
633
|
+
offset: heading.offset,
|
|
634
|
+
};
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
function taskScopes(text, status) {
|
|
638
|
+
return lineScopes(text).filter((scope) => {
|
|
639
|
+
const match = scope.text.match(/^\s*[-*+]\s+\[([^\]])\]\s+/);
|
|
640
|
+
if (!match)
|
|
641
|
+
return false;
|
|
642
|
+
const done = match[1]?.toLowerCase() === "x";
|
|
643
|
+
return status === "any" || (status === "done" ? done : !done);
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
function legacyTerms(query) {
|
|
647
|
+
return query
|
|
648
|
+
.toLowerCase()
|
|
649
|
+
.split(/\s+/)
|
|
650
|
+
.map((part) => part.trim())
|
|
651
|
+
.filter(Boolean);
|
|
652
|
+
}
|
|
653
|
+
function mergeFieldRanges(ranges) {
|
|
654
|
+
const merged = {};
|
|
655
|
+
for (const fieldRanges of ranges) {
|
|
656
|
+
for (const [field, values] of Object.entries(fieldRanges)) {
|
|
657
|
+
merged[field] = mergeRanges([
|
|
658
|
+
...(merged[field] ?? []),
|
|
659
|
+
...(values ?? []),
|
|
660
|
+
]);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return merged;
|
|
664
|
+
}
|
|
665
|
+
function mergeRanges(ranges) {
|
|
666
|
+
const sorted = [...ranges].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
667
|
+
const merged = [];
|
|
668
|
+
for (const range of sorted) {
|
|
669
|
+
const previous = merged[merged.length - 1];
|
|
670
|
+
if (previous && range.start <= previous.end) {
|
|
671
|
+
previous.end = Math.max(previous.end, range.end);
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
merged.push({ ...range });
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
return merged;
|
|
678
|
+
}
|