diff --git a/packages/SwingSet/src/controller/initializeSwingset.js b/packages/SwingSet/src/controller/initializeSwingset.js index 4adb8bb1155e..f6cc7b977c74 100644 --- a/packages/SwingSet/src/controller/initializeSwingset.js +++ b/packages/SwingSet/src/controller/initializeSwingset.js @@ -4,6 +4,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'; @@ -11,24 +12,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 5408fb2242a1..6193d2b13234 100644 --- a/packages/inter-protocol/src/collect.js +++ b/packages/inter-protocol/src/collect.js @@ -1,11 +1 @@ -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 f4da273b8af7..ed22946d0215 100644 --- a/packages/inter-protocol/src/proposals/startPSM.js +++ b/packages/inter-protocol/src/proposals/startPSM.js @@ -4,7 +4,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 b084680cb588..7f1e2ecca26d 100644 --- a/packages/internal/src/utils.js +++ b/packages/internal/src/utils.js @@ -353,3 +353,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))); +};