@fluidframework/tree 2.53.1 → 2.60.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/.eslintrc.cjs +0 -19
- package/.mocharc.customBenchmarks.cjs +1 -9
- package/CHANGELOG.md +56 -0
- package/api-report/tree.alpha.api.md +50 -36
- package/api-report/tree.beta.api.md +15 -1
- package/api-report/{tree.legacy.alpha.api.md → tree.legacy.beta.api.md} +5 -5
- package/api-report/tree.legacy.public.api.md +1 -1
- package/api-report/tree.public.api.md +1 -1
- package/dist/alpha.d.ts +8 -2
- package/dist/beta.d.ts +3 -0
- package/dist/codec/codec.d.ts +43 -6
- package/dist/codec/codec.d.ts.map +1 -1
- package/dist/codec/codec.js +22 -2
- package/dist/codec/codec.js.map +1 -1
- package/dist/codec/index.d.ts +1 -1
- package/dist/codec/index.d.ts.map +1 -1
- package/dist/codec/index.js +4 -1
- package/dist/codec/index.js.map +1 -1
- package/dist/external-utilities/index.d.ts +1 -1
- package/dist/external-utilities/index.d.ts.map +1 -1
- package/dist/external-utilities/index.js +2 -1
- package/dist/external-utilities/index.js.map +1 -1
- package/dist/external-utilities/typeboxValidator.d.ts +6 -1
- package/dist/external-utilities/typeboxValidator.d.ts.map +1 -1
- package/dist/external-utilities/typeboxValidator.js +7 -1
- package/dist/external-utilities/typeboxValidator.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +10 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +28 -5
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +19 -2
- package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +10 -2
- package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +59 -4
- package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.js +9 -2
- package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +46 -8
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +91 -16
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format.d.ts +14 -0
- package/dist/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format.js +10 -1
- package/dist/feature-libraries/chunked-forest/codec/format.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/index.d.ts +1 -1
- package/dist/feature-libraries/chunked-forest/codec/index.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/index.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts +8 -3
- package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +17 -6
- package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/index.d.ts +1 -1
- package/dist/feature-libraries/chunked-forest/index.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/index.js.map +1 -1
- package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/codec.js +3 -0
- package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +13 -8
- package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.js +76 -38
- package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
- package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +178 -0
- package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -0
- package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +322 -0
- package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -0
- package/dist/feature-libraries/forest-summary/index.d.ts +1 -1
- package/dist/feature-libraries/forest-summary/index.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/index.js +2 -1
- package/dist/feature-libraries/forest-summary/index.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +1 -1
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +2 -1
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +2 -2
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts +6 -9
- package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
- package/dist/feature-libraries/treeCompressionUtils.d.ts +15 -0
- package/dist/feature-libraries/treeCompressionUtils.d.ts.map +1 -1
- package/dist/feature-libraries/treeCompressionUtils.js +16 -1
- package/dist/feature-libraries/treeCompressionUtils.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/jsonDomainSchema.d.ts +1 -1
- package/dist/jsonDomainSchema.d.ts.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/schematizingTreeView.d.ts +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +23 -6
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +4 -1
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/sharedTreeChangeFamily.d.ts +2 -2
- package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
- package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
- package/dist/shared-tree/tree.d.ts.map +1 -1
- package/dist/shared-tree/tree.js +3 -0
- package/dist/shared-tree/tree.js.map +1 -1
- package/dist/shared-tree/treeAlpha.d.ts +9 -11
- package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
- package/dist/shared-tree/treeAlpha.js.map +1 -1
- package/dist/shared-tree/treeCheckout.d.ts +2 -2
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +13 -0
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/sharedTreeAttributes.d.ts +2 -2
- package/dist/sharedTreeAttributes.js +2 -2
- package/dist/sharedTreeAttributes.js.map +1 -1
- package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/conciseTree.js +1 -1
- package/dist/simple-tree/api/conciseTree.js.map +1 -1
- package/dist/simple-tree/api/customTree.d.ts +39 -11
- package/dist/simple-tree/api/customTree.d.ts.map +1 -1
- package/dist/simple-tree/api/customTree.js +79 -19
- package/dist/simple-tree/api/customTree.js.map +1 -1
- package/dist/simple-tree/api/getJsonSchema.d.ts +7 -2
- package/dist/simple-tree/api/getJsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/getJsonSchema.js +1 -0
- package/dist/simple-tree/api/getJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +2 -1
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +4 -1
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.d.ts +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.js +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +9 -6
- package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactory.js +8 -7
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +13 -17
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.js +21 -25
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryBeta.d.ts +20 -0
- package/dist/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -0
- package/dist/simple-tree/api/schemaFactoryBeta.js +26 -0
- package/dist/simple-tree/api/schemaFactoryBeta.js.map +1 -0
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts +0 -2
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +6 -3
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/transactionTypes.d.ts +1 -0
- package/dist/simple-tree/api/transactionTypes.d.ts.map +1 -1
- package/dist/simple-tree/api/transactionTypes.js.map +1 -1
- package/dist/simple-tree/api/tree.d.ts +68 -74
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/verboseTree.js +3 -3
- package/dist/simple-tree/api/verboseTree.js.map +1 -1
- package/dist/simple-tree/core/simpleNodeSchemaBase.d.ts +6 -0
- package/dist/simple-tree/core/simpleNodeSchemaBase.d.ts.map +1 -1
- package/dist/simple-tree/core/simpleNodeSchemaBase.js.map +1 -1
- package/dist/simple-tree/fieldSchema.d.ts +3 -4
- package/dist/simple-tree/fieldSchema.d.ts.map +1 -1
- package/dist/simple-tree/fieldSchema.js +0 -3
- package/dist/simple-tree/fieldSchema.js.map +1 -1
- package/dist/simple-tree/index.d.ts +1 -1
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +4 -2
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNode.js +2 -3
- package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
- package/dist/simple-tree/simpleSchema.d.ts +12 -0
- 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 +0 -3
- package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/dist/simple-tree/toStoredSchema.js +0 -3
- package/dist/simple-tree/toStoredSchema.js.map +1 -1
- package/dist/tableSchema.d.ts +11 -80
- package/dist/tableSchema.d.ts.map +1 -1
- package/dist/tableSchema.js +200 -117
- package/dist/tableSchema.js.map +1 -1
- package/dist/treeFactory.d.ts +1 -2
- package/dist/treeFactory.d.ts.map +1 -1
- package/dist/treeFactory.js +1 -2
- package/dist/treeFactory.js.map +1 -1
- package/lib/alpha.d.ts +8 -2
- package/lib/beta.d.ts +3 -0
- package/lib/codec/codec.d.ts +43 -6
- package/lib/codec/codec.d.ts.map +1 -1
- package/lib/codec/codec.js +19 -1
- package/lib/codec/codec.js.map +1 -1
- package/lib/codec/index.d.ts +1 -1
- package/lib/codec/index.d.ts.map +1 -1
- package/lib/codec/index.js +1 -1
- package/lib/codec/index.js.map +1 -1
- package/lib/external-utilities/index.d.ts +1 -1
- package/lib/external-utilities/index.d.ts.map +1 -1
- package/lib/external-utilities/index.js +1 -1
- package/lib/external-utilities/index.js.map +1 -1
- package/lib/external-utilities/typeboxValidator.d.ts +6 -1
- package/lib/external-utilities/typeboxValidator.d.ts.map +1 -1
- package/lib/external-utilities/typeboxValidator.js +6 -0
- package/lib/external-utilities/typeboxValidator.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +10 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +27 -5
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +19 -2
- package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +10 -2
- package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +59 -4
- package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/codecs.js +10 -3
- package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +46 -8
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +87 -14
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format.d.ts +14 -0
- package/lib/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format.js +9 -0
- package/lib/feature-libraries/chunked-forest/codec/format.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/index.d.ts +1 -1
- package/lib/feature-libraries/chunked-forest/codec/index.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/index.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts +8 -3
- package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +18 -7
- package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/index.d.ts +1 -1
- package/lib/feature-libraries/chunked-forest/index.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/index.js.map +1 -1
- package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/codec.js +3 -0
- package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +13 -8
- package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.js +75 -37
- package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
- package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +178 -0
- package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -0
- package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +318 -0
- package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -0
- package/lib/feature-libraries/forest-summary/index.d.ts +1 -1
- package/lib/feature-libraries/forest-summary/index.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/index.js +1 -1
- package/lib/feature-libraries/forest-summary/index.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +1 -1
- 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/modular-schema/modularChangeCodecs.d.ts +2 -2
- package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +3 -3
- package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts +6 -9
- package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
- package/lib/feature-libraries/treeCompressionUtils.d.ts +15 -0
- package/lib/feature-libraries/treeCompressionUtils.d.ts.map +1 -1
- package/lib/feature-libraries/treeCompressionUtils.js +15 -0
- package/lib/feature-libraries/treeCompressionUtils.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/jsonDomainSchema.d.ts +1 -1
- package/lib/jsonDomainSchema.d.ts.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/schematizingTreeView.d.ts +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +23 -6
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +4 -1
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/sharedTreeChangeFamily.d.ts +2 -2
- package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
- package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
- package/lib/shared-tree/tree.d.ts.map +1 -1
- package/lib/shared-tree/tree.js +3 -0
- package/lib/shared-tree/tree.js.map +1 -1
- package/lib/shared-tree/treeAlpha.d.ts +9 -11
- package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
- package/lib/shared-tree/treeAlpha.js.map +1 -1
- package/lib/shared-tree/treeCheckout.d.ts +2 -2
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +13 -0
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/sharedTreeAttributes.d.ts +2 -2
- package/lib/sharedTreeAttributes.js +2 -2
- package/lib/sharedTreeAttributes.js.map +1 -1
- package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/conciseTree.js +2 -2
- package/lib/simple-tree/api/conciseTree.js.map +1 -1
- package/lib/simple-tree/api/customTree.d.ts +39 -11
- package/lib/simple-tree/api/customTree.d.ts.map +1 -1
- package/lib/simple-tree/api/customTree.js +79 -19
- package/lib/simple-tree/api/customTree.js.map +1 -1
- package/lib/simple-tree/api/getJsonSchema.d.ts +7 -2
- package/lib/simple-tree/api/getJsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/getJsonSchema.js +1 -0
- package/lib/simple-tree/api/getJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +2 -1
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +2 -1
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.d.ts +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.js +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +9 -6
- package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactory.js +6 -6
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +13 -17
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.js +22 -26
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryBeta.d.ts +20 -0
- package/lib/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -0
- package/lib/simple-tree/api/schemaFactoryBeta.js +22 -0
- package/lib/simple-tree/api/schemaFactoryBeta.js.map +1 -0
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts +0 -2
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +6 -3
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/transactionTypes.d.ts +1 -0
- package/lib/simple-tree/api/transactionTypes.d.ts.map +1 -1
- package/lib/simple-tree/api/transactionTypes.js.map +1 -1
- package/lib/simple-tree/api/tree.d.ts +68 -74
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/verboseTree.js +4 -4
- package/lib/simple-tree/api/verboseTree.js.map +1 -1
- package/lib/simple-tree/core/simpleNodeSchemaBase.d.ts +6 -0
- package/lib/simple-tree/core/simpleNodeSchemaBase.d.ts.map +1 -1
- package/lib/simple-tree/core/simpleNodeSchemaBase.js.map +1 -1
- package/lib/simple-tree/fieldSchema.d.ts +3 -4
- package/lib/simple-tree/fieldSchema.d.ts.map +1 -1
- package/lib/simple-tree/fieldSchema.js +0 -3
- package/lib/simple-tree/fieldSchema.js.map +1 -1
- package/lib/simple-tree/index.d.ts +1 -1
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +1 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNode.js +2 -3
- package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
- package/lib/simple-tree/simpleSchema.d.ts +12 -0
- 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 +0 -3
- package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/lib/simple-tree/toStoredSchema.js +0 -3
- package/lib/simple-tree/toStoredSchema.js.map +1 -1
- package/lib/tableSchema.d.ts +11 -80
- package/lib/tableSchema.d.ts.map +1 -1
- package/lib/tableSchema.js +201 -118
- package/lib/tableSchema.js.map +1 -1
- package/lib/treeFactory.d.ts +1 -2
- package/lib/treeFactory.d.ts.map +1 -1
- package/lib/treeFactory.js +1 -2
- package/lib/treeFactory.js.map +1 -1
- package/package.json +21 -21
- package/src/codec/codec.ts +52 -7
- package/src/codec/index.ts +4 -0
- package/src/external-utilities/index.ts +1 -1
- package/src/external-utilities/typeboxValidator.ts +7 -1
- package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +38 -4
- package/src/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.ts +10 -3
- package/src/feature-libraries/chunked-forest/codec/codecs.ts +96 -8
- package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +123 -19
- package/src/feature-libraries/chunked-forest/codec/format.ts +11 -0
- package/src/feature-libraries/chunked-forest/codec/index.ts +4 -0
- package/src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts +28 -3
- package/src/feature-libraries/chunked-forest/index.ts +2 -0
- package/src/feature-libraries/forest-summary/codec.ts +3 -0
- package/src/feature-libraries/forest-summary/forestSummarizer.ts +118 -50
- package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +511 -0
- package/src/feature-libraries/forest-summary/index.ts +1 -1
- package/src/feature-libraries/index.ts +5 -1
- package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +8 -4
- package/src/feature-libraries/treeCompressionUtils.ts +19 -0
- package/src/index.ts +6 -1
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/schematizingTreeView.ts +1 -1
- package/src/shared-tree/sharedTree.ts +37 -4
- package/src/shared-tree/sharedTreeChangeFamily.ts +2 -2
- package/src/shared-tree/tree.ts +3 -0
- package/src/shared-tree/treeAlpha.ts +10 -11
- package/src/shared-tree/treeCheckout.ts +2 -2
- package/src/shared-tree-core/sharedTreeCore.ts +17 -0
- package/src/sharedTreeAttributes.ts +2 -2
- package/src/simple-tree/api/conciseTree.ts +2 -1
- package/src/simple-tree/api/customTree.ts +102 -32
- package/src/simple-tree/api/getJsonSchema.ts +7 -2
- package/src/simple-tree/api/index.ts +3 -0
- package/src/simple-tree/api/schemaCreationUtilities.ts +1 -1
- package/src/simple-tree/api/schemaFactory.ts +21 -14
- package/src/simple-tree/api/schemaFactoryAlpha.ts +29 -30
- package/src/simple-tree/api/schemaFactoryBeta.ts +28 -0
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +7 -3
- package/src/simple-tree/api/transactionTypes.ts +1 -0
- package/src/simple-tree/api/tree.ts +75 -81
- package/src/simple-tree/api/verboseTree.ts +42 -39
- package/src/simple-tree/core/simpleNodeSchemaBase.ts +6 -0
- package/src/simple-tree/fieldSchema.ts +3 -4
- package/src/simple-tree/index.ts +3 -0
- package/src/simple-tree/node-kinds/record/recordNode.ts +2 -3
- package/src/simple-tree/simpleSchema.ts +12 -0
- package/src/simple-tree/toStoredSchema.ts +0 -3
- package/src/tableSchema.ts +261 -243
- package/src/treeFactory.ts +1 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forestSummarizer.js","sourceRoot":"","sources":["../../../src/feature-libraries/forest-summary/forestSummarizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAC9D,kEAA6D;AAQ7D,0EAAsF;AAGtF,kDAY6B;AAM7B,kDAA2D;AAC3D,yDAAkF;AAGlF,yCAAyE;AAEzE;;GAEG;AACU,QAAA,WAAW,GAAG,YAAY,CAAC;AAExC;;GAEG;AACH,MAAa,gBAAgB;IAK5B;;OAEG;IACH,YACkB,MAAuB,EACvB,gBAAkC,EACnD,eAAgC,EACf,cAAyC,EAC1D,OAA0B,EACT,YAA2B;QAL3B,WAAM,GAAN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M,CAAC,OAAO,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAC9D,IAAA,qBAAU,EACT,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,YAAY,CAAC,EAAE,EACxC,SAAS,EACT,IAAI,CAAC,MAAM,EACX,IAAA,iCAAsB,EAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,YAAY,CAAC,CACxE,CAAC;QACH,CAAC;IACF,CAAC;CACD;AA7FD,4CA6FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\nimport type {\n\tIExperimentalIncrementalSummaryContext,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { createSingleBlobSummary } from \"@fluidframework/shared-object-base/internal\";\n\nimport type { CodecWriteOptions } from \"../../codec/index.js\";\nimport {\n\ttype DeltaDetachedNodeBuild,\n\ttype DeltaFieldChanges,\n\ttype FieldKey,\n\ttype IEditableForest,\n\ttype ITreeCursorSynchronous,\n\ttype ITreeSubscriptionCursor,\n\ttype RevisionTagCodec,\n\tTreeNavigationResult,\n\tapplyDelta,\n\tforEachField,\n\tmakeDetachedFieldIndex,\n} from \"../../core/index.js\";\nimport type {\n\tSummarizable,\n\tSummaryElementParser,\n\tSummaryElementStringifier,\n} from \"../../shared-tree-core/index.js\";\nimport { idAllocatorFromMaxId } from \"../../util/index.js\";\nimport { chunkFieldSingle, defaultChunkPolicy } from \"../chunked-forest/index.js\";\nimport type { FieldBatchCodec, FieldBatchEncodingContext } from \"../chunked-forest/index.js\";\n\nimport { type ForestCodec, makeForestSummarizerCodec } from \"./codec.js\";\nimport type { Format } from \"./format.js\";\n/**\n * The storage key for the blob in the summary containing tree data\n */\nexport const treeBlobKey = \"ForestTree\";\n\n/**\n * Provides methods for summarizing and loading a forest.\n */\nexport class ForestSummarizer implements Summarizable {\n\tpublic readonly key = \"Forest\";\n\n\tprivate readonly codec: ForestCodec;\n\n\t/**\n\t * @param encoderContext - The schema if provided here must be mutated by the caller to keep it up to date.\n\t */\n\tpublic constructor(\n\t\tprivate readonly forest: IEditableForest,\n\t\tprivate readonly revisionTagCodec: RevisionTagCodec,\n\t\tfieldBatchCodec: FieldBatchCodec,\n\t\tprivate readonly encoderContext: FieldBatchEncodingContext,\n\t\toptions: CodecWriteOptions,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t) {\n\t\t// TODO: this should take in CodecWriteOptions, and use it to pick the write version.\n\t\tthis.codec = makeForestSummarizerCodec(options, fieldBatchCodec);\n\t}\n\n\t/**\n\t * Synchronous monolithic summarization of tree content.\n\t *\n\t * TODO: when perf matters, this should be replaced with a chunked async version using a binary format.\n\t *\n\t * @returns a snapshot of the forest's tree as a string.\n\t */\n\tprivate getTreeString(stringify: SummaryElementStringifier): string {\n\t\tconst rootCursor = this.forest.getCursorAboveDetachedFields();\n\t\tconst fieldMap: Map<FieldKey, ITreeCursorSynchronous & ITreeSubscriptionCursor> =\n\t\t\tnew Map();\n\t\t// TODO: Encode all detached fields in one operation for better performance and compression\n\t\tforEachField(rootCursor, (cursor) => {\n\t\t\tconst key = cursor.getFieldKey();\n\t\t\tconst innerCursor = this.forest.allocateCursor(\"getTreeString\");\n\t\t\tassert(\n\t\t\t\tthis.forest.tryMoveCursorToField({ fieldKey: key, parent: undefined }, innerCursor) ===\n\t\t\t\t\tTreeNavigationResult.Ok,\n\t\t\t\t0x892 /* failed to navigate to field */,\n\t\t\t);\n\t\t\tfieldMap.set(key, innerCursor as ITreeCursorSynchronous & ITreeSubscriptionCursor);\n\t\t});\n\t\tconst encoded = this.codec.encode(fieldMap, this.encoderContext);\n\n\t\tfieldMap.forEach((value) => value.free());\n\t\treturn stringify(encoded);\n\t}\n\n\tpublic summarize(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\t\treturn createSingleBlobSummary(treeBlobKey, this.getTreeString(props.stringify));\n\t}\n\n\tpublic async load(\n\t\tservices: IChannelStorageService,\n\t\tparse: SummaryElementParser,\n\t): Promise<void> {\n\t\tif (await services.contains(treeBlobKey)) {\n\t\t\tconst treeBuffer = await services.readBlob(treeBlobKey);\n\t\t\tconst treeBufferString = bufferToString(treeBuffer, \"utf8\");\n\t\t\t// TODO: this code is parsing data without an optional validator, this should be defined in a typebox schema as part of the\n\t\t\t// forest summary format.\n\t\t\tconst fields = this.codec.decode(parse(treeBufferString) as Format, this.encoderContext);\n\t\t\tconst allocator = idAllocatorFromMaxId();\n\t\t\tconst fieldChanges: [FieldKey, DeltaFieldChanges][] = [];\n\t\t\tconst build: DeltaDetachedNodeBuild[] = [];\n\t\t\tfor (const [fieldKey, field] of fields) {\n\t\t\t\tconst chunked = chunkFieldSingle(field, {\n\t\t\t\t\tpolicy: defaultChunkPolicy,\n\t\t\t\t\tidCompressor: this.idCompressor,\n\t\t\t\t});\n\t\t\t\tconst buildId = { minor: allocator.allocate(chunked.topLevelLength) };\n\t\t\t\tbuild.push({\n\t\t\t\t\tid: buildId,\n\t\t\t\t\ttrees: chunked,\n\t\t\t\t});\n\t\t\t\tfieldChanges.push([fieldKey, [{ count: chunked.topLevelLength, attach: buildId }]]);\n\t\t\t}\n\n\t\t\tassert(this.forest.isEmpty, 0x797 /* forest must be empty */);\n\t\t\tapplyDelta(\n\t\t\t\t{ build, fields: new Map(fieldChanges) },\n\t\t\t\tundefined,\n\t\t\t\tthis.forest,\n\t\t\t\tmakeDetachedFieldIndex(\"init\", this.revisionTagCodec, this.idCompressor),\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"forestSummarizer.js","sourceRoot":"","sources":["../../../src/feature-libraries/forest-summary/forestSummarizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAC9D,kEAA6D;AAU7D,kDAa6B;AAM7B,kDAAgF;AAChF,sDAAsD;AACtD,iEAAsF;AAGtF,yCAAyE;AACzE,iFAIwC;AACxC,wEAA6E;AAG7E;;;;GAIG;AACU,QAAA,gBAAgB,GAAG,QAAQ,CAAC;AAEzC;;GAEG;AACH,MAAa,gBAAgB;IAO5B;;OAEG;IACH,YACkB,MAAuB,EACvB,gBAAkC,EACnD,eAAgC,EACf,cAAyC,EAC1D,OAA0B,EACT,YAA2B,EAC5C,8BAGY;QATK,WAAM,GAAN,MAAM,CAAiB;QACvB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAElC,mBAAc,GAAd,cAAc,CAA2B;QAEzC,iBAAY,GAAZ,YAAY,CAAe;QAf7B,QAAG,GAAG,wBAAgB,CAAC;QAqBtC,qFAAqF;QACrF,IAAI,CAAC,KAAK,GAAG,IAAA,oCAAyB,EAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAEjE,MAAM,mCAAmC,GAAG,CAC3C,cAAwC,EACxC,QAAkB,EACR,EAAE,CAAC,8BAA8B,EAAE,CAAC,cAAc,EAAE,QAAQ,CAAC,IAAI,KAAK,CAAC;QAClF,IAAI,CAAC,yBAAyB,GAAG,IAAI,8DAA+B,CACnE,cAAc,CAAC,UAAU;YACxB,yDAA+B,CAAC,qBAAqB,CAAC,8BAA8B,EACrF,CAAC,MAA8B,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAClE,mCAAmC,CACnC,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACI,SAAS,CAAC,KAMhB;QACA,MAAM,EAAE,SAAS,EAAE,QAAQ,GAAG,KAAK,EAAE,yBAAyB,EAAE,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,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACtE,KAAK,CAAC,IAAI,CAAC;gBACV,EAAE,EAAE,OAAO;gBACX,KAAK,EAAE,OAAO;aACd,CAAC,CAAC;YACH,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QACrF,CAAC;QAED,IAAA,iBAAM,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9D,IAAA,qBAAU,EACT,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,YAAY,CAAC,EAAE,EACxC,SAAS,EACT,IAAI,CAAC,MAAM,EACX,IAAA,iCAAsB,EAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,YAAY,CAAC,CACxE,CAAC;IACH,CAAC;CACD;AAvJD,4CAuJC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\nimport type {\n\tIExperimentalIncrementalSummaryContext,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions/internal\";\n\nimport type { CodecWriteOptions } from \"../../codec/index.js\";\nimport {\n\ttype DeltaDetachedNodeBuild,\n\ttype DeltaFieldChanges,\n\ttype FieldKey,\n\ttype IEditableForest,\n\ttype ITreeCursorSynchronous,\n\ttype ITreeSubscriptionCursor,\n\ttype RevisionTagCodec,\n\tTreeNavigationResult,\n\ttype TreeNodeSchemaIdentifier,\n\tapplyDelta,\n\tforEachField,\n\tmakeDetachedFieldIndex,\n} from \"../../core/index.js\";\nimport type {\n\tSummarizable,\n\tSummaryElementParser,\n\tSummaryElementStringifier,\n} from \"../../shared-tree-core/index.js\";\nimport { idAllocatorFromMaxId, type JsonCompatible } from \"../../util/index.js\";\n// eslint-disable-next-line import/no-internal-modules\nimport { chunkFieldSingle, defaultChunkPolicy } from \"../chunked-forest/chunkTree.js\";\nimport type { FieldBatchCodec, FieldBatchEncodingContext } from \"../chunked-forest/index.js\";\n\nimport { type ForestCodec, makeForestSummarizerCodec } from \"./codec.js\";\nimport {\n\tForestIncrementalSummaryBehavior,\n\tForestIncrementalSummaryBuilder,\n\tforestSummaryContentKey,\n} from \"./incrementalSummaryBuilder.js\";\nimport { TreeCompressionStrategyExtended } from \"../treeCompressionUtils.js\";\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\n\n/**\n * The key for the tree that contains the overall forest's summary tree.\n * This tree is added by the parent of the forest summarizer.\n * See {@link ForestIncrementalSummaryBuilder} for details on the summary structure.\n */\nexport const forestSummaryKey = \"Forest\";\n\n/**\n * Provides methods for summarizing and loading a forest.\n */\nexport class ForestSummarizer implements Summarizable {\n\tpublic readonly key = forestSummaryKey;\n\n\tprivate readonly codec: ForestCodec;\n\n\tprivate readonly incrementalSummaryBuilder: ForestIncrementalSummaryBuilder;\n\n\t/**\n\t * @param encoderContext - The schema if provided here must be mutated by the caller to keep it up to date.\n\t */\n\tpublic constructor(\n\t\tprivate readonly forest: IEditableForest,\n\t\tprivate readonly revisionTagCodec: RevisionTagCodec,\n\t\tfieldBatchCodec: FieldBatchCodec,\n\t\tprivate readonly encoderContext: FieldBatchEncodingContext,\n\t\toptions: CodecWriteOptions,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t\tshouldEncodeFieldIncrementally?: (\n\t\t\tnodeIdentifier: TreeNodeSchemaIdentifier,\n\t\t\tfieldKey: FieldKey,\n\t\t) => boolean,\n\t) {\n\t\t// TODO: this should take in CodecWriteOptions, and use it to pick the write version.\n\t\tthis.codec = makeForestSummarizerCodec(options, fieldBatchCodec);\n\n\t\tconst shouldEncodeFieldIncrementallyLocal = (\n\t\t\tnodeIdentifier: TreeNodeSchemaIdentifier,\n\t\t\tfieldKey: FieldKey,\n\t\t): boolean => shouldEncodeFieldIncrementally?.(nodeIdentifier, fieldKey) ?? false;\n\t\tthis.incrementalSummaryBuilder = new ForestIncrementalSummaryBuilder(\n\t\t\tencoderContext.encodeType ===\n\t\t\t\tTreeCompressionStrategyExtended.CompressedIncremental /* enableIncrementalSummary */,\n\t\t\t(cursor: ITreeCursorSynchronous) => this.forest.chunkField(cursor),\n\t\t\tshouldEncodeFieldIncrementallyLocal,\n\t\t);\n\t}\n\n\t/**\n\t * Summarization of the forest's tree content.\n\t * @returns a summary tree containing the forest's tree content.\n\t * @remarks\n\t * If incremental summary is disabled, all the content will be added to a single summary blob.\n\t * If incremental summary is enabled, the summary will be a tree.\n\t * See {@link ForestIncrementalSummaryBuilder} for details of what this tree looks like.\n\t *\n\t * TODO: when perf matters, this should be replaced with a chunked async version using a binary format.\n\t */\n\tpublic summarize(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\t\tconst { stringify, fullTree = false, incrementalSummaryContext } = props;\n\n\t\tconst rootCursor = this.forest.getCursorAboveDetachedFields();\n\t\tconst fieldMap: Map<FieldKey, ITreeCursorSynchronous & ITreeSubscriptionCursor> =\n\t\t\tnew Map();\n\t\t// TODO: Encode all detached fields in one operation for better performance and compression\n\t\tforEachField(rootCursor, (cursor) => {\n\t\t\tconst key = cursor.getFieldKey();\n\t\t\tconst innerCursor = this.forest.allocateCursor(\"getTreeString\");\n\t\t\tassert(\n\t\t\t\tthis.forest.tryMoveCursorToField({ fieldKey: key, parent: undefined }, innerCursor) ===\n\t\t\t\t\tTreeNavigationResult.Ok,\n\t\t\t\t0x892 /* failed to navigate to field */,\n\t\t\t);\n\t\t\tfieldMap.set(key, innerCursor as ITreeCursorSynchronous & ITreeSubscriptionCursor);\n\t\t});\n\n\t\t// Let the incremental summary builder know that we are starting a new summary.\n\t\t// It returns whether incremental encoding is enabled.\n\t\tconst incrementalSummaryBehavior = this.incrementalSummaryBuilder.startSummary({\n\t\t\tfullTree,\n\t\t\tincrementalSummaryContext,\n\t\t\tstringify,\n\t\t});\n\t\tconst encoderContext: FieldBatchEncodingContext = {\n\t\t\t...this.encoderContext,\n\t\t\tincrementalEncoderDecoder:\n\t\t\t\tincrementalSummaryBehavior === ForestIncrementalSummaryBehavior.Incremental\n\t\t\t\t\t? this.incrementalSummaryBuilder\n\t\t\t\t\t: undefined,\n\t\t};\n\t\tconst encoded = this.codec.encode(fieldMap, encoderContext);\n\t\tfieldMap.forEach((value) => value.free());\n\n\t\treturn this.incrementalSummaryBuilder.completeSummary({\n\t\t\tincrementalSummaryContext,\n\t\t\tforestSummaryContent: stringify(encoded),\n\t\t});\n\t}\n\n\tpublic async load(\n\t\tservices: IChannelStorageService,\n\t\tparse: SummaryElementParser,\n\t): Promise<void> {\n\t\t// The contents of the top-level forest must be present under a summary blob named `forestSummaryContentKey`.\n\t\t// If the summary was generated as `ForestIncrementalSummaryBehavior.SingleBlob`, this blob will contain all\n\t\t// of forest's contents.\n\t\t// If the summary was generated as `ForestIncrementalSummaryBehavior.Incremental`, this blob will contain only\n\t\t// the top-level forest node's contents.\n\t\t// The contents of the incremental chunks will be in separate tree nodes and will be read later during decoding.\n\t\tassert(\n\t\t\tawait services.contains(forestSummaryContentKey),\n\t\t\t0xc21 /* Forest summary content missing in snapshot */,\n\t\t);\n\n\t\tconst readAndParseBlob = async <T extends JsonCompatible<IFluidHandle>>(\n\t\t\tid: string,\n\t\t): Promise<T> => {\n\t\t\tconst treeBuffer = await services.readBlob(id);\n\t\t\tconst treeBufferString = bufferToString(treeBuffer, \"utf8\");\n\t\t\treturn parse(treeBufferString) as T;\n\t\t};\n\n\t\t// Load the incremental summary builder so that it can download any incremental chunks in the\n\t\t// snapshot.\n\t\tawait this.incrementalSummaryBuilder.load(services, readAndParseBlob);\n\n\t\t// TODO: this code is parsing data without an optional validator, this should be defined in a typebox schema as part of the\n\t\t// forest summary format.\n\t\tconst fields = this.codec.decode(await readAndParseBlob(forestSummaryContentKey), {\n\t\t\t...this.encoderContext,\n\t\t\tincrementalEncoderDecoder: this.incrementalSummaryBuilder,\n\t\t});\n\t\tconst allocator = idAllocatorFromMaxId();\n\t\tconst fieldChanges: [FieldKey, DeltaFieldChanges][] = [];\n\t\tconst build: DeltaDetachedNodeBuild[] = [];\n\t\tfor (const [fieldKey, field] of fields) {\n\t\t\tconst chunked = chunkFieldSingle(field, {\n\t\t\t\tpolicy: defaultChunkPolicy,\n\t\t\t\tidCompressor: this.idCompressor,\n\t\t\t});\n\t\t\tconst buildId = { minor: allocator.allocate(chunked.topLevelLength) };\n\t\t\tbuild.push({\n\t\t\t\tid: buildId,\n\t\t\t\ttrees: chunked,\n\t\t\t});\n\t\t\tfieldChanges.push([fieldKey, [{ count: chunked.topLevelLength, attach: buildId }]]);\n\t\t}\n\n\t\tassert(this.forest.isEmpty, 0x797 /* forest must be empty */);\n\t\tapplyDelta(\n\t\t\t{ build, fields: new Map(fieldChanges) },\n\t\t\tundefined,\n\t\t\tthis.forest,\n\t\t\tmakeDetachedFieldIndex(\"init\", this.revisionTagCodec, this.idCompressor),\n\t\t);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { IExperimentalIncrementalSummaryContext, ISummaryTreeWithStats } from "@fluidframework/runtime-definitions/internal";
|
|
6
|
+
import { type JsonCompatible } from "../../util/index.js";
|
|
7
|
+
import type { ChunkReferenceId, EncodedFieldBatch, IncrementalEncoderDecoder, TreeChunk } from "../chunked-forest/index.js";
|
|
8
|
+
import type { FieldKey, ITreeCursorSynchronous, TreeNodeSchemaIdentifier } from "../../core/index.js";
|
|
9
|
+
import type { IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
|
|
10
|
+
import type { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
11
|
+
import type { SummaryElementStringifier } from "../../shared-tree-core/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* The key for the blob under ForestSummarizer's root.
|
|
14
|
+
* This blob contains the ForestCodec's output.
|
|
15
|
+
* See {@link ForestIncrementalSummaryBuilder} for details on the summary structure.
|
|
16
|
+
*/
|
|
17
|
+
export declare const forestSummaryContentKey = "ForestTree";
|
|
18
|
+
/**
|
|
19
|
+
* State that tells whether a summary is currently being tracked.
|
|
20
|
+
*/
|
|
21
|
+
export declare const ForestSummaryTrackingState: {
|
|
22
|
+
/** A summary is currently being tracked. */
|
|
23
|
+
readonly Tracking: "Tracking";
|
|
24
|
+
/** A summary is ready to be tracked. */
|
|
25
|
+
readonly ReadyToTrack: "ReadyToTrack";
|
|
26
|
+
};
|
|
27
|
+
export type ForestSummaryTrackingState = (typeof ForestSummaryTrackingState)[keyof typeof ForestSummaryTrackingState];
|
|
28
|
+
/**
|
|
29
|
+
* The behavior of the forest's incremental summary - whether the summary should be a single blob or incremental.
|
|
30
|
+
*/
|
|
31
|
+
export declare enum ForestIncrementalSummaryBehavior {
|
|
32
|
+
/**
|
|
33
|
+
* The forest can encode chunks incrementally, i.e., chunks that support incremental encoding will be encoded
|
|
34
|
+
* separately - they will be added to a separate tree.
|
|
35
|
+
* The incremental summary format is described in {@link ForestIncrementalSummaryBuilder}.
|
|
36
|
+
*/
|
|
37
|
+
Incremental = 0,
|
|
38
|
+
/**
|
|
39
|
+
* The forest should encode all of it's data in a single summary blob.
|
|
40
|
+
* @remarks
|
|
41
|
+
* The format of the summary will be the same as the old format (pre-incremental summaries) and is fully
|
|
42
|
+
* backwards compatible with the old format. The summary will basically look like an incremental summary
|
|
43
|
+
* with no incremental fields - it will only contain the "ForestTree" blob in the summary format described
|
|
44
|
+
* in {@link ForestIncrementalSummaryBuilder}.
|
|
45
|
+
*/
|
|
46
|
+
SingleBlob = 1
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Tracks and builds the incremental summary tree for a forest where chunks that support incremental encoding are
|
|
50
|
+
* stored in a separate tree in the summary under its {@link ChunkReferenceId}.
|
|
51
|
+
* The summary tree for a chunk is self-sufficient and can be independently loaded and used to reconstruct the
|
|
52
|
+
* chunk's contents without any additional context from its parent.
|
|
53
|
+
*
|
|
54
|
+
* An example summary tree with incremental summary:
|
|
55
|
+
* Forest
|
|
56
|
+
* ├── ForestTree
|
|
57
|
+
* ├── 0
|
|
58
|
+
* | ├── contents
|
|
59
|
+
* | ├── 1
|
|
60
|
+
* | | ├── contents
|
|
61
|
+
* | | ├── 2
|
|
62
|
+
* | | | ├── contents
|
|
63
|
+
* | ├── 3 - ".../Forest/ForestTree/0/1/3"
|
|
64
|
+
* ├── 4
|
|
65
|
+
* | ├── contents
|
|
66
|
+
* | ├── ...
|
|
67
|
+
* ├── 5 - "/.../Forest/ForestTree/5"
|
|
68
|
+
* - Forest is a summary tree node added by the shared tree and contains the following:
|
|
69
|
+
* - The inline portion of the top-level forest content is stored in a summary blob called "ForestTree".
|
|
70
|
+
* It also contains the {@link ChunkReferenceId}s of the incremental chunks under it.
|
|
71
|
+
* - The summary for each incremental chunk under it is stored against its {@link ChunkReferenceId}.
|
|
72
|
+
* - For each chunk, the structure of the summary tree is the same as the Forest. It contains the following:
|
|
73
|
+
* - The inline portion of the chunk content is stored in a blob called "contents".
|
|
74
|
+
* It also contains the {@link ChunkReferenceId}s of the incremental chunks under it.
|
|
75
|
+
* - The summary for each incremental chunk under it is stored against its {@link ChunkReferenceId}.
|
|
76
|
+
* - Chunks that do not change between summaries are summarized as handles in the summary tree.
|
|
77
|
+
* @remarks
|
|
78
|
+
* It may seem inconsistent that although the structure for the top-level forest tree is similar to that of
|
|
79
|
+
* an incremental chunk, its content is stored in a summary blob called "ForestTree" while the content for
|
|
80
|
+
* the incremental chunks are stored in a summary blob called "contents".
|
|
81
|
+
* This is to keep this summary backwards compatible with old format (before incremental summaries were added)
|
|
82
|
+
* where the entire forest content was in a summary blob called "ForestTree". So, if incremental summaries were
|
|
83
|
+
* disabled, the forest content will be fully backwards compatible.
|
|
84
|
+
* Note that this limits reusing the root node in a location other than root and a non-root node in the root.
|
|
85
|
+
* We could phase this out by switching to write the top-level contents under "contents" if we want to support
|
|
86
|
+
* the above. However, there is no plan to do that for now.
|
|
87
|
+
*
|
|
88
|
+
* TODO: AB#46752
|
|
89
|
+
* Add strong types for the summary structure to document it better. It will help make it super clear what the actual
|
|
90
|
+
* format is in a way that can easily be linked to, documented and inspected.
|
|
91
|
+
*/
|
|
92
|
+
export declare class ForestIncrementalSummaryBuilder implements IncrementalEncoderDecoder {
|
|
93
|
+
private readonly enableIncrementalSummary;
|
|
94
|
+
private readonly getChunkAtCursor;
|
|
95
|
+
/**
|
|
96
|
+
* {@link IncrementalEncoder.shouldEncodeFieldIncrementally}
|
|
97
|
+
*/
|
|
98
|
+
readonly shouldEncodeFieldIncrementally: (nodeIdentifier: TreeNodeSchemaIdentifier, fieldKey: FieldKey) => boolean;
|
|
99
|
+
/**
|
|
100
|
+
* The next reference ID to use for a chunk.
|
|
101
|
+
*/
|
|
102
|
+
private nextReferenceId;
|
|
103
|
+
/**
|
|
104
|
+
* For a given summary sequence number, keeps track of a chunk's properties that will be used to generate
|
|
105
|
+
* a summary handle for the chunk if it does not change between summaries.
|
|
106
|
+
*/
|
|
107
|
+
private readonly chunkTrackingPropertiesMap;
|
|
108
|
+
/**
|
|
109
|
+
* The state indicating whether a summary is currently being tracked or not.
|
|
110
|
+
*/
|
|
111
|
+
forestSummaryState: ForestSummaryTrackingState;
|
|
112
|
+
/**
|
|
113
|
+
* The sequence number of the latest summary that was successful.
|
|
114
|
+
*/
|
|
115
|
+
private latestSummarySequenceNumber;
|
|
116
|
+
/**
|
|
117
|
+
* The current state of the summary being tracked.
|
|
118
|
+
* This is undefined if no summary is currently being tracked.
|
|
119
|
+
*/
|
|
120
|
+
private trackedSummaryProperties;
|
|
121
|
+
/**
|
|
122
|
+
* A map of chunk reference IDs to their encoded contents. This is typically used during the loading of the
|
|
123
|
+
* forest to retrieve the contents of the chunks that were summarized incrementally.
|
|
124
|
+
*/
|
|
125
|
+
private readonly encodedChunkContentsMap;
|
|
126
|
+
constructor(enableIncrementalSummary: boolean, getChunkAtCursor: (cursor: ITreeCursorSynchronous) => TreeChunk,
|
|
127
|
+
/**
|
|
128
|
+
* {@link IncrementalEncoder.shouldEncodeFieldIncrementally}
|
|
129
|
+
*/
|
|
130
|
+
shouldEncodeFieldIncrementally: (nodeIdentifier: TreeNodeSchemaIdentifier, fieldKey: FieldKey) => boolean);
|
|
131
|
+
/**
|
|
132
|
+
* Must be called when the forest is loaded to download the encoded contents of incremental chunks.
|
|
133
|
+
* @param services - The channel storage service to use to access the snapshot tree and download the
|
|
134
|
+
* contents of the chunks.
|
|
135
|
+
* @param readAndParse - A function that reads and parses a blob from the storage service.
|
|
136
|
+
*/
|
|
137
|
+
load(services: IChannelStorageService, readAndParseChunk: <T extends JsonCompatible<IFluidHandle>>(id: string) => Promise<T>): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Must be called when starting a new forest summary to track it.
|
|
140
|
+
* @param fullTree - Whether the summary is a full tree summary. If true, the summary will not contain
|
|
141
|
+
* any summary handles. All chunks must be summarized in full.
|
|
142
|
+
* @param incrementalSummaryContext - The context for the incremental summary that contains the sequence numbers
|
|
143
|
+
* for the current and latest summaries.
|
|
144
|
+
* @param stringify - Serializes content (including {@link (IFluidHandle:interface)}s) for adding to a summary blob.
|
|
145
|
+
* @returns the behavior of the forest's incremental summary.
|
|
146
|
+
*/
|
|
147
|
+
startSummary(args: {
|
|
148
|
+
fullTree: boolean;
|
|
149
|
+
incrementalSummaryContext: IExperimentalIncrementalSummaryContext | undefined;
|
|
150
|
+
stringify: SummaryElementStringifier;
|
|
151
|
+
}): ForestIncrementalSummaryBehavior;
|
|
152
|
+
/**
|
|
153
|
+
* {@link IncrementalEncoder.encodeIncrementalField}
|
|
154
|
+
* @remarks Returns an empty array if the field has no content.
|
|
155
|
+
*/
|
|
156
|
+
encodeIncrementalField(cursor: ITreeCursorSynchronous, chunkEncoder: (chunk: TreeChunk) => EncodedFieldBatch): ChunkReferenceId[];
|
|
157
|
+
/**
|
|
158
|
+
* Must be called after summary generation is complete to finish tracking the summary.
|
|
159
|
+
* It clears any tracking state and deletes the tracking properties for summaries that are older than the
|
|
160
|
+
* latest successful summary.
|
|
161
|
+
* @param incrementalSummaryContext - The context for the incremental summary that contains the sequence numbers.
|
|
162
|
+
* If this is undefined, the summary tree will only contain a summary blob for `forestSummaryContent`.
|
|
163
|
+
* @param forestSummaryContent - The stringified ForestCodec output of top-level Forest content.
|
|
164
|
+
* @returns the Forest's summary tree.
|
|
165
|
+
*/
|
|
166
|
+
completeSummary(args: {
|
|
167
|
+
incrementalSummaryContext: IExperimentalIncrementalSummaryContext | undefined;
|
|
168
|
+
forestSummaryContent: string;
|
|
169
|
+
}): ISummaryTreeWithStats;
|
|
170
|
+
/**
|
|
171
|
+
* Called to get the encoded contents of an incremental chunk with the given reference ID.
|
|
172
|
+
* This is typically used when loading the forest to retrieve the contents of incremental chunks.
|
|
173
|
+
* @param referenceId - The reference ID of the chunk to retrieve.
|
|
174
|
+
* @returns The encoded contents of the chunk.
|
|
175
|
+
*/
|
|
176
|
+
getEncodedIncrementalChunk(referenceId: ChunkReferenceId): EncodedFieldBatch;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=incrementalSummaryBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incrementalSummaryBuilder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|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ForestIncrementalSummaryBuilder = exports.ForestIncrementalSummaryBehavior = exports.ForestSummaryTrackingState = exports.forestSummaryContentKey = void 0;
|
|
8
|
+
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
9
|
+
const internal_2 = require("@fluidframework/runtime-utils/internal");
|
|
10
|
+
const index_js_1 = require("../../util/index.js");
|
|
11
|
+
const driver_definitions_1 = require("@fluidframework/driver-definitions");
|
|
12
|
+
const internal_3 = require("@fluidframework/telemetry-utils/internal");
|
|
13
|
+
/**
|
|
14
|
+
* The key for the blob under ForestSummarizer's root.
|
|
15
|
+
* This blob contains the ForestCodec's output.
|
|
16
|
+
* See {@link ForestIncrementalSummaryBuilder} for details on the summary structure.
|
|
17
|
+
*/
|
|
18
|
+
exports.forestSummaryContentKey = "ForestTree";
|
|
19
|
+
/**
|
|
20
|
+
* The contents of an incremental chunk is under a summary tree node with its {@link ChunkReferenceId} as the key.
|
|
21
|
+
* The inline portion of the chunk content is encoded with the forest codec is stored in a blob with this key.
|
|
22
|
+
* The rest of the chunk contents is stored in the summary tree under the summary tree node.
|
|
23
|
+
* See the summary format in {@link ForestIncrementalSummaryBuilder} for more details.
|
|
24
|
+
*/
|
|
25
|
+
const chunkContentsBlobKey = "contents";
|
|
26
|
+
/**
|
|
27
|
+
* State that tells whether a summary is currently being tracked.
|
|
28
|
+
*/
|
|
29
|
+
exports.ForestSummaryTrackingState = {
|
|
30
|
+
/** A summary is currently being tracked. */
|
|
31
|
+
Tracking: "Tracking",
|
|
32
|
+
/** A summary is ready to be tracked. */
|
|
33
|
+
ReadyToTrack: "ReadyToTrack",
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The behavior of the forest's incremental summary - whether the summary should be a single blob or incremental.
|
|
37
|
+
*/
|
|
38
|
+
var ForestIncrementalSummaryBehavior;
|
|
39
|
+
(function (ForestIncrementalSummaryBehavior) {
|
|
40
|
+
/**
|
|
41
|
+
* The forest can encode chunks incrementally, i.e., chunks that support incremental encoding will be encoded
|
|
42
|
+
* separately - they will be added to a separate tree.
|
|
43
|
+
* The incremental summary format is described in {@link ForestIncrementalSummaryBuilder}.
|
|
44
|
+
*/
|
|
45
|
+
ForestIncrementalSummaryBehavior[ForestIncrementalSummaryBehavior["Incremental"] = 0] = "Incremental";
|
|
46
|
+
/**
|
|
47
|
+
* The forest should encode all of it's data in a single summary blob.
|
|
48
|
+
* @remarks
|
|
49
|
+
* The format of the summary will be the same as the old format (pre-incremental summaries) and is fully
|
|
50
|
+
* backwards compatible with the old format. The summary will basically look like an incremental summary
|
|
51
|
+
* with no incremental fields - it will only contain the "ForestTree" blob in the summary format described
|
|
52
|
+
* in {@link ForestIncrementalSummaryBuilder}.
|
|
53
|
+
*/
|
|
54
|
+
ForestIncrementalSummaryBehavior[ForestIncrementalSummaryBehavior["SingleBlob"] = 1] = "SingleBlob";
|
|
55
|
+
})(ForestIncrementalSummaryBehavior || (exports.ForestIncrementalSummaryBehavior = ForestIncrementalSummaryBehavior = {}));
|
|
56
|
+
/**
|
|
57
|
+
* Validates that a summary is currently being tracked and that the tracked summary properties are defined.
|
|
58
|
+
* @param forestSummaryState - The current state of the forest summary tracking.
|
|
59
|
+
* @param trackedSummaryProperties - The properties of the tracked summary, which must be available.
|
|
60
|
+
*/
|
|
61
|
+
function validateTrackingSummary(forestSummaryState, trackedSummaryProperties) {
|
|
62
|
+
(0, internal_1.assert)(forestSummaryState === exports.ForestSummaryTrackingState.Tracking, 0xc22 /* Not tracking a summary */);
|
|
63
|
+
(0, internal_1.assert)(trackedSummaryProperties !== undefined, 0xc23 /* Tracked summary properties must be available when tracking a summary */);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Validates that a summary is ready to be tracked and that the tracked summary properties are undefined.
|
|
67
|
+
* @param forestSummaryState - The current state of the forest summary tracking.
|
|
68
|
+
* @param trackedSummaryProperties - The properties of the tracked summary, which must be undefined.
|
|
69
|
+
*/
|
|
70
|
+
function validateReadyToTrackSummary(forestSummaryState, trackedSummaryProperties) {
|
|
71
|
+
(0, internal_1.assert)(forestSummaryState === exports.ForestSummaryTrackingState.ReadyToTrack, 0xc24 /* Already tracking a summary */);
|
|
72
|
+
(0, internal_1.assert)(trackedSummaryProperties === undefined, 0xc25 /* Tracked summary properties must not be available when ready to track */);
|
|
73
|
+
}
|
|
74
|
+
/* eslint-disable jsdoc/check-indentation */
|
|
75
|
+
/**
|
|
76
|
+
* Tracks and builds the incremental summary tree for a forest where chunks that support incremental encoding are
|
|
77
|
+
* stored in a separate tree in the summary under its {@link ChunkReferenceId}.
|
|
78
|
+
* The summary tree for a chunk is self-sufficient and can be independently loaded and used to reconstruct the
|
|
79
|
+
* chunk's contents without any additional context from its parent.
|
|
80
|
+
*
|
|
81
|
+
* An example summary tree with incremental summary:
|
|
82
|
+
* Forest
|
|
83
|
+
* ├── ForestTree
|
|
84
|
+
* ├── 0
|
|
85
|
+
* | ├── contents
|
|
86
|
+
* | ├── 1
|
|
87
|
+
* | | ├── contents
|
|
88
|
+
* | | ├── 2
|
|
89
|
+
* | | | ├── contents
|
|
90
|
+
* | ├── 3 - ".../Forest/ForestTree/0/1/3"
|
|
91
|
+
* ├── 4
|
|
92
|
+
* | ├── contents
|
|
93
|
+
* | ├── ...
|
|
94
|
+
* ├── 5 - "/.../Forest/ForestTree/5"
|
|
95
|
+
* - Forest is a summary tree node added by the shared tree and contains the following:
|
|
96
|
+
* - The inline portion of the top-level forest content is stored in a summary blob called "ForestTree".
|
|
97
|
+
* It also contains the {@link ChunkReferenceId}s of the incremental chunks under it.
|
|
98
|
+
* - The summary for each incremental chunk under it is stored against its {@link ChunkReferenceId}.
|
|
99
|
+
* - For each chunk, the structure of the summary tree is the same as the Forest. It contains the following:
|
|
100
|
+
* - The inline portion of the chunk content is stored in a blob called "contents".
|
|
101
|
+
* It also contains the {@link ChunkReferenceId}s of the incremental chunks under it.
|
|
102
|
+
* - The summary for each incremental chunk under it is stored against its {@link ChunkReferenceId}.
|
|
103
|
+
* - Chunks that do not change between summaries are summarized as handles in the summary tree.
|
|
104
|
+
* @remarks
|
|
105
|
+
* It may seem inconsistent that although the structure for the top-level forest tree is similar to that of
|
|
106
|
+
* an incremental chunk, its content is stored in a summary blob called "ForestTree" while the content for
|
|
107
|
+
* the incremental chunks are stored in a summary blob called "contents".
|
|
108
|
+
* This is to keep this summary backwards compatible with old format (before incremental summaries were added)
|
|
109
|
+
* where the entire forest content was in a summary blob called "ForestTree". So, if incremental summaries were
|
|
110
|
+
* disabled, the forest content will be fully backwards compatible.
|
|
111
|
+
* Note that this limits reusing the root node in a location other than root and a non-root node in the root.
|
|
112
|
+
* We could phase this out by switching to write the top-level contents under "contents" if we want to support
|
|
113
|
+
* the above. However, there is no plan to do that for now.
|
|
114
|
+
*
|
|
115
|
+
* TODO: AB#46752
|
|
116
|
+
* Add strong types for the summary structure to document it better. It will help make it super clear what the actual
|
|
117
|
+
* format is in a way that can easily be linked to, documented and inspected.
|
|
118
|
+
*/
|
|
119
|
+
/* eslint-enable jsdoc/check-indentation */
|
|
120
|
+
class ForestIncrementalSummaryBuilder {
|
|
121
|
+
constructor(enableIncrementalSummary, getChunkAtCursor,
|
|
122
|
+
/**
|
|
123
|
+
* {@link IncrementalEncoder.shouldEncodeFieldIncrementally}
|
|
124
|
+
*/
|
|
125
|
+
shouldEncodeFieldIncrementally) {
|
|
126
|
+
this.enableIncrementalSummary = enableIncrementalSummary;
|
|
127
|
+
this.getChunkAtCursor = getChunkAtCursor;
|
|
128
|
+
this.shouldEncodeFieldIncrementally = shouldEncodeFieldIncrementally;
|
|
129
|
+
/**
|
|
130
|
+
* The next reference ID to use for a chunk.
|
|
131
|
+
*/
|
|
132
|
+
this.nextReferenceId = (0, index_js_1.brand)(0);
|
|
133
|
+
/**
|
|
134
|
+
* For a given summary sequence number, keeps track of a chunk's properties that will be used to generate
|
|
135
|
+
* a summary handle for the chunk if it does not change between summaries.
|
|
136
|
+
*/
|
|
137
|
+
this.chunkTrackingPropertiesMap = new Map();
|
|
138
|
+
/**
|
|
139
|
+
* The state indicating whether a summary is currently being tracked or not.
|
|
140
|
+
*/
|
|
141
|
+
this.forestSummaryState = exports.ForestSummaryTrackingState.ReadyToTrack;
|
|
142
|
+
/**
|
|
143
|
+
* The sequence number of the latest summary that was successful.
|
|
144
|
+
*/
|
|
145
|
+
this.latestSummarySequenceNumber = -1;
|
|
146
|
+
/**
|
|
147
|
+
* A map of chunk reference IDs to their encoded contents. This is typically used during the loading of the
|
|
148
|
+
* forest to retrieve the contents of the chunks that were summarized incrementally.
|
|
149
|
+
*/
|
|
150
|
+
this.encodedChunkContentsMap = new Map();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Must be called when the forest is loaded to download the encoded contents of incremental chunks.
|
|
154
|
+
* @param services - The channel storage service to use to access the snapshot tree and download the
|
|
155
|
+
* contents of the chunks.
|
|
156
|
+
* @param readAndParse - A function that reads and parses a blob from the storage service.
|
|
157
|
+
*/
|
|
158
|
+
async load(services, readAndParseChunk) {
|
|
159
|
+
const forestTree = services.getSnapshotTree?.();
|
|
160
|
+
// Snapshot tree should be available when loading forest's contents. However, it is an optional function
|
|
161
|
+
// and may not be implemented by the storage service.
|
|
162
|
+
if (forestTree === undefined) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// Downloads the contents of incremental chunks in the given snapshot tree. Also, recursively downloads
|
|
166
|
+
// the contents of incremental chunks in any sub-trees.
|
|
167
|
+
const downloadChunkContentsInTree = async (snapshotTree, parentTreeKey) => {
|
|
168
|
+
// All trees in the snapshot tree are for incremental chunks. The key is the chunk's reference ID
|
|
169
|
+
// and the value is the snapshot tree for the chunk.
|
|
170
|
+
for (const [chunkReferenceId, chunkSnapshotTree] of Object.entries(snapshotTree.trees)) {
|
|
171
|
+
const chunkSubTreePath = `${parentTreeKey}${chunkReferenceId}`;
|
|
172
|
+
const chunkContentsPath = `${chunkSubTreePath}/${chunkContentsBlobKey}`;
|
|
173
|
+
if (!(await services.contains(chunkContentsPath))) {
|
|
174
|
+
throw new internal_3.LoggingError(`SharedTree: Cannot find contents for incremental chunk ${chunkContentsPath}`);
|
|
175
|
+
}
|
|
176
|
+
const chunkContents = await readAndParseChunk(chunkContentsPath);
|
|
177
|
+
this.encodedChunkContentsMap.set(chunkReferenceId, chunkContents);
|
|
178
|
+
// Recursively download the contents of chunks in this chunk's sub tree.
|
|
179
|
+
await downloadChunkContentsInTree(chunkSnapshotTree, `${chunkSubTreePath}/`);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
await downloadChunkContentsInTree(forestTree, "");
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Must be called when starting a new forest summary to track it.
|
|
186
|
+
* @param fullTree - Whether the summary is a full tree summary. If true, the summary will not contain
|
|
187
|
+
* any summary handles. All chunks must be summarized in full.
|
|
188
|
+
* @param incrementalSummaryContext - The context for the incremental summary that contains the sequence numbers
|
|
189
|
+
* for the current and latest summaries.
|
|
190
|
+
* @param stringify - Serializes content (including {@link (IFluidHandle:interface)}s) for adding to a summary blob.
|
|
191
|
+
* @returns the behavior of the forest's incremental summary.
|
|
192
|
+
*/
|
|
193
|
+
startSummary(args) {
|
|
194
|
+
const { fullTree, incrementalSummaryContext, stringify } = args;
|
|
195
|
+
// If there is no incremental summary context, do not summarize incrementally. This happens in two scenarios:
|
|
196
|
+
// 1. When summarizing a detached container, i.e., the first ever summary.
|
|
197
|
+
// 2. When running GC, the default behavior is to call summarize on DDS without incrementalSummaryContext.
|
|
198
|
+
if (!this.enableIncrementalSummary || incrementalSummaryContext === undefined) {
|
|
199
|
+
return ForestIncrementalSummaryBehavior.SingleBlob;
|
|
200
|
+
}
|
|
201
|
+
validateReadyToTrackSummary(this.forestSummaryState, this.trackedSummaryProperties);
|
|
202
|
+
this.forestSummaryState = exports.ForestSummaryTrackingState.Tracking;
|
|
203
|
+
this.latestSummarySequenceNumber = incrementalSummaryContext.latestSummarySequenceNumber;
|
|
204
|
+
this.trackedSummaryProperties = {
|
|
205
|
+
summarySequenceNumber: incrementalSummaryContext.summarySequenceNumber,
|
|
206
|
+
latestSummaryBasePath: incrementalSummaryContext.summaryPath,
|
|
207
|
+
chunkSummaryPath: [],
|
|
208
|
+
parentSummaryBuilder: new internal_2.SummaryTreeBuilder(),
|
|
209
|
+
fullTree,
|
|
210
|
+
stringify,
|
|
211
|
+
};
|
|
212
|
+
return ForestIncrementalSummaryBehavior.Incremental;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* {@link IncrementalEncoder.encodeIncrementalField}
|
|
216
|
+
* @remarks Returns an empty array if the field has no content.
|
|
217
|
+
*/
|
|
218
|
+
encodeIncrementalField(cursor, chunkEncoder) {
|
|
219
|
+
// Validate that a summary is currently being tracked and that the tracked summary properties are defined.
|
|
220
|
+
validateTrackingSummary(this.forestSummaryState, this.trackedSummaryProperties);
|
|
221
|
+
if (cursor.getFieldLength() === 0) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
let chunkReferenceId;
|
|
225
|
+
let chunkProperties;
|
|
226
|
+
const chunk = this.getChunkAtCursor(cursor);
|
|
227
|
+
// Try and get the properties of the chunk from the latest successful summary.
|
|
228
|
+
// If it exists and the summary is not a full tree, use the properties to generate a summary handle.
|
|
229
|
+
// If it does not exist, encode the chunk and generate new properties for it.
|
|
230
|
+
const previousChunkProperties = (0, index_js_1.tryGetFromNestedMap)(this.chunkTrackingPropertiesMap, this.latestSummarySequenceNumber, chunk);
|
|
231
|
+
if (previousChunkProperties !== undefined && !this.trackedSummaryProperties.fullTree) {
|
|
232
|
+
chunkProperties = previousChunkProperties;
|
|
233
|
+
chunkReferenceId = previousChunkProperties.referenceId;
|
|
234
|
+
this.trackedSummaryProperties.parentSummaryBuilder.addHandle(`${chunkReferenceId}`, driver_definitions_1.SummaryType.Tree, `${this.trackedSummaryProperties.latestSummaryBasePath}/${previousChunkProperties.summaryPath}`);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
// Generate a new reference ID for the chunk.
|
|
238
|
+
chunkReferenceId = (0, index_js_1.brand)(this.nextReferenceId++);
|
|
239
|
+
// Add the reference ID of this chunk to the chunk summary path and use the path as the summary path
|
|
240
|
+
// for the chunk in its summary properties.
|
|
241
|
+
// This is done before encoding the chunk so that the summary path is updated correctly when encoding
|
|
242
|
+
// any incremental chunks that are under this chunk.
|
|
243
|
+
this.trackedSummaryProperties.chunkSummaryPath.push(chunkReferenceId);
|
|
244
|
+
chunkProperties = {
|
|
245
|
+
referenceId: chunkReferenceId,
|
|
246
|
+
summaryPath: this.trackedSummaryProperties.chunkSummaryPath.join("/"),
|
|
247
|
+
};
|
|
248
|
+
const parentSummaryBuilder = this.trackedSummaryProperties.parentSummaryBuilder;
|
|
249
|
+
// Create a new summary builder for this chunk to build its summary tree which will be stored in the
|
|
250
|
+
// parent's summary tree under its reference ID.
|
|
251
|
+
// Before encoding the chunk, set the parent summary builder to this chunk's summary builder so that
|
|
252
|
+
// any incremental chunks in the subtree of this chunk will use that as their parent summary builder.
|
|
253
|
+
const chunkSummaryBuilder = new internal_2.SummaryTreeBuilder();
|
|
254
|
+
this.trackedSummaryProperties.parentSummaryBuilder = chunkSummaryBuilder;
|
|
255
|
+
chunkSummaryBuilder.addBlob(chunkContentsBlobKey, this.trackedSummaryProperties.stringify(chunkEncoder(chunk)));
|
|
256
|
+
// Add this chunk's summary tree to the parent's summary tree. The summary tree contains its encoded
|
|
257
|
+
// contents and the summary trees of any incremental chunks under it.
|
|
258
|
+
parentSummaryBuilder.addWithStats(`${chunkReferenceId}`, chunkSummaryBuilder.getSummaryTree());
|
|
259
|
+
// Restore the parent summary builder and chunk summary path.
|
|
260
|
+
this.trackedSummaryProperties.parentSummaryBuilder = parentSummaryBuilder;
|
|
261
|
+
this.trackedSummaryProperties.chunkSummaryPath.pop();
|
|
262
|
+
}
|
|
263
|
+
(0, index_js_1.setInNestedMap)(this.chunkTrackingPropertiesMap, this.trackedSummaryProperties.summarySequenceNumber, chunk, chunkProperties);
|
|
264
|
+
return [chunkReferenceId];
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Must be called after summary generation is complete to finish tracking the summary.
|
|
268
|
+
* It clears any tracking state and deletes the tracking properties for summaries that are older than the
|
|
269
|
+
* latest successful summary.
|
|
270
|
+
* @param incrementalSummaryContext - The context for the incremental summary that contains the sequence numbers.
|
|
271
|
+
* If this is undefined, the summary tree will only contain a summary blob for `forestSummaryContent`.
|
|
272
|
+
* @param forestSummaryContent - The stringified ForestCodec output of top-level Forest content.
|
|
273
|
+
* @returns the Forest's summary tree.
|
|
274
|
+
*/
|
|
275
|
+
completeSummary(args) {
|
|
276
|
+
const { incrementalSummaryContext, forestSummaryContent } = args;
|
|
277
|
+
if (!this.enableIncrementalSummary || incrementalSummaryContext === undefined) {
|
|
278
|
+
const summaryBuilder = new internal_2.SummaryTreeBuilder();
|
|
279
|
+
summaryBuilder.addBlob(exports.forestSummaryContentKey, forestSummaryContent);
|
|
280
|
+
return summaryBuilder.getSummaryTree();
|
|
281
|
+
}
|
|
282
|
+
validateTrackingSummary(this.forestSummaryState, this.trackedSummaryProperties);
|
|
283
|
+
this.trackedSummaryProperties.parentSummaryBuilder.addBlob(exports.forestSummaryContentKey, forestSummaryContent);
|
|
284
|
+
// Copy over the entries from the latest summary to the current summary.
|
|
285
|
+
// In the current summary, there can be fields that haven't changed since the latest summary and the chunks
|
|
286
|
+
// in these fields and in any of its children weren't encoded. So, we need get the entries for these chunks
|
|
287
|
+
// to be able to incrementally summarize them in the next summary.
|
|
288
|
+
const latestSummaryTrackingMap = this.chunkTrackingPropertiesMap.get(this.latestSummarySequenceNumber);
|
|
289
|
+
const currentSummaryTrackingMap = this.chunkTrackingPropertiesMap.get(this.trackedSummaryProperties.summarySequenceNumber);
|
|
290
|
+
if (latestSummaryTrackingMap !== undefined && currentSummaryTrackingMap !== undefined) {
|
|
291
|
+
for (const [chunk, chunkProperties] of latestSummaryTrackingMap.entries()) {
|
|
292
|
+
if (!currentSummaryTrackingMap.has(chunk)) {
|
|
293
|
+
currentSummaryTrackingMap.set(chunk, chunkProperties);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// Delete tracking for summaries that are older than the latest successful summary because they will
|
|
298
|
+
// never be referenced again for generating summary handles.
|
|
299
|
+
for (const sequenceNumber of this.chunkTrackingPropertiesMap.keys()) {
|
|
300
|
+
if (sequenceNumber < this.latestSummarySequenceNumber) {
|
|
301
|
+
this.chunkTrackingPropertiesMap.delete(sequenceNumber);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
this.forestSummaryState = exports.ForestSummaryTrackingState.ReadyToTrack;
|
|
305
|
+
const summaryTree = this.trackedSummaryProperties.parentSummaryBuilder.getSummaryTree();
|
|
306
|
+
this.trackedSummaryProperties = undefined;
|
|
307
|
+
return summaryTree;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Called to get the encoded contents of an incremental chunk with the given reference ID.
|
|
311
|
+
* This is typically used when loading the forest to retrieve the contents of incremental chunks.
|
|
312
|
+
* @param referenceId - The reference ID of the chunk to retrieve.
|
|
313
|
+
* @returns The encoded contents of the chunk.
|
|
314
|
+
*/
|
|
315
|
+
getEncodedIncrementalChunk(referenceId) {
|
|
316
|
+
const chunkEncodedContents = this.encodedChunkContentsMap.get(`${referenceId}`);
|
|
317
|
+
(0, internal_1.assert)(chunkEncodedContents !== undefined, 0xc26 /* Incremental chunk contents not found */);
|
|
318
|
+
return chunkEncodedContents;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
exports.ForestIncrementalSummaryBuilder = ForestIncrementalSummaryBuilder;
|
|
322
|
+
//# sourceMappingURL=incrementalSummaryBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"incrementalSummaryBuilder.js","sourceRoot":"","sources":["../../../src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAK7D,qEAA4E;AAC5E,kDAM6B;AAY7B,2EAAiE;AAGjE,uEAAwE;AAIxE;;;;GAIG;AACU,QAAA,uBAAuB,GAAG,YAAY,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAExC;;GAEG;AACU,QAAA,0BAA0B,GAAG;IACzC,4CAA4C;IAC5C,QAAQ,EAAE,UAAU;IACpB,wCAAwC;IACxC,YAAY,EAAE,cAAc;CACnB,CAAC;AA2DX;;GAEG;AACH,IAAY,gCAgBX;AAhBD,WAAY,gCAAgC;IAC3C;;;;OAIG;IACH,qGAAW,CAAA;IACX;;;;;;;OAOG;IACH,mGAAU,CAAA;AACX,CAAC,EAhBW,gCAAgC,gDAAhC,gCAAgC,QAgB3C;AAED;;;;GAIG;AACH,SAAS,uBAAuB,CAC/B,kBAA8C,EAC9C,wBAA8D;IAE9D,IAAA,iBAAM,EACL,kBAAkB,KAAK,kCAA0B,CAAC,QAAQ,EAC1D,KAAK,CAAC,4BAA4B,CAClC,CAAC;IACF,IAAA,iBAAM,EACL,wBAAwB,KAAK,SAAS,EACtC,KAAK,CAAC,0EAA0E,CAChF,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,2BAA2B,CACnC,kBAA8C,EAC9C,wBAA8D;IAE9D,IAAA,iBAAM,EACL,kBAAkB,KAAK,kCAA0B,CAAC,YAAY,EAC9D,KAAK,CAAC,gCAAgC,CACtC,CAAC;IACF,IAAA,iBAAM,EACL,wBAAwB,KAAK,SAAS,EACtC,KAAK,CAAC,0EAA0E,CAChF,CAAC;AACH,CAAC;AAED,4CAA4C;AAC5C;;;;;;;;;;;;;;;;;;;;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ED;;;;;OAKG;IACI,0BAA0B,CAAC,WAA6B;QAC9D,MAAM,oBAAoB,GAAG,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,GAAG,WAAW,EAAE,CAAC,CAAC;QAChF,IAAA,iBAAM,EACL,oBAAoB,KAAK,SAAS,EAClC,KAAK,CAAC,0CAA0C,CAChD,CAAC;QACF,OAAO,oBAAoB,CAAC;IAC7B,CAAC;CACD;AA/RD,0EA+RC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIExperimentalIncrementalSummaryContext,\n\tISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tbrand,\n\tsetInNestedMap,\n\ttryGetFromNestedMap,\n\ttype JsonCompatible,\n\ttype NestedMap,\n} from \"../../util/index.js\";\nimport type {\n\tChunkReferenceId,\n\tEncodedFieldBatch,\n\tIncrementalEncoderDecoder,\n\tTreeChunk,\n} from \"../chunked-forest/index.js\";\nimport type {\n\tFieldKey,\n\tITreeCursorSynchronous,\n\tTreeNodeSchemaIdentifier,\n} from \"../../core/index.js\";\nimport { SummaryType } from \"@fluidframework/driver-definitions\";\nimport type { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type { ISnapshotTree } from \"@fluidframework/driver-definitions/internal\";\nimport { LoggingError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport type { SummaryElementStringifier } from \"../../shared-tree-core/index.js\";\n\n/**\n * The key for the blob under ForestSummarizer's root.\n * This blob contains the ForestCodec's output.\n * See {@link ForestIncrementalSummaryBuilder} for details on the summary structure.\n */\nexport const forestSummaryContentKey = \"ForestTree\";\n\n/**\n * The contents of an incremental chunk is under a summary tree node with its {@link ChunkReferenceId} as the key.\n * The inline portion of the chunk content is encoded with the forest codec is stored in a blob with this key.\n * The rest of the chunk contents is stored in the summary tree under the summary tree node.\n * See the summary format in {@link ForestIncrementalSummaryBuilder} for more details.\n */\nconst chunkContentsBlobKey = \"contents\";\n\n/**\n * State that tells whether a summary is currently being tracked.\n */\nexport const ForestSummaryTrackingState = {\n\t/** A summary is currently being tracked. */\n\tTracking: \"Tracking\",\n\t/** A summary is ready to be tracked. */\n\tReadyToTrack: \"ReadyToTrack\",\n} as const;\nexport type ForestSummaryTrackingState =\n\t(typeof ForestSummaryTrackingState)[keyof typeof ForestSummaryTrackingState];\n\n/**\n * The properties of a chunk that is tracked for every summary.\n * If a chunk doesn't change between summaries,\n * these properties will be used to generate a summary handle for the chunk.\n */\ninterface ChunkSummaryProperties {\n\t/**\n\t * The reference ID of the chunk which uniquely identifies it under its parent's summary tree.\n\t * The summary for this chunk will be stored against this reference ID as key in the summary tree.\n\t */\n\treadonly referenceId: ChunkReferenceId;\n\t/**\n\t * The path for this chunk's summary in the summary tree relative to the forest's summary tree.\n\t * This path is used to generate a summary handle for the chunk if it doesn't change between summaries.\n\t */\n\treadonly summaryPath: string;\n}\n\n/**\n * The properties of a summary being tracked.\n */\ninterface TrackedSummaryProperties {\n\t/**\n\t * The sequence number of the summary in progress.\n\t */\n\treadonly summarySequenceNumber: number;\n\t/**\n\t * The base path for the latest summary that was successful.\n\t * This is used to generate summary handles.\n\t */\n\treadonly latestSummaryBasePath: string;\n\t/**\n\t * Whether the summary being tracked is a full tree summary.\n\t * If true, the summary will not contain any summary handles. All chunks must be summarized in full.\n\t */\n\treadonly fullTree: boolean;\n\t/**\n\t * Represents the path of a chunk in the summary tree relative to the forest's summary tree.\n\t * Each item in the array is the {@link ChunkReferenceId} of a chunk in the summary tree starting\n\t * from the chunk under forest summary tree.\n\t * When a chunk is summarized, this array will be used to generate the path for the chunk's summary in the\n\t * summary tree.\n\t */\n\treadonly chunkSummaryPath: ChunkReferenceId[];\n\t/**\n\t * The parent summary builder to use to build the incremental summary tree.\n\t * When a chunk is being summarized, it will add its summary to this builder against its reference ID.\n\t */\n\tparentSummaryBuilder: SummaryTreeBuilder;\n\t/**\n\t * Serializes content (including {@link (IFluidHandle:interface)}s) for adding to a summary blob.\n\t */\n\tstringify: SummaryElementStringifier;\n}\n\n/**\n * The behavior of the forest's incremental summary - whether the summary should be a single blob or incremental.\n */\nexport enum ForestIncrementalSummaryBehavior {\n\t/**\n\t * The forest can encode chunks incrementally, i.e., chunks that support incremental encoding will be encoded\n\t * separately - they will be added to a separate tree.\n\t * The incremental summary format is described in {@link ForestIncrementalSummaryBuilder}.\n\t */\n\tIncremental,\n\t/**\n\t * The forest should encode all of it's data in a single summary blob.\n\t * @remarks\n\t * The format of the summary will be the same as the old format (pre-incremental summaries) and is fully\n\t * backwards compatible with the old format. The summary will basically look like an incremental summary\n\t * with no incremental fields - it will only contain the \"ForestTree\" blob in the summary format described\n\t * in {@link ForestIncrementalSummaryBuilder}.\n\t */\n\tSingleBlob,\n}\n\n/**\n * Validates that a summary is currently being tracked and that the tracked summary properties are defined.\n * @param forestSummaryState - The current state of the forest summary tracking.\n * @param trackedSummaryProperties - The properties of the tracked summary, which must be available.\n */\nfunction validateTrackingSummary(\n\tforestSummaryState: ForestSummaryTrackingState,\n\ttrackedSummaryProperties: TrackedSummaryProperties | undefined,\n): asserts trackedSummaryProperties is TrackedSummaryProperties {\n\tassert(\n\t\tforestSummaryState === ForestSummaryTrackingState.Tracking,\n\t\t0xc22 /* Not tracking a summary */,\n\t);\n\tassert(\n\t\ttrackedSummaryProperties !== undefined,\n\t\t0xc23 /* Tracked summary properties must be available when tracking a summary */,\n\t);\n}\n\n/**\n * Validates that a summary is ready to be tracked and that the tracked summary properties are undefined.\n * @param forestSummaryState - The current state of the forest summary tracking.\n * @param trackedSummaryProperties - The properties of the tracked summary, which must be undefined.\n */\nfunction validateReadyToTrackSummary(\n\tforestSummaryState: ForestSummaryTrackingState,\n\ttrackedSummaryProperties: TrackedSummaryProperties | undefined,\n): asserts trackedSummaryProperties is undefined {\n\tassert(\n\t\tforestSummaryState === ForestSummaryTrackingState.ReadyToTrack,\n\t\t0xc24 /* Already tracking a summary */,\n\t);\n\tassert(\n\t\ttrackedSummaryProperties === undefined,\n\t\t0xc25 /* Tracked summary properties must not be available when ready to track */,\n\t);\n}\n\n/* eslint-disable jsdoc/check-indentation */\n/**\n * Tracks and builds the incremental summary tree for a forest where chunks that support incremental encoding are\n * stored in a separate tree in the summary under its {@link ChunkReferenceId}.\n * The summary tree for a chunk is self-sufficient and can be independently loaded and used to reconstruct the\n * chunk's contents without any additional context from its parent.\n *\n * An example summary tree with incremental summary:\n * Forest\n * ├── ForestTree\n * ├── 0\n * | ├── contents\n * | ├── 1\n * | | ├── contents\n * | | ├── 2\n * | | | ├── contents\n * | ├── 3 - \".../Forest/ForestTree/0/1/3\"\n * ├── 4\n * | ├── contents\n * | ├── ...\n * ├── 5 - \"/.../Forest/ForestTree/5\"\n * - Forest is a summary tree node added by the shared tree and contains the following:\n * - The inline portion of the top-level forest content is stored in a summary blob called \"ForestTree\".\n * It also contains the {@link ChunkReferenceId}s of the incremental chunks under it.\n * - The summary for each incremental chunk under it is stored against its {@link ChunkReferenceId}.\n * - For each chunk, the structure of the summary tree is the same as the Forest. It contains the following:\n * - The inline portion of the chunk content is stored in a blob called \"contents\".\n * It also contains the {@link ChunkReferenceId}s of the incremental chunks under it.\n * - The summary for each incremental chunk under it is stored against its {@link ChunkReferenceId}.\n * - Chunks that do not change between summaries are summarized as handles in the summary tree.\n * @remarks\n * It may seem inconsistent that although the structure for the top-level forest tree is similar to that of\n * an incremental chunk, its content is stored in a summary blob called \"ForestTree\" while the content for\n * the incremental chunks are stored in a summary blob called \"contents\".\n * This is to keep this summary backwards compatible with old format (before incremental summaries were added)\n * where the entire forest content was in a summary blob called \"ForestTree\". So, if incremental summaries were\n * disabled, the forest content will be fully backwards compatible.\n * Note that this limits reusing the root node in a location other than root and a non-root node in the root.\n * We could phase this out by switching to write the top-level contents under \"contents\" if we want to support\n * the above. However, there is no plan to do that for now.\n *\n * TODO: AB#46752\n * Add strong types for the summary structure to document it better. It will help make it super clear what the actual\n * format is in a way that can easily be linked to, documented and inspected.\n */\n/* eslint-enable jsdoc/check-indentation */\nexport class ForestIncrementalSummaryBuilder implements IncrementalEncoderDecoder {\n\t/**\n\t * The next reference ID to use for a chunk.\n\t */\n\tprivate nextReferenceId: ChunkReferenceId = brand(0);\n\n\t/**\n\t * For a given summary sequence number, keeps track of a chunk's properties that will be used to generate\n\t * a summary handle for the chunk if it does not change between summaries.\n\t */\n\tprivate readonly chunkTrackingPropertiesMap: NestedMap<\n\t\tnumber,\n\t\tTreeChunk,\n\t\tChunkSummaryProperties\n\t> = new Map();\n\n\t/**\n\t * The state indicating whether a summary is currently being tracked or not.\n\t */\n\tpublic forestSummaryState: ForestSummaryTrackingState =\n\t\tForestSummaryTrackingState.ReadyToTrack;\n\n\t/**\n\t * The sequence number of the latest summary that was successful.\n\t */\n\tprivate latestSummarySequenceNumber: number = -1;\n\n\t/**\n\t * The current state of the summary being tracked.\n\t * This is undefined if no summary is currently being tracked.\n\t */\n\tprivate trackedSummaryProperties: TrackedSummaryProperties | undefined;\n\n\t/**\n\t * A map of chunk reference IDs to their encoded contents. This is typically used during the loading of the\n\t * forest to retrieve the contents of the chunks that were summarized incrementally.\n\t */\n\tprivate readonly encodedChunkContentsMap: Map<string, EncodedFieldBatch> = new Map();\n\n\tpublic constructor(\n\t\tprivate readonly enableIncrementalSummary: boolean,\n\t\tprivate readonly getChunkAtCursor: (cursor: ITreeCursorSynchronous) => TreeChunk,\n\t\t/**\n\t\t * {@link IncrementalEncoder.shouldEncodeFieldIncrementally}\n\t\t */\n\t\tpublic readonly shouldEncodeFieldIncrementally: (\n\t\t\tnodeIdentifier: TreeNodeSchemaIdentifier,\n\t\t\tfieldKey: FieldKey,\n\t\t) => boolean,\n\t) {}\n\n\t/**\n\t * Must be called when the forest is loaded to download the encoded contents of incremental chunks.\n\t * @param services - The channel storage service to use to access the snapshot tree and download the\n\t * contents of the chunks.\n\t * @param readAndParse - A function that reads and parses a blob from the storage service.\n\t */\n\tpublic async load(\n\t\tservices: IChannelStorageService,\n\t\treadAndParseChunk: <T extends JsonCompatible<IFluidHandle>>(id: string) => Promise<T>,\n\t): Promise<void> {\n\t\tconst forestTree = services.getSnapshotTree?.();\n\t\t// Snapshot tree should be available when loading forest's contents. However, it is an optional function\n\t\t// and may not be implemented by the storage service.\n\t\tif (forestTree === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Downloads the contents of incremental chunks in the given snapshot tree. Also, recursively downloads\n\t\t// the contents of incremental chunks in any sub-trees.\n\t\tconst downloadChunkContentsInTree = async (\n\t\t\tsnapshotTree: ISnapshotTree,\n\t\t\tparentTreeKey: string,\n\t\t): Promise<void> => {\n\t\t\t// All trees in the snapshot tree are for incremental chunks. The key is the chunk's reference ID\n\t\t\t// and the value is the snapshot tree for the chunk.\n\t\t\tfor (const [chunkReferenceId, chunkSnapshotTree] of Object.entries(snapshotTree.trees)) {\n\t\t\t\tconst chunkSubTreePath = `${parentTreeKey}${chunkReferenceId}`;\n\t\t\t\tconst chunkContentsPath = `${chunkSubTreePath}/${chunkContentsBlobKey}`;\n\t\t\t\tif (!(await services.contains(chunkContentsPath))) {\n\t\t\t\t\tthrow new LoggingError(\n\t\t\t\t\t\t`SharedTree: Cannot find contents for incremental chunk ${chunkContentsPath}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst chunkContents = await readAndParseChunk<EncodedFieldBatch>(chunkContentsPath);\n\t\t\t\tthis.encodedChunkContentsMap.set(chunkReferenceId, chunkContents);\n\n\t\t\t\t// Recursively download the contents of chunks in this chunk's sub tree.\n\t\t\t\tawait downloadChunkContentsInTree(chunkSnapshotTree, `${chunkSubTreePath}/`);\n\t\t\t}\n\t\t};\n\t\tawait downloadChunkContentsInTree(forestTree, \"\");\n\t}\n\n\t/**\n\t * Must be called when starting a new forest summary to track it.\n\t * @param fullTree - Whether the summary is a full tree summary. If true, the summary will not contain\n\t * any summary handles. All chunks must be summarized in full.\n\t * @param incrementalSummaryContext - The context for the incremental summary that contains the sequence numbers\n\t * for the current and latest summaries.\n\t * @param stringify - Serializes content (including {@link (IFluidHandle:interface)}s) for adding to a summary blob.\n\t * @returns the behavior of the forest's incremental summary.\n\t */\n\tpublic startSummary(args: {\n\t\tfullTree: boolean;\n\t\tincrementalSummaryContext: IExperimentalIncrementalSummaryContext | undefined;\n\t\tstringify: SummaryElementStringifier;\n\t}): ForestIncrementalSummaryBehavior {\n\t\tconst { fullTree, incrementalSummaryContext, stringify } = args;\n\t\t// If there is no incremental summary context, do not summarize incrementally. This happens in two scenarios:\n\t\t// 1. When summarizing a detached container, i.e., the first ever summary.\n\t\t// 2. When running GC, the default behavior is to call summarize on DDS without incrementalSummaryContext.\n\t\tif (!this.enableIncrementalSummary || incrementalSummaryContext === undefined) {\n\t\t\treturn ForestIncrementalSummaryBehavior.SingleBlob;\n\t\t}\n\n\t\tvalidateReadyToTrackSummary(this.forestSummaryState, this.trackedSummaryProperties);\n\n\t\tthis.forestSummaryState = ForestSummaryTrackingState.Tracking;\n\t\tthis.latestSummarySequenceNumber = incrementalSummaryContext.latestSummarySequenceNumber;\n\t\tthis.trackedSummaryProperties = {\n\t\t\tsummarySequenceNumber: incrementalSummaryContext.summarySequenceNumber,\n\t\t\tlatestSummaryBasePath: incrementalSummaryContext.summaryPath,\n\t\t\tchunkSummaryPath: [],\n\t\t\tparentSummaryBuilder: new SummaryTreeBuilder(),\n\t\t\tfullTree,\n\t\t\tstringify,\n\t\t};\n\t\treturn ForestIncrementalSummaryBehavior.Incremental;\n\t}\n\n\t/**\n\t * {@link IncrementalEncoder.encodeIncrementalField}\n\t * @remarks Returns an empty array if the field has no content.\n\t */\n\tpublic encodeIncrementalField(\n\t\tcursor: ITreeCursorSynchronous,\n\t\tchunkEncoder: (chunk: TreeChunk) => EncodedFieldBatch,\n\t): ChunkReferenceId[] {\n\t\t// Validate that a summary is currently being tracked and that the tracked summary properties are defined.\n\t\tvalidateTrackingSummary(this.forestSummaryState, this.trackedSummaryProperties);\n\n\t\tif (cursor.getFieldLength() === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tlet chunkReferenceId: ChunkReferenceId;\n\t\tlet chunkProperties: ChunkSummaryProperties;\n\n\t\tconst chunk = this.getChunkAtCursor(cursor);\n\n\t\t// Try and get the properties of the chunk from the latest successful summary.\n\t\t// If it exists and the summary is not a full tree, use the properties to generate a summary handle.\n\t\t// If it does not exist, encode the chunk and generate new properties for it.\n\t\tconst previousChunkProperties = tryGetFromNestedMap(\n\t\t\tthis.chunkTrackingPropertiesMap,\n\t\t\tthis.latestSummarySequenceNumber,\n\t\t\tchunk,\n\t\t);\n\t\tif (previousChunkProperties !== undefined && !this.trackedSummaryProperties.fullTree) {\n\t\t\tchunkProperties = previousChunkProperties;\n\t\t\tchunkReferenceId = previousChunkProperties.referenceId;\n\t\t\tthis.trackedSummaryProperties.parentSummaryBuilder.addHandle(\n\t\t\t\t`${chunkReferenceId}`,\n\t\t\t\tSummaryType.Tree,\n\t\t\t\t`${this.trackedSummaryProperties.latestSummaryBasePath}/${previousChunkProperties.summaryPath}`,\n\t\t\t);\n\t\t} else {\n\t\t\t// Generate a new reference ID for the chunk.\n\t\t\tchunkReferenceId = brand(this.nextReferenceId++);\n\t\t\t// Add the reference ID of this chunk to the chunk summary path and use the path as the summary path\n\t\t\t// for the chunk in its summary properties.\n\t\t\t// This is done before encoding the chunk so that the summary path is updated correctly when encoding\n\t\t\t// any incremental chunks that are under this chunk.\n\t\t\tthis.trackedSummaryProperties.chunkSummaryPath.push(chunkReferenceId);\n\n\t\t\tchunkProperties = {\n\t\t\t\treferenceId: chunkReferenceId,\n\t\t\t\tsummaryPath: this.trackedSummaryProperties.chunkSummaryPath.join(\"/\"),\n\t\t\t};\n\n\t\t\tconst parentSummaryBuilder = this.trackedSummaryProperties.parentSummaryBuilder;\n\t\t\t// Create a new summary builder for this chunk to build its summary tree which will be stored in the\n\t\t\t// parent's summary tree under its reference ID.\n\t\t\t// Before encoding the chunk, set the parent summary builder to this chunk's summary builder so that\n\t\t\t// any incremental chunks in the subtree of this chunk will use that as their parent summary builder.\n\t\t\tconst chunkSummaryBuilder = new SummaryTreeBuilder();\n\t\t\tthis.trackedSummaryProperties.parentSummaryBuilder = chunkSummaryBuilder;\n\t\t\tchunkSummaryBuilder.addBlob(\n\t\t\t\tchunkContentsBlobKey,\n\t\t\t\tthis.trackedSummaryProperties.stringify(chunkEncoder(chunk)),\n\t\t\t);\n\n\t\t\t// Add this chunk's summary tree to the parent's summary tree. The summary tree contains its encoded\n\t\t\t// contents and the summary trees of any incremental chunks under it.\n\t\t\tparentSummaryBuilder.addWithStats(\n\t\t\t\t`${chunkReferenceId}`,\n\t\t\t\tchunkSummaryBuilder.getSummaryTree(),\n\t\t\t);\n\n\t\t\t// Restore the parent summary builder and chunk summary path.\n\t\t\tthis.trackedSummaryProperties.parentSummaryBuilder = parentSummaryBuilder;\n\t\t\tthis.trackedSummaryProperties.chunkSummaryPath.pop();\n\t\t}\n\n\t\tsetInNestedMap(\n\t\t\tthis.chunkTrackingPropertiesMap,\n\t\t\tthis.trackedSummaryProperties.summarySequenceNumber,\n\t\t\tchunk,\n\t\t\tchunkProperties,\n\t\t);\n\t\treturn [chunkReferenceId];\n\t}\n\n\t/**\n\t * Must be called after summary generation is complete to finish tracking the summary.\n\t * It clears any tracking state and deletes the tracking properties for summaries that are older than the\n\t * latest successful summary.\n\t * @param incrementalSummaryContext - The context for the incremental summary that contains the sequence numbers.\n\t * If this is undefined, the summary tree will only contain a summary blob for `forestSummaryContent`.\n\t * @param forestSummaryContent - The stringified ForestCodec output of top-level Forest content.\n\t * @returns the Forest's summary tree.\n\t */\n\tpublic completeSummary(args: {\n\t\tincrementalSummaryContext: IExperimentalIncrementalSummaryContext | undefined;\n\t\tforestSummaryContent: string;\n\t}): ISummaryTreeWithStats {\n\t\tconst { incrementalSummaryContext, forestSummaryContent } = args;\n\t\tif (!this.enableIncrementalSummary || incrementalSummaryContext === undefined) {\n\t\t\tconst summaryBuilder = new SummaryTreeBuilder();\n\t\t\tsummaryBuilder.addBlob(forestSummaryContentKey, forestSummaryContent);\n\t\t\treturn summaryBuilder.getSummaryTree();\n\t\t}\n\n\t\tvalidateTrackingSummary(this.forestSummaryState, this.trackedSummaryProperties);\n\n\t\tthis.trackedSummaryProperties.parentSummaryBuilder.addBlob(\n\t\t\tforestSummaryContentKey,\n\t\t\tforestSummaryContent,\n\t\t);\n\n\t\t// Copy over the entries from the latest summary to the current summary.\n\t\t// In the current summary, there can be fields that haven't changed since the latest summary and the chunks\n\t\t// in these fields and in any of its children weren't encoded. So, we need get the entries for these chunks\n\t\t// to be able to incrementally summarize them in the next summary.\n\t\tconst latestSummaryTrackingMap = this.chunkTrackingPropertiesMap.get(\n\t\t\tthis.latestSummarySequenceNumber,\n\t\t);\n\t\tconst currentSummaryTrackingMap = this.chunkTrackingPropertiesMap.get(\n\t\t\tthis.trackedSummaryProperties.summarySequenceNumber,\n\t\t);\n\t\tif (latestSummaryTrackingMap !== undefined && currentSummaryTrackingMap !== undefined) {\n\t\t\tfor (const [chunk, chunkProperties] of latestSummaryTrackingMap.entries()) {\n\t\t\t\tif (!currentSummaryTrackingMap.has(chunk)) {\n\t\t\t\t\tcurrentSummaryTrackingMap.set(chunk, chunkProperties);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Delete tracking for summaries that are older than the latest successful summary because they will\n\t\t// never be referenced again for generating summary handles.\n\t\tfor (const sequenceNumber of this.chunkTrackingPropertiesMap.keys()) {\n\t\t\tif (sequenceNumber < this.latestSummarySequenceNumber) {\n\t\t\t\tthis.chunkTrackingPropertiesMap.delete(sequenceNumber);\n\t\t\t}\n\t\t}\n\n\t\tthis.forestSummaryState = ForestSummaryTrackingState.ReadyToTrack;\n\t\tconst summaryTree = this.trackedSummaryProperties.parentSummaryBuilder.getSummaryTree();\n\t\tthis.trackedSummaryProperties = undefined;\n\t\treturn summaryTree;\n\t}\n\n\t/**\n\t * Called to get the encoded contents of an incremental chunk with the given reference ID.\n\t * This is typically used when loading the forest to retrieve the contents of incremental chunks.\n\t * @param referenceId - The reference ID of the chunk to retrieve.\n\t * @returns The encoded contents of the chunk.\n\t */\n\tpublic getEncodedIncrementalChunk(referenceId: ChunkReferenceId): EncodedFieldBatch {\n\t\tconst chunkEncodedContents = this.encodedChunkContentsMap.get(`${referenceId}`);\n\t\tassert(\n\t\t\tchunkEncodedContents !== undefined,\n\t\t\t0xc26 /* Incremental chunk contents not found */,\n\t\t);\n\t\treturn chunkEncodedContents;\n\t}\n}\n"]}
|