Repository navigation
feat(worker)!: the handler leaf takes helpers first, message second #671
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8e9e7d5
feat(worker)!: the handler leaf takes helpers first, message second
btravers c83c0a2
feat(worker): hand the handler its retry constructors, and finish the…
btravers 56736e9
feat(worker)!: the message rides the helpers record too
btravers 3f89ca6
feat(worker)!: the record is the spelling, and its message is `input`
btravers 52fd92a
fix(worker): finish the `input` rename, and make the identity gate bite
btravers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| --- | ||
| "@amqp-contract/worker": major | ||
| --- | ||
|
|
||
| Handlers take **one record** — `{ input, context, errors, raw, retryable, | ||
| nonRetryable }`, where `input` is the validated `{ payload, headers }` — with | ||
| that message repeated as a second positional parameter. It was | ||
| `({ payload, headers }, rawMessage, { context, errors })`: the raw amqplib | ||
| delivery moved onto the record as `raw`, and the message is reachable from | ||
| either place. | ||
|
|
||
| oRPC is the reference shape for this family, being the most widely used of the | ||
| three transports a `@btravstack/*` application composes: a developer arriving | ||
| here has more likely seen `({ errors, input })` than either of the others — | ||
| down to the word, since oRPC's `ProcedureHandlerOptions` carries `input` and | ||
| its handler still takes it positionally, which is exactly the pair of spellings | ||
| offered here. The mint and compose calls already agreed across the three; the leaf a | ||
| developer types by hand did not, and it is the one they relearn per transport. | ||
| `@temporal-contract`'s activity leaf moves with it. | ||
|
|
||
| It is also what makes the AMQP triage site the same SHAPE as the other two, and | ||
| that half is not cosmetic: `retryable` and `nonRetryable` ride the helpers | ||
| record beside `errors`, so a handler that wants "infrastructure comes back" | ||
| reaches for the constructor it was handed instead of importing `RetryableError` | ||
| and constructing it by hand. | ||
|
|
||
| ```ts | ||
| processOrder: ({ retryable, input: { payload } }) => | ||
| fromPromise(save(payload), (cause) => retryable("database unavailable", cause)), | ||
| ``` | ||
|
|
||
| They sit BESIDE `errors` rather than inside it: `errors` is the | ||
| contract-declared error map — `errors.ORDER_NOT_FOUND({ orderId })` — which is | ||
| what it means on the other two transports, and folding the framework's own two | ||
| into that namespace would both break the mirror and collide with a declared code | ||
| called `retryable`. | ||
|
|
||
| ```diff | ||
| - processOrder: ({ payload }) => save(payload), | ||
| + processOrder: ({ input: { payload } }) => save(payload), | ||
| - handleFailed: ({ payload }, rawMessage) => log(rawMessage.properties.headers), | ||
| + handleFailed: ({ raw, input: { payload } }) => log(raw.properties.headers), | ||
| - getOrder: ({ payload }, _raw, { errors }) => lookup(payload, errors), | ||
| + getOrder: ({ errors, input: { payload } }) => lookup(payload, errors), | ||
| ``` | ||
|
|
||
| The message is on the helpers record as well as in the second parameter, which | ||
| is oRPC's own shape — `ProcedureHandlerOptions` carries `input` and the handler | ||
| still takes it positionally — so both spellings are the same call: | ||
|
|
||
| ```ts | ||
| getOrder: ({ errors, input }) => lookup(input.payload, errors), | ||
| getOrder: ({ errors, input: { payload } }) => lookup(payload, errors), | ||
| ``` | ||
|
|
||
| A handler that reads its payload fails to compile until it is swapped, since | ||
| the first parameter is the helpers record now; one that ignores its message | ||
| keeps compiling with a parameter whose name lies — grep the handlers object for | ||
| a leaf whose first parameter is neither `_` nor a helpers destructuring. A | ||
| handler that wants only its message is `({ input: { payload } }) => ...`, with no placeholder to spell. | ||
|
|
||
| Closes #670. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.