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

Deprecate simple objects from endpoints #8132

Merged
merged 3 commits into from
Aug 21, 2023
Merged

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Aug 18, 2023

Changes

  • Deprecate returning simple objects from endpoints
  • Refactor endpoint handling to within callEndpoint. This makes the #endpointHandler convention in Pipeline not used much (only ssrPipeline has a special case) cc @ematipico
  • NOTE: much of the refactor was a port from Refactor endpoint response object handling #7588

Testing

Added test for ResponseWithEncoding, and tests for previous object form so they still work, until they're removed.

Docs

Added changeset. Any mention of the object form in docs might need to be removed.
/cc @withastro/maintainers-docs for feedback!

@bluwy bluwy requested a review from a team as a code owner August 18, 2023 13:28
@changeset-bot
Copy link

changeset-bot bot commented Aug 18, 2023

🦋 Changeset detected

Latest commit: 81a7056

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 18, 2023
Comment on lines 1970 to 1976
export type EndpointOutput =
| {
body: Body;
encoding?: Exclude<BufferEncoding, 'binary'>;
encoding?: BufferEncoding;
}
| {
body: Uint8Array;
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this was a mistake in #8003, we technically only support binary strings, and not binary unit8arrays. We have a test for binary strings and the PR caused a type error.

But simple objects are being deprecated anyways so I don't think it's a big deal.

type: 'simple',
cookies: context.cookies,
};
let body: BodyInit;
Copy link
Member Author

Choose a reason for hiding this comment

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

All the pipeline simple object handling converges into this function starting from this line. This should also make the dev/prod behaviour more consistent.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

I love how much churn we removed, and we consolidated one way to process the responses from the endpoints!

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Looks great, @bluwy !

As for the rest of docs, when you file an issue for this, please add a note there to remind us (inclusive! anyone can jump in here!) to do a "find all" instances of "Response" in the docs, then examine the surrounding context and update any text descriptions or code samples as needed! 🙌

@bluwy bluwy merged commit 767eb68 into next Aug 21, 2023
14 checks passed
@bluwy bluwy deleted the deprecate-endpoint-object branch August 21, 2023 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants