reptree 0.9.0 → 1.0.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/dist/index.d.cts CHANGED
@@ -20,52 +20,52 @@ declare function tryParseOpIdStr(opIdStr: string): OpId;
20
20
  declare function isOpIdGreaterThan(opIdA: OpId | string, opIdB: OpId | string): boolean;
21
21
  declare function opIdToString(opId: OpId): string;
22
22
 
23
- declare class VertexState {
23
+ declare class NodeState {
24
24
  readonly id: string;
25
- parentId: TreeVertexId | null;
25
+ parentId: TreeNodeId | null;
26
26
  private properties;
27
27
  private transientProperties;
28
28
  children: string[];
29
- constructor(id: string, parentId: TreeVertexId | null);
30
- setProperty(key: string, value: VertexPropertyType): void;
31
- setTransientProperty(key: string, value: VertexPropertyType): void;
32
- getProperty(key: string, includingTransient?: boolean): VertexPropertyType | undefined;
33
- getAllProperties(includingTransient?: boolean): ReadonlyArray<TreeVertexProperty>;
29
+ constructor(id: string, parentId: TreeNodeId | null);
30
+ setProperty(key: string, value: NodePropertyType): void;
31
+ setTransientProperty(key: string, value: NodePropertyType): void;
32
+ getProperty(key: string, includingTransient?: boolean): NodePropertyType | undefined;
33
+ getAllProperties(includingTransient?: boolean): ReadonlyArray<TreeNodeProperty>;
34
34
  removeProperty(key: string): void;
35
35
  removeTransientProperty(key: string): void;
36
- getTransientProperties(): ReadonlyArray<TreeVertexProperty>;
36
+ getTransientProperties(): ReadonlyArray<TreeNodeProperty>;
37
37
  clearAllTransientProperties(): void;
38
38
  }
39
39
 
40
- type TreeVertexId = string;
40
+ type TreeNodeId = string;
41
41
  type JsonPrimitive = string | number | boolean | null;
42
42
  type JsonValue = JsonPrimitive | JsonValue[] | {
43
43
  [key: string]: JsonValue;
44
44
  };
45
45
  /** Property type for state (undefined means removal) */
46
- type VertexPropertyType = JsonValue | undefined;
47
- type TreeVertexProperty = {
46
+ type NodePropertyType = JsonValue | undefined;
47
+ type TreeNodeProperty = {
48
48
  readonly key: string;
49
- readonly value: VertexPropertyType;
49
+ readonly value: NodePropertyType;
50
50
  };
51
- type VertexChangeEventType = 'move' | 'property' | 'children';
52
- interface VertexChangeEvent {
53
- type: VertexChangeEventType;
54
- vertexId: TreeVertexId;
51
+ type NodeChangeEventType = 'move' | 'property' | 'children';
52
+ interface NodeChangeEvent {
53
+ type: NodeChangeEventType;
54
+ nodeId: TreeNodeId;
55
55
  }
56
- type VertexPropertyChangeEvent = VertexChangeEvent & {
56
+ type NodePropertyChangeEvent = NodeChangeEvent & {
57
57
  type: 'property';
58
58
  key: string;
59
- value: VertexPropertyType | undefined;
59
+ value: NodePropertyType | undefined;
60
60
  };
61
- type VertexMoveEvent = VertexChangeEvent & {
61
+ type NodeMoveEvent = NodeChangeEvent & {
62
62
  type: 'move';
63
- oldParentId: TreeVertexId | null | undefined;
64
- newParentId: TreeVertexId;
63
+ oldParentId: TreeNodeId | null | undefined;
64
+ newParentId: TreeNodeId;
65
65
  };
66
- type VertexChildrenChangeEvent = VertexChangeEvent & {
66
+ type NodeChildrenChangeEvent = NodeChangeEvent & {
67
67
  type: 'children';
68
- children: VertexState[];
68
+ children: NodeState[];
69
69
  };
70
70
  /**
71
71
  * Type definition for operation ID range used in state vectors
@@ -75,25 +75,29 @@ interface OpIdRange {
75
75
  start: number;
76
76
  end: number;
77
77
  }
78
+ type StateVectors = {
79
+ move: Record<string, number[][]>;
80
+ prop: Record<string, number[][]>;
81
+ };
78
82
 
79
- interface MoveVertex {
83
+ interface MoveNode {
80
84
  id: OpId;
81
85
  targetId: string;
82
86
  parentId: string | null;
83
87
  }
84
- interface SetVertexProperty {
88
+ interface SetNodeProperty {
85
89
  id: OpId;
86
90
  targetId: string;
87
91
  key: string;
88
- value: VertexPropertyType;
92
+ value: NodePropertyType;
89
93
  transient: boolean;
90
94
  }
91
- type VertexOperation = MoveVertex | SetVertexProperty;
92
- declare function isMoveVertexOp(op: VertexOperation): op is MoveVertex;
93
- declare function isAnyPropertyOp(op: VertexOperation): op is SetVertexProperty;
94
- declare function newMoveVertexOp(clock: number, peerId: string, targetId: string, parentId: string | null): MoveVertex;
95
- declare function newSetVertexPropertyOp(clock: number, peerId: string, targetId: string, key: string, value: VertexPropertyType): SetVertexProperty;
96
- declare function newSetTransientVertexPropertyOp(clock: number, peerId: string, targetId: string, key: string, value: VertexPropertyType): SetVertexProperty;
95
+ type NodeOperation = MoveNode | SetNodeProperty;
96
+ declare function isMoveNodeOp(op: NodeOperation): op is MoveNode;
97
+ declare function isAnyPropertyOp(op: NodeOperation): op is SetNodeProperty;
98
+ declare function newMoveNodeOp(clock: number, peerId: string, targetId: string, parentId: string | null): MoveNode;
99
+ declare function newSetNodePropertyOp(clock: number, peerId: string, targetId: string, key: string, value: NodePropertyType): SetNodeProperty;
100
+ declare function newSetTransientNodePropertyOp(clock: number, peerId: string, targetId: string, key: string, value: NodePropertyType): SetNodeProperty;
97
101
 
98
102
  type FieldSchemaLike = {
99
103
  safeParse?: (input: unknown) => {
@@ -118,15 +122,15 @@ type BindOptions<T> = {
118
122
  includeInternalKeys?: boolean;
119
123
  };
120
124
  /**
121
- * A bound vertex object that forwards reads/writes to a vertex.
122
- * @param T - The type of the vertex.
125
+ * A bound node object that forwards reads/writes to a node.
126
+ * @param T - The type of the node.
123
127
  */
124
- type BindedVertex<T> = T & {
125
- $vertex: Vertex;
128
+ type BindedNode<T> = T & {
129
+ $node: Node;
126
130
  $id: string;
127
131
  $parentId: string | null;
128
- $parent: Vertex | undefined;
129
- $children: Vertex[];
132
+ $parent: Node | undefined;
133
+ $children: Node[];
130
134
  $childrenIds: string[];
131
135
  /**
132
136
  * Apply transient edits that override reads but do not persist yet.
@@ -138,183 +142,185 @@ type BindedVertex<T> = T & {
138
142
  */
139
143
  $commitTransients(): void;
140
144
  /**
141
- * Move the vertex to a new parent.
142
- * @param parent - The new parent vertex or ID.
145
+ * Move the node to a new parent.
146
+ * @param parent - The new parent node or ID.
143
147
  */
144
- $moveTo(parent: Vertex | BindedVertex<any> | string): void;
148
+ $moveTo(parent: Node | BindedNode<any> | string): void;
145
149
  /**
146
- * Delete the vertex.
150
+ * Delete the node.
147
151
  */
148
152
  $delete(): void;
149
153
  /**
150
- * Observe changes to the vertex.
154
+ * Observe changes to the node.
151
155
  * @param listener - The listener function to call when changes occur.
152
156
  */
153
157
  $observe(listener: (events: any[]) => void): () => void;
154
158
  /**
155
- * Observe changes to the children of the vertex.
159
+ * Observe changes to the children of the node.
156
160
  * @param listener - The listener function to call when children change.
157
161
  */
158
- $observeChildren(listener: (children: Vertex[]) => void): () => void;
162
+ $observeChildren(listener: (children: Node[]) => void): () => void;
159
163
  /**
160
- * Create a new child vertex.
161
- * @param props - The properties to set on the new child vertex.
164
+ * Create a new child node.
165
+ * @param props - The properties to set on the new child node.
162
166
  */
163
- $newChild(props?: Record<string, any> | object | null): Vertex;
167
+ $newChild(props?: Record<string, any> | object | null): Node;
164
168
  /**
165
- * Create a new named child vertex.
166
- * @param name - The name of the new child vertex.
167
- * @param props - The properties to set on the new child vertex.
169
+ * Create a new named child node.
170
+ * @param name - The name of the new child node.
171
+ * @param props - The properties to set on the new child node.
168
172
  */
169
- $newNamedChild(name: string, props?: Record<string, any> | object | null): Vertex;
173
+ $newNamedChild(name: string, props?: Record<string, any> | object | null): Node;
170
174
  };
171
175
  /**
172
- * Returns a live Proxy that forwards reads/writes to a vertex.
176
+ * Returns a live Proxy that forwards reads/writes to a node.
173
177
  * - Reads reflect the latest CRDT state (including transients by default)
174
178
  * - Writes persist to the CRDT with optional schema validation
175
179
  */
176
- declare function bindVertex<T extends Record<string, unknown>>(tree: RepTree, id: string, schemaOrOptions?: SchemaLike<T> | BindOptions<T>): BindedVertex<T>;
180
+ declare function bindNode<T extends Record<string, unknown>>(tree: RepTree, id: string, schemaOrOptions?: SchemaLike<T> | BindOptions<T>): BindedNode<T>;
177
181
 
178
182
  /**
179
- * A wrapper class for VertexState that provides a more convenient API
180
- * for working with vertices in a RepTree.
183
+ * A wrapper class for NodeState that provides a more convenient API
184
+ * for working with nodes in a RepTree.
181
185
  */
182
- declare class Vertex {
186
+ declare class Node {
183
187
  private state;
184
188
  private _tree;
185
- constructor(tree: RepTree, state: VertexState);
186
- /** Returns the tree this vertex belongs to. */
189
+ constructor(tree: RepTree, state: NodeState);
190
+ /** Returns the tree this node belongs to. */
187
191
  get tree(): RepTree;
188
192
  private set tree(value);
189
- /** Returns the ID of this vertex. */
193
+ /** Returns the ID of this node. */
190
194
  get id(): string;
191
- /** Returns the name of this vertex. The name is stored as a property with the key 'name'. */
195
+ /** Returns the name of this node. The name is stored as a property with the key 'name'. */
192
196
  get name(): string | undefined;
193
- /** Sets the name of this vertex. The name is stored as a property with the key 'name'. */
197
+ /** Sets the name of this node. The name is stored as a property with the key 'name'. */
194
198
  set name(name: string);
195
- /** Returns the creation date of this vertex. The creation date is stored as a property with the key '_c'. */
199
+ /** Returns the creation date of this node. The creation date is stored as a property with the key '_c'. */
196
200
  get createdAt(): Date;
197
- /** Returns the ID of the parent vertex of this vertex. */
201
+ /** Returns the ID of the parent node of this node. */
198
202
  get parentId(): string | null;
199
- /** Returns the parent vertex of this vertex. */
200
- get parent(): Vertex | undefined;
201
- /** Returns the children vertices of this vertex. */
202
- get children(): Vertex[];
203
- /** Returns the IDs of the children vertices of this vertex. */
203
+ /** Returns the parent node of this node. */
204
+ get parent(): Node | undefined;
205
+ /** Returns the children nodes of this node. */
206
+ get children(): Node[];
207
+ /** Returns the IDs of the children nodes of this node. */
204
208
  get childrenIds(): string[];
205
- /** Returns the ancestors of this vertex. The first element is the root vertex.
209
+ /** Returns the ancestors of this node. The first element is the root node.
206
210
  * E.g root -> grandparent -> parent.
207
- * Doesn't include this vertex in the array.
211
+ * Doesn't include this node in the array.
208
212
  */
209
- get ancestors(): Vertex[];
210
- /** Returns the ID of the root vertex of the tree this vertex belongs to. */
213
+ get ancestors(): Node[];
214
+ /** Returns the ID of the root node of the tree this node belongs to. */
211
215
  get treeId(): string;
212
- /** Returns the root vertex of the tree this vertex belongs to. */
213
- get root(): Vertex;
216
+ /** Returns the root node of the tree this node belongs to. */
217
+ get root(): Node;
214
218
  getAsTypedObject<T>(): T;
215
219
  getChildrenAsTypedArray<T>(): T[];
216
- /** Creates a new child vertex of this vertex. */
217
- newChild(props?: Record<string, VertexPropertyType> | object | null): Vertex;
218
- /** Creates a new named child vertex of this vertex. */
219
- newNamedChild(name: string, props?: Record<string, VertexPropertyType> | object | null): Vertex;
220
- /** Sets a property on this vertex. */
221
- setProperty(key: string, value: VertexPropertyType): void;
222
- /** Sets a transient property on this vertex. Transient properties are not persisted to the tree and are not included in the state vector. */
223
- setTransientProperty(key: string, value: VertexPropertyType): void;
220
+ /** Creates a new child node of this node. */
221
+ newChild(props?: Record<string, NodePropertyType> | object | null): Node;
222
+ /** Creates a new named child node of this node. */
223
+ newNamedChild(name: string, props?: Record<string, NodePropertyType> | object | null): Node;
224
+ /** Sets a property on this node. */
225
+ setProperty(key: string, value: NodePropertyType): void;
226
+ /** Sets a transient property on this node. Transient properties are not persisted to the tree and are not included in the state vector. */
227
+ setTransientProperty(key: string, value: NodePropertyType): void;
224
228
  /** Promotes all transient (temporary) properties to persistent properties. */
225
229
  commitTransients(): void;
226
- /** Sets multiple properties on this vertex. */
227
- setProperties(props: Record<string, VertexPropertyType> | object): void;
228
- /** Returns the value of a property on this vertex. */
229
- getProperty(key: string, includingTransient?: boolean): VertexPropertyType | undefined;
230
- /** Returns all properties on this vertex. */
231
- getProperties(): Record<string, VertexPropertyType>;
232
- findAllChildrenWithProperty(key: string, value: VertexPropertyType): Vertex[];
233
- findFirstChildVertexWithProperty(key: string, value: VertexPropertyType): Vertex | undefined;
234
- findFirstTypedChildWithProperty<T>(key: string, value: VertexPropertyType): T | undefined;
235
- findAllTypedChildrenWithProperty<T>(key: string, value: VertexPropertyType): T[];
236
- /** Observes changes to this vertex. */
237
- observe(listener: (events: VertexChangeEvent[]) => void): () => void;
238
- /** Observes changes to the children of this vertex. */
239
- observeChildren(listener: (children: Vertex[]) => void): () => void;
230
+ /** Sets multiple properties on this node. */
231
+ setProperties(props: Record<string, NodePropertyType> | object): void;
232
+ /** Returns the value of a property on this node. */
233
+ getProperty(key: string, includingTransient?: boolean): NodePropertyType | undefined;
234
+ /** Returns all properties on this node. */
235
+ getProperties(): Record<string, NodePropertyType>;
236
+ findAllChildrenWithProperty(key: string, value: NodePropertyType): Node[];
237
+ findFirstChildNodeWithProperty(key: string, value: NodePropertyType): Node | undefined;
238
+ findFirstTypedChildWithProperty<T>(key: string, value: NodePropertyType): T | undefined;
239
+ findAllTypedChildrenWithProperty<T>(key: string, value: NodePropertyType): T[];
240
+ /** Observes changes to this node. */
241
+ observe(listener: (events: NodeChangeEvent[]) => void): () => void;
242
+ /** Observes changes to the children of this node. */
243
+ observeChildren(listener: (children: Node[]) => void): () => void;
240
244
  observeChildrenAsTypedArray<T>(listener: (children: T[]) => void): () => void;
241
245
  delete(): void;
242
- moveTo(parent: Vertex): void;
243
- /** Returns a live reactive object bound to this vertex. Accepts schema or options. */
244
- bind<T extends Record<string, unknown>>(schemaOrOptions?: SchemaLike<T> | BindOptions<T>): BindedVertex<T>;
246
+ moveTo(parent: Node): void;
247
+ /** Returns a live reactive object bound to this node. Accepts schema or options. */
248
+ bind<T extends Record<string, unknown>>(schemaOrOptions?: SchemaLike<T> | BindOptions<T>): BindedNode<T>;
245
249
  }
246
250
 
247
251
  /**
248
- * RepTree is a tree data structure for storing vertices with properties.
252
+ * RepTree is a tree data structure for storing nodes with properties.
249
253
  * It uses 2 conflict-free replicated data types (CRDTs) to manage seamless replication between peers.
250
254
  * A move tree CRDT is used for the tree structure (https://martin.kleppmann.com/papers/move-op.pdf).
251
255
  * A last writer wins (LWW) CRDT is used for properties.
252
256
  */
253
257
  declare class RepTree {
254
- private static NULL_VERTEX_ID;
258
+ private static NULL_NODE_ID;
255
259
  readonly peerId: string;
256
- private rootVertexId;
257
- private lamportClock;
260
+ private rootNodeId;
261
+ private moveClock;
262
+ private propClock;
258
263
  private state;
259
264
  private moveOps;
260
- private setPropertyOps;
261
- private propertiesAndTheirOpIds;
265
+ private propertyOpsByKey;
262
266
  private transientPropertiesAndTheirOpIds;
263
267
  private localOps;
264
268
  private pendingMovesWithMissingParent;
265
- private pendingPropertiesWithMissingVertex;
269
+ private pendingPropertiesWithMissingNode;
266
270
  private knownOps;
267
271
  private parentIdBeforeMove;
268
272
  private opAppliedCallbacks;
269
- private stateVector;
273
+ private moveStateVector;
274
+ private propStateVector;
270
275
  private _stateVectorEnabled;
271
276
  /**
272
277
  * @param peerId - The peer ID of the current client. Should be unique across all peers.
273
- * @param ops - The operations to replicate an existing tree, if not provided - an empty tree will be created without a root vertex
278
+ * @param ops - The operations to replicate an existing tree, if not provided - an empty tree will be created without a root node
274
279
  */
275
- constructor(peerId: string, ops?: ReadonlyArray<VertexOperation>);
276
- get root(): Vertex | undefined;
280
+ constructor(peerId: string, ops?: ReadonlyArray<NodeOperation>);
281
+ dispose(): void;
282
+ get root(): Node | undefined;
277
283
  replicate(newPeerId: string): RepTree;
278
- getMoveOps(): ReadonlyArray<MoveVertex>;
279
- getAllOps(): ReadonlyArray<VertexOperation>;
280
- getVertex(vertexId: string): Vertex | undefined;
281
- getAllVertices(): ReadonlyArray<Vertex>;
282
- getParent(vertexId: string): Vertex | undefined;
283
- getChildren(vertexId: string): Vertex[];
284
- getChildrenIds(vertexId: string): string[];
285
- /** Returns the ancestors of the given vertex. The first element is the root vertex. */
286
- getAncestors(vertexId: string): Vertex[];
287
- getVertexProperty(vertexId: string, key: string, includingTransient?: boolean): VertexPropertyType | undefined;
288
- getVertexProperties(vertexId: string): Readonly<TreeVertexProperty[]>;
284
+ getMoveOps(): ReadonlyArray<MoveNode>;
285
+ getAllOps(): ReadonlyArray<NodeOperation>;
286
+ getNode(nodeId: string): Node | undefined;
287
+ getAllNodes(): ReadonlyArray<Node>;
288
+ getParent(nodeId: string): Node | undefined;
289
+ getChildren(nodeId: string): Node[];
290
+ getChildrenIds(nodeId: string): string[];
291
+ /** Returns the ancestors of the given node. The first element is the root node. */
292
+ getAncestors(nodeId: string): Node[];
293
+ getNodeProperty(nodeId: string, key: string, includingTransient?: boolean): NodePropertyType | undefined;
294
+ getNodeProperties(nodeId: string): Readonly<TreeNodeProperty[]>;
289
295
  /**
290
296
  * Returns all local operations and clears the local operations list.
291
297
  * Can be used to get all operations that were generated from this peer and need to be sent to other peers.
292
298
  */
293
- popLocalOps(): VertexOperation[];
299
+ popLocalOps(): NodeOperation[];
294
300
  /**
295
- * This is the first vertex that will contain all other vertices.
301
+ * This is the first node that will contain all other nodes.
296
302
  * If you plan to replicate a tree then don't use this method and instead merge
297
- * in the ops from another tree (that will also contain the root vertex).
298
- * @returns The root vertex
303
+ * in the ops from another tree (that will also contain the root node).
304
+ * @returns The root node
299
305
  */
300
- createRoot(): Vertex;
301
- newVertex(parentId: string, props?: Record<string, VertexPropertyType> | object | null): Vertex;
302
- newNamedVertex(parentId: string, name: string, props?: Record<string, VertexPropertyType> | object | null): Vertex;
303
- moveVertex(vertexId: string, parentId: string): void;
304
- deleteVertex(vertexId: string): void;
305
- setTransientVertexProperty(vertexId: string, key: string, value: VertexPropertyType): void;
306
+ createRoot(): Node;
307
+ newNode(parentId: string, props?: Record<string, NodePropertyType> | object | null): Node;
308
+ newNamedNode(parentId: string, name: string, props?: Record<string, NodePropertyType> | object | null): Node;
309
+ moveNode(nodeId: string, parentId: string): void;
310
+ deleteNode(nodeId: string): void;
311
+ setTransientNodeProperty(nodeId: string, key: string, value: NodePropertyType): void;
306
312
  /**
307
313
  * Promotes all transient (temporary) properties to persistent properties.
308
- * @param vertexId - The ID of the vertex to commit transients for.
314
+ * @param nodeId - The ID of the node to commit transients for.
309
315
  * @returns
310
316
  */
311
- commitTransients(vertexId: string): void;
312
- setVertexProperty(vertexId: string, key: string, value: VertexPropertyType): void;
313
- setVertexProperties(vertexId: string, props: Record<string, VertexPropertyType> | object): void;
314
- getVertexByPath(path: string): Vertex | undefined;
315
- private getVertexByPathArray;
317
+ commitTransients(nodeId: string): void;
318
+ setNodeProperty(nodeId: string, key: string, value: NodePropertyType): void;
319
+ setNodeProperties(nodeId: string, props: Record<string, NodePropertyType> | object): void;
320
+ getNodeByPath(path: string): Node | undefined;
321
+ private getNodeByPathArray;
316
322
  printTree(): string;
317
- merge(ops: ReadonlyArray<VertexOperation>): void;
323
+ merge(ops: ReadonlyArray<NodeOperation>): void;
318
324
  private applyOps;
319
325
  /** Applies operations in an optimized way, sorting move ops by OpId to avoid undo-do-redo cycles */
320
326
  private applyOpsOptimizedForLotsOfMoves;
@@ -322,16 +328,17 @@ declare class RepTree {
322
328
  compareMoveOps(other: RepTree): boolean;
323
329
  /** Checks if the given `ancestorId` is an ancestor of `childId` in the tree */
324
330
  isAncestor(childId: string, ancestorId: string | null): boolean;
325
- observeVertex(vertexId: string, callback: (updatedVertex: Vertex) => void): () => void;
326
- observeVertexMove(callback: (movedVertex: Vertex, isNew: boolean) => void): () => void;
327
- observe(vertexId: string, callback: (events: VertexChangeEvent[]) => void): () => void;
328
- observeOpApplied(callback: (op: VertexOperation) => void): () => void;
329
- static compareVertices(vertexId: string, treeA: RepTree, treeB: RepTree): boolean;
330
- private newVertexInternal;
331
- private newVertexInternalWithUUID;
332
- private ensureNullVertex;
331
+ observeNode(nodeId: string, callback: (updatedNode: Node) => void): () => void;
332
+ observeNodeMove(callback: (movedNode: Node, isNew: boolean) => void): () => void;
333
+ observe(nodeId: string, callback: (events: NodeChangeEvent[]) => void): () => void;
334
+ observeOpApplied(callback: (op: NodeOperation) => void): () => void;
335
+ static compareNodes(nodeId: string, treeA: RepTree, treeB: RepTree): boolean;
336
+ private newNodeInternal;
337
+ private newNodeInternalWithUUID;
338
+ private ensureNullNode;
333
339
  /** Updates the lamport clock with the counter value of the operation */
334
- private updateLamportClock;
340
+ private updateMoveClock;
341
+ private updatePropClock;
335
342
  private applyPendingMovesForParent;
336
343
  private applyMove;
337
344
  private setLLWPropertyAndItsOpId;
@@ -339,22 +346,26 @@ declare class RepTree {
339
346
  private applyProperty;
340
347
  private applyLLWProperty;
341
348
  private applyOperation;
349
+ private markOpSeen;
342
350
  private reportOpAsApplied;
343
351
  private tryToMove;
344
352
  private undoMove;
345
353
  /**
346
- * Returns the current state vector.
347
- * Returns a readonly reference to the internal state vector.
354
+ * Returns the current state vectors for move and property streams.
355
+ * Returns readonly references to the internal state vectors.
348
356
  */
349
- getStateVector(): Readonly<Record<string, number[][]>> | null;
357
+ getStateVectors(): {
358
+ move: Readonly<StateVectors["move"]>;
359
+ prop: Readonly<StateVectors["prop"]>;
360
+ } | null;
350
361
  /**
351
362
  * Determines which operations are needed to synchronize
352
363
  * with the provided state vector.
353
364
  *
354
- * @param theirStateVector The state vector from another peer
355
- * @returns Operations that should be sent to the other peer, sorted by OpId.
365
+ * @param theirStateVectors The state vectors from another peer
366
+ * @returns Operations that should be sent to the other peer, sorted by OpId within each stream.
356
367
  */
357
- getMissingOps(theirStateVector: Record<string, number[][]>): VertexOperation[];
368
+ getMissingOps(theirStateVectors: StateVectors): NodeOperation[];
358
369
  /**
359
370
  * Gets or sets whether state vector tracking is enabled
360
371
  */
@@ -365,35 +376,41 @@ declare class RepTree {
365
376
  */
366
377
  set stateVectorEnabled(value: boolean);
367
378
  /**
368
- * Parses the vertex properties with a provided schema that has a `parse` method (e.g., Zod schema)
379
+ * Parses the node properties with a provided schema that has a `parse` method (e.g., Zod schema)
369
380
  */
370
- parseVertex<T>(vertexId: string, schema: {
381
+ parseNode<T>(nodeId: string, schema: {
371
382
  parse: (data: unknown) => T;
372
383
  }): T;
384
+ private getPropertyOps;
385
+ private refreshPropStateVector;
386
+ private getOpKey;
387
+ private filterOpsByRanges;
373
388
  }
374
389
 
375
390
  declare class TreeState {
376
- private vertices;
391
+ private static BATCH_DELAY_MS;
392
+ private nodes;
377
393
  private changeCallbacks;
378
394
  private globalChangeCallbacks;
379
- private batchTickInterval;
395
+ private batchTickTimeout;
380
396
  private batchedEvents;
381
397
  constructor();
382
398
  dispose(): void;
399
+ private scheduleBatchProcessing;
383
400
  private processBatchedEvents;
384
- getAllVertices(): ReadonlyArray<VertexState>;
385
- getVertex(id: string): VertexState | undefined;
386
- getChildrenIds(vertexId: TreeVertexId): string[];
387
- getChildren(vertexId: TreeVertexId): VertexState[];
388
- moveVertex(vertexId: TreeVertexId, newParentId: TreeVertexId | null): VertexState;
389
- setProperty(vertexId: string, key: string, value: VertexPropertyType): void;
390
- setTransientProperty(vertexId: string, key: string, value: VertexPropertyType): void;
391
- addChangeCallback(vertexId: TreeVertexId, listener: (events: VertexChangeEvent[]) => void): void;
392
- removeChangeCallback(vertexId: TreeVertexId, listener: (events: VertexChangeEvent[]) => void): void;
393
- addGlobalChangeCallback(listener: (events: VertexChangeEvent[]) => void): void;
394
- removeGlobalChangeCallback(listener: (events: VertexChangeEvent[]) => void): void;
401
+ getAllNodes(): ReadonlyArray<NodeState>;
402
+ getNode(id: string): NodeState | undefined;
403
+ getChildrenIds(nodeId: TreeNodeId): string[];
404
+ getChildren(nodeId: TreeNodeId): NodeState[];
405
+ moveNode(nodeId: TreeNodeId, newParentId: TreeNodeId | null): NodeState;
406
+ setProperty(nodeId: string, key: string, value: NodePropertyType): void;
407
+ setTransientProperty(nodeId: string, key: string, value: NodePropertyType): void;
408
+ addChangeCallback(nodeId: TreeNodeId, listener: (events: NodeChangeEvent[]) => void): void;
409
+ removeChangeCallback(nodeId: TreeNodeId, listener: (events: NodeChangeEvent[]) => void): void;
410
+ addGlobalChangeCallback(listener: (events: NodeChangeEvent[]) => void): void;
411
+ removeGlobalChangeCallback(listener: (events: NodeChangeEvent[]) => void): void;
395
412
  private notifyChange;
396
- printTree(vertexId: TreeVertexId, indent?: string, isLast?: boolean): string;
413
+ printTree(nodeId: TreeNodeId, indent?: string, isLast?: boolean): string;
397
414
  }
398
415
 
399
416
  /**
@@ -420,7 +437,7 @@ declare class StateVector {
420
437
  *
421
438
  * @param op The operation that was just applied
422
439
  */
423
- updateFromOp(op: VertexOperation): void;
440
+ updateFromOp(op: NodeOperation): void;
424
441
  /**
425
442
  * Returns the current state vector.
426
443
  * Returns a readonly reference to the internal state.
@@ -450,9 +467,9 @@ declare class StateVector {
450
467
  * @param operations The operations to build the state vector from
451
468
  * @returns A new StateVector instance
452
469
  */
453
- static fromOperations(operations: ReadonlyArray<VertexOperation>): StateVector;
470
+ static fromOperations(operations: ReadonlyArray<NodeOperation>): StateVector;
454
471
  }
455
472
 
456
473
  declare function uuid(): string;
457
474
 
458
- export { type BindOptions, type BindedVertex, type JsonPrimitive, type JsonValue, type MoveVertex, type OpId, type OpIdRange, RepTree, type SchemaLike, type SetVertexProperty, StateVector, TreeState, type TreeVertexId, type TreeVertexProperty, Vertex, type VertexChangeEvent, type VertexChildrenChangeEvent, type VertexMoveEvent, type VertexOperation, type VertexPropertyChangeEvent, type VertexPropertyType, VertexState, bindVertex, compareOpId, createOpId, equalsOpId, isAnyPropertyOp, isMoveVertexOp, isOpIdGreaterThan, newMoveVertexOp, newSetTransientVertexPropertyOp, newSetVertexPropertyOp, opIdToString, tryParseOpIdStr, uuid };
475
+ export { type BindOptions, type BindedNode, type JsonPrimitive, type JsonValue, type MoveNode, Node, type NodeChangeEvent, type NodeChildrenChangeEvent, type NodeMoveEvent, type NodeOperation, type NodePropertyChangeEvent, type NodePropertyType, NodeState, type OpId, type OpIdRange, RepTree, type SchemaLike, type SetNodeProperty, StateVector, type StateVectors, type TreeNodeId, type TreeNodeProperty, TreeState, bindNode, compareOpId, createOpId, equalsOpId, isAnyPropertyOp, isMoveNodeOp, isOpIdGreaterThan, newMoveNodeOp, newSetNodePropertyOp, newSetTransientNodePropertyOp, opIdToString, tryParseOpIdStr, uuid };