Skip to content

Commit

Permalink
feat: Support apiToken to be an async function
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Oct 22, 2019
1 parent 1a82605 commit 3a3b5f5
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 101 deletions.
80 changes: 48 additions & 32 deletions packages/cubejs-client-core/dist/cubejs-client-core.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ function () {
var _ref2 = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee4(response, next) {
var subscribeNext, continueWait, body, error, result;
var subscribeNext, continueWait, token, body, error, result;
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
Expand Down Expand Up @@ -1022,107 +1022,123 @@ function () {
};
}();

if (!(response.status === 502)) {
_context4.next = 6;
if (!(typeof _this.apiToken === 'function')) {
_context4.next = 7;
break;
}

_context4.next = 5;
return checkMutex();
return _this.apiToken();

case 5:
token = _context4.sent;

if (_this.transport.authorization !== token) {
_this.transport.authorization = token;
}

case 7:
if (!(response.status === 502)) {
_context4.next = 11;
break;
}

_context4.next = 10;
return checkMutex();

case 10:
return _context4.abrupt("return", continueWait(true));

case 6:
_context4.next = 8;
case 11:
_context4.next = 13;
return response.json();

case 8:
case 13:
body = _context4.sent;

if (!(body.error === 'Continue wait')) {
_context4.next = 14;
_context4.next = 19;
break;
}

_context4.next = 12;
_context4.next = 17;
return checkMutex();

case 12:
case 17:
if (options.progressCallback) {
options.progressCallback(new ProgressResult(body));
}

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

case 14:
case 19:
if (!(response.status !== 200)) {
_context4.next = 27;
_context4.next = 32;
break;
}

_context4.next = 17;
_context4.next = 22;
return checkMutex();

case 17:
case 22:
if (!(!options.subscribe && requestInstance.unsubscribe)) {
_context4.next = 20;
_context4.next = 25;
break;
}

_context4.next = 20;
_context4.next = 25;
return requestInstance.unsubscribe();

case 20:
case 25:
error = new Error(body.error); // TODO error class

if (!callback) {
_context4.next = 25;
_context4.next = 30;
break;
}

callback(error);
_context4.next = 26;
_context4.next = 31;
break;

case 25:
case 30:
throw error;

case 26:
case 31:
return _context4.abrupt("return", subscribeNext());

case 27:
_context4.next = 29;
case 32:
_context4.next = 34;
return checkMutex();

case 29:
case 34:
if (!(!options.subscribe && requestInstance.unsubscribe)) {
_context4.next = 32;
_context4.next = 37;
break;
}

_context4.next = 32;
_context4.next = 37;
return requestInstance.unsubscribe();

case 32:
case 37:
result = toResult(body);

if (!callback) {
_context4.next = 37;
_context4.next = 42;
break;
}

callback(null, result);
_context4.next = 38;
_context4.next = 43;
break;

case 37:
case 42:
return _context4.abrupt("return", result);

case 38:
case 43:
return _context4.abrupt("return", subscribeNext());

case 39:
case 44:
case "end":
return _context4.stop();
}
Expand Down
80 changes: 48 additions & 32 deletions packages/cubejs-client-core/dist/cubejs-client-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ function () {
var _ref2 = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee4(response, next) {
var subscribeNext, continueWait, body, error, result;
var subscribeNext, continueWait, token, body, error, result;
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
Expand Down Expand Up @@ -1028,107 +1028,123 @@ function () {
};
}();

if (!(response.status === 502)) {
_context4.next = 6;
if (!(typeof _this.apiToken === 'function')) {
_context4.next = 7;
break;
}

_context4.next = 5;
return checkMutex();
return _this.apiToken();

case 5:
token = _context4.sent;

if (_this.transport.authorization !== token) {
_this.transport.authorization = token;
}

case 7:
if (!(response.status === 502)) {
_context4.next = 11;
break;
}

_context4.next = 10;
return checkMutex();

case 10:
return _context4.abrupt("return", continueWait(true));

case 6:
_context4.next = 8;
case 11:
_context4.next = 13;
return response.json();

case 8:
case 13:
body = _context4.sent;

if (!(body.error === 'Continue wait')) {
_context4.next = 14;
_context4.next = 19;
break;
}

_context4.next = 12;
_context4.next = 17;
return checkMutex();

case 12:
case 17:
if (options.progressCallback) {
options.progressCallback(new ProgressResult(body));
}

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

case 14:
case 19:
if (!(response.status !== 200)) {
_context4.next = 27;
_context4.next = 32;
break;
}

_context4.next = 17;
_context4.next = 22;
return checkMutex();

case 17:
case 22:
if (!(!options.subscribe && requestInstance.unsubscribe)) {
_context4.next = 20;
_context4.next = 25;
break;
}

_context4.next = 20;
_context4.next = 25;
return requestInstance.unsubscribe();

case 20:
case 25:
error = new Error(body.error); // TODO error class

if (!callback) {
_context4.next = 25;
_context4.next = 30;
break;
}

callback(error);
_context4.next = 26;
_context4.next = 31;
break;

case 25:
case 30:
throw error;

case 26:
case 31:
return _context4.abrupt("return", subscribeNext());

case 27:
_context4.next = 29;
case 32:
_context4.next = 34;
return checkMutex();

case 29:
case 34:
if (!(!options.subscribe && requestInstance.unsubscribe)) {
_context4.next = 32;
_context4.next = 37;
break;
}

_context4.next = 32;
_context4.next = 37;
return requestInstance.unsubscribe();

case 32:
case 37:
result = toResult(body);

if (!callback) {
_context4.next = 37;
_context4.next = 42;
break;
}

callback(null, result);
_context4.next = 38;
_context4.next = 43;
break;

case 37:
case 42:
return _context4.abrupt("return", result);

case 38:
case 43:
return _context4.abrupt("return", subscribeNext());

case 39:
case 44:
case "end":
return _context4.stop();
}
Expand Down
Loading

0 comments on commit 3a3b5f5

Please sign in to comment.