@workglow/indexeddb 0.4.8 → 0.5.0

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.
@@ -76,8 +76,8 @@ function compareSchemas(store, expectedPrimaryKey, expectedIndexes) {
76
76
  diff.indexesToAdd.push(expectedIdx);
77
77
  } else {
78
78
  const expectedKeyPath = Array.isArray(expectedIdx.keyPath) ? expectedIdx.keyPath : [expectedIdx.keyPath];
79
- const actualKeyPath2 = Array.isArray(existingIdx.keyPath) ? existingIdx.keyPath : [existingIdx.keyPath];
80
- const keyPathChanged = !deepEqual(expectedKeyPath, actualKeyPath2);
79
+ const actualKeyPath = Array.isArray(existingIdx.keyPath) ? existingIdx.keyPath : [existingIdx.keyPath];
80
+ const keyPathChanged = !deepEqual(expectedKeyPath, actualKeyPath);
81
81
  const uniqueChanged = existingIdx.unique !== (expectedIdx.options?.unique ?? false);
82
82
  const multiEntryChanged = existingIdx.multiEntry !== (expectedIdx.options?.multiEntry ?? false);
83
83
  if (keyPathChanged || uniqueChanged || multiEntryChanged) {
@@ -162,11 +162,11 @@ async function performDestructiveMigration(db, tableName, primaryKey, expectedIn
162
162
  }
163
163
  options.onMigrationProgress?.(`Recreating object store...`, 0.75);
164
164
  const newDb = await openIndexedDbTable(tableName, newVersion, (event) => {
165
- const db2 = event.target.result;
166
- if (db2.objectStoreNames.contains(tableName)) {
167
- db2.deleteObjectStore(tableName);
165
+ const db = event.target.result;
166
+ if (db.objectStoreNames.contains(tableName)) {
167
+ db.deleteObjectStore(tableName);
168
168
  }
169
- const store = db2.createObjectStore(tableName, { keyPath: primaryKey, autoIncrement });
169
+ const store = db.createObjectStore(tableName, { keyPath: primaryKey, autoIncrement });
170
170
  for (const idx of expectedIndexes) {
171
171
  store.createIndex(idx.name, idx.keyPath, idx.options);
172
172
  }
@@ -192,11 +192,11 @@ async function createNewDatabase(tableName, primaryKey, expectedIndexes, options
192
192
  } catch (err) {}
193
193
  const version = 1;
194
194
  const db = await openIndexedDbTable(tableName, version, (event) => {
195
- const db2 = event.target.result;
196
- if (!db2.objectStoreNames.contains(METADATA_STORE_NAME)) {
197
- db2.createObjectStore(METADATA_STORE_NAME, { keyPath: "tableName" });
195
+ const db = event.target.result;
196
+ if (!db.objectStoreNames.contains(METADATA_STORE_NAME)) {
197
+ db.createObjectStore(METADATA_STORE_NAME, { keyPath: "tableName" });
198
198
  }
199
- const store = db2.createObjectStore(tableName, { keyPath: primaryKey, autoIncrement });
199
+ const store = db.createObjectStore(tableName, { keyPath: primaryKey, autoIncrement });
200
200
  for (const idx of expectedIndexes) {
201
201
  store.createIndex(idx.name, idx.keyPath, idx.options);
202
202
  }
@@ -233,23 +233,23 @@ async function ensureIndexedDbTable(tableName, primaryKey, expectedIndexes = [],
233
233
  await new Promise((resolve) => setTimeout(resolve, 50));
234
234
  } catch (err) {}
235
235
  db = await openIndexedDbTable(tableName, 1, (event) => {
236
- const db2 = event.target.result;
237
- if (!db2.objectStoreNames.contains(METADATA_STORE_NAME)) {
238
- db2.createObjectStore(METADATA_STORE_NAME, { keyPath: "tableName" });
236
+ const db = event.target.result;
237
+ if (!db.objectStoreNames.contains(METADATA_STORE_NAME)) {
238
+ db.createObjectStore(METADATA_STORE_NAME, { keyPath: "tableName" });
239
239
  }
240
- const store2 = db2.createObjectStore(tableName, { keyPath: primaryKey, autoIncrement });
240
+ const store = db.createObjectStore(tableName, { keyPath: primaryKey, autoIncrement });
241
241
  for (const idx of expectedIndexes) {
242
- store2.createIndex(idx.name, idx.keyPath, idx.options);
242
+ store.createIndex(idx.name, idx.keyPath, idx.options);
243
243
  }
244
244
  });
245
- const snapshot2 = {
245
+ const snapshot = {
246
246
  version: db.version,
247
247
  primaryKey,
248
248
  indexes: expectedIndexes,
249
249
  recordCount: 0,
250
250
  timestamp: Date.now()
251
251
  };
252
- await saveSchemaMetadata(db, tableName, snapshot2);
252
+ await saveSchemaMetadata(db, tableName, snapshot);
253
253
  options.onMigrationProgress?.(`Database created successfully`, 1);
254
254
  return db;
255
255
  }
@@ -257,9 +257,9 @@ async function ensureIndexedDbTable(tableName, primaryKey, expectedIndexes = [],
257
257
  const currentVersion = db.version;
258
258
  db.close();
259
259
  db = await openIndexedDbTable(tableName, currentVersion + 1, (event) => {
260
- const db2 = event.target.result;
261
- if (!db2.objectStoreNames.contains(METADATA_STORE_NAME)) {
262
- db2.createObjectStore(METADATA_STORE_NAME, { keyPath: "tableName" });
260
+ const db = event.target.result;
261
+ if (!db.objectStoreNames.contains(METADATA_STORE_NAME)) {
262
+ db.createObjectStore(METADATA_STORE_NAME, { keyPath: "tableName" });
263
263
  }
264
264
  });
265
265
  }
@@ -278,13 +278,13 @@ async function ensureIndexedDbTable(tableName, primaryKey, expectedIndexes = [],
278
278
  const needsMigration = diff.indexesToAdd.length > 0 || diff.indexesToRemove.length > 0 || diff.indexesToModify.length > 0 || diff.needsObjectStoreRecreation;
279
279
  if (!needsMigration) {
280
280
  options.onMigrationProgress?.(`Schema for ${tableName} is up to date`, 1);
281
- const snapshot2 = {
281
+ const snapshot = {
282
282
  version: db.version,
283
283
  primaryKey,
284
284
  indexes: expectedIndexes,
285
285
  timestamp: Date.now()
286
286
  };
287
- await saveSchemaMetadata(db, tableName, snapshot2);
287
+ await saveSchemaMetadata(db, tableName, snapshot);
288
288
  return db;
289
289
  }
290
290
  if (diff.needsObjectStoreRecreation) {
@@ -320,8 +320,11 @@ import {
320
320
  HybridSubscriptionManager,
321
321
  isSearchCondition,
322
322
  isSearchInCondition,
323
+ isSearchNotInCondition,
323
324
  matchesEqualityCriterion,
325
+ matchesInCriterion,
324
326
  matchesInequalityCriterion,
327
+ matchesNotInCriterion,
325
328
  normalizeCriterion,
326
329
  pickCoveringIndex,
327
330
  safeEmit,
@@ -1151,9 +1154,9 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
1151
1154
  const store = transaction.objectStore(this.table);
1152
1155
  const plan = this.createIndexedRange(store, criteria);
1153
1156
  if (plan?.coversCriteria) {
1154
- const request2 = plan.source.count(plan.range);
1155
- request2.onerror = () => reject(request2.error);
1156
- request2.onsuccess = () => resolve(request2.result);
1157
+ const request = plan.source.count(plan.range);
1158
+ request.onerror = () => reject(request.error);
1159
+ request.onsuccess = () => resolve(request.result);
1157
1160
  return;
1158
1161
  }
1159
1162
  const source = plan?.source ?? store;
@@ -1215,7 +1218,12 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
1215
1218
  const recordValue = record[column];
1216
1219
  const normalized = normalizeCriterion(criterion);
1217
1220
  if (normalized.kind === "in") {
1218
- if (!normalized.values.some((candidate) => recordValue === candidate))
1221
+ if (!matchesInCriterion(recordValue, normalized.values))
1222
+ return false;
1223
+ continue;
1224
+ }
1225
+ if (normalized.kind === "not-in") {
1226
+ if (!matchesNotInCriterion(recordValue, normalized.values))
1219
1227
  return false;
1220
1228
  continue;
1221
1229
  }
@@ -1255,10 +1263,8 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
1255
1263
  return true;
1256
1264
  }
1257
1265
  async deleteSearch(criteria) {
1258
- const criteriaKeys = Object.keys(criteria);
1259
- if (criteriaKeys.length === 0) {
1266
+ if (!this.shouldRunDeleteSearch(criteria))
1260
1267
  return;
1261
- }
1262
1268
  const db = await this.getDb();
1263
1269
  return new Promise((resolve, reject) => {
1264
1270
  try {
@@ -1348,7 +1354,7 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
1348
1354
  const criterion = criteria[column];
1349
1355
  if (criterion === undefined)
1350
1356
  return;
1351
- if (isSearchInCondition(criterion))
1357
+ if (isSearchInCondition(criterion) || isSearchNotInCondition(criterion))
1352
1358
  return;
1353
1359
  if (isSearchCondition(criterion)) {
1354
1360
  if (criterion.operator !== "=")
@@ -1503,6 +1509,9 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
1503
1509
  });
1504
1510
  for (const col of picked.keyPath) {
1505
1511
  const criterion = criteria[col];
1512
+ if (isSearchNotInCondition(criterion) && criterion.value.length === 0) {
1513
+ throw new StorageUnsupportedError(`An empty "not-in" criterion on indexed column "${col}" (it matches every ` + `row including null-valued ones, but IndexedDB omits those from an index, ` + `so an index scan can never reach them — use query() instead)`, "IndexedDbTabularStorage");
1514
+ }
1506
1515
  const isNullEquality = isSearchCondition(criterion) ? criterion.operator === "=" && criterion.value === null : criterion === null;
1507
1516
  if (isNullEquality) {
1508
1517
  throw new StorageUnsupportedError(`A null equality criterion on indexed column "${col}" (IndexedDB omits ` + `null-valued records from an index, so an index scan can never reach ` + `them — use query() instead)`, "IndexedDbTabularStorage");
@@ -1518,7 +1527,7 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
1518
1527
  const c = criteria[col];
1519
1528
  if (c === undefined && !(col in criteria))
1520
1529
  break;
1521
- if (isSearchInCondition(c))
1530
+ if (isSearchInCondition(c) || isSearchNotInCondition(c))
1522
1531
  break;
1523
1532
  if (isSearchCondition(c)) {
1524
1533
  if (c.operator !== "=")
@@ -1527,7 +1536,7 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
1527
1536
  break;
1528
1537
  prefix.push(c.value);
1529
1538
  } else {
1530
- if (c === null)
1539
+ if (c === null || c === undefined)
1531
1540
  break;
1532
1541
  prefix.push(c);
1533
1542
  }
@@ -1575,7 +1584,7 @@ class IndexedDbTabularStorage extends BaseTabularStorage {
1575
1584
  continue;
1576
1585
  const valFromKey = Array.isArray(key) ? key[pos] : key;
1577
1586
  const normalized = normalizeCriterion(crit);
1578
- const ok = normalized.kind === "in" ? normalized.values.some((candidate) => valFromKey === candidate) : compareWithOperator(valFromKey, normalized.operator, normalized.value);
1587
+ const ok = normalized.kind === "in" ? matchesInCriterion(valFromKey, normalized.values) : normalized.kind === "not-in" ? matchesNotInCriterion(valFromKey, normalized.values) : compareWithOperator(valFromKey, normalized.operator, normalized.value);
1579
1588
  if (!ok) {
1580
1589
  matches = false;
1581
1590
  break;
@@ -1760,4 +1769,4 @@ export {
1760
1769
  runIndexedDbMigrationGroups
1761
1770
  };
1762
1771
 
1763
- //# debugId=0833B0AFB348CFFE64756E2164756E21
1772
+ //# debugId=2B2714B1793C3B3064756E2164756E21