@runium/core 0.0.2 → 0.0.4
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/index.d.ts +409 -0
- package/index.js +16 -16
- package/package.json +5 -2
package/index.d.ts
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { WriteStream } from 'node:fs';
|
|
4
|
+
|
|
5
|
+
export declare function applyMacros(text: string, macros: MacrosCollection): string;
|
|
6
|
+
|
|
7
|
+
export declare class EventTrigger extends RuniumTrigger<EventTriggerOptions> {
|
|
8
|
+
constructor(options: EventTriggerOptions, project: RuniumTriggerProjectAccessible);
|
|
9
|
+
enable(): void;
|
|
10
|
+
disable(): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare interface EventTriggerOptions extends RuniumTriggerOptions {
|
|
14
|
+
event: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export declare function extendProjectSchema(schema: object, extensions: ProjectSchemaExtension): object;
|
|
18
|
+
|
|
19
|
+
export declare enum FileErrorCode {
|
|
20
|
+
READ_JSON = "file-read-json",
|
|
21
|
+
WRITE_JSON = "file-write-json"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export declare function getProjectSchema(): object;
|
|
25
|
+
|
|
26
|
+
export declare class IntervalTrigger extends RuniumTrigger<IntervalTriggerOptions> {
|
|
27
|
+
constructor(options: IntervalTriggerOptions, project: RuniumTriggerProjectAccessible);
|
|
28
|
+
enable(): void;
|
|
29
|
+
disable(): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare interface IntervalTriggerOptions extends RuniumTriggerOptions {
|
|
33
|
+
interval: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare function isCustomAction(action: ProjectAction): action is ProjectCustomAction;
|
|
37
|
+
|
|
38
|
+
export declare function isCustomTrigger(trigger: ProjectTrigger): trigger is ProjectCustomTrigger;
|
|
39
|
+
|
|
40
|
+
export declare function isProcessTaskAction(action: ProjectAction): action is ProjectActionProcessTask;
|
|
41
|
+
|
|
42
|
+
export declare function isRuniumError(error: unknown): boolean;
|
|
43
|
+
|
|
44
|
+
export declare function isToggleTriggerAction(action: ProjectAction): action is ProjectActionToggleTrigger;
|
|
45
|
+
|
|
46
|
+
export declare interface JSONObject {
|
|
47
|
+
[x: string]: JSONValue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export declare type JSONValue = string | number | boolean | JSONObject | JSONValue[];
|
|
51
|
+
|
|
52
|
+
export declare type Macro = (...params: string[]) => string;
|
|
53
|
+
|
|
54
|
+
export declare type MacrosCollection = Record<string, Macro>;
|
|
55
|
+
|
|
56
|
+
export declare enum MacrosErrorCode {
|
|
57
|
+
MACRO_APPLY_ERROR = "macro-apply-error"
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export declare class Project extends EventEmitter {
|
|
61
|
+
constructor(config: ProjectConfig);
|
|
62
|
+
validate(): void;
|
|
63
|
+
getConfig(): ProjectConfig;
|
|
64
|
+
setConfig(config: ProjectConfig): void;
|
|
65
|
+
getState(): ProjectState;
|
|
66
|
+
start(): Promise<void>;
|
|
67
|
+
stop(reason?: string): Promise<void>;
|
|
68
|
+
extendValidationSchema(extensions: ProjectSchemaExtension): void;
|
|
69
|
+
registerAction(type: string, processor: RuniumActionProcessor): void;
|
|
70
|
+
registerTask(type: string, processor: RuniumTaskConstructor<unknown, any>): void;
|
|
71
|
+
registerTrigger(type: string, processor: RuniumTriggerConstructor<any>): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export declare type ProjectAction = ProjectCustomAction | ProjectActionEmitEvent | ProjectActionProcessTask | ProjectActionStopProject | ProjectActionToggleTrigger;
|
|
75
|
+
|
|
76
|
+
export declare interface ProjectActionEmitEvent {
|
|
77
|
+
type: ProjectActionType.EMIT_EVENT;
|
|
78
|
+
event: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export declare interface ProjectActionProcessTask {
|
|
82
|
+
type: ProjectActionType.START_TASK | ProjectActionType.RESTART_TASK | ProjectActionType.STOP_TASK;
|
|
83
|
+
taskId: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export declare interface ProjectActionStopProject {
|
|
87
|
+
type: ProjectActionType.STOP_PROJECT;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export declare interface ProjectActionToggleTrigger {
|
|
91
|
+
type: ProjectActionType.ENABLE_TRIGGER | ProjectActionType.DISABLE_TRIGGER;
|
|
92
|
+
triggerId: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export declare enum ProjectActionType {
|
|
96
|
+
EMIT_EVENT = "emit-event",
|
|
97
|
+
START_TASK = "start-task",
|
|
98
|
+
RESTART_TASK = "restart-task",
|
|
99
|
+
STOP_TASK = "stop-task",
|
|
100
|
+
STOP_PROJECT = "stop-project",
|
|
101
|
+
ENABLE_TRIGGER = "enable-trigger",
|
|
102
|
+
DISABLE_TRIGGER = "disable-trigger"
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export declare interface ProjectConfig {
|
|
106
|
+
id: string;
|
|
107
|
+
name?: string;
|
|
108
|
+
tasks: ProjectTaskConfig[];
|
|
109
|
+
triggers?: ProjectTrigger[];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export declare enum ProjectConfigErrorCode {
|
|
113
|
+
INCORRECT_DATA = "project-config-incorrect-data",
|
|
114
|
+
TASKS_CIRCULAR_DEPENDENCY = "project-config-tasks-circular-dependency",
|
|
115
|
+
TASK_NOT_EXISTS = "project-config-task-not-exists",
|
|
116
|
+
TRIGGER_NOT_EXISTS = "project-config-trigger-not-exists"
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export declare interface ProjectCustomAction {
|
|
120
|
+
type: string;
|
|
121
|
+
payload?: unknown;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export declare interface ProjectCustomTrigger extends ProjectTriggerBase {
|
|
125
|
+
type: string;
|
|
126
|
+
payload?: unknown;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export declare interface ProjectDefaultTaskConfig extends ProjectTaskConfig<TaskOptions> {
|
|
130
|
+
type?: ProjectTaskType.DEFAULT;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export declare enum ProjectErrorCode {
|
|
134
|
+
ACTION_PROCESSOR_ALREADY_REGISTERED = "project-action-processor-already-registered",
|
|
135
|
+
ACTION_PROCESSOR_INCORRECT = "project-action-processor-incorrect",
|
|
136
|
+
TASK_PROCESSOR_NOT_FOUND = "project-task-processor-not-found",
|
|
137
|
+
TASK_PROCESSOR_ALREADY_REGISTERED = "project-task-processor-already-registered",
|
|
138
|
+
TASK_PROCESSOR_INCORRECT = "project-task-processor-incorrect",
|
|
139
|
+
TRIGGER_PROCESSOR_ALREADY_REGISTERED = "project-trigger-processor-already-registered",
|
|
140
|
+
TRIGGER_PROCESSOR_INCORRECT = "project-trigger-processor-incorrect"
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export declare enum ProjectEvent {
|
|
144
|
+
STATE_CHANGE = "state-change",
|
|
145
|
+
START_TASK = "start-task",
|
|
146
|
+
RESTART_TASK = "restart-task",
|
|
147
|
+
STOP_TASK = "stop-task",
|
|
148
|
+
PROCESS_ACTION = "process-action",
|
|
149
|
+
ENABLE_TRIGGER = "enable-trigger",
|
|
150
|
+
DISABLE_TRIGGER = "disable-trigger",
|
|
151
|
+
TASK_STATE_CHANGE = "task-state-change",
|
|
152
|
+
TASK_STDOUT = "task-stdout",
|
|
153
|
+
TASK_STDERR = "task-stderr"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export declare enum ProjectSchemaErrorCode {
|
|
157
|
+
ACTION_TYPE_ALREADY_USED = "project-schema-action-type-already-used",
|
|
158
|
+
TASK_TYPE_ALREADY_USED = "project-schema-task-type-already-used",
|
|
159
|
+
TRIGGER_TYPE_ALREADY_USED = "project-schema-trigger-type-already-used"
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export declare interface ProjectSchemaExtension {
|
|
163
|
+
project?: {
|
|
164
|
+
properties: unknown;
|
|
165
|
+
required?: string[];
|
|
166
|
+
};
|
|
167
|
+
tasks?: Record<string, {
|
|
168
|
+
type: string;
|
|
169
|
+
options: unknown;
|
|
170
|
+
}>;
|
|
171
|
+
definitions?: Record<string, unknown>;
|
|
172
|
+
actions?: Record<string, {
|
|
173
|
+
type: string;
|
|
174
|
+
payload?: unknown;
|
|
175
|
+
}>;
|
|
176
|
+
triggers?: Record<string, {
|
|
177
|
+
type: string;
|
|
178
|
+
payload?: unknown;
|
|
179
|
+
}>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export declare interface ProjectState {
|
|
183
|
+
status: ProjectStatus;
|
|
184
|
+
timestamp: number;
|
|
185
|
+
reason?: string;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export declare enum ProjectStatus {
|
|
189
|
+
IDLE = "idle",
|
|
190
|
+
STARTING = "starting",
|
|
191
|
+
STARTED = "started",
|
|
192
|
+
STOPPING = "stopping",
|
|
193
|
+
STOPPED = "stopped"
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export declare interface ProjectTaskConfig<Options = unknown> {
|
|
197
|
+
id: string;
|
|
198
|
+
options: Options;
|
|
199
|
+
type?: ProjectTaskType | string;
|
|
200
|
+
name?: string;
|
|
201
|
+
mode?: ProjectTaskStartMode;
|
|
202
|
+
dependencies?: ProjectTaskDependency[];
|
|
203
|
+
handlers?: ProjectTaskHandler[];
|
|
204
|
+
restart?: ProjectTaskRestartPolicy;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export declare interface ProjectTaskDependency {
|
|
208
|
+
taskId: string;
|
|
209
|
+
condition: ProjectTaskStateCondition;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export declare interface ProjectTaskHandler {
|
|
213
|
+
condition: ProjectTaskStateCondition;
|
|
214
|
+
action: ProjectAction;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export declare type ProjectTaskRestartPolicy = ProjectTaskRestartPolicyAlways | ProjectTaskRestartPolicyOnFailure;
|
|
218
|
+
|
|
219
|
+
export declare interface ProjectTaskRestartPolicyAlways {
|
|
220
|
+
policy: ProjectTaskRestartPolicyType.ALWAYS;
|
|
221
|
+
delay?: number;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export declare interface ProjectTaskRestartPolicyOnFailure {
|
|
225
|
+
policy: ProjectTaskRestartPolicyType.ON_FAILURE;
|
|
226
|
+
delay?: number;
|
|
227
|
+
maxRetries?: number;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export declare enum ProjectTaskRestartPolicyType {
|
|
231
|
+
ALWAYS = "always",
|
|
232
|
+
ON_FAILURE = "on-failure"
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export declare enum ProjectTaskStartMode {
|
|
236
|
+
IMMEDIATE = "immediate",
|
|
237
|
+
DEFERRED = "deferred"
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export declare type ProjectTaskStateCondition = string | boolean | Partial<RuniumTaskState> | ((state: RuniumTaskState) => boolean);
|
|
241
|
+
|
|
242
|
+
export declare enum ProjectTaskType {
|
|
243
|
+
DEFAULT = "default"
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export declare type ProjectTrigger = ProjectTriggerEvent | ProjectTriggerInterval | ProjectTriggerTimeout | ProjectCustomTrigger;
|
|
247
|
+
|
|
248
|
+
declare interface ProjectTriggerBase {
|
|
249
|
+
id: string;
|
|
250
|
+
type: ProjectTriggerType | string;
|
|
251
|
+
action: ProjectAction;
|
|
252
|
+
disabled?: boolean;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export declare interface ProjectTriggerEvent extends ProjectTriggerBase {
|
|
256
|
+
type: ProjectTriggerType.EVENT;
|
|
257
|
+
event: string;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export declare interface ProjectTriggerInterval extends ProjectTriggerBase {
|
|
261
|
+
type: ProjectTriggerType.INTERVAL;
|
|
262
|
+
interval: number;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export declare interface ProjectTriggerTimeout extends ProjectTriggerBase {
|
|
266
|
+
type: ProjectTriggerType.TIMEOUT;
|
|
267
|
+
timeout: number;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export declare enum ProjectTriggerType {
|
|
271
|
+
EVENT = "event",
|
|
272
|
+
TIMEOUT = "timeout",
|
|
273
|
+
INTERVAL = "interval"
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export declare function readJsonFile<T = JSONValue>(path: string): Promise<T>;
|
|
277
|
+
|
|
278
|
+
declare type RuniumActionProcessor = (payload: unknown) => void;
|
|
279
|
+
|
|
280
|
+
export declare class RuniumError extends Error {
|
|
281
|
+
code: string;
|
|
282
|
+
payload: unknown;
|
|
283
|
+
constructor(message: string, code: string, payload?: unknown);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export declare abstract class RuniumTask<Options = unknown, State = RuniumTaskState> extends EventEmitter {
|
|
287
|
+
protected options: Options;
|
|
288
|
+
protected constructor(options: Options);
|
|
289
|
+
abstract getOptions(): Options;
|
|
290
|
+
abstract getState(): State;
|
|
291
|
+
abstract start(): Promise<void>;
|
|
292
|
+
abstract stop(reason?: string): Promise<void>;
|
|
293
|
+
abstract restart(): Promise<void>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export declare type RuniumTaskConstructor<Options = unknown, State extends RuniumTaskState = RuniumTaskState> = new (options: any) => RuniumTask<Options, State>;
|
|
297
|
+
|
|
298
|
+
export declare interface RuniumTaskState {
|
|
299
|
+
status: TaskStatus;
|
|
300
|
+
timestamp: number;
|
|
301
|
+
iteration: number;
|
|
302
|
+
exitCode?: number;
|
|
303
|
+
error?: Error;
|
|
304
|
+
reason?: string;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export declare abstract class RuniumTrigger<Options extends RuniumTriggerOptions> {
|
|
308
|
+
protected project: RuniumTriggerProjectAccessible;
|
|
309
|
+
protected id: string;
|
|
310
|
+
protected action: ProjectAction;
|
|
311
|
+
protected disabled: boolean;
|
|
312
|
+
constructor(options: Options, project: RuniumTriggerProjectAccessible);
|
|
313
|
+
abstract enable(): void;
|
|
314
|
+
abstract disable(): void;
|
|
315
|
+
getId(): string;
|
|
316
|
+
isDisabled(): boolean;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export declare type RuniumTriggerConstructor<Options extends RuniumTriggerOptions> = new (options: Options, project: RuniumTriggerProjectAccessible) => RuniumTrigger<Options>;
|
|
320
|
+
|
|
321
|
+
export declare interface RuniumTriggerOptions {
|
|
322
|
+
id: string;
|
|
323
|
+
action: ProjectAction;
|
|
324
|
+
disabled?: boolean;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export declare interface RuniumTriggerProjectAccessible {
|
|
328
|
+
processAction(action: ProjectAction): void;
|
|
329
|
+
on: NodeJS.EventEmitter['on'];
|
|
330
|
+
off: NodeJS.EventEmitter['off'];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export declare const SILENT_EXIT_CODE = -1;
|
|
334
|
+
|
|
335
|
+
export declare class Task extends RuniumTask<TaskOptions, TaskState> {
|
|
336
|
+
protected readonly options: TaskOptions;
|
|
337
|
+
protected state: TaskState;
|
|
338
|
+
protected process: ChildProcessWithoutNullStreams | null;
|
|
339
|
+
protected stdoutStream: WriteStream | null;
|
|
340
|
+
protected stderrStream: WriteStream | null;
|
|
341
|
+
protected ttlTimer: NodeJS.Timeout | null;
|
|
342
|
+
constructor(options: TaskOptions);
|
|
343
|
+
getState(): TaskState;
|
|
344
|
+
getOptions(): TaskOptions;
|
|
345
|
+
start(): Promise<void>;
|
|
346
|
+
stop(reason?: string): Promise<void>;
|
|
347
|
+
restart(): Promise<void>;
|
|
348
|
+
protected updateState(state: Partial<TaskState>): void;
|
|
349
|
+
protected initLogStreams(): Promise<void>;
|
|
350
|
+
protected setTTLTimer(): void;
|
|
351
|
+
protected addProcessListeners(): void;
|
|
352
|
+
protected onStdOutData(data: Buffer): void;
|
|
353
|
+
protected onStdErrData(data: Buffer): void;
|
|
354
|
+
protected onExit(code: number | null): void;
|
|
355
|
+
protected onError(error: Error): void;
|
|
356
|
+
protected cleanup(): void;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export declare enum TaskEvent {
|
|
360
|
+
STATE_CHANGE = "state-change",
|
|
361
|
+
STDOUT = "stdout",
|
|
362
|
+
STDERR = "stderr"
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export declare interface TaskOptions {
|
|
366
|
+
command: string;
|
|
367
|
+
arguments?: string[];
|
|
368
|
+
shell?: boolean;
|
|
369
|
+
stopSignal?: string;
|
|
370
|
+
cwd?: string;
|
|
371
|
+
env?: {
|
|
372
|
+
[key: string]: string | number | boolean;
|
|
373
|
+
};
|
|
374
|
+
ttl?: number;
|
|
375
|
+
log?: {
|
|
376
|
+
stdout?: string | null;
|
|
377
|
+
stderr?: string | null;
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export declare interface TaskState extends RuniumTaskState {
|
|
382
|
+
pid: number;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export declare enum TaskStatus {
|
|
386
|
+
IDLE = "idle",
|
|
387
|
+
STARTING = "starting",
|
|
388
|
+
STARTED = "started",
|
|
389
|
+
COMPLETED = "completed",
|
|
390
|
+
FAILED = "failed",
|
|
391
|
+
STOPPING = "stopping",
|
|
392
|
+
STOPPED = "stopped"
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export declare class TimeoutTrigger extends RuniumTrigger<TimeoutTriggerOptions> {
|
|
396
|
+
constructor(options: TimeoutTriggerOptions, project: RuniumTriggerProjectAccessible);
|
|
397
|
+
enable(): void;
|
|
398
|
+
disable(): void;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export declare interface TimeoutTriggerOptions extends RuniumTriggerOptions {
|
|
402
|
+
timeout: number;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export declare function validateProject(project: ProjectConfig, schema: object): void;
|
|
406
|
+
|
|
407
|
+
export declare function writeJsonFile<T = JSONValue>(path: string, data: T): Promise<void>;
|
|
408
|
+
|
|
409
|
+
export { }
|
package/index.js
CHANGED
|
@@ -148,16 +148,16 @@ class et extends C {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
async stop() {
|
|
152
|
-
if (this.process && this.state.status !== "stopping" && this.state.status === "started") return this.updateState({ status: "stopping" }), new Promise((
|
|
153
|
-
const
|
|
154
|
-
this.process.kill(
|
|
155
|
-
|
|
151
|
+
async stop(t = "") {
|
|
152
|
+
if (this.process && this.state.status !== "stopping" && this.state.status === "started") return this.updateState({ status: "stopping", reason: t }), new Promise((s) => {
|
|
153
|
+
const r = this.options.stopSignal || "SIGTERM";
|
|
154
|
+
this.process.kill(r), this.process.on("exit", () => {
|
|
155
|
+
s();
|
|
156
156
|
});
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
async restart() {
|
|
160
|
-
await this.stop(), this.start();
|
|
160
|
+
await this.stop("restart"), this.start();
|
|
161
161
|
}
|
|
162
162
|
updateState(t) {
|
|
163
163
|
const s = { ...this.state, ...t, timestamp: Date.now() };
|
|
@@ -177,7 +177,7 @@ class et extends C {
|
|
|
177
177
|
setTTLTimer() {
|
|
178
178
|
const { ttl: t } = this.options;
|
|
179
179
|
t && this.process && (this.ttlTimer = setTimeout(() => {
|
|
180
|
-
this.stop();
|
|
180
|
+
this.stop("ttl");
|
|
181
181
|
}, t));
|
|
182
182
|
}
|
|
183
183
|
addProcessListeners() {
|
|
@@ -215,7 +215,7 @@ function ot(e, t) {
|
|
|
215
215
|
return { type: "object", properties: { ...structuredClone(k), type: { type: "string", const: e }, ...s }, required: ["id", "type", "action", ...r], additionalProperties: !1 };
|
|
216
216
|
}
|
|
217
217
|
function nt() {
|
|
218
|
-
const e = { $schema: "https://json-schema.org/draft/2020-12/schema", $id: "https://example.com/schemas/project.json", title: "Project", type: "object", properties: { id: { type: "string" }, name: { type: "string" }, tasks: { type: "array", items: { oneOf: [{ $ref: "#/$defs/Runium_TaskConfig" }] }, minItems: 1, uniqueItemProperties: ["id"] }, triggers: { type: "array", items: { $ref: "#/$defs/Runium_Trigger" }, uniqueItemProperties: ["id"] } }, required: ["id", "tasks"], additionalProperties: !1, $defs: { Runium_EnvValue: { type: ["string", "number", "boolean"] }, Runium_Env: { type: "object", additionalProperties: { $ref: "#/$defs/Runium_EnvValue" } }, Runium_TaskStartMode: { type: "string", enum: Object.values(R) }, Runium_TaskHandler: { type: "object", properties: { action: { $ref: "#/$defs/Runium_Action" }, condition: { $ref: "#/$defs/Runium_TaskStateCondition" } }, required: ["action", "condition"], additionalProperties: !1 }, Runium_TaskStateCondition: { oneOf: [{ type: "string" }, { type: "boolean" }, { $ref: "#/$defs/Runium_TaskState" }] }, Runium_TaskState: { type: "object", properties: { status: { $ref: "#/$defs/Runium_TaskStatus" }, iteration: { type: "number", minimum: 0 }, exitCode: { type: "number", minimum: 0 } }, additionalProperties: !1 }, Runium_TaskStatus: { type: "string", enum: Object.values(h) }, Runium_TaskDependency: { type: "object", properties: { taskId: { type: "string" }, condition: { $ref: "#/$defs/Runium_TaskStateCondition" } }, required: ["taskId", "condition"], additionalProperties: !1 }, Runium_Trigger: { oneOf: [{ $ref: "#/$defs/Runium_TriggerEvent" }, { $ref: "#/$defs/Runium_TriggerInterval" }, { $ref: "#/$defs/Runium_TriggerTimeout" }] }, Runium_TriggerEvent: { type: "object", properties: { ...structuredClone(k), type: { const: l.EVENT }, event: { type: "string" } }, required: ["id", "type", "event", "action"], additionalProperties: !1 }, Runium_TriggerInterval: { type: "object", properties: { ...structuredClone(k), type: { const: l.INTERVAL }, interval: { type: "number", minimum: 0 } }, required: ["id", "type", "interval", "action"], additionalProperties: !1 }, Runium_TriggerTimeout: { type: "object", properties: { ...structuredClone(k), type: { const: l.TIMEOUT }, timeout: { type: "number", minimum: 0 } }, required: ["id", "type", "timeout", "action"], additionalProperties: !1 }, Runium_Action: { oneOf: [{ $ref: "#/$defs/Runium_ActionEmitEvent" }, { $ref: "#/$defs/Runium_ActionProcessTask" }, { $ref: "#/$defs/Runium_ActionStopProject" }, { $ref: "#/$defs/Runium_ActionToggleTrigger" }] }, Runium_ActionEmitEvent: { type: "object", properties: { type: { type: "string", const: d.EMIT_EVENT }, event: { type: "string" } }, required: ["type", "event"], additionalProperties: !1 }, Runium_ActionProcessTask: { type: "object", properties: { type: { type: "string", enum: [d.START_TASK, d.RESTART_TASK, d.STOP_TASK] }, taskId: { type: "string" } }, required: ["type", "taskId"], additionalProperties: !1 }, Runium_ActionStopProject: { type: "object", properties: { type: { type: "string", const: d.STOP_PROJECT } }, required: ["type"], additionalProperties: !1 }, Runium_ActionToggleTrigger: { type: "object", properties: { type: { type: "string", enum: [d.ENABLE_TRIGGER, d.DISABLE_TRIGGER] }, triggerId: { type: "string" } }, required: ["type", "triggerId"], additionalProperties: !1 }, Runium_TaskConfig: { ...D(f.DEFAULT, { $ref: "#/$defs/Runium_TaskOptions" }) }, Runium_TaskOptions: { type: "object", properties: { command: { type: "string" }, arguments: { type: "array", items: { type: "string" } }, shell: { type: "boolean" }, cwd: { type: "string" }, env: { $ref: "#/$defs/Runium_Env" }, ttl: { type: "number" }, log: { $ref: "#/$defs/Runium_TaskLog" }, stopSignal: { type: "string" } }, required: ["command"], additionalProperties: !1 }, Runium_TaskRestartPolicy: { oneOf: [{ $ref: "#/$defs/Runium_TaskRestartPolicyAlways" }, { $ref: "#/$defs/Runium_TaskRestartPolicyOnFailure" }] }, Runium_TaskRestartPolicyAlways: { type: "object", required: ["policy"], properties: { policy: { const: T.ALWAYS }, delay: { type: "number" } }, additionalProperties: !1 }, Runium_TaskRestartPolicyOnFailure: { type: "object", required: ["policy"], properties: { policy: { const: T.ON_FAILURE }, delay: { type: "number" }, maxRetries: { type: "number" } }, additionalProperties: !1 }, Runium_TaskLog: { type: "object", properties: { stdout: { type: ["string", "null"] }, stderr: { type: ["string", "null"] } }, additionalProperties: !1 } } };
|
|
218
|
+
const e = { $schema: "https://json-schema.org/draft/2020-12/schema", $id: "https://example.com/schemas/project.json", title: "Project", type: "object", properties: { id: { type: "string" }, name: { type: "string" }, tasks: { type: "array", items: { oneOf: [{ $ref: "#/$defs/Runium_TaskConfig" }] }, minItems: 1, uniqueItemProperties: ["id"] }, triggers: { type: "array", items: { $ref: "#/$defs/Runium_Trigger" }, uniqueItemProperties: ["id"] } }, required: ["id", "tasks"], additionalProperties: !1, $defs: { Runium_EnvValue: { type: ["string", "number", "boolean"] }, Runium_Env: { type: "object", additionalProperties: { $ref: "#/$defs/Runium_EnvValue" } }, Runium_TaskStartMode: { type: "string", enum: Object.values(R) }, Runium_TaskHandler: { type: "object", properties: { action: { $ref: "#/$defs/Runium_Action" }, condition: { $ref: "#/$defs/Runium_TaskStateCondition" } }, required: ["action", "condition"], additionalProperties: !1 }, Runium_TaskStateCondition: { oneOf: [{ type: "string" }, { type: "boolean" }, { $ref: "#/$defs/Runium_TaskState" }] }, Runium_TaskState: { type: "object", properties: { status: { $ref: "#/$defs/Runium_TaskStatus" }, iteration: { type: "number", minimum: 0 }, exitCode: { type: "number", minimum: 0 }, reason: { type: "string" } }, additionalProperties: !1 }, Runium_TaskStatus: { type: "string", enum: Object.values(h) }, Runium_TaskDependency: { type: "object", properties: { taskId: { type: "string" }, condition: { $ref: "#/$defs/Runium_TaskStateCondition" } }, required: ["taskId", "condition"], additionalProperties: !1 }, Runium_Trigger: { oneOf: [{ $ref: "#/$defs/Runium_TriggerEvent" }, { $ref: "#/$defs/Runium_TriggerInterval" }, { $ref: "#/$defs/Runium_TriggerTimeout" }] }, Runium_TriggerEvent: { type: "object", properties: { ...structuredClone(k), type: { const: l.EVENT }, event: { type: "string" } }, required: ["id", "type", "event", "action"], additionalProperties: !1 }, Runium_TriggerInterval: { type: "object", properties: { ...structuredClone(k), type: { const: l.INTERVAL }, interval: { type: "number", minimum: 0 } }, required: ["id", "type", "interval", "action"], additionalProperties: !1 }, Runium_TriggerTimeout: { type: "object", properties: { ...structuredClone(k), type: { const: l.TIMEOUT }, timeout: { type: "number", minimum: 0 } }, required: ["id", "type", "timeout", "action"], additionalProperties: !1 }, Runium_Action: { oneOf: [{ $ref: "#/$defs/Runium_ActionEmitEvent" }, { $ref: "#/$defs/Runium_ActionProcessTask" }, { $ref: "#/$defs/Runium_ActionStopProject" }, { $ref: "#/$defs/Runium_ActionToggleTrigger" }] }, Runium_ActionEmitEvent: { type: "object", properties: { type: { type: "string", const: d.EMIT_EVENT }, event: { type: "string" } }, required: ["type", "event"], additionalProperties: !1 }, Runium_ActionProcessTask: { type: "object", properties: { type: { type: "string", enum: [d.START_TASK, d.RESTART_TASK, d.STOP_TASK] }, taskId: { type: "string" } }, required: ["type", "taskId"], additionalProperties: !1 }, Runium_ActionStopProject: { type: "object", properties: { type: { type: "string", const: d.STOP_PROJECT } }, required: ["type"], additionalProperties: !1 }, Runium_ActionToggleTrigger: { type: "object", properties: { type: { type: "string", enum: [d.ENABLE_TRIGGER, d.DISABLE_TRIGGER] }, triggerId: { type: "string" } }, required: ["type", "triggerId"], additionalProperties: !1 }, Runium_TaskConfig: { ...D(f.DEFAULT, { $ref: "#/$defs/Runium_TaskOptions" }) }, Runium_TaskOptions: { type: "object", properties: { command: { type: "string" }, arguments: { type: "array", items: { type: "string" } }, shell: { type: "boolean" }, cwd: { type: "string" }, env: { $ref: "#/$defs/Runium_Env" }, ttl: { type: "number" }, log: { $ref: "#/$defs/Runium_TaskLog" }, stopSignal: { type: "string" } }, required: ["command"], additionalProperties: !1 }, Runium_TaskRestartPolicy: { oneOf: [{ $ref: "#/$defs/Runium_TaskRestartPolicyAlways" }, { $ref: "#/$defs/Runium_TaskRestartPolicyOnFailure" }] }, Runium_TaskRestartPolicyAlways: { type: "object", required: ["policy"], properties: { policy: { const: T.ALWAYS }, delay: { type: "number" } }, additionalProperties: !1 }, Runium_TaskRestartPolicyOnFailure: { type: "object", required: ["policy"], properties: { policy: { const: T.ON_FAILURE }, delay: { type: "number" }, maxRetries: { type: "number" } }, additionalProperties: !1 }, Runium_TaskLog: { type: "object", properties: { stdout: { type: ["string", "null"] }, stderr: { type: ["string", "null"] } }, additionalProperties: !1 } } };
|
|
219
219
|
return Object.freeze(e);
|
|
220
220
|
}
|
|
221
221
|
function at(e, t) {
|
|
@@ -359,15 +359,15 @@ class jt extends O {
|
|
|
359
359
|
}
|
|
360
360
|
this.updateState({ status: "started" });
|
|
361
361
|
}
|
|
362
|
-
async stop() {
|
|
362
|
+
async stop(t = "") {
|
|
363
363
|
if (this.state.status !== "started" && this.state.status !== "starting") return;
|
|
364
|
-
this.updateState({ status: "stopping" }), this.cleanupTriggers();
|
|
365
|
-
const
|
|
366
|
-
for (const
|
|
367
|
-
const { instance:
|
|
368
|
-
|
|
364
|
+
this.updateState({ status: "stopping", reason: t }), this.cleanupTriggers();
|
|
365
|
+
const s = this.getTasksStartOrder().reverse(), r = [];
|
|
366
|
+
for (const i of s) if (this.tasks.has(i)) {
|
|
367
|
+
const { instance: o } = this.tasks.get(i), { status: a } = o.getState();
|
|
368
|
+
a === h.STARTED && r.push(o.stop("project-stop"));
|
|
369
369
|
}
|
|
370
|
-
await Promise.allSettled(
|
|
370
|
+
await Promise.allSettled(r), this.updateState({ status: "stopped" });
|
|
371
371
|
}
|
|
372
372
|
extendValidationSchema(t) {
|
|
373
373
|
this.schema = at(this.schema, t);
|
|
@@ -445,7 +445,7 @@ class jt extends O {
|
|
|
445
445
|
async stopTask(t) {
|
|
446
446
|
if (this.tasks.has(t)) {
|
|
447
447
|
const { instance: s } = this.tasks.get(t), { status: r } = s.getState();
|
|
448
|
-
if (r === h.STARTED) return this.emit("stop-task", t), s.stop();
|
|
448
|
+
if (r === h.STARTED) return this.emit("stop-task", t), s.stop("action-stop");
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
451
|
async restartTask(t) {
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runium/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Runium Core",
|
|
5
5
|
"author": "TheBeastApp",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"types": "./index.d.ts",
|
|
8
9
|
"main": "./index.js",
|
|
9
10
|
"module": "./index.js",
|
|
10
11
|
"files": [
|
|
11
|
-
"index.js"
|
|
12
|
+
"index.js",
|
|
13
|
+
"index.d.ts"
|
|
12
14
|
],
|
|
13
15
|
"exports": {
|
|
14
16
|
".": {
|
|
17
|
+
"types": "./index.d.ts",
|
|
15
18
|
"import": "./index.js"
|
|
16
19
|
}
|
|
17
20
|
},
|