UNPKG

2.55 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.dev/license
7 */
8import { BaseException, JsonValue, logging } from '@angular-devkit/core';
9import { Observable, Observer } from 'rxjs';
10import { JobDescription, JobHandler, JobHandlerContext } from './api';
11export declare class ChannelAlreadyExistException extends BaseException {
12 constructor(name: string);
13}
14/**
15 * Interface for the JobHandler context that is used when using `createJobHandler()`. It extends
16 * the basic `JobHandlerContext` with additional functionality.
17 */
18export interface SimpleJobHandlerContext<A extends JsonValue, I extends JsonValue, O extends JsonValue> extends JobHandlerContext<A, I, O> {
19 createChannel: (name: string) => Observer<JsonValue>;
20 input: Observable<I>;
21 addTeardown(teardown: () => Promise<void> | void): void;
22}
23/**
24 * A simple version of the JobHandler. This simplifies a lot of the interaction with the job
25 * scheduler and registry. For example, instead of returning a JobOutboundMessage observable, you
26 * can directly return an output.
27 */
28export type SimpleJobHandlerFn<A extends JsonValue, I extends JsonValue, O extends JsonValue> = (input: A, context: SimpleJobHandlerContext<A, I, O>) => O | Promise<O> | Observable<O>;
29/**
30 * Make a simple job handler that sets start and end from a function that's synchronous.
31 *
32 * @param fn The function to create a handler for.
33 * @param options An optional set of properties to set on the handler. Some fields might be
34 * required by registry or schedulers.
35 */
36export declare function createJobHandler<A extends JsonValue, I extends JsonValue, O extends JsonValue>(fn: SimpleJobHandlerFn<A, I, O>, options?: Partial<JobDescription>): JobHandler<A, I, O>;
37/**
38 * Lazily create a job using a function.
39 * @param loader A factory function that returns a promise/observable of a JobHandler.
40 * @param options Same options as createJob.
41 */
42export declare function createJobFactory<A extends JsonValue, I extends JsonValue, O extends JsonValue>(loader: () => Promise<JobHandler<A, I, O>>, options?: Partial<JobDescription>): JobHandler<A, I, O>;
43/**
44 * Creates a job that logs out input/output messages of another Job. The messages are still
45 * propagated to the other job.
46 */
47export declare function createLoggerJob<A extends JsonValue, I extends JsonValue, O extends JsonValue>(job: JobHandler<A, I, O>, logger: logging.LoggerApi): JobHandler<A, I, O>;