@makoojs/core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.CN.md +104 -178
- package/README.md +89 -163
- package/dist/Makoo/createMakoo.d.ts +4 -0
- package/dist/Makoo/types.d.ts +89 -0
- package/dist/Task/TaskContext.d.ts +4 -84
- package/dist/Task/TaskLifeCycle.d.ts +7 -18
- package/dist/Task/TaskRegister.d.ts +15 -16
- package/dist/Task/TaskRunner.d.ts +6 -19
- package/dist/Task/types.d.ts +2 -6
- package/dist/adapter/Adapter.d.ts +2 -6
- package/dist/adapter/types.d.ts +5 -1
- package/dist/error/ErrorCode.d.ts +7 -0
- package/dist/error/SignalError.d.ts +4 -0
- package/dist/hooks/ObserverHub.d.ts +2 -20
- package/dist/hooks/types.d.ts +13 -1
- package/dist/hooks/util.d.ts +1 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1214 -1125
- package/dist/payload/buildRunObservePayload.d.ts +7 -7
- package/dist/runtime/createRuntime.d.ts +3 -0
- package/dist/runtime/types.d.ts +13 -0
- package/dist/signal/observeActivitySignal.d.ts +0 -4
- package/package.json +1 -1
- package/dist/Injector/Injector.d.ts +0 -48
- package/dist/Injector/types.d.ts +0 -29
package/dist/index.js
CHANGED
|
@@ -5,6 +5,13 @@ var e = {
|
|
|
5
5
|
ADAPTER_MOUNT_FAIL: "MAKOO_ADAPTER_MOUNT_FAIL",
|
|
6
6
|
ADAPTER_UNMOUNT_FAIL: "MAKOO_ADAPTER_UNMOUNT_FAIL",
|
|
7
7
|
TASK_NO_REGISTERED: "MAKOO_TASK_NO_REGISTERED",
|
|
8
|
+
TASK_NOT_FOUND: "MAKOO_TASK_NOT_FOUND",
|
|
9
|
+
TASK_INJECT_FAIL: "MAKOO_TASK_INJECT_FAIL",
|
|
10
|
+
TASK_ALREADY_MOUNTED: "MAKOO_TASK_ALREADY_MOUNTED",
|
|
11
|
+
TASK_TARGET_DETACHED: "MAKOO_TASK_TARGET_DETACHED",
|
|
12
|
+
TASK_LISTENER_ATTACH_FAIL: "MAKOO_TASK_LISTENER_ATTACH_FAIL",
|
|
13
|
+
TASK_SIGNAL_INVALID: "MAKOO_TASK_SIGNAL_INVALID",
|
|
14
|
+
TASK_SIGNAL_BIND_FAIL: "MAKOO_TASK_SIGNAL_BIND_FAIL",
|
|
8
15
|
CLI_SOURCE_DIR_NOT_FOUND: "MAKOO_CLI_SOURCE_DIR_NOT_FOUND",
|
|
9
16
|
CLI_MANIFEST_LOAD_FAIL: "MAKOO_CLI_MANIFEST_LOAD_FAIL",
|
|
10
17
|
CLI_MODULE_MANIFEST_LOAD_FAIL: "MAKOO_CLI_MODULE_MANIFEST_LOAD_FAIL",
|
|
@@ -42,10 +49,14 @@ var n = class extends Error {
|
|
|
42
49
|
super(t, n, r, i), this.name = "AdapterError";
|
|
43
50
|
}
|
|
44
51
|
}, i = class extends n {
|
|
52
|
+
constructor(t, n, r = e.TASK_SIGNAL_INVALID, i) {
|
|
53
|
+
super(t, n, r, i), this.name = "SignalError";
|
|
54
|
+
}
|
|
55
|
+
}, a = class extends n {
|
|
45
56
|
constructor(t, n, r = e.TASK_NO_REGISTERED, i) {
|
|
46
57
|
super(t, n, r, i), this.name = "TaskError";
|
|
47
58
|
}
|
|
48
|
-
},
|
|
59
|
+
}, o = class e {
|
|
49
60
|
static LEVELS = [
|
|
50
61
|
"debug",
|
|
51
62
|
"info",
|
|
@@ -79,24 +90,24 @@ var n = class extends Error {
|
|
|
79
90
|
debug(e, ...t) {
|
|
80
91
|
this.log("debug", e, ...t);
|
|
81
92
|
}
|
|
82
|
-
},
|
|
83
|
-
function
|
|
93
|
+
}, s = () => {};
|
|
94
|
+
function c(e) {
|
|
84
95
|
return e ? (t, n = {}) => {
|
|
85
96
|
e.emit({
|
|
86
97
|
name: t,
|
|
87
98
|
ts: Date.now(),
|
|
88
99
|
...n
|
|
89
100
|
});
|
|
90
|
-
} :
|
|
101
|
+
} : s;
|
|
91
102
|
}
|
|
92
|
-
function
|
|
103
|
+
function l(e, t, n) {
|
|
93
104
|
if (t) for (let [r, i] of Object.entries(t)) {
|
|
94
105
|
if (!i) continue;
|
|
95
106
|
let t = Array.isArray(i) ? i : [i];
|
|
96
107
|
for (let i of t) n ? e.onTask(n, r, i) : e.on(r, i);
|
|
97
108
|
}
|
|
98
109
|
}
|
|
99
|
-
function
|
|
110
|
+
function u() {
|
|
100
111
|
let e = !1, t = !1;
|
|
101
112
|
return {
|
|
102
113
|
ctrl: {
|
|
@@ -117,120 +128,128 @@ function l() {
|
|
|
117
128
|
}
|
|
118
129
|
//#endregion
|
|
119
130
|
//#region packages/core/src/hooks/ObserverHub.ts
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
onTask(e, t, n) {
|
|
134
|
-
this.taskHooks.has(e) || this.taskHooks.set(e, /* @__PURE__ */ new Map());
|
|
135
|
-
let r = this.taskHooks.get(e);
|
|
136
|
-
return r?.has(t) || r?.set(t, /* @__PURE__ */ new Set()), r?.get(t)?.add(n), () => {
|
|
137
|
-
this.offTask(e, t, n);
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
offTask(e, t, n) {
|
|
141
|
-
let r = this.taskHooks.get(e);
|
|
142
|
-
if (!r) return;
|
|
131
|
+
function d(e = new o()) {
|
|
132
|
+
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
|
|
133
|
+
function i(e, n) {
|
|
134
|
+
if (n) {
|
|
135
|
+
let r = t.get(e);
|
|
136
|
+
if (!r) return;
|
|
137
|
+
r.delete(n), r.size === 0 && t.delete(e);
|
|
138
|
+
} else t.delete(e);
|
|
139
|
+
}
|
|
140
|
+
function a(e, t, r) {
|
|
141
|
+
let i = n.get(e);
|
|
142
|
+
if (!i) return;
|
|
143
143
|
if (!t) {
|
|
144
|
-
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if (!n) {
|
|
148
|
-
r.delete(t), r.size === 0 && this.taskHooks.delete(e);
|
|
144
|
+
n.delete(e);
|
|
149
145
|
return;
|
|
150
146
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
onAny(e) {
|
|
155
|
-
return this.anyHooks.add(e), () => {
|
|
156
|
-
this.offAny(e);
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
off(e, t) {
|
|
160
|
-
if (t) {
|
|
161
|
-
let n = this.eventHooks.get(e);
|
|
162
|
-
if (!n) return;
|
|
163
|
-
n.delete(t), n.size === 0 && this.eventHooks.delete(e);
|
|
164
|
-
} else this.eventHooks.delete(e);
|
|
165
|
-
}
|
|
166
|
-
offAny(e) {
|
|
167
|
-
this.anyHooks.delete(e);
|
|
168
|
-
}
|
|
169
|
-
clear() {
|
|
170
|
-
this.eventHooks.clear(), this.anyHooks.clear(), this.taskHooks.clear();
|
|
171
|
-
}
|
|
172
|
-
hasHooks(e) {
|
|
173
|
-
if (e) {
|
|
174
|
-
let t = this.eventHooks.get(e);
|
|
175
|
-
if (t && t.size > 0 || this.anyHooks.size > 0) return !0;
|
|
176
|
-
for (let t of this.taskHooks.values()) {
|
|
177
|
-
let n = t.get(e);
|
|
178
|
-
if (n && n.size > 0) return !0;
|
|
179
|
-
}
|
|
180
|
-
return !1;
|
|
181
|
-
}
|
|
182
|
-
if (this.anyHooks.size > 0) return !0;
|
|
183
|
-
for (let e of this.eventHooks.values()) if (e.size > 0) return !0;
|
|
184
|
-
for (let e of this.taskHooks.values()) for (let t of e.values()) if (t.size > 0) return !0;
|
|
185
|
-
return !1;
|
|
186
|
-
}
|
|
187
|
-
emit(e) {
|
|
188
|
-
if (e.taskId) {
|
|
189
|
-
this.emitOnTask(e.taskId, e);
|
|
147
|
+
if (!r) {
|
|
148
|
+
i.delete(t), i.size === 0 && n.delete(e);
|
|
190
149
|
return;
|
|
191
150
|
}
|
|
192
|
-
let
|
|
193
|
-
|
|
151
|
+
let a = i.get(t);
|
|
152
|
+
a && (a.delete(r), a.size === 0 && i.delete(t), i.size === 0 && n.delete(e));
|
|
194
153
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
...t,
|
|
198
|
-
taskId: e
|
|
199
|
-
}, r = this.taskHooks.get(e)?.get(n.name), i = this.eventHooks.get(n.name), a = !!(r && r.size > 0), o = !!(i && i.size > 0);
|
|
200
|
-
if (!a && !o && this.anyHooks.size === 0) return;
|
|
201
|
-
let s = l();
|
|
202
|
-
this.dispatchHooks(r, n, s), !s.isPropagationStopped() && (this.dispatchHooks(i, n, s), !s.isPropagationStopped() && this.dispatchHooks(this.anyHooks, n, s));
|
|
154
|
+
function s(e) {
|
|
155
|
+
r.delete(e);
|
|
203
156
|
}
|
|
204
|
-
|
|
157
|
+
function c(e, t, n) {
|
|
205
158
|
if (!(!e || e.size === 0)) for (let r of [...e]) {
|
|
206
159
|
if (n.isImmediatePropagationStopped()) return;
|
|
207
|
-
|
|
160
|
+
l(r, t, n.ctrl);
|
|
208
161
|
}
|
|
209
162
|
}
|
|
210
|
-
|
|
163
|
+
function l(t, n, r) {
|
|
211
164
|
try {
|
|
212
|
-
|
|
213
|
-
} catch (
|
|
214
|
-
|
|
165
|
+
t(n, r);
|
|
166
|
+
} catch (t) {
|
|
167
|
+
e.error(`Hook execution failed for event "${n.name}".`, t);
|
|
215
168
|
}
|
|
216
169
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
170
|
+
function d(e, i) {
|
|
171
|
+
let a = i.taskId === e ? i : {
|
|
172
|
+
...i,
|
|
173
|
+
taskId: e
|
|
174
|
+
}, o = n.get(e)?.get(a.name), s = t.get(a.name), l = !!(o && o.size > 0), d = !!(s && s.size > 0);
|
|
175
|
+
if (!l && !d && r.size === 0) return;
|
|
176
|
+
let f = u();
|
|
177
|
+
c(o, a, f), !f.isPropagationStopped() && (c(s, a, f), !f.isPropagationStopped() && c(r, a, f));
|
|
224
178
|
}
|
|
225
|
-
|
|
179
|
+
return {
|
|
180
|
+
on(e, n) {
|
|
181
|
+
return t.has(e) || t.set(e, /* @__PURE__ */ new Set()), t.get(e)?.add(n), () => {
|
|
182
|
+
i(e, n);
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
onTask(e, t, r) {
|
|
186
|
+
n.has(e) || n.set(e, /* @__PURE__ */ new Map());
|
|
187
|
+
let i = n.get(e);
|
|
188
|
+
return i?.has(t) || i?.set(t, /* @__PURE__ */ new Set()), i?.get(t)?.add(r), () => {
|
|
189
|
+
a(e, t, r);
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
onAny(e) {
|
|
193
|
+
return r.add(e), () => {
|
|
194
|
+
s(e);
|
|
195
|
+
};
|
|
196
|
+
},
|
|
197
|
+
off: i,
|
|
198
|
+
offTask: a,
|
|
199
|
+
offAny: s,
|
|
200
|
+
clear() {
|
|
201
|
+
t.clear(), r.clear(), n.clear();
|
|
202
|
+
},
|
|
203
|
+
hasHooks(e) {
|
|
204
|
+
if (e) {
|
|
205
|
+
let i = t.get(e);
|
|
206
|
+
if (i && i.size > 0 || r.size > 0) return !0;
|
|
207
|
+
for (let t of n.values()) {
|
|
208
|
+
let n = t.get(e);
|
|
209
|
+
if (n && n.size > 0) return !0;
|
|
210
|
+
}
|
|
211
|
+
return !1;
|
|
212
|
+
}
|
|
213
|
+
if (r.size > 0) return !0;
|
|
214
|
+
for (let e of t.values()) if (e.size > 0) return !0;
|
|
215
|
+
for (let e of n.values()) for (let t of e.values()) if (t.size > 0) return !0;
|
|
216
|
+
return !1;
|
|
217
|
+
},
|
|
218
|
+
emit(e) {
|
|
219
|
+
if (e.taskId) {
|
|
220
|
+
d(e.taskId, e);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
let n = u();
|
|
224
|
+
c(t.get(e.name), e, n), !n.isPropagationStopped() && c(r, e, n);
|
|
225
|
+
},
|
|
226
|
+
emitOnTask: d
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region packages/core/src/hooks/types.ts
|
|
231
|
+
var f = /* @__PURE__ */ "register:start.register:success.register:duplicate.register:error.start:requested.start:taskScheduled.start:taskSkipped.artifact:mountStart.artifact:mountSuccess.artifact:mountFail.listener:attached.listener:detached.listener:attachFail.alive:enabled.alive:disabled.alive:observerStarted.alive:observerStopped.task:targetReady.task:statusChange.task:beforeReset.task:afterReset.task:beforeDestroy.task:afterDestroy.signal:watcherReleased.resource:listenerReleased.artifact:unmounted.dom:targetFound.dom:targetTimeout.dom:targetRemoved.dom:targetRestored".split(".");
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region packages/core/src/adapter/Adapter.ts
|
|
234
|
+
function p() {
|
|
235
|
+
let e = [];
|
|
236
|
+
return {
|
|
237
|
+
resolve(t) {
|
|
238
|
+
return e.find((e) => e.matches(t));
|
|
239
|
+
},
|
|
240
|
+
use(t) {
|
|
241
|
+
e.includes(t) || e.push(t);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
226
245
|
//#endregion
|
|
227
246
|
//#region packages/core/src/payload/buildObservePayload.ts
|
|
228
|
-
function
|
|
247
|
+
function m(e, t, n) {
|
|
229
248
|
return n[e](t);
|
|
230
249
|
}
|
|
231
250
|
//#endregion
|
|
232
251
|
//#region packages/core/src/payload/buildResourceObservePayload.ts
|
|
233
|
-
var
|
|
252
|
+
var h = {
|
|
234
253
|
"signal:watcherReleased": (e) => ({
|
|
235
254
|
taskId: e.taskId,
|
|
236
255
|
kind: e.kind,
|
|
@@ -260,12 +279,12 @@ var m = {
|
|
|
260
279
|
}
|
|
261
280
|
})
|
|
262
281
|
};
|
|
263
|
-
function
|
|
264
|
-
return
|
|
282
|
+
function g(e, t) {
|
|
283
|
+
return m(e, t, h);
|
|
265
284
|
}
|
|
266
285
|
//#endregion
|
|
267
286
|
//#region packages/core/src/payload/buildTaskObservePayload.ts
|
|
268
|
-
var
|
|
287
|
+
var _ = {
|
|
269
288
|
"task:statusChange": (e) => ({
|
|
270
289
|
taskId: e.taskId,
|
|
271
290
|
kind: e.kind,
|
|
@@ -299,22 +318,25 @@ var g = {
|
|
|
299
318
|
preStatus: e.preStatus
|
|
300
319
|
})
|
|
301
320
|
};
|
|
302
|
-
function
|
|
303
|
-
return
|
|
321
|
+
function v(e, t) {
|
|
322
|
+
return m(e, t, _);
|
|
304
323
|
}
|
|
305
324
|
//#endregion
|
|
306
325
|
//#region packages/core/src/signal/observeActivitySignal.ts
|
|
307
|
-
function
|
|
326
|
+
function y(e) {
|
|
308
327
|
return typeof e == "object" && !!e;
|
|
309
328
|
}
|
|
310
|
-
function
|
|
311
|
-
return
|
|
329
|
+
function b(e) {
|
|
330
|
+
return y(e) && "get" in e && "subscribe" in e && typeof e.get == "function" && typeof e.subscribe == "function";
|
|
312
331
|
}
|
|
313
|
-
function
|
|
314
|
-
if (
|
|
315
|
-
throw
|
|
332
|
+
function ee(t) {
|
|
333
|
+
if (b(t)) return t;
|
|
334
|
+
throw new i("Invalid activity signal source", [{
|
|
335
|
+
path: "activitySignal",
|
|
336
|
+
message: "must provide get() and subscribe() methods"
|
|
337
|
+
}], e.TASK_SIGNAL_INVALID);
|
|
316
338
|
}
|
|
317
|
-
function
|
|
339
|
+
function x(e) {
|
|
318
340
|
let t = e, n = /* @__PURE__ */ new Set(), r = (e) => {
|
|
319
341
|
if (!Object.is(t, e)) {
|
|
320
342
|
t = e;
|
|
@@ -338,11 +360,11 @@ function b(e) {
|
|
|
338
360
|
}
|
|
339
361
|
};
|
|
340
362
|
}
|
|
341
|
-
function
|
|
342
|
-
let n =
|
|
363
|
+
function S(e, t) {
|
|
364
|
+
let n = ee(e);
|
|
343
365
|
return t(n.get()), n.subscribe(t);
|
|
344
366
|
}
|
|
345
|
-
function
|
|
367
|
+
function C(e) {
|
|
346
368
|
if (typeof e == "function") {
|
|
347
369
|
e();
|
|
348
370
|
return;
|
|
@@ -351,173 +373,189 @@ function S(e) {
|
|
|
351
373
|
}
|
|
352
374
|
//#endregion
|
|
353
375
|
//#region packages/core/src/Task/util.ts
|
|
354
|
-
function C(e) {
|
|
355
|
-
return e.kind === "component";
|
|
356
|
-
}
|
|
357
376
|
function w(e) {
|
|
358
|
-
return
|
|
377
|
+
return e.kind === "component";
|
|
359
378
|
}
|
|
360
379
|
function T(e) {
|
|
380
|
+
return w(e) ? e.injectAt : e.listenAt;
|
|
381
|
+
}
|
|
382
|
+
function E(e) {
|
|
361
383
|
if (!e.withEvent) return;
|
|
362
|
-
let t =
|
|
384
|
+
let t = w(e) ? e.listener : e;
|
|
363
385
|
if (!(!t?.listenAt || !t.event || !t.callback)) return t;
|
|
364
386
|
}
|
|
365
387
|
//#endregion
|
|
366
388
|
//#region packages/core/src/Task/TaskContext.ts
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
injectAt: i,
|
|
407
|
-
status: t,
|
|
408
|
-
preStatus: r
|
|
409
|
-
}));
|
|
410
|
-
}
|
|
411
|
-
destroy(e) {
|
|
412
|
-
let t = this.contextMap.get(e);
|
|
413
|
-
if (!t) {
|
|
414
|
-
this.logger.warn(`Task "${e}" not found, may already be destroyed`);
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
this.setTaskStatus(e, "idle"), this.taskRecords = this.taskRecords.filter((t) => t.taskId !== e), this.taskErrorMessages = this.taskErrorMessages.filter((t) => t.taskId !== e), this.releaseWatcher(e), this.releaseListener(e), C(t) && (this.releaseComponentInstance(e), this.releaseDomElement(e)), this.contextMap.delete(e);
|
|
418
|
-
}
|
|
419
|
-
destroyAll() {
|
|
420
|
-
let e = Array.from(this.contextMap.keys());
|
|
421
|
-
for (let t of e) this.releaseWatcher(t);
|
|
422
|
-
for (let t of e) {
|
|
423
|
-
this.releaseListener(t);
|
|
424
|
-
let e = this.contextMap.get(t);
|
|
425
|
-
e && C(e) && (this.releaseComponentInstance(t), this.releaseDomElement(t));
|
|
426
|
-
}
|
|
427
|
-
this.contextMap.clear(), this.taskRecords = [], this.taskErrorMessages = [], this.logger.info("All tasks destroyed");
|
|
428
|
-
}
|
|
429
|
-
releaseComponentInstance(e) {
|
|
430
|
-
let t = this.contextMap.get(e);
|
|
431
|
-
if (t && C(t) && t.mountHandle && t.appRoot) try {
|
|
432
|
-
t.adapter.unmount({
|
|
433
|
-
host: t.hostElement,
|
|
434
|
-
mountPoint: t.appRoot,
|
|
435
|
-
handle: t.mountHandle,
|
|
436
|
-
taskId: e,
|
|
437
|
-
injectAt: t.injectAt,
|
|
438
|
-
reason: "destroy"
|
|
439
|
-
}), t.mountHandle = void 0, t.instance = void 0, this.emit("artifact:unmounted", h("artifact:unmounted", {
|
|
440
|
-
taskId: e,
|
|
441
|
-
kind: "component",
|
|
442
|
-
injectAt: t.injectAt,
|
|
443
|
-
status: t.taskStatus,
|
|
444
|
-
artifactName: t.artifactName
|
|
389
|
+
function te(e = s, t = new o()) {
|
|
390
|
+
let n = /* @__PURE__ */ new Map();
|
|
391
|
+
function r(e, t) {
|
|
392
|
+
let r = n.get(e);
|
|
393
|
+
if (r) return t ? r.kind === t ? r : void 0 : r;
|
|
394
|
+
}
|
|
395
|
+
let i = {
|
|
396
|
+
taskErrorMessages: [],
|
|
397
|
+
taskRecords: [],
|
|
398
|
+
set(e, t) {
|
|
399
|
+
n.set(e, t);
|
|
400
|
+
},
|
|
401
|
+
get: r,
|
|
402
|
+
has(e) {
|
|
403
|
+
return n.has(e);
|
|
404
|
+
},
|
|
405
|
+
keys() {
|
|
406
|
+
return n.keys();
|
|
407
|
+
},
|
|
408
|
+
getTaskStatus(e) {
|
|
409
|
+
let t = n.get(e);
|
|
410
|
+
return t ? t.taskStatus : void 0;
|
|
411
|
+
},
|
|
412
|
+
setTaskStatus(r, i) {
|
|
413
|
+
let a = n.get(r);
|
|
414
|
+
if (!a) {
|
|
415
|
+
t.warn(`Task "${r}" not found, may already be destroyed`);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (a.taskStatus === i) return;
|
|
419
|
+
let o = a.taskStatus;
|
|
420
|
+
a.taskStatus = i;
|
|
421
|
+
let s = T(a);
|
|
422
|
+
e("task:statusChange", v("task:statusChange", {
|
|
423
|
+
taskId: r,
|
|
424
|
+
kind: a.kind,
|
|
425
|
+
injectAt: s,
|
|
426
|
+
status: i,
|
|
427
|
+
preStatus: o
|
|
445
428
|
}));
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
429
|
+
},
|
|
430
|
+
destroy(e) {
|
|
431
|
+
let r = n.get(e);
|
|
432
|
+
if (!r) {
|
|
433
|
+
t.warn(`Task "${e}" not found, may already be destroyed`);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
i.setTaskStatus(e, "idle"), i.taskRecords = i.taskRecords.filter((t) => t.taskId !== e), i.taskErrorMessages = i.taskErrorMessages.filter((t) => t.taskId !== e), i.releaseWatcher(e), i.releaseListener(e), w(r) && (i.releaseComponentInstance(e), i.releaseDomElement(e)), n.delete(e);
|
|
437
|
+
},
|
|
438
|
+
destroyAll() {
|
|
439
|
+
let e = Array.from(n.keys());
|
|
440
|
+
for (let t of e) i.releaseWatcher(t);
|
|
441
|
+
for (let t of e) {
|
|
442
|
+
i.releaseListener(t);
|
|
443
|
+
let e = n.get(t);
|
|
444
|
+
e && w(e) && (i.releaseComponentInstance(t), i.releaseDomElement(t));
|
|
445
|
+
}
|
|
446
|
+
n.clear(), i.taskRecords = [], i.taskErrorMessages = [], t.info("All tasks destroyed");
|
|
447
|
+
},
|
|
448
|
+
releaseComponentInstance(r) {
|
|
449
|
+
let i = n.get(r);
|
|
450
|
+
if (i && w(i) && i.mountHandle && i.appRoot) try {
|
|
451
|
+
i.adapter.unmount({
|
|
452
|
+
host: i.hostElement,
|
|
453
|
+
mountPoint: i.appRoot,
|
|
454
|
+
handle: i.mountHandle,
|
|
455
|
+
taskId: r,
|
|
456
|
+
injectAt: i.injectAt,
|
|
457
|
+
reason: "destroy"
|
|
458
|
+
}), i.mountHandle = void 0, i.instance = void 0, e("artifact:unmounted", g("artifact:unmounted", {
|
|
459
|
+
taskId: r,
|
|
460
|
+
kind: "component",
|
|
461
|
+
injectAt: i.injectAt,
|
|
462
|
+
status: i.taskStatus,
|
|
463
|
+
artifactName: i.artifactName
|
|
464
|
+
}));
|
|
465
|
+
} catch (e) {
|
|
466
|
+
t.error(`Failed to unmount component for task "${r}":`, e);
|
|
467
|
+
}
|
|
468
|
+
else t.warn(`Component for task "${r}" already unmounted`);
|
|
469
|
+
},
|
|
470
|
+
releaseDomElement(e) {
|
|
471
|
+
let r = n.get(e);
|
|
472
|
+
if (!r || !w(r)) {
|
|
473
|
+
t.warn(`Task "${e}" context not found, unable to remove root element`);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (!r.appRoot) {
|
|
477
|
+
t.warn(`Root element for task "${e}" not found, may already be removed`);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
try {
|
|
481
|
+
r.appRoot.remove(), r.appRoot = void 0, r.hostElement = void 0;
|
|
482
|
+
} catch (n) {
|
|
483
|
+
t.error(`Failed to remove root element for task "${e}":`, n);
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
releaseListener(r) {
|
|
487
|
+
let i = n.get(r);
|
|
488
|
+
if (!i) return;
|
|
489
|
+
let a = E(i), o = a?.event ?? (w(i) ? i.listener?.event : i.event), s = a?.listenAt ?? (w(i) ? i.listener?.listenAt : i.listenAt);
|
|
490
|
+
if (a?.controller) try {
|
|
491
|
+
a.controller.abort();
|
|
492
|
+
} catch (e) {
|
|
493
|
+
t.error(`Failed to abort listener for task "${r}":`, e);
|
|
494
|
+
}
|
|
495
|
+
a && (a.controller = void 0), w(i) && (i.listener = void 0), i.withEvent = !1, e("resource:listenerReleased", g("resource:listenerReleased", {
|
|
496
|
+
taskId: r,
|
|
497
|
+
kind: i.kind,
|
|
498
|
+
injectAt: T(i),
|
|
499
|
+
status: i.taskStatus,
|
|
500
|
+
listenerEvent: o,
|
|
501
|
+
listenAt: s
|
|
493
502
|
}));
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
503
|
+
},
|
|
504
|
+
releaseWatcher(r) {
|
|
505
|
+
let i = n.get(r);
|
|
506
|
+
if (i?.watcher) try {
|
|
507
|
+
C(i.watcher.watcher), i.watcher = void 0, e("signal:watcherReleased", g("signal:watcherReleased", {
|
|
508
|
+
taskId: r,
|
|
509
|
+
kind: i.kind,
|
|
510
|
+
injectAt: T(i),
|
|
511
|
+
status: i.taskStatus
|
|
512
|
+
}));
|
|
513
|
+
} catch (e) {
|
|
514
|
+
t.error(`Failed to stop watcher for task "${r}":`, e);
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
reset(r) {
|
|
518
|
+
let a = n.get(r);
|
|
519
|
+
if (!a) return;
|
|
520
|
+
let o = !1;
|
|
521
|
+
if (w(a) && a.mountHandle && a.appRoot) try {
|
|
522
|
+
a.adapter.unmount({
|
|
523
|
+
host: a.hostElement,
|
|
524
|
+
mountPoint: a.appRoot,
|
|
525
|
+
handle: a.mountHandle,
|
|
526
|
+
taskId: r,
|
|
527
|
+
injectAt: a.injectAt,
|
|
528
|
+
reason: "reset"
|
|
529
|
+
}), o = !0;
|
|
530
|
+
} catch (e) {
|
|
531
|
+
t.warn(`Failed to unmount component for task "${r}" during reset:`, e);
|
|
532
|
+
}
|
|
533
|
+
i.setTaskStatus(r, "idle"), o && w(a) && e("artifact:unmounted", g("artifact:unmounted", {
|
|
534
|
+
taskId: r,
|
|
535
|
+
kind: "component",
|
|
536
|
+
injectAt: a.injectAt,
|
|
537
|
+
status: a.taskStatus,
|
|
538
|
+
artifactName: a.artifactName
|
|
539
|
+
})), w(a) && (a.mountHandle = void 0, a.instance = void 0, a.hostElement = void 0, a.appRoot?.remove(), a.appRoot = void 0, a.isObserver = !1), a.watcher && i.releaseWatcher(r);
|
|
540
|
+
let s = E(a), c = s?.event, l = s?.listenAt;
|
|
541
|
+
s?.controller && (s.controller.abort(), s.controller = void 0), s && e("resource:listenerReleased", g("resource:listenerReleased", {
|
|
542
|
+
taskId: r,
|
|
543
|
+
kind: a.kind,
|
|
544
|
+
injectAt: T(a),
|
|
545
|
+
status: a.taskStatus,
|
|
546
|
+
listenerEvent: c,
|
|
547
|
+
listenAt: l
|
|
548
|
+
}));
|
|
549
|
+
},
|
|
550
|
+
resetAll() {
|
|
551
|
+
for (let e of n.keys()) i.reset(e);
|
|
512
552
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
}, D = {
|
|
553
|
+
};
|
|
554
|
+
return i;
|
|
555
|
+
}
|
|
556
|
+
//#endregion
|
|
557
|
+
//#region packages/core/src/payload/buildAliveObservePayload.ts
|
|
558
|
+
var ne = {
|
|
521
559
|
"alive:enabled": (e) => ({
|
|
522
560
|
taskId: e.taskId,
|
|
523
561
|
kind: e.kind,
|
|
@@ -553,12 +591,12 @@ var E = class {
|
|
|
553
591
|
}
|
|
554
592
|
})
|
|
555
593
|
};
|
|
556
|
-
function
|
|
557
|
-
return
|
|
594
|
+
function D(e, t) {
|
|
595
|
+
return m(e, t, ne);
|
|
558
596
|
}
|
|
559
597
|
//#endregion
|
|
560
598
|
//#region packages/core/src/payload/buildDomObservePayload.ts
|
|
561
|
-
var
|
|
599
|
+
var O = {
|
|
562
600
|
"dom:targetFound": (e) => ({
|
|
563
601
|
injectAt: e.injectAt,
|
|
564
602
|
taskId: e.taskId,
|
|
@@ -586,16 +624,16 @@ var k = {
|
|
|
586
624
|
durationMs: e.durationMs
|
|
587
625
|
})
|
|
588
626
|
};
|
|
589
|
-
function
|
|
590
|
-
return
|
|
627
|
+
function k(e, t) {
|
|
628
|
+
return m(e, t, O);
|
|
591
629
|
}
|
|
592
630
|
//#endregion
|
|
593
631
|
//#region packages/core/src/payload/createDomObserveEmitFactory.ts
|
|
594
|
-
function
|
|
632
|
+
function A(e) {
|
|
595
633
|
let t = Date.now(), n, r = e.root instanceof Document ? "document" : "element";
|
|
596
634
|
return (i) => {
|
|
597
635
|
if (i === "dom:targetFound") {
|
|
598
|
-
e.emit("dom:targetFound",
|
|
636
|
+
e.emit("dom:targetFound", k("dom:targetFound", {
|
|
599
637
|
injectAt: e.injectAt,
|
|
600
638
|
taskId: e.taskId,
|
|
601
639
|
kind: e.kind,
|
|
@@ -605,7 +643,7 @@ function j(e) {
|
|
|
605
643
|
return;
|
|
606
644
|
}
|
|
607
645
|
if (i === "dom:targetTimeout") {
|
|
608
|
-
e.emit("dom:targetTimeout",
|
|
646
|
+
e.emit("dom:targetTimeout", k("dom:targetTimeout", {
|
|
609
647
|
injectAt: e.injectAt,
|
|
610
648
|
taskId: e.taskId,
|
|
611
649
|
kind: e.kind,
|
|
@@ -615,14 +653,14 @@ function j(e) {
|
|
|
615
653
|
return;
|
|
616
654
|
}
|
|
617
655
|
if (i === "dom:targetRemoved") {
|
|
618
|
-
n = Date.now(), e.emit("dom:targetRemoved",
|
|
656
|
+
n = Date.now(), e.emit("dom:targetRemoved", k("dom:targetRemoved", {
|
|
619
657
|
injectAt: e.injectAt,
|
|
620
658
|
taskId: e.taskId,
|
|
621
659
|
kind: e.kind
|
|
622
660
|
}));
|
|
623
661
|
return;
|
|
624
662
|
}
|
|
625
|
-
e.emit("dom:targetRestored",
|
|
663
|
+
e.emit("dom:targetRestored", k("dom:targetRestored", {
|
|
626
664
|
injectAt: e.injectAt,
|
|
627
665
|
taskId: e.taskId,
|
|
628
666
|
kind: e.kind,
|
|
@@ -632,59 +670,59 @@ function j(e) {
|
|
|
632
670
|
}
|
|
633
671
|
//#endregion
|
|
634
672
|
//#region packages/core/src/watcher/DomWatcher.ts
|
|
635
|
-
function
|
|
636
|
-
logger: new
|
|
637
|
-
emit:
|
|
673
|
+
function j(e, t, n = document, r, i = {
|
|
674
|
+
logger: new o(),
|
|
675
|
+
emit: s
|
|
638
676
|
}) {
|
|
639
|
-
let
|
|
677
|
+
let a = [], c = !1, l = () => {
|
|
640
678
|
if (!c) {
|
|
641
679
|
c = !0;
|
|
642
|
-
for (let e of
|
|
643
|
-
|
|
680
|
+
for (let e of a) e.disconnect();
|
|
681
|
+
a.length = 0;
|
|
644
682
|
}
|
|
645
683
|
}, u = (n, a) => {
|
|
646
684
|
i.emit("dom:targetFound"), t(n, a), r?.once && (l(), i.logger.info(`Element "${e}" found, observer disconnected`));
|
|
647
685
|
};
|
|
648
686
|
return ((t) => {
|
|
649
|
-
c || (
|
|
687
|
+
c || (re(t, e, u), !c && ie(t, e, a, u));
|
|
650
688
|
})(n), r?.timeout && setTimeout(() => {
|
|
651
689
|
c || (l(), i.emit("dom:targetTimeout"), i.logger.warn(`Element "${e}" not found within ${r.timeout}ms, observer disconnected`));
|
|
652
690
|
}, r.timeout), l;
|
|
653
691
|
}
|
|
654
|
-
function
|
|
655
|
-
logger: new
|
|
656
|
-
emit:
|
|
692
|
+
function M(e, t, n, r, i = document, a, c = {
|
|
693
|
+
logger: new o(),
|
|
694
|
+
emit: s
|
|
657
695
|
}) {
|
|
658
|
-
let l = !0, u, d =
|
|
659
|
-
c.emit("dom:targetRemoved"), n(), l && (u =
|
|
696
|
+
let l = !0, u, d = ae(e, () => {
|
|
697
|
+
c.emit("dom:targetRemoved"), n(), l && (u = j(t, (e) => {
|
|
660
698
|
l && (c.emit("dom:targetRestored"), r(e));
|
|
661
|
-
}, document,
|
|
699
|
+
}, document, a, c));
|
|
662
700
|
}, i, c.logger);
|
|
663
701
|
return () => {
|
|
664
702
|
l && (l = !1, d?.disconnect(), u?.(), c.logger.info(`Alive observer for "${t}" stopped`));
|
|
665
703
|
};
|
|
666
704
|
}
|
|
667
705
|
var N = {
|
|
668
|
-
onDomReady:
|
|
669
|
-
onDomAlive:
|
|
706
|
+
onDomReady: j,
|
|
707
|
+
onDomAlive: M
|
|
670
708
|
};
|
|
671
|
-
function
|
|
709
|
+
function re(e, t, n) {
|
|
672
710
|
let r = (e instanceof Document ? e : e.ownerDocument).querySelector(t);
|
|
673
711
|
r && n(r, void 0);
|
|
674
712
|
}
|
|
675
|
-
function
|
|
713
|
+
function ie(e, t, n, r) {
|
|
676
714
|
let i = new MutationObserver((e, n) => {
|
|
677
715
|
for (let i of e) i.addedNodes.forEach((e) => {
|
|
678
|
-
e.nodeType === 1 &&
|
|
716
|
+
e.nodeType === 1 && oe(e, t, n, r);
|
|
679
717
|
});
|
|
680
|
-
}), a =
|
|
718
|
+
}), a = P(e);
|
|
681
719
|
a && (i.observe(a, {
|
|
682
720
|
childList: !0,
|
|
683
721
|
subtree: !0
|
|
684
722
|
}), n.push(i));
|
|
685
723
|
}
|
|
686
|
-
function
|
|
687
|
-
let i =
|
|
724
|
+
function ae(e, t, n, r) {
|
|
725
|
+
let i = P(n), a = i instanceof HTMLBodyElement;
|
|
688
726
|
if (i === null) return r.error("Failed to set up removal observer: no valid observation target found"), null;
|
|
689
727
|
if (!a && !i.isConnected) return r.error("Failed to set up removal observer: observation target is detached from DOM"), null;
|
|
690
728
|
let o = a ? i : i.parentElement || i;
|
|
@@ -699,527 +737,101 @@ function I(e, t, n, r) {
|
|
|
699
737
|
subtree: !!a
|
|
700
738
|
}), r.info("Removal observer started", o), s;
|
|
701
739
|
}
|
|
702
|
-
function
|
|
740
|
+
function oe(e, t, n, r) {
|
|
703
741
|
let i = e.matches(t) ? e : e.querySelector(t);
|
|
704
742
|
i && r(i, n);
|
|
705
743
|
}
|
|
706
|
-
function
|
|
744
|
+
function P(e) {
|
|
707
745
|
return (e instanceof Document ? e.body : e) || document.body;
|
|
708
746
|
}
|
|
709
747
|
//#endregion
|
|
710
|
-
//#region packages/core/src/
|
|
711
|
-
var
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
logger;
|
|
716
|
-
emit;
|
|
717
|
-
constructor(e, t, n, r, i) {
|
|
718
|
-
this.taskContext = e, this.onTargetReady = t, this.injectConfig = n, this.emit = r, this.logger = i ?? n.logger ?? new a();
|
|
719
|
-
}
|
|
720
|
-
enableAlive(e) {
|
|
721
|
-
let t = this.taskContext.get(e);
|
|
722
|
-
if (!t) {
|
|
723
|
-
this.logger.error(`Task "${e}" not found`);
|
|
724
|
-
return;
|
|
725
|
-
}
|
|
726
|
-
if (!C(t)) {
|
|
727
|
-
this.logger.warn(`enableAlive is not applicable to non-component task "${e}"`);
|
|
728
|
-
return;
|
|
729
|
-
}
|
|
730
|
-
if (t.alive && t.isObserver) {
|
|
731
|
-
this.logger.warn(`Task "${e}" already has an active alive observer`);
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
if (t.alive = !0, t.isObserver = !1, this.emit("alive:enabled", O("alive:enabled", {
|
|
735
|
-
taskId: e,
|
|
736
|
-
kind: "component",
|
|
737
|
-
injectAt: t.injectAt,
|
|
738
|
-
status: t.taskStatus,
|
|
739
|
-
scope: t.scope
|
|
740
|
-
})), t.disableAlive = () => {}, t.mountHandle && t.appRoot?.isConnected) {
|
|
741
|
-
let n = t.hostElement ?? t.appRoot.parentElement;
|
|
742
|
-
if (!n) {
|
|
743
|
-
this.logger.warn(`Task "${e}": host element not found, unable to activate alive observer`);
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
let r = n.ownerDocument || document, i = t.injectAt, a = N.onDomAlive(n, i, () => {
|
|
747
|
-
this.taskContext.reset(e);
|
|
748
|
-
}, (t) => this.onTargetReady(t, e), t.scope === "global" ? r : n, {
|
|
749
|
-
once: !0,
|
|
750
|
-
timeout: this.injectConfig.timeout
|
|
751
|
-
}, {
|
|
752
|
-
logger: this.logger,
|
|
753
|
-
emit: j({
|
|
754
|
-
emit: this.emit,
|
|
755
|
-
taskId: e,
|
|
756
|
-
kind: "component",
|
|
757
|
-
injectAt: i,
|
|
758
|
-
root: t.scope === "global" ? r : n
|
|
759
|
-
})
|
|
760
|
-
});
|
|
761
|
-
if (!t.alive) {
|
|
762
|
-
a();
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
t.disableAlive = a, t.isObserver = !0, this.emit("alive:observerStarted", O("alive:observerStarted", {
|
|
766
|
-
taskId: e,
|
|
767
|
-
kind: "component",
|
|
768
|
-
injectAt: i,
|
|
769
|
-
status: t.taskStatus,
|
|
770
|
-
scope: t.scope,
|
|
771
|
-
observerMode: "mounted"
|
|
772
|
-
})), this.logger.info(`Task "${e}" alive observer activated`);
|
|
773
|
-
return;
|
|
774
|
-
}
|
|
775
|
-
if (t.mountHandle && !t.appRoot?.isConnected && this.taskContext.reset(e), !t.mountHandle) {
|
|
776
|
-
let n = !1, r = N.onDomReady(t.injectAt, (r) => {
|
|
777
|
-
if (n || !t.alive) {
|
|
778
|
-
this.logger.warn(`Task "${e}" alive state changed before element appears`);
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
|
-
this.onTargetReady(r, e);
|
|
782
|
-
}, document, {
|
|
783
|
-
once: !0,
|
|
784
|
-
timeout: this.injectConfig.timeout
|
|
785
|
-
}, {
|
|
786
|
-
logger: this.logger,
|
|
787
|
-
emit: j({
|
|
788
|
-
emit: this.emit,
|
|
789
|
-
taskId: e,
|
|
790
|
-
kind: "component",
|
|
791
|
-
injectAt: t.injectAt,
|
|
792
|
-
root: document
|
|
793
|
-
})
|
|
794
|
-
});
|
|
795
|
-
t.disableAlive = () => {
|
|
796
|
-
n || (n = !0, this.emit("alive:observerStopped", O("alive:observerStopped", {
|
|
797
|
-
taskId: e,
|
|
798
|
-
kind: "component",
|
|
799
|
-
injectAt: t.injectAt,
|
|
800
|
-
status: t.taskStatus,
|
|
801
|
-
scope: t.scope,
|
|
802
|
-
observerMode: "await-target"
|
|
803
|
-
})), r());
|
|
804
|
-
}, t.isObserver = !0, this.emit("alive:observerStarted", O("alive:observerStarted", {
|
|
805
|
-
taskId: e,
|
|
806
|
-
kind: "component",
|
|
807
|
-
injectAt: t.injectAt,
|
|
808
|
-
status: t.taskStatus,
|
|
809
|
-
scope: t.scope,
|
|
810
|
-
observerMode: "await-target"
|
|
811
|
-
})), this.logger.info(`Task "${e}" awaiting target element for re-injection`);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
disableAlive(e) {
|
|
815
|
-
let t = this.taskContext.get(e);
|
|
816
|
-
if (!t) {
|
|
817
|
-
this.logger.error(`Task "${e}" not found`);
|
|
818
|
-
return;
|
|
819
|
-
}
|
|
820
|
-
if (!C(t)) {
|
|
821
|
-
this.logger.warn(`disableAlive is not applicable to non-component task "${e}"`);
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
if (!t.alive) {
|
|
825
|
-
this.logger.warn(`Task "${e}" has no active alive observer to stop`);
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
let n = t.disableAlive;
|
|
829
|
-
t.alive = !1, t.isObserver = !1, t.disableAlive = void 0, n?.(), this.emit("alive:disabled", O("alive:disabled", {
|
|
830
|
-
taskId: e,
|
|
831
|
-
kind: "component",
|
|
832
|
-
injectAt: t.injectAt,
|
|
833
|
-
status: t.taskStatus,
|
|
834
|
-
scope: t.scope
|
|
835
|
-
})), this.emit("alive:observerStopped", O("alive:observerStopped", {
|
|
836
|
-
taskId: e,
|
|
837
|
-
kind: "component",
|
|
838
|
-
injectAt: t.injectAt,
|
|
839
|
-
status: t.taskStatus,
|
|
840
|
-
scope: t.scope,
|
|
841
|
-
observerMode: t.mountHandle ? "mounted" : "await-target"
|
|
842
|
-
}));
|
|
843
|
-
}
|
|
844
|
-
destroy(e) {
|
|
845
|
-
let t = this.taskContext.get(e);
|
|
846
|
-
if (!t) {
|
|
847
|
-
this.logger.error(`Task ${e} not found`);
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
let n = t.taskStatus, r = w(t);
|
|
851
|
-
this.emit("task:beforeDestroy", _("task:beforeDestroy", {
|
|
852
|
-
taskId: e,
|
|
853
|
-
kind: t.kind,
|
|
854
|
-
injectAt: r,
|
|
855
|
-
status: n
|
|
856
|
-
})), C(t) && t.alive && this.disableAlive(e), this.taskContext.destroy(e), this.emit("task:afterDestroy", _("task:afterDestroy", {
|
|
857
|
-
taskId: e,
|
|
858
|
-
kind: t.kind,
|
|
859
|
-
injectAt: r,
|
|
860
|
-
preStatus: n
|
|
861
|
-
}));
|
|
862
|
-
}
|
|
863
|
-
destroyAll() {
|
|
864
|
-
for (let e of this.taskContext.keys()) {
|
|
865
|
-
let t = this.taskContext.get(e);
|
|
866
|
-
t && C(t) && t.alive && this.disableAlive(e);
|
|
867
|
-
}
|
|
868
|
-
this.taskContext.destroyAll();
|
|
869
|
-
}
|
|
870
|
-
reset(e) {
|
|
871
|
-
let t = this.taskContext.get(e);
|
|
872
|
-
if (!t) {
|
|
873
|
-
this.logger.error(`Task ${e} not found`);
|
|
874
|
-
return;
|
|
875
|
-
}
|
|
876
|
-
let n = t.taskStatus, r = w(t);
|
|
877
|
-
this.emit("task:beforeReset", _("task:beforeReset", {
|
|
878
|
-
taskId: e,
|
|
879
|
-
kind: t.kind,
|
|
880
|
-
injectAt: r,
|
|
881
|
-
status: n
|
|
882
|
-
})), C(t) && t.alive && this.disableAlive(e), this.taskContext.reset(e), this.emit("task:afterReset", _("task:afterReset", {
|
|
883
|
-
taskId: e,
|
|
884
|
-
kind: t.kind,
|
|
885
|
-
injectAt: r,
|
|
886
|
-
status: t.taskStatus,
|
|
887
|
-
preStatus: n
|
|
888
|
-
}));
|
|
889
|
-
}
|
|
890
|
-
resetAll() {
|
|
891
|
-
for (let e of this.taskContext.keys()) {
|
|
892
|
-
let t = this.taskContext.get(e);
|
|
893
|
-
t && C(t) && t.alive && this.disableAlive(e);
|
|
894
|
-
}
|
|
895
|
-
this.taskContext.resetAll();
|
|
896
|
-
}
|
|
897
|
-
}, B = {
|
|
898
|
-
"register:start": (e) => ({
|
|
748
|
+
//#region packages/core/src/Makoo/types.ts
|
|
749
|
+
var F = /* @__PURE__ */ function(e) {
|
|
750
|
+
return e.OPEN = "OPEN", e.CLOSE = "CLOSE", e;
|
|
751
|
+
}({}), se = {
|
|
752
|
+
"artifact:mountStart": (e) => ({
|
|
899
753
|
taskId: e.taskId,
|
|
900
754
|
kind: e.kind,
|
|
901
755
|
injectAt: e.injectAt,
|
|
902
756
|
status: e.status,
|
|
903
757
|
meta: {
|
|
904
758
|
artifactName: e.artifactName,
|
|
905
|
-
listenerEvent: e.listenerEvent,
|
|
906
|
-
listenAt: e.listenAt,
|
|
907
759
|
alive: e.alive,
|
|
908
760
|
scope: e.scope,
|
|
909
|
-
timeout: e.timeout,
|
|
910
761
|
withEvent: e.withEvent
|
|
911
762
|
}
|
|
912
763
|
}),
|
|
913
|
-
"
|
|
764
|
+
"artifact:mountSuccess": (e) => ({
|
|
914
765
|
taskId: e.taskId,
|
|
915
766
|
kind: e.kind,
|
|
916
767
|
injectAt: e.injectAt,
|
|
917
768
|
status: e.status,
|
|
918
769
|
meta: {
|
|
919
770
|
artifactName: e.artifactName,
|
|
920
|
-
listenerEvent: e.listenerEvent,
|
|
921
|
-
listenAt: e.listenAt,
|
|
922
771
|
alive: e.alive,
|
|
923
|
-
scope: e.scope
|
|
924
|
-
timeout: e.timeout,
|
|
925
|
-
withEvent: e.withEvent
|
|
772
|
+
scope: e.scope
|
|
926
773
|
}
|
|
927
774
|
}),
|
|
928
|
-
"
|
|
775
|
+
"artifact:mountFail": (e) => ({
|
|
776
|
+
taskId: e.taskId,
|
|
777
|
+
kind: e.kind,
|
|
778
|
+
injectAt: e.injectAt,
|
|
779
|
+
status: "idle",
|
|
780
|
+
error: e.error,
|
|
781
|
+
meta: { artifactName: e.artifactName }
|
|
782
|
+
})
|
|
783
|
+
};
|
|
784
|
+
function I(e, t) {
|
|
785
|
+
return m(e, t, se);
|
|
786
|
+
}
|
|
787
|
+
//#endregion
|
|
788
|
+
//#region packages/core/src/payload/buildListenerObservePayload.ts
|
|
789
|
+
var L = {
|
|
790
|
+
"listener:attached": (e) => ({
|
|
929
791
|
taskId: e.taskId,
|
|
930
792
|
kind: e.kind,
|
|
931
793
|
injectAt: e.injectAt,
|
|
932
794
|
status: e.status,
|
|
933
|
-
meta:
|
|
795
|
+
meta: {
|
|
796
|
+
listenerEvent: e.listenerEvent,
|
|
797
|
+
listenAt: e.listenAt
|
|
798
|
+
}
|
|
934
799
|
}),
|
|
935
|
-
"
|
|
800
|
+
"listener:detached": (e) => ({
|
|
801
|
+
taskId: e.taskId,
|
|
802
|
+
kind: e.kind,
|
|
803
|
+
injectAt: e.injectAt,
|
|
804
|
+
status: e.status,
|
|
805
|
+
meta: {
|
|
806
|
+
listenerEvent: e.listenerEvent,
|
|
807
|
+
listenAt: e.listenAt
|
|
808
|
+
}
|
|
809
|
+
}),
|
|
810
|
+
"listener:attachFail": (e) => ({
|
|
936
811
|
taskId: e.taskId,
|
|
937
812
|
kind: e.kind,
|
|
938
813
|
injectAt: e.injectAt,
|
|
939
814
|
status: e.status,
|
|
940
815
|
error: e.error,
|
|
941
|
-
meta:
|
|
816
|
+
meta: {
|
|
817
|
+
listenerEvent: e.listenerEvent,
|
|
818
|
+
listenAt: e.listenAt
|
|
819
|
+
}
|
|
942
820
|
})
|
|
943
821
|
};
|
|
944
|
-
function
|
|
945
|
-
return e
|
|
946
|
-
}
|
|
947
|
-
function H(e, t) {
|
|
948
|
-
return p(e, t, B);
|
|
949
|
-
}
|
|
950
|
-
//#endregion
|
|
951
|
-
//#region packages/core/src/util/uuid.ts
|
|
952
|
-
function U() {
|
|
953
|
-
return "xxxxxxxx".replace(/[xy]/g, (e) => {
|
|
954
|
-
let t = Math.random() * 16 | 0;
|
|
955
|
-
return (e === "x" ? t : t & 3 | 8).toString(16);
|
|
956
|
-
});
|
|
957
|
-
}
|
|
958
|
-
//#endregion
|
|
959
|
-
//#region packages/core/src/util/getArtifactName.ts
|
|
960
|
-
var W = /* @__PURE__ */ new WeakMap();
|
|
961
|
-
function G(e, t, n, r) {
|
|
962
|
-
let i = e?.name || e?.__name;
|
|
963
|
-
if (i) return i;
|
|
964
|
-
if (typeof e == "string") return e;
|
|
965
|
-
if (typeof e == "object" || typeof e == "function") {
|
|
966
|
-
let r = e, i = t.get(r);
|
|
967
|
-
if (i) return i;
|
|
968
|
-
let a = `${n}-${U()}`;
|
|
969
|
-
return t.set(r, a), a;
|
|
970
|
-
}
|
|
971
|
-
return r;
|
|
972
|
-
}
|
|
973
|
-
function K(e) {
|
|
974
|
-
return G(e, W, "artifact", "artifact-anonymous");
|
|
975
|
-
}
|
|
976
|
-
//#endregion
|
|
977
|
-
//#region packages/core/src/Task/TaskRegister.ts
|
|
978
|
-
var q = class {
|
|
979
|
-
taskContext;
|
|
980
|
-
injectConfig;
|
|
981
|
-
logger;
|
|
982
|
-
emit;
|
|
983
|
-
resolveMountAdapter;
|
|
984
|
-
constructor(e, t, n, r, i) {
|
|
985
|
-
this.taskContext = e, this.injectConfig = t, this.emit = n, this.logger = i ?? t.logger ?? new a(), this.resolveMountAdapter = r;
|
|
986
|
-
}
|
|
987
|
-
getTaskId(e, t) {
|
|
988
|
-
return e ? `${e}@${t}` : `artifact-${t}`;
|
|
989
|
-
}
|
|
990
|
-
registerListener(e, t, n, r) {
|
|
991
|
-
let i = `listener-${e}-${t}`;
|
|
992
|
-
this.emit("register:start", H("register:start", {
|
|
993
|
-
taskId: i,
|
|
994
|
-
kind: "listener",
|
|
995
|
-
injectAt: e,
|
|
996
|
-
status: "idle",
|
|
997
|
-
listenerEvent: t,
|
|
998
|
-
listenAt: e,
|
|
999
|
-
withEvent: !0
|
|
1000
|
-
}));
|
|
1001
|
-
try {
|
|
1002
|
-
if (this.taskContext.has(i)) return this.logger.warn(`Listener "${i}" is already registered, skipping`), this.emit("register:duplicate", H("register:duplicate", {
|
|
1003
|
-
taskId: i,
|
|
1004
|
-
kind: "listener",
|
|
1005
|
-
injectAt: e,
|
|
1006
|
-
status: this.taskContext.getTaskStatus(i) ?? "idle",
|
|
1007
|
-
listenerEvent: t
|
|
1008
|
-
})), {
|
|
1009
|
-
taskId: i,
|
|
1010
|
-
isSuccess: !0
|
|
1011
|
-
};
|
|
1012
|
-
let a = {
|
|
1013
|
-
taskId: i,
|
|
1014
|
-
kind: "listener",
|
|
1015
|
-
taskStatus: "idle",
|
|
1016
|
-
timeout: this.injectConfig.timeout,
|
|
1017
|
-
withEvent: !0,
|
|
1018
|
-
listenAt: e,
|
|
1019
|
-
event: t,
|
|
1020
|
-
callback: n
|
|
1021
|
-
};
|
|
1022
|
-
return r && (a.activitySignal = r), this.taskContext.set(i, a), this.taskContext.taskRecords.push({
|
|
1023
|
-
taskId: i,
|
|
1024
|
-
injectAt: e
|
|
1025
|
-
}), this.logger.info(`Listener "${i}" registered`), this.emit("register:success", H("register:success", {
|
|
1026
|
-
taskId: i,
|
|
1027
|
-
kind: "listener",
|
|
1028
|
-
injectAt: e,
|
|
1029
|
-
status: "idle",
|
|
1030
|
-
listenerEvent: t,
|
|
1031
|
-
listenAt: e,
|
|
1032
|
-
withEvent: !0
|
|
1033
|
-
})), {
|
|
1034
|
-
taskId: i,
|
|
1035
|
-
isSuccess: !0
|
|
1036
|
-
};
|
|
1037
|
-
} catch (n) {
|
|
1038
|
-
return this.emit("register:error", H("register:error", {
|
|
1039
|
-
taskId: i,
|
|
1040
|
-
kind: "listener",
|
|
1041
|
-
injectAt: e,
|
|
1042
|
-
status: this.taskContext.getTaskStatus(i) ?? "idle",
|
|
1043
|
-
error: n,
|
|
1044
|
-
listenerEvent: t
|
|
1045
|
-
})), {
|
|
1046
|
-
taskId: i,
|
|
1047
|
-
isSuccess: !1
|
|
1048
|
-
};
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
register(t, n, i) {
|
|
1052
|
-
let a = K(n), o = this.getTaskId(a, t), s = !!i?.on, l = i?.on?.type, u = i?.on?.listenAt, d = i?.alive ?? this.injectConfig.alive, f = i?.scope ?? this.injectConfig.scope, p = i?.timeout ?? this.injectConfig.timeout, m = this.resolveMountAdapter(n);
|
|
1053
|
-
if (!m) throw new r(`No adapter found for artifact: ${a}`, [{
|
|
1054
|
-
path: "artifact",
|
|
1055
|
-
message: a
|
|
1056
|
-
}], e.ADAPTER_NOT_FOUND);
|
|
1057
|
-
this.emit("register:start", H("register:start", {
|
|
1058
|
-
taskId: o,
|
|
1059
|
-
kind: "component",
|
|
1060
|
-
injectAt: t,
|
|
1061
|
-
status: "idle",
|
|
1062
|
-
artifactName: a,
|
|
1063
|
-
listenerEvent: l,
|
|
1064
|
-
listenAt: u,
|
|
1065
|
-
alive: d,
|
|
1066
|
-
scope: f,
|
|
1067
|
-
timeout: p,
|
|
1068
|
-
withEvent: s
|
|
1069
|
-
}));
|
|
1070
|
-
try {
|
|
1071
|
-
if (this.taskContext.has(o)) return this.logger.warn(`Task "${o}" is already registered, skipping`), this.emit("register:duplicate", H("register:duplicate", {
|
|
1072
|
-
taskId: o,
|
|
1073
|
-
kind: "component",
|
|
1074
|
-
injectAt: t,
|
|
1075
|
-
status: this.taskContext.getTaskStatus(o) ?? "idle",
|
|
1076
|
-
artifactName: a
|
|
1077
|
-
})), {
|
|
1078
|
-
taskId: o,
|
|
1079
|
-
isSuccess: !0
|
|
1080
|
-
};
|
|
1081
|
-
let e = {
|
|
1082
|
-
taskId: o,
|
|
1083
|
-
taskStatus: "idle",
|
|
1084
|
-
kind: "component",
|
|
1085
|
-
artifactName: a,
|
|
1086
|
-
injectAt: t,
|
|
1087
|
-
artifact: n,
|
|
1088
|
-
adapter: m,
|
|
1089
|
-
withEvent: !1,
|
|
1090
|
-
alive: d,
|
|
1091
|
-
scope: f,
|
|
1092
|
-
timeout: p,
|
|
1093
|
-
isObserver: !1,
|
|
1094
|
-
hooks: i?.hooks
|
|
1095
|
-
};
|
|
1096
|
-
if (i?.on) {
|
|
1097
|
-
let t = {
|
|
1098
|
-
listenAt: i.on.listenAt,
|
|
1099
|
-
event: i.on.type,
|
|
1100
|
-
callback: i.on.callback
|
|
1101
|
-
};
|
|
1102
|
-
e.withEvent = !0, i.on.activitySignal && (t.activitySignal = i.on.activitySignal), e.listener = t;
|
|
1103
|
-
}
|
|
1104
|
-
return this.injectConfig.observer && i?.hooks && c(this.injectConfig.observer, i.hooks, o), this.taskContext.set(o, e), this.taskContext.taskRecords.push({
|
|
1105
|
-
taskId: o,
|
|
1106
|
-
injectAt: t
|
|
1107
|
-
}), this.logger.info(`Task "${o}" registered`), this.emit("register:success", H("register:success", {
|
|
1108
|
-
taskId: o,
|
|
1109
|
-
kind: "component",
|
|
1110
|
-
injectAt: t,
|
|
1111
|
-
status: "idle",
|
|
1112
|
-
artifactName: a,
|
|
1113
|
-
listenerEvent: l,
|
|
1114
|
-
listenAt: u,
|
|
1115
|
-
alive: d,
|
|
1116
|
-
scope: f,
|
|
1117
|
-
timeout: p,
|
|
1118
|
-
withEvent: s
|
|
1119
|
-
})), {
|
|
1120
|
-
taskId: o,
|
|
1121
|
-
isSuccess: !0
|
|
1122
|
-
};
|
|
1123
|
-
} catch (e) {
|
|
1124
|
-
return this.emit("register:error", H("register:error", {
|
|
1125
|
-
taskId: o,
|
|
1126
|
-
kind: "component",
|
|
1127
|
-
injectAt: t,
|
|
1128
|
-
status: this.taskContext.getTaskStatus(o) ?? "idle",
|
|
1129
|
-
error: e,
|
|
1130
|
-
artifactName: a
|
|
1131
|
-
})), {
|
|
1132
|
-
taskId: o,
|
|
1133
|
-
isSuccess: !1
|
|
1134
|
-
};
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
}, J = /* @__PURE__ */ function(e) {
|
|
1138
|
-
return e.OPEN = "OPEN", e.CLOSE = "CLOSE", e;
|
|
1139
|
-
}({}), Y = {
|
|
1140
|
-
"artifact:mountStart": (e) => ({
|
|
1141
|
-
taskId: e.taskId,
|
|
1142
|
-
kind: e.kind,
|
|
1143
|
-
injectAt: e.injectAt,
|
|
1144
|
-
status: e.status,
|
|
1145
|
-
meta: {
|
|
1146
|
-
artifactName: e.artifactName,
|
|
1147
|
-
alive: e.alive,
|
|
1148
|
-
scope: e.scope,
|
|
1149
|
-
withEvent: e.withEvent
|
|
1150
|
-
}
|
|
1151
|
-
}),
|
|
1152
|
-
"artifact:mountSuccess": (e) => ({
|
|
1153
|
-
taskId: e.taskId,
|
|
1154
|
-
kind: e.kind,
|
|
1155
|
-
injectAt: e.injectAt,
|
|
1156
|
-
status: e.status,
|
|
1157
|
-
meta: {
|
|
1158
|
-
artifactName: e.artifactName,
|
|
1159
|
-
alive: e.alive,
|
|
1160
|
-
scope: e.scope
|
|
1161
|
-
}
|
|
1162
|
-
}),
|
|
1163
|
-
"artifact:mountFail": (e) => ({
|
|
1164
|
-
taskId: e.taskId,
|
|
1165
|
-
kind: e.kind,
|
|
1166
|
-
injectAt: e.injectAt,
|
|
1167
|
-
status: "idle",
|
|
1168
|
-
error: e.error,
|
|
1169
|
-
meta: { artifactName: e.artifactName }
|
|
1170
|
-
})
|
|
1171
|
-
};
|
|
1172
|
-
function X(e, t) {
|
|
1173
|
-
return p(e, t, Y);
|
|
1174
|
-
}
|
|
1175
|
-
//#endregion
|
|
1176
|
-
//#region packages/core/src/payload/buildListenerObservePayload.ts
|
|
1177
|
-
var Z = {
|
|
1178
|
-
"listener:attached": (e) => ({
|
|
1179
|
-
taskId: e.taskId,
|
|
1180
|
-
kind: e.kind,
|
|
1181
|
-
injectAt: e.injectAt,
|
|
1182
|
-
status: e.status,
|
|
1183
|
-
meta: {
|
|
1184
|
-
listenerEvent: e.listenerEvent,
|
|
1185
|
-
listenAt: e.listenAt
|
|
1186
|
-
}
|
|
1187
|
-
}),
|
|
1188
|
-
"listener:detached": (e) => ({
|
|
1189
|
-
taskId: e.taskId,
|
|
1190
|
-
kind: e.kind,
|
|
1191
|
-
injectAt: e.injectAt,
|
|
1192
|
-
status: e.status,
|
|
1193
|
-
meta: {
|
|
1194
|
-
listenerEvent: e.listenerEvent,
|
|
1195
|
-
listenAt: e.listenAt
|
|
1196
|
-
}
|
|
1197
|
-
}),
|
|
1198
|
-
"listener:attachFail": (e) => ({
|
|
1199
|
-
taskId: e.taskId,
|
|
1200
|
-
kind: e.kind,
|
|
1201
|
-
injectAt: e.injectAt,
|
|
1202
|
-
status: e.status,
|
|
1203
|
-
error: e.error,
|
|
1204
|
-
meta: {
|
|
1205
|
-
listenerEvent: e.listenerEvent,
|
|
1206
|
-
listenAt: e.listenAt
|
|
1207
|
-
}
|
|
1208
|
-
})
|
|
1209
|
-
};
|
|
1210
|
-
function Q(e, t) {
|
|
1211
|
-
return p(e, t, Z);
|
|
822
|
+
function R(e, t) {
|
|
823
|
+
return m(e, t, L);
|
|
1212
824
|
}
|
|
1213
825
|
//#endregion
|
|
1214
826
|
//#region packages/core/src/payload/buildRunObservePayload.ts
|
|
1215
|
-
var
|
|
1216
|
-
"
|
|
827
|
+
var z = {
|
|
828
|
+
"start:requested": (e) => ({ meta: {
|
|
1217
829
|
totalTasks: e.totalTasks,
|
|
1218
830
|
idleTasks: e.idleTasks,
|
|
1219
831
|
pendingTasks: e.pendingTasks,
|
|
1220
832
|
activeTasks: e.activeTasks
|
|
1221
833
|
} }),
|
|
1222
|
-
"
|
|
834
|
+
"start:taskScheduled": (e) => ({
|
|
1223
835
|
taskId: e.taskId,
|
|
1224
836
|
kind: e.kind,
|
|
1225
837
|
injectAt: e.injectAt,
|
|
@@ -1227,7 +839,7 @@ var ne = {
|
|
|
1227
839
|
preStatus: e.preStatus,
|
|
1228
840
|
meta: { timeout: e.timeout }
|
|
1229
841
|
}),
|
|
1230
|
-
"
|
|
842
|
+
"start:taskSkipped": (e) => ({
|
|
1231
843
|
taskId: e.taskId,
|
|
1232
844
|
kind: e.kind,
|
|
1233
845
|
injectAt: e.injectAt,
|
|
@@ -1241,392 +853,869 @@ var ne = {
|
|
|
1241
853
|
status: e.status
|
|
1242
854
|
})
|
|
1243
855
|
};
|
|
1244
|
-
function
|
|
1245
|
-
return
|
|
856
|
+
function B(e, t) {
|
|
857
|
+
return m(e, t, z);
|
|
858
|
+
}
|
|
859
|
+
//#endregion
|
|
860
|
+
//#region packages/core/src/util/uuid.ts
|
|
861
|
+
function V() {
|
|
862
|
+
return "xxxxxxxx".replace(/[xy]/g, (e) => {
|
|
863
|
+
let t = Math.random() * 16 | 0;
|
|
864
|
+
return (e === "x" ? t : t & 3 | 8).toString(16);
|
|
865
|
+
});
|
|
1246
866
|
}
|
|
1247
867
|
//#endregion
|
|
1248
868
|
//#region packages/core/src/Task/TaskRunner.ts
|
|
1249
|
-
|
|
1250
|
-
taskContext
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
pendingTasks: 0,
|
|
1266
|
-
activeTasks: 0
|
|
1267
|
-
});
|
|
1268
|
-
if (this.emit("run:start", $("run:start", t)), this.taskContext.taskRecords.length === 0) throw new i("No registered tasks found, call register() before run()", [], e.TASK_NO_REGISTERED);
|
|
1269
|
-
this.taskContext.taskRecords.forEach(({ taskId: e, injectAt: t }) => {
|
|
1270
|
-
let n = this.taskContext.getTaskStatus(e), r = this.taskContext.get(e);
|
|
1271
|
-
if (!(!r || !n)) {
|
|
1272
|
-
if (n === "active" || n === "pending") {
|
|
1273
|
-
this.emit("run:taskSkipped", $("run:taskSkipped", {
|
|
1274
|
-
taskId: e,
|
|
1275
|
-
kind: r.kind,
|
|
1276
|
-
injectAt: t,
|
|
1277
|
-
status: n,
|
|
1278
|
-
skipReason: n === "active" ? "already-active" : "already-pending"
|
|
1279
|
-
}));
|
|
1280
|
-
return;
|
|
1281
|
-
}
|
|
1282
|
-
N.onDomReady(t, (t) => this.onTargetReady(t, e), document, {
|
|
1283
|
-
once: !0,
|
|
1284
|
-
timeout: r.timeout
|
|
1285
|
-
}, {
|
|
1286
|
-
logger: this.logger,
|
|
1287
|
-
emit: j({
|
|
1288
|
-
emit: this.emit,
|
|
1289
|
-
taskId: e,
|
|
1290
|
-
kind: r.kind,
|
|
1291
|
-
injectAt: t,
|
|
1292
|
-
root: document
|
|
1293
|
-
})
|
|
1294
|
-
}), this.taskContext.getTaskStatus(e) !== "active" && (this.taskContext.setTaskStatus(e, "pending"), this.emit("run:taskScheduled", $("run:taskScheduled", {
|
|
869
|
+
function H(t, n) {
|
|
870
|
+
let r = new Set(n), i = t.taskContext.taskRecords.filter(({ taskId: e }) => r.has(e)), o = i.reduce((e, { taskId: n }) => {
|
|
871
|
+
let r = t.taskContext.getTaskStatus(n);
|
|
872
|
+
return r === "idle" && (e.idleTasks += 1), r === "pending" && (e.pendingTasks += 1), r === "active" && (e.activeTasks += 1), e;
|
|
873
|
+
}, {
|
|
874
|
+
totalTasks: i.length,
|
|
875
|
+
idleTasks: 0,
|
|
876
|
+
pendingTasks: 0,
|
|
877
|
+
activeTasks: 0
|
|
878
|
+
});
|
|
879
|
+
if (t.emit("start:requested", B("start:requested", o)), i.length === 0) throw new a("No registered tasks found, call start() with tasks before starting", [], e.TASK_NO_REGISTERED);
|
|
880
|
+
i.forEach(({ taskId: e, injectAt: n }) => {
|
|
881
|
+
let r = t.taskContext.getTaskStatus(e), i = t.taskContext.get(e);
|
|
882
|
+
if (!(!i || !r)) {
|
|
883
|
+
if (r === "active" || r === "pending") {
|
|
884
|
+
t.emit("start:taskSkipped", B("start:taskSkipped", {
|
|
1295
885
|
taskId: e,
|
|
1296
|
-
kind:
|
|
1297
|
-
injectAt:
|
|
1298
|
-
status:
|
|
1299
|
-
|
|
1300
|
-
timeout: r.timeout
|
|
1301
|
-
})));
|
|
1302
|
-
}
|
|
1303
|
-
});
|
|
1304
|
-
}
|
|
1305
|
-
onTargetReady(e, t) {
|
|
1306
|
-
let n = this.taskContext.get(t);
|
|
1307
|
-
if (!n) {
|
|
1308
|
-
this.logger.error(`Task "${t}" not found, unable to proceed with injection`);
|
|
1309
|
-
return;
|
|
1310
|
-
}
|
|
1311
|
-
if (this.emit("task:targetReady", $("task:targetReady", {
|
|
1312
|
-
taskId: t,
|
|
1313
|
-
kind: n.kind,
|
|
1314
|
-
injectAt: w(n),
|
|
1315
|
-
status: n.taskStatus
|
|
1316
|
-
})), n.taskStatus === "active") return;
|
|
1317
|
-
let r = w(n);
|
|
1318
|
-
if (C(n)) {
|
|
1319
|
-
this.emit("artifact:mountStart", X("artifact:mountStart", {
|
|
1320
|
-
taskId: t,
|
|
1321
|
-
kind: "component",
|
|
1322
|
-
injectAt: n.injectAt,
|
|
1323
|
-
status: n.taskStatus,
|
|
1324
|
-
artifactName: n.artifactName,
|
|
1325
|
-
alive: n.alive,
|
|
1326
|
-
scope: n.scope,
|
|
1327
|
-
withEvent: n.withEvent
|
|
1328
|
-
}));
|
|
1329
|
-
let r = this.injectArtifact(e, t);
|
|
1330
|
-
if (!r.isSuccess) {
|
|
1331
|
-
this.taskContext.setTaskStatus(t, "idle"), this.emit("artifact:mountFail", X("artifact:mountFail", {
|
|
1332
|
-
taskId: t,
|
|
1333
|
-
kind: "component",
|
|
1334
|
-
injectAt: n.injectAt,
|
|
1335
|
-
status: "idle",
|
|
1336
|
-
error: r.error ?? /* @__PURE__ */ Error(`Component inject failed for task "${t}"`),
|
|
1337
|
-
artifactName: n.artifactName
|
|
1338
|
-
}));
|
|
1339
|
-
return;
|
|
1340
|
-
}
|
|
1341
|
-
this.emit("artifact:mountSuccess", X("artifact:mountSuccess", {
|
|
1342
|
-
taskId: t,
|
|
1343
|
-
kind: "component",
|
|
1344
|
-
injectAt: n.injectAt,
|
|
1345
|
-
status: n.taskStatus,
|
|
1346
|
-
artifactName: n.artifactName,
|
|
1347
|
-
alive: n.alive,
|
|
1348
|
-
scope: n.scope
|
|
1349
|
-
}));
|
|
1350
|
-
}
|
|
1351
|
-
if (n.withEvent) {
|
|
1352
|
-
let e = null, i = T(n);
|
|
1353
|
-
if (e = i?.activitySignal ? this.bindListenerSignal(t, i.activitySignal()) : this.controlListener(t, J.OPEN), e === !1) {
|
|
1354
|
-
this.taskContext.setTaskStatus(t, "idle");
|
|
1355
|
-
let e = T(n);
|
|
1356
|
-
this.emit("listener:attachFail", Q("listener:attachFail", {
|
|
1357
|
-
taskId: t,
|
|
1358
|
-
kind: n.kind,
|
|
1359
|
-
injectAt: r,
|
|
1360
|
-
status: "idle",
|
|
1361
|
-
error: /* @__PURE__ */ Error(`Listener attach failed for task "${t}"`),
|
|
1362
|
-
listenerEvent: e?.event,
|
|
1363
|
-
listenAt: e?.listenAt
|
|
886
|
+
kind: i.kind,
|
|
887
|
+
injectAt: n,
|
|
888
|
+
status: r,
|
|
889
|
+
skipReason: r === "active" ? "already-active" : "already-pending"
|
|
1364
890
|
}));
|
|
1365
891
|
return;
|
|
1366
892
|
}
|
|
893
|
+
N.onDomReady(n, (n) => U(t, n, e), document, {
|
|
894
|
+
once: !0,
|
|
895
|
+
timeout: i.timeout
|
|
896
|
+
}, {
|
|
897
|
+
logger: t.logger,
|
|
898
|
+
emit: A({
|
|
899
|
+
emit: t.emit,
|
|
900
|
+
taskId: e,
|
|
901
|
+
kind: i.kind,
|
|
902
|
+
injectAt: n,
|
|
903
|
+
root: document
|
|
904
|
+
})
|
|
905
|
+
}), t.taskContext.getTaskStatus(e) !== "active" && (t.taskContext.setTaskStatus(e, "pending"), t.emit("start:taskScheduled", B("start:taskScheduled", {
|
|
906
|
+
taskId: e,
|
|
907
|
+
kind: i.kind,
|
|
908
|
+
injectAt: n,
|
|
909
|
+
status: "pending",
|
|
910
|
+
preStatus: "idle",
|
|
911
|
+
timeout: i.timeout
|
|
912
|
+
})));
|
|
1367
913
|
}
|
|
1368
|
-
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
function U(t, n, r) {
|
|
917
|
+
let i = t.taskContext.get(r);
|
|
918
|
+
if (!i) {
|
|
919
|
+
t.logger.error(`Task "${r}" not found, unable to proceed with injection`);
|
|
920
|
+
return;
|
|
1369
921
|
}
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
922
|
+
if (t.emit("task:targetReady", B("task:targetReady", {
|
|
923
|
+
taskId: r,
|
|
924
|
+
kind: i.kind,
|
|
925
|
+
injectAt: T(i),
|
|
926
|
+
status: i.taskStatus
|
|
927
|
+
})), i.taskStatus === "active") return;
|
|
928
|
+
let o = T(i);
|
|
929
|
+
if (w(i)) {
|
|
930
|
+
t.emit("artifact:mountStart", I("artifact:mountStart", {
|
|
931
|
+
taskId: r,
|
|
932
|
+
kind: "component",
|
|
933
|
+
injectAt: i.injectAt,
|
|
934
|
+
status: i.taskStatus,
|
|
935
|
+
artifactName: i.artifactName,
|
|
936
|
+
alive: i.alive,
|
|
937
|
+
scope: i.scope,
|
|
938
|
+
withEvent: i.withEvent
|
|
939
|
+
}));
|
|
940
|
+
let o = ce(t, n, r);
|
|
941
|
+
if (!o.isSuccess) {
|
|
942
|
+
t.taskContext.setTaskStatus(r, "idle"), t.emit("artifact:mountFail", I("artifact:mountFail", {
|
|
943
|
+
taskId: r,
|
|
944
|
+
kind: "component",
|
|
945
|
+
injectAt: i.injectAt,
|
|
946
|
+
status: "idle",
|
|
947
|
+
error: o.error ?? new a(`Component inject failed for task "${r}"`, [{
|
|
948
|
+
path: "taskId",
|
|
949
|
+
message: r
|
|
950
|
+
}], e.TASK_INJECT_FAIL),
|
|
951
|
+
artifactName: i.artifactName
|
|
952
|
+
}));
|
|
953
|
+
return;
|
|
1383
954
|
}
|
|
955
|
+
t.emit("artifact:mountSuccess", I("artifact:mountSuccess", {
|
|
956
|
+
taskId: r,
|
|
957
|
+
kind: "component",
|
|
958
|
+
injectAt: i.injectAt,
|
|
959
|
+
status: i.taskStatus,
|
|
960
|
+
artifactName: i.artifactName,
|
|
961
|
+
alive: i.alive,
|
|
962
|
+
scope: i.scope
|
|
963
|
+
}));
|
|
1384
964
|
}
|
|
1385
|
-
|
|
1386
|
-
let n =
|
|
1387
|
-
if (
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
let t = /* @__PURE__ */ Error(`Failed to attach event "${r.event}" for task "${e}"`);
|
|
1404
|
-
return this.logger.error(t.message), this.emit("listener:attachFail", Q("listener:attachFail", {
|
|
1405
|
-
taskId: e,
|
|
1406
|
-
kind: n.kind,
|
|
1407
|
-
injectAt: r.listenAt,
|
|
1408
|
-
status: n.taskStatus,
|
|
1409
|
-
error: t,
|
|
1410
|
-
listenerEvent: r.event,
|
|
1411
|
-
listenAt: r.listenAt
|
|
1412
|
-
})), !1;
|
|
1413
|
-
}
|
|
1414
|
-
break;
|
|
1415
|
-
}
|
|
1416
|
-
case J.CLOSE:
|
|
1417
|
-
if (!r.controller) return !1;
|
|
1418
|
-
r.controller.abort(), r.controller = void 0, this.logger.info(`Event "${r.event}" detached from task "${e}"`), this.emit("listener:detached", Q("listener:detached", {
|
|
1419
|
-
taskId: e,
|
|
1420
|
-
kind: n.kind,
|
|
1421
|
-
injectAt: r.listenAt,
|
|
1422
|
-
status: n.taskStatus,
|
|
1423
|
-
listenerEvent: r.event,
|
|
1424
|
-
listenAt: r.listenAt
|
|
1425
|
-
}));
|
|
1426
|
-
break;
|
|
1427
|
-
default: return this.logger.warn(`Unknown action type "${t}" for task "${e}"`), !1;
|
|
965
|
+
if (i.withEvent) {
|
|
966
|
+
let n = null, s = E(i);
|
|
967
|
+
if (n = s?.activitySignal ? W(t, r, s.activitySignal()) : G(t, r, F.OPEN), n === !1) {
|
|
968
|
+
t.taskContext.setTaskStatus(r, "idle");
|
|
969
|
+
let n = E(i);
|
|
970
|
+
t.emit("listener:attachFail", R("listener:attachFail", {
|
|
971
|
+
taskId: r,
|
|
972
|
+
kind: i.kind,
|
|
973
|
+
injectAt: o,
|
|
974
|
+
status: "idle",
|
|
975
|
+
error: new a(`Listener attach failed for task "${r}"`, [{
|
|
976
|
+
path: "taskId",
|
|
977
|
+
message: r
|
|
978
|
+
}], e.TASK_LISTENER_ATTACH_FAIL),
|
|
979
|
+
listenerEvent: n?.event,
|
|
980
|
+
listenAt: n?.listenAt
|
|
981
|
+
}));
|
|
982
|
+
return;
|
|
1428
983
|
}
|
|
1429
|
-
return !0;
|
|
1430
984
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
return
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
},
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
root: document
|
|
1451
|
-
})
|
|
1452
|
-
}), o;
|
|
985
|
+
t.taskContext.setTaskStatus(r, "active");
|
|
986
|
+
}
|
|
987
|
+
function W(t, n, r) {
|
|
988
|
+
let a = t.taskContext.get(n);
|
|
989
|
+
if (!a) return t.logger.error(`Task "${n}" not found, unable to bind activity signal`), !1;
|
|
990
|
+
a.watcher &&= (C(a.watcher.watcher), void 0);
|
|
991
|
+
try {
|
|
992
|
+
return a.watcher = {
|
|
993
|
+
watcher: S(r, (e) => {
|
|
994
|
+
G(t, n, e ? F.OPEN : F.CLOSE);
|
|
995
|
+
}),
|
|
996
|
+
watchSource: r
|
|
997
|
+
}, !0;
|
|
998
|
+
} catch (r) {
|
|
999
|
+
let a = r instanceof i ? r : new i(`Failed to bind activity signal for task "${n}"`, [{
|
|
1000
|
+
path: "taskId",
|
|
1001
|
+
message: n
|
|
1002
|
+
}], e.TASK_SIGNAL_BIND_FAIL, r instanceof Error ? r : void 0);
|
|
1003
|
+
return t.logger.error(`Failed to bind activity signal for task "${n}":`, a), !1;
|
|
1453
1004
|
}
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
let a = N.onDomAlive(e, r, () => {
|
|
1497
|
-
this.taskContext.reset(t);
|
|
1498
|
-
}, (e) => this.onTargetReady(e, t), n.scope === "global" ? i : e, {
|
|
1499
|
-
once: !0,
|
|
1500
|
-
timeout: this.injectConfig.timeout
|
|
1501
|
-
}, {
|
|
1502
|
-
logger: this.logger,
|
|
1503
|
-
emit: j({
|
|
1504
|
-
emit: this.emit,
|
|
1505
|
-
taskId: t,
|
|
1506
|
-
kind: n.kind,
|
|
1507
|
-
injectAt: r,
|
|
1508
|
-
root: n.scope === "global" ? i : e
|
|
1509
|
-
})
|
|
1510
|
-
});
|
|
1511
|
-
!n.alive || n.mountHandle !== o.handle ? a() : (n.disableAlive = a, n.isObserver = !0, this.logger.info(`Task "${t}" alive observer activated`));
|
|
1005
|
+
}
|
|
1006
|
+
function G(t, n, r) {
|
|
1007
|
+
let i = t.taskContext.get(n);
|
|
1008
|
+
if (!i) return t.logger.error(`Task "${n}" not found, unable to manage listener state`), !1;
|
|
1009
|
+
let o = E(i);
|
|
1010
|
+
if (!o) return t.logger.warn(`Task "${n}" has no event binding configured`), !1;
|
|
1011
|
+
switch (r) {
|
|
1012
|
+
case F.OPEN: {
|
|
1013
|
+
if (o.controller) return !1;
|
|
1014
|
+
let r = K(t, n, i.kind, o.listenAt, o.event, o.callback);
|
|
1015
|
+
if (r) o.controller = r, t.emit("listener:attached", R("listener:attached", {
|
|
1016
|
+
taskId: n,
|
|
1017
|
+
kind: i.kind,
|
|
1018
|
+
injectAt: o.listenAt,
|
|
1019
|
+
status: i.taskStatus,
|
|
1020
|
+
listenerEvent: o.event,
|
|
1021
|
+
listenAt: o.listenAt
|
|
1022
|
+
}));
|
|
1023
|
+
else {
|
|
1024
|
+
let r = new a(`Failed to attach event "${o.event}" for task "${n}"`, [
|
|
1025
|
+
{
|
|
1026
|
+
path: "taskId",
|
|
1027
|
+
message: n
|
|
1028
|
+
},
|
|
1029
|
+
{
|
|
1030
|
+
path: "listener.event",
|
|
1031
|
+
message: o.event
|
|
1032
|
+
},
|
|
1033
|
+
{
|
|
1034
|
+
path: "listener.listenAt",
|
|
1035
|
+
message: o.listenAt
|
|
1036
|
+
}
|
|
1037
|
+
], e.TASK_LISTENER_ATTACH_FAIL);
|
|
1038
|
+
return t.logger.error(r.message), t.emit("listener:attachFail", R("listener:attachFail", {
|
|
1039
|
+
taskId: n,
|
|
1040
|
+
kind: i.kind,
|
|
1041
|
+
injectAt: o.listenAt,
|
|
1042
|
+
status: i.taskStatus,
|
|
1043
|
+
error: r,
|
|
1044
|
+
listenerEvent: o.event,
|
|
1045
|
+
listenAt: o.listenAt
|
|
1046
|
+
})), !1;
|
|
1512
1047
|
}
|
|
1513
|
-
|
|
1514
|
-
} catch (e) {
|
|
1515
|
-
return this.logger.error(`Artifact mount failed for task "${t}":`, e), a.remove(), {
|
|
1516
|
-
isSuccess: !1,
|
|
1517
|
-
error: e
|
|
1518
|
-
};
|
|
1048
|
+
break;
|
|
1519
1049
|
}
|
|
1050
|
+
case F.CLOSE:
|
|
1051
|
+
if (!o.controller) return !1;
|
|
1052
|
+
o.controller.abort(), o.controller = void 0, t.logger.info(`Event "${o.event}" detached from task "${n}"`), t.emit("listener:detached", R("listener:detached", {
|
|
1053
|
+
taskId: n,
|
|
1054
|
+
kind: i.kind,
|
|
1055
|
+
injectAt: o.listenAt,
|
|
1056
|
+
status: i.taskStatus,
|
|
1057
|
+
listenerEvent: o.event,
|
|
1058
|
+
listenAt: o.listenAt
|
|
1059
|
+
}));
|
|
1060
|
+
break;
|
|
1061
|
+
default: return t.logger.warn(`Unknown action type "${r}" for task "${n}"`), !1;
|
|
1520
1062
|
}
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
offTask: (t, n) => this.observer.offTask(e, t, n),
|
|
1557
|
-
getLogger: () => this.logger,
|
|
1558
|
-
bindListenerSignal: (t) => this.taskRunner.bindListenerSignal(e, t),
|
|
1559
|
-
controlListener: (t) => this.taskRunner.controlListener(e, t)
|
|
1063
|
+
return !0;
|
|
1064
|
+
}
|
|
1065
|
+
function K(e, t, n, r, i, a) {
|
|
1066
|
+
let o = document.querySelector(r);
|
|
1067
|
+
if (o) {
|
|
1068
|
+
let n = new AbortController();
|
|
1069
|
+
return o.addEventListener(i, a, { signal: n.signal }), e.logger.info(`Event "${i}" attached at "${r}" (task: ${t})`), n;
|
|
1070
|
+
}
|
|
1071
|
+
let s = new AbortController();
|
|
1072
|
+
return N.onDomReady(r, (n) => {
|
|
1073
|
+
s.signal.aborted || (n.addEventListener(i, a, { signal: s.signal }), e.logger.info(`Event "${i}" attached at "${r}" (task: ${t})`));
|
|
1074
|
+
}, document, {
|
|
1075
|
+
once: !0,
|
|
1076
|
+
timeout: e.config.timeout
|
|
1077
|
+
}, {
|
|
1078
|
+
logger: e.logger,
|
|
1079
|
+
emit: A({
|
|
1080
|
+
emit: e.emit,
|
|
1081
|
+
taskId: t,
|
|
1082
|
+
kind: n,
|
|
1083
|
+
injectAt: r,
|
|
1084
|
+
root: document
|
|
1085
|
+
})
|
|
1086
|
+
}), s;
|
|
1087
|
+
}
|
|
1088
|
+
function ce(t, n, i) {
|
|
1089
|
+
let o = t.taskContext.get(i);
|
|
1090
|
+
if (!o || !w(o)) {
|
|
1091
|
+
let n = new a(`Task "${i}" context missing, injection aborted`, [{
|
|
1092
|
+
path: "taskId",
|
|
1093
|
+
message: i
|
|
1094
|
+
}], e.TASK_NOT_FOUND);
|
|
1095
|
+
return t.logger.error(n.message), {
|
|
1096
|
+
isSuccess: !1,
|
|
1097
|
+
error: n
|
|
1560
1098
|
};
|
|
1561
1099
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1100
|
+
if (!o.taskId) {
|
|
1101
|
+
let n = new a(`No artifact found for task "${i}", injection aborted`, [{
|
|
1102
|
+
path: "taskId",
|
|
1103
|
+
message: i
|
|
1104
|
+
}], e.TASK_INJECT_FAIL);
|
|
1105
|
+
return t.logger.error(n.message), {
|
|
1106
|
+
isSuccess: !1,
|
|
1107
|
+
error: n
|
|
1108
|
+
};
|
|
1567
1109
|
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1110
|
+
if (o.mountHandle) {
|
|
1111
|
+
let n = new a(`Task "${i}" is already mounted, skipping`, [{
|
|
1112
|
+
path: "taskId",
|
|
1113
|
+
message: i
|
|
1114
|
+
}], e.TASK_ALREADY_MOUNTED);
|
|
1115
|
+
return t.logger.warn(n.message), {
|
|
1116
|
+
isSuccess: !1,
|
|
1117
|
+
error: n
|
|
1118
|
+
};
|
|
1570
1119
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1120
|
+
let s = o.injectAt, c = n.ownerDocument || document, l = c.createElement("div");
|
|
1121
|
+
if (l.id = `implant-root-${V()}`, l.style.display = "contents", l.style.zIndex = "999999", n.isConnected) n.appendChild(l);
|
|
1122
|
+
else {
|
|
1123
|
+
let n = new a(`Target element for task "${i}" is detached from DOM, injection skipped`, [{
|
|
1124
|
+
path: "taskId",
|
|
1125
|
+
message: i
|
|
1126
|
+
}], e.TASK_TARGET_DETACHED);
|
|
1127
|
+
return t.logger.warn(n.message), {
|
|
1128
|
+
isSuccess: !1,
|
|
1129
|
+
error: n
|
|
1577
1130
|
};
|
|
1578
1131
|
}
|
|
1579
|
-
|
|
1580
|
-
|
|
1132
|
+
try {
|
|
1133
|
+
let e = o.adapter.mount({
|
|
1134
|
+
host: n,
|
|
1135
|
+
mountPoint: l,
|
|
1136
|
+
artifact: o.artifact,
|
|
1137
|
+
taskId: i,
|
|
1138
|
+
injectAt: s,
|
|
1139
|
+
makoo: t.makooContext(i, s)
|
|
1140
|
+
});
|
|
1141
|
+
if (o.mountHandle = e.handle, o.hostElement = n, o.instance = e.instance, o.appRoot = l, t.logger.info(`Artifact "${o.artifactName}" injected at "${s}"`), o.alive && !o.isObserver) {
|
|
1142
|
+
let r = N.onDomAlive(n, s, () => {
|
|
1143
|
+
t.taskContext.reset(i);
|
|
1144
|
+
}, (e) => U(t, e, i), o.scope === "global" ? c : n, {
|
|
1145
|
+
once: !0,
|
|
1146
|
+
timeout: t.config.timeout
|
|
1147
|
+
}, {
|
|
1148
|
+
logger: t.logger,
|
|
1149
|
+
emit: A({
|
|
1150
|
+
emit: t.emit,
|
|
1151
|
+
taskId: i,
|
|
1152
|
+
kind: o.kind,
|
|
1153
|
+
injectAt: s,
|
|
1154
|
+
root: o.scope === "global" ? c : n
|
|
1155
|
+
})
|
|
1156
|
+
});
|
|
1157
|
+
!o.alive || o.mountHandle !== e.handle ? r() : (o.disableAlive = r, o.isObserver = !0, t.emit("alive:observerStarted", D("alive:observerStarted", {
|
|
1158
|
+
taskId: i,
|
|
1159
|
+
kind: "component",
|
|
1160
|
+
injectAt: s,
|
|
1161
|
+
status: o.taskStatus,
|
|
1162
|
+
scope: o.scope,
|
|
1163
|
+
observerMode: "mounted"
|
|
1164
|
+
})), t.logger.info(`Task "${i}" alive observer activated`));
|
|
1165
|
+
}
|
|
1166
|
+
return { isSuccess: !0 };
|
|
1167
|
+
} catch (n) {
|
|
1168
|
+
let a = new r(`Artifact mount failed for task "${i}"`, [{
|
|
1169
|
+
path: "taskId",
|
|
1170
|
+
message: i
|
|
1171
|
+
}], e.ADAPTER_MOUNT_FAIL, n instanceof Error ? n : void 0);
|
|
1172
|
+
return t.logger.error(`Artifact mount failed for task "${i}":`, a), l.remove(), {
|
|
1173
|
+
isSuccess: !1,
|
|
1174
|
+
error: a
|
|
1175
|
+
};
|
|
1581
1176
|
}
|
|
1582
|
-
|
|
1583
|
-
|
|
1177
|
+
}
|
|
1178
|
+
//#endregion
|
|
1179
|
+
//#region packages/core/src/Task/TaskLifeCycle.ts
|
|
1180
|
+
function q(e, t) {
|
|
1181
|
+
let n = e.taskContext.get(t);
|
|
1182
|
+
if (!n) {
|
|
1183
|
+
e.logger.error(`Task "${t}" not found`);
|
|
1184
|
+
return;
|
|
1584
1185
|
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1186
|
+
if (!w(n)) {
|
|
1187
|
+
e.logger.warn(`enableAlive is not applicable to non-component task "${t}"`);
|
|
1188
|
+
return;
|
|
1587
1189
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
1190
|
+
if (n.alive && n.isObserver) {
|
|
1191
|
+
e.logger.warn(`Task "${t}" already has an active alive observer`);
|
|
1192
|
+
return;
|
|
1590
1193
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1194
|
+
if (n.alive = !0, n.isObserver = !1, e.emit("alive:enabled", D("alive:enabled", {
|
|
1195
|
+
taskId: t,
|
|
1196
|
+
kind: "component",
|
|
1197
|
+
injectAt: n.injectAt,
|
|
1198
|
+
status: n.taskStatus,
|
|
1199
|
+
scope: n.scope
|
|
1200
|
+
})), n.disableAlive = () => {}, n.mountHandle && n.appRoot?.isConnected) {
|
|
1201
|
+
let r = n.hostElement ?? n.appRoot.parentElement;
|
|
1202
|
+
if (!r) {
|
|
1203
|
+
e.logger.warn(`Task "${t}": host element not found, unable to activate alive observer`);
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
let i = r.ownerDocument || document, a = n.injectAt, o = N.onDomAlive(r, a, () => {
|
|
1207
|
+
e.taskContext.reset(t);
|
|
1208
|
+
}, (n) => U(e, n, t), n.scope === "global" ? i : r, {
|
|
1209
|
+
once: !0,
|
|
1210
|
+
timeout: e.config.timeout
|
|
1211
|
+
}, {
|
|
1212
|
+
logger: e.logger,
|
|
1213
|
+
emit: A({
|
|
1214
|
+
emit: e.emit,
|
|
1215
|
+
taskId: t,
|
|
1216
|
+
kind: "component",
|
|
1217
|
+
injectAt: a,
|
|
1218
|
+
root: n.scope === "global" ? i : r
|
|
1219
|
+
})
|
|
1220
|
+
});
|
|
1221
|
+
if (!n.alive) {
|
|
1222
|
+
o();
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
n.disableAlive = o, n.isObserver = !0, e.emit("alive:observerStarted", D("alive:observerStarted", {
|
|
1226
|
+
taskId: t,
|
|
1227
|
+
kind: "component",
|
|
1228
|
+
injectAt: a,
|
|
1229
|
+
status: n.taskStatus,
|
|
1230
|
+
scope: n.scope,
|
|
1231
|
+
observerMode: "mounted"
|
|
1232
|
+
})), e.logger.info(`Task "${t}" alive observer activated`);
|
|
1233
|
+
return;
|
|
1593
1234
|
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1235
|
+
if (n.mountHandle && !n.appRoot?.isConnected && e.taskContext.reset(t), !n.mountHandle) {
|
|
1236
|
+
let r = !1, i = N.onDomReady(n.injectAt, (i) => {
|
|
1237
|
+
if (r || !n.alive) {
|
|
1238
|
+
e.logger.warn(`Task "${t}" alive state changed before element appears`);
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
U(e, i, t);
|
|
1242
|
+
}, document, {
|
|
1243
|
+
once: !0,
|
|
1244
|
+
timeout: e.config.timeout
|
|
1245
|
+
}, {
|
|
1246
|
+
logger: e.logger,
|
|
1247
|
+
emit: A({
|
|
1248
|
+
emit: e.emit,
|
|
1249
|
+
taskId: t,
|
|
1250
|
+
kind: "component",
|
|
1251
|
+
injectAt: n.injectAt,
|
|
1252
|
+
root: document
|
|
1253
|
+
})
|
|
1254
|
+
});
|
|
1255
|
+
n.disableAlive = () => {
|
|
1256
|
+
r || (r = !0, e.emit("alive:observerStopped", D("alive:observerStopped", {
|
|
1257
|
+
taskId: t,
|
|
1258
|
+
kind: "component",
|
|
1259
|
+
injectAt: n.injectAt,
|
|
1260
|
+
status: n.taskStatus,
|
|
1261
|
+
scope: n.scope,
|
|
1262
|
+
observerMode: "await-target"
|
|
1263
|
+
})), i());
|
|
1264
|
+
}, n.isObserver = !0, e.emit("alive:observerStarted", D("alive:observerStarted", {
|
|
1265
|
+
taskId: t,
|
|
1266
|
+
kind: "component",
|
|
1267
|
+
injectAt: n.injectAt,
|
|
1268
|
+
status: n.taskStatus,
|
|
1269
|
+
scope: n.scope,
|
|
1270
|
+
observerMode: "await-target"
|
|
1271
|
+
})), e.logger.info(`Task "${t}" awaiting target element for re-injection`);
|
|
1596
1272
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1273
|
+
}
|
|
1274
|
+
function J(e, t) {
|
|
1275
|
+
let n = e.taskContext.get(t);
|
|
1276
|
+
if (!n) {
|
|
1277
|
+
e.logger.error(`Task "${t}" not found`);
|
|
1278
|
+
return;
|
|
1599
1279
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1280
|
+
if (!w(n)) {
|
|
1281
|
+
e.logger.warn(`disableAlive is not applicable to non-component task "${t}"`);
|
|
1282
|
+
return;
|
|
1602
1283
|
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1284
|
+
if (!n.alive) {
|
|
1285
|
+
e.logger.warn(`Task "${t}" has no active alive observer to stop`);
|
|
1286
|
+
return;
|
|
1605
1287
|
}
|
|
1606
|
-
|
|
1607
|
-
|
|
1288
|
+
let r = n.disableAlive;
|
|
1289
|
+
n.alive = !1, n.isObserver = !1, n.disableAlive = void 0, r?.(), e.emit("alive:disabled", D("alive:disabled", {
|
|
1290
|
+
taskId: t,
|
|
1291
|
+
kind: "component",
|
|
1292
|
+
injectAt: n.injectAt,
|
|
1293
|
+
status: n.taskStatus,
|
|
1294
|
+
scope: n.scope
|
|
1295
|
+
})), e.emit("alive:observerStopped", D("alive:observerStopped", {
|
|
1296
|
+
taskId: t,
|
|
1297
|
+
kind: "component",
|
|
1298
|
+
injectAt: n.injectAt,
|
|
1299
|
+
status: n.taskStatus,
|
|
1300
|
+
scope: n.scope,
|
|
1301
|
+
observerMode: n.mountHandle ? "mounted" : "await-target"
|
|
1302
|
+
}));
|
|
1303
|
+
}
|
|
1304
|
+
function Y(e, t) {
|
|
1305
|
+
let n = e.taskContext.get(t);
|
|
1306
|
+
if (!n) {
|
|
1307
|
+
e.logger.error(`Task ${t} not found`);
|
|
1308
|
+
return;
|
|
1608
1309
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1310
|
+
let r = n.taskStatus, i = T(n);
|
|
1311
|
+
e.emit("task:beforeDestroy", v("task:beforeDestroy", {
|
|
1312
|
+
taskId: t,
|
|
1313
|
+
kind: n.kind,
|
|
1314
|
+
injectAt: i,
|
|
1315
|
+
status: r
|
|
1316
|
+
})), w(n) && n.alive && J(e, t), e.taskContext.destroy(t), e.emit("task:afterDestroy", v("task:afterDestroy", {
|
|
1317
|
+
taskId: t,
|
|
1318
|
+
kind: n.kind,
|
|
1319
|
+
injectAt: i,
|
|
1320
|
+
preStatus: r
|
|
1321
|
+
}));
|
|
1322
|
+
}
|
|
1323
|
+
function le(e) {
|
|
1324
|
+
for (let t of e.taskContext.keys()) {
|
|
1325
|
+
let n = e.taskContext.get(t);
|
|
1326
|
+
n && w(n) && n.alive && J(e, t);
|
|
1611
1327
|
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1328
|
+
e.taskContext.destroyAll();
|
|
1329
|
+
}
|
|
1330
|
+
function X(e, t) {
|
|
1331
|
+
let n = e.taskContext.get(t);
|
|
1332
|
+
if (!n) {
|
|
1333
|
+
e.logger.error(`Task ${t} not found`);
|
|
1334
|
+
return;
|
|
1614
1335
|
}
|
|
1615
|
-
|
|
1616
|
-
|
|
1336
|
+
let r = n.taskStatus, i = T(n);
|
|
1337
|
+
e.emit("task:beforeReset", v("task:beforeReset", {
|
|
1338
|
+
taskId: t,
|
|
1339
|
+
kind: n.kind,
|
|
1340
|
+
injectAt: i,
|
|
1341
|
+
status: r
|
|
1342
|
+
})), w(n) && n.alive && J(e, t), e.taskContext.reset(t), e.emit("task:afterReset", v("task:afterReset", {
|
|
1343
|
+
taskId: t,
|
|
1344
|
+
kind: n.kind,
|
|
1345
|
+
injectAt: i,
|
|
1346
|
+
status: n.taskStatus,
|
|
1347
|
+
preStatus: r
|
|
1348
|
+
}));
|
|
1349
|
+
}
|
|
1350
|
+
function ue(e) {
|
|
1351
|
+
for (let t of e.taskContext.keys()) {
|
|
1352
|
+
let n = e.taskContext.get(t);
|
|
1353
|
+
n && w(n) && n.alive && J(e, t);
|
|
1617
1354
|
}
|
|
1618
|
-
|
|
1619
|
-
|
|
1355
|
+
e.taskContext.resetAll();
|
|
1356
|
+
}
|
|
1357
|
+
//#endregion
|
|
1358
|
+
//#region packages/core/src/runtime/createRuntime.ts
|
|
1359
|
+
var de = {
|
|
1360
|
+
alive: !1,
|
|
1361
|
+
scope: "local",
|
|
1362
|
+
timeout: 5e3
|
|
1363
|
+
};
|
|
1364
|
+
function fe(e = {}) {
|
|
1365
|
+
let t = e.logger ?? new o(), n = e.observer ?? d(t), r = c(n), i = te(r, t), a = p();
|
|
1366
|
+
for (let t of e.adapters ?? []) a.use(t);
|
|
1367
|
+
let s = {
|
|
1368
|
+
config: {
|
|
1369
|
+
...de,
|
|
1370
|
+
...e.defaults,
|
|
1371
|
+
logger: t,
|
|
1372
|
+
observer: n,
|
|
1373
|
+
hooks: e.hooks
|
|
1374
|
+
},
|
|
1375
|
+
logger: t,
|
|
1376
|
+
emit: r,
|
|
1377
|
+
taskContext: i,
|
|
1378
|
+
adapterRegistry: a,
|
|
1379
|
+
makooContext(e, t) {
|
|
1380
|
+
return pe(s, e, t);
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
return l(n, e.hooks), s;
|
|
1384
|
+
}
|
|
1385
|
+
function pe(e, t, n) {
|
|
1386
|
+
return {
|
|
1387
|
+
taskId: t,
|
|
1388
|
+
injectAt: n,
|
|
1389
|
+
enableAlive: () => q(e, t),
|
|
1390
|
+
disableAlive: () => J(e, t),
|
|
1391
|
+
reset: () => X(e, t),
|
|
1392
|
+
destroy: () => Y(e, t),
|
|
1393
|
+
on: (t, n) => e.config.observer?.on(t, n) ?? (() => {}),
|
|
1394
|
+
onTask: (n, r) => e.config.observer?.onTask(t, n, r) ?? (() => {}),
|
|
1395
|
+
off: (t, n) => e.config.observer?.off(t, n),
|
|
1396
|
+
offTask: (n, r) => e.config.observer?.offTask(t, n, r),
|
|
1397
|
+
getLogger: () => e.logger,
|
|
1398
|
+
bindListenerSignal: (n) => W(e, t, n),
|
|
1399
|
+
controlListener: (n) => G(e, t, n)
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
//#endregion
|
|
1403
|
+
//#region packages/core/src/payload/buildRegisterObservePayload.ts
|
|
1404
|
+
var me = {
|
|
1405
|
+
"register:start": (e) => ({
|
|
1406
|
+
taskId: e.taskId,
|
|
1407
|
+
kind: e.kind,
|
|
1408
|
+
injectAt: e.injectAt,
|
|
1409
|
+
status: e.status,
|
|
1410
|
+
meta: {
|
|
1411
|
+
artifactName: e.artifactName,
|
|
1412
|
+
listenerEvent: e.listenerEvent,
|
|
1413
|
+
listenAt: e.listenAt,
|
|
1414
|
+
alive: e.alive,
|
|
1415
|
+
scope: e.scope,
|
|
1416
|
+
timeout: e.timeout,
|
|
1417
|
+
withEvent: e.withEvent
|
|
1418
|
+
}
|
|
1419
|
+
}),
|
|
1420
|
+
"register:success": (e) => ({
|
|
1421
|
+
taskId: e.taskId,
|
|
1422
|
+
kind: e.kind,
|
|
1423
|
+
injectAt: e.injectAt,
|
|
1424
|
+
status: e.status,
|
|
1425
|
+
meta: {
|
|
1426
|
+
artifactName: e.artifactName,
|
|
1427
|
+
listenerEvent: e.listenerEvent,
|
|
1428
|
+
listenAt: e.listenAt,
|
|
1429
|
+
alive: e.alive,
|
|
1430
|
+
scope: e.scope,
|
|
1431
|
+
timeout: e.timeout,
|
|
1432
|
+
withEvent: e.withEvent
|
|
1433
|
+
}
|
|
1434
|
+
}),
|
|
1435
|
+
"register:duplicate": (e) => ({
|
|
1436
|
+
taskId: e.taskId,
|
|
1437
|
+
kind: e.kind,
|
|
1438
|
+
injectAt: e.injectAt,
|
|
1439
|
+
status: e.status,
|
|
1440
|
+
meta: Z(e)
|
|
1441
|
+
}),
|
|
1442
|
+
"register:error": (e) => ({
|
|
1443
|
+
taskId: e.taskId,
|
|
1444
|
+
kind: e.kind,
|
|
1445
|
+
injectAt: e.injectAt,
|
|
1446
|
+
status: e.status,
|
|
1447
|
+
error: e.error,
|
|
1448
|
+
meta: Z(e)
|
|
1449
|
+
})
|
|
1450
|
+
};
|
|
1451
|
+
function Z(e) {
|
|
1452
|
+
return e.artifactName === void 0 ? e.listenerEvent === void 0 ? {} : { listenerEvent: e.listenerEvent } : { artifactName: e.artifactName };
|
|
1453
|
+
}
|
|
1454
|
+
function Q(e, t) {
|
|
1455
|
+
return m(e, t, me);
|
|
1456
|
+
}
|
|
1457
|
+
//#endregion
|
|
1458
|
+
//#region packages/core/src/util/getArtifactName.ts
|
|
1459
|
+
var he = /* @__PURE__ */ new WeakMap();
|
|
1460
|
+
function ge(e, t, n, r) {
|
|
1461
|
+
let i = e?.name || e?.__name;
|
|
1462
|
+
if (i) return i;
|
|
1463
|
+
if (typeof e == "string") return e;
|
|
1464
|
+
if (typeof e == "object" || typeof e == "function") {
|
|
1465
|
+
let r = e, i = t.get(r);
|
|
1466
|
+
if (i) return i;
|
|
1467
|
+
let a = `${n}-${V()}`;
|
|
1468
|
+
return t.set(r, a), a;
|
|
1620
1469
|
}
|
|
1621
|
-
|
|
1622
|
-
|
|
1470
|
+
return r;
|
|
1471
|
+
}
|
|
1472
|
+
function _e(e) {
|
|
1473
|
+
return ge(e, he, "artifact", "artifact-anonymous");
|
|
1474
|
+
}
|
|
1475
|
+
//#endregion
|
|
1476
|
+
//#region packages/core/src/Task/TaskRegister.ts
|
|
1477
|
+
function ve(e, t) {
|
|
1478
|
+
let { listenAt: n, event: r, callback: i, activitySignal: a } = t, o = `listener-${n}-${r}`;
|
|
1479
|
+
e.emit("register:start", Q("register:start", {
|
|
1480
|
+
taskId: o,
|
|
1481
|
+
kind: "listener",
|
|
1482
|
+
injectAt: n,
|
|
1483
|
+
status: "idle",
|
|
1484
|
+
listenerEvent: r,
|
|
1485
|
+
listenAt: n,
|
|
1486
|
+
withEvent: !0
|
|
1487
|
+
}));
|
|
1488
|
+
try {
|
|
1489
|
+
if (e.taskContext.has(o)) return e.logger.warn(`Listener "${o}" is already registered, skipping`), e.emit("register:duplicate", Q("register:duplicate", {
|
|
1490
|
+
taskId: o,
|
|
1491
|
+
kind: "listener",
|
|
1492
|
+
injectAt: n,
|
|
1493
|
+
status: e.taskContext.getTaskStatus(o) ?? "idle",
|
|
1494
|
+
listenerEvent: r
|
|
1495
|
+
})), {
|
|
1496
|
+
taskId: o,
|
|
1497
|
+
isSuccess: !0,
|
|
1498
|
+
isDuplicate: !0
|
|
1499
|
+
};
|
|
1500
|
+
let t = {
|
|
1501
|
+
taskId: o,
|
|
1502
|
+
kind: "listener",
|
|
1503
|
+
taskStatus: "idle",
|
|
1504
|
+
timeout: e.config.timeout,
|
|
1505
|
+
withEvent: !0,
|
|
1506
|
+
listenAt: n,
|
|
1507
|
+
event: r,
|
|
1508
|
+
callback: i
|
|
1509
|
+
};
|
|
1510
|
+
return a && (t.activitySignal = a), e.taskContext.set(o, t), e.taskContext.taskRecords.push({
|
|
1511
|
+
taskId: o,
|
|
1512
|
+
injectAt: n
|
|
1513
|
+
}), e.logger.info(`Listener "${o}" registered`), e.emit("register:success", Q("register:success", {
|
|
1514
|
+
taskId: o,
|
|
1515
|
+
kind: "listener",
|
|
1516
|
+
injectAt: n,
|
|
1517
|
+
status: "idle",
|
|
1518
|
+
listenerEvent: r,
|
|
1519
|
+
listenAt: n,
|
|
1520
|
+
withEvent: !0
|
|
1521
|
+
})), {
|
|
1522
|
+
taskId: o,
|
|
1523
|
+
isSuccess: !0
|
|
1524
|
+
};
|
|
1525
|
+
} catch (t) {
|
|
1526
|
+
return e.emit("register:error", Q("register:error", {
|
|
1527
|
+
taskId: o,
|
|
1528
|
+
kind: "listener",
|
|
1529
|
+
injectAt: n,
|
|
1530
|
+
status: e.taskContext.getTaskStatus(o) ?? "idle",
|
|
1531
|
+
error: t,
|
|
1532
|
+
listenerEvent: r
|
|
1533
|
+
})), {
|
|
1534
|
+
taskId: o,
|
|
1535
|
+
isSuccess: !1
|
|
1536
|
+
};
|
|
1623
1537
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1538
|
+
}
|
|
1539
|
+
function ye(t, n) {
|
|
1540
|
+
let { injectAt: i, artifact: a, options: o } = n, s = _e(a), c = s ? `${s}@${i}` : `artifact-${i}`, u = !!o?.on, d = o?.on?.type, f = o?.on?.listenAt, p = o?.alive ?? t.config.alive, m = o?.scope ?? t.config.scope, h = o?.timeout ?? t.config.timeout, g = t.adapterRegistry.resolve(a);
|
|
1541
|
+
if (!g) throw new r(`No adapter found for artifact: ${s}`, [{
|
|
1542
|
+
path: "artifact",
|
|
1543
|
+
message: s
|
|
1544
|
+
}], e.ADAPTER_NOT_FOUND);
|
|
1545
|
+
t.emit("register:start", Q("register:start", {
|
|
1546
|
+
taskId: c,
|
|
1547
|
+
kind: "component",
|
|
1548
|
+
injectAt: i,
|
|
1549
|
+
status: "idle",
|
|
1550
|
+
artifactName: s,
|
|
1551
|
+
listenerEvent: d,
|
|
1552
|
+
listenAt: f,
|
|
1553
|
+
alive: p,
|
|
1554
|
+
scope: m,
|
|
1555
|
+
timeout: h,
|
|
1556
|
+
withEvent: u
|
|
1557
|
+
}));
|
|
1558
|
+
try {
|
|
1559
|
+
if (t.taskContext.has(c)) return t.logger.warn(`Task "${c}" is already registered, skipping`), t.emit("register:duplicate", Q("register:duplicate", {
|
|
1560
|
+
taskId: c,
|
|
1561
|
+
kind: "component",
|
|
1562
|
+
injectAt: i,
|
|
1563
|
+
status: t.taskContext.getTaskStatus(c) ?? "idle",
|
|
1564
|
+
artifactName: s
|
|
1565
|
+
})), {
|
|
1566
|
+
taskId: c,
|
|
1567
|
+
isSuccess: !0,
|
|
1568
|
+
isDuplicate: !0
|
|
1569
|
+
};
|
|
1570
|
+
let e = {
|
|
1571
|
+
taskId: c,
|
|
1572
|
+
taskStatus: "idle",
|
|
1573
|
+
kind: "component",
|
|
1574
|
+
artifactName: s,
|
|
1575
|
+
injectAt: i,
|
|
1576
|
+
artifact: a,
|
|
1577
|
+
adapter: g,
|
|
1578
|
+
withEvent: !1,
|
|
1579
|
+
alive: p,
|
|
1580
|
+
scope: m,
|
|
1581
|
+
timeout: h,
|
|
1582
|
+
isObserver: !1,
|
|
1583
|
+
hooks: o?.hooks
|
|
1584
|
+
};
|
|
1585
|
+
if (o?.on) {
|
|
1586
|
+
let t = {
|
|
1587
|
+
listenAt: o.on.listenAt,
|
|
1588
|
+
event: o.on.type,
|
|
1589
|
+
callback: o.on.callback
|
|
1590
|
+
};
|
|
1591
|
+
e.withEvent = !0, o.on.activitySignal && (t.activitySignal = o.on.activitySignal), e.listener = t;
|
|
1592
|
+
}
|
|
1593
|
+
return t.config.observer && o?.hooks && l(t.config.observer, o.hooks, c), t.taskContext.set(c, e), t.taskContext.taskRecords.push({
|
|
1594
|
+
taskId: c,
|
|
1595
|
+
injectAt: i
|
|
1596
|
+
}), t.logger.info(`Task "${c}" registered`), t.emit("register:success", Q("register:success", {
|
|
1597
|
+
taskId: c,
|
|
1598
|
+
kind: "component",
|
|
1599
|
+
injectAt: i,
|
|
1600
|
+
status: "idle",
|
|
1601
|
+
artifactName: s,
|
|
1602
|
+
listenerEvent: d,
|
|
1603
|
+
listenAt: f,
|
|
1604
|
+
alive: p,
|
|
1605
|
+
scope: m,
|
|
1606
|
+
timeout: h,
|
|
1607
|
+
withEvent: u
|
|
1608
|
+
})), {
|
|
1609
|
+
taskId: c,
|
|
1610
|
+
isSuccess: !0
|
|
1611
|
+
};
|
|
1612
|
+
} catch (e) {
|
|
1613
|
+
return t.emit("register:error", Q("register:error", {
|
|
1614
|
+
taskId: c,
|
|
1615
|
+
kind: "component",
|
|
1616
|
+
injectAt: i,
|
|
1617
|
+
status: t.taskContext.getTaskStatus(c) ?? "idle",
|
|
1618
|
+
error: e,
|
|
1619
|
+
artifactName: s
|
|
1620
|
+
})), {
|
|
1621
|
+
taskId: c,
|
|
1622
|
+
isSuccess: !1
|
|
1623
|
+
};
|
|
1626
1624
|
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1625
|
+
}
|
|
1626
|
+
//#endregion
|
|
1627
|
+
//#region packages/core/src/Makoo/createMakoo.ts
|
|
1628
|
+
function be(e = {}) {
|
|
1629
|
+
let t = fe(e);
|
|
1630
|
+
return {
|
|
1631
|
+
start(e) {
|
|
1632
|
+
e.length === 0 && H(t, []);
|
|
1633
|
+
let n = Se(t, e);
|
|
1634
|
+
return n.length > 0 && H(t, n.map((e) => e.taskId)), Ce(t, n);
|
|
1635
|
+
},
|
|
1636
|
+
reset: (e) => X(t, e),
|
|
1637
|
+
destroy: (e) => Y(t, e),
|
|
1638
|
+
resetAll: () => ue(t),
|
|
1639
|
+
destroyAll: () => le(t),
|
|
1640
|
+
enableAlive: (e) => q(t, e),
|
|
1641
|
+
disableAlive: (e) => J(t, e),
|
|
1642
|
+
on: (e, n) => t.config.observer?.on(e, n) ?? (() => {}),
|
|
1643
|
+
onTask: (e, n, r) => t.config.observer?.onTask(e, n, r) ?? (() => {}),
|
|
1644
|
+
onAny: (e) => t.config.observer?.onAny(e) ?? (() => {}),
|
|
1645
|
+
off: (e, n) => t.config.observer?.off(e, n),
|
|
1646
|
+
offTask: (e, n, r) => t.config.observer?.offTask(e, n, r),
|
|
1647
|
+
offAny: (e) => t.config.observer?.offAny(e),
|
|
1648
|
+
getLogger: () => t.logger
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
function $(e, t, n) {
|
|
1652
|
+
return {
|
|
1653
|
+
kind: "component",
|
|
1654
|
+
injectAt: e,
|
|
1655
|
+
artifact: t,
|
|
1656
|
+
...n ? { options: n } : {}
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1659
|
+
function xe(e, t, n, r = {}) {
|
|
1660
|
+
return {
|
|
1661
|
+
kind: "listener",
|
|
1662
|
+
listenAt: e,
|
|
1663
|
+
event: t,
|
|
1664
|
+
type: t,
|
|
1665
|
+
callback: n,
|
|
1666
|
+
...r.activitySignal ? { activitySignal: r.activitySignal } : {}
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
function Se(e, t) {
|
|
1670
|
+
let n = [];
|
|
1671
|
+
for (let r of t) {
|
|
1672
|
+
if (r.kind === "component") {
|
|
1673
|
+
let t = ye(e, {
|
|
1674
|
+
injectAt: r.injectAt,
|
|
1675
|
+
artifact: r.artifact,
|
|
1676
|
+
...r.options ? { options: r.options } : {}
|
|
1677
|
+
});
|
|
1678
|
+
t.isSuccess && !t.isDuplicate && n.push(we(e, t.taskId));
|
|
1679
|
+
continue;
|
|
1680
|
+
}
|
|
1681
|
+
let t = ve(e, r);
|
|
1682
|
+
t.isSuccess && !t.isDuplicate && n.push(Te(e, t.taskId));
|
|
1629
1683
|
}
|
|
1630
|
-
|
|
1684
|
+
return n;
|
|
1685
|
+
}
|
|
1686
|
+
function Ce(e, t) {
|
|
1687
|
+
let n = new Map(t.map((e) => [e.taskId, e]));
|
|
1688
|
+
return {
|
|
1689
|
+
tasks: t,
|
|
1690
|
+
get(t) {
|
|
1691
|
+
return e.taskContext.has(t) ? n.get(t) : void 0;
|
|
1692
|
+
},
|
|
1693
|
+
resetAll() {
|
|
1694
|
+
for (let n of t) e.taskContext.has(n.taskId) && X(e, n.taskId);
|
|
1695
|
+
},
|
|
1696
|
+
destroyAll() {
|
|
1697
|
+
for (let n of t) e.taskContext.has(n.taskId) && Y(e, n.taskId);
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
}
|
|
1701
|
+
function we(e, t) {
|
|
1702
|
+
return {
|
|
1703
|
+
kind: "component",
|
|
1704
|
+
taskId: t,
|
|
1705
|
+
enableAlive: () => q(e, t),
|
|
1706
|
+
disableAlive: () => J(e, t),
|
|
1707
|
+
reset: () => X(e, t),
|
|
1708
|
+
destroy: () => Y(e, t)
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1711
|
+
function Te(e, t) {
|
|
1712
|
+
return {
|
|
1713
|
+
kind: "listener",
|
|
1714
|
+
taskId: t,
|
|
1715
|
+
open: () => G(e, t, F.OPEN),
|
|
1716
|
+
close: () => G(e, t, F.CLOSE),
|
|
1717
|
+
destroy: () => Y(e, t)
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1631
1720
|
//#endregion
|
|
1632
|
-
export {
|
|
1721
|
+
export { F as Action, r as AdapterError, N as DOMWatcher, e as ErrorCode, o as Logger, n as MakooError, f as OBSERVE_EVENT_NAMES, i as SignalError, a as TaskError, x as createActivityStore, be as createMakoo, d as createObserverHub, $ as inject, xe as listen };
|