@platform/cell.typesystem
Version:
The 'strongly typed sheets' system of the CellOS.
92 lines (91 loc) • 4.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stub = void 0;
var tslib_1 = require("tslib");
var common_1 = require("../common");
var TypeClient_1 = require("../TypeSystem.core/TypeClient");
var util_1 = require("../util");
var fetch_fromFuncs_1 = require("./fetch.fromFuncs");
var fetch = function (data) {
var before = function (method, args) {
if (data.before) {
data.before({ method: method, args: args });
}
};
var filterCells = function (query, cells) {
var range = common_1.coord.range.fromKey(query);
return Object.keys(cells).reduce(function (acc, next) {
if (range.contains(next)) {
acc[next] = cells[next];
}
return acc;
}, {});
};
var getNs = function (args) { return (0, tslib_1.__awaiter)(void 0, void 0, void 0, function () {
var key, def, ns;
return (0, tslib_1.__generator)(this, function (_a) {
before('getNs', args);
key = common_1.Uri.ns(args.ns).toString();
def = data.defs[key];
ns = !def ? undefined : (def.ns || {});
res.count = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, res.count), { getNs: res.count.getNs + 1 });
return [2, { ns: ns }];
});
}); };
var getColumns = function (args) { return (0, tslib_1.__awaiter)(void 0, void 0, void 0, function () {
var def, columns;
return (0, tslib_1.__generator)(this, function (_a) {
before('getColumns', args);
def = data.defs[args.ns];
columns = def === null || def === void 0 ? void 0 : def.columns;
res.count = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, res.count), { getColumns: res.count.getColumns + 1 });
return [2, { columns: columns }];
});
}); };
var getCells = function (args) { return (0, tslib_1.__awaiter)(void 0, void 0, void 0, function () {
var rows, total, cells;
return (0, tslib_1.__generator)(this, function (_a) {
before('getCells', args);
rows = common_1.coord.cell.max.row(Object.keys(data.cells || {})) + 1;
total = { rows: rows };
cells = data.cells ? filterCells(args.query, data.cells) : undefined;
res.count = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, res.count), { getCells: res.count.getCells + 1 });
return [2, { cells: cells, total: total }];
});
}); };
var res = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, (0, fetch_fromFuncs_1.fromFuncs)({ getNs: getNs, getColumns: getColumns, getCells: getCells })), { count: {
getNs: 0,
getColumns: 0,
getCells: 0,
} });
return res;
};
var instance = function (args) { return (0, tslib_1.__awaiter)(void 0, void 0, void 0, function () {
var loaded, typeDef, cells, def;
var _a;
return (0, tslib_1.__generator)(this, function (_b) {
switch (_b.label) {
case 0: return [4, TypeClient_1.TypeClient.load({
ns: args.implements,
fetch: fetch({ defs: args.defs }),
cache: args.cache,
})];
case 1:
loaded = _b.sent();
typeDef = args.getTypeDef ? args.getTypeDef(loaded.defs) : loaded.defs[0];
cells = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, (args.cells || {})), (0, util_1.objectToCells)(typeDef).rows(0, args.rows || []));
def = {
ns: { type: { implements: args.implements } },
columns: {},
};
return [2, fetch({
cells: cells,
defs: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, args.defs), (_a = {}, _a[args.instance] = def, _a)),
})];
}
});
}); };
exports.stub = {
fetch: fetch,
instance: instance,
};