@graphprotocol/graph-cli 0.37.3 → 0.37.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +5 -1
  3. package/babel.config.js +0 -3
  4. package/jest.config.js +0 -175
  5. package/src/bin.ts +0 -6
  6. package/src/cli.ts +0 -30
  7. package/src/codegen/schema.test.ts +0 -460
  8. package/src/codegen/schema.ts +0 -299
  9. package/src/codegen/template.ts +0 -45
  10. package/src/codegen/types/conversions.ts +0 -358
  11. package/src/codegen/types/index.test.ts +0 -715
  12. package/src/codegen/types/index.ts +0 -111
  13. package/src/codegen/typescript.ts +0 -224
  14. package/src/codegen/util.test.ts +0 -112
  15. package/src/codegen/util.ts +0 -54
  16. package/src/command-helpers/abi.ts +0 -99
  17. package/src/command-helpers/auth.ts +0 -46
  18. package/src/command-helpers/compiler.ts +0 -60
  19. package/src/command-helpers/data-sources.ts +0 -36
  20. package/src/command-helpers/fs.ts +0 -5
  21. package/src/command-helpers/gluegun.ts +0 -52
  22. package/src/command-helpers/ipfs-http-client.d.ts +0 -1
  23. package/src/command-helpers/ipfs.ts +0 -3
  24. package/src/command-helpers/jsonrpc.ts +0 -22
  25. package/src/command-helpers/network.test.ts +0 -85
  26. package/src/command-helpers/network.ts +0 -133
  27. package/src/command-helpers/node.ts +0 -46
  28. package/src/command-helpers/scaffold.ts +0 -174
  29. package/src/command-helpers/spinner.ts +0 -60
  30. package/src/command-helpers/studio.test.ts +0 -84
  31. package/src/command-helpers/studio.ts +0 -25
  32. package/src/command-helpers/subgraph.ts +0 -21
  33. package/src/command-helpers/version.test.ts +0 -241
  34. package/src/command-helpers/version.ts +0 -53
  35. package/src/commands/add.ts +0 -220
  36. package/src/commands/auth.ts +0 -138
  37. package/src/commands/binary-install-raw.d.ts +0 -1
  38. package/src/commands/build.ts +0 -147
  39. package/src/commands/codegen.ts +0 -123
  40. package/src/commands/create.ts +0 -109
  41. package/src/commands/deploy.ts +0 -388
  42. package/src/commands/init.ts +0 -1060
  43. package/src/commands/local.ts +0 -539
  44. package/src/commands/remove.ts +0 -110
  45. package/src/commands/test.ts +0 -369
  46. package/src/compiler/asc.ts +0 -77
  47. package/src/compiler/index.ts +0 -677
  48. package/src/debug.ts +0 -15
  49. package/src/migrations/mapping_api_version_0_0_1.ts +0 -75
  50. package/src/migrations/mapping_api_version_0_0_2.ts +0 -75
  51. package/src/migrations/mapping_api_version_0_0_3.ts +0 -75
  52. package/src/migrations/mapping_api_version_0_0_4.ts +0 -77
  53. package/src/migrations/mapping_api_version_0_0_5.ts +0 -77
  54. package/src/migrations/spec_version_0_0_2.ts +0 -24
  55. package/src/migrations/spec_version_0_0_3.ts +0 -29
  56. package/src/migrations/util/load-manifest.ts +0 -10
  57. package/src/migrations/util/versions.ts +0 -27
  58. package/src/migrations.ts +0 -33
  59. package/src/protocols/arweave/manifest.graphql +0 -57
  60. package/src/protocols/arweave/scaffold/manifest.ts +0 -14
  61. package/src/protocols/arweave/scaffold/mapping.ts +0 -49
  62. package/src/protocols/arweave/subgraph.ts +0 -22
  63. package/src/protocols/contract.ts +0 -9
  64. package/src/protocols/cosmos/manifest.graphql +0 -76
  65. package/src/protocols/cosmos/scaffold/manifest.ts +0 -11
  66. package/src/protocols/cosmos/scaffold/mapping.ts +0 -35
  67. package/src/protocols/cosmos/subgraph.ts +0 -27
  68. package/src/protocols/ethereum/abi.ts +0 -153
  69. package/src/protocols/ethereum/codegen/abi.test.ts +0 -330
  70. package/src/protocols/ethereum/codegen/abi.ts +0 -719
  71. package/src/protocols/ethereum/codegen/template.ts +0 -41
  72. package/src/protocols/ethereum/contract.ts +0 -24
  73. package/src/protocols/ethereum/manifest.graphql +0 -94
  74. package/src/protocols/ethereum/scaffold/manifest.ts +0 -28
  75. package/src/protocols/ethereum/scaffold/mapping.ts +0 -76
  76. package/src/protocols/ethereum/subgraph.ts +0 -189
  77. package/src/protocols/ethereum/type-generator.ts +0 -191
  78. package/src/protocols/index.ts +0 -287
  79. package/src/protocols/ipfs/codegen/file_template.ts +0 -43
  80. package/src/protocols/near/contract.ts +0 -47
  81. package/src/protocols/near/manifest.graphql +0 -64
  82. package/src/protocols/near/scaffold/manifest.ts +0 -13
  83. package/src/protocols/near/scaffold/mapping.ts +0 -35
  84. package/src/protocols/near/subgraph.ts +0 -22
  85. package/src/protocols/subgraph.ts +0 -12
  86. package/src/protocols/substreams/manifest.graphql +0 -45
  87. package/src/protocols/substreams/scaffold/manifest.ts +0 -8
  88. package/src/protocols/substreams/subgraph.ts +0 -22
  89. package/src/scaffold/cosmos.test.ts +0 -83
  90. package/src/scaffold/ethereum.test.ts +0 -512
  91. package/src/scaffold/index.ts +0 -172
  92. package/src/scaffold/mapping.ts +0 -44
  93. package/src/scaffold/near.test.ts +0 -86
  94. package/src/scaffold/schema.ts +0 -89
  95. package/src/scaffold/tests.ts +0 -217
  96. package/src/schema.ts +0 -26
  97. package/src/subgraph.ts +0 -302
  98. package/src/type-generator.ts +0 -266
  99. package/src/validation/contract.ts +0 -51
  100. package/src/validation/index.ts +0 -5
  101. package/src/validation/manifest.ts +0 -360
  102. package/src/validation/schema.test.ts +0 -38
  103. package/src/validation/schema.ts +0 -957
  104. package/src/watcher.ts +0 -96
  105. package/tests/cli/globalSetup.ts +0 -8
  106. package/tests/cli/globalTeardown.ts +0 -8
  107. package/tests/cli/init/ethereum/abis/Marketplace.json +0 -408
  108. package/tests/cli/init/ethereum/abis/OverloadedElements.json +0 -91
  109. package/tests/cli/init/ethereum/abis/SoloMargin.json +0 -2729
  110. package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stderr +0 -14
  111. package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stdout +0 -12
  112. package/tests/cli/init/ethereum/from-contract-with-abi.stderr +0 -14
  113. package/tests/cli/init/ethereum/from-contract-with-abi.stdout +0 -12
  114. package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stderr +0 -14
  115. package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stdout +0 -12
  116. package/tests/cli/init/ethereum/from-contract.stderr +0 -16
  117. package/tests/cli/init/ethereum/from-contract.stdout +0 -12
  118. package/tests/cli/init/ethereum/from-example.stderr +0 -12
  119. package/tests/cli/init/ethereum/from-example.stdout +0 -12
  120. package/tests/cli/init/near/from-contract.stderr +0 -14
  121. package/tests/cli/init/near/from-contract.stdout +0 -12
  122. package/tests/cli/init.test.ts +0 -157
  123. package/tests/cli/spawn-command.d.ts +0 -7
  124. package/tests/cli/util.ts +0 -132
  125. package/tests/cli/validation/abi-not-found/Abi.json +0 -7
  126. package/tests/cli/validation/abi-not-found/mapping.ts +0 -0
  127. package/tests/cli/validation/abi-not-found/schema.graphql +0 -3
  128. package/tests/cli/validation/abi-not-found/subgraph.yaml +0 -42
  129. package/tests/cli/validation/abi-not-found copy.stderr +0 -13
  130. package/tests/cli/validation/big-decimal-is-valid/Abi.json +0 -7
  131. package/tests/cli/validation/big-decimal-is-valid/mapping.ts +0 -0
  132. package/tests/cli/validation/big-decimal-is-valid/schema.graphql +0 -4
  133. package/tests/cli/validation/big-decimal-is-valid/subgraph.yaml +0 -23
  134. package/tests/cli/validation/call-function-not-found/Abi.json +0 -57
  135. package/tests/cli/validation/call-function-not-found/mapping.ts +0 -0
  136. package/tests/cli/validation/call-function-not-found/schema.graphql +0 -3
  137. package/tests/cli/validation/call-function-not-found/subgraph.yaml +0 -22
  138. package/tests/cli/validation/call-function-not-found.stderr +0 -10
  139. package/tests/cli/validation/call-handler-with-tuple/Abi.json +0 -24
  140. package/tests/cli/validation/call-handler-with-tuple/generated/schema.ts +0 -44
  141. package/tests/cli/validation/call-handler-with-tuple/mapping.ts +0 -0
  142. package/tests/cli/validation/call-handler-with-tuple/schema.graphql +0 -3
  143. package/tests/cli/validation/call-handler-with-tuple/subgraph.yaml +0 -22
  144. package/tests/cli/validation/call-handler-with-tuple.stderr +0 -24
  145. package/tests/cli/validation/conflicting-network-names/Abi.json +0 -7
  146. package/tests/cli/validation/conflicting-network-names/mapping.ts +0 -0
  147. package/tests/cli/validation/conflicting-network-names/schema.graphql +0 -3
  148. package/tests/cli/validation/conflicting-network-names/subgraph.yaml +0 -41
  149. package/tests/cli/validation/conflicting-network-names.stderr +0 -10
  150. package/tests/cli/validation/conflicting-protocol-names/Abi.json +0 -7
  151. package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
  152. package/tests/cli/validation/conflicting-protocol-names/schema.graphql +0 -3
  153. package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +0 -41
  154. package/tests/cli/validation/conflicting-protocol-names.stderr +0 -10
  155. package/tests/cli/validation/derived-from-target-type-missing/Abi.json +0 -6
  156. package/tests/cli/validation/derived-from-target-type-missing/mapping.ts +0 -0
  157. package/tests/cli/validation/derived-from-target-type-missing/schema.graphql +0 -4
  158. package/tests/cli/validation/derived-from-target-type-missing/subgraph.yaml +0 -22
  159. package/tests/cli/validation/derived-from-target-type-missing.stderr +0 -5
  160. package/tests/cli/validation/derived-from-with-interface/Gravity.json +0 -1
  161. package/tests/cli/validation/derived-from-with-interface/mapping.ts +0 -22
  162. package/tests/cli/validation/derived-from-with-interface/schema.graphql +0 -19
  163. package/tests/cli/validation/derived-from-with-interface/subgraph.yaml +0 -25
  164. package/tests/cli/validation/duplicate-data-source-name/Abi.json +0 -7
  165. package/tests/cli/validation/duplicate-data-source-name/mapping.ts +0 -0
  166. package/tests/cli/validation/duplicate-data-source-name/schema.graphql +0 -4
  167. package/tests/cli/validation/duplicate-data-source-name/subgraph.yaml +0 -40
  168. package/tests/cli/validation/duplicate-data-source-name.stderr +0 -5
  169. package/tests/cli/validation/duplicate-template-name/Abi.json +0 -7
  170. package/tests/cli/validation/duplicate-template-name/mapping.ts +0 -0
  171. package/tests/cli/validation/duplicate-template-name/schema.graphql +0 -4
  172. package/tests/cli/validation/duplicate-template-name/subgraph.yaml +0 -59
  173. package/tests/cli/validation/duplicate-template-name.stderr +0 -5
  174. package/tests/cli/validation/entity-field-args/Abi.json +0 -7
  175. package/tests/cli/validation/entity-field-args/mapping.ts +0 -0
  176. package/tests/cli/validation/entity-field-args/schema.graphql +0 -4
  177. package/tests/cli/validation/entity-field-args/subgraph.yaml +0 -22
  178. package/tests/cli/validation/entity-field-args.stderr +0 -5
  179. package/tests/cli/validation/ethereum-contract-without-handlers/Abi.json +0 -7
  180. package/tests/cli/validation/ethereum-contract-without-handlers/mapping.ts +0 -0
  181. package/tests/cli/validation/ethereum-contract-without-handlers/schema.graphql +0 -3
  182. package/tests/cli/validation/ethereum-contract-without-handlers/subgraph.yaml +0 -19
  183. package/tests/cli/validation/ethereum-contract-without-handlers.stderr +0 -6
  184. package/tests/cli/validation/event-not-found/Abi.json +0 -7
  185. package/tests/cli/validation/event-not-found/mapping.ts +0 -0
  186. package/tests/cli/validation/event-not-found/schema.graphql +0 -3
  187. package/tests/cli/validation/event-not-found/subgraph.yaml +0 -40
  188. package/tests/cli/validation/event-not-found.stderr +0 -12
  189. package/tests/cli/validation/example-values-found/Abi.json +0 -7
  190. package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts +0 -35
  191. package/tests/cli/validation/example-values-found/generated/schema.ts +0 -44
  192. package/tests/cli/validation/example-values-found/mapping.ts +0 -0
  193. package/tests/cli/validation/example-values-found/schema.graphql +0 -3
  194. package/tests/cli/validation/example-values-found/subgraph.yaml +0 -24
  195. package/tests/cli/validation/example-values-found.stderr +0 -34
  196. package/tests/cli/validation/invalid-abis/InvalidAbi.json +0 -1
  197. package/tests/cli/validation/invalid-abis/mapping.ts +0 -0
  198. package/tests/cli/validation/invalid-abis/schema.graphql +0 -3
  199. package/tests/cli/validation/invalid-abis/subgraph.yaml +0 -22
  200. package/tests/cli/validation/invalid-abis.stderr +0 -5
  201. package/tests/cli/validation/invalid-contract-addresses/Abi.json +0 -7
  202. package/tests/cli/validation/invalid-contract-addresses/mapping.ts +0 -0
  203. package/tests/cli/validation/invalid-contract-addresses/schema.graphql +0 -3
  204. package/tests/cli/validation/invalid-contract-addresses/subgraph.yaml +0 -58
  205. package/tests/cli/validation/invalid-contract-addresses.stderr +0 -14
  206. package/tests/cli/validation/invalid-data-source-template/mapping.ts +0 -0
  207. package/tests/cli/validation/invalid-data-source-template/schema.graphql +0 -3
  208. package/tests/cli/validation/invalid-data-source-template/subgraph.yaml +0 -32
  209. package/tests/cli/validation/invalid-data-source-template.stderr +0 -30
  210. package/tests/cli/validation/invalid-entity-field-types/Abi.json +0 -7
  211. package/tests/cli/validation/invalid-entity-field-types/mapping.ts +0 -0
  212. package/tests/cli/validation/invalid-entity-field-types/schema.graphql +0 -157
  213. package/tests/cli/validation/invalid-entity-field-types/subgraph.yaml +0 -22
  214. package/tests/cli/validation/invalid-entity-field-types.stderr +0 -148
  215. package/tests/cli/validation/invalid-fulltext-directive/Abi.json +0 -7
  216. package/tests/cli/validation/invalid-fulltext-directive/mapping.ts +0 -0
  217. package/tests/cli/validation/invalid-fulltext-directive/schema.graphql +0 -140
  218. package/tests/cli/validation/invalid-fulltext-directive/subgraph.yaml +0 -22
  219. package/tests/cli/validation/invalid-fulltext-directive.stderr +0 -32
  220. package/tests/cli/validation/invalid-graphql-schema/Abi.json +0 -7
  221. package/tests/cli/validation/invalid-graphql-schema/mapping.ts +0 -0
  222. package/tests/cli/validation/invalid-graphql-schema/schema.graphql +0 -8
  223. package/tests/cli/validation/invalid-graphql-schema/subgraph.yaml +0 -22
  224. package/tests/cli/validation/invalid-graphql-schema.stderr +0 -25
  225. package/tests/cli/validation/invalid-manifest/subgraph.yaml +0 -13
  226. package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +0 -12
  227. package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +0 -5
  228. package/tests/cli/validation/invalid-manifest.stderr +0 -28
  229. package/tests/cli/validation/missing-entity-id/Abi.json +0 -7
  230. package/tests/cli/validation/missing-entity-id/mapping.ts +0 -0
  231. package/tests/cli/validation/missing-entity-id/schema.graphql +0 -3
  232. package/tests/cli/validation/missing-entity-id/subgraph.yaml +0 -22
  233. package/tests/cli/validation/missing-entity-id/types/ExampleSubgraph/ExampleContract.ts +0 -35
  234. package/tests/cli/validation/missing-entity-id/types/schema.ts +0 -27
  235. package/tests/cli/validation/missing-entity-id.stderr +0 -5
  236. package/tests/cli/validation/missing-or-invalid-derived-from-fields/Abi.json +0 -7
  237. package/tests/cli/validation/missing-or-invalid-derived-from-fields/mapping.ts +0 -0
  238. package/tests/cli/validation/missing-or-invalid-derived-from-fields/schema.graphql +0 -40
  239. package/tests/cli/validation/missing-or-invalid-derived-from-fields/subgraph.yaml +0 -22
  240. package/tests/cli/validation/missing-or-invalid-derived-from-fields.stderr +0 -10
  241. package/tests/cli/validation/missing-or-invalid-derived-from-fields.stdout +0 -0
  242. package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
  243. package/tests/cli/validation/near-is-valid/schema.graphql +0 -8
  244. package/tests/cli/validation/near-is-valid/subgraph.yaml +0 -30
  245. package/tests/cli/validation/nested-template-nice-error/Abi.json +0 -7
  246. package/tests/cli/validation/nested-template-nice-error/mapping.ts +0 -0
  247. package/tests/cli/validation/nested-template-nice-error/schema.graphql +0 -3
  248. package/tests/cli/validation/nested-template-nice-error/subgraph.yaml +0 -35
  249. package/tests/cli/validation/nested-template-nice-error.stderr +0 -5
  250. package/tests/cli/validation/no-network-names/Abi.json +0 -7
  251. package/tests/cli/validation/no-network-names/mapping.ts +0 -0
  252. package/tests/cli/validation/no-network-names/schema.graphql +0 -3
  253. package/tests/cli/validation/no-network-names/subgraph.yaml +0 -40
  254. package/tests/cli/validation/no-network-names.stderr +0 -34
  255. package/tests/cli/validation/source-without-address-is-valid/Abi.json +0 -7
  256. package/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts +0 -35
  257. package/tests/cli/validation/source-without-address-is-valid/mapping.ts +0 -0
  258. package/tests/cli/validation/source-without-address-is-valid/schema.graphql +0 -3
  259. package/tests/cli/validation/source-without-address-is-valid/subgraph.yaml +0 -23
  260. package/tests/cli/validation/source-without-address-is-valid.stderr +0 -24
  261. package/tests/cli/validation/topic0-is-valid/Abi.json +0 -7
  262. package/tests/cli/validation/topic0-is-valid/mapping.ts +0 -0
  263. package/tests/cli/validation/topic0-is-valid/schema.graphql +0 -4
  264. package/tests/cli/validation/topic0-is-valid/subgraph.yaml +0 -24
  265. package/tests/cli/validation.test.ts +0 -226
  266. package/tsconfig.build.json +0 -4
  267. package/tsconfig.json +0 -19
@@ -1,369 +0,0 @@
1
- import { exec, spawn } from 'child_process';
2
- import os from 'os';
3
- import path from 'path';
4
- import { Binary } from 'binary-install-raw';
5
- import chalk from 'chalk';
6
- import { filesystem, GluegunToolbox, patching, print, system } from 'gluegun';
7
- import yaml from 'js-yaml';
8
- import fetch from 'node-fetch';
9
- import semver from 'semver';
10
- import { fixParameters } from '../command-helpers/gluegun';
11
-
12
- const HELP = `
13
- ${chalk.bold('graph test')} ${chalk.dim('[options]')} ${chalk.bold('<datasource>')}
14
-
15
- ${chalk.dim('Options:')}
16
- -c, --coverage Run the tests in coverage mode
17
- -d, --docker Run the tests in a docker container(Note: Please execute from the root folder of the subgraph)
18
- -f --force Binary - overwrites folder + file when downloading. Docker - rebuilds the docker image
19
- -h, --help Show usage information
20
- -l, --logs Logs to the console information about the OS, CPU model and download url (debugging purposes)
21
- -r, --recompile Force-recompile tests
22
- -v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
23
- `;
24
-
25
- export interface TestOptions {
26
- coverage?: boolean;
27
- docker?: boolean;
28
- force?: boolean;
29
- help?: boolean;
30
- logs?: boolean;
31
- recompile?: boolean;
32
- version?: string;
33
- // not a cli arg
34
- testsFolder: string;
35
- cachePath: string;
36
- latestVersion?: string;
37
- }
38
-
39
- export default {
40
- description: 'Runs rust binary for subgraph testing',
41
- run: async (toolbox: GluegunToolbox) => {
42
- // Read CLI parameters
43
- const { c, coverage, d, docker, f, force, h, help, l, logs, r, recompile, v, version } =
44
- toolbox.parameters.options;
45
-
46
- const testsFolder = './tests';
47
- const opts: TestOptions = {
48
- testsFolder,
49
- cachePath: path.join(testsFolder, '.latest.json'),
50
- };
51
- // Support both long and short option variants
52
- opts.coverage = coverage || c;
53
- opts.docker = docker || d;
54
- opts.force = force || f;
55
- opts.help = help || h;
56
- opts.logs = logs || l;
57
- opts.recompile = recompile || r;
58
- opts.version = version || v;
59
- // Fix if a boolean flag (e.g -c, --coverage) has an argument
60
- try {
61
- fixParameters(toolbox.parameters, {
62
- h,
63
- help,
64
- c,
65
- coverage,
66
- d,
67
- docker,
68
- f,
69
- force,
70
- l,
71
- logs,
72
- r,
73
- recompile,
74
- });
75
- } catch (e) {
76
- print.error(e.message);
77
- process.exitCode = 1;
78
- return;
79
- }
80
-
81
- const datasource = toolbox.parameters.first || toolbox.parameters.array?.[0];
82
- // Show help text if requested
83
- if (opts.help) {
84
- print.info(HELP);
85
- return;
86
- }
87
-
88
- // Check if matchstick.yaml config exists
89
- if (filesystem.exists('matchstick.yaml')) {
90
- try {
91
- // Load the config
92
- const config = await yaml.load(filesystem.read('matchstick.yaml', 'utf8')!);
93
-
94
- // Check if matchstick.yaml and testsFolder not null
95
- if (config?.testsFolder) {
96
- // assign test folder from matchstick.yaml if present
97
- opts.testsFolder = config.testsFolder;
98
- }
99
- } catch (error) {
100
- print.info(
101
- 'A problem occurred while reading matchstick.yaml. Please attend to the errors below:',
102
- );
103
- print.error(error.message);
104
- process.exit(1);
105
- }
106
- }
107
-
108
- setVersionFromCache(opts);
109
-
110
- // Fetch the latest version tag if version is not specified with -v/--version or if the version is not cached
111
- if (opts.force || (!opts.version && !opts.latestVersion)) {
112
- print.info('Fetching latest version tag');
113
- const result = await fetch(
114
- 'https://api.github.com/repos/LimeChain/matchstick/releases/latest',
115
- );
116
- const json = await result.json();
117
- opts.latestVersion = json.tag_name;
118
-
119
- filesystem.file(opts.cachePath, {
120
- content: {
121
- version: json.tag_name,
122
- timestamp: Date.now(),
123
- },
124
- });
125
- }
126
-
127
- if (opts.docker) {
128
- runDocker(datasource, opts);
129
- } else {
130
- runBinary(datasource, opts);
131
- }
132
- },
133
- };
134
-
135
- async function setVersionFromCache(opts: TestOptions) {
136
- if (filesystem.exists(opts.cachePath) == 'file') {
137
- const cached = filesystem.read(opts.cachePath, 'json');
138
- // Get the cache age in days
139
- const cacheAge = (Date.now() - cached.timestamp) / (1000 * 60 * 60 * 24);
140
- // If cache age is less than 1 day, use the cached version
141
- if (cacheAge < 1) {
142
- opts.latestVersion = cached.version;
143
- }
144
- }
145
- }
146
-
147
- async function runBinary(datasource: string | undefined, opts: TestOptions) {
148
- const coverageOpt = opts.coverage;
149
- const forceOpt = opts.force;
150
- const logsOpt = opts.logs;
151
- const versionOpt = opts.version;
152
- const latestVersion = opts.latestVersion;
153
- const recompileOpt = opts.recompile;
154
-
155
- const platform = await getPlatform(logsOpt);
156
-
157
- const url = `https://github.com/LimeChain/matchstick/releases/download/${
158
- versionOpt || latestVersion
159
- }/${platform}`;
160
-
161
- if (logsOpt) {
162
- print.info(`Download link: ${url}`);
163
- }
164
-
165
- const binary = new Binary(platform, url, versionOpt || latestVersion);
166
- forceOpt ? await binary.install(true) : await binary.install(false);
167
- const args = [];
168
-
169
- if (coverageOpt) args.push('-c');
170
- if (recompileOpt) args.push('-r');
171
- if (datasource) args.push(datasource);
172
- args.length > 0 ? binary.run(...args) : binary.run();
173
- }
174
-
175
- async function getPlatform(logsOpt: boolean | undefined) {
176
- const type = os.type();
177
- const arch = os.arch();
178
- const cpuCore = os.cpus()[0];
179
- const isAppleSilicon = arch === 'arm64' && /Apple (M1|M2|processor)/.test(cpuCore.model);
180
- const linuxInfo = type === 'Linux' ? await getLinuxInfo() : {};
181
- const linuxDistro = linuxInfo.name;
182
- const release = linuxInfo.version || os.release();
183
- const majorVersion = parseInt(linuxInfo.version || '', 10) || semver.major(release);
184
-
185
- if (logsOpt) {
186
- print.info(
187
- `OS type: ${
188
- linuxDistro || type
189
- }\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${
190
- cpuCore.model
191
- }`,
192
- );
193
- }
194
-
195
- if (arch === 'x64' || isAppleSilicon) {
196
- if (type === 'Darwin') {
197
- if (majorVersion === 18 || majorVersion === 19) {
198
- return 'binary-macos-10.15'; // GitHub dropped support for macOS 10.14 in Actions, but it seems 10.15 binary works on 10.14 too
199
- }
200
- if (isAppleSilicon) {
201
- return 'binary-macos-11-m1';
202
- }
203
- return 'binary-macos-11';
204
- }
205
- if (type === 'Linux') {
206
- if (majorVersion === 18) {
207
- return 'binary-linux-18';
208
- }
209
- if (majorVersion === 22) {
210
- return 'binary-linux-22';
211
- }
212
- return 'binary-linux-20';
213
- }
214
- }
215
-
216
- throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`);
217
- }
218
-
219
- /**
220
- * The result of running `cat /etc/*-release | grep -E '(^VERSION|^NAME)='`
221
- *
222
- * May look like this:
223
- * ```sh
224
- * NAME="Ubuntu"
225
- * VERSION="16.04.7 LTS (Xenial Xerus)"
226
- * ```
227
- */
228
- interface LinuxInfo {
229
- name?: string;
230
- version?: string;
231
- }
232
-
233
- async function getLinuxInfo(): Promise<LinuxInfo> {
234
- try {
235
- const result = await system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {
236
- trim: true,
237
- });
238
- const infoArray = result
239
- .replace(/['"]+/g, '')
240
- .split('\n')
241
- .map(p => p.split('='));
242
- const linuxInfo: LinuxInfo = {};
243
-
244
- infoArray.forEach(val => {
245
- linuxInfo[val[0].toLowerCase() as keyof LinuxInfo] = val[1];
246
- });
247
-
248
- return linuxInfo;
249
- } catch (error) {
250
- print.error(`Error fetching the Linux version:\n ${error}`);
251
- process.exit(1);
252
- }
253
- }
254
-
255
- async function runDocker(datasource: string | undefined, opts: TestOptions) {
256
- const coverageOpt = opts.coverage;
257
- const forceOpt = opts.force;
258
- const versionOpt = opts.version;
259
- const latestVersion = opts.latestVersion;
260
- const recompileOpt = opts.recompile;
261
-
262
- // Remove binary-install-raw binaries, because docker has permission issues
263
- // when building the docker images
264
- filesystem.remove('./node_modules/binary-install-raw/bin');
265
-
266
- // Get current working directory
267
- const current_folder = filesystem.cwd();
268
-
269
- // Declate dockerfilePath with default location
270
- const dockerfilePath = path.join(opts.testsFolder || 'tests', '.docker/Dockerfile');
271
-
272
- // Check if the Dockerfil already exists
273
- const dockerfileExists = filesystem.exists(dockerfilePath);
274
-
275
- // Generate the Dockerfile only if it doesn't exists,
276
- // version flag and/or force flag is passed.
277
- if (!dockerfileExists || versionOpt || forceOpt) {
278
- await dockerfile(dockerfilePath, versionOpt, latestVersion);
279
- }
280
-
281
- // Run a command to check if matchstick image already exists
282
- exec('docker images -q matchstick', (_error, stdout, _stderr) => {
283
- // Collect all(if any) flags and options that have to be passed to the matchstick binary
284
- let testArgs = '';
285
- if (coverageOpt) testArgs = testArgs + ' -c';
286
- if (recompileOpt) testArgs = testArgs + ' -r';
287
- if (datasource) testArgs = testArgs + ' ' + datasource;
288
-
289
- // Build the `docker run` command options and flags
290
- const dockerRunOpts = [
291
- 'run',
292
- '-it',
293
- '--rm',
294
- '--mount',
295
- `type=bind,source=${current_folder},target=/matchstick`,
296
- ];
297
-
298
- if (testArgs !== '') {
299
- dockerRunOpts.push('-e');
300
- dockerRunOpts.push(`ARGS=${testArgs.trim()}`);
301
- }
302
-
303
- dockerRunOpts.push('matchstick');
304
-
305
- // If a matchstick image does not exists, the command returns an empty string,
306
- // else it'll return the image ID. Skip `docker build` if an image already exists
307
- // Delete current image(if any) and rebuild.
308
- // Use spawn() and {stdio: 'inherit'} so we can see the logs in real time.
309
- if (!dockerfileExists || stdout === '' || versionOpt || forceOpt) {
310
- if (stdout !== '') {
311
- exec('docker image rm matchstick', (_error, stdout, _stderr) => {
312
- print.info(chalk.bold(`Removing matchstick image\n${stdout}`));
313
- });
314
- }
315
- // Build a docker image. If the process has executed successfully
316
- // run a container from that image.
317
- spawn('docker', ['build', '-f', dockerfilePath, '-t', 'matchstick', '.'], {
318
- stdio: 'inherit',
319
- }).on('close', code => {
320
- if (code === 0) {
321
- spawn('docker', dockerRunOpts, { stdio: 'inherit' });
322
- }
323
- });
324
- } else {
325
- print.info('Docker image already exists. Skipping `docker build` command.');
326
- // Run the container from the existing matchstick docker image
327
- spawn('docker', dockerRunOpts, { stdio: 'inherit' });
328
- }
329
- });
330
- }
331
-
332
- // Downloads Dockerfile template from the demo-subgraph repo
333
- // Replaces the placeholders with their respective values
334
- async function dockerfile(
335
- dockerfilePath: string,
336
- versionOpt: string | undefined,
337
- latestVersion: string | undefined,
338
- ) {
339
- const spinner = print.spin('Generating Dockerfile...');
340
-
341
- try {
342
- // Fetch the Dockerfile template content from the demo-subgraph repo
343
- const content = await fetch(
344
- 'https://raw.githubusercontent.com/LimeChain/demo-subgraph/main/Dockerfile',
345
- ).then(response => {
346
- if (response.ok) {
347
- return response.text();
348
- }
349
- throw new Error(`Status Code: ${response.status}, with error: ${response.statusText}`);
350
- });
351
-
352
- // Write the Dockerfile
353
- filesystem.write(dockerfilePath, content);
354
-
355
- // Replaces the version placeholders
356
- await patching.replace(
357
- dockerfilePath,
358
- '<MATCHSTICK_VERSION>',
359
- versionOpt || latestVersion || 'unknown',
360
- );
361
- } catch (error) {
362
- spinner.fail(
363
- `A problem occurred while generating the Dockerfile. Please attend to the errors below:\n ${error.message}`,
364
- );
365
- process.exit(1);
366
- }
367
-
368
- spinner.succeed('Successfully generated Dockerfile.');
369
- }
@@ -1,77 +0,0 @@
1
- import * as asc from 'assemblyscript/cli/asc';
2
-
3
- const createExitHandler = (inputFile: string) => () => {
4
- throw new Error(`The AssemblyScript compiler crashed when compiling this file: '${inputFile}'
5
- Suggestion: try to comment the whole file and uncomment it little by little while re-running the graph-cli until you isolate the line where the problem happens.
6
- Also, please contact us so we can make the CLI better by handling errors like this. You can reach out in any of these links:
7
- - Discord channel: https://discord.gg/eM8CA6WA9r
8
- - Github issues: https://github.com/graphprotocol/graph-cli/issues`);
9
- };
10
-
11
- const setupExitHandler = (exitHandler: (code: number) => void) =>
12
- process.addListener('exit', exitHandler);
13
-
14
- const removeExitHandler = (exitHandler: (code: number) => void) =>
15
- process.removeListener('exit', exitHandler);
16
-
17
- // Important note, the `asc.main` callback function parameter is synchronous,
18
- // that's why this function doesn't need to be `async` and the throw works properly.
19
- const assemblyScriptCompiler = (argv: string[], options: asc.APIOptions) =>
20
- asc.main(argv, options, err => {
21
- if (err) {
22
- throw err;
23
- }
24
- return 0;
25
- });
26
-
27
- const compilerDefaults = {
28
- stdout: process.stdout,
29
- stderr: process.stdout,
30
- };
31
-
32
- // You MUST call this function once before compiling anything.
33
- // Internally it just delegates to the AssemblyScript compiler
34
- // which just delegates to the binaryen lib.
35
- export const ready = async () => {
36
- await asc.ready;
37
- };
38
-
39
- export interface CompileOptions {
40
- inputFile: string;
41
- global: string;
42
- baseDir: string;
43
- libs: string;
44
- outputFile: string;
45
- }
46
-
47
- // For now this function doesn't check if `asc` is ready, because
48
- // it requires an asynchronous wait. Whenever you call this function,
49
- // it doesn't matter how many times, just make sure you call `ready`
50
- // once before everything..
51
- export const compile = ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => {
52
- const exitHandler = createExitHandler(inputFile);
53
-
54
- setupExitHandler(exitHandler);
55
-
56
- const compilerArgs = [
57
- '--explicitStart',
58
- '--exportRuntime',
59
- '--runtime',
60
- 'stub',
61
- inputFile,
62
- global,
63
- '--baseDir',
64
- baseDir,
65
- '--lib',
66
- libs,
67
- '--outFile',
68
- outputFile,
69
- '--optimize',
70
- '--debug',
71
- ];
72
-
73
- assemblyScriptCompiler(compilerArgs, compilerDefaults);
74
-
75
- // only if compiler succeded, that is, when the line above doesn't throw
76
- removeExitHandler(exitHandler);
77
- };