Skip to content

Commit

Permalink
refactor: internal type names
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Jul 9, 2024
1 parent bb676af commit d11f227
Show file tree
Hide file tree
Showing 194 changed files with 544 additions and 537 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Abi } from 'abitype'
import type { Address } from 'viem'

import type { Evaluate, MaybeArray, MaybePromise } from './types.js'
import type { Compute, MaybeArray, MaybePromise } from './types.js'

export type ContractConfig<
chainId extends number = number,
Expand Down Expand Up @@ -37,7 +37,7 @@ export type ContractConfig<
name: string
}

export type Contract = Evaluate<
export type Contract = Compute<
ContractConfig & {
/** Generated string content */
content: string
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pascalCase } from 'change-case'

import type { Contract, Plugin } from '../config.js'
import type { Evaluate, RequiredBy } from '../types.js'
import type { Compute, RequiredBy } from '../types.js'
import { getAddressDocString } from '../utils/getAddressDocString.js'
import { getIsPackageInstalled } from '../utils/packages.js'

Expand All @@ -16,7 +16,7 @@ export type ActionsConfig = {
overridePackageName?: '@wagmi/core' | 'wagmi' | undefined
}

type ActionsResult = Evaluate<RequiredBy<Plugin, 'run'>>
type ActionsResult = Compute<RequiredBy<Plugin, 'run'>>

export function actions(config: ActionsConfig = {}): ActionsResult {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/blockExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { z } from 'zod'

import type { ContractConfig } from '../config.js'
import { fromZodError } from '../errors.js'
import type { Evaluate } from '../types.js'
import type { Compute } from '../types.js'
import { fetch } from './fetch.js'

export type BlockExplorerConfig = {
Expand All @@ -25,7 +25,7 @@ export type BlockExplorerConfig = {
/**
* Contracts to fetch ABIs for.
*/
contracts: Evaluate<Omit<ContractConfig, 'abi'>>[]
contracts: Compute<Omit<ContractConfig, 'abi'>>[]
/**
* Function to get address from contract config.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/etherscan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ContractConfig } from '../config.js'
import type { Evaluate } from '../types.js'
import type { Compute } from '../types.js'
import { blockExplorer } from './blockExplorer.js'

const apiUrls = {
Expand Down Expand Up @@ -82,7 +82,7 @@ export type EtherscanConfig<chainId extends number> = {
/**
* Contracts to fetch ABIs for.
*/
contracts: Evaluate<Omit<ContractConfig<ChainId, chainId>, 'abi'>>[]
contracts: Compute<Omit<ContractConfig<ChainId, chainId>, 'abi'>>[]
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/plugins/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { join } from 'pathe'

import type { Abi } from 'abitype'
import type { ContractConfig, Plugin } from '../config.js'
import type { Evaluate, RequiredBy } from '../types.js'
import type { Compute, RequiredBy } from '../types.js'

export type FetchConfig = {
/**
Expand All @@ -16,12 +16,12 @@ export type FetchConfig = {
/**
* Contracts to fetch ABIs for.
*/
contracts: Evaluate<Omit<ContractConfig, 'abi'>>[]
contracts: Compute<Omit<ContractConfig, 'abi'>>[]
/**
* Function for creating a cache key for contract.
*/
getCacheKey?:
| ((config: { contract: Evaluate<Omit<ContractConfig, 'abi'>> }) => string)
| ((config: { contract: Compute<Omit<ContractConfig, 'abi'>> }) => string)
| undefined
/**
* Name of source.
Expand Down Expand Up @@ -53,7 +53,7 @@ export type FetchConfig = {
timeoutDuration?: number | undefined
}

type FetchResult = Evaluate<RequiredBy<Plugin, 'contracts'>>
type FetchResult = Compute<RequiredBy<Plugin, 'contracts'>>

/** Fetches and parses contract ABIs from network resource with `fetch`. */
export function fetch(config: FetchConfig): FetchResult {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/foundry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { z } from 'zod'

import type { ContractConfig, Plugin } from '../config.js'
import * as logger from '../logger.js'
import type { Evaluate, RequiredBy } from '../types.js'
import type { Compute, RequiredBy } from '../types.js'

const defaultExcludes = [
'Base.sol/**',
Expand Down Expand Up @@ -93,7 +93,7 @@ export type FoundryConfig = {
project?: string | undefined
}

type FoundryResult = Evaluate<
type FoundryResult = Compute<
RequiredBy<Plugin, 'contracts' | 'validate' | 'watch'>
>

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/hardhat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import pc from 'picocolors'

import type { ContractConfig, Plugin } from '../config.js'
import * as logger from '../logger.js'
import type { Evaluate, RequiredBy } from '../types.js'
import type { Compute, RequiredBy } from '../types.js'
import { getIsPackageInstalled, getPackageManager } from '../utils/packages.js'

const defaultExcludes = ['build-info/**', '*.dbg.json']
Expand Down Expand Up @@ -63,7 +63,7 @@ export type HardhatConfig = {
sources?: string | undefined
}

type HardhatResult = Evaluate<
type HardhatResult = Compute<
RequiredBy<Plugin, 'contracts' | 'validate' | 'watch'>
>

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/react.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pascalCase } from 'change-case'

import type { Contract, Plugin } from '../config.js'
import type { Evaluate, RequiredBy } from '../types.js'
import type { Compute, RequiredBy } from '../types.js'
import { getAddressDocString } from '../utils/getAddressDocString.js'

export type ReactConfig = {
Expand All @@ -14,7 +14,7 @@ export type ReactConfig = {
}) => `use${string}`)
}

type ReactResult = Evaluate<RequiredBy<Plugin, 'run'>>
type ReactResult = Compute<RequiredBy<Plugin, 'run'>>

export function react(config: ReactConfig = {}): ReactResult {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/sourcify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { z } from 'zod'

import type { ContractConfig } from '../config.js'
import { fromZodError } from '../errors.js'
import type { Evaluate } from '../types.js'
import type { Compute } from '../types.js'
import { fetch } from './fetch.js'

export type SourcifyConfig<chainId extends number> = {
Expand All @@ -26,7 +26,7 @@ export type SourcifyConfig<chainId extends number> = {
/**
* Contracts to fetch ABIs for.
*/
contracts: Evaluate<Omit<ContractConfig<ChainId, chainId>, 'abi'>>[]
contracts: Compute<Omit<ContractConfig<ChainId, chainId>, 'abi'>>[]
}

const SourcifyResponse = z.object({
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Evaluate<type> = { [key in keyof type]: type[key] } & unknown
export type Compute<type> = { [key in keyof type]: type[key] } & unknown

export type MaybeArray<T> = T | T[]

Expand Down
6 changes: 3 additions & 3 deletions packages/connectors/src/coinbaseWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type Connector,
createConnector,
} from '@wagmi/core'
import type { Evaluate, Mutable, Omit } from '@wagmi/core/internal'
import type { Compute, Mutable, Omit } from '@wagmi/core/internal'
import type {
CoinbaseWalletProvider as CBW_Provider,
CoinbaseWalletSDK as CBW_SDK,
Expand All @@ -27,14 +27,14 @@ type Version = '3' | '4'

export type CoinbaseWalletParameters<version extends Version = '3'> =
version extends '4'
? Evaluate<
? Compute<
{
headlessMode?: false | undefined
/** Coinbase Wallet SDK version */
version?: version | '3' | undefined
} & Version4Parameters
>
: Evaluate<
: Compute<
{
/**
* @deprecated `headlessMode` will be removed in the next major version. Upgrade to `version: '4'`.
Expand Down
4 changes: 2 additions & 2 deletions packages/connectors/src/metaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
createConnector,
} from '@wagmi/core'
import type {
Evaluate,
Compute,
ExactPartial,
RemoveUndefined,
} from '@wagmi/core/internal'
Expand All @@ -28,7 +28,7 @@ import {
withTimeout,
} from 'viem'

export type MetaMaskParameters = Evaluate<
export type MetaMaskParameters = Compute<
ExactPartial<Omit<MetaMaskSDKOptions, '_source' | 'readonlyRPCMap'>>
>

Expand Down
4 changes: 2 additions & 2 deletions packages/connectors/src/safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
ProviderNotFoundError,
createConnector,
} from '@wagmi/core'
import type { Evaluate } from '@wagmi/core/internal'
import type { Compute } from '@wagmi/core/internal'
import { getAddress, withTimeout } from 'viem'

export type SafeParameters = Evaluate<
export type SafeParameters = Compute<
Opts & {
/**
* Connector automatically connects when used as Safe App.
Expand Down
4 changes: 2 additions & 2 deletions packages/connectors/src/walletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ProviderNotFoundError,
createConnector,
} from '@wagmi/core'
import type { Evaluate, ExactPartial, Omit } from '@wagmi/core/internal'
import type { Compute, ExactPartial, Omit } from '@wagmi/core/internal'
import type { EthereumProvider } from '@walletconnect/ethereum-provider'
import {
type AddEthereumChainParameter,
Expand All @@ -25,7 +25,7 @@ type WalletConnectConnector = Connector & {

type EthereumProviderOptions = Parameters<(typeof EthereumProvider)['init']>[0]

export type WalletConnectParameters = Evaluate<
export type WalletConnectParameters = Compute<
{
/**
* If a new chain is added to a previously existing configured connector `chains`, this flag
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/actions/codegen/createReadContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
} from 'viem'

import type { Config } from '../../createConfig.js'
import type { UnionEvaluate, UnionOmit } from '../../types/utils.js'
import type { UnionCompute, UnionStrictOmit } from '../../types/utils.js'
import { getAccount } from '../getAccount.js'
import { getChainId } from '../getChainId.js'
import {
Expand Down Expand Up @@ -50,8 +50,8 @@ export type CreateReadContractReturnType<
args extends ContractFunctionArgs<abi, stateMutability, name>,
>(
config: config,
parameters: UnionEvaluate<
UnionOmit<
parameters: UnionCompute<
UnionStrictOmit<
ReadContractParameters<abi, name, args, config>,
omittedProperties
>
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/actions/codegen/createSimulateContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
ChainIdParameter,
ConnectorParameter,
} from '../../types/properties.js'
import type { UnionEvaluate, UnionOmit } from '../../types/utils.js'
import type { UnionCompute, UnionStrictOmit } from '../../types/utils.js'
import { getAccount } from '../getAccount.js'
import { getChainId } from '../getChainId.js'
import {
Expand Down Expand Up @@ -55,8 +55,8 @@ export type CreateSimulateContractReturnType<
>(
config: config,
parameters: {
[key in keyof chains]: UnionEvaluate<
UnionOmit<
[key in keyof chains]: UnionCompute<
UnionStrictOmit<
viem_SimulateContractParameters<
abi,
name,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/actions/codegen/createWatchContractEvent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Abi, Address, ContractEventName } from 'viem'

import type { Config } from '../../createConfig.js'
import type { UnionEvaluate, UnionOmit } from '../../types/utils.js'
import type { UnionCompute, UnionStrictOmit } from '../../types/utils.js'
import { getAccount } from '../getAccount.js'
import { getChainId } from '../getChainId.js'
import {
Expand Down Expand Up @@ -40,8 +40,8 @@ export type CreateWatchContractEventReturnType<
config['chains'][number]['id'] = config['chains'][number]['id'],
>(
config: config,
parameters: UnionEvaluate<
UnionOmit<
parameters: UnionCompute<
UnionStrictOmit<
WatchContractEventParameters<abi, name, strict, config, chainId>,
omittedProperties
>
Expand Down
12 changes: 8 additions & 4 deletions packages/core/src/actions/codegen/createWriteContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import type {
ChainIdParameter,
ConnectorParameter,
} from '../../types/properties.js'
import type { Evaluate, UnionEvaluate, UnionOmit } from '../../types/utils.js'
import type {
Compute,
UnionCompute,
UnionStrictOmit,
} from '../../types/utils.js'
import { getAccount } from '../getAccount.js'
import { getChainId } from '../getChainId.js'
import {
Expand Down Expand Up @@ -59,9 +63,9 @@ export type CreateWriteContractReturnType<
| (functionName extends undefined ? never : 'functionName'),
>(
config: config,
parameters: UnionEvaluate<
parameters: UnionCompute<
{
[key in keyof chains]: UnionOmit<
[key in keyof chains]: UnionStrictOmit<
viem_WriteContractParameters<
abi,
name,
Expand All @@ -81,7 +85,7 @@ export type CreateWriteContractReturnType<
| (chainId extends keyof address ? chainId : never)
| undefined
}
: Evaluate<ChainIdParameter<config, chainId>>) &
: Compute<ChainIdParameter<config, chainId>>) &
ConnectorParameter & { __mode?: 'prepared' }
>,
) => Promise<WriteContractReturnType>
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
type ConnectorAlreadyConnectedErrorType,
} from '../errors/config.js'
import type { ChainIdParameter } from '../types/properties.js'
import type { Evaluate } from '../types/utils.js'
import type { Compute } from '../types/utils.js'

export type ConnectParameters<config extends Config = Config> = Evaluate<
export type ConnectParameters<config extends Config = Config> = Compute<
ChainIdParameter<config> & {
connector: Connector | CreateConnectorFn
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actions/deployContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
ChainIdParameter,
ConnectorParameter,
} from '../types/properties.js'
import type { Evaluate } from '../types/utils.js'
import type { Compute } from '../types/utils.js'
import { getAction } from '../utils/getAction.js'
import {
type GetConnectorClientErrorType,
Expand All @@ -28,7 +28,7 @@ export type DeployContractParameters<
allArgs = ContractConstructorArgs<abi>,
chains extends readonly Chain[] = SelectChains<config, chainId>,
> = {
[key in keyof chains]: Evaluate<
[key in keyof chains]: Compute<
Omit<
viem_DeployContractParameters<
abi,
Expand Down
Loading

0 comments on commit d11f227

Please sign in to comment.