@runium/core 1.0.0 → 1.0.1
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 +41 -39
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -41,24 +41,26 @@ function qt(e, t) {
|
|
|
41
41
|
const s = Object.keys(t), i = String.raw`\$(${s.join("|")})\(([^()]*(?:\([^()]*\)[^()]*)*)\)`, r = (o) => {
|
|
42
42
|
const a = new RegExp(i, "g");
|
|
43
43
|
let c = o, n = !0;
|
|
44
|
-
for (; n; ) n = !1, c = c.replace(a, (
|
|
44
|
+
for (; n; ) n = !1, c = c.replace(a, (d, h, Y) => {
|
|
45
45
|
n = !0;
|
|
46
46
|
const R = [];
|
|
47
47
|
let w = 0, k = "";
|
|
48
|
-
for (const
|
|
48
|
+
for (const g of Y) g === "," && w === 0 ? (R.push(k.trim()), k = "") : (g === "(" && w++, g === ")" && w--, k += g);
|
|
49
49
|
R.push(k.trim());
|
|
50
|
-
const V = R.map((
|
|
50
|
+
const V = R.map((g) => g ? r(g) : "");
|
|
51
51
|
try {
|
|
52
|
-
return t[
|
|
53
|
-
} catch (
|
|
54
|
-
throw new p(`Can not apply macro "${
|
|
52
|
+
return t[h](...V);
|
|
53
|
+
} catch (g) {
|
|
54
|
+
throw new p(`Can not apply macro "${h}"`, "macro-apply-error", { type: h, args: R, original: g });
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
return c;
|
|
58
58
|
};
|
|
59
59
|
return (function(o) {
|
|
60
60
|
const a = new RegExp(rt, "g");
|
|
61
|
-
|
|
61
|
+
let c = o, n = !0;
|
|
62
|
+
for (; n; ) n = !1, c = c.replace(a, (d, h) => (n = !0, h.trim()));
|
|
63
|
+
return c;
|
|
62
64
|
})(s.length ? r(e) : e);
|
|
63
65
|
}
|
|
64
66
|
const L = z(H);
|
|
@@ -128,11 +130,11 @@ async function ot(e, t = "SIGTERM", s = "SIGKILL", i = 1e3) {
|
|
|
128
130
|
const r = await G(e);
|
|
129
131
|
K(r);
|
|
130
132
|
const o = (function(a) {
|
|
131
|
-
const c = [], n = (
|
|
132
|
-
c.push(
|
|
133
|
-
for (const
|
|
133
|
+
const c = [], n = (d) => {
|
|
134
|
+
c.push(d);
|
|
135
|
+
for (const h of d.children) n(h);
|
|
134
136
|
};
|
|
135
|
-
return n(a), c.sort((
|
|
137
|
+
return n(a), c.sort((d, h) => h.depth - d.depth);
|
|
136
138
|
})(r);
|
|
137
139
|
for (const a of o)
|
|
138
140
|
m(a.pid) && !await C(a.pid, t, i) && m(a.pid) && await C(a.pid, s, i);
|
|
@@ -144,8 +146,8 @@ async function Ut(e) {
|
|
|
144
146
|
};
|
|
145
147
|
return i(t), s;
|
|
146
148
|
}
|
|
147
|
-
var y = ((e) => (e.IMMEDIATE = "immediate", e.DEFERRED = "deferred", e.IGNORE = "ignore", e))(y || {}),
|
|
148
|
-
const at = /* @__PURE__ */ new Set(["start-task", "restart-task", "stop-task"]), ct = /* @__PURE__ */ new Set(["enable-trigger", "disable-trigger"]), pt = new Set(Object.values(
|
|
149
|
+
var y = ((e) => (e.IMMEDIATE = "immediate", e.DEFERRED = "deferred", e.IGNORE = "ignore", e))(y || {}), u = ((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))(u || {}), S = ((e) => (e.DEFAULT = "default", e))(S || {}), l = ((e) => (e.EVENT = "event", e.TIMEOUT = "timeout", e.INTERVAL = "interval", e))(l || {}), E = ((e) => (e.ALWAYS = "always", e.ON_FAILURE = "on-failure", e))(E || {}), nt = ((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))(nt || {});
|
|
150
|
+
const at = /* @__PURE__ */ new Set(["start-task", "restart-task", "stop-task"]), ct = /* @__PURE__ */ new Set(["enable-trigger", "disable-trigger"]), pt = new Set(Object.values(u)), dt = new Set(Object.values(l));
|
|
149
151
|
function P(e) {
|
|
150
152
|
return at.has(e.type);
|
|
151
153
|
}
|
|
@@ -180,12 +182,12 @@ function gt(e) {
|
|
|
180
182
|
(function(r) {
|
|
181
183
|
const o = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), c = (n) => {
|
|
182
184
|
if (a.has(n)) {
|
|
183
|
-
const
|
|
184
|
-
throw new p(`Project config tasks circular dependency detected ${
|
|
185
|
+
const d = [...a, n].join(" -> ");
|
|
186
|
+
throw new p(`Project config tasks circular dependency detected ${d}`, "project-config-tasks-circular-dependency", { task: n, dependencies: [...a] });
|
|
185
187
|
}
|
|
186
188
|
if (!o.has(n)) {
|
|
187
189
|
a.add(n);
|
|
188
|
-
for (const
|
|
190
|
+
for (const d of r.get(n) || []) c(d);
|
|
189
191
|
a.delete(n), o.add(n);
|
|
190
192
|
}
|
|
191
193
|
};
|
|
@@ -199,7 +201,7 @@ function ft(e, t) {
|
|
|
199
201
|
})(e, t), gt(e);
|
|
200
202
|
}
|
|
201
203
|
tt(q, ["uniqueItemProperties"]);
|
|
202
|
-
var
|
|
204
|
+
var f = ((e) => (e.IDLE = "idle", e.STARTING = "starting", e.STARTED = "started", e.COMPLETED = "completed", e.FAILED = "failed", e.STOPPING = "stopping", e.STOPPED = "stopped", e))(f || {}), A = ((e) => (e.STATE_CHANGE = "state-change", e.STDOUT = "stdout", e.STDERR = "stderr", e))(A || {});
|
|
203
205
|
const Ft = -1;
|
|
204
206
|
class U extends N {
|
|
205
207
|
constructor(t) {
|
|
@@ -307,7 +309,7 @@ function _(e, t) {
|
|
|
307
309
|
return { type: "object", properties: { ...structuredClone(yt), type: { type: "string", const: e }, ...s }, required: ["id", "type", "action", ...i], additionalProperties: !1 };
|
|
308
310
|
}
|
|
309
311
|
function St() {
|
|
310
|
-
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", pattern: b.source }, 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(y) }, 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(
|
|
312
|
+
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", pattern: b.source }, 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(y) }, 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(f) }, 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: _(l.EVENT, { type: "object", properties: { event: { type: "string" } }, required: ["event"], additionalProperties: !1 }), Runium_TriggerInterval: _(l.INTERVAL, { type: "object", properties: { interval: { type: "number", minimum: 0 } }, required: ["interval"], additionalProperties: !1 }), Runium_TriggerTimeout: _(l.TIMEOUT, { type: "object", properties: { timeout: { type: "number", minimum: 0 } }, required: ["timeout"], additionalProperties: !1 }), Runium_Action: { oneOf: [{ $ref: "#/$defs/Runium_ActionEmitEvent" }, { $ref: "#/$defs/Runium_ActionProcessTask" }, { $ref: "#/$defs/Runium_ActionStopProject" }, { $ref: "#/$defs/Runium_ActionToggleTrigger" }] }, Runium_ActionEmitEvent: T(u.EMIT_EVENT, { type: "object", properties: { event: { type: "string" } }, required: ["event"], additionalProperties: !1 }), Runium_ActionProcessTask: T([u.START_TASK, u.RESTART_TASK, u.STOP_TASK], { type: "object", properties: { taskId: { type: "string" } }, required: ["taskId"], additionalProperties: !1 }), Runium_ActionStopProject: T(u.STOP_PROJECT), Runium_ActionToggleTrigger: T([u.ENABLE_TRIGGER, u.DISABLE_TRIGGER], { type: "object", properties: { triggerId: { type: "string" } }, required: ["triggerId"], additionalProperties: !1 }), Runium_TaskConfig: { ...F(S.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: E.ALWAYS }, delay: { type: "number" } }, additionalProperties: !1 }, Runium_TaskRestartPolicyOnFailure: { type: "object", required: ["policy"], properties: { policy: { const: E.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 } } };
|
|
311
313
|
return Object.freeze(e);
|
|
312
314
|
}
|
|
313
315
|
function Et(e, t) {
|
|
@@ -332,8 +334,8 @@ function Et(e, t) {
|
|
|
332
334
|
})(s, t.tasks)), t.actions && (s = (function(i, r) {
|
|
333
335
|
if (r) {
|
|
334
336
|
const o = new Set(i.$defs.Runium_Action.oneOf.map((c) => {
|
|
335
|
-
const n = c.$ref.split("/").pop() || "",
|
|
336
|
-
return
|
|
337
|
+
const n = c.$ref.split("/").pop() || "", d = i.$defs[n]?.properties?.type;
|
|
338
|
+
return d?.enum || [d?.const];
|
|
337
339
|
}).flat()), a = {};
|
|
338
340
|
for (const [c, n] of Object.entries(r)) {
|
|
339
341
|
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 });
|
|
@@ -460,7 +462,7 @@ class Yt extends N {
|
|
|
460
462
|
const s = this.getTasksStartOrder().reverse(), i = [];
|
|
461
463
|
for (const r of s) if (this.tasks.has(r)) {
|
|
462
464
|
const { instance: o } = this.tasks.get(r), { status: a } = o.getState();
|
|
463
|
-
a ===
|
|
465
|
+
a === f.STARTED && i.push(o.stop("project-stop"));
|
|
464
466
|
}
|
|
465
467
|
await Promise.allSettled(i), this.updateState({ status: "stopped" });
|
|
466
468
|
}
|
|
@@ -514,13 +516,13 @@ class Yt extends N {
|
|
|
514
516
|
onTaskStateChange(t, s) {
|
|
515
517
|
const { config: i, instance: r } = this.tasks.get(t), o = this.getDependentTasks(t);
|
|
516
518
|
for (const a of o) this.isDependentTaskReady(a) && this.startTask(a);
|
|
517
|
-
if (s.status ===
|
|
519
|
+
if (s.status === f.COMPLETED || s.status === f.FAILED) {
|
|
518
520
|
const { restart: a } = i;
|
|
519
521
|
if (a && s.exitCode !== -1) {
|
|
520
522
|
const { policy: c } = a;
|
|
521
523
|
if (c === E.ALWAYS || c === E.ON_FAILURE && s.exitCode !== 0) {
|
|
522
|
-
const { maxRetries: n = 1 / 0, delay:
|
|
523
|
-
s.iteration <= n && setTimeout(r.restart.bind(r),
|
|
524
|
+
const { maxRetries: n = 1 / 0, delay: d = 0 } = a;
|
|
525
|
+
s.iteration <= n && setTimeout(r.restart.bind(r), d);
|
|
524
526
|
}
|
|
525
527
|
}
|
|
526
528
|
}
|
|
@@ -534,13 +536,13 @@ class Yt extends N {
|
|
|
534
536
|
async startTask(t) {
|
|
535
537
|
if (this.tasks.has(t)) {
|
|
536
538
|
const { instance: s } = this.tasks.get(t), { status: i } = s.getState();
|
|
537
|
-
if (i !==
|
|
539
|
+
if (i !== f.STARTED && i !== f.STARTING && i !== f.STOPPING) return this.emit("start-task", t), s.start();
|
|
538
540
|
}
|
|
539
541
|
}
|
|
540
542
|
async stopTask(t) {
|
|
541
543
|
if (this.tasks.has(t)) {
|
|
542
544
|
const { instance: s } = this.tasks.get(t), { status: i } = s.getState();
|
|
543
|
-
if (i ===
|
|
545
|
+
if (i === f.STARTED) return this.emit("stop-task", t), s.stop("action-stop");
|
|
544
546
|
}
|
|
545
547
|
}
|
|
546
548
|
async restartTask(t) {
|
|
@@ -584,13 +586,13 @@ class Yt extends N {
|
|
|
584
586
|
if (this.emit("process-action", t), P(t)) {
|
|
585
587
|
const s = t.options.taskId;
|
|
586
588
|
switch (t.type) {
|
|
587
|
-
case
|
|
589
|
+
case u.START_TASK:
|
|
588
590
|
this.startTask(s);
|
|
589
591
|
break;
|
|
590
|
-
case
|
|
592
|
+
case u.RESTART_TASK:
|
|
591
593
|
this.restartTask(s);
|
|
592
594
|
break;
|
|
593
|
-
case
|
|
595
|
+
case u.STOP_TASK:
|
|
594
596
|
this.stopTask(s);
|
|
595
597
|
}
|
|
596
598
|
return;
|
|
@@ -598,10 +600,10 @@ class Yt extends N {
|
|
|
598
600
|
if (j(t)) {
|
|
599
601
|
const s = t.options.triggerId;
|
|
600
602
|
switch (t.type) {
|
|
601
|
-
case
|
|
603
|
+
case u.ENABLE_TRIGGER:
|
|
602
604
|
this.enableTrigger(s);
|
|
603
605
|
break;
|
|
604
|
-
case
|
|
606
|
+
case u.DISABLE_TRIGGER:
|
|
605
607
|
this.disableTrigger(s);
|
|
606
608
|
}
|
|
607
609
|
return;
|
|
@@ -611,10 +613,10 @@ class Yt extends N {
|
|
|
611
613
|
return void (s && s(t.options || {}));
|
|
612
614
|
}
|
|
613
615
|
switch (t.type) {
|
|
614
|
-
case
|
|
616
|
+
case u.EMIT_EVENT:
|
|
615
617
|
this.emit(t.options.event);
|
|
616
618
|
break;
|
|
617
|
-
case
|
|
619
|
+
case u.STOP_PROJECT:
|
|
618
620
|
this.stop("action");
|
|
619
621
|
}
|
|
620
622
|
}
|
|
@@ -626,13 +628,13 @@ class Yt extends N {
|
|
|
626
628
|
const r = this.triggerProcessors.get(i.type);
|
|
627
629
|
r && (s = new r(i, t));
|
|
628
630
|
} else switch (i.type) {
|
|
629
|
-
case
|
|
631
|
+
case l.EVENT:
|
|
630
632
|
s = new Rt(i, t);
|
|
631
633
|
break;
|
|
632
|
-
case
|
|
634
|
+
case l.INTERVAL:
|
|
633
635
|
s = new kt(i, t);
|
|
634
636
|
break;
|
|
635
|
-
case
|
|
637
|
+
case l.TIMEOUT:
|
|
636
638
|
s = new At(i, t);
|
|
637
639
|
}
|
|
638
640
|
s && (this.triggers.set(i.id, s), i.disabled !== !0 && s.enable());
|
|
@@ -661,7 +663,7 @@ export {
|
|
|
661
663
|
kt as IntervalTrigger,
|
|
662
664
|
it as MacrosErrorCode,
|
|
663
665
|
Yt as Project,
|
|
664
|
-
|
|
666
|
+
u as ProjectActionType,
|
|
665
667
|
nt as ProjectConfigErrorCode,
|
|
666
668
|
wt as ProjectErrorCode,
|
|
667
669
|
_t as ProjectEvent,
|
|
@@ -670,14 +672,14 @@ export {
|
|
|
670
672
|
E as ProjectTaskRestartPolicyType,
|
|
671
673
|
y as ProjectTaskStartMode,
|
|
672
674
|
S as ProjectTaskType,
|
|
673
|
-
|
|
675
|
+
l as ProjectTriggerType,
|
|
674
676
|
p as RuniumError,
|
|
675
677
|
U as RuniumTask,
|
|
676
678
|
I as RuniumTrigger,
|
|
677
679
|
Ft as SILENT_EXIT_CODE,
|
|
678
680
|
lt as Task,
|
|
679
681
|
A as TaskEvent,
|
|
680
|
-
|
|
682
|
+
f as TaskStatus,
|
|
681
683
|
At as TimeoutTrigger,
|
|
682
684
|
qt as applyMacros,
|
|
683
685
|
Et as extendProjectSchema,
|