@cocreate/indexeddb 1.4.5 → 1.4.6

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,13 @@
1
+ ## [1.4.6](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.4.5...v1.4.6) (2022-12-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump @cocreat/utils ([4b4801f](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/4b4801f86ee329182683e96a174eadb8411a64dd))
7
+ * export default ([33e1721](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/33e17219877f692a71d8b8f876751642b157b7b0))
8
+ * if condition for readDocument _id, if condition for count results to prevent error. sortType renamed to direction ([5b3d817](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/5b3d8170a06f001bcd71d00ca9d4284c4039ffaa))
9
+ * if data.organization_id add to document ([55e7ad7](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/55e7ad70c64f0848f99343a73fff0db8376c7938))
10
+
1
11
  ## [1.4.5](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.4.4...v1.4.5) (2022-11-28)
2
12
 
3
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/indexeddb",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
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.8",
65
- "@cocreate/hosting": "^1.6.7",
66
- "@cocreate/utils": "^1.12.6"
64
+ "@cocreate/docs": "^1.4.9",
65
+ "@cocreate/hosting": "^1.6.8",
66
+ "@cocreate/utils": "^1.13.0"
67
67
  }
68
68
  }
package/src/index.js CHANGED
@@ -710,8 +710,9 @@ function runDocs({action, data, objectStore, documents, filterDocs, database, co
710
710
 
711
711
  if (action == 'updateDocument' || action == 'deleteDocument') {
712
712
  if (doc._id) {
713
- doc['organization_id'] = data.organization_id
714
- doc['modified'] = {on: data.timeStamp, by: data.user || data.clientId}
713
+ if (data.organization_id)
714
+ doc['organization_id'] = data.organization_id
715
+ doc['modified'] = {on: data.timeStamp, by: data.user_id || data.clientId}
715
716
 
716
717
  updateDoc(action, data, doc, objectStore, database, collection).then((doc) => {
717
718
  doc.db = 'indexeddb'
@@ -735,13 +736,20 @@ function runDocs({action, data, objectStore, documents, filterDocs, database, co
735
736
  doc['_id'] = ObjectId()
736
737
  doc = dotNotationToObject(doc)
737
738
 
738
- doc['organization_id'] = data.organization_id
739
- doc['created'] = {on: data.timeStamp, by: data.user || data.clientId}
739
+ if (data.organization_id)
740
+ doc['organization_id'] = data.organization_id
741
+ doc['created'] = {on: data.timeStamp, by: data.user_id || data.clientId}
740
742
  request = objectStore.add(doc);
741
743
  }
742
744
 
743
- if (action == 'readDocument') {
745
+ if (action == 'readDocument' && doc._id) {
744
746
  request = objectStore.get(doc._id);
747
+ } else {
748
+ docsLength -= 1
749
+ errorHandler(data, {message: 'requires _id', document: doc}, database, objectStore.name)
750
+ if (!docsLength) {
751
+ resolve()
752
+ }
745
753
  }
746
754
 
747
755
  request.onsuccess = function() {
@@ -860,12 +868,14 @@ const readDocuments = (data, database, collection) => {
860
868
  try {
861
869
  let transaction = db.transaction([collection], "readonly");
862
870
  let objectStore = transaction.objectStore(collection);
863
-
864
- let count = objectStore.count();
865
- count.onsuccess = function() {
866
- data.filter.count = count.result
867
- }
868
871
 
872
+ if (data.filter) {
873
+ let count = objectStore.count();
874
+ count.onsuccess = function() {
875
+ data.filter.count = count.result
876
+ }
877
+ }
878
+
869
879
  let isIndex = false
870
880
  let indexName;
871
881
  if (data.filter && data.filter.sort && data.filter.sort[0] && data.filter.sort[0].name) {
@@ -878,11 +888,11 @@ const readDocuments = (data, database, collection) => {
878
888
  }
879
889
 
880
890
  if (isIndex) {
881
- let sortType = data.filter.sort[0].type
882
- if (sortType == -1)
883
- sortType = 'prev'
891
+ let direction = data.filter.sort[0].direction
892
+ if (direction == -1)
893
+ direction = 'prev'
884
894
  else
885
- sortType = 'next'
895
+ direction = 'next'
886
896
 
887
897
  let indexNames = Array.from(objectStore.indexNames)
888
898
  let indexExist = indexNames.includes(indexName)
@@ -891,17 +901,22 @@ const readDocuments = (data, database, collection) => {
891
901
  getDatabase({database, upgrade: true}).then((db2) => {
892
902
  let transaction = db2.transaction;
893
903
  let objectStore = transaction.objectStore(collection);
894
- objectStore.createIndex(indexName, indexName, {unique: false})
904
+ try {
905
+ objectStore.createIndex(indexName, indexName, {unique: false})
906
+ } catch(error) {
907
+ // console.log(error)
908
+ }
895
909
  const indexStore = objectStore.index(indexName);
896
910
 
897
- readDocs(data, database, collection, indexStore, isIndex, sortType).then((results) => {
898
- db2.close()
911
+ readDocs(data, database, collection, indexStore, isIndex, direction).then((results) => {
912
+ if (db2 && db2.close)
913
+ db2.close()
899
914
  resolve(results)
900
915
  })
901
916
  })
902
917
  } else {
903
918
  const indexStore = objectStore.index(indexName);
904
- readDocs(data, database, collection, indexStore, isIndex, sortType).then((results) => {
919
+ readDocs(data, database, collection, indexStore, isIndex, direction).then((results) => {
905
920
  db.close()
906
921
  resolve(results)
907
922
  })
@@ -928,7 +943,7 @@ const readDocuments = (data, database, collection) => {
928
943
  })
929
944
  }
930
945
 
931
- async function readDocs(data, database, collection, objectStore, isIndex, sortType) {
946
+ async function readDocs(data, database, collection, objectStore, isIndex, direction) {
932
947
  return new Promise((resolve, reject) => {
933
948
 
934
949
  let results = [], index = 0, limit
@@ -941,7 +956,7 @@ async function readDocs(data, database, collection, objectStore, isIndex, sortTy
941
956
  limit = index + limit;
942
957
  }
943
958
 
944
- const request = objectStore.openCursor(null, sortType);
959
+ const request = objectStore.openCursor(null, direction);
945
960
  request.onsuccess = function() {
946
961
  let cursor = request.result;
947
962
  if (cursor) {
@@ -1024,10 +1039,9 @@ async function generateDB(data) {
1024
1039
  },
1025
1040
  "modules": {
1026
1041
  "actions": [
1027
- "login",
1028
- "signin",
1042
+ "signIn",
1043
+ "signUp",
1029
1044
  "userCurrentOrg",
1030
- "createUser",
1031
1045
  "createOrg",
1032
1046
  "runIndustry"
1033
1047
  ],
@@ -1151,7 +1165,7 @@ function init() {
1151
1165
 
1152
1166
  init();
1153
1167
 
1154
- export {
1168
+ export default {
1155
1169
  getDatabase,
1156
1170
  createDatabase,
1157
1171
  readDatabase,