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: Promote schemaCreationUtilities to beta #20035

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

CraigMacomber
Copy link
Contributor

@CraigMacomber CraigMacomber commented Mar 8, 2024

Description

Promote schemaCreationUtilities to beta, and a bit of polish for their API and docs.

This is not targeting FF 2.0: it can get stabilized later (if ever).

Reviewer Guidance

The review process is outlined on this wiki page.

@CraigMacomber CraigMacomber requested a review from a team as a code owner March 8, 2024 19:16
@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree public api change Changes to a public API base: main PRs targeted against main branch labels Mar 8, 2024
@@ -61,32 +66,49 @@ export function singletonSchema<TScope extends string, TName extends string | nu
* Converts an enum into a collection of schema which can be used in a union.
* @remarks
* Currently only supports `string` enums.
* The string value of the enum is used as the name of the schema: ensure that its stable and unique.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
* The string value of the enum is used as the name of the schema: ensure that its stable and unique.
* The string value of the enum is used as the name of the schema: you must ensure that its stable and unique.

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 don't think there is a clear "you" here (ex: neither of us as reviewers or implementers are the "you"). Perhaps "callers" would make more sense?

export function adaptEnum<
TScope extends string,
const TEnum extends Record<string, string | number>,
>(factory: SchemaFactory<TScope>, members: TEnum) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add an explicit return type here? That is required by our all of our non-minimal (now deprecated) eslint configs.

Copy link
Contributor

@Josmithr Josmithr Mar 8, 2024

Choose a reason for hiding this comment

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

+ the other functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Omitting it here was intentional. Specifying the return the here is messy since it can't refer to any of the typers in the function. Additionally doing so causes an implicit conversion to this messy hard to maintain type, which I feel is both less type safe, and annoying. For reference the return type here would be

(<TValue extends TEnum[keyof TEnum]>(value: TValue) => TreeNode & {
    readonly value: TValue;
}) & { readonly [Property in keyof TEnum]: TreeNodeSchemaClass<ScopedSchemaName<TScope, TEnum[Property]>, NodeKind.Object, TreeNode & {
        readonly value: TEnum[Property];
    }, never, true, unknown> & (new () => TreeNode & {
        readonly value: TEnum[Property];
    }); };

Given that anyone using this from outside the package will see that due to using the d.ts files, and anyone working on the package can see it in the API report, d.ts files, public docs and intelisense, I just don't see much value from including it in the .ts file explicitly when the current approach lets us express that type as typeof factoryOut & TOut; which is way simpler.

Generally I prefer explicit return types, but when they are a huge mess like this, I think they are more harm than good. I'd rather let the compiler come up with it, then review that (ex: in this PR, where I got that from the api report)

That said, I still see value it the argument for explicit return types: if you do really want them here I can do that, but I think it makes this code less nice of an example of how you can relatively simply write utilities that combine schema as it becomes about equal parts runtime logic and types (which duplicate the same thing).

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 couple of mechanical comments.

The API (based on the example you added) is more complex than seems ideal - mostly, the required call to typedObjectValues when using the union in a schema. Would it be possible to refactor things such that this step isn't required?

Also interested in @nmsimons's thoughts on the API.

@Josmithr Josmithr requested a review from nmsimons March 8, 2024 20:20
Copy link
Contributor

@DLehenbauer DLehenbauer left a comment

Choose a reason for hiding this comment

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

Sorry, beta and public have similar bars with respect to expectations around spec, design reviews, etc.

Consider alpha?

Co-authored-by: Joshua Smithrud <54606601+Josmithr@users.noreply.github.com>
@CraigMacomber
Copy link
Contributor Author

Sorry, beta and public have similar bars with respect to expectations around spec, design reviews, etc.

Consider alpha?

I want the semantics defined here: https://github.com/microsoft/FluidFramework/wiki/Release-Tags#beta (specifically I want feedback from customers, but reserve the ability to change the API).

I do not want the semantics defined for alpha ( https://github.com/microsoft/FluidFramework/wiki/Release-Tags#alpha ) as these APIs do not meet those requirements at all. They are not "currently in use by known partners (with previous agreement), but which we do not plan to support long term." Its the exact opposite of that.

Therefore I think alpha would be very misleading to use here and beta has the exact documented semantics I want. If getting an API to the level of quality where we are allowed to ask for feedback from customers via beta means we need to do some extra work, we can work toward that. Marking them as alpha instead might not require as much quality review, but I don't think alpha is a reasonable shortcut as it sends the exact wrong message (that these are legacy and being removed, have existing users, and don't want feedback).

@CraigMacomber
Copy link
Contributor Author

This is still valid, just waiting for FF 2.1 is its feature work not required for 2.0

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 base: main PRs targeted against main branch public api change Changes to a public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants