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

fix: added context with client and schema to slugify and source options #3711

Merged
merged 3 commits into from
Oct 3, 2022

Conversation

snorrees
Copy link
Contributor

@snorrees snorrees commented Oct 3, 2022

Description

Extends the context object passed to options.source and options.slugify with getClient, schema, currentUser (and projectId and dataset for consistency with initial value context).

Also fixes the context type for options.isUnique which was duplicated in the definition, and missing some properties (they where available at runtime already though, via validation context).

This is primarily to make it possible to use the client when using these options; a common thing in v2.

What to review

All the code.

Notes for release

Slug options source and slugify are now passed a context parameter as the last argument. It contains getClient, schema and currentUser.

@vercel
Copy link

vercel bot commented Oct 3, 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 3, 2022 at 9:08PM (UTC)
1 Ignored Deployment
Name Status Preview Comments Updated
studio-workshop ⬜️ Ignored (Inspect) Oct 3, 2022 at 9:08PM (UTC)

) => string | Promise<string>

export type SlugifierFn = (source: string, schemaType: SlugSchemaType) => string | Promise<string>

// TODO: De-dupe with validation types
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TOdone

Copy link
Member

@bjoerge bjoerge left a comment

Choose a reason for hiding this comment

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

Nice! Noted a couple of non-required suggestions for improvement.

@@ -9,12 +9,16 @@ const defaultSlugify = (value: FIXME, type: SlugSchemaType): string => {
return value ? speakingurl(value, slugifyOpts) : ''
}

export function slugify(sourceValue: FIXME, type: SlugSchemaType): Promise<string> {
export function slugify(
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: same as above re: converting async function. I think we want the error to propagate on the returned promise (I do realise that this isn't "new" behavior, so feel free to ignore)

Copy link
Member

Choose a reason for hiding this comment

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

(and by "above" I mean "below" 🙃)

return {parentPath, parent, ...context}
}

function getNewFromSource(
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: make this an async function? That way we make sure that any (current or future) sync errors triggered by either this function or the slugifier call are thrown on the returned promise. As a bonus, the Promise.resolve call in here can be removed too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. Funny seeing eslint fight itself:

image

image

🤷

Copy link
Member

Choose a reason for hiding this comment

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

Seems like we should turn off the require-await rule or replace it with @typescript/require-await which uses type information: https://typescript-eslint.io/rules/require-await/

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