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/README.md +8 -8
- package/dist/index.cjs +444 -404
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +190 -173
- package/dist/index.d.ts +190 -173
- package/dist/index.js +437 -397
- package/dist/index.js.map +1 -1
- package/package.json +1 -3
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
|
|
23
|
+
declare class NodeState {
|
|
24
24
|
readonly id: string;
|
|
25
|
-
parentId:
|
|
25
|
+
parentId: TreeNodeId | null;
|
|
26
26
|
private properties;
|
|
27
27
|
private transientProperties;
|
|
28
28
|
children: string[];
|
|
29
|
-
constructor(id: string, parentId:
|
|
30
|
-
setProperty(key: string, value:
|
|
31
|
-
setTransientProperty(key: string, value:
|
|
32
|
-
getProperty(key: string, includingTransient?: boolean):
|
|
33
|
-
getAllProperties(includingTransient?: boolean): ReadonlyArray<
|
|
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<
|
|
36
|
+
getTransientProperties(): ReadonlyArray<TreeNodeProperty>;
|
|
37
37
|
clearAllTransientProperties(): void;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
type
|
|
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
|
|
47
|
-
type
|
|
46
|
+
type NodePropertyType = JsonValue | undefined;
|
|
47
|
+
type TreeNodeProperty = {
|
|
48
48
|
readonly key: string;
|
|
49
|
-
readonly value:
|
|
49
|
+
readonly value: NodePropertyType;
|
|
50
50
|
};
|
|
51
|
-
type
|
|
52
|
-
interface
|
|
53
|
-
type:
|
|
54
|
-
|
|
51
|
+
type NodeChangeEventType = 'move' | 'property' | 'children';
|
|
52
|
+
interface NodeChangeEvent {
|
|
53
|
+
type: NodeChangeEventType;
|
|
54
|
+
nodeId: TreeNodeId;
|
|
55
55
|
}
|
|
56
|
-
type
|
|
56
|
+
type NodePropertyChangeEvent = NodeChangeEvent & {
|
|
57
57
|
type: 'property';
|
|
58
58
|
key: string;
|
|
59
|
-
value:
|
|
59
|
+
value: NodePropertyType | undefined;
|
|
60
60
|
};
|
|
61
|
-
type
|
|
61
|
+
type NodeMoveEvent = NodeChangeEvent & {
|
|
62
62
|
type: 'move';
|
|
63
|
-
oldParentId:
|
|
64
|
-
newParentId:
|
|
63
|
+
oldParentId: TreeNodeId | null | undefined;
|
|
64
|
+
newParentId: TreeNodeId;
|
|
65
65
|
};
|
|
66
|
-
type
|
|
66
|
+
type NodeChildrenChangeEvent = NodeChangeEvent & {
|
|
67
67
|
type: 'children';
|
|
68
|
-
children:
|
|
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
|
|
83
|
+
interface MoveNode {
|
|
80
84
|
id: OpId;
|
|
81
85
|
targetId: string;
|
|
82
86
|
parentId: string | null;
|
|
83
87
|
}
|
|
84
|
-
interface
|
|
88
|
+
interface SetNodeProperty {
|
|
85
89
|
id: OpId;
|
|
86
90
|
targetId: string;
|
|
87
91
|
key: string;
|
|
88
|
-
value:
|
|
92
|
+
value: NodePropertyType;
|
|
89
93
|
transient: boolean;
|
|
90
94
|
}
|
|
91
|
-
type
|
|
92
|
-
declare function
|
|
93
|
-
declare function isAnyPropertyOp(op:
|
|
94
|
-
declare function
|
|
95
|
-
declare function
|
|
96
|
-
declare function
|
|
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
|
|
122
|
-
* @param T - The type of the
|
|
125
|
+
* A bound node object that forwards reads/writes to a node.
|
|
126
|
+
* @param T - The type of the node.
|
|
123
127
|
*/
|
|
124
|
-
type
|
|
125
|
-
$
|
|
128
|
+
type BindedNode<T> = T & {
|
|
129
|
+
$node: Node;
|
|
126
130
|
$id: string;
|
|
127
131
|
$parentId: string | null;
|
|
128
|
-
$parent:
|
|
129
|
-
$children:
|
|
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
|
|
142
|
-
* @param parent - The new parent
|
|
145
|
+
* Move the node to a new parent.
|
|
146
|
+
* @param parent - The new parent node or ID.
|
|
143
147
|
*/
|
|
144
|
-
$moveTo(parent:
|
|
148
|
+
$moveTo(parent: Node | BindedNode<any> | string): void;
|
|
145
149
|
/**
|
|
146
|
-
* Delete the
|
|
150
|
+
* Delete the node.
|
|
147
151
|
*/
|
|
148
152
|
$delete(): void;
|
|
149
153
|
/**
|
|
150
|
-
* Observe changes to the
|
|
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
|
|
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:
|
|
162
|
+
$observeChildren(listener: (children: Node[]) => void): () => void;
|
|
159
163
|
/**
|
|
160
|
-
* Create a new child
|
|
161
|
-
* @param props - The properties to set on the new child
|
|
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):
|
|
167
|
+
$newChild(props?: Record<string, any> | object | null): Node;
|
|
164
168
|
/**
|
|
165
|
-
* Create a new named child
|
|
166
|
-
* @param name - The name of the new child
|
|
167
|
-
* @param props - The properties to set on the new child
|
|
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):
|
|
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
|
|
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
|
|
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
|
|
180
|
-
* for working with
|
|
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
|
|
186
|
+
declare class Node {
|
|
183
187
|
private state;
|
|
184
188
|
private _tree;
|
|
185
|
-
constructor(tree: RepTree, state:
|
|
186
|
-
/** Returns the tree this
|
|
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
|
|
193
|
+
/** Returns the ID of this node. */
|
|
190
194
|
get id(): string;
|
|
191
|
-
/** Returns the name of this
|
|
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
|
|
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
|
|
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
|
|
201
|
+
/** Returns the ID of the parent node of this node. */
|
|
198
202
|
get parentId(): string | null;
|
|
199
|
-
/** Returns the parent
|
|
200
|
-
get parent():
|
|
201
|
-
/** Returns the children
|
|
202
|
-
get children():
|
|
203
|
-
/** Returns the IDs of the children
|
|
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
|
|
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
|
|
211
|
+
* Doesn't include this node in the array.
|
|
208
212
|
*/
|
|
209
|
-
get ancestors():
|
|
210
|
-
/** Returns the ID of the root
|
|
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
|
|
213
|
-
get root():
|
|
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
|
|
217
|
-
newChild(props?: Record<string,
|
|
218
|
-
/** Creates a new named child
|
|
219
|
-
newNamedChild(name: string, props?: Record<string,
|
|
220
|
-
/** Sets a property on this
|
|
221
|
-
setProperty(key: string, value:
|
|
222
|
-
/** Sets a transient property on this
|
|
223
|
-
setTransientProperty(key: string, value:
|
|
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
|
|
227
|
-
setProperties(props: Record<string,
|
|
228
|
-
/** Returns the value of a property on this
|
|
229
|
-
getProperty(key: string, includingTransient?: boolean):
|
|
230
|
-
/** Returns all properties on this
|
|
231
|
-
getProperties(): Record<string,
|
|
232
|
-
findAllChildrenWithProperty(key: string, value:
|
|
233
|
-
|
|
234
|
-
findFirstTypedChildWithProperty<T>(key: string, value:
|
|
235
|
-
findAllTypedChildrenWithProperty<T>(key: string, value:
|
|
236
|
-
/** Observes changes to this
|
|
237
|
-
observe(listener: (events:
|
|
238
|
-
/** Observes changes to the children of this
|
|
239
|
-
observeChildren(listener: (children:
|
|
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:
|
|
243
|
-
/** Returns a live reactive object bound to this
|
|
244
|
-
bind<T extends Record<string, unknown>>(schemaOrOptions?: SchemaLike<T> | BindOptions<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
|
|
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
|
|
258
|
+
private static NULL_NODE_ID;
|
|
255
259
|
readonly peerId: string;
|
|
256
|
-
private
|
|
257
|
-
private
|
|
260
|
+
private rootNodeId;
|
|
261
|
+
private moveClock;
|
|
262
|
+
private propClock;
|
|
258
263
|
private state;
|
|
259
264
|
private moveOps;
|
|
260
|
-
private
|
|
261
|
-
private propertiesAndTheirOpIds;
|
|
265
|
+
private propertyOpsByKey;
|
|
262
266
|
private transientPropertiesAndTheirOpIds;
|
|
263
267
|
private localOps;
|
|
264
268
|
private pendingMovesWithMissingParent;
|
|
265
|
-
private
|
|
269
|
+
private pendingPropertiesWithMissingNode;
|
|
266
270
|
private knownOps;
|
|
267
271
|
private parentIdBeforeMove;
|
|
268
272
|
private opAppliedCallbacks;
|
|
269
|
-
private
|
|
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
|
|
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<
|
|
276
|
-
|
|
280
|
+
constructor(peerId: string, ops?: ReadonlyArray<NodeOperation>);
|
|
281
|
+
dispose(): void;
|
|
282
|
+
get root(): Node | undefined;
|
|
277
283
|
replicate(newPeerId: string): RepTree;
|
|
278
|
-
getMoveOps(): ReadonlyArray<
|
|
279
|
-
getAllOps(): ReadonlyArray<
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
getParent(
|
|
283
|
-
getChildren(
|
|
284
|
-
getChildrenIds(
|
|
285
|
-
/** Returns the ancestors of the given
|
|
286
|
-
getAncestors(
|
|
287
|
-
|
|
288
|
-
|
|
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():
|
|
299
|
+
popLocalOps(): NodeOperation[];
|
|
294
300
|
/**
|
|
295
|
-
* This is the first
|
|
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
|
|
298
|
-
* @returns The root
|
|
303
|
+
* in the ops from another tree (that will also contain the root node).
|
|
304
|
+
* @returns The root node
|
|
299
305
|
*/
|
|
300
|
-
createRoot():
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
|
314
|
+
* @param nodeId - The ID of the node to commit transients for.
|
|
309
315
|
* @returns
|
|
310
316
|
*/
|
|
311
|
-
commitTransients(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
private
|
|
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<
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
observe(
|
|
328
|
-
observeOpApplied(callback: (op:
|
|
329
|
-
static
|
|
330
|
-
private
|
|
331
|
-
private
|
|
332
|
-
private
|
|
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
|
|
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
|
|
347
|
-
* Returns
|
|
354
|
+
* Returns the current state vectors for move and property streams.
|
|
355
|
+
* Returns readonly references to the internal state vectors.
|
|
348
356
|
*/
|
|
349
|
-
|
|
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
|
|
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(
|
|
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
|
|
379
|
+
* Parses the node properties with a provided schema that has a `parse` method (e.g., Zod schema)
|
|
369
380
|
*/
|
|
370
|
-
|
|
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
|
|
391
|
+
private static BATCH_DELAY_MS;
|
|
392
|
+
private nodes;
|
|
377
393
|
private changeCallbacks;
|
|
378
394
|
private globalChangeCallbacks;
|
|
379
|
-
private
|
|
395
|
+
private batchTickTimeout;
|
|
380
396
|
private batchedEvents;
|
|
381
397
|
constructor();
|
|
382
398
|
dispose(): void;
|
|
399
|
+
private scheduleBatchProcessing;
|
|
383
400
|
private processBatchedEvents;
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
getChildrenIds(
|
|
387
|
-
getChildren(
|
|
388
|
-
|
|
389
|
-
setProperty(
|
|
390
|
-
setTransientProperty(
|
|
391
|
-
addChangeCallback(
|
|
392
|
-
removeChangeCallback(
|
|
393
|
-
addGlobalChangeCallback(listener: (events:
|
|
394
|
-
removeGlobalChangeCallback(listener: (events:
|
|
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(
|
|
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:
|
|
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<
|
|
470
|
+
static fromOperations(operations: ReadonlyArray<NodeOperation>): StateVector;
|
|
454
471
|
}
|
|
455
472
|
|
|
456
473
|
declare function uuid(): string;
|
|
457
474
|
|
|
458
|
-
export { type BindOptions, type
|
|
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 };
|