refactor: small cleanups extracted from #96 prep work#124
Merged
Conversation
Three independently-mergeable cleanups identified while preparing the Rust core runtime port (#96): - `truapi/transport.ts`: extract a module-level `toError(unknown): Error` helper and use it at the three sites that hand-rolled the same `error instanceof Error ? error : new Error(String(error))` coercion. - `truapi-codegen::MethodKind`: derive `Clone` and `Copy` so the enum can be passed through helpers without re-matching. Trivial additive change; the variants are bare. - `rust/crates/truapi/README.md`: drop the spurious `v02` mention from the bulleted module list. The table below it (and the rest of the document) only mentions `v01`; the prose was out of date.
- Don't introduce typealias chains that just rename a type from another crate; use the canonical name directly. A typealias should capture a real abstraction, not just a rename. - After any code change, update README.md (and CLAUDE.md if the layout changed) so the top-level docs match the repo. Stale docs are a regression. - In codegen emitters, prefer indoc::writedoc! / formatdoc! over chains of writeln!. Multi-line raw strings keep the emitted shape visible in source instead of fragmenting it. - In PR descriptions, issue comments, and other artifacts that outlive the conversation, describe the resulting state, not the transition between commits. "Previously X, now Y" framing reads as ephemeral history once the PR is squash-merged.
Permission request enums are surfaced to host UIs through the prompt
flow, where they need human-readable rendering. The versioned wrappers
and the inner v01 enums now implement Display through `derive_more`:
- `v01::HostDevicePermissionRequest` formats each variant with a short
label ("camera", "open URL", "NFC", ...).
- `v01::RemotePermission` formats `Remote { domains }` as
"access to <comma-separated sorted list>" and each named variant with
its own phrase ("submit chain transactions", "WebRTC connections",
...).
- `v01::RemotePermissionRequest` formats the `permissions` vec joined
with "; ".
- The versioned wrappers `HostDevicePermissionRequest` and
`RemotePermissionRequest` forward through `{_0}` so callers can format
either layer.
Internal `DisplayDomains` and `DisplayPermissions` adapters write
straight into the `Formatter`, avoiding the intermediate `Vec<String>` +
`join` allocations a `format_*` helper would incur.
The `versioned_type!` macro is extended to thread outer enum and inner
variant `#[meta]` attributes so the `derive(Display)` lands on the
generated code.
Drop the DisplayDomains helper and call domains.join(", ") directly
from the #[display] template.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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.
No description provided.