Skip to content

feat: flat pipeline syntax — mw(config) returns an Entry directly - #9

Merged
johnstonmatt merged 4 commits into
mainfrom
feat/flat-pipeline-syntax
Jul 2, 2026
Merged

feat: flat pipeline syntax — mw(config) returns an Entry directly#9
johnstonmatt merged 4 commits into
mainfrom
feat/flat-pipeline-syntax

Conversation

@mandarini

@mandarini mandarini commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds pipeline() and flat entry syntax to @supabase/web-middleware.

pipeline(entries, handler) composes an ordered list of middleware entries around a handler. Each entry is created by calling a middleware with its config — no handler argument:

import { pipeline } from '@supabase/web-middleware'

export default {
  fetch: pipeline(
    [withCors({}), withFeatureFlag({ name: 'beta' })],
    async (req, ctx) => {
      ctx.cors       // from withCors
      ctx.flag       // from withFeatureFlag
      return Response.json({ ok: true })
    },
  ) satisfies FetchHandler,
}

mw(config) with no handler returns an Entry — the unit that pipeline accepts. The rule: if the last argument is not a function, return an Entry.

What changed

  • src/core/types.tsEntry<Key, In, Contribution> and ConfigArgs<Config> added here so both defineMiddleware and pipeline can import them
  • src/core/define-middleware.ts — added config-only overload: mw(config)Entry
  • src/core/pipeline.ts — new file; pipeline(entries, handler) folds entries right-to-left so the first entry is outermost
  • src/core/pipeline.test.ts — new test file
  • Exports and README updated

Try it

npm i https://pkg.pr.new/supabase/web-middleware/@supabase/web-middleware@9

Merge order

@mandarini mandarini changed the title Feat/flat pipeline syntax @mandarini feat: flat pipeline syntax — mw(config) returns an Entry directly Jul 1, 2026
@mandarini mandarini changed the title @mandarini feat: flat pipeline syntax — mw(config) returns an Entry directly feat: flat pipeline syntax — mw(config) returns an Entry directly Jul 1, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/supabase/web-middleware/@supabase/web-middleware@9

commit: 9c2db60

@johnstonmatt

Copy link
Copy Markdown
Collaborator

awesome!

@johnstonmatt
johnstonmatt merged commit 537f5ed into main Jul 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants