@loro-dev/roost 0.2.0 → 0.3.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 +75 -4
- package/dist/history-publication.d.ts +13 -0
- package/dist/history-publication.js +94 -7
- package/dist/lody-history.d.ts +137 -20
- package/dist/lody-history.js +649 -61
- package/node/client.d.mts +8 -2
- package/node/client.mjs +23 -2
- package/package.json +13 -13
package/node/client.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Private prototype API. Pair this client with the artifact's matching owner binary. */
|
|
2
2
|
export const MAX_MESSAGE_BYTES: number;
|
|
3
3
|
export class RoostHostError extends Error { readonly code: string; }
|
|
4
|
-
export type OwnerCapability = 'history-v1' | 'create-once-v1' | 'create-once-cas-v1' | 'sync-v1' | 'host-crypto-v1' | 'index-cas-v1' | 'index-events-v1' | 'index-cas-events-v1';
|
|
4
|
+
export type OwnerCapability = 'history-v1' | 'create-once-v1' | 'create-once-cas-v1' | 'field-reads-v1' | 'exclusive-batch-v1' | 'sync-v1' | 'host-crypto-v1' | 'index-cas-v1' | 'index-events-v1' | 'index-cas-events-v1' | 'commit-metadata-v1' | 'derived-indexes-v1' | 'receipt-checks-v1' | 'commit-observation-v1';
|
|
5
5
|
export type ParentRef = { id: Uint8Array; hash: Uint8Array };
|
|
6
6
|
export type UpdateRef = { turnId: Uint8Array; seq: bigint };
|
|
7
7
|
export type Verification = 'notRetrieved' | 'provisional' | 'selfVerified' | 'ancestorsVerified';
|
|
@@ -9,6 +9,8 @@ export type Header = { turnId: Uint8Array; owner: Uint8Array; parents: ParentRef
|
|
|
9
9
|
export type Turn = Header & { contentJson: string };
|
|
10
10
|
export type ReadResult<T> = { kind: 'found'; turn: T } | { kind: 'notFound'; turnId: Uint8Array } | { kind: 'incomplete'; turnId: Uint8Array; prefix: T | null };
|
|
11
11
|
export type Path = ({ key: string } | { index: bigint })[];
|
|
12
|
+
export type FieldSelector = { path: Path; jsonPath?: Path; info?: boolean };
|
|
13
|
+
export type FieldReadResult = { state: "missing" } | { state: "ready"; contentJson: string };
|
|
12
14
|
export type ContentOp =
|
|
13
15
|
| { kind: 'set'; path: Path; contentJson: string }
|
|
14
16
|
| { kind: 'remove'; path: Path }
|
|
@@ -43,7 +45,7 @@ export interface RoostNodeStream {
|
|
|
43
45
|
createOnce(key: Uint8Array, parents: ParentRef[], contentJson: string, options?: RequestOptions & {expectedEventCursor?: bigint}): Promise<{ turnId: Uint8Array; created: boolean }>;
|
|
44
46
|
edit(turnId: Uint8Array, expectedNextSeq: bigint, ops: ContentOp[], options?: RequestOptions): Promise<{ updates: UpdateRef[] }>;
|
|
45
47
|
seal(turnId: Uint8Array, expectedNextSeq: bigint, options?: RequestOptions): Promise<{ updates: UpdateRef[] }>;
|
|
46
|
-
writeBatch(writes: Write[], options?: RequestOptions & {indexPuts?: IndexPut[]; expectedEventCursor?: bigint}): Promise<{ updates: UpdateRef[] }>;
|
|
48
|
+
writeBatch(writes: Write[], options?: RequestOptions & {requireLocalInterval?: boolean; indexPuts?: IndexPut[]; expectedEventCursor?: bigint}): Promise<{ updates: UpdateRef[]; before?: bigint; through?: bigint }>;
|
|
47
49
|
readIndex(keys: IndexKey[], options?: RequestOptions): Promise<(Uint8Array | null)[]>;
|
|
48
50
|
compareAndWriteIndex(expected: IndexEntry[], changes: IndexEntry[], options?: RequestOptions & {eventKeys?: IndexKey[]}): Promise<boolean>;
|
|
49
51
|
scanIndex(table: string, start: Uint8Array, limit: bigint, options?: RequestOptions): Promise<{key: Uint8Array; value: Uint8Array}[]>;
|
|
@@ -55,6 +57,10 @@ export interface RoostNodeStream {
|
|
|
55
57
|
turnHeadersBefore(before: Uint8Array, limit: bigint, options?: RequestOptions): Promise<Header[]>;
|
|
56
58
|
turnHeadersAfter(after: Uint8Array | null, limit: bigint, options?: RequestOptions): Promise<ReadResult<Header>[]>;
|
|
57
59
|
readValue(turnId: Uint8Array, path: Path, options?: RequestOptions): Promise<{ contentJson: string; nextSeq: bigint }>;
|
|
60
|
+
readonly fieldReads: boolean;
|
|
61
|
+
readonly exclusiveBatches: boolean;
|
|
62
|
+
readCreateFields(turnId: Uint8Array, selectors: FieldSelector[], omitDigestKeys?: string[], options?: RequestOptions): Promise<{fields: FieldReadResult[]; owner: Uint8Array; digest: Uint8Array; filteredDigest: Uint8Array}>;
|
|
63
|
+
readFields(turnId: Uint8Array, selectors: FieldSelector[], options?: RequestOptions): Promise<{ fields: FieldReadResult[]; nextSeq: bigint }>;
|
|
58
64
|
readText(turnId: Uint8Array, path: Path, start: bigint, end: bigint, options?: RequestOptions): Promise<{ text: string; nextSeq: bigint }>;
|
|
59
65
|
verification(turnId: Uint8Array, options?: RequestOptions): Promise<Verification>;
|
|
60
66
|
eventsAfter(after: bigint, limit: bigint, options?: RequestOptions): Promise<EventRecord[]>;
|
package/node/client.mjs
CHANGED
|
@@ -243,11 +243,32 @@ class RoostNodeStream {
|
|
|
243
243
|
async turnHeadersAfter(after, limit, options) { return this.client.request({method:'turnHeadersAfter',stream:this.id,after:after===null?null:hex(after,16),limit:decimal(limit)},v=>v.map(r=>read(r,header)),options); }
|
|
244
244
|
async readTurns(turnIds, options) { return this.client.request({method:'readTurns',stream:this.id,turnIds:turnIds.map(id=>hex(id,16))},v=>v.map(r=>read(r)),options); }
|
|
245
245
|
async readValue(turnId, p, options) { return this.client.request({method:'readValue',stream:this.id,turnId:hex(turnId,16),path:path(p)},v=>{if(typeof v.contentJson!=='string')throw error('protocol');return {contentJson:v.contentJson,nextSeq:fromDecimal(v.nextSeq)};},options); }
|
|
246
|
+
get exclusiveBatches() { return this.client.capabilities.includes("exclusive-batch-v1"); }
|
|
247
|
+
get fieldReads() { return this.client.capabilities.includes("field-reads-v1"); }
|
|
248
|
+
async readCreateFields(turnId, selectors, omitDigestKeys = [], options) {
|
|
249
|
+
if (!Array.isArray(selectors) || selectors.length > 1024 || !Array.isArray(omitDigestKeys) || omitDigestKeys.length > 64) throw error("invalid");
|
|
250
|
+
return this.client.request({method:"readCreateFields",stream:this.id,turnId:hex(turnId,16),
|
|
251
|
+
selectors:selectors.map(selector=>({path:path(selector.path),...(selector.jsonPath===undefined?{}:{jsonPath:path(selector.jsonPath)}),...(selector.info===undefined?{}:{info:selector.info})})),omitDigestKeys}, v=>{
|
|
252
|
+
if (!Array.isArray(v.fields) || v.fields.length !== selectors.length) throw error("protocol");
|
|
253
|
+
return {fields:v.fields.map(field=>{
|
|
254
|
+
if(field?.state==="missing")return {state:"missing"};
|
|
255
|
+
if(field?.state!=="ready"||typeof field.contentJson!=="string")throw error("protocol");
|
|
256
|
+
return {state:"ready",contentJson:field.contentJson};
|
|
257
|
+
}),owner:unhex(v.owner,32),digest:unhex(v.digest,32),filteredDigest:unhex(v.filteredDigest,32)};
|
|
258
|
+
},options);
|
|
259
|
+
}
|
|
260
|
+
async readFields(turnId, selectors, options) {
|
|
261
|
+
if (!Array.isArray(selectors) || selectors.length > 1024) throw error('invalid');
|
|
262
|
+
return this.client.request({method:'readFields',stream:this.id,turnId:hex(turnId,16),selectors:selectors.map(selector=>({path:path(selector.path),...(selector.jsonPath===undefined?{}:{jsonPath:path(selector.jsonPath)}),...(selector.info===undefined?{}:{info:selector.info})}))},v=>{
|
|
263
|
+
if(!Array.isArray(v.fields)||v.fields.length!==selectors.length)throw error('protocol');
|
|
264
|
+
return {fields:v.fields.map(field=>{if(field?.state==='missing')return {state:'missing'};if(field?.state!=='ready'||typeof field.contentJson!=='string')throw error('protocol');return {state:'ready',contentJson:field.contentJson};}),nextSeq:fromDecimal(v.nextSeq)};
|
|
265
|
+
},options);
|
|
266
|
+
}
|
|
246
267
|
async verification(turnId, options) { return this.client.request({method:'verification',stream:this.id,turnId:hex(turnId,16)},v=>{if(!['notRetrieved','provisional','selfVerified','ancestorsVerified'].includes(v))throw error('protocol');return v;},options); }
|
|
247
268
|
async writeBatch(writes, options) {
|
|
248
269
|
const indexPuts = options?.indexPuts;
|
|
249
270
|
const cursor = options?.expectedEventCursor;
|
|
250
|
-
return this.client.request({method:'writeBatch',stream:this.id,writes:writes.map(w=>{
|
|
271
|
+
return this.client.request({method:'writeBatch',stream:this.id,...(options?.requireLocalInterval===undefined?{}:{requireLocalInterval:bool(options.requireLocalInterval)}),writes:writes.map(w=>{
|
|
251
272
|
switch(w.kind){
|
|
252
273
|
case 'create':return {kind:w.kind,parents:w.parents.map(p=>({id:hex(p.id,16),hash:hex(p.hash,32)})),contentJson:string(w.contentJson)};
|
|
253
274
|
case 'createOnce':return {kind:w.kind,keyHex:hex(w.key),parents:w.parents.map(p=>({id:hex(p.id,16),hash:hex(p.hash,32)})),contentJson:string(w.contentJson)};
|
|
@@ -257,7 +278,7 @@ class RoostNodeStream {
|
|
|
257
278
|
case 'sealOnce':return {kind:w.kind,keyHex:hex(w.key),expectedNextSeq:decimal(w.expectedNextSeq)};
|
|
258
279
|
default:throw new TypeError('unknown write');
|
|
259
280
|
}
|
|
260
|
-
}),...(indexPuts===undefined?{}:{indexPuts:indexPuts.map(p=>({table:string(p.table),keyHex:hex(p.key),valueHex:hex(p.value),...(p.emitEvent===undefined?{}:{emitEvent:bool(p.emitEvent)}),...(p.onceKey===undefined?{}:{onceKeyHex:hex(p.onceKey)})}))}),...(cursor===undefined?{}:{expectedEventCursor:decimal(cursor)})},v=>({updates:refs(v.updates)}),options); }
|
|
281
|
+
}),...(indexPuts===undefined?{}:{indexPuts:indexPuts.map(p=>({table:string(p.table),keyHex:hex(p.key),valueHex:hex(p.value),...(p.emitEvent===undefined?{}:{emitEvent:bool(p.emitEvent)}),...(p.onceKey===undefined?{}:{onceKeyHex:hex(p.onceKey)})}))}),...(cursor===undefined?{}:{expectedEventCursor:decimal(cursor)})},v=>({updates:refs(v.updates),before:fromDecimal(v.before),through:fromDecimal(v.through)}),options); }
|
|
261
282
|
async scanIndex(table, start, limit, options) {
|
|
262
283
|
return this.client.request({method:'indexScan',stream:this.id,table:string(table),start:hex(start),limit:decimal(limit)},v=>v.map(r=>({key:unhex(r.keyHex),value:unhex(r.valueHex)})),options);
|
|
263
284
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loro-dev/roost",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Browser conversation history and sync for Loro Roost",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
6
|
+
"publishConfig": { "access": "public" },
|
|
9
7
|
"type": "module",
|
|
8
|
+
"packageManager": "pnpm@12.3.4",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"check": "tsc --noEmit",
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepack": "pnpm build",
|
|
13
|
+
"test": "pnpm build && node --test tests/*.test.mjs",
|
|
14
|
+
"pack:consumer": "pnpm build && node scripts/pack-consumer.mjs",
|
|
15
|
+
"check:consumer": "pnpm build && node scripts/check-consumer.mjs"
|
|
16
|
+
},
|
|
10
17
|
"devDependencies": {
|
|
11
18
|
"playwright": "1.58.2",
|
|
12
19
|
"typescript": "5.9.3"
|
|
@@ -42,12 +49,5 @@
|
|
|
42
49
|
"node/client.d.mts",
|
|
43
50
|
"README.md",
|
|
44
51
|
"LICENSE"
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
"check": "tsc --noEmit",
|
|
48
|
-
"build": "tsc",
|
|
49
|
-
"test": "pnpm build && node --test tests/*.test.mjs",
|
|
50
|
-
"pack:consumer": "pnpm build && node scripts/pack-consumer.mjs",
|
|
51
|
-
"check:consumer": "pnpm build && node scripts/check-consumer.mjs"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
52
|
+
]
|
|
53
|
+
}
|