Skip to content

Commit

Permalink
Merge pull request #9185 from Agoric/9184-NodeNext
Browse files Browse the repository at this point in the history
adopt ESM in tsconfig
  • Loading branch information
mergify[bot] authored Apr 2, 2024
2 parents f1638f9 + 3990fe3 commit fa844b5
Show file tree
Hide file tree
Showing 64 changed files with 236 additions and 128 deletions.
43 changes: 43 additions & 0 deletions packages/ERTP/exported.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable -- doesn't understand .d.ts */
/**
* @file re-export types into global namespace, for consumers that expect these
* to be ambient
*/

// export everything
export * from './src/types.js';

// XXX re-export types into global namespace, for consumers that expect these to
// be ambient. Why the _ prefix? Because without it TS gets confused between the
// import and export symbols. h/t https://stackoverflow.com/a/66588974
// Note one big downside vs ambients is that these types will appear to be on `globalThis`.
import {
Amount as _Amount,
Brand as _Brand,
Issuer as _Issuer,
IssuerKit as _IssuerKit,
Mint as _Mint,
AssetKind as _AssetKind,
SetValue as _SetValue,
NatValue as _NatValue,
DisplayInfo as _DisplayInfo,
AdditionalDisplayInfo as _AdditionalDisplayInfo,
Payment as _Payment,
Purse as _Purse,
} from './src/types.js';
declare global {
export {
_Amount as Amount,
_Brand as Brand,
_Issuer as Issuer,
_IssuerKit as IssuerKit,
_Mint as Mint,
_AssetKind as AssetKind,
_SetValue as SetValue,
_NatValue as NatValue,
_DisplayInfo as DisplayInfo,
_AdditionalDisplayInfo as AdditionalDisplayInfo,
_Payment as Payment,
_Purse as Purse,
};
}
2 changes: 1 addition & 1 deletion packages/ERTP/exported.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import './src/types-ambient.js';
// Dummy file for .d.ts twin to declare ambients
7 changes: 4 additions & 3 deletions packages/ERTP/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"scripts": {
"build": "exit 0",
"prepack": "echo \"export {}; \" | cat - src/types-ambient.js > src/types.js && tsc --build --clean tsconfig.build.json",
"postpack": "git clean -f '*.d.ts*' src/types.js",
"prepack": "tsc --build tsconfig.build.json",
"postpack": "git clean -f '*.d.ts*'",
"test": "ava",
"test:c8": "c8 $C8_OPTIONS ava",
"test:xs": "yarn test:xs-unit && yarn test:xs-worker",
Expand Down Expand Up @@ -61,7 +61,8 @@
"files": [
"src",
"NEWS.md",
"exported.js"
"exported.js",
"exported.d.ts"
],
"ava-xs": {
"exclude": [
Expand Down
2 changes: 2 additions & 0 deletions packages/ERTP/src/amountMath.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { setMathHelpers } from './mathHelpers/setMathHelpers.js';
import { copySetMathHelpers } from './mathHelpers/copySetMathHelpers.js';
import { copyBagMathHelpers } from './mathHelpers/copyBagMathHelpers.js';

/** @import {Amount, AssetKind, AmountValue, AssetKindForValue, AssetValueForKind, Brand, MathHelpers} from './types.js' */

const { quote: q, Fail } = assert;

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/ERTP/src/amountStore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { AmountMath } from './amountMath.js';

/** @import {Amount, AssetKind, AmountValue, AssetKindForValue, AssetValueForKind, Brand, MathHelpers} from './types.js' */

/**
* @template {AssetKind} [K=AssetKind]
* @typedef {object} AmountStore
Expand Down
2 changes: 2 additions & 0 deletions packages/ERTP/src/displayInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { mustMatch } from '@agoric/store';

import { DisplayInfoShape } from './typeGuards.js';

/** @import {AdditionalDisplayInfo, AssetKind, DisplayInfo} from './types.js' */

/**
* @param {AdditionalDisplayInfo} allegedDisplayInfo
* @param {AssetKind} assetKind
Expand Down
5 changes: 3 additions & 2 deletions packages/ERTP/src/issuerKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { AssetKind, assertAssetKind } from './amountMath.js';
import { coerceDisplayInfo } from './displayInfo.js';
import { preparePaymentLedger } from './paymentLedger.js';

import './types-ambient.js';
/** @import {AdditionalDisplayInfo, RecoverySetsOption, IssuerKit, PaymentLedger} from './types.js' */
/** @import {ShutdownWithFailure} from '@agoric/swingset-vat' */

/**
* @template {AssetKind} K
Expand Down Expand Up @@ -58,7 +59,7 @@ const setupIssuerKit = (

// Attenuate the powerful authority to mint and change balances
/** @type {PaymentLedger<K>} */
// @ts-expect-error could be instantiated with different subtype of AssetKind
// @ts-expect-error could be instantiated with a different subtype
const { issuer, mint, brand, mintRecoveryPurse } = preparePaymentLedger(
issuerZone,
name,
Expand Down
2 changes: 2 additions & 0 deletions packages/ERTP/src/legacy-payment-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { mustMatch } from '@agoric/store';
import { E } from '@endo/far';
import { AmountMath } from './amountMath.js';

/** @import {Amount, AssetKind, AmountValue, AssetKindForValue, Payment, Brand, Purse} from './types.js' */

const { Fail } = assert;

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/ERTP/src/mathHelpers/copyBagMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
bagUnion,
bagDisjointSubtract,
} from '@agoric/store';
import '../types-ambient.js';

/** @import {MathHelpers} from '../types.js' */

/** @type {import('@endo/patterns').CopyBag} */
const empty = makeCopyBag([]);
Expand Down
6 changes: 5 additions & 1 deletion packages/ERTP/src/mathHelpers/copySetMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
setDisjointUnion,
setDisjointSubtract,
} from '@agoric/store';
import '../types-ambient.js';

/**
* @import {MathHelpers} from '../types.js'
* @import {CopySet} from '@endo/patterns'
*/

/** @type {CopySet} */
const empty = makeCopySet([]);
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/mathHelpers/natMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Nat, isNat } from '@endo/nat';

import '../types-ambient.js';
/** @import {MathHelpers, NatValue} from '../types.js' */

const { Fail } = assert;
const empty = 0n;
Expand Down
3 changes: 2 additions & 1 deletion packages/ERTP/src/mathHelpers/setMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
coerceToElements,
elementsCompare,
} from '@agoric/store';
import '../types-ambient.js';

/** @import {MathHelpers, SetValue} from '../types.js' */

// Operations for arrays with unique objects identifying and providing
// information about digital assets. Used for Zoe invites.
Expand Down
2 changes: 2 additions & 0 deletions packages/ERTP/src/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { initEmpty } from '@agoric/store';

/** @import {AssetKind, Brand, Payment} from './types.js' */

// TODO Type InterfaceGuard better than InterfaceGuard<any>
/**
* @template {AssetKind} K
Expand Down
5 changes: 5 additions & 0 deletions packages/ERTP/src/paymentLedger.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { preparePurseKind } from './purse.js';
import '@agoric/store/exported.js';
import { BrandI, makeIssuerInterfaces } from './typeGuards.js';

/**
* @import {Amount, AssetKind, DisplayInfo, PaymentLedger, Payment, Brand, RecoverySetsOption, Purse, Issuer, Mint} from './types.js'
* @import {ShutdownWithFailure} from '@agoric/swingset-vat'
*/

const { details: X, quote: q, Fail } = assert;

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/ERTP/src/purse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AmountMath } from './amountMath.js';
import { makeTransientNotifierKit } from './transientNotifier.js';
import { makeAmountStore } from './amountStore.js';

/** @import {Amount, AssetKind, AmountValue, AssetKindForValue, RecoverySetsOption, Brand, Payment} from './types.js' */

const { Fail } = assert;

const EMPTY_COPY_SET = makeCopySet([]);
Expand Down
2 changes: 2 additions & 0 deletions packages/ERTP/src/transientNotifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { makeScalarBigWeakMapStore } from '@agoric/vat-data';
import { provideLazy } from '@agoric/store';
import { makeNotifierKit } from '@agoric/notifier';

/** @import {Purse} from './types.js' */

// Note: Virtual for high cardinality, but *not* durable, and so
// broken across an upgrade.
export const makeTransientNotifierKit = () => {
Expand Down
1 change: 1 addition & 0 deletions packages/ERTP/src/typeGuards.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @jessie-check

import { M, matches, getInterfaceGuardPayload } from '@endo/patterns';
/** @import {AmountValue, AssetKindForValue, AssetValueForKind, Brand, MathHelpers} from './types.js' */

export const BrandShape = M.remotable('Brand');
export const IssuerShape = M.remotable('Issuer');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// @jessie-check

// Ensure this is a module.
export {};

/// <reference types="ses"/>
/**
* @import {Passable} from '@endo/pass-style')
Expand Down Expand Up @@ -210,8 +213,6 @@
* @property {AssetKind} [assetKind]
*/

/** @import {ShutdownWithFailure} from '@agoric/swingset-vat') */

/**
* @template {AssetKind} [K=AssetKind]
* @typedef {object} Mint Holding a Mint carries the right to issue new digital
Expand Down
8 changes: 6 additions & 2 deletions packages/ERTP/test/types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { Far } from '@endo/marshal';
import { expectType } from 'tsd';

import { AmountMath, AssetKind } from '../src/index.js';

import '../src/types-ambient.js';
import type {
Amount,
AssetValueForKind,
Brand,
SetValue,
} from '../src/types.js';

{
const brand: Brand<'nat'> = Far('natbrand');
Expand Down
2 changes: 2 additions & 0 deletions packages/ERTP/test/unitTests/mathHelpers/mockBrand.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Far } from '@endo/marshal';
import { AssetKind } from '../../../src/index.js';

/** @import {Brand} from '../../../src/types.js'; */

/** @type {Brand<AssetKind>} */
export const mockBrand = Far('brand', {
// eslint-disable-next-line no-unused-vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { getCopySetKeys, makeCopySet } from '@agoric/store';
import { AmountMath as m, AssetKind } from '../../../src/index.js';
import { mockBrand } from './mockBrand.js';

/** @import {CopySet} from '@endo/patterns' */

// The "unit tests" for MathHelpers actually make the calls through
// AmountMath so that we can test that any duplication is handled
// correctly.
Expand Down
2 changes: 2 additions & 0 deletions packages/ERTP/test/unitTests/test-inputValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Far } from '@endo/marshal';
import { AssetKind, makeIssuerKit, AmountMath } from '../../src/index.js';
import { claim, combine } from '../../src/legacy-payment-helpers.js';

/** @import {Amount, Issuer} from '../../src/types.js' */

test('makeIssuerKit bad allegedName', async t => {
// @ts-expect-error Intentional wrong type for testing
t.throws(() => makeIssuerKit(harden({})), { message: `{} must be a string` });
Expand Down
3 changes: 2 additions & 1 deletion packages/ERTP/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"maxNodeModuleJsDepth": 1,
},
"include": [
"exported.js",
// omit exported.js because 1) it's empty and would overwrite exported.d.ts
// and 2) because it's only for consumption in other packages
"src/**/*.js",
"src/**/*.ts",
"test"
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/deviceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function makeDeviceManager(
/** @type { DeviceInvocationResult } */
const deviceResults = dispatch.invoke(target, method, args);
// common error: raw devices returning capdata instead of ['ok', capdata]
assert.equal(deviceResults.length, 2, deviceResults);
assert.equal(deviceResults.length, 2, JSON.stringify(deviceResults));
if (deviceResults[0] === 'ok') {
insistCapData(deviceResults[1]);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export function makeXsSubprocessFactory({
]);
await closeP;

/** @type {Partial<import('@agoric/swing-store/src/snapStore.js').SnapshotInfo>} */
/** @type {Partial<import('@agoric/swing-store').SnapshotInfo>} */
const reloadSnapshotInfo = {
snapPos,
hash: snapshotResults.hash,
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/commands/inter.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const coerceBid = (offerStatus, agoricNames, warn) => {
*
* @param {import('@agoric/smart-wallet/src/offers.js').OfferStatus &
* { offerArgs: BidSpec}} bid
* @param {import('agoric/src/lib/format.js').AssetDescriptor[]} assets
* @param {import('../lib/format.js').AssetDescriptor[]} assets
*/
export const fmtBid = (bid, assets) => {
const fmt = makeFormatters(assets);
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/lib/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ harden(execSwingsetTransaction);
/**
*
* @param {import('./rpc.js').MinimalNetworkConfig} net
* @returns {Promise<import('@agoric/cosmic-proto/dist/codegen/agoric/swingset/swingset').Params>}
* @returns {Promise<import('@agoric/cosmic-proto/swingset/swingset.js').Params>}
*/
export const fetchSwingsetParams = async net => {
const { rpcAddrs } = net;
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/test/test-inter-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const agoricNames = harden({
auctioneer: makeBoardRemote({ boardId: 'board434', iface: 'Instance' }),
},

/** @type {Record<string,import('agoric/src/lib/format.js').AssetDescriptor>} */
/** @type {Record<string,import('../src/lib/format.js').AssetDescriptor>} */
vbankAsset: {
ubld: {
denom: 'ubld',
Expand Down
4 changes: 1 addition & 3 deletions packages/assert/src/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
// but we need to import it here as well.
/// <reference path="./types.js" />

/** @import {Checker} from '@endo/marshal' */

const { freeze } = Object;

/** @type {Assert} */
/** @type {import("ses").Assert} */
const globalAssert = globalThis.assert;

if (globalAssert === undefined) {
Expand Down
1 change: 0 additions & 1 deletion packages/base-zone/src/exports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
// Types exposed from modules.
//

// @ts-expect-error TS1383: Only named exports may use 'export type'.
export type * from './types.js';
2 changes: 1 addition & 1 deletion packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import type { ExecutionContext as AvaT } from 'ava';

import { makeRunUtils } from '@agoric/swingset-vat/tools/run-utils.js';
import type { CoreEvalSDKType } from '@agoric/cosmic-proto/dist/codegen/agoric/swingset/swingset';
import type { CoreEvalSDKType } from '@agoric/cosmic-proto/swingset/swingset.js';
import type { BridgeHandler } from '@agoric/vats';

const trace = makeTracer('BSTSupport', false);
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/src/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const encodeQueueSizes = queueSizes =>

/**
* Map the SwingSet parameters to a deterministic data structure.
* @param {import('@agoric/cosmic-proto/dist/codegen/agoric/swingset/swingset.js').ParamsSDKType} params
* @param {import('@agoric/cosmic-proto/swingset/swingset.js').ParamsSDKType} params
*/
export const parseParams = params => {
const {
Expand Down
4 changes: 2 additions & 2 deletions packages/cosmic-swingset/src/sim-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const defaultBeansPerUnit = [
const defaultBootstrapVatConfig =
'@agoric/vm-config/decentral-demo-config.json';

/** @type {import('@agoric/cosmic-proto/dist/codegen/agoric/swingset/swingset.js').PowerFlagFeeSDKType[]} */
/** @type {import('@agoric/cosmic-proto/swingset/swingset.js').PowerFlagFeeSDKType[]} */
export const defaultPowerFlagFees = [
{ power_flag: 'SMART_WALLET', fee: [makeCoin('ubld', 10_000_000n)] },
];
Expand All @@ -77,7 +77,7 @@ export const defaultQueueMax = [
];

/**
* @type {import('@agoric/cosmic-proto/dist/codegen/agoric/swingset/swingset.js').ParamsSDKType}
* @type {import('@agoric/cosmic-proto/swingset/swingset.js').ParamsSDKType}
*/
export const DEFAULT_SIM_SWINGSET_PARAMS = {
beans_per_unit: defaultBeansPerUnit,
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@endo/marshal": "^1.4.0",
"@endo/nat": "^5.0.5",
"@endo/promise-kit": "^1.1.0",
"jessie.js": "^0.3.2"
"jessie.js": "^0.3.4"
},
"devDependencies": {
"@agoric/smart-wallet": "^0.5.3",
Expand Down
Loading

0 comments on commit fa844b5

Please sign in to comment.