@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
package/dist/json.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
export const MAX_JSON_DEPTH = 127;
|
|
2
|
+
export const MAX_JSON_BYTES = 16 * 1024 * 1024;
|
|
3
|
+
export const U64_MAX = (1n << 64n) - 1n;
|
|
4
|
+
const I64_MIN = -(1n << 63n);
|
|
5
|
+
const encoder = new TextEncoder();
|
|
6
|
+
const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
7
|
+
export function assertScalars(value) {
|
|
8
|
+
if (typeof value !== 'string')
|
|
9
|
+
throw new TypeError('string required');
|
|
10
|
+
for (let i = 0; i < value.length; i++) {
|
|
11
|
+
const unit = value.charCodeAt(i);
|
|
12
|
+
if (unit >= 0xd800 && unit <= 0xdbff) {
|
|
13
|
+
const low = value.charCodeAt(++i);
|
|
14
|
+
if (!(low >= 0xdc00 && low <= 0xdfff))
|
|
15
|
+
throw new Error('unpaired surrogate');
|
|
16
|
+
}
|
|
17
|
+
else if (unit >= 0xdc00 && unit <= 0xdfff)
|
|
18
|
+
throw new Error('unpaired surrogate');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function encodeUtf8(value) { assertScalars(value); return encoder.encode(value); }
|
|
22
|
+
export function decodeUtf8(value) { return decoder.decode(value); }
|
|
23
|
+
export function compareScalarKeys(a, b) {
|
|
24
|
+
let i = 0, j = 0;
|
|
25
|
+
while (i < a.length && j < b.length) {
|
|
26
|
+
const x = a.codePointAt(i), y = b.codePointAt(j);
|
|
27
|
+
if (x !== y)
|
|
28
|
+
return x < y ? -1 : 1;
|
|
29
|
+
i += x > 0xffff ? 2 : 1;
|
|
30
|
+
j += y > 0xffff ? 2 : 1;
|
|
31
|
+
}
|
|
32
|
+
return i < a.length ? 1 : j < b.length ? -1 : 0;
|
|
33
|
+
}
|
|
34
|
+
/** Shortest IEEE digits with zmij 1.0.23's f64 presentation, including float .0.
|
|
35
|
+
* Number#toString supplies correctly rounded shortest digits; JSON.stringify
|
|
36
|
+
* does not supply the required integer/float distinction or exponent layout.
|
|
37
|
+
*/
|
|
38
|
+
export function formatFloat(value) {
|
|
39
|
+
if (!Number.isFinite(value))
|
|
40
|
+
throw new Error('non-finite JSON float');
|
|
41
|
+
if (Object.is(value, -0))
|
|
42
|
+
return '-0.0';
|
|
43
|
+
if (value === 0)
|
|
44
|
+
return '0.0';
|
|
45
|
+
const sign = value < 0 ? '-' : '';
|
|
46
|
+
const [significand, exponentText = '0'] = Math.abs(value).toString().split('e');
|
|
47
|
+
const point = significand.indexOf('.');
|
|
48
|
+
let exponent = Number(exponentText) + (point < 0 ? significand.length : point) - 1;
|
|
49
|
+
let digits = significand.replace('.', '');
|
|
50
|
+
while (digits[0] === '0') {
|
|
51
|
+
digits = digits.slice(1);
|
|
52
|
+
exponent--;
|
|
53
|
+
}
|
|
54
|
+
digits = digits.replace(/0+$/, '');
|
|
55
|
+
let out;
|
|
56
|
+
if (exponent >= -5 && exponent <= 15) {
|
|
57
|
+
if (exponent < 0)
|
|
58
|
+
out = '0.' + '0'.repeat(-exponent - 1) + digits;
|
|
59
|
+
else if (exponent + 1 >= digits.length)
|
|
60
|
+
out = digits + '0'.repeat(exponent + 1 - digits.length) + '.0';
|
|
61
|
+
else
|
|
62
|
+
out = digits.slice(0, exponent + 1) + '.' + digits.slice(exponent + 1);
|
|
63
|
+
}
|
|
64
|
+
else
|
|
65
|
+
out = digits[0] + (digits.length > 1 ? '.' + digits.slice(1) : '') + 'e' + (exponent >= 0 ? '+' : '') + exponent;
|
|
66
|
+
return sign + out;
|
|
67
|
+
}
|
|
68
|
+
function stringify(value, depth) {
|
|
69
|
+
if (value === null)
|
|
70
|
+
return 'null';
|
|
71
|
+
if (typeof value === 'boolean')
|
|
72
|
+
return value ? 'true' : 'false';
|
|
73
|
+
if (typeof value === 'string') {
|
|
74
|
+
assertScalars(value);
|
|
75
|
+
return JSON.stringify(value);
|
|
76
|
+
}
|
|
77
|
+
if (typeof value !== 'object')
|
|
78
|
+
throw new TypeError('explicit JsonNumber required');
|
|
79
|
+
if (Array.isArray(value) || value instanceof Map) {
|
|
80
|
+
if (depth >= MAX_JSON_DEPTH)
|
|
81
|
+
throw new Error('json too deep');
|
|
82
|
+
if (Array.isArray(value)) {
|
|
83
|
+
const parts = [];
|
|
84
|
+
for (let i = 0; i < value.length; i++) {
|
|
85
|
+
if (!Object.hasOwn(value, i))
|
|
86
|
+
throw new TypeError('sparse JSON array');
|
|
87
|
+
parts.push(stringify(value[i], depth + 1));
|
|
88
|
+
}
|
|
89
|
+
return '[' + parts.join(',') + ']';
|
|
90
|
+
}
|
|
91
|
+
const keys = [...value.keys()];
|
|
92
|
+
for (const key of keys) {
|
|
93
|
+
if (typeof key !== 'string')
|
|
94
|
+
throw new TypeError('JSON object key must be string');
|
|
95
|
+
assertScalars(key);
|
|
96
|
+
}
|
|
97
|
+
return '{' + keys.sort(compareScalarKeys).map(k => JSON.stringify(k) + ':' + stringify(value.get(k), depth + 1)).join(',') + '}';
|
|
98
|
+
}
|
|
99
|
+
if (value.kind === 'f64' && typeof value.value === 'number')
|
|
100
|
+
return formatFloat(value.value);
|
|
101
|
+
if (typeof value.value !== 'bigint')
|
|
102
|
+
throw new TypeError('explicit integer bigint required');
|
|
103
|
+
if (value.kind === 'u64' && value.value >= 0n && value.value <= U64_MAX)
|
|
104
|
+
return value.value.toString();
|
|
105
|
+
if (value.kind === 'i64' && value.value < 0n && value.value >= I64_MIN)
|
|
106
|
+
return value.value.toString();
|
|
107
|
+
throw new RangeError('integer kind or range');
|
|
108
|
+
}
|
|
109
|
+
export function encodeJson(value) {
|
|
110
|
+
const result = encoder.encode(stringify(value, 0));
|
|
111
|
+
if (result.length > MAX_JSON_BYTES)
|
|
112
|
+
throw new Error('JSON payload too large');
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
class Parser {
|
|
116
|
+
source;
|
|
117
|
+
pos = 0;
|
|
118
|
+
constructor(source) {
|
|
119
|
+
this.source = source;
|
|
120
|
+
}
|
|
121
|
+
string() {
|
|
122
|
+
const start = this.pos++;
|
|
123
|
+
for (; this.pos < this.source.length; this.pos++) {
|
|
124
|
+
const char = this.source[this.pos];
|
|
125
|
+
if (char === '\\') {
|
|
126
|
+
this.pos++;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (char === '"') {
|
|
130
|
+
const value = JSON.parse(this.source.slice(start, ++this.pos));
|
|
131
|
+
if (typeof value !== 'string')
|
|
132
|
+
throw new Error('expected JSON string');
|
|
133
|
+
assertScalars(value);
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
throw new Error('unterminated JSON string');
|
|
138
|
+
}
|
|
139
|
+
value(depth) {
|
|
140
|
+
const char = this.source[this.pos];
|
|
141
|
+
if (char === '"')
|
|
142
|
+
return this.string();
|
|
143
|
+
for (const [word, result] of [['null', null], ['true', true], ['false', false]]) {
|
|
144
|
+
if (this.source.startsWith(word, this.pos)) {
|
|
145
|
+
this.pos += word.length;
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (char === '[' || char === '{') {
|
|
150
|
+
if (depth >= MAX_JSON_DEPTH)
|
|
151
|
+
throw new Error('json too deep');
|
|
152
|
+
this.pos++;
|
|
153
|
+
if (char === '[') {
|
|
154
|
+
const result = [];
|
|
155
|
+
if (this.source[this.pos] === ']') {
|
|
156
|
+
this.pos++;
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
for (;;) {
|
|
160
|
+
result.push(this.value(depth + 1));
|
|
161
|
+
const separator = this.source[this.pos++];
|
|
162
|
+
if (separator === ']')
|
|
163
|
+
return result;
|
|
164
|
+
if (separator !== ',')
|
|
165
|
+
throw new Error('array separator');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const result = new Map();
|
|
169
|
+
if (this.source[this.pos] === '}') {
|
|
170
|
+
this.pos++;
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
for (;;) {
|
|
174
|
+
if (this.source[this.pos] !== '"')
|
|
175
|
+
throw new Error('object key');
|
|
176
|
+
const key = this.string();
|
|
177
|
+
if (result.has(key))
|
|
178
|
+
throw new Error('duplicate object key');
|
|
179
|
+
if (this.source[this.pos++] !== ':')
|
|
180
|
+
throw new Error('object colon');
|
|
181
|
+
result.set(key, this.value(depth + 1));
|
|
182
|
+
const separator = this.source[this.pos++];
|
|
183
|
+
if (separator === '}')
|
|
184
|
+
return result;
|
|
185
|
+
if (separator !== ',')
|
|
186
|
+
throw new Error('object separator');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Match at current position without copying the remainder of large documents.
|
|
190
|
+
const number = /-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/y;
|
|
191
|
+
number.lastIndex = this.pos;
|
|
192
|
+
const token = number.exec(this.source)?.[0];
|
|
193
|
+
if (token === undefined)
|
|
194
|
+
throw new Error('invalid JSON token');
|
|
195
|
+
this.pos += token.length;
|
|
196
|
+
if (!/[.eE]/.test(token) && token !== '-0' && token.length <= 21) {
|
|
197
|
+
const integer = BigInt(token);
|
|
198
|
+
if (integer >= 0n && integer <= U64_MAX)
|
|
199
|
+
return { kind: 'u64', value: integer };
|
|
200
|
+
if (integer < 0n && integer >= I64_MIN)
|
|
201
|
+
return { kind: 'i64', value: integer };
|
|
202
|
+
}
|
|
203
|
+
const value = Number(token);
|
|
204
|
+
if (!Number.isFinite(value))
|
|
205
|
+
throw new Error('JSON number out of range');
|
|
206
|
+
return { kind: 'f64', value };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export function decodeJson(bytes) {
|
|
210
|
+
if (bytes.length > MAX_JSON_BYTES)
|
|
211
|
+
throw new Error('JSON payload too large');
|
|
212
|
+
const source = decodeUtf8(bytes);
|
|
213
|
+
const parser = new Parser(source);
|
|
214
|
+
const value = parser.value(0);
|
|
215
|
+
if (parser.pos !== source.length)
|
|
216
|
+
throw new Error('trailing JSON bytes');
|
|
217
|
+
const encoded = encodeJson(value);
|
|
218
|
+
if (encoded.length !== bytes.length || !encoded.every((v, i) => v === bytes[i]))
|
|
219
|
+
throw new Error('noncanonical JSON');
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/** Experimental application adapter; not yet wired into Lody's runtime. */
|
|
2
|
+
/** Host-owned 32-byte signing seed. Roost never persists, recovers, or writes
|
|
3
|
+
* seed files. The host calls `loadSeed()` and passes the bytes into
|
|
4
|
+
* `RoostNodeClient`. A missing host identity is a host gap, not a Roost
|
|
5
|
+
* recovery problem — do not hash other secrets or invent a seed file. */
|
|
6
|
+
export type HostOwnerIdentity = {
|
|
7
|
+
loadSeed(): Promise<Uint8Array>;
|
|
8
|
+
};
|
|
9
|
+
import { type ContentOp, type ParentRef } from './codec.js';
|
|
10
|
+
import { type JsonValue } from './json.js';
|
|
11
|
+
import { Identity } from './identity.js';
|
|
12
|
+
import { Stream, type TurnReadResult } from './store.js';
|
|
13
|
+
type Kind = 'message' | 'permission_response' | 'dispatch_intent' | 'batch_receipt' | 'publication';
|
|
14
|
+
export type HistoryIdentity = {
|
|
15
|
+
businessId: string;
|
|
16
|
+
segmentId: string;
|
|
17
|
+
kind: Kind;
|
|
18
|
+
};
|
|
19
|
+
export type HistoryBatchCommand = {
|
|
20
|
+
type: 'accept';
|
|
21
|
+
identity: HistoryIdentity;
|
|
22
|
+
parents: ParentRef[];
|
|
23
|
+
content: JsonValue;
|
|
24
|
+
attachments?: AttachmentIdentity[];
|
|
25
|
+
} | {
|
|
26
|
+
type: 'setContent';
|
|
27
|
+
identity: HistoryIdentity;
|
|
28
|
+
expectedNextSeq: bigint;
|
|
29
|
+
content: JsonValue;
|
|
30
|
+
} | {
|
|
31
|
+
type: 'finish';
|
|
32
|
+
identity: HistoryIdentity;
|
|
33
|
+
expectedNextSeq: bigint;
|
|
34
|
+
} | {
|
|
35
|
+
type: 'permission';
|
|
36
|
+
requestId: string;
|
|
37
|
+
assistantBusinessId: string;
|
|
38
|
+
outcome: JsonValue;
|
|
39
|
+
parents: ParentRef[];
|
|
40
|
+
} | {
|
|
41
|
+
type: 'dispatch';
|
|
42
|
+
latestUserMsgId: string;
|
|
43
|
+
state: 'pending' | 'published';
|
|
44
|
+
};
|
|
45
|
+
export type HistoryBatchResult = {
|
|
46
|
+
batchId: string;
|
|
47
|
+
created: boolean;
|
|
48
|
+
revision: bigint;
|
|
49
|
+
};
|
|
50
|
+
export type HistoryProjectedMessage = {
|
|
51
|
+
businessId: string;
|
|
52
|
+
segmentId: string;
|
|
53
|
+
turnId: Uint8Array;
|
|
54
|
+
content: JsonValue;
|
|
55
|
+
nextSeq: bigint;
|
|
56
|
+
sealed: boolean;
|
|
57
|
+
};
|
|
58
|
+
export type HistoryProjectedPage = {
|
|
59
|
+
messages: HistoryProjectedMessage[];
|
|
60
|
+
hasMore: boolean;
|
|
61
|
+
cursor: Uint8Array | null;
|
|
62
|
+
};
|
|
63
|
+
export type AttachmentIdentity = {
|
|
64
|
+
attachmentId: string;
|
|
65
|
+
sha256: string;
|
|
66
|
+
name: string;
|
|
67
|
+
size: bigint;
|
|
68
|
+
};
|
|
69
|
+
export type AcceptHistory = HistoryIdentity & {
|
|
70
|
+
parents: ParentRef[];
|
|
71
|
+
content: JsonValue;
|
|
72
|
+
attachments?: AttachmentIdentity[];
|
|
73
|
+
};
|
|
74
|
+
export type HistoryDiagnostic = {
|
|
75
|
+
turnId: Uint8Array;
|
|
76
|
+
reason: 'invalid_envelope';
|
|
77
|
+
};
|
|
78
|
+
type Binding = {
|
|
79
|
+
version: 1;
|
|
80
|
+
turnId: number[];
|
|
81
|
+
owner: number[];
|
|
82
|
+
digest: number[];
|
|
83
|
+
conflict?: boolean;
|
|
84
|
+
};
|
|
85
|
+
/** A business message may contain append-only execution segments. A new segment
|
|
86
|
+
* never replaces an older signature. Dispatch/Flock and locations are host-owned. */
|
|
87
|
+
export declare class LodyHistory {
|
|
88
|
+
readonly stream: Stream;
|
|
89
|
+
readonly identity: Identity;
|
|
90
|
+
constructor(stream: Stream, identity: Identity);
|
|
91
|
+
private get space();
|
|
92
|
+
private get cursorSpace();
|
|
93
|
+
indexPage(limit?: number): Promise<boolean>;
|
|
94
|
+
catchUpIndex(): Promise<void>;
|
|
95
|
+
invalidMessages(limit?: number): Promise<HistoryDiagnostic[]>;
|
|
96
|
+
lookup(input: HistoryIdentity): Promise<TurnReadResult | undefined>;
|
|
97
|
+
accept(input: AcceptHistory, options?: {
|
|
98
|
+
publish?: boolean;
|
|
99
|
+
}): Promise<{
|
|
100
|
+
turnId: Uint8Array;
|
|
101
|
+
created: boolean;
|
|
102
|
+
}>;
|
|
103
|
+
append(id: Uint8Array, expectedNextSeq: bigint, ops: ContentOp[]): Promise<import("./store.js").Commit>;
|
|
104
|
+
finish(id: Uint8Array, expectedNextSeq: bigint): Promise<import("./store.js").Commit>;
|
|
105
|
+
respondPermission(input: {
|
|
106
|
+
requestId: string;
|
|
107
|
+
assistantBusinessId: string;
|
|
108
|
+
outcome: JsonValue;
|
|
109
|
+
parents: ParentRef[];
|
|
110
|
+
}): Promise<{
|
|
111
|
+
turnId: Uint8Array;
|
|
112
|
+
created: boolean;
|
|
113
|
+
}>;
|
|
114
|
+
attachments(id: Uint8Array, resolve: (identity: AttachmentIdentity) => Promise<string | undefined>): Promise<{
|
|
115
|
+
identity: {
|
|
116
|
+
attachmentId: string;
|
|
117
|
+
sha256: string;
|
|
118
|
+
name: string;
|
|
119
|
+
size: bigint;
|
|
120
|
+
};
|
|
121
|
+
location: string | undefined;
|
|
122
|
+
}[]>;
|
|
123
|
+
commitHistoryBatch(batchId: string, commands: HistoryBatchCommand[]): Promise<HistoryBatchResult>;
|
|
124
|
+
recoverPendingBatches(): Promise<void>;
|
|
125
|
+
/** A consumer-owned cache. Call refresh on change hints (or host polling). */
|
|
126
|
+
createMessageView(limit?: number): HistoryMessageView;
|
|
127
|
+
readProjectedMessagesById(ids: Uint8Array[]): Promise<HistoryProjectedMessage[]>;
|
|
128
|
+
readProjectedMessages(): Promise<HistoryProjectedMessage[]>;
|
|
129
|
+
readProjectedMessagePage(input?: {
|
|
130
|
+
after?: Uint8Array;
|
|
131
|
+
before?: Uint8Array;
|
|
132
|
+
latest?: boolean;
|
|
133
|
+
limit?: number;
|
|
134
|
+
}): Promise<HistoryProjectedPage>;
|
|
135
|
+
readProjectedEntries(): Promise<{
|
|
136
|
+
businessId: string;
|
|
137
|
+
segmentId: string;
|
|
138
|
+
turnId: Uint8Array;
|
|
139
|
+
entry: unknown;
|
|
140
|
+
nextSeq: bigint;
|
|
141
|
+
sealed: boolean;
|
|
142
|
+
}[]>;
|
|
143
|
+
observedEventCursor(): Promise<bigint>;
|
|
144
|
+
indexedBindings(): Promise<{
|
|
145
|
+
identity: HistoryIdentity;
|
|
146
|
+
binding: Binding;
|
|
147
|
+
}[]>;
|
|
148
|
+
}
|
|
149
|
+
/** Process-host variant. The durable source of this rebuildable index is the
|
|
150
|
+
* owner's operation/event log; it never opens a second database connection. */
|
|
151
|
+
type NodeHistoryTurn = {
|
|
152
|
+
turnId: Uint8Array;
|
|
153
|
+
contentJson: string;
|
|
154
|
+
nextSeq: bigint;
|
|
155
|
+
sealed: Uint8Array | null;
|
|
156
|
+
bodyVerified: boolean;
|
|
157
|
+
hashVerified: boolean;
|
|
158
|
+
};
|
|
159
|
+
export type NodeHistoryRead = {
|
|
160
|
+
kind: 'found';
|
|
161
|
+
turn: NodeHistoryTurn;
|
|
162
|
+
} | {
|
|
163
|
+
kind: 'notFound';
|
|
164
|
+
turnId: Uint8Array;
|
|
165
|
+
} | {
|
|
166
|
+
kind: 'incomplete';
|
|
167
|
+
turnId: Uint8Array;
|
|
168
|
+
prefix: NodeHistoryTurn | null;
|
|
169
|
+
};
|
|
170
|
+
export type NodeHistoryOp = {
|
|
171
|
+
kind: 'appendText';
|
|
172
|
+
path: ({
|
|
173
|
+
key: string;
|
|
174
|
+
} | {
|
|
175
|
+
index: bigint;
|
|
176
|
+
})[];
|
|
177
|
+
text: string;
|
|
178
|
+
} | {
|
|
179
|
+
kind: 'set';
|
|
180
|
+
path: ({
|
|
181
|
+
key: string;
|
|
182
|
+
} | {
|
|
183
|
+
index: bigint;
|
|
184
|
+
})[];
|
|
185
|
+
contentJson: string;
|
|
186
|
+
};
|
|
187
|
+
export interface LodyNodeHost {
|
|
188
|
+
eventsAfter(after: bigint, limit: bigint): Promise<{
|
|
189
|
+
cursor: bigint;
|
|
190
|
+
event: {
|
|
191
|
+
kind: string;
|
|
192
|
+
update?: {
|
|
193
|
+
turnId: Uint8Array;
|
|
194
|
+
seq: bigint;
|
|
195
|
+
};
|
|
196
|
+
table?: string;
|
|
197
|
+
key?: Uint8Array;
|
|
198
|
+
};
|
|
199
|
+
}[]>;
|
|
200
|
+
exportUpdates(id: Uint8Array, from: bigint, limit: bigint): Promise<Uint8Array>;
|
|
201
|
+
createOnce(key: Uint8Array, parents: ParentRef[], contentJson: string, options?: {
|
|
202
|
+
expectedEventCursor?: bigint;
|
|
203
|
+
}): Promise<{
|
|
204
|
+
turnId: Uint8Array;
|
|
205
|
+
created: boolean;
|
|
206
|
+
}>;
|
|
207
|
+
readTurn(id: Uint8Array): Promise<NodeHistoryRead>;
|
|
208
|
+
readTurns(ids: Uint8Array[]): Promise<NodeHistoryRead[]>;
|
|
209
|
+
readTurnHeader(id: Uint8Array): Promise<{
|
|
210
|
+
kind: string;
|
|
211
|
+
turn?: {
|
|
212
|
+
sealed: Uint8Array | null;
|
|
213
|
+
nextSeq: bigint;
|
|
214
|
+
bodyVerified: boolean;
|
|
215
|
+
};
|
|
216
|
+
prefix?: {
|
|
217
|
+
sealed: Uint8Array | null;
|
|
218
|
+
nextSeq: bigint;
|
|
219
|
+
bodyVerified: boolean;
|
|
220
|
+
} | null;
|
|
221
|
+
}>;
|
|
222
|
+
readValue(id: Uint8Array, path: ({
|
|
223
|
+
key: string;
|
|
224
|
+
} | {
|
|
225
|
+
index: bigint;
|
|
226
|
+
})[]): Promise<{
|
|
227
|
+
contentJson: string;
|
|
228
|
+
nextSeq: bigint;
|
|
229
|
+
}>;
|
|
230
|
+
edit(id: Uint8Array, seq: bigint, ops: NodeHistoryOp[]): Promise<unknown>;
|
|
231
|
+
seal(id: Uint8Array, seq: bigint): Promise<unknown>;
|
|
232
|
+
turnHeadersAfter?(after: Uint8Array | null, limit: bigint): Promise<{
|
|
233
|
+
kind: string;
|
|
234
|
+
turn?: {
|
|
235
|
+
turnId: Uint8Array;
|
|
236
|
+
};
|
|
237
|
+
}[]>;
|
|
238
|
+
writeBatch(writes: ({
|
|
239
|
+
kind: 'create';
|
|
240
|
+
parents: ParentRef[];
|
|
241
|
+
contentJson: string;
|
|
242
|
+
} | {
|
|
243
|
+
kind: 'createOnce';
|
|
244
|
+
key: Uint8Array;
|
|
245
|
+
parents: ParentRef[];
|
|
246
|
+
contentJson: string;
|
|
247
|
+
} | {
|
|
248
|
+
kind: 'edit';
|
|
249
|
+
turnId: Uint8Array;
|
|
250
|
+
expectedNextSeq: bigint;
|
|
251
|
+
ops: NodeHistoryOp[];
|
|
252
|
+
} | {
|
|
253
|
+
kind: 'editOnce';
|
|
254
|
+
key: Uint8Array;
|
|
255
|
+
expectedNextSeq: bigint;
|
|
256
|
+
ops: NodeHistoryOp[];
|
|
257
|
+
} | {
|
|
258
|
+
kind: 'seal';
|
|
259
|
+
turnId: Uint8Array;
|
|
260
|
+
expectedNextSeq: bigint;
|
|
261
|
+
} | {
|
|
262
|
+
kind: 'sealOnce';
|
|
263
|
+
key: Uint8Array;
|
|
264
|
+
expectedNextSeq: bigint;
|
|
265
|
+
})[], options?: {
|
|
266
|
+
indexPuts?: {
|
|
267
|
+
table: string;
|
|
268
|
+
key: Uint8Array;
|
|
269
|
+
value: Uint8Array;
|
|
270
|
+
onceKey?: Uint8Array;
|
|
271
|
+
emitEvent?: boolean;
|
|
272
|
+
}[];
|
|
273
|
+
expectedEventCursor?: bigint;
|
|
274
|
+
}): Promise<unknown>;
|
|
275
|
+
scanIndex(table: string, start: Uint8Array, limit: bigint): Promise<{
|
|
276
|
+
key: Uint8Array;
|
|
277
|
+
value: Uint8Array;
|
|
278
|
+
}[]>;
|
|
279
|
+
scanIndexReverse?(table: string, end: Uint8Array | null, limit: bigint): Promise<{
|
|
280
|
+
key: Uint8Array;
|
|
281
|
+
value: Uint8Array;
|
|
282
|
+
}[]>;
|
|
283
|
+
readIndex(keys: NodeIndexKey[]): Promise<(Uint8Array | null)[]>;
|
|
284
|
+
compareAndWriteIndex(expected: NodeIndexEntry[], changes: NodeIndexEntry[], options?: {
|
|
285
|
+
eventKeys?: NodeIndexKey[];
|
|
286
|
+
}): Promise<boolean>;
|
|
287
|
+
}
|
|
288
|
+
type NodeIndexKey = {
|
|
289
|
+
table: string;
|
|
290
|
+
key: Uint8Array;
|
|
291
|
+
};
|
|
292
|
+
type NodeIndexEntry = NodeIndexKey & {
|
|
293
|
+
value: Uint8Array | null;
|
|
294
|
+
};
|
|
295
|
+
export declare class NodeLodyHistory {
|
|
296
|
+
readonly stream: LodyNodeHost;
|
|
297
|
+
readonly owner: Uint8Array;
|
|
298
|
+
constructor(stream: LodyNodeHost, owner: Uint8Array);
|
|
299
|
+
/** One bounded local event page. The cursor belongs to this database's
|
|
300
|
+
* event journal, including P2P imports and pending operations when applied.
|
|
301
|
+
* All computation is outside the owner transaction; its cursor CAS rejects
|
|
302
|
+
* a stale page together with every derived change. */
|
|
303
|
+
indexPage(limit?: number): Promise<boolean>;
|
|
304
|
+
catchUpIndex(): Promise<void>;
|
|
305
|
+
invalidMessages(limit?: number): Promise<HistoryDiagnostic[]>;
|
|
306
|
+
lookup(input: HistoryIdentity): Promise<NodeHistoryRead | undefined>;
|
|
307
|
+
acceptJson(input: {
|
|
308
|
+
businessId: string;
|
|
309
|
+
segmentId: string;
|
|
310
|
+
parents: ParentRef[];
|
|
311
|
+
contentJson: string;
|
|
312
|
+
}): Promise<{
|
|
313
|
+
turnId: Uint8Array;
|
|
314
|
+
created: boolean;
|
|
315
|
+
}>;
|
|
316
|
+
read(id: Uint8Array): Promise<NodeHistoryRead>;
|
|
317
|
+
append(id: Uint8Array, seq: bigint, ops: NodeHistoryOp[]): Promise<void>;
|
|
318
|
+
finish(id: Uint8Array, seq: bigint): Promise<void>;
|
|
319
|
+
accept(input: AcceptHistory, options?: {
|
|
320
|
+
publish?: boolean;
|
|
321
|
+
}): Promise<{
|
|
322
|
+
turnId: Uint8Array;
|
|
323
|
+
created: boolean;
|
|
324
|
+
}>;
|
|
325
|
+
respondPermission(input: {
|
|
326
|
+
requestId: string;
|
|
327
|
+
assistantBusinessId: string;
|
|
328
|
+
outcome: JsonValue;
|
|
329
|
+
parents: ParentRef[];
|
|
330
|
+
}): Promise<{
|
|
331
|
+
turnId: Uint8Array;
|
|
332
|
+
created: boolean;
|
|
333
|
+
}>;
|
|
334
|
+
commitHistoryBatch(batchId: string, commands: HistoryBatchCommand[]): Promise<HistoryBatchResult>;
|
|
335
|
+
recoverPendingBatches(): Promise<void>;
|
|
336
|
+
/** A consumer-owned cache. Call refresh on change hints (or host polling). */
|
|
337
|
+
createMessageView(limit?: number): HistoryMessageView;
|
|
338
|
+
readProjectedMessagesById(ids: Uint8Array[]): Promise<HistoryProjectedMessage[]>;
|
|
339
|
+
readProjectedMessages(): Promise<HistoryProjectedMessage[]>;
|
|
340
|
+
readProjectedMessagePage(input?: {
|
|
341
|
+
after?: Uint8Array;
|
|
342
|
+
before?: Uint8Array;
|
|
343
|
+
latest?: boolean;
|
|
344
|
+
limit?: number;
|
|
345
|
+
}): Promise<HistoryProjectedPage>;
|
|
346
|
+
readProjectedEntries(): Promise<{
|
|
347
|
+
businessId: string;
|
|
348
|
+
segmentId: string;
|
|
349
|
+
turnId: Uint8Array;
|
|
350
|
+
entry: unknown;
|
|
351
|
+
nextSeq: bigint;
|
|
352
|
+
sealed: boolean;
|
|
353
|
+
}[]>;
|
|
354
|
+
observedEventCursor(): Promise<bigint>;
|
|
355
|
+
indexedBindings(): Promise<{
|
|
356
|
+
identity: HistoryIdentity;
|
|
357
|
+
binding: Binding;
|
|
358
|
+
}[]>;
|
|
359
|
+
pendingBatchBindings(): AsyncGenerator<{
|
|
360
|
+
identity: HistoryIdentity;
|
|
361
|
+
binding: Binding;
|
|
362
|
+
}>;
|
|
363
|
+
}
|
|
364
|
+
type HistoryHost = LodyHistory | NodeLodyHistory;
|
|
365
|
+
export type HistoryMessageViewUpdate = {
|
|
366
|
+
/** Treat rows and their nested content as read-only. Unchanged rows retain identity. */
|
|
367
|
+
messages: readonly HistoryProjectedMessage[];
|
|
368
|
+
changed: readonly HistoryProjectedMessage[];
|
|
369
|
+
hasMoreOlder: boolean;
|
|
370
|
+
eventCursor: bigint;
|
|
371
|
+
};
|
|
372
|
+
/** Loaded latest window plus any explicitly loaded older pages. Refresh consumes
|
|
373
|
+
* local events and reads only affected published bodies, never the whole page.
|
|
374
|
+
* A view is stream-local and consumer-owned; recreate it after closing the host. */
|
|
375
|
+
export declare class HistoryMessageView {
|
|
376
|
+
private readonly host;
|
|
377
|
+
private readonly limit;
|
|
378
|
+
private state;
|
|
379
|
+
private queue;
|
|
380
|
+
private closed;
|
|
381
|
+
constructor(host: HistoryHost, limit?: number);
|
|
382
|
+
get snapshot(): HistoryMessageViewUpdate | undefined;
|
|
383
|
+
initialize(): Promise<HistoryMessageViewUpdate>;
|
|
384
|
+
refresh(): Promise<HistoryMessageViewUpdate>;
|
|
385
|
+
loadOlder(): Promise<HistoryMessageViewUpdate>;
|
|
386
|
+
dispose(): void;
|
|
387
|
+
private enqueue;
|
|
388
|
+
private read;
|
|
389
|
+
}
|
|
390
|
+
/** Application conversion only: safe integers use integer tags; every other
|
|
391
|
+
* finite JS number keeps its actual IEEE value as f64, including -0. This cannot
|
|
392
|
+
* recover precision already lost before the caller supplied a Number. */
|
|
393
|
+
export declare function fromApplicationJson(input: unknown): JsonValue;
|
|
394
|
+
/** Integer tags outside the safe range return bigint, never a rounded Number. */
|
|
395
|
+
export declare function toApplicationJson(input: JsonValue): unknown;
|
|
396
|
+
export declare function applicationJsonText(input: unknown): string;
|
|
397
|
+
export {};
|