UNPKG

@platform/cell.typesystem

Version:

The 'strongly typed sheets' system of the CellOS.

69 lines (68 loc) 3.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fromClient = void 0; var tslib_1 = require("tslib"); var common_1 = require("../common"); var fetch_fromFuncs_1 = require("./fetch.fromFuncs"); function fromClient(http) { var _this = this; var getNs = function (args) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { var res, exists, error, message, ns, payload; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: return [4, http.ns(args.ns).read()]; case 1: res = _a.sent(); exists = res.body.exists; if (!exists) { message = "The namespace (" + args.ns + ") does not exist"; error = { status: 404, message: message, type: common_1.ERROR.HTTP.NOT_FOUND }; } ns = (res.body.data.ns.props || {}); payload = { ns: ns, error: error }; return [2, payload]; } }); }); }; var getColumns = function (args) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { var res, error, columns, payload; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: return [4, http.ns(args.ns).read({ columns: true })]; case 1: res = _a.sent(); error = formatError(res.error, function (msg) { return "Failed to retrieve type information from namespace (" + args.ns + "). " + msg; }); columns = res.body.data.columns; payload = { columns: columns, error: error }; return [2, payload]; } }); }); }; var getCells = function (args) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { var ns, query, res, error, cells, total, rows, payload; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: ns = args.ns, query = args.query; return [4, http.ns(ns).read({ cells: query, total: 'rows' })]; case 1: res = _a.sent(); error = formatError(res.error, function (msg) { return "Failed to retrieve cells \"" + query + "\" within namespace (" + ns + "). " + msg; }); cells = res.body.data.cells; total = res.body.data.total || {}; rows = total.rows || 0; payload = { total: { rows: rows }, cells: cells, error: error }; return [2, payload]; } }); }); }; return (0, fetch_fromFuncs_1.fromFuncs)({ getNs: getNs, getColumns: getColumns, getCells: getCells, }); } exports.fromClient = fromClient; function formatError(error, getMessage) { return !error ? undefined : (0, tslib_1.__assign)((0, tslib_1.__assign)({}, error), { message: getMessage(error.message) }); }