@cocreate/indexeddb 1.13.1 → 1.13.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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## [1.13.3](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.13.2...v1.13.3) (2023-09-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * get.database response ([a2311df](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/a2311df7ef6c29cab8e21144ff10fa94a9c71540))
7
+ * handle method get.database ([dbc998e](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/dbc998ef9e7cd141c14c41c55e625bec9c996e55))
8
+ * Refactor condition for filtering objects in `processObject` function ([d5fc6a3](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/d5fc6a32ff3f09d2d6542c7733d4963df7900513))
9
+
10
+ ## [1.13.2](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.13.1...v1.13.2) (2023-08-21)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * update status logic ([2eee57a](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/2eee57afa24e3628d7a97f745d7694db8315b3c3))
16
+
1
17
  ## [1.13.1](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.13.0...v1.13.1) (2023-08-21)
2
18
 
3
19
 
@@ -1,25 +1,25 @@
1
- module.exports = {
2
- "organization_id": "",
3
- "key": "",
4
- "host": "",
5
- "sources": [
6
- {
7
- "array": "files",
8
- "object": {
9
- "_id": "637ca2aa50234ef1671ce308",
10
- "name": "index.html",
11
- "path": "/docs/indexeddb/index.html",
12
- "src": "{{./docs/index.html}}",
13
- "host": [
14
- "cocreate.app",
15
- "general.cocreate.app"
16
- ],
17
- "directory": "/docs/indexeddb",
18
- "parentDirectory": "{{parentDirectory}}",
19
- "content-type": "{{content-type}}",
20
- "public": "true",
21
- "website_id": "644d4bff8036fb9d1d1fd69c"
22
- }
23
- }
24
- ]
1
+ module.exports = {
2
+ "organization_id": "",
3
+ "key": "",
4
+ "host": "",
5
+ "sources": [
6
+ {
7
+ "array": "files",
8
+ "object": {
9
+ "_id": "637ca2aa50234ef1671ce308",
10
+ "name": "index.html",
11
+ "path": "/docs/indexeddb/index.html",
12
+ "src": "{{./docs/index.html}}",
13
+ "host": [
14
+ "cocreate.app",
15
+ "general.cocreate.app"
16
+ ],
17
+ "directory": "/docs/indexeddb",
18
+ "parentDirectory": "{{parentDirectory}}",
19
+ "content-type": "{{content-type}}",
20
+ "public": "true",
21
+ "website_id": "644d4bff8036fb9d1d1fd69c"
22
+ }
23
+ }
24
+ ]
25
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/indexeddb",
3
- "version": "1.13.1",
3
+ "version": "1.13.3",
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",
package/src/index.js CHANGED
@@ -46,10 +46,11 @@ function setStatus(value) {
46
46
  window.CoCreateConfig.indexeddb = value;
47
47
  else
48
48
  window.CoCreateConfig = { indexeddb: value };
49
+
49
50
  if (!value) {
50
51
  indexedDbFunction = indexedDb
51
52
  indexedDb = value;
52
- } else {
53
+ } else if (!indexedDb) {
53
54
  indexedDb = indexedDbFunction
54
55
  indexedDbFunction = true
55
56
  }
@@ -62,9 +63,12 @@ async function indexedDb(data) {
62
63
  let type = data.method.split('.');
63
64
  type = type[type.length - 1];
64
65
 
65
- if (type === 'database')
66
- await processDatabase(data, newData, type)
67
- else {
66
+ if (type === 'database') {
67
+ if (data.method === 'get.database') {
68
+ return await processDatabase(data)
69
+ } else
70
+ await processDatabase(data, newData, type)
71
+ } else {
68
72
  if (data.request)
69
73
  data[type] = data.request
70
74
 
@@ -418,7 +422,7 @@ async function processObject(data, newData, database, array, type) {
418
422
  let filteredObjects
419
423
  let arrayExist = db.objectStoreNames.contains(array)
420
424
  if (arrayExist) {
421
- if (data.filter || data.method == 'read.object' && !data.object && !data.object.length) {
425
+ if (data.filter || data.method == 'read.object' && (!data.object || data.object && !data.object.length)) {
422
426
  db.close()
423
427
  filteredObjects = await readObject(data, database, array)
424
428
  db = await processDatabase({ method: 'get.database', database })
@@ -433,10 +437,10 @@ async function processObject(data, newData, database, array, type) {
433
437
  }
434
438
  }
435
439
 
436
- let transaction, objectStore
440
+ // let transaction, objectStore
437
441
  if (array && db) {
438
- transaction = db.transaction([array], "readwrite");
439
- objectStore = transaction.objectStore(array);
442
+ var transaction = db.transaction([array], "readwrite");
443
+ var objectStore = transaction.objectStore(array);
440
444
  }
441
445
 
442
446
  let objects = []