UNPKG

@platform/cell.typesystem

Version:

The 'strongly typed sheets' system of the CellOS.

80 lines (79 loc) 3.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var common_1 = require("../common"); function fromClient(http) { var _this = this; var getNs = function (args) { return tslib_1.__awaiter(_this, void 0, void 0, function () { var res, exists, error, message, ns, payload; return 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 tslib_1.__awaiter(_this, void 0, void 0, function () { var res, error, columns, payload; return 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 tslib_1.__awaiter(_this, void 0, void 0, function () { var ns, query, res, error, cells, total, rows, payload; return 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 fromFuncs({ getNs: getNs, getColumns: getColumns, getCells: getCells, }); } function fromFuncs(args) { var getNs = args.getNs, getCells = args.getCells, getColumns = args.getColumns; return { getNs: getNs, getCells: getCells, getColumns: getColumns }; } exports.fetcher = { fromClient: fromClient, fromFuncs: fromFuncs, }; function formatError(error, getMessage) { if (!error) { return undefined; } else { var message = getMessage(error.message); return tslib_1.__assign(tslib_1.__assign({}, error), { message: message }); } }