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