-
Notifications
You must be signed in to change notification settings - Fork 221
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
9449 membrane types #9685
9449 membrane types #9685
Changes from all commits
884a94b
94dfab1
6005984
d91d11d
35380af
da4380d
541900f
df5d174
9e8a29a
704bad6
b4fdee6
96b5c6e
4ad9fb5
beeb7da
91ef352
4be4842
43a8f5a
2405c8f
f10c9c1
6b41829
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './src/async-flow.js'; | ||
export * from './src/types.js'; | ||
export { makeStateRecord } from './src/endowments.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
import type { Passable } from '@endo/pass-style'; | ||
import type { Vow, VowTools } from '@agoric/vow'; | ||
import type { LogStore } from './log-store.js'; | ||
import type { Bijection } from './bijection.js'; | ||
import type { EndowmentTools } from './endowments.js'; | ||
|
||
export type FlowState = | ||
| 'Running' | ||
| 'Sleeping' | ||
| 'Replaying' | ||
| 'Failed' | ||
| 'Done'; | ||
|
||
/** | ||
* `T` defaults to `any`, not `Passable`, because unwrapped guests include | ||
* non-passables, like unwrapped functions and unwrapped state records. | ||
* (Unwrapped functions could be made into Remotables, | ||
* but since they still could not be made durable, in this context | ||
* it'd be pointless.) | ||
*/ | ||
export type Guest<T extends unknown = any> = T; | ||
export type Host<T extends Passable = Passable> = T; | ||
|
||
/** | ||
* A HostVow must be durably storable. It corresponds to an | ||
* ephemeral guest promise. | ||
*/ | ||
export type HostVow<T extends Passable = Passable> = Host<Vow<T>>; | ||
|
||
export type GuestAsyncFunc = ( | ||
...activationArgs: Guest[] | ||
) => Guest<Promise<any>>; | ||
|
||
export type HostAsyncFuncWrapper = (...activationArgs: Host[]) => HostVow; | ||
|
||
/** | ||
* The function from the host as it will be available in the guest. | ||
* | ||
* Specifically, Vow return values are converted to Promises. | ||
*/ | ||
export type GuestOf<F extends HostAsyncFuncWrapper> = F extends ( | ||
...args: infer A | ||
) => Vow<infer R> | ||
? (...args: A) => Promise<R> | ||
: F; | ||
Comment on lines
+41
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow! Thanks for translating all those type declarations into better .d.ts types. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tsc did the work! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL! Good to know. |
||
|
||
/** | ||
* Convert an entire Guest interface into what the host will implement. | ||
*/ | ||
type HostInterface<T> = { | ||
[K in keyof T]: HostOf<T[K]>; | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work on these. Do we also need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we define an interface it should be in the view of the guest. |
||
/** | ||
* The function the host must provide to match an interface the guest expects. | ||
* | ||
* Specifically, Promise return values are converted to Vows. | ||
*/ | ||
export type HostOf<F> = F extends (...args: infer A) => Promise<infer R> | ||
? (...args: A) => Vow<R extends Passable ? R : HostInterface<R>> | ||
: F; | ||
|
||
export type PreparationOptions = { | ||
vowTools?: VowTools; | ||
makeLogStore?: (() => LogStore) | undefined; | ||
makeBijection?: (() => Bijection) | undefined; | ||
endowmentTools?: EndowmentTools; | ||
}; | ||
export type OutcomeKind = 'return' | 'throw'; | ||
|
||
export type Outcome = | ||
| { | ||
kind: 'return'; | ||
result: any; | ||
} | ||
| { | ||
kind: 'throw'; | ||
problem: any; | ||
}; | ||
|
||
export type Ephemera<S extends WeakKey = WeakKey, V extends unknown = any> = { | ||
for: (self: S) => V; | ||
resetFor: (self: S) => void; | ||
}; | ||
|
||
/** | ||
* This is the type alias for the membrane log entries we currently implement. | ||
* | ||
* @see {FutureLogEntry} below for the full membrane log entry, which we do not | ||
* yet support. | ||
*/ | ||
export type LogEntry = | ||
| [ | ||
// ///////////////// From Host to Guest ///////////////////////// | ||
op: 'doFulfill', | ||
vow: HostVow, | ||
fulfillment: Host, | ||
] | ||
| [op: 'doReject', vow: HostVow, reason: Host] | ||
| [op: 'doReturn', callIndex: number, result: Host] | ||
| [op: 'doThrow', callIndex: number, problem: Host] | ||
| [ | ||
// ///////////////////// From Guest to Host ///////////////////////// | ||
op: 'checkCall', | ||
target: Host, | ||
optVerb: PropertyKey | undefined, | ||
args: Host[], | ||
callIndex: number, | ||
] | ||
| [ | ||
op: 'checkSendOnly', | ||
target: Host, | ||
optVerb: PropertyKey | undefined, | ||
args: Host[], | ||
callIndex: number, | ||
] | ||
| [ | ||
op: 'checkSend', | ||
target: Host, | ||
optVerb: PropertyKey | undefined, | ||
args: Host[], | ||
callIndex: number, | ||
]; | ||
|
||
/** | ||
* This would be the type alias for the full membrane log, if we supported: | ||
* - the guest sending guest-promises and guest-remotables to the host | ||
* - the guest using `E` to eventual-send to guest wrappers of the host | ||
* vows and remotables. | ||
*/ | ||
export type FutureLogEntry = | ||
| [ | ||
// ///////////////// From Host to Guest /////////////////////// | ||
op: 'doFulfill', | ||
vow: HostVow, | ||
fulfillment: Host, | ||
] | ||
| [op: 'doReject', vow: HostVow, reason: Host] | ||
| [ | ||
op: 'doCall', | ||
target: Host, | ||
optVerb: PropertyKey | undefined, | ||
args: Host[], | ||
callIndex: number, | ||
] | ||
| [ | ||
op: 'doSendOnly', | ||
target: Host, | ||
optVerb: PropertyKey | undefined, | ||
args: Host[], | ||
callIndex: number, | ||
] | ||
| [ | ||
op: 'doSend', | ||
target: Host, | ||
optVerb: PropertyKey | undefined, | ||
args: Host[], | ||
callIndex: number, | ||
] | ||
| [op: 'doReturn', callIndex: number, result: Host] | ||
| [op: 'doThrow', callIndex: number, problem: Host] | ||
| [ | ||
// ///////////////////// From Guest to Host ///////////////////////// | ||
op: 'checkFulfill', | ||
vow: HostVow, | ||
fulfillment: Host, | ||
] | ||
| [op: 'checkReject', vow: HostVow, reason: Host] | ||
| [ | ||
op: 'checkCall', | ||
target: Host, | ||
optVerb: PropertyKey | undefined, | ||
args: Host[], | ||
callIndex: number, | ||
] | ||
| [ | ||
op: 'checkSendOnly', | ||
target: Host, | ||
optVerb: PropertyKey | undefined, | ||
args: Host[], | ||
callIndex: number, | ||
] | ||
| [ | ||
op: 'checkSend', | ||
target: Host, | ||
optVerb: PropertyKey | undefined, | ||
args: Host[], | ||
callIndex: number, | ||
] | ||
| [op: 'checkReturn', callIndex: number, result: Host] | ||
| [op: 'checkThrow', callIndex: number, problem: Host]; |
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.
Realize this is an existing comment, but consider an
@internal
directiveThere 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.
when I added it there was a jsdoc lint error the tag should be empty
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.
What does @internal mean/do?
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.
https://typedoc.org/tags/internal/
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.
#9690 fixes the lint error. I'm still not sure whether this should be
@internal
.