@fluidframework/tree 2.51.0 → 2.52.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 +0 -1
- package/CHANGELOG.md +43 -0
- package/api-report/tree.alpha.api.md +3 -2
- package/dist/codec/codec.d.ts +2 -1
- package/dist/codec/codec.d.ts.map +1 -1
- package/dist/codec/codec.js +4 -3
- package/dist/codec/codec.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/rebase/index.d.ts +1 -1
- package/dist/core/rebase/index.d.ts.map +1 -1
- package/dist/core/rebase/index.js +2 -1
- package/dist/core/rebase/index.js.map +1 -1
- package/dist/core/rebase/types.d.ts +3 -1
- package/dist/core/rebase/types.d.ts.map +1 -1
- package/dist/core/rebase/types.js +2 -1
- package/dist/core/rebase/types.js.map +1 -1
- package/dist/core/schema-stored/schema.d.ts +1 -23
- package/dist/core/schema-stored/schema.d.ts.map +1 -1
- package/dist/core/schema-stored/schema.js +2 -2
- package/dist/core/schema-stored/schema.js.map +1 -1
- package/dist/core/tree/detachedFieldIndex.d.ts.map +1 -1
- package/dist/core/tree/detachedFieldIndex.js +2 -3
- package/dist/core/tree/detachedFieldIndex.js.map +1 -1
- package/dist/core/tree/detachedFieldIndexCodecCommon.d.ts +17 -0
- package/dist/core/tree/detachedFieldIndexCodecCommon.d.ts.map +1 -0
- package/dist/core/tree/detachedFieldIndexCodecCommon.js +68 -0
- package/dist/core/tree/detachedFieldIndexCodecCommon.js.map +1 -0
- package/dist/core/tree/detachedFieldIndexCodecV1.d.ts +11 -0
- package/dist/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -0
- package/dist/core/tree/detachedFieldIndexCodecV1.js +55 -0
- package/dist/core/tree/detachedFieldIndexCodecV1.js.map +1 -0
- package/dist/core/tree/detachedFieldIndexCodecV2.d.ts +11 -0
- package/dist/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -0
- package/dist/core/tree/detachedFieldIndexCodecV2.js +49 -0
- package/dist/core/tree/detachedFieldIndexCodecV2.js.map +1 -0
- package/dist/core/tree/detachedFieldIndexCodecs.d.ts +11 -0
- package/dist/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -0
- package/dist/core/tree/detachedFieldIndexCodecs.js +26 -0
- package/dist/core/tree/detachedFieldIndexCodecs.js.map +1 -0
- package/dist/core/tree/detachedFieldIndexFormatCommon.d.ts +37 -0
- package/dist/core/tree/detachedFieldIndexFormatCommon.d.ts.map +1 -0
- package/dist/core/tree/{detachedFieldIndexFormat.js → detachedFieldIndexFormatCommon.js} +18 -13
- package/dist/core/tree/detachedFieldIndexFormatCommon.js.map +1 -0
- package/dist/core/tree/detachedFieldIndexFormatV1.d.ts +13 -0
- package/dist/core/tree/detachedFieldIndexFormatV1.d.ts.map +1 -0
- package/dist/core/tree/detachedFieldIndexFormatV1.js +12 -0
- package/dist/core/tree/detachedFieldIndexFormatV1.js.map +1 -0
- package/dist/core/tree/detachedFieldIndexFormatV2.d.ts +14 -0
- package/dist/core/tree/detachedFieldIndexFormatV2.d.ts.map +1 -0
- package/dist/core/tree/detachedFieldIndexFormatV2.js +14 -0
- package/dist/core/tree/detachedFieldIndexFormatV2.js.map +1 -0
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +9 -9
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +21 -21
- package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +4 -2
- package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +4 -4
- package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +50 -31
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +74 -61
- package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format.d.ts +20 -14
- package/dist/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/format.js +18 -12
- package/dist/feature-libraries/chunked-forest/codec/format.js.map +1 -1
- package/{lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts → dist/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts} +20 -14
- package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts.map +1 -0
- package/dist/feature-libraries/chunked-forest/codec/{nodeShape.js → nodeEncoder.js} +23 -17
- package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -0
- package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts +7 -7
- package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +22 -22
- package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
- package/dist/feature-libraries/chunked-forest/codec/uncompressedEncode.js +2 -2
- package/dist/feature-libraries/chunked-forest/codec/uncompressedEncode.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 +14 -2
- package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
- package/dist/feature-libraries/default-schema/defaultSchema.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/defaultSchema.js +0 -2
- package/dist/feature-libraries/default-schema/defaultSchema.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 -2
- package/dist/feature-libraries/default-schema/index.js.map +1 -1
- package/dist/feature-libraries/default-schema/schemaChecker.d.ts +14 -4
- package/dist/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/schemaChecker.js +31 -26
- package/dist/feature-libraries/default-schema/schemaChecker.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +1 -2
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +2 -4
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/comparison.d.ts +5 -6
- package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/comparison.js +15 -16
- package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
- package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts +9 -3
- package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
- package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
- package/dist/feature-libraries/object-forest/objectForest.js +2 -3
- package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/shared-tree/independentView.d.ts +8 -0
- package/dist/shared-tree/independentView.d.ts.map +1 -1
- package/dist/shared-tree/independentView.js +23 -11
- package/dist/shared-tree/independentView.js.map +1 -1
- package/dist/shared-tree/schematizeTree.js +1 -1
- package/dist/shared-tree/schematizeTree.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts +0 -1
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +7 -10
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +1 -29
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/treeAlpha.d.ts +20 -6
- package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
- package/dist/shared-tree/treeAlpha.js +9 -4
- package/dist/shared-tree/treeAlpha.js.map +1 -1
- package/dist/shared-tree/treeCheckout.d.ts +2 -1
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +32 -0
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/branch.d.ts.map +1 -1
- package/dist/shared-tree-core/branch.js +1 -1
- package/dist/shared-tree-core/branch.js.map +1 -1
- package/dist/simple-tree/api/conciseTree.d.ts +2 -2
- package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/conciseTree.js +6 -6
- package/dist/simple-tree/api/conciseTree.js.map +1 -1
- package/dist/simple-tree/api/configuration.d.ts +8 -2
- package/dist/simple-tree/api/configuration.d.ts.map +1 -1
- package/dist/simple-tree/api/configuration.js.map +1 -1
- package/dist/simple-tree/api/create.d.ts +8 -7
- package/dist/simple-tree/api/create.d.ts.map +1 -1
- package/dist/simple-tree/api/create.js +35 -22
- package/dist/simple-tree/api/create.js.map +1 -1
- package/dist/simple-tree/api/customTree.d.ts +25 -4
- package/dist/simple-tree/api/customTree.d.ts.map +1 -1
- package/dist/simple-tree/api/customTree.js +42 -16
- package/dist/simple-tree/api/customTree.js.map +1 -1
- package/dist/simple-tree/api/discrepancies.d.ts +98 -0
- package/dist/simple-tree/api/discrepancies.d.ts.map +1 -0
- package/dist/simple-tree/api/discrepancies.js +255 -0
- package/dist/simple-tree/api/discrepancies.js.map +1 -0
- package/dist/simple-tree/api/schemaCompatibilityTester.d.ts +9 -7
- package/dist/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaCompatibilityTester.js +18 -117
- package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +7 -4
- package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/storedSchema.js +5 -1
- package/dist/simple-tree/api/storedSchema.js.map +1 -1
- package/dist/simple-tree/api/treeBeta.d.ts +2 -2
- package/dist/simple-tree/api/treeBeta.d.ts.map +1 -1
- package/dist/simple-tree/api/treeBeta.js +10 -4
- package/dist/simple-tree/api/treeBeta.js.map +1 -1
- package/dist/simple-tree/api/verboseTree.d.ts +2 -2
- package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/verboseTree.js +15 -15
- package/dist/simple-tree/api/verboseTree.js.map +1 -1
- package/dist/simple-tree/core/allowedTypes.d.ts +20 -4
- package/dist/simple-tree/core/allowedTypes.d.ts.map +1 -1
- package/dist/simple-tree/core/allowedTypes.js +45 -13
- package/dist/simple-tree/core/allowedTypes.js.map +1 -1
- package/dist/simple-tree/core/context.d.ts +13 -2
- package/dist/simple-tree/core/context.d.ts.map +1 -1
- package/dist/simple-tree/core/context.js +22 -9
- package/dist/simple-tree/core/context.js.map +1 -1
- package/dist/simple-tree/core/index.d.ts +2 -2
- package/dist/simple-tree/core/index.d.ts.map +1 -1
- package/dist/simple-tree/core/index.js +3 -1
- package/dist/simple-tree/core/index.js.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.d.ts +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/dist/simple-tree/core/treeNodeValid.d.ts +1 -1
- package/dist/simple-tree/core/treeNodeValid.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeValid.js +8 -1
- package/dist/simple-tree/core/treeNodeValid.js.map +1 -1
- package/dist/simple-tree/core/walkSchema.d.ts +3 -0
- package/dist/simple-tree/core/walkSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/walkSchema.js +2 -0
- package/dist/simple-tree/core/walkSchema.js.map +1 -1
- package/dist/simple-tree/createContext.d.ts +2 -0
- package/dist/simple-tree/createContext.d.ts.map +1 -1
- package/dist/simple-tree/createContext.js +3 -1
- package/dist/simple-tree/createContext.js.map +1 -1
- package/dist/simple-tree/fieldSchema.d.ts +1 -0
- package/dist/simple-tree/fieldSchema.d.ts.map +1 -1
- package/dist/simple-tree/fieldSchema.js +1 -0
- package/dist/simple-tree/fieldSchema.js.map +1 -1
- package/dist/simple-tree/index.d.ts +4 -4
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +7 -8
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.js +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/index.d.ts +1 -1
- package/dist/simple-tree/node-kinds/index.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/index.js +1 -2
- package/dist/simple-tree/node-kinds/index.js.map +1 -1
- package/dist/simple-tree/node-kinds/object/index.d.ts +1 -1
- package/dist/simple-tree/node-kinds/object/index.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/object/index.js +1 -2
- package/dist/simple-tree/node-kinds/object/index.js.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts +2 -7
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.js +4 -18
- package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
- package/dist/simple-tree/prepareForInsertion.d.ts +5 -5
- package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
- package/dist/simple-tree/prepareForInsertion.js +9 -3
- package/dist/simple-tree/prepareForInsertion.js.map +1 -1
- package/dist/simple-tree/toStoredSchema.d.ts +3 -0
- package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/dist/simple-tree/toStoredSchema.js +3 -0
- package/dist/simple-tree/toStoredSchema.js.map +1 -1
- package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts +2 -2
- package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
- package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
- package/dist/simple-tree/walkFieldSchema.d.ts +1 -0
- package/dist/simple-tree/walkFieldSchema.d.ts.map +1 -1
- package/dist/simple-tree/walkFieldSchema.js +1 -0
- package/dist/simple-tree/walkFieldSchema.js.map +1 -1
- package/lib/codec/codec.d.ts +2 -1
- package/lib/codec/codec.d.ts.map +1 -1
- package/lib/codec/codec.js +4 -3
- package/lib/codec/codec.js.map +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.d.ts.map +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/rebase/index.d.ts +1 -1
- package/lib/core/rebase/index.d.ts.map +1 -1
- package/lib/core/rebase/index.js +1 -1
- package/lib/core/rebase/index.js.map +1 -1
- package/lib/core/rebase/types.d.ts +3 -1
- package/lib/core/rebase/types.d.ts.map +1 -1
- package/lib/core/rebase/types.js +1 -0
- package/lib/core/rebase/types.js.map +1 -1
- package/lib/core/schema-stored/schema.d.ts +1 -23
- package/lib/core/schema-stored/schema.d.ts.map +1 -1
- package/lib/core/schema-stored/schema.js +2 -2
- package/lib/core/schema-stored/schema.js.map +1 -1
- package/lib/core/tree/detachedFieldIndex.d.ts.map +1 -1
- package/lib/core/tree/detachedFieldIndex.js +2 -3
- package/lib/core/tree/detachedFieldIndex.js.map +1 -1
- package/lib/core/tree/detachedFieldIndexCodecCommon.d.ts +17 -0
- package/lib/core/tree/detachedFieldIndexCodecCommon.d.ts.map +1 -0
- package/lib/core/tree/detachedFieldIndexCodecCommon.js +64 -0
- package/lib/core/tree/detachedFieldIndexCodecCommon.js.map +1 -0
- package/lib/core/tree/detachedFieldIndexCodecV1.d.ts +11 -0
- package/lib/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -0
- package/lib/core/tree/detachedFieldIndexCodecV1.js +51 -0
- package/lib/core/tree/detachedFieldIndexCodecV1.js.map +1 -0
- package/lib/core/tree/detachedFieldIndexCodecV2.d.ts +11 -0
- package/lib/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -0
- package/lib/core/tree/detachedFieldIndexCodecV2.js +45 -0
- package/lib/core/tree/detachedFieldIndexCodecV2.js.map +1 -0
- package/lib/core/tree/detachedFieldIndexCodecs.d.ts +11 -0
- package/lib/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -0
- package/lib/core/tree/detachedFieldIndexCodecs.js +21 -0
- package/lib/core/tree/detachedFieldIndexCodecs.js.map +1 -0
- package/lib/core/tree/detachedFieldIndexFormatCommon.d.ts +37 -0
- package/lib/core/tree/detachedFieldIndexFormatCommon.d.ts.map +1 -0
- package/lib/core/tree/{detachedFieldIndexFormat.js → detachedFieldIndexFormatCommon.js} +13 -10
- package/lib/core/tree/detachedFieldIndexFormatCommon.js.map +1 -0
- package/lib/core/tree/detachedFieldIndexFormatV1.d.ts +13 -0
- package/lib/core/tree/detachedFieldIndexFormatV1.d.ts.map +1 -0
- package/lib/core/tree/detachedFieldIndexFormatV1.js +9 -0
- package/lib/core/tree/detachedFieldIndexFormatV1.js.map +1 -0
- package/lib/core/tree/detachedFieldIndexFormatV2.d.ts +14 -0
- package/lib/core/tree/detachedFieldIndexFormatV2.d.ts.map +1 -0
- package/lib/core/tree/detachedFieldIndexFormatV2.js +11 -0
- package/lib/core/tree/detachedFieldIndexFormatV2.js.map +1 -0
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +9 -9
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +19 -19
- package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +4 -2
- package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +4 -4
- package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +50 -31
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +70 -57
- package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format.d.ts +20 -14
- package/lib/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/format.js +17 -11
- package/lib/feature-libraries/chunked-forest/codec/format.js.map +1 -1
- package/{dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts → lib/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts} +20 -14
- package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.d.ts.map +1 -0
- package/lib/feature-libraries/chunked-forest/codec/{nodeShape.js → nodeEncoder.js} +21 -15
- package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -0
- package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts +7 -7
- package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +19 -19
- package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
- package/lib/feature-libraries/chunked-forest/codec/uncompressedEncode.js +2 -2
- package/lib/feature-libraries/chunked-forest/codec/uncompressedEncode.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 +14 -2
- package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
- package/lib/feature-libraries/default-schema/defaultSchema.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/defaultSchema.js +0 -2
- package/lib/feature-libraries/default-schema/defaultSchema.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/default-schema/schemaChecker.d.ts +14 -4
- package/lib/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/schemaChecker.js +29 -24
- package/lib/feature-libraries/default-schema/schemaChecker.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +1 -2
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +1 -2
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/comparison.d.ts +5 -6
- package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/comparison.js +14 -14
- package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
- package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts +9 -3
- package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +1 -1
- package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
- package/lib/feature-libraries/object-forest/objectForest.js +3 -4
- package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/shared-tree/independentView.d.ts +8 -0
- package/lib/shared-tree/independentView.d.ts.map +1 -1
- package/lib/shared-tree/independentView.js +21 -10
- package/lib/shared-tree/independentView.js.map +1 -1
- package/lib/shared-tree/schematizeTree.js +1 -1
- package/lib/shared-tree/schematizeTree.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts +0 -1
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +8 -11
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +2 -30
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/treeAlpha.d.ts +20 -6
- package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
- package/lib/shared-tree/treeAlpha.js +10 -5
- package/lib/shared-tree/treeAlpha.js.map +1 -1
- package/lib/shared-tree/treeCheckout.d.ts +2 -1
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +33 -1
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/branch.d.ts.map +1 -1
- package/lib/shared-tree-core/branch.js +1 -1
- package/lib/shared-tree-core/branch.js.map +1 -1
- package/lib/simple-tree/api/conciseTree.d.ts +2 -2
- package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/conciseTree.js +6 -6
- package/lib/simple-tree/api/conciseTree.js.map +1 -1
- package/lib/simple-tree/api/configuration.d.ts +8 -2
- package/lib/simple-tree/api/configuration.d.ts.map +1 -1
- package/lib/simple-tree/api/configuration.js.map +1 -1
- package/lib/simple-tree/api/create.d.ts +8 -7
- package/lib/simple-tree/api/create.d.ts.map +1 -1
- package/lib/simple-tree/api/create.js +38 -25
- package/lib/simple-tree/api/create.js.map +1 -1
- package/lib/simple-tree/api/customTree.d.ts +25 -4
- package/lib/simple-tree/api/customTree.d.ts.map +1 -1
- package/lib/simple-tree/api/customTree.js +43 -17
- package/lib/simple-tree/api/customTree.js.map +1 -1
- package/lib/simple-tree/api/discrepancies.d.ts +98 -0
- package/lib/simple-tree/api/discrepancies.d.ts.map +1 -0
- package/lib/simple-tree/{discrepancies.js → api/discrepancies.js} +80 -206
- package/lib/simple-tree/api/discrepancies.js.map +1 -0
- package/lib/simple-tree/api/schemaCompatibilityTester.d.ts +9 -7
- package/lib/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaCompatibilityTester.js +19 -118
- package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +7 -4
- package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/storedSchema.js +6 -2
- package/lib/simple-tree/api/storedSchema.js.map +1 -1
- package/lib/simple-tree/api/treeBeta.d.ts +2 -2
- package/lib/simple-tree/api/treeBeta.d.ts.map +1 -1
- package/lib/simple-tree/api/treeBeta.js +8 -2
- package/lib/simple-tree/api/treeBeta.js.map +1 -1
- package/lib/simple-tree/api/verboseTree.d.ts +2 -2
- package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/verboseTree.js +9 -9
- package/lib/simple-tree/api/verboseTree.js.map +1 -1
- package/lib/simple-tree/core/allowedTypes.d.ts +20 -4
- package/lib/simple-tree/core/allowedTypes.d.ts.map +1 -1
- package/lib/simple-tree/core/allowedTypes.js +42 -12
- package/lib/simple-tree/core/allowedTypes.js.map +1 -1
- package/lib/simple-tree/core/context.d.ts +13 -2
- package/lib/simple-tree/core/context.d.ts.map +1 -1
- package/lib/simple-tree/core/context.js +22 -9
- package/lib/simple-tree/core/context.js.map +1 -1
- package/lib/simple-tree/core/index.d.ts +2 -2
- package/lib/simple-tree/core/index.d.ts.map +1 -1
- package/lib/simple-tree/core/index.js +2 -2
- package/lib/simple-tree/core/index.js.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.d.ts +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/lib/simple-tree/core/treeNodeValid.d.ts +1 -1
- package/lib/simple-tree/core/treeNodeValid.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeValid.js +8 -1
- package/lib/simple-tree/core/treeNodeValid.js.map +1 -1
- package/lib/simple-tree/core/walkSchema.d.ts +3 -0
- package/lib/simple-tree/core/walkSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/walkSchema.js +2 -0
- package/lib/simple-tree/core/walkSchema.js.map +1 -1
- package/lib/simple-tree/createContext.d.ts +2 -0
- package/lib/simple-tree/createContext.d.ts.map +1 -1
- package/lib/simple-tree/createContext.js +3 -1
- package/lib/simple-tree/createContext.js.map +1 -1
- package/lib/simple-tree/fieldSchema.d.ts +1 -0
- package/lib/simple-tree/fieldSchema.d.ts.map +1 -1
- package/lib/simple-tree/fieldSchema.js +1 -0
- package/lib/simple-tree/fieldSchema.js.map +1 -1
- package/lib/simple-tree/index.d.ts +4 -4
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +4 -4
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.js +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/index.d.ts +1 -1
- package/lib/simple-tree/node-kinds/index.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/index.js +1 -1
- package/lib/simple-tree/node-kinds/index.js.map +1 -1
- package/lib/simple-tree/node-kinds/object/index.d.ts +1 -1
- package/lib/simple-tree/node-kinds/object/index.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/object/index.js +1 -1
- package/lib/simple-tree/node-kinds/object/index.js.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts +2 -7
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.js +3 -16
- package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
- package/lib/simple-tree/prepareForInsertion.d.ts +5 -5
- package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
- package/lib/simple-tree/prepareForInsertion.js +11 -5
- package/lib/simple-tree/prepareForInsertion.js.map +1 -1
- package/lib/simple-tree/toStoredSchema.d.ts +3 -0
- package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/lib/simple-tree/toStoredSchema.js +3 -0
- package/lib/simple-tree/toStoredSchema.js.map +1 -1
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts +2 -2
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js +1 -1
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
- package/lib/simple-tree/walkFieldSchema.d.ts +1 -0
- package/lib/simple-tree/walkFieldSchema.d.ts.map +1 -1
- package/lib/simple-tree/walkFieldSchema.js +1 -0
- package/lib/simple-tree/walkFieldSchema.js.map +1 -1
- package/package.json +23 -23
- package/src/codec/codec.ts +4 -3
- package/src/core/index.ts +2 -0
- package/src/core/rebase/index.ts +2 -0
- package/src/core/rebase/types.ts +4 -0
- package/src/core/schema-stored/schema.ts +2 -26
- package/src/core/tree/detachedFieldIndex.ts +4 -6
- package/src/core/tree/detachedFieldIndexCodecCommon.ts +87 -0
- package/src/core/tree/{detachedFieldIndexCodec.ts → detachedFieldIndexCodecV1.ts} +22 -68
- package/src/core/tree/detachedFieldIndexCodecV2.ts +72 -0
- package/src/core/tree/detachedFieldIndexCodecs.ts +44 -0
- package/src/core/tree/{detachedFieldIndexFormat.ts → detachedFieldIndexFormatCommon.ts} +32 -23
- package/src/core/tree/detachedFieldIndexFormatV1.ts +15 -0
- package/src/core/tree/detachedFieldIndexFormatV2.ts +17 -0
- package/src/feature-libraries/chunked-forest/codec/README.md +1 -1
- package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +25 -25
- package/src/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.ts +10 -6
- package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +96 -73
- package/src/feature-libraries/chunked-forest/codec/format.ts +20 -14
- package/src/feature-libraries/chunked-forest/codec/{nodeShape.ts → nodeEncoder.ts} +23 -17
- package/src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts +34 -34
- package/src/feature-libraries/chunked-forest/codec/uncompressedEncode.ts +5 -5
- package/src/feature-libraries/default-schema/defaultFieldKinds.ts +10 -0
- package/src/feature-libraries/default-schema/defaultSchema.ts +0 -2
- package/src/feature-libraries/default-schema/index.ts +1 -1
- package/src/feature-libraries/default-schema/schemaChecker.ts +47 -30
- package/src/feature-libraries/index.ts +1 -3
- package/src/feature-libraries/modular-schema/comparison.ts +14 -29
- package/src/feature-libraries/object-forest/objectForest.ts +10 -6
- package/src/index.ts +5 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/independentView.ts +45 -19
- package/src/shared-tree/schematizeTree.ts +1 -1
- package/src/shared-tree/schematizingTreeView.ts +16 -13
- package/src/shared-tree/sharedTree.ts +2 -42
- package/src/shared-tree/treeAlpha.ts +30 -18
- package/src/shared-tree/treeCheckout.ts +54 -10
- package/src/shared-tree-core/branch.ts +1 -6
- package/src/simple-tree/api/conciseTree.ts +9 -7
- package/src/simple-tree/api/configuration.ts +8 -2
- package/src/simple-tree/api/create.ts +49 -36
- package/src/simple-tree/api/customTree.ts +59 -20
- package/src/simple-tree/{discrepancies.ts → api/discrepancies.ts} +128 -303
- package/src/simple-tree/api/schemaCompatibilityTester.ts +27 -151
- package/src/simple-tree/api/schemaFactory.ts +7 -4
- package/src/simple-tree/api/storedSchema.ts +6 -9
- package/src/simple-tree/api/treeBeta.ts +17 -4
- package/src/simple-tree/api/verboseTree.ts +17 -8
- package/src/simple-tree/core/allowedTypes.ts +54 -21
- package/src/simple-tree/core/context.ts +24 -22
- package/src/simple-tree/core/index.ts +2 -1
- package/src/simple-tree/core/treeNodeKernel.ts +1 -1
- package/src/simple-tree/core/treeNodeValid.ts +9 -2
- package/src/simple-tree/core/walkSchema.ts +3 -0
- package/src/simple-tree/createContext.ts +6 -1
- package/src/simple-tree/fieldSchema.ts +1 -0
- package/src/simple-tree/index.ts +5 -10
- package/src/simple-tree/node-kinds/array/arrayNode.ts +32 -19
- package/src/simple-tree/node-kinds/index.ts +0 -1
- package/src/simple-tree/node-kinds/object/index.ts +0 -1
- package/src/simple-tree/node-kinds/object/objectNode.ts +9 -27
- package/src/simple-tree/prepareForInsertion.ts +17 -9
- package/src/simple-tree/toStoredSchema.ts +3 -0
- package/src/simple-tree/unhydratedFlexTreeFromInsertable.ts +6 -2
- package/src/simple-tree/walkFieldSchema.ts +1 -0
- package/dist/core/tree/detachedFieldIndexCodec.d.ts +0 -11
- package/dist/core/tree/detachedFieldIndexCodec.d.ts.map +0 -1
- package/dist/core/tree/detachedFieldIndexCodec.js +0 -100
- package/dist/core/tree/detachedFieldIndexCodec.js.map +0 -1
- package/dist/core/tree/detachedFieldIndexFormat.d.ts +0 -33
- package/dist/core/tree/detachedFieldIndexFormat.d.ts.map +0 -1
- package/dist/core/tree/detachedFieldIndexFormat.js.map +0 -1
- package/dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +0 -1
- package/dist/feature-libraries/chunked-forest/codec/nodeShape.js.map +0 -1
- package/dist/feature-libraries/initializeForest.d.ts +0 -18
- package/dist/feature-libraries/initializeForest.d.ts.map +0 -1
- package/dist/feature-libraries/initializeForest.js +0 -35
- package/dist/feature-libraries/initializeForest.js.map +0 -1
- package/dist/simple-tree/discrepancies.d.ts +0 -167
- package/dist/simple-tree/discrepancies.d.ts.map +0 -1
- package/dist/simple-tree/discrepancies.js +0 -382
- package/dist/simple-tree/discrepancies.js.map +0 -1
- package/lib/core/tree/detachedFieldIndexCodec.d.ts +0 -11
- package/lib/core/tree/detachedFieldIndexCodec.d.ts.map +0 -1
- package/lib/core/tree/detachedFieldIndexCodec.js +0 -96
- package/lib/core/tree/detachedFieldIndexCodec.js.map +0 -1
- package/lib/core/tree/detachedFieldIndexFormat.d.ts +0 -33
- package/lib/core/tree/detachedFieldIndexFormat.d.ts.map +0 -1
- package/lib/core/tree/detachedFieldIndexFormat.js.map +0 -1
- package/lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +0 -1
- package/lib/feature-libraries/chunked-forest/codec/nodeShape.js.map +0 -1
- package/lib/feature-libraries/initializeForest.d.ts +0 -18
- package/lib/feature-libraries/initializeForest.d.ts.map +0 -1
- package/lib/feature-libraries/initializeForest.js +0 -31
- package/lib/feature-libraries/initializeForest.js.map +0 -1
- package/lib/simple-tree/discrepancies.d.ts +0 -167
- package/lib/simple-tree/discrepancies.d.ts.map +0 -1
- package/lib/simple-tree/discrepancies.js.map +0 -1
- package/src/feature-libraries/initializeForest.ts +0 -55
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type { IFluidHandle } from "@fluidframework/core-interfaces";
|
|
6
6
|
import { type ITreeCursor, type ITreeCursorSynchronous } from "../../core/index.js";
|
|
7
7
|
import type { ImplicitFieldSchema } from "../fieldSchema.js";
|
|
8
|
-
import type {
|
|
8
|
+
import type { Context, TreeLeafValue } from "../core/index.js";
|
|
9
9
|
import { type HandleConverter, type SchemalessParseOptions, type TreeEncodingOptions } from "./customTree.js";
|
|
10
10
|
/**
|
|
11
11
|
* Verbose encoding of a {@link TreeNode} or {@link TreeLeafValue}.
|
|
@@ -82,7 +82,7 @@ export declare function fieldCursorFromVerbose(data: VerboseTree[], options: Sch
|
|
|
82
82
|
/**
|
|
83
83
|
* Used to read a node cursor as a VerboseTree.
|
|
84
84
|
*/
|
|
85
|
-
export declare function verboseFromCursor(reader: ITreeCursor,
|
|
85
|
+
export declare function verboseFromCursor(reader: ITreeCursor, context: Context, options: TreeEncodingOptions): VerboseTree;
|
|
86
86
|
/**
|
|
87
87
|
* Clones tree, replacing any handles.
|
|
88
88
|
* @remarks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verboseTree.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/verboseTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAKpE,OAAO,
|
|
1
|
+
{"version":3,"file":"verboseTree.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/verboseTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAKpE,OAAO,EAMN,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAE3B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAC;AAe/E,OAAO,EAKN,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,MAAM,iBAAiB,CAAC;AAGzB;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,CAAC,OAAO,GAAG,YAAY,IAC3C,eAAe,CAAC,OAAO,CAAC,GACxB,OAAO,CAAC,aAAa,EAAE,YAAY,CAAC,GACpC,OAAO,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,eAAe,CAAC,OAAO,GAAG,YAAY;IACtD;;;;;;OAMG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;OAMG;IACH,MAAM,EACH,WAAW,CAAC,OAAO,CAAC,EAAE,GACtB;QACA,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;KACnC,CAAC;CACL;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,mBAAmB,GAC1B,sBAAsB,CAkDxB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,sBAAsB,GAC7B,sBAAsB,CAExB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,WAAW,EAAE,EACnB,OAAO,EAAE,sBAAsB,GAC7B,sBAAsB,CAMxB;AAiFD;;GAEG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,mBAAmB,GAC1B,WAAW,CAUb;AA2BD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EAC1C,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,GAC1B,WAAW,CAAC,CAAC,CAAC,CAEhB"}
|
|
@@ -10,10 +10,9 @@ const internal_2 = require("@fluidframework/core-utils/internal");
|
|
|
10
10
|
const internal_3 = require("@fluidframework/telemetry-utils/internal");
|
|
11
11
|
const index_js_1 = require("../../core/index.js");
|
|
12
12
|
const index_js_2 = require("../../util/index.js");
|
|
13
|
-
const index_js_3 = require("
|
|
14
|
-
const index_js_4 = require("../../feature-libraries/index.js");
|
|
13
|
+
const index_js_3 = require("../../feature-libraries/index.js");
|
|
15
14
|
const leafNodeSchema_js_1 = require("../leafNodeSchema.js");
|
|
16
|
-
const
|
|
15
|
+
const index_js_4 = require("../node-kinds/index.js");
|
|
17
16
|
const customTree_js_1 = require("./customTree.js");
|
|
18
17
|
const createContext_js_1 = require("../createContext.js");
|
|
19
18
|
/**
|
|
@@ -32,7 +31,7 @@ function applySchemaToParserOptions(schema, options) {
|
|
|
32
31
|
encode: (type, key) => {
|
|
33
32
|
// translate stored key into property key.
|
|
34
33
|
const simpleNodeSchema = context.schema.get((0, index_js_2.brand)(type)) ?? (0, internal_2.fail)(0xb39 /* missing schema */);
|
|
35
|
-
if ((0,
|
|
34
|
+
if ((0, index_js_4.isObjectNodeSchema)(simpleNodeSchema)) {
|
|
36
35
|
const propertyKey = simpleNodeSchema.storedKeyToPropertyKey.get(key);
|
|
37
36
|
if (propertyKey !== undefined) {
|
|
38
37
|
return propertyKey;
|
|
@@ -50,7 +49,7 @@ function applySchemaToParserOptions(schema, options) {
|
|
|
50
49
|
},
|
|
51
50
|
parse: (type, inputKey) => {
|
|
52
51
|
const simpleNodeSchema = context.schema.get((0, index_js_2.brand)(type)) ?? (0, customTree_js_1.unknownTypeError)(type);
|
|
53
|
-
if ((0,
|
|
52
|
+
if ((0, index_js_4.isObjectNodeSchema)(simpleNodeSchema)) {
|
|
54
53
|
const info = simpleNodeSchema.flexKeyMap.get(inputKey);
|
|
55
54
|
if (info === undefined) {
|
|
56
55
|
throw new internal_3.UsageError(`Failed to parse VerboseTree due to unexpected key ${JSON.stringify(inputKey)} on type ${JSON.stringify(type)}.`);
|
|
@@ -69,7 +68,7 @@ exports.applySchemaToParserOptions = applySchemaToParserOptions;
|
|
|
69
68
|
* @returns an {@link ITreeCursorSynchronous} for a single node in nodes mode.
|
|
70
69
|
*/
|
|
71
70
|
function cursorFromVerbose(data, options) {
|
|
72
|
-
return (0,
|
|
71
|
+
return (0, index_js_3.stackTreeNodeCursor)(verboseTreeAdapter(options), data);
|
|
73
72
|
}
|
|
74
73
|
exports.cursorFromVerbose = cursorFromVerbose;
|
|
75
74
|
/**
|
|
@@ -78,13 +77,13 @@ exports.cursorFromVerbose = cursorFromVerbose;
|
|
|
78
77
|
* @returns an {@link ITreeCursorSynchronous} for a single field in fields mode.
|
|
79
78
|
*/
|
|
80
79
|
function fieldCursorFromVerbose(data, options) {
|
|
81
|
-
return (0,
|
|
80
|
+
return (0, index_js_3.stackTreeFieldCursor)(verboseTreeAdapter(options), { type: index_js_1.aboveRootPlaceholder, fields: data }, (0, index_js_1.keyAsDetachedField)(index_js_1.EmptyKey));
|
|
82
81
|
}
|
|
83
82
|
exports.fieldCursorFromVerbose = fieldCursorFromVerbose;
|
|
84
83
|
function verboseTreeAdapter(options) {
|
|
85
84
|
return {
|
|
86
85
|
value: (node) => {
|
|
87
|
-
return (0,
|
|
86
|
+
return (0, index_js_3.isTreeValue)(node) ? node : undefined;
|
|
88
87
|
},
|
|
89
88
|
type: (node) => {
|
|
90
89
|
switch (typeof node) {
|
|
@@ -154,19 +153,20 @@ function verboseTreeAdapter(options) {
|
|
|
154
153
|
/**
|
|
155
154
|
* Used to read a node cursor as a VerboseTree.
|
|
156
155
|
*/
|
|
157
|
-
function verboseFromCursor(reader,
|
|
156
|
+
function verboseFromCursor(reader, context, options) {
|
|
158
157
|
const config = {
|
|
159
158
|
useStoredKeys: false,
|
|
160
159
|
...options,
|
|
161
160
|
};
|
|
162
|
-
const
|
|
163
|
-
|
|
161
|
+
const storedSchemaMap = context.flexContext.schema.nodeSchema;
|
|
162
|
+
const schemaMap = context.schema;
|
|
163
|
+
return verboseFromCursorInner(reader, config, storedSchemaMap, schemaMap);
|
|
164
164
|
}
|
|
165
165
|
exports.verboseFromCursor = verboseFromCursor;
|
|
166
|
-
function verboseFromCursorInner(reader, options, schema) {
|
|
167
|
-
const fields = (0, customTree_js_1.customFromCursor)(reader, options, schema, verboseFromCursorInner);
|
|
168
|
-
const nodeSchema =
|
|
169
|
-
if (nodeSchema
|
|
166
|
+
function verboseFromCursorInner(reader, options, storedSchema, schema) {
|
|
167
|
+
const fields = (0, customTree_js_1.customFromCursor)(reader, options, storedSchema, schema, verboseFromCursorInner);
|
|
168
|
+
const nodeSchema = storedSchema.get(reader.type) ?? (0, internal_2.fail)(0xb3c /* missing schema for type in cursor */);
|
|
169
|
+
if (nodeSchema instanceof index_js_1.LeafNodeStoredSchema) {
|
|
170
170
|
return fields;
|
|
171
171
|
}
|
|
172
172
|
return {
|
|
@@ -1 +1 @@
|
|
|
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AACH,SAAgB,yBAAyB,CACxC,IAAiB,EACjB,QAA4B;IAE5B,OAAO,IAAA,8BAAc,EAAC,IAAI,EAAE,QAAQ,CAAmB,CAAC;AACzD,CAAC;AALD,8DAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\taboveRootPlaceholder,\n\tEmptyKey,\n\tkeyAsDetachedField,\n\ttype FieldKey,\n\ttype ITreeCursor,\n\ttype ITreeCursorSynchronous,\n} from \"../../core/index.js\";\nimport { brand } from \"../../util/index.js\";\nimport type { ImplicitFieldSchema } from \"../fieldSchema.js\";\nimport { NodeKind } from \"../core/index.js\";\nimport type { TreeNodeSchema, ImplicitAllowedTypes, TreeLeafValue } from \"../core/index.js\";\nimport {\n\tisTreeValue,\n\tstackTreeFieldCursor,\n\tstackTreeNodeCursor,\n\ttype CursorAdapter,\n} from \"../../feature-libraries/index.js\";\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"../leafNodeSchema.js\";\nimport { isObjectNodeSchema } from \"../node-kinds/index.js\";\nimport {\n\tcustomFromCursor,\n\treplaceHandles,\n\tunknownTypeError,\n\ttype CustomTreeNode,\n\ttype HandleConverter,\n\ttype SchemalessParseOptions,\n\ttype TreeEncodingOptions,\n} from \"./customTree.js\";\nimport { getUnhydratedContext } from \"../createContext.js\";\n\n/**\n * Verbose encoding of a {@link TreeNode} or {@link TreeLeafValue}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} is a {@link VerboseTreeNode}.\n * Any IFluidHandle values have been replaced by `THandle`.\n * @privateRemarks\n * This can store all possible simple trees,\n * but it can not store all possible trees representable by our internal representations like FlexTree and JsonableTree.\n * @alpha\n */\nexport type VerboseTree<THandle = IFluidHandle> =\n\t| VerboseTreeNode<THandle>\n\t| Exclude<TreeLeafValue, IFluidHandle>\n\t| THandle;\n\n/**\n * Verbose encoding of a {@link TreeNode}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} has an explicit `type` property, and `fields`.\n * This allowed VerboseTreeNode to be unambiguous regarding which type each node is without relying on symbols or hidden state.\n *\n * Any IFluidHandle values have been replaced by `THandle`. If the `THandle` is JSON compatible, then this type is JSON compatible as well.\n *\n * @privateRemarks\n * This type is only used for data which is copied into and out of the tree.\n * When being copied out, its fine to have the data be mutable since its a copy.\n *\n * When being copied in, we don't need to mutate, so we could use a readonly variant of this type.\n * however the copy in case (createFromVerbose) probably isn't harmed much by just reusing this type as is,\n * since if the caller has immutable data, TypeScript doesn't prevent assigning immutable data to a mutable type anyway.\n * Also relaxing the input methods to take readonly data would be a non-breaking change so it can be done later if desired.\n *\n * This format is simple-tree specialized alternative to {@link JsonableTree}.\n * This format allows for all simple-tree compatible trees to be represented.\n *\n * Unlike `JsonableTree`, leaf nodes are not boxed into node objects, and instead have their schema inferred from the value.\n * Additionally, sequence fields can only occur on a node that has a single sequence field (with the empty key)\n * replicating the behavior of simple-tree ArrayNodes.\n * @alpha\n */\nexport interface VerboseTreeNode<THandle = IFluidHandle> {\n\t/**\n\t * The meaning of this node.\n\t * Provides contexts/semantics for this node and its content.\n\t * @remarks\n\t * Typically used to associate a node with metadata (including a schema) and source code (types, behaviors, etc).\n\t * When used with this package's schema system, it will be the {@link TreeNodeSchemaCore.identifier}.\n\t */\n\ttype: string;\n\n\t/**\n\t * Content of this node.\n\t * For array nodes, an array of children.\n\t * For map and object nodes, an object which children under keys.\n\t * @remarks\n\t * For object nodes, the keys could be either the stored keys, or the property keys depending on usage.\n\t */\n\tfields:\n\t\t| VerboseTree<THandle>[]\n\t\t| {\n\t\t\t\t[key: string]: VerboseTree<THandle>;\n\t\t };\n}\n\n/**\n * Use info from `schema` to convert `options` to {@link SchemalessParseOptions}.\n */\nexport function applySchemaToParserOptions(\n\tschema: ImplicitFieldSchema,\n\toptions: TreeEncodingOptions,\n): SchemalessParseOptions {\n\tconst config: Required<TreeEncodingOptions> = {\n\t\tuseStoredKeys: false,\n\t\t...options,\n\t};\n\n\tconst context = getUnhydratedContext(schema);\n\n\treturn {\n\t\tkeyConverter: config.useStoredKeys\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tencode: (type, key: FieldKey): string => {\n\t\t\t\t\t\t// translate stored key into property key.\n\t\t\t\t\t\tconst simpleNodeSchema =\n\t\t\t\t\t\t\tcontext.schema.get(brand(type)) ?? fail(0xb39 /* missing schema */);\n\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\tconst propertyKey = simpleNodeSchema.storedKeyToPropertyKey.get(key);\n\t\t\t\t\t\t\tif (propertyKey !== undefined) {\n\t\t\t\t\t\t\t\treturn propertyKey;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Looking up an out of schema key.\n\t\t\t\t\t\t\t// This must point to a non-existent field.\n\t\t\t\t\t\t\t// It's possible that the key, if we returned it unmodified, could point to some data\n\t\t\t\t\t\t\t// (for example if looking up a key which is a stored key already when using property keys).\n\t\t\t\t\t\t\t// Thus return an arbitrary key that was selected randomly, so should not exist on non-adversarial data:\n\t\t\t\t\t\t\tconst arbitrary = \"arbitrary unused key: fe71614a-bf3e-43b3-b7b0-4cef39538e90\";\n\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t!simpleNodeSchema.storedKeyToPropertyKey.has(brand(arbitrary)),\n\t\t\t\t\t\t\t\t0xa13 /* arbitrarily selected unused key was actually used */,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn arbitrary;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn key;\n\t\t\t\t\t},\n\t\t\t\t\tparse: (type, inputKey): FieldKey => {\n\t\t\t\t\t\tconst simpleNodeSchema = context.schema.get(brand(type)) ?? unknownTypeError(type);\n\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\tconst info = simpleNodeSchema.flexKeyMap.get(inputKey);\n\t\t\t\t\t\t\tif (info === undefined) {\n\t\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\t`Failed to parse VerboseTree due to unexpected key ${JSON.stringify(inputKey)} on type ${JSON.stringify(type)}.`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn info.storedKey;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn brand(inputKey);\n\t\t\t\t\t},\n\t\t\t\t},\n\t};\n}\n\n/**\n * Used to read a VerboseTree as a node cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single node in nodes mode.\n */\nexport function cursorFromVerbose(\n\tdata: VerboseTree,\n\toptions: SchemalessParseOptions,\n): ITreeCursorSynchronous {\n\treturn stackTreeNodeCursor(verboseTreeAdapter(options), data);\n}\n\n/**\n * Used to read a VerboseTree[] as a field cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single field in fields mode.\n */\nexport function fieldCursorFromVerbose(\n\tdata: VerboseTree[],\n\toptions: SchemalessParseOptions,\n): ITreeCursorSynchronous {\n\treturn stackTreeFieldCursor(\n\t\tverboseTreeAdapter(options),\n\t\t{ type: aboveRootPlaceholder, fields: data },\n\t\tkeyAsDetachedField(EmptyKey),\n\t);\n}\n\nfunction verboseTreeAdapter(options: SchemalessParseOptions): CursorAdapter<VerboseTree> {\n\treturn {\n\t\tvalue: (node: VerboseTree) => {\n\t\t\treturn isTreeValue(node) ? node : undefined;\n\t\t},\n\t\ttype: (node: VerboseTree) => {\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"number\":\n\t\t\t\t\treturn brand(numberSchema.identifier);\n\t\t\t\tcase \"string\":\n\t\t\t\t\treturn brand(stringSchema.identifier);\n\t\t\t\tcase \"boolean\":\n\t\t\t\t\treturn brand(booleanSchema.identifier);\n\t\t\t\tdefault:\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn brand(nullSchema.identifier);\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn brand(handleSchema.identifier);\n\t\t\t\t\t}\n\t\t\t\t\treturn brand(node.type);\n\t\t\t}\n\t\t},\n\t\tkeysFromNode: (node: VerboseTree): readonly FieldKey[] => {\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"object\": {\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\t\t\treturn node.fields.length === 0 ? [] : [EmptyKey];\n\t\t\t\t\t}\n\n\t\t\t\t\tconst inputKeys = Object.keys(node.fields);\n\t\t\t\t\tconst converter = options.keyConverter;\n\t\t\t\t\tif (converter === undefined) {\n\t\t\t\t\t\treturn inputKeys as FieldKey[];\n\t\t\t\t\t}\n\t\t\t\t\treturn inputKeys.map((k) => converter.parse(node.type, k));\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn [];\n\t\t\t}\n\t\t},\n\t\tgetFieldFromNode: (node: VerboseTree, key: FieldKey): readonly VerboseTree[] => {\n\t\t\t// Object.prototype.hasOwnProperty can return true for strings (ex: with key \"0\"), so we have to filter them out.\n\t\t\t// Rather than just special casing strings, we can handle them with an early return for all primitives.\n\t\t\tif (typeof node !== \"object\") {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (node === null) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (isFluidHandle(node)) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\treturn key === EmptyKey ? node.fields : [];\n\t\t\t}\n\n\t\t\tconst convertedKey =\n\t\t\t\toptions.keyConverter === undefined ? key : options.keyConverter.encode(node.type, key);\n\n\t\t\tif (Object.prototype.hasOwnProperty.call(node.fields, convertedKey)) {\n\t\t\t\tconst field = node.fields[convertedKey];\n\t\t\t\treturn field === undefined ? [] : [field];\n\t\t\t}\n\n\t\t\treturn [];\n\t\t},\n\t};\n}\n\n/**\n * Used to read a node cursor as a VerboseTree.\n */\nexport function verboseFromCursor(\n\treader: ITreeCursor,\n\trootSchema: ImplicitAllowedTypes,\n\toptions: TreeEncodingOptions,\n): VerboseTree {\n\tconst config: Required<TreeEncodingOptions> = {\n\t\tuseStoredKeys: false,\n\t\t...options,\n\t};\n\n\tconst schemaMap = getUnhydratedContext(rootSchema).schema;\n\n\treturn verboseFromCursorInner(reader, config, schemaMap);\n}\n\nfunction verboseFromCursorInner(\n\treader: ITreeCursor,\n\toptions: Required<TreeEncodingOptions>,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n): VerboseTree {\n\tconst fields = customFromCursor(reader, options, schema, verboseFromCursorInner);\n\tconst nodeSchema =\n\t\tschema.get(reader.type) ?? fail(0xb3c /* missing schema for type in cursor */);\n\tif (nodeSchema.kind === NodeKind.Leaf) {\n\t\treturn fields as TreeLeafValue;\n\t}\n\n\treturn {\n\t\ttype: reader.type,\n\t\tfields: fields as CustomTreeNode<VerboseTree>,\n\t};\n}\n\n/**\n * Clones tree, replacing any handles.\n * @remarks\n * A strongly types version of {@link replaceHandles}.\n * @alpha\n */\nexport function replaceVerboseTreeHandles<T>(\n\ttree: VerboseTree,\n\treplacer: HandleConverter<T>,\n): VerboseTree<T> {\n\treturn replaceHandles(tree, replacer) as VerboseTree<T>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"verboseTree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/verboseTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,qEAAuE;AACvE,kEAAmE;AACnE,uEAAsE;AAEtE,kDAS6B;AAC7B,kDAA4C;AA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cesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\taboveRootPlaceholder,\n\tEmptyKey,\n\tkeyAsDetachedField,\n\tLeafNodeStoredSchema,\n\ttype FieldKey,\n\ttype ITreeCursor,\n\ttype ITreeCursorSynchronous,\n\ttype TreeNodeStoredSchema,\n} from \"../../core/index.js\";\nimport { brand } from \"../../util/index.js\";\nimport type { ImplicitFieldSchema } from \"../fieldSchema.js\";\nimport type { Context, TreeLeafValue, TreeNodeSchema } from \"../core/index.js\";\nimport {\n\tisTreeValue,\n\tstackTreeFieldCursor,\n\tstackTreeNodeCursor,\n\ttype CursorAdapter,\n} from \"../../feature-libraries/index.js\";\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"../leafNodeSchema.js\";\nimport { isObjectNodeSchema } from \"../node-kinds/index.js\";\nimport {\n\tcustomFromCursor,\n\treplaceHandles,\n\tunknownTypeError,\n\ttype CustomTreeNode,\n\ttype HandleConverter,\n\ttype SchemalessParseOptions,\n\ttype TreeEncodingOptions,\n} from \"./customTree.js\";\nimport { getUnhydratedContext } from \"../createContext.js\";\n\n/**\n * Verbose encoding of a {@link TreeNode} or {@link TreeLeafValue}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} is a {@link VerboseTreeNode}.\n * Any IFluidHandle values have been replaced by `THandle`.\n * @privateRemarks\n * This can store all possible simple trees,\n * but it can not store all possible trees representable by our internal representations like FlexTree and JsonableTree.\n * @alpha\n */\nexport type VerboseTree<THandle = IFluidHandle> =\n\t| VerboseTreeNode<THandle>\n\t| Exclude<TreeLeafValue, IFluidHandle>\n\t| THandle;\n\n/**\n * Verbose encoding of a {@link TreeNode}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} has an explicit `type` property, and `fields`.\n * This allowed VerboseTreeNode to be unambiguous regarding which type each node is without relying on symbols or hidden state.\n *\n * Any IFluidHandle values have been replaced by `THandle`. If the `THandle` is JSON compatible, then this type is JSON compatible as well.\n *\n * @privateRemarks\n * This type is only used for data which is copied into and out of the tree.\n * When being copied out, its fine to have the data be mutable since its a copy.\n *\n * When being copied in, we don't need to mutate, so we could use a readonly variant of this type.\n * however the copy in case (createFromVerbose) probably isn't harmed much by just reusing this type as is,\n * since if the caller has immutable data, TypeScript doesn't prevent assigning immutable data to a mutable type anyway.\n * Also relaxing the input methods to take readonly data would be a non-breaking change so it can be done later if desired.\n *\n * This format is simple-tree specialized alternative to {@link JsonableTree}.\n * This format allows for all simple-tree compatible trees to be represented.\n *\n * Unlike `JsonableTree`, leaf nodes are not boxed into node objects, and instead have their schema inferred from the value.\n * Additionally, sequence fields can only occur on a node that has a single sequence field (with the empty key)\n * replicating the behavior of simple-tree ArrayNodes.\n * @alpha\n */\nexport interface VerboseTreeNode<THandle = IFluidHandle> {\n\t/**\n\t * The meaning of this node.\n\t * Provides contexts/semantics for this node and its content.\n\t * @remarks\n\t * Typically used to associate a node with metadata (including a schema) and source code (types, behaviors, etc).\n\t * When used with this package's schema system, it will be the {@link TreeNodeSchemaCore.identifier}.\n\t */\n\ttype: string;\n\n\t/**\n\t * Content of this node.\n\t * For array nodes, an array of children.\n\t * For map and object nodes, an object which children under keys.\n\t * @remarks\n\t * For object nodes, the keys could be either the stored keys, or the property keys depending on usage.\n\t */\n\tfields:\n\t\t| VerboseTree<THandle>[]\n\t\t| {\n\t\t\t\t[key: string]: VerboseTree<THandle>;\n\t\t };\n}\n\n/**\n * Use info from `schema` to convert `options` to {@link SchemalessParseOptions}.\n */\nexport function applySchemaToParserOptions(\n\tschema: ImplicitFieldSchema,\n\toptions: TreeEncodingOptions,\n): SchemalessParseOptions {\n\tconst config: Required<TreeEncodingOptions> = {\n\t\tuseStoredKeys: false,\n\t\t...options,\n\t};\n\n\tconst context = getUnhydratedContext(schema);\n\n\treturn {\n\t\tkeyConverter: config.useStoredKeys\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tencode: (type, key: FieldKey): string => {\n\t\t\t\t\t\t// translate stored key into property key.\n\t\t\t\t\t\tconst simpleNodeSchema =\n\t\t\t\t\t\t\tcontext.schema.get(brand(type)) ?? fail(0xb39 /* missing schema */);\n\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\tconst propertyKey = simpleNodeSchema.storedKeyToPropertyKey.get(key);\n\t\t\t\t\t\t\tif (propertyKey !== undefined) {\n\t\t\t\t\t\t\t\treturn propertyKey;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Looking up an out of schema key.\n\t\t\t\t\t\t\t// This must point to a non-existent field.\n\t\t\t\t\t\t\t// It's possible that the key, if we returned it unmodified, could point to some data\n\t\t\t\t\t\t\t// (for example if looking up a key which is a stored key already when using property keys).\n\t\t\t\t\t\t\t// Thus return an arbitrary key that was selected randomly, so should not exist on non-adversarial data:\n\t\t\t\t\t\t\tconst arbitrary = \"arbitrary unused key: fe71614a-bf3e-43b3-b7b0-4cef39538e90\";\n\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t!simpleNodeSchema.storedKeyToPropertyKey.has(brand(arbitrary)),\n\t\t\t\t\t\t\t\t0xa13 /* arbitrarily selected unused key was actually used */,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn arbitrary;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn key;\n\t\t\t\t\t},\n\t\t\t\t\tparse: (type, inputKey): FieldKey => {\n\t\t\t\t\t\tconst simpleNodeSchema = context.schema.get(brand(type)) ?? unknownTypeError(type);\n\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\tconst info = simpleNodeSchema.flexKeyMap.get(inputKey);\n\t\t\t\t\t\t\tif (info === undefined) {\n\t\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\t`Failed to parse VerboseTree due to unexpected key ${JSON.stringify(inputKey)} on type ${JSON.stringify(type)}.`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn info.storedKey;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn brand(inputKey);\n\t\t\t\t\t},\n\t\t\t\t},\n\t};\n}\n\n/**\n * Used to read a VerboseTree as a node cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single node in nodes mode.\n */\nexport function cursorFromVerbose(\n\tdata: VerboseTree,\n\toptions: SchemalessParseOptions,\n): ITreeCursorSynchronous {\n\treturn stackTreeNodeCursor(verboseTreeAdapter(options), data);\n}\n\n/**\n * Used to read a VerboseTree[] as a field cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single field in fields mode.\n */\nexport function fieldCursorFromVerbose(\n\tdata: VerboseTree[],\n\toptions: SchemalessParseOptions,\n): ITreeCursorSynchronous {\n\treturn stackTreeFieldCursor(\n\t\tverboseTreeAdapter(options),\n\t\t{ type: aboveRootPlaceholder, fields: data },\n\t\tkeyAsDetachedField(EmptyKey),\n\t);\n}\n\nfunction verboseTreeAdapter(options: SchemalessParseOptions): CursorAdapter<VerboseTree> {\n\treturn {\n\t\tvalue: (node: VerboseTree) => {\n\t\t\treturn isTreeValue(node) ? node : undefined;\n\t\t},\n\t\ttype: (node: VerboseTree) => {\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"number\":\n\t\t\t\t\treturn brand(numberSchema.identifier);\n\t\t\t\tcase \"string\":\n\t\t\t\t\treturn brand(stringSchema.identifier);\n\t\t\t\tcase \"boolean\":\n\t\t\t\t\treturn brand(booleanSchema.identifier);\n\t\t\t\tdefault:\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn brand(nullSchema.identifier);\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn brand(handleSchema.identifier);\n\t\t\t\t\t}\n\t\t\t\t\treturn brand(node.type);\n\t\t\t}\n\t\t},\n\t\tkeysFromNode: (node: VerboseTree): readonly FieldKey[] => {\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"object\": {\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\t\t\treturn node.fields.length === 0 ? [] : [EmptyKey];\n\t\t\t\t\t}\n\n\t\t\t\t\tconst inputKeys = Object.keys(node.fields);\n\t\t\t\t\tconst converter = options.keyConverter;\n\t\t\t\t\tif (converter === undefined) {\n\t\t\t\t\t\treturn inputKeys as FieldKey[];\n\t\t\t\t\t}\n\t\t\t\t\treturn inputKeys.map((k) => converter.parse(node.type, k));\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn [];\n\t\t\t}\n\t\t},\n\t\tgetFieldFromNode: (node: VerboseTree, key: FieldKey): readonly VerboseTree[] => {\n\t\t\t// Object.prototype.hasOwnProperty can return true for strings (ex: with key \"0\"), so we have to filter them out.\n\t\t\t// Rather than just special casing strings, we can handle them with an early return for all primitives.\n\t\t\tif (typeof node !== \"object\") {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (node === null) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (isFluidHandle(node)) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\treturn key === EmptyKey ? node.fields : [];\n\t\t\t}\n\n\t\t\tconst convertedKey =\n\t\t\t\toptions.keyConverter === undefined ? key : options.keyConverter.encode(node.type, key);\n\n\t\t\tif (Object.prototype.hasOwnProperty.call(node.fields, convertedKey)) {\n\t\t\t\tconst field = node.fields[convertedKey];\n\t\t\t\treturn field === undefined ? [] : [field];\n\t\t\t}\n\n\t\t\treturn [];\n\t\t},\n\t};\n}\n\n/**\n * Used to read a node cursor as a VerboseTree.\n */\nexport function verboseFromCursor(\n\treader: ITreeCursor,\n\tcontext: Context,\n\toptions: TreeEncodingOptions,\n): VerboseTree {\n\tconst config: Required<TreeEncodingOptions> = {\n\t\tuseStoredKeys: false,\n\t\t...options,\n\t};\n\n\tconst storedSchemaMap = context.flexContext.schema.nodeSchema;\n\tconst schemaMap = context.schema;\n\n\treturn verboseFromCursorInner(reader, config, storedSchemaMap, schemaMap);\n}\n\nfunction verboseFromCursorInner(\n\treader: ITreeCursor,\n\toptions: Required<TreeEncodingOptions>,\n\tstoredSchema: ReadonlyMap<string, TreeNodeStoredSchema>,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n): VerboseTree {\n\tconst fields = customFromCursor(\n\t\treader,\n\t\toptions,\n\t\tstoredSchema,\n\t\tschema,\n\t\tverboseFromCursorInner,\n\t);\n\tconst nodeSchema =\n\t\tstoredSchema.get(reader.type) ?? fail(0xb3c /* missing schema for type in cursor */);\n\tif (nodeSchema instanceof LeafNodeStoredSchema) {\n\t\treturn fields as TreeLeafValue;\n\t}\n\n\treturn {\n\t\ttype: reader.type,\n\t\tfields: fields as CustomTreeNode<VerboseTree>,\n\t};\n}\n\n/**\n * Clones tree, replacing any handles.\n * @remarks\n * A strongly types version of {@link replaceHandles}.\n * @alpha\n */\nexport function replaceVerboseTreeHandles<T>(\n\ttree: VerboseTree,\n\treplacer: HandleConverter<T>,\n): VerboseTree<T> {\n\treturn replaceHandles(tree, replacer) as VerboseTree<T>;\n}\n"]}
|
|
@@ -169,7 +169,7 @@ export type UnannotateAllowedTypes<T extends AnnotatedAllowedTypes> = Unannotate
|
|
|
169
169
|
* Removes annotations from an allowed type.
|
|
170
170
|
* @system @alpha
|
|
171
171
|
*/
|
|
172
|
-
export type UnannotateAllowedType<T extends AnnotatedAllowedType
|
|
172
|
+
export type UnannotateAllowedType<T extends AnnotatedAllowedType | LazyItem<TreeNodeSchema>> = T extends AnnotatedAllowedType<infer X> ? [X] : T;
|
|
173
173
|
/**
|
|
174
174
|
* Normalizes a {@link ImplicitAllowedTypes} to a set of {@link TreeNodeSchema}s, by eagerly evaluating any
|
|
175
175
|
* lazy schema declarations.
|
|
@@ -179,11 +179,17 @@ export type UnannotateAllowedType<T extends AnnotatedAllowedType> = T extends An
|
|
|
179
179
|
*
|
|
180
180
|
* @internal
|
|
181
181
|
*/
|
|
182
|
-
export declare function normalizeAllowedTypes(types:
|
|
182
|
+
export declare function normalizeAllowedTypes(types: ImplicitAnnotatedAllowedTypes): ReadonlySet<TreeNodeSchema>;
|
|
183
183
|
/**
|
|
184
|
-
* Normalizes an allowed type to an {@link AnnotatedAllowedType}, by adding empty annotations if they don't already exist
|
|
184
|
+
* Normalizes an allowed type to an {@link AnnotatedAllowedType}, by adding empty annotations if they don't already exist
|
|
185
|
+
* and eagerly evaluating any lazy schema declarations.
|
|
186
|
+
*
|
|
187
|
+
* @remarks
|
|
188
|
+
* Note: this must only be called after all required schemas have been declared, otherwise evaluation of
|
|
189
|
+
* recursive schemas may fail.
|
|
190
|
+
* type is frozen and should not be modified after being passed in.
|
|
185
191
|
*/
|
|
186
|
-
export declare function normalizeToAnnotatedAllowedType<T extends TreeNodeSchema>(type: T | AnnotatedAllowedType<T> | AnnotatedAllowedType<LazyItem<T>>): AnnotatedAllowedType<T
|
|
192
|
+
export declare function normalizeToAnnotatedAllowedType<T extends TreeNodeSchema>(type: T | AnnotatedAllowedType<T> | AnnotatedAllowedType<LazyItem<T>>): AnnotatedAllowedType<T>;
|
|
187
193
|
/**
|
|
188
194
|
* Normalizes a {@link ImplicitAnnotatedAllowedTypes} to a set of {@link AnnotatedAllowedSchema}s, by eagerly evaluating any
|
|
189
195
|
* lazy schema declarations and adding empty metadata if it doesn't already exist.
|
|
@@ -199,6 +205,12 @@ export declare function normalizeAnnotatedAllowedTypes(types: ImplicitAnnotatedA
|
|
|
199
205
|
* This does not evaluate any lazy schemas.
|
|
200
206
|
*/
|
|
201
207
|
export declare function unannotateImplicitAllowedTypes<Types extends ImplicitAnnotatedAllowedTypes>(types: Types): UnannotateImplicitAllowedTypes<Types>;
|
|
208
|
+
/**
|
|
209
|
+
* Converts an {@link AnnotatedAllowedType} to an {@link LazyItem} by removing any annotations.
|
|
210
|
+
* @remarks
|
|
211
|
+
* This does not evaluate any lazy schemas.
|
|
212
|
+
*/
|
|
213
|
+
export declare function unannotateAllowedType<Type extends AnnotatedAllowedType | LazyItem<TreeNodeSchema>>(allowedType: Type): UnannotateAllowedType<Type>;
|
|
202
214
|
/**
|
|
203
215
|
* Returns the schema referenced by the {@link LazyItem}.
|
|
204
216
|
* @remarks
|
|
@@ -206,6 +218,10 @@ export declare function unannotateImplicitAllowedTypes<Types extends ImplicitAnn
|
|
|
206
218
|
* @alpha
|
|
207
219
|
*/
|
|
208
220
|
export declare function evaluateLazySchema<T extends TreeNodeSchema>(value: LazyItem<T>): T;
|
|
221
|
+
/**
|
|
222
|
+
* Throws a UsageError if the provided schema is undefined, most likely due to being used before it was initialized.
|
|
223
|
+
*/
|
|
224
|
+
export declare function checkForUninitializedSchema(schema: ImplicitAnnotatedAllowedTypes | LazyItem<TreeNodeSchema>): void;
|
|
209
225
|
/**
|
|
210
226
|
* Indicates that the provided schema is the "most derived" version in its class hierarchy.
|
|
211
227
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowedTypes.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/core/allowedTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAgC,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAU,KAAK,eAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAEN,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,MAAM,qBA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AoB,IAC1F;IAAC,OAAO;CAAC,SAAS,CAAC,cAAc,CAAC,GAC/B,mBAAmB,CAAC,OAAO,CAAC,GAC5B,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,GAC/B,kCAAkC,CAAC,OAAO,CAAC,GAC3C,KAAK,CAAC;AAEX;;;;;;;;;;GAUG;AACH,MAAM,MAAM,kCAAkC,CAAC,KAAK,SAAS,YAAY,IACxE,OAAO,CAAC,KAAK,CAAC,SAAS,IAAI,GACxB,KAAK,GACL;IACA,QAAQ,EAAE,QAAQ,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,SAAS,QAAQ,CACnE,MAAM,OAAO,SAAS,cAAc,CACpC,GACE,mBAAmB,CAAC,OAAO,CAAC,GAC5B,KAAK;CACR,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.markSchemaMostDerived = exports.evaluateLazySchema = exports.unannotateImplicitAllowedTypes = exports.normalizeAnnotatedAllowedTypes = exports.normalizeToAnnotatedAllowedType = exports.normalizeAllowedTypes = exports.isAnnotatedAllowedType = exports.isAnnotatedAllowedTypes = void 0;
|
|
7
|
+
exports.markSchemaMostDerived = exports.checkForUninitializedSchema = exports.evaluateLazySchema = exports.unannotateAllowedType = exports.unannotateImplicitAllowedTypes = exports.normalizeAnnotatedAllowedTypes = exports.normalizeToAnnotatedAllowedType = exports.normalizeAllowedTypes = exports.isAnnotatedAllowedType = exports.isAnnotatedAllowedTypes = void 0;
|
|
8
8
|
const internal_1 = require("@fluidframework/telemetry-utils/internal");
|
|
9
9
|
const index_js_1 = require("../../util/index.js");
|
|
10
10
|
const flexList_js_1 = require("./flexList.js");
|
|
@@ -14,6 +14,7 @@ const treeNodeValid_js_1 = require("./treeNodeValid.js");
|
|
|
14
14
|
* Checks if the input is an {@link AnnotatedAllowedTypes}.
|
|
15
15
|
*/
|
|
16
16
|
function isAnnotatedAllowedTypes(allowedTypes) {
|
|
17
|
+
checkForUninitializedSchema(allowedTypes);
|
|
17
18
|
return (
|
|
18
19
|
// Class based schema, and lazy schema references report type "function": filtering them out with typeof makes narrowing based on members mostly safe
|
|
19
20
|
typeof allowedTypes === "object" && "metadata" in allowedTypes && "types" in allowedTypes);
|
|
@@ -23,7 +24,9 @@ exports.isAnnotatedAllowedTypes = isAnnotatedAllowedTypes;
|
|
|
23
24
|
* Checks if the given allowed type is annotated with {@link AllowedTypeMetadata}.
|
|
24
25
|
*/
|
|
25
26
|
function isAnnotatedAllowedType(allowedType) {
|
|
26
|
-
|
|
27
|
+
checkForUninitializedSchema(allowedType);
|
|
28
|
+
// Class based schema, and lazy schema references report type "function": filtering them out with typeof makes narrowing based on members mostly safe
|
|
29
|
+
return typeof allowedType === "object" && "metadata" in allowedType && "type" in allowedType;
|
|
27
30
|
}
|
|
28
31
|
exports.isAnnotatedAllowedType = isAnnotatedAllowedType;
|
|
29
32
|
/**
|
|
@@ -36,26 +39,37 @@ exports.isAnnotatedAllowedType = isAnnotatedAllowedType;
|
|
|
36
39
|
* @internal
|
|
37
40
|
*/
|
|
38
41
|
function normalizeAllowedTypes(types) {
|
|
42
|
+
// remove annotations before normalizing
|
|
43
|
+
const unannotated = unannotateImplicitAllowedTypes(types);
|
|
39
44
|
const normalized = new Set();
|
|
40
|
-
if ((0, index_js_1.isReadonlyArray)(
|
|
45
|
+
if ((0, index_js_1.isReadonlyArray)(unannotated)) {
|
|
41
46
|
// Types array must not be modified after it is normalized since that would result in the user of the normalized data having wrong (out of date) content.
|
|
42
|
-
Object.freeze(
|
|
43
|
-
for (const lazyType of
|
|
47
|
+
Object.freeze(unannotated);
|
|
48
|
+
for (const lazyType of unannotated) {
|
|
44
49
|
normalized.add(evaluateLazySchema(lazyType));
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
52
|
else {
|
|
48
|
-
normalized.add(evaluateLazySchema(
|
|
53
|
+
normalized.add(evaluateLazySchema(unannotated));
|
|
49
54
|
}
|
|
50
55
|
return normalized;
|
|
51
56
|
}
|
|
52
57
|
exports.normalizeAllowedTypes = normalizeAllowedTypes;
|
|
53
58
|
/**
|
|
54
|
-
* Normalizes an allowed type to an {@link AnnotatedAllowedType}, by adding empty annotations if they don't already exist
|
|
59
|
+
* Normalizes an allowed type to an {@link AnnotatedAllowedType}, by adding empty annotations if they don't already exist
|
|
60
|
+
* and eagerly evaluating any lazy schema declarations.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* Note: this must only be called after all required schemas have been declared, otherwise evaluation of
|
|
64
|
+
* recursive schemas may fail.
|
|
65
|
+
* type is frozen and should not be modified after being passed in.
|
|
55
66
|
*/
|
|
56
67
|
function normalizeToAnnotatedAllowedType(type) {
|
|
57
68
|
return isAnnotatedAllowedType(type)
|
|
58
|
-
?
|
|
69
|
+
? {
|
|
70
|
+
metadata: type.metadata,
|
|
71
|
+
type: evaluateLazySchema(type.type),
|
|
72
|
+
}
|
|
59
73
|
: {
|
|
60
74
|
metadata: {},
|
|
61
75
|
type,
|
|
@@ -110,14 +124,25 @@ exports.normalizeAnnotatedAllowedTypes = normalizeAnnotatedAllowedTypes;
|
|
|
110
124
|
*/
|
|
111
125
|
function unannotateImplicitAllowedTypes(types) {
|
|
112
126
|
return (isAnnotatedAllowedTypes(types)
|
|
113
|
-
? types.types.map(
|
|
127
|
+
? types.types.map(unannotateAllowedType)
|
|
114
128
|
: (0, index_js_1.isReadonlyArray)(types)
|
|
115
|
-
? types.map(
|
|
129
|
+
? types.map(unannotateAllowedType)
|
|
116
130
|
: isAnnotatedAllowedType(types)
|
|
117
131
|
? types.type
|
|
118
132
|
: types);
|
|
119
133
|
}
|
|
120
134
|
exports.unannotateImplicitAllowedTypes = unannotateImplicitAllowedTypes;
|
|
135
|
+
/**
|
|
136
|
+
* Converts an {@link AnnotatedAllowedType} to an {@link LazyItem} by removing any annotations.
|
|
137
|
+
* @remarks
|
|
138
|
+
* This does not evaluate any lazy schemas.
|
|
139
|
+
*/
|
|
140
|
+
function unannotateAllowedType(allowedType) {
|
|
141
|
+
return isAnnotatedAllowedType(allowedType)
|
|
142
|
+
? allowedType.type
|
|
143
|
+
: allowedType;
|
|
144
|
+
}
|
|
145
|
+
exports.unannotateAllowedType = unannotateAllowedType;
|
|
121
146
|
const cachedLazyItem = new WeakMap();
|
|
122
147
|
/**
|
|
123
148
|
* Returns the schema referenced by the {@link LazyItem}.
|
|
@@ -129,13 +154,20 @@ function evaluateLazySchema(value) {
|
|
|
129
154
|
const evaluatedSchema = (0, flexList_js_1.isLazy)(value)
|
|
130
155
|
? (0, index_js_1.getOrCreate)(cachedLazyItem, value, value)
|
|
131
156
|
: value;
|
|
132
|
-
|
|
133
|
-
throw new internal_1.UsageError(`Encountered an undefined schema. This could indicate that some referenced schema has not yet been instantiated.`);
|
|
134
|
-
}
|
|
157
|
+
checkForUninitializedSchema(evaluatedSchema);
|
|
135
158
|
markSchemaMostDerived(evaluatedSchema);
|
|
136
159
|
return evaluatedSchema;
|
|
137
160
|
}
|
|
138
161
|
exports.evaluateLazySchema = evaluateLazySchema;
|
|
162
|
+
/**
|
|
163
|
+
* Throws a UsageError if the provided schema is undefined, most likely due to being used before it was initialized.
|
|
164
|
+
*/
|
|
165
|
+
function checkForUninitializedSchema(schema) {
|
|
166
|
+
if (schema === undefined) {
|
|
167
|
+
throw new internal_1.UsageError(`Encountered an undefined schema. This could indicate that some referenced schema has not yet been instantiated. Consider using a lazy schema reference (like "() => schema") or delaying the evaluation of the lazy reference if one is already being used.`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.checkForUninitializedSchema = checkForUninitializedSchema;
|
|
139
171
|
/**
|
|
140
172
|
* Indicates that the provided schema is the "most derived" version in its class hierarchy.
|
|
141
173
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowedTypes.js","sourceRoot":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E,CAAC;QACnC,OAAO;IACR,CAAC;IAED,MAAM,WAAW,GAAG,IAAA,wCAAqB,EAAC,MAAM,CAAC,CAAC;IAElD,IAAI,iBAAiB,EAAE,CAAC;QACvB,WAAW,CAAC,iBAAiB,EAAE,CAAC;IACjC,CAAC;SAAM,CAAC;QACP,WAAW,CAAC,eAAe,EAAE,CAAC;IAC/B,CAAC;AACF,CAAC;AAhBD,sDAgBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { getOrCreate, isReadonlyArray, type IsUnion } from \"../../util/index.js\";\nimport { isLazy, type FlexListToUnion, type LazyItem } from \"./flexList.js\";\nimport {\n\tNodeKind,\n\ttype InsertableTypedNode,\n\ttype NodeFromSchema,\n\ttype TreeNodeSchema,\n} from \"./treeNodeSchema.js\";\nimport { schemaAsTreeNodeValid } from \"./treeNodeValid.js\";\n\n/**\n * Schema for types allowed in some location in a tree (like a field, map entry or array).\n * @remarks\n * Type constraint used in schema declaration APIs.\n *\n * The order of types in the array is not significant.\n * Additionally, it is legal for users of this type to have the runtime and compile time order of items within this array not match.\n * Therefor to ensure type safety, these arrays should not be indexed, and instead just be iterated.\n *\n * 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)\n * way to declare and manipulate unordered sets of types in TypeScript.\n *\n * Duplicate entries in this array are not allowed and will produce runtime errors.\n * Duplicate types are allowed,\n * but this must only be reflected in the type and not the runtime values.\n * This duplication can be used to encode the typing when the number of items in the array is not known at compile time\n * but some of the items are known to be present unconditionally.\n * For example, typing `[typeof A] | [typeof A, typeof B]` as `[typeof A, typeof B | typeof A]` is allowed,\n * and can produce more useful {@link Input} types.\n * @privateRemarks\n * Code reading data from this should use `normalizeAllowedTypes` to ensure consistent handling, caching, nice errors etc.\n * @system @public\n */\nexport type AllowedTypes = readonly LazyItem<TreeNodeSchema>[];\n\n/**\n * Stores annotations for an individual allowed type.\n * @alpha\n */\nexport interface AnnotatedAllowedType<T = LazyItem<TreeNodeSchema>> {\n\t/**\n\t * Annotations for the allowed type.\n\t */\n\treadonly metadata: AllowedTypeMetadata;\n\t/**\n\t * The allowed type the annotations apply to in a particular schema.\n\t */\n\treadonly type: T;\n}\n\n/**\n * Stores annotations for a set of evaluated annotated allowed types.\n * @alpha\n */\nexport interface NormalizedAnnotatedAllowedTypes {\n\t/**\n\t * Annotations that apply to a set of allowed types.\n\t */\n\treadonly metadata: AllowedTypesMetadata;\n\t/**\n\t * All the evaluated allowed types that the annotations apply to. The types themselves are also individually annotated.\n\t */\n\treadonly types: readonly AnnotatedAllowedType<TreeNodeSchema>[];\n}\n\n/**\n * Checks if the input is an {@link AnnotatedAllowedTypes}.\n */\nexport function isAnnotatedAllowedTypes(\n\tallowedTypes: ImplicitAnnotatedAllowedTypes,\n): allowedTypes is AnnotatedAllowedTypes {\n\treturn (\n\t\t// Class based schema, and lazy schema references report type \"function\": filtering them out with typeof makes narrowing based on members mostly safe\n\t\ttypeof allowedTypes === \"object\" && \"metadata\" in allowedTypes && \"types\" in allowedTypes\n\t);\n}\n\n/**\n * Stores annotations for a set of allowed types.\n * @alpha\n */\nexport interface AnnotatedAllowedTypes {\n\t/**\n\t * Annotations that apply to a set of allowed types.\n\t */\n\treadonly metadata: AllowedTypesMetadata;\n\t/**\n\t * All the allowed types that the annotations apply to. The types themselves may also have individual annotations.\n\t */\n\treadonly types: readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[];\n}\n\n/**\n * Annotations that apply to a set of allowed types.\n * @remarks\n * Additional optionals may be added to this as non-breaking changes, so implementations of it should be simple object literals with no unlisted members.\n * @alpha\n */\nexport interface AllowedTypesMetadata {\n\t/**\n\t * User defined metadata\n\t */\n\treadonly custom?: unknown;\n}\n\n/**\n * Checks if the given allowed type is annotated with {@link AllowedTypeMetadata}.\n */\nexport function isAnnotatedAllowedType(\n\tallowedType: AnnotatedAllowedType | LazyItem<TreeNodeSchema>,\n): allowedType is AnnotatedAllowedType {\n\treturn \"metadata\" in allowedType && \"type\" in allowedType;\n}\n\n/**\n * Annotations that apply to an individual allowed type.\n * @remarks\n * Additional optionals may be added to this as non-breaking changes, so implementations of it should be simple object literals with no unlisted members.\n * @alpha\n */\nexport interface AllowedTypeMetadata {\n\t/**\n\t * User defined metadata\n\t */\n\treadonly custom?: unknown;\n\n\t// TODO metadata for enablable types will be added here\n}\n\n/**\n * Types of {@link TreeNode|TreeNodes} or {@link TreeLeafValue|TreeLeafValues} allowed at a location in a tree.\n * @remarks\n * Used by {@link TreeViewConfiguration} for the root and various kinds of {@link TreeNodeSchema} to specify their allowed child types.\n *\n * Use {@link SchemaFactory} to access leaf schema or declare new composite schema.\n *\n * Implicitly treats a single type as an array of one type.\n *\n * Arrays of schema can be used to specify multiple types are allowed, which result in unions of those types in the Tree APIs.\n *\n * When saved into variables, avoid type-erasing the details, as doing so loses the compile time schema awareness of APIs derived from the types.\n *\n * When referring to types that are declared after the definition of the `ImplicitAllowedTypes`, the schema can be wrapped in a lambda to allow the forward reference.\n * See {@link ValidateRecursiveSchema} for details on how to structure the `ImplicitAllowedTypes` instances when constructing recursive schema.\n *\n * @example Explicit use with strong typing\n * ```typescript\n * const sf = new SchemaFactory(\"myScope\");\n * const childTypes = [sf.number, sf.string] as const satisfies ImplicitAllowedTypes;\n * const config = new TreeViewConfiguration({ schema: childTypes });\n * ```\n *\n * @example Forward reference\n * ```typescript\n * const sf = new SchemaFactory(\"myScope\");\n * class A extends sf.array(\"example\", [() => B]) {}\n * class B extends sf.array(\"Inner\", sf.number) {}\n * ```\n * @privateRemarks\n * Code reading data from this should use `normalizeAllowedTypes` to ensure consistent handling, caching, nice errors etc.\n * @public\n */\nexport type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;\n\n/**\n * Types of {@link TreeNode|TreeNodes} or {@link TreeLeafValue|TreeLeafValues} allowed at a location in a tree with\n * additional metadata associated with the location they're allowed at.\n * @alpha\n */\nexport type ImplicitAnnotatedAllowedTypes =\n\t| TreeNodeSchema\n\t| AnnotatedAllowedType\n\t| AnnotatedAllowedTypes\n\t| readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[];\n\n/**\n * Returns an {@link ImplicitAllowedTypes} that is equivalent to the input without annotations.\n * @system @alpha\n */\nexport type UnannotateImplicitAllowedTypes<T extends ImplicitAnnotatedAllowedTypes> =\n\tT extends AnnotatedAllowedTypes\n\t\t? UnannotateAllowedTypes<T>\n\t\t: T extends AnnotatedAllowedType\n\t\t\t? UnannotateAllowedType<T>\n\t\t\t: T extends readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[]\n\t\t\t\t? UnannotateAllowedTypesList<T>\n\t\t\t\t: T extends TreeNodeSchema\n\t\t\t\t\t? T\n\t\t\t\t\t: never;\n\n/**\n * Removes annotations from a list of allowed types that may contain annotations.\n * @system @alpha\n */\nexport type UnannotateAllowedTypesList<\n\tT extends readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[],\n> = {\n\t[I in keyof T]: UnannotateAllowedTypeOrLazyItem<T[I]>;\n};\n\n/**\n * Removes annotations from an allowed type that may contain annotations.\n * @system @alpha\n */\nexport type UnannotateAllowedTypeOrLazyItem<\n\tT extends AnnotatedAllowedType | LazyItem<TreeNodeSchema>,\n> = T extends AnnotatedAllowedType<infer X> ? X : T;\n\n/**\n * Removes all annotations from a set of allowed types.\n * @system @alpha\n */\nexport type UnannotateAllowedTypes<T extends AnnotatedAllowedTypes> =\n\tUnannotateAllowedTypesList<T[\"types\"]>;\n\n/**\n * Removes annotations from an allowed type.\n * @system @alpha\n */\nexport type UnannotateAllowedType<T extends AnnotatedAllowedType> =\n\tT extends AnnotatedAllowedType<infer X> ? [X] : T;\n\n/**\n * Normalizes a {@link ImplicitAllowedTypes} to a set of {@link TreeNodeSchema}s, by eagerly evaluating any\n * lazy schema declarations.\n *\n * @remarks Note: this must only be called after all required schemas have been declared, otherwise evaluation of\n * recursive schemas may fail.\n *\n * @internal\n */\nexport function normalizeAllowedTypes(\n\ttypes: ImplicitAllowedTypes,\n): ReadonlySet<TreeNodeSchema> {\n\tconst normalized = new Set<TreeNodeSchema>();\n\tif (isReadonlyArray(types)) {\n\t\t// Types array must not be modified after it is normalized since that would result in the user of the normalized data having wrong (out of date) content.\n\t\tObject.freeze(types);\n\t\tfor (const lazyType of types) {\n\t\t\tnormalized.add(evaluateLazySchema(lazyType));\n\t\t}\n\t} else {\n\t\tnormalized.add(evaluateLazySchema(types));\n\t}\n\treturn normalized;\n}\n\n/**\n * Normalizes an allowed type to an {@link AnnotatedAllowedType}, by adding empty annotations if they don't already exist.\n */\nexport function normalizeToAnnotatedAllowedType<T extends TreeNodeSchema>(\n\ttype: T | AnnotatedAllowedType<T> | AnnotatedAllowedType<LazyItem<T>>,\n): AnnotatedAllowedType<T> | AnnotatedAllowedType<LazyItem<T>> {\n\treturn isAnnotatedAllowedType(type)\n\t\t? type\n\t\t: {\n\t\t\t\tmetadata: {},\n\t\t\t\ttype,\n\t\t\t};\n}\n\n/**\n * Normalizes a {@link ImplicitAnnotatedAllowedTypes} to a set of {@link AnnotatedAllowedSchema}s, by eagerly evaluating any\n * lazy schema declarations and adding empty metadata if it doesn't already exist.\n *\n * @remarks Note: this must only be called after all required schemas have been declared, otherwise evaluation of\n * recursive schemas may fail.\n */\nexport function normalizeAnnotatedAllowedTypes(\n\ttypes: ImplicitAnnotatedAllowedTypes,\n): NormalizedAnnotatedAllowedTypes {\n\tconst typesWithoutAnnotation = isAnnotatedAllowedTypes(types) ? types.types : types;\n\tconst annotatedTypes: AnnotatedAllowedType<TreeNodeSchema>[] = [];\n\tif (isReadonlyArray(typesWithoutAnnotation)) {\n\t\tfor (const annotatedType of typesWithoutAnnotation) {\n\t\t\tif (isAnnotatedAllowedType(annotatedType)) {\n\t\t\t\tannotatedTypes.push({\n\t\t\t\t\ttype: evaluateLazySchema(annotatedType.type),\n\t\t\t\t\tmetadata: annotatedType.metadata,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tannotatedTypes.push({ type: evaluateLazySchema(annotatedType), metadata: {} });\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif (isAnnotatedAllowedType(typesWithoutAnnotation)) {\n\t\t\tannotatedTypes.push({\n\t\t\t\ttype: evaluateLazySchema(typesWithoutAnnotation.type),\n\t\t\t\tmetadata: typesWithoutAnnotation.metadata,\n\t\t\t});\n\t\t} else {\n\t\t\tannotatedTypes.push({ type: evaluateLazySchema(typesWithoutAnnotation), metadata: {} });\n\t\t}\n\t}\n\n\treturn {\n\t\tmetadata: isAnnotatedAllowedTypes(types) ? types.metadata : {},\n\t\ttypes: annotatedTypes,\n\t};\n}\n\n/**\n * Converts an {@link ImplicitAnnotatedAllowedTypes} to an {@link ImplicitAllowedTypes}s, by removing\n * any annotations.\n * @remarks\n * This does not evaluate any lazy schemas.\n */\nexport function unannotateImplicitAllowedTypes<Types extends ImplicitAnnotatedAllowedTypes>(\n\ttypes: Types,\n): UnannotateImplicitAllowedTypes<Types> {\n\treturn (\n\t\tisAnnotatedAllowedTypes(types)\n\t\t\t? types.types.map((allowedType) =>\n\t\t\t\t\tisAnnotatedAllowedType(allowedType) ? allowedType.type : allowedType,\n\t\t\t\t)\n\t\t\t: isReadonlyArray(types)\n\t\t\t\t? types.map((allowedType) =>\n\t\t\t\t\t\tisAnnotatedAllowedType(allowedType) ? allowedType.type : allowedType,\n\t\t\t\t\t)\n\t\t\t\t: isAnnotatedAllowedType(types)\n\t\t\t\t\t? (types.type as UnannotateImplicitAllowedTypes<Types>)\n\t\t\t\t\t: types\n\t) as UnannotateImplicitAllowedTypes<Types>;\n}\n\nconst cachedLazyItem = new WeakMap<() => unknown, unknown>();\n\n/**\n * Returns the schema referenced by the {@link LazyItem}.\n * @remarks\n * Caches results to handle {@link LazyItem}s which compute their resulting schema.\n * @alpha\n */\nexport function evaluateLazySchema<T extends TreeNodeSchema>(value: LazyItem<T>): T {\n\tconst evaluatedSchema = isLazy(value)\n\t\t? (getOrCreate(cachedLazyItem, value, value) as T)\n\t\t: value;\n\tif (evaluatedSchema === undefined) {\n\t\tthrow new UsageError(\n\t\t\t`Encountered an undefined schema. This could indicate that some referenced schema has not yet been instantiated.`,\n\t\t);\n\t}\n\tmarkSchemaMostDerived(evaluatedSchema);\n\treturn evaluatedSchema;\n}\n\n/**\n * Indicates that the provided schema is the \"most derived\" version in its class hierarchy.\n *\n * @param oneTimeInitialize - If true this runs {@link TreeNodeValid.oneTimeInitialize} which does even more initialization and validation.\n * `oneTimeInitialize` can't safely be run until all transitively referenced schema are defined, so which cases can safely use it are more limited.\n * When legal for the caller to set this to true, it is preferred, but it is often not safe due to possible forward references.\n * @remarks\n * See {@link MostDerivedData} and {@link SchemaFactory} for details on what a \"most derived\" schema is and why it matters.\n *\n * This is a helper for invoking {@link TreeNodeValid.markMostDerived} for {@link TreeNodeSchema}.\n *\n * Calling this helps with error messages about invalid schema usage (See {@link SchemaFactory} for the rules, some of which this helps validate).\n * Typically this should be called for each schema as early as practical to improve error reporting for invalid usages of schema\n * (using two different schema derived from the same {@link SchemaFactory} produced base class).\n *\n * Note that construction of actual {@link TreeNode} instances or use of a schema transitively in a {@link TreeViewConfiguration} already do this,\n * so any calls to this that is unconditionally after that point for the given schema is not needed.\n * Instead most usages of this should be from those cases, and from miscellaneous cases where a schema is passed into an public API where theoretically someone could accidentally\n * pass in a base class of a schema instead of the most derived one.\n */\nexport function markSchemaMostDerived(\n\tschema: TreeNodeSchema,\n\toneTimeInitialize = false,\n): void {\n\t// Leaf schema are not classes, and thus do not need to be marked as most derived.\n\tif (schema.kind === NodeKind.Leaf) {\n\t\treturn;\n\t}\n\n\tconst schemaValid = schemaAsTreeNodeValid(schema);\n\n\tif (oneTimeInitialize) {\n\t\tschemaValid.oneTimeInitialize();\n\t} else {\n\t\tschemaValid.markMostDerived();\n\t}\n}\n\n/**\n * Type of tree node for a field of the given schema.\n * @public\n */\nexport type TreeNodeFromImplicitAllowedTypes<\n\tTSchema extends ImplicitAllowedTypes = TreeNodeSchema,\n> = TSchema extends TreeNodeSchema\n\t? NodeFromSchema<TSchema>\n\t: TSchema extends AllowedTypes\n\t\t? NodeFromSchema<FlexListToUnion<TSchema>>\n\t\t: unknown;\n\n/**\n * This type exists only to be linked from documentation to provide a single linkable place to document some details of\n * \"Input\" types and how they handle schema.\n *\n * 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.\n * (See also, [TypeScript Variance Annotations](https://www.typescriptlang.org/docs/handbook/2/generics.html#variance-annotations)).\n *\n * 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.\n *\n * Consider a field with schema type of `A | B` (where A and B are types of schema).\n *\n * - 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.\n *\n * - 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`.\n *\n * Note that this is distinct from the case where the schema is `[A, B]`.\n * 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).\n * When `A | B` is used, the field might allow\n * A but not B (so assigning a B value would be out of schema),\n * B but not A (so assigning an A value would be out of schema)\n * or both A and B.\n *\n * This gets more extreme when given completely unspecified schema.\n * For example if a field is just provided {@link ImplicitFieldSchema}, nothing is known about the content of the field.\n * This means that reading the field (via {@link TreeFieldFromImplicitField}) can give any valid tree field content,\n * 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`.\n *\n * To implement this variance correctly, the computation of types for input and output have to use separate utilities\n * which take very different approaches when encountering non-exact schema like unions or `ImplicitFieldSchema`.\n * The utilities which behave contravariantly (as required to handle input correctly) link this documentation to indicate that this is how they behave.\n *\n * In addition to behaving contravariantly, these input type computation utilities often have further limitations.\n * This is due to TypeScript making it difficult to implement this contravariance exactly.\n * When faced with these implementation limitations these contravariant type computation utilities error on the side of producing overly strict requirements.\n * 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`.\n * Future versions of the API can relax these requirements as the type computations are made more accurate.\n *\n * For a more concrete example: if {@link InsertableTreeFieldFromImplicitField} produced `never` for a schema `A | OptionalField<A>`,\n * a future version could instead return a more flexible but still safe type, like `A`.\n *\n * More generally: try to avoid providing non-exact schema, especially for the fields of other schema.\n * While these APIs attempt to handle such cases correctly, there are limitations and known bugs in this handling.\n * Code using non-exact schema is much more likely to have its compilation break due to updates of this package or even TypeScript,\n * and thus compilation breaks due to edge cases of non-exact schema handling, especially with recursive schema, are not considered breaking changes.\n * This may change as the API become more stable.\n *\n * @privateRemarks\n * There likely is a better way to share this documentation, but none was found at the time of writing.\n *\n * TODO: Once {@link InsertableField} is public, consider using it in the examples above.\n * @system @public\n */\nexport type Input<T extends never> = T;\n\n/**\n * Type of content that can be inserted into the tree for a node of the given schema.\n *\n * @see {@link Input}\n *\n * @typeparam TSchema - Schema to process.\n *\n * @privateRemarks\n * This is a bit overly conservative, since cases like `A | [A]` give never and could give `A`.\n * @public\n */\nexport type InsertableTreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes> =\n\t[TSchema] extends [TreeNodeSchema]\n\t\t? InsertableTypedNode<TSchema>\n\t\t: [TSchema] extends [AllowedTypes]\n\t\t\t? InsertableTreeNodeFromAllowedTypes<TSchema>\n\t\t\t: never;\n\n/**\n * Type of content that can be inserted into the tree for a node of the given schema.\n *\n * @see {@link Input}\n *\n * @typeparam TList - AllowedTypes to process\n *\n * @privateRemarks\n * This loop is manually unrolled to allow larger unions before hitting the recursion limit in TypeScript.\n * @system @public\n */\nexport type InsertableTreeNodeFromAllowedTypes<TList extends AllowedTypes> =\n\tIsUnion<TList> extends true\n\t\t? never\n\t\t: {\n\t\t\t\treadonly [Property in keyof TList]: TList[Property] extends LazyItem<\n\t\t\t\t\tinfer TSchema extends TreeNodeSchema\n\t\t\t\t>\n\t\t\t\t\t? InsertableTypedNode<TSchema>\n\t\t\t\t\t: never;\n\t\t\t}[number];\n"]}
|
|
1
|
+
{"version":3,"file":"allowedTypes.js","sourceRoot":"","sources":["../../../src/simple-tree/core/allowedTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AAEtE,kDAAiF;AACjF,+CAA4E;AAC5E,2DAK6B;AAC7B,yDAA2D;AAyD3D;;GAEG;AACH,SAAgB,uBAAuB,CACtC,YAA2C;IAE3C,2BAA2B,CAAC,YAAY,CAAC,CAAC;IAC1C,OAAO;IACN,qJAAqJ;IACrJ,OAAO,YAAY,KAAK,QAAQ,IAAI,UAAU,IAAI,YAAY,IAAI,OAAO,IAAI,YAAY,CACzF,CAAC;AACH,CAAC;AARD,0DAQC;AA8BD;;GAEG;AACH,SAAgB,sBAAsB,CACrC,WAA4D;IAE5D,2BAA2B,CAAC,WAAW,CAAC,CAAC;IACzC,qJAAqJ;IACrJ,OAAO,OAAO,WAAW,KAAK,QAAQ,IAAI,UAAU,IAAI,WAAW,IAAI,MAAM,IAAI,WAAW,CAAC;AAC9F,CAAC;AAND,wDAMC;AA8GD;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CACpC,KAAoC;IAEpC,wCAAwC;IACxC,MAAM,WAAW,GAAG,8BAA8B,CAAC,KAAK,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC7C,IAAI,IAAA,0BAAe,EAAC,WAAW,CAAC,EAAE,CAAC;QAClC,yJAAyJ;QACzJ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAC3B,KAAK,MAAM,QAAQ,IAAI,WAAW,EAAE,CAAC;YACpC,UAAU,CAAC,GAAG,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;SAAM,CAA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AAA,sBAAW,EAAC,cAAc,EAAE,KAAK,EAAE,KAAK,CAAO;QAClD,CAAC,CAAC,KAAK,CAAC;IAET,2BAA2B,CAAC,eAAe,CAAC,CAAC;IAC7C,qBAAqB,CAAC,eAAe,CAAC,CAAC;IACvC,OAAO,eAAe,CAAC;AACxB,CAAC;AARD,gDAQC;AAED;;GAEG;AACH,SAAgB,2BAA2B,CAC1C,MAAgE;IAEhE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,qBAAU,CACnB,6PAA6P,CAC7P,CAAC;IACH,CAAC;AACF,CAAC;AARD,kEAQC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,qBAAqB,CACpC,MAAsB,EACtB,iBAAiB,GAAG,KAAK;IAEzB,kFAAkF;IAClF,IAAI,MAAM,CAAC,IAAI,KAAK,4BAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,OAAO;IACR,CAAC;IAED,MAAM,WAAW,GAAG,IAAA,wCAAqB,EAAC,MAAM,CAAC,CAAC;IAElD,IAAI,iBAAiB,EAAE,CAAC;QACvB,WAAW,CAAC,iBAAiB,EAAE,CAAC;IACjC,CAAC;SAAM,CAAC;QACP,WAAW,CAAC,eAAe,EAAE,CAAC;IAC/B,CAAC;AACF,CAAC;AAhBD,sDAgBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { getOrCreate, isReadonlyArray, type IsUnion } from \"../../util/index.js\";\nimport { isLazy, type FlexListToUnion, type LazyItem } from \"./flexList.js\";\nimport {\n\tNodeKind,\n\ttype InsertableTypedNode,\n\ttype NodeFromSchema,\n\ttype TreeNodeSchema,\n} from \"./treeNodeSchema.js\";\nimport { schemaAsTreeNodeValid } from \"./treeNodeValid.js\";\n\n/**\n * Schema for types allowed in some location in a tree (like a field, map entry or array).\n * @remarks\n * Type constraint used in schema declaration APIs.\n *\n * The order of types in the array is not significant.\n * Additionally, it is legal for users of this type to have the runtime and compile time order of items within this array not match.\n * Therefor to ensure type safety, these arrays should not be indexed, and instead just be iterated.\n *\n * 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)\n * way to declare and manipulate unordered sets of types in TypeScript.\n *\n * Duplicate entries in this array are not allowed and will produce runtime errors.\n * Duplicate types are allowed,\n * but this must only be reflected in the type and not the runtime values.\n * This duplication can be used to encode the typing when the number of items in the array is not known at compile time\n * but some of the items are known to be present unconditionally.\n * For example, typing `[typeof A] | [typeof A, typeof B]` as `[typeof A, typeof B | typeof A]` is allowed,\n * and can produce more useful {@link Input} types.\n * @privateRemarks\n * Code reading data from this should use `normalizeAllowedTypes` to ensure consistent handling, caching, nice errors etc.\n * @system @public\n */\nexport type AllowedTypes = readonly LazyItem<TreeNodeSchema>[];\n\n/**\n * Stores annotations for an individual allowed type.\n * @alpha\n */\nexport interface AnnotatedAllowedType<T = LazyItem<TreeNodeSchema>> {\n\t/**\n\t * Annotations for the allowed type.\n\t */\n\treadonly metadata: AllowedTypeMetadata;\n\t/**\n\t * The allowed type the annotations apply to in a particular schema.\n\t */\n\treadonly type: T;\n}\n\n/**\n * Stores annotations for a set of evaluated annotated allowed types.\n * @alpha\n */\nexport interface NormalizedAnnotatedAllowedTypes {\n\t/**\n\t * Annotations that apply to a set of allowed types.\n\t */\n\treadonly metadata: AllowedTypesMetadata;\n\t/**\n\t * All the evaluated allowed types that the annotations apply to. The types themselves are also individually annotated.\n\t */\n\treadonly types: readonly AnnotatedAllowedType<TreeNodeSchema>[];\n}\n\n/**\n * Checks if the input is an {@link AnnotatedAllowedTypes}.\n */\nexport function isAnnotatedAllowedTypes(\n\tallowedTypes: ImplicitAnnotatedAllowedTypes,\n): allowedTypes is AnnotatedAllowedTypes {\n\tcheckForUninitializedSchema(allowedTypes);\n\treturn (\n\t\t// Class based schema, and lazy schema references report type \"function\": filtering them out with typeof makes narrowing based on members mostly safe\n\t\ttypeof allowedTypes === \"object\" && \"metadata\" in allowedTypes && \"types\" in allowedTypes\n\t);\n}\n\n/**\n * Stores annotations for a set of allowed types.\n * @alpha\n */\nexport interface AnnotatedAllowedTypes {\n\t/**\n\t * Annotations that apply to a set of allowed types.\n\t */\n\treadonly metadata: AllowedTypesMetadata;\n\t/**\n\t * All the allowed types that the annotations apply to. The types themselves may also have individual annotations.\n\t */\n\treadonly types: readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[];\n}\n\n/**\n * Annotations that apply to a set of allowed types.\n * @remarks\n * Additional optionals may be added to this as non-breaking changes, so implementations of it should be simple object literals with no unlisted members.\n * @alpha\n */\nexport interface AllowedTypesMetadata {\n\t/**\n\t * User defined metadata\n\t */\n\treadonly custom?: unknown;\n}\n\n/**\n * Checks if the given allowed type is annotated with {@link AllowedTypeMetadata}.\n */\nexport function isAnnotatedAllowedType(\n\tallowedType: AnnotatedAllowedType | LazyItem<TreeNodeSchema>,\n): allowedType is AnnotatedAllowedType {\n\tcheckForUninitializedSchema(allowedType);\n\t// Class based schema, and lazy schema references report type \"function\": filtering them out with typeof makes narrowing based on members mostly safe\n\treturn typeof allowedType === \"object\" && \"metadata\" in allowedType && \"type\" in allowedType;\n}\n\n/**\n * Annotations that apply to an individual allowed type.\n * @remarks\n * Additional optionals may be added to this as non-breaking changes, so implementations of it should be simple object literals with no unlisted members.\n * @alpha\n */\nexport interface AllowedTypeMetadata {\n\t/**\n\t * User defined metadata\n\t */\n\treadonly custom?: unknown;\n\n\t// TODO metadata for enablable types will be added here\n}\n\n/**\n * Types of {@link TreeNode|TreeNodes} or {@link TreeLeafValue|TreeLeafValues} allowed at a location in a tree.\n * @remarks\n * Used by {@link TreeViewConfiguration} for the root and various kinds of {@link TreeNodeSchema} to specify their allowed child types.\n *\n * Use {@link SchemaFactory} to access leaf schema or declare new composite schema.\n *\n * Implicitly treats a single type as an array of one type.\n *\n * Arrays of schema can be used to specify multiple types are allowed, which result in unions of those types in the Tree APIs.\n *\n * When saved into variables, avoid type-erasing the details, as doing so loses the compile time schema awareness of APIs derived from the types.\n *\n * When referring to types that are declared after the definition of the `ImplicitAllowedTypes`, the schema can be wrapped in a lambda to allow the forward reference.\n * See {@link ValidateRecursiveSchema} for details on how to structure the `ImplicitAllowedTypes` instances when constructing recursive schema.\n *\n * @example Explicit use with strong typing\n * ```typescript\n * const sf = new SchemaFactory(\"myScope\");\n * const childTypes = [sf.number, sf.string] as const satisfies ImplicitAllowedTypes;\n * const config = new TreeViewConfiguration({ schema: childTypes });\n * ```\n *\n * @example Forward reference\n * ```typescript\n * const sf = new SchemaFactory(\"myScope\");\n * class A extends sf.array(\"example\", [() => B]) {}\n * class B extends sf.array(\"Inner\", sf.number) {}\n * ```\n * @privateRemarks\n * Code reading data from this should use `normalizeAllowedTypes` to ensure consistent handling, caching, nice errors etc.\n * @public\n */\nexport type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;\n\n/**\n * Types of {@link TreeNode|TreeNodes} or {@link TreeLeafValue|TreeLeafValues} allowed at a location in a tree with\n * additional metadata associated with the location they're allowed at.\n * @alpha\n */\nexport type ImplicitAnnotatedAllowedTypes =\n\t| TreeNodeSchema\n\t| AnnotatedAllowedType\n\t| AnnotatedAllowedTypes\n\t| readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[];\n\n/**\n * Returns an {@link ImplicitAllowedTypes} that is equivalent to the input without annotations.\n * @system @alpha\n */\nexport type UnannotateImplicitAllowedTypes<T extends ImplicitAnnotatedAllowedTypes> =\n\tT extends AnnotatedAllowedTypes\n\t\t? UnannotateAllowedTypes<T>\n\t\t: T extends AnnotatedAllowedType\n\t\t\t? UnannotateAllowedType<T>\n\t\t\t: T extends readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[]\n\t\t\t\t? UnannotateAllowedTypesList<T>\n\t\t\t\t: T extends TreeNodeSchema\n\t\t\t\t\t? T\n\t\t\t\t\t: never;\n\n/**\n * Removes annotations from a list of allowed types that may contain annotations.\n * @system @alpha\n */\nexport type UnannotateAllowedTypesList<\n\tT extends readonly (AnnotatedAllowedType | LazyItem<TreeNodeSchema>)[],\n> = {\n\t[I in keyof T]: UnannotateAllowedTypeOrLazyItem<T[I]>;\n};\n\n/**\n * Removes annotations from an allowed type that may contain annotations.\n * @system @alpha\n */\nexport type UnannotateAllowedTypeOrLazyItem<\n\tT extends AnnotatedAllowedType | LazyItem<TreeNodeSchema>,\n> = T extends AnnotatedAllowedType<infer X> ? X : T;\n\n/**\n * Removes all annotations from a set of allowed types.\n * @system @alpha\n */\nexport type UnannotateAllowedTypes<T extends AnnotatedAllowedTypes> =\n\tUnannotateAllowedTypesList<T[\"types\"]>;\n\n/**\n * Removes annotations from an allowed type.\n * @system @alpha\n */\nexport type UnannotateAllowedType<T extends AnnotatedAllowedType | LazyItem<TreeNodeSchema>> =\n\tT extends AnnotatedAllowedType<infer X> ? [X] : T;\n\n/**\n * Normalizes a {@link ImplicitAllowedTypes} to a set of {@link TreeNodeSchema}s, by eagerly evaluating any\n * lazy schema declarations.\n *\n * @remarks Note: this must only be called after all required schemas have been declared, otherwise evaluation of\n * recursive schemas may fail.\n *\n * @internal\n */\nexport function normalizeAllowedTypes(\n\ttypes: ImplicitAnnotatedAllowedTypes,\n): ReadonlySet<TreeNodeSchema> {\n\t// remove annotations before normalizing\n\tconst unannotated = unannotateImplicitAllowedTypes(types);\n\tconst normalized = new Set<TreeNodeSchema>();\n\tif (isReadonlyArray(unannotated)) {\n\t\t// Types array must not be modified after it is normalized since that would result in the user of the normalized data having wrong (out of date) content.\n\t\tObject.freeze(unannotated);\n\t\tfor (const lazyType of unannotated) {\n\t\t\tnormalized.add(evaluateLazySchema(lazyType));\n\t\t}\n\t} else {\n\t\tnormalized.add(evaluateLazySchema(unannotated));\n\t}\n\treturn normalized;\n}\n\n/**\n * Normalizes an allowed type to an {@link AnnotatedAllowedType}, by adding empty annotations if they don't already exist\n * and eagerly evaluating any lazy schema declarations.\n *\n * @remarks\n * Note: this must only be called after all required schemas have been declared, otherwise evaluation of\n * recursive schemas may fail.\n * type is frozen and should not be modified after being passed in.\n */\nexport function normalizeToAnnotatedAllowedType<T extends TreeNodeSchema>(\n\ttype: T | AnnotatedAllowedType<T> | AnnotatedAllowedType<LazyItem<T>>,\n): AnnotatedAllowedType<T> {\n\treturn isAnnotatedAllowedType(type)\n\t\t? {\n\t\t\t\tmetadata: type.metadata,\n\t\t\t\ttype: evaluateLazySchema(type.type),\n\t\t\t}\n\t\t: {\n\t\t\t\tmetadata: {},\n\t\t\t\ttype,\n\t\t\t};\n}\n\n/**\n * Normalizes a {@link ImplicitAnnotatedAllowedTypes} to a set of {@link AnnotatedAllowedSchema}s, by eagerly evaluating any\n * lazy schema declarations and adding empty metadata if it doesn't already exist.\n *\n * @remarks Note: this must only be called after all required schemas have been declared, otherwise evaluation of\n * recursive schemas may fail.\n */\nexport function normalizeAnnotatedAllowedTypes(\n\ttypes: ImplicitAnnotatedAllowedTypes,\n): NormalizedAnnotatedAllowedTypes {\n\tconst typesWithoutAnnotation = isAnnotatedAllowedTypes(types) ? types.types : types;\n\tconst annotatedTypes: AnnotatedAllowedType<TreeNodeSchema>[] = [];\n\tif (isReadonlyArray(typesWithoutAnnotation)) {\n\t\tfor (const annotatedType of typesWithoutAnnotation) {\n\t\t\tif (isAnnotatedAllowedType(annotatedType)) {\n\t\t\t\tannotatedTypes.push({\n\t\t\t\t\ttype: evaluateLazySchema(annotatedType.type),\n\t\t\t\t\tmetadata: annotatedType.metadata,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tannotatedTypes.push({ type: evaluateLazySchema(annotatedType), metadata: {} });\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif (isAnnotatedAllowedType(typesWithoutAnnotation)) {\n\t\t\tannotatedTypes.push({\n\t\t\t\ttype: evaluateLazySchema(typesWithoutAnnotation.type),\n\t\t\t\tmetadata: typesWithoutAnnotation.metadata,\n\t\t\t});\n\t\t} else {\n\t\t\tannotatedTypes.push({ type: evaluateLazySchema(typesWithoutAnnotation), metadata: {} });\n\t\t}\n\t}\n\n\treturn {\n\t\tmetadata: isAnnotatedAllowedTypes(types) ? types.metadata : {},\n\t\ttypes: annotatedTypes,\n\t};\n}\n\n/**\n * Converts an {@link ImplicitAnnotatedAllowedTypes} to an {@link ImplicitAllowedTypes}s, by removing\n * any annotations.\n * @remarks\n * This does not evaluate any lazy schemas.\n */\nexport function unannotateImplicitAllowedTypes<Types extends ImplicitAnnotatedAllowedTypes>(\n\ttypes: Types,\n): UnannotateImplicitAllowedTypes<Types> {\n\treturn (\n\t\tisAnnotatedAllowedTypes(types)\n\t\t\t? types.types.map(unannotateAllowedType)\n\t\t\t: isReadonlyArray(types)\n\t\t\t\t? types.map(unannotateAllowedType)\n\t\t\t\t: isAnnotatedAllowedType(types)\n\t\t\t\t\t? types.type\n\t\t\t\t\t: types\n\t) as UnannotateImplicitAllowedTypes<Types>;\n}\n\n/**\n * Converts an {@link AnnotatedAllowedType} to an {@link LazyItem} by removing any annotations.\n * @remarks\n * This does not evaluate any lazy schemas.\n */\nexport function unannotateAllowedType<\n\tType extends AnnotatedAllowedType | LazyItem<TreeNodeSchema>,\n>(allowedType: Type): UnannotateAllowedType<Type> {\n\treturn isAnnotatedAllowedType(allowedType)\n\t\t? (allowedType.type as UnannotateAllowedType<Type>)\n\t\t: (allowedType as UnannotateAllowedType<Type>);\n}\n\nconst cachedLazyItem = new WeakMap<() => unknown, unknown>();\n\n/**\n * Returns the schema referenced by the {@link LazyItem}.\n * @remarks\n * Caches results to handle {@link LazyItem}s which compute their resulting schema.\n * @alpha\n */\nexport function evaluateLazySchema<T extends TreeNodeSchema>(value: LazyItem<T>): T {\n\tconst evaluatedSchema = isLazy(value)\n\t\t? (getOrCreate(cachedLazyItem, value, value) as T)\n\t\t: value;\n\n\tcheckForUninitializedSchema(evaluatedSchema);\n\tmarkSchemaMostDerived(evaluatedSchema);\n\treturn evaluatedSchema;\n}\n\n/**\n * Throws a UsageError if the provided schema is undefined, most likely due to being used before it was initialized.\n */\nexport function checkForUninitializedSchema(\n\tschema: ImplicitAnnotatedAllowedTypes | LazyItem<TreeNodeSchema>,\n): void {\n\tif (schema === undefined) {\n\t\tthrow new UsageError(\n\t\t\t`Encountered an undefined schema. This could indicate that some referenced schema has not yet been instantiated. Consider using a lazy schema reference (like \"() => schema\") or delaying the evaluation of the lazy reference if one is already being used.`,\n\t\t);\n\t}\n}\n\n/**\n * Indicates that the provided schema is the \"most derived\" version in its class hierarchy.\n *\n * @param oneTimeInitialize - If true this runs {@link TreeNodeValid.oneTimeInitialize} which does even more initialization and validation.\n * `oneTimeInitialize` can't safely be run until all transitively referenced schema are defined, so which cases can safely use it are more limited.\n * When legal for the caller to set this to true, it is preferred, but it is often not safe due to possible forward references.\n * @remarks\n * See {@link MostDerivedData} and {@link SchemaFactory} for details on what a \"most derived\" schema is and why it matters.\n *\n * This is a helper for invoking {@link TreeNodeValid.markMostDerived} for {@link TreeNodeSchema}.\n *\n * Calling this helps with error messages about invalid schema usage (See {@link SchemaFactory} for the rules, some of which this helps validate).\n * Typically this should be called for each schema as early as practical to improve error reporting for invalid usages of schema\n * (using two different schema derived from the same {@link SchemaFactory} produced base class).\n *\n * Note that construction of actual {@link TreeNode} instances or use of a schema transitively in a {@link TreeViewConfiguration} already do this,\n * so any calls to this that is unconditionally after that point for the given schema is not needed.\n * Instead most usages of this should be from those cases, and from miscellaneous cases where a schema is passed into an public API where theoretically someone could accidentally\n * pass in a base class of a schema instead of the most derived one.\n */\nexport function markSchemaMostDerived(\n\tschema: TreeNodeSchema,\n\toneTimeInitialize = false,\n): void {\n\t// Leaf schema are not classes, and thus do not need to be marked as most derived.\n\tif (schema.kind === NodeKind.Leaf) {\n\t\treturn;\n\t}\n\n\tconst schemaValid = schemaAsTreeNodeValid(schema);\n\n\tif (oneTimeInitialize) {\n\t\tschemaValid.oneTimeInitialize();\n\t} else {\n\t\tschemaValid.markMostDerived();\n\t}\n}\n\n/**\n * Type of tree node for a field of the given schema.\n * @public\n */\nexport type TreeNodeFromImplicitAllowedTypes<\n\tTSchema extends ImplicitAllowedTypes = TreeNodeSchema,\n> = TSchema extends TreeNodeSchema\n\t? NodeFromSchema<TSchema>\n\t: TSchema extends AllowedTypes\n\t\t? NodeFromSchema<FlexListToUnion<TSchema>>\n\t\t: unknown;\n\n/**\n * This type exists only to be linked from documentation to provide a single linkable place to document some details of\n * \"Input\" types and how they handle schema.\n *\n * 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.\n * (See also, [TypeScript Variance Annotations](https://www.typescriptlang.org/docs/handbook/2/generics.html#variance-annotations)).\n *\n * 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.\n *\n * Consider a field with schema type of `A | B` (where A and B are types of schema).\n *\n * - 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.\n *\n * - 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`.\n *\n * Note that this is distinct from the case where the schema is `[A, B]`.\n * 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).\n * When `A | B` is used, the field might allow\n * A but not B (so assigning a B value would be out of schema),\n * B but not A (so assigning an A value would be out of schema)\n * or both A and B.\n *\n * This gets more extreme when given completely unspecified schema.\n * For example if a field is just provided {@link ImplicitFieldSchema}, nothing is known about the content of the field.\n * This means that reading the field (via {@link TreeFieldFromImplicitField}) can give any valid tree field content,\n * 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`.\n *\n * To implement this variance correctly, the computation of types for input and output have to use separate utilities\n * which take very different approaches when encountering non-exact schema like unions or `ImplicitFieldSchema`.\n * The utilities which behave contravariantly (as required to handle input correctly) link this documentation to indicate that this is how they behave.\n *\n * In addition to behaving contravariantly, these input type computation utilities often have further limitations.\n * This is due to TypeScript making it difficult to implement this contravariance exactly.\n * When faced with these implementation limitations these contravariant type computation utilities error on the side of producing overly strict requirements.\n * 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`.\n * Future versions of the API can relax these requirements as the type computations are made more accurate.\n *\n * For a more concrete example: if {@link InsertableTreeFieldFromImplicitField} produced `never` for a schema `A | OptionalField<A>`,\n * a future version could instead return a more flexible but still safe type, like `A`.\n *\n * More generally: try to avoid providing non-exact schema, especially for the fields of other schema.\n * While these APIs attempt to handle such cases correctly, there are limitations and known bugs in this handling.\n * Code using non-exact schema is much more likely to have its compilation break due to updates of this package or even TypeScript,\n * and thus compilation breaks due to edge cases of non-exact schema handling, especially with recursive schema, are not considered breaking changes.\n * This may change as the API become more stable.\n *\n * @privateRemarks\n * There likely is a better way to share this documentation, but none was found at the time of writing.\n *\n * TODO: Once {@link InsertableField} is public, consider using it in the examples above.\n * @system @public\n */\nexport type Input<T extends never> = T;\n\n/**\n * Type of content that can be inserted into the tree for a node of the given schema.\n *\n * @see {@link Input}\n *\n * @typeparam TSchema - Schema to process.\n *\n * @privateRemarks\n * This is a bit overly conservative, since cases like `A | [A]` give never and could give `A`.\n * @public\n */\nexport type InsertableTreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes> =\n\t[TSchema] extends [TreeNodeSchema]\n\t\t? InsertableTypedNode<TSchema>\n\t\t: [TSchema] extends [AllowedTypes]\n\t\t\t? InsertableTreeNodeFromAllowedTypes<TSchema>\n\t\t\t: never;\n\n/**\n * Type of content that can be inserted into the tree for a node of the given schema.\n *\n * @see {@link Input}\n *\n * @typeparam TList - AllowedTypes to process\n *\n * @privateRemarks\n * This loop is manually unrolled to allow larger unions before hitting the recursion limit in TypeScript.\n * @system @public\n */\nexport type InsertableTreeNodeFromAllowedTypes<TList extends AllowedTypes> =\n\tIsUnion<TList> extends true\n\t\t? never\n\t\t: {\n\t\t\t\treadonly [Property in keyof TList]: TList[Property] extends LazyItem<\n\t\t\t\t\tinfer TSchema extends TreeNodeSchema\n\t\t\t\t>\n\t\t\t\t\t? InsertableTypedNode<TSchema>\n\t\t\t\t\t: never;\n\t\t\t}[number];\n"]}
|
|
@@ -31,12 +31,23 @@ export declare class Context {
|
|
|
31
31
|
* This design mirrors how {@link FlexTreeSchema} are accessed off the {@link FlexTreeContext}, making the migration away from them simpler.
|
|
32
32
|
*/
|
|
33
33
|
readonly schema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeSchema>;
|
|
34
|
+
static schemaMapFromRootSchema(rootSchema: NormalizedAnnotatedAllowedTypes): ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeSchema>;
|
|
34
35
|
/**
|
|
35
36
|
* Builds the context.
|
|
36
37
|
* @remarks
|
|
37
38
|
* Since this walks the schema, it must not be invoked during schema declaration or schema forward references could fail to be resolved.
|
|
38
39
|
*/
|
|
39
|
-
constructor(
|
|
40
|
+
constructor(flexContext: FlexTreeContext,
|
|
41
|
+
/**
|
|
42
|
+
* All schema which could transitively be used under the associated node.
|
|
43
|
+
* @remarks
|
|
44
|
+
* While generally {@link TreeNodeSchema} are referenced as objects and thus do not need to be looked up by identifier,
|
|
45
|
+
* there are a few cases (mainly constructing new TreeNodes from existing tree data) where such a lookup is useful.
|
|
46
|
+
* Having this map in the context addresses this use-case.
|
|
47
|
+
* @privateRemarks
|
|
48
|
+
* This design mirrors how {@link FlexTreeSchema} are accessed off the {@link FlexTreeContext}, making the migration away from them simpler.
|
|
49
|
+
*/
|
|
50
|
+
schema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeSchema>);
|
|
40
51
|
}
|
|
41
52
|
/**
|
|
42
53
|
* Extends {@link Context} with additional information from the view and/or tree which becomes known when a {@link TreeNode} is hydrated,
|
|
@@ -44,6 +55,6 @@ export declare class Context {
|
|
|
44
55
|
*/
|
|
45
56
|
export declare class HydratedContext extends Context {
|
|
46
57
|
readonly flexContext: FlexTreeHydratedContext;
|
|
47
|
-
constructor(
|
|
58
|
+
constructor(flexContext: FlexTreeHydratedContext, schema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeSchema>);
|
|
48
59
|
}
|
|
49
60
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/core/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,KAAK,EACX,eAAe,EACf,uBAAuB,EACvB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D;;;;;;;;;;;;GAYG;AACH,qBAAa,OAAO;aAmBF,WAAW,EAAE,eAAe;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/core/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,KAAK,EACX,eAAe,EACf,uBAAuB,EACvB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D;;;;;;;;;;;;GAYG;AACH,qBAAa,OAAO;aAmBF,WAAW,EAAE,eAAe;IAC5C;;;;;;;;OAQG;aACa,MAAM,EAAE,WAAW,CAAC,wBAAwB,EAAE,cAAc,CAAC;WA5BhE,uBAAuB,CACpC,UAAU,EAAE,+BAA+B,GACzC,WAAW,CAAC,wBAAwB,EAAE,cAAc,CAAC;IAUxD;;;;OAIG;gBAEc,WAAW,EAAE,eAAe;IAC5C;;;;;;;;OAQG;IACa,MAAM,EAAE,WAAW,CAAC,wBAAwB,EAAE,cAAc,CAAC;CAE9E;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,OAAO;aAEjB,WAAW,EAAE,uBAAuB;gBAApC,WAAW,EAAE,uBAAuB,EAC7D,MAAM,EAAE,WAAW,CAAC,wBAAwB,EAAE,cAAc,CAAC;CAI9D"}
|
|
@@ -21,19 +21,32 @@ const walkSchema_js_1 = require("./walkSchema.js");
|
|
|
21
21
|
* This design is the same as {@link FlexTreeContext} with its base type and {@link FlexTreeHydratedContext} extending it.
|
|
22
22
|
*/
|
|
23
23
|
class Context {
|
|
24
|
-
|
|
25
|
-
* Builds the context.
|
|
26
|
-
* @remarks
|
|
27
|
-
* Since this walks the schema, it must not be invoked during schema declaration or schema forward references could fail to be resolved.
|
|
28
|
-
*/
|
|
29
|
-
constructor(rootSchema, flexContext) {
|
|
30
|
-
this.flexContext = flexContext;
|
|
24
|
+
static schemaMapFromRootSchema(rootSchema) {
|
|
31
25
|
const schema = new Map();
|
|
32
26
|
(0, walkSchema_js_1.walkAllowedTypes)(rootSchema, {
|
|
33
27
|
node(nodeSchema) {
|
|
34
28
|
schema.set((0, index_js_1.brand)(nodeSchema.identifier), nodeSchema);
|
|
35
29
|
},
|
|
36
30
|
});
|
|
31
|
+
return schema;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Builds the context.
|
|
35
|
+
* @remarks
|
|
36
|
+
* Since this walks the schema, it must not be invoked during schema declaration or schema forward references could fail to be resolved.
|
|
37
|
+
*/
|
|
38
|
+
constructor(flexContext,
|
|
39
|
+
/**
|
|
40
|
+
* All schema which could transitively be used under the associated node.
|
|
41
|
+
* @remarks
|
|
42
|
+
* While generally {@link TreeNodeSchema} are referenced as objects and thus do not need to be looked up by identifier,
|
|
43
|
+
* there are a few cases (mainly constructing new TreeNodes from existing tree data) where such a lookup is useful.
|
|
44
|
+
* Having this map in the context addresses this use-case.
|
|
45
|
+
* @privateRemarks
|
|
46
|
+
* This design mirrors how {@link FlexTreeSchema} are accessed off the {@link FlexTreeContext}, making the migration away from them simpler.
|
|
47
|
+
*/
|
|
48
|
+
schema) {
|
|
49
|
+
this.flexContext = flexContext;
|
|
37
50
|
this.schema = schema;
|
|
38
51
|
}
|
|
39
52
|
}
|
|
@@ -43,8 +56,8 @@ exports.Context = Context;
|
|
|
43
56
|
* associating it with the containing {@link TreeView}.
|
|
44
57
|
*/
|
|
45
58
|
class HydratedContext extends Context {
|
|
46
|
-
constructor(
|
|
47
|
-
super(
|
|
59
|
+
constructor(flexContext, schema) {
|
|
60
|
+
super(flexContext, schema);
|
|
48
61
|
this.flexContext = flexContext;
|
|
49
62
|
}
|
|
50
63
|
}
|