Repository navigation
feat: add withTiming middleware - #71
Open
johnstonmatt wants to merge 2 commits into
Open
johnstonmatt wants to merge 2 commits into
johnstonmatt wants to merge 2 commits into
Conversation
Add `@supabase/middleware/timing`. `withTiming` contributes `ctx.timing`: `mark()` ends the entry for the middleware that ran before the handler, and `measure(name, fn)` times named calls such as database queries, summing calls that share a name. On the way out it appends the entries to `Server-Timing`, timed with `performance.now()`.
The authoring guide's response-seam variant now walks through the built-in `withTiming` rather than a standalone sketch, and every list of built-ins names timing alongside feature-flag and cors.
commit: |
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
Adds
withTiming, a third built-in, at@supabase/middleware/timing. It adds the time only the function can see to the response'sServer-Timingheader, alongside the entries platform hops add: the time spent in the middleware before the handler, and the time spent in named calls such as database queries.The subpath is wired into
package.json,tsdown.config.ts,jsr.jsonandtypedoc.json. The authoring guide's response-seam variant now walks through the realwithTimingrather than a standalone sketch, and every list of built-ins names it. The repository still takes no new middleware; timing is one of its worked examples.Evidence
import { withTiming } from '@supabase/middleware/timing'doesn't resolve; the guide'swithTimingonly stamped a singletotalentry.After:
pnpm testpasses 135 tests, 11 of them new inwith-timing.test.tsagainst a hand-driven clock:pnpm build && pnpm smokeloads all 8 entrypoints, includingok esm ./timingandok cjs ./timing;pnpm check-exports,pnpm typecheck,pnpm lintandpnpm format:checkare clean. The Deno, Bun and Workers runtime suites weren't run locally.Merge Danger
Door: one-way
A new public subpath after 1.0. Once released, removing
/timingor changingctx.timing's shape is a breaking change. Merging alone is two-way: revert before the release-please PR ships it.Blast Radius: additive
Nothing existing changes behavior. Consumers who don't import
/timingload none of it: it's its own entry behind"sideEffects": false. Thefeat:commit makes the next release a minor.