feat: Add script to extract RPC method documentation#3853
feat: Add script to extract RPC method documentation#3853
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. Ignoring alerts on:
|
|
@SocketSecurity ignore npm/@ts-morph/common@0.28.1 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3853 +/- ##
==========================================
- Coverage 98.59% 98.59% -0.01%
==========================================
Files 429 429
Lines 12417 12413 -4
Branches 1928 1928
==========================================
- Hits 12242 12238 -4
Misses 175 175 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| }: DialogMethodHooks) { | ||
| return async function dialogImplementation( | ||
| args: RestrictedMethodOptions<DialogParameters>, | ||
| ): Promise<boolean | null | string | Json> { |
There was a problem hiding this comment.
In some ways this was better at documenting the return types being different for different inputs 😅
There was a problem hiding this comment.
Sure, but this was inferred as Json anyway. It was causing the type to be extracted in a weird way because of an edge case. I can add a way to handle the edge case as well instead of changing the type here, if you prefer.
There was a problem hiding this comment.
Probably just documenting it thoroughly is better since it will be inferred for consumers.
| * - If the dialog is a `prompt`, the result is the value entered by | ||
| * the user. |
There was a problem hiding this comment.
| * - If the dialog is a `prompt`, the result is the value entered by | |
| * the user. | |
| * - If the dialog is a `prompt`, the result is the value entered by | |
| * the user. | |
| * - If the dialog has no type, the result is entirely up to the Snap. |
Or similar?
| methodNames: [methodName] as const, | ||
| implementation: getCancelBackgroundEventImplementation, | ||
| hookNames, | ||
| } satisfies PermittedHandlerExport< |
There was a problem hiding this comment.
No problem with the changes, but why is this preferred?
There was a problem hiding this comment.
It makes it slightly easier to extract type information. When using const foo: Type, any specific type information is lost. Could potentially work around the changes by looking at the type nodes (AST) instead of types, but this seemed like a better solution.
| }; | ||
|
|
||
| export const providerRequestHandler: PermittedHandlerExport< | ||
| export const providerRequestHandler = { |
There was a problem hiding this comment.
Just realized we should remove this, will open a PR
This adds a script to extract types and documentation from the
snaps-rpc-methods, which can then be used to generate documentation. It works by looking at the TypeScript AST to extract properties and type information, writing the result to a JSON file.To make it easier to use the JSON in the docs website, it will be published to a
schemadirectory on GitHub Pages.Note
Medium Risk
Introduces a large new codegen script and changes handler/type definitions to support extraction, plus adds new release-time GitHub Pages publishing; failures could break schema/docs publishing or subtly alter exported types.
Overview
Adds a new
@metamask/snaps-rpc-methodsbuild step (build:schema) that generatesschema/schema.jsonby walking the TypeScript AST to extract each permitted/restricted JSON-RPC method’s name, JSDoc description, params/result type strings, allowed caller type, and@exampleblocks.Updates permitted handler exports to use
satisfies PermittedHandlerExportwithmethodNames: [methodName] as const(to preserve literal types for extraction), tweaks a few SDK method type docs/aliases (notablyDialogResult→Json), and wires CI to publish the generatedschema/directory togh-pagesfor main (schema/staging) and releases (schema/<tag>plusschema/latest).Written by Cursor Bugbot for commit 32f4f4c. This will update automatically on new commits. Configure here.