@oada/client
Version:
A lightweight client tool to interact with an OADA-compliant server
55 lines (54 loc) • 1.79 kB
TypeScript
/**
* @license
* Copyright 2023 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.
*/
import type Job from "@oada/types/oada/service/job.js";
import type { OADAClient } from "./index.js";
export declare class JobsRequest<J extends Job> {
#private;
job: J;
oadaId?: string;
oadaListKey?: string;
oada: OADAClient;
constructor({ oada, job }: {
oada: OADAClient;
job: J;
});
on<E extends JobEventType>(event: E, listener: (jobChange: JobType<E, J>) => PromiseLike<void> | void): Promise<void>;
start(): Promise<{
_id: string;
key: string;
}>;
}
export declare enum JobEventType {
Status = "Status",
Success = "Success",
Failure = "Failure",
Result = "Result",
Update = "Update"
}
export interface JobEvent<J = never> {
readonly job: Promise<J>;
}
export interface JobEventTypes<J> {
[JobEventType.Success]: [JobEvent<J>];
[JobEventType.Status]: [JobEvent<J>];
[JobEventType.Failure]: [JobEvent<J>];
[JobEventType.Result]: [JobEvent<J>];
[JobEventType.Update]: [JobEvent<J>];
error: unknown[];
}
export type JobType<E extends JobEventType, J> = JobEventTypes<J>[E][0];
export declare const doJob: (oada: OADAClient, job: Job) => Promise<Job>;