Skip to content

Commit

Permalink
refactor(daemon): Handles have agents, rename
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Mar 27, 2024
1 parent 401dfa0 commit 903c571
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions packages/daemon/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ const makeDaemonCore = async (
context,
);
} else if (formula.type === 'handle') {
context.thisDiesIfThatDies(formula.target);
context.thisDiesIfThatDies(formula.agent);
return {
external: {},
internal: {
targetId: formula.target,
agentId: formula.agent,
},
};
} else if (formula.type === 'endo') {
Expand Down Expand Up @@ -885,13 +885,13 @@ const makeDaemonCore = async (
return controller;
}
// @ts-expect-error We can't know the type of the internal facet.
if (internalFacet.targetId === undefined) {
if (internalFacet.agentId === undefined) {
return controller;
}
const handle = /** @type {import('./types.js').InternalHandle} */ (
internalFacet
);
currentId = handle.targetId;
currentId = handle.agentId;
}
};

Expand Down Expand Up @@ -931,14 +931,14 @@ const makeDaemonCore = async (
* The returned promise is resolved after the formula is persisted.
*
* @param {string} formulaNumber - The formula number of the handle to formulate.
* @param {string} targetId - The formula identifier of the handle's target.
* @param {string} agentId - The formula identifier of the handle's agent.
* @returns {import('./types.js').FormulateResult<import('./types.js').ExternalHandle>} The formulated handle.
*/
const formulateNumberedHandle = (formulaNumber, targetId) => {
const formulateNumberedHandle = (formulaNumber, agentId) => {
/** @type {import('./types.js').HandleFormula} */
const formula = {
type: 'handle',
target: targetId,
agent: agentId,
};
return /** @type {import('./types').FormulateResult<import('./types').ExternalHandle>} */ (
formulate(formulaNumber, formula)
Expand Down
6 changes: 3 additions & 3 deletions packages/daemon/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ type WebBundleFormula = {

type HandleFormula = {
type: 'handle';
target: string;
agent: string;
};

type KnownPeersStoreFormula = {
Expand Down Expand Up @@ -353,7 +353,7 @@ export interface Controller<External = unknown, Internal = unknown>
* provide an EndoGuest with a reference to its creator EndoHost. By using a handle
* that points to the host instead of giving a direct reference to the host, the
* guest does not get access to the functions of the host. This is the external
* facet of a handle. It directly exposes nothing. The handle's target is only
* facet of a handle. It directly exposes nothing. The handle's agent is only
* exposed on the internal facet.
*/
export interface ExternalHandle {}
Expand All @@ -362,7 +362,7 @@ export interface ExternalHandle {}
* handle points to. This should not be exposed outside of the endo daemon.
*/
export interface InternalHandle {
targetId: string;
agentId: string;
}

export type MakeSha512 = () => Sha512;
Expand Down

0 comments on commit 903c571

Please sign in to comment.