@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,17 @@
|
|
|
1
|
+
/** Application sync entry point. Storage keys and record DTOs remain internal. */
|
|
2
|
+
export { RemoteRegistry, RegistryError } from './registry.js';
|
|
3
|
+
export type { EndpointConfig, Generation, RemoteId, RemoteRecord } from './registry.js';
|
|
4
|
+
export { Executor, ExecuteError, TransportError } from './execute.js';
|
|
5
|
+
export type { DiscoverReport, FlushReport, ResumeReport, SendTransport } from './execute.js';
|
|
6
|
+
export { StreamsTransport } from './transport.js';
|
|
7
|
+
export type { HeadInfo, ReadPage, ReadTransport } from './transport.js';
|
|
8
|
+
export { Link, LinkError, linkLimitsForSync } from './link.js';
|
|
9
|
+
export type { BridgeReport, DownloadReport, LinkLimits, StopToken } from './link.js';
|
|
10
|
+
export { HistoryReader, HistoryError } from './history.js';
|
|
11
|
+
export type { BackwardByteSource, BackwardPage, HistoryReport, PrefixScan } from './history.js';
|
|
12
|
+
export { PolicyStore, PolicyError, DEFAULT_MIRROR_POLICY } from './policy.js';
|
|
13
|
+
export type { MirrorDirection, MirrorPolicy } from './policy.js';
|
|
14
|
+
export { CryptoError } from './crypto.js';
|
|
15
|
+
export type { PayloadCrypto, AsyncPayloadCrypto } from './crypto.js';
|
|
16
|
+
export type { WorkScope } from './work.js';
|
|
17
|
+
export { sealEnvelopeAsync, openEnvelopeAsync, openFirstEnvelopeAsync, openConcatenatedAsync, openConcatenatedPrefixAsync } from './crypto.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Application sync entry point. Storage keys and record DTOs remain internal. */
|
|
2
|
+
export { RemoteRegistry, RegistryError } from './registry.js';
|
|
3
|
+
export { Executor, ExecuteError, TransportError } from './execute.js';
|
|
4
|
+
export { StreamsTransport } from './transport.js';
|
|
5
|
+
export { Link, LinkError, linkLimitsForSync } from './link.js';
|
|
6
|
+
export { HistoryReader, HistoryError } from './history.js';
|
|
7
|
+
export { PolicyStore, PolicyError, DEFAULT_MIRROR_POLICY } from './policy.js';
|
|
8
|
+
export { CryptoError } from './crypto.js';
|
|
9
|
+
export { sealEnvelopeAsync, openEnvelopeAsync, openFirstEnvelopeAsync, openConcatenatedAsync, openConcatenatedPrefixAsync } from './crypto.js';
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { Inbox } from '../inbox.js';
|
|
2
|
+
import type { InboxLimits } from '../inbox.js';
|
|
3
|
+
import type { IndexedDbStorage } from '../indexeddb.js';
|
|
4
|
+
import { DurableReplay } from '../replay.js';
|
|
5
|
+
import type { ReplayLimits } from '../replay.js';
|
|
6
|
+
import type { ImportStatus, Stream } from '../store.js';
|
|
7
|
+
import { CoverageStore } from './coverage.js';
|
|
8
|
+
import type { CoverageScope } from './coverage.js';
|
|
9
|
+
import { Executor } from './execute.js';
|
|
10
|
+
import type { DiscoverReport, FlushReport, SendTransport } from './execute.js';
|
|
11
|
+
import { PolicyStore } from './policy.js';
|
|
12
|
+
import type { WorkScope } from './work.js';
|
|
13
|
+
import type { ReadTransport } from './transport.js';
|
|
14
|
+
/**
|
|
15
|
+
* One bidirectional sync link between a local stream and one remote (N1),
|
|
16
|
+
* the IndexedDB mirror of src/sync/link.rs: the download loop that reads
|
|
17
|
+
* the remote's durable log into the local store, layered on the existing
|
|
18
|
+
* Inbox/Replay durable machinery, plus a thin upload-cycle convenience over
|
|
19
|
+
* the RS2-03 executor.
|
|
20
|
+
*
|
|
21
|
+
* # Download contract (T4)
|
|
22
|
+
*
|
|
23
|
+
* Catch-up pages are fetched OUTSIDE every transaction
|
|
24
|
+
* (`ReadTransport.readOnce`). Each complete RST1 batch the page carries is
|
|
25
|
+
* durably received into the per-(stream, remote-generation) Inbox ledger
|
|
26
|
+
* with a cursor-chained receipt — cursor
|
|
27
|
+
* `0x01 || fetch_len[1] || fetch_offset || next_len[1] || next_offset ||
|
|
28
|
+
* byte_skip[4 BE] || page_len[4 BE]` — so a crash mid-page resumes from the
|
|
29
|
+
* head receipt's fetch offset, skips the received prefix, and re-receives
|
|
30
|
+
* the rest (exact retries are deduped by the Inbox). The Replay runner then
|
|
31
|
+
* imports each receipt in order through the real store (full
|
|
32
|
+
* seal/signature/dependency verification — nothing is trusted from the
|
|
33
|
+
* transport), and the frames it admitted (Applied/Duplicate/Pending — never
|
|
34
|
+
* Rejected) are marked present-exact on this remote's coverage scope: the
|
|
35
|
+
* K(remote) lower bound includes what the remote demonstrably serves, which
|
|
36
|
+
* is also what stops a mirrored backfill from re-uploading it. Remote
|
|
37
|
+
* imports never echo into the application outbox (the core's standing rule)
|
|
38
|
+
* and never mark coverage from bytes the store refused.
|
|
39
|
+
*
|
|
40
|
+
* Network, receipt persistence, import and coverage marks are all atomic
|
|
41
|
+
* per batch; the durable download position never advances past received
|
|
42
|
+
* work, and a stopped cycle reports itself instead of faking completion.
|
|
43
|
+
*/
|
|
44
|
+
/** Errors of link operations. Semantic rejections roll their transaction
|
|
45
|
+
* back; nothing is half-committed. */
|
|
46
|
+
export declare class LinkError extends Error {
|
|
47
|
+
readonly code: 'invalid' | 'transport' | 'inbox' | 'replay' | 'retryQuota' | 'coverage' | 'store' | 'work' | 'execute' | 'policyDenied' | 'policy';
|
|
48
|
+
constructor(code: 'invalid' | 'transport' | 'inbox' | 'replay' | 'retryQuota' | 'coverage' | 'store' | 'work' | 'execute' | 'policyDenied' | 'policy', message?: string, options?: ErrorOptions);
|
|
49
|
+
}
|
|
50
|
+
/** Explicit limits of a link's durable download ledgers. Retention is
|
|
51
|
+
* unbounded by design (no GC); the caps exist to catch corruption loops.
|
|
52
|
+
* `LinkLimits.forSync()` derives them from the wire constants; hosts may
|
|
53
|
+
* tighten per namespace. */
|
|
54
|
+
export type LinkLimits = {
|
|
55
|
+
inbox: InboxLimits;
|
|
56
|
+
replay: ReplayLimits;
|
|
57
|
+
};
|
|
58
|
+
/** Wire-derived limits: a receipt is one complete RST1 batch (bounded by the
|
|
59
|
+
* wire ceiling); cursors carry two offsets and an index; ledgers are retained
|
|
60
|
+
* without GC, so the record/byte caps are corruption tripwires, not product
|
|
61
|
+
* budgets. */
|
|
62
|
+
export declare const linkLimitsForSync: () => LinkLimits;
|
|
63
|
+
/** Result of one `Link.downloadCycle`. */
|
|
64
|
+
export type DownloadReport = {
|
|
65
|
+
/** Catch-up pages fetched. */
|
|
66
|
+
pages: number;
|
|
67
|
+
/** Complete batches durably received. */
|
|
68
|
+
batches: number;
|
|
69
|
+
/** Turns the import applied (deduped, in application order): the host's
|
|
70
|
+
* bridging signal — offer them to other scopes via
|
|
71
|
+
* `Executor.discoverTurns`. */
|
|
72
|
+
appliedTurns: Uint8Array[];
|
|
73
|
+
/** Turns whose bytes the download received but the import pended (a
|
|
74
|
+
* declared parent is not local yet, deduped): they wait for their
|
|
75
|
+
* parent's source and never stall the download — the host reports them
|
|
76
|
+
* through `Link.bridgeTurns` as `waitingParent`. */
|
|
77
|
+
pendingTurns: Uint8Array[];
|
|
78
|
+
/** The cycle reached the remote's current tail. */
|
|
79
|
+
upToDate: boolean;
|
|
80
|
+
/** The remote stream is closed at its final position. */
|
|
81
|
+
closed: boolean;
|
|
82
|
+
/** The stop token was observed; the cycle halted cleanly between
|
|
83
|
+
* receipts and makes no completeness claim. */
|
|
84
|
+
stopped: boolean;
|
|
85
|
+
/** The durable fetch position for the next cycle (the next read's
|
|
86
|
+
* offset), or undefined before any receipt. */
|
|
87
|
+
position: string | undefined;
|
|
88
|
+
};
|
|
89
|
+
/** Outcome of bridging downloaded turns into another scope's upload queue
|
|
90
|
+
* (the 代传 wiring): turns whose parents are not local yet are reported as
|
|
91
|
+
* waiting, never a permanent bridge failure (Root review checkpoint). */
|
|
92
|
+
export type BridgeReport = {
|
|
93
|
+
/** Turns whose ops entered the scope's discovery (new tasks or idempotent
|
|
94
|
+
* duplicates). */
|
|
95
|
+
discovered: Uint8Array[];
|
|
96
|
+
/** Turns that cannot be offered yet because their parent is not local:
|
|
97
|
+
* they wait for the parent's source (another remote or P2P) and the host
|
|
98
|
+
* retries this call after it lands. */
|
|
99
|
+
waitingParent: Uint8Array[];
|
|
100
|
+
};
|
|
101
|
+
/** The cooperative stop token of a download cycle (the mirror of the Rust
|
|
102
|
+
* `&AtomicBool`): the host sets `stopped` between receipts; the cycle never
|
|
103
|
+
* starts new work once observed and reports itself stopped. */
|
|
104
|
+
export type StopToken = {
|
|
105
|
+
stopped: boolean;
|
|
106
|
+
};
|
|
107
|
+
/** One bidirectional link between a local stream and one remote scope.
|
|
108
|
+
* Opened over the device's single storage owner; the download ledger
|
|
109
|
+
* namespace embeds the scope's full generation identity, so a rebound
|
|
110
|
+
* generation starts a fresh ledger while the old one stays retained. */
|
|
111
|
+
export declare class Link {
|
|
112
|
+
#private;
|
|
113
|
+
readonly scope: WorkScope;
|
|
114
|
+
readonly stream: Stream;
|
|
115
|
+
readonly inbox: Inbox;
|
|
116
|
+
readonly replay: DurableReplay;
|
|
117
|
+
readonly coverage: CoverageStore;
|
|
118
|
+
readonly executor: Executor;
|
|
119
|
+
readonly policy: PolicyStore;
|
|
120
|
+
private constructor();
|
|
121
|
+
/** Open the link for one (stream, remote-generation) scope. The scope
|
|
122
|
+
* comes from `Executor.scope`; the executor it shares is created here
|
|
123
|
+
* over the same storage owner. */
|
|
124
|
+
static open(storage: IndexedDbStorage, stream: Stream, scope: WorkScope, limits: LinkLimits): Link;
|
|
125
|
+
/** The partial-replica live path (N3/N019): receipts import through
|
|
126
|
+
* `importPartialBatch`, so a reverse-history window can keep catching
|
|
127
|
+
* up without requiring the ancestor chain. Coverage marks bind parents
|
|
128
|
+
* only where they are local. Mirror of `Link::open_partial`. */
|
|
129
|
+
static openPartial(storage: IndexedDbStorage, stream: Stream, scope: WorkScope, limits: LinkLimits): Link;
|
|
130
|
+
private static openWithReplay;
|
|
131
|
+
/** The durable fetch position of the next read (from the head receipt). */
|
|
132
|
+
position(): Promise<string | undefined>;
|
|
133
|
+
/** Start live catch-up at `offset` without importing the prefix.
|
|
134
|
+
* Used after a reverse-history window. Does not mark coverage and
|
|
135
|
+
* does not claim that prefix. Idempotent at the same offset;
|
|
136
|
+
* a different established position is a typed error. Mirror of
|
|
137
|
+
* `Link::catch_up_at`. `offset` is the tail observed when the window
|
|
138
|
+
* was fetched — a later head skips concurrent appends. */
|
|
139
|
+
catchUpAt(offset: string): Promise<void>;
|
|
140
|
+
/** One bounded download cycle: keep fetching catch-up pages until the
|
|
141
|
+
* remote's tail (up-to-date or closed), a page cap, or the stop token —
|
|
142
|
+
* each completed batch received and replayed atomically before the next.
|
|
143
|
+
* The durable position is a batch-boundary byte skip, so a batch spanning
|
|
144
|
+
* two pages is never lost on resume (HTTP responses may split or coalesce
|
|
145
|
+
* appends arbitrarily). The page cap bounds completed pages; a batch
|
|
146
|
+
* spanning into the next page is always completed first (bounded by the
|
|
147
|
+
* wire ceiling), so a page-limited host always makes progress.
|
|
148
|
+
* `pageLimit === 0` reads to the tail in one call. */
|
|
149
|
+
downloadCycle(transport: ReadTransport, pageLimit: number, stop: StopToken): Promise<DownloadReport>;
|
|
150
|
+
/** One upload cycle through the shared executor (resume → one discovery
|
|
151
|
+
* cycle → one bounded flush). Convenience over `Executor` keeping the
|
|
152
|
+
* host loop symmetrical with `downloadCycle`. */
|
|
153
|
+
uploadCycle(stream: Stream, transport: SendTransport, maxSend: number): Promise<{
|
|
154
|
+
discovery: DiscoverReport;
|
|
155
|
+
flushed: FlushReport;
|
|
156
|
+
}>;
|
|
157
|
+
/** Offer downloaded turns to another scope's upload discovery. Turns
|
|
158
|
+
* whose parents are not local are collected into `waitingParent`
|
|
159
|
+
* (retryable, never fatal), so a bridge cycle never permanently stalls
|
|
160
|
+
* behind a missing Create (RS3-02/CASE-15). */
|
|
161
|
+
bridgeTurns(stream: Stream, scope: WorkScope, ids: Uint8Array[]): Promise<BridgeReport>;
|
|
162
|
+
}
|
|
163
|
+
/** Mark present-exact on a coverage scope from the LOCAL store, for every
|
|
164
|
+
* op the import admitted (Applied/Duplicate, plus any older pending the
|
|
165
|
+
* import unlocked): the fingerprints are the exact exported frame batches —
|
|
166
|
+
* byte-identical to what the upload path discovers — and parents resolve to
|
|
167
|
+
* the parent's seal frame batch, so closure and later adoption behave
|
|
168
|
+
* exactly as if these ops had been confirmed by this device's own upload.
|
|
169
|
+
* Rejected and still-pending frames are never marked: diagnostics and later
|
|
170
|
+
* unlocks only. Shared by the link's download loop and the history reader
|
|
171
|
+
* (N2): anything a remote demonstrably serves is present on it. The mirror
|
|
172
|
+
* of `mark_admitted_from_batch` in src/sync/link.rs. */
|
|
173
|
+
export declare function markAdmittedFromBatch(stream: Stream, coverage: CoverageStore, scope: CoverageScope, batch: Uint8Array, statuses: ImportStatus[], applied: {
|
|
174
|
+
turnId: Uint8Array;
|
|
175
|
+
seq: bigint;
|
|
176
|
+
}[], appliedTurns: Uint8Array[], appliedSeen: Set<string>, pendingTurns: Uint8Array[], pendingSeen: Set<string>): Promise<void>;
|
|
177
|
+
/** The partial-replica intake's marking (N017 P1-C): real coverage evidence
|
|
178
|
+
* for the window's frames, with declared parents bound only where they are
|
|
179
|
+
* local. Mirror of `mark_admitted_from_batch_local_parents` in
|
|
180
|
+
* src/sync/link.rs. */
|
|
181
|
+
export declare function markAdmittedFromBatchLocalParents(stream: Stream, coverage: CoverageStore, scope: CoverageScope, batch: Uint8Array, statuses: ImportStatus[], applied: {
|
|
182
|
+
turnId: Uint8Array;
|
|
183
|
+
seq: bigint;
|
|
184
|
+
}[], appliedTurns: Uint8Array[], appliedSeen: Set<string>, pendingTurns: Uint8Array[], pendingSeen: Set<string>): Promise<void>;
|
|
185
|
+
/** Mark one op present-exact from the local store (the import already
|
|
186
|
+
* committed it, so its dependencies are locally resolvable). With
|
|
187
|
+
* `localParentsOnly` a turn whose declared parent is not local is skipped
|
|
188
|
+
* entirely — no partial claim is written, so no closure is fabricated. */
|
|
189
|
+
export declare function recordNextServed(inbox: Inbox, replay: DurableReplay, coverage: CoverageStore, scope: CoverageScope): Promise<void>;
|
|
190
|
+
export declare function intakeSource(scope: CoverageScope, kind: 'remote' | 'history'): string;
|
|
191
|
+
export declare function replayReceipt(inbox: Inbox, sequence: bigint): Promise<import("../inbox.js").InboxRecord>;
|
|
192
|
+
export declare function recordServedBatch(bytes: Uint8Array, coverage: CoverageStore, scope: CoverageScope): Promise<void>;
|