Skip to content

Commit

Permalink
fix(exo): mark exoClassKit facets Remotable
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Oct 18, 2023
1 parent 25f027a commit fe8ad36
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/exo/src/exo-makers.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ export const defineExoClass = (
};
harden(defineExoClass);

/**
* @template {Record<FacetName, Methods>} F
* @typedef {{ [K in keyof F]: FarFacet<F[K]> }} FarFacets
*/

/**
* @template {Methods} F
* @typedef {{ [M in keyof F]: F[M] } & import('@endo/eventual-send').RemotableBrand<{}, F>} FarFacet
*/

/**
* @template {(...args: any[]) => any} I init function
* @template {Record<FacetName, Methods>} F facet methods
Expand All @@ -153,9 +163,9 @@ harden(defineExoClass);
* [M in keyof F[K]]: import("@endo/patterns").MethodGuard;
* }> } | undefined} interfaceGuardKit
* @param {I} init
* @param {F & ThisType<{ facets: F, state: ReturnType<I> }> } methodsKit
* @param {FarClassOptions<KitContext<ReturnType<I>,F>>} [options]
* @returns {(...args: Parameters<I>) => F}
* @param {F & ThisType<{ facets: FarFacets<F>, state: ReturnType<I> }> } methodsKit
* @param {FarClassOptions<KitContext<ReturnType<I>,FarFacets<F>>>} [options]
* @returns {(...args: Parameters<I>) => FarFacets<F>}
*/
export const defineExoClassKit = (
tag,
Expand Down Expand Up @@ -186,15 +196,15 @@ export const defineExoClassKit = (
// Be careful not to freeze the state record
const state = seal(init(...args));
// Don't freeze context until we add facets
/** @type {KitContext<ReturnType<I>,F>} */
const context = { state, facets: {} };
/** @type {{ state: ReturnType<I>, facets: FarFacets<F> }} */
const context = { state, facets: /** @type {FarFacets<F>} */ ({}) };
instanceCount += 1;
const facets = objectMap(prototypeKit, (proto, facetName) => {
const self = makeSelf(proto, instanceCount);
contextMapKit[facetName].set(self, context);
return self;
});
context.facets = facets;
context.facets = /** @type {typeof context.facets} */ (facets);
// Be careful not to freeze the state record
freeze(context);
if (finish) {
Expand Down

0 comments on commit fe8ad36

Please sign in to comment.