@fluidframework/tree 2.116.1 → 2.117.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +116 -0
- package/api-report/tree.alpha.api.md +78 -30
- package/api-report/tree.beta.api.md +12 -9
- package/api-report/tree.legacy.beta.api.md +12 -9
- package/dist/codec/codec.d.ts +18 -0
- package/dist/codec/codec.d.ts.map +1 -1
- package/dist/codec/codec.js +18 -0
- package/dist/codec/codec.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/rebase/index.d.ts +1 -1
- package/dist/core/rebase/index.d.ts.map +1 -1
- package/dist/core/rebase/index.js +2 -1
- package/dist/core/rebase/index.js.map +1 -1
- package/dist/core/rebase/types.d.ts +39 -2
- package/dist/core/rebase/types.d.ts.map +1 -1
- package/dist/core/rebase/types.js +37 -2
- package/dist/core/rebase/types.js.map +1 -1
- package/dist/core/rebase/utils.d.ts.map +1 -1
- package/dist/core/rebase/utils.js +1 -0
- package/dist/core/rebase/utils.js.map +1 -1
- package/dist/core/revertible.d.ts +62 -6
- package/dist/core/revertible.d.ts.map +1 -1
- package/dist/core/revertible.js.map +1 -1
- package/dist/entrypoints/alpha.d.ts +1 -1
- package/dist/entrypoints/alpha.d.ts.map +1 -1
- package/dist/entrypoints/alpha.js.map +1 -1
- package/dist/entrypoints/beta.d.ts +1 -1
- package/dist/entrypoints/beta.d.ts.map +1 -1
- package/dist/entrypoints/beta.js.map +1 -1
- package/dist/entrypoints/legacy.d.ts +1 -1
- package/dist/entrypoints/legacy.d.ts.map +1 -1
- package/dist/entrypoints/legacy.js.map +1 -1
- package/dist/feature-libraries/indexing/types.d.ts +1 -1
- package/dist/feature-libraries/indexing/types.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/shared-tree/history.d.ts +22 -0
- package/dist/shared-tree/history.d.ts.map +1 -0
- package/dist/shared-tree/history.js +66 -0
- package/dist/shared-tree/history.js.map +1 -0
- package/dist/shared-tree/schematizingTreeView.d.ts +12 -7
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +13 -0
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +3 -2
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +2 -0
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/tree.js +1 -1
- package/dist/shared-tree/tree.js.map +1 -1
- package/dist/shared-tree/treeAlpha.d.ts +8 -20
- package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
- package/dist/shared-tree/treeAlpha.js +9 -12
- package/dist/shared-tree/treeAlpha.js.map +1 -1
- package/dist/shared-tree/treeCheckout.d.ts +16 -9
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +122 -25
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree/unhydratedTreeContext.d.ts +3 -2
- package/dist/shared-tree/unhydratedTreeContext.d.ts.map +1 -1
- package/dist/shared-tree/unhydratedTreeContext.js +3 -0
- package/dist/shared-tree/unhydratedTreeContext.js.map +1 -1
- package/dist/shared-tree-core/branch.d.ts +16 -2
- package/dist/shared-tree-core/branch.d.ts.map +1 -1
- package/dist/shared-tree-core/branch.js +20 -2
- package/dist/shared-tree-core/branch.js.map +1 -1
- package/dist/shared-tree-core/branchCommitCounter.d.ts +31 -0
- package/dist/shared-tree-core/branchCommitCounter.d.ts.map +1 -0
- package/dist/shared-tree-core/branchCommitCounter.js +79 -0
- package/dist/shared-tree-core/branchCommitCounter.js.map +1 -0
- package/dist/shared-tree-core/customMetadataCodec.d.ts +9 -0
- package/dist/shared-tree-core/customMetadataCodec.d.ts.map +1 -0
- package/dist/shared-tree-core/customMetadataCodec.js +37 -0
- package/dist/shared-tree-core/customMetadataCodec.js.map +1 -0
- package/dist/shared-tree-core/customMetadataFormat.d.ts +18 -0
- package/dist/shared-tree-core/customMetadataFormat.d.ts.map +1 -0
- package/dist/shared-tree-core/customMetadataFormat.js +15 -0
- package/dist/shared-tree-core/customMetadataFormat.js.map +1 -0
- package/dist/shared-tree-core/editManager.d.ts.map +1 -1
- package/dist/shared-tree-core/editManager.js +15 -3
- package/dist/shared-tree-core/editManager.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerCodecs.js +5 -0
- package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsCommons.d.ts +1 -1
- package/dist/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsCommons.js +17 -5
- package/dist/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsV1toV4.js +4 -2
- package/dist/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js +2 -2
- package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
- package/dist/shared-tree-core/editManagerFormatCommons.d.ts +17 -6
- package/dist/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerFormatCommons.js +18 -8
- package/dist/shared-tree-core/editManagerFormatCommons.js.map +1 -1
- package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts +7 -5
- package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerFormatV1toV4.js +4 -3
- package/dist/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
- package/dist/shared-tree-core/editManagerFormatVSharedBranches.d.ts +4 -0
- package/dist/shared-tree-core/editManagerFormatVSharedBranches.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerFormatVSharedBranches.js +2 -2
- package/dist/shared-tree-core/editManagerFormatVSharedBranches.js.map +1 -1
- package/dist/shared-tree-core/index.d.ts +2 -1
- package/dist/shared-tree-core/index.d.ts.map +1 -1
- package/dist/shared-tree-core/index.js +3 -1
- package/dist/shared-tree-core/index.js.map +1 -1
- package/dist/shared-tree-core/messageCodecV1ToV4.d.ts +2 -2
- package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
- package/dist/shared-tree-core/messageCodecV1ToV4.js +12 -3
- package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
- package/dist/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
- package/dist/shared-tree-core/messageCodecVSharedBranches.js +8 -2
- package/dist/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
- package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
- package/dist/shared-tree-core/messageCodecs.js +5 -0
- package/dist/shared-tree-core/messageCodecs.js.map +1 -1
- package/dist/shared-tree-core/messageFormat.d.ts +1 -0
- package/dist/shared-tree-core/messageFormat.d.ts.map +1 -1
- package/dist/shared-tree-core/messageFormat.js +6 -0
- package/dist/shared-tree-core/messageFormat.js.map +1 -1
- package/dist/shared-tree-core/messageFormatV1ToV4.d.ts +10 -3
- package/dist/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
- package/dist/shared-tree-core/messageFormatV1ToV4.js +10 -2
- package/dist/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
- package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts +7 -0
- package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts.map +1 -1
- package/dist/shared-tree-core/messageFormatVSharedBranches.js +2 -0
- package/dist/shared-tree-core/messageFormatVSharedBranches.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +4 -2
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/shared-tree-core/transaction.d.ts +9 -0
- package/dist/shared-tree-core/transaction.d.ts.map +1 -1
- package/dist/shared-tree-core/transaction.js +26 -4
- package/dist/shared-tree-core/transaction.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +1 -1
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/transactionTypes.d.ts +28 -2
- 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 +180 -61
- 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/index.d.ts +1 -1
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/tableSchema.js +10 -10
- package/dist/tableSchema.js.map +1 -1
- package/lib/codec/codec.d.ts +18 -0
- package/lib/codec/codec.d.ts.map +1 -1
- package/lib/codec/codec.js +18 -0
- package/lib/codec/codec.js.map +1 -1
- package/lib/core/index.d.ts +2 -2
- package/lib/core/index.d.ts.map +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/rebase/index.d.ts +1 -1
- package/lib/core/rebase/index.d.ts.map +1 -1
- package/lib/core/rebase/index.js +1 -1
- package/lib/core/rebase/index.js.map +1 -1
- package/lib/core/rebase/types.d.ts +39 -2
- package/lib/core/rebase/types.d.ts.map +1 -1
- package/lib/core/rebase/types.js +35 -1
- package/lib/core/rebase/types.js.map +1 -1
- package/lib/core/rebase/utils.d.ts.map +1 -1
- package/lib/core/rebase/utils.js +1 -0
- package/lib/core/rebase/utils.js.map +1 -1
- package/lib/core/revertible.d.ts +62 -6
- package/lib/core/revertible.d.ts.map +1 -1
- package/lib/core/revertible.js.map +1 -1
- package/lib/entrypoints/alpha.d.ts +1 -1
- package/lib/entrypoints/alpha.d.ts.map +1 -1
- package/lib/entrypoints/alpha.js.map +1 -1
- package/lib/entrypoints/beta.d.ts +1 -1
- package/lib/entrypoints/beta.d.ts.map +1 -1
- package/lib/entrypoints/beta.js.map +1 -1
- package/lib/entrypoints/legacy.d.ts +1 -1
- package/lib/entrypoints/legacy.d.ts.map +1 -1
- package/lib/entrypoints/legacy.js.map +1 -1
- package/lib/feature-libraries/indexing/types.d.ts +1 -1
- package/lib/feature-libraries/indexing/types.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/shared-tree/history.d.ts +22 -0
- package/lib/shared-tree/history.d.ts.map +1 -0
- package/lib/shared-tree/history.js +62 -0
- package/lib/shared-tree/history.js.map +1 -0
- package/lib/shared-tree/schematizingTreeView.d.ts +12 -7
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +13 -0
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +3 -2
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +2 -0
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/tree.js +1 -1
- package/lib/shared-tree/tree.js.map +1 -1
- package/lib/shared-tree/treeAlpha.d.ts +8 -20
- package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
- package/lib/shared-tree/treeAlpha.js +9 -12
- package/lib/shared-tree/treeAlpha.js.map +1 -1
- package/lib/shared-tree/treeCheckout.d.ts +16 -9
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +123 -26
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree/unhydratedTreeContext.d.ts +3 -2
- package/lib/shared-tree/unhydratedTreeContext.d.ts.map +1 -1
- package/lib/shared-tree/unhydratedTreeContext.js +3 -0
- package/lib/shared-tree/unhydratedTreeContext.js.map +1 -1
- package/lib/shared-tree-core/branch.d.ts +16 -2
- package/lib/shared-tree-core/branch.d.ts.map +1 -1
- package/lib/shared-tree-core/branch.js +20 -2
- package/lib/shared-tree-core/branch.js.map +1 -1
- package/lib/shared-tree-core/branchCommitCounter.d.ts +31 -0
- package/lib/shared-tree-core/branchCommitCounter.d.ts.map +1 -0
- package/lib/shared-tree-core/branchCommitCounter.js +75 -0
- package/lib/shared-tree-core/branchCommitCounter.js.map +1 -0
- package/lib/shared-tree-core/customMetadataCodec.d.ts +9 -0
- package/lib/shared-tree-core/customMetadataCodec.d.ts.map +1 -0
- package/lib/shared-tree-core/customMetadataCodec.js +32 -0
- package/lib/shared-tree-core/customMetadataCodec.js.map +1 -0
- package/lib/shared-tree-core/customMetadataFormat.d.ts +18 -0
- package/lib/shared-tree-core/customMetadataFormat.d.ts.map +1 -0
- package/lib/shared-tree-core/customMetadataFormat.js +11 -0
- package/lib/shared-tree-core/customMetadataFormat.js.map +1 -0
- package/lib/shared-tree-core/editManager.d.ts.map +1 -1
- package/lib/shared-tree-core/editManager.js +16 -4
- package/lib/shared-tree-core/editManager.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerCodecs.js +5 -0
- package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsCommons.d.ts +1 -1
- package/lib/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsCommons.js +17 -5
- package/lib/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsV1toV4.js +4 -2
- package/lib/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js +2 -2
- package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
- package/lib/shared-tree-core/editManagerFormatCommons.d.ts +17 -6
- package/lib/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerFormatCommons.js +18 -8
- package/lib/shared-tree-core/editManagerFormatCommons.js.map +1 -1
- package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts +7 -5
- package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerFormatV1toV4.js +4 -3
- package/lib/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
- package/lib/shared-tree-core/editManagerFormatVSharedBranches.d.ts +4 -0
- package/lib/shared-tree-core/editManagerFormatVSharedBranches.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerFormatVSharedBranches.js +2 -2
- package/lib/shared-tree-core/editManagerFormatVSharedBranches.js.map +1 -1
- package/lib/shared-tree-core/index.d.ts +2 -1
- package/lib/shared-tree-core/index.d.ts.map +1 -1
- package/lib/shared-tree-core/index.js +1 -0
- package/lib/shared-tree-core/index.js.map +1 -1
- package/lib/shared-tree-core/messageCodecV1ToV4.d.ts +2 -2
- package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
- package/lib/shared-tree-core/messageCodecV1ToV4.js +12 -3
- package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
- package/lib/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
- package/lib/shared-tree-core/messageCodecVSharedBranches.js +8 -2
- package/lib/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
- package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
- package/lib/shared-tree-core/messageCodecs.js +5 -0
- package/lib/shared-tree-core/messageCodecs.js.map +1 -1
- package/lib/shared-tree-core/messageFormat.d.ts +1 -0
- package/lib/shared-tree-core/messageFormat.d.ts.map +1 -1
- package/lib/shared-tree-core/messageFormat.js +6 -0
- package/lib/shared-tree-core/messageFormat.js.map +1 -1
- package/lib/shared-tree-core/messageFormatV1ToV4.d.ts +10 -3
- package/lib/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
- package/lib/shared-tree-core/messageFormatV1ToV4.js +10 -2
- package/lib/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
- package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts +7 -0
- package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts.map +1 -1
- package/lib/shared-tree-core/messageFormatVSharedBranches.js +2 -0
- package/lib/shared-tree-core/messageFormatVSharedBranches.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +5 -3
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/shared-tree-core/transaction.d.ts +9 -0
- package/lib/shared-tree-core/transaction.d.ts.map +1 -1
- package/lib/shared-tree-core/transaction.js +27 -5
- package/lib/shared-tree-core/transaction.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +1 -1
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/transactionTypes.d.ts +28 -2
- 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 +180 -61
- 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/index.d.ts +1 -1
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/tableSchema.js +10 -10
- package/lib/tableSchema.js.map +1 -1
- package/package.json +22 -22
- package/src/codec/codec.ts +19 -0
- package/src/core/index.ts +4 -0
- package/src/core/rebase/index.ts +2 -0
- package/src/core/rebase/types.ts +72 -2
- package/src/core/rebase/utils.ts +1 -0
- package/src/core/revertible.ts +67 -6
- package/src/entrypoints/alpha.ts +8 -0
- package/src/entrypoints/beta.ts +1 -0
- package/src/entrypoints/legacy.ts +1 -0
- package/src/feature-libraries/indexing/types.ts +1 -1
- package/src/index.ts +8 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/history.ts +99 -0
- package/src/shared-tree/schematizingTreeView.ts +25 -8
- package/src/shared-tree/sharedTree.ts +5 -2
- package/src/shared-tree/tree.ts +1 -1
- package/src/shared-tree/treeAlpha.ts +17 -35
- package/src/shared-tree/treeCheckout.ts +170 -31
- package/src/shared-tree/unhydratedTreeContext.ts +6 -2
- package/src/shared-tree-core/branch.ts +34 -2
- package/src/shared-tree-core/branchCommitCounter.ts +103 -0
- package/src/shared-tree-core/customMetadataCodec.ts +42 -0
- package/src/shared-tree-core/customMetadataFormat.ts +39 -0
- package/src/shared-tree-core/editManager.ts +22 -3
- package/src/shared-tree-core/editManagerCodecs.ts +12 -0
- package/src/shared-tree-core/editManagerCodecsCommons.ts +41 -15
- package/src/shared-tree-core/editManagerCodecsV1toV4.ts +7 -1
- package/src/shared-tree-core/editManagerCodecsVSharedBranches.ts +2 -0
- package/src/shared-tree-core/editManagerFormatCommons.ts +46 -12
- package/src/shared-tree-core/editManagerFormatV1toV4.ts +13 -5
- package/src/shared-tree-core/editManagerFormatVSharedBranches.ts +2 -2
- package/src/shared-tree-core/index.ts +3 -0
- package/src/shared-tree-core/messageCodecV1ToV4.ts +18 -5
- package/src/shared-tree-core/messageCodecVSharedBranches.ts +9 -2
- package/src/shared-tree-core/messageCodecs.ts +12 -0
- package/src/shared-tree-core/messageFormat.ts +6 -0
- package/src/shared-tree-core/messageFormatV1ToV4.ts +21 -3
- package/src/shared-tree-core/messageFormatVSharedBranches.ts +8 -0
- package/src/shared-tree-core/sharedTreeCore.ts +5 -2
- package/src/shared-tree-core/transaction.ts +56 -4
- package/src/simple-tree/api/index.ts +5 -0
- package/src/simple-tree/api/transactionTypes.ts +29 -2
- package/src/simple-tree/api/tree.ts +199 -60
- package/src/simple-tree/index.ts +5 -0
- package/src/tableSchema.ts +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unhydratedTreeContext.js","sourceRoot":"","sources":["../../src/shared-tree/unhydratedTreeContext.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AAWtE,uDAA0D;AAE1D;;GAEG;AACH,MAAa,qBAAqB;IAGjC;QADQ,qBAAgB,GAAG,CAAC,CAAC;IACN,CAAC;IAEjB,QAAQ;QACd,OAAO,KAAK,CAAC;IACd,CAAC;IAUM,cAAc,CACpB,CAAkC,EAClC,MAAkC;QAElC,KAAK,MAAM,UAAU,IAAI,MAAM,EAAE,aAAa,IAAI,EAAE,EAAE,CAAC;YACtD,IAAA,uCAAqB,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;QACD,IAAI,CAAC,gBAAgB,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC;YACJ,OAAO,qBAAqB,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC;QACzD,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,gBAAgB,IAAI,CAAC,CAAC;QAC5B,CAAC;IACF,CAAC;IAUM,KAAK,CAAC,mBAAmB,CAC/B,CAA2C,EAC3C,MAAkC;QAElC,IAAI,IAAI,CAAC,gBAAgB,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,qBAAU,CACnB,iGAAiG,CACjG,CAAC;QACH,CAAC;QACD,KAAK,MAAM,UAAU,IAAI,MAAM,EAAE,aAAa,IAAI,EAAE,EAAE,CAAC;YACtD,IAAA,uCAAqB,EAAC,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I,CAAC,CAAC;QAC5B,CAAC;IACF,CAAC;IAUM,KAAK,CAAC,mBAAmB,CAC/B,CAA2C,EAC3C,MAAkC;QAElC,IAAI,IAAI,CAAC,gBAAgB,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,qBAAU,CACnB,iGAAiG,CACjG,CAAC;QACH,CAAC;QACD,KAAK,MAAM,UAAU,IAAI,MAAM,EAAE,aAAa,IAAI,EAAE,EAAE,CAAC;YACtD,IAAA,uCAAqB,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;QACD,IAAI,CAAC,gBAAgB,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC;YACJ,OAAO,qBAAqB,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC/D,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,gBAAgB,IAAI,CAAC,CAAC;QAC5B,CAAC;IACF,CAAC;IAEO,MAAM,CAAC,qBAAqB,CACnC,KAA+B;QAE/B,IAAI,KAAK,EAAE,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAC9C,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;;AAvEF,sDAwEC;AAvEc,8BAAQ,GAAG,IAAI,qBAAqB,EAAE,AAA9B,CAA+B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type {\n\tTreeContextAlpha,\n\tUntypedTreeViewAlpha,\n\tRunTransactionParamsAlpha,\n\tTransactionVoidResult,\n\tTransactionValueResult,\n\tWithValue,\n} from \"../simple-tree/index.js\";\n\nimport { assertValidConstraint } from \"./treeCheckout.js\";\n\n/**\n * A {@link TreeContextAlpha | tree context} that can be used for e.g. unhydrated nodes.\n */\nexport class UnhydratedTreeContext implements TreeContextAlpha {\n\tpublic static instance = new UnhydratedTreeContext();\n\tprivate transactionCount = 0;\n\tprivate constructor() {}\n\n\tpublic isBranch(): this is UntypedTreeViewAlpha {\n\t\treturn this.isView();\n\t}\n\n\tpublic isView(): this is UntypedTreeViewAlpha {\n\t\treturn false;\n\t}\n\n\tpublic runTransaction<TValue>(\n\t\tt: () => WithValue<TValue>,\n\t\tparams?: RunTransactionParamsAlpha,\n\t): TransactionValueResult<TValue, TValue>;\n\tpublic runTransaction(\n\t\tt: () => void,\n\t\t_params?: RunTransactionParamsAlpha,\n\t): TransactionVoidResult;\n\tpublic runTransaction(\n\t\tt: () => WithValue<unknown> | void,\n\t\tparams?: RunTransactionParamsAlpha,\n\t): TransactionValueResult<unknown, unknown> | TransactionVoidResult {\n\t\tfor (const constraint of params?.preconditions ?? []) {\n\t\t\tassertValidConstraint(constraint, false);\n\t\t}\n\t\tthis.transactionCount += 1;\n\t\ttry {\n\t\t\treturn UnhydratedTreeContext.wrapTransactionResult(t());\n\t\t} finally {\n\t\t\tthis.transactionCount -= 1;\n\t\t}\n\t}\n\n\tpublic runTransactionAsync<TValue>(\n\t\tt: () => Promise<WithValue<TValue>>,\n\t\tparams?: RunTransactionParamsAlpha,\n\t): Promise<TransactionValueResult<TValue, TValue>>;\n\tpublic runTransactionAsync(\n\t\tt: () => Promise<void>,\n\t\tparams?: RunTransactionParamsAlpha,\n\t): Promise<TransactionVoidResult>;\n\tpublic async runTransactionAsync(\n\t\tt: () => Promise<WithValue<unknown> | void>,\n\t\tparams?: RunTransactionParamsAlpha,\n\t): Promise<TransactionValueResult<unknown, unknown> | TransactionVoidResult> {\n\t\tif (this.transactionCount > 0) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"An asynchronous transaction cannot be started while another transaction is already in progress.\",\n\t\t\t);\n\t\t}\n\t\tfor (const constraint of params?.preconditions ?? []) {\n\t\t\tassertValidConstraint(constraint, false);\n\t\t}\n\t\tthis.transactionCount += 1;\n\t\ttry {\n\t\t\treturn UnhydratedTreeContext.wrapTransactionResult(await t());\n\t\t} finally {\n\t\t\tthis.transactionCount -= 1;\n\t\t}\n\t}\n\n\tprivate static wrapTransactionResult<TValue>(\n\t\tvalue: WithValue<TValue> | void,\n\t): TransactionValueResult<TValue, TValue> | TransactionVoidResult {\n\t\tif (value?.value !== undefined) {\n\t\t\treturn { success: true, value: value.value };\n\t\t}\n\t\treturn { success: true };\n\t}\n}\n"]}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type { Listenable } from "@fluidframework/core-interfaces";
|
|
6
6
|
import type { OpSpaceCompressedId, SessionSpaceCompressedId } from "@fluidframework/id-compressor";
|
|
7
7
|
import { type TelemetryEventBatcher } from "@fluidframework/telemetry-utils/internal";
|
|
8
|
-
import { type ChangeFamily, type ChangeFamilyEditor, CommitKind, type GraphCommit, type RevisionTag, type TaggedChange, type RebaseStatsWithDuration } from "../core/index.js";
|
|
8
|
+
import { type ChangeFamily, type ChangeFamilyEditor, CommitKind, type CustomMetadataTree, type GraphCommit, type RevisionTag, type TaggedChange, type RebaseStatsWithDuration } from "../core/index.js";
|
|
9
9
|
export type BranchId = SessionSpaceCompressedId | "main";
|
|
10
10
|
export type EncodedBranchId = OpSpaceCompressedId;
|
|
11
11
|
/**
|
|
@@ -29,6 +29,10 @@ export type SharedTreeBranchChange<TChange> = {
|
|
|
29
29
|
} | {
|
|
30
30
|
type: "rebase";
|
|
31
31
|
change: TaggedChange<TChange> | undefined;
|
|
32
|
+
/** The commits removed from the head of the branch by this operation */
|
|
33
|
+
removedCommits: readonly GraphCommit<TChange>[];
|
|
34
|
+
/** The commits appended to the head of the branch by this operation */
|
|
35
|
+
newCommits: readonly GraphCommit<TChange>[];
|
|
32
36
|
};
|
|
33
37
|
/**
|
|
34
38
|
* The events emitted by a `SharedTreeBranch`
|
|
@@ -113,9 +117,11 @@ export declare class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChang
|
|
|
113
117
|
* Apply a change to this branch.
|
|
114
118
|
* @param change - the change to apply
|
|
115
119
|
* @param kind - the kind of change to apply
|
|
120
|
+
* @param customMetadata - {@link GraphCommit.customMetadata | metadata} to attach to the new commit.
|
|
121
|
+
* Callers reconstructing an existing commit, rather than minting one, must pass that commit's metadata.
|
|
116
122
|
* @returns the change that was applied and the new head commit of the branch
|
|
117
123
|
*/
|
|
118
|
-
apply(change: TaggedChange<TChange>, kind
|
|
124
|
+
apply(change: TaggedChange<TChange>, kind: CommitKind, customMetadata: CustomMetadataTree | undefined): void;
|
|
119
125
|
/**
|
|
120
126
|
* Notifies the branch that a commit has been sequenced by the sequencing service.
|
|
121
127
|
* @param commit - The commit that was sequenced
|
|
@@ -125,6 +131,14 @@ export declare class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChang
|
|
|
125
131
|
* Gets the commit at the head of this branch.
|
|
126
132
|
*/
|
|
127
133
|
getHead(): GraphCommit<TChange>;
|
|
134
|
+
/**
|
|
135
|
+
* Gets the number of commits in this branch.
|
|
136
|
+
* This includes commits on ancestor branches but excludes the sentinel commit at the root of all branches.
|
|
137
|
+
* @remarks
|
|
138
|
+
* This method has linear complexity in the number of commits in the branch.
|
|
139
|
+
* See {@link BranchCommitCounter} for a cached version.
|
|
140
|
+
*/
|
|
141
|
+
getCommitCount(): number;
|
|
128
142
|
/**
|
|
129
143
|
* Spawn a new branch that is based off of the current state of this branch.
|
|
130
144
|
* @param commit - The commit to base the new branch off of. Defaults to the head of this branch.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/branch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE,OAAO,KAAK,EACX,mBAAmB,EACnB,wBAAwB,EACxB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,KAAK,qBAAqB,EAAW,MAAM,0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AE,CAAC,EACT,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GACvB,MAAM,IAAI,CAaZ"}
|
|
@@ -33,7 +33,7 @@ class SharedTreeBranch {
|
|
|
33
33
|
_SharedTreeBranch_events.set(this, (0, client_utils_1.createEmitter)());
|
|
34
34
|
this.events = tslib_1.__classPrivateFieldGet(this, _SharedTreeBranch_events, "f");
|
|
35
35
|
this.disposed = false;
|
|
36
|
-
this.editor = this.changeFamily.buildEditor(mintRevisionTag, (change) => this.apply(change));
|
|
36
|
+
this.editor = this.changeFamily.buildEditor(mintRevisionTag, (change) => this.apply(change, index_js_1.CommitKind.Default, undefined));
|
|
37
37
|
this.unsubscribeBranchTrimmer = branchTrimmer?.on("ancestryTrimmed", (commit) => {
|
|
38
38
|
tslib_1.__classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("ancestryTrimmed", commit);
|
|
39
39
|
});
|
|
@@ -51,15 +51,18 @@ class SharedTreeBranch {
|
|
|
51
51
|
* Apply a change to this branch.
|
|
52
52
|
* @param change - the change to apply
|
|
53
53
|
* @param kind - the kind of change to apply
|
|
54
|
+
* @param customMetadata - {@link GraphCommit.customMetadata | metadata} to attach to the new commit.
|
|
55
|
+
* Callers reconstructing an existing commit, rather than minting one, must pass that commit's metadata.
|
|
54
56
|
* @returns the change that was applied and the new head commit of the branch
|
|
55
57
|
*/
|
|
56
|
-
apply(change, kind
|
|
58
|
+
apply(change, kind, customMetadata) {
|
|
57
59
|
this.assertNotDisposed();
|
|
58
60
|
const revisionTag = change.revision;
|
|
59
61
|
(0, internal_1.assert)(revisionTag !== undefined, 0xa49 /* Revision tag must be provided */);
|
|
60
62
|
const newHead = (0, index_js_1.mintCommit)(this.head, {
|
|
61
63
|
revision: revisionTag,
|
|
62
64
|
change: change.change,
|
|
65
|
+
customMetadata,
|
|
63
66
|
});
|
|
64
67
|
const changeEvent = {
|
|
65
68
|
type: "append",
|
|
@@ -84,6 +87,21 @@ class SharedTreeBranch {
|
|
|
84
87
|
getHead() {
|
|
85
88
|
return this.head;
|
|
86
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Gets the number of commits in this branch.
|
|
92
|
+
* This includes commits on ancestor branches but excludes the sentinel commit at the root of all branches.
|
|
93
|
+
* @remarks
|
|
94
|
+
* This method has linear complexity in the number of commits in the branch.
|
|
95
|
+
* See {@link BranchCommitCounter} for a cached version.
|
|
96
|
+
*/
|
|
97
|
+
getCommitCount() {
|
|
98
|
+
let count = 0;
|
|
99
|
+
for (let commit = this.head; commit !== undefined; commit = commit.parent) {
|
|
100
|
+
count++;
|
|
101
|
+
}
|
|
102
|
+
// Exclude the sentinel commit that serves as the base to all branches.
|
|
103
|
+
return count - 1;
|
|
104
|
+
}
|
|
87
105
|
/**
|
|
88
106
|
* Spawn a new branch that is based off of the current state of this branch.
|
|
89
107
|
* @param commit - The commit to base the new branch off of. Defaults to the head of this branch.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.js","sourceRoot":"","sources":["../../src/shared-tree-core/branch.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH,+DAA6D;AAE7D,kEAA6D;AAK7D,uEAA+F;AAE/F,+CAc0B;AAC1B,+CAAqE;AA2FrE;;GAEG;AACH,MAAa,gBAAgB;IAa5B;;;;;;;OAOG;IACH,YACS,IAA0B,EAClB,YAAsE,EACrE,eAAkC,EAClC,aAAgD,EAChD,qBAEhB;QANO,SAAI,GAAJ,IAAI,CAAsB;QAClB,iBAAY,GAAZ,YAAY,CAA0D;QACrE,oBAAe,GAAf,eAAe,CAAmB;QAClC,kBAAa,GAAb,aAAa,CAAmC;QAChD,0BAAqB,GAArB,qBAAqB,CAErC;QAvBO,mCACR,IAAA,4BAAa,GAAsE,EAAC;QACrE,WAAM,GAElB,+BAAA,IAAI,gCAAQ,CAAC;QAET,aAAQ,GAAG,KAAK,CAAC;QAmBxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,WAA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AQ,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACxD,CAAC;CACD;AA9RD,4CA8RC;;AAED;;;;;;;GAOG;AACH,sCAAsC;AACtC,SAAgB,gBAAgB,CAC/B,MAAS,EACT,MAAyB;IAEzB,MAAM,IAAI,GAAmB,EAAE,CAAC;IAChC,IAAI,CAAC,IAAI,CACR,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAO,EAAE,EAAE;QACpC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,CAAC;IACd,CAAC,CAAC,CACF,CAAC;IACF,OAAO,GAAG,EAAE;QACX,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,GAAG,EAAE,CAAC;QACP,CAAC;IACF,CAAC,CAAC;AACH,CAAC;AAhBD,4CAgBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tOpSpaceCompressedId,\n\tSessionSpaceCompressedId,\n} from \"@fluidframework/id-compressor\";\nimport { type TelemetryEventBatcher, measure } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype BranchRebaseResult,\n\ttype ChangeFamily,\n\ttype ChangeFamilyEditor,\n\tCommitKind,\n\ttype GraphCommit,\n\ttype RevisionTag,\n\ttype TaggedChange,\n\tfindAncestor,\n\tmakeAnonChange,\n\tmintCommit,\n\trebaseBranch,\n\ttagRollbackInverse,\n\ttype RebaseStatsWithDuration,\n} from \"../core/index.js\";\nimport { hasSome, defineLazyCachedProperty } from \"../util/index.js\";\n\nexport type BranchId = SessionSpaceCompressedId | \"main\";\nexport type EncodedBranchId = OpSpaceCompressedId;\n\n/**\n * Describes a change to a `SharedTreeBranch`. Each of the following event types provides a `change` which contains the net change to the branch (or is undefined if there was no net change):\n * * Append - when one or more commits are appended to the head of the branch, for example via\n * a change applied by the branch's editor, or as a result of merging another branch into this one\n * * Remove - when one or more commits are removed from the head of the branch.\n * * Rebase - when a rebase operation adds commits from another branch and replaces existing commits with their rebased versions.\n */\nexport type SharedTreeBranchChange<TChange> =\n\t| {\n\t\t\ttype: \"append\";\n\t\t\tkind: CommitKind;\n\t\t\tchange: TaggedChange<TChange>;\n\t\t\t/** The commits appended to the head of the branch by this operation */\n\t\t\tnewCommits: readonly [GraphCommit<TChange>, ...GraphCommit<TChange>[]];\n\t }\n\t| {\n\t\t\ttype: \"remove\";\n\t\t\tchange: TaggedChange<TChange>;\n\t\t\t/** The commits removed from the head of the branch by this operation */\n\t\t\tremovedCommits: readonly [GraphCommit<TChange>, ...GraphCommit<TChange>[]];\n\t }\n\t| {\n\t\t\ttype: \"rebase\";\n\t\t\tchange: TaggedChange<TChange> | undefined;\n\t };\n\n/**\n * The events emitted by a `SharedTreeBranch`\n */\nexport interface SharedTreeBranchEvents<\n\tTEditor extends ChangeFamilyEditor,\n\tTChange,\n\tTChangeProcessingContext,\n> extends BranchTrimmingEvents {\n\t/**\n\t * Fired just before the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tbeforeChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * Fired just after the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tafterChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * Fired when this branch forks\n\t * @param fork - the new branch that forked off of this branch\n\t */\n\tfork(fork: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>): void;\n\n\t/**\n\t * Fired when a commit is ordered by the sequencing service.\n\t * @param commit - The commit that was sequenced\n\t *\n\t * @remarks\n\t * Once a commit is sequenced, the following guarantees hold:\n\t * 1. The changes carried by the commit have been persisted and other peers are able to see them.\n\t * 2. There can be no more concurrent changes sequenced before this commit, which means this commit has reached its settled form.\n\t */\n\tcommitSequenced(commit: GraphCommit<TChange>): void;\n\n\t/**\n\t * Fired after this branch is disposed\n\t */\n\tdispose(): void;\n}\n\n/**\n * Events related to branch trimming.\n *\n * @remarks\n * Trimming is a very specific kind of mutation which is the only allowed mutations to branches.\n * References to commits from other commits are removed so that the commit objects can be GC'd by the JS engine.\n * This happens by changing a commit's parent property to undefined, which drops all commits that are in its \"ancestry\".\n * It is done as a performance optimization when it is determined that commits are no longer needed for future computation.\n */\nexport interface BranchTrimmingEvents {\n\t/**\n\t * Fired when some contiguous range of commits beginning with the \"global tail\" of this branch are trimmed from the branch.\n\t * This happens by deleting the parent pointer to the last commit in that range. This event can be fired at any time.\n\t */\n\tancestryTrimmed(trimmedRevisions: RevisionTag[]): void;\n}\n\n/**\n * A branch of changes that can be applied to a SharedTree.\n */\nexport class SharedTreeBranch<\n\tTEditor extends ChangeFamilyEditor,\n\tTChange,\n\tTChangeProcessingContext,\n> {\n\treadonly #events =\n\t\tcreateEmitter<SharedTreeBranchEvents<TEditor, TChange, TChangeProcessingContext>>();\n\tpublic readonly events: Listenable<\n\t\tSharedTreeBranchEvents<TEditor, TChange, TChangeProcessingContext>\n\t> = this.#events;\n\tpublic readonly editor: TEditor;\n\tprivate disposed = false;\n\tprivate readonly unsubscribeBranchTrimmer?: () => void;\n\t/**\n\t * Construct a new branch.\n\t * @param head - the head of the branch\n\t * @param changeFamily - determines the set of changes that this branch can commit\n\t * @param mintRevisionTag - used to generate a `RevisionTag` for each change.\n\t * @param branchTrimmer - an optional event emitter that informs the branch it has been trimmed. If this is not supplied, then the branch must\n\t * never be trimmed. See {@link BranchTrimmingEvents} for details on trimming.\n\t */\n\tpublic constructor(\n\t\tprivate head: GraphCommit<TChange>,\n\t\tpublic readonly changeFamily: ChangeFamily<TEditor, TChange, TChangeProcessingContext>,\n\t\tprivate readonly mintRevisionTag: () => RevisionTag,\n\t\tprivate readonly branchTrimmer?: Listenable<BranchTrimmingEvents>,\n\t\tprivate readonly telemetryEventBatcher?: TelemetryEventBatcher<\n\t\t\tkeyof RebaseStatsWithDuration\n\t\t>,\n\t) {\n\t\tthis.editor = this.changeFamily.buildEditor(mintRevisionTag, (change) =>\n\t\t\tthis.apply(change),\n\t\t);\n\t\tthis.unsubscribeBranchTrimmer = branchTrimmer?.on(\"ancestryTrimmed\", (commit) => {\n\t\t\tthis.#events.emit(\"ancestryTrimmed\", commit);\n\t\t});\n\t}\n\n\t/**\n\t * Sets the head of this branch.\n\t * @remarks This is a \"manual override\" of sorts, for when the branch needs to be set to a certain state without going through the usual flow of edits.\n\t * This might be necessary as a performance optimization, or to prevent parts of the system updating incorrectly (this method emits no change events!).\n\t */\n\tpublic setHead(head: GraphCommit<TChange>): void {\n\t\tthis.assertNotDisposed();\n\t\tthis.head = head;\n\t}\n\n\t/**\n\t * Apply a change to this branch.\n\t * @param change - the change to apply\n\t * @param kind - the kind of change to apply\n\t * @returns the change that was applied and the new head commit of the branch\n\t */\n\tpublic apply(change: TaggedChange<TChange>, kind: CommitKind = CommitKind.Default): void {\n\t\tthis.assertNotDisposed();\n\n\t\tconst revisionTag = change.revision;\n\t\tassert(revisionTag !== undefined, 0xa49 /* Revision tag must be provided */);\n\n\t\tconst newHead = mintCommit(this.head, {\n\t\t\trevision: revisionTag,\n\t\t\tchange: change.change,\n\t\t});\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"append\",\n\t\t\tkind,\n\t\t\tchange,\n\t\t\tnewCommits: [newHead],\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t}\n\n\t/**\n\t * Notifies the branch that a commit has been sequenced by the sequencing service.\n\t * @param commit - The commit that was sequenced\n\t */\n\tpublic commitWasSequenced(commit: GraphCommit<TChange>): void {\n\t\tthis.#events.emit(\"commitSequenced\", commit);\n\t}\n\n\t/**\n\t * Gets the commit at the head of this branch.\n\t */\n\tpublic getHead(): GraphCommit<TChange> {\n\t\treturn this.head;\n\t}\n\n\t/**\n\t * Spawn a new branch that is based off of the current state of this branch.\n\t * @param commit - The commit to base the new branch off of. Defaults to the head of this branch.\n\t * @param mintRevisionTag - used to generate a `RevisionTag` for each change.\n\t * @remarks Changes made to the new branch will not be applied to this branch until the new branch is {@link SharedTreeBranch.merge | merged} back in.\n\t * Forks created during a transaction will be disposed when the transaction ends.\n\t */\n\tpublic fork(\n\t\tcommit: GraphCommit<TChange> = this.head,\n\t\tmintRevisionTag: () => RevisionTag = this.mintRevisionTag,\n\t): SharedTreeBranch<TEditor, TChange, TChangeProcessingContext> {\n\t\tthis.assertNotDisposed();\n\t\tconst fork = new SharedTreeBranch(\n\t\t\tcommit,\n\t\t\tthis.changeFamily,\n\t\t\tmintRevisionTag,\n\t\t\tthis.branchTrimmer,\n\t\t);\n\t\tthis.#events.emit(\"fork\", fork);\n\t\treturn fork;\n\t}\n\n\t/**\n\t * Rebase the changes that have been applied to this branch over divergent changes in the given branch.\n\t * After this operation completes, this branch will be based off of `branch`.\n\t *\n\t * @param branch - the branch to rebase onto\n\t * @param upTo - the furthest commit on `branch` over which to rebase (inclusive). Defaults to the head commit of `branch`.\n\t * @returns the result of the rebase or undefined if nothing changed\n\t */\n\tpublic rebaseOnto(\n\t\tbranch: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>,\n\t\tupTo = branch.getHead(),\n\t): void {\n\t\tthis.assertNotDisposed();\n\n\t\t// Rebase this branch onto the given branch\n\t\tconst rebaseResult = this.rebaseBranch(this, branch, upTo);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The net change to this branch is provided by the `rebaseBranch` API\n\t\tconst { newSourceHead, commits } = rebaseResult;\n\t\tconst { deletedSourceCommits, targetCommits, sourceCommits } = commits;\n\t\tassert(hasSome(targetCommits), 0xa83 /* Expected commit(s) for a non no-op rebase */);\n\n\t\tconst newCommits = [...targetCommits, ...sourceCommits];\n\t\tconst changeEvent = {\n\t\t\ttype: \"rebase\",\n\t\t\tget change() {\n\t\t\t\tconst change = rebaseResult.sourceChange;\n\t\t\t\treturn change === undefined ? undefined : makeAnonChange(change);\n\t\t\t},\n\t\t\tremovedCommits: deletedSourceCommits,\n\t\t\tnewCommits,\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newSourceHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t}\n\n\t/**\n\t * Remove a range of commits from this branch.\n\t * @param commit - All commits after (but not including) this commit will be removed.\n\t * @returns The net change to this branch and the commits that were removed from this branch.\n\t */\n\tpublic removeAfter(commit: GraphCommit<TChange>): void {\n\t\tif (commit === this.head) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst removedCommits: GraphCommit<TChange>[] = [];\n\t\tconst inverses: TaggedChange<TChange>[] = [];\n\t\tfindAncestor([this.head, removedCommits], (c) => {\n\t\t\t// TODO: Pull this side effect out if/when more diverse ancestry walking helpers are available\n\t\t\tif (c !== commit) {\n\t\t\t\tconst revision = this.mintRevisionTag();\n\t\t\t\tconst inverse = this.changeFamily.rebaser.invert(c, true, revision);\n\t\t\t\tinverses.push(tagRollbackInverse(inverse, revision, c.revision));\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\t\tassert(hasSome(removedCommits), 0xa84 /* Commit must be in the branch's ancestry */);\n\n\t\tconst change = makeAnonChange(this.changeFamily.rebaser.compose(inverses));\n\t\tconst changeEvent = {\n\t\t\ttype: \"remove\",\n\t\t\tchange,\n\t\t\tremovedCommits,\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = commit;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t}\n\n\t/**\n\t * Apply all the divergent changes on the given branch to this branch.\n\t *\n\t * @param branch - the branch to merge into this branch\n\t * @returns the commits that were added to this branch by the merge, or undefined if nothing changed\n\t */\n\tpublic merge(\n\t\tbranch: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>,\n\t): { sourceCommits: GraphCommit<TChange>[] } | undefined {\n\t\tthis.assertNotDisposed();\n\t\tbranch.assertNotDisposed();\n\n\t\tif (branch === this) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Rebase the given branch onto this branch\n\t\tconst rebaseResult = this.rebaseBranch(branch, this);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Compute the net change to this branch\n\t\tconst sourceCommits = rebaseResult.commits.sourceCommits;\n\t\tassert(hasSome(sourceCommits), 0xa86 /* Expected source commits in non no-op merge */);\n\t\tconst { rebaser } = this.changeFamily;\n\t\tconst changeEvent = defineLazyCachedProperty(\n\t\t\t{\n\t\t\t\ttype: \"append\",\n\t\t\t\tkind: CommitKind.Default,\n\t\t\t\tnewCommits: sourceCommits,\n\t\t\t} as const,\n\t\t\t\"change\",\n\t\t\t() => makeAnonChange(rebaser.compose(sourceCommits)),\n\t\t);\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = rebaseResult.newSourceHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn { sourceCommits };\n\t}\n\n\t/** Rebase `branchHead` onto `onto`, but return undefined if nothing changed */\n\tprivate rebaseBranch(\n\t\tbranch: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>,\n\t\tonto: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>,\n\t\tupTo = onto.getHead(),\n\t): BranchRebaseResult<TChange> | undefined {\n\t\tconst { head } = branch;\n\t\tif (head === upTo) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst { duration, output } = measure(() =>\n\t\t\trebaseBranch(\n\t\t\t\tthis.mintRevisionTag,\n\t\t\t\tthis.changeFamily.rebaser,\n\t\t\t\thead,\n\t\t\t\tupTo,\n\t\t\t\tonto.getHead(),\n\t\t\t),\n\t\t);\n\n\t\tthis.telemetryEventBatcher?.accumulateAndLog({ duration, ...output.telemetryProperties });\n\n\t\tif (this.head === output.newSourceHead) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\t/**\n\t * Dispose this branch, freezing its state.\n\t *\n\t * @remarks\n\t * Attempts to further mutate the branch will error.\n\t * Any transactions in progress will be aborted.\n\t * Calling dispose more than once has no effect.\n\t */\n\tpublic dispose(): void {\n\t\tif (this.disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.unsubscribeBranchTrimmer?.();\n\n\t\tthis.disposed = true;\n\t\tthis.#events.emit(\"dispose\");\n\t}\n\n\tprivate assertNotDisposed(): void {\n\t\tassert(!this.disposed, 0x66e /* Branch is disposed */);\n\t}\n}\n\n/**\n * Registers an event listener that fires when the given branch forks.\n * The listener will also fire when any of those forks fork, and when those forks of forks fork, and so on.\n * @param branch - the branch that will be listened to for forks\n * @param onFork - the fork event listener\n * @returns a function which when called will deregister all registrations (including transitive) created by this function.\n * The deregister function has undefined behavior if called more than once.\n */\n// Branches are invariant over TChange\nexport function onForkTransitive<T extends { events: Listenable<{ fork(t: T): void }> }>(\n\tbranch: T,\n\tonFork: (fork: T) => void,\n): () => void {\n\tconst offs: (() => void)[] = [];\n\toffs.push(\n\t\tbranch.events.on(\"fork\", (fork: T) => {\n\t\t\toffs.push(onForkTransitive(fork, onFork));\n\t\t\tonFork(fork);\n\t\t}),\n\t);\n\treturn () => {\n\t\tfor (const off of offs) {\n\t\t\toff();\n\t\t}\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"branch.js","sourceRoot":"","sources":["../../src/shared-tree-core/branch.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH,+DAA6D;AAE7D,kEAA6D;AAK7D,uEAA+F;AAE/F,+CAe0B;AAC1B,+CAAqE;AA+FrE;;GAEG;AACH,MAAa,gBAAgB;IAa5B;;;;;;;OAOG;IACH,YACS,IAA0B,EAClB,YAAsE,EACrE,eAAkC,EAClC,aAA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CAAC,CAAC;AACH,CAAC;AAhBD,4CAgBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tOpSpaceCompressedId,\n\tSessionSpaceCompressedId,\n} from \"@fluidframework/id-compressor\";\nimport { type TelemetryEventBatcher, measure } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype BranchRebaseResult,\n\ttype ChangeFamily,\n\ttype ChangeFamilyEditor,\n\tCommitKind,\n\ttype CustomMetadataTree,\n\ttype GraphCommit,\n\ttype RevisionTag,\n\ttype TaggedChange,\n\tfindAncestor,\n\tmakeAnonChange,\n\tmintCommit,\n\trebaseBranch,\n\ttagRollbackInverse,\n\ttype RebaseStatsWithDuration,\n} from \"../core/index.js\";\nimport { hasSome, defineLazyCachedProperty } from \"../util/index.js\";\n\nexport type BranchId = SessionSpaceCompressedId | \"main\";\nexport type EncodedBranchId = OpSpaceCompressedId;\n\n/**\n * Describes a change to a `SharedTreeBranch`. Each of the following event types provides a `change` which contains the net change to the branch (or is undefined if there was no net change):\n * * Append - when one or more commits are appended to the head of the branch, for example via\n * a change applied by the branch's editor, or as a result of merging another branch into this one\n * * Remove - when one or more commits are removed from the head of the branch.\n * * Rebase - when a rebase operation adds commits from another branch and replaces existing commits with their rebased versions.\n */\nexport type SharedTreeBranchChange<TChange> =\n\t| {\n\t\t\ttype: \"append\";\n\t\t\tkind: CommitKind;\n\t\t\tchange: TaggedChange<TChange>;\n\t\t\t/** The commits appended to the head of the branch by this operation */\n\t\t\tnewCommits: readonly [GraphCommit<TChange>, ...GraphCommit<TChange>[]];\n\t }\n\t| {\n\t\t\ttype: \"remove\";\n\t\t\tchange: TaggedChange<TChange>;\n\t\t\t/** The commits removed from the head of the branch by this operation */\n\t\t\tremovedCommits: readonly [GraphCommit<TChange>, ...GraphCommit<TChange>[]];\n\t }\n\t| {\n\t\t\ttype: \"rebase\";\n\t\t\tchange: TaggedChange<TChange> | undefined;\n\t\t\t/** The commits removed from the head of the branch by this operation */\n\t\t\tremovedCommits: readonly GraphCommit<TChange>[];\n\t\t\t/** The commits appended to the head of the branch by this operation */\n\t\t\tnewCommits: readonly GraphCommit<TChange>[];\n\t };\n\n/**\n * The events emitted by a `SharedTreeBranch`\n */\nexport interface SharedTreeBranchEvents<\n\tTEditor extends ChangeFamilyEditor,\n\tTChange,\n\tTChangeProcessingContext,\n> extends BranchTrimmingEvents {\n\t/**\n\t * Fired just before the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tbeforeChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * Fired just after the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tafterChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * Fired when this branch forks\n\t * @param fork - the new branch that forked off of this branch\n\t */\n\tfork(fork: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>): void;\n\n\t/**\n\t * Fired when a commit is ordered by the sequencing service.\n\t * @param commit - The commit that was sequenced\n\t *\n\t * @remarks\n\t * Once a commit is sequenced, the following guarantees hold:\n\t * 1. The changes carried by the commit have been persisted and other peers are able to see them.\n\t * 2. There can be no more concurrent changes sequenced before this commit, which means this commit has reached its settled form.\n\t */\n\tcommitSequenced(commit: GraphCommit<TChange>): void;\n\n\t/**\n\t * Fired after this branch is disposed\n\t */\n\tdispose(): void;\n}\n\n/**\n * Events related to branch trimming.\n *\n * @remarks\n * Trimming is a very specific kind of mutation which is the only allowed mutations to branches.\n * References to commits from other commits are removed so that the commit objects can be GC'd by the JS engine.\n * This happens by changing a commit's parent property to undefined, which drops all commits that are in its \"ancestry\".\n * It is done as a performance optimization when it is determined that commits are no longer needed for future computation.\n */\nexport interface BranchTrimmingEvents {\n\t/**\n\t * Fired when some contiguous range of commits beginning with the \"global tail\" of this branch are trimmed from the branch.\n\t * This happens by deleting the parent pointer to the last commit in that range. This event can be fired at any time.\n\t */\n\tancestryTrimmed(trimmedRevisions: RevisionTag[]): void;\n}\n\n/**\n * A branch of changes that can be applied to a SharedTree.\n */\nexport class SharedTreeBranch<\n\tTEditor extends ChangeFamilyEditor,\n\tTChange,\n\tTChangeProcessingContext,\n> {\n\treadonly #events =\n\t\tcreateEmitter<SharedTreeBranchEvents<TEditor, TChange, TChangeProcessingContext>>();\n\tpublic readonly events: Listenable<\n\t\tSharedTreeBranchEvents<TEditor, TChange, TChangeProcessingContext>\n\t> = this.#events;\n\tpublic readonly editor: TEditor;\n\tprivate disposed = false;\n\tprivate readonly unsubscribeBranchTrimmer?: () => void;\n\t/**\n\t * Construct a new branch.\n\t * @param head - the head of the branch\n\t * @param changeFamily - determines the set of changes that this branch can commit\n\t * @param mintRevisionTag - used to generate a `RevisionTag` for each change.\n\t * @param branchTrimmer - an optional event emitter that informs the branch it has been trimmed. If this is not supplied, then the branch must\n\t * never be trimmed. See {@link BranchTrimmingEvents} for details on trimming.\n\t */\n\tpublic constructor(\n\t\tprivate head: GraphCommit<TChange>,\n\t\tpublic readonly changeFamily: ChangeFamily<TEditor, TChange, TChangeProcessingContext>,\n\t\tprivate readonly mintRevisionTag: () => RevisionTag,\n\t\tprivate readonly branchTrimmer?: Listenable<BranchTrimmingEvents>,\n\t\tprivate readonly telemetryEventBatcher?: TelemetryEventBatcher<\n\t\t\tkeyof RebaseStatsWithDuration\n\t\t>,\n\t) {\n\t\tthis.editor = this.changeFamily.buildEditor(mintRevisionTag, (change) =>\n\t\t\tthis.apply(change, CommitKind.Default, undefined),\n\t\t);\n\t\tthis.unsubscribeBranchTrimmer = branchTrimmer?.on(\"ancestryTrimmed\", (commit) => {\n\t\t\tthis.#events.emit(\"ancestryTrimmed\", commit);\n\t\t});\n\t}\n\n\t/**\n\t * Sets the head of this branch.\n\t * @remarks This is a \"manual override\" of sorts, for when the branch needs to be set to a certain state without going through the usual flow of edits.\n\t * This might be necessary as a performance optimization, or to prevent parts of the system updating incorrectly (this method emits no change events!).\n\t */\n\tpublic setHead(head: GraphCommit<TChange>): void {\n\t\tthis.assertNotDisposed();\n\t\tthis.head = head;\n\t}\n\n\t/**\n\t * Apply a change to this branch.\n\t * @param change - the change to apply\n\t * @param kind - the kind of change to apply\n\t * @param customMetadata - {@link GraphCommit.customMetadata | metadata} to attach to the new commit.\n\t * Callers reconstructing an existing commit, rather than minting one, must pass that commit's metadata.\n\t * @returns the change that was applied and the new head commit of the branch\n\t */\n\tpublic apply(\n\t\tchange: TaggedChange<TChange>,\n\t\tkind: CommitKind,\n\t\tcustomMetadata: CustomMetadataTree | undefined,\n\t): void {\n\t\tthis.assertNotDisposed();\n\n\t\tconst revisionTag = change.revision;\n\t\tassert(revisionTag !== undefined, 0xa49 /* Revision tag must be provided */);\n\n\t\tconst newHead = mintCommit(this.head, {\n\t\t\trevision: revisionTag,\n\t\t\tchange: change.change,\n\t\t\tcustomMetadata,\n\t\t});\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"append\",\n\t\t\tkind,\n\t\t\tchange,\n\t\t\tnewCommits: [newHead],\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t}\n\n\t/**\n\t * Notifies the branch that a commit has been sequenced by the sequencing service.\n\t * @param commit - The commit that was sequenced\n\t */\n\tpublic commitWasSequenced(commit: GraphCommit<TChange>): void {\n\t\tthis.#events.emit(\"commitSequenced\", commit);\n\t}\n\n\t/**\n\t * Gets the commit at the head of this branch.\n\t */\n\tpublic getHead(): GraphCommit<TChange> {\n\t\treturn this.head;\n\t}\n\n\t/**\n\t * Gets the number of commits in this branch.\n\t * This includes commits on ancestor branches but excludes the sentinel commit at the root of all branches.\n\t * @remarks\n\t * This method has linear complexity in the number of commits in the branch.\n\t * See {@link BranchCommitCounter} for a cached version.\n\t */\n\tpublic getCommitCount(): number {\n\t\tlet count = 0;\n\t\tfor (\n\t\t\tlet commit: GraphCommit<TChange> | undefined = this.head;\n\t\t\tcommit !== undefined;\n\t\t\tcommit = commit.parent\n\t\t) {\n\t\t\tcount++;\n\t\t}\n\t\t// Exclude the sentinel commit that serves as the base to all branches.\n\t\treturn count - 1;\n\t}\n\n\t/**\n\t * Spawn a new branch that is based off of the current state of this branch.\n\t * @param commit - The commit to base the new branch off of. Defaults to the head of this branch.\n\t * @param mintRevisionTag - used to generate a `RevisionTag` for each change.\n\t * @remarks Changes made to the new branch will not be applied to this branch until the new branch is {@link SharedTreeBranch.merge | merged} back in.\n\t * Forks created during a transaction will be disposed when the transaction ends.\n\t */\n\tpublic fork(\n\t\tcommit: GraphCommit<TChange> = this.head,\n\t\tmintRevisionTag: () => RevisionTag = this.mintRevisionTag,\n\t): SharedTreeBranch<TEditor, TChange, TChangeProcessingContext> {\n\t\tthis.assertNotDisposed();\n\t\tconst fork = new SharedTreeBranch(\n\t\t\tcommit,\n\t\t\tthis.changeFamily,\n\t\t\tmintRevisionTag,\n\t\t\tthis.branchTrimmer,\n\t\t);\n\t\tthis.#events.emit(\"fork\", fork);\n\t\treturn fork;\n\t}\n\n\t/**\n\t * Rebase the changes that have been applied to this branch over divergent changes in the given branch.\n\t * After this operation completes, this branch will be based off of `branch`.\n\t *\n\t * @param branch - the branch to rebase onto\n\t * @param upTo - the furthest commit on `branch` over which to rebase (inclusive). Defaults to the head commit of `branch`.\n\t * @returns the result of the rebase or undefined if nothing changed\n\t */\n\tpublic rebaseOnto(\n\t\tbranch: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>,\n\t\tupTo = branch.getHead(),\n\t): void {\n\t\tthis.assertNotDisposed();\n\n\t\t// Rebase this branch onto the given branch\n\t\tconst rebaseResult = this.rebaseBranch(this, branch, upTo);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The net change to this branch is provided by the `rebaseBranch` API\n\t\tconst { newSourceHead, commits } = rebaseResult;\n\t\tconst { deletedSourceCommits, targetCommits, sourceCommits } = commits;\n\t\tassert(hasSome(targetCommits), 0xa83 /* Expected commit(s) for a non no-op rebase */);\n\n\t\tconst newCommits = [...targetCommits, ...sourceCommits];\n\t\tconst changeEvent = {\n\t\t\ttype: \"rebase\",\n\t\t\tget change() {\n\t\t\t\tconst change = rebaseResult.sourceChange;\n\t\t\t\treturn change === undefined ? undefined : makeAnonChange(change);\n\t\t\t},\n\t\t\tremovedCommits: deletedSourceCommits,\n\t\t\tnewCommits,\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newSourceHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t}\n\n\t/**\n\t * Remove a range of commits from this branch.\n\t * @param commit - All commits after (but not including) this commit will be removed.\n\t * @returns The net change to this branch and the commits that were removed from this branch.\n\t */\n\tpublic removeAfter(commit: GraphCommit<TChange>): void {\n\t\tif (commit === this.head) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst removedCommits: GraphCommit<TChange>[] = [];\n\t\tconst inverses: TaggedChange<TChange>[] = [];\n\t\tfindAncestor([this.head, removedCommits], (c) => {\n\t\t\t// TODO: Pull this side effect out if/when more diverse ancestry walking helpers are available\n\t\t\tif (c !== commit) {\n\t\t\t\tconst revision = this.mintRevisionTag();\n\t\t\t\tconst inverse = this.changeFamily.rebaser.invert(c, true, revision);\n\t\t\t\tinverses.push(tagRollbackInverse(inverse, revision, c.revision));\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\t\tassert(hasSome(removedCommits), 0xa84 /* Commit must be in the branch's ancestry */);\n\n\t\tconst change = makeAnonChange(this.changeFamily.rebaser.compose(inverses));\n\t\tconst changeEvent = {\n\t\t\ttype: \"remove\",\n\t\t\tchange,\n\t\t\tremovedCommits,\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = commit;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t}\n\n\t/**\n\t * Apply all the divergent changes on the given branch to this branch.\n\t *\n\t * @param branch - the branch to merge into this branch\n\t * @returns the commits that were added to this branch by the merge, or undefined if nothing changed\n\t */\n\tpublic merge(\n\t\tbranch: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>,\n\t): { sourceCommits: GraphCommit<TChange>[] } | undefined {\n\t\tthis.assertNotDisposed();\n\t\tbranch.assertNotDisposed();\n\n\t\tif (branch === this) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Rebase the given branch onto this branch\n\t\tconst rebaseResult = this.rebaseBranch(branch, this);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Compute the net change to this branch\n\t\tconst sourceCommits = rebaseResult.commits.sourceCommits;\n\t\tassert(hasSome(sourceCommits), 0xa86 /* Expected source commits in non no-op merge */);\n\t\tconst { rebaser } = this.changeFamily;\n\t\tconst changeEvent = defineLazyCachedProperty(\n\t\t\t{\n\t\t\t\ttype: \"append\",\n\t\t\t\tkind: CommitKind.Default,\n\t\t\t\tnewCommits: sourceCommits,\n\t\t\t} as const,\n\t\t\t\"change\",\n\t\t\t() => makeAnonChange(rebaser.compose(sourceCommits)),\n\t\t);\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = rebaseResult.newSourceHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn { sourceCommits };\n\t}\n\n\t/** Rebase `branchHead` onto `onto`, but return undefined if nothing changed */\n\tprivate rebaseBranch(\n\t\tbranch: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>,\n\t\tonto: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>,\n\t\tupTo = onto.getHead(),\n\t): BranchRebaseResult<TChange> | undefined {\n\t\tconst { head } = branch;\n\t\tif (head === upTo) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst { duration, output } = measure(() =>\n\t\t\trebaseBranch(\n\t\t\t\tthis.mintRevisionTag,\n\t\t\t\tthis.changeFamily.rebaser,\n\t\t\t\thead,\n\t\t\t\tupTo,\n\t\t\t\tonto.getHead(),\n\t\t\t),\n\t\t);\n\n\t\tthis.telemetryEventBatcher?.accumulateAndLog({ duration, ...output.telemetryProperties });\n\n\t\tif (this.head === output.newSourceHead) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\t/**\n\t * Dispose this branch, freezing its state.\n\t *\n\t * @remarks\n\t * Attempts to further mutate the branch will error.\n\t * Any transactions in progress will be aborted.\n\t * Calling dispose more than once has no effect.\n\t */\n\tpublic dispose(): void {\n\t\tif (this.disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.unsubscribeBranchTrimmer?.();\n\n\t\tthis.disposed = true;\n\t\tthis.#events.emit(\"dispose\");\n\t}\n\n\tprivate assertNotDisposed(): void {\n\t\tassert(!this.disposed, 0x66e /* Branch is disposed */);\n\t}\n}\n\n/**\n * Registers an event listener that fires when the given branch forks.\n * The listener will also fire when any of those forks fork, and when those forks of forks fork, and so on.\n * @param branch - the branch that will be listened to for forks\n * @param onFork - the fork event listener\n * @returns a function which when called will deregister all registrations (including transitive) created by this function.\n * The deregister function has undefined behavior if called more than once.\n */\n// Branches are invariant over TChange\nexport function onForkTransitive<T extends { events: Listenable<{ fork(t: T): void }> }>(\n\tbranch: T,\n\tonFork: (fork: T) => void,\n): () => void {\n\tconst offs: (() => void)[] = [];\n\toffs.push(\n\t\tbranch.events.on(\"fork\", (fork: T) => {\n\t\t\toffs.push(onForkTransitive(fork, onFork));\n\t\t\tonFork(fork);\n\t\t}),\n\t);\n\treturn () => {\n\t\tfor (const off of offs) {\n\t\t\toff();\n\t\t}\n\t};\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { ChangeFamilyEditor } from "../core/index.js";
|
|
6
|
+
import type { SharedTreeBranch } from "./branch.js";
|
|
7
|
+
/**
|
|
8
|
+
* A utility class that counts the number of commits in a branch and keeps the count updated as the branch changes.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This class has no inside knowledge of what the commits represent.
|
|
12
|
+
* It is therefore oblivious to any scheme where some root commit is considered "special" and should not be counted.
|
|
13
|
+
*/
|
|
14
|
+
export declare class BranchCommitCounter<TEditor extends ChangeFamilyEditor, TChange, TChangeProcessingContext> {
|
|
15
|
+
private readonly branch;
|
|
16
|
+
private unsubscribeAfterChange?;
|
|
17
|
+
private unsubscribeAncestryTrimmed?;
|
|
18
|
+
private commitCountInitialized;
|
|
19
|
+
private cachedCommitCount;
|
|
20
|
+
constructor(branch: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>);
|
|
21
|
+
dispose(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Gets the number of commits in the branch.
|
|
24
|
+
*/
|
|
25
|
+
get count(): number;
|
|
26
|
+
private subscribeToBranch;
|
|
27
|
+
private unsubscribeFromBranch;
|
|
28
|
+
private readonly onAfterBranchChange;
|
|
29
|
+
private readonly onAncestryTrimmed;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=branchCommitCounter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branchCommitCounter.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/branchCommitCounter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,kBAAkB,EAAe,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAA0B,MAAM,aAAa,CAAC;AAE5E;;;;;;GAMG;AACH,qBAAa,mBAAmB,CAC/B,OAAO,SAAS,kBAAkB,EAClC,OAAO,EACP,wBAAwB;IAQvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IANxB,OAAO,CAAC,sBAAsB,CAAC,CAAa;IAC5C,OAAO,CAAC,0BAA0B,CAAC,CAAa;IAChD,OAAO,CAAC,sBAAsB,CAAkB;IAChD,OAAO,CAAC,iBAAiB,CAAa;gBAGpB,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,wBAAwB,CAAC;IAG/E,OAAO,IAAI,IAAI;IAItB;;OAEG;IACH,IAAW,KAAK,IAAI,MAAM,CAOzB;IAED,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,qBAAqB;IAO7B,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAuBlC;IAEF,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAUhC;CACF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
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.BranchCommitCounter = void 0;
|
|
8
|
+
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
9
|
+
/**
|
|
10
|
+
* A utility class that counts the number of commits in a branch and keeps the count updated as the branch changes.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* This class has no inside knowledge of what the commits represent.
|
|
14
|
+
* It is therefore oblivious to any scheme where some root commit is considered "special" and should not be counted.
|
|
15
|
+
*/
|
|
16
|
+
class BranchCommitCounter {
|
|
17
|
+
constructor(branch) {
|
|
18
|
+
this.branch = branch;
|
|
19
|
+
this.commitCountInitialized = false;
|
|
20
|
+
this.cachedCommitCount = 0;
|
|
21
|
+
this.onAfterBranchChange = (event) => {
|
|
22
|
+
if (!this.commitCountInitialized) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
switch (event.type) {
|
|
26
|
+
case "append": {
|
|
27
|
+
this.cachedCommitCount += event.newCommits.length;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
case "remove": {
|
|
31
|
+
this.cachedCommitCount -= event.removedCommits.length;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
case "rebase": {
|
|
35
|
+
this.cachedCommitCount += event.newCommits.length;
|
|
36
|
+
this.cachedCommitCount -= event.removedCommits.length;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
default: {
|
|
40
|
+
(0, internal_1.unreachableCase)(event);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
this.onAncestryTrimmed = (trimmedRevisions) => {
|
|
45
|
+
if (!this.commitCountInitialized) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
(0, internal_1.assert)(this.cachedCommitCount >= trimmedRevisions.length, 0xd35 /* Trimmed more commits than exist in the branch */);
|
|
49
|
+
this.cachedCommitCount = this.cachedCommitCount - trimmedRevisions.length;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
dispose() {
|
|
53
|
+
this.unsubscribeFromBranch();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Gets the number of commits in the branch.
|
|
57
|
+
*/
|
|
58
|
+
get count() {
|
|
59
|
+
if (!this.commitCountInitialized) {
|
|
60
|
+
this.cachedCommitCount = this.branch.getCommitCount();
|
|
61
|
+
this.subscribeToBranch();
|
|
62
|
+
this.commitCountInitialized = true;
|
|
63
|
+
}
|
|
64
|
+
return this.cachedCommitCount;
|
|
65
|
+
}
|
|
66
|
+
subscribeToBranch() {
|
|
67
|
+
this.unsubscribeFromBranch();
|
|
68
|
+
this.unsubscribeAfterChange = this.branch.events.on("afterChange", this.onAfterBranchChange);
|
|
69
|
+
this.unsubscribeAncestryTrimmed = this.branch.events.on("ancestryTrimmed", this.onAncestryTrimmed);
|
|
70
|
+
}
|
|
71
|
+
unsubscribeFromBranch() {
|
|
72
|
+
this.unsubscribeAfterChange?.();
|
|
73
|
+
this.unsubscribeAfterChange = undefined;
|
|
74
|
+
this.unsubscribeAncestryTrimmed?.();
|
|
75
|
+
this.unsubscribeAncestryTrimmed = undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.BranchCommitCounter = BranchCommitCounter;
|
|
79
|
+
//# sourceMappingURL=branchCommitCounter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branchCommitCounter.js","sourceRoot":"","sources":["../../src/shared-tree-core/branchCommitCounter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA8E;AAK9E;;;;;;GAMG;AACH,MAAa,mBAAmB;IAU/B,YACkB,MAAoE;QAApE,WAAM,GAAN,MAAM,CAA8D;QAJ9E,2BAAsB,GAAY,KAAK,CAAC;QACxC,sBAAiB,GAAW,CAAC,CAAC;QAyCrB,wBAAmB,GAAG,CAAC,KAAsC,EAAQ,EAAE;YACvF,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC;gBAClC,OAAO;YACR,CAAC;YAED,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;gBACpB,KAAK,QAAQ,CAAC,CAAC,CAAC;oBACf,IAAI,CAAC,iBAAiB,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC;oBAClD,OAAO;gBACR,CAAC;gBACD,KAAK,QAAQ,CAAC,CAAC,CAAC;oBACf,IAAI,CAAC,iBAAiB,IAAI,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC;oBACtD,OAAO;gBACR,CAAC;gBACD,KAAK,QAAQ,CAAC,CAAC,CAAC;oBACf,IAAI,CAAC,iBAAiB,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC;oBAClD,IAAI,CAAC,iBAAiB,IAAI,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC;oBACtD,OAAO;gBACR,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACT,IAAA,0BAAe,EAAC,KAAK,CAAC,CAAC;gBACxB,CAAC;YACF,CAAC;QACF,CAAC,CA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AC;CAsCD;AArFD,kDAqFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\n\nimport type { ChangeFamilyEditor, RevisionTag } from \"../core/index.js\";\nimport type { SharedTreeBranch, SharedTreeBranchChange } from \"./branch.js\";\n\n/**\n * A utility class that counts the number of commits in a branch and keeps the count updated as the branch changes.\n *\n * @remarks\n * This class has no inside knowledge of what the commits represent.\n * It is therefore oblivious to any scheme where some root commit is considered \"special\" and should not be counted.\n */\nexport class BranchCommitCounter<\n\tTEditor extends ChangeFamilyEditor,\n\tTChange,\n\tTChangeProcessingContext,\n> {\n\tprivate unsubscribeAfterChange?: () => void;\n\tprivate unsubscribeAncestryTrimmed?: () => void;\n\tprivate commitCountInitialized: boolean = false;\n\tprivate cachedCommitCount: number = 0;\n\n\tpublic constructor(\n\t\tprivate readonly branch: SharedTreeBranch<TEditor, TChange, TChangeProcessingContext>,\n\t) {}\n\n\tpublic dispose(): void {\n\t\tthis.unsubscribeFromBranch();\n\t}\n\n\t/**\n\t * Gets the number of commits in the branch.\n\t */\n\tpublic get count(): number {\n\t\tif (!this.commitCountInitialized) {\n\t\t\tthis.cachedCommitCount = this.branch.getCommitCount();\n\t\t\tthis.subscribeToBranch();\n\t\t\tthis.commitCountInitialized = true;\n\t\t}\n\t\treturn this.cachedCommitCount;\n\t}\n\n\tprivate subscribeToBranch(): void {\n\t\tthis.unsubscribeFromBranch();\n\t\tthis.unsubscribeAfterChange = this.branch.events.on(\n\t\t\t\"afterChange\",\n\t\t\tthis.onAfterBranchChange,\n\t\t);\n\t\tthis.unsubscribeAncestryTrimmed = this.branch.events.on(\n\t\t\t\"ancestryTrimmed\",\n\t\t\tthis.onAncestryTrimmed,\n\t\t);\n\t}\n\n\tprivate unsubscribeFromBranch(): void {\n\t\tthis.unsubscribeAfterChange?.();\n\t\tthis.unsubscribeAfterChange = undefined;\n\t\tthis.unsubscribeAncestryTrimmed?.();\n\t\tthis.unsubscribeAncestryTrimmed = undefined;\n\t}\n\n\tprivate readonly onAfterBranchChange = (event: SharedTreeBranchChange<TChange>): void => {\n\t\tif (!this.commitCountInitialized) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch (event.type) {\n\t\t\tcase \"append\": {\n\t\t\t\tthis.cachedCommitCount += event.newCommits.length;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"remove\": {\n\t\t\t\tthis.cachedCommitCount -= event.removedCommits.length;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"rebase\": {\n\t\t\t\tthis.cachedCommitCount += event.newCommits.length;\n\t\t\t\tthis.cachedCommitCount -= event.removedCommits.length;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tunreachableCase(event);\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate readonly onAncestryTrimmed = (trimmedRevisions: RevisionTag[]): void => {\n\t\tif (!this.commitCountInitialized) {\n\t\t\treturn;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.cachedCommitCount >= trimmedRevisions.length,\n\t\t\t0xd35 /* Trimmed more commits than exist in the branch */,\n\t\t);\n\t\tthis.cachedCommitCount = this.cachedCommitCount - trimmedRevisions.length;\n\t};\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { CustomMetadataTree } from "../core/index.js";
|
|
6
|
+
import type { EncodedCustomMetadataTree } from "./customMetadataFormat.js";
|
|
7
|
+
export declare function encodeCustomMetadataTree(tree: CustomMetadataTree): EncodedCustomMetadataTree;
|
|
8
|
+
export declare function decodeCustomMetadataTree(encoded: EncodedCustomMetadataTree | undefined): CustomMetadataTree | undefined;
|
|
9
|
+
//# sourceMappingURL=customMetadataCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customMetadataCodec.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/customMetadataCodec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAE3E,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,kBAAkB,GAAG,yBAAyB,CAS5F;AAED,wBAAgB,wBAAwB,CACvC,OAAO,EAAE,yBAAyB,GAAG,SAAS,GAC5C,kBAAkB,GAAG,SAAS,CAOhC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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.decodeCustomMetadataTree = exports.encodeCustomMetadataTree = void 0;
|
|
8
|
+
function encodeCustomMetadataTree(tree) {
|
|
9
|
+
const encoded = {};
|
|
10
|
+
if (tree.metadata !== undefined) {
|
|
11
|
+
encoded.m = tree.metadata;
|
|
12
|
+
}
|
|
13
|
+
if (tree.children.length > 0) {
|
|
14
|
+
encoded.c = tree.children.map(encodeCustomMetadataTree);
|
|
15
|
+
}
|
|
16
|
+
return encoded;
|
|
17
|
+
}
|
|
18
|
+
exports.encodeCustomMetadataTree = encodeCustomMetadataTree;
|
|
19
|
+
function decodeCustomMetadataTree(encoded) {
|
|
20
|
+
if (encoded === undefined) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const decoded = decodeNode(encoded);
|
|
24
|
+
// A tree in which no node supplied metadata carries no information.
|
|
25
|
+
return hasMetadata(decoded) ? decoded : undefined;
|
|
26
|
+
}
|
|
27
|
+
exports.decodeCustomMetadataTree = decodeCustomMetadataTree;
|
|
28
|
+
function decodeNode(encoded) {
|
|
29
|
+
return {
|
|
30
|
+
metadata: encoded.m,
|
|
31
|
+
children: encoded.c?.map(decodeNode) ?? [],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function hasMetadata(node) {
|
|
35
|
+
return node.metadata !== undefined || node.children.some(hasMetadata);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=customMetadataCodec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customMetadataCodec.js","sourceRoot":"","sources":["../../src/shared-tree-core/customMetadataCodec.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,SAAgB,wBAAwB,CAAC,IAAwB;IAChE,MAAM,OAAO,GAAuC,EAAE,CAAC;IACvD,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;IAC3B,CAAC;IACD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AATD,4DASC;AAED,SAAgB,wBAAwB,CACvC,OAA8C;IAE9C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,oEAAoE;IACpE,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC;AATD,4DASC;AAED,SAAS,UAAU,CAAC,OAAkC;IACrD,OAAO;QACN,QAAQ,EAAE,OAAO,CAAC,CAAC;QACnB,QAAQ,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE;KAC1C,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAwB;IAC5C,OAAO,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACvE,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { CustomMetadataTree } from \"../core/index.js\";\nimport type { Mutable } from \"../util/index.js\";\n\nimport type { EncodedCustomMetadataTree } from \"./customMetadataFormat.js\";\n\nexport function encodeCustomMetadataTree(tree: CustomMetadataTree): EncodedCustomMetadataTree {\n\tconst encoded: Mutable<EncodedCustomMetadataTree> = {};\n\tif (tree.metadata !== undefined) {\n\t\tencoded.m = tree.metadata;\n\t}\n\tif (tree.children.length > 0) {\n\t\tencoded.c = tree.children.map(encodeCustomMetadataTree);\n\t}\n\treturn encoded;\n}\n\nexport function decodeCustomMetadataTree(\n\tencoded: EncodedCustomMetadataTree | undefined,\n): CustomMetadataTree | undefined {\n\tif (encoded === undefined) {\n\t\treturn undefined;\n\t}\n\tconst decoded = decodeNode(encoded);\n\t// A tree in which no node supplied metadata carries no information.\n\treturn hasMetadata(decoded) ? decoded : undefined;\n}\n\nfunction decodeNode(encoded: EncodedCustomMetadataTree): CustomMetadataTree {\n\treturn {\n\t\tmetadata: encoded.m,\n\t\tchildren: encoded.c?.map(decodeNode) ?? [],\n\t};\n}\n\nfunction hasMetadata(node: CustomMetadataTree): boolean {\n\treturn node.metadata !== undefined || node.children.some(hasMetadata);\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import * as Type from "@sinclair/typebox";
|
|
6
|
+
import { type JsonCompatibleReadOnlyObject } from "../util/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* The persisted form of a {@link CustomMetadataTree}.
|
|
9
|
+
* @remarks
|
|
10
|
+
* The property names (`m` for metadata, `c` for children) are abbreviated and both are optional because
|
|
11
|
+
* this rides on every annotated op and occupies summary space for as long as its commit survives.
|
|
12
|
+
*/
|
|
13
|
+
export type EncodedCustomMetadataTree = {
|
|
14
|
+
readonly m?: JsonCompatibleReadOnlyObject;
|
|
15
|
+
readonly c?: readonly EncodedCustomMetadataTree[];
|
|
16
|
+
};
|
|
17
|
+
export declare const EncodedCustomMetadataTree: Type.TSchema;
|
|
18
|
+
//# sourceMappingURL=customMetadataFormat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customMetadataFormat.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/customMetadataFormat.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EACN,KAAK,4BAA4B,EAEjC,MAAM,kBAAkB,CAAC;AAE1B;;;;;GAKG;AAIH,MAAM,MAAM,yBAAyB,GAAG;IACvC,QAAQ,CAAC,CAAC,CAAC,EAAE,4BAA4B,CAAC;IAC1C,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,yBAAyB,EAAE,CAAC;CAClD,CAAC;AAEF,eAAO,MAAM,yBAAyB,cAYV,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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.EncodedCustomMetadataTree = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const Type = tslib_1.__importStar(require("@sinclair/typebox"));
|
|
10
|
+
const index_js_1 = require("../util/index.js");
|
|
11
|
+
exports.EncodedCustomMetadataTree = Type.Recursive((Self) => Type.Object({
|
|
12
|
+
m: Type.Optional(Type.Unsafe(Type.Record(Type.String(), index_js_1.JsonCompatibleReadOnlySchema))),
|
|
13
|
+
c: Type.Optional(Type.Array(Self)),
|
|
14
|
+
}, { additionalProperties: false }));
|
|
15
|
+
//# sourceMappingURL=customMetadataFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customMetadataFormat.js","sourceRoot":"","sources":["../../src/shared-tree-core/customMetadataFormat.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;AAEH,gEAA0C;AAE1C,+CAG0B;AAgBb,QAAA,yBAAyB,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAChE,IAAI,CAAC,MAAM,CACV;IACC,CAAC,EAAE,IAAI,CAAC,QAAQ,CACf,IAAI,CAAC,MAAM,CACV,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,uCAA4B,CAAC,CACxD,CACD;IACD,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;CAClC,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAC0B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as Type from \"@sinclair/typebox\";\n\nimport {\n\ttype JsonCompatibleReadOnlyObject,\n\tJsonCompatibleReadOnlySchema,\n} from \"../util/index.js\";\n\n/**\n * The persisted form of a {@link CustomMetadataTree}.\n * @remarks\n * The property names (`m` for metadata, `c` for children) are abbreviated and both are optional because\n * this rides on every annotated op and occupies summary space for as long as its commit survives.\n */\n// Declared as a type alias rather than an interface so that it satisfies the index signature of\n// `JsonCompatibleReadOnlyObject`, which the encoded message and summary types are constrained to.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport type EncodedCustomMetadataTree = {\n\treadonly m?: JsonCompatibleReadOnlyObject;\n\treadonly c?: readonly EncodedCustomMetadataTree[];\n};\n\nexport const EncodedCustomMetadataTree = Type.Recursive((Self) =>\n\tType.Object(\n\t\t{\n\t\t\tm: Type.Optional(\n\t\t\t\tType.Unsafe<JsonCompatibleReadOnlyObject>(\n\t\t\t\t\tType.Record(Type.String(), JsonCompatibleReadOnlySchema),\n\t\t\t\t),\n\t\t\t),\n\t\t\tc: Type.Optional(Type.Array(Self)),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n) as unknown as Type.TSchema;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editManager.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/editManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAGN,KAAK,kBAAkB,EACvB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,kBAAkB,
|
|
1
|
+
{"version":3,"file":"editManager.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/editManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAGN,KAAK,kBAAkB,EACvB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,kBAAkB,EAEvB,KAAK,WAAW,EAChB,KAAK,WAAW,EAMhB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACN,gBAAgB,EAGhB,KAAK,QAAQ,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAEX,SAAS,EAET,eAAe,EACf,oBAAoB,EACpB,MAAM,+BAA+B,CAAC;AASvC,eAAO,MAAM,6BAA6B,EAAE,SAA0C,CAAC;AAkBvF;;;GAGG;AAEH,qBAAa,WAAW,CACvB,OAAO,S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,YAAY,EAAE,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;CAS7E;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,UAAU;IACtC,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAC,CAAC;CAC/E;AAED,MAAM,WAAW,uBAAuB,CAAC,UAAU;IAClD,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;IACvD,QAAQ,CAAC,iBAAiB,EAAE,WAAW,CAAC,SAAS,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC;CACrF"}
|
|
@@ -68,6 +68,7 @@ class EditManager {
|
|
|
68
68
|
this.trunkBase = {
|
|
69
69
|
revision: rootRevision,
|
|
70
70
|
change: changeFamily.rebaser.compose([]),
|
|
71
|
+
customMetadata: undefined,
|
|
71
72
|
};
|
|
72
73
|
if (logger !== undefined) {
|
|
73
74
|
this.telemetryEventBatcher = new internal_2.TelemetryEventBatcher({
|
|
@@ -216,6 +217,10 @@ class EditManager {
|
|
|
216
217
|
// The minimum sequence number informs us that all peer branches are at least caught up to the tail commit,
|
|
217
218
|
// so rebase them accordingly. This is necessary to prevent peer branches from referencing any evicted commits.
|
|
218
219
|
mainBranch.trimHistory(latestEvicted, sequenceId);
|
|
220
|
+
// Custom metadata shares the lifetime of its commit, so it must be dropped when the commit is
|
|
221
|
+
// trimmed. The new trunk base stays reachable as the sentinel for the remaining history, so its
|
|
222
|
+
// metadata is cleared rather than trapped; fully evicted commits get the throwing trap below.
|
|
223
|
+
newTrunkBase.customMetadata = undefined;
|
|
219
224
|
// Only the last trimmed commit, which is the new trunk base, should remain accessible.
|
|
220
225
|
for (const commit of trimmedCommits.slice(0, -1)) {
|
|
221
226
|
Reflect.defineProperty(commit, "change", {
|
|
@@ -227,6 +232,9 @@ class EditManager {
|
|
|
227
232
|
Reflect.defineProperty(commit, "parent", {
|
|
228
233
|
get: () => (0, internal_1.fail)(0xa60 /* Should not access 'parent' property of an evicted commit */),
|
|
229
234
|
});
|
|
235
|
+
Reflect.defineProperty(commit, "customMetadata", {
|
|
236
|
+
get: () => (0, internal_1.fail)(0xd36 /* Should not access 'customMetadata' property of an evicted commit */),
|
|
237
|
+
});
|
|
230
238
|
}
|
|
231
239
|
// Dropping the parent field removes (transitively) all references to the evicted commits so they can be garbage collected.
|
|
232
240
|
delete newTrunkBase.parent;
|
|
@@ -244,11 +252,13 @@ class EditManager {
|
|
|
244
252
|
getSummaryData() {
|
|
245
253
|
// Trimming the trunk before serializing ensures that the trunk data in the summary is as minimal as possible.
|
|
246
254
|
this.trimHistory();
|
|
255
|
+
const mainBranch = this.getSharedBranch("main");
|
|
247
256
|
const minSeqNumberToSummarize = {
|
|
248
257
|
sequenceNumber: (0, index_js_2.brand)(this.minimumSequenceNumber + 1),
|
|
249
258
|
};
|
|
250
|
-
let minBaseSeqId =
|
|
251
|
-
|
|
259
|
+
let minBaseSeqId = this.retainHistory
|
|
260
|
+
? (mainBranch.sequenceIdToCommit.minKey() ?? minimumPossibleSequenceId)
|
|
261
|
+
: minSeqNumberToSummarize;
|
|
252
262
|
const branches = new Map();
|
|
253
263
|
for (const [branchId, branch] of this.sharedBranches) {
|
|
254
264
|
if (branchId !== "main") {
|
|
@@ -498,7 +508,7 @@ class SharedBranch {
|
|
|
498
508
|
else {
|
|
499
509
|
// Otherwise, push the changes to the peer local branch and merge the branch into the trunk.
|
|
500
510
|
for (const newCommit of newCommits) {
|
|
501
|
-
peerLocalBranch.apply((0, index_js_1.tagChange)(newCommit.change, newCommit.revision));
|
|
511
|
+
peerLocalBranch.apply((0, index_js_1.tagChange)(newCommit.change, newCommit.revision), index_js_1.CommitKind.Default, newCommit.customMetadata);
|
|
502
512
|
}
|
|
503
513
|
const result = this.trunk.merge(peerLocalBranch);
|
|
504
514
|
if (result !== undefined) {
|
|
@@ -675,6 +685,7 @@ class SharedBranch {
|
|
|
675
685
|
revision: c.revision,
|
|
676
686
|
sequenceNumber: metadata.sequenceId.sequenceNumber,
|
|
677
687
|
sessionId: metadata.sessionId,
|
|
688
|
+
customMetadata: c.customMetadata,
|
|
678
689
|
};
|
|
679
690
|
if (metadata.sequenceId.indexInBatch !== undefined) {
|
|
680
691
|
commit.indexInBatch = metadata.sequenceId.indexInBatch;
|
|
@@ -695,6 +706,7 @@ class SharedBranch {
|
|
|
695
706
|
change: c.change,
|
|
696
707
|
revision: c.revision,
|
|
697
708
|
sessionId,
|
|
709
|
+
customMetadata: c.customMetadata,
|
|
698
710
|
};
|
|
699
711
|
return commit;
|
|
700
712
|
}),
|