jexidb 2.2.2 → 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 +28 -1
- package/package.json +1 -1
- package/src/managers/IndexManager.mjs +34 -1
package/dist/Database.cjs
CHANGED
|
@@ -2662,6 +2662,11 @@ class IndexManager {
|
|
|
2662
2662
|
* on-disk index after an unload must first ensure it is loaded again, e.g.
|
|
2663
2663
|
* `await database._ensureLazyIndexLoaded()`.
|
|
2664
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
|
+
*
|
|
2665
2670
|
* @param {string} column - Indexed field name (e.g. 'nameTerms', 'groupTerms', 'category')
|
|
2666
2671
|
* @returns {Set<string>} Terms currently indexed for the column (empty Set if the
|
|
2667
2672
|
* column is not indexed or the index is not loaded)
|
|
@@ -2670,7 +2675,29 @@ class IndexManager {
|
|
|
2670
2675
|
if (!this.index || !this.index.data || !this.index.data[column]) {
|
|
2671
2676
|
return new Set();
|
|
2672
2677
|
}
|
|
2673
|
-
|
|
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;
|
|
2674
2701
|
}
|
|
2675
2702
|
|
|
2676
2703
|
/**
|
package/package.json
CHANGED
|
@@ -2351,6 +2351,11 @@ export default class IndexManager {
|
|
|
2351
2351
|
* on-disk index after an unload must first ensure it is loaded again, e.g.
|
|
2352
2352
|
* `await database._ensureLazyIndexLoaded()`.
|
|
2353
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
|
+
*
|
|
2354
2359
|
* @param {string} column - Indexed field name (e.g. 'nameTerms', 'groupTerms', 'category')
|
|
2355
2360
|
* @returns {Set<string>} Terms currently indexed for the column (empty Set if the
|
|
2356
2361
|
* column is not indexed or the index is not loaded)
|
|
@@ -2359,7 +2364,35 @@ export default class IndexManager {
|
|
|
2359
2364
|
if (!this.index || !this.index.data || !this.index.data[column]) {
|
|
2360
2365
|
return new Set()
|
|
2361
2366
|
}
|
|
2362
|
-
|
|
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
|
|
2363
2396
|
}
|
|
2364
2397
|
|
|
2365
2398
|
/**
|