Repository navigation
ref(cli): Check output.schema for commands with jsonTransform - #1869
Merged
Merged
Conversation
With a jsonTransform, output.schema describes the transform's item: each
item of a { data: [...] } envelope or an array, otherwise the result.
The builders now infer the transform's return type and require every
field the schema documents to exist on that item with a matching type.
Optionality isn't compared, since --fields makes items Partial. A
transform that returns unknown no longer matches a schema, and the error
lists the mismatched fields under ~outputMismatch.
Transforms now return typed JSON: ListJson<T> from
jsonTransformListResult, ListEnvelope<T> for hand-built envelopes, and
the spread object's own type for single-object views. OrgListConfig
takes the schema's type and checks the entity against it.
The check found these mismatches:
- span list documented the API's field names (id, span.op, trace, ...)
but emits the renamed ones (span_id, op, trace_id, ...), so --help,
--fields completion, and the skill reference listed fields that never
appear. It now documents the emitted fields with FlatSpanSchema, which
FlatSpan is derived from.
- IssueEvent typed metadata as nullable; it now is the @sentry/api
GroupEventsResponseDict item, as the schema already was.
- ReplayListItem and ReplayDetails typed project_id as string | number,
though the API layer normalizes it to a string.
issue list and project list annotated or checked their output config as
OutputConfig<T>, which erased the schema's type; both are now checked.
Fixes #1860
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
BYK
approved these changes
Nov 3, 2026
7 tasks done
This branch was successfully 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.
Fixes #1860, the follow-up from #1854.
#1854 checked
output.schemaagainst the yielded data, but only for commands withoutjsonTransform. With a transform, the schema describes the transform's item rather thanT, and every transform returnedunknown, so there was nothing to check against.The builders now infer the transform's return type. The item is each element of a
{ data: [...] }envelope or an array, or else the result itself. Every field the schema documents must exist on that item with a matching type. Optionality isn't compared, since--fieldsmakes itemsPartial. A transform that returnsunknownno longer matches a schema. On a mismatch, the error lists only the mismatched fields under~outputMismatch(e.g.{ "~outputMismatch": { b: number } }), not the whole schema.To make the results typed:
jsonTransformListResultreturnsListJson<T>(ListEnvelope<T> | Partial<T>[]).ListEnvelope<Item>.log listreturnsListEnvelope<LogLike> | Partial<LogLike>.Record<string, unknown>annotations and let the spread's type through, usingfilterFieldsIfSet.OrgListConfigtakes the schema's type as a third parameter and checks the entity against it, so team, repo, monitor, and integration list are covered.buildOrgListCommanditself only sees a genericTWithOrgand can't check anything, so it erases the schema type there.issue listandproject listusedOutputConfig<T>as an annotation or withsatisfies. That erased the schema's type, so the check passed without comparing anything. Both are now inferred.The check found these mismatches:
span list: the schema documented the API's field names (id,span.op,span.duration,timestamp,project,trace). The command emits the namesspanListItemToFlatSpangives them (span_id,op,duration_ms,start_timestamp,project_slug,trace_id). As a result,--help,--fieldscompletion, and the skill reference listed fields that never appear in the output. A newFlatSpanSchemadocuments the emitted fields, andFlatSpanis now derived from it. A regression test checks that every key in the JSON output is a documented field. It fails against the old schema.IssueEvent: the hand-written type saidmetadatacould benull. The schema, built from@sentry/api, says it can't.IssueEventis now theGroupEventsResponseDictitem type.ReplayListItem/ReplayDetails: these typedproject_idasstring | number, butlib/api/replays.tsnormalizes it to a string.normalizeReplayProjectIdnow returns that type.The regenerated
span.mdskill reference is included.packages/cli/AGENTS.mddescribes the check and how to type a transform.Transforms without a schema (
api,issue merge,trace view,span view, and others) are unchanged.To confirm the check catches drift, I built throwaway commands that each break one way:
unknown;OrgListConfigentity is missing a field.All six failed to compile. The matching versions, and a transform without a schema, compiled. These weren't kept as tests, because
tsconly coverssrc/.via @BYK.
--
View Session in Sentry