@fluid-experimental/tree 0.59.4002 → 1.0.2

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.
Files changed (36) hide show
  1. package/dist/SharedTree.d.ts +89 -30
  2. package/dist/SharedTree.d.ts.map +1 -1
  3. package/dist/SharedTree.js +94 -59
  4. package/dist/SharedTree.js.map +1 -1
  5. package/dist/SharedTreeEncoder.d.ts +1 -1
  6. package/dist/SharedTreeEncoder.d.ts.map +1 -1
  7. package/dist/SharedTreeEncoder.js.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/lib/SharedTree.d.ts +89 -30
  12. package/lib/SharedTree.d.ts.map +1 -1
  13. package/lib/SharedTree.js +95 -60
  14. package/lib/SharedTree.js.map +1 -1
  15. package/lib/SharedTreeEncoder.d.ts +1 -1
  16. package/lib/SharedTreeEncoder.d.ts.map +1 -1
  17. package/lib/SharedTreeEncoder.js.map +1 -1
  18. package/lib/index.d.ts +1 -1
  19. package/lib/index.d.ts.map +1 -1
  20. package/lib/index.js.map +1 -1
  21. package/lib/test/fuzz/SharedTreeFuzzTests.d.ts.map +1 -1
  22. package/lib/test/fuzz/SharedTreeFuzzTests.js +3 -1
  23. package/lib/test/fuzz/SharedTreeFuzzTests.js.map +1 -1
  24. package/lib/test/utilities/SharedTreeTests.d.ts.map +1 -1
  25. package/lib/test/utilities/SharedTreeTests.js +27 -50
  26. package/lib/test/utilities/SharedTreeTests.js.map +1 -1
  27. package/lib/test/utilities/SharedTreeVersioningTests.d.ts.map +1 -1
  28. package/lib/test/utilities/SharedTreeVersioningTests.js +19 -19
  29. package/lib/test/utilities/SharedTreeVersioningTests.js.map +1 -1
  30. package/lib/test/utilities/TestUtilities.d.ts.map +1 -1
  31. package/lib/test/utilities/TestUtilities.js +11 -11
  32. package/lib/test/utilities/TestUtilities.js.map +1 -1
  33. package/package.json +18 -31
  34. package/src/SharedTree.ts +196 -47
  35. package/src/SharedTreeEncoder.ts +1 -1
  36. package/src/index.ts +4 -0
package/lib/SharedTree.js CHANGED
@@ -8,7 +8,7 @@ import { createSingleBlobSummary, serializeHandles, SharedObject, } from '@fluid
8
8
  import { ChildLogger, PerformanceEvent } from '@fluidframework/telemetry-utils';
9
9
  import { assert, assertNotUndefined, fail, copyPropertyIfDefined, noop } from './Common';
10
10
  import { EditLog, getNumberOfHandlesFromEditLogSummary } from './EditLog';
11
- import { isDetachedSequenceId } from './Identifiers';
11
+ import { isDetachedSequenceId, } from './Identifiers';
12
12
  import { initialTree } from './InitialTree';
13
13
  import { CachingLogViewer, } from './LogViewer';
14
14
  import { deserialize, getSummaryStatistics } from './SummaryBackCompatibility';
@@ -24,25 +24,15 @@ import { ChangeType } from './ChangeTypes';
24
24
  import { IdCompressor, createSessionId } from './id-compressor';
25
25
  import { convertEditIds } from './IdConversion';
26
26
  import { MutableStringInterner } from './StringInterner';
27
+ import { nilUuid } from './UuidUtilities';
27
28
  /**
28
29
  * Factory for SharedTree.
29
30
  * Includes history in the summary.
30
31
  * @public
31
32
  */
32
33
  export class SharedTreeFactory {
33
- /**
34
- * Get a factory for SharedTree to register with the data store.
35
- * @param writeFormat - Determines the format version the SharedTree will write ops and summaries in. See [the write format
36
- * documentation](../docs/Write-Format.md) for more information.
37
- * @param summarizeHistory - Determines if the history is included in summaries and if edit chunks are uploaded when they are full.
38
- * See the [breaking change migration documentation](docs/Breaking-Change-Migration) for more details on this scheme.
39
- * @param expensiveValidation - Enables expensive asserts on SharedTree.
40
- * @returns A factory that creates `SharedTree`s and loads them from storage.
41
- */
42
- constructor(writeFormat, summarizeHistory = false, expensiveValidation = false) {
43
- this.writeFormat = writeFormat;
44
- this.summarizeHistory = summarizeHistory;
45
- this.expensiveValidation = expensiveValidation;
34
+ constructor(...args) {
35
+ this.args = args;
46
36
  }
47
37
  /**
48
38
  * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory."type"}
@@ -69,15 +59,21 @@ export class SharedTreeFactory {
69
59
  * @param runtime - data store runtime that owns the new SharedTree
70
60
  * @param id - optional name for the SharedTree
71
61
  */
72
- create(runtime, id, expensiveValidation = false) {
73
- this.expensiveValidation = expensiveValidation;
62
+ create(runtime, id) {
74
63
  const sharedTree = this.createSharedTree(runtime, id);
75
64
  sharedTree.initializeLocal();
76
65
  return sharedTree;
77
66
  }
78
67
  createSharedTree(runtime, id) {
79
- const sharedTree = new SharedTree(runtime, id, this.writeFormat, this.summarizeHistory, this.expensiveValidation);
80
- return sharedTree;
68
+ const [writeFormat] = this.args;
69
+ switch (writeFormat) {
70
+ case WriteFormat.v0_0_2:
71
+ return new SharedTree(runtime, id, ...this.args);
72
+ case WriteFormat.v0_1_1:
73
+ return new SharedTree(runtime, id, ...this.args);
74
+ default:
75
+ fail('Unknown write format');
76
+ }
81
77
  }
82
78
  }
83
79
  /**
@@ -106,20 +102,9 @@ const sharedTreeTelemetryProperties = { all: { isSharedTreeEvent: true } };
106
102
  * @public
107
103
  */
108
104
  export class SharedTree extends SharedObject {
109
- /**
110
- * Create a new SharedTreeFactory.
111
- * @param runtime - The runtime the SharedTree will be associated with
112
- * @param id - Unique ID for the SharedTree
113
- * @param writeFormat - Determines the format version the SharedTree will write ops and summaries in. See [the write format
114
- * documentation](../docs/Write-Format.md) for more information.
115
- * @param summarizeHistory - Determines if the history is included in summaries and if edit chunks are uploaded when they are full.
116
- * @param expensiveValidation - Enable expensive asserts.
117
- */
118
- constructor(runtime, id, writeFormat, summarizeHistory = false, expensiveValidation = false) {
119
- super(id, runtime, SharedTreeFactory.Attributes);
105
+ constructor(runtime, id, writeFormat, options = {}) {
106
+ super(id, runtime, SharedTreeFactory.Attributes, 'fluid_sharedTree_');
120
107
  this.writeFormat = writeFormat;
121
- this.expensiveValidation = expensiveValidation;
122
- this.idCompressor = new IdCompressor(createSessionId(), reservedIdCount);
123
108
  this.idNormalizer = {
124
109
  tree: this,
125
110
  get localSessionId() {
@@ -162,8 +147,9 @@ export class SharedTree extends SharedObject {
162
147
  }
163
148
  }
164
149
  };
165
- this.summarizeHistory = summarizeHistory === false ? false : true;
166
- this.uploadEditChunks = summarizeHistory === false ? false : summarizeHistory.uploadEditChunks;
150
+ const historyPolicy = this.getHistoryPolicy(options);
151
+ this.summarizeHistory = historyPolicy.summarizeHistory;
152
+ this.uploadEditChunks = historyPolicy.uploadEditChunks;
167
153
  // This code is somewhat duplicated from OldestClientObserver because it currently depends on the container runtime
168
154
  // which SharedTree does not have access to.
169
155
  // TODO:#55900: Get rid of copy-pasted OldestClientObserver code
@@ -175,11 +161,12 @@ export class SharedTree extends SharedObject {
175
161
  runtime.on('disconnected', this.updateOldest);
176
162
  this.logger = ChildLogger.create(runtime.logger, 'SharedTree', sharedTreeTelemetryProperties);
177
163
  this.sequencedEditAppliedLogger = ChildLogger.create(this.logger, 'SequencedEditApplied', sharedTreeTelemetryProperties);
164
+ const attributionId = options.attributionId;
165
+ this.idCompressor = new IdCompressor(createSessionId(), reservedIdCount, attributionId);
178
166
  const { editLog, cachingLogViewer } = this.initializeNewEditLogFromSummary({
179
167
  editChunks: [],
180
168
  editIds: [],
181
- }, undefined, this.idCompressor, // TODO: Attribution info
182
- this.processEditResult, this.processSequencedEditResult, WriteFormat.v0_1_1);
169
+ }, undefined, this.idCompressor, this.processEditResult, this.processSequencedEditResult, WriteFormat.v0_1_1);
183
170
  this.editLog = editLog;
184
171
  this.cachingLogViewer = cachingLogViewer;
185
172
  this.encoder_0_0_2 = new SharedTreeEncoder_0_0_2(this.summarizeHistory);
@@ -191,31 +178,39 @@ export class SharedTree extends SharedObject {
191
178
  static create(runtime, id) {
192
179
  return runtime.createChannel(id, SharedTreeFactory.Type);
193
180
  }
194
- /**
195
- * Get a factory for SharedTree to register with the data store.
196
- * @param summarizeHistory - Determines if the history is included in summaries and if edit chunks are uploaded when they are full.
197
- *
198
- * On 0.1.1 documents, due to current code limitations, this parameter is only impactful for newly created documents.
199
- * `SharedTree`s which load existing documents will summarize history if and only if the loaded summary included history.
200
- *
201
- * The technical limitations here relate to clients with mixed versions collaborating.
202
- * In the future we may allow modification of whether or not a particular document saves history, but only via a consensus mechanism.
203
- * See the skipped test in SharedTreeFuzzTests.ts for more details on this issue.
204
- * See docs/Breaking-Change-Migration for more details on the consensus scheme.
205
- * @param writeFormat - Determines the format version the SharedTree will write ops and summaries in.
206
- * This format may be updated to a newer (supported) version at runtime if a collaborating shared-tree
207
- * that was initialized with a newer write version connects to the session. Care must be taken when changing this value,
208
- * as a staged rollout must of occurred such that all collaborating clients must have the code to read at least the version
209
- * written.
210
- * See [the write format documentation](../docs/Write-Format.md) for more information.
211
- * @returns A factory that creates `SharedTree`s and loads them from storage.
212
- */
213
- static getFactory(writeFormat, summarizeHistory = false) {
181
+ static getFactory(...args) {
182
+ const [writeFormat] = args;
214
183
  // On 0.1.1 documents, due to current code limitations, all clients MUST agree on the value of `summarizeHistory`.
215
184
  // Note that this means staged rollout changing this value should not be attempted.
216
185
  // It is possible to update shared-tree to correctly handle such a staged rollout, but that hasn't been implemented.
217
186
  // See the skipped test in SharedTreeFuzzTests.ts for more details on this issue.
218
- return new SharedTreeFactory(writeFormat, summarizeHistory);
187
+ switch (writeFormat) {
188
+ case WriteFormat.v0_0_2:
189
+ return new SharedTreeFactory(...args);
190
+ case WriteFormat.v0_1_1:
191
+ return new SharedTreeFactory(...args);
192
+ default:
193
+ fail('Unknown write format');
194
+ }
195
+ }
196
+ /**
197
+ * The UUID used for attribution of nodes created by this SharedTree. All shared trees with a write format of 0.1.1 or
198
+ * greater have a unique attribution ID which may be configured in the constructor. All other shared trees (i.e. those
199
+ * with a write format of 0.0.2) use the nil UUID as their attribution ID.
200
+ * @public
201
+ */
202
+ get attributionId() {
203
+ switch (this.writeFormat) {
204
+ case WriteFormat.v0_0_2:
205
+ return nilUuid;
206
+ default: {
207
+ const { attributionId } = this.idCompressor;
208
+ if (attributionId === ghostSessionId) {
209
+ return nilUuid;
210
+ }
211
+ return attributionId;
212
+ }
213
+ }
219
214
  }
220
215
  /**
221
216
  * Viewer for trees defined by editLog. This allows access to views of the tree at different revisions (various points in time).
@@ -223,6 +218,27 @@ export class SharedTree extends SharedObject {
223
218
  get logViewer() {
224
219
  return this.cachingLogViewer;
225
220
  }
221
+ getHistoryPolicy(options) {
222
+ var _a;
223
+ const noCompatOptions = options;
224
+ if (typeof noCompatOptions.summarizeHistory === 'object') {
225
+ return {
226
+ summarizeHistory: true,
227
+ uploadEditChunks: noCompatOptions.summarizeHistory.uploadEditChunks,
228
+ };
229
+ }
230
+ else {
231
+ return {
232
+ summarizeHistory: (_a = noCompatOptions.summarizeHistory) !== null && _a !== void 0 ? _a : false,
233
+ uploadEditChunks: false,
234
+ };
235
+ }
236
+ }
237
+ /**
238
+ * The write format version currently used by this `SharedTree`. This is always initialized to the write format
239
+ * passed to the tree's constructor, but it may automatically upgrade over time (e.g. when connected to another
240
+ * SharedTree with a higher write format, or when loading a summary with a higher write format).
241
+ */
226
242
  getWriteFormat() {
227
243
  return this.writeFormat;
228
244
  }
@@ -319,6 +335,25 @@ export class SharedTree extends SharedObject {
319
335
  tryConvertToNodeId(id) {
320
336
  return this.idCompressor.tryRecompress(id);
321
337
  }
338
+ /**
339
+ * Returns the attribution ID associated with the SharedTree that generated the given node ID. This is generally only useful for clients
340
+ * 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
341
+ * `attributionId` of the tree.
342
+ * @public
343
+ */
344
+ attributeNodeId(id) {
345
+ switch (this.writeFormat) {
346
+ case WriteFormat.v0_0_2:
347
+ return nilUuid;
348
+ default: {
349
+ const attributionId = this.idCompressor.attributeId(id);
350
+ if (attributionId === ghostSessionId) {
351
+ return nilUuid;
352
+ }
353
+ return attributionId;
354
+ }
355
+ }
356
+ }
322
357
  /**
323
358
  * @returns the edit history of the tree.
324
359
  * @public
@@ -465,7 +500,7 @@ export class SharedTree extends SharedObject {
465
500
  let convertedSummary;
466
501
  switch (loadedSummaryVersion) {
467
502
  case WriteFormat.v0_0_2:
468
- convertedSummary = this.encoder_0_0_2.decodeSummary(summary);
503
+ convertedSummary = this.encoder_0_0_2.decodeSummary(summary, this.attributionId);
469
504
  break;
470
505
  case WriteFormat.v0_1_1: {
471
506
  const typedSummary = summary;
@@ -476,7 +511,7 @@ export class SharedTree extends SharedObject {
476
511
  this.uploadEditChunks = loadedSummaryIncludesHistory;
477
512
  this.encoder_0_1_1 = new SharedTreeEncoder_0_1_1(this.summarizeHistory);
478
513
  }
479
- convertedSummary = this.encoder_0_1_1.decodeSummary(summary); // TODO:#461: pass attribution info
514
+ convertedSummary = this.encoder_0_1_1.decodeSummary(summary, this.attributionId);
480
515
  break;
481
516
  }
482
517
  default:
@@ -764,7 +799,7 @@ export class SharedTree extends SharedObject {
764
799
  this.interner = new MutableStringInterner([initialTree.definition]);
765
800
  const oldIdCompressor = this.idCompressor;
766
801
  // Create the IdCompressor that will be used after the upgrade
767
- const newIdCompressor = new IdCompressor(createSessionId(), reservedIdCount); // TODO: attribution info
802
+ const newIdCompressor = new IdCompressor(createSessionId(), reservedIdCount, this.attributionId);
768
803
  const newContext = getNodeIdContext(newIdCompressor);
769
804
  // Generate all local IDs in the new compressor that were in the old compressor and preserve their UUIDs.
770
805
  // This will allow the client to continue to use local IDs that were allocated pre-upgrade
@@ -778,7 +813,7 @@ export class SharedTree extends SharedObject {
778
813
  }
779
814
  };
780
815
  // Construct a temporary "ghost" compressor which is used to generate final IDs that will be consistent across all upgrading clients
781
- const ghostIdCompressor = new IdCompressor(ghostSessionId, reservedIdCount); // TODO: attribution info
816
+ const ghostIdCompressor = new IdCompressor(ghostSessionId, reservedIdCount);
782
817
  const ghostContext = getNodeIdContext(ghostIdCompressor);
783
818
  if (this.summarizeHistory) {
784
819
  // All clients have the full history, and can therefore all "generate" the same final IDs for every ID in the history