Skip to content

Commit

Permalink
chore(agoric-cli): maxNodeModuleJsDepth=0 and disable ambient types
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Sep 20, 2022
1 parent 503219b commit 2057268
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"integration-test": "ava --config .ava-integration-test.config.js",
"lint-fix": "yarn lint:eslint --fix",
"lint": "run-s --continue-on-error lint:*",
"lint:types": "tsc --maxNodeModuleJsDepth 4 -p jsconfig.json",
"lint:types": "tsc --maxNodeModuleJsDepth 0 -p jsconfig.json",
"lint:eslint": "eslint ."
},
"devDependencies": {
Expand Down
11 changes: 7 additions & 4 deletions packages/agoric-cli/src/commands/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,12 @@ export const makePsmCommand = async logger => {
const opts = this.opts();
console.warn('running with options', opts);
const instance = await lookupPsmInstance(opts.pair);
// @ts-expect-error RpcRemote types not real instances
const spendAction = makePSMSpendAction(instance, agoricNames.brand, opts);
const spendAction = makePSMSpendAction(
instance,
// @ts-expect-error xxx RpcRemote
agoricNames.brand,
opts,
);
outputAction(spendAction);
});

Expand All @@ -182,7 +186,6 @@ export const makePsmCommand = async logger => {
id: Number(opts.offerId),
invitationSpec: {
source: 'purse',
// @ts-expect-error rpc
instance: economicCommittee,
description: 'Voter0', // XXX it may not always be
},
Expand Down Expand Up @@ -212,7 +215,6 @@ export const makePsmCommand = async logger => {
id: Number(opts.offerId),
invitationSpec: {
source: 'purse',
// @ts-expect-error rpc
instance: psmCharter,
description: 'PSM charter member invitation',
},
Expand Down Expand Up @@ -317,6 +319,7 @@ export const makePsmCommand = async logger => {
const psmInstance = lookupPsmInstance(opts.pair);

/** @type {import('../types.js').Brand} */
// @ts-expect-error xxx RpcRemote
const istBrand = agoricNames.brand.IST;
const scaledAmount = harden({
brand: istBrand,
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const asPercent = ratio => {
};

/**
* @param {Amount[]} balances
* @param {Array<import('../types').Amount>} balances
* @param {AssetDescriptor[]} assets
*/
export const simplePurseBalances = (balances, assets) => {
Expand Down
14 changes: 4 additions & 10 deletions packages/agoric-cli/src/lib/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { COSMOS_UNIT, makeAmountFormatter } from './format.js';
// eslint-disable-next-line no-unused-vars -- typeof below
import { makeAgoricNames } from './rpc.js';

// Ambient types. Needed only for dev but this does a runtime import.
// eslint-disable-next-line import/no-extraneous-dependencies
import '@agoric/swingset-vat/src/types-ambient.js';
import '@agoric/zoe/src/zoeService/types.js';

/** @typedef {import('@agoric/smart-wallet/src/offers').OfferSpec} OfferSpec */
/** @typedef {import('@agoric/smart-wallet/src/offers').OfferStatus} OfferStatus */
/** @typedef {import('@agoric/smart-wallet/src/smartWallet').BridgeAction} BridgeAction */
Expand All @@ -34,7 +29,6 @@ export const simpleOffers = (state, agoricNames) => {
payouts,
} = o;
const entry = Object.entries(agoricNames.instance).find(
// @ts-expect-error xxx RpcRemote
([_name, candidate]) => candidate === instance,
);
const instanceName = entry ? entry[0] : '???';
Expand All @@ -54,11 +48,11 @@ export const simpleOffers = (state, agoricNames) => {
};

/**
* @param {Record<string, Brand>} brands
* @param {Record<string, import('../types').Brand>} brands
* @param {({ wantMinted: number | undefined, giveMinted: number | undefined })} opts
* @param {number} [fee=0]
* @param {string} [anchor]
* @returns {Proposal}
* @returns {import('../types').Proposal}
*/
export const makePSMProposal = (brands, opts, fee = 0, anchor = 'AUSD') => {
const giving = opts.giveMinted ? 'minted' : 'anchor';
Expand All @@ -84,8 +78,8 @@ export const makePSMProposal = (brands, opts, fee = 0, anchor = 'AUSD') => {
};

/**
* @param {Instance} instance
* @param {Record<string, Brand>} brands
* @param {import('../types').Instance} instance
* @param {Record<string, import('../types').Brand>} brands
* @param {{ offerId: number, feePct?: number } &
* ({ wantMinted: number | undefined, giveMinted: number | undefined })} opts
* @returns {BridgeAction}
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/lib/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const makeVStorage = powers => {
* - if a part being serialized has a boardId property, it passes through as a slot value whereas the normal marshaller would treat it as a copyRecord
*
* @param {(slot: string, iface: string) => any} slotToVal
* @returns {Marshaller}
* @returns {import('@endo/marshal').Marshal<string>}
*/
export const boardSlottingMarshaller = (slotToVal = (s, _i) => s) => ({
/** @param {{body: string, slots: string[]}} capData */
Expand Down
8 changes: 5 additions & 3 deletions packages/agoric-cli/src/lib/wallet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
/* eslint-disable @typescript-eslint/prefer-ts-expect-error -- https://github.com/Agoric/agoric-sdk/issues/4620 */
import { boardSlottingMarshaller, storageHelper } from './rpc.js';

/**
Expand All @@ -16,7 +17,7 @@ export const getWalletState = async (addr, ctx, { vstorage }) => {

/** @type {Map<number, import('./psm').OfferSpec>} */
const offers = new Map();
/** @type {Map<Brand, Amount>} */
/** @type {Map<import('../types').Brand, import('../types').Amount>} */
const balances = new Map();
/** @type {import('./format').AssetDescriptor[]} */
const brands = [];
Expand All @@ -37,17 +38,18 @@ export const getWalletState = async (addr, ctx, { vstorage }) => {
case 'balance': {
const { currentAmount } = update;
if (!balances.has(currentAmount.brand)) {
// @ts-ignore https://github.com/agoric/agoric-sdk/issues/4560
balances.set(currentAmount.brand, currentAmount);
}
break;
}
case 'brand': {
// @ts-expect-error cast for unserialization hack
// @ts-ignore https://github.com/agoric/agoric-sdk/issues/4560
brands.push(update.descriptor);
break;
}
default:
// @ts-expect-error
// @ts-ignore https://github.com/agoric/agoric-sdk/issues/4560
throw Error(`unsupported update ${update.updated}`);
}
});
Expand Down
6 changes: 6 additions & 0 deletions packages/agoric-cli/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This package has maxNodeModuleJsDepth=0 to prevent ambient imports.
// A consequence is that types that are only provided ambiently have to be defined.

export { Amount, Brand, Proposal } from '@agoric/ertp/src/types-module';

export type Instance = unknown;

0 comments on commit 2057268

Please sign in to comment.