@cocreate/indexeddb 1.4.4 → 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 +17 -0
- package/package.json +4 -4
- package/src/index.js +38 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
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
|
+
|
|
11
|
+
## [1.4.5](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.4.4...v1.4.5) (2022-11-28)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* bump dependencies ([5b5a05d](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/5b5a05d7cfeb5a8ff7b4a86cd4668604f94f7e95))
|
|
17
|
+
|
|
1
18
|
## [1.4.4](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.4.3...v1.4.4) (2022-11-28)
|
|
2
19
|
|
|
3
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/indexeddb",
|
|
3
|
-
"version": "1.4.
|
|
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.
|
|
65
|
-
"@cocreate/hosting": "^1.6.
|
|
66
|
-
"@cocreate/utils": "^1.
|
|
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
|
-
|
|
714
|
-
|
|
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
|
-
|
|
739
|
-
|
|
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
|
|
882
|
-
if (
|
|
883
|
-
|
|
891
|
+
let direction = data.filter.sort[0].direction
|
|
892
|
+
if (direction == -1)
|
|
893
|
+
direction = 'prev'
|
|
884
894
|
else
|
|
885
|
-
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
"
|
|
1028
|
-
|
|
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,
|