@platform/cell.client
Version:
A strongly typed HTTP client for operating with a CellOS service end-point.
67 lines (66 loc) • 2.79 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 pool = args.pool || common_1.TypeSystem.Pool.create();
var change;
var http = Client_http_1.HttpClient.isClient(args.http)
? args.http
: Client_http_1.HttpClient.create(args.http);
var host = http.origin;
var fetch = common_1.TypeSystem.Cache.wrapFetch(common_1.TypeSystem.fetcher.fromClient(http), { event$: event$ });
var api = {
host: host,
http: http,
fetch: fetch,
cache: cache,
pool: pool,
get changes() {
return change || (change = common_1.TypeSystem.ChangeMonitor.create());
},
typeDefs: 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(fetch);
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.typeDefs(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$, pool: pool });
},
};
return api;
}
exports.typesystem = typesystem;