@cocreate/indexeddb 1.16.0 → 1.16.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.16.2](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.16.1...v1.16.2) (2023-10-26)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * expanded the try catch ([ab77e43](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/ab77e434f4811832089d63256afb8e678209b4f7))
7
+
8
+ ## [1.16.1](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.16.0...v1.16.1) (2023-10-25)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * bump dependencies ([7597870](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/759787005654c5439cab247d848829542427db45))
14
+
1
15
  # [1.16.0](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.15.0...v1.16.0) (2023-10-24)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/indexeddb",
3
- "version": "1.16.0",
3
+ "version": "1.16.2",
4
4
  "description": "A simple indexeddb component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "indexeddb",
@@ -58,6 +58,6 @@
58
58
  "webpack-log": "^3.0.1"
59
59
  },
60
60
  "dependencies": {
61
- "@cocreate/utils": "^1.25.3"
61
+ "@cocreate/utils": "^1.26.1"
62
62
  }
63
63
  }
package/src/index.js CHANGED
@@ -105,7 +105,6 @@ async function send(data) {
105
105
  }
106
106
  }
107
107
 
108
-
109
108
  return createData(data, newData, type)
110
109
 
111
110
  } catch (error) {
@@ -423,48 +422,48 @@ async function processIndex(data, newData, database, array, type) {
423
422
  async function processObject(data, newData, database, array, type) {
424
423
  let db = await processDatabase({ method: 'get.database', database })
425
424
 
426
- let isFilter
427
- if (data.$filter && data.$filter.query)
428
- isFilter = true
429
-
430
- let arrayExist = db.objectStoreNames.contains(array)
431
- if (!arrayExist) {
432
- if (data.method == 'create.object' || data.method == 'update.object') {
433
- db.close()
434
- db = await processDatabase({ method: 'get.database', database, array })
435
- } else {
436
- return errorHandler(data, "array does not exist", database, array)
425
+ try {
426
+ let isFilter
427
+ if (data.$filter && data.$filter.query)
428
+ isFilter = true
429
+
430
+ let arrayExist = db.objectStoreNames.contains(array)
431
+ if (!arrayExist) {
432
+ if (data.method == 'create.object' || data.method == 'update.object') {
433
+ db.close()
434
+ db = await processDatabase({ method: 'get.database', database, array })
435
+ } else {
436
+ return errorHandler(data, "array does not exist", database, array)
437
+ }
437
438
  }
438
- }
439
439
 
440
- if (!array || !db)
441
- throw new Error({ error: "This is an error message.", db, array });
440
+ if (!array || !db)
441
+ throw new Error({ error: "This is an error message.", db, array });
442
442
 
443
- let transactionType = "readwrite" //test
444
- if (data.method == 'read.object')
445
- transactionType = "readonly"
443
+ if (!data[type])
444
+ data[type] = []
445
+ if (data[type] && !Array.isArray(data[type]))
446
+ data[type] = [data[type]]
446
447
 
447
- let transaction = db.transaction([array], transactionType);
448
- let objectStore = transaction.objectStore(array);
449
- if (!data[type])
450
- data[type] = []
451
- if (data[type] && !Array.isArray(data[type]))
452
- data[type] = [data[type]]
448
+ if (isFilter && !data[type].length)
449
+ data[type] = [{}]
453
450
 
454
- if (isFilter && !data[type].length)
455
- data[type] = [{}]
451
+ let transactionType = "readwrite" //test
452
+ if (data.method == 'read.object')
453
+ transactionType = "readonly"
456
454
 
457
- let globalOperators = getGlobalOperators(data)
458
- let upsert = data.upsert
455
+ let transaction = db.transaction([array], transactionType);
456
+ let objectStore = transaction.objectStore(array);
459
457
 
460
- if (data.$filter) {
461
- let count = objectStore.count();
462
- count.onsuccess = function () {
463
- data.$filter.count = count.result
464
- }
465
- }
458
+ let globalOperators = getGlobalOperators(data)
459
+ let upsert = data.upsert
466
460
 
467
- try {
461
+ if (data.$filter) {
462
+ let count = objectStore.count();
463
+ count.onsuccess = function () {
464
+ data.$filter.count = count.result
465
+ }
466
+ }
468
467
 
469
468
  for (let i = 0; i < data[type].length; i++) {
470
469
  delete data[type][i].$storage
@@ -572,11 +571,16 @@ async function processObject(data, newData, database, array, type) {
572
571
  }
573
572
 
574
573
  }
574
+
575
+ if (db.close)
576
+ db.close()
577
+
575
578
  } catch (error) {
576
579
  errorHandler(data, error, database, array)
577
- }
580
+ if (db.close)
581
+ db.close()
578
582
 
579
- db.close()
583
+ }
580
584
  }
581
585
 
582
586
  function openCursor(objectStore, range, direction, data, newData, isFilter, limit, database, array, upsert, type, i, globalOperators) {