Skip to content

Commit

Permalink
refactor(far): deduplicate types from eventual-send by aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Dec 12, 2024
1 parent b8c2107 commit 43e4d43
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
15 changes: 11 additions & 4 deletions packages/eventual-send/src/E.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,11 @@ export default makeE;
/** @typedef {ReturnType<makeE>} EProxy */

/**
* Creates a type that accepts both near and marshalled references that were
* returned from `Remotable` or `Far`, and also promises for such references.
* Declare an object that is potentially a far reference of type Primary whose
* auxilliary data has type Local. This should be used only for consumers of
* Far objects in arguments and declarations; the only creators of Far objects
* are distributed object creator components like the `Far` or `Remotable`
* functions.
*
* @template Primary The type of the primary reference.
* @template [Local=DataOnly<Primary>] The local properties of the object.
Expand All @@ -274,6 +277,9 @@ export default makeE;
* @see {@link https://github.com/microsoft/TypeScript/issues/31394}
* @template T
* @typedef {PromiseLike<T> | T} ERef
* Declare that `T` may or may not be a Promise. This should be used only for
* consumers of arguments and declarations; return values should specifically be
* `Promise<T>` or `T` itself.
*/

/**
Expand Down Expand Up @@ -406,8 +412,9 @@ export default makeE;
*/

/**
* Type for an object that must only be invoked with E. It supports a given
* interface but declares all the functions as asyncable.
* Declare a near object that must only be invoked with E, even locally. It
* supports the `T` interface but additionally permits `T`'s methods to return
* `PromiseLike`s even if `T` declares them as only synchronous.
*
* @template T
* @typedef {(
Expand Down
1 change: 1 addition & 0 deletions packages/far/src/exports.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { FarRef, ERef, EOnly, EReturn } from '@endo/eventual-send';
2 changes: 2 additions & 0 deletions packages/far/src/exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Just a dummy to use exports.d.ts and satisfy runtime imports.
export {};
29 changes: 2 additions & 27 deletions packages/far/src/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
export { E } from '@endo/eventual-send';
export { Far, getInterfaceOf, passStyleOf } from '@endo/pass-style';

// TODO re-export from eventual-send, may require .d.ts
/**
* @template Primary
* @template [Local=import('@endo/eventual-send').DataOnly<Primary>]
* @typedef {import('@endo/eventual-send').FarRef<Primary, Local>} FarRef
* Declare an object that is potentially a far reference of type Primary whose
* auxilliary data has type Local. This should be used only for consumers of
* Far objects in arguments and declarations; the only creators of Far objects
* are distributed object creator components like the `Far` or `Remotable`
* functions.
*/

/**
* @template T
* @typedef {import('@endo/eventual-send').ERef<T>} ERef
* Declare that `T` may or may not be a Promise. This should be used only for
* consumers of arguments and declarations; return values should specifically be
* `Promise<T>` or `T` itself.
*/

/**
* @template T
* @typedef {import('@endo/eventual-send').EOnly<T>} EOnly
* Declare a near object that must only be invoked with E, even locally. It
* supports the `T` interface but additionally permits `T`'s methods to return
* `PromiseLike`s even if `T` declares them as only synchronous.
*/
// eslint-disable-next-line import/export
export * from './exports.js';

0 comments on commit 43e4d43

Please sign in to comment.