Repository navigation
Document generic types once by their declaration - #308
Conversation
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | 512db92 | Nov 22 2026, 07:34 PM |
| let annotations = node | ||
| .parameters() | ||
| .iter() | ||
| .chain(node.type_parameters()) | ||
| .copied() | ||
| .chain(node.type_node()) | ||
| .collect::<Vec<_>>(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
3055d6b to
512db92
Compare
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&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&next=%2Fwidefleet%2Fwidefleet%2Fpull%2F265&utm_source=greptile_review&utm_medium=github&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"> **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 -->
## 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&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&next=%2Fwidefleet%2Fwidefleet%2Fpull%2F311&utm_source=greptile_review&utm_medium=github&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 -->
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 | nullis flattened into the union, soRolewas neither documented nor recorded inuses.Documents also say nothing about how a type is declared, so declaration files generated from them cannot reproduce
interfaceandtypesemantics.What changes
Page<T>. Signatures keep their instantiated names, such asPage<Item>, and record the declaration inuses. A generic alias prints its own structure, so references inside it keep their names.kind(interfaceortype). A generic declaration lists its type parameters with constraints and defaults intypeParameters, such asT 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 checkpnpm exec vitest run apps/control-plane packagesRUN_CLI_TESTS=1CLI suites from the Rust job with a freshly built CLI; the extraction tests now assertPage<T>,A<T>/B<T>,Loop<T>, a generic alias andRole | nullRUN_WASM_TESTS=1 pnpm exec vitest run packages/service-docsandRUN_BUILDER_TESTS=1 pnpm exec vitest run packages/app-builderwith the rebuilt WebAssembly moduleRUN_SERVICE_TESTS=1runtime service tests (workerd and celld)bash tools/cargo.sh fmt --all --check,clippy --workspace --all-targets -D warnings,clippyfor the WebAssembly target,test --workspace

Confidence Score: 5/5
The PR appears safe to merge, with the existing non-blocking concern about implementation-only types in default expressions.Findings
Summary
Documents generic interfaces and aliases once by their declaration.
Reviews (2) · Last reviewed commit: "Document generic types once by their dec..." · Reviewed by Greptile