Skip to content

Commit 3a3b5f5

Browse files
committed
feat: Support apiToken to be an async function
1 parent 1a82605 commit 3a3b5f5

File tree

9 files changed

+170
-101
lines changed

9 files changed

+170
-101
lines changed

packages/cubejs-client-core/dist/cubejs-client-core.esm.js

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ function () {
922922
var _ref2 = _asyncToGenerator(
923923
/*#__PURE__*/
924924
_regeneratorRuntime.mark(function _callee4(response, next) {
925-
var subscribeNext, continueWait, body, error, result;
925+
var subscribeNext, continueWait, token, body, error, result;
926926
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
927927
while (1) {
928928
switch (_context4.prev = _context4.next) {
@@ -1022,107 +1022,123 @@ function () {
10221022
};
10231023
}();
10241024

1025-
if (!(response.status === 502)) {
1026-
_context4.next = 6;
1025+
if (!(typeof _this.apiToken === 'function')) {
1026+
_context4.next = 7;
10271027
break;
10281028
}
10291029

10301030
_context4.next = 5;
1031-
return checkMutex();
1031+
return _this.apiToken();
10321032

10331033
case 5:
1034+
token = _context4.sent;
1035+
1036+
if (_this.transport.authorization !== token) {
1037+
_this.transport.authorization = token;
1038+
}
1039+
1040+
case 7:
1041+
if (!(response.status === 502)) {
1042+
_context4.next = 11;
1043+
break;
1044+
}
1045+
1046+
_context4.next = 10;
1047+
return checkMutex();
1048+
1049+
case 10:
10341050
return _context4.abrupt("return", continueWait(true));
10351051

1036-
case 6:
1037-
_context4.next = 8;
1052+
case 11:
1053+
_context4.next = 13;
10381054
return response.json();
10391055

1040-
case 8:
1056+
case 13:
10411057
body = _context4.sent;
10421058

10431059
if (!(body.error === 'Continue wait')) {
1044-
_context4.next = 14;
1060+
_context4.next = 19;
10451061
break;
10461062
}
10471063

1048-
_context4.next = 12;
1064+
_context4.next = 17;
10491065
return checkMutex();
10501066

1051-
case 12:
1067+
case 17:
10521068
if (options.progressCallback) {
10531069
options.progressCallback(new ProgressResult(body));
10541070
}
10551071

10561072
return _context4.abrupt("return", continueWait());
10571073

1058-
case 14:
1074+
case 19:
10591075
if (!(response.status !== 200)) {
1060-
_context4.next = 27;
1076+
_context4.next = 32;
10611077
break;
10621078
}
10631079

1064-
_context4.next = 17;
1080+
_context4.next = 22;
10651081
return checkMutex();
10661082

1067-
case 17:
1083+
case 22:
10681084
if (!(!options.subscribe && requestInstance.unsubscribe)) {
1069-
_context4.next = 20;
1085+
_context4.next = 25;
10701086
break;
10711087
}
10721088

1073-
_context4.next = 20;
1089+
_context4.next = 25;
10741090
return requestInstance.unsubscribe();
10751091

1076-
case 20:
1092+
case 25:
10771093
error = new Error(body.error); // TODO error class
10781094

10791095
if (!callback) {
1080-
_context4.next = 25;
1096+
_context4.next = 30;
10811097
break;
10821098
}
10831099

10841100
callback(error);
1085-
_context4.next = 26;
1101+
_context4.next = 31;
10861102
break;
10871103

1088-
case 25:
1104+
case 30:
10891105
throw error;
10901106

1091-
case 26:
1107+
case 31:
10921108
return _context4.abrupt("return", subscribeNext());
10931109

1094-
case 27:
1095-
_context4.next = 29;
1110+
case 32:
1111+
_context4.next = 34;
10961112
return checkMutex();
10971113

1098-
case 29:
1114+
case 34:
10991115
if (!(!options.subscribe && requestInstance.unsubscribe)) {
1100-
_context4.next = 32;
1116+
_context4.next = 37;
11011117
break;
11021118
}
11031119

1104-
_context4.next = 32;
1120+
_context4.next = 37;
11051121
return requestInstance.unsubscribe();
11061122

1107-
case 32:
1123+
case 37:
11081124
result = toResult(body);
11091125

11101126
if (!callback) {
1111-
_context4.next = 37;
1127+
_context4.next = 42;
11121128
break;
11131129
}
11141130

11151131
callback(null, result);
1116-
_context4.next = 38;
1132+
_context4.next = 43;
11171133
break;
11181134

1119-
case 37:
1135+
case 42:
11201136
return _context4.abrupt("return", result);
11211137

1122-
case 38:
1138+
case 43:
11231139
return _context4.abrupt("return", subscribeNext());
11241140

1125-
case 39:
1141+
case 44:
11261142
case "end":
11271143
return _context4.stop();
11281144
}

packages/cubejs-client-core/dist/cubejs-client-core.js

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ function () {
928928
var _ref2 = _asyncToGenerator(
929929
/*#__PURE__*/
930930
_regeneratorRuntime.mark(function _callee4(response, next) {
931-
var subscribeNext, continueWait, body, error, result;
931+
var subscribeNext, continueWait, token, body, error, result;
932932
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
933933
while (1) {
934934
switch (_context4.prev = _context4.next) {
@@ -1028,107 +1028,123 @@ function () {
10281028
};
10291029
}();
10301030

1031-
if (!(response.status === 502)) {
1032-
_context4.next = 6;
1031+
if (!(typeof _this.apiToken === 'function')) {
1032+
_context4.next = 7;
10331033
break;
10341034
}
10351035

10361036
_context4.next = 5;
1037-
return checkMutex();
1037+
return _this.apiToken();
10381038

10391039
case 5:
1040+
token = _context4.sent;
1041+
1042+
if (_this.transport.authorization !== token) {
1043+
_this.transport.authorization = token;
1044+
}
1045+
1046+
case 7:
1047+
if (!(response.status === 502)) {
1048+
_context4.next = 11;
1049+
break;
1050+
}
1051+
1052+
_context4.next = 10;
1053+
return checkMutex();
1054+
1055+
case 10:
10401056
return _context4.abrupt("return", continueWait(true));
10411057

1042-
case 6:
1043-
_context4.next = 8;
1058+
case 11:
1059+
_context4.next = 13;
10441060
return response.json();
10451061

1046-
case 8:
1062+
case 13:
10471063
body = _context4.sent;
10481064

10491065
if (!(body.error === 'Continue wait')) {
1050-
_context4.next = 14;
1066+
_context4.next = 19;
10511067
break;
10521068
}
10531069

1054-
_context4.next = 12;
1070+
_context4.next = 17;
10551071
return checkMutex();
10561072

1057-
case 12:
1073+
case 17:
10581074
if (options.progressCallback) {
10591075
options.progressCallback(new ProgressResult(body));
10601076
}
10611077

10621078
return _context4.abrupt("return", continueWait());
10631079

1064-
case 14:
1080+
case 19:
10651081
if (!(response.status !== 200)) {
1066-
_context4.next = 27;
1082+
_context4.next = 32;
10671083
break;
10681084
}
10691085

1070-
_context4.next = 17;
1086+
_context4.next = 22;
10711087
return checkMutex();
10721088

1073-
case 17:
1089+
case 22:
10741090
if (!(!options.subscribe && requestInstance.unsubscribe)) {
1075-
_context4.next = 20;
1091+
_context4.next = 25;
10761092
break;
10771093
}
10781094

1079-
_context4.next = 20;
1095+
_context4.next = 25;
10801096
return requestInstance.unsubscribe();
10811097

1082-
case 20:
1098+
case 25:
10831099
error = new Error(body.error); // TODO error class
10841100

10851101
if (!callback) {
1086-
_context4.next = 25;
1102+
_context4.next = 30;
10871103
break;
10881104
}
10891105

10901106
callback(error);
1091-
_context4.next = 26;
1107+
_context4.next = 31;
10921108
break;
10931109

1094-
case 25:
1110+
case 30:
10951111
throw error;
10961112

1097-
case 26:
1113+
case 31:
10981114
return _context4.abrupt("return", subscribeNext());
10991115

1100-
case 27:
1101-
_context4.next = 29;
1116+
case 32:
1117+
_context4.next = 34;
11021118
return checkMutex();
11031119

1104-
case 29:
1120+
case 34:
11051121
if (!(!options.subscribe && requestInstance.unsubscribe)) {
1106-
_context4.next = 32;
1122+
_context4.next = 37;
11071123
break;
11081124
}
11091125

1110-
_context4.next = 32;
1126+
_context4.next = 37;
11111127
return requestInstance.unsubscribe();
11121128

1113-
case 32:
1129+
case 37:
11141130
result = toResult(body);
11151131

11161132
if (!callback) {
1117-
_context4.next = 37;
1133+
_context4.next = 42;
11181134
break;
11191135
}
11201136

11211137
callback(null, result);
1122-
_context4.next = 38;
1138+
_context4.next = 43;
11231139
break;
11241140

1125-
case 37:
1141+
case 42:
11261142
return _context4.abrupt("return", result);
11271143

1128-
case 38:
1144+
case 43:
11291145
return _context4.abrupt("return", subscribeNext());
11301146

1131-
case 39:
1147+
case 44:
11321148
case "end":
11331149
return _context4.stop();
11341150
}

0 commit comments

Comments
 (0)