@fluidframework/tree 2.4.0 → 2.5.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/.vscode/settings.json +12 -1
- package/CHANGELOG.md +371 -0
- package/api-report/tree.alpha.api.md +271 -80
- package/api-report/tree.beta.api.md +100 -51
- package/api-report/tree.legacy.alpha.api.md +99 -50
- package/api-report/tree.legacy.public.api.md +99 -50
- package/api-report/tree.public.api.md +99 -50
- package/dist/alpha.d.ts +32 -2
- package/dist/beta.d.ts +6 -0
- package/dist/codec/codec.d.ts +24 -0
- package/dist/codec/codec.d.ts.map +1 -1
- package/dist/codec/codec.js +26 -1
- package/dist/codec/codec.js.map +1 -1
- package/dist/codec/index.d.ts +1 -1
- package/dist/codec/index.d.ts.map +1 -1
- package/dist/codec/index.js +2 -1
- package/dist/codec/index.js.map +1 -1
- package/dist/core/rebase/index.d.ts +2 -2
- package/dist/core/rebase/index.d.ts.map +1 -1
- package/dist/core/rebase/index.js +2 -2
- package/dist/core/rebase/index.js.map +1 -1
- package/dist/core/rebase/types.d.ts +0 -4
- package/dist/core/rebase/types.d.ts.map +1 -1
- package/dist/core/rebase/types.js +1 -7
- package/dist/core/rebase/types.js.map +1 -1
- package/dist/core/rebase/utils.d.ts +1 -0
- package/dist/core/rebase/utils.d.ts.map +1 -1
- package/dist/core/rebase/utils.js +29 -4
- package/dist/core/rebase/utils.js.map +1 -1
- package/dist/events/interop.d.ts +1 -7
- package/dist/events/interop.d.ts.map +1 -1
- package/dist/events/interop.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/basicChunk.js +1 -1
- package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/uniformChunk.js +1 -1
- package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +8 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts +2 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.js +3 -0
- package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/dist/feature-libraries/object-forest/objectForest.js +1 -1
- package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
- package/dist/feature-libraries/treeCursorUtils.js +2 -2
- package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/dist/internalTypes.d.ts +1 -1
- package/dist/internalTypes.d.ts.map +1 -1
- package/dist/internalTypes.js.map +1 -1
- package/dist/legacy.d.ts +6 -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 +6 -0
- package/dist/shared-tree/independentView.d.ts +57 -0
- package/dist/shared-tree/independentView.d.ts.map +1 -0
- package/dist/shared-tree/independentView.js +89 -0
- package/dist/shared-tree/independentView.js.map +1 -0
- package/dist/shared-tree/index.d.ts +3 -1
- package/dist/shared-tree/index.d.ts.map +1 -1
- package/dist/shared-tree/index.js +6 -1
- package/dist/shared-tree/index.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts +12 -8
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +28 -0
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +10 -7
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/treeApi.d.ts +6 -6
- package/dist/shared-tree/treeApi.d.ts.map +1 -1
- package/dist/shared-tree/treeApi.js.map +1 -1
- package/dist/shared-tree/treeApiAlpha.d.ts +147 -0
- package/dist/shared-tree/treeApiAlpha.d.ts.map +1 -0
- package/dist/shared-tree/treeApiAlpha.js +122 -0
- package/dist/shared-tree/treeApiAlpha.js.map +1 -0
- package/dist/shared-tree/treeCheckout.d.ts +12 -7
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +11 -4
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/editManager.d.ts +13 -6
- package/dist/shared-tree-core/editManager.d.ts.map +1 -1
- package/dist/shared-tree-core/editManager.js +80 -33
- package/dist/shared-tree-core/editManager.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts +1 -0
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +28 -3
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/conciseTree.d.ts +2 -1
- package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/conciseTree.js.map +1 -1
- package/dist/simple-tree/api/create.d.ts +6 -24
- package/dist/simple-tree/api/create.d.ts.map +1 -1
- package/dist/simple-tree/api/create.js +4 -19
- package/dist/simple-tree/api/create.js.map +1 -1
- package/dist/simple-tree/api/customTree.d.ts +1 -0
- package/dist/simple-tree/api/customTree.d.ts.map +1 -1
- package/dist/simple-tree/api/customTree.js +2 -2
- package/dist/simple-tree/api/customTree.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +7 -7
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +10 -2
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.d.ts +25 -27
- package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.js +31 -21
- package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +16 -12
- package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactory.js +4 -0
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +3 -3
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/storedSchema.js +2 -2
- package/dist/simple-tree/api/storedSchema.js.map +1 -1
- package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
- package/dist/simple-tree/api/tree.d.ts +122 -5
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js +12 -4
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/treeApiBeta.d.ts +8 -5
- package/dist/simple-tree/api/treeApiBeta.d.ts.map +1 -1
- package/dist/simple-tree/api/treeApiBeta.js +3 -15
- package/dist/simple-tree/api/treeApiBeta.js.map +1 -1
- package/dist/simple-tree/api/typesUnsafe.d.ts +69 -17
- package/dist/simple-tree/api/typesUnsafe.d.ts.map +1 -1
- package/dist/simple-tree/api/typesUnsafe.js.map +1 -1
- package/dist/simple-tree/api/verboseTree.d.ts +3 -0
- package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/verboseTree.js.map +1 -1
- package/dist/simple-tree/arrayNode.d.ts +15 -4
- package/dist/simple-tree/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/arrayNode.js +1 -1
- package/dist/simple-tree/arrayNode.js.map +1 -1
- package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.d.ts +51 -11
- 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/core/unhydratedFlexTree.d.ts +2 -1
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js +3 -0
- package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/dist/simple-tree/core/withType.d.ts +2 -1
- package/dist/simple-tree/core/withType.d.ts.map +1 -1
- package/dist/simple-tree/core/withType.js.map +1 -1
- package/dist/simple-tree/createContext.js +2 -2
- package/dist/simple-tree/createContext.js.map +1 -1
- package/dist/simple-tree/index.d.ts +6 -6
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +15 -5
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/leafNodeSchema.d.ts +6 -5
- package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/leafNodeSchema.js +3 -0
- package/dist/simple-tree/leafNodeSchema.js.map +1 -1
- package/dist/simple-tree/mapNode.d.ts +1 -1
- package/dist/simple-tree/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/mapNode.js +6 -0
- package/dist/simple-tree/mapNode.js.map +1 -1
- package/dist/simple-tree/objectNode.d.ts +4 -2
- package/dist/simple-tree/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/objectNode.js.map +1 -1
- package/dist/simple-tree/schemaTypes.d.ts +210 -18
- package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
- package/dist/simple-tree/schemaTypes.js +66 -1
- package/dist/simple-tree/schemaTypes.js.map +1 -1
- package/dist/simple-tree/toMapTree.d.ts +4 -2
- package/dist/simple-tree/toMapTree.d.ts.map +1 -1
- package/dist/simple-tree/toMapTree.js.map +1 -1
- package/dist/simple-tree/{toFlexSchema.d.ts → toStoredSchema.d.ts} +1 -1
- package/dist/simple-tree/toStoredSchema.d.ts.map +1 -0
- package/dist/simple-tree/{toFlexSchema.js → toStoredSchema.js} +1 -1
- package/dist/simple-tree/toStoredSchema.js.map +1 -0
- package/dist/simple-tree/treeNodeValid.d.ts +5 -1
- package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
- package/dist/simple-tree/treeNodeValid.js +7 -1
- package/dist/simple-tree/treeNodeValid.js.map +1 -1
- package/dist/util/index.d.ts +3 -2
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +3 -1
- package/dist/util/index.js.map +1 -1
- package/dist/util/typeCheck.d.ts +9 -0
- package/dist/util/typeCheck.d.ts.map +1 -1
- package/dist/util/typeCheck.js.map +1 -1
- package/dist/util/typeUtils.d.ts +61 -0
- package/dist/util/typeUtils.d.ts.map +1 -1
- package/dist/util/typeUtils.js +27 -0
- package/dist/util/typeUtils.js.map +1 -1
- package/dist/util/utils.d.ts +7 -3
- package/dist/util/utils.d.ts.map +1 -1
- package/dist/util/utils.js +13 -3
- package/dist/util/utils.js.map +1 -1
- package/lib/alpha.d.ts +32 -2
- package/lib/beta.d.ts +6 -0
- package/lib/codec/codec.d.ts +24 -0
- package/lib/codec/codec.d.ts.map +1 -1
- package/lib/codec/codec.js +25 -0
- package/lib/codec/codec.js.map +1 -1
- package/lib/codec/index.d.ts +1 -1
- package/lib/codec/index.d.ts.map +1 -1
- package/lib/codec/index.js +1 -1
- package/lib/codec/index.js.map +1 -1
- package/lib/core/rebase/index.d.ts +2 -2
- package/lib/core/rebase/index.d.ts.map +1 -1
- package/lib/core/rebase/index.js +2 -2
- package/lib/core/rebase/index.js.map +1 -1
- package/lib/core/rebase/types.d.ts +0 -4
- package/lib/core/rebase/types.d.ts.map +1 -1
- package/lib/core/rebase/types.js +0 -5
- package/lib/core/rebase/types.js.map +1 -1
- package/lib/core/rebase/utils.d.ts +1 -0
- package/lib/core/rebase/utils.d.ts.map +1 -1
- package/lib/core/rebase/utils.js +27 -3
- package/lib/core/rebase/utils.js.map +1 -1
- package/lib/events/interop.d.ts +1 -7
- package/lib/events/interop.d.ts.map +1 -1
- package/lib/events/interop.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/basicChunk.js +1 -1
- package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/uniformChunk.js +1 -1
- package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +8 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts +2 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.js +3 -0
- package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/lib/feature-libraries/object-forest/objectForest.js +1 -1
- package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
- package/lib/feature-libraries/treeCursorUtils.js +2 -2
- package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -3
- package/lib/index.js.map +1 -1
- package/lib/internalTypes.d.ts +1 -1
- package/lib/internalTypes.d.ts.map +1 -1
- package/lib/internalTypes.js.map +1 -1
- package/lib/legacy.d.ts +6 -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 +6 -0
- package/lib/shared-tree/independentView.d.ts +57 -0
- package/lib/shared-tree/independentView.d.ts.map +1 -0
- package/lib/shared-tree/independentView.js +84 -0
- package/lib/shared-tree/independentView.js.map +1 -0
- package/lib/shared-tree/index.d.ts +3 -1
- package/lib/shared-tree/index.d.ts.map +1 -1
- package/lib/shared-tree/index.js +2 -0
- package/lib/shared-tree/index.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts +12 -8
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +29 -1
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +10 -7
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/treeApi.d.ts +6 -6
- package/lib/shared-tree/treeApi.d.ts.map +1 -1
- package/lib/shared-tree/treeApi.js.map +1 -1
- package/lib/shared-tree/treeApiAlpha.d.ts +147 -0
- package/lib/shared-tree/treeApiAlpha.d.ts.map +1 -0
- package/lib/shared-tree/treeApiAlpha.js +119 -0
- package/lib/shared-tree/treeApiAlpha.js.map +1 -0
- package/lib/shared-tree/treeCheckout.d.ts +12 -7
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +11 -4
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/editManager.d.ts +13 -6
- package/lib/shared-tree-core/editManager.d.ts.map +1 -1
- package/lib/shared-tree-core/editManager.js +80 -33
- package/lib/shared-tree-core/editManager.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts +1 -0
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +29 -4
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/conciseTree.d.ts +2 -1
- package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/conciseTree.js.map +1 -1
- package/lib/simple-tree/api/create.d.ts +6 -24
- package/lib/simple-tree/api/create.d.ts.map +1 -1
- package/lib/simple-tree/api/create.js +2 -16
- package/lib/simple-tree/api/create.js.map +1 -1
- package/lib/simple-tree/api/customTree.d.ts +1 -0
- package/lib/simple-tree/api/customTree.d.ts.map +1 -1
- package/lib/simple-tree/api/customTree.js +2 -2
- package/lib/simple-tree/api/customTree.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +7 -7
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +6 -4
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.d.ts +25 -27
- package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.js +30 -19
- package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +16 -12
- package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactory.js +4 -0
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +3 -3
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/storedSchema.js +1 -1
- package/lib/simple-tree/api/storedSchema.js.map +1 -1
- package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
- package/lib/simple-tree/api/tree.d.ts +122 -5
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js +9 -2
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/treeApiBeta.d.ts +8 -5
- package/lib/simple-tree/api/treeApiBeta.d.ts.map +1 -1
- package/lib/simple-tree/api/treeApiBeta.js +4 -16
- package/lib/simple-tree/api/treeApiBeta.js.map +1 -1
- package/lib/simple-tree/api/typesUnsafe.d.ts +69 -17
- package/lib/simple-tree/api/typesUnsafe.d.ts.map +1 -1
- package/lib/simple-tree/api/typesUnsafe.js.map +1 -1
- package/lib/simple-tree/api/verboseTree.d.ts +3 -0
- package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/verboseTree.js.map +1 -1
- package/lib/simple-tree/arrayNode.d.ts +15 -4
- package/lib/simple-tree/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/arrayNode.js +1 -1
- package/lib/simple-tree/arrayNode.js.map +1 -1
- package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.d.ts +51 -11
- 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/core/unhydratedFlexTree.d.ts +2 -1
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js +4 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/lib/simple-tree/core/withType.d.ts +2 -1
- package/lib/simple-tree/core/withType.d.ts.map +1 -1
- package/lib/simple-tree/core/withType.js.map +1 -1
- package/lib/simple-tree/createContext.js +1 -1
- package/lib/simple-tree/createContext.js.map +1 -1
- package/lib/simple-tree/index.d.ts +6 -6
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +5 -5
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/leafNodeSchema.d.ts +6 -5
- package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/leafNodeSchema.js +3 -0
- package/lib/simple-tree/leafNodeSchema.js.map +1 -1
- package/lib/simple-tree/mapNode.d.ts +1 -1
- package/lib/simple-tree/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/mapNode.js +6 -0
- package/lib/simple-tree/mapNode.js.map +1 -1
- package/lib/simple-tree/objectNode.d.ts +4 -2
- package/lib/simple-tree/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/objectNode.js.map +1 -1
- package/lib/simple-tree/schemaTypes.d.ts +210 -18
- package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
- package/lib/simple-tree/schemaTypes.js +64 -1
- package/lib/simple-tree/schemaTypes.js.map +1 -1
- package/lib/simple-tree/toMapTree.d.ts +4 -2
- package/lib/simple-tree/toMapTree.d.ts.map +1 -1
- package/lib/simple-tree/toMapTree.js.map +1 -1
- package/lib/simple-tree/{toFlexSchema.d.ts → toStoredSchema.d.ts} +1 -1
- package/lib/simple-tree/toStoredSchema.d.ts.map +1 -0
- package/lib/simple-tree/{toFlexSchema.js → toStoredSchema.js} +1 -1
- package/lib/simple-tree/toStoredSchema.js.map +1 -0
- package/lib/simple-tree/treeNodeValid.d.ts +5 -1
- package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
- package/lib/simple-tree/treeNodeValid.js +7 -1
- package/lib/simple-tree/treeNodeValid.js.map +1 -1
- package/lib/util/index.d.ts +3 -2
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/typeCheck.d.ts +9 -0
- package/lib/util/typeCheck.d.ts.map +1 -1
- package/lib/util/typeCheck.js.map +1 -1
- package/lib/util/typeUtils.d.ts +61 -0
- package/lib/util/typeUtils.d.ts.map +1 -1
- package/lib/util/typeUtils.js +25 -1
- package/lib/util/typeUtils.js.map +1 -1
- package/lib/util/utils.d.ts +7 -3
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js +13 -3
- package/lib/util/utils.js.map +1 -1
- package/package.json +55 -30
- package/src/codec/codec.ts +25 -0
- package/src/codec/index.ts +1 -0
- package/src/core/rebase/index.ts +1 -1
- package/src/core/rebase/types.ts +0 -12
- package/src/core/rebase/utils.ts +35 -3
- package/src/events/interop.ts +1 -12
- package/src/feature-libraries/chunked-forest/basicChunk.ts +1 -1
- package/src/feature-libraries/chunked-forest/uniformChunk.ts +1 -1
- package/src/feature-libraries/flex-tree/flexTreeTypes.ts +9 -0
- package/src/feature-libraries/flex-tree/lazyNode.ts +5 -0
- package/src/feature-libraries/object-forest/objectForest.ts +1 -1
- package/src/feature-libraries/treeCursorUtils.ts +2 -2
- package/src/index.ts +36 -6
- package/src/internalTypes.ts +4 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/independentView.ts +176 -0
- package/src/shared-tree/index.ts +9 -1
- package/src/shared-tree/schematizingTreeView.ts +64 -13
- package/src/shared-tree/sharedTree.ts +29 -9
- package/src/shared-tree/treeApi.ts +19 -9
- package/src/shared-tree/treeApiAlpha.ts +401 -0
- package/src/shared-tree/treeCheckout.ts +28 -5
- package/src/shared-tree-core/editManager.ts +126 -59
- package/src/shared-tree-core/sharedTreeCore.ts +37 -8
- package/src/simple-tree/api/conciseTree.ts +2 -1
- package/src/simple-tree/api/create.ts +33 -65
- package/src/simple-tree/api/customTree.ts +3 -2
- package/src/simple-tree/api/index.ts +19 -8
- package/src/simple-tree/api/schemaCreationUtilities.ts +59 -37
- package/src/simple-tree/api/schemaFactory.ts +28 -12
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +3 -3
- package/src/simple-tree/api/storedSchema.ts +1 -1
- package/src/simple-tree/api/tree.ts +152 -7
- package/src/simple-tree/api/treeApiBeta.ts +35 -31
- package/src/simple-tree/api/typesUnsafe.ts +125 -30
- package/src/simple-tree/api/verboseTree.ts +3 -0
- package/src/simple-tree/arrayNode.ts +38 -17
- package/src/simple-tree/core/getOrCreateNode.ts +1 -1
- package/src/simple-tree/core/treeNodeSchema.ts +107 -34
- package/src/simple-tree/core/unhydratedFlexTree.ts +6 -0
- package/src/simple-tree/core/withType.ts +2 -1
- package/src/simple-tree/createContext.ts +1 -1
- package/src/simple-tree/index.ts +34 -3
- package/src/simple-tree/leafNodeSchema.ts +6 -1
- package/src/simple-tree/mapNode.ts +13 -4
- package/src/simple-tree/objectNode.ts +5 -3
- package/src/simple-tree/schemaTypes.ts +342 -36
- package/src/simple-tree/toMapTree.ts +4 -1
- package/src/simple-tree/treeNodeValid.ts +11 -1
- package/src/util/index.ts +7 -0
- package/src/util/typeCheck.ts +13 -0
- package/src/util/typeUtils.ts +87 -0
- package/src/util/utils.ts +20 -7
- package/dist/simple-tree/toFlexSchema.d.ts.map +0 -1
- package/dist/simple-tree/toFlexSchema.js.map +0 -1
- package/lib/simple-tree/toFlexSchema.d.ts.map +0 -1
- package/lib/simple-tree/toFlexSchema.js.map +0 -1
- /package/src/simple-tree/{toFlexSchema.ts → toStoredSchema.ts} +0 -0
package/lib/util/typeUtils.d.ts
CHANGED
|
@@ -105,4 +105,65 @@ export type RestrictiveStringRecord<T> = {
|
|
|
105
105
|
} & {
|
|
106
106
|
readonly [P in symbol]?: never;
|
|
107
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Returns `true` if T is a union and false if it is not.
|
|
110
|
+
* @typeparam T - Type to test if it is a union.
|
|
111
|
+
* @typeparam T2 - Do not specify: default value used as implementation detail.
|
|
112
|
+
* @system @alpha
|
|
113
|
+
*/
|
|
114
|
+
export type IsUnion<T, T2 = T> = T extends unknown ? [T2] extends [T] ? false : true : "error";
|
|
115
|
+
/**
|
|
116
|
+
* Convert a union of types to an intersection of those types. Useful for `TransformEvents`.
|
|
117
|
+
* @privateRemarks
|
|
118
|
+
* First an always true extends clause is used (T extends T) to distribute T into to a union of types contravariant over each member of the T union.
|
|
119
|
+
* Then the constraint on the type parameter in this new context is inferred, giving the intersection.
|
|
120
|
+
* @system @public
|
|
121
|
+
*/
|
|
122
|
+
export type UnionToIntersection<T> = (T extends T ? (k: T) => unknown : never) extends (k: infer U) => unknown ? U : never;
|
|
123
|
+
/**
|
|
124
|
+
* Gets the first item of a union type.
|
|
125
|
+
*
|
|
126
|
+
* @typeparam Union - The union to convert.
|
|
127
|
+
* @typeparam AsOverloadedFunction - Implementation detail: do not specify.
|
|
128
|
+
* @system @alpha
|
|
129
|
+
*/
|
|
130
|
+
export type PopUnion<Union, AsOverloadedFunction = UnionToIntersection<Union extends unknown ? (f: Union) => void : never>> = AsOverloadedFunction extends (a: infer First) => void ? First : never;
|
|
131
|
+
/**
|
|
132
|
+
* Converts a union type to a tuple type.
|
|
133
|
+
*
|
|
134
|
+
* @typeparam T - The union to convert.
|
|
135
|
+
* @typeparam A - Implementation detail: do not specify.
|
|
136
|
+
* @typeparam First - Implementation detail: do not specify.
|
|
137
|
+
*
|
|
138
|
+
* @privateRemarks
|
|
139
|
+
* `A` is a tuple to prepend members of the union to.
|
|
140
|
+
*
|
|
141
|
+
* https://www.hacklewayne.com/typescript-convert-union-to-tuple-array-yes-but-how and https://catchts.com/union-array both explain the general approach this uses pretty well.
|
|
142
|
+
* This implementation is inspired to those, but slightly different in implementation.
|
|
143
|
+
* @alpha
|
|
144
|
+
*/
|
|
145
|
+
export type UnionToTuple<Union, A extends unknown[] = [], First = PopUnion<Union>> = IsUnion<Union> extends true ? UnionToTuple<Exclude<Union, First>, [First, ...A]> : [Union, ...A];
|
|
146
|
+
/**
|
|
147
|
+
* This is unsafe, meaning that the returned value might not match its type.
|
|
148
|
+
*
|
|
149
|
+
* For the result to match its type, T must be a union of the types of each item in `items` in the order that they occur.
|
|
150
|
+
* For this to be possible, there must be no duplicate or overlapping types.
|
|
151
|
+
* This is fragile and must be used with care.
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* The main use-case for this is recovering lost information from {@link AllowedTypes} which is necessary to preserve when using them with {@link Input} APIs.
|
|
155
|
+
* Since {@link AllowedTypes} is actually order independent, it is somewhat safer when used to produce `AllowedTypes`.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* // Gives imprecise type (typeof A | typeof B)[]
|
|
160
|
+
* const schemaBad = [A, B];
|
|
161
|
+
* // Fixes the type to be [typeof A, typeof B]
|
|
162
|
+
* const schema = unsafeArrayToTuple(schemaBad);
|
|
163
|
+
*
|
|
164
|
+
* const config = new TreeViewConfiguration({ schema });
|
|
165
|
+
* ```
|
|
166
|
+
* @alpha
|
|
167
|
+
*/
|
|
168
|
+
export declare function unsafeArrayToTuple<T>(items: T[]): UnionToTuple<T>;
|
|
108
169
|
//# sourceMappingURL=typeUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeUtils.d.ts","sourceRoot":"","sources":["../../src/util/typeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AAEH;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC;KAAG,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;CAAE,CAAC,CAAC,YAAY,CAAC,CAAC;AAEpF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EjB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAEjE"}
|
package/lib/util/typeUtils.js
CHANGED
|
@@ -6,5 +6,29 @@
|
|
|
6
6
|
{
|
|
7
7
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* This is unsafe, meaning that the returned value might not match its type.
|
|
11
|
+
*
|
|
12
|
+
* For the result to match its type, T must be a union of the types of each item in `items` in the order that they occur.
|
|
13
|
+
* For this to be possible, there must be no duplicate or overlapping types.
|
|
14
|
+
* This is fragile and must be used with care.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* The main use-case for this is recovering lost information from {@link AllowedTypes} which is necessary to preserve when using them with {@link Input} APIs.
|
|
18
|
+
* Since {@link AllowedTypes} is actually order independent, it is somewhat safer when used to produce `AllowedTypes`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Gives imprecise type (typeof A | typeof B)[]
|
|
23
|
+
* const schemaBad = [A, B];
|
|
24
|
+
* // Fixes the type to be [typeof A, typeof B]
|
|
25
|
+
* const schema = unsafeArrayToTuple(schemaBad);
|
|
26
|
+
*
|
|
27
|
+
* const config = new TreeViewConfiguration({ schema });
|
|
28
|
+
* ```
|
|
29
|
+
* @alpha
|
|
30
|
+
*/
|
|
31
|
+
export function unsafeArrayToTuple(items) {
|
|
32
|
+
return items;
|
|
33
|
+
}
|
|
10
34
|
//# sourceMappingURL=typeUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeUtils.js","sourceRoot":"","sources":["../../src/util/typeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA8EH,wIAAwI;AACxI,CAAC;IAwBA,qDAAqD;AACtD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Utilities for manipulating types.\n */\n\n/**\n * Return a type thats equivalent to the input, but with different IntelliSense.\n * This tends to convert unions and intersections into objects.\n * @system @public\n */\nexport type FlattenKeys<T> = [{ [Property in keyof T]: T[Property] }][_InlineTrick];\n\n/**\n * Use for trick to \"inline\" generic types.\n *\n * @remarks\n * The TypeScript compiler can be convinced to inline a generic type\n * (so the result of evaluating the generic type show up in IntelliSense and error messages instead of just the invocation of the generic type)\n * by creating an object with a field, and returning the type of that field.\n *\n * For example:\n * ```typescript\n * type MyGeneric<T1, T2> = {x: T1 extends [] ? T1 : T2 };\n * type MyGenericExpanded<T1, T2> = [{x: T1 extends [] ? T1 : T2 }][_InlineTrick]\n *\n * // Type is MyGeneric<5, string>\n * const foo: MyGeneric<5, string> = {x: \"x\"}\n * // Type is {x: \"x\"}\n * const foo2: MyGenericExpanded<5, string> = {x: \"x\"}\n * ```\n *\n * This constant is defined to provide a way to find this documentation from types which use this pattern,\n * and to locate types which use this pattern in case they need updating for compiler changes.\n * @system @public\n */\nexport type _InlineTrick = 0;\n\n/**\n * Use for trick to prevent self reference error `ts(2456)`.\n *\n * Prefix a type expression with `K extends _RecursiveTrick ? _RecursiveTrick : ` for some K to break the cycle.\n *\n * @remarks\n * The TypeScript compiler handles some cases of recursive types, but not others.\n * Sometimes adding an otherwise needless conditional can make a type compile.\n * Use this type in such cases.\n *\n *For example:\n * ```typescript\n * // The TypeScript compiler can't handle this case\n * type Broken<T> = FlattenKeys<\n *\t{\n * \t\t[K in keyof T]: 0;\n * \t} & {\n * \t\t[K in keyof T]: Broken<T[K]>;\n * \t}\n * >;\n *\n * // Adding `K extends _RecursiveTrick ? _RecursiveTrick :` makes it compile, and has no effect on the type produced.\n * type Works<T> = FlattenKeys<\n * \t{\n * \t\t[K in keyof T]: 0;\n * \t} & {\n * \t\t// Trick added here. Since `k` never extends `never`, the second conditional option is always taken,\n * \t\t// making this equivalent to the broken version, except this one compiles.\n * \t\t[K in keyof T]: K extends _RecursiveTrick ? _RecursiveTrick : Works<T[K]>;\n * \t}\n * >;\n * ```\n *\n * This trick appears to start working in TypeScript 4.1 and is confirmed to still work in 5.0.4.\n *\n * This constant is defined to provide a way to find this documentation from types which use this pattern,\n * and to locate types which use this pattern in case they need updating for compiler changes.\n */\nexport type _RecursiveTrick = never;\n\n// This block is kept here to ensure the above example behaves as documented, and can be copied into the example to update it as needed.\n{\n\t/* eslint-disable @typescript-eslint/no-unused-vars */\n\n\t// @ts-expect-error The TypeScript compiler can't handle this case\n\ttype Broken<T> = FlattenKeys<\n\t\t{\n\t\t\t[K in keyof T]: 0;\n\t\t} & {\n\t\t\t// @ts-expect-error Same error as above.\n\t\t\t[K in keyof T]: Broken<T[K]>;\n\t\t}\n\t>;\n\n\t// Adding `K extends _RecursiveTrick ? _RecursiveTrick:` OR `T extends _RecursiveTrick ? _RecursiveTrick :` makes it compile and has no effect on the type produced.\n\ttype Works<T> = FlattenKeys<\n\t\t{\n\t\t\t[K in keyof T]: 0;\n\t\t} & {\n\t\t\t// Trick added here. Since `K` never extends `never`, the second conditional option is always taken,\n\t\t\t// making this equivalent to the broken version, except this one compiles.\n\t\t\t[K in keyof T]: T extends _RecursiveTrick ? _RecursiveTrick : Works<T[K]>;\n\t\t}\n\t>;\n\n\t/* eslint-enable @typescript-eslint/no-unused-vars */\n}\n\n/**\n * Alternative to the built in Record type which does not permit unexpected members,\n * and is readonly.\n *\n * @remarks\n * This does not work correctly when `K` is more specific than `string` or `symbol`.\n * For example `{a: 5}` is not assignable to `RestrictiveReadonlyRecord<\"a\",: number>`\n *\n * @privateRemarks\n * `number` is not allowed as a key here since doing so causes the compiler to reject recursive schema.\n * The cause for this is unclear, but empirically it was the case when this comment was written.\n *\n * @deprecated Use a more robust / specific type instead. This type never worked as intended.\n * @public\n */\nexport type RestrictiveReadonlyRecord<K extends symbol | string, T> = {\n\treadonly [P in symbol | string]: P extends K ? T : never;\n};\n\n/**\n * Alternative to the built-in `Record<string, T>` type which is readonly and does not permit symbols.\n * @remarks\n * It would be nice if `keyof RestrictiveStringRecord<T>` returned string, but it does not: use `keyof RestrictiveStringRecord<T> & string` instead.\n * @system @public\n */\nexport type RestrictiveStringRecord<T> = {\n\treadonly [P in string]: T;\n} & {\n\treadonly [P in symbol]?: never;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"typeUtils.js","sourceRoot":"","sources":["../../src/util/typeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA8EH,wIAAwI;AACxI,CAAC;IAwBA,qDAAqD;AACtD,CAAC;AA8FD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,kBAAkB,CAAI,KAAU;IAC/C,OAAO,KAAwB,CAAC;AACjC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Utilities for manipulating types.\n */\n\n/**\n * Return a type thats equivalent to the input, but with different IntelliSense.\n * This tends to convert unions and intersections into objects.\n * @system @public\n */\nexport type FlattenKeys<T> = [{ [Property in keyof T]: T[Property] }][_InlineTrick];\n\n/**\n * Use for trick to \"inline\" generic types.\n *\n * @remarks\n * The TypeScript compiler can be convinced to inline a generic type\n * (so the result of evaluating the generic type show up in IntelliSense and error messages instead of just the invocation of the generic type)\n * by creating an object with a field, and returning the type of that field.\n *\n * For example:\n * ```typescript\n * type MyGeneric<T1, T2> = {x: T1 extends [] ? T1 : T2 };\n * type MyGenericExpanded<T1, T2> = [{x: T1 extends [] ? T1 : T2 }][_InlineTrick]\n *\n * // Type is MyGeneric<5, string>\n * const foo: MyGeneric<5, string> = {x: \"x\"}\n * // Type is {x: \"x\"}\n * const foo2: MyGenericExpanded<5, string> = {x: \"x\"}\n * ```\n *\n * This constant is defined to provide a way to find this documentation from types which use this pattern,\n * and to locate types which use this pattern in case they need updating for compiler changes.\n * @system @public\n */\nexport type _InlineTrick = 0;\n\n/**\n * Use for trick to prevent self reference error `ts(2456)`.\n *\n * Prefix a type expression with `K extends _RecursiveTrick ? _RecursiveTrick : ` for some K to break the cycle.\n *\n * @remarks\n * The TypeScript compiler handles some cases of recursive types, but not others.\n * Sometimes adding an otherwise needless conditional can make a type compile.\n * Use this type in such cases.\n *\n *For example:\n * ```typescript\n * // The TypeScript compiler can't handle this case\n * type Broken<T> = FlattenKeys<\n *\t{\n * \t\t[K in keyof T]: 0;\n * \t} & {\n * \t\t[K in keyof T]: Broken<T[K]>;\n * \t}\n * >;\n *\n * // Adding `K extends _RecursiveTrick ? _RecursiveTrick :` makes it compile, and has no effect on the type produced.\n * type Works<T> = FlattenKeys<\n * \t{\n * \t\t[K in keyof T]: 0;\n * \t} & {\n * \t\t// Trick added here. Since `k` never extends `never`, the second conditional option is always taken,\n * \t\t// making this equivalent to the broken version, except this one compiles.\n * \t\t[K in keyof T]: K extends _RecursiveTrick ? _RecursiveTrick : Works<T[K]>;\n * \t}\n * >;\n * ```\n *\n * This trick appears to start working in TypeScript 4.1 and is confirmed to still work in 5.0.4.\n *\n * This constant is defined to provide a way to find this documentation from types which use this pattern,\n * and to locate types which use this pattern in case they need updating for compiler changes.\n */\nexport type _RecursiveTrick = never;\n\n// This block is kept here to ensure the above example behaves as documented, and can be copied into the example to update it as needed.\n{\n\t/* eslint-disable @typescript-eslint/no-unused-vars */\n\n\t// @ts-expect-error The TypeScript compiler can't handle this case\n\ttype Broken<T> = FlattenKeys<\n\t\t{\n\t\t\t[K in keyof T]: 0;\n\t\t} & {\n\t\t\t// @ts-expect-error Same error as above.\n\t\t\t[K in keyof T]: Broken<T[K]>;\n\t\t}\n\t>;\n\n\t// Adding `K extends _RecursiveTrick ? _RecursiveTrick:` OR `T extends _RecursiveTrick ? _RecursiveTrick :` makes it compile and has no effect on the type produced.\n\ttype Works<T> = FlattenKeys<\n\t\t{\n\t\t\t[K in keyof T]: 0;\n\t\t} & {\n\t\t\t// Trick added here. Since `K` never extends `never`, the second conditional option is always taken,\n\t\t\t// making this equivalent to the broken version, except this one compiles.\n\t\t\t[K in keyof T]: T extends _RecursiveTrick ? _RecursiveTrick : Works<T[K]>;\n\t\t}\n\t>;\n\n\t/* eslint-enable @typescript-eslint/no-unused-vars */\n}\n\n/**\n * Alternative to the built in Record type which does not permit unexpected members,\n * and is readonly.\n *\n * @remarks\n * This does not work correctly when `K` is more specific than `string` or `symbol`.\n * For example `{a: 5}` is not assignable to `RestrictiveReadonlyRecord<\"a\",: number>`\n *\n * @privateRemarks\n * `number` is not allowed as a key here since doing so causes the compiler to reject recursive schema.\n * The cause for this is unclear, but empirically it was the case when this comment was written.\n *\n * @deprecated Use a more robust / specific type instead. This type never worked as intended.\n * @public\n */\nexport type RestrictiveReadonlyRecord<K extends symbol | string, T> = {\n\treadonly [P in symbol | string]: P extends K ? T : never;\n};\n\n/**\n * Alternative to the built-in `Record<string, T>` type which is readonly and does not permit symbols.\n * @remarks\n * It would be nice if `keyof RestrictiveStringRecord<T>` returned string, but it does not: use `keyof RestrictiveStringRecord<T> & string` instead.\n * @system @public\n */\nexport type RestrictiveStringRecord<T> = {\n\treadonly [P in string]: T;\n} & {\n\treadonly [P in symbol]?: never;\n};\n\n/**\n * Returns `true` if T is a union and false if it is not.\n * @typeparam T - Type to test if it is a union.\n * @typeparam T2 - Do not specify: default value used as implementation detail.\n * @system @alpha\n */\nexport type IsUnion<T, T2 = T> = T extends unknown\n\t? [T2] extends [T]\n\t\t? false\n\t\t: true\n\t: \"error\";\n\n/**\n * Convert a union of types to an intersection of those types. Useful for `TransformEvents`.\n * @privateRemarks\n * First an always true extends clause is used (T extends T) to distribute T into to a union of types contravariant over each member of the T union.\n * Then the constraint on the type parameter in this new context is inferred, giving the intersection.\n * @system @public\n */\nexport type UnionToIntersection<T> = (T extends T ? (k: T) => unknown : never) extends (\n\tk: infer U,\n) => unknown\n\t? U\n\t: never;\n\n/**\n * Gets the first item of a union type.\n *\n * @typeparam Union - The union to convert.\n * @typeparam AsOverloadedFunction - Implementation detail: do not specify.\n * @system @alpha\n */\nexport type PopUnion<\n\tUnion,\n\tAsOverloadedFunction = UnionToIntersection<\n\t\tUnion extends unknown ? (f: Union) => void : never\n\t>,\n> = AsOverloadedFunction extends (a: infer First) => void ? First : never;\n\n/**\n * Converts a union type to a tuple type.\n *\n * @typeparam T - The union to convert.\n * @typeparam A - Implementation detail: do not specify.\n * @typeparam First - Implementation detail: do not specify.\n *\n * @privateRemarks\n * `A` is a tuple to prepend members of the union to.\n *\n * https://www.hacklewayne.com/typescript-convert-union-to-tuple-array-yes-but-how and https://catchts.com/union-array both explain the general approach this uses pretty well.\n * This implementation is inspired to those, but slightly different in implementation.\n * @alpha\n */\nexport type UnionToTuple<\n\tUnion,\n\tA extends unknown[] = [],\n\tFirst = PopUnion<Union>,\n> = IsUnion<Union> extends true\n\t? UnionToTuple<Exclude<Union, First>, [First, ...A]>\n\t: [Union, ...A];\n\n/**\n * This is unsafe, meaning that the returned value might not match its type.\n *\n * For the result to match its type, T must be a union of the types of each item in `items` in the order that they occur.\n * For this to be possible, there must be no duplicate or overlapping types.\n * This is fragile and must be used with care.\n *\n * @remarks\n * The main use-case for this is recovering lost information from {@link AllowedTypes} which is necessary to preserve when using them with {@link Input} APIs.\n * Since {@link AllowedTypes} is actually order independent, it is somewhat safer when used to produce `AllowedTypes`.\n *\n * @example\n * ```typescript\n * // Gives imprecise type (typeof A | typeof B)[]\n * const schemaBad = [A, B];\n * // Fixes the type to be [typeof A, typeof B]\n * const schema = unsafeArrayToTuple(schemaBad);\n *\n * const config = new TreeViewConfiguration({ schema });\n * ```\n * @alpha\n */\nexport function unsafeArrayToTuple<T>(items: T[]): UnionToTuple<T> {\n\treturn items as UnionToTuple<T>;\n}\n"]}
|
package/lib/util/utils.d.ts
CHANGED
|
@@ -114,12 +114,16 @@ export declare function find<T>(iterable: Iterable<T>, predicate: (t: T) => bool
|
|
|
114
114
|
export declare function count(iterable: Iterable<unknown>): number;
|
|
115
115
|
/**
|
|
116
116
|
* Use for Json compatible data.
|
|
117
|
+
*
|
|
118
|
+
* @typeparam TExtra - Type permitted in addition to the normal JSON types.
|
|
119
|
+
* Commonly used for to allow {@link @fluidframework/core-interfaces#IFluidHandle} within the otherwise JSON compatible content.
|
|
120
|
+
*
|
|
117
121
|
* @remarks
|
|
118
122
|
* This does not robustly forbid non json comparable data via type checking,
|
|
119
123
|
* but instead mostly restricts access to it.
|
|
120
124
|
* @alpha
|
|
121
125
|
*/
|
|
122
|
-
export type JsonCompatible = string | number | boolean | null | JsonCompatible[] | JsonCompatibleObject;
|
|
126
|
+
export type JsonCompatible<TExtra = never> = string | number | boolean | null | JsonCompatible<TExtra>[] | JsonCompatibleObject<TExtra> | TExtra;
|
|
123
127
|
/**
|
|
124
128
|
* Use for Json object compatible data.
|
|
125
129
|
* @remarks
|
|
@@ -127,8 +131,8 @@ export type JsonCompatible = string | number | boolean | null | JsonCompatible[]
|
|
|
127
131
|
* but instead mostly restricts access to it.
|
|
128
132
|
* @alpha
|
|
129
133
|
*/
|
|
130
|
-
export type JsonCompatibleObject = {
|
|
131
|
-
[P in string]?: JsonCompatible
|
|
134
|
+
export type JsonCompatibleObject<TExtra = never> = {
|
|
135
|
+
[P in string]?: JsonCompatible<TExtra>;
|
|
132
136
|
};
|
|
133
137
|
/**
|
|
134
138
|
* Use for readonly view of Json compatible data.
|
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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AM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAEnE"}
|
package/lib/util/utils.js
CHANGED
|
@@ -58,19 +58,29 @@ export function makeArray(size, filler) {
|
|
|
58
58
|
export function compareSets({ a, b, aExtra, bExtra, same, }) {
|
|
59
59
|
for (const item of a.keys()) {
|
|
60
60
|
if (!b.has(item)) {
|
|
61
|
-
if (aExtra
|
|
61
|
+
if (aExtra !== undefined) {
|
|
62
|
+
if (!aExtra(item)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
62
67
|
return false;
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
else {
|
|
66
|
-
if (same && !same(item)) {
|
|
71
|
+
if (same !== undefined && !same(item)) {
|
|
67
72
|
return false;
|
|
68
73
|
}
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
76
|
for (const item of b.keys()) {
|
|
72
77
|
if (!a.has(item)) {
|
|
73
|
-
if (bExtra
|
|
78
|
+
if (bExtra !== undefined) {
|
|
79
|
+
if (!bExtra(item)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
74
84
|
return false;
|
|
75
85
|
}
|
|
76
86
|
}
|
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,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IACD,OAAO,CAAC,CAAC;AACV,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkB,MAAM,CAAC,4BAA4B,CAAC,CAAC;AA4BjF;;GAEG;AACH,MAAM,UAAU,UAAU,CAAmB,CAAI;IAChD,8EAA8E;IAC9E,qEAAqE;IACrE,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;IAC7C,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC5B,qBAAqB;QACrB,OAAO,EAAmB,CAAC;IAC5B,CAAC;IAED,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAkB,CAAC;AACzF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAmB,CAAI,EAAE,CAAI;IAC1D,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,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 * 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 && !aExtra(item)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t} else {\n\t\t\tif (same && !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 && !bExtra(item)) {\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 * @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 =\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[]\n\t| JsonCompatibleObject;\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 = { [P in string]?: JsonCompatible };\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"]}
|
|
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,C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D,8EAA8E;IAC9E,qEAAqE;IACrE,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;IAC7C,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC5B,qBAAqB;QACrB,OAAO,EAAmB,CAAC;IAC5B,CAAC;IAED,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAkB,CAAC;AACzF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAmB,CAAI,EAAE,CAAI;IAC1D,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,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 * 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/tree",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Distributed tree",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -89,45 +89,45 @@
|
|
|
89
89
|
"temp-directory": "nyc/.nyc_output"
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"@fluid-internal/client-utils": "~2.
|
|
93
|
-
"@fluidframework/container-runtime": "~2.
|
|
94
|
-
"@fluidframework/core-interfaces": "~2.
|
|
95
|
-
"@fluidframework/core-utils": "~2.
|
|
96
|
-
"@fluidframework/datastore-definitions": "~2.
|
|
97
|
-
"@fluidframework/driver-definitions": "~2.
|
|
98
|
-
"@fluidframework/id-compressor": "~2.
|
|
99
|
-
"@fluidframework/runtime-definitions": "~2.
|
|
100
|
-
"@fluidframework/runtime-utils": "~2.
|
|
101
|
-
"@fluidframework/shared-object-base": "~2.
|
|
102
|
-
"@fluidframework/telemetry-utils": "~2.
|
|
92
|
+
"@fluid-internal/client-utils": "~2.5.0",
|
|
93
|
+
"@fluidframework/container-runtime": "~2.5.0",
|
|
94
|
+
"@fluidframework/core-interfaces": "~2.5.0",
|
|
95
|
+
"@fluidframework/core-utils": "~2.5.0",
|
|
96
|
+
"@fluidframework/datastore-definitions": "~2.5.0",
|
|
97
|
+
"@fluidframework/driver-definitions": "~2.5.0",
|
|
98
|
+
"@fluidframework/id-compressor": "~2.5.0",
|
|
99
|
+
"@fluidframework/runtime-definitions": "~2.5.0",
|
|
100
|
+
"@fluidframework/runtime-utils": "~2.5.0",
|
|
101
|
+
"@fluidframework/shared-object-base": "~2.5.0",
|
|
102
|
+
"@fluidframework/telemetry-utils": "~2.5.0",
|
|
103
103
|
"@sinclair/typebox": "^0.32.29",
|
|
104
104
|
"@tylerbu/sorted-btree-es6": "^1.8.0",
|
|
105
|
+
"@types/ungap__structured-clone": "^1.2.0",
|
|
105
106
|
"@ungap/structured-clone": "^1.2.0",
|
|
106
107
|
"uuid": "^9.0.0"
|
|
107
108
|
},
|
|
108
109
|
"devDependencies": {
|
|
109
110
|
"@arethetypeswrong/cli": "^0.16.4",
|
|
110
|
-
"@biomejs/biome": "~1.
|
|
111
|
-
"@fluid-internal/mocha-test-setup": "~2.
|
|
112
|
-
"@fluid-private/stochastic-test-utils": "~2.
|
|
113
|
-
"@fluid-private/test-dds-utils": "~2.
|
|
114
|
-
"@fluid-private/test-drivers": "~2.
|
|
111
|
+
"@biomejs/biome": "~1.9.3",
|
|
112
|
+
"@fluid-internal/mocha-test-setup": "~2.5.0",
|
|
113
|
+
"@fluid-private/stochastic-test-utils": "~2.5.0",
|
|
114
|
+
"@fluid-private/test-dds-utils": "~2.5.0",
|
|
115
|
+
"@fluid-private/test-drivers": "~2.5.0",
|
|
115
116
|
"@fluid-tools/benchmark": "^0.50.0",
|
|
116
|
-
"@fluid-tools/build-cli": "^0.
|
|
117
|
+
"@fluid-tools/build-cli": "^0.49.0",
|
|
117
118
|
"@fluidframework/build-common": "^2.0.3",
|
|
118
|
-
"@fluidframework/build-tools": "^0.
|
|
119
|
-
"@fluidframework/container-definitions": "~2.
|
|
120
|
-
"@fluidframework/container-loader": "~2.
|
|
119
|
+
"@fluidframework/build-tools": "^0.49.0",
|
|
120
|
+
"@fluidframework/container-definitions": "~2.5.0",
|
|
121
|
+
"@fluidframework/container-loader": "~2.5.0",
|
|
121
122
|
"@fluidframework/eslint-config-fluid": "^5.4.0",
|
|
122
|
-
"@fluidframework/test-runtime-utils": "~2.
|
|
123
|
-
"@fluidframework/test-utils": "~2.
|
|
124
|
-
"@fluidframework/tree-previous": "npm:@fluidframework/tree@~2.
|
|
123
|
+
"@fluidframework/test-runtime-utils": "~2.5.0",
|
|
124
|
+
"@fluidframework/test-utils": "~2.5.0",
|
|
125
|
+
"@fluidframework/tree-previous": "npm:@fluidframework/tree@~2.4.0",
|
|
125
126
|
"@microsoft/api-extractor": "7.47.8",
|
|
126
127
|
"@types/diff": "^3.5.1",
|
|
127
128
|
"@types/easy-table": "^0.0.32",
|
|
128
129
|
"@types/mocha": "^9.1.1",
|
|
129
130
|
"@types/node": "^18.19.0",
|
|
130
|
-
"@types/ungap__structured-clone": "^1.2.0",
|
|
131
131
|
"@types/uuid": "^9.0.2",
|
|
132
132
|
"ajv": "^8.12.0",
|
|
133
133
|
"ajv-formats": "^3.0.1",
|
|
@@ -164,23 +164,48 @@
|
|
|
164
164
|
},
|
|
165
165
|
"typeValidation": {
|
|
166
166
|
"broken": {
|
|
167
|
-
"
|
|
167
|
+
"TypeAlias_InsertableTreeFieldFromImplicitField": {
|
|
168
|
+
"backCompat": false,
|
|
169
|
+
"forwardCompat": false
|
|
170
|
+
},
|
|
171
|
+
"Interface_TreeArrayNode": {
|
|
172
|
+
"backCompat": false
|
|
173
|
+
},
|
|
174
|
+
"TypeAlias_InsertableTreeNodeFromImplicitAllowedTypes": {
|
|
175
|
+
"backCompat": false,
|
|
176
|
+
"forwardCompat": false
|
|
177
|
+
},
|
|
178
|
+
"TypeAlias_NodeFromSchema": {
|
|
179
|
+
"backCompat": false
|
|
180
|
+
},
|
|
181
|
+
"TypeAlias_TreeFieldFromImplicitField": {
|
|
168
182
|
"backCompat": false
|
|
169
183
|
},
|
|
170
|
-
"
|
|
184
|
+
"TypeAlias_TreeNodeFromImplicitAllowedTypes": {
|
|
171
185
|
"backCompat": false
|
|
172
186
|
},
|
|
173
|
-
"
|
|
187
|
+
"TypeAlias_InternalTypes_ApplyKind": {
|
|
188
|
+
"forwardCompat": false,
|
|
189
|
+
"backCompat": false
|
|
190
|
+
},
|
|
191
|
+
"TypeAlias_InternalTypes_InsertableObjectFromSchemaRecord": {
|
|
192
|
+
"forwardCompat": false,
|
|
193
|
+
"backCompat": false
|
|
194
|
+
},
|
|
195
|
+
"TypeAlias_InsertableTreeFieldFromImplicitFieldUnsafe": {
|
|
174
196
|
"forwardCompat": false
|
|
175
197
|
},
|
|
176
|
-
"
|
|
198
|
+
"TypeAlias_InternalTypes_InsertableTreeFieldFromImplicitFieldUnsafe": {
|
|
177
199
|
"forwardCompat": false
|
|
178
200
|
},
|
|
179
|
-
"
|
|
201
|
+
"Interface_ITreeViewConfiguration": {
|
|
180
202
|
"forwardCompat": false
|
|
181
203
|
},
|
|
182
204
|
"TypeAlias_ImplicitAllowedTypes": {
|
|
183
205
|
"forwardCompat": false
|
|
206
|
+
},
|
|
207
|
+
"TypeAlias_ImplicitFieldSchema": {
|
|
208
|
+
"forwardCompat": false
|
|
184
209
|
}
|
|
185
210
|
},
|
|
186
211
|
"entrypoint": "public"
|
package/src/codec/codec.ts
CHANGED
|
@@ -328,3 +328,28 @@ export function withSchemaValidation<
|
|
|
328
328
|
},
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Versions of Fluid Framework client packages.
|
|
334
|
+
* @remarks
|
|
335
|
+
* Used to express compatibility requirements by indicating the oldest version with which compatibility must be maintained.
|
|
336
|
+
* @privateRemarks
|
|
337
|
+
* This scheme assumes a single version will always be enough to communicate compatibility.
|
|
338
|
+
* For this to work, compatibility has to be strictly increasing.
|
|
339
|
+
* If this is violated (for example a subset of incompatible features from 3.x that are not in 3.0 are back ported to 2.x),
|
|
340
|
+
* a more complex scheme may be needed to allow safely opting into incompatible features in those cases:
|
|
341
|
+
* such a system can be added if/when its needed since it will be opt in and thus non-breaking.
|
|
342
|
+
*
|
|
343
|
+
* TODO: this should likely be defined higher in the stack and specified when creating the container, possibly as part of its schema.
|
|
344
|
+
* @alpha
|
|
345
|
+
*/
|
|
346
|
+
export enum FluidClientVersion {
|
|
347
|
+
/** Fluid Framework Client 2.0 and newer. */
|
|
348
|
+
v2_0 = "v2_0",
|
|
349
|
+
/** Fluid Framework Client 2.1 and newer. */
|
|
350
|
+
v2_1 = "v2_1",
|
|
351
|
+
/** Fluid Framework Client 2.2 and newer. */
|
|
352
|
+
v2_2 = "v2_2",
|
|
353
|
+
/** Fluid Framework Client 2.4 and newer. */
|
|
354
|
+
v2_3 = "v2_3",
|
|
355
|
+
}
|
package/src/codec/index.ts
CHANGED
package/src/core/rebase/index.ts
CHANGED
|
@@ -24,7 +24,6 @@ export {
|
|
|
24
24
|
taggedOptAtomId,
|
|
25
25
|
offsetChangeAtomId,
|
|
26
26
|
replaceAtomRevisions,
|
|
27
|
-
replaceChange,
|
|
28
27
|
} from "./types.js";
|
|
29
28
|
export { RevisionTagCodec } from "./revisionTagCodec.js";
|
|
30
29
|
export {
|
|
@@ -49,4 +48,5 @@ export {
|
|
|
49
48
|
revisionMetadataSourceFromInfo,
|
|
50
49
|
type RebaseStats,
|
|
51
50
|
type RebaseStatsWithDuration,
|
|
51
|
+
replaceChange,
|
|
52
52
|
} from "./utils.js";
|
package/src/core/rebase/types.ts
CHANGED
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
brandedNumberType,
|
|
19
19
|
brandedStringType,
|
|
20
20
|
} from "../../util/index.js";
|
|
21
|
-
import type { TaggedChange } from "./changeRebaser.js";
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* The identifier for a particular session/user/client that can generate `GraphCommit`s
|
|
@@ -154,8 +153,6 @@ export interface GraphCommit<TChange> {
|
|
|
154
153
|
readonly change: TChange;
|
|
155
154
|
/** The parent of this commit, on whose change this commit's change is based */
|
|
156
155
|
readonly parent?: GraphCommit<TChange>;
|
|
157
|
-
/** The rollback of this commit */
|
|
158
|
-
rollback?: TaggedChange<TChange, RevisionTag>;
|
|
159
156
|
}
|
|
160
157
|
|
|
161
158
|
/**
|
|
@@ -207,12 +204,3 @@ export function mintCommit<TChange>(
|
|
|
207
204
|
parent,
|
|
208
205
|
};
|
|
209
206
|
}
|
|
210
|
-
|
|
211
|
-
export function replaceChange<TChange>(
|
|
212
|
-
commit: GraphCommit<TChange>,
|
|
213
|
-
change: TChange,
|
|
214
|
-
): GraphCommit<TChange> {
|
|
215
|
-
const output = { ...commit, change };
|
|
216
|
-
delete output.rollback;
|
|
217
|
-
return output;
|
|
218
|
-
}
|
package/src/core/rebase/utils.ts
CHANGED
|
@@ -441,8 +441,9 @@ function rollbackFromCommit<TChange>(
|
|
|
441
441
|
mintRevisionTag: () => RevisionTag,
|
|
442
442
|
cache?: boolean,
|
|
443
443
|
): TaggedChange<TChange, RevisionTag> {
|
|
444
|
-
|
|
445
|
-
|
|
444
|
+
const rollback = Rollback.get(commit);
|
|
445
|
+
if (rollback !== undefined) {
|
|
446
|
+
return rollback;
|
|
446
447
|
}
|
|
447
448
|
const tag = mintRevisionTag();
|
|
448
449
|
const untagged = changeRebaser.invert(commit, true, tag);
|
|
@@ -450,7 +451,7 @@ function rollbackFromCommit<TChange>(
|
|
|
450
451
|
const fullyTaggedRollback = tagRollbackInverse(deeplyTaggedRollback, tag, commit.revision);
|
|
451
452
|
|
|
452
453
|
if (cache === true) {
|
|
453
|
-
commit
|
|
454
|
+
Rollback.set(commit, fullyTaggedRollback);
|
|
454
455
|
}
|
|
455
456
|
return fullyTaggedRollback;
|
|
456
457
|
}
|
|
@@ -620,3 +621,34 @@ export function findCommonAncestor<T extends { parent?: T }>(
|
|
|
620
621
|
}
|
|
621
622
|
return undefined;
|
|
622
623
|
}
|
|
624
|
+
|
|
625
|
+
export function replaceChange<TChange>(
|
|
626
|
+
commit: GraphCommit<TChange>,
|
|
627
|
+
change: TChange,
|
|
628
|
+
): GraphCommit<TChange> {
|
|
629
|
+
const output = { ...commit, change };
|
|
630
|
+
Rollback.set(output, undefined);
|
|
631
|
+
return output;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/** Associates rollback data with commits */
|
|
635
|
+
namespace Rollback {
|
|
636
|
+
const map = new WeakMap<GraphCommit<unknown>, TaggedChange<unknown, RevisionTag>>();
|
|
637
|
+
|
|
638
|
+
export function get<TChange>(
|
|
639
|
+
commit: GraphCommit<TChange>,
|
|
640
|
+
): TaggedChange<TChange, RevisionTag> | undefined {
|
|
641
|
+
return map.get(commit) as TaggedChange<TChange, RevisionTag> | undefined;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export function set<TChange>(
|
|
645
|
+
commit: GraphCommit<TChange>,
|
|
646
|
+
rollback: TaggedChange<TChange, RevisionTag> | undefined,
|
|
647
|
+
): void {
|
|
648
|
+
if (rollback === undefined) {
|
|
649
|
+
map.delete(commit);
|
|
650
|
+
} else {
|
|
651
|
+
map.set(commit, rollback);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|