-
Notifications
You must be signed in to change notification settings - Fork 553
feat: customizeSchemaTyping #23084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
CraigMacomber
wants to merge
45
commits into
microsoft:main
Choose a base branch
from
CraigMacomber:inversion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: customizeSchemaTyping #23084
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
8c91051
Initial example
CraigMacomber aea7d62
Make fields safer
CraigMacomber 73d05f5
Merge branch 'fieldSafe' into inversion
CraigMacomber ec64de4
Update packages/dds/tree/src/simple-tree/objectNode.ts
CraigMacomber 395c688
typeNarrow asserts
CraigMacomber 4119174
Fixes for optional
CraigMacomber a90e167
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber 90a79f5
FIx build
CraigMacomber 494dde2
Merge branch 'fieldSafe' into inversion
CraigMacomber 6997880
Export ObjectNodeSchema
CraigMacomber 735622f
customizeSchemaTyping
CraigMacomber a1c3bd0
Add customized narrowing example
CraigMacomber beffae5
add another example, and more docs
CraigMacomber 2836d9b
add branding example
CraigMacomber 7ebff45
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber 1dcd254
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber eb49097
Remove unneeded changes
CraigMacomber 10c5ef8
Fix package API
CraigMacomber 9645aa6
Recursive type support
CraigMacomber 2a91ad2
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber a3981a8
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber 773afb9
Fix merge
CraigMacomber d7cf0e5
Cleanup CustomizerUnsafe
CraigMacomber cc2684a
Cleanup and docs
CraigMacomber ec90211
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber b3dffdc
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber 6e4faa2
Fix export and reports
CraigMacomber a6df85c
Fixes tests and cleanup
CraigMacomber 14893ad
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber bdc6959
update reports
CraigMacomber 86a4b5d
Better document and test ObjectFromSchemaRecordUnsafe
CraigMacomber 8ab3281
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber addb022
Skip failing/broken/hanging test
CraigMacomber 91fe629
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber 3b33fea
Add "components" example
CraigMacomber 224c7b5
add components example
CraigMacomber 9e1328b
Add generic components system
CraigMacomber b1b2c41
Apply suggestions from code review
CraigMacomber 23487bf
More consistent and robust handling of lazy schema
CraigMacomber 13beb5e
Fix infinite recursion and broken test
CraigMacomber 3da123f
Expose evaluateLazySchema
CraigMacomber 41d2c5c
Export Component
CraigMacomber d8681cb
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber ff69090
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
CraigMacomber 94b9178
Fix merge
CraigMacomber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
"fluid-framework": minor | ||
"@fluidframework/tree": minor | ||
--- | ||
--- | ||
"section": tree | ||
--- | ||
|
||
Disallow some invalid and unsafe ObjectNode field assignments at compile time | ||
|
||
The compile time validation of the type of values assigned to ObjectNode fields is limited by TypeScript's limitations. | ||
Two cases which were actually possible to disallow and should be disallowed for consistency with runtime behavior and similar APIs were being allowed: | ||
|
||
1. [Identifier fields](https://fluidframework.com/docs/api/v2/fluid-framework/schemafactory-class#identifier-property): | ||
Identifier fields are immutable, and setting them produces a runtime error. | ||
This changes fixes them to no longer be typed as assignable. | ||
|
||
2. Fields with non-exact schema: | ||
When non-exact scheme is used for a field (for example the schema is either a schema only allowing numbers or a schema only allowing strings) the field is no longer typed as assignable. | ||
This matches how constructors and implicit node construction work. | ||
For example when a node `Foo` has such an non-exact schema for field `bar`, you can no longer unsafely do `foo.bar = 5` just like how you could already not do `new Foo({bar: 5})`. | ||
|
||
This fix only applies to [`SchemaFactory.object`](https://fluidframework.com/docs/api/v2/fluid-framework/schemafactory-class#object-method). | ||
[`SchemaFactory.objectRecursive`](https://fluidframework.com/docs/api/v2/fluid-framework/schemafactory-class#objectrecursive-method) was unable to be updated to match due to TypeScript limitations on recursive types. | ||
|
||
An `@alpha` API, `customizeSchemaTyping` has been added to allow control over the types generated from schema. | ||
For example code relying on the unsound typing fixed above can restore the behavior using `customizeSchemaTyping`: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR builds upon #23053 . This changeset will probably need to be rewritten based on the major changes.