|
1 | 1 | // To extend one of Hardhat's types, you need to import the module where it has been defined, and redeclare it. |
2 | 2 | import 'hardhat/types/config' |
3 | 3 | import 'hardhat/types/runtime' |
4 | | - |
5 | | -import type { GraphDeployment, GraphDeploymentRuntimeEnvironmentMap } from './deployments' |
6 | | -import type { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider' |
7 | | - |
8 | | -export type GraphRuntimeEnvironmentOptions = { |
9 | | - deployments?: { |
10 | | - [deployment in GraphDeployment]?: string | { |
11 | | - addressBook: string |
12 | | - } |
13 | | - } |
14 | | -} |
15 | | - |
16 | | -export type GraphRuntimeEnvironment = { |
17 | | - [deployment in keyof GraphDeploymentRuntimeEnvironmentMap]?: GraphDeploymentRuntimeEnvironmentMap[deployment] |
18 | | -} & { |
19 | | - provider: HardhatEthersProvider |
20 | | - chainId: number |
21 | | -} |
22 | | - |
23 | | -export function assertGraphRuntimeEnvironment( |
24 | | - obj: unknown, |
25 | | -): obj is GraphRuntimeEnvironment { |
26 | | - if (typeof obj !== 'object' || obj === null) return false |
27 | | - |
28 | | - const deployments = obj as Partial<GraphDeploymentRuntimeEnvironmentMap> |
29 | | - |
30 | | - for (const deployment in deployments) { |
31 | | - const environment = deployments[deployment as keyof GraphDeploymentRuntimeEnvironmentMap] |
32 | | - if (!environment || typeof environment !== 'object') { |
33 | | - return false |
34 | | - } |
35 | | - } |
36 | | - |
37 | | - if (typeof (obj as GraphRuntimeEnvironment).provider !== 'object') { |
38 | | - return false |
39 | | - } |
40 | | - |
41 | | - if (typeof (obj as GraphRuntimeEnvironment).chainId !== 'function') { |
42 | | - return false |
43 | | - } |
44 | | - |
45 | | - return true |
46 | | -} |
| 4 | +import type { GraphDeployments, GraphRuntimeEnvironment, GraphRuntimeEnvironmentOptions } from './types' |
47 | 5 |
|
48 | 6 | declare module 'hardhat/types/runtime' { |
49 | | - export interface HardhatRuntimeEnvironment { |
| 7 | + interface HardhatRuntimeEnvironment { |
50 | 8 | graph: (opts?: GraphRuntimeEnvironmentOptions) => GraphRuntimeEnvironment |
51 | 9 | } |
52 | 10 | } |
53 | 11 |
|
54 | 12 | declare module 'hardhat/types/config' { |
55 | | - export interface HardhatConfig { |
| 13 | + interface HardhatConfig { |
56 | 14 | graph: GraphRuntimeEnvironmentOptions |
57 | 15 | } |
58 | 16 |
|
59 | | - export interface HardhatUserConfig { |
| 17 | + interface HardhatUserConfig { |
60 | 18 | graph: GraphRuntimeEnvironmentOptions |
61 | 19 | } |
62 | 20 |
|
63 | | - export interface HardhatNetworkConfig { |
64 | | - deployments?: { |
65 | | - [deployment in GraphDeployment]?: string | { |
66 | | - addressBook: string |
67 | | - } |
68 | | - } |
| 21 | + interface HardhatNetworkConfig { |
| 22 | + deployments?: GraphDeployments |
69 | 23 | } |
70 | 24 |
|
71 | | - export interface HardhatNetworkUserConfig { |
72 | | - deployments?: { |
73 | | - [deployment in GraphDeployment]?: string | { |
74 | | - addressBook: string |
75 | | - } |
76 | | - } |
| 25 | + interface HardhatNetworkUserConfig { |
| 26 | + deployments?: GraphDeployments |
77 | 27 | } |
78 | 28 |
|
79 | | - export interface HttpNetworkConfig { |
80 | | - deployments?: { |
81 | | - [deployment in GraphDeployment]?: string | { |
82 | | - addressBook: string |
83 | | - } |
84 | | - } |
| 29 | + interface HttpNetworkConfig { |
| 30 | + deployments?: GraphDeployments |
85 | 31 | } |
86 | 32 |
|
87 | | - export interface HttpNetworkUserConfig { |
88 | | - deployments?: { |
89 | | - [deployment in GraphDeployment]?: string | { |
90 | | - addressBook: string |
91 | | - } |
92 | | - } |
| 33 | + interface HttpNetworkUserConfig { |
| 34 | + deployments?: GraphDeployments |
93 | 35 | } |
94 | 36 |
|
95 | | - export interface ProjectPathsConfig { |
| 37 | + interface ProjectPathsConfig { |
96 | 38 | graph?: string |
97 | 39 | } |
98 | 40 |
|
99 | | - export interface ProjectPathsUserConfig { |
| 41 | + interface ProjectPathsUserConfig { |
100 | 42 | graph?: string |
101 | 43 | } |
102 | 44 | } |
0 commit comments