@runium/core 0.0.1 → 0.0.2
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.js +133 -127
- package/package.json +2 -5
- package/index.d.ts +0 -387
package/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { readFile as G, writeFile as x, mkdir as
|
|
2
|
-
import { EventEmitter as
|
|
1
|
+
import { readFile as G, writeFile as x, mkdir as $ } from "node:fs/promises";
|
|
2
|
+
import { EventEmitter as O } from "node:events";
|
|
3
3
|
import M from "bcx-expression-evaluator";
|
|
4
4
|
import q from "ajv/dist/2020.js";
|
|
5
5
|
import K from "ajv-keywords";
|
|
6
6
|
import { spawn as U } from "node:child_process";
|
|
7
|
-
import { createWriteStream as
|
|
8
|
-
import { resolve as
|
|
9
|
-
class
|
|
7
|
+
import { createWriteStream as j } from "node:fs";
|
|
8
|
+
import { resolve as I, dirname as w } from "node:path";
|
|
9
|
+
class p extends Error {
|
|
10
10
|
code;
|
|
11
11
|
payload;
|
|
12
12
|
constructor(t, s, r = null) {
|
|
@@ -14,37 +14,42 @@ class d extends Error {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
function Et(e) {
|
|
17
|
-
return !!e && e instanceof
|
|
17
|
+
return !!e && e instanceof p;
|
|
18
18
|
}
|
|
19
19
|
var F = ((e) => (e.READ_JSON = "file-read-json", e.WRITE_JSON = "file-write-json", e))(F || {});
|
|
20
|
-
async function
|
|
20
|
+
async function At(e) {
|
|
21
21
|
try {
|
|
22
22
|
const t = await G(e, { encoding: "utf-8" });
|
|
23
23
|
return JSON.parse(t);
|
|
24
24
|
} catch (t) {
|
|
25
|
-
throw new
|
|
25
|
+
throw new p(`Can not read JSON file ${e}`, "file-read-json", { path: e, original: t });
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
async function
|
|
28
|
+
async function _t(e, t) {
|
|
29
29
|
try {
|
|
30
30
|
await x(e, JSON.stringify(t, null, 2), { encoding: "utf-8" });
|
|
31
31
|
} catch (s) {
|
|
32
|
-
throw new
|
|
32
|
+
throw new p(`Can not write JSON file ${e}`, "file-write-json", { path: e, data: t, original: s });
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
const Y = String.raw`"\$unwrap\((.*)\)"`;
|
|
36
|
-
|
|
36
|
+
var V = ((e) => (e.MACRO_APPLY_ERROR = "macro-apply-error", e))(V || {});
|
|
37
|
+
function It(e, t) {
|
|
37
38
|
const s = Object.keys(t), r = String.raw`\$(${s.join("|")})\(([^()]*(?:\([^()]*\)[^()]*)*)\)`, i = (o) => {
|
|
38
39
|
const a = new RegExp(r, "g");
|
|
39
40
|
let c = o, n = !0;
|
|
40
|
-
for (; n; ) n = !1, c = c.replace(a, (u,
|
|
41
|
+
for (; n; ) n = !1, c = c.replace(a, (u, A, L) => {
|
|
41
42
|
n = !0;
|
|
42
|
-
const
|
|
43
|
-
let
|
|
44
|
-
for (const
|
|
45
|
-
|
|
46
|
-
const N =
|
|
47
|
-
|
|
43
|
+
const m = [];
|
|
44
|
+
let _ = 0, y = "";
|
|
45
|
+
for (const g of L) g === "," && _ === 0 ? (m.push(y.trim()), y = "") : (g === "(" && _++, g === ")" && _--, y += g);
|
|
46
|
+
m.push(y.trim());
|
|
47
|
+
const N = m.map((g) => g ? i(g) : "");
|
|
48
|
+
try {
|
|
49
|
+
return t[A](...N);
|
|
50
|
+
} catch (g) {
|
|
51
|
+
throw new p(`Can not apply macro "${A}"`, "macro-apply-error", { type: A, args: m, original: g });
|
|
52
|
+
}
|
|
48
53
|
});
|
|
49
54
|
return c;
|
|
50
55
|
};
|
|
@@ -53,44 +58,44 @@ function _t(e, t) {
|
|
|
53
58
|
return o.replace(a, (c, n) => n.trim());
|
|
54
59
|
})(s.length ? i(e) : e);
|
|
55
60
|
}
|
|
56
|
-
var
|
|
57
|
-
const
|
|
58
|
-
function w(e) {
|
|
59
|
-
return J.has(e.type);
|
|
60
|
-
}
|
|
61
|
+
var R = ((e) => (e.IMMEDIATE = "immediate", e.DEFERRED = "deferred", e))(R || {}), d = ((e) => (e.EMIT_EVENT = "emit-event", e.START_TASK = "start-task", e.RESTART_TASK = "restart-task", e.STOP_TASK = "stop-task", e.STOP_PROJECT = "stop-project", e.ENABLE_TRIGGER = "enable-trigger", e.DISABLE_TRIGGER = "disable-trigger", e))(d || {}), f = ((e) => (e.DEFAULT = "default", e))(f || {}), l = ((e) => (e.EVENT = "event", e.TIMEOUT = "timeout", e.INTERVAL = "interval", e))(l || {}), T = ((e) => (e.ALWAYS = "always", e.ON_FAILURE = "on-failure", e))(T || {}), J = ((e) => (e.INCORRECT_DATA = "project-config-incorrect-data", e.TASKS_CIRCULAR_DEPENDENCY = "project-config-tasks-circular-dependency", e.TASK_NOT_EXISTS = "project-config-task-not-exists", e.TRIGGER_NOT_EXISTS = "project-config-trigger-not-exists", e))(J || {});
|
|
62
|
+
const B = /* @__PURE__ */ new Set(["start-task", "restart-task", "stop-task"]), H = /* @__PURE__ */ new Set(["enable-trigger", "disable-trigger"]), W = new Set(Object.values(d)), X = new Set(Object.values(l));
|
|
61
63
|
function P(e) {
|
|
62
64
|
return B.has(e.type);
|
|
63
65
|
}
|
|
64
|
-
function
|
|
65
|
-
return
|
|
66
|
+
function b(e) {
|
|
67
|
+
return H.has(e.type);
|
|
66
68
|
}
|
|
67
69
|
function z(e) {
|
|
68
70
|
return !W.has(e.type);
|
|
69
71
|
}
|
|
70
|
-
const O = new q({ allowUnionTypes: !0 });
|
|
71
72
|
function Q(e) {
|
|
73
|
+
return !X.has(e.type);
|
|
74
|
+
}
|
|
75
|
+
const v = new q({ allowUnionTypes: !0 });
|
|
76
|
+
function Z(e) {
|
|
72
77
|
const t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
|
|
73
78
|
for (const i of e.tasks) s.add(i.id), t.set(i.id, []);
|
|
74
79
|
const r = new Set(e.triggers?.map((i) => i.id) || []);
|
|
75
80
|
for (const i of e.tasks) {
|
|
76
81
|
for (const o of i.dependencies || []) {
|
|
77
|
-
if (!s.has(o.taskId)) throw new
|
|
82
|
+
if (!s.has(o.taskId)) throw new p(`Task "${i.id}" depends on not existing task "${o.taskId}"`, "project-config-task-not-exists", { taskId: i.id, dependency: { ...o }, scope: "dependencies" });
|
|
78
83
|
t.get(o.taskId).push(i.id);
|
|
79
84
|
}
|
|
80
85
|
for (const o of i.handlers || []) {
|
|
81
|
-
if (
|
|
82
|
-
if (
|
|
86
|
+
if (P(o.action) && !s.has(o.action.taskId)) throw new p(`Task "${i.id}" handler action uses not existing task "${o.action.taskId}"`, "project-config-task-not-exists", { taskId: i.id, handler: { ...o }, scope: "handlers" });
|
|
87
|
+
if (b(o.action) && !r.has(o.action.triggerId)) throw new p(`Task "${i.id}" handler action uses not existing trigger "${o.action.triggerId}"`, "project-config-trigger-not-exists", { taskId: i.id, handler: { ...o }, scope: "handlers" });
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
90
|
for (const i of e.triggers || []) {
|
|
86
|
-
if (
|
|
87
|
-
if (
|
|
91
|
+
if (P(i.action) && !s.has(i.action.taskId)) throw new p(`Trigger "${i.id}" action uses not existing task "${i.action.taskId}"`, "project-config-task-not-exists", { trigger: { ...i }, scope: "triggers" });
|
|
92
|
+
if (b(i.action) && !r.has(i.action.triggerId)) throw new p(`Trigger "${i.id}" action uses not existing trigger "${i.action.triggerId}"`, "project-config-trigger-not-exists", { trigger: { ...i }, scope: "triggers" });
|
|
88
93
|
}
|
|
89
94
|
(function(i) {
|
|
90
95
|
const o = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), c = (n) => {
|
|
91
96
|
if (a.has(n)) {
|
|
92
97
|
const u = [...a, n].join(" -> ");
|
|
93
|
-
throw new
|
|
98
|
+
throw new p(`Project config tasks circular dependency detected ${u}`, "project-config-tasks-circular-dependency", { task: n, dependencies: [...a] });
|
|
94
99
|
}
|
|
95
100
|
if (!o.has(n)) {
|
|
96
101
|
a.add(n);
|
|
@@ -101,23 +106,23 @@ function Q(e) {
|
|
|
101
106
|
for (const n of i.keys()) o.has(n) || c(n);
|
|
102
107
|
})(t);
|
|
103
108
|
}
|
|
104
|
-
function
|
|
109
|
+
function tt(e, t) {
|
|
105
110
|
(function(s, r) {
|
|
106
|
-
const i =
|
|
107
|
-
if (!i(s)) throw new
|
|
108
|
-
})(e, t),
|
|
111
|
+
const i = v.compile(r || {});
|
|
112
|
+
if (!i(s)) throw new p("Incorrect project config data", "project-config-incorrect-data", { errors: i.errors });
|
|
113
|
+
})(e, t), Z(e);
|
|
109
114
|
}
|
|
110
|
-
K(
|
|
111
|
-
var
|
|
112
|
-
const
|
|
113
|
-
class
|
|
115
|
+
K(v, ["uniqueItemProperties"]);
|
|
116
|
+
var h = ((e) => (e.IDLE = "idle", e.STARTING = "starting", e.STARTED = "started", e.COMPLETED = "completed", e.FAILED = "failed", e.STOPPING = "stopping", e.STOPPED = "stopped", e))(h || {}), S = ((e) => (e.STATE_CHANGE = "state-change", e.STDOUT = "stdout", e.STDERR = "stderr", e))(S || {});
|
|
117
|
+
const $t = -1;
|
|
118
|
+
class C extends O {
|
|
114
119
|
constructor(t) {
|
|
115
120
|
super(), this.options = t;
|
|
116
121
|
}
|
|
117
122
|
}
|
|
118
|
-
class
|
|
123
|
+
class et extends C {
|
|
119
124
|
constructor(t) {
|
|
120
|
-
super(t), this.options = t, this.setMaxListeners(50), this.options.env = { ...process.env, ...t.env || {} }, this.options.cwd =
|
|
125
|
+
super(t), this.options = t, this.setMaxListeners(50), this.options.env = { ...process.env, ...t.env || {} }, this.options.cwd = I(process.cwd(), t.cwd || "");
|
|
121
126
|
}
|
|
122
127
|
state = { status: "idle", pid: -1, timestamp: Date.now(), iteration: 0 };
|
|
123
128
|
process = null;
|
|
@@ -161,12 +166,12 @@ class tt extends v {
|
|
|
161
166
|
async initLogStreams() {
|
|
162
167
|
const { stdout: t = null, stderr: s = null } = this.options.log || {};
|
|
163
168
|
if (t) {
|
|
164
|
-
const r =
|
|
165
|
-
await
|
|
169
|
+
const r = I(t);
|
|
170
|
+
await $(w(r), { recursive: !0 }), this.stdoutStream = j(t, { flags: "w" });
|
|
166
171
|
}
|
|
167
172
|
if (s) {
|
|
168
|
-
const r =
|
|
169
|
-
await
|
|
173
|
+
const r = I(s);
|
|
174
|
+
await $(w(r), { recursive: !0 }), this.stderrStream = j(s, { flags: "w" });
|
|
170
175
|
}
|
|
171
176
|
}
|
|
172
177
|
setTTLTimer() {
|
|
@@ -197,23 +202,23 @@ class tt extends v {
|
|
|
197
202
|
this.ttlTimer && (clearTimeout(this.ttlTimer), this.ttlTimer = null), this.process && (this.process.removeAllListeners(), this.process.stdout?.removeAllListeners(), this.process.stderr?.removeAllListeners(), this.process = null), this.stdoutStream && (this.stdoutStream.end(), this.stdoutStream = null), this.stderrStream && (this.stderrStream.end(), this.stderrStream = null);
|
|
198
203
|
}
|
|
199
204
|
}
|
|
200
|
-
var
|
|
201
|
-
const
|
|
202
|
-
function
|
|
203
|
-
return { type: "object", properties: { ...structuredClone(
|
|
205
|
+
var st = ((e) => (e.ACTION_TYPE_ALREADY_USED = "project-schema-action-type-already-used", e.TASK_TYPE_ALREADY_USED = "project-schema-task-type-already-used", e.TRIGGER_TYPE_ALREADY_USED = "project-schema-trigger-type-already-used", e))(st || {});
|
|
206
|
+
const rt = { id: { type: "string" }, name: { type: "string" }, type: { type: "string" }, mode: { $ref: "#/$defs/Runium_TaskStartMode" }, dependencies: { type: "array", items: { $ref: "#/$defs/Runium_TaskDependency" } }, handlers: { type: "array", items: { $ref: "#/$defs/Runium_TaskHandler" } }, restart: { $ref: "#/$defs/Runium_TaskRestartPolicy" } }, k = { id: { type: "string" }, action: { $ref: "#/$defs/Runium_Action" }, disabled: { type: "boolean" } };
|
|
207
|
+
function D(e, t) {
|
|
208
|
+
return { type: "object", properties: { ...structuredClone(rt), type: { const: e }, options: { ...structuredClone(t) } }, required: ["id", "options"], additionalProperties: !1 };
|
|
204
209
|
}
|
|
205
|
-
function
|
|
210
|
+
function it(e, t) {
|
|
206
211
|
return { type: "object", properties: { type: { type: "string", const: e }, ...t ? { payload: t } : {} }, required: ["type", ...t ? ["payload"] : []], additionalProperties: !1 };
|
|
207
212
|
}
|
|
208
|
-
function
|
|
213
|
+
function ot(e, t) {
|
|
209
214
|
const s = t ? { payload: t } : {}, r = t ? ["payload"] : [];
|
|
210
|
-
return { type: "object", properties: { ...structuredClone(
|
|
215
|
+
return { type: "object", properties: { ...structuredClone(k), type: { type: "string", const: e }, ...s }, required: ["id", "type", "action", ...r], additionalProperties: !1 };
|
|
211
216
|
}
|
|
212
|
-
function
|
|
213
|
-
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(
|
|
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 } } };
|
|
214
219
|
return Object.freeze(e);
|
|
215
220
|
}
|
|
216
|
-
function
|
|
221
|
+
function at(e, t) {
|
|
217
222
|
let s = structuredClone(e);
|
|
218
223
|
return t.project && (s = (function(r, i) {
|
|
219
224
|
return i && (r.properties = { ...i.properties || {}, ...r.properties }, r.required = Array.from(/* @__PURE__ */ new Set([...r.required ?? [], ...i.required ?? []]))), r;
|
|
@@ -226,8 +231,8 @@ function nt(e, t) {
|
|
|
226
231
|
return r.$defs[n]?.properties?.type?.const || f.DEFAULT;
|
|
227
232
|
})), a = {};
|
|
228
233
|
for (const [c, n] of Object.entries(i)) {
|
|
229
|
-
if (o.has(n.type)) throw new
|
|
230
|
-
a[c] =
|
|
234
|
+
if (o.has(n.type)) throw new p(`Task type "${n.type}" already used in project schema`, "project-schema-task-type-already-used", { type: n.type });
|
|
235
|
+
a[c] = D(n.type, n.options), r.properties.tasks.items.oneOf.push({ $ref: `#/$defs/${c}` }), o.add(n.type);
|
|
231
236
|
}
|
|
232
237
|
r.$defs = { ...a, ...r.$defs };
|
|
233
238
|
}
|
|
@@ -239,8 +244,8 @@ function nt(e, t) {
|
|
|
239
244
|
return u?.enum || [u?.const];
|
|
240
245
|
}).flat()), a = {};
|
|
241
246
|
for (const [c, n] of Object.entries(i)) {
|
|
242
|
-
if (o.has(n.type)) throw new
|
|
243
|
-
a[c] =
|
|
247
|
+
if (o.has(n.type)) throw new p(`Action type "${n.type}" already used in project schema`, "project-schema-action-type-already-used", { type: n.type });
|
|
248
|
+
a[c] = it(n.type, n.payload), r.$defs.Runium_Action.oneOf.push({ $ref: `#/$defs/${c}` }), o.add(n.type);
|
|
244
249
|
}
|
|
245
250
|
r.$defs = { ...a, ...r.$defs };
|
|
246
251
|
}
|
|
@@ -252,8 +257,8 @@ function nt(e, t) {
|
|
|
252
257
|
return r.$defs[n]?.properties?.type?.const;
|
|
253
258
|
})), a = {};
|
|
254
259
|
for (const [c, n] of Object.entries(i)) {
|
|
255
|
-
if (o.has(n.type)) throw new
|
|
256
|
-
a[c] =
|
|
260
|
+
if (o.has(n.type)) throw new p(`Trigger type "${n.type}" already used in project schema`, "project-schema-trigger-type-already-used", { type: n.type });
|
|
261
|
+
a[c] = ot(n.type, n.payload), r.$defs.Runium_Trigger.oneOf.push({ $ref: `#/$defs/${c}` }), o.add(n.type);
|
|
257
262
|
}
|
|
258
263
|
r.$defs = { ...a, ...r.$defs };
|
|
259
264
|
}
|
|
@@ -275,7 +280,7 @@ class E {
|
|
|
275
280
|
return this.disabled;
|
|
276
281
|
}
|
|
277
282
|
}
|
|
278
|
-
class
|
|
283
|
+
class ct extends E {
|
|
279
284
|
event;
|
|
280
285
|
constructor(t, s) {
|
|
281
286
|
super(t, s), this.event = t.event;
|
|
@@ -290,7 +295,7 @@ class at extends E {
|
|
|
290
295
|
this.project.processAction(this.action);
|
|
291
296
|
};
|
|
292
297
|
}
|
|
293
|
-
class
|
|
298
|
+
class pt extends E {
|
|
294
299
|
interval;
|
|
295
300
|
intervalId = null;
|
|
296
301
|
constructor(t, s) {
|
|
@@ -320,20 +325,20 @@ class dt extends E {
|
|
|
320
325
|
this.timeoutId && clearTimeout(this.timeoutId), this.disabled = !0, this.timeoutId = null;
|
|
321
326
|
}
|
|
322
327
|
}
|
|
323
|
-
var
|
|
324
|
-
class
|
|
328
|
+
var ut = ((e) => (e.STATE_CHANGE = "state-change", e.START_TASK = "start-task", e.RESTART_TASK = "restart-task", e.STOP_TASK = "stop-task", e.PROCESS_ACTION = "process-action", e.ENABLE_TRIGGER = "enable-trigger", e.DISABLE_TRIGGER = "disable-trigger", e.TASK_STATE_CHANGE = "task-state-change", e.TASK_STDOUT = "task-stdout", e.TASK_STDERR = "task-stderr", e))(ut || {}), gt = ((e) => (e.IDLE = "idle", e.STARTING = "starting", e.STARTED = "started", e.STOPPING = "stopping", e.STOPPED = "stopped", e))(gt || {}), ht = ((e) => (e.ACTION_PROCESSOR_ALREADY_REGISTERED = "project-action-processor-already-registered", e.ACTION_PROCESSOR_INCORRECT = "project-action-processor-incorrect", e.TASK_PROCESSOR_NOT_FOUND = "project-task-processor-not-found", e.TASK_PROCESSOR_ALREADY_REGISTERED = "project-task-processor-already-registered", e.TASK_PROCESSOR_INCORRECT = "project-task-processor-incorrect", e.TRIGGER_PROCESSOR_ALREADY_REGISTERED = "project-trigger-processor-already-registered", e.TRIGGER_PROCESSOR_INCORRECT = "project-trigger-processor-incorrect", e))(ht || {});
|
|
329
|
+
class jt extends O {
|
|
325
330
|
constructor(t) {
|
|
326
331
|
super(), this.config = t;
|
|
327
332
|
}
|
|
328
|
-
schema =
|
|
329
|
-
taskProcessors = /* @__PURE__ */ new Map([[f.DEFAULT,
|
|
333
|
+
schema = nt();
|
|
334
|
+
taskProcessors = /* @__PURE__ */ new Map([[f.DEFAULT, et]]);
|
|
330
335
|
actionProcessors = /* @__PURE__ */ new Map();
|
|
331
336
|
triggerProcessors = /* @__PURE__ */ new Map();
|
|
332
337
|
tasks = /* @__PURE__ */ new Map();
|
|
333
338
|
triggers = /* @__PURE__ */ new Map();
|
|
334
339
|
state = { timestamp: Date.now(), status: "idle" };
|
|
335
340
|
validate() {
|
|
336
|
-
|
|
341
|
+
tt(this.config, this.schema);
|
|
337
342
|
}
|
|
338
343
|
getConfig() {
|
|
339
344
|
return { ...this.config };
|
|
@@ -349,8 +354,8 @@ class $t extends b {
|
|
|
349
354
|
this.validate(), this.initTasks(), this.initTriggers(), this.updateState({ status: "starting" });
|
|
350
355
|
const t = this.getTasksStartOrder();
|
|
351
356
|
for (const s of t) if (this.tasks.has(s)) {
|
|
352
|
-
const { instance: r, config: i } = this.tasks.get(s), { mode: o =
|
|
353
|
-
o ===
|
|
357
|
+
const { instance: r, config: i } = this.tasks.get(s), { mode: o = R.IMMEDIATE, dependencies: a = [] } = i;
|
|
358
|
+
o === R.IMMEDIATE && a.length === 0 && r.start();
|
|
354
359
|
}
|
|
355
360
|
this.updateState({ status: "started" });
|
|
356
361
|
}
|
|
@@ -360,26 +365,26 @@ class $t extends b {
|
|
|
360
365
|
const t = this.getTasksStartOrder().reverse(), s = [];
|
|
361
366
|
for (const r of t) if (this.tasks.has(r)) {
|
|
362
367
|
const { instance: i } = this.tasks.get(r), { status: o } = i.getState();
|
|
363
|
-
o ===
|
|
368
|
+
o === h.STARTED && s.push(i.stop());
|
|
364
369
|
}
|
|
365
370
|
await Promise.allSettled(s), this.updateState({ status: "stopped" });
|
|
366
371
|
}
|
|
367
372
|
extendValidationSchema(t) {
|
|
368
|
-
this.schema =
|
|
373
|
+
this.schema = at(this.schema, t);
|
|
369
374
|
}
|
|
370
375
|
registerAction(t, s) {
|
|
371
|
-
if (this.actionProcessors.has(t)) throw new
|
|
372
|
-
if (typeof s != "function") throw new
|
|
376
|
+
if (this.actionProcessors.has(t)) throw new p(`Action processor for type "${t}" already registered`, "project-action-processor-already-registered", { type: t });
|
|
377
|
+
if (typeof s != "function") throw new p(`Action processor for type "${t}" must be a function`, "project-action-processor-incorrect", { type: t });
|
|
373
378
|
this.actionProcessors.set(t, s);
|
|
374
379
|
}
|
|
375
380
|
registerTask(t, s) {
|
|
376
|
-
if (this.taskProcessors.has(t)) throw new
|
|
377
|
-
if (!(s.prototype instanceof
|
|
381
|
+
if (this.taskProcessors.has(t)) throw new p(`Task processor for type "${t}" already registered`, "project-task-processor-already-registered", { type: t });
|
|
382
|
+
if (!(s.prototype instanceof C)) throw new p(`Task processor for type "${t}" must be a subclass of "RuniumTask"`, "project-task-processor-incorrect", { type: t });
|
|
378
383
|
this.taskProcessors.set(t, s);
|
|
379
384
|
}
|
|
380
385
|
registerTrigger(t, s) {
|
|
381
|
-
if (this.triggerProcessors.has(t)) throw new
|
|
382
|
-
if (!(s.prototype instanceof E)) throw new
|
|
386
|
+
if (this.triggerProcessors.has(t)) throw new p(`Trigger processor for type "${t}" already registered`, "project-trigger-processor-already-registered", { type: t });
|
|
387
|
+
if (!(s.prototype instanceof E)) throw new p(`Trigger processor for type "${t}" must be a subclass of "RuniumTrigger"`, "project-trigger-processor-incorrect", { type: t });
|
|
383
388
|
this.triggerProcessors.set(t, s);
|
|
384
389
|
}
|
|
385
390
|
updateState(t) {
|
|
@@ -389,13 +394,13 @@ class $t extends b {
|
|
|
389
394
|
this.tasks.clear();
|
|
390
395
|
for (const t of this.config.tasks) {
|
|
391
396
|
const s = t.type || f.DEFAULT, r = this.taskProcessors.get(s);
|
|
392
|
-
if (!r) throw new
|
|
397
|
+
if (!r) throw new p(`Task processor for type "${s}" not found`, "project-task-processor-not-found", { type: s });
|
|
393
398
|
const i = new r(t.options);
|
|
394
|
-
i.on(
|
|
399
|
+
i.on(S.STATE_CHANGE, (o) => {
|
|
395
400
|
this.emit("task-state-change", t.id, o), this.onTaskStateChange(t.id, o);
|
|
396
|
-
}), i.on(
|
|
401
|
+
}), i.on(S.STDOUT, (o) => {
|
|
397
402
|
this.emit("task-stdout", t.id, o);
|
|
398
|
-
}), i.on(
|
|
403
|
+
}), i.on(S.STDERR, (o) => {
|
|
399
404
|
this.emit("task-stderr", t.id, o);
|
|
400
405
|
}), this.tasks.set(t.id, { instance: i, config: t, dependencies: [...t.dependencies || []], dependents: null });
|
|
401
406
|
}
|
|
@@ -414,7 +419,7 @@ class $t extends b {
|
|
|
414
419
|
onTaskStateChange(t, s) {
|
|
415
420
|
const { config: r, instance: i } = this.tasks.get(t), o = this.getDependentTasks(t);
|
|
416
421
|
for (const a of o) this.isDependentTaskReady(a) && this.startTask(a);
|
|
417
|
-
if (s.status ===
|
|
422
|
+
if (s.status === h.COMPLETED || s.status === h.FAILED) {
|
|
418
423
|
const { restart: a } = r;
|
|
419
424
|
if (a && s.exitCode !== -1) {
|
|
420
425
|
const { policy: c } = a;
|
|
@@ -434,13 +439,13 @@ class $t extends b {
|
|
|
434
439
|
async startTask(t) {
|
|
435
440
|
if (this.tasks.has(t)) {
|
|
436
441
|
const { instance: s } = this.tasks.get(t), { status: r } = s.getState();
|
|
437
|
-
if (r !==
|
|
442
|
+
if (r !== h.STARTED && r !== h.STARTING && r !== h.STOPPING) return this.emit("start-task", t), s.start();
|
|
438
443
|
}
|
|
439
444
|
}
|
|
440
445
|
async stopTask(t) {
|
|
441
446
|
if (this.tasks.has(t)) {
|
|
442
447
|
const { instance: s } = this.tasks.get(t), { status: r } = s.getState();
|
|
443
|
-
if (r ===
|
|
448
|
+
if (r === h.STARTED) return this.emit("stop-task", t), s.stop();
|
|
444
449
|
}
|
|
445
450
|
}
|
|
446
451
|
async restartTask(t) {
|
|
@@ -473,28 +478,28 @@ class $t extends b {
|
|
|
473
478
|
return s;
|
|
474
479
|
}
|
|
475
480
|
processAction(t) {
|
|
476
|
-
if (this.emit("process-action", t),
|
|
481
|
+
if (this.emit("process-action", t), z(t)) {
|
|
477
482
|
const s = this.actionProcessors.get(t.type);
|
|
478
483
|
s && s(t.payload || {});
|
|
479
484
|
} else switch (t.type) {
|
|
480
|
-
case
|
|
485
|
+
case d.START_TASK:
|
|
481
486
|
this.startTask(t.taskId);
|
|
482
487
|
break;
|
|
483
|
-
case
|
|
488
|
+
case d.RESTART_TASK:
|
|
484
489
|
this.restartTask(t.taskId);
|
|
485
490
|
break;
|
|
486
|
-
case
|
|
491
|
+
case d.STOP_TASK:
|
|
487
492
|
this.stopTask(t.taskId);
|
|
488
493
|
break;
|
|
489
|
-
case
|
|
494
|
+
case d.EMIT_EVENT:
|
|
490
495
|
this.emit(t.event);
|
|
491
496
|
break;
|
|
492
|
-
case
|
|
497
|
+
case d.STOP_PROJECT:
|
|
493
498
|
break;
|
|
494
|
-
case
|
|
499
|
+
case d.ENABLE_TRIGGER:
|
|
495
500
|
this.enableTrigger(t.triggerId);
|
|
496
501
|
break;
|
|
497
|
-
case
|
|
502
|
+
case d.DISABLE_TRIGGER:
|
|
498
503
|
this.disableTrigger(t.triggerId);
|
|
499
504
|
}
|
|
500
505
|
}
|
|
@@ -502,17 +507,17 @@ class $t extends b {
|
|
|
502
507
|
const t = { processAction: this.processAction.bind(this), on: this.on.bind(this), off: this.off.bind(this) };
|
|
503
508
|
let s = null;
|
|
504
509
|
for (const r of this.config.triggers || []) {
|
|
505
|
-
if (
|
|
510
|
+
if (Q(r)) {
|
|
506
511
|
const i = this.triggerProcessors.get(r.type);
|
|
507
512
|
i && (s = new i(r, t));
|
|
508
513
|
} else switch (r.type) {
|
|
509
|
-
case
|
|
510
|
-
s = new at(r, t);
|
|
511
|
-
break;
|
|
512
|
-
case h.INTERVAL:
|
|
514
|
+
case l.EVENT:
|
|
513
515
|
s = new ct(r, t);
|
|
514
516
|
break;
|
|
515
|
-
case
|
|
517
|
+
case l.INTERVAL:
|
|
518
|
+
s = new pt(r, t);
|
|
519
|
+
break;
|
|
520
|
+
case l.TIMEOUT:
|
|
516
521
|
s = new dt(r, t);
|
|
517
522
|
}
|
|
518
523
|
s && (this.triggers.set(r.id, s), r.disabled !== !0 && s.enable());
|
|
@@ -535,37 +540,38 @@ class $t extends b {
|
|
|
535
540
|
}
|
|
536
541
|
}
|
|
537
542
|
export {
|
|
538
|
-
|
|
543
|
+
ct as EventTrigger,
|
|
539
544
|
F as FileErrorCode,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
545
|
+
pt as IntervalTrigger,
|
|
546
|
+
V as MacrosErrorCode,
|
|
547
|
+
jt as Project,
|
|
548
|
+
d as ProjectActionType,
|
|
549
|
+
J as ProjectConfigErrorCode,
|
|
550
|
+
ht as ProjectErrorCode,
|
|
551
|
+
ut as ProjectEvent,
|
|
552
|
+
st as ProjectSchemaErrorCode,
|
|
553
|
+
gt as ProjectStatus,
|
|
548
554
|
T as ProjectTaskRestartPolicyType,
|
|
549
|
-
|
|
555
|
+
R as ProjectTaskStartMode,
|
|
550
556
|
f as ProjectTaskType,
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
557
|
+
l as ProjectTriggerType,
|
|
558
|
+
p as RuniumError,
|
|
559
|
+
C as RuniumTask,
|
|
554
560
|
E as RuniumTrigger,
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
561
|
+
$t as SILENT_EXIT_CODE,
|
|
562
|
+
et as Task,
|
|
563
|
+
S as TaskEvent,
|
|
564
|
+
h as TaskStatus,
|
|
559
565
|
dt as TimeoutTrigger,
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
+
It as applyMacros,
|
|
567
|
+
at as extendProjectSchema,
|
|
568
|
+
nt as getProjectSchema,
|
|
569
|
+
z as isCustomAction,
|
|
570
|
+
Q as isCustomTrigger,
|
|
571
|
+
P as isProcessTaskAction,
|
|
566
572
|
Et as isRuniumError,
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
573
|
+
b as isToggleTriggerAction,
|
|
574
|
+
At as readJsonFile,
|
|
575
|
+
tt as validateProject,
|
|
576
|
+
_t as writeJsonFile
|
|
571
577
|
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runium/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Runium Core",
|
|
5
5
|
"author": "TheBeastApp",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"types": "./index.d.ts",
|
|
9
8
|
"main": "./index.js",
|
|
10
9
|
"module": "./index.js",
|
|
11
10
|
"files": [
|
|
12
|
-
"index.js"
|
|
13
|
-
"index.d.ts"
|
|
11
|
+
"index.js"
|
|
14
12
|
],
|
|
15
13
|
"exports": {
|
|
16
14
|
".": {
|
|
17
|
-
"types": "./index.d.ts",
|
|
18
15
|
"import": "./index.js"
|
|
19
16
|
}
|
|
20
17
|
},
|
package/index.d.ts
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'node:events';
|
|
2
|
-
|
|
3
|
-
export declare function applyMacros(text: string, macros: MacrosCollection): string;
|
|
4
|
-
|
|
5
|
-
export declare class EventTrigger extends RuniumTrigger<EventTriggerOptions> {
|
|
6
|
-
constructor(options: EventTriggerOptions, project: RuniumTriggerProjectAccessible);
|
|
7
|
-
enable(): void;
|
|
8
|
-
disable(): void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export declare interface EventTriggerOptions extends RuniumTriggerOptions {
|
|
12
|
-
event: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export declare function extendProjectSchema(schema: object, extensions: ProjectSchemaExtension): object;
|
|
16
|
-
|
|
17
|
-
export declare enum FileErrorCode {
|
|
18
|
-
READ_JSON = "file-read-json",
|
|
19
|
-
WRITE_JSON = "file-write-json"
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export declare function getProjectSchema(): object;
|
|
23
|
-
|
|
24
|
-
export declare class IntervalTrigger extends RuniumTrigger<IntervalTriggerOptions> {
|
|
25
|
-
constructor(options: IntervalTriggerOptions, project: RuniumTriggerProjectAccessible);
|
|
26
|
-
enable(): void;
|
|
27
|
-
disable(): void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export declare interface IntervalTriggerOptions extends RuniumTriggerOptions {
|
|
31
|
-
interval: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export declare function isCustomAction(action: ProjectAction): action is ProjectCustomAction;
|
|
35
|
-
|
|
36
|
-
export declare function isCustomTrigger(trigger: ProjectTrigger): trigger is ProjectCustomTrigger;
|
|
37
|
-
|
|
38
|
-
export declare function isProcessTaskAction(action: ProjectAction): action is ProjectActionProcessTask;
|
|
39
|
-
|
|
40
|
-
export declare function isRuniumError(error: unknown): boolean;
|
|
41
|
-
|
|
42
|
-
export declare function isToggleTriggerAction(action: ProjectAction): action is ProjectActionToggleTrigger;
|
|
43
|
-
|
|
44
|
-
export declare interface JSONObject {
|
|
45
|
-
[x: string]: JSONValue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export declare type JSONValue = string | number | boolean | JSONObject | JSONValue[];
|
|
49
|
-
|
|
50
|
-
export declare type Macro = (...params: string[]) => string;
|
|
51
|
-
|
|
52
|
-
export declare type MacrosCollection = Record<string, Macro>;
|
|
53
|
-
|
|
54
|
-
export declare class Project extends EventEmitter {
|
|
55
|
-
constructor(config: ProjectConfig);
|
|
56
|
-
validate(): void;
|
|
57
|
-
getConfig(): ProjectConfig;
|
|
58
|
-
setConfig(config: ProjectConfig): void;
|
|
59
|
-
getState(): ProjectState;
|
|
60
|
-
start(): Promise<void>;
|
|
61
|
-
stop(): Promise<void>;
|
|
62
|
-
extendValidationSchema(extensions: ProjectSchemaExtension): void;
|
|
63
|
-
registerAction(type: string, processor: RuniumActionProcessor): void;
|
|
64
|
-
registerTask(type: string, processor: RuniumTaskConstructor<unknown, any>): void;
|
|
65
|
-
registerTrigger(type: string, processor: RuniumTriggerConstructor<any>): void;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export declare type ProjectAction = ProjectCustomAction | ProjectActionEmitEvent | ProjectActionProcessTask | ProjectActionStopProject | ProjectActionToggleTrigger;
|
|
69
|
-
|
|
70
|
-
export declare interface ProjectActionEmitEvent {
|
|
71
|
-
type: ProjectActionType.EMIT_EVENT;
|
|
72
|
-
event: string;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export declare interface ProjectActionProcessTask {
|
|
76
|
-
type: ProjectActionType.START_TASK | ProjectActionType.RESTART_TASK | ProjectActionType.STOP_TASK;
|
|
77
|
-
taskId: string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export declare interface ProjectActionStopProject {
|
|
81
|
-
type: ProjectActionType.STOP_PROJECT;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export declare interface ProjectActionToggleTrigger {
|
|
85
|
-
type: ProjectActionType.ENABLE_TRIGGER | ProjectActionType.DISABLE_TRIGGER;
|
|
86
|
-
triggerId: string;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export declare enum ProjectActionType {
|
|
90
|
-
EMIT_EVENT = "emit-event",
|
|
91
|
-
START_TASK = "start-task",
|
|
92
|
-
RESTART_TASK = "restart-task",
|
|
93
|
-
STOP_TASK = "stop-task",
|
|
94
|
-
STOP_PROJECT = "stop-project",
|
|
95
|
-
ENABLE_TRIGGER = "enable-trigger",
|
|
96
|
-
DISABLE_TRIGGER = "disable-trigger"
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export declare interface ProjectConfig {
|
|
100
|
-
id: string;
|
|
101
|
-
name?: string;
|
|
102
|
-
tasks: ProjectTaskConfig[];
|
|
103
|
-
triggers?: ProjectTrigger[];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export declare enum ProjectConfigErrorCode {
|
|
107
|
-
INCORRECT_DATA = "project-config-incorrect-data",
|
|
108
|
-
TASKS_CIRCULAR_DEPENDENCY = "project-config-tasks-circular-dependency",
|
|
109
|
-
TASK_NOT_EXISTS = "project-config-task-not-exists",
|
|
110
|
-
TRIGGER_NOT_EXISTS = "project-config-trigger-not-exists"
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export declare interface ProjectCustomAction {
|
|
114
|
-
type: string;
|
|
115
|
-
payload?: unknown;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export declare interface ProjectCustomTrigger extends ProjectTriggerBase {
|
|
119
|
-
type: string;
|
|
120
|
-
payload?: unknown;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export declare interface ProjectDefaultTaskConfig extends ProjectTaskConfig<TaskOptions> {
|
|
124
|
-
type?: ProjectTaskType.DEFAULT;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export declare enum ProjectErrorCode {
|
|
128
|
-
ACTION_PROCESSOR_ALREADY_REGISTERED = "project-action-processor-already-registered",
|
|
129
|
-
ACTION_PROCESSOR_INCORRECT = "project-action-processor-incorrect",
|
|
130
|
-
TASK_PROCESSOR_NOT_FOUND = "project-task-processor-not-found",
|
|
131
|
-
TASK_PROCESSOR_ALREADY_REGISTERED = "project-task-processor-already-registered",
|
|
132
|
-
TASK_PROCESSOR_INCORRECT = "project-task-processor-incorrect",
|
|
133
|
-
TRIGGER_PROCESSOR_ALREADY_REGISTERED = "project-trigger-processor-already-registered",
|
|
134
|
-
TRIGGER_PROCESSOR_INCORRECT = "project-trigger-processor-incorrect"
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export declare enum ProjectEvent {
|
|
138
|
-
STATE_CHANGE = "state-change",
|
|
139
|
-
START_TASK = "start-task",
|
|
140
|
-
RESTART_TASK = "restart-task",
|
|
141
|
-
STOP_TASK = "stop-task",
|
|
142
|
-
PROCESS_ACTION = "process-action",
|
|
143
|
-
ENABLE_TRIGGER = "enable-trigger",
|
|
144
|
-
DISABLE_TRIGGER = "disable-trigger",
|
|
145
|
-
TASK_STATE_CHANGE = "task-state-change",
|
|
146
|
-
TASK_STDOUT = "task-stdout",
|
|
147
|
-
TASK_STDERR = "task-stderr"
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export declare enum ProjectSchemaErrorCode {
|
|
151
|
-
ACTION_TYPE_ALREADY_USED = "project-schema-action-type-already-used",
|
|
152
|
-
TASK_TYPE_ALREADY_USED = "project-schema-task-type-already-used",
|
|
153
|
-
TRIGGER_TYPE_ALREADY_USED = "project-schema-trigger-type-already-used"
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export declare interface ProjectSchemaExtension {
|
|
157
|
-
project?: {
|
|
158
|
-
properties: unknown;
|
|
159
|
-
required?: string[];
|
|
160
|
-
};
|
|
161
|
-
tasks?: Record<string, {
|
|
162
|
-
type: string;
|
|
163
|
-
options: unknown;
|
|
164
|
-
}>;
|
|
165
|
-
definitions?: Record<string, unknown>;
|
|
166
|
-
actions?: Record<string, {
|
|
167
|
-
type: string;
|
|
168
|
-
payload?: unknown;
|
|
169
|
-
}>;
|
|
170
|
-
triggers?: Record<string, {
|
|
171
|
-
type: string;
|
|
172
|
-
payload?: unknown;
|
|
173
|
-
}>;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export declare interface ProjectState {
|
|
177
|
-
status: ProjectStatus;
|
|
178
|
-
timestamp: number;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export declare enum ProjectStatus {
|
|
182
|
-
IDLE = "idle",
|
|
183
|
-
STARTING = "starting",
|
|
184
|
-
STARTED = "started",
|
|
185
|
-
STOPPING = "stopping",
|
|
186
|
-
STOPPED = "stopped"
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export declare interface ProjectTaskConfig<Options = unknown> {
|
|
190
|
-
id: string;
|
|
191
|
-
options: Options;
|
|
192
|
-
type?: ProjectTaskType | string;
|
|
193
|
-
name?: string;
|
|
194
|
-
mode?: ProjectTaskStartMode;
|
|
195
|
-
dependencies?: ProjectTaskDependency[];
|
|
196
|
-
handlers?: ProjectTaskHandler[];
|
|
197
|
-
restart?: ProjectTaskRestartPolicy;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export declare interface ProjectTaskDependency {
|
|
201
|
-
taskId: string;
|
|
202
|
-
condition: ProjectTaskStateCondition;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export declare interface ProjectTaskHandler {
|
|
206
|
-
condition: ProjectTaskStateCondition;
|
|
207
|
-
action: ProjectAction;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export declare type ProjectTaskRestartPolicy = ProjectTaskRestartPolicyAlways | ProjectTaskRestartPolicyOnFailure;
|
|
211
|
-
|
|
212
|
-
export declare interface ProjectTaskRestartPolicyAlways {
|
|
213
|
-
policy: ProjectTaskRestartPolicyType.ALWAYS;
|
|
214
|
-
delay?: number;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export declare interface ProjectTaskRestartPolicyOnFailure {
|
|
218
|
-
policy: ProjectTaskRestartPolicyType.ON_FAILURE;
|
|
219
|
-
delay?: number;
|
|
220
|
-
maxRetries?: number;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export declare enum ProjectTaskRestartPolicyType {
|
|
224
|
-
ALWAYS = "always",
|
|
225
|
-
ON_FAILURE = "on-failure"
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export declare enum ProjectTaskStartMode {
|
|
229
|
-
IMMEDIATE = "immediate",
|
|
230
|
-
DEFERRED = "deferred"
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export declare type ProjectTaskStateCondition = string | boolean | Partial<RuniumTaskState> | ((state: RuniumTaskState) => boolean);
|
|
234
|
-
|
|
235
|
-
export declare enum ProjectTaskType {
|
|
236
|
-
DEFAULT = "default"
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export declare type ProjectTrigger = ProjectTriggerEvent | ProjectTriggerInterval | ProjectTriggerTimeout | ProjectCustomTrigger;
|
|
240
|
-
|
|
241
|
-
declare interface ProjectTriggerBase {
|
|
242
|
-
id: string;
|
|
243
|
-
type: ProjectTriggerType | string;
|
|
244
|
-
action: ProjectAction;
|
|
245
|
-
disabled?: boolean;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export declare interface ProjectTriggerEvent extends ProjectTriggerBase {
|
|
249
|
-
type: ProjectTriggerType.EVENT;
|
|
250
|
-
event: string;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export declare interface ProjectTriggerInterval extends ProjectTriggerBase {
|
|
254
|
-
type: ProjectTriggerType.INTERVAL;
|
|
255
|
-
interval: number;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export declare interface ProjectTriggerTimeout extends ProjectTriggerBase {
|
|
259
|
-
type: ProjectTriggerType.TIMEOUT;
|
|
260
|
-
timeout: number;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export declare enum ProjectTriggerType {
|
|
264
|
-
EVENT = "event",
|
|
265
|
-
TIMEOUT = "timeout",
|
|
266
|
-
INTERVAL = "interval"
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export declare function readJsonFile<T = JSONValue>(path: string): Promise<T>;
|
|
270
|
-
|
|
271
|
-
declare type RuniumActionProcessor = (payload: unknown) => void;
|
|
272
|
-
|
|
273
|
-
export declare class RuniumError extends Error {
|
|
274
|
-
code: string;
|
|
275
|
-
payload: unknown;
|
|
276
|
-
constructor(message: string, code: string, payload?: unknown);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export declare abstract class RuniumTask<Options = unknown, State = RuniumTaskState> extends EventEmitter {
|
|
280
|
-
protected options: Options;
|
|
281
|
-
protected constructor(options: Options);
|
|
282
|
-
abstract getOptions(): Options;
|
|
283
|
-
abstract getState(): State;
|
|
284
|
-
abstract start(): Promise<void>;
|
|
285
|
-
abstract stop(): Promise<void>;
|
|
286
|
-
abstract restart(): Promise<void>;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export declare type RuniumTaskConstructor<Options = unknown, State extends RuniumTaskState = RuniumTaskState> = new (options: any) => RuniumTask<Options, State>;
|
|
290
|
-
|
|
291
|
-
export declare interface RuniumTaskState {
|
|
292
|
-
status: TaskStatus;
|
|
293
|
-
timestamp: number;
|
|
294
|
-
iteration: number;
|
|
295
|
-
exitCode?: number;
|
|
296
|
-
error?: Error;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export declare abstract class RuniumTrigger<Options extends RuniumTriggerOptions> {
|
|
300
|
-
protected project: RuniumTriggerProjectAccessible;
|
|
301
|
-
protected id: string;
|
|
302
|
-
protected action: ProjectAction;
|
|
303
|
-
protected disabled: boolean;
|
|
304
|
-
constructor(options: Options, project: RuniumTriggerProjectAccessible);
|
|
305
|
-
abstract enable(): void;
|
|
306
|
-
abstract disable(): void;
|
|
307
|
-
getId(): string;
|
|
308
|
-
isDisabled(): boolean;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export declare type RuniumTriggerConstructor<Options extends RuniumTriggerOptions> = new (options: Options, project: RuniumTriggerProjectAccessible) => RuniumTrigger<Options>;
|
|
312
|
-
|
|
313
|
-
export declare interface RuniumTriggerOptions {
|
|
314
|
-
id: string;
|
|
315
|
-
action: ProjectAction;
|
|
316
|
-
disabled?: boolean;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export declare interface RuniumTriggerProjectAccessible {
|
|
320
|
-
processAction(action: ProjectAction): void;
|
|
321
|
-
on: NodeJS.EventEmitter['on'];
|
|
322
|
-
off: NodeJS.EventEmitter['off'];
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export declare const SILENT_EXIT_CODE = -1;
|
|
326
|
-
|
|
327
|
-
export declare class Task extends RuniumTask<TaskOptions, TaskState> {
|
|
328
|
-
protected readonly options: TaskOptions;
|
|
329
|
-
constructor(options: TaskOptions);
|
|
330
|
-
getState(): TaskState;
|
|
331
|
-
getOptions(): TaskOptions;
|
|
332
|
-
start(): Promise<void>;
|
|
333
|
-
stop(): Promise<void>;
|
|
334
|
-
restart(): Promise<void>;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
export declare enum TaskEvent {
|
|
338
|
-
STATE_CHANGE = "state-change",
|
|
339
|
-
STDOUT = "stdout",
|
|
340
|
-
STDERR = "stderr"
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
export declare interface TaskOptions {
|
|
344
|
-
command: string;
|
|
345
|
-
arguments?: string[];
|
|
346
|
-
shell?: boolean;
|
|
347
|
-
stopSignal?: string;
|
|
348
|
-
cwd?: string;
|
|
349
|
-
env?: {
|
|
350
|
-
[key: string]: string | number | boolean;
|
|
351
|
-
};
|
|
352
|
-
ttl?: number;
|
|
353
|
-
log?: {
|
|
354
|
-
stdout?: string | null;
|
|
355
|
-
stderr?: string | null;
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
export declare interface TaskState extends RuniumTaskState {
|
|
360
|
-
pid: number;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export declare enum TaskStatus {
|
|
364
|
-
IDLE = "idle",
|
|
365
|
-
STARTING = "starting",
|
|
366
|
-
STARTED = "started",
|
|
367
|
-
COMPLETED = "completed",
|
|
368
|
-
FAILED = "failed",
|
|
369
|
-
STOPPING = "stopping",
|
|
370
|
-
STOPPED = "stopped"
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export declare class TimeoutTrigger extends RuniumTrigger<TimeoutTriggerOptions> {
|
|
374
|
-
constructor(options: TimeoutTriggerOptions, project: RuniumTriggerProjectAccessible);
|
|
375
|
-
enable(): void;
|
|
376
|
-
disable(): void;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
export declare interface TimeoutTriggerOptions extends RuniumTriggerOptions {
|
|
380
|
-
timeout: number;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
export declare function validateProject(project: ProjectConfig, schema: object): void;
|
|
384
|
-
|
|
385
|
-
export declare function writeJsonFile<T = JSONValue>(path: string, data: T): Promise<void>;
|
|
386
|
-
|
|
387
|
-
export { }
|