@greeneyesai/toolkit
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

GreenEyes.AI API Toolkit

Helper classes for GreenEyes.AI REST API.

Usage

import * as events from "events";
import { 
    APIClient, 
    QueuedExecutor, 
    QueuedExecutorDelegate, 
    QueuedExecutorEvents
} from "@greeneyesai/toolkit"

...

const client = new APIClient(appId, appSecret);

const { maxConcurrency } = await client.authenticate();

...

type ArgsType = [string, { internalId: string; }];

const delegate: QueuedExecutorDelegate<ArgsType> = {
    exec: async (...args: ArgsType): Promise<void> => {
        try {
            const { object } = await client.storeObject({
                src: args[0],
                meta: args[1];
            });

            // process object.id
            // ...
        } catch (e) {
            console.error(e);
            // ...
        }
    }
};

const executor = new QueuedExecutor<ArgsType>(
    maxConcurrency, 
    100, // request throtling in ms 
    delegate
);

...

executor.push(src, meta);

...

executor.inputStreamClosed();

...

await events.once(executor, QueuedExecutorEvents.Finished); 
// Import finished

Note: feel free to use any form of pagination when pushing to the executor, the executor emits QueuedExecutorEvents.BufferEmpty event when the page is processed and if the inputStreamClosed has not been called prior.

License

GNU Lesser General Public License v3.0

© GreenEyes Artificial Intelligence Services, LLC.

Package Sidebar

Install

npm i @greeneyesai/toolkit

Weekly Downloads

0

Version

1.1.0

License

LGPL-3.0-only

Unpacked Size

41.2 kB

Total Files

19

Last publish

Collaborators

  • arpad.kiss