Skip to content

Document generic types once by their declaration - #308

Merged
tnkuehne merged 1 commit into
mainfrom
feat/generic-type-declarations
Nov 22, 2026
Merged

tnkuehne merged 1 commit into
mainfrom
feat/generic-type-declarations

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Why

A generic interface or alias was documented once per instantiation. A generated API that types its results through shared generics, such as Page<T> or a selection type over every model, expanded into thousands of copies: a generated GraphQL API of about 900 types needed 127 MiB in the extractor and produced documents far beyond the limits.

The documentation also lost references the checker's types do not carry. An alias in Role | null is flattened into the union, so Role was neither documented nor recorded in uses.

Documents also say nothing about how a type is declared, so declaration files generated from them cannot reproduce interface and type semantics.

What changes

  • Extractor: a generic interface or type alias is documented once as its declaration with its type parameters, named like Page<T>. Signatures keep their instantiated names, such as Page<Item>, and record the declaration in uses. A generic alias prints its own structure, so references inside it keep their names.
  • Extractor: the types named in a declaration's annotations are followed in addition to the checker's types. Signatures use the annotations of their documented parameters, type parameters and return type: method bodies and the parameters the runtime passes to object handlers are not read.
  • Contract: each documented type has kind (interface or type). A generic declaration lists its type parameters with constraints and defaults in typeParameters, such as T extends Item = Item. The documentation format moves to 3. Documentation of an earlier format counts as missing until the app is deployed again.

On the same generated API the extractor needs 52 MiB, and the document has 1.8 MB and 867 types.

Verification

  • pnpm check
  • pnpm exec vitest run apps/control-plane packages
  • RUN_CLI_TESTS=1 CLI suites from the Rust job with a freshly built CLI; the extraction tests now assert Page<T>, A<T>/B<T>, Loop<T>, a generic alias and Role | null
  • RUN_WASM_TESTS=1 pnpm exec vitest run packages/service-docs and RUN_BUILDER_TESTS=1 pnpm exec vitest run packages/app-builder with the rebuilt WebAssembly module
  • RUN_SERVICE_TESTS=1 runtime service tests (workerd and celld)
  • bash tools/cargo.sh fmt --all --check, clippy --workspace --all-targets -D warnings, clippy for the WebAssembly target, test --workspace

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with the existing non-blocking concern about implementation-only types in default expressions.

Findings

  1. P2 Internal types enter public docs ▶

Summary

Documents generic interfaces and aliases once by their declaration.

  • Generic types appear once under their shared declaration name.
  • Service documents now say whether each type is an interface or alias.

Reviews (2) · Last reviewed commit: "Document generic types once by their dec..." · Reviewed by Greptile

@tnkuehne
tnkuehne added this pull request to stack #310 November 22, 2026 18:46
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 512db92 Nov 22 2026, 07:34 PM

Comment on lines +43 to +49
let annotations = node
.parameters()
.iter()
.chain(node.type_parameters())
.copied()
.chain(node.type_node())
.collect::<Vec<_>>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Internal types enter public docs

declaration_references reads every parameter before the extractor removes injected arguments from object-handler signatures. For echo(input: string, env: InternalEnv), it documents InternalEnv and records it in uses, although clients only pass input.

Passing whole parameter nodes also reads types inside default-value expressions, including function bodies nested there. This adds implementation details to public docs. Walk only the exposed parameters' type annotations, plus the return annotation and type parameters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 512db92. declaration_references now reads only the parameters the documentation keeps: all for classes, the first for object handlers. The object-handler test declares env: InternalEnv and asserts that no type is documented.

A generic interface or alias was documented once per instantiation, so a
generated API with a shared selection type such as Page<T> expanded into
thousands of copies. Each generic declaration is now documented once with its
type parameters. References that the checker's types no longer carry, such as
an alias inside `Alias | null`, are taken from the declarations. Each type
records whether it is declared as an interface or a type alias, so generated
declaration files keep its meaning. The documentation format moves to 3.
@tnkuehne
tnkuehne force-pushed the feat/generic-type-declarations branch from 3055d6b to 512db92 Compare November 22, 2026 19:33
@tnkuehne
tnkuehne merged commit e4d1398 into main Nov 22, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the feat/generic-type-declarations branch November 22, 2026 20:51
tnkuehne added a commit that referenced this pull request Nov 22, 2026
Depends on #308 and #309 (stack). The generated API documents within
limits only with generic declarations documented once (#308).

## What changes

**New `templates/linear` on Linear's GraphQL API.**
- Connects each signed-in user's Linear account (`read`, `write`) and
offers every query and mutation of `https://api.linear.app/graphql` as a
typed method with the same name: 422 methods today.
- `pnpm generate` (`scripts/generate.ts`) downloads Linear's published
schema from Linear's SDK repository and writes `src/api.ts` (types and
methods, with Linear's descriptions as TSDoc) and `src/schema.ts` (field
types and argument types for writing requests).
- `connectionStatus` reports setup and linking, as in the other
templates.

**Typed selections.**
- Methods returning objects take the fields to return. The result has
exactly the selected fields with their schema types; unknown fields,
missing nested selections and wrong argument types are compile errors
(`tests/types.ts`).
- `$args` passes arguments of nested fields: `{ comments: { $args: {
first: 5 }, nodes: { body: true } } }`. Fields with arguments are
methods of their type, so declaration files keep them.
- `$on` selects fields per concrete type of unions and interfaces;
results carry `__typename`.
- At runtime every argument travels as a GraphQL variable with the type
the schema declares. Selections and inputs that do not match the schema
fail before anything is asked or sent.
- `Selection<T>` is a plain mapped type: a conditional type made the
documentation extractor expand each selection in full.

**Which operations are offered.**
- `scripts/operations.ts` lists every mutation as `create`, `update` or
`delete`, or as not offered with a reason. Generation stops on a
mutation it does not list and on names it lists that the schema no
longer has.
- Not offered (57): Linear's sign-in and session flows, agent-app
(`actor=app`) operations, OAuth application management (`oauth:create`
scope), completing other providers' OAuth authorizations, release
pipeline access keys, Linear website operations without a user, and one
operation Linear marks internal.
- The queries `initiativeUpdate` and `projectUpdate` share their names
with mutations; they are `initiativeUpdateById` and `projectUpdateById`.
Generation fails on any other name collision.
- Operations needing Linear's `admin` scope stay offered: Linear does
not document which they are, and it answers them with an error.

**Approval levels.**
- Queries never ask. Mutations ask as the user's level says:
`all_changes`, `updates_and_deletions` (default: only creating runs at
once) or `none`.
- A question returns `input_required` with the mutation and its input,
shortened to the 4,096-character limit; `declined` does not run. Users
without a connection get `connection_required` instead of a question.
- Each user's level is kept in the app's D1 database. `approvalLevel`
reads it; `setApprovalLevel` asks for confirmation before asking less,
and takes effect at once for asking more.
- Users also choose the level on the app's page. The choice saves
immediately and returns to the saved level with a notice if saving
fails.

**Results and errors.** `connected` with `data`, or `linear_error` with
Linear's errors (its `userPresentableMessage` where present). HTTP 401
and GraphQL authentication errors give `reconnect_required`; HTTP 429
and `ratelimited` errors give `rate_limited` with `Retry-After`.
Questions have no `status` and other results no `resultType`, so callers
can branch on either field.

**Login.**
- Managed OAuth uses a registered Linear OAuth application (`provider:
"linear"`) with `https://api.linear.app` as its host and revocation at
`https://api.linear.app/oauth/revoke`. The CIMD client for Linear's MCP
server is no longer used.
- Without managed OAuth, `LINEAR_CLIENT_ID` and `LINEAR_CLIENT_SECRET`
as before. Better Auth's Linear provider reads the profile from the
`viewer` query.
- `widefleet.jsonc` declares only `https://api.linear.app`.

## Screenshots

Connected account page, before and after (390 and 1280 px). The page has
no dark theme, like the other template pages.

| Before | After |
| --- | --- |
| <img
src="https://gist.githubusercontent.com/tnkuehne/b18582250038507a8a0fb9ae4addf385/raw/7ee665d928b076e78793775af2273587026a7907/before-1280.png"
width="420"> | <img
src="https://gist.githubusercontent.com/tnkuehne/b18582250038507a8a0fb9ae4addf385/raw/7ee665d928b076e78793775af2273587026a7907/after-1280.png"
width="420"> |
| <img
src="https://gist.githubusercontent.com/tnkuehne/b18582250038507a8a0fb9ae4addf385/raw/7ee665d928b076e78793775af2273587026a7907/before-390.png"
width="200"> | <img
src="https://gist.githubusercontent.com/tnkuehne/b18582250038507a8a0fb9ae4addf385/raw/7ee665d928b076e78793775af2273587026a7907/after-390.png"
width="200"> |

Saving failed: the previous level returns with a notice.

<img
src="https://gist.githubusercontent.com/tnkuehne/b18582250038507a8a0fb9ae4addf385/raw/7ee665d928b076e78793775af2273587026a7907/after-failed-1280.png"
width="420">

## Tests

- `templates/linear/src/graphql.test.ts`: request writing (variables
with schema types, nested `$args`, `$on`, scalar fields with arguments)
and rejected selections and inputs, including prototype keys.
- `templates/linear/tests/app.test.ts` against a synthetic Linear OAuth
application and GraphQL API: the GraphQL requests sent, all three
approval levels, confirming and declining, per-user levels, the page's
level form and its origin check, Linear errors, rate limits, revoked
tokens, refresh and outages, user and issuer isolation, replayed
callbacks.
- `tests/types.ts`: result types of selections and the compile errors
above.
- `packages/app-runtime/src/template-oauth.test.ts`: Linear runs the
managed OAuth suite through the real broker with a registered client,
including revocation on disconnect.
- Documentation of the template with the CLI from #309: 1.8 MB, 824
types, 425 methods, no warnings; describing a typical method returns 15
to 29 KB.
- `pnpm check` and `pnpm exec vitest run` pass.
`runtime-errors.integration.test.ts` needs a built control plane, which
my checkout lacked; it passes in a checkout with one.

## Not covered by tests

- Calls against Linear's production API: the managed Linear OAuth
application is not configured in any installation yet.
- The page in a real browser session; the screenshots render the page's
HTML with synthetic values.












<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><a
href="https://app.greptile.com/api/retrigger?id=115175738&amp;sig=6a855b2f18090b4cbd2213678bc2aa7c4d12f908132ba0f489f126dbd5bb616c"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F265&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5 <sup><img alt="Tier:
plus" title="Review tier: plus"
src="https://greptile-static-assets.s3.amazonaws.com/badges/effort-plus.svg?v=3"
height="12"></sup></h2>

<!-- greptile-impact-verdict --> The PR appears safe to merge, with one
non-blocking part of the previous optional-value finding still open.

<h2>Findings</h2>

1. <img alt="P2"
src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9"
align="top">&nbsp;**Optional values stop valid requests** <a
href="https://github.com/widefleet/widefleet/pull/265#discussion_r4659668631">▶</a>

<details open><summary><h3>Summary</h3></summary>

Adds a Linear template with generated GraphQL methods, personal OAuth
connections, typed field selections, and per-user approval levels.

- Linear calls now use schema-checked methods with typed field
selections.
- Linear mutations ask users first according to their saved approval
level.
- Each user can connect a Linear account for app calls.
- Linear appears as a deployable template in the catalog.
</details>

<details open><summary><h3>Diagram</h3></summary>

```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Generated Linear method] --> B[Write GraphQL request]
  B --> C{Mutation?}
  C -- No --> G[Load user token]
  C -- Yes --> D[Check connection and approval level]
  D --> E{Ask first?}
  E -- No --> G
  E -- Yes --> F{User answer}
  F -- Missing --> Q[Return input_required]
  F -- Decline --> R[Return declined]
  F -- Accept --> G
  G --> H[Call Linear GraphQL API]
  H --> I[Return selected data or error]
```
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (10) · Last reviewed commit: ["Ask before creates that
change existing
..."](2ca211e)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
tnkuehne added a commit that referenced this pull request Nov 22, 2026
## Why

A non-generic type alias is documented with references to other aliases
expanded one level. A generated input type whose fields are themselves
aliases grows several times: in the Linear template, `IssueFilter`
(about 100 fields of comparator aliases such as
`NullableDateComparator`) is 57 KB in `describe`, and describing
`viewer` with `issues` returns 84 KB. Interfaces are not affected, since
they keep their names.

## What changes

- Type aliases are printed as declaration files write them, with
references to other aliases by name, as #308 already does for generic
aliases. The referenced aliases are documented on their own and listed
in `uses`.

On the Linear template, `IssueFilter` drops from 57 KB to 17 KB, and
describing `viewer` with `issues` from 84 KB to 41 KB. The whole
document is 2.0 MB with 828 types.

## Verification

- New extraction test: an alias referring to another alias keeps its
name and records it in `uses`. It fails without the change.
- `RUN_CLI_TESTS=1` documentation extraction, app-services CLI and
integration tests
- `RUN_WASM_TESTS=1 pnpm exec vitest run packages/service-docs` and
`RUN_BUILDER_TESTS=1 pnpm exec vitest run packages/app-builder` with the
rebuilt WebAssembly module
- `pnpm check`; `bash tools/cargo.sh fmt --all --check`, `clippy
--workspace --all-targets -D warnings`, `clippy` for the WebAssembly
target, `test --workspace`


<!-- greptile_comment -->

<!-- greptile_summary -->

<h2><a
href="https://app.greptile.com/api/retrigger?id=115966209&amp;sig=c9b107cd899d8f4b86bfd668412dd5ebfc9984b37cc11534c42f68789e690d4d"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img
alt="Retrigger"
src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"
align="right"></picture></a><a
href="https://app.greptile.com/-/switch-tenant?tenant=mendra&amp;next=%2Fwidefleet%2Fwidefleet%2Fpull%2F311&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img
alt="View in Greptile"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"
align="right"></picture></a>Confidence Score: 5/5</h2>

<!-- greptile-impact-verdict --> The PR appears safe to merge; no
actionable issues were found.

<details open><summary><h3>Summary</h3></summary>

Non-generic type aliases now keep referenced alias names instead of
expanding their bodies.
- Service docs keep aliases referenced by other aliases by name.
</details>

<!-- greptile_confidence_score:5 -->

<sub>Reviews (1) · Last reviewed commit: ["Keep the names of aliases a
documented
a..."](15d34ef)
· [Reviewed by
Greptile](https://www.greptile.com/?utm_source=greptile_review&utm_medium=github&utm_campaign=review_public&utm_content=widefleet/widefleet)</sub>

<!-- /greptile_comment -->
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