Repository navigation
feat: type a pipeline in an unanchored stack against the enclosing context - #55
Draft
johnstonmatt wants to merge 2 commits into
Conversation
commit: |
…ntext `Middleware` and `Composite` keep the enclosing keys on their handler parameter while their own upstream is still being inferred (`Upstream<Base>`). A `pipeline` written as their handler argument then sees those keys with no anchor, and nesting catches a duplicate key with no `satisfies FetchHandler`. The propagation overloads also check a prerequisite's type in the direction the optional-key constraint can't (`NoMismatch`), so a provider of the wrong type two layers up fails to compile. With these handler types, nesting a middleware inside one with a hand-written generic signature fails to type-check before TypeScript 5.9. The test `a middleware with a hand-written signature` fails there by design, until `withSupabase` and `withOpenFeature` are typed with the engine's own types. Refs FUNC-1177
The README, the authoring guide, the skill and the core README say that `ctx` accumulation, collision detection and a `pipeline` in a middleware's handler argument need no anchor, and that `satisfies FetchHandler` asserts the stack can be the `fetch` export. Refs FUNC-1177
johnstonmatt
force-pushed
the
FUNC-1177/middleware/pipeline-handler-position
branch
from
November 27, 2026 21:36
56aded2 to
6619f4f
Compare
johnstonmatt
changed the base branch from
main
to
FUNC-1185/middleware/pipeline-anchored-stack
November 27, 2026 21:36
This was referenced Nov 28, 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
Stacked on #56, which types a
pipelineagainst the enclosing context when the stack is anchored. This PR removes the need for the anchor: apipelinewritten as a middleware's or composite's handler argument sees the keys around it in any stack written as one expression.Why the unanchored form fails without this:
Nested stacks without
satisfies FetchHandlernow infer the way anchored ones do, so they also catch a duplicate key. There are no new exports.Hand-written signatures
Nesting a middleware inside one that publishes a hand-written generic signature, such as
withSupabase, fails to type-check before TypeScript 5.9 with these handler types:Before 5.9, TypeScript passes the outer signature's unresolved
Baseinto the inner call, whereUpstreamandNoMismatchcan't be evaluated. That coversdeno checkon Deno 2.0 to 2.4, and Edge Functions' runtime is built on Deno 2.1.4. Middleware typed with the engine's ownMiddlewareandCompositetypes nest correctly on every version from 5.4. So this ships no earlier than a@supabase/serverrelease with supabase/server#209, which typeswithSupabasewith the engine'sComposite. Nesting insidewithOpenFeaturewithout an anchor already fails on 5.4 to 5.8 with 1.0.0, so this doesn't make it worse. Third-party middleware written with the authoring guide's hand-written-signature variant still break; whether this ships anyway is the open decision in FUNC-1186.Evidence
pipeline.test.ts,define-middleware.test.tsanddefine-composite.test.ts:typecheck(TS 5.9),typecheck:consumer, lint, Prettier,check-exports, the docs build and 154 vitest tests pass.typecheck:min(TS 5.4) fails on one test,a middleware with a hand-written signature, by design. The repo typechecks with no other errors on TypeScript 5.4 to 5.8, and with none at all on 5.9.2, 5.9.3, 6.0.3 and 7.0.2.@supabase/server: source and testswithSupabasefail, as they do on 1.0.0@supabase/server: examples, e2e@supabase-labs/middleware-openfeaturedeno checkof a function nesting a middleware insidewithSupabase, with@supabase/serversharing this build: fails on Deno 2.1.4 and 2.4.5, passes on 2.5.0 and 2.9.8. The same function bundles and serves in edge-runtime v1.79.5 (the image Supabase CLI v3.4.0 uses), with responses identical to 1.0.0: types only.withSupabasetyped as aComposite, and with a plainMiddlewareouter, a nested middleware, a nestedwithPostgresClientand apipelineas the handler argument all type-check on TypeScript 5.4 to 7.0.main: anchored nesting 3,647 → 4,234 (+16%), nesting without an anchor 9,616 → 5,901 (−39%),pipeline11,602 → 14,413 (+24%), composite 10,699 → 12,095 (+13%). Check time stays under 0.03 s.Merge Danger
Door: two-way
Types only, with no runtime change; reverting restores #56's types.
Blast Radius: types
withSupabaseis covered once feat: type withSupabase with the engine's Composite server#209 is released; a project pinned to an earlier@supabase/serverstill breaks, as do third-party middleware that follow the guide's hand-written-signature variant. Whether this ships anyway is the open decision in FUNC-1186.typecheck:minfails by design until then.envas upstream context (FUNC-1184).Refs FUNC-1177