@fluidframework/tree 2.50.0 → 2.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +3 -2
- package/.vscode/Tree.code-workspace +14 -1
- package/.vscode/settings.json +16 -0
- package/CHANGELOG.md +51 -2
- package/api-report/tree.alpha.api.md +7 -7
- package/dist/core/schema-stored/schema.d.ts +14 -1
- package/dist/core/schema-stored/schema.d.ts.map +1 -1
- package/dist/core/schema-stored/schema.js.map +1 -1
- package/dist/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
- package/dist/feature-libraries/default-schema/schemaChecker.js +3 -0
- package/dist/feature-libraries/default-schema/schemaChecker.js.map +1 -1
- package/dist/feature-libraries/flex-tree/context.d.ts +7 -2
- package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/context.js +4 -4
- package/dist/feature-libraries/flex-tree/context.js.map +1 -1
- package/dist/feature-libraries/flex-tree/index.d.ts +1 -0
- package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/index.js +3 -1
- package/dist/feature-libraries/flex-tree/index.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.js +5 -5
- package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts +3 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.js +5 -3
- package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
- package/dist/feature-libraries/forest-summary/forestSummarizer.js +3 -4
- package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +2 -2
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +3 -8
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/comparison.js +0 -3
- package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
- package/dist/feature-libraries/modular-schema/index.d.ts +0 -1
- package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/dist/feature-libraries/modular-schema/index.js +1 -8
- package/dist/feature-libraries/modular-schema/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/index.d.ts +0 -1
- package/dist/shared-tree/index.d.ts.map +1 -1
- package/dist/shared-tree/index.js +1 -3
- package/dist/shared-tree/index.js.map +1 -1
- package/dist/shared-tree/schematizeTree.d.ts +1 -1
- package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
- package/dist/shared-tree/schematizeTree.js +7 -10
- package/dist/shared-tree/schematizeTree.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.d.ts +11 -13
- package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +60 -83
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTreeChangeTypes.d.ts +1 -1
- package/dist/shared-tree/sharedTreeChangeTypes.js.map +1 -1
- package/dist/shared-tree/tree.d.ts.map +1 -1
- package/dist/shared-tree/tree.js +4 -3
- package/dist/shared-tree/tree.js.map +1 -1
- package/dist/shared-tree/treeAlpha.d.ts +7 -1
- package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
- package/dist/shared-tree/treeAlpha.js.map +1 -1
- package/dist/shared-tree/treeCheckout.d.ts +7 -2
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +4 -1
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/simple-tree/api/conciseTree.d.ts +1 -1
- package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/conciseTree.js.map +1 -1
- package/dist/simple-tree/api/configuration.d.ts +1 -1
- package/dist/simple-tree/api/configuration.d.ts.map +1 -1
- package/dist/simple-tree/api/configuration.js +5 -5
- package/dist/simple-tree/api/configuration.js.map +1 -1
- package/dist/simple-tree/api/create.d.ts +3 -1
- package/dist/simple-tree/api/create.d.ts.map +1 -1
- package/dist/simple-tree/api/create.js +2 -0
- package/dist/simple-tree/api/create.js.map +1 -1
- package/dist/simple-tree/api/customTree.d.ts +1 -2
- package/dist/simple-tree/api/customTree.d.ts.map +1 -1
- package/dist/simple-tree/api/customTree.js.map +1 -1
- package/dist/simple-tree/api/getJsonSchema.d.ts +1 -1
- package/dist/simple-tree/api/getJsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/getJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/getSimpleSchema.d.ts +1 -1
- package/dist/simple-tree/api/getSimpleSchema.js.map +1 -1
- package/dist/simple-tree/api/identifierIndex.d.ts +1 -1
- package/dist/simple-tree/api/identifierIndex.js +2 -2
- package/dist/simple-tree/api/identifierIndex.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +1 -1
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/schemaCompatibilityTester.d.ts +4 -19
- package/dist/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaCompatibilityTester.js +31 -82
- package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.d.ts +14 -2
- package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaCreationUtilities.js +41 -4
- package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/dist/simple-tree/api/schemaFactory.d.ts +36 -3
- package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactory.js +18 -18
- package/dist/simple-tree/api/schemaFactory.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +16 -16
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryRecursive.d.ts +2 -2
- package/dist/simple-tree/api/schemaFactoryRecursive.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryRecursive.js +2 -2
- package/dist/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
- package/dist/simple-tree/api/schemaFromSimple.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFromSimple.js +4 -4
- package/dist/simple-tree/api/schemaFromSimple.js.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +2 -2
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/simpleTreeIndex.d.ts +2 -2
- package/dist/simple-tree/api/simpleTreeIndex.d.ts.map +1 -1
- package/dist/simple-tree/api/simpleTreeIndex.js +1 -1
- package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
- package/dist/simple-tree/api/storedSchema.d.ts +1 -1
- package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/storedSchema.js +2 -2
- package/dist/simple-tree/api/storedSchema.js.map +1 -1
- package/dist/simple-tree/api/tree.d.ts +2 -1
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/treeBeta.d.ts +4 -1
- package/dist/simple-tree/api/treeBeta.d.ts.map +1 -1
- package/dist/simple-tree/api/treeBeta.js.map +1 -1
- package/dist/simple-tree/api/treeNodeApi.d.ts +1 -2
- package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
- package/dist/simple-tree/api/treeNodeApi.js +3 -3
- package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
- package/dist/simple-tree/api/typesUnsafe.d.ts +2 -3
- package/dist/simple-tree/api/typesUnsafe.d.ts.map +1 -1
- package/dist/simple-tree/api/typesUnsafe.js.map +1 -1
- package/dist/simple-tree/api/verboseTree.d.ts +2 -1
- package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/verboseTree.js.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +2 -2
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/dist/simple-tree/core/allowedTypes.d.ts +316 -0
- package/dist/simple-tree/core/allowedTypes.d.ts.map +1 -0
- package/dist/simple-tree/core/allowedTypes.js +173 -0
- package/dist/simple-tree/core/allowedTypes.js.map +1 -0
- package/dist/simple-tree/core/context.d.ts +3 -9
- package/dist/simple-tree/core/context.d.ts.map +1 -1
- package/dist/simple-tree/core/context.js +3 -11
- package/dist/simple-tree/core/context.js.map +1 -1
- package/dist/simple-tree/core/flexList.d.ts.map +1 -0
- package/dist/simple-tree/core/flexList.js.map +1 -0
- package/dist/simple-tree/core/getOrCreateNode.d.ts +1 -1
- package/dist/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
- package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
- package/dist/simple-tree/core/index.d.ts +9 -3
- package/dist/simple-tree/core/index.d.ts.map +1 -1
- package/dist/simple-tree/core/index.js +19 -3
- package/dist/simple-tree/core/index.js.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.d.ts +8 -1
- package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js +24 -20
- package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.d.ts +182 -39
- package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeSchema.js +47 -17
- package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/{lib/simple-tree → dist/simple-tree/core}/treeNodeValid.d.ts +18 -4
- package/dist/simple-tree/core/treeNodeValid.d.ts.map +1 -0
- package/dist/simple-tree/{treeNodeValid.js → core/treeNodeValid.js} +41 -11
- package/dist/simple-tree/core/treeNodeValid.js.map +1 -0
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/dist/simple-tree/core/walkSchema.d.ts +2 -1
- package/dist/simple-tree/core/walkSchema.d.ts.map +1 -1
- package/dist/simple-tree/core/walkSchema.js +6 -2
- package/dist/simple-tree/core/walkSchema.js.map +1 -1
- package/dist/simple-tree/createContext.d.ts +6 -2
- package/dist/simple-tree/createContext.d.ts.map +1 -1
- package/dist/simple-tree/createContext.js +15 -3
- package/dist/simple-tree/createContext.js.map +1 -1
- package/dist/{feature-libraries/modular-schema → simple-tree}/discrepancies.d.ts +22 -29
- package/dist/simple-tree/discrepancies.d.ts.map +1 -0
- package/dist/simple-tree/discrepancies.js +382 -0
- package/dist/simple-tree/discrepancies.js.map +1 -0
- package/dist/simple-tree/fieldSchema.d.ts +423 -0
- package/dist/simple-tree/fieldSchema.d.ts.map +1 -0
- package/dist/simple-tree/{schemaTypes.js → fieldSchema.js} +5 -195
- package/dist/simple-tree/fieldSchema.js.map +1 -0
- package/dist/simple-tree/index.d.ts +7 -6
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +17 -11
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/leafNodeSchema.d.ts +14 -5
- package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/dist/simple-tree/leafNodeSchema.js +117 -2
- package/dist/simple-tree/leafNodeSchema.js.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +3 -4
- package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNode.js +97 -26
- package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNodeTypes.d.ts +2 -2
- package/dist/simple-tree/node-kinds/array/arrayNodeTypes.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/array/arrayNodeTypes.js.map +1 -1
- package/dist/simple-tree/node-kinds/common.d.ts +16 -0
- package/dist/simple-tree/node-kinds/common.d.ts.map +1 -0
- package/dist/simple-tree/node-kinds/common.js +42 -0
- package/dist/simple-tree/node-kinds/common.js.map +1 -0
- 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.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNode.d.ts +2 -3
- package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNode.js +64 -26
- package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNodeTypes.d.ts +2 -2
- package/dist/simple-tree/node-kinds/map/mapNodeTypes.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/map/mapNodeTypes.js.map +1 -1
- package/dist/simple-tree/node-kinds/object/index.d.ts +2 -2
- package/dist/simple-tree/node-kinds/object/index.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/object/index.js.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts +19 -5
- package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNode.js +131 -27
- package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNodeTypes.d.ts +11 -4
- package/dist/simple-tree/node-kinds/object/objectNodeTypes.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/object/objectNodeTypes.js.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNode.d.ts +2 -2
- package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNode.js +41 -13
- package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts +2 -2
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts.map +1 -1
- package/dist/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
- package/dist/simple-tree/prepareForInsertion.d.ts +2 -2
- package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
- package/dist/simple-tree/prepareForInsertion.js +3 -3
- package/dist/simple-tree/prepareForInsertion.js.map +1 -1
- package/dist/simple-tree/simpleSchema.d.ts +2 -2
- package/dist/simple-tree/simpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/simpleSchema.js.map +1 -1
- package/dist/simple-tree/toStoredSchema.d.ts +1 -1
- package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/dist/simple-tree/toStoredSchema.js +6 -7
- package/dist/simple-tree/toStoredSchema.js.map +1 -1
- package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts +5 -11
- package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
- package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js +25 -395
- package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
- package/dist/simple-tree/unsafeUnknownSchema.d.ts +52 -0
- package/dist/simple-tree/unsafeUnknownSchema.d.ts.map +1 -0
- package/dist/simple-tree/unsafeUnknownSchema.js +13 -0
- package/dist/simple-tree/unsafeUnknownSchema.js.map +1 -0
- package/dist/simple-tree/walkFieldSchema.d.ts +1 -1
- package/dist/simple-tree/walkFieldSchema.js +2 -2
- package/dist/simple-tree/walkFieldSchema.js.map +1 -1
- package/dist/tableSchema.d.ts +12 -12
- package/dist/treeFactory.d.ts +0 -1
- package/dist/treeFactory.d.ts.map +1 -1
- package/dist/treeFactory.js +0 -1
- package/dist/treeFactory.js.map +1 -1
- package/lib/core/schema-stored/schema.d.ts +14 -1
- package/lib/core/schema-stored/schema.d.ts.map +1 -1
- package/lib/core/schema-stored/schema.js.map +1 -1
- package/lib/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
- package/lib/feature-libraries/default-schema/schemaChecker.js +3 -0
- package/lib/feature-libraries/default-schema/schemaChecker.js.map +1 -1
- package/lib/feature-libraries/flex-tree/context.d.ts +7 -2
- package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/context.js +4 -4
- package/lib/feature-libraries/flex-tree/context.js.map +1 -1
- package/lib/feature-libraries/flex-tree/index.d.ts +1 -0
- package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/index.js +1 -0
- package/lib/feature-libraries/flex-tree/index.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.js +6 -6
- package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts +3 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.js +3 -1
- package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
- package/lib/feature-libraries/forest-summary/forestSummarizer.js +1 -2
- package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +2 -2
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +2 -2
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/comparison.js +0 -3
- package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
- package/lib/feature-libraries/modular-schema/index.d.ts +0 -1
- package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
- package/lib/feature-libraries/modular-schema/index.js +0 -1
- package/lib/feature-libraries/modular-schema/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/index.d.ts +0 -1
- package/lib/shared-tree/index.d.ts.map +1 -1
- package/lib/shared-tree/index.js +0 -1
- package/lib/shared-tree/index.js.map +1 -1
- package/lib/shared-tree/schematizeTree.d.ts +1 -1
- package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
- package/lib/shared-tree/schematizeTree.js +5 -8
- package/lib/shared-tree/schematizeTree.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.d.ts +11 -13
- package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +61 -83
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTreeChangeTypes.d.ts +1 -1
- package/lib/shared-tree/sharedTreeChangeTypes.js.map +1 -1
- package/lib/shared-tree/tree.d.ts.map +1 -1
- package/lib/shared-tree/tree.js +4 -3
- package/lib/shared-tree/tree.js.map +1 -1
- package/lib/shared-tree/treeAlpha.d.ts +7 -1
- package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
- package/lib/shared-tree/treeAlpha.js.map +1 -1
- package/lib/shared-tree/treeCheckout.d.ts +7 -2
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +5 -2
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/simple-tree/api/conciseTree.d.ts +1 -1
- package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/conciseTree.js.map +1 -1
- package/lib/simple-tree/api/configuration.d.ts +1 -1
- package/lib/simple-tree/api/configuration.d.ts.map +1 -1
- package/lib/simple-tree/api/configuration.js +2 -2
- package/lib/simple-tree/api/configuration.js.map +1 -1
- package/lib/simple-tree/api/create.d.ts +3 -1
- package/lib/simple-tree/api/create.d.ts.map +1 -1
- package/lib/simple-tree/api/create.js +2 -0
- package/lib/simple-tree/api/create.js.map +1 -1
- package/lib/simple-tree/api/customTree.d.ts +1 -2
- package/lib/simple-tree/api/customTree.d.ts.map +1 -1
- package/lib/simple-tree/api/customTree.js.map +1 -1
- package/lib/simple-tree/api/getJsonSchema.d.ts +1 -1
- package/lib/simple-tree/api/getJsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/getJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/getSimpleSchema.d.ts +1 -1
- package/lib/simple-tree/api/getSimpleSchema.js.map +1 -1
- package/lib/simple-tree/api/identifierIndex.d.ts +1 -1
- package/lib/simple-tree/api/identifierIndex.js +1 -1
- package/lib/simple-tree/api/identifierIndex.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +1 -1
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/schemaCompatibilityTester.d.ts +4 -19
- package/lib/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaCompatibilityTester.js +25 -76
- package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.d.ts +14 -2
- package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaCreationUtilities.js +40 -4
- package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
- package/lib/simple-tree/api/schemaFactory.d.ts +36 -3
- package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactory.js +2 -2
- package/lib/simple-tree/api/schemaFactory.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +16 -16
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryRecursive.d.ts +2 -2
- package/lib/simple-tree/api/schemaFactoryRecursive.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryRecursive.js +1 -1
- package/lib/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
- package/lib/simple-tree/api/schemaFromSimple.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFromSimple.js +1 -1
- package/lib/simple-tree/api/schemaFromSimple.js.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/simpleTreeIndex.d.ts +2 -2
- package/lib/simple-tree/api/simpleTreeIndex.d.ts.map +1 -1
- package/lib/simple-tree/api/simpleTreeIndex.js +2 -2
- package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -1
- package/lib/simple-tree/api/storedSchema.d.ts +1 -1
- package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/storedSchema.js +2 -2
- package/lib/simple-tree/api/storedSchema.js.map +1 -1
- package/lib/simple-tree/api/tree.d.ts +2 -1
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/treeBeta.d.ts +4 -1
- package/lib/simple-tree/api/treeBeta.d.ts.map +1 -1
- package/lib/simple-tree/api/treeBeta.js.map +1 -1
- package/lib/simple-tree/api/treeNodeApi.d.ts +1 -2
- package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
- package/lib/simple-tree/api/treeNodeApi.js +2 -2
- package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
- package/lib/simple-tree/api/typesUnsafe.d.ts +2 -3
- package/lib/simple-tree/api/typesUnsafe.d.ts.map +1 -1
- package/lib/simple-tree/api/typesUnsafe.js.map +1 -1
- package/lib/simple-tree/api/verboseTree.d.ts +2 -1
- package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/verboseTree.js.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/lib/simple-tree/core/allowedTypes.d.ts +316 -0
- package/lib/simple-tree/core/allowedTypes.d.ts.map +1 -0
- package/lib/simple-tree/core/allowedTypes.js +162 -0
- package/lib/simple-tree/core/allowedTypes.js.map +1 -0
- package/lib/simple-tree/core/context.d.ts +3 -9
- package/lib/simple-tree/core/context.d.ts.map +1 -1
- package/lib/simple-tree/core/context.js +0 -8
- package/lib/simple-tree/core/context.js.map +1 -1
- package/lib/simple-tree/core/flexList.d.ts.map +1 -0
- package/lib/simple-tree/core/flexList.js.map +1 -0
- package/lib/simple-tree/core/getOrCreateNode.d.ts +1 -1
- package/lib/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
- package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
- package/lib/simple-tree/core/index.d.ts +9 -3
- package/lib/simple-tree/core/index.d.ts.map +1 -1
- package/lib/simple-tree/core/index.js +6 -3
- package/lib/simple-tree/core/index.js.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.d.ts +8 -1
- package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js +10 -6
- package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.d.ts +182 -39
- package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeSchema.js +44 -14
- package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
- package/{dist/simple-tree → lib/simple-tree/core}/treeNodeValid.d.ts +18 -4
- package/lib/simple-tree/core/treeNodeValid.d.ts.map +1 -0
- package/lib/simple-tree/{treeNodeValid.js → core/treeNodeValid.js} +31 -3
- package/lib/simple-tree/core/treeNodeValid.js.map +1 -0
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/lib/simple-tree/core/walkSchema.d.ts +2 -1
- package/lib/simple-tree/core/walkSchema.d.ts.map +1 -1
- package/lib/simple-tree/core/walkSchema.js +7 -3
- package/lib/simple-tree/core/walkSchema.js.map +1 -1
- package/lib/simple-tree/createContext.d.ts +6 -2
- package/lib/simple-tree/createContext.d.ts.map +1 -1
- package/lib/simple-tree/createContext.js +13 -2
- package/lib/simple-tree/createContext.js.map +1 -1
- package/lib/{feature-libraries/modular-schema → simple-tree}/discrepancies.d.ts +22 -29
- package/lib/simple-tree/discrepancies.d.ts.map +1 -0
- package/lib/simple-tree/discrepancies.js +376 -0
- package/lib/simple-tree/discrepancies.js.map +1 -0
- package/lib/simple-tree/fieldSchema.d.ts +423 -0
- package/lib/simple-tree/fieldSchema.d.ts.map +1 -0
- package/lib/simple-tree/{schemaTypes.js → fieldSchema.js} +3 -183
- package/lib/simple-tree/fieldSchema.js.map +1 -0
- package/lib/simple-tree/index.d.ts +7 -6
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +4 -3
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/leafNodeSchema.d.ts +14 -5
- package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
- package/lib/simple-tree/leafNodeSchema.js +117 -3
- package/lib/simple-tree/leafNodeSchema.js.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +3 -4
- package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNode.js +86 -15
- package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNodeTypes.d.ts +2 -2
- package/lib/simple-tree/node-kinds/array/arrayNodeTypes.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNodeTypes.js +1 -1
- package/lib/simple-tree/node-kinds/array/arrayNodeTypes.js.map +1 -1
- package/lib/simple-tree/node-kinds/common.d.ts +16 -0
- package/lib/simple-tree/node-kinds/common.d.ts.map +1 -0
- package/lib/simple-tree/node-kinds/common.js +38 -0
- package/lib/simple-tree/node-kinds/common.js.map +1 -0
- 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.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNode.d.ts +2 -3
- package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNode.js +51 -13
- package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNodeTypes.d.ts +2 -2
- package/lib/simple-tree/node-kinds/map/mapNodeTypes.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/map/mapNodeTypes.js +1 -1
- package/lib/simple-tree/node-kinds/map/mapNodeTypes.js.map +1 -1
- package/lib/simple-tree/node-kinds/object/index.d.ts +2 -2
- package/lib/simple-tree/node-kinds/object/index.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/object/index.js.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts +19 -5
- package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNode.js +116 -14
- package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNodeTypes.d.ts +11 -4
- package/lib/simple-tree/node-kinds/object/objectNodeTypes.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/object/objectNodeTypes.js +1 -1
- package/lib/simple-tree/node-kinds/object/objectNodeTypes.js.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNode.d.ts +2 -2
- package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNode.js +40 -12
- package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts +2 -2
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts.map +1 -1
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.js +1 -1
- package/lib/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
- package/lib/simple-tree/prepareForInsertion.d.ts +2 -2
- package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
- package/lib/simple-tree/prepareForInsertion.js +2 -2
- package/lib/simple-tree/prepareForInsertion.js.map +1 -1
- package/lib/simple-tree/simpleSchema.d.ts +2 -2
- package/lib/simple-tree/simpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/simpleSchema.js.map +1 -1
- package/lib/simple-tree/toStoredSchema.d.ts +1 -1
- package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
- package/lib/simple-tree/toStoredSchema.js +2 -3
- package/lib/simple-tree/toStoredSchema.js.map +1 -1
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts +5 -11
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js +10 -381
- package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
- package/lib/simple-tree/unsafeUnknownSchema.d.ts +52 -0
- package/lib/simple-tree/unsafeUnknownSchema.d.ts.map +1 -0
- package/lib/simple-tree/unsafeUnknownSchema.js +10 -0
- package/lib/simple-tree/unsafeUnknownSchema.js.map +1 -0
- package/lib/simple-tree/walkFieldSchema.d.ts +1 -1
- package/lib/simple-tree/walkFieldSchema.js +1 -1
- package/lib/simple-tree/walkFieldSchema.js.map +1 -1
- package/lib/tableSchema.d.ts +12 -12
- package/lib/treeFactory.d.ts +0 -1
- package/lib/treeFactory.d.ts.map +1 -1
- package/lib/treeFactory.js +0 -1
- package/lib/treeFactory.js.map +1 -1
- package/package.json +22 -23
- package/src/core/schema-stored/schema.ts +14 -1
- package/src/feature-libraries/default-schema/schemaChecker.ts +3 -0
- package/src/feature-libraries/flex-tree/context.ts +10 -5
- package/src/feature-libraries/flex-tree/index.ts +2 -0
- package/src/feature-libraries/flex-tree/lazyField.ts +10 -6
- package/src/feature-libraries/flex-tree/lazyNode.ts +6 -1
- package/src/feature-libraries/forest-summary/forestSummarizer.ts +1 -2
- package/src/feature-libraries/index.ts +1 -15
- package/src/feature-libraries/modular-schema/comparison.ts +0 -4
- package/src/feature-libraries/modular-schema/index.ts +0 -17
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/index.ts +0 -2
- package/src/shared-tree/schematizeTree.ts +5 -9
- package/src/shared-tree/schematizingTreeView.ts +75 -113
- package/src/shared-tree/sharedTreeChangeTypes.ts +1 -1
- package/src/shared-tree/tree.ts +4 -3
- package/src/shared-tree/treeAlpha.ts +7 -1
- package/src/shared-tree/treeCheckout.ts +15 -2
- package/src/simple-tree/api/conciseTree.ts +1 -2
- package/src/simple-tree/api/configuration.ts +7 -4
- package/src/simple-tree/api/create.ts +3 -1
- package/src/simple-tree/api/customTree.ts +1 -2
- package/src/simple-tree/api/getJsonSchema.ts +1 -1
- package/src/simple-tree/api/getSimpleSchema.ts +1 -1
- package/src/simple-tree/api/identifierIndex.ts +1 -1
- package/src/simple-tree/api/index.ts +2 -0
- package/src/simple-tree/api/schemaCompatibilityTester.ts +38 -128
- package/src/simple-tree/api/schemaCreationUtilities.ts +50 -5
- package/src/simple-tree/api/schemaFactory.ts +45 -10
- package/src/simple-tree/api/schemaFactoryAlpha.ts +4 -7
- package/src/simple-tree/api/schemaFactoryRecursive.ts +9 -4
- package/src/simple-tree/api/schemaFromSimple.ts +2 -3
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +1 -1
- package/src/simple-tree/api/simpleTreeIndex.ts +8 -3
- package/src/simple-tree/api/storedSchema.ts +1 -2
- package/src/simple-tree/api/tree.ts +2 -2
- package/src/simple-tree/api/treeBeta.ts +4 -1
- package/src/simple-tree/api/treeNodeApi.ts +5 -8
- package/src/simple-tree/api/typesUnsafe.ts +5 -4
- package/src/simple-tree/api/verboseTree.ts +3 -6
- package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +1 -1
- package/src/simple-tree/core/README.md +1 -1
- package/src/simple-tree/core/allowedTypes.ts +496 -0
- package/src/simple-tree/core/context.ts +3 -10
- package/src/simple-tree/core/getOrCreateNode.ts +1 -1
- package/src/simple-tree/core/index.ts +62 -9
- package/src/simple-tree/core/treeNodeKernel.ts +12 -6
- package/src/simple-tree/core/treeNodeSchema.ts +247 -63
- package/src/simple-tree/{treeNodeValid.ts → core/treeNodeValid.ts} +59 -15
- package/src/simple-tree/core/unhydratedFlexTree.ts +1 -1
- package/src/simple-tree/core/walkSchema.ts +9 -5
- package/src/simple-tree/createContext.ts +26 -2
- package/src/simple-tree/discrepancies.ts +648 -0
- package/src/simple-tree/fieldSchema.ts +734 -0
- package/src/simple-tree/index.ts +41 -31
- package/src/simple-tree/leafNodeSchema.ts +137 -5
- package/src/simple-tree/node-kinds/array/arrayNode.ts +141 -30
- package/src/simple-tree/node-kinds/array/arrayNodeTypes.ts +5 -7
- package/src/simple-tree/node-kinds/common.ts +60 -0
- package/src/simple-tree/node-kinds/index.ts +2 -0
- package/src/simple-tree/node-kinds/map/mapNode.ts +91 -33
- package/src/simple-tree/node-kinds/map/mapNodeTypes.ts +5 -7
- package/src/simple-tree/node-kinds/object/index.ts +2 -0
- package/src/simple-tree/node-kinds/object/objectNode.ts +205 -25
- package/src/simple-tree/node-kinds/object/objectNodeTypes.ts +22 -5
- package/src/simple-tree/node-kinds/record/recordNode.ts +68 -26
- package/src/simple-tree/node-kinds/record/recordNodeTypes.ts +6 -8
- package/src/simple-tree/prepareForInsertion.ts +7 -6
- package/src/simple-tree/simpleSchema.ts +2 -2
- package/src/simple-tree/toStoredSchema.ts +2 -3
- package/src/simple-tree/unhydratedFlexTreeFromInsertable.ts +12 -494
- package/src/simple-tree/unsafeUnknownSchema.ts +70 -0
- package/src/simple-tree/walkFieldSchema.ts +1 -1
- package/src/treeFactory.ts +0 -1
- package/dist/feature-libraries/modular-schema/discrepancies.d.ts.map +0 -1
- package/dist/feature-libraries/modular-schema/discrepancies.js +0 -361
- package/dist/feature-libraries/modular-schema/discrepancies.js.map +0 -1
- package/dist/shared-tree/checkoutFlexTreeView.d.ts +0 -58
- package/dist/shared-tree/checkoutFlexTreeView.d.ts.map +0 -1
- package/dist/shared-tree/checkoutFlexTreeView.js +0 -77
- package/dist/shared-tree/checkoutFlexTreeView.js.map +0 -1
- package/dist/simple-tree/flexList.d.ts.map +0 -1
- package/dist/simple-tree/flexList.js.map +0 -1
- package/dist/simple-tree/schemaTypes.d.ts +0 -856
- package/dist/simple-tree/schemaTypes.d.ts.map +0 -1
- package/dist/simple-tree/schemaTypes.js.map +0 -1
- package/dist/simple-tree/treeNodeValid.d.ts.map +0 -1
- package/dist/simple-tree/treeNodeValid.js.map +0 -1
- package/lib/feature-libraries/modular-schema/discrepancies.d.ts.map +0 -1
- package/lib/feature-libraries/modular-schema/discrepancies.js +0 -354
- package/lib/feature-libraries/modular-schema/discrepancies.js.map +0 -1
- package/lib/shared-tree/checkoutFlexTreeView.d.ts +0 -58
- package/lib/shared-tree/checkoutFlexTreeView.d.ts.map +0 -1
- package/lib/shared-tree/checkoutFlexTreeView.js +0 -72
- package/lib/shared-tree/checkoutFlexTreeView.js.map +0 -1
- package/lib/simple-tree/flexList.d.ts.map +0 -1
- package/lib/simple-tree/flexList.js.map +0 -1
- package/lib/simple-tree/schemaTypes.d.ts +0 -856
- package/lib/simple-tree/schemaTypes.d.ts.map +0 -1
- package/lib/simple-tree/schemaTypes.js.map +0 -1
- package/lib/simple-tree/treeNodeValid.d.ts.map +0 -1
- package/lib/simple-tree/treeNodeValid.js.map +0 -1
- package/src/feature-libraries/modular-schema/discrepancies.ts +0 -567
- package/src/shared-tree/checkoutFlexTreeView.ts +0 -100
- package/src/simple-tree/schemaTypes.ts +0 -1420
- /package/dist/simple-tree/{flexList.d.ts → core/flexList.d.ts} +0 -0
- /package/dist/simple-tree/{flexList.js → core/flexList.js} +0 -0
- /package/lib/simple-tree/{flexList.d.ts → core/flexList.d.ts} +0 -0
- /package/lib/simple-tree/{flexList.js → core/flexList.js} +0 -0
- /package/src/simple-tree/{flexList.ts → core/flexList.ts} +0 -0
|
@@ -11,10 +11,11 @@ const index_js_1 = require("../../../util/index.js");
|
|
|
11
11
|
const index_js_2 = require("../../core/index.js");
|
|
12
12
|
const createContext_js_1 = require("../../createContext.js");
|
|
13
13
|
const getTreeNodeForField_js_1 = require("../../getTreeNodeForField.js");
|
|
14
|
-
const
|
|
14
|
+
const fieldSchema_js_1 = require("../../fieldSchema.js");
|
|
15
15
|
const unhydratedFlexTreeFromInsertable_js_1 = require("../../unhydratedFlexTreeFromInsertable.js");
|
|
16
|
-
const
|
|
16
|
+
const index_js_3 = require("../../../feature-libraries/index.js");
|
|
17
17
|
const prepareForInsertion_js_1 = require("../../prepareForInsertion.js");
|
|
18
|
+
const common_js_1 = require("../common.js");
|
|
18
19
|
/**
|
|
19
20
|
* Create a proxy which implements the {@link TreeRecordNode} API.
|
|
20
21
|
* @param proxyTarget - Target object of the proxy.
|
|
@@ -72,7 +73,7 @@ function createRecordNodeProxy(proxyTarget, customizable, schema) {
|
|
|
72
73
|
const innerNode = (0, index_js_2.getOrCreateInnerNode)(receiver);
|
|
73
74
|
const field = innerNode.getBoxed((0, index_js_1.brand)(key));
|
|
74
75
|
const kernel = (0, index_js_2.getKernel)(receiver);
|
|
75
|
-
const mapTree = (0, prepareForInsertion_js_1.prepareForInsertion)(value, (0,
|
|
76
|
+
const mapTree = (0, prepareForInsertion_js_1.prepareForInsertion)(value, (0, fieldSchema_js_1.createFieldSchema)(fieldSchema_js_1.FieldKind.Optional, kernel.schema.info), innerNode.context);
|
|
76
77
|
field.editor.set(mapTree, field.length === 0);
|
|
77
78
|
return true;
|
|
78
79
|
},
|
|
@@ -122,7 +123,7 @@ function createRecordNodeProxy(proxyTarget, customizable, schema) {
|
|
|
122
123
|
});
|
|
123
124
|
return proxy;
|
|
124
125
|
}
|
|
125
|
-
class CustomRecordNodeBase extends
|
|
126
|
+
class CustomRecordNodeBase extends index_js_2.TreeNodeValid {
|
|
126
127
|
constructor(input) {
|
|
127
128
|
super(input ?? {});
|
|
128
129
|
}
|
|
@@ -137,10 +138,9 @@ CustomRecordNodeBase.kind = index_js_2.NodeKind.Record;
|
|
|
137
138
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
138
139
|
function recordSchema(options) {
|
|
139
140
|
const { identifier, info, customizable, implicitlyConstructable, metadata, persistedMetadata, } = options;
|
|
140
|
-
const lazyChildTypes = new internal_1.Lazy(() => (0,
|
|
141
|
-
const lazyAnnotatedTypes = new internal_1.Lazy(() => [(0, schemaTypes_js_1.normalizeAnnotatedAllowedTypes)(info)]);
|
|
141
|
+
const lazyChildTypes = new internal_1.Lazy(() => (0, index_js_2.normalizeAllowedTypes)((0, index_js_2.unannotateImplicitAllowedTypes)(info)));
|
|
142
142
|
const lazyAllowedTypesIdentifiers = new internal_1.Lazy(() => new Set([...lazyChildTypes.value].map((type) => type.identifier)));
|
|
143
|
-
let
|
|
143
|
+
let privateData;
|
|
144
144
|
class Schema extends CustomRecordNodeBase {
|
|
145
145
|
static prepareInstance(instance, flexNode) {
|
|
146
146
|
// Differentiate between the following cases:
|
|
@@ -168,8 +168,6 @@ function recordSchema(options) {
|
|
|
168
168
|
return (0, unhydratedFlexTreeFromInsertable_js_1.unhydratedFlexTreeFromInsertable)(input, this);
|
|
169
169
|
}
|
|
170
170
|
static oneTimeSetup() {
|
|
171
|
-
const schema = this;
|
|
172
|
-
unhydratedContext = (0, createContext_js_1.getUnhydratedContext)(schema);
|
|
173
171
|
// First run, do extra validation.
|
|
174
172
|
// TODO: provide a way for TreeConfiguration to trigger this same validation to ensure it gets run early.
|
|
175
173
|
// Scan for shadowing inherited members which won't work, but stop scan early to allow shadowing built in (which seems to work ok).
|
|
@@ -191,7 +189,11 @@ function recordSchema(options) {
|
|
|
191
189
|
prototype = Reflect.getPrototypeOf(prototype);
|
|
192
190
|
}
|
|
193
191
|
}
|
|
194
|
-
|
|
192
|
+
const schema = this;
|
|
193
|
+
return (0, createContext_js_1.getTreeNodeSchemaInitializedData)(this, {
|
|
194
|
+
shallowCompatibilityTest,
|
|
195
|
+
toFlexContent: (data) => recordToFlexContent(data, schema),
|
|
196
|
+
});
|
|
195
197
|
}
|
|
196
198
|
static get allowedTypesIdentifiers() {
|
|
197
199
|
return lazyAllowedTypesIdentifiers.value;
|
|
@@ -199,9 +201,6 @@ function recordSchema(options) {
|
|
|
199
201
|
static get childTypes() {
|
|
200
202
|
return lazyChildTypes.value;
|
|
201
203
|
}
|
|
202
|
-
static get childAnnotatedAllowedTypes() {
|
|
203
|
-
return lazyAnnotatedTypes.value;
|
|
204
|
-
}
|
|
205
204
|
// eslint-disable-next-line import/no-deprecated
|
|
206
205
|
get [index_js_2.typeNameSymbol]() {
|
|
207
206
|
return identifier;
|
|
@@ -215,6 +214,9 @@ function recordSchema(options) {
|
|
|
215
214
|
get [Symbol.toStringTag]() {
|
|
216
215
|
return identifier;
|
|
217
216
|
}
|
|
217
|
+
static get [index_js_2.privateDataSymbol]() {
|
|
218
|
+
return (privateData ??= (0, index_js_2.createTreeNodeSchemaPrivateData)(this, [info]));
|
|
219
|
+
}
|
|
218
220
|
}
|
|
219
221
|
Schema.constructorCached = undefined;
|
|
220
222
|
Schema.identifier = identifier;
|
|
@@ -231,4 +233,30 @@ function* recordIterator(record) {
|
|
|
231
233
|
yield [key, value];
|
|
232
234
|
}
|
|
233
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* {@link TreeNodeSchemaInitializedData.shallowCompatibilityTest} for Record nodes.
|
|
238
|
+
*/
|
|
239
|
+
function shallowCompatibilityTest(data) {
|
|
240
|
+
if ((0, index_js_3.isTreeValue)(data)) {
|
|
241
|
+
return index_js_2.CompatibilityLevel.None;
|
|
242
|
+
}
|
|
243
|
+
if (Symbol.iterator in data) {
|
|
244
|
+
return index_js_2.CompatibilityLevel.None;
|
|
245
|
+
}
|
|
246
|
+
return index_js_2.CompatibilityLevel.Normal;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* {@link TreeNodeSchemaInitializedData.toFlexContent} for Record nodes.
|
|
250
|
+
*
|
|
251
|
+
* Transforms data under a Record schema.
|
|
252
|
+
* @param data - The tree data to be transformed. Must be a Record-like object.
|
|
253
|
+
* @param schema - The schema to comply with.
|
|
254
|
+
*/
|
|
255
|
+
function recordToFlexContent(data, schema) {
|
|
256
|
+
if (!(typeof data === "object" && data !== null)) {
|
|
257
|
+
throw new internal_2.UsageError(`Input data is incompatible with Record schema: ${data}`);
|
|
258
|
+
}
|
|
259
|
+
const fieldsIterator = Object.entries(data);
|
|
260
|
+
return (0, common_js_1.recordLikeDataToFlexContent)(fieldsIterator, schema);
|
|
261
|
+
}
|
|
234
262
|
//# sourceMappingURL=recordNode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNode.js","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/record/recordNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAC3D,uEAAsE;AAEtE,qDAAkF;AAElF,kDAY6B;AAC7B,6DAA8D;AAC9D,yEAAsE;AACtE,yDAW8B;AAC9B,mGAGmD;AACnD,6DAA6E;AAS7E,yEAAmE;AAEnE;;;;;GAKG;AACH,SAAS,qBAAqB,CAC7B,WAAmB,EACnB,YAAqB,EACrB,MAAwB;IAExB,MAAM,KAAK,GAAmB,IAAI,KAAK,CAAiB,WAA6B,EAAE;QACtF,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAW,EAAE;YACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAC7B,QAAQ,GAAG,EAAE,CA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,CAAC;YAC5B,OAAO,MAAM,CAAC,iBAAiB,EAAE,WAAgC,CAAC;QACnE,CAAC;QAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;YAGvB,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QACD,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC;YAC9B,OAAO,UAAU,CAAC;QACnB,CAAC;;IA/ByB,wBAAiB,GAAgC,SAAS,CAAC;IAE9D,iBAAU,GAAG,UAAU,CAAC;IACxB,WAAI,GAAG,IAAI,CAAC;IACZ,8BAAuB,GAC7C,uBAAuB,CAAC;IAOF,eAAQ,GAAwC,QAAQ,IAAI,EAAE,CAAC;IAC/D,wBAAiB,GACvC,iBAAiB,CAAC;IAiCpB,MAAM,MAAM,GAAW,MAAM,CAAC;IAC9B,OAAO,MAAM,CAAC;AACf,CAAC;AAvKD,oCAuKC;AAED,QAAQ,CAAC,CAAC,cAAc,CACvB,MAAqC;IAErC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpB,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Lazy } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { type JsonCompatibleReadOnlyObject, brand } from \"../../../util/index.js\";\n\nimport {\n\ttype TreeNodeSchema,\n\tNodeKind,\n\t// eslint-disable-next-line import/no-deprecated\n\ttypeNameSymbol,\n\ttypeSchemaSymbol,\n\ttype Context,\n\ttype UnhydratedFlexTreeNode,\n\tgetOrCreateInnerNode,\n\tgetKernel,\n\ttype InternalTreeNode,\n\ttype NormalizedAnnotatedAllowedTypes,\n} from \"../../core/index.js\";\nimport { getUnhydratedContext } from \"../../createContext.js\";\nimport { tryGetTreeNodeForField } from \"../../getTreeNodeForField.js\";\nimport {\n\ttype NodeSchemaMetadata,\n\ttype TreeNodeFromImplicitAllowedTypes,\n\ttype ImplicitAllowedTypes,\n\tnormalizeAllowedTypes,\n\tunannotateImplicitAllowedTypes,\n\ttype ImplicitAnnotatedAllowedTypes,\n\ttype UnannotateImplicitAllowedTypes,\n\tcreateFieldSchema,\n\tFieldKind,\n\tnormalizeAnnotatedAllowedTypes,\n} from \"../../schemaTypes.js\";\nimport {\n\tunhydratedFlexTreeFromInsertable,\n\ttype InsertableContent,\n} from \"../../unhydratedFlexTreeFromInsertable.js\";\nimport { TreeNodeValid, type MostDerivedData } from \"../../treeNodeValid.js\";\nimport type {\n\tRecordNodeCustomizableSchema,\n\tRecordNodeInsertableData,\n\tRecordNodePojoEmulationSchema,\n\tRecordNodeSchema,\n\tTreeRecordNode,\n} from \"./recordNodeTypes.js\";\nimport type { FlexTreeNode, FlexTreeOptionalField } from \"../../../feature-libraries/index.js\";\nimport { prepareForInsertion } from \"../../prepareForInsertion.js\";\n\n/**\n * Create a proxy which implements the {@link TreeRecordNode} API.\n * @param proxyTarget - Target object of the proxy.\n * @param customizable - See {@link RecordNodeSchemaOptions.customizable}.\n * @param schema - The schema of the record node.\n */\nfunction createRecordNodeProxy(\n\tproxyTarget: object,\n\tcustomizable: boolean,\n\tschema: RecordNodeSchema,\n): TreeRecordNode {\n\tconst proxy: TreeRecordNode = new Proxy<TreeRecordNode>(proxyTarget as TreeRecordNode, {\n\t\tget: (target, key, receiver): unknown => {\n\t\t\tif (typeof key === \"symbol\") {\n\t\t\t\tswitch (key) {\n\t\t\t\t\t// POJO mode records don't have TreeNode's build in members on their targets, so special case them:\n\t\t\t\t\tcase typeSchemaSymbol: {\n\t\t\t\t\t\treturn schema;\n\t\t\t\t\t}\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tcase typeNameSymbol: {\n\t\t\t\t\t\treturn schema.identifier;\n\t\t\t\t\t}\n\t\t\t\t\tcase Symbol.iterator: {\n\t\t\t\t\t\treturn () => recordIterator(proxy);\n\t\t\t\t\t}\n\t\t\t\t\tcase Symbol.toPrimitive: {\n\t\t\t\t\t\t// Handle string interpolation and coercion to string\n\t\t\t\t\t\treturn () => Object.prototype.toString.call(proxy);\n\t\t\t\t\t}\n\t\t\t\t\tcase Symbol.toStringTag: {\n\t\t\t\t\t\t// In order to satisfy deep equality checks in POJO (non-customizable) mode,\n\t\t\t\t\t\t// we cannot override the behavior of this.\n\t\t\t\t\t\tif (customizable) {\n\t\t\t\t\t\t\t// Generates nicer toString behavior for customizable records.\n\t\t\t\t\t\t\t// E.g. `[object My.Record]` instead of `[object Object]`.\n\t\t\t\t\t\t\treturn schema.identifier;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\t// No-op\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (typeof key === \"string\") {\n\t\t\t\tconst innerNode = getOrCreateInnerNode(receiver);\n\t\t\t\tconst field = innerNode.tryGetField(brand(key));\n\t\t\t\tif (field !== undefined) {\n\t\t\t\t\treturn tryGetTreeNodeForField(field);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn undefined;\n\t\t},\n\t\tset: (target, key, value: InsertableContent | undefined, receiver): boolean => {\n\t\t\tif (typeof key === \"symbol\") {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst innerNode = getOrCreateInnerNode(receiver);\n\t\t\tconst field = innerNode.getBoxed(brand(key)) as FlexTreeOptionalField;\n\t\t\tconst kernel = getKernel(receiver);\n\n\t\t\tconst mapTree = prepareForInsertion(\n\t\t\t\tvalue,\n\t\t\t\tcreateFieldSchema(FieldKind.Optional, kernel.schema.info as ImplicitAllowedTypes),\n\t\t\t\tinnerNode.context,\n\t\t\t);\n\n\t\t\tfield.editor.set(mapTree, field.length === 0);\n\t\t\treturn true;\n\t\t},\n\t\thas: (target, key): boolean => {\n\t\t\tif (typeof key === \"symbol\") {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst innerNode = getOrCreateInnerNode(proxy);\n\t\t\tconst childField = innerNode.tryGetField(brand(key));\n\n\t\t\treturn childField !== undefined;\n\t\t},\n\t\townKeys: (target) => {\n\t\t\tconst innerNode = getOrCreateInnerNode(proxy);\n\t\t\treturn [...innerNode.keys()];\n\t\t},\n\t\tgetOwnPropertyDescriptor: (target, key) => {\n\t\t\tif (typeof key === \"symbol\") {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst innerNode = getOrCreateInnerNode(proxy);\n\t\t\tconst field = innerNode.tryGetField(brand(key));\n\n\t\t\tif (field === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tvalue: tryGetTreeNodeForField(field),\n\t\t\t\twritable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true, // Must be 'configurable' if property is absent from proxy target.\n\t\t\t};\n\t\t},\n\t\tdefineProperty(target, key, attributes) {\n\t\t\tthrow new UsageError(\"Shadowing properties of record nodes is not permitted.\");\n\t\t},\n\t\tdeleteProperty(target, key) {\n\t\t\tif (typeof key === \"symbol\") {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst innerNode = getOrCreateInnerNode(proxy);\n\t\t\tconst field = innerNode.tryGetField(brand(key)) as FlexTreeOptionalField | undefined;\n\t\t\tif (field === undefined) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfield.editor.set(undefined, field.length === 0);\n\t\t\treturn true;\n\t\t},\n\t});\n\treturn proxy;\n}\n\nabstract class CustomRecordNodeBase<\n\tconst TAllowedTypes extends ImplicitAllowedTypes,\n> extends TreeNodeValid<RecordNodeInsertableData<TAllowedTypes>> {\n\tpublic static readonly kind = NodeKind.Record;\n\n\tpublic constructor(\n\t\tinput?: InternalTreeNode | RecordNodeInsertableData<TAllowedTypes> | undefined,\n\t) {\n\t\tsuper(input ?? {});\n\t}\n}\n\n/**\n * {@link recordSchema} options.\n * @input\n */\nexport interface RecordSchemaOptions<\n\tTName extends string,\n\tTAllowedTypes extends ImplicitAnnotatedAllowedTypes,\n\tTImplicitlyConstructable extends boolean,\n\tTCustomMetadata = unknown,\n> {\n\t/**\n\t * Unique identifier for this schema within this factory's scope.\n\t */\n\treadonly identifier: TName;\n\n\treadonly customizable: boolean;\n\n\t/**\n\t * The kinds of nodes that are allowed as children of this record.\n\t */\n\treadonly info: TAllowedTypes;\n\n\treadonly implicitlyConstructable: TImplicitlyConstructable;\n\n\t/**\n\t * Optional ephemeral metadata for the object node schema.\n\t */\n\treadonly metadata?: NodeSchemaMetadata<TCustomMetadata>;\n\n\t/**\n\t * Optional persisted metadata for the object node schema.\n\t */\n\treadonly persistedMetadata?: JsonCompatibleReadOnlyObject | undefined;\n}\n\n/**\n * Define a {@link TreeNodeSchema} for a {@link TreeRecordNode}.\n *\n * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.\n * @param persistedMetadata -\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function recordSchema<\n\tTName extends string,\n\tconst TAllowedTypes extends ImplicitAnnotatedAllowedTypes,\n\tconst TImplicitlyConstructable extends boolean,\n\tconst TCustomMetadata = unknown,\n>(\n\toptions: RecordSchemaOptions<\n\t\tTName,\n\t\tTAllowedTypes,\n\t\tTImplicitlyConstructable,\n\t\tTCustomMetadata\n\t>,\n) {\n\ttype TUnannotatedAllowedTypes = UnannotateImplicitAllowedTypes<TAllowedTypes>;\n\n\tconst {\n\t\tidentifier,\n\t\tinfo,\n\t\tcustomizable,\n\t\timplicitlyConstructable,\n\t\tmetadata,\n\t\tpersistedMetadata,\n\t} = options;\n\n\tconst lazyChildTypes = new Lazy(() =>\n\t\tnormalizeAllowedTypes(unannotateImplicitAllowedTypes(info)),\n\t);\n\tconst lazyAnnotatedTypes = new Lazy(() => [normalizeAnnotatedAllowedTypes(info)]);\n\tconst lazyAllowedTypesIdentifiers = new Lazy(\n\t\t() => new Set([...lazyChildTypes.value].map((type) => type.identifier)),\n\t);\n\n\tlet unhydratedContext: Context;\n\n\tclass Schema\n\t\textends CustomRecordNodeBase<TUnannotatedAllowedTypes>\n\t\timplements TreeRecordNode<TUnannotatedAllowedTypes>\n\t{\n\t\t/**\n\t\t * Record-like index signature for the node.\n\t\t */\n\t\t[key: string]: TreeNodeFromImplicitAllowedTypes<TUnannotatedAllowedTypes>;\n\n\t\tpublic static override prepareInstance<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tflexNode: FlexTreeNode,\n\t\t): TreeNodeValid<T2> {\n\t\t\t// Differentiate between the following cases:\n\t\t\t//\n\t\t\t// Case 1: Direct construction (POJO emulation)\n\t\t\t//\n\t\t\t// const Foo = schemaFactory.record(\"Foo\", schemaFactory.number);\n\t\t\t//\n\t\t\t// assert.deepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t//\t\t \"Prototype chain equivalent to POJO.\");\n\t\t\t//\n\t\t\t// Case 2: Subclass construction (Customizable Record)\n\t\t\t//\n\t\t\t// \t class Foo extends schemaFactory.record(\"Foo\", schemaFactory.number) {}\n\t\t\t//\n\t\t\t// \t assert.notDeepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t// \t \"Subclass prototype chain differs from POJO.\");\n\t\t\t//\n\t\t\t// In Case 1 (POJO emulation), the prototype chain match '{}' (proxyTarget = undefined)\n\t\t\t// In Case 2 (Customizable Object), the prototype chain include the user's subclass (proxyTarget = this)\n\t\t\tconst proxyTarget = customizable ? instance : {};\n\t\t\treturn createRecordNodeProxy(\n\t\t\t\tproxyTarget,\n\t\t\t\tcustomizable,\n\t\t\t\tthis as unknown as RecordNodeSchema,\n\t\t\t) as unknown as Schema;\n\t\t}\n\n\t\tpublic static override buildRawNode<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tinput: T2,\n\t\t): UnhydratedFlexTreeNode {\n\t\t\treturn unhydratedFlexTreeFromInsertable(input as object, this as typeof Schema);\n\t\t}\n\n\t\tprotected static override oneTimeSetup<T2>(this: typeof TreeNodeValid<T2>): Context {\n\t\t\tconst schema = this as unknown as RecordNodeSchema;\n\t\t\tunhydratedContext = getUnhydratedContext(schema);\n\n\t\t\t// First run, do extra validation.\n\t\t\t// TODO: provide a way for TreeConfiguration to trigger this same validation to ensure it gets run early.\n\t\t\t// Scan for shadowing inherited members which won't work, but stop scan early to allow shadowing built in (which seems to work ok).\n\t\t\t{\n\t\t\t\tlet prototype: object = this.prototype;\n\t\t\t\t// There isn't a clear cleaner way to author this loop.\n\t\t\t\twhile (prototype !== Schema.prototype) {\n\t\t\t\t\tfor (const key of Object.getOwnPropertyNames(prototype)) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t// constructor is a special case, since one is built in on the derived type, and shadowing it works fine since we only use it before fields are applied.\n\t\t\t\t\t\t\tkey !== \"constructor\" &&\n\t\t\t\t\t\t\tReflect.getOwnPropertyDescriptor(prototype, key) !== undefined\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t`Schema ${identifier} defines an inherited property \"${key.toString()}\" which could shadow a legal entry. Since child fields are exposed as own properties, shadowing properties of record nodes is not permitted.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Since this stops at CustomRecordNode, it should never see a null prototype, so this case is safe.\n\t\t\t\t\t// Additionally, if the prototype chain is ever messed up such that CustomRecordNode is not in it,\n\t\t\t\t\t// the null that would show up here does at least ensure this code throws instead of hanging.\n\t\t\t\t\tprototype = Reflect.getPrototypeOf(prototype) as object;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn unhydratedContext;\n\t\t}\n\n\t\tpublic static get allowedTypesIdentifiers(): ReadonlySet<string> {\n\t\t\treturn lazyAllowedTypesIdentifiers.value;\n\t\t}\n\n\t\tprotected static override constructorCached: MostDerivedData | undefined = undefined;\n\n\t\tpublic static readonly identifier = identifier;\n\t\tpublic static readonly info = info;\n\t\tpublic static readonly implicitlyConstructable: TImplicitlyConstructable =\n\t\t\timplicitlyConstructable;\n\t\tpublic static get childTypes(): ReadonlySet<TreeNodeSchema> {\n\t\t\treturn lazyChildTypes.value;\n\t\t}\n\t\tpublic static get childAnnotatedAllowedTypes(): readonly NormalizedAnnotatedAllowedTypes[] {\n\t\t\treturn lazyAnnotatedTypes.value;\n\t\t}\n\t\tpublic static readonly metadata: NodeSchemaMetadata<TCustomMetadata> = metadata ?? {};\n\t\tpublic static readonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined =\n\t\t\tpersistedMetadata;\n\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tpublic get [typeNameSymbol](): TName {\n\t\t\treturn identifier;\n\t\t}\n\t\tpublic get [typeSchemaSymbol](): Output {\n\t\t\treturn Schema.constructorCached?.constructor as unknown as Output;\n\t\t}\n\n\t\tpublic [Symbol.iterator](): IterableIterator<\n\t\t\t[string, TreeNodeFromImplicitAllowedTypes<TUnannotatedAllowedTypes>]\n\t\t> {\n\t\t\treturn recordIterator(this);\n\t\t}\n\t\tpublic get [Symbol.toStringTag](): string {\n\t\t\treturn identifier;\n\t\t}\n\t}\n\n\ttype Output = RecordNodeCustomizableSchema<\n\t\tTName,\n\t\tTAllowedTypes,\n\t\tTImplicitlyConstructable,\n\t\tTCustomMetadata\n\t> &\n\t\tRecordNodePojoEmulationSchema<\n\t\t\tTName,\n\t\t\tTAllowedTypes,\n\t\t\tTImplicitlyConstructable,\n\t\t\tTCustomMetadata\n\t\t>;\n\n\tconst output: Output = Schema;\n\treturn output;\n}\n\nfunction* recordIterator<TAllowedTypes extends ImplicitAllowedTypes>(\n\trecord: TreeRecordNode<TAllowedTypes>,\n): IterableIterator<[string, TreeNodeFromImplicitAllowedTypes<TAllowedTypes>]> {\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tyield [key, value];\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recordNode.js","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/record/recordNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAC3D,uEAAsE;AAEtE,qDAAkF;AAElF,kDA0B6B;AAC7B,6DAA0E;AAC1E,yEAAsE;AACtE,yDAAoE;AACpE,mGAImD;AAQnD,kEAI6C;AAC7C,yEAAmE;AACnE,4CAA2D;AAE3D;;;;;GAKG;AACH,SAAS,qBAAqB,CAC7B,WAAmB,EACnB,YAAqB,EACrB,MAAwB;IAExB,MAAM,KAAK,GAAmB,IAAI,KAAK,CAAiB,WAA6B,EAAE;QACtF,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAW,EAAE;YACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAC7B,QAAQ,GAAG,EAAE,CAAC;oBACb,mGAAmG;oBACnG,KAAK,2BAAgB,CAAC,CAAC,CAAC;wBACvB,OAAO,MAAM,CAAC;oBACf,CAAC;oBACD,gDAAgD;oBAChD,KAAK,yBAAc,CAAC,CAAC,CAAC;wBACrB,OAAO,MAAM,CAAC,UAAU,CAAC;oBAC1B,CAAC;oBACD,KAAK,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACtB,OAAO,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;oBACpC,CAAC;oBACD,KAAK,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;wBACzB,qDAAqD;wBACrD,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBACpD,CAAC;oBACD,KAAK,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;wBACzB,4EAA4E;wBAC5E,2CAA2C;wBAC3C,IAAI,YAAY,E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,CAAC,cAAc,CACvB,MAAqC;IAErC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpB,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAS,wBAAwB,CAAC,IAAoB;IACrD,IAAI,IAAA,sBAAW,EAAC,IAAI,CAAC,EAAE,CAAC;QACvB,OAAO,6BAAkB,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,IAAI,MAAM,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;QAC7B,OAAO,6BAAkB,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,OAAO,6BAAkB,CAAC,MAAM,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,SAAS,mBAAmB,CAAC,IAAoB,EAAE,MAAwB;IAC1E,IAAI,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,qBAAU,CAAC,kDAAkD,IAAI,EAAE,CAAC,CAAC;IAChF,CAAC;IAED,MAAM,cAAc,GAAmD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5F,OAAO,IAAA,uCAA2B,EAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Lazy } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { type JsonCompatibleReadOnlyObject, brand } from \"../../../util/index.js\";\n\nimport {\n\ttype TreeNodeSchema,\n\tNodeKind,\n\t// eslint-disable-next-line import/no-deprecated\n\ttypeNameSymbol,\n\ttypeSchemaSymbol,\n\ttype UnhydratedFlexTreeNode,\n\tgetOrCreateInnerNode,\n\tgetKernel,\n\ttype InternalTreeNode,\n\ttype NodeSchemaMetadata,\n\ttype ImplicitAnnotatedAllowedTypes,\n\ttype UnannotateImplicitAllowedTypes,\n\ttype ImplicitAllowedTypes,\n\tnormalizeAllowedTypes,\n\tunannotateImplicitAllowedTypes,\n\ttype TreeNodeFromImplicitAllowedTypes,\n\tTreeNodeValid,\n\ttype MostDerivedData,\n\ttype TreeNodeSchemaInitializedData,\n\ttype TreeNodeSchemaCorePrivate,\n\tprivateDataSymbol,\n\tcreateTreeNodeSchemaPrivateData,\n\ttype FlexContent,\n\tCompatibilityLevel,\n\ttype TreeNodeSchemaPrivateData,\n} from \"../../core/index.js\";\nimport { getTreeNodeSchemaInitializedData } from \"../../createContext.js\";\nimport { tryGetTreeNodeForField } from \"../../getTreeNodeForField.js\";\nimport { createFieldSchema, FieldKind } from \"../../fieldSchema.js\";\nimport {\n\tunhydratedFlexTreeFromInsertable,\n\ttype FactoryContent,\n\ttype InsertableContent,\n} from \"../../unhydratedFlexTreeFromInsertable.js\";\nimport type {\n\tRecordNodeCustomizableSchema,\n\tRecordNodeInsertableData,\n\tRecordNodePojoEmulationSchema,\n\tRecordNodeSchema,\n\tTreeRecordNode,\n} from \"./recordNodeTypes.js\";\nimport {\n\tisTreeValue,\n\ttype FlexTreeNode,\n\ttype FlexTreeOptionalField,\n} from \"../../../feature-libraries/index.js\";\nimport { prepareForInsertion } from \"../../prepareForInsertion.js\";\nimport { recordLikeDataToFlexContent } from \"../common.js\";\n\n/**\n * Create a proxy which implements the {@link TreeRecordNode} API.\n * @param proxyTarget - Target object of the proxy.\n * @param customizable - See {@link RecordNodeSchemaOptions.customizable}.\n * @param schema - The schema of the record node.\n */\nfunction createRecordNodeProxy(\n\tproxyTarget: object,\n\tcustomizable: boolean,\n\tschema: RecordNodeSchema,\n): TreeRecordNode {\n\tconst proxy: TreeRecordNode = new Proxy<TreeRecordNode>(proxyTarget as TreeRecordNode, {\n\t\tget: (target, key, receiver): unknown => {\n\t\t\tif (typeof key === \"symbol\") {\n\t\t\t\tswitch (key) {\n\t\t\t\t\t// POJO mode records don't have TreeNode's build in members on their targets, so special case them:\n\t\t\t\t\tcase typeSchemaSymbol: {\n\t\t\t\t\t\treturn schema;\n\t\t\t\t\t}\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\tcase typeNameSymbol: {\n\t\t\t\t\t\treturn schema.identifier;\n\t\t\t\t\t}\n\t\t\t\t\tcase Symbol.iterator: {\n\t\t\t\t\t\treturn () => recordIterator(proxy);\n\t\t\t\t\t}\n\t\t\t\t\tcase Symbol.toPrimitive: {\n\t\t\t\t\t\t// Handle string interpolation and coercion to string\n\t\t\t\t\t\treturn () => Object.prototype.toString.call(proxy);\n\t\t\t\t\t}\n\t\t\t\t\tcase Symbol.toStringTag: {\n\t\t\t\t\t\t// In order to satisfy deep equality checks in POJO (non-customizable) mode,\n\t\t\t\t\t\t// we cannot override the behavior of this.\n\t\t\t\t\t\tif (customizable) {\n\t\t\t\t\t\t\t// Generates nicer toString behavior for customizable records.\n\t\t\t\t\t\t\t// E.g. `[object My.Record]` instead of `[object Object]`.\n\t\t\t\t\t\t\treturn schema.identifier;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\t// No-op\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (typeof key === \"string\") {\n\t\t\t\tconst innerNode = getOrCreateInnerNode(receiver);\n\t\t\t\tconst field = innerNode.tryGetField(brand(key));\n\t\t\t\tif (field !== undefined) {\n\t\t\t\t\treturn tryGetTreeNodeForField(field);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn undefined;\n\t\t},\n\t\tset: (target, key, value: InsertableContent | undefined, receiver): boolean => {\n\t\t\tif (typeof key === \"symbol\") {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst innerNode = getOrCreateInnerNode(receiver);\n\t\t\tconst field = innerNode.getBoxed(brand(key)) as FlexTreeOptionalField;\n\t\t\tconst kernel = getKernel(receiver);\n\n\t\t\tconst mapTree = prepareForInsertion(\n\t\t\t\tvalue,\n\t\t\t\tcreateFieldSchema(FieldKind.Optional, kernel.schema.info as ImplicitAllowedTypes),\n\t\t\t\tinnerNode.context,\n\t\t\t);\n\n\t\t\tfield.editor.set(mapTree, field.length === 0);\n\t\t\treturn true;\n\t\t},\n\t\thas: (target, key): boolean => {\n\t\t\tif (typeof key === \"symbol\") {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst innerNode = getOrCreateInnerNode(proxy);\n\t\t\tconst childField = innerNode.tryGetField(brand(key));\n\n\t\t\treturn childField !== undefined;\n\t\t},\n\t\townKeys: (target) => {\n\t\t\tconst innerNode = getOrCreateInnerNode(proxy);\n\t\t\treturn [...innerNode.keys()];\n\t\t},\n\t\tgetOwnPropertyDescriptor: (target, key) => {\n\t\t\tif (typeof key === \"symbol\") {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst innerNode = getOrCreateInnerNode(proxy);\n\t\t\tconst field = innerNode.tryGetField(brand(key));\n\n\t\t\tif (field === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tvalue: tryGetTreeNodeForField(field),\n\t\t\t\twritable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true, // Must be 'configurable' if property is absent from proxy target.\n\t\t\t};\n\t\t},\n\t\tdefineProperty(target, key, attributes) {\n\t\t\tthrow new UsageError(\"Shadowing properties of record nodes is not permitted.\");\n\t\t},\n\t\tdeleteProperty(target, key) {\n\t\t\tif (typeof key === \"symbol\") {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst innerNode = getOrCreateInnerNode(proxy);\n\t\t\tconst field = innerNode.tryGetField(brand(key)) as FlexTreeOptionalField | undefined;\n\t\t\tif (field === undefined) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfield.editor.set(undefined, field.length === 0);\n\t\t\treturn true;\n\t\t},\n\t});\n\treturn proxy;\n}\n\nabstract class CustomRecordNodeBase<\n\tconst TAllowedTypes extends ImplicitAllowedTypes,\n> extends TreeNodeValid<RecordNodeInsertableData<TAllowedTypes>> {\n\tpublic static readonly kind = NodeKind.Record;\n\n\tpublic constructor(\n\t\tinput?: InternalTreeNode | RecordNodeInsertableData<TAllowedTypes> | undefined,\n\t) {\n\t\tsuper(input ?? {});\n\t}\n}\n\n/**\n * {@link recordSchema} options.\n * @input\n */\nexport interface RecordSchemaOptions<\n\tTName extends string,\n\tTAllowedTypes extends ImplicitAnnotatedAllowedTypes,\n\tTImplicitlyConstructable extends boolean,\n\tTCustomMetadata = unknown,\n> {\n\t/**\n\t * Unique identifier for this schema within this factory's scope.\n\t */\n\treadonly identifier: TName;\n\n\treadonly customizable: boolean;\n\n\t/**\n\t * The kinds of nodes that are allowed as children of this record.\n\t */\n\treadonly info: TAllowedTypes;\n\n\treadonly implicitlyConstructable: TImplicitlyConstructable;\n\n\t/**\n\t * Optional ephemeral metadata for the object node schema.\n\t */\n\treadonly metadata?: NodeSchemaMetadata<TCustomMetadata>;\n\n\t/**\n\t * Optional persisted metadata for the object node schema.\n\t */\n\treadonly persistedMetadata?: JsonCompatibleReadOnlyObject | undefined;\n}\n\n/**\n * Define a {@link TreeNodeSchema} for a {@link TreeRecordNode}.\n *\n * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.\n * @param persistedMetadata -\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function recordSchema<\n\tTName extends string,\n\tconst TAllowedTypes extends ImplicitAnnotatedAllowedTypes,\n\tconst TImplicitlyConstructable extends boolean,\n\tconst TCustomMetadata = unknown,\n>(\n\toptions: RecordSchemaOptions<\n\t\tTName,\n\t\tTAllowedTypes,\n\t\tTImplicitlyConstructable,\n\t\tTCustomMetadata\n\t>,\n) {\n\ttype TUnannotatedAllowedTypes = UnannotateImplicitAllowedTypes<TAllowedTypes>;\n\n\tconst {\n\t\tidentifier,\n\t\tinfo,\n\t\tcustomizable,\n\t\timplicitlyConstructable,\n\t\tmetadata,\n\t\tpersistedMetadata,\n\t} = options;\n\n\tconst lazyChildTypes = new Lazy(() =>\n\t\tnormalizeAllowedTypes(unannotateImplicitAllowedTypes(info)),\n\t);\n\tconst lazyAllowedTypesIdentifiers = new Lazy(\n\t\t() => new Set([...lazyChildTypes.value].map((type) => type.identifier)),\n\t);\n\n\tlet privateData: TreeNodeSchemaPrivateData | undefined;\n\n\tclass Schema\n\t\textends CustomRecordNodeBase<TUnannotatedAllowedTypes>\n\t\timplements TreeRecordNode<TUnannotatedAllowedTypes>\n\t{\n\t\t/**\n\t\t * Record-like index signature for the node.\n\t\t */\n\t\t[key: string]: TreeNodeFromImplicitAllowedTypes<TUnannotatedAllowedTypes>;\n\n\t\tpublic static override prepareInstance<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tflexNode: FlexTreeNode,\n\t\t): TreeNodeValid<T2> {\n\t\t\t// Differentiate between the following cases:\n\t\t\t//\n\t\t\t// Case 1: Direct construction (POJO emulation)\n\t\t\t//\n\t\t\t// const Foo = schemaFactory.record(\"Foo\", schemaFactory.number);\n\t\t\t//\n\t\t\t// assert.deepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t//\t\t \"Prototype chain equivalent to POJO.\");\n\t\t\t//\n\t\t\t// Case 2: Subclass construction (Customizable Record)\n\t\t\t//\n\t\t\t// \t class Foo extends schemaFactory.record(\"Foo\", schemaFactory.number) {}\n\t\t\t//\n\t\t\t// \t assert.notDeepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t// \t \"Subclass prototype chain differs from POJO.\");\n\t\t\t//\n\t\t\t// In Case 1 (POJO emulation), the prototype chain match '{}' (proxyTarget = undefined)\n\t\t\t// In Case 2 (Customizable Object), the prototype chain include the user's subclass (proxyTarget = this)\n\t\t\tconst proxyTarget = customizable ? instance : {};\n\t\t\treturn createRecordNodeProxy(\n\t\t\t\tproxyTarget,\n\t\t\t\tcustomizable,\n\t\t\t\tthis as unknown as RecordNodeSchema,\n\t\t\t) as unknown as Schema;\n\t\t}\n\n\t\tpublic static override buildRawNode<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tinput: T2,\n\t\t): UnhydratedFlexTreeNode {\n\t\t\treturn unhydratedFlexTreeFromInsertable(input as object, this as typeof Schema);\n\t\t}\n\n\t\tprotected static override oneTimeSetup(): TreeNodeSchemaInitializedData {\n\t\t\t// First run, do extra validation.\n\t\t\t// TODO: provide a way for TreeConfiguration to trigger this same validation to ensure it gets run early.\n\t\t\t// Scan for shadowing inherited members which won't work, but stop scan early to allow shadowing built in (which seems to work ok).\n\t\t\t{\n\t\t\t\tlet prototype: object = this.prototype;\n\t\t\t\t// There isn't a clear cleaner way to author this loop.\n\t\t\t\twhile (prototype !== Schema.prototype) {\n\t\t\t\t\tfor (const key of Object.getOwnPropertyNames(prototype)) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t// constructor is a special case, since one is built in on the derived type, and shadowing it works fine since we only use it before fields are applied.\n\t\t\t\t\t\t\tkey !== \"constructor\" &&\n\t\t\t\t\t\t\tReflect.getOwnPropertyDescriptor(prototype, key) !== undefined\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t`Schema ${identifier} defines an inherited property \"${key.toString()}\" which could shadow a legal entry. Since child fields are exposed as own properties, shadowing properties of record nodes is not permitted.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Since this stops at CustomRecordNode, it should never see a null prototype, so this case is safe.\n\t\t\t\t\t// Additionally, if the prototype chain is ever messed up such that CustomRecordNode is not in it,\n\t\t\t\t\t// the null that would show up here does at least ensure this code throws instead of hanging.\n\t\t\t\t\tprototype = Reflect.getPrototypeOf(prototype) as object;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst schema = this as RecordNodeSchema;\n\t\t\treturn getTreeNodeSchemaInitializedData(this, {\n\t\t\t\tshallowCompatibilityTest,\n\t\t\t\ttoFlexContent: (data: FactoryContent): FlexContent =>\n\t\t\t\t\trecordToFlexContent(data, schema),\n\t\t\t});\n\t\t}\n\n\t\tpublic static get allowedTypesIdentifiers(): ReadonlySet<string> {\n\t\t\treturn lazyAllowedTypesIdentifiers.value;\n\t\t}\n\n\t\tprotected static override constructorCached: MostDerivedData | undefined = undefined;\n\n\t\tpublic static readonly identifier = identifier;\n\t\tpublic static readonly info = info;\n\t\tpublic static readonly implicitlyConstructable: TImplicitlyConstructable =\n\t\t\timplicitlyConstructable;\n\t\tpublic static get childTypes(): ReadonlySet<TreeNodeSchema> {\n\t\t\treturn lazyChildTypes.value;\n\t\t}\n\t\tpublic static readonly metadata: NodeSchemaMetadata<TCustomMetadata> = metadata ?? {};\n\t\tpublic static readonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined =\n\t\t\tpersistedMetadata;\n\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tpublic get [typeNameSymbol](): TName {\n\t\t\treturn identifier;\n\t\t}\n\t\tpublic get [typeSchemaSymbol](): Output {\n\t\t\treturn Schema.constructorCached?.constructor as unknown as Output;\n\t\t}\n\n\t\tpublic [Symbol.iterator](): IterableIterator<\n\t\t\t[string, TreeNodeFromImplicitAllowedTypes<TUnannotatedAllowedTypes>]\n\t\t> {\n\t\t\treturn recordIterator(this);\n\t\t}\n\t\tpublic get [Symbol.toStringTag](): string {\n\t\t\treturn identifier;\n\t\t}\n\n\t\tpublic static get [privateDataSymbol](): TreeNodeSchemaPrivateData {\n\t\t\treturn (privateData ??= createTreeNodeSchemaPrivateData(this, [info]));\n\t\t}\n\t}\n\n\ttype Output = RecordNodeCustomizableSchema<\n\t\tTName,\n\t\tTAllowedTypes,\n\t\tTImplicitlyConstructable,\n\t\tTCustomMetadata\n\t> &\n\t\tRecordNodePojoEmulationSchema<\n\t\t\tTName,\n\t\t\tTAllowedTypes,\n\t\t\tTImplicitlyConstructable,\n\t\t\tTCustomMetadata\n\t\t> &\n\t\tTreeNodeSchemaCorePrivate;\n\n\tconst output: Output = Schema;\n\treturn output;\n}\n\nfunction* recordIterator<TAllowedTypes extends ImplicitAllowedTypes>(\n\trecord: TreeRecordNode<TAllowedTypes>,\n): IterableIterator<[string, TreeNodeFromImplicitAllowedTypes<TAllowedTypes>]> {\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tyield [key, value];\n\t}\n}\n\n/**\n * {@link TreeNodeSchemaInitializedData.shallowCompatibilityTest} for Record nodes.\n */\nfunction shallowCompatibilityTest(data: FactoryContent): CompatibilityLevel {\n\tif (isTreeValue(data)) {\n\t\treturn CompatibilityLevel.None;\n\t}\n\n\tif (Symbol.iterator in data) {\n\t\treturn CompatibilityLevel.None;\n\t}\n\n\treturn CompatibilityLevel.Normal;\n}\n\n/**\n * {@link TreeNodeSchemaInitializedData.toFlexContent} for Record nodes.\n *\n * Transforms data under a Record schema.\n * @param data - The tree data to be transformed. Must be a Record-like object.\n * @param schema - The schema to comply with.\n */\nfunction recordToFlexContent(data: FactoryContent, schema: RecordNodeSchema): FlexContent {\n\tif (!(typeof data === \"object\" && data !== null)) {\n\t\tthrow new UsageError(`Input data is incompatible with Record schema: ${data}`);\n\t}\n\n\tconst fieldsIterator: Iterable<readonly [string, InsertableContent]> = Object.entries(data);\n\treturn recordLikeDataToFlexContent(fieldsIterator, schema);\n}\n"]}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
5
|
+
import { NodeKind } from "../../core/index.js";
|
|
6
|
+
import type { TreeNodeSchemaClass, TreeNodeSchema, TreeNodeSchemaNonClass, WithType, TreeNode, ImplicitAllowedTypes, ImplicitAnnotatedAllowedTypes, InsertableTreeNodeFromImplicitAllowedTypes, TreeNodeFromImplicitAllowedTypes, UnannotateImplicitAllowedTypes } from "../../core/index.js";
|
|
7
7
|
import type { SimpleRecordNodeSchema } from "../../simpleSchema.js";
|
|
8
8
|
import type { RestrictiveStringRecord } from "../../../util/index.js";
|
|
9
9
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodeTypes.d.ts","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/record/recordNodeTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"recordNodeTypes.d.ts","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/record/recordNodeTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,KAAK,EACX,mBAAmB,EACnB,cAAc,EACd,sBAAsB,EACtB,QAAQ,EACR,QAAQ,EACR,oBAAoB,EACpB,6BAA6B,EAC7B,0CAA0C,EAC1C,gCAAgC,EAChC,8BAA8B,EAC9B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEtE;;;;;;;;;GASG;AACH,MAAM,WAAW,cAAc,CAC9B,aAAa,SAAS,oBAAoB,GAAG,oBAAoB,CAChE,SAAQ,QAAQ,EAChB,MAAM,CAAC,MAAM,EAAE,gCAAgC,CAAC,aAAa,CAAC,CAAC;IAChE;;OAEG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CACpC;QAAC,MAAM;QAAE,gCAAgC,CAAC,aAAa,CAAC;KAAC,CACzD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,S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,MAAM,MAAM,gBAAgB,CAC3B,KAAK,SAAS,MAAM,GAAG,MAAM,EAC7B,CAAC,SAAS,6BAA6B,GAAG,6BAA6B,EACvE,uBAAuB,SAAS,OAAO,GAAG,IAAI,EAC9C,eAAe,GAAG,OAAO,IAEvB,4BAA4B,CAAC,KAAK,EAAE,CAAC,EAAE,uBAAuB,EAAE,eAAe,CAAC,GAChF,6BAA6B,CAAC,KAAK,EAAE,CAAC,EAAE,uBAAuB,EAAE,eAAe,CAAC,CAAC;AAErF;;GAEG;AACH,eAAO,MAAM,gBAAgB;IAC5B;;OAEG;2CACyB,cAAc;CAGjC,CAAC;AAEX;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,IAAI,gBAAgB,CAErF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodeTypes.js","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/record/recordNodeTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"recordNodeTypes.js","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/record/recordNodeTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kDAA+C;AA4G/C;;GAEG;AACU,QAAA,gBAAgB,GAAG;IAC/B;;OAEG;IACH,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAqB;QACzC,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACQ,CAAC;AAEX;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAAsB;IACxD,OAAO,MAAM,CAAC,IAAI,KAAK,mBAAQ,CAAC,MAAM,CAAC;AACxC,CAAC;AAFD,gDAEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { NodeKind } from \"../../core/index.js\";\nimport type {\n\tTreeNodeSchemaClass,\n\tTreeNodeSchema,\n\tTreeNodeSchemaNonClass,\n\tWithType,\n\tTreeNode,\n\tImplicitAllowedTypes,\n\tImplicitAnnotatedAllowedTypes,\n\tInsertableTreeNodeFromImplicitAllowedTypes,\n\tTreeNodeFromImplicitAllowedTypes,\n\tUnannotateImplicitAllowedTypes,\n} from \"../../core/index.js\";\n\nimport type { SimpleRecordNodeSchema } from \"../../simpleSchema.js\";\nimport type { RestrictiveStringRecord } from \"../../../util/index.js\";\n\n/**\n * A {@link TreeNode} which models a TypeScript {@link https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type | record}.\n *\n * @remarks\n * Due to {@link https://github.com/microsoft/TypeScript/issues/43826}, we can't enable implicit construction of {@link TreeNode|TreeNodes} for setters.\n * Therefore code assigning to these fields must explicitly construct nodes using the schema's constructor or create method,\n * or using some other method like {@link (TreeAlpha:interface).create}.\n *\n * @alpha\n */\nexport interface TreeRecordNode<\n\tTAllowedTypes extends ImplicitAllowedTypes = ImplicitAllowedTypes,\n> extends TreeNode,\n\t\tRecord<string, TreeNodeFromImplicitAllowedTypes<TAllowedTypes>> {\n\t/**\n\t * Allows the record's entries to be iterated over, including in contexts like `for...of` loops.\n\t */\n\t[Symbol.iterator](): IterableIterator<\n\t\t[string, TreeNodeFromImplicitAllowedTypes<TAllowedTypes>]\n\t>;\n}\n\n/**\n * Content which can be used to construct a Record node, explicitly or implicitly.\n * @system @alpha\n */\nexport type RecordNodeInsertableData<T extends ImplicitAllowedTypes> = RestrictiveStringRecord<\n\tInsertableTreeNodeFromImplicitAllowedTypes<T>\n>;\n\n/**\n * A schema for customizable {@link (TreeMapNode:interface)}s.\n * @system @sealed @alpha\n */\nexport interface RecordNodeCustomizableSchema<\n\tout TName extends string = string,\n\tin out T extends ImplicitAnnotatedAllowedTypes = ImplicitAnnotatedAllowedTypes,\n\tout ImplicitlyConstructable extends boolean = true,\n\tout TCustomMetadata = unknown,\n> extends TreeNodeSchemaClass<\n\t\t\t/* Name */ TName,\n\t\t\t/* Kind */ NodeKind.Record,\n\t\t\t/* TNode */ TreeRecordNode<UnannotateImplicitAllowedTypes<T>> &\n\t\t\t\tWithType<TName, NodeKind.Record, T>,\n\t\t\t/* TInsertable */ RecordNodeInsertableData<UnannotateImplicitAllowedTypes<T>>,\n\t\t\t/* ImplicitlyConstructable */ ImplicitlyConstructable,\n\t\t\t/* Info */ T,\n\t\t\t/* TConstructorExtra */ never,\n\t\t\t/* TCustomMetadata */ TCustomMetadata\n\t\t>,\n\t\tSimpleRecordNodeSchema<TCustomMetadata> {}\n\n/**\n * A schema for POJO emulation mode {@link (TreeMapNode:interface)}s.\n * @system @sealed @alpha\n */\nexport interface RecordNodePojoEmulationSchema<\n\tout TName extends string = string,\n\tin out T extends ImplicitAnnotatedAllowedTypes = ImplicitAnnotatedAllowedTypes,\n\tout ImplicitlyConstructable extends boolean = true,\n\tout TCustomMetadata = unknown,\n> extends TreeNodeSchemaNonClass<\n\t\t\t/* Name */ TName,\n\t\t\t/* Kind */ NodeKind.Record,\n\t\t\t/* TNode */ TreeRecordNode<UnannotateImplicitAllowedTypes<T>> &\n\t\t\t\tWithType<TName, NodeKind.Record, T>,\n\t\t\t/* TInsertable */ RecordNodeInsertableData<UnannotateImplicitAllowedTypes<T>>,\n\t\t\t/* ImplicitlyConstructable */ ImplicitlyConstructable,\n\t\t\t/* Info */ T,\n\t\t\t/* TConstructorExtra */ never,\n\t\t\t/* TCustomMetadata */ TCustomMetadata\n\t\t>,\n\t\tSimpleRecordNodeSchema<TCustomMetadata> {}\n\n/**\n * A schema for {@link (TreeRecordNode:interface)}s.\n * @privateRemarks\n * This could have generic arguments added and forwarded.\n * The expected use-cases for this don't need them however, and if they did want an argument it would probably be the allowed types;\n * perhaps if moving to an order independent way to pass generic arguments, adding support for them here would make sense.\n * @alpha\n */\nexport type RecordNodeSchema<\n\tTName extends string = string,\n\tT extends ImplicitAnnotatedAllowedTypes = ImplicitAnnotatedAllowedTypes,\n\tImplicitlyConstructable extends boolean = true,\n\tTCustomMetadata = unknown,\n> =\n\t| RecordNodeCustomizableSchema<TName, T, ImplicitlyConstructable, TCustomMetadata>\n\t| RecordNodePojoEmulationSchema<TName, T, ImplicitlyConstructable, TCustomMetadata>;\n\n/**\n * @alpha\n */\nexport const RecordNodeSchema = {\n\t/**\n\t * `instanceof`-based narrowing support for {@link (RecordNodeSchema:type)} in JavaScript and TypeScript 5.3 or newer.\n\t */\n\t[Symbol.hasInstance](value: TreeNodeSchema): value is RecordNodeSchema {\n\t\treturn isRecordNodeSchema(value);\n\t},\n} as const;\n\n/**\n * Narrows a {@link (TreeNodeSchema:interface)} to an {@link (RecordNodeSchema:interface)}.\n * @privateRemarks\n * If at some point we want to have internal only APIs for RecordNodeSchema (like done for objects),\n * this can include those since its not the public-facing API.\n */\nexport function isRecordNodeSchema(schema: TreeNodeSchema): schema is RecordNodeSchema {\n\treturn schema.kind === NodeKind.Record;\n}\n"]}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { SchemaAndPolicy, IForestSubscription } from "../core/index.js";
|
|
6
6
|
import { type FlexTreeContext, type FlexTreeHydratedContextMinimal, type FlexibleFieldContent, type FlexibleNodeContent } from "../feature-libraries/index.js";
|
|
7
|
-
import { type
|
|
7
|
+
import { type ImplicitFieldSchema } from "./fieldSchema.js";
|
|
8
8
|
import { type InsertableContent } from "./unhydratedFlexTreeFromInsertable.js";
|
|
9
|
-
import { type UnhydratedFlexTreeNode } from "./core/index.js";
|
|
9
|
+
import { type ImplicitAllowedTypes, type UnhydratedFlexTreeNode } from "./core/index.js";
|
|
10
10
|
/**
|
|
11
11
|
* Prepare content from a user for insertion into a tree.
|
|
12
12
|
* @remarks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareForInsertion.d.ts","sourceRoot":"","sources":["../../src/simple-tree/prepareForInsertion.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,eAAe,EACf,mBAAmB,EAMnB,MAAM,kBAAk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AS,SAAS,GAAG,SAAS,GAAG,mBAAmB,CAQzD;AA2DD;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,SAAS,sBAAsB,EAAE,EAC1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,8BAA8B,GACrC,IAAI,CAuBN"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.prepareContentForHydration = exports.prepareForInsertionContextless = exports.prepareArrayContentForInsertion = exports.prepareForInsertion = void 0;
|
|
8
8
|
const index_js_1 = require("../feature-libraries/index.js");
|
|
9
|
-
const
|
|
9
|
+
const fieldSchema_js_1 = require("./fieldSchema.js");
|
|
10
10
|
const unhydratedFlexTreeFromInsertable_js_1 = require("./unhydratedFlexTreeFromInsertable.js");
|
|
11
11
|
const internal_1 = require("@fluidframework/telemetry-utils/internal");
|
|
12
12
|
const index_js_2 = require("../util/index.js");
|
|
@@ -41,7 +41,7 @@ exports.prepareForInsertion = prepareForInsertion;
|
|
|
41
41
|
*/
|
|
42
42
|
function prepareArrayContentForInsertion(data, schema, destinationContext) {
|
|
43
43
|
const mapTrees = data.map((item) => (0, unhydratedFlexTreeFromInsertable_js_1.unhydratedFlexTreeFromInsertable)(item, schema));
|
|
44
|
-
const fieldSchema = (0, toStoredSchema_js_1.convertField)((0,
|
|
44
|
+
const fieldSchema = (0, toStoredSchema_js_1.convertField)((0, fieldSchema_js_1.normalizeFieldSchema)(schema));
|
|
45
45
|
validateAndPrepare((0, index_js_1.getSchemaAndPolicy)(destinationContext), destinationContext.isHydrated() ? destinationContext : undefined, {
|
|
46
46
|
kind: index_js_1.FieldKinds.sequence.identifier,
|
|
47
47
|
types: fieldSchema.types,
|
|
@@ -62,7 +62,7 @@ exports.prepareArrayContentForInsertion = prepareArrayContentForInsertion;
|
|
|
62
62
|
function prepareForInsertionContextless(data, schema, schemaAndPolicy, hydratedData) {
|
|
63
63
|
const mapTree = (0, unhydratedFlexTreeFromInsertable_js_1.unhydratedFlexTreeFromInsertable)(data, schema);
|
|
64
64
|
const contentArray = mapTree === undefined ? [] : [mapTree];
|
|
65
|
-
const fieldSchema = (0, toStoredSchema_js_1.convertField)((0,
|
|
65
|
+
const fieldSchema = (0, toStoredSchema_js_1.convertField)((0, fieldSchema_js_1.normalizeFieldSchema)(schema));
|
|
66
66
|
validateAndPrepare(schemaAndPolicy, hydratedData, fieldSchema, contentArray);
|
|
67
67
|
return mapTree;
|
|
68
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareForInsertion.js","sourceRoot":"","sources":["../../src/simple-tree/prepareForInsertion.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAWH,4DAOuC;AACvC,qDAI0B;AAC1B,+FAG+C;AAC/C,uEAAsE;AACtE,+CAAyC;AACzC,8CAAwF;AACxF,kEAAuE;AACvE,4DAAiF;AACjF,2DAAmD;AAEnD;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAClC,IAAS,EACT,MAA2B,EAC3B,kBAAmC;IAEnC,OAAO,8BAA8B,CACpC,IAAI,EACJ,MAAM,EACN,IAAA,6BAAkB,EAAC,kBAAkB,CAAC,EACtC,kBAAkB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAChE,CAAC;AACH,CAAC;AAXD,kDAWC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,+BAA+B,CAC9C,IAAkC,EAClC,MAA4B,EAC5B,kBAAmC;IAEnC,MAAM,QAAQ,GAA6B,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC5D,IAAA,sEAAgC,EAAC,IAAI,EAAE,MAAM,CAAC,CAC9C,CAAC;IAEF,MAAM,WAAW,GAAG,IAAA,gCAAY,EAAC,IAAA,qCAAoB,EAAC,MAAM,CAAC,CAAC,CAAC;IAE/D,kBAAkB,CACjB,IAAA,6BAAkB,E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CAAC,CAAC;YAC7C,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;gBAC1C,IAAA,oBAAS,EAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC/C,CAAC;YACD,IAAI,EAAE,CAAC,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;gBACjC,GAAG,EAAE,CAAC;YACP,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tSchemaAndPolicy,\n\tIForestSubscription,\n\tUpPath,\n\tNodeIndex,\n\tFieldKey,\n\tDetachedField,\n\tTreeFieldStoredSchema,\n} from \"../core/index.js\";\nimport {\n\ttype FlexTreeContext,\n\tgetSchemaAndPolicy,\n\ttype FlexTreeHydratedContextMinimal,\n\tFieldKinds,\n\ttype FlexibleFieldContent,\n\ttype FlexibleNodeContent,\n} from \"../feature-libraries/index.js\";\nimport {\n\tnormalizeFieldSchema,\n\ttype ImplicitAllowedTypes,\n\ttype ImplicitFieldSchema,\n} from \"./schemaTypes.js\";\nimport {\n\ttype InsertableContent,\n\tunhydratedFlexTreeFromInsertable,\n} from \"./unhydratedFlexTreeFromInsertable.js\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { brand } from \"../util/index.js\";\nimport { getKernel, type TreeNode, type UnhydratedFlexTreeNode } from \"./core/index.js\";\nimport { debugAssert, oob } from \"@fluidframework/core-utils/internal\";\nimport { inSchemaOrThrow, isFieldInSchema } from \"../feature-libraries/index.js\";\nimport { convertField } from \"./toStoredSchema.js\";\n\n/**\n * Prepare content from a user for insertion into a tree.\n * @remarks\n * This validates and converts the input, and if necessary invokes {@link prepareContentForHydration}.\n *\n * The next edit made to `destinationContext`'s forest must be the creation of a detached field containing this content,\n * (Triggering {@link ForestEvents.afterRootFieldCreated}) otherwise hydration will break.\n */\nexport function prepareForInsertion<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tdestinationContext: FlexTreeContext,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\treturn prepareForInsertionContextless(\n\t\tdata,\n\t\tschema,\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t);\n}\n\n/**\n * {@link prepareForInsertion} but batched for array content.\n * @remarks\n * This is for inserting items into an array, not a inserting a {@link TreeArrayNode} (that would use {@link prepareForInsertion}).\n *\n * The next edits made to `destinationContext`'s forest must be the creation of a detached field.\n * One edit for each item in `data`, in order.\n *\n * @privateRemarks\n * This has to be done as a single operation for all items in data\n * (as opposed to mapping {@link prepareForInsertion} over the array)\n * due to how the eventing in prepareContentForHydration works.\n */\nexport function prepareArrayContentForInsertion(\n\tdata: readonly InsertableContent[],\n\tschema: ImplicitAllowedTypes,\n\tdestinationContext: FlexTreeContext,\n): FlexibleFieldContent {\n\tconst mapTrees: UnhydratedFlexTreeNode[] = data.map((item) =>\n\t\tunhydratedFlexTreeFromInsertable(item, schema),\n\t);\n\n\tconst fieldSchema = convertField(normalizeFieldSchema(schema));\n\n\tvalidateAndPrepare(\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t\t{\n\t\t\tkind: FieldKinds.sequence.identifier,\n\t\t\ttypes: fieldSchema.types,\n\t\t\tpersistedMetadata: undefined,\n\t\t},\n\t\tmapTrees,\n\t);\n\n\treturn mapTrees;\n}\n\n/**\n * Split out from {@link prepareForInsertion} as to allow use without a context.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n *\n * @remarks\n * Adding this entry point is a workaround for initialize not currently having a context.\n */\nexport function prepareForInsertionContextless<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\tconst mapTree = unhydratedFlexTreeFromInsertable(data, schema);\n\n\tconst contentArray = mapTree === undefined ? [] : [mapTree];\n\tconst fieldSchema = convertField(normalizeFieldSchema(schema));\n\tvalidateAndPrepare(schemaAndPolicy, hydratedData, fieldSchema, contentArray);\n\n\treturn mapTree;\n}\n\n/**\n * If hydrating, do a final validation against the schema and prepare the content for hydration.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n */\nfunction validateAndPrepare(\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n\tfieldSchema: TreeFieldStoredSchema,\n\tmapTrees: readonly UnhydratedFlexTreeNode[],\n): void {\n\tif (hydratedData !== undefined) {\n\t\t// Run `prepareContentForHydration` before walking the tree in `isFieldInSchema`.\n\t\t// This ensures that when `isFieldInSchema` requests identifiers (or any other contextual defaults),\n\t\t// they were already creating used the more specific context we have access to from `hydratedData`.\n\t\tprepareContentForHydration(mapTrees, hydratedData.checkout.forest, hydratedData);\n\t\tif (schemaAndPolicy.policy.validateSchema === true) {\n\t\t\tconst maybeError = isFieldInSchema(mapTrees, fieldSchema, schemaAndPolicy);\n\t\t\tinSchemaOrThrow(maybeError);\n\t\t}\n\t}\n}\n\n/**\n * An {@link UpPath} that is just index zero in a {@link DetachedField} which can be modified at a later time.\n */\ninterface Root extends UpPath {\n\treadonly parent: undefined;\n\tparentField: DetachedField & FieldKey;\n\treadonly parentIndex: NodeIndex & 0;\n}\n\n/**\n * The path from the included node to the root of the content tree it was inserted as part of.\n */\ninterface RelativeNodePath {\n\treadonly path: UpPath;\n\treadonly node: TreeNode;\n}\n\n/**\n * {@link RelativeNodePath}s for every {@link TreeNode} in the content tree inserted as an atomic operation.\n */\ninterface LocatedNodesBatch {\n\t/**\n\t * UpPath shared by all {@link RelativeNodePath}s in this batch corresponding to the root of the inserted content.\n\t */\n\treadonly rootPath: Root;\n\treadonly paths: RelativeNodePath[];\n}\n\n/**\n * A dummy key value used in {@link LocatedNodesBatch.rootPath} which will be replaced with the actual detached field once it is known.\n */\nconst placeholderKey: DetachedField & FieldKey = brand(\"placeholder\" as const);\n\n/**\n * Records any {@link TreeNode}s in the given `content` tree and does the necessary bookkeeping to ensure they are synchronized with subsequent reads of the tree.\n * Additionally populates any {@link UnhydratedFlexTreeField.pendingDefault}s using the provided `context`.\n *\n * @remarks If the content tree contains has any associated {@link TreeNode}s, this function must be called just prior to inserting the content into the tree.\n * Specifically, no other content may be inserted into the tree between the invocation of this function and the insertion of `content`.\n * The insertion of `content` must occur or else this function will cause memory leaks.\n *\n * Exported for testing purposes: otherwise should not be used outside this module.\n * @param content - the content subsequence to be inserted, of which might deeply contain {@link TreeNode}s which need to be hydrated.\n * @param forest - the forest the content is being inserted into.\n */\nexport function prepareContentForHydration(\n\tcontent: readonly UnhydratedFlexTreeNode[],\n\tforest: IForestSubscription,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tconst batches: LocatedNodesBatch[] = [];\n\tfor (const item of content) {\n\t\tconst batch: LocatedNodesBatch = {\n\t\t\trootPath: {\n\t\t\t\tparent: undefined,\n\t\t\t\tparentField: placeholderKey,\n\t\t\t\tparentIndex: 0,\n\t\t\t},\n\t\t\tpaths: [],\n\t\t};\n\t\tbatches.push(batch);\n\t\twalkMapTree(\n\t\t\titem,\n\t\t\tbatch.rootPath,\n\t\t\t(p, node) => {\n\t\t\t\tbatch.paths.push({ path: p, node });\n\t\t\t},\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tscheduleHydration(batches, forest);\n}\n\nfunction walkMapTree(\n\troot: UnhydratedFlexTreeNode,\n\tpath: UpPath,\n\tonVisitTreeNode: (path: UpPath, treeNode: TreeNode) => void,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tif (root.parentField.parent.parent !== undefined) {\n\t\tthrow new UsageError(\n\t\t\t\"Attempted to insert a node which is already under a parent. If this is desired, remove the node from its parent before inserting it elsewhere.\",\n\t\t);\n\t}\n\n\ttype Next = [path: UpPath, tree: UnhydratedFlexTreeNode];\n\tconst nexts: Next[] = [];\n\tfor (let next: Next | undefined = [path, root]; next !== undefined; next = nexts.pop()) {\n\t\tconst [p, node] = next;\n\t\tif (node !== undefined) {\n\t\t\tconst treeNode = node.treeNode;\n\t\t\tif (treeNode !== undefined) {\n\t\t\t\tonVisitTreeNode(p, treeNode);\n\t\t\t}\n\t\t}\n\n\t\tfor (const [key, field] of node.allFieldsLazy) {\n\t\t\tfield.fillPendingDefaults(context);\n\t\t\tfor (const [i, child] of field.children.entries()) {\n\t\t\t\tnexts.push([\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: p,\n\t\t\t\t\t\tparentField: key,\n\t\t\t\t\t\tparentIndex: i,\n\t\t\t\t\t},\n\t\t\t\t\tchild,\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Register events which will hydrate batches of nodes when they are inserted.\n * The next edits to forest must be their insertions, in order, or data corruption can occur.\n * @param locatedNodes - the nodes to register with the forest.\n * Each index in this array expects its content to be added and produce its own `afterRootFieldCreated` event.\n * If array subsequence insertion is optimized to produce a single event, this will not work correctly as is, and will need to be modified to take in a single {@link LocatedNodesBatch}.\n */\nfunction scheduleHydration(\n\tlocatedNodes: readonly LocatedNodesBatch[],\n\tforest: IForestSubscription,\n): void {\n\t// Only subscribe to the event if there is at least one TreeNode tree to hydrate - this is not the case when inserting an empty array [].\n\tif (locatedNodes.length > 0) {\n\t\t// Creating a new array emits one event per element in the array, so listen to the event once for each element\n\t\tlet i = 0;\n\t\tconst off = forest.events.on(\"afterRootFieldCreated\", (fieldKey) => {\n\t\t\t// Indexing is safe here because of the length check above. This assumes the array has not been modified which should be the case.\n\t\t\tconst batch = locatedNodes[i] ?? oob();\n\t\t\tdebugAssert(() => batch.rootPath.parentField === placeholderKey);\n\t\t\tbatch.rootPath.parentField = brand(fieldKey);\n\t\t\tfor (const { path, node } of batch.paths) {\n\t\t\t\tgetKernel(node).hydrate(forest.anchors, path);\n\t\t\t}\n\t\t\tif (++i === locatedNodes.length) {\n\t\t\t\toff();\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prepareForInsertion.js","sourceRoot":"","sources":["../../src/simple-tree/prepareForInsertion.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAWH,4DAOuC;AACvC,qDAAkF;AAClF,+FAG+C;AAC/C,uEAAsE;AACtE,+CAAyC;AACzC,8CAKyB;AACzB,kEAAuE;AACvE,4DAAiF;AACjF,2DAAmD;AAEnD;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAClC,IAAS,EACT,MAA2B,EAC3B,kBAAmC;IAEnC,OAAO,8BAA8B,CACpC,IAAI,EACJ,MAAM,EACN,IAAA,6BAAkB,EAAC,kBAAkB,CAAC,EACtC,kBAAkB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAChE,CAAC;AACH,CAAC;AAXD,kDAWC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,+BAA+B,CAC9C,IAAkC,EAClC,MAA4B,EAC5B,kBAAmC;IAEnC,MAAM,QAAQ,GAA6B,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC5D,IAAA,sEAAgC,EAAC,IAAI,EAAE,MAAM,CAAC,CAC9C,CAAC;IAEF,MAAM,WAAW,GAAG,IAAA,gCAAY,EAAC,IAAA,qCAAoB,EAAC,MAAM,CAAC,CAAC,CAAC;IAE/D,kBAAkB,CACjB,IAAA,6BAAkB,EAAC,kBAAkB,CAAC,EACtC,kBAAkB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC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AAK,CAAC,KAAK,EAAE,CAAC;gBAC1C,IAAA,oBAAS,EAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC/C,CAAC;YACD,IAAI,EAAE,CAAC,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;gBACjC,GAAG,EAAE,CAAC;YACP,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tSchemaAndPolicy,\n\tIForestSubscription,\n\tUpPath,\n\tNodeIndex,\n\tFieldKey,\n\tDetachedField,\n\tTreeFieldStoredSchema,\n} from \"../core/index.js\";\nimport {\n\ttype FlexTreeContext,\n\tgetSchemaAndPolicy,\n\ttype FlexTreeHydratedContextMinimal,\n\tFieldKinds,\n\ttype FlexibleFieldContent,\n\ttype FlexibleNodeContent,\n} from \"../feature-libraries/index.js\";\nimport { normalizeFieldSchema, type ImplicitFieldSchema } from \"./fieldSchema.js\";\nimport {\n\ttype InsertableContent,\n\tunhydratedFlexTreeFromInsertable,\n} from \"./unhydratedFlexTreeFromInsertable.js\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { brand } from \"../util/index.js\";\nimport {\n\tgetKernel,\n\ttype ImplicitAllowedTypes,\n\ttype TreeNode,\n\ttype UnhydratedFlexTreeNode,\n} from \"./core/index.js\";\nimport { debugAssert, oob } from \"@fluidframework/core-utils/internal\";\nimport { inSchemaOrThrow, isFieldInSchema } from \"../feature-libraries/index.js\";\nimport { convertField } from \"./toStoredSchema.js\";\n\n/**\n * Prepare content from a user for insertion into a tree.\n * @remarks\n * This validates and converts the input, and if necessary invokes {@link prepareContentForHydration}.\n *\n * The next edit made to `destinationContext`'s forest must be the creation of a detached field containing this content,\n * (Triggering {@link ForestEvents.afterRootFieldCreated}) otherwise hydration will break.\n */\nexport function prepareForInsertion<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tdestinationContext: FlexTreeContext,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\treturn prepareForInsertionContextless(\n\t\tdata,\n\t\tschema,\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t);\n}\n\n/**\n * {@link prepareForInsertion} but batched for array content.\n * @remarks\n * This is for inserting items into an array, not a inserting a {@link TreeArrayNode} (that would use {@link prepareForInsertion}).\n *\n * The next edits made to `destinationContext`'s forest must be the creation of a detached field.\n * One edit for each item in `data`, in order.\n *\n * @privateRemarks\n * This has to be done as a single operation for all items in data\n * (as opposed to mapping {@link prepareForInsertion} over the array)\n * due to how the eventing in prepareContentForHydration works.\n */\nexport function prepareArrayContentForInsertion(\n\tdata: readonly InsertableContent[],\n\tschema: ImplicitAllowedTypes,\n\tdestinationContext: FlexTreeContext,\n): FlexibleFieldContent {\n\tconst mapTrees: UnhydratedFlexTreeNode[] = data.map((item) =>\n\t\tunhydratedFlexTreeFromInsertable(item, schema),\n\t);\n\n\tconst fieldSchema = convertField(normalizeFieldSchema(schema));\n\n\tvalidateAndPrepare(\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t\t{\n\t\t\tkind: FieldKinds.sequence.identifier,\n\t\t\ttypes: fieldSchema.types,\n\t\t\tpersistedMetadata: undefined,\n\t\t},\n\t\tmapTrees,\n\t);\n\n\treturn mapTrees;\n}\n\n/**\n * Split out from {@link prepareForInsertion} as to allow use without a context.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n *\n * @remarks\n * Adding this entry point is a workaround for initialize not currently having a context.\n */\nexport function prepareForInsertionContextless<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\tconst mapTree = unhydratedFlexTreeFromInsertable(data, schema);\n\n\tconst contentArray = mapTree === undefined ? [] : [mapTree];\n\tconst fieldSchema = convertField(normalizeFieldSchema(schema));\n\tvalidateAndPrepare(schemaAndPolicy, hydratedData, fieldSchema, contentArray);\n\n\treturn mapTree;\n}\n\n/**\n * If hydrating, do a final validation against the schema and prepare the content for hydration.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n */\nfunction validateAndPrepare(\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n\tfieldSchema: TreeFieldStoredSchema,\n\tmapTrees: readonly UnhydratedFlexTreeNode[],\n): void {\n\tif (hydratedData !== undefined) {\n\t\t// Run `prepareContentForHydration` before walking the tree in `isFieldInSchema`.\n\t\t// This ensures that when `isFieldInSchema` requests identifiers (or any other contextual defaults),\n\t\t// they were already creating used the more specific context we have access to from `hydratedData`.\n\t\tprepareContentForHydration(mapTrees, hydratedData.checkout.forest, hydratedData);\n\t\tif (schemaAndPolicy.policy.validateSchema === true) {\n\t\t\tconst maybeError = isFieldInSchema(mapTrees, fieldSchema, schemaAndPolicy);\n\t\t\tinSchemaOrThrow(maybeError);\n\t\t}\n\t}\n}\n\n/**\n * An {@link UpPath} that is just index zero in a {@link DetachedField} which can be modified at a later time.\n */\ninterface Root extends UpPath {\n\treadonly parent: undefined;\n\tparentField: DetachedField & FieldKey;\n\treadonly parentIndex: NodeIndex & 0;\n}\n\n/**\n * The path from the included node to the root of the content tree it was inserted as part of.\n */\ninterface RelativeNodePath {\n\treadonly path: UpPath;\n\treadonly node: TreeNode;\n}\n\n/**\n * {@link RelativeNodePath}s for every {@link TreeNode} in the content tree inserted as an atomic operation.\n */\ninterface LocatedNodesBatch {\n\t/**\n\t * UpPath shared by all {@link RelativeNodePath}s in this batch corresponding to the root of the inserted content.\n\t */\n\treadonly rootPath: Root;\n\treadonly paths: RelativeNodePath[];\n}\n\n/**\n * A dummy key value used in {@link LocatedNodesBatch.rootPath} which will be replaced with the actual detached field once it is known.\n */\nconst placeholderKey: DetachedField & FieldKey = brand(\"placeholder\" as const);\n\n/**\n * Records any {@link TreeNode}s in the given `content` tree and does the necessary bookkeeping to ensure they are synchronized with subsequent reads of the tree.\n * Additionally populates any {@link UnhydratedFlexTreeField.pendingDefault}s using the provided `context`.\n *\n * @remarks If the content tree contains has any associated {@link TreeNode}s, this function must be called just prior to inserting the content into the tree.\n * Specifically, no other content may be inserted into the tree between the invocation of this function and the insertion of `content`.\n * The insertion of `content` must occur or else this function will cause memory leaks.\n *\n * Exported for testing purposes: otherwise should not be used outside this module.\n * @param content - the content subsequence to be inserted, of which might deeply contain {@link TreeNode}s which need to be hydrated.\n * @param forest - the forest the content is being inserted into.\n */\nexport function prepareContentForHydration(\n\tcontent: readonly UnhydratedFlexTreeNode[],\n\tforest: IForestSubscription,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tconst batches: LocatedNodesBatch[] = [];\n\tfor (const item of content) {\n\t\tconst batch: LocatedNodesBatch = {\n\t\t\trootPath: {\n\t\t\t\tparent: undefined,\n\t\t\t\tparentField: placeholderKey,\n\t\t\t\tparentIndex: 0,\n\t\t\t},\n\t\t\tpaths: [],\n\t\t};\n\t\tbatches.push(batch);\n\t\twalkMapTree(\n\t\t\titem,\n\t\t\tbatch.rootPath,\n\t\t\t(p, node) => {\n\t\t\t\tbatch.paths.push({ path: p, node });\n\t\t\t},\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tscheduleHydration(batches, forest);\n}\n\nfunction walkMapTree(\n\troot: UnhydratedFlexTreeNode,\n\tpath: UpPath,\n\tonVisitTreeNode: (path: UpPath, treeNode: TreeNode) => void,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tif (root.parentField.parent.parent !== undefined) {\n\t\tthrow new UsageError(\n\t\t\t\"Attempted to insert a node which is already under a parent. If this is desired, remove the node from its parent before inserting it elsewhere.\",\n\t\t);\n\t}\n\n\ttype Next = [path: UpPath, tree: UnhydratedFlexTreeNode];\n\tconst nexts: Next[] = [];\n\tfor (let next: Next | undefined = [path, root]; next !== undefined; next = nexts.pop()) {\n\t\tconst [p, node] = next;\n\t\tif (node !== undefined) {\n\t\t\tconst treeNode = node.treeNode;\n\t\t\tif (treeNode !== undefined) {\n\t\t\t\tonVisitTreeNode(p, treeNode);\n\t\t\t}\n\t\t}\n\n\t\tfor (const [key, field] of node.allFieldsLazy) {\n\t\t\tfield.fillPendingDefaults(context);\n\t\t\tfor (const [i, child] of field.children.entries()) {\n\t\t\t\tnexts.push([\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: p,\n\t\t\t\t\t\tparentField: key,\n\t\t\t\t\t\tparentIndex: i,\n\t\t\t\t\t},\n\t\t\t\t\tchild,\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Register events which will hydrate batches of nodes when they are inserted.\n * The next edits to forest must be their insertions, in order, or data corruption can occur.\n * @param locatedNodes - the nodes to register with the forest.\n * Each index in this array expects its content to be added and produce its own `afterRootFieldCreated` event.\n * If array subsequence insertion is optimized to produce a single event, this will not work correctly as is, and will need to be modified to take in a single {@link LocatedNodesBatch}.\n */\nfunction scheduleHydration(\n\tlocatedNodes: readonly LocatedNodesBatch[],\n\tforest: IForestSubscription,\n): void {\n\t// Only subscribe to the event if there is at least one TreeNode tree to hydrate - this is not the case when inserting an empty array [].\n\tif (locatedNodes.length > 0) {\n\t\t// Creating a new array emits one event per element in the array, so listen to the event once for each element\n\t\tlet i = 0;\n\t\tconst off = forest.events.on(\"afterRootFieldCreated\", (fieldKey) => {\n\t\t\t// Indexing is safe here because of the length check above. This assumes the array has not been modified which should be the case.\n\t\t\tconst batch = locatedNodes[i] ?? oob();\n\t\t\tdebugAssert(() => batch.rootPath.parentField === placeholderKey);\n\t\t\tbatch.rootPath.parentField = brand(fieldKey);\n\t\t\tfor (const { path, node } of batch.paths) {\n\t\t\t\tgetKernel(node).hydrate(forest.anchors, path);\n\t\t\t}\n\t\t\tif (++i === locatedNodes.length) {\n\t\t\t\toff();\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { ValueSchema } from "../core/index.js";
|
|
6
6
|
import type { JsonCompatibleReadOnlyObject } from "../util/index.js";
|
|
7
|
-
import type { NodeKind } from "./core/index.js";
|
|
8
|
-
import type { FieldKind, FieldSchemaMetadata
|
|
7
|
+
import type { NodeKind, NodeSchemaMetadata } from "./core/index.js";
|
|
8
|
+
import type { FieldKind, FieldSchemaMetadata } from "./fieldSchema.js";
|
|
9
9
|
/**
|
|
10
10
|
* Base interface for {@link TreeNodeSchema} and {@link SimpleNodeSchema} types.
|
|
11
11
|
* Once simple schema is stable this doesn't have a reason to be kept `@system`, but it could be.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleSchema.d.ts","sourceRoot":"","sources":["../../src/simple-tree/simpleSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"simpleSchema.d.ts","sourceRoot":"","sources":["../../src/simple-tree/simpleSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,iB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-1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleSchema.js","sourceRoot":"","sources":["../../src/simple-tree/simpleSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ValueSchema } from \"../core/index.js\";\nimport type { JsonCompatibleReadOnlyObject } from \"../util/index.js\";\nimport type { NodeKind } from \"./core/index.js\";\nimport type { FieldKind, FieldSchemaMetadata
|
|
1
|
+
{"version":3,"file":"simpleSchema.js","sourceRoot":"","sources":["../../src/simple-tree/simpleSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ValueSchema } from \"../core/index.js\";\nimport type { JsonCompatibleReadOnlyObject } from \"../util/index.js\";\nimport type { NodeKind, NodeSchemaMetadata } from \"./core/index.js\";\nimport type { FieldKind, FieldSchemaMetadata } from \"./fieldSchema.js\";\n\n/*\n * TODO:\n * - Customize their JSON serialization to use these formats or provide some other serialization scheme.\n */\n\n/**\n * Base interface for {@link TreeNodeSchema} and {@link SimpleNodeSchema} types.\n * Once simple schema is stable this doesn't have a reason to be kept `@system`, but it could be.\n * @system\n * @public\n * @sealed\n */\nexport interface SimpleNodeSchemaBase<\n\tout TNodeKind extends NodeKind,\n\tout TCustomMetadata = unknown,\n> {\n\t/**\n\t * The {@link NodeKind}.\n\t *\n\t * @remarks can be used to type-switch between implementations.\n\t */\n\treadonly kind: TNodeKind;\n\n\t/**\n\t * User-provided {@link NodeSchemaMetadata} for this schema.\n\t */\n\treadonly metadata: NodeSchemaMetadata<TCustomMetadata>;\n}\n\n/**\n * A {@link SimpleNodeSchema} containing fields for alpha features.\n *\n * @system\n * @alpha\n * @sealed\n */\nexport interface SimpleNodeSchemaBaseAlpha<\n\tout TNodeKind extends NodeKind,\n\tout TCustomMetadata = unknown,\n> extends SimpleNodeSchemaBase<TNodeKind, TCustomMetadata> {\n\t/**\n\t * Persisted metadata for this node schema.\n\t */\n\treadonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined;\n}\n\n/**\n * A {@link SimpleNodeSchema} for an object node.\n *\n * @alpha\n * @sealed\n */\nexport interface SimpleObjectNodeSchema<out TCustomMetadata = unknown>\n\textends SimpleNodeSchemaBaseAlpha<NodeKind.Object, TCustomMetadata> {\n\t/**\n\t * Schemas for each of the object's fields, keyed off of schema's keys.\n\t * @remarks\n\t * The keys are the property keys if known, otherwise they are the stored keys.\n\t * Use {@link SimpleObjectFieldSchema.storedKey} to get the stored key.\n\t * @privateRemarks\n\t * TODO: Provide and link a way to translate from stored keys to the property keys.\n\t * TODO: Consider adding `storedKeysToFields` or something similar to reduce confusion,\n\t * especially if/when TreeNodeSchema for objects provide more maps.\n\t */\n\treadonly fields: ReadonlyMap<string, SimpleObjectFieldSchema>;\n}\n\n/**\n * A {@link SimpleFieldSchema} for an {@link SimpleObjectNodeSchema} field.\n * @remarks\n * The only other case fields are uses in the root schema.\n *\n * @alpha\n * @sealed\n */\nexport interface SimpleObjectFieldSchema extends SimpleFieldSchema {\n\t/**\n\t * The stored key of the field.\n\t * @remarks\n\t * See {@link FieldProps.key} for more information.\n\t */\n\treadonly storedKey: string;\n}\n\n/**\n * A {@link SimpleNodeSchema} for an array node.\n *\n * @alpha\n * @sealed\n */\nexport interface SimpleArrayNodeSchema<out TCustomMetadata = unknown>\n\textends SimpleNodeSchemaBaseAlpha<NodeKind.Array, TCustomMetadata> {\n\t/**\n\t * The types allowed in the array.\n\t *\n\t * @remarks Refers to the types by identifier.\n\t * A {@link SimpleTreeSchema} is needed to resolve these identifiers to their schema {@link SimpleTreeSchema.definitions}.\n\t */\n\treadonly allowedTypesIdentifiers: ReadonlySet<string>;\n}\n\n/**\n * A {@link SimpleNodeSchema} for a map node.\n *\n * @alpha\n * @sealed\n */\nexport interface SimpleMapNodeSchema<out TCustomMetadata = unknown>\n\textends SimpleNodeSchemaBaseAlpha<NodeKind.Map, TCustomMetadata> {\n\t/**\n\t * The types allowed as values in the map.\n\t *\n\t * @remarks Refers to the types by identifier.\n\t * A {@link SimpleTreeSchema} is needed to resolve these identifiers to their schema {@link SimpleTreeSchema.definitions}.\n\t */\n\treadonly allowedTypesIdentifiers: ReadonlySet<string>;\n}\n\n/**\n * A {@link SimpleNodeSchema} for a map node.\n *\n * @alpha\n * @sealed\n */\nexport interface SimpleRecordNodeSchema<out TCustomMetadata = unknown>\n\textends SimpleNodeSchemaBaseAlpha<NodeKind.Record, TCustomMetadata> {\n\t/**\n\t * The types allowed as values in the record.\n\t *\n\t * @remarks Refers to the types by identifier.\n\t * A {@link SimpleTreeSchema} is needed to resolve these identifiers to their schema {@link SimpleTreeSchema.definitions}.\n\t */\n\treadonly allowedTypesIdentifiers: ReadonlySet<string>;\n}\n\n/**\n * A {@link SimpleNodeSchema} for a leaf node.\n *\n * @alpha\n * @sealed\n */\nexport interface SimpleLeafNodeSchema extends SimpleNodeSchemaBaseAlpha<NodeKind.Leaf> {\n\t/**\n\t * The kind of leaf node.\n\t */\n\treadonly leafKind: ValueSchema;\n}\n\n/**\n * A simple, shallow representation of a schema for a node.\n *\n * @remarks This definition is incomplete, and references child types by identifiers.\n * To be useful, this generally needs to be used as a part of a complete {@link SimpleTreeSchema}, which\n * contains backing {@link SimpleTreeSchema.definitions} for each referenced identifier.\n *\n * Note that, as documented on {@link NodeKind}, more kinds of nodes may be added,\n * and therefore code should not assume that switching over all these cases can be done exhaustively.\n * @privateRemarks\n * Because of the above mentioned extensibility of node kinds, does it make sense to stabilize this?\n *\n * @alpha\n */\nexport type SimpleNodeSchema =\n\t| SimpleLeafNodeSchema\n\t| SimpleMapNodeSchema\n\t| SimpleArrayNodeSchema\n\t| SimpleObjectNodeSchema\n\t| SimpleRecordNodeSchema;\n\n/**\n * A simple, shallow representation of a schema for a field.\n *\n * @remarks This definition is incomplete, and references child types by identifiers.\n * To be useful, this generally needs to be used as a part of a complete {@link SimpleTreeSchema}, which\n * contains backing {@link SimpleTreeSchema.definitions} for each referenced identifier.\n *\n * @alpha\n * @sealed\n */\nexport interface SimpleFieldSchema {\n\t/**\n\t * The kind of tree field.\n\t */\n\treadonly kind: FieldKind;\n\n\t/**\n\t * The types allowed under the field.\n\t *\n\t * @remarks Refers to the types by identifier.\n\t * A {@link SimpleTreeSchema} is needed to resolve these identifiers to their schema {@link SimpleTreeSchema.definitions}.\n\t */\n\treadonly allowedTypesIdentifiers: ReadonlySet<string>;\n\n\t/**\n\t * {@inheritDoc FieldSchemaMetadata}\n\t */\n\treadonly metadata: FieldSchemaMetadata;\n\n\t/**\n\t * Persisted metadata for this field schema.\n\t */\n\treadonly persistedMetadata?: JsonCompatibleReadOnlyObject | undefined;\n}\n\n/**\n * A simplified representation of a schema for a tree.\n *\n * @remarks Contains the complete set of schema {@link SimpleTreeSchema.definitions} required to resolve references,\n * which are represented inline with identifiers.\n *\n * @alpha\n * @sealed\n */\nexport interface SimpleTreeSchema {\n\t/**\n\t * The tree field representing the root of the tree.\n\t */\n\treadonly root: SimpleFieldSchema;\n\n\t/**\n\t * The complete set of node schema definitions recursively referenced by the tree's {@link SimpleTreeSchema.root}.\n\t *\n\t * @remarks the keys are the schemas' {@link TreeNodeSchemaCore.identifier | identifiers}.\n\t */\n\treadonly definitions: ReadonlyMap<string, SimpleNodeSchema>;\n}\n"]}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { type TreeFieldStoredSchema, type TreeNodeStoredSchema, type TreeStoredSchema } from "../core/index.js";
|
|
6
6
|
import { type FlexFieldKind } from "../feature-libraries/index.js";
|
|
7
|
-
import { FieldKind, type ImplicitFieldSchema } from "./
|
|
7
|
+
import { FieldKind, type ImplicitFieldSchema } from "./fieldSchema.js";
|
|
8
8
|
import type { SimpleFieldSchema, SimpleNodeSchema, SimpleTreeSchema } from "./simpleSchema.js";
|
|
9
9
|
/**
|
|
10
10
|
* Converts a {@link ImplicitFieldSchema} into a {@link TreeStoredSchema}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toStoredSchema.d.ts","sourceRoot":"","sources":["../../src/simple-tree/toStoredSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAON,KAAK,qBAAqB,EAE1B,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAErB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"toStoredSchema.d.ts","sourceRoot":"","sources":["../../src/simple-tree/toStoredSchema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAON,KAAK,qBAAqB,EAE1B,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAErB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAI/E,OAAO,EAAE,SAAS,EAAwB,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,KAAK,EACX,iBAAiB,EACjB,gBAAgB,EAEhB,gBAAgB,EAChB,MAAM,mBAAmB,CAAC;AAK3B;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,mBAAmB,GAAG,gBAAgB,CA2B1E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CAW7E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,qBAAqB,CAK7E;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,SAAS,EAAE,aAAa,CAOjE,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,gBAAgB,GAAG,oBAAoB,CAyC9E"}
|
|
@@ -11,8 +11,7 @@ const index_js_1 = require("../core/index.js");
|
|
|
11
11
|
const index_js_2 = require("../feature-libraries/index.js");
|
|
12
12
|
const index_js_3 = require("../util/index.js");
|
|
13
13
|
const index_js_4 = require("./core/index.js");
|
|
14
|
-
const
|
|
15
|
-
const schemaTypes_js_1 = require("./schemaTypes.js");
|
|
14
|
+
const fieldSchema_js_1 = require("./fieldSchema.js");
|
|
16
15
|
const walkFieldSchema_js_1 = require("./walkFieldSchema.js");
|
|
17
16
|
const viewToStoredCache = new WeakMap();
|
|
18
17
|
/**
|
|
@@ -22,7 +21,7 @@ const viewToStoredCache = new WeakMap();
|
|
|
22
21
|
*/
|
|
23
22
|
function toStoredSchema(root) {
|
|
24
23
|
return (0, index_js_3.getOrCreate)(viewToStoredCache, root, () => {
|
|
25
|
-
const normalized = (0,
|
|
24
|
+
const normalized = (0, fieldSchema_js_1.normalizeFieldSchema)(root);
|
|
26
25
|
const nodeSchema = new Map();
|
|
27
26
|
(0, walkFieldSchema_js_1.walkFieldSchema)(normalized, {
|
|
28
27
|
node(schema) {
|
|
@@ -69,9 +68,9 @@ exports.convertField = convertField;
|
|
|
69
68
|
* A map that converts {@link FieldKind} to {@link FlexFieldKind}.
|
|
70
69
|
*/
|
|
71
70
|
exports.convertFieldKind = new Map([
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
71
|
+
[fieldSchema_js_1.FieldKind.Optional, index_js_2.FieldKinds.optional],
|
|
72
|
+
[fieldSchema_js_1.FieldKind.Required, index_js_2.FieldKinds.required],
|
|
73
|
+
[fieldSchema_js_1.FieldKind.Identifier, index_js_2.FieldKinds.identifier],
|
|
75
74
|
]);
|
|
76
75
|
/**
|
|
77
76
|
* Converts a {@link TreeNodeSchema} into a {@link TreeNodeStoredSchema}.
|
|
@@ -82,7 +81,7 @@ function getStoredSchema(schema) {
|
|
|
82
81
|
const kind = schema.kind;
|
|
83
82
|
switch (kind) {
|
|
84
83
|
case index_js_4.NodeKind.Leaf: {
|
|
85
|
-
(0, internal_1.assert)(schema
|
|
84
|
+
(0, internal_1.assert)(schema.kind === index_js_4.NodeKind.Leaf, 0xa4a /* invalid kind */);
|
|
86
85
|
return new index_js_1.LeafNodeStoredSchema(schema.leafKind);
|
|
87
86
|
}
|
|
88
87
|
case index_js_4.NodeKind.Map:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toStoredSchema.js","sourceRoot":"","sources":["../../src/simple-tree/toStoredSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAoF;AACpF,uEAAsE;AAEtE,+CAY0B;AAC1B,4DAA+E;AAC/E,+CAAsD;AAEtD,8CAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"toStoredSchema.js","sourceRoot":"","sources":["../../src/simple-tree/toStoredSchema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAoF;AACpF,uEAAsE;AAEtE,+CAY0B;AAC1B,4DAA+E;AAC/E,+CAAsD;AAEtD,8CAA2C;AAC3C,qDAA6F;AAO7F,6DAAuD;AAEvD,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAyC,CAAC;AAE/E;;;;GAIG;AACH,SAAgB,cAAc,CAAC,IAAyB;IACvD,OAAO,IAAA,sBAAW,EAAC,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE;QAChD,MAAM,UAAU,GAAG,IAAA,qCAAoB,EAAC,IAAI,CAAC,CAAC;QAC9C,MAAM,UAAU,GAAwD,IAAI,GAAG,EAAE,CAAC;QAClF,IAAA,oCAAe,EAAC,UAAU,EAAE;YAC3B,IAAI,CAAC,MAAM;gBACV,IAAI,UAAU,CAAC,GAAG,CAAC,IAAA,gBAAK,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;oBAC9C,4DAA4D;oBAC5D,MAAM,IAAI,qBAAU,CACnB,mDAAmD,IAAI,CAAC,SAAS,CAChE,MAAM,CAAC,UAAU,CACjB,iDAAiD,CAClD,CAAC;gBACH,CAAC;gBACD,UAAU,CAAC,GAAG,CACb,IAA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C;QACrE,CAAC;QACD,KAAK,mBAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;YACtB,MAAM,MAAM,GAAyC,IAAI,GAAG,EAAE,CAAC;YAC/D,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;gBAClD,MAAM,CAAC,GAAG,CAAC,IAAA,gBAAK,EAAC,WAAW,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC;YACrE,CAAC;YACD,OAAO,IAAI,iCAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACT,IAAA,0BAAe,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;IACF,CAAC;AACF,CAAC;AAzCD,0CAyCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEmptyKey,\n\tLeafNodeStoredSchema,\n\tMapNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeNodeStoredSchema,\n\ttype TreeStoredSchema,\n\ttype TreeTypeSet,\n} from \"../core/index.js\";\nimport { FieldKinds, type FlexFieldKind } from \"../feature-libraries/index.js\";\nimport { brand, getOrCreate } from \"../util/index.js\";\n\nimport { NodeKind } from \"./core/index.js\";\nimport { FieldKind, normalizeFieldSchema, type ImplicitFieldSchema } from \"./fieldSchema.js\";\nimport type {\n\tSimpleFieldSchema,\n\tSimpleNodeSchema,\n\tSimpleNodeSchemaBase,\n\tSimpleTreeSchema,\n} from \"./simpleSchema.js\";\nimport { walkFieldSchema } from \"./walkFieldSchema.js\";\n\nconst viewToStoredCache = new WeakMap<ImplicitFieldSchema, TreeStoredSchema>();\n\n/**\n * Converts a {@link ImplicitFieldSchema} into a {@link TreeStoredSchema}.\n * @throws\n * Throws a `UsageError` if multiple schemas are encountered with the same identifier.\n */\nexport function toStoredSchema(root: ImplicitFieldSchema): TreeStoredSchema {\n\treturn getOrCreate(viewToStoredCache, root, () => {\n\t\tconst normalized = normalizeFieldSchema(root);\n\t\tconst nodeSchema: Map<TreeNodeSchemaIdentifier, TreeNodeStoredSchema> = new Map();\n\t\twalkFieldSchema(normalized, {\n\t\t\tnode(schema) {\n\t\t\t\tif (nodeSchema.has(brand(schema.identifier))) {\n\t\t\t\t\t// Use JSON.stringify to quote and escape identifier string.\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`Multiple schema encountered with the identifier ${JSON.stringify(\n\t\t\t\t\t\t\tschema.identifier,\n\t\t\t\t\t\t)}. Remove or rename them to avoid the collision.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tnodeSchema.set(\n\t\t\t\t\tbrand(schema.identifier),\n\t\t\t\t\tgetStoredSchema(schema as SimpleNodeSchemaBase<NodeKind> as SimpleNodeSchema),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\n\t\tconst result: TreeStoredSchema = {\n\t\t\tnodeSchema,\n\t\t\trootFieldSchema: convertField(normalized),\n\t\t};\n\t\treturn result;\n\t});\n}\n\n/**\n * Converts a {@link SimpleTreeSchema} into a {@link TreeStoredSchema}.\n */\nexport function simpleToStoredSchema(root: SimpleTreeSchema): TreeStoredSchema {\n\tconst nodeSchema: Map<TreeNodeSchemaIdentifier, TreeNodeStoredSchema> = new Map();\n\tfor (const [identifier, schema] of root.definitions) {\n\t\tnodeSchema.set(brand(identifier), getStoredSchema(schema));\n\t}\n\n\tconst result: TreeStoredSchema = {\n\t\tnodeSchema,\n\t\trootFieldSchema: convertField(root.root),\n\t};\n\treturn result;\n}\n\n/**\n * Normalizes an {@link ImplicitFieldSchema} into a {@link TreeFieldSchema}.\n */\nexport function convertField(schema: SimpleFieldSchema): TreeFieldStoredSchema {\n\tconst kind: FieldKindIdentifier =\n\t\tconvertFieldKind.get(schema.kind)?.identifier ?? fail(0xae3 /* Invalid field kind */);\n\tconst types: TreeTypeSet = schema.allowedTypesIdentifiers as TreeTypeSet;\n\treturn { kind, types, persistedMetadata: schema.persistedMetadata };\n}\n\n/**\n * A map that converts {@link FieldKind} to {@link FlexFieldKind}.\n */\nexport const convertFieldKind: ReadonlyMap<FieldKind, FlexFieldKind> = new Map<\n\tFieldKind,\n\tFlexFieldKind\n>([\n\t[FieldKind.Optional, FieldKinds.optional],\n\t[FieldKind.Required, FieldKinds.required],\n\t[FieldKind.Identifier, FieldKinds.identifier],\n]);\n\n/**\n * Converts a {@link TreeNodeSchema} into a {@link TreeNodeStoredSchema}.\n * @privateRemarks\n * TODO: Persist node metadata once schema FormatV2 is supported.\n */\nexport function getStoredSchema(schema: SimpleNodeSchema): TreeNodeStoredSchema {\n\tconst kind = schema.kind;\n\tswitch (kind) {\n\t\tcase NodeKind.Leaf: {\n\t\t\tassert(schema.kind === NodeKind.Leaf, 0xa4a /* invalid kind */);\n\t\t\treturn new LeafNodeStoredSchema(schema.leafKind);\n\t\t}\n\t\tcase NodeKind.Map:\n\t\tcase NodeKind.Record: {\n\t\t\tconst types = schema.allowedTypesIdentifiers as TreeTypeSet;\n\t\t\treturn new MapNodeStoredSchema(\n\t\t\t\t{\n\t\t\t\t\tkind: FieldKinds.optional.identifier,\n\t\t\t\t\ttypes,\n\t\t\t\t\tpersistedMetadata: schema.persistedMetadata,\n\t\t\t\t},\n\t\t\t\t// TODO: Find a way to avoid injecting persistedMetadata twice in these constructor calls.\n\t\t\t\tschema.persistedMetadata,\n\t\t\t);\n\t\t}\n\t\tcase NodeKind.Array: {\n\t\t\tconst types = schema.allowedTypesIdentifiers as TreeTypeSet;\n\t\t\tconst field = {\n\t\t\t\tkind: FieldKinds.sequence.identifier,\n\t\t\t\ttypes,\n\t\t\t\tpersistedMetadata: schema.persistedMetadata,\n\t\t\t};\n\t\t\tconst fields = new Map([[EmptyKey, field]]);\n\t\t\treturn new ObjectNodeStoredSchema(fields, schema.persistedMetadata);\n\t\t}\n\t\tcase NodeKind.Object: {\n\t\t\tconst fields: Map<FieldKey, TreeFieldStoredSchema> = new Map();\n\t\t\tfor (const fieldSchema of schema.fields.values()) {\n\t\t\t\tfields.set(brand(fieldSchema.storedKey), convertField(fieldSchema));\n\t\t\t}\n\t\t\treturn new ObjectNodeStoredSchema(fields, schema.persistedMetadata);\n\t\t}\n\t\tdefault: {\n\t\t\tunreachableCase(kind);\n\t\t}\n\t}\n}\n"]}
|