@mblaney/holster 1.0.32 → 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/holster.js +1 -1
- package/src/store.js +54 -73
- package/src/user.js +4 -3
- package/src/wire.js +3 -3
- package/test/holster.user.get.test.js +1 -0
- package/test/holster.user.lex.test.js +1 -0
- package/test/holster.user.off.test.js +1 -0
- package/test/holster.user.on.test.js +6 -1
- package/test/holster.user.put.test.js +1 -0
- package/test/system/user-chained-on.test.js +5 -1
- package/test/system/user-concurrent-listeners.test.js +1 -0
- package/test/system/user-listener-before-data.test.js +1 -0
- package/test/user.test.js +1 -1
package/package.json
CHANGED
package/src/holster.js
CHANGED
|
@@ -9,7 +9,7 @@ const Holster = opt => {
|
|
|
9
9
|
else if (!utils.obj.is(opt)) opt = {}
|
|
10
10
|
|
|
11
11
|
const wire = Wire(opt)
|
|
12
|
-
const user = User(
|
|
12
|
+
const user = User(opt, wire)
|
|
13
13
|
// Map callbacks since the user's callback is not passed to wire.on.
|
|
14
14
|
const map = new Map()
|
|
15
15
|
// Allow concurrent calls to the api by storing each context.
|
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
|
}
|
package/src/user.js
CHANGED
|
@@ -5,6 +5,7 @@ import {userPublicKey, userSignature} from "./utils.js"
|
|
|
5
5
|
|
|
6
6
|
const User = (opt, wire) => {
|
|
7
7
|
if (!wire) wire = Wire(opt)
|
|
8
|
+
const wait = opt?.wait ?? 5000
|
|
8
9
|
let pubs = []
|
|
9
10
|
let creating = false
|
|
10
11
|
let authing = false
|
|
@@ -75,7 +76,7 @@ const User = (opt, wire) => {
|
|
|
75
76
|
|
|
76
77
|
done(null)
|
|
77
78
|
},
|
|
78
|
-
{wait:
|
|
79
|
+
{wait: wait},
|
|
79
80
|
)
|
|
80
81
|
}
|
|
81
82
|
|
|
@@ -102,7 +103,7 @@ const User = (opt, wire) => {
|
|
|
102
103
|
pubs = Object.keys(data)
|
|
103
104
|
next()
|
|
104
105
|
},
|
|
105
|
-
{wait:
|
|
106
|
+
{wait: wait},
|
|
106
107
|
)
|
|
107
108
|
}
|
|
108
109
|
|
|
@@ -182,7 +183,7 @@ const User = (opt, wire) => {
|
|
|
182
183
|
})
|
|
183
184
|
})
|
|
184
185
|
},
|
|
185
|
-
{wait:
|
|
186
|
+
{wait: wait},
|
|
186
187
|
)
|
|
187
188
|
},
|
|
188
189
|
auth: (username, password, cb) => {
|
package/src/wire.js
CHANGED
|
@@ -589,11 +589,11 @@ const Wire = opt => {
|
|
|
589
589
|
return
|
|
590
590
|
}
|
|
591
591
|
|
|
592
|
-
const processMessage = () => {
|
|
592
|
+
const processMessage = async () => {
|
|
593
593
|
dup.track(msg["#"])
|
|
594
594
|
|
|
595
595
|
if (msg.get) get(msg, send)
|
|
596
|
-
if (msg.put) put(msg, send)
|
|
596
|
+
if (msg.put) await put(msg, send)
|
|
597
597
|
send(data, isBinary)
|
|
598
598
|
|
|
599
599
|
const id = msg["@"]
|
|
@@ -807,7 +807,7 @@ const Wire = opt => {
|
|
|
807
807
|
if (Object.keys(filteredPut).length > 0) {
|
|
808
808
|
// Create filtered message for Ham.mix with original message ID
|
|
809
809
|
const filteredMsg = {put: filteredPut, "#": msg["#"]}
|
|
810
|
-
put(filteredMsg, send)
|
|
810
|
+
await put(filteredMsg, send)
|
|
811
811
|
}
|
|
812
812
|
}
|
|
813
813
|
|
|
@@ -6,7 +6,12 @@ import Holster from "../src/holster.js"
|
|
|
6
6
|
|
|
7
7
|
describe("holster.user.on", () => {
|
|
8
8
|
const wss = new Server("ws://localhost:1234")
|
|
9
|
-
const holster = Holster({
|
|
9
|
+
const holster = Holster({
|
|
10
|
+
file: "test/holster.user.on",
|
|
11
|
+
wss: wss,
|
|
12
|
+
maxAge: 100,
|
|
13
|
+
wait: 500,
|
|
14
|
+
})
|
|
10
15
|
const user = holster.user()
|
|
11
16
|
|
|
12
17
|
test("user create", (t, done) => {
|
|
@@ -6,7 +6,11 @@ import Holster from "../../src/holster.js"
|
|
|
6
6
|
|
|
7
7
|
describe("system - user chained get with on", () => {
|
|
8
8
|
const wss = new Server("ws://localhost:9012")
|
|
9
|
-
const holster = Holster({
|
|
9
|
+
const holster = Holster({
|
|
10
|
+
file: "test/system/user-chained-on",
|
|
11
|
+
wss: wss,
|
|
12
|
+
wait: 500,
|
|
13
|
+
})
|
|
10
14
|
const user = holster.user()
|
|
11
15
|
|
|
12
16
|
test("user create and auth", (t, done) => {
|
package/test/user.test.js
CHANGED
|
@@ -6,7 +6,7 @@ import User from "../src/user.js"
|
|
|
6
6
|
|
|
7
7
|
describe("user", () => {
|
|
8
8
|
const wss = new Server("ws://localhost:1234")
|
|
9
|
-
const user = User({file: "test/user", wss: wss, maxAge: 100})
|
|
9
|
+
const user = User({file: "test/user", wss: wss, maxAge: 100, wait: 500})
|
|
10
10
|
|
|
11
11
|
test("create", (t, done) => {
|
|
12
12
|
user.create("alice", "password", err => {
|