@superbee/core 0.2.0-pre.8 → 0.4.10-pre.11
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/LICENSE +202 -0
- package/README.md +1345 -6
- package/dist/artifact-contract.d.ts +90 -0
- package/dist/artifact-contract.d.ts.map +1 -0
- package/dist/artifact-contract.js +205 -0
- package/dist/artifact-contract.js.map +1 -0
- package/dist/backend.d.ts +50 -2
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +311 -33
- package/dist/backend.js.map +1 -1
- package/dist/blob-contract.d.ts +82 -0
- package/dist/blob-contract.d.ts.map +1 -0
- package/dist/blob-contract.js +134 -0
- package/dist/blob-contract.js.map +1 -0
- package/dist/blob-journal.d.ts +303 -0
- package/dist/blob-journal.d.ts.map +1 -0
- package/dist/blob-journal.js +541 -0
- package/dist/blob-journal.js.map +1 -0
- package/dist/body-pages.d.ts +20 -0
- package/dist/body-pages.d.ts.map +1 -0
- package/dist/body-pages.js +56 -0
- package/dist/body-pages.js.map +1 -0
- package/dist/body-replace-guards.d.ts +81 -0
- package/dist/body-replace-guards.d.ts.map +1 -0
- package/dist/body-replace-guards.js +271 -0
- package/dist/body-replace-guards.js.map +1 -0
- package/dist/bounded-yaml.d.ts +28 -0
- package/dist/bounded-yaml.d.ts.map +1 -0
- package/dist/bounded-yaml.js +182 -0
- package/dist/bounded-yaml.js.map +1 -0
- package/dist/builtin-recipes/content.d.ts +93 -0
- package/dist/builtin-recipes/content.d.ts.map +1 -0
- package/dist/builtin-recipes/content.js +288 -0
- package/dist/builtin-recipes/content.js.map +1 -0
- package/dist/builtin-recipes/site.d.ts +5 -0
- package/dist/builtin-recipes/site.d.ts.map +1 -0
- package/dist/builtin-recipes/site.js +83 -0
- package/dist/builtin-recipes/site.js.map +1 -0
- package/dist/builtin-recipes.d.ts +13 -0
- package/dist/builtin-recipes.d.ts.map +1 -0
- package/dist/builtin-recipes.js +123 -0
- package/dist/builtin-recipes.js.map +1 -0
- package/dist/bundle-health/index.d.ts +14 -0
- package/dist/bundle-health/index.d.ts.map +1 -0
- package/dist/bundle-health/index.js +12 -0
- package/dist/bundle-health/index.js.map +1 -0
- package/dist/bundle-health/kind-findings.d.ts +45 -0
- package/dist/bundle-health/kind-findings.d.ts.map +1 -0
- package/dist/bundle-health/kind-findings.js +67 -0
- package/dist/bundle-health/kind-findings.js.map +1 -0
- package/dist/bundle-health/legacy-page.d.ts +21 -0
- package/dist/bundle-health/legacy-page.d.ts.map +1 -0
- package/dist/bundle-health/legacy-page.js +25 -0
- package/dist/bundle-health/legacy-page.js.map +1 -0
- package/dist/bundle-health/report.d.ts +191 -0
- package/dist/bundle-health/report.d.ts.map +1 -0
- package/dist/bundle-health/report.js +419 -0
- package/dist/bundle-health/report.js.map +1 -0
- package/dist/bundle-ops.d.ts +10 -4
- package/dist/bundle-ops.d.ts.map +1 -1
- package/dist/bundle-ops.js +15 -8
- package/dist/bundle-ops.js.map +1 -1
- package/dist/bundle.d.ts +2 -4
- package/dist/bundle.d.ts.map +1 -1
- package/dist/bundle.js +3 -12
- package/dist/bundle.js.map +1 -1
- package/dist/code-point-order.d.ts +8 -0
- package/dist/code-point-order.d.ts.map +1 -0
- package/dist/code-point-order.js +20 -0
- package/dist/code-point-order.js.map +1 -0
- package/dist/code-unit-order.d.ts +15 -0
- package/dist/code-unit-order.d.ts.map +1 -0
- package/dist/code-unit-order.js +17 -0
- package/dist/code-unit-order.js.map +1 -0
- package/dist/connector-request.d.ts +112 -0
- package/dist/connector-request.d.ts.map +1 -0
- package/dist/connector-request.js +495 -0
- package/dist/connector-request.js.map +1 -0
- package/dist/connectors.d.ts +297 -0
- package/dist/connectors.d.ts.map +1 -0
- package/dist/connectors.js +1233 -0
- package/dist/connectors.js.map +1 -0
- package/dist/convention-record.d.ts +9 -0
- package/dist/convention-record.d.ts.map +1 -0
- package/dist/convention-record.js +13 -0
- package/dist/convention-record.js.map +1 -0
- package/dist/cross-bundle.d.ts +135 -0
- package/dist/cross-bundle.d.ts.map +1 -0
- package/dist/cross-bundle.js +191 -0
- package/dist/cross-bundle.js.map +1 -0
- package/dist/dependencies.d.ts +208 -0
- package/dist/dependencies.d.ts.map +1 -0
- package/dist/dependencies.js +367 -0
- package/dist/dependencies.js.map +1 -0
- package/dist/document-codec.d.ts +4 -1
- package/dist/document-codec.d.ts.map +1 -1
- package/dist/document-codec.js +3 -1
- package/dist/document-codec.js.map +1 -1
- package/dist/document-field-actions.d.ts +34 -3
- package/dist/document-field-actions.d.ts.map +1 -1
- package/dist/document-field-actions.js +149 -43
- package/dist/document-field-actions.js.map +1 -1
- package/dist/document-mutation.d.ts +55 -18
- package/dist/document-mutation.d.ts.map +1 -1
- package/dist/document-mutation.js +210 -86
- package/dist/document-mutation.js.map +1 -1
- package/dist/document-persistence.d.ts +12 -0
- package/dist/document-persistence.d.ts.map +1 -0
- package/dist/document-persistence.js +44 -0
- package/dist/document-persistence.js.map +1 -0
- package/dist/document-replace-rules.d.ts +44 -0
- package/dist/document-replace-rules.d.ts.map +1 -0
- package/dist/document-replace-rules.js +41 -0
- package/dist/document-replace-rules.js.map +1 -0
- package/dist/document-scan.d.ts +26 -0
- package/dist/document-scan.d.ts.map +1 -0
- package/dist/document-scan.js +70 -0
- package/dist/document-scan.js.map +1 -0
- package/dist/document-transfer.d.ts +312 -0
- package/dist/document-transfer.d.ts.map +1 -0
- package/dist/document-transfer.js +1400 -0
- package/dist/document-transfer.js.map +1 -0
- package/dist/document-write-policy.d.ts +15 -4
- package/dist/document-write-policy.d.ts.map +1 -1
- package/dist/document-write-policy.js +41 -27
- package/dist/document-write-policy.js.map +1 -1
- package/dist/domain-model.d.ts +73 -0
- package/dist/domain-model.d.ts.map +1 -0
- package/dist/domain-model.js +169 -0
- package/dist/domain-model.js.map +1 -0
- package/dist/edge-harness/corpus.d.ts +9 -0
- package/dist/edge-harness/corpus.d.ts.map +1 -0
- package/dist/edge-harness/corpus.js +57 -0
- package/dist/edge-harness/corpus.js.map +1 -0
- package/dist/edge-harness/index.d.ts +21 -0
- package/dist/edge-harness/index.d.ts.map +1 -0
- package/dist/edge-harness/index.js +537 -0
- package/dist/edge-harness/index.js.map +1 -0
- package/dist/edges/find.d.ts +14 -0
- package/dist/edges/find.d.ts.map +1 -0
- package/dist/edges/find.js +46 -0
- package/dist/edges/find.js.map +1 -0
- package/dist/edges/index.d.ts +13 -0
- package/dist/edges/index.d.ts.map +1 -0
- package/dist/edges/index.js +5 -0
- package/dist/edges/index.js.map +1 -0
- package/dist/edges/memory-source.d.ts +8 -0
- package/dist/edges/memory-source.d.ts.map +1 -0
- package/dist/edges/memory-source.js +164 -0
- package/dist/edges/memory-source.js.map +1 -0
- package/dist/edges/read-bounds.d.ts +6 -0
- package/dist/edges/read-bounds.d.ts.map +1 -0
- package/dist/edges/read-bounds.js +13 -0
- package/dist/edges/read-bounds.js.map +1 -0
- package/dist/edges/source.d.ts +123 -0
- package/dist/edges/source.d.ts.map +1 -0
- package/dist/edges/source.js +2 -0
- package/dist/edges/source.js.map +1 -0
- package/dist/edges/walk.d.ts +7 -0
- package/dist/edges/walk.d.ts.map +1 -0
- package/dist/edges/walk.js +14 -0
- package/dist/edges/walk.js.map +1 -0
- package/dist/engine.d.ts +54 -18
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +137 -108
- package/dist/engine.js.map +1 -1
- package/dist/errors.d.ts +37 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +75 -3
- package/dist/errors.js.map +1 -1
- package/dist/file-journaled-backend-internal.d.ts +2 -0
- package/dist/file-journaled-backend-internal.d.ts.map +1 -1
- package/dist/file-journaled-backend-internal.js +2 -0
- package/dist/file-journaled-backend-internal.js.map +1 -1
- package/dist/file-journaled-backend.d.ts +38 -40
- package/dist/file-journaled-backend.d.ts.map +1 -1
- package/dist/file-journaled-backend.js +284 -52
- package/dist/file-journaled-backend.js.map +1 -1
- package/dist/filesystem-identity.d.ts +116 -17
- package/dist/filesystem-identity.d.ts.map +1 -1
- package/dist/filesystem-identity.js +532 -51
- package/dist/filesystem-identity.js.map +1 -1
- package/dist/filesystem-lock.d.ts +9 -2
- package/dist/filesystem-lock.d.ts.map +1 -1
- package/dist/filesystem-lock.js +134 -17
- package/dist/filesystem-lock.js.map +1 -1
- package/dist/filesystem-temp-name.d.ts +9 -0
- package/dist/filesystem-temp-name.d.ts.map +1 -0
- package/dist/filesystem-temp-name.js +20 -0
- package/dist/filesystem-temp-name.js.map +1 -0
- package/dist/filesystem.d.ts +6 -0
- package/dist/filesystem.d.ts.map +1 -1
- package/dist/filesystem.js +2 -1
- package/dist/filesystem.js.map +1 -1
- package/dist/freshness.d.ts +16 -1
- package/dist/freshness.d.ts.map +1 -1
- package/dist/freshness.js +47 -17
- package/dist/freshness.js.map +1 -1
- package/dist/frontmatter-contract.d.ts +14 -0
- package/dist/frontmatter-contract.d.ts.map +1 -1
- package/dist/frontmatter-contract.js +22 -0
- package/dist/frontmatter-contract.js.map +1 -1
- package/dist/frontmatter-splitter.d.ts +6 -0
- package/dist/frontmatter-splitter.d.ts.map +1 -1
- package/dist/frontmatter-splitter.js +8 -0
- package/dist/frontmatter-splitter.js.map +1 -1
- package/dist/frontmatter.d.ts +17 -7
- package/dist/frontmatter.d.ts.map +1 -1
- package/dist/frontmatter.js +52 -11
- package/dist/frontmatter.js.map +1 -1
- package/dist/governed-body-write.d.ts.map +1 -1
- package/dist/governed-body-write.js +13 -6
- package/dist/governed-body-write.js.map +1 -1
- package/dist/heads-digest.d.ts.map +1 -1
- package/dist/heads-digest.js +2 -1
- package/dist/heads-digest.js.map +1 -1
- package/dist/hosted-client/binding.d.ts +7 -0
- package/dist/hosted-client/binding.d.ts.map +1 -0
- package/dist/hosted-client/binding.js +10 -0
- package/dist/hosted-client/binding.js.map +1 -0
- package/dist/hosted-client/blob-delivery.d.ts +68 -0
- package/dist/hosted-client/blob-delivery.d.ts.map +1 -0
- package/dist/hosted-client/blob-delivery.js +170 -0
- package/dist/hosted-client/blob-delivery.js.map +1 -0
- package/dist/hosted-client/blob-write.d.ts +387 -0
- package/dist/hosted-client/blob-write.d.ts.map +1 -0
- package/dist/hosted-client/blob-write.js +770 -0
- package/dist/hosted-client/blob-write.js.map +1 -0
- package/dist/hosted-client/bundle-listing.d.ts +46 -0
- package/dist/hosted-client/bundle-listing.d.ts.map +1 -0
- package/dist/hosted-client/bundle-listing.js +36 -0
- package/dist/hosted-client/bundle-listing.js.map +1 -0
- package/dist/hosted-client/client.d.ts +249 -0
- package/dist/hosted-client/client.d.ts.map +1 -0
- package/dist/hosted-client/client.js +381 -0
- package/dist/hosted-client/client.js.map +1 -0
- package/dist/hosted-client/directory.d.ts +46 -0
- package/dist/hosted-client/directory.d.ts.map +1 -0
- package/dist/hosted-client/directory.js +74 -0
- package/dist/hosted-client/directory.js.map +1 -0
- package/dist/hosted-client/errors.d.ts +26 -0
- package/dist/hosted-client/errors.d.ts.map +1 -0
- package/dist/hosted-client/errors.js +35 -0
- package/dist/hosted-client/errors.js.map +1 -0
- package/dist/hosted-client/inbox.d.ts +320 -0
- package/dist/hosted-client/inbox.d.ts.map +1 -0
- package/dist/hosted-client/inbox.js +379 -0
- package/dist/hosted-client/inbox.js.map +1 -0
- package/dist/hosted-client/index.d.ts +31 -0
- package/dist/hosted-client/index.d.ts.map +1 -0
- package/dist/hosted-client/index.js +33 -0
- package/dist/hosted-client/index.js.map +1 -0
- package/dist/hosted-client/journal.d.ts +103 -0
- package/dist/hosted-client/journal.d.ts.map +1 -0
- package/dist/hosted-client/journal.js +464 -0
- package/dist/hosted-client/journal.js.map +1 -0
- package/dist/hosted-client/node.d.ts +74 -0
- package/dist/hosted-client/node.d.ts.map +1 -0
- package/dist/hosted-client/node.js +219 -0
- package/dist/hosted-client/node.js.map +1 -0
- package/dist/hosted-client/reference.d.ts +12 -0
- package/dist/hosted-client/reference.d.ts.map +1 -0
- package/dist/hosted-client/reference.js +29 -0
- package/dist/hosted-client/reference.js.map +1 -0
- package/dist/hosted-client/view-content.d.ts +184 -0
- package/dist/hosted-client/view-content.d.ts.map +1 -0
- package/dist/hosted-client/view-content.js +268 -0
- package/dist/hosted-client/view-content.js.map +1 -0
- package/dist/hosted-client/write.d.ts +219 -0
- package/dist/hosted-client/write.d.ts.map +1 -0
- package/dist/hosted-client/write.js +419 -0
- package/dist/hosted-client/write.js.map +1 -0
- package/dist/hosted-transport/answer-rows.d.ts +132 -4
- package/dist/hosted-transport/answer-rows.d.ts.map +1 -1
- package/dist/hosted-transport/answer-rows.js +211 -11
- package/dist/hosted-transport/answer-rows.js.map +1 -1
- package/dist/hosted-transport/attribution.d.ts +32 -0
- package/dist/hosted-transport/attribution.d.ts.map +1 -0
- package/dist/hosted-transport/attribution.js +38 -0
- package/dist/hosted-transport/attribution.js.map +1 -0
- package/dist/hosted-transport/blob-reads.d.ts +35 -0
- package/dist/hosted-transport/blob-reads.d.ts.map +1 -0
- package/dist/hosted-transport/blob-reads.js +179 -0
- package/dist/hosted-transport/blob-reads.js.map +1 -0
- package/dist/hosted-transport/blob-write.d.ts +34 -0
- package/dist/hosted-transport/blob-write.d.ts.map +1 -0
- package/dist/hosted-transport/blob-write.js +115 -0
- package/dist/hosted-transport/blob-write.js.map +1 -0
- package/dist/hosted-transport/carrier.d.ts +35 -11
- package/dist/hosted-transport/carrier.d.ts.map +1 -1
- package/dist/hosted-transport/carrier.js +101 -57
- package/dist/hosted-transport/carrier.js.map +1 -1
- package/dist/hosted-transport/document-backend.d.ts +74 -0
- package/dist/hosted-transport/document-backend.d.ts.map +1 -0
- package/dist/hosted-transport/document-backend.js +160 -0
- package/dist/hosted-transport/document-backend.js.map +1 -0
- package/dist/hosted-transport/index.d.ts +7 -4
- package/dist/hosted-transport/index.d.ts.map +1 -1
- package/dist/hosted-transport/index.js +7 -4
- package/dist/hosted-transport/index.js.map +1 -1
- package/dist/hosted-transport/operations.d.ts +6 -0
- package/dist/hosted-transport/operations.d.ts.map +1 -1
- package/dist/hosted-transport/operations.js +2 -1
- package/dist/hosted-transport/operations.js.map +1 -1
- package/dist/hosted-transport/port-run.d.ts +41 -0
- package/dist/hosted-transport/port-run.d.ts.map +1 -0
- package/dist/hosted-transport/port-run.js +92 -0
- package/dist/hosted-transport/port-run.js.map +1 -0
- package/dist/hosted-transport/read-adapter.d.ts +19 -3
- package/dist/hosted-transport/read-adapter.d.ts.map +1 -1
- package/dist/hosted-transport/read-adapter.js +18 -5
- package/dist/hosted-transport/read-adapter.js.map +1 -1
- package/dist/hosted-transport/root-write.d.ts.map +1 -1
- package/dist/hosted-transport/root-write.js +5 -2
- package/dist/hosted-transport/root-write.js.map +1 -1
- package/dist/hosted-transport/whole-document-transport.d.ts +56 -7
- package/dist/hosted-transport/whole-document-transport.d.ts.map +1 -1
- package/dist/hosted-transport/whole-document-transport.js +120 -31
- package/dist/hosted-transport/whole-document-transport.js.map +1 -1
- package/dist/identity-fold.d.ts +16 -0
- package/dist/identity-fold.d.ts.map +1 -0
- package/dist/identity-fold.js +24 -0
- package/dist/identity-fold.js.map +1 -0
- package/dist/index-projection.d.ts +2 -1
- package/dist/index-projection.d.ts.map +1 -1
- package/dist/index-projection.js +38 -28
- package/dist/index-projection.js.map +1 -1
- package/dist/index.d.ts +61 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -21
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-backend.d.ts +0 -31
- package/dist/indexeddb-backend.d.ts.map +1 -1
- package/dist/indexeddb-backend.js +5 -2
- package/dist/indexeddb-backend.js.map +1 -1
- package/dist/inventory-guard.d.ts +58 -0
- package/dist/inventory-guard.d.ts.map +1 -0
- package/dist/inventory-guard.js +169 -0
- package/dist/inventory-guard.js.map +1 -0
- package/dist/journaled-backend.d.ts +14 -4
- package/dist/journaled-backend.d.ts.map +1 -1
- package/dist/journaled-backend.js +19 -78
- package/dist/journaled-backend.js.map +1 -1
- package/dist/json-data.d.ts +3 -0
- package/dist/json-data.d.ts.map +1 -0
- package/dist/json-data.js +19 -0
- package/dist/json-data.js.map +1 -0
- package/dist/kind-authoring.d.ts +188 -0
- package/dist/kind-authoring.d.ts.map +1 -0
- package/dist/kind-authoring.js +520 -0
- package/dist/kind-authoring.js.map +1 -0
- package/dist/kind-changes.d.ts +45 -0
- package/dist/kind-changes.d.ts.map +1 -0
- package/dist/kind-changes.js +96 -0
- package/dist/kind-changes.js.map +1 -0
- package/dist/kind-conformance-error.d.ts +16 -0
- package/dist/kind-conformance-error.d.ts.map +1 -0
- package/dist/kind-conformance-error.js +20 -0
- package/dist/kind-conformance-error.js.map +1 -0
- package/dist/kind-coverage.d.ts +100 -0
- package/dist/kind-coverage.d.ts.map +1 -0
- package/dist/kind-coverage.js +185 -0
- package/dist/kind-coverage.js.map +1 -0
- package/dist/kind-deprecation.d.ts +32 -0
- package/dist/kind-deprecation.d.ts.map +1 -0
- package/dist/kind-deprecation.js +141 -0
- package/dist/kind-deprecation.js.map +1 -0
- package/dist/kind-field-mutation.d.ts +7 -2
- package/dist/kind-field-mutation.d.ts.map +1 -1
- package/dist/kind-field-mutation.js +28 -3
- package/dist/kind-field-mutation.js.map +1 -1
- package/dist/kind-undeclared-fields.d.ts +72 -0
- package/dist/kind-undeclared-fields.d.ts.map +1 -0
- package/dist/kind-undeclared-fields.js +124 -0
- package/dist/kind-undeclared-fields.js.map +1 -0
- package/dist/kinds-load.d.ts.map +1 -1
- package/dist/kinds-load.js +8 -5
- package/dist/kinds-load.js.map +1 -1
- package/dist/kinds.d.ts +105 -13
- package/dist/kinds.d.ts.map +1 -1
- package/dist/kinds.js +369 -30
- package/dist/kinds.js.map +1 -1
- package/dist/link-add.d.ts +81 -0
- package/dist/link-add.d.ts.map +1 -0
- package/dist/link-add.js +94 -0
- package/dist/link-add.js.map +1 -0
- package/dist/link-emit.d.ts +29 -0
- package/dist/link-emit.d.ts.map +1 -0
- package/dist/link-emit.js +39 -0
- package/dist/link-emit.js.map +1 -0
- package/dist/link-findings.d.ts +132 -0
- package/dist/link-findings.d.ts.map +1 -0
- package/dist/link-findings.js +263 -0
- package/dist/link-findings.js.map +1 -0
- package/dist/link-types.d.ts +34 -0
- package/dist/link-types.d.ts.map +1 -0
- package/dist/link-types.js +79 -0
- package/dist/link-types.js.map +1 -0
- package/dist/links.d.ts +68 -9
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +370 -57
- package/dist/links.js.map +1 -1
- package/dist/local-search-index.d.ts +86 -0
- package/dist/local-search-index.d.ts.map +1 -0
- package/dist/local-search-index.js +1055 -0
- package/dist/local-search-index.js.map +1 -0
- package/dist/managed-document-metadata.d.ts +5 -0
- package/dist/managed-document-metadata.d.ts.map +1 -0
- package/dist/managed-document-metadata.js +10 -0
- package/dist/managed-document-metadata.js.map +1 -0
- package/dist/markdown-syntax.d.ts +39 -0
- package/dist/markdown-syntax.d.ts.map +1 -0
- package/dist/markdown-syntax.js +10170 -0
- package/dist/markdown-syntax.js.map +1 -0
- package/dist/memory-backend.d.ts +3 -0
- package/dist/memory-backend.d.ts.map +1 -1
- package/dist/memory-backend.js +40 -2
- package/dist/memory-backend.js.map +1 -1
- package/dist/mutation-attribution.d.ts +2 -1
- package/dist/mutation-attribution.d.ts.map +1 -1
- package/dist/mutation-attribution.js.map +1 -1
- package/dist/okf-actor.d.ts +14 -3
- package/dist/okf-actor.d.ts.map +1 -1
- package/dist/okf-actor.js +25 -4
- package/dist/okf-actor.js.map +1 -1
- package/dist/okf-authored-values.d.ts +2 -0
- package/dist/okf-authored-values.d.ts.map +1 -1
- package/dist/okf-authored-values.js +4 -0
- package/dist/okf-authored-values.js.map +1 -1
- package/dist/okf-authoring.d.ts +7 -0
- package/dist/okf-authoring.d.ts.map +1 -0
- package/dist/okf-authoring.js +30 -0
- package/dist/okf-authoring.js.map +1 -0
- package/dist/okf-standard-fields.d.ts +4 -0
- package/dist/okf-standard-fields.d.ts.map +1 -1
- package/dist/okf-standard-fields.js +24 -14
- package/dist/okf-standard-fields.js.map +1 -1
- package/dist/okf-timestamps.d.ts +2 -2
- package/dist/okf-timestamps.d.ts.map +1 -1
- package/dist/okf-timestamps.js +25 -15
- package/dist/okf-timestamps.js.map +1 -1
- package/dist/page.d.ts +3 -7
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +3 -7
- package/dist/page.js.map +1 -1
- package/dist/path-fold.d.ts +67 -0
- package/dist/path-fold.d.ts.map +1 -0
- package/dist/path-fold.js +107 -0
- package/dist/path-fold.js.map +1 -0
- package/dist/paths.d.ts +46 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +114 -1
- package/dist/paths.js.map +1 -1
- package/dist/platform.d.ts +13 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +16 -0
- package/dist/platform.js.map +1 -1
- package/dist/portable-export-contract.d.ts +17 -0
- package/dist/portable-export-contract.d.ts.map +1 -0
- package/dist/portable-export-contract.js +59 -0
- package/dist/portable-export-contract.js.map +1 -0
- package/dist/portable-export.d.ts +115 -0
- package/dist/portable-export.d.ts.map +1 -0
- package/dist/portable-export.js +452 -0
- package/dist/portable-export.js.map +1 -0
- package/dist/portable-frontmatter.d.ts +17 -0
- package/dist/portable-frontmatter.d.ts.map +1 -1
- package/dist/portable-frontmatter.js +42 -5
- package/dist/portable-frontmatter.js.map +1 -1
- package/dist/publication-filesystem.d.ts +1 -1
- package/dist/publication-filesystem.d.ts.map +1 -1
- package/dist/publication-filesystem.js +1 -1
- package/dist/publication-filesystem.js.map +1 -1
- package/dist/qualified-links.d.ts +67 -0
- package/dist/qualified-links.d.ts.map +1 -0
- package/dist/qualified-links.js +121 -0
- package/dist/qualified-links.js.map +1 -0
- package/dist/query-filter.d.ts +16 -4
- package/dist/query-filter.d.ts.map +1 -1
- package/dist/query-filter.js +44 -2
- package/dist/query-filter.js.map +1 -1
- package/dist/query-order.d.ts.map +1 -1
- package/dist/query-order.js +2 -1
- package/dist/query-order.js.map +1 -1
- package/dist/recipe-lifecycle/errors.d.ts +96 -0
- package/dist/recipe-lifecycle/errors.d.ts.map +1 -0
- package/dist/recipe-lifecycle/errors.js +122 -0
- package/dist/recipe-lifecycle/errors.js.map +1 -0
- package/dist/recipe-lifecycle/evolution.d.ts +134 -0
- package/dist/recipe-lifecycle/evolution.d.ts.map +1 -0
- package/dist/recipe-lifecycle/evolution.js +1047 -0
- package/dist/recipe-lifecycle/evolution.js.map +1 -0
- package/dist/recipe-lifecycle/index.d.ts +38 -0
- package/dist/recipe-lifecycle/index.d.ts.map +1 -0
- package/dist/recipe-lifecycle/index.js +31 -0
- package/dist/recipe-lifecycle/index.js.map +1 -0
- package/dist/recipe-lifecycle/install.d.ts +172 -0
- package/dist/recipe-lifecycle/install.d.ts.map +1 -0
- package/dist/recipe-lifecycle/install.js +652 -0
- package/dist/recipe-lifecycle/install.js.map +1 -0
- package/dist/recipe-lifecycle/legacy-aliases.d.ts +4 -0
- package/dist/recipe-lifecycle/legacy-aliases.d.ts.map +1 -0
- package/dist/recipe-lifecycle/legacy-aliases.js +22 -0
- package/dist/recipe-lifecycle/legacy-aliases.js.map +1 -0
- package/dist/recipe-lifecycle/retirement-apply.d.ts +59 -0
- package/dist/recipe-lifecycle/retirement-apply.d.ts.map +1 -0
- package/dist/recipe-lifecycle/retirement-apply.js +165 -0
- package/dist/recipe-lifecycle/retirement-apply.js.map +1 -0
- package/dist/recipe-lifecycle/retirement.d.ts +89 -0
- package/dist/recipe-lifecycle/retirement.d.ts.map +1 -0
- package/dist/recipe-lifecycle/retirement.js +347 -0
- package/dist/recipe-lifecycle/retirement.js.map +1 -0
- package/dist/recipe-lifecycle/set-commit.d.ts +31 -0
- package/dist/recipe-lifecycle/set-commit.d.ts.map +1 -0
- package/dist/recipe-lifecycle/set-commit.js +37 -0
- package/dist/recipe-lifecycle/set-commit.js.map +1 -0
- package/dist/recipe-lifecycle/stamp.d.ts +146 -0
- package/dist/recipe-lifecycle/stamp.d.ts.map +1 -0
- package/dist/recipe-lifecycle/stamp.js +361 -0
- package/dist/recipe-lifecycle/stamp.js.map +1 -0
- package/dist/recipe-qualify.d.ts +80 -0
- package/dist/recipe-qualify.d.ts.map +1 -0
- package/dist/recipe-qualify.js +352 -0
- package/dist/recipe-qualify.js.map +1 -0
- package/dist/recipe-set-preflight.d.ts +139 -0
- package/dist/recipe-set-preflight.d.ts.map +1 -0
- package/dist/recipe-set-preflight.js +536 -0
- package/dist/recipe-set-preflight.js.map +1 -0
- package/dist/recipe-sources.d.ts +209 -0
- package/dist/recipe-sources.d.ts.map +1 -0
- package/dist/recipe-sources.js +607 -0
- package/dist/recipe-sources.js.map +1 -0
- package/dist/recipes.d.ts +45 -1
- package/dist/recipes.d.ts.map +1 -1
- package/dist/recipes.js +138 -1
- package/dist/recipes.js.map +1 -1
- package/dist/record-overlay/apply.d.ts +43 -0
- package/dist/record-overlay/apply.d.ts.map +1 -0
- package/dist/record-overlay/apply.js +523 -0
- package/dist/record-overlay/apply.js.map +1 -0
- package/dist/record-overlay/canonical.d.ts +22 -0
- package/dist/record-overlay/canonical.d.ts.map +1 -0
- package/dist/record-overlay/canonical.js +47 -0
- package/dist/record-overlay/canonical.js.map +1 -0
- package/dist/record-overlay/digest.d.ts +4 -0
- package/dist/record-overlay/digest.d.ts.map +1 -0
- package/dist/record-overlay/digest.js +11 -0
- package/dist/record-overlay/digest.js.map +1 -0
- package/dist/record-overlay/errors.d.ts +44 -0
- package/dist/record-overlay/errors.d.ts.map +1 -0
- package/dist/record-overlay/errors.js +55 -0
- package/dist/record-overlay/errors.js.map +1 -0
- package/dist/record-overlay/findings.d.ts +5 -0
- package/dist/record-overlay/findings.d.ts.map +1 -0
- package/dist/record-overlay/findings.js +86 -0
- package/dist/record-overlay/findings.js.map +1 -0
- package/dist/record-overlay/index.d.ts +23 -0
- package/dist/record-overlay/index.d.ts.map +1 -0
- package/dist/record-overlay/index.js +21 -0
- package/dist/record-overlay/index.js.map +1 -0
- package/dist/record-overlay/plan.d.ts +12 -0
- package/dist/record-overlay/plan.d.ts.map +1 -0
- package/dist/record-overlay/plan.js +285 -0
- package/dist/record-overlay/plan.js.map +1 -0
- package/dist/record-overlay/policy.d.ts +74 -0
- package/dist/record-overlay/policy.d.ts.map +1 -0
- package/dist/record-overlay/policy.js +235 -0
- package/dist/record-overlay/policy.js.map +1 -0
- package/dist/record-overlay/redact.d.ts +3 -0
- package/dist/record-overlay/redact.d.ts.map +1 -0
- package/dist/record-overlay/redact.js +27 -0
- package/dist/record-overlay/redact.js.map +1 -0
- package/dist/record-overlay/signal-kind.d.ts +30 -0
- package/dist/record-overlay/signal-kind.d.ts.map +1 -0
- package/dist/record-overlay/signal-kind.js +38 -0
- package/dist/record-overlay/signal-kind.js.map +1 -0
- package/dist/record-overlay/signal-text.d.ts +52 -0
- package/dist/record-overlay/signal-text.d.ts.map +1 -0
- package/dist/record-overlay/signal-text.js +126 -0
- package/dist/record-overlay/signal-text.js.map +1 -0
- package/dist/record-overlay/source-index.d.ts +19 -0
- package/dist/record-overlay/source-index.d.ts.map +1 -0
- package/dist/record-overlay/source-index.js +102 -0
- package/dist/record-overlay/source-index.js.map +1 -0
- package/dist/record-overlay/types.d.ts +291 -0
- package/dist/record-overlay/types.d.ts.map +1 -0
- package/dist/record-overlay/types.js +2 -0
- package/dist/record-overlay/types.js.map +1 -0
- package/dist/relationships.d.ts +71 -0
- package/dist/relationships.d.ts.map +1 -0
- package/dist/relationships.js +87 -0
- package/dist/relationships.js.map +1 -0
- package/dist/remote-backend.d.ts +11 -21
- package/dist/remote-backend.d.ts.map +1 -1
- package/dist/remote-backend.js +20 -15
- package/dist/remote-backend.js.map +1 -1
- package/dist/remote-document-codec.d.ts +2 -1
- package/dist/remote-document-codec.d.ts.map +1 -1
- package/dist/remote-document-codec.js +3 -2
- package/dist/remote-document-codec.js.map +1 -1
- package/dist/remote-operations.d.ts +0 -41
- package/dist/remote-operations.d.ts.map +1 -1
- package/dist/remote-operations.js +14 -2
- package/dist/remote-operations.js.map +1 -1
- package/dist/remote-parsers.d.ts +19 -0
- package/dist/remote-parsers.d.ts.map +1 -1
- package/dist/remote-parsers.js.map +1 -1
- package/dist/remote.d.ts +2 -4
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +2 -3
- package/dist/remote.js.map +1 -1
- package/dist/reserved-write.d.ts +9 -0
- package/dist/reserved-write.d.ts.map +1 -0
- package/dist/reserved-write.js +15 -0
- package/dist/reserved-write.js.map +1 -0
- package/dist/search/backend-source.d.ts +6 -0
- package/dist/search/backend-source.d.ts.map +1 -0
- package/dist/search/backend-source.js +57 -0
- package/dist/search/backend-source.js.map +1 -0
- package/dist/search/contract.d.ts +162 -0
- package/dist/search/contract.d.ts.map +1 -0
- package/dist/search/contract.js +82 -0
- package/dist/search/contract.js.map +1 -0
- package/dist/search/errors.d.ts +30 -0
- package/dist/search/errors.d.ts.map +1 -0
- package/dist/search/errors.js +50 -0
- package/dist/search/errors.js.map +1 -0
- package/dist/search/identity.d.ts +12 -0
- package/dist/search/identity.d.ts.map +1 -0
- package/dist/search/identity.js +90 -0
- package/dist/search/identity.js.map +1 -0
- package/dist/search/index.d.ts +16 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +15 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/memory-source.d.ts +36 -0
- package/dist/search/memory-source.d.ts.map +1 -0
- package/dist/search/memory-source.js +238 -0
- package/dist/search/memory-source.js.map +1 -0
- package/dist/search/rank.d.ts +29 -0
- package/dist/search/rank.d.ts.map +1 -0
- package/dist/search/rank.js +132 -0
- package/dist/search/rank.js.map +1 -0
- package/dist/search/row-text.d.ts +38 -0
- package/dist/search/row-text.d.ts.map +1 -0
- package/dist/search/row-text.js +88 -0
- package/dist/search/row-text.js.map +1 -0
- package/dist/search/search.d.ts +28 -0
- package/dist/search/search.d.ts.map +1 -0
- package/dist/search/search.js +265 -0
- package/dist/search/search.js.map +1 -0
- package/dist/search/source.d.ts +70 -0
- package/dist/search/source.d.ts.map +1 -0
- package/dist/search/source.js +2 -0
- package/dist/search/source.js.map +1 -0
- package/dist/search/text.d.ts +49 -0
- package/dist/search/text.d.ts.map +1 -0
- package/dist/search/text.js +165 -0
- package/dist/search/text.js.map +1 -0
- package/dist/search-index.d.ts +9 -0
- package/dist/search-index.d.ts.map +1 -0
- package/dist/search-index.js +9 -0
- package/dist/search-index.js.map +1 -0
- package/dist/sha256.d.ts.map +1 -1
- package/dist/sha256.js +3 -2
- package/dist/sha256.js.map +1 -1
- package/dist/site-capabilities.d.ts +345 -0
- package/dist/site-capabilities.d.ts.map +1 -0
- package/dist/site-capabilities.js +724 -0
- package/dist/site-capabilities.js.map +1 -0
- package/dist/site-manifest.d.ts +51 -0
- package/dist/site-manifest.d.ts.map +1 -0
- package/dist/site-manifest.js +115 -0
- package/dist/site-manifest.js.map +1 -0
- package/dist/skip-reasons.d.ts +12 -0
- package/dist/skip-reasons.d.ts.map +1 -0
- package/dist/skip-reasons.js +15 -0
- package/dist/skip-reasons.js.map +1 -0
- package/dist/source-engine/driver.d.ts +40 -0
- package/dist/source-engine/driver.d.ts.map +1 -0
- package/dist/source-engine/driver.js +513 -0
- package/dist/source-engine/driver.js.map +1 -0
- package/dist/source-engine/evidence.d.ts +39 -0
- package/dist/source-engine/evidence.d.ts.map +1 -0
- package/dist/source-engine/evidence.js +54 -0
- package/dist/source-engine/evidence.js.map +1 -0
- package/dist/source-engine/guard.d.ts +87 -0
- package/dist/source-engine/guard.d.ts.map +1 -0
- package/dist/source-engine/guard.js +427 -0
- package/dist/source-engine/guard.js.map +1 -0
- package/dist/source-engine/index.d.ts +35 -0
- package/dist/source-engine/index.d.ts.map +1 -0
- package/dist/source-engine/index.js +27 -0
- package/dist/source-engine/index.js.map +1 -0
- package/dist/source-engine/machine-state.d.ts +87 -0
- package/dist/source-engine/machine-state.d.ts.map +1 -0
- package/dist/source-engine/machine-state.js +94 -0
- package/dist/source-engine/machine-state.js.map +1 -0
- package/dist/source-engine/observe.d.ts +10 -0
- package/dist/source-engine/observe.d.ts.map +1 -0
- package/dist/source-engine/observe.js +276 -0
- package/dist/source-engine/observe.js.map +1 -0
- package/dist/source-engine/overlay.d.ts +50 -0
- package/dist/source-engine/overlay.d.ts.map +1 -0
- package/dist/source-engine/overlay.js +114 -0
- package/dist/source-engine/overlay.js.map +1 -0
- package/dist/source-engine/robots.d.ts +53 -0
- package/dist/source-engine/robots.d.ts.map +1 -0
- package/dist/source-engine/robots.js +158 -0
- package/dist/source-engine/robots.js.map +1 -0
- package/dist/source-engine/snapshot.d.ts +104 -0
- package/dist/source-engine/snapshot.d.ts.map +1 -0
- package/dist/source-engine/snapshot.js +240 -0
- package/dist/source-engine/snapshot.js.map +1 -0
- package/dist/source-engine/target-consumer.d.ts +12 -0
- package/dist/source-engine/target-consumer.d.ts.map +1 -0
- package/dist/source-engine/target-consumer.js +15 -0
- package/dist/source-engine/target-consumer.js.map +1 -0
- package/dist/source-engine/target-descriptor.d.ts +3 -0
- package/dist/source-engine/target-descriptor.d.ts.map +1 -0
- package/dist/source-engine/target-descriptor.js +26 -0
- package/dist/source-engine/target-descriptor.js.map +1 -0
- package/dist/source-engine/target.d.ts +82 -0
- package/dist/source-engine/target.d.ts.map +1 -0
- package/dist/source-engine/target.js +213 -0
- package/dist/source-engine/target.js.map +1 -0
- package/dist/source-engine/types.d.ts +296 -0
- package/dist/source-engine/types.d.ts.map +1 -0
- package/dist/source-engine/types.js +2 -0
- package/dist/source-engine/types.js.map +1 -0
- package/dist/source-harness/conformance.d.ts +16 -0
- package/dist/source-harness/conformance.d.ts.map +1 -0
- package/dist/source-harness/conformance.js +266 -0
- package/dist/source-harness/conformance.js.map +1 -0
- package/dist/source-harness/fixture.d.ts +97 -0
- package/dist/source-harness/fixture.d.ts.map +1 -0
- package/dist/source-harness/fixture.js +276 -0
- package/dist/source-harness/fixture.js.map +1 -0
- package/dist/source-harness/index.d.ts +22 -0
- package/dist/source-harness/index.d.ts.map +1 -0
- package/dist/source-harness/index.js +19 -0
- package/dist/source-harness/index.js.map +1 -0
- package/dist/source-harness/peer.d.ts +74 -0
- package/dist/source-harness/peer.d.ts.map +1 -0
- package/dist/source-harness/peer.js +106 -0
- package/dist/source-harness/peer.js.map +1 -0
- package/dist/source-profiles/index.d.ts +31 -0
- package/dist/source-profiles/index.d.ts.map +1 -0
- package/dist/source-profiles/index.js +206 -0
- package/dist/source-profiles/index.js.map +1 -0
- package/dist/source-profiles/link-header.d.ts +6 -0
- package/dist/source-profiles/link-header.d.ts.map +1 -0
- package/dist/source-profiles/link-header.js +131 -0
- package/dist/source-profiles/link-header.js.map +1 -0
- package/dist/storage-harness/contract.d.ts +109 -0
- package/dist/storage-harness/contract.d.ts.map +1 -0
- package/dist/storage-harness/contract.js +853 -0
- package/dist/storage-harness/contract.js.map +1 -0
- package/dist/storage-harness/index.d.ts +39 -0
- package/dist/storage-harness/index.d.ts.map +1 -0
- package/dist/storage-harness/index.js +55 -0
- package/dist/storage-harness/index.js.map +1 -0
- package/dist/storage.d.ts +10 -2
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +10 -2
- package/dist/storage.js.map +1 -1
- package/dist/string-identity-agreement.d.ts +35 -0
- package/dist/string-identity-agreement.d.ts.map +1 -0
- package/dist/string-identity-agreement.js +78 -0
- package/dist/string-identity-agreement.js.map +1 -0
- package/dist/system-documents.d.ts +82 -0
- package/dist/system-documents.d.ts.map +1 -0
- package/dist/system-documents.js +127 -0
- package/dist/system-documents.js.map +1 -0
- package/dist/types.d.ts +45 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -10
- package/dist/types.js.map +1 -1
- package/dist/uncertain-write.d.ts +119 -6
- package/dist/uncertain-write.d.ts.map +1 -1
- package/dist/uncertain-write.js +67 -32
- package/dist/uncertain-write.js.map +1 -1
- package/dist/validation.d.ts +5 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/verification.d.ts +22 -10
- package/dist/verification.d.ts.map +1 -1
- package/dist/verification.js +87 -39
- package/dist/verification.js.map +1 -1
- package/dist/view-launch-contract.d.ts +14 -0
- package/dist/view-launch-contract.d.ts.map +1 -0
- package/dist/view-launch-contract.js +23 -0
- package/dist/view-launch-contract.js.map +1 -0
- package/dist/write-identity.d.ts +5 -0
- package/dist/write-identity.d.ts.map +1 -0
- package/dist/write-identity.js +9 -0
- package/dist/write-identity.js.map +1 -0
- package/package.json +188 -10
|
@@ -0,0 +1,1055 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The local search index: a `SearchSource` whose index lives in one SQLite file outside the bundle,
|
|
3
|
+
* through Node's built-in `node:sqlite`. It stores what `searchRowText` derives from each document
|
|
4
|
+
* (per-field token texts in a contentless FTS5 table, plus the fields ranking and facets read) and
|
|
5
|
+
* never the bodies. Core's engine still ranks, pages and facets; this source answers `evidence()`
|
|
6
|
+
* and `text()`, so on the same corpus it answers what `searchSourceFromBackend` answers.
|
|
7
|
+
*
|
|
8
|
+
* Every `evidence()` call first brings the index up to date: the bundle is listed, each file's
|
|
9
|
+
* content stamp is compared with the one recorded, and only files whose stamp moved, was never
|
|
10
|
+
* trusted, or was recorded before it settled are read again. A read whose version is unchanged
|
|
11
|
+
* only records the new stamp. The index holds no corpus-size limit; `maxTermsPerDocument` still
|
|
12
|
+
* skips and counts an over-long document.
|
|
13
|
+
*
|
|
14
|
+
* The same file keeps the bundle's link facts, refreshed by the same pass: a document read again
|
|
15
|
+
* has its links derived again, in the same write transaction as its search row, and `edgeSource()`
|
|
16
|
+
* answers Core's `EdgeSource` with indexed queries over them, as `edgeSourceFromBackend` answers on
|
|
17
|
+
* the same folder.
|
|
18
|
+
*
|
|
19
|
+
* The file is derived state: a missing, corrupt, foreign, older-schema or other-text-version file is
|
|
20
|
+
* rebuilt. Several processes may share it: SQLite's WAL journal and a busy timeout serialize the
|
|
21
|
+
* short write transactions, and each search reads one consistent snapshot.
|
|
22
|
+
*/
|
|
23
|
+
import { mkdir, open as openFile, realpath, unlink } from "node:fs/promises";
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
import { FilesystemBackend, filesystemDocumentStamp } from "./backend.js";
|
|
26
|
+
import { isConventionRecord } from "./convention-record.js";
|
|
27
|
+
import { readManyExisting } from "./document-scan.js";
|
|
28
|
+
import { assertEdgeReadBounds } from "./edges/read-bounds.js";
|
|
29
|
+
import { assertWalkBounds } from "./edges/walk.js";
|
|
30
|
+
import { deriveRelationshipSource, readBundleOkfVersion } from "./engine.js";
|
|
31
|
+
import { InvalidInputError } from "./errors.js";
|
|
32
|
+
import { headsDigest } from "./heads-digest.js";
|
|
33
|
+
import { sha256HexOfUtf8 } from "./sha256.js";
|
|
34
|
+
import { SEARCH_LIMITS, SEARCH_MATCH_FIELDS, SIGNAL_INTERVAL, documentDescription, documentTags, documentTitle, documentType, } from "./search/contract.js";
|
|
35
|
+
import { stopIfAsked } from "./search/errors.js";
|
|
36
|
+
import { canonicalJson, codeUnitCompare } from "./search/identity.js";
|
|
37
|
+
import { searchRowText, textVersion } from "./search/row-text.js";
|
|
38
|
+
import { RELATIONSHIP_PROJECTION_VERSIONS, relationshipProjectionForEdition } from "./relationships.js";
|
|
39
|
+
/** Bumped whenever the tables below change shape; an index of another schema is rebuilt. 2: the
|
|
40
|
+
* link facts (`edges`, and the node columns of `docs`). */
|
|
41
|
+
const SCHEMA_VERSION = "2";
|
|
42
|
+
/** The link projections the `edges` rows were derived under; another set rebuilds the file. */
|
|
43
|
+
const LINKS_VERSION = RELATIONSHIP_PROJECTION_VERSIONS.join(" ");
|
|
44
|
+
/**
|
|
45
|
+
* Names what an index file was built by: this file's schema and `textVersion()` (the ranking
|
|
46
|
+
* algorithm, the text revision and the runtime's normalizer fingerprint). Two builds with different
|
|
47
|
+
* keys cannot share a file; put the key in the index file name so two tool versions or two Node
|
|
48
|
+
* versions sharing a state folder each keep their own index instead of rebuilding each other's.
|
|
49
|
+
* Sixteen lowercase hex characters. The file still records and checks these inputs itself.
|
|
50
|
+
*/
|
|
51
|
+
export function localSearchIndexFileKey() {
|
|
52
|
+
return sha256HexOfUtf8(`local-search-index\u0000${SCHEMA_VERSION}\u0000${textVersion()}\u0000${LINKS_VERSION}`).slice(0, 16);
|
|
53
|
+
}
|
|
54
|
+
/** Documents read and derived between cancellation checks and memory bounds. */
|
|
55
|
+
const BATCH = 128;
|
|
56
|
+
/** A write transaction's most changes and most token text: each commit flushes and merges FTS5
|
|
57
|
+
* segments, so fewer, larger commits build faster, while a bound keeps the lock and memory short. */
|
|
58
|
+
const WRITE_CHANGES = 2_048;
|
|
59
|
+
const WRITE_TEXT_UNITS = 16 * 1024 * 1024;
|
|
60
|
+
/** Files stamped at once. */
|
|
61
|
+
const STAMP_CONCURRENCY = 64;
|
|
62
|
+
/** How long a search waits for another process's write transaction. */
|
|
63
|
+
const BUSY_TIMEOUT_MS = 10_000;
|
|
64
|
+
const INDEXED = 0;
|
|
65
|
+
/** Over SEARCH_LIMITS.maxTermsPerDocument body terms: counted, not searched. */
|
|
66
|
+
const OVER_TERM_CAP = 1;
|
|
67
|
+
/** Unreadable: reported in `skipped` with its reason, as the in-memory path reports it. */
|
|
68
|
+
const MALFORMED = 2;
|
|
69
|
+
/** The host refused to read it (EACCES, EPERM). Kept only by a link refresh, which skips such a
|
|
70
|
+
* file as Core's link reads do; never trusted, so a search reads it again and fails as before. */
|
|
71
|
+
const DENIED = 3;
|
|
72
|
+
/** The local index cannot be used here. A caller can fall back to the in-memory source. */
|
|
73
|
+
export class LocalSearchIndexUnavailableError extends Error {
|
|
74
|
+
reason;
|
|
75
|
+
constructor(reason, options) {
|
|
76
|
+
super(MESSAGES[reason], options);
|
|
77
|
+
this.name = "LocalSearchIndexUnavailableError";
|
|
78
|
+
this.reason = reason;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const MESSAGES = {
|
|
82
|
+
"sqlite-unavailable": "The local search index needs node:sqlite, which this Node.js does not provide.",
|
|
83
|
+
"fts5-unavailable": "The local search index needs SQLite FTS5 with contentless delete, which this Node.js's SQLite does not provide.",
|
|
84
|
+
"index-inside-bundle": "The local search index must be kept outside the bundle folder.",
|
|
85
|
+
"index-unusable": "The local search index file cannot be created or opened.",
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Opens (creating or rebuilding as needed) the index for one bundle. Throws
|
|
89
|
+
* `LocalSearchIndexUnavailableError` when this host cannot keep one.
|
|
90
|
+
*/
|
|
91
|
+
export function openLocalSearchIndex(options) {
|
|
92
|
+
return openLocalSearchIndexWith(options, {});
|
|
93
|
+
}
|
|
94
|
+
export async function openLocalSearchIndexWith(options, seams) {
|
|
95
|
+
const { backend } = options;
|
|
96
|
+
if (typeof options.root !== "string" || options.root === "")
|
|
97
|
+
throw new TypeError("openLocalSearchIndex needs the bundle root");
|
|
98
|
+
if (typeof options.indexPath !== "string" || options.indexPath === "")
|
|
99
|
+
throw new TypeError("openLocalSearchIndex needs an index path");
|
|
100
|
+
const root = path.resolve(options.root);
|
|
101
|
+
const indexPath = path.resolve(options.indexPath);
|
|
102
|
+
await refuseInsideBundle(root, indexPath);
|
|
103
|
+
let sqlite;
|
|
104
|
+
try {
|
|
105
|
+
sqlite = (await (seams.loadSqlite ?? loadSqlite)());
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
throw new LocalSearchIndexUnavailableError("sqlite-unavailable", { cause: error });
|
|
109
|
+
}
|
|
110
|
+
await prepareIndexFile(indexPath);
|
|
111
|
+
// Only a filesystem backend's files can vouch for themselves; any other backend is read each search.
|
|
112
|
+
const contentStamp = seams.contentStamp ??
|
|
113
|
+
(backend instanceof FilesystemBackend ? (id) => filesystemDocumentStamp(backend, id) : async () => undefined);
|
|
114
|
+
const busyTimeoutMs = seams.busyTimeoutMs ?? BUSY_TIMEOUT_MS;
|
|
115
|
+
let db = await openDatabase(sqlite, indexPath, busyTimeoutMs);
|
|
116
|
+
let closed = false;
|
|
117
|
+
/** Runs `body`; a corrupt or non-database file is deleted and rebuilt once. */
|
|
118
|
+
const recovering = async (body) => {
|
|
119
|
+
try {
|
|
120
|
+
return await body();
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (!isCorruption(error))
|
|
124
|
+
throw error;
|
|
125
|
+
db = await discardAndReopen(sqlite, db, indexPath, busyTimeoutMs);
|
|
126
|
+
return body();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/** A busy, full, read-only or failing index is one typed condition a caller can fall back on. */
|
|
130
|
+
const typed = async (body) => {
|
|
131
|
+
if (closed)
|
|
132
|
+
throw new TypeError("the local search index is closed");
|
|
133
|
+
try {
|
|
134
|
+
return await body();
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (isSqliteError(error))
|
|
138
|
+
throw new LocalSearchIndexUnavailableError("index-unusable", { cause: error });
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const source = {
|
|
143
|
+
async evidence(terms, filters, bounds, stop) {
|
|
144
|
+
if (closed)
|
|
145
|
+
throw new TypeError("the local search index is closed");
|
|
146
|
+
stopIfAsked(stop);
|
|
147
|
+
return typed(() => recovering(async () => {
|
|
148
|
+
await refresh(db, backend, contentStamp, stop, false);
|
|
149
|
+
stopIfAsked(stop);
|
|
150
|
+
return readEvidence(db, terms, filters, bounds, stop);
|
|
151
|
+
}));
|
|
152
|
+
},
|
|
153
|
+
edgeSource(options = {}) {
|
|
154
|
+
let opened;
|
|
155
|
+
const snapshot = () => (opened ??= typed(() => recovering(async () => {
|
|
156
|
+
const listed = await refresh(db, backend, contentStamp, undefined, true);
|
|
157
|
+
return openEdgeSnapshot(db, backend, listed, options.onSkip);
|
|
158
|
+
})));
|
|
159
|
+
return Object.freeze({
|
|
160
|
+
async edges(selection, limit, after) {
|
|
161
|
+
assertEdgeReadBounds(limit, after);
|
|
162
|
+
const state = await snapshot();
|
|
163
|
+
return typed(() => readEdges(db, state, selection, limit, after));
|
|
164
|
+
},
|
|
165
|
+
async heads(ids) {
|
|
166
|
+
const state = await snapshot();
|
|
167
|
+
return typed(() => readHeads(db, state, ids));
|
|
168
|
+
},
|
|
169
|
+
async walk(start, hops, limit) {
|
|
170
|
+
assertWalkBounds(start, hops, limit);
|
|
171
|
+
const state = await snapshot();
|
|
172
|
+
return typed(() => readWalk(db, state, start, hops, limit));
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
async linksOf(documents, okfVersion) {
|
|
177
|
+
const projection = relationshipProjectionForEdition(okfVersion);
|
|
178
|
+
// Rows of exactly these versions were derived from exactly these bytes, so a file that already
|
|
179
|
+
// holds them answers without a refresh; one that does not is brought up to the folder first.
|
|
180
|
+
const read = () => readLinksOf(db, documents, projection);
|
|
181
|
+
return typed(() => recovering(async () => {
|
|
182
|
+
if (ownSchema(readMeta(db))) {
|
|
183
|
+
const held = read();
|
|
184
|
+
if (held !== undefined)
|
|
185
|
+
return held;
|
|
186
|
+
}
|
|
187
|
+
await refresh(db, backend, contentStamp, undefined, true);
|
|
188
|
+
return read();
|
|
189
|
+
}));
|
|
190
|
+
},
|
|
191
|
+
async text(hits) {
|
|
192
|
+
if (closed)
|
|
193
|
+
throw new TypeError("the local search index is closed");
|
|
194
|
+
return readTexts(backend, hits);
|
|
195
|
+
},
|
|
196
|
+
close() {
|
|
197
|
+
if (closed)
|
|
198
|
+
return;
|
|
199
|
+
closed = true;
|
|
200
|
+
db.close();
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
return Object.freeze(source);
|
|
204
|
+
}
|
|
205
|
+
// ── host edges ───────────────────────────────────────────────────────────────
|
|
206
|
+
/**
|
|
207
|
+
* `node:sqlite` with its one-time ExperimentalWarning (Node 22 and 24) left unprinted. Only a
|
|
208
|
+
* warning of that type naming SQLite is dropped, and only while the module loads; every other
|
|
209
|
+
* warning still reaches `process.emitWarning`.
|
|
210
|
+
*/
|
|
211
|
+
async function loadSqlite() {
|
|
212
|
+
const emitWarning = process.emitWarning;
|
|
213
|
+
const quiet = function (warning, ...rest) {
|
|
214
|
+
const type = typeof rest[0] === "string" ? rest[0] : rest[0]?.type;
|
|
215
|
+
const name = typeof warning === "string" ? type : warning.name;
|
|
216
|
+
const message = typeof warning === "string" ? warning : warning.message;
|
|
217
|
+
if (name === "ExperimentalWarning" && /\bSQLite\b/.test(message))
|
|
218
|
+
return;
|
|
219
|
+
return emitWarning.call(this, warning, ...rest);
|
|
220
|
+
};
|
|
221
|
+
process.emitWarning = quiet;
|
|
222
|
+
try {
|
|
223
|
+
return await import("node:sqlite");
|
|
224
|
+
}
|
|
225
|
+
finally {
|
|
226
|
+
if (process.emitWarning === quiet)
|
|
227
|
+
process.emitWarning = emitWarning;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/** The real path of `target`, resolving its longest existing ancestor (the rest may not exist yet). */
|
|
231
|
+
async function realPathOf(target) {
|
|
232
|
+
const pending = [];
|
|
233
|
+
let current = target;
|
|
234
|
+
for (;;) {
|
|
235
|
+
try {
|
|
236
|
+
return path.join(await realpath(current), ...pending.reverse());
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
const parent = path.dirname(current);
|
|
240
|
+
if (parent === current)
|
|
241
|
+
throw error;
|
|
242
|
+
pending.push(path.basename(current));
|
|
243
|
+
current = parent;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async function refuseInsideBundle(root, indexPath) {
|
|
248
|
+
const fold = (value) => (process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value);
|
|
249
|
+
const bundle = fold(await realPathOf(root));
|
|
250
|
+
const index = fold(await realPathOf(indexPath));
|
|
251
|
+
const relative = path.relative(bundle, index);
|
|
252
|
+
if (relative === "" || (relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative)))
|
|
253
|
+
throw new LocalSearchIndexUnavailableError("index-inside-bundle");
|
|
254
|
+
}
|
|
255
|
+
/** Creates the folder (owner only) and an empty owner-only file, so SQLite's journals inherit its mode. */
|
|
256
|
+
async function prepareIndexFile(indexPath) {
|
|
257
|
+
try {
|
|
258
|
+
await mkdir(path.dirname(indexPath), { recursive: true, mode: 0o700 });
|
|
259
|
+
const handle = await openFile(indexPath, "a", 0o600);
|
|
260
|
+
await handle.close();
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
throw new LocalSearchIndexUnavailableError("index-unusable", { cause: error });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async function openDatabase(sqlite, indexPath, busyTimeoutMs) {
|
|
267
|
+
let db;
|
|
268
|
+
try {
|
|
269
|
+
db = new sqlite.DatabaseSync(indexPath);
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
throw new LocalSearchIndexUnavailableError("index-unusable", { cause: error });
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
probeFts5(sqlite);
|
|
276
|
+
db.exec(`PRAGMA busy_timeout = ${busyTimeoutMs}`);
|
|
277
|
+
await useWal(db, busyTimeoutMs);
|
|
278
|
+
db.exec("PRAGMA synchronous = NORMAL");
|
|
279
|
+
return db;
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
if (isCorruption(error))
|
|
283
|
+
return db; // The first search discards and rebuilds it.
|
|
284
|
+
db.close();
|
|
285
|
+
if (error instanceof LocalSearchIndexUnavailableError)
|
|
286
|
+
throw error;
|
|
287
|
+
throw new LocalSearchIndexUnavailableError("index-unusable", { cause: error });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* WAL mode, once per file. The switch needs the file to itself, and SQLite answers it busy without
|
|
292
|
+
* waiting while another connection opens the same new file, so the switch is retried here.
|
|
293
|
+
*/
|
|
294
|
+
async function useWal(db, busyTimeoutMs) {
|
|
295
|
+
const deadline = Date.now() + busyTimeoutMs;
|
|
296
|
+
for (;;) {
|
|
297
|
+
try {
|
|
298
|
+
const { journal_mode: mode } = db.prepare("PRAGMA journal_mode").get();
|
|
299
|
+
if (mode === "wal")
|
|
300
|
+
return;
|
|
301
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
if (!isBusy(error) || Date.now() > deadline)
|
|
305
|
+
throw error;
|
|
306
|
+
await new Promise((resolve) => setTimeout(resolve, 10 + Math.random() * 40));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/** In a private in-memory database, so another process's lock on the index cannot fail it. */
|
|
311
|
+
function probeFts5(sqlite) {
|
|
312
|
+
const probe = new sqlite.DatabaseSync(":memory:");
|
|
313
|
+
try {
|
|
314
|
+
probe.exec("CREATE VIRTUAL TABLE probe USING fts5(a, content='', contentless_delete=1); CREATE VIRTUAL TABLE vocab USING fts5vocab(probe, instance);");
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
throw new LocalSearchIndexUnavailableError("fts5-unavailable", { cause: error });
|
|
318
|
+
}
|
|
319
|
+
finally {
|
|
320
|
+
probe.close();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
// SQLite's own result codes when the error carries them, else its fixed result-code text, so a
|
|
324
|
+
// Node whose `node:sqlite` errors have no `errcode` still classifies them.
|
|
325
|
+
const SQLITE_BUSY = 5;
|
|
326
|
+
const SQLITE_CORRUPT = 11;
|
|
327
|
+
const SQLITE_NOTADB = 26;
|
|
328
|
+
function sqliteCode(error) {
|
|
329
|
+
const code = error?.errcode;
|
|
330
|
+
return typeof code === "number" ? code & 0xff : undefined;
|
|
331
|
+
}
|
|
332
|
+
function sqliteMessage(error) {
|
|
333
|
+
const record = error;
|
|
334
|
+
return `${typeof record?.errstr === "string" ? record.errstr : ""} ${typeof record?.message === "string" ? record.message : ""}`;
|
|
335
|
+
}
|
|
336
|
+
/** An error raised by `node:sqlite` (by its code, or SQLite's result code). */
|
|
337
|
+
function isSqliteError(error) {
|
|
338
|
+
return sqliteCode(error) !== undefined || error?.code === "ERR_SQLITE_ERROR";
|
|
339
|
+
}
|
|
340
|
+
/** SQLITE_CORRUPT or SQLITE_NOTADB: the file is not an index this source can read. */
|
|
341
|
+
function isCorruption(error) {
|
|
342
|
+
const code = sqliteCode(error);
|
|
343
|
+
if (code !== undefined)
|
|
344
|
+
return code === SQLITE_CORRUPT || code === SQLITE_NOTADB;
|
|
345
|
+
return isSqliteError(error) && /database disk image is malformed|file is not a database/.test(sqliteMessage(error));
|
|
346
|
+
}
|
|
347
|
+
function isBusy(error) {
|
|
348
|
+
const code = sqliteCode(error);
|
|
349
|
+
if (code !== undefined)
|
|
350
|
+
return code === SQLITE_BUSY;
|
|
351
|
+
return isSqliteError(error) && /database is locked/.test(sqliteMessage(error));
|
|
352
|
+
}
|
|
353
|
+
async function discardAndReopen(sqlite, db, indexPath, busyTimeoutMs) {
|
|
354
|
+
try {
|
|
355
|
+
db.close();
|
|
356
|
+
}
|
|
357
|
+
catch {
|
|
358
|
+
// Already unusable.
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
for (const file of [indexPath, `${indexPath}-wal`, `${indexPath}-shm`])
|
|
362
|
+
await unlink(file).catch((error) => {
|
|
363
|
+
if (error.code !== "ENOENT")
|
|
364
|
+
throw error;
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
// Windows refuses to delete a file another process holds open.
|
|
369
|
+
throw new LocalSearchIndexUnavailableError("index-unusable", { cause: error });
|
|
370
|
+
}
|
|
371
|
+
await prepareIndexFile(indexPath);
|
|
372
|
+
return openDatabase(sqlite, indexPath, busyTimeoutMs);
|
|
373
|
+
}
|
|
374
|
+
// ── schema ───────────────────────────────────────────────────────────────────
|
|
375
|
+
/** FTS5 columns, in the contract's field order; the vocabulary tables report these names. */
|
|
376
|
+
const FTS_COLUMNS = SEARCH_MATCH_FIELDS;
|
|
377
|
+
/** Drops whatever holds this schema's names in a foreign or older file: tables, views, triggers,
|
|
378
|
+
* indexes, and FTS5 shadow tables (dropped with their table, or alone when orphaned). */
|
|
379
|
+
function dropOwnNames(db) {
|
|
380
|
+
db.exec("DROP TABLE IF EXISTS temp.vocab_instance; DROP TABLE IF EXISTS temp.vocab_row;");
|
|
381
|
+
const objects = db
|
|
382
|
+
.prepare("SELECT type, name FROM main.sqlite_master WHERE name IN ('meta', 'docs', 'fts', 'edges', 'edges_by_target') OR name LIKE 'fts\\_%' ESCAPE '\\'")
|
|
383
|
+
.all();
|
|
384
|
+
const order = ["trigger", "view", "index", "table"];
|
|
385
|
+
objects.sort((a, b) => order.indexOf(a.type) - order.indexOf(b.type) || (a.name === "fts" ? -1 : b.name === "fts" ? 1 : 0));
|
|
386
|
+
for (const { type, name } of objects) {
|
|
387
|
+
const kind = type === "view" ? "VIEW" : type === "trigger" ? "TRIGGER" : type === "index" ? "INDEX" : "TABLE";
|
|
388
|
+
db.exec(`DROP ${kind} IF EXISTS main."${name.replaceAll('"', '""')}"`);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
function createSchema(db, edition) {
|
|
392
|
+
dropOwnNames(db);
|
|
393
|
+
db.exec(`
|
|
394
|
+
CREATE TABLE main.meta (key TEXT PRIMARY KEY, value TEXT NOT NULL) WITHOUT ROWID;
|
|
395
|
+
CREATE TABLE main.docs (
|
|
396
|
+
rowid INTEGER PRIMARY KEY,
|
|
397
|
+
id TEXT NOT NULL UNIQUE,
|
|
398
|
+
version TEXT,
|
|
399
|
+
stamp TEXT,
|
|
400
|
+
settled INTEGER NOT NULL,
|
|
401
|
+
state INTEGER NOT NULL,
|
|
402
|
+
reason TEXT,
|
|
403
|
+
title TEXT,
|
|
404
|
+
type TEXT,
|
|
405
|
+
tags TEXT NOT NULL,
|
|
406
|
+
title_phrase TEXT NOT NULL,
|
|
407
|
+
id_phrase TEXT NOT NULL,
|
|
408
|
+
node INTEGER NOT NULL,
|
|
409
|
+
head_title TEXT,
|
|
410
|
+
head_type TEXT,
|
|
411
|
+
link_error TEXT
|
|
412
|
+
);
|
|
413
|
+
CREATE VIRTUAL TABLE main.fts USING fts5(${FTS_COLUMNS.join(", ")}, tokenize = 'ascii', content = '', contentless_delete = 1, detail = full);
|
|
414
|
+
CREATE TABLE main.edges (
|
|
415
|
+
source TEXT NOT NULL,
|
|
416
|
+
ordinal INTEGER NOT NULL,
|
|
417
|
+
target TEXT NOT NULL,
|
|
418
|
+
text TEXT NOT NULL,
|
|
419
|
+
href TEXT NOT NULL,
|
|
420
|
+
PRIMARY KEY (source, ordinal)
|
|
421
|
+
) WITHOUT ROWID;
|
|
422
|
+
CREATE INDEX main.edges_by_target ON edges (target, source, ordinal);
|
|
423
|
+
`);
|
|
424
|
+
const put = db.prepare("INSERT INTO main.meta (key, value) VALUES (?, ?)");
|
|
425
|
+
put.run("schema", SCHEMA_VERSION);
|
|
426
|
+
put.run("textVersion", textVersion());
|
|
427
|
+
put.run("links", LINKS_VERSION);
|
|
428
|
+
put.run("edition", edition);
|
|
429
|
+
put.run("generation", "0");
|
|
430
|
+
}
|
|
431
|
+
function readMeta(db) {
|
|
432
|
+
try {
|
|
433
|
+
const rows = db.prepare("SELECT key, value FROM main.meta").all();
|
|
434
|
+
return new Map(rows.map((row) => [row.key, row.value]));
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
// A busy or corrupt file is not an answer; any other failure to read meta rows (no table, other
|
|
438
|
+
// columns, a view over something else) means the file is not this schema's index: rebuild it.
|
|
439
|
+
if (!isSqliteError(error) || isCorruption(error) || isBusy(error))
|
|
440
|
+
throw error;
|
|
441
|
+
return undefined;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
/** The file holds this schema's tables, derived by this build. */
|
|
445
|
+
function ownSchema(meta) {
|
|
446
|
+
return (meta !== undefined &&
|
|
447
|
+
meta.get("schema") === SCHEMA_VERSION &&
|
|
448
|
+
meta.get("textVersion") === textVersion() &&
|
|
449
|
+
meta.get("links") === LINKS_VERSION);
|
|
450
|
+
}
|
|
451
|
+
function current(meta, edition) {
|
|
452
|
+
return ownSchema(meta) && meta.get("edition") === edition;
|
|
453
|
+
}
|
|
454
|
+
/** Rebuilds the tables when the file holds another schema, text version or bundle edition. */
|
|
455
|
+
function ensureSchema(db, edition) {
|
|
456
|
+
if (current(readMeta(db), edition))
|
|
457
|
+
return ensureVocabulary(db);
|
|
458
|
+
transaction(db, () => {
|
|
459
|
+
// Another process may have rebuilt it while this one waited for the lock.
|
|
460
|
+
if (!current(readMeta(db), edition))
|
|
461
|
+
createSchema(db, edition);
|
|
462
|
+
});
|
|
463
|
+
ensureVocabulary(db);
|
|
464
|
+
}
|
|
465
|
+
/** Per-connection vocabulary views over the FTS index: per-instance rows and per-term totals.
|
|
466
|
+
* Made again on every refresh, so a table another process rebuilt is never read through a stale view. */
|
|
467
|
+
function ensureVocabulary(db) {
|
|
468
|
+
db.exec(`
|
|
469
|
+
DROP TABLE IF EXISTS temp.vocab_instance;
|
|
470
|
+
DROP TABLE IF EXISTS temp.vocab_row;
|
|
471
|
+
CREATE VIRTUAL TABLE temp.vocab_instance USING fts5vocab(main, fts, instance);
|
|
472
|
+
CREATE VIRTUAL TABLE temp.vocab_row USING fts5vocab(main, fts, row);
|
|
473
|
+
`);
|
|
474
|
+
}
|
|
475
|
+
function transaction(db, body) {
|
|
476
|
+
db.exec("BEGIN IMMEDIATE");
|
|
477
|
+
try {
|
|
478
|
+
body();
|
|
479
|
+
db.exec("COMMIT");
|
|
480
|
+
}
|
|
481
|
+
catch (error) {
|
|
482
|
+
try {
|
|
483
|
+
db.exec("ROLLBACK");
|
|
484
|
+
}
|
|
485
|
+
catch {
|
|
486
|
+
// The failed statement may already have ended the transaction.
|
|
487
|
+
}
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Brings the index up to the bundle: re-reads every file whose stamp cannot vouch for its row, and
|
|
493
|
+
* derives its search row and its links together. `links`: a file the host refuses to read is kept
|
|
494
|
+
* as skipped, as Core's link reads skip it, rather than failing the refresh as a search does.
|
|
495
|
+
*/
|
|
496
|
+
async function refresh(db, backend, contentStamp, stop, links) {
|
|
497
|
+
// The edition decides how every document parses, so a change re-derives every row.
|
|
498
|
+
const okfVersion = await readBundleOkfVersion(backend, { allowMalformedRoot: true });
|
|
499
|
+
const edition = JSON.stringify(okfVersion ?? null);
|
|
500
|
+
const projection = relationshipProjectionForEdition(okfVersion);
|
|
501
|
+
ensureSchema(db, edition);
|
|
502
|
+
const manifest = new Map();
|
|
503
|
+
for (const row of db.prepare("SELECT id, version, stamp, settled, state, reason FROM main.docs").all())
|
|
504
|
+
manifest.set(row.id, row);
|
|
505
|
+
const ids = await backend.list();
|
|
506
|
+
const stale = [];
|
|
507
|
+
for (let start = 0; start < ids.length; start += STAMP_CONCURRENCY) {
|
|
508
|
+
stopIfAsked(stop);
|
|
509
|
+
const batch = ids.slice(start, start + STAMP_CONCURRENCY);
|
|
510
|
+
// Each stamp is taken before its file is read, so a write after it moves the stamp again.
|
|
511
|
+
const stamps = await Promise.all(batch.map((id) => contentStamp(id)));
|
|
512
|
+
for (const [index, id] of batch.entries()) {
|
|
513
|
+
const stamp = stamps[index];
|
|
514
|
+
const row = manifest.get(id);
|
|
515
|
+
if (row !== undefined && stamp !== undefined && row.settled === 1 && row.stamp === stamp.value)
|
|
516
|
+
continue;
|
|
517
|
+
stale.push({ id, stamp });
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
let pending = [];
|
|
521
|
+
let pendingText = 0;
|
|
522
|
+
const flush = () => {
|
|
523
|
+
apply(db, pending, manifest);
|
|
524
|
+
pending = [];
|
|
525
|
+
pendingText = 0;
|
|
526
|
+
};
|
|
527
|
+
const queue = (change) => {
|
|
528
|
+
pending.push(change);
|
|
529
|
+
if (change.kind === "row")
|
|
530
|
+
for (const column of change.columns ?? [])
|
|
531
|
+
pendingText += column.length;
|
|
532
|
+
if (pending.length >= WRITE_CHANGES || pendingText >= WRITE_TEXT_UNITS)
|
|
533
|
+
flush();
|
|
534
|
+
};
|
|
535
|
+
for (let start = 0; start < stale.length; start += BATCH) {
|
|
536
|
+
stopIfAsked(stop);
|
|
537
|
+
const batch = stale.slice(start, start + BATCH);
|
|
538
|
+
const malformed = new Map();
|
|
539
|
+
const denied = new Map();
|
|
540
|
+
const results = await readManyExisting(backend, batch.map((entry) => entry.id), (skip) => void malformed.set(skip.id, skip), undefined, links ? (skip) => void denied.set(skip.id, skip) : undefined);
|
|
541
|
+
let next = 0;
|
|
542
|
+
for (const [position, { id, stamp }] of batch.entries()) {
|
|
543
|
+
if (position % SIGNAL_INTERVAL === 0)
|
|
544
|
+
stopIfAsked(stop);
|
|
545
|
+
const unread = malformed.has(id)
|
|
546
|
+
? [MALFORMED, malformed.get(id).reason, stamp]
|
|
547
|
+
: denied.has(id)
|
|
548
|
+
? [DENIED, denied.get(id).reason, undefined]
|
|
549
|
+
: undefined;
|
|
550
|
+
if (unread !== undefined) {
|
|
551
|
+
const [state, reason, kept] = unread;
|
|
552
|
+
// Unreadable as recorded: nothing to write.
|
|
553
|
+
const row = manifest.get(id);
|
|
554
|
+
const same = row !== undefined && row.state === state && row.reason === reason && row.stamp === (kept?.value ?? null) && row.settled === (kept?.settled ? 1 : 0);
|
|
555
|
+
if (!same)
|
|
556
|
+
queue(unreadRow(id, kept, state, reason));
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
const result = results[next];
|
|
560
|
+
if (result === undefined || result.doc.id !== id) {
|
|
561
|
+
queue({ kind: "delete", id }); // Gone between the listing and the read.
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
next += 1;
|
|
565
|
+
const row = manifest.get(id);
|
|
566
|
+
if (row !== undefined && row.state !== MALFORMED && row.version === result.version) {
|
|
567
|
+
// An unchanged stamp (an untrusted one is always null) needs no write, so a search that
|
|
568
|
+
// finds nothing changed takes no write lock.
|
|
569
|
+
if (row.stamp !== (stamp?.value ?? null) || row.settled !== (stamp?.settled ? 1 : 0))
|
|
570
|
+
queue({ kind: "stamp", id, version: result.version, stamp });
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
queue(derivedRow({ ...result.doc, version: result.version }, stamp, projection));
|
|
574
|
+
}
|
|
575
|
+
if (next !== results.length)
|
|
576
|
+
throw new TypeError("Search backend returned a different document identity.");
|
|
577
|
+
}
|
|
578
|
+
const listed = new Set(ids);
|
|
579
|
+
for (const id of manifest.keys())
|
|
580
|
+
if (!listed.has(id))
|
|
581
|
+
queue({ kind: "delete", id });
|
|
582
|
+
flush();
|
|
583
|
+
return { ids, edition: okfVersion };
|
|
584
|
+
}
|
|
585
|
+
function unreadRow(id, stamp, state, reason) {
|
|
586
|
+
return {
|
|
587
|
+
kind: "row",
|
|
588
|
+
id,
|
|
589
|
+
version: null,
|
|
590
|
+
stamp,
|
|
591
|
+
state,
|
|
592
|
+
reason,
|
|
593
|
+
title: null,
|
|
594
|
+
type: null,
|
|
595
|
+
tags: "[]",
|
|
596
|
+
titlePhrase: "",
|
|
597
|
+
idPhrase: "",
|
|
598
|
+
node: 0,
|
|
599
|
+
headTitle: null,
|
|
600
|
+
headType: null,
|
|
601
|
+
linkError: null,
|
|
602
|
+
links: [],
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
/** A document's links as Core's link reads derive them (`deriveRelationshipSource`): its node
|
|
606
|
+
* status, head and occurrences, or the error that fails a link read. */
|
|
607
|
+
function derivedLinks(document, projection) {
|
|
608
|
+
try {
|
|
609
|
+
const source = deriveRelationshipSource(document, projection);
|
|
610
|
+
const node = projection?.conceptsOnly ? source.concept === true : true;
|
|
611
|
+
return {
|
|
612
|
+
node: node ? 1 : 0,
|
|
613
|
+
headTitle: source.title,
|
|
614
|
+
headType: source.type ?? null,
|
|
615
|
+
linkError: null,
|
|
616
|
+
links: node ? source.links : [],
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
catch (error) {
|
|
620
|
+
// A search still indexes the document; only a link read fails, with Core's own error.
|
|
621
|
+
return { node: 0, headTitle: null, headType: null, linkError: error instanceof Error ? error.message : String(error), links: [] };
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
function derivedRow(document, stamp, projection) {
|
|
625
|
+
const text = searchRowText(document);
|
|
626
|
+
const searched = text.bodyTermCount <= SEARCH_LIMITS.maxTermsPerDocument;
|
|
627
|
+
const byField = {
|
|
628
|
+
title: text.titleTerms,
|
|
629
|
+
type: text.typeTerms,
|
|
630
|
+
tag: text.tagTerms,
|
|
631
|
+
description: text.descriptionTerms,
|
|
632
|
+
id: text.idTerms,
|
|
633
|
+
body: text.bodyTerms,
|
|
634
|
+
};
|
|
635
|
+
return {
|
|
636
|
+
kind: "row",
|
|
637
|
+
id: document.id,
|
|
638
|
+
version: document.version,
|
|
639
|
+
stamp,
|
|
640
|
+
state: searched ? INDEXED : OVER_TERM_CAP,
|
|
641
|
+
reason: null,
|
|
642
|
+
title: documentTitle(document) ?? null,
|
|
643
|
+
type: documentType(document) ?? null,
|
|
644
|
+
tags: JSON.stringify(documentTags(document)),
|
|
645
|
+
titlePhrase: text.titlePhrase,
|
|
646
|
+
idPhrase: text.idPhrase,
|
|
647
|
+
...(searched ? { columns: FTS_COLUMNS.map((field) => byField[field]) } : {}),
|
|
648
|
+
...derivedLinks(document, projection),
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* One write transaction. A stored row is replaced only while it still has the version this refresh
|
|
653
|
+
* found in `manifest`: when another process wrote it in between, that write stands, so a slower
|
|
654
|
+
* process never puts back an older read over a newer one. A file changed again since is read on the
|
|
655
|
+
* next refresh, as its stamp no longer matches.
|
|
656
|
+
*/
|
|
657
|
+
function apply(db, changes, manifest) {
|
|
658
|
+
if (changes.length === 0)
|
|
659
|
+
return;
|
|
660
|
+
const find = db.prepare("SELECT rowid, state, version FROM main.docs WHERE id = ?");
|
|
661
|
+
const stampOnly = db.prepare("UPDATE main.docs SET stamp = ?, settled = ? WHERE id = ? AND version = ? AND state != ?");
|
|
662
|
+
const update = db.prepare("UPDATE main.docs SET version = ?, stamp = ?, settled = ?, state = ?, reason = ?, title = ?, type = ?, tags = ?, title_phrase = ?, id_phrase = ?, node = ?, head_title = ?, head_type = ?, link_error = ? WHERE rowid = ?");
|
|
663
|
+
const insert = db.prepare("INSERT INTO main.docs (id, version, stamp, settled, state, reason, title, type, tags, title_phrase, id_phrase, node, head_title, head_type, link_error) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING rowid");
|
|
664
|
+
const remove = db.prepare("DELETE FROM main.docs WHERE rowid = ?");
|
|
665
|
+
const unindex = db.prepare("DELETE FROM main.fts WHERE rowid = ?");
|
|
666
|
+
const index = db.prepare(`INSERT INTO main.fts (rowid, ${FTS_COLUMNS.join(", ")}) VALUES (?, ${FTS_COLUMNS.map(() => "?").join(", ")})`);
|
|
667
|
+
const dropLinks = db.prepare("DELETE FROM main.edges WHERE source = ?");
|
|
668
|
+
const addLink = db.prepare("INSERT INTO main.edges (source, ordinal, target, text, href) VALUES (?, ?, ?, ?, ?)");
|
|
669
|
+
// A change to any row moves the generation, so an edge source that read before it can tell; a
|
|
670
|
+
// new stamp alone changes no answer.
|
|
671
|
+
const advance = db.prepare("UPDATE main.meta SET value = CAST(CAST(value AS INTEGER) + 1 AS TEXT) WHERE key = 'generation'");
|
|
672
|
+
// A write through FTS5 can report a shadow-table rowid past 2^53 as its last insert rowid, which
|
|
673
|
+
// Node 26 refuses to convert to a number; nothing here reads it.
|
|
674
|
+
for (const statement of [stampOnly, update, insert, remove, unindex, index, dropLinks, addLink, advance])
|
|
675
|
+
statement.setReadBigInts(true);
|
|
676
|
+
transaction(db, () => {
|
|
677
|
+
let changed = false;
|
|
678
|
+
for (const change of changes) {
|
|
679
|
+
const existing = find.get(change.id);
|
|
680
|
+
if (change.kind === "stamp") {
|
|
681
|
+
stampOnly.run(change.stamp?.value ?? null, change.stamp?.settled ? 1 : 0, change.id, change.version, MALFORMED);
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
// Another process wrote this row since the manifest was read: its write stands. A missing row is
|
|
685
|
+
// always written (a file every reader lists must have one, even after another rebuilt the file).
|
|
686
|
+
const seen = manifest.get(change.id);
|
|
687
|
+
if (existing !== undefined && (seen === undefined || existing.version !== seen.version))
|
|
688
|
+
continue;
|
|
689
|
+
changed = true;
|
|
690
|
+
if (existing !== undefined && existing.state === INDEXED)
|
|
691
|
+
unindex.run(existing.rowid);
|
|
692
|
+
// A document's links change with its row, in this transaction.
|
|
693
|
+
dropLinks.run(change.id);
|
|
694
|
+
if (change.kind === "delete") {
|
|
695
|
+
if (existing !== undefined)
|
|
696
|
+
remove.run(existing.rowid);
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
const values = [
|
|
700
|
+
change.version,
|
|
701
|
+
change.stamp?.value ?? null,
|
|
702
|
+
change.stamp?.settled ? 1 : 0,
|
|
703
|
+
change.state,
|
|
704
|
+
change.reason,
|
|
705
|
+
change.title,
|
|
706
|
+
change.type,
|
|
707
|
+
change.tags,
|
|
708
|
+
change.titlePhrase,
|
|
709
|
+
change.idPhrase,
|
|
710
|
+
change.node,
|
|
711
|
+
change.headTitle,
|
|
712
|
+
change.headType,
|
|
713
|
+
change.linkError,
|
|
714
|
+
];
|
|
715
|
+
let rowid;
|
|
716
|
+
if (existing !== undefined) {
|
|
717
|
+
update.run(...values, existing.rowid);
|
|
718
|
+
rowid = existing.rowid;
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
rowid = Number(insert.get(change.id, ...values).rowid);
|
|
722
|
+
}
|
|
723
|
+
if (change.columns !== undefined)
|
|
724
|
+
index.run(rowid, ...change.columns);
|
|
725
|
+
for (const [ordinal, occurrence] of change.links.entries())
|
|
726
|
+
addLink.run(change.id, ordinal, occurrence.to, occurrence.text, occurrence.href);
|
|
727
|
+
}
|
|
728
|
+
if (changed)
|
|
729
|
+
advance.run();
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
/** One read transaction: the corpus identity and sizes, the volume and the evidence agree. */
|
|
733
|
+
function readEvidence(db, terms, filters, bounds, stop) {
|
|
734
|
+
db.exec("BEGIN");
|
|
735
|
+
try {
|
|
736
|
+
const corpus = db.prepare("SELECT id, version, state, reason FROM main.docs").all();
|
|
737
|
+
const heads = [];
|
|
738
|
+
const skipped = [];
|
|
739
|
+
let indexed = 0;
|
|
740
|
+
for (const row of corpus) {
|
|
741
|
+
if (row.state === MALFORMED)
|
|
742
|
+
skipped.push(Object.freeze({ id: row.id, reason: row.reason ?? "" }));
|
|
743
|
+
else
|
|
744
|
+
heads.push({ id: row.id, version: row.version });
|
|
745
|
+
if (row.state === INDEXED)
|
|
746
|
+
indexed += 1;
|
|
747
|
+
}
|
|
748
|
+
skipped.sort((a, b) => codeUnitCompare(a.id, b.id));
|
|
749
|
+
const digest = headsDigest(heads);
|
|
750
|
+
const key = skipped.length === 0 ? digest : sha256HexOfUtf8(canonicalJson({ heads: digest, skipped }));
|
|
751
|
+
const size = Object.freeze({
|
|
752
|
+
documents: corpus.length,
|
|
753
|
+
indexed,
|
|
754
|
+
skipped: corpus.length - indexed,
|
|
755
|
+
reindexPending: 0,
|
|
756
|
+
});
|
|
757
|
+
const answer = (volume, documents) => ({
|
|
758
|
+
key,
|
|
759
|
+
size,
|
|
760
|
+
...(skipped.length === 0 ? {} : { skipped: Object.freeze(skipped) }),
|
|
761
|
+
volume,
|
|
762
|
+
documents,
|
|
763
|
+
});
|
|
764
|
+
if (terms.length === 0)
|
|
765
|
+
return answer(0, []);
|
|
766
|
+
const json = JSON.stringify(terms);
|
|
767
|
+
const volume = Number(db.prepare("SELECT coalesce(sum(cnt), 0) AS volume FROM temp.vocab_row WHERE term IN (SELECT value FROM json_each(?))").get(json).volume);
|
|
768
|
+
// Over the bound nothing is walked, as the engine refuses the request.
|
|
769
|
+
if (volume > bounds.maxInstances)
|
|
770
|
+
return answer(volume, []);
|
|
771
|
+
const instances = db
|
|
772
|
+
.prepare("SELECT term, doc, col, count(*) AS n FROM temp.vocab_instance WHERE term IN (SELECT value FROM json_each(?)) GROUP BY term, doc, col")
|
|
773
|
+
.all(json);
|
|
774
|
+
const held = new Map();
|
|
775
|
+
for (const { term, doc, col, n } of instances) {
|
|
776
|
+
let perDoc = held.get(doc);
|
|
777
|
+
if (perDoc === undefined)
|
|
778
|
+
held.set(doc, (perDoc = new Map()));
|
|
779
|
+
let perTerm = perDoc.get(term);
|
|
780
|
+
if (perTerm === undefined)
|
|
781
|
+
perDoc.set(term, (perTerm = { fields: new Set(), body: 0 }));
|
|
782
|
+
perTerm.fields.add(col);
|
|
783
|
+
if (col === "body")
|
|
784
|
+
perTerm.body = n;
|
|
785
|
+
}
|
|
786
|
+
const rows = db
|
|
787
|
+
.prepare("SELECT rowid, id, version, title, type, tags, title_phrase, id_phrase FROM main.docs WHERE rowid IN (SELECT value FROM json_each(?))")
|
|
788
|
+
.all(JSON.stringify([...held.keys()]));
|
|
789
|
+
const documents = [];
|
|
790
|
+
for (const [position, row] of rows.entries()) {
|
|
791
|
+
if (position % SIGNAL_INTERVAL === 0)
|
|
792
|
+
stopIfAsked(stop);
|
|
793
|
+
const type = row.type ?? undefined;
|
|
794
|
+
const tags = Object.freeze(JSON.parse(row.tags));
|
|
795
|
+
if (filters.type !== undefined && type !== filters.type)
|
|
796
|
+
continue;
|
|
797
|
+
if (filters.tag !== undefined && !tags.includes(filters.tag))
|
|
798
|
+
continue;
|
|
799
|
+
if (filters.prefix !== undefined && !row.id.startsWith(filters.prefix))
|
|
800
|
+
continue;
|
|
801
|
+
if (filters.excludeConventions && isConventionRecord(row.id, type))
|
|
802
|
+
continue;
|
|
803
|
+
const perDoc = held.get(row.rowid);
|
|
804
|
+
const termEvidence = new Map();
|
|
805
|
+
for (const term of terms) {
|
|
806
|
+
const entry = perDoc.get(term);
|
|
807
|
+
if (entry === undefined)
|
|
808
|
+
continue;
|
|
809
|
+
termEvidence.set(term, {
|
|
810
|
+
fields: Object.freeze(SEARCH_MATCH_FIELDS.filter((field) => entry.fields.has(field))),
|
|
811
|
+
bodyOccurrences: entry.body,
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
documents.push({
|
|
815
|
+
id: row.id,
|
|
816
|
+
version: row.version,
|
|
817
|
+
...(row.title === null ? {} : { title: row.title }),
|
|
818
|
+
...(type === undefined ? {} : { type }),
|
|
819
|
+
tags,
|
|
820
|
+
titlePhrase: row.title_phrase,
|
|
821
|
+
idPhrase: row.id_phrase,
|
|
822
|
+
terms: termEvidence,
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
return answer(volume, documents);
|
|
826
|
+
}
|
|
827
|
+
finally {
|
|
828
|
+
db.exec("COMMIT");
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
/** Inside one read transaction; `pending` once another refresh has changed the file since `state`. */
|
|
832
|
+
function readSnapshot(db, state, body) {
|
|
833
|
+
db.exec("BEGIN");
|
|
834
|
+
try {
|
|
835
|
+
if (generationOf(db) !== state.generation)
|
|
836
|
+
return { status: "pending" };
|
|
837
|
+
return body();
|
|
838
|
+
}
|
|
839
|
+
finally {
|
|
840
|
+
db.exec("COMMIT");
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
function generationOf(db) {
|
|
844
|
+
return db.prepare("SELECT value FROM main.meta WHERE key = 'generation'").get().value;
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Pins an edge source to the file as its own refresh left it, and reports the unreadable documents
|
|
848
|
+
* in listing order. As Core's in-memory link read, it fails on the first document (in listing
|
|
849
|
+
* order) whose links cannot be derived, or that cannot be read when nobody takes `onSkip`: that
|
|
850
|
+
* document is read again here, so the failure is Core's own error.
|
|
851
|
+
*/
|
|
852
|
+
async function openEdgeSnapshot(db, backend, listed, onSkip) {
|
|
853
|
+
db.exec("BEGIN");
|
|
854
|
+
let generation;
|
|
855
|
+
let unread;
|
|
856
|
+
let failed;
|
|
857
|
+
try {
|
|
858
|
+
generation = generationOf(db);
|
|
859
|
+
const rows = db
|
|
860
|
+
.prepare("SELECT id, state, reason, link_error FROM main.docs WHERE state IN (?, ?) OR link_error IS NOT NULL")
|
|
861
|
+
.all(MALFORMED, DENIED);
|
|
862
|
+
unread = new Map(rows.filter((row) => row.link_error === null).map((row) => [row.id, row.reason ?? ""]));
|
|
863
|
+
failed = new Map(rows.filter((row) => row.link_error !== null).map((row) => [row.id, row.link_error]));
|
|
864
|
+
}
|
|
865
|
+
finally {
|
|
866
|
+
db.exec("COMMIT");
|
|
867
|
+
}
|
|
868
|
+
const projection = relationshipProjectionForEdition(listed.edition);
|
|
869
|
+
for (const id of listed.ids) {
|
|
870
|
+
const message = failed.get(id);
|
|
871
|
+
if (message === undefined && (onSkip !== undefined || !unread.has(id)))
|
|
872
|
+
continue;
|
|
873
|
+
const { doc } = await backend.read(id);
|
|
874
|
+
if (message !== undefined)
|
|
875
|
+
deriveRelationshipSource(doc, projection);
|
|
876
|
+
// Readable and derivable now: it changed after the refresh, which a later read picks up.
|
|
877
|
+
throw new InvalidInputError(message ?? `'${id}' changed while its links were read. Read again.`);
|
|
878
|
+
}
|
|
879
|
+
if (onSkip !== undefined)
|
|
880
|
+
for (const id of listed.ids)
|
|
881
|
+
if (unread.has(id))
|
|
882
|
+
onSkip({ id, reason: unread.get(id) });
|
|
883
|
+
return { generation, conceptsOnly: projection?.conceptsOnly === true };
|
|
884
|
+
}
|
|
885
|
+
/** The least string above every string that starts with `prefix`, in code point (UTF-8 byte) order;
|
|
886
|
+
* undefined when there is none. */
|
|
887
|
+
function prefixEnd(prefix) {
|
|
888
|
+
const points = [...prefix];
|
|
889
|
+
while (points.length > 0) {
|
|
890
|
+
const last = points.pop().codePointAt(0);
|
|
891
|
+
if (last === 0x10ffff)
|
|
892
|
+
continue;
|
|
893
|
+
return points.join("") + String.fromCodePoint(last === 0xd7ff ? 0xe000 : last + 1);
|
|
894
|
+
}
|
|
895
|
+
return undefined;
|
|
896
|
+
}
|
|
897
|
+
/** A facet as SQL over `column`: exact ids, and each prefix as a range seek under BINARY collation
|
|
898
|
+
* (exact bytes: no case folding, no wildcards). An empty facet matches nothing. */
|
|
899
|
+
function facetSql(column, facet, params) {
|
|
900
|
+
const terms = [];
|
|
901
|
+
if (facet.ids.length > 0) {
|
|
902
|
+
terms.push(`e.${column} IN (SELECT value FROM json_each(?))`);
|
|
903
|
+
params.push(JSON.stringify(facet.ids));
|
|
904
|
+
}
|
|
905
|
+
for (const prefix of facet.prefixes) {
|
|
906
|
+
const end = prefixEnd(prefix);
|
|
907
|
+
terms.push(end === undefined ? `e.${column} >= ?` : `(e.${column} >= ? AND e.${column} < ?)`);
|
|
908
|
+
params.push(prefix, ...(end === undefined ? [] : [end]));
|
|
909
|
+
}
|
|
910
|
+
return terms.length === 0 ? "0" : `(${terms.join(" OR ")})`;
|
|
911
|
+
}
|
|
912
|
+
function readEdges(db, state, selection, limit, after) {
|
|
913
|
+
const params = [];
|
|
914
|
+
const where = [];
|
|
915
|
+
// Ids compare as BINARY, UTF-8 bytes: code point order, the interface's.
|
|
916
|
+
if (after !== undefined) {
|
|
917
|
+
where.push("(e.source, e.ordinal) > (?, ?)");
|
|
918
|
+
params.push(after.from, after.ordinal);
|
|
919
|
+
}
|
|
920
|
+
if (selection.from !== undefined)
|
|
921
|
+
where.push(facetSql("source", selection.from, params));
|
|
922
|
+
if (selection.to !== undefined)
|
|
923
|
+
where.push(facetSql("target", selection.to, params));
|
|
924
|
+
if (selection.text !== undefined) {
|
|
925
|
+
where.push("e.text = ?");
|
|
926
|
+
params.push(selection.text);
|
|
927
|
+
}
|
|
928
|
+
// In OKF 0.3 a link counts only between nodes; only a node's links are stored.
|
|
929
|
+
if (state.conceptsOnly)
|
|
930
|
+
where.push("EXISTS (SELECT 1 FROM main.docs n WHERE n.id = e.target AND n.node = 1)");
|
|
931
|
+
const bounded = limit !== undefined && limit !== Infinity;
|
|
932
|
+
const sql = `SELECT e.source AS "from", e.target AS "to", e.text AS text, e.href AS href, e.ordinal AS ordinal FROM main.edges e` +
|
|
933
|
+
(where.length === 0 ? "" : ` WHERE ${where.join(" AND ")}`) +
|
|
934
|
+
` ORDER BY e.source, e.ordinal${bounded ? ` LIMIT ${limit + 1}` : ""}`;
|
|
935
|
+
return readSnapshot(db, state, () => {
|
|
936
|
+
const rows = db.prepare(sql).all(...params);
|
|
937
|
+
const more = bounded && rows.length > limit;
|
|
938
|
+
const kept = more ? rows.slice(0, limit) : rows;
|
|
939
|
+
const edges = kept.map(({ from, to, text, href }) => ({ from, to, text, href }));
|
|
940
|
+
const last = kept.at(-1);
|
|
941
|
+
return more && last !== undefined
|
|
942
|
+
? { status: "ready", edges, more, next: { from: last.from, ordinal: Number(last.ordinal) } }
|
|
943
|
+
: { status: "ready", edges, more };
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
/** In one read transaction: every link, when the file holds exactly `documents`, all derived under
|
|
947
|
+
* `projection`'s link rule. */
|
|
948
|
+
function readLinksOf(db, documents, projection) {
|
|
949
|
+
db.exec("BEGIN");
|
|
950
|
+
try {
|
|
951
|
+
// Derived under another edition's link rule: not these documents' links.
|
|
952
|
+
const edition = readMeta(db)?.get("edition");
|
|
953
|
+
if (edition === undefined || relationshipProjectionForEdition(JSON.parse(edition) ?? undefined) !== projection)
|
|
954
|
+
return undefined;
|
|
955
|
+
const conceptsOnly = projection?.conceptsOnly === true;
|
|
956
|
+
const rows = db.prepare("SELECT id, version, link_error FROM main.docs").all();
|
|
957
|
+
if (rows.length !== documents.length)
|
|
958
|
+
return undefined;
|
|
959
|
+
const held = new Map(rows.map((row) => [row.id, row]));
|
|
960
|
+
for (const { id, version } of documents) {
|
|
961
|
+
const row = held.get(id);
|
|
962
|
+
if (row === undefined || row.version !== version || row.link_error !== null)
|
|
963
|
+
return undefined;
|
|
964
|
+
}
|
|
965
|
+
const node = conceptsOnly ? " WHERE EXISTS (SELECT 1 FROM main.docs n WHERE n.id = e.target AND n.node = 1)" : "";
|
|
966
|
+
const links = db
|
|
967
|
+
.prepare(`SELECT e.source AS "from", e.target AS "to", e.text AS text, e.href AS href FROM main.edges e${node} ORDER BY e.source, e.ordinal`)
|
|
968
|
+
.all();
|
|
969
|
+
return links.map(({ from, to, text, href }) => ({ from, to, text, href }));
|
|
970
|
+
}
|
|
971
|
+
finally {
|
|
972
|
+
db.exec("COMMIT");
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
function readHeads(db, state, ids) {
|
|
976
|
+
return readSnapshot(db, state, () => {
|
|
977
|
+
const rows = db
|
|
978
|
+
.prepare("SELECT id, head_title, head_type FROM main.docs WHERE node = 1 AND id IN (SELECT value FROM json_each(?))")
|
|
979
|
+
.all(JSON.stringify(ids));
|
|
980
|
+
const found = new Map(rows.map((row) => [row.id, row]));
|
|
981
|
+
const heads = new Map();
|
|
982
|
+
for (const id of ids) {
|
|
983
|
+
const row = found.get(id);
|
|
984
|
+
if (row !== undefined)
|
|
985
|
+
heads.set(id, Object.freeze({ id, title: row.head_title, type: row.head_type }));
|
|
986
|
+
}
|
|
987
|
+
return { status: "ready", heads };
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* One hop of a walk: every node not in `reached` that one link joins to a node of `frontier` (ranked
|
|
992
|
+
* by its position there), each with its least candidate link (rank, outgoing first, written
|
|
993
|
+
* position), ordered by rank, direction and id, at most `bound` of them. A link counts only between
|
|
994
|
+
* nodes: the frontier holds nodes, and the joined end must be one.
|
|
995
|
+
*/
|
|
996
|
+
const WALK_HOP_SQL = `
|
|
997
|
+
WITH f AS (SELECT key AS rank, value AS id FROM json_each(?)),
|
|
998
|
+
c AS (
|
|
999
|
+
SELECT f.rank AS rank, 0 AS dir, e.target AS id, e.source AS "from", e.target AS "to", e.text AS text, e.href AS href, e.ordinal AS ordinal
|
|
1000
|
+
FROM f JOIN main.edges e ON e.source = f.id
|
|
1001
|
+
UNION ALL
|
|
1002
|
+
SELECT f.rank, 1, e.source, e.source, e.target, e.text, e.href, e.ordinal
|
|
1003
|
+
FROM f JOIN main.edges e INDEXED BY edges_by_target ON e.target = f.id
|
|
1004
|
+
),
|
|
1005
|
+
k AS (
|
|
1006
|
+
SELECT c.*, ROW_NUMBER() OVER (PARTITION BY c.id ORDER BY c.rank, c.dir, c.ordinal) AS n
|
|
1007
|
+
FROM c WHERE c.id NOT IN (SELECT value FROM json_each(?))
|
|
1008
|
+
)
|
|
1009
|
+
SELECT k.id AS id, k.dir AS dir, k."from" AS "from", k."to" AS "to", k.text AS text, k.href AS href,
|
|
1010
|
+
d.head_title AS title, d.head_type AS type
|
|
1011
|
+
FROM k JOIN main.docs d ON d.id = k.id AND d.node = 1
|
|
1012
|
+
WHERE k.n = 1
|
|
1013
|
+
ORDER BY k.rank, k.dir, k.id
|
|
1014
|
+
LIMIT ?`;
|
|
1015
|
+
/** A walk (`EdgeSource.walk`) in one read transaction, one query per hop. */
|
|
1016
|
+
function readWalk(db, state, start, hops, limit) {
|
|
1017
|
+
return readSnapshot(db, state, () => {
|
|
1018
|
+
const nodes = new Set(db.prepare("SELECT id FROM main.docs WHERE node = 1 AND id IN (SELECT value FROM json_each(?))").all(JSON.stringify(start)).map(({ id }) => id));
|
|
1019
|
+
const reached = [...new Set(start.filter((id) => nodes.has(id)))];
|
|
1020
|
+
let frontier = [...reached];
|
|
1021
|
+
const steps = [];
|
|
1022
|
+
let more = false;
|
|
1023
|
+
const hop = db.prepare(WALK_HOP_SQL);
|
|
1024
|
+
for (let h = 1; h <= hops && frontier.length > 0 && !more; h++) {
|
|
1025
|
+
const room = limit - steps.length;
|
|
1026
|
+
const rows = hop.all(JSON.stringify(frontier), JSON.stringify(reached), room + 1);
|
|
1027
|
+
if (rows.length > room) {
|
|
1028
|
+
more = true;
|
|
1029
|
+
rows.length = room;
|
|
1030
|
+
}
|
|
1031
|
+
frontier = [];
|
|
1032
|
+
for (const { id, dir, from, to, text, href, title, type } of rows) {
|
|
1033
|
+
steps.push(Object.freeze({ id, title, type, hop: h, direction: dir === 0 ? "outgoing" : "incoming", link: { from, to, text, href } }));
|
|
1034
|
+
reached.push(id);
|
|
1035
|
+
frontier.push(id);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
return { status: "ready", steps, more };
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
/** Description and body of the hits, read again; a file changed since its evidence gives none. */
|
|
1042
|
+
async function readTexts(backend, hits) {
|
|
1043
|
+
const texts = new Map();
|
|
1044
|
+
const wanted = new Map(hits.map((hit) => [hit.id, hit.version]));
|
|
1045
|
+
if (wanted.size === 0)
|
|
1046
|
+
return texts;
|
|
1047
|
+
const results = await readManyExisting(backend, [...wanted.keys()], () => { });
|
|
1048
|
+
for (const { doc, version } of results) {
|
|
1049
|
+
if (wanted.get(doc.id) !== version)
|
|
1050
|
+
continue;
|
|
1051
|
+
texts.set(doc.id, { description: documentDescription({ ...doc, version }) ?? "", body: doc.body });
|
|
1052
|
+
}
|
|
1053
|
+
return texts;
|
|
1054
|
+
}
|
|
1055
|
+
//# sourceMappingURL=local-search-index.js.map
|