@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,85 @@
1
+ import { existsSync, statSync } from "node:fs";
2
+ import path, { resolve } from "node:path";
3
+ import { spawn } from "node:child_process";
4
+ //#region src/cli/commands/dev.ts
5
+ /**
6
+ * `zen dev` — launch the local app under Electron with the setup-gate as the
7
+ * main entry. This is the entrypoint of `pnpm dev` in scaffolded apps. The
8
+ * command is intentionally hookable: future versions can layer doctor checks,
9
+ * environment validation, or a managed dev-server here without touching the
10
+ * user's `package.json` scripts.
11
+ *
12
+ * Defaults to a foreground/blocking child so Ctrl+C in the terminal kills the
13
+ * Electron process and `pnpm dev` exits cleanly. Pass `--detach` to spawn it
14
+ * in the background instead (returns immediately, Electron lives until quit).
15
+ */
16
+ function parseArgs(argv) {
17
+ let pathArg;
18
+ let detach = false;
19
+ let verbose = false;
20
+ for (let i = 0; i < argv.length; i++) {
21
+ const arg = argv[i];
22
+ if (arg === "--detach") detach = true;
23
+ else if (arg === "--verbose" || arg === "-v") verbose = true;
24
+ else if (!arg.startsWith("-") && pathArg == null) pathArg = arg;
25
+ else {
26
+ console.error(`zen dev: unknown flag "${arg}"`);
27
+ console.error(`valid: zen dev [path] [--detach] [--verbose]`);
28
+ process.exit(1);
29
+ }
30
+ }
31
+ const projectDir = pathArg ? resolve(process.cwd(), pathArg) : process.cwd();
32
+ if (!existsSync(projectDir)) {
33
+ console.error(`zen dev: path "${pathArg}" does not exist`);
34
+ process.exit(1);
35
+ }
36
+ try {
37
+ if (!statSync(projectDir).isDirectory()) {
38
+ console.error(`zen dev: path "${pathArg}" is not a directory`);
39
+ process.exit(1);
40
+ }
41
+ } catch {
42
+ console.error(`zen dev: cannot stat "${pathArg}"`);
43
+ process.exit(1);
44
+ }
45
+ return {
46
+ projectDir,
47
+ detach,
48
+ verbose
49
+ };
50
+ }
51
+ function resolveLocalElectron(projectDir) {
52
+ const candidates = [path.join(projectDir, "node_modules", "electron", "dist", "Electron.app", "Contents", "MacOS", "Electron"), path.join(projectDir, "node_modules", ".bin", "electron")];
53
+ for (const candidate of candidates) if (existsSync(candidate)) return candidate;
54
+ throw new Error(`Electron is not installed in ${projectDir}. Run \`pnpm install\` in the app.`);
55
+ }
56
+ function ensureSetupGate(projectDir) {
57
+ const setupGate = path.join(projectDir, "node_modules", "@zenbujs", "core", "dist", "setup-gate.mjs");
58
+ if (!existsSync(setupGate)) throw new Error(`@zenbujs/core setup-gate not found at ${setupGate}. Run \`pnpm install\` in the app.`);
59
+ }
60
+ async function runDev(argv) {
61
+ const { projectDir, detach, verbose } = parseArgs(argv);
62
+ if (verbose) console.error("[zen dev] launching:", projectDir);
63
+ const electron = resolveLocalElectron(projectDir);
64
+ ensureSetupGate(projectDir);
65
+ const electronArgs = [projectDir, `--project=${projectDir}`];
66
+ if (detach) {
67
+ spawn(electron, electronArgs, {
68
+ cwd: projectDir,
69
+ detached: true,
70
+ stdio: "ignore"
71
+ }).unref();
72
+ return;
73
+ }
74
+ const child = spawn(electron, electronArgs, {
75
+ cwd: projectDir,
76
+ stdio: "inherit"
77
+ });
78
+ process.on("SIGINT", () => child.kill("SIGINT"));
79
+ process.on("SIGTERM", () => child.kill("SIGTERM"));
80
+ child.on("exit", (code, signal) => {
81
+ process.exit(code ?? (signal ? 1 : 0));
82
+ });
83
+ }
84
+ //#endregion
85
+ export { runDev };
@@ -0,0 +1,16 @@
1
+ //#region src/env-bootstrap.d.ts
2
+ declare function bootstrapEnv(): {
3
+ paths: {
4
+ cacheRoot: string;
5
+ binDir: string;
6
+ bunInstall: string;
7
+ bunPath: string;
8
+ pnpmHome: string;
9
+ pnpmPath: string;
10
+ gitPath: string;
11
+ writtenAt: number;
12
+ };
13
+ needsToolchainDownload: boolean;
14
+ };
15
+ //#endregion
16
+ export { bootstrapEnv as t };
@@ -0,0 +1,53 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ //#region src/env-bootstrap.ts
5
+ const internalDir = path.join(os.homedir(), ".zenbu", ".internal");
6
+ const pathsJson = path.join(internalDir, "paths.json");
7
+ function userCacheRoot() {
8
+ if (process.platform === "darwin") return path.join(os.homedir(), "Library", "Caches");
9
+ if (process.platform === "win32") return process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local");
10
+ return process.env.XDG_CACHE_HOME ?? path.join(os.homedir(), ".cache");
11
+ }
12
+ function computePaths() {
13
+ const cacheRoot = path.join(userCacheRoot(), "Zenbu");
14
+ const binDir = path.join(cacheRoot, "bin");
15
+ return {
16
+ cacheRoot,
17
+ binDir,
18
+ bunInstall: path.join(cacheRoot, "bun"),
19
+ bunPath: path.join(binDir, "bun"),
20
+ pnpmHome: path.join(cacheRoot, "pnpm"),
21
+ pnpmPath: path.join(binDir, "pnpm"),
22
+ gitPath: path.join(binDir, "git"),
23
+ writtenAt: Date.now()
24
+ };
25
+ }
26
+ function bootstrapEnv() {
27
+ const paths = computePaths();
28
+ try {
29
+ fs.mkdirSync(paths.binDir, { recursive: true });
30
+ } catch {}
31
+ const toolchainReady = fs.existsSync(paths.bunPath) && fs.existsSync(paths.pnpmPath);
32
+ if (toolchainReady) {
33
+ process.env.BUN_INSTALL ??= paths.bunInstall;
34
+ process.env.PNPM_HOME ??= paths.pnpmHome;
35
+ }
36
+ const pathParts = toolchainReady ? [paths.binDir, process.env.PATH ?? ""] : [process.env.PATH ?? ""];
37
+ const seen = /* @__PURE__ */ new Set();
38
+ process.env.PATH = pathParts.flatMap((part) => part.split(path.delimiter)).filter((part) => {
39
+ if (!part || seen.has(part)) return false;
40
+ seen.add(part);
41
+ return true;
42
+ }).join(path.delimiter);
43
+ try {
44
+ fs.mkdirSync(internalDir, { recursive: true });
45
+ fs.writeFileSync(pathsJson, JSON.stringify(paths, null, 2));
46
+ } catch {}
47
+ return {
48
+ paths,
49
+ needsToolchainDownload: !toolchainReady
50
+ };
51
+ }
52
+ //#endregion
53
+ export { bootstrapEnv as t };
@@ -0,0 +1,2 @@
1
+ import { t as bootstrapEnv } from "./env-bootstrap-BtVME-CU.mjs";
2
+ export { bootstrapEnv };
@@ -0,0 +1,2 @@
1
+ import { t as bootstrapEnv } from "./env-bootstrap-rj7I-59x.mjs";
2
+ export { bootstrapEnv };
@@ -0,0 +1,2 @@
1
+ import "./renderer-host-Bg8QdeeH.mjs";
2
+ export {};
@@ -0,0 +1,63 @@
1
+ import * as Effect from "effect/Effect";
2
+
3
+ //#region ../zenrpc/src/types.d.ts
4
+ type AnyRouter = {
5
+ [key: string]: ((...args: any[]) => any) | AnyRouter;
6
+ };
7
+ /**
8
+ * Strips Error/Effect internals from a tagged error type, keeping _tag
9
+ * and user-defined data fields. Excludes stack, name, cause, symbols,
10
+ * and function-valued properties.
11
+ */
12
+ type SerializedError<E> = E extends {
13
+ readonly _tag: string;
14
+ } ? { [K in keyof E as K extends symbol ? never : K extends "stack" | "name" | "cause" ? never : E[K] extends ((...args: any[]) => any) ? never : K]: E[K] } : never;
15
+ /**
16
+ * Result type for Effect-returning router methods.
17
+ * Always wraps success in { _tag: "success", data: A }.
18
+ * If E has tagged errors, they're added to the discriminated union.
19
+ */
20
+ type EffectResult<A, E> = [E] extends [never] ? {
21
+ readonly _tag: "success";
22
+ readonly data: A;
23
+ } : {
24
+ readonly _tag: "success";
25
+ readonly data: A;
26
+ } | SerializedError<E>;
27
+ /**
28
+ * Recursively converts a router's methods into Promise-returning versions.
29
+ *
30
+ * The first branch is intentional and load-bearing: when a method is
31
+ * **already async** (`(...args) => Promise<X>`), we hand back `T[K]`
32
+ * unchanged — an indexed access type — so editors can resolve cmd+click /
33
+ * go-to-definition through the proxy back to the original service method.
34
+ * The non-async and Effect branches still `infer` and rebuild the signature
35
+ * (the call really does need to be wrapped on the wire), at the cost of
36
+ * breaking go-to-def on those — services that want navigability should make
37
+ * their RPC methods `async`.
38
+ */
39
+ type RouterProxy<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => Promise<any>) ? T[K] : T[K] extends ((...args: infer A) => infer R) ? [R] extends [Effect.Effect<infer S, infer E, any>] ? (...args: A) => Promise<EffectResult<S, E>> : (...args: A) => Promise<Awaited<R>> : T[K] extends Record<string, any> ? RouterProxy<T[K]> : never };
40
+ /**
41
+ * Recursively maps an event definition tree into subscribe proxies.
42
+ * Every node is both navigable (for nesting) and subscribable (for leaf events).
43
+ * In practice, only call .subscribe on leaf event nodes.
44
+ */
45
+ type EventProxy<T> = { [K in keyof T]: T[K] extends Record<string, any> ? EventProxy<T[K]> & {
46
+ subscribe: (cb: (data: T[K]) => void) => () => void;
47
+ } : {
48
+ subscribe: (cb: (data: T[K]) => void) => () => void;
49
+ } };
50
+ //#endregion
51
+ //#region ../zenrpc/src/transport.d.ts
52
+ declare function connectRpc<TServerRouter extends AnyRouter, TEvents extends Record<string, any> = Record<string, never>>(opts: {
53
+ version: string;
54
+ clientId?: string;
55
+ send: (data: string) => void;
56
+ subscribe: (cb: (data: string) => void) => () => void;
57
+ }): Promise<{
58
+ server: RouterProxy<TServerRouter>;
59
+ events: EventProxy<TEvents>;
60
+ disconnect: () => void;
61
+ }>;
62
+ //#endregion
63
+ export { EventProxy as n, RouterProxy as r, connectRpc as t };
@@ -0,0 +1,442 @@
1
+ import zod, { infer as __Infer } from "zod";
2
+ import * as Effect from "effect/Effect";
3
+ //#region ../kyju/src/v2/db/schema.d.ts
4
+ type Field<T, HasDefault extends boolean = false> = {
5
+ schema: T;
6
+ _defaultValue: any;
7
+ readonly _hasDefault: HasDefault;
8
+ };
9
+ type BlobRef = {
10
+ type: "blob";
11
+ debugName?: string;
12
+ };
13
+ declare const __collectionRefBrand: unique symbol;
14
+ type CollectionRefBrand<T = unknown> = {
15
+ readonly [__collectionRefBrand]: T;
16
+ };
17
+ type CollectionRefValue<T = unknown> = {
18
+ collectionId: string;
19
+ debugName: string;
20
+ } & CollectionRefBrand<T>;
21
+ type InferCollectionItem<T> = T extends CollectionRefBrand<infer Item> ? Item : unknown;
22
+ type InferFieldType<T> = T extends BlobRef ? {
23
+ blobId: string;
24
+ debugName: string;
25
+ } : T extends {
26
+ _zod: {
27
+ output: any;
28
+ };
29
+ } ? __Infer<T> : never;
30
+ type FieldSchema = BlobRef | {
31
+ _zod: {
32
+ output: any;
33
+ };
34
+ };
35
+ type SchemaShape = Record<string, Field<FieldSchema, boolean> | zod.ZodType | BlobRef>;
36
+ type InferRoot<T extends SchemaShape> = { [K in keyof T]: T[K] extends BlobRef ? {
37
+ blobId: string;
38
+ debugName: string;
39
+ } : T[K] extends Field<infer S, infer D> ? S extends BlobRef ? InferFieldType<S> : [D] extends [true] ? InferFieldType<S> : InferFieldType<S> | undefined : T[K] extends zod.ZodType<infer O> ? O : never };
40
+ type InferSchema<S extends Schema> = S extends Schema<infer TShape> ? TShape : never;
41
+ type Schema<TShape extends SchemaShape = SchemaShape> = {
42
+ shape: TShape;
43
+ };
44
+ declare function createSchema<TShape extends SchemaShape>(shape: TShape): Schema<TShape>;
45
+ /**
46
+ * Standalone collection field — drop into a `createSchema({...})` shape next
47
+ * to raw zod schemas:
48
+ *
49
+ * createSchema({
50
+ * logs: collection(z.object({ id: z.string(), text: z.string() })),
51
+ * })
52
+ *
53
+ * The returned value is a marked zod schema; the runtime + serializer detect
54
+ * the marker (`__kyjuCollectionRef`) and treat the field as a paginated kyju
55
+ * collection rather than plain JSON data.
56
+ */
57
+ declare function collection<T extends zod.ZodType>(itemSchema: T, opts?: {
58
+ debugName?: string;
59
+ }): zod.ZodType<CollectionRefValue<zod.infer<T>>>;
60
+ /**
61
+ * Standalone blob field. The returned value is a `BlobRef` marker; the
62
+ * runtime detects `type: "blob"` and stores the field as a binary blob.
63
+ */
64
+ declare function blob(opts?: {
65
+ debugName?: string;
66
+ }): BlobRef;
67
+ //#endregion
68
+ //#region ../kyju/src/v2/shared.d.ts
69
+ type KyjuJSON = string | number | boolean | null | KyjuJSON[] | {
70
+ [key: string]: KyjuJSON;
71
+ };
72
+ type InvalidSessionError = {
73
+ readonly _tag: "InvalidSessionError";
74
+ readonly message: string;
75
+ };
76
+ type VersionMismatchError = {
77
+ readonly _tag: "VersionMismatchError";
78
+ readonly message: string;
79
+ };
80
+ type NotFoundError = {
81
+ readonly _tag: "NotFoundError";
82
+ readonly message: string;
83
+ };
84
+ type ReferenceExistsError = {
85
+ readonly _tag: "ReferenceExistsError";
86
+ readonly message: string;
87
+ };
88
+ type KyjuError = InvalidSessionError | VersionMismatchError | NotFoundError | ReferenceExistsError;
89
+ type ErrorTag = KyjuError["_tag"];
90
+ type Ack<T extends {} = {}, E extends ErrorTag = never> = {
91
+ type: "ack";
92
+ requestId: string;
93
+ sessionId: string;
94
+ error?: Extract<KyjuError, {
95
+ _tag: E;
96
+ }>;
97
+ } & T;
98
+ type RootSetOp = {
99
+ type: "root.set";
100
+ path: string[];
101
+ value: KyjuJSON;
102
+ };
103
+ type CollectionCreateOp = {
104
+ type: "collection.create";
105
+ collectionId: string;
106
+ data?: KyjuJSON[];
107
+ };
108
+ type CollectionConcatOp = {
109
+ type: "collection.concat";
110
+ collectionId: string;
111
+ data: KyjuJSON[];
112
+ authority?: {
113
+ startIndex: number;
114
+ totalCount: number;
115
+ };
116
+ };
117
+ type CollectionDeleteOp = {
118
+ type: "collection.delete";
119
+ collectionId: string;
120
+ };
121
+ type BlobCreateOp = {
122
+ type: "blob.create";
123
+ blobId: string;
124
+ data: Uint8Array;
125
+ hot?: boolean;
126
+ };
127
+ type BlobSetOp = {
128
+ type: "blob.set";
129
+ blobId: string;
130
+ data: Uint8Array;
131
+ };
132
+ type BlobDeleteOp = {
133
+ type: "blob.delete";
134
+ blobId: string;
135
+ };
136
+ type WriteOp = RootSetOp | CollectionCreateOp | CollectionConcatOp | CollectionDeleteOp | BlobCreateOp | BlobSetOp | BlobDeleteOp;
137
+ type CollectionFetchRangeOp = {
138
+ type: "collection.fetch-range";
139
+ collectionId: string;
140
+ range: {
141
+ start: number;
142
+ end: number;
143
+ };
144
+ };
145
+ type BlobReadOp = {
146
+ type: "blob.read";
147
+ blobId: string;
148
+ };
149
+ type ReadOp = CollectionFetchRangeOp | BlobReadOp;
150
+ type BlobMetadataUpdate = {
151
+ type: "blob.metadataUpdate";
152
+ blobId: string;
153
+ fileSize: number;
154
+ };
155
+ type ReconnectUpdate = {
156
+ type: "reconnect";
157
+ };
158
+ type DbUpdateMessage = Ack | BlobMetadataUpdate | ReconnectUpdate;
159
+ type ClientEvent = {
160
+ kind: "connect";
161
+ version: number;
162
+ } | {
163
+ kind: "disconnect";
164
+ } | {
165
+ kind: "subscribe-collection";
166
+ collectionId: string;
167
+ } | {
168
+ kind: "unsubscribe-collection";
169
+ collectionId: string;
170
+ } | {
171
+ kind: "write";
172
+ op: WriteOp;
173
+ } | {
174
+ kind: "replicated-write";
175
+ op: WriteOp;
176
+ } | {
177
+ kind: "read";
178
+ op: ReadOp;
179
+ } | {
180
+ kind: "db-update";
181
+ message: DbUpdateMessage;
182
+ };
183
+ type DbSendEvent = ClientEvent & {
184
+ replicaId: string;
185
+ };
186
+ type ServerEvent = {
187
+ kind: "connect";
188
+ message: {
189
+ type: "connect";
190
+ version: number;
191
+ requestId: string;
192
+ replicaId: string;
193
+ };
194
+ } | {
195
+ kind: "disconnect";
196
+ message: {
197
+ type: "disconnect";
198
+ sessionId: string;
199
+ requestId: string;
200
+ };
201
+ replicaId: string;
202
+ } | {
203
+ kind: "subscribe-collection";
204
+ collectionId: string;
205
+ sessionId: string;
206
+ requestId: string;
207
+ replicaId: string;
208
+ } | {
209
+ kind: "unsubscribe-collection";
210
+ collectionId: string;
211
+ sessionId: string;
212
+ requestId: string;
213
+ replicaId: string;
214
+ } | {
215
+ kind: "write";
216
+ op: WriteOp;
217
+ sessionId: string;
218
+ requestId: string;
219
+ replicaId: string;
220
+ } | {
221
+ kind: "read";
222
+ op: ReadOp;
223
+ sessionId: string;
224
+ requestId: string;
225
+ replicaId: string;
226
+ };
227
+ /**
228
+ * Replica-side collection state. The replica holds the full item set;
229
+ * paging is an internal storage concern of the database.
230
+ */
231
+ type CollectionState = {
232
+ id: string;
233
+ totalCount: number;
234
+ items: KyjuJSON[];
235
+ };
236
+ type BlobData = {
237
+ kind: "hot";
238
+ value: Uint8Array;
239
+ } | {
240
+ kind: "cold";
241
+ };
242
+ type ClientBlob = {
243
+ id: string;
244
+ data: BlobData;
245
+ fileSize: number;
246
+ };
247
+ type ClientState = {
248
+ kind: "connected";
249
+ sessionId: string;
250
+ root: KyjuJSON;
251
+ collections: CollectionState[];
252
+ blobs: ClientBlob[];
253
+ } | {
254
+ kind: "disconnected";
255
+ };
256
+ /** @deprecated Use CollectionState */
257
+ type CollectionWindow = CollectionState;
258
+ //#endregion
259
+ //#region ../kyju/src/v2/replica/replica.d.ts
260
+ type CollectionConcatCallback = (data: {
261
+ collectionId: string;
262
+ newItems: KyjuJSON[];
263
+ collection: CollectionState;
264
+ }) => void;
265
+ type CreateReplicaArgs = {
266
+ send: (event: ServerEvent) => void;
267
+ maxPageSizeBytes: number;
268
+ replicaId?: string;
269
+ };
270
+ declare const createReplica: (args: CreateReplicaArgs) => {
271
+ postMessage: (event: ClientEvent) => Promise<void>;
272
+ postMessageEffect: (event: ClientEvent) => Effect.Effect<undefined, any, never>;
273
+ getState: () => ClientState;
274
+ _forceState: (state: ClientState) => void;
275
+ subscribe: (cb: (state: ClientState) => void) => (() => void);
276
+ replicaId: string;
277
+ onCollectionConcat: (collectionId: string, cb: CollectionConcatCallback) => void;
278
+ offCollectionConcat: (collectionId: string, cb: CollectionConcatCallback) => void;
279
+ };
280
+ //#endregion
281
+ //#region ../kyju/src/v2/client/client.d.ts
282
+ type EffectCollectionNode<Item> = {
283
+ concat(items: Item[]): Effect.Effect<void, KyjuError>;
284
+ read(range?: {
285
+ start: number;
286
+ end: number;
287
+ }): Effect.Effect<void, KyjuError>;
288
+ create(data?: Item[]): Effect.Effect<void, KyjuError>;
289
+ delete(): Effect.Effect<void, KyjuError>;
290
+ subscribe(cb: (value: {
291
+ collectionId: string;
292
+ debugName: string;
293
+ }) => void): () => void;
294
+ subscribeData(cb: (data: {
295
+ collection: CollectionWindow;
296
+ newItems: Item[];
297
+ }) => void): () => void;
298
+ };
299
+ type EffectBlobNode = {
300
+ read(): Effect.Effect<void, KyjuError>;
301
+ set(data: Uint8Array): Effect.Effect<void, KyjuError>;
302
+ create(data: Uint8Array, hot?: boolean): Effect.Effect<void, KyjuError>;
303
+ delete(): Effect.Effect<void, KyjuError>;
304
+ };
305
+ type EffectFieldNode<T> = T extends CollectionRefBrand<infer Item> ? EffectCollectionNode<Item> : T extends Array<infer E> ? EffectArrayFieldNode<T, E> : {
306
+ read(): T;
307
+ set(value: T): Effect.Effect<void, KyjuError>;
308
+ subscribe(cb: (value: T) => void): () => void;
309
+ } & (T extends Record<string, any> ? { [K in keyof T]: EffectFieldNode<T[K]> } : {});
310
+ type EffectArrayFieldNode<T extends Array<any>, E> = {
311
+ read(): T;
312
+ set(value: T): Effect.Effect<void, KyjuError>;
313
+ subscribe(cb: (value: T) => void): () => void;
314
+ length: number;
315
+ find(predicate: (item: E, index: number, arr: E[]) => boolean): EffectFieldNode<E> | undefined;
316
+ findIndex(predicate: (item: E, index: number, arr: E[]) => boolean): number;
317
+ at(index: number): EffectFieldNode<E> | undefined;
318
+ map<U>(fn: (item: E, index: number, arr: E[]) => U): U[];
319
+ filter(predicate: (item: E, index: number, arr: E[]) => boolean): E[];
320
+ some(predicate: (item: E, index: number, arr: E[]) => boolean): boolean;
321
+ every(predicate: (item: E, index: number, arr: E[]) => boolean): boolean;
322
+ forEach(fn: (item: E, index: number, arr: E[]) => void): void;
323
+ reduce<U>(fn: (acc: U, item: E, index: number, arr: E[]) => U, initial: U): U;
324
+ indexOf(item: E, fromIndex?: number): number;
325
+ includes(item: E, fromIndex?: number): boolean;
326
+ slice(start?: number, end?: number): E[];
327
+ flatMap<U>(fn: (item: E, index: number, arr: E[]) => U | U[]): U[];
328
+ join(separator?: string): string;
329
+ [Symbol.iterator](): IterableIterator<E>;
330
+ [index: number]: EffectFieldNode<E>;
331
+ };
332
+ type CollectionNode<Item> = {
333
+ concat(items: Item[]): Promise<void>;
334
+ read(range?: {
335
+ start: number;
336
+ end: number;
337
+ }): Promise<void>;
338
+ create(data?: Item[]): Promise<void>;
339
+ delete(): Promise<void>;
340
+ subscribe(cb: (value: {
341
+ collectionId: string;
342
+ debugName: string;
343
+ }) => void): () => void;
344
+ subscribeData(cb: (data: {
345
+ collection: CollectionWindow;
346
+ newItems: Item[];
347
+ }) => void): () => void;
348
+ };
349
+ type BlobNode = {
350
+ read(): Promise<void>;
351
+ set(data: Uint8Array): Promise<void>;
352
+ create(data: Uint8Array, hot?: boolean): Promise<void>;
353
+ delete(): Promise<void>;
354
+ };
355
+ type FieldNode<T> = T extends CollectionRefBrand<infer Item> ? CollectionNode<Item> : T extends Array<infer E> ? ArrayFieldNode<T, E> : {
356
+ read(): T;
357
+ set(value: T): Promise<void>;
358
+ subscribe(cb: (value: T) => void): () => void;
359
+ } & (T extends Record<string, any> ? { [K in keyof T]: FieldNode<T[K]> } : {});
360
+ type ArrayFieldNode<T extends Array<any>, E> = {
361
+ read(): T;
362
+ set(value: T): Promise<void>;
363
+ subscribe(cb: (value: T) => void): () => void;
364
+ length: number;
365
+ find(predicate: (item: E, index: number, arr: E[]) => boolean): FieldNode<E> | undefined;
366
+ findIndex(predicate: (item: E, index: number, arr: E[]) => boolean): number;
367
+ at(index: number): FieldNode<E> | undefined;
368
+ map<U>(fn: (item: E, index: number, arr: E[]) => U): U[];
369
+ filter(predicate: (item: E, index: number, arr: E[]) => boolean): E[];
370
+ some(predicate: (item: E, index: number, arr: E[]) => boolean): boolean;
371
+ every(predicate: (item: E, index: number, arr: E[]) => boolean): boolean;
372
+ forEach(fn: (item: E, index: number, arr: E[]) => void): void;
373
+ reduce<U>(fn: (acc: U, item: E, index: number, arr: E[]) => U, initial: U): U;
374
+ indexOf(item: E, fromIndex?: number): number;
375
+ includes(item: E, fromIndex?: number): boolean;
376
+ slice(start?: number, end?: number): E[];
377
+ flatMap<U>(fn: (item: E, index: number, arr: E[]) => U | U[]): U[];
378
+ join(separator?: string): string;
379
+ [Symbol.iterator](): IterableIterator<E>;
380
+ [index: number]: FieldNode<E>;
381
+ };
382
+ type ResolveField<V> = V extends Field<infer S, boolean> ? InferFieldType<S> : V extends zod.ZodType<infer O> ? O : never;
383
+ type EffectClientProxy<Shape extends SchemaShape> = { [K in keyof Shape]: Shape[K] extends Field<BlobRef, boolean> ? EffectBlobNode : EffectFieldNode<ResolveField<Shape[K]>> } & {
384
+ readRoot(): InferRoot<Shape>;
385
+ update(fn: (root: InferRoot<Shape>) => void | InferRoot<Shape>): Effect.Effect<void, KyjuError>;
386
+ createBlob(data: Uint8Array, hot?: boolean): Effect.Effect<string, KyjuError>;
387
+ deleteBlob(blobId: string): Effect.Effect<void, KyjuError>;
388
+ getBlobData(blobId: string): Effect.Effect<Uint8Array | null, KyjuError>;
389
+ };
390
+ type ClientProxy<Shape extends SchemaShape> = { [K in keyof Shape]: Shape[K] extends Field<BlobRef, boolean> ? BlobNode : FieldNode<ResolveField<Shape[K]>> } & {
391
+ readRoot(): InferRoot<Shape>;
392
+ update(fn: (root: InferRoot<Shape>) => void | InferRoot<Shape>): Promise<void>;
393
+ createBlob(data: Uint8Array, hot?: boolean): Promise<string>;
394
+ deleteBlob(blobId: string): Promise<void>;
395
+ getBlobData(blobId: string): Promise<Uint8Array | null>;
396
+ };
397
+ //#endregion
398
+ //#region ../kyju/src/v2/transport.d.ts
399
+ declare function dbStringify(value: unknown): string;
400
+ declare function dbParse(text: string): any;
401
+ declare function createRouter(): {
402
+ send(event: DbSendEvent): void;
403
+ connection(opts: {
404
+ send: (event: DbSendEvent) => void;
405
+ postMessage: (event: ServerEvent) => Promise<void>;
406
+ }): {
407
+ receive(event: ServerEvent): Promise<void>;
408
+ close(): void;
409
+ };
410
+ };
411
+ declare function connectReplica<T extends SchemaShape>(opts: {
412
+ send: (event: ServerEvent) => void;
413
+ subscribe: (cb: (event: DbSendEvent) => void) => () => void;
414
+ maxPageSizeBytes?: number;
415
+ }): Promise<{
416
+ client: ClientProxy<T>;
417
+ replica: ReturnType<typeof createReplica>;
418
+ disconnect: () => Promise<void>;
419
+ }>;
420
+ //#endregion
421
+ //#region ../kyju/src/v2/db/db.d.ts
422
+ type Db<TShape extends SchemaShape = SchemaShape> = {
423
+ postMessage: (event: ServerEvent) => Promise<void>;
424
+ reconnectClients: () => Promise<void>;
425
+ /**
426
+ * Drain the lagged-persistence queue: writes that were applied to the
427
+ * in-memory root cache but not yet committed to disk. Idempotent and
428
+ * cheap when nothing is pending. Call before clean shutdown to ensure
429
+ * durability of any writes that completed during this process's lifetime.
430
+ */
431
+ flush: () => Promise<void>;
432
+ /**
433
+ * Flush + release the cross-process lock at `<dbPath>/.lock`. Idempotent;
434
+ * safe to call from a `process.on("exit")` handler. After `close()`
435
+ * resolves, another process can open the same `dbPath` without conflict.
436
+ */
437
+ close: () => Promise<void>;
438
+ client: ClientProxy<TShape>;
439
+ effectClient: EffectClientProxy<TShape>;
440
+ };
441
+ //#endregion
442
+ export { createSchema as S, InferSchema as _, dbStringify as a, blob as b, EffectFieldNode as c, KyjuError as d, CollectionRefBrand as f, InferRoot as g, InferCollectionItem as h, dbParse as i, FieldNode as l, Field as m, connectReplica as n, ClientProxy as o, CollectionRefValue as p, createRouter as r, CollectionNode as s, Db as t, CollectionState as u, Schema as v, collection as x, SchemaShape as y };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,6 @@
1
+ import { t as bootstrapEnv } from "./env-bootstrap-BtVME-CU.mjs";
2
+ import { t as setupGate } from "./setup-gate-BqOzm7zp.mjs";
3
+ import { a as runtime, i as optional, n as Service, o as serviceWithDeps, r as ServiceRuntime, t as CleanupReason } from "./runtime-CjqDr8Yf.mjs";
4
+ import { n as SchemaRoot, o as schema, t as CoreSchema } from "./schema-DMoSkwUx.mjs";
5
+ import { i as CoreServiceRouter, n as CoreEvents, r as CorePreloads, t as CoreDbSections } from "./registry-Dh_e7HU1.mjs";
6
+ export { CleanupReason, CoreDbSections, CoreEvents, CorePreloads, CoreSchema, SchemaRoot as CoreSchemaRoot, CoreServiceRouter, Service, ServiceRuntime, bootstrapEnv, schema as coreSchema, optional, runtime, serviceWithDeps, setupGate };
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import { t as bootstrapEnv } from "./env-bootstrap-rj7I-59x.mjs";
2
+ import { t as setupGate } from "./setup-gate-BeD6WS6d.mjs";
3
+ import { a as serviceWithDeps, i as runtime, n as ServiceRuntime, r as optional, t as Service } from "./runtime-DUFKDIe4.mjs";
4
+ import { t as schema } from "./schema-dGK6qkfR.mjs";
5
+ export { Service, ServiceRuntime, bootstrapEnv, schema as coreSchema, optional, runtime, serviceWithDeps, setupGate };