@fluidframework/tree 2.62.0 → 2.63.0-359286
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 +4 -0
- package/api-report/tree.alpha.api.md +31 -5
- package/api-report/tree.beta.api.md +26 -0
- package/api-report/tree.legacy.beta.api.md +26 -0
- package/dist/alpha.d.ts +4 -3
- package/dist/beta.d.ts +3 -0
- package/dist/codec/codec.d.ts +32 -0
- package/dist/codec/codec.d.ts.map +1 -1
- package/dist/codec/codec.js +32 -1
- package/dist/codec/codec.js.map +1 -1
- package/dist/codec/index.d.ts +1 -1
- package/dist/codec/index.d.ts.map +1 -1
- package/dist/codec/index.js +3 -1
- package/dist/codec/index.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +4 -3
- package/dist/core/index.js.map +1 -1
- package/dist/core/schema-stored/index.d.ts +1 -1
- package/dist/core/schema-stored/index.d.ts.map +1 -1
- package/dist/core/schema-stored/index.js.map +1 -1
- package/dist/core/schema-stored/schema.d.ts +5 -7
- package/dist/core/schema-stored/schema.d.ts.map +1 -1
- package/dist/core/schema-stored/schema.js +3 -6
- package/dist/core/schema-stored/schema.js.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecs.d.ts +4 -1
- package/dist/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecs.js +5 -1
- package/dist/core/tree/detachedFieldIndexCodecs.js.map +1 -1
- package/dist/core/tree/index.d.ts +1 -0
- package/dist/core/tree/index.d.ts.map +1 -1
- package/dist/core/tree/index.js +3 -1
- package/dist/core/tree/index.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +3 -2
- package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.js +5 -1
- package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format.d.ts +2 -0
- package/dist/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/index.d.ts +2 -2
- package/dist/feature-libraries/chunked-forest/codec/index.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/index.js +2 -1
- package/dist/feature-libraries/chunked-forest/codec/index.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/index.d.ts +1 -1
- package/dist/feature-libraries/chunked-forest/index.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/index.js +2 -1
- package/dist/feature-libraries/chunked-forest/index.js.map +1 -1
- package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts +5 -1
- package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/defaultFieldKinds.js +19 -5
- package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
- package/dist/feature-libraries/default-schema/index.d.ts +1 -1
- package/dist/feature-libraries/default-schema/index.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/index.js +2 -1
- package/dist/feature-libraries/default-schema/index.js.map +1 -1
- package/dist/feature-libraries/forest-summary/codec.d.ts +4 -1
- package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/codec.js +5 -1
- package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
- package/dist/feature-libraries/forest-summary/index.d.ts +1 -0
- package/dist/feature-libraries/forest-summary/index.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/index.js +3 -1
- package/dist/feature-libraries/forest-summary/index.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +5 -5
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +7 -2
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/dist/feature-libraries/schema-edits/index.d.ts +1 -1
- package/dist/feature-libraries/schema-edits/index.d.ts.map +1 -1
- package/dist/feature-libraries/schema-edits/index.js +2 -1
- package/dist/feature-libraries/schema-edits/index.js.map +1 -1
- package/dist/feature-libraries/schema-edits/schemaChangeCodecs.d.ts +4 -1
- package/dist/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
- package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js +9 -1
- package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
- package/dist/feature-libraries/schema-index/codec.d.ts +2 -1
- package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
- package/dist/feature-libraries/schema-index/codec.js +5 -1
- package/dist/feature-libraries/schema-index/codec.js.map +1 -1
- package/dist/feature-libraries/schema-index/index.d.ts +1 -1
- package/dist/feature-libraries/schema-index/index.d.ts.map +1 -1
- package/dist/feature-libraries/schema-index/index.js +2 -1
- package/dist/feature-libraries/schema-index/index.js.map +1 -1
- package/dist/legacy.d.ts +3 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/serializableDomainSchema.d.ts +12 -16
- package/dist/serializableDomainSchema.d.ts.map +1 -1
- package/dist/serializableDomainSchema.js +8 -8
- package/dist/serializableDomainSchema.js.map +1 -1
- package/dist/shared-tree/index.d.ts +2 -1
- package/dist/shared-tree/index.d.ts.map +1 -1
- package/dist/shared-tree/index.js +4 -1
- package/dist/shared-tree/index.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +18 -2
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +122 -8
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/sharedTreeChangeCodecs.d.ts +17 -2
- package/dist/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
- package/dist/shared-tree/sharedTreeChangeCodecs.js +31 -18
- package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/defaultResubmitMachine.d.ts +7 -12
- package/dist/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
- package/dist/shared-tree-core/defaultResubmitMachine.js +53 -73
- package/dist/shared-tree-core/defaultResubmitMachine.js.map +1 -1
- package/dist/shared-tree-core/editManager.js +8 -4
- package/dist/shared-tree-core/editManager.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecs.d.ts +7 -4
- package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerCodecs.js +42 -11
- package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
- package/dist/shared-tree-core/index.d.ts +2 -1
- package/dist/shared-tree-core/index.d.ts.map +1 -1
- package/dist/shared-tree-core/index.js +6 -1
- package/dist/shared-tree-core/index.js.map +1 -1
- package/dist/shared-tree-core/messageCodecs.d.ts +7 -4
- package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
- package/dist/shared-tree-core/messageCodecs.js +44 -23
- package/dist/shared-tree-core/messageCodecs.js.map +1 -1
- package/dist/shared-tree-core/resubmitMachine.d.ts +9 -18
- package/dist/shared-tree-core/resubmitMachine.d.ts.map +1 -1
- package/dist/shared-tree-core/resubmitMachine.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts +6 -4
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +12 -13
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +7 -166
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.js +11 -44
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryBeta.d.ts +90 -1
- package/dist/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryBeta.js +55 -0
- package/dist/simple-tree/api/schemaFactoryBeta.js.map +1 -1
- package/dist/simple-tree/api/treeBeta.d.ts +12 -2
- package/dist/simple-tree/api/treeBeta.d.ts.map +1 -1
- package/dist/simple-tree/api/treeBeta.js +6 -0
- package/dist/simple-tree/api/treeBeta.js.map +1 -1
- package/dist/simple-tree/api/typesUnsafe.d.ts +1 -1
- package/dist/simple-tree/api/typesUnsafe.js.map +1 -1
- package/dist/simple-tree/core/treeNode.d.ts +3 -2
- package/dist/simple-tree/core/treeNode.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNode.js +3 -2
- package/dist/simple-tree/core/treeNode.js.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts +2 -2
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
- package/dist/util/brand.d.ts +1 -1
- package/dist/util/brand.js.map +1 -1
- package/docs/main/compatibility.md +8 -0
- package/lib/alpha.d.ts +4 -3
- package/lib/beta.d.ts +3 -0
- package/lib/codec/codec.d.ts +32 -0
- package/lib/codec/codec.d.ts.map +1 -1
- package/lib/codec/codec.js +28 -0
- package/lib/codec/codec.js.map +1 -1
- package/lib/codec/index.d.ts +1 -1
- package/lib/codec/index.d.ts.map +1 -1
- package/lib/codec/index.js +1 -1
- package/lib/codec/index.js.map +1 -1
- package/lib/core/index.d.ts +2 -2
- package/lib/core/index.d.ts.map +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/schema-stored/index.d.ts +1 -1
- package/lib/core/schema-stored/index.d.ts.map +1 -1
- package/lib/core/schema-stored/index.js.map +1 -1
- package/lib/core/schema-stored/schema.d.ts +5 -7
- package/lib/core/schema-stored/schema.d.ts.map +1 -1
- package/lib/core/schema-stored/schema.js +3 -6
- package/lib/core/schema-stored/schema.js.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecs.d.ts +4 -1
- package/lib/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecs.js +3 -0
- package/lib/core/tree/detachedFieldIndexCodecs.js.map +1 -1
- package/lib/core/tree/index.d.ts +1 -0
- package/lib/core/tree/index.d.ts.map +1 -1
- package/lib/core/tree/index.js +1 -0
- package/lib/core/tree/index.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +3 -2
- package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/codecs.js +3 -0
- package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format.d.ts +2 -0
- package/lib/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/index.d.ts +2 -2
- package/lib/feature-libraries/chunked-forest/codec/index.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/index.js +1 -1
- package/lib/feature-libraries/chunked-forest/codec/index.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/index.d.ts +1 -1
- package/lib/feature-libraries/chunked-forest/index.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/index.js +1 -1
- package/lib/feature-libraries/chunked-forest/index.js.map +1 -1
- package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts +5 -1
- package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/defaultFieldKinds.js +17 -4
- package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
- package/lib/feature-libraries/default-schema/index.d.ts +1 -1
- package/lib/feature-libraries/default-schema/index.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/index.js +1 -1
- package/lib/feature-libraries/default-schema/index.js.map +1 -1
- package/lib/feature-libraries/forest-summary/codec.d.ts +4 -1
- package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/codec.js +3 -0
- package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
- package/lib/feature-libraries/forest-summary/index.d.ts +1 -0
- package/lib/feature-libraries/forest-summary/index.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/index.js +1 -0
- package/lib/feature-libraries/forest-summary/index.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +5 -5
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +5 -5
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
- package/lib/feature-libraries/schema-edits/index.d.ts +1 -1
- package/lib/feature-libraries/schema-edits/index.d.ts.map +1 -1
- package/lib/feature-libraries/schema-edits/index.js +1 -1
- package/lib/feature-libraries/schema-edits/index.js.map +1 -1
- package/lib/feature-libraries/schema-edits/schemaChangeCodecs.d.ts +4 -1
- package/lib/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
- package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js +8 -1
- package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
- package/lib/feature-libraries/schema-index/codec.d.ts +2 -1
- package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
- package/lib/feature-libraries/schema-index/codec.js +3 -0
- package/lib/feature-libraries/schema-index/codec.js.map +1 -1
- package/lib/feature-libraries/schema-index/index.d.ts +1 -1
- package/lib/feature-libraries/schema-index/index.d.ts.map +1 -1
- package/lib/feature-libraries/schema-index/index.js +1 -1
- package/lib/feature-libraries/schema-index/index.js.map +1 -1
- package/lib/legacy.d.ts +3 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/serializableDomainSchema.d.ts +12 -16
- package/lib/serializableDomainSchema.d.ts.map +1 -1
- package/lib/serializableDomainSchema.js +9 -9
- package/lib/serializableDomainSchema.js.map +1 -1
- package/lib/shared-tree/index.d.ts +2 -1
- package/lib/shared-tree/index.d.ts.map +1 -1
- package/lib/shared-tree/index.js +2 -1
- package/lib/shared-tree/index.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +18 -2
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +126 -13
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/sharedTreeChangeCodecs.d.ts +17 -2
- package/lib/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
- package/lib/shared-tree/sharedTreeChangeCodecs.js +30 -18
- package/lib/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/defaultResubmitMachine.d.ts +7 -12
- package/lib/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
- package/lib/shared-tree-core/defaultResubmitMachine.js +55 -75
- package/lib/shared-tree-core/defaultResubmitMachine.js.map +1 -1
- package/lib/shared-tree-core/editManager.js +8 -4
- package/lib/shared-tree-core/editManager.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecs.d.ts +7 -4
- package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerCodecs.js +40 -10
- package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
- package/lib/shared-tree-core/index.d.ts +2 -1
- package/lib/shared-tree-core/index.d.ts.map +1 -1
- package/lib/shared-tree-core/index.js +2 -1
- package/lib/shared-tree-core/index.js.map +1 -1
- package/lib/shared-tree-core/messageCodecs.d.ts +7 -4
- package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
- package/lib/shared-tree-core/messageCodecs.js +42 -22
- package/lib/shared-tree-core/messageCodecs.js.map +1 -1
- package/lib/shared-tree-core/resubmitMachine.d.ts +9 -18
- package/lib/shared-tree-core/resubmitMachine.d.ts.map +1 -1
- package/lib/shared-tree-core/resubmitMachine.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts +6 -4
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +13 -14
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +7 -166
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.js +12 -45
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryBeta.d.ts +90 -1
- package/lib/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryBeta.js +56 -1
- package/lib/simple-tree/api/schemaFactoryBeta.js.map +1 -1
- package/lib/simple-tree/api/treeBeta.d.ts +12 -2
- package/lib/simple-tree/api/treeBeta.d.ts.map +1 -1
- package/lib/simple-tree/api/treeBeta.js +7 -1
- package/lib/simple-tree/api/treeBeta.js.map +1 -1
- package/lib/simple-tree/api/typesUnsafe.d.ts +1 -1
- package/lib/simple-tree/api/typesUnsafe.js.map +1 -1
- package/lib/simple-tree/core/treeNode.d.ts +3 -2
- package/lib/simple-tree/core/treeNode.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNode.js +3 -2
- package/lib/simple-tree/core/treeNode.js.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts +2 -2
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
- package/lib/util/brand.d.ts +1 -1
- package/lib/util/brand.js.map +1 -1
- package/package.json +21 -21
- package/src/codec/codec.ts +60 -0
- package/src/codec/index.ts +3 -0
- package/src/core/index.ts +3 -0
- package/src/core/schema-stored/index.ts +1 -0
- package/src/core/schema-stored/schema.ts +5 -6
- package/src/core/tree/detachedFieldIndexCodecs.ts +9 -0
- package/src/core/tree/index.ts +6 -0
- package/src/feature-libraries/chunked-forest/codec/codecs.ts +6 -1
- package/src/feature-libraries/chunked-forest/codec/format.ts +2 -0
- package/src/feature-libraries/chunked-forest/codec/index.ts +2 -1
- package/src/feature-libraries/chunked-forest/index.ts +2 -0
- package/src/feature-libraries/default-schema/defaultFieldKinds.ts +29 -5
- package/src/feature-libraries/default-schema/index.ts +2 -0
- package/src/feature-libraries/forest-summary/codec.ts +7 -0
- package/src/feature-libraries/forest-summary/index.ts +1 -0
- package/src/feature-libraries/index.ts +12 -1
- package/src/feature-libraries/modular-schema/modularChangeFamily.ts +1 -1
- package/src/feature-libraries/schema-edits/index.ts +5 -1
- package/src/feature-libraries/schema-edits/schemaChangeCodecs.ts +17 -1
- package/src/feature-libraries/schema-index/codec.ts +5 -0
- package/src/feature-libraries/schema-index/index.ts +1 -0
- package/src/packageVersion.ts +1 -1
- package/src/serializableDomainSchema.ts +12 -11
- package/src/shared-tree/index.ts +6 -0
- package/src/shared-tree/sharedTree.ts +151 -11
- package/src/shared-tree/sharedTreeChangeCodecs.ts +68 -30
- package/src/shared-tree/treeCheckout.ts +1 -1
- package/src/shared-tree-core/defaultResubmitMachine.ts +77 -120
- package/src/shared-tree-core/editManager.ts +10 -4
- package/src/shared-tree-core/editManagerCodecs.ts +62 -9
- package/src/shared-tree-core/index.ts +12 -1
- package/src/shared-tree-core/messageCodecs.ts +70 -27
- package/src/shared-tree-core/resubmitMachine.ts +12 -20
- package/src/shared-tree-core/sharedTreeCore.ts +26 -18
- package/src/simple-tree/api/schemaFactoryAlpha.ts +16 -296
- package/src/simple-tree/api/schemaFactoryBeta.ts +269 -1
- package/src/simple-tree/api/treeBeta.ts +36 -1
- package/src/simple-tree/api/typesUnsafe.ts +1 -1
- package/src/simple-tree/core/treeNode.ts +3 -2
- package/src/simple-tree/core/treeNodeKernel.ts +1 -1
- package/src/simple-tree/node-kinds/record/recordNodeTypes.ts +2 -2
- package/src/util/brand.ts +1 -1
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { type ArrayNodeCustomizableSchema, type MapNodeCustomizableSchema, type ObjectNodeSchema, type RecordNodeCustomizableSchema
|
|
5
|
+
import { type ArrayNodeCustomizableSchema, type MapNodeCustomizableSchema, type ObjectNodeSchema, type RecordNodeCustomizableSchema } from "../node-kinds/index.js";
|
|
6
6
|
import { type NodeSchemaOptionsAlpha, type SchemaFactoryObjectOptions, type ScopedSchemaName } from "./schemaFactory.js";
|
|
7
7
|
import type { ImplicitAnnotatedFieldSchema } from "../fieldSchema.js";
|
|
8
8
|
import type { RestrictiveStringRecord } from "../../util/index.js";
|
|
9
|
-
import type { NodeKind, TreeNodeSchema, TreeNodeSchemaClass,
|
|
9
|
+
import type { NodeKind, TreeNodeSchema, TreeNodeSchemaClass, ImplicitAllowedTypes, ImplicitAnnotatedAllowedTypes, AnnotatedAllowedType, LazyItem, WithType } from "../core/index.js";
|
|
10
10
|
import type { ArrayNodeCustomizableSchemaUnsafe, MapNodeCustomizableSchemaUnsafe, System_Unsafe, TreeRecordNodeUnsafe } from "./typesUnsafe.js";
|
|
11
11
|
import type { SimpleObjectNodeSchema } from "../simpleSchema.js";
|
|
12
12
|
import { SchemaFactoryBeta } from "./schemaFactoryBeta.js";
|
|
@@ -26,8 +26,9 @@ export interface SchemaStaticsAlpha {
|
|
|
26
26
|
* Declares a staged type in a set of {@link AllowedTypes}.
|
|
27
27
|
*
|
|
28
28
|
* @remarks
|
|
29
|
-
* Staged allowed types add support for loading documents which may
|
|
29
|
+
* Staged allowed types add support for loading documents which may contain that type at the declared location.
|
|
30
30
|
* This allows for an incremental rollout of a schema change to add a {@link TreeNodeSchema} to an {@link AllowedTypes} without breaking cross version collaboration.
|
|
31
|
+
* A guide on this process can be found here: https://fluidframework.com/docs/data-structures/tree/schema-evolution/allowed-types-rollout
|
|
31
32
|
*
|
|
32
33
|
* Once enough clients have the type staged (and thus can read documents which allow it), documents can start being created and upgraded to allow the staged type.
|
|
33
34
|
* This is done by deploying a new version of the app which removes the `staged` wrapper around the allowed type in the the schema definition.
|
|
@@ -38,107 +39,17 @@ export interface SchemaStaticsAlpha {
|
|
|
38
39
|
* 1. {@link TreeView.initialize} will omit the staged allowed type from the newly created stored schema.
|
|
39
40
|
* 2. {@link TreeView.upgradeSchema} will omit the staged allowed type from the the upgraded stored schema.
|
|
40
41
|
* 3. When evaluating {@link TreeView.compatibility}, it will be viewable even if the staged allowed type is not present in the stored schema's corresponding allowed types.
|
|
41
|
-
* 4. Because of the above, it is possible to get errors when inserting content which uses the staged allowed type
|
|
42
|
+
* 4. Because of the above, it is possible to get errors when inserting content which uses the staged allowed type into a tree whose stored schema does not permit it.
|
|
42
43
|
*
|
|
43
44
|
* Currently, `staged` is not supported in the recursive type APIs: this is a known limitation which future versions of the API will address.
|
|
44
45
|
*
|
|
45
46
|
* @example
|
|
46
|
-
*
|
|
47
|
+
* A full code example of the schema migration process can be found in our {@link https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/test/simple-tree/api/stagedSchemaUpgrade.spec.ts | tests}.
|
|
47
48
|
*
|
|
48
|
-
* The first change is to used to mark the new type as staged, replacing `A` in the schema with `[A, SchemaStaticsAlpha.staged(B)]`.
|
|
49
|
-
* Once this is done, and any code which reads contents from documents is updated to handle any `B` content that may be present, this version of the code can be deployed.
|
|
50
|
-
*
|
|
51
|
-
* Once all users have the above changes, the schema can be updated again to `[A, B]`, and the app can be updated to allow creating of `B` content.
|
|
52
|
-
* This updated version of the app will need to call {@link TreeView.upgradeSchema} when opening documents created by earlier versions.
|
|
53
|
-
*
|
|
54
|
-
* Adding a `B` schema as an option in the root could look like this:
|
|
55
|
-
* ```typescript
|
|
56
|
-
* const factory = new SchemaFactoryAlpha("test");
|
|
57
|
-
* class A extends factory.objectAlpha("A", {}) {}
|
|
58
|
-
* class B extends factory.objectAlpha("B", {}) {}
|
|
59
|
-
*
|
|
60
|
-
* // Does not support B
|
|
61
|
-
* const configBefore = new TreeViewConfigurationAlpha({
|
|
62
|
-
* schema: A,
|
|
63
|
-
* });
|
|
64
|
-
*
|
|
65
|
-
* // Supports documents with or without B
|
|
66
|
-
* const configStaged = new TreeViewConfigurationAlpha({
|
|
67
|
-
* // Adds staged support for B.
|
|
68
|
-
* // Currently this requires wrapping the root field with `SchemaFactoryAlpha.required`:
|
|
69
|
-
* // this is normally implicitly included, but is currently required while the "staged" APIs are `@alpha`.
|
|
70
|
-
* schema: SchemaFactoryAlpha.required([A, SchemaFactoryAlpha.staged(B)]),
|
|
71
|
-
* });
|
|
72
|
-
*
|
|
73
|
-
* // Only supports documents with A and B: can be used to upgrade schema to add B.
|
|
74
|
-
* const configAfter = new TreeViewConfigurationAlpha({
|
|
75
|
-
* schema: [A, B],
|
|
76
|
-
* });
|
|
77
|
-
* ```
|
|
78
|
-
* @example
|
|
79
|
-
* Below is a full example of how the schema migration process works.
|
|
80
|
-
* This can also be found in our {@link https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/test/simple-tree/api/stagedSchemaUpgrade.spec.ts | tests}.
|
|
81
|
-
* ```typescript
|
|
82
|
-
* // Schema A: only number allowed
|
|
83
|
-
* const schemaA = SchemaFactoryAlpha.optional([SchemaFactoryAlpha.number]);
|
|
84
|
-
*
|
|
85
|
-
* // Schema B: number or string (string is staged)
|
|
86
|
-
* const schemaB = SchemaFactoryAlpha.optional([
|
|
87
|
-
* SchemaFactoryAlpha.number,
|
|
88
|
-
* SchemaFactoryAlpha.staged(SchemaFactoryAlpha.string),
|
|
89
|
-
* ]);
|
|
90
|
-
*
|
|
91
|
-
* // Schema C: number or string, both fully allowed
|
|
92
|
-
* const schemaC = SchemaFactoryAlpha.optional([
|
|
93
|
-
* SchemaFactoryAlpha.number,
|
|
94
|
-
* SchemaFactoryAlpha.string,
|
|
95
|
-
* ]);
|
|
96
|
-
*
|
|
97
|
-
* // Initialize with schema A.
|
|
98
|
-
* const configA = new TreeViewConfiguration({
|
|
99
|
-
* schema: schemaA,
|
|
100
|
-
* });
|
|
101
|
-
* const viewA = treeA.viewWith(configA);
|
|
102
|
-
* viewA.initialize(5);
|
|
103
|
-
*
|
|
104
|
-
* // Since we are running all the different versions of the app in the same process making changes synchronously,
|
|
105
|
-
* // an explicit flush is needed to make them available to each other.
|
|
106
|
-
* synchronizeTrees();
|
|
107
|
-
*
|
|
108
|
-
* assert.deepEqual(viewA.root, 5);
|
|
109
|
-
*
|
|
110
|
-
* // View the same document with a second tree using schema B.
|
|
111
|
-
* const configB = new TreeViewConfiguration({
|
|
112
|
-
* schema: schemaB,
|
|
113
|
-
* });
|
|
114
|
-
* const viewB = treeB.viewWith(configB);
|
|
115
|
-
* // B cannot write strings to the root.
|
|
116
|
-
* assert.throws(() => (viewB.root = "test"));
|
|
117
|
-
*
|
|
118
|
-
* // View the same document with a third tree using schema C.
|
|
119
|
-
* const configC = new TreeViewConfiguration({
|
|
120
|
-
* schema: schemaC,
|
|
121
|
-
* });
|
|
122
|
-
* const viewC = treeC.viewWith(configC);
|
|
123
|
-
* // Upgrade to schema C
|
|
124
|
-
* viewC.upgradeSchema();
|
|
125
|
-
* // Use the newly enabled schema.
|
|
126
|
-
* viewC.root = "test";
|
|
127
|
-
*
|
|
128
|
-
* synchronizeTrees();
|
|
129
|
-
*
|
|
130
|
-
* // View A is now incompatible with the stored schema:
|
|
131
|
-
* assert.equal(viewA.compatibility.canView, false);
|
|
132
|
-
*
|
|
133
|
-
* // View B can still read the document, and now sees the string root which relies on the staged schema.
|
|
134
|
-
* assert.deepEqual(viewB.root, "test");
|
|
135
|
-
* ```
|
|
136
49
|
* @privateRemarks
|
|
137
50
|
* TODO:#44317 staged allowed types rely on schema validation of stored schema to output errors, these errors are not very
|
|
138
51
|
* user friendly and should be improved, particularly in the case of staged allowed types
|
|
139
52
|
*
|
|
140
|
-
* TODO: the example above does not work tell in intellisense: its formatted to work onm the website. We should find a solution that works well for both.
|
|
141
|
-
*
|
|
142
53
|
* TODO: AB#45711: Update the docs above when recursive type support is added.
|
|
143
54
|
*/
|
|
144
55
|
staged: <const T extends LazyItem<TreeNodeSchema>>(t: T | AnnotatedAllowedType<T>) => AnnotatedAllowedType<T>;
|
|
@@ -277,76 +188,6 @@ export declare class SchemaFactoryAlpha<out TScope extends string | undefined =
|
|
|
277
188
|
* {@inheritDoc SchemaFactory.objectRecursive}
|
|
278
189
|
*/
|
|
279
190
|
arrayRecursive<const Name extends TName, const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptionsAlpha<TCustomMetadata>): ArrayNodeCustomizableSchemaUnsafe<ScopedSchemaName<TScope, Name>, T, TCustomMetadata>;
|
|
280
|
-
/**
|
|
281
|
-
* Define a structurally typed {@link TreeNodeSchema} for a {@link (TreeRecordNode:interface)}.
|
|
282
|
-
*
|
|
283
|
-
* @param allowedTypes - The types that may appear in the record.
|
|
284
|
-
*
|
|
285
|
-
* @remarks
|
|
286
|
-
* The identifier for this record is defined as a function of the provided types.
|
|
287
|
-
* It is still scoped to this `SchemaFactory`, but multiple calls with the same arguments will return the same
|
|
288
|
-
* schema object, providing somewhat structural typing.
|
|
289
|
-
* This does not support recursive types.
|
|
290
|
-
*
|
|
291
|
-
* If using these structurally named records, other types in this schema builder should avoid names of the form `Record<${string}>`.
|
|
292
|
-
*
|
|
293
|
-
* @example
|
|
294
|
-
* The returned schema should be used as a schema directly:
|
|
295
|
-
* ```typescript
|
|
296
|
-
* const MyRecord = factory.record(factory.number);
|
|
297
|
-
* type MyRecord = NodeFromSchema<typeof Record>;
|
|
298
|
-
* ```
|
|
299
|
-
* Or inline:
|
|
300
|
-
* ```typescript
|
|
301
|
-
* factory.object("Foo", { myRecord: factory.record(factory.number) });
|
|
302
|
-
* ```
|
|
303
|
-
*
|
|
304
|
-
* @privateRemarks
|
|
305
|
-
* The name produced at the type-level here is not as specific as it could be; however, doing type-level sorting and escaping is a real mess.
|
|
306
|
-
* There are cases where not having this full type provided will be less than ideal, since TypeScript's structural types will allow assignment between runtime incompatible types at compile time.
|
|
307
|
-
* For example, attempts to narrow unions of structural records by name won't work.
|
|
308
|
-
* Planned future changes to move to a class based schema system as well as factor function based node construction should mostly avoid these issues,
|
|
309
|
-
* though there may still be some problematic cases even after that work is done.
|
|
310
|
-
*
|
|
311
|
-
* The return value is a class, but its type is intentionally not specific enough to indicate it is a class.
|
|
312
|
-
* This prevents callers of this from sub-classing it, which is unlikely to work well (due to the ease of accidentally giving two different calls to this different subclasses)
|
|
313
|
-
* when working with structural typing.
|
|
314
|
-
*
|
|
315
|
-
* {@label STRUCTURAL}
|
|
316
|
-
*/
|
|
317
|
-
record<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record, TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record>, RecordNodeInsertableData<T>, true, T, undefined>;
|
|
318
|
-
/**
|
|
319
|
-
* Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeRecordNode:interface)}.
|
|
320
|
-
*
|
|
321
|
-
* @param name - Unique identifier for this schema within this factory's scope.
|
|
322
|
-
* @param allowedTypes - The types that may appear in the record.
|
|
323
|
-
*
|
|
324
|
-
* @remarks
|
|
325
|
-
* Like TypeScript `Record`s, record nodes have some potential pitfalls.
|
|
326
|
-
* For example: TypeScript makes assumptions about built-in keys being present (e.g. `toString`, `hasOwnProperty`, etc.).
|
|
327
|
-
* Since these are otherwise valid keys in a record, this can lead to unexpected behavior.
|
|
328
|
-
* To prevent inconsistent behavior, these built-ins are hidden by record nodes.
|
|
329
|
-
* This means that if you try to call these built-ins (e.g. `toString()`) on a record node, you will get an error.
|
|
330
|
-
*
|
|
331
|
-
* In most cases, it is probably preferable to use {@link SchemaFactory.(map:2)} instead.
|
|
332
|
-
*
|
|
333
|
-
* @example
|
|
334
|
-
* ```typescript
|
|
335
|
-
* class NamedRecord extends factory.record("name", factory.number) {}
|
|
336
|
-
* ```
|
|
337
|
-
*
|
|
338
|
-
* {@label NAMED}
|
|
339
|
-
*/
|
|
340
|
-
record<const Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Record, TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Record>, RecordNodeInsertableData<T>, true, T, undefined>;
|
|
341
|
-
/**
|
|
342
|
-
* Define a {@link TreeNodeSchema} for a {@link (TreeRecordNode:interface)}.
|
|
343
|
-
*
|
|
344
|
-
* @param name - Unique identifier for this schema within this factory's scope.
|
|
345
|
-
*
|
|
346
|
-
* @remarks
|
|
347
|
-
* This is not intended to be used directly, use the overload of `record` which takes a name instead.
|
|
348
|
-
*/
|
|
349
|
-
private namedRecord;
|
|
350
191
|
/**
|
|
351
192
|
* Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeRecordNode:interface)}.
|
|
352
193
|
*
|
|
@@ -361,7 +202,7 @@ export declare class SchemaFactoryAlpha<out TScope extends string | undefined =
|
|
|
361
202
|
*/
|
|
362
203
|
recordAlpha<const Name extends TName, const T extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptionsAlpha<TCustomMetadata>): RecordNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata>;
|
|
363
204
|
/**
|
|
364
|
-
* {@link
|
|
205
|
+
* {@link SchemaFactoryBeta.(record:2)} except tweaked to work better for recursive types.
|
|
365
206
|
* Use with {@link ValidateRecursiveSchema} for improved type safety.
|
|
366
207
|
* @remarks
|
|
367
208
|
* This version of `SchemaFactory.record` uses the same workarounds as {@link SchemaFactory.objectRecursive}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaFactoryAlpha.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFactoryAlpha.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,2BAA2B,EAEhC,KAAK,yBAAyB,EAE9B,KAAK,gBAAgB,EAErB,KAAK,4BAA4B,
|
|
1
|
+
{"version":3,"file":"schemaFactoryAlpha.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFactoryAlpha.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,2BAA2B,EAEhC,KAAK,yBAAyB,EAE9B,KAAK,gBAAgB,EAErB,KAAK,4BAA4B,EAEjC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGN,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,EAC/B,KAAK,gBAAgB,EACrB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,4BAA4B,EAAuB,MAAM,mBAAmB,CAAC;AAC3F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EACX,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,6BAA6B,EAC7B,oBAAoB,EACpB,QAAQ,EACR,QAAQ,EACR,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EACX,iCAAiC,EACjC,+BAA+B,EAC/B,aAAa,EACb,oBAAoB,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAI3D,OAAO,KAAK,EACX,UAAU,EACV,gBAAgB,EAChB,e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B,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,CAAC,EACf,OAAO,CAAC,EAAE,sBAAsB,CAAC,eAAe,CAAC,GAC/C,4BAA4B,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC;IAWzF;;;;;;OAMG;IAEa,eAAe,CAC9B,IAAI,SAAS,KAAK,EAClB,KAAK,CAAC,CAAC,SAAS,aAAa,CAAC,0BAA0B,EACxD,KAAK,CAAC,eAAe,GAAG,OAAO,EAC9B,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,sBAAsB,CAAC,eAAe,CAAC;;;IA+BhF;;OAEG;IACI,kBAAkB,CACxB,KAAK,CAAC,CAAC,SAAS,KAAK,EACrB,UAAU,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAC1C,IAAI,EAAE,CAAC,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC;CAGvE"}
|
|
@@ -122,44 +122,6 @@ class SchemaFactoryAlpha extends schemaFactoryBeta_js_1.SchemaFactoryBeta {
|
|
|
122
122
|
arrayRecursive(name, allowedTypes, options) {
|
|
123
123
|
return this.arrayAlpha(name, allowedTypes, options);
|
|
124
124
|
}
|
|
125
|
-
/**
|
|
126
|
-
* {@link SchemaFactory.array} implementation.
|
|
127
|
-
*
|
|
128
|
-
* @privateRemarks
|
|
129
|
-
* This should return TreeNodeSchemaBoth: see note on "map" implementation for details.
|
|
130
|
-
*/
|
|
131
|
-
record(nameOrAllowedTypes, maybeAllowedTypes) {
|
|
132
|
-
if (maybeAllowedTypes === undefined) {
|
|
133
|
-
const types = nameOrAllowedTypes;
|
|
134
|
-
const fullName = (0, schemaFactory_js_1.structuralName)("Record", types);
|
|
135
|
-
return this.getStructuralType(fullName, types, () => this.namedRecord(fullName, nameOrAllowedTypes,
|
|
136
|
-
/* customizable */ false,
|
|
137
|
-
/* implicitlyConstructable */ true));
|
|
138
|
-
}
|
|
139
|
-
const out = this.namedRecord(nameOrAllowedTypes, maybeAllowedTypes,
|
|
140
|
-
/* customizable */ true,
|
|
141
|
-
/* implicitlyConstructable */ true);
|
|
142
|
-
return out;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Define a {@link TreeNodeSchema} for a {@link (TreeRecordNode:interface)}.
|
|
146
|
-
*
|
|
147
|
-
* @param name - Unique identifier for this schema within this factory's scope.
|
|
148
|
-
*
|
|
149
|
-
* @remarks
|
|
150
|
-
* This is not intended to be used directly, use the overload of `record` which takes a name instead.
|
|
151
|
-
*/
|
|
152
|
-
namedRecord(name, allowedTypes, customizable, implicitlyConstructable, options) {
|
|
153
|
-
const record = (0, index_js_1.recordSchema)({
|
|
154
|
-
identifier: (0, schemaFactory_js_1.scoped)(this, name),
|
|
155
|
-
info: allowedTypes,
|
|
156
|
-
customizable,
|
|
157
|
-
implicitlyConstructable,
|
|
158
|
-
metadata: options?.metadata,
|
|
159
|
-
persistedMetadata: options?.persistedMetadata,
|
|
160
|
-
});
|
|
161
|
-
return record;
|
|
162
|
-
}
|
|
163
125
|
/**
|
|
164
126
|
* Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeRecordNode:interface)}.
|
|
165
127
|
*
|
|
@@ -183,7 +145,7 @@ class SchemaFactoryAlpha extends schemaFactoryBeta_js_1.SchemaFactoryBeta {
|
|
|
183
145
|
});
|
|
184
146
|
}
|
|
185
147
|
/**
|
|
186
|
-
* {@link
|
|
148
|
+
* {@link SchemaFactoryBeta.(record:2)} except tweaked to work better for recursive types.
|
|
187
149
|
* Use with {@link ValidateRecursiveSchema} for improved type safety.
|
|
188
150
|
* @remarks
|
|
189
151
|
* This version of `SchemaFactory.record` uses the same workarounds as {@link SchemaFactory.objectRecursive}.
|
|
@@ -191,11 +153,16 @@ class SchemaFactoryAlpha extends schemaFactoryBeta_js_1.SchemaFactoryBeta {
|
|
|
191
153
|
*/
|
|
192
154
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
193
155
|
recordRecursive(name, allowedTypes, options) {
|
|
194
|
-
const RecordSchema =
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
156
|
+
const RecordSchema = (0, index_js_1.recordSchema)({
|
|
157
|
+
identifier: (0, schemaFactory_js_1.scoped)(this, name),
|
|
158
|
+
info: allowedTypes,
|
|
159
|
+
customizable: true,
|
|
160
|
+
// Setting this to true seems to work ok currently, but not for other node kinds.
|
|
161
|
+
// Supporting this could be fragile and might break other future changes, so it's being kept as false for now.
|
|
162
|
+
implicitlyConstructable: false,
|
|
163
|
+
metadata: options?.metadata,
|
|
164
|
+
persistedMetadata: options?.persistedMetadata,
|
|
165
|
+
});
|
|
199
166
|
return RecordSchema;
|
|
200
167
|
}
|
|
201
168
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaFactoryAlpha.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFactoryAlpha.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qDAWgC;AAChC,yDAO4B;AAC5B,yDAAmD;AAenD,+CAAwF;AAQxF,iEAA2D;AAmJ3D,MAAM,kBAAkB,GAAuB;IAC9C,MAAM,EAAE,CACP,CAA8B,EACJ,EAAE;QAC5B,MAAM,aAAa,GAAG,IAAA,0CAA+B,EAAC,CAAC,CAAC,CAAC;QACzD,OAAO;YACN,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,QAAQ,EAAE;gBACT,GAAG,aAAa,CAAC,QAAQ;gBACzB,mBAAmB,EAAE,IAAA,8BAAmB,GAAE;aAC1C;SACD,CAAC;IACH,CAAC;CACD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAa,kBAGX,SAAQ,wCAAgC;IAH1C;;QAiIC;;WAEG;QACsB,WAAM,GAAG,gCAAa,CAAC,MAAM,CAAC;QAEvD;;WAEG;QACsB,aAAQ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AAG,gCAAa,CAAC,iBAAiB,AAAlC,CAAmC;AAEpF;;GAEG;AACoB,6BAAU,GAAG,gCAAa,CAAC,UAAU,AAA3B,CAA4B;AA2B7D;;GAEG;AACW,yBAAM,GAAG,kBAAkB,CAAC,MAAM,AAA5B,CAA6B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype ArrayNodeCustomizableSchema,\n\tarraySchema,\n\ttype MapNodeCustomizableSchema,\n\tmapSchema,\n\ttype ObjectNodeSchema,\n\tobjectSchema,\n\ttype RecordNodeCustomizableSchema,\n\ttype RecordNodeInsertableData,\n\trecordSchema,\n\ttype TreeRecordNode,\n} from \"../node-kinds/index.js\";\nimport {\n\tdefaultSchemaFactoryObjectOptions,\n\tscoped,\n\tstructuralName,\n\ttype NodeSchemaOptionsAlpha,\n\ttype SchemaFactoryObjectOptions,\n\ttype ScopedSchemaName,\n} from \"./schemaFactory.js\";\nimport { schemaStatics } from \"./schemaStatics.js\";\nimport type { ImplicitAnnotatedFieldSchema, ImplicitFieldSchema } from \"../fieldSchema.js\";\nimport type { RestrictiveStringRecord } from \"../../util/index.js\";\nimport type {\n\tNodeKind,\n\tTreeNodeSchema,\n\tTreeNodeSchemaBoth,\n\tTreeNodeSchemaClass,\n\tTreeNodeSchemaNonClass,\n\tWithType,\n\tImplicitAllowedTypes,\n\tImplicitAnnotatedAllowedTypes,\n\tAnnotatedAllowedType,\n\tLazyItem,\n} from \"../core/index.js\";\nimport { normalizeToAnnotatedAllowedType, createSchemaUpgrade } from \"../core/index.js\";\nimport type {\n\tArrayNodeCustomizableSchemaUnsafe,\n\tMapNodeCustomizableSchemaUnsafe,\n\tSystem_Unsafe,\n\tTreeRecordNodeUnsafe,\n} from \"./typesUnsafe.js\";\nimport type { SimpleObjectNodeSchema } from \"../simpleSchema.js\";\nimport { SchemaFactoryBeta } from \"./schemaFactoryBeta.js\";\n\n// This import prevents a large number of type references in the API reports from showing up as *_2.\n/* eslint-disable unused-imports/no-unused-imports, @typescript-eslint/no-unused-vars, import/no-duplicates */\nimport type {\n\tFieldProps,\n\tFieldSchemaAlpha,\n\tFieldPropsAlpha,\n\tFieldKind,\n} from \"../fieldSchema.js\";\nimport type { LeafSchema } from \"../leafNodeSchema.js\";\nimport type { SimpleLeafNodeSchema } from \"../simpleSchema.js\";\nimport type { UnannotateImplicitAllowedTypes } from \"../core/index.js\";\nimport type { FieldSchemaAlphaUnsafe } from \"./typesUnsafe.js\";\n/* eslint-enable unused-imports/no-unused-imports, @typescript-eslint/no-unused-vars, import/no-duplicates */\n\n/**\n * Stateless APIs exposed via {@link SchemaFactoryAlpha} as both instance properties and as statics.\n * @remarks\n * See {@link SchemaStatics} for why this is useful.\n * @system @sealed @alpha\n */\nexport interface SchemaStaticsAlpha {\n\t/**\n\t * Declares a staged type in a set of {@link AllowedTypes}.\n\t *\n\t * @remarks\n\t * Staged allowed types add support for loading documents which may or may not permit an allowed type in a location in a schema.\n\t * This allows for an incremental rollout of a schema change to add a {@link TreeNodeSchema} to an {@link AllowedTypes} without breaking cross version collaboration.\n\t *\n\t * Once enough clients have the type staged (and thus can read documents which allow it), documents can start being created and upgraded to allow the staged type.\n\t * This is done by deploying a new version of the app which removes the `staged` wrapper around the allowed type in the the schema definition.\n\t * This will also require {@link TreeView.upgradeSchema|upgrading the schema} for existing documents.\n\t *\n\t * Using a staged allowed type in a schema is just like using the schema as an allowed type with the following exceptions:\n\t *\n\t * 1. {@link TreeView.initialize} will omit the staged allowed type from the newly created stored schema.\n\t * 2. {@link TreeView.upgradeSchema} will omit the staged allowed type from the the upgraded stored schema.\n\t * 3. When evaluating {@link TreeView.compatibility}, it will be viewable even if the staged allowed type is not present in the stored schema's corresponding allowed types.\n\t * 4. Because of the above, it is possible to get errors when inserting content which uses the staged allowed type when inserting the content into a tree who's stored schema does not permit it.\n\t *\n\t * Currently, `staged` is not supported in the recursive type APIs: this is a known limitation which future versions of the API will address.\n\t *\n\t * @example\n\t * Suppose you have a schema which has a field that allows some type `A`, but you want to add support for type `B`.\n\t *\n\t * The first change is to used to mark the new type as staged, replacing `A` in the schema with `[A, SchemaStaticsAlpha.staged(B)]`.\n\t * Once this is done, and any code which reads contents from documents is updated to handle any `B` content that may be present, this version of the code can be deployed.\n\t *\n\t * Once all users have the above changes, the schema can be updated again to `[A, B]`, and the app can be updated to allow creating of `B` content.\n\t * This updated version of the app will need to call {@link TreeView.upgradeSchema} when opening documents created by earlier versions.\n\t *\n\t * Adding a `B` schema as an option in the root could look like this:\n\t * ```typescript\n\t * const factory = new SchemaFactoryAlpha(\"test\");\n\t * class A extends factory.objectAlpha(\"A\", {}) {}\n\t * class B extends factory.objectAlpha(\"B\", {}) {}\n\t *\n\t * // Does not support B\n\t * const configBefore = new TreeViewConfigurationAlpha({\n\t * \tschema: A,\n\t * });\n\t *\n\t * // Supports documents with or without B\n\t * const configStaged = new TreeViewConfigurationAlpha({\n\t * \t// Adds staged support for B.\n\t * \t// Currently this requires wrapping the root field with `SchemaFactoryAlpha.required`:\n\t * \t// this is normally implicitly included, but is currently required while the \"staged\" APIs are `@alpha`.\n\t * \tschema: SchemaFactoryAlpha.required([A, SchemaFactoryAlpha.staged(B)]),\n\t * });\n\t *\n\t * // Only supports documents with A and B: can be used to upgrade schema to add B.\n\t * const configAfter = new TreeViewConfigurationAlpha({\n\t * \tschema: [A, B],\n\t * });\n\t * ```\n\t * @example\n\t * Below is a full example of how the schema migration process works.\n\t * This can also be found in our {@link https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/test/simple-tree/api/stagedSchemaUpgrade.spec.ts | tests}.\n\t * ```typescript\n\t * // Schema A: only number allowed\n\t * const schemaA = SchemaFactoryAlpha.optional([SchemaFactoryAlpha.number]);\n\t *\n\t * // Schema B: number or string (string is staged)\n\t * const schemaB = SchemaFactoryAlpha.optional([\n\t * \tSchemaFactoryAlpha.number,\n\t * \tSchemaFactoryAlpha.staged(SchemaFactoryAlpha.string),\n\t * ]);\n\t *\n\t * // Schema C: number or string, both fully allowed\n\t * const schemaC = SchemaFactoryAlpha.optional([\n\t * \tSchemaFactoryAlpha.number,\n\t * \tSchemaFactoryAlpha.string,\n\t * ]);\n\t *\n\t * // Initialize with schema A.\n\t * const configA = new TreeViewConfiguration({\n\t * \tschema: schemaA,\n\t * });\n\t * const viewA = treeA.viewWith(configA);\n\t * viewA.initialize(5);\n\t *\n\t * // Since we are running all the different versions of the app in the same process making changes synchronously,\n\t * // an explicit flush is needed to make them available to each other.\n\t * synchronizeTrees();\n\t *\n\t * assert.deepEqual(viewA.root, 5);\n\t *\n\t * // View the same document with a second tree using schema B.\n\t * const configB = new TreeViewConfiguration({\n\t * \tschema: schemaB,\n\t * });\n\t * const viewB = treeB.viewWith(configB);\n\t * // B cannot write strings to the root.\n\t * assert.throws(() => (viewB.root = \"test\"));\n\t *\n\t * // View the same document with a third tree using schema C.\n\t * const configC = new TreeViewConfiguration({\n\t * \tschema: schemaC,\n\t * });\n\t * const viewC = treeC.viewWith(configC);\n\t * // Upgrade to schema C\n\t * viewC.upgradeSchema();\n\t * // Use the newly enabled schema.\n\t * viewC.root = \"test\";\n\t *\n\t * synchronizeTrees();\n\t *\n\t * // View A is now incompatible with the stored schema:\n\t * assert.equal(viewA.compatibility.canView, false);\n\t *\n\t * // View B can still read the document, and now sees the string root which relies on the staged schema.\n\t * assert.deepEqual(viewB.root, \"test\");\n\t * ```\n\t * @privateRemarks\n\t * TODO:#44317 staged allowed types rely on schema validation of stored schema to output errors, these errors are not very\n\t * user friendly and should be improved, particularly in the case of staged allowed types\n\t *\n\t * TODO: the example above does not work tell in intellisense: its formatted to work onm the website. We should find a solution that works well for both.\n\t *\n\t * TODO: AB#45711: Update the docs above when recursive type support is added.\n\t */\n\tstaged: <const T extends LazyItem<TreeNodeSchema>>(\n\t\tt: T | AnnotatedAllowedType<T>,\n\t) => AnnotatedAllowedType<T>;\n}\n\nconst schemaStaticsAlpha: SchemaStaticsAlpha = {\n\tstaged: <const T extends LazyItem<TreeNodeSchema>>(\n\t\tt: T | AnnotatedAllowedType<T>,\n\t): AnnotatedAllowedType<T> => {\n\t\tconst annotatedType = normalizeToAnnotatedAllowedType(t);\n\t\treturn {\n\t\t\ttype: annotatedType.type,\n\t\t\tmetadata: {\n\t\t\t\t...annotatedType.metadata,\n\t\t\t\tstagedSchemaUpgrade: createSchemaUpgrade(),\n\t\t\t},\n\t\t};\n\t},\n};\n\n/**\n * {@link SchemaFactory} with additional alpha APIs.\n *\n * @alpha\n * @privateRemarks\n * When building schema, when `options` is not provided, `TCustomMetadata` is inferred as `unknown`.\n * If desired, this could be made to infer `undefined` instead by adding overloads for everything,\n * but currently it is not worth the maintenance overhead as there is no use case which this is known to be helpful for.\n */\nexport class SchemaFactoryAlpha<\n\tout TScope extends string | undefined = string | undefined,\n\tTName extends number | string = string,\n> extends SchemaFactoryBeta<TScope, TName> {\n\t/**\n\t * Define a {@link TreeNodeSchemaClass} for a {@link TreeObjectNode}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.\n\t * @param options - Additional options for the schema.\n\t */\n\tpublic objectAlpha<\n\t\tconst Name extends TName,\n\t\tconst T extends RestrictiveStringRecord<ImplicitAnnotatedFieldSchema>,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tfields: T,\n\t\toptions?: SchemaFactoryObjectOptions<TCustomMetadata>,\n\t): ObjectNodeSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> & {\n\t\t/**\n\t\t * Typing checking workaround: not for for actual use.\n\t\t * @remarks\n\t\t * This API collides with {@link TreeNodeSchemaCore.createFromInsertable} to disable a type checking optimization which produces different and undesired results.\n\t\t * See {@link https://github.com/microsoft/TypeScript/issues/59049#issuecomment-2773459693} for more details.\n\t\t * @privateRemarks\n\t\t * The specific issue here is non-empty POJO mode object schema not being assignable to `ObjectNodeSchema`,\n\t\t * See the above link and the tests in objectNode.spec.ts which reference it.\n\t\t * @system\n\t\t */\n\t\treadonly createFromInsertable: unknown;\n\t} {\n\t\treturn objectSchema(\n\t\t\tscoped<TScope, TName, Name>(this, name),\n\t\t\tfields,\n\t\t\ttrue,\n\t\t\toptions?.allowUnknownOptionalFields ??\n\t\t\t\tdefaultSchemaFactoryObjectOptions.allowUnknownOptionalFields,\n\t\t\toptions?.metadata,\n\t\t\toptions?.persistedMetadata,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritdoc SchemaFactory.objectRecursive}\n\t */\n\tpublic override objectRecursive<\n\t\tconst Name extends TName,\n\t\tconst T extends RestrictiveStringRecord<System_Unsafe.ImplicitFieldSchemaUnsafe>,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tt: T,\n\t\toptions?: SchemaFactoryObjectOptions<TCustomMetadata>,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Object,\n\t\tSystem_Unsafe.TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>,\n\t\tobject & System_Unsafe.InsertableObjectFromSchemaRecordUnsafe<T>,\n\t\tfalse,\n\t\tT,\n\t\tnever,\n\t\tTCustomMetadata\n\t> &\n\t\tSimpleObjectNodeSchema<TCustomMetadata> &\n\t\t// We can't just use non generic `ObjectNodeSchema` here since \"Base constructors must all have the same return type\".\n\t\t// We also can't just use generic `ObjectNodeSchema` here and not `TreeNodeSchemaClass` since that doesn't work with unsafe recursive types.\n\t\t// ObjectNodeSchema<\n\t\t// \tScopedSchemaName<TScope, Name>,\n\t\t// \t// T & RestrictiveStringRecord<ImplicitFieldSchema> would be nice to use here, but it breaks the recursive type self references.\n\t\t// \tRestrictiveStringRecord<ImplicitFieldSchema>,\n\t\t// \tfalse,\n\t\t// \tTCustomMetadata\n\t\t// >\n\t\tPick<ObjectNodeSchema, \"fields\"> {\n\t\t// TODO: syntax highting is vs code is broken here. Don't trust it. Use the compiler instead.\n\t\ttype TScopedName = ScopedSchemaName<TScope, Name>;\n\t\treturn this.objectAlpha(\n\t\t\tname,\n\t\t\tt as T & RestrictiveStringRecord<ImplicitFieldSchema>,\n\t\t\toptions,\n\t\t) as unknown as TreeNodeSchemaClass<\n\t\t\tTScopedName,\n\t\t\tNodeKind.Object,\n\t\t\tSystem_Unsafe.TreeObjectNodeUnsafe<T, TScopedName>,\n\t\t\tobject & System_Unsafe.InsertableObjectFromSchemaRecordUnsafe<T>,\n\t\t\tfalse,\n\t\t\tT,\n\t\t\tnever,\n\t\t\tTCustomMetadata\n\t\t> &\n\t\t\tObjectNodeSchema<\n\t\t\t\tScopedSchemaName<TScope, Name>,\n\t\t\t\tRestrictiveStringRecord<ImplicitFieldSchema>,\n\t\t\t\tfalse,\n\t\t\t\tTCustomMetadata\n\t\t\t>;\n\t}\n\n\t/**\n\t * {@inheritDoc SchemaStatics.leaves}\n\t */\n\tpublic static override readonly leaves = schemaStatics.leaves;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.optional}\n\t */\n\tpublic static override readonly optional = schemaStatics.optional;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.required}\n\t */\n\tpublic static override readonly required = schemaStatics.required;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.optionalRecursive}\n\t */\n\tpublic static override readonly optionalRecursive = schemaStatics.optionalRecursive;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.requiredRecursive}\n\t */\n\tpublic static override readonly requiredRecursive = schemaStatics.requiredRecursive;\n\n\t/**\n\t * Like {@link SchemaFactory.identifier} but static and a factory function that can be provided {@link FieldProps}.\n\t */\n\tpublic static readonly identifier = schemaStatics.identifier;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.leaves}\n\t */\n\tpublic override readonly leaves = schemaStatics.leaves;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.optional}\n\t */\n\tpublic override readonly optional = schemaStatics.optional;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.required}\n\t */\n\tpublic override readonly required = schemaStatics.required;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.optionalRecursive}\n\t */\n\tpublic override readonly optionalRecursive = schemaStatics.optionalRecursive;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.requiredRecursive}\n\t */\n\tpublic override readonly requiredRecursive = schemaStatics.requiredRecursive;\n\n\t/**\n\t * {@inheritDoc SchemaStaticsAlpha.staged}\n\t */\n\tpublic static staged = schemaStaticsAlpha.staged;\n\n\t/**\n\t * {@inheritDoc SchemaStaticsAlpha.staged}\n\t */\n\tpublic staged = schemaStaticsAlpha.staged;\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link TreeMapNode}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param allowedTypes - The types that may appear as values in the map.\n\t * @param options - Additional options for the schema.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedMap extends factory.map(\"name\", factory.number, {\n\t * \tmetadata: { description: \"A map of numbers\" }\n\t * }) {}\n\t * ```\n\t */\n\tpublic mapAlpha<\n\t\tName extends TName,\n\t\tconst T extends ImplicitAnnotatedAllowedTypes,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\toptions?: NodeSchemaOptionsAlpha<TCustomMetadata>,\n\t): MapNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> {\n\t\treturn mapSchema(\n\t\t\tscoped<TScope, TName, Name>(this, name),\n\t\t\tallowedTypes,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t\toptions?.metadata,\n\t\t\toptions?.persistedMetadata,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc SchemaFactory.objectRecursive}\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tpublic override mapRecursive<\n\t\tName extends TName,\n\t\tconst T extends System_Unsafe.ImplicitAllowedTypesUnsafe,\n\t\tconst TCustomMetadata = unknown,\n\t>(name: Name, allowedTypes: T, options?: NodeSchemaOptionsAlpha<TCustomMetadata>) {\n\t\treturn this.mapAlpha(\n\t\t\tname,\n\t\t\tallowedTypes as T & ImplicitAllowedTypes,\n\t\t\toptions,\n\t\t) as unknown as MapNodeCustomizableSchemaUnsafe<\n\t\t\tScopedSchemaName<TScope, Name>,\n\t\t\tT,\n\t\t\tTCustomMetadata\n\t\t>;\n\t}\n\n\t/**\n\t * Define a {@link TreeNodeSchemaClass} for a {@link (TreeArrayNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param allowedTypes - The types that may appear in the array.\n\t * @param options - Additional options for the schema.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedArray extends factory.arrayAlpha(\"name\", factory.number) {}\n\t * ```\n\t */\n\tpublic arrayAlpha<\n\t\tconst Name extends TName,\n\t\tconst T extends ImplicitAnnotatedAllowedTypes,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\toptions?: NodeSchemaOptionsAlpha<TCustomMetadata>,\n\t): ArrayNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> {\n\t\treturn arraySchema(\n\t\t\tscoped<TScope, TName, Name>(this, name),\n\t\t\tallowedTypes,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t\toptions?.metadata,\n\t\t\toptions?.persistedMetadata,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc SchemaFactory.objectRecursive}\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tpublic override arrayRecursive<\n\t\tconst Name extends TName,\n\t\tconst T extends System_Unsafe.ImplicitAllowedTypesUnsafe,\n\t\tconst TCustomMetadata = unknown,\n\t>(name: Name, allowedTypes: T, options?: NodeSchemaOptionsAlpha<TCustomMetadata>) {\n\t\treturn this.arrayAlpha(\n\t\t\tname,\n\t\t\tallowedTypes as T & ImplicitAllowedTypes,\n\t\t\toptions,\n\t\t) as unknown as ArrayNodeCustomizableSchemaUnsafe<\n\t\t\tScopedSchemaName<TScope, Name>,\n\t\t\tT,\n\t\t\tTCustomMetadata\n\t\t>;\n\t}\n\n\t/**\n\t * Define a structurally typed {@link TreeNodeSchema} for a {@link (TreeRecordNode:interface)}.\n\t *\n\t * @param allowedTypes - The types that may appear in the record.\n\t *\n\t * @remarks\n\t * The identifier for this record is defined as a function of the provided types.\n\t * It is still scoped to this `SchemaFactory`, but multiple calls with the same arguments will return the same\n\t * schema object, providing somewhat structural typing.\n\t * This does not support recursive types.\n\t *\n\t * If using these structurally named records, other types in this schema builder should avoid names of the form `Record<${string}>`.\n\t *\n\t * @example\n\t * The returned schema should be used as a schema directly:\n\t * ```typescript\n\t * const MyRecord = factory.record(factory.number);\n\t * type MyRecord = NodeFromSchema<typeof Record>;\n\t * ```\n\t * Or inline:\n\t * ```typescript\n\t * factory.object(\"Foo\", { myRecord: factory.record(factory.number) });\n\t * ```\n\t *\n\t * @privateRemarks\n\t * The name produced at the type-level here is not as specific as it could be; however, doing type-level sorting and escaping is a real mess.\n\t * There are cases where not having this full type provided will be less than ideal, since TypeScript's structural types will allow assignment between runtime incompatible types at compile time.\n\t * For example, attempts to narrow unions of structural records by name won't work.\n\t * Planned future changes to move to a class based schema system as well as factor function based node construction should mostly avoid these issues,\n\t * though there may still be some problematic cases even after that work is done.\n\t *\n\t * The return value is a class, but its type is intentionally not specific enough to indicate it is a class.\n\t * This prevents callers of this from sub-classing it, which is unlikely to work well (due to the ease of accidentally giving two different calls to this different subclasses)\n\t * when working with structural typing.\n\t *\n\t * {@label STRUCTURAL}\n\t */\n\tpublic record<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(\n\t\tallowedTypes: T,\n\t): TreeNodeSchemaNonClass<\n\t\t/* Name */ ScopedSchemaName<TScope, `Record<${string}>`>,\n\t\t/* Kind */ NodeKind.Record,\n\t\t/* TNode */ TreeRecordNode<T> &\n\t\t\tWithType<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record>,\n\t\t/* TInsertable */ RecordNodeInsertableData<T>,\n\t\t/* ImplicitlyConstructable */ true,\n\t\t/* Info */ T,\n\t\t/* TConstructorExtra */ undefined\n\t>;\n\t/**\n\t * Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeRecordNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param allowedTypes - The types that may appear in the record.\n\t *\n\t * @remarks\n\t * Like TypeScript `Record`s, record nodes have some potential pitfalls.\n\t * For example: TypeScript makes assumptions about built-in keys being present (e.g. `toString`, `hasOwnProperty`, etc.).\n\t * Since these are otherwise valid keys in a record, this can lead to unexpected behavior.\n\t * To prevent inconsistent behavior, these built-ins are hidden by record nodes.\n\t * This means that if you try to call these built-ins (e.g. `toString()`) on a record node, you will get an error.\n\t *\n\t * In most cases, it is probably preferable to use {@link SchemaFactory.(map:2)} instead.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedRecord extends factory.record(\"name\", factory.number) {}\n\t * ```\n\t *\n\t * {@label NAMED}\n\t */\n\tpublic record<const Name extends TName, const T extends ImplicitAllowedTypes>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t): TreeNodeSchemaClass<\n\t\t/* Name */ ScopedSchemaName<TScope, Name>,\n\t\t/* Kind */ NodeKind.Record,\n\t\t/* TNode */ TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Record>,\n\t\t/* TInsertable */ RecordNodeInsertableData<T>,\n\t\t/* ImplicitlyConstructable */ true,\n\t\t/* Info */ T,\n\t\t/* TConstructorExtra */ undefined\n\t>;\n\t/**\n\t * {@link SchemaFactory.array} implementation.\n\t *\n\t * @privateRemarks\n\t * This should return TreeNodeSchemaBoth: see note on \"map\" implementation for details.\n\t */\n\tpublic record<const T extends ImplicitAllowedTypes>(\n\t\tnameOrAllowedTypes: TName | ((T & TreeNodeSchema) | readonly TreeNodeSchema[]),\n\t\tmaybeAllowedTypes?: T,\n\t): TreeNodeSchema<\n\t\t/* Name */ ScopedSchemaName<TScope, string>,\n\t\t/* Kind */ NodeKind.Record,\n\t\t/* TNode */ TreeRecordNode<T>,\n\t\t/* TInsertable */ RecordNodeInsertableData<T>,\n\t\t/* ImplicitlyConstructable */ true,\n\t\t/* Info */ T\n\t> {\n\t\tif (maybeAllowedTypes === undefined) {\n\t\t\tconst types = nameOrAllowedTypes as (T & TreeNodeSchema) | readonly TreeNodeSchema[];\n\t\t\tconst fullName = structuralName(\"Record\", types);\n\t\t\treturn this.getStructuralType(fullName, types, () =>\n\t\t\t\tthis.namedRecord(\n\t\t\t\t\tfullName,\n\t\t\t\t\tnameOrAllowedTypes as T,\n\t\t\t\t\t/* customizable */ false,\n\t\t\t\t\t/* implicitlyConstructable */ true,\n\t\t\t\t),\n\t\t\t) as TreeNodeSchemaClass<\n\t\t\t\t/* Name */ ScopedSchemaName<TScope, string>,\n\t\t\t\t/* Kind */ NodeKind.Record,\n\t\t\t\t/* TNode */ TreeRecordNode<T>,\n\t\t\t\t/* TInsertable */ RecordNodeInsertableData<T>,\n\t\t\t\t/* ImplicitlyConstructable */ true,\n\t\t\t\t/* Info */ T,\n\t\t\t\t/* TConstructorExtra */ undefined\n\t\t\t>;\n\t\t}\n\t\tconst out: TreeNodeSchemaBoth<\n\t\t\t/* Name */ ScopedSchemaName<TScope, string>,\n\t\t\t/* Kind */ NodeKind.Record,\n\t\t\t/* TNode */ TreeRecordNode<T>,\n\t\t\t/* TInsertable */ RecordNodeInsertableData<T>,\n\t\t\t/* ImplicitlyConstructable */ true,\n\t\t\t/* Info */ T,\n\t\t\t/* TConstructorExtra */ undefined\n\t\t> = this.namedRecord(\n\t\t\tnameOrAllowedTypes as TName,\n\t\t\tmaybeAllowedTypes,\n\t\t\t/* customizable */ true,\n\t\t\t/* implicitlyConstructable */ true,\n\t\t);\n\t\treturn out;\n\t}\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link (TreeRecordNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t *\n\t * @remarks\n\t * This is not intended to be used directly, use the overload of `record` which takes a name instead.\n\t */\n\tprivate namedRecord<\n\t\tName extends TName | string,\n\t\tconst T extends ImplicitAllowedTypes,\n\t\tconst ImplicitlyConstructable extends boolean,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\tcustomizable: boolean,\n\t\timplicitlyConstructable: ImplicitlyConstructable,\n\t\toptions?: NodeSchemaOptionsAlpha<TCustomMetadata>,\n\t): TreeNodeSchemaBoth<\n\t\t/* Name */ ScopedSchemaName<TScope, Name>,\n\t\t/* Kind */ NodeKind.Record,\n\t\t/* TNode */ TreeRecordNode<T> &\n\t\t\tWithType<ScopedSchemaName<TScope, string>, NodeKind.Record>,\n\t\t/* TInsertable */ RecordNodeInsertableData<T>,\n\t\t/* ImplicitlyConstructable */ ImplicitlyConstructable,\n\t\t/* Info */ T,\n\t\t/* TConstructorExtra */ undefined\n\t> {\n\t\tconst record = recordSchema({\n\t\t\tidentifier: scoped<TScope, TName, Name>(this, name),\n\t\t\tinfo: allowedTypes,\n\t\t\tcustomizable,\n\t\t\timplicitlyConstructable,\n\t\t\tmetadata: options?.metadata,\n\t\t\tpersistedMetadata: options?.persistedMetadata,\n\t\t});\n\n\t\treturn record as TreeNodeSchemaBoth<\n\t\t\t/* Name */ ScopedSchemaName<TScope, Name>,\n\t\t\t/* Kind */ NodeKind.Record,\n\t\t\t/* TNode */ TreeRecordNode<T> &\n\t\t\t\tWithType<ScopedSchemaName<TScope, string>, NodeKind.Record>,\n\t\t\t/* TInsertable */ RecordNodeInsertableData<T>,\n\t\t\t/* ImplicitlyConstructable */ ImplicitlyConstructable,\n\t\t\t/* Info */ T,\n\t\t\t/* TConstructorExtra */ undefined\n\t\t>;\n\t}\n\n\t/**\n\t * Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeRecordNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param allowedTypes - The types that may appear in the record.\n\t * @param options - Additional options for the schema.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedRecord extends factory.recordAlpha(\"name\", factory.number) {}\n\t * ```\n\t */\n\tpublic recordAlpha<\n\t\tconst Name extends TName,\n\t\tconst T extends ImplicitAnnotatedAllowedTypes,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\toptions?: NodeSchemaOptionsAlpha<TCustomMetadata>,\n\t): RecordNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> {\n\t\treturn recordSchema({\n\t\t\tidentifier: scoped<TScope, TName, Name>(this, name),\n\t\t\tinfo: allowedTypes,\n\t\t\tcustomizable: true,\n\t\t\timplicitlyConstructable: true,\n\t\t\tmetadata: options?.metadata,\n\t\t\tpersistedMetadata: options?.persistedMetadata,\n\t\t});\n\t}\n\n\t/**\n\t * {@link SchemaFactoryAlpha.(record:2)} except tweaked to work better for recursive types.\n\t * Use with {@link ValidateRecursiveSchema} for improved type safety.\n\t * @remarks\n\t * This version of `SchemaFactory.record` uses the same workarounds as {@link SchemaFactory.objectRecursive}.\n\t * See {@link ValidateRecursiveSchema} for additional information about using recursive schema.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tpublic recordRecursive<\n\t\tName extends TName,\n\t\tconst T extends System_Unsafe.ImplicitAllowedTypesUnsafe,\n\t\tconst TCustomMetadata = unknown,\n\t>(name: Name, allowedTypes: T, options?: NodeSchemaOptionsAlpha<TCustomMetadata>) {\n\t\tconst RecordSchema = this.namedRecord(\n\t\t\tname,\n\t\t\tallowedTypes as T & ImplicitAllowedTypes,\n\t\t\t/* customizable */ true,\n\t\t\t// Setting this to true seems to work ok currently, but not for other node kinds.\n\t\t\t// Supporting this could be fragile and might break other future changes, so it's being kept as false for now.\n\t\t\t/* implicitlyConstructable */ false,\n\t\t\toptions,\n\t\t);\n\n\t\treturn RecordSchema as TreeNodeSchemaClass<\n\t\t\t/* Name */ ScopedSchemaName<TScope, Name>,\n\t\t\t/* Kind */ NodeKind.Record,\n\t\t\t/* TNode */ TreeRecordNodeUnsafe<T> &\n\t\t\t\tWithType<ScopedSchemaName<TScope, Name>, NodeKind.Record>,\n\t\t\t/* TInsertable */ {\n\t\t\t\t// Ideally this would be\n\t\t\t\t// RestrictiveStringRecord<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>,\n\t\t\t\t// but doing so breaks recursive types.\n\t\t\t\t// Instead we do a less nice version:\n\t\t\t\treadonly [P in string]: System_Unsafe.InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>;\n\t\t\t},\n\t\t\t/* ImplicitlyConstructable */ false,\n\t\t\t/* Info */ T,\n\t\t\t/* TConstructorExtra */ undefined,\n\t\t\t/* TCustomMetadata */ TCustomMetadata\n\t\t>;\n\t}\n\n\t/**\n\t * {@inheritDoc SchemaFactoryBeta.scopedFactory}\n\t */\n\tpublic scopedFactoryAlpha<\n\t\tconst T extends TName,\n\t\tTNameInner extends number | string = string,\n\t>(name: T): SchemaFactoryAlpha<ScopedSchemaName<TScope, T>, TNameInner> {\n\t\treturn new SchemaFactoryAlpha(scoped<TScope, TName, T>(this, name));\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"schemaFactoryAlpha.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFactoryAlpha.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qDASgC;AAChC,yDAM4B;AAC5B,yDAAmD;AAanD,+CAAwF;AAQxF,iEAA2D;AA0D3D,MAAM,kBAAkB,GAAuB;IAC9C,MAAM,EAAE,CACP,CAA8B,EACJ,EAAE;QAC5B,MAAM,aAAa,GAAG,IAAA,0CAA+B,EAAC,CAAC,CAAC,CAAC;QACzD,OAAO;YACN,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,QAAQ,EAAE;gBACT,GAAG,aAAa,CAAC,QAAQ;gBACzB,mBAAmB,EAAE,IAAA,8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,EAAE,OAAO,EAAE,QAAQ;YAC3B,iBAAiB,EAAE,OAAO,EAAE,iBAAiB;SAC7C,CAAC,CAAC;QAEH,OAAO,YAgBN,CAAC;IACH,CAAC;IAED;;OAEG;IACI,kBAAkB,CAGvB,IAAO;QACR,OAAO,IAAI,kBAAkB,CAAC,IAAA,yBAAM,EAAmB,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACrE,CAAC;;AA9VF,gDA+VC;AA5PA;;GAEG;AAC6B,yBAAM,GAAG,gCAAa,CAAC,MAAM,AAAvB,CAAwB;AAE9D;;GAEG;AAC6B,2BAAQ,GAAG,gCAAa,CAAC,QAAQ,AAAzB,CAA0B;AAElE;;GAEG;AAC6B,2BAAQ,GAAG,gCAAa,CAAC,QAAQ,AAAzB,CAA0B;AAElE;;GAEG;AAC6B,oCAAiB,GAAG,gCAAa,CAAC,iBAAiB,AAAlC,CAAmC;AAEpF;;GAEG;AAC6B,oCAAiB,GAAG,gCAAa,CAAC,iBAAiB,AAAlC,CAAmC;AAEpF;;GAEG;AACoB,6BAAU,GAAG,gCAAa,CAAC,UAAU,AAA3B,CAA4B;AA2B7D;;GAEG;AACW,yBAAM,GAAG,kBAAkB,CAAC,MAAM,AAA5B,CAA6B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype ArrayNodeCustomizableSchema,\n\tarraySchema,\n\ttype MapNodeCustomizableSchema,\n\tmapSchema,\n\ttype ObjectNodeSchema,\n\tobjectSchema,\n\ttype RecordNodeCustomizableSchema,\n\trecordSchema,\n} from \"../node-kinds/index.js\";\nimport {\n\tdefaultSchemaFactoryObjectOptions,\n\tscoped,\n\ttype NodeSchemaOptionsAlpha,\n\ttype SchemaFactoryObjectOptions,\n\ttype ScopedSchemaName,\n} from \"./schemaFactory.js\";\nimport { schemaStatics } from \"./schemaStatics.js\";\nimport type { ImplicitAnnotatedFieldSchema, ImplicitFieldSchema } from \"../fieldSchema.js\";\nimport type { RestrictiveStringRecord } from \"../../util/index.js\";\nimport type {\n\tNodeKind,\n\tTreeNodeSchema,\n\tTreeNodeSchemaClass,\n\tImplicitAllowedTypes,\n\tImplicitAnnotatedAllowedTypes,\n\tAnnotatedAllowedType,\n\tLazyItem,\n\tWithType,\n} from \"../core/index.js\";\nimport { normalizeToAnnotatedAllowedType, createSchemaUpgrade } from \"../core/index.js\";\nimport type {\n\tArrayNodeCustomizableSchemaUnsafe,\n\tMapNodeCustomizableSchemaUnsafe,\n\tSystem_Unsafe,\n\tTreeRecordNodeUnsafe,\n} from \"./typesUnsafe.js\";\nimport type { SimpleObjectNodeSchema } from \"../simpleSchema.js\";\nimport { SchemaFactoryBeta } from \"./schemaFactoryBeta.js\";\n\n// These imports prevent a large number of type references in the API reports from showing up as *_2.\n/* eslint-disable unused-imports/no-unused-imports, @typescript-eslint/no-unused-vars, import/no-duplicates */\nimport type {\n\tFieldProps,\n\tFieldSchemaAlpha,\n\tFieldPropsAlpha,\n\tFieldKind,\n} from \"../fieldSchema.js\";\nimport type { LeafSchema } from \"../leafNodeSchema.js\";\nimport type { SimpleLeafNodeSchema } from \"../simpleSchema.js\";\nimport type { UnannotateImplicitAllowedTypes } from \"../core/index.js\";\nimport type { FieldSchemaAlphaUnsafe } from \"./typesUnsafe.js\";\n/* eslint-enable unused-imports/no-unused-imports, @typescript-eslint/no-unused-vars, import/no-duplicates */\n\n/**\n * Stateless APIs exposed via {@link SchemaFactoryAlpha} as both instance properties and as statics.\n * @remarks\n * See {@link SchemaStatics} for why this is useful.\n * @system @sealed @alpha\n */\nexport interface SchemaStaticsAlpha {\n\t/**\n\t * Declares a staged type in a set of {@link AllowedTypes}.\n\t *\n\t * @remarks\n\t * Staged allowed types add support for loading documents which may contain that type at the declared location.\n\t * This allows for an incremental rollout of a schema change to add a {@link TreeNodeSchema} to an {@link AllowedTypes} without breaking cross version collaboration.\n\t * A guide on this process can be found here: https://fluidframework.com/docs/data-structures/tree/schema-evolution/allowed-types-rollout\n\t *\n\t * Once enough clients have the type staged (and thus can read documents which allow it), documents can start being created and upgraded to allow the staged type.\n\t * This is done by deploying a new version of the app which removes the `staged` wrapper around the allowed type in the the schema definition.\n\t * This will also require {@link TreeView.upgradeSchema|upgrading the schema} for existing documents.\n\t *\n\t * Using a staged allowed type in a schema is just like using the schema as an allowed type with the following exceptions:\n\t *\n\t * 1. {@link TreeView.initialize} will omit the staged allowed type from the newly created stored schema.\n\t * 2. {@link TreeView.upgradeSchema} will omit the staged allowed type from the the upgraded stored schema.\n\t * 3. When evaluating {@link TreeView.compatibility}, it will be viewable even if the staged allowed type is not present in the stored schema's corresponding allowed types.\n\t * 4. Because of the above, it is possible to get errors when inserting content which uses the staged allowed type into a tree whose stored schema does not permit it.\n\t *\n\t * Currently, `staged` is not supported in the recursive type APIs: this is a known limitation which future versions of the API will address.\n\t *\n\t * @example\n\t * A full code example of the schema migration process can be found in our {@link https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/test/simple-tree/api/stagedSchemaUpgrade.spec.ts | tests}.\n\t *\n\t * @privateRemarks\n\t * TODO:#44317 staged allowed types rely on schema validation of stored schema to output errors, these errors are not very\n\t * user friendly and should be improved, particularly in the case of staged allowed types\n\t *\n\t * TODO: AB#45711: Update the docs above when recursive type support is added.\n\t */\n\tstaged: <const T extends LazyItem<TreeNodeSchema>>(\n\t\tt: T | AnnotatedAllowedType<T>,\n\t) => AnnotatedAllowedType<T>;\n}\n\nconst schemaStaticsAlpha: SchemaStaticsAlpha = {\n\tstaged: <const T extends LazyItem<TreeNodeSchema>>(\n\t\tt: T | AnnotatedAllowedType<T>,\n\t): AnnotatedAllowedType<T> => {\n\t\tconst annotatedType = normalizeToAnnotatedAllowedType(t);\n\t\treturn {\n\t\t\ttype: annotatedType.type,\n\t\t\tmetadata: {\n\t\t\t\t...annotatedType.metadata,\n\t\t\t\tstagedSchemaUpgrade: createSchemaUpgrade(),\n\t\t\t},\n\t\t};\n\t},\n};\n\n/**\n * {@link SchemaFactory} with additional alpha APIs.\n *\n * @alpha\n * @privateRemarks\n * When building schema, when `options` is not provided, `TCustomMetadata` is inferred as `unknown`.\n * If desired, this could be made to infer `undefined` instead by adding overloads for everything,\n * but currently it is not worth the maintenance overhead as there is no use case which this is known to be helpful for.\n */\nexport class SchemaFactoryAlpha<\n\tout TScope extends string | undefined = string | undefined,\n\tTName extends number | string = string,\n> extends SchemaFactoryBeta<TScope, TName> {\n\t/**\n\t * Define a {@link TreeNodeSchemaClass} for a {@link TreeObjectNode}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.\n\t * @param options - Additional options for the schema.\n\t */\n\tpublic objectAlpha<\n\t\tconst Name extends TName,\n\t\tconst T extends RestrictiveStringRecord<ImplicitAnnotatedFieldSchema>,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tfields: T,\n\t\toptions?: SchemaFactoryObjectOptions<TCustomMetadata>,\n\t): ObjectNodeSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> & {\n\t\t/**\n\t\t * Typing checking workaround: not for for actual use.\n\t\t * @remarks\n\t\t * This API collides with {@link TreeNodeSchemaCore.createFromInsertable} to disable a type checking optimization which produces different and undesired results.\n\t\t * See {@link https://github.com/microsoft/TypeScript/issues/59049#issuecomment-2773459693} for more details.\n\t\t * @privateRemarks\n\t\t * The specific issue here is non-empty POJO mode object schema not being assignable to `ObjectNodeSchema`,\n\t\t * See the above link and the tests in objectNode.spec.ts which reference it.\n\t\t * @system\n\t\t */\n\t\treadonly createFromInsertable: unknown;\n\t} {\n\t\treturn objectSchema(\n\t\t\tscoped<TScope, TName, Name>(this, name),\n\t\t\tfields,\n\t\t\ttrue,\n\t\t\toptions?.allowUnknownOptionalFields ??\n\t\t\t\tdefaultSchemaFactoryObjectOptions.allowUnknownOptionalFields,\n\t\t\toptions?.metadata,\n\t\t\toptions?.persistedMetadata,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritdoc SchemaFactory.objectRecursive}\n\t */\n\tpublic override objectRecursive<\n\t\tconst Name extends TName,\n\t\tconst T extends RestrictiveStringRecord<System_Unsafe.ImplicitFieldSchemaUnsafe>,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tt: T,\n\t\toptions?: SchemaFactoryObjectOptions<TCustomMetadata>,\n\t): TreeNodeSchemaClass<\n\t\tScopedSchemaName<TScope, Name>,\n\t\tNodeKind.Object,\n\t\tSystem_Unsafe.TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>,\n\t\tobject & System_Unsafe.InsertableObjectFromSchemaRecordUnsafe<T>,\n\t\tfalse,\n\t\tT,\n\t\tnever,\n\t\tTCustomMetadata\n\t> &\n\t\tSimpleObjectNodeSchema<TCustomMetadata> &\n\t\t// We can't just use non generic `ObjectNodeSchema` here since \"Base constructors must all have the same return type\".\n\t\t// We also can't just use generic `ObjectNodeSchema` here and not `TreeNodeSchemaClass` since that doesn't work with unsafe recursive types.\n\t\t// ObjectNodeSchema<\n\t\t// \tScopedSchemaName<TScope, Name>,\n\t\t// \t// T & RestrictiveStringRecord<ImplicitFieldSchema> would be nice to use here, but it breaks the recursive type self references.\n\t\t// \tRestrictiveStringRecord<ImplicitFieldSchema>,\n\t\t// \tfalse,\n\t\t// \tTCustomMetadata\n\t\t// >\n\t\tPick<ObjectNodeSchema, \"fields\"> {\n\t\t// TODO: syntax highting is vs code is broken here. Don't trust it. Use the compiler instead.\n\t\ttype TScopedName = ScopedSchemaName<TScope, Name>;\n\t\treturn this.objectAlpha(\n\t\t\tname,\n\t\t\tt as T & RestrictiveStringRecord<ImplicitFieldSchema>,\n\t\t\toptions,\n\t\t) as unknown as TreeNodeSchemaClass<\n\t\t\tTScopedName,\n\t\t\tNodeKind.Object,\n\t\t\tSystem_Unsafe.TreeObjectNodeUnsafe<T, TScopedName>,\n\t\t\tobject & System_Unsafe.InsertableObjectFromSchemaRecordUnsafe<T>,\n\t\t\tfalse,\n\t\t\tT,\n\t\t\tnever,\n\t\t\tTCustomMetadata\n\t\t> &\n\t\t\tObjectNodeSchema<\n\t\t\t\tScopedSchemaName<TScope, Name>,\n\t\t\t\tRestrictiveStringRecord<ImplicitFieldSchema>,\n\t\t\t\tfalse,\n\t\t\t\tTCustomMetadata\n\t\t\t>;\n\t}\n\n\t/**\n\t * {@inheritDoc SchemaStatics.leaves}\n\t */\n\tpublic static override readonly leaves = schemaStatics.leaves;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.optional}\n\t */\n\tpublic static override readonly optional = schemaStatics.optional;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.required}\n\t */\n\tpublic static override readonly required = schemaStatics.required;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.optionalRecursive}\n\t */\n\tpublic static override readonly optionalRecursive = schemaStatics.optionalRecursive;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.requiredRecursive}\n\t */\n\tpublic static override readonly requiredRecursive = schemaStatics.requiredRecursive;\n\n\t/**\n\t * Like {@link SchemaFactory.identifier} but static and a factory function that can be provided {@link FieldProps}.\n\t */\n\tpublic static readonly identifier = schemaStatics.identifier;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.leaves}\n\t */\n\tpublic override readonly leaves = schemaStatics.leaves;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.optional}\n\t */\n\tpublic override readonly optional = schemaStatics.optional;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.required}\n\t */\n\tpublic override readonly required = schemaStatics.required;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.optionalRecursive}\n\t */\n\tpublic override readonly optionalRecursive = schemaStatics.optionalRecursive;\n\n\t/**\n\t * {@inheritDoc SchemaStatics.requiredRecursive}\n\t */\n\tpublic override readonly requiredRecursive = schemaStatics.requiredRecursive;\n\n\t/**\n\t * {@inheritDoc SchemaStaticsAlpha.staged}\n\t */\n\tpublic static staged = schemaStaticsAlpha.staged;\n\n\t/**\n\t * {@inheritDoc SchemaStaticsAlpha.staged}\n\t */\n\tpublic staged = schemaStaticsAlpha.staged;\n\n\t/**\n\t * Define a {@link TreeNodeSchema} for a {@link TreeMapNode}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param allowedTypes - The types that may appear as values in the map.\n\t * @param options - Additional options for the schema.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedMap extends factory.map(\"name\", factory.number, {\n\t * \tmetadata: { description: \"A map of numbers\" }\n\t * }) {}\n\t * ```\n\t */\n\tpublic mapAlpha<\n\t\tName extends TName,\n\t\tconst T extends ImplicitAnnotatedAllowedTypes,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\toptions?: NodeSchemaOptionsAlpha<TCustomMetadata>,\n\t): MapNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> {\n\t\treturn mapSchema(\n\t\t\tscoped<TScope, TName, Name>(this, name),\n\t\t\tallowedTypes,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t\toptions?.metadata,\n\t\t\toptions?.persistedMetadata,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc SchemaFactory.objectRecursive}\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tpublic override mapRecursive<\n\t\tName extends TName,\n\t\tconst T extends System_Unsafe.ImplicitAllowedTypesUnsafe,\n\t\tconst TCustomMetadata = unknown,\n\t>(name: Name, allowedTypes: T, options?: NodeSchemaOptionsAlpha<TCustomMetadata>) {\n\t\treturn this.mapAlpha(\n\t\t\tname,\n\t\t\tallowedTypes as T & ImplicitAllowedTypes,\n\t\t\toptions,\n\t\t) as unknown as MapNodeCustomizableSchemaUnsafe<\n\t\t\tScopedSchemaName<TScope, Name>,\n\t\t\tT,\n\t\t\tTCustomMetadata\n\t\t>;\n\t}\n\n\t/**\n\t * Define a {@link TreeNodeSchemaClass} for a {@link (TreeArrayNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param allowedTypes - The types that may appear in the array.\n\t * @param options - Additional options for the schema.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedArray extends factory.arrayAlpha(\"name\", factory.number) {}\n\t * ```\n\t */\n\tpublic arrayAlpha<\n\t\tconst Name extends TName,\n\t\tconst T extends ImplicitAnnotatedAllowedTypes,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\toptions?: NodeSchemaOptionsAlpha<TCustomMetadata>,\n\t): ArrayNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> {\n\t\treturn arraySchema(\n\t\t\tscoped<TScope, TName, Name>(this, name),\n\t\t\tallowedTypes,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t\toptions?.metadata,\n\t\t\toptions?.persistedMetadata,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc SchemaFactory.objectRecursive}\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tpublic override arrayRecursive<\n\t\tconst Name extends TName,\n\t\tconst T extends System_Unsafe.ImplicitAllowedTypesUnsafe,\n\t\tconst TCustomMetadata = unknown,\n\t>(name: Name, allowedTypes: T, options?: NodeSchemaOptionsAlpha<TCustomMetadata>) {\n\t\treturn this.arrayAlpha(\n\t\t\tname,\n\t\t\tallowedTypes as T & ImplicitAllowedTypes,\n\t\t\toptions,\n\t\t) as unknown as ArrayNodeCustomizableSchemaUnsafe<\n\t\t\tScopedSchemaName<TScope, Name>,\n\t\t\tT,\n\t\t\tTCustomMetadata\n\t\t>;\n\t}\n\n\t/**\n\t * Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeRecordNode:interface)}.\n\t *\n\t * @param name - Unique identifier for this schema within this factory's scope.\n\t * @param allowedTypes - The types that may appear in the record.\n\t * @param options - Additional options for the schema.\n\t *\n\t * @example\n\t * ```typescript\n\t * class NamedRecord extends factory.recordAlpha(\"name\", factory.number) {}\n\t * ```\n\t */\n\tpublic recordAlpha<\n\t\tconst Name extends TName,\n\t\tconst T extends ImplicitAnnotatedAllowedTypes,\n\t\tconst TCustomMetadata = unknown,\n\t>(\n\t\tname: Name,\n\t\tallowedTypes: T,\n\t\toptions?: NodeSchemaOptionsAlpha<TCustomMetadata>,\n\t): RecordNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> {\n\t\treturn recordSchema({\n\t\t\tidentifier: scoped<TScope, TName, Name>(this, name),\n\t\t\tinfo: allowedTypes,\n\t\t\tcustomizable: true,\n\t\t\timplicitlyConstructable: true,\n\t\t\tmetadata: options?.metadata,\n\t\t\tpersistedMetadata: options?.persistedMetadata,\n\t\t});\n\t}\n\n\t/**\n\t * {@link SchemaFactoryBeta.(record:2)} except tweaked to work better for recursive types.\n\t * Use with {@link ValidateRecursiveSchema} for improved type safety.\n\t * @remarks\n\t * This version of `SchemaFactory.record` uses the same workarounds as {@link SchemaFactory.objectRecursive}.\n\t * See {@link ValidateRecursiveSchema} for additional information about using recursive schema.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n\tpublic override recordRecursive<\n\t\tName extends TName,\n\t\tconst T extends System_Unsafe.ImplicitAllowedTypesUnsafe,\n\t\tconst TCustomMetadata = unknown,\n\t>(name: Name, allowedTypes: T, options?: NodeSchemaOptionsAlpha<TCustomMetadata>) {\n\t\tconst RecordSchema = recordSchema({\n\t\t\tidentifier: scoped<TScope, TName, Name>(this, name),\n\t\t\tinfo: allowedTypes as T & ImplicitAllowedTypes,\n\t\t\tcustomizable: true,\n\t\t\t// Setting this to true seems to work ok currently, but not for other node kinds.\n\t\t\t// Supporting this could be fragile and might break other future changes, so it's being kept as false for now.\n\t\t\timplicitlyConstructable: false,\n\t\t\tmetadata: options?.metadata,\n\t\t\tpersistedMetadata: options?.persistedMetadata,\n\t\t});\n\n\t\treturn RecordSchema as TreeNodeSchemaClass<\n\t\t\t/* Name */ ScopedSchemaName<TScope, Name>,\n\t\t\t/* Kind */ NodeKind.Record,\n\t\t\t/* TNode */ TreeRecordNodeUnsafe<T> &\n\t\t\t\tWithType<ScopedSchemaName<TScope, Name>, NodeKind.Record>,\n\t\t\t/* TInsertable */ {\n\t\t\t\t// Ideally this would be\n\t\t\t\t// RestrictiveStringRecord<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>,\n\t\t\t\t// but doing so breaks recursive types.\n\t\t\t\t// Instead we do a less nice version:\n\t\t\t\treadonly [P in string]: System_Unsafe.InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>;\n\t\t\t},\n\t\t\t/* ImplicitlyConstructable */ false,\n\t\t\t/* Info */ T,\n\t\t\t/* TConstructorExtra */ undefined,\n\t\t\t/* TCustomMetadata */ TCustomMetadata\n\t\t>;\n\t}\n\n\t/**\n\t * {@inheritDoc SchemaFactoryBeta.scopedFactory}\n\t */\n\tpublic scopedFactoryAlpha<\n\t\tconst T extends TName,\n\t\tTNameInner extends number | string = string,\n\t>(name: T): SchemaFactoryAlpha<ScopedSchemaName<TScope, T>, TNameInner> {\n\t\treturn new SchemaFactoryAlpha(scoped<TScope, TName, T>(this, name));\n\t}\n}\n"]}
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import type { ImplicitAllowedTypes, NodeKind, TreeNodeSchema, TreeNodeSchemaClass, TreeNodeSchemaNonClass, WithType } from "../core/index.js";
|
|
6
|
+
import { type RecordNodeInsertableData, type TreeRecordNode } from "../node-kinds/index.js";
|
|
7
|
+
import { SchemaFactory, type NodeSchemaOptions, type ScopedSchemaName } from "./schemaFactory.js";
|
|
8
|
+
import type { System_Unsafe, TreeRecordNodeUnsafe } from "./typesUnsafe.js";
|
|
6
9
|
/**
|
|
7
10
|
* {@link SchemaFactory} with additional beta APIs.
|
|
8
11
|
* @beta
|
|
@@ -16,5 +19,91 @@ export declare class SchemaFactoryBeta<out TScope extends string | undefined = s
|
|
|
16
19
|
* Creating such related schema using a sub-scope helps ensure they won't collide with other schema in the parent scope.
|
|
17
20
|
*/
|
|
18
21
|
scopedFactory<const T extends TName, TNameInner extends number | string = string>(name: T): SchemaFactoryBeta<ScopedSchemaName<TScope, T>, TNameInner>;
|
|
22
|
+
/**
|
|
23
|
+
* Define a structurally typed {@link TreeNodeSchema} for a {@link (TreeRecordNode:interface)}.
|
|
24
|
+
*
|
|
25
|
+
* @param allowedTypes - The types that may appear in the record.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* The identifier for this record is defined as a function of the provided types.
|
|
29
|
+
* It is still scoped to this `SchemaFactory`, but multiple calls with the same arguments will return the same
|
|
30
|
+
* schema object, providing somewhat structural typing.
|
|
31
|
+
* This does not support recursive types.
|
|
32
|
+
*
|
|
33
|
+
* If using these structurally named records, other types in this schema builder should avoid names of the form `Record<${string}>`.
|
|
34
|
+
*
|
|
35
|
+
* The underlying data format for `Record` nodes is the same as that for `Map` nodes.
|
|
36
|
+
* Therefore, changing an existing `Map` schema to a `Record` schema (or vice versa) is
|
|
37
|
+
* a non-breaking change and does not require schema migration.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* The returned schema should be used as a schema directly:
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const MyRecord = factory.record(factory.number);
|
|
43
|
+
* type MyRecord = NodeFromSchema<typeof Record>;
|
|
44
|
+
* ```
|
|
45
|
+
* Or inline:
|
|
46
|
+
* ```typescript
|
|
47
|
+
* factory.object("Foo", { myRecord: factory.record(factory.number) });
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @privateRemarks
|
|
51
|
+
* The name produced at the type-level here is not as specific as it could be; however, doing type-level sorting and escaping is a real mess.
|
|
52
|
+
* There are cases where not having this full type provided will be less than ideal, since TypeScript's structural types will allow assignment between runtime incompatible types at compile time.
|
|
53
|
+
* For example, attempts to narrow unions of structural records by name won't work.
|
|
54
|
+
* Planned future changes to move to a class based schema system as well as factor function based node construction should mostly avoid these issues,
|
|
55
|
+
* though there may still be some problematic cases even after that work is done.
|
|
56
|
+
*
|
|
57
|
+
* The return value is a class, but its type is intentionally not specific enough to indicate it is a class.
|
|
58
|
+
* This prevents callers of this from sub-classing it, which is unlikely to work well (due to the ease of accidentally giving two different calls to this different subclasses)
|
|
59
|
+
* when working with structural typing.
|
|
60
|
+
*
|
|
61
|
+
* {@label STRUCTURAL}
|
|
62
|
+
*/
|
|
63
|
+
record<const T extends TreeNodeSchema | readonly TreeNodeSchema[]>(allowedTypes: T): TreeNodeSchemaNonClass<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record, TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, `Record<${string}>`>, NodeKind.Record>, RecordNodeInsertableData<T>, true, T, undefined>;
|
|
64
|
+
/**
|
|
65
|
+
* Define (and add to this library) a {@link TreeNodeSchemaClass} for a {@link (TreeRecordNode:interface)}.
|
|
66
|
+
*
|
|
67
|
+
* @param name - Unique identifier for this schema within this factory's scope.
|
|
68
|
+
* @param allowedTypes - The types that may appear in the record.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* The underlying data format for `Record` nodes is the same as that for `Map` nodes.
|
|
72
|
+
* Therefore, changing an existing `Map` schema to a `Record` schema (or vice versa) is
|
|
73
|
+
* a non-breaking change and does not require schema migration.
|
|
74
|
+
*
|
|
75
|
+
* Like TypeScript `Record`s, record nodes have some potential pitfalls.
|
|
76
|
+
* For example: TypeScript makes assumptions about built-in keys being present (e.g. `toString`, `hasOwnProperty`, etc.).
|
|
77
|
+
* Since these are otherwise valid keys in a record, this can lead to unexpected behavior.
|
|
78
|
+
* To prevent inconsistent behavior, these built-ins are hidden by record nodes.
|
|
79
|
+
* This means that if you try to call these built-ins (e.g. `toString()`) on a record node, you will get an error.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* class NamedRecord extends factory.record("name", factory.number) {}
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* {@label NAMED}
|
|
87
|
+
*/
|
|
88
|
+
record<const Name extends TName, const T extends ImplicitAllowedTypes>(name: Name, allowedTypes: T): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Record, TreeRecordNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Record>, RecordNodeInsertableData<T>, true, T, undefined>;
|
|
89
|
+
/**
|
|
90
|
+
* Define a {@link TreeNodeSchema} for a {@link (TreeRecordNode:interface)}.
|
|
91
|
+
*
|
|
92
|
+
* @param name - Unique identifier for this schema within this factory's scope.
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* This is not intended to be used directly, use the overload of `record` which takes a name instead.
|
|
96
|
+
*/
|
|
97
|
+
private namedRecord;
|
|
98
|
+
/**
|
|
99
|
+
* {@link SchemaFactoryBeta.(record:2)} except tweaked to work better for recursive types.
|
|
100
|
+
* Use with {@link ValidateRecursiveSchema} for improved type safety.
|
|
101
|
+
* @remarks
|
|
102
|
+
* This version of `SchemaFactory.record` uses the same workarounds as {@link SchemaFactory.objectRecursive}.
|
|
103
|
+
* See {@link ValidateRecursiveSchema} for additional information about using recursive schema.
|
|
104
|
+
*/
|
|
105
|
+
recordRecursive<Name extends TName, const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Record, TreeRecordNodeUnsafe<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Record, unknown>, {
|
|
106
|
+
readonly [x: string]: System_Unsafe.InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>;
|
|
107
|
+
}, false, T, undefined, TCustomMetadata>;
|
|
19
108
|
}
|
|
20
109
|
//# sourceMappingURL=schemaFactoryBeta.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaFactoryBeta.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFactoryBeta.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"schemaFactoryBeta.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaFactoryBeta.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,oBAAoB,EACpB,QAAQ,EACR,cAAc,EAEd,mBAAmB,EACnB,sBAAsB,EACtB,QAAQ,EACR,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEN,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,aAAa,EAGb,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAc5E;;;;GAIG;AACH,qBAAa,iBAAiB,CAC7B,GAAG,CAAC,MAAM,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,EAC1D,KAAK,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,CACrC,SAAQ,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC;IACrC;;;;;OAKG;IACI,aAAa,CAAC,KAAK,CAAC,CAAC,SAAS,KAAK,EAAE,UAAU,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EACtF,IAAI,EAAE,CAAC,GACL,iBAAiB,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC;IAI7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACI,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,SAAS,cAAc,EA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