@zenbujs/core 0.0.1

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 (94) hide show
  1. package/LICENSE +11 -0
  2. package/dist/advice-config-CjgkEf2E.mjs +135 -0
  3. package/dist/advice-config-Cy133IQP.mjs +2 -0
  4. package/dist/advice-runtime.d.mts +35 -0
  5. package/dist/advice-runtime.mjs +131 -0
  6. package/dist/advice.d.mts +36 -0
  7. package/dist/advice.mjs +2 -0
  8. package/dist/base-window-BUt8pwbw.mjs +94 -0
  9. package/dist/base-window-DEIAk618.mjs +2 -0
  10. package/dist/build-config-pbv0w4oN.mjs +17 -0
  11. package/dist/build-electron-B4Gd0Gi4.mjs +516 -0
  12. package/dist/build-source-_q1n1zTV.mjs +162 -0
  13. package/dist/chunk-Dm34NbLt.mjs +6 -0
  14. package/dist/cli/bin.d.mts +1 -0
  15. package/dist/cli/bin.mjs +88 -0
  16. package/dist/cli/build.d.mts +53 -0
  17. package/dist/cli/build.mjs +48 -0
  18. package/dist/cli-BLbQQIVB.mjs +8054 -0
  19. package/dist/config-CdVrW85P.mjs +59 -0
  20. package/dist/config-LK73dJmO.mjs +2 -0
  21. package/dist/db-ByKPbnP6.mjs +2 -0
  22. package/dist/db-DhuAJrye.mjs +531 -0
  23. package/dist/db.d.mts +16 -0
  24. package/dist/db.mjs +16 -0
  25. package/dist/dev-BuqklM0k.mjs +85 -0
  26. package/dist/env-bootstrap-BtVME-CU.d.mts +16 -0
  27. package/dist/env-bootstrap-rj7I-59x.mjs +53 -0
  28. package/dist/env-bootstrap.d.mts +2 -0
  29. package/dist/env-bootstrap.mjs +2 -0
  30. package/dist/http-IBcLzbYu.mjs +2 -0
  31. package/dist/index-Bhlbyrn7.d.mts +63 -0
  32. package/dist/index-CPZ5d6Hl.d.mts +442 -0
  33. package/dist/index-FtE8MXJ_.d.mts +1 -0
  34. package/dist/index.d.mts +6 -0
  35. package/dist/index.mjs +5 -0
  36. package/dist/launcher.mjs +173 -0
  37. package/dist/link-6roQ7Cn6.mjs +580 -0
  38. package/dist/loaders/zenbu.d.mts +22 -0
  39. package/dist/loaders/zenbu.mjs +267 -0
  40. package/dist/log-CyKv8hQg.mjs +20 -0
  41. package/dist/mirror-sync-CodOnwkD.mjs +332 -0
  42. package/dist/monorepo-CmGPHsVm.mjs +119 -0
  43. package/dist/node-D4M19_mV.mjs +5 -0
  44. package/dist/node-loader.d.mts +17 -0
  45. package/dist/node-loader.mjs +33 -0
  46. package/dist/pause-DvAUNmKn.mjs +52 -0
  47. package/dist/publish-source-BVgB62Zj.mjs +131 -0
  48. package/dist/react.d.mts +76 -0
  49. package/dist/react.mjs +291 -0
  50. package/dist/registry-Dh_e7HU1.d.mts +61 -0
  51. package/dist/registry.d.mts +2 -0
  52. package/dist/registry.mjs +1 -0
  53. package/dist/reloader-BCkLjDhS.mjs +2 -0
  54. package/dist/reloader-lLAJ3lqg.mjs +164 -0
  55. package/dist/renderer-host-Bg8QdeeH.mjs +1508 -0
  56. package/dist/renderer-host-DpvBPTHJ.mjs +2 -0
  57. package/dist/rpc-BwwQK6hD.mjs +71 -0
  58. package/dist/rpc-CqitnyR4.mjs +2 -0
  59. package/dist/rpc.d.mts +2 -0
  60. package/dist/rpc.mjs +2 -0
  61. package/dist/runtime-CjqDr8Yf.d.mts +109 -0
  62. package/dist/runtime-DUFKDIe4.mjs +409 -0
  63. package/dist/runtime.d.mts +2 -0
  64. package/dist/runtime.mjs +2 -0
  65. package/dist/schema-CIg4GzHQ.mjs +100 -0
  66. package/dist/schema-DMoSkwUx.d.mts +62 -0
  67. package/dist/schema-dGK6qkfR.mjs +28 -0
  68. package/dist/schema.d.mts +2 -0
  69. package/dist/schema.mjs +2 -0
  70. package/dist/server-BXwZEQ-n.mjs +66 -0
  71. package/dist/server-DjrZUbbu.mjs +2 -0
  72. package/dist/services/default.d.mts +11 -0
  73. package/dist/services/default.mjs +22 -0
  74. package/dist/services/index.d.mts +276 -0
  75. package/dist/services/index.mjs +7 -0
  76. package/dist/setup-gate-BeD6WS6d.mjs +110 -0
  77. package/dist/setup-gate-BqOzm7zp.d.mts +4 -0
  78. package/dist/setup-gate.d.mts +2 -0
  79. package/dist/setup-gate.mjs +2 -0
  80. package/dist/src-pELM4_iH.mjs +376 -0
  81. package/dist/trace-DCB7qFzT.mjs +10 -0
  82. package/dist/transform-DJH3vN4b.mjs +84041 -0
  83. package/dist/transport-BMSzG2-F.mjs +1045 -0
  84. package/dist/view-registry-BualWgAf.mjs +2 -0
  85. package/dist/vite-plugins-Bh3SCOw-.mjs +331 -0
  86. package/dist/vite.d.mts +68 -0
  87. package/dist/vite.mjs +2 -0
  88. package/dist/window-CM2a9Kyc.mjs +2 -0
  89. package/dist/window-CmmpCVX6.mjs +156 -0
  90. package/dist/write-9dRFczGJ.mjs +1248 -0
  91. package/migrations/0000_migration.ts +34 -0
  92. package/migrations/meta/0000_snapshot.json +18 -0
  93. package/migrations/meta/_journal.json +10 -0
  94. package/package.json +124 -0
@@ -0,0 +1,119 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { execFileSync } from "node:child_process";
5
+ //#region src/cli/commands/monorepo.ts
6
+ const MARKER_FILE = ".zenbu-dev-link";
7
+ const DEFAULT_MONOREPO = path.join(os.homedir(), ".zenbu", "plugins", "zenbu");
8
+ function resolveProjectDir() {
9
+ const cwd = process.cwd();
10
+ if (fs.existsSync(path.join(cwd, "zenbu.plugin.json")) || fs.existsSync(path.join(cwd, "zenbu")) || fs.existsSync(path.join(cwd, MARKER_FILE))) return cwd;
11
+ console.error("zen monorepo: not in a zenbu project (no zenbu.plugin.json or zenbu/ found)");
12
+ process.exit(1);
13
+ }
14
+ function resolveMonorepoPath(explicit) {
15
+ const candidate = explicit || process.env.ZENBU_DEV || DEFAULT_MONOREPO;
16
+ const resolved = path.resolve(candidate);
17
+ if (!fs.existsSync(resolved)) {
18
+ console.error(`zen dev link: monorepo not found at ${resolved}`);
19
+ process.exit(1);
20
+ }
21
+ if (!fs.existsSync(path.join(resolved, "packages", "core"))) {
22
+ console.error(`zen monorepo link: ${resolved} doesn't look like a zenbu monorepo (missing packages/core)`);
23
+ process.exit(1);
24
+ }
25
+ return resolved;
26
+ }
27
+ async function link(argv) {
28
+ const projectDir = resolveProjectDir();
29
+ const monorepoPath = resolveMonorepoPath(argv[0]);
30
+ const zenbuDir = path.join(projectDir, "zenbu");
31
+ const markerPath = path.join(projectDir, MARKER_FILE);
32
+ if (fs.existsSync(markerPath)) {
33
+ console.log(" Already dev-linked. Run 'zen dev unlink' first to change.");
34
+ return;
35
+ }
36
+ if (fs.lstatSync(zenbuDir, { throwIfNoEntry: false })?.isSymbolicLink()) {
37
+ console.log(" zenbu/ is already a symlink. Run 'zen dev unlink' first.");
38
+ return;
39
+ }
40
+ let submoduleSha = "";
41
+ if (fs.existsSync(zenbuDir)) {
42
+ try {
43
+ submoduleSha = execFileSync("git", [
44
+ "-C",
45
+ zenbuDir,
46
+ "rev-parse",
47
+ "HEAD"
48
+ ], { encoding: "utf8" }).trim();
49
+ } catch {}
50
+ console.log(" → removing zenbu/ submodule directory...");
51
+ fs.rmSync(zenbuDir, {
52
+ recursive: true,
53
+ force: true
54
+ });
55
+ }
56
+ fs.writeFileSync(markerPath, JSON.stringify({
57
+ monorepo: monorepoPath,
58
+ previousSha: submoduleSha,
59
+ linkedAt: (/* @__PURE__ */ new Date()).toISOString()
60
+ }, null, 2) + "\n");
61
+ console.log(` → linking zenbu/ -> ${monorepoPath}`);
62
+ fs.symlinkSync(monorepoPath, zenbuDir);
63
+ if (!fs.existsSync(path.join(monorepoPath, "node_modules"))) console.log(" → monorepo missing node_modules, run 'pnpm install' there first");
64
+ console.log(`\n ✓ Dev-linked to ${monorepoPath}`);
65
+ console.log(` Changes to the monorepo are now live in this project.`);
66
+ console.log(` Run 'zen dev unlink' to restore the git submodule.\n`);
67
+ }
68
+ async function unlink(_argv) {
69
+ const projectDir = resolveProjectDir();
70
+ const zenbuDir = path.join(projectDir, "zenbu");
71
+ const markerPath = path.join(projectDir, MARKER_FILE);
72
+ if (!fs.existsSync(markerPath)) {
73
+ console.error("zen dev unlink: not dev-linked (no .zenbu-dev-link marker)");
74
+ process.exit(1);
75
+ }
76
+ if (fs.lstatSync(zenbuDir, { throwIfNoEntry: false })?.isSymbolicLink()) {
77
+ console.log(" → removing symlink...");
78
+ fs.unlinkSync(zenbuDir);
79
+ }
80
+ console.log(" → restoring git submodule...");
81
+ try {
82
+ execFileSync("git", [
83
+ "submodule",
84
+ "update",
85
+ "--init",
86
+ "zenbu"
87
+ ], {
88
+ cwd: projectDir,
89
+ stdio: "inherit"
90
+ });
91
+ } catch (err) {
92
+ console.error(" ⚠ submodule restore failed, you may need to run 'git submodule update --init zenbu' manually");
93
+ }
94
+ fs.unlinkSync(markerPath);
95
+ console.log(`\n ✓ Dev-link removed. zenbu/ restored to git submodule.\n`);
96
+ }
97
+ async function runMonorepo(argv) {
98
+ const sub = argv[0];
99
+ if (sub === "link") {
100
+ await link(argv.slice(1));
101
+ return;
102
+ }
103
+ if (sub === "unlink") {
104
+ await unlink(argv.slice(1));
105
+ return;
106
+ }
107
+ console.log(`
108
+ zen monorepo — framework-internal monorepo dev tools
109
+
110
+ Usage:
111
+ zen monorepo link [monorepo-path] Symlink zenbu/ to a local monorepo for live editing
112
+ zen monorepo unlink Restore zenbu/ to the git submodule
113
+
114
+ Environment:
115
+ ZENBU_DEV Default monorepo path (fallback: ~/.zenbu/plugins/zenbu)
116
+ `);
117
+ }
118
+ //#endregion
119
+ export { runMonorepo };
@@ -0,0 +1,5 @@
1
+ import { register } from "node:module";
2
+ //#region ../advice/src/node.ts
3
+ register("./node-loader.mjs", import.meta.url);
4
+ //#endregion
5
+ export {};
@@ -0,0 +1,17 @@
1
+ //#region ../advice/src/node-loader.d.ts
2
+ interface LoadContext {
3
+ conditions: string[];
4
+ importAttributes: Record<string, string>;
5
+ format?: string;
6
+ }
7
+ type NextLoad = (url: string, context: LoadContext) => Promise<{
8
+ source: string | ArrayBuffer;
9
+ format: string;
10
+ }>;
11
+ declare function load(url: string, context: LoadContext, nextLoad: NextLoad): Promise<{
12
+ source: string | ArrayBuffer;
13
+ format: string;
14
+ shortCircuit?: boolean;
15
+ }>;
16
+ //#endregion
17
+ export { load };
@@ -0,0 +1,33 @@
1
+ import { n as require_lib, t as zenbuAdviceTransform } from "./transform-DJH3vN4b.mjs";
2
+ import { fileURLToPath } from "node:url";
3
+ //#region ../advice/src/node-loader.ts
4
+ var import_lib = require_lib();
5
+ const includeRe = /\.[jt]sx?$/;
6
+ const excludeRe = /node_modules|packages\/advice\//;
7
+ const rootDir = (process.env.ZENBU_ADVICE_ROOT ?? process.cwd()).replace(/\\/g, "/").replace(/\/$/, "");
8
+ async function load(url, context, nextLoad) {
9
+ if (!url.startsWith("file://")) return nextLoad(url, context);
10
+ const filePath = fileURLToPath(url);
11
+ const normalizedPath = filePath.replace(/\\/g, "/");
12
+ if (!(normalizedPath === rootDir || normalizedPath.startsWith(rootDir + "/")) || !includeRe.test(filePath) || excludeRe.test(filePath)) return nextLoad(url, context);
13
+ const loaded = await nextLoad(url, context);
14
+ const source = typeof loaded.source === "string" ? loaded.source : new TextDecoder().decode(loaded.source);
15
+ const parserPlugins = /\.tsx?$/.test(filePath) ? ["typescript"] : [];
16
+ if (/\.[jt]sx$/.test(filePath)) parserPlugins.push("jsx");
17
+ const result = (0, import_lib.transformSync)(source, {
18
+ filename: filePath,
19
+ plugins: [[zenbuAdviceTransform, { root: rootDir }]],
20
+ parserOpts: { plugins: parserPlugins },
21
+ sourceMaps: "inline",
22
+ configFile: false,
23
+ babelrc: false
24
+ });
25
+ if (!result?.code) return loaded;
26
+ return {
27
+ source: result.code,
28
+ format: loaded.format,
29
+ shortCircuit: true
30
+ };
31
+ }
32
+ //#endregion
33
+ export { load };
@@ -0,0 +1,52 @@
1
+ //#region ../dynohot/dist/runtime/pause.js
2
+ /**
3
+ * Registry of fs.watch-backed watchers that need to be `.close()`'d before
4
+ * process exit. On macOS, `fs.watch` uses FSEvents.framework on a
5
+ * background thread; if we `_exit(0)` (or skip shutdown hooks) while
6
+ * watchers are still armed, FSEvents will try to dispatch events into a
7
+ * dying V8 isolate → `napi_call_function` assertion → SIGABRT. Callers
8
+ * (dynohot's FileWatcher, the kernel's zenbu-loader-hooks) register their
9
+ * fs watchers here and the shell invokes `closeAllWatchers()` as part of
10
+ * shutdown.
11
+ */
12
+ const WATCHER_SET_KEY = Symbol.for("dynohot.fileWatcher.closables");
13
+ function getClosables() {
14
+ const g = globalThis;
15
+ let set = g[WATCHER_SET_KEY];
16
+ if (!set) {
17
+ set = /* @__PURE__ */ new Set();
18
+ g[WATCHER_SET_KEY] = set;
19
+ }
20
+ return set;
21
+ }
22
+ /**
23
+ * Register a closable (typically an `fs.FSWatcher`) for shutdown cleanup.
24
+ * Returns a de-registration function — call it when the watcher is
25
+ * closed normally, so the shutdown list doesn't grow unbounded.
26
+ */
27
+ function registerWatcherClosable(watcher) {
28
+ const set = getClosables();
29
+ set.add(watcher);
30
+ return () => {
31
+ set.delete(watcher);
32
+ };
33
+ }
34
+ /**
35
+ * Close every registered watcher. Call this synchronously immediately
36
+ * before a hard process exit so FSEvents stops dispatching before the V8
37
+ * isolate dies.
38
+ */
39
+ async function closeAllWatchers() {
40
+ const set = getClosables();
41
+ const all = [...set];
42
+ set.clear();
43
+ await Promise.allSettled(all.map((w) => {
44
+ try {
45
+ return w.close();
46
+ } catch {
47
+ return;
48
+ }
49
+ }));
50
+ }
51
+ //#endregion
52
+ export { closeAllWatchers, registerWatcherClosable };
@@ -0,0 +1,131 @@
1
+ import { a as findBuildConfig, i as push, n as init, o as loadBuildConfig } from "./mirror-sync-CodOnwkD.mjs";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import fsp from "node:fs/promises";
5
+ import { execFileSync } from "node:child_process";
6
+ //#region src/cli/commands/publish-source.ts
7
+ function resolveProjectDir() {
8
+ const cwd = process.cwd();
9
+ if (fs.existsSync(path.join(cwd, "zenbu.plugin.json"))) return cwd;
10
+ console.error("zen publish:source: no zenbu.plugin.json found in current directory");
11
+ process.exit(1);
12
+ }
13
+ function currentSourceSha(projectDir) {
14
+ try {
15
+ return execFileSync("git", ["rev-parse", "HEAD"], {
16
+ cwd: projectDir,
17
+ encoding: "utf8"
18
+ }).trim();
19
+ } catch {
20
+ return "uncommitted";
21
+ }
22
+ }
23
+ async function readStagingMeta(stagingDir) {
24
+ const shaPath = path.join(stagingDir, ".sha");
25
+ if (!fs.existsSync(stagingDir) || !fs.existsSync(shaPath)) throw new Error(`staging dir missing or incomplete: ${stagingDir}\n run \`zen build:source\` first.`);
26
+ return JSON.parse(await fsp.readFile(shaPath, "utf8"));
27
+ }
28
+ function parseFlags(argv) {
29
+ let subcommand = "push";
30
+ if (argv[0] === "init" || argv[0] === "push") {
31
+ subcommand = argv[0];
32
+ argv = argv.slice(1);
33
+ }
34
+ const flags = {
35
+ subcommand,
36
+ force: false
37
+ };
38
+ for (let i = 0; i < argv.length; i++) {
39
+ const arg = argv[i];
40
+ if (arg === "--config" || arg === "-c") flags.config = argv[++i];
41
+ else if (arg.startsWith("--config=")) flags.config = arg.slice(9);
42
+ else if (arg === "--target") flags.target = argv[++i];
43
+ else if (arg.startsWith("--target=")) flags.target = arg.slice(9);
44
+ else if (arg === "--branch") flags.branch = argv[++i];
45
+ else if (arg.startsWith("--branch=")) flags.branch = arg.slice(9);
46
+ else if (arg === "--force" || arg === "-f") flags.force = true;
47
+ }
48
+ return flags;
49
+ }
50
+ function expandMirrorUrl(target) {
51
+ if (target.startsWith("http://") || target.startsWith("https://") || target.startsWith("git@")) return target;
52
+ if (/^[\w.-]+\/[\w.-]+$/.test(target)) {
53
+ const token = process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN ?? null;
54
+ return token ? `https://x-access-token:${token}@github.com/${target}.git` : `https://github.com/${target}.git`;
55
+ }
56
+ return target;
57
+ }
58
+ function resolveAuthor(projectDir) {
59
+ try {
60
+ const name = execFileSync("git", ["config", "user.name"], {
61
+ cwd: projectDir,
62
+ encoding: "utf8"
63
+ }).trim();
64
+ const email = execFileSync("git", ["config", "user.email"], {
65
+ cwd: projectDir,
66
+ encoding: "utf8"
67
+ }).trim();
68
+ return {
69
+ name: name || void 0,
70
+ email: email || void 0
71
+ };
72
+ } catch {
73
+ return {};
74
+ }
75
+ }
76
+ function logResult(action, result, mirrorUrl) {
77
+ if (result.status === "noop") {
78
+ console.log(`\n → ${result.reason ?? "nothing to push"}\n`);
79
+ return;
80
+ }
81
+ const sha = result.mirrorSha ? ` (${result.mirrorSha.slice(0, 7)})` : "";
82
+ console.log(`\n ✓ ${action === "init" ? "initialized" : "pushed to"} ${mirrorUrl}${sha}\n`);
83
+ }
84
+ async function runPublishSource(argv) {
85
+ const projectDir = resolveProjectDir();
86
+ const flags = parseFlags(argv);
87
+ const config = await loadBuildConfig(flags.config ? path.resolve(projectDir, flags.config) : findBuildConfig(projectDir));
88
+ const target = flags.target ?? config.mirror?.target;
89
+ if (!target) {
90
+ console.error("zen publish:source: no mirror target specified (config.mirror.target or --target)");
91
+ process.exit(1);
92
+ }
93
+ const branch = flags.branch ?? config.mirror?.branch ?? "main";
94
+ const mirrorUrl = expandMirrorUrl(target);
95
+ const stagingDir = path.resolve(projectDir, config.out);
96
+ const meta = await readStagingMeta(stagingDir);
97
+ const head = currentSourceSha(projectDir);
98
+ if (head !== "uncommitted" && meta.sourceSha !== head && !flags.force) {
99
+ console.error(`zen publish:source: staging is stale (built from ${meta.sourceSha.slice(0, 7)}, current HEAD ${head.slice(0, 7)}).\n run \`zen build:source\` again, or pass --force to publish staging anyway.`);
100
+ process.exit(1);
101
+ }
102
+ const author = resolveAuthor(projectDir);
103
+ console.log(`\n zen publish:source ${flags.subcommand}`);
104
+ console.log(` target: ${target}`);
105
+ console.log(` branch: ${branch}`);
106
+ console.log(` source: ${meta.sourceSha === "uncommitted" ? "uncommitted" : meta.sourceSha.slice(0, 7)}`);
107
+ try {
108
+ const result = flags.subcommand === "init" ? await init({
109
+ staging: stagingDir,
110
+ mirrorUrl,
111
+ branch,
112
+ sourceSha: meta.sourceSha,
113
+ authorName: author.name,
114
+ authorEmail: author.email,
115
+ force: flags.force
116
+ }) : await push({
117
+ staging: stagingDir,
118
+ mirrorUrl,
119
+ branch,
120
+ sourceSha: meta.sourceSha,
121
+ authorName: author.name,
122
+ authorEmail: author.email
123
+ });
124
+ logResult(flags.subcommand, result, target);
125
+ } catch (err) {
126
+ console.error(`zen publish:source: ${err instanceof Error ? err.message : String(err)}`);
127
+ process.exit(1);
128
+ }
129
+ }
130
+ //#endregion
131
+ export { runPublishSource };
@@ -0,0 +1,76 @@
1
+ import { f as CollectionRefBrand, h as InferCollectionItem, n as connectReplica, o as ClientProxy, p as CollectionRefValue, u as CollectionState, y as SchemaShape } from "./index-CPZ5d6Hl.mjs";
2
+ import { c as ResolvedServiceRouter, l as ZenbuRegister, o as ResolvedDbRoot, s as ResolvedEvents } from "./registry-Dh_e7HU1.mjs";
3
+ import { n as EventProxy, r as RouterProxy } from "./index-Bhlbyrn7.mjs";
4
+ import * as _$react from "react";
5
+ import { ReactNode } from "react";
6
+
7
+ //#region ../kyju/src/v2/react/index.d.ts
8
+ type CollectionResult<Item> = {
9
+ items: Item[];
10
+ totalCount: number;
11
+ collection: CollectionState | null;
12
+ concat: (items: Item[]) => void;
13
+ };
14
+ //#endregion
15
+ //#region src/react.d.ts
16
+ type AnyRpc = RouterProxy<Record<string, Record<string, (...args: any[]) => any>>>;
17
+ type AnyEvents = EventProxy<Record<string, unknown>>;
18
+ type AnyDbClient = ClientProxy<SchemaShape>;
19
+ type Replica = Awaited<ReturnType<typeof connectReplica>>["replica"];
20
+ type Connection = {
21
+ rpc: AnyRpc;
22
+ events: AnyEvents;
23
+ db: AnyDbClient;
24
+ replica: Replica;
25
+ };
26
+ type ConnectionState = {
27
+ status: "connecting";
28
+ } | {
29
+ status: "connected";
30
+ conn: Connection;
31
+ } | {
32
+ status: "error";
33
+ error: string;
34
+ };
35
+ type RegisteredDbRoot = ResolvedDbRoot;
36
+ type RegisteredServiceRouter = ResolvedServiceRouter;
37
+ type RegisteredEvents = ResolvedEvents;
38
+ /**
39
+ * Subscribe to a slice of the live DB. The selector's `root` is typed via
40
+ * `ZenbuRegister["db"]`, populated by `zen link`. No generic at the call site.
41
+ *
42
+ * const count = useDb((root) => root.plugin.app.count)
43
+ */
44
+ declare function useDb(): RegisteredDbRoot;
45
+ declare function useDb<T>(selector: (root: RegisteredDbRoot) => T, isEqual?: (a: T, b: T) => boolean): T;
46
+ declare const useCollection: <T extends {
47
+ collectionId: string;
48
+ } & CollectionRefBrand<unknown>>(ref: T | null | undefined) => CollectionResult<InferCollectionItem<T>>;
49
+ type ZenbuProviderProps = {
50
+ wsUrl?: string;
51
+ fallback?: ReactNode;
52
+ errorFallback?: (error: string) => ReactNode;
53
+ children: ReactNode;
54
+ };
55
+ declare function ZenbuProvider({
56
+ wsUrl,
57
+ fallback,
58
+ errorFallback,
59
+ children
60
+ }: ZenbuProviderProps): _$react.ReactElement<{
61
+ "data-zenbu-connecting": boolean;
62
+ }, string | _$react.JSXElementConstructor<any>> | _$react.ReactElement<{
63
+ "data-zenbu-error": boolean;
64
+ }, string | _$react.JSXElementConstructor<any>> | _$react.FunctionComponentElement<_$react.ProviderProps<ConnectionState | null>>;
65
+ declare function useRpc(): RouterProxy<RegisteredServiceRouter>;
66
+ type DbClient = {
67
+ readRoot(): RegisteredDbRoot;
68
+ update(fn: (root: RegisteredDbRoot) => void | RegisteredDbRoot): Promise<void>;
69
+ createBlob(data: Uint8Array, hot?: boolean): Promise<string>;
70
+ deleteBlob(blobId: string): Promise<void>;
71
+ getBlobData(blobId: string): Promise<Uint8Array | null>;
72
+ };
73
+ declare function useDbClient(): DbClient;
74
+ declare function useEvents(): EventProxy<RegisteredEvents>;
75
+ //#endregion
76
+ export { type CollectionRefValue, DbClient, ZenbuProvider, ZenbuProviderProps, type ZenbuRegister, useCollection, useDb, useDbClient, useEvents, useRpc };