@zenbujs/core 0.0.4 → 0.0.8
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-DXSIo0sg.mjs} +49 -38
- package/dist/advice.d.mts +8 -8
- package/dist/advice.mjs +2 -2
- package/dist/base-window-BxBZ2md_.mjs +143 -0
- package/dist/build-config-Dzg2frpk.d.mts +215 -0
- package/dist/build-config-pWdmLnrk.mjs +53 -0
- package/dist/{build-electron-C3Beey84.mjs → build-electron-Dsbb1EMl.mjs} +308 -120
- package/dist/{build-source-BvC4bPqH.mjs → build-source-d1J3shV8.mjs} +62 -27
- package/dist/chunk-DsiFFCwN.mjs +16 -0
- package/dist/cli/bin.mjs +7 -7
- package/dist/cli/build.d.mts +2 -2
- package/dist/cli/build.mjs +2 -3
- package/dist/cli/resolve-config.mjs +3 -2
- package/dist/{cli-F0B4dvSg.mjs → cli-kL6mPgBE.mjs} +4 -4
- package/dist/{config-BlRXeUXx.mjs → config-BK78JDRI.mjs} +1 -1
- package/dist/config.d.mts +3 -2
- package/dist/config.mjs +3 -3
- package/dist/{db-Cd5ETuPG.mjs → db-Bc292RYo.mjs} +2 -2
- package/dist/db.d.mts +1 -1
- package/dist/db.mjs +2 -2
- package/dist/dev-B2emj0HZ.mjs +301 -0
- package/dist/env-bootstrap.d.mts +1 -1
- package/dist/env-bootstrap.mjs +52 -1
- package/dist/events.d.mts +19 -0
- package/dist/events.mjs +1 -0
- package/dist/host-version-BIrF8tX7.mjs +65 -0
- package/dist/index-w5QyDjuf.d.mts +780 -0
- package/dist/index.d.mts +5 -6
- package/dist/index.mjs +5 -5
- package/dist/installing-preload.cjs +60 -0
- package/dist/launcher.mjs +2615 -122
- package/dist/{link-BJmsKgPa.mjs → link-glX89NV5.mjs} +215 -89
- package/dist/{load-config-BG2tPIfF.mjs → load-config-C4Oe2qZO.mjs} +22 -3
- package/dist/loaders/zenbu.d.mts +1 -0
- package/dist/loaders/zenbu.mjs +108 -86
- package/dist/{monorepo-DCruz9Jx.mjs → monorepo-Dct-kkbQ.mjs} +3 -0
- package/dist/node-loader.mjs +1 -1
- package/dist/{publish-source-34Hn9zb0.mjs → publish-source-Dq2c0iOw.mjs} +2 -2
- package/dist/react.d.mts +56 -7
- package/dist/react.mjs +118 -7
- package/dist/registry-CMp8FYgS.d.mts +47 -0
- package/dist/registry-generated.d.mts +26 -0
- package/dist/registry-generated.mjs +1 -0
- package/dist/registry.d.mts +2 -2
- package/dist/{reloader-DJoCB0bC.mjs → reloader-B22UiNA2.mjs} +7 -7
- package/dist/{renderer-host-ztaSIOGx.mjs → renderer-host-DD16MXhI.mjs} +178 -57
- package/dist/{rpc-CsgWnlZx.mjs → rpc-C4_NQmpT.mjs} +11 -8
- package/dist/rpc.d.mts +1 -1
- package/dist/rpc.mjs +1 -1
- package/dist/runtime-BQWntcOb.d.mts +218 -0
- package/dist/runtime.d.mts +2 -2
- package/dist/runtime.mjs +578 -2
- package/dist/{schema-DvT61x2_.d.mts → schema-CjrMVk36.d.mts} +3 -3
- package/dist/schema.d.mts +1 -1
- package/dist/schema.mjs +27 -1
- package/dist/{server-DB3Eki_G.mjs → server-CZLMF8Dj.mjs} +6 -6
- package/dist/services/default.d.mts +3 -3
- package/dist/services/default.mjs +14 -13
- package/dist/services/index.d.mts +2 -276
- package/dist/services/index.mjs +8 -7
- package/dist/setup-gate.d.mts +1 -1
- package/dist/setup-gate.mjs +341 -1
- package/dist/{transform-DJH3vN4b.mjs → transform-BzrwkEdf.mjs} +23 -917
- package/dist/{transport-BMSzG2-F.mjs → transport-F2hv_OEm.mjs} +1 -1
- package/dist/updater-DCkz9M1c.mjs +1008 -0
- package/dist/{vite-plugins-t4MlFcz3.mjs → vite-plugins-tt6KAtyE.mjs} +27 -26
- package/dist/vite.d.mts +3 -3
- package/dist/vite.mjs +1 -1
- package/dist/{window-DUvMTons.mjs → window-YFKvAM0l.mjs} +36 -19
- package/dist/{write-9dRFczGJ.mjs → write-DgIRjo23.mjs} +1 -1
- package/package.json +18 -5
- package/dist/advice-config-D6K_a7e9.mjs +0 -2
- package/dist/base-window-D8CpxMU3.mjs +0 -94
- package/dist/base-window-OXg2KSyP.mjs +0 -2
- package/dist/build-config-BwnnfrN-.mjs +0 -23
- package/dist/chunk-Dm34NbLt.mjs +0 -6
- package/dist/config-Ch1FreWU.mjs +0 -2
- package/dist/db-Bz_CDIWg.mjs +0 -2
- package/dist/dev-DLutFPyo.mjs +0 -85
- 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/registry-CioEYLI5.d.mts +0 -61
- 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/runtime-CsiDppGF.d.mts +0 -149
- package/dist/schema-dGK6qkfR.mjs +0 -28
- package/dist/server-CgzQOPSW.mjs +0 -2
- package/dist/setup-gate-D8XfYY52.mjs +0 -140
- package/dist/transforms-DVoy8dCu.mjs +0 -47
- package/dist/transforms-EVd5Fgyk.d.mts +0 -136
- package/dist/view-registry-2zePxTEg.mjs +0 -2
- package/dist/window-S3TlTXlK.mjs +0 -2
- /package/dist/{env-bootstrap-uCKbw2q8.d.mts → env-bootstrap-rTs8KR3-.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-DeDxePAa.d.mts} +0 -0
- /package/dist/{log-CyKv8hQg.mjs → log-6rzaCV0I.mjs} +0 -0
- /package/dist/{mirror-sync-EiWvdzTJ.mjs → mirror-sync-pYU6f3-c.mjs} +0 -0
- /package/dist/{node-CvZnTx53.mjs → node-BhfLKYCi.mjs} +0 -0
- /package/dist/{schema-CIg4GzHQ.mjs → schema-Ca7SxXgS.mjs} +0 -0
- /package/dist/{setup-gate-D62nX5lk.d.mts → setup-gate-BQq0QgZH.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
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { t as
|
|
9
|
-
import {
|
|
1
|
+
import { n as __exportAll } from "./chunk-DsiFFCwN.mjs";
|
|
2
|
+
import { Service, getAppEntrypoint, getPlugins, runtime, subscribeConfig } from "./runtime.mjs";
|
|
3
|
+
import { o as getZodDefault } from "./schema-Ca7SxXgS.mjs";
|
|
4
|
+
import { schema } from "./schema.mjs";
|
|
5
|
+
import { t as createLogger } from "./log-6rzaCV0I.mjs";
|
|
6
|
+
import { t as ServerService } from "./server-CZLMF8Dj.mjs";
|
|
7
|
+
import { i as INTERNAL_DIR, r as DB_CONFIG_JSON, t as ReloaderService } from "./reloader-B22UiNA2.mjs";
|
|
8
|
+
import { a as createBlob, c as makeErrorAck, g as layer$1, h as writeJsonFile, i as cleanupStaleTmpFiles, l as paths, m as validateSession, n as makeRootCache, o as createCollection, p as sendAck, r as broadcastDbUpdate, s as makeAck, t as handleWrite, u as readCollectionItemRange, v as FileSystem } from "./write-DgIRjo23.mjs";
|
|
9
|
+
import { t as traceKyju } from "./trace-BaVg0rnY.mjs";
|
|
10
|
+
import { a as createClient, i as dbStringify, n as createRouter, o as createEffectClient, r as dbParse, s as createReplica } from "./transport-F2hv_OEm.mjs";
|
|
10
11
|
import fs from "node:fs";
|
|
11
12
|
import os from "node:os";
|
|
12
13
|
import path from "node:path";
|
|
@@ -14,6 +15,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
14
15
|
import http from "node:http";
|
|
15
16
|
import fsp from "node:fs/promises";
|
|
16
17
|
import * as Effect from "effect/Effect";
|
|
18
|
+
import { subscribe } from "@parcel/watcher";
|
|
17
19
|
import * as Ref from "effect/Ref";
|
|
18
20
|
import { nanoid } from "nanoid";
|
|
19
21
|
//#region ../../node_modules/.pnpm/@effect+platform-node@0.104.1_@effect+cluster@0.56.4_@effect+platform@0.94.5_effect@3.2_4dd4c94e7ca0ae112861b6965a5da5f4/node_modules/@effect/platform-node/dist/esm/NodeFileSystem.js
|
|
@@ -798,13 +800,15 @@ async function resolveDbPath(argv, app) {
|
|
|
798
800
|
}
|
|
799
801
|
//#endregion
|
|
800
802
|
//#region src/services/http.ts
|
|
803
|
+
var http_exports = /* @__PURE__ */ __exportAll({ HttpService: () => HttpService });
|
|
801
804
|
const log$3 = createLogger("http");
|
|
802
|
-
var HttpService = class extends Service
|
|
803
|
-
|
|
804
|
-
|
|
805
|
+
var HttpService = class extends Service.create({
|
|
806
|
+
key: "http",
|
|
807
|
+
deps: {
|
|
805
808
|
server: ServerService,
|
|
806
809
|
reloader: ReloaderService
|
|
807
|
-
}
|
|
810
|
+
}
|
|
811
|
+
}) {
|
|
808
812
|
connectedCallbacks = [];
|
|
809
813
|
disconnectedCallbacks = [];
|
|
810
814
|
activeConnections = /* @__PURE__ */ new Map();
|
|
@@ -932,6 +936,11 @@ var HttpService = class extends Service {
|
|
|
932
936
|
runtime.register(HttpService, import.meta);
|
|
933
937
|
//#endregion
|
|
934
938
|
//#region src/services/db.ts
|
|
939
|
+
var db_exports = /* @__PURE__ */ __exportAll({
|
|
940
|
+
DbService: () => DbService,
|
|
941
|
+
discoverSections: () => discoverSections,
|
|
942
|
+
resolveManifestModulePath: () => resolveManifestModulePath
|
|
943
|
+
});
|
|
935
944
|
const log$2 = createLogger("db");
|
|
936
945
|
/**
|
|
937
946
|
* Walk up from this file's location until we hit the @zenbujs/core
|
|
@@ -1007,7 +1016,7 @@ function resolveConfigPath() {
|
|
|
1007
1016
|
* loader-emitted barrel before any service evaluates.
|
|
1008
1017
|
*/
|
|
1009
1018
|
async function loadAppDbField(configPath) {
|
|
1010
|
-
const { loadConfig } = await import("./load-config-
|
|
1019
|
+
const { loadConfig } = await import("./load-config-C4Oe2qZO.mjs").then((n) => n.n);
|
|
1011
1020
|
const { resolved } = await loadConfig(path.dirname(configPath));
|
|
1012
1021
|
return resolved.dbPath;
|
|
1013
1022
|
}
|
|
@@ -1097,9 +1106,10 @@ async function discoverSections() {
|
|
|
1097
1106
|
for (const ptm of sorted) log$2.verbose(` ${ptm.name.padEnd(28)} total=${String(ptm.totalMs).padStart(6)} resS=${String(ptm.resolveSchemaMs).padStart(5)} impS=${String(ptm.importSchemaMs).padStart(6)} resM=${String(ptm.resolveMigrationsMs).padStart(5)} impM=${String(ptm.importMigrationsMs).padStart(6)}`);
|
|
1098
1107
|
return sections;
|
|
1099
1108
|
}
|
|
1100
|
-
var DbService = class extends Service
|
|
1101
|
-
|
|
1102
|
-
|
|
1109
|
+
var DbService = class extends Service.create({
|
|
1110
|
+
key: "db",
|
|
1111
|
+
deps: { http: HttpService }
|
|
1112
|
+
}) {
|
|
1103
1113
|
db = null;
|
|
1104
1114
|
dbRouter = null;
|
|
1105
1115
|
sectionsHash = "";
|
|
@@ -1188,6 +1198,110 @@ var DbService = class extends Service {
|
|
|
1188
1198
|
this.setup("kyju-close-on-cleanup", () => async () => {
|
|
1189
1199
|
await this.close();
|
|
1190
1200
|
});
|
|
1201
|
+
this.setup("migrations-watcher", () => {
|
|
1202
|
+
const subs = [];
|
|
1203
|
+
let closed = false;
|
|
1204
|
+
let pendingTimer = null;
|
|
1205
|
+
let inFlight = null;
|
|
1206
|
+
let queued = false;
|
|
1207
|
+
const triggerReload = async () => {
|
|
1208
|
+
if (closed) return;
|
|
1209
|
+
if (inFlight) {
|
|
1210
|
+
queued = true;
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
inFlight = runtime.reload("db").catch((err) => {
|
|
1214
|
+
log$2.error("migrations-watcher reload failed:", err);
|
|
1215
|
+
});
|
|
1216
|
+
try {
|
|
1217
|
+
await inFlight;
|
|
1218
|
+
} finally {
|
|
1219
|
+
inFlight = null;
|
|
1220
|
+
if (queued && !closed) {
|
|
1221
|
+
queued = false;
|
|
1222
|
+
scheduleReload();
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1226
|
+
const scheduleReload = () => {
|
|
1227
|
+
if (closed) return;
|
|
1228
|
+
if (pendingTimer) clearTimeout(pendingTimer);
|
|
1229
|
+
pendingTimer = setTimeout(() => {
|
|
1230
|
+
pendingTimer = null;
|
|
1231
|
+
triggerReload();
|
|
1232
|
+
}, 100);
|
|
1233
|
+
};
|
|
1234
|
+
(async () => {
|
|
1235
|
+
for (const plugin of getPlugins()) {
|
|
1236
|
+
const migPath = plugin.migrationsPath;
|
|
1237
|
+
if (!migPath) continue;
|
|
1238
|
+
let isDir = false;
|
|
1239
|
+
try {
|
|
1240
|
+
isDir = (await fsp.stat(migPath)).isDirectory();
|
|
1241
|
+
} catch {
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
if (!isDir) continue;
|
|
1245
|
+
const journalPath = path.join(migPath, "meta", "_journal.json");
|
|
1246
|
+
try {
|
|
1247
|
+
const sub = await subscribe(migPath, (err, events) => {
|
|
1248
|
+
if (err || closed) return;
|
|
1249
|
+
for (const event of events) {
|
|
1250
|
+
if (event.path === journalPath) {
|
|
1251
|
+
scheduleReload();
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
if (path.dirname(event.path) !== migPath) continue;
|
|
1255
|
+
if (event.type === "update") continue;
|
|
1256
|
+
const ext = path.extname(event.path);
|
|
1257
|
+
if (ext === ".ts" || ext === ".js" || ext === ".mjs") {
|
|
1258
|
+
scheduleReload();
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
if (closed) {
|
|
1264
|
+
await sub.unsubscribe().catch(() => {});
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
subs.push(sub);
|
|
1268
|
+
} catch (err) {
|
|
1269
|
+
log$2.error(`migrations-watcher subscribe failed for ${plugin.name}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
})().catch((err) => {
|
|
1273
|
+
log$2.error("migrations-watcher setup failed:", err);
|
|
1274
|
+
});
|
|
1275
|
+
return async () => {
|
|
1276
|
+
closed = true;
|
|
1277
|
+
if (pendingTimer) {
|
|
1278
|
+
clearTimeout(pendingTimer);
|
|
1279
|
+
pendingTimer = null;
|
|
1280
|
+
}
|
|
1281
|
+
const toClose = subs.splice(0);
|
|
1282
|
+
await Promise.all(toClose.map((s) => s.unsubscribe().catch(() => {})));
|
|
1283
|
+
};
|
|
1284
|
+
});
|
|
1285
|
+
this.setup("plugin-set-watcher", () => {
|
|
1286
|
+
const fingerprint = (snap) => JSON.stringify([...snap.plugins].map((p) => ({
|
|
1287
|
+
name: p.name,
|
|
1288
|
+
schemaPath: p.schemaPath ?? null,
|
|
1289
|
+
migrationsPath: p.migrationsPath ?? null
|
|
1290
|
+
})).sort((a, b) => a.name.localeCompare(b.name)));
|
|
1291
|
+
let lastHash = null;
|
|
1292
|
+
return subscribeConfig((snap) => {
|
|
1293
|
+
const hash = fingerprint(snap);
|
|
1294
|
+
if (lastHash === null) {
|
|
1295
|
+
lastHash = hash;
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
if (hash === lastHash) return;
|
|
1299
|
+
lastHash = hash;
|
|
1300
|
+
runtime.reload("db").catch((err) => {
|
|
1301
|
+
log$2.error("plugin-set-watcher reload failed:", err);
|
|
1302
|
+
});
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1191
1305
|
this.setup("ws-transport", () => {
|
|
1192
1306
|
const onConnected = (id, ws) => {
|
|
1193
1307
|
const dbConn = this.dbRouter.connection({
|
|
@@ -1227,69 +1341,71 @@ var DbService = class extends Service {
|
|
|
1227
1341
|
runtime.register(DbService, import.meta);
|
|
1228
1342
|
//#endregion
|
|
1229
1343
|
//#region src/services/view-registry.ts
|
|
1344
|
+
var view_registry_exports = /* @__PURE__ */ __exportAll({ ViewRegistryService: () => ViewRegistryService });
|
|
1230
1345
|
const log$1 = createLogger("view-registry");
|
|
1231
|
-
var ViewRegistryService = class extends Service
|
|
1232
|
-
|
|
1233
|
-
|
|
1346
|
+
var ViewRegistryService = class extends Service.create({
|
|
1347
|
+
key: "view-registry",
|
|
1348
|
+
deps: {
|
|
1234
1349
|
reloader: ReloaderService,
|
|
1235
1350
|
db: DbService
|
|
1236
|
-
}
|
|
1351
|
+
}
|
|
1352
|
+
}) {
|
|
1237
1353
|
views = /* @__PURE__ */ new Map();
|
|
1238
1354
|
manifestIcons = /* @__PURE__ */ new Map();
|
|
1239
|
-
async register(
|
|
1240
|
-
log$1.verbose(`register("${
|
|
1241
|
-
const existing = this.views.get(
|
|
1355
|
+
async register(type, root, configFile, meta) {
|
|
1356
|
+
log$1.verbose(`register("${type}", root="${root}", config="${configFile}")`);
|
|
1357
|
+
const existing = this.views.get(type);
|
|
1242
1358
|
if (existing) {
|
|
1243
|
-
log$1.verbose(`"${
|
|
1359
|
+
log$1.verbose(`"${type}" already exists at ${existing.url}`);
|
|
1244
1360
|
return existing;
|
|
1245
1361
|
}
|
|
1246
|
-
log$1.verbose(`creating reloader for "${
|
|
1247
|
-
const reloaderEntry = await this.ctx.reloader.create(
|
|
1362
|
+
log$1.verbose(`creating reloader for "${type}"...`);
|
|
1363
|
+
const reloaderEntry = await this.ctx.reloader.create(type, root, configFile);
|
|
1248
1364
|
log$1.verbose(`reloader created: ${reloaderEntry.url} (port ${reloaderEntry.port})`);
|
|
1249
1365
|
const entry = {
|
|
1250
|
-
|
|
1366
|
+
type,
|
|
1251
1367
|
url: reloaderEntry.url,
|
|
1252
1368
|
port: reloaderEntry.port,
|
|
1253
1369
|
ownsServer: true,
|
|
1254
1370
|
meta
|
|
1255
1371
|
};
|
|
1256
|
-
this.views.set(
|
|
1372
|
+
this.views.set(type, entry);
|
|
1257
1373
|
await this.syncToDb();
|
|
1258
|
-
log$1.verbose(`"${
|
|
1374
|
+
log$1.verbose(`"${type}" registered at ${entry.url}`);
|
|
1259
1375
|
return entry;
|
|
1260
1376
|
}
|
|
1261
|
-
registerAlias(
|
|
1262
|
-
const existing = this.views.get(
|
|
1377
|
+
registerAlias(type, reloaderId, pathPrefix, meta) {
|
|
1378
|
+
const existing = this.views.get(type);
|
|
1263
1379
|
if (existing) return existing;
|
|
1264
1380
|
const reloaderEntry = this.ctx.reloader.get(reloaderId);
|
|
1265
|
-
if (!reloaderEntry) throw new Error(`Reloader "${reloaderId}" not found for alias "${
|
|
1381
|
+
if (!reloaderEntry) throw new Error(`Reloader "${reloaderId}" not found for alias "${type}"`);
|
|
1266
1382
|
const entry = {
|
|
1267
|
-
|
|
1383
|
+
type,
|
|
1268
1384
|
url: `${reloaderEntry.url}${pathPrefix}`,
|
|
1269
1385
|
port: reloaderEntry.port,
|
|
1270
1386
|
ownsServer: false,
|
|
1271
1387
|
meta
|
|
1272
1388
|
};
|
|
1273
|
-
this.views.set(
|
|
1389
|
+
this.views.set(type, entry);
|
|
1274
1390
|
this.syncToDb();
|
|
1275
1391
|
return entry;
|
|
1276
1392
|
}
|
|
1277
|
-
async unregister(
|
|
1278
|
-
const entry = this.views.get(
|
|
1393
|
+
async unregister(type) {
|
|
1394
|
+
const entry = this.views.get(type);
|
|
1279
1395
|
if (!entry) return;
|
|
1280
|
-
if (entry.ownsServer) await this.ctx.reloader.remove(
|
|
1281
|
-
this.views.delete(
|
|
1396
|
+
if (entry.ownsServer) await this.ctx.reloader.remove(type);
|
|
1397
|
+
this.views.delete(type);
|
|
1282
1398
|
await this.syncToDb();
|
|
1283
1399
|
}
|
|
1284
|
-
get(
|
|
1285
|
-
return this.views.get(
|
|
1400
|
+
get(type) {
|
|
1401
|
+
return this.views.get(type);
|
|
1286
1402
|
}
|
|
1287
1403
|
evaluate() {
|
|
1288
1404
|
this.loadManifestIcons();
|
|
1289
1405
|
this.syncToDb();
|
|
1290
1406
|
this.setup("view-registry-cleanup", () => {
|
|
1291
1407
|
return async () => {
|
|
1292
|
-
for (const [
|
|
1408
|
+
for (const [type, entry] of this.views) if (entry.ownsServer) await this.ctx.reloader.remove(type);
|
|
1293
1409
|
this.views.clear();
|
|
1294
1410
|
await this.syncToDb();
|
|
1295
1411
|
};
|
|
@@ -1299,16 +1415,16 @@ var ViewRegistryService = class extends Service {
|
|
|
1299
1415
|
this.manifestIcons.clear();
|
|
1300
1416
|
for (const plugin of getPlugins()) {
|
|
1301
1417
|
if (!plugin.icons) continue;
|
|
1302
|
-
for (const [
|
|
1418
|
+
for (const [type, svg] of Object.entries(plugin.icons)) this.manifestIcons.set(type, svg);
|
|
1303
1419
|
}
|
|
1304
1420
|
}
|
|
1305
1421
|
async syncToDb() {
|
|
1306
1422
|
const client = this.ctx.db.effectClient;
|
|
1307
1423
|
const snapshot = [...this.views.values()].map((e) => ({
|
|
1308
|
-
|
|
1424
|
+
type: e.type,
|
|
1309
1425
|
url: e.url,
|
|
1310
1426
|
port: e.port,
|
|
1311
|
-
icon: this.manifestIcons.get(e.
|
|
1427
|
+
icon: this.manifestIcons.get(e.type),
|
|
1312
1428
|
meta: e.meta
|
|
1313
1429
|
}));
|
|
1314
1430
|
await Effect.runPromise(client.update((root) => {
|
|
@@ -1319,6 +1435,10 @@ var ViewRegistryService = class extends Service {
|
|
|
1319
1435
|
runtime.register(ViewRegistryService, import.meta);
|
|
1320
1436
|
//#endregion
|
|
1321
1437
|
//#region src/services/renderer-host.ts
|
|
1438
|
+
var renderer_host_exports = /* @__PURE__ */ __exportAll({
|
|
1439
|
+
APP_RENDERER_RELOADER_ID: () => "app",
|
|
1440
|
+
RendererHostService: () => RendererHostService
|
|
1441
|
+
});
|
|
1322
1442
|
const log = createLogger("renderer-host");
|
|
1323
1443
|
async function pathExists(filePath) {
|
|
1324
1444
|
try {
|
|
@@ -1329,18 +1449,18 @@ async function pathExists(filePath) {
|
|
|
1329
1449
|
}
|
|
1330
1450
|
}
|
|
1331
1451
|
/**
|
|
1332
|
-
* The app's renderer root is the directory
|
|
1333
|
-
*
|
|
1334
|
-
*
|
|
1452
|
+
* The app's renderer root is the `uiEntrypoint` directory in
|
|
1453
|
+
* `zenbu.config.ts`. Vite's `root` resolves to it, and `index.html` inside
|
|
1454
|
+
* it is served through Vite. `splash.html` (sibling) is loaded raw — see
|
|
1455
|
+
* `setup-gate.spawnSplashWindow`.
|
|
1335
1456
|
*
|
|
1336
1457
|
* `vite.config.ts` is picked up from the project root if present (sibling
|
|
1337
1458
|
* of `zenbu.config.ts`).
|
|
1338
1459
|
*/
|
|
1339
1460
|
async function resolveRendererRoot() {
|
|
1340
|
-
const
|
|
1341
|
-
if (!
|
|
1342
|
-
|
|
1343
|
-
if (!await pathExists(rendererRoot)) throw new Error(`[renderer-host] uiEntrypoint references ${entrypoint} but ${rendererRoot} does not exist.`);
|
|
1461
|
+
const rendererRoot = getAppEntrypoint();
|
|
1462
|
+
if (!rendererRoot) throw new Error("[renderer-host] no `uiEntrypoint` registered. Set `uiEntrypoint` in zenbu.config.ts before starting the app.");
|
|
1463
|
+
if (!await pathExists(rendererRoot)) throw new Error(`[renderer-host] uiEntrypoint directory does not exist: ${rendererRoot}.`);
|
|
1344
1464
|
const configPath = process.env.ZENBU_CONFIG_PATH;
|
|
1345
1465
|
const projectDir = configPath ? path.dirname(configPath) : rendererRoot;
|
|
1346
1466
|
const viteConfig = path.join(projectDir, "vite.config.ts");
|
|
@@ -1349,12 +1469,13 @@ async function resolveRendererRoot() {
|
|
|
1349
1469
|
configFile: await pathExists(viteConfig) ? viteConfig : false
|
|
1350
1470
|
};
|
|
1351
1471
|
}
|
|
1352
|
-
var RendererHostService = class extends Service
|
|
1353
|
-
|
|
1354
|
-
|
|
1472
|
+
var RendererHostService = class extends Service.create({
|
|
1473
|
+
key: "renderer-host",
|
|
1474
|
+
deps: {
|
|
1355
1475
|
reloader: ReloaderService,
|
|
1356
1476
|
viewRegistry: ViewRegistryService
|
|
1357
|
-
}
|
|
1477
|
+
}
|
|
1478
|
+
}) {
|
|
1358
1479
|
url = "";
|
|
1359
1480
|
port = 0;
|
|
1360
1481
|
async evaluate() {
|
|
@@ -1371,4 +1492,4 @@ var RendererHostService = class extends Service {
|
|
|
1371
1492
|
};
|
|
1372
1493
|
runtime.register(RendererHostService, import.meta);
|
|
1373
1494
|
//#endregion
|
|
1374
|
-
export {
|
|
1495
|
+
export { DbService as a, http_exports as c, view_registry_exports as i, renderer_host_exports as n, db_exports as o, ViewRegistryService as r, HttpService as s, RendererHostService as t };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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";
|
|
4
|
+
import { s as HttpService } from "./renderer-host-DD16MXhI.mjs";
|
|
5
|
+
import { n as createRpcRouter, r as createServer } from "./src-Cven45mq.mjs";
|
|
5
6
|
//#region src/services/rpc.ts
|
|
7
|
+
var rpc_exports = /* @__PURE__ */ __exportAll({ RpcService: () => RpcService });
|
|
6
8
|
const log = createLogger("rpc");
|
|
7
|
-
var RpcService = class extends Service
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
var RpcService = class extends Service.create({
|
|
10
|
+
key: "rpc",
|
|
11
|
+
deps: { http: HttpService }
|
|
12
|
+
}) {
|
|
10
13
|
_emit = null;
|
|
11
14
|
get emit() {
|
|
12
15
|
if (!this._emit) throw new Error("RpcService not yet evaluated");
|
|
@@ -68,4 +71,4 @@ var RpcService = class extends Service {
|
|
|
68
71
|
};
|
|
69
72
|
runtime.register(RpcService, import.meta);
|
|
70
73
|
//#endregion
|
|
71
|
-
export { RpcService as t };
|
|
74
|
+
export { rpc_exports as n, RpcService as t };
|
package/dist/rpc.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as EventProxy, r as RouterProxy, t as connectRpc } from "./index-
|
|
1
|
+
import { n as EventProxy, r as RouterProxy, t as connectRpc } from "./index-C-ALz_SH.mjs";
|
|
2
2
|
export { type EventProxy, type RouterProxy, connectRpc };
|
package/dist/rpc.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as connectRpc } from "./src-
|
|
1
|
+
import { t as connectRpc } from "./src-Cven45mq.mjs";
|
|
2
2
|
export { connectRpc };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
//#region src/runtime.d.ts
|
|
2
|
+
type CleanupReason = "reload" | "shutdown";
|
|
3
|
+
type SetupCleanup = ((reason: CleanupReason) => void | Promise<void>) | void;
|
|
4
|
+
type SetupFn = () => SetupCleanup;
|
|
5
|
+
interface ServiceSlot {
|
|
6
|
+
error: unknown | null;
|
|
7
|
+
instance: Service | null;
|
|
8
|
+
ServiceClass: ServiceConstructor;
|
|
9
|
+
status: "blocked" | "evaluating" | "ready" | "failed";
|
|
10
|
+
}
|
|
11
|
+
type AnyServiceClass = (abstract new (...args: any[]) => Service) & {
|
|
12
|
+
key: string;
|
|
13
|
+
};
|
|
14
|
+
type DepEntry = AnyServiceClass | string;
|
|
15
|
+
type DepInstance<D> = D extends AnyServiceClass ? InstanceType<D> : unknown;
|
|
16
|
+
type ResolveCtx<TDeps> = { [K in keyof TDeps]: DepInstance<TDeps[K]> };
|
|
17
|
+
/**
|
|
18
|
+
* A concrete service class registered with the runtime. Always has a
|
|
19
|
+
* `static key` (set by `Service.create`) and an optional `static deps`
|
|
20
|
+
* map. Used as the parameter type of `runtime.register`.
|
|
21
|
+
*/
|
|
22
|
+
type ServiceConstructor = (new (...args: any[]) => Service) & {
|
|
23
|
+
key: string;
|
|
24
|
+
deps?: Record<string, DepEntry>;
|
|
25
|
+
};
|
|
26
|
+
declare abstract class Service {
|
|
27
|
+
static deps: Record<string, DepEntry>;
|
|
28
|
+
/**
|
|
29
|
+
* Define a Service base class. The returned abstract class has
|
|
30
|
+
* `static key`, `static deps`, and a typed `this.ctx` already set up;
|
|
31
|
+
* extend it and add your `evaluate()` body.
|
|
32
|
+
*
|
|
33
|
+
* export class WindowService extends Service.create({
|
|
34
|
+
* key: "window",
|
|
35
|
+
* deps: {
|
|
36
|
+
* baseWindow: BaseWindowService,
|
|
37
|
+
* http: HttpService,
|
|
38
|
+
* },
|
|
39
|
+
* }) {
|
|
40
|
+
* evaluate() {
|
|
41
|
+
* this.ctx.baseWindow // BaseWindowService
|
|
42
|
+
* this.ctx.http // HttpService
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* `key` is a required field on the config object, so TypeScript errors
|
|
47
|
+
* if you forget it. `deps` is optional (defaults to no deps).
|
|
48
|
+
*
|
|
49
|
+
* For dynamic / optional access to another service, use
|
|
50
|
+
* `runtime.get(SomeService, cb)` instead of declaring it in `deps`.
|
|
51
|
+
*/
|
|
52
|
+
static create<TKey extends string, TDeps extends Record<string, DepEntry> = {}>(config: {
|
|
53
|
+
key: TKey;
|
|
54
|
+
deps?: TDeps;
|
|
55
|
+
}): (abstract new () => {
|
|
56
|
+
ctx: ResolveCtx<TDeps>; /** @internal */
|
|
57
|
+
__setupCleanups: Map<string, (reason: CleanupReason) => void | Promise<void>>;
|
|
58
|
+
evaluate(): void | Promise<void>;
|
|
59
|
+
setup(key: string, fn: SetupFn): void;
|
|
60
|
+
/**
|
|
61
|
+
* Run `fn` and return its result. Historically reported a boot-trace span;
|
|
62
|
+
* now a thin wrapper preserved for caller ergonomics inside service
|
|
63
|
+
* `evaluate()` bodies.
|
|
64
|
+
*/
|
|
65
|
+
trace<T>(_name: string, fn: () => T | Promise<T>, _meta?: Record<string, unknown>): Promise<T>;
|
|
66
|
+
traceSync<T>(_name: string, fn: () => T, _meta?: Record<string, unknown>): T; /** @internal */
|
|
67
|
+
__cleanupAllSetups(reason?: CleanupReason): Promise<void>;
|
|
68
|
+
}) & {
|
|
69
|
+
key: TKey;
|
|
70
|
+
deps: Record<string, DepEntry>;
|
|
71
|
+
create<TKey extends string, TDeps extends Record<string, DepEntry> = {}>(config: {
|
|
72
|
+
key: TKey;
|
|
73
|
+
deps?: TDeps;
|
|
74
|
+
}): /*elided*/any;
|
|
75
|
+
};
|
|
76
|
+
ctx: any;
|
|
77
|
+
/** @internal */
|
|
78
|
+
__setupCleanups: Map<string, (reason: CleanupReason) => void | Promise<void>>;
|
|
79
|
+
evaluate(): void | Promise<void>;
|
|
80
|
+
setup(key: string, fn: SetupFn): void;
|
|
81
|
+
/**
|
|
82
|
+
* Run `fn` and return its result. Historically reported a boot-trace span;
|
|
83
|
+
* now a thin wrapper preserved for caller ergonomics inside service
|
|
84
|
+
* `evaluate()` bodies.
|
|
85
|
+
*/
|
|
86
|
+
trace<T>(_name: string, fn: () => T | Promise<T>, _meta?: Record<string, unknown>): Promise<T>;
|
|
87
|
+
traceSync<T>(_name: string, fn: () => T, _meta?: Record<string, unknown>): T;
|
|
88
|
+
/** @internal */
|
|
89
|
+
__cleanupAllSetups(reason?: CleanupReason): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
declare class ServiceRuntime {
|
|
92
|
+
private definitions;
|
|
93
|
+
private dependentsIndex;
|
|
94
|
+
private dirtyKeys;
|
|
95
|
+
private drainError;
|
|
96
|
+
private draining;
|
|
97
|
+
private registrationTokens;
|
|
98
|
+
private slots;
|
|
99
|
+
private onReconciledCallbacks;
|
|
100
|
+
private subscribers;
|
|
101
|
+
register(ServiceClass: ServiceConstructor, importMeta?: ImportMeta | null): void;
|
|
102
|
+
getAllKeys(): string[];
|
|
103
|
+
getSlot(key: string): ServiceSlot | undefined;
|
|
104
|
+
whenIdle(): Promise<void>;
|
|
105
|
+
reloadAll(): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Reload a single service by key. No-op if the key is not registered.
|
|
108
|
+
* Used by infrastructure that watches resources outside dynohot's
|
|
109
|
+
* import-graph (e.g. the migrations directory watcher in DbService) and
|
|
110
|
+
* needs to nudge a specific service to re-evaluate without leaning on
|
|
111
|
+
* the devtools-only `__zenbu_dev__.reloadService` hook.
|
|
112
|
+
*/
|
|
113
|
+
reload(key: string): Promise<void>;
|
|
114
|
+
shutdown(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Subscribe to a service. Behavior-subject style: the callback fires
|
|
117
|
+
* synchronously once with the current value (the live instance if ready,
|
|
118
|
+
* `undefined` otherwise), then again on every reconcile of that service —
|
|
119
|
+
* so you see the new instance after each HMR. Pass through `undefined`
|
|
120
|
+
* when the service tears down or unregisters.
|
|
121
|
+
*
|
|
122
|
+
* Returns an unsubscribe function. Always call it from a `setup()` cleanup
|
|
123
|
+
* (or wherever you'd otherwise leak callbacks across reloads).
|
|
124
|
+
*/
|
|
125
|
+
get<T extends Service>(ref: {
|
|
126
|
+
key: string;
|
|
127
|
+
}, cb: (instance: T | undefined) => void): () => void;
|
|
128
|
+
private fireSubscribers;
|
|
129
|
+
buildRouter(): Record<string, Record<string, (...args: any[]) => any>>;
|
|
130
|
+
onReconciled(cb: (changedKeys: string[]) => void): () => void;
|
|
131
|
+
private resolveDepSlot;
|
|
132
|
+
private injectCtx;
|
|
133
|
+
private rebuildDependentsIndex;
|
|
134
|
+
private getAffectedKeys;
|
|
135
|
+
private listMissingDeps;
|
|
136
|
+
private ensureSlot;
|
|
137
|
+
private teardownService;
|
|
138
|
+
private unregister;
|
|
139
|
+
private scheduleReconcile;
|
|
140
|
+
private reconcileBatch;
|
|
141
|
+
private reconcileKey;
|
|
142
|
+
private topologicalLevels;
|
|
143
|
+
}
|
|
144
|
+
declare const runtime: ServiceRuntime;
|
|
145
|
+
/**
|
|
146
|
+
* A plugin manifest after the loader has resolved every relative path to
|
|
147
|
+
* absolute. Mirrors `ResolvedPlugin` in `cli/lib/build-config.ts` but is
|
|
148
|
+
* declared inline here to avoid runtime.ts importing CLI code.
|
|
149
|
+
*/
|
|
150
|
+
interface PluginRecord {
|
|
151
|
+
name: string;
|
|
152
|
+
dir: string;
|
|
153
|
+
services: string[];
|
|
154
|
+
schemaPath?: string;
|
|
155
|
+
migrationsPath?: string;
|
|
156
|
+
preloadPath?: string;
|
|
157
|
+
eventsPath?: string;
|
|
158
|
+
icons?: Record<string, string>;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Live snapshot of the resolved Zenbu config. Returned by `getConfig()` and
|
|
162
|
+
* delivered to `subscribeConfig` callbacks. Re-emitted whenever the loader
|
|
163
|
+
* regenerates the plugin barrel — i.e. on every edit to `zenbu.config.ts`
|
|
164
|
+
* or any imported `zenbu.plugin.ts`.
|
|
165
|
+
*/
|
|
166
|
+
interface ConfigSnapshot {
|
|
167
|
+
plugins: PluginRecord[];
|
|
168
|
+
/** Absolute path of the renderer entrypoint directory. */
|
|
169
|
+
appEntrypoint: string | null;
|
|
170
|
+
/** Absolute path of `splash.html` inside the entrypoint dir. */
|
|
171
|
+
splashPath: string | null;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Register a plugin's resolved manifest. Idempotent — replaces any existing
|
|
175
|
+
* entry for the same `name`. Called by the loader-emitted barrel; user code
|
|
176
|
+
* normally does not call this directly.
|
|
177
|
+
*/
|
|
178
|
+
declare function registerPlugin(record: PluginRecord): void;
|
|
179
|
+
/**
|
|
180
|
+
* Drop a plugin from the registry. Used when the loader regenerates the
|
|
181
|
+
* barrel and needs to clear stale entries.
|
|
182
|
+
*/
|
|
183
|
+
declare function unregisterPlugin(name: string): void;
|
|
184
|
+
/**
|
|
185
|
+
* Replace the entire plugin set in one shot. The loader uses this on every
|
|
186
|
+
* barrel regeneration so removed plugins disappear cleanly.
|
|
187
|
+
*/
|
|
188
|
+
declare function replacePlugins(records: PluginRecord[]): void;
|
|
189
|
+
declare function getPlugins(): PluginRecord[];
|
|
190
|
+
declare function getPlugin(name: string): PluginRecord | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* Set the renderer entrypoint directory + the absolute path to splash.html
|
|
193
|
+
* inside it. Called once by the loader-emitted barrel. Consumers
|
|
194
|
+
* (`view-registry`, `vite-plugins`, `setup-gate`'s splash window) read
|
|
195
|
+
* via `getAppEntrypoint()` / `getSplashPath()`.
|
|
196
|
+
*/
|
|
197
|
+
declare function registerAppEntrypoint(rendererDir: string, splashPath: string): void;
|
|
198
|
+
declare function getAppEntrypoint(): string | null;
|
|
199
|
+
declare function getSplashPath(): string | null;
|
|
200
|
+
/**
|
|
201
|
+
* Snapshot of the current resolved config — plugins + entrypoints. Cheap;
|
|
202
|
+
* just walks the in-memory registry. The returned object is a fresh copy,
|
|
203
|
+
* safe to retain or pass through serialization boundaries.
|
|
204
|
+
*/
|
|
205
|
+
declare function getConfig(): ConfigSnapshot;
|
|
206
|
+
/**
|
|
207
|
+
* Subscribe to config changes. The callback fires:
|
|
208
|
+
* - immediately on subscription (with the current snapshot),
|
|
209
|
+
* - after each `replacePlugins(...)` / `registerPlugin(...)` /
|
|
210
|
+
* `registerAppEntrypoint(...)` call — i.e. every time the loader
|
|
211
|
+
* regenerates the plugin barrel after a `zenbu.config.ts` edit.
|
|
212
|
+
*
|
|
213
|
+
* Callback exceptions are logged and swallowed so one buggy subscriber
|
|
214
|
+
* can't break others. The returned function unsubscribes.
|
|
215
|
+
*/
|
|
216
|
+
declare function subscribeConfig(callback: (snapshot: ConfigSnapshot) => void): () => void;
|
|
217
|
+
//#endregion
|
|
218
|
+
export { unregisterPlugin as _, ServiceConstructor as a, getConfig as c, getSplashPath as d, registerAppEntrypoint as f, subscribeConfig as g, runtime as h, Service as i, getPlugin as l, replacePlugins as m, ConfigSnapshot as n, ServiceRuntime as o, registerPlugin as p, PluginRecord as r, getAppEntrypoint as s, CleanupReason as t, getPlugins as u };
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { CleanupReason, PluginRecord, Service, ServiceRuntime, getAppEntrypoint, getPlugin, getPlugins,
|
|
1
|
+
import { _ as unregisterPlugin, a as ServiceConstructor, c as getConfig, d as getSplashPath, f as registerAppEntrypoint, g as subscribeConfig, h as runtime, i as Service, l as getPlugin, m as replacePlugins, n as ConfigSnapshot, o as ServiceRuntime, p as registerPlugin, r as PluginRecord, s as getAppEntrypoint, t as CleanupReason, u as getPlugins } from "./runtime-BQWntcOb.mjs";
|
|
2
|
+
export { CleanupReason, ConfigSnapshot, PluginRecord, Service, ServiceConstructor, ServiceRuntime, getAppEntrypoint, getConfig, getPlugin, getPlugins, getSplashPath, registerAppEntrypoint, registerPlugin, replacePlugins, runtime, subscribeConfig, unregisterPlugin };
|