@fluidframework/tree 2.42.0 → 2.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +189 -0
- package/api-report/tree.alpha.api.md +72 -25
- package/api-report/tree.beta.api.md +34 -0
- package/api-report/tree.legacy.alpha.api.md +1 -0
- package/api-report/tree.legacy.public.api.md +1 -0
- package/api-report/tree.public.api.md +1 -0
- package/dist/alpha.d.ts +12 -6
- package/dist/beta.d.ts +6 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +5 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/schema-stored/formatV2.d.ts +80 -0
- package/dist/core/schema-stored/formatV2.d.ts.map +1 -0
- package/dist/core/schema-stored/formatV2.js +55 -0
- package/dist/core/schema-stored/formatV2.js.map +1 -0
- package/dist/core/schema-stored/index.d.ts +3 -1
- package/dist/core/schema-stored/index.d.ts.map +1 -1
- package/dist/core/schema-stored/index.js +5 -2
- package/dist/core/schema-stored/index.js.map +1 -1
- package/dist/core/schema-stored/schema.d.ts +49 -17
- package/dist/core/schema-stored/schema.d.ts.map +1 -1
- package/dist/core/schema-stored/schema.js +65 -22
- package/dist/core/schema-stored/schema.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts +9 -7
- package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +13 -9
- package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +3 -3
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +6 -6
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts +1 -1
- package/dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/nodeShape.js +3 -3
- package/dist/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
- package/dist/feature-libraries/detachedFieldIndexSummarizer.d.ts +8 -3
- package/dist/feature-libraries/detachedFieldIndexSummarizer.d.ts.map +1 -1
- package/dist/feature-libraries/detachedFieldIndexSummarizer.js +2 -5
- package/dist/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +24 -25
- 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 +0 -1
- package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/index.js +1 -7
- package/dist/feature-libraries/flex-tree/index.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyEntity.d.ts +2 -2
- package/dist/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyEntity.js +3 -0
- package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.d.ts +1 -2
- package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.js +2 -5
- package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts +5 -5
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.js +15 -7
- package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +8 -3
- package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.js +2 -5
- package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +2 -2
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +1 -2
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/mapTreeCursor.d.ts +16 -2
- package/dist/feature-libraries/mapTreeCursor.d.ts.map +1 -1
- package/dist/feature-libraries/mapTreeCursor.js.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldKindWithEditor.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldKindWithEditor.js +2 -0
- package/dist/feature-libraries/modular-schema/fieldKindWithEditor.js.map +1 -1
- package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
- package/dist/feature-libraries/object-forest/objectForest.js +2 -0
- package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
- package/dist/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
- package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js +8 -4
- package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
- package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -36
- package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts.map +1 -1
- package/dist/feature-libraries/schema-edits/schemaChangeFormat.js +3 -3
- package/dist/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
- package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
- package/dist/feature-libraries/schema-index/codec.js +59 -9
- package/dist/feature-libraries/schema-index/codec.js.map +1 -1
- package/dist/feature-libraries/schema-index/formatV1.d.ts +1 -1
- package/dist/feature-libraries/schema-index/formatV2.d.ts +42 -0
- package/dist/feature-libraries/schema-index/formatV2.d.ts.map +1 -0
- package/dist/feature-libraries/schema-index/formatV2.js +26 -0
- package/dist/feature-libraries/schema-index/formatV2.js.map +1 -0
- package/dist/feature-libraries/schema-index/index.d.ts +2 -1
- package/dist/feature-libraries/schema-index/index.d.ts.map +1 -1
- package/dist/feature-libraries/schema-index/index.js +4 -2
- package/dist/feature-libraries/schema-index/index.js.map +1 -1
- package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts +7 -2
- package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
- package/dist/feature-libraries/schema-index/schemaSummarizer.js +6 -6
- package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
- package/dist/index.d.ts +2 -2
- 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/shared-tree/schematizeTree.d.ts.map +1 -1
- package/dist/shared-tree/schematizeTree.js +1 -0
- package/dist/shared-tree/schematizeTree.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +3 -3
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +5 -1
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +34 -5
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/treeAlpha.d.ts +39 -1
- package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
- package/dist/shared-tree/treeAlpha.js +117 -11
- package/dist/shared-tree/treeAlpha.js.map +1 -1
- package/dist/shared-tree-core/editManagerSummarizer.d.ts +8 -3
- package/dist/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerSummarizer.js +2 -5
- package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts +18 -7
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +15 -2
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/configuration.d.ts +15 -3
- package/dist/simple-tree/api/configuration.d.ts.map +1 -1
- package/dist/simple-tree/api/configuration.js +40 -22
- package/dist/simple-tree/api/configuration.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +1 -1
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +4 -4
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/schemaCompatibilityTester.js +1 -1
- package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.d.ts +3 -3
- package/dist/simple-tree/api/schemaCreationUtilities.js +3 -3
- package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +15 -11
- 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/schemaFactoryAlpha.d.ts +41 -11
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.js +31 -4
- package/dist/simple-tree/api/schemaFactoryAlpha.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/treeChangeEvents.d.ts +8 -3
- package/dist/simple-tree/api/treeChangeEvents.d.ts.map +1 -1
- package/dist/simple-tree/api/treeChangeEvents.js.map +1 -1
- package/dist/simple-tree/api/treeNodeApi.d.ts +3 -0
- package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
- package/dist/simple-tree/api/treeNodeApi.js +1 -1
- package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +5 -0
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/dist/simple-tree/core/context.d.ts +3 -3
- package/dist/simple-tree/core/context.d.ts.map +1 -1
- package/dist/simple-tree/core/context.js.map +1 -1
- package/dist/simple-tree/core/getOrCreateNode.d.ts +9 -0
- package/dist/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
- package/dist/simple-tree/core/getOrCreateNode.js +12 -1
- package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
- package/dist/simple-tree/core/index.d.ts +2 -2
- package/dist/simple-tree/core/index.d.ts.map +1 -1
- package/dist/simple-tree/core/index.js +3 -1
- package/dist/simple-tree/core/index.js.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js +2 -2
- package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.d.ts +68 -1
- package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.js +24 -1
- package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts +5 -9
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js +12 -31
- package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/dist/simple-tree/core/walkSchema.d.ts +3 -3
- package/dist/simple-tree/core/walkSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/walkSchema.js +9 -5
- package/dist/simple-tree/core/walkSchema.js.map +1 -1
- package/dist/simple-tree/createContext.js +1 -1
- package/dist/simple-tree/createContext.js.map +1 -1
- package/dist/simple-tree/getTreeNodeForField.d.ts +1 -1
- package/dist/simple-tree/getTreeNodeForField.d.ts.map +1 -1
- package/dist/simple-tree/getTreeNodeForField.js +3 -3
- package/dist/simple-tree/getTreeNodeForField.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 +8 -5
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/leafNodeSchema.d.ts +4 -1
- package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/leafNodeSchema.js +1 -0
- package/dist/simple-tree/leafNodeSchema.js.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +3 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.js +21 -16
- package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNode.d.ts +3 -2
- package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNode.js +11 -5
- package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts +3 -2
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.js +12 -7
- package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
- package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
- package/dist/simple-tree/prepareForInsertion.js +5 -1
- package/dist/simple-tree/prepareForInsertion.js.map +1 -1
- package/dist/simple-tree/schemaTypes.d.ts +63 -30
- package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
- package/dist/simple-tree/schemaTypes.js +73 -40
- package/dist/simple-tree/schemaTypes.js.map +1 -1
- package/dist/simple-tree/simpleSchema.d.ts +22 -4
- package/dist/simple-tree/simpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/simpleSchema.js.map +1 -1
- package/dist/simple-tree/toStoredSchema.d.ts +4 -0
- package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/dist/simple-tree/toStoredSchema.js +15 -4
- package/dist/simple-tree/toStoredSchema.js.map +1 -1
- package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
- package/dist/simple-tree/treeNodeValid.js +1 -2
- package/dist/simple-tree/treeNodeValid.js.map +1 -1
- package/dist/simple-tree/walkFieldSchema.d.ts.map +1 -1
- package/dist/simple-tree/walkFieldSchema.js +1 -1
- package/dist/simple-tree/walkFieldSchema.js.map +1 -1
- package/dist/tableSchema.d.ts +1 -1
- package/dist/util/typeUtils.d.ts +2 -2
- package/dist/util/typeUtils.js.map +1 -1
- package/dist/util/utils.d.ts +2 -0
- package/dist/util/utils.d.ts.map +1 -1
- package/dist/util/utils.js.map +1 -1
- package/lib/alpha.d.ts +12 -6
- package/lib/beta.d.ts +6 -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/schema-stored/formatV2.d.ts +80 -0
- package/lib/core/schema-stored/formatV2.d.ts.map +1 -0
- package/lib/core/schema-stored/formatV2.js +52 -0
- package/lib/core/schema-stored/formatV2.js.map +1 -0
- package/lib/core/schema-stored/index.d.ts +3 -1
- package/lib/core/schema-stored/index.d.ts.map +1 -1
- package/lib/core/schema-stored/index.js +3 -1
- package/lib/core/schema-stored/index.js.map +1 -1
- package/lib/core/schema-stored/schema.d.ts +49 -17
- package/lib/core/schema-stored/schema.d.ts.map +1 -1
- package/lib/core/schema-stored/schema.js +63 -21
- package/lib/core/schema-stored/schema.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts +9 -7
- package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +11 -7
- package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +3 -3
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +7 -7
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts +1 -1
- package/lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/nodeShape.js +3 -3
- package/lib/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
- package/lib/feature-libraries/detachedFieldIndexSummarizer.d.ts +8 -3
- package/lib/feature-libraries/detachedFieldIndexSummarizer.d.ts.map +1 -1
- package/lib/feature-libraries/detachedFieldIndexSummarizer.js +2 -5
- package/lib/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +24 -25
- 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 +0 -1
- package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/index.js +0 -1
- package/lib/feature-libraries/flex-tree/index.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyEntity.d.ts +2 -2
- package/lib/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyEntity.js +3 -0
- package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.d.ts +1 -2
- package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.js +3 -6
- package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts +5 -5
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.js +15 -7
- package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +8 -3
- package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.js +2 -5
- package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +2 -2
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +1 -1
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/feature-libraries/mapTreeCursor.d.ts +16 -2
- package/lib/feature-libraries/mapTreeCursor.d.ts.map +1 -1
- package/lib/feature-libraries/mapTreeCursor.js.map +1 -1
- package/lib/feature-libraries/modular-schema/fieldKindWithEditor.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/fieldKindWithEditor.js +2 -0
- package/lib/feature-libraries/modular-schema/fieldKindWithEditor.js.map +1 -1
- package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
- package/lib/feature-libraries/object-forest/objectForest.js +2 -0
- package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
- package/lib/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
- package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js +8 -4
- package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
- package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -36
- package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts.map +1 -1
- package/lib/feature-libraries/schema-edits/schemaChangeFormat.js +3 -3
- package/lib/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
- package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
- package/lib/feature-libraries/schema-index/codec.js +60 -10
- package/lib/feature-libraries/schema-index/codec.js.map +1 -1
- package/lib/feature-libraries/schema-index/formatV1.d.ts +1 -1
- package/lib/feature-libraries/schema-index/formatV2.d.ts +42 -0
- package/lib/feature-libraries/schema-index/formatV2.d.ts.map +1 -0
- package/lib/feature-libraries/schema-index/formatV2.js +23 -0
- package/lib/feature-libraries/schema-index/formatV2.js.map +1 -0
- package/lib/feature-libraries/schema-index/index.d.ts +2 -1
- package/lib/feature-libraries/schema-index/index.d.ts.map +1 -1
- package/lib/feature-libraries/schema-index/index.js +2 -1
- package/lib/feature-libraries/schema-index/index.js.map +1 -1
- package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts +7 -2
- package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
- package/lib/feature-libraries/schema-index/schemaSummarizer.js +6 -6
- package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
- package/lib/index.d.ts +2 -2
- 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/shared-tree/schematizeTree.d.ts.map +1 -1
- package/lib/shared-tree/schematizeTree.js +1 -0
- package/lib/shared-tree/schematizeTree.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +4 -4
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +5 -1
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +34 -5
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/treeAlpha.d.ts +39 -1
- package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
- package/lib/shared-tree/treeAlpha.js +111 -5
- package/lib/shared-tree/treeAlpha.js.map +1 -1
- package/lib/shared-tree-core/editManagerSummarizer.d.ts +8 -3
- package/lib/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerSummarizer.js +2 -5
- package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts +18 -7
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +15 -2
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/configuration.d.ts +15 -3
- package/lib/simple-tree/api/configuration.d.ts.map +1 -1
- package/lib/simple-tree/api/configuration.js +42 -24
- package/lib/simple-tree/api/configuration.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +1 -1
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +1 -1
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/schemaCompatibilityTester.js +1 -1
- package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.d.ts +3 -3
- package/lib/simple-tree/api/schemaCreationUtilities.js +3 -3
- package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +15 -11
- 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/schemaFactoryAlpha.d.ts +41 -11
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.js +31 -4
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/lib/simple-tree/api/storedSchema.js +2 -2
- package/lib/simple-tree/api/storedSchema.js.map +1 -1
- package/lib/simple-tree/api/treeChangeEvents.d.ts +8 -3
- package/lib/simple-tree/api/treeChangeEvents.d.ts.map +1 -1
- package/lib/simple-tree/api/treeChangeEvents.js.map +1 -1
- package/lib/simple-tree/api/treeNodeApi.d.ts +3 -0
- package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
- package/lib/simple-tree/api/treeNodeApi.js +2 -2
- package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +5 -0
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/lib/simple-tree/core/context.d.ts +3 -3
- package/lib/simple-tree/core/context.d.ts.map +1 -1
- package/lib/simple-tree/core/context.js.map +1 -1
- package/lib/simple-tree/core/getOrCreateNode.d.ts +9 -0
- package/lib/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
- package/lib/simple-tree/core/getOrCreateNode.js +10 -0
- package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
- package/lib/simple-tree/core/index.d.ts +2 -2
- package/lib/simple-tree/core/index.d.ts.map +1 -1
- package/lib/simple-tree/core/index.js +2 -2
- package/lib/simple-tree/core/index.js.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js +2 -2
- package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.d.ts +68 -1
- package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.js +21 -0
- package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts +5 -9
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js +15 -34
- package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/lib/simple-tree/core/walkSchema.d.ts +3 -3
- package/lib/simple-tree/core/walkSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/walkSchema.js +9 -5
- package/lib/simple-tree/core/walkSchema.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/getTreeNodeForField.d.ts +1 -1
- package/lib/simple-tree/getTreeNodeForField.d.ts.map +1 -1
- package/lib/simple-tree/getTreeNodeForField.js +1 -1
- package/lib/simple-tree/getTreeNodeForField.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 +4 -4
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/leafNodeSchema.d.ts +4 -1
- package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/leafNodeSchema.js +2 -1
- package/lib/simple-tree/leafNodeSchema.js.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +3 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.js +13 -8
- package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNode.d.ts +3 -2
- package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNode.js +14 -8
- package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts +3 -2
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.js +14 -9
- package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
- package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
- package/lib/simple-tree/prepareForInsertion.js +5 -1
- package/lib/simple-tree/prepareForInsertion.js.map +1 -1
- package/lib/simple-tree/schemaTypes.d.ts +63 -30
- package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
- package/lib/simple-tree/schemaTypes.js +70 -36
- package/lib/simple-tree/schemaTypes.js.map +1 -1
- package/lib/simple-tree/simpleSchema.d.ts +22 -4
- package/lib/simple-tree/simpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/simpleSchema.js.map +1 -1
- package/lib/simple-tree/toStoredSchema.d.ts +4 -0
- package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/lib/simple-tree/toStoredSchema.js +15 -4
- package/lib/simple-tree/toStoredSchema.js.map +1 -1
- package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
- package/lib/simple-tree/treeNodeValid.js +1 -2
- package/lib/simple-tree/treeNodeValid.js.map +1 -1
- package/lib/simple-tree/walkFieldSchema.d.ts.map +1 -1
- package/lib/simple-tree/walkFieldSchema.js +1 -1
- package/lib/simple-tree/walkFieldSchema.js.map +1 -1
- package/lib/tableSchema.d.ts +1 -1
- package/lib/util/typeUtils.d.ts +2 -2
- package/lib/util/typeUtils.js.map +1 -1
- package/lib/util/utils.d.ts +2 -0
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js.map +1 -1
- package/package.json +23 -23
- package/src/core/index.ts +3 -1
- package/src/core/schema-stored/formatV2.ts +78 -0
- package/src/core/schema-stored/index.ts +4 -1
- package/src/core/schema-stored/schema.ts +123 -33
- package/src/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.ts +16 -11
- package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +16 -7
- package/src/feature-libraries/chunked-forest/codec/nodeShape.ts +4 -4
- package/src/feature-libraries/detachedFieldIndexSummarizer.ts +9 -16
- package/src/feature-libraries/flex-tree/flexTreeTypes.ts +33 -30
- package/src/feature-libraries/flex-tree/index.ts +0 -8
- package/src/feature-libraries/flex-tree/lazyEntity.ts +5 -1
- package/src/feature-libraries/flex-tree/lazyField.ts +5 -8
- package/src/feature-libraries/flex-tree/lazyNode.ts +17 -8
- package/src/feature-libraries/forest-summary/forestSummarizer.ts +9 -16
- package/src/feature-libraries/index.ts +1 -1
- package/src/feature-libraries/mapTreeCursor.ts +17 -8
- package/src/feature-libraries/modular-schema/fieldKindWithEditor.ts +2 -0
- package/src/feature-libraries/object-forest/objectForest.ts +3 -0
- package/src/feature-libraries/schema-edits/schemaChangeCodecs.ts +11 -6
- package/src/feature-libraries/schema-edits/schemaChangeFormat.ts +3 -3
- package/src/feature-libraries/schema-index/codec.ts +73 -14
- package/src/feature-libraries/schema-index/formatV2.ts +30 -0
- package/src/feature-libraries/schema-index/index.ts +2 -1
- package/src/feature-libraries/schema-index/schemaSummarizer.ts +11 -18
- package/src/index.ts +6 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/schematizeTree.ts +1 -0
- package/src/shared-tree/schematizingTreeView.ts +8 -5
- package/src/shared-tree/sharedTree.ts +42 -12
- package/src/shared-tree/treeAlpha.ts +196 -6
- package/src/shared-tree-core/editManagerSummarizer.ts +9 -16
- package/src/shared-tree-core/sharedTreeCore.ts +33 -24
- package/src/simple-tree/api/configuration.ts +59 -27
- package/src/simple-tree/api/index.ts +3 -3
- package/src/simple-tree/api/schemaCompatibilityTester.ts +1 -1
- package/src/simple-tree/api/schemaCreationUtilities.ts +3 -3
- package/src/simple-tree/api/schemaFactory.ts +16 -11
- package/src/simple-tree/api/schemaFactoryAlpha.ts +53 -8
- package/src/simple-tree/api/storedSchema.ts +4 -4
- package/src/simple-tree/api/treeChangeEvents.ts +8 -3
- package/src/simple-tree/api/treeNodeApi.ts +5 -2
- package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +5 -0
- package/src/simple-tree/core/context.ts +3 -3
- package/src/simple-tree/core/getOrCreateNode.ts +14 -0
- package/src/simple-tree/core/index.ts +7 -1
- package/src/simple-tree/core/treeNodeKernel.ts +2 -2
- package/src/simple-tree/core/treeNodeSchema.ts +113 -1
- package/src/simple-tree/core/unhydratedFlexTree.ts +22 -44
- package/src/simple-tree/core/walkSchema.ts +16 -7
- package/src/simple-tree/createContext.ts +1 -1
- package/src/simple-tree/getTreeNodeForField.ts +3 -1
- package/src/simple-tree/index.ts +12 -5
- package/src/simple-tree/leafNodeSchema.ts +9 -1
- package/src/simple-tree/node-kinds/array/arrayNode.ts +20 -9
- package/src/simple-tree/node-kinds/map/mapNode.ts +21 -6
- package/src/simple-tree/node-kinds/object/objectNode.ts +29 -12
- package/src/simple-tree/prepareForInsertion.ts +5 -1
- package/src/simple-tree/schemaTypes.ts +151 -71
- package/src/simple-tree/simpleSchema.ts +27 -5
- package/src/simple-tree/toStoredSchema.ts +17 -4
- package/src/simple-tree/treeNodeValid.ts +1 -1
- package/src/simple-tree/walkFieldSchema.ts +5 -1
- package/src/util/typeUtils.ts +2 -2
- package/src/util/utils.ts +2 -0
- package/dist/feature-libraries/flex-tree/navigation.d.ts +0 -46
- package/dist/feature-libraries/flex-tree/navigation.d.ts.map +0 -1
- package/dist/feature-libraries/flex-tree/navigation.js +0 -104
- package/dist/feature-libraries/flex-tree/navigation.js.map +0 -1
- package/lib/feature-libraries/flex-tree/navigation.d.ts +0 -46
- package/lib/feature-libraries/flex-tree/navigation.d.ts.map +0 -1
- package/lib/feature-libraries/flex-tree/navigation.js +0 -97
- package/lib/feature-libraries/flex-tree/navigation.js.map +0 -1
- package/src/feature-libraries/flex-tree/navigation.ts +0 -121
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedTreeCore.js","sourceRoot":"","sources":["../../src/shared-tree-core/sharedTreeCore.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAS7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAK5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAG7E,OAAO,EAGN,YAAY,EAGZ,gBAAgB,GAKhB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEN,KAAK,EAGL,aAAa,EACb,aAAa,GACb,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAuC,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BA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ft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidLoadable, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type { IIdCompressor, SessionId } from \"@fluidframework/id-compressor\";\nimport type {\n\tIExperimentalIncrementalSummaryContext,\n\tIRuntimeMessageCollection,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport type {\n\tIChannelView,\n\tIFluidSerializer,\n} from \"@fluidframework/shared-object-base/internal\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ICodecOptions, IJsonCodec } from \"../codec/index.js\";\nimport {\n\ttype ChangeFamily,\n\ttype ChangeFamilyEditor,\n\tfindAncestor,\n\ttype GraphCommit,\n\ttype RevisionTag,\n\tRevisionTagCodec,\n\ttype SchemaAndPolicy,\n\ttype SchemaPolicy,\n\ttype TaggedChange,\n\ttype TreeStoredSchemaRepository,\n} from \"../core/index.js\";\nimport {\n\ttype JsonCompatibleReadOnly,\n\tbrand,\n\ttype Breakable,\n\ttype WithBreakable,\n\tthrowIfBroken,\n\tbreakingClass,\n} from \"../util/index.js\";\n\nimport type { SharedTreeBranch } from \"./branch.js\";\nimport { BranchCommitEnricher } from \"./branchCommitEnricher.js\";\nimport { type ChangeEnricherReadonlyCheckout, NoOpChangeEnricher } from \"./changeEnricher.js\";\nimport { DefaultResubmitMachine } from \"./defaultResubmitMachine.js\";\nimport { EditManager, minimumPossibleSequenceNumber } from \"./editManager.js\";\nimport { makeEditManagerCodec } from \"./editManagerCodecs.js\";\nimport type { SeqNumber } from \"./editManagerFormat.js\";\nimport { EditManagerSummarizer } from \"./editManagerSummarizer.js\";\nimport { type MessageEncodingContext, makeMessageCodec } from \"./messageCodecs.js\";\nimport type { DecodedMessage } from \"./messageTypes.js\";\nimport type { ResubmitMachine } from \"./resubmitMachine.js\";\n\n// TODO: Organize this to be adjacent to persisted types.\nconst summarizablesTreeKey = \"indexes\";\n\nexport interface ExplicitCoreCodecVersions {\n\teditManager: number;\n\tmessage: number;\n}\n\nexport interface ClonableSchemaAndPolicy extends SchemaAndPolicy {\n\tschema: TreeStoredSchemaRepository;\n}\n\n/**\n * Generic shared tree, which needs to be configured with indexes, field kinds and other configuration.\n */\n@breakingClass\nexport class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>\n\timplements WithBreakable\n{\n\tprivate readonly editManager: EditManager<TEditor, TChange, ChangeFamily<TEditor, TChange>>;\n\tprivate readonly summarizables: readonly [EditManagerSummarizer<TChange>, ...Summarizable[]];\n\t/**\n\t * The sequence number that this instance is at.\n\t * This number is artificial in that it is made up by this instance as opposed to being provided by the runtime.\n\t * Is `undefined` after (and only after) this instance is attached.\n\t */\n\tprivate detachedRevision: SeqNumber | undefined = minimumPossibleSequenceNumber;\n\n\t/**\n\t * Used to encode/decode messages sent to/received from the Fluid runtime.\n\t *\n\t * @remarks Since there is currently only one format, this can just be cached on the class.\n\t * With more write formats active, it may make sense to keep around the \"usual\" format codec\n\t * (the one for the current persisted configuration) and resolve codecs for different versions\n\t * as necessary (e.g. an upgrade op came in, or the configuration changed within the collab window\n\t * and an op needs to be interpreted which isn't written with the current configuration).\n\t */\n\tprivate readonly messageCodec: IJsonCodec<\n\t\tDecodedMessage<TChange>,\n\t\tunknown,\n\t\tunknown,\n\t\tMessageEncodingContext\n\t>;\n\n\tprivate readonly resubmitMachine: ResubmitMachine<TChange>;\n\tpublic readonly commitEnricher: BranchCommitEnricher<TChange>;\n\n\tpublic readonly mintRevisionTag: () => RevisionTag;\n\n\tprivate readonly schemaAndPolicy: ClonableSchemaAndPolicy;\n\n\t/**\n\t * @param summarizables - Summarizers for all indexes used by this tree\n\t * @param changeFamily - The change family\n\t * @param editManager - The edit manager\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param editor - Used to edit the state of the tree. Edits will be immediately applied locally to the tree.\n\t * If there is no transaction currently ongoing, then the edits will be submitted to Fluid immediately as well.\n\t */\n\tpublic constructor(\n\t\tpublic readonly breaker: Breakable,\n\t\tpublic readonly sharedObject: IChannelView & IFluidLoadable,\n\t\tpublic readonly serializer: IFluidSerializer,\n\t\tpublic readonly submitLocalMessage: (content: unknown, localOpMetadata?: unknown) => void,\n\t\tlogger: ITelemetryBaseLogger | undefined,\n\t\tsummarizables: readonly Summarizable[],\n\t\tchangeFamily: ChangeFamily<TEditor, TChange>,\n\t\toptions: ICodecOptions,\n\t\tformatOptions: ExplicitCoreCodecVersions,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t\tschema: TreeStoredSchemaRepository,\n\t\tschemaPolicy: SchemaPolicy,\n\t\tresubmitMachine?: ResubmitMachine<TChange>,\n\t\tenricher?: ChangeEnricherReadonlyCheckout<TChange>,\n\t\tpublic readonly getEditor: () => TEditor = () => this.getLocalBranch().editor,\n\t) {\n\t\tthis.schemaAndPolicy = {\n\t\t\tschema,\n\t\t\tpolicy: schemaPolicy,\n\t\t};\n\n\t\tconst rebaseLogger = createChildLogger({\n\t\t\tlogger,\n\t\t\tnamespace: \"Rebase\",\n\t\t});\n\n\t\tthis.mintRevisionTag = () => this.idCompressor.generateCompressedId();\n\t\t/**\n\t\t * A random ID that uniquely identifies this client in the collab session.\n\t\t * This is sent alongside every op to identify which client the op originated from.\n\t\t * This is used rather than the Fluid client ID because the Fluid client ID is not stable across reconnections.\n\t\t */\n\t\tconst localSessionId = idCompressor.localSessionId;\n\t\tthis.editManager = new EditManager(\n\t\t\tchangeFamily,\n\t\t\tlocalSessionId,\n\t\t\tthis.mintRevisionTag,\n\t\t\trebaseLogger,\n\t\t);\n\n\t\tthis.editManager.localBranch.events.on(\"beforeChange\", (change) => {\n\t\t\tif (this.detachedRevision === undefined) {\n\t\t\t\t// Commit enrichment is only necessary for changes that will be submitted as ops, and changes issued while detached are not submitted.\n\t\t\t\tthis.commitEnricher.processChange(change);\n\t\t\t}\n\t\t\tif (change.type === \"append\") {\n\t\t\t\tfor (const commit of change.newCommits) {\n\t\t\t\t\tthis.submitCommit(commit, this.schemaAndPolicy, false);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tconst revisionTagCodec = new RevisionTagCodec(idCompressor);\n\t\tconst editManagerCodec = makeEditManagerCodec(\n\t\t\tthis.editManager.changeFamily.codecs,\n\t\t\trevisionTagCodec,\n\t\t\toptions,\n\t\t\tformatOptions.editManager,\n\t\t);\n\t\tthis.summarizables = [\n\t\t\tnew EditManagerSummarizer(\n\t\t\t\tthis.editManager,\n\t\t\t\teditManagerCodec,\n\t\t\t\tthis.idCompressor,\n\t\t\t\tthis.schemaAndPolicy,\n\t\t\t),\n\t\t\t...summarizables,\n\t\t];\n\t\tassert(\n\t\t\tnew Set(this.summarizables.map((e) => e.key)).size === this.summarizables.length,\n\t\t\t0x350 /* Index summary element keys must be unique */,\n\t\t);\n\n\t\tthis.messageCodec = makeMessageCodec(\n\t\t\tchangeFamily.codecs,\n\t\t\tnew RevisionTagCodec(idCompressor),\n\t\t\toptions,\n\t\t\tformatOptions.message,\n\t\t);\n\n\t\tconst changeEnricher = enricher ?? new NoOpChangeEnricher();\n\t\tthis.resubmitMachine =\n\t\t\tresubmitMachine ??\n\t\t\tnew DefaultResubmitMachine(\n\t\t\t\t(change: TaggedChange<TChange>) =>\n\t\t\t\t\tchangeFamily.rebaser.invert(change, true, this.mintRevisionTag()),\n\t\t\t\tchangeEnricher,\n\t\t\t);\n\t\tthis.commitEnricher = new BranchCommitEnricher(changeFamily.rebaser, changeEnricher);\n\t}\n\n\t// TODO: SharedObject's merging of the two summary methods into summarizeCore is not what we want here:\n\t// We might want to not subclass it, or override/reimplement most of its functionality.\n\t@throwIfBroken\n\tpublic summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tconst summarizableBuilder = new SummaryTreeBuilder();\n\t\t// Merge the summaries of all summarizables together under a single ISummaryTree\n\t\tfor (const s of this.summarizables) {\n\t\t\tsummarizableBuilder.addWithStats(\n\t\t\t\ts.key,\n\t\t\t\ts.getAttachSummary(\n\t\t\t\t\t(contents) => serializer.stringify(contents, this.sharedObject.handle),\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\ttelemetryContext,\n\t\t\t\t\tincrementalSummaryContext,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tbuilder.addWithStats(summarizablesTreeKey, summarizableBuilder.getSummaryTree());\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic async loadCore(services: IChannelStorageService): Promise<void> {\n\t\tassert(\n\t\t\tthis.editManager.localBranch.getHead() === this.editManager.getTrunkHead(),\n\t\t\t0xaaa /* All local changes should be applied to the trunk before loading from summary */,\n\t\t);\n\t\tconst [editManagerSummarizer, ...summarizables] = this.summarizables;\n\t\tconst loadEditManager = this.loadSummarizable(editManagerSummarizer, services);\n\t\tconst loadSummarizables = summarizables.map(async (s) =>\n\t\t\tthis.loadSummarizable(s, services),\n\t\t);\n\n\t\tif (this.detachedRevision !== undefined) {\n\t\t\t// If we are detached but loading from a summary, then we need to update our detached revision to ensure that it is ahead of all detached revisions in the summary.\n\t\t\t// First, finish loading the edit manager so that we can inspect the sequence numbers of the commits on the trunk.\n\t\t\tawait loadEditManager;\n\t\t\t// Find the most recent detached revision in the summary trunk...\n\t\t\tlet latestDetachedSequenceNumber: SeqNumber | undefined;\n\t\t\tfindAncestor(this.editManager.getTrunkHead(), (c) => {\n\t\t\t\tconst sequenceNumber = this.editManager.getSequenceNumber(c);\n\t\t\t\tif (sequenceNumber !== undefined && sequenceNumber < 0) {\n\t\t\t\t\tlatestDetachedSequenceNumber = sequenceNumber;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t});\n\t\t\t// ...and set our detached revision to be as it would be if we had been already created that revision.\n\t\t\tthis.detachedRevision = latestDetachedSequenceNumber ?? this.detachedRevision;\n\t\t\tawait Promise.all(loadSummarizables);\n\t\t} else {\n\t\t\tawait Promise.all([loadEditManager, ...loadSummarizables]);\n\t\t}\n\t}\n\n\tprivate async loadSummarizable(\n\t\tsummarizable: Summarizable,\n\t\tservices: IChannelStorageService,\n\t): Promise<void> {\n\t\treturn summarizable.load(\n\t\t\tscopeStorageService(services, summarizablesTreeKey, summarizable.key),\n\t\t\t(contents) => this.serializer.parse(contents),\n\t\t);\n\t}\n\n\t/**\n\t * Submits an op to the Fluid runtime containing the given commit\n\t * @param commit - the commit to submit\n\t * @returns the submitted commit. This is undefined if the underlying `SharedObject` is not attached,\n\t * and may differ from `commit` due to enrichments like detached tree refreshers.\n\t */\n\tprotected submitCommit(\n\t\tcommit: GraphCommit<TChange>,\n\t\tschemaAndPolicy: ClonableSchemaAndPolicy,\n\t\tisResubmit: boolean,\n\t): void {\n\t\tassert(\n\t\t\tthis.sharedObject.isAttached() === (this.detachedRevision === undefined),\n\t\t\t0x95a /* Detached revision should only be set when not attached */,\n\t\t);\n\n\t\tconst enrichedCommit =\n\t\t\tthis.detachedRevision === undefined && !isResubmit\n\t\t\t\t? this.commitEnricher.enrich(commit)\n\t\t\t\t: commit;\n\n\t\t// Edits submitted before the first attach are treated as sequenced because they will be included\n\t\t// in the attach summary that is uploaded to the service.\n\t\t// Until this attach workflow happens, this instance essentially behaves as a centralized data structure.\n\t\tif (this.detachedRevision !== undefined) {\n\t\t\tconst newRevision: SeqNumber = brand((this.detachedRevision as number) + 1);\n\t\t\tthis.detachedRevision = newRevision;\n\t\t\tthis.editManager.addSequencedChanges(\n\t\t\t\t[enrichedCommit],\n\t\t\t\tthis.editManager.localSessionId,\n\t\t\t\tnewRevision,\n\t\t\t\tthis.detachedRevision,\n\t\t\t);\n\t\t\tthis.editManager.advanceMinimumSequenceNumber(newRevision, false);\n\t\t\treturn undefined;\n\t\t}\n\t\tconst message = this.messageCodec.encode(\n\t\t\t{\n\t\t\t\tcommit: enrichedCommit,\n\t\t\t\tsessionId: this.editManager.localSessionId,\n\t\t\t},\n\t\t\t{\n\t\t\t\tidCompressor: this.idCompressor,\n\t\t\t\tschema: schemaAndPolicy,\n\t\t\t},\n\t\t);\n\t\tthis.submitLocalMessage(message, {\n\t\t\t// Clone the schema to ensure that during resubmit the schema has not been mutated by later changes\n\t\t\tschema: schemaAndPolicy.schema.clone(),\n\t\t\tpolicy: schemaAndPolicy.policy,\n\t\t});\n\t\tthis.resubmitMachine.onCommitSubmitted(enrichedCommit);\n\t}\n\n\t/**\n\t * Process a bunch of messages from the runtime. SharedObject will call this method with a bunch of messages.\n\t */\n\tpublic processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tconst { envelope, local, messagesContent } = messagesCollection;\n\t\tconst commits: GraphCommit<TChange>[] = [];\n\t\tlet messagesSessionId: SessionId | undefined;\n\n\t\t// Get a list of all the commits from the messages.\n\t\tfor (const messageContent of messagesContent) {\n\t\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\t\tconst { commit, sessionId } = this.messageCodec.decode(messageContent.contents, {\n\t\t\t\tidCompressor: this.idCompressor,\n\t\t\t});\n\t\t\tcommits.push(commit);\n\n\t\t\tif (messagesSessionId !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tmessagesSessionId === sessionId,\n\t\t\t\t\t0xad9 /* All messages in a bunch must have the same session ID */,\n\t\t\t\t);\n\t\t\t}\n\t\t\tmessagesSessionId = sessionId;\n\t\t}\n\n\t\tassert(messagesSessionId !== undefined, 0xada /* Messages must have a session ID */);\n\n\t\tthis.editManager.addSequencedChanges(\n\t\t\tcommits,\n\t\t\tmessagesSessionId,\n\t\t\tbrand(envelope.sequenceNumber),\n\t\t\tbrand(envelope.referenceSequenceNumber),\n\t\t);\n\n\t\t// Update the resubmit machine for each commit applied.\n\t\tfor (const _ of messagesContent) {\n\t\t\tthis.resubmitMachine.onSequencedCommitApplied(local);\n\t\t}\n\n\t\tthis.editManager.advanceMinimumSequenceNumber(brand(envelope.minimumSequenceNumber));\n\t}\n\n\tpublic getLocalBranch(): SharedTreeBranch<TEditor, TChange> {\n\t\treturn this.editManager.localBranch;\n\t}\n\n\tpublic didAttach(): void {\n\t\tthis.detachedRevision = undefined;\n\t}\n\n\tpublic reSubmitCore(content: JsonCompatibleReadOnly, localOpMetadata: unknown): void {\n\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\tconst {\n\t\t\tcommit: { revision },\n\t\t} = this.messageCodec.decode(this.serializer.decode(content), {\n\t\t\tidCompressor: this.idCompressor,\n\t\t});\n\t\tconst [commit] = this.editManager.findLocalCommit(revision);\n\t\t// If a resubmit phase is not already in progress, then this must be the first commit of a new resubmit phase.\n\t\tif (this.resubmitMachine.isInResubmitPhase === false) {\n\t\t\tconst toResubmit = this.editManager.getLocalCommits();\n\t\t\tassert(\n\t\t\t\tcommit === toResubmit[0],\n\t\t\t\t0x95d /* Resubmit phase should start with the oldest local commit */,\n\t\t\t);\n\t\t\tthis.resubmitMachine.prepareForResubmit(toResubmit);\n\t\t}\n\t\tassert(\n\t\t\tisClonableSchemaPolicy(localOpMetadata),\n\t\t\t0x95e /* Local metadata must contain schema and policy. */,\n\t\t);\n\t\tassert(\n\t\t\tthis.resubmitMachine.isInResubmitPhase !== false,\n\t\t\t0x984 /* Invalid resubmit outside of resubmit phase */,\n\t\t);\n\t\tconst enrichedCommit = this.resubmitMachine.peekNextCommit();\n\t\tthis.submitCommit(enrichedCommit, localOpMetadata, true);\n\t}\n\n\tpublic applyStashedOp(content: JsonCompatibleReadOnly): void {\n\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\tconst {\n\t\t\tcommit: { revision, change },\n\t\t} = this.messageCodec.decode(content, { idCompressor: this.idCompressor });\n\t\tthis.editManager.localBranch.apply({ change, revision });\n\t}\n}\n\nfunction isClonableSchemaPolicy(\n\tmaybeSchemaPolicy: unknown,\n): maybeSchemaPolicy is ClonableSchemaAndPolicy {\n\tconst schemaAndPolicy = maybeSchemaPolicy as ClonableSchemaAndPolicy;\n\treturn schemaAndPolicy.schema !== undefined && schemaAndPolicy.policy !== undefined;\n}\n\n/**\n * Specifies the behavior of a component that puts data in a summary.\n */\nexport interface Summarizable {\n\t/**\n\t * Field name in summary json under which this element stores its data.\n\t */\n\treadonly key: string;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t * @param stringify - Serializes the contents of the component (including {@link (IFluidHandle:interface)}s) for storage.\n\t */\n\tgetAttachSummary(\n\t\tstringify: SummaryElementStringifier,\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t * @param stringify - Serializes the contents of the component (including {@link (IFluidHandle:interface)}s) for storage.\n\t */\n\tsummarize(\n\t\tstringify: SummaryElementStringifier,\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): Promise<ISummaryTreeWithStats>;\n\n\t/**\n\t * Allows the component to perform custom loading. The storage service is scoped to this component and therefore\n\t * paths in this component will not collide with those in other components, even if they are the same string.\n\t * @param service - Storage used by the component\n\t * @param parse - Parses serialized data from storage into runtime objects for the component\n\t */\n\tload(service: IChannelStorageService, parse: SummaryElementParser): Promise<void>;\n}\n\n/**\n * Serializes the given contents into a string acceptable for storing in summaries, i.e. all\n * Fluid handles have been replaced appropriately by an IFluidSerializer\n */\nexport type SummaryElementStringifier = (contents: unknown) => string;\n\n/**\n * Parses a serialized/summarized string into an object, rehydrating any Fluid handles as necessary\n */\nexport type SummaryElementParser = (contents: string) => unknown;\n\n/**\n * Compose an {@link IChannelStorageService} which prefixes all paths before forwarding them to the original service\n */\nfunction scopeStorageService(\n\tservice: IChannelStorageService,\n\t...pathElements: string[]\n): IChannelStorageService {\n\tconst scope = `${pathElements.join(\"/\")}/`;\n\n\treturn {\n\t\tasync readBlob(path: string): Promise<ArrayBufferLike> {\n\t\t\treturn service.readBlob(`${scope}${path}`);\n\t\t},\n\t\tasync contains(path) {\n\t\t\treturn service.contains(`${scope}${path}`);\n\t\t},\n\t\tasync list(path) {\n\t\t\treturn service.list(`${scope}${path}`);\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sharedTreeCore.js","sourceRoot":"","sources":["../../src/shared-tree-core/sharedTreeCore.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAS7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAK5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAG7E,OAAO,EAGN,YAAY,EAGZ,gBAAgB,GAKhB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEN,KAAK,EAGL,aAAa,EACb,aAAa,GACb,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAuC,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAA+B,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAInF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,GAAG,IAAI,EAAE,CAAC,CAAC;QAC5C,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,IAAI;YACd,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,GAAG,IAAI,EAAE,CAAC,CAAC;QACxC,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidLoadable, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type { IIdCompressor, SessionId } from \"@fluidframework/id-compressor\";\nimport type {\n\tIExperimentalIncrementalSummaryContext,\n\tIRuntimeMessageCollection,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport type {\n\tIChannelView,\n\tIFluidSerializer,\n} from \"@fluidframework/shared-object-base/internal\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { ICodecOptions, IJsonCodec } from \"../codec/index.js\";\nimport {\n\ttype ChangeFamily,\n\ttype ChangeFamilyEditor,\n\tfindAncestor,\n\ttype GraphCommit,\n\ttype RevisionTag,\n\tRevisionTagCodec,\n\ttype SchemaAndPolicy,\n\ttype SchemaPolicy,\n\ttype TaggedChange,\n\ttype TreeStoredSchemaRepository,\n} from \"../core/index.js\";\nimport {\n\ttype JsonCompatibleReadOnly,\n\tbrand,\n\ttype Breakable,\n\ttype WithBreakable,\n\tthrowIfBroken,\n\tbreakingClass,\n} from \"../util/index.js\";\n\nimport type { SharedTreeBranch } from \"./branch.js\";\nimport { BranchCommitEnricher } from \"./branchCommitEnricher.js\";\nimport { type ChangeEnricherReadonlyCheckout, NoOpChangeEnricher } from \"./changeEnricher.js\";\nimport { DefaultResubmitMachine } from \"./defaultResubmitMachine.js\";\nimport { EditManager, minimumPossibleSequenceNumber } from \"./editManager.js\";\nimport { makeEditManagerCodec } from \"./editManagerCodecs.js\";\nimport type { SeqNumber } from \"./editManagerFormat.js\";\nimport { EditManagerSummarizer } from \"./editManagerSummarizer.js\";\nimport { type MessageEncodingContext, makeMessageCodec } from \"./messageCodecs.js\";\nimport type { DecodedMessage } from \"./messageTypes.js\";\nimport type { ResubmitMachine } from \"./resubmitMachine.js\";\n\n// TODO: Organize this to be adjacent to persisted types.\nconst summarizablesTreeKey = \"indexes\";\n\nexport interface ExplicitCoreCodecVersions {\n\teditManager: number;\n\tmessage: number;\n}\n\nexport interface ClonableSchemaAndPolicy extends SchemaAndPolicy {\n\tschema: TreeStoredSchemaRepository;\n}\n\n/**\n * Generic shared tree, which needs to be configured with indexes, field kinds and other configuration.\n */\n@breakingClass\nexport class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>\n\timplements WithBreakable\n{\n\tprivate readonly editManager: EditManager<TEditor, TChange, ChangeFamily<TEditor, TChange>>;\n\tprivate readonly summarizables: readonly [EditManagerSummarizer<TChange>, ...Summarizable[]];\n\t/**\n\t * The sequence number that this instance is at.\n\t * This number is artificial in that it is made up by this instance as opposed to being provided by the runtime.\n\t * Is `undefined` after (and only after) this instance is attached.\n\t */\n\tprivate detachedRevision: SeqNumber | undefined = minimumPossibleSequenceNumber;\n\n\t/**\n\t * Used to encode/decode messages sent to/received from the Fluid runtime.\n\t *\n\t * @remarks Since there is currently only one format, this can just be cached on the class.\n\t * With more write formats active, it may make sense to keep around the \"usual\" format codec\n\t * (the one for the current persisted configuration) and resolve codecs for different versions\n\t * as necessary (e.g. an upgrade op came in, or the configuration changed within the collab window\n\t * and an op needs to be interpreted which isn't written with the current configuration).\n\t */\n\tprivate readonly messageCodec: IJsonCodec<\n\t\tDecodedMessage<TChange>,\n\t\tunknown,\n\t\tunknown,\n\t\tMessageEncodingContext\n\t>;\n\n\tprivate readonly resubmitMachine: ResubmitMachine<TChange>;\n\tpublic readonly commitEnricher: BranchCommitEnricher<TChange>;\n\n\tpublic readonly mintRevisionTag: () => RevisionTag;\n\n\tprivate readonly schemaAndPolicy: ClonableSchemaAndPolicy;\n\n\t/**\n\t * @param summarizables - Summarizers for all indexes used by this tree\n\t * @param changeFamily - The change family\n\t * @param editManager - The edit manager\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param editor - Used to edit the state of the tree. Edits will be immediately applied locally to the tree.\n\t * If there is no transaction currently ongoing, then the edits will be submitted to Fluid immediately as well.\n\t */\n\tpublic constructor(\n\t\tpublic readonly breaker: Breakable,\n\t\tpublic readonly sharedObject: IChannelView & IFluidLoadable,\n\t\tpublic readonly serializer: IFluidSerializer,\n\t\tpublic readonly submitLocalMessage: (content: unknown, localOpMetadata?: unknown) => void,\n\t\tlogger: ITelemetryBaseLogger | undefined,\n\t\tsummarizables: readonly Summarizable[],\n\t\tchangeFamily: ChangeFamily<TEditor, TChange>,\n\t\toptions: ICodecOptions,\n\t\tformatOptions: ExplicitCoreCodecVersions,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t\tschema: TreeStoredSchemaRepository,\n\t\tschemaPolicy: SchemaPolicy,\n\t\tresubmitMachine?: ResubmitMachine<TChange>,\n\t\tenricher?: ChangeEnricherReadonlyCheckout<TChange>,\n\t\tpublic readonly getEditor: () => TEditor = () => this.getLocalBranch().editor,\n\t) {\n\t\tthis.schemaAndPolicy = {\n\t\t\tschema,\n\t\t\tpolicy: schemaPolicy,\n\t\t};\n\n\t\tconst rebaseLogger = createChildLogger({\n\t\t\tlogger,\n\t\t\tnamespace: \"Rebase\",\n\t\t});\n\n\t\tthis.mintRevisionTag = () => this.idCompressor.generateCompressedId();\n\t\t/**\n\t\t * A random ID that uniquely identifies this client in the collab session.\n\t\t * This is sent alongside every op to identify which client the op originated from.\n\t\t * This is used rather than the Fluid client ID because the Fluid client ID is not stable across reconnections.\n\t\t */\n\t\tconst localSessionId = idCompressor.localSessionId;\n\t\tthis.editManager = new EditManager(\n\t\t\tchangeFamily,\n\t\t\tlocalSessionId,\n\t\t\tthis.mintRevisionTag,\n\t\t\trebaseLogger,\n\t\t);\n\n\t\tthis.editManager.localBranch.events.on(\"beforeChange\", (change) => {\n\t\t\tif (this.detachedRevision === undefined) {\n\t\t\t\t// Commit enrichment is only necessary for changes that will be submitted as ops, and changes issued while detached are not submitted.\n\t\t\t\tthis.commitEnricher.processChange(change);\n\t\t\t}\n\t\t\tif (change.type === \"append\") {\n\t\t\t\tfor (const commit of change.newCommits) {\n\t\t\t\t\tthis.submitCommit(commit, this.schemaAndPolicy, false);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tconst revisionTagCodec = new RevisionTagCodec(idCompressor);\n\t\tconst editManagerCodec = makeEditManagerCodec(\n\t\t\tthis.editManager.changeFamily.codecs,\n\t\t\trevisionTagCodec,\n\t\t\toptions,\n\t\t\tformatOptions.editManager,\n\t\t);\n\t\tthis.summarizables = [\n\t\t\tnew EditManagerSummarizer(\n\t\t\t\tthis.editManager,\n\t\t\t\teditManagerCodec,\n\t\t\t\tthis.idCompressor,\n\t\t\t\tthis.schemaAndPolicy,\n\t\t\t),\n\t\t\t...summarizables,\n\t\t];\n\t\tassert(\n\t\t\tnew Set(this.summarizables.map((e) => e.key)).size === this.summarizables.length,\n\t\t\t0x350 /* Index summary element keys must be unique */,\n\t\t);\n\n\t\tthis.messageCodec = makeMessageCodec(\n\t\t\tchangeFamily.codecs,\n\t\t\tnew RevisionTagCodec(idCompressor),\n\t\t\toptions,\n\t\t\tformatOptions.message,\n\t\t);\n\n\t\tconst changeEnricher = enricher ?? new NoOpChangeEnricher();\n\t\tthis.resubmitMachine =\n\t\t\tresubmitMachine ??\n\t\t\tnew DefaultResubmitMachine(\n\t\t\t\t(change: TaggedChange<TChange>) =>\n\t\t\t\t\tchangeFamily.rebaser.invert(change, true, this.mintRevisionTag()),\n\t\t\t\tchangeEnricher,\n\t\t\t);\n\t\tthis.commitEnricher = new BranchCommitEnricher(changeFamily.rebaser, changeEnricher);\n\t}\n\n\t// TODO: SharedObject's merging of the two summary methods into summarizeCore is not what we want here:\n\t// We might want to not subclass it, or override/reimplement most of its functionality.\n\t@throwIfBroken\n\tpublic summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t\tfullTree?: boolean,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tconst summarizableBuilder = new SummaryTreeBuilder();\n\t\t// Merge the summaries of all summarizables together under a single ISummaryTree\n\t\tfor (const s of this.summarizables) {\n\t\t\t// Add the summarizable's path in the summary tree to the incremental summary context's\n\t\t\t// summary path, so that the summarizable can use it to generate incremental summaries.\n\t\t\tconst childIncrementalSummaryContext =\n\t\t\t\tincrementalSummaryContext === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: {\n\t\t\t\t\t\t\t...incrementalSummaryContext,\n\t\t\t\t\t\t\tsummaryPath: `${incrementalSummaryContext.summaryPath}/${summarizablesTreeKey}/${s.key}`,\n\t\t\t\t\t\t};\n\t\t\tsummarizableBuilder.addWithStats(\n\t\t\t\ts.key,\n\t\t\t\ts.summarize({\n\t\t\t\t\tstringify: (contents: unknown) =>\n\t\t\t\t\t\tserializer.stringify(contents, this.sharedObject.handle),\n\t\t\t\t\tfullTree,\n\t\t\t\t\ttelemetryContext,\n\t\t\t\t\tincrementalSummaryContext: childIncrementalSummaryContext,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tbuilder.addWithStats(summarizablesTreeKey, summarizableBuilder.getSummaryTree());\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic async loadCore(services: IChannelStorageService): Promise<void> {\n\t\tassert(\n\t\t\tthis.editManager.localBranch.getHead() === this.editManager.getTrunkHead(),\n\t\t\t0xaaa /* All local changes should be applied to the trunk before loading from summary */,\n\t\t);\n\t\tconst [editManagerSummarizer, ...summarizables] = this.summarizables;\n\t\tconst loadEditManager = this.loadSummarizable(editManagerSummarizer, services);\n\t\tconst loadSummarizables = summarizables.map(async (s) =>\n\t\t\tthis.loadSummarizable(s, services),\n\t\t);\n\n\t\tif (this.detachedRevision !== undefined) {\n\t\t\t// If we are detached but loading from a summary, then we need to update our detached revision to ensure that it is ahead of all detached revisions in the summary.\n\t\t\t// First, finish loading the edit manager so that we can inspect the sequence numbers of the commits on the trunk.\n\t\t\tawait loadEditManager;\n\t\t\t// Find the most recent detached revision in the summary trunk...\n\t\t\tlet latestDetachedSequenceNumber: SeqNumber | undefined;\n\t\t\tfindAncestor(this.editManager.getTrunkHead(), (c) => {\n\t\t\t\tconst sequenceNumber = this.editManager.getSequenceNumber(c);\n\t\t\t\tif (sequenceNumber !== undefined && sequenceNumber < 0) {\n\t\t\t\t\tlatestDetachedSequenceNumber = sequenceNumber;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t});\n\t\t\t// ...and set our detached revision to be as it would be if we had been already created that revision.\n\t\t\tthis.detachedRevision = latestDetachedSequenceNumber ?? this.detachedRevision;\n\t\t\tawait Promise.all(loadSummarizables);\n\t\t} else {\n\t\t\tawait Promise.all([loadEditManager, ...loadSummarizables]);\n\t\t}\n\t}\n\n\tprivate async loadSummarizable(\n\t\tsummarizable: Summarizable,\n\t\tservices: IChannelStorageService,\n\t): Promise<void> {\n\t\treturn summarizable.load(\n\t\t\tscopeStorageService(services, summarizablesTreeKey, summarizable.key),\n\t\t\t(contents) => this.serializer.parse(contents),\n\t\t);\n\t}\n\n\t/**\n\t * Submits an op to the Fluid runtime containing the given commit\n\t * @param commit - the commit to submit\n\t * @returns the submitted commit. This is undefined if the underlying `SharedObject` is not attached,\n\t * and may differ from `commit` due to enrichments like detached tree refreshers.\n\t */\n\tprotected submitCommit(\n\t\tcommit: GraphCommit<TChange>,\n\t\tschemaAndPolicy: ClonableSchemaAndPolicy,\n\t\tisResubmit: boolean,\n\t): void {\n\t\tassert(\n\t\t\tthis.sharedObject.isAttached() === (this.detachedRevision === undefined),\n\t\t\t0x95a /* Detached revision should only be set when not attached */,\n\t\t);\n\n\t\tconst enrichedCommit =\n\t\t\tthis.detachedRevision === undefined && !isResubmit\n\t\t\t\t? this.commitEnricher.enrich(commit)\n\t\t\t\t: commit;\n\n\t\t// Edits submitted before the first attach are treated as sequenced because they will be included\n\t\t// in the attach summary that is uploaded to the service.\n\t\t// Until this attach workflow happens, this instance essentially behaves as a centralized data structure.\n\t\tif (this.detachedRevision !== undefined) {\n\t\t\tconst newRevision: SeqNumber = brand((this.detachedRevision as number) + 1);\n\t\t\tthis.detachedRevision = newRevision;\n\t\t\tthis.editManager.addSequencedChanges(\n\t\t\t\t[enrichedCommit],\n\t\t\t\tthis.editManager.localSessionId,\n\t\t\t\tnewRevision,\n\t\t\t\tthis.detachedRevision,\n\t\t\t);\n\t\t\tthis.editManager.advanceMinimumSequenceNumber(newRevision, false);\n\t\t\treturn undefined;\n\t\t}\n\t\tconst message = this.messageCodec.encode(\n\t\t\t{\n\t\t\t\tcommit: enrichedCommit,\n\t\t\t\tsessionId: this.editManager.localSessionId,\n\t\t\t},\n\t\t\t{\n\t\t\t\tidCompressor: this.idCompressor,\n\t\t\t\tschema: schemaAndPolicy,\n\t\t\t},\n\t\t);\n\t\tthis.submitLocalMessage(message, {\n\t\t\t// Clone the schema to ensure that during resubmit the schema has not been mutated by later changes\n\t\t\tschema: schemaAndPolicy.schema.clone(),\n\t\t\tpolicy: schemaAndPolicy.policy,\n\t\t});\n\t\tthis.resubmitMachine.onCommitSubmitted(enrichedCommit);\n\t}\n\n\t/**\n\t * Process a bunch of messages from the runtime. SharedObject will call this method with a bunch of messages.\n\t */\n\tpublic processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {\n\t\tconst { envelope, local, messagesContent } = messagesCollection;\n\t\tconst commits: GraphCommit<TChange>[] = [];\n\t\tlet messagesSessionId: SessionId | undefined;\n\n\t\t// Get a list of all the commits from the messages.\n\t\tfor (const messageContent of messagesContent) {\n\t\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\t\tconst { commit, sessionId } = this.messageCodec.decode(messageContent.contents, {\n\t\t\t\tidCompressor: this.idCompressor,\n\t\t\t});\n\t\t\tcommits.push(commit);\n\n\t\t\tif (messagesSessionId !== undefined) {\n\t\t\t\tassert(\n\t\t\t\t\tmessagesSessionId === sessionId,\n\t\t\t\t\t0xad9 /* All messages in a bunch must have the same session ID */,\n\t\t\t\t);\n\t\t\t}\n\t\t\tmessagesSessionId = sessionId;\n\t\t}\n\n\t\tassert(messagesSessionId !== undefined, 0xada /* Messages must have a session ID */);\n\n\t\tthis.editManager.addSequencedChanges(\n\t\t\tcommits,\n\t\t\tmessagesSessionId,\n\t\t\tbrand(envelope.sequenceNumber),\n\t\t\tbrand(envelope.referenceSequenceNumber),\n\t\t);\n\n\t\t// Update the resubmit machine for each commit applied.\n\t\tfor (const _ of messagesContent) {\n\t\t\tthis.resubmitMachine.onSequencedCommitApplied(local);\n\t\t}\n\n\t\tthis.editManager.advanceMinimumSequenceNumber(brand(envelope.minimumSequenceNumber));\n\t}\n\n\tpublic getLocalBranch(): SharedTreeBranch<TEditor, TChange> {\n\t\treturn this.editManager.localBranch;\n\t}\n\n\tpublic didAttach(): void {\n\t\tthis.detachedRevision = undefined;\n\t}\n\n\tpublic reSubmitCore(content: JsonCompatibleReadOnly, localOpMetadata: unknown): void {\n\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\tconst {\n\t\t\tcommit: { revision },\n\t\t} = this.messageCodec.decode(this.serializer.decode(content), {\n\t\t\tidCompressor: this.idCompressor,\n\t\t});\n\t\tconst [commit] = this.editManager.findLocalCommit(revision);\n\t\t// If a resubmit phase is not already in progress, then this must be the first commit of a new resubmit phase.\n\t\tif (this.resubmitMachine.isInResubmitPhase === false) {\n\t\t\tconst toResubmit = this.editManager.getLocalCommits();\n\t\t\tassert(\n\t\t\t\tcommit === toResubmit[0],\n\t\t\t\t0x95d /* Resubmit phase should start with the oldest local commit */,\n\t\t\t);\n\t\t\tthis.resubmitMachine.prepareForResubmit(toResubmit);\n\t\t}\n\t\tassert(\n\t\t\tisClonableSchemaPolicy(localOpMetadata),\n\t\t\t0x95e /* Local metadata must contain schema and policy. */,\n\t\t);\n\t\tassert(\n\t\t\tthis.resubmitMachine.isInResubmitPhase !== false,\n\t\t\t0x984 /* Invalid resubmit outside of resubmit phase */,\n\t\t);\n\t\tconst enrichedCommit = this.resubmitMachine.peekNextCommit();\n\t\tthis.submitCommit(enrichedCommit, localOpMetadata, true);\n\t}\n\n\tpublic applyStashedOp(content: JsonCompatibleReadOnly): void {\n\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\tconst {\n\t\t\tcommit: { revision, change },\n\t\t} = this.messageCodec.decode(content, { idCompressor: this.idCompressor });\n\t\tthis.editManager.localBranch.apply({ change, revision });\n\t}\n}\n\nfunction isClonableSchemaPolicy(\n\tmaybeSchemaPolicy: unknown,\n): maybeSchemaPolicy is ClonableSchemaAndPolicy {\n\tconst schemaAndPolicy = maybeSchemaPolicy as ClonableSchemaAndPolicy;\n\treturn schemaAndPolicy.schema !== undefined && schemaAndPolicy.policy !== undefined;\n}\n\n/**\n * Specifies the behavior of a component that puts data in a summary.\n */\nexport interface Summarizable {\n\t/**\n\t * Field name in summary json under which this element stores its data.\n\t */\n\treadonly key: string;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t * @param stringify - Serializes the contents of the component (including {@link (IFluidHandle:interface)}s) for storage.\n\t * @param fullTree - A flag indicating whether the attempt should generate a full\n\t * summary tree without any handles for unchanged subtrees. It should only be set to true when generating\n\t * a summary from the entire container. The default value is false.\n\t * @param trackState - An optimization for tracking state of objects across summaries. If the state\n\t * of an object did not change since last successful summary, an\n\t * {@link @fluidframework/protocol-definitions#ISummaryHandle} can be used\n\t * instead of re-summarizing it. If this is `false`, the expectation is that you should never\n\t * send an `ISummaryHandle`, since you are not expected to track state. The default value is true.\n\t * @param telemetryContext - See {@link @fluidframework/runtime-definitions#ITelemetryContext}.\n\t * @param incrementalSummaryContext - See {@link @fluidframework/runtime-definitions#IExperimentalIncrementalSummaryContext}.\n\t */\n\tsummarize(props: {\n\t\tstringify: SummaryElementStringifier;\n\t\tfullTree?: boolean;\n\t\ttrackState?: boolean;\n\t\ttelemetryContext?: ITelemetryContext;\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext;\n\t}): ISummaryTreeWithStats;\n\n\t/**\n\t * Allows the component to perform custom loading. The storage service is scoped to this component and therefore\n\t * paths in this component will not collide with those in other components, even if they are the same string.\n\t * @param service - Storage used by the component\n\t * @param parse - Parses serialized data from storage into runtime objects for the component\n\t */\n\tload(service: IChannelStorageService, parse: SummaryElementParser): Promise<void>;\n}\n\n/**\n * Serializes the given contents into a string acceptable for storing in summaries, i.e. all\n * Fluid handles have been replaced appropriately by an IFluidSerializer\n */\nexport type SummaryElementStringifier = (contents: unknown) => string;\n\n/**\n * Parses a serialized/summarized string into an object, rehydrating any Fluid handles as necessary\n */\nexport type SummaryElementParser = (contents: string) => unknown;\n\n/**\n * Compose an {@link IChannelStorageService} which prefixes all paths before forwarding them to the original service\n */\nfunction scopeStorageService(\n\tservice: IChannelStorageService,\n\t...pathElements: string[]\n): IChannelStorageService {\n\tconst scope = `${pathElements.join(\"/\")}/`;\n\n\treturn {\n\t\tasync readBlob(path: string): Promise<ArrayBufferLike> {\n\t\t\treturn service.readBlob(`${scope}${path}`);\n\t\t},\n\t\tasync contains(path) {\n\t\t\treturn service.contains(`${scope}${path}`);\n\t\t},\n\t\tasync list(path) {\n\t\t\treturn service.list(`${scope}${path}`);\n\t\t},\n\t};\n}\n"]}
|
|
@@ -126,6 +126,10 @@ export declare class TreeViewConfiguration<const TSchema extends ImplicitFieldSc
|
|
|
126
126
|
* {@inheritDoc ITreeConfigurationOptions.preventAmbiguity}
|
|
127
127
|
*/
|
|
128
128
|
readonly preventAmbiguity: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* {@link TreeSchema.definitions} but with public types.
|
|
131
|
+
*/
|
|
132
|
+
protected readonly definitionsInternal: ReadonlyMap<string, TreeNodeSchema>;
|
|
129
133
|
/**
|
|
130
134
|
* Construct a new {@link TreeViewConfiguration}.
|
|
131
135
|
*
|
|
@@ -153,7 +157,7 @@ export declare class TreeViewConfigurationAlpha<const TSchema extends ImplicitFi
|
|
|
153
157
|
/**
|
|
154
158
|
* {@inheritDoc TreeSchema.definitions}
|
|
155
159
|
*/
|
|
156
|
-
|
|
160
|
+
get definitions(): ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema>;
|
|
157
161
|
constructor(props: ITreeViewConfiguration<TSchema>);
|
|
158
162
|
}
|
|
159
163
|
/**
|
|
@@ -171,7 +175,15 @@ export interface TreeSchema extends SimpleTreeSchema {
|
|
|
171
175
|
readonly definitions: ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema>;
|
|
172
176
|
}
|
|
173
177
|
/**
|
|
174
|
-
*
|
|
178
|
+
* Check if union contents are valid (shallowly).
|
|
179
|
+
*
|
|
180
|
+
* @param union - The union of {@link TreeNodeSchema} to check.
|
|
181
|
+
* @param preventAmbiguity - If true, detect cases documented in {@link ITreeConfigurationOptions.preventAmbiguity}, reporting them to `ambiguityErrors`.
|
|
182
|
+
* @param ambiguityErrors - An array into which this function inserts any ambiguity errors, see {@link ITreeConfigurationOptions.preventAmbiguity}.
|
|
183
|
+
*
|
|
184
|
+
* @remarks
|
|
185
|
+
* Includes checks for non-ambiguity errors as well: such as duplicate schemas in the union.
|
|
186
|
+
* Any non-ambiguity errors are thrown as exceptions: `UsageError`s if causable by incorrect API use, and asserts if violating internal invariants.
|
|
175
187
|
*/
|
|
176
|
-
export declare function checkUnion(union: Iterable<TreeNodeSchema>,
|
|
188
|
+
export declare function checkUnion(union: Iterable<TreeNodeSchema>, preventAmbiguity: boolean, ambiguityErrors: string[]): void;
|
|
177
189
|
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/configuration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/configuration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EAMxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAKjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE7E;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACzC;;;;;;;;;OASG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyEG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACpC;AAOD;;;GAGG;AACH,MAAM,WAAW,sBAAsB,CACtC,OAAO,SAAS,mBAAmB,GAAG,mBAAmB,CACxD,SAAQ,yBAAyB;IAClC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CACzB;AAED;;;GAGG;AACH,qBAAa,qBAAqB,CACjC,KAAK,CAAC,OAAO,SAAS,mBAAmB,GAAG,mBAAmB,CAC9D,YAAW,QAAQ,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAErD,SAAS,CAAC,UAAU,EAAG,WAAW,CAAC;IAEnC;;OAEG;IACH,SAAgB,MAAM,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,SAAgB,sBAAsB,EAAE,OAAO,CAAC;IAEhD;;OAEG;IACH,SAAgB,gBAAgB,EAAE,OAAO,CAAC;IAE1C;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,mBAAmB,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAE5E;;;;;;;;;;;;OAYG;gBACgB,KAAK,EAAE,sBAAsB,CAAC,OAAO,CAAC;CA0CzD;AAED;;;GAGG;AACH,qBAAa,0BAA0B,CACrC,KAAK,CAAC,OAAO,SAAS,mBAAmB,GAAG,mBAAmB,CAEhE,SAAQ,qBAAqB,CAAC,OAAO,CACrC,YAAW,UAAU;IAErB;;OAEG;IACH,SAAgB,IAAI,EAAE,gBAAgB,CAAC;IAEvC;;OAEG;IACH,IAAW,WAAW,IAAI,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAAC,CAE/E;gBAEkB,KAAK,EAAE,sBAAsB,CAAC,OAAO,CAAC;CAIzD;AAED;;;GAGG;AACH,MAAM,WAAW,UAAW,SAAQ,gBAAgB;IACnD;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAAC,CAAC;CAC7E;AAWD;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACzB,KAAK,EAAE,QAAQ,CAAC,cAAc,CAAC,EAC/B,gBAAgB,EAAE,OAAO,EACzB,eAAe,EAAE,MAAM,EAAE,GACvB,IAAI,CA2FN"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { assert, fail } from "@fluidframework/core-utils/internal";
|
|
5
|
+
import { assert, debugAssert, fail } from "@fluidframework/core-utils/internal";
|
|
6
6
|
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
7
|
-
import { FieldKind, markSchemaMostDerived, normalizeFieldSchema, } from "../schemaTypes.js";
|
|
7
|
+
import { evaluateLazySchema, FieldKind, isAnnotatedAllowedType, markSchemaMostDerived, normalizeFieldSchema, } from "../schemaTypes.js";
|
|
8
8
|
import { NodeKind } from "../core/index.js";
|
|
9
9
|
import { toStoredSchema } from "../toStoredSchema.js";
|
|
10
10
|
import { LeafNodeSchema } from "../leafNodeSchema.js";
|
|
@@ -40,24 +40,29 @@ export class TreeViewConfiguration {
|
|
|
40
40
|
this.preventAmbiguity = config.preventAmbiguity;
|
|
41
41
|
// Ambiguity errors are lower priority to report than invalid schema errors, so collect these in an array and report them all at once.
|
|
42
42
|
const ambiguityErrors = [];
|
|
43
|
+
// Eagerly perform this conversion to surface errors sooner.
|
|
44
|
+
// Includes detection of duplicate schema identifiers.
|
|
45
|
+
toStoredSchema(config.schema);
|
|
46
|
+
const definitions = new Map();
|
|
43
47
|
walkFieldSchema(config.schema, {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
node: (schema) => {
|
|
49
|
+
// Ensure all reachable schema are marked as most derived.
|
|
50
|
+
// This ensures if multiple schema extending the same schema factory generated class are present (or have had instances of them constructed, or get instances of them constructed in the future),
|
|
51
|
+
// an error is reported.
|
|
52
|
+
markSchemaMostDerived(schema, true);
|
|
53
|
+
debugAssert(() => !definitions.has(schema.identifier));
|
|
54
|
+
definitions.set(schema.identifier, schema);
|
|
55
|
+
},
|
|
56
|
+
allowedTypes({ types }) {
|
|
57
|
+
checkUnion(types.map((t) => evaluateLazySchema(isAnnotatedAllowedType(t) ? t.type : t)), config.preventAmbiguity, ambiguityErrors);
|
|
52
58
|
},
|
|
53
59
|
});
|
|
60
|
+
this.definitionsInternal = definitions;
|
|
54
61
|
if (ambiguityErrors.length !== 0) {
|
|
55
62
|
// Duplicate errors are common since when two types conflict, both orders error:
|
|
56
63
|
const deduplicated = new Set(ambiguityErrors);
|
|
57
64
|
throw new UsageError(`Ambiguous schema found:\n${[...deduplicated].join("\n")}`);
|
|
58
65
|
}
|
|
59
|
-
// Eagerly perform this conversion to surface errors sooner.
|
|
60
|
-
toStoredSchema(config.schema);
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
/**
|
|
@@ -65,14 +70,15 @@ export class TreeViewConfiguration {
|
|
|
65
70
|
* @sealed @alpha
|
|
66
71
|
*/
|
|
67
72
|
export class TreeViewConfigurationAlpha extends TreeViewConfiguration {
|
|
73
|
+
/**
|
|
74
|
+
* {@inheritDoc TreeSchema.definitions}
|
|
75
|
+
*/
|
|
76
|
+
get definitions() {
|
|
77
|
+
return this.definitionsInternal;
|
|
78
|
+
}
|
|
68
79
|
constructor(props) {
|
|
69
80
|
super(props);
|
|
70
81
|
this.root = normalizeFieldSchema(props.schema);
|
|
71
|
-
const definitions = new Map();
|
|
72
|
-
walkFieldSchema(props.schema, {
|
|
73
|
-
node: (schema) => definitions.set(schema.identifier, schema),
|
|
74
|
-
});
|
|
75
|
-
this.definitions = definitions;
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
/**
|
|
@@ -84,9 +90,17 @@ function formatTypes(allowed) {
|
|
|
84
90
|
return `[${Array.from(allowed, (s) => JSON.stringify(s.identifier)).join(", ")}]`;
|
|
85
91
|
}
|
|
86
92
|
/**
|
|
87
|
-
*
|
|
93
|
+
* Check if union contents are valid (shallowly).
|
|
94
|
+
*
|
|
95
|
+
* @param union - The union of {@link TreeNodeSchema} to check.
|
|
96
|
+
* @param preventAmbiguity - If true, detect cases documented in {@link ITreeConfigurationOptions.preventAmbiguity}, reporting them to `ambiguityErrors`.
|
|
97
|
+
* @param ambiguityErrors - An array into which this function inserts any ambiguity errors, see {@link ITreeConfigurationOptions.preventAmbiguity}.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* Includes checks for non-ambiguity errors as well: such as duplicate schemas in the union.
|
|
101
|
+
* Any non-ambiguity errors are thrown as exceptions: `UsageError`s if causable by incorrect API use, and asserts if violating internal invariants.
|
|
88
102
|
*/
|
|
89
|
-
export function checkUnion(union,
|
|
103
|
+
export function checkUnion(union, preventAmbiguity, ambiguityErrors) {
|
|
90
104
|
const checked = new Set();
|
|
91
105
|
const maps = [];
|
|
92
106
|
const arrays = [];
|
|
@@ -115,17 +129,21 @@ export function checkUnion(union, errors) {
|
|
|
115
129
|
maps.push(schema);
|
|
116
130
|
}
|
|
117
131
|
}
|
|
132
|
+
if (!preventAmbiguity) {
|
|
133
|
+
// All remaining checks are for the preventAmbiguity case, so skip them if not enabled.
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
118
136
|
if (arrays.length > 1) {
|
|
119
|
-
|
|
137
|
+
ambiguityErrors.push(`More than one kind of array allowed within union (${formatTypes(arrays)}). This would require type disambiguation which is not supported by arrays during import or export.`);
|
|
120
138
|
}
|
|
121
139
|
if (maps.length > 1) {
|
|
122
|
-
|
|
140
|
+
ambiguityErrors.push(`More than one kind of map allowed within union (${formatTypes(maps)}). This would require type disambiguation which is not supported by maps during import or export.`);
|
|
123
141
|
}
|
|
124
142
|
if (maps.length > 0 && arrays.length > 0) {
|
|
125
|
-
|
|
143
|
+
ambiguityErrors.push(`Both a map and an array allowed within union (${formatTypes([...arrays, ...maps])}). Both can be implicitly constructed from iterables like arrays, which are ambiguous when the array is empty.`);
|
|
126
144
|
}
|
|
127
145
|
if (objects.length > 0 && maps.length > 0) {
|
|
128
|
-
|
|
146
|
+
ambiguityErrors.push(`Both a object and a map allowed within union (${formatTypes([...objects, ...maps])}). Both can be constructed from objects and can be ambiguous.`);
|
|
129
147
|
}
|
|
130
148
|
// Check for objects which fully overlap:
|
|
131
149
|
for (const schema of objects) {
|
|
@@ -150,7 +168,7 @@ export function checkUnion(union, errors) {
|
|
|
150
168
|
// Add "constant" fields which can be used to disambiguate even more cases without adding persisted data: maybe make them optional in constructor?
|
|
151
169
|
// Consider separating unambiguous implicit construction format from constructor arguments at type level, allowing constructor to superset the implicit construction options (ex: optional constant fields).
|
|
152
170
|
// The policy here however must remain at least as conservative as shallowCompatibilityTest in src/simple-tree/unhydratedFlexTreeFromInsertable.ts.
|
|
153
|
-
|
|
171
|
+
ambiguityErrors.push(`The required fields of ${JSON.stringify(schema.identifier)} are insufficient to differentiate it from the following types: ${formatTypes(possiblyAmbiguous)}. For objects to be considered unambiguous, each must have required fields that do not all occur on any other object in the union.`);
|
|
154
172
|
}
|
|
155
173
|
}
|
|
156
174
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/simple-tree/api/configuration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAGN,SAAS,EACT,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAuB,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAyB,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAiGxD,MAAM,+BAA+B,GAAwC;IAC5E,sBAAsB,EAAE,KAAK;IAC7B,gBAAgB,EAAE,KAAK;CACvB,CAAC;AAeF;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAqBjC;;;;;;;;;;;;OAYG;IACH,YAAmB,KAAsC;QACxD,MAAM,MAAM,GAAG,EAAE,GAAG,+BAA+B,EA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D;QAC7D,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAE3C,0CAA0C;QAC1C,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAEjC,6FAA6F;QAC7F,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAC1C,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,QAAQ,EAAE,CAAC;gBACvC,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;gBAC3E,KAAK,MAAM,SAAS,IAAI,iBAAiB,EAAE,CAAC;oBAC3C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;wBAC7B,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBACrC,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,IAAI,iBAAiB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAChC,yCAAyC;YACzC,8EAA8E;YAC9E,kJAAkJ;YAClJ,4MAA4M;YAC5M,mJAAmJ;YAEnJ,MAAM,CAAC,IAAI,CACV,0BAA0B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,mEAAmE,WAAW,CAAC,iBAAiB,CAAC,oIAAoI,CAChS,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype FieldSchemaAlpha,\n\ttype ImplicitFieldSchema,\n\tFieldKind,\n\tmarkSchemaMostDerived,\n\tnormalizeFieldSchema,\n} from \"../schemaTypes.js\";\nimport { NodeKind, type TreeNodeSchema } from \"../core/index.js\";\nimport { toStoredSchema } from \"../toStoredSchema.js\";\nimport { LeafNodeSchema } from \"../leafNodeSchema.js\";\nimport { isObjectNodeSchema, type ObjectNodeSchema } from \"../node-kinds/index.js\";\nimport { getOrCreate } from \"../../util/index.js\";\nimport type { MakeNominal } from \"../../util/index.js\";\nimport { walkFieldSchema } from \"../walkFieldSchema.js\";\nimport type { SimpleNodeSchema, SimpleTreeSchema } from \"../simpleSchema.js\";\n\n/**\n * Options when constructing a tree view.\n * @public\n */\nexport interface ITreeConfigurationOptions {\n\t/**\n\t * If `true`, the tree will validate new content against its stored schema at insertion time\n\t * and throw an error if the new content doesn't match the expected schema.\n\t *\n\t * @defaultValue `false`.\n\t *\n\t * @remarks Enabling schema validation has a performance penalty when inserting new content into the tree because\n\t * additional checks are done. Enable this option only in scenarios where you are ok with that operation being a\n\t * bit slower.\n\t */\n\tenableSchemaValidation?: boolean;\n\n\t/**\n\t * A flag used to opt into strict rules ensuring that the schema avoids cases which can make the type of nodes ambiguous when importing or exporting data.\n\t * @defaultValue `false`.\n\t *\n\t * @remarks\n\t * When this is true, it ensures that the compile time type safety for data when constructing nodes is sufficient to ensure that the runtime behavior will not give node data ambiguity errors.\n\t *\n\t * This ensures that the canonical JSON-like representation of all unions in the tree are lossless and unambiguous.\n\t * This canonical JSON-like representation consists of arrays, plain old JavaScript objects with string keys, booleans, numbers (excluding NaN, -0 and infinities), strings, null and {@link @fluidframework/core-interfaces#IFluidHandle}s.\n\t * It is compatible with the node creation APIs (such as schema class constructors) and is also compatible with JSON assuming any IFluidHandles get special handling (since they are not JSON compatible).\n\t * Currently these cases can cause ambiguity in a union:\n\t *\n\t * - More than one ArrayNode type: it's impossible to tell which array type is intended in the case of empty arrays (`[]`).\n\t *\n\t * - More than one MapNode type: it's impossible to tell which map type is intended in the case of an empty map (`{}`).\n\t *\n\t * - Both a MapNode and an ArrayNode: this case is not a problem for the canonical JSON representation, but is an issue when constructing from an Iterable, which is supported for both MapNode and ArrayNode.\n\t *\n\t * - Both a MapNode and an ObjectNode: when the input is valid for the ObjectNode, the current parser always considers it ambiguous with being a MapNode.\n\t *\n\t * - ObjectNodes which have fields (required or optional) which include all required fields of another ObjectNode: currently each ObjectNode is differentiated by the presence of its required fields.\n\t *\n\t * This check is conservative: some complex cases may error if the current simple algorithm cannot show no ambiguity is possible.\n\t * This check may become more permissive over time.\n\t *\n\t * @example Ambiguous schema (with `preventAmbiguity: false`), and how to disambiguate it using {@link Unhydrated} nodes:\n\t * ```typescript\n\t * const schemaFactory = new SchemaFactory(\"com.example\");\n\t * class Feet extends schemaFactory.object(\"Feet\", { length: schemaFactory.number }) {}\n\t * class Meters extends schemaFactory.object(\"Meters\", { length: schemaFactory.number }) {}\n\t * const config = new TreeViewConfiguration({\n\t * \t// This combination of schema can lead to ambiguous cases and will error if `preventAmbiguity` is true.\n\t * \tschema: [Feet, Meters],\n\t * \tpreventAmbiguity: false,\n\t * });\n\t * const view = tree.viewWith(config);\n\t * // This is invalid since it is ambiguous which type of node is being constructed:\n\t * // view.initialize({ length: 5 });\n\t * // To work, an explicit type can be provided by using an {@link Unhydrated} Node:\n\t * view.initialize(new Meters({ length: 5 }));\n\t * ```\n\t *\n\t * @example Schema disambiguated by adjusting field names, validated with `preventAmbiguity: true:`\n\t * ```typescript\n\t * const schemaFactory = new SchemaFactory(\"com.example\");\n\t * class Feet extends schemaFactory.object(\"Feet\", { length: schemaFactory.number }) {}\n\t * class Meters extends schemaFactory.object(\"Meters\", {\n\t * \t// To avoid ambiguity when parsing unions of Feet and Meters, this renames the length field to \"meters\".\n\t * \t// To preserve compatibility with existing data from the ambiguous case,\n\t * \t// `{ key: \"length\" }` is set, so when persisted in the tree \"length\" is used as the field name.\n\t * \tmeters: schemaFactory.required(schemaFactory.number, { key: \"length\" }),\n\t * }) {}\n\t * const config = new TreeViewConfiguration({\n\t * \t// This combination of schema is not ambiguous because `Feet` and `Meters` have different required keys.\n\t * \tschema: [Feet, Meters],\n\t * \tpreventAmbiguity: true,\n\t * });\n\t * const view = tree.viewWith(config);\n\t * // This now works, since the field is sufficient to determine this is a `Meters` node.\n\t * view.initialize({ meters: 5 });\n\t * ```\n\t *\n\t * @privateRemarks\n\t * In the future, we can support lossless round tripping via the canonical JSON-like representation above when unambiguous.\n\t * This could be done via methods added to `Tree` to export and import such objects, which would give us a place to explicitly define the type of this representation.\n\t *\n\t * To make this more permissive in the future we can:\n\t *\n\t * - Make unhydratedFlexTreeFromInsertable more permissive (ex: allow disambiguation based on leaf type)\n\t * - Update this check to more tightly match unhydratedFlexTreeFromInsertable\n\t * - Add options to help schema authors disambiguate their types, such as \"constant fields\" which are not persisted, and always have a constant value.\n\t *\n\t * The above examples exist in executable form in this files tests, and should be updated there then copied back here.\n\t */\n\treadonly preventAmbiguity?: boolean;\n}\n\nconst defaultTreeConfigurationOptions: Required<ITreeConfigurationOptions> = {\n\tenableSchemaValidation: false,\n\tpreventAmbiguity: false,\n};\n\n/**\n * Property-bag configuration for {@link TreeViewConfiguration} construction.\n * @public\n */\nexport interface ITreeViewConfiguration<\n\tTSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n> extends ITreeConfigurationOptions {\n\t/**\n\t * The schema which the application wants to view the tree with.\n\t */\n\treadonly schema: TSchema;\n}\n\n/**\n * Configuration for {@link ViewableTree.viewWith}.\n * @sealed @public\n */\nexport class TreeViewConfiguration<\n\tconst TSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n> implements Required<ITreeViewConfiguration<TSchema>>\n{\n\tprotected _typeCheck!: MakeNominal;\n\n\t/**\n\t * {@inheritDoc ITreeViewConfiguration.schema}\n\t */\n\tpublic readonly schema: TSchema;\n\n\t/**\n\t * {@inheritDoc ITreeConfigurationOptions.enableSchemaValidation}\n\t */\n\tpublic readonly enableSchemaValidation: boolean;\n\n\t/**\n\t * {@inheritDoc ITreeConfigurationOptions.preventAmbiguity}\n\t */\n\tpublic readonly preventAmbiguity: boolean;\n\n\t/**\n\t * Construct a new {@link TreeViewConfiguration}.\n\t *\n\t * @param props - Property bag of configuration options.\n\t *\n\t * @remarks\n\t * Performing this construction deeply validates the provided schema.\n\t * This means that when this constructor is called, all {@link LazyItem} {@link TreeNodeSchema} references will be evaluated (using {@link evaluateLazySchema}).\n\t * This means that the declarations for all transitively reachable {@link TreeNodeSchema} must be available at this time.\n\t *\n\t * For example, a schema reachable from this configuration cannot reference this configuration during its declaration,\n\t * since this would be a cyclic dependency that will cause an error when constructing this configuration.\n\t */\n\tpublic constructor(props: ITreeViewConfiguration<TSchema>) {\n\t\tconst config = { ...defaultTreeConfigurationOptions, ...props };\n\t\tthis.schema = config.schema;\n\t\tthis.enableSchemaValidation = config.enableSchemaValidation;\n\t\tthis.preventAmbiguity = config.preventAmbiguity;\n\n\t\t// Ambiguity errors are lower priority to report than invalid schema errors, so collect these in an array and report them all at once.\n\t\tconst ambiguityErrors: string[] = [];\n\n\t\twalkFieldSchema(config.schema, {\n\t\t\t// Ensure all reachable schema are marked as most derived.\n\t\t\t// This ensures if multiple schema extending the same schema factory generated class are present (or have been constructed, or get constructed in the future),\n\t\t\t// an error is reported.\n\n\t\t\tnode: (schema) => markSchemaMostDerived(schema, true),\n\t\t\tallowedTypes(types): void {\n\t\t\t\tif (config.preventAmbiguity) {\n\t\t\t\t\tcheckUnion(types, ambiguityErrors);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\n\t\tif (ambiguityErrors.length !== 0) {\n\t\t\t// Duplicate errors are common since when two types conflict, both orders error:\n\t\t\tconst deduplicated = new Set(ambiguityErrors);\n\t\t\tthrow new UsageError(`Ambiguous schema found:\\n${[...deduplicated].join(\"\\n\")}`);\n\t\t}\n\n\t\t// Eagerly perform this conversion to surface errors sooner.\n\t\ttoStoredSchema(config.schema);\n\t}\n}\n\n/**\n * {@link TreeViewConfiguration} extended with some alpha APIs.\n * @sealed @alpha\n */\nexport class TreeViewConfigurationAlpha<\n\t\tconst TSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n\t>\n\textends TreeViewConfiguration<TSchema>\n\timplements TreeSchema\n{\n\t/**\n\t * {@inheritDoc TreeSchema.root}\n\t */\n\tpublic readonly root: FieldSchemaAlpha;\n\t/**\n\t * {@inheritDoc TreeSchema.definitions}\n\t */\n\tpublic readonly definitions: ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema>;\n\n\tpublic constructor(props: ITreeViewConfiguration<TSchema>) {\n\t\tsuper(props);\n\t\tthis.root = normalizeFieldSchema(props.schema);\n\t\tconst definitions = new Map<string, SimpleNodeSchema & TreeNodeSchema>();\n\t\twalkFieldSchema(props.schema, {\n\t\t\tnode: (schema) =>\n\t\t\t\tdefinitions.set(schema.identifier, schema as SimpleNodeSchema & TreeNodeSchema),\n\t\t});\n\t\tthis.definitions = definitions;\n\t}\n}\n\n/**\n * {@link TreeViewConfigurationAlpha}\n * @sealed @alpha\n */\nexport interface TreeSchema extends SimpleTreeSchema {\n\t/**\n\t * {@inheritDoc SimpleTreeSchema.root}\n\t */\n\treadonly root: FieldSchemaAlpha;\n\n\t/**\n\t * {@inheritDoc SimpleTreeSchema.definitions}\n\t */\n\treadonly definitions: ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema>;\n}\n\n/**\n * Pretty print a set of types for use in error messages.\n */\nfunction formatTypes(allowed: Iterable<TreeNodeSchema>): string {\n\t// Use JSON.stringify to quote and escape identifiers.\n\t// Don't just use a single array JSON.stringify since that omits spaces between items\n\treturn `[${Array.from(allowed, (s) => JSON.stringify(s.identifier)).join(\", \")}]`;\n}\n\n/**\n * Detect cases documented in {@link ITreeConfigurationOptions.preventAmbiguity}.\n */\nexport function checkUnion(union: Iterable<TreeNodeSchema>, errors: string[]): void {\n\tconst checked: Set<TreeNodeSchema> = new Set();\n\tconst maps: TreeNodeSchema[] = [];\n\tconst arrays: TreeNodeSchema[] = [];\n\n\tconst objects: ObjectNodeSchema[] = [];\n\t// Map from key to schema using that key\n\tconst allObjectKeys: Map<string, Set<TreeNodeSchema>> = new Map();\n\n\tfor (const schema of union) {\n\t\tif (checked.has(schema)) {\n\t\t\tthrow new UsageError(`Duplicate schema in allowed types: ${schema.identifier}`);\n\t\t}\n\t\tchecked.add(schema);\n\n\t\tif (schema instanceof LeafNodeSchema) {\n\t\t\t// nothing to do\n\t\t} else if (isObjectNodeSchema(schema)) {\n\t\t\tobjects.push(schema);\n\t\t\tfor (const key of schema.fields.keys()) {\n\t\t\t\tgetOrCreate(allObjectKeys, key, () => new Set()).add(schema);\n\t\t\t}\n\t\t} else if (schema.kind === NodeKind.Array) {\n\t\t\tarrays.push(schema);\n\t\t} else {\n\t\t\tassert(schema.kind === NodeKind.Map, 0x9e7 /* invalid schema */);\n\t\t\tmaps.push(schema);\n\t\t}\n\t}\n\n\tif (arrays.length > 1) {\n\t\terrors.push(\n\t\t\t`More than one kind of array allowed within union (${formatTypes(arrays)}). This would require type disambiguation which is not supported by arrays during import or export.`,\n\t\t);\n\t}\n\n\tif (maps.length > 1) {\n\t\terrors.push(\n\t\t\t`More than one kind of map allowed within union (${formatTypes(maps)}). This would require type disambiguation which is not supported by maps during import or export.`,\n\t\t);\n\t}\n\n\tif (maps.length > 0 && arrays.length > 0) {\n\t\terrors.push(\n\t\t\t`Both a map and an array allowed within union (${formatTypes([...arrays, ...maps])}). Both can be implicitly constructed from iterables like arrays, which are ambiguous when the array is empty.`,\n\t\t);\n\t}\n\n\tif (objects.length > 0 && maps.length > 0) {\n\t\terrors.push(\n\t\t\t`Both a object and a map allowed within union (${formatTypes([...objects, ...maps])}). Both can be constructed from objects and can be ambiguous.`,\n\t\t);\n\t}\n\n\t// Check for objects which fully overlap:\n\tfor (const schema of objects) {\n\t\t// All objects which might be ambiguous relative to `schema`.\n\t\tconst possiblyAmbiguous = new Set(objects);\n\n\t\t// A schema can't be ambiguous with itself\n\t\tpossiblyAmbiguous.delete(schema);\n\n\t\t// For each field of schema, remove schema from possiblyAmbiguous that do not have that field\n\t\tfor (const [key, field] of schema.fields) {\n\t\t\tif (field.kind === FieldKind.Required) {\n\t\t\t\tconst withKey = allObjectKeys.get(key) ?? fail(0xb35 /* missing schema */);\n\t\t\t\tfor (const candidate of possiblyAmbiguous) {\n\t\t\t\t\tif (!withKey.has(candidate)) {\n\t\t\t\t\t\tpossiblyAmbiguous.delete(candidate);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (possiblyAmbiguous.size > 0) {\n\t\t\t// TODO: make this check more permissive.\n\t\t\t// Allow using the type of the field to disambiguate, at least for leaf types.\n\t\t\t// Add \"constant\" fields which can be used to disambiguate even more cases without adding persisted data: maybe make them optional in constructor?\n\t\t\t// Consider separating unambiguous implicit construction format from constructor arguments at type level, allowing constructor to superset the implicit construction options (ex: optional constant fields).\n\t\t\t// The policy here however must remain at least as conservative as shallowCompatibilityTest in src/simple-tree/unhydratedFlexTreeFromInsertable.ts.\n\n\t\t\terrors.push(\n\t\t\t\t`The required fields of ${JSON.stringify(schema.identifier)} are insufficient to differentiate it from the following types: ${formatTypes(possiblyAmbiguous)}. For objects to be considered unambiguous, each must have required fields that do not all occur on any other object in the union.`,\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/simple-tree/api/configuration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAGN,kBAAkB,EAClB,SAAS,EACT,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAuB,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,kBAAkB,E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AAG,CAAC,SAAS,CAAC,EAAE,CAAC;wBAC7B,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBACrC,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,IAAI,iBAAiB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAChC,yCAAyC;YACzC,8EAA8E;YAC9E,kJAAkJ;YAClJ,4MAA4M;YAC5M,mJAAmJ;YAEnJ,eAAe,CAAC,IAAI,CACnB,0BAA0B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,mEAAmE,WAAW,CAAC,iBAAiB,CAAC,oIAAoI,CAChS,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, debugAssert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype FieldSchemaAlpha,\n\ttype ImplicitFieldSchema,\n\tevaluateLazySchema,\n\tFieldKind,\n\tisAnnotatedAllowedType,\n\tmarkSchemaMostDerived,\n\tnormalizeFieldSchema,\n} from \"../schemaTypes.js\";\nimport { NodeKind, type TreeNodeSchema } from \"../core/index.js\";\nimport { toStoredSchema } from \"../toStoredSchema.js\";\nimport { LeafNodeSchema } from \"../leafNodeSchema.js\";\nimport { isObjectNodeSchema, type ObjectNodeSchema } from \"../node-kinds/index.js\";\nimport { getOrCreate } from \"../../util/index.js\";\nimport type { MakeNominal } from \"../../util/index.js\";\nimport { walkFieldSchema } from \"../walkFieldSchema.js\";\nimport type { SimpleNodeSchema, SimpleTreeSchema } from \"../simpleSchema.js\";\n\n/**\n * Options when constructing a tree view.\n * @public\n */\nexport interface ITreeConfigurationOptions {\n\t/**\n\t * If `true`, the tree will validate new content against its stored schema at insertion time\n\t * and throw an error if the new content doesn't match the expected schema.\n\t *\n\t * @defaultValue `false`.\n\t *\n\t * @remarks Enabling schema validation has a performance penalty when inserting new content into the tree because\n\t * additional checks are done. Enable this option only in scenarios where you are ok with that operation being a\n\t * bit slower.\n\t */\n\tenableSchemaValidation?: boolean;\n\n\t/**\n\t * A flag used to opt into strict rules ensuring that the schema avoids cases which can make the type of nodes ambiguous when importing or exporting data.\n\t * @defaultValue `false`.\n\t *\n\t * @remarks\n\t * When this is true, it ensures that the compile time type safety for data when constructing nodes is sufficient to ensure that the runtime behavior will not give node data ambiguity errors.\n\t *\n\t * This ensures that the canonical JSON-like representation of all unions in the tree are lossless and unambiguous.\n\t * This canonical JSON-like representation consists of arrays, plain old JavaScript objects with string keys, booleans, numbers (excluding NaN, -0 and infinities), strings, null and {@link @fluidframework/core-interfaces#IFluidHandle}s.\n\t * It is compatible with the node creation APIs (such as schema class constructors) and is also compatible with JSON assuming any IFluidHandles get special handling (since they are not JSON compatible).\n\t * Currently these cases can cause ambiguity in a union:\n\t *\n\t * - More than one ArrayNode type: it's impossible to tell which array type is intended in the case of empty arrays (`[]`).\n\t *\n\t * - More than one MapNode type: it's impossible to tell which map type is intended in the case of an empty map (`{}`).\n\t *\n\t * - Both a MapNode and an ArrayNode: this case is not a problem for the canonical JSON representation, but is an issue when constructing from an Iterable, which is supported for both MapNode and ArrayNode.\n\t *\n\t * - Both a MapNode and an ObjectNode: when the input is valid for the ObjectNode, the current parser always considers it ambiguous with being a MapNode.\n\t *\n\t * - ObjectNodes which have fields (required or optional) which include all required fields of another ObjectNode: currently each ObjectNode is differentiated by the presence of its required fields.\n\t *\n\t * This check is conservative: some complex cases may error if the current simple algorithm cannot show no ambiguity is possible.\n\t * This check may become more permissive over time.\n\t *\n\t * @example Ambiguous schema (with `preventAmbiguity: false`), and how to disambiguate it using {@link Unhydrated} nodes:\n\t * ```typescript\n\t * const schemaFactory = new SchemaFactory(\"com.example\");\n\t * class Feet extends schemaFactory.object(\"Feet\", { length: schemaFactory.number }) {}\n\t * class Meters extends schemaFactory.object(\"Meters\", { length: schemaFactory.number }) {}\n\t * const config = new TreeViewConfiguration({\n\t * \t// This combination of schema can lead to ambiguous cases and will error if `preventAmbiguity` is true.\n\t * \tschema: [Feet, Meters],\n\t * \tpreventAmbiguity: false,\n\t * });\n\t * const view = tree.viewWith(config);\n\t * // This is invalid since it is ambiguous which type of node is being constructed:\n\t * // view.initialize({ length: 5 });\n\t * // To work, an explicit type can be provided by using an {@link Unhydrated} Node:\n\t * view.initialize(new Meters({ length: 5 }));\n\t * ```\n\t *\n\t * @example Schema disambiguated by adjusting field names, validated with `preventAmbiguity: true:`\n\t * ```typescript\n\t * const schemaFactory = new SchemaFactory(\"com.example\");\n\t * class Feet extends schemaFactory.object(\"Feet\", { length: schemaFactory.number }) {}\n\t * class Meters extends schemaFactory.object(\"Meters\", {\n\t * \t// To avoid ambiguity when parsing unions of Feet and Meters, this renames the length field to \"meters\".\n\t * \t// To preserve compatibility with existing data from the ambiguous case,\n\t * \t// `{ key: \"length\" }` is set, so when persisted in the tree \"length\" is used as the field name.\n\t * \tmeters: schemaFactory.required(schemaFactory.number, { key: \"length\" }),\n\t * }) {}\n\t * const config = new TreeViewConfiguration({\n\t * \t// This combination of schema is not ambiguous because `Feet` and `Meters` have different required keys.\n\t * \tschema: [Feet, Meters],\n\t * \tpreventAmbiguity: true,\n\t * });\n\t * const view = tree.viewWith(config);\n\t * // This now works, since the field is sufficient to determine this is a `Meters` node.\n\t * view.initialize({ meters: 5 });\n\t * ```\n\t *\n\t * @privateRemarks\n\t * In the future, we can support lossless round tripping via the canonical JSON-like representation above when unambiguous.\n\t * This could be done via methods added to `Tree` to export and import such objects, which would give us a place to explicitly define the type of this representation.\n\t *\n\t * To make this more permissive in the future we can:\n\t *\n\t * - Make unhydratedFlexTreeFromInsertable more permissive (ex: allow disambiguation based on leaf type)\n\t * - Update this check to more tightly match unhydratedFlexTreeFromInsertable\n\t * - Add options to help schema authors disambiguate their types, such as \"constant fields\" which are not persisted, and always have a constant value.\n\t *\n\t * The above examples exist in executable form in this files tests, and should be updated there then copied back here.\n\t */\n\treadonly preventAmbiguity?: boolean;\n}\n\nconst defaultTreeConfigurationOptions: Required<ITreeConfigurationOptions> = {\n\tenableSchemaValidation: false,\n\tpreventAmbiguity: false,\n};\n\n/**\n * Property-bag configuration for {@link TreeViewConfiguration} construction.\n * @public\n */\nexport interface ITreeViewConfiguration<\n\tTSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n> extends ITreeConfigurationOptions {\n\t/**\n\t * The schema which the application wants to view the tree with.\n\t */\n\treadonly schema: TSchema;\n}\n\n/**\n * Configuration for {@link ViewableTree.viewWith}.\n * @sealed @public\n */\nexport class TreeViewConfiguration<\n\tconst TSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n> implements Required<ITreeViewConfiguration<TSchema>>\n{\n\tprotected _typeCheck!: MakeNominal;\n\n\t/**\n\t * {@inheritDoc ITreeViewConfiguration.schema}\n\t */\n\tpublic readonly schema: TSchema;\n\n\t/**\n\t * {@inheritDoc ITreeConfigurationOptions.enableSchemaValidation}\n\t */\n\tpublic readonly enableSchemaValidation: boolean;\n\n\t/**\n\t * {@inheritDoc ITreeConfigurationOptions.preventAmbiguity}\n\t */\n\tpublic readonly preventAmbiguity: boolean;\n\n\t/**\n\t * {@link TreeSchema.definitions} but with public types.\n\t */\n\tprotected readonly definitionsInternal: ReadonlyMap<string, TreeNodeSchema>;\n\n\t/**\n\t * Construct a new {@link TreeViewConfiguration}.\n\t *\n\t * @param props - Property bag of configuration options.\n\t *\n\t * @remarks\n\t * Performing this construction deeply validates the provided schema.\n\t * This means that when this constructor is called, all {@link LazyItem} {@link TreeNodeSchema} references will be evaluated (using {@link evaluateLazySchema}).\n\t * This means that the declarations for all transitively reachable {@link TreeNodeSchema} must be available at this time.\n\t *\n\t * For example, a schema reachable from this configuration cannot reference this configuration during its declaration,\n\t * since this would be a cyclic dependency that will cause an error when constructing this configuration.\n\t */\n\tpublic constructor(props: ITreeViewConfiguration<TSchema>) {\n\t\tconst config = { ...defaultTreeConfigurationOptions, ...props };\n\t\tthis.schema = config.schema;\n\t\tthis.enableSchemaValidation = config.enableSchemaValidation;\n\t\tthis.preventAmbiguity = config.preventAmbiguity;\n\n\t\t// Ambiguity errors are lower priority to report than invalid schema errors, so collect these in an array and report them all at once.\n\t\tconst ambiguityErrors: string[] = [];\n\n\t\t// Eagerly perform this conversion to surface errors sooner.\n\t\t// Includes detection of duplicate schema identifiers.\n\t\ttoStoredSchema(config.schema);\n\n\t\tconst definitions = new Map<string, SimpleNodeSchema & TreeNodeSchema>();\n\n\t\twalkFieldSchema(config.schema, {\n\t\t\tnode: (schema) => {\n\t\t\t\t// Ensure all reachable schema are marked as most derived.\n\t\t\t\t// This ensures if multiple schema extending the same schema factory generated class are present (or have had instances of them constructed, or get instances of them constructed in the future),\n\t\t\t\t// an error is reported.\n\t\t\t\tmarkSchemaMostDerived(schema, true);\n\n\t\t\t\tdebugAssert(() => !definitions.has(schema.identifier));\n\t\t\t\tdefinitions.set(schema.identifier, schema as SimpleNodeSchema & TreeNodeSchema);\n\t\t\t},\n\t\t\tallowedTypes({ types }): void {\n\t\t\t\tcheckUnion(\n\t\t\t\t\ttypes.map((t) => evaluateLazySchema(isAnnotatedAllowedType(t) ? t.type : t)),\n\t\t\t\t\tconfig.preventAmbiguity,\n\t\t\t\t\tambiguityErrors,\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\n\t\tthis.definitionsInternal = definitions;\n\n\t\tif (ambiguityErrors.length !== 0) {\n\t\t\t// Duplicate errors are common since when two types conflict, both orders error:\n\t\t\tconst deduplicated = new Set(ambiguityErrors);\n\t\t\tthrow new UsageError(`Ambiguous schema found:\\n${[...deduplicated].join(\"\\n\")}`);\n\t\t}\n\t}\n}\n\n/**\n * {@link TreeViewConfiguration} extended with some alpha APIs.\n * @sealed @alpha\n */\nexport class TreeViewConfigurationAlpha<\n\t\tconst TSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n\t>\n\textends TreeViewConfiguration<TSchema>\n\timplements TreeSchema\n{\n\t/**\n\t * {@inheritDoc TreeSchema.root}\n\t */\n\tpublic readonly root: FieldSchemaAlpha;\n\n\t/**\n\t * {@inheritDoc TreeSchema.definitions}\n\t */\n\tpublic get definitions(): ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema> {\n\t\treturn this.definitionsInternal as ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema>;\n\t}\n\n\tpublic constructor(props: ITreeViewConfiguration<TSchema>) {\n\t\tsuper(props);\n\t\tthis.root = normalizeFieldSchema(props.schema);\n\t}\n}\n\n/**\n * {@link TreeViewConfigurationAlpha}\n * @sealed @alpha\n */\nexport interface TreeSchema extends SimpleTreeSchema {\n\t/**\n\t * {@inheritDoc SimpleTreeSchema.root}\n\t */\n\treadonly root: FieldSchemaAlpha;\n\n\t/**\n\t * {@inheritDoc SimpleTreeSchema.definitions}\n\t */\n\treadonly definitions: ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema>;\n}\n\n/**\n * Pretty print a set of types for use in error messages.\n */\nfunction formatTypes(allowed: Iterable<TreeNodeSchema>): string {\n\t// Use JSON.stringify to quote and escape identifiers.\n\t// Don't just use a single array JSON.stringify since that omits spaces between items\n\treturn `[${Array.from(allowed, (s) => JSON.stringify(s.identifier)).join(\", \")}]`;\n}\n\n/**\n * Check if union contents are valid (shallowly).\n *\n * @param union - The union of {@link TreeNodeSchema} to check.\n * @param preventAmbiguity - If true, detect cases documented in {@link ITreeConfigurationOptions.preventAmbiguity}, reporting them to `ambiguityErrors`.\n * @param ambiguityErrors - An array into which this function inserts any ambiguity errors, see {@link ITreeConfigurationOptions.preventAmbiguity}.\n *\n * @remarks\n * Includes checks for non-ambiguity errors as well: such as duplicate schemas in the union.\n * Any non-ambiguity errors are thrown as exceptions: `UsageError`s if causable by incorrect API use, and asserts if violating internal invariants.\n */\nexport function checkUnion(\n\tunion: Iterable<TreeNodeSchema>,\n\tpreventAmbiguity: boolean,\n\tambiguityErrors: string[],\n): void {\n\tconst checked: Set<TreeNodeSchema> = new Set();\n\tconst maps: TreeNodeSchema[] = [];\n\tconst arrays: TreeNodeSchema[] = [];\n\n\tconst objects: ObjectNodeSchema[] = [];\n\t// Map from key to schema using that key\n\tconst allObjectKeys: Map<string, Set<TreeNodeSchema>> = new Map();\n\n\tfor (const schema of union) {\n\t\tif (checked.has(schema)) {\n\t\t\tthrow new UsageError(`Duplicate schema in allowed types: ${schema.identifier}`);\n\t\t}\n\t\tchecked.add(schema);\n\n\t\tif (schema instanceof LeafNodeSchema) {\n\t\t\t// nothing to do\n\t\t} else if (isObjectNodeSchema(schema)) {\n\t\t\tobjects.push(schema);\n\t\t\tfor (const key of schema.fields.keys()) {\n\t\t\t\tgetOrCreate(allObjectKeys, key, () => new Set()).add(schema);\n\t\t\t}\n\t\t} else if (schema.kind === NodeKind.Array) {\n\t\t\tarrays.push(schema);\n\t\t} else {\n\t\t\tassert(schema.kind === NodeKind.Map, 0x9e7 /* invalid schema */);\n\t\t\tmaps.push(schema);\n\t\t}\n\t}\n\n\tif (!preventAmbiguity) {\n\t\t// All remaining checks are for the preventAmbiguity case, so skip them if not enabled.\n\t\treturn;\n\t}\n\n\tif (arrays.length > 1) {\n\t\tambiguityErrors.push(\n\t\t\t`More than one kind of array allowed within union (${formatTypes(arrays)}). This would require type disambiguation which is not supported by arrays during import or export.`,\n\t\t);\n\t}\n\n\tif (maps.length > 1) {\n\t\tambiguityErrors.push(\n\t\t\t`More than one kind of map allowed within union (${formatTypes(maps)}). This would require type disambiguation which is not supported by maps during import or export.`,\n\t\t);\n\t}\n\n\tif (maps.length > 0 && arrays.length > 0) {\n\t\tambiguityErrors.push(\n\t\t\t`Both a map and an array allowed within union (${formatTypes([...arrays, ...maps])}). Both can be implicitly constructed from iterables like arrays, which are ambiguous when the array is empty.`,\n\t\t);\n\t}\n\n\tif (objects.length > 0 && maps.length > 0) {\n\t\tambiguityErrors.push(\n\t\t\t`Both a object and a map allowed within union (${formatTypes([...objects, ...maps])}). Both can be constructed from objects and can be ambiguous.`,\n\t\t);\n\t}\n\n\t// Check for objects which fully overlap:\n\tfor (const schema of objects) {\n\t\t// All objects which might be ambiguous relative to `schema`.\n\t\tconst possiblyAmbiguous = new Set(objects);\n\n\t\t// A schema can't be ambiguous with itself\n\t\tpossiblyAmbiguous.delete(schema);\n\n\t\t// For each field of schema, remove schema from possiblyAmbiguous that do not have that field\n\t\tfor (const [key, field] of schema.fields) {\n\t\t\tif (field.kind === FieldKind.Required) {\n\t\t\t\tconst withKey = allObjectKeys.get(key) ?? fail(0xb35 /* missing schema */);\n\t\t\t\tfor (const candidate of possiblyAmbiguous) {\n\t\t\t\t\tif (!withKey.has(candidate)) {\n\t\t\t\t\t\tpossiblyAmbiguous.delete(candidate);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (possiblyAmbiguous.size > 0) {\n\t\t\t// TODO: make this check more permissive.\n\t\t\t// Allow using the type of the field to disambiguate, at least for leaf types.\n\t\t\t// Add \"constant\" fields which can be used to disambiguate even more cases without adding persisted data: maybe make them optional in constructor?\n\t\t\t// Consider separating unambiguous implicit construction format from constructor arguments at type level, allowing constructor to superset the implicit construction options (ex: optional constant fields).\n\t\t\t// The policy here however must remain at least as conservative as shallowCompatibilityTest in src/simple-tree/unhydratedFlexTreeFromInsertable.ts.\n\n\t\t\tambiguityErrors.push(\n\t\t\t\t`The required fields of ${JSON.stringify(schema.identifier)} are insufficient to differentiate it from the following types: ${formatTypes(possiblyAmbiguous)}. For objects to be considered unambiguous, each must have required fields that do not all occur on any other object in the union.`,\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -11,7 +11,7 @@ export { SchemaFactoryAlpha } from "./schemaFactoryAlpha.js";
|
|
|
11
11
|
export type { ValidateRecursiveSchema, FixRecursiveArraySchema, ValidateRecursiveSchemaTemplate, FixRecursiveRecursionLimit, } from "./schemaFactoryRecursive.js";
|
|
12
12
|
export { allowUnused } from "./schemaFactoryRecursive.js";
|
|
13
13
|
export { adaptEnum, enumFromStrings, singletonSchema, } from "./schemaCreationUtilities.js";
|
|
14
|
-
export {
|
|
14
|
+
export { getIdentifierFromNode, getPropertyKeyFromStoredKey, getStoredKey, treeNodeApi, type TreeNodeApi, tryGetSchema, } from "./treeNodeApi.js";
|
|
15
15
|
export { createFromCursor } from "./create.js";
|
|
16
16
|
export { type JsonSchemaId, type JsonSchemaType, type JsonObjectNodeSchema, type JsonArrayNodeSchema, type JsonMapNodeSchema, type JsonLeafNodeSchema, type JsonSchemaRef, type JsonRefPath, type JsonNodeSchema, type JsonNodeSchemaBase, type JsonTreeSchema, type JsonFieldSchema, type JsonLeafSchemaType, } from "./jsonSchema.js";
|
|
17
17
|
export type { TreeSchemaEncodingOptions } from "./getJsonSchema.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACX,UAAU,EACV,sBAAsB,EACtB,yBAAyB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,qBAAqB,EACrB,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACX,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,yBAAyB,EACzB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,UAAU,GACV,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACN,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,0BAA0B,EAC/B,KAAK,aAAa,EAClB,aAAa,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EACX,uBAAuB,EACvB,uBAAuB,EACvB,+BAA+B,EAC/B,0BAA0B,GAC1B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,eAAe,EACf,eAAe,GACf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACX,UAAU,EACV,sBAAsB,EACtB,yBAAyB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,qBAAqB,EACrB,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACX,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,yBAAyB,EACzB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,UAAU,GACV,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACN,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,0BAA0B,EAC/B,KAAK,aAAa,EAClB,aAAa,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EACX,uBAAuB,EACvB,uBAAuB,EACvB,+BAA+B,EAC/B,0BAA0B,GAC1B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,eAAe,EACf,eAAe,GACf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,qBAAqB,EACrB,2BAA2B,EAC3B,YAAY,EACZ,WAAW,EACX,KAAK,WAAW,EAChB,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAA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KAAK,6BAA6B,EAClC,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -8,7 +8,7 @@ export { SchemaFactory, schemaStatics, } from "./schemaFactory.js";
|
|
|
8
8
|
export { SchemaFactoryAlpha } from "./schemaFactoryAlpha.js";
|
|
9
9
|
export { allowUnused } from "./schemaFactoryRecursive.js";
|
|
10
10
|
export { adaptEnum, enumFromStrings, singletonSchema, } from "./schemaCreationUtilities.js";
|
|
11
|
-
export {
|
|
11
|
+
export { getIdentifierFromNode, getPropertyKeyFromStoredKey, getStoredKey, treeNodeApi, tryGetSchema, } from "./treeNodeApi.js";
|
|
12
12
|
export { createFromCursor } from "./create.js";
|
|
13
13
|
export { getJsonSchema } from "./getJsonSchema.js";
|
|
14
14
|
export { getSimpleSchema } from "./getSimpleSchema.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/simple-tree/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EACN,qBAAqB,EACrB,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAY5B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EACN,aAAa,EAIb,aAAa,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAO7D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EACN,SAAS,EACT,eAAe,EACf,eAAe,GACf,MAAM,8BAA8B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sB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAUN,QAAQ,GACR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport type {\n\tTreeSchema,\n\tITreeViewConfiguration,\n\tITreeConfigurationOptions,\n} from \"./configuration.js\";\nexport {\n\tTreeViewConfiguration,\n\tTreeViewConfigurationAlpha,\n} from \"./configuration.js\";\nexport type {\n\tITree,\n\tTreeView,\n\tViewableTree,\n\tTreeViewEvents,\n\tSchemaCompatibilityStatus,\n\tTreeViewAlpha,\n\tTreeBranch,\n\tTreeBranchEvents,\n\tITreeAlpha,\n} from \"./tree.js\";\nexport { asTreeViewAlpha } from \"./tree.js\";\nexport {\n\tSchemaFactory,\n\ttype ScopedSchemaName,\n\ttype SchemaFactoryObjectOptions,\n\ttype SchemaStatics,\n\tschemaStatics,\n} from \"./schemaFactory.js\";\nexport { SchemaFactoryAlpha } from \"./schemaFactoryAlpha.js\";\nexport type {\n\tValidateRecursiveSchema,\n\tFixRecursiveArraySchema,\n\tValidateRecursiveSchemaTemplate,\n\tFixRecursiveRecursionLimit,\n} from \"./schemaFactoryRecursive.js\";\nexport { allowUnused } from \"./schemaFactoryRecursive.js\";\nexport {\n\tadaptEnum,\n\tenumFromStrings,\n\tsingletonSchema,\n} from \"./schemaCreationUtilities.js\";\nexport {\n\tgetIdentifierFromNode,\n\tgetPropertyKeyFromStoredKey,\n\tgetStoredKey,\n\ttreeNodeApi,\n\ttype TreeNodeApi,\n\ttryGetSchema,\n} from \"./treeNodeApi.js\";\nexport { createFromCursor } from \"./create.js\";\nexport {\n\ttype JsonSchemaId,\n\ttype JsonSchemaType,\n\ttype JsonObjectNodeSchema,\n\ttype JsonArrayNodeSchema,\n\ttype JsonMapNodeSchema,\n\ttype JsonLeafNodeSchema,\n\ttype JsonSchemaRef,\n\ttype JsonRefPath,\n\ttype JsonNodeSchema,\n\ttype JsonNodeSchemaBase,\n\ttype JsonTreeSchema,\n\ttype JsonFieldSchema,\n\ttype JsonLeafSchemaType,\n} from \"./jsonSchema.js\";\nexport type { TreeSchemaEncodingOptions } from \"./getJsonSchema.js\";\nexport { getJsonSchema } from \"./getJsonSchema.js\";\nexport { getSimpleSchema } from \"./getSimpleSchema.js\";\nexport { SchemaCompatibilityTester } from \"./schemaCompatibilityTester.js\";\nexport type {\n\tUnenforced,\n\tFieldSchemaAlphaUnsafe,\n\tArrayNodeCustomizableSchemaUnsafe,\n\tMapNodeCustomizableSchemaUnsafe,\n\tSystem_Unsafe,\n} from \"./typesUnsafe.js\";\n\nexport {\n\ttype VerboseTreeNode,\n\ttype VerboseTree,\n\tapplySchemaToParserOptions,\n\tcursorFromVerbose,\n\tverboseFromCursor,\n\treplaceVerboseTreeHandles,\n} from \"./verboseTree.js\";\n\nexport {\n\ttype TreeEncodingOptions,\n\tcustomFromCursorStored,\n\ttype CustomTreeNode,\n\ttype CustomTreeValue,\n\ttryStoredSchemaAsArray,\n\treplaceHandles,\n\ttype HandleConverter,\n} from \"./customTree.js\";\n\nexport {\n\ttype ConciseTree,\n\tconciseFromCursor,\n\treplaceConciseTreeHandles,\n} from \"./conciseTree.js\";\n\nexport { TreeBeta, type NodeChangedData, type TreeChangeEventsBeta } from \"./treeBeta.js\";\nexport { createSimpleTreeIndex, type SimpleTreeIndex } from \"./simpleTreeIndex.js\";\nexport {\n\tcreateIdentifierIndex,\n\ttype IdentifierIndex,\n} from \"./identifierIndex.js\";\n\nexport {\n\textractPersistedSchema,\n\tcomparePersistedSchema,\n} from \"./storedSchema.js\";\n\nexport {\n\ttype TransactionConstraint,\n\ttype NodeInDocumentConstraint,\n\ttype RunTransactionParams,\n\ttype VoidTransactionCallbackStatus,\n\ttype TransactionCallbackStatus,\n\ttype TransactionResult,\n\ttype TransactionResultExt,\n\ttype TransactionResultSuccess,\n\ttype TransactionResultFailed,\n\trollback,\n} from \"./transactionTypes.js\";\n\nexport { generateSchemaFromSimpleSchema } from \"./schemaFromSimple.js\";\nexport { toSimpleTreeSchema } from \"./viewSchemaToSimpleSchema.js\";\nexport type { TreeChangeEvents } from \"./treeChangeEvents.js\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaCompatibilityTester.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaCompatibilityTester.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAE5E,OAAO,EACN,iBAAiB,GAMjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,UAAU,EAGV,8BAA8B,EAC9B,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,oBAAoB,GACpB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD;;;;GAIG;AACH,MAAM,OAAO,yBAAyB;IAMrC;;OAEG;IACH,YACiB,MAAwB,EACxB,QAAkB,EAClC,cAA2B;QAFX,WAAM,GAAN,MAAM,CAAkB;QACxB,aAAQ,GAAR,QAAQ,CAAU;QAGlC,IAAI,CAAC,kBAAkB,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;;;OASG;IACI,kBAAkB,CACxB,MAAwB;QAExB,yBAAyB;QACzB,0CAA0C;QAE1C,gHAAgH;QAChH,6HAA6H;QAC7H,sDAAsD;QACtD,8HAA8H;QAC9H,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,sIAAsI;QACtI,4CAA4C;QAC5C,IAAI,UAAU,GAAG,IAAI,CAAC;QAEtB,MAAM,uCAAuC,GAAG,CAAC,WAA6B,EAAQ,EAAE;YACvF,QAAQ,WAAW,CAAC,QAAQ,EAAE,CAAC;gB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AI,EAAE,EAAE,CAAC;gBACrD,IAAI,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;oBAClC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;oBAChC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBAC/B,CAAC;YACF,CAAC;YAED,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;QACvC,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;IAEO,SAAS,CAAC,QAA8B;QAC/C,sDAAsD;QACtD,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase, fail } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\tAdaptedViewSchema,\n\ttype TreeNodeStoredSchema,\n\ttype Adapters,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeStoredSchema,\n} from \"../../core/index.js\";\nimport {\n\tFieldKinds,\n\ttype FullSchemaPolicy,\n\ttype FieldDiscrepancy,\n\tgetAllowedContentDiscrepancies,\n\tisNeverTree,\n\tPosetComparisonResult,\n\tfieldRealizer,\n\tcomparePosetElements,\n} from \"../../feature-libraries/index.js\";\nimport type { FieldSchema } from \"../schemaTypes.js\";\nimport { toStoredSchema } from \"../toStoredSchema.js\";\n\nimport type { SchemaCompatibilityStatus } from \"./tree.js\";\n\n/**\n * A collection of View information for schema, including policy.\n * @remarks\n * This contains everything needed to determine compatibility with a given stored schema.\n */\nexport class SchemaCompatibilityTester {\n\t/**\n\t * Cached conversion of the view schema in the stored schema format.\n\t */\n\tpublic readonly viewSchemaAsStored: TreeStoredSchema;\n\n\t/**\n\t * @param viewSchemaRoot - Schema for the root field.\n\t */\n\tpublic constructor(\n\t\tpublic readonly policy: FullSchemaPolicy,\n\t\tpublic readonly adapters: Adapters,\n\t\tviewSchemaRoot: FieldSchema,\n\t) {\n\t\tthis.viewSchemaAsStored = toStoredSchema(viewSchemaRoot);\n\t}\n\n\t/**\n\t * Determines the compatibility of a stored document\n\t * (based on its stored schema) with a viewer (based on its view schema).\n\t *\n\t * Adapters can be provided to handle differences between the two schema.\n\t * Adapters should only use to types in the `view` SchemaRepository.\n\t *\n\t * TODO: this API violates the parse don't validate design philosophy.\n\t * It should be wrapped with (or replaced by) a parse style API.\n\t */\n\tpublic checkCompatibility(\n\t\tstored: TreeStoredSchema,\n\t): Omit<SchemaCompatibilityStatus, \"canInitialize\"> {\n\t\t// TODO: support adapters\n\t\t// const adapted = this.adaptRepo(stored);\n\n\t\t// View schema allows a subset of documents that stored schema does, and the discrepancies are allowed by policy\n\t\t// determined by the view schema (i.e. objects with extra optional fields in the stored schema have opted into allowing this.\n\t\t// In the future, this would also include things like:\n\t\t// - fields with more allowed types in the stored schema than in the view schema have out-of-schema \"unknown content\" adapters\n\t\tlet canView = true;\n\t\t// View schema allows a superset of documents that stored schema does, hence the document could be upgraded to use a persisted version\n\t\t// of this view schema as its stored schema.\n\t\tlet canUpgrade = true;\n\n\t\tconst updateCompatibilityFromFieldDiscrepancy = (discrepancy: FieldDiscrepancy): void => {\n\t\t\tswitch (discrepancy.mismatch) {\n\t\t\t\tcase \"allowedTypes\": {\n\t\t\t\t\t// Since we only track the symmetric difference between the allowed types in the view and\n\t\t\t\t\t// stored schemas, it's sufficient to check if any extra allowed types still exist in the\n\t\t\t\t\t// stored schema.\n\t\t\t\t\tif (\n\t\t\t\t\t\tdiscrepancy.stored.some(\n\t\t\t\t\t\t\t(identifier) =>\n\t\t\t\t\t\t\t\t!isNeverTree(this.policy, stored, stored.nodeSchema.get(identifier)),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Stored schema has extra allowed types that the view schema does not.\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tdiscrepancy.view.some(\n\t\t\t\t\t\t\t(identifier) =>\n\t\t\t\t\t\t\t\t!isNeverTree(\n\t\t\t\t\t\t\t\t\tthis.policy,\n\t\t\t\t\t\t\t\t\tthis.viewSchemaAsStored,\n\t\t\t\t\t\t\t\t\tthis.viewSchemaAsStored.nodeSchema.get(identifier),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// View schema has extra allowed types that the stored schema does not.\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"fieldKind\": {\n\t\t\t\t\tconst result = comparePosetElements(\n\t\t\t\t\t\tdiscrepancy.stored,\n\t\t\t\t\t\tdiscrepancy.view,\n\t\t\t\t\t\tfieldRealizer,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (result === PosetComparisonResult.Greater) {\n\t\t\t\t\t\t// Stored schema is more relaxed than view schema.\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tdiscrepancy.view === FieldKinds.forbidden.identifier &&\n\t\t\t\t\t\t\tdiscrepancy.identifier !== undefined &&\n\t\t\t\t\t\t\tthis.policy.allowUnknownOptionalFields(discrepancy.identifier)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// When the application has opted into it, we allow viewing documents which have additional\n\t\t\t\t\t\t\t// optional fields in the stored schema that are not present in the view schema.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (result === PosetComparisonResult.Less) {\n\t\t\t\t\t\t// View schema is more relaxed than stored schema.\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (result === PosetComparisonResult.Incomparable) {\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"valueSchema\": {\n\t\t\t\t\tcanView = false;\n\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(discrepancy);\n\t\t\t}\n\t\t};\n\n\t\tfor (const discrepancy of getAllowedContentDiscrepancies(\n\t\t\tthis.viewSchemaAsStored,\n\t\t\tstored,\n\t\t)) {\n\t\t\tif (!canView && !canUpgrade) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tswitch (discrepancy.mismatch) {\n\t\t\t\tcase \"nodeKind\": {\n\t\t\t\t\tconst viewNodeSchema = this.viewSchemaAsStored.nodeSchema.get(\n\t\t\t\t\t\tdiscrepancy.identifier,\n\t\t\t\t\t);\n\t\t\t\t\tconst storedNodeSchema = stored.nodeSchema.get(discrepancy.identifier);\n\t\t\t\t\t// We conservatively do not allow node types to change.\n\t\t\t\t\t// The only time this might be valid in the sense that the data canonically converts is converting an object node\n\t\t\t\t\t// to a map node over the union of all the object fields' types.\n\t\t\t\t\tif (discrepancy.stored === undefined) {\n\t\t\t\t\t\tconst viewIsNever =\n\t\t\t\t\t\t\tviewNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, this.viewSchemaAsStored, viewNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!viewIsNever) {\n\t\t\t\t\t\t\t// View schema has added a node type that the stored schema doesn't know about.\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (discrepancy.view === undefined) {\n\t\t\t\t\t\tconst storedIsNever =\n\t\t\t\t\t\t\tstoredNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, stored, storedNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!storedIsNever) {\n\t\t\t\t\t\t\t// Stored schema has a node type that the view schema doesn't know about.\n\t\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Node type exists in both schemas but has changed. We conservatively never allow this.\n\t\t\t\t\t\tconst storedIsNever =\n\t\t\t\t\t\t\tstoredNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, stored, storedNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tconst viewIsNever =\n\t\t\t\t\t\t\tviewNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, this.viewSchemaAsStored, viewNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!storedIsNever || !viewIsNever) {\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"valueSchema\":\n\t\t\t\tcase \"allowedTypes\":\n\t\t\t\tcase \"fieldKind\": {\n\t\t\t\t\tupdateCompatibilityFromFieldDiscrepancy(discrepancy);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"fields\": {\n\t\t\t\t\tdiscrepancy.differences.forEach(updateCompatibilityFromFieldDiscrepancy);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// No default\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tcanView,\n\t\t\tcanUpgrade,\n\t\t\tisEquivalent: canView && canUpgrade,\n\t\t};\n\t}\n\n\t/**\n\t * Compute a schema that `original` could be viewed as using adapters as needed.\n\t *\n\t * TODO: have a way for callers to get invalidated on schema updates.\n\t */\n\tpublic adaptRepo(stored: TreeStoredSchema): AdaptedViewSchema {\n\t\t// Sanity check on adapters:\n\t\t// it's probably a bug if they use the never types,\n\t\t// since there never is a reason to have a never type as an adapter input,\n\t\t// and its impossible for an adapter to be correctly implemented if its output type is never\n\t\t// (unless its input is also never).\n\n\t\tfor (const adapter of this.adapters?.tree ?? []) {\n\t\t\tif (\n\t\t\t\tisNeverTree(\n\t\t\t\t\tthis.policy,\n\t\t\t\t\tthis.viewSchemaAsStored,\n\t\t\t\t\tthis.viewSchemaAsStored.nodeSchema.get(adapter.output),\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tfail(0xb3d /* tree adapter for stored adapter.output should not be never */);\n\t\t\t}\n\t\t}\n\n\t\tconst adapted = {\n\t\t\trootFieldSchema: this.adaptField(stored.rootFieldSchema),\n\t\t\tnodeSchema: new Map<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>(),\n\t\t};\n\n\t\tfor (const [key, schema] of stored.nodeSchema) {\n\t\t\tconst adapatedTree = this.adaptTree(schema);\n\t\t\tadapted.nodeSchema.set(key, adapatedTree);\n\t\t}\n\n\t\t// TODO: subset these adapters to the ones that were needed/used.\n\t\treturn new AdaptedViewSchema(this.adapters, adapted);\n\t}\n\n\t/**\n\t * Adapt original such that it allows member types which can be adapted to its specified types.\n\t */\n\tprivate adaptField(original: TreeFieldStoredSchema): TreeFieldStoredSchema {\n\t\tif (original.types !== undefined) {\n\t\t\tconst types: Set<TreeNodeSchemaIdentifier> = new Set(original.types);\n\t\t\tfor (const treeAdapter of this.adapters?.tree ?? []) {\n\t\t\t\tif (types.has(treeAdapter.input)) {\n\t\t\t\t\ttypes.delete(treeAdapter.input);\n\t\t\t\t\ttypes.add(treeAdapter.output);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { kind: original.kind, types };\n\t\t}\n\t\treturn original;\n\t}\n\n\tprivate adaptTree(original: TreeNodeStoredSchema): TreeNodeStoredSchema {\n\t\t// TODO: support adapters like missing field adapters.\n\t\treturn original;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"schemaCompatibilityTester.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaCompatibilityTester.ts"],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C;QACrE,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;IAEO,SAAS,CAAC,QAA8B;QAC/C,sDAAsD;QACtD,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase, fail } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\tAdaptedViewSchema,\n\ttype TreeNodeStoredSchema,\n\ttype Adapters,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeStoredSchema,\n} from \"../../core/index.js\";\nimport {\n\tFieldKinds,\n\ttype FullSchemaPolicy,\n\ttype FieldDiscrepancy,\n\tgetAllowedContentDiscrepancies,\n\tisNeverTree,\n\tPosetComparisonResult,\n\tfieldRealizer,\n\tcomparePosetElements,\n} from \"../../feature-libraries/index.js\";\nimport type { FieldSchema } from \"../schemaTypes.js\";\nimport { toStoredSchema } from \"../toStoredSchema.js\";\n\nimport type { SchemaCompatibilityStatus } from \"./tree.js\";\n\n/**\n * A collection of View information for schema, including policy.\n * @remarks\n * This contains everything needed to determine compatibility with a given stored schema.\n */\nexport class SchemaCompatibilityTester {\n\t/**\n\t * Cached conversion of the view schema in the stored schema format.\n\t */\n\tpublic readonly viewSchemaAsStored: TreeStoredSchema;\n\n\t/**\n\t * @param viewSchemaRoot - Schema for the root field.\n\t */\n\tpublic constructor(\n\t\tpublic readonly policy: FullSchemaPolicy,\n\t\tpublic readonly adapters: Adapters,\n\t\tviewSchemaRoot: FieldSchema,\n\t) {\n\t\tthis.viewSchemaAsStored = toStoredSchema(viewSchemaRoot);\n\t}\n\n\t/**\n\t * Determines the compatibility of a stored document\n\t * (based on its stored schema) with a viewer (based on its view schema).\n\t *\n\t * Adapters can be provided to handle differences between the two schema.\n\t * Adapters should only use to types in the `view` SchemaRepository.\n\t *\n\t * TODO: this API violates the parse don't validate design philosophy.\n\t * It should be wrapped with (or replaced by) a parse style API.\n\t */\n\tpublic checkCompatibility(\n\t\tstored: TreeStoredSchema,\n\t): Omit<SchemaCompatibilityStatus, \"canInitialize\"> {\n\t\t// TODO: support adapters\n\t\t// const adapted = this.adaptRepo(stored);\n\n\t\t// View schema allows a subset of documents that stored schema does, and the discrepancies are allowed by policy\n\t\t// determined by the view schema (i.e. objects with extra optional fields in the stored schema have opted into allowing this.\n\t\t// In the future, this would also include things like:\n\t\t// - fields with more allowed types in the stored schema than in the view schema have out-of-schema \"unknown content\" adapters\n\t\tlet canView = true;\n\t\t// View schema allows a superset of documents that stored schema does, hence the document could be upgraded to use a persisted version\n\t\t// of this view schema as its stored schema.\n\t\tlet canUpgrade = true;\n\n\t\tconst updateCompatibilityFromFieldDiscrepancy = (discrepancy: FieldDiscrepancy): void => {\n\t\t\tswitch (discrepancy.mismatch) {\n\t\t\t\tcase \"allowedTypes\": {\n\t\t\t\t\t// Since we only track the symmetric difference between the allowed types in the view and\n\t\t\t\t\t// stored schemas, it's sufficient to check if any extra allowed types still exist in the\n\t\t\t\t\t// stored schema.\n\t\t\t\t\tif (\n\t\t\t\t\t\tdiscrepancy.stored.some(\n\t\t\t\t\t\t\t(identifier) =>\n\t\t\t\t\t\t\t\t!isNeverTree(this.policy, stored, stored.nodeSchema.get(identifier)),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Stored schema has extra allowed types that the view schema does not.\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tdiscrepancy.view.some(\n\t\t\t\t\t\t\t(identifier) =>\n\t\t\t\t\t\t\t\t!isNeverTree(\n\t\t\t\t\t\t\t\t\tthis.policy,\n\t\t\t\t\t\t\t\t\tthis.viewSchemaAsStored,\n\t\t\t\t\t\t\t\t\tthis.viewSchemaAsStored.nodeSchema.get(identifier),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\t// View schema has extra allowed types that the stored schema does not.\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"fieldKind\": {\n\t\t\t\t\tconst result = comparePosetElements(\n\t\t\t\t\t\tdiscrepancy.stored,\n\t\t\t\t\t\tdiscrepancy.view,\n\t\t\t\t\t\tfieldRealizer,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (result === PosetComparisonResult.Greater) {\n\t\t\t\t\t\t// Stored schema is more relaxed than view schema.\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tdiscrepancy.view === FieldKinds.forbidden.identifier &&\n\t\t\t\t\t\t\tdiscrepancy.identifier !== undefined &&\n\t\t\t\t\t\t\tthis.policy.allowUnknownOptionalFields(discrepancy.identifier)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// When the application has opted into it, we allow viewing documents which have additional\n\t\t\t\t\t\t\t// optional fields in the stored schema that are not present in the view schema.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (result === PosetComparisonResult.Less) {\n\t\t\t\t\t\t// View schema is more relaxed than stored schema.\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (result === PosetComparisonResult.Incomparable) {\n\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"valueSchema\": {\n\t\t\t\t\tcanView = false;\n\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(discrepancy);\n\t\t\t}\n\t\t};\n\n\t\tfor (const discrepancy of getAllowedContentDiscrepancies(\n\t\t\tthis.viewSchemaAsStored,\n\t\t\tstored,\n\t\t)) {\n\t\t\tif (!canView && !canUpgrade) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tswitch (discrepancy.mismatch) {\n\t\t\t\tcase \"nodeKind\": {\n\t\t\t\t\tconst viewNodeSchema = this.viewSchemaAsStored.nodeSchema.get(\n\t\t\t\t\t\tdiscrepancy.identifier,\n\t\t\t\t\t);\n\t\t\t\t\tconst storedNodeSchema = stored.nodeSchema.get(discrepancy.identifier);\n\t\t\t\t\t// We conservatively do not allow node types to change.\n\t\t\t\t\t// The only time this might be valid in the sense that the data canonically converts is converting an object node\n\t\t\t\t\t// to a map node over the union of all the object fields' types.\n\t\t\t\t\tif (discrepancy.stored === undefined) {\n\t\t\t\t\t\tconst viewIsNever =\n\t\t\t\t\t\t\tviewNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, this.viewSchemaAsStored, viewNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!viewIsNever) {\n\t\t\t\t\t\t\t// View schema has added a node type that the stored schema doesn't know about.\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (discrepancy.view === undefined) {\n\t\t\t\t\t\tconst storedIsNever =\n\t\t\t\t\t\t\tstoredNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, stored, storedNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!storedIsNever) {\n\t\t\t\t\t\t\t// Stored schema has a node type that the view schema doesn't know about.\n\t\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Node type exists in both schemas but has changed. We conservatively never allow this.\n\t\t\t\t\t\tconst storedIsNever =\n\t\t\t\t\t\t\tstoredNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, stored, storedNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tconst viewIsNever =\n\t\t\t\t\t\t\tviewNodeSchema !== undefined\n\t\t\t\t\t\t\t\t? isNeverTree(this.policy, this.viewSchemaAsStored, viewNodeSchema)\n\t\t\t\t\t\t\t\t: true;\n\t\t\t\t\t\tif (!storedIsNever || !viewIsNever) {\n\t\t\t\t\t\t\tcanView = false;\n\t\t\t\t\t\t\tcanUpgrade = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"valueSchema\":\n\t\t\t\tcase \"allowedTypes\":\n\t\t\t\tcase \"fieldKind\": {\n\t\t\t\t\tupdateCompatibilityFromFieldDiscrepancy(discrepancy);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"fields\": {\n\t\t\t\t\tdiscrepancy.differences.forEach(updateCompatibilityFromFieldDiscrepancy);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// No default\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tcanView,\n\t\t\tcanUpgrade,\n\t\t\tisEquivalent: canView && canUpgrade,\n\t\t};\n\t}\n\n\t/**\n\t * Compute a schema that `original` could be viewed as using adapters as needed.\n\t *\n\t * TODO: have a way for callers to get invalidated on schema updates.\n\t */\n\tpublic adaptRepo(stored: TreeStoredSchema): AdaptedViewSchema {\n\t\t// Sanity check on adapters:\n\t\t// it's probably a bug if they use the never types,\n\t\t// since there never is a reason to have a never type as an adapter input,\n\t\t// and its impossible for an adapter to be correctly implemented if its output type is never\n\t\t// (unless its input is also never).\n\n\t\tfor (const adapter of this.adapters?.tree ?? []) {\n\t\t\tif (\n\t\t\t\tisNeverTree(\n\t\t\t\t\tthis.policy,\n\t\t\t\t\tthis.viewSchemaAsStored,\n\t\t\t\t\tthis.viewSchemaAsStored.nodeSchema.get(adapter.output),\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tfail(0xb3d /* tree adapter for stored adapter.output should not be never */);\n\t\t\t}\n\t\t}\n\n\t\tconst adapted = {\n\t\t\trootFieldSchema: this.adaptField(stored.rootFieldSchema),\n\t\t\tnodeSchema: new Map<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>(),\n\t\t};\n\n\t\tfor (const [key, schema] of stored.nodeSchema) {\n\t\t\tconst adapatedTree = this.adaptTree(schema);\n\t\t\tadapted.nodeSchema.set(key, adapatedTree);\n\t\t}\n\n\t\t// TODO: subset these adapters to the ones that were needed/used.\n\t\treturn new AdaptedViewSchema(this.adapters, adapted);\n\t}\n\n\t/**\n\t * Adapt original such that it allows member types which can be adapted to its specified types.\n\t */\n\tprivate adaptField(original: TreeFieldStoredSchema): TreeFieldStoredSchema {\n\t\tif (original.types !== undefined) {\n\t\t\tconst types: Set<TreeNodeSchemaIdentifier> = new Set(original.types);\n\t\t\tfor (const treeAdapter of this.adapters?.tree ?? []) {\n\t\t\t\tif (types.has(treeAdapter.input)) {\n\t\t\t\t\ttypes.delete(treeAdapter.input);\n\t\t\t\t\ttypes.add(treeAdapter.output);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { kind: original.kind, types, persistedMetadata: undefined };\n\t\t}\n\t\treturn original;\n\t}\n\n\tprivate adaptTree(original: TreeNodeStoredSchema): TreeNodeStoredSchema {\n\t\t// TODO: support adapters like missing field adapters.\n\t\treturn original;\n\t}\n}\n"]}
|