@graphprotocol/graph-cli 0.37.2 → 0.37.3-alpha-20230110163550-d64bef6

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 (206) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/babel.config.js +3 -0
  3. package/dist/bin.js +6 -0
  4. package/dist/cli.js +32 -0
  5. package/dist/codegen/schema.js +250 -0
  6. package/dist/codegen/schema.test.js +458 -0
  7. package/dist/codegen/template.js +65 -0
  8. package/dist/codegen/types/conversions.js +359 -0
  9. package/dist/codegen/types/index.js +71 -0
  10. package/dist/codegen/types/index.test.js +563 -0
  11. package/dist/codegen/typescript.js +200 -0
  12. package/dist/codegen/util.js +46 -0
  13. package/dist/codegen/util.test.js +93 -0
  14. package/dist/command-helpers/abi.js +78 -0
  15. package/dist/command-helpers/auth.js +77 -0
  16. package/dist/command-helpers/compiler.js +66 -0
  17. package/dist/command-helpers/data-sources.js +29 -0
  18. package/dist/command-helpers/fs.js +9 -0
  19. package/dist/command-helpers/gluegun.js +49 -0
  20. package/dist/command-helpers/ipfs.js +5 -0
  21. package/dist/command-helpers/jsonrpc.js +29 -0
  22. package/dist/command-helpers/network.js +93 -0
  23. package/dist/command-helpers/network.test.js +86 -0
  24. package/dist/command-helpers/node.js +40 -0
  25. package/dist/command-helpers/scaffold.js +112 -0
  26. package/dist/command-helpers/spinner.js +84 -0
  27. package/dist/command-helpers/studio.js +13 -0
  28. package/dist/command-helpers/studio.test.js +41 -0
  29. package/dist/command-helpers/subgraph.js +24 -0
  30. package/dist/command-helpers/version.js +74 -0
  31. package/dist/command-helpers/version.test.js +179 -0
  32. package/dist/commands/add.js +190 -0
  33. package/dist/commands/auth.js +127 -0
  34. package/dist/commands/build.js +140 -0
  35. package/dist/commands/codegen.js +135 -0
  36. package/dist/commands/create.js +86 -0
  37. package/dist/commands/deploy.js +334 -0
  38. package/dist/commands/init.js +788 -0
  39. package/dist/commands/local.js +387 -0
  40. package/dist/commands/remove.js +86 -0
  41. package/dist/commands/test.js +295 -0
  42. package/dist/compiler/asc.js +83 -0
  43. package/dist/compiler/index.js +474 -0
  44. package/dist/debug.js +16 -0
  45. package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
  46. package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
  47. package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
  48. package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
  49. package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
  50. package/dist/migrations/spec_version_0_0_2.js +49 -0
  51. package/dist/migrations/spec_version_0_0_3.js +54 -0
  52. package/dist/migrations/util/load-manifest.js +18 -0
  53. package/dist/migrations/util/versions.js +29 -0
  54. package/dist/migrations.js +56 -0
  55. package/dist/protocols/arweave/manifest.graphql +57 -0
  56. package/dist/protocols/arweave/scaffold/manifest.js +18 -0
  57. package/dist/protocols/arweave/scaffold/mapping.js +52 -0
  58. package/dist/protocols/arweave/subgraph.js +23 -0
  59. package/dist/protocols/cosmos/manifest.graphql +76 -0
  60. package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
  61. package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
  62. package/dist/protocols/cosmos/subgraph.js +25 -0
  63. package/dist/protocols/ethereum/abi.js +140 -0
  64. package/dist/protocols/ethereum/codegen/abi.js +451 -0
  65. package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
  66. package/dist/protocols/ethereum/codegen/template.js +50 -0
  67. package/dist/protocols/ethereum/contract.js +20 -0
  68. package/dist/protocols/ethereum/manifest.graphql +94 -0
  69. package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
  70. package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
  71. package/dist/protocols/ethereum/subgraph.js +171 -0
  72. package/dist/protocols/ethereum/type-generator.js +125 -0
  73. package/dist/protocols/index.js +268 -0
  74. package/dist/protocols/ipfs/codegen/file_template.js +50 -0
  75. package/dist/protocols/near/contract.js +41 -0
  76. package/dist/protocols/near/manifest.graphql +64 -0
  77. package/dist/protocols/near/scaffold/manifest.js +16 -0
  78. package/dist/protocols/near/scaffold/mapping.js +38 -0
  79. package/dist/protocols/near/subgraph.js +20 -0
  80. package/dist/protocols/subgraph.js +2 -0
  81. package/dist/protocols/substreams/manifest.graphql +45 -0
  82. package/dist/protocols/substreams/scaffold/manifest.js +12 -0
  83. package/dist/protocols/substreams/subgraph.js +23 -0
  84. package/dist/scaffold/cosmos.test.js +83 -0
  85. package/dist/scaffold/ethereum.test.js +505 -0
  86. package/dist/scaffold/index.js +128 -0
  87. package/dist/scaffold/mapping.js +61 -0
  88. package/dist/scaffold/near.test.js +86 -0
  89. package/dist/scaffold/schema.js +83 -0
  90. package/dist/scaffold/tests.js +175 -0
  91. package/dist/schema.js +54 -0
  92. package/dist/subgraph.js +249 -0
  93. package/dist/type-generator.js +224 -0
  94. package/dist/validation/contract.js +46 -0
  95. package/dist/validation/index.js +8 -0
  96. package/dist/validation/manifest.js +271 -0
  97. package/dist/validation/schema.js +796 -0
  98. package/dist/validation/schema.test.js +35 -0
  99. package/dist/watcher.js +79 -0
  100. package/jest.config.js +1 -1
  101. package/package.json +16 -9
  102. package/{bin/graph → src/bin.ts} +2 -1
  103. package/src/cli.ts +36 -0
  104. package/src/codegen/schema.js +23 -22
  105. package/src/codegen/schema.test.js +33 -27
  106. package/src/codegen/{template.js → template.ts} +8 -6
  107. package/src/codegen/types/conversions.ts +382 -0
  108. package/src/codegen/types/index.js +4 -7
  109. package/src/codegen/types/index.test.js +10 -4
  110. package/src/codegen/{typescript.js → typescript.ts} +44 -26
  111. package/src/codegen/util.js +1 -1
  112. package/src/codegen/util.test.js +5 -2
  113. package/src/command-helpers/abi.js +46 -30
  114. package/src/command-helpers/auth.js +6 -9
  115. package/src/command-helpers/compiler.js +4 -6
  116. package/src/command-helpers/data-sources.js +8 -11
  117. package/src/command-helpers/fs.ts +5 -0
  118. package/src/command-helpers/gluegun.js +2 -4
  119. package/src/command-helpers/ipfs.ts +3 -0
  120. package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
  121. package/src/command-helpers/network.js +58 -44
  122. package/src/command-helpers/network.test.js +23 -19
  123. package/src/command-helpers/node.js +3 -7
  124. package/src/command-helpers/scaffold.js +34 -25
  125. package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
  126. package/src/command-helpers/studio.test.js +61 -30
  127. package/src/command-helpers/studio.ts +20 -0
  128. package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
  129. package/src/command-helpers/version.js +11 -16
  130. package/src/command-helpers/version.test.js +111 -82
  131. package/src/commands/add.js +49 -35
  132. package/src/commands/auth.js +13 -25
  133. package/src/commands/build.js +9 -9
  134. package/src/commands/codegen.js +12 -12
  135. package/src/commands/create.js +22 -22
  136. package/src/commands/deploy.js +39 -34
  137. package/src/commands/init.js +21 -24
  138. package/src/commands/local.js +15 -14
  139. package/src/commands/remove.js +22 -22
  140. package/src/commands/test.js +86 -70
  141. package/src/compiler/{asc.js → asc.ts} +29 -16
  142. package/src/compiler/index.js +18 -18
  143. package/src/{debug.js → debug.ts} +2 -2
  144. package/src/migrations/mapping_api_version_0_0_1.js +7 -7
  145. package/src/migrations/mapping_api_version_0_0_2.js +5 -5
  146. package/src/migrations/mapping_api_version_0_0_3.js +7 -7
  147. package/src/migrations/mapping_api_version_0_0_4.js +7 -7
  148. package/src/migrations/mapping_api_version_0_0_5.js +7 -7
  149. package/src/migrations/spec_version_0_0_2.js +5 -5
  150. package/src/migrations/spec_version_0_0_3.js +5 -5
  151. package/src/migrations/util/load-manifest.js +6 -9
  152. package/src/migrations/util/versions.js +5 -10
  153. package/src/{migrations.js → migrations.ts} +14 -15
  154. package/src/protocols/arweave/scaffold/manifest.js +1 -4
  155. package/src/protocols/arweave/scaffold/mapping.js +1 -3
  156. package/src/protocols/arweave/subgraph.ts +22 -0
  157. package/src/protocols/cosmos/scaffold/manifest.js +1 -4
  158. package/src/protocols/cosmos/scaffold/mapping.js +1 -3
  159. package/src/protocols/cosmos/subgraph.js +2 -2
  160. package/src/protocols/ethereum/abi.js +7 -13
  161. package/src/protocols/ethereum/codegen/abi.js +219 -222
  162. package/src/protocols/ethereum/codegen/abi.test.js +6 -6
  163. package/src/protocols/ethereum/codegen/template.js +3 -5
  164. package/src/protocols/ethereum/contract.js +3 -2
  165. package/src/protocols/ethereum/scaffold/manifest.js +4 -7
  166. package/src/protocols/ethereum/scaffold/mapping.js +4 -11
  167. package/src/protocols/ethereum/subgraph.js +21 -20
  168. package/src/protocols/ethereum/type-generator.js +24 -30
  169. package/src/protocols/{index.js → index.ts} +65 -46
  170. package/src/protocols/ipfs/codegen/file_template.js +2 -2
  171. package/src/protocols/near/{contract.js → contract.ts} +16 -12
  172. package/src/protocols/near/scaffold/manifest.js +2 -5
  173. package/src/protocols/near/scaffold/mapping.js +1 -3
  174. package/src/protocols/near/subgraph.js +3 -6
  175. package/src/protocols/subgraph.ts +12 -0
  176. package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
  177. package/src/protocols/substreams/subgraph.ts +22 -0
  178. package/src/scaffold/cosmos.test.js +3 -3
  179. package/src/scaffold/ethereum.test.js +4 -4
  180. package/src/scaffold/index.js +7 -7
  181. package/src/scaffold/mapping.js +3 -3
  182. package/src/scaffold/near.test.js +3 -3
  183. package/src/scaffold/schema.js +4 -4
  184. package/src/scaffold/tests.js +72 -58
  185. package/src/schema.ts +26 -0
  186. package/src/{subgraph.js → subgraph.ts} +80 -60
  187. package/src/type-generator.js +20 -20
  188. package/src/validation/contract.js +2 -6
  189. package/src/validation/index.js +1 -1
  190. package/src/validation/manifest.js +24 -22
  191. package/src/validation/schema.test.js +1 -1
  192. package/src/validation/{schema.js → schema.ts} +268 -221
  193. package/src/{watcher.js → watcher.ts} +23 -12
  194. package/tests/cli/globalSetup.js +2 -2
  195. package/tests/cli/globalTeardown.js +2 -2
  196. package/tests/cli/init.test.js +2 -2
  197. package/tests/cli/util.js +7 -13
  198. package/tsconfig.json +18 -0
  199. package/src/cli.js +0 -38
  200. package/src/codegen/types/conversions.js +0 -329
  201. package/src/command-helpers/fs.js +0 -8
  202. package/src/command-helpers/ipfs.js +0 -6
  203. package/src/command-helpers/studio.js +0 -15
  204. package/src/protocols/arweave/subgraph.js +0 -20
  205. package/src/protocols/substreams/subgraph.js +0 -17
  206. package/src/schema.js +0 -23
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const version_1 = require("./version");
27
+ const loadManifestUtil = __importStar(require("../migrations/util/load-manifest"));
28
+ const graphTsUtil = __importStar(require("../migrations/util/versions"));
29
+ describe('Version Command Helpers', () => {
30
+ describe('assertManifestApiVersion', () => {
31
+ const fakeManifestPath = 'fake/manifest/path';
32
+ const minimumApiVersion = '0.0.5';
33
+ describe('With just dataSources', () => {
34
+ test('When all of them are less than minimum apiVersion', async () => {
35
+ loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
36
+ dataSources: [
37
+ { mapping: { apiVersion: '0.0.1' } },
38
+ { mapping: { apiVersion: '0.0.2' } },
39
+ { mapping: { apiVersion: '0.0.3' } },
40
+ ],
41
+ }));
42
+ await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
43
+ });
44
+ test('When one of them is less than minimum apiVersion', async () => {
45
+ loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
46
+ dataSources: [
47
+ { mapping: { apiVersion: '0.0.5' } },
48
+ { mapping: { apiVersion: '0.0.2' } },
49
+ { mapping: { apiVersion: '0.0.5' } },
50
+ ],
51
+ }));
52
+ await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
53
+ });
54
+ test('When none of them are less than minimum apiVersion', async () => {
55
+ loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
56
+ dataSources: [
57
+ { mapping: { apiVersion: '0.0.5' } },
58
+ { mapping: { apiVersion: '0.0.6' } },
59
+ { mapping: { apiVersion: '0.0.5' } },
60
+ ],
61
+ }));
62
+ await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
63
+ });
64
+ });
65
+ describe('With dataSources and templates', () => {
66
+ describe('And the dataSources have a lower apiVersion', () => {
67
+ test('When all of the templates are less than minimum apiVersion', async () => {
68
+ loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
69
+ dataSources: [
70
+ { mapping: { apiVersion: '0.0.5' } },
71
+ { mapping: { apiVersion: '0.0.5' } },
72
+ { mapping: { apiVersion: '0.0.3' } },
73
+ ],
74
+ templates: [
75
+ { mapping: { apiVersion: '0.0.1' } },
76
+ { mapping: { apiVersion: '0.0.2' } },
77
+ { mapping: { apiVersion: '0.0.3' } },
78
+ ],
79
+ }));
80
+ await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
81
+ });
82
+ test('When one of the templates is less than minimum apiVersion', async () => {
83
+ loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
84
+ dataSources: [
85
+ { mapping: { apiVersion: '0.0.5' } },
86
+ { mapping: { apiVersion: '0.0.5' } },
87
+ { mapping: { apiVersion: '0.0.3' } },
88
+ ],
89
+ templates: [
90
+ { mapping: { apiVersion: '0.0.5' } },
91
+ { mapping: { apiVersion: '0.0.2' } },
92
+ { mapping: { apiVersion: '0.0.5' } },
93
+ ],
94
+ }));
95
+ await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
96
+ });
97
+ test('When none of the templates are less than minimum apiVersion', async () => {
98
+ loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
99
+ dataSources: [
100
+ { mapping: { apiVersion: '0.0.5' } },
101
+ { mapping: { apiVersion: '0.0.5' } },
102
+ { mapping: { apiVersion: '0.0.3' } },
103
+ ],
104
+ templates: [
105
+ { mapping: { apiVersion: '0.0.5' } },
106
+ { mapping: { apiVersion: '0.0.6' } },
107
+ { mapping: { apiVersion: '0.0.5' } },
108
+ ],
109
+ }));
110
+ await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
111
+ });
112
+ });
113
+ describe('And the dataSources do NOT have a lower apiVersion', () => {
114
+ test('When all of the templates are less than minimum apiVersion', async () => {
115
+ loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
116
+ dataSources: [
117
+ { mapping: { apiVersion: '0.0.5' } },
118
+ { mapping: { apiVersion: '0.0.5' } },
119
+ { mapping: { apiVersion: '0.0.6' } },
120
+ ],
121
+ templates: [
122
+ { mapping: { apiVersion: '0.0.1' } },
123
+ { mapping: { apiVersion: '0.0.2' } },
124
+ { mapping: { apiVersion: '0.0.3' } },
125
+ ],
126
+ }));
127
+ await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
128
+ });
129
+ test('When one of the templates is less than minimum apiVersion', async () => {
130
+ loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
131
+ dataSources: [
132
+ { mapping: { apiVersion: '0.0.5' } },
133
+ { mapping: { apiVersion: '0.0.5' } },
134
+ { mapping: { apiVersion: '0.0.6' } },
135
+ ],
136
+ templates: [
137
+ { mapping: { apiVersion: '0.0.5' } },
138
+ { mapping: { apiVersion: '0.0.2' } },
139
+ { mapping: { apiVersion: '0.0.5' } },
140
+ ],
141
+ }));
142
+ await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).rejects.toThrow(new Error(`The current version of graph-cli can't be used with mappings on apiVersion less than '${minimumApiVersion}'`));
143
+ });
144
+ test('When none of the templates are less than minimum apiVersion', async () => {
145
+ loadManifestUtil.loadManifest = jest.fn().mockImplementation(() => Promise.resolve({
146
+ dataSources: [
147
+ { mapping: { apiVersion: '0.0.5' } },
148
+ { mapping: { apiVersion: '0.0.5' } },
149
+ { mapping: { apiVersion: '0.0.6' } },
150
+ ],
151
+ templates: [
152
+ { mapping: { apiVersion: '0.0.5' } },
153
+ { mapping: { apiVersion: '0.0.6' } },
154
+ { mapping: { apiVersion: '0.0.5' } },
155
+ ],
156
+ }));
157
+ await expect((0, version_1.assertManifestApiVersion)(fakeManifestPath, minimumApiVersion)).resolves.toBe(undefined);
158
+ });
159
+ });
160
+ });
161
+ });
162
+ describe('assertGraphTsVersion', () => {
163
+ const fakeNodeModulesDir = 'fake/path/to/node/modules';
164
+ const minimumGraphTsVersion = '0.22.0';
165
+ test("When the installed graph-ts version is less than what's supported", async () => {
166
+ graphTsUtil.getGraphTsVersion = jest
167
+ .fn()
168
+ .mockImplementation(() => Promise.resolve('0.19.0'));
169
+ await expect((0, version_1.assertGraphTsVersion)(fakeNodeModulesDir, minimumGraphTsVersion)).rejects.toThrow(new Error(`To use this version of the graph-cli you must upgrade the graph-ts dependency to a version greater than or equal to ${minimumGraphTsVersion}
170
+ Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://thegraph.com/docs/developer/assemblyscript-migration-guide`));
171
+ });
172
+ test('When the installed graph-ts version is a supported one', async () => {
173
+ graphTsUtil.getGraphTsVersion = jest
174
+ .fn()
175
+ .mockImplementation(() => Promise.resolve('0.22.0'));
176
+ await expect((0, version_1.assertGraphTsVersion)(fakeNodeModulesDir, minimumGraphTsVersion)).resolves.toBe(undefined);
177
+ });
178
+ });
179
+ });
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const chalk_1 = __importDefault(require("chalk"));
30
+ const toolbox = __importStar(require("gluegun/toolbox"));
31
+ const immutable_1 = __importDefault(require("immutable"));
32
+ const spinner_1 = require("../command-helpers/spinner");
33
+ const subgraph_1 = __importDefault(require("../subgraph"));
34
+ const protocols_1 = __importDefault(require("../protocols"));
35
+ const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
36
+ const scaffold_1 = require("../command-helpers/scaffold");
37
+ const abi_1 = require("../command-helpers/abi");
38
+ const abi_2 = __importDefault(require("../protocols/ethereum/abi"));
39
+ const gluegun_1 = require("../command-helpers/gluegun");
40
+ const network_1 = require("../command-helpers/network");
41
+ const HELP = `
42
+ ${chalk_1.default.bold('graph add')} <address> [<subgraph-manifest default: "./subgraph.yaml">]
43
+
44
+ ${chalk_1.default.dim('Options:')}
45
+
46
+ --abi <path> Path to the contract ABI (default: download from Etherscan)
47
+ --contract-name Name of the contract (default: Contract)
48
+ --merge-entities Whether to merge entities with the same name (default: false)
49
+ --network-file <path> Networks config file path (default: "./networks.json")
50
+ -h, --help Show usage information
51
+ `;
52
+ exports.default = {
53
+ description: 'Adds a new datasource to a subgraph',
54
+ run: async (toolbox) => {
55
+ // Obtain tools
56
+ let { print, system } = toolbox;
57
+ // Read CLI parameters
58
+ let { abi, contractName, h, help, mergeEntities, networkFile } = toolbox.parameters.options;
59
+ contractName = contractName || 'Contract';
60
+ try {
61
+ (0, gluegun_1.fixParameters)(toolbox.parameters, {
62
+ h,
63
+ help,
64
+ mergeEntities,
65
+ });
66
+ }
67
+ catch (e) {
68
+ print.error(e.message);
69
+ process.exitCode = 1;
70
+ return;
71
+ }
72
+ let address = toolbox.parameters.first || toolbox.parameters.array[0];
73
+ let manifestPath = toolbox.parameters.second || toolbox.parameters.array[1] || './subgraph.yaml';
74
+ // Show help text if requested
75
+ if (help || h) {
76
+ print.info(HELP);
77
+ return;
78
+ }
79
+ // Validate the address
80
+ if (!address) {
81
+ print.error('No contract address provided');
82
+ process.exitCode = 1;
83
+ return;
84
+ }
85
+ const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifestPath);
86
+ let protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
87
+ let manifest = await subgraph_1.default.load(manifestPath, { protocol });
88
+ let network = manifest.result.get('dataSources').get(0).get('network');
89
+ let result = manifest.result.asMutable();
90
+ let entities = getEntities(manifest);
91
+ let contractNames = getContractNames(manifest);
92
+ if (contractNames.indexOf(contractName) !== -1) {
93
+ print.error(`Datasource or template with name ${contractName} already exists, please choose a different name`);
94
+ process.exitCode = 1;
95
+ return;
96
+ }
97
+ let ethabi = null;
98
+ if (abi) {
99
+ ethabi = abi_2.default.load(contractName, abi);
100
+ }
101
+ else {
102
+ if (network === 'poa-core') {
103
+ ethabi = await (0, abi_1.loadAbiFromBlockScout)(abi_2.default, network, address);
104
+ }
105
+ else {
106
+ ethabi = await (0, abi_1.loadAbiFromEtherscan)(abi_2.default, network, address);
107
+ }
108
+ }
109
+ let { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(ethabi, entities, contractName, mergeEntities);
110
+ ethabi.data = abiData;
111
+ await (0, scaffold_1.writeABI)(ethabi, contractName);
112
+ await (0, scaffold_1.writeSchema)(ethabi, protocol, result.getIn(['schema', 'file']), collisionEntities);
113
+ await (0, scaffold_1.writeMapping)(ethabi, protocol, contractName, collisionEntities);
114
+ await (0, scaffold_1.writeTestsFiles)(ethabi, protocol, contractName);
115
+ let dataSources = result.get('dataSources');
116
+ let dataSource = await (0, scaffold_1.generateDataSource)(protocol, contractName, network, address, ethabi);
117
+ // Handle the collisions edge case by copying another data source yaml data
118
+ if (mergeEntities && onlyCollisions) {
119
+ let firstDataSource = dataSources.get(0);
120
+ let source = dataSource.get('source');
121
+ let mapping = firstDataSource.get('mapping').asMutable();
122
+ // Save the address of the new data source
123
+ source.abi = firstDataSource.get('source').get('abi');
124
+ dataSource.set('mapping', mapping);
125
+ dataSource.set('source', source);
126
+ }
127
+ result.set('dataSources', dataSources.push(dataSource));
128
+ await subgraph_1.default.write(result, manifestPath);
129
+ // Update networks.json
130
+ const networksFile = networkFile || './networks.json';
131
+ await (0, network_1.updateNetworksFile)(toolbox, network, contractName, address, networksFile);
132
+ // Detect Yarn and/or NPM
133
+ let yarn = await system.which('yarn');
134
+ let npm = await system.which('npm');
135
+ if (!yarn && !npm) {
136
+ print.error(`Neither Yarn nor NPM were found on your system. Please install one of them.`);
137
+ process.exitCode = 1;
138
+ return;
139
+ }
140
+ await (0, spinner_1.withSpinner)('Running codegen', 'Failed to run codegen', 'Warning during codegen', async (spinner) => {
141
+ await system.run(yarn ? 'yarn codegen' : 'npm run codegen');
142
+ });
143
+ },
144
+ };
145
+ const getEntities = manifest => {
146
+ let dataSources = manifest.result.get('dataSources', immutable_1.default.List());
147
+ let templates = manifest.result.get('templates', immutable_1.default.List());
148
+ return dataSources
149
+ .concat(templates)
150
+ .map(dataSource => dataSource.getIn(['mapping', 'entities']))
151
+ .flatten();
152
+ };
153
+ const getContractNames = manifest => {
154
+ let dataSources = manifest.result.get('dataSources', immutable_1.default.List());
155
+ let templates = manifest.result.get('templates', immutable_1.default.List());
156
+ return dataSources.concat(templates).map(dataSource => dataSource.get('name'));
157
+ };
158
+ const updateEventNamesOnCollision = (ethabi, entities, contractName, mergeEntities) => {
159
+ let abiData = ethabi.data;
160
+ let { print } = toolbox;
161
+ let collisionEntities = [];
162
+ let onlyCollisions = true;
163
+ for (let i = 0; i < abiData.size; i++) {
164
+ let dataRow = abiData.get(i).asMutable();
165
+ if (dataRow.get('type') === 'event') {
166
+ if (entities.indexOf(dataRow.get('name')) !== -1) {
167
+ if (entities.indexOf(`${contractName}${dataRow.get('name')}`) !== -1) {
168
+ print.error(`Contract name ('${contractName}')
169
+ + event name ('${dataRow.get('name')}') entity already exists.`);
170
+ process.exitCode = 1;
171
+ return;
172
+ }
173
+ if (mergeEntities) {
174
+ collisionEntities.push(dataRow.get('name'));
175
+ abiData = abiData.asImmutable().delete(i); // needs to be immutable when deleting, yes you read that right - https://github.com/immutable-js/immutable-js/issues/1901
176
+ i--; // deletion also shifts values to the left
177
+ continue;
178
+ }
179
+ else {
180
+ dataRow.set('name', `${contractName}${dataRow.get('name')}`);
181
+ }
182
+ }
183
+ else {
184
+ onlyCollisions = false;
185
+ }
186
+ }
187
+ abiData = abiData.asMutable().set(i, dataRow);
188
+ }
189
+ return { abiData, collisionEntities, onlyCollisions };
190
+ };
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const chalk_1 = __importDefault(require("chalk"));
7
+ const auth_1 = require("../command-helpers/auth");
8
+ const node_1 = require("../command-helpers/node");
9
+ const gluegun_1 = require("../command-helpers/gluegun");
10
+ const HELP = `
11
+ ${chalk_1.default.bold('graph auth')} [options] ${chalk_1.default.bold('<node>')} ${chalk_1.default.bold('<deploy-key>')}
12
+
13
+ ${chalk_1.default.dim('Options:')}
14
+
15
+ --product <subgraph-studio|hosted-service>
16
+ Selects the product for which to authenticate
17
+ --studio Shortcut for --product subgraph-studio
18
+ -h, --help Show usage information
19
+ `;
20
+ const processForm = async (toolbox, { product, studio, node, deployKey }) => {
21
+ const questions = [
22
+ {
23
+ type: 'select',
24
+ name: 'product',
25
+ message: 'Product for which to initialize',
26
+ choices: ['subgraph-studio', 'hosted-service'],
27
+ skip: product === 'subgraph-studio' ||
28
+ product === 'hosted-service' ||
29
+ studio !== undefined ||
30
+ node !== undefined,
31
+ },
32
+ {
33
+ type: 'password',
34
+ name: 'deployKey',
35
+ message: 'Deploy key',
36
+ skip: deployKey !== undefined,
37
+ },
38
+ ];
39
+ try {
40
+ const answers = await toolbox.prompt.ask(questions);
41
+ return answers;
42
+ }
43
+ catch (e) {
44
+ return undefined;
45
+ }
46
+ };
47
+ exports.default = {
48
+ description: 'Sets the deploy key to use when deploying to a Graph node',
49
+ run: async (toolbox) => {
50
+ // Obtain tools
51
+ let { filesystem, print, system } = toolbox;
52
+ // Read CLI parameters
53
+ let { product, studio, h, help } = toolbox.parameters.options;
54
+ // Show help text if requested
55
+ if (help || h) {
56
+ print.info(HELP);
57
+ return;
58
+ }
59
+ let firstParam, secondParam;
60
+ try {
61
+ ;
62
+ [firstParam, secondParam] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
63
+ h,
64
+ help,
65
+ studio,
66
+ });
67
+ }
68
+ catch (e) {
69
+ print.error(e.message);
70
+ process.exitCode = 1;
71
+ return;
72
+ }
73
+ // if user specifies --product or --studio then deployKey is the first parameter
74
+ let node;
75
+ let deployKey;
76
+ if (product || studio) {
77
+ ;
78
+ ({ node } = (0, node_1.chooseNodeUrl)({ product, studio, node }));
79
+ deployKey = firstParam;
80
+ }
81
+ else {
82
+ node = firstParam;
83
+ deployKey = secondParam;
84
+ }
85
+ if (!node || !deployKey) {
86
+ const inputs = await processForm(toolbox, {
87
+ product,
88
+ studio,
89
+ node,
90
+ deployKey,
91
+ });
92
+ if (inputs === undefined) {
93
+ process.exit(1);
94
+ }
95
+ if (!node) {
96
+ ;
97
+ ({ node } = (0, node_1.chooseNodeUrl)({
98
+ product: inputs.product,
99
+ studio,
100
+ node,
101
+ }));
102
+ }
103
+ if (!deployKey) {
104
+ deployKey = inputs.deployKey;
105
+ }
106
+ }
107
+ if (!deployKey) {
108
+ print.error(`No deploy key provided`);
109
+ print.info(HELP);
110
+ process.exitCode = 1;
111
+ return;
112
+ }
113
+ if (deployKey.length > 200) {
114
+ print.error(`Deploy key must not exceed 200 characters`);
115
+ process.exitCode = 1;
116
+ return;
117
+ }
118
+ try {
119
+ await (0, auth_1.saveDeployKey)(node, deployKey);
120
+ print.success(`Deploy key set for ${node}`);
121
+ }
122
+ catch (e) {
123
+ print.error(e);
124
+ process.exitCode = 1;
125
+ }
126
+ },
127
+ };
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const chalk_1 = __importDefault(require("chalk"));
30
+ const compiler_1 = require("../command-helpers/compiler");
31
+ const gluegun_1 = require("../command-helpers/gluegun");
32
+ const network_1 = require("../command-helpers/network");
33
+ const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
34
+ const protocols_1 = __importDefault(require("../protocols"));
35
+ const debug_1 = __importDefault(require("../debug"));
36
+ let buildDebug = (0, debug_1.default)('graph-cli:build');
37
+ const HELP = `
38
+ ${chalk_1.default.bold('graph build')} [options] ${chalk_1.default.bold('[<subgraph-manifest>]')}
39
+
40
+ Options:
41
+
42
+ -h, --help Show usage information
43
+ -i, --ipfs <node> Upload build results to an IPFS node
44
+ -o, --output-dir <path> Output directory for build results (default: build/)
45
+ -t, --output-format <format> Output format for mappings (wasm, wast) (default: wasm)
46
+ --skip-migrations Skip subgraph migrations (default: false)
47
+ -w, --watch Regenerate types when subgraph files change (default: false)
48
+ --network <name> Network configuration to use from the networks config file
49
+ --network-file <path> Networks config file path (default: "./networks.json")
50
+ `;
51
+ exports.default = {
52
+ description: 'Builds a subgraph and (optionally) uploads it to IPFS',
53
+ run: async (toolbox) => {
54
+ // Obtain tools
55
+ let { filesystem, patching, print, system } = toolbox;
56
+ // Parse CLI parameters
57
+ let { i, h, help, ipfs, o, outputDir, outputFormat, skipMigrations, t, w, watch, network, networkFile, } = toolbox.parameters.options;
58
+ // Support both short and long option variants
59
+ help = help || h;
60
+ ipfs = ipfs || i;
61
+ outputDir = outputDir || o;
62
+ outputFormat = outputFormat || t;
63
+ watch = watch || w;
64
+ let manifest;
65
+ try {
66
+ ;
67
+ [manifest] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
68
+ h,
69
+ help,
70
+ w,
71
+ watch,
72
+ });
73
+ }
74
+ catch (e) {
75
+ print.error(e.message);
76
+ process.exitCode = 1;
77
+ return;
78
+ }
79
+ // Fall back to default values for options / parameters
80
+ outputFormat =
81
+ outputFormat && ['wasm', 'wast'].indexOf(outputFormat) >= 0 ? outputFormat : 'wasm';
82
+ outputDir = outputDir && outputDir !== '' ? outputDir : filesystem.path('build');
83
+ manifest =
84
+ manifest !== undefined && manifest !== ''
85
+ ? manifest
86
+ : filesystem.resolve('subgraph.yaml');
87
+ networkFile =
88
+ networkFile !== undefined && networkFile !== ''
89
+ ? networkFile
90
+ : filesystem.resolve('networks.json');
91
+ // Show help text if requested
92
+ if (help) {
93
+ print.info(HELP);
94
+ return;
95
+ }
96
+ let protocol;
97
+ try {
98
+ const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
99
+ protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
100
+ }
101
+ catch (e) {
102
+ print.error(e.message);
103
+ process.exitCode = 1;
104
+ return;
105
+ }
106
+ buildDebug('Detected protocol "%s" (%o)', protocol.name, protocol);
107
+ if (network && filesystem.exists(networkFile) !== 'file') {
108
+ print.error(`Network file '${networkFile}' does not exists or is not a file!`);
109
+ process.exitCode = 1;
110
+ return;
111
+ }
112
+ if (network) {
113
+ let identifierName = protocol.getContract().identifierName();
114
+ await (0, network_1.updateSubgraphNetwork)(toolbox, manifest, network, networkFile, identifierName);
115
+ }
116
+ let compiler = (0, compiler_1.createCompiler)(manifest, {
117
+ ipfs,
118
+ outputDir,
119
+ outputFormat,
120
+ skipMigrations,
121
+ protocol,
122
+ });
123
+ // Exit with an error code if the compiler couldn't be created
124
+ if (!compiler) {
125
+ process.exitCode = 1;
126
+ return;
127
+ }
128
+ // Watch subgraph files for changes or additions, trigger
129
+ // compile (if watch argument specified)
130
+ if (watch) {
131
+ await compiler.watchAndCompile();
132
+ }
133
+ else {
134
+ let result = await compiler.compile();
135
+ if (result === false) {
136
+ process.exitCode = 1;
137
+ }
138
+ }
139
+ },
140
+ };