@nxtedition/deepstream.io-client-js 23.4.61 → 24.0.0
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/package.json +1 -1
- package/src/record/record-handler.js +77 -69
- package/src/record/record.js +20 -7
- package/src/utils/utils.js +10 -6
package/package.json
CHANGED
|
@@ -13,6 +13,46 @@ const timers = require('../utils/timers')
|
|
|
13
13
|
|
|
14
14
|
const kEmpty = Symbol('kEmpty')
|
|
15
15
|
|
|
16
|
+
function noop() {}
|
|
17
|
+
|
|
18
|
+
function onUpdate(record, subscription) {
|
|
19
|
+
if (subscription.state && record.state < subscription.state) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (subscription.timeout) {
|
|
24
|
+
timers.clearTimeout(subscription.timeout)
|
|
25
|
+
subscription.timeout = null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const data = subscription.path ? record.get(subscription.path) : record.data
|
|
29
|
+
|
|
30
|
+
if (subscription.dataOnly) {
|
|
31
|
+
if (data !== subscription.data) {
|
|
32
|
+
subscription.data = data
|
|
33
|
+
subscription.subscriber.next(data)
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
subscription.subscriber.next({
|
|
37
|
+
name: record.name,
|
|
38
|
+
version: record.version,
|
|
39
|
+
state: record.state,
|
|
40
|
+
data,
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function onTimeout(subscription) {
|
|
46
|
+
const expected = C.RECORD_STATE_NAME[subscription.state]
|
|
47
|
+
const current = C.RECORD_STATE_NAME[subscription.record.state]
|
|
48
|
+
|
|
49
|
+
subscription.subscriber.error(
|
|
50
|
+
Object.assign(new Error(`timeout ${subscription.record.name} [${current}<${expected}]`), {
|
|
51
|
+
code: 'ETIMEDOUT',
|
|
52
|
+
})
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
16
56
|
class RecordHandler {
|
|
17
57
|
constructor(options, connection, client) {
|
|
18
58
|
this.JSON = jsonPath
|
|
@@ -261,7 +301,7 @@ class RecordHandler {
|
|
|
261
301
|
let path
|
|
262
302
|
let state = defaults ? defaults.state : undefined
|
|
263
303
|
let signal
|
|
264
|
-
let
|
|
304
|
+
let timeout = defaults ? defaults.timeout : undefined
|
|
265
305
|
let dataOnly = defaults ? defaults.dataOnly : undefined
|
|
266
306
|
|
|
267
307
|
let idx = 0
|
|
@@ -282,7 +322,7 @@ class RecordHandler {
|
|
|
282
322
|
}
|
|
283
323
|
|
|
284
324
|
if (options.timeout != null) {
|
|
285
|
-
|
|
325
|
+
timeout = options.timeout
|
|
286
326
|
}
|
|
287
327
|
|
|
288
328
|
if (options.path != null) {
|
|
@@ -302,84 +342,52 @@ class RecordHandler {
|
|
|
302
342
|
state = C.RECORD_STATE[state.toUpperCase()]
|
|
303
343
|
}
|
|
304
344
|
|
|
305
|
-
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
return rxjs.throwError(() => new utils.AbortError())
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
return new rxjs.Observable((o) => {
|
|
324
|
-
let timeoutHandle
|
|
325
|
-
let prevData = kEmpty
|
|
326
|
-
|
|
327
|
-
const onUpdate = (record) => {
|
|
328
|
-
if (state && record.state < state) {
|
|
329
|
-
return
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (timeoutHandle) {
|
|
333
|
-
timers.clearTimeout(timeoutHandle)
|
|
334
|
-
timeoutHandle = null
|
|
335
|
-
}
|
|
345
|
+
return new rxjs.Observable((subscriber) => {
|
|
346
|
+
const subscription = {
|
|
347
|
+
subscriber,
|
|
348
|
+
path,
|
|
349
|
+
state,
|
|
350
|
+
signal,
|
|
351
|
+
dataOnly,
|
|
352
|
+
data: kEmpty,
|
|
353
|
+
timeout: null,
|
|
354
|
+
abort: noop,
|
|
355
|
+
unsubscribe() {
|
|
356
|
+
if (this.timeout) {
|
|
357
|
+
timers.clearTimeout(this.timeout)
|
|
358
|
+
this.timeout = null
|
|
359
|
+
}
|
|
336
360
|
|
|
337
|
-
|
|
361
|
+
if (this.ignal) {
|
|
362
|
+
utils.removeAbortListener(this.signal, this.abort)
|
|
363
|
+
this.signal = null
|
|
364
|
+
this.abort = noop
|
|
365
|
+
}
|
|
338
366
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
367
|
+
if (this.record) {
|
|
368
|
+
this.record.unsubscribe(onUpdate, this)
|
|
369
|
+
this.record.unref()
|
|
370
|
+
this.record = null
|
|
343
371
|
}
|
|
344
|
-
}
|
|
345
|
-
o.next({
|
|
346
|
-
name: record.name,
|
|
347
|
-
version: record.version,
|
|
348
|
-
data: nextData,
|
|
349
|
-
state: record.state,
|
|
350
|
-
})
|
|
351
|
-
}
|
|
372
|
+
},
|
|
352
373
|
}
|
|
353
374
|
|
|
354
|
-
const record = this.getRecord(name).subscribe(onUpdate)
|
|
355
|
-
|
|
356
|
-
if (
|
|
357
|
-
|
|
358
|
-
const expected = C.RECORD_STATE_NAME[state]
|
|
359
|
-
const current = C.RECORD_STATE_NAME[record.state]
|
|
360
|
-
o.error(
|
|
361
|
-
Object.assign(
|
|
362
|
-
new Error(
|
|
363
|
-
`timeout after ${timeoutValue / 1e3}s: ${record.name} [${current}<${expected}]`
|
|
364
|
-
),
|
|
365
|
-
{ code: 'ETIMEDOUT' }
|
|
366
|
-
)
|
|
367
|
-
)
|
|
368
|
-
}, timeoutValue)
|
|
375
|
+
const record = this.getRecord(name).subscribe(onUpdate, subscription)
|
|
376
|
+
|
|
377
|
+
if (timeout && subscription.state && record.state < subscription.state) {
|
|
378
|
+
subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
|
|
369
379
|
}
|
|
370
380
|
|
|
371
381
|
if (record.version) {
|
|
372
|
-
onUpdate(record)
|
|
382
|
+
onUpdate(record, subscription)
|
|
373
383
|
}
|
|
374
384
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
return () => {
|
|
380
|
-
record.unsubscribe(onUpdate).unref()
|
|
381
|
-
utils.removeAbortListener(signal, abort)
|
|
385
|
+
if (subscription.signal) {
|
|
386
|
+
subscription.abort = () => subscription.subscriber.error(new utils.AbortError())
|
|
387
|
+
utils.addAbortListener(subscription.signal, subscription.abort)
|
|
382
388
|
}
|
|
389
|
+
|
|
390
|
+
return subscription
|
|
383
391
|
})
|
|
384
392
|
}
|
|
385
393
|
|
package/src/record/record.js
CHANGED
|
@@ -64,26 +64,36 @@ class Record {
|
|
|
64
64
|
return this
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
subscribe(fn) {
|
|
67
|
+
subscribe(fn, opaque = null) {
|
|
68
68
|
if (this._emitting) {
|
|
69
69
|
this._subscriptions = this._subscriptions.slice()
|
|
70
70
|
this._emitting = false
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
this._subscriptions.push(fn)
|
|
73
|
+
this._subscriptions.push(fn, opaque)
|
|
74
74
|
|
|
75
75
|
return this
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
unsubscribe(fn) {
|
|
78
|
+
unsubscribe(fn, opaque = null) {
|
|
79
79
|
if (this._emitting) {
|
|
80
80
|
this._subscriptions = this._subscriptions.slice()
|
|
81
81
|
this._emitting = false
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
let idx = -1
|
|
85
|
+
|
|
86
|
+
const arr = this._subscriptions
|
|
87
|
+
const len = arr.length
|
|
88
|
+
for (let n = 0; n < len; n += 2) {
|
|
89
|
+
if (arr[n + 0] === fn && arr[n + 1] === opaque) {
|
|
90
|
+
idx = n
|
|
91
|
+
break
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
85
95
|
if (idx !== -1) {
|
|
86
|
-
this._subscriptions.splice(idx,
|
|
96
|
+
this._subscriptions.splice(idx, 2)
|
|
87
97
|
}
|
|
88
98
|
|
|
89
99
|
return this
|
|
@@ -417,9 +427,12 @@ class Record {
|
|
|
417
427
|
_emitUpdate() {
|
|
418
428
|
this._emitting = true
|
|
419
429
|
try {
|
|
420
|
-
|
|
430
|
+
const arr = this._subscriptions
|
|
431
|
+
const len = arr.length
|
|
432
|
+
|
|
433
|
+
for (let n = 0; n < len; n += 2) {
|
|
421
434
|
try {
|
|
422
|
-
|
|
435
|
+
arr[n + 0](this, arr[n + 1])
|
|
423
436
|
} catch (err) {
|
|
424
437
|
this._error(
|
|
425
438
|
C.EVENT.USER_ERROR,
|
package/src/utils/utils.js
CHANGED
|
@@ -143,13 +143,17 @@ module.exports.addAbortListener = function addAbortListener(signal, handler) {
|
|
|
143
143
|
return
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
abortSignals.
|
|
150
|
-
|
|
146
|
+
if (signal.aborted) {
|
|
147
|
+
queueMicrotask(handler)
|
|
148
|
+
} else {
|
|
149
|
+
let handlers = abortSignals.get(signal)
|
|
150
|
+
if (!handlers) {
|
|
151
|
+
handlers = []
|
|
152
|
+
abortSignals.set(signal, handlers)
|
|
153
|
+
signal.addEventListener('abort', onAbort)
|
|
154
|
+
}
|
|
155
|
+
handlers.push(handler)
|
|
151
156
|
}
|
|
152
|
-
handlers.push(handler)
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
module.exports.removeAbortListener = function removeAbortListener(signal, handler) {
|