@fluid-experimental/tree 2.0.0-dev-rc.3.0.0.254513 → 2.0.0-dev-rc.3.0.0.254674

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.
@@ -1,3820 +0,0 @@
1
- /**
2
- * Fluid DDS storing a tree.
3
- *
4
- * @packageDocumentation
5
- */
6
-
7
- import { EventEmitterWithErrorHandling } from '@fluidframework/telemetry-utils/internal';
8
- import { IChannel } from '@fluidframework/datastore-definitions';
9
- import { IChannelAttributes } from '@fluidframework/datastore-definitions';
10
- import { IChannelFactory } from '@fluidframework/datastore-definitions';
11
- import { IChannelServices } from '@fluidframework/datastore-definitions';
12
- import { IChannelStorageService } from '@fluidframework/datastore-definitions';
13
- import { IDisposable } from '@fluidframework/core-interfaces';
14
- import { IErrorEvent } from '@fluidframework/core-interfaces';
15
- import { IEvent } from '@fluidframework/core-interfaces';
16
- import { IExperimentalIncrementalSummaryContext } from '@fluidframework/runtime-definitions';
17
- import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
18
- import { IFluidHandle } from '@fluidframework/core-interfaces';
19
- import { IFluidLoadable } from '@fluidframework/core-interfaces';
20
- import { IFluidSerializer } from '@fluidframework/shared-object-base';
21
- import { IGarbageCollectionData } from '@fluidframework/runtime-definitions';
22
- import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
23
- import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
24
- import { ITelemetryBaseEvent } from '@fluidframework/core-interfaces';
25
- import { ITelemetryBaseProperties } from '@fluidframework/core-interfaces';
26
- import { ITelemetryContext } from '@fluidframework/runtime-definitions';
27
- import { ITelemetryLoggerExt } from '@fluidframework/telemetry-utils';
28
- import { ITree } from '@fluidframework/tree';
29
- import { SharedObject } from '@fluidframework/shared-object-base/internal';
30
- import { TypedEventEmitter } from '@fluid-internal/client-utils';
31
-
32
- /**
33
- * Compare two views such that semantically equivalent node IDs are considered equal.
34
- * @internal
35
- */
36
- export declare function areRevisionViewsSemanticallyEqual(treeViewA: TreeView, idConverterA: NodeIdConverter, treeViewB: TreeView, idConverterB: NodeIdConverter): boolean;
37
-
38
- /**
39
- * An identifier associated with a session for the purpose of attributing its created content to some user/entity.
40
- * @alpha
41
- */
42
- export declare type AttributionId = UuidString;
43
-
44
- /**
45
- * The result of validating a bad place.
46
- * @alpha
47
- */
48
- export declare type BadPlaceValidationResult = Exclude<PlaceValidationResult, PlaceValidationResult.Valid>;
49
-
50
- /**
51
- * The result of validating a bad range.
52
- * @alpha
53
- */
54
- export declare type BadRangeValidationResult = Exclude<RangeValidationResult, RangeValidationResultKind.Valid>;
55
-
56
- /**
57
- * Constructs a sequence of nodes, associates it with the supplied ID, and stores it for use in later changes.
58
- * Does not modify the document.
59
- *
60
- * Valid if (transitively) all DetachedSequenceId are used according to their rules (use here counts as a destination),
61
- * and all Nodes' identifiers are previously unused.
62
- * @alpha
63
- */
64
- export declare interface Build {
65
- readonly destination: number;
66
- readonly source: BuildNode | TreeNodeSequence<BuildNode>;
67
- readonly type: typeof ChangeType.Build;
68
- }
69
-
70
- /**
71
- * {@inheritdoc Build}
72
- * @alpha
73
- */
74
- export declare interface BuildInternal extends Omit<BuildInternal_0_0_2, 'source'> {
75
- readonly source: TreeNodeSequence<BuildNodeInternal>;
76
- }
77
-
78
- /**
79
- * {@inheritdoc Build}
80
- * @alpha
81
- */
82
- export declare interface BuildInternal_0_0_2 {
83
- /** {@inheritdoc Build.destination } */
84
- readonly destination: DetachedSequenceId;
85
- /** {@inheritdoc Build.source } */
86
- readonly source: TreeNodeSequence<BuildNodeInternal_0_0_2>;
87
- /** {@inheritdoc Build."type" } */
88
- readonly type: typeof ChangeTypeInternal.Build;
89
- }
90
-
91
- /**
92
- * Node or a detached sequence of nodes (referred to by a detached sequence ID) for use in a Build change.
93
- * See `BuildTreeNode` for more.
94
- * @alpha
95
- */
96
- export declare type BuildNode = BuildTreeNode | number;
97
-
98
- /**
99
- * {@inheritdoc BuildNode}
100
- * @alpha
101
- */
102
- export declare type BuildNodeInternal = TreeNode<BuildNodeInternal, NodeId> | DetachedSequenceId;
103
-
104
- /**
105
- * {@inheritdoc BuildNode}
106
- * @alpha
107
- */
108
- export declare type BuildNodeInternal_0_0_2 = TreeNode<BuildNodeInternal_0_0_2, StableNodeId> | DetachedSequenceId;
109
-
110
- /**
111
- * Node for use in a Build change, which is composed of a definition describing what this nodes type, an identifier identifying this node
112
- * within the tree, and a payload containing an opaque serializable piece of data.
113
- * An identifier can be provided explicitly if the node must be referred to before the results of the `Change` containing this
114
- * BuildTreeNode can be observed. If `identifier` is not supplied, one will be generated for it in an especially efficient manner
115
- * that allows for compact storage and transmission and thus this property should be omitted if convenient.
116
- * See the SharedTree readme for more on the tree format.
117
- * @alpha
118
- */
119
- export declare interface BuildTreeNode extends HasVariadicTraits<BuildNode> {
120
- definition: string;
121
- identifier?: NodeId;
122
- payload?: Payload;
123
- }
124
-
125
- /**
126
- * A change that composes an Edit.
127
- *
128
- * @remarks
129
- *
130
- * `Change` objects can be conveniently constructed with the helper methods exported on a constant of the same name.
131
- *
132
- * @example
133
- *
134
- * ```typescript
135
- * Change.insert(sourceId, destination)
136
- * ```
137
- * @alpha
138
- */
139
- export declare type Change = Insert | Detach | Build | SetValue | Constraint;
140
-
141
- /**
142
- * @alpha
143
- */
144
- export declare const Change: {
145
- build: (source: BuildNode | TreeNodeSequence<BuildNode>, destination: number) => Build;
146
- insert: (source: number, destination: StablePlace) => Insert;
147
- detach: (source: StableRange, destination?: number) => Detach;
148
- setPayload: (nodeToModify: NodeId, payload: Payload) => SetValue;
149
- clearPayload: (nodeToModify: NodeId) => SetValue;
150
- constraint: (toConstrain: StableRange, effect: ConstraintEffect, identityHash?: UuidString, length?: number, contentHash?: UuidString, parentNode?: NodeId, label?: TraitLabel) => Constraint;
151
- /** Helpers for making high-level composite operations */
152
- /**
153
- * @returns a change that deletes the supplied part of the tree.
154
- */
155
- delete: (stableRange: StableRange) => Change;
156
- /**
157
- * @returns changes that insert 'nodes' into the specified location in the tree.
158
- */
159
- insertTree: (nodes: BuildNode | TreeNodeSequence<BuildNode>, destination: StablePlace) => Change[];
160
- /**
161
- * @returns changes that moves the specified content to a new location in the tree.
162
- */
163
- move: (source: StableRange, destination: StablePlace) => Change[];
164
- };
165
-
166
- /**
167
- * {@inheritdoc (Change:type)}
168
- * @alpha
169
- */
170
- export declare type ChangeInternal = InsertInternal | DetachInternal | BuildInternal | SetValueInternal | ConstraintInternal;
171
-
172
- /**
173
- * @alpha
174
- */
175
- export declare const ChangeInternal: {
176
- build: (source: TreeNodeSequence<BuildNodeInternal>, destination: DetachedSequenceId) => BuildInternal;
177
- insert: (source: DetachedSequenceId, destination: StablePlaceInternal) => InsertInternal;
178
- detach: (source: StableRangeInternal, destination?: DetachedSequenceId) => DetachInternal;
179
- setPayload: (nodeToModify: NodeData<NodeId> | NodeId, payload: Payload) => SetValueInternal;
180
- clearPayload: (nodeToModify: NodeData<NodeId> | NodeId) => SetValueInternal;
181
- constraint: (toConstrain: StableRangeInternal, effect: ConstraintEffect, identityHash?: UuidString, length?: number, contentHash?: UuidString, parentNode?: NodeId, label?: TraitLabel) => ConstraintInternal;
182
- /** {@inheritdoc (Change:variable).delete } */
183
- delete: (stableRange: StableRangeInternal) => ChangeInternal;
184
- /** {@inheritdoc (Change:variable).insertTree } */
185
- insertTree: (nodes: TreeNodeSequence<BuildNodeInternal>, destination: StablePlaceInternal) => ChangeInternal[];
186
- /** {@inheritdoc (Change:variable).move } */
187
- move: (source: StableRangeInternal, destination: StablePlaceInternal) => ChangeInternal[];
188
- };
189
-
190
- /**
191
- * JSON-compatible Node type. Objects of this type will be persisted in internal change objects (under Edits) in the SharedTree history.
192
- * @internal
193
- */
194
- export declare type ChangeNode = TreeNode<ChangeNode, NodeId>;
195
-
196
- /**
197
- * JSON-compatible Node type. Objects of this type will be persisted in internal change objects (under Edits) in the SharedTree history.
198
- * @alpha
199
- */
200
- export declare type ChangeNode_0_0_2 = TreeNode<ChangeNode_0_0_2, StableNodeId>;
201
-
202
- /**
203
- * The result of applying a change within a transaction.
204
- * @internal
205
- */
206
- export declare type ChangeResult = Result<TransactionView, TransactionFailure>;
207
-
208
- /**
209
- * The type of a Change
210
- * @alpha
211
- */
212
- export declare enum ChangeType {
213
- Insert = 0,
214
- Detach = 1,
215
- Build = 2,
216
- SetValue = 3,
217
- Constraint = 4
218
- }
219
-
220
- /**
221
- * {@inheritdoc ChangeType}
222
- * @alpha
223
- */
224
- export declare enum ChangeTypeInternal {
225
- Insert = 0,
226
- Detach = 1,
227
- Build = 2,
228
- SetValue = 3,
229
- Constraint = 4,
230
- CompressedBuild = 5
231
- }
232
-
233
- /**
234
- * A mutable Checkout of a SharedTree, allowing viewing and interactive transactional editing.
235
- * Provides {@link https://en.wikipedia.org/wiki/Snapshot_isolation | snapshot-isolation} while editing.
236
- *
237
- * A Checkout always shows a consistent sequence of versions of the SharedTree, but it may skip intermediate versions, and may fall behind.
238
- * In this case consistent means the sequence of versions could occur with fully synchronous shared tree access,
239
- * though the timing of sequenced edits arriving to the Checkout may be later than they actually arrive in the SharedTree.
240
- * Specifically no sequenced edits will arrive during an ongoing edit (to implement snapshot isolation):
241
- * they will be applied asynchronously some time after the ongoing edit is ended.
242
- *
243
- * Events emitted by `Checkout` are documented in {@link CheckoutEvent}.
244
- * Exceptions thrown during event handling will be emitted as error events, which are automatically surfaced as error events on the
245
- * `SharedTree` used at construction time.
246
- * @alpha
247
- */
248
- export declare abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEvents> implements IDisposable {
249
- /**
250
- * The view of the latest committed revision.
251
- * Does not include changes from any open edits.
252
- *
253
- * When this changes, emitChange must be called.
254
- */
255
- protected abstract get latestCommittedView(): RevisionView;
256
- /**
257
- * The last view for which invalidation was sent.
258
- * Updated by emitChange.
259
- */
260
- private previousView;
261
- /**
262
- * A handler for 'committedEdit' SharedTreeEvent
263
- */
264
- private readonly editCommittedHandler;
265
- /**
266
- * The shared tree this checkout views/edits.
267
- */
268
- readonly tree: SharedTree;
269
- /**
270
- * `tree`'s log viewer as a CachingLogViewer if it is one, otherwise undefined.
271
- * Used for optimizations if provided.
272
- */
273
- private readonly cachingLogViewer?;
274
- /**
275
- * Holds the state required to manage the currently open edit.
276
- * Undefined if there is currently not an open edit.
277
- *
278
- * Since `currentView` exposes the the intermediate state from this edit,
279
- * operations that modify `currentEdit.view` must call `emitChange` to handle invalidation.
280
- */
281
- private currentEdit?;
282
- private readonly logger;
283
- disposed: boolean;
284
- protected constructor(tree: SharedTree, currentView: RevisionView, onEditCommitted: EditCommittedHandler);
285
- /**
286
- * @returns the current view of the tree, including the result of changes applied so far during an edit.
287
- * Note that any external edits (from other clients) will not added to view while there is a `currentEdit`.
288
- */
289
- get currentView(): TreeView;
290
- /**
291
- * @returns true iff there is an open edit.
292
- */
293
- hasOpenEdit(): boolean;
294
- /**
295
- * Opens a new edit operation.
296
- * Changes accumulate in the edit via calls to `applyChanges()`.
297
- */
298
- openEdit(): void;
299
- /**
300
- * Ends the ongoing edit operation and commits it to the history.
301
- *
302
- * Malformed edits are considered an error, and will assert:
303
- * All named detached sequences must have been used or the Edit is malformed.
304
- *
305
- * @returns the `id` of the committed edit
306
- */
307
- closeEdit(): EditId;
308
- private validateChangesApplied;
309
- /**
310
- * Inform the Checkout that a particular edit is know to have a specific result when applied to a particular TreeView.
311
- * This may be used as a caching hint to avoid recomputation.
312
- */
313
- protected hintKnownEditingResult(edit: Edit<ChangeInternal>, result: ValidEditingResult): void;
314
- /**
315
- * Take any needed action between when an edit is completed.
316
- * Usually this will include submitting it to a SharedTree.
317
- *
318
- * Override this to customize.
319
- */
320
- protected handleNewEdit(id: EditId, result: ValidEditingResult): void;
321
- /**
322
- * Applies the supplied changes to the tree and emits a change event.
323
- * Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).
324
- * `changes` must be well-formed and valid: it is an error if they do not apply cleanly.
325
- */
326
- applyChanges(changes: readonly Change[]): void;
327
- applyChanges(...changes: readonly Change[]): void;
328
- /**
329
- * Applies the supplied changes to the tree and emits a change event.
330
- * Must be called during an ongoing edit (see `openEdit()`/`closeEdit()`).
331
- * `changes` must be well-formed and valid: it is an error if they do not apply cleanly.
332
- */
333
- protected tryApplyChangesInternal(changes: readonly ChangeInternal[]): EditStatus;
334
- protected tryApplyChangesInternal(...changes: readonly ChangeInternal[]): EditStatus;
335
- /**
336
- * Convenience helper for applying an edit containing the given changes.
337
- * Opens an edit, applies the given changes, and closes the edit. See (`openEdit()`/`applyChanges()`/`closeEdit()`).
338
- */
339
- applyEdit(changes: readonly Change[]): EditId;
340
- applyEdit(...changes: readonly Change[]): EditId;
341
- /**
342
- * Apply an edit, if valid, otherwise does nothing (the edit is not added to the history).
343
- * If the edit applied, its changes will be immediately visible on this checkout, though it still may end up invalid once sequenced due to concurrent edits.
344
- * @returns The EditId if the edit was valid and thus applied, and undefined if it was invalid and thus not applied.
345
- */
346
- tryApplyEdit(changes: readonly Change[]): EditId | undefined;
347
- tryApplyEdit(...changes: readonly Change[]): EditId | undefined;
348
- /**
349
- * Rebases the ongoing edit to the latest revision loaded by this 'Checkout'.
350
- *
351
- * If the rebase succeeds (none of the changes in the ongoing edit became invalid), the ongoing edit will remain open and the current
352
- * view will reflect those changes.
353
- *
354
- * If the rebase fails (changes become invalid), the ongoing edit will be aborted and
355
- * currentView will return to showing the newest committed revision as it always does when there is no ongoing edit.
356
- *
357
- * Must only be called during an open edit.
358
- *
359
- * @returns The result of the rebase.
360
- */
361
- rebaseCurrentEdit(): EditValidationResult.Valid | EditValidationResult.Invalid;
362
- /**
363
- * Ends the ongoing edit operation without committing it to the history.
364
- * Can only be called if an edit is open.
365
- */
366
- abortEdit(): void;
367
- /**
368
- * @returns the {@link EditStatus} of the current edit.
369
- * Has no side effects.
370
- * Can only be called if an edit is open.
371
- */
372
- getEditStatus(): EditStatus;
373
- /**
374
- * Reverts a collection of edits.
375
- * @param editIds - the edits to revert
376
- */
377
- revert(editId: EditId): void;
378
- /**
379
- * Send invalidation message for all changes since last call to emitChange.
380
- * This must be called every time `currentView` could have changed.
381
- * It is ok to make excessive calls to this: change notifications will be cheaply de-duplicated.
382
- */
383
- protected emitChange(): void;
384
- /**
385
- * @returns a Promise which completes after all currently known edits are available in this checkout.
386
- */
387
- abstract waitForPendingUpdates(): Promise<void>;
388
- /**
389
- * @returns a Promise which completes after edits that were closed on this checkout (before calling this) have been
390
- * submitted to Fluid. This does NOT wait for the Fluid service to ack them
391
- */
392
- abstract waitForEditsToSubmit(): Promise<void>;
393
- /**
394
- * release all unmanaged resources
395
- * e.g. unregister event listeners
396
- */
397
- dispose(error?: Error): void;
398
- }
399
-
400
- /**
401
- * An event emitted by a `Checkout` to indicate a state change. See {@link ICheckoutEvents} for event argument information.
402
- * @alpha
403
- */
404
- export declare enum CheckoutEvent {
405
- /**
406
- * `currentView` has changed.
407
- * Passed a before and after TreeView.
408
- */
409
- ViewChange = "viewChange"
410
- }
411
-
412
- /**
413
- * @returns true if two `Payloads` are identical.
414
- * May return false for equivalent payloads encoded differently.
415
- *
416
- * Object field order and object identity are not considered significant, and are ignored by this function.
417
- * (This is because they may not be preserved through roundtrip).
418
- *
419
- * For other information which Fluid would lose on serialization round trip,
420
- * behavior is unspecified other than this this function is reflective (all payloads are equal to themselves)
421
- * and commutative (argument order does not matter).
422
- *
423
- * This means that any Payload is equal to itself and a deep clone of itself.
424
- *
425
- * Payloads might not be equal to a version of themselves that has been serialized then deserialized.
426
- * If they are serialized then deserialized again, the two deserialized objects will compare equal,
427
- * however the serialized strings may be unequal (due to field order for objects being unspecified).
428
- *
429
- * Fluid will cause lossy operations due to use of JSON.stringify().
430
- * This includes:
431
- * - Loss of object identity
432
- * - Loss of field order (may be ordered arbitrarily)
433
- * - -0 becomes +0
434
- * - NaN, Infinity, -Infinity all become null
435
- * - custom toJSON functions may cause arbitrary behavior
436
- * - functions become undefined or null
437
- * - non enumerable properties (including prototype) are lost
438
- * - more (this is not a complete list)
439
- *
440
- * Inputs must not contain cyclic references other than fields set to their immediate parent (for the JavaScript feature detection pattern).
441
- *
442
- * IFluidHandle instances (detected via JavaScript feature detection pattern) are only compared by absolutePath.
443
- *
444
- * TODO:#54095: Is there a better way to do this comparison?
445
- * @alpha
446
- */
447
- export declare function comparePayloads(a: Payload, b: Payload): boolean;
448
-
449
- /**
450
- * An identifier (UUID) that has been shortened by a distributed compression algorithm.
451
- * @alpha
452
- */
453
- export declare type CompressedId = FinalCompressedId | LocalCompressedId;
454
-
455
- /**
456
- * A set of constraints on the validity of an Edit.
457
- * A Constraint is used to detect when an Edit, due to other concurrent edits, may have unintended effects or merge in
458
- * non-semantic ways. It is processed in order like any other Change in an Edit. It can cause an edit to fail if the
459
- * various constraints are not met at the time of evaluation (ex: the parentNode has changed due to concurrent editing).
460
- * Does not modify the document.
461
- * @alpha
462
- */
463
- export declare interface Constraint {
464
- /**
465
- * Selects a sequence of nodes which will be checked against the constraints specified by the optional fields.
466
- * If `toConstrain` is invalid, it will be treated like a constraint being unmet.
467
- * Depending on `effect` this may or may not make the Edit invalid.
468
- *
469
- * When a constraint is not met, the effects is specified by `effect`.
470
- */
471
- readonly toConstrain: StableRange;
472
- /**
473
- * Require that the identities of all the nodes in toConstrain hash to this value.
474
- * Hash is order dependent.
475
- * TODO: implement and specify exact hash function.
476
- *
477
- * This is an efficient (O(1) space) way to constrain a sequence of nodes to have specific identities.
478
- */
479
- readonly identityHash?: UuidString;
480
- /**
481
- * Require that the number of nodes in toConstrain is this value.
482
- */
483
- readonly length?: number;
484
- /**
485
- * Require that the contents of all of the nodes in toConstrain hash to this value.
486
- * Hash is an order dependant deep hash, which includes all subtree content recursively.
487
- * TODO: implement and specify exact hash function.
488
- *
489
- * This is an efficient (O(1) space) way to constrain a sequence of nodes have exact values (transitively).
490
- */
491
- readonly contentHash?: UuidString;
492
- /**
493
- * Require that parent under which toConstrain is located has this identifier.
494
- */
495
- readonly parentNode?: NodeId;
496
- /**
497
- * Require that the trait under which toConstrain is located has this label.
498
- */
499
- readonly label?: TraitLabel;
500
- /**
501
- * What to do if a constraint is not met.
502
- */
503
- readonly effect: ConstraintEffect;
504
- /**
505
- * Marker for which kind of Change this is.
506
- */
507
- readonly type: typeof ChangeType.Constraint;
508
- }
509
-
510
- /**
511
- * What to do when a Constraint is violated.
512
- * @alpha
513
- */
514
- export declare enum ConstraintEffect {
515
- /**
516
- * Discard Edit.
517
- */
518
- InvalidAndDiscard = 0,
519
- /**
520
- * Discard Edit, but record metadata that application may want to try and recover this change by recreating it.
521
- * Should this be the default policy for when another (non Constraint) change is invalid?
522
- */
523
- InvalidRetry = 1,
524
- /**
525
- * Apply the change, but flag it for possible reconsideration by the app
526
- * (applying it is better than not, but perhaps the high level logic could produce something better).
527
- */
528
- ValidRetry = 2
529
- }
530
-
531
- /**
532
- * {@inheritdoc Constraint}
533
- * @alpha
534
- */
535
- export declare interface ConstraintInternal extends Omit<ConstraintInternal_0_0_2, 'toConstrain' | 'parentNode'> {
536
- /** {@inheritdoc Constraint.toConstrain } */
537
- readonly toConstrain: StableRangeInternal;
538
- /** {@inheritdoc Constraint.parentNode } */
539
- readonly parentNode?: NodeId;
540
- }
541
-
542
- /**
543
- * {@inheritdoc Constraint}
544
- * @alpha
545
- */
546
- export declare interface ConstraintInternal_0_0_2 {
547
- /** {@inheritdoc Constraint.toConstrain } */
548
- readonly toConstrain: StableRangeInternal_0_0_2;
549
- /** {@inheritdoc Constraint.identityHash } */
550
- readonly identityHash?: UuidString;
551
- /** {@inheritdoc Constraint.length } */
552
- readonly length?: number;
553
- /** {@inheritdoc Constraint.contentHash } */
554
- readonly contentHash?: UuidString;
555
- /** {@inheritdoc Constraint.parentNode } */
556
- readonly parentNode?: StableNodeId;
557
- /** {@inheritdoc Constraint.label } */
558
- readonly label?: TraitLabel;
559
- /** {@inheritdoc Constraint.effect } */
560
- readonly effect: ConstraintEffect;
561
- /** {@inheritdoc Constraint."type" } */
562
- readonly type: typeof ChangeTypeInternal.Constraint;
563
- }
564
-
565
- /**
566
- * Definition.
567
- * A full (Uuid) persistable definition.
568
- * @alpha
569
- */
570
- export declare type Definition = UuidString & {
571
- readonly Definition: 'c0ef9488-2a78-482d-aeed-37fba996354c';
572
- };
573
-
574
- /**
575
- * Differences from one forest to another.
576
- * @alpha
577
- */
578
- export declare interface Delta<NodeId> {
579
- /**
580
- * Nodes whose content changed.
581
- */
582
- readonly changed: readonly NodeId[];
583
- /**
584
- * Nodes that were added.
585
- */
586
- readonly added: readonly NodeId[];
587
- /**
588
- * Nodes that were removed.
589
- */
590
- readonly removed: readonly NodeId[];
591
- }
592
-
593
- /**
594
- * Removes a sequence of nodes from the tree.
595
- * If a destination is specified, the detached sequence is associated with that ID and held for possible reuse
596
- * by later changes in this same Edit (such as by an Insert).
597
- * A Detach without a destination is a deletion of the specified sequence, as is a Detach with a destination that is not used later.
598
- * @alpha
599
- */
600
- export declare interface Detach {
601
- readonly destination?: number;
602
- readonly source: StableRange;
603
- readonly type: typeof ChangeType.Detach;
604
- }
605
-
606
- /**
607
- * Scoped to a single edit: identifies a sequences of nodes that can be moved into a trait.
608
- *
609
- * Within a given Edit, any DetachedSequenceId must be a source at most once, and a destination at most once.
610
- * If used as a source, it must be after it is used as a destination.
611
- * If this is violated, the Edit is considered malformed.
612
- * @alpha
613
- */
614
- export declare type DetachedSequenceId = number & {
615
- readonly DetachedSequenceId: 'f7d7903a-194e-45e7-8e82-c9ef4333577d';
616
- };
617
-
618
- /**
619
- * {@inheritdoc Detach}
620
- * @alpha
621
- */
622
- export declare interface DetachInternal extends Omit<DetachInternal_0_0_2, 'source'> {
623
- /** {@inheritdoc Detach.source } */
624
- readonly source: StableRangeInternal;
625
- }
626
-
627
- /**
628
- * {@inheritdoc Detach}
629
- * @alpha
630
- */
631
- export declare interface DetachInternal_0_0_2 {
632
- /** {@inheritdoc Detach.destination } */
633
- readonly destination?: DetachedSequenceId;
634
- /** {@inheritdoc Detach.source } */
635
- readonly source: StableRangeInternal_0_0_2;
636
- /** {@inheritdoc Detach."type" } */
637
- readonly type: typeof ChangeTypeInternal.Detach;
638
- }
639
-
640
- /**
641
- * Checkout that always stays up to date with the SharedTree.
642
- * This means that {@link EagerCheckout.waitForPendingUpdates} is always a no-op since EagerCheckout is always up to date.
643
- * @sealed
644
- * @alpha
645
- */
646
- export declare class EagerCheckout extends Checkout {
647
- /**
648
- * @param tree - the tree
649
- */
650
- constructor(tree: SharedTree);
651
- protected get latestCommittedView(): RevisionView;
652
- waitForPendingUpdates(): Promise<void>;
653
- waitForEditsToSubmit(): Promise<void>;
654
- }
655
-
656
- /**
657
- * A collection of changes to the tree that are applied atomically along with a unique identifier for the edit.
658
- * If any individual change fails to apply, the entire Edit will fail to apply.
659
- * @alpha
660
- */
661
- export declare interface Edit<TChange> extends EditBase<TChange> {
662
- /**
663
- * Unique identifier for this edit. Must never be reused.
664
- * Used for referencing and de-duplicating edits.
665
- */
666
- readonly id: EditId;
667
- }
668
-
669
- /**
670
- * The outcome of an edit.
671
- * @alpha
672
- */
673
- export declare type EditApplicationOutcome = {
674
- /**
675
- * The revision view resulting from the edit.
676
- */
677
- readonly view: RevisionView;
678
- /**
679
- * The status code for the edit that produced the revision.
680
- */
681
- readonly status: EditStatus.Applied;
682
- } | {
683
- /**
684
- * The revision view resulting from the edit.
685
- */
686
- readonly failure: TransactionInternal.Failure;
687
- /**
688
- * The status code for the edit that produced the revision.
689
- */
690
- readonly status: EditStatus.Invalid | EditStatus.Malformed;
691
- };
692
-
693
- /**
694
- * The information included in an edit.
695
- * @alpha
696
- */
697
- export declare interface EditBase<TChange> {
698
- /**
699
- * Actual changes to apply.
700
- * Applied in order as part of a single transaction.
701
- */
702
- readonly changes: readonly TChange[];
703
- /**
704
- * For edits which are being re-issued due to a conflict, the number of times this edit has already been attempted.
705
- * Undefined means 0.
706
- */
707
- readonly pastAttemptCount?: number;
708
- }
709
-
710
- /**
711
- * The arguments included when the EditCommitted SharedTreeEvent is emitted.
712
- * @alpha
713
- */
714
- export declare interface EditCommittedEventArguments {
715
- /** The ID of the edit committed. */
716
- readonly editId: EditId;
717
- /** Whether or not this is a local edit. */
718
- readonly local: boolean;
719
- /** The tree the edit was committed on. Required for local edit events handled by SharedTreeUndoRedoHandler. */
720
- readonly tree: SharedTree;
721
- }
722
-
723
- /**
724
- * Expected type for a handler of the `EditCommitted` event.
725
- * @alpha
726
- */
727
- export declare type EditCommittedHandler = (args: EditCommittedEventArguments) => void;
728
-
729
- /**
730
- * EditHandles are used to load edit chunks stored outside of the EditLog.
731
- * This is typically implemented by a wrapper around an IFluidHandle<ArrayBufferLike>.
732
- * @deprecated Edit virtualization is no longer supported.
733
- * @internal
734
- */
735
- export declare interface EditHandle<TChange> {
736
- readonly get: () => Promise<EditWithoutId<TChange>[]>;
737
- readonly baseHandle: FluidEditHandle;
738
- }
739
-
740
- /**
741
- * Edit identifier
742
- * @alpha
743
- */
744
- export declare type EditId = UuidString & {
745
- readonly EditId: '56897beb-53e4-4e66-85da-4bf5cd5d0d49';
746
- };
747
-
748
- /**
749
- * Result of applying a transaction.
750
- * @internal
751
- */
752
- export declare type EditingResult = FailedEditingResult | ValidEditingResult;
753
-
754
- /**
755
- * Basic result of applying a transaction.
756
- * @alpha
757
- */
758
- export declare interface EditingResultBase {
759
- /**
760
- * The final status of the transaction.
761
- */
762
- readonly status: EditStatus;
763
- /**
764
- * The valid changes applied as part of the transaction.
765
- */
766
- readonly changes: readonly ChangeInternal[];
767
- /**
768
- * The editing steps applied as part of the transaction.
769
- */
770
- readonly steps: readonly ReconciliationChange[];
771
- /**
772
- * The revision preceding the transaction.
773
- */
774
- readonly before: RevisionView;
775
- }
776
-
777
- /**
778
- * Information used to populate an edit log.
779
- * In 0.1.1, this is a persisted type only for `EditLogSummary<CompressedChangeInternal, FluidEditHandle>`,
780
- * where calling `FluidEditHandle.get` returns an array buffer of compressed `editChunk` contents.
781
- * The type is parameterized to avoid nearly identical type definitions for uncompressed forms of the edit
782
- * log, and abstracting away the fact that handle fetching needs to invoke decompression.
783
- * @internal
784
- */
785
- export declare interface EditLogSummary<TChange, THandle> {
786
- /**
787
- * A of list of serialized chunks and their corresponding keys.
788
- * Start revision is the index of the first edit in the chunk in relation to the edit log.
789
- */
790
- readonly editChunks: readonly {
791
- readonly startRevision: number;
792
- /**
793
- * Either a chunk of edits or a handle that can be used to load that chunk.
794
- */
795
- readonly chunk: THandle | readonly EditWithoutId<TChange>[];
796
- }[];
797
- /**
798
- * A list of edits IDs for all sequenced edits.
799
- */
800
- readonly editIds: readonly EditId[];
801
- }
802
-
803
- /**
804
- * The status code of an attempt to apply the changes in an Edit.
805
- * @alpha
806
- */
807
- export declare enum EditStatus {
808
- /**
809
- * The edit contained one or more malformed changes (e.g. was missing required fields such as `id`),
810
- * or contained a sequence of changes that could not possibly be applied sequentially without error
811
- * (e.g. an edit which tries to insert the same detached node twice).
812
- */
813
- Malformed = 0,
814
- /**
815
- * The edit contained a well-formed sequence of changes that couldn't be applied to the current view,
816
- * generally because concurrent changes caused one or more merge conflicts.
817
- */
818
- Invalid = 1,
819
- /**
820
- * The edit was applied to the current view successfully.
821
- */
822
- Applied = 2
823
- }
824
-
825
- /**
826
- * The result of validation of an Edit.
827
- * @alpha
828
- */
829
- export declare enum EditValidationResult {
830
- /**
831
- * The edit contained one or more malformed changes (e.g. was missing required fields such as `id`),
832
- * or contained a sequence of changes that could not possibly be applied sequentially without error
833
- * (e.g. an edit which tries to insert the same detached node twice).
834
- */
835
- Malformed = 0,
836
- /**
837
- * The edit is well-formed but cannot be applied to the current view, generally because concurrent changes
838
- * caused one or more merge conflicts.
839
- * For example, the edit refers to the `StablePlace` after node `C`, but `C` has since been deleted.
840
- */
841
- Invalid = 1,
842
- /**
843
- * The edit is well-formed and can be applied to the current view.
844
- */
845
- Valid = 2
846
- }
847
-
848
- /**
849
- * A collection of changes to the tree that are applied atomically. If any individual change fails to apply,
850
- * the entire Edit will fail to apply.
851
- * @internal
852
- */
853
- export declare interface EditWithoutId<TChange> extends EditBase<TChange> {
854
- /**
855
- * Used to explicitly state that EditWithoutId cannot contain an id and prevents type Edit from being assigned to type EditWithoutId.
856
- */
857
- readonly id?: never;
858
- }
859
-
860
- /**
861
- * Result of applying an invalid or malformed transaction.
862
- * @internal
863
- */
864
- export declare interface FailedEditingResult extends EditingResultBase {
865
- /**
866
- * {@inheritDoc EditingResultBase.status}
867
- */
868
- readonly status: EditStatus.Invalid | EditStatus.Malformed;
869
- /**
870
- * Information about what caused the transaction to fail.
871
- */
872
- readonly failure: TransactionInternal.Failure;
873
- /**
874
- * The valid changes applied as part of the transaction.
875
- * Those were ultimately abandoned due to the transaction failure.
876
- */
877
- readonly changes: readonly ChangeInternal[];
878
- /**
879
- * The editing steps applied as part of the transaction.
880
- * Those were ultimately abandoned due to the transaction failure.
881
- */
882
- readonly steps: readonly ReconciliationChange[];
883
- }
884
-
885
- /**
886
- * The state of a transaction that has encountered an error.
887
- * @internal
888
- */
889
- export declare interface FailingTransactionState extends TransactionFailure {
890
- /**
891
- * The view reflecting the latest applied change.
892
- */
893
- readonly view: TransactionView;
894
- /**
895
- * The applied changes so far.
896
- */
897
- readonly changes: readonly ChangeInternal[];
898
- /**
899
- * The editing steps applied so far.
900
- */
901
- readonly steps: readonly ReconciliationChange[];
902
- }
903
-
904
- /**
905
- * A compressed ID that is local to a document. Stable across all revisions of a document starting from the one in which it was created.
906
- * It should not be persisted outside of the history as it can only be decompressed in the context of the originating document.
907
- * If external persistence is needed (e.g. by a client), a StableId should be used instead.
908
- * @alpha
909
- */
910
- export declare type FinalCompressedId = number & {
911
- readonly FinalCompressedId: '5d83d1e2-98b7-4e4e-a889-54c855cfa73d';
912
- readonly OpNormalized: '9209432d-a959-4df7-b2ad-767ead4dbcae';
913
- };
914
-
915
- /**
916
- * FluidEditHandles are used to load edit chunks stored outside of the EditLog.
917
- * Can be satisfied by IFluidHandle<ArrayBufferLike>.
918
- * Note that though this is in `PersistedTypes`, it isn't directly serializable (e.g. `get` is a function).
919
- * Its serialization relies on being encoded via an IFluidSerializer.
920
- * @internal
921
- */
922
- export declare interface FluidEditHandle {
923
- readonly get: () => Promise<ArrayBuffer>;
924
- readonly absolutePath: string;
925
- }
926
-
927
- /**
928
- * An immutable forest of ForestNode.
929
- * Enforces single parenting, and allows querying the parent.
930
- * @alpha
931
- */
932
- export declare class Forest {
933
- /**
934
- * Contains the nodes in the forest.
935
- * Used as an immutable data-structure: must not be modified.
936
- */
937
- private readonly nodes;
938
- /**
939
- * If true, consistency checks will be applied after forest operations.
940
- */
941
- private readonly expensiveValidation;
942
- /**
943
- * Caller must ensure provided BTrees are not modified.
944
- * Will not modify the BTrees.
945
- */
946
- private constructor();
947
- /**
948
- * Construct a new forest without reusing nodes from a previous one.
949
- */
950
- private constructor();
951
- /**
952
- * Creates a new Forest.
953
- */
954
- static create(expensiveValidation?: boolean): Forest;
955
- /**
956
- * Returns the number of nodes in the forest.
957
- */
958
- get size(): number;
959
- /**
960
- * Adds the supplied nodes to the forest. The nodes' IDs must be unique in the forest.
961
- * @param nodes - the sequence of nodes to add to the forest. If any of them have children which exist in the forest already, those
962
- * children will be parented. Any trait arrays present in a node must be non-empty. The nodes may be provided in any order.
963
- */
964
- add(nodes: Iterable<ForestNode>): Forest;
965
- /**
966
- * Parents a set of nodes already in the forest at a specified location within a trait.
967
- * @param parentId - the id of the parent under which to insert the new nodes
968
- * @param label - the label of the trait under which to insert the new nodes
969
- * @param index - the index in the trait after which to insert the new nodes
970
- * @param childIds - the ids of the nodes to insert
971
- */
972
- attachRangeOfChildren(parentId: NodeId, label: TraitLabel, index: number, childIds: readonly NodeId[]): Forest;
973
- /**
974
- * Detaches a range of nodes from their parent. The detached nodes remain in the `Forest`.
975
- * @param parentId - the id of the parent from which to detach the nodes
976
- * @param label - the label of the trait from which to detach the nodes
977
- * @param startIndex - the index of the first node in the range to detach
978
- * @param endIndex - the index after the last node in the range to detach
979
- * @returns a new `Forest` with the nodes detached, and a list of the ids of the nodes that were detached
980
- */
981
- detachRangeOfChildren(parentId: NodeId, label: TraitLabel, startIndex: number, endIndex: number): {
982
- forest: Forest;
983
- detached: readonly NodeId[];
984
- };
985
- /**
986
- * Replaces a node's value. The node must exist in this `Forest`.
987
- * @param nodeId - the id of the node
988
- * @param value - the new value
989
- */
990
- setValue(nodeId: NodeId, value: Payload | null): Forest;
991
- /**
992
- * @returns true if the node associated with `id` exists in this forest, otherwise false
993
- */
994
- has(id: NodeId): boolean;
995
- /**
996
- * @returns the node associated with `id`. Should not be used if there is no node with the provided id.
997
- */
998
- get(id: NodeId): ForestNode;
999
- /**
1000
- * @returns the node associated with `id`, or undefined if there is none
1001
- */
1002
- tryGet(id: NodeId): ForestNode | undefined;
1003
- /**
1004
- * Deletes every node in ids (each of which must be unparented)
1005
- * @param ids - The IDs of the nodes to delete.
1006
- * @param deleteChildren - If true, recursively deletes descendants. Otherwise, leaves children unparented.
1007
- */
1008
- delete(ids: Iterable<NodeId>, deleteChildren: boolean): Forest;
1009
- private deleteRecursive;
1010
- /**
1011
- * Checks that the metadata is correct, and the items form a forest.
1012
- * This is an expensive O(map size) operation.
1013
- */
1014
- assertConsistent(): void;
1015
- /**
1016
- * @returns the parent of `id`. Should not be used if there is no node with id or if id refers to the root node.
1017
- */
1018
- getParent(id: NodeId): ParentData;
1019
- /**
1020
- * @returns undefined iff root, otherwise the parent of `id`.
1021
- */
1022
- tryGetParent(id: NodeId): ParentData | undefined;
1023
- /**
1024
- * Compares two forests for equality.
1025
- * @param forest - the other forest to compare to this one
1026
- * @param comparator - a function which returns true if two objects of type ForestNode are equivalent, false otherwise
1027
- * @returns true iff the forests are equal.
1028
- */
1029
- equals(forest: Forest): boolean;
1030
- /**
1031
- * Calculate the difference between two forests.
1032
- * @param forest - the other forest to compare to this one
1033
- * @param comparator - a function which returns true if two objects of type ForestNode are equivalent, false otherwise
1034
- * @returns A {@link Delta} listing which nodes must be changed, added, and removed to get from `this` to `forest`.
1035
- */
1036
- delta(forest: Forest): Delta<NodeId>;
1037
- }
1038
-
1039
- /**
1040
- * A node that can be contained within a Forest
1041
- * @alpha
1042
- */
1043
- export declare interface ForestNode extends NodeData<NodeId> {
1044
- readonly traits: ReadonlyMap<TraitLabel, readonly NodeId[]>;
1045
- }
1046
-
1047
- /**
1048
- * A mutable transaction for applying sequences of changes to a TreeView.
1049
- * Allows viewing the intermediate states.
1050
- *
1051
- * Contains necessary state to apply changes within an edit to a TreeView.
1052
- *
1053
- * May have any number of changes applied to make up the edit.
1054
- * Use `close` to complete the transaction, returning the array of changes and an EditingResult showing the
1055
- * results of applying the changes as an Edit to the initial TreeView (passed to the constructor).
1056
- *
1057
- * No data outside the Transaction is modified by Transaction:
1058
- * the results from `close` must be used to actually submit an `Edit`.
1059
- * @internal
1060
- */
1061
- export declare class GenericTransaction {
1062
- private readonly policy;
1063
- protected readonly before: RevisionView;
1064
- private state;
1065
- private open;
1066
- /**
1067
- * Create and open an edit of the provided `TreeView`. After applying 0 or more changes, this editor should be closed via `close()`.
1068
- * @param view - the `TreeView` at which this edit begins. The first change will be applied against this view.
1069
- */
1070
- constructor(view: RevisionView, policy: GenericTransactionPolicy);
1071
- /** Whether or not this transaction has been closed via `close()` */
1072
- get isOpen(): boolean;
1073
- /**
1074
- * The most up-to-date `TreeView` for this edit. This is the state of the tree after all changes applied so far.
1075
- */
1076
- get view(): TransactionView;
1077
- /**
1078
- * The status code of the most recent attempted change.
1079
- */
1080
- get status(): EditStatus;
1081
- /**
1082
- * The status code of the most recent attempted change.
1083
- */
1084
- get changes(): readonly ChangeInternal[];
1085
- /**
1086
- * The status code of the most recent attempted change.
1087
- */
1088
- get steps(): readonly ReconciliationChange[];
1089
- /**
1090
- * Information about why the transaction failed. Defined if and only if `status` is invalid or malformed.
1091
- */
1092
- get failure(): TransactionInternal.Failure | undefined;
1093
- /** @returns the final `EditStatus` and `TreeView` after all changes are applied. */
1094
- close(): EditingResult;
1095
- /**
1096
- * A helper to apply a sequence of changes. Changes will be applied one after the other. If a change fails to apply,
1097
- * the remaining changes in `changes` will be ignored.
1098
- * @param changes - the sequence of changes to apply.
1099
- * @param path - the reconciliation path for the first change.
1100
- * @returns this
1101
- */
1102
- applyChanges(changes: Iterable<ChangeInternal>, path?: ReconciliationPath): this;
1103
- /**
1104
- * Attempt to apply the given change as part of this edit. This method should not be called if a previous change in this edit failed to
1105
- * apply.
1106
- * @param change - the change to apply
1107
- * @param path - the reconciliation path for the change.
1108
- * @returns this
1109
- */
1110
- applyChange(change: ChangeInternal, path?: ReconciliationPath): this;
1111
- }
1112
-
1113
- /**
1114
- * An object that encapsulates the rules and state pertaining to a specific subclass of {@link GenericTransaction}.
1115
- * The characteristics that define such a subclass (and an implementation of this interface) are:
1116
- * - The type of change that can be applied
1117
- * - How those changes impact the state of the tree
1118
- * - How those changes are resolved in the face of concurrent changes
1119
- * - What makes a transaction valid
1120
- * - The kind of situations that might lead to a transaction failure
1121
- *
1122
- * Instances of this type are passed to the {@link GenericTransaction} constructor.
1123
- * @internal
1124
- */
1125
- export declare interface GenericTransactionPolicy {
1126
- /**
1127
- * Given a change, attempts to derive an equivalent change which can be applied to the current state even if the given change was issued
1128
- * over a different state. This can be used to apply a sequence of changes that were issued concurrently, i.e., without knowledge of
1129
- * each other.
1130
- * @param state - The current state on which the returned change will be applied.
1131
- * @param change - The original change issued.
1132
- * @param path - The reconciliation path for the change.
1133
- * @returns The change to be applied to the current state, or a failure if the change cannot be resolved.
1134
- */
1135
- tryResolveChange(state: SucceedingTransactionState, change: ChangeInternal, path: ReconciliationPath): Result<ChangeInternal, TransactionFailure>;
1136
- /**
1137
- * Provides a new state given the current state and a change to apply.
1138
- * @param state - The current state on which the change is applied.
1139
- * @param change - The change to apply to the current state.
1140
- * @returns The new state reflecting the applied change, or a failure.
1141
- */
1142
- dispatchChange(state: SucceedingTransactionState, change: ChangeInternal): ChangeResult;
1143
- /**
1144
- * Additional transaction validation when the transaction is closed.
1145
- * @param state - The current state of the transaction.
1146
- * @returns The new state reflecting the closed transaction, or a failure if the transaction cannot be closed.
1147
- */
1148
- validateOnClose(state: SucceedingTransactionState): ChangeResult;
1149
- }
1150
-
1151
- /**
1152
- * Returns a serialized description of blob paths and their associated contents for all uploaded edit chunks in the given edit log.
1153
- * @deprecated Edit virtualization is no longer supported. Do not use this.
1154
- * @internal
1155
- */
1156
- declare function getSerializedUploadedEditChunkContents(sharedTree: SharedTree): Promise<string>;
1157
- export { getSerializedUploadedEditChunkContents }
1158
- export { getSerializedUploadedEditChunkContents as getUploadedEditChunkContents }
1159
-
1160
- /**
1161
- * Return the trait under which the given range resides
1162
- * @param view - the {@link TreeView} within which to retrieve the trait location
1163
- * @param range - must be well formed and valid
1164
- * @internal
1165
- */
1166
- export declare function getTraitLocationOfRange(view: TreeView, range: StableRange): TraitLocation;
1167
-
1168
- /**
1169
- * An object which may have traits with children of the given type underneath it
1170
- * @alpha
1171
- */
1172
- export declare interface HasTraits<TChild> {
1173
- readonly traits: TraitMap<TChild>;
1174
- }
1175
-
1176
- /**
1177
- * An object which may have traits with children of the given type underneath it
1178
- * @alpha
1179
- */
1180
- export declare interface HasVariadicTraits<TChild> {
1181
- readonly traits?: {
1182
- readonly [key: string]: TChild | TreeNodeSequence<TChild> | undefined;
1183
- };
1184
- }
1185
-
1186
- /**
1187
- * Events which may be emitted by `Checkout`. See {@link CheckoutEvent} for documentation of event semantics.
1188
- * @alpha
1189
- */
1190
- export declare interface ICheckoutEvents extends IErrorEvent {
1191
- (event: 'viewChange', listener: (before: TreeView, after: TreeView) => void): any;
1192
- }
1193
-
1194
- /**
1195
- * Interface for migration events to indicate the stage of the migration. There really is two stages: before, and after.
1196
- *
1197
- * @internal
1198
- */
1199
- export declare interface IMigrationEvent extends IEvent {
1200
- /**
1201
- * Event that is emitted when the migration is complete.
1202
- */
1203
- (event: 'migrated', listener: () => void): any;
1204
- }
1205
-
1206
- /**
1207
- * The initial tree.
1208
- * @alpha
1209
- */
1210
- export declare const initialTree: ChangeNode_0_0_2;
1211
-
1212
- /**
1213
- * Inserts a sequence of nodes at the specified destination.
1214
- * The source can be constructed either by a Build (used to insert new nodes) or a Detach (amounts to a "move" operation).
1215
- * @alpha
1216
- */
1217
- export declare interface Insert {
1218
- readonly destination: StablePlace;
1219
- readonly source: number;
1220
- readonly type: typeof ChangeType.Insert;
1221
- }
1222
-
1223
- /**
1224
- * {@inheritdoc (Insert:interface)}
1225
- * @alpha
1226
- */
1227
- export declare interface InsertInternal extends Omit<InsertInternal_0_0_2, 'destination'> {
1228
- /** {@inheritdoc (Insert:interface).destination } */
1229
- readonly destination: StablePlaceInternal;
1230
- }
1231
-
1232
- /**
1233
- * {@inheritdoc (Insert:interface)}
1234
- * @alpha
1235
- */
1236
- export declare interface InsertInternal_0_0_2 {
1237
- /** {@inheritdoc (Insert:interface).destination } */
1238
- readonly destination: StablePlaceInternal_0_0_2;
1239
- /** {@inheritdoc (Insert:interface).source } */
1240
- readonly source: DetachedSequenceId;
1241
- /** {@inheritdoc (Insert:interface)."type" } */
1242
- readonly type: typeof ChangeTypeInternal.Insert;
1243
- }
1244
-
1245
- /**
1246
- * This type should be used as an opaque handle in the public API for `ChangeInternal` objects.
1247
- * This is useful for supporting public APIs which involve working with a tree's edit history,
1248
- * which will involve changes that have already been internalized.
1249
- * @alpha
1250
- */
1251
- export declare interface InternalizedChange {
1252
- InternalChangeBrand: '2cae1045-61cf-4ef7-a6a3-8ad920cb7ab3';
1253
- }
1254
-
1255
- /**
1256
- * The ID of the string that has been interned, which can be used by a {@link StringInterner} to retrieve the original string.
1257
- * @internal
1258
- */
1259
- export declare type InternedStringId = number & {
1260
- readonly InternedStringId: 'e221abc9-9d17-4493-8db0-70c871a1c27c';
1261
- };
1262
-
1263
- /**
1264
- * Determine if a node is a DetachedSequenceId.
1265
- * @internal
1266
- */
1267
- export declare function isDetachedSequenceId(node: DetachedSequenceId | object): node is DetachedSequenceId;
1268
-
1269
- /**
1270
- * Events which may be emitted by `SharedTree`. See {@link SharedTreeEvent} for documentation of event semantics.
1271
- * @alpha
1272
- */
1273
- export declare interface ISharedTreeEvents extends ISharedObjectEvents {
1274
- (event: 'committedEdit', listener: EditCommittedHandler): any;
1275
- (event: 'appliedSequencedEdit', listener: SequencedEditAppliedHandler): any;
1276
- }
1277
-
1278
- /**
1279
- * An interface for a shim channel that intercepts a LegacySharedTree or new SharedTree DDS.
1280
- *
1281
- * @internal
1282
- */
1283
- export declare interface IShim extends IChannel {
1284
- create(): void;
1285
- load(channelServices: IChannelServices): Promise<void>;
1286
- currentTree: ITree | SharedTree;
1287
- }
1288
-
1289
- /**
1290
- * Returns if the supplied event is a SharedTree telemetry event.
1291
- * @internal
1292
- */
1293
- export declare function isSharedTreeEvent(event: ITelemetryBaseEvent): boolean;
1294
-
1295
- /**
1296
- * Checkout that only updates its view of the tree when explicitly requested.
1297
- * This means that the {@link Checkout.currentView} field will never change unless {@link LazyCheckout.waitForPendingUpdates} is called.
1298
- * @sealed
1299
- * @internal
1300
- */
1301
- export declare class LazyCheckout extends Checkout {
1302
- private latestView;
1303
- /**
1304
- * @param tree - the tree
1305
- */
1306
- constructor(tree: SharedTree);
1307
- protected handleNewEdit(id: EditId, result: ValidEditingResult): void;
1308
- protected get latestCommittedView(): RevisionView;
1309
- waitForPendingUpdates(): Promise<void>;
1310
- waitForEditsToSubmit(): Promise<void>;
1311
- }
1312
-
1313
- /**
1314
- * A compressed ID that is local to a session (can only be decompressed when paired with a SessionId).
1315
- * It should not be persisted outside of the history as it can only be decompressed in the context of the originating session.
1316
- * If external persistence is needed (e.g. by a client), a StableId should be used instead.
1317
- * @alpha
1318
- */
1319
- export declare type LocalCompressedId = number & {
1320
- readonly LocalCompressedId: '6fccb42f-e2a4-4243-bd29-f13d12b9c6d1';
1321
- } & SessionUnique;
1322
-
1323
- /**
1324
- * Creates `RevisionView`s for the revisions in an `EditLog`
1325
- * @alpha
1326
- */
1327
- export declare interface LogViewer {
1328
- /**
1329
- * Returns the `TreeView` output associated with the largest revision in `editLog` less than (but not equal to) the supplied revision.
1330
- *
1331
- * For example:
1332
- *
1333
- * - revision 0 returns the initialRevision.
1334
- *
1335
- * - revision 1 returns the output of editLog[0] (or initialRevision if there is no edit 0).
1336
- *
1337
- * - revision Number.POSITIVE_INFINITY returns the newest revision.
1338
- *
1339
- * @deprecated Edit virtualization is no longer supported, use {@link LogViewer.getRevisionViewInMemory}
1340
- */
1341
- getRevisionView(revision: Revision): Promise<RevisionView>;
1342
- /**
1343
- * Returns the `TreeView` output associated with the largest revision in `editLog` less than (but not equal to) the supplied revision.
1344
- * Can only be used to retrieve revisions added during the current sessions.
1345
- *
1346
- * For example:
1347
- *
1348
- * - revision 0 returns the initialRevision.
1349
- *
1350
- * - revision 1 returns the output of editLog[0] (or initialRevision if there is no edit 0).
1351
- *
1352
- * - revision Number.POSITIVE_INFINITY returns the newest revision.
1353
- *
1354
- * @deprecated Edit virtualization is no longer supported so the 'inSession' APIs will be removed, use {@link LogViewer.getRevisionViewInMemory}
1355
- */
1356
- getRevisionViewInSession(revision: Revision): RevisionView;
1357
- /**
1358
- * Returns the `TreeView` output associated with the largest revision in `editLog` less than (but not equal to) the supplied revision.
1359
- * Can only be used to retrieve revisions added during the current session that have not been evicted from `editLog`.
1360
- *
1361
- * For example:
1362
- *
1363
- * - revision 0 returns the oldest edit in the log (which might be initialRevision).
1364
- *
1365
- * - revision 1 returns the output of editLog[0] (or initialRevision if there is no edit 0).
1366
- *
1367
- * - revision Number.POSITIVE_INFINITY returns the newest revision.
1368
- */
1369
- getRevisionViewInMemory(revision: Revision): RevisionView;
1370
- }
1371
-
1372
- /**
1373
- * Statistics about the health of collaborative edit merging when using {@link SharedTree}.
1374
- * All of those numbers constitute a tally since the last heartbeat was logged or cleared.
1375
- * @internal
1376
- */
1377
- export declare interface MergeHealthStats {
1378
- /** Number of sequenced edits applied (failed or not). */
1379
- editCount: number;
1380
- /**
1381
- * Number of sequenced edits that failed to apply.
1382
- * Such cases are also counted under {@link MergeHealthStats.editCount}.
1383
- *
1384
- * If this number is greater than the sum of:
1385
- * * {@link MergeHealthStats.badPlaceCount}
1386
- * * {@link MergeHealthStats.badRangeCount}
1387
- * * {@link MergeHealthStats.constraintViolationCount}
1388
- * * {@link MergeHealthStats.idAlreadyInUseCount}
1389
- * * {@link MergeHealthStats.unknownIdCount}
1390
- * * {@link MergeHealthStats.malformedEditCount}
1391
- *
1392
- * then some failure scenarios are not being tracked adequately.
1393
- */
1394
- failedEditCount: number;
1395
- /**
1396
- * Number of sequenced edits that failed to apply due to a bad place.
1397
- * Such cases are also counted under {@link MergeHealthStats.failedEditCount}.
1398
- *
1399
- * If this number is greater than the sum of:
1400
- * * {@link MergeHealthStats.deletedAncestorBadPlaceCount}
1401
- * * {@link MergeHealthStats.deletedSiblingBadPlaceCount}
1402
- *
1403
- * then some failure scenarios are not being tracked adequately.
1404
- */
1405
- badPlaceCount: number;
1406
- /**
1407
- * Number of sequenced edits that failed to apply due to a bad range.
1408
- * Such cases are also counted under {@link MergeHealthStats.failedEditCount}.
1409
- *
1410
- * If this number is greater than the sum of:
1411
- * * {@link MergeHealthStats.deletedAncestorBadRangeCount}
1412
- * * {@link MergeHealthStats.deletedSiblingBadRangeCount}
1413
- * * {@link MergeHealthStats.updatedRangeInvertedCount}
1414
- * * {@link MergeHealthStats.updatedRangeHasPlacesInDifferentTraitsCount}
1415
- * * {@link MergeHealthStats.updatedRangeBadPlaceCount}
1416
- * * {@link MergeHealthStats.updatedRangeNeverValidPlaceCount}
1417
- *
1418
- * then some failure scenarios are not being tracked adequately.
1419
- */
1420
- badRangeCount: number;
1421
- /**
1422
- * Number of sequenced edits that failed to apply due to a place whose ancestors had been concurrently deleted.
1423
- * Such cases are also counted under {@link MergeHealthStats.badPlaceCount}.
1424
- */
1425
- deletedAncestorBadPlaceCount: number;
1426
- /**
1427
- * Number of sequenced edits that failed to apply due to a range whose ancestors had been concurrently deleted.
1428
- * Such cases are also counted under {@link MergeHealthStats.badRangeCount}.
1429
- */
1430
- deletedAncestorBadRangeCount: number;
1431
- /**
1432
- * Number of sequenced edits that failed to apply due to a place whose sibling (but not its parent) had been concurrently deleted.
1433
- * Such cases are also counted under {@link MergeHealthStats.badPlaceCount}.
1434
- */
1435
- deletedSiblingBadPlaceCount: number;
1436
- /**
1437
- * Number of sequenced edits that failed to apply due to a range whose delimiting sibling(s) (but not its parent) had been concurrently
1438
- * deleted.
1439
- * Such cases are also counted under {@link MergeHealthStats.badRangeCount}.
1440
- */
1441
- deletedSiblingBadRangeCount: number;
1442
- /**
1443
- * Number of sequenced edits that failed to apply due to a range whose places were resolvable but inverted (i.e., end before start).
1444
- * Such cases are also counted under {@link MergeHealthStats.badRangeCount}.
1445
- */
1446
- updatedRangeInvertedCount: number;
1447
- /**
1448
- * Number of sequenced edits that failed to apply due to a range whose places were resolvable but in different traits.
1449
- * Such cases are also counted under {@link MergeHealthStats.badRangeCount}.
1450
- */
1451
- updatedRangeHasPlacesInDifferentTraitsCount: number;
1452
- /**
1453
- * Number of sequenced edits that failed to apply due to a range whose places were resolvable but bad.
1454
- * This should not happen because place resolution is expected to either return a valid place or fail.
1455
- * Such cases are also counted under {@link MergeHealthStats.badRangeCount}.
1456
- */
1457
- updatedRangeBadPlaceCount: number;
1458
- /**
1459
- * Number of sequenced edits that failed to apply due to a range whose places were not resolvable due to not being valid for any state.
1460
- * Such cases are also counted under {@link MergeHealthStats.badRangeCount}.
1461
- */
1462
- updatedRangeNeverValidPlaceCount: number;
1463
- /**
1464
- * Number of sequenced edits that failed to apply due to a constraint violation.
1465
- * Such cases are also counted under {@link MergeHealthStats.failedEditCount}.
1466
- *
1467
- * If this number is greater than the sum of:
1468
- * * {@link MergeHealthStats.rangeConstraintViolationCount}
1469
- * * {@link MergeHealthStats.lengthConstraintViolationCount}
1470
- * * {@link MergeHealthStats.parentConstraintViolationCount}
1471
- * * {@link MergeHealthStats.labelConstraintViolationCount}
1472
- *
1473
- * then some failure scenarios are not being tracked adequately.
1474
- */
1475
- constraintViolationCount: number;
1476
- /**
1477
- * Number of sequenced edits that failed to apply due to a constrained range becoming invalid or malformed.
1478
- * Such cases are also counted under {@link MergeHealthStats.constraintViolationCount}.
1479
- */
1480
- rangeConstraintViolationCount: number;
1481
- /**
1482
- * Number of sequenced edits that failed to apply due to a constrained range having a different length.
1483
- * Such cases are also counted under {@link MergeHealthStats.constraintViolationCount}.
1484
- */
1485
- lengthConstraintViolationCount: number;
1486
- /**
1487
- * Number of sequenced edits that failed to apply due to a constrained range being under a different parent.
1488
- * Such cases are also counted under {@link MergeHealthStats.constraintViolationCount}.
1489
- */
1490
- parentConstraintViolationCount: number;
1491
- /**
1492
- * Number of sequenced edits that failed to apply due to a constrained range being under a different label.
1493
- * Such cases are also counted under {@link MergeHealthStats.constraintViolationCount}.
1494
- */
1495
- labelConstraintViolationCount: number;
1496
- /**
1497
- * Number of sequenced edits that failed to apply due to an ID collision.
1498
- * Such cases are also counted under {@link MergeHealthStats.failedEditCount}.
1499
- */
1500
- idAlreadyInUseCount: number;
1501
- /**
1502
- * Number of sequenced edits that failed to apply due to an ID being unknown.
1503
- * Such cases are also counted under {@link MergeHealthStats.failedEditCount}.
1504
- */
1505
- unknownIdCount: number;
1506
- /**
1507
- * Number of sequenced edits that failed to apply due to an edit becoming malformed.
1508
- * This should theoretically never happen.
1509
- * Such cases are also counted under {@link MergeHealthStats.failedEditCount}.
1510
- */
1511
- malformedEditCount: number;
1512
- /**
1513
- * The counts of occurrences for a given path length. `pathLengths[1] === 2` means two occurrences of length one.
1514
- */
1515
- pathLengths: number[];
1516
- /** The highest number previous attempts on a sequenced edit. */
1517
- maxAttemptCount: number;
1518
- }
1519
-
1520
- /**
1521
- * The MigrationShim loads in place of the legacy SharedTree. It provides API surface for migrating it to the new SharedTree, while also providing access to the current SharedTree for usage.
1522
- *
1523
- * @remarks
1524
- *
1525
- * This MigrationShim is responsible for submitting a migration op, processing the migrate op, swapping from the old
1526
- * tree to the new tree, loading an old tree snapshot and creating an old tree.
1527
- *
1528
- * The MigrationShim expects to always load from a legacy SharedTree snapshot, though by the time it catches up in
1529
- * processing all ops, it may find that the migration has already occurred. After migration occurs, it modifies its
1530
- * attributes to point at the SharedTreeShimFactory. This will cause future clients to load with a SharedTreeShim and
1531
- * the new SharedTree snapshot instead after the next summarization.
1532
- *
1533
- * @internal
1534
- */
1535
- export declare class MigrationShim extends EventEmitterWithErrorHandling<IMigrationEvent> implements IShim {
1536
- readonly id: string;
1537
- private readonly runtime;
1538
- private readonly legacyTreeFactory;
1539
- private readonly newTreeFactory;
1540
- private readonly populateNewSharedObjectFn;
1541
- constructor(id: string, runtime: IFluidDataStoreRuntime, legacyTreeFactory: SharedTreeFactory, newTreeFactory: IChannelFactory, populateNewSharedObjectFn: (legacyTree: SharedTree, newTree: ITree) => void);
1542
- private readonly processMigrateOp;
1543
- private readonly migrationDeltaHandler;
1544
- private services?;
1545
- private preMigrationDeltaConnection?;
1546
- private postMigrationServices?;
1547
- private _legacyTree;
1548
- private get legacyTree();
1549
- private newTree;
1550
- /**
1551
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.closeError}
1552
- */
1553
- private closeError?;
1554
- /**
1555
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.eventListenerErrorHandler}
1556
- */
1557
- private eventListenerErrorHandler;
1558
- /**
1559
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.closeWithError}
1560
- */
1561
- private closeWithError;
1562
- /**
1563
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.verifyNotClosed}
1564
- */
1565
- private verifyNotClosed;
1566
- /**
1567
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.submitLocalMessage}
1568
- */
1569
- private readonly submitLocalMessage;
1570
- submitMigrateOp(): void;
1571
- get currentTree(): SharedTree | ITree;
1572
- load(services: IChannelServices): Promise<void>;
1573
- create(): void;
1574
- get attributes(): IChannelAttributes;
1575
- getAttachSummary(fullTree?: boolean | undefined, trackState?: boolean | undefined, telemetryContext?: ITelemetryContext | undefined): ISummaryTreeWithStats;
1576
- summarize(fullTree?: boolean | undefined, trackState?: boolean | undefined, telemetryContext?: ITelemetryContext | undefined, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext | undefined): Promise<ISummaryTreeWithStats>;
1577
- isAttached(): boolean;
1578
- connect(services: IChannelServices): void;
1579
- private reconnect;
1580
- /**
1581
- * Only generate the ShimServices once as the underlying DeltaHandler can only be connected to once. If we connect
1582
- * twice, we will be in a "v2" state even though we really are in a "v1" state. We will encounter unexpected op
1583
- * dropping behavior or lack thereof and may corrupt the document.
1584
- * @param services - the services to generate the shim services from
1585
- * @returns - shim services
1586
- */
1587
- private generateShimServicesOnce;
1588
- getGCData(fullGC?: boolean | undefined): IGarbageCollectionData;
1589
- handle: IFluidHandle<MigrationShim>;
1590
- get IFluidLoadable(): IFluidLoadable;
1591
- }
1592
-
1593
- /**
1594
- * {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link MigrationShim}.
1595
- *
1596
- * Creates the migration shim that allows a migration from legacy shared tree to shared tree.
1597
- * @remarks
1598
- *
1599
- * It takes over the attributes of the legacy factory, so that it is loaded instead of the normal legacy factory. Once migration finishes, the shim it produces will change its attributes to those of the new factory - meaning that on the next summarization the shim will write a summary that will cause future clients to load a different factory and shim (the SharedTreeShimFactory and SharedTreeShim).
1600
- * 1. pre-migration
1601
- *
1602
- * @sealed
1603
- * @internal
1604
- */
1605
- export declare class MigrationShimFactory implements IChannelFactory {
1606
- private readonly oldFactory;
1607
- private readonly newFactory;
1608
- private readonly populateNewChannelFn;
1609
- constructor(oldFactory: SharedTreeFactory, newFactory: IChannelFactory, populateNewChannelFn: (oldChannel: SharedTree, newChannel: ITree) => void);
1610
- /**
1611
- * This factory takes over the type of the oldFactory to load in its place. The user must not include the MigrationShimFactory and the oldFactory in the same registry to avoid conflict.
1612
- *
1613
- * {@link @fluidframework/datastore-definitions#IChannelFactory."type"}
1614
- */
1615
- get type(): string;
1616
- /**
1617
- * Should be the LegacySharedTree attributes
1618
- *
1619
- * {@link @fluidframework/datastore-definitions#IChannelFactory.attributes}
1620
- */
1621
- get attributes(): IChannelAttributes;
1622
- /**
1623
- * {@link @fluidframework/datastore-definitions#IChannelFactory.load}
1624
- *
1625
- * Should be loading the MigrationShim - it should just load the old tree as this makes the factory's
1626
- * responsibility simple. Trying to follow the Single Responsibility Principle here.
1627
- */
1628
- load(runtime: IFluidDataStoreRuntime, id: string, services: IChannelServices, attributes: IChannelAttributes): Promise<MigrationShim>;
1629
- /**
1630
- * {@link @fluidframework/datastore-definitions#IChannelFactory.create}
1631
- *
1632
- * Create MigrationShim that can hot swap from one DDS to a new DDS. We want the capability of creating an old tree
1633
- * as when this code rolls out, there may be clients on the v1 version of the code, and we may want to have a dark
1634
- * rollout capability.
1635
- */
1636
- create(runtime: IFluidDataStoreRuntime, id: string): MigrationShim;
1637
- }
1638
-
1639
- /**
1640
- * The fields required by a node in a tree
1641
- * @alpha
1642
- */
1643
- export declare interface NodeData<TId> {
1644
- /**
1645
- * A payload of arbitrary serializable data
1646
- */
1647
- readonly payload?: Payload;
1648
- /**
1649
- * The meaning of this node.
1650
- * Provides contexts/semantics for this node and its content.
1651
- * Typically use to associate a node with metadata (including a schema) and source code (types, behaviors, etc).
1652
- */
1653
- readonly definition: Definition;
1654
- /**
1655
- * Identifier which can be used to refer to this Node.
1656
- */
1657
- readonly identifier: TId;
1658
- }
1659
-
1660
- /**
1661
- * Node identifier.
1662
- * Identifies a node within a document.
1663
- * @alpha
1664
- */
1665
- export declare type NodeId = number & SessionSpaceCompressedId & NodeIdBrand;
1666
-
1667
- /**
1668
- * @alpha
1669
- */
1670
- export declare interface NodeIdBrand {
1671
- readonly NodeId: 'e53e7d6b-c8b9-431a-8805-4843fc639342';
1672
- }
1673
-
1674
- /**
1675
- * An object which can generate node IDs and convert node IDs between compressed and stable variants
1676
- * @alpha
1677
- */
1678
- export declare interface NodeIdContext extends NodeIdGenerator, NodeIdConverter {
1679
- }
1680
-
1681
- /**
1682
- * An object which can convert node IDs between compressed and stable variants
1683
- * @alpha
1684
- */
1685
- export declare interface NodeIdConverter {
1686
- /**
1687
- * Given a NodeId, returns the corresponding stable ID or throws if the supplied node ID was not generated with this tree (`NodeId`s
1688
- * may not be used across SharedTree instances, see `generateNodeId` for more).
1689
- * The returned value will be a UUID, unless the creation of `id` used an override string (see `generateNodeId` for more).
1690
- * The result is safe to persist and re-use across `SharedTree` instances, unlike `NodeId`.
1691
- */
1692
- convertToStableNodeId(id: NodeId): StableNodeId;
1693
- /**
1694
- * Given a NodeId, attempt to return the corresponding stable ID.
1695
- * The returned value will be a UUID, unless the creation of `id` used an override string (see `generateNodeId` for more).
1696
- * The returned stable ID is undefined if `id` was never created with this SharedTree. If a stable ID is returned, this does not imply
1697
- * that there is a node with `id` in the current revision of the tree, only that `id` was at some point generated by some instance of
1698
- * this tree.
1699
- */
1700
- tryConvertToStableNodeId(id: NodeId): StableNodeId | undefined;
1701
- /**
1702
- * Given a stable ID, return the corresponding NodeId or throws if the supplied stable ID was never generated with this tree, either
1703
- * as a UUID corresponding to a `NodeId` or as an override passed to `generateNodeId`.
1704
- * If a stable ID is returned, this does not imply that there is a node with `id` in the current revision of the tree, only that
1705
- * `id` was at some point generated by an instance of this SharedTree.
1706
- */
1707
- convertToNodeId(id: StableNodeId): NodeId;
1708
- /**
1709
- * Given a stable ID, return the corresponding NodeId or return undefined if the supplied stable ID was never generated with this tree,
1710
- * either as a UUID corresponding to a `NodeId` or as an override passed to `generateNodeId`.
1711
- * If a stable ID is returned, this does not imply that there is a node with `id` in the current revision of the tree, only that
1712
- * `id` was at some point generated by an instance of this SharedTree.
1713
- */
1714
- tryConvertToNodeId(id: StableNodeId): NodeId | undefined;
1715
- }
1716
-
1717
- /**
1718
- * An object which can generate node IDs
1719
- * @alpha
1720
- */
1721
- export declare interface NodeIdGenerator {
1722
- /**
1723
- * Generates a node identifier.
1724
- * The returned IDs may be used as the identifier of a node in the SharedTree.
1725
- * `NodeId`s are *always* unique and stable within the scope of the tree and session that generated them. They are *not* unique within
1726
- * a Fluid container, and *cannot* be compared across instances of a SharedTree. They are *not* stable across sessions/lifetimes of a
1727
- * SharedTree, and *cannot* be persisted (e.g. stored in payloads, uploaded in blobs, etc.). If stable persistence is needed,
1728
- * NodeIdConverter.convertToStableNodeId may be used to return a corresponding UUID that is globally unique and stable.
1729
- * @param override - if supplied, calls to `convertToStableNodeId` using the returned node ID will return the override instead of
1730
- * the UUID. Calls to `generateNodeId` with the same override always return the same ID. Performance note: passing an override string
1731
- * incurs a storage cost that is significantly higher that a node ID without one, and should be avoided if possible.
1732
- */
1733
- generateNodeId(override?: string): NodeId;
1734
- }
1735
-
1736
- /**
1737
- * Contains some redundant information. Use only in computations between edits. Do not store.
1738
- * @internal
1739
- */
1740
- export declare interface NodeInTrait {
1741
- readonly trait: TraitLocation;
1742
- readonly index: TraitNodeIndex;
1743
- }
1744
-
1745
- /**
1746
- * An ordered set of Edits associated with a SharedTree.
1747
- * Supports fast lookup of edits by ID and enforces idempotence.
1748
- * @sealed
1749
- * @alpha
1750
- */
1751
- export declare interface OrderedEditSet<TChange = unknown> {
1752
- /**
1753
- * The length of this `OrderedEditSet`.
1754
- */
1755
- readonly length: number;
1756
- /**
1757
- * The edit IDs of all edits in the log.
1758
- */
1759
- readonly editIds: readonly EditId[];
1760
- /**
1761
- * @returns the index of the edit with the given editId within this `OrderedEditSet`.
1762
- */
1763
- getIndexOfId(editId: EditId): number;
1764
- /**
1765
- * @returns the id of the edit at the given index within this 'OrderedEditSet'.
1766
- */
1767
- getIdAtIndex(index: number): EditId;
1768
- /**
1769
- * @returns the index of the edit with the given editId within this `OrderedEditSet`, or `undefined` if no such edit exists.
1770
- */
1771
- tryGetIndexOfId(editId: EditId): number | undefined;
1772
- /**
1773
- * @returns the edit at the given index within this `OrderedEditSet`.
1774
- */
1775
- tryGetEditAtIndex(index: number): Edit<TChange> | undefined;
1776
- /**
1777
- * @returns the edit with the given identifier within this `OrderedEditSet`.
1778
- */
1779
- tryGetEditFromId(editId: EditId): Edit<TChange> | undefined;
1780
- /**
1781
- * @returns the Edit associated with the EditId or undefined if there is no such edit in the set.
1782
- * @deprecated Edit virtualization is no longer supported. Don't use the asynchronous APIs. Instead, use {@link OrderedEditSet.tryGetEditFromId}.
1783
- */
1784
- tryGetEdit(editId: EditId): Promise<Edit<TChange> | undefined>;
1785
- /**
1786
- * @returns the edit at the given index within this `OrderedEditSet`.
1787
- * @deprecated Edit virtualization is no longer supported. Don't use the asynchronous APIs.
1788
- */
1789
- getEditAtIndex(index: number): Promise<Edit<TChange>>;
1790
- /**
1791
- * @returns the edit at the given index. Must have been added to the log during the current session.
1792
- * @deprecated this will be removed in favor of {@link OrderedEditSet.tryGetEditAtIndex}
1793
- */
1794
- getEditInSessionAtIndex(index: number): Edit<TChange>;
1795
- }
1796
-
1797
- /**
1798
- * Information about a ForestNode's parent
1799
- * @alpha
1800
- */
1801
- export declare interface ParentData {
1802
- readonly parentId: NodeId;
1803
- readonly traitParent: TraitLabel;
1804
- }
1805
-
1806
- /**
1807
- * Json compatible representation of a payload storing arbitrary Serializable data.
1808
- *
1809
- * Keys starting with "IFluid" are reserved for special use such as the JavaScript feature detection pattern and should not be used.
1810
- *
1811
- * See {@link comparePayloads} for equality semantics and related details (like what is allowed to be lost when serializing)
1812
- *
1813
- * TODO:#51984: Allow opting into heuristic blobbing in snapshots with a special IFluid key.
1814
- * @alpha
1815
- */
1816
- export declare type Payload = any;
1817
-
1818
- /**
1819
- * Express the given {@link (StablePlace:interface)} as a {@link TreeViewPlace}
1820
- * @internal
1821
- */
1822
- export declare function placeFromStablePlace(view: TreeView, stablePlace: StablePlace): TreeViewPlace;
1823
-
1824
- /**
1825
- * A tree whose nodes are either TreeNodes or a placeholder
1826
- * @internal
1827
- */
1828
- export declare type PlaceholderTree<TPlaceholder = never> = TreeNode<PlaceholderTree<TPlaceholder>, NodeId> | TPlaceholder;
1829
-
1830
- /**
1831
- * Index of a place within a trait.
1832
- * 0 = before all nodes,
1833
- * 1 = after first node,
1834
- * etc.
1835
- * @alpha
1836
- */
1837
- export declare type PlaceIndex = number & {
1838
- readonly PlaceIndex: unique symbol;
1839
- };
1840
-
1841
- /**
1842
- * The result of validating a place.
1843
- * @alpha
1844
- */
1845
- export declare enum PlaceValidationResult {
1846
- Valid = "Valid",
1847
- Malformed = "Malformed",
1848
- SiblingIsRootOrDetached = "SiblingIsRootOrDetached",
1849
- MissingSibling = "MissingSibling",
1850
- MissingParent = "MissingParent"
1851
- }
1852
-
1853
- /**
1854
- * Express the given {@link (StableRange:interface)} as a {@link TreeViewRange}
1855
- * @internal
1856
- */
1857
- export declare function rangeFromStableRange(view: TreeView, range: StableRange): TreeViewRange;
1858
-
1859
- /**
1860
- * The result of validating a range.
1861
- * @alpha
1862
- */
1863
- export declare type RangeValidationResult = RangeValidationResultKind.Valid | RangeValidationResultKind.PlacesInDifferentTraits | RangeValidationResultKind.Inverted | {
1864
- kind: RangeValidationResultKind.BadPlace;
1865
- place: StablePlaceInternal;
1866
- placeFailure: BadPlaceValidationResult;
1867
- };
1868
-
1869
- /**
1870
- * The kinds of result of validating a range.
1871
- * @alpha
1872
- */
1873
- export declare enum RangeValidationResultKind {
1874
- Valid = "Valid",
1875
- BadPlace = "BadPlace",
1876
- PlacesInDifferentTraits = "PlacesInDifferentTraits",
1877
- Inverted = "Inverted"
1878
- }
1879
-
1880
- /**
1881
- * A change in the `ReconciliationPath`.
1882
- * @alpha
1883
- */
1884
- export declare interface ReconciliationChange {
1885
- /**
1886
- * The resolved change that was applied during the edit.
1887
- * Resolved changes are guaranteed to be expressed with valid tree locations instead of anchors that need resolution.
1888
- */
1889
- readonly resolvedChange: ChangeInternal;
1890
- /**
1891
- * The resulting view from applying the resolved change.
1892
- */
1893
- readonly after: TransactionView;
1894
- }
1895
-
1896
- /**
1897
- * An edit in the `ReconciliationPath`.
1898
- * @alpha
1899
- */
1900
- export declare interface ReconciliationEdit {
1901
- /**
1902
- * The state before the edit was applied.
1903
- */
1904
- readonly before: TreeView;
1905
- /**
1906
- * The state after the edit was applied.
1907
- */
1908
- readonly after: TreeView;
1909
- /**
1910
- * The number of changes in the edit.
1911
- */
1912
- readonly length: number;
1913
- /**
1914
- * Allows access to change information.
1915
- * @returns Reconciliation information for the change at the given `index`.
1916
- */
1917
- readonly [index: number]: ReconciliationChange;
1918
- }
1919
-
1920
- /**
1921
- * The path of edits from the revision view where a change was meant to have been applied to the view where the edit that contains the
1922
- * change is actually applied.
1923
- * The path only contains edits that were successfully applied.
1924
- * This path is always empty for a change that has no concurrent edits.
1925
- * @alpha
1926
- */
1927
- export declare interface ReconciliationPath {
1928
- /**
1929
- * The number of edits in the path.
1930
- */
1931
- readonly length: number;
1932
- /**
1933
- * Allows access to edit information.
1934
- * @returns Reconciliation information for the edit at the given `index`.
1935
- */
1936
- readonly [index: number]: ReconciliationEdit;
1937
- }
1938
-
1939
- /**
1940
- * Discriminated union instance that wraps either a result of type `TOk` or an error of type `TError`.
1941
- * @internal
1942
- */
1943
- export declare type Result<TOk, TError> = Result.Ok<TOk> | Result.Error<TError>;
1944
-
1945
- /**
1946
- * @internal
1947
- */
1948
- export declare namespace Result {
1949
- /**
1950
- * Factory function for making a successful Result.
1951
- * @param result - The result to wrap in the Result.
1952
- * @internal
1953
- */
1954
- export function ok<TOk>(result: TOk): Ok<TOk>;
1955
- /**
1956
- * Factory function for making a unsuccessful Result.
1957
- * @param error - The error to wrap in the Result.
1958
- * @internal
1959
- */
1960
- export function error<TError>(error: TError): Error<TError>;
1961
- /**
1962
- * Type guard for successful Result.
1963
- * @returns True if `result` is successful.
1964
- * @internal
1965
- */
1966
- export function isOk<TOk, TError>(result: Result<TOk, TError>): result is Ok<TOk>;
1967
- /**
1968
- * Type guard for unsuccessful Result.
1969
- * @returns True if `result` is unsuccessful.
1970
- * @internal
1971
- */
1972
- export function isError<TOk, TError>(result: Result<TOk, TError>): result is Error<TError>;
1973
- /**
1974
- * Maps the given result with the given function when the result is ok.
1975
- * @param result - The result to map.
1976
- * @param map - The function to apply to derive the new result.
1977
- * @returns The given result if it is not ok, the mapped result otherwise.
1978
- * @internal
1979
- */
1980
- export function mapOk<TOkIn, TOkOut, TError>(result: Result<TOkIn, TError>, map: (ok: TOkIn) => TOkOut): Result<TOkOut, TError>;
1981
- /**
1982
- * Maps the given result with the given function when the result is an error.
1983
- * @param result - The result to map.
1984
- * @param map - The function to apply to derive the new error.
1985
- * @returns The given result if it is ok, the mapped result otherwise.
1986
- * @internal
1987
- */
1988
- export function mapError<TOk, TErrorIn, TErrorOut>(result: Result<TOk, TErrorIn>, map: (error: TErrorIn) => TErrorOut): Result<TOk, TErrorOut>;
1989
- /**
1990
- * Tag value use to differentiate the members of the `Result` discriminated union.
1991
- * @internal
1992
- */
1993
- export enum ResultType {
1994
- /** Signals a successful result. */
1995
- Ok = 0,
1996
- /** Signals an unsuccessful result. */
1997
- Error = 1
1998
- }
1999
- /**
2000
- * Wraps a result of type `TOk`.
2001
- * @internal
2002
- */
2003
- export interface Ok<TOk> {
2004
- readonly type: ResultType.Ok;
2005
- readonly result: TOk;
2006
- }
2007
- /**
2008
- * Wraps an error of type `TError`.
2009
- * @internal
2010
- */
2011
- export interface Error<TError> {
2012
- readonly type: ResultType.Error;
2013
- readonly error: TError;
2014
- }
2015
- }
2016
-
2017
- /**
2018
- * A revision corresponds to an index in an `EditLog`.
2019
- *
2020
- * It is associated with the output `RevisionView` of applying the edit at the index to the previous revision.
2021
- * For example:
2022
- *
2023
- * - revision 0 corresponds to the initialRevision.
2024
- *
2025
- * - revision 1 corresponds to the output of editLog[0] applied to the initialRevision.
2026
- * @alpha
2027
- */
2028
- export declare type Revision = number;
2029
-
2030
- /**
2031
- * An immutable view of a distributed tree.
2032
- * @alpha
2033
- */
2034
- export declare class RevisionView extends TreeView {
2035
- /**
2036
- * Constructs a {@link RevisionView} using the supplied tree.
2037
- * @param root - the root of the tree to use as the contents of the {@link RevisionView}
2038
- * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing
2039
- */
2040
- static fromTree<T extends TreeNode<T, NodeId>>(root: T, expensiveValidation?: boolean): RevisionView;
2041
- /**
2042
- * Constructs a {@link RevisionView} using the supplied tree.
2043
- * @param root - the root of the tree to use as the contents of the `RevisionView`
2044
- * @param idConverter - the {@link NodeIdConverter} that will recompress the IDs the in the tree
2045
- * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing
2046
- */
2047
- static fromTree<T extends TreeNode<T, StableNodeId>>(root: T, idConverter: NodeIdConverter, expensiveValidation?: boolean): RevisionView;
2048
- /** Begin a transaction by generating a mutable `TransactionView` from this view */
2049
- openForTransaction(): TransactionView;
2050
- equals(view: TreeView): boolean;
2051
- }
2052
-
2053
- /**
2054
- * The arguments included when the {@link SharedTreeEvent.SequencedEditApplied} SharedTreeEvent is emitted.
2055
- * @alpha
2056
- */
2057
- export declare interface SequencedEditAppliedEventArguments {
2058
- /** The ID of the edit committed. */
2059
- readonly edit: Edit<ChangeInternal>;
2060
- /** Whether or not this was a local edit. */
2061
- readonly wasLocal: boolean;
2062
- /** The tree the edit was applied to. */
2063
- readonly tree: SharedTree;
2064
- /** The telemetry logger associated with sequenced edit application. */
2065
- readonly logger: ITelemetryLoggerExt;
2066
- /** The reconciliation path for the edit. See {@link ReconciliationPath} for details. */
2067
- readonly reconciliationPath: ReconciliationPath;
2068
- /** The outcome of the sequenced edit being applied. */
2069
- readonly outcome: EditApplicationOutcome;
2070
- }
2071
-
2072
- /**
2073
- * Expected type for a handler of the {@link SharedTreeEvent.SequencedEditApplied} event.
2074
- * @alpha
2075
- */
2076
- export declare type SequencedEditAppliedHandler = (args: SequencedEditAppliedEventArguments) => void;
2077
-
2078
- /**
2079
- * A compressed ID that has been normalized into "session space" (see `IdCompressor` for more).
2080
- * Consumer-facing APIs and data structures should use session-space IDs as their lifetime and equality is stable and tied to the
2081
- * compressor that produced them.
2082
- * @alpha
2083
- */
2084
- export declare type SessionSpaceCompressedId = CompressedId & SessionUnique;
2085
-
2086
- /**
2087
- * A brand for identity types that are unique within a particular session (SharedTree instance).
2088
- * @alpha
2089
- */
2090
- export declare interface SessionUnique {
2091
- readonly SessionUnique: 'cea55054-6b82-4cbf-ad19-1fa645ea3b3e';
2092
- }
2093
-
2094
- /**
2095
- * Create a sequence of changes that resets the contents of `trait`.
2096
- * @internal
2097
- */
2098
- export declare function setTrait(trait: TraitLocation, nodes: BuildNode | TreeNodeSequence<BuildNode>): Change[];
2099
-
2100
- /**
2101
- * Modifies the payload of a node.
2102
- * @alpha
2103
- */
2104
- export declare interface SetValue {
2105
- readonly nodeToModify: NodeId;
2106
- /**
2107
- * Sets or clears the payload.
2108
- * To improve ease of forwards compatibility, an explicit `null` value is used to represent the clearing of a payload.
2109
- * SetValue may use `undefined` in future API versions to mean "don't change the payload" (which is useful if e.g. other
2110
- * fields are added to SetValue that can be changed without altering the payload)
2111
- */
2112
- readonly payload: Payload | null;
2113
- readonly type: typeof ChangeType.SetValue;
2114
- }
2115
-
2116
- /**
2117
- * {@inheritdoc SetValue}
2118
- * @alpha
2119
- */
2120
- export declare interface SetValueInternal extends Omit<SetValueInternal_0_0_2, 'nodeToModify'> {
2121
- /** {@inheritdoc SetValue.nodeToModify } */
2122
- readonly nodeToModify: NodeId;
2123
- }
2124
-
2125
- /**
2126
- * {@inheritdoc SetValue}
2127
- * @alpha
2128
- */
2129
- export declare interface SetValueInternal_0_0_2 {
2130
- /** {@inheritdoc SetValue.nodeToModify } */
2131
- readonly nodeToModify: StableNodeId;
2132
- /** {@inheritdoc SetValue.payload } */
2133
- readonly payload: Payload | null;
2134
- /** {@inheritdoc SetValue."type" } */
2135
- readonly type: typeof ChangeTypeInternal.SetValue;
2136
- }
2137
-
2138
- /**
2139
- * A [distributed tree](../Readme.md).
2140
- * @alpha
2141
- */
2142
- export declare class SharedTree extends SharedObject<ISharedTreeEvents> implements NodeIdContext {
2143
- private writeFormat;
2144
- /**
2145
- * Create a new SharedTree. It will contain the default value (see initialTree).
2146
- */
2147
- static create(runtime: IFluidDataStoreRuntime, id?: string): SharedTree;
2148
- /**
2149
- * Get a factory for SharedTree to register with the data store.
2150
- * @param writeFormat - Determines the format version the SharedTree will write ops and summaries in.
2151
- * This format may be updated to a newer (supported) version at runtime if a collaborating shared-tree
2152
- * that was initialized with a newer write version connects to the session. Care must be taken when changing this value,
2153
- * as a staged rollout must of occurred such that all collaborating clients must have the code to read at least the version
2154
- * written.
2155
- * See [the write format documentation](../docs/Write-Format.md) for more information.
2156
- * @param options - Configuration options for this tree
2157
- * @returns A factory that creates `SharedTree`s and loads them from storage.
2158
- */
2159
- static getFactory(...args: SharedTreeArgs<WriteFormat.v0_0_2>): SharedTreeFactory;
2160
- static getFactory(...args: SharedTreeArgs<WriteFormat.v0_1_1>): SharedTreeFactory;
2161
- /**
2162
- * Get a factory for SharedTree to register with the data store, using the latest write version and default options.
2163
- */
2164
- static getFactory(): SharedTreeFactory;
2165
- /**
2166
- * The UUID used for attribution of nodes created by this SharedTree. All shared trees with a write format of 0.1.1 or
2167
- * greater have a unique attribution ID which may be configured in the constructor. All other shared trees (i.e. those
2168
- * with a write format of 0.0.2) use the nil UUID as their attribution ID.
2169
- */
2170
- get attributionId(): AttributionId;
2171
- /**
2172
- * This is SharedTree's internal IdCompressor that predates the one in the runtime. If access
2173
- * to the IdCompressor is needed, this is the one that should be used.
2174
- */
2175
- private idCompressor;
2176
- private readonly idNormalizer;
2177
- /** Temporarily created to apply stashed ops from a previous session */
2178
- private stashedIdCompressor?;
2179
- private interner;
2180
- /**
2181
- * The log of completed edits for this SharedTree.
2182
- */
2183
- private editLog;
2184
- private readonly editLogSize?;
2185
- private readonly editEvictionFrequency?;
2186
- /**
2187
- * As an implementation detail, SharedTree uses a log viewer that caches views of different revisions.
2188
- * It is not exposed to avoid accidental correctness issues, but `logViewer` is exposed in order to give clients a way
2189
- * to access the revision history.
2190
- */
2191
- private cachingLogViewer;
2192
- /**
2193
- * Viewer for trees defined by editLog. This allows access to views of the tree at different revisions (various points in time).
2194
- */
2195
- get logViewer(): LogViewer;
2196
- /**
2197
- * logger for SharedTree events.
2198
- */
2199
- readonly logger: ITelemetryLoggerExt;
2200
- private readonly sequencedEditAppliedLogger;
2201
- private readonly encoder_0_0_2;
2202
- private encoder_0_1_1;
2203
- private readonly processEditResult;
2204
- private readonly processSequencedEditResult;
2205
- private summarizeHistory;
2206
- private getHistoryPolicy;
2207
- /**
2208
- * Create a new SharedTree.
2209
- * @param runtime - The runtime the SharedTree will be associated with
2210
- * @param id - Unique ID for the SharedTree
2211
- * @param writeFormat - Determines the format version the SharedTree will write ops and summaries in. See [the write format
2212
- * documentation](../docs/Write-Format.md) for more information.
2213
- * @param options - Configuration options for this tree
2214
- */
2215
- constructor(runtime: IFluidDataStoreRuntime, id: string, ...args: SharedTreeArgs<WriteFormat.v0_0_2>);
2216
- constructor(runtime: IFluidDataStoreRuntime, id: string, ...args: SharedTreeArgs<WriteFormat.v0_1_1>);
2217
- /**
2218
- * The write format version currently used by this `SharedTree`. This is always initialized to the write format
2219
- * passed to the tree's constructor, but it may automatically upgrade over time (e.g. when connected to another
2220
- * SharedTree with a higher write format, or when loading a summary with a higher write format).
2221
- */
2222
- getWriteFormat(): WriteFormat;
2223
- /**
2224
- * Computes the oldest client in the quorum, true by default if the container is detached and false by default if the client isn't connected.
2225
- * TODO:#55900: Get rid of copy-pasted OldestClientObserver code
2226
- */
2227
- private computeIsOldest;
2228
- /**
2229
- * @returns the current view of the tree.
2230
- */
2231
- get currentView(): RevisionView;
2232
- /**
2233
- * Generates a node identifier.
2234
- * The returned IDs may be used as the identifier of a node in the SharedTree.
2235
- * `NodeId`s are *always* unique and stable within the scope of the tree and session that generated them. They are *not* unique within
2236
- * a Fluid container, and *cannot* be compared across instances of a SharedTree. They are *not* stable across sessions/lifetimes of a
2237
- * SharedTree, and *cannot* be persisted (e.g. stored in payloads, uploaded in blobs, etc.). If stable persistence is needed,
2238
- * NodeIdConverter.convertToStableNodeId may be used to return a corresponding UUID that is globally unique and stable.
2239
- * @param override - if supplied, calls to `convertToStableNodeId` using the returned node ID will return the override instead of
2240
- * the UUID. Calls to `generateNodeId` with the same override always return the same ID. Performance note: passing an override string
2241
- * incurs a storage cost that is significantly higher that a node ID without one, and should be avoided if possible.
2242
- */
2243
- generateNodeId(override?: string): NodeId;
2244
- /**
2245
- * Given a NodeId, returns the corresponding stable ID or throws if the supplied node ID was not generated with this tree (`NodeId`s
2246
- * may not be used across SharedTree instances, see `generateNodeId` for more).
2247
- * The returned value will be a UUID, unless the creation of `id` used an override string (see `generateNodeId` for more).
2248
- * The result is safe to persist and re-use across `SharedTree` instances, unlike `NodeId`.
2249
- */
2250
- convertToStableNodeId(id: NodeId): StableNodeId;
2251
- /**
2252
- * Given a NodeId, attempt to return the corresponding stable ID.
2253
- * The returned value will be a UUID, unless the creation of `id` used an override string (see `generateNodeId` for more).
2254
- * The returned stable ID is undefined if `id` was never created with this SharedTree. If a stable ID is returned, this does not imply
2255
- * that there is a node with `id` in the current revision of the tree, only that `id` was at some point generated by some instance of
2256
- * this tree.
2257
- */
2258
- tryConvertToStableNodeId(id: NodeId): StableNodeId | undefined;
2259
- /**
2260
- * Given a stable ID, return the corresponding NodeId or throws if the supplied stable ID was never generated with this tree, either
2261
- * as a UUID corresponding to a `NodeId` or as an override passed to `generateNodeId`.
2262
- * If a stable ID is returned, this does not imply that there is a node with `id` in the current revision of the tree, only that
2263
- * `id` was at some point generated by an instance of this SharedTree.
2264
- */
2265
- convertToNodeId(id: StableNodeId): NodeId;
2266
- /**
2267
- * Given a stable ID, return the corresponding NodeId or return undefined if the supplied stable ID was never generated with this tree,
2268
- * either as a UUID corresponding to a `NodeId` or as an override passed to `generateNodeId`.
2269
- * If a stable ID is returned, this does not imply that there is a node with `id` in the current revision of the tree, only that
2270
- * `id` was at some point generated by an instance of this SharedTree.
2271
- */
2272
- tryConvertToNodeId(id: StableNodeId): NodeId | undefined;
2273
- /**
2274
- * Returns the attribution ID associated with the SharedTree that generated the given node ID. This is generally only useful for clients
2275
- * with a write format of 0.1.1 or greater since older clients cannot be given an attribution ID and will always use the default
2276
- * `attributionId` of the tree.
2277
- */
2278
- attributeNodeId(id: NodeId): AttributionId;
2279
- /**
2280
- * @returns the edit history of the tree.
2281
- */
2282
- get edits(): OrderedEditSet<InternalizedChange>;
2283
- /**
2284
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}
2285
- */
2286
- summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
2287
- /**
2288
- * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
2289
- */
2290
- getAttachSummary(fullTree?: boolean | undefined, trackState?: boolean | undefined, telemetryContext?: ITelemetryContext | undefined): ISummaryTreeWithStats;
2291
- /**
2292
- * Saves this SharedTree into a serialized summary. This is used for testing.
2293
- *
2294
- * @param summarizer - Optional summarizer to use. If not passed in, SharedTree's summarizer is used.
2295
- */
2296
- saveSerializedSummary(options?: {
2297
- serializer?: IFluidSerializer;
2298
- }): string;
2299
- /**
2300
- * Initialize shared tree with a serialized summary. This is used for testing.
2301
- * @returns Statistics about the loaded summary.
2302
- */
2303
- loadSerializedSummary(blobData: string): ITelemetryBaseProperties;
2304
- /**
2305
- * Saves this SharedTree into a deserialized summary.
2306
- */
2307
- saveSummary(): SharedTreeSummaryBase;
2308
- /**
2309
- * Generates a SharedTree summary for the current state of the tree.
2310
- * Will never be called when local edits are present.
2311
- */
2312
- private generateSummary;
2313
- /**
2314
- * Initialize shared tree with a deserialized summary.
2315
- */
2316
- loadSummary(summary: SharedTreeSummaryBase): void;
2317
- private static eventFromEditResult;
2318
- /**
2319
- * Initializes a new `EditLog` and `CachingLogViewer` on this `SharedTree`, replacing and disposing of any previously existing ones.
2320
- * @returns the initialized values (this is mostly to keep the constructor happy)
2321
- */
2322
- private initializeNewEditLogFromSummary;
2323
- /**
2324
- * Compares this shared tree to another for equality. Should only be used for internal correctness testing.
2325
- *
2326
- * Equality means that the histories as captured by the EditLogs are equivalent.
2327
- *
2328
- * Equality does not include:
2329
- *
2330
- * - if an edit is open
2331
- *
2332
- * - the shared tree's id
2333
- *
2334
- * - local vs sequenced status of edits
2335
- *
2336
- * - registered event listeners
2337
- *
2338
- * - state of caches
2339
- */
2340
- equals(sharedTree: SharedTree): boolean;
2341
- /**
2342
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
2343
- */
2344
- protected loadCore(storage: IChannelStorageService): Promise<void>;
2345
- /**
2346
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}
2347
- */
2348
- protected processCore(message: unknown, local: boolean): void;
2349
- /**
2350
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}
2351
- */
2352
- protected registerCore(): void;
2353
- /**
2354
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}
2355
- */
2356
- protected onDisconnect(): void;
2357
- /**
2358
- * Parses a sequenced edit. This is only invoked for ops with version matching the current `writeFormat`.
2359
- */
2360
- private parseSequencedEdit;
2361
- private processSequencedEdit;
2362
- /**
2363
- * Updates SharedTree to the provided version if the version is a valid write version newer than the current version.
2364
- * @param version - The version to update to.
2365
- */
2366
- private processVersionUpdate;
2367
- private upgradeFrom_0_0_2_to_0_1_1;
2368
- /**
2369
- * Applies a set of changes to this tree. The result will be reflected in `SharedTree.currentView`.
2370
- * This method does not allow for snapshot isolation, as the changes are always applied to the most recent revision.
2371
- * If it is desireable to read from and apply changes to a fixed view that does not change when remote changes arrive, `Checkout`
2372
- * should be used instead.
2373
- */
2374
- applyEdit(...changes: readonly Change[]): Edit<InternalizedChange>;
2375
- applyEdit(changes: readonly Change[]): Edit<InternalizedChange>;
2376
- /**
2377
- * Merges `edits` from `other` into this SharedTree.
2378
- * @param other - Tree containing the edits that should be applied to this one.
2379
- * @param edits - Iterable of edits from `other` to apply.
2380
- * @param stableIdRemapper - Optional remapper to translate stable identities from `other` into stable identities on this tree.
2381
- * Any references that `other` contains to a stable id `foo` will be replaced with references to the id `stableIdRemapper(foo)`.
2382
- *
2383
- * Payloads on the edits are left intact.
2384
- * @returns a list containing `EditId`s for all applied edits.
2385
- */
2386
- mergeEditsFrom(other: SharedTree, edits: Iterable<Edit<InternalizedChange>>, stableIdRemapper?: (id: StableNodeId) => StableNodeId): EditId[];
2387
- /**
2388
- * Applies a set of internal changes to this tree. The result will be reflected in `SharedTree.currentView`.
2389
- * External users should use one of the more specialized functions, like `applyEdit` which handles constructing the actual `Edit`
2390
- * and uses public Change types.
2391
- * This is exposed for internal use only.
2392
- */
2393
- applyEditInternal(editOrChanges: Edit<ChangeInternal> | readonly ChangeInternal[]): Edit<ChangeInternal>;
2394
- /**
2395
- * Converts a public Change type to an internal representation.
2396
- * This is exposed for internal use only.
2397
- */
2398
- internalizeChange(change: Change): ChangeInternal;
2399
- private applyEditLocally;
2400
- /**
2401
- * Reverts a previous edit by applying a new edit containing the inverse of the original edit's changes.
2402
- * @param editId - the edit to revert
2403
- * @returns the id of the new edit, or undefined if the original edit could not be inverted given the current tree state.
2404
- */
2405
- revert(editId: EditId): EditId | undefined;
2406
- /**
2407
- * Revert the given changes
2408
- * @param changes - the changes to revert
2409
- * @param before - the revision view before the changes were originally applied
2410
- * @returns the inverse of `changes` or undefined if the changes could not be inverted for the given tree state.
2411
- */
2412
- revertChanges(changes: readonly InternalizedChange[], before: RevisionView): ChangeInternal[] | undefined;
2413
- /**
2414
- * Submits an edit by the local client to the runtime.
2415
- */
2416
- private submitEditOp;
2417
- /** A type-safe `submitLocalMessage` wrapper to enforce op format */
2418
- private submitOp;
2419
- getRuntime(): IFluidDataStoreRuntime;
2420
- /**
2421
- * "Pending local state" refers to ops submitted to the runtime that have not yet been acked.
2422
- * When closing a container, hosts have the option to stash this pending local state somewhere to be reapplied
2423
- * later (to avoid data loss).
2424
- * If a host then loads a container using that stashed state, this function is called for each stashed op, and is expected to:
2425
- * Update this DDS to reflect that state locally, and submit the op to do that.
2426
- *
2427
- * @param content - op to apply locally.
2428
- */
2429
- protected applyStashedOp(op: unknown): void;
2430
- protected reSubmitCore(op: unknown, localOpMetadata?: StashedLocalOpMetadata): void;
2431
- private changeWriteFormat;
2432
- /**
2433
- * Interns all Definitions and TraitLabel_s referenced by the provided edit.
2434
- *
2435
- * Clients must have consensus on the interned values to guarantee the interned ID is valid.
2436
- */
2437
- private internStringsFromEdit;
2438
- }
2439
-
2440
- /**
2441
- * The write format and associated options used to construct a `SharedTree`
2442
- * @alpha
2443
- */
2444
- export declare type SharedTreeArgs<WF extends WriteFormat = WriteFormat> = [writeFormat: WF, options?: SharedTreeOptions<WF>];
2445
-
2446
- /**
2447
- * Assertion failures in SharedTree will throw an exception containing this value as an `errorType`. The Fluid runtime propagates this field
2448
- * in its handlings of errors thrown by containers. See
2449
- * https://github.com/microsoft/FluidFramework/blob/main/packages/loader/container-utils/src/error.ts
2450
- *
2451
- * Exporting this enables users to safely filter telemetry handling of errors based on their type.
2452
- * @internal
2453
- */
2454
- export declare const sharedTreeAssertionErrorType = "SharedTreeAssertion";
2455
-
2456
- /**
2457
- * Configuration options for SharedTree that are independent of write format versions.
2458
- * @alpha
2459
- */
2460
- export declare interface SharedTreeBaseOptions {
2461
- /**
2462
- * The target number of sequenced edits that the tree will try to store in memory.
2463
- * Depending on eviction frequency and the collaboration window, there can be more edits in memory at a given time.
2464
- * Edits in the collaboration window are not evicted.
2465
- *
2466
- * The size is set to infinity by default, meaning that all edits in session are kept within memory.
2467
- */
2468
- inMemoryHistorySize?: number;
2469
- /**
2470
- * The rate at which edits are evicted from memory. This is a factor of the inMemoryHistorySize.
2471
- * For example, with the default frequency of inMemoryHistorySize * 2 and a size of 10, the log will evict once it reaches 20 sequenced edits
2472
- * down to 10 edits, also keeping any that are still in the collaboration window.
2473
- */
2474
- editEvictionFrequency?: number;
2475
- }
2476
-
2477
- /**
2478
- * An event emitted by a `SharedTree` for diagnostic purposes.
2479
- * See {@link ISharedTreeEvents} for event argument information.
2480
- * @internal
2481
- */
2482
- export declare enum SharedTreeDiagnosticEvent {
2483
- /**
2484
- * A single catch up blob has been uploaded.
2485
- */
2486
- CatchUpBlobUploaded = "uploadedCatchUpBlob",
2487
- /**
2488
- * An edit chunk blob has been uploaded. This includes catchup blobs.
2489
- */
2490
- EditChunkUploaded = "uploadedEditChunk",
2491
- /**
2492
- * A valid edit (local or remote) has been applied.
2493
- * Passed the EditId of the applied edit.
2494
- * Note that this may be called multiple times, due to concurrent edits causing reordering,
2495
- * and/or due to not caching the output of every edit.
2496
- */
2497
- AppliedEdit = "appliedEdit",
2498
- /**
2499
- * An invalid edit (local or remote) has been dropped.
2500
- * Passed the EditId of the dropped edit.
2501
- * Note that this may be called multiple times, due to concurrent edits causing reordering,
2502
- * and/or due to not caching the output of every edit.
2503
- */
2504
- DroppedInvalidEdit = "droppedInvalidEdit",
2505
- /**
2506
- * A malformed edit (local or remote) has been dropped.
2507
- * Passed the EditId of the dropped edit.
2508
- * Note that this may be called multiple times, due to concurrent edits causing reordering,
2509
- * and/or due to not caching the output of every edit.
2510
- */
2511
- DroppedMalformedEdit = "droppedMalformedEdit",
2512
- /**
2513
- * A history chunk has been received that does not have a corresponding edit chunk on the edit log.
2514
- */
2515
- UnexpectedHistoryChunk = "unexpectedHistoryChunk",
2516
- /**
2517
- * The current write format changed, either because an old summary was loaded or an update op was successfully processed.
2518
- * This event is emitted with the new version as an argument.
2519
- */
2520
- WriteVersionChanged = "writeVersionChanged"
2521
- }
2522
-
2523
- /**
2524
- * An event emitted by a `SharedTree` to indicate a state change. See {@link ISharedTreeEvents} for event
2525
- * argument information.
2526
- * @alpha
2527
- */
2528
- export declare enum SharedTreeEvent {
2529
- /**
2530
- * Note: It is _strongly_ recommended that you avoid this API and instead use the `viewChange` event
2531
- * on a {@link Checkout}. See "Use a Checkout" in the README for an example of how to create a
2532
- * checkout of a tree. The Checkout API is generally more user friendly and also avoids a class
2533
- * of bugs involving the interleaving of remote and local edits that can arise when querying the
2534
- * tree's {@link LogViewer} directly.
2535
- *
2536
- * An edit has been committed to the log.
2537
- * This happens when either:
2538
- *
2539
- * 1. A locally generated edit is added to the log.
2540
- *
2541
- * 2. A remotely generated edit is added to the log.
2542
- *
2543
- * Note that, for locally generated edits, this event will not be emitted again when that edit is sequenced.
2544
- * Passed the EditId of the committed edit, i.e. supports callbacks of type {@link EditCommittedHandler}.
2545
- */
2546
- EditCommitted = "committedEdit",
2547
- /**
2548
- * Note: It is _strongly_ recommended that you avoid this API and instead use the `viewChange` event
2549
- * on a {@link Checkout}. See "Use a Checkout" in the README for an example of how to create a
2550
- * checkout of a tree. The Checkout API is generally more user friendly and also avoids a class
2551
- * of bugs involving the interleaving of remote and local edits that can arise when querying the
2552
- * tree's {@link LogViewer} directly.
2553
- *
2554
- * A sequenced edit has been applied.
2555
- * This includes local edits though the callback is only invoked once the sequenced version is received.
2556
- * For edits that were local (see {@link SequencedEditAppliedEventArguments.wasLocal}, this callback will only
2557
- * be called once.
2558
- * For non-local edits, it may be called multiple times: the number of calls and when they occur depends on caching
2559
- * and is an implementation detail.
2560
- * Supports callbacks of type {@link SequencedEditAppliedHandler}.
2561
- */
2562
- SequencedEditApplied = "sequencedEditApplied"
2563
- }
2564
-
2565
- /**
2566
- * Factory for SharedTree.
2567
- * Includes history in the summary.
2568
- * @alpha
2569
- */
2570
- export declare class SharedTreeFactory implements IChannelFactory {
2571
- /**
2572
- * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory."type"}
2573
- */
2574
- static Type: string;
2575
- /**
2576
- * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory.attributes}
2577
- */
2578
- static Attributes: IChannelAttributes;
2579
- private readonly args;
2580
- /**
2581
- * Get a factory for SharedTree to register with the data store.
2582
- * @param writeFormat - Determines the format version the SharedTree will write ops and summaries in. See [the write format
2583
- * documentation](../docs/Write-Format.md) for more information.
2584
- * @param options - Configuration options for this tree
2585
- * @returns A factory that creates `SharedTree`s and loads them from storage.
2586
- */
2587
- constructor(...args: SharedTreeArgs);
2588
- /**
2589
- * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory."type"}
2590
- */
2591
- get type(): string;
2592
- /**
2593
- * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory.attributes}
2594
- */
2595
- get attributes(): IChannelAttributes;
2596
- /**
2597
- * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory.load}
2598
- */
2599
- load(runtime: IFluidDataStoreRuntime, id: string, services: IChannelServices, _channelAttributes: Readonly<IChannelAttributes>): Promise<SharedTree>;
2600
- /**
2601
- * Create a new SharedTree.
2602
- * @param runtime - data store runtime that owns the new SharedTree
2603
- * @param id - optional name for the SharedTree
2604
- */
2605
- create(runtime: IFluidDataStoreRuntime, id: string): SharedTree;
2606
- private createSharedTree;
2607
- }
2608
-
2609
- /**
2610
- * Aggregates and logs telemetry about the success of concurrent edits.
2611
- * @internal
2612
- */
2613
- export declare class SharedTreeMergeHealthTelemetryHeartbeat {
2614
- private heartbeatTimerId;
2615
- private readonly treeData;
2616
- /**
2617
- * Adds a tree to the set of tree to log merge health telemetry for.
2618
- * Noop if such a tree was already in the set.
2619
- * @param tree - The tree to log merge health telemetry for.
2620
- */
2621
- attachTree(tree: SharedTree): void;
2622
- /**
2623
- * Removes a tree from the set of tree to log merge health telemetry for.
2624
- * Noop if such a tree was never in the set.
2625
- * @param tree - The tree to stop logging merge health telemetry for.
2626
- */
2627
- detachTree(tree: SharedTree): void;
2628
- /**
2629
- * Exposes the aggregated statistics about merge health for the given tree.
2630
- * @param tree - The tree to get stats for.
2631
- * @returns Aggregated statistics about merge health for the given tree.
2632
- */
2633
- getStats(tree: SharedTree): MergeHealthStats;
2634
- /**
2635
- * Removes all trees from the set of tree to log merge health telemetry for.
2636
- */
2637
- detachAllTrees(): void;
2638
- /**
2639
- * Resets the aggregated merge health data for the given tree.
2640
- * @param tree - The tree to reset the merge health data for.
2641
- */
2642
- resetTreeData(tree: SharedTree): void;
2643
- /**
2644
- * Enables the regular telemetry logging of merge health data.
2645
- * The first message will be sent after `interval` milliseconds. See {@link SharedTreeMergeHealthTelemetryHeartbeat.flushHeartbeat} for
2646
- * immediate logging.
2647
- * @param interval - The amount of time in milliseconds between log messages.
2648
- */
2649
- startHeartbeat(interval?: number): void;
2650
- /**
2651
- * Disables the regular telemetry logging of merge health data.
2652
- */
2653
- stopHeartbeat(): void;
2654
- /**
2655
- * Sends all collected merge health data and resets the aggregated state.
2656
- */
2657
- flushHeartbeat(): void;
2658
- /**
2659
- * Resets all aggregated state.
2660
- */
2661
- clearData(): void;
2662
- /**
2663
- * Receives SequencedEditApplied events from trees.
2664
- */
2665
- private readonly sequencedEditHandler;
2666
- /**
2667
- * Logs the accumulated merge health data to each tree's designated logger.
2668
- */
2669
- private readonly logHeartbeat;
2670
- }
2671
-
2672
- /**
2673
- * The type of shared tree options for a given write format
2674
- * @alpha
2675
- */
2676
- export declare type SharedTreeOptions<WF extends WriteFormat, HistoryCompatibility extends 'Forwards' | 'None' = 'Forwards'> = SharedTreeBaseOptions & Omit<WF extends WriteFormat.v0_0_2 ? SharedTreeOptions_0_0_2 : WF extends WriteFormat.v0_1_1 ? SharedTreeOptions_0_1_1 : never, HistoryCompatibility extends 'Forwards' ? 'summarizeHistory' : never>;
2677
-
2678
- /**
2679
- * Configuration options for a SharedTree with write format 0.0.2
2680
- * @alpha
2681
- */
2682
- export declare interface SharedTreeOptions_0_0_2 {
2683
- /**
2684
- * Determines if the history is included in summaries.
2685
- *
2686
- * Warning: enabling history summarization incurs a permanent cost in the document. It is not possible to disable history summarization
2687
- * later once it has been enabled, and thus the history cannot be safely deleted.
2688
- *
2689
- * On 0.1.1 documents, due to current code limitations, this parameter is only impactful for newly created documents.
2690
- * `SharedTree`s which load existing documents will summarize history if and only if the loaded summary included history.
2691
- *
2692
- * The technical limitations here relate to clients with mixed versions collaborating.
2693
- * In the future we may allow modification of whether or not a particular document saves history, but only via a consensus mechanism.
2694
- * See the skipped test in SharedTreeFuzzTests.ts for more details on this issue.
2695
- * See docs/Breaking-Change-Migration for more details on the consensus scheme.
2696
- */
2697
- summarizeHistory?: boolean;
2698
- }
2699
-
2700
- /**
2701
- * Configuration options for a SharedTree with write format 0.1.1
2702
- * @alpha
2703
- */
2704
- export declare interface SharedTreeOptions_0_1_1 {
2705
- /**
2706
- * Determines if the history is included in summaries and if edit chunks are uploaded when they are full.
2707
- *
2708
- * Warning: enabling history summarization incurs a permanent cost in the document. It is not possible to disable history summarization
2709
- * later once it has been enabled, and thus the history cannot be safely deleted.
2710
- *
2711
- * On 0.1.1 documents, due to current code limitations, this parameter is only impactful for newly created documents.
2712
- * `SharedTree`s which load existing documents will summarize history if and only if the loaded summary included history.
2713
- *
2714
- * The technical limitations here relate to clients with mixed versions collaborating.
2715
- * In the future we may allow modification of whether or not a particular document saves history, but only via a consensus mechanism.
2716
- * See the skipped test in SharedTreeFuzzTests.ts for more details on this issue.
2717
- * See docs/Breaking-Change-Migration for more details on the consensus scheme.
2718
- */
2719
- summarizeHistory?: false | {
2720
- uploadEditChunks: boolean;
2721
- };
2722
- /** a UUID that identifies the user of this tree; all node IDs generated by this tree will be associated with this UUID */
2723
- attributionId?: AttributionId;
2724
- }
2725
-
2726
- /**
2727
- * SharedTreeShim is loaded by clients that join after the migration completes, and holds the new SharedTree.
2728
- *
2729
- * @remarks
2730
- *
2731
- * Its sole responsibility should be to drop v1 & migrate ops. It should not be responsible for any other migration
2732
- * logic. This should make the classes easier to reason about.
2733
- * about.
2734
- *
2735
- * @internal
2736
- */
2737
- export declare class SharedTreeShim implements IShim {
2738
- readonly id: string;
2739
- readonly runtime: IFluidDataStoreRuntime;
2740
- readonly sharedTreeFactory: IChannelFactory;
2741
- constructor(id: string, runtime: IFluidDataStoreRuntime, sharedTreeFactory: IChannelFactory);
2742
- private readonly newTreeShimDeltaHandler;
2743
- private services?;
2744
- private _currentTree?;
2745
- get currentTree(): ITree;
2746
- get attributes(): IChannelAttributes;
2747
- handle: IFluidHandle<SharedTreeShim>;
2748
- get IFluidLoadable(): IFluidLoadable;
2749
- getAttachSummary(fullTree?: boolean | undefined, trackState?: boolean | undefined, telemetryContext?: ITelemetryContext | undefined): ISummaryTreeWithStats;
2750
- summarize(fullTree?: boolean | undefined, trackState?: boolean | undefined, telemetryContext?: ITelemetryContext | undefined, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext | undefined): Promise<ISummaryTreeWithStats>;
2751
- isAttached(): boolean;
2752
- connect(services: IChannelServices): void;
2753
- load(services: IChannelServices): Promise<void>;
2754
- create(): void;
2755
- private generateShimServicesOnce;
2756
- getGCData(fullGC?: boolean | undefined): IGarbageCollectionData;
2757
- }
2758
-
2759
- /**
2760
- * {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedTreeShim}.
2761
- *
2762
- * Creates the migration shim that allows a migration from legacy shared tree to shared tree.
2763
- * Note: There may be a need for 3 different factories for different parts of the migration.
2764
- * That or three different shims. Potentially we can just do 2 as 2 and 3 can be combined.
2765
- * 1. pre-migration
2766
- * 2. after a summary has been generated but there may still be potential v1 ops
2767
- * 3. post-migration after a summary has been generated and the msn has moved far enough forward for only v2 ops
2768
- *
2769
- * @sealed
2770
- * @internal
2771
- */
2772
- export declare class SharedTreeShimFactory implements IChannelFactory {
2773
- private readonly factory;
2774
- constructor(factory: IChannelFactory);
2775
- /**
2776
- * Can only load the new SharedTree - this allows our snapshots to be simple. We do not have to consider any new
2777
- * unique snapshot formats and how to load from them.
2778
- *
2779
- * {@link @fluidframework/datastore-definitions#IChannelFactory."type"}
2780
- */
2781
- get type(): string;
2782
- /**
2783
- * Should be the new SharedTree attributes - this should indicate what type of tree snapshot we are expecting or
2784
- * are capable of loading from.
2785
- *
2786
- * {@link @fluidframework/datastore-definitions#IChannelFactory.attributes}
2787
- */
2788
- get attributes(): IChannelAttributes;
2789
- /**
2790
- * {@link @fluidframework/datastore-definitions#IChannelFactory.load}
2791
- *
2792
- * Should be loading the SharedTreeShim from a new SharedTree snapshot only.
2793
- */
2794
- load(runtime: IFluidDataStoreRuntime, id: string, services: IChannelServices, attributes: IChannelAttributes): Promise<SharedTreeShim>;
2795
- /**
2796
- * {@link @fluidframework/datastore-definitions#IChannelFactory.create}
2797
- *
2798
- * Should be only creating the SharedTreeShim, which will only generate a new SharedTree snapshot. That way we do
2799
- * not have the capability of accidentally creating a LegacySharedTree snapshot.
2800
- */
2801
- create(runtime: IFluidDataStoreRuntime, id: string): SharedTreeShim;
2802
- }
2803
-
2804
- /**
2805
- * The minimal information on a SharedTree summary. Contains the summary format version.
2806
- * @alpha
2807
- */
2808
- export declare interface SharedTreeSummaryBase {
2809
- /**
2810
- * Field on summary under which version is stored.
2811
- */
2812
- readonly version: WriteFormat;
2813
- }
2814
-
2815
- /**
2816
- * Defines a place relative to sibling.
2817
- * The "outside" of a trait is the `undefined` sibling,
2818
- * so After `undefined` is the beginning of the trait, and before `undefined` is the end.
2819
- *
2820
- * For this purpose, traits look like:
2821
- *
2822
- * `{undefined} - {Node 0} - {Node 1} - ... - {Node N} - {undefined}`
2823
- *
2824
- * Each `{value}` in the diagram is a possible sibling, which is either a Node or undefined.
2825
- * Each `-` in the above diagram is a `Place`, and can be describe as being `After` a particular `{sibling}` or `Before` it.
2826
- * This means that `After` `{undefined}` means the same `Place` as before the first node
2827
- * and `Before` `{undefined}` means the `Place` after the last Node.
2828
- *
2829
- * Each place can be specified, (aka 'anchored') in two ways (relative to the sibling before or after):
2830
- * the choice of which way to anchor a place only matters when the kept across an edit, and thus evaluated in multiple contexts where the
2831
- * two place description may no longer evaluate to the same place.
2832
- * @alpha
2833
- */
2834
- export declare enum Side {
2835
- Before = 0,
2836
- After = 1
2837
- }
2838
-
2839
- /**
2840
- * Globally unique node identifier.
2841
- * Uniquely identifies a node within and across documents. Can be used across SharedTree instances.
2842
- * @alpha
2843
- */
2844
- export declare type StableNodeId = string & {
2845
- readonly StableNodeId: 'a0843b38-699d-4bb2-aa7a-16c502a71151';
2846
- };
2847
-
2848
- /**
2849
- * A location in a trait.
2850
- * This is NOT the location of a node, but a location where a node could be inserted:
2851
- * it is next to a sibling or at one end of the trait.
2852
- *
2853
- * To be well formed, either `sibling` or `trait` must be defined, but not both.
2854
- *
2855
- * Any given insertion location can be described by two `StablePlace` objects, one with `Side.After` and one with `Side.Before`.
2856
- * For example, in a trait containing two strings "foo" and "bar", there are 6 different `StablePlace`s corresponding to 3 locations in the
2857
- * trait a new node could be inserted: at the start, before "foo", after "foo", before "bar", after "bar", and at the end.
2858
- * Neither of the two ways to specify the same location are considered to be after each other.
2859
- *
2860
- * The anchor (`referenceSibling` or `referenceTrait`) used for a particular `StablePlace` can have an impact in collaborative scenarios.
2861
- *
2862
- * `StablePlace` objects can be conveniently constructed with the helper methods exported on a constant of the same name.
2863
- *
2864
- * @example
2865
- *
2866
- * ```typescript
2867
- * StablePlace.before(node)
2868
- * StablePlace.atStartOf(trait)
2869
- * ```
2870
- * @alpha
2871
- */
2872
- export declare interface StablePlace {
2873
- /**
2874
- * Where this StablePlace is relative to the sibling (if specified), or an end of the trait (if no sibling specified).
2875
- * If 'After' and there is no sibling, this StablePlace is after the front of the trait.
2876
- * If 'Before' and there is no sibling, this StablePlace is before the back of the trait.
2877
- */
2878
- readonly side: Side;
2879
- /**
2880
- * The sibling to which this 'StablePlace' is anchored (by 'side').
2881
- * If specified, referenceTrait must be unspecified.
2882
- */
2883
- readonly referenceSibling?: NodeId;
2884
- /**
2885
- * The trait to which this 'StablePlace' is anchored (by 'side').
2886
- * If specified, referenceSibling must be unspecified.
2887
- */
2888
- readonly referenceTrait?: TraitLocation;
2889
- }
2890
-
2891
- /**
2892
- * @alpha
2893
- */
2894
- export declare const StablePlace: {
2895
- /**
2896
- * @returns The location directly before `node`.
2897
- */
2898
- before: (node: NodeData<NodeId> | NodeId) => StablePlace;
2899
- /**
2900
- * @returns The location directly after `node`.
2901
- */
2902
- after: (node: NodeData<NodeId> | NodeId) => StablePlace;
2903
- /**
2904
- * @returns The location at the start of `trait`.
2905
- */
2906
- atStartOf: (trait: TraitLocation) => StablePlace;
2907
- /**
2908
- * @returns The location at the end of `trait`.
2909
- */
2910
- atEndOf: (trait: TraitLocation) => StablePlace;
2911
- };
2912
-
2913
- /**
2914
- * {@inheritdoc (StablePlace:interface) }
2915
- * @alpha
2916
- */
2917
- export declare interface StablePlaceInternal extends Omit<StablePlaceInternal_0_0_2, 'referenceSibling' | 'referenceTrait'> {
2918
- /**
2919
- * {@inheritdoc (StablePlace:interface).referenceSibling }
2920
- */
2921
- readonly referenceSibling?: NodeId;
2922
- /**
2923
- * {@inheritdoc (StablePlace:interface).referenceTrait }
2924
- */
2925
- readonly referenceTrait?: TraitLocationInternal;
2926
- }
2927
-
2928
- /**
2929
- * @alpha
2930
- */
2931
- export declare const StablePlaceInternal: {
2932
- /**
2933
- * @returns The location directly before `node`.
2934
- */
2935
- before: (node: NodeData<NodeId> | NodeId) => StablePlaceInternal;
2936
- /**
2937
- * @returns The location directly after `node`.
2938
- */
2939
- after: (node: NodeData<NodeId> | NodeId) => StablePlaceInternal;
2940
- /**
2941
- * @returns The location at the start of `trait`.
2942
- */
2943
- atStartOf: (trait: TraitLocationInternal) => StablePlaceInternal;
2944
- /**
2945
- * @returns The location at the end of `trait`.
2946
- */
2947
- atEndOf: (trait: TraitLocationInternal) => StablePlaceInternal;
2948
- };
2949
-
2950
- /**
2951
- * {@inheritdoc (StablePlace:interface) }
2952
- * @alpha
2953
- */
2954
- export declare interface StablePlaceInternal_0_0_2 {
2955
- /**
2956
- * {@inheritdoc (StablePlace:interface).side }
2957
- */
2958
- readonly side: Side;
2959
- /**
2960
- * {@inheritdoc (StablePlace:interface).referenceSibling }
2961
- */
2962
- readonly referenceSibling?: StableNodeId;
2963
- /**
2964
- * {@inheritdoc (StablePlace:interface).referenceTrait }
2965
- */
2966
- readonly referenceTrait?: TraitLocationInternal_0_0_2;
2967
- }
2968
-
2969
- /**
2970
- * Specifies the range of nodes from `start` to `end` within a trait.
2971
- * Valid iff start and end are valid and are within the same trait and the start does not occur after the end in the trait.
2972
- *
2973
- * See {@link (StablePlace:interface)} for what it means for a place to be "after" another place.
2974
- *
2975
- * @remarks
2976
- *
2977
- * `StableRange` objects can be conveniently constructed with the helper methods exported on a constant of the same name.
2978
- *
2979
- * @example
2980
- *
2981
- * ```typescript
2982
- * StableRange.from(StablePlace.before(startNode)).to(StablePlace.after(endNode))
2983
- * ```
2984
- * @alpha
2985
- */
2986
- export declare interface StableRange {
2987
- readonly start: StablePlace;
2988
- readonly end: StablePlace;
2989
- }
2990
-
2991
- /**
2992
- * @alpha
2993
- */
2994
- export declare const StableRange: {
2995
- /**
2996
- * Factory for producing a `StableRange` from a start `StablePlace` to an end `StablePlace`.
2997
- *
2998
- * @example
2999
- *
3000
- * ```typescript
3001
- * StableRange.from(StablePlace.before(startNode)).to(StablePlace.after(endNode))
3002
- * ```
3003
- */
3004
- from: (start: StablePlace) => {
3005
- to: (end: StablePlace) => StableRange;
3006
- };
3007
- /**
3008
- * @returns a `StableRange` which contains only the provided `node`.
3009
- * Both the start and end `StablePlace` objects used to anchor this `StableRange` are in terms of the passed in node.
3010
- */
3011
- only: (node: NodeData<NodeId> | NodeId) => StableRange;
3012
- /**
3013
- * @returns a `StableRange` which contains everything in the trait.
3014
- * This is anchored using the provided `trait`, and is independent of the actual contents of the trait:
3015
- * it does not use sibling anchoring.
3016
- */
3017
- all: (trait: TraitLocation) => StableRange;
3018
- };
3019
-
3020
- /**
3021
- * {@inheritdoc (StableRange:interface) }
3022
- * @alpha
3023
- */
3024
- export declare interface StableRangeInternal {
3025
- /** {@inheritdoc (StableRange:interface).start } */
3026
- readonly start: StablePlaceInternal;
3027
- /** {@inheritdoc (StableRange:interface).end } */
3028
- readonly end: StablePlaceInternal;
3029
- }
3030
-
3031
- /**
3032
- * @alpha
3033
- */
3034
- export declare const StableRangeInternal: {
3035
- /**
3036
- * Factory for producing a `StableRange` from a start `StablePlace` to an end `StablePlace`.
3037
- *
3038
- * @example
3039
- *
3040
- * ```typescript
3041
- * StableRange.from(StablePlace.before(startNode)).to(StablePlace.after(endNode))
3042
- * ```
3043
- */
3044
- from: (start: StablePlaceInternal) => {
3045
- to: (end: StablePlaceInternal) => StableRangeInternal;
3046
- };
3047
- /**
3048
- * @returns a `StableRange` which contains only the provided `node`.
3049
- * Both the start and end `StablePlace` objects used to anchor this `StableRange` are in terms of the passed in node.
3050
- */
3051
- only: (node: NodeData<NodeId> | NodeId) => StableRangeInternal;
3052
- /**
3053
- * @returns a `StableRange` which contains everything in the trait.
3054
- * This is anchored using the provided `trait`, and is independent of the actual contents of the trait:
3055
- * it does not use sibling anchoring.
3056
- */
3057
- all: (trait: TraitLocationInternal) => StableRangeInternal;
3058
- };
3059
-
3060
- /**
3061
- * {@inheritdoc (StableRange:interface) }
3062
- * @alpha
3063
- */
3064
- export declare interface StableRangeInternal_0_0_2 {
3065
- /** {@inheritdoc (StableRange:interface).start } */
3066
- readonly start: StablePlaceInternal_0_0_2;
3067
- /** {@inheritdoc (StableRange:interface).end } */
3068
- readonly end: StablePlaceInternal_0_0_2;
3069
- }
3070
-
3071
- /**
3072
- * Contains information resulting from processing stashed shared tree ops
3073
- * @alpha
3074
- */
3075
- export declare interface StashedLocalOpMetadata {
3076
- /** A modified version of the edit in an edit op that should be resubmitted rather than the original edit */
3077
- transformedEdit?: Edit<ChangeInternal>;
3078
- }
3079
-
3080
- /**
3081
- * Interns strings as integers.
3082
- * @internal
3083
- */
3084
- export declare interface StringInterner {
3085
- getInternedId(input: string): InternedStringId | undefined;
3086
- getString(internedId: number): string;
3087
- getSerializable(): readonly string[];
3088
- }
3089
-
3090
- /**
3091
- * The state of a transaction that has not encountered an error.
3092
- * @alpha
3093
- */
3094
- export declare interface SucceedingTransactionState {
3095
- /**
3096
- * The current status of the transaction.
3097
- */
3098
- readonly status: EditStatus.Applied;
3099
- /**
3100
- * The view reflecting the latest applied change.
3101
- */
3102
- readonly view: TransactionView;
3103
- /**
3104
- * The applied changes so far.
3105
- */
3106
- readonly changes: readonly ChangeInternal[];
3107
- /**
3108
- * The editing steps applied so far.
3109
- */
3110
- readonly steps: readonly ReconciliationChange[];
3111
- }
3112
-
3113
- /**
3114
- * Definition.
3115
- * A full (Uuid) persistable label for a trait.
3116
- * @alpha
3117
- */
3118
- export declare type TraitLabel = UuidString & {
3119
- readonly TraitLabel: '613826ed-49cc-4df3-b2b8-bfc6866af8e3';
3120
- };
3121
-
3122
- /**
3123
- * Specifies the location of a trait (a labeled sequence of nodes) within the tree.
3124
- * @alpha
3125
- */
3126
- export declare interface TraitLocation {
3127
- readonly parent: NodeId;
3128
- readonly label: TraitLabel;
3129
- }
3130
-
3131
- /**
3132
- * Specifies the location of a trait (a labeled sequence of nodes) within the tree.
3133
- * @alpha
3134
- */
3135
- export declare interface TraitLocationInternal extends Omit<TraitLocationInternal_0_0_2, 'parent'> {
3136
- readonly parent: NodeId;
3137
- }
3138
-
3139
- /**
3140
- * Specifies the location of a trait (a labeled sequence of nodes) within the tree.
3141
- * @alpha
3142
- */
3143
- export declare interface TraitLocationInternal_0_0_2 {
3144
- readonly parent: StableNodeId;
3145
- readonly label: TraitLabel;
3146
- }
3147
-
3148
- /**
3149
- * Json compatible map as object.
3150
- * Keys are TraitLabels,
3151
- * Values are the content of the trait specified by the key.
3152
- * @alpha
3153
- */
3154
- export declare interface TraitMap<TChild> {
3155
- readonly [key: string]: TreeNodeSequence<TChild>;
3156
- }
3157
-
3158
- /**
3159
- * Index of a node within a trait.
3160
- * 0 = first node,
3161
- * 1 = second node,
3162
- * etc.
3163
- * @alpha
3164
- */
3165
- export declare type TraitNodeIndex = number & {
3166
- readonly TraitNodeIndex: unique symbol;
3167
- };
3168
-
3169
- /**
3170
- * Buffers changes to be applied to an isolated view of a `SharedTree` over time before applying them directly to the tree itself as a
3171
- * single edit
3172
- * @alpha
3173
- */
3174
- export declare class Transaction extends TypedEventEmitter<TransactionEvents> {
3175
- readonly tree: SharedTree;
3176
- /** The view of the tree when this transaction was created */
3177
- readonly startingView: TreeView;
3178
- private readonly transaction;
3179
- /**
3180
- * Create a new transaction over the given tree. The tree's `currentView` at this time will become the `startingView` for this
3181
- * transaction.
3182
- * @param tree - the `SharedTree` that this transaction applies changes to
3183
- */
3184
- constructor(tree: SharedTree);
3185
- /**
3186
- * True if this transaction is open, false if it is closed. A transaction may be closed manually via `closeAndApplyEdit()`, or may
3187
- * be automatically closed by a change in this transaction failing to apply (see `applyChange()`).
3188
- */
3189
- get isOpen(): boolean;
3190
- /**
3191
- * The status of the most recently applied change in this transaction
3192
- */
3193
- get status(): EditStatus;
3194
- /**
3195
- * The state of the tree following the most change that was successfully applied. If no changes have been applied, this is the same as
3196
- * `startingView`.
3197
- */
3198
- get currentView(): TreeView;
3199
- /**
3200
- * Attempt to apply a sequence of changes in this transaction. The `currentView` will be updated to reflect the new tree state after all
3201
- * applied changes. If any change fails to apply, the remaining changes will be ignored and this transaction will be automatically
3202
- * closed (see `isOpen`). If this transaction is already closed, this method has no effect. This method will emit a
3203
- * `TransactionEvent.ViewChange` event at most once per call.
3204
- * @param changes - the changes to apply
3205
- * @returns either the `EditStatus` of the given changes or the `EditStatus` of the last change before the transaction was closed
3206
- */
3207
- apply(...changes: readonly Change[]): EditStatus;
3208
- apply(changes: readonly Change[]): EditStatus;
3209
- /**
3210
- * Close this transaction and apply its changes to the `SharedTree`. If this transaction is already closed, this method has no effect.
3211
- */
3212
- closeAndCommit(): void;
3213
- }
3214
-
3215
- /**
3216
- * An event emitted by a `Transaction` to indicate a state change. See {@link TransactionEvents} for event argument information.
3217
- * @alpha
3218
- */
3219
- export declare enum TransactionEvent {
3220
- /**
3221
- * `currentView` has changed from `before` to `after`
3222
- */
3223
- ViewChange = "viewChange"
3224
- }
3225
-
3226
- /**
3227
- * Events which may be emitted by `Transaction`
3228
- * @alpha
3229
- */
3230
- export declare interface TransactionEvents extends IErrorEvent {
3231
- (event: TransactionEvent.ViewChange, listener: (before: TreeView, after: TreeView) => void): any;
3232
- }
3233
-
3234
- /**
3235
- * The failure state of a transaction.
3236
- * @internal
3237
- */
3238
- export declare interface TransactionFailure {
3239
- /**
3240
- * The status indicating the kind of failure encountered.
3241
- */
3242
- readonly status: EditStatus.Invalid | EditStatus.Malformed;
3243
- /**
3244
- * Information about what caused the transaction to fail.
3245
- */
3246
- readonly failure: TransactionInternal.Failure;
3247
- }
3248
-
3249
- /**
3250
- * A mutable transaction for applying sequences of changes to a TreeView.
3251
- * Allows viewing the intermediate states.
3252
- *
3253
- * Contains necessary state to apply changes within an edit to a TreeView.
3254
- *
3255
- * May have any number of changes applied to make up the edit.
3256
- * Use `close` to complete the transaction, returning the array of changes and an EditingResult showing the
3257
- * results of applying the changes as an Edit to the initial TreeView (passed to the constructor).
3258
- *
3259
- * No data outside the Transaction is modified by Transaction:
3260
- * the results from `close` must be used to actually submit an `Edit`.
3261
- * @alpha
3262
- */
3263
- export declare namespace TransactionInternal {
3264
- /**
3265
- * Makes a new {@link GenericTransaction} that follows the {@link TransactionInternal.Policy} policy.
3266
- * @internal
3267
- */
3268
- export function factory(view: RevisionView): GenericTransaction;
3269
- export type ValidState = SucceedingTransactionState;
3270
- /**
3271
- * The policy followed by a {@link TransactionInternal}.
3272
- * @internal
3273
- */
3274
- export class Policy implements GenericTransactionPolicy {
3275
- /**
3276
- * Maps detached sequences of nodes to their NodeIds
3277
- */
3278
- protected readonly detached: Map<DetachedSequenceId, readonly NodeId[]>;
3279
- /**
3280
- * Resolves change with Result.Ok
3281
- *
3282
- * @param state - Unused
3283
- * @param change - Change to resolve
3284
- * @returns Result.Ok which contains change
3285
- */
3286
- tryResolveChange(state: ValidState, change: ChangeInternal): Result.Ok<ChangeInternal>;
3287
- /**
3288
- * Validates the transaction when it is closed
3289
- *
3290
- * @param state - Current state
3291
- * @returns a {@link ChangeResult} containing either the change result or a Failure
3292
- */
3293
- validateOnClose(state: ValidState): ChangeResult;
3294
- /**
3295
- * Applies a given change
3296
- *
3297
- * @param state - Current state
3298
- * @param change - Change to apply
3299
- * @returns a {@link ChangeResult} containing either the change result or a Failure
3300
- */
3301
- dispatchChange(state: ValidState, change: ChangeInternal): ChangeResult;
3302
- private applyBuild;
3303
- private applyInsert;
3304
- private applyDetach;
3305
- private applyConstraint;
3306
- private applySetValue;
3307
- /**
3308
- * Generates tree view nodes from the supplied edit nodes.
3309
- * Invokes onCreateNode for each new node, and halts creation early if it returns true.
3310
- * Invokes onInvalidDetachedId and halts early for any invalid detached IDs referenced in the edit node sequence.
3311
- * @returns all the top-level node IDs in `sequence` (both from nodes and from detached sequences).
3312
- */
3313
- protected createViewNodesForTree(sequence: Iterable<BuildNodeInternal>, onCreateNode: (stableId: NodeId, node: TreeViewNode) => boolean, onInvalidDetachedId: (sequenceId: DetachedSequenceId) => void): NodeId[] | undefined;
3314
- private getDetachedNodeIds;
3315
- }
3316
- /**
3317
- * The kinds of failures that a transaction might encounter.
3318
- * @alpha
3319
- */
3320
- export enum FailureKind {
3321
- /**
3322
- * Transaction has an unused DetachedSequenceId
3323
- */
3324
- UnusedDetachedSequence = "UnusedDetachedSequence",
3325
- /**
3326
- * Transaction has a build operation using an already in use DetachedSequenceID.
3327
- */
3328
- DetachedSequenceIdAlreadyInUse = "DetachedSequenceIdAlreadyInUse",
3329
- /**
3330
- * Transaction tries to operate on an unknown DetachedSequenceID
3331
- */
3332
- DetachedSequenceNotFound = "DetachedSequenceNotFound",
3333
- /**
3334
- * Transaction has a build which uses a duplicated NodeId
3335
- */
3336
- DuplicateIdInBuild = "DuplicateIdInBuild",
3337
- /**
3338
- * Transaction tries to build a node using an ID which is already used in the current state
3339
- */
3340
- IdAlreadyInUse = "IdAlreadyInUse",
3341
- /**
3342
- * Transaction tries to set value of an unknown node
3343
- */
3344
- UnknownId = "UnknownId",
3345
- /**
3346
- * Transaction tries to insert in an invalid Place
3347
- */
3348
- BadPlace = "BadPlace",
3349
- /**
3350
- * Transaction tries to detach an invalid Range
3351
- */
3352
- BadRange = "BadRange",
3353
- /**
3354
- * Transaction has an invalid constraint
3355
- */
3356
- ConstraintViolation = "ConstraintViolation"
3357
- }
3358
- /**
3359
- * A failure encountered by a transaction.
3360
- * @alpha
3361
- */
3362
- export type Failure = UnusedDetachedSequenceFailure | DetachedSequenceIdAlreadyInUseFailure | DetachedSequenceNotFoundFailure | DuplicateIdInBuildFailure | IdAlreadyInUseFailure | UnknownIdFailure | BadPlaceFailure | BadRangeFailure | ConstraintViolationFailure;
3363
- /**
3364
- * Error returned when a transaction is closed while there is an unused detached sequence.
3365
- * @alpha
3366
- */
3367
- export interface UnusedDetachedSequenceFailure {
3368
- /**
3369
- * Failure kind (will always be FailureKind.UnusedDetachedSequence)
3370
- */
3371
- readonly kind: FailureKind.UnusedDetachedSequence;
3372
- /**
3373
- * The unused DetachedSequenceId
3374
- */
3375
- readonly sequenceId: DetachedSequenceId;
3376
- }
3377
- /**
3378
- * Error thrown when a transaction encounters a build operation using an already in use DetachedSequenceID.
3379
- * @alpha
3380
- */
3381
- export interface DetachedSequenceIdAlreadyInUseFailure {
3382
- /**
3383
- * Failure kind (will always be FailureKind.DetachedSequenceIdAlreadyInUse)
3384
- */
3385
- readonly kind: FailureKind.DetachedSequenceIdAlreadyInUse;
3386
- /**
3387
- * Faulting Change
3388
- */
3389
- readonly change: ChangeInternal;
3390
- /**
3391
- * The DetachedSequenceId that is already in use
3392
- */
3393
- readonly sequenceId: DetachedSequenceId;
3394
- }
3395
- /**
3396
- * Error thrown when a transaction tries to operate on an unknown DetachedSequenceID
3397
- * @alpha
3398
- */
3399
- export interface DetachedSequenceNotFoundFailure {
3400
- /**
3401
- * Failure kind (will always be FailureKind.DetachedSequenceNotFound)
3402
- */
3403
- readonly kind: FailureKind.DetachedSequenceNotFound;
3404
- /**
3405
- * Faulting Change
3406
- */
3407
- readonly change: ChangeInternal;
3408
- /**
3409
- * The DetachedSequenceId that wasn't found
3410
- */
3411
- readonly sequenceId: DetachedSequenceId;
3412
- }
3413
- /**
3414
- * Error thrown when a build uses a duplicated NodeId
3415
- * @alpha
3416
- */
3417
- export interface DuplicateIdInBuildFailure {
3418
- /**
3419
- * Failure kind (will always be FailureKind.DuplicateIdInBuild)
3420
- */
3421
- readonly kind: FailureKind.DuplicateIdInBuild;
3422
- /**
3423
- * Faulting Change
3424
- */
3425
- readonly change: ChangeInternal;
3426
- /**
3427
- * ID of duplicated node
3428
- */
3429
- readonly id: NodeId;
3430
- }
3431
- /**
3432
- * Error thrown when a build node ID is already used in the current state
3433
- * @alpha
3434
- */
3435
- export interface IdAlreadyInUseFailure {
3436
- /**
3437
- * Failure kind (will always be FailureKind.IdAlreadyInUse)
3438
- */
3439
- readonly kind: FailureKind.IdAlreadyInUse;
3440
- /**
3441
- * Faulting Change
3442
- */
3443
- readonly change: ChangeInternal;
3444
- /**
3445
- * ID of already in use node
3446
- */
3447
- readonly id: NodeId;
3448
- }
3449
- /**
3450
- * Error thrown when a change is attempted on an unknown NodeId
3451
- * @alpha
3452
- */
3453
- export interface UnknownIdFailure {
3454
- /**
3455
- * Failure kind (will always be FailureKind.UnknownId)
3456
- */
3457
- readonly kind: FailureKind.UnknownId;
3458
- /**
3459
- * Faulting Change
3460
- */
3461
- readonly change: ChangeInternal;
3462
- /**
3463
- * The unknown ID
3464
- */
3465
- readonly id: NodeId;
3466
- }
3467
- /**
3468
- * Error thrown when an insert change uses an invalid Place
3469
- * @alpha
3470
- */
3471
- export interface BadPlaceFailure {
3472
- /**
3473
- * Failure kind (will always be FailureKind.BadPlace)
3474
- */
3475
- readonly kind: FailureKind.BadPlace;
3476
- /**
3477
- * Faulting Change
3478
- */
3479
- readonly change: ChangeInternal;
3480
- /**
3481
- * The faulting place
3482
- */
3483
- readonly place: StablePlaceInternal;
3484
- /**
3485
- * The reason for the failure
3486
- */
3487
- readonly placeFailure: BadPlaceValidationResult;
3488
- }
3489
- /**
3490
- * Error thrown when a detach operation is given an invalid or malformed Range
3491
- * @alpha
3492
- */
3493
- export interface BadRangeFailure {
3494
- /**
3495
- * Failure kind (will always be FailureKind.BadRange)
3496
- */
3497
- readonly kind: FailureKind.BadRange;
3498
- /**
3499
- * Faulting Change
3500
- */
3501
- readonly change: ChangeInternal;
3502
- /**
3503
- * Faulting range
3504
- */
3505
- readonly range: StableRangeInternal;
3506
- /**
3507
- * The reason for the failure
3508
- */
3509
- readonly rangeFailure: BadRangeValidationResult;
3510
- }
3511
- /**
3512
- * Error thrown when a constraint fails to apply
3513
- * @alpha
3514
- */
3515
- export interface ConstraintViolationFailure {
3516
- /**
3517
- * Failure kind (will always be FailureKind.ConstraintViolation)
3518
- */
3519
- readonly kind: FailureKind.ConstraintViolation;
3520
- /**
3521
- * Faulting Change
3522
- */
3523
- readonly constraint: ConstraintInternal;
3524
- /**
3525
- * The first violation the constraint encounters (there may be others).
3526
- */
3527
- readonly violation: ConstraintViolationResult;
3528
- }
3529
- /**
3530
- * The details of what kind of constraint was violated and caused a ConstraintViolationFailure error to occur
3531
- * @alpha
3532
- */
3533
- export type ConstraintViolationResult = {
3534
- readonly kind: ConstraintViolationKind.BadRange;
3535
- readonly rangeFailure: BadRangeValidationResult;
3536
- } | {
3537
- readonly kind: ConstraintViolationKind.BadLength;
3538
- readonly actual: number;
3539
- } | {
3540
- readonly kind: ConstraintViolationKind.BadParent;
3541
- readonly actual: NodeId;
3542
- } | {
3543
- readonly kind: ConstraintViolationKind.BadLabel;
3544
- readonly actual: TraitLabel;
3545
- };
3546
- /**
3547
- * Enum of possible kinds of constraint violations that can be encountered
3548
- * @alpha
3549
- */
3550
- export enum ConstraintViolationKind {
3551
- /**
3552
- * The constraint failed because it applies to an invalid range
3553
- */
3554
- BadRange = "BadRange",
3555
- /**
3556
- * The constraint failed because the length prescribed by the constraint does not match the length of range being constrained
3557
- */
3558
- BadLength = "BadLength",
3559
- /**
3560
- * The constraint failed because the parent prescribed by the constraint does not match the actual parent of the range being constrained
3561
- */
3562
- BadParent = "BadParent",
3563
- /**
3564
- * The constraint failed because the trait label prescribed by the constraint does not match the actual trait label of the range being constrained
3565
- */
3566
- BadLabel = "BadLabel"
3567
- }
3568
- {};
3569
- }
3570
-
3571
- /**
3572
- * The ongoing state of a transaction.
3573
- * @internal
3574
- */
3575
- export declare type TransactionState = SucceedingTransactionState | FailingTransactionState;
3576
-
3577
- /**
3578
- * An view of a distributed tree that is part of an ongoing transaction between `RevisionView`s.
3579
- * @alpha
3580
- */
3581
- export declare class TransactionView extends TreeView {
3582
- /** Conclude a transaction by generating an immutable `RevisionView` from this view */
3583
- close(): RevisionView;
3584
- /** Inserts all nodes in a NodeSequence into the view */
3585
- addNodes(sequence: Iterable<TreeViewNode>): TransactionView;
3586
- /** Remove all nodes with the given ids from the view */
3587
- deleteNodes(nodes: Iterable<NodeId>): TransactionView;
3588
- /**
3589
- * Parents a set of detached nodes at a specified place.
3590
- * @param nodesToAttach - the nodes to parent in the specified place. The nodes must already be present in the view.
3591
- * @param place - the location to insert the nodes.
3592
- */
3593
- attachRange(nodesToAttach: readonly NodeId[], place: TreeViewPlace): TransactionView;
3594
- /**
3595
- * Detaches a range of nodes from their parent. The detached nodes remain in the view.
3596
- * @param rangeToDetach - the range of nodes to detach
3597
- */
3598
- detachRange(rangeToDetach: TreeViewRange): {
3599
- view: TransactionView;
3600
- detached: readonly NodeId[];
3601
- };
3602
- /**
3603
- * Sets or overwrites a node's value. The node must exist in this view.
3604
- * @param nodeId - the id of the node
3605
- * @param value - the new value
3606
- */
3607
- setNodeValue(nodeId: NodeId, value: Payload): TransactionView;
3608
- equals(view: TreeView): boolean;
3609
- }
3610
-
3611
- /**
3612
- * Satisfies `NodeData` and may contain children under traits (which may or may not be `TreeNodes`)
3613
- * @alpha
3614
- */
3615
- export declare interface TreeNode<TChild, TId> extends NodeData<TId>, HasTraits<TChild> {
3616
- }
3617
-
3618
- /**
3619
- * A handle to a `TreeNode` that exists within a specific `TreeView`. This type provides a convenient
3620
- * API for traversing trees of nodes in a TreeView and is not designed to provide maximum runtime
3621
- * performance; if performance is a concern, consider using the TreeView and TreeViewNode APIs directly.
3622
- * @internal
3623
- */
3624
- export declare class TreeNodeHandle implements TreeNode<TreeNodeHandle, NodeId> {
3625
- private readonly view;
3626
- private readonly viewNode;
3627
- /** Construct a handle which references the node with the given id in the given `TreeView` */
3628
- constructor(view: TreeView, nodeId: NodeId);
3629
- get payload(): Payload | undefined;
3630
- get definition(): Definition;
3631
- get identifier(): NodeId;
3632
- get traits(): TraitMap<TreeNodeHandle>;
3633
- /**
3634
- * Get a `TreeViewNode` for the tree view node that this handle references
3635
- */
3636
- get node(): TreeViewNode;
3637
- }
3638
-
3639
- /**
3640
- * A sequence of Nodes that make up a trait under a Node
3641
- * @alpha
3642
- */
3643
- export declare type TreeNodeSequence<TChild> = readonly TChild[];
3644
-
3645
- /**
3646
- * A view of a distributed tree.
3647
- * @alpha
3648
- */
3649
- export declare abstract class TreeView {
3650
- readonly root: NodeId;
3651
- protected readonly forest: Forest;
3652
- private readonly rootNode;
3653
- /**
3654
- * A cache of node's index within their parent trait.
3655
- * Used to avoid redundant linear scans of traits.
3656
- * Not shared across views; initialized to empty each time a TreeView is created.
3657
- */
3658
- private traitIndicesCache?;
3659
- protected constructor(root: NodeId, forest: Forest);
3660
- /** @returns the number of nodes in this view */
3661
- get size(): number;
3662
- /** @returns true iff a node with the given id exists in this view */
3663
- hasNode(id: NodeId): boolean;
3664
- /**
3665
- * @returns the index just after place (which specifies a location between items).
3666
- * Performance note: this is O(siblings in trait).
3667
- */
3668
- findIndexWithinTrait(place: TreeViewPlace): PlaceIndex;
3669
- /** @returns the node associated with the given id in this view. Fails if the node does not exist in this view. */
3670
- getViewNode(id: NodeId): TreeViewNode;
3671
- /** @returns the node associated with the given id in this view, or undefined if the node does not exist in this view */
3672
- tryGetViewNode(id: NodeId): TreeViewNode | undefined;
3673
- /**
3674
- * @returns the label of the trait under which a node with the given id resides. Fails if the node does not exist in this view or if
3675
- * it is the root node.
3676
- */
3677
- getTraitLabel(id: NodeId): TraitLabel;
3678
- /**
3679
- * @returns the label of the trait under which a node with the given id resides, or undefined if the node is not present in this
3680
- * view or if it is the root node
3681
- */
3682
- tryGetTraitLabel(id: NodeId): TraitLabel | undefined;
3683
- /**
3684
- * @returns the parent of the node with the given id. Fails if the node does not exist in this view or if it is the root node.
3685
- */
3686
- getParentViewNode(id: NodeId): TreeViewNode;
3687
- /**
3688
- * @returns the parent of the node with the given id. Returns undefined if the node does not exist in this view or if it is the root
3689
- * node.
3690
- */
3691
- tryGetParentViewNode(id: NodeId): TreeViewNode | undefined;
3692
- /**
3693
- * @returns the trait location of the node with the given id. Fails if the node does not exist in this view or of it is the root
3694
- * node
3695
- */
3696
- getTraitLocation(id: NodeId): TraitLocation;
3697
- /**
3698
- * @returns the trait location of the node with the given id, or undefined if the node does not exist in this view or if it is the root
3699
- * node
3700
- */
3701
- tryGetTraitLocation(id: NodeId): TraitLocation | undefined;
3702
- /**
3703
- * @returns the index within the trait under which the node with the given id resides. The node must exist in this view and must have a
3704
- * parent.
3705
- * Performance note: this is O(siblings in trait).
3706
- */
3707
- getIndexInTrait(id: NodeId): TraitNodeIndex;
3708
- /**
3709
- * @returns the index within the trait under which the node with the given id resides, or undefined if the node does not exist in this
3710
- * view or does not have a parent.
3711
- * Performance note: this is O(siblings in trait).
3712
- */
3713
- tryGetIndexInTrait(id: NodeId): TraitNodeIndex | undefined;
3714
- /**
3715
- * @returns the trait at the given location. If no such trait exists, returns an empty trait.
3716
- */
3717
- getTrait(traitLocation: TraitLocation): readonly NodeId[];
3718
- /** Asserts that the view's internal state is consistent. Useful for testing/validation. */
3719
- assertConsistent(): void;
3720
- [Symbol.iterator](): IterableIterator<TreeViewNode>;
3721
- /** @returns true iff the given view is equal to this view */
3722
- abstract equals(view: TreeView): boolean;
3723
- /**
3724
- * @returns true iff the given view's forest of nodes is equivalent to this view's forest of nodes
3725
- * @param strict - if true, the views' forests must be the same object, otherwise they must merely be equivalent
3726
- */
3727
- hasEqualForest(view: TreeView, strict?: boolean): boolean;
3728
- private iterateNodeDescendants;
3729
- private getIndexOfSide;
3730
- /**
3731
- * Calculate the difference between two `TreeView`s
3732
- * @param view - the other view to compare to this one
3733
- * @returns A {@link Delta} which nodes must be changed, added, and removed to get from `this` to `view`.
3734
- * The views must share a root.
3735
- */
3736
- delta(view: TreeView): Delta<NodeId>;
3737
- }
3738
-
3739
- /**
3740
- * An immutable view of a distributed tree node.
3741
- * @alpha
3742
- */
3743
- export declare interface TreeViewNode extends NodeData<NodeId> {
3744
- /** The IDs of the children under this node */
3745
- readonly traits: ReadonlyMap<TraitLabel, readonly NodeId[]>;
3746
- /** The parent and trait under which this node resides. Undefined iff this is the root node of the tree (i.e. {@link initialTree}). */
3747
- readonly parentage?: TraitLocation;
3748
- }
3749
-
3750
- /**
3751
- * A place within a particular `TreeView` that is anchored relative to a specific node in the tree, or relative to the outside of the trait.
3752
- * Valid iff 'trait' is valid and, if provided, sibling is in the Location specified by 'trait'.
3753
- * @alpha
3754
- */
3755
- export declare interface TreeViewPlace {
3756
- readonly sibling?: NodeId;
3757
- readonly side: Side;
3758
- readonly trait: TraitLocation;
3759
- }
3760
-
3761
- /**
3762
- * Specifies the range of nodes from `start` to `end` within a trait within a particular `TreeView`.
3763
- * Valid iff start and end are valid and are within the same trait.
3764
- * @alpha
3765
- */
3766
- export declare interface TreeViewRange {
3767
- readonly start: TreeViewPlace;
3768
- readonly end: TreeViewPlace;
3769
- }
3770
-
3771
- /**
3772
- * Logs generic telemetry for failed sequenced edits.
3773
- * Only failing edits that were originally made locally are logged.
3774
- * @param tree - The tree for which to log the telemetry.
3775
- * @internal
3776
- */
3777
- export declare function useFailedSequencedEditTelemetry(tree: SharedTree): {
3778
- disable: () => void;
3779
- };
3780
-
3781
- /**
3782
- * Type-safe identifiers for specific use cases.
3783
- */
3784
- /**
3785
- * A 128-bit Universally Unique IDentifier. Represented here
3786
- * with a string of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
3787
- * where x is a lowercase hex digit.
3788
- * @alpha
3789
- */
3790
- export declare type UuidString = string & {
3791
- readonly UuidString: '9d40d0ae-90d9-44b1-9482-9f55d59d5465';
3792
- };
3793
-
3794
- /**
3795
- * Result of applying a valid transaction.
3796
- * @alpha
3797
- */
3798
- export declare interface ValidEditingResult extends EditingResultBase {
3799
- /**
3800
- * {@inheritDoc EditingResultBase.status}
3801
- */
3802
- readonly status: EditStatus.Applied;
3803
- /**
3804
- * The new revision produced by the transaction.
3805
- */
3806
- readonly after: RevisionView;
3807
- }
3808
-
3809
- /**
3810
- * Format versions that SharedTree supports writing. Changes to op or summary formats necessitate updates.
3811
- * @alpha
3812
- */
3813
- export declare enum WriteFormat {
3814
- /** Stores all edits in their raw format. */
3815
- v0_0_2 = "0.0.2",
3816
- /** Supports history virtualization, tree compression, string interning, and makes currentView optional. */
3817
- v0_1_1 = "0.1.1"
3818
- }
3819
-
3820
- export { }