-
Notifications
You must be signed in to change notification settings - Fork 6
refactor: Extract message / command types into utils package #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Attempts to delineate an abstraction boundary in our message types.
| const envelopeKit: ReturnType< | ||
| typeof makeStreamEnvelopeKit< | ||
| typeof envelopeLabels, | ||
| { | ||
| command: VatMessage; | ||
| capTp: CapTpMessage; | ||
| } | ||
| > | ||
| > = makeStreamEnvelopeKit< | ||
| typeof envelopeLabels, | ||
| { | ||
| command: VatMessage; | ||
| capTp: CapTpMessage; | ||
| } | ||
| >({ | ||
| command: isVatMessage, | ||
| capTp: isCapTpMessage, | ||
| }); | ||
|
|
||
| export type StreamEnvelope = GuardType<typeof envelopeKit.isStreamEnvelope>; | ||
| export type StreamEnvelopeHandler = ReturnType< | ||
| typeof envelopeKit.makeStreamEnvelopeHandler | ||
| >; | ||
|
|
||
| export const wrapStreamCommand: typeof envelopeKit.streamEnveloper.command.wrap = | ||
| envelopeKit.streamEnveloper.command.wrap; | ||
| export const wrapCapTp: typeof envelopeKit.streamEnveloper.capTp.wrap = | ||
| envelopeKit.streamEnveloper.capTp.wrap; | ||
| // eslint-disable-next-line prefer-destructuring | ||
| export const makeStreamEnvelopeHandler: typeof envelopeKit.makeStreamEnvelopeHandler = | ||
| envelopeKit.makeStreamEnvelopeHandler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I ran into what appears to be a cursed TypeScript bug. It doesn't believe that these types can be inferred, and instead require explicit annotation. I think we can leave it be for now as I have hopes that we can simplify this situation later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe, good branch name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were a number of cursed bugs that surfaced as the error I got for this, but they appear to have been resolved, and this appears to have been legitimate (ref: microsoft/TypeScript#42873 (comment)).
Apparently typescript needs these types explicitly exported in order to do inference in other packages.
grypez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good step toward figuring out where things ought to land.
The stream envelope kit enforces compile and runtime constraints on the types of messages which can pass through the stream in either direction. I expect that eventually we will have a thing-stream-envelope.ts declaration for every thing with a distinctly typed stream, but let the stream-envelope.ts here serve as a prototype.
Co-authored-by: grypez <143971198+grypez@users.noreply.github.com>
grypez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
The command / message types have frustrated us on various occasion (exhibit A), and this is in part because they blur abstraction boundaries between the kernel and the platform it runs on. Here we attempt to delineate this abstraction boundary by extracting these types into a new "kitchen drawer" package (
@ocap/utils), and refactoring them such that only a smaller set needs to be shared between different packages. In addition, theCommand-family of types and enums receives an overhaul.Changes in detail:
@ocap/streamsinto a new package,@ocap/utils@ocap/utilsutils/src/types.tsCommandtype itself blurs our ideal abstraction boundary by implementing low-level plumbing likepingalongside porcelain such as `callCapTp. Fixing this is deferred to future work.CommandMethod, and the actual command payloadCommand. Various unnecessary generic parameters have been removed.Commits are individually reviewable.