Skip to content
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

tree: handle schema contravariantly when generating input types #22874

Merged
merged 17 commits into from
Oct 29, 2024

Conversation

CraigMacomber
Copy link
Contributor

@CraigMacomber CraigMacomber commented Oct 22, 2024

Description

Handle schema contravariantly when generating input types.

Breaking Changes

No runtime changes, but typing tweaks could break users on non-exact schema, and the enum schema APIs have been tweaked to avoid relying on non-exact schema, see changeset.

Reviewer Guidance

The review process is outlined on this wiki page.

@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree base: main PRs targeted against main branch labels Oct 22, 2024
CraigMacomber added a commit that referenced this pull request Oct 23, 2024
## Description

Misc improvements found when working on
#22874 .

Many of these are places where schema types were not captured properly,
or incorrect typing wasn't detected due to the incorrect variance.

## Breaking Changes

The change to `InsertableObjectFromSchemaRecord` could impact something:
it's strictly a bug fix but its unclear what implications its wrong
version could have. I suspect no realistic code would be broken by these
more correct types, but it's possible something could be impacted.
@github-actions github-actions bot added area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct public api change Changes to a public API labels Oct 23, 2024
Copy link
Collaborator

@msfluid-bot msfluid-bot left a comment

Choose a reason for hiding this comment

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

Code Coverage Summary

↓ packages.dds.tree.src.simple-tree.api:
Line Coverage Change: -0.44%    Branch Coverage Change: No change
Metric NameBaseline coveragePR coverageCoverage Diff
Branch Coverage 86.53% 86.53% → No change
Line Coverage 82.12% 81.68% ↓ -0.44%
↑ packages.dds.tree.src.simple-tree.core:
Line Coverage Change: 0.01%    Branch Coverage Change: No change
Metric NameBaseline coveragePR coverageCoverage Diff
Branch Coverage 93.39% 93.39% → No change
Line Coverage 97.22% 97.23% ↑ 0.01%
↑ packages.dds.tree.src.simple-tree:
Line Coverage Change: 0.09%    Branch Coverage Change: 0.01%
Metric NameBaseline coveragePR coverageCoverage Diff
Branch Coverage 93.29% 93.30% ↑ 0.01%
Line Coverage 97.13% 97.22% ↑ 0.09%
↑ packages.dds.tree.src.events:
Line Coverage Change: 2.09%    Branch Coverage Change: No change
Metric NameBaseline coveragePR coverageCoverage Diff
Branch Coverage 92.00% 92.00% → No change
Line Coverage 68.46% 70.55% ↑ 2.09%
↑ packages.dds.tree.src.util:
Line Coverage Change: 6.23%    Branch Coverage Change: 0.40%
Metric NameBaseline coveragePR coverageCoverage Diff
Branch Coverage 96.34% 96.74% ↑ 0.40%
Line Coverage 73.80% 80.03% ↑ 6.23%

Baseline commit: a1b4cdd
Baseline build: 303010
Happy Coding!!

Code coverage comparison check passed!!

@msfluid-bot
Copy link
Collaborator

msfluid-bot commented Oct 23, 2024

@fluid-example/bundle-size-tests: +245 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 464.08 KB 464.11 KB +35 Bytes
azureClient.js 561.65 KB 561.7 KB +49 Bytes
connectionState.js 724 Bytes 724 Bytes No change
containerRuntime.js 261.67 KB 261.68 KB +14 Bytes
fluidFramework.js 406.28 KB 406.29 KB +14 Bytes
loader.js 134.16 KB 134.18 KB +14 Bytes
map.js 42.71 KB 42.71 KB +7 Bytes
matrix.js 148.54 KB 148.54 KB +7 Bytes
odspClient.js 528.18 KB 528.23 KB +49 Bytes
odspDriver.js 97.84 KB 97.86 KB +21 Bytes
odspPrefetchSnapshot.js 42.81 KB 42.82 KB +14 Bytes
sharedString.js 164.73 KB 164.74 KB +7 Bytes
sharedTree.js 396.74 KB 396.74 KB +7 Bytes
Total Size 3.32 MB 3.32 MB +245 Bytes

Baseline commit: a1b4cdd

Generated by 🚫 dangerJS against 23bfe4c

@CraigMacomber CraigMacomber marked this pull request as ready for review October 23, 2024 19:26
@CraigMacomber CraigMacomber requested review from a team as code owners October 23, 2024 19:26
Copy link
Member

@tylerbutler tylerbutler left a comment

Choose a reason for hiding this comment

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

Just some nits. Approved for docs.

.changeset/shy-dots-prove.md Outdated Show resolved Hide resolved
.changeset/shy-dots-prove.md Outdated Show resolved Hide resolved
.changeset/shy-dots-prove.md Outdated Show resolved Hide resolved
.changeset/shy-dots-prove.md Outdated Show resolved Hide resolved
const view = sharedTree.viewWith(config);

// Does not compile since setter for root is typed `never` due to imprecise schema.
view.root = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious: what does the error look like in this case? Is it intelligible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its cannot assign [] to never I believe. I know what that means, but not sure if others would.

* @see {@link Input}
*
* @typeparam TSchema - Schema to process.
* @typeparam TResult - Do not specify: default value used as implementation detail.
Copy link
Contributor

Choose a reason for hiding this comment

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

I take it there is no reasonable way for us to hide these parameters that we strictly want to be inferred? I can't think of one, but you know TypeScript's generics way better than I do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding extra dummy parameters is just a way to have variables in these type computations which can be reused. I think its cleaner than making an additional "inner" type which we also would have to export. We could also just copy past the expression into every use site.

I don't find either of those workarounds better, but they are options we could take instead.

In this specific case though these docs are stale and there is no such parameter: oops!

@@ -229,13 +229,15 @@
"typeValidation": {
"broken": {
"TypeAlias_InsertableTreeFieldFromImplicitField": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sanity check: these are all @system or @internal exports?

Copy link
Contributor Author

@CraigMacomber CraigMacomber Oct 24, 2024

Choose a reason for hiding this comment

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

Type tests are basically meaningless for generic types since they just pass in any, and we don't actually define what using a schema of any is supposed to result in. There are real and important breaking changes that these do not catch (like those called out in the changeset: type tests didn't detect those), and non breaking changes (like adding a defaulted parameter you aren't allowed to use) which it considers breaking (as is the case for this one).

And no, these are not all system. This one is just public for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, @internal types won't be included here since they are filtered based on release tag. We have some public type exported in the InternalTypes module, but those are not actually @internal just a flawed attempted to try and make systems types not get mixed in with the others.

Copy link
Contributor

@Josmithr Josmithr left a comment

Choose a reason for hiding this comment

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

Left a handful of suggestions and questions. Biggest question: how confident are we that the type-wise breaking changes made here will not disrupt the majority of users?

@CraigMacomber
Copy link
Contributor Author

Left a handful of suggestions and questions. Biggest question: how confident are we that the type-wise breaking changes made here will not disrupt the majority of users?

It's hard to tell. It did break our in repo ai-collab code, but it's doing non-schema aware editing. I don't really know how many people are doing things that we never intended to support and are unsafe. I'll do a test build and try it in the examples repo.

Copy link
Contributor

@alexvy86 alexvy86 left a comment

Choose a reason for hiding this comment

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

Didn't go through the functional changes, just looked at the changesets and left a couple of suggestions, but they otherwise look good. Definitely worth getting more approvals, particularly from API council given the breaking change.

.changeset/shy-dots-prove.md Outdated Show resolved Hide resolved
.changeset/shy-dots-prove.md Outdated Show resolved Hide resolved
.changeset/shy-dots-prove.md Outdated Show resolved Hide resolved
@CraigMacomber
Copy link
Contributor Author

Left a handful of suggestions and questions. Biggest question: how confident are we that the type-wise breaking changes made here will not disrupt the majority of users?

It's hard to tell. It did break our in repo ai-collab code, but it's doing non-schema aware editing. I don't really know how many people are doing things that we never intended to support and are unsafe. I'll do a test build and try it in the examples repo.

I have done the test integration into the examples repo. It has some preexisting problems, but I don't see anything new from these changes.

Copy link
Contributor

🔗 No broken links found! ✅

Your attention to detail is admirable.

linkcheck output


> [email protected] ci:linkcheck /home/runner/work/FluidFramework/FluidFramework/docs
> start-server-and-test ci:start 1313 linkcheck:full

1: starting server using command "npm run ci:start"
and when url "[ 'http://127.0.0.1:1313' ]" is responding with HTTP status code 200
running tests using command "npm run linkcheck:full"


> [email protected] ci:start
> http-server ./public --port 1313 --silent


> [email protected] linkcheck:full
> npm run linkcheck:fast -- --external


> [email protected] linkcheck:fast
> linkcheck http://localhost:1313 --skip-file skipped-urls.txt --external

Crawling...

Stats:
  436034 links
    3364 destination URLs
       2 URLs ignored
       0 warnings
       0 errors


@CraigMacomber CraigMacomber merged commit 645b9ed into microsoft:main Oct 29, 2024
30 checks passed
@CraigMacomber CraigMacomber deleted the contra-schema branch October 29, 2024 20:02
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.

5 participants