Skip to content

Commit

Permalink
feat(types): ExoObj utility
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Feb 28, 2024
1 parent 111247f commit 47867d0
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/governance/src/contractGovernorKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,4 @@ export const prepareContractGovernorKit = (baggage, powers) => {
return makeContractGovernorKit;
};

/** @typedef {ReturnType<ReturnType<typeof prepareContractGovernorKit>>} ContractGovernorKit */
/** @typedef {import('@agoric/internal').ExoObj<typeof prepareContractGovernorKit>} ContractGovernorKit */
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const build = async (log, zoe) => {
};

/**
* @typedef {ReturnType<Awaited<ReturnType<typeof build>>['createVoter']>} EVatVoter
* @typedef {import('@agoric/internal').ExoObjtypeof build>>['createVoter']>} EVatVoter
*/

/** @type {import('@agoric/swingset-vat/src/kernel/vat-loader/types.js').BuildRootObjectForTestVat} */
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/auction/auctionBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,4 +789,4 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
};
harden(prepareAuctionBook);

/** @typedef {ReturnType<ReturnType<typeof prepareAuctionBook>>} AuctionBook */
/** @typedef {import('@agoric/internal').ExoObj<typeof prepareAuctionBook>} AuctionBook */
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/price/fluxAggregatorKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,4 @@ export const prepareFluxAggregatorKit = async (
return makeFluxAggregatorKit;
};
harden(prepareFluxAggregatorKit);
/** @typedef {ReturnType<Awaited<ReturnType<typeof prepareFluxAggregatorKit>>>} FluxAggregatorKit */
/** @typedef {import('@agoric/internal').ExoObjtypeof prepareFluxAggregatorKit>>>} FluxAggregatorKit */
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/price/priceOracleKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ export const prepareOracleAdminKit = baggage =>
},
);

/** @typedef {ReturnType<ReturnType<typeof prepareOracleAdminKit>>} OracleKit */
/** @typedef {import('@agoric/internal').ExoObj<typeof prepareOracleAdminKit>} OracleKit */
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/reserve/assetReserveKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,4 @@ export const prepareAssetReserveKit = async (
return makeAssetReserveKit;
};
harden(prepareAssetReserveKit);
/** @typedef {ReturnType<Awaited<ReturnType<typeof prepareAssetReserveKit>>>} AssetReserveKit */
/** @typedef {import('@agoric/internal').ExoObjtypeof prepareAssetReserveKit>>>} AssetReserveKit */
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/vaultFactory/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,4 +867,4 @@ export const prepareVault = (baggage, makeRecorderKit, zcf) => {
return maker;
};

/** @typedef {ReturnType<ReturnType<typeof prepareVault>>['self']} Vault */
/** @typedef {import('@agoric/internal').ExoObj<typeof prepareVault>['self']} Vault */
3 changes: 2 additions & 1 deletion packages/inter-protocol/src/vaultFactory/vaultDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,14 @@ const prepareVaultDirector = (
return makeVaultDirector;
};
harden(prepareVaultDirector);
/** @typedef {import('@agoric/internal').ExoObj<typeof prepareVaultDirector>} VaultDirector */

/**
* Prepare the VaultDirector kind, get or make the singleton
*
* @type {(
* ...pvdArgs: Parameters<typeof prepareVaultDirector>
* ) => ReturnType<ReturnType<typeof prepareVaultDirector>>}
* ) => VaultDirector}
*/
export const provideDirector = (...args) => {
const makeVaultDirector = prepareVaultDirector(...args);
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/vaultFactory/vaultKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ export const prepareVaultKit = (baggage, makeRecorderKit) => {
return makeVaultKit;
};

/** @typedef {ReturnType<ReturnType<typeof prepareVaultKit>>} VaultKit */
/** @typedef {import('@agoric/internal').ExoObj<typeof prepareVaultKit>} VaultKit */
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/vaultFactory/vaultManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ export const prepareVaultManagerKit = (
return makeVaultManagerKit;
};

/** @typedef {Awaited<ReturnType<ReturnType<typeof prepareVaultManagerKit>>>} VaultManagerKit */
/** @typedef {import('@agoric/internal').ExoObj<typeof prepareVaultManagerKit>} VaultManagerKit */
/**
* @typedef {VaultManagerKit['self']} VaultManager Each VaultManager manages a
* single collateral type.
Expand Down
2 changes: 2 additions & 0 deletions packages/internal/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export * from './debug.js';
export * from './utils.js';
export * from './method-tools.js';
export * from './typeGuards.js';
// eslint-disable-next-line import/no-unresolved -- implemented as .d.ts
export * from './types.js';

export { objectMap } from '@endo/common/object-map.js';
export { fromUniqueEntries } from '@endo/common/from-unique-entries.js';
2 changes: 2 additions & 0 deletions packages/internal/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ export declare class SyncCallback<

public isSync: true;
}

export type ExoObj<T> = Awaited<ReturnType<Awaited<ReturnType<T>>>>;
3 changes: 1 addition & 2 deletions packages/smart-wallet/src/smartWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1187,5 +1187,4 @@ export const prepareSmartWallet = (baggage, shared) => {
return makeSmartWallet;
};
harden(prepareSmartWallet);

/** @typedef {Awaited<ReturnType<ReturnType<typeof prepareSmartWallet>>>} SmartWallet */
/** @typedef {import('@agoric/internal').ExoObj<typeof prepareSmartWallet>} SmartWallet */
2 changes: 1 addition & 1 deletion packages/vats/src/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const prepareBridgeManager = (zone, D) => {
/**
* @type {MapStore<
* string,
* ReturnType<ReturnType<typeof prepareScopedManager>>
* import('@agoric/internal').ExoObj<typeof prepareScopedManager>
* >}
*/
scopedManagers: zone.detached().mapStore('scopedManagers'),
Expand Down
8 changes: 6 additions & 2 deletions packages/vats/src/localchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ const prepareLocalChainAccount = zone =>
},
},
);
/**
* @typedef {import('@agoric/internal').ExoObj<
* typeof prepareLocalChainAccount
* >} LocalChainAccount
*/

export const LocalChainI = M.interface('LocalChain', {
createAccount: M.callWhen().returns(M.remotable('LocalChainAccount')),
Expand Down Expand Up @@ -92,6 +97,7 @@ const prepareLocalChain = (zone, createAccount) =>
},
},
);
/** @typedef {import('@agoric/internal').ExoObj<typeof prepareLocalChain>} LocalChain */

/** @param {import('@agoric/base-zone').Zone} zone */
export const prepareLocalChainTools = zone => {
Expand All @@ -101,6 +107,4 @@ export const prepareLocalChainTools = zone => {
return harden({ makeLocalChain });
};
harden(prepareLocalChainTools);

/** @typedef {ReturnType<typeof prepareLocalChainTools>} LocalChainTools */
/** @typedef {ReturnType<LocalChainTools['makeLocalChain']>} LocalChain */
2 changes: 1 addition & 1 deletion packages/vats/src/vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const BridgeChannelI = M.interface('BridgeChannel', {
/**
* @typedef {import('./virtual-purse.js').VirtualPurseController} VirtualPurseController
*
* @typedef {Awaited<ReturnType<ReturnType<typeof prepareVirtualPurse>>>} VirtualPurse
* @typedef {import('@agoric/internal').ExoObj<typeof prepareVirtualPurse>} VirtualPurse
*/

/**
Expand Down
1 change: 1 addition & 0 deletions packages/vow/src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export const prepareVowTools = (zone, powers = {}) => {
return harden({ when, watch, makeVowKit });
};
harden(prepareVowTools);
/** @type {import('@agoric/internal').ExoObj<typeof prepareVowTools>} VowTools */

0 comments on commit 47867d0

Please sign in to comment.