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

Remove schema namespace #3699

Merged
merged 2 commits into from
Oct 4, 2022
Merged

Remove schema namespace #3699

merged 2 commits into from
Oct 4, 2022

Conversation

snorrees
Copy link
Contributor

@snorrees snorrees commented Sep 30, 2022

Description

Replaces the Schema namespace with plain exports.

The contents of the namespace is split into file-per-type in /definitions.
Apart from namespace being gone, this only moves types around; Option types are now located with each type and reused by SchemaTypes where possible.

No attempt was made to improve the SchemaType typings beyond what they are today. This PR is about improving the definition types.

What to review

Does the code-organization look ok?

Notes for release

Schema namespace has been removed. The same types can now be accessed as regular imports from the sanity package.

IntrinsicTypeDefinition was renamed to IntrinsicDefinitions. Module extensions relying on declaration merging to this type must rename the interface.

@vercel
Copy link

vercel bot commented Sep 30, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Oct 4, 2022 at 11:36AM (UTC)
1 Ignored Deployment
Name Status Preview Comments Updated
studio-workshop ⬜️ Ignored (Inspect) Oct 4, 2022 at 11:36AM (UTC)

sortable?: boolean
modal?: {type?: 'dialog' | 'popover'; width?: number | 'auto'}
}
options?: ArrayOptions<V> & {layout?: V extends string ? 'tag' : 'grid'}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to diverge from the definition type here, and narrow layout a bit. This is more correct, but supporting it in the definition is not worth it (need to drill the type of array.of every where via generics)

@@ -0,0 +1,131 @@
import {PreviewConfig} from '../preview'
Copy link
Member

Choose a reason for hiding this comment

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

Hm, actually – this file is already in a directory called definition. Should this file be renamed to types.ts then?

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 have no strong opinion on it.

/**
* A union of all intrinsic types allowed natively in the schema.
*/
export type TypeName = IntrinsicTypeDefinition[keyof IntrinsicTypeDefinition]['type']
Copy link
Member

Choose a reason for hiding this comment

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

IntrinsicDefinitionTypeName?

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 would really like to keep this short, as it is used in a lot of generic contexts. If it is a long name, that reads worse imo.

IntrinsicTypeName perhaps?

Copy link
Member

Choose a reason for hiding this comment

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

I think IntrinsicTypeName makes sense, since it's built from keys of IntrinsicTypeDefinition.

…initions

This fixes naming conflict between namespace and interface, and will make definition type extensions
easier to work with (by declaration merging interfaces in sanity module directly).

Option-definitions is now shared between SchemaTypes and Definition types.

BREAKING CHANGE: Code that accessed types in the Schema namespace must import the types directly instead.
@snorrees snorrees force-pushed the feat/v3/nuke-schema-namespace branch from b155c03 to eaa0923 Compare October 4, 2022 07:56
@snorrees
Copy link
Contributor Author

snorrees commented Oct 4, 2022

Had to recreate the branch since v3 branch was force-pushed or something.

Copy link
Member

@mariuslundgard mariuslundgard left a comment

Choose a reason for hiding this comment

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

LGTM! Namespaces be gone!

@snorrees snorrees deleted the feat/v3/nuke-schema-namespace branch October 4, 2022 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants