Skip to content

feat: name enum query parameter types - #108

Merged
BYK merged 2 commits into
mainfrom
feat/query-enum-types
Oct 23, 2026
Merged

BYK merged 2 commits into
mainfrom
feat/query-enum-types

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Each enum-valued query parameter now gets a named type for one of its values, called <Operation>Query<Parameter>. For array parameters, it's the element type:

import type {
  ListOrganizationTraceItemAttributesQueryAttributeType, // "array" | "boolean" | "number" | "string"
  ListOrganizationTraceItemAttributesQueryDataset,       // "logs" | "preprod" | "processing_errors" | "spans" | "tracemetrics"
} from "@sentry/api";

The spec is dereferenced, so the generator inlines these enums in each operation's <Operation>Data type. Consumers currently have to dig them out by hand. getsentry/toolkit#1559 does exactly that:

type TraceItemAttributeValueType = NonNullable<
  NonNullable<ListOrganizationTraceItemAttributesData["query"]>["attributeType"]
>[number];

With these types, consumers import the name instead and no longer redeclare the shape themselves.

How it works

  • scripts/generate-query-enum-types.mjs runs after generate-error-results.mjs. It maps each sdk.gen.ts operation to its route the same way that script does, and writes src/query-enums.gen.ts.
  • Each alias derives from the existing <Operation>Data type rather than copying the enum values, so it can't drift from what the operation accepts.
  • The root entry adds export type * from './query-enums.gen.ts'. It's type-only, so the bundle doesn't change.
  • The build fails if an alias collides with an existing types.gen.ts export or with another alias. The Query infix keeps the names clear of the generator's Data, Error(s) and Response(s) suffixes.

The current spec produces 64 aliases across 36 operations. test/typecheck.ts checks a valid and an invalid dataset, and that the array parameter's alias is the element type. The README gains a short "Query parameter types" section.

Ran bun run build, bun run typecheck, bun test (163 pass) and bun run test:node.

via BYK.

--

View Junior Session in Sentry

Generate a type for each enum-valued query parameter, named
<Operation>Query<Parameter>, e.g.
ListOrganizationTraceItemAttributesQueryDataset. Array parameters name
their element type. These enums are inlined in each <Operation>Data type,
so consumers had to derive them with NonNullable<...['query']>[...].

Co-Authored-By: BYK <burak.kaya@sentry.io>
Comment thread scripts/generate-query-enum-types.mjs Outdated
Read operations and their Data types from the sdk.gen.ts and types.gen.ts
ASTs instead of matching source text with regexes, like
generate-client.mjs and constrain-throw-options.mjs do. Fail the build
when an operation has an unexpected shape or a spec enum parameter is
missing from its Data['query'] type, instead of skipping it silently.
@BYK
BYK merged commit ca9a742 into main Oct 23, 2026
10 checks passed
@BYK
BYK deleted the feat/query-enum-types branch October 23, 2026 21:55
BYK added a commit to getsentry/toolkit that referenced this pull request Oct 23, 2026
Upgrades the CLI's `@sentry/api` dependency from `^0.356.0` to
`^0.399.0`, the release that includes getsentry/sentry-api-schema#108.
That release exports a named type for every enum-valued query parameter,
such as `ListOrganizationTraceItemAttributesQueryDataset`, so callers no
longer need to derive them with `NonNullable<…["query"]>`. #1559 will
switch its trace-item attribute types to these once this lands.

The lockfile change only covers `@sentry/api`. `pnpm-workspace.yaml`
moves the `minimumReleaseAgeExclude` entry to the new version, because
0.399.0 was published today.

Two schema changes between 0.356.0 and 0.399.0 broke existing tests.
Both changes match Sentry's current behavior, so the tests were updated
rather than the code:

- **Sentry App components:** the organization endpoint now returns a
required `installationUuid` (getsentry/sentry#127591). The CLI validates
this response against the schema, so the `issue-app-links` test fixture
now includes the field; without it, all 37 issue-link tests failed. The
org endpoint always passes `installation_uuids` to the serializer, so
live responses always include the field. Self-hosted servers older than
that change will fail this validation.
- **Replay fields:** the replay index now accepts every replay response
field, including `replay_type`, because the field list comes from
`ReplayDetailsResponse` (getsentry/sentry#128518). The two tests that
expected `replay_type` to be rejected now check a field that isn't in
the schema, `device.model_id`.

Verification: typecheck and lint pass. CLI tests: 11,295 passed and 6
failed. The 6 failures are permission tests that also fail on a clean
`main` in my sandbox (completions, code-scanner, file-changes,
telemetry, upgrade).

<!-- junior-request-attribution:start -->
via **BYK**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A7fba2603229556152deec3d2 -->

--

[View Junior Session in
Sentry](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A7fba2603229556152deec3d2/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <burak.kaya@sentry.io>
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