Skip to content

Commit

Permalink
fix(daemon): enhance types for mail #2084
Browse files Browse the repository at this point in the history
  • Loading branch information
kumavis authored Feb 17, 2024
2 parents dc3eb02 + 51bfe84 commit cacb843
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 91 deletions.
25 changes: 8 additions & 17 deletions packages/daemon/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const makeEndoBootstrap = async (
// reference", and not for "what is my name for this promise".
/** @type {WeakMap<object, string>} */
const formulaIdentifierForRef = new WeakMap();
const getFormulaIdentifierForRef = ref => formulaIdentifierForRef.get(ref);

/**
* @param {string} sha512
Expand Down Expand Up @@ -252,7 +253,7 @@ const makeEndoBootstrap = async (
// Behold, recursion:
// eslint-disable-next-line no-use-before-define
const hub = provideValueForFormulaIdentifier(hubFormulaIdentifier);

// @ts-expect-error calling lookup on an unknown object
const external = E(hub).lookup(...path);
return { external, internal: undefined };
};
Expand Down Expand Up @@ -521,13 +522,7 @@ const makeEndoBootstrap = async (
// share a responsibility for maintaining the memoization tables
// controllerForFormulaIdentifier and formulaIdentifierForRef, since the
// former bypasses the latter in order to avoid a round trip with disk.

/**
* @param {string} formulaType - The type of the formula.
* @param {string} formulaNumber - The number of the formula.
* @param {import('./types').Formula} formula - The formula.
* @returns {Promise<{ formulaIdentifier: string, value: unknown }>} The value of the formula.
*/
/** @type {import('./types.js').ProvideValueForNumberedFormula} */
const provideValueForNumberedFormula = async (
formulaType,
formulaNumber,
Expand Down Expand Up @@ -583,9 +578,7 @@ const makeEndoBootstrap = async (
return provideValueForNumberedFormula(formulaType, formulaNumber, formula);
};

/**
* @param {string} formulaIdentifier
*/
/** @type {import('./types.js').ProvideControllerForFormulaIdentifier} */
const provideControllerForFormulaIdentifier = formulaIdentifier => {
const { type: formulaType, number: formulaNumber } =
parseFormulaIdentifier(formulaIdentifier);
Expand Down Expand Up @@ -619,9 +612,7 @@ const makeEndoBootstrap = async (
return controller;
};

/**
* @param {string} formulaIdentifier
*/
/** @type {import('./types.js').ProvideValueForFormulaIdentifier} */
const provideValueForFormulaIdentifier = async formulaIdentifier => {
const controller = /** @type {import('./types.js').Controller<>} */ (
provideControllerForFormulaIdentifier(formulaIdentifier)
Expand All @@ -639,7 +630,7 @@ const makeEndoBootstrap = async (
});

const makeMailbox = makeMailboxMaker({
formulaIdentifierForRef,
getFormulaIdentifierForRef,
provideValueForFormulaIdentifier,
provideControllerForFormulaIdentifier,
makeSha512,
Expand Down Expand Up @@ -673,8 +664,8 @@ const makeEndoBootstrap = async (
* @returns {Promise<import('./types').EndoInspector>}
*/
const makePetStoreInspector = async petStoreFormulaIdentifier => {
const petStore = await provideValueForFormulaIdentifier(
petStoreFormulaIdentifier,
const petStore = /** @type {import('./types').PetStore} */ (
await provideValueForFormulaIdentifier(petStoreFormulaIdentifier)
);

/**
Expand Down
Loading

0 comments on commit cacb843

Please sign in to comment.