-
Notifications
You must be signed in to change notification settings - Fork 534
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
Conversation
@@ -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, |
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 is really the main part of this change. Pretty much everything else is done to allow this change to take place.
⯅ @fluid-example/bundle-size-tests: +305 Bytes
Baseline commit: 5c17a9c |
Co-authored-by: Noah Encke <[email protected]>
Co-authored-by: Noah Encke <[email protected]>
@@ -83,6 +142,14 @@ export type TreeFieldFromImplicitFieldUnsafe<TSchema extends Unenforced<Implicit | |||
? TreeNodeFromImplicitAllowedTypesUnsafe<TSchema> | |||
: unknown; | |||
|
|||
/** | |||
* {@link Unenforced} version of {@link AllowedTypes}. | |||
* @remarks |
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.
Not necessarily for this PR, but should we add similar notices to the existing Unsafe
types here as well?
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.
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. |
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.
Should this type be @system
?
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.
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. |
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 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. |
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.
Should we leave a TODO to not do this? Or is this intentional and desired? Not clear to me from the docs.
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.
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:
- support such a use case
- stop depending on such usage
- 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.
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.
Co-authored-by: Joshua Smithrud <[email protected]>
Co-authored-by: Joshua Smithrud <[email protected]>
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.
ai-collab changes are fine
@@ -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; |
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.
No issues here. Besides being an @alpha
API, we're in the process of redesigning this library's whole API anyway.
packages/framework/ai-collab/src/shared-tree-diff/sharedTreeBranchManager.ts
Outdated
Show resolved
Hide resolved
@@ -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. |
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.
Co-authored-by: Alex Villarreal <[email protected]>
Co-authored-by: Joshua Smithrud <[email protected]>
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. |
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output
|
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.