UNPKG

@platform/cell.client

Version:

A strongly typed HTTP client for operating with a CellOS service end-point.

36 lines (35 loc) 1.12 kB
import { TypeSystem } from '../common'; import { HttpClient } from '../HttpClient'; export class Client { static http(input) { return Client.Http.create(input); } static type(input) { const args = typeof input === 'object' ? input : { http: input }; const { cache, events$ } = args; const http = HttpClient.isClient(args.http) ? args.http : HttpClient.create(args.http); const fetch = TypeSystem.fetcher.fromClient(http); const api = { http, fetch, async defs(ns) { return (await TypeSystem.client(http).load(ns)).defs; }, async typescript(ns) { const defs = await api.defs(ns); return TypeSystem.Client.typescript(defs); }, sheet(ns) { return TypeSystem.Sheet.load({ ns, fetch, cache, events$ }); }, }; return api; } static sheet(ns, options) { return Client.type(options).sheet(ns); } } Client.Http = HttpClient; Client.Type = TypeSystem;