@depup/angular-devkit__architect 0.2102.2-depup.0
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/LICENSE +21 -0
- package/README.md +25 -0
- package/bin/architect.d.ts +9 -0
- package/bin/architect.js +252 -0
- package/bin/architect.js.map +1 -0
- package/bin/cli.js +10 -0
- package/builders/all-of.d.ts +11 -0
- package/builders/all-of.js +49 -0
- package/builders/all-of.js.map +1 -0
- package/builders/builders.json +25 -0
- package/builders/concat.d.ts +11 -0
- package/builders/concat.js +46 -0
- package/builders/concat.js.map +1 -0
- package/builders/false.d.ts +10 -0
- package/builders/false.js +16 -0
- package/builders/false.js.map +1 -0
- package/builders/noop-schema.json +4 -0
- package/builders/operator-schema.d.ts +22 -0
- package/builders/operator-schema.js +5 -0
- package/builders/operator-schema.js.map +1 -0
- package/builders/operator-schema.json +41 -0
- package/builders/true.d.ts +10 -0
- package/builders/true.js +13 -0
- package/builders/true.js.map +1 -0
- package/changes.json +5 -0
- package/index.d.ts +8 -0
- package/index.js +25 -0
- package/index.js.map +1 -0
- package/node/index.d.ts +10 -0
- package/node/index.js +50 -0
- package/node/index.js.map +1 -0
- package/node/jobs/job-registry.d.ts +20 -0
- package/node/jobs/job-registry.js +60 -0
- package/node/jobs/job-registry.js.map +1 -0
- package/node/node-modules-architect-host.d.ts +41 -0
- package/node/node-modules-architect-host.js +242 -0
- package/node/node-modules-architect-host.js.map +1 -0
- package/package.json +51 -0
- package/src/api.d.ts +269 -0
- package/src/api.js +98 -0
- package/src/api.js.map +1 -0
- package/src/architect.d.ts +25 -0
- package/src/architect.js +268 -0
- package/src/architect.js.map +1 -0
- package/src/builders-schema.d.ts +33 -0
- package/src/builders-schema.js +5 -0
- package/src/builders-schema.js.map +1 -0
- package/src/builders-schema.json +70 -0
- package/src/create-builder.d.ts +12 -0
- package/src/create-builder.js +184 -0
- package/src/create-builder.js.map +1 -0
- package/src/index.d.ts +12 -0
- package/src/index.js +54 -0
- package/src/index.js.map +1 -0
- package/src/input-schema.d.ts +19 -0
- package/src/input-schema.js +5 -0
- package/src/input-schema.js.map +1 -0
- package/src/input-schema.json +39 -0
- package/src/internal.d.ts +68 -0
- package/src/internal.js +27 -0
- package/src/internal.js.map +1 -0
- package/src/jobs/api.d.ts +332 -0
- package/src/jobs/api.js +74 -0
- package/src/jobs/api.js.map +1 -0
- package/src/jobs/create-job-handler.d.ts +47 -0
- package/src/jobs/create-job-handler.js +146 -0
- package/src/jobs/create-job-handler.js.map +1 -0
- package/src/jobs/dispatcher.d.ts +31 -0
- package/src/jobs/dispatcher.js +50 -0
- package/src/jobs/dispatcher.js.map +1 -0
- package/src/jobs/exception.d.ts +15 -0
- package/src/jobs/exception.js +24 -0
- package/src/jobs/exception.js.map +1 -0
- package/src/jobs/fallback-registry.d.ts +19 -0
- package/src/jobs/fallback-registry.js +28 -0
- package/src/jobs/fallback-registry.js.map +1 -0
- package/src/jobs/index.d.ts +16 -0
- package/src/jobs/index.js +56 -0
- package/src/jobs/index.js.map +1 -0
- package/src/jobs/simple-registry.d.ts +44 -0
- package/src/jobs/simple-registry.js +76 -0
- package/src/jobs/simple-registry.js.map +1 -0
- package/src/jobs/simple-scheduler.d.ts +77 -0
- package/src/jobs/simple-scheduler.js +395 -0
- package/src/jobs/simple-scheduler.js.map +1 -0
- package/src/jobs/strategy.d.ts +26 -0
- package/src/jobs/strategy.js +94 -0
- package/src/jobs/strategy.js.map +1 -0
- package/src/jobs/types.d.ts +15 -0
- package/src/jobs/types.js +10 -0
- package/src/jobs/types.js.map +1 -0
- package/src/options.d.ts +12 -0
- package/src/options.js +30 -0
- package/src/options.js.map +1 -0
- package/src/output-schema.d.ts +15 -0
- package/src/output-schema.js +5 -0
- package/src/output-schema.js.map +1 -0
- package/src/output-schema.json +33 -0
- package/src/progress-schema.d.ts +21 -0
- package/src/progress-schema.js +13 -0
- package/src/progress-schema.js.map +1 -0
- package/src/progress-schema.json +83 -0
- package/src/schedule-by-name.d.ts +23 -0
- package/src/schedule-by-name.js +101 -0
- package/src/schedule-by-name.js.map +1 -0
- package/src/targets-schema.json +39 -0
- package/testing/index.d.ts +9 -0
- package/testing/index.js +26 -0
- package/testing/index.js.map +1 -0
- package/testing/test-project-host.d.ts +32 -0
- package/testing/test-project-host.js +110 -0
- package/testing/test-project-host.js.map +1 -0
- package/testing/testing-architect-host.d.ts +42 -0
- package/testing/testing-architect-host.js +135 -0
- package/testing/testing-architect-host.js.map +1 -0
|
@@ -0,0 +1,332 @@
|
|
|
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
|
+
*/
|
|
8
|
+
import { JsonObject, JsonValue, schema } from '@angular-devkit/core';
|
|
9
|
+
import { Observable, Observer } from 'rxjs';
|
|
10
|
+
import { DeepReadonly } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* A job name is just a string (needs to be serializable).
|
|
13
|
+
*/
|
|
14
|
+
export type JobName = string;
|
|
15
|
+
/**
|
|
16
|
+
* The job handler function, which is a method that's executed for the job.
|
|
17
|
+
*/
|
|
18
|
+
export interface JobHandler<ArgT extends JsonValue, InputT extends JsonValue, OutputT extends JsonValue> {
|
|
19
|
+
(argument: ArgT, context: JobHandlerContext<ArgT, InputT, OutputT>): Observable<JobOutboundMessage<OutputT>>;
|
|
20
|
+
jobDescription: Partial<JobDescription>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The context in which the job is run.
|
|
24
|
+
*/
|
|
25
|
+
export interface JobHandlerContext<MinimumArgumentValueT extends JsonValue = JsonValue, MinimumInputValueT extends JsonValue = JsonValue, MinimumOutputValueT extends JsonValue = JsonValue> {
|
|
26
|
+
readonly description: JobDescription;
|
|
27
|
+
readonly scheduler: Scheduler<JsonValue, JsonValue, JsonValue>;
|
|
28
|
+
readonly dependencies: Job<JsonValue, JsonValue, JsonValue>[];
|
|
29
|
+
readonly inboundBus: Observable<JobInboundMessage<MinimumInputValueT>>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Metadata associated with a job.
|
|
33
|
+
*/
|
|
34
|
+
export interface JobDescription extends JsonObject {
|
|
35
|
+
readonly name: JobName;
|
|
36
|
+
readonly argument: DeepReadonly<schema.JsonSchema>;
|
|
37
|
+
readonly input: DeepReadonly<schema.JsonSchema>;
|
|
38
|
+
readonly output: DeepReadonly<schema.JsonSchema>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Messages that can be sent TO a job. The job needs to listen to those.
|
|
42
|
+
*/
|
|
43
|
+
export declare enum JobInboundMessageKind {
|
|
44
|
+
Ping = "ip",
|
|
45
|
+
Stop = "is",
|
|
46
|
+
Input = "in"
|
|
47
|
+
}
|
|
48
|
+
/** Base interface for the all job inbound messages. */
|
|
49
|
+
export interface JobInboundMessageBase extends JsonObject {
|
|
50
|
+
/**
|
|
51
|
+
* The kind of message this is.
|
|
52
|
+
*/
|
|
53
|
+
readonly kind: JobInboundMessageKind;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A ping to the job. The job should reply with a pong as soon as possible.
|
|
57
|
+
*/
|
|
58
|
+
export interface JobInboundMessagePing extends JobInboundMessageBase {
|
|
59
|
+
readonly kind: JobInboundMessageKind.Ping;
|
|
60
|
+
/**
|
|
61
|
+
* An ID that should be returned in the corresponding Pong.
|
|
62
|
+
*/
|
|
63
|
+
readonly id: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Stop the job. This is handled by the job itself and jobs might not handle it. It will also
|
|
67
|
+
* unsubscribe from the Observable<>.
|
|
68
|
+
* This is equivalent to SIGTERM.
|
|
69
|
+
*/
|
|
70
|
+
export interface JobInboundMessageStop extends JobInboundMessageBase {
|
|
71
|
+
readonly kind: JobInboundMessageKind.Stop;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A Job wants to send a message to a channel. This can be marshaled, and the Job object
|
|
75
|
+
* has helpers to transform this into an observable. The context also can create RxJS subjects that
|
|
76
|
+
* marshall messages through a channel.
|
|
77
|
+
*/
|
|
78
|
+
export interface JobInboundMessageInput<InputT extends JsonValue> extends JobInboundMessageBase {
|
|
79
|
+
readonly kind: JobInboundMessageKind.Input;
|
|
80
|
+
/**
|
|
81
|
+
* The input being sent to the job.
|
|
82
|
+
*/
|
|
83
|
+
readonly value: InputT;
|
|
84
|
+
}
|
|
85
|
+
export type JobInboundMessage<InputT extends JsonValue> = JobInboundMessagePing | JobInboundMessageStop | JobInboundMessageInput<InputT>;
|
|
86
|
+
/**
|
|
87
|
+
* Kind of messages that can be outputted from a job.
|
|
88
|
+
*/
|
|
89
|
+
export declare enum JobOutboundMessageKind {
|
|
90
|
+
OnReady = "c",
|
|
91
|
+
Start = "s",
|
|
92
|
+
End = "e",
|
|
93
|
+
Pong = "p",
|
|
94
|
+
Output = "o",
|
|
95
|
+
ChannelCreate = "cn",
|
|
96
|
+
ChannelMessage = "cm",
|
|
97
|
+
ChannelError = "ce",
|
|
98
|
+
ChannelComplete = "cc"
|
|
99
|
+
}
|
|
100
|
+
/** Base interface for the all job messages. */
|
|
101
|
+
export interface JobOutboundMessageBase {
|
|
102
|
+
/**
|
|
103
|
+
* The job description.
|
|
104
|
+
*/
|
|
105
|
+
readonly description: JobDescription;
|
|
106
|
+
/**
|
|
107
|
+
* The kind of message this is.
|
|
108
|
+
*/
|
|
109
|
+
readonly kind: JobOutboundMessageKind;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The job has been created and will validate its input.
|
|
113
|
+
*/
|
|
114
|
+
export interface JobOutboundMessageOnReady extends JobOutboundMessageBase {
|
|
115
|
+
readonly kind: JobOutboundMessageKind.OnReady;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The job started. This is done by the job itself.
|
|
119
|
+
*/
|
|
120
|
+
export interface JobOutboundMessageStart extends JobOutboundMessageBase {
|
|
121
|
+
readonly kind: JobOutboundMessageKind.Start;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* An output value is available.
|
|
125
|
+
*/
|
|
126
|
+
export interface JobOutboundMessageOutput<OutputT extends JsonValue> extends JobOutboundMessageBase {
|
|
127
|
+
readonly kind: JobOutboundMessageKind.Output;
|
|
128
|
+
/**
|
|
129
|
+
* The message being outputted from the job.
|
|
130
|
+
*/
|
|
131
|
+
readonly value: OutputT;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Base interface for all job message related to channels.
|
|
135
|
+
*/
|
|
136
|
+
export interface JobOutboundMessageChannelBase extends JobOutboundMessageBase {
|
|
137
|
+
/**
|
|
138
|
+
* The name of the channel.
|
|
139
|
+
*/
|
|
140
|
+
readonly name: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A job wants to send a message to a channel. This can be marshaled, and the Job object
|
|
144
|
+
* has helpers to transform this into an observable. The context also can create RxJS subjects that
|
|
145
|
+
* marshall messages through a channel.
|
|
146
|
+
*/
|
|
147
|
+
export interface JobOutboundMessageChannelMessage extends JobOutboundMessageChannelBase {
|
|
148
|
+
readonly kind: JobOutboundMessageKind.ChannelMessage;
|
|
149
|
+
/**
|
|
150
|
+
* The message being sent to the channel.
|
|
151
|
+
*/
|
|
152
|
+
readonly message: JsonValue;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* A job wants to send an error to one of its channel. This is the equivalent of throwing through
|
|
156
|
+
* an Observable. The side channel will not receive any more messages after this, and will not
|
|
157
|
+
* complete.
|
|
158
|
+
*/
|
|
159
|
+
export interface JobOutboundMessageChannelError extends JobOutboundMessageChannelBase {
|
|
160
|
+
readonly kind: JobOutboundMessageKind.ChannelError;
|
|
161
|
+
/**
|
|
162
|
+
* The error message being sent to the channel.
|
|
163
|
+
*/
|
|
164
|
+
readonly error: JsonValue;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* A job wants to create a new channel.
|
|
168
|
+
*/
|
|
169
|
+
export interface JobOutboundMessageChannelCreate extends JobOutboundMessageChannelBase {
|
|
170
|
+
readonly kind: JobOutboundMessageKind.ChannelCreate;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* A job wants to close the channel, as completed. This is done automatically when the job ends,
|
|
174
|
+
* or can be done from the job to close it. A closed channel might be reopened, but the user
|
|
175
|
+
* need to recall getChannel().
|
|
176
|
+
*/
|
|
177
|
+
export interface JobOutboundMessageChannelComplete extends JobOutboundMessageChannelBase {
|
|
178
|
+
readonly kind: JobOutboundMessageKind.ChannelComplete;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* OnEnd of the job run.
|
|
182
|
+
*/
|
|
183
|
+
export interface JobOutboundMessageEnd extends JobOutboundMessageBase {
|
|
184
|
+
readonly kind: JobOutboundMessageKind.End;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* A pong response from a ping input. The id is the same as the one passed in.
|
|
188
|
+
*/
|
|
189
|
+
export interface JobOutboundMessagePong extends JobOutboundMessageBase {
|
|
190
|
+
readonly kind: JobOutboundMessageKind.Pong;
|
|
191
|
+
/**
|
|
192
|
+
* The ID that was passed in the `Ping` messages.
|
|
193
|
+
*/
|
|
194
|
+
readonly id: number;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Generic message type.
|
|
198
|
+
*/
|
|
199
|
+
export type JobOutboundMessage<OutputT extends JsonValue> = JobOutboundMessageOnReady | JobOutboundMessageStart | JobOutboundMessageOutput<OutputT> | JobOutboundMessageChannelCreate | JobOutboundMessageChannelMessage | JobOutboundMessageChannelError | JobOutboundMessageChannelComplete | JobOutboundMessageEnd | JobOutboundMessagePong;
|
|
200
|
+
/**
|
|
201
|
+
* The state of a job. These are changed as the job reports a new state through its messages.
|
|
202
|
+
*/
|
|
203
|
+
export declare enum JobState {
|
|
204
|
+
/**
|
|
205
|
+
* The job was queued and is waiting to start.
|
|
206
|
+
*/
|
|
207
|
+
Queued = "queued",
|
|
208
|
+
/**
|
|
209
|
+
* The job description was found, its dependencies (see "Synchronizing and Dependencies")
|
|
210
|
+
* are done running, and the job's argument is validated and the job's code will be executed.
|
|
211
|
+
*/
|
|
212
|
+
Ready = "ready",
|
|
213
|
+
/**
|
|
214
|
+
* The job has been started. The job implementation is expected to send this as soon as its
|
|
215
|
+
* work is starting.
|
|
216
|
+
*/
|
|
217
|
+
Started = "started",
|
|
218
|
+
/**
|
|
219
|
+
* The job has ended and is done running.
|
|
220
|
+
*/
|
|
221
|
+
Ended = "ended",
|
|
222
|
+
/**
|
|
223
|
+
* An error occured and the job stopped because of internal state.
|
|
224
|
+
*/
|
|
225
|
+
Errored = "errored"
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* A Job instance, returned from scheduling a job. A Job instance is _not_ serializable.
|
|
229
|
+
*/
|
|
230
|
+
export interface Job<ArgumentT extends JsonValue = JsonValue, InputT extends JsonValue = JsonValue, OutputT extends JsonValue = JsonValue> {
|
|
231
|
+
/**
|
|
232
|
+
* Description of the job. Resolving the job's description can be done asynchronously, so this
|
|
233
|
+
* is an observable that will resolve when it's ready.
|
|
234
|
+
*/
|
|
235
|
+
readonly description: Observable<JobDescription>;
|
|
236
|
+
/**
|
|
237
|
+
* Argument sent when scheduling the job. This is a copy of the argument.
|
|
238
|
+
*/
|
|
239
|
+
readonly argument: ArgumentT;
|
|
240
|
+
/**
|
|
241
|
+
* The input to the job. This goes through the input channel as messages.
|
|
242
|
+
*/
|
|
243
|
+
readonly input: Observer<InputT>;
|
|
244
|
+
/**
|
|
245
|
+
* Outputs of this job.
|
|
246
|
+
*/
|
|
247
|
+
readonly output: Observable<OutputT>;
|
|
248
|
+
/**
|
|
249
|
+
* The current state of the job.
|
|
250
|
+
*/
|
|
251
|
+
readonly state: JobState;
|
|
252
|
+
/**
|
|
253
|
+
* Get a channel that validates against the schema. Messages will be filtered by the schema.
|
|
254
|
+
* @param name The name of the channel.
|
|
255
|
+
* @param schema A schema to use to validate messages.
|
|
256
|
+
*/
|
|
257
|
+
getChannel<T extends JsonValue>(name: string, schema?: schema.JsonSchema): Observable<T>;
|
|
258
|
+
/**
|
|
259
|
+
* Pings the job and wait for the resulting Pong before completing.
|
|
260
|
+
*/
|
|
261
|
+
ping(): Observable<never>;
|
|
262
|
+
/**
|
|
263
|
+
* Stops the job from running. This is different than unsubscribing from the output as in it
|
|
264
|
+
* sends the JobInboundMessageKind.Stop raw input to the job.
|
|
265
|
+
*/
|
|
266
|
+
stop(): void;
|
|
267
|
+
/**
|
|
268
|
+
* The JobInboundMessage messages TO the job.
|
|
269
|
+
*/
|
|
270
|
+
readonly inboundBus: Observer<JobInboundMessage<InputT>>;
|
|
271
|
+
/**
|
|
272
|
+
* The JobOutboundMessage FROM the job.
|
|
273
|
+
*/
|
|
274
|
+
readonly outboundBus: Observable<JobOutboundMessage<OutputT>>;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Options for scheduling jobs.
|
|
278
|
+
*/
|
|
279
|
+
export interface ScheduleJobOptions {
|
|
280
|
+
/**
|
|
281
|
+
* Jobs that need to finish before scheduling this job. These dependencies will be passed
|
|
282
|
+
* to the job itself in its context.
|
|
283
|
+
*/
|
|
284
|
+
dependencies?: Job | Job[];
|
|
285
|
+
}
|
|
286
|
+
export interface Registry<MinimumArgumentValueT extends JsonValue = JsonValue, MinimumInputValueT extends JsonValue = JsonValue, MinimumOutputValueT extends JsonValue = JsonValue> {
|
|
287
|
+
/**
|
|
288
|
+
* Get a job handler.
|
|
289
|
+
* @param name The name of the job to get a handler from.
|
|
290
|
+
*/
|
|
291
|
+
get<A extends MinimumArgumentValueT, I extends MinimumInputValueT, O extends MinimumOutputValueT>(name: JobName): Observable<JobHandler<A, I, O> | null>;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* An interface that can schedule jobs.
|
|
295
|
+
*/
|
|
296
|
+
export interface Scheduler<MinimumArgumentValueT extends JsonValue = JsonValue, MinimumInputValueT extends JsonValue = JsonValue, MinimumOutputValueT extends JsonValue = JsonValue> {
|
|
297
|
+
/**
|
|
298
|
+
* Get a job description for a named job.
|
|
299
|
+
*
|
|
300
|
+
* @param name The name of the job.
|
|
301
|
+
* @returns A description, or null if no description is available for this job.
|
|
302
|
+
*/
|
|
303
|
+
getDescription(name: JobName): Observable<JobDescription | null>;
|
|
304
|
+
/**
|
|
305
|
+
* Returns true if the job name has been registered.
|
|
306
|
+
* @param name The name of the job.
|
|
307
|
+
* @returns True if the job exists, false otherwise.
|
|
308
|
+
*/
|
|
309
|
+
has(name: JobName): Observable<boolean>;
|
|
310
|
+
/**
|
|
311
|
+
* Pause the scheduler, temporary queueing _new_ jobs. Returns a resume function that should be
|
|
312
|
+
* used to resume execution. If multiple `pause()` were called, all their resume functions must
|
|
313
|
+
* be called before the Scheduler actually starts new jobs. Additional calls to the same resume
|
|
314
|
+
* function will have no effect.
|
|
315
|
+
*
|
|
316
|
+
* Jobs already running are NOT paused. This is pausing the scheduler only.
|
|
317
|
+
*
|
|
318
|
+
* @returns A function that can be run to resume the scheduler. If multiple `pause()` calls
|
|
319
|
+
* were made, all their return function must be called (in any order) before the
|
|
320
|
+
* scheduler can resume.
|
|
321
|
+
*/
|
|
322
|
+
pause(): () => void;
|
|
323
|
+
/**
|
|
324
|
+
* Schedule a job to be run, using its name.
|
|
325
|
+
* @param name The name of job to be run.
|
|
326
|
+
* @param argument The argument to send to the job when starting it.
|
|
327
|
+
* @param options Scheduling options.
|
|
328
|
+
* @returns The job being run.
|
|
329
|
+
*/
|
|
330
|
+
schedule<A extends MinimumArgumentValueT, I extends MinimumInputValueT, O extends MinimumOutputValueT>(name: JobName, argument: A, options?: ScheduleJobOptions): Job<A, I, O>;
|
|
331
|
+
}
|
|
332
|
+
export declare function isJobHandler<A extends JsonValue, I extends JsonValue, O extends JsonValue>(value: unknown): value is JobHandler<A, I, O>;
|
package/src/jobs/api.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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.dev/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.JobState = exports.JobOutboundMessageKind = exports.JobInboundMessageKind = void 0;
|
|
11
|
+
exports.isJobHandler = isJobHandler;
|
|
12
|
+
/**
|
|
13
|
+
* Messages that can be sent TO a job. The job needs to listen to those.
|
|
14
|
+
*/
|
|
15
|
+
var JobInboundMessageKind;
|
|
16
|
+
(function (JobInboundMessageKind) {
|
|
17
|
+
JobInboundMessageKind["Ping"] = "ip";
|
|
18
|
+
JobInboundMessageKind["Stop"] = "is";
|
|
19
|
+
// Channel specific messages.
|
|
20
|
+
JobInboundMessageKind["Input"] = "in";
|
|
21
|
+
// Input channel does not allow completion / error. Erroring this will just close the Subject
|
|
22
|
+
// but not notify the job.
|
|
23
|
+
})(JobInboundMessageKind || (exports.JobInboundMessageKind = JobInboundMessageKind = {}));
|
|
24
|
+
/**
|
|
25
|
+
* Kind of messages that can be outputted from a job.
|
|
26
|
+
*/
|
|
27
|
+
var JobOutboundMessageKind;
|
|
28
|
+
(function (JobOutboundMessageKind) {
|
|
29
|
+
// Lifecycle specific messages.
|
|
30
|
+
JobOutboundMessageKind["OnReady"] = "c";
|
|
31
|
+
JobOutboundMessageKind["Start"] = "s";
|
|
32
|
+
JobOutboundMessageKind["End"] = "e";
|
|
33
|
+
JobOutboundMessageKind["Pong"] = "p";
|
|
34
|
+
// Feedback messages.
|
|
35
|
+
JobOutboundMessageKind["Output"] = "o";
|
|
36
|
+
// Channel specific messages.
|
|
37
|
+
JobOutboundMessageKind["ChannelCreate"] = "cn";
|
|
38
|
+
JobOutboundMessageKind["ChannelMessage"] = "cm";
|
|
39
|
+
JobOutboundMessageKind["ChannelError"] = "ce";
|
|
40
|
+
JobOutboundMessageKind["ChannelComplete"] = "cc";
|
|
41
|
+
})(JobOutboundMessageKind || (exports.JobOutboundMessageKind = JobOutboundMessageKind = {}));
|
|
42
|
+
/**
|
|
43
|
+
* The state of a job. These are changed as the job reports a new state through its messages.
|
|
44
|
+
*/
|
|
45
|
+
var JobState;
|
|
46
|
+
(function (JobState) {
|
|
47
|
+
/**
|
|
48
|
+
* The job was queued and is waiting to start.
|
|
49
|
+
*/
|
|
50
|
+
JobState["Queued"] = "queued";
|
|
51
|
+
/**
|
|
52
|
+
* The job description was found, its dependencies (see "Synchronizing and Dependencies")
|
|
53
|
+
* are done running, and the job's argument is validated and the job's code will be executed.
|
|
54
|
+
*/
|
|
55
|
+
JobState["Ready"] = "ready";
|
|
56
|
+
/**
|
|
57
|
+
* The job has been started. The job implementation is expected to send this as soon as its
|
|
58
|
+
* work is starting.
|
|
59
|
+
*/
|
|
60
|
+
JobState["Started"] = "started";
|
|
61
|
+
/**
|
|
62
|
+
* The job has ended and is done running.
|
|
63
|
+
*/
|
|
64
|
+
JobState["Ended"] = "ended";
|
|
65
|
+
/**
|
|
66
|
+
* An error occured and the job stopped because of internal state.
|
|
67
|
+
*/
|
|
68
|
+
JobState["Errored"] = "errored";
|
|
69
|
+
})(JobState || (exports.JobState = JobState = {}));
|
|
70
|
+
function isJobHandler(value) {
|
|
71
|
+
const job = value;
|
|
72
|
+
return (typeof job == 'function' && typeof job.jobDescription == 'object' && job.jobDescription !== null);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["api.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAsbH,oCAQC;AAvYD;;GAEG;AACH,IAAY,qBAQX;AARD,WAAY,qBAAqB;IAC/B,oCAAW,CAAA;IACX,oCAAW,CAAA;IAEX,6BAA6B;IAC7B,qCAAY,CAAA;IACZ,6FAA6F;IAC7F,0BAA0B;AAC5B,CAAC,EARW,qBAAqB,qCAArB,qBAAqB,QAQhC;AAkDD;;GAEG;AACH,IAAY,sBAeX;AAfD,WAAY,sBAAsB;IAChC,+BAA+B;IAC/B,uCAAa,CAAA;IACb,qCAAW,CAAA;IACX,mCAAS,CAAA;IACT,oCAAU,CAAA;IAEV,qBAAqB;IACrB,sCAAY,CAAA;IAEZ,6BAA6B;IAC7B,8CAAoB,CAAA;IACpB,+CAAqB,CAAA;IACrB,6CAAmB,CAAA;IACnB,gDAAsB,CAAA;AACxB,CAAC,EAfW,sBAAsB,sCAAtB,sBAAsB,QAejC;AAiID;;GAEG;AACH,IAAY,QA2BX;AA3BD,WAAY,QAAQ;IAClB;;OAEG;IACH,6BAAiB,CAAA;IAEjB;;;OAGG;IACH,2BAAe,CAAA;IAEf;;;OAGG;IACH,+BAAmB,CAAA;IAEnB;;OAEG;IACH,2BAAe,CAAA;IAEf;;OAEG;IACH,+BAAmB,CAAA;AACrB,CAAC,EA3BW,QAAQ,wBAAR,QAAQ,QA2BnB;AAiJD,SAAgB,YAAY,CAC1B,KAAc;IAEd,MAAM,GAAG,GAAG,KAA4B,CAAC;IAEzC,OAAO,CACL,OAAO,GAAG,IAAI,UAAU,IAAI,OAAO,GAAG,CAAC,cAAc,IAAI,QAAQ,IAAI,GAAG,CAAC,cAAc,KAAK,IAAI,CACjG,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
*/
|
|
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
|
+
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
|
+
*/
|
|
28
|
+
export 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
|
+
*/
|
|
36
|
+
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>;
|
|
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
|
+
*/
|
|
42
|
+
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>;
|
|
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
|
+
*/
|
|
47
|
+
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,146 @@
|
|
|
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.dev/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ChannelAlreadyExistException = void 0;
|
|
11
|
+
exports.createJobHandler = createJobHandler;
|
|
12
|
+
exports.createJobFactory = createJobFactory;
|
|
13
|
+
exports.createLoggerJob = createLoggerJob;
|
|
14
|
+
const core_1 = require("@angular-devkit/core");
|
|
15
|
+
const rxjs_1 = require("rxjs");
|
|
16
|
+
const api_1 = require("./api");
|
|
17
|
+
class ChannelAlreadyExistException extends core_1.BaseException {
|
|
18
|
+
constructor(name) {
|
|
19
|
+
super(`Channel ${JSON.stringify(name)} already exist.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ChannelAlreadyExistException = ChannelAlreadyExistException;
|
|
23
|
+
/**
|
|
24
|
+
* Make a simple job handler that sets start and end from a function that's synchronous.
|
|
25
|
+
*
|
|
26
|
+
* @param fn The function to create a handler for.
|
|
27
|
+
* @param options An optional set of properties to set on the handler. Some fields might be
|
|
28
|
+
* required by registry or schedulers.
|
|
29
|
+
*/
|
|
30
|
+
function createJobHandler(fn, options = {}) {
|
|
31
|
+
const handler = (argument, context) => {
|
|
32
|
+
const description = context.description;
|
|
33
|
+
const inboundBus = context.inboundBus;
|
|
34
|
+
const inputChannel = new rxjs_1.Subject();
|
|
35
|
+
let subscription;
|
|
36
|
+
const teardownLogics = [];
|
|
37
|
+
let tearingDown = false;
|
|
38
|
+
return new rxjs_1.Observable((subject) => {
|
|
39
|
+
function complete() {
|
|
40
|
+
if (subscription) {
|
|
41
|
+
subscription.unsubscribe();
|
|
42
|
+
}
|
|
43
|
+
subject.next({ kind: api_1.JobOutboundMessageKind.End, description });
|
|
44
|
+
subject.complete();
|
|
45
|
+
inputChannel.complete();
|
|
46
|
+
}
|
|
47
|
+
// Handle input.
|
|
48
|
+
const inboundSub = inboundBus.subscribe((message) => {
|
|
49
|
+
switch (message.kind) {
|
|
50
|
+
case api_1.JobInboundMessageKind.Ping:
|
|
51
|
+
subject.next({ kind: api_1.JobOutboundMessageKind.Pong, description, id: message.id });
|
|
52
|
+
break;
|
|
53
|
+
case api_1.JobInboundMessageKind.Stop:
|
|
54
|
+
// Run teardown logic then complete.
|
|
55
|
+
tearingDown = true;
|
|
56
|
+
if (teardownLogics.length) {
|
|
57
|
+
Promise.all(teardownLogics.map((fn) => fn())).then(() => complete(), () => complete());
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
complete();
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case api_1.JobInboundMessageKind.Input:
|
|
64
|
+
if (!tearingDown) {
|
|
65
|
+
inputChannel.next(message.value);
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
// Execute the function with the additional context.
|
|
71
|
+
const channels = new Map();
|
|
72
|
+
const newContext = {
|
|
73
|
+
...context,
|
|
74
|
+
input: inputChannel.asObservable(),
|
|
75
|
+
addTeardown(teardown) {
|
|
76
|
+
teardownLogics.push(teardown);
|
|
77
|
+
},
|
|
78
|
+
createChannel(name) {
|
|
79
|
+
if (channels.has(name)) {
|
|
80
|
+
throw new ChannelAlreadyExistException(name);
|
|
81
|
+
}
|
|
82
|
+
const channelSubject = new rxjs_1.Subject();
|
|
83
|
+
const channelSub = channelSubject.subscribe((message) => {
|
|
84
|
+
subject.next({
|
|
85
|
+
kind: api_1.JobOutboundMessageKind.ChannelMessage,
|
|
86
|
+
description,
|
|
87
|
+
name,
|
|
88
|
+
message,
|
|
89
|
+
});
|
|
90
|
+
}, (error) => {
|
|
91
|
+
subject.next({ kind: api_1.JobOutboundMessageKind.ChannelError, description, name, error });
|
|
92
|
+
// This can be reopened.
|
|
93
|
+
channels.delete(name);
|
|
94
|
+
}, () => {
|
|
95
|
+
subject.next({ kind: api_1.JobOutboundMessageKind.ChannelComplete, description, name });
|
|
96
|
+
// This can be reopened.
|
|
97
|
+
channels.delete(name);
|
|
98
|
+
});
|
|
99
|
+
channels.set(name, channelSubject);
|
|
100
|
+
if (subscription) {
|
|
101
|
+
subscription.add(channelSub);
|
|
102
|
+
}
|
|
103
|
+
return channelSubject;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
subject.next({ kind: api_1.JobOutboundMessageKind.Start, description });
|
|
107
|
+
let result = fn(argument, newContext);
|
|
108
|
+
// If the result is a promise, simply wait for it to complete before reporting the result.
|
|
109
|
+
if ((0, core_1.isPromise)(result)) {
|
|
110
|
+
result = (0, rxjs_1.from)(result);
|
|
111
|
+
}
|
|
112
|
+
else if (!(0, rxjs_1.isObservable)(result)) {
|
|
113
|
+
result = (0, rxjs_1.of)(result);
|
|
114
|
+
}
|
|
115
|
+
subscription = result.subscribe((value) => subject.next({ kind: api_1.JobOutboundMessageKind.Output, description, value }), (error) => subject.error(error), () => complete());
|
|
116
|
+
subscription.add(inboundSub);
|
|
117
|
+
return subscription;
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
return Object.assign(handler, { jobDescription: options });
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Lazily create a job using a function.
|
|
124
|
+
* @param loader A factory function that returns a promise/observable of a JobHandler.
|
|
125
|
+
* @param options Same options as createJob.
|
|
126
|
+
*/
|
|
127
|
+
function createJobFactory(loader, options = {}) {
|
|
128
|
+
const handler = (argument, context) => {
|
|
129
|
+
return (0, rxjs_1.from)(loader()).pipe((0, rxjs_1.switchMap)((fn) => fn(argument, context)));
|
|
130
|
+
};
|
|
131
|
+
return Object.assign(handler, { jobDescription: options });
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Creates a job that logs out input/output messages of another Job. The messages are still
|
|
135
|
+
* propagated to the other job.
|
|
136
|
+
*/
|
|
137
|
+
function createLoggerJob(job, logger) {
|
|
138
|
+
const handler = (argument, context) => {
|
|
139
|
+
context.inboundBus
|
|
140
|
+
.pipe((0, rxjs_1.tap)((message) => logger.info(`Input: ${JSON.stringify(message)}`)))
|
|
141
|
+
.subscribe();
|
|
142
|
+
return job(argument, context).pipe((0, rxjs_1.tap)((message) => logger.info(`Message: ${JSON.stringify(message)}`), (error) => logger.warn(`Error: ${JSON.stringify(error)}`), () => logger.info(`Completed`)));
|
|
143
|
+
};
|
|
144
|
+
return Object.assign(handler, job);
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=create-job-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-job-handler.js","sourceRoot":"","sources":["create-job-handler.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA4DH,4CAmHC;AAOD,4CASC;AAMD,0CAmBC;AAtND,+CAAoF;AACpF,+BAUc;AACd,+BAOe;AAEf,MAAa,4BAA6B,SAAQ,oBAAa;IAC7D,YAAY,IAAY;QACtB,KAAK,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC1D,CAAC;CACF;AAJD,oEAIC;AA0BD;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAC9B,EAA+B,EAC/B,UAAmC,EAAE;IAErC,MAAM,OAAO,GAAG,CAAC,QAAW,EAAE,OAAmC,EAAE,EAAE;QACnE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACxC,MAAM,UAAU,GAAG,OAAO,CAAC,UA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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.dev/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>;
|