@loro-dev/loro-repo-engine 0.1.0 → 0.2.0-next.0

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/README.md CHANGED
@@ -559,7 +559,7 @@ try {
559
559
 
560
560
  For cloud sync, register the protector first, then configure `{ remote_id: "cloud", base_url: yourStreamsUrl, encrypted: true }` with `client.configureRemote(namespace, remote)` and call `client.syncNamespace(namespace, "cloud")`. Configure bearer auth separately if the server requires it. A peer needs the same genesis and epoch keys plus `admitWriterPubkey(namespace, publicKey)` for every trusted sending device. Only admit keys authenticated by your application's verified ledger. This keyring does not fetch or verify that ledger or distribute keys.
561
561
 
562
- All genesis/seed/key/public-key arguments are exactly 32-byte `Uint8Array`s. Epochs are integers from `0` through `4294967295`. Namespace and writer names are nonempty and cannot contain NUL. `configureNamespace` rejects conflicting genesis; `installEpochKey` permits identical reinstalls and rejects conflicting material for an existing epoch. The highest installed epoch immediately becomes the seal epoch. Older installed epochs remain usable for opening history.
562
+ All genesis/seed/key/public-key arguments are exactly 32-byte `Uint8Array`s. Epochs are integers from `0` through `4294967295`. Namespace and writer names are nonempty and cannot contain NUL. `configureNamespace` rejects conflicting genesis; `installEpochKey` permits identical reinstalls and rejects conflicting material for an existing epoch. The highest installed epoch immediately becomes the seal epoch unless `setSealEpoch` fixed one; a later install does not move a fixed seal epoch. Older installed epochs remain usable for opening history. `holdSealing(ns, writer?)` refuses that writer's seals with `unauthorized` until `releaseSealing`, and `removeWriterSigner(ns, writer?)` drops its seed; both keep its public key admitted, so frames it wrote keep opening. `revokeWriterPubkey` is the only call that removes admission.
563
563
 
564
564
  `configureNamespace(namespace, genesis, seed?)` installs an optional default signer. `configureWriterSigner(namespace, writer, seed)` installs a concrete writer signer; a requested writer never falls back to the default. Both return the signer's public key and admit it locally. Replacing a signer does not revoke the previous public key: explicitly call `revokeWriterPubkey` when your authorization policy requires it. Revocation blocks both opening that writer's frames and sealing with its local signer. `clearNamespace` drops all namespace custody and admission; restore genesis, trusted writers, and required epochs before resuming sync.
565
565
 
@@ -587,3 +587,41 @@ pnpm --dir packages/client exec vitest run test/keyring.test.ts test/keyring-int
587
587
  ```
588
588
 
589
589
  `keyring-smoke.mjs` exchanges update and snapshot fixtures in both directions with a separate Rust executable, checks unknown epochs, unauthorized/revoked writers, tampering, AAD/room/offset mismatches, immutable key conflicts, and clear/restore/history behavior. Set `KEYRING_INTEROP_BIN` to override the fixture executable path. The interop test also exchanges frames with an independent TypeScript test implementation. The E2E tests require a built `loro-repo` daemon (`LORO_REPO_BIN` override supported) and use real IPC, HTTP, and native custody. They cover a held seal callback plus separate custody processes, lost and stale installation acknowledgements, crash/restart, restoration of historical keys, and epoch-2 writes after all live participants acknowledge. These checks exercise an application coordinator in a test harness; production key delivery and coordinator recovery remain application responsibilities.
590
+
591
+ ## Room Resource Lifecycle
592
+
593
+ | Operation | Releases | Retains |
594
+ | --- | --- | --- |
595
+ | `unsubscribe` | That subscription; after the last subscription the room becomes eligible for eviction and leaves remote interest | Other connections' subscriptions, outbox, persistent data |
596
+ | Connection close | All that connection's subscriptions and reverse RPC registrations | Other connections' resources and committed writes |
597
+ | Idle eviction | The in-memory room backend | Persistent data, checkpoints, outbox, room table entry |
598
+ | `deleteRoom` | The room's stored data and associated room state | This is a data operation, not a memory management tool |
599
+ | Engine stop | Directory lock and all engine memory | Persistent data |
600
+
601
+ The idle backend limit is **16 per namespace**, excluding rooms with active
602
+ subscriptions. Eviction skips locked rooms, so concurrent activity can temporarily
603
+ exceed that limit. Access reloads a backend from committed storage. Room table
604
+ entries remain until `deleteRoom`; they are not the loaded backend count.
605
+
606
+ A room without subscriptions does not receive remote real-time updates. Its
607
+ outbox still uploads when a configured remote is unpaused, including after
608
+ backend eviction or an engine restart. The directory lock belongs to the engine
609
+ lifetime and is unrelated to individual rooms. A write committed before a socket
610
+ closes stays committed even if its reply was lost; callers must reconcile an
611
+ unknown write result before retrying.
612
+
613
+ `engine.stats()` provides structured resource counters through the in-process
614
+ addon only (no wire operation): per namespace `roomEntries`, `loadedBackends`,
615
+ `docSubscriptions`, `flockSubscriptions`; globally `connections` and
616
+ `pendingOutboxNamespaces`. This is a memory-only observation: it never calls the
617
+ storage factory, queries SQLite, or creates/configures remotes. Only loaded
618
+ namespaces appear in `namespaces`. A busy room is included in `roomEntries`, but
619
+ skipped in the backend and subscription counts; those counts are lower bounds
620
+ while room operations hold locks.
621
+
622
+ `pendingOutboxNamespaces` is the background discovery index: namespaces already
623
+ discovered with unpaused upload work. It excludes paused and unprobed persisted
624
+ backlog and can lag live writes or draining. Use `getRemoteStatus` for current
625
+ storage-backed outbox counts. The result is not an atomic snapshot across
626
+ namespaces. Calling after stop throws. It includes no room IDs, keys, values or
627
+ credentials.
package/index.d.ts CHANGED
@@ -17,6 +17,13 @@ export interface EngineOptions {
17
17
  streamsUrl?: string;
18
18
  /** Maximum local IPC frame size in bytes (omitted uses `67_108_864` / `64 MiB`). */
19
19
  maxFrameBytes?: number;
20
+ /**
21
+ * Report only these capabilities, to stand in for an older build in
22
+ * compatibility tests. Serving does not change.
23
+ */
24
+ advertisedCapabilities?: string[];
25
+ /** Report this release instead, to stand in for an older release in compatibility tests. */
26
+ advertisedVersion?: string;
20
27
  }
21
28
 
22
29
  /**
@@ -35,10 +42,33 @@ export interface EngineEndpoint {
35
42
  pid: number;
36
43
  /** Wire protocol version implemented by this engine (currently `2`). */
37
44
  protocolVersion: number;
45
+ /** This release (SemVer), which orders builds for takeover. */
46
+ version: string;
47
+ /** This build's identity. */
48
+ build: string;
49
+ /** What this build serves beyond the protocol's baseline. */
50
+ capabilities: string[];
51
+ }
52
+
53
+ /** Resource counters; no room content or keys. Concurrent activity may change counts. */
54
+ export interface NamespaceStats {
55
+ namespace: string;
56
+ roomEntries: number;
57
+ loadedBackends: number;
58
+ docSubscriptions: number;
59
+ flockSubscriptions: number;
60
+ }
61
+ export interface EngineStats {
62
+ namespaces: NamespaceStats[];
63
+ connections: number;
64
+ /** Background discovery index: known unpaused backlog; excludes paused/unprobed work and can lag. */
65
+ pendingOutboxNamespaces: number;
38
66
  }
39
67
 
40
68
  /** Running in-process engine handle returned by {@link startEngine}. */
41
69
  export declare class Engine {
70
+ /** Memory-only counts. Busy rooms count only toward roomEntries; others are lower bounds while busy. Throws after stop. */
71
+ stats(): EngineStats;
42
72
  /** Published local IPC endpoint matching `<dataDir>/engine.json`. */
43
73
  get endpoint(): EngineEndpoint;
44
74
  /** `true` once the engine has exited (via `stop()`, idle timeout, or lock loss). */
@@ -65,6 +95,12 @@ export interface EngineVersion {
65
95
  package: string;
66
96
  /** Wire protocol version supported by this engine (`2`). */
67
97
  protocol: number;
98
+ /** This release (SemVer), which orders builds for takeover. */
99
+ version: string;
100
+ /** This build's identity, as `engine.json` and `engine_info` report it. */
101
+ build: string;
102
+ /** What this build serves beyond the protocol's baseline; never shrinks within a protocol. */
103
+ capabilities: string[];
68
104
  }
69
105
 
70
106
  /** Returns the engine's package version and wire protocol version before touching a `dataDir`. */
@@ -81,6 +117,15 @@ export declare function engineVersion(): EngineVersion;
81
117
  */
82
118
  export declare function runCli(args: string[]): number;
83
119
 
120
+ /**
121
+ * Closes the descriptors this process inherited from whoever launched it: every
122
+ * descriptor above stderr open without close-on-exec. A long-lived host started
123
+ * by a short-lived application otherwise keeps that application's sockets and
124
+ * pipes open after it exits. Call it first thing in a dedicated host process.
125
+ * Returns how many were closed; off Unix it closes nothing.
126
+ */
127
+ export declare function closeInheritedDescriptors(): number;
128
+
84
129
  /** Engine-provided request; pass bytes through without re-encoding or wrapping LSCE. */
85
130
  export interface ContentSealRequest {
86
131
  namespace: string;
@@ -130,11 +175,23 @@ export declare class ContentKeyring {
130
175
  /** Remove admission (including local sealing permission); idempotent, does not erase signer custody. */
131
176
  revokeWriterPubkey(namespace: string, publicKey: Uint8Array): void;
132
177
  /**
133
- * Install an integer epoch in [0, 4294967295]. Highest installed epoch immediately seals new data.
178
+ * Install an integer epoch in [0, 4294967295]. Without {@link setSealEpoch}, the highest installed epoch immediately seals new data.
134
179
  * Identical reinstall is allowed; a conflicting key for an existing epoch is rejected.
135
180
  * Retain older epochs for historical ciphertext; install only after readers are ready.
136
181
  */
137
182
  installEpochKey(namespace: string, epoch: number, key: Uint8Array): void;
183
+ /**
184
+ * Seal new content at this installed epoch instead of the highest installed one; a later
185
+ * install does not move it. Opening still uses every installed epoch. Unknown epochs fail
186
+ * with `unknown_key`.
187
+ */
188
+ setSealEpoch(namespace: string, epoch: number): void;
189
+ /** Refuse seals for `writer` (omitted: the default signer) with `unauthorized` until released; admission is kept. */
190
+ holdSealing(namespace: string, writer?: string | null): void;
191
+ /** End {@link holdSealing}; idempotent. */
192
+ releaseSealing(namespace: string, writer?: string | null): void;
193
+ /** Drop the writer's signing seed and keep its public key admitted, so its frames keep opening. */
194
+ removeWriterSigner(namespace: string, writer?: string | null): void;
138
195
  /** Drop all namespace custody and admission; idempotent. Subsequent seal/open reports missing_provider. */
139
196
  clearNamespace(namespace: string): void;
140
197
  /** Synchronous native seal; explicit writer never falls back to the default signer. Roost streams unsupported. */
package/index.js CHANGED
@@ -34,5 +34,13 @@ function load() {
34
34
  return require(`@loro-dev/loro-repo-engine-${suffix}`);
35
35
  }
36
36
 
37
- const { Engine, ContentKeyring, startEngine, engineVersion, runCli } = load();
38
- module.exports = { Engine, ContentKeyring, startEngine, engineVersion, runCli };
37
+ const { Engine, ContentKeyring, startEngine, engineVersion, runCli, closeInheritedDescriptors } =
38
+ load();
39
+ module.exports = {
40
+ Engine,
41
+ ContentKeyring,
42
+ startEngine,
43
+ engineVersion,
44
+ runCli,
45
+ closeInheritedDescriptors,
46
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loro-dev/loro-repo-engine",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-next.0",
4
4
  "description": "The loro-repo engine, prebuilt as a Node-API addon. Source is not public (D3).",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {
@@ -32,12 +32,12 @@
32
32
  ]
33
33
  },
34
34
  "optionalDependencies": {
35
- "@loro-dev/loro-repo-engine-darwin-arm64": "0.1.0",
36
- "@loro-dev/loro-repo-engine-darwin-x64": "0.1.0",
37
- "@loro-dev/loro-repo-engine-linux-x64-gnu": "0.1.0",
38
- "@loro-dev/loro-repo-engine-linux-arm64-gnu": "0.1.0",
39
- "@loro-dev/loro-repo-engine-win32-x64-msvc": "0.1.0",
40
- "@loro-dev/loro-repo-engine-win32-arm64-msvc": "0.1.0"
35
+ "@loro-dev/loro-repo-engine-darwin-arm64": "0.2.0-next.0",
36
+ "@loro-dev/loro-repo-engine-darwin-x64": "0.2.0-next.0",
37
+ "@loro-dev/loro-repo-engine-linux-x64-gnu": "0.2.0-next.0",
38
+ "@loro-dev/loro-repo-engine-linux-arm64-gnu": "0.2.0-next.0",
39
+ "@loro-dev/loro-repo-engine-win32-x64-msvc": "0.2.0-next.0",
40
+ "@loro-dev/loro-repo-engine-win32-arm64-msvc": "0.2.0-next.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@napi-rs/cli": "^3.10.0"