@fluidframework/tree 2.52.0 → 2.53.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 +14 -2
- package/CHANGELOG.md +125 -0
- package/api-report/tree.alpha.api.md +48 -41
- package/dist/alpha.d.ts +2 -1
- package/dist/core/tree/visitDelta.d.ts +1 -1
- package/dist/core/tree/visitDelta.d.ts.map +1 -1
- package/dist/core/tree/visitDelta.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/index.d.ts +1 -0
- package/dist/feature-libraries/chunked-forest/index.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/index.js +3 -1
- package/dist/feature-libraries/chunked-forest/index.js.map +1 -1
- package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +2 -4
- package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
- package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
- package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/defaultFieldKinds.js +1 -0
- package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
- package/dist/feature-libraries/default-schema/noChangeCodecs.d.ts +1 -1
- package/dist/feature-libraries/default-schema/noChangeCodecs.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/noChangeCodecs.js.map +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +4 -0
- package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.js +5 -5
- package/dist/feature-libraries/forest-summary/forestSummarizer.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 +4 -2
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +7 -0
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.js +1 -0
- package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/genericFieldKind.js +1 -0
- package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +1 -0
- package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +9 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js +49 -20
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
- package/dist/feature-libraries/optional-field/optionalField.js +3 -0
- package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldChangeRebaser.d.ts +1 -0
- package/dist/feature-libraries/sequence-field/sequenceFieldChangeRebaser.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldChangeRebaser.js +4 -0
- package/dist/feature-libraries/sequence-field/sequenceFieldChangeRebaser.js.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.js.map +1 -1
- package/dist/feature-libraries/sequence-field/types.d.ts +1 -1
- package/dist/feature-libraries/sequence-field/types.d.ts.map +1 -1
- package/dist/feature-libraries/sequence-field/types.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/jsonDomainSchema.d.ts +5 -3
- package/dist/jsonDomainSchema.d.ts.map +1 -1
- package/dist/jsonDomainSchema.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/independentView.d.ts.map +1 -1
- package/dist/shared-tree/independentView.js +1 -1
- package/dist/shared-tree/independentView.js.map +1 -1
- package/dist/shared-tree/index.d.ts +0 -1
- package/dist/shared-tree/index.d.ts.map +1 -1
- package/dist/shared-tree/index.js.map +1 -1
- package/dist/shared-tree/schematizeTree.d.ts +23 -60
- package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
- package/dist/shared-tree/schematizeTree.js +59 -151
- package/dist/shared-tree/schematizeTree.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +11 -11
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
- package/dist/shared-tree/treeAlpha.js +9 -3
- package/dist/shared-tree/treeAlpha.js.map +1 -1
- package/dist/shared-tree-core/defaultResubmitMachine.d.ts +2 -1
- package/dist/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
- package/dist/shared-tree-core/defaultResubmitMachine.js.map +1 -1
- package/dist/simple-tree/api/configuration.d.ts +3 -0
- package/dist/simple-tree/api/configuration.d.ts.map +1 -1
- package/dist/simple-tree/api/configuration.js +5 -1
- package/dist/simple-tree/api/configuration.js.map +1 -1
- package/dist/simple-tree/api/create.d.ts +4 -4
- package/dist/simple-tree/api/create.d.ts.map +1 -1
- package/dist/simple-tree/api/create.js +3 -6
- package/dist/simple-tree/api/create.js.map +1 -1
- package/dist/simple-tree/api/discrepancies.d.ts +5 -9
- package/dist/simple-tree/api/discrepancies.d.ts.map +1 -1
- package/dist/simple-tree/api/discrepancies.js +11 -10
- package/dist/simple-tree/api/discrepancies.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +3 -2
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +3 -2
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaCompatibilityTester.js +3 -4
- package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +9 -155
- package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactory.js +4 -47
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +157 -16
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.js +33 -11
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryRecursive.d.ts +1 -3
- package/dist/simple-tree/api/schemaFactoryRecursive.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryRecursive.js +1 -7
- package/dist/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
- package/dist/simple-tree/api/schemaStatics.d.ts +158 -0
- package/dist/simple-tree/api/schemaStatics.d.ts.map +1 -0
- package/dist/simple-tree/api/schemaStatics.js +59 -0
- package/dist/simple-tree/api/schemaStatics.js.map +1 -0
- package/dist/simple-tree/api/storedSchema.d.ts +5 -3
- package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/storedSchema.js +4 -2
- package/dist/simple-tree/api/storedSchema.js.map +1 -1
- package/dist/simple-tree/api/treeBeta.d.ts.map +1 -1
- package/dist/simple-tree/api/treeBeta.js +12 -6
- package/dist/simple-tree/api/treeBeta.js.map +1 -1
- package/dist/simple-tree/core/allowedTypes.d.ts +46 -30
- package/dist/simple-tree/core/allowedTypes.d.ts.map +1 -1
- package/dist/simple-tree/core/allowedTypes.js +20 -12
- package/dist/simple-tree/core/allowedTypes.js.map +1 -1
- package/dist/simple-tree/core/index.d.ts +5 -3
- package/dist/simple-tree/core/index.d.ts.map +1 -1
- package/dist/simple-tree/core/index.js +6 -1
- package/dist/simple-tree/core/index.js.map +1 -1
- package/dist/simple-tree/core/simpleNodeSchemaBase.d.ts +25 -0
- package/dist/simple-tree/core/simpleNodeSchemaBase.d.ts.map +1 -0
- package/dist/simple-tree/core/simpleNodeSchemaBase.js +7 -0
- package/dist/simple-tree/core/simpleNodeSchemaBase.js.map +1 -0
- package/dist/simple-tree/core/toStored.d.ts +32 -0
- package/dist/simple-tree/core/toStored.d.ts.map +1 -0
- package/dist/simple-tree/core/toStored.js +37 -0
- package/dist/simple-tree/core/toStored.js.map +1 -0
- package/dist/simple-tree/core/treeNode.d.ts +0 -3
- package/dist/simple-tree/core/treeNode.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNode.js +3 -3
- package/dist/simple-tree/core/treeNode.js.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.d.ts +7 -2
- package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/dist/simple-tree/core/treeNodeValid.d.ts +6 -1
- package/dist/simple-tree/core/treeNodeValid.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeValid.js +11 -6
- package/dist/simple-tree/core/treeNodeValid.js.map +1 -1
- package/dist/simple-tree/core/walkSchema.d.ts +19 -5
- package/dist/simple-tree/core/walkSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/walkSchema.js +4 -2
- package/dist/simple-tree/core/walkSchema.js.map +1 -1
- package/dist/simple-tree/createContext.d.ts.map +1 -1
- package/dist/simple-tree/createContext.js +1 -1
- package/dist/simple-tree/createContext.js.map +1 -1
- package/dist/simple-tree/fieldSchema.d.ts +2 -1
- package/dist/simple-tree/fieldSchema.d.ts.map +1 -1
- package/dist/simple-tree/fieldSchema.js +1 -1
- package/dist/simple-tree/fieldSchema.js.map +1 -1
- package/dist/simple-tree/index.d.ts +4 -4
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +9 -2
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/leafNodeSchema.js +1 -0
- package/dist/simple-tree/leafNodeSchema.js.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.js +18 -4
- package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNode.js +9 -2
- package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts +2 -2
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.js +37 -26
- package/dist/simple-tree/node-kinds/object/objectNode.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 +9 -2
- package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
- package/dist/simple-tree/prepareForInsertion.d.ts +5 -5
- package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
- package/dist/simple-tree/prepareForInsertion.js +10 -10
- package/dist/simple-tree/prepareForInsertion.js.map +1 -1
- package/dist/simple-tree/simpleSchema.d.ts +6 -21
- 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 +35 -11
- package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/dist/simple-tree/toStoredSchema.js +68 -33
- package/dist/simple-tree/toStoredSchema.js.map +1 -1
- package/dist/tableSchema.d.ts +25 -32
- package/dist/tableSchema.d.ts.map +1 -1
- package/dist/tableSchema.js +10 -24
- package/dist/tableSchema.js.map +1 -1
- package/docs/.attachments/cell-ordering/C-knows-of-ABC.png +0 -0
- package/docs/.attachments/cell-ordering/C-knows-of-C.png +0 -0
- package/docs/.attachments/cell-ordering/XvsA.png +0 -0
- package/docs/.attachments/cell-ordering/compose-a-b.png +0 -0
- package/docs/.attachments/cell-ordering/compose-a-ref-p1-b-ref-p2.png +0 -0
- package/docs/.attachments/cell-ordering/compose-b-no-ref-to-ca.png +0 -0
- package/docs/.attachments/cell-ordering/rebase-ab-over-x.png +0 -0
- package/docs/.attachments/cell-ordering/rebase-b-over-x.png +0 -0
- package/docs/.attachments/cell-ordering/rebase-b2-over-x.png +0 -0
- package/docs/.attachments/cell-ordering/rebase-b2.png +0 -0
- package/docs/.attachments/cell-ordering/rebase-to-abprime.png +0 -0
- package/docs/.attachments/cell-ordering/rebase-to-bprime.png +0 -0
- package/docs/main/cell-ordering.md +638 -0
- package/lib/alpha.d.ts +2 -1
- package/lib/core/tree/visitDelta.d.ts +1 -1
- package/lib/core/tree/visitDelta.d.ts.map +1 -1
- package/lib/core/tree/visitDelta.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/index.d.ts +1 -0
- package/lib/feature-libraries/chunked-forest/index.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/index.js +1 -0
- package/lib/feature-libraries/chunked-forest/index.js.map +1 -1
- package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +2 -4
- package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/defaultEditBuilder.js +4 -1
- package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
- package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/defaultFieldKinds.js +1 -0
- package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
- package/lib/feature-libraries/default-schema/noChangeCodecs.d.ts +1 -1
- package/lib/feature-libraries/default-schema/noChangeCodecs.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/noChangeCodecs.js.map +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +4 -0
- package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.js +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.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/fieldChangeHandler.d.ts +7 -0
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.js +1 -0
- package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/genericFieldKind.js +1 -0
- package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +1 -0
- package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +9 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js +50 -21
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
- package/lib/feature-libraries/optional-field/optionalField.js +3 -0
- package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldChangeRebaser.d.ts +1 -0
- package/lib/feature-libraries/sequence-field/sequenceFieldChangeRebaser.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldChangeRebaser.js +4 -0
- package/lib/feature-libraries/sequence-field/sequenceFieldChangeRebaser.js.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.js.map +1 -1
- package/lib/feature-libraries/sequence-field/types.d.ts +1 -1
- package/lib/feature-libraries/sequence-field/types.d.ts.map +1 -1
- package/lib/feature-libraries/sequence-field/types.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/jsonDomainSchema.d.ts +5 -3
- package/lib/jsonDomainSchema.d.ts.map +1 -1
- package/lib/jsonDomainSchema.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/independentView.d.ts.map +1 -1
- package/lib/shared-tree/independentView.js +2 -2
- package/lib/shared-tree/independentView.js.map +1 -1
- package/lib/shared-tree/index.d.ts +0 -1
- package/lib/shared-tree/index.d.ts.map +1 -1
- package/lib/shared-tree/index.js.map +1 -1
- package/lib/shared-tree/schematizeTree.d.ts +23 -60
- package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
- package/lib/shared-tree/schematizeTree.js +60 -150
- package/lib/shared-tree/schematizeTree.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +14 -14
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
- package/lib/shared-tree/treeAlpha.js +10 -4
- package/lib/shared-tree/treeAlpha.js.map +1 -1
- package/lib/shared-tree-core/defaultResubmitMachine.d.ts +2 -1
- package/lib/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
- package/lib/shared-tree-core/defaultResubmitMachine.js.map +1 -1
- package/lib/simple-tree/api/configuration.d.ts +3 -0
- package/lib/simple-tree/api/configuration.d.ts.map +1 -1
- package/lib/simple-tree/api/configuration.js +6 -2
- package/lib/simple-tree/api/configuration.js.map +1 -1
- package/lib/simple-tree/api/create.d.ts +4 -4
- package/lib/simple-tree/api/create.d.ts.map +1 -1
- package/lib/simple-tree/api/create.js +3 -6
- package/lib/simple-tree/api/create.js.map +1 -1
- package/lib/simple-tree/api/discrepancies.d.ts +5 -9
- package/lib/simple-tree/api/discrepancies.d.ts.map +1 -1
- package/lib/simple-tree/api/discrepancies.js +11 -10
- package/lib/simple-tree/api/discrepancies.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +3 -2
- 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/schemaCompatibilityTester.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaCompatibilityTester.js +4 -5
- package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +9 -155
- package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactory.js +2 -45
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +157 -16
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.js +23 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryRecursive.d.ts +1 -3
- package/lib/simple-tree/api/schemaFactoryRecursive.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryRecursive.js +0 -5
- package/lib/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
- package/lib/simple-tree/api/schemaStatics.d.ts +158 -0
- package/lib/simple-tree/api/schemaStatics.d.ts.map +1 -0
- package/lib/simple-tree/api/schemaStatics.js +56 -0
- package/lib/simple-tree/api/schemaStatics.js.map +1 -0
- package/lib/simple-tree/api/storedSchema.d.ts +5 -3
- package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/storedSchema.js +6 -4
- package/lib/simple-tree/api/storedSchema.js.map +1 -1
- package/lib/simple-tree/api/treeBeta.d.ts.map +1 -1
- package/lib/simple-tree/api/treeBeta.js +8 -2
- package/lib/simple-tree/api/treeBeta.js.map +1 -1
- package/lib/simple-tree/core/allowedTypes.d.ts +46 -30
- package/lib/simple-tree/core/allowedTypes.d.ts.map +1 -1
- package/lib/simple-tree/core/allowedTypes.js +23 -12
- package/lib/simple-tree/core/allowedTypes.js.map +1 -1
- package/lib/simple-tree/core/index.d.ts +5 -3
- package/lib/simple-tree/core/index.d.ts.map +1 -1
- package/lib/simple-tree/core/index.js +3 -2
- package/lib/simple-tree/core/index.js.map +1 -1
- package/lib/simple-tree/core/simpleNodeSchemaBase.d.ts +25 -0
- package/lib/simple-tree/core/simpleNodeSchemaBase.d.ts.map +1 -0
- package/lib/simple-tree/core/simpleNodeSchemaBase.js +6 -0
- package/lib/simple-tree/core/simpleNodeSchemaBase.js.map +1 -0
- package/lib/simple-tree/core/toStored.d.ts +32 -0
- package/lib/simple-tree/core/toStored.d.ts.map +1 -0
- package/lib/simple-tree/core/toStored.js +32 -0
- package/lib/simple-tree/core/toStored.js.map +1 -0
- package/lib/simple-tree/core/treeNode.d.ts +0 -3
- package/lib/simple-tree/core/treeNode.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNode.js +3 -3
- package/lib/simple-tree/core/treeNode.js.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.d.ts +7 -2
- package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/lib/simple-tree/core/treeNodeValid.d.ts +6 -1
- package/lib/simple-tree/core/treeNodeValid.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeValid.js +9 -5
- package/lib/simple-tree/core/treeNodeValid.js.map +1 -1
- package/lib/simple-tree/core/walkSchema.d.ts +19 -5
- package/lib/simple-tree/core/walkSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/walkSchema.js +4 -2
- package/lib/simple-tree/core/walkSchema.js.map +1 -1
- package/lib/simple-tree/createContext.d.ts.map +1 -1
- package/lib/simple-tree/createContext.js +2 -2
- package/lib/simple-tree/createContext.js.map +1 -1
- package/lib/simple-tree/fieldSchema.d.ts +2 -1
- package/lib/simple-tree/fieldSchema.d.ts.map +1 -1
- package/lib/simple-tree/fieldSchema.js +1 -1
- package/lib/simple-tree/fieldSchema.js.map +1 -1
- package/lib/simple-tree/index.d.ts +4 -4
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +2 -2
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/leafNodeSchema.js +2 -1
- package/lib/simple-tree/leafNodeSchema.js.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.js +21 -7
- package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNode.js +12 -5
- package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts +2 -2
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.js +16 -5
- package/lib/simple-tree/node-kinds/object/objectNode.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 +12 -5
- package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
- package/lib/simple-tree/prepareForInsertion.d.ts +5 -5
- package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
- package/lib/simple-tree/prepareForInsertion.js +10 -10
- package/lib/simple-tree/prepareForInsertion.js.map +1 -1
- package/lib/simple-tree/simpleSchema.d.ts +6 -21
- 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 +35 -11
- package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/lib/simple-tree/toStoredSchema.js +67 -34
- package/lib/simple-tree/toStoredSchema.js.map +1 -1
- package/lib/tableSchema.d.ts +25 -32
- package/lib/tableSchema.d.ts.map +1 -1
- package/lib/tableSchema.js +11 -25
- package/lib/tableSchema.js.map +1 -1
- package/package.json +21 -21
- package/src/core/tree/visitDelta.ts +3 -1
- package/src/feature-libraries/chunked-forest/index.ts +1 -0
- package/src/feature-libraries/default-schema/defaultEditBuilder.ts +12 -5
- package/src/feature-libraries/default-schema/defaultFieldKinds.ts +1 -0
- package/src/feature-libraries/default-schema/noChangeCodecs.ts +1 -1
- package/src/feature-libraries/forest-summary/forestSummarizer.ts +1 -1
- package/src/feature-libraries/index.ts +2 -0
- package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +9 -0
- package/src/feature-libraries/modular-schema/genericFieldKind.ts +1 -0
- package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +1 -0
- package/src/feature-libraries/modular-schema/modularChangeFamily.ts +61 -19
- package/src/feature-libraries/optional-field/optionalField.ts +4 -0
- package/src/feature-libraries/sequence-field/sequenceFieldChangeRebaser.ts +4 -0
- package/src/feature-libraries/sequence-field/sequenceFieldCodecV1.ts +4 -2
- package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +4 -2
- package/src/feature-libraries/sequence-field/sequenceFieldCodecV3.ts +4 -2
- package/src/feature-libraries/sequence-field/sequenceFieldCodecs.ts +1 -1
- package/src/feature-libraries/sequence-field/types.ts +1 -1
- package/src/index.ts +2 -1
- package/src/jsonDomainSchema.ts +4 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/independentView.ts +6 -2
- package/src/shared-tree/index.ts +0 -2
- package/src/shared-tree/schematizeTree.ts +83 -199
- package/src/shared-tree/schematizingTreeView.ts +26 -12
- package/src/shared-tree/treeAlpha.ts +18 -4
- package/src/shared-tree-core/defaultResubmitMachine.ts +2 -1
- package/src/simple-tree/api/configuration.ts +10 -2
- package/src/simple-tree/api/create.ts +5 -10
- package/src/simple-tree/api/discrepancies.ts +18 -17
- package/src/simple-tree/api/index.ts +2 -3
- package/src/simple-tree/api/schemaCompatibilityTester.ts +5 -9
- package/src/simple-tree/api/schemaFactory.ts +6 -250
- package/src/simple-tree/api/schemaFactoryAlpha.ts +174 -1
- package/src/simple-tree/api/schemaFactoryRecursive.ts +1 -25
- package/src/simple-tree/api/schemaStatics.ts +291 -0
- package/src/simple-tree/api/storedSchema.ts +12 -5
- package/src/simple-tree/api/treeBeta.ts +9 -2
- package/src/simple-tree/core/allowedTypes.ts +71 -42
- package/src/simple-tree/core/index.ts +9 -1
- package/src/simple-tree/core/simpleNodeSchemaBase.ts +30 -0
- package/src/simple-tree/core/toStored.ts +58 -0
- package/src/simple-tree/core/treeNode.ts +3 -3
- package/src/simple-tree/core/treeNodeSchema.ts +8 -2
- package/src/simple-tree/core/treeNodeValid.ts +14 -5
- package/src/simple-tree/core/walkSchema.ts +23 -6
- package/src/simple-tree/createContext.ts +5 -2
- package/src/simple-tree/fieldSchema.ts +4 -2
- package/src/simple-tree/index.ts +15 -6
- package/src/simple-tree/leafNodeSchema.ts +2 -1
- package/src/simple-tree/node-kinds/array/arrayNode.ts +58 -37
- package/src/simple-tree/node-kinds/map/mapNode.ts +26 -2
- package/src/simple-tree/node-kinds/object/objectNode.ts +37 -4
- package/src/simple-tree/node-kinds/record/recordNode.ts +23 -2
- package/src/simple-tree/prepareForInsertion.ts +12 -7
- package/src/simple-tree/simpleSchema.ts +6 -26
- package/src/simple-tree/toStoredSchema.ts +107 -44
- package/src/tableSchema.ts +40 -35
|
@@ -2,171 +2,81 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { assert
|
|
6
|
-
import { rootFieldKey, schemaDataIsEmpty
|
|
7
|
-
import { FieldKinds, allowsRepoSuperset,
|
|
8
|
-
import { toStoredSchema } from "../simple-tree/index.js";
|
|
9
|
-
import { isReadonlyArray } from "../util/index.js";
|
|
10
|
-
/**
|
|
11
|
-
* Modify `storedSchema` and invoke `setInitialTree` when it's time to set the tree content.
|
|
12
|
-
*
|
|
13
|
-
* Requires `storedSchema` to be in its default/empty state.
|
|
14
|
-
*
|
|
15
|
-
* This is done in such a way that if the content (implicitly assumed to start empty)
|
|
16
|
-
* is never out of schema.
|
|
17
|
-
* This means that if the root field of the new schema requires content (like a value field),
|
|
18
|
-
* a temporary intermediate schema is used so the initial empty state is not out of schema.
|
|
19
|
-
*
|
|
20
|
-
* Since this makes multiple changes, callers may want to wrap it in a transaction.
|
|
21
|
-
*/
|
|
22
|
-
export function initializeContent(schemaRepository, newSchema, setInitialTree) {
|
|
23
|
-
assert(schemaDataIsEmpty(schemaRepository.storedSchema), 0x743 /* cannot initialize after a schema is set */);
|
|
24
|
-
const rootSchema = newSchema.rootFieldSchema;
|
|
25
|
-
const rootKind = rootSchema.kind;
|
|
26
|
-
// To keep the data in schema during the update, first define a schema that tolerates the current (empty) tree as well as the final (initial) tree.
|
|
27
|
-
let incrementalSchemaUpdate;
|
|
28
|
-
if (rootKind === FieldKinds.sequence.identifier ||
|
|
29
|
-
rootKind === FieldKinds.optional.identifier) {
|
|
30
|
-
// These kinds are known to tolerate empty, so use the schema as is:
|
|
31
|
-
incrementalSchemaUpdate = newSchema;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
assert(rootKind === FieldKinds.required.identifier, 0x5c8 /* Unexpected kind */);
|
|
35
|
-
// Replace value kind with optional kind in root field schema:
|
|
36
|
-
incrementalSchemaUpdate = {
|
|
37
|
-
nodeSchema: newSchema.nodeSchema,
|
|
38
|
-
rootFieldSchema: {
|
|
39
|
-
kind: FieldKinds.optional.identifier,
|
|
40
|
-
types: rootSchema.types,
|
|
41
|
-
persistedMetadata: rootSchema.persistedMetadata,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
assert(allowsRepoSuperset(defaultSchemaPolicy, newSchema, incrementalSchemaUpdate), 0x5c9 /* Incremental Schema during update should allow a superset of the final schema */);
|
|
46
|
-
// Update to intermediate schema
|
|
47
|
-
schemaRepository.updateSchema(incrementalSchemaUpdate);
|
|
48
|
-
// Insert initial tree
|
|
49
|
-
setInitialTree();
|
|
50
|
-
// If intermediate schema is not final desired schema, update to the final schema:
|
|
51
|
-
if (incrementalSchemaUpdate !== newSchema) {
|
|
52
|
-
// This makes the root more strict, so set allowNonSupersetSchema to true.
|
|
53
|
-
schemaRepository.updateSchema(newSchema, true);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export var UpdateType;
|
|
57
|
-
(function (UpdateType) {
|
|
58
|
-
/**
|
|
59
|
-
* Already compatible, no update needed.
|
|
60
|
-
*/
|
|
61
|
-
UpdateType[UpdateType["None"] = 0] = "None";
|
|
62
|
-
/**
|
|
63
|
-
* Schema can be upgraded leaving tree as is.
|
|
64
|
-
*/
|
|
65
|
-
UpdateType[UpdateType["SchemaCompatible"] = 1] = "SchemaCompatible";
|
|
66
|
-
/**
|
|
67
|
-
* No update currently supported.
|
|
68
|
-
*/
|
|
69
|
-
UpdateType[UpdateType["Incompatible"] = 2] = "Incompatible";
|
|
70
|
-
})(UpdateType || (UpdateType = {}));
|
|
71
|
-
/**
|
|
72
|
-
* Returns how compatible updating checkout's schema is with the viewSchema.
|
|
73
|
-
*/
|
|
74
|
-
export function evaluateUpdate(viewSchema, checkout) {
|
|
75
|
-
const compatibility = viewSchema.checkCompatibility(checkout.storedSchema);
|
|
76
|
-
if (compatibility.canUpgrade && compatibility.canView) {
|
|
77
|
-
// Compatible as is
|
|
78
|
-
return UpdateType.None;
|
|
79
|
-
}
|
|
80
|
-
if (!compatibility.canUpgrade) {
|
|
81
|
-
// Existing stored schema permits trees which are incompatible with the view schema, so schema can not be updated
|
|
82
|
-
return UpdateType.Incompatible;
|
|
83
|
-
}
|
|
84
|
-
assert(!compatibility.canView, 0x8bd /* unexpected case */);
|
|
85
|
-
assert(compatibility.canUpgrade, 0x8be /* unexpected case */);
|
|
86
|
-
return UpdateType.SchemaCompatible;
|
|
87
|
-
}
|
|
5
|
+
import { assert } from "@fluidframework/core-utils/internal";
|
|
6
|
+
import { rootFieldKey, schemaDataIsEmpty } from "../core/index.js";
|
|
7
|
+
import { FieldKinds, allowsRepoSuperset, defaultSchemaPolicy, } from "../feature-libraries/index.js";
|
|
88
8
|
export function canInitialize(checkout) {
|
|
89
9
|
// Check for empty.
|
|
90
10
|
return checkout.forest.isEmpty && schemaDataIsEmpty(checkout.storedSchema);
|
|
91
11
|
}
|
|
92
|
-
function normalizeNewFieldContent(content) {
|
|
93
|
-
if (content === undefined) {
|
|
94
|
-
return cursorForMapTreeField([]);
|
|
95
|
-
}
|
|
96
|
-
if (isReadonlyArray(content)) {
|
|
97
|
-
return cursorForMapTreeField(content.map((c) => mapTreeFromCursor(c)));
|
|
98
|
-
}
|
|
99
|
-
if (content.mode === 1 /* CursorLocationType.Fields */) {
|
|
100
|
-
return content;
|
|
101
|
-
}
|
|
102
|
-
return cursorForMapTreeField([mapTreeFromCursor(content)]);
|
|
103
|
-
}
|
|
104
12
|
/**
|
|
105
13
|
* Initialize a checkout with a schema and tree content.
|
|
106
14
|
* This function should only be called when the tree is uninitialized (no schema or content).
|
|
107
|
-
* @remarks
|
|
108
15
|
*
|
|
109
|
-
*
|
|
16
|
+
* @param checkout - The tree checkout to initialize.
|
|
17
|
+
* @param newSchema - The new schema to apply.
|
|
18
|
+
* @param contentFactory - A function that sets the initial tree content.
|
|
19
|
+
* Invoked after a schema containing all nodes from newSchema is applied.
|
|
20
|
+
* Note that the final root field schema may not have been applied yet: if the root is required, it will be optional at this time
|
|
21
|
+
* (so the root being empty before the insertion is not out of schema).
|
|
22
|
+
* @remarks
|
|
23
|
+
* If `newSchema` is not compatible with the empty tree, this function handles it using an intermediate schema
|
|
110
24
|
* which supports the empty tree as well as the final tree content.
|
|
25
|
+
* @privateRemarks
|
|
26
|
+
* This takes in a checkout using a subset of the checkout interface to enable easier unit testing.
|
|
111
27
|
*/
|
|
112
|
-
export function initialize(checkout,
|
|
113
|
-
checkout.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
});
|
|
28
|
+
export function initialize(checkout, newSchema, setInitialTree) {
|
|
29
|
+
assert(schemaDataIsEmpty(checkout.storedSchema), 0x743 /* cannot initialize after a schema is set */);
|
|
30
|
+
// To keep the data in schema during the update, first define a schema that tolerates the current (empty) tree as well as the final (initial) tree.
|
|
31
|
+
let intermediateSchema;
|
|
32
|
+
{
|
|
33
|
+
const rootSchema = newSchema.rootFieldSchema;
|
|
34
|
+
const rootKind = rootSchema.kind;
|
|
35
|
+
if (rootKind === FieldKinds.sequence.identifier ||
|
|
36
|
+
rootKind === FieldKinds.optional.identifier) {
|
|
37
|
+
// These kinds are known to tolerate empty, so use the schema as is:
|
|
38
|
+
intermediateSchema = newSchema;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
assert(rootKind === FieldKinds.required.identifier, 0x5c8 /* Unexpected kind */);
|
|
42
|
+
// Replace value kind with optional kind in root field schema:
|
|
43
|
+
intermediateSchema = {
|
|
44
|
+
nodeSchema: newSchema.nodeSchema,
|
|
45
|
+
rootFieldSchema: {
|
|
46
|
+
kind: FieldKinds.optional.identifier,
|
|
47
|
+
types: rootSchema.types,
|
|
48
|
+
persistedMetadata: rootSchema.persistedMetadata,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
137
52
|
}
|
|
138
|
-
|
|
139
|
-
|
|
53
|
+
assert(allowsRepoSuperset(defaultSchemaPolicy, newSchema, intermediateSchema), 0x5c9 /* Incremental Schema during update should allow a superset of the final schema */);
|
|
54
|
+
checkout.updateSchema(intermediateSchema);
|
|
55
|
+
setInitialTree();
|
|
56
|
+
// If intermediate schema is not final desired schema, update to the final schema:
|
|
57
|
+
if (intermediateSchema !== newSchema) {
|
|
58
|
+
// This makes the root more strict, so set allowNonSupersetSchema to true.
|
|
59
|
+
checkout.updateSchema(newSchema, true);
|
|
140
60
|
}
|
|
141
61
|
}
|
|
142
62
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
63
|
+
* Construct a general purpose `setInitialTree` for use with {@link initialize} from a function that returns a chunk.
|
|
64
|
+
* @param contentFactory - A function that returns the initial tree content as a chunk.
|
|
65
|
+
* Invoked after a schema containing all nodes from newSchema is applied.
|
|
66
|
+
* Note that the final root field schema may not have been applied yet: if the root is required, it will be optional at this time
|
|
67
|
+
* (so the root being empty before the insertion is not out of schema).
|
|
145
68
|
* @remarks
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* @param viewSchema - View schema that `checkout` should be made compatible with.
|
|
149
|
-
* @param allowedSchemaModifications - Flags enum describing the ways this is allowed to modify `checkout`.
|
|
150
|
-
* @param checkout - To be modified as needed to be compatible with `viewSchema`.
|
|
151
|
-
* @param treeContent - Content to be used to initialize `checkout`'s the tree if needed and allowed.
|
|
152
|
-
* @returns true iff checkout now is compatible with `viewSchema`.
|
|
69
|
+
* This does not support sequence roots as they are not allowed in the public API surface.
|
|
70
|
+
* A test utility for them can be found as `initializeSequenceRoot` for testing internal logic which uses a sequence root.
|
|
153
71
|
*/
|
|
154
|
-
export function
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
case UpdateType.SchemaCompatible: {
|
|
164
|
-
checkout.updateSchema(toStoredSchema(viewSchema.viewSchema.root));
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
default: {
|
|
168
|
-
unreachableCase(updatedNeeded);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
72
|
+
export function initializerFromChunk(checkout, contentFactory) {
|
|
73
|
+
return () => initializeFromChunk(checkout, contentFactory());
|
|
74
|
+
}
|
|
75
|
+
function initializeFromChunk(checkout, contentChunk) {
|
|
76
|
+
const field = { field: rootFieldKey, parent: undefined };
|
|
77
|
+
assert(checkout.storedSchema.rootFieldSchema.kind === FieldKinds.optional.identifier, 0xc11 /* initializerFromChunk only supports optional roots */);
|
|
78
|
+
const fieldEditor = checkout.editor.optionalField(field);
|
|
79
|
+
assert(contentChunk.topLevelLength <= 1, 0x7f4 /* optional field content should normalize at most one item */);
|
|
80
|
+
fieldEditor.set(contentChunk.topLevelLength === 0 ? undefined : contentChunk, true);
|
|
171
81
|
}
|
|
172
82
|
//# sourceMappingURL=schematizeTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schematizeTree.js","sourceRoot":"","sources":["../../src/shared-tree/schematizeTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAEpF,OAAO,EAIN,YAAY,EACZ,iBAAiB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,UAAU,EACV,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,GACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,cAAc,EAAkC,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAInD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAChC,gBAGC,EACD,SAA2B,EAC3B,cAA0B;IAE1B,MAAM,CACL,iBAAiB,CAAC,gBAAgB,C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D,OAAO,CAAC,CAAC,CAAC;oBACT,IAAI,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;gBAChE,CAAC;YACF,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;YAAS,CAAC;QACV,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;AACF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAC3B,UAAqC,EACrC,QAAuB;IAEvB,MAAM,aAAa,GAAG,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC3D,QAAQ,aAAa,EAAE,CAAC;QACvB,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;YACtB,OAAO,IAAI,CAAC;QACb,CAAC;QACD,KAAK,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;YAC9B,OAAO,KAAK,CAAC;QACd,CAAC;QACD,KAAK,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC;YAClC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;YAClE,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACT,eAAe,CAAC,aAAa,CAAC,CAAC;QAChC,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase, fail } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\tCursorLocationType,\n\ttype ITreeCursorSynchronous,\n\ttype TreeStoredSchema,\n\trootFieldKey,\n\tschemaDataIsEmpty,\n} from \"../core/index.js\";\nimport {\n\tFieldKinds,\n\tallowsRepoSuperset,\n\tcursorForMapTreeField,\n\tdefaultSchemaPolicy,\n\tmapTreeFromCursor,\n} from \"../feature-libraries/index.js\";\nimport { toStoredSchema, type SchemaCompatibilityTester } from \"../simple-tree/index.js\";\nimport { isReadonlyArray } from \"../util/index.js\";\n\nimport type { ITreeCheckout } from \"./treeCheckout.js\";\n\n/**\n * Modify `storedSchema` and invoke `setInitialTree` when it's time to set the tree content.\n *\n * Requires `storedSchema` to be in its default/empty state.\n *\n * This is done in such a way that if the content (implicitly assumed to start empty)\n * is never out of schema.\n * This means that if the root field of the new schema requires content (like a value field),\n * a temporary intermediate schema is used so the initial empty state is not out of schema.\n *\n * Since this makes multiple changes, callers may want to wrap it in a transaction.\n */\nexport function initializeContent(\n\tschemaRepository: {\n\t\tstoredSchema: ITreeCheckout[\"storedSchema\"];\n\t\tupdateSchema: ITreeCheckout[\"updateSchema\"];\n\t},\n\tnewSchema: TreeStoredSchema,\n\tsetInitialTree: () => void,\n): void {\n\tassert(\n\t\tschemaDataIsEmpty(schemaRepository.storedSchema),\n\t\t0x743 /* cannot initialize after a schema is set */,\n\t);\n\n\tconst rootSchema = newSchema.rootFieldSchema;\n\tconst rootKind = rootSchema.kind;\n\n\t// To keep the data in schema during the update, first define a schema that tolerates the current (empty) tree as well as the final (initial) tree.\n\tlet incrementalSchemaUpdate: TreeStoredSchema;\n\tif (\n\t\trootKind === FieldKinds.sequence.identifier ||\n\t\trootKind === FieldKinds.optional.identifier\n\t) {\n\t\t// These kinds are known to tolerate empty, so use the schema as is:\n\t\tincrementalSchemaUpdate = newSchema;\n\t} else {\n\t\tassert(rootKind === FieldKinds.required.identifier, 0x5c8 /* Unexpected kind */);\n\t\t// Replace value kind with optional kind in root field schema:\n\t\tincrementalSchemaUpdate = {\n\t\t\tnodeSchema: newSchema.nodeSchema,\n\t\t\trootFieldSchema: {\n\t\t\t\tkind: FieldKinds.optional.identifier,\n\t\t\t\ttypes: rootSchema.types,\n\t\t\t\tpersistedMetadata: rootSchema.persistedMetadata,\n\t\t\t},\n\t\t};\n\t}\n\n\tassert(\n\t\tallowsRepoSuperset(defaultSchemaPolicy, newSchema, incrementalSchemaUpdate),\n\t\t0x5c9 /* Incremental Schema during update should allow a superset of the final schema */,\n\t);\n\t// Update to intermediate schema\n\tschemaRepository.updateSchema(incrementalSchemaUpdate);\n\t// Insert initial tree\n\tsetInitialTree();\n\n\t// If intermediate schema is not final desired schema, update to the final schema:\n\tif (incrementalSchemaUpdate !== newSchema) {\n\t\t// This makes the root more strict, so set allowNonSupersetSchema to true.\n\t\tschemaRepository.updateSchema(newSchema, true);\n\t}\n}\n\nexport enum UpdateType {\n\t/**\n\t * Already compatible, no update needed.\n\t */\n\tNone,\n\t/**\n\t * Schema can be upgraded leaving tree as is.\n\t */\n\tSchemaCompatible,\n\t/**\n\t * No update currently supported.\n\t */\n\tIncompatible,\n}\n\n/**\n * Returns how compatible updating checkout's schema is with the viewSchema.\n */\nexport function evaluateUpdate(\n\tviewSchema: SchemaCompatibilityTester,\n\tcheckout: ITreeCheckout,\n): UpdateType {\n\tconst compatibility = viewSchema.checkCompatibility(checkout.storedSchema);\n\n\tif (compatibility.canUpgrade && compatibility.canView) {\n\t\t// Compatible as is\n\t\treturn UpdateType.None;\n\t}\n\n\tif (!compatibility.canUpgrade) {\n\t\t// Existing stored schema permits trees which are incompatible with the view schema, so schema can not be updated\n\t\treturn UpdateType.Incompatible;\n\t}\n\n\tassert(!compatibility.canView, 0x8bd /* unexpected case */);\n\tassert(compatibility.canUpgrade, 0x8be /* unexpected case */);\n\n\treturn UpdateType.SchemaCompatible;\n}\n\nexport function canInitialize(checkout: ITreeCheckout): boolean {\n\t// Check for empty.\n\treturn checkout.forest.isEmpty && schemaDataIsEmpty(checkout.storedSchema);\n}\n\nfunction normalizeNewFieldContent(\n\tcontent: readonly ITreeCursorSynchronous[] | ITreeCursorSynchronous | undefined,\n): ITreeCursorSynchronous {\n\tif (content === undefined) {\n\t\treturn cursorForMapTreeField([]);\n\t}\n\n\tif (isReadonlyArray(content)) {\n\t\treturn cursorForMapTreeField(content.map((c) => mapTreeFromCursor(c)));\n\t}\n\n\tif (content.mode === CursorLocationType.Fields) {\n\t\treturn content;\n\t}\n\n\treturn cursorForMapTreeField([mapTreeFromCursor(content)]);\n}\n\n/**\n * Initialize a checkout with a schema and tree content.\n * This function should only be called when the tree is uninitialized (no schema or content).\n * @remarks\n *\n * If the proposed schema (from `treeContent`) is not compatible with the empty tree, this function handles using an intermediate schema\n * which supports the empty tree as well as the final tree content.\n */\nexport function initialize(checkout: ITreeCheckout, treeContent: TreeStoredContent): void {\n\tcheckout.transaction.start();\n\ttry {\n\t\tinitializeContent(checkout, treeContent.schema, () => {\n\t\t\tconst field = { field: rootFieldKey, parent: undefined };\n\t\t\tconst content = normalizeNewFieldContent(treeContent.initialTree);\n\t\t\tconst contentChunk = checkout.forest.chunkField(content);\n\n\t\t\tswitch (checkout.storedSchema.rootFieldSchema.kind) {\n\t\t\t\tcase FieldKinds.optional.identifier: {\n\t\t\t\t\tconst fieldEditor = checkout.editor.optionalField(field);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tcontent.getFieldLength() <= 1,\n\t\t\t\t\t\t0x7f4 /* optional field content should normalize at most one item */,\n\t\t\t\t\t);\n\t\t\t\t\tfieldEditor.set(contentChunk.topLevelLength === 0 ? undefined : contentChunk, true);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase FieldKinds.sequence.identifier: {\n\t\t\t\t\tconst fieldEditor = checkout.editor.sequenceField(field);\n\t\t\t\t\t// TODO: should do an idempotent edit here.\n\t\t\t\t\tfieldEditor.insert(0, contentChunk);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tfail(0xac7 /* unexpected root field kind during initialize */);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t} finally {\n\t\tcheckout.transaction.commit();\n\t}\n}\n\n/**\n * Ensure a {@link ITreeCheckout} can be used with a given {@link SchemaCompatibilityTester}.\n *\n * @remarks\n * It is up to the caller to ensure that compatibility is reevaluated if the checkout's stored schema is edited in the future.\n *\n * @param viewSchema - View schema that `checkout` should be made compatible with.\n * @param allowedSchemaModifications - Flags enum describing the ways this is allowed to modify `checkout`.\n * @param checkout - To be modified as needed to be compatible with `viewSchema`.\n * @param treeContent - Content to be used to initialize `checkout`'s the tree if needed and allowed.\n * @returns true iff checkout now is compatible with `viewSchema`.\n */\nexport function ensureSchema(\n\tviewSchema: SchemaCompatibilityTester,\n\tcheckout: ITreeCheckout,\n): boolean {\n\tconst updatedNeeded = evaluateUpdate(viewSchema, checkout);\n\tswitch (updatedNeeded) {\n\t\tcase UpdateType.None: {\n\t\t\treturn true;\n\t\t}\n\t\tcase UpdateType.Incompatible: {\n\t\t\treturn false;\n\t\t}\n\t\tcase UpdateType.SchemaCompatible: {\n\t\t\tcheckout.updateSchema(toStoredSchema(viewSchema.viewSchema.root));\n\t\t\treturn true;\n\t\t}\n\t\tdefault: {\n\t\t\tunreachableCase(updatedNeeded);\n\t\t}\n\t}\n}\n\n/**\n * Content that can populate a `SharedTree`.\n */\nexport interface TreeStoredContent {\n\treadonly schema: TreeStoredSchema;\n\n\t/**\n\t * Default tree content to initialize the tree with iff the tree is uninitialized\n\t * (meaning it does not even have any schema set at all).\n\t */\n\treadonly initialTree: readonly ITreeCursorSynchronous[] | ITreeCursorSynchronous | undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"schematizeTree.js","sourceRoot":"","sources":["../../src/shared-tree/schematizeTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAAyB,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EACN,UAAU,EACV,kBAAkB,EAClB,mBAAmB,GAGnB,MAAM,+BAA+B,CAAC;AAIvC,MAAM,UAAU,aAAa,CAAC,QAAuB;IACpD,mBAAmB;IACnB,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,IAAI,iBAAiB,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,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,MAAM,UAAU,oBAAoB,CACnC,QAEC,EACD,cAA+B;IAE/B,OAAO,GAAG,EAAE,CAAC,mBAAmB,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,mBAAmB,CAC3B,QAEC,EACD,YAAuB;IAEvB,MAAM,KAAK,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACzD,MAAM,CACL,QAAQ,CAAC,YAAY,CAAC,eAAe,CAAC,IAAI,KAAK,UAAU,CAAC,QAAQ,CAAC,UAAU,EAC7E,KAAK,CAAC,uDAAuD,CAC7D,CAAC;IACF,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACzD,MAAM,CACL,YAAY,CAAC,cAAc,IAAI,CAAC,EAChC,KAAK,CAAC,8DAA8D,CACpE,CAAC;IACF,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,cAAc,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACrF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport { type TreeStoredSchema, rootFieldKey, schemaDataIsEmpty } from \"../core/index.js\";\nimport {\n\tFieldKinds,\n\tallowsRepoSuperset,\n\tdefaultSchemaPolicy,\n\ttype IDefaultEditBuilder,\n\ttype TreeChunk,\n} from \"../feature-libraries/index.js\";\n\nimport type { ITreeCheckout } from \"./treeCheckout.js\";\n\nexport function canInitialize(checkout: ITreeCheckout): boolean {\n\t// Check for empty.\n\treturn checkout.forest.isEmpty && schemaDataIsEmpty(checkout.storedSchema);\n}\n\n/**\n * Initialize a checkout with a schema and tree content.\n * This function should only be called when the tree is uninitialized (no schema or content).\n *\n * @param checkout - The tree checkout to initialize.\n * @param newSchema - The new schema to apply.\n * @param contentFactory - A function that sets the initial tree content.\n * Invoked after a schema containing all nodes from newSchema is applied.\n * Note that the final root field schema may not have been applied yet: if the root is required, it will be optional at this time\n * (so the root being empty before the insertion is not out of schema).\n * @remarks\n * If `newSchema` is not compatible with the empty tree, this function handles it using an intermediate schema\n * which supports the empty tree as well as the final tree content.\n * @privateRemarks\n * This takes in a checkout using a subset of the checkout interface to enable easier unit testing.\n */\nexport function initialize(\n\tcheckout: Pick<ITreeCheckout, \"storedSchema\" | \"updateSchema\">,\n\tnewSchema: TreeStoredSchema,\n\tsetInitialTree: () => void,\n): void {\n\tassert(\n\t\tschemaDataIsEmpty(checkout.storedSchema),\n\t\t0x743 /* cannot initialize after a schema is set */,\n\t);\n\n\t// To keep the data in schema during the update, first define a schema that tolerates the current (empty) tree as well as the final (initial) tree.\n\tlet intermediateSchema: TreeStoredSchema;\n\t{\n\t\tconst rootSchema = newSchema.rootFieldSchema;\n\t\tconst rootKind = rootSchema.kind;\n\t\tif (\n\t\t\trootKind === FieldKinds.sequence.identifier ||\n\t\t\trootKind === FieldKinds.optional.identifier\n\t\t) {\n\t\t\t// These kinds are known to tolerate empty, so use the schema as is:\n\t\t\tintermediateSchema = newSchema;\n\t\t} else {\n\t\t\tassert(rootKind === FieldKinds.required.identifier, 0x5c8 /* Unexpected kind */);\n\t\t\t// Replace value kind with optional kind in root field schema:\n\t\t\tintermediateSchema = {\n\t\t\t\tnodeSchema: newSchema.nodeSchema,\n\t\t\t\trootFieldSchema: {\n\t\t\t\t\tkind: FieldKinds.optional.identifier,\n\t\t\t\t\ttypes: rootSchema.types,\n\t\t\t\t\tpersistedMetadata: rootSchema.persistedMetadata,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t}\n\n\tassert(\n\t\tallowsRepoSuperset(defaultSchemaPolicy, newSchema, intermediateSchema),\n\t\t0x5c9 /* Incremental Schema during update should allow a superset of the final schema */,\n\t);\n\n\tcheckout.updateSchema(intermediateSchema);\n\tsetInitialTree();\n\n\t// If intermediate schema is not final desired schema, update to the final schema:\n\tif (intermediateSchema !== newSchema) {\n\t\t// This makes the root more strict, so set allowNonSupersetSchema to true.\n\t\tcheckout.updateSchema(newSchema, true);\n\t}\n}\n\n/**\n * Construct a general purpose `setInitialTree` for use with {@link initialize} from a function that returns a chunk.\n * @param contentFactory - A function that returns the initial tree content as a chunk.\n * Invoked after a schema containing all nodes from newSchema is applied.\n * Note that the final root field schema may not have been applied yet: if the root is required, it will be optional at this time\n * (so the root being empty before the insertion is not out of schema).\n * @remarks\n * This does not support sequence roots as they are not allowed in the public API surface.\n * A test utility for them can be found as `initializeSequenceRoot` for testing internal logic which uses a sequence root.\n */\nexport function initializerFromChunk(\n\tcheckout: Pick<ITreeCheckout, \"storedSchema\"> & {\n\t\treadonly editor: IDefaultEditBuilder;\n\t},\n\tcontentFactory: () => TreeChunk,\n): () => void {\n\treturn () => initializeFromChunk(checkout, contentFactory());\n}\n\nfunction initializeFromChunk(\n\tcheckout: Pick<ITreeCheckout, \"storedSchema\"> & {\n\t\treadonly editor: IDefaultEditBuilder;\n\t},\n\tcontentChunk: TreeChunk,\n): void {\n\tconst field = { field: rootFieldKey, parent: undefined };\n\tassert(\n\t\tcheckout.storedSchema.rootFieldSchema.kind === FieldKinds.optional.identifier,\n\t\t0xc11 /* initializerFromChunk only supports optional roots */,\n\t);\n\tconst fieldEditor = checkout.editor.optionalField(field);\n\tassert(\n\t\tcontentChunk.topLevelLength <= 1,\n\t\t0x7f4 /* optional field content should normalize at most one item */,\n\t);\n\tfieldEditor.set(contentChunk.topLevelLength === 0 ? undefined : contentChunk, true);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schematizingTreeView.d.ts","sourceRoot":"","sources":["../../src/shared-tree/schematizingTreeView.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACX,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,MAAM,0CAA0C,CAAC;AAKlD,OAAO,EACN,KAAK,qBAAqB,EAI1B,OAAO,EACP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,QAAQ,EACb,KAAK,cAAc,EAMnB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,KAAK,gBAAgB,EAGrB,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,
|
|
1
|
+
{"version":3,"file":"schematizingTreeView.d.ts","sourceRoot":"","sources":["../../src/shared-tree/schematizingTreeView.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACX,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,MAAM,0CAA0C,CAAC;AAKlD,OAAO,EACN,KAAK,qBAAqB,EAI1B,OAAO,EACP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,QAAQ,EACb,KAAK,cAAc,EAMnB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,KAAK,gBAAgB,EAGrB,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAW1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,KAAK,SAAS,EAGd,KAAK,aAAa,EAClB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC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AAO,GAChD,IAAI,CAwBN"}
|
|
@@ -44,10 +44,10 @@ import { createEmitter } from "@fluid-internal/client-utils";
|
|
|
44
44
|
import { assert, unreachableCase } from "@fluidframework/core-utils/internal";
|
|
45
45
|
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
46
46
|
import { anchorSlot } from "../core/index.js";
|
|
47
|
-
import { defaultSchemaPolicy,
|
|
48
|
-
import { tryGetTreeNodeForField, setField, normalizeFieldSchema, SchemaCompatibilityTester, getOrCreateInnerNode, getKernel, HydratedContext, SimpleContextSlot, areImplicitFieldSchemaEqual, prepareForInsertionContextless,
|
|
47
|
+
import { defaultSchemaPolicy, cursorForMapTreeField, TreeStatus, Context, } from "../feature-libraries/index.js";
|
|
48
|
+
import { tryGetTreeNodeForField, setField, normalizeFieldSchema, SchemaCompatibilityTester, getOrCreateInnerNode, getKernel, HydratedContext, SimpleContextSlot, areImplicitFieldSchemaEqual, prepareForInsertionContextless, tryDisposeTreeNode, FieldSchemaAlpha, TreeViewConfigurationAlpha, toInitialSchema, toUpgradeSchema, } from "../simple-tree/index.js";
|
|
49
49
|
import { breakingClass, disposeSymbol, } from "../util/index.js";
|
|
50
|
-
import { canInitialize,
|
|
50
|
+
import { canInitialize, initialize, initializerFromChunk } from "./schematizeTree.js";
|
|
51
51
|
/**
|
|
52
52
|
* Creating multiple tree views from the same checkout is not supported. This slot is used to detect if one already
|
|
53
53
|
* exists and error if creating a second.
|
|
@@ -118,15 +118,17 @@ let SchematizingSimpleTreeView = (() => {
|
|
|
118
118
|
throw new UsageError("Tree cannot be initialized more than once.");
|
|
119
119
|
}
|
|
120
120
|
this.runSchemaEdit(() => {
|
|
121
|
-
const schema =
|
|
121
|
+
const schema = toInitialSchema(this.config.schema);
|
|
122
122
|
const mapTree = prepareForInsertionContextless(content, this.rootFieldSchema, {
|
|
123
123
|
schema,
|
|
124
124
|
policy: defaultSchemaPolicy,
|
|
125
|
-
}, this);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
}, this, schema.rootFieldSchema);
|
|
126
|
+
this.checkout.transaction.start();
|
|
127
|
+
initialize(this.checkout, schema, initializerFromChunk(this.checkout, () => {
|
|
128
|
+
// This must be done after initial schema is set!
|
|
129
|
+
return this.checkout.forest.chunkField(cursorForMapTreeField(mapTree === undefined ? [] : [mapTree]));
|
|
130
|
+
}));
|
|
131
|
+
this.checkout.transaction.commit();
|
|
130
132
|
});
|
|
131
133
|
}
|
|
132
134
|
upgradeSchema() {
|
|
@@ -139,10 +141,8 @@ let SchematizingSimpleTreeView = (() => {
|
|
|
139
141
|
if (!compatibility.canUpgrade) {
|
|
140
142
|
throw new UsageError("Existing stored schema cannot be upgraded (see TreeView.compatibility.canUpgrade).");
|
|
141
143
|
}
|
|
142
|
-
this.
|
|
143
|
-
|
|
144
|
-
assert(result, 0x8bf /* Schema upgrade should always work if canUpgrade is set. */);
|
|
145
|
-
});
|
|
144
|
+
const newSchema = toUpgradeSchema(this.viewSchema.viewSchema.root);
|
|
145
|
+
this.runSchemaEdit(() => this.checkout.updateSchema(newSchema));
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Gets the flex-tree context. Throws when disposed or out of schema.
|
|
@@ -295,7 +295,7 @@ let SchematizingSimpleTreeView = (() => {
|
|
|
295
295
|
throw new UsageError("Document is out of schema. Check TreeView.compatibility before accessing TreeView.root.");
|
|
296
296
|
}
|
|
297
297
|
const view = this.getFlexTreeContext();
|
|
298
|
-
setField(view.root, this.rootFieldSchema, newRoot);
|
|
298
|
+
setField(view.root, this.rootFieldSchema, newRoot, this.checkout.storedSchema.rootFieldSchema);
|
|
299
299
|
}
|
|
300
300
|
// #region Branching
|
|
301
301
|
fork() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schematizingTreeView.js","sourceRoot":"","sources":["../../src/shared-tree/schematizingTreeView.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAC1D,CAAC;gBACD,MAAM;YACP,CAAC;YACD;gBACC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type {\n\tHasListeners,\n\tIEmitter,\n\tListenable,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { anchorSlot } from \"../core/index.js\";\nimport {\n\ttype NodeIdentifierManager,\n\tdefaultSchemaPolicy,\n\tcursorForMapTreeNode,\n\tTreeStatus,\n\tContext,\n} from \"../feature-libraries/index.js\";\nimport {\n\ttype ImplicitFieldSchema,\n\ttype SchemaCompatibilityStatus,\n\ttype TreeView,\n\ttype TreeViewEvents,\n\ttryGetTreeNodeForField,\n\tsetField,\n\tnormalizeFieldSchema,\n\tSchemaCompatibilityTester,\n\ttype InsertableContent,\n\ttype TreeViewConfiguration,\n\ttype TreeViewAlpha,\n\ttype InsertableField,\n\ttype ReadableField,\n\ttype ReadSchema,\n\ttype UnsafeUnknownSchema,\n\ttype TreeBranch,\n\ttype TreeBranchEvents,\n\tgetOrCreateInnerNode,\n\tgetKernel,\n\ttype VoidTransactionCallbackStatus,\n\ttype TransactionCallbackStatus,\n\ttype TransactionResult,\n\ttype TransactionResultExt,\n\ttype RunTransactionParams,\n\ttype TransactionConstraint,\n\tHydratedContext,\n\tSimpleContextSlot,\n\tareImplicitFieldSchemaEqual,\n\tprepareForInsertionContextless,\n\ttype FieldSchema,\n\ttoStoredSchema,\n\ttryDisposeTreeNode,\n\tFieldSchemaAlpha,\n\tTreeViewConfigurationAlpha,\n} from \"../simple-tree/index.js\";\nimport {\n\ttype Breakable,\n\tbreakingClass,\n\tdisposeSymbol,\n\ttype WithBreakable,\n} from \"../util/index.js\";\n\nimport { canInitialize, ensureSchema, initialize } from \"./schematizeTree.js\";\nimport type { ITreeCheckout, TreeCheckout } from \"./treeCheckout.js\";\n\n/**\n * Creating multiple tree views from the same checkout is not supported. This slot is used to detect if one already\n * exists and error if creating a second.\n */\nexport const ViewSlot = anchorSlot<TreeView<ImplicitFieldSchema>>();\n\n/**\n * Implementation of TreeView wrapping a FlexTreeView.\n */\n@breakingClass\nexport class SchematizingSimpleTreeView<\n\tin out TRootSchema extends ImplicitFieldSchema | UnsafeUnknownSchema,\n> implements TreeBranch, TreeViewAlpha<TRootSchema>, WithBreakable\n{\n\t/**\n\t * This is set to undefined when this object is disposed or the view schema does not support viewing the document's stored schema.\n\t *\n\t * The view schema may be incompatible with the stored schema. Use `compatibility` to check.\n\t */\n\tprivate flexTreeContext: Context | undefined;\n\n\t/**\n\t * Undefined iff uninitialized or disposed.\n\t */\n\tprivate currentCompatibility: SchemaCompatibilityStatus | undefined;\n\tpublic readonly events: Listenable<TreeViewEvents & TreeBranchEvents> &\n\t\tIEmitter<TreeViewEvents & TreeBranchEvents> &\n\t\tHasListeners<TreeViewEvents & TreeBranchEvents> = createEmitter();\n\n\tprivate readonly viewSchema: SchemaCompatibilityTester;\n\n\t/**\n\t * Events to unregister upon flex-tree view disposal.\n\t */\n\tprivate readonly flexTreeViewUnregisterCallbacks = new Set<() => void>();\n\n\t/**\n\t * Events to unregister upon disposal.\n\t */\n\tprivate readonly unregisterCallbacks = new Set<() => void>();\n\n\tpublic disposed = false;\n\t/**\n\t * This is set to true while an edit impacting the document schema is in progress.\n\t * This allows suppressing extra rootChanged / schemaChanged events until the edit concludes.\n\t * This is useful especially for some initialization edits, since document initialization can involve transient schemas\n\t * which are implementation details and should not be exposed to the user.\n\t */\n\tprivate midUpgrade = false;\n\n\tprivate readonly rootFieldSchema: FieldSchema;\n\tpublic readonly breaker: Breakable;\n\n\tpublic constructor(\n\t\tpublic readonly checkout: TreeCheckout,\n\t\tpublic readonly config: TreeViewConfiguration<ReadSchema<TRootSchema>>,\n\t\tpublic readonly nodeKeyManager: NodeIdentifierManager,\n\t\tprivate readonly onDispose?: () => void,\n\t) {\n\t\tthis.breaker = checkout.breaker;\n\t\tif (checkout.forest.anchors.slots.has(ViewSlot)) {\n\t\t\tthrow new UsageError(\"Cannot create a second tree view from the same checkout\");\n\t\t}\n\t\tcheckout.forest.anchors.slots.set(ViewSlot, this);\n\n\t\tthis.rootFieldSchema = normalizeFieldSchema(config.schema);\n\n\t\tconst configAlpha = new TreeViewConfigurationAlpha({ schema: config.schema });\n\n\t\tthis.viewSchema = new SchemaCompatibilityTester(configAlpha);\n\t\t// This must be initialized before `update` can be called.\n\t\tthis.currentCompatibility = {\n\t\t\tcanView: false,\n\t\t\tcanUpgrade: true,\n\t\t\tisEquivalent: false,\n\t\t\tcanInitialize: true,\n\t\t};\n\t\tthis.update();\n\n\t\tthis.unregisterCallbacks.add(\n\t\t\tthis.checkout.events.on(\"changed\", (data, getRevertible) => {\n\t\t\t\tthis.events.emit(\"changed\", data, getRevertible);\n\t\t\t\tthis.events.emit(\"commitApplied\", data, getRevertible);\n\t\t\t}),\n\t\t);\n\t}\n\n\tpublic hasRootSchema<TSchema extends ImplicitFieldSchema>(\n\t\tschema: TSchema,\n\t): this is TreeViewAlpha<TSchema> {\n\t\treturn areImplicitFieldSchemaEqual(this.rootFieldSchema, schema);\n\t}\n\n\tpublic get schema(): ReadSchema<TRootSchema> {\n\t\treturn this.config.schema;\n\t}\n\n\tpublic initialize(content: InsertableField<TRootSchema>): void {\n\t\tthis.ensureUndisposed();\n\n\t\tconst compatibility = this.compatibility;\n\t\tif (!compatibility.canInitialize) {\n\t\t\tthrow new UsageError(\"Tree cannot be initialized more than once.\");\n\t\t}\n\n\t\tthis.runSchemaEdit(() => {\n\t\t\tconst schema = toStoredSchema(this.config.schema);\n\t\t\tconst mapTree = prepareForInsertionContextless(\n\t\t\t\tcontent as InsertableContent | undefined,\n\t\t\t\tthis.rootFieldSchema,\n\t\t\t\t{\n\t\t\t\t\tschema,\n\t\t\t\t\tpolicy: defaultSchemaPolicy,\n\t\t\t\t},\n\t\t\t\tthis,\n\t\t\t);\n\n\t\t\tinitialize(this.checkout, {\n\t\t\t\tschema,\n\t\t\t\tinitialTree: mapTree === undefined ? undefined : cursorForMapTreeNode(mapTree),\n\t\t\t});\n\t\t});\n\t}\n\n\tpublic upgradeSchema(): void {\n\t\tthis.ensureUndisposed();\n\n\t\tconst compatibility = this.compatibility;\n\t\tif (compatibility.isEquivalent) {\n\t\t\t// No-op\n\t\t\treturn;\n\t\t}\n\n\t\tif (!compatibility.canUpgrade) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Existing stored schema cannot be upgraded (see TreeView.compatibility.canUpgrade).\",\n\t\t\t);\n\t\t}\n\n\t\tthis.runSchemaEdit(() => {\n\t\t\tconst result = ensureSchema(this.viewSchema, this.checkout);\n\t\t\tassert(result, 0x8bf /* Schema upgrade should always work if canUpgrade is set. */);\n\t\t});\n\t}\n\n\t/**\n\t * Gets the flex-tree context. Throws when disposed or out of schema.\n\t */\n\tpublic getFlexTreeContext(): Context {\n\t\tthis.ensureUndisposed();\n\t\tassert(this.flexTreeContext !== undefined, 0x8c0 /* unexpected getViewOrError */);\n\t\treturn this.flexTreeContext;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-tree#TreeViewAlpha.runTransaction}\n\t */\n\tpublic runTransaction<TSuccessValue, TFailureValue>(\n\t\ttransaction: () => TransactionCallbackStatus<TSuccessValue, TFailureValue>,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResultExt<TSuccessValue, TFailureValue>;\n\t/**\n\t * {@inheritDoc @fluidframework/shared-tree#TreeViewAlpha.runTransaction}\n\t */\n\tpublic runTransaction(\n\t\ttransaction: () => VoidTransactionCallbackStatus | void,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResult;\n\tpublic runTransaction<TSuccessValue, TFailureValue>(\n\t\ttransaction: () =>\n\t\t\t| TransactionCallbackStatus<TSuccessValue, TFailureValue>\n\t\t\t| VoidTransactionCallbackStatus\n\t\t\t| void,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResultExt<TSuccessValue, TFailureValue> | TransactionResult {\n\t\tconst addConstraints = (\n\t\t\tconstraintsOnRevert: boolean,\n\t\t\tconstraints: readonly TransactionConstraint[] = [],\n\t\t): void => {\n\t\t\taddConstraintsToTransaction(this.checkout, constraintsOnRevert, constraints);\n\t\t};\n\n\t\tthis.checkout.transaction.start();\n\n\t\t// Validate preconditions before running the transaction callback.\n\t\taddConstraints(false /* constraintsOnRevert */, params?.preconditions);\n\t\tconst transactionCallbackStatus = transaction();\n\t\tconst rollback = transactionCallbackStatus?.rollback;\n\t\tconst value = (\n\t\t\ttransactionCallbackStatus as TransactionCallbackStatus<TSuccessValue, TFailureValue>\n\t\t)?.value;\n\n\t\tif (rollback === true) {\n\t\t\tthis.checkout.transaction.abort();\n\t\t\treturn value !== undefined\n\t\t\t\t? { success: false, value: value as TFailureValue }\n\t\t\t\t: { success: false };\n\t\t}\n\n\t\t// Validate preconditions on revert after running the transaction callback and was successful.\n\t\taddConstraints(\n\t\t\ttrue /* constraintsOnRevert */,\n\t\t\ttransactionCallbackStatus?.preconditionsOnRevert,\n\t\t);\n\n\t\tthis.checkout.transaction.commit();\n\t\treturn value !== undefined\n\t\t\t? { success: true, value: value as TSuccessValue }\n\t\t\t: { success: true };\n\t}\n\n\tprivate ensureUndisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthis.failDisposed();\n\t\t}\n\t}\n\n\tprivate failDisposed(): never {\n\t\tthrow new UsageError(\"Accessed a disposed TreeView.\");\n\t}\n\n\t/**\n\t * Updates `this.view` and the current compatibility status.\n\t * Invoked during initialization and when `this.view` needs to be replaced due to stored schema changes.\n\t * Handles re-registering for events to call update in the future.\n\t * @remarks\n\t * This does not check if the view needs to be replaced, it replaces it unconditionally:\n\t * callers should do any checking to detect if it's really needed before calling `update`.\n\t * @privateRemarks\n\t * This implementation avoids making any edits, which prevents it from being invoked reentrantly.\n\t * If implicit initialization (or some other edit) is desired, it should be done outside of this method.\n\t */\n\tprivate update(): void {\n\t\tthis.disposeFlexView();\n\n\t\tconst compatibility = this.viewSchema.checkCompatibility(this.checkout.storedSchema);\n\n\t\tthis.currentCompatibility = {\n\t\t\t...compatibility,\n\t\t\tcanInitialize: canInitialize(this.checkout),\n\t\t};\n\n\t\tconst anchors = this.checkout.forest.anchors;\n\t\tconst slots = anchors.slots;\n\n\t\tif (compatibility.canView) {\n\t\t\tthis.flexTreeContext = new Context(\n\t\t\t\tdefaultSchemaPolicy,\n\t\t\t\tthis.checkout,\n\t\t\t\tthis.nodeKeyManager,\n\t\t\t);\n\t\t\tassert(!slots.has(SimpleContextSlot), 0xa47 /* extra simple tree context */);\n\t\t\tassert(\n\t\t\t\tthis.rootFieldSchema instanceof FieldSchemaAlpha,\n\t\t\t\t0xbfa /* all field schema should be FieldSchemaAlpha */,\n\t\t\t);\n\t\t\tslots.set(\n\t\t\t\tSimpleContextSlot,\n\t\t\t\tnew HydratedContext(\n\t\t\t\t\tthis.flexTreeContext,\n\t\t\t\t\tHydratedContext.schemaMapFromRootSchema(\n\t\t\t\t\t\tthis.rootFieldSchema.annotatedAllowedTypesNormalized,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\t// Trigger \"rootChanged\" events if the root changes in the future.\n\t\t\t{\n\t\t\t\t// Currently there is no good way to do this as FlexTreeField has no events for changes.\n\t\t\t\t// this.root.on(????)\n\t\t\t\t// As a workaround for the above, trigger \"rootChanged\" in \"afterBatch\".\n\t\t\t\t// Ideally these events would be just events for changes within the root.\n\t\t\t\t// TODO: provide a better event: this.view.flexTree.on(????) and/or integrate with with the normal event code paths.\n\n\t\t\t\t// Track what the root was before to be able to detect changes.\n\t\t\t\tlet lastRoot: ReadableField<TRootSchema> = this.root;\n\n\t\t\t\tthis.flexTreeViewUnregisterCallbacks.add(\n\t\t\t\t\tthis.checkout.events.on(\"afterBatch\", () => {\n\t\t\t\t\t\t// In the initialization flow, this event is raised before the correct compatibility w.r.t the new schema is calculated.\n\t\t\t\t\t\t// Accessing `this.root` in that case can throw. It's OK to ignore this because:\n\t\t\t\t\t\t// - The rootChanged event will already be raised at the end of the current upgrade\n\t\t\t\t\t\t// - It doesn't matter that `lastRoot` isn't updated in this case, because `update` will be called again before the upgrade\n\t\t\t\t\t\t// completes (at which point this callback and the `lastRoot` captured here will be out of scope anyway)\n\t\t\t\t\t\tif (!this.midUpgrade && lastRoot !== this.root) {\n\t\t\t\t\t\t\tlastRoot = this.root;\n\t\t\t\t\t\t\tthis.events.emit(\"rootChanged\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tthis.flexTreeViewUnregisterCallbacks.add(\n\t\t\t// Will dispose the old view (if there is one) when its no longer valid, and create a new one if appropriate.\n\t\t\tthis.checkout.storedSchema.events.on(\"afterSchemaChange\", () => this.update()),\n\t\t);\n\n\t\tif (!this.midUpgrade) {\n\t\t\tthis.events.emit(\"schemaChanged\");\n\t\t\tthis.events.emit(\"rootChanged\");\n\t\t}\n\t}\n\n\tprivate runSchemaEdit(edit: () => void): void {\n\t\tthis.midUpgrade = true;\n\t\ttry {\n\t\t\tedit();\n\t\t} finally {\n\t\t\tthis.midUpgrade = false;\n\t\t}\n\t\tthis.events.emit(\"schemaChanged\");\n\t\tthis.events.emit(\"rootChanged\");\n\t}\n\n\tprivate disposeFlexView(): void {\n\t\tconst anchors = this.checkout.forest.anchors;\n\t\tif (this.flexTreeContext !== undefined) {\n\t\t\t// Cleanup any TreeNodes cached in the AnchorSet when disposing the flex-tree which they wrap.\n\t\t\tfor (const anchorNode of anchors) {\n\t\t\t\ttryDisposeTreeNode(anchorNode);\n\t\t\t}\n\n\t\t\tthis.flexTreeContext[disposeSymbol]();\n\t\t\tthis.flexTreeContext = undefined;\n\t\t}\n\t\tthis.flexTreeViewUnregisterCallbacks.forEach((unregister) => unregister());\n\t\tthis.flexTreeViewUnregisterCallbacks.clear();\n\t\tanchors.slots.delete(SimpleContextSlot);\n\t}\n\n\tpublic get compatibility(): SchemaCompatibilityStatus {\n\t\tif (!this.currentCompatibility) {\n\t\t\tthis.failDisposed();\n\t\t}\n\t\treturn this.currentCompatibility;\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.disposeFlexView();\n\t\tthis.unregisterCallbacks.forEach((unregister) => unregister());\n\t\tthis.checkout.forest.anchors.slots.delete(ViewSlot);\n\t\tthis.currentCompatibility = undefined;\n\t\tthis.onDispose?.();\n\t\tif (this.checkout.isBranch && !this.checkout.disposed) {\n\t\t\t// All (non-main) branches are 1:1 with views, so if a user manually disposes a view, we should also dispose the checkout/branch.\n\t\t\tthis.checkout.dispose();\n\t\t}\n\t}\n\n\tpublic get root(): ReadableField<TRootSchema> {\n\t\tthis.breaker.use();\n\t\tif (!this.compatibility.canView) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Document is out of schema. Check TreeView.compatibility before accessing TreeView.root.\",\n\t\t\t);\n\t\t}\n\t\tconst view = this.getFlexTreeContext();\n\t\treturn tryGetTreeNodeForField(view.root) as ReadableField<TRootSchema>;\n\t}\n\n\tpublic set root(newRoot: InsertableField<TRootSchema>) {\n\t\tthis.breaker.use();\n\t\tif (!this.compatibility.canView) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Document is out of schema. Check TreeView.compatibility before accessing TreeView.root.\",\n\t\t\t);\n\t\t}\n\t\tconst view = this.getFlexTreeContext();\n\t\tsetField(view.root, this.rootFieldSchema, newRoot as InsertableContent | undefined);\n\t}\n\n\t// #region Branching\n\n\tpublic fork(): ReturnType<TreeBranch[\"fork\"]> & SchematizingSimpleTreeView<TRootSchema> {\n\t\treturn this.checkout.branch().viewWith(this.config);\n\t}\n\n\tpublic merge(context: TreeBranch, disposeMerged = true): void {\n\t\tthis.checkout.merge(getCheckout(context), disposeMerged);\n\t}\n\n\tpublic rebaseOnto(context: TreeBranch): void {\n\t\tgetCheckout(context).rebase(this.checkout);\n\t}\n\n\t// #endregion Branching\n}\n\n/**\n * Get the {@link TreeCheckout} associated with a given {@link TreeBranch}.\n * @remarks Currently, all contexts are also {@link SchematizingSimpleTreeView}s.\n * Other checkout implementations (e.g. not associated with a view) may be supported in the future.\n */\nexport function getCheckout(context: TreeBranch): TreeCheckout {\n\tif (context instanceof SchematizingSimpleTreeView) {\n\t\treturn context.checkout;\n\t}\n\tthrow new UsageError(\"Unsupported context implementation\");\n}\n\n/**\n * Adds constraints to a `checkout`'s pending transaction.\n *\n * @param checkout - The checkout's who's transaction will have the constraints added to it.\n * @param constraintsOnRevert - If true, use {@link ISharedTreeEditor.addNodeExistsConstraintOnRevert}.\n * @param constraints - The constraints to add to the transaction.\n *\n * @see {@link RunTransactionParams.preconditions}.\n */\nexport function addConstraintsToTransaction(\n\tcheckout: ITreeCheckout,\n\tconstraintsOnRevert: boolean,\n\tconstraints: readonly TransactionConstraint[] = [],\n): void {\n\tfor (const constraint of constraints) {\n\t\tswitch (constraint.type) {\n\t\t\tcase \"nodeInDocument\": {\n\t\t\t\tconst node = getOrCreateInnerNode(constraint.node);\n\t\t\t\tconst nodeStatus = getKernel(constraint.node).getStatus();\n\t\t\t\tif (nodeStatus !== TreeStatus.InDocument) {\n\t\t\t\t\tconst revertText = constraintsOnRevert ? \" on revert\" : \"\";\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`Attempted to add a \"nodeInDocument\" constraint${revertText}, but the node is not currently in the document. Node status: ${nodeStatus}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tassert(node.isHydrated(), 0xbc2 /* In document node must be hydrated. */);\n\t\t\t\tif (constraintsOnRevert) {\n\t\t\t\t\tcheckout.editor.addNodeExistsConstraintOnRevert(node.anchorNode);\n\t\t\t\t} else {\n\t\t\t\t\tcheckout.editor.addNodeExistsConstraint(node.anchorNode);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tunreachableCase(constraint.type);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"schematizingTreeView.js","sourceRoot":"","sources":["../../src/shared-tree/schematizingTreeView.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAM7D,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAEN,mBAAmB,EACnB,qBAAqB,EACrB,UAAU,EACV,OAAO,GACP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAKN,sBAAsB,EACtB,QAAQ,EACR,oBAAoB,EACpB,yBAAyB,EAUzB,oBAAoB,EACpB,SAAS,EAOT,eAAe,EACf,iBAAiB,EACjB,2BAA2B,EAC3B,8BAA8B,EAE9B,kBAAkB,EAClB,gBAAgB,EAChB,0BAA0B,EAC1B,eAAe,EACf,eAAe,GACf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEN,aAAa,EACb,aAAa,GAEb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGtF;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,EAAiC,CAAC;AAEpE;;GAEG;IAEU,0BAA0B;4BADtC,aAAa;;;;;QA4Cb,YACiB,QAAsB,EACtB,MAAsD,EACtD,cAAqC,EACpC,SAAsB;YAHvB,aAAQ,GAAR,QAAQ,CAAc;YACtB,WAAM,GAAN,MAAM,CAAgD;YACtD,mBAAc,GAAd,cAAc,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gBACnD,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;gBAC1D,IAAI,UAAU,KAAK,UAAU,CAAC,UAAU,EAAE,CAAC;oBAC1C,MAAM,UAAU,GAAG,mBAAmB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC3D,MAAM,IAAI,UAAU,CACnB,iDAAiD,UAAU,iEAAiE,UAAU,EAAE,CACxI,CAAC;gBACH,CAAC;gBACD,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,KAAK,CAAC,wCAAwC,CAAC,CAAC;gBAC1E,IAAI,mBAAmB,EAAE,CAAC;oBACzB,QAAQ,CAAC,MAAM,CAAC,+BAA+B,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAClE,CAAC;qBAAM,CAAC;oBACP,QAAQ,CAAC,MAAM,CAAC,uBAAuB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAC1D,CAAC;gBACD,MAAM;YACP,CAAC;YACD;gBACC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type {\n\tHasListeners,\n\tIEmitter,\n\tListenable,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { anchorSlot } from \"../core/index.js\";\nimport {\n\ttype NodeIdentifierManager,\n\tdefaultSchemaPolicy,\n\tcursorForMapTreeField,\n\tTreeStatus,\n\tContext,\n} from \"../feature-libraries/index.js\";\nimport {\n\ttype ImplicitFieldSchema,\n\ttype SchemaCompatibilityStatus,\n\ttype TreeView,\n\ttype TreeViewEvents,\n\ttryGetTreeNodeForField,\n\tsetField,\n\tnormalizeFieldSchema,\n\tSchemaCompatibilityTester,\n\ttype InsertableContent,\n\ttype TreeViewConfiguration,\n\ttype TreeViewAlpha,\n\ttype InsertableField,\n\ttype ReadableField,\n\ttype ReadSchema,\n\ttype UnsafeUnknownSchema,\n\ttype TreeBranch,\n\ttype TreeBranchEvents,\n\tgetOrCreateInnerNode,\n\tgetKernel,\n\ttype VoidTransactionCallbackStatus,\n\ttype TransactionCallbackStatus,\n\ttype TransactionResult,\n\ttype TransactionResultExt,\n\ttype RunTransactionParams,\n\ttype TransactionConstraint,\n\tHydratedContext,\n\tSimpleContextSlot,\n\tareImplicitFieldSchemaEqual,\n\tprepareForInsertionContextless,\n\ttype FieldSchema,\n\ttryDisposeTreeNode,\n\tFieldSchemaAlpha,\n\tTreeViewConfigurationAlpha,\n\ttoInitialSchema,\n\ttoUpgradeSchema,\n} from \"../simple-tree/index.js\";\nimport {\n\ttype Breakable,\n\tbreakingClass,\n\tdisposeSymbol,\n\ttype WithBreakable,\n} from \"../util/index.js\";\n\nimport { canInitialize, initialize, initializerFromChunk } from \"./schematizeTree.js\";\nimport type { ITreeCheckout, TreeCheckout } from \"./treeCheckout.js\";\n\n/**\n * Creating multiple tree views from the same checkout is not supported. This slot is used to detect if one already\n * exists and error if creating a second.\n */\nexport const ViewSlot = anchorSlot<TreeView<ImplicitFieldSchema>>();\n\n/**\n * Implementation of TreeView wrapping a FlexTreeView.\n */\n@breakingClass\nexport class SchematizingSimpleTreeView<\n\tin out TRootSchema extends ImplicitFieldSchema | UnsafeUnknownSchema,\n> implements TreeBranch, TreeViewAlpha<TRootSchema>, WithBreakable\n{\n\t/**\n\t * This is set to undefined when this object is disposed or the view schema does not support viewing the document's stored schema.\n\t *\n\t * The view schema may be incompatible with the stored schema. Use `compatibility` to check.\n\t */\n\tprivate flexTreeContext: Context | undefined;\n\n\t/**\n\t * Undefined iff uninitialized or disposed.\n\t */\n\tprivate currentCompatibility: SchemaCompatibilityStatus | undefined;\n\tpublic readonly events: Listenable<TreeViewEvents & TreeBranchEvents> &\n\t\tIEmitter<TreeViewEvents & TreeBranchEvents> &\n\t\tHasListeners<TreeViewEvents & TreeBranchEvents> = createEmitter();\n\n\tprivate readonly viewSchema: SchemaCompatibilityTester;\n\n\t/**\n\t * Events to unregister upon flex-tree view disposal.\n\t */\n\tprivate readonly flexTreeViewUnregisterCallbacks = new Set<() => void>();\n\n\t/**\n\t * Events to unregister upon disposal.\n\t */\n\tprivate readonly unregisterCallbacks = new Set<() => void>();\n\n\tpublic disposed = false;\n\t/**\n\t * This is set to true while an edit impacting the document schema is in progress.\n\t * This allows suppressing extra rootChanged / schemaChanged events until the edit concludes.\n\t * This is useful especially for some initialization edits, since document initialization can involve transient schemas\n\t * which are implementation details and should not be exposed to the user.\n\t */\n\tprivate midUpgrade = false;\n\n\tprivate readonly rootFieldSchema: FieldSchema;\n\tpublic readonly breaker: Breakable;\n\n\tpublic constructor(\n\t\tpublic readonly checkout: TreeCheckout,\n\t\tpublic readonly config: TreeViewConfiguration<ReadSchema<TRootSchema>>,\n\t\tpublic readonly nodeKeyManager: NodeIdentifierManager,\n\t\tprivate readonly onDispose?: () => void,\n\t) {\n\t\tthis.breaker = checkout.breaker;\n\t\tif (checkout.forest.anchors.slots.has(ViewSlot)) {\n\t\t\tthrow new UsageError(\"Cannot create a second tree view from the same checkout\");\n\t\t}\n\t\tcheckout.forest.anchors.slots.set(ViewSlot, this);\n\n\t\tthis.rootFieldSchema = normalizeFieldSchema(config.schema);\n\n\t\tconst configAlpha = new TreeViewConfigurationAlpha({ schema: config.schema });\n\n\t\tthis.viewSchema = new SchemaCompatibilityTester(configAlpha);\n\t\t// This must be initialized before `update` can be called.\n\t\tthis.currentCompatibility = {\n\t\t\tcanView: false,\n\t\t\tcanUpgrade: true,\n\t\t\tisEquivalent: false,\n\t\t\tcanInitialize: true,\n\t\t};\n\t\tthis.update();\n\n\t\tthis.unregisterCallbacks.add(\n\t\t\tthis.checkout.events.on(\"changed\", (data, getRevertible) => {\n\t\t\t\tthis.events.emit(\"changed\", data, getRevertible);\n\t\t\t\tthis.events.emit(\"commitApplied\", data, getRevertible);\n\t\t\t}),\n\t\t);\n\t}\n\n\tpublic hasRootSchema<TSchema extends ImplicitFieldSchema>(\n\t\tschema: TSchema,\n\t): this is TreeViewAlpha<TSchema> {\n\t\treturn areImplicitFieldSchemaEqual(this.rootFieldSchema, schema);\n\t}\n\n\tpublic get schema(): ReadSchema<TRootSchema> {\n\t\treturn this.config.schema;\n\t}\n\n\tpublic initialize(content: InsertableField<TRootSchema>): void {\n\t\tthis.ensureUndisposed();\n\n\t\tconst compatibility = this.compatibility;\n\t\tif (!compatibility.canInitialize) {\n\t\t\tthrow new UsageError(\"Tree cannot be initialized more than once.\");\n\t\t}\n\n\t\tthis.runSchemaEdit(() => {\n\t\t\tconst schema = toInitialSchema(this.config.schema);\n\t\t\tconst mapTree = prepareForInsertionContextless(\n\t\t\t\tcontent as InsertableContent | undefined,\n\t\t\t\tthis.rootFieldSchema,\n\t\t\t\t{\n\t\t\t\t\tschema,\n\t\t\t\t\tpolicy: defaultSchemaPolicy,\n\t\t\t\t},\n\t\t\t\tthis,\n\t\t\t\tschema.rootFieldSchema,\n\t\t\t);\n\n\t\t\tthis.checkout.transaction.start();\n\n\t\t\tinitialize(\n\t\t\t\tthis.checkout,\n\t\t\t\tschema,\n\t\t\t\tinitializerFromChunk(this.checkout, () => {\n\t\t\t\t\t// This must be done after initial schema is set!\n\t\t\t\t\treturn this.checkout.forest.chunkField(\n\t\t\t\t\t\tcursorForMapTreeField(mapTree === undefined ? [] : [mapTree]),\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t\tthis.checkout.transaction.commit();\n\t\t});\n\t}\n\n\tpublic upgradeSchema(): void {\n\t\tthis.ensureUndisposed();\n\n\t\tconst compatibility = this.compatibility;\n\t\tif (compatibility.isEquivalent) {\n\t\t\t// No-op\n\t\t\treturn;\n\t\t}\n\n\t\tif (!compatibility.canUpgrade) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Existing stored schema cannot be upgraded (see TreeView.compatibility.canUpgrade).\",\n\t\t\t);\n\t\t}\n\n\t\tconst newSchema = toUpgradeSchema(this.viewSchema.viewSchema.root);\n\t\tthis.runSchemaEdit(() => this.checkout.updateSchema(newSchema));\n\t}\n\n\t/**\n\t * Gets the flex-tree context. Throws when disposed or out of schema.\n\t */\n\tpublic getFlexTreeContext(): Context {\n\t\tthis.ensureUndisposed();\n\t\tassert(this.flexTreeContext !== undefined, 0x8c0 /* unexpected getViewOrError */);\n\t\treturn this.flexTreeContext;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-tree#TreeViewAlpha.runTransaction}\n\t */\n\tpublic runTransaction<TSuccessValue, TFailureValue>(\n\t\ttransaction: () => TransactionCallbackStatus<TSuccessValue, TFailureValue>,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResultExt<TSuccessValue, TFailureValue>;\n\t/**\n\t * {@inheritDoc @fluidframework/shared-tree#TreeViewAlpha.runTransaction}\n\t */\n\tpublic runTransaction(\n\t\ttransaction: () => VoidTransactionCallbackStatus | void,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResult;\n\tpublic runTransaction<TSuccessValue, TFailureValue>(\n\t\ttransaction: () =>\n\t\t\t| TransactionCallbackStatus<TSuccessValue, TFailureValue>\n\t\t\t| VoidTransactionCallbackStatus\n\t\t\t| void,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResultExt<TSuccessValue, TFailureValue> | TransactionResult {\n\t\tconst addConstraints = (\n\t\t\tconstraintsOnRevert: boolean,\n\t\t\tconstraints: readonly TransactionConstraint[] = [],\n\t\t): void => {\n\t\t\taddConstraintsToTransaction(this.checkout, constraintsOnRevert, constraints);\n\t\t};\n\n\t\tthis.checkout.transaction.start();\n\n\t\t// Validate preconditions before running the transaction callback.\n\t\taddConstraints(false /* constraintsOnRevert */, params?.preconditions);\n\t\tconst transactionCallbackStatus = transaction();\n\t\tconst rollback = transactionCallbackStatus?.rollback;\n\t\tconst value = (\n\t\t\ttransactionCallbackStatus as TransactionCallbackStatus<TSuccessValue, TFailureValue>\n\t\t)?.value;\n\n\t\tif (rollback === true) {\n\t\t\tthis.checkout.transaction.abort();\n\t\t\treturn value !== undefined\n\t\t\t\t? { success: false, value: value as TFailureValue }\n\t\t\t\t: { success: false };\n\t\t}\n\n\t\t// Validate preconditions on revert after running the transaction callback and was successful.\n\t\taddConstraints(\n\t\t\ttrue /* constraintsOnRevert */,\n\t\t\ttransactionCallbackStatus?.preconditionsOnRevert,\n\t\t);\n\n\t\tthis.checkout.transaction.commit();\n\t\treturn value !== undefined\n\t\t\t? { success: true, value: value as TSuccessValue }\n\t\t\t: { success: true };\n\t}\n\n\tprivate ensureUndisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthis.failDisposed();\n\t\t}\n\t}\n\n\tprivate failDisposed(): never {\n\t\tthrow new UsageError(\"Accessed a disposed TreeView.\");\n\t}\n\n\t/**\n\t * Updates `this.view` and the current compatibility status.\n\t * Invoked during initialization and when `this.view` needs to be replaced due to stored schema changes.\n\t * Handles re-registering for events to call update in the future.\n\t * @remarks\n\t * This does not check if the view needs to be replaced, it replaces it unconditionally:\n\t * callers should do any checking to detect if it's really needed before calling `update`.\n\t * @privateRemarks\n\t * This implementation avoids making any edits, which prevents it from being invoked reentrantly.\n\t * If implicit initialization (or some other edit) is desired, it should be done outside of this method.\n\t */\n\tprivate update(): void {\n\t\tthis.disposeFlexView();\n\n\t\tconst compatibility = this.viewSchema.checkCompatibility(this.checkout.storedSchema);\n\n\t\tthis.currentCompatibility = {\n\t\t\t...compatibility,\n\t\t\tcanInitialize: canInitialize(this.checkout),\n\t\t};\n\n\t\tconst anchors = this.checkout.forest.anchors;\n\t\tconst slots = anchors.slots;\n\n\t\tif (compatibility.canView) {\n\t\t\tthis.flexTreeContext = new Context(\n\t\t\t\tdefaultSchemaPolicy,\n\t\t\t\tthis.checkout,\n\t\t\t\tthis.nodeKeyManager,\n\t\t\t);\n\t\t\tassert(!slots.has(SimpleContextSlot), 0xa47 /* extra simple tree context */);\n\t\t\tassert(\n\t\t\t\tthis.rootFieldSchema instanceof FieldSchemaAlpha,\n\t\t\t\t0xbfa /* all field schema should be FieldSchemaAlpha */,\n\t\t\t);\n\t\t\tslots.set(\n\t\t\t\tSimpleContextSlot,\n\t\t\t\tnew HydratedContext(\n\t\t\t\t\tthis.flexTreeContext,\n\t\t\t\t\tHydratedContext.schemaMapFromRootSchema(\n\t\t\t\t\t\tthis.rootFieldSchema.annotatedAllowedTypesNormalized,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\t// Trigger \"rootChanged\" events if the root changes in the future.\n\t\t\t{\n\t\t\t\t// Currently there is no good way to do this as FlexTreeField has no events for changes.\n\t\t\t\t// this.root.on(????)\n\t\t\t\t// As a workaround for the above, trigger \"rootChanged\" in \"afterBatch\".\n\t\t\t\t// Ideally these events would be just events for changes within the root.\n\t\t\t\t// TODO: provide a better event: this.view.flexTree.on(????) and/or integrate with with the normal event code paths.\n\n\t\t\t\t// Track what the root was before to be able to detect changes.\n\t\t\t\tlet lastRoot: ReadableField<TRootSchema> = this.root;\n\n\t\t\t\tthis.flexTreeViewUnregisterCallbacks.add(\n\t\t\t\t\tthis.checkout.events.on(\"afterBatch\", () => {\n\t\t\t\t\t\t// In the initialization flow, this event is raised before the correct compatibility w.r.t the new schema is calculated.\n\t\t\t\t\t\t// Accessing `this.root` in that case can throw. It's OK to ignore this because:\n\t\t\t\t\t\t// - The rootChanged event will already be raised at the end of the current upgrade\n\t\t\t\t\t\t// - It doesn't matter that `lastRoot` isn't updated in this case, because `update` will be called again before the upgrade\n\t\t\t\t\t\t// completes (at which point this callback and the `lastRoot` captured here will be out of scope anyway)\n\t\t\t\t\t\tif (!this.midUpgrade && lastRoot !== this.root) {\n\t\t\t\t\t\t\tlastRoot = this.root;\n\t\t\t\t\t\t\tthis.events.emit(\"rootChanged\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tthis.flexTreeViewUnregisterCallbacks.add(\n\t\t\t// Will dispose the old view (if there is one) when its no longer valid, and create a new one if appropriate.\n\t\t\tthis.checkout.storedSchema.events.on(\"afterSchemaChange\", () => this.update()),\n\t\t);\n\n\t\tif (!this.midUpgrade) {\n\t\t\tthis.events.emit(\"schemaChanged\");\n\t\t\tthis.events.emit(\"rootChanged\");\n\t\t}\n\t}\n\n\tprivate runSchemaEdit(edit: () => void): void {\n\t\tthis.midUpgrade = true;\n\t\ttry {\n\t\t\tedit();\n\t\t} finally {\n\t\t\tthis.midUpgrade = false;\n\t\t}\n\t\tthis.events.emit(\"schemaChanged\");\n\t\tthis.events.emit(\"rootChanged\");\n\t}\n\n\tprivate disposeFlexView(): void {\n\t\tconst anchors = this.checkout.forest.anchors;\n\t\tif (this.flexTreeContext !== undefined) {\n\t\t\t// Cleanup any TreeNodes cached in the AnchorSet when disposing the flex-tree which they wrap.\n\t\t\tfor (const anchorNode of anchors) {\n\t\t\t\ttryDisposeTreeNode(anchorNode);\n\t\t\t}\n\n\t\t\tthis.flexTreeContext[disposeSymbol]();\n\t\t\tthis.flexTreeContext = undefined;\n\t\t}\n\t\tthis.flexTreeViewUnregisterCallbacks.forEach((unregister) => unregister());\n\t\tthis.flexTreeViewUnregisterCallbacks.clear();\n\t\tanchors.slots.delete(SimpleContextSlot);\n\t}\n\n\tpublic get compatibility(): SchemaCompatibilityStatus {\n\t\tif (!this.currentCompatibility) {\n\t\t\tthis.failDisposed();\n\t\t}\n\t\treturn this.currentCompatibility;\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.disposeFlexView();\n\t\tthis.unregisterCallbacks.forEach((unregister) => unregister());\n\t\tthis.checkout.forest.anchors.slots.delete(ViewSlot);\n\t\tthis.currentCompatibility = undefined;\n\t\tthis.onDispose?.();\n\t\tif (this.checkout.isBranch && !this.checkout.disposed) {\n\t\t\t// All (non-main) branches are 1:1 with views, so if a user manually disposes a view, we should also dispose the checkout/branch.\n\t\t\tthis.checkout.dispose();\n\t\t}\n\t}\n\n\tpublic get root(): ReadableField<TRootSchema> {\n\t\tthis.breaker.use();\n\t\tif (!this.compatibility.canView) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Document is out of schema. Check TreeView.compatibility before accessing TreeView.root.\",\n\t\t\t);\n\t\t}\n\t\tconst view = this.getFlexTreeContext();\n\t\treturn tryGetTreeNodeForField(view.root) as ReadableField<TRootSchema>;\n\t}\n\n\tpublic set root(newRoot: InsertableField<TRootSchema>) {\n\t\tthis.breaker.use();\n\t\tif (!this.compatibility.canView) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Document is out of schema. Check TreeView.compatibility before accessing TreeView.root.\",\n\t\t\t);\n\t\t}\n\t\tconst view = this.getFlexTreeContext();\n\t\tsetField(\n\t\t\tview.root,\n\t\t\tthis.rootFieldSchema,\n\t\t\tnewRoot as InsertableContent | undefined,\n\t\t\tthis.checkout.storedSchema.rootFieldSchema,\n\t\t);\n\t}\n\n\t// #region Branching\n\n\tpublic fork(): ReturnType<TreeBranch[\"fork\"]> & SchematizingSimpleTreeView<TRootSchema> {\n\t\treturn this.checkout.branch().viewWith(this.config);\n\t}\n\n\tpublic merge(context: TreeBranch, disposeMerged = true): void {\n\t\tthis.checkout.merge(getCheckout(context), disposeMerged);\n\t}\n\n\tpublic rebaseOnto(context: TreeBranch): void {\n\t\tgetCheckout(context).rebase(this.checkout);\n\t}\n\n\t// #endregion Branching\n}\n\n/**\n * Get the {@link TreeCheckout} associated with a given {@link TreeBranch}.\n * @remarks Currently, all contexts are also {@link SchematizingSimpleTreeView}s.\n * Other checkout implementations (e.g. not associated with a view) may be supported in the future.\n */\nexport function getCheckout(context: TreeBranch): TreeCheckout {\n\tif (context instanceof SchematizingSimpleTreeView) {\n\t\treturn context.checkout;\n\t}\n\tthrow new UsageError(\"Unsupported context implementation\");\n}\n\n/**\n * Adds constraints to a `checkout`'s pending transaction.\n *\n * @param checkout - The checkout's who's transaction will have the constraints added to it.\n * @param constraintsOnRevert - If true, use {@link ISharedTreeEditor.addNodeExistsConstraintOnRevert}.\n * @param constraints - The constraints to add to the transaction.\n *\n * @see {@link RunTransactionParams.preconditions}.\n */\nexport function addConstraintsToTransaction(\n\tcheckout: ITreeCheckout,\n\tconstraintsOnRevert: boolean,\n\tconstraints: readonly TransactionConstraint[] = [],\n): void {\n\tfor (const constraint of constraints) {\n\t\tswitch (constraint.type) {\n\t\t\tcase \"nodeInDocument\": {\n\t\t\t\tconst node = getOrCreateInnerNode(constraint.node);\n\t\t\t\tconst nodeStatus = getKernel(constraint.node).getStatus();\n\t\t\t\tif (nodeStatus !== TreeStatus.InDocument) {\n\t\t\t\t\tconst revertText = constraintsOnRevert ? \" on revert\" : \"\";\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`Attempted to add a \"nodeInDocument\" constraint${revertText}, but the node is not currently in the document. Node status: ${nodeStatus}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tassert(node.isHydrated(), 0xbc2 /* In document node must be hydrated. */);\n\t\t\t\tif (constraintsOnRevert) {\n\t\t\t\t\tcheckout.editor.addNodeExistsConstraintOnRevert(node.anchorNode);\n\t\t\t\t} else {\n\t\t\t\t\tcheckout.editor.addNodeExistsConstraint(node.anchorNode);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tunreachableCase(constraint.type);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treeAlpha.d.ts","sourceRoot":"","sources":["../../src/shared-tree/treeAlpha.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,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Q,GAAG,aAAa,CAAC,CAAC,CAAC;CAC7E;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,EAAE,SA+RvB,CAAC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { assert, debugAssert, fail, unreachableCase, } from "@fluidframework/core-utils/internal";
|
|
6
6
|
import { createIdCompressor } from "@fluidframework/id-compressor/internal";
|
|
7
7
|
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
8
|
-
import { asIndex, getKernel, TreeBeta, tryGetSchema, createFromCursor, FieldKind, normalizeFieldSchema, conciseFromCursor, applySchemaToParserOptions, cursorFromVerbose, verboseFromCursor,
|
|
8
|
+
import { asIndex, getKernel, TreeBeta, tryGetSchema, createFromCursor, FieldKind, normalizeFieldSchema, conciseFromCursor, applySchemaToParserOptions, cursorFromVerbose, verboseFromCursor, extractPersistedSchema, TreeViewConfigurationAlpha, getStoredKey, getPropertyKeyFromStoredKey, treeNodeApi, getIdentifierFromNode, unhydratedFlexTreeFromInsertable, getOrCreateNodeFromInnerNode, getOrCreateNodeFromInnerUnboxedNode, getOrCreateInnerNode, NodeKind, tryGetTreeNodeForField, isObjectNodeSchema, isTreeNode, toInitialSchema, convertField, toUnhydratedSchema, } from "../simple-tree/index.js";
|
|
9
9
|
import { brand, extractFromOpaque } from "../util/index.js";
|
|
10
10
|
import { FluidClientVersion, noopValidator, } from "../codec/index.js";
|
|
11
11
|
import { EmptyKey } from "../core/index.js";
|
|
@@ -78,7 +78,7 @@ export const TreeAlpha = {
|
|
|
78
78
|
return undefined;
|
|
79
79
|
}
|
|
80
80
|
const cursor = cursorFromVerbose(data, schemalessConfig);
|
|
81
|
-
return createFromCursor(schema, cursor);
|
|
81
|
+
return createFromCursor(schema, cursor, convertField(normalizeFieldSchema(schema), toUnhydratedSchema));
|
|
82
82
|
},
|
|
83
83
|
exportConcise,
|
|
84
84
|
exportVerbose(node, options) {
|
|
@@ -98,11 +98,16 @@ export const TreeAlpha = {
|
|
|
98
98
|
const batch = [cursor];
|
|
99
99
|
// If none provided, create a compressor which will not compress anything.
|
|
100
100
|
const idCompressor = options.idCompressor ?? createIdCompressor();
|
|
101
|
+
// Grabbing an existing stored schema from the node is important to ensure that unknown optional fields can be preserved.
|
|
102
|
+
// Note that if the node is unhydrated, this can result in all staged allowed types being included in the schema, which might be undesired.
|
|
103
|
+
const storedSchema = isTreeNode(node)
|
|
104
|
+
? getKernel(node).context.flexContext.schema
|
|
105
|
+
: toInitialSchema(schema);
|
|
101
106
|
const context = {
|
|
102
107
|
encodeType: TreeCompressionStrategy.Compressed,
|
|
103
108
|
idCompressor,
|
|
104
109
|
originatorId: idCompressor.localSessionId, // TODO: Why is this needed?
|
|
105
|
-
schema: { schema:
|
|
110
|
+
schema: { schema: storedSchema, policy: defaultSchemaPolicy },
|
|
106
111
|
};
|
|
107
112
|
const result = codec.encode(batch, context);
|
|
108
113
|
return result;
|
|
@@ -111,7 +116,8 @@ export const TreeAlpha = {
|
|
|
111
116
|
const config = new TreeViewConfigurationAlpha({ schema });
|
|
112
117
|
const content = {
|
|
113
118
|
// Always use a v1 schema codec for consistency.
|
|
114
|
-
|
|
119
|
+
// TODO: reevaluate how staged schema should behave in schema import/export APIs before stabilizing this.
|
|
120
|
+
schema: extractPersistedSchema(config.schema, FluidClientVersion.v2_0, () => true),
|
|
115
121
|
tree: compressedData,
|
|
116
122
|
idCompressor: options.idCompressor ?? createIdCompressor(),
|
|
117
123
|
};
|