@nxtedition/deepstream.io-client-js 25.1.1 → 25.1.3
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 +49 -34
- package/src/record/record.js +5 -0
- package/src/utils/utils.js +11 -0
package/package.json
CHANGED
|
@@ -49,8 +49,8 @@ function onTimeout(subscription) {
|
|
|
49
49
|
new Error(`timeout state: ${subscription.record.name} [${current}<${expected}]`),
|
|
50
50
|
{
|
|
51
51
|
code: 'ETIMEDOUT',
|
|
52
|
-
}
|
|
53
|
-
)
|
|
52
|
+
},
|
|
53
|
+
),
|
|
54
54
|
)
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -208,9 +208,11 @@ class RecordHandler {
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
getKey(name) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
if (name.length > 8) {
|
|
212
|
+
return this._connection.hasher.h64(name)
|
|
213
|
+
}
|
|
214
|
+
const buf = this._encoder.encode(name)
|
|
215
|
+
return buf.byteLength === 8 ? utils.readBigUInt64BE(buf) : this._connection.hasher.h64Raw(buf)
|
|
214
216
|
}
|
|
215
217
|
|
|
216
218
|
/**
|
|
@@ -220,7 +222,7 @@ class RecordHandler {
|
|
|
220
222
|
getRecord(name) {
|
|
221
223
|
invariant(
|
|
222
224
|
typeof name === 'string' && name.length > 0 && name !== '[object Object]',
|
|
223
|
-
`invalid name ${name}
|
|
225
|
+
`invalid name ${name}`,
|
|
224
226
|
)
|
|
225
227
|
|
|
226
228
|
let record = this._records.get(name)
|
|
@@ -294,17 +296,22 @@ class RecordHandler {
|
|
|
294
296
|
const patching = [...this._patching.values()]
|
|
295
297
|
await Promise.race([
|
|
296
298
|
Promise.all(
|
|
297
|
-
patching.map((callbacks) => new Promise((resolve) => callbacks.push(resolve)))
|
|
299
|
+
patching.map((callbacks) => new Promise((resolve) => callbacks.push(resolve))),
|
|
298
300
|
),
|
|
299
301
|
new Promise((resolve) => {
|
|
300
|
-
patchingTimeout = timers.setTimeout(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
302
|
+
patchingTimeout = timers.setTimeout(
|
|
303
|
+
() => {
|
|
304
|
+
this._client._$onError(
|
|
305
|
+
C.TOPIC.RECORD,
|
|
306
|
+
C.EVENT.TIMEOUT,
|
|
307
|
+
Object.assign(new Error('sync patching timeout'), {
|
|
308
|
+
data: { patching, timeout },
|
|
309
|
+
}),
|
|
310
|
+
)
|
|
311
|
+
resolve(null)
|
|
312
|
+
},
|
|
313
|
+
timeout ?? 2 * 60e3,
|
|
314
|
+
)
|
|
308
315
|
}),
|
|
309
316
|
signalPromise,
|
|
310
317
|
]).finally(() => {
|
|
@@ -317,17 +324,22 @@ class RecordHandler {
|
|
|
317
324
|
const updating = [...this._updating.values()]
|
|
318
325
|
await Promise.race([
|
|
319
326
|
Promise.all(
|
|
320
|
-
updating.map((callbacks) => new Promise((resolve) => callbacks.push(resolve)))
|
|
327
|
+
updating.map((callbacks) => new Promise((resolve) => callbacks.push(resolve))),
|
|
321
328
|
),
|
|
322
329
|
new Promise((resolve) => {
|
|
323
|
-
updatingTimeout = timers.setTimeout(
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
330
|
+
updatingTimeout = timers.setTimeout(
|
|
331
|
+
() => {
|
|
332
|
+
this._client._$onError(
|
|
333
|
+
C.TOPIC.RECORD,
|
|
334
|
+
C.EVENT.TIMEOUT,
|
|
335
|
+
Object.assign(new Error('sync updating timeout'), {
|
|
336
|
+
data: { updating, timeout },
|
|
337
|
+
}),
|
|
338
|
+
)
|
|
339
|
+
resolve(null)
|
|
340
|
+
},
|
|
341
|
+
timeout ?? 2 * 60e3,
|
|
342
|
+
)
|
|
331
343
|
}),
|
|
332
344
|
signalPromise,
|
|
333
345
|
]).finally(() => {
|
|
@@ -343,14 +355,17 @@ class RecordHandler {
|
|
|
343
355
|
this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
|
|
344
356
|
}),
|
|
345
357
|
new Promise((resolve) => {
|
|
346
|
-
serverTimeout = timers.setTimeout(
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
358
|
+
serverTimeout = timers.setTimeout(
|
|
359
|
+
() => {
|
|
360
|
+
this._client._$onError(
|
|
361
|
+
C.TOPIC.RECORD,
|
|
362
|
+
C.EVENT.TIMEOUT,
|
|
363
|
+
Object.assign(new Error('sync server timeout'), { data: { token, timeout } }),
|
|
364
|
+
)
|
|
365
|
+
resolve(null)
|
|
366
|
+
},
|
|
367
|
+
timeout ?? 2 * 60e3,
|
|
368
|
+
)
|
|
354
369
|
}),
|
|
355
370
|
signalPromise,
|
|
356
371
|
]).finally(() => {
|
|
@@ -423,7 +438,7 @@ class RecordHandler {
|
|
|
423
438
|
timeout: 2 * 60e3,
|
|
424
439
|
dataOnly: true,
|
|
425
440
|
},
|
|
426
|
-
...args
|
|
441
|
+
...args,
|
|
427
442
|
)
|
|
428
443
|
}
|
|
429
444
|
|
|
@@ -499,7 +514,7 @@ class RecordHandler {
|
|
|
499
514
|
{
|
|
500
515
|
timeout: 2 * 60e3,
|
|
501
516
|
},
|
|
502
|
-
...args
|
|
517
|
+
...args,
|
|
503
518
|
)
|
|
504
519
|
}
|
|
505
520
|
|
package/src/record/record.js
CHANGED
package/src/utils/utils.js
CHANGED
|
@@ -174,3 +174,14 @@ export function removeAbortListener(signal, handler) {
|
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
+
|
|
178
|
+
export function readBigUInt64BE(buf, offset = 0) {
|
|
179
|
+
const first = buf[offset]
|
|
180
|
+
const last = buf[offset + 7]
|
|
181
|
+
|
|
182
|
+
const hi = first * 2 ** 24 + buf[++offset] * 2 ** 16 + buf[++offset] * 2 ** 8 + buf[++offset]
|
|
183
|
+
|
|
184
|
+
const lo = buf[++offset] * 2 ** 24 + buf[++offset] * 2 ** 16 + buf[++offset] * 2 ** 8 + last
|
|
185
|
+
|
|
186
|
+
return (BigInt(hi) << 32n) + BigInt(lo)
|
|
187
|
+
}
|