Repository navigation
feat: type a pipeline in an anchored stack against the enclosing context - #56
Draft
johnstonmatt wants to merge 4 commits into
Draft
johnstonmatt wants to merge 4 commits into
johnstonmatt wants to merge 4 commits into
Conversation
`ValidateEntries` checked an entry's prerequisites by key name only, so `pipeline([withAuthAsNumber(), withNeedsAuthAsString()], handler)` compiled. It now also checks each prerequisite's type against the context accumulated so far, and reports `middleware-prereq: key '…' is on the upstream context with an incompatible type` on the handler argument. Refs FUNC-1185
…middleware With no `build` parameter, `defineComposite` inferred `Config` as `unknown`, which collapsed the expected type of the composite's handler argument to `unknown`. On TypeScript 5.9, a middleware call nested there lost the composite's keys. `Config` now defaults to `void`, as it does for a config-less middleware, so passing a config value to such a composite is also a type error. Refs FUNC-1185
A `pipeline` written where a handler is expected now takes its upstream from that position, so its handler sees the keys of the layers around it and its entries are checked against them: a key they already carry is a `middleware-conflict`, and a key they supply meets a prerequisite. That holds in another `pipeline`'s handler argument and in any position typed as a handler. In a middleware's or composite's handler argument it holds once the outermost call is anchored: `satisfies FetchHandler`, a typed declaration, or a host signature such as `Deno.serve`. Unanchored, the pipeline there starts from the empty upstream, as before. A `pipeline` written directly in a host-typed export (`Deno.serve`, a Workers `ExportedHandler`) also keeps the empty upstream, because the host's second parameter is a platform value, not a context. `Middleware` and `Composite` are unchanged, so nesting a middleware inside one with a hand-written signature types as before on every TypeScript version. A new test pins that. Refs FUNC-1185
The README, the authoring guide, the skill and the core README say that a `pipeline` can be a middleware's handler argument and sees the keys around it once the outermost call is anchored, and that a middleware with a hand-written type signature, such as `withSupabase`, goes in the `pipeline` array instead. The `pipeline` API row describes what it returns in a handler position. Refs FUNC-1185
commit: |
This was referenced Nov 27, 2026
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.
Summary
A
pipelinewritten where a handler is expected takes its upstream from that position, so its handler sees the keys of the layers around it and its entries are checked against them. In a middleware's or composite's handler argument that needs the stack anchored:satisfies FetchHandler, a typed declaration, or a host signature such asDeno.serve.MiddlewareandCompositekeep their 1.0.0 types, so nesting a middleware inside one with a hand-written signature, such aswithSupabase, types as before on every TypeScript version. A new test pins that. An unanchored stack such asexport default { fetch: withA(pipeline(…)) }still starts thepipelinefrom the empty upstream; FUNC-1177 covers it.Evidence
main) / After (here), from the new type tests inpipeline.test.tsanddefine-composite.test.ts:typecheck,typecheck:min(TS 5.4),typecheck:consumer, lint, Prettier,check-exports, the docs build, 144 vitest tests, and the Deno, Bun and Workers suites pass.@supabase/server(source, tests, examples, e2e),@supabase-labs/middleware-openfeature, or one internal dependent.deno checkon Deno 2.1.4 (TS 5.6.2), 2.4.5, 2.5.0 and 2.9.8, with@supabase/serversharing this build: the server README's handlers, and a middleware nested insidewithSupabaseand in apipelinewith it, give the same results as 1.0.0. Edge Functions run on edge-runtime, which is built on Deno 2.1.4.Merge Danger
Door: two-way
Types only, with no runtime change; reverting restores 1.0.0's types.
Blast Radius: types
pipelineentry's prerequisite supplied at the wrong type, or an entry repeating a key from an enclosingpipelineor an anchored enclosing middleware.pipelinewritten directly in a host-typed export (satisfies ExportedHandler<Env>,Deno.serve(…)) returnsPromise<Response> | Response, so.thenon a direct call to it no longer compiles.buildtakes no config rejects a config argument.pipelinehovers as(req: Request, ctx?: object) => Promise<Response>rather thanFetchHandler, which is the same type.feat).Refs FUNC-1185