reptree 0.8.2 → 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,189 +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>;
245
- /**
246
- * Normalizes an input props object for vertex creation:
247
- * - Filters unsupported field types with a console warning
248
- * - When a name param is provided to newNamedChild, ignores conflicting name in props
249
- */
250
- private static normalizePropsForCreation;
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>;
251
249
  }
252
250
 
253
251
  /**
254
- * RepTree is a tree data structure for storing vertices with properties.
252
+ * RepTree is a tree data structure for storing nodes with properties.
255
253
  * It uses 2 conflict-free replicated data types (CRDTs) to manage seamless replication between peers.
256
254
  * A move tree CRDT is used for the tree structure (https://martin.kleppmann.com/papers/move-op.pdf).
257
255
  * A last writer wins (LWW) CRDT is used for properties.
258
256
  */
259
257
  declare class RepTree {
260
- private static NULL_VERTEX_ID;
258
+ private static NULL_NODE_ID;
261
259
  readonly peerId: string;
262
- private rootVertexId;
263
- private lamportClock;
260
+ private rootNodeId;
261
+ private moveClock;
262
+ private propClock;
264
263
  private state;
265
264
  private moveOps;
266
- private setPropertyOps;
267
- private propertiesAndTheirOpIds;
265
+ private propertyOpsByKey;
268
266
  private transientPropertiesAndTheirOpIds;
269
267
  private localOps;
270
268
  private pendingMovesWithMissingParent;
271
- private pendingPropertiesWithMissingVertex;
269
+ private pendingPropertiesWithMissingNode;
272
270
  private knownOps;
273
271
  private parentIdBeforeMove;
274
272
  private opAppliedCallbacks;
275
- private stateVector;
273
+ private moveStateVector;
274
+ private propStateVector;
276
275
  private _stateVectorEnabled;
277
276
  /**
278
277
  * @param peerId - The peer ID of the current client. Should be unique across all peers.
279
- * @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
280
279
  */
281
- constructor(peerId: string, ops?: ReadonlyArray<VertexOperation>);
282
- get root(): Vertex | undefined;
280
+ constructor(peerId: string, ops?: ReadonlyArray<NodeOperation>);
281
+ dispose(): void;
282
+ get root(): Node | undefined;
283
283
  replicate(newPeerId: string): RepTree;
284
- getMoveOps(): ReadonlyArray<MoveVertex>;
285
- getAllOps(): ReadonlyArray<VertexOperation>;
286
- getVertex(vertexId: string): Vertex | undefined;
287
- getAllVertices(): ReadonlyArray<Vertex>;
288
- getParent(vertexId: string): Vertex | undefined;
289
- getChildren(vertexId: string): Vertex[];
290
- getChildrenIds(vertexId: string): string[];
291
- /** Returns the ancestors of the given vertex. The first element is the root vertex. */
292
- getAncestors(vertexId: string): Vertex[];
293
- getVertexProperty(vertexId: string, key: string, includingTransient?: boolean): VertexPropertyType | undefined;
294
- 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[]>;
295
295
  /**
296
296
  * Returns all local operations and clears the local operations list.
297
297
  * Can be used to get all operations that were generated from this peer and need to be sent to other peers.
298
298
  */
299
- popLocalOps(): VertexOperation[];
299
+ popLocalOps(): NodeOperation[];
300
300
  /**
301
- * This is the first vertex that will contain all other vertices.
301
+ * This is the first node that will contain all other nodes.
302
302
  * If you plan to replicate a tree then don't use this method and instead merge
303
- * in the ops from another tree (that will also contain the root vertex).
304
- * @returns The root vertex
303
+ * in the ops from another tree (that will also contain the root node).
304
+ * @returns The root node
305
305
  */
306
- createRoot(): Vertex;
307
- newVertex(parentId: string, props?: Record<string, VertexPropertyType> | object | null): Vertex;
308
- newNamedVertex(parentId: string, name: string, props?: Record<string, VertexPropertyType> | object | null): Vertex;
309
- moveVertex(vertexId: string, parentId: string): void;
310
- deleteVertex(vertexId: string): void;
311
- 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;
312
312
  /**
313
313
  * Promotes all transient (temporary) properties to persistent properties.
314
- * @param vertexId - The ID of the vertex to commit transients for.
314
+ * @param nodeId - The ID of the node to commit transients for.
315
315
  * @returns
316
316
  */
317
- commitTransients(vertexId: string): void;
318
- setVertexProperty(vertexId: string, key: string, value: VertexPropertyType): void;
319
- setVertexProperties(vertexId: string, props: Record<string, VertexPropertyType> | object): void;
320
- getVertexByPath(path: string): Vertex | undefined;
321
- 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;
322
322
  printTree(): string;
323
- merge(ops: ReadonlyArray<VertexOperation>): void;
323
+ merge(ops: ReadonlyArray<NodeOperation>): void;
324
324
  private applyOps;
325
325
  /** Applies operations in an optimized way, sorting move ops by OpId to avoid undo-do-redo cycles */
326
326
  private applyOpsOptimizedForLotsOfMoves;
@@ -328,16 +328,17 @@ declare class RepTree {
328
328
  compareMoveOps(other: RepTree): boolean;
329
329
  /** Checks if the given `ancestorId` is an ancestor of `childId` in the tree */
330
330
  isAncestor(childId: string, ancestorId: string | null): boolean;
331
- observeVertex(vertexId: string, callback: (updatedVertex: Vertex) => void): () => void;
332
- observeVertexMove(callback: (movedVertex: Vertex, isNew: boolean) => void): () => void;
333
- observe(vertexId: string, callback: (events: VertexChangeEvent[]) => void): () => void;
334
- observeOpApplied(callback: (op: VertexOperation) => void): () => void;
335
- static compareVertices(vertexId: string, treeA: RepTree, treeB: RepTree): boolean;
336
- private newVertexInternal;
337
- private newVertexInternalWithUUID;
338
- 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;
339
339
  /** Updates the lamport clock with the counter value of the operation */
340
- private updateLamportClock;
340
+ private updateMoveClock;
341
+ private updatePropClock;
341
342
  private applyPendingMovesForParent;
342
343
  private applyMove;
343
344
  private setLLWPropertyAndItsOpId;
@@ -345,22 +346,26 @@ declare class RepTree {
345
346
  private applyProperty;
346
347
  private applyLLWProperty;
347
348
  private applyOperation;
349
+ private markOpSeen;
348
350
  private reportOpAsApplied;
349
351
  private tryToMove;
350
352
  private undoMove;
351
353
  /**
352
- * Returns the current state vector.
353
- * 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.
354
356
  */
355
- getStateVector(): Readonly<Record<string, number[][]>> | null;
357
+ getStateVectors(): {
358
+ move: Readonly<StateVectors["move"]>;
359
+ prop: Readonly<StateVectors["prop"]>;
360
+ } | null;
356
361
  /**
357
362
  * Determines which operations are needed to synchronize
358
363
  * with the provided state vector.
359
364
  *
360
- * @param theirStateVector The state vector from another peer
361
- * @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.
362
367
  */
363
- getMissingOps(theirStateVector: Record<string, number[][]>): VertexOperation[];
368
+ getMissingOps(theirStateVectors: StateVectors): NodeOperation[];
364
369
  /**
365
370
  * Gets or sets whether state vector tracking is enabled
366
371
  */
@@ -371,35 +376,41 @@ declare class RepTree {
371
376
  */
372
377
  set stateVectorEnabled(value: boolean);
373
378
  /**
374
- * 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)
375
380
  */
376
- parseVertex<T>(vertexId: string, schema: {
381
+ parseNode<T>(nodeId: string, schema: {
377
382
  parse: (data: unknown) => T;
378
383
  }): T;
384
+ private getPropertyOps;
385
+ private refreshPropStateVector;
386
+ private getOpKey;
387
+ private filterOpsByRanges;
379
388
  }
380
389
 
381
390
  declare class TreeState {
382
- private vertices;
391
+ private static BATCH_DELAY_MS;
392
+ private nodes;
383
393
  private changeCallbacks;
384
394
  private globalChangeCallbacks;
385
- private batchTickInterval;
395
+ private batchTickTimeout;
386
396
  private batchedEvents;
387
397
  constructor();
388
398
  dispose(): void;
399
+ private scheduleBatchProcessing;
389
400
  private processBatchedEvents;
390
- getAllVertices(): ReadonlyArray<VertexState>;
391
- getVertex(id: string): VertexState | undefined;
392
- getChildrenIds(vertexId: TreeVertexId): string[];
393
- getChildren(vertexId: TreeVertexId): VertexState[];
394
- moveVertex(vertexId: TreeVertexId, newParentId: TreeVertexId | null): VertexState;
395
- setProperty(vertexId: string, key: string, value: VertexPropertyType): void;
396
- setTransientProperty(vertexId: string, key: string, value: VertexPropertyType): void;
397
- addChangeCallback(vertexId: TreeVertexId, listener: (events: VertexChangeEvent[]) => void): void;
398
- removeChangeCallback(vertexId: TreeVertexId, listener: (events: VertexChangeEvent[]) => void): void;
399
- addGlobalChangeCallback(listener: (events: VertexChangeEvent[]) => void): void;
400
- 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;
401
412
  private notifyChange;
402
- printTree(vertexId: TreeVertexId, indent?: string, isLast?: boolean): string;
413
+ printTree(nodeId: TreeNodeId, indent?: string, isLast?: boolean): string;
403
414
  }
404
415
 
405
416
  /**
@@ -426,7 +437,7 @@ declare class StateVector {
426
437
  *
427
438
  * @param op The operation that was just applied
428
439
  */
429
- updateFromOp(op: VertexOperation): void;
440
+ updateFromOp(op: NodeOperation): void;
430
441
  /**
431
442
  * Returns the current state vector.
432
443
  * Returns a readonly reference to the internal state.
@@ -456,9 +467,9 @@ declare class StateVector {
456
467
  * @param operations The operations to build the state vector from
457
468
  * @returns A new StateVector instance
458
469
  */
459
- static fromOperations(operations: ReadonlyArray<VertexOperation>): StateVector;
470
+ static fromOperations(operations: ReadonlyArray<NodeOperation>): StateVector;
460
471
  }
461
472
 
462
473
  declare function uuid(): string;
463
474
 
464
- 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 };