-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes: #9449 ## Description Address all the FIXMEs about types and vows in Orchestration. To do so I moved some stuff down to async-flow and zoe packages. I also made some small fixes in smart-wallet. I believe this ticks the last box of #9449. ### Security Considerations none ### Scaling Considerations none ### Documentation Considerations none ### Testing Considerations This adds type tests and I used `type-coverage` to verify no regressions. ### Upgrade Considerations orchestration and async-flow not yet deployed. The changes in zoe and smart-wallet are just typedefs so safe to deploy anytime.
- Loading branch information
Showing
37 changed files
with
444 additions
and
452 deletions.
There are no files selected for viewing
This file contains 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
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'; |
This file contains 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
This file contains 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
This file contains 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
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; | ||
|
||
/** | ||
* Convert an entire Guest interface into what the host will implement. | ||
*/ | ||
type HostInterface<T> = { | ||
[K in keyof T]: HostOf<T[K]>; | ||
}; | ||
|
||
/** | ||
* 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]; |
Oops, something went wrong.