@platform/cell.client
Version:
A strongly typed HTTP client for operating with a CellOS service end-point.
63 lines (62 loc) • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.typesystem = void 0;
var tslib_1 = require("tslib");
var Client_http_1 = require("../Client.http");
var common_1 = require("../common");
function typesystem(input) {
var args = typeof input === 'object' ? input : { http: input };
var event$ = args.event$ ? args.event$ : undefined;
var cache = args.cache || common_1.MemoryCache.create();
var change;
var http = Client_http_1.HttpClient.isClient(args.http)
? args.http
: Client_http_1.HttpClient.create(args.http);
var fetch = common_1.TypeSystem.fetcher.fromClient(http);
var api = {
http: http,
fetch: fetch,
cache: cache,
get changes() {
return change || (change = common_1.TypeSystem.ChangeMonitor.create());
},
defs: function (ns) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var uris, client, defs;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
uris = Array.isArray(ns) ? ns : [ns];
client = common_1.TypeSystem.client(http);
return [4, Promise.all(uris.map(function (ns) { return client.load(ns); }))];
case 1:
defs = (_a.sent()).map(function (_a) {
var defs = _a.defs;
return defs;
});
return [2, defs.reduce(function (acc, next) { return acc.concat(next); }, [])];
}
});
});
},
typescript: function (ns, options) {
if (options === void 0) { options = {}; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var defs;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, api.defs(ns)];
case 1:
defs = _a.sent();
return [2, common_1.TypeSystem.Client.typescript(defs, options)];
}
});
});
},
sheet: function (ns) {
return common_1.TypeSystem.Sheet.load({ ns: ns, fetch: fetch, cache: cache, event$: event$ });
},
};
return api;
}
exports.typesystem = typesystem;