Add post function to templateHandler - #15
Open
jannikluhn wants to merge 1 commit into
Open
jannikluhn wants to merge 1 commit into
jannikluhn wants to merge 1 commit into
Conversation
…into one
`SignalHandler` has had `post` all along, and the template Handler's own doc
comment sold the workaround: `{ ...templateHandler(options), post }` is a
Handler. It is, and it is worse than it reads.
The spread drops the payload type. `TPayload` reaches `session` and `data`, but
a `post` written outside the call is typed by the map it lands in, which is
`Record<string, SignalHandler>` and so `Signal<unknown>`. The Operator has to
re-annotate the signal by hand, naming a type the other options never made them
name, and an annotation that is wrong is an assertion about a payload nothing
checked. The spread also works only because `handle` never touches `this`,
which nothing enforces and nothing tests, so an implementation detail had
become part of the contract.
So `post` is an option, carried to the Worker as written. Nothing wraps it and
nothing calls it from here: the same argument that keeps `session` and `data`
outside the try/catch keeps this outside it too, because putting our sentence
about a template on somebody else's bug is what that argument is against. The
Worker already records it as `the post phase failed: ...`. The spread still
works and is now the long way round.
It is spread into the returned object rather than assigned, because
`exactOptionalPropertyTypes` refuses an explicit `undefined` against `post?`,
and because a Handler given no post phase must not carry the property at all:
the Worker asks `handler.post !== undefined` before running one, so the two
spellings are not the same Handler. That absence is the assertion with teeth
and it is the first of the new tests.
The rest are the two outcomes a template Handler can reach, through a real
worker: `failed: false` after a Run that ran, and `failed: true` for a template
that did not render and so produced no Run at all, which is the case a post
phase is written for, a Signal never being retried. And a throwing post phase,
whose words reach the Signal log as its own, saying nothing about a template
that rendered perfectly well.
`scripts/check-package.ts` carries the option in the annotated `main.ts` and
reads `signal.payload.userId` in it, so the narrowing is proved from the
installed package and not only in this tree.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #7