From 4efbed8f4153b4dc0ee8eda440ce0886cc263a4c Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 20 Jun 2023 10:27:30 -0700 Subject: [PATCH] chore(types): correct ManifestBundleRef --- .../test/upgrade-contract/propose-buggy-contract.js | 1 + .../upgrade-contract/propose-upgrade-contract.js | 1 + .../src/coreProposalBehavior.js | 12 +++++++----- packages/deploy-script-support/src/externalTypes.js | 9 ++++----- .../deploy-script-support/src/extract-proposal.js | 10 +++++++++- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/agoric-cli/test/upgrade-contract/propose-buggy-contract.js b/packages/agoric-cli/test/upgrade-contract/propose-buggy-contract.js index 1e5829e6511b..1420d080f7eb 100644 --- a/packages/agoric-cli/test/upgrade-contract/propose-buggy-contract.js +++ b/packages/agoric-cli/test/upgrade-contract/propose-buggy-contract.js @@ -3,6 +3,7 @@ // eslint-disable-next-line import/no-extraneous-dependencies import { makeHelpers } from '@agoric/deploy-script-support'; +/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */ export const defaultProposalBuilder = async ({ publishRef, install }) => harden({ sourceSpec: './init-proposal.js', diff --git a/packages/agoric-cli/test/upgrade-contract/propose-upgrade-contract.js b/packages/agoric-cli/test/upgrade-contract/propose-upgrade-contract.js index b149f7ef75be..60ad54bb46cb 100644 --- a/packages/agoric-cli/test/upgrade-contract/propose-upgrade-contract.js +++ b/packages/agoric-cli/test/upgrade-contract/propose-upgrade-contract.js @@ -3,6 +3,7 @@ // eslint-disable-next-line import/no-extraneous-dependencies import { makeHelpers } from '@agoric/deploy-script-support'; +/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */ export const defaultProposalBuilder = async ({ publishRef, install }) => harden({ sourceSpec: './upgrade-proposal.js', diff --git a/packages/deploy-script-support/src/coreProposalBehavior.js b/packages/deploy-script-support/src/coreProposalBehavior.js index 477e8dddd7a3..080a14bfbf22 100644 --- a/packages/deploy-script-support/src/coreProposalBehavior.js +++ b/packages/deploy-script-support/src/coreProposalBehavior.js @@ -24,12 +24,12 @@ export const permits = { * definitions. * * @param {object} opts - * @param {{ bundleName: string } | { bundleID: string }} opts.manifestBundleRef + * @param {import('./externalTypes.js').ManifestBundleRef} opts.manifestBundleRef * @param {[string, ...unknown[]]} opts.getManifestCall * @param {Record>} [opts.overrideManifest] * @param {typeof import('@endo/far').E} opts.E * @param {(...args: unknown[]) => void} [opts.log] - * @param {(ref: unknown) => Promise} [opts.restoreRef] + * @param {(ref: import('./externalTypes.js').ManifestBundleRef) => Promise>} [opts.restoreRef] * @returns {(vatPowers: unknown) => Promise} */ export const makeCoreProposalBehavior = ({ @@ -70,13 +70,15 @@ export const makeCoreProposalBehavior = ({ } = allPowers; const [exportedGetManifest, ...manifestArgs] = getManifestCall; + /** @type {(ref: import('./externalTypes.js').ManifestBundleRef) => Promise>} */ const defaultRestoreRef = async ref => { // extract-proposal.js creates these records, and bundleName is // the name under which the bundle was installed into // config.bundles - const p = ref.bundleName - ? E(vatAdminSvc).getBundleIDByName(ref.bundleName) - : ref.bundleID; + const p = + 'bundleName' in ref + ? E(vatAdminSvc).getBundleIDByName(ref.bundleName) + : ref.bundleID; const bundleID = await p; const label = bundleID.slice(0, 8); return E(zoe).installBundleID(bundleID, label); diff --git a/packages/deploy-script-support/src/externalTypes.js b/packages/deploy-script-support/src/externalTypes.js index 35535dcf66a5..442ea8bcce38 100644 --- a/packages/deploy-script-support/src/externalTypes.js +++ b/packages/deploy-script-support/src/externalTypes.js @@ -16,14 +16,13 @@ export {}; */ /** - * @typedef BundleHandle - * @property {string} [bundleName] + * @typedef {{ bundleName: string } | { bundleID: string} } ManifestBundleRef */ /** * @callback PublishBundleRef - * @param {ERef} bundle - * @returns {Promise} + * @param {ERef} bundle + * @returns {Promise} */ /** @@ -31,7 +30,7 @@ export {}; * @param {string} srcSpec * @param {string} bundlePath * @param {any} [opts] - * @returns {BundleHandle} + * @returns {ManifestBundleRef} */ /** diff --git a/packages/deploy-script-support/src/extract-proposal.js b/packages/deploy-script-support/src/extract-proposal.js index ea539b145b0e..fc2e91ee4830 100644 --- a/packages/deploy-script-support/src/extract-proposal.js +++ b/packages/deploy-script-support/src/extract-proposal.js @@ -135,11 +135,19 @@ export const extractCoreProposalBundles = async ( /** @type {import('./externalTypes.js').PublishBundleRef} */ const publishRef = async handleP => { const handle = await handleP; + // @ts-expect-error xxx types bundleHandleToAbsolutePaths.has(handle) || Fail`${handle} not in installed bundles`; return handle; }; - const proposal = await ns[entrypoint]({ publishRef, install }, ...args); + const proposal = await ns[entrypoint]( + { + publishRef, + // @ts-expect-error not statically verified to return a full obj + install, + }, + ...args, + ); // Add the proposal bundle handles in sorted order. const bundleSpecEntries = [...thisProposalBundleHandles.keys()]