@cubejs-client/ws-transport 0.35.0 → 0.35.23
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/dist/cubejs-client-ws-transport.esm.js +1 -35
- package/dist/cubejs-client-ws-transport.esm.js.map +1 -1
- package/dist/cubejs-client-ws-transport.js +5 -63
- package/dist/cubejs-client-ws-transport.js.map +1 -1
- package/dist/cubejs-client-ws-transport.umd.js +5 -63
- package/dist/cubejs-client-ws-transport.umd.js.map +1 -1
- package/package.json +3 -3
|
@@ -3243,7 +3243,6 @@
|
|
|
3243
3243
|
var browser = ws;
|
|
3244
3244
|
|
|
3245
3245
|
var _excluded = ["baseRequestId"];
|
|
3246
|
-
|
|
3247
3246
|
/**
|
|
3248
3247
|
* @title @cubejs-client/ws-transport
|
|
3249
3248
|
* @permalink /@cubejs-client-ws-transport
|
|
@@ -3255,18 +3254,13 @@
|
|
|
3255
3254
|
var WebSocketTransportResult = /*#__PURE__*/function () {
|
|
3256
3255
|
function WebSocketTransportResult(_ref) {
|
|
3257
3256
|
var status = _ref.status,
|
|
3258
|
-
|
|
3259
|
-
|
|
3257
|
+
message = _ref.message;
|
|
3260
3258
|
_classCallCheck(this, WebSocketTransportResult);
|
|
3261
|
-
|
|
3262
3259
|
_defineProperty(this, "status", void 0);
|
|
3263
|
-
|
|
3264
3260
|
_defineProperty(this, "result", void 0);
|
|
3265
|
-
|
|
3266
3261
|
this.status = status;
|
|
3267
3262
|
this.result = message;
|
|
3268
3263
|
}
|
|
3269
|
-
|
|
3270
3264
|
_createClass(WebSocketTransportResult, [{
|
|
3271
3265
|
key: "json",
|
|
3272
3266
|
value: function () {
|
|
@@ -3276,7 +3270,6 @@
|
|
|
3276
3270
|
switch (_context.prev = _context.next) {
|
|
3277
3271
|
case 0:
|
|
3278
3272
|
return _context.abrupt("return", this.result);
|
|
3279
|
-
|
|
3280
3273
|
case 1:
|
|
3281
3274
|
case "end":
|
|
3282
3275
|
return _context.stop();
|
|
@@ -3284,11 +3277,9 @@
|
|
|
3284
3277
|
}
|
|
3285
3278
|
}, _callee, this);
|
|
3286
3279
|
}));
|
|
3287
|
-
|
|
3288
3280
|
function json() {
|
|
3289
3281
|
return _json.apply(this, arguments);
|
|
3290
3282
|
}
|
|
3291
|
-
|
|
3292
3283
|
return json;
|
|
3293
3284
|
}()
|
|
3294
3285
|
}, {
|
|
@@ -3306,7 +3297,6 @@
|
|
|
3306
3297
|
switch (_context2.prev = _context2.next) {
|
|
3307
3298
|
case 0:
|
|
3308
3299
|
return _context2.abrupt("return", typeof this.result === 'string' ? this.result : JSON.stringify(this.result));
|
|
3309
|
-
|
|
3310
3300
|
case 1:
|
|
3311
3301
|
case "end":
|
|
3312
3302
|
return _context2.stop();
|
|
@@ -3314,44 +3304,30 @@
|
|
|
3314
3304
|
}
|
|
3315
3305
|
}, _callee2, this);
|
|
3316
3306
|
}));
|
|
3317
|
-
|
|
3318
3307
|
function text() {
|
|
3319
3308
|
return _text.apply(this, arguments);
|
|
3320
3309
|
}
|
|
3321
|
-
|
|
3322
3310
|
return text;
|
|
3323
3311
|
}()
|
|
3324
3312
|
}]);
|
|
3325
|
-
|
|
3326
3313
|
return WebSocketTransportResult;
|
|
3327
3314
|
}();
|
|
3328
|
-
|
|
3329
3315
|
var WebSocketTransport = /*#__PURE__*/function () {
|
|
3330
3316
|
function WebSocketTransport(_ref2) {
|
|
3331
3317
|
var authorization = _ref2.authorization,
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3318
|
+
apiUrl = _ref2.apiUrl,
|
|
3319
|
+
heartBeatInterval = _ref2.heartBeatInterval,
|
|
3320
|
+
hearBeatInterval = _ref2.hearBeatInterval;
|
|
3336
3321
|
_classCallCheck(this, WebSocketTransport);
|
|
3337
|
-
|
|
3338
3322
|
_defineProperty(this, "apiUrl", void 0);
|
|
3339
|
-
|
|
3340
3323
|
_defineProperty(this, "heartBeatInterval", 60);
|
|
3341
|
-
|
|
3342
3324
|
_defineProperty(this, "token", void 0);
|
|
3343
|
-
|
|
3344
3325
|
_defineProperty(this, "ws", null);
|
|
3345
|
-
|
|
3346
3326
|
_defineProperty(this, "messageCounter", 1);
|
|
3347
|
-
|
|
3348
3327
|
_defineProperty(this, "messageIdToSubscription", {});
|
|
3349
|
-
|
|
3350
3328
|
_defineProperty(this, "messageQueue", []);
|
|
3351
|
-
|
|
3352
3329
|
this.token = authorization;
|
|
3353
3330
|
this.apiUrl = apiUrl;
|
|
3354
|
-
|
|
3355
3331
|
if (heartBeatInterval) {
|
|
3356
3332
|
this.heartBeatInterval = heartBeatInterval;
|
|
3357
3333
|
} else if (hearBeatInterval) {
|
|
@@ -3359,7 +3335,6 @@
|
|
|
3359
3335
|
this.heartBeatInterval = hearBeatInterval;
|
|
3360
3336
|
}
|
|
3361
3337
|
}
|
|
3362
|
-
|
|
3363
3338
|
_createClass(WebSocketTransport, [{
|
|
3364
3339
|
key: "authorization",
|
|
3365
3340
|
get: function get() {
|
|
@@ -3367,7 +3342,6 @@
|
|
|
3367
3342
|
},
|
|
3368
3343
|
set: function set(token) {
|
|
3369
3344
|
this.token = token;
|
|
3370
|
-
|
|
3371
3345
|
if (this.ws) {
|
|
3372
3346
|
this.ws.close();
|
|
3373
3347
|
}
|
|
@@ -3383,7 +3357,6 @@
|
|
|
3383
3357
|
if (this.ws) {
|
|
3384
3358
|
this.ws.close();
|
|
3385
3359
|
}
|
|
3386
|
-
|
|
3387
3360
|
case 1:
|
|
3388
3361
|
case "end":
|
|
3389
3362
|
return _context3.stop();
|
|
@@ -3391,40 +3364,32 @@
|
|
|
3391
3364
|
}
|
|
3392
3365
|
}, _callee3, this);
|
|
3393
3366
|
}));
|
|
3394
|
-
|
|
3395
3367
|
function close() {
|
|
3396
3368
|
return _close.apply(this, arguments);
|
|
3397
3369
|
}
|
|
3398
|
-
|
|
3399
3370
|
return close;
|
|
3400
3371
|
}()
|
|
3401
3372
|
}, {
|
|
3402
3373
|
key: "initSocket",
|
|
3403
3374
|
value: function initSocket() {
|
|
3404
3375
|
var _this = this;
|
|
3405
|
-
|
|
3406
3376
|
if (this.ws) {
|
|
3407
3377
|
return this.ws.initPromise;
|
|
3408
3378
|
}
|
|
3409
|
-
|
|
3410
3379
|
var ws = new browser(this.apiUrl);
|
|
3411
3380
|
ws.messageIdSent = {};
|
|
3412
|
-
|
|
3413
3381
|
ws.sendMessage = function (message) {
|
|
3414
3382
|
if (!message.messageId || message.messageId && !ws.messageIdSent[message.messageId]) {
|
|
3415
3383
|
ws.send(JSON.stringify(message));
|
|
3416
3384
|
ws.messageIdSent[message.messageId] = true;
|
|
3417
3385
|
}
|
|
3418
3386
|
};
|
|
3419
|
-
|
|
3420
3387
|
ws.sendQueue = function () {
|
|
3421
3388
|
_this.messageQueue.forEach(function (message) {
|
|
3422
3389
|
return ws.sendMessage(message);
|
|
3423
3390
|
});
|
|
3424
|
-
|
|
3425
3391
|
_this.messageQueue = [];
|
|
3426
3392
|
};
|
|
3427
|
-
|
|
3428
3393
|
ws.reconcile = function () {
|
|
3429
3394
|
if (new Date().getTime() - ws.lastMessageTimestamp.getTime() > 4 * _this.heartBeatInterval * 1000) {
|
|
3430
3395
|
ws.close();
|
|
@@ -3435,7 +3400,6 @@
|
|
|
3435
3400
|
});
|
|
3436
3401
|
}
|
|
3437
3402
|
};
|
|
3438
|
-
|
|
3439
3403
|
ws.lastMessageTimestamp = new Date();
|
|
3440
3404
|
ws.initPromise = new Promise(function (resolve) {
|
|
3441
3405
|
ws.onopen = function () {
|
|
@@ -3443,11 +3407,9 @@
|
|
|
3443
3407
|
authorization: _this.authorization
|
|
3444
3408
|
});
|
|
3445
3409
|
};
|
|
3446
|
-
|
|
3447
3410
|
ws.onmessage = function (event) {
|
|
3448
3411
|
ws.lastMessageTimestamp = new Date();
|
|
3449
3412
|
var message = JSON.parse(event.data);
|
|
3450
|
-
|
|
3451
3413
|
if (message.handshake) {
|
|
3452
3414
|
ws.reconcile();
|
|
3453
3415
|
ws.reconcileTimer = setInterval(function () {
|
|
@@ -3456,33 +3418,26 @@
|
|
|
3456
3418
|
}, _this.heartBeatInterval * 1000);
|
|
3457
3419
|
resolve();
|
|
3458
3420
|
}
|
|
3459
|
-
|
|
3460
3421
|
if (_this.messageIdToSubscription[message.messageId]) {
|
|
3461
3422
|
_this.messageIdToSubscription[message.messageId].callback(new WebSocketTransportResult(message));
|
|
3462
3423
|
}
|
|
3463
|
-
|
|
3464
3424
|
ws.sendQueue();
|
|
3465
3425
|
};
|
|
3466
|
-
|
|
3467
3426
|
ws.onclose = function () {
|
|
3468
3427
|
if (ws && ws.readyState !== browser.CLOSED && ws.readyState !== browser.CLOSING) {
|
|
3469
3428
|
ws.close();
|
|
3470
3429
|
}
|
|
3471
|
-
|
|
3472
3430
|
if (ws.reconcileTimer) {
|
|
3473
3431
|
clearInterval(ws.reconcileTimer);
|
|
3474
3432
|
ws.reconcileTimer = null;
|
|
3475
3433
|
}
|
|
3476
|
-
|
|
3477
3434
|
if (_this.ws === ws) {
|
|
3478
3435
|
_this.ws = null;
|
|
3479
|
-
|
|
3480
3436
|
if (Object.keys(_this.messageIdToSubscription).length) {
|
|
3481
3437
|
_this.initSocket();
|
|
3482
3438
|
}
|
|
3483
3439
|
}
|
|
3484
3440
|
};
|
|
3485
|
-
|
|
3486
3441
|
ws.onerror = ws.onclose;
|
|
3487
3442
|
});
|
|
3488
3443
|
this.ws = ws;
|
|
@@ -3492,7 +3447,6 @@
|
|
|
3492
3447
|
key: "sendMessage",
|
|
3493
3448
|
value: function sendMessage(message) {
|
|
3494
3449
|
var _this2 = this;
|
|
3495
|
-
|
|
3496
3450
|
if (message.unsubscribe && this.messageQueue.find(function (m) {
|
|
3497
3451
|
return m.messageId === message.unsubscribe;
|
|
3498
3452
|
})) {
|
|
@@ -3502,7 +3456,6 @@
|
|
|
3502
3456
|
} else {
|
|
3503
3457
|
this.messageQueue.push(message);
|
|
3504
3458
|
}
|
|
3505
|
-
|
|
3506
3459
|
setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
|
|
3507
3460
|
return regenerator.wrap(function _callee4$(_context4) {
|
|
3508
3461
|
while (1) {
|
|
@@ -3510,10 +3463,8 @@
|
|
|
3510
3463
|
case 0:
|
|
3511
3464
|
_context4.next = 2;
|
|
3512
3465
|
return _this2.initSocket();
|
|
3513
|
-
|
|
3514
3466
|
case 2:
|
|
3515
3467
|
_this2.ws.sendQueue();
|
|
3516
|
-
|
|
3517
3468
|
case 3:
|
|
3518
3469
|
case "end":
|
|
3519
3470
|
return _context4.stop();
|
|
@@ -3526,8 +3477,7 @@
|
|
|
3526
3477
|
key: "request",
|
|
3527
3478
|
value: function request(method, _ref4) {
|
|
3528
3479
|
var baseRequestId = _ref4.baseRequestId,
|
|
3529
|
-
|
|
3530
|
-
|
|
3480
|
+
params = _objectWithoutProperties(_ref4, _excluded);
|
|
3531
3481
|
var message = {
|
|
3532
3482
|
messageId: this.messageCounter++,
|
|
3533
3483
|
requestId: baseRequestId,
|
|
@@ -3536,14 +3486,12 @@
|
|
|
3536
3486
|
};
|
|
3537
3487
|
var pendingResults = [];
|
|
3538
3488
|
var nextMessage = null;
|
|
3539
|
-
|
|
3540
3489
|
var runNextMessage = function runNextMessage() {
|
|
3541
3490
|
if (nextMessage) {
|
|
3542
3491
|
nextMessage(pendingResults.pop());
|
|
3543
3492
|
nextMessage = null;
|
|
3544
3493
|
}
|
|
3545
3494
|
};
|
|
3546
|
-
|
|
3547
3495
|
this.messageIdToSubscription[message.messageId] = {
|
|
3548
3496
|
message: message,
|
|
3549
3497
|
callback: function callback(result) {
|
|
@@ -3555,7 +3503,6 @@
|
|
|
3555
3503
|
return {
|
|
3556
3504
|
subscribe: function subscribe(callback) {
|
|
3557
3505
|
var _this3 = this;
|
|
3558
|
-
|
|
3559
3506
|
return _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
|
|
3560
3507
|
var result;
|
|
3561
3508
|
return regenerator.wrap(function _callee5$(_context5) {
|
|
@@ -3566,18 +3513,15 @@
|
|
|
3566
3513
|
_context5.next = 3;
|
|
3567
3514
|
return new Promise(function (resolve) {
|
|
3568
3515
|
nextMessage = resolve;
|
|
3569
|
-
|
|
3570
3516
|
if (pendingResults.length) {
|
|
3571
3517
|
runNextMessage();
|
|
3572
3518
|
}
|
|
3573
3519
|
});
|
|
3574
|
-
|
|
3575
3520
|
case 3:
|
|
3576
3521
|
result = _context5.sent;
|
|
3577
3522
|
return _context5.abrupt("return", callback(result, function () {
|
|
3578
3523
|
return _this3.subscribe(callback);
|
|
3579
3524
|
}));
|
|
3580
|
-
|
|
3581
3525
|
case 5:
|
|
3582
3526
|
case "end":
|
|
3583
3527
|
return _context5.stop();
|
|
@@ -3596,7 +3540,6 @@
|
|
|
3596
3540
|
unsubscribe: message.messageId
|
|
3597
3541
|
});
|
|
3598
3542
|
delete transport.messageIdToSubscription[message.messageId];
|
|
3599
|
-
|
|
3600
3543
|
case 2:
|
|
3601
3544
|
case "end":
|
|
3602
3545
|
return _context6.stop();
|
|
@@ -3608,7 +3551,6 @@
|
|
|
3608
3551
|
};
|
|
3609
3552
|
}
|
|
3610
3553
|
}]);
|
|
3611
|
-
|
|
3612
3554
|
return WebSocketTransport;
|
|
3613
3555
|
}();
|
|
3614
3556
|
|