@lazily-hub/lazily-js 0.4.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/.github/workflows/release.yml +48 -0
- package/README.md +356 -0
- package/package.json +64 -0
- package/src/collections.d.ts +110 -0
- package/src/collections.js +413 -0
- package/src/index.d.ts +416 -0
- package/src/index.js +1109 -0
- package/src/reactive.d.ts +43 -0
- package/src/reactive.js +531 -0
- package/src/sem-tree.d.ts +21 -0
- package/src/sem-tree.js +130 -0
- package/src/seq-crdt.d.ts +44 -0
- package/src/seq-crdt.js +364 -0
- package/src/stable-id.d.ts +45 -0
- package/src/stable-id.js +214 -0
- package/src/state-machine.d.ts +14 -0
- package/src/state-machine.js +78 -0
- package/src/state-projection.d.ts +114 -0
- package/src/state-projection.js +256 -0
- package/src/statechart.d.ts +154 -0
- package/src/statechart.js +678 -0
- package/src/text-crdt.d.ts +23 -0
- package/src/text-crdt.js +317 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
export type NodeId = number;
|
|
2
|
+
export type PeerId = number;
|
|
3
|
+
export type WireBytes = readonly number[] | Uint8Array;
|
|
4
|
+
|
|
5
|
+
export class ShmBlobRef {
|
|
6
|
+
constructor(fields: {
|
|
7
|
+
offset: number;
|
|
8
|
+
len: number;
|
|
9
|
+
generation: number;
|
|
10
|
+
epoch: number;
|
|
11
|
+
checksum: number;
|
|
12
|
+
});
|
|
13
|
+
readonly offset: number;
|
|
14
|
+
readonly len: number;
|
|
15
|
+
readonly generation: number;
|
|
16
|
+
readonly epoch: number;
|
|
17
|
+
readonly checksum: number;
|
|
18
|
+
toWire(): ShmBlobRefWire;
|
|
19
|
+
static fromWire(value: ShmBlobRefWire): ShmBlobRef;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type ShmBlobRefWire = {
|
|
23
|
+
offset: number;
|
|
24
|
+
len: number;
|
|
25
|
+
generation: number;
|
|
26
|
+
epoch: number;
|
|
27
|
+
checksum: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export class NodeStatePayload {
|
|
31
|
+
constructor(bytes: WireBytes);
|
|
32
|
+
readonly bytes: readonly number[];
|
|
33
|
+
toWire(): { Payload: number[] };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class NodeStateSharedBlob {
|
|
37
|
+
constructor(blob: ShmBlobRef | ShmBlobRefWire);
|
|
38
|
+
readonly blob: ShmBlobRef;
|
|
39
|
+
toWire(): { SharedBlob: ShmBlobRefWire };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class NodeStateOpaque {
|
|
43
|
+
toWire(): "Opaque";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type NodeStateValue =
|
|
47
|
+
| NodeStatePayload
|
|
48
|
+
| NodeStateSharedBlob
|
|
49
|
+
| NodeStateOpaque;
|
|
50
|
+
|
|
51
|
+
export const NodeState: {
|
|
52
|
+
payload(bytes: WireBytes): NodeStatePayload;
|
|
53
|
+
sharedBlob(blob: ShmBlobRef | ShmBlobRefWire): NodeStateSharedBlob;
|
|
54
|
+
opaque(): NodeStateOpaque;
|
|
55
|
+
fromWire(value: unknown): NodeStateValue;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export class IpcValueInline {
|
|
59
|
+
constructor(bytes: WireBytes);
|
|
60
|
+
readonly bytes: readonly number[];
|
|
61
|
+
toWire(): { Inline: number[] };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class IpcValueSharedBlob {
|
|
65
|
+
constructor(blob: ShmBlobRef | ShmBlobRefWire);
|
|
66
|
+
readonly blob: ShmBlobRef;
|
|
67
|
+
toWire(): { SharedBlob: ShmBlobRefWire };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type IpcValueValue = IpcValueInline | IpcValueSharedBlob;
|
|
71
|
+
|
|
72
|
+
export const IpcValue: {
|
|
73
|
+
inline(bytes: WireBytes): IpcValueInline;
|
|
74
|
+
sharedBlob(blob: ShmBlobRef | ShmBlobRefWire): IpcValueSharedBlob;
|
|
75
|
+
of(value: IpcValueValue | ShmBlobRef | ShmBlobRefWire | WireBytes): IpcValueValue;
|
|
76
|
+
fromWire(value: unknown): IpcValueValue;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export class NodeSnapshot {
|
|
80
|
+
constructor(node: NodeId, typeTag: string, state: NodeStateValue, key?: string | null);
|
|
81
|
+
readonly node: NodeId;
|
|
82
|
+
readonly typeTag: string;
|
|
83
|
+
readonly state: NodeStateValue;
|
|
84
|
+
readonly key: string | null;
|
|
85
|
+
toWire(): unknown;
|
|
86
|
+
static payload(node: NodeId, typeTag: string, bytes: WireBytes, key?: string | null): NodeSnapshot;
|
|
87
|
+
static sharedBlob(
|
|
88
|
+
node: NodeId,
|
|
89
|
+
typeTag: string,
|
|
90
|
+
blob: ShmBlobRef | ShmBlobRefWire,
|
|
91
|
+
key?: string | null,
|
|
92
|
+
): NodeSnapshot;
|
|
93
|
+
static opaque(node: NodeId, typeTag: string, key?: string | null): NodeSnapshot;
|
|
94
|
+
static fromWire(value: unknown): NodeSnapshot;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export class EdgeSnapshot {
|
|
98
|
+
constructor(dependent: NodeId, dependency: NodeId);
|
|
99
|
+
readonly dependent: NodeId;
|
|
100
|
+
readonly dependency: NodeId;
|
|
101
|
+
toWire(): { dependent: NodeId; dependency: NodeId };
|
|
102
|
+
isReadableBy(permissions: PeerPermissions, peer: PeerId): boolean;
|
|
103
|
+
static fromWire(value: unknown): EdgeSnapshot;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export class Snapshot {
|
|
107
|
+
constructor(fields: {
|
|
108
|
+
epoch: number;
|
|
109
|
+
nodes?: readonly NodeSnapshot[];
|
|
110
|
+
edges?: readonly EdgeSnapshot[];
|
|
111
|
+
roots?: readonly NodeId[];
|
|
112
|
+
});
|
|
113
|
+
readonly epoch: number;
|
|
114
|
+
readonly nodes: readonly NodeSnapshot[];
|
|
115
|
+
readonly edges: readonly EdgeSnapshot[];
|
|
116
|
+
readonly roots: readonly NodeId[];
|
|
117
|
+
toWire(): unknown;
|
|
118
|
+
filterReadable(permissions: PeerPermissions, peer: PeerId): Snapshot;
|
|
119
|
+
static fromWire(value: unknown): Snapshot;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type DeltaOpValue =
|
|
123
|
+
| DeltaOpCellSet
|
|
124
|
+
| DeltaOpSlotValue
|
|
125
|
+
| DeltaOpInvalidate
|
|
126
|
+
| DeltaOpNodeAdd
|
|
127
|
+
| DeltaOpNodeRemove
|
|
128
|
+
| DeltaOpEdgeAdd
|
|
129
|
+
| DeltaOpEdgeRemove;
|
|
130
|
+
|
|
131
|
+
export class DeltaOpCellSet {
|
|
132
|
+
constructor(node: NodeId, payload: IpcValueValue | ShmBlobRef | WireBytes);
|
|
133
|
+
readonly node: NodeId;
|
|
134
|
+
readonly payload: IpcValueValue;
|
|
135
|
+
toWire(): unknown;
|
|
136
|
+
targetReadable(permissions: PeerPermissions, peer: PeerId): boolean;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export class DeltaOpSlotValue {
|
|
140
|
+
constructor(node: NodeId, payload: IpcValueValue | ShmBlobRef | WireBytes);
|
|
141
|
+
readonly node: NodeId;
|
|
142
|
+
readonly payload: IpcValueValue;
|
|
143
|
+
toWire(): unknown;
|
|
144
|
+
targetReadable(permissions: PeerPermissions, peer: PeerId): boolean;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export class DeltaOpInvalidate {
|
|
148
|
+
constructor(node: NodeId);
|
|
149
|
+
readonly node: NodeId;
|
|
150
|
+
toWire(): unknown;
|
|
151
|
+
targetReadable(permissions: PeerPermissions, peer: PeerId): boolean;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export class DeltaOpNodeAdd {
|
|
155
|
+
constructor(node: NodeId, typeTag: string, state: NodeStateValue, key?: string | null);
|
|
156
|
+
readonly node: NodeId;
|
|
157
|
+
readonly typeTag: string;
|
|
158
|
+
readonly state: NodeStateValue;
|
|
159
|
+
readonly key: string | null;
|
|
160
|
+
toWire(): unknown;
|
|
161
|
+
targetReadable(permissions: PeerPermissions, peer: PeerId): boolean;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export class DeltaOpNodeRemove {
|
|
165
|
+
constructor(node: NodeId);
|
|
166
|
+
readonly node: NodeId;
|
|
167
|
+
toWire(): unknown;
|
|
168
|
+
targetReadable(permissions: PeerPermissions, peer: PeerId): boolean;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export class DeltaOpEdgeAdd {
|
|
172
|
+
constructor(dependent: NodeId, dependency: NodeId);
|
|
173
|
+
readonly dependent: NodeId;
|
|
174
|
+
readonly dependency: NodeId;
|
|
175
|
+
toWire(): unknown;
|
|
176
|
+
targetReadable(permissions: PeerPermissions, peer: PeerId): boolean;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export class DeltaOpEdgeRemove {
|
|
180
|
+
constructor(dependent: NodeId, dependency: NodeId);
|
|
181
|
+
readonly dependent: NodeId;
|
|
182
|
+
readonly dependency: NodeId;
|
|
183
|
+
toWire(): unknown;
|
|
184
|
+
targetReadable(permissions: PeerPermissions, peer: PeerId): boolean;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export const DeltaOp: {
|
|
188
|
+
cellSet(node: NodeId, payload: IpcValueValue | ShmBlobRef | WireBytes): DeltaOpCellSet;
|
|
189
|
+
slotValue(node: NodeId, payload: IpcValueValue | ShmBlobRef | WireBytes): DeltaOpSlotValue;
|
|
190
|
+
invalidate(node: NodeId): DeltaOpInvalidate;
|
|
191
|
+
nodeAdd(node: NodeId, typeTag: string, state: NodeStateValue, key?: string | null): DeltaOpNodeAdd;
|
|
192
|
+
nodeRemove(node: NodeId): DeltaOpNodeRemove;
|
|
193
|
+
edgeAdd(dependent: NodeId, dependency: NodeId): DeltaOpEdgeAdd;
|
|
194
|
+
edgeRemove(dependent: NodeId, dependency: NodeId): DeltaOpEdgeRemove;
|
|
195
|
+
fromWire(value: unknown): DeltaOpValue;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export const DeltaApplyStatusKind: {
|
|
199
|
+
readonly Apply: "apply";
|
|
200
|
+
readonly ResyncRequired: "resync_required";
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export class DeltaApplyStatus {
|
|
204
|
+
readonly kind: "apply" | "resync_required";
|
|
205
|
+
readonly lastEpoch?: number;
|
|
206
|
+
readonly baseEpoch?: number;
|
|
207
|
+
readonly epoch?: number;
|
|
208
|
+
readonly isApply: boolean;
|
|
209
|
+
readonly isResyncRequired: boolean;
|
|
210
|
+
static apply(): DeltaApplyStatus;
|
|
211
|
+
static resyncRequired(lastEpoch: number, baseEpoch: number, epoch: number): DeltaApplyStatus;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export class Delta {
|
|
215
|
+
constructor(fields: {
|
|
216
|
+
baseEpoch: number;
|
|
217
|
+
epoch: number;
|
|
218
|
+
ops?: readonly DeltaOpValue[];
|
|
219
|
+
});
|
|
220
|
+
readonly baseEpoch: number;
|
|
221
|
+
readonly epoch: number;
|
|
222
|
+
readonly ops: readonly DeltaOpValue[];
|
|
223
|
+
isNextAfter(lastEpoch: number): boolean;
|
|
224
|
+
applyStatus(lastEpoch: number): DeltaApplyStatus;
|
|
225
|
+
filterReadable(permissions: PeerPermissions, peer: PeerId): Delta;
|
|
226
|
+
toWire(): unknown;
|
|
227
|
+
static next(baseEpoch: number, ops?: readonly DeltaOpValue[]): Delta;
|
|
228
|
+
static fromWire(value: unknown): Delta;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export class WireStamp {
|
|
232
|
+
constructor(fields: { wallTime: number; logical: number; peer: number });
|
|
233
|
+
readonly wallTime: number;
|
|
234
|
+
readonly logical: number;
|
|
235
|
+
readonly peer: number;
|
|
236
|
+
toWire(): WireStampWire;
|
|
237
|
+
static fromWire(value: WireStampWire): WireStamp;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export type WireStampWire = {
|
|
241
|
+
wall_time: number;
|
|
242
|
+
logical: number;
|
|
243
|
+
peer: number;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export type FrontierEntry = { peer: NodeId; stamp: WireStamp };
|
|
247
|
+
|
|
248
|
+
export class CrdtOp {
|
|
249
|
+
constructor(
|
|
250
|
+
node: NodeId,
|
|
251
|
+
stamp: WireStamp | WireStampWire,
|
|
252
|
+
state: IpcValueValue | ShmBlobRef | WireBytes,
|
|
253
|
+
key?: string | null,
|
|
254
|
+
);
|
|
255
|
+
readonly node: NodeId;
|
|
256
|
+
readonly stamp: WireStamp;
|
|
257
|
+
readonly state: IpcValueValue;
|
|
258
|
+
readonly key: string | null;
|
|
259
|
+
toWire(): unknown;
|
|
260
|
+
targetReadable(permissions: PeerPermissions, peer: PeerId): boolean;
|
|
261
|
+
static keyed(
|
|
262
|
+
node: NodeId,
|
|
263
|
+
key: string | null,
|
|
264
|
+
stamp: WireStamp | WireStampWire,
|
|
265
|
+
state: IpcValueValue | ShmBlobRef | WireBytes,
|
|
266
|
+
): CrdtOp;
|
|
267
|
+
static fromWire(value: unknown): CrdtOp;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export class CrdtSync {
|
|
271
|
+
constructor(fields: {
|
|
272
|
+
frontier?: ReadonlyArray<FrontierEntry | [NodeId, WireStamp | WireStampWire]>;
|
|
273
|
+
ops?: ReadonlyArray<CrdtOp>;
|
|
274
|
+
});
|
|
275
|
+
readonly frontier: ReadonlyArray<FrontierEntry>;
|
|
276
|
+
readonly ops: ReadonlyArray<CrdtOp>;
|
|
277
|
+
filterReadable(permissions: PeerPermissions, peer: PeerId): CrdtSync;
|
|
278
|
+
toWire(): unknown;
|
|
279
|
+
static fromWire(value: unknown): CrdtSync;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export class IpcMessage {
|
|
283
|
+
readonly kind: "Snapshot" | "Delta" | "CrdtSync";
|
|
284
|
+
readonly snapshot?: Snapshot;
|
|
285
|
+
readonly delta?: Delta;
|
|
286
|
+
readonly crdtSync?: CrdtSync;
|
|
287
|
+
readonly isSnapshot: boolean;
|
|
288
|
+
readonly isDelta: boolean;
|
|
289
|
+
readonly isCrdtSync: boolean;
|
|
290
|
+
toWire(): unknown;
|
|
291
|
+
encodeJson(): Uint8Array;
|
|
292
|
+
static snapshot(snapshot: Snapshot): IpcMessage;
|
|
293
|
+
static delta(delta: Delta): IpcMessage;
|
|
294
|
+
static crdtSync(crdtSync: CrdtSync): IpcMessage;
|
|
295
|
+
static fromWire(value: unknown): IpcMessage;
|
|
296
|
+
static decodeJson(data: Uint8Array | string): IpcMessage;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export const OpKind: {
|
|
300
|
+
readonly Read: "read";
|
|
301
|
+
readonly Write: "write";
|
|
302
|
+
readonly TriggerEffect: "trigger_effect";
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
export class RemoteOp {
|
|
306
|
+
constructor(kind: string, node: NodeId);
|
|
307
|
+
readonly kind: string;
|
|
308
|
+
readonly node: NodeId;
|
|
309
|
+
static read(node: NodeId): RemoteOp;
|
|
310
|
+
static write(node: NodeId): RemoteOp;
|
|
311
|
+
static triggerEffect(node: NodeId): RemoteOp;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export class PermissionDenied extends Error {
|
|
315
|
+
readonly peer: PeerId;
|
|
316
|
+
readonly op: RemoteOp;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export class PeerPermissions {
|
|
320
|
+
allow(peer: PeerId, op: RemoteOp): boolean;
|
|
321
|
+
allowMany(peer: PeerId, kind: string, nodes: Iterable<NodeId>): void;
|
|
322
|
+
revoke(peer: PeerId, op: RemoteOp): boolean;
|
|
323
|
+
revokePeer(peer: PeerId): boolean;
|
|
324
|
+
isAllowed(peer: PeerId, op: RemoteOp): boolean;
|
|
325
|
+
canRead(peer: PeerId, node: NodeId): boolean;
|
|
326
|
+
check(peer: PeerId, op: RemoteOp): void;
|
|
327
|
+
filterReadable(peer: PeerId, nodes: Iterable<NodeId>): NodeId[];
|
|
328
|
+
peerCount(): number;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Capability negotiation (protocol.md § Capability Negotiation).
|
|
332
|
+
export const PROTOCOL_ID: "lazily-ipc";
|
|
333
|
+
export const PROTOCOL_MAJOR_VERSION: 1;
|
|
334
|
+
|
|
335
|
+
export const Codec: {
|
|
336
|
+
readonly Json: "json";
|
|
337
|
+
readonly Bincode: "bincode";
|
|
338
|
+
readonly Postcard: "postcard";
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export const LazilyFfiMessageKind: {
|
|
342
|
+
readonly Unknown: 0;
|
|
343
|
+
readonly Snapshot: 1;
|
|
344
|
+
readonly Delta: 2;
|
|
345
|
+
readonly CrdtSync: 3;
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
export const LazilyFfiStatus: {
|
|
349
|
+
readonly Ok: 0;
|
|
350
|
+
readonly Empty: 1;
|
|
351
|
+
readonly NullPointer: 2;
|
|
352
|
+
readonly InvalidMessage: 3;
|
|
353
|
+
readonly EncodeFailed: 4;
|
|
354
|
+
readonly Panic: 5;
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
export type HandshakeWire = {
|
|
358
|
+
protocol_id: string;
|
|
359
|
+
protocol_major_version: number;
|
|
360
|
+
codec: string;
|
|
361
|
+
max_frame_size: number;
|
|
362
|
+
fragmentation_supported: boolean;
|
|
363
|
+
ordered_reliable: boolean;
|
|
364
|
+
peer_id: NodeId;
|
|
365
|
+
session_id: string;
|
|
366
|
+
features?: string[];
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
export type CompatibilityResult =
|
|
370
|
+
| { ok: true }
|
|
371
|
+
| { ok: false; field: string; reason: string };
|
|
372
|
+
|
|
373
|
+
export class SessionHandshake {
|
|
374
|
+
constructor(fields: HandshakeWire);
|
|
375
|
+
readonly protocolId: string;
|
|
376
|
+
readonly protocolMajorVersion: number;
|
|
377
|
+
readonly codec: string;
|
|
378
|
+
readonly maxFrameSize: number;
|
|
379
|
+
readonly fragmentationSupported: boolean;
|
|
380
|
+
readonly orderedReliable: boolean;
|
|
381
|
+
readonly peerId: NodeId;
|
|
382
|
+
readonly sessionId: string;
|
|
383
|
+
readonly features: readonly string[];
|
|
384
|
+
toWire(): HandshakeWire;
|
|
385
|
+
encodeJson(): Uint8Array;
|
|
386
|
+
checkCompatible(other: SessionHandshake, requiredFeatures?: string[]): CompatibilityResult;
|
|
387
|
+
static fromWire(value: unknown): SessionHandshake;
|
|
388
|
+
static decodeJson(data: Uint8Array | string): SessionHandshake;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export const FfiCapability: {
|
|
392
|
+
readonly Host: "host";
|
|
393
|
+
readonly None: "none";
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
export type BindingCapabilities = {
|
|
397
|
+
readonly binding: string;
|
|
398
|
+
readonly ffi: "host" | "none";
|
|
399
|
+
readonly reactive_core: boolean;
|
|
400
|
+
readonly async_context: boolean;
|
|
401
|
+
readonly ipc: boolean;
|
|
402
|
+
readonly crdt: boolean;
|
|
403
|
+
readonly collections: { cellmap: boolean; celltree: boolean; reconcile: boolean };
|
|
404
|
+
readonly sem_tree: boolean;
|
|
405
|
+
readonly seq_crdt: boolean;
|
|
406
|
+
readonly text_crdt: boolean;
|
|
407
|
+
readonly stable_id: boolean;
|
|
408
|
+
readonly state_machine: boolean;
|
|
409
|
+
readonly state_charts: boolean;
|
|
410
|
+
readonly permissions: boolean;
|
|
411
|
+
readonly capability_negotiation: boolean;
|
|
412
|
+
readonly signaling: boolean;
|
|
413
|
+
readonly webrtc: boolean;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
export const BINDING_CAPABILITIES: BindingCapabilities;
|