2.0.0 • Published 1 year ago

generic-client-interface v2.0.0

Weekly downloads
-
License
(MIT or CC0 1.0)
Repository
github
Last release
1 year ago

generic-client-interface

A wrapper for creation a group of clients that are independent from each other, easily testable, and asynchronously imported.

Installation

npm i generic-client-interface

Usage

Full api reference: https://electrovir.github.io/generic-client-interface/

  • Define individual clients (one exported per file) with defineClient.
  • Define a whole client interface with defineClientInterface.

Defining a client

import {defineClient} from 'generic-client-interface';

/** Clients must be exported. Only one client can be exported per file. */
export const exampleClient1 = defineClient({
    /** Define the client's members. */
    doStuff() {
        console.log('hello');
    },
    async sendRequest(url: string) {
        return await (await fetch(url)).json();
    },
});

Defining a whole client interface

import {awaitAllClients, defineClientInterface} from 'generic-client-interface';

const myClientInterface = defineClientInterface({
    /** Establish the client names and where they're imported from. */
    exampleClient: () => import('./define-client.example'),
});

async function exampleMain() {
    /** A client must be awaited before it can be accessed. */
    (await myClientInterface.exampleClient).doStuff();

    /** All clients can be awaited in a single promise. */
    const clients = await awaitAllClients(myClientInterface);
    clients.exampleClient.doStuff();
}
2.0.0

1 year ago

1.0.0

1 year ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago