@fluidframework/tree 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +12 -1
- package/CHANGELOG.md +371 -0
- package/api-report/tree.alpha.api.md +271 -80
- package/api-report/tree.beta.api.md +100 -51
- package/api-report/tree.legacy.alpha.api.md +99 -50
- package/api-report/tree.legacy.public.api.md +99 -50
- package/api-report/tree.public.api.md +99 -50
- package/dist/alpha.d.ts +32 -2
- package/dist/beta.d.ts +6 -0
- package/dist/codec/codec.d.ts +24 -0
- package/dist/codec/codec.d.ts.map +1 -1
- package/dist/codec/codec.js +26 -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 +2 -1
- package/dist/codec/index.js.map +1 -1
- package/dist/core/rebase/index.d.ts +2 -2
- package/dist/core/rebase/index.d.ts.map +1 -1
- package/dist/core/rebase/index.js +2 -2
- package/dist/core/rebase/index.js.map +1 -1
- package/dist/core/rebase/types.d.ts +0 -4
- package/dist/core/rebase/types.d.ts.map +1 -1
- package/dist/core/rebase/types.js +1 -7
- package/dist/core/rebase/types.js.map +1 -1
- package/dist/core/rebase/utils.d.ts +1 -0
- package/dist/core/rebase/utils.d.ts.map +1 -1
- package/dist/core/rebase/utils.js +29 -4
- package/dist/core/rebase/utils.js.map +1 -1
- package/dist/events/interop.d.ts +1 -7
- package/dist/events/interop.d.ts.map +1 -1
- package/dist/events/interop.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/basicChunk.js +1 -1
- package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/uniformChunk.js +1 -1
- package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +8 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts +2 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.js +3 -0
- package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/dist/feature-libraries/object-forest/objectForest.js +1 -1
- package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
- package/dist/feature-libraries/treeCursorUtils.js +2 -2
- package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/dist/internalTypes.d.ts +1 -1
- package/dist/internalTypes.d.ts.map +1 -1
- package/dist/internalTypes.js.map +1 -1
- package/dist/legacy.d.ts +6 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/public.d.ts +6 -0
- package/dist/shared-tree/independentView.d.ts +57 -0
- package/dist/shared-tree/independentView.d.ts.map +1 -0
- package/dist/shared-tree/independentView.js +89 -0
- package/dist/shared-tree/independentView.js.map +1 -0
- package/dist/shared-tree/index.d.ts +3 -1
- package/dist/shared-tree/index.d.ts.map +1 -1
- package/dist/shared-tree/index.js +6 -1
- package/dist/shared-tree/index.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts +12 -8
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +28 -0
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +10 -7
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/treeApi.d.ts +6 -6
- package/dist/shared-tree/treeApi.d.ts.map +1 -1
- package/dist/shared-tree/treeApi.js.map +1 -1
- package/dist/shared-tree/treeApiAlpha.d.ts +147 -0
- package/dist/shared-tree/treeApiAlpha.d.ts.map +1 -0
- package/dist/shared-tree/treeApiAlpha.js +122 -0
- package/dist/shared-tree/treeApiAlpha.js.map +1 -0
- package/dist/shared-tree/treeCheckout.d.ts +12 -7
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +11 -4
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/editManager.d.ts +13 -6
- package/dist/shared-tree-core/editManager.d.ts.map +1 -1
- package/dist/shared-tree-core/editManager.js +80 -33
- package/dist/shared-tree-core/editManager.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts +1 -0
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +28 -3
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/conciseTree.d.ts +2 -1
- package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/conciseTree.js.map +1 -1
- package/dist/simple-tree/api/create.d.ts +6 -24
- package/dist/simple-tree/api/create.d.ts.map +1 -1
- package/dist/simple-tree/api/create.js +4 -19
- package/dist/simple-tree/api/create.js.map +1 -1
- package/dist/simple-tree/api/customTree.d.ts +1 -0
- package/dist/simple-tree/api/customTree.d.ts.map +1 -1
- package/dist/simple-tree/api/customTree.js +2 -2
- package/dist/simple-tree/api/customTree.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +7 -7
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +10 -2
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.d.ts +25 -27
- package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.js +31 -21
- package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +16 -12
- package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactory.js +4 -0
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +3 -3
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/storedSchema.js +2 -2
- package/dist/simple-tree/api/storedSchema.js.map +1 -1
- package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
- package/dist/simple-tree/api/tree.d.ts +122 -5
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js +12 -4
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/treeApiBeta.d.ts +8 -5
- package/dist/simple-tree/api/treeApiBeta.d.ts.map +1 -1
- package/dist/simple-tree/api/treeApiBeta.js +3 -15
- package/dist/simple-tree/api/treeApiBeta.js.map +1 -1
- package/dist/simple-tree/api/typesUnsafe.d.ts +69 -17
- package/dist/simple-tree/api/typesUnsafe.d.ts.map +1 -1
- package/dist/simple-tree/api/typesUnsafe.js.map +1 -1
- package/dist/simple-tree/api/verboseTree.d.ts +3 -0
- package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/verboseTree.js.map +1 -1
- package/dist/simple-tree/arrayNode.d.ts +15 -4
- package/dist/simple-tree/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/arrayNode.js +1 -1
- package/dist/simple-tree/arrayNode.js.map +1 -1
- package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.d.ts +51 -11
- package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts +2 -1
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js +3 -0
- package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/dist/simple-tree/core/withType.d.ts +2 -1
- package/dist/simple-tree/core/withType.d.ts.map +1 -1
- package/dist/simple-tree/core/withType.js.map +1 -1
- package/dist/simple-tree/createContext.js +2 -2
- package/dist/simple-tree/createContext.js.map +1 -1
- package/dist/simple-tree/index.d.ts +6 -6
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +15 -5
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/leafNodeSchema.d.ts +6 -5
- package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/leafNodeSchema.js +3 -0
- package/dist/simple-tree/leafNodeSchema.js.map +1 -1
- package/dist/simple-tree/mapNode.d.ts +1 -1
- package/dist/simple-tree/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/mapNode.js +6 -0
- package/dist/simple-tree/mapNode.js.map +1 -1
- package/dist/simple-tree/objectNode.d.ts +4 -2
- package/dist/simple-tree/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/objectNode.js.map +1 -1
- package/dist/simple-tree/schemaTypes.d.ts +210 -18
- package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
- package/dist/simple-tree/schemaTypes.js +66 -1
- package/dist/simple-tree/schemaTypes.js.map +1 -1
- package/dist/simple-tree/toMapTree.d.ts +4 -2
- package/dist/simple-tree/toMapTree.d.ts.map +1 -1
- package/dist/simple-tree/toMapTree.js.map +1 -1
- package/dist/simple-tree/{toFlexSchema.d.ts → toStoredSchema.d.ts} +1 -1
- package/dist/simple-tree/toStoredSchema.d.ts.map +1 -0
- package/dist/simple-tree/{toFlexSchema.js → toStoredSchema.js} +1 -1
- package/dist/simple-tree/toStoredSchema.js.map +1 -0
- package/dist/simple-tree/treeNodeValid.d.ts +5 -1
- package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
- package/dist/simple-tree/treeNodeValid.js +7 -1
- package/dist/simple-tree/treeNodeValid.js.map +1 -1
- package/dist/util/index.d.ts +3 -2
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +3 -1
- package/dist/util/index.js.map +1 -1
- package/dist/util/typeCheck.d.ts +9 -0
- package/dist/util/typeCheck.d.ts.map +1 -1
- package/dist/util/typeCheck.js.map +1 -1
- package/dist/util/typeUtils.d.ts +61 -0
- package/dist/util/typeUtils.d.ts.map +1 -1
- package/dist/util/typeUtils.js +27 -0
- package/dist/util/typeUtils.js.map +1 -1
- package/dist/util/utils.d.ts +7 -3
- package/dist/util/utils.d.ts.map +1 -1
- package/dist/util/utils.js +13 -3
- package/dist/util/utils.js.map +1 -1
- package/lib/alpha.d.ts +32 -2
- package/lib/beta.d.ts +6 -0
- package/lib/codec/codec.d.ts +24 -0
- package/lib/codec/codec.d.ts.map +1 -1
- package/lib/codec/codec.js +25 -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/rebase/index.d.ts +2 -2
- package/lib/core/rebase/index.d.ts.map +1 -1
- package/lib/core/rebase/index.js +2 -2
- package/lib/core/rebase/index.js.map +1 -1
- package/lib/core/rebase/types.d.ts +0 -4
- package/lib/core/rebase/types.d.ts.map +1 -1
- package/lib/core/rebase/types.js +0 -5
- package/lib/core/rebase/types.js.map +1 -1
- package/lib/core/rebase/utils.d.ts +1 -0
- package/lib/core/rebase/utils.d.ts.map +1 -1
- package/lib/core/rebase/utils.js +27 -3
- package/lib/core/rebase/utils.js.map +1 -1
- package/lib/events/interop.d.ts +1 -7
- package/lib/events/interop.d.ts.map +1 -1
- package/lib/events/interop.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/basicChunk.js +1 -1
- package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/uniformChunk.js +1 -1
- package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +8 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts +2 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.js +3 -0
- package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/lib/feature-libraries/object-forest/objectForest.js +1 -1
- package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
- package/lib/feature-libraries/treeCursorUtils.js +2 -2
- package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -3
- package/lib/index.js.map +1 -1
- package/lib/internalTypes.d.ts +1 -1
- package/lib/internalTypes.d.ts.map +1 -1
- package/lib/internalTypes.js.map +1 -1
- package/lib/legacy.d.ts +6 -0
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/public.d.ts +6 -0
- package/lib/shared-tree/independentView.d.ts +57 -0
- package/lib/shared-tree/independentView.d.ts.map +1 -0
- package/lib/shared-tree/independentView.js +84 -0
- package/lib/shared-tree/independentView.js.map +1 -0
- package/lib/shared-tree/index.d.ts +3 -1
- package/lib/shared-tree/index.d.ts.map +1 -1
- package/lib/shared-tree/index.js +2 -0
- package/lib/shared-tree/index.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts +12 -8
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +29 -1
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +10 -7
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/treeApi.d.ts +6 -6
- package/lib/shared-tree/treeApi.d.ts.map +1 -1
- package/lib/shared-tree/treeApi.js.map +1 -1
- package/lib/shared-tree/treeApiAlpha.d.ts +147 -0
- package/lib/shared-tree/treeApiAlpha.d.ts.map +1 -0
- package/lib/shared-tree/treeApiAlpha.js +119 -0
- package/lib/shared-tree/treeApiAlpha.js.map +1 -0
- package/lib/shared-tree/treeCheckout.d.ts +12 -7
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +11 -4
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/editManager.d.ts +13 -6
- package/lib/shared-tree-core/editManager.d.ts.map +1 -1
- package/lib/shared-tree-core/editManager.js +80 -33
- package/lib/shared-tree-core/editManager.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts +1 -0
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +29 -4
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/conciseTree.d.ts +2 -1
- package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/conciseTree.js.map +1 -1
- package/lib/simple-tree/api/create.d.ts +6 -24
- package/lib/simple-tree/api/create.d.ts.map +1 -1
- package/lib/simple-tree/api/create.js +2 -16
- package/lib/simple-tree/api/create.js.map +1 -1
- package/lib/simple-tree/api/customTree.d.ts +1 -0
- package/lib/simple-tree/api/customTree.d.ts.map +1 -1
- package/lib/simple-tree/api/customTree.js +2 -2
- package/lib/simple-tree/api/customTree.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +7 -7
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +6 -4
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.d.ts +25 -27
- package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.js +30 -19
- package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +16 -12
- package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactory.js +4 -0
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +3 -3
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/storedSchema.js +1 -1
- package/lib/simple-tree/api/storedSchema.js.map +1 -1
- package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
- package/lib/simple-tree/api/tree.d.ts +122 -5
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js +9 -2
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/treeApiBeta.d.ts +8 -5
- package/lib/simple-tree/api/treeApiBeta.d.ts.map +1 -1
- package/lib/simple-tree/api/treeApiBeta.js +4 -16
- package/lib/simple-tree/api/treeApiBeta.js.map +1 -1
- package/lib/simple-tree/api/typesUnsafe.d.ts +69 -17
- package/lib/simple-tree/api/typesUnsafe.d.ts.map +1 -1
- package/lib/simple-tree/api/typesUnsafe.js.map +1 -1
- package/lib/simple-tree/api/verboseTree.d.ts +3 -0
- package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/verboseTree.js.map +1 -1
- package/lib/simple-tree/arrayNode.d.ts +15 -4
- package/lib/simple-tree/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/arrayNode.js +1 -1
- package/lib/simple-tree/arrayNode.js.map +1 -1
- package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.d.ts +51 -11
- package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts +2 -1
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js +4 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/lib/simple-tree/core/withType.d.ts +2 -1
- package/lib/simple-tree/core/withType.d.ts.map +1 -1
- package/lib/simple-tree/core/withType.js.map +1 -1
- package/lib/simple-tree/createContext.js +1 -1
- package/lib/simple-tree/createContext.js.map +1 -1
- package/lib/simple-tree/index.d.ts +6 -6
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +5 -5
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/leafNodeSchema.d.ts +6 -5
- package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/leafNodeSchema.js +3 -0
- package/lib/simple-tree/leafNodeSchema.js.map +1 -1
- package/lib/simple-tree/mapNode.d.ts +1 -1
- package/lib/simple-tree/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/mapNode.js +6 -0
- package/lib/simple-tree/mapNode.js.map +1 -1
- package/lib/simple-tree/objectNode.d.ts +4 -2
- package/lib/simple-tree/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/objectNode.js.map +1 -1
- package/lib/simple-tree/schemaTypes.d.ts +210 -18
- package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
- package/lib/simple-tree/schemaTypes.js +64 -1
- package/lib/simple-tree/schemaTypes.js.map +1 -1
- package/lib/simple-tree/toMapTree.d.ts +4 -2
- package/lib/simple-tree/toMapTree.d.ts.map +1 -1
- package/lib/simple-tree/toMapTree.js.map +1 -1
- package/lib/simple-tree/{toFlexSchema.d.ts → toStoredSchema.d.ts} +1 -1
- package/lib/simple-tree/toStoredSchema.d.ts.map +1 -0
- package/lib/simple-tree/{toFlexSchema.js → toStoredSchema.js} +1 -1
- package/lib/simple-tree/toStoredSchema.js.map +1 -0
- package/lib/simple-tree/treeNodeValid.d.ts +5 -1
- package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
- package/lib/simple-tree/treeNodeValid.js +7 -1
- package/lib/simple-tree/treeNodeValid.js.map +1 -1
- package/lib/util/index.d.ts +3 -2
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +1 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/typeCheck.d.ts +9 -0
- package/lib/util/typeCheck.d.ts.map +1 -1
- package/lib/util/typeCheck.js.map +1 -1
- package/lib/util/typeUtils.d.ts +61 -0
- package/lib/util/typeUtils.d.ts.map +1 -1
- package/lib/util/typeUtils.js +25 -1
- package/lib/util/typeUtils.js.map +1 -1
- package/lib/util/utils.d.ts +7 -3
- package/lib/util/utils.d.ts.map +1 -1
- package/lib/util/utils.js +13 -3
- package/lib/util/utils.js.map +1 -1
- package/package.json +55 -30
- package/src/codec/codec.ts +25 -0
- package/src/codec/index.ts +1 -0
- package/src/core/rebase/index.ts +1 -1
- package/src/core/rebase/types.ts +0 -12
- package/src/core/rebase/utils.ts +35 -3
- package/src/events/interop.ts +1 -12
- package/src/feature-libraries/chunked-forest/basicChunk.ts +1 -1
- package/src/feature-libraries/chunked-forest/uniformChunk.ts +1 -1
- package/src/feature-libraries/flex-tree/flexTreeTypes.ts +9 -0
- package/src/feature-libraries/flex-tree/lazyNode.ts +5 -0
- package/src/feature-libraries/object-forest/objectForest.ts +1 -1
- package/src/feature-libraries/treeCursorUtils.ts +2 -2
- package/src/index.ts +36 -6
- package/src/internalTypes.ts +4 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/independentView.ts +176 -0
- package/src/shared-tree/index.ts +9 -1
- package/src/shared-tree/schematizingTreeView.ts +64 -13
- package/src/shared-tree/sharedTree.ts +29 -9
- package/src/shared-tree/treeApi.ts +19 -9
- package/src/shared-tree/treeApiAlpha.ts +401 -0
- package/src/shared-tree/treeCheckout.ts +28 -5
- package/src/shared-tree-core/editManager.ts +126 -59
- package/src/shared-tree-core/sharedTreeCore.ts +37 -8
- package/src/simple-tree/api/conciseTree.ts +2 -1
- package/src/simple-tree/api/create.ts +33 -65
- package/src/simple-tree/api/customTree.ts +3 -2
- package/src/simple-tree/api/index.ts +19 -8
- package/src/simple-tree/api/schemaCreationUtilities.ts +59 -37
- package/src/simple-tree/api/schemaFactory.ts +28 -12
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +3 -3
- package/src/simple-tree/api/storedSchema.ts +1 -1
- package/src/simple-tree/api/tree.ts +152 -7
- package/src/simple-tree/api/treeApiBeta.ts +35 -31
- package/src/simple-tree/api/typesUnsafe.ts +125 -30
- package/src/simple-tree/api/verboseTree.ts +3 -0
- package/src/simple-tree/arrayNode.ts +38 -17
- package/src/simple-tree/core/getOrCreateNode.ts +1 -1
- package/src/simple-tree/core/treeNodeSchema.ts +107 -34
- package/src/simple-tree/core/unhydratedFlexTree.ts +6 -0
- package/src/simple-tree/core/withType.ts +2 -1
- package/src/simple-tree/createContext.ts +1 -1
- package/src/simple-tree/index.ts +34 -3
- package/src/simple-tree/leafNodeSchema.ts +6 -1
- package/src/simple-tree/mapNode.ts +13 -4
- package/src/simple-tree/objectNode.ts +5 -3
- package/src/simple-tree/schemaTypes.ts +342 -36
- package/src/simple-tree/toMapTree.ts +4 -1
- package/src/simple-tree/treeNodeValid.ts +11 -1
- package/src/util/index.ts +7 -0
- package/src/util/typeCheck.ts +13 -0
- package/src/util/typeUtils.ts +87 -0
- package/src/util/utils.ts +20 -7
- package/dist/simple-tree/toFlexSchema.d.ts.map +0 -1
- package/dist/simple-tree/toFlexSchema.js.map +0 -1
- package/lib/simple-tree/toFlexSchema.d.ts.map +0 -1
- package/lib/simple-tree/toFlexSchema.js.map +0 -1
- /package/src/simple-tree/{toFlexSchema.ts → toStoredSchema.ts} +0 -0
|
@@ -8,12 +8,22 @@ import { Lazy } from "@fluidframework/core-utils/internal";
|
|
|
8
8
|
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
9
9
|
|
|
10
10
|
import type { NodeKeyManager } from "../feature-libraries/index.js";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
type MakeNominal,
|
|
13
|
+
brand,
|
|
14
|
+
isReadonlyArray,
|
|
15
|
+
type UnionToIntersection,
|
|
16
|
+
compareSets,
|
|
17
|
+
type requireTrue,
|
|
18
|
+
type areOnlyKeys,
|
|
19
|
+
} from "../util/index.js";
|
|
12
20
|
import type {
|
|
13
21
|
Unhydrated,
|
|
14
22
|
NodeKind,
|
|
15
23
|
TreeNodeSchema,
|
|
16
24
|
TreeNodeSchemaClass,
|
|
25
|
+
TreeNode,
|
|
26
|
+
TreeNodeSchemaCore,
|
|
17
27
|
} from "./core/index.js";
|
|
18
28
|
import type { FieldKey } from "../core/index.js";
|
|
19
29
|
import type { InsertableContent } from "./toMapTree.js";
|
|
@@ -25,13 +35,22 @@ import { isLazy, type FlexListToUnion, type LazyItem } from "./flexList.js";
|
|
|
25
35
|
export function isTreeNodeSchemaClass<
|
|
26
36
|
Name extends string,
|
|
27
37
|
Kind extends NodeKind,
|
|
28
|
-
TNode,
|
|
38
|
+
TNode extends TreeNode | TreeLeafValue,
|
|
29
39
|
TBuild,
|
|
30
40
|
ImplicitlyConstructable extends boolean,
|
|
31
41
|
Info,
|
|
32
42
|
>(
|
|
33
|
-
schema:
|
|
34
|
-
|
|
43
|
+
schema:
|
|
44
|
+
| TreeNodeSchema<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>
|
|
45
|
+
| TreeNodeSchemaClass<Name, Kind, TNode & TreeNode, TBuild, ImplicitlyConstructable, Info>,
|
|
46
|
+
): schema is TreeNodeSchemaClass<
|
|
47
|
+
Name,
|
|
48
|
+
Kind,
|
|
49
|
+
TNode & TreeNode,
|
|
50
|
+
TBuild,
|
|
51
|
+
ImplicitlyConstructable,
|
|
52
|
+
Info
|
|
53
|
+
> {
|
|
35
54
|
return schema.constructor !== undefined;
|
|
36
55
|
}
|
|
37
56
|
|
|
@@ -39,8 +58,16 @@ export function isTreeNodeSchemaClass<
|
|
|
39
58
|
* Types for use in fields.
|
|
40
59
|
* @remarks
|
|
41
60
|
* Type constraint used in schema declaration APIs.
|
|
61
|
+
*
|
|
62
|
+
* The order of types in the array is not significant.
|
|
63
|
+
* Additionally, it is legal for users of this type to have the runtime and compile time order of items within this array not match.
|
|
64
|
+
* Therefor to ensure type safety, these arrays should not be indexed, and instead just be iterated.
|
|
65
|
+
*
|
|
66
|
+
* Ideally this restriction would be modeled in the type itself, but it is not ergonomic to do so as there is no easy (when compared to arrays)
|
|
67
|
+
* way to declare and manipulate unordered sets of types in TypeScript.
|
|
68
|
+
*
|
|
42
69
|
* Not intended for direct use outside of package.
|
|
43
|
-
* @public
|
|
70
|
+
* @system @public
|
|
44
71
|
*/
|
|
45
72
|
export type AllowedTypes = readonly LazyItem<TreeNodeSchema>[];
|
|
46
73
|
|
|
@@ -354,6 +381,87 @@ export function normalizeAllowedTypes(
|
|
|
354
381
|
return normalized;
|
|
355
382
|
}
|
|
356
383
|
|
|
384
|
+
/**
|
|
385
|
+
* Returns true if the given {@link ImplicitFieldSchema} are equivalent, otherwise false.
|
|
386
|
+
* @remarks Two ImplicitFieldSchema are considered equivalent if all of the following are true:
|
|
387
|
+
* 1. They have the same {@link FieldKind | kinds}.
|
|
388
|
+
* 2. They have {@link areFieldPropsEqual | equivalent FieldProps}.
|
|
389
|
+
* 3. They have the same exact set of allowed types. The allowed types must be (respectively) reference equal.
|
|
390
|
+
*
|
|
391
|
+
* For example, comparing an ImplicitFieldSchema that is a {@link TreeNodeSchema} to an ImplicitFieldSchema that is a {@link FieldSchema}
|
|
392
|
+
* will return true if they are the same kind, the FieldSchema has exactly one allowed type (the TreeNodeSchema), and they have equivalent FieldProps.
|
|
393
|
+
*/
|
|
394
|
+
export function areImplicitFieldSchemaEqual(
|
|
395
|
+
a: ImplicitFieldSchema,
|
|
396
|
+
b: ImplicitFieldSchema,
|
|
397
|
+
): boolean {
|
|
398
|
+
return areFieldSchemaEqual(normalizeFieldSchema(a), normalizeFieldSchema(b));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Returns true if the given {@link FieldSchema} are equivalent, otherwise false.
|
|
403
|
+
* @remarks Two FieldSchema are considered equivalent if all of the following are true:
|
|
404
|
+
* 1. They have the same {@link FieldKind | kinds}.
|
|
405
|
+
* 2. They have {@link areFieldPropsEqual | equivalent FieldProps}.
|
|
406
|
+
* 3. They have the same exact set of allowed types. The allowed types must be reference equal.
|
|
407
|
+
*/
|
|
408
|
+
export function areFieldSchemaEqual(a: FieldSchema, b: FieldSchema): boolean {
|
|
409
|
+
if (a === b) {
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (a.kind !== b.kind) {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (!areFieldPropsEqual(a.props, b.props)) {
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return compareSets({ a: a.allowedTypeSet, b: b.allowedTypeSet });
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Returns true if the given {@link FieldProps} are equivalent, otherwise false.
|
|
426
|
+
* @remarks FieldProps are considered equivalent if their keys and default providers are reference equal, and their metadata are {@link areMetadataEqual | equivalent}.
|
|
427
|
+
*/
|
|
428
|
+
function areFieldPropsEqual(a: FieldProps | undefined, b: FieldProps | undefined): boolean {
|
|
429
|
+
// If any new fields are added to FieldProps, this check will stop compiling as a reminder that this function needs to be updated.
|
|
430
|
+
type _keys = requireTrue<areOnlyKeys<FieldProps, "key" | "defaultProvider" | "metadata">>;
|
|
431
|
+
|
|
432
|
+
if (a === b) {
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (a?.key !== b?.key || a?.defaultProvider !== b?.defaultProvider) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (!areMetadataEqual(a?.metadata, b?.metadata)) {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Returns true if the given {@link FieldSchemaMetadata} are equivalent, otherwise false.
|
|
449
|
+
* @remarks FieldSchemaMetadata are considered equivalent if their custom data and descriptions are (respectively) reference equal.
|
|
450
|
+
*/
|
|
451
|
+
function areMetadataEqual(
|
|
452
|
+
a: FieldSchemaMetadata | undefined,
|
|
453
|
+
b: FieldSchemaMetadata | undefined,
|
|
454
|
+
): boolean {
|
|
455
|
+
// If any new fields are added to FieldSchemaMetadata, this check will stop compiling as a reminder that this function needs to be updated.
|
|
456
|
+
type _keys = requireTrue<areOnlyKeys<FieldSchemaMetadata, "custom" | "description">>;
|
|
457
|
+
|
|
458
|
+
if (a === b) {
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
return a?.custom === b?.custom && a?.description === b?.description;
|
|
463
|
+
}
|
|
464
|
+
|
|
357
465
|
function evaluateLazySchema(value: LazyItem<TreeNodeSchema>): TreeNodeSchema {
|
|
358
466
|
const evaluatedSchema = isLazy(value) ? value() : value;
|
|
359
467
|
if (evaluatedSchema === undefined) {
|
|
@@ -381,39 +489,147 @@ export type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;
|
|
|
381
489
|
export type ImplicitFieldSchema = FieldSchema | ImplicitAllowedTypes;
|
|
382
490
|
|
|
383
491
|
/**
|
|
384
|
-
* Converts ImplicitFieldSchema to
|
|
492
|
+
* Converts an `ImplicitFieldSchema` to a property type suitable for reading a field with this that schema.
|
|
493
|
+
*
|
|
494
|
+
* @typeparam TSchema - When non-exact schema are provided this errors on the side of returning too general of a type (a conservative union of all possibilities).
|
|
495
|
+
* This is ideal for "output APIs" - i.e. it converts the schema type to the runtime type that a user will _read_ from the tree.
|
|
496
|
+
* Examples of such "non-exact" schema include `ImplicitFieldSchema`, `ImplicitAllowedTypes`, and TypeScript unions of schema types.
|
|
385
497
|
* @public
|
|
386
498
|
*/
|
|
387
499
|
export type TreeFieldFromImplicitField<TSchema extends ImplicitFieldSchema = FieldSchema> =
|
|
388
500
|
TSchema extends FieldSchema<infer Kind, infer Types>
|
|
389
|
-
? ApplyKind<TreeNodeFromImplicitAllowedTypes<Types>, Kind
|
|
501
|
+
? ApplyKind<TreeNodeFromImplicitAllowedTypes<Types>, Kind>
|
|
390
502
|
: TSchema extends ImplicitAllowedTypes
|
|
391
503
|
? TreeNodeFromImplicitAllowedTypes<TSchema>
|
|
392
|
-
:
|
|
504
|
+
: TreeNode | TreeLeafValue | undefined;
|
|
393
505
|
|
|
394
506
|
/**
|
|
395
507
|
* Type of content that can be inserted into the tree for a field of the given schema.
|
|
508
|
+
*
|
|
509
|
+
* @see {@link Input}
|
|
510
|
+
*
|
|
511
|
+
* @typeparam TSchemaInput - Schema to process.
|
|
512
|
+
* @typeparam TSchema - Do not specify: default value used as implementation detail.
|
|
396
513
|
* @public
|
|
397
514
|
*/
|
|
398
515
|
export type InsertableTreeFieldFromImplicitField<
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
516
|
+
TSchemaInput extends ImplicitFieldSchema,
|
|
517
|
+
TSchema = UnionToIntersection<TSchemaInput>,
|
|
518
|
+
> = [TSchema] extends [FieldSchema<infer Kind, infer Types>]
|
|
519
|
+
? ApplyKindInput<InsertableTreeNodeFromImplicitAllowedTypes<Types>, Kind, true>
|
|
520
|
+
: [TSchema] extends [ImplicitAllowedTypes]
|
|
403
521
|
? InsertableTreeNodeFromImplicitAllowedTypes<TSchema>
|
|
404
|
-
:
|
|
522
|
+
: never;
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* {@inheritdoc (UnsafeUnknownSchema:type)}
|
|
526
|
+
* @alpha
|
|
527
|
+
*/
|
|
528
|
+
export const UnsafeUnknownSchema: unique symbol = Symbol("UnsafeUnknownSchema");
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* A special type which can be provided to some APIs as the schema type parameter when schema cannot easily be provided at compile time and an unsafe (instead of disabled) editing API is desired.
|
|
532
|
+
* @remarks
|
|
533
|
+
* When used, this means the TypeScript typing should err on the side of completeness (allow all inputs that could be valid).
|
|
534
|
+
* This introduces the risk that out-of-schema data could be allowed at compile time, and only error at runtime.
|
|
535
|
+
*
|
|
536
|
+
* @privateRemarks
|
|
537
|
+
* This only applies to APIs which input data which is expected to be in schema, since APIs outputting have easy mechanisms to do so in a type safe way even when the schema is unknown.
|
|
538
|
+
* In most cases that amounts to returning `TreeNode | TreeLeafValue`.
|
|
539
|
+
*
|
|
540
|
+
* This can be contrasted with the default behavior of TypeScript, which is to require the intersection of the possible types for input APIs,
|
|
541
|
+
* which for unknown schema defining input trees results in the `never` type.
|
|
542
|
+
*
|
|
543
|
+
* Any APIs which use this must produce UsageErrors when out of schema data is encountered, and never produce unrecoverable errors,
|
|
544
|
+
* or silently accept invalid data.
|
|
545
|
+
* This is currently only type exported from the package: the symbol is just used as a way to get a named type.
|
|
546
|
+
* @alpha
|
|
547
|
+
*/
|
|
548
|
+
export type UnsafeUnknownSchema = typeof UnsafeUnknownSchema;
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Content which could be inserted into a tree.
|
|
552
|
+
*
|
|
553
|
+
* @see {@link Input}
|
|
554
|
+
* @remarks
|
|
555
|
+
* Extended version of {@link InsertableTreeNodeFromImplicitAllowedTypes} that also allows {@link (UnsafeUnknownSchema:type)}.
|
|
556
|
+
* @alpha
|
|
557
|
+
*/
|
|
558
|
+
export type Insertable<TSchema extends ImplicitAllowedTypes | UnsafeUnknownSchema> =
|
|
559
|
+
TSchema extends ImplicitAllowedTypes
|
|
560
|
+
? InsertableTreeNodeFromImplicitAllowedTypes<TSchema>
|
|
561
|
+
: InsertableContent;
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Content which could be inserted into a field within a tree.
|
|
565
|
+
*
|
|
566
|
+
* @see {@link Input}
|
|
567
|
+
* @remarks
|
|
568
|
+
* Extended version of {@link InsertableTreeFieldFromImplicitField} that also allows {@link (UnsafeUnknownSchema:type)}.
|
|
569
|
+
* @alpha
|
|
570
|
+
*/
|
|
571
|
+
export type InsertableField<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema> = [
|
|
572
|
+
TSchema,
|
|
573
|
+
] extends [ImplicitFieldSchema]
|
|
574
|
+
? InsertableTreeFieldFromImplicitField<TSchema>
|
|
575
|
+
: [TSchema] extends [UnsafeUnknownSchema]
|
|
576
|
+
? InsertableContent | undefined
|
|
577
|
+
: never;
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Content which could be read from a field within a tree.
|
|
581
|
+
*
|
|
582
|
+
* @remarks
|
|
583
|
+
* Extended version of {@link TreeFieldFromImplicitField} that also allows {@link (UnsafeUnknownSchema:type)}.
|
|
584
|
+
* Since reading from fields with non-exact schema is still safe, this is only useful (compared to {@link TreeFieldFromImplicitField}) when the schema is also used as input and thus allows {@link (UnsafeUnknownSchema:type)}
|
|
585
|
+
* for use
|
|
586
|
+
* @system @alpha
|
|
587
|
+
*/
|
|
588
|
+
export type ReadableField<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema> =
|
|
589
|
+
TreeFieldFromImplicitField<ReadSchema<TSchema>>;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Adapter to remove {@link (UnsafeUnknownSchema:type)} from a schema type so it can be used with types for generating APIs for reading data.
|
|
593
|
+
*
|
|
594
|
+
* @remarks
|
|
595
|
+
* Since reading with non-exact schema is still safe, this is mainly useful when the schema is also used as input and thus allows {@link (UnsafeUnknownSchema:type)}.
|
|
596
|
+
* @system @alpha
|
|
597
|
+
*/
|
|
598
|
+
export type ReadSchema<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema> = [
|
|
599
|
+
TSchema,
|
|
600
|
+
] extends [ImplicitFieldSchema]
|
|
601
|
+
? TSchema
|
|
602
|
+
: ImplicitFieldSchema;
|
|
405
603
|
|
|
406
604
|
/**
|
|
407
605
|
* Suitable for output.
|
|
408
606
|
* For input must error on side of excluding undefined instead.
|
|
409
607
|
* @system @public
|
|
410
608
|
*/
|
|
411
|
-
export type ApplyKind<T, Kind extends FieldKind
|
|
609
|
+
export type ApplyKind<T, Kind extends FieldKind> = {
|
|
412
610
|
[FieldKind.Required]: T;
|
|
413
611
|
[FieldKind.Optional]: T | undefined;
|
|
414
|
-
[FieldKind.Identifier]:
|
|
612
|
+
[FieldKind.Identifier]: T;
|
|
415
613
|
}[Kind];
|
|
416
614
|
|
|
615
|
+
/**
|
|
616
|
+
* Suitable for input.
|
|
617
|
+
*
|
|
618
|
+
* @see {@link Input}
|
|
619
|
+
* @system @public
|
|
620
|
+
*/
|
|
621
|
+
export type ApplyKindInput<T, Kind extends FieldKind, DefaultsAreOptional extends boolean> = [
|
|
622
|
+
Kind,
|
|
623
|
+
] extends [FieldKind.Required]
|
|
624
|
+
? T
|
|
625
|
+
: [Kind] extends [FieldKind.Optional]
|
|
626
|
+
? T | undefined
|
|
627
|
+
: [Kind] extends [FieldKind.Identifier]
|
|
628
|
+
? DefaultsAreOptional extends true
|
|
629
|
+
? T | undefined
|
|
630
|
+
: T
|
|
631
|
+
: never;
|
|
632
|
+
|
|
417
633
|
/**
|
|
418
634
|
* Type of tree node for a field of the given schema.
|
|
419
635
|
* @public
|
|
@@ -426,16 +642,91 @@ export type TreeNodeFromImplicitAllowedTypes<
|
|
|
426
642
|
? NodeFromSchema<FlexListToUnion<TSchema>>
|
|
427
643
|
: unknown;
|
|
428
644
|
|
|
645
|
+
/**
|
|
646
|
+
* This type exists only to be linked from documentation to provide a single linkable place to document some details of
|
|
647
|
+
* "Input" types and how they handle schema.
|
|
648
|
+
*
|
|
649
|
+
* When a schema is used to describe data which is an input into an API, the API is [contravariant](https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)) over the schema.
|
|
650
|
+
* (See also, [TypeScript Variance Annotations](https://www.typescriptlang.org/docs/handbook/2/generics.html#variance-annotations)).
|
|
651
|
+
*
|
|
652
|
+
* Since these schema are expressed using TypeScript types, it is possible for the user of the API to provide non-exact values of these types which has implications that depended on the variance.
|
|
653
|
+
*
|
|
654
|
+
* Consider a field with schema type of `A | B` (where A and B are types of schema).
|
|
655
|
+
*
|
|
656
|
+
* - Reading the field behaves covariantly so {@link NodeFromSchema} of `<A | B>` is the same as `NodeFromSchema<A> | NodeFromSchema<B>`, indicating that either type of node can be read from the field.
|
|
657
|
+
* - Writing to the field behaves contravariantly. Since it is unknown if the node actually has a schema `A` or a schema `B`, the only legal values (known to be in schema regardless of which schema the underlying node has) are values which are legal for both `A & B`.
|
|
658
|
+
*
|
|
659
|
+
* Note that this is distinct from the case where the schema is `[A, B]`.
|
|
660
|
+
* In this case it is known that the field allows both A and B (the field can be set to an A or a B value).
|
|
661
|
+
* When `A | B` is used, the field might allow
|
|
662
|
+
* A but not B (so assigning a B value would be out of schema),
|
|
663
|
+
* B but not A (so assigning an A value would be out of schema)
|
|
664
|
+
* or both A and B.
|
|
665
|
+
*
|
|
666
|
+
* This gets more extreme when given completely unspecified schema.
|
|
667
|
+
* For example if a field is just provided {@link ImplicitFieldSchema}, nothing is known about the content of the field.
|
|
668
|
+
* This means that reading the field (via {@link TreeFieldFromImplicitField}) can give any valid tree field content,
|
|
669
|
+
* but there are no safe values which could be written to the field (since it is unknown what values would be out of schema) so {@link InsertableTreeFieldFromImplicitField} gives `never`.
|
|
670
|
+
*
|
|
671
|
+
* To implement this variance correctly, the computation of types for input and output have to use separate utilities
|
|
672
|
+
* which take very different approaches when encountering non-exact schema like unions or `ImplicitFieldSchema`.
|
|
673
|
+
* The utilities which behave contravariantly (as required to handle input correctly) link this documentation to indicate that this is how they behave.
|
|
674
|
+
*
|
|
675
|
+
* In addition to behaving contravariantly, these input type computation utilities often have further limitations.
|
|
676
|
+
* This is due to TypeScript making it difficult to implement this contravariance exactly.
|
|
677
|
+
* When faced with these implementation limitations these contravariant type computation utilities error on the side of producing overly strict requirements.
|
|
678
|
+
* For example in the above case of `A | B`, the utilities might compute an allowed insertable type as `never` even if there happens to be a common value accepted by both `A` and `B`.
|
|
679
|
+
* Future versions of the API can relax these requirements as the type computations are made more accurate.
|
|
680
|
+
*
|
|
681
|
+
* For a more concrete example: if {@link InsertableTreeFieldFromImplicitField} produced `never` for a schema `A | OptionalField<A>`,
|
|
682
|
+
* a future version could instead return a more flexible but still safe type, like `A`.
|
|
683
|
+
*
|
|
684
|
+
* More generally: try to avoid providing non-exact schema, especially for the fields of other schema.
|
|
685
|
+
* While these APIs attempt to handle such cases correctly, there are limitations and known bugs in this handling.
|
|
686
|
+
* Code using non-exact schema is much more likely to have its compilation break due to updates of this package or even TypeScript,
|
|
687
|
+
* and thus compilation breaks due to edge cases of non-exact schema handling, especially with recursive schema, are not considered breaking changes.
|
|
688
|
+
* This may change as the API become more stable.
|
|
689
|
+
*
|
|
690
|
+
* @privateRemarks
|
|
691
|
+
* There likely is a better way to share this documentation, but none was found at the time of writing.
|
|
692
|
+
*
|
|
693
|
+
* TODO: Once {@link InsertableField} is public, consider using it in the examples above.
|
|
694
|
+
* @system @public
|
|
695
|
+
*/
|
|
696
|
+
export type Input<T extends never> = T;
|
|
697
|
+
|
|
429
698
|
/**
|
|
430
699
|
* Type of content that can be inserted into the tree for a node of the given schema.
|
|
700
|
+
*
|
|
701
|
+
* @see {@link Input}
|
|
702
|
+
*
|
|
703
|
+
* @typeparam TSchema - Schema to process.
|
|
704
|
+
*
|
|
705
|
+
* @privateRemarks
|
|
706
|
+
* This is a bit overly conservative, since cases like `A | [A]` give never and could give `A`.
|
|
431
707
|
* @public
|
|
432
708
|
*/
|
|
433
|
-
export type InsertableTreeNodeFromImplicitAllowedTypes<
|
|
434
|
-
TSchema extends
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
709
|
+
export type InsertableTreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes> =
|
|
710
|
+
[TSchema] extends [TreeNodeSchema]
|
|
711
|
+
? InsertableTypedNode<TSchema>
|
|
712
|
+
: [TSchema] extends [AllowedTypes]
|
|
713
|
+
? InsertableTreeNodeFromAllowedTypes<TSchema>
|
|
714
|
+
: never;
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* Type of content that can be inserted into the tree for a node of the given schema.
|
|
718
|
+
*
|
|
719
|
+
* @see {@link Input}
|
|
720
|
+
*
|
|
721
|
+
* @typeparam TList - AllowedTypes to process
|
|
722
|
+
* @system @public
|
|
723
|
+
*/
|
|
724
|
+
export type InsertableTreeNodeFromAllowedTypes<TList extends AllowedTypes> =
|
|
725
|
+
TList extends readonly [
|
|
726
|
+
LazyItem<infer TSchema extends TreeNodeSchema>,
|
|
727
|
+
...infer Rest extends AllowedTypes,
|
|
728
|
+
]
|
|
729
|
+
? InsertableTypedNode<TSchema> | InsertableTreeNodeFromAllowedTypes<Rest>
|
|
439
730
|
: never;
|
|
440
731
|
|
|
441
732
|
/**
|
|
@@ -453,29 +744,44 @@ export type NodeFromSchema<T extends TreeNodeSchema> = T extends TreeNodeSchema<
|
|
|
453
744
|
/**
|
|
454
745
|
* Data which can be used as a node to be inserted.
|
|
455
746
|
* Either an unhydrated node, or content to build a new node.
|
|
747
|
+
*
|
|
748
|
+
* @see {@link Input}
|
|
749
|
+
*
|
|
750
|
+
* @typeparam TSchemaInput - Schema to process.
|
|
751
|
+
* @typeparam T - Do not specify: default value used as implementation detail.
|
|
752
|
+
* @privateRemarks
|
|
753
|
+
* This can't really be fully correct, since TreeNodeSchema's TNode is generally use covariantly but this code uses it contravariantly.
|
|
754
|
+
* That makes this TreeNodeSchema actually invariant with respect to TNode, but doing that would break all `extends TreeNodeSchema` clauses.
|
|
755
|
+
* As is, this works correctly in most realistic use-cases.
|
|
756
|
+
*
|
|
757
|
+
* One special case this makes is if the result of NodeFromSchema contains TreeNode, this must be an under constrained schema, so the result is set to never.
|
|
758
|
+
* Note that applying UnionToIntersection on the result of NodeFromSchema<T> does not work since it breaks booleans.
|
|
759
|
+
*
|
|
456
760
|
* @public
|
|
457
761
|
*/
|
|
458
|
-
export type InsertableTypedNode<
|
|
459
|
-
|
|
460
|
-
|
|
762
|
+
export type InsertableTypedNode<
|
|
763
|
+
TSchema extends TreeNodeSchema,
|
|
764
|
+
T = UnionToIntersection<TSchema>,
|
|
765
|
+
> =
|
|
766
|
+
| (T extends TreeNodeSchema<string, NodeKind, TreeNode | TreeLeafValue, never, true>
|
|
767
|
+
? NodeBuilderData<T>
|
|
768
|
+
: never)
|
|
769
|
+
| (T extends TreeNodeSchema
|
|
770
|
+
? Unhydrated<TreeNode extends NodeFromSchema<T> ? never : NodeFromSchema<T>>
|
|
771
|
+
: never);
|
|
461
772
|
|
|
462
773
|
/**
|
|
463
774
|
* Given a node's schema, return the corresponding object from which the node could be built.
|
|
464
775
|
* @privateRemarks
|
|
465
|
-
*
|
|
466
|
-
* This
|
|
467
|
-
*
|
|
468
|
-
* These factory functions can also take a FlexTreeNode, but this is not exposed in the public facing types.
|
|
776
|
+
* This uses TreeNodeSchemaCore, and thus depends on TreeNodeSchemaCore.createFromInsertable for the typing.
|
|
777
|
+
* This works almost the same as using TreeNodeSchema,
|
|
778
|
+
* except that the more complex typing in TreeNodeSchema case breaks for non-class schema and leaks in `undefined` from optional crete parameters.
|
|
469
779
|
* @system @public
|
|
470
780
|
*/
|
|
471
|
-
export type NodeBuilderData<T extends
|
|
472
|
-
string,
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
infer TBuild
|
|
476
|
-
>
|
|
477
|
-
? TBuild
|
|
478
|
-
: never;
|
|
781
|
+
export type NodeBuilderData<T extends TreeNodeSchemaCore<string, NodeKind, boolean>> =
|
|
782
|
+
T extends TreeNodeSchemaCore<string, NodeKind, boolean, unknown, infer TBuild>
|
|
783
|
+
? TBuild
|
|
784
|
+
: never;
|
|
479
785
|
|
|
480
786
|
/**
|
|
481
787
|
* Value that may be stored as a leaf node.
|
|
@@ -726,6 +726,7 @@ function tryGetInnerNode(target: unknown): InnerNode | undefined {
|
|
|
726
726
|
* Content which can be used to build a node.
|
|
727
727
|
* @remarks
|
|
728
728
|
* Can contain unhydrated nodes, but can not be an unhydrated node at the root.
|
|
729
|
+
* @system @alpha
|
|
729
730
|
*/
|
|
730
731
|
export type FactoryContent =
|
|
731
732
|
| IFluidHandle
|
|
@@ -744,12 +745,14 @@ export type FactoryContent =
|
|
|
744
745
|
* Can contain unhydrated nodes, but can not be an unhydrated node at the root.
|
|
745
746
|
*
|
|
746
747
|
* Supports object and map nodes.
|
|
748
|
+
* @system @alpha
|
|
747
749
|
*/
|
|
748
|
-
type FactoryContentObject = {
|
|
750
|
+
export type FactoryContentObject = {
|
|
749
751
|
readonly [P in string]?: InsertableContent;
|
|
750
752
|
};
|
|
751
753
|
|
|
752
754
|
/**
|
|
753
755
|
* Content which can be inserted into a tree.
|
|
756
|
+
* @system @alpha
|
|
754
757
|
*/
|
|
755
758
|
export type InsertableContent = Unhydrated<TreeNode> | FactoryContent;
|
|
@@ -133,7 +133,7 @@ export abstract class TreeNodeValid<TInput> extends TreeNode {
|
|
|
133
133
|
* @remarks
|
|
134
134
|
* When used as TreeNodeSchemaNonClass and subclassed,
|
|
135
135
|
* does not actually have the correct compile time type for the return value due to TypeScript limitations.
|
|
136
|
-
* This is why this is not exposed as part of
|
|
136
|
+
* This is why this is not exposed as part of TreeNodeSchemaClass where subclassing is allowed.
|
|
137
137
|
*/
|
|
138
138
|
public static create<TInput, TOut, TThis extends new (args: TInput) => TOut>(
|
|
139
139
|
this: TThis,
|
|
@@ -142,6 +142,16 @@ export abstract class TreeNodeValid<TInput> extends TreeNode {
|
|
|
142
142
|
return new this(input);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
/**
|
|
146
|
+
* @see {@link TreeNodeSchemaCore.createFromInsertable}.
|
|
147
|
+
*/
|
|
148
|
+
public static createFromInsertable<TInput, TOut, TThis extends new (args: TInput) => TOut>(
|
|
149
|
+
this: TThis,
|
|
150
|
+
input: TInput,
|
|
151
|
+
): TOut {
|
|
152
|
+
return new this(input);
|
|
153
|
+
}
|
|
154
|
+
|
|
145
155
|
public constructor(input: TInput | InternalTreeNode) {
|
|
146
156
|
super(privateToken);
|
|
147
157
|
const schema = this.constructor as typeof TreeNodeValid & TreeNodeSchema;
|
package/src/util/index.ts
CHANGED
|
@@ -52,6 +52,7 @@ export type {
|
|
|
52
52
|
requireFalse,
|
|
53
53
|
requireTrue,
|
|
54
54
|
requireAssignableTo,
|
|
55
|
+
areOnlyKeys,
|
|
55
56
|
} from "./typeCheck.js";
|
|
56
57
|
export { StackyIterator } from "./stackyIterator.js";
|
|
57
58
|
export {
|
|
@@ -99,8 +100,14 @@ export type {
|
|
|
99
100
|
RestrictiveStringRecord,
|
|
100
101
|
_InlineTrick,
|
|
101
102
|
FlattenKeys,
|
|
103
|
+
IsUnion,
|
|
104
|
+
UnionToIntersection,
|
|
105
|
+
UnionToTuple,
|
|
106
|
+
PopUnion,
|
|
102
107
|
} from "./typeUtils.js";
|
|
103
108
|
|
|
109
|
+
export { unsafeArrayToTuple } from "./typeUtils.js";
|
|
110
|
+
|
|
104
111
|
export {
|
|
105
112
|
type BrandedKey,
|
|
106
113
|
type BrandedKeyContent,
|
package/src/util/typeCheck.ts
CHANGED
|
@@ -190,3 +190,16 @@ export type isAny<T> = boolean extends (T extends never ? true : false) ? true :
|
|
|
190
190
|
* `type _check = requireAssignableTo<T, Expected>;`
|
|
191
191
|
*/
|
|
192
192
|
export type requireAssignableTo<_A extends B, B> = true;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Returns a type parameter that is true iff the `Keys` union includes all the keys of `T`.
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* type _check = requireTrue<areOnlyKeys<{a: number, b: number}, 'a' | 'b'>> // true`
|
|
199
|
+
* type _check = requireTrue<areOnlyKeys<{a: number, b: number}, 'a'>> // false`
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
export type areOnlyKeys<T, Keys extends keyof T> = isAssignableTo<
|
|
203
|
+
Record<string, never>,
|
|
204
|
+
Omit<T, Keys>
|
|
205
|
+
>;
|
package/src/util/typeUtils.ts
CHANGED
|
@@ -137,3 +137,90 @@ export type RestrictiveStringRecord<T> = {
|
|
|
137
137
|
} & {
|
|
138
138
|
readonly [P in symbol]?: never;
|
|
139
139
|
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Returns `true` if T is a union and false if it is not.
|
|
143
|
+
* @typeparam T - Type to test if it is a union.
|
|
144
|
+
* @typeparam T2 - Do not specify: default value used as implementation detail.
|
|
145
|
+
* @system @alpha
|
|
146
|
+
*/
|
|
147
|
+
export type IsUnion<T, T2 = T> = T extends unknown
|
|
148
|
+
? [T2] extends [T]
|
|
149
|
+
? false
|
|
150
|
+
: true
|
|
151
|
+
: "error";
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Convert a union of types to an intersection of those types. Useful for `TransformEvents`.
|
|
155
|
+
* @privateRemarks
|
|
156
|
+
* First an always true extends clause is used (T extends T) to distribute T into to a union of types contravariant over each member of the T union.
|
|
157
|
+
* Then the constraint on the type parameter in this new context is inferred, giving the intersection.
|
|
158
|
+
* @system @public
|
|
159
|
+
*/
|
|
160
|
+
export type UnionToIntersection<T> = (T extends T ? (k: T) => unknown : never) extends (
|
|
161
|
+
k: infer U,
|
|
162
|
+
) => unknown
|
|
163
|
+
? U
|
|
164
|
+
: never;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Gets the first item of a union type.
|
|
168
|
+
*
|
|
169
|
+
* @typeparam Union - The union to convert.
|
|
170
|
+
* @typeparam AsOverloadedFunction - Implementation detail: do not specify.
|
|
171
|
+
* @system @alpha
|
|
172
|
+
*/
|
|
173
|
+
export type PopUnion<
|
|
174
|
+
Union,
|
|
175
|
+
AsOverloadedFunction = UnionToIntersection<
|
|
176
|
+
Union extends unknown ? (f: Union) => void : never
|
|
177
|
+
>,
|
|
178
|
+
> = AsOverloadedFunction extends (a: infer First) => void ? First : never;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Converts a union type to a tuple type.
|
|
182
|
+
*
|
|
183
|
+
* @typeparam T - The union to convert.
|
|
184
|
+
* @typeparam A - Implementation detail: do not specify.
|
|
185
|
+
* @typeparam First - Implementation detail: do not specify.
|
|
186
|
+
*
|
|
187
|
+
* @privateRemarks
|
|
188
|
+
* `A` is a tuple to prepend members of the union to.
|
|
189
|
+
*
|
|
190
|
+
* https://www.hacklewayne.com/typescript-convert-union-to-tuple-array-yes-but-how and https://catchts.com/union-array both explain the general approach this uses pretty well.
|
|
191
|
+
* This implementation is inspired to those, but slightly different in implementation.
|
|
192
|
+
* @alpha
|
|
193
|
+
*/
|
|
194
|
+
export type UnionToTuple<
|
|
195
|
+
Union,
|
|
196
|
+
A extends unknown[] = [],
|
|
197
|
+
First = PopUnion<Union>,
|
|
198
|
+
> = IsUnion<Union> extends true
|
|
199
|
+
? UnionToTuple<Exclude<Union, First>, [First, ...A]>
|
|
200
|
+
: [Union, ...A];
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* This is unsafe, meaning that the returned value might not match its type.
|
|
204
|
+
*
|
|
205
|
+
* For the result to match its type, T must be a union of the types of each item in `items` in the order that they occur.
|
|
206
|
+
* For this to be possible, there must be no duplicate or overlapping types.
|
|
207
|
+
* This is fragile and must be used with care.
|
|
208
|
+
*
|
|
209
|
+
* @remarks
|
|
210
|
+
* The main use-case for this is recovering lost information from {@link AllowedTypes} which is necessary to preserve when using them with {@link Input} APIs.
|
|
211
|
+
* Since {@link AllowedTypes} is actually order independent, it is somewhat safer when used to produce `AllowedTypes`.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* // Gives imprecise type (typeof A | typeof B)[]
|
|
216
|
+
* const schemaBad = [A, B];
|
|
217
|
+
* // Fixes the type to be [typeof A, typeof B]
|
|
218
|
+
* const schema = unsafeArrayToTuple(schemaBad);
|
|
219
|
+
*
|
|
220
|
+
* const config = new TreeViewConfiguration({ schema });
|
|
221
|
+
* ```
|
|
222
|
+
* @alpha
|
|
223
|
+
*/
|
|
224
|
+
export function unsafeArrayToTuple<T>(items: T[]): UnionToTuple<T> {
|
|
225
|
+
return items as UnionToTuple<T>;
|
|
226
|
+
}
|