@ocap/indexdb 1.31.7 → 1.31.9

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/esm/backfill.mjs CHANGED
@@ -222,17 +222,24 @@ function applyTxIndexBackfill(params) {
222
222
  indexDb.exec("CREATE INDEX IF NOT EXISTS idx_tx_gasPayer ON tx(gasPayer)");
223
223
  const updateStmt = indexDb.prepare("UPDATE tx SET sender = ?, gasPayer = ?, tx = ?, accounts = ? WHERE hash = ?");
224
224
  const insertTxStmt = indexDb.prepare("INSERT OR IGNORE INTO tx (hash, type, code, valid, time, sender, receiver, gasPayer, tx, receipts, tokenSymbols, accounts) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
225
- const insertRefStmt = hasTxRef ? indexDb.prepare("INSERT OR IGNORE INTO tx_ref (hash, type, value, time) VALUES (?, ?, ?, ?)") : null;
225
+ const hasTxRefTxType = (hasTxRef ? new Set((indexDb.prepare("PRAGMA table_info('tx_ref')").all?.() || []).map((r) => r.name)) : /* @__PURE__ */ new Set()).has("tx_type");
226
+ const insertRefSql = hasTxRefTxType ? "INSERT OR IGNORE INTO tx_ref (hash, type, value, time, tx_type) VALUES (?, ?, ?, ?, (SELECT type FROM tx WHERE hash = ?))" : "INSERT OR IGNORE INTO tx_ref (hash, type, value, time) VALUES (?, ?, ?, ?)";
227
+ const insertRefStmt = hasTxRef ? indexDb.prepare(insertRefSql) : null;
228
+ const insertRef = (hash, value, time) => {
229
+ if (!insertRefStmt) return;
230
+ if (hasTxRefTxType) insertRefStmt.run?.(hash, "account", value, time, hash);
231
+ else insertRefStmt.run?.(hash, "account", value, time);
232
+ };
226
233
  let updatedRows = 0;
227
234
  for (const item of plan.updates) {
228
235
  updateStmt.run?.(item.nextSender, item.nextGasPayer, item.nextTxJson, item.nextAccountsJson, item.hash);
229
- if (insertRefStmt) for (const acc of item.addedAccountRefs) insertRefStmt.run?.(item.hash, "account", acc, item.time || "");
236
+ for (const acc of item.addedAccountRefs) insertRef(item.hash, acc, item.time || "");
230
237
  updatedRows += 1;
231
238
  }
232
239
  let insertedRows = 0;
233
240
  for (const item of plan.inserts) {
234
241
  insertTxStmt.run?.(item.hash, item.type, item.code, item.valid, item.time, item.sender, item.receiver, item.gasPayer, item.txJson, item.receiptsJson, item.tokenSymbolsJson, item.accountsJson);
235
- if (insertRefStmt) for (const acc of item.accountRefs) insertRefStmt.run?.(item.hash, "account", acc, item.time || "");
242
+ for (const acc of item.accountRefs) insertRef(item.hash, acc, item.time || "");
236
243
  insertedRows += 1;
237
244
  }
238
245
  indexDb.exec("COMMIT");
package/lib/backfill.cjs CHANGED
@@ -225,17 +225,24 @@ function applyTxIndexBackfill(params) {
225
225
  indexDb.exec("CREATE INDEX IF NOT EXISTS idx_tx_gasPayer ON tx(gasPayer)");
226
226
  const updateStmt = indexDb.prepare("UPDATE tx SET sender = ?, gasPayer = ?, tx = ?, accounts = ? WHERE hash = ?");
227
227
  const insertTxStmt = indexDb.prepare("INSERT OR IGNORE INTO tx (hash, type, code, valid, time, sender, receiver, gasPayer, tx, receipts, tokenSymbols, accounts) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
228
- const insertRefStmt = hasTxRef ? indexDb.prepare("INSERT OR IGNORE INTO tx_ref (hash, type, value, time) VALUES (?, ?, ?, ?)") : null;
228
+ const hasTxRefTxType = (hasTxRef ? new Set((indexDb.prepare("PRAGMA table_info('tx_ref')").all?.() || []).map((r) => r.name)) : /* @__PURE__ */ new Set()).has("tx_type");
229
+ const insertRefSql = hasTxRefTxType ? "INSERT OR IGNORE INTO tx_ref (hash, type, value, time, tx_type) VALUES (?, ?, ?, ?, (SELECT type FROM tx WHERE hash = ?))" : "INSERT OR IGNORE INTO tx_ref (hash, type, value, time) VALUES (?, ?, ?, ?)";
230
+ const insertRefStmt = hasTxRef ? indexDb.prepare(insertRefSql) : null;
231
+ const insertRef = (hash, value, time) => {
232
+ if (!insertRefStmt) return;
233
+ if (hasTxRefTxType) insertRefStmt.run?.(hash, "account", value, time, hash);
234
+ else insertRefStmt.run?.(hash, "account", value, time);
235
+ };
229
236
  let updatedRows = 0;
230
237
  for (const item of plan.updates) {
231
238
  updateStmt.run?.(item.nextSender, item.nextGasPayer, item.nextTxJson, item.nextAccountsJson, item.hash);
232
- if (insertRefStmt) for (const acc of item.addedAccountRefs) insertRefStmt.run?.(item.hash, "account", acc, item.time || "");
239
+ for (const acc of item.addedAccountRefs) insertRef(item.hash, acc, item.time || "");
233
240
  updatedRows += 1;
234
241
  }
235
242
  let insertedRows = 0;
236
243
  for (const item of plan.inserts) {
237
244
  insertTxStmt.run?.(item.hash, item.type, item.code, item.valid, item.time, item.sender, item.receiver, item.gasPayer, item.txJson, item.receiptsJson, item.tokenSymbolsJson, item.accountsJson);
238
- if (insertRefStmt) for (const acc of item.accountRefs) insertRefStmt.run?.(item.hash, "account", acc, item.time || "");
245
+ for (const acc of item.accountRefs) insertRef(item.hash, acc, item.time || "");
239
246
  insertedRows += 1;
240
247
  }
241
248
  indexDb.exec("COMMIT");
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.31.7",
6
+ "version": "1.31.9",
7
7
  "type": "module",
8
8
  "description": "Defines the basic interface for OCAP IndexDB",
9
9
  "main": "./lib/main.cjs",
@@ -52,9 +52,9 @@
52
52
  "tsdown": "^0.18.4"
53
53
  },
54
54
  "dependencies": {
55
- "@ocap/state": "1.31.7",
56
- "@ocap/types": "1.31.7",
57
- "@ocap/util": "1.31.7",
55
+ "@ocap/state": "1.31.9",
56
+ "@ocap/types": "1.31.9",
57
+ "@ocap/util": "1.31.9",
58
58
  "kareem": "^2.4.1",
59
59
  "lodash": "^4.17.23"
60
60
  }