Skip to content

Add Tree.tagContentSchema helper#25740

Merged
noencke merged 6 commits intomicrosoft:mainfrom
noencke:schema-type
Oct 24, 2025
Merged

Add Tree.tagContentSchema helper#25740
noencke merged 6 commits intomicrosoft:mainfrom
noencke:schema-type

Conversation

@noencke
Copy link
Contributor

@noencke noencke commented Oct 23, 2025

See the changeset for details

@noencke noencke requested a review from a team as a code owner October 23, 2025 17:34
Copilot AI review requested due to automatic review settings October 23, 2025 17:34
@noencke noencke requested a review from a team as a code owner October 23, 2025 17:34
@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct changeset-present public api change Changes to a public API base: main PRs targeted against main branch labels Oct 23, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new Tree.ensureSchema helper function to the alpha API that allows developers to explicitly tag insertable content with a schema type, resolving ambiguity when the same object structure could match multiple schemas. The implementation introduces a new schemaSymbol that gets attached to objects to indicate their intended schema.

Key changes:

  • Added schemaSymbol and TreeAlpha.ensureSchema to help disambiguate content that matches multiple schemas
  • Modified getPossibleTypes to respect the schemaSymbol when determining compatible schemas
  • Added comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/framework/fluid-framework/api-report/fluid-framework.alpha.api.md Exported schemaSymbol and added ensureSchema method to TreeAlpha interface
packages/dds/tree/api-report/tree.alpha.api.md Exported schemaSymbol and added ensureSchema method to TreeAlpha interface
packages/dds/tree/src/simple-tree/core/withType.ts Defined the new schemaSymbol with documentation
packages/dds/tree/src/simple-tree/core/index.ts Exported schemaSymbol from the core module
packages/dds/tree/src/simple-tree/index.ts Re-exported schemaSymbol from the simple-tree module
packages/dds/tree/src/index.ts Re-exported schemaSymbol from the main tree package
packages/dds/tree/src/simple-tree/unhydratedFlexTreeFromInsertable.ts Modified getPossibleTypes to check for and respect the schemaSymbol property
packages/dds/tree/src/shared-tree/treeAlpha.ts Implemented the ensureSchema function that tags content with the schema symbol
packages/dds/tree/src/test/simple-tree/unhydratedFlexTreeFromInsertable.spec.ts Added tests for getPossibleTypes with the type symbol
packages/dds/tree/src/test/simple-tree/api/treeNodeApi.spec.ts Added comprehensive tests for the ensureSchema API
.changeset/tricky-shirts-sleep.md Added changeset documenting the new feature

@noencke noencke requested a review from Josmithr October 23, 2025 19:43
* view.root.pet = pet; // No error - it's a Dog.
* ```
*/
ensureSchema<TSchema extends TreeNodeSchema, TContent extends InsertableField<TSchema>>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming there's no additional type-narrowing that we can provide here? The content is already InsertableField<TSchema>, there's just the potential for ambiguity that we're now preventing by tacking on the symbol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand your question. Are you thinking that we could e.g. have the return type be the type + the symbol?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not specifically. I was just musing that it might be neat if we could differentiate between insertable content that might be ambiguous vs insertable content that is not ambiguous at the type-level. I think currently the answer is no. And since nowhere else in our system is that distinction made at the type-level, I don't think it makes sense to introduce something like that here. But maybe a future consideration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea. That would be cool. Got me thinking if it's possible... maybe? You transform the input type union into a tuple with some TS trickery, and then check if the tuple has a length > 1?

@noencke noencke changed the title Add Tree.ensureSchema helper Add Tree.tagContentSchema helper Oct 24, 2025
@github-actions
Copy link
Contributor

🔗 Found some broken links! 💔

Run a link check locally to find them. See
https://github.com/microsoft/FluidFramework/wiki/Checking-for-broken-links-in-the-documentation for more information.

linkcheck output


> fluid-framework-docs-site@0.0.0 ci:check-links /home/runner/work/FluidFramework/FluidFramework/docs
> start-server-and-test "npm run serve -- --no-open" 3000 check-links

1: starting server using command "npm run serve -- --no-open"
and when url "[ 'http://127.0.0.1:3000' ]" is responding with HTTP status code 200
running tests using command "npm run check-links"


> fluid-framework-docs-site@0.0.0 serve
> docusaurus serve --no-open

[SUCCESS] Serving "build" directory at: http://localhost:3000/

> fluid-framework-docs-site@0.0.0 check-links
> linkcheck http://localhost:3000 --skip-file skipped-urls.txt

 ELIFECYCLE  Command failed with exit code 1.

@noencke noencke merged commit 8213407 into microsoft:main Oct 24, 2025
38 checks passed
anthony-murphy-agent pushed a commit to anthony-murphy-agent/FluidFramework that referenced this pull request Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: dds: tree area: dds Issues related to distributed data structures area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct base: main PRs targeted against main branch changeset-present public api change Changes to a public API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants