@graphprotocol/graph-cli 0.37.3-alpha-20230113132704-4100b25 → 0.37.3-alpha-20230113140856-3e7bd95
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.
- package/CHANGELOG.md +12 -5
- package/babel.config.js +1 -1
- package/dist/codegen/schema.js +33 -42
- package/dist/codegen/schema.test.js +2 -4
- package/dist/codegen/template.js +3 -3
- package/dist/codegen/types/conversions.js +6 -30
- package/dist/codegen/types/index.js +8 -11
- package/dist/codegen/typescript.js +2 -2
- package/dist/codegen/util.js +6 -8
- package/dist/command-helpers/abi.js +8 -12
- package/dist/command-helpers/auth.js +11 -13
- package/dist/command-helpers/compiler.js +9 -9
- package/dist/command-helpers/gluegun.js +3 -3
- package/dist/command-helpers/jsonrpc.js +5 -7
- package/dist/command-helpers/network.js +16 -19
- package/dist/command-helpers/network.test.js +8 -8
- package/dist/command-helpers/node.js +1 -1
- package/dist/command-helpers/scaffold.js +19 -21
- package/dist/command-helpers/spinner.js +7 -11
- package/dist/command-helpers/studio.js +2 -2
- package/dist/command-helpers/subgraph.js +3 -5
- package/dist/command-helpers/version.js +6 -15
- package/dist/command-helpers/version.test.js +3 -7
- package/dist/commands/add.js +38 -40
- package/dist/commands/auth.js +2 -7
- package/dist/commands/build.js +13 -17
- package/dist/commands/codegen.js +17 -24
- package/dist/commands/create.js +10 -11
- package/dist/commands/deploy.js +19 -23
- package/dist/commands/init.js +49 -51
- package/dist/commands/local.js +31 -35
- package/dist/commands/remove.js +10 -11
- package/dist/commands/test.js +41 -45
- package/dist/compiler/asc.js +1 -1
- package/dist/compiler/index.js +77 -97
- package/dist/migrations/mapping_api_version_0_0_1.js +5 -4
- package/dist/migrations/mapping_api_version_0_0_2.js +4 -3
- package/dist/migrations/mapping_api_version_0_0_3.js +4 -3
- package/dist/migrations/mapping_api_version_0_0_4.js +4 -3
- package/dist/migrations/mapping_api_version_0_0_5.js +4 -3
- package/dist/migrations/spec_version_0_0_2.js +2 -1
- package/dist/migrations/spec_version_0_0_3.js +2 -1
- package/dist/migrations/util/load-manifest.js +2 -4
- package/dist/migrations/util/versions.js +4 -4
- package/dist/migrations.js +5 -7
- package/dist/protocols/ethereum/abi.js +17 -25
- package/dist/protocols/ethereum/codegen/abi.js +54 -56
- package/dist/protocols/ethereum/codegen/abi.test.js +16 -17
- package/dist/protocols/ethereum/scaffold/manifest.js +2 -2
- package/dist/protocols/ethereum/subgraph.js +15 -19
- package/dist/protocols/ethereum/type-generator.js +17 -21
- package/dist/protocols/index.js +19 -19
- package/dist/protocols/ipfs/codegen/file_template.js +1 -0
- package/dist/protocols/near/contract.js +2 -3
- package/dist/scaffold/cosmos.test.js +1 -1
- package/dist/scaffold/ethereum.test.js +86 -95
- package/dist/scaffold/index.js +8 -12
- package/dist/scaffold/mapping.js +1 -1
- package/dist/scaffold/near.test.js +1 -1
- package/dist/scaffold/schema.js +2 -4
- package/dist/scaffold/tests.js +14 -10
- package/dist/schema.js +2 -2
- package/dist/subgraph.js +24 -24
- package/dist/type-generator.js +38 -40
- package/dist/validation/contract.js +6 -8
- package/dist/validation/index.js +6 -6
- package/dist/validation/manifest.js +17 -22
- package/dist/validation/schema.js +56 -84
- package/dist/watcher.js +13 -13
- package/jest.config.js +1 -1
- package/package.json +5 -5
- package/src/bin.ts +3 -2
- package/src/cli.ts +12 -12
- package/src/codegen/schema.test.ts +44 -50
- package/src/codegen/schema.ts +87 -90
- package/src/codegen/template.ts +16 -16
- package/src/codegen/types/conversions.ts +13 -37
- package/src/codegen/types/index.test.ts +416 -506
- package/src/codegen/types/index.ts +32 -42
- package/src/codegen/typescript.ts +74 -76
- package/src/codegen/util.test.ts +13 -13
- package/src/codegen/util.ts +21 -22
- package/src/command-helpers/abi.ts +35 -47
- package/src/command-helpers/auth.ts +28 -29
- package/src/command-helpers/compiler.ts +24 -24
- package/src/command-helpers/data-sources.ts +12 -14
- package/src/command-helpers/fs.ts +3 -3
- package/src/command-helpers/gluegun.ts +11 -11
- package/src/command-helpers/ipfs-http-client.d.ts +1 -1
- package/src/command-helpers/ipfs.ts +2 -2
- package/src/command-helpers/jsonrpc.ts +10 -14
- package/src/command-helpers/network.test.ts +43 -43
- package/src/command-helpers/network.ts +49 -61
- package/src/command-helpers/node.ts +21 -21
- package/src/command-helpers/scaffold.ts +69 -87
- package/src/command-helpers/spinner.ts +24 -26
- package/src/command-helpers/studio.test.ts +15 -15
- package/src/command-helpers/studio.ts +9 -9
- package/src/command-helpers/subgraph.ts +9 -10
- package/src/command-helpers/version.test.ts +56 -66
- package/src/command-helpers/version.ts +22 -39
- package/src/commands/add.ts +105 -121
- package/src/commands/auth.ts +50 -54
- package/src/commands/binary-install-raw.d.ts +1 -1
- package/src/commands/build.ts +57 -60
- package/src/commands/codegen.ts +52 -72
- package/src/commands/create.ts +48 -49
- package/src/commands/deploy.ts +137 -147
- package/src/commands/init.ts +336 -353
- package/src/commands/local.ts +189 -205
- package/src/commands/remove.ts +48 -49
- package/src/commands/test.ts +143 -145
- package/src/compiler/asc.ts +23 -29
- package/src/compiler/index.ts +245 -301
- package/src/debug.ts +7 -7
- package/src/migrations/mapping_api_version_0_0_1.ts +16 -20
- package/src/migrations/mapping_api_version_0_0_2.ts +16 -20
- package/src/migrations/mapping_api_version_0_0_3.ts +16 -20
- package/src/migrations/mapping_api_version_0_0_4.ts +16 -20
- package/src/migrations/mapping_api_version_0_0_5.ts +16 -20
- package/src/migrations/spec_version_0_0_2.ts +10 -20
- package/src/migrations/spec_version_0_0_3.ts +8 -6
- package/src/migrations/util/load-manifest.ts +5 -6
- package/src/migrations/util/versions.ts +10 -15
- package/src/migrations.ts +13 -18
- package/src/protocols/arweave/scaffold/manifest.ts +2 -2
- package/src/protocols/arweave/scaffold/mapping.ts +1 -1
- package/src/protocols/arweave/subgraph.ts +10 -10
- package/src/protocols/contract.ts +3 -3
- package/src/protocols/cosmos/scaffold/manifest.ts +2 -2
- package/src/protocols/cosmos/scaffold/mapping.ts +1 -1
- package/src/protocols/cosmos/subgraph.ts +10 -10
- package/src/protocols/ethereum/abi.ts +53 -58
- package/src/protocols/ethereum/codegen/abi.test.ts +90 -102
- package/src/protocols/ethereum/codegen/abi.ts +181 -237
- package/src/protocols/ethereum/codegen/template.ts +8 -8
- package/src/protocols/ethereum/contract.ts +7 -8
- package/src/protocols/ethereum/scaffold/manifest.ts +6 -12
- package/src/protocols/ethereum/scaffold/mapping.ts +6 -6
- package/src/protocols/ethereum/subgraph.ts +49 -59
- package/src/protocols/ethereum/type-generator.ts +59 -73
- package/src/protocols/index.ts +88 -93
- package/src/protocols/ipfs/codegen/file_template.ts +10 -8
- package/src/protocols/near/contract.ts +12 -15
- package/src/protocols/near/scaffold/manifest.ts +3 -3
- package/src/protocols/near/scaffold/mapping.ts +1 -1
- package/src/protocols/near/subgraph.ts +10 -10
- package/src/protocols/subgraph.ts +6 -6
- package/src/protocols/substreams/scaffold/manifest.ts +2 -2
- package/src/protocols/substreams/subgraph.ts +10 -10
- package/src/scaffold/cosmos.test.ts +12 -12
- package/src/scaffold/ethereum.test.ts +120 -129
- package/src/scaffold/index.ts +52 -57
- package/src/scaffold/mapping.ts +7 -15
- package/src/scaffold/near.test.ts +12 -12
- package/src/scaffold/schema.ts +23 -26
- package/src/scaffold/tests.ts +59 -63
- package/src/schema.ts +11 -11
- package/src/subgraph.ts +93 -100
- package/src/type-generator.ts +119 -137
- package/src/validation/contract.ts +24 -28
- package/src/validation/index.ts +4 -4
- package/src/validation/manifest.ts +59 -72
- package/src/validation/schema.test.ts +22 -22
- package/src/validation/schema.ts +210 -265
- package/src/watcher.ts +45 -45
- package/tests/cli/globalSetup.ts +6 -4
- package/tests/cli/globalTeardown.ts +6 -4
- package/tests/cli/init.test.ts +20 -20
- package/tests/cli/spawn-command.d.ts +5 -4
- package/tests/cli/util.ts +49 -45
- 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-
|
|
3
|
+
## 0.37.3-alpha-20230113140856-3e7bd95
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- [#1020](https://github.com/graphprotocol/graph-cli/pull/1020)
|
|
8
|
-
|
|
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)
|
|
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)
|
|
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
package/dist/codegen/schema.js
CHANGED
|
@@ -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
|
-
|
|
110
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
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
|
-
|
|
181
|
+
const setNonNullable = `
|
|
183
182
|
this.set('${name}', ${typesCodegen.valueFromAsc(`value`, fieldValueType)})
|
|
184
183
|
`;
|
|
185
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
214
|
+
if (gqlType.get('kind') === 'ListType') {
|
|
218
215
|
return '[' + this._valueTypeFromGraphQl(gqlType.get('type')) + ']';
|
|
219
216
|
}
|
|
220
|
-
|
|
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
|
-
|
|
225
|
+
if (gqlType.get('kind') === 'ListType') {
|
|
231
226
|
return this._baseType(gqlType.get('type'));
|
|
232
227
|
}
|
|
233
|
-
|
|
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
|
-
|
|
242
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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) {
|
package/dist/codegen/template.js
CHANGED
|
@@ -35,7 +35,7 @@ class DataSourceTemplateCodeGenerator {
|
|
|
35
35
|
constructor(template, protocol) {
|
|
36
36
|
this.template = template;
|
|
37
37
|
this.template = template;
|
|
38
|
-
|
|
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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
31
|
+
const conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
|
|
32
|
+
const conversion = conversions.find(conversion => typeof conversion.get(0) === 'string'
|
|
33
33
|
? conversion.get(0) === fromType
|
|
34
|
-
:
|
|
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
|
-
|
|
43
|
-
|
|
42
|
+
const conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
|
|
43
|
+
const conversion = conversions.find(conversion => typeof conversion.get(1) === 'string'
|
|
44
44
|
? conversion.get(1) === toType
|
|
45
|
-
:
|
|
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.
|
|
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
|
-
|
|
122
|
+
const primitives = [
|
|
123
123
|
'boolean',
|
|
124
124
|
'u8',
|
|
125
125
|
'i8',
|
package/dist/codegen/util.js
CHANGED
|
@@ -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
|
-
|
|
5
|
+
const collisionCounter = new Map();
|
|
6
6
|
return values.map((value, index) => {
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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,11 +27,11 @@ 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 toolbox = __importStar(require("gluegun"));
|
|
31
|
-
const node_1 = require("./node");
|
|
32
30
|
const fs_1 = __importDefault(require("fs"));
|
|
33
|
-
const path_1 = __importDefault(require("path"));
|
|
34
31
|
const os_1 = __importDefault(require("os"));
|
|
32
|
+
const path_1 = __importDefault(require("path"));
|
|
33
|
+
const toolbox = __importStar(require("gluegun"));
|
|
34
|
+
const node_1 = require("./node");
|
|
35
35
|
const homedir = os_1.default.homedir();
|
|
36
36
|
const CONFIG_PATH = path_1.default.join(homedir, '/.graph-cli.json');
|
|
37
37
|
const getConfig = () => {
|
|
@@ -51,16 +51,14 @@ const identifyDeployKey = async (node, deployKey) => {
|
|
|
51
51
|
if (deployKey !== undefined) {
|
|
52
52
|
return deployKey;
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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;
|
|
@@ -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
|
|
31
|
-
const ipfs_http_client_1 = __importDefault(require("ipfs-http-client"));
|
|
30
|
+
const url_1 = require("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 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
|
|
50
|
-
host: url
|
|
51
|
-
port: url
|
|
52
|
-
'api-path': url
|
|
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
|
|
60
|
-
outputFormat
|
|
59
|
+
outputDir,
|
|
60
|
+
outputFormat,
|
|
61
61
|
skipMigrations,
|
|
62
62
|
blockIpfsMethods,
|
|
63
63
|
protocol,
|
|
@@ -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
|
-
|
|
30
|
+
const unexpectedStringOptions = Object.keys(booleanOptions)
|
|
31
31
|
.filter(key => typeof booleanOptions[key] === 'string')
|
|
32
32
|
.map(key => ({ key, value: booleanOptions[key] }));
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20
|
+
if (url.protocol === 'http:') {
|
|
21
21
|
return jayson_1.default.Client.http(params);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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;
|