@mblaney/holster 1.0.33 → 1.0.34
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/build/holster.js +3 -3
- package/build/holster.js.map +3 -3
- package/package.json +1 -1
- package/src/store.js +54 -73
package/package.json
CHANGED
package/src/store.js
CHANGED
|
@@ -64,35 +64,46 @@ const fileSystem = opt => {
|
|
|
64
64
|
|
|
65
65
|
if (opt.indexedDB) {
|
|
66
66
|
let db
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
event
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
req.
|
|
88
|
-
|
|
67
|
+
const dbReady = new Promise((resolve, reject) => {
|
|
68
|
+
const o = indexedDB.open(dir, 1)
|
|
69
|
+
o.onupgradeneeded = event => {
|
|
70
|
+
event.target.result.createObjectStore(dir)
|
|
71
|
+
}
|
|
72
|
+
o.onerror = event => {
|
|
73
|
+
console.log(event)
|
|
74
|
+
reject(event)
|
|
75
|
+
}
|
|
76
|
+
o.onsuccess = () => {
|
|
77
|
+
db = o.result
|
|
78
|
+
// Create the root node if it doesn't exist.
|
|
79
|
+
if (db) {
|
|
80
|
+
const tx = db.transaction([dir], "readonly")
|
|
81
|
+
const req = tx.objectStore(dir).getKey("!")
|
|
82
|
+
req.onerror = () => {
|
|
83
|
+
console.log(`error getting key ${dir}/!`)
|
|
84
|
+
reject(req.error)
|
|
85
|
+
}
|
|
86
|
+
req.onsuccess = () => {
|
|
87
|
+
if (!req.result) {
|
|
88
|
+
const tx = db.transaction([dir], "readwrite")
|
|
89
|
+
const req = tx.objectStore(dir).put(root, "!")
|
|
90
|
+
req.onerror = () => {
|
|
91
|
+
console.log(`error putting root on ${dir}/!`)
|
|
92
|
+
reject(req.error)
|
|
93
|
+
}
|
|
94
|
+
req.onsuccess = () => {
|
|
95
|
+
resolve()
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
resolve()
|
|
89
99
|
}
|
|
90
100
|
}
|
|
101
|
+
} else {
|
|
102
|
+
console.log("error indexedDB not available")
|
|
103
|
+
reject(new Error("indexedDB not available"))
|
|
91
104
|
}
|
|
92
|
-
} else {
|
|
93
|
-
console.log("error indexedDB not available")
|
|
94
105
|
}
|
|
95
|
-
}
|
|
106
|
+
})
|
|
96
107
|
|
|
97
108
|
return {
|
|
98
109
|
get: (file, cb) => {
|
|
@@ -106,24 +117,14 @@ const fileSystem = opt => {
|
|
|
106
117
|
cb(null, req.result)
|
|
107
118
|
}
|
|
108
119
|
}
|
|
109
|
-
if (db) {
|
|
110
|
-
_get(file, cb)
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
120
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (db) {
|
|
117
|
-
clearInterval(interval)
|
|
121
|
+
dbReady
|
|
122
|
+
.then(() => {
|
|
118
123
|
_get(file, cb)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
clearInterval(interval)
|
|
124
|
-
cb("error indexedDB not available")
|
|
125
|
-
}
|
|
126
|
-
}, 1000)
|
|
124
|
+
})
|
|
125
|
+
.catch(err => {
|
|
126
|
+
cb(err)
|
|
127
|
+
})
|
|
127
128
|
},
|
|
128
129
|
put: (file, data, cb) => {
|
|
129
130
|
const _put = (file, data, cb) => {
|
|
@@ -136,24 +137,14 @@ const fileSystem = opt => {
|
|
|
136
137
|
cb(null)
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
|
-
if (db) {
|
|
140
|
-
_put(file, data, cb)
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
140
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (db) {
|
|
147
|
-
clearInterval(interval)
|
|
141
|
+
dbReady
|
|
142
|
+
.then(() => {
|
|
148
143
|
_put(file, data, cb)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
clearInterval(interval)
|
|
154
|
-
cb("error indexedDB not available")
|
|
155
|
-
}
|
|
156
|
-
}, 1000)
|
|
144
|
+
})
|
|
145
|
+
.catch(err => {
|
|
146
|
+
cb(err)
|
|
147
|
+
})
|
|
157
148
|
},
|
|
158
149
|
list: cb => {
|
|
159
150
|
const _list = cb => {
|
|
@@ -165,25 +156,15 @@ const fileSystem = opt => {
|
|
|
165
156
|
cb()
|
|
166
157
|
}
|
|
167
158
|
}
|
|
168
|
-
if (db) {
|
|
169
|
-
_list(cb)
|
|
170
|
-
return
|
|
171
|
-
}
|
|
172
159
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (db) {
|
|
176
|
-
clearInterval(interval)
|
|
160
|
+
dbReady
|
|
161
|
+
.then(() => {
|
|
177
162
|
_list(cb)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (retry++ > 5) {
|
|
182
|
-
clearInterval(interval)
|
|
183
|
-
console.log("error indexedDB not available")
|
|
163
|
+
})
|
|
164
|
+
.catch(err => {
|
|
165
|
+
console.log("error indexedDB not available:", err)
|
|
184
166
|
cb()
|
|
185
|
-
}
|
|
186
|
-
}, 1000)
|
|
167
|
+
})
|
|
187
168
|
},
|
|
188
169
|
}
|
|
189
170
|
}
|