Skip to content

Commit

Permalink
Merge pull request #1667 from endojs/mfig-eonly-fix
Browse files Browse the repository at this point in the history
fix(eventual-send): propagate `ERef<EOnly<R>>` to `EOnly` returns
  • Loading branch information
michaelfig authored Jul 4, 2023
2 parents 0dde19e + 5358648 commit 8a99cc6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
26 changes: 7 additions & 19 deletions packages/eventual-send/src/E.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,13 @@ export default makeE;

/** @typedef {ReturnType<makeE>} EProxy */

/**
* Nominal type to carry the local and remote interfaces of a Remotable.
*
* @template Local The local properties of the object.
* @template Remote The type of all the remotely-callable functions.
* @typedef {{
* constructor?: {
* new (...args: RemotableBrand<Local, Remote>[]): RemotableBrand<Local, Remote>;
* };
* }} RemotableBrand
*/

/**
* Creates a type that accepts both near and marshalled references that were
* returned from `Remotable` or `Far`, and also promises for such references.
*
* @template Primary The type of the primary reference.
* @template [Local=DataOnly<Primary>] The local properties of the object.
* @typedef {ERef<Local & RemotableBrand<Local, Primary>>} FarRef
* @typedef {ERef<Local & import('./types').RemotableBrand<Local, Primary>>} FarRef
*/

/**
Expand Down Expand Up @@ -335,9 +323,9 @@ export default makeE;
*
* @template T
* @typedef {(
* T extends RemotableBrand<infer L, infer R> // if a given T is some remote interface R
* T extends import('./types').RemotableBrand<infer L, infer R> // if a given T is some remote interface R
* ? PickCallable<R> // then return the callable properties of R
* : Awaited<T> extends RemotableBrand<infer L, infer R> // otherwise, if the final resolution of T is some remote interface R
* : Awaited<T> extends import('./types').RemotableBrand<infer L, infer R> // otherwise, if the final resolution of T is some remote interface R
* ? PickCallable<R> // then return the callable properties of R
* : T extends PromiseLike<infer U> // otherwise, if T is a promise
* ? Awaited<T> // then return resolved value T
Expand All @@ -348,9 +336,9 @@ export default makeE;
/**
* @template T
* @typedef {(
* T extends RemotableBrand<infer L, infer R>
* T extends import('./types').RemotableBrand<infer L, infer R>
* ? L
* : Awaited<T> extends RemotableBrand<infer L, infer R>
* : Awaited<T> extends import('./types').RemotableBrand<infer L, infer R>
* ? L
* : T extends PromiseLike<infer U>
* ? Awaited<T>
Expand All @@ -373,11 +361,11 @@ export default makeE;
* @template T
* @typedef {(
* T extends (...args: infer P) => infer R
* ? (...args: P) => Promise<R>
* ? (...args: P) => ERef<EOnly<R>>
* : T extends Record<PropertyKey, import('./types').Callable>
* ? {
* [K in keyof T]: T[K] extends import('./types').Callable
* ? (...args: Parameters<T[K]>) => Promise<ReturnType<T[K]>>
* ? (...args: Parameters<T[K]>) => ERef<EOnly<ReturnType<T[K]>>>
* : T[K];
* }
* : T
Expand Down
11 changes: 11 additions & 0 deletions packages/eventual-send/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ export type * from './track-turns.js';
//

export type Callable = (...args: unknown[]) => any;

/**
* Nominal type to carry the local and remote interfaces of a Remotable.
*/
export declare class RemotableBrand<Local, Remote> {
/** The local properties of the object. */
private L: Local;

/** The type of all the remotely-callable functions. */
private R: Remote;
}

0 comments on commit 8a99cc6

Please sign in to comment.