UNPKG

@platform/cell.client

Version:

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

63 lines (62 loc) 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpClientNs = void 0; var tslib_1 = require("tslib"); var common_1 = require("../common"); function HttpClientNs(args) { var uri = args.uri, urls = args.urls, http = args.http; var api = { uri: uri, get url() { return urls.ns(uri); }, 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, http.get(api.url.info.toString())]; case 1: res = _a.sent(); return [2, res.status.toString().startsWith('2')]; } }); }); }, read: function (options) { if (options === void 0) { options = {}; } return tslib_1.__awaiter(this, void 0, void 0, function () { var url, res; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: url = api.url.info.query(options).toString(); return [4, http.get(url)]; case 1: res = _a.sent(); return [2, common_1.util.fromHttpResponse(res).toClientResponse()]; } }); }); }, write: function (data, options) { if (options === void 0) { options = {}; } return tslib_1.__awaiter(this, void 0, void 0, function () { var url, res; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: url = api.url.info.query(options).toString(); return [4, http.post(url, data)]; case 1: res = _a.sent(); return [2, common_1.util.fromHttpResponse(res).toClientResponse()]; } }); }); }, toString: function () { return uri.toString(); }, }; return api; } exports.HttpClientNs = HttpClientNs;