UNPKG

@oada/client

Version:

A lightweight client tool to interact with an OADA-compliant server

55 lines 2.04 kB
/** * @license * Copyright 2021 Open Ag Data Alliance * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // eslint-disable-next-line @typescript-eslint/triple-slash-reference /// <reference path="types.d.ts" /> import { autoConnection, parseDomain } from "./auto.js"; import { OADAClient } from "./client.js"; /** Create a new instance of OADAClient */ export function createInstance(config) { return new OADAClient(config); } export function normalizeDomain(domain) { const url = parseDomain(domain); return url.toString(); } /** Create a new instance and wrap it with Promise */ export async function connect({ connection: proto = "auto", concurrency = 1, userAgent = `${process.env.npm_package_name}/${process.env.npm_package_version}`, timeouts: t = {}, ...config }) { const timeouts = typeof t === "number" ? { connect: t, keepAlive: t, headers: t, body: t, } : t; const connection = proto === "auto" ? await autoConnection({ concurrency, userAgent, timeouts, ...config }) : proto; // Create an instance of client and start connection const client = new OADAClient({ ...config, domain: normalizeDomain(config.domain), connection, }); // Wait for the connection to open await client.awaitConnection(); // Return the instance return client; } export { OADAClient, } from "./client.js"; export { TimeoutError } from "./utils.js"; //# sourceMappingURL=index.js.map