@zenbujs/core 0.0.4 → 0.0.5
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/dist/{advice-config-BLXjqjGN.mjs → advice-config-QYB2qEd_.mjs} +12 -2
- package/dist/advice.mjs +1 -1
- package/dist/{base-window-D8CpxMU3.mjs → base-window-BbFRRhKP.mjs} +9 -4
- package/dist/{build-electron-C3Beey84.mjs → build-electron-CNJ0dLND.mjs} +1 -1
- package/dist/{build-source-BvC4bPqH.mjs → build-source-C2puqEVr.mjs} +2 -2
- package/dist/chunk-DsiFFCwN.mjs +16 -0
- package/dist/cli/bin.mjs +7 -7
- package/dist/cli/build.d.mts +1 -1
- package/dist/cli/build.mjs +2 -2
- package/dist/cli/resolve-config.mjs +3 -2
- package/dist/{cli-F0B4dvSg.mjs → cli-C3R1LBMY.mjs} +4 -4
- package/dist/{config-BlRXeUXx.mjs → config-DXRCDUxG.mjs} +1 -1
- package/dist/config.d.mts +3 -2
- package/dist/config.mjs +4 -3
- package/dist/{db-Cd5ETuPG.mjs → db-xjvahRFJ.mjs} +2 -2
- package/dist/db.d.mts +1 -1
- package/dist/db.mjs +2 -2
- package/dist/env-bootstrap.d.mts +1 -1
- package/dist/env-bootstrap.mjs +52 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +4 -4
- package/dist/{link-BJmsKgPa.mjs → link-c0_aLWQ3.mjs} +1 -1
- package/dist/{load-config-BG2tPIfF.mjs → load-config-xMf2wxH8.mjs} +18 -3
- package/dist/loaders/zenbu.d.mts +1 -0
- package/dist/loaders/zenbu.mjs +7 -87
- package/dist/{monorepo-DCruz9Jx.mjs → monorepo-3avKJwzJ.mjs} +3 -0
- package/dist/node-loader.mjs +1 -1
- package/dist/{publish-source-34Hn9zb0.mjs → publish-source-Dill72NS.mjs} +2 -2
- package/dist/react.d.mts +3 -3
- package/dist/react.mjs +2 -2
- package/dist/{registry-CioEYLI5.d.mts → registry-eX6e2oql.d.mts} +1 -1
- package/dist/registry.d.mts +1 -1
- package/dist/{reloader-DJoCB0bC.mjs → reloader-DzEO8kJr.mjs} +6 -4
- package/dist/{renderer-host-ztaSIOGx.mjs → renderer-host-Cau9JK0v.mjs} +30 -18
- package/dist/{rpc-CsgWnlZx.mjs → rpc-JfGv-Wuw.mjs} +7 -5
- package/dist/rpc.d.mts +1 -1
- package/dist/rpc.mjs +1 -1
- package/dist/{runtime-CsiDppGF.d.mts → runtime-pCeVzj--.d.mts} +37 -5
- package/dist/runtime.d.mts +2 -2
- package/dist/runtime.mjs +522 -2
- package/dist/{schema-DvT61x2_.d.mts → schema-Dl85YjXW.d.mts} +1 -1
- package/dist/schema.d.mts +1 -1
- package/dist/schema.mjs +27 -1
- package/dist/{server-DB3Eki_G.mjs → server-y3PPbh3l.mjs} +5 -3
- package/dist/services/default.mjs +10 -10
- package/dist/services/index.d.mts +8 -4
- package/dist/services/index.mjs +6 -6
- package/dist/setup-gate.d.mts +1 -1
- package/dist/setup-gate.mjs +248 -1
- package/dist/{transform-DJH3vN4b.mjs → transform-CmFYPmt8.mjs} +1 -1
- package/dist/{transforms-EVd5Fgyk.d.mts → transforms-CuTODvDx.d.mts} +10 -1
- package/dist/{transport-BMSzG2-F.mjs → transport-F2hv_OEm.mjs} +1 -1
- package/dist/{vite-plugins-t4MlFcz3.mjs → vite-plugins-Do7liKi_.mjs} +3 -3
- package/dist/vite.mjs +1 -1
- package/dist/{window-DUvMTons.mjs → window-o2NGUsIb.mjs} +10 -7
- package/dist/{write-9dRFczGJ.mjs → write-DgIRjo23.mjs} +1 -1
- package/package.json +4 -4
- package/dist/advice-config-D6K_a7e9.mjs +0 -2
- package/dist/base-window-OXg2KSyP.mjs +0 -2
- package/dist/chunk-Dm34NbLt.mjs +0 -6
- package/dist/config-Ch1FreWU.mjs +0 -2
- package/dist/db-Bz_CDIWg.mjs +0 -2
- package/dist/env-bootstrap-rj7I-59x.mjs +0 -53
- package/dist/http-B36qtsm0.mjs +0 -2
- package/dist/load-config-CQG4297M.mjs +0 -2
- package/dist/reloader-FeHKV2jd.mjs +0 -2
- package/dist/renderer-host-BQpS0ZM2.mjs +0 -2
- package/dist/rpc-D_s7-WZe.mjs +0 -2
- package/dist/runtime-C95iyVn6.mjs +0 -461
- package/dist/schema-dGK6qkfR.mjs +0 -28
- package/dist/server-CgzQOPSW.mjs +0 -2
- package/dist/setup-gate-D8XfYY52.mjs +0 -140
- package/dist/view-registry-2zePxTEg.mjs +0 -2
- package/dist/window-S3TlTXlK.mjs +0 -2
- /package/dist/{build-config-BwnnfrN-.mjs → build-config-C3a-o3_B.mjs} +0 -0
- /package/dist/{dev-DLutFPyo.mjs → dev-Dazhu66l.mjs} +0 -0
- /package/dist/{env-bootstrap-uCKbw2q8.d.mts → env-bootstrap-DW2hVhSO.d.mts} +0 -0
- /package/dist/{index-CE0iPntP.d.mts → index-C-ALz_SH.d.mts} +0 -0
- /package/dist/{index-CKKoxA9V.d.mts → index-ClXLQ1fw.d.mts} +0 -0
- /package/dist/{index-UK58xuoR.d.mts → index-M_lSNBrq.d.mts} +0 -0
- /package/dist/{log-CyKv8hQg.mjs → log-6rzaCV0I.mjs} +0 -0
- /package/dist/{mirror-sync-EiWvdzTJ.mjs → mirror-sync-PDzxhf1w.mjs} +0 -0
- /package/dist/{node-CvZnTx53.mjs → node-_8xShqxr.mjs} +0 -0
- /package/dist/{schema-CIg4GzHQ.mjs → schema-Ca7SxXgS.mjs} +0 -0
- /package/dist/{setup-gate-D62nX5lk.d.mts → setup-gate-Dcy8gGPJ.d.mts} +0 -0
- /package/dist/{src-pELM4_iH.mjs → src-Cven45mq.mjs} +0 -0
- /package/dist/{trace-DCB7qFzT.mjs → trace-BaVg0rnY.mjs} +0 -0
- /package/dist/{transforms-DVoy8dCu.mjs → transforms-htxfTwsY.mjs} +0 -0
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
//#region src/runtime.ts
|
|
2
|
-
function optional(ref) {
|
|
3
|
-
return {
|
|
4
|
-
__optional: true,
|
|
5
|
-
ref
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
function resolveDep(entry) {
|
|
9
|
-
if (typeof entry === "string") return {
|
|
10
|
-
key: entry,
|
|
11
|
-
optional: false
|
|
12
|
-
};
|
|
13
|
-
if (typeof entry === "object" && entry !== null && "__optional" in entry) {
|
|
14
|
-
const ref = entry.ref;
|
|
15
|
-
return {
|
|
16
|
-
key: typeof ref === "string" ? ref : ref.key,
|
|
17
|
-
optional: true
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
key: entry.key,
|
|
22
|
-
optional: false
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
var Service = class {
|
|
26
|
-
static key;
|
|
27
|
-
static deps;
|
|
28
|
-
ctx;
|
|
29
|
-
/** @internal */
|
|
30
|
-
__setupCleanups = /* @__PURE__ */ new Map();
|
|
31
|
-
evaluate() {}
|
|
32
|
-
setup(key, fn) {
|
|
33
|
-
const existing = this.__setupCleanups.get(key);
|
|
34
|
-
if (existing) try {
|
|
35
|
-
existing("reload");
|
|
36
|
-
} catch (e) {
|
|
37
|
-
console.error(`[hot] setup cleanup "${key}" failed:`, e);
|
|
38
|
-
}
|
|
39
|
-
const cleanup = fn();
|
|
40
|
-
if (cleanup) this.__setupCleanups.set(key, cleanup);
|
|
41
|
-
else this.__setupCleanups.delete(key);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Run `fn` and return its result. Historically reported a boot-trace span;
|
|
45
|
-
* now a thin wrapper preserved for caller ergonomics inside service
|
|
46
|
-
* `evaluate()` bodies.
|
|
47
|
-
*/
|
|
48
|
-
trace(_name, fn, _meta) {
|
|
49
|
-
return Promise.resolve(fn());
|
|
50
|
-
}
|
|
51
|
-
traceSync(_name, fn, _meta) {
|
|
52
|
-
return fn();
|
|
53
|
-
}
|
|
54
|
-
/** @internal */
|
|
55
|
-
async __cleanupAllSetups(reason = "shutdown") {
|
|
56
|
-
for (const [key, cleanup] of this.__setupCleanups) try {
|
|
57
|
-
await cleanup(reason);
|
|
58
|
-
} catch (e) {
|
|
59
|
-
console.error(`[hot] setup cleanup "${key}" failed:`, e);
|
|
60
|
-
}
|
|
61
|
-
this.__setupCleanups.clear();
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Declare a Service base class with typed deps. The returned class has
|
|
66
|
-
* `static deps = <your map>` already set, and `this.ctx` is auto-typed
|
|
67
|
-
* from the dep classes — no `declare ctx` needed in the subclass.
|
|
68
|
-
*
|
|
69
|
-
* export class WindowService extends serviceWithDeps({
|
|
70
|
-
* baseWindow: BaseWindowService,
|
|
71
|
-
* http: HttpService,
|
|
72
|
-
* }) {
|
|
73
|
-
* static key = "window"
|
|
74
|
-
* evaluate() {
|
|
75
|
-
* this.ctx.baseWindow // BaseWindowService
|
|
76
|
-
* this.ctx.http // HttpService
|
|
77
|
-
* }
|
|
78
|
-
* }
|
|
79
|
-
*
|
|
80
|
-
* `optional(SomeService)` is supported and produces `Instance | undefined`.
|
|
81
|
-
*/
|
|
82
|
-
function serviceWithDeps(deps) {
|
|
83
|
-
class ServiceWithDeps extends Service {
|
|
84
|
-
static deps = deps;
|
|
85
|
-
}
|
|
86
|
-
return ServiceWithDeps;
|
|
87
|
-
}
|
|
88
|
-
const SERVICE_BASE_METHODS = new Set(Object.getOwnPropertyNames(Service.prototype));
|
|
89
|
-
var ServiceRuntime = class {
|
|
90
|
-
definitions = /* @__PURE__ */ new Map();
|
|
91
|
-
dependentsIndex = /* @__PURE__ */ new Map();
|
|
92
|
-
dirtyKeys = /* @__PURE__ */ new Set();
|
|
93
|
-
drainError = null;
|
|
94
|
-
draining = null;
|
|
95
|
-
registrationTokens = /* @__PURE__ */ new Map();
|
|
96
|
-
slots = /* @__PURE__ */ new Map();
|
|
97
|
-
onReconciledCallbacks = [];
|
|
98
|
-
register(ServiceClass, importMeta) {
|
|
99
|
-
const hot = importMeta?.hot ?? null;
|
|
100
|
-
const baseKey = ServiceClass.key;
|
|
101
|
-
if (!baseKey) throw new Error("Service must have a static key property");
|
|
102
|
-
const slotKey = baseKey;
|
|
103
|
-
this.definitions.set(slotKey, ServiceClass);
|
|
104
|
-
const slot = this.slots.get(slotKey);
|
|
105
|
-
if (slot) slot.ServiceClass = ServiceClass;
|
|
106
|
-
else this.slots.set(slotKey, {
|
|
107
|
-
error: null,
|
|
108
|
-
instance: null,
|
|
109
|
-
ServiceClass,
|
|
110
|
-
status: "blocked"
|
|
111
|
-
});
|
|
112
|
-
this.rebuildDependentsIndex();
|
|
113
|
-
hot?.accept();
|
|
114
|
-
const token = Symbol(slotKey);
|
|
115
|
-
this.registrationTokens.set(slotKey, token);
|
|
116
|
-
hot?.prune?.(() => {
|
|
117
|
-
this.unregister(slotKey, token);
|
|
118
|
-
});
|
|
119
|
-
this.scheduleReconcile([slotKey]);
|
|
120
|
-
}
|
|
121
|
-
getAllKeys() {
|
|
122
|
-
return [...this.slots.keys()];
|
|
123
|
-
}
|
|
124
|
-
getSlot(key) {
|
|
125
|
-
return this.slots.get(key);
|
|
126
|
-
}
|
|
127
|
-
async whenIdle() {
|
|
128
|
-
while (this.draining) await this.draining;
|
|
129
|
-
if (this.drainError) {
|
|
130
|
-
const error = this.drainError;
|
|
131
|
-
this.drainError = null;
|
|
132
|
-
throw error;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
async reloadAll() {
|
|
136
|
-
const keys = [...this.slots.keys()];
|
|
137
|
-
if (keys.length === 0) return;
|
|
138
|
-
await this.scheduleReconcile(keys);
|
|
139
|
-
await this.whenIdle();
|
|
140
|
-
}
|
|
141
|
-
async shutdown() {
|
|
142
|
-
try {
|
|
143
|
-
await this.whenIdle();
|
|
144
|
-
} catch (error) {
|
|
145
|
-
console.error("[hot] runtime idle wait failed during shutdown:", error);
|
|
146
|
-
}
|
|
147
|
-
const keys = [...this.slots.keys()].reverse();
|
|
148
|
-
for (const key of keys) await this.teardownService(key, { removeSlot: true });
|
|
149
|
-
this.definitions.clear();
|
|
150
|
-
this.dependentsIndex.clear();
|
|
151
|
-
this.dirtyKeys.clear();
|
|
152
|
-
this.registrationTokens.clear();
|
|
153
|
-
}
|
|
154
|
-
get(ref) {
|
|
155
|
-
const slot = this.slots.get(ref.key);
|
|
156
|
-
if (!slot || slot.status !== "ready" || !slot.instance) throw new Error(`Service "${ref.key}" not ready. Is it registered and evaluated?`);
|
|
157
|
-
return slot.instance;
|
|
158
|
-
}
|
|
159
|
-
buildRouter() {
|
|
160
|
-
const router = {};
|
|
161
|
-
for (const [slotKey, slot] of this.slots) {
|
|
162
|
-
if (slot.status !== "ready" || !slot.instance) continue;
|
|
163
|
-
const proto = Object.getPrototypeOf(slot.instance);
|
|
164
|
-
const methods = {};
|
|
165
|
-
for (const name of Object.getOwnPropertyNames(proto)) {
|
|
166
|
-
if (SERVICE_BASE_METHODS.has(name)) continue;
|
|
167
|
-
if (name.startsWith("_")) continue;
|
|
168
|
-
const desc = Object.getOwnPropertyDescriptor(proto, name);
|
|
169
|
-
if (!desc || typeof desc.value !== "function") continue;
|
|
170
|
-
const instance = slot.instance;
|
|
171
|
-
methods[name] = (...args) => instance[name](...args);
|
|
172
|
-
}
|
|
173
|
-
if (Object.keys(methods).length > 0) router[slotKey] = methods;
|
|
174
|
-
}
|
|
175
|
-
return router;
|
|
176
|
-
}
|
|
177
|
-
onReconciled(cb) {
|
|
178
|
-
this.onReconciledCallbacks.push(cb);
|
|
179
|
-
return () => {
|
|
180
|
-
const idx = this.onReconciledCallbacks.indexOf(cb);
|
|
181
|
-
if (idx >= 0) this.onReconciledCallbacks.splice(idx, 1);
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
resolveDepSlot(depKey) {
|
|
185
|
-
return this.slots.get(depKey);
|
|
186
|
-
}
|
|
187
|
-
injectCtx(instance, ServiceClass) {
|
|
188
|
-
const deps = ServiceClass.deps ?? {};
|
|
189
|
-
const ctx = {};
|
|
190
|
-
for (const [name, entry] of Object.entries(deps)) {
|
|
191
|
-
const { key, optional: isOptional } = resolveDep(entry);
|
|
192
|
-
const slot = this.resolveDepSlot(key);
|
|
193
|
-
if (!slot || slot.status !== "ready" || !slot.instance) {
|
|
194
|
-
if (isOptional) {
|
|
195
|
-
ctx[name] = void 0;
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
throw new Error(`Dependency "${key}" not ready for "${ServiceClass.key}"`);
|
|
199
|
-
}
|
|
200
|
-
ctx[name] = slot.instance;
|
|
201
|
-
}
|
|
202
|
-
instance.ctx = ctx;
|
|
203
|
-
}
|
|
204
|
-
rebuildDependentsIndex() {
|
|
205
|
-
const next = /* @__PURE__ */ new Map();
|
|
206
|
-
for (const [slotKey, ServiceClass] of this.definitions) {
|
|
207
|
-
const deps = ServiceClass.deps ?? {};
|
|
208
|
-
for (const entry of Object.values(deps)) {
|
|
209
|
-
const { key: depKey } = resolveDep(entry);
|
|
210
|
-
const dependents = next.get(depKey) ?? /* @__PURE__ */ new Set();
|
|
211
|
-
dependents.add(slotKey);
|
|
212
|
-
next.set(depKey, dependents);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
this.dependentsIndex = next;
|
|
216
|
-
}
|
|
217
|
-
getAffectedKeys(changedKeys) {
|
|
218
|
-
const affected = /* @__PURE__ */ new Set();
|
|
219
|
-
const visit = (key) => {
|
|
220
|
-
if (affected.has(key)) return;
|
|
221
|
-
affected.add(key);
|
|
222
|
-
for (const dependent of this.dependentsIndex.get(key) ?? []) visit(dependent);
|
|
223
|
-
};
|
|
224
|
-
for (const key of changedKeys) visit(key);
|
|
225
|
-
return [...affected].filter((key) => this.definitions.has(key));
|
|
226
|
-
}
|
|
227
|
-
listMissingDeps(ServiceClass) {
|
|
228
|
-
const deps = ServiceClass.deps ?? {};
|
|
229
|
-
const missing = [];
|
|
230
|
-
for (const entry of Object.values(deps)) {
|
|
231
|
-
const { key, optional: isOptional } = resolveDep(entry);
|
|
232
|
-
if (isOptional) continue;
|
|
233
|
-
const slot = this.resolveDepSlot(key);
|
|
234
|
-
if (!slot || slot.status !== "ready" || !slot.instance) missing.push(key);
|
|
235
|
-
}
|
|
236
|
-
return missing;
|
|
237
|
-
}
|
|
238
|
-
ensureSlot(key, ServiceClass) {
|
|
239
|
-
const existing = this.slots.get(key);
|
|
240
|
-
if (existing) return existing;
|
|
241
|
-
const slot = {
|
|
242
|
-
error: null,
|
|
243
|
-
instance: null,
|
|
244
|
-
ServiceClass,
|
|
245
|
-
status: "blocked"
|
|
246
|
-
};
|
|
247
|
-
this.slots.set(key, slot);
|
|
248
|
-
return slot;
|
|
249
|
-
}
|
|
250
|
-
async teardownService(key, options = {}) {
|
|
251
|
-
const slot = this.slots.get(key);
|
|
252
|
-
if (!slot) return;
|
|
253
|
-
const instance = slot.instance;
|
|
254
|
-
slot.instance = null;
|
|
255
|
-
slot.status = "blocked";
|
|
256
|
-
slot.error = null;
|
|
257
|
-
if (instance) await instance.__cleanupAllSetups(options.reason ?? "shutdown");
|
|
258
|
-
if (options.removeSlot) this.slots.delete(key);
|
|
259
|
-
}
|
|
260
|
-
async unregister(key, token) {
|
|
261
|
-
if (this.registrationTokens.get(key) !== token) return;
|
|
262
|
-
this.registrationTokens.delete(key);
|
|
263
|
-
this.definitions.delete(key);
|
|
264
|
-
await this.teardownService(key, { removeSlot: true });
|
|
265
|
-
this.rebuildDependentsIndex();
|
|
266
|
-
await this.scheduleReconcile([key]);
|
|
267
|
-
}
|
|
268
|
-
async scheduleReconcile(keys) {
|
|
269
|
-
for (const key of keys) this.dirtyKeys.add(key);
|
|
270
|
-
if (this.draining) return this.draining;
|
|
271
|
-
this.draining = (async () => {
|
|
272
|
-
try {
|
|
273
|
-
while (this.dirtyKeys.size > 0) {
|
|
274
|
-
const batch = [...this.dirtyKeys];
|
|
275
|
-
this.dirtyKeys.clear();
|
|
276
|
-
await this.reconcileBatch(batch);
|
|
277
|
-
}
|
|
278
|
-
} catch (error) {
|
|
279
|
-
this.drainError = error;
|
|
280
|
-
console.error("[hot] runtime reconcile failed:", error);
|
|
281
|
-
} finally {
|
|
282
|
-
this.draining = null;
|
|
283
|
-
if (this.dirtyKeys.size > 0) this.scheduleReconcile([]);
|
|
284
|
-
}
|
|
285
|
-
})();
|
|
286
|
-
return this.draining;
|
|
287
|
-
}
|
|
288
|
-
async reconcileBatch(changedKeys) {
|
|
289
|
-
const affectedKeys = this.getAffectedKeys(changedKeys);
|
|
290
|
-
if (affectedKeys.length === 0) return;
|
|
291
|
-
const affected = /* @__PURE__ */ new Map();
|
|
292
|
-
for (const key of affectedKeys) {
|
|
293
|
-
const ServiceClass = this.definitions.get(key);
|
|
294
|
-
if (ServiceClass) affected.set(key, ServiceClass);
|
|
295
|
-
}
|
|
296
|
-
const levels = this.topologicalLevels(affected);
|
|
297
|
-
for (const level of [...levels].reverse()) await Promise.all(level.map(async (key) => {
|
|
298
|
-
const slot = this.slots.get(key);
|
|
299
|
-
if (slot?.instance) await slot.instance.__cleanupAllSetups("reload");
|
|
300
|
-
}));
|
|
301
|
-
for (const level of levels) await Promise.all(level.map((key) => this.reconcileKey(key)));
|
|
302
|
-
if (affectedKeys.length > 0) for (const cb of this.onReconciledCallbacks) try {
|
|
303
|
-
cb(affectedKeys);
|
|
304
|
-
} catch (e) {
|
|
305
|
-
console.error("[hot] onReconciled callback failed:", e);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
async reconcileKey(key) {
|
|
309
|
-
const ServiceClass = this.definitions.get(key);
|
|
310
|
-
if (!ServiceClass) return;
|
|
311
|
-
const slot = this.ensureSlot(key, ServiceClass);
|
|
312
|
-
slot.ServiceClass = ServiceClass;
|
|
313
|
-
const missingDeps = this.listMissingDeps(ServiceClass);
|
|
314
|
-
if (missingDeps.length > 0) {
|
|
315
|
-
const shouldLog = slot.instance !== null || slot.status !== "blocked";
|
|
316
|
-
await this.teardownService(key, { reason: "reload" });
|
|
317
|
-
if (shouldLog) console.log(`[hot] ${key} waiting on: ${missingDeps.join(", ")}`);
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
let instance = slot.instance;
|
|
321
|
-
if (!instance) {
|
|
322
|
-
instance = new ServiceClass();
|
|
323
|
-
slot.instance = instance;
|
|
324
|
-
} else Object.setPrototypeOf(instance, ServiceClass.prototype);
|
|
325
|
-
slot.status = "evaluating";
|
|
326
|
-
slot.error = null;
|
|
327
|
-
try {
|
|
328
|
-
await instance.__cleanupAllSetups("reload");
|
|
329
|
-
this.injectCtx(instance, ServiceClass);
|
|
330
|
-
await instance.evaluate();
|
|
331
|
-
slot.status = "ready";
|
|
332
|
-
} catch (e) {
|
|
333
|
-
slot.status = "failed";
|
|
334
|
-
slot.error = e;
|
|
335
|
-
console.error(`[hot] ${key} failed to evaluate:`, e);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
topologicalLevels(services) {
|
|
339
|
-
const keys = new Set(services.keys());
|
|
340
|
-
const inDegree = /* @__PURE__ */ new Map();
|
|
341
|
-
const dependents = /* @__PURE__ */ new Map();
|
|
342
|
-
for (const key of keys) {
|
|
343
|
-
inDegree.set(key, 0);
|
|
344
|
-
dependents.set(key, []);
|
|
345
|
-
}
|
|
346
|
-
for (const [slotKey, ServiceClass] of services) {
|
|
347
|
-
const deps = ServiceClass.deps ?? {};
|
|
348
|
-
let degree = 0;
|
|
349
|
-
for (const entry of Object.values(deps)) {
|
|
350
|
-
const { key: depKey, optional: isOptional } = resolveDep(entry);
|
|
351
|
-
if (keys.has(depKey)) {
|
|
352
|
-
degree++;
|
|
353
|
-
dependents.get(depKey).push(slotKey);
|
|
354
|
-
} else if (isOptional) continue;
|
|
355
|
-
}
|
|
356
|
-
inDegree.set(slotKey, degree);
|
|
357
|
-
}
|
|
358
|
-
const levels = [];
|
|
359
|
-
let queue = [...keys].filter((k) => inDegree.get(k) === 0);
|
|
360
|
-
while (queue.length > 0) {
|
|
361
|
-
levels.push(queue);
|
|
362
|
-
const next = [];
|
|
363
|
-
for (const key of queue) for (const dep of dependents.get(key)) {
|
|
364
|
-
const d = inDegree.get(dep) - 1;
|
|
365
|
-
inDegree.set(dep, d);
|
|
366
|
-
if (d === 0) next.push(dep);
|
|
367
|
-
}
|
|
368
|
-
queue = next;
|
|
369
|
-
}
|
|
370
|
-
const resolved = levels.flat();
|
|
371
|
-
if (resolved.length !== keys.size) {
|
|
372
|
-
const missing = [...keys].filter((k) => !resolved.includes(k));
|
|
373
|
-
throw new Error(`Circular dependency detected involving: ${missing.join(", ")}`);
|
|
374
|
-
}
|
|
375
|
-
return levels;
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
/**
|
|
379
|
-
* fixme: i don't think these commments make sense
|
|
380
|
-
*/
|
|
381
|
-
/**
|
|
382
|
-
* Devtools-only handles, attached to the global so they aren't part of the
|
|
383
|
-
* public `ServiceRuntime` autocomplete surface. Same shape React DevTools
|
|
384
|
-
* uses (`__REACT_DEVTOOLS_GLOBAL_HOOK__`): user code reading
|
|
385
|
-
* `runtime.<...>` never lands on these methods; you only find them if you
|
|
386
|
-
* specifically type `globalThis.__zenbu_dev__`. Kept here (next to the
|
|
387
|
-
* runtime that owns the state) because the hook reaches into private
|
|
388
|
-
* implementation details — `scheduleReconcile` stays `private` on the
|
|
389
|
-
* class; the cast lives inside the encapsulation boundary.
|
|
390
|
-
*/
|
|
391
|
-
function installDevHook(rt) {
|
|
392
|
-
const internals = rt;
|
|
393
|
-
globalThis.__zenbu_dev__ = { reloadService: async (key) => {
|
|
394
|
-
if (!internals.definitions.has(key)) throw new Error(`No service registered for key "${key}"`);
|
|
395
|
-
await internals.scheduleReconcile([key]);
|
|
396
|
-
await rt.whenIdle();
|
|
397
|
-
} };
|
|
398
|
-
}
|
|
399
|
-
const runtime = (() => {
|
|
400
|
-
const existing = globalThis.__zenbu_service_runtime__;
|
|
401
|
-
if (existing) {
|
|
402
|
-
Object.setPrototypeOf(existing, ServiceRuntime.prototype);
|
|
403
|
-
installDevHook(existing);
|
|
404
|
-
return existing;
|
|
405
|
-
}
|
|
406
|
-
const fresh = new ServiceRuntime();
|
|
407
|
-
globalThis.__zenbu_service_runtime__ = fresh;
|
|
408
|
-
installDevHook(fresh);
|
|
409
|
-
return fresh;
|
|
410
|
-
})();
|
|
411
|
-
function getPluginRegistry() {
|
|
412
|
-
const slot = globalThis;
|
|
413
|
-
if (!slot.__zenbu_plugin_registry__) slot.__zenbu_plugin_registry__ = {
|
|
414
|
-
plugins: /* @__PURE__ */ new Map(),
|
|
415
|
-
appEntrypoint: null
|
|
416
|
-
};
|
|
417
|
-
return slot.__zenbu_plugin_registry__;
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Register a plugin's resolved manifest. Idempotent — replaces any existing
|
|
421
|
-
* entry for the same `name`. Called by the loader-emitted barrel; user code
|
|
422
|
-
* normally does not call this directly.
|
|
423
|
-
*/
|
|
424
|
-
function registerPlugin(record) {
|
|
425
|
-
getPluginRegistry().plugins.set(record.name, record);
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Drop a plugin from the registry. Used when the loader regenerates the
|
|
429
|
-
* barrel and needs to clear stale entries.
|
|
430
|
-
*/
|
|
431
|
-
function unregisterPlugin(name) {
|
|
432
|
-
getPluginRegistry().plugins.delete(name);
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Replace the entire plugin set in one shot. The loader uses this on every
|
|
436
|
-
* barrel regeneration so removed plugins disappear cleanly.
|
|
437
|
-
*/
|
|
438
|
-
function replacePlugins(records) {
|
|
439
|
-
const reg = getPluginRegistry();
|
|
440
|
-
reg.plugins.clear();
|
|
441
|
-
for (const record of records) reg.plugins.set(record.name, record);
|
|
442
|
-
}
|
|
443
|
-
function getPlugins() {
|
|
444
|
-
return [...getPluginRegistry().plugins.values()];
|
|
445
|
-
}
|
|
446
|
-
function getPlugin(name) {
|
|
447
|
-
return getPluginRegistry().plugins.get(name);
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Set the boot-window HTML path. Called once by the loader-emitted barrel.
|
|
451
|
-
* Consumers (`view-registry`, `vite-plugins`) ask for it via
|
|
452
|
-
* `getAppEntrypoint()`.
|
|
453
|
-
*/
|
|
454
|
-
function registerAppEntrypoint(htmlPath) {
|
|
455
|
-
getPluginRegistry().appEntrypoint = htmlPath;
|
|
456
|
-
}
|
|
457
|
-
function getAppEntrypoint() {
|
|
458
|
-
return getPluginRegistry().appEntrypoint;
|
|
459
|
-
}
|
|
460
|
-
//#endregion
|
|
461
|
-
export { getPlugins as a, registerPlugin as c, serviceWithDeps as d, unregisterPlugin as f, getPlugin as i, replacePlugins as l, ServiceRuntime as n, optional as o, getAppEntrypoint as r, registerAppEntrypoint as s, Service as t, runtime as u };
|
package/dist/schema-dGK6qkfR.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { a as f, i as createSchema } from "./schema-CIg4GzHQ.mjs";
|
|
2
|
-
import zod from "zod";
|
|
3
|
-
//#region src/schema.ts
|
|
4
|
-
const viewRegistryEntrySchema = zod.object({
|
|
5
|
-
scope: zod.string(),
|
|
6
|
-
url: zod.string(),
|
|
7
|
-
port: zod.number(),
|
|
8
|
-
icon: zod.string().optional(),
|
|
9
|
-
meta: zod.object({
|
|
10
|
-
kind: zod.string().optional(),
|
|
11
|
-
sidebar: zod.boolean().optional(),
|
|
12
|
-
bottomPanel: zod.boolean().optional(),
|
|
13
|
-
label: zod.string().optional()
|
|
14
|
-
}).optional()
|
|
15
|
-
});
|
|
16
|
-
const windowBoundsSchema = zod.object({
|
|
17
|
-
x: zod.number(),
|
|
18
|
-
y: zod.number(),
|
|
19
|
-
width: zod.number(),
|
|
20
|
-
height: zod.number()
|
|
21
|
-
});
|
|
22
|
-
const windowPrefsSchema = zod.object({ lastKnownBounds: windowBoundsSchema.optional() });
|
|
23
|
-
const schema = createSchema({
|
|
24
|
-
lastKnownViewRegistry: f.array(viewRegistryEntrySchema).default([]),
|
|
25
|
-
windowPrefs: f.record(zod.string(), windowPrefsSchema).default({})
|
|
26
|
-
});
|
|
27
|
-
//#endregion
|
|
28
|
-
export { schema as t };
|
package/dist/server-CgzQOPSW.mjs
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { t as bootstrapEnv } from "./env-bootstrap-rj7I-59x.mjs";
|
|
2
|
-
import { createRequire, register } from "node:module";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { pathToFileURL } from "node:url";
|
|
7
|
-
import { register as register$1 } from "tsx/esm/api";
|
|
8
|
-
//#region src/setup-gate.ts
|
|
9
|
-
function registerLoader(specifier, opts) {
|
|
10
|
-
return register(specifier, void 0, opts);
|
|
11
|
-
}
|
|
12
|
-
const verbose = process.env.ZENBU_VERBOSE === "1";
|
|
13
|
-
function projectArg() {
|
|
14
|
-
const arg = process.argv.find((item) => item.startsWith("--project="));
|
|
15
|
-
return arg ? path.resolve(arg.slice(10)) : null;
|
|
16
|
-
}
|
|
17
|
-
function appDirName(name) {
|
|
18
|
-
return name.replace(/^@/, "").replace(/[\\/]/g, "__");
|
|
19
|
-
}
|
|
20
|
-
function readPackageJson(packageDir) {
|
|
21
|
-
const pkgPath = path.join(packageDir, "package.json");
|
|
22
|
-
return JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
23
|
-
}
|
|
24
|
-
function findProjectRoot(projectDir) {
|
|
25
|
-
let dir = path.resolve(projectDir);
|
|
26
|
-
while (dir !== path.dirname(dir)) {
|
|
27
|
-
if (fs.existsSync(path.join(dir, "package.json"))) return dir;
|
|
28
|
-
dir = path.dirname(dir);
|
|
29
|
-
}
|
|
30
|
-
return path.resolve(projectDir);
|
|
31
|
-
}
|
|
32
|
-
function resolveConfigPath(projectRoot) {
|
|
33
|
-
const candidates = [
|
|
34
|
-
"zenbu.config.ts",
|
|
35
|
-
"zenbu.config.mts",
|
|
36
|
-
"zenbu.config.js",
|
|
37
|
-
"zenbu.config.mjs"
|
|
38
|
-
];
|
|
39
|
-
for (const name of candidates) {
|
|
40
|
-
const candidate = path.join(projectRoot, name);
|
|
41
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
42
|
-
}
|
|
43
|
-
throw new Error(`No zenbu config found at ${projectRoot}. Expected one of: ${candidates.join(", ")}`);
|
|
44
|
-
}
|
|
45
|
-
function findTsconfig(projectRoot) {
|
|
46
|
-
const candidate = path.join(projectRoot, "tsconfig.json");
|
|
47
|
-
return fs.existsSync(candidate) ? candidate : false;
|
|
48
|
-
}
|
|
49
|
-
function loadElectronApp() {
|
|
50
|
-
const electron = createRequire(import.meta.url)("electron");
|
|
51
|
-
if (!electron.app) throw new Error("Electron app API is unavailable; setup-gate must run inside Electron");
|
|
52
|
-
return electron.app;
|
|
53
|
-
}
|
|
54
|
-
async function closeRegisteredWatchers() {
|
|
55
|
-
await (await import("@zenbujs/hmr/pause")).closeAllWatchers?.();
|
|
56
|
-
}
|
|
57
|
-
async function registerLoaders(tsconfig, projectRoot) {
|
|
58
|
-
register$1({ tsconfig });
|
|
59
|
-
const { loadConfig } = await import("./load-config-CQG4297M.mjs");
|
|
60
|
-
const { resolved, pluginSourceFiles } = await loadConfig(projectRoot);
|
|
61
|
-
const loaderData = {
|
|
62
|
-
payload: {
|
|
63
|
-
plugins: resolved.plugins.map((p) => ({
|
|
64
|
-
name: p.name,
|
|
65
|
-
dir: p.dir,
|
|
66
|
-
services: p.services,
|
|
67
|
-
schemaPath: p.schemaPath,
|
|
68
|
-
migrationsPath: p.migrationsPath,
|
|
69
|
-
preloadPath: p.preloadPath,
|
|
70
|
-
eventsPath: p.eventsPath,
|
|
71
|
-
icons: p.icons
|
|
72
|
-
})),
|
|
73
|
-
appEntrypoint: resolved.uiEntrypointPath
|
|
74
|
-
},
|
|
75
|
-
pluginSourceFiles
|
|
76
|
-
};
|
|
77
|
-
globalThis.__zenbu_main_resolved_config__ = loaderData;
|
|
78
|
-
registerLoader(import.meta.resolve("@zenbujs/core/loaders/zenbu"), { data: loaderData });
|
|
79
|
-
process.env.ZENBU_ADVICE_ROOT = projectRoot;
|
|
80
|
-
await import("./node-CvZnTx53.mjs");
|
|
81
|
-
const dynohot = await import(pathToFileURL(createRequire(import.meta.url).resolve("@zenbujs/hmr/register")).href);
|
|
82
|
-
if (typeof dynohot.register === "function") dynohot.register({ ignore: /[/\\](?:node_modules|dist)[/\\]/ });
|
|
83
|
-
}
|
|
84
|
-
async function setupGate() {
|
|
85
|
-
const app = loadElectronApp();
|
|
86
|
-
await app.whenReady();
|
|
87
|
-
bootstrapEnv();
|
|
88
|
-
const bundledAppPath = app.getAppPath();
|
|
89
|
-
const appName = readPackageJson(bundledAppPath).name ?? path.basename(bundledAppPath);
|
|
90
|
-
const resolvedProjectDir = projectArg() ?? path.join(process.env.ZENBU_APPS_DIR ?? path.join(os.homedir(), ".zenbu", "apps"), appDirName(appName));
|
|
91
|
-
if (!fs.existsSync(resolvedProjectDir)) throw new Error(`setup-gate: project directory ${resolvedProjectDir} does not exist. In a shipped .app, the launcher provisions this dir before invoking setup-gate. In dev, point at an existing project with --project=.`);
|
|
92
|
-
const projectRoot = findProjectRoot(resolvedProjectDir);
|
|
93
|
-
const configPath = resolveConfigPath(projectRoot);
|
|
94
|
-
const tsconfig = findTsconfig(projectRoot);
|
|
95
|
-
process.chdir(projectRoot);
|
|
96
|
-
process.env.ZENBU_CONFIG_PATH = configPath;
|
|
97
|
-
if (!process.argv.some((arg) => arg.startsWith("--project="))) process.argv.push(`--project=${resolvedProjectDir}`);
|
|
98
|
-
if (verbose) {
|
|
99
|
-
console.log("[setup-gate] project:", resolvedProjectDir);
|
|
100
|
-
console.log("[setup-gate] config:", configPath);
|
|
101
|
-
}
|
|
102
|
-
await registerLoaders(tsconfig, projectRoot);
|
|
103
|
-
const { defaultServices } = await import("./services/default.mjs");
|
|
104
|
-
await defaultServices();
|
|
105
|
-
let shuttingDown = false;
|
|
106
|
-
const shutdown = async (exitCode = 0) => {
|
|
107
|
-
if (shuttingDown) return;
|
|
108
|
-
shuttingDown = true;
|
|
109
|
-
try {
|
|
110
|
-
await globalThis.__zenbu_service_runtime__?.shutdown();
|
|
111
|
-
} catch (err) {
|
|
112
|
-
console.error("[setup-gate] shutdown failed:", err);
|
|
113
|
-
}
|
|
114
|
-
try {
|
|
115
|
-
await closeRegisteredWatchers();
|
|
116
|
-
} catch (err) {
|
|
117
|
-
console.error("[setup-gate] closeAllWatchers failed:", err);
|
|
118
|
-
}
|
|
119
|
-
app.exit(exitCode);
|
|
120
|
-
};
|
|
121
|
-
app.on("before-quit", (event) => {
|
|
122
|
-
if (shuttingDown) return;
|
|
123
|
-
event.preventDefault();
|
|
124
|
-
shutdown(0);
|
|
125
|
-
});
|
|
126
|
-
process.on("SIGINT", () => void shutdown(0));
|
|
127
|
-
process.on("SIGTERM", () => void shutdown(0));
|
|
128
|
-
const mod = await import(`zenbu:plugins?config=${encodeURIComponent(configPath)}`, { with: { hot: "import" } });
|
|
129
|
-
if (typeof mod.default === "function") {
|
|
130
|
-
const controller = mod.default();
|
|
131
|
-
if (controller && typeof controller.main === "function") await controller.main();
|
|
132
|
-
}
|
|
133
|
-
await globalThis.__zenbu_service_runtime__?.whenIdle();
|
|
134
|
-
}
|
|
135
|
-
setupGate().catch((error) => {
|
|
136
|
-
console.error(error);
|
|
137
|
-
process.exit(1);
|
|
138
|
-
});
|
|
139
|
-
//#endregion
|
|
140
|
-
export { setupGate as t };
|
package/dist/window-S3TlTXlK.mjs
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|