diff --git a/packages/SwingSet/src/controller/initializeSwingset.js b/packages/SwingSet/src/controller/initializeSwingset.js index e3aea5a599f6..bfeb9af1847a 100644 --- a/packages/SwingSet/src/controller/initializeSwingset.js +++ b/packages/SwingSet/src/controller/initializeSwingset.js @@ -5,6 +5,7 @@ import path from 'path'; import { resolve as resolveModuleSpecifier } from 'import-meta-resolve'; import { assert, details as X } from '@agoric/assert'; +import { allValues } from '@agoric/internal'; import bundleSource from '@endo/bundle-source'; import '../types-ambient.js'; @@ -12,24 +13,6 @@ import { insistStorageAPI } from '../lib/storageAPI.js'; import { initializeKernel } from './initializeKernel.js'; import { kdebugEnable } from '../lib/kdebug.js'; -/** - * @param {X[]} xs - * @param {Y[]} ys - * @returns {[X, Y][]} - * @template X, Y - */ -const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]); -const { keys, values, fromEntries } = Object; -/** - * @param {Record>} obj - * @returns {Promise>} - * @template V - */ -const allValues = async obj => { - const vals = await Promise.all(values(obj)); - return fromEntries(zip(keys(obj), vals)); -}; - const bundleRelative = rel => bundleSource(new URL(rel, import.meta.url).pathname); const bundleRelativeCallable = rel => diff --git a/packages/inter-protocol/src/collect.js b/packages/inter-protocol/src/collect.js index 967d41430a1b..7f55df346496 100644 --- a/packages/inter-protocol/src/collect.js +++ b/packages/inter-protocol/src/collect.js @@ -1,13 +1,3 @@ // @ts-check -const { fromEntries, keys, values } = Object; - -/** @type { (xs: X[], ys: Y[]) => [X, Y][]} */ -export const zip = (xs, ys) => harden(xs.map((x, i) => [x, ys[+i]])); - -/** @type { (obj: Record>) => Promise> } */ -export const allValues = async obj => { - const resolved = await Promise.all(values(obj)); - // @ts-expect-error cast - return harden(fromEntries(zip(keys(obj), resolved))); -}; +export { allValues, zip } from '@agoric/internal'; diff --git a/packages/inter-protocol/src/proposals/committee-proposal.js b/packages/inter-protocol/src/proposals/committee-proposal.js index 52bd270a3f4e..4651f30b036b 100644 --- a/packages/inter-protocol/src/proposals/committee-proposal.js +++ b/packages/inter-protocol/src/proposals/committee-proposal.js @@ -1,13 +1,10 @@ // @ts-check -import { deeplyFulfilledObject } from '@agoric/internal'; +import { deeplyFulfilledObject, zip } from '@agoric/internal'; import { E } from '@endo/far'; import { reserveThenDeposit } from './utils.js'; const { values } = Object; -/** @type { (xs: X[], ys: Y[]) => [X, Y][]} */ -const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]); - /** * @param {import('./econ-behaviors').EconomyBootstrapPowers} powers * @param {{ options: { voterAddresses: Record }}} param1 diff --git a/packages/inter-protocol/src/proposals/startPSM.js b/packages/inter-protocol/src/proposals/startPSM.js index 376030591390..6bed5f4f8bf0 100644 --- a/packages/inter-protocol/src/proposals/startPSM.js +++ b/packages/inter-protocol/src/proposals/startPSM.js @@ -6,7 +6,7 @@ import { makeStorageNodeChild } from '@agoric/vats/src/lib-chainStorage.js'; import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js'; import { E } from '@endo/far'; import { Stable } from '@agoric/vats/src/tokens.js'; -import { deeplyFulfilledObject } from '@agoric/internal'; +import { deeplyFulfilledObject, zip } from '@agoric/internal'; import { makeScalarMapStore } from '@agoric/vat-data'; import { reserveThenDeposit, reserveThenGetNamePaths } from './utils.js'; @@ -360,9 +360,6 @@ export const PSM_GOV_MANIFEST = { }, }; -/** @type { (xs: X[], ys: Y[]) => [X, Y][]} */ -const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]); - /** * @param {import('./econ-behaviors').EconomyBootstrapPowers} powers * @param {{ options: { voterAddresses: Record }}} param1 diff --git a/packages/internal/src/utils.js b/packages/internal/src/utils.js index a0c3fe8e97bb..7f701e860261 100644 --- a/packages/internal/src/utils.js +++ b/packages/internal/src/utils.js @@ -341,3 +341,13 @@ export const fsStreamReady = stream => stream.on('ready', onReady); stream.on('error', onError); }); + +/** @type { (xs: X[], ys: Y[]) => [X, Y][]} */ +export const zip = (xs, ys) => harden(xs.map((x, i) => [x, ys[+i]])); + +/** @type { (obj: Record>) => Promise> } */ +export const allValues = async obj => { + const resolved = await Promise.all(Object.values(obj)); + // @ts-expect-error cast + return harden(fromEntries(zip(Object.keys(obj), resolved))); +};