UNPKG

@platform/cell.client

Version:

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

80 lines (79 loc) 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpClientCellDb = void 0; var tslib_1 = require("tslib"); var common_1 = require("../common"); var HttpClientNs_1 = require("./HttpClientNs"); function HttpClientCellDb(args) { var parent = args.parent, urls = args.urls, http = args.http; var uri = parent.uri; var api = { uri: uri, toString: function () { return uri.toString(); }, 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(urls.cell(uri).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 = urls.cell(uri).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) { return tslib_1.__awaiter(this, void 0, void 0, function () { var ns; var _a; return tslib_1.__generator(this, function (_b) { ns = (0, HttpClientNs_1.HttpClientNs)({ uri: common_1.Uri.ns(uri.ns), urls: urls, http: http }); return [2, ns.write({ cells: (_a = {}, _a[uri.key] = data, _a) }, options)]; }); }); }, props: { read: function (options) { var _a, _b; return tslib_1.__awaiter(this, void 0, void 0, function () { var res, props; return tslib_1.__generator(this, function (_c) { switch (_c.label) { case 0: return [4, api.read(options)]; case 1: res = _c.sent(); props = (_b = (_a = res.body) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.props; return [2, common_1.util.toClientResponse(res.status, props)]; } }); }); }, write: function (props, options) { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { return [2, api.write({ props: props }, options)]; }); }); }, }, }; return api; } exports.HttpClientCellDb = HttpClientCellDb;