jexidb 2.2.1 → 2.2.3
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/dist/Database.cjs +48 -0
- package/package.json +1 -1
- package/src/managers/IndexManager.mjs +54 -0
package/dist/Database.cjs
CHANGED
|
@@ -2652,6 +2652,54 @@ class IndexManager {
|
|
|
2652
2652
|
this.markIndexUsed();
|
|
2653
2653
|
}
|
|
2654
2654
|
|
|
2655
|
+
/**
|
|
2656
|
+
* Restored public API: return the indexed terms (keys) currently held in memory
|
|
2657
|
+
* for a given column.
|
|
2658
|
+
*
|
|
2659
|
+
* IMPORTANT: This method reads ONLY the in-memory index. It never triggers a lazy
|
|
2660
|
+
* reload and never performs any disk I/O. If the index was idle-unloaded
|
|
2661
|
+
* (`indexLoaded === false`), it returns an empty Set. Callers that need the
|
|
2662
|
+
* on-disk index after an unload must first ensure it is loaded again, e.g.
|
|
2663
|
+
* `await database._ensureLazyIndexLoaded()`.
|
|
2664
|
+
*
|
|
2665
|
+
* The return format is ALWAYS the actual term strings (words/values), never the
|
|
2666
|
+
* internal numeric term IDs. For term-mapped columns the index stores term IDs as
|
|
2667
|
+
* keys, so they are translated back to words through the TermManager before being
|
|
2668
|
+
* returned. This keeps the API consistent across indexed fields.
|
|
2669
|
+
*
|
|
2670
|
+
* @param {string} column - Indexed field name (e.g. 'nameTerms', 'groupTerms', 'category')
|
|
2671
|
+
* @returns {Set<string>} Terms currently indexed for the column (empty Set if the
|
|
2672
|
+
* column is not indexed or the index is not loaded)
|
|
2673
|
+
*/
|
|
2674
|
+
readColumnIndex(column) {
|
|
2675
|
+
if (!this.index || !this.index.data || !this.index.data[column]) {
|
|
2676
|
+
return new Set();
|
|
2677
|
+
}
|
|
2678
|
+
const keys = Object.keys(this.index.data[column]);
|
|
2679
|
+
|
|
2680
|
+
// Consistent contract: always return term strings, never numeric term IDs.
|
|
2681
|
+
const termManager = this.database?.termManager;
|
|
2682
|
+
const isTermMappingField = Boolean(termManager && termManager.termMappingFields && termManager.termMappingFields.includes(column));
|
|
2683
|
+
if (!isTermMappingField) {
|
|
2684
|
+
return new Set(keys);
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
// Term-mapped column: index keys are numeric term IDs -> translate back to words.
|
|
2688
|
+
const terms = new Set();
|
|
2689
|
+
for (const key of keys) {
|
|
2690
|
+
if (/^\d+$/.test(key)) {
|
|
2691
|
+
const word = termManager.getTerm?.(Number(key));
|
|
2692
|
+
if (word !== null && word !== undefined) {
|
|
2693
|
+
terms.add(word);
|
|
2694
|
+
}
|
|
2695
|
+
} else {
|
|
2696
|
+
// Defensive: key is already a term string (legacy/in-memory data)
|
|
2697
|
+
terms.add(key);
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
return terms;
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2655
2703
|
/**
|
|
2656
2704
|
* Convert index to JSON-serializable format for debugging and export
|
|
2657
2705
|
* This resolves the issue where Sets appear as empty objects in JSON.stringify
|
package/package.json
CHANGED
|
@@ -2341,6 +2341,60 @@ export default class IndexManager {
|
|
|
2341
2341
|
this.markIndexUsed()
|
|
2342
2342
|
}
|
|
2343
2343
|
|
|
2344
|
+
/**
|
|
2345
|
+
* Restored public API: return the indexed terms (keys) currently held in memory
|
|
2346
|
+
* for a given column.
|
|
2347
|
+
*
|
|
2348
|
+
* IMPORTANT: This method reads ONLY the in-memory index. It never triggers a lazy
|
|
2349
|
+
* reload and never performs any disk I/O. If the index was idle-unloaded
|
|
2350
|
+
* (`indexLoaded === false`), it returns an empty Set. Callers that need the
|
|
2351
|
+
* on-disk index after an unload must first ensure it is loaded again, e.g.
|
|
2352
|
+
* `await database._ensureLazyIndexLoaded()`.
|
|
2353
|
+
*
|
|
2354
|
+
* The return format is ALWAYS the actual term strings (words/values), never the
|
|
2355
|
+
* internal numeric term IDs. For term-mapped columns the index stores term IDs as
|
|
2356
|
+
* keys, so they are translated back to words through the TermManager before being
|
|
2357
|
+
* returned. This keeps the API consistent across indexed fields.
|
|
2358
|
+
*
|
|
2359
|
+
* @param {string} column - Indexed field name (e.g. 'nameTerms', 'groupTerms', 'category')
|
|
2360
|
+
* @returns {Set<string>} Terms currently indexed for the column (empty Set if the
|
|
2361
|
+
* column is not indexed or the index is not loaded)
|
|
2362
|
+
*/
|
|
2363
|
+
readColumnIndex(column) {
|
|
2364
|
+
if (!this.index || !this.index.data || !this.index.data[column]) {
|
|
2365
|
+
return new Set()
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
const keys = Object.keys(this.index.data[column])
|
|
2369
|
+
|
|
2370
|
+
// Consistent contract: always return term strings, never numeric term IDs.
|
|
2371
|
+
const termManager = this.database?.termManager
|
|
2372
|
+
const isTermMappingField = Boolean(
|
|
2373
|
+
termManager &&
|
|
2374
|
+
termManager.termMappingFields &&
|
|
2375
|
+
termManager.termMappingFields.includes(column)
|
|
2376
|
+
)
|
|
2377
|
+
|
|
2378
|
+
if (!isTermMappingField) {
|
|
2379
|
+
return new Set(keys)
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
// Term-mapped column: index keys are numeric term IDs -> translate back to words.
|
|
2383
|
+
const terms = new Set()
|
|
2384
|
+
for (const key of keys) {
|
|
2385
|
+
if (/^\d+$/.test(key)) {
|
|
2386
|
+
const word = termManager.getTerm?.(Number(key))
|
|
2387
|
+
if (word !== null && word !== undefined) {
|
|
2388
|
+
terms.add(word)
|
|
2389
|
+
}
|
|
2390
|
+
} else {
|
|
2391
|
+
// Defensive: key is already a term string (legacy/in-memory data)
|
|
2392
|
+
terms.add(key)
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
return terms
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2344
2398
|
/**
|
|
2345
2399
|
* Convert index to JSON-serializable format for debugging and export
|
|
2346
2400
|
* This resolves the issue where Sets appear as empty objects in JSON.stringify
|