UNPKG

@platform/cell.client

Version:

A strongly typed HTTP client for operating with a CellOS service end-point.

55 lines (54 loc) 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var common_1 = require("../common"); var HttpClientFile_1 = require("./HttpClientFile"); var HttpClientCellLinks = (function () { function HttpClientCellLinks(args) { var _this = this; var _a = args.links, links = _a === void 0 ? {} : _a; this.args = args; this.list = Object.keys(links).map(function (key) { return _this.toLink(key, links[key]); }); } HttpClientCellLinks.create = function (args) { return new HttpClientCellLinks(args); }; Object.defineProperty(HttpClientCellLinks.prototype, "files", { get: function () { return this.list.filter(function (item) { return item.type === 'FILE'; }); }, enumerable: true, configurable: true }); HttpClientCellLinks.prototype.toObject = function () { return this.args.links; }; HttpClientCellLinks.prototype.toLink = function (key, value) { var _a = this.args, http = _a.http, urls = _a.urls; var uri = common_1.Uri.parse(value); var type = uri.parts.type; if (type === 'FILE') { var file_1; var link = common_1.Schema.file.links.parseValue(value); var uri_1 = link.uri.toString(); var hash = link.query.hash || ''; var _b = common_1.Schema.file.links.parseKey(key), name_1 = _b.name, dir = _b.dir, path = _b.path; var res_1 = { type: 'FILE', uri: uri_1, key: key, path: path, dir: dir, name: name_1, hash: hash, get file() { return file_1 || (file_1 = HttpClientFile_1.HttpClientFile.create({ uri: uri_1, urls: urls, http: http })); }, }; return res_1; } var res = { type: 'UNKNOWN', key: key, uri: value }; return res; }; return HttpClientCellLinks; }()); exports.HttpClientCellLinks = HttpClientCellLinks;