From 41fa16b967113347c403c27188436e4386a48760 Mon Sep 17 00:00:00 2001 From: kumavis Date: Sun, 18 Feb 2024 18:27:39 -1000 Subject: [PATCH] feat(daemon): add incarnateBundle --- packages/daemon/src/daemon.js | 23 +++++++++++++++++++++++ packages/daemon/src/host.js | 16 +++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/packages/daemon/src/daemon.js b/packages/daemon/src/daemon.js index 8f1c8a0f92..a06c313490 100644 --- a/packages/daemon/src/daemon.js +++ b/packages/daemon/src/daemon.js @@ -851,6 +851,28 @@ const makeDaemonCore = async ( return provideValueForNumberedFormula(formula.type, formulaNumber, formula); }; + /** + * @param {string} powersFormulaIdentifier + * @param {string} workerFormulaIdentifier + * @param {string} bundleFormulaIdentifier + * @returns {Promise<{ formulaIdentifier: string, value: unknown }>} + */ + const incarnateBundle = async ( + powersFormulaIdentifier, + workerFormulaIdentifier, + bundleFormulaIdentifier, + ) => { + const formulaNumber = await randomHex512(); + /** @type {import('./types.js').MakeBundleFormula} */ + const formula = { + type: 'make-bundle', + worker: workerFormulaIdentifier, + powers: powersFormulaIdentifier, + bundle: bundleFormulaIdentifier, + }; + return provideValueForNumberedFormula(formula.type, formulaNumber, formula); + }; + /** * @param {string} [specifiedFormulaNumber] * @returns {Promise<{ formulaIdentifier: string, value: import('./types').EndoBootstrap }>} @@ -901,6 +923,7 @@ const makeDaemonCore = async ( incarnateGuest, incarnateEval, incarnateUnconfined, + incarnateBundle, incarnateHandle, storeReaderRef, randomHex512, diff --git a/packages/daemon/src/host.js b/packages/daemon/src/host.js index fdb7692c47..641e43daa6 100644 --- a/packages/daemon/src/host.js +++ b/packages/daemon/src/host.js @@ -14,6 +14,7 @@ export const makeHostMaker = ({ incarnateGuest, incarnateEval, incarnateUnconfined, + incarnateBundle, incarnateHandle, storeReaderRef, makeSha512, @@ -354,19 +355,12 @@ export const makeHostMaker = ({ powersName, ); - const formula = { - /** @type {'make-bundle'} */ - type: 'make-bundle', - worker: workerFormulaIdentifier, - powers: powersFormulaIdentifier, - bundle: bundleFormulaIdentifier, - }; - // Behold, recursion: // eslint-disable-next-line no-use-before-define - const { value, formulaIdentifier } = await provideValueForFormula( - formula, - 'make-bundle', + const { value, formulaIdentifier } = await incarnateBundle( + powersFormulaIdentifier, + workerFormulaIdentifier, + bundleFormulaIdentifier, ); if (resultName !== undefined) {