@graphprotocol/graph-cli 0.37.3-alpha-20230113132704-4100b25 → 0.37.3-alpha-20230113140726-64762bb

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 (174) hide show
  1. package/CHANGELOG.md +12 -5
  2. package/babel.config.js +1 -1
  3. package/dist/cli.js +2 -2
  4. package/dist/codegen/schema.js +33 -42
  5. package/dist/codegen/schema.test.js +2 -4
  6. package/dist/codegen/template.js +3 -3
  7. package/dist/codegen/types/conversions.js +6 -30
  8. package/dist/codegen/types/index.js +8 -11
  9. package/dist/codegen/typescript.js +2 -2
  10. package/dist/codegen/util.js +6 -8
  11. package/dist/command-helpers/abi.js +8 -12
  12. package/dist/command-helpers/auth.js +15 -17
  13. package/dist/command-helpers/compiler.js +9 -9
  14. package/dist/command-helpers/fs.js +2 -2
  15. package/dist/command-helpers/gluegun.js +3 -3
  16. package/dist/command-helpers/jsonrpc.js +5 -7
  17. package/dist/command-helpers/network.js +17 -20
  18. package/dist/command-helpers/network.test.js +9 -9
  19. package/dist/command-helpers/node.js +4 -4
  20. package/dist/command-helpers/scaffold.js +20 -22
  21. package/dist/command-helpers/spinner.js +7 -11
  22. package/dist/command-helpers/studio.js +2 -2
  23. package/dist/command-helpers/subgraph.js +3 -5
  24. package/dist/command-helpers/version.js +6 -15
  25. package/dist/command-helpers/version.test.js +3 -7
  26. package/dist/commands/add.js +38 -40
  27. package/dist/commands/auth.js +2 -7
  28. package/dist/commands/build.js +13 -17
  29. package/dist/commands/codegen.js +18 -25
  30. package/dist/commands/create.js +11 -12
  31. package/dist/commands/deploy.js +20 -24
  32. package/dist/commands/init.js +58 -60
  33. package/dist/commands/local.js +39 -43
  34. package/dist/commands/remove.js +11 -12
  35. package/dist/commands/test.js +51 -55
  36. package/dist/compiler/asc.js +1 -1
  37. package/dist/compiler/index.js +103 -123
  38. package/dist/migrations/mapping_api_version_0_0_1.js +5 -4
  39. package/dist/migrations/mapping_api_version_0_0_2.js +4 -3
  40. package/dist/migrations/mapping_api_version_0_0_3.js +4 -3
  41. package/dist/migrations/mapping_api_version_0_0_4.js +4 -3
  42. package/dist/migrations/mapping_api_version_0_0_5.js +4 -3
  43. package/dist/migrations/spec_version_0_0_2.js +2 -1
  44. package/dist/migrations/spec_version_0_0_3.js +2 -1
  45. package/dist/migrations/util/load-manifest.js +3 -5
  46. package/dist/migrations/util/versions.js +7 -7
  47. package/dist/migrations.js +5 -7
  48. package/dist/protocols/ethereum/abi.js +18 -26
  49. package/dist/protocols/ethereum/codegen/abi.js +56 -58
  50. package/dist/protocols/ethereum/codegen/abi.test.js +16 -17
  51. package/dist/protocols/ethereum/scaffold/manifest.js +2 -2
  52. package/dist/protocols/ethereum/subgraph.js +15 -19
  53. package/dist/protocols/ethereum/type-generator.js +19 -23
  54. package/dist/protocols/index.js +19 -19
  55. package/dist/protocols/ipfs/codegen/file_template.js +1 -0
  56. package/dist/protocols/near/contract.js +2 -3
  57. package/dist/scaffold/cosmos.test.js +1 -1
  58. package/dist/scaffold/ethereum.test.js +86 -95
  59. package/dist/scaffold/index.js +8 -12
  60. package/dist/scaffold/mapping.js +1 -1
  61. package/dist/scaffold/near.test.js +1 -1
  62. package/dist/scaffold/schema.js +2 -4
  63. package/dist/scaffold/tests.js +14 -10
  64. package/dist/schema.js +2 -2
  65. package/dist/subgraph.js +28 -28
  66. package/dist/type-generator.js +42 -44
  67. package/dist/validation/contract.js +6 -8
  68. package/dist/validation/index.js +6 -6
  69. package/dist/validation/manifest.js +18 -23
  70. package/dist/validation/schema.js +58 -86
  71. package/dist/watcher.js +14 -14
  72. package/jest.config.js +1 -1
  73. package/package.json +5 -5
  74. package/src/bin.ts +3 -2
  75. package/src/cli.ts +12 -12
  76. package/src/codegen/schema.test.ts +44 -50
  77. package/src/codegen/schema.ts +87 -90
  78. package/src/codegen/template.ts +16 -16
  79. package/src/codegen/types/conversions.ts +13 -37
  80. package/src/codegen/types/index.test.ts +416 -506
  81. package/src/codegen/types/index.ts +32 -42
  82. package/src/codegen/typescript.ts +74 -76
  83. package/src/codegen/util.test.ts +13 -13
  84. package/src/codegen/util.ts +21 -22
  85. package/src/command-helpers/abi.ts +35 -47
  86. package/src/command-helpers/auth.ts +28 -29
  87. package/src/command-helpers/compiler.ts +24 -24
  88. package/src/command-helpers/data-sources.ts +12 -14
  89. package/src/command-helpers/fs.ts +3 -3
  90. package/src/command-helpers/gluegun.ts +11 -11
  91. package/src/command-helpers/ipfs-http-client.d.ts +1 -1
  92. package/src/command-helpers/ipfs.ts +2 -2
  93. package/src/command-helpers/jsonrpc.ts +10 -14
  94. package/src/command-helpers/network.test.ts +43 -43
  95. package/src/command-helpers/network.ts +49 -61
  96. package/src/command-helpers/node.ts +21 -21
  97. package/src/command-helpers/scaffold.ts +69 -87
  98. package/src/command-helpers/spinner.ts +24 -26
  99. package/src/command-helpers/studio.test.ts +15 -15
  100. package/src/command-helpers/studio.ts +9 -9
  101. package/src/command-helpers/subgraph.ts +9 -10
  102. package/src/command-helpers/version.test.ts +56 -66
  103. package/src/command-helpers/version.ts +22 -39
  104. package/src/commands/add.ts +105 -121
  105. package/src/commands/auth.ts +50 -54
  106. package/src/commands/binary-install-raw.d.ts +1 -1
  107. package/src/commands/build.ts +57 -60
  108. package/src/commands/codegen.ts +52 -72
  109. package/src/commands/create.ts +48 -49
  110. package/src/commands/deploy.ts +137 -147
  111. package/src/commands/init.ts +336 -353
  112. package/src/commands/local.ts +189 -205
  113. package/src/commands/remove.ts +48 -49
  114. package/src/commands/test.ts +143 -145
  115. package/src/compiler/asc.ts +23 -29
  116. package/src/compiler/index.ts +245 -301
  117. package/src/debug.ts +7 -7
  118. package/src/migrations/mapping_api_version_0_0_1.ts +16 -20
  119. package/src/migrations/mapping_api_version_0_0_2.ts +16 -20
  120. package/src/migrations/mapping_api_version_0_0_3.ts +16 -20
  121. package/src/migrations/mapping_api_version_0_0_4.ts +16 -20
  122. package/src/migrations/mapping_api_version_0_0_5.ts +16 -20
  123. package/src/migrations/spec_version_0_0_2.ts +10 -20
  124. package/src/migrations/spec_version_0_0_3.ts +8 -6
  125. package/src/migrations/util/load-manifest.ts +5 -6
  126. package/src/migrations/util/versions.ts +10 -15
  127. package/src/migrations.ts +13 -18
  128. package/src/protocols/arweave/scaffold/manifest.ts +2 -2
  129. package/src/protocols/arweave/scaffold/mapping.ts +1 -1
  130. package/src/protocols/arweave/subgraph.ts +10 -10
  131. package/src/protocols/contract.ts +3 -3
  132. package/src/protocols/cosmos/scaffold/manifest.ts +2 -2
  133. package/src/protocols/cosmos/scaffold/mapping.ts +1 -1
  134. package/src/protocols/cosmos/subgraph.ts +10 -10
  135. package/src/protocols/ethereum/abi.ts +53 -58
  136. package/src/protocols/ethereum/codegen/abi.test.ts +90 -102
  137. package/src/protocols/ethereum/codegen/abi.ts +181 -237
  138. package/src/protocols/ethereum/codegen/template.ts +8 -8
  139. package/src/protocols/ethereum/contract.ts +7 -8
  140. package/src/protocols/ethereum/scaffold/manifest.ts +6 -12
  141. package/src/protocols/ethereum/scaffold/mapping.ts +6 -6
  142. package/src/protocols/ethereum/subgraph.ts +49 -59
  143. package/src/protocols/ethereum/type-generator.ts +59 -73
  144. package/src/protocols/index.ts +88 -93
  145. package/src/protocols/ipfs/codegen/file_template.ts +10 -8
  146. package/src/protocols/near/contract.ts +12 -15
  147. package/src/protocols/near/scaffold/manifest.ts +3 -3
  148. package/src/protocols/near/scaffold/mapping.ts +1 -1
  149. package/src/protocols/near/subgraph.ts +10 -10
  150. package/src/protocols/subgraph.ts +6 -6
  151. package/src/protocols/substreams/scaffold/manifest.ts +2 -2
  152. package/src/protocols/substreams/subgraph.ts +10 -10
  153. package/src/scaffold/cosmos.test.ts +12 -12
  154. package/src/scaffold/ethereum.test.ts +120 -129
  155. package/src/scaffold/index.ts +52 -57
  156. package/src/scaffold/mapping.ts +7 -15
  157. package/src/scaffold/near.test.ts +12 -12
  158. package/src/scaffold/schema.ts +23 -26
  159. package/src/scaffold/tests.ts +59 -63
  160. package/src/schema.ts +11 -11
  161. package/src/subgraph.ts +93 -100
  162. package/src/type-generator.ts +119 -137
  163. package/src/validation/contract.ts +24 -28
  164. package/src/validation/index.ts +4 -4
  165. package/src/validation/manifest.ts +59 -72
  166. package/src/validation/schema.test.ts +22 -22
  167. package/src/validation/schema.ts +210 -265
  168. package/src/watcher.ts +45 -45
  169. package/tests/cli/globalSetup.ts +6 -4
  170. package/tests/cli/globalTeardown.ts +6 -4
  171. package/tests/cli/init.test.ts +20 -20
  172. package/tests/cli/spawn-command.d.ts +5 -4
  173. package/tests/cli/util.ts +49 -45
  174. package/tests/cli/validation.test.ts +35 -43
package/CHANGELOG.md CHANGED
@@ -1,20 +1,27 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.37.3-alpha-20230113132704-4100b25
3
+ ## 0.37.3-alpha-20230113140726-64762bb
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - [#1020](https://github.com/graphprotocol/graph-cli/pull/1020) [`6184688`](https://github.com/graphprotocol/graph-cli/commit/6184688d7e6efaae49a722410befd28da0af87b0) Thanks [@saihaj](https://github.com/saihaj)! - dependencies updates:
8
- - Updated dependency [`immutable@4.2.1` ↗︎](https://www.npmjs.com/package/immutable/v/4.2.1) (from `3.8.2`, in `dependencies`)
7
+ - [#1020](https://github.com/graphprotocol/graph-cli/pull/1020)
8
+ [`4c5e452`](https://github.com/graphprotocol/graph-cli/commit/4c5e452cbc2eceb75db29019fb3b4c769c9618f4)
9
+ Thanks [@saihaj](https://github.com/saihaj)! - dependencies updates:
10
+ - Updated dependency [`immutable@4.2.1` ↗︎](https://www.npmjs.com/package/immutable/v/4.2.1) (from
11
+ `3.8.2`, in `dependencies`)
9
12
 
10
13
  ## 0.37.2
11
14
 
12
15
  ### Patch Changes
13
16
 
14
- - [#1023](https://github.com/graphprotocol/graph-cli/pull/1023) [`bf5ab6d`](https://github.com/graphprotocol/graph-cli/commit/bf5ab6dc0f19fcb5b8e599b7d9b1c2b6efcbe005) Thanks [@evaporei](https://github.com/evaporei)! - update graph-ts to 0.29.1
17
+ - [#1023](https://github.com/graphprotocol/graph-cli/pull/1023)
18
+ [`bf5ab6d`](https://github.com/graphprotocol/graph-cli/commit/bf5ab6dc0f19fcb5b8e599b7d9b1c2b6efcbe005)
19
+ Thanks [@evaporei](https://github.com/evaporei)! - update graph-ts to 0.29.1
15
20
 
16
21
  ## 0.37.1
17
22
 
18
23
  ### Patch Changes
19
24
 
20
- - [#1015](https://github.com/graphprotocol/graph-cli/pull/1015) [`5df304c`](https://github.com/graphprotocol/graph-cli/commit/5df304c75ecc339f681eeae858325a7859183dda) Thanks [@saihaj](https://github.com/saihaj)! - fix fantom network init URLs
25
+ - [#1015](https://github.com/graphprotocol/graph-cli/pull/1015)
26
+ [`5df304c`](https://github.com/graphprotocol/graph-cli/commit/5df304c75ecc339f681eeae858325a7859183dda)
27
+ Thanks [@saihaj](https://github.com/saihaj)! - fix fantom network init URLs
package/babel.config.js CHANGED
@@ -1,3 +1,3 @@
1
1
  module.exports = {
2
2
  presets: [['@babel/env', { targets: { node: 'current' } }], '@babel/typescript'],
3
- }
3
+ };
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.run = void 0;
7
- const path_1 = __importDefault(require("path"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
8
  const gluegun_1 = require("gluegun");
9
9
  const run = async (argv) => {
10
10
  let builder = (0, gluegun_1.build)().brand('graph').src(__dirname);
@@ -19,7 +19,7 @@ const run = async (argv) => {
19
19
  }
20
20
  }));
21
21
  // Inject potential plugin directories
22
- builder = pluginDirs.reduce((cli, dir) => cli.plugin(path_1.default.join(dir, '@graphprotocol', 'indexer-cli', 'dist')), builder);
22
+ builder = pluginDirs.reduce((cli, dir) => cli.plugin(node_path_1.default.join(dir, '@graphprotocol', 'indexer-cli', 'dist')), builder);
23
23
  const cli = builder.help().version().defaultCommand().create();
24
24
  return await cli.run(argv);
25
25
  };
@@ -27,8 +27,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const immutable_1 = __importDefault(require("immutable"));
30
- const tsCodegen = __importStar(require("./typescript"));
31
30
  const typesCodegen = __importStar(require("./types"));
31
+ const tsCodegen = __importStar(require("./typescript"));
32
32
  class IdField {
33
33
  static BYTES = Symbol('Bytes');
34
34
  static STRING = Symbol('String');
@@ -99,15 +99,14 @@ class SchemaCodeGenerator {
99
99
  return (def.get('kind') === 'ObjectTypeDefinition' &&
100
100
  def
101
101
  .get('directives')
102
- .find((directive) => directive.getIn(['name', 'value']) === 'entity') !==
103
- undefined);
102
+ .find((directive) => directive.getIn(['name', 'value']) === 'entity') !== undefined);
104
103
  }
105
104
  _isInterfaceDefinition(def) {
106
105
  return def.get('kind') === 'InterfaceTypeDefinition';
107
106
  }
108
107
  _generateEntityType(def) {
109
- let name = def.getIn(['name', 'value']);
110
- let klass = tsCodegen.klass(name, { export: true, extends: 'Entity' });
108
+ const name = def.getIn(['name', 'value']);
109
+ const klass = tsCodegen.klass(name, { export: true, extends: 'Entity' });
111
110
  const fields = def.get('fields');
112
111
  const idField = IdField.fromFields(fields);
113
112
  // Generate and add a constructor
@@ -148,13 +147,13 @@ class SchemaCodeGenerator {
148
147
  ]);
149
148
  }
150
149
  _generateEntityFieldGetter(_entityDef, fieldDef) {
151
- let name = fieldDef.getIn(['name', 'value']);
152
- let gqlType = fieldDef.get('type');
153
- let fieldValueType = this._valueTypeFromGraphQl(gqlType);
154
- let returnType = this._typeFromGraphQl(gqlType);
155
- let isNullable = returnType instanceof tsCodegen.NullableType;
156
- let getNonNullable = `return ${typesCodegen.valueToAsc('value!', fieldValueType)}`;
157
- let getNullable = `if (!value || value.kind == ValueKind.NULL) {
150
+ const name = fieldDef.getIn(['name', 'value']);
151
+ const gqlType = fieldDef.get('type');
152
+ const fieldValueType = this._valueTypeFromGraphQl(gqlType);
153
+ const returnType = this._typeFromGraphQl(gqlType);
154
+ const isNullable = returnType instanceof tsCodegen.NullableType;
155
+ const getNonNullable = `return ${typesCodegen.valueToAsc('value!', fieldValueType)}`;
156
+ const getNullable = `if (!value || value.kind == ValueKind.NULL) {
158
157
  return null
159
158
  } else {
160
159
  return ${typesCodegen.valueToAsc('value', fieldValueType)}
@@ -165,24 +164,24 @@ class SchemaCodeGenerator {
165
164
  `);
166
165
  }
167
166
  _generateEntityFieldSetter(_entityDef, fieldDef) {
168
- let name = fieldDef.getIn(['name', 'value']);
169
- let gqlType = fieldDef.get('type');
170
- let fieldValueType = this._valueTypeFromGraphQl(gqlType);
171
- let paramType = this._typeFromGraphQl(gqlType);
172
- let isNullable = paramType instanceof tsCodegen.NullableType;
173
- let paramTypeString = isNullable ? paramType.inner.toString() : paramType.toString();
174
- let isArray = paramType instanceof tsCodegen.ArrayType;
167
+ const name = fieldDef.getIn(['name', 'value']);
168
+ const gqlType = fieldDef.get('type');
169
+ const fieldValueType = this._valueTypeFromGraphQl(gqlType);
170
+ const paramType = this._typeFromGraphQl(gqlType);
171
+ const isNullable = paramType instanceof tsCodegen.NullableType;
172
+ const paramTypeString = isNullable ? paramType.inner.toString() : paramType.toString();
173
+ const isArray = paramType instanceof tsCodegen.ArrayType;
175
174
  if (isArray && paramType.inner instanceof tsCodegen.NullableType) {
176
- let baseType = this._baseType(gqlType);
175
+ const baseType = this._baseType(gqlType);
177
176
  throw new Error(`
178
177
  GraphQL schema can't have List's with Nullable members.
179
178
  Error in '${name}' field of type '[${baseType}]'.
180
179
  Suggestion: add an '!' to the member type of the List, change from '[${baseType}]' to '[${baseType}!]'`);
181
180
  }
182
- let setNonNullable = `
181
+ const setNonNullable = `
183
182
  this.set('${name}', ${typesCodegen.valueFromAsc(`value`, fieldValueType)})
184
183
  `;
185
- let setNullable = `
184
+ const setNullable = `
186
185
  if (!value) {
187
186
  this.unset('${name}')
188
187
  } else {
@@ -192,7 +191,7 @@ Suggestion: add an '!' to the member type of the List, change from '[${baseType}
192
191
  return tsCodegen.method(`set ${name}`, [tsCodegen.param('value', paramType)], undefined, isNullable ? setNullable : setNonNullable);
193
192
  }
194
193
  _resolveFieldType(gqlType) {
195
- let typeName = gqlType.getIn(['name', 'value']);
194
+ const typeName = gqlType.getIn(['name', 'value']);
196
195
  // If this is a reference to another type, the field has the type of
197
196
  // the referred type's id field
198
197
  const typeDef = this.schema.ast
@@ -202,9 +201,7 @@ Suggestion: add an '!' to the member type of the List, change from '[${baseType}
202
201
  if (typeDef) {
203
202
  return IdField.fromTypeDef(typeDef).typeName();
204
203
  }
205
- else {
206
- return typeName;
207
- }
204
+ return typeName;
208
205
  }
209
206
  /** Return the type that values for this field must have. For scalar
210
207
  * types, that's the type from the subgraph schema. For references to
@@ -214,12 +211,10 @@ Suggestion: add an '!' to the member type of the List, change from '[${baseType}
214
211
  if (gqlType.get('kind') === 'NonNullType') {
215
212
  return this._valueTypeFromGraphQl(gqlType.get('type'));
216
213
  }
217
- else if (gqlType.get('kind') === 'ListType') {
214
+ if (gqlType.get('kind') === 'ListType') {
218
215
  return '[' + this._valueTypeFromGraphQl(gqlType.get('type')) + ']';
219
216
  }
220
- else {
221
- return this._resolveFieldType(gqlType);
222
- }
217
+ return this._resolveFieldType(gqlType);
223
218
  }
224
219
  /** Determine the base type of `gqlType` by removing any non-null
225
220
  * constraints and using the type of elements of lists */
@@ -227,27 +222,23 @@ Suggestion: add an '!' to the member type of the List, change from '[${baseType}
227
222
  if (gqlType.get('kind') === 'NonNullType') {
228
223
  return this._baseType(gqlType.get('type'));
229
224
  }
230
- else if (gqlType.get('kind') === 'ListType') {
225
+ if (gqlType.get('kind') === 'ListType') {
231
226
  return this._baseType(gqlType.get('type'));
232
227
  }
233
- else {
234
- return gqlType.getIn(['name', 'value']);
235
- }
228
+ return gqlType.getIn(['name', 'value']);
236
229
  }
237
230
  _typeFromGraphQl(gqlType, nullable = true) {
238
231
  if (gqlType.get('kind') === 'NonNullType') {
239
232
  return this._typeFromGraphQl(gqlType.get('type'), false);
240
233
  }
241
- else if (gqlType.get('kind') === 'ListType') {
242
- let type = tsCodegen.arrayType(this._typeFromGraphQl(gqlType.get('type')));
234
+ if (gqlType.get('kind') === 'ListType') {
235
+ const type = tsCodegen.arrayType(this._typeFromGraphQl(gqlType.get('type')));
243
236
  return nullable ? tsCodegen.nullableType(type) : type;
244
237
  }
245
- else {
246
- // NamedType
247
- let type = tsCodegen.namedType(typesCodegen.ascTypeForValue(this._resolveFieldType(gqlType)));
248
- // In AssemblyScript, primitives cannot be nullable.
249
- return nullable && !type.isPrimitive() ? tsCodegen.nullableType(type) : type;
250
- }
238
+ // NamedType
239
+ const type = tsCodegen.namedType(typesCodegen.ascTypeForValue(this._resolveFieldType(gqlType)));
240
+ // In AssemblyScript, primitives cannot be nullable.
241
+ return nullable && !type.isPrimitive() ? tsCodegen.nullableType(type) : type;
251
242
  }
252
243
  }
253
244
  exports.default = SchemaCodeGenerator;
@@ -26,9 +26,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- const prettier_1 = __importDefault(require("prettier"));
30
29
  const graphql = __importStar(require("graphql/language"));
31
30
  const immutable_1 = __importDefault(require("immutable"));
31
+ const prettier_1 = __importDefault(require("prettier"));
32
32
  const schema_1 = __importDefault(require("../schema"));
33
33
  const schema_2 = __importDefault(require("./schema"));
34
34
  const typescript_1 = require("./typescript");
@@ -246,9 +246,7 @@ describe('Schema code generator', () => {
246
246
  },
247
247
  {
248
248
  name: 'set wallets',
249
- params: [
250
- new typescript_1.Param('value', new typescript_1.NullableType(new typescript_1.ArrayType(new typescript_1.NamedType('string')))),
251
- ],
249
+ params: [new typescript_1.Param('value', new typescript_1.NullableType(new typescript_1.ArrayType(new typescript_1.NamedType('string'))))],
252
250
  returnType: undefined,
253
251
  body: `
254
252
  if (!value) {
@@ -35,7 +35,7 @@ class DataSourceTemplateCodeGenerator {
35
35
  constructor(template, protocol) {
36
36
  this.template = template;
37
37
  this.template = template;
38
- let kind = template.get('kind');
38
+ const kind = template.get('kind');
39
39
  if (kind.split('/')[0] == protocol.name) {
40
40
  this.protocolTemplateCodeGen = protocol.getTemplateCodeGen(template);
41
41
  }
@@ -56,8 +56,8 @@ class DataSourceTemplateCodeGenerator {
56
56
  return immutable_1.default.List([this._generateTemplateType()]);
57
57
  }
58
58
  _generateTemplateType() {
59
- let name = this.template.get('name');
60
- let klass = tsCodegen.klass(name, { export: true, extends: 'DataSourceTemplate' });
59
+ const name = this.template.get('name');
60
+ const klass = tsCodegen.klass(name, { export: true, extends: 'DataSourceTemplate' });
61
61
  klass.addMethod(this.protocolTemplateCodeGen.generateCreateMethod());
62
62
  klass.addMethod(this.protocolTemplateCodeGen.generateCreateWithContextMethod());
63
63
  return klass;
@@ -154,11 +154,7 @@ const ASSEMBLYSCRIPT_TO_ETHEREUM_VALUE = [
154
154
  /^byte\[([0-9]+)?\]$/,
155
155
  (code) => `ethereum.Value.fromFixedBytesArray(${code})`,
156
156
  ],
157
- [
158
- 'Array<Bytes>',
159
- /bytes\[([0-9]+)?\]$/,
160
- (code) => `ethereum.Value.fromBytesArray(${code})`,
161
- ],
157
+ ['Array<Bytes>', /bytes\[([0-9]+)?\]$/, (code) => `ethereum.Value.fromBytesArray(${code})`],
162
158
  [
163
159
  'Array<Bytes>',
164
160
  /^bytes(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32)\[([0-9]+)?\]$/,
@@ -287,33 +283,17 @@ const ASSEMBLYSCRIPT_TO_VALUE = [
287
283
  // Matrices
288
284
  ['Array<Array<Address>>', '[[Bytes]]', (code) => `Value.fromBytesMatrix(${code})`],
289
285
  ['Array<Array<Bytes>>', '[[Bytes]]', (code) => `Value.fromBytesMatrix(${code})`],
290
- [
291
- 'Array<Array<boolean>>',
292
- '[[Boolean]]',
293
- (code) => `Value.fromBooleanMatrix(${code})`,
294
- ],
286
+ ['Array<Array<boolean>>', '[[Boolean]]', (code) => `Value.fromBooleanMatrix(${code})`],
295
287
  ['Array<Array<i32>>', '[[Int]]', (code) => `Value.fromI32Matrix(${code})`],
296
- [
297
- 'Array<Array<BigInt>>',
298
- '[[BigInt]]',
299
- (code) => `Value.fromBigIntMatrix(${code})`,
300
- ],
301
- [
302
- 'Array<Array<string>>',
303
- '[[String]]',
304
- (code) => `Value.fromStringMatrix(${code})`,
305
- ],
288
+ ['Array<Array<BigInt>>', '[[BigInt]]', (code) => `Value.fromBigIntMatrix(${code})`],
289
+ ['Array<Array<string>>', '[[String]]', (code) => `Value.fromStringMatrix(${code})`],
306
290
  ['Array<Array<string>>', '[[ID]]', (code) => `Value.fromStringMatrix(${code})`],
307
291
  [
308
292
  'Array<Array<BigDecimal>>',
309
293
  '[[BigDecimal]]',
310
294
  (code) => `Value.fromBigDecimalMatrix(${code})`,
311
295
  ],
312
- [
313
- 'Array<Array<string>>',
314
- /\[\[.*\]\]/,
315
- (code) => `Value.fromStringMatrix(${code})`,
316
- ],
296
+ ['Array<Array<string>>', /\[\[.*\]\]/, (code) => `Value.fromStringMatrix(${code})`],
317
297
  ['Array<Array<string | null>>', null, (code) => `Value.fromStringMatrix(${code})`],
318
298
  // Arrays
319
299
  ['Array<Address>', '[Bytes]', (code) => `Value.fromBytesArray(${code})`],
@@ -323,11 +303,7 @@ const ASSEMBLYSCRIPT_TO_VALUE = [
323
303
  ['Array<BigInt>', '[BigInt]', (code) => `Value.fromBigIntArray(${code})`],
324
304
  ['Array<string>', '[String]', (code) => `Value.fromStringArray(${code})`],
325
305
  ['Array<string>', '[ID]', (code) => `Value.fromStringArray(${code})`],
326
- [
327
- 'Array<BigDecimal>',
328
- '[BigDecimal]',
329
- (code) => `Value.fromBigDecimalArray(${code})`,
330
- ],
306
+ ['Array<BigDecimal>', '[BigDecimal]', (code) => `Value.fromBigDecimalArray(${code})`],
331
307
  ['Array<string>', /\[.*\]/, (code) => `Value.fromStringArray(${code})`],
332
308
  ['Array<string | null>', null, (code) => `Value.fromStringArray(${code})`],
333
309
  // Scalar values
@@ -8,7 +8,7 @@ const immutable_1 = __importDefault(require("immutable"));
8
8
  const conversions_1 = __importDefault(require("./conversions"));
9
9
  // Conversion utilities
10
10
  const conversionsForTypeSystems = (fromTypeSystem, toTypeSystem) => {
11
- let conversions = conversions_1.default.getIn([fromTypeSystem, toTypeSystem]);
11
+ const conversions = conversions_1.default.getIn([fromTypeSystem, toTypeSystem]);
12
12
  if (conversions === undefined) {
13
13
  throw new Error(`Conversions from '${fromTypeSystem}' to '${toTypeSystem}' are not supported`);
14
14
  }
@@ -28,10 +28,10 @@ const objectifyConversion = (fromTypeSystem, toTypeSystem, conversion) => {
28
28
  });
29
29
  };
30
30
  const findConversionFromType = (fromTypeSystem, toTypeSystem, fromType) => {
31
- let conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
32
- let conversion = conversions.find(conversion => typeof conversion.get(0) === 'string'
31
+ const conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
32
+ const conversion = conversions.find(conversion => typeof conversion.get(0) === 'string'
33
33
  ? conversion.get(0) === fromType
34
- : Boolean(fromType.match(conversion.get(0))));
34
+ : !!fromType.match(conversion.get(0)));
35
35
  if (conversion === undefined) {
36
36
  throw new Error(`Conversion from '${fromTypeSystem}' to '${toTypeSystem}' for ` +
37
37
  `source type '${fromType}' is not supported`);
@@ -39,10 +39,10 @@ const findConversionFromType = (fromTypeSystem, toTypeSystem, fromType) => {
39
39
  return objectifyConversion(fromTypeSystem, toTypeSystem, conversion);
40
40
  };
41
41
  const findConversionToType = (fromTypeSystem, toTypeSystem, toType) => {
42
- let conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
43
- let conversion = conversions.find(conversion => typeof conversion.get(1) === 'string'
42
+ const conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
43
+ const conversion = conversions.find(conversion => typeof conversion.get(1) === 'string'
44
44
  ? conversion.get(1) === toType
45
- : Boolean(toType.match(conversion.get(1))));
45
+ : !!toType.match(conversion.get(1)));
46
46
  if (conversion === undefined) {
47
47
  throw new Error(`Conversion from '${fromTypeSystem}' to '${toTypeSystem}' for ` +
48
48
  `target type '${toType}' is not supported`);
@@ -50,10 +50,7 @@ const findConversionToType = (fromTypeSystem, toTypeSystem, toType) => {
50
50
  return objectifyConversion(fromTypeSystem, toTypeSystem, conversion);
51
51
  };
52
52
  // High-level type system API
53
- const ascTypeForProtocol = (protocol, protocolType) => findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn([
54
- 'to',
55
- 'type',
56
- ]);
53
+ const ascTypeForProtocol = (protocol, protocolType) => findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn(['to', 'type']);
57
54
  exports.ascTypeForProtocol = ascTypeForProtocol;
58
55
  // TODO: this can be removed/replaced by the function above
59
56
  const ascTypeForEthereum = (ethereumType) => (0, exports.ascTypeForProtocol)('ethereum', ethereumType);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GENERATED_FILE_NOTE = exports.moduleImports = exports.nullableType = exports.param = exports.staticMethod = exports.method = exports.klassMember = exports.klass = exports.arrayType = exports.namedType = exports.ModuleImports = exports.ArrayType = exports.NullableType = exports.NamedType = exports.ClassMember = exports.Class = exports.StaticMethod = exports.Method = exports.Param = void 0;
3
+ exports.staticMethod = exports.StaticMethod = exports.param = exports.Param = exports.nullableType = exports.NullableType = exports.namedType = exports.NamedType = exports.moduleImports = exports.ModuleImports = exports.method = exports.Method = exports.klassMember = exports.klass = exports.GENERATED_FILE_NOTE = exports.ClassMember = exports.Class = exports.arrayType = exports.ArrayType = void 0;
4
4
  class Param {
5
5
  name;
6
6
  type;
@@ -119,7 +119,7 @@ class NamedType {
119
119
  return this;
120
120
  }
121
121
  isPrimitive() {
122
- let primitives = [
122
+ const primitives = [
123
123
  'boolean',
124
124
  'u8',
125
125
  'i8',
@@ -2,18 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unrollTuple = exports.isTupleMatrixType = exports.isTupleArrayType = exports.containsTupleType = exports.isTupleType = exports.disambiguateNames = void 0;
4
4
  function disambiguateNames({ values, getName, setName, }) {
5
- let collisionCounter = new Map();
5
+ const collisionCounter = new Map();
6
6
  return values.map((value, index) => {
7
- let name = getName(value, index);
8
- let counter = collisionCounter.get(name);
7
+ const name = getName(value, index);
8
+ const counter = collisionCounter.get(name);
9
9
  if (counter === undefined) {
10
10
  collisionCounter.set(name, 1);
11
11
  return setName(value, name);
12
12
  }
13
- else {
14
- collisionCounter.set(name, counter + 1);
15
- return setName(value, `${name}${counter}`);
16
- }
13
+ collisionCounter.set(name, counter + 1);
14
+ return setName(value, `${name}${counter}`);
17
15
  });
18
16
  }
19
17
  exports.disambiguateNames = disambiguateNames;
@@ -34,7 +32,7 @@ function isTupleMatrixType(t) {
34
32
  }
35
33
  exports.isTupleMatrixType = isTupleMatrixType;
36
34
  const unrollTuple = ({ path, value, }) => value.components.reduce((acc, component, index) => {
37
- let name = component.name || `value${index}`;
35
+ const name = component.name || `value${index}`;
38
36
  return acc.concat(component.type === 'tuple'
39
37
  ? (0, exports.unrollTuple)({ path: [...path, name], index, value: component })
40
38
  : [{ path: [...path, name], type: component.type }]);
@@ -4,36 +4,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.loadAbiFromBlockScout = exports.loadAbiFromEtherscan = void 0;
7
- const spinner_1 = require("./spinner");
8
- const node_fetch_1 = __importDefault(require("node-fetch"));
9
7
  const immutable_1 = __importDefault(require("immutable"));
8
+ const node_fetch_1 = __importDefault(require("node-fetch"));
9
+ const spinner_1 = require("./spinner");
10
10
  const loadAbiFromEtherscan = async (ABICtor, network, address) => await (0, spinner_1.withSpinner)(`Fetching ABI from Etherscan`, `Failed to fetch ABI from Etherscan`, `Warnings while fetching ABI from Etherscan`, async () => {
11
11
  const scanApiUrl = getEtherscanLikeAPIUrl(network);
12
- let result = await (0, node_fetch_1.default)(`${scanApiUrl}?module=contract&action=getabi&address=${address}`);
13
- let json = await result.json();
12
+ const result = await (0, node_fetch_1.default)(`${scanApiUrl}?module=contract&action=getabi&address=${address}`);
13
+ const json = await result.json();
14
14
  // Etherscan returns a JSON object that has a `status`, a `message` and
15
15
  // a `result` field. The `status` is '0' in case of errors and '1' in
16
16
  // case of success
17
17
  if (json.status === '1') {
18
18
  return new ABICtor('Contract', undefined, immutable_1.default.fromJS(JSON.parse(json.result)));
19
19
  }
20
- else {
21
- throw new Error('ABI not found, try loading it from a local file');
22
- }
20
+ throw new Error('ABI not found, try loading it from a local file');
23
21
  });
24
22
  exports.loadAbiFromEtherscan = loadAbiFromEtherscan;
25
23
  const loadAbiFromBlockScout = async (ABICtor, network, address) => await (0, spinner_1.withSpinner)(`Fetching ABI from BlockScout`, `Failed to fetch ABI from BlockScout`, `Warnings while fetching ABI from BlockScout`, async () => {
26
- let result = await (0, node_fetch_1.default)(`https://blockscout.com/${network.replace('-', '/')}/api?module=contract&action=getabi&address=${address}`);
27
- let json = await result.json();
24
+ const result = await (0, node_fetch_1.default)(`https://blockscout.com/${network.replace('-', '/')}/api?module=contract&action=getabi&address=${address}`);
25
+ const json = await result.json();
28
26
  // BlockScout returns a JSON object that has a `status`, a `message` and
29
27
  // a `result` field. The `status` is '0' in case of errors and '1' in
30
28
  // case of success
31
29
  if (json.status === '1') {
32
30
  return new ABICtor('Contract', undefined, immutable_1.default.fromJS(JSON.parse(json.result)));
33
31
  }
34
- else {
35
- throw new Error('ABI not found, try loading it from a local file');
36
- }
32
+ throw new Error('ABI not found, try loading it from a local file');
37
33
  });
38
34
  exports.loadAbiFromBlockScout = loadAbiFromBlockScout;
39
35
  const getEtherscanLikeAPIUrl = (network) => {
@@ -27,17 +27,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.saveDeployKey = exports.identifyDeployKey = void 0;
30
+ const node_fs_1 = __importDefault(require("node:fs"));
31
+ const node_os_1 = __importDefault(require("node:os"));
32
+ const node_path_1 = __importDefault(require("node:path"));
30
33
  const toolbox = __importStar(require("gluegun"));
31
34
  const node_1 = require("./node");
32
- const fs_1 = __importDefault(require("fs"));
33
- const path_1 = __importDefault(require("path"));
34
- const os_1 = __importDefault(require("os"));
35
- const homedir = os_1.default.homedir();
36
- const CONFIG_PATH = path_1.default.join(homedir, '/.graph-cli.json');
35
+ const homedir = node_os_1.default.homedir();
36
+ const CONFIG_PATH = node_path_1.default.join(homedir, '/.graph-cli.json');
37
37
  const getConfig = () => {
38
38
  let config;
39
39
  try {
40
- config = JSON.parse(fs_1.default.readFileSync(CONFIG_PATH).toString());
40
+ config = JSON.parse(node_fs_1.default.readFileSync(CONFIG_PATH).toString());
41
41
  }
42
42
  catch {
43
43
  config = {};
@@ -51,16 +51,14 @@ const identifyDeployKey = async (node, deployKey) => {
51
51
  if (deployKey !== undefined) {
52
52
  return deployKey;
53
53
  }
54
- else {
55
- try {
56
- node = (0, node_1.normalizeNodeUrl)(node);
57
- const config = getConfig();
58
- return config[node];
59
- }
60
- catch (e) {
61
- toolbox.print.warning(`Could not get deploy key: ${e.message}`);
62
- toolbox.print.info(`Continuing without a deploy key\n`);
63
- }
54
+ try {
55
+ node = (0, node_1.normalizeNodeUrl)(node);
56
+ const config = getConfig();
57
+ return config[node];
58
+ }
59
+ catch (e) {
60
+ toolbox.print.warning(`Could not get deploy key: ${e.message}`);
61
+ toolbox.print.info(`Continuing without a deploy key\n`);
64
62
  }
65
63
  };
66
64
  exports.identifyDeployKey = identifyDeployKey;
@@ -69,7 +67,7 @@ const saveDeployKey = async (node, deployKey) => {
69
67
  node = (0, node_1.normalizeNodeUrl)(node);
70
68
  const config = getConfig();
71
69
  config[node] = deployKey;
72
- fs_1.default.writeFileSync(CONFIG_PATH, JSON.stringify(config));
70
+ node_fs_1.default.writeFileSync(CONFIG_PATH, JSON.stringify(config));
73
71
  }
74
72
  catch (e) {
75
73
  throw new Error(`Error storing deploy key: ${e.message}`);
@@ -27,16 +27,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.createCompiler = void 0;
30
- const URL = require('url').URL;
31
- const ipfs_http_client_1 = __importDefault(require("ipfs-http-client"));
30
+ const node_url_1 = require("node:url");
32
31
  const toolbox = __importStar(require("gluegun"));
32
+ const ipfs_http_client_1 = __importDefault(require("ipfs-http-client"));
33
33
  const compiler_1 = __importDefault(require("../compiler"));
34
34
  // Helper function to construct a subgraph compiler
35
35
  function createCompiler(manifest, { ipfs, headers, outputDir, outputFormat, skipMigrations, blockIpfsMethods, protocol, }) {
36
36
  // Parse the IPFS URL
37
37
  let url;
38
38
  try {
39
- url = ipfs ? new URL(ipfs) : undefined;
39
+ url = ipfs ? new node_url_1.URL(ipfs) : undefined;
40
40
  }
41
41
  catch (e) {
42
42
  toolbox.print.error(`Invalid IPFS URL: ${ipfs}
@@ -46,18 +46,18 @@ The IPFS URL must be of the following format: http(s)://host[:port]/[path]`);
46
46
  // Connect to the IPFS node (if a node address was provided)
47
47
  ipfs = ipfs
48
48
  ? (0, ipfs_http_client_1.default)({
49
- protocol: url.protocol.replace(/[:]+$/, ''),
50
- host: url.hostname,
51
- port: url.port,
52
- 'api-path': url.pathname.replace(/\/$/, '') + '/api/v0/',
49
+ protocol: url?.protocol.replace(/[:]+$/, ''),
50
+ host: url?.hostname,
51
+ port: url?.port,
52
+ 'api-path': url?.pathname.replace(/\/$/, '') + '/api/v0/',
53
53
  headers,
54
54
  })
55
55
  : undefined;
56
56
  return new compiler_1.default({
57
57
  ipfs,
58
58
  subgraphManifest: manifest,
59
- outputDir: outputDir,
60
- outputFormat: outputFormat,
59
+ outputDir,
60
+ outputFormat,
61
61
  skipMigrations,
62
62
  blockIpfsMethods,
63
63
  protocol,
@@ -4,6 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.displayPath = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const displayPath = (p) => path_1.default.relative(process.cwd(), p);
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const displayPath = (p) => node_path_1.default.relative(process.cwd(), p);
9
9
  exports.displayPath = displayPath;
@@ -27,17 +27,17 @@
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
28
  exports.fixParameters = void 0;
29
29
  const fixParameters = (parameters, booleanOptions) => {
30
- let unexpectedStringOptions = Object.keys(booleanOptions)
30
+ const unexpectedStringOptions = Object.keys(booleanOptions)
31
31
  .filter(key => typeof booleanOptions[key] === 'string')
32
32
  .map(key => ({ key, value: booleanOptions[key] }));
33
- let optionNames = unexpectedStringOptions
33
+ const optionNames = unexpectedStringOptions
34
34
  .map(({ key }) => `--` + key.replace(/([A-Z])/, '-$1').toLowerCase())
35
35
  .join(', ');
36
36
  if (unexpectedStringOptions.length > 1) {
37
37
  throw new Error(`Unexpected value provided for one or more of ${optionNames}. See --help for more information.`);
38
38
  }
39
39
  else if (unexpectedStringOptions.length == 1) {
40
- let params = parameters.array;
40
+ const params = parameters.array;
41
41
  params.unshift(unexpectedStringOptions[0].value);
42
42
  return params;
43
43
  }
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createJsonRpcClient = void 0;
7
- const jayson_1 = __importDefault(require("jayson"));
8
7
  const gluegun_1 = require("gluegun");
8
+ const jayson_1 = __importDefault(require("jayson"));
9
9
  function createJsonRpcClient(url) {
10
10
  const params = {
11
11
  host: url.hostname,
@@ -17,13 +17,11 @@ function createJsonRpcClient(url) {
17
17
  if (url.protocol === 'https:') {
18
18
  return jayson_1.default.Client.https(params);
19
19
  }
20
- else if (url.protocol === 'http:') {
20
+ if (url.protocol === 'http:') {
21
21
  return jayson_1.default.Client.http(params);
22
22
  }
23
- else {
24
- gluegun_1.print.error(`Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`);
25
- gluegun_1.print.error('The Graph Node URL must be of the following format: http(s)://host[:port]/[path]');
26
- return null;
27
- }
23
+ gluegun_1.print.error(`Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`);
24
+ gluegun_1.print.error('The Graph Node URL must be of the following format: http(s)://host[:port]/[path]');
25
+ return null;
28
26
  }
29
27
  exports.createJsonRpcClient = createJsonRpcClient;