@loro-dev/roost 0.1.0 → 0.1.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.
- package/README.md +42 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lody-history.d.ts +98 -1
- package/dist/lody-history.js +952 -12
- package/node/client.d.mts +102 -0
- package/node/client.mjs +316 -0
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -358,6 +358,48 @@ polling and rendering. Browser hosts should subscribe before initializing the
|
|
|
358
358
|
view; the Node adapter currently uses host polling/change hints. The external
|
|
359
359
|
Lody UI is not wired by this library change.
|
|
360
360
|
|
|
361
|
+
New sessions can use the adapter's active-view primitives without changing the
|
|
362
|
+
existing LoroDoc path:
|
|
363
|
+
|
|
364
|
+
```ts
|
|
365
|
+
const first = await history.acceptToView({
|
|
366
|
+
viewId: sessionId,
|
|
367
|
+
expectedRevision: 0n,
|
|
368
|
+
expectedHead: null,
|
|
369
|
+
operationId: requestId,
|
|
370
|
+
input: { kind: 'message', businessId: userId, segmentId: 'primary', parents: [], content },
|
|
371
|
+
});
|
|
372
|
+
const page = await history.readActiveBranchPage(sessionId, { latest: true, limit: 40 });
|
|
373
|
+
if (!page.complete) throw new Error('Active branch is incomplete');
|
|
374
|
+
const older = page.cursor
|
|
375
|
+
? await history.readActiveBranchPage(sessionId, { before: page.cursor, limit: 40 })
|
|
376
|
+
: null;
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Use `forkAndActivate` for an edit/resend. Its replacement Create must include
|
|
380
|
+
the retained base Turn as a parent; the old suffix remains stored and immutable.
|
|
381
|
+
The active-view revision/head is checked with the same atomic write and event
|
|
382
|
+
cursor CAS as the Turn Create. Repeating an operation ID is idempotent, while a
|
|
383
|
+
different input under that ID is a conflict. `LodyHistory` and `NodeLodyHistory`
|
|
384
|
+
expose the same contract. The caller still owns queue, steer and ACP lifecycle
|
|
385
|
+
decisions.
|
|
386
|
+
|
|
387
|
+
Active-branch pages return `startPosition`, `totalCount`, `hasMoreOlder`, and an
|
|
388
|
+
opaque ancestry cursor alongside the selected messages. Positions/counts refer
|
|
389
|
+
to logical `businessId` rows: use `primary` for the initial segment and distinct
|
|
390
|
+
successor IDs for late output. Project all returned segments of a business ID
|
|
391
|
+
into one row. Linear branches written with this metadata read a bounded page;
|
|
392
|
+
legacy/nonlinear ancestry may rebuild a complete directory. `readActiveBranch`
|
|
393
|
+
remains available for explicit full snapshots. Generic published-message reverse
|
|
394
|
+
pages include superseded messages and cannot substitute for active-branch pages.
|
|
395
|
+
|
|
396
|
+
An append preserves older cursors while adding any intervening late successors.
|
|
397
|
+
A fork that removes the cursor's ancestry rejects it as `stale`; refresh the
|
|
398
|
+
loaded window and obtain a new cursor. The last reverse page can contain fewer
|
|
399
|
+
than `limit` rows and never extends past the cursor. These APIs are currently
|
|
400
|
+
used by Lody's local Node owner integration; that does not imply a separate
|
|
401
|
+
browser replica or remote synchronization acceptance.
|
|
402
|
+
|
|
361
403
|
New records in the private `lody_history_published_v1` table have a `version: "2"`
|
|
362
404
|
membership-only value. Current readers also accept legacy full-snapshot values;
|
|
363
405
|
there is no separate startup scan solely to convert these membership values
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Application entry point.
|
|
1
|
+
/** Application entry point. Pin the package and storage writer revision. */
|
|
2
2
|
export { IndexedDbStorage } from './indexeddb.js';
|
|
3
3
|
export { Identity } from './identity.js';
|
|
4
4
|
export { Store, Stream, Writer, StoreError, MAX_PAGE_HEADERS } from './store.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Application entry point.
|
|
1
|
+
/** Application entry point. Pin the package and storage writer revision. */
|
|
2
2
|
export { IndexedDbStorage } from './indexeddb.js';
|
|
3
3
|
export { Identity } from './identity.js';
|
|
4
4
|
export { Store, Stream, Writer, StoreError, MAX_PAGE_HEADERS } from './store.js';
|
package/dist/lody-history.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Lody's durable logical-history adapter. */
|
|
2
2
|
/** Host-owned 32-byte signing seed. Roost never persists, recovers, or writes
|
|
3
3
|
* seed files. The host calls `loadSeed()` and passes the bytes into
|
|
4
4
|
* `RoostNodeClient`. A missing host identity is a host gap, not a Roost
|
|
@@ -54,6 +54,10 @@ export type HistoryProjectedMessage = {
|
|
|
54
54
|
content: JsonValue;
|
|
55
55
|
nextSeq: bigint;
|
|
56
56
|
sealed: boolean;
|
|
57
|
+
/** The exact signed parent edges of this physical segment. */
|
|
58
|
+
parents: ParentRef[];
|
|
59
|
+
/** The sealed body hash, when the segment is sealed. */
|
|
60
|
+
sealedHash: Uint8Array | null;
|
|
57
61
|
};
|
|
58
62
|
export type HistoryProjectedPage = {
|
|
59
63
|
messages: HistoryProjectedMessage[];
|
|
@@ -75,6 +79,76 @@ export type HistoryDiagnostic = {
|
|
|
75
79
|
turnId: Uint8Array;
|
|
76
80
|
reason: 'invalid_envelope';
|
|
77
81
|
};
|
|
82
|
+
export type BranchViewState = {
|
|
83
|
+
viewId: string;
|
|
84
|
+
revision: bigint;
|
|
85
|
+
head: HistoryIdentity | null;
|
|
86
|
+
operationId: string | null;
|
|
87
|
+
logicalCount?: bigint;
|
|
88
|
+
conflict?: boolean;
|
|
89
|
+
};
|
|
90
|
+
export type BranchMutationResult = {
|
|
91
|
+
operationId: string;
|
|
92
|
+
created: boolean;
|
|
93
|
+
oldHead: HistoryIdentity | null;
|
|
94
|
+
newHead: HistoryIdentity;
|
|
95
|
+
revision: bigint;
|
|
96
|
+
turnId: Uint8Array;
|
|
97
|
+
};
|
|
98
|
+
export type BranchAcceptInput = {
|
|
99
|
+
viewId: string;
|
|
100
|
+
expectedRevision: bigint;
|
|
101
|
+
expectedHead: HistoryIdentity | null;
|
|
102
|
+
operationId: string;
|
|
103
|
+
input: AcceptHistory;
|
|
104
|
+
};
|
|
105
|
+
export type ForkAndActivateInput = BranchAcceptInput & {
|
|
106
|
+
/** Last retained Turn. The replacement must name it as a parent when present. */
|
|
107
|
+
baseTurn: Uint8Array | null;
|
|
108
|
+
/** Business identities from the old active suffix. They are provenance only. */
|
|
109
|
+
supersedes: HistoryIdentity[];
|
|
110
|
+
};
|
|
111
|
+
export type ActiveBranchRead = {
|
|
112
|
+
state: BranchViewState;
|
|
113
|
+
messages: HistoryProjectedMessage[];
|
|
114
|
+
complete: boolean;
|
|
115
|
+
};
|
|
116
|
+
export type ActiveBranchPageRead = {
|
|
117
|
+
state: BranchViewState;
|
|
118
|
+
totalCount: number;
|
|
119
|
+
startPosition: number;
|
|
120
|
+
messages: HistoryProjectedMessage[];
|
|
121
|
+
hasMoreOlder: boolean;
|
|
122
|
+
cursor: ActiveBranchPageCursor | null;
|
|
123
|
+
complete: boolean;
|
|
124
|
+
};
|
|
125
|
+
export type ActiveBranchPageCursor = {
|
|
126
|
+
viewId: string;
|
|
127
|
+
turnId: Uint8Array;
|
|
128
|
+
position: number;
|
|
129
|
+
revision: bigint;
|
|
130
|
+
headTurnId: Uint8Array;
|
|
131
|
+
pendingSegments: {
|
|
132
|
+
businessId: string;
|
|
133
|
+
segmentId: string;
|
|
134
|
+
turnId: Uint8Array;
|
|
135
|
+
}[];
|
|
136
|
+
};
|
|
137
|
+
export type RestoreActiveBranchInput = {
|
|
138
|
+
viewId: string;
|
|
139
|
+
expectedRevision: bigint;
|
|
140
|
+
expectedHead: HistoryIdentity | null;
|
|
141
|
+
restoreHead: HistoryIdentity | null;
|
|
142
|
+
operationId: string;
|
|
143
|
+
};
|
|
144
|
+
export type RestoreActiveBranchResult = {
|
|
145
|
+
operationId: string;
|
|
146
|
+
created: boolean;
|
|
147
|
+
oldHead: HistoryIdentity | null;
|
|
148
|
+
newHead: HistoryIdentity | null;
|
|
149
|
+
revision: bigint;
|
|
150
|
+
turnId: Uint8Array | null;
|
|
151
|
+
};
|
|
78
152
|
type Binding = {
|
|
79
153
|
version: 1;
|
|
80
154
|
turnId: number[];
|
|
@@ -100,6 +174,17 @@ export declare class LodyHistory {
|
|
|
100
174
|
turnId: Uint8Array;
|
|
101
175
|
created: boolean;
|
|
102
176
|
}>;
|
|
177
|
+
/** Append a message to an active view and advance that view atomically. */
|
|
178
|
+
acceptToView(input: BranchAcceptInput): Promise<BranchMutationResult>;
|
|
179
|
+
/** Create a replacement Turn and switch the same logical view to it. */
|
|
180
|
+
forkAndActivate(input: ForkAndActivateInput): Promise<BranchMutationResult>;
|
|
181
|
+
readActiveBranch(viewId: string): Promise<ActiveBranchRead>;
|
|
182
|
+
readActiveBranchPage(viewId: string, input?: {
|
|
183
|
+
before?: ActiveBranchPageCursor;
|
|
184
|
+
from?: number;
|
|
185
|
+
latest?: boolean;
|
|
186
|
+
limit?: number;
|
|
187
|
+
}): Promise<ActiveBranchPageRead>;
|
|
103
188
|
append(id: Uint8Array, expectedNextSeq: bigint, ops: ContentOp[]): Promise<import("./store.js").Commit>;
|
|
104
189
|
finish(id: Uint8Array, expectedNextSeq: bigint): Promise<import("./store.js").Commit>;
|
|
105
190
|
respondPermission(input: {
|
|
@@ -209,11 +294,13 @@ export interface LodyNodeHost {
|
|
|
209
294
|
readTurnHeader(id: Uint8Array): Promise<{
|
|
210
295
|
kind: string;
|
|
211
296
|
turn?: {
|
|
297
|
+
parents: ParentRef[];
|
|
212
298
|
sealed: Uint8Array | null;
|
|
213
299
|
nextSeq: bigint;
|
|
214
300
|
bodyVerified: boolean;
|
|
215
301
|
};
|
|
216
302
|
prefix?: {
|
|
303
|
+
parents: ParentRef[];
|
|
217
304
|
sealed: Uint8Array | null;
|
|
218
305
|
nextSeq: bigint;
|
|
219
306
|
bodyVerified: boolean;
|
|
@@ -322,6 +409,16 @@ export declare class NodeLodyHistory {
|
|
|
322
409
|
turnId: Uint8Array;
|
|
323
410
|
created: boolean;
|
|
324
411
|
}>;
|
|
412
|
+
acceptToView(input: BranchAcceptInput): Promise<BranchMutationResult>;
|
|
413
|
+
forkAndActivate(input: ForkAndActivateInput): Promise<BranchMutationResult>;
|
|
414
|
+
restoreActiveBranch(input: RestoreActiveBranchInput): Promise<RestoreActiveBranchResult>;
|
|
415
|
+
readActiveBranch(viewId: string): Promise<ActiveBranchRead>;
|
|
416
|
+
readActiveBranchPage(viewId: string, input?: {
|
|
417
|
+
before?: ActiveBranchPageCursor;
|
|
418
|
+
from?: number;
|
|
419
|
+
latest?: boolean;
|
|
420
|
+
limit?: number;
|
|
421
|
+
}): Promise<ActiveBranchPageRead>;
|
|
325
422
|
respondPermission(input: {
|
|
326
423
|
requestId: string;
|
|
327
424
|
assistantBusinessId: string;
|