@zenbujs/core 0.0.3 → 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.
Files changed (89) hide show
  1. package/dist/{advice-config-CjgkEf2E.mjs → advice-config-QYB2qEd_.mjs} +32 -14
  2. package/dist/advice.mjs +1 -1
  3. package/dist/{base-window-BUt8pwbw.mjs → base-window-BbFRRhKP.mjs} +9 -4
  4. package/dist/{build-config-pbv0w4oN.mjs → build-config-C3a-o3_B.mjs} +8 -2
  5. package/dist/{build-electron-BzHa_hRi.mjs → build-electron-CNJ0dLND.mjs} +12 -6
  6. package/dist/{build-source-CnTfQBGK.mjs → build-source-C2puqEVr.mjs} +13 -8
  7. package/dist/chunk-DsiFFCwN.mjs +16 -0
  8. package/dist/cli/bin.mjs +12 -15
  9. package/dist/cli/build.d.mts +1 -52
  10. package/dist/cli/build.mjs +2 -47
  11. package/dist/cli/resolve-config.mjs +37 -0
  12. package/dist/{cli-BLbQQIVB.mjs → cli-C3R1LBMY.mjs} +5 -5
  13. package/dist/{config-CdVrW85P.mjs → config-DXRCDUxG.mjs} +1 -1
  14. package/dist/config.d.mts +3 -0
  15. package/dist/config.mjs +4 -0
  16. package/dist/{db-BXadETOb.mjs → db-xjvahRFJ.mjs} +47 -41
  17. package/dist/db.d.mts +1 -1
  18. package/dist/db.mjs +2 -2
  19. package/dist/env-bootstrap.d.mts +1 -1
  20. package/dist/env-bootstrap.mjs +52 -1
  21. package/dist/index-ClXLQ1fw.d.mts +1 -0
  22. package/dist/index.d.mts +5 -5
  23. package/dist/index.mjs +4 -4
  24. package/dist/{link-VOoGs-pY.mjs → link-c0_aLWQ3.mjs} +87 -120
  25. package/dist/load-config-xMf2wxH8.mjs +141 -0
  26. package/dist/loaders/zenbu.d.mts +17 -0
  27. package/dist/loaders/zenbu.mjs +144 -135
  28. package/dist/{monorepo-CQeQBIpa.mjs → monorepo-3avKJwzJ.mjs} +5 -2
  29. package/dist/node-loader.mjs +1 -1
  30. package/dist/{publish-source-BJdpDAFH.mjs → publish-source-Dill72NS.mjs} +12 -6
  31. package/dist/react.d.mts +3 -3
  32. package/dist/react.mjs +2 -2
  33. package/dist/{registry-Dh_e7HU1.d.mts → registry-eX6e2oql.d.mts} +1 -1
  34. package/dist/registry.d.mts +1 -1
  35. package/dist/{reloader-lLAJ3lqg.mjs → reloader-DzEO8kJr.mjs} +6 -4
  36. package/dist/{renderer-host-Bg8QdeeH.mjs → renderer-host-Cau9JK0v.mjs} +90 -212
  37. package/dist/{rpc-BwwQK6hD.mjs → rpc-JfGv-Wuw.mjs} +7 -5
  38. package/dist/rpc.d.mts +1 -1
  39. package/dist/rpc.mjs +1 -1
  40. package/dist/{runtime-CjqDr8Yf.d.mts → runtime-pCeVzj--.d.mts} +73 -1
  41. package/dist/runtime.d.mts +2 -2
  42. package/dist/runtime.mjs +522 -2
  43. package/dist/{schema-DMoSkwUx.d.mts → schema-Dl85YjXW.d.mts} +1 -1
  44. package/dist/schema.d.mts +1 -1
  45. package/dist/schema.mjs +27 -1
  46. package/dist/{server-BXwZEQ-n.mjs → server-y3PPbh3l.mjs} +5 -3
  47. package/dist/services/default.mjs +10 -10
  48. package/dist/services/index.d.mts +8 -4
  49. package/dist/services/index.mjs +6 -6
  50. package/dist/setup-gate.d.mts +1 -1
  51. package/dist/setup-gate.mjs +248 -1
  52. package/dist/{transform-DJH3vN4b.mjs → transform-CmFYPmt8.mjs} +1 -1
  53. package/dist/transforms-CuTODvDx.d.mts +145 -0
  54. package/dist/transforms-htxfTwsY.mjs +47 -0
  55. package/dist/{transport-BMSzG2-F.mjs → transport-F2hv_OEm.mjs} +1 -1
  56. package/dist/{vite-plugins-Bh3SCOw-.mjs → vite-plugins-Do7liKi_.mjs} +5 -19
  57. package/dist/vite.mjs +1 -1
  58. package/dist/{window-CmmpCVX6.mjs → window-o2NGUsIb.mjs} +10 -7
  59. package/dist/{write-9dRFczGJ.mjs → write-DgIRjo23.mjs} +1 -1
  60. package/package.json +11 -10
  61. package/dist/advice-config-Cy133IQP.mjs +0 -2
  62. package/dist/base-window-DEIAk618.mjs +0 -2
  63. package/dist/chunk-Dm34NbLt.mjs +0 -6
  64. package/dist/config-LK73dJmO.mjs +0 -2
  65. package/dist/db-ByKPbnP6.mjs +0 -2
  66. package/dist/env-bootstrap-rj7I-59x.mjs +0 -53
  67. package/dist/http-IBcLzbYu.mjs +0 -2
  68. package/dist/load-build-config-DozuRhAN.mjs +0 -40
  69. package/dist/reloader-BCkLjDhS.mjs +0 -2
  70. package/dist/renderer-host-DpvBPTHJ.mjs +0 -2
  71. package/dist/rpc-CqitnyR4.mjs +0 -2
  72. package/dist/runtime-DUFKDIe4.mjs +0 -409
  73. package/dist/schema-dGK6qkfR.mjs +0 -28
  74. package/dist/server-DjrZUbbu.mjs +0 -2
  75. package/dist/setup-gate-BcoqWu8S.mjs +0 -110
  76. package/dist/view-registry-BualWgAf.mjs +0 -2
  77. package/dist/window-CM2a9Kyc.mjs +0 -2
  78. package/dist/{index-FtE8MXJ_.d.mts → cli/resolve-config.d.mts} +0 -0
  79. package/dist/{dev-BU_llQh1.mjs → dev-Dazhu66l.mjs} +0 -0
  80. package/dist/{env-bootstrap-BtVME-CU.d.mts → env-bootstrap-DW2hVhSO.d.mts} +0 -0
  81. package/dist/{index-Bhlbyrn7.d.mts → index-C-ALz_SH.d.mts} +0 -0
  82. package/dist/{index-CPZ5d6Hl.d.mts → index-M_lSNBrq.d.mts} +0 -0
  83. package/dist/{log-CyKv8hQg.mjs → log-6rzaCV0I.mjs} +0 -0
  84. package/dist/{mirror-sync-BN59kMCG.mjs → mirror-sync-PDzxhf1w.mjs} +1 -1
  85. /package/dist/{node-D4M19_mV.mjs → node-_8xShqxr.mjs} +0 -0
  86. /package/dist/{schema-CIg4GzHQ.mjs → schema-Ca7SxXgS.mjs} +0 -0
  87. /package/dist/{setup-gate-BqOzm7zp.d.mts → setup-gate-Dcy8gGPJ.d.mts} +0 -0
  88. /package/dist/{src-pELM4_iH.mjs → src-Cven45mq.mjs} +0 -0
  89. /package/dist/{trace-DCB7qFzT.mjs → trace-BaVg0rnY.mjs} +0 -0
package/dist/runtime.mjs CHANGED
@@ -1,2 +1,522 @@
1
- import { a as serviceWithDeps, i as runtime, n as ServiceRuntime, r as optional, t as Service } from "./runtime-DUFKDIe4.mjs";
2
- export { Service, ServiceRuntime, optional, runtime, serviceWithDeps };
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
+ splashPath: null,
417
+ subscribers: /* @__PURE__ */ new Set()
418
+ };
419
+ else if (!slot.__zenbu_plugin_registry__.subscribers) slot.__zenbu_plugin_registry__.subscribers = /* @__PURE__ */ new Set();
420
+ return slot.__zenbu_plugin_registry__;
421
+ }
422
+ function snapshotConfig(reg) {
423
+ return {
424
+ plugins: [...reg.plugins.values()],
425
+ appEntrypoint: reg.appEntrypoint,
426
+ splashPath: reg.splashPath
427
+ };
428
+ }
429
+ function notifySubscribers(reg) {
430
+ if (reg.subscribers.size === 0) return;
431
+ const snapshot = snapshotConfig(reg);
432
+ for (const cb of reg.subscribers) try {
433
+ cb(snapshot);
434
+ } catch (err) {
435
+ console.error("[zenbu config subscriber] threw:", err);
436
+ }
437
+ }
438
+ /**
439
+ * Register a plugin's resolved manifest. Idempotent — replaces any existing
440
+ * entry for the same `name`. Called by the loader-emitted barrel; user code
441
+ * normally does not call this directly.
442
+ */
443
+ function registerPlugin(record) {
444
+ const reg = getPluginRegistry();
445
+ reg.plugins.set(record.name, record);
446
+ notifySubscribers(reg);
447
+ }
448
+ /**
449
+ * Drop a plugin from the registry. Used when the loader regenerates the
450
+ * barrel and needs to clear stale entries.
451
+ */
452
+ function unregisterPlugin(name) {
453
+ const reg = getPluginRegistry();
454
+ if (!reg.plugins.delete(name)) return;
455
+ notifySubscribers(reg);
456
+ }
457
+ /**
458
+ * Replace the entire plugin set in one shot. The loader uses this on every
459
+ * barrel regeneration so removed plugins disappear cleanly.
460
+ */
461
+ function replacePlugins(records) {
462
+ const reg = getPluginRegistry();
463
+ reg.plugins.clear();
464
+ for (const record of records) reg.plugins.set(record.name, record);
465
+ notifySubscribers(reg);
466
+ }
467
+ function getPlugins() {
468
+ return [...getPluginRegistry().plugins.values()];
469
+ }
470
+ function getPlugin(name) {
471
+ return getPluginRegistry().plugins.get(name);
472
+ }
473
+ /**
474
+ * Set the renderer entrypoint directory + the absolute path to splash.html
475
+ * inside it. Called once by the loader-emitted barrel. Consumers
476
+ * (`view-registry`, `vite-plugins`, `setup-gate`'s splash window) read
477
+ * via `getAppEntrypoint()` / `getSplashPath()`.
478
+ */
479
+ function registerAppEntrypoint(rendererDir, splashPath) {
480
+ const reg = getPluginRegistry();
481
+ reg.appEntrypoint = rendererDir;
482
+ reg.splashPath = splashPath;
483
+ notifySubscribers(reg);
484
+ }
485
+ function getAppEntrypoint() {
486
+ return getPluginRegistry().appEntrypoint;
487
+ }
488
+ function getSplashPath() {
489
+ return getPluginRegistry().splashPath;
490
+ }
491
+ /**
492
+ * Snapshot of the current resolved config — plugins + entrypoints. Cheap;
493
+ * just walks the in-memory registry. The returned object is a fresh copy,
494
+ * safe to retain or pass through serialization boundaries.
495
+ */
496
+ function getConfig() {
497
+ return snapshotConfig(getPluginRegistry());
498
+ }
499
+ /**
500
+ * Subscribe to config changes. The callback fires:
501
+ * - immediately on subscription (with the current snapshot),
502
+ * - after each `replacePlugins(...)` / `registerPlugin(...)` /
503
+ * `registerAppEntrypoint(...)` call — i.e. every time the loader
504
+ * regenerates the plugin barrel after a `zenbu.config.ts` edit.
505
+ *
506
+ * Callback exceptions are logged and swallowed so one buggy subscriber
507
+ * can't break others. The returned function unsubscribes.
508
+ */
509
+ function subscribeConfig(callback) {
510
+ const reg = getPluginRegistry();
511
+ reg.subscribers.add(callback);
512
+ try {
513
+ callback(snapshotConfig(reg));
514
+ } catch (err) {
515
+ console.error("[zenbu config subscriber] initial fire threw:", err);
516
+ }
517
+ return () => {
518
+ reg.subscribers.delete(callback);
519
+ };
520
+ }
521
+ //#endregion
522
+ export { Service, ServiceRuntime, getAppEntrypoint, getConfig, getPlugin, getPlugins, getSplashPath, optional, registerAppEntrypoint, registerPlugin, replacePlugins, runtime, serviceWithDeps, subscribeConfig, unregisterPlugin };
@@ -1,4 +1,4 @@
1
- import { m as Field, v as Schema } from "./index-CPZ5d6Hl.mjs";
1
+ import { m as Field, v as Schema } from "./index-M_lSNBrq.mjs";
2
2
  import zod from "zod";
3
3
 
4
4
  //#region src/schema.d.ts
package/dist/schema.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as WindowPrefs, i as WindowBounds, n as SchemaRoot, o as schema, r as ViewRegistryEntry, t as CoreSchema } from "./schema-DMoSkwUx.mjs";
1
+ import { a as WindowPrefs, i as WindowBounds, n as SchemaRoot, o as schema, r as ViewRegistryEntry, t as CoreSchema } from "./schema-Dl85YjXW.mjs";
2
2
  export { CoreSchema, SchemaRoot, ViewRegistryEntry, WindowBounds, WindowPrefs, schema };
package/dist/schema.mjs CHANGED
@@ -1,2 +1,28 @@
1
- import { t as schema } from "./schema-dGK6qkfR.mjs";
1
+ import { a as f, i as createSchema } from "./schema-Ca7SxXgS.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
2
28
  export { schema };
@@ -1,9 +1,11 @@
1
- import { i as runtime, t as Service } from "./runtime-DUFKDIe4.mjs";
2
- import { t as createLogger } from "./log-CyKv8hQg.mjs";
1
+ import { n as __exportAll } from "./chunk-DsiFFCwN.mjs";
2
+ import { Service, runtime } from "./runtime.mjs";
3
+ import { t as createLogger } from "./log-6rzaCV0I.mjs";
3
4
  import http from "node:http";
4
5
  import { randomBytes, timingSafeEqual } from "node:crypto";
5
6
  import { WebSocketServer } from "ws";
6
7
  //#region src/services/server.ts
8
+ var server_exports = /* @__PURE__ */ __exportAll({ ServerService: () => ServerService });
7
9
  const log = createLogger("server");
8
10
  var ServerService = class extends Service {
9
11
  static key = "server";
@@ -63,4 +65,4 @@ var ServerService = class extends Service {
63
65
  };
64
66
  runtime.register(ServerService, import.meta);
65
67
  //#endregion
66
- export { ServerService as t };
68
+ export { server_exports as n, ServerService as t };
@@ -7,16 +7,16 @@
7
7
  * chance to bootstrap env vars and `process.chdir(projectRoot)`.
8
8
  */
9
9
  async function defaultServices() {
10
- await import("../server-DjrZUbbu.mjs");
11
- await import("../reloader-BCkLjDhS.mjs");
12
- await import("../renderer-host-DpvBPTHJ.mjs");
13
- await import("../http-IBcLzbYu.mjs");
14
- await import("../db-ByKPbnP6.mjs");
15
- await import("../base-window-DEIAk618.mjs");
16
- await import("../rpc-CqitnyR4.mjs");
17
- await import("../view-registry-BualWgAf.mjs");
18
- await import("../window-CM2a9Kyc.mjs");
19
- await import("../advice-config-Cy133IQP.mjs");
10
+ await import("../server-y3PPbh3l.mjs").then((n) => n.n);
11
+ await import("../reloader-DzEO8kJr.mjs").then((n) => n.n);
12
+ await import("../renderer-host-Cau9JK0v.mjs").then((n) => n.n);
13
+ await import("../renderer-host-Cau9JK0v.mjs").then((n) => n.c);
14
+ await import("../renderer-host-Cau9JK0v.mjs").then((n) => n.o);
15
+ await import("../base-window-BbFRRhKP.mjs").then((n) => n.r);
16
+ await import("../rpc-JfGv-Wuw.mjs").then((n) => n.n);
17
+ await import("../renderer-host-Cau9JK0v.mjs").then((n) => n.i);
18
+ await import("../window-o2NGUsIb.mjs").then((n) => n.n);
19
+ await import("../advice-config-QYB2qEd_.mjs").then((n) => n.t);
20
20
  }
21
21
  //#endregion
22
22
  export { defaultServices };
@@ -1,11 +1,11 @@
1
- import { c as EffectFieldNode, d as KyjuError, l as FieldNode, r as createRouter, t as Db } from "../index-CPZ5d6Hl.mjs";
2
- import { n as Service, t as CleanupReason } from "../runtime-CjqDr8Yf.mjs";
3
- import { o as ResolvedDbRoot, s as ResolvedEvents } from "../registry-Dh_e7HU1.mjs";
1
+ import { i as Service, t as CleanupReason } from "../runtime-pCeVzj--.mjs";
2
+ import { c as EffectFieldNode, d as KyjuError, l as FieldNode, r as createRouter, t as Db } from "../index-M_lSNBrq.mjs";
3
+ import { o as ResolvedDbRoot, s as ResolvedEvents } from "../registry-eX6e2oql.mjs";
4
4
  import http from "node:http";
5
5
  import { WebSocket, WebSocketServer } from "ws";
6
6
  import { ViteDevServer } from "vite";
7
7
  import * as Effect from "effect/Effect";
8
- import { BaseWindow } from "electron";
8
+ import { BaseWindow, WebPreferences } from "electron";
9
9
  import * as _$stream from "stream";
10
10
 
11
11
  //#region src/services/server.d.ts
@@ -260,6 +260,10 @@ declare class WindowService extends WindowService_base {
260
260
  scope: string;
261
261
  windowId?: string;
262
262
  query?: Record<string, string | number | boolean | null | undefined>;
263
+ view?: {
264
+ backgroundColor?: string;
265
+ webPreferences?: WebPreferences;
266
+ };
263
267
  }): Promise<{
264
268
  windowId: string;
265
269
  }>;
@@ -1,7 +1,7 @@
1
- import { t as ServerService } from "../server-BXwZEQ-n.mjs";
2
- import { t as ReloaderService } from "../reloader-lLAJ3lqg.mjs";
3
- import { n as ViewRegistryService, o as HttpService, r as DbService, t as RendererHostService } from "../renderer-host-Bg8QdeeH.mjs";
4
- import { n as MAIN_WINDOW_ID, t as BaseWindowService } from "../base-window-BUt8pwbw.mjs";
5
- import { t as RpcService } from "../rpc-BwwQK6hD.mjs";
6
- import { t as WindowService } from "../window-CmmpCVX6.mjs";
1
+ import { t as ServerService } from "../server-y3PPbh3l.mjs";
2
+ import { t as ReloaderService } from "../reloader-DzEO8kJr.mjs";
3
+ import { a as DbService, r as ViewRegistryService, s as HttpService, t as RendererHostService } from "../renderer-host-Cau9JK0v.mjs";
4
+ import { n as MAIN_WINDOW_ID, t as BaseWindowService } from "../base-window-BbFRRhKP.mjs";
5
+ import { t as RpcService } from "../rpc-JfGv-Wuw.mjs";
6
+ import { t as WindowService } from "../window-o2NGUsIb.mjs";
7
7
  export { BaseWindowService, DbService, HttpService, MAIN_WINDOW_ID, ReloaderService, RendererHostService, RpcService, ServerService, ViewRegistryService, WindowService };
@@ -1,2 +1,2 @@
1
- import { t as setupGate } from "./setup-gate-BqOzm7zp.mjs";
1
+ import { t as setupGate } from "./setup-gate-Dcy8gGPJ.mjs";
2
2
  export { setupGate };