1.1.0 • Published 5 months ago

@greeneyesai/toolkit v1.1.0

Weekly downloads
-
License
LGPL-3.0-only
Repository
gitlab
Last release
5 months ago

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.

1.1.0

5 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago