@platform/cell.client
Version:
A strongly typed HTTP client for operating with a CellOS service end-point.
94 lines (93 loc) • 3.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var common_1 = require("../common");
var HttpClientCellFile_1 = require("./HttpClientCellFile");
var HttpClientCellFiles_1 = require("./HttpClientCellFiles");
var HttpClientCellLinks_1 = require("./HttpClientCellLinks");
var HttpClientCell = (function () {
function HttpClientCell(args) {
var urls = args.urls;
this.args = args;
this.uri = common_1.Uri.parse(args.uri);
this.url = urls.cell(args.uri);
}
HttpClientCell.create = function (args) {
return new HttpClientCell(args);
};
Object.defineProperty(HttpClientCell.prototype, "file", {
get: function () {
var urls = this.args.urls;
var http = this.args.http;
return this._file || (this._file = HttpClientCellFile_1.HttpClientCellFile.create({ parent: this, urls: urls, http: http }));
},
enumerable: true,
configurable: true
});
Object.defineProperty(HttpClientCell.prototype, "files", {
get: function () {
var urls = this.args.urls;
var http = this.args.http;
return this._files || (this._files = HttpClientCellFiles_1.HttpClientCellFiles.create({ parent: this, urls: urls, http: http }));
},
enumerable: true,
configurable: true
});
HttpClientCell.prototype.toString = function () {
return this.uri.toString();
};
HttpClientCell.prototype.exists = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var res;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.args.http.get(this.url.info.toString())];
case 1:
res = _a.sent();
return [2, res.status.toString().startsWith('2')];
}
});
});
};
HttpClientCell.prototype.info = function (options) {
if (options === void 0) { options = {}; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var http, url, res;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
http = this.args.http;
url = this.url.info.query(options).toString();
return [4, http.get(url)];
case 1:
res = _a.sent();
return [2, common_1.util.fromHttpResponse(res).toClientResponse()];
}
});
});
};
HttpClientCell.prototype.links = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var info, message, http, cell, links, urls, body;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.info()];
case 1:
info = _a.sent();
if (info.error) {
message = "Failed to get links for '" + this.uri.toString() + "'. " + info.error.message;
return [2, common_1.util.toError(info.status, info.error.type, message)];
}
http = this.args.http;
cell = info.body.data;
links = cell.links || {};
urls = this.args.urls;
body = HttpClientCellLinks_1.HttpClientCellLinks.create({ links: links, urls: urls, http: http });
return [2, common_1.util.toClientResponse(200, body)];
}
});
});
};
return HttpClientCell;
}());
exports.HttpClientCell = HttpClientCell;