-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(astro:actions): add docs for missing public APIs #12596
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
feat(astro:actions): add docs for missing public APIs #12596
Conversation
✅ Deploy Preview for astro-docs-2 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
|
I think I've done all the changes I noticed here... Sorry for the Github diff: some content was already there but was moved. I'm pinging @florian-lefebvre (no rush!) because I need a technical review to check the accuracy and if some things should be removed in v6, but anyone else is welcome to review this one! I tried to keep a track of all the changes in the first post but there are a lot of changes so I'm not sure how readable/understandable it is. As explained in the issue, I noticed a lack of documentation for all the following imports: import {
ACTION_ERROR_CODES,
ACTION_QUERY_PARAMS,
ActionInputError,
appendForwardSlash,
astroCalledServerError,
callSafely,
deserializeActionResult,
formDataToObject,
getActionQueryString,
serializeActionResult,
type Actions,
type ActionAPIContext,
type ActionAccept,
type ActionClient,
type ActionErrorCode,
type ActionHandler,
type ActionReturnType,
type AstroActionContext,
type SafeResult,
type SerializedActionResult,
} from "astro:actions";So I would need a technical point of view for all of them, with some exceptions listed below:
I added docs for:
And because your issue was specifically about I'm not quite sure about the organization. I documented some properties under their types but maybe it could be more useful under the related function... But, we can think about this later! (If you need direct links to the implementation, they are listed under a EDIT: I was also not sure about an use case for |
|
Thanks a lot! Before reviewing the content, let's agree on what not to document so we can remove them more easily in v6. For me:
That's what I'm thinking but I may be wrong, happy to discuss further! Am I missing something? |
|
Thanks! Except maybe
Oh okay, I'll need your help to describe when this is useful then! 😅
Probably not. It seems the
I'm not sure I see the relationship with
Makes sense! This is what I meant with "I documented some properties under their types but maybe it could be more useful under the related function...", so I agree this is probably not useful.
While users might not need to use it directly, maybe this is still useful to describe the format? ie: Because many functions uses this and so we can link to a single place? |
Sorry yes that's what I meant!
SGTM |
| </p> | ||
|
|
||
| `serializeActionResult()` will serialize an action result to JSON for persistence. This is required to properly handle non-JSON return values like `Map` or `Date` as well as the `ActionError` object. | ||
| Serializes an action result to JSON for persistence. This is required to properly handle non-JSON return values like `Map` or `Date` as well as the `ActionError` object. |
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.
Such nice editing choices! 🙌
sarah11918
left a comment
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.
Just left some comments below based on the text (and not yet looking at deploy preview to make sure all these code blocks render properly etc.).
There is some amazing writing here, and this is shaping up to be super high quality and helpful! Thank you both for the effort on these pages! 🙌
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
florian-lefebvre
left a comment
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.
LGTM thank you!
sarah11918
left a comment
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.
Putting this stuff in the guide feels WAY better, I think! Thank you Armand!
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
|
Thanks @sarah11918 , I pushed a new commit with your two suggestions! I was a bit annoyed to have to repeat more or less the same information before, so I agree this makes more sense. 😄 I let you check the wording, but, yes, this looks better now! |
yanthomasdev
left a comment
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.
LGTM! Amazing work here 🙌
sarah11918
left a comment
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.
Love it! Thank you everyone! Let's Get That Money! 💰
|
Thanks again everyone ❤️ , let's merge this! 🫡 |
| getUserOrThrow: defineAction({ | ||
| accept: 'form', | ||
| handler: async (_, { locals }) => { | ||
| if (locals.user?.name !== 'florian') { |
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.
Sorry that I am little very late to the party and that I criticize here, but is this a good example for "Not authorized". Personally, I find it a little bit confusing that the user is unauthorized, when they are not "florian". I mean, I love such easter eggs in the docs, but I'm not sure if they are maybe too confusing 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.
Lol I completely missed that! I don't have strong opinions on this, I'll let others answer
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'm not an actions expert so I look at examples in the source code. 😅 I don't recall the exact example but I recall I adapt it a bit because the value seemed weird or something like that.
I guess we could update it with something like locals.user?.role !== 'admin' if you think this is better?
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.
Sorry for the delayed answer, but personally I would find the admin check more fitting. However, as I think I might be the only one that was confused by it, we might as well just leave it and if more people complain, we can update it... Would that be fine for you?
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.
Both work for me. But if you find this confusing, feel free to submit a PR to update the example! You may not be the only one, others might be hesitant to report this... So, as long as it's correct, an update can be helpful for others!
Description (required)
getActionContextandgetActionPath.ACTION_QUERY_PARAMSandactions.astro:actionstypes section with docs forActionAPIContext,ActionClient,ActionErrorCode,ActionReturnType, andSafeResult.ActionClient<any, any, any>withActionClientbecause this is always<any, any, any>and it seems to be an implementation detail rather than something useful to the end-user. And because we now have docs for the types, I think it makes it easier to understand.defineAction()type:acceptwas missing while we were documenting it underinput. Not sure if there was a reason for that, maybe we should use the same heading level as the others to avoid any confusion?Types:with a list instead of using an union.code(inActionError) to the newActionErrorCodeheading. And, actually, replace the outdated list with a description of the expected format and an external link.Sincewhen the version is the same as the modulefull>subset).Things we might want to consider
ACTION_ERROR_CODESlist was expanded in ExpandActionErrorcodes to include all IANA HTTP error codes astro#13769 (with some renaming). This list is quite long and I don't think this should be the role of Astro to describe them. Especially since some of them are defined asreserved for future use(e.g.PAYMENT_REQUIRED). If we think otherwise, happy to add back a full list instead.defineAction()andgetActionContext()will throw on the client: https://github.com/withastro/astro/blob/main/packages/astro/src/actions/runtime/client.ts I think the current description could be enough, but maybe we want to be more explicit.Not documented
Based on Florian's feedback, some of the available imports are not documented. I think it's fine (NWTWWHB) and they should be removed in v6.
See the list of undocumented imports
Implementation links
There are a lot of changes, so I tried to keep track of the links to help you review the accuracy of the API blocks (type/since).
I haven't updated those list, so they include undocumented imports too.
Details of the "regular" imports:
appendForwardSlash(): since5.0.6, see fix(actions): support trailing slash astro#12657astroCalledServerError(): no since, it's been there since the Actions stable releasecallSafely(): no since, it's been there since the Actions stable releasedefineAction():acceptisundefined, but onlyformchanges the behavior so I think it's safe to sayjsonis the default here.deserializeActionResult(): no since, it's been there since the Actions stable releaseformDataToObject(): no since, it's been there since the Actions stable releasegetActionContext(): since5.0.0, see Actions middleware astro#12373getActionPath(): since5.1.0getActionQueryString(): no since, it's been there since the Actions stable releaseisActionError(): no since, it's been there since the Actions stable releaseisInputError(): no since, it's been there since the Actions stable releaseserializeActionResult(): no since, it's been there since the Actions stable releaseACTION_ERROR_CODES: no since, it's been there since the Actions stable releaseACTION_QUERY_PARAMS: no since, it's been there since the Actions stable releaseActionError: no since, it's been there since the Actions stable releaseActionInputError: no since, it's been there since the Actions stable releaseDetails of the type imports:
Actions: no since, it's been there since the Actions stable releaseActionAPIContext: no since, it's been there since the Actions stable releaseActionAccept: no since, it's been there since the Actions stable releaseActionClient: no since, it's been there since the Actions stable releaseActionErrorCode: no since, it's been there since the Actions stable releaseActionHandler: no since, it's been there since the Actions stable releaseActionReturnType: no since, it's been there since the Actions stable releaseAstroActionContext: since5.0.0under a different name. Since5.4.2with the current name, see refactor(core): move actions inside core astro#13262SafeResult: no since, it's been there since the Actions stable releaseSerializedActionResult: no since, it's been there since the Actions stable releaseRelated issues & labels (optional)
add new content,improve or update documentation