From 1323449e97e34ca48a3fd1c145876f1039e3b2d5 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 25 Apr 2024 12:01:58 -0700 Subject: [PATCH] chore(types): adopt Passable --- packages/cache/src/cache.js | 8 ++++++-- packages/cache/src/store.js | 11 ++++++----- .../src/contractGovernance/governApi.js | 5 +++-- .../src/contractGovernance/governParam.js | 1 + packages/governance/src/contractGovernorKit.js | 3 ++- packages/governance/src/types.js | 16 ++++++++++------ .../test/unitTests/test-typedParamManager.js | 2 ++ .../governance/tools/puppetContractGovernor.js | 3 ++- 8 files changed, 32 insertions(+), 17 deletions(-) diff --git a/packages/cache/src/cache.js b/packages/cache/src/cache.js index 1788745a74f5..19412f782617 100644 --- a/packages/cache/src/cache.js +++ b/packages/cache/src/cache.js @@ -4,9 +4,13 @@ import { E, Far } from '@endo/far'; import { makeScalarStoreCoordinator } from './store.js'; +/** + * @import {Passable, RemotableObject} from '@endo/pass-style'; + */ + /** * @typedef {{ [x: PropertyKey]: any } | string | symbol | bigint | null | - * undefined | number | ((oldValue: any) => ERef)} Update a `newValue` + * undefined | number | ((oldValue: any) => ERef)} Update a `newValue` * to update to. If a function, then it should take an oldValue and return a * `newValue` or promise for `newValue` */ @@ -19,7 +23,7 @@ export const makeCache = (coordinator = makeScalarStoreCoordinator()) => { * The ground state for a cache key value is `undefined`. It is impossible to * distinguish a set value of `undefined` from an unset key * - * @param {unknown} key the cache key (any key type acceptable to the cache) + * @param {Passable} key the cache key (any key type acceptable to the cache) * @param {[] | [Update] | [Update, Pattern]} optUpdateGuardPattern an optional */ const cache = (key, ...optUpdateGuardPattern) => { diff --git a/packages/cache/src/store.js b/packages/cache/src/store.js index 1619641d27cc..b3700a284e99 100644 --- a/packages/cache/src/store.js +++ b/packages/cache/src/store.js @@ -7,7 +7,7 @@ import { withGroundState, makeState } from './state.js'; /** @import {Passable} from '@endo/pass-style' */ /** - * @param {(obj: unknown) => unknown} [sanitize] + * @param {(obj: Passable) => Passable} [sanitize] * @returns {(key: Passable) => Promise} */ const makeKeyToString = (sanitize = obj => obj) => { @@ -36,16 +36,16 @@ const makeKeyToString = (sanitize = obj => obj) => { /** * @param {string} keyStr - * @param {(oldValue: unknown) => unknown} txn + * @param {(oldValue: Passable) => Passable} txn * @param {Pattern} guardPattern - * @param {(obj: unknown) => unknown} sanitize Process keys and values with + * @param {(obj: Passable) => Passable} sanitize Process keys and values with * this function before storing them * @param {{ * get(key: string): import('./state.js').State; * set(key: string, value: import('./state.js').State): void; * init(key: string, value: import('./state.js').State): void; * }} stateStore - * @returns {Promise} the value of the updated state + * @returns {Promise} the value of the updated state */ const applyCacheTransaction = async ( keyStr, @@ -112,6 +112,7 @@ const applyCacheTransaction = async ( * @returns {Promise} */ const stringifyStateStore = async (stateStore, marshaller) => { + /** @type {Passable} */ const obj = {}; for (const [key, value] of stateStore.entries()) { obj[key] = E(marshaller).toCapData(value); @@ -126,7 +127,7 @@ const stringifyStateStore = async (stateStore, marshaller) => { * currently enforce any cache eviction, but that would be a useful feature. * * @param {MapStore} [stateStore] - * @param {(obj: unknown) => unknown} [sanitize] Process keys and values with + * @param {(obj: Passable) => Passable} [sanitize] Process keys and values with * this function before storing them. Defaults to deeplyFulfilled. */ export const makeScalarStoreCoordinator = ( diff --git a/packages/governance/src/contractGovernance/governApi.js b/packages/governance/src/contractGovernance/governApi.js index 386e89e801e7..e13debafc73a 100644 --- a/packages/governance/src/contractGovernance/governApi.js +++ b/packages/governance/src/contractGovernance/governApi.js @@ -10,6 +10,7 @@ import { } from '../question.js'; /** + * @import {Passable, RemotableObject} from '@endo/pass-style'; * @import {Position, ApiGovernor, ApiInvocationIssue, PoserFacet, VoteOnApiInvocation} from '../types.js'; */ @@ -21,7 +22,7 @@ const { Fail, quote: q } = assert; * arguments that were provided. * * @param {string} apiMethodName - * @param {unknown[]} methodArgs + * @param {Passable[]} methodArgs */ const makeApiInvocationPositions = (apiMethodName, methodArgs) => { const positive = harden({ apiMethodName, methodArgs }); @@ -32,7 +33,7 @@ const makeApiInvocationPositions = (apiMethodName, methodArgs) => { /** * manage contracts that allow governance to invoke functions. * - * @param {ERef<{ [methodName: string]: (...args: any) => unknown }>} governedApis + * @param {ERef<{ [methodName: string]: (...args: any) => Passable }>} governedApis * @param {Array} governedNames names of the governed API methods * @param {ERef} timer * @param {() => Promise} getUpdatedPoserFacet diff --git a/packages/governance/src/contractGovernance/governParam.js b/packages/governance/src/contractGovernance/governParam.js index f06c7d4bb194..789a441d32a3 100644 --- a/packages/governance/src/contractGovernance/governParam.js +++ b/packages/governance/src/contractGovernance/governParam.js @@ -78,6 +78,7 @@ const setupParamGovernance = ( paramSpec, ) => { const paramMgr = await E(paramManagerRetriever).get(paramSpec.paramPath); + /** @type {import('@endo/marshal').Passable} */ const changePs = {}; for (const name of Object.keys(paramSpec.changes)) { const proposedValue = E(paramMgr).getVisibleValue( diff --git a/packages/governance/src/contractGovernorKit.js b/packages/governance/src/contractGovernorKit.js index 3bdf7e7bf6a4..b7b6abe8e5b6 100644 --- a/packages/governance/src/contractGovernorKit.js +++ b/packages/governance/src/contractGovernorKit.js @@ -129,7 +129,8 @@ export const prepareContractGovernorKit = (baggage, powers) => { ]); trace('setupApiGovernance'); apiGovernance = governedNames.length - ? setupApiGovernance(governedApis, governedNames, timer, () => + ? // @ts-expect-error FIXME + setupApiGovernance(governedApis, governedNames, timer, () => this.facets.helper.getUpdatedPoserFacet(), ) : { diff --git a/packages/governance/src/types.js b/packages/governance/src/types.js index f909ee5b0042..3a3f0b531a10 100644 --- a/packages/governance/src/types.js +++ b/packages/governance/src/types.js @@ -1,6 +1,10 @@ export {}; -/** @import {ContractStartFunction} from '@agoric/zoe/src/zoeService/utils.js' */ +/** + * @import {Guarded} from '@endo/exo'; + * @import {Passable, Container} from '@endo/pass-style'; + * @import {ContractStartFunction} from '@agoric/zoe/src/zoeService/utils.js'; + */ /** * @typedef { 'unranked' | 'order' | 'plurality' } ChoiceMethod @@ -34,9 +38,9 @@ export {}; */ /** - * @typedef { Amount | Brand | Installation | Instance | bigint | + * @typedef { Amount | Brand | Installation | Instance | number | bigint | * Ratio | string | import('@agoric/time').TimestampRecord | - * import('@agoric/time').RelativeTimeRecord | unknown } ParamValue + * import('@agoric/time').RelativeTimeRecord | Container } ParamValue */ // XXX better to use the manifest constant ParamTypes @@ -484,7 +488,7 @@ export {}; /** * @typedef {object} ChangeParamsPosition - * @property {Record} changes one or more changes to parameters + * @property {Record} changes one or more changes to parameters */ /** @@ -500,7 +504,7 @@ export {}; /** * @typedef {object} InvokeApiPosition * @property {string} apiMethodName - * @property {unknown[]} methodArgs + * @property {Passable[]} methodArgs */ /** @@ -625,7 +629,7 @@ export {}; /** * @callback VoteOnApiInvocation * @param {string} apiMethodName - * @param {unknown[]} methodArgs + * @param {Passable[]} methodArgs * @param {Installation} voteCounterInstallation * @param {import('@agoric/time').Timestamp} deadline * @returns {Promise} diff --git a/packages/governance/test/unitTests/test-typedParamManager.js b/packages/governance/test/unitTests/test-typedParamManager.js index 505d826acfa8..a4ef53487db7 100644 --- a/packages/governance/test/unitTests/test-typedParamManager.js +++ b/packages/governance/test/unitTests/test-typedParamManager.js @@ -228,6 +228,7 @@ test('Invitation', async t => { const { instance, zcf, zoe } = await setupZCFTest(issuerKeywordRecord, terms); + /** @type {Invitation} */ const invitation = await E(E(zoe).getPublicFacet(instance)).makeInvitation(); const invitationAmount = await E(E(zoe).getInvitationIssuer()).getAmountOf( @@ -251,6 +252,7 @@ test('Invitation', async t => { await eventLoopIteration(); const invitationActualAmount = paramManager.getInvite().value; t.deepEqual(invitationActualAmount, invitationAmount.value); + // @ts-expect-error XXX t.is(invitationActualAmount[0].description, 'simple'); t.is(await paramManager.getInternalParamValue('Invite'), invitation); diff --git a/packages/governance/tools/puppetContractGovernor.js b/packages/governance/tools/puppetContractGovernor.js index 3f6db072a1d4..d4edd79883b4 100644 --- a/packages/governance/tools/puppetContractGovernor.js +++ b/packages/governance/tools/puppetContractGovernor.js @@ -7,6 +7,7 @@ import { CONTRACT_ELECTORATE } from '../src/contractGovernance/governParam.js'; import { makeApiInvocationPositions } from '../src/contractGovernance/governApi.js'; /** + * @import {Passable, RemotableObject} from '@endo/pass-style'; * @import {GovernableStartFn, ParamChangesSpec} from '../src/types.js'; */ @@ -72,7 +73,7 @@ export const start = async (zcf, privateArgs) => { /** * @param {string} apiMethodName - * @param {unknown[]} methodArgs + * @param {Passable[]} methodArgs */ const invokeAPI = async (apiMethodName, methodArgs) => { const governedNames = await E(governedCF).getGovernedApiNames();