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: Improve non-schema aware typing #22763

Merged
merged 29 commits into from
Oct 22, 2024

Conversation

CraigMacomber
Copy link
Contributor

Description

See changeset

Breaking Changes

See changeset

Reviewer Guidance

The review process is outlined on this wiki page.

This is a rather risky change, as it could break some use-cases due to typing changes. These are use cases we never really intended to support, and there should be alternatives, but this could cause some breakage when integrating.

Extra care should be given to evaluating if this is ok to release in a minor version. A prerelease build, and testing by some representative customers would likely be a good idea.

@CraigMacomber CraigMacomber requested review from a team as code owners October 8, 2024 23:46
@github-actions github-actions bot added area: contributor experience 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 8, 2024
.vscode/settings.json Outdated Show resolved Hide resolved
@@ -19,7 +20,7 @@ import type { InternalTreeNode, Unhydrated } from "./types.js";
export type TreeNodeSchema<
Name extends string = string,
Kind extends NodeKind = NodeKind,
TNode = unknown,
TNode extends TreeNode | TreeLeafValue = TreeNode | TreeLeafValue,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is really the main part of this change. Pretty much everything else is done to allow this change to take place.

@msfluid-bot
Copy link
Collaborator

msfluid-bot commented Oct 9, 2024

@fluid-example/bundle-size-tests: +305 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 459.85 KB 459.89 KB +35 Bytes
azureClient.js 557 KB 557.04 KB +49 Bytes
connectionState.js 724 Bytes 724 Bytes No change
containerRuntime.js 259.47 KB 259.48 KB +14 Bytes
fluidFramework.js 405.81 KB 405.85 KB +44 Bytes
loader.js 134.16 KB 134.18 KB +14 Bytes
map.js 42.46 KB 42.46 KB +7 Bytes
matrix.js 148.29 KB 148.29 KB +7 Bytes
odspClient.js 523.96 KB 524 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.48 KB 164.49 KB +7 Bytes
sharedTree.js 396.27 KB 396.31 KB +37 Bytes
Total Size 3.31 MB 3.31 MB +305 Bytes

Baseline commit: 5c17a9c

Generated by 🚫 dangerJS against 0160982

.changeset/shiny-swans-relax.md Outdated Show resolved Hide resolved
packages/dds/tree/src/simple-tree/api/tree.ts Show resolved Hide resolved
packages/dds/tree/src/simple-tree/arrayNode.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/simple-tree/schemaTypes.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/simple-tree/schemaTypes.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/simple-tree/schemaTypes.ts Outdated Show resolved Hide resolved
@@ -83,6 +142,14 @@ export type TreeFieldFromImplicitFieldUnsafe<TSchema extends Unenforced<Implicit
? TreeNodeFromImplicitAllowedTypesUnsafe<TSchema>
: unknown;

/**
* {@link Unenforced} version of {@link AllowedTypes}.
* @remarks
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessarily for this PR, but should we add similar notices to the existing Unsafe types here as well?

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 redundant with the system tag: I'd prefer a more general/automated solution to convey that to intelisense users.

@@ -381,15 +382,25 @@ export type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema;
export type ImplicitFieldSchema = FieldSchema | ImplicitAllowedTypes;

/**
* Converts ImplicitFieldSchema to the corresponding tree node's field type.
* Converts an `ImplicitFieldSchema` to a property type suitable for reading a field with this that schema.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this type be @system?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making this system would be a breaking change (it removes app's ability to use this), so we can't do that, regardless of if we think apps need it.

/**
* Map a generic function over an array, assuming that this is a well defined operation.
* @remarks
* This is useful for when a collection of generic interface value with differing values for their type parameter got collected in a single type erased array, but you want to process them generically.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit hard to parse, IMO. Might be worth restructuring a bit.

@@ -183,7 +184,10 @@ export class SharedTreeBranchManager {
switch (diff.type) {
case "CHANGE":
case "CREATE": {
targetObject.set(diff.path[diff.path.length - 1] as string, diff.value);
// This code is doing non-schema aware editing, which is not a supported feature of this API.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we leave a TODO to not do this? Or is this intentional and desired? Not clear to me from the docs.

Copy link
Contributor Author

@CraigMacomber CraigMacomber Oct 21, 2024

Choose a reason for hiding this comment

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

I don't have a lot of context on this ai-collab code. My understanding was that we don't support non-schema aware editing, but this code is doing exactly that. We should probably do one of:

  1. support such a use case
  2. stop depending on such usage
  3. decide this code is a kludge

This package was added after I created this PR, and does not compile with my changes, so I looked at why and found it doing things we do not support which are now correctly blocked from compiling.

I this package is believe based on FHL work. Someone who owns this is going to need to provide some guidance here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Decent chance it's #3. Not sure if the way we're headed (what we're calling the "explicit approach") we'll still need this code. @seanimam might be able to comment. If we keep the code, I suspect we'll want to figure out how to make this schema-aware.

CraigMacomber and others added 2 commits October 21, 2024 14:40
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.

ai-collab changes are fine

.changeset/shiny-swans-relax.md Outdated Show resolved Hide resolved
.changeset/shiny-swans-relax.md Outdated Show resolved Hide resolved
.changeset/shiny-swans-relax.md Outdated Show resolved Hide resolved
.changeset/shiny-swans-relax.md Outdated Show resolved Hide resolved
@@ -105,6 +105,6 @@ export class SharedTreeBranchManager {
export function sharedTreeDiff(obj: Record<string, unknown> | unknown[], newObj: Record<string, unknown> | unknown[], options?: Options, _stack?: (Record<string, unknown> | unknown[])[]): Difference[];

// @alpha
export function sharedTreeTraverse<T = unknown>(jsonObject: TreeMapNode | TreeArrayNode | Record<string, unknown> | unknown[], path: ObjectPath): T | undefined;
export function sharedTreeTraverse<T = unknown>(jsonObject: TreeMapNode | TreeArrayNode | Record<string, unknown>, path: ObjectPath): T | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

No issues here. Besides being an @alpha API, we're in the process of redesigning this library's whole API anyway.

@@ -183,7 +184,10 @@ export class SharedTreeBranchManager {
switch (diff.type) {
case "CHANGE":
case "CREATE": {
targetObject.set(diff.path[diff.path.length - 1] as string, diff.value);
// This code is doing non-schema aware editing, which is not a supported feature of this API.
Copy link
Contributor

Choose a reason for hiding this comment

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

Decent chance it's #3. Not sure if the way we're headed (what we're calling the "explicit approach") we'll still need this code. @seanimam might be able to comment. If we keep the code, I suspect we'll want to figure out how to make this schema-aware.

@CraigMacomber
Copy link
Contributor Author

I'm skipping the code coverage check since only simple-tree/api (the folder) regressed, and no files regressed. I'm going to assume this is because typesUnsafe.ts is longer, and the tool seems to consider it uncovered since its entirely type definitions.

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:
  428384 links
    3310 destination URLs
       2 URLs ignored
       0 warnings
       0 errors


@CraigMacomber CraigMacomber merged commit 05197d6 into microsoft:main Oct 22, 2024
30 checks passed
@CraigMacomber CraigMacomber deleted the BetterTypes2 branch October 22, 2024 19:31
CraigMacomber added a commit that referenced this pull request Oct 30, 2024
…22938)

## Description

This improves on #22763 to be slightly more specific in the case of
TreeNodeSchemaClass with an unspecified TNode parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: contributor experience 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