@fluid-experimental/tree 1.2.0-77818 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Common.d.ts +12 -6
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js +14 -8
- package/dist/Common.js.map +1 -1
- package/dist/SharedTree.d.ts +12 -1
- package/dist/SharedTree.d.ts.map +1 -1
- package/dist/SharedTree.js +61 -11
- package/dist/SharedTree.js.map +1 -1
- package/dist/id-compressor/IdCompressor.d.ts.map +1 -1
- package/dist/id-compressor/IdCompressor.js +7 -11
- package/dist/id-compressor/IdCompressor.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/lib/Common.d.ts +12 -6
- package/lib/Common.d.ts.map +1 -1
- package/lib/Common.js +14 -8
- package/lib/Common.js.map +1 -1
- package/lib/SharedTree.d.ts +12 -1
- package/lib/SharedTree.d.ts.map +1 -1
- package/lib/SharedTree.js +61 -11
- package/lib/SharedTree.js.map +1 -1
- package/lib/id-compressor/IdCompressor.d.ts.map +1 -1
- package/lib/id-compressor/IdCompressor.js +7 -11
- package/lib/id-compressor/IdCompressor.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/test/IdCompressor.tests.js +2 -1
- package/lib/test/IdCompressor.tests.js.map +1 -1
- package/lib/test/fuzz/Generators.d.ts.map +1 -1
- package/lib/test/fuzz/Generators.js +20 -10
- package/lib/test/fuzz/Generators.js.map +1 -1
- package/lib/test/fuzz/SharedTreeFuzzTests.d.ts.map +1 -1
- package/lib/test/fuzz/SharedTreeFuzzTests.js +55 -20
- package/lib/test/fuzz/SharedTreeFuzzTests.js.map +1 -1
- package/lib/test/fuzz/Types.d.ts +14 -4
- package/lib/test/fuzz/Types.d.ts.map +1 -1
- package/lib/test/fuzz/Types.js.map +1 -1
- package/lib/test/utilities/PendingLocalStateTests.d.ts.map +1 -1
- package/lib/test/utilities/PendingLocalStateTests.js +199 -56
- package/lib/test/utilities/PendingLocalStateTests.js.map +1 -1
- package/lib/test/utilities/TestUtilities.d.ts +12 -1
- package/lib/test/utilities/TestUtilities.d.ts.map +1 -1
- package/lib/test/utilities/TestUtilities.js +12 -2
- package/lib/test/utilities/TestUtilities.js.map +1 -1
- package/package.json +17 -17
- package/src/Common.ts +14 -8
- package/src/SharedTree.ts +90 -12
- package/src/id-compressor/IdCompressor.ts +9 -11
- package/src/index.ts +1 -0
package/dist/Common.d.ts
CHANGED
|
@@ -59,16 +59,21 @@ export declare function fail(message?: string, containsPII?: boolean): never;
|
|
|
59
59
|
* Asserts a value is not undefined, and returns the value.
|
|
60
60
|
* Use when violations are logic errors in the program.
|
|
61
61
|
*
|
|
62
|
+
* @remarks
|
|
62
63
|
* When practical, prefer the pattern `x ?? fail('message')` over `assertNotUndefined(x, 'message')`.
|
|
63
|
-
* Using `?? fail` allows for message formatting without incurring the cost of formatting the message
|
|
64
|
-
*
|
|
65
|
-
*
|
|
64
|
+
* Using `?? fail` allows for message formatting without incurring the cost of formatting the message
|
|
65
|
+
* in the non failing case.
|
|
66
|
+
*
|
|
67
|
+
* Example:
|
|
68
|
+
* ```typescript
|
|
66
69
|
* x ?? fail(`x should exist for ${y}`)
|
|
67
70
|
* ```
|
|
68
|
-
*
|
|
71
|
+
*
|
|
72
|
+
* Additionally the `?? fail` avoids an extra call/stack frame in the non failing case.
|
|
69
73
|
*
|
|
70
74
|
* Another pattern to prefer over `assertNotUndefined(x, 'message')` is `assert(x !== undefined)`.
|
|
71
|
-
* This pattern is preferred because it is more general (same approach works with typeof, instance of,
|
|
75
|
+
* This pattern is preferred because it is more general (same approach works with typeof, instance of,
|
|
76
|
+
* comparison to other values etc.).
|
|
72
77
|
*
|
|
73
78
|
* @param value - Value to assert against is non undefined.
|
|
74
79
|
* @param message - Message to be printed if assertion fails.
|
|
@@ -91,8 +96,9 @@ export declare function assign<T, K extends keyof never, V>(object: T, property:
|
|
|
91
96
|
/**
|
|
92
97
|
* Redefine a property to have the given value. This is simply a type-safe wrapper around
|
|
93
98
|
* `Object.defineProperty`, but it is useful for caching public getters on first read.
|
|
99
|
+
*
|
|
94
100
|
* @example
|
|
95
|
-
* ```
|
|
101
|
+
* ```typescript
|
|
96
102
|
* // `randomOnce()` will return a random number, but always the same random number.
|
|
97
103
|
* {
|
|
98
104
|
* get randomOnce(): number {
|
package/dist/Common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Common.d.ts","sourceRoot":"","sources":["../src/Common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC/F,OAAO,KAAK,MAAM,cAAc,CAAC;AAIjC;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,wBAAwB,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,6BAA8B,SAAQ,oBAAoB;IAC1E,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC;CACjC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAErE;AAgBD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAEjF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAEnE;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,C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,21 @@ exports.fail = fail;
|
|
|
93
93
|
* Asserts a value is not undefined, and returns the value.
|
|
94
94
|
* Use when violations are logic errors in the program.
|
|
95
95
|
*
|
|
96
|
+
* @remarks
|
|
96
97
|
* When practical, prefer the pattern `x ?? fail('message')` over `assertNotUndefined(x, 'message')`.
|
|
97
|
-
* Using `?? fail` allows for message formatting without incurring the cost of formatting the message
|
|
98
|
-
*
|
|
99
|
-
*
|
|
98
|
+
* Using `?? fail` allows for message formatting without incurring the cost of formatting the message
|
|
99
|
+
* in the non failing case.
|
|
100
|
+
*
|
|
101
|
+
* Example:
|
|
102
|
+
* ```typescript
|
|
100
103
|
* x ?? fail(`x should exist for ${y}`)
|
|
101
104
|
* ```
|
|
102
|
-
*
|
|
105
|
+
*
|
|
106
|
+
* Additionally the `?? fail` avoids an extra call/stack frame in the non failing case.
|
|
103
107
|
*
|
|
104
108
|
* Another pattern to prefer over `assertNotUndefined(x, 'message')` is `assert(x !== undefined)`.
|
|
105
|
-
* This pattern is preferred because it is more general (same approach works with typeof, instance of,
|
|
109
|
+
* This pattern is preferred because it is more general (same approach works with typeof, instance of,
|
|
110
|
+
* comparison to other values etc.).
|
|
106
111
|
*
|
|
107
112
|
* @param value - Value to assert against is non undefined.
|
|
108
113
|
* @param message - Message to be printed if assertion fails.
|
|
@@ -136,8 +141,9 @@ exports.assign = assign;
|
|
|
136
141
|
/**
|
|
137
142
|
* Redefine a property to have the given value. This is simply a type-safe wrapper around
|
|
138
143
|
* `Object.defineProperty`, but it is useful for caching public getters on first read.
|
|
144
|
+
*
|
|
139
145
|
* @example
|
|
140
|
-
* ```
|
|
146
|
+
* ```typescript
|
|
141
147
|
* // `randomOnce()` will return a random number, but always the same random number.
|
|
142
148
|
* {
|
|
143
149
|
* get randomOnce(): number {
|
|
@@ -335,7 +341,8 @@ function setPropertyIfDefined(value, destination, property) {
|
|
|
335
341
|
}
|
|
336
342
|
exports.setPropertyIfDefined = setPropertyIfDefined;
|
|
337
343
|
/**
|
|
338
|
-
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```typescript
|
|
339
346
|
* function (thing: ObjectWithMaybeFoo) {
|
|
340
347
|
* const x: MyActualType = {
|
|
341
348
|
* bar: 3
|
|
@@ -345,7 +352,6 @@ exports.setPropertyIfDefined = setPropertyIfDefined;
|
|
|
345
352
|
* copyPropertyIfDefined(thing, x, 'foo');
|
|
346
353
|
* }
|
|
347
354
|
* ```
|
|
348
|
-
* @returns
|
|
349
355
|
*/
|
|
350
356
|
function breakOnDifference() {
|
|
351
357
|
return { break: true };
|
package/dist/Common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Common.js","sourceRoot":"","sources":["../src/Common.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAE9C;;;;;;;;GAQG;AACU,QAAA,4BAA4B,GAAG,qBAAqB,CAAC;AASlE;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAA0B;IAC3D,OAAQ,KAAkD,CAAC,iBAAiB,KAAK,IAAI,CAAC;AACvF,CAAC;AAFD,8CAEC;AAED;;GAEG;AACH,MAAM,wBAAyB,SAAQ,KAAK;IAG3C,YAAmB,OAAe;;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHA,cAAS,GAAG,oCAA4B,CAAC;QAIxD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,wFAAwF;QACxF,MAAA,KAAK,CAAC,iBAAiB,+CAAvB,KAAK,EAAqB,IAAI,CAAC,CAAC;IACjC,CAAC;CACD;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAmB,CAAI,EAAE,CAAI;IAChE,OAAO,CAAC,GAAG,CAAC,CAAC;AACd,CAAC;AAFD,oDAEC;AAED;;;;GAIG;AACH,SAAgB,4BAA4B,CAAmB,CAAI,EAAE,CAAI;IACxE,OAAO,CAAC,GAAG,CAAC,CAAC;AACd,CAAC;AAFD,oEAEC;AAED;;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C,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5D,CAAC;IALe,eAAQ,WAKvB,CAAA;IACD;;OAEG;IACH,IAAY,UAKX;IALD,WAAY,UAAU;QACrB,mCAAmC;QACnC,uCAAE,CAAA;QACF,sCAAsC;QACtC,6CAAK,CAAA;IACN,CAAC,EALW,UAAU,GAAV,iBAAU,KAAV,iBAAU,QAKrB;AAeF,CAAC,EA5EgB,MAAM,GAAN,cAAM,KAAN,cAAM,QA4EtB;AAoDD;;GAEG;AACH,SAAgB,gBAAgB,CAC/B,KAAmB,EACnB,MAAW;IAEX,OAAO,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC;AAChC,CAAC;AALD,4CAKC;AACD;;GAEG;AACH,SAAgB,SAAS,CACxB,KAAmB,EACnB,MAAW;IAEX,OAAO,KAAK,CAAC,MAAM,IAAI,MAAM,CAAC;AAC/B,CAAC;AALD,8BAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseEvent, ITelemetryProperties } from '@fluidframework/common-definitions';\nimport BTree from 'sorted-btree';\n\nconst defaultFailMessage = 'Assertion failed';\n\n/**\n * Assertion failures in SharedTree will throw an exception containing this value as an `errorType`. The Fluid runtime propagates this field\n * in its handlings of errors thrown by containers. See\n * https://github.com/microsoft/FluidFramework/blob/main/packages/loader/container-utils/src/error.ts\n *\n * Exporting this enables users to safely filter telemetry handling of errors based on their type.\n *\n * @public\n */\nexport const sharedTreeAssertionErrorType = 'SharedTreeAssertion';\n\n/**\n * Telemetry properties decorated on all SharedTree events.\n */\nexport interface SharedTreeTelemetryProperties extends ITelemetryProperties {\n\treadonly isSharedTreeEvent: true;\n}\n\n/**\n * Returns if the supplied event is a SharedTree telemetry event.\n */\nexport function isSharedTreeEvent(event: ITelemetryBaseEvent): boolean {\n\treturn (event as unknown as SharedTreeTelemetryProperties).isSharedTreeEvent === true;\n}\n\n/**\n * Error object thrown by assertion failures in `SharedTree`.\n */\nclass SharedTreeAssertionError extends Error {\n\tpublic readonly errorType = sharedTreeAssertionErrorType;\n\n\tpublic constructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = 'Assertion error';\n\t\t// Note: conditional as `captureStackTrace` isn't defined in all browsers (e.g. Safari).\n\t\tError.captureStackTrace?.(this);\n\t}\n}\n\n/**\n * A numeric comparator used for sorting in ascending order.\n *\n * Handles +/-0 like Map: -0 is equal to +0.\n */\nexport function compareFiniteNumbers<T extends number>(a: T, b: T): number {\n\treturn a - b;\n}\n\n/**\n * A numeric comparator used for sorting in descending order.\n *\n * Handles +/-0 like Map: -0 is equal to +0.\n */\nexport function compareFiniteNumbersReversed<T extends number>(a: T, b: T): number {\n\treturn b - a;\n}\n\n/**\n * Compares strings lexically to form a strict partial ordering.\n */\nexport function compareStrings<T extends string>(a: T, b: T): number {\n\treturn a > b ? 1 : a === b ? 0 : -1;\n}\n\n/**\n * Asserts against a boolean condition. Throws an Error if the assertion failed. Will run and throw in release builds.\n * Use when violations are logic errors in the program.\n * @param condition - A condition to assert is truthy\n * @param message - Message to be printed if assertion fails. Will print \"Assertion failed\" by default\n * @param containsPII - boolean flag for whether the message passed in contains personally identifying information (PII).\n */\nexport function assert(condition: unknown, message?: string, containsPII = false): asserts condition {\n\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\tif (!condition) {\n\t\tfail(message, containsPII);\n\t}\n}\n\n/**\n * Fails an assertion. Throws an Error that the assertion failed.\n * Use when violations are logic errors in the program.\n * @param message - Message to be printed if assertion fails. Will print \"Assertion failed\" by default\n * @param containsPII - boolean flag for whether the message passed in contains personally identifying information (PII).\n */\nexport function fail(message: string = defaultFailMessage, containsPII = false): never {\n\tif (process.env.NODE_ENV !== 'production') {\n\t\tdebugger;\n\t\tconsole.error(message);\n\t}\n\n\tthrow new SharedTreeAssertionError(containsPII ? 'Assertion failed' : message);\n}\n\n/**\n * Asserts a value is not undefined, and returns the value.\n * Use when violations are logic errors in the program.\n *\n * When practical, prefer the pattern `x ?? fail('message')` over `assertNotUndefined(x, 'message')`.\n * Using `?? fail` allows for message formatting without incurring the cost of formatting the message in the non failing case\n * (ex:\n * ```\n * x ?? fail(`x should exist for ${y}`)\n * ```\n * ). Additionally the `?? fail` avoids an extra call/stack frame in the non failing case.\n *\n * Another pattern to prefer over `assertNotUndefined(x, 'message')` is `assert(x !== undefined)`.\n * This pattern is preferred because it is more general (same approach works with typeof, instance of, comparison to other values etc.).\n *\n * @param value - Value to assert against is non undefined.\n * @param message - Message to be printed if assertion fails.\n */\nexport function assertNotUndefined<T>(value: T | undefined, message = 'value must not be undefined'): T {\n\tassert(value !== undefined, message);\n\treturn value;\n}\n\n/**\n * Asserts an array contains a single value and returns the value.\n * @param array - array to assert contains a single value.\n * @param message - Message to be printed if assertion fails.\n */\nexport function assertArrayOfOne<T>(array: readonly T[], message = 'array value must contain exactly one item'): T {\n\tassert(array.length === 1, message);\n\treturn array[0];\n}\n\n/**\n * Assign a property and value to a given object.\n * @param object - the object to add the property to\n * @param property - the property key\n * @param value - the value of the property\n * @returns `object` after assigning `value` to the property `property`.\n */\nexport function assign<T, K extends keyof never, V>(object: T, property: K, value: V): With<T, K, V> {\n\treturn Object.assign(object, { [property]: value }) as With<T, K, V>;\n}\n\n/**\n * Redefine a property to have the given value. This is simply a type-safe wrapper around\n * `Object.defineProperty`, but it is useful for caching public getters on first read.\n * @example\n * ```\n * // `randomOnce()` will return a random number, but always the same random number.\n * {\n * get randomOnce(): number {\n * return memoizeGetter(this, 'randomOnce', random(100))\n * }\n * }\n * ```\n * @param object - the object containing the property\n * @param propName - the name of the property on the object\n * @param value - the value of the property\n */\nexport function memoizeGetter<T, K extends keyof T>(object: T, propName: K, value: T[K]): T[K] {\n\tObject.defineProperty(object, propName, {\n\t\tvalue,\n\t\tenumerable: true,\n\t\tconfigurable: true,\n\t});\n\n\treturn value;\n}\n\n/**\n * Map an iterable to another iterable\n */\nexport function* map<T, R>(sequence: Iterable<T>, mapper: (t: T) => R): Iterable<R> {\n\tfor (const t of sequence) {\n\t\tyield mapper(t);\n\t}\n}\n\n/**\n * Filter an iterable into another iterable\n */\nexport function* filter<T>(sequence: Iterable<T>, filter: (t: T) => boolean): Iterable<T> {\n\tfor (const t of sequence) {\n\t\tif (filter(t)) {\n\t\t\tyield t;\n\t\t}\n\t}\n}\n\n/**\n * Reduce an iterable into a single value, or undefined if the iterable has too few elements to reduce\n */\nexport function reduce<T>(\n\tsequence: Iterable<T>,\n\treduce: (previous: T, current: T) => T,\n\tinitialValue?: T\n): T | undefined {\n\tlet previous: T | undefined;\n\tlet current: T | undefined;\n\tfor (const t of sequence) {\n\t\tcurrent = t;\n\t\tif (previous === undefined) {\n\t\t\tif (initialValue !== undefined) {\n\t\t\t\tcurrent = reduce(initialValue, current);\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent = reduce(previous, current);\n\t\t}\n\t\tprevious = current;\n\t}\n\treturn current;\n}\n\n/**\n * Returns the first element of the given sequence that satisfies the given predicate, or undefined if no such element exists\n */\nexport function find<T>(sequence: Iterable<T>, find: (t: T) => boolean): T | undefined {\n\tfor (const t of sequence) {\n\t\tif (find(t)) {\n\t\t\treturn t;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Iterate through two iterables and return true if they yield equivalent elements in the same order.\n * @param iterableA - the first iterable to compare\n * @param iterableB - the second iterable to compare\n * @param elementComparator - the function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare)\n */\nexport function compareIterables<T>(\n\titerableA: Iterable<T>,\n\titerableB: Iterable<T>,\n\telementComparator: (a: T, b: T) => boolean = Object.is\n): boolean {\n\treturn compareIterators<T>(iterableA[Symbol.iterator](), iterableB[Symbol.iterator](), elementComparator);\n}\n\n/**\n * Iterate through two iterators and return true if they yield equivalent elements in the same order.\n * @param iteratorA - the first iterator to compare\n * @param iteratorB - the second iterator to compare\n * @param elementComparator - the function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare)\n */\nfunction compareIterators<T, TReturn extends T = T>(\n\titeratorA: Iterator<T, TReturn>,\n\titeratorB: Iterator<T, TReturn>,\n\telementComparator: (a: T, b: T) => boolean = Object.is\n): boolean {\n\tlet a: IteratorResult<T, TReturn>;\n\tlet b: IteratorResult<T, TReturn>;\n\tfor (\n\t\ta = iteratorA.next(), b = iteratorB.next(); // Given two iterators...\n\t\ta.done !== true && b.done !== true; // ...while both have elements remaining...\n\t\ta = iteratorA.next(), b = iteratorB.next() // ...take one element at a time from each...\n\t) {\n\t\t// ...and ensure that their elements are equivalent\n\t\tif (!elementComparator(a.value, b.value)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// If one iterator is done, but not the other, then they are not equivalent\n\treturn a.done === b.done;\n}\n\n/**\n * Compare two arrays and return true if their elements are equivalent and in the same order.\n * @param arrayA - the first array to compare\n * @param arrayB - the second array to compare\n * @param elementComparator - the function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare)\n */\nexport function compareArrays<T>(\n\tarrayA: readonly T[],\n\tarrayB: readonly T[],\n\telementComparator: (a: T, b: T) => boolean = Object.is\n): boolean {\n\tif (arrayA.length !== arrayB.length) {\n\t\treturn false;\n\t}\n\n\tfor (let i = 0; i < arrayA.length; i++) {\n\t\tif (!elementComparator(arrayA[i], arrayB[i])) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * Compare two maps and return true if their contents are equivalent.\n * @param mapA - the first array to compare\n * @param mapB - the second array to compare\n * @param elementComparator - the function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare)\n */\nexport function compareMaps<K, V>(\n\tmapA: ReadonlyMap<K, V>,\n\tmapB: ReadonlyMap<K, V>,\n\telementComparator: (a: V, b: V) => boolean = Object.is\n): boolean {\n\tif (mapA.size !== mapB.size) {\n\t\treturn false;\n\t}\n\n\tfor (const [keyA, valueA] of mapA) {\n\t\tconst valueB = mapB.get(keyA);\n\t\tif (valueB === undefined || !elementComparator(valueA, valueB)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - the map to query/update\n * @param key - the key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n */\nexport function getOrCreate<K, V>(map: Map<K, V>, key: K, defaultValue: (key: K) => V): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n\n/**\n * Function which does nothing (no-ops).\n */\nexport function noop(): void {\n\t// noop\n}\n\n/**\n * Function which returns its input\n */\nexport function identity<T>(t: T): T {\n\treturn t;\n}\n\n/**\n * Copies a property in such a way that it is only set on `destination` if it is present on `source`.\n * This avoids having explicit undefined values under properties that would cause `Object.hasOwnProperty` to return true.\n */\nexport function copyPropertyIfDefined<TSrc, TDst>(source: TSrc, destination: TDst, property: keyof TSrc): void {\n\tconst value = source[property];\n\tif (value !== undefined) {\n\t\t(destination as any)[property] = value;\n\t}\n}\n\n/**\n * Sets a property in such a way that it is only set on `destination` if the provided value is not undefined.\n * This avoids having explicit undefined values under properties that would cause `Object.hasOwnProperty` to return true.\n */\nexport function setPropertyIfDefined<TDst, P extends keyof TDst>(\n\tvalue: TDst[P] | undefined,\n\tdestination: TDst,\n\tproperty: P\n): void {\n\tif (value !== undefined) {\n\t\tdestination[property] = value;\n\t}\n}\n\n/**\n * ```\n * function (thing: ObjectWithMaybeFoo) {\n * \t const x: MyActualType = {\n * \t bar: 3\n * };\n * \t\tx.foo = 3;\n *\n * \t copyPropertyIfDefined(thing, x, 'foo');\n * }\n * ```\n * @returns\n */\n\nfunction breakOnDifference(): { break: boolean } {\n\treturn { break: true };\n}\n\n/**\n * Helper that returns whether two b-trees are equal.\n * Accelerated when large portions of the tree are shared between the two.\n */\nexport function compareBtrees<K, V>(treeA: BTree<K, V>, treeB: BTree<K, V>, compare: (valA: V, valB: V) => boolean) {\n\tconst diff = treeA.diffAgainst(treeB, breakOnDifference, breakOnDifference, (_, valA, valB) => {\n\t\tif (!compare(valA, valB)) {\n\t\t\treturn { break: true };\n\t\t}\n\t\treturn undefined;\n\t});\n\n\treturn diff === undefined;\n}\n\nexport function backmap<K, V>(forwardmap: Map<V, K>): Map<K, V> {\n\treturn new Map(map(forwardmap, ([key, value]) => [value, key]));\n}\n\n/**\n * A developer facing (non-localized) error message.\n * TODO: better error system.\n */\nexport type ErrorString = string;\n\n/**\n * Discriminated union instance that wraps either a result of type `TOk` or an error of type `TError`.\n */\nexport type Result<TOk, TError> = Result.Ok<TOk> | Result.Error<TError>;\n\nexport namespace Result {\n\t/**\n\t * Factory function for making a successful Result.\n\t * @param result - The result to wrap in the Result.\n\t */\n\texport function ok<TOk>(result: TOk): Ok<TOk> {\n\t\treturn { type: ResultType.Ok, result };\n\t}\n\t/**\n\t * Factory function for making a unsuccessful Result.\n\t * @param error - The error to wrap in the Result.\n\t */\n\texport function error<TError>(error: TError): Error<TError> {\n\t\treturn { type: ResultType.Error, error };\n\t}\n\t/**\n\t * Type guard for successful Result.\n\t * @returns True if `result` is successful.\n\t */\n\texport function isOk<TOk, TError>(result: Result<TOk, TError>): result is Ok<TOk> {\n\t\treturn result.type === ResultType.Ok;\n\t}\n\t/**\n\t * Type guard for unsuccessful Result.\n\t * @returns True if `result` is unsuccessful.\n\t */\n\texport function isError<TOk, TError>(result: Result<TOk, TError>): result is Error<TError> {\n\t\treturn result.type === ResultType.Error;\n\t}\n\t/**\n\t * Maps the given result with the given function when the result is ok.\n\t * @param result - The result to map.\n\t * @param map - The function to apply to derive the new result.\n\t * @returns The given result if it is not ok, the mapped result otherwise.\n\t */\n\texport function mapOk<TOkIn, TOkOut, TError>(\n\t\tresult: Result<TOkIn, TError>,\n\t\tmap: (ok: TOkIn) => TOkOut\n\t): Result<TOkOut, TError> {\n\t\treturn isOk(result) ? ok(map(result.result)) : result;\n\t}\n\t/**\n\t * Maps the given result with the given function when the result is an error.\n\t * @param result - The result to map.\n\t * @param map - The function to apply to derive the new error.\n\t * @returns The given result if it is ok, the mapped result otherwise.\n\t */\n\texport function mapError<TOk, TErrorIn, TErrorOut>(\n\t\tresult: Result<TOk, TErrorIn>,\n\t\tmap: (error: TErrorIn) => TErrorOut\n\t): Result<TOk, TErrorOut> {\n\t\treturn isError(result) ? error(map(result.error)) : result;\n\t}\n\t/**\n\t * Tag value use to differentiate the members of the `Result` discriminated union.\n\t */\n\texport enum ResultType {\n\t\t/** Signals a successful result. */\n\t\tOk,\n\t\t/** Signals an unsuccessful result. */\n\t\tError,\n\t}\n\t/**\n\t * Wraps a result of type `TOk`.\n\t */\n\texport interface Ok<TOk> {\n\t\treadonly type: ResultType.Ok;\n\t\treadonly result: TOk;\n\t}\n\t/**\n\t * Wraps an error of type `TError`.\n\t */\n\texport interface Error<TError> {\n\t\treadonly type: ResultType.Error;\n\t\treadonly error: TError;\n\t}\n}\n\n/** Type that removes `readonly` from fields. */\nexport type Mutable<T> = { -readonly [P in keyof T]: T[P] };\n\n/** Type that recursively removes `readonly` from fields. */\nexport type RecursiveMutable<T> = {\n\t-readonly [K in keyof T]: RecursiveMutable<T[K]>;\n};\n\n/** Type that produces a writeable map from a readonly map. */\nexport type MutableMap<T extends ReadonlyMap<unknown, unknown>> = T extends ReadonlyMap<infer K, infer V>\n\t? Map<K, V>\n\t: never;\n\n/** Type that includes the property K: V on T */\nexport type With<T, K extends keyof never, V> = T & { [key in K]: V };\n\n/**\n * A readonly `Map` which is known to contain a value for every possible key\n */\nexport interface ClosedMap<K, V> extends Omit<Map<K, V>, 'delete' | 'clear'> {\n\tget(key: K): V;\n}\n\n/**\n * Change the given property Prop of type T to have a type of TPropNew\n */\nexport type ChangePropType<T, Prop extends keyof T, TPropNew> = Omit<T, Prop> & { [_ in Prop]: TPropNew };\n\n// eslint-disable-next-line @rushstack/no-new-null\ntype Primitive = string | number | bigint | boolean | null | symbol | undefined;\n\n/**\n * Recursively replace all properties with type assignable to type TReplace in T with properties of type TWith.\n */\nexport type ReplaceRecursive<T, TReplace, TWith> = T extends TReplace\n\t? TWith\n\t: T extends Primitive\n\t? T\n\t: {\n\t\t\t[P in keyof T]: ReplaceRecursive<T[P], TReplace, TWith>;\n\t };\n\n/** A union type of the first `N` positive integers */\nexport type TakeWholeNumbers<N extends number, A extends never[] = []> = N extends A['length']\n\t? never\n\t: A['length'] | TakeWholeNumbers<N, [never, ...A]>;\n/** Returns a tuple type with exactly `Length` elements of type `T` */\nexport type ArrayOfLength<T, Length extends number, A extends T[] = []> = Length extends A['length']\n\t? A\n\t: ArrayOfLength<T, Length, [T, ...A]>;\n/**\n * Fails if `array` does not have exactly `length` elements\n */\nexport function hasExactlyLength<T, Len extends TakeWholeNumbers<16>>(\n\tarray: readonly T[],\n\tlength: Len\n): array is ArrayOfLength<T, Len> {\n\treturn array.length === length;\n}\n/**\n * Fails if `array` does not have at least `length` elements\n */\nexport function hasLength<T, Len extends TakeWholeNumbers<16>>(\n\tarray: readonly T[],\n\tlength: Len\n): array is [...ArrayOfLength<T, Len>, ...T[]] {\n\treturn array.length >= length;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Common.js","sourceRoot":"","sources":["../src/Common.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAE9C;;;;;;;;GAQG;AACU,QAAA,4BAA4B,GAAG,qBAAqB,CAAC;AASlE;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAA0B;IAC3D,OAAQ,KAAkD,CAAC,iBAAiB,KAAK,IAAI,CAAC;AACvF,CAAC;AAFD,8CAEC;AAED;;GAEG;AACH,MAAM,wBAAyB,SAAQ,KAAK;IAG3C,YAAmB,OAAe;;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHA,cAAS,GAAG,oCAA4B,CAAC;QAIxD,IAAI,CAAC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,SAAgB,KAAK,CACpB,MAA6B,EAC7B,GAA0B;QAE1B,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACvD,CAAC;IALe,YAAK,QAKpB,CAAA;IACD;;;;;OAKG;IACH,SAAgB,QAAQ,CACvB,MAA6B,EAC7B,GAAmC;QAEnC,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5D,CAAC;IALe,eAAQ,WAKvB,CAAA;IACD;;OAEG;IACH,IAAY,UAKX;IALD,WAAY,UAAU;QACrB,mCAAmC;QACnC,uCAAE,CAAA;QACF,sCAAsC;QACtC,6CAAK,CAAA;IACN,CAAC,EALW,UAAU,GAAV,iBAAU,KAAV,iBAAU,QAKrB;AAeF,CAAC,EA5EgB,MAAM,GAAN,cAAM,KAAN,cAAM,QA4EtB;AAoDD;;GAEG;AACH,SAAgB,gBAAgB,CAC/B,KAAmB,EACnB,MAAW;IAEX,OAAO,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC;AAChC,CAAC;AALD,4CAKC;AACD;;GAEG;AACH,SAAgB,SAAS,CACxB,KAAmB,EACnB,MAAW;IAEX,OAAO,KAAK,CAAC,MAAM,IAAI,MAAM,CAAC;AAC/B,CAAC;AALD,8BAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseEvent, ITelemetryProperties } from '@fluidframework/common-definitions';\nimport BTree from 'sorted-btree';\n\nconst defaultFailMessage = 'Assertion failed';\n\n/**\n * Assertion failures in SharedTree will throw an exception containing this value as an `errorType`. The Fluid runtime propagates this field\n * in its handlings of errors thrown by containers. See\n * https://github.com/microsoft/FluidFramework/blob/main/packages/loader/container-utils/src/error.ts\n *\n * Exporting this enables users to safely filter telemetry handling of errors based on their type.\n *\n * @public\n */\nexport const sharedTreeAssertionErrorType = 'SharedTreeAssertion';\n\n/**\n * Telemetry properties decorated on all SharedTree events.\n */\nexport interface SharedTreeTelemetryProperties extends ITelemetryProperties {\n\treadonly isSharedTreeEvent: true;\n}\n\n/**\n * Returns if the supplied event is a SharedTree telemetry event.\n */\nexport function isSharedTreeEvent(event: ITelemetryBaseEvent): boolean {\n\treturn (event as unknown as SharedTreeTelemetryProperties).isSharedTreeEvent === true;\n}\n\n/**\n * Error object thrown by assertion failures in `SharedTree`.\n */\nclass SharedTreeAssertionError extends Error {\n\tpublic readonly errorType = sharedTreeAssertionErrorType;\n\n\tpublic constructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = 'Assertion error';\n\t\t// Note: conditional as `captureStackTrace` isn't defined in all browsers (e.g. Safari).\n\t\tError.captureStackTrace?.(this);\n\t}\n}\n\n/**\n * A numeric comparator used for sorting in ascending order.\n *\n * Handles +/-0 like Map: -0 is equal to +0.\n */\nexport function compareFiniteNumbers<T extends number>(a: T, b: T): number {\n\treturn a - b;\n}\n\n/**\n * A numeric comparator used for sorting in descending order.\n *\n * Handles +/-0 like Map: -0 is equal to +0.\n */\nexport function compareFiniteNumbersReversed<T extends number>(a: T, b: T): number {\n\treturn b - a;\n}\n\n/**\n * Compares strings lexically to form a strict partial ordering.\n */\nexport function compareStrings<T extends string>(a: T, b: T): number {\n\treturn a > b ? 1 : a === b ? 0 : -1;\n}\n\n/**\n * Asserts against a boolean condition. Throws an Error if the assertion failed. Will run and throw in release builds.\n * Use when violations are logic errors in the program.\n * @param condition - A condition to assert is truthy\n * @param message - Message to be printed if assertion fails. Will print \"Assertion failed\" by default\n * @param containsPII - boolean flag for whether the message passed in contains personally identifying information (PII).\n */\nexport function assert(condition: unknown, message?: string, containsPII = false): asserts condition {\n\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\tif (!condition) {\n\t\tfail(message, containsPII);\n\t}\n}\n\n/**\n * Fails an assertion. Throws an Error that the assertion failed.\n * Use when violations are logic errors in the program.\n * @param message - Message to be printed if assertion fails. Will print \"Assertion failed\" by default\n * @param containsPII - boolean flag for whether the message passed in contains personally identifying information (PII).\n */\nexport function fail(message: string = defaultFailMessage, containsPII = false): never {\n\tif (process.env.NODE_ENV !== 'production') {\n\t\tdebugger;\n\t\tconsole.error(message);\n\t}\n\n\tthrow new SharedTreeAssertionError(containsPII ? 'Assertion failed' : message);\n}\n\n/**\n * Asserts a value is not undefined, and returns the value.\n * Use when violations are logic errors in the program.\n *\n * @remarks\n * When practical, prefer the pattern `x ?? fail('message')` over `assertNotUndefined(x, 'message')`.\n * Using `?? fail` allows for message formatting without incurring the cost of formatting the message\n * in the non failing case.\n *\n * Example:\n * ```typescript\n * x ?? fail(`x should exist for ${y}`)\n * ```\n *\n * Additionally the `?? fail` avoids an extra call/stack frame in the non failing case.\n *\n * Another pattern to prefer over `assertNotUndefined(x, 'message')` is `assert(x !== undefined)`.\n * This pattern is preferred because it is more general (same approach works with typeof, instance of,\n * comparison to other values etc.).\n *\n * @param value - Value to assert against is non undefined.\n * @param message - Message to be printed if assertion fails.\n */\nexport function assertNotUndefined<T>(value: T | undefined, message = 'value must not be undefined'): T {\n\tassert(value !== undefined, message);\n\treturn value;\n}\n\n/**\n * Asserts an array contains a single value and returns the value.\n * @param array - array to assert contains a single value.\n * @param message - Message to be printed if assertion fails.\n */\nexport function assertArrayOfOne<T>(array: readonly T[], message = 'array value must contain exactly one item'): T {\n\tassert(array.length === 1, message);\n\treturn array[0];\n}\n\n/**\n * Assign a property and value to a given object.\n * @param object - the object to add the property to\n * @param property - the property key\n * @param value - the value of the property\n * @returns `object` after assigning `value` to the property `property`.\n */\nexport function assign<T, K extends keyof never, V>(object: T, property: K, value: V): With<T, K, V> {\n\treturn Object.assign(object, { [property]: value }) as With<T, K, V>;\n}\n\n/**\n * Redefine a property to have the given value. This is simply a type-safe wrapper around\n * `Object.defineProperty`, but it is useful for caching public getters on first read.\n *\n * @example\n * ```typescript\n * // `randomOnce()` will return a random number, but always the same random number.\n * {\n * get randomOnce(): number {\n * return memoizeGetter(this, 'randomOnce', random(100))\n * }\n * }\n * ```\n * @param object - the object containing the property\n * @param propName - the name of the property on the object\n * @param value - the value of the property\n */\nexport function memoizeGetter<T, K extends keyof T>(object: T, propName: K, value: T[K]): T[K] {\n\tObject.defineProperty(object, propName, {\n\t\tvalue,\n\t\tenumerable: true,\n\t\tconfigurable: true,\n\t});\n\n\treturn value;\n}\n\n/**\n * Map an iterable to another iterable\n */\nexport function* map<T, R>(sequence: Iterable<T>, mapper: (t: T) => R): Iterable<R> {\n\tfor (const t of sequence) {\n\t\tyield mapper(t);\n\t}\n}\n\n/**\n * Filter an iterable into another iterable\n */\nexport function* filter<T>(sequence: Iterable<T>, filter: (t: T) => boolean): Iterable<T> {\n\tfor (const t of sequence) {\n\t\tif (filter(t)) {\n\t\t\tyield t;\n\t\t}\n\t}\n}\n\n/**\n * Reduce an iterable into a single value, or undefined if the iterable has too few elements to reduce\n */\nexport function reduce<T>(\n\tsequence: Iterable<T>,\n\treduce: (previous: T, current: T) => T,\n\tinitialValue?: T\n): T | undefined {\n\tlet previous: T | undefined;\n\tlet current: T | undefined;\n\tfor (const t of sequence) {\n\t\tcurrent = t;\n\t\tif (previous === undefined) {\n\t\t\tif (initialValue !== undefined) {\n\t\t\t\tcurrent = reduce(initialValue, current);\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent = reduce(previous, current);\n\t\t}\n\t\tprevious = current;\n\t}\n\treturn current;\n}\n\n/**\n * Returns the first element of the given sequence that satisfies the given predicate, or undefined if no such element exists\n */\nexport function find<T>(sequence: Iterable<T>, find: (t: T) => boolean): T | undefined {\n\tfor (const t of sequence) {\n\t\tif (find(t)) {\n\t\t\treturn t;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Iterate through two iterables and return true if they yield equivalent elements in the same order.\n * @param iterableA - the first iterable to compare\n * @param iterableB - the second iterable to compare\n * @param elementComparator - the function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare)\n */\nexport function compareIterables<T>(\n\titerableA: Iterable<T>,\n\titerableB: Iterable<T>,\n\telementComparator: (a: T, b: T) => boolean = Object.is\n): boolean {\n\treturn compareIterators<T>(iterableA[Symbol.iterator](), iterableB[Symbol.iterator](), elementComparator);\n}\n\n/**\n * Iterate through two iterators and return true if they yield equivalent elements in the same order.\n * @param iteratorA - the first iterator to compare\n * @param iteratorB - the second iterator to compare\n * @param elementComparator - the function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare)\n */\nfunction compareIterators<T, TReturn extends T = T>(\n\titeratorA: Iterator<T, TReturn>,\n\titeratorB: Iterator<T, TReturn>,\n\telementComparator: (a: T, b: T) => boolean = Object.is\n): boolean {\n\tlet a: IteratorResult<T, TReturn>;\n\tlet b: IteratorResult<T, TReturn>;\n\tfor (\n\t\ta = iteratorA.next(), b = iteratorB.next(); // Given two iterators...\n\t\ta.done !== true && b.done !== true; // ...while both have elements remaining...\n\t\ta = iteratorA.next(), b = iteratorB.next() // ...take one element at a time from each...\n\t) {\n\t\t// ...and ensure that their elements are equivalent\n\t\tif (!elementComparator(a.value, b.value)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// If one iterator is done, but not the other, then they are not equivalent\n\treturn a.done === b.done;\n}\n\n/**\n * Compare two arrays and return true if their elements are equivalent and in the same order.\n * @param arrayA - the first array to compare\n * @param arrayB - the second array to compare\n * @param elementComparator - the function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare)\n */\nexport function compareArrays<T>(\n\tarrayA: readonly T[],\n\tarrayB: readonly T[],\n\telementComparator: (a: T, b: T) => boolean = Object.is\n): boolean {\n\tif (arrayA.length !== arrayB.length) {\n\t\treturn false;\n\t}\n\n\tfor (let i = 0; i < arrayA.length; i++) {\n\t\tif (!elementComparator(arrayA[i], arrayB[i])) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * Compare two maps and return true if their contents are equivalent.\n * @param mapA - the first array to compare\n * @param mapB - the second array to compare\n * @param elementComparator - the function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare)\n */\nexport function compareMaps<K, V>(\n\tmapA: ReadonlyMap<K, V>,\n\tmapB: ReadonlyMap<K, V>,\n\telementComparator: (a: V, b: V) => boolean = Object.is\n): boolean {\n\tif (mapA.size !== mapB.size) {\n\t\treturn false;\n\t}\n\n\tfor (const [keyA, valueA] of mapA) {\n\t\tconst valueB = mapB.get(keyA);\n\t\tif (valueB === undefined || !elementComparator(valueA, valueB)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - the map to query/update\n * @param key - the key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n */\nexport function getOrCreate<K, V>(map: Map<K, V>, key: K, defaultValue: (key: K) => V): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n\n/**\n * Function which does nothing (no-ops).\n */\nexport function noop(): void {\n\t// noop\n}\n\n/**\n * Function which returns its input\n */\nexport function identity<T>(t: T): T {\n\treturn t;\n}\n\n/**\n * Copies a property in such a way that it is only set on `destination` if it is present on `source`.\n * This avoids having explicit undefined values under properties that would cause `Object.hasOwnProperty` to return true.\n */\nexport function copyPropertyIfDefined<TSrc, TDst>(source: TSrc, destination: TDst, property: keyof TSrc): void {\n\tconst value = source[property];\n\tif (value !== undefined) {\n\t\t(destination as any)[property] = value;\n\t}\n}\n\n/**\n * Sets a property in such a way that it is only set on `destination` if the provided value is not undefined.\n * This avoids having explicit undefined values under properties that would cause `Object.hasOwnProperty` to return true.\n */\nexport function setPropertyIfDefined<TDst, P extends keyof TDst>(\n\tvalue: TDst[P] | undefined,\n\tdestination: TDst,\n\tproperty: P\n): void {\n\tif (value !== undefined) {\n\t\tdestination[property] = value;\n\t}\n}\n\n/**\n * @example\n * ```typescript\n * function (thing: ObjectWithMaybeFoo) {\n * \t const x: MyActualType = {\n * \t bar: 3\n * };\n * \t\tx.foo = 3;\n *\n * \t copyPropertyIfDefined(thing, x, 'foo');\n * }\n * ```\n */\n\nfunction breakOnDifference(): { break: boolean } {\n\treturn { break: true };\n}\n\n/**\n * Helper that returns whether two b-trees are equal.\n * Accelerated when large portions of the tree are shared between the two.\n */\nexport function compareBtrees<K, V>(treeA: BTree<K, V>, treeB: BTree<K, V>, compare: (valA: V, valB: V) => boolean) {\n\tconst diff = treeA.diffAgainst(treeB, breakOnDifference, breakOnDifference, (_, valA, valB) => {\n\t\tif (!compare(valA, valB)) {\n\t\t\treturn { break: true };\n\t\t}\n\t\treturn undefined;\n\t});\n\n\treturn diff === undefined;\n}\n\nexport function backmap<K, V>(forwardmap: Map<V, K>): Map<K, V> {\n\treturn new Map(map(forwardmap, ([key, value]) => [value, key]));\n}\n\n/**\n * A developer facing (non-localized) error message.\n * TODO: better error system.\n */\nexport type ErrorString = string;\n\n/**\n * Discriminated union instance that wraps either a result of type `TOk` or an error of type `TError`.\n */\nexport type Result<TOk, TError> = Result.Ok<TOk> | Result.Error<TError>;\n\nexport namespace Result {\n\t/**\n\t * Factory function for making a successful Result.\n\t * @param result - The result to wrap in the Result.\n\t */\n\texport function ok<TOk>(result: TOk): Ok<TOk> {\n\t\treturn { type: ResultType.Ok, result };\n\t}\n\t/**\n\t * Factory function for making a unsuccessful Result.\n\t * @param error - The error to wrap in the Result.\n\t */\n\texport function error<TError>(error: TError): Error<TError> {\n\t\treturn { type: ResultType.Error, error };\n\t}\n\t/**\n\t * Type guard for successful Result.\n\t * @returns True if `result` is successful.\n\t */\n\texport function isOk<TOk, TError>(result: Result<TOk, TError>): result is Ok<TOk> {\n\t\treturn result.type === ResultType.Ok;\n\t}\n\t/**\n\t * Type guard for unsuccessful Result.\n\t * @returns True if `result` is unsuccessful.\n\t */\n\texport function isError<TOk, TError>(result: Result<TOk, TError>): result is Error<TError> {\n\t\treturn result.type === ResultType.Error;\n\t}\n\t/**\n\t * Maps the given result with the given function when the result is ok.\n\t * @param result - The result to map.\n\t * @param map - The function to apply to derive the new result.\n\t * @returns The given result if it is not ok, the mapped result otherwise.\n\t */\n\texport function mapOk<TOkIn, TOkOut, TError>(\n\t\tresult: Result<TOkIn, TError>,\n\t\tmap: (ok: TOkIn) => TOkOut\n\t): Result<TOkOut, TError> {\n\t\treturn isOk(result) ? ok(map(result.result)) : result;\n\t}\n\t/**\n\t * Maps the given result with the given function when the result is an error.\n\t * @param result - The result to map.\n\t * @param map - The function to apply to derive the new error.\n\t * @returns The given result if it is ok, the mapped result otherwise.\n\t */\n\texport function mapError<TOk, TErrorIn, TErrorOut>(\n\t\tresult: Result<TOk, TErrorIn>,\n\t\tmap: (error: TErrorIn) => TErrorOut\n\t): Result<TOk, TErrorOut> {\n\t\treturn isError(result) ? error(map(result.error)) : result;\n\t}\n\t/**\n\t * Tag value use to differentiate the members of the `Result` discriminated union.\n\t */\n\texport enum ResultType {\n\t\t/** Signals a successful result. */\n\t\tOk,\n\t\t/** Signals an unsuccessful result. */\n\t\tError,\n\t}\n\t/**\n\t * Wraps a result of type `TOk`.\n\t */\n\texport interface Ok<TOk> {\n\t\treadonly type: ResultType.Ok;\n\t\treadonly result: TOk;\n\t}\n\t/**\n\t * Wraps an error of type `TError`.\n\t */\n\texport interface Error<TError> {\n\t\treadonly type: ResultType.Error;\n\t\treadonly error: TError;\n\t}\n}\n\n/** Type that removes `readonly` from fields. */\nexport type Mutable<T> = { -readonly [P in keyof T]: T[P] };\n\n/** Type that recursively removes `readonly` from fields. */\nexport type RecursiveMutable<T> = {\n\t-readonly [K in keyof T]: RecursiveMutable<T[K]>;\n};\n\n/** Type that produces a writeable map from a readonly map. */\nexport type MutableMap<T extends ReadonlyMap<unknown, unknown>> = T extends ReadonlyMap<infer K, infer V>\n\t? Map<K, V>\n\t: never;\n\n/** Type that includes the property K: V on T */\nexport type With<T, K extends keyof never, V> = T & { [key in K]: V };\n\n/**\n * A readonly `Map` which is known to contain a value for every possible key\n */\nexport interface ClosedMap<K, V> extends Omit<Map<K, V>, 'delete' | 'clear'> {\n\tget(key: K): V;\n}\n\n/**\n * Change the given property Prop of type T to have a type of TPropNew\n */\nexport type ChangePropType<T, Prop extends keyof T, TPropNew> = Omit<T, Prop> & { [_ in Prop]: TPropNew };\n\n// eslint-disable-next-line @rushstack/no-new-null\ntype Primitive = string | number | bigint | boolean | null | symbol | undefined;\n\n/**\n * Recursively replace all properties with type assignable to type TReplace in T with properties of type TWith.\n */\nexport type ReplaceRecursive<T, TReplace, TWith> = T extends TReplace\n\t? TWith\n\t: T extends Primitive\n\t? T\n\t: {\n\t\t\t[P in keyof T]: ReplaceRecursive<T[P], TReplace, TWith>;\n\t };\n\n/** A union type of the first `N` positive integers */\nexport type TakeWholeNumbers<N extends number, A extends never[] = []> = N extends A['length']\n\t? never\n\t: A['length'] | TakeWholeNumbers<N, [never, ...A]>;\n/** Returns a tuple type with exactly `Length` elements of type `T` */\nexport type ArrayOfLength<T, Length extends number, A extends T[] = []> = Length extends A['length']\n\t? A\n\t: ArrayOfLength<T, Length, [T, ...A]>;\n/**\n * Fails if `array` does not have exactly `length` elements\n */\nexport function hasExactlyLength<T, Len extends TakeWholeNumbers<16>>(\n\tarray: readonly T[],\n\tlength: Len\n): array is ArrayOfLength<T, Len> {\n\treturn array.length === length;\n}\n/**\n * Fails if `array` does not have at least `length` elements\n */\nexport function hasLength<T, Len extends TakeWholeNumbers<16>>(\n\tarray: readonly T[],\n\tlength: Len\n): array is [...ArrayOfLength<T, Len>, ...T[]] {\n\treturn array.length >= length;\n}\n"]}
|
package/dist/SharedTree.d.ts
CHANGED
|
@@ -186,6 +186,14 @@ export declare type EditCommittedHandler = (args: EditCommittedEventArguments) =
|
|
|
186
186
|
* @public
|
|
187
187
|
*/
|
|
188
188
|
export declare type SequencedEditAppliedHandler = (args: SequencedEditAppliedEventArguments) => void;
|
|
189
|
+
/**
|
|
190
|
+
* Contains information resulting from processing stashed shared tree ops
|
|
191
|
+
* @public
|
|
192
|
+
*/
|
|
193
|
+
export interface StashedLocalOpMetadata {
|
|
194
|
+
/** A modified version of the edit in an edit op that should be resubmitted rather than the original edit */
|
|
195
|
+
transformedEdit?: Edit<ChangeInternal>;
|
|
196
|
+
}
|
|
189
197
|
/**
|
|
190
198
|
* A [distributed tree](../Readme.md).
|
|
191
199
|
* @public
|
|
@@ -218,6 +226,8 @@ export declare class SharedTree extends SharedObject<ISharedTreeEvents> implemen
|
|
|
218
226
|
get attributionId(): AttributionId;
|
|
219
227
|
private idCompressor;
|
|
220
228
|
private readonly idNormalizer;
|
|
229
|
+
/** Temporarily created to apply stashed ops from a previous session */
|
|
230
|
+
private stashedIdCompressor?;
|
|
221
231
|
private interner;
|
|
222
232
|
/**
|
|
223
233
|
* The log of completed edits for this SharedTree.
|
|
@@ -495,7 +505,8 @@ export declare class SharedTree extends SharedObject<ISharedTreeEvents> implemen
|
|
|
495
505
|
*
|
|
496
506
|
* @param content - op to apply locally.
|
|
497
507
|
*/
|
|
498
|
-
protected applyStashedOp(op: unknown):
|
|
508
|
+
protected applyStashedOp(op: unknown): StashedLocalOpMetadata;
|
|
509
|
+
protected reSubmitCore(op: unknown, localOpMetadata?: StashedLocalOpMetadata): void;
|
|
499
510
|
private changeWriteFormat;
|
|
500
511
|
/**
|
|
501
512
|
* Interns all Definitions and TraitLabel_s referenced by the provided edit.
|
package/dist/SharedTree.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharedTree.d.ts","sourceRoot":"","sources":["../src/SharedTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,sBAAsB,EACtB,sBA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AS,CAAC,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,eAAe,CAAC,EAAE,sBAAsB,GAAG,IAAI;IAoBnF,OAAO,CAAC,iBAAiB;IAKzB;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;CAuB7B"}
|
package/dist/SharedTree.js
CHANGED
|
@@ -101,6 +101,8 @@ const snapshotFileName = 'header';
|
|
|
101
101
|
*/
|
|
102
102
|
const sortedWriteVersions = [persisted_types_1.WriteFormat.v0_0_2, persisted_types_1.WriteFormat.v0_1_1];
|
|
103
103
|
const sharedTreeTelemetryProperties = { all: { isSharedTreeEvent: true } };
|
|
104
|
+
/** The SessionId of the temporary IdCompressor that records stashed ops */
|
|
105
|
+
const stashedSessionId = '8477b8d5-cf6c-4673-8345-8f076a8f9bc6';
|
|
104
106
|
/**
|
|
105
107
|
* A [distributed tree](../Readme.md).
|
|
106
108
|
* @public
|
|
@@ -1040,19 +1042,20 @@ class SharedTree extends shared_object_base_1.SharedObject {
|
|
|
1040
1042
|
* @param content - op to apply locally.
|
|
1041
1043
|
*/
|
|
1042
1044
|
applyStashedOp(op) {
|
|
1045
|
+
// In some scenarios, edit ops need to have their edits transformed before application and resubmission. The transformation
|
|
1046
|
+
// occurs in this method, and the result is passed to `resubmitCore` via the return value of this function.
|
|
1043
1047
|
const sharedTreeOp = op;
|
|
1044
1048
|
switch (sharedTreeOp.type) {
|
|
1045
1049
|
case persisted_types_1.SharedTreeOpType.Edit: {
|
|
1050
|
+
let stashedEdit;
|
|
1046
1051
|
switch (this.writeFormat) {
|
|
1047
1052
|
case persisted_types_1.WriteFormat.v0_0_2:
|
|
1048
1053
|
switch (sharedTreeOp.version) {
|
|
1049
1054
|
case persisted_types_1.WriteFormat.v0_0_2: {
|
|
1050
|
-
|
|
1051
|
-
this.applyEditLocally(edit, undefined);
|
|
1055
|
+
stashedEdit = this.parseSequencedEdit(sharedTreeOp);
|
|
1052
1056
|
break;
|
|
1053
1057
|
}
|
|
1054
1058
|
case persisted_types_1.WriteFormat.v0_1_1:
|
|
1055
|
-
// TODO:#74390: Implement
|
|
1056
1059
|
(0, Common_1.fail)('Received stashed op 0.1.1 before upgrade');
|
|
1057
1060
|
default:
|
|
1058
1061
|
(0, Common_1.fail)('Unknown version');
|
|
@@ -1060,29 +1063,76 @@ class SharedTree extends shared_object_base_1.SharedObject {
|
|
|
1060
1063
|
break;
|
|
1061
1064
|
case persisted_types_1.WriteFormat.v0_1_1:
|
|
1062
1065
|
switch (sharedTreeOp.version) {
|
|
1063
|
-
case persisted_types_1.WriteFormat.v0_0_2:
|
|
1064
|
-
//
|
|
1065
|
-
(0,
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1066
|
+
case persisted_types_1.WriteFormat.v0_0_2: {
|
|
1067
|
+
// Use the IDs from the stashed ops as overrides for the equivalent new ops
|
|
1068
|
+
stashedEdit = (0, IdConversion_1.convertEditIds)(sharedTreeOp.edit, (id) => this.generateNodeId(id));
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1071
|
+
case persisted_types_1.WriteFormat.v0_1_1: {
|
|
1072
|
+
(0, Common_1.assert)(this.stashedIdCompressor !== null, 'Stashed op applied after expected window');
|
|
1073
|
+
if (this.stashedIdCompressor === undefined) {
|
|
1074
|
+
// Use a temporary compressor that will help translate the stashed ops
|
|
1075
|
+
this.stashedIdCompressor = id_compressor_1.IdCompressor.deserialize(this.idCompressor.serialize(false), stashedSessionId, sharedTreeOp.idRange.attributionId);
|
|
1076
|
+
// Once all stashed ops have been applied, clear the temporary state
|
|
1077
|
+
this.runtime.on('connected', () => {
|
|
1078
|
+
this.stashedIdCompressor = null;
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
// Pretend (from the perspective of the temporary compressor) that the stashed ops have been sequenced
|
|
1082
|
+
this.stashedIdCompressor.finalizeCreationRange(sharedTreeOp.idRange);
|
|
1083
|
+
const stashedIdContext = (0, NodeIdUtilities_1.getNodeIdContext)(this.stashedIdCompressor);
|
|
1084
|
+
// Use a normalizer to translate all node IDs in the stashed ops
|
|
1085
|
+
const normalizer = {
|
|
1086
|
+
localSessionId: this.idCompressor.localSessionId,
|
|
1087
|
+
normalizeToSessionSpace: (id, _sessionId) => {
|
|
1088
|
+
// Interpret the IDs from the stashed ops as stable IDs, and use those as overrides for the equivalent new ops
|
|
1089
|
+
const sessionSpaceId = stashedIdContext.normalizeToSessionSpace(id, sharedTreeOp.idRange.sessionId);
|
|
1090
|
+
return this.generateNodeId(stashedIdContext.convertToStableNodeId(sessionSpaceId));
|
|
1091
|
+
},
|
|
1092
|
+
normalizeToOpSpace: (id) => this.idNormalizer.normalizeToOpSpace(id),
|
|
1093
|
+
};
|
|
1094
|
+
stashedEdit = this.encoder_0_1_1.decodeEditOp(sharedTreeOp, this.encodeSemiSerializedEdit.bind(this), normalizer, this.interner);
|
|
1095
|
+
break;
|
|
1096
|
+
}
|
|
1069
1097
|
default:
|
|
1070
1098
|
(0, Common_1.fail)('Unknown version');
|
|
1071
1099
|
}
|
|
1100
|
+
break;
|
|
1072
1101
|
default:
|
|
1073
1102
|
(0, Common_1.fail)('Unknown version');
|
|
1074
1103
|
}
|
|
1075
|
-
|
|
1104
|
+
this.applyEditLocally(stashedEdit, undefined);
|
|
1105
|
+
return { transformedEdit: stashedEdit };
|
|
1076
1106
|
}
|
|
1077
1107
|
// Handle and update ops are only acknowledged by the client that generated them upon sequencing--no local changes necessary.
|
|
1078
1108
|
case persisted_types_1.SharedTreeOpType.Handle:
|
|
1079
1109
|
case persisted_types_1.SharedTreeOpType.Update:
|
|
1080
1110
|
case persisted_types_1.SharedTreeOpType.NoOp:
|
|
1081
|
-
|
|
1111
|
+
return {};
|
|
1082
1112
|
default:
|
|
1083
1113
|
(0, Common_1.fail)('Unrecognized op');
|
|
1084
1114
|
}
|
|
1085
1115
|
}
|
|
1116
|
+
reSubmitCore(op, localOpMetadata) {
|
|
1117
|
+
const sharedTreeOp = op;
|
|
1118
|
+
switch (sharedTreeOp.type) {
|
|
1119
|
+
case persisted_types_1.SharedTreeOpType.Edit:
|
|
1120
|
+
if (compareSummaryFormatVersions(sharedTreeOp.version, this.writeFormat) > 0) {
|
|
1121
|
+
(0, Common_1.fail)('Attempted to resubmit op of version newer than current version');
|
|
1122
|
+
}
|
|
1123
|
+
else if ((localOpMetadata === null || localOpMetadata === void 0 ? void 0 : localOpMetadata.transformedEdit) !== undefined) {
|
|
1124
|
+
// Optimization: stashed 0.0.2 ops require no transformation in 0.0.2; don't re-encode
|
|
1125
|
+
if (this.writeFormat !== persisted_types_1.WriteFormat.v0_0_2 || sharedTreeOp.version !== persisted_types_1.WriteFormat.v0_0_2) {
|
|
1126
|
+
this.submitEditOp(localOpMetadata.transformedEdit);
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
break;
|
|
1131
|
+
default:
|
|
1132
|
+
break;
|
|
1133
|
+
}
|
|
1134
|
+
super.reSubmitCore(sharedTreeOp, localOpMetadata);
|
|
1135
|
+
}
|
|
1086
1136
|
changeWriteFormat(newFormat) {
|
|
1087
1137
|
this.writeFormat = newFormat;
|
|
1088
1138
|
this.emit(EventTypes_1.SharedTreeDiagnosticEvent.WriteVersionChanged, newFormat);
|