@fluidframework/tree 2.12.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +136 -0
- package/api-report/tree.alpha.api.md +86 -10
- package/api-report/tree.beta.api.md +22 -10
- package/api-report/tree.legacy.alpha.api.md +22 -10
- package/api-report/tree.legacy.public.api.md +22 -10
- package/api-report/tree.public.api.md +22 -10
- package/dist/alpha.d.ts +11 -0
- package/dist/beta.d.ts +2 -0
- package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
- package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
- package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +0 -1
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +2 -4
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.js +8 -2
- package/dist/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +12 -5
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.js +2 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
- package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
- package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +1 -0
- package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js +89 -25
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +12 -0
- package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
- package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
- package/dist/feature-libraries/optional-field/optionalField.js +24 -4
- package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
- package/dist/feature-libraries/sequence-field/utils.d.ts +2 -2
- package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/utils.js +14 -5
- package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/legacy.d.ts +2 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +2 -0
- package/dist/shared-tree/index.d.ts +2 -1
- package/dist/shared-tree/index.d.ts.map +1 -1
- package/dist/shared-tree/index.js +2 -1
- package/dist/shared-tree/index.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts +10 -1
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +43 -0
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +6 -3
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +3 -1
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/transactionTypes.d.ts +105 -0
- package/dist/shared-tree/transactionTypes.d.ts.map +1 -0
- package/dist/shared-tree/transactionTypes.js +13 -0
- package/dist/shared-tree/transactionTypes.js.map +1 -0
- package/dist/shared-tree/treeApi.d.ts +1 -25
- package/dist/shared-tree/treeApi.d.ts.map +1 -1
- package/dist/shared-tree/treeApi.js +4 -8
- package/dist/shared-tree/treeApi.js.map +1 -1
- package/dist/shared-tree/treeCheckout.d.ts +4 -1
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +130 -15
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +1 -0
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +3 -1
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/jsonSchema.d.ts +6 -0
- package/dist/simple-tree/api/jsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/jsonSchema.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +21 -12
- package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactory.js +5 -2
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.js +90 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
- package/dist/simple-tree/api/simpleSchema.d.ts +5 -1
- package/dist/simple-tree/api/simpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/simpleSchema.js.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +13 -10
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
- package/dist/simple-tree/api/tree.d.ts +60 -0
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +11 -11
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/dist/simple-tree/arrayNode.d.ts +2 -2
- package/dist/simple-tree/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/arrayNode.js +2 -1
- package/dist/simple-tree/arrayNode.js.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.d.ts +10 -6
- package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/dist/simple-tree/index.d.ts +2 -2
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +3 -2
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/leafNodeSchema.d.ts +5 -5
- package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/mapNode.d.ts +2 -2
- package/dist/simple-tree/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/mapNode.js +2 -1
- package/dist/simple-tree/mapNode.js.map +1 -1
- package/dist/simple-tree/objectNode.d.ts +2 -2
- package/dist/simple-tree/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/objectNode.js +2 -1
- package/dist/simple-tree/objectNode.js.map +1 -1
- package/dist/simple-tree/objectNodeTypes.d.ts +2 -2
- package/dist/simple-tree/objectNodeTypes.d.ts.map +1 -1
- package/dist/simple-tree/objectNodeTypes.js.map +1 -1
- package/dist/simple-tree/schemaTypes.d.ts +47 -1
- package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
- package/dist/simple-tree/schemaTypes.js.map +1 -1
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +3 -5
- package/dist/util/index.js.map +1 -1
- package/dist/util/rangeMap.d.ts +72 -42
- package/dist/util/rangeMap.d.ts.map +1 -1
- package/dist/util/rangeMap.js +161 -151
- package/dist/util/rangeMap.js.map +1 -1
- package/dist/util/utils.d.ts +22 -1
- package/dist/util/utils.d.ts.map +1 -1
- package/dist/util/utils.js +10 -1
- package/dist/util/utils.js.map +1 -1
- package/lib/alpha.d.ts +11 -0
- package/lib/beta.d.ts +2 -0
- package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
- package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
- package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +0 -1
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +0 -1
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.js +9 -3
- package/lib/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +12 -5
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.js +2 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
- package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
- package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +1 -0
- package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js +89 -25
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +12 -0
- package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
- package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
- package/lib/feature-libraries/optional-field/optionalField.js +24 -4
- package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
- package/lib/feature-libraries/sequence-field/utils.d.ts +2 -2
- package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/utils.js +14 -5
- package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/legacy.d.ts +2 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +2 -0
- package/lib/shared-tree/index.d.ts +2 -1
- package/lib/shared-tree/index.d.ts.map +1 -1
- package/lib/shared-tree/index.js +2 -1
- package/lib/shared-tree/index.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts +10 -1
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +46 -3
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +6 -3
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +3 -1
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/transactionTypes.d.ts +105 -0
- package/lib/shared-tree/transactionTypes.d.ts.map +1 -0
- package/lib/shared-tree/transactionTypes.js +10 -0
- package/lib/shared-tree/transactionTypes.js.map +1 -0
- package/lib/shared-tree/treeApi.d.ts +1 -25
- package/lib/shared-tree/treeApi.d.ts.map +1 -1
- package/lib/shared-tree/treeApi.js +1 -5
- package/lib/shared-tree/treeApi.js.map +1 -1
- package/lib/shared-tree/treeCheckout.d.ts +4 -1
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +130 -15
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +1 -0
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +1 -0
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/jsonSchema.d.ts +6 -0
- package/lib/simple-tree/api/jsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/jsonSchema.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +21 -12
- package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactory.js +5 -2
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.js +86 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
- package/lib/simple-tree/api/simpleSchema.d.ts +5 -1
- package/lib/simple-tree/api/simpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/simpleSchema.js.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +14 -11
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
- package/lib/simple-tree/api/tree.d.ts +60 -0
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +12 -12
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/lib/simple-tree/arrayNode.d.ts +2 -2
- package/lib/simple-tree/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/arrayNode.js +2 -1
- package/lib/simple-tree/arrayNode.js.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.d.ts +10 -6
- package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/lib/simple-tree/index.d.ts +2 -2
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +1 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/leafNodeSchema.d.ts +5 -5
- package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/mapNode.d.ts +2 -2
- package/lib/simple-tree/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/mapNode.js +2 -1
- package/lib/simple-tree/mapNode.js.map +1 -1
- package/lib/simple-tree/objectNode.d.ts +2 -2
- package/lib/simple-tree/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/objectNode.js +2 -1
- package/lib/simple-tree/objectNode.js.map +1 -1
- package/lib/simple-tree/objectNodeTypes.d.ts +2 -2
- package/lib/simple-tree/objectNodeTypes.d.ts.map +1 -1
- package/lib/simple-tree/objectNodeTypes.js.map +1 -1
- package/lib/simple-tree/schemaTypes.d.ts +47 -1
- package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
- package/lib/simple-tree/schemaTypes.js.map +1 -1
- package/lib/util/index.d.ts +2 -2
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +2 -2
- package/lib/util/index.js.map +1 -1
- package/lib/util/rangeMap.d.ts +72 -42
- package/lib/util/rangeMap.d.ts.map +1 -1
- package/lib/util/rangeMap.js +159 -146
- package/lib/util/rangeMap.js.map +1 -1
- package/lib/util/utils.d.ts +22 -1
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js +8 -0
- package/lib/util/utils.js.map +1 -1
- package/package.json +22 -22
- package/src/feature-libraries/default-schema/defaultEditBuilder.ts +14 -1
- package/src/feature-libraries/index.ts +0 -1
- package/src/feature-libraries/modular-schema/crossFieldQueries.ts +9 -9
- package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +13 -9
- package/src/feature-libraries/modular-schema/genericFieldKind.ts +4 -2
- package/src/feature-libraries/modular-schema/index.ts +1 -0
- package/src/feature-libraries/modular-schema/modularChangeFamily.ts +124 -31
- package/src/feature-libraries/modular-schema/modularChangeTypes.ts +12 -0
- package/src/feature-libraries/optional-field/optionalField.ts +34 -5
- package/src/feature-libraries/sequence-field/utils.ts +18 -7
- package/src/index.ts +11 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/index.ts +12 -2
- package/src/shared-tree/schematizingTreeView.ts +91 -2
- package/src/shared-tree/sharedTree.ts +9 -4
- package/src/shared-tree/transactionTypes.ts +125 -0
- package/src/shared-tree/treeApi.ts +1 -28
- package/src/shared-tree/treeCheckout.ts +147 -13
- package/src/shared-tree-core/sharedTreeCore.ts +1 -1
- package/src/simple-tree/api/index.ts +1 -0
- package/src/simple-tree/api/jsonSchema.ts +7 -0
- package/src/simple-tree/api/schemaFactory.ts +33 -6
- package/src/simple-tree/api/schemaFactoryAlpha.ts +253 -0
- package/src/simple-tree/api/simpleSchema.ts +6 -1
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +22 -12
- package/src/simple-tree/api/tree.ts +76 -4
- package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +19 -13
- package/src/simple-tree/arrayNode.ts +7 -1
- package/src/simple-tree/core/treeNodeSchema.ts +51 -7
- package/src/simple-tree/index.ts +3 -0
- package/src/simple-tree/mapNode.ts +7 -1
- package/src/simple-tree/objectNode.ts +7 -1
- package/src/simple-tree/objectNodeTypes.ts +4 -1
- package/src/simple-tree/schemaTypes.ts +50 -1
- package/src/util/index.ts +2 -6
- package/src/util/rangeMap.ts +199 -189
- package/src/util/utils.ts +47 -1
- package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
- package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
- package/dist/feature-libraries/memoizedIdRangeAllocator.js +0 -74
- package/dist/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
- package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
- package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
- package/lib/feature-libraries/memoizedIdRangeAllocator.js +0 -71
- package/lib/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
- package/src/feature-libraries/memoizedIdRangeAllocator.ts +0 -112
package/lib/util/rangeMap.js
CHANGED
|
@@ -4,164 +4,177 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { oob } from "@fluidframework/core-utils/internal";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* RangeMap represents a mapping from integers to values of type T or undefined.
|
|
8
|
+
* The values for a range of consecutive keys can be changed or queried in a single operation.
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
export class RangeMap {
|
|
11
|
+
constructor(initialEntries) {
|
|
12
|
+
this.entries = initialEntries ? [...initialEntries] : [];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves all entries from the rangeMap.
|
|
16
|
+
* @returns An array of RangeEntryResult objects, each containing the start index, length, and value of a contiguous range.
|
|
17
|
+
*/
|
|
18
|
+
getAllEntries() {
|
|
19
|
+
return this.entries;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the value for some prefix of the query range.
|
|
23
|
+
*
|
|
24
|
+
* @param start - The first key in the query range.
|
|
25
|
+
* @param length - The length of the query range.
|
|
26
|
+
* @returns A RangeQueryResult containing the value associated with `start`,
|
|
27
|
+
* and the number of consecutive keys with that same value.
|
|
28
|
+
*/
|
|
29
|
+
get(start, length) {
|
|
30
|
+
for (const entry of this.entries) {
|
|
31
|
+
if (entry.start > start) {
|
|
32
|
+
return { value: undefined, length: Math.min(entry.start - start, length) };
|
|
33
|
+
}
|
|
34
|
+
const lastRangeKey = entry.start + entry.length - 1;
|
|
35
|
+
if (lastRangeKey >= start) {
|
|
36
|
+
const overlapLength = lastRangeKey - start + 1;
|
|
37
|
+
return { value: entry.value, length: Math.min(overlapLength, length) };
|
|
38
|
+
}
|
|
19
39
|
}
|
|
40
|
+
// There were no entries intersecting the query range, so the entire query range has undefined value.
|
|
41
|
+
return { value: undefined, length };
|
|
20
42
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Sets the value for a specified range.
|
|
45
|
+
*
|
|
46
|
+
* @param start - The first key in the range being set.
|
|
47
|
+
* @param length - The length of the range.
|
|
48
|
+
* @param value - The value to associate with the range.
|
|
49
|
+
*/
|
|
50
|
+
set(start, length, value) {
|
|
51
|
+
if (value === undefined) {
|
|
52
|
+
this.delete(start, length);
|
|
53
|
+
return;
|
|
30
54
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
55
|
+
const end = start + length - 1;
|
|
56
|
+
const newEntry = { start, length, value };
|
|
57
|
+
let iBefore = -1;
|
|
58
|
+
let iAfter = this.entries.length;
|
|
59
|
+
for (const [i, entry] of this.entries.entries()) {
|
|
60
|
+
const entryLastKey = entry.start + entry.length - 1;
|
|
61
|
+
if (entryLastKey < start) {
|
|
62
|
+
iBefore = i;
|
|
63
|
+
}
|
|
64
|
+
else if (entry.start > end) {
|
|
65
|
+
iAfter = i;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
34
68
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* Sets the keys from `start` to `start + length - 1` to `value`.
|
|
40
|
-
*/
|
|
41
|
-
export function setInRangeMap(map, start, length, value) {
|
|
42
|
-
const end = start + length - 1;
|
|
43
|
-
const newEntry = { start, length, value };
|
|
44
|
-
let iBefore = -1;
|
|
45
|
-
let iAfter = map.length;
|
|
46
|
-
for (const [i, entry] of map.entries()) {
|
|
47
|
-
const entryLastKey = entry.start + entry.length - 1;
|
|
48
|
-
if (entryLastKey < start) {
|
|
49
|
-
iBefore = i;
|
|
69
|
+
const numOverlappingEntries = iAfter - iBefore - 1;
|
|
70
|
+
if (numOverlappingEntries === 0) {
|
|
71
|
+
this.entries.splice(iAfter, 0, newEntry);
|
|
72
|
+
return;
|
|
50
73
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
74
|
+
const iFirst = iBefore + 1;
|
|
75
|
+
const firstEntry = this.entries[iFirst] ?? oob();
|
|
76
|
+
const iLast = iAfter - 1;
|
|
77
|
+
const lastEntry = this.entries[iLast] ?? oob();
|
|
78
|
+
const lengthBeforeFirst = start - firstEntry.start;
|
|
79
|
+
const lastEntryKey = lastEntry.start + lastEntry.length - 1;
|
|
80
|
+
const lengthAfterLast = lastEntryKey - end;
|
|
81
|
+
if (lengthBeforeFirst > 0 && lengthAfterLast > 0 && iFirst === iLast) {
|
|
82
|
+
// The new entry fits in the middle of an existing entry.
|
|
83
|
+
// We replace the existing entry with:
|
|
84
|
+
// 1) the portion which comes before `newEntry`
|
|
85
|
+
// 2) `newEntry`
|
|
86
|
+
// 3) the portion which comes after `newEntry`
|
|
87
|
+
this.entries.splice(iFirst, 1, { ...firstEntry, length: lengthBeforeFirst }, newEntry, {
|
|
88
|
+
...lastEntry,
|
|
89
|
+
start: end + 1,
|
|
90
|
+
length: lengthAfterLast,
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
54
93
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const iFirst = iBefore + 1;
|
|
62
|
-
const firstEntry = map[iFirst] ?? oob();
|
|
63
|
-
const iLast = iAfter - 1;
|
|
64
|
-
const lastEntry = map[iLast] ?? oob();
|
|
65
|
-
const lengthBeforeFirst = start - firstEntry.start;
|
|
66
|
-
const lastEntryKey = lastEntry.start + lastEntry.length - 1;
|
|
67
|
-
const lengthAfterLast = lastEntryKey - end;
|
|
68
|
-
if (lengthBeforeFirst > 0 && lengthAfterLast > 0 && iFirst === iLast) {
|
|
69
|
-
// The new entry fits in the middle of an existing entry.
|
|
70
|
-
// We replace the existing entry with:
|
|
71
|
-
// 1) the portion which comes before `newEntry`
|
|
72
|
-
// 2) `newEntry`
|
|
73
|
-
// 3) the portion which comes after `newEntry`
|
|
74
|
-
map.splice(iFirst, 1, { ...firstEntry, length: lengthBeforeFirst }, newEntry, {
|
|
75
|
-
...lastEntry,
|
|
76
|
-
start: end + 1,
|
|
77
|
-
length: lengthAfterLast,
|
|
78
|
-
});
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (lengthBeforeFirst > 0) {
|
|
82
|
-
map[iFirst] = { ...firstEntry, length: lengthBeforeFirst };
|
|
83
|
-
// The entry at `iFirst` is no longer overlapping with `newEntry`.
|
|
84
|
-
iBefore = iFirst;
|
|
85
|
-
}
|
|
86
|
-
if (lengthAfterLast > 0) {
|
|
87
|
-
map[iLast] = {
|
|
88
|
-
...lastEntry,
|
|
89
|
-
start: end + 1,
|
|
90
|
-
length: lengthAfterLast,
|
|
91
|
-
};
|
|
92
|
-
// The entry at `iLast` is no longer overlapping with `newEntry`.
|
|
93
|
-
iAfter = iLast;
|
|
94
|
-
}
|
|
95
|
-
const numContainedEntries = iAfter - iBefore - 1;
|
|
96
|
-
map.splice(iBefore + 1, numContainedEntries, newEntry);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Delete the keys from `start` to `start + length - 1`
|
|
100
|
-
*
|
|
101
|
-
* 1. If an entry is completely included in the deletion range, the whole entry will be deleted
|
|
102
|
-
* e.g.: map = [[1, 2], [4, 6]], delete range: [3, 6]
|
|
103
|
-
* map becomes [[1, 2]] after deletion
|
|
104
|
-
* (Note: the notation [a, b] represents start = a, end = b for simpler visiualization, instead of `b`
|
|
105
|
-
* representing the length)
|
|
106
|
-
*
|
|
107
|
-
* 2. If an entry is partially overlapped with the deletion range, the start or end point will be shifted
|
|
108
|
-
* e.g.: map = [[1, 2], [4, 6]], delete range: [2, 4]
|
|
109
|
-
* map becomes [[1, 1], [5, 6]] after deletion
|
|
110
|
-
*
|
|
111
|
-
* 3. If an entry completely includes the deletion range, the original entry may be split into two.
|
|
112
|
-
* e.g.: map = [[1, 6]], delete range: [2, 4]
|
|
113
|
-
* map becomes [[1, 1], [5, 6]]
|
|
114
|
-
*
|
|
115
|
-
* TODO: We may find ways to mitigate the code duplication between set and delete, and we need to better
|
|
116
|
-
* document the API. AB#7413
|
|
117
|
-
*/
|
|
118
|
-
export function deleteFromRangeMap(map, start, length) {
|
|
119
|
-
const end = start + length - 1;
|
|
120
|
-
let iBefore = -1;
|
|
121
|
-
let iAfter = map.length;
|
|
122
|
-
for (const [i, entry] of map.entries()) {
|
|
123
|
-
const entryLastKey = entry.start + entry.length - 1;
|
|
124
|
-
if (entryLastKey < start) {
|
|
125
|
-
iBefore = i;
|
|
94
|
+
if (lengthBeforeFirst > 0) {
|
|
95
|
+
this.entries[iFirst] = { ...firstEntry, length: lengthBeforeFirst };
|
|
96
|
+
// The entry at `iFirst` is no longer overlapping with `newEntry`.
|
|
97
|
+
iBefore = iFirst;
|
|
126
98
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
99
|
+
if (lengthAfterLast > 0) {
|
|
100
|
+
this.entries[iLast] = {
|
|
101
|
+
...lastEntry,
|
|
102
|
+
start: end + 1,
|
|
103
|
+
length: lengthAfterLast,
|
|
104
|
+
};
|
|
105
|
+
// The entry at `iLast` is no longer overlapping with `newEntry`.
|
|
106
|
+
iAfter = iLast;
|
|
130
107
|
}
|
|
108
|
+
const numContainedEntries = iAfter - iBefore - 1;
|
|
109
|
+
this.entries.splice(iBefore + 1, numContainedEntries, newEntry);
|
|
131
110
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Deletes values within a specified range, updating or removing existing entries.
|
|
113
|
+
*
|
|
114
|
+
* 1. If an entry is completely included in the deletion range, the whole entry will be deleted
|
|
115
|
+
* e.g.: map = [[1, 2], [4, 6]], delete range: [3, 6]
|
|
116
|
+
* map becomes [[1, 2]] after deletion
|
|
117
|
+
* (Note: the notation [a, b] represents start = a, end = b for simpler visualization, instead of `b`
|
|
118
|
+
* representing the length)
|
|
119
|
+
*
|
|
120
|
+
* 2. If an entry is partially overlapped with the deletion range, the start or end point will be shifted
|
|
121
|
+
* e.g.: map = [[1, 2], [4, 6]], delete range: [2, 4]
|
|
122
|
+
* map becomes [[1, 1], [5, 6]] after deletion
|
|
123
|
+
*
|
|
124
|
+
* 3. If an entry completely includes the deletion range, the original entry may be split into two.
|
|
125
|
+
* e.g.: map = [[1, 6]], delete range: [2, 4]
|
|
126
|
+
* map becomes [[1, 1], [5, 6]]
|
|
127
|
+
*
|
|
128
|
+
* @param start - The start of the range to delete (inclusive).
|
|
129
|
+
* @param length - The length of the range to delete.
|
|
130
|
+
*/
|
|
131
|
+
delete(start, length) {
|
|
132
|
+
const end = start + length - 1;
|
|
133
|
+
let iBefore = -1;
|
|
134
|
+
let iAfter = this.entries.length;
|
|
135
|
+
for (const [i, entry] of this.entries.entries()) {
|
|
136
|
+
const entryLastKey = entry.start + entry.length - 1;
|
|
137
|
+
if (entryLastKey < start) {
|
|
138
|
+
iBefore = i;
|
|
139
|
+
}
|
|
140
|
+
else if (entry.start > end) {
|
|
141
|
+
iAfter = i;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const numOverlappingEntries = iAfter - iBefore - 1;
|
|
146
|
+
if (numOverlappingEntries === 0) {
|
|
147
|
+
// No entry will be removed
|
|
148
|
+
return;
|
|
147
149
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
const iFirst = iBefore + 1;
|
|
151
|
+
const iLast = iAfter - 1;
|
|
152
|
+
for (let i = iFirst; i <= iLast; ++i) {
|
|
153
|
+
const entry = this.entries[i] ?? oob();
|
|
154
|
+
const entryLastKey = entry.start + entry.length - 1;
|
|
155
|
+
let isDirty = false;
|
|
156
|
+
if (entry.start >= start && entryLastKey <= end) {
|
|
157
|
+
// If the entry lies within the range to be deleted, remove it
|
|
158
|
+
this.entries.splice(i, 1);
|
|
155
159
|
}
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
else {
|
|
161
|
+
// If the entry partially or completely overlaps with the range to be deleted
|
|
162
|
+
if (entry.start < start) {
|
|
163
|
+
// Update the endpoint and length of the portion before the range to be deleted
|
|
164
|
+
const lengthBefore = start - entry.start;
|
|
165
|
+
this.entries[i] = { ...entry, length: lengthBefore };
|
|
166
|
+
isDirty = true;
|
|
167
|
+
}
|
|
168
|
+
if (entryLastKey > end) {
|
|
169
|
+
// Update the startpoint and length of the portion after the range to be deleted
|
|
170
|
+
const newStart = end + 1;
|
|
171
|
+
const newLength = entryLastKey - end;
|
|
172
|
+
this.entries.splice(isDirty ? i + 1 : i, isDirty ? 0 : 1, {
|
|
173
|
+
start: newStart,
|
|
174
|
+
length: newLength,
|
|
175
|
+
value: entry.value,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
165
178
|
}
|
|
166
179
|
}
|
|
167
180
|
}
|
package/lib/util/rangeMap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rangeMap.js","sourceRoot":"","sources":["../../src/util/rangeMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAgC1D;;GAEG;AACH,MAAM,UAAU,eAAe,CAC9B,GAAgB,EAChB,KAAa,EACb,MAAc;IAEd,KAAK,MAAM,KAAK,IAAI,GAAG,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,KAAK,GAAG,KAAK,EAAE,CAAC;YACzB,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;QAC5E,CAAC;QAED,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACpD,IAAI,YAAY,IAAI,KAAK,EAAE,CAAC;YAC3B,+BAA+B;YAC/B,MAAM,aAAa,GAAG,YAAY,GAAG,KAAK,GAAG,CAAC,CAAC;YAC/C,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,EAAE,CAAC;QACxE,CAAC;IACF,CAAC;IAED,qGAAqG;IACrG,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,yBAAyB,CACxC,GAAgB,EAChB,KAAa,EACb,MAAc;IAEd,MAAM,YAAY,GAAG,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;IACxC,KAAK,MAAM,KAAK,IAAI,GAAG,EAAE,CAAC;QACzB,IAAI,KAAK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K,CAAC,MAAM,GAAG,CAAC,CAAC;QACpD,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,8DAA8D;QAC9D,IAAI,KAAK,CAAC,KAAK,IAAI,KAAK,IAAI,YAAY,IAAI,GAAG,EAAE,CAAC;YACjD,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACP,6EAA6E;YAC7E,IAAI,KAAK,CAAC,KAAK,GAAG,KAAK,EAAE,CAAC;gBACzB,+EAA+E;gBAC/E,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;gBACzC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;gBAC5C,OAAO,GAAG,IAAI,CAAC;YAChB,CAAC;YAED,IAAI,YAAY,GAAG,GAAG,EAAE,CAAC;gBACxB,gFAAgF;gBAChF,MAAM,QAAQ,GAAG,GAAG,GAAG,CAAC,CAAC;gBACzB,MAAM,SAAS,GAAG,YAAY,GAAG,GAAG,CAAC;gBACrC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;oBAChD,KAAK,EAAE,QAAQ;oBACf,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,KAAK,CAAC,KAAK;iBAClB,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { oob } from \"@fluidframework/core-utils/internal\";\n\n/**\n * A map keyed on integers allowing reading and writing contiguous ranges of integer keys.\n *\n * TODO: We should avoid the direct exposure of RangeEntry. AB#7414\n */\nexport type RangeMap<T> = RangeEntry<T>[];\n\nexport interface RangeEntry<T> {\n\tstart: number;\n\tlength: number;\n\tvalue: T;\n}\n\n/**\n * The result of a query about a range of keys.\n */\nexport interface RangeQueryResult<T> {\n\t/**\n\t * The value of the first key in the query range.\n\t */\n\tvalue: T | undefined;\n\n\t/**\n\t * The length of the prefix of the query range which have the same value.\n\t * For example, if a RangeMap has the same value for keys 5, 6, and 7,\n\t * a query about the range [5, 10] would give a result with length 3.\n\t */\n\tlength: number;\n}\n\n/**\n * See comments on `RangeQueryResult`.\n */\nexport function getFromRangeMap<T>(\n\tmap: RangeMap<T>,\n\tstart: number,\n\tlength: number,\n): RangeQueryResult<T> {\n\tfor (const range of map) {\n\t\tif (range.start > start) {\n\t\t\treturn { value: undefined, length: Math.min(range.start - start, length) };\n\t\t}\n\n\t\tconst lastRangeKey = range.start + range.length - 1;\n\t\tif (lastRangeKey >= start) {\n\t\t\t// This range contains `start`.\n\t\t\tconst overlapLength = lastRangeKey - start + 1;\n\t\t\treturn { value: range.value, length: Math.min(overlapLength, length) };\n\t\t}\n\t}\n\n\t// There were no entries intersecting the query range, so the entire query range has undefined value.\n\treturn { value: undefined, length };\n}\n\nexport function getFirstEntryFromRangeMap<T>(\n\tmap: RangeMap<T>,\n\tstart: number,\n\tlength: number,\n): RangeEntry<T> | undefined {\n\tconst lastQueryKey = start + length - 1;\n\tfor (const range of map) {\n\t\tif (range.start > lastQueryKey) {\n\t\t\t// We've passed the end of the query range.\n\t\t\tbreak;\n\t\t}\n\n\t\tconst lastRangeKey = range.start + range.length - 1;\n\t\tif (lastRangeKey >= start) {\n\t\t\treturn range;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Sets the keys from `start` to `start + length - 1` to `value`.\n */\nexport function setInRangeMap<T>(\n\tmap: RangeMap<T>,\n\tstart: number,\n\tlength: number,\n\tvalue: T,\n): void {\n\tconst end = start + length - 1;\n\tconst newEntry: RangeEntry<T> = { start, length, value };\n\n\tlet iBefore = -1;\n\tlet iAfter = map.length;\n\tfor (const [i, entry] of map.entries()) {\n\t\tconst entryLastKey = entry.start + entry.length - 1;\n\t\tif (entryLastKey < start) {\n\t\t\tiBefore = i;\n\t\t} else if (entry.start > end) {\n\t\t\tiAfter = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tconst numOverlappingEntries = iAfter - iBefore - 1;\n\tif (numOverlappingEntries === 0) {\n\t\tmap.splice(iAfter, 0, newEntry);\n\t\treturn;\n\t}\n\n\tconst iFirst = iBefore + 1;\n\tconst firstEntry = map[iFirst] ?? oob();\n\tconst iLast = iAfter - 1;\n\tconst lastEntry = map[iLast] ?? oob();\n\tconst lengthBeforeFirst = start - firstEntry.start;\n\tconst lastEntryKey = lastEntry.start + lastEntry.length - 1;\n\tconst lengthAfterLast = lastEntryKey - end;\n\n\tif (lengthBeforeFirst > 0 && lengthAfterLast > 0 && iFirst === iLast) {\n\t\t// The new entry fits in the middle of an existing entry.\n\t\t// We replace the existing entry with:\n\t\t// 1) the portion which comes before `newEntry`\n\t\t// 2) `newEntry`\n\t\t// 3) the portion which comes after `newEntry`\n\t\tmap.splice(iFirst, 1, { ...firstEntry, length: lengthBeforeFirst }, newEntry, {\n\t\t\t...lastEntry,\n\t\t\tstart: end + 1,\n\t\t\tlength: lengthAfterLast,\n\t\t});\n\t\treturn;\n\t}\n\n\tif (lengthBeforeFirst > 0) {\n\t\tmap[iFirst] = { ...firstEntry, length: lengthBeforeFirst };\n\n\t\t// The entry at `iFirst` is no longer overlapping with `newEntry`.\n\t\tiBefore = iFirst;\n\t}\n\n\tif (lengthAfterLast > 0) {\n\t\tmap[iLast] = {\n\t\t\t...lastEntry,\n\t\t\tstart: end + 1,\n\t\t\tlength: lengthAfterLast,\n\t\t};\n\n\t\t// The entry at `iLast` is no longer overlapping with `newEntry`.\n\t\tiAfter = iLast;\n\t}\n\n\tconst numContainedEntries = iAfter - iBefore - 1;\n\tmap.splice(iBefore + 1, numContainedEntries, newEntry);\n}\n\n/**\n * Delete the keys from `start` to `start + length - 1`\n *\n * 1. If an entry is completely included in the deletion range, the whole entry will be deleted\n * e.g.: map = [[1, 2], [4, 6]], delete range: [3, 6]\n * map becomes [[1, 2]] after deletion\n * (Note: the notation [a, b] represents start = a, end = b for simpler visiualization, instead of `b`\n * representing the length)\n *\n * 2. If an entry is partially overlapped with the deletion range, the start or end point will be shifted\n * e.g.: map = [[1, 2], [4, 6]], delete range: [2, 4]\n * map becomes [[1, 1], [5, 6]] after deletion\n *\n * 3. If an entry completely includes the deletion range, the original entry may be split into two.\n * e.g.: map = [[1, 6]], delete range: [2, 4]\n * map becomes [[1, 1], [5, 6]]\n *\n * TODO: We may find ways to mitigate the code duplication between set and delete, and we need to better\n * document the API. AB#7413\n */\nexport function deleteFromRangeMap<T>(map: RangeMap<T>, start: number, length: number): void {\n\tconst end = start + length - 1;\n\n\tlet iBefore = -1;\n\tlet iAfter = map.length;\n\n\tfor (const [i, entry] of map.entries()) {\n\t\tconst entryLastKey = entry.start + entry.length - 1;\n\t\tif (entryLastKey < start) {\n\t\t\tiBefore = i;\n\t\t} else if (entry.start > end) {\n\t\t\tiAfter = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tconst numOverlappingEntries = iAfter - iBefore - 1;\n\n\tif (numOverlappingEntries === 0) {\n\t\t// No entry will be removed\n\t\treturn;\n\t}\n\n\tconst iFirst = iBefore + 1;\n\tconst iLast = iAfter - 1;\n\n\t// Update or remove the overlapping entries\n\tfor (let i = iFirst; i <= iLast; ++i) {\n\t\tconst entry = map[i] ?? oob();\n\t\tconst entryLastKey = entry.start + entry.length - 1;\n\t\tlet isDirty = false;\n\n\t\t// If the entry lies within the range to be deleted, remove it\n\t\tif (entry.start >= start && entryLastKey <= end) {\n\t\t\tmap.splice(i, 1);\n\t\t} else {\n\t\t\t// If the entry partially or completely overlaps with the range to be deleted\n\t\t\tif (entry.start < start) {\n\t\t\t\t// Update the endpoint and length of the portion before the range to be deleted\n\t\t\t\tconst lengthBefore = start - entry.start;\n\t\t\t\tmap[i] = { ...entry, length: lengthBefore };\n\t\t\t\tisDirty = true;\n\t\t\t}\n\n\t\t\tif (entryLastKey > end) {\n\t\t\t\t// Update the startpoint and length of the portion after the range to be deleted\n\t\t\t\tconst newStart = end + 1;\n\t\t\t\tconst newLength = entryLastKey - end;\n\t\t\t\tmap.splice(isDirty ? i + 1 : i, isDirty ? 0 : 1, {\n\t\t\t\t\tstart: newStart,\n\t\t\t\t\tlength: newLength,\n\t\t\t\t\tvalue: entry.value,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rangeMap.js","sourceRoot":"","sources":["../../src/util/rangeMap.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAE1D;;;GAGG;AACH,MAAM,OAAO,QAAQ;IAGpB,YAAmB,cAAgC;QAClD,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACI,aAAa;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;;;;;;OAOG;IACI,GAAG,CAAC,KAAa,EAAE,MAAc;QACvC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,KAAK,CAAC,KAAK,GAAG,KAAK,EAAE,CAAC;gBACzB,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;YAC5E,CAAC;YAED,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YACpD,IAAI,YAAY,IAAI,KAAK,EAAE,CAAC;gBAC3B,MAAM,aAAa,GAAG,YAAY,GAAG,KAAK,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AC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { oob } from \"@fluidframework/core-utils/internal\";\n\n/**\n * RangeMap represents a mapping from integers to values of type T or undefined.\n * The values for a range of consecutive keys can be changed or queried in a single operation.\n */\nexport class RangeMap<T> {\n\tprivate readonly entries: RangeEntry<T>[];\n\n\tpublic constructor(initialEntries?: RangeEntry<T>[]) {\n\t\tthis.entries = initialEntries ? [...initialEntries] : [];\n\t}\n\n\t/**\n\t * Retrieves all entries from the rangeMap.\n\t * @returns An array of RangeEntryResult objects, each containing the start index, length, and value of a contiguous range.\n\t */\n\tpublic getAllEntries(): readonly RangeQueryResult<T>[] {\n\t\treturn this.entries;\n\t}\n\n\t/**\n\t * Retrieves the value for some prefix of the query range.\n\t *\n\t * @param start - The first key in the query range.\n\t * @param length - The length of the query range.\n\t * @returns A RangeQueryResult containing the value associated with `start`,\n\t * and the number of consecutive keys with that same value.\n\t */\n\tpublic get(start: number, length: number): RangeQueryResult<T> {\n\t\tfor (const entry of this.entries) {\n\t\t\tif (entry.start > start) {\n\t\t\t\treturn { value: undefined, length: Math.min(entry.start - start, length) };\n\t\t\t}\n\n\t\t\tconst lastRangeKey = entry.start + entry.length - 1;\n\t\t\tif (lastRangeKey >= start) {\n\t\t\t\tconst overlapLength = lastRangeKey - start + 1;\n\t\t\t\treturn { value: entry.value, length: Math.min(overlapLength, length) };\n\t\t\t}\n\t\t}\n\n\t\t// There were no entries intersecting the query range, so the entire query range has undefined value.\n\t\treturn { value: undefined, length };\n\t}\n\n\t/**\n\t * Sets the value for a specified range.\n\t *\n\t * @param start - The first key in the range being set.\n\t * @param length - The length of the range.\n\t * @param value - The value to associate with the range.\n\t */\n\tpublic set(start: number, length: number, value: T | undefined): void {\n\t\tif (value === undefined) {\n\t\t\tthis.delete(start, length);\n\t\t\treturn;\n\t\t}\n\n\t\tconst end = start + length - 1;\n\t\tconst newEntry: RangeEntry<T> = { start, length, value };\n\n\t\tlet iBefore = -1;\n\t\tlet iAfter = this.entries.length;\n\t\tfor (const [i, entry] of this.entries.entries()) {\n\t\t\tconst entryLastKey = entry.start + entry.length - 1;\n\t\t\tif (entryLastKey < start) {\n\t\t\t\tiBefore = i;\n\t\t\t} else if (entry.start > end) {\n\t\t\t\tiAfter = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst numOverlappingEntries = iAfter - iBefore - 1;\n\t\tif (numOverlappingEntries === 0) {\n\t\t\tthis.entries.splice(iAfter, 0, newEntry);\n\t\t\treturn;\n\t\t}\n\n\t\tconst iFirst = iBefore + 1;\n\t\tconst firstEntry = this.entries[iFirst] ?? oob();\n\t\tconst iLast = iAfter - 1;\n\t\tconst lastEntry = this.entries[iLast] ?? oob();\n\t\tconst lengthBeforeFirst = start - firstEntry.start;\n\t\tconst lastEntryKey = lastEntry.start + lastEntry.length - 1;\n\t\tconst lengthAfterLast = lastEntryKey - end;\n\n\t\tif (lengthBeforeFirst > 0 && lengthAfterLast > 0 && iFirst === iLast) {\n\t\t\t// The new entry fits in the middle of an existing entry.\n\t\t\t// We replace the existing entry with:\n\t\t\t// 1) the portion which comes before `newEntry`\n\t\t\t// 2) `newEntry`\n\t\t\t// 3) the portion which comes after `newEntry`\n\t\t\tthis.entries.splice(iFirst, 1, { ...firstEntry, length: lengthBeforeFirst }, newEntry, {\n\t\t\t\t...lastEntry,\n\t\t\t\tstart: end + 1,\n\t\t\t\tlength: lengthAfterLast,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tif (lengthBeforeFirst > 0) {\n\t\t\tthis.entries[iFirst] = { ...firstEntry, length: lengthBeforeFirst };\n\t\t\t// The entry at `iFirst` is no longer overlapping with `newEntry`.\n\t\t\tiBefore = iFirst;\n\t\t}\n\n\t\tif (lengthAfterLast > 0) {\n\t\t\tthis.entries[iLast] = {\n\t\t\t\t...lastEntry,\n\t\t\t\tstart: end + 1,\n\t\t\t\tlength: lengthAfterLast,\n\t\t\t};\n\n\t\t\t// The entry at `iLast` is no longer overlapping with `newEntry`.\n\t\t\tiAfter = iLast;\n\t\t}\n\n\t\tconst numContainedEntries = iAfter - iBefore - 1;\n\t\tthis.entries.splice(iBefore + 1, numContainedEntries, newEntry);\n\t}\n\n\t/**\n\t * Deletes values within a specified range, updating or removing existing entries.\n\t *\n\t * 1. If an entry is completely included in the deletion range, the whole entry will be deleted\n\t * e.g.: map = [[1, 2], [4, 6]], delete range: [3, 6]\n\t * map becomes [[1, 2]] after deletion\n\t * (Note: the notation [a, b] represents start = a, end = b for simpler visualization, instead of `b`\n\t * representing the length)\n\t *\n\t * 2. If an entry is partially overlapped with the deletion range, the start or end point will be shifted\n\t * e.g.: map = [[1, 2], [4, 6]], delete range: [2, 4]\n\t * map becomes [[1, 1], [5, 6]] after deletion\n\t *\n\t * 3. If an entry completely includes the deletion range, the original entry may be split into two.\n\t * e.g.: map = [[1, 6]], delete range: [2, 4]\n\t * map becomes [[1, 1], [5, 6]]\n\t *\n\t * @param start - The start of the range to delete (inclusive).\n\t * @param length - The length of the range to delete.\n\t */\n\tpublic delete(start: number, length: number): void {\n\t\tconst end = start + length - 1;\n\n\t\tlet iBefore = -1;\n\t\tlet iAfter = this.entries.length;\n\n\t\tfor (const [i, entry] of this.entries.entries()) {\n\t\t\tconst entryLastKey = entry.start + entry.length - 1;\n\t\t\tif (entryLastKey < start) {\n\t\t\t\tiBefore = i;\n\t\t\t} else if (entry.start > end) {\n\t\t\t\tiAfter = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst numOverlappingEntries = iAfter - iBefore - 1;\n\n\t\tif (numOverlappingEntries === 0) {\n\t\t\t// No entry will be removed\n\t\t\treturn;\n\t\t}\n\n\t\tconst iFirst = iBefore + 1;\n\t\tconst iLast = iAfter - 1;\n\n\t\tfor (let i = iFirst; i <= iLast; ++i) {\n\t\t\tconst entry = this.entries[i] ?? oob();\n\t\t\tconst entryLastKey = entry.start + entry.length - 1;\n\t\t\tlet isDirty = false;\n\n\t\t\tif (entry.start >= start && entryLastKey <= end) {\n\t\t\t\t// If the entry lies within the range to be deleted, remove it\n\t\t\t\tthis.entries.splice(i, 1);\n\t\t\t} else {\n\t\t\t\t// If the entry partially or completely overlaps with the range to be deleted\n\t\t\t\tif (entry.start < start) {\n\t\t\t\t\t// Update the endpoint and length of the portion before the range to be deleted\n\t\t\t\t\tconst lengthBefore = start - entry.start;\n\t\t\t\t\tthis.entries[i] = { ...entry, length: lengthBefore };\n\t\t\t\t\tisDirty = true;\n\t\t\t\t}\n\n\t\t\t\tif (entryLastKey > end) {\n\t\t\t\t\t// Update the startpoint and length of the portion after the range to be deleted\n\t\t\t\t\tconst newStart = end + 1;\n\t\t\t\t\tconst newLength = entryLastKey - end;\n\t\t\t\t\tthis.entries.splice(isDirty ? i + 1 : i, isDirty ? 0 : 1, {\n\t\t\t\t\t\tstart: newStart,\n\t\t\t\t\t\tlength: newLength,\n\t\t\t\t\t\tvalue: entry.value,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Represents a contiguous range of values in the RangeMap.\n * This interface is used internally and should not be exposed to consumers.\n */\ninterface RangeEntry<T> {\n\t/**\n\t * The starting index of the range (inclusive).\n\t */\n\treadonly start: number;\n\n\t/**\n\t * The length of the range.\n\t */\n\treadonly length: number;\n\n\t/**\n\t * The value associated with this range.\n\t */\n\treadonly value: T;\n}\n\n/**\n * Describes the result of a range query, including the value and length of the matching prefix.\n */\nexport interface RangeQueryResult<T> {\n\t/**\n\t * The value of the first key in the query range.\n\t * If no matching range is found, this will be undefined.\n\t */\n\treadonly value: T | undefined;\n\n\t/**\n\t * The length of the prefix of the query range which has the same value.\n\t * For example, if a RangeMap has the same value for keys 5, 6, and 7,\n\t * a query about the range [5, 10] would give a result with length 3.\n\t */\n\treadonly length: number;\n}\n"]}
|
package/lib/util/utils.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface MapGetSet<K, V> {
|
|
|
11
11
|
set(key: K, value: V): void;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Make all transitive properties in T readonly
|
|
14
|
+
* Make all transitive properties in `T` readonly
|
|
15
15
|
*/
|
|
16
16
|
export type RecursiveReadonly<T> = {
|
|
17
17
|
readonly [P in keyof T]: RecursiveReadonly<T[P]>;
|
|
@@ -308,4 +308,25 @@ export declare function compareStrings<T extends string>(a: T, b: T): number;
|
|
|
308
308
|
export declare function defineLazyCachedProperty<T extends object, K extends string | number | symbol, V>(obj: T, key: K, get: () => V): typeof obj & {
|
|
309
309
|
[P in K]: V;
|
|
310
310
|
};
|
|
311
|
+
/**
|
|
312
|
+
* Copies a given property from one object to another if and only if the property is defined.
|
|
313
|
+
* @param source - The object to copy the property from.
|
|
314
|
+
* If `source` is undefined or does not have the property defined, then this function will do nothing.
|
|
315
|
+
* @param property - The property to copy.
|
|
316
|
+
* @param destination - The object to copy the property to.
|
|
317
|
+
* @remarks This function is useful for copying properties from one object to another while minimizing the presence of `undefined` values.
|
|
318
|
+
* If `property` is not present on `source` - or if `property` is present, but has a value of `undefined` - then this function will not modify `destination`.
|
|
319
|
+
* This is different from doing `destination.foo = source.foo`, which would define a `"foo"` property on `destination` with the value `undefined`.
|
|
320
|
+
*
|
|
321
|
+
* If the type of `source` is known to have `property`, then this function asserts that the type of `destination` has `property` as well after the call.
|
|
322
|
+
*
|
|
323
|
+
* This function first reads the property value (if present) from `source` and then sets it on `destination`, as opposed to e.g. directly copying the property descriptor.
|
|
324
|
+
* @privateRemarks The first overload of this function allows auto-complete to suggest property names from `source`, but by having the second overload we still allow for arbitrary property names.
|
|
325
|
+
*/
|
|
326
|
+
export declare function copyPropertyIfDefined<S extends object, K extends keyof S, D extends object>(source: S | undefined, property: K, destination: D): asserts destination is K extends keyof S ? D & {
|
|
327
|
+
[P in K]: S[K];
|
|
328
|
+
} : D;
|
|
329
|
+
export declare function copyPropertyIfDefined<S extends object, K extends string | number | symbol, D extends object>(source: S | undefined, property: K, destination: D): asserts destination is K extends keyof S ? D & {
|
|
330
|
+
[P in K]: S[K];
|
|
331
|
+
} : D;
|
|
311
332
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/util/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/util/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,eAAe,MAAM,yBAAyB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC;IAC9B,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC3B,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;IAClC,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAChD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;KACzB,CAAC,IAAI,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACxE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEpD;AAED,eAAO,MAAM,KAAK,wBAAkB,CAAC;AAErC;GACG;AACH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CAAC,GAAG,CAAC,GAAG;KAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,CAAC,CAAC"}
|
package/lib/util/utils.js
CHANGED
|
@@ -343,4 +343,12 @@ export function defineLazyCachedProperty(obj, key, get) {
|
|
|
343
343
|
});
|
|
344
344
|
return obj;
|
|
345
345
|
}
|
|
346
|
+
export function copyPropertyIfDefined(source, property, destination) {
|
|
347
|
+
if (source !== undefined) {
|
|
348
|
+
const value = source[property];
|
|
349
|
+
if (value !== undefined) {
|
|
350
|
+
destination[property] = value;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
346
354
|
//# sourceMappingURL=utils.js.map
|
package/lib/util/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/util/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,eAAe,MAAM,yBAAyB,CAAC;AA8BtD;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAI,QAAW;IACvC,OAAO,QAAsB,CAAC;AAC/B,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,eAAe,CAAC;AAErC;GACG;AACH,MAAM,UAAU,IAAI,CAAC,OAAe;IACnC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAI,CAAyB;IAC3D,+EAA+E;IAC/E,wEAAwE;IACxE,oEAAoE;IACpE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAI,IAAY,EAAE,MAA4B;IACtE,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KA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C;QACD,YAAY,EAAE,IAAI;KAClB,CAAC,CAAC;IACH,OAAO,GAAmC,CAAC;AAC5C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { Type } from \"@sinclair/typebox\";\nimport structuredClone from \"@ungap/structured-clone\";\n\n/**\n * Subset of Map interface.\n */\nexport interface MapGetSet<K, V> {\n\tget(key: K): V | undefined;\n\tset(key: K, value: V): void;\n}\n\n/**\n * Make all transitive properties in T readonly\n */\nexport type RecursiveReadonly<T> = {\n\treadonly [P in keyof T]: RecursiveReadonly<T[P]>;\n};\n\n/**\n * Remove `readonly` from all fields.\n */\nexport type Mutable<T> = { -readonly [P in keyof T]: T[P] };\n\n/**\n * Make all field required and omits fields whose ony valid value would be `undefined`.\n * This is analogous to `Required<T>` except it tolerates 'optional undefined'.\n */\nexport type Populated<T> = {\n\t[P in keyof T as Exclude<P, T[P] extends undefined ? P : never>]-?: T[P];\n};\n\n/**\n * Casts a readonly object to a mutable one.\n * Better than casting to `Mutable<Foo>` because it doesn't risk casting a non-`Foo` to a `Mutable<Foo>`.\n * @param readonly - The object with readonly fields.\n * @returns The same object but with a type that makes all fields mutable.\n */\nexport function asMutable<T>(readonly: T): Mutable<T> {\n\treturn readonly as Mutable<T>;\n}\n\nexport const clone = structuredClone;\n\n/**\n */\nexport function fail(message: string): never {\n\tthrow new Error(message);\n}\n\n/**\n * Checks whether or not the given object is a `readonly` array.\n *\n * Note that this does NOT indicate if a given array should be treated as readonly.\n * This instead indicates if an object is an Array, and is typed to tolerate the readonly case.\n */\nexport function isReadonlyArray<T>(x: readonly T[] | unknown): x is readonly T[] {\n\t// `Array.isArray()` does not properly narrow `readonly` array types by itself,\n\t// so we wrap it in this type guard. This may become unnecessary if/when\n\t// https://github.com/microsoft/TypeScript/issues/17002 is resolved.\n\treturn Array.isArray(x);\n}\n\n/**\n * Creates and populates a new array.\n * @param size - The size of the array to be created.\n * @param filler - Callback for populating the array with a value for a given index\n */\nexport function makeArray<T>(size: number, filler: (index: number) => T): T[] {\n\tconst array = [];\n\tfor (let i = 0; i < size; ++i) {\n\t\tarray.push(filler(i));\n\t}\n\treturn array;\n}\n\n/**\n * Returns the last element of an array, or `undefined` if the array has no elements.\n * @param array - The array to get the last element from.\n * @remarks\n * If the type of the array has been narrowed by e.g. {@link hasSome | hasSome(array)} or {@link hasSingle | hasOne(array)} then the return type will be `T` rather than `T | undefined`.\n */\nexport function getLast<T>(array: readonly [T, ...T[]]): T;\nexport function getLast<T>(array: { [index: number]: T; length: number }): T | undefined;\nexport function getLast<T>(array: { [index: number]: T; length: number }): T | undefined {\n\treturn array[array.length - 1];\n}\n\n/**\n * Returns true if and only if the given array has at least one element.\n * @param array - The array to check.\n * @remarks\n * If `array` contains at least one element, its type will be narrowed and can benefit from improved typing from e.g. `array[0]` and {@link getLast | getLast(array)}.\n * This is especially useful when \"noUncheckedIndexedAccess\" is enabled in the TypeScript compiler options, since the return type of `array[0]` will be `T` rather than `T | undefined`.\n */\nexport function hasSome<T>(array: T[]): array is [T, ...T[]];\nexport function hasSome<T>(array: readonly T[]): array is readonly [T, ...T[]];\nexport function hasSome<T>(array: readonly T[]): array is [T, ...T[]] {\n\treturn array.length > 0;\n}\n\n/**\n * Returns true if and only if the given array has exactly one element.\n * @param array - The array to check.\n * @remarks\n * If `array` contains exactly one element, its type will be narrowed and can benefit from improved typing from e.g. `array[0]` and {@link getLast | getLast(array)}.\n * This is especially useful when \"noUncheckedIndexedAccess\" is enabled in the TypeScript compiler options, since the return type of `array[0]` will be `T` rather than `T | undefined`.\n */\nexport function hasSingle<T>(array: T[]): array is [T];\nexport function hasSingle<T>(array: readonly T[]): array is readonly [T];\nexport function hasSingle<T>(array: readonly T[]): array is [T] {\n\treturn array.length === 1;\n}\n\n/**\n * Compares two sets using callbacks.\n * Early returns on first false comparison.\n *\n * @param a - One Set.\n * @param b - The other Set.\n * @param aExtra - Called for items in `a` but not `b`.\n * @param bExtra - Called for items in `b` but not `a`.\n * @param same - Called for items in `a` and `b`.\n * @returns false iff any of the call backs returned false.\n */\nexport function compareSets<T>({\n\ta,\n\tb,\n\taExtra,\n\tbExtra,\n\tsame,\n}: {\n\ta: ReadonlySet<T> | ReadonlyMap<T, unknown>;\n\tb: ReadonlySet<T> | ReadonlyMap<T, unknown>;\n\taExtra?: (t: T) => boolean;\n\tbExtra?: (t: T) => boolean;\n\tsame?: (t: T) => boolean;\n}): boolean {\n\tfor (const item of a.keys()) {\n\t\tif (!b.has(item)) {\n\t\t\tif (aExtra !== undefined) {\n\t\t\t\tif (!aExtra(item)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t} else {\n\t\t\tif (same !== undefined && !same(item)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\tfor (const item of b.keys()) {\n\t\tif (!a.has(item)) {\n\t\t\tif (bExtra !== undefined) {\n\t\t\t\tif (!bExtra(item)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\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>(\n\tmap: MapGetSet<K, V>,\n\tkey: K,\n\tdefaultValue: (key: K) => V,\n): 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 * Utility for dictionaries whose values are lists.\n * Gets the list associated with the provided key, if it exists.\n * Otherwise, creates an entry with an empty list, and returns that list.\n */\nexport function getOrAddEmptyToMap<K, V>(map: MapGetSet<K, V[]>, key: K): V[] {\n\tlet collection = map.get(key);\n\tif (collection === undefined) {\n\t\tcollection = [];\n\t\tmap.set(key, collection);\n\t}\n\treturn collection;\n}\n\n/**\n * Map one iterable to another by transforming each element one at a time\n * @param iterable - the iterable to transform\n * @param map - the transformation function to run on each element of the iterable\n * @returns a new iterable of elements which have been transformed by the `map` function\n */\nexport function* mapIterable<T, U>(\n\titerable: Iterable<T>,\n\tmap: (t: T) => U,\n): IterableIterator<U> {\n\tfor (const t of iterable) {\n\t\tyield map(t);\n\t}\n}\n\n/**\n * Filter one iterable into another\n * @param iterable - the iterable to filter\n * @param filter - the predicate function to run on each element of the iterable\n * @returns a new iterable including only the elements that passed the filter predicate\n */\nexport function* filterIterable<T>(\n\titerable: Iterable<T>,\n\tfilter: (t: T) => boolean,\n): IterableIterator<T> {\n\tfor (const t of iterable) {\n\t\tif (filter(t)) {\n\t\t\tyield t;\n\t\t}\n\t}\n}\n\n/**\n * Finds the first element in the given iterable that satisfies a predicate.\n * @param iterable - The iterable to search for an eligible element\n * @param predicate - The predicate to run against each element\n * @returns The first element in the iterable that satisfies the predicate, or undefined if the iterable contains no such element\n */\nexport function find<T>(iterable: Iterable<T>, predicate: (t: T) => boolean): T | undefined {\n\tfor (const t of iterable) {\n\t\tif (predicate(t)) {\n\t\t\treturn t;\n\t\t}\n\t}\n}\n\n/**\n * Counts the number of elements in the given iterable.\n * @param iterable - the iterable to enumerate\n * @returns the number of elements that were iterated after exhausting the iterable\n */\nexport function count(iterable: Iterable<unknown>): number {\n\tlet n = 0;\n\tfor (const _ of iterable) {\n\t\tn += 1;\n\t}\n\treturn n;\n}\n\n/**\n * Use for Json compatible data.\n *\n * @typeparam TExtra - Type permitted in addition to the normal JSON types.\n * Commonly used for to allow {@link @fluidframework/core-interfaces#IFluidHandle} within the otherwise JSON compatible content.\n *\n * @remarks\n * This does not robustly forbid non json comparable data via type checking,\n * but instead mostly restricts access to it.\n * @alpha\n */\nexport type JsonCompatible<TExtra = never> =\n\t| string\n\t| number\n\t| boolean\n\t// eslint-disable-next-line @rushstack/no-new-null\n\t| null\n\t| JsonCompatible<TExtra>[]\n\t| JsonCompatibleObject<TExtra>\n\t| TExtra;\n\n/**\n * Use for Json object compatible data.\n * @remarks\n * This does not robustly forbid non json comparable data via type checking,\n * but instead mostly restricts access to it.\n * @alpha\n */\nexport type JsonCompatibleObject<TExtra = never> = { [P in string]?: JsonCompatible<TExtra> };\n\n/**\n * Use for readonly view of Json compatible data.\n * @remarks\n * This does not robustly forbid non json comparable data via type checking,\n * but instead mostly restricts access to it.\n */\nexport type JsonCompatibleReadOnly =\n\t| string\n\t| number\n\t| boolean\n\t// eslint-disable-next-line @rushstack/no-new-null\n\t| null\n\t| readonly JsonCompatibleReadOnly[]\n\t| JsonCompatibleReadOnlyObject;\n\n/**\n * Use for readonly view of Json compatible data.\n * @remarks\n * This does not robustly forbid non json comparable data via type checking,\n * but instead mostly restricts access to it.\n */\nexport type JsonCompatibleReadOnlyObject = { readonly [P in string]?: JsonCompatibleReadOnly };\n\n/**\n * @remarks TODO: Audit usage of this type in schemas, evaluating whether it is necessary and performance\n * of alternatives.\n *\n * True \"arbitrary serializable data\" is probably fine, but some persisted types declarations might be better\n * expressed using composition of schemas for runtime validation, even if we don't think making the types\n * generic is worth the maintenance cost.\n */\nexport const JsonCompatibleReadOnlySchema = Type.Any();\n\n/**\n * Returns if a particular json compatible value is an object.\n * Does not include `null` or arrays.\n */\nexport function isJsonObject(\n\tvalue: JsonCompatibleReadOnly,\n): value is { readonly [P in string]?: JsonCompatibleReadOnly } {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Verifies that the supplied indices are valid within the supplied array.\n * @param startIndex - The starting index in the range. Must be in [0, length).\n * @param endIndex - The ending index in the range. Must be within (start, length].\n * @param array - The array the indices refer to\n */\nexport function assertValidRangeIndices(\n\tstartIndex: number,\n\tendIndex: number,\n\tarray: { readonly length: number },\n): void {\n\tassert(endIndex >= startIndex, 0x79c /* Range indices are malformed. */);\n\tassertValidIndex(startIndex, array, false);\n\tassertValidIndex(endIndex, array, true);\n}\n\nexport function assertValidIndex(\n\tindex: number,\n\tarray: { readonly length: number },\n\tallowOnePastEnd: boolean = false,\n): void {\n\tassertNonNegativeSafeInteger(index);\n\tif (allowOnePastEnd) {\n\t\tassert(index <= array.length, 0x378 /* index must be less than or equal to length */);\n\t} else {\n\t\tassert(index < array.length, 0x379 /* index must be less than length */);\n\t}\n}\n\nexport function assertValidRange(\n\t{ start, end }: { start: number; end: number },\n\tarray: { readonly length: number },\n): void {\n\tassertNonNegativeSafeInteger(start);\n\tassertNonNegativeSafeInteger(end);\n\tassert(end <= array.length, 0x79d /* Range end must be less than or equal to length */);\n\tassert(start <= end, 0x79e /* Range start must be less than or equal to range start */);\n}\n\nexport function assertNonNegativeSafeInteger(index: number): void {\n\tassert(Number.isSafeInteger(index), 0x376 /* index must be an integer */);\n\tassert(index >= 0, 0x377 /* index must be non-negative */);\n}\n\n/**\n * Convert an object into a Map.\n *\n * This function must only be used with objects specifically intended to encode map like information.\n * The only time such objects should be used is for encoding maps as object literals to allow for developer ergonomics or JSON compatibility.\n * Even those two use-cases need to be carefully considered as using objects as maps can have a lot of issues\n * (including but not limited to unintended access to __proto__ and other non-owned keys).\n * This function helps these few cases get into using an actual map in as safe of was as is practical.\n */\nexport function objectToMap<MapKey extends string | number | symbol, MapValue>(\n\tobjectMap: Record<MapKey, MapValue>,\n): Map<MapKey, MapValue> {\n\tconst map = new Map<MapKey, MapValue>();\n\t// This function must only be used with objects specifically intended to encode map like information.\n\tfor (const key of Object.keys(objectMap)) {\n\t\tconst element = objectMap[key as MapKey];\n\t\tmap.set(key as MapKey, element);\n\t}\n\treturn map;\n}\n\n/**\n * Convert an object used as a map into a new object used like a map.\n *\n * @remarks\n * This function must only be used with objects specifically intended to encode map like information.\n * The only time such objects should be used is for encoding maps as object literals to allow for developer ergonomics or JSON compatibility.\n * Even those two use-cases need to be carefully considered as using objects as maps can have a lot of issues\n * (including but not limited to unintended access to __proto__ and other non-owned keys).\n * {@link objectToMap} helps these few cases get into using an actual map in as safe of a way as is practical.\n */\nexport function transformObjectMap<\n\tMapKey extends string | number | symbol,\n\tMapValue,\n\tNewMapValue,\n>(\n\tobjectMap: Record<MapKey, MapValue>,\n\ttransformer: (value: MapValue, key: MapKey) => NewMapValue,\n): Record<MapKey, MapValue> {\n\tconst output: Record<MapKey, MapValue> = Object.create(null);\n\t// This function must only be used with objects specifically intended to encode map like information.\n\tfor (const key of Object.keys(objectMap)) {\n\t\tconst element = objectMap[key as MapKey];\n\t\tObject.defineProperty(output, key, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t\twritable: true,\n\t\t\tvalue: transformer(element, key as MapKey),\n\t\t});\n\t}\n\treturn output;\n}\n\n/**\n * Make an inverted copy of a map.\n *\n * @returns a map which can look up the keys from the values of the original map.\n */\nexport function invertMap<Key, Value>(input: Map<Key, Value>): Map<Value, Key> {\n\tconst result = new Map<Value, Key>(mapIterable(input, ([key, value]) => [value, key]));\n\tassert(\n\t\tresult.size === input.size,\n\t\t0x88a /* all values in a map must be unique to invert it */,\n\t);\n\treturn result;\n}\n\n/**\n * Returns the value from `set` if it contains exactly one item, otherwise `undefined`.\n */\nexport function oneFromSet<T>(set: ReadonlySet<T> | undefined): T | undefined {\n\tif (set === undefined) {\n\t\treturn undefined;\n\t}\n\tif (set.size !== 1) {\n\t\treturn undefined;\n\t}\n\tfor (const item of set) {\n\t\treturn item;\n\t}\n}\n\n/**\n * Type with a name describing what it is.\n * Typically used with values (like schema) that can be stored in a map, but in some representations have their name/key as a field.\n */\nexport interface Named<TName> {\n\treadonly name: TName;\n}\n\n/**\n * Order {@link Named} objects by their name.\n */\nexport function compareNamed(a: Named<string>, b: Named<string>): -1 | 0 | 1 {\n\tif (a.name < b.name) {\n\t\treturn -1;\n\t}\n\tif (a.name > b.name) {\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n/**\n * Placeholder for `Symbol.dispose`.\n * @privateRemarks\n * TODO: replace this with `Symbol.dispose` when it is available or make it a valid polyfill.\n */\nexport const disposeSymbol: unique symbol = Symbol(\"Symbol.dispose placeholder\");\n\n/**\n * An object with an explicit lifetime that can be ended.\n * @privateRemarks\n * Simpler alternative to core-utils/IDisposable for internal use in this package.\n * This avoids adding a named \"dispose\" method, and will eventually be replaced with\n * {@link https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management| TypeScript's Disposable}.\n *\n * Once this is replaced with TypeScript's Disposable, core-utils/IDisposable can extend it, bringing the APIs into a reasonable alignment.\n */\nexport interface IDisposable {\n\t/**\n\t * Call to end the lifetime of this object.\n\t *\n\t * It is invalid to use this object after this,\n\t * except for operations which explicitly document they are valid after disposal.\n\t *\n\t * @remarks\n\t * May cleanup resources retained by this object.\n\t * Often includes un-registering from events and thus preventing other objects from retaining a reference to this indefinably.\n\t *\n\t * Usually the only operations allowed after disposal are querying if an object is already disposed,\n\t * but this can vary between implementations.\n\t */\n\t[disposeSymbol](): void;\n}\n\n/**\n * Capitalize a string.\n */\nexport function capitalize<S extends string>(s: S): Capitalize<S> {\n\t// To avoid splitting characters which are made of multiple UTF-16 code units,\n\t// use iteration instead of indexing to separate the first character.\n\tconst iterated = s[Symbol.iterator]().next();\n\tif (iterated.done === true) {\n\t\t// Empty string case.\n\t\treturn \"\" as Capitalize<S>;\n\t}\n\n\treturn (iterated.value.toUpperCase() + s.slice(iterated.value.length)) as Capitalize<S>;\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 * Defines a property on an object that is lazily initialized and cached.\n * @remarks This is useful for properties that are expensive to compute and it is not guaranteed that they will be accessed.\n * This function initially defines a getter on the object, but after first read it replaces the getter with a value property.\n * @param obj - The object on which to define the property.\n * @param key - The key of the property to define.\n * @param get - The function (called either once or not at all) to compute the value of the property.\n * @returns `obj`, typed such that it has the new property.\n * This allows for the new property to be read off of `obj` in a type-safe manner after calling this function.\n */\nexport function defineLazyCachedProperty<\n\tT extends object,\n\tK extends string | number | symbol,\n\tV,\n>(obj: T, key: K, get: () => V): typeof obj & { [P in K]: V } {\n\tReflect.defineProperty(obj, key, {\n\t\tget() {\n\t\t\tconst value = get();\n\t\t\tReflect.defineProperty(obj, key, { value });\n\t\t\treturn value;\n\t\t},\n\t\tconfigurable: true,\n\t});\n\treturn obj as typeof obj & { [P in K]: V };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/util/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,eAAe,MAAM,yBAAyB,CAAC;AA8BtD;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAI,QAAW;IACvC,OAAO,QAAsB,CAAC;AAC/B,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,eAAe,CAAC;AAErC;GACG;AACH,MAAM,UAAU,IAAI,CAAC,OAAe;IACnC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAI,CAAyB;IAC3D,+EAA+E;IAC/E,wEAAwE;IACxE,oEAAoE;IACpE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAI,IAAY,EAAE,MAA4B;IACtE,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC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AAW,EACX,WAAc;IAEd,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAI,MAAiC,CAAC,QAAQ,CAAC,CAAC;QAC3D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,WAAqC,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;QAC1D,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { Type } from \"@sinclair/typebox\";\nimport structuredClone from \"@ungap/structured-clone\";\n\n/**\n * Subset of Map interface.\n */\nexport interface MapGetSet<K, V> {\n\tget(key: K): V | undefined;\n\tset(key: K, value: V): void;\n}\n\n/**\n * Make all transitive properties in `T` readonly\n */\nexport type RecursiveReadonly<T> = {\n\treadonly [P in keyof T]: RecursiveReadonly<T[P]>;\n};\n\n/**\n * Remove `readonly` from all fields.\n */\nexport type Mutable<T> = { -readonly [P in keyof T]: T[P] };\n\n/**\n * Make all field required and omits fields whose ony valid value would be `undefined`.\n * This is analogous to `Required<T>` except it tolerates 'optional undefined'.\n */\nexport type Populated<T> = {\n\t[P in keyof T as Exclude<P, T[P] extends undefined ? P : never>]-?: T[P];\n};\n\n/**\n * Casts a readonly object to a mutable one.\n * Better than casting to `Mutable<Foo>` because it doesn't risk casting a non-`Foo` to a `Mutable<Foo>`.\n * @param readonly - The object with readonly fields.\n * @returns The same object but with a type that makes all fields mutable.\n */\nexport function asMutable<T>(readonly: T): Mutable<T> {\n\treturn readonly as Mutable<T>;\n}\n\nexport const clone = structuredClone;\n\n/**\n */\nexport function fail(message: string): never {\n\tthrow new Error(message);\n}\n\n/**\n * Checks whether or not the given object is a `readonly` array.\n *\n * Note that this does NOT indicate if a given array should be treated as readonly.\n * This instead indicates if an object is an Array, and is typed to tolerate the readonly case.\n */\nexport function isReadonlyArray<T>(x: readonly T[] | unknown): x is readonly T[] {\n\t// `Array.isArray()` does not properly narrow `readonly` array types by itself,\n\t// so we wrap it in this type guard. This may become unnecessary if/when\n\t// https://github.com/microsoft/TypeScript/issues/17002 is resolved.\n\treturn Array.isArray(x);\n}\n\n/**\n * Creates and populates a new array.\n * @param size - The size of the array to be created.\n * @param filler - Callback for populating the array with a value for a given index\n */\nexport function makeArray<T>(size: number, filler: (index: number) => T): T[] {\n\tconst array = [];\n\tfor (let i = 0; i < size; ++i) {\n\t\tarray.push(filler(i));\n\t}\n\treturn array;\n}\n\n/**\n * Returns the last element of an array, or `undefined` if the array has no elements.\n * @param array - The array to get the last element from.\n * @remarks\n * If the type of the array has been narrowed by e.g. {@link hasSome | hasSome(array)} or {@link hasSingle | hasOne(array)} then the return type will be `T` rather than `T | undefined`.\n */\nexport function getLast<T>(array: readonly [T, ...T[]]): T;\nexport function getLast<T>(array: { [index: number]: T; length: number }): T | undefined;\nexport function getLast<T>(array: { [index: number]: T; length: number }): T | undefined {\n\treturn array[array.length - 1];\n}\n\n/**\n * Returns true if and only if the given array has at least one element.\n * @param array - The array to check.\n * @remarks\n * If `array` contains at least one element, its type will be narrowed and can benefit from improved typing from e.g. `array[0]` and {@link getLast | getLast(array)}.\n * This is especially useful when \"noUncheckedIndexedAccess\" is enabled in the TypeScript compiler options, since the return type of `array[0]` will be `T` rather than `T | undefined`.\n */\nexport function hasSome<T>(array: T[]): array is [T, ...T[]];\nexport function hasSome<T>(array: readonly T[]): array is readonly [T, ...T[]];\nexport function hasSome<T>(array: readonly T[]): array is [T, ...T[]] {\n\treturn array.length > 0;\n}\n\n/**\n * Returns true if and only if the given array has exactly one element.\n * @param array - The array to check.\n * @remarks\n * If `array` contains exactly one element, its type will be narrowed and can benefit from improved typing from e.g. `array[0]` and {@link getLast | getLast(array)}.\n * This is especially useful when \"noUncheckedIndexedAccess\" is enabled in the TypeScript compiler options, since the return type of `array[0]` will be `T` rather than `T | undefined`.\n */\nexport function hasSingle<T>(array: T[]): array is [T];\nexport function hasSingle<T>(array: readonly T[]): array is readonly [T];\nexport function hasSingle<T>(array: readonly T[]): array is [T] {\n\treturn array.length === 1;\n}\n\n/**\n * Compares two sets using callbacks.\n * Early returns on first false comparison.\n *\n * @param a - One Set.\n * @param b - The other Set.\n * @param aExtra - Called for items in `a` but not `b`.\n * @param bExtra - Called for items in `b` but not `a`.\n * @param same - Called for items in `a` and `b`.\n * @returns false iff any of the call backs returned false.\n */\nexport function compareSets<T>({\n\ta,\n\tb,\n\taExtra,\n\tbExtra,\n\tsame,\n}: {\n\ta: ReadonlySet<T> | ReadonlyMap<T, unknown>;\n\tb: ReadonlySet<T> | ReadonlyMap<T, unknown>;\n\taExtra?: (t: T) => boolean;\n\tbExtra?: (t: T) => boolean;\n\tsame?: (t: T) => boolean;\n}): boolean {\n\tfor (const item of a.keys()) {\n\t\tif (!b.has(item)) {\n\t\t\tif (aExtra !== undefined) {\n\t\t\t\tif (!aExtra(item)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t} else {\n\t\t\tif (same !== undefined && !same(item)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\tfor (const item of b.keys()) {\n\t\tif (!a.has(item)) {\n\t\t\tif (bExtra !== undefined) {\n\t\t\t\tif (!bExtra(item)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\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>(\n\tmap: MapGetSet<K, V>,\n\tkey: K,\n\tdefaultValue: (key: K) => V,\n): 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 * Utility for dictionaries whose values are lists.\n * Gets the list associated with the provided key, if it exists.\n * Otherwise, creates an entry with an empty list, and returns that list.\n */\nexport function getOrAddEmptyToMap<K, V>(map: MapGetSet<K, V[]>, key: K): V[] {\n\tlet collection = map.get(key);\n\tif (collection === undefined) {\n\t\tcollection = [];\n\t\tmap.set(key, collection);\n\t}\n\treturn collection;\n}\n\n/**\n * Map one iterable to another by transforming each element one at a time\n * @param iterable - the iterable to transform\n * @param map - the transformation function to run on each element of the iterable\n * @returns a new iterable of elements which have been transformed by the `map` function\n */\nexport function* mapIterable<T, U>(\n\titerable: Iterable<T>,\n\tmap: (t: T) => U,\n): IterableIterator<U> {\n\tfor (const t of iterable) {\n\t\tyield map(t);\n\t}\n}\n\n/**\n * Filter one iterable into another\n * @param iterable - the iterable to filter\n * @param filter - the predicate function to run on each element of the iterable\n * @returns a new iterable including only the elements that passed the filter predicate\n */\nexport function* filterIterable<T>(\n\titerable: Iterable<T>,\n\tfilter: (t: T) => boolean,\n): IterableIterator<T> {\n\tfor (const t of iterable) {\n\t\tif (filter(t)) {\n\t\t\tyield t;\n\t\t}\n\t}\n}\n\n/**\n * Finds the first element in the given iterable that satisfies a predicate.\n * @param iterable - The iterable to search for an eligible element\n * @param predicate - The predicate to run against each element\n * @returns The first element in the iterable that satisfies the predicate, or undefined if the iterable contains no such element\n */\nexport function find<T>(iterable: Iterable<T>, predicate: (t: T) => boolean): T | undefined {\n\tfor (const t of iterable) {\n\t\tif (predicate(t)) {\n\t\t\treturn t;\n\t\t}\n\t}\n}\n\n/**\n * Counts the number of elements in the given iterable.\n * @param iterable - the iterable to enumerate\n * @returns the number of elements that were iterated after exhausting the iterable\n */\nexport function count(iterable: Iterable<unknown>): number {\n\tlet n = 0;\n\tfor (const _ of iterable) {\n\t\tn += 1;\n\t}\n\treturn n;\n}\n\n/**\n * Use for Json compatible data.\n *\n * @typeparam TExtra - Type permitted in addition to the normal JSON types.\n * Commonly used for to allow {@link @fluidframework/core-interfaces#IFluidHandle} within the otherwise JSON compatible content.\n *\n * @remarks\n * This does not robustly forbid non json comparable data via type checking,\n * but instead mostly restricts access to it.\n * @alpha\n */\nexport type JsonCompatible<TExtra = never> =\n\t| string\n\t| number\n\t| boolean\n\t// eslint-disable-next-line @rushstack/no-new-null\n\t| null\n\t| JsonCompatible<TExtra>[]\n\t| JsonCompatibleObject<TExtra>\n\t| TExtra;\n\n/**\n * Use for Json object compatible data.\n * @remarks\n * This does not robustly forbid non json comparable data via type checking,\n * but instead mostly restricts access to it.\n * @alpha\n */\nexport type JsonCompatibleObject<TExtra = never> = { [P in string]?: JsonCompatible<TExtra> };\n\n/**\n * Use for readonly view of Json compatible data.\n * @remarks\n * This does not robustly forbid non json comparable data via type checking,\n * but instead mostly restricts access to it.\n */\nexport type JsonCompatibleReadOnly =\n\t| string\n\t| number\n\t| boolean\n\t// eslint-disable-next-line @rushstack/no-new-null\n\t| null\n\t| readonly JsonCompatibleReadOnly[]\n\t| JsonCompatibleReadOnlyObject;\n\n/**\n * Use for readonly view of Json compatible data.\n * @remarks\n * This does not robustly forbid non json comparable data via type checking,\n * but instead mostly restricts access to it.\n */\nexport type JsonCompatibleReadOnlyObject = { readonly [P in string]?: JsonCompatibleReadOnly };\n\n/**\n * @remarks TODO: Audit usage of this type in schemas, evaluating whether it is necessary and performance\n * of alternatives.\n *\n * True \"arbitrary serializable data\" is probably fine, but some persisted types declarations might be better\n * expressed using composition of schemas for runtime validation, even if we don't think making the types\n * generic is worth the maintenance cost.\n */\nexport const JsonCompatibleReadOnlySchema = Type.Any();\n\n/**\n * Returns if a particular json compatible value is an object.\n * Does not include `null` or arrays.\n */\nexport function isJsonObject(\n\tvalue: JsonCompatibleReadOnly,\n): value is { readonly [P in string]?: JsonCompatibleReadOnly } {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Verifies that the supplied indices are valid within the supplied array.\n * @param startIndex - The starting index in the range. Must be in [0, length).\n * @param endIndex - The ending index in the range. Must be within (start, length].\n * @param array - The array the indices refer to\n */\nexport function assertValidRangeIndices(\n\tstartIndex: number,\n\tendIndex: number,\n\tarray: { readonly length: number },\n): void {\n\tassert(endIndex >= startIndex, 0x79c /* Range indices are malformed. */);\n\tassertValidIndex(startIndex, array, false);\n\tassertValidIndex(endIndex, array, true);\n}\n\nexport function assertValidIndex(\n\tindex: number,\n\tarray: { readonly length: number },\n\tallowOnePastEnd: boolean = false,\n): void {\n\tassertNonNegativeSafeInteger(index);\n\tif (allowOnePastEnd) {\n\t\tassert(index <= array.length, 0x378 /* index must be less than or equal to length */);\n\t} else {\n\t\tassert(index < array.length, 0x379 /* index must be less than length */);\n\t}\n}\n\nexport function assertValidRange(\n\t{ start, end }: { start: number; end: number },\n\tarray: { readonly length: number },\n): void {\n\tassertNonNegativeSafeInteger(start);\n\tassertNonNegativeSafeInteger(end);\n\tassert(end <= array.length, 0x79d /* Range end must be less than or equal to length */);\n\tassert(start <= end, 0x79e /* Range start must be less than or equal to range start */);\n}\n\nexport function assertNonNegativeSafeInteger(index: number): void {\n\tassert(Number.isSafeInteger(index), 0x376 /* index must be an integer */);\n\tassert(index >= 0, 0x377 /* index must be non-negative */);\n}\n\n/**\n * Convert an object into a Map.\n *\n * This function must only be used with objects specifically intended to encode map like information.\n * The only time such objects should be used is for encoding maps as object literals to allow for developer ergonomics or JSON compatibility.\n * Even those two use-cases need to be carefully considered as using objects as maps can have a lot of issues\n * (including but not limited to unintended access to __proto__ and other non-owned keys).\n * This function helps these few cases get into using an actual map in as safe of was as is practical.\n */\nexport function objectToMap<MapKey extends string | number | symbol, MapValue>(\n\tobjectMap: Record<MapKey, MapValue>,\n): Map<MapKey, MapValue> {\n\tconst map = new Map<MapKey, MapValue>();\n\t// This function must only be used with objects specifically intended to encode map like information.\n\tfor (const key of Object.keys(objectMap)) {\n\t\tconst element = objectMap[key as MapKey];\n\t\tmap.set(key as MapKey, element);\n\t}\n\treturn map;\n}\n\n/**\n * Convert an object used as a map into a new object used like a map.\n *\n * @remarks\n * This function must only be used with objects specifically intended to encode map like information.\n * The only time such objects should be used is for encoding maps as object literals to allow for developer ergonomics or JSON compatibility.\n * Even those two use-cases need to be carefully considered as using objects as maps can have a lot of issues\n * (including but not limited to unintended access to __proto__ and other non-owned keys).\n * {@link objectToMap} helps these few cases get into using an actual map in as safe of a way as is practical.\n */\nexport function transformObjectMap<\n\tMapKey extends string | number | symbol,\n\tMapValue,\n\tNewMapValue,\n>(\n\tobjectMap: Record<MapKey, MapValue>,\n\ttransformer: (value: MapValue, key: MapKey) => NewMapValue,\n): Record<MapKey, MapValue> {\n\tconst output: Record<MapKey, MapValue> = Object.create(null);\n\t// This function must only be used with objects specifically intended to encode map like information.\n\tfor (const key of Object.keys(objectMap)) {\n\t\tconst element = objectMap[key as MapKey];\n\t\tObject.defineProperty(output, key, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t\twritable: true,\n\t\t\tvalue: transformer(element, key as MapKey),\n\t\t});\n\t}\n\treturn output;\n}\n\n/**\n * Make an inverted copy of a map.\n *\n * @returns a map which can look up the keys from the values of the original map.\n */\nexport function invertMap<Key, Value>(input: Map<Key, Value>): Map<Value, Key> {\n\tconst result = new Map<Value, Key>(mapIterable(input, ([key, value]) => [value, key]));\n\tassert(\n\t\tresult.size === input.size,\n\t\t0x88a /* all values in a map must be unique to invert it */,\n\t);\n\treturn result;\n}\n\n/**\n * Returns the value from `set` if it contains exactly one item, otherwise `undefined`.\n */\nexport function oneFromSet<T>(set: ReadonlySet<T> | undefined): T | undefined {\n\tif (set === undefined) {\n\t\treturn undefined;\n\t}\n\tif (set.size !== 1) {\n\t\treturn undefined;\n\t}\n\tfor (const item of set) {\n\t\treturn item;\n\t}\n}\n\n/**\n * Type with a name describing what it is.\n * Typically used with values (like schema) that can be stored in a map, but in some representations have their name/key as a field.\n */\nexport interface Named<TName> {\n\treadonly name: TName;\n}\n\n/**\n * Order {@link Named} objects by their name.\n */\nexport function compareNamed(a: Named<string>, b: Named<string>): -1 | 0 | 1 {\n\tif (a.name < b.name) {\n\t\treturn -1;\n\t}\n\tif (a.name > b.name) {\n\t\treturn 1;\n\t}\n\treturn 0;\n}\n\n/**\n * Placeholder for `Symbol.dispose`.\n * @privateRemarks\n * TODO: replace this with `Symbol.dispose` when it is available or make it a valid polyfill.\n */\nexport const disposeSymbol: unique symbol = Symbol(\"Symbol.dispose placeholder\");\n\n/**\n * An object with an explicit lifetime that can be ended.\n * @privateRemarks\n * Simpler alternative to core-utils/IDisposable for internal use in this package.\n * This avoids adding a named \"dispose\" method, and will eventually be replaced with\n * {@link https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management| TypeScript's Disposable}.\n *\n * Once this is replaced with TypeScript's Disposable, core-utils/IDisposable can extend it, bringing the APIs into a reasonable alignment.\n */\nexport interface IDisposable {\n\t/**\n\t * Call to end the lifetime of this object.\n\t *\n\t * It is invalid to use this object after this,\n\t * except for operations which explicitly document they are valid after disposal.\n\t *\n\t * @remarks\n\t * May cleanup resources retained by this object.\n\t * Often includes un-registering from events and thus preventing other objects from retaining a reference to this indefinably.\n\t *\n\t * Usually the only operations allowed after disposal are querying if an object is already disposed,\n\t * but this can vary between implementations.\n\t */\n\t[disposeSymbol](): void;\n}\n\n/**\n * Capitalize a string.\n */\nexport function capitalize<S extends string>(s: S): Capitalize<S> {\n\t// To avoid splitting characters which are made of multiple UTF-16 code units,\n\t// use iteration instead of indexing to separate the first character.\n\tconst iterated = s[Symbol.iterator]().next();\n\tif (iterated.done === true) {\n\t\t// Empty string case.\n\t\treturn \"\" as Capitalize<S>;\n\t}\n\n\treturn (iterated.value.toUpperCase() + s.slice(iterated.value.length)) as Capitalize<S>;\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 * Defines a property on an object that is lazily initialized and cached.\n * @remarks This is useful for properties that are expensive to compute and it is not guaranteed that they will be accessed.\n * This function initially defines a getter on the object, but after first read it replaces the getter with a value property.\n * @param obj - The object on which to define the property.\n * @param key - The key of the property to define.\n * @param get - The function (called either once or not at all) to compute the value of the property.\n * @returns `obj`, typed such that it has the new property.\n * This allows for the new property to be read off of `obj` in a type-safe manner after calling this function.\n */\nexport function defineLazyCachedProperty<\n\tT extends object,\n\tK extends string | number | symbol,\n\tV,\n>(obj: T, key: K, get: () => V): typeof obj & { [P in K]: V } {\n\tReflect.defineProperty(obj, key, {\n\t\tget() {\n\t\t\tconst value = get();\n\t\t\tReflect.defineProperty(obj, key, { value });\n\t\t\treturn value;\n\t\t},\n\t\tconfigurable: true,\n\t});\n\treturn obj as typeof obj & { [P in K]: V };\n}\n\n/**\n * Copies a given property from one object to another if and only if the property is defined.\n * @param source - The object to copy the property from.\n * If `source` is undefined or does not have the property defined, then this function will do nothing.\n * @param property - The property to copy.\n * @param destination - The object to copy the property to.\n * @remarks This function is useful for copying properties from one object to another while minimizing the presence of `undefined` values.\n * If `property` is not present on `source` - or if `property` is present, but has a value of `undefined` - then this function will not modify `destination`.\n * This is different from doing `destination.foo = source.foo`, which would define a `\"foo\"` property on `destination` with the value `undefined`.\n *\n * If the type of `source` is known to have `property`, then this function asserts that the type of `destination` has `property` as well after the call.\n *\n * This function first reads the property value (if present) from `source` and then sets it on `destination`, as opposed to e.g. directly copying the property descriptor.\n * @privateRemarks The first overload of this function allows auto-complete to suggest property names from `source`, but by having the second overload we still allow for arbitrary property names.\n */\nexport function copyPropertyIfDefined<S extends object, K extends keyof S, D extends object>(\n\tsource: S | undefined,\n\tproperty: K,\n\tdestination: D,\n): asserts destination is K extends keyof S ? D & { [P in K]: S[K] } : D;\nexport function copyPropertyIfDefined<\n\tS extends object,\n\tK extends string | number | symbol,\n\tD extends object,\n>(\n\tsource: S | undefined,\n\tproperty: K,\n\tdestination: D,\n): asserts destination is K extends keyof S ? D & { [P in K]: S[K] } : D;\nexport function copyPropertyIfDefined<\n\tS extends object,\n\tK extends string | number | symbol,\n\tD extends object,\n>(\n\tsource: S | undefined,\n\tproperty: K,\n\tdestination: D,\n): asserts destination is K extends keyof S ? D & { [P in K]: S[K] } : D {\n\tif (source !== undefined) {\n\t\tconst value = (source as { [P in K]?: unknown })[property];\n\t\tif (value !== undefined) {\n\t\t\t(destination as { [P in K]: unknown })[property] = value;\n\t\t}\n\t}\n}\n"]}
|