@knowlearning/agents 0.4.5 → 0.4.7
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/agents/generic.js +14 -16
- package/package.json +1 -1
package/agents/generic.js
CHANGED
|
@@ -14,10 +14,6 @@ function sanitizeJSONPatchPathSegment(s) {
|
|
|
14
14
|
else return s
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function copy(value) {
|
|
18
|
-
return JSON.parse(JSON.stringify(value))
|
|
19
|
-
}
|
|
20
|
-
|
|
21
17
|
export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fetch, applyPatch, login, logout, reboot }) {
|
|
22
18
|
let ws
|
|
23
19
|
let user
|
|
@@ -40,11 +36,10 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
40
36
|
let lastSentSI = -1
|
|
41
37
|
let lastHeartbeat
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const patches = new MutableProxy({}, patch => queueMessage({scope: 'patches', patch}))
|
|
39
|
+
const subscriptions = mutate('subscriptions', false)
|
|
40
|
+
const uploads = mutate('uploads', false)
|
|
41
|
+
const downloads = mutate('downloads', false)
|
|
42
|
+
const patches = mutate('patches', false)
|
|
48
43
|
|
|
49
44
|
log('INITIALIZING AGENT CONNECTION')
|
|
50
45
|
initWS()
|
|
@@ -219,10 +214,14 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
219
214
|
keyToSubscriptionId[k] = id
|
|
220
215
|
watchers[k] = []
|
|
221
216
|
states[k] = new Promise(async resolve => {
|
|
222
|
-
subscriptions[id] = { scope, ii: null, session }
|
|
223
217
|
|
|
224
|
-
|
|
225
|
-
|
|
218
|
+
subscriptions[id] = {
|
|
219
|
+
session,
|
|
220
|
+
domain: d,
|
|
221
|
+
user: u,
|
|
222
|
+
scope,
|
|
223
|
+
ii: null
|
|
224
|
+
}
|
|
226
225
|
|
|
227
226
|
const { ii, state } = await lastMessageResponse()
|
|
228
227
|
subscriptions[id].ii = ii
|
|
@@ -344,10 +343,9 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
344
343
|
return interact('claims', [{ op: 'add', path: [domain], value: null }])
|
|
345
344
|
}
|
|
346
345
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
return new MutableProxy(initial, patch => interact(scope, patch))
|
|
346
|
+
function mutate(scope, initialize=true) {
|
|
347
|
+
const mp = s => new MutableProxy(s || {}, patch => interact(scope, patch))
|
|
348
|
+
return initialize ? state.then(mp) : mp({})
|
|
351
349
|
}
|
|
352
350
|
|
|
353
351
|
function reset(scope) {
|