@looker/sdk-rtl
Version:
Looker SDK Runtime Library
117 lines • 5.93 kB
JavaScript
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { agentPrefix, sdkOk } from './transport';
export var functionalSdk = (authSession, apiVersion, sdkVersion) => {
var sdk = new APIMethods(authSession, sdkVersion);
sdk.apiVersion = apiVersion;
sdk.apiPath = authSession.settings.base_url === '' ? '' : authSession.settings.base_url + '/api/' + apiVersion;
return sdk;
};
export class APIMethods {
constructor(authSession, sdkVersion) {
this.authSession = authSession;
this.sdkVersion = sdkVersion;
_defineProperty(this, "_apiPath", '');
_defineProperty(this, "_apiVersion", '');
if (!('agentTag' in authSession.settings && authSession.settings.agentTag)) {
authSession.settings.agentTag = "".concat(agentPrefix, " ").concat(sdkVersion);
}
}
get apiPath() {
return this._apiPath;
}
set apiPath(value) {
if (this._apiPath) {
throw new Error("API Path is set to \"".concat(this._apiPath, "\" and cannot be reassigned"));
}
this._apiPath = value;
}
get apiVersion() {
return this._apiVersion;
}
set apiVersion(value) {
if (this._apiVersion) {
throw new Error("API Version is set to \"".concat(this._apiVersion, "\" and cannot be reassigned"));
}
this._apiVersion = value;
}
static create(type, authSession) {
return new type(authSession);
}
ok(promise) {
return _asyncToGenerator(function* () {
return sdkOk(promise);
})();
}
makePath(path, options, authenticator) {
if (path.match(/^(http:\/\/|https:\/\/)/gi)) return path;
var base = authenticator ? this.apiPath : options.base_url;
return "".concat(base).concat(path);
}
authRequest(method, path, queryParams, body, options) {
var _this = this;
return _asyncToGenerator(function* () {
options = _objectSpread(_objectSpread({}, _this.authSession.settings), options);
var authenticator = init => {
return _this.authSession.authenticate(init);
};
path = _this.makePath(path, options, authenticator);
return _this.authSession.transport.request(method, path, queryParams, body, authenticator, options);
})();
}
authStream(callback, method, path, queryParams, body, options) {
var _this2 = this;
return _asyncToGenerator(function* () {
options = _objectSpread(_objectSpread({}, _this2.authSession.settings), options);
var authenticator = init => {
return _this2.authSession.authenticate(init);
};
path = _this2.makePath(path, options, authenticator);
return _this2.authSession.transport.stream(callback, method, path, queryParams, body, init => {
return _this2.authSession.authenticate(init);
}, options);
})();
}
get(path, queryParams, body, options) {
var _this3 = this;
return _asyncToGenerator(function* () {
return _this3.authRequest('GET', path, queryParams, body, options);
})();
}
head(path, queryParams, body, options) {
var _this4 = this;
return _asyncToGenerator(function* () {
return _this4.authRequest('HEAD', path, queryParams, body, options);
})();
}
delete(path, queryParams, body, options) {
var _this5 = this;
return _asyncToGenerator(function* () {
return _this5.authRequest('DELETE', path, queryParams, body, options);
})();
}
post(path, queryParams, body, options) {
var _this6 = this;
return _asyncToGenerator(function* () {
return _this6.authRequest('POST', path, queryParams, body, options);
})();
}
put(path, queryParams, body, options) {
var _this7 = this;
return _asyncToGenerator(function* () {
return _this7.authRequest('PUT', path, queryParams, body, options);
})();
}
patch(path, queryParams, body, options) {
var _this8 = this;
return _asyncToGenerator(function* () {
return _this8.authRequest('PATCH', path, queryParams, body, options);
})();
}
}
//# sourceMappingURL=apiMethods.js.map