Skip to content

feat(promql): typed duration builders (seconds/minutes/.../duration)#96

Merged
pyramation merged 1 commit into
mainfrom
feat/promql-duration-builders
Jul 18, 2026
Merged

feat(promql): typed duration builders (seconds/minutes/.../duration)#96
pyramation merged 1 commit into
mainfrom
feat/promql-duration-builders

Conversation

@pyramation

Copy link
Copy Markdown
Contributor

Summary

Adds typed duration builders to promql-ast so callers never hand-assemble PromQL duration syntax with string interpolation (e.g. `${n}s`). The syntax now lives in the package, which is the whole point of the AST.

import { rate, range, metric, seconds, minutes, duration } from 'promql-ast';

range(metric('x'), seconds(60));       // x[60s]
range(metric('x'), minutes(5));        // x[5m]
duration({ h: 1, m: 30 });             // '1h30m'

New exports: seconds, minutes, hours, days, weeks, years, milliseconds, and the composite duration({ y,w,d,h,m,s,ms }) (throws on an empty spec). A branded Duration type is added; range / subquery / offset now take Duration instead of string.

Backwards compatible: Duration's brand is optional, so existing call sites passing plain string literals (range(sel, '5m')) still typecheck.

Version bump 0.2.1 → 0.3.0.

Tests

+3 tests (duration composition, empty-spec rejection, range(metric, seconds(60))x[60s]). Full suite 51 green; tsc clean; makage build (CJS+ESM) green.

Follow-up

constructive-db#2275's collector will use seconds() for its rate window instead of `${rateWindowSeconds}s` once this is published.

Link to Devin session: https://app.devin.ai/sessions/16409487e97d44828dfb46277767604b
Requested by: @pyramation

@pyramation pyramation self-assigned this Jul 18, 2026
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@pyramation
pyramation merged commit 85c1fd5 into main Jul 18, 2026
48 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.

1 participant