@angular-devkit/architect 0.1500.0-next.4 → 0.1500.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node/BUILD.bazel +30 -0
- package/node/index.d.ts +2 -0
- package/node/index.js +15 -0
- package/node/jobs/job-registry.d.ts +20 -0
- package/node/jobs/job-registry.js +59 -0
- package/package.json +3 -3
- package/src/api.d.ts +3 -7
- package/src/architect.d.ts +4 -4
- package/src/architect.js +10 -11
- package/src/create-builder.js +4 -5
- package/src/index.d.ts +2 -0
- package/src/index.js +15 -1
- package/src/internal.d.ts +5 -4
- package/src/jobs/README.md +508 -0
- package/src/jobs/api.d.ts +332 -0
- package/src/jobs/api.js +73 -0
- package/src/jobs/architecture.md +260 -0
- package/src/jobs/create-job-handler.d.ts +46 -0
- package/src/jobs/create-job-handler.js +134 -0
- package/src/jobs/dispatcher.d.ts +31 -0
- package/src/jobs/dispatcher.js +50 -0
- package/src/jobs/exception.d.ts +15 -0
- package/src/jobs/exception.js +23 -0
- package/src/jobs/fallback-registry.d.ts +19 -0
- package/src/jobs/fallback-registry.js +27 -0
- package/src/jobs/index.d.ts +15 -0
- package/src/jobs/index.js +31 -0
- package/src/jobs/simple-registry.d.ts +44 -0
- package/src/jobs/simple-registry.js +77 -0
- package/src/jobs/simple-scheduler.d.ts +77 -0
- package/src/jobs/simple-scheduler.js +382 -0
- package/src/jobs/strategy.d.ts +28 -0
- package/src/jobs/strategy.js +99 -0
- package/src/jobs/types.d.ts +15 -0
- package/src/jobs/types.js +9 -0
- package/src/schedule-by-name.d.ts +4 -5
- package/src/schedule-by-name.js +3 -10
|
@@ -0,0 +1,46 @@
|
|
|
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.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { BaseException, JsonValue, logging } from '@angular-devkit/core';
|
|
9
|
+
import { Observable, Observer } from 'rxjs';
|
|
10
|
+
import { JobDescription, JobHandler, JobHandlerContext } from './api';
|
|
11
|
+
export 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
|
+
*/
|
|
18
|
+
export 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
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A simple version of the JobHandler. This simplifies a lot of the interaction with the job
|
|
24
|
+
* scheduler and registry. For example, instead of returning a JobOutboundMessage observable, you
|
|
25
|
+
* can directly return an output.
|
|
26
|
+
*/
|
|
27
|
+
export declare type SimpleJobHandlerFn<A extends JsonValue, I extends JsonValue, O extends JsonValue> = (input: A, context: SimpleJobHandlerContext<A, I, O>) => O | Promise<O> | Observable<O>;
|
|
28
|
+
/**
|
|
29
|
+
* Make a simple job handler that sets start and end from a function that's synchronous.
|
|
30
|
+
*
|
|
31
|
+
* @param fn The function to create a handler for.
|
|
32
|
+
* @param options An optional set of properties to set on the handler. Some fields might be
|
|
33
|
+
* required by registry or schedulers.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createJobHandler<A extends JsonValue, I extends JsonValue, O extends JsonValue>(fn: SimpleJobHandlerFn<A, I, O>, options?: Partial<JobDescription>): JobHandler<A, I, O>;
|
|
36
|
+
/**
|
|
37
|
+
* Lazily create a job using a function.
|
|
38
|
+
* @param loader A factory function that returns a promise/observable of a JobHandler.
|
|
39
|
+
* @param options Same options as createJob.
|
|
40
|
+
*/
|
|
41
|
+
export 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>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a job that logs out input/output messages of another Job. The messages are still
|
|
44
|
+
* propagated to the other job.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createLoggerJob<A extends JsonValue, I extends JsonValue, O extends JsonValue>(job: JobHandler<A, I, O>, logger: logging.LoggerApi): JobHandler<A, I, O>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createLoggerJob = exports.createJobFactory = exports.createJobHandler = exports.ChannelAlreadyExistException = void 0;
|
|
11
|
+
const core_1 = require("@angular-devkit/core");
|
|
12
|
+
const rxjs_1 = require("rxjs");
|
|
13
|
+
const operators_1 = require("rxjs/operators");
|
|
14
|
+
const api_1 = require("./api");
|
|
15
|
+
class ChannelAlreadyExistException extends core_1.BaseException {
|
|
16
|
+
constructor(name) {
|
|
17
|
+
super(`Channel ${JSON.stringify(name)} already exist.`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ChannelAlreadyExistException = ChannelAlreadyExistException;
|
|
21
|
+
/**
|
|
22
|
+
* Make a simple job handler that sets start and end from a function that's synchronous.
|
|
23
|
+
*
|
|
24
|
+
* @param fn The function to create a handler for.
|
|
25
|
+
* @param options An optional set of properties to set on the handler. Some fields might be
|
|
26
|
+
* required by registry or schedulers.
|
|
27
|
+
*/
|
|
28
|
+
function createJobHandler(fn, options = {}) {
|
|
29
|
+
const handler = (argument, context) => {
|
|
30
|
+
const description = context.description;
|
|
31
|
+
const inboundBus = context.inboundBus;
|
|
32
|
+
const inputChannel = new rxjs_1.Subject();
|
|
33
|
+
let subscription;
|
|
34
|
+
return new rxjs_1.Observable((subject) => {
|
|
35
|
+
function complete() {
|
|
36
|
+
if (subscription) {
|
|
37
|
+
subscription.unsubscribe();
|
|
38
|
+
}
|
|
39
|
+
subject.next({ kind: api_1.JobOutboundMessageKind.End, description });
|
|
40
|
+
subject.complete();
|
|
41
|
+
inputChannel.complete();
|
|
42
|
+
}
|
|
43
|
+
// Handle input.
|
|
44
|
+
const inboundSub = inboundBus.subscribe((message) => {
|
|
45
|
+
switch (message.kind) {
|
|
46
|
+
case api_1.JobInboundMessageKind.Ping:
|
|
47
|
+
subject.next({ kind: api_1.JobOutboundMessageKind.Pong, description, id: message.id });
|
|
48
|
+
break;
|
|
49
|
+
case api_1.JobInboundMessageKind.Stop:
|
|
50
|
+
// There's no way to cancel a promise or a synchronous function, but we do cancel
|
|
51
|
+
// observables where possible.
|
|
52
|
+
complete();
|
|
53
|
+
break;
|
|
54
|
+
case api_1.JobInboundMessageKind.Input:
|
|
55
|
+
inputChannel.next(message.value);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
// Execute the function with the additional context.
|
|
60
|
+
const channels = new Map();
|
|
61
|
+
const newContext = {
|
|
62
|
+
...context,
|
|
63
|
+
input: inputChannel.asObservable(),
|
|
64
|
+
createChannel(name) {
|
|
65
|
+
if (channels.has(name)) {
|
|
66
|
+
throw new ChannelAlreadyExistException(name);
|
|
67
|
+
}
|
|
68
|
+
const channelSubject = new rxjs_1.Subject();
|
|
69
|
+
const channelSub = channelSubject.subscribe((message) => {
|
|
70
|
+
subject.next({
|
|
71
|
+
kind: api_1.JobOutboundMessageKind.ChannelMessage,
|
|
72
|
+
description,
|
|
73
|
+
name,
|
|
74
|
+
message,
|
|
75
|
+
});
|
|
76
|
+
}, (error) => {
|
|
77
|
+
subject.next({ kind: api_1.JobOutboundMessageKind.ChannelError, description, name, error });
|
|
78
|
+
// This can be reopened.
|
|
79
|
+
channels.delete(name);
|
|
80
|
+
}, () => {
|
|
81
|
+
subject.next({ kind: api_1.JobOutboundMessageKind.ChannelComplete, description, name });
|
|
82
|
+
// This can be reopened.
|
|
83
|
+
channels.delete(name);
|
|
84
|
+
});
|
|
85
|
+
channels.set(name, channelSubject);
|
|
86
|
+
if (subscription) {
|
|
87
|
+
subscription.add(channelSub);
|
|
88
|
+
}
|
|
89
|
+
return channelSubject;
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
subject.next({ kind: api_1.JobOutboundMessageKind.Start, description });
|
|
93
|
+
let result = fn(argument, newContext);
|
|
94
|
+
// If the result is a promise, simply wait for it to complete before reporting the result.
|
|
95
|
+
if ((0, core_1.isPromise)(result)) {
|
|
96
|
+
result = (0, rxjs_1.from)(result);
|
|
97
|
+
}
|
|
98
|
+
else if (!(0, rxjs_1.isObservable)(result)) {
|
|
99
|
+
result = (0, rxjs_1.of)(result);
|
|
100
|
+
}
|
|
101
|
+
subscription = result.subscribe((value) => subject.next({ kind: api_1.JobOutboundMessageKind.Output, description, value }), (error) => subject.error(error), () => complete());
|
|
102
|
+
subscription.add(inboundSub);
|
|
103
|
+
return subscription;
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
return Object.assign(handler, { jobDescription: options });
|
|
107
|
+
}
|
|
108
|
+
exports.createJobHandler = createJobHandler;
|
|
109
|
+
/**
|
|
110
|
+
* Lazily create a job using a function.
|
|
111
|
+
* @param loader A factory function that returns a promise/observable of a JobHandler.
|
|
112
|
+
* @param options Same options as createJob.
|
|
113
|
+
*/
|
|
114
|
+
function createJobFactory(loader, options = {}) {
|
|
115
|
+
const handler = (argument, context) => {
|
|
116
|
+
return (0, rxjs_1.from)(loader()).pipe((0, operators_1.switchMap)((fn) => fn(argument, context)));
|
|
117
|
+
};
|
|
118
|
+
return Object.assign(handler, { jobDescription: options });
|
|
119
|
+
}
|
|
120
|
+
exports.createJobFactory = createJobFactory;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a job that logs out input/output messages of another Job. The messages are still
|
|
123
|
+
* propagated to the other job.
|
|
124
|
+
*/
|
|
125
|
+
function createLoggerJob(job, logger) {
|
|
126
|
+
const handler = (argument, context) => {
|
|
127
|
+
context.inboundBus
|
|
128
|
+
.pipe((0, operators_1.tap)((message) => logger.info(`Input: ${JSON.stringify(message)}`)))
|
|
129
|
+
.subscribe();
|
|
130
|
+
return job(argument, context).pipe((0, operators_1.tap)((message) => logger.info(`Message: ${JSON.stringify(message)}`), (error) => logger.warn(`Error: ${JSON.stringify(error)}`), () => logger.info(`Completed`)));
|
|
131
|
+
};
|
|
132
|
+
return Object.assign(handler, job);
|
|
133
|
+
}
|
|
134
|
+
exports.createLoggerJob = createLoggerJob;
|
|
@@ -0,0 +1,31 @@
|
|
|
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.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { JsonValue } from '@angular-devkit/core';
|
|
9
|
+
import { JobDescription, JobHandler, JobName } from './api';
|
|
10
|
+
import { Readwrite } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* A JobDispatcher can be used to dispatch between multiple jobs.
|
|
13
|
+
*/
|
|
14
|
+
export interface JobDispatcher<A extends JsonValue, I extends JsonValue, O extends JsonValue> extends JobHandler<A, I, O> {
|
|
15
|
+
/**
|
|
16
|
+
* Set the default job if all conditionals failed.
|
|
17
|
+
* @param name The default name if all conditions are false.
|
|
18
|
+
*/
|
|
19
|
+
setDefaultJob(name: JobName | null | JobHandler<JsonValue, JsonValue, JsonValue>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Add a conditional job that will be selected if the input fits a predicate.
|
|
22
|
+
* @param predicate
|
|
23
|
+
* @param name
|
|
24
|
+
*/
|
|
25
|
+
addConditionalJob(predicate: (args: A) => boolean, name: string): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* OnReady a dispatcher that can dispatch to a sub job, depending on conditions.
|
|
29
|
+
* @param options
|
|
30
|
+
*/
|
|
31
|
+
export declare function createDispatcher<A extends JsonValue, I extends JsonValue, O extends JsonValue>(options?: Partial<Readwrite<JobDescription>>): JobDispatcher<A, I, O>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createDispatcher = void 0;
|
|
11
|
+
const api_1 = require("./api");
|
|
12
|
+
const exception_1 = require("./exception");
|
|
13
|
+
/**
|
|
14
|
+
* OnReady a dispatcher that can dispatch to a sub job, depending on conditions.
|
|
15
|
+
* @param options
|
|
16
|
+
*/
|
|
17
|
+
function createDispatcher(options = {}) {
|
|
18
|
+
let defaultDelegate = null;
|
|
19
|
+
const conditionalDelegateList = [];
|
|
20
|
+
const job = Object.assign((argument, context) => {
|
|
21
|
+
const maybeDelegate = conditionalDelegateList.find(([predicate]) => predicate(argument));
|
|
22
|
+
let delegate = null;
|
|
23
|
+
if (maybeDelegate) {
|
|
24
|
+
delegate = context.scheduler.schedule(maybeDelegate[1], argument);
|
|
25
|
+
}
|
|
26
|
+
else if (defaultDelegate) {
|
|
27
|
+
delegate = context.scheduler.schedule(defaultDelegate, argument);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new exception_1.JobDoesNotExistException('<null>');
|
|
31
|
+
}
|
|
32
|
+
context.inboundBus.subscribe(delegate.inboundBus);
|
|
33
|
+
return delegate.outboundBus;
|
|
34
|
+
}, {
|
|
35
|
+
jobDescription: options,
|
|
36
|
+
});
|
|
37
|
+
return Object.assign(job, {
|
|
38
|
+
setDefaultJob(name) {
|
|
39
|
+
if ((0, api_1.isJobHandler)(name)) {
|
|
40
|
+
name = name.jobDescription.name === undefined ? null : name.jobDescription.name;
|
|
41
|
+
}
|
|
42
|
+
defaultDelegate = name;
|
|
43
|
+
},
|
|
44
|
+
addConditionalJob(predicate, name) {
|
|
45
|
+
conditionalDelegateList.push([predicate, name]);
|
|
46
|
+
},
|
|
47
|
+
// TODO: Remove return-only generic from createDispatcher() API.
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.createDispatcher = createDispatcher;
|
|
@@ -0,0 +1,15 @@
|
|
|
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.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { BaseException } from '@angular-devkit/core';
|
|
9
|
+
import { JobName } from './api';
|
|
10
|
+
export declare class JobNameAlreadyRegisteredException extends BaseException {
|
|
11
|
+
constructor(name: JobName);
|
|
12
|
+
}
|
|
13
|
+
export declare class JobDoesNotExistException extends BaseException {
|
|
14
|
+
constructor(name: JobName);
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.JobDoesNotExistException = exports.JobNameAlreadyRegisteredException = void 0;
|
|
11
|
+
const core_1 = require("@angular-devkit/core");
|
|
12
|
+
class JobNameAlreadyRegisteredException extends core_1.BaseException {
|
|
13
|
+
constructor(name) {
|
|
14
|
+
super(`Job named ${JSON.stringify(name)} already exists.`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.JobNameAlreadyRegisteredException = JobNameAlreadyRegisteredException;
|
|
18
|
+
class JobDoesNotExistException extends core_1.BaseException {
|
|
19
|
+
constructor(name) {
|
|
20
|
+
super(`Job name ${JSON.stringify(name)} does not exist.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.JobDoesNotExistException = JobDoesNotExistException;
|
|
@@ -0,0 +1,19 @@
|
|
|
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.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { JsonValue } from '@angular-devkit/core';
|
|
9
|
+
import { Observable } from 'rxjs';
|
|
10
|
+
import { JobHandler, JobName, Registry } from './api';
|
|
11
|
+
/**
|
|
12
|
+
* A simple job registry that keep a map of JobName => JobHandler internally.
|
|
13
|
+
*/
|
|
14
|
+
export declare class FallbackRegistry<MinimumArgumentValueT extends JsonValue = JsonValue, MinimumInputValueT extends JsonValue = JsonValue, MinimumOutputValueT extends JsonValue = JsonValue> implements Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT> {
|
|
15
|
+
protected _fallbacks: Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT>[];
|
|
16
|
+
constructor(_fallbacks?: Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT>[]);
|
|
17
|
+
addFallback(registry: Registry): void;
|
|
18
|
+
get<A extends MinimumArgumentValueT = MinimumArgumentValueT, I extends MinimumInputValueT = MinimumInputValueT, O extends MinimumOutputValueT = MinimumOutputValueT>(name: JobName): Observable<JobHandler<A, I, O> | null>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.FallbackRegistry = void 0;
|
|
11
|
+
const rxjs_1 = require("rxjs");
|
|
12
|
+
const operators_1 = require("rxjs/operators");
|
|
13
|
+
/**
|
|
14
|
+
* A simple job registry that keep a map of JobName => JobHandler internally.
|
|
15
|
+
*/
|
|
16
|
+
class FallbackRegistry {
|
|
17
|
+
constructor(_fallbacks = []) {
|
|
18
|
+
this._fallbacks = _fallbacks;
|
|
19
|
+
}
|
|
20
|
+
addFallback(registry) {
|
|
21
|
+
this._fallbacks.push(registry);
|
|
22
|
+
}
|
|
23
|
+
get(name) {
|
|
24
|
+
return (0, rxjs_1.from)(this._fallbacks).pipe((0, operators_1.concatMap)((fb) => fb.get(name)), (0, operators_1.first)((x) => x !== null, null));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.FallbackRegistry = FallbackRegistry;
|
|
@@ -0,0 +1,15 @@
|
|
|
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.io/license
|
|
7
|
+
*/
|
|
8
|
+
export * from './api';
|
|
9
|
+
export * from './create-job-handler';
|
|
10
|
+
export * from './exception';
|
|
11
|
+
export * from './dispatcher';
|
|
12
|
+
export * from './fallback-registry';
|
|
13
|
+
export * from './simple-registry';
|
|
14
|
+
export * from './simple-scheduler';
|
|
15
|
+
export * from './strategy';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
__exportStar(require("./api"), exports);
|
|
25
|
+
__exportStar(require("./create-job-handler"), exports);
|
|
26
|
+
__exportStar(require("./exception"), exports);
|
|
27
|
+
__exportStar(require("./dispatcher"), exports);
|
|
28
|
+
__exportStar(require("./fallback-registry"), exports);
|
|
29
|
+
__exportStar(require("./simple-registry"), exports);
|
|
30
|
+
__exportStar(require("./simple-scheduler"), exports);
|
|
31
|
+
__exportStar(require("./strategy"), exports);
|
|
@@ -0,0 +1,44 @@
|
|
|
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.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { JsonValue } from '@angular-devkit/core';
|
|
9
|
+
import { Observable } from 'rxjs';
|
|
10
|
+
import { JobDescription, JobHandler, JobName, Registry } from './api';
|
|
11
|
+
/**
|
|
12
|
+
* SimpleJobRegistry job registration options.
|
|
13
|
+
*/
|
|
14
|
+
export interface RegisterJobOptions extends Partial<JobDescription> {
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A simple job registry that keep a map of JobName => JobHandler internally.
|
|
18
|
+
*/
|
|
19
|
+
export declare class SimpleJobRegistry<MinimumArgumentValueT extends JsonValue = JsonValue, MinimumInputValueT extends JsonValue = JsonValue, MinimumOutputValueT extends JsonValue = JsonValue> implements Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT> {
|
|
20
|
+
private _jobNames;
|
|
21
|
+
get<A extends MinimumArgumentValueT = MinimumArgumentValueT, I extends MinimumInputValueT = MinimumInputValueT, O extends MinimumOutputValueT = MinimumOutputValueT>(name: JobName): Observable<JobHandler<A, I, O> | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Register a job handler. The name must be unique.
|
|
24
|
+
*
|
|
25
|
+
* @param name The name of the job.
|
|
26
|
+
* @param handler The function that will be called for the job.
|
|
27
|
+
* @param options An optional list of options to override the handler. {@see RegisterJobOptions}
|
|
28
|
+
*/
|
|
29
|
+
register<A extends MinimumArgumentValueT, I extends MinimumInputValueT, O extends MinimumOutputValueT>(name: JobName, handler: JobHandler<A, I, O>, options?: RegisterJobOptions): void;
|
|
30
|
+
/**
|
|
31
|
+
* Register a job handler. The name must be unique.
|
|
32
|
+
*
|
|
33
|
+
* @param handler The function that will be called for the job.
|
|
34
|
+
* @param options An optional list of options to override the handler. {@see RegisterJobOptions}
|
|
35
|
+
*/
|
|
36
|
+
register<ArgumentT extends JsonValue, InputT extends JsonValue, OutputT extends JsonValue>(handler: JobHandler<ArgumentT, InputT, OutputT>, options?: RegisterJobOptions & {
|
|
37
|
+
name: string;
|
|
38
|
+
}): void;
|
|
39
|
+
protected _register<ArgumentT extends JsonValue, InputT extends JsonValue, OutputT extends JsonValue>(name: JobName, handler: JobHandler<ArgumentT, InputT, OutputT>, options: RegisterJobOptions): void;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the job names of all jobs.
|
|
42
|
+
*/
|
|
43
|
+
getJobNames(): JobName[];
|
|
44
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SimpleJobRegistry = void 0;
|
|
11
|
+
const core_1 = require("@angular-devkit/core");
|
|
12
|
+
const rxjs_1 = require("rxjs");
|
|
13
|
+
const api_1 = require("./api");
|
|
14
|
+
const exception_1 = require("./exception");
|
|
15
|
+
/**
|
|
16
|
+
* A simple job registry that keep a map of JobName => JobHandler internally.
|
|
17
|
+
*/
|
|
18
|
+
class SimpleJobRegistry {
|
|
19
|
+
constructor() {
|
|
20
|
+
this._jobNames = new Map();
|
|
21
|
+
}
|
|
22
|
+
get(name) {
|
|
23
|
+
return (0, rxjs_1.of)(this._jobNames.get(name) || null);
|
|
24
|
+
}
|
|
25
|
+
register(nameOrHandler, handlerOrOptions = {}, options = {}) {
|
|
26
|
+
// Switch on the arguments.
|
|
27
|
+
if (typeof nameOrHandler == 'string') {
|
|
28
|
+
if (!(0, api_1.isJobHandler)(handlerOrOptions)) {
|
|
29
|
+
// This is an error.
|
|
30
|
+
throw new TypeError('Expected a JobHandler as second argument.');
|
|
31
|
+
}
|
|
32
|
+
this._register(nameOrHandler, handlerOrOptions, options);
|
|
33
|
+
}
|
|
34
|
+
else if ((0, api_1.isJobHandler)(nameOrHandler)) {
|
|
35
|
+
if (typeof handlerOrOptions !== 'object') {
|
|
36
|
+
// This is an error.
|
|
37
|
+
throw new TypeError('Expected an object options as second argument.');
|
|
38
|
+
}
|
|
39
|
+
const name = options.name || nameOrHandler.jobDescription.name || handlerOrOptions.name;
|
|
40
|
+
if (name === undefined) {
|
|
41
|
+
throw new TypeError('Expected name to be a string.');
|
|
42
|
+
}
|
|
43
|
+
this._register(name, nameOrHandler, options);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new TypeError('Unrecognized arguments.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
_register(name, handler, options) {
|
|
50
|
+
if (this._jobNames.has(name)) {
|
|
51
|
+
// We shouldn't allow conflicts.
|
|
52
|
+
throw new exception_1.JobNameAlreadyRegisteredException(name);
|
|
53
|
+
}
|
|
54
|
+
// Merge all fields with the ones in the handler (to make sure we respect the handler).
|
|
55
|
+
const argument = core_1.schema.mergeSchemas(handler.jobDescription.argument, options.argument);
|
|
56
|
+
const input = core_1.schema.mergeSchemas(handler.jobDescription.input, options.input);
|
|
57
|
+
const output = core_1.schema.mergeSchemas(handler.jobDescription.output, options.output);
|
|
58
|
+
// Create the job description.
|
|
59
|
+
const jobDescription = {
|
|
60
|
+
name,
|
|
61
|
+
argument,
|
|
62
|
+
output,
|
|
63
|
+
input,
|
|
64
|
+
};
|
|
65
|
+
const jobHandler = Object.assign(handler.bind(undefined), {
|
|
66
|
+
jobDescription,
|
|
67
|
+
});
|
|
68
|
+
this._jobNames.set(name, jobHandler);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns the job names of all jobs.
|
|
72
|
+
*/
|
|
73
|
+
getJobNames() {
|
|
74
|
+
return [...this._jobNames.keys()];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.SimpleJobRegistry = SimpleJobRegistry;
|
|
@@ -0,0 +1,77 @@
|
|
|
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.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { JsonValue, schema } from '@angular-devkit/core';
|
|
9
|
+
import { Observable } from 'rxjs';
|
|
10
|
+
import { Job, JobDescription, JobName, Registry, ScheduleJobOptions, Scheduler } from './api';
|
|
11
|
+
export declare class JobArgumentSchemaValidationError extends schema.SchemaValidationException {
|
|
12
|
+
constructor(errors?: schema.SchemaValidatorError[]);
|
|
13
|
+
}
|
|
14
|
+
export declare class JobInboundMessageSchemaValidationError extends schema.SchemaValidationException {
|
|
15
|
+
constructor(errors?: schema.SchemaValidatorError[]);
|
|
16
|
+
}
|
|
17
|
+
export declare class JobOutputSchemaValidationError extends schema.SchemaValidationException {
|
|
18
|
+
constructor(errors?: schema.SchemaValidatorError[]);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Simple scheduler. Should be the base of all registries and schedulers.
|
|
22
|
+
*/
|
|
23
|
+
export declare class SimpleScheduler<MinimumArgumentT extends JsonValue = JsonValue, MinimumInputT extends JsonValue = JsonValue, MinimumOutputT extends JsonValue = JsonValue> implements Scheduler<MinimumArgumentT, MinimumInputT, MinimumOutputT> {
|
|
24
|
+
protected _jobRegistry: Registry<MinimumArgumentT, MinimumInputT, MinimumOutputT>;
|
|
25
|
+
protected _schemaRegistry: schema.SchemaRegistry;
|
|
26
|
+
private _internalJobDescriptionMap;
|
|
27
|
+
private _queue;
|
|
28
|
+
private _pauseCounter;
|
|
29
|
+
constructor(_jobRegistry: Registry<MinimumArgumentT, MinimumInputT, MinimumOutputT>, _schemaRegistry?: schema.SchemaRegistry);
|
|
30
|
+
private _getInternalDescription;
|
|
31
|
+
/**
|
|
32
|
+
* Get a job description for a named job.
|
|
33
|
+
*
|
|
34
|
+
* @param name The name of the job.
|
|
35
|
+
* @returns A description, or null if the job is not registered.
|
|
36
|
+
*/
|
|
37
|
+
getDescription(name: JobName): Observable<JobDescription | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Returns true if the job name has been registered.
|
|
40
|
+
* @param name The name of the job.
|
|
41
|
+
* @returns True if the job exists, false otherwise.
|
|
42
|
+
*/
|
|
43
|
+
has(name: JobName): Observable<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Pause the scheduler, temporary queueing _new_ jobs. Returns a resume function that should be
|
|
46
|
+
* used to resume execution. If multiple `pause()` were called, all their resume functions must
|
|
47
|
+
* be called before the Scheduler actually starts new jobs. Additional calls to the same resume
|
|
48
|
+
* function will have no effect.
|
|
49
|
+
*
|
|
50
|
+
* Jobs already running are NOT paused. This is pausing the scheduler only.
|
|
51
|
+
*/
|
|
52
|
+
pause(): () => void;
|
|
53
|
+
/**
|
|
54
|
+
* Schedule a job to be run, using its name.
|
|
55
|
+
* @param name The name of job to be run.
|
|
56
|
+
* @param argument The argument to send to the job when starting it.
|
|
57
|
+
* @param options Scheduling options.
|
|
58
|
+
* @returns The Job being run.
|
|
59
|
+
*/
|
|
60
|
+
schedule<A extends MinimumArgumentT, I extends MinimumInputT, O extends MinimumOutputT>(name: JobName, argument: A, options?: ScheduleJobOptions): Job<A, I, O>;
|
|
61
|
+
/**
|
|
62
|
+
* Filter messages.
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
private _filterJobOutboundMessages;
|
|
66
|
+
/**
|
|
67
|
+
* Return a new state. This is just to simplify the reading of the _createJob method.
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
private _updateState;
|
|
71
|
+
/**
|
|
72
|
+
* Create the job.
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
private _createJob;
|
|
76
|
+
protected _scheduleJob<A extends MinimumArgumentT, I extends MinimumInputT, O extends MinimumOutputT>(name: JobName, argument: A, options: ScheduleJobOptions, waitable: Observable<never>): Job<A, I, O>;
|
|
77
|
+
}
|