@cocreate/indexeddb 1.4.16 → 1.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [1.5.0](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.4.16...v1.5.0) (2022-12-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump dependencies ([1cb7795](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/1cb779552fb31c546c471f5c73d8e6babcff30db))
7
+
8
+
9
+ ### Features
10
+
11
+ * query, search and sort databases, collections, and indexes ([fd3f248](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/fd3f2486239d002d313069cfc19c86df2f341b97))
12
+
1
13
  ## [1.4.16](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.4.15...v1.4.16) (2022-12-09)
2
14
 
3
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/indexeddb",
3
- "version": "1.4.16",
3
+ "version": "1.5.0",
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",
@@ -61,8 +61,8 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/docs": "^1.4.16",
65
- "@cocreate/hosting": "^1.6.15",
66
- "@cocreate/utils": "^1.15.1"
64
+ "@cocreate/docs": "^1.4.17",
65
+ "@cocreate/hosting": "^1.6.16",
66
+ "@cocreate/utils": "^1.15.2"
67
67
  }
68
68
  }
package/src/index.js CHANGED
@@ -40,8 +40,13 @@ const Database = (action, data) => {
40
40
 
41
41
  if (action == 'readDatabase') {
42
42
  indexedDB.databases().then((databases) => {
43
- data.databases = databases
44
- resolve(data)
43
+ for (let database of databases){
44
+ let isFilter = queryData(database, data.filter.query)
45
+ if (isFilter)
46
+ databaseArray.push({database, db: 'indexeddb'})
47
+ }
48
+
49
+ resolve(createData(data, databaseArray, type))
45
50
  })
46
51
  } else {
47
52
  let databases
@@ -220,8 +225,8 @@ const Database = (action, data) => {
220
225
  }
221
226
  }
222
227
 
223
- }, (err) => {
224
- errorHandler(data, err)
228
+ }, (error) => {
229
+ errorHandler(data, error)
225
230
  });
226
231
  }
227
232
 
@@ -270,7 +275,9 @@ const collection = (action, data) => {
270
275
  data[type] = []
271
276
 
272
277
  for (let collection of Array.from(objectStoreNames)){
273
- collectionArray.push({name: collection, db: 'indexeddb', database})
278
+ let isFilter = queryData({name: collection}, data.filter.query)
279
+ if (isFilter)
280
+ collectionArray.push({name: collection, db: 'indexeddb', database})
274
281
  }
275
282
 
276
283
  databasesLength -= 1
@@ -340,8 +347,8 @@ const collection = (action, data) => {
340
347
  }
341
348
 
342
349
  }
343
- }, (err) => {
344
- errorHandler(data, err, database)
350
+ }, (error) => {
351
+ errorHandler(data, error, database)
345
352
  })
346
353
 
347
354
  } else {
@@ -371,8 +378,8 @@ const collection = (action, data) => {
371
378
  }
372
379
  };
373
380
  }
374
- }, (err) => {
375
- errorHandler(data, err)
381
+ }, (error) => {
382
+ errorHandler(data, error)
376
383
  });
377
384
  }
378
385
 
@@ -425,7 +432,9 @@ const index = (action, data) => {
425
432
 
426
433
  if (action == 'readIndex') {
427
434
  for (let index of indexNames) {
428
- indexArray.push({name: index, db: 'indexeddb', database, collection})
435
+ let isFilter = queryData({name: index}, data.filter.query)
436
+ if (isFilter)
437
+ indexArray.push({name: index, db: 'indexeddb', database, collection})
429
438
  }
430
439
  collectionsLength -= 1
431
440
  db.close()
@@ -514,8 +523,8 @@ const index = (action, data) => {
514
523
  }
515
524
  }
516
525
 
517
- }, (err) => {
518
- errorHandler(data, err)
526
+ }, (error) => {
527
+ errorHandler(data, error)
519
528
  });
520
529
  }
521
530
 
@@ -777,8 +786,8 @@ function runDocs({action, data, objectStore, documents, filterDocs, database, co
777
786
  } else {
778
787
  resolve()
779
788
  }
780
- }, (err) => {
781
- errorHandler(data, {message: err, document: doc}, database, objectStore.name)
789
+ }, (error) => {
790
+ errorHandler(data, {message: error, document: doc}, database, objectStore.name)
782
791
  })
783
792
  }
784
793
 
@@ -880,9 +889,8 @@ const readDocuments = (data, database, collection) => {
880
889
  let indexName;
881
890
  if (data.filter && data.filter.sort && data.filter.sort[0] && data.filter.sort[0].name) {
882
891
  indexName = data.filter.sort[0].name
883
- if (indexName.includes('-')) {
892
+ if (indexName.includes('-'))
884
893
  isIndex = false
885
- }
886
894
  else
887
895
  isIndex = true
888
896
  }
@@ -908,7 +916,7 @@ const readDocuments = (data, database, collection) => {
908
916
  }
909
917
  const indexStore = objectStore.index(indexName);
910
918
 
911
- readDocs(data, database, collection, indexStore, isIndex, direction).then((results) => {
919
+ readDocs(data, database, collection, indexStore, direction).then((results) => {
912
920
  if (db2 && db2.close)
913
921
  db2.close()
914
922
  resolve(results)
@@ -916,19 +924,19 @@ const readDocuments = (data, database, collection) => {
916
924
  })
917
925
  } else {
918
926
  const indexStore = objectStore.index(indexName);
919
- readDocs(data, database, collection, indexStore, isIndex, direction).then((results) => {
927
+ readDocs(data, database, collection, indexStore, direction).then((results) => {
920
928
  db.close()
921
929
  resolve(results)
922
930
  })
923
931
  }
924
932
  } else {
925
- readDocs(data, database, collection, objectStore, isIndex).then((results) => {
933
+ readDocs(data, database, collection, objectStore).then((results) => {
926
934
  db.close()
927
935
  resolve(results)
928
936
  })
929
937
  }
930
- } catch (err) {
931
- errorHandler(data, err, database)
938
+ } catch (error) {
939
+ errorHandler(data, error, database)
932
940
  db.close()
933
941
  resolve([])
934
942
  return
@@ -943,7 +951,7 @@ const readDocuments = (data, database, collection) => {
943
951
  })
944
952
  }
945
953
 
946
- async function readDocs(data, database, collection, objectStore, isIndex, direction) {
954
+ async function readDocs(data, database, collection, objectStore, direction) {
947
955
  return new Promise((resolve, reject) => {
948
956
 
949
957
  let results = [], index = 0, limit
@@ -970,7 +978,7 @@ async function readDocs(data, database, collection, objectStore, isIndex, direct
970
978
  }
971
979
  if (isFilter !== false)
972
980
  results.push(value)
973
- if (isIndex && limit && limit == results.length) {
981
+ if (limit && limit == results.length) {
974
982
  results = results.slice(index, limit)
975
983
  resolve(results)
976
984
  } else