@loro-dev/roost 0.1.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/LICENSE +21 -0
- package/README.md +397 -0
- package/dist/codec.d.ts +66 -0
- package/dist/codec.js +275 -0
- package/dist/crypto.d.ts +21 -0
- package/dist/crypto.js +103 -0
- package/dist/durable-framing.d.ts +44 -0
- package/dist/durable-framing.js +207 -0
- package/dist/framing.d.ts +28 -0
- package/dist/framing.js +144 -0
- package/dist/history-publication.d.ts +58 -0
- package/dist/history-publication.js +234 -0
- package/dist/identity.d.ts +14 -0
- package/dist/identity.js +62 -0
- package/dist/inbox.d.ts +69 -0
- package/dist/inbox.js +262 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +6 -0
- package/dist/indexeddb.d.ts +38 -0
- package/dist/indexeddb.js +299 -0
- package/dist/json.d.ts +23 -0
- package/dist/json.js +221 -0
- package/dist/lody-history.d.ts +397 -0
- package/dist/lody-history.js +1559 -0
- package/dist/projection.d.ts +53 -0
- package/dist/projection.js +543 -0
- package/dist/replay.d.ts +63 -0
- package/dist/replay.js +201 -0
- package/dist/sender.d.ts +26 -0
- package/dist/sender.js +67 -0
- package/dist/store.d.ts +384 -0
- package/dist/store.js +1437 -0
- package/dist/sync/coverage.d.ts +276 -0
- package/dist/sync/coverage.js +1084 -0
- package/dist/sync/crypto.d.ts +64 -0
- package/dist/sync/crypto.js +155 -0
- package/dist/sync/execute.d.ts +142 -0
- package/dist/sync/execute.js +321 -0
- package/dist/sync/history.d.ts +214 -0
- package/dist/sync/history.js +786 -0
- package/dist/sync/index.d.ts +17 -0
- package/dist/sync/index.js +9 -0
- package/dist/sync/link.d.ts +192 -0
- package/dist/sync/link.js +663 -0
- package/dist/sync/mod.d.ts +24 -0
- package/dist/sync/mod.js +15 -0
- package/dist/sync/policy.d.ts +62 -0
- package/dist/sync/policy.js +128 -0
- package/dist/sync/registry.d.ts +129 -0
- package/dist/sync/registry.js +333 -0
- package/dist/sync/transport.d.ts +91 -0
- package/dist/sync/transport.js +162 -0
- package/dist/sync/work.d.ts +351 -0
- package/dist/sync/work.js +1344 -0
- package/package.json +47 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-injected payload crypto for the sync transport (Spec §9 / Q5), the
|
|
3
|
+
* IndexedDB-side mirror of src/sync/crypto.rs. The library does not store
|
|
4
|
+
* keys, pick algorithms, or rotate credentials. Encrypt/decrypt run outside
|
|
5
|
+
* every database transaction. Failure never falls back to plaintext. The
|
|
6
|
+
* durable executor stores the first successful envelope before sending it;
|
|
7
|
+
* retries reuse those bytes after reopening too. Hosts choose nonces according
|
|
8
|
+
* to their algorithm; deterministic encryption is not required. Direct
|
|
9
|
+
* transport calls do not provide cross-process durable binding.
|
|
10
|
+
*/
|
|
11
|
+
/** Failure of host-injected encrypt/decrypt. Never a cue to send or import
|
|
12
|
+
* plaintext instead. */
|
|
13
|
+
export declare class CryptoError extends Error {
|
|
14
|
+
constructor(message: string, options?: ErrorOptions);
|
|
15
|
+
}
|
|
16
|
+
/** Host-supplied payload transform. Called only from the transport / history
|
|
17
|
+
* reader, never from a storage transaction. Implementations must throw
|
|
18
|
+
* `CryptoError` (or any Error) on failure — the caller maps it to a typed
|
|
19
|
+
* rejection and never sends or imports plaintext. */
|
|
20
|
+
export interface PayloadCrypto {
|
|
21
|
+
encrypt(plaintext: Uint8Array): Uint8Array;
|
|
22
|
+
decrypt(ciphertext: Uint8Array): Uint8Array;
|
|
23
|
+
}
|
|
24
|
+
/** Wire envelope around one encrypted append: `RSE1 || u32_be(len) || ct`. */
|
|
25
|
+
export declare const ENVELOPE_MAGIC: Uint8Array<ArrayBuffer>;
|
|
26
|
+
/** Encrypt `plaintext` and wrap it as one stream message. */
|
|
27
|
+
export declare function sealEnvelope(crypto: PayloadCrypto, plaintext: Uint8Array): Uint8Array;
|
|
28
|
+
/** Open one envelope (one append body) to plaintext. */
|
|
29
|
+
export declare function openEnvelope(crypto: PayloadCrypto, wire: Uint8Array): Uint8Array;
|
|
30
|
+
/** Open a concatenation of complete envelopes (a forward catch-up page).
|
|
31
|
+
* A truncated or mixed-plaintext page is a typed failure, never a silent
|
|
32
|
+
* plaintext import. */
|
|
33
|
+
export declare function openConcatenated(crypto: PayloadCrypto, wire: Uint8Array): Uint8Array;
|
|
34
|
+
/** Open every complete envelope at the front of `wire` and return the
|
|
35
|
+
* leftover incomplete envelope bytes (empty when the page ends on a
|
|
36
|
+
* boundary). A mixed-plaintext prefix is a typed failure. */
|
|
37
|
+
export declare function openConcatenatedPrefix(crypto: PayloadCrypto, wire: Uint8Array): {
|
|
38
|
+
plaintext: Uint8Array;
|
|
39
|
+
leftover: Uint8Array;
|
|
40
|
+
};
|
|
41
|
+
/** Open the first complete envelope at the front of `wire`.
|
|
42
|
+
* `undefined` means `wire` is empty or a truncated prefix of one envelope.
|
|
43
|
+
* The number is the envelope's wire length (`8 + ciphertext`). */
|
|
44
|
+
export declare function openFirstEnvelope(crypto: PayloadCrypto, wire: Uint8Array): {
|
|
45
|
+
plaintext: Uint8Array;
|
|
46
|
+
wireLen: number;
|
|
47
|
+
} | undefined;
|
|
48
|
+
/** Async-capable host transform, including WebCrypto. Sync implementations also
|
|
49
|
+
* satisfy this interface. Every awaited operation remains outside DB transactions. */
|
|
50
|
+
export interface AsyncPayloadCrypto {
|
|
51
|
+
encrypt(plaintext: Uint8Array): Uint8Array | Promise<Uint8Array>;
|
|
52
|
+
decrypt(ciphertext: Uint8Array): Uint8Array | Promise<Uint8Array>;
|
|
53
|
+
}
|
|
54
|
+
export declare function sealEnvelopeAsync(crypto: AsyncPayloadCrypto, plaintext: Uint8Array): Promise<Uint8Array>;
|
|
55
|
+
export declare function openEnvelopeAsync(crypto: AsyncPayloadCrypto, wire: Uint8Array): Promise<Uint8Array>;
|
|
56
|
+
export declare function openFirstEnvelopeAsync(crypto: AsyncPayloadCrypto, wire: Uint8Array): Promise<{
|
|
57
|
+
plaintext: Uint8Array;
|
|
58
|
+
wireLen: number;
|
|
59
|
+
} | undefined>;
|
|
60
|
+
export declare function openConcatenatedPrefixAsync(crypto: AsyncPayloadCrypto, wire: Uint8Array): Promise<{
|
|
61
|
+
plaintext: Uint8Array;
|
|
62
|
+
leftover: Uint8Array;
|
|
63
|
+
}>;
|
|
64
|
+
export declare function openConcatenatedAsync(crypto: AsyncPayloadCrypto, wire: Uint8Array): Promise<Uint8Array>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-injected payload crypto for the sync transport (Spec §9 / Q5), the
|
|
3
|
+
* IndexedDB-side mirror of src/sync/crypto.rs. The library does not store
|
|
4
|
+
* keys, pick algorithms, or rotate credentials. Encrypt/decrypt run outside
|
|
5
|
+
* every database transaction. Failure never falls back to plaintext. The
|
|
6
|
+
* durable executor stores the first successful envelope before sending it;
|
|
7
|
+
* retries reuse those bytes after reopening too. Hosts choose nonces according
|
|
8
|
+
* to their algorithm; deterministic encryption is not required. Direct
|
|
9
|
+
* transport calls do not provide cross-process durable binding.
|
|
10
|
+
*/
|
|
11
|
+
/** Failure of host-injected encrypt/decrypt. Never a cue to send or import
|
|
12
|
+
* plaintext instead. */
|
|
13
|
+
export class CryptoError extends Error {
|
|
14
|
+
constructor(message, options) {
|
|
15
|
+
super(message, options);
|
|
16
|
+
this.name = 'CryptoError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Wire envelope around one encrypted append: `RSE1 || u32_be(len) || ct`. */
|
|
20
|
+
export const ENVELOPE_MAGIC = new Uint8Array([0x52, 0x53, 0x45, 0x31]);
|
|
21
|
+
const magicAt = (buf, i) => buf.length >= i + 4
|
|
22
|
+
&& buf[i] === 0x52 && buf[i + 1] === 0x53 && buf[i + 2] === 0x45 && buf[i + 3] === 0x31;
|
|
23
|
+
const readU32be = (buf, i) => {
|
|
24
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
25
|
+
return view.getUint32(i, false);
|
|
26
|
+
};
|
|
27
|
+
const writeU32be = (n) => {
|
|
28
|
+
const out = new Uint8Array(4);
|
|
29
|
+
new DataView(out.buffer).setUint32(0, n, false);
|
|
30
|
+
return out;
|
|
31
|
+
};
|
|
32
|
+
/** Encrypt `plaintext` and wrap it as one stream message. */
|
|
33
|
+
export function sealEnvelope(crypto, plaintext) {
|
|
34
|
+
const ciphertext = crypto.encrypt(plaintext);
|
|
35
|
+
if (ciphertext.byteLength > 0xFFFFFFFF)
|
|
36
|
+
throw new CryptoError('ciphertext length overflows u32');
|
|
37
|
+
const out = new Uint8Array(8 + ciphertext.byteLength);
|
|
38
|
+
out.set(ENVELOPE_MAGIC, 0);
|
|
39
|
+
out.set(writeU32be(ciphertext.byteLength), 4);
|
|
40
|
+
out.set(ciphertext, 8);
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** Open one envelope (one append body) to plaintext. */
|
|
44
|
+
export function openEnvelope(crypto, wire) {
|
|
45
|
+
if (wire.length < 8 || !magicAt(wire, 0))
|
|
46
|
+
throw new CryptoError('missing stream envelope (refusing plaintext fallback)');
|
|
47
|
+
const len = readU32be(wire, 4);
|
|
48
|
+
if (wire.length !== 8 + len)
|
|
49
|
+
throw new CryptoError('envelope length mismatch');
|
|
50
|
+
return crypto.decrypt(wire.subarray(8));
|
|
51
|
+
}
|
|
52
|
+
/** Open a concatenation of complete envelopes (a forward catch-up page).
|
|
53
|
+
* A truncated or mixed-plaintext page is a typed failure, never a silent
|
|
54
|
+
* plaintext import. */
|
|
55
|
+
export function openConcatenated(crypto, wire) {
|
|
56
|
+
const { plaintext, leftover } = openConcatenatedPrefix(crypto, wire);
|
|
57
|
+
if (leftover.length !== 0)
|
|
58
|
+
throw new CryptoError('truncated envelope');
|
|
59
|
+
return plaintext;
|
|
60
|
+
}
|
|
61
|
+
/** Open every complete envelope at the front of `wire` and return the
|
|
62
|
+
* leftover incomplete envelope bytes (empty when the page ends on a
|
|
63
|
+
* boundary). A mixed-plaintext prefix is a typed failure. */
|
|
64
|
+
export function openConcatenatedPrefix(crypto, wire) {
|
|
65
|
+
const chunks = [];
|
|
66
|
+
let i = 0;
|
|
67
|
+
let total = 0;
|
|
68
|
+
while (i < wire.length) {
|
|
69
|
+
if (i + 8 > wire.length)
|
|
70
|
+
return { plaintext: concat(chunks, total), leftover: wire.subarray(i) };
|
|
71
|
+
if (!magicAt(wire, i))
|
|
72
|
+
throw new CryptoError('truncated or mixed plaintext on an encrypted stream');
|
|
73
|
+
const len = readU32be(wire, i + 4);
|
|
74
|
+
const end = i + 8 + len;
|
|
75
|
+
if (end > wire.length)
|
|
76
|
+
return { plaintext: concat(chunks, total), leftover: wire.subarray(i) };
|
|
77
|
+
const plain = crypto.decrypt(wire.subarray(i + 8, end));
|
|
78
|
+
chunks.push(plain);
|
|
79
|
+
total += plain.length;
|
|
80
|
+
i = end;
|
|
81
|
+
}
|
|
82
|
+
return { plaintext: concat(chunks, total), leftover: new Uint8Array() };
|
|
83
|
+
}
|
|
84
|
+
function concat(chunks, total) {
|
|
85
|
+
const out = new Uint8Array(total);
|
|
86
|
+
let at = 0;
|
|
87
|
+
for (const chunk of chunks) {
|
|
88
|
+
out.set(chunk, at);
|
|
89
|
+
at += chunk.length;
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
/** Open the first complete envelope at the front of `wire`.
|
|
94
|
+
* `undefined` means `wire` is empty or a truncated prefix of one envelope.
|
|
95
|
+
* The number is the envelope's wire length (`8 + ciphertext`). */
|
|
96
|
+
export function openFirstEnvelope(crypto, wire) {
|
|
97
|
+
if (wire.length === 0)
|
|
98
|
+
return undefined;
|
|
99
|
+
if (wire.length < 8)
|
|
100
|
+
return undefined;
|
|
101
|
+
if (!magicAt(wire, 0))
|
|
102
|
+
throw new CryptoError('truncated or mixed plaintext on an encrypted stream');
|
|
103
|
+
const len = readU32be(wire, 4);
|
|
104
|
+
const end = 8 + len;
|
|
105
|
+
if (end > wire.length)
|
|
106
|
+
return undefined;
|
|
107
|
+
return { plaintext: crypto.decrypt(wire.subarray(8, end)), wireLen: end };
|
|
108
|
+
}
|
|
109
|
+
export async function sealEnvelopeAsync(crypto, plaintext) {
|
|
110
|
+
const ciphertext = await crypto.encrypt(plaintext);
|
|
111
|
+
if (ciphertext.byteLength > 0xFFFFFFFF)
|
|
112
|
+
throw new CryptoError('ciphertext length overflows u32');
|
|
113
|
+
const out = new Uint8Array(8 + ciphertext.byteLength);
|
|
114
|
+
out.set(ENVELOPE_MAGIC, 0);
|
|
115
|
+
out.set(writeU32be(ciphertext.byteLength), 4);
|
|
116
|
+
out.set(ciphertext, 8);
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
export async function openEnvelopeAsync(crypto, wire) {
|
|
120
|
+
if (wire.length < 8 || !magicAt(wire, 0))
|
|
121
|
+
throw new CryptoError('missing stream envelope (refusing plaintext fallback)');
|
|
122
|
+
if (wire.length !== 8 + readU32be(wire, 4))
|
|
123
|
+
throw new CryptoError('envelope length mismatch');
|
|
124
|
+
return await crypto.decrypt(wire.subarray(8));
|
|
125
|
+
}
|
|
126
|
+
export async function openFirstEnvelopeAsync(crypto, wire) {
|
|
127
|
+
if (wire.length < 8)
|
|
128
|
+
return undefined;
|
|
129
|
+
if (!magicAt(wire, 0))
|
|
130
|
+
throw new CryptoError('truncated or mixed plaintext on an encrypted stream');
|
|
131
|
+
const end = 8 + readU32be(wire, 4);
|
|
132
|
+
if (end > wire.length)
|
|
133
|
+
return undefined;
|
|
134
|
+
return { plaintext: await crypto.decrypt(wire.subarray(8, end)), wireLen: end };
|
|
135
|
+
}
|
|
136
|
+
export async function openConcatenatedPrefixAsync(crypto, wire) {
|
|
137
|
+
const chunks = [];
|
|
138
|
+
let total = 0;
|
|
139
|
+
let at = 0;
|
|
140
|
+
while (at < wire.length) {
|
|
141
|
+
const opened = await openFirstEnvelopeAsync(crypto, wire.subarray(at));
|
|
142
|
+
if (opened === undefined)
|
|
143
|
+
break;
|
|
144
|
+
chunks.push(opened.plaintext);
|
|
145
|
+
total += opened.plaintext.length;
|
|
146
|
+
at += opened.wireLen;
|
|
147
|
+
}
|
|
148
|
+
return { plaintext: concat(chunks, total), leftover: wire.subarray(at) };
|
|
149
|
+
}
|
|
150
|
+
export async function openConcatenatedAsync(crypto, wire) {
|
|
151
|
+
const { plaintext, leftover } = await openConcatenatedPrefixAsync(crypto, wire);
|
|
152
|
+
if (leftover.length !== 0)
|
|
153
|
+
throw new CryptoError('truncated envelope');
|
|
154
|
+
return plaintext;
|
|
155
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { IndexedDbStorage } from '../indexeddb.js';
|
|
2
|
+
import type { Stream } from '../store.js';
|
|
3
|
+
import type { MarkResult } from './coverage.js';
|
|
4
|
+
import type { RemoteId } from './registry.js';
|
|
5
|
+
import { RemoteRegistry } from './registry.js';
|
|
6
|
+
import { WorkStore } from './work.js';
|
|
7
|
+
import type { DiscoverResult, ResumePlan, TaskRef, WorkScope } from './work.js';
|
|
8
|
+
/**
|
|
9
|
+
* Dependency-first backfill execution (RS2-03), the IndexedDB mirror of
|
|
10
|
+
* src/sync/execute.rs: the wiring between the host's stream store and the
|
|
11
|
+
* durable sync stores. An Executor composes, over the device's single storage
|
|
12
|
+
* owner: startup recovery (`resume` — the work store's rebuilds plus an
|
|
13
|
+
* automatic replay of persisted `acked_local` confirms, F2), bounded paged
|
|
14
|
+
* discovery (`discoverCycle` and the targeted compensation `discoverTurns`),
|
|
15
|
+
* and the send loop (`flush` — candidates sweep, `acquire` (T2 re-checks the
|
|
16
|
+
* dependency gate), transport append, `ack`, `confirm` bound to the
|
|
17
|
+
* registry's current generation, all network I/O outside every transaction).
|
|
18
|
+
*
|
|
19
|
+
* # Discovery contract
|
|
20
|
+
*
|
|
21
|
+
* Discovery first reads bounded pages of the local event journal. Each
|
|
22
|
+
* Changed record offers its exact operation, irrespective of Turn ID or
|
|
23
|
+
* import source. Tasks, indexes and the per-target event checkpoint commit
|
|
24
|
+
* together with a CAS on the previous checkpoint; stale batches write
|
|
25
|
+
* nothing. Known exact operations are adopted from this target's coverage.
|
|
26
|
+
*
|
|
27
|
+
* Open-turn tracking and the forward header scan remain as repair paths for
|
|
28
|
+
* explicitly seeded/legacy work. Event discovery advances the compatible
|
|
29
|
+
* Turn ID high-water mark too, avoiding duplicate exports through those
|
|
30
|
+
* paths. The event checkpoint catches late older IDs across restarts;
|
|
31
|
+
* ordinary relay needs no host call to `discoverTurns`.
|
|
32
|
+
*
|
|
33
|
+
* # Send contract
|
|
34
|
+
*
|
|
35
|
+
* `flush` sweeps the ungated candidates in (Turn ID, seq) order and lets
|
|
36
|
+
* `acquire` re-check the
|
|
37
|
+
* dependency gate per task (T2); gate failures collect into a straggler list
|
|
38
|
+
* retried while progress is made. Every confirm re-reads the registry's
|
|
39
|
+
* current generation *inside* the confirm transaction (CASE-02 consumer side,
|
|
40
|
+
* G009). Packages are sent exactly as frozen at `acquire` (T2) — a retry
|
|
41
|
+
* after a lost ack or a transport failure resends byte-identical bytes.
|
|
42
|
+
*
|
|
43
|
+
* This module performs no network I/O of its own; the caller supplies a
|
|
44
|
+
* SendTransport. Module name and API shape are provisional (D-PORTS pending).
|
|
45
|
+
*/
|
|
46
|
+
/** The minimal upload port of a target (StreamTransport's send subset):
|
|
47
|
+
* append one frozen package; resolving is the target's durable-store signal
|
|
48
|
+
* (the ack). The transport performs no retries of its own and never runs
|
|
49
|
+
* inside a database transaction. Rejections must throw a TransportError. */
|
|
50
|
+
export interface SendTransport {
|
|
51
|
+
append(pkg: Uint8Array): Promise<void>;
|
|
52
|
+
/** Transform plaintext into the exact bytes that will be appended.
|
|
53
|
+
* Default: identity. Encrypted transports return an envelope. */
|
|
54
|
+
seal?(pkg: Uint8Array): Uint8Array | Promise<Uint8Array>;
|
|
55
|
+
/** Append exact wire bytes. Encrypted transports must not encrypt again. */
|
|
56
|
+
appendWire?(body: Uint8Array): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
/** Typed transport outcomes the scheduler distinguishes. */
|
|
59
|
+
export declare class TransportError extends Error {
|
|
60
|
+
readonly code: 'unavailable' | 'rejected';
|
|
61
|
+
constructor(code: 'unavailable' | 'rejected', message?: string);
|
|
62
|
+
}
|
|
63
|
+
/** Errors of executor operations. Semantic rejections roll their transaction
|
|
64
|
+
* back; nothing is half-committed. */
|
|
65
|
+
export declare class ExecuteError extends Error {
|
|
66
|
+
readonly code: 'work' | 'registry' | 'store' | 'invalid';
|
|
67
|
+
constructor(code: 'work' | 'registry' | 'store' | 'invalid', message?: string, options?: ErrorOptions);
|
|
68
|
+
}
|
|
69
|
+
/** Result of `Executor.resume`: the work store's recovery plan plus the
|
|
70
|
+
* confirms the executor replayed on the host's behalf (F2). */
|
|
71
|
+
export type ResumeReport = {
|
|
72
|
+
plan: ResumePlan;
|
|
73
|
+
/** `acked_local` tasks whose confirm semantics were replayed; each
|
|
74
|
+
* replay is byte-idempotent (a re-mark is a duplicate). */
|
|
75
|
+
replayed: TaskRef[];
|
|
76
|
+
};
|
|
77
|
+
/** Result of one `Executor.discoverCycle`. */
|
|
78
|
+
export type DiscoverReport = {
|
|
79
|
+
/** Header visits while offering operations or checking repair paths. */
|
|
80
|
+
turnsScanned: number;
|
|
81
|
+
/** Ops that became new tasks (duplicates excluded). */
|
|
82
|
+
tasksCreated: number;
|
|
83
|
+
/** Compatible Turn ID high-water mark, not the local event checkpoint
|
|
84
|
+
* or proof that the target has received every earlier Turn. */
|
|
85
|
+
cursor: Uint8Array | undefined;
|
|
86
|
+
};
|
|
87
|
+
/** Result of one `Executor.flush`. */
|
|
88
|
+
export type FlushReport = {
|
|
89
|
+
/** Tasks acquired and appended to the target, in send order. */
|
|
90
|
+
sent: TaskRef[];
|
|
91
|
+
/** Tasks confirmed (with their atomic coverage mark) after the target's
|
|
92
|
+
* store signal, in confirm order. */
|
|
93
|
+
confirmed: {
|
|
94
|
+
task: TaskRef;
|
|
95
|
+
coverage: MarkResult;
|
|
96
|
+
}[];
|
|
97
|
+
/** Set when a transport error stopped the round early; the failed task
|
|
98
|
+
* stays `inflight` and a later flush retries the identical bytes. */
|
|
99
|
+
transportError: TransportError | undefined;
|
|
100
|
+
/** Tasks waiting for their local bytes (`pending_local`) — a report to
|
|
101
|
+
* the host, never a send and never a blocker for other scopes. */
|
|
102
|
+
waitingLocal: TaskRef[];
|
|
103
|
+
};
|
|
104
|
+
/** The backfill executor: a stateless composition over the device's single
|
|
105
|
+
* storage owner; all progress lives in the work store. */
|
|
106
|
+
export declare class Executor {
|
|
107
|
+
#private;
|
|
108
|
+
readonly storage: IndexedDbStorage;
|
|
109
|
+
constructor(storage: IndexedDbStorage);
|
|
110
|
+
/** Host access to the underlying work store (e.g. `fillBytes` for
|
|
111
|
+
* locally-fetched packages or direct task inspection). */
|
|
112
|
+
workStore(): WorkStore;
|
|
113
|
+
/** The work scope of one registered remote and stream, bound to the
|
|
114
|
+
* registry's current generation. */
|
|
115
|
+
scope(registry: RemoteRegistry, remote: RemoteId, stream: string): Promise<WorkScope>;
|
|
116
|
+
/** Startup recovery: the work store's resume (including the prefix
|
|
117
|
+
* watermark rebuild for pre-watermark databases and the open-turn set
|
|
118
|
+
* rebuild for pre-G009 databases) followed by an automatic,
|
|
119
|
+
* byte-idempotent replay of every persisted `acked_local` confirm (F2).
|
|
120
|
+
* Each replay runs the same atomic confirm as the send loop, with the
|
|
121
|
+
* registry generation re-read inside the confirm transaction. */
|
|
122
|
+
resume(scope: WorkScope): Promise<ResumeReport>;
|
|
123
|
+
/** Drain local event pages, then repair explicitly seeded/legacy work
|
|
124
|
+
* through open-turn tracking and forward header pages. Tasks and the
|
|
125
|
+
* event checkpoint commit atomically. Page size bounds each read/commit,
|
|
126
|
+
* not the total work of a catch-up cycle. */
|
|
127
|
+
discoverCycle(stream: Stream, scope: WorkScope, pageSize: number): Promise<DiscoverReport>;
|
|
128
|
+
/** Optional directed discovery. Ordinary late P2P/server imports are
|
|
129
|
+
* already picked up by the event journal in `discoverCycle`.
|
|
130
|
+
* Targeted discovery never advances the global cursor (G009): a directed
|
|
131
|
+
* id above the cursor must not make the scan skip unenumerated history —
|
|
132
|
+
* the regular cycle still walks past the position later and the per-op
|
|
133
|
+
* dedupe absorbs the overlap. */
|
|
134
|
+
discoverTurns(stream: Stream, scope: WorkScope, ids: Uint8Array[]): Promise<DiscoverResult>;
|
|
135
|
+
/** Send everything runnable, bounded by `maxSend`: sweep the ungated
|
|
136
|
+
* candidates in (Turn ID, seq) keyset order and let `acquire` re-check the dependency
|
|
137
|
+
* gate per task (T2); gate failures collect into a straggler list that is
|
|
138
|
+
* retried after each sweep round while progress is made. A transport
|
|
139
|
+
* error stops the round with a typed report; the failed task stays
|
|
140
|
+
* `inflight` and a later flush retries the identical frozen bytes. */
|
|
141
|
+
flush(scope: WorkScope, transport: SendTransport, maxSend: number): Promise<FlushReport>;
|
|
142
|
+
}
|