@forwardimpact/libindex
Advanced tools
+3
-2
| { | ||
| "name": "@forwardimpact/libindex", | ||
| "version": "0.1.40", | ||
| "version": "0.1.41", | ||
| "description": "JSONL-backed indexes with filtering and buffered writes — fast context lookup without an external search engine.", | ||
@@ -42,3 +42,4 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@forwardimpact/libtype": "^0.1.63" | ||
| "@forwardimpact/libtype": "^0.1.63", | ||
| "@forwardimpact/libutil": "^0.1.84" | ||
| }, | ||
@@ -45,0 +46,0 @@ "devDependencies": { |
+16
-3
| import { IndexBase } from "./base.js"; | ||
| import { createDefaultRuntime } from "@forwardimpact/libutil/runtime"; | ||
@@ -13,2 +14,3 @@ /** | ||
| #maxBufferSize; | ||
| #clock; | ||
@@ -22,7 +24,15 @@ /** | ||
| * @param {number} [config.max_buffer_size] - Max items before forced flush (default: 1000) | ||
| * @param {object} [deps] - Injected collaborators | ||
| * @param {import("@forwardimpact/libutil/runtime").Runtime} [deps.runtime] | ||
| */ | ||
| constructor(storage, indexKey, config = {}) { | ||
| constructor( | ||
| storage, | ||
| indexKey, | ||
| config = {}, | ||
| { runtime = createDefaultRuntime() } = {}, | ||
| ) { | ||
| super(storage, indexKey); | ||
| this.#flushInterval = config.flush_interval || 5000; | ||
| this.#maxBufferSize = config.max_buffer_size || 1000; | ||
| this.#clock = runtime.clock; | ||
| } | ||
@@ -52,3 +62,6 @@ | ||
| if (!this.#flushTimer) { | ||
| this.#flushTimer = setTimeout(() => this.flush(), this.#flushInterval); | ||
| this.#flushTimer = this.#clock.setTimeout( | ||
| () => this.flush(), | ||
| this.#flushInterval, | ||
| ); | ||
| } | ||
@@ -63,3 +76,3 @@ } | ||
| if (this.#flushTimer) { | ||
| clearTimeout(this.#flushTimer); | ||
| this.#clock.clearTimeout(this.#flushTimer); | ||
| this.#flushTimer = null; | ||
@@ -66,0 +79,0 @@ } |
23359
1.74%295
4.61%2
100%