@firtoz/idb-collections 0.2.0 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/idb-collections",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "IndexedDB collection utilities for TanStack DB — key-value adapter, query optimization",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -56,7 +56,7 @@
56
56
  "devDependencies": {
57
57
  "@standard-schema/spec": "^1.1.0",
58
58
  "@tanstack/db": "^0.5.33",
59
- "bun-types": "^1.3.10",
59
+ "bun-types": "^1.3.11",
60
60
  "zod": "^4.3.6"
61
61
  },
62
62
  "dependencies": {
@@ -33,7 +33,18 @@ export function tryExtractIndexedQuery(
33
33
  }
34
34
 
35
35
  try {
36
- const comparisons = extractSimpleComparisons(expression);
36
+ let comparisons: ReturnType<typeof extractSimpleComparisons>;
37
+ try {
38
+ comparisons = extractSimpleComparisons(expression);
39
+ } catch {
40
+ // e.g. `like` and other ops TanStack does not decompose here — fall back to full scan + filter
41
+ if (debug) {
42
+ console.warn(
43
+ "Indexed query extraction skipped: expression not supported by extractSimpleComparisons",
44
+ );
45
+ }
46
+ return null;
47
+ }
37
48
 
38
49
  if (comparisons.length !== 1) {
39
50
  return null;
@@ -41,7 +52,10 @@ export function tryExtractIndexedQuery(
41
52
 
42
53
  const comparison = comparisons[0];
43
54
  const fieldName = comparison.field.join(".");
44
- const indexName = indexes[fieldName];
55
+ const lastIdx = comparison.field.length - 1;
56
+ const lastSegment = lastIdx >= 0 ? (comparison.field[lastIdx] ?? "") : "";
57
+ // TanStack may use nested refs (`todo.priority`); IDB indexes are keyed by column (e.g. `priority`)
58
+ const indexName = indexes[fieldName] ?? indexes[lastSegment];
45
59
 
46
60
  if (!indexName) {
47
61
  return null;
@@ -96,7 +110,9 @@ export function tryExtractIndexedQuery(
96
110
 
97
111
  return { fieldName, indexName, keyRange };
98
112
  } catch (error) {
99
- console.error("Error extracting indexed query", error, expression);
113
+ if (debug) {
114
+ console.warn("Error extracting indexed query", error, expression);
115
+ }
100
116
  return null;
101
117
  }
102
118
  }