@fluidframework/tree 2.1.0-276985 → 2.1.0-281041
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/.eslintrc.cjs +7 -0
- package/.vscode/Tree.code-workspace +7 -1
- package/README.md +51 -8
- package/api-report/tree.alpha.api.md +1 -0
- package/api-report/tree.beta.api.md +1 -0
- package/api-report/tree.public.api.md +1 -0
- package/beta.d.ts +1 -1
- package/dist/beta.d.ts +1 -1
- package/dist/core/forest/editableForest.d.ts +6 -3
- package/dist/core/forest/editableForest.d.ts.map +1 -1
- package/dist/core/forest/editableForest.js +14 -4
- package/dist/core/forest/editableForest.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/rebase/index.d.ts +1 -1
- package/dist/core/rebase/index.d.ts.map +1 -1
- package/dist/core/rebase/index.js +3 -1
- package/dist/core/rebase/index.js.map +1 -1
- package/dist/core/rebase/types.d.ts +2 -0
- package/dist/core/rebase/types.d.ts.map +1 -1
- package/dist/core/rebase/types.js +9 -1
- package/dist/core/rebase/types.js.map +1 -1
- package/dist/core/tree/visitDelta.d.ts.map +1 -1
- package/dist/core/tree/visitDelta.js.map +1 -1
- package/dist/events/events.d.ts +4 -1
- package/dist/events/events.d.ts.map +1 -1
- package/dist/events/events.js.map +1 -1
- package/dist/feature-libraries/default-schema/defaultEditBuilder.js +1 -1
- package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
- package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/defaultFieldKinds.js +1 -0
- package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
- package/dist/feature-libraries/flex-map-tree/mapTreeNode.d.ts +0 -2
- package/dist/feature-libraries/flex-map-tree/mapTreeNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-map-tree/mapTreeNode.js +0 -20
- package/dist/feature-libraries/flex-map-tree/mapTreeNode.js.map +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +0 -38
- 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/index.d.ts +1 -1
- package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/index.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.d.ts +0 -4
- package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.js +1 -14
- package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts +0 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.js +0 -3
- package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +3 -3
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +2 -2
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts +11 -0
- package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
- package/dist/feature-libraries/modular-schema/discrepancies.d.ts +96 -0
- package/dist/feature-libraries/modular-schema/discrepancies.d.ts.map +1 -0
- package/dist/feature-libraries/modular-schema/discrepancies.js +264 -0
- package/dist/feature-libraries/modular-schema/discrepancies.js.map +1 -0
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +9 -2
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.js +3 -0
- package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
- package/dist/feature-libraries/modular-schema/index.d.ts +2 -1
- package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/index.js +3 -1
- package/dist/feature-libraries/modular-schema/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +42 -26
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +51 -2
- package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js +830 -245
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFormat.js +2 -0
- package/dist/feature-libraries/modular-schema/modularChangeFormat.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +44 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
- package/dist/feature-libraries/node-key/index.d.ts +0 -1
- package/dist/feature-libraries/node-key/index.d.ts.map +1 -1
- package/dist/feature-libraries/node-key/index.js +1 -3
- package/dist/feature-libraries/node-key/index.js.map +1 -1
- package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
- package/dist/feature-libraries/optional-field/optionalField.js +1 -0
- package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
- package/dist/feature-libraries/sequence-field/index.d.ts +1 -1
- package/dist/feature-libraries/sequence-field/index.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/index.js +1 -2
- package/dist/feature-libraries/sequence-field/index.js.map +1 -1
- package/dist/feature-libraries/sequence-field/invert.js +1 -1
- package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
- package/dist/feature-libraries/sequence-field/rebase.js +6 -1
- package/dist/feature-libraries/sequence-field/rebase.js.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldChangeHandler.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldChangeHandler.js +1 -0
- package/dist/feature-libraries/sequence-field/sequenceFieldChangeHandler.js.map +1 -1
- package/dist/feature-libraries/sequence-field/utils.d.ts +2 -17
- package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/utils.js +31 -39
- package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
- package/dist/feature-libraries/typed-schema/typedTreeSchema.d.ts +1 -0
- package/dist/feature-libraries/typed-schema/typedTreeSchema.d.ts.map +1 -1
- package/dist/feature-libraries/typed-schema/typedTreeSchema.js +2 -0
- package/dist/feature-libraries/typed-schema/typedTreeSchema.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts +4 -2
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +240 -184
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +150 -90
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +2 -1
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/branch.d.ts.map +1 -1
- package/dist/shared-tree-core/branch.js +1 -0
- package/dist/shared-tree-core/branch.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts +4 -6
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +265 -209
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/arrayNode.d.ts +4 -0
- package/dist/simple-tree/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/arrayNode.js +36 -19
- package/dist/simple-tree/arrayNode.js.map +1 -1
- package/dist/simple-tree/leafNodeSchema.d.ts +22 -1
- package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/leafNodeSchema.js +2 -1
- package/dist/simple-tree/leafNodeSchema.js.map +1 -1
- package/dist/simple-tree/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/mapNode.js.map +1 -1
- package/dist/simple-tree/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/objectNode.js +2 -1
- package/dist/simple-tree/objectNode.js.map +1 -1
- package/dist/simple-tree/proxies.d.ts.map +1 -1
- package/dist/simple-tree/proxies.js +2 -4
- package/dist/simple-tree/proxies.js.map +1 -1
- package/dist/simple-tree/schemaFactory.d.ts +16 -1
- package/dist/simple-tree/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/schemaFactory.js +32 -4
- package/dist/simple-tree/schemaFactory.js.map +1 -1
- package/dist/simple-tree/schemaTypes.d.ts +36 -1
- package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
- package/dist/simple-tree/schemaTypes.js.map +1 -1
- package/dist/simple-tree/toFlexSchema.d.ts +2 -2
- package/dist/simple-tree/toFlexSchema.d.ts.map +1 -1
- package/dist/simple-tree/toFlexSchema.js +3 -2
- package/dist/simple-tree/toFlexSchema.js.map +1 -1
- package/dist/simple-tree/tree.d.ts +4 -1
- package/dist/simple-tree/tree.d.ts.map +1 -1
- package/dist/simple-tree/tree.js +48 -1
- package/dist/simple-tree/tree.js.map +1 -1
- package/dist/simple-tree/treeNodeApi.d.ts.map +1 -1
- package/dist/simple-tree/treeNodeApi.js +10 -10
- package/dist/simple-tree/treeNodeApi.js.map +1 -1
- package/dist/simple-tree/types.d.ts +22 -3
- package/dist/simple-tree/types.d.ts.map +1 -1
- package/dist/simple-tree/types.js +32 -21
- package/dist/simple-tree/types.js.map +1 -1
- package/dist/util/breakable.d.ts +83 -0
- package/dist/util/breakable.d.ts.map +1 -0
- package/dist/util/breakable.js +178 -0
- package/dist/util/breakable.js.map +1 -0
- package/dist/util/index.d.ts +3 -2
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +9 -2
- package/dist/util/index.js.map +1 -1
- package/dist/util/nestedMap.d.ts +17 -3
- package/dist/util/nestedMap.d.ts.map +1 -1
- package/dist/util/nestedMap.js +21 -1
- package/dist/util/nestedMap.js.map +1 -1
- package/dist/util/utils.d.ts +7 -0
- package/dist/util/utils.d.ts.map +1 -1
- package/dist/util/utils.js +15 -1
- package/dist/util/utils.js.map +1 -1
- package/internal.d.ts +1 -1
- package/lib/beta.d.ts +1 -1
- package/lib/core/forest/editableForest.d.ts +6 -3
- package/lib/core/forest/editableForest.d.ts.map +1 -1
- package/lib/core/forest/editableForest.js +15 -5
- package/lib/core/forest/editableForest.js.map +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.d.ts.map +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/rebase/index.d.ts +1 -1
- package/lib/core/rebase/index.d.ts.map +1 -1
- package/lib/core/rebase/index.js +1 -1
- package/lib/core/rebase/index.js.map +1 -1
- package/lib/core/rebase/types.d.ts +2 -0
- package/lib/core/rebase/types.d.ts.map +1 -1
- package/lib/core/rebase/types.js +7 -1
- package/lib/core/rebase/types.js.map +1 -1
- package/lib/core/tree/visitDelta.d.ts.map +1 -1
- package/lib/core/tree/visitDelta.js.map +1 -1
- package/lib/events/events.d.ts +4 -1
- package/lib/events/events.d.ts.map +1 -1
- package/lib/events/events.js.map +1 -1
- package/lib/feature-libraries/default-schema/defaultEditBuilder.js +1 -1
- package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
- package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/defaultFieldKinds.js +1 -0
- package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
- package/lib/feature-libraries/flex-map-tree/mapTreeNode.d.ts +0 -2
- package/lib/feature-libraries/flex-map-tree/mapTreeNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-map-tree/mapTreeNode.js +0 -20
- package/lib/feature-libraries/flex-map-tree/mapTreeNode.js.map +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +0 -38
- 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/index.d.ts +1 -1
- package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/index.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.d.ts +0 -4
- package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.js +1 -14
- package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts +0 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.js +0 -3
- package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +3 -3
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +2 -2
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts +11 -0
- package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
- package/lib/feature-libraries/modular-schema/discrepancies.d.ts +96 -0
- package/lib/feature-libraries/modular-schema/discrepancies.d.ts.map +1 -0
- package/lib/feature-libraries/modular-schema/discrepancies.js +260 -0
- package/lib/feature-libraries/modular-schema/discrepancies.js.map +1 -0
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +9 -2
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.js +3 -0
- package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
- package/lib/feature-libraries/modular-schema/index.d.ts +2 -1
- package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/index.js +1 -0
- package/lib/feature-libraries/modular-schema/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +42 -26
- package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +51 -2
- package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js +829 -247
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFormat.js +2 -0
- package/lib/feature-libraries/modular-schema/modularChangeFormat.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +44 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
- package/lib/feature-libraries/node-key/index.d.ts +0 -1
- package/lib/feature-libraries/node-key/index.d.ts.map +1 -1
- package/lib/feature-libraries/node-key/index.js +0 -1
- package/lib/feature-libraries/node-key/index.js.map +1 -1
- package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
- package/lib/feature-libraries/optional-field/optionalField.js +1 -0
- package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
- package/lib/feature-libraries/sequence-field/index.d.ts +1 -1
- package/lib/feature-libraries/sequence-field/index.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/index.js +1 -1
- package/lib/feature-libraries/sequence-field/index.js.map +1 -1
- package/lib/feature-libraries/sequence-field/invert.js +1 -1
- package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
- package/lib/feature-libraries/sequence-field/rebase.js +6 -1
- package/lib/feature-libraries/sequence-field/rebase.js.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldChangeHandler.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldChangeHandler.js +2 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldChangeHandler.js.map +1 -1
- package/lib/feature-libraries/sequence-field/utils.d.ts +2 -17
- package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/utils.js +31 -39
- package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
- package/lib/feature-libraries/typed-schema/typedTreeSchema.d.ts +1 -0
- package/lib/feature-libraries/typed-schema/typedTreeSchema.d.ts.map +1 -1
- package/lib/feature-libraries/typed-schema/typedTreeSchema.js +4 -2
- package/lib/feature-libraries/typed-schema/typedTreeSchema.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts +4 -2
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +242 -185
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +151 -90
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +2 -1
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/branch.d.ts.map +1 -1
- package/lib/shared-tree-core/branch.js +1 -0
- package/lib/shared-tree-core/branch.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts +4 -6
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +267 -210
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/arrayNode.d.ts +4 -0
- package/lib/simple-tree/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/arrayNode.js +38 -21
- package/lib/simple-tree/arrayNode.js.map +1 -1
- package/lib/simple-tree/leafNodeSchema.d.ts +22 -1
- package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/leafNodeSchema.js +1 -1
- package/lib/simple-tree/leafNodeSchema.js.map +1 -1
- package/lib/simple-tree/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/mapNode.js.map +1 -1
- package/lib/simple-tree/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/objectNode.js +3 -2
- package/lib/simple-tree/objectNode.js.map +1 -1
- package/lib/simple-tree/proxies.d.ts.map +1 -1
- package/lib/simple-tree/proxies.js +2 -4
- package/lib/simple-tree/proxies.js.map +1 -1
- package/lib/simple-tree/schemaFactory.d.ts +16 -1
- package/lib/simple-tree/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/schemaFactory.js +30 -3
- package/lib/simple-tree/schemaFactory.js.map +1 -1
- package/lib/simple-tree/schemaTypes.d.ts +36 -1
- package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
- package/lib/simple-tree/schemaTypes.js.map +1 -1
- package/lib/simple-tree/toFlexSchema.d.ts +2 -2
- package/lib/simple-tree/toFlexSchema.d.ts.map +1 -1
- package/lib/simple-tree/toFlexSchema.js +3 -2
- package/lib/simple-tree/toFlexSchema.js.map +1 -1
- package/lib/simple-tree/tree.d.ts +4 -1
- package/lib/simple-tree/tree.d.ts.map +1 -1
- package/lib/simple-tree/tree.js +44 -0
- package/lib/simple-tree/tree.js.map +1 -1
- package/lib/simple-tree/treeNodeApi.d.ts.map +1 -1
- package/lib/simple-tree/treeNodeApi.js +11 -11
- package/lib/simple-tree/treeNodeApi.js.map +1 -1
- package/lib/simple-tree/types.d.ts +22 -3
- package/lib/simple-tree/types.d.ts.map +1 -1
- package/lib/simple-tree/types.js +32 -21
- package/lib/simple-tree/types.js.map +1 -1
- package/lib/util/breakable.d.ts +83 -0
- package/lib/util/breakable.d.ts.map +1 -0
- package/lib/util/breakable.js +171 -0
- package/lib/util/breakable.js.map +1 -0
- package/lib/util/index.d.ts +3 -2
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +3 -2
- package/lib/util/index.js.map +1 -1
- package/lib/util/nestedMap.d.ts +17 -3
- package/lib/util/nestedMap.d.ts.map +1 -1
- package/lib/util/nestedMap.js +19 -0
- package/lib/util/nestedMap.js.map +1 -1
- package/lib/util/utils.d.ts +7 -0
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js +13 -0
- package/lib/util/utils.js.map +1 -1
- package/package.json +29 -27
- package/src/core/forest/editableForest.ts +17 -4
- package/src/core/index.ts +2 -0
- package/src/core/rebase/index.ts +2 -0
- package/src/core/rebase/types.ts +17 -0
- package/src/core/tree/visitDelta.ts +1 -0
- package/src/events/events.ts +4 -2
- package/src/feature-libraries/default-schema/defaultEditBuilder.ts +1 -1
- package/src/feature-libraries/default-schema/defaultFieldKinds.ts +1 -0
- package/src/feature-libraries/flex-map-tree/mapTreeNode.ts +0 -30
- package/src/feature-libraries/flex-tree/flexTreeTypes.ts +0 -43
- package/src/feature-libraries/flex-tree/index.ts +0 -1
- package/src/feature-libraries/flex-tree/lazyField.ts +1 -21
- package/src/feature-libraries/flex-tree/lazyNode.ts +0 -6
- package/src/feature-libraries/index.ts +1 -2
- package/src/feature-libraries/modular-schema/crossFieldQueries.ts +18 -0
- package/src/feature-libraries/modular-schema/discrepancies.ts +395 -0
- package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +10 -2
- package/src/feature-libraries/modular-schema/genericFieldKind.ts +3 -0
- package/src/feature-libraries/modular-schema/index.ts +2 -0
- package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +81 -35
- package/src/feature-libraries/modular-schema/modularChangeFamily.ts +1529 -454
- package/src/feature-libraries/modular-schema/modularChangeFormat.ts +2 -0
- package/src/feature-libraries/modular-schema/modularChangeTypes.ts +51 -0
- package/src/feature-libraries/node-key/index.ts +0 -1
- package/src/feature-libraries/optional-field/optionalField.ts +1 -0
- package/src/feature-libraries/sequence-field/index.ts +0 -2
- package/src/feature-libraries/sequence-field/invert.ts +1 -1
- package/src/feature-libraries/sequence-field/rebase.ts +7 -1
- package/src/feature-libraries/sequence-field/sequenceFieldChangeHandler.ts +2 -1
- package/src/feature-libraries/sequence-field/utils.ts +37 -85
- package/src/feature-libraries/typed-schema/typedTreeSchema.ts +10 -0
- package/src/index.ts +0 -1
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/schematizingTreeView.ts +6 -2
- package/src/shared-tree/sharedTree.ts +4 -0
- package/src/shared-tree/treeCheckout.ts +6 -2
- package/src/shared-tree-core/branch.ts +1 -0
- package/src/shared-tree-core/sharedTreeCore.ts +18 -6
- package/src/simple-tree/arrayNode.ts +49 -22
- package/src/simple-tree/leafNodeSchema.ts +1 -1
- package/src/simple-tree/mapNode.ts +2 -2
- package/src/simple-tree/objectNode.ts +9 -3
- package/src/simple-tree/proxies.ts +2 -4
- package/src/simple-tree/schemaFactory.ts +37 -2
- package/src/simple-tree/schemaTypes.ts +36 -1
- package/src/simple-tree/toFlexSchema.ts +5 -4
- package/src/simple-tree/tree.ts +65 -4
- package/src/simple-tree/treeNodeApi.ts +15 -15
- package/src/simple-tree/types.ts +60 -30
- package/src/util/breakable.ts +214 -0
- package/src/util/index.ts +10 -0
- package/src/util/nestedMap.ts +33 -3
- package/src/util/utils.ts +17 -0
- package/dist/feature-libraries/node-key/nodeKeyIndex.d.ts +0 -41
- package/dist/feature-libraries/node-key/nodeKeyIndex.d.ts.map +0 -1
- package/dist/feature-libraries/node-key/nodeKeyIndex.js +0 -101
- package/dist/feature-libraries/node-key/nodeKeyIndex.js.map +0 -1
- package/lib/feature-libraries/node-key/nodeKeyIndex.d.ts +0 -41
- package/lib/feature-libraries/node-key/nodeKeyIndex.d.ts.map +0 -1
- package/lib/feature-libraries/node-key/nodeKeyIndex.js +0 -97
- package/lib/feature-libraries/node-key/nodeKeyIndex.js.map +0 -1
- package/src/feature-libraries/node-key/nodeKeyIndex.ts +0 -132
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { assert } from "@fluidframework/core-utils/internal";
|
|
7
|
+
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An object which can enter a "broken" state where trying to use it is a UsageError.
|
|
11
|
+
*/
|
|
12
|
+
export class Breakable {
|
|
13
|
+
private brokenBy?: Error;
|
|
14
|
+
|
|
15
|
+
public constructor(private readonly name: string) {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Throws if the object is in the broken state.
|
|
19
|
+
* @remarks
|
|
20
|
+
* Can use {@link throwIfBroken} to apply this to a method.
|
|
21
|
+
*/
|
|
22
|
+
public use(): void {
|
|
23
|
+
if (this.brokenBy !== undefined) {
|
|
24
|
+
throw new UsageError(
|
|
25
|
+
`Invalid use of ${this.name} after it was put into an invalid state by another error.\nOriginal Error:\n${this.brokenBy}`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Puts this object into the broken state, and throws an error.
|
|
32
|
+
*
|
|
33
|
+
* @throws If already broken by a different error, throws a UsageError, otherwise throws `brokenBy`.
|
|
34
|
+
*/
|
|
35
|
+
public break(brokenBy: Error): never {
|
|
36
|
+
// If already broken by this error, let it bubble up without rethrowing a modified version.
|
|
37
|
+
// This prevents internal errors like asserts getting rethrown as different errors when wrapped with multiple call to `{@link Breakable.run}` or `{@link breakingMethod}`.
|
|
38
|
+
if (this.brokenBy !== brokenBy) {
|
|
39
|
+
this.use();
|
|
40
|
+
this.brokenBy = brokenBy;
|
|
41
|
+
}
|
|
42
|
+
throw brokenBy;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* {@link Breakable.break}, except tolerates `unknown` to be more easily used by catch blocks.
|
|
47
|
+
* @privateRemarks
|
|
48
|
+
* If there is a use-case, this should be made public.
|
|
49
|
+
*/
|
|
50
|
+
private rethrowCaught(brokenBy: unknown): never {
|
|
51
|
+
if (brokenBy instanceof Error) {
|
|
52
|
+
this.break(brokenBy);
|
|
53
|
+
}
|
|
54
|
+
this.break(
|
|
55
|
+
new Error(`Non-error thrown breaking ${this.name}. Thrown value: "${brokenBy}"`),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Runs code which should break the object if it throws.
|
|
61
|
+
* @remarks
|
|
62
|
+
* This also throws if already broken like {@link Breakable.use}.
|
|
63
|
+
* Any exceptions this catches are re-thrown.
|
|
64
|
+
* Can use {@link breakingMethod} to apply this to a method.
|
|
65
|
+
*/
|
|
66
|
+
public run<TResult>(breaker: () => TResult): TResult {
|
|
67
|
+
this.use();
|
|
68
|
+
try {
|
|
69
|
+
return breaker();
|
|
70
|
+
} catch (error: unknown) {
|
|
71
|
+
this.rethrowCaught(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Clears the existing broken state.
|
|
77
|
+
* @remarks
|
|
78
|
+
* This is rarely safe to to: it is only ok when all objects using this breaker are known to not have been left in an invalid state.
|
|
79
|
+
* This is pretty much only safe in tests which just were checking a specific error was thrown, and which know that error closepath is actually exception safe.
|
|
80
|
+
*/
|
|
81
|
+
public clearError(): void {
|
|
82
|
+
assert(this.brokenBy !== undefined, "No error to clear");
|
|
83
|
+
this.brokenBy = undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Marks an object as being able to be in a broken state (unknown/unspecified/broken state due to unhandled exception).
|
|
89
|
+
* @remarks
|
|
90
|
+
* See decorators {@link breakingMethod} and {@link throwIfBroken} for ease of use.
|
|
91
|
+
*/
|
|
92
|
+
export interface WithBreakable {
|
|
93
|
+
readonly breaker: Breakable;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Decorator for methods which should break the object when they throw.
|
|
98
|
+
* @remarks
|
|
99
|
+
* This also throws if already broken like {@link throwIfBroken}.
|
|
100
|
+
* See {@link Breakable.run} for details.
|
|
101
|
+
*
|
|
102
|
+
* This should be used on methods which modify data that could result in an unsupported/broken state if an exception is thrown while modifying.
|
|
103
|
+
* It is ok for breakingMethods to call each-other.
|
|
104
|
+
* @privateRemarks
|
|
105
|
+
* Explicitly capturing the full `Target` type is necessary to make this work with generic methods with unknown numbers of type parameters.
|
|
106
|
+
*/
|
|
107
|
+
export function breakingMethod<
|
|
108
|
+
Target extends ((...args: any[]) => unknown) & ((this: This, ...args: Args) => Return),
|
|
109
|
+
This extends WithBreakable,
|
|
110
|
+
Args extends never[],
|
|
111
|
+
Return,
|
|
112
|
+
>(target: Target, context?: ClassMethodDecoratorContext<This, Target>): Target {
|
|
113
|
+
function replacementMethod(this: This, ...args: Args): Return {
|
|
114
|
+
if (this.breaker === undefined) {
|
|
115
|
+
// This case is necessary for when wrapping methods which are invoked inside the constructor of the base class before `breaker` is set.
|
|
116
|
+
// Since the constructor throwing does not return an object, failing to put it into a broken state is not too bad.
|
|
117
|
+
// However when more than just the constructed object should be broken, this can result in missing a break.
|
|
118
|
+
return target.call(this, ...args);
|
|
119
|
+
}
|
|
120
|
+
return this.breaker.run(() => {
|
|
121
|
+
return target.call(this, ...args);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
markBreaker(replacementMethod);
|
|
125
|
+
nameFunctionFrom(replacementMethod, target);
|
|
126
|
+
return replacementMethod as Target;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Decorator for methods which should throw if the object is in a broken state.
|
|
131
|
+
* @remarks
|
|
132
|
+
* This should be used on methods which read data that could be invalid when the object is broken.
|
|
133
|
+
* @privateRemarks
|
|
134
|
+
* Explicitly capturing the full `Target` type is necessary to make this work with generic methods with unknown numbers of type parameters.
|
|
135
|
+
*/
|
|
136
|
+
export function throwIfBroken<
|
|
137
|
+
Target extends ((...args: any[]) => unknown) & ((this: This, ...args: Args) => Return),
|
|
138
|
+
This extends WithBreakable,
|
|
139
|
+
Args extends never[],
|
|
140
|
+
Return,
|
|
141
|
+
>(target: Target, context: ClassMethodDecoratorContext<This, Target>): Target {
|
|
142
|
+
function replacementMethod(this: This, ...args: Args): Return {
|
|
143
|
+
this.breaker.use();
|
|
144
|
+
return target.call(this, ...args);
|
|
145
|
+
}
|
|
146
|
+
markBreaker(replacementMethod);
|
|
147
|
+
nameFunctionFrom(replacementMethod, target);
|
|
148
|
+
return replacementMethod as Target;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
152
|
+
type PossiblyNamedFunction = Function & { displayName?: undefined | string };
|
|
153
|
+
|
|
154
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
155
|
+
function nameFunctionFrom(toName: Function, nameFrom: Function): void {
|
|
156
|
+
(toName as PossiblyNamedFunction).displayName =
|
|
157
|
+
(nameFrom as PossiblyNamedFunction).displayName ?? nameFrom.name;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const isBreakerSymbol: unique symbol = Symbol("isBreaker");
|
|
161
|
+
|
|
162
|
+
// Accepting any function like value is desired and safe here as this does not call the provided function.
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
164
|
+
function markBreaker(f: Function): void {
|
|
165
|
+
(f as unknown as Record<typeof isBreakerSymbol, true>)[isBreakerSymbol] = true;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Accepting any function like value is desired and safe here as this does not call the provided function.
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
170
|
+
function isBreaker(f: Function): boolean {
|
|
171
|
+
return isBreakerSymbol in (f as unknown as Record<typeof isBreakerSymbol, true>);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Decorator for classes which should break when their methods throw.
|
|
176
|
+
* @remarks
|
|
177
|
+
* Applies {@link breakingMethod} to all methods declared directly by class or its base classes.
|
|
178
|
+
* Does not include those on derived classes.
|
|
179
|
+
* Does not include getters or setters, or value properties.
|
|
180
|
+
* Methods already marked as {@link breakingMethod} or {@link throwIfBroken} are unaffected.
|
|
181
|
+
*/
|
|
182
|
+
export function breakingClass<Target extends abstract new (...args: any[]) => WithBreakable>(
|
|
183
|
+
target: Target,
|
|
184
|
+
context: ClassDecoratorContext<Target>,
|
|
185
|
+
): Target {
|
|
186
|
+
abstract class DecoratedBreakable extends target {}
|
|
187
|
+
|
|
188
|
+
// Keep track of what keys we have seen,
|
|
189
|
+
// since we visit most derived properties first and need to avoid wrapping base properties overriding more derived ones.
|
|
190
|
+
const overriddenKeys: Set<string | symbol> = new Set();
|
|
191
|
+
|
|
192
|
+
let prototype: object | null = target.prototype;
|
|
193
|
+
while (prototype !== null) {
|
|
194
|
+
for (const key of Reflect.ownKeys(prototype)) {
|
|
195
|
+
if (!overriddenKeys.has(key)) {
|
|
196
|
+
overriddenKeys.add(key);
|
|
197
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(prototype, key);
|
|
198
|
+
if (descriptor !== undefined) {
|
|
199
|
+
// Method
|
|
200
|
+
if (typeof descriptor.value === "function") {
|
|
201
|
+
if (!isBreaker(descriptor.value)) {
|
|
202
|
+
// This does not affect the original class, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor
|
|
203
|
+
descriptor.value = breakingMethod(descriptor.value);
|
|
204
|
+
Object.defineProperty(DecoratedBreakable.prototype, key, descriptor);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
prototype = Reflect.getPrototypeOf(prototype);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return DecoratedBreakable;
|
|
214
|
+
}
|
package/src/util/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ export {
|
|
|
29
29
|
setInNestedMap,
|
|
30
30
|
tryAddToNestedMap,
|
|
31
31
|
tryGetFromNestedMap,
|
|
32
|
+
mapNestedMap,
|
|
32
33
|
nestedMapToFlatList,
|
|
33
34
|
nestedMapFromFlatList,
|
|
34
35
|
} from "./nestedMap.js";
|
|
@@ -67,6 +68,7 @@ export {
|
|
|
67
68
|
JsonCompatibleReadOnlySchema,
|
|
68
69
|
makeArray,
|
|
69
70
|
mapIterable,
|
|
71
|
+
filterIterable,
|
|
70
72
|
type Mutable,
|
|
71
73
|
type Populated,
|
|
72
74
|
type RecursiveReadonly,
|
|
@@ -125,3 +127,11 @@ export {
|
|
|
125
127
|
type IdAllocationState,
|
|
126
128
|
fakeIdAllocator,
|
|
127
129
|
} from "./idAllocator.js";
|
|
130
|
+
|
|
131
|
+
export {
|
|
132
|
+
Breakable,
|
|
133
|
+
type WithBreakable,
|
|
134
|
+
breakingMethod,
|
|
135
|
+
throwIfBroken,
|
|
136
|
+
breakingClass,
|
|
137
|
+
} from "./breakable.js";
|
package/src/util/nestedMap.ts
CHANGED
|
@@ -16,6 +16,13 @@ import type { MapGetSet } from "./utils.js";
|
|
|
16
16
|
*/
|
|
17
17
|
export type NestedMap<Key1, Key2, Value> = Map<Key1, Map<Key2, Value>>;
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* A read-only version of {@link NestedMap}.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export type ReadonlyNestedMap<Key1, Key2, Value> = ReadonlyMap<Key1, ReadonlyMap<Key2, Value>>;
|
|
25
|
+
|
|
19
26
|
/**
|
|
20
27
|
* If (key1, key2) already has a value in the map, it is returned, otherwise value is added under (key1, key2) and undefined is returned.
|
|
21
28
|
*
|
|
@@ -51,7 +58,7 @@ export function tryAddToNestedMap<Key1, Key2, Value>(
|
|
|
51
58
|
* @internal
|
|
52
59
|
*/
|
|
53
60
|
export function populateNestedMap<Key1, Key2, Value>(
|
|
54
|
-
source:
|
|
61
|
+
source: ReadonlyNestedMap<Key1, Key2, Value>,
|
|
55
62
|
destination: NestedMap<Key1, Key2, Value>,
|
|
56
63
|
override: boolean,
|
|
57
64
|
): void {
|
|
@@ -187,7 +194,7 @@ export function deleteFromNestedMap<Key1, Key2, Value>(
|
|
|
187
194
|
* Converts a nested map to a flat list of triplets.
|
|
188
195
|
*/
|
|
189
196
|
export function nestedMapToFlatList<Key1, Key2, Value>(
|
|
190
|
-
map:
|
|
197
|
+
map: ReadonlyNestedMap<Key1, Key2, Value>,
|
|
191
198
|
): [Key1, Key2, Value][] {
|
|
192
199
|
const list: [Key1, Key2, Value][] = [];
|
|
193
200
|
map.forEach((innerMap, key1) => {
|
|
@@ -212,7 +219,7 @@ export function nestedMapFromFlatList<Key1, Key2, Value>(
|
|
|
212
219
|
}
|
|
213
220
|
|
|
214
221
|
export function forEachInNestedMap<Key1, Key2, Value>(
|
|
215
|
-
map:
|
|
222
|
+
map: ReadonlyNestedMap<Key1, Key2, Value>,
|
|
216
223
|
delegate: (value: Value, key1: Key1, key2: Key2) => void,
|
|
217
224
|
): void {
|
|
218
225
|
map.forEach((innerMap, keyFirst) => {
|
|
@@ -222,6 +229,29 @@ export function forEachInNestedMap<Key1, Key2, Value>(
|
|
|
222
229
|
});
|
|
223
230
|
}
|
|
224
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Maps the `input` map values using the provided `delegate`.
|
|
234
|
+
*
|
|
235
|
+
* @param input - The `NestedMap` whose contents are being mapped.
|
|
236
|
+
* @param delegate - The delegate to use for mapping values,
|
|
237
|
+
* @returns A new `NestedMap` with the same keys as `input`, but with the values produced by `delegate`.
|
|
238
|
+
*/
|
|
239
|
+
export function mapNestedMap<Key1, Key2, ValueIn, ValueOut = ValueIn>(
|
|
240
|
+
input: ReadonlyNestedMap<Key1, Key2, ValueIn>,
|
|
241
|
+
delegate: (value: ValueIn, key1: Key1, key2: Key2) => ValueOut,
|
|
242
|
+
): NestedMap<Key1, Key2, ValueOut> {
|
|
243
|
+
const output = new Map<Key1, Map<Key2, ValueOut>>();
|
|
244
|
+
input.forEach((inputInnerMap, keyFirst) => {
|
|
245
|
+
const outputInnerMap = new Map<Key2, ValueOut>();
|
|
246
|
+
inputInnerMap.forEach((val, keySecond) => {
|
|
247
|
+
const mappedValue = delegate(val, keyFirst, keySecond);
|
|
248
|
+
outputInnerMap.set(keySecond, mappedValue);
|
|
249
|
+
});
|
|
250
|
+
output.set(keyFirst, outputInnerMap);
|
|
251
|
+
});
|
|
252
|
+
return output;
|
|
253
|
+
}
|
|
254
|
+
|
|
225
255
|
/**
|
|
226
256
|
* Map with two keys; same semantics as NestedMap, but maintains a size count for the entire collection.
|
|
227
257
|
* Note: undefined is not supported as a value, and will cause incorrect behavior.
|
package/src/util/utils.ts
CHANGED
|
@@ -174,6 +174,23 @@ export function* mapIterable<T, U>(
|
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Filter one iterable into another
|
|
179
|
+
* @param iterable - the iterable to filter
|
|
180
|
+
* @param filter - the predicate function to run on each element of the iterable
|
|
181
|
+
* @returns a new iterable including only the elements that passed the filter predicate
|
|
182
|
+
*/
|
|
183
|
+
export function* filterIterable<T>(
|
|
184
|
+
iterable: Iterable<T>,
|
|
185
|
+
filter: (t: T) => boolean,
|
|
186
|
+
): IterableIterator<T> {
|
|
187
|
+
for (const t of iterable) {
|
|
188
|
+
if (filter(t)) {
|
|
189
|
+
yield t;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
177
194
|
/**
|
|
178
195
|
* Finds the first element in the given iterable that satisfies a predicate.
|
|
179
196
|
* @param iterable - The iterable to search for an eligible element
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { type FieldKey } from "../../core/index.js";
|
|
6
|
-
import type { FlexTreeContext, FlexTreeObjectNode } from "../flex-tree/index.js";
|
|
7
|
-
import { type FlexTreeSchema } from "../typed-schema/index.js";
|
|
8
|
-
import { type LocalNodeKey } from "./nodeKey.js";
|
|
9
|
-
/**
|
|
10
|
-
* The node key index records nodes with {@link LocalNodeKey}s and allows them to be looked up by key.
|
|
11
|
-
*/
|
|
12
|
-
export declare class NodeKeyIndex implements ReadonlyMap<LocalNodeKey, FlexTreeObjectNode> {
|
|
13
|
-
readonly fieldKey: FieldKey;
|
|
14
|
-
private readonly nodes;
|
|
15
|
-
constructor(fieldKey: FieldKey, keys?: Iterable<[LocalNodeKey, FlexTreeObjectNode]>);
|
|
16
|
-
/**
|
|
17
|
-
* Returns true if the given schema contains the node key type, otherwise false
|
|
18
|
-
*/
|
|
19
|
-
static hasNodeKeyTreeSchema(schema: FlexTreeSchema): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Search the tree for all nodes with keys, and record them in this index for lookup.
|
|
22
|
-
* This should be called each time the tree changes; each call to scan forgets all existing keys.
|
|
23
|
-
* @param context - the flex tree context in which to search for node keys
|
|
24
|
-
*/
|
|
25
|
-
scanKeys(context: FlexTreeContext): void;
|
|
26
|
-
/**
|
|
27
|
-
* Create a copy of this index which can be mutated without affecting this one.
|
|
28
|
-
*/
|
|
29
|
-
clone(context: FlexTreeContext): NodeKeyIndex;
|
|
30
|
-
forEach(callbackfn: (value: FlexTreeObjectNode, key: LocalNodeKey, map: ReadonlyMap<LocalNodeKey, FlexTreeObjectNode>) => void, thisArg?: unknown): void;
|
|
31
|
-
get(key: LocalNodeKey): FlexTreeObjectNode | undefined;
|
|
32
|
-
has(key: LocalNodeKey): boolean;
|
|
33
|
-
get size(): number;
|
|
34
|
-
entries(): IterableIterator<[LocalNodeKey, FlexTreeObjectNode]>;
|
|
35
|
-
keys(): IterableIterator<LocalNodeKey>;
|
|
36
|
-
values(): IterableIterator<FlexTreeObjectNode>;
|
|
37
|
-
[Symbol.iterator](): IterableIterator<[LocalNodeKey, FlexTreeObjectNode]>;
|
|
38
|
-
private findKeys;
|
|
39
|
-
private findKeysInField;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=nodeKeyIndex.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodeKeyIndex.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/node-key/nodeKeyIndex.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,KAAK,QAAQ,EAAe,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EACX,eAAe,EAGf,kBAAkB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,cAAc,EAGnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,KAAK,YAAY,EAAyB,MAAM,cAAc,CA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the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.NodeKeyIndex = void 0;
|
|
8
|
-
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
9
|
-
const index_js_1 = require("../../core/index.js");
|
|
10
|
-
const index_js_2 = require("../typed-schema/index.js");
|
|
11
|
-
const nodeKey_js_1 = require("./nodeKey.js");
|
|
12
|
-
/**
|
|
13
|
-
* The node key index records nodes with {@link LocalNodeKey}s and allows them to be looked up by key.
|
|
14
|
-
*/
|
|
15
|
-
class NodeKeyIndex {
|
|
16
|
-
constructor(fieldKey, keys = []) {
|
|
17
|
-
this.fieldKey = fieldKey;
|
|
18
|
-
this.nodes = new Map(keys);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Returns true if the given schema contains the node key type, otherwise false
|
|
22
|
-
*/
|
|
23
|
-
static hasNodeKeyTreeSchema(schema) {
|
|
24
|
-
// TODO: make TreeStoredSchema contain ViewSchema and compare by reference to nodeKeyTreeSchema.
|
|
25
|
-
const treeSchema = schema.nodeSchema.get(nodeKey_js_1.nodeKeyTreeIdentifier);
|
|
26
|
-
if (!(treeSchema instanceof index_js_2.LeafNodeSchema)) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
return treeSchema.leafValue === index_js_1.ValueSchema.String;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Search the tree for all nodes with keys, and record them in this index for lookup.
|
|
33
|
-
* This should be called each time the tree changes; each call to scan forgets all existing keys.
|
|
34
|
-
* @param context - the flex tree context in which to search for node keys
|
|
35
|
-
*/
|
|
36
|
-
// TODO: This can be optimized by responding to deltas/changes to the tree, rather than rescanning the whole tree every time
|
|
37
|
-
scanKeys(context) {
|
|
38
|
-
this.nodes.clear();
|
|
39
|
-
if (NodeKeyIndex.hasNodeKeyTreeSchema(context.schema)) {
|
|
40
|
-
for (const [id, node] of this.findKeysInField(context.root)) {
|
|
41
|
-
// TODO:
|
|
42
|
-
// This invariant (that there is only one node with a given key) is not enforced by tree, so it should not assert.
|
|
43
|
-
// Multiple nodes (including deleted ones), might occur with the same key.
|
|
44
|
-
(0, internal_1.assert)(!this.nodes.has(id), 0x6e1 /* Encountered duplicate node key */);
|
|
45
|
-
this.nodes.set(id, node);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Create a copy of this index which can be mutated without affecting this one.
|
|
51
|
-
*/
|
|
52
|
-
clone(context) {
|
|
53
|
-
const indexClone = new NodeKeyIndex(this.fieldKey);
|
|
54
|
-
indexClone.scanKeys(context);
|
|
55
|
-
return indexClone;
|
|
56
|
-
}
|
|
57
|
-
// #region ReadonlyMap interface
|
|
58
|
-
forEach(callbackfn, thisArg) {
|
|
59
|
-
return this.nodes.forEach(callbackfn, thisArg);
|
|
60
|
-
}
|
|
61
|
-
get(key) {
|
|
62
|
-
return this.nodes.get(key);
|
|
63
|
-
}
|
|
64
|
-
has(key) {
|
|
65
|
-
return this.nodes.has(key);
|
|
66
|
-
}
|
|
67
|
-
get size() {
|
|
68
|
-
return this.nodes.size;
|
|
69
|
-
}
|
|
70
|
-
entries() {
|
|
71
|
-
return this.nodes.entries();
|
|
72
|
-
}
|
|
73
|
-
keys() {
|
|
74
|
-
return this.nodes.keys();
|
|
75
|
-
}
|
|
76
|
-
values() {
|
|
77
|
-
return this.nodes.values();
|
|
78
|
-
}
|
|
79
|
-
[Symbol.iterator]() {
|
|
80
|
-
return this.nodes[Symbol.iterator]();
|
|
81
|
-
}
|
|
82
|
-
// #endregion ReadonlyMap interface
|
|
83
|
-
*findKeys(node) {
|
|
84
|
-
if ((0, index_js_2.schemaIsObjectNode)(node.schema)) {
|
|
85
|
-
const key = node.localNodeKey;
|
|
86
|
-
if (key !== undefined) {
|
|
87
|
-
yield [key, node];
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
for (const f of node.boxedIterator()) {
|
|
91
|
-
yield* this.findKeysInField(f);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
*findKeysInField(f) {
|
|
95
|
-
for (const child of f.boxedIterator()) {
|
|
96
|
-
yield* this.findKeys(child);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
exports.NodeKeyIndex = NodeKeyIndex;
|
|
101
|
-
//# sourceMappingURL=nodeKeyIndex.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodeKeyIndex.js","sourceRoot":"","sources":["../../../src/feature-libraries/node-key/nodeKeyIndex.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,kDAAiE;AAOjE,uDAIkC;AAElC,6CAAwE;AAExE;;GAEG;AACH,MAAa,YAAY;IAIxB,YACiB,QAAkB,EAClC,OAAqD,EAAE;QADvC,aAAQ,GAAR,QAAQ,CAAU;QAGlC,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,oBAAoB,CAAC,MAAsB;QACxD,gGAAgG;QAChG,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,kCAAqB,CAAC,CAAC;QAChE,IAAI,CAAC,CAAC,UAAU,YAAY,yBAAc,CAAC,EAAE,CAAC;YAC7C,OAAO,KAAK,CAAC;QACd,CAAC;QACD,OAAO,UAAU,CAAC,SAAS,KAAK,sBAAW,CAAC,MAAM,CAAC;IACpD,CAAC;IAED;;;;OAIG;IACH,4HAA4H;IACrH,QAAQ,CAAC,OAAwB;QACvC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,YAAY,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACvD,KAAK,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,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AQ,CAAC,EAAE,CAAC;IACtC,CAAC;IACD,mCAAmC;IAE3B,CAAC,QAAQ,CAChB,IAAkB;QAElB,IAAI,IAAA,6BAAkB,EAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACrC,MAAM,GAAG,GAAI,IAA2B,CAAC,YAAY,CAAC;YACtD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,CAAC,GAAG,EAAE,IAA0B,CAAC,CAAC;YACzC,CAAC;QACF,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;YACtC,KAAK,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAChC,CAAC;IACF,CAAC;IAEO,CAAC,eAAe,CACvB,CAAgB;QAEhB,KAAK,MAAM,KAAK,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC;YACvC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;IACF,CAAC;CACD;AA1GD,oCA0GC","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\";\n\nimport { type FieldKey, ValueSchema } from \"../../core/index.js\";\nimport type {\n\tFlexTreeContext,\n\tFlexTreeField,\n\tFlexTreeNode,\n\tFlexTreeObjectNode,\n} from \"../flex-tree/index.js\";\nimport {\n\ttype FlexTreeSchema,\n\tLeafNodeSchema,\n\tschemaIsObjectNode,\n} from \"../typed-schema/index.js\";\n\nimport { type LocalNodeKey, nodeKeyTreeIdentifier } from \"./nodeKey.js\";\n\n/**\n * The node key index records nodes with {@link LocalNodeKey}s and allows them to be looked up by key.\n */\nexport class NodeKeyIndex implements ReadonlyMap<LocalNodeKey, FlexTreeObjectNode> {\n\t// TODO: The data structure that holds the nodes can likely be optimized to better support cloning\n\tprivate readonly nodes: Map<LocalNodeKey, FlexTreeObjectNode>;\n\n\tpublic constructor(\n\t\tpublic readonly fieldKey: FieldKey,\n\t\tkeys: Iterable<[LocalNodeKey, FlexTreeObjectNode]> = [],\n\t) {\n\t\tthis.nodes = new Map(keys);\n\t}\n\n\t/**\n\t * Returns true if the given schema contains the node key type, otherwise false\n\t */\n\tpublic static hasNodeKeyTreeSchema(schema: FlexTreeSchema): boolean {\n\t\t// TODO: make TreeStoredSchema contain ViewSchema and compare by reference to nodeKeyTreeSchema.\n\t\tconst treeSchema = schema.nodeSchema.get(nodeKeyTreeIdentifier);\n\t\tif (!(treeSchema instanceof LeafNodeSchema)) {\n\t\t\treturn false;\n\t\t}\n\t\treturn treeSchema.leafValue === ValueSchema.String;\n\t}\n\n\t/**\n\t * Search the tree for all nodes with keys, and record them in this index for lookup.\n\t * This should be called each time the tree changes; each call to scan forgets all existing keys.\n\t * @param context - the flex tree context in which to search for node keys\n\t */\n\t// TODO: This can be optimized by responding to deltas/changes to the tree, rather than rescanning the whole tree every time\n\tpublic scanKeys(context: FlexTreeContext): void {\n\t\tthis.nodes.clear();\n\t\tif (NodeKeyIndex.hasNodeKeyTreeSchema(context.schema)) {\n\t\t\tfor (const [id, node] of this.findKeysInField(context.root)) {\n\t\t\t\t// TODO:\n\t\t\t\t// This invariant (that there is only one node with a given key) is not enforced by tree, so it should not assert.\n\t\t\t\t// Multiple nodes (including deleted ones), might occur with the same key.\n\t\t\t\tassert(!this.nodes.has(id), 0x6e1 /* Encountered duplicate node key */);\n\t\t\t\tthis.nodes.set(id, node);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Create a copy of this index which can be mutated without affecting this one.\n\t */\n\tpublic clone(context: FlexTreeContext): NodeKeyIndex {\n\t\tconst indexClone = new NodeKeyIndex(this.fieldKey);\n\t\tindexClone.scanKeys(context);\n\t\treturn indexClone;\n\t}\n\n\t// #region ReadonlyMap interface\n\tpublic forEach(\n\t\tcallbackfn: (\n\t\t\tvalue: FlexTreeObjectNode,\n\t\t\tkey: LocalNodeKey,\n\t\t\tmap: ReadonlyMap<LocalNodeKey, FlexTreeObjectNode>,\n\t\t) => void,\n\t\tthisArg?: unknown,\n\t): void {\n\t\treturn this.nodes.forEach(callbackfn, thisArg);\n\t}\n\tpublic get(key: LocalNodeKey): FlexTreeObjectNode | undefined {\n\t\treturn this.nodes.get(key);\n\t}\n\tpublic has(key: LocalNodeKey): boolean {\n\t\treturn this.nodes.has(key);\n\t}\n\tpublic get size(): number {\n\t\treturn this.nodes.size;\n\t}\n\tpublic entries(): IterableIterator<[LocalNodeKey, FlexTreeObjectNode]> {\n\t\treturn this.nodes.entries();\n\t}\n\tpublic keys(): IterableIterator<LocalNodeKey> {\n\t\treturn this.nodes.keys();\n\t}\n\tpublic values(): IterableIterator<FlexTreeObjectNode> {\n\t\treturn this.nodes.values();\n\t}\n\tpublic [Symbol.iterator](): IterableIterator<[LocalNodeKey, FlexTreeObjectNode]> {\n\t\treturn this.nodes[Symbol.iterator]();\n\t}\n\t// #endregion ReadonlyMap interface\n\n\tprivate *findKeys(\n\t\tnode: FlexTreeNode,\n\t): Iterable<[key: LocalNodeKey, node: FlexTreeObjectNode]> {\n\t\tif (schemaIsObjectNode(node.schema)) {\n\t\t\tconst key = (node as FlexTreeObjectNode).localNodeKey;\n\t\t\tif (key !== undefined) {\n\t\t\t\tyield [key, node as FlexTreeObjectNode];\n\t\t\t}\n\t\t}\n\t\tfor (const f of node.boxedIterator()) {\n\t\t\tyield* this.findKeysInField(f);\n\t\t}\n\t}\n\n\tprivate *findKeysInField(\n\t\tf: FlexTreeField,\n\t): Iterable<[key: LocalNodeKey, node: FlexTreeObjectNode]> {\n\t\tfor (const child of f.boxedIterator()) {\n\t\t\tyield* this.findKeys(child);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { type FieldKey } from "../../core/index.js";
|
|
6
|
-
import type { FlexTreeContext, FlexTreeObjectNode } from "../flex-tree/index.js";
|
|
7
|
-
import { type FlexTreeSchema } from "../typed-schema/index.js";
|
|
8
|
-
import { type LocalNodeKey } from "./nodeKey.js";
|
|
9
|
-
/**
|
|
10
|
-
* The node key index records nodes with {@link LocalNodeKey}s and allows them to be looked up by key.
|
|
11
|
-
*/
|
|
12
|
-
export declare class NodeKeyIndex implements ReadonlyMap<LocalNodeKey, FlexTreeObjectNode> {
|
|
13
|
-
readonly fieldKey: FieldKey;
|
|
14
|
-
private readonly nodes;
|
|
15
|
-
constructor(fieldKey: FieldKey, keys?: Iterable<[LocalNodeKey, FlexTreeObjectNode]>);
|
|
16
|
-
/**
|
|
17
|
-
* Returns true if the given schema contains the node key type, otherwise false
|
|
18
|
-
*/
|
|
19
|
-
static hasNodeKeyTreeSchema(schema: FlexTreeSchema): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Search the tree for all nodes with keys, and record them in this index for lookup.
|
|
22
|
-
* This should be called each time the tree changes; each call to scan forgets all existing keys.
|
|
23
|
-
* @param context - the flex tree context in which to search for node keys
|
|
24
|
-
*/
|
|
25
|
-
scanKeys(context: FlexTreeContext): void;
|
|
26
|
-
/**
|
|
27
|
-
* Create a copy of this index which can be mutated without affecting this one.
|
|
28
|
-
*/
|
|
29
|
-
clone(context: FlexTreeContext): NodeKeyIndex;
|
|
30
|
-
forEach(callbackfn: (value: FlexTreeObjectNode, key: LocalNodeKey, map: ReadonlyMap<LocalNodeKey, FlexTreeObjectNode>) => void, thisArg?: unknown): void;
|
|
31
|
-
get(key: LocalNodeKey): FlexTreeObjectNode | undefined;
|
|
32
|
-
has(key: LocalNodeKey): boolean;
|
|
33
|
-
get size(): number;
|
|
34
|
-
entries(): IterableIterator<[LocalNodeKey, FlexTreeObjectNode]>;
|
|
35
|
-
keys(): IterableIterator<LocalNodeKey>;
|
|
36
|
-
values(): IterableIterator<FlexTreeObjectNode>;
|
|
37
|
-
[Symbol.iterator](): IterableIterator<[LocalNodeKey, FlexTreeObjectNode]>;
|
|
38
|
-
private findKeys;
|
|
39
|
-
private findKeysInField;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=nodeKeyIndex.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodeKeyIndex.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/node-key/nodeKeyIndex.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,KAAK,QAAQ,EAAe,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EACX,eAAe,EAGf,kBAAkB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,KAAK,cAAc,EAGnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,KAAK,YAAY,EAAyB,MAAM,cAAc,CAAC;AAExE;;GAEG;AACH,qBAAa,YAAa,YAAW,WAAW,CAAC,YAAY,EAAE,kBAAkB,CAAC;aAKhE,QAAQ,EAAE,QAAQ;IAHnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwC;gBAG7C,QAAQ,EAAE,QAAQ,EAClC,IAAI,GAAE,QAAQ,CAAC,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAM;IAKxD;;OAEG;WACW,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO;IASnE;;;;OAIG;IAEI,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAa/C;;OAEG;IACI,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,YAAY;IAO7C,OAAO,CACb,UAAU,EAAE,CACX,KAAK,EAAE,kBAAkB,EACzB,GAAG,EAAE,YAAY,EACjB,GAAG,EAAE,WAAW,CAAC,YAAY,EAAE,kBAAkB,CAAC,KAC9C,IAAI,EACT,OAAO,CAAC,EAAE,OAAO,GACf,IAAI;IAGA,GAAG,CAAC,GAAG,EAAE,YAAY,GAAG,kBAAkB,GAAG,SAAS;IAGtD,GAAG,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO;IAGtC,IAAW,IAAI,IAAI,MAAM,CAExB;IACM,OAAO,IAAI,gBAAgB,CAAC,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAG/D,IAAI,IAAI,gBAAgB,CAAC,YAAY,CAAC;IAGtC,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,CAAC;IAG9C,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAKhF,OAAO,CAAE,QAAQ;IAcjB,OAAO,CAAE,eAAe;CAOxB"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { assert } from "@fluidframework/core-utils/internal";
|
|
6
|
-
import { ValueSchema } from "../../core/index.js";
|
|
7
|
-
import { LeafNodeSchema, schemaIsObjectNode, } from "../typed-schema/index.js";
|
|
8
|
-
import { nodeKeyTreeIdentifier } from "./nodeKey.js";
|
|
9
|
-
/**
|
|
10
|
-
* The node key index records nodes with {@link LocalNodeKey}s and allows them to be looked up by key.
|
|
11
|
-
*/
|
|
12
|
-
export class NodeKeyIndex {
|
|
13
|
-
constructor(fieldKey, keys = []) {
|
|
14
|
-
this.fieldKey = fieldKey;
|
|
15
|
-
this.nodes = new Map(keys);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Returns true if the given schema contains the node key type, otherwise false
|
|
19
|
-
*/
|
|
20
|
-
static hasNodeKeyTreeSchema(schema) {
|
|
21
|
-
// TODO: make TreeStoredSchema contain ViewSchema and compare by reference to nodeKeyTreeSchema.
|
|
22
|
-
const treeSchema = schema.nodeSchema.get(nodeKeyTreeIdentifier);
|
|
23
|
-
if (!(treeSchema instanceof LeafNodeSchema)) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return treeSchema.leafValue === ValueSchema.String;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Search the tree for all nodes with keys, and record them in this index for lookup.
|
|
30
|
-
* This should be called each time the tree changes; each call to scan forgets all existing keys.
|
|
31
|
-
* @param context - the flex tree context in which to search for node keys
|
|
32
|
-
*/
|
|
33
|
-
// TODO: This can be optimized by responding to deltas/changes to the tree, rather than rescanning the whole tree every time
|
|
34
|
-
scanKeys(context) {
|
|
35
|
-
this.nodes.clear();
|
|
36
|
-
if (NodeKeyIndex.hasNodeKeyTreeSchema(context.schema)) {
|
|
37
|
-
for (const [id, node] of this.findKeysInField(context.root)) {
|
|
38
|
-
// TODO:
|
|
39
|
-
// This invariant (that there is only one node with a given key) is not enforced by tree, so it should not assert.
|
|
40
|
-
// Multiple nodes (including deleted ones), might occur with the same key.
|
|
41
|
-
assert(!this.nodes.has(id), 0x6e1 /* Encountered duplicate node key */);
|
|
42
|
-
this.nodes.set(id, node);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Create a copy of this index which can be mutated without affecting this one.
|
|
48
|
-
*/
|
|
49
|
-
clone(context) {
|
|
50
|
-
const indexClone = new NodeKeyIndex(this.fieldKey);
|
|
51
|
-
indexClone.scanKeys(context);
|
|
52
|
-
return indexClone;
|
|
53
|
-
}
|
|
54
|
-
// #region ReadonlyMap interface
|
|
55
|
-
forEach(callbackfn, thisArg) {
|
|
56
|
-
return this.nodes.forEach(callbackfn, thisArg);
|
|
57
|
-
}
|
|
58
|
-
get(key) {
|
|
59
|
-
return this.nodes.get(key);
|
|
60
|
-
}
|
|
61
|
-
has(key) {
|
|
62
|
-
return this.nodes.has(key);
|
|
63
|
-
}
|
|
64
|
-
get size() {
|
|
65
|
-
return this.nodes.size;
|
|
66
|
-
}
|
|
67
|
-
entries() {
|
|
68
|
-
return this.nodes.entries();
|
|
69
|
-
}
|
|
70
|
-
keys() {
|
|
71
|
-
return this.nodes.keys();
|
|
72
|
-
}
|
|
73
|
-
values() {
|
|
74
|
-
return this.nodes.values();
|
|
75
|
-
}
|
|
76
|
-
[Symbol.iterator]() {
|
|
77
|
-
return this.nodes[Symbol.iterator]();
|
|
78
|
-
}
|
|
79
|
-
// #endregion ReadonlyMap interface
|
|
80
|
-
*findKeys(node) {
|
|
81
|
-
if (schemaIsObjectNode(node.schema)) {
|
|
82
|
-
const key = node.localNodeKey;
|
|
83
|
-
if (key !== undefined) {
|
|
84
|
-
yield [key, node];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
for (const f of node.boxedIterator()) {
|
|
88
|
-
yield* this.findKeysInField(f);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
*findKeysInField(f) {
|
|
92
|
-
for (const child of f.boxedIterator()) {
|
|
93
|
-
yield* this.findKeys(child);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
//# sourceMappingURL=nodeKeyIndex.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodeKeyIndex.js","sourceRoot":"","sources":["../../../src/feature-libraries/node-key/nodeKeyIndex.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAAiB,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAOjE,OAAO,EAEN,cAAc,EACd,kBAAkB,GAClB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAqB,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAExE;;GAEG;AACH,MAAM,OAAO,YAAY;IAIxB,YACiB,QAAkB,EAClC,OAAqD,EAAE;QADvC,aAAQ,GAAR,QAAQ,CAAU;QAGlC,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,M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\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\";\n\nimport { type FieldKey, ValueSchema } from \"../../core/index.js\";\nimport type {\n\tFlexTreeContext,\n\tFlexTreeField,\n\tFlexTreeNode,\n\tFlexTreeObjectNode,\n} from \"../flex-tree/index.js\";\nimport {\n\ttype FlexTreeSchema,\n\tLeafNodeSchema,\n\tschemaIsObjectNode,\n} from \"../typed-schema/index.js\";\n\nimport { type LocalNodeKey, nodeKeyTreeIdentifier } from \"./nodeKey.js\";\n\n/**\n * The node key index records nodes with {@link LocalNodeKey}s and allows them to be looked up by key.\n */\nexport class NodeKeyIndex implements ReadonlyMap<LocalNodeKey, FlexTreeObjectNode> {\n\t// TODO: The data structure that holds the nodes can likely be optimized to better support cloning\n\tprivate readonly nodes: Map<LocalNodeKey, FlexTreeObjectNode>;\n\n\tpublic constructor(\n\t\tpublic readonly fieldKey: FieldKey,\n\t\tkeys: Iterable<[LocalNodeKey, FlexTreeObjectNode]> = [],\n\t) {\n\t\tthis.nodes = new Map(keys);\n\t}\n\n\t/**\n\t * Returns true if the given schema contains the node key type, otherwise false\n\t */\n\tpublic static hasNodeKeyTreeSchema(schema: FlexTreeSchema): boolean {\n\t\t// TODO: make TreeStoredSchema contain ViewSchema and compare by reference to nodeKeyTreeSchema.\n\t\tconst treeSchema = schema.nodeSchema.get(nodeKeyTreeIdentifier);\n\t\tif (!(treeSchema instanceof LeafNodeSchema)) {\n\t\t\treturn false;\n\t\t}\n\t\treturn treeSchema.leafValue === ValueSchema.String;\n\t}\n\n\t/**\n\t * Search the tree for all nodes with keys, and record them in this index for lookup.\n\t * This should be called each time the tree changes; each call to scan forgets all existing keys.\n\t * @param context - the flex tree context in which to search for node keys\n\t */\n\t// TODO: This can be optimized by responding to deltas/changes to the tree, rather than rescanning the whole tree every time\n\tpublic scanKeys(context: FlexTreeContext): void {\n\t\tthis.nodes.clear();\n\t\tif (NodeKeyIndex.hasNodeKeyTreeSchema(context.schema)) {\n\t\t\tfor (const [id, node] of this.findKeysInField(context.root)) {\n\t\t\t\t// TODO:\n\t\t\t\t// This invariant (that there is only one node with a given key) is not enforced by tree, so it should not assert.\n\t\t\t\t// Multiple nodes (including deleted ones), might occur with the same key.\n\t\t\t\tassert(!this.nodes.has(id), 0x6e1 /* Encountered duplicate node key */);\n\t\t\t\tthis.nodes.set(id, node);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Create a copy of this index which can be mutated without affecting this one.\n\t */\n\tpublic clone(context: FlexTreeContext): NodeKeyIndex {\n\t\tconst indexClone = new NodeKeyIndex(this.fieldKey);\n\t\tindexClone.scanKeys(context);\n\t\treturn indexClone;\n\t}\n\n\t// #region ReadonlyMap interface\n\tpublic forEach(\n\t\tcallbackfn: (\n\t\t\tvalue: FlexTreeObjectNode,\n\t\t\tkey: LocalNodeKey,\n\t\t\tmap: ReadonlyMap<LocalNodeKey, FlexTreeObjectNode>,\n\t\t) => void,\n\t\tthisArg?: unknown,\n\t): void {\n\t\treturn this.nodes.forEach(callbackfn, thisArg);\n\t}\n\tpublic get(key: LocalNodeKey): FlexTreeObjectNode | undefined {\n\t\treturn this.nodes.get(key);\n\t}\n\tpublic has(key: LocalNodeKey): boolean {\n\t\treturn this.nodes.has(key);\n\t}\n\tpublic get size(): number {\n\t\treturn this.nodes.size;\n\t}\n\tpublic entries(): IterableIterator<[LocalNodeKey, FlexTreeObjectNode]> {\n\t\treturn this.nodes.entries();\n\t}\n\tpublic keys(): IterableIterator<LocalNodeKey> {\n\t\treturn this.nodes.keys();\n\t}\n\tpublic values(): IterableIterator<FlexTreeObjectNode> {\n\t\treturn this.nodes.values();\n\t}\n\tpublic [Symbol.iterator](): IterableIterator<[LocalNodeKey, FlexTreeObjectNode]> {\n\t\treturn this.nodes[Symbol.iterator]();\n\t}\n\t// #endregion ReadonlyMap interface\n\n\tprivate *findKeys(\n\t\tnode: FlexTreeNode,\n\t): Iterable<[key: LocalNodeKey, node: FlexTreeObjectNode]> {\n\t\tif (schemaIsObjectNode(node.schema)) {\n\t\t\tconst key = (node as FlexTreeObjectNode).localNodeKey;\n\t\t\tif (key !== undefined) {\n\t\t\t\tyield [key, node as FlexTreeObjectNode];\n\t\t\t}\n\t\t}\n\t\tfor (const f of node.boxedIterator()) {\n\t\t\tyield* this.findKeysInField(f);\n\t\t}\n\t}\n\n\tprivate *findKeysInField(\n\t\tf: FlexTreeField,\n\t): Iterable<[key: LocalNodeKey, node: FlexTreeObjectNode]> {\n\t\tfor (const child of f.boxedIterator()) {\n\t\t\tyield* this.findKeys(child);\n\t\t}\n\t}\n}\n"]}
|