@graphprotocol/graph-cli 0.37.3-alpha-20230111115045-e3bcf23 → 0.37.3-alpha-20230111125757-b437012

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.37.3-alpha-20230111115045-e3bcf23
3
+ ## 0.37.3-alpha-20230111125757-b437012
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -9,7 +9,7 @@ const conversions_1 = __importDefault(require("./conversions"));
9
9
  // Conversion utilities
10
10
  const conversionsForTypeSystems = (fromTypeSystem, toTypeSystem) => {
11
11
  let conversions = conversions_1.default.getIn([fromTypeSystem, toTypeSystem]);
12
- if (conversions === undefined) {
12
+ if (conversions == undefined) {
13
13
  throw new Error(`Conversions from '${fromTypeSystem}' to '${toTypeSystem}' are not supported`);
14
14
  }
15
15
  return conversions;
@@ -31,7 +31,7 @@ const findConversionFromType = (fromTypeSystem, toTypeSystem, fromType) => {
31
31
  let conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
32
32
  let conversion = conversions.find(conversion => typeof conversion.get(0) === 'string'
33
33
  ? conversion.get(0) === fromType
34
- : fromType.match(conversion.get(0)));
34
+ : Boolean(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`);
@@ -42,7 +42,7 @@ const findConversionToType = (fromTypeSystem, toTypeSystem, toType) => {
42
42
  let conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem);
43
43
  let conversion = conversions.find(conversion => typeof conversion.get(1) === 'string'
44
44
  ? conversion.get(1) === toType
45
- : toType.match(conversion.get(1)));
45
+ : Boolean(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,20 +50,26 @@ 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(['to', 'type']);
53
+ const ascTypeForProtocol = (protocol, protocolType) => findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn([
54
+ 'to',
55
+ 'type',
56
+ ]);
54
57
  exports.ascTypeForProtocol = ascTypeForProtocol;
55
58
  // TODO: this can be removed/replaced by the function above
56
- const ascTypeForEthereum = ethereumType => ascTypeForProtocol('ethereum', ethereumType);
59
+ const ascTypeForEthereum = (ethereumType) => (0, exports.ascTypeForProtocol)('ethereum', ethereumType);
57
60
  exports.ascTypeForEthereum = ascTypeForEthereum;
58
- const ethereumTypeForAsc = ascType => findConversionFromType('AssemblyScript', 'ethereum', ascType).getIn(['to', 'type']);
61
+ const ethereumTypeForAsc = (ascType) => findConversionFromType('AssemblyScript', 'ethereum', ascType).getIn([
62
+ 'to',
63
+ 'type',
64
+ ]);
59
65
  exports.ethereumTypeForAsc = ethereumTypeForAsc;
60
66
  const ethereumToAsc = (code, ethereumType, internalType) => findConversionFromType('ethereum', 'AssemblyScript', ethereumType).get('convert')(code, internalType);
61
67
  exports.ethereumToAsc = ethereumToAsc;
62
68
  const ethereumFromAsc = (code, ethereumType) => findConversionToType('AssemblyScript', 'ethereum', ethereumType).get('convert')(code);
63
69
  exports.ethereumFromAsc = ethereumFromAsc;
64
- const ascTypeForValue = valueType => findConversionFromType('Value', 'AssemblyScript', valueType).getIn(['to', 'type']);
70
+ const ascTypeForValue = (valueType) => findConversionFromType('Value', 'AssemblyScript', valueType).getIn(['to', 'type']);
65
71
  exports.ascTypeForValue = ascTypeForValue;
66
- const valueTypeForAsc = ascType => findConversionFromType('AssemblyScript', 'Value', ascType).getIn(['to', 'type']);
72
+ const valueTypeForAsc = (ascType) => findConversionFromType('AssemblyScript', 'Value', ascType).getIn(['to', 'type']);
67
73
  exports.valueTypeForAsc = valueTypeForAsc;
68
74
  const valueToAsc = (code, valueType) => findConversionFromType('Value', 'AssemblyScript', valueType).get('convert')(code);
69
75
  exports.valueToAsc = valueToAsc;
@@ -17,11 +17,11 @@ const VARIABLES_VALUES = {
17
17
  };
18
18
  const generateTestsFiles = (contract, events, indexEvents) => {
19
19
  const eventsTypes = events
20
- .flatMap(event => event.inputs.map(input => {
20
+ .flatMap(event => event.inputs.map((input) => {
21
21
  // If the asc type is Array<T> we need to check if T is a native type or a custom graph-ts type
22
22
  // If we don't do that we may miss a type that should be imported from graph-ts
23
23
  const ascType = (0, types_1.ascTypeForEthereum)(input.type);
24
- const inner = fetchArrayInnerType(ascType);
24
+ const inner = fetchArrayInnerType(String(ascType));
25
25
  return inner ? inner[1] : ascType;
26
26
  }))
27
27
  .filter(type => !type.startsWith('ethereum.') && !isNativeType(type));
@@ -39,16 +39,16 @@ exports.generateTestsFiles = generateTestsFiles;
39
39
  let displayName = "Example string value"
40
40
  let imageUrl = "Example string value"
41
41
  */
42
- const generateArguments = eventInputs => {
42
+ const generateArguments = (eventInputs) => {
43
43
  return eventInputs
44
44
  .map((input, index) => {
45
45
  let ascType = (0, types_1.ascTypeForEthereum)(input.type);
46
- return `let ${input.name || `param${index}`} = ${assignValue(ascType, input.name)}`;
46
+ return `let ${input.name || `param${index}`} = ${assignValue(ascType)}`;
47
47
  })
48
48
  .join('\n');
49
49
  };
50
50
  // Generates the value that will be assigned to a variable in generateArguments()
51
- const assignValue = type => {
51
+ const assignValue = (type) => {
52
52
  switch (type) {
53
53
  case 'string':
54
54
  return `"${VARIABLES_VALUES[type]}"`;
@@ -85,7 +85,7 @@ const generateFieldsAssertions = (entity, eventInputs, indexEvents) => eventInpu
85
85
  )`)
86
86
  .join('\n');
87
87
  // Returns the expected value for a given type in generateFieldsAssertions()
88
- const expectedValue = type => {
88
+ const expectedValue = (type) => {
89
89
  switch (type) {
90
90
  case fetchArrayInnerType(type)?.input:
91
91
  const innerType = fetchArrayInnerType(type)[1];
@@ -96,11 +96,11 @@ const expectedValue = type => {
96
96
  }
97
97
  };
98
98
  // Checks if the type is a native AS type or should be imported from graph-ts
99
- const isNativeType = type => {
99
+ const isNativeType = (type) => {
100
100
  let natives = [/i32/, /string/, /boolean/];
101
101
  return natives.some(rx => rx.test(type));
102
102
  };
103
- const fetchArrayInnerType = type => type.match(/Array<(.*?)>/);
103
+ const fetchArrayInnerType = (type) => type.match(/Array<(.*?)>/);
104
104
  // Generates the example test.ts file
105
105
  const generateExampleTest = (contract, event, indexEvents, importTypes) => {
106
106
  const entity = indexEvents ? `${event._alias}` : 'ExampleEntity';
@@ -156,11 +156,12 @@ const generateTestHelper = (contract, events, importTypes) => {
156
156
 
157
157
  ${generateMockedEvents(events).join('\n')}`;
158
158
  };
159
- const generateMockedEvents = events => events.reduce((acc, event) => acc.concat(generateMockedEvent(event)), []);
160
- const generateMockedEvent = event => {
159
+ const generateMockedEvents = (events) => events.reduce((acc, event) => acc.concat(generateMockedEvent(event)), []);
160
+ const generateMockedEvent = (event) => {
161
161
  const varName = `${gluegun_1.strings.camelCase(event._alias)}Event`;
162
162
  const fnArgs = event.inputs.map((input, index) => `${input.name || `param${index}`}: ${(0, types_1.ascTypeForEthereum)(input.type)}`);
163
- const ascToEth = event.inputs.map((input, index) => `${varName}.parameters.push(new ethereum.EventParam("${input.name || `param${index}`}", ${(0, types_1.ethereumFromAsc)(input.name || `param${index}`, input.type)}))`);
163
+ const ascToEth = event.inputs.map((input, index) => `${varName}.parameters.push(new ethereum.EventParam("${input.name ||
164
+ `param${index}`}", ${(0, types_1.ethereumFromAsc)(input.name || `param${index}`, input.type)}))`);
164
165
  return `
165
166
  export function create${event._alias}Event(${fnArgs.join(', ')}): ${event._alias} {
166
167
  let ${varName} = changetype<${event._alias}>(newMockEvent());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.37.3-alpha-20230111115045-e3bcf23",
3
+ "version": "0.37.3-alpha-20230111125757-b437012",
4
4
  "license": "(Apache-2.0 OR MIT)",
5
5
  "description": "CLI for building for and deploying to The Graph",
6
6
  "main": "dist/cli.js",
@@ -4,17 +4,21 @@ import TYPE_CONVERSIONS from './conversions'
4
4
 
5
5
  // Conversion utilities
6
6
 
7
- const conversionsForTypeSystems = (fromTypeSystem, toTypeSystem) => {
7
+ const conversionsForTypeSystems = (fromTypeSystem: string, toTypeSystem: string) => {
8
8
  let conversions = TYPE_CONVERSIONS.getIn([fromTypeSystem, toTypeSystem])
9
- if (conversions === undefined) {
9
+ if (conversions == undefined) {
10
10
  throw new Error(
11
11
  `Conversions from '${fromTypeSystem}' to '${toTypeSystem}' are not supported`,
12
12
  )
13
13
  }
14
- return conversions
14
+ return conversions as immutable.Collection<any, any>
15
15
  }
16
16
 
17
- const objectifyConversion = (fromTypeSystem, toTypeSystem, conversion) => {
17
+ const objectifyConversion = (
18
+ fromTypeSystem: string,
19
+ toTypeSystem: string,
20
+ conversion: immutable.Collection<any, any>,
21
+ ) => {
18
22
  return immutable.fromJS({
19
23
  from: {
20
24
  typeSystem: fromTypeSystem,
@@ -28,13 +32,17 @@ const objectifyConversion = (fromTypeSystem, toTypeSystem, conversion) => {
28
32
  })
29
33
  }
30
34
 
31
- const findConversionFromType = (fromTypeSystem, toTypeSystem, fromType) => {
35
+ const findConversionFromType = (
36
+ fromTypeSystem: string,
37
+ toTypeSystem: string,
38
+ fromType: string,
39
+ ): immutable.Collection<any, any> => {
32
40
  let conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem)
33
41
 
34
42
  let conversion = conversions.find(conversion =>
35
43
  typeof conversion.get(0) === 'string'
36
44
  ? conversion.get(0) === fromType
37
- : fromType.match(conversion.get(0)),
45
+ : Boolean(fromType.match(conversion.get(0))),
38
46
  )
39
47
 
40
48
  if (conversion === undefined) {
@@ -47,13 +55,17 @@ const findConversionFromType = (fromTypeSystem, toTypeSystem, fromType) => {
47
55
  return objectifyConversion(fromTypeSystem, toTypeSystem, conversion)
48
56
  }
49
57
 
50
- const findConversionToType = (fromTypeSystem, toTypeSystem, toType) => {
58
+ const findConversionToType = (
59
+ fromTypeSystem: string,
60
+ toTypeSystem: string,
61
+ toType: string,
62
+ ): immutable.Collection<any, any> => {
51
63
  let conversions = conversionsForTypeSystems(fromTypeSystem, toTypeSystem)
52
64
 
53
65
  let conversion = conversions.find(conversion =>
54
66
  typeof conversion.get(1) === 'string'
55
67
  ? conversion.get(1) === toType
56
- : toType.match(conversion.get(1)),
68
+ : Boolean(toType.match(conversion.get(1))),
57
69
  )
58
70
 
59
71
  if (conversion === undefined) {
@@ -68,47 +80,43 @@ const findConversionToType = (fromTypeSystem, toTypeSystem, toType) => {
68
80
 
69
81
  // High-level type system API
70
82
 
71
- const ascTypeForProtocol = (protocol, protocolType) =>
72
- findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn(['to', 'type'])
83
+ export const ascTypeForProtocol = (protocol: any, protocolType: string) =>
84
+ findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn([
85
+ 'to',
86
+ 'type',
87
+ ]) as string
73
88
 
74
89
  // TODO: this can be removed/replaced by the function above
75
- const ascTypeForEthereum = ethereumType => ascTypeForProtocol('ethereum', ethereumType)
76
-
77
- const ethereumTypeForAsc = ascType =>
78
- findConversionFromType('AssemblyScript', 'ethereum', ascType).getIn(['to', 'type'])
79
-
80
- const ethereumToAsc = (code, ethereumType, internalType) =>
90
+ export const ascTypeForEthereum = (ethereumType: string) =>
91
+ ascTypeForProtocol('ethereum', ethereumType)
92
+
93
+ export const ethereumTypeForAsc = (ascType: string) =>
94
+ findConversionFromType('AssemblyScript', 'ethereum', ascType).getIn([
95
+ 'to',
96
+ 'type',
97
+ ]) as string
98
+
99
+ export const ethereumToAsc = (
100
+ code: string,
101
+ ethereumType: string,
102
+ internalType?: string,
103
+ ) =>
81
104
  findConversionFromType('ethereum', 'AssemblyScript', ethereumType).get('convert')(
82
105
  code,
83
106
  internalType,
84
107
  )
85
108
 
86
- const ethereumFromAsc = (code, ethereumType) =>
109
+ export const ethereumFromAsc = (code: string, ethereumType: string) =>
87
110
  findConversionToType('AssemblyScript', 'ethereum', ethereumType).get('convert')(code)
88
111
 
89
- const ascTypeForValue = valueType =>
112
+ export const ascTypeForValue = (valueType: string) =>
90
113
  findConversionFromType('Value', 'AssemblyScript', valueType).getIn(['to', 'type'])
91
114
 
92
- const valueTypeForAsc = ascType =>
115
+ export const valueTypeForAsc = (ascType: string) =>
93
116
  findConversionFromType('AssemblyScript', 'Value', ascType).getIn(['to', 'type'])
94
117
 
95
- const valueToAsc = (code, valueType) =>
118
+ export const valueToAsc = (code: string, valueType: string) =>
96
119
  findConversionFromType('Value', 'AssemblyScript', valueType).get('convert')(code)
97
120
 
98
- const valueFromAsc = (code, valueType) =>
121
+ export const valueFromAsc = (code: string, valueType: string) =>
99
122
  findConversionToType('AssemblyScript', 'Value', valueType).get('convert')(code)
100
-
101
- export {
102
- // protocol <-> AssemblyScript
103
- ascTypeForProtocol,
104
- // ethereum <-> AssemblyScript
105
- ascTypeForEthereum,
106
- ethereumTypeForAsc,
107
- ethereumToAsc,
108
- ethereumFromAsc,
109
- // Value <-> AssemblyScript
110
- ascTypeForValue,
111
- valueTypeForAsc,
112
- valueToAsc,
113
- valueFromAsc,
114
- }
@@ -11,14 +11,14 @@ const VARIABLES_VALUES = {
11
11
  bool: true,
12
12
  }
13
13
 
14
- const generateTestsFiles = (contract, events, indexEvents) => {
14
+ export const generateTestsFiles = (contract: any, events: any[], indexEvents: number) => {
15
15
  const eventsTypes = events
16
16
  .flatMap(event =>
17
- event.inputs.map(input => {
17
+ event.inputs.map((input: any) => {
18
18
  // If the asc type is Array<T> we need to check if T is a native type or a custom graph-ts type
19
19
  // If we don't do that we may miss a type that should be imported from graph-ts
20
20
  const ascType = ascTypeForEthereum(input.type)
21
- const inner = fetchArrayInnerType(ascType)
21
+ const inner = fetchArrayInnerType(String(ascType))
22
22
  return inner ? inner[1] : ascType
23
23
  }),
24
24
  )
@@ -44,17 +44,17 @@ const generateTestsFiles = (contract, events, indexEvents) => {
44
44
  let displayName = "Example string value"
45
45
  let imageUrl = "Example string value"
46
46
  */
47
- const generateArguments = eventInputs => {
47
+ const generateArguments = (eventInputs: any[]) => {
48
48
  return eventInputs
49
49
  .map((input, index) => {
50
50
  let ascType = ascTypeForEthereum(input.type)
51
- return `let ${input.name || `param${index}`} = ${assignValue(ascType, input.name)}`
51
+ return `let ${input.name || `param${index}`} = ${assignValue(ascType)}`
52
52
  })
53
53
  .join('\n')
54
54
  }
55
55
 
56
56
  // Generates the value that will be assigned to a variable in generateArguments()
57
- const assignValue = type => {
57
+ const assignValue = (type: string): string | number | boolean => {
58
58
  switch (type) {
59
59
  case 'string':
60
60
  return `"${VARIABLES_VALUES[type]}"`
@@ -65,10 +65,10 @@ const assignValue = type => {
65
65
  case 'Bytes':
66
66
  return `Bytes.fromI32(${VARIABLES_VALUES[type]})`
67
67
  case fetchArrayInnerType(type)?.input:
68
- const innerType = fetchArrayInnerType(type)[1]
68
+ const innerType = fetchArrayInnerType(type)![1]
69
69
  return `[${assignValue(innerType)}]`
70
70
  default:
71
- let value = VARIABLES_VALUES[type]
71
+ let value = VARIABLES_VALUES[type as keyof typeof VARIABLES_VALUES]
72
72
  return value ? value : `"${type} Not implemented"`
73
73
  }
74
74
  }
@@ -82,7 +82,11 @@ const assignValue = type => {
82
82
  "0x0000000000000000000000000000000000000001"
83
83
  )
84
84
  */
85
- const generateFieldsAssertions = (entity, eventInputs, indexEvents) =>
85
+ const generateFieldsAssertions = (
86
+ entity: string,
87
+ eventInputs: any[],
88
+ indexEvents: number,
89
+ ) =>
86
90
  eventInputs
87
91
  .filter(input => input.name != 'id')
88
92
  .map(
@@ -97,28 +101,33 @@ const generateFieldsAssertions = (entity, eventInputs, indexEvents) =>
97
101
  .join('\n')
98
102
 
99
103
  // Returns the expected value for a given type in generateFieldsAssertions()
100
- const expectedValue = type => {
104
+ const expectedValue = (type: string): string | number | boolean => {
101
105
  switch (type) {
102
106
  case fetchArrayInnerType(type)?.input:
103
- const innerType = fetchArrayInnerType(type)[1]
107
+ const innerType = fetchArrayInnerType(type)![1]
104
108
  return `[${expectedValue(innerType)}]`
105
109
  default:
106
- let value = VARIABLES_VALUES[type]
110
+ let value = VARIABLES_VALUES[type as keyof typeof VARIABLES_VALUES]
107
111
  return value ? value : `${type} Not implemented`
108
112
  }
109
113
  }
110
114
 
111
115
  // Checks if the type is a native AS type or should be imported from graph-ts
112
- const isNativeType = type => {
116
+ const isNativeType = (type: string) => {
113
117
  let natives = [/i32/, /string/, /boolean/]
114
118
 
115
119
  return natives.some(rx => rx.test(type))
116
120
  }
117
121
 
118
- const fetchArrayInnerType = type => type.match(/Array<(.*?)>/)
122
+ const fetchArrayInnerType = (type: string) => type.match(/Array<(.*?)>/)
119
123
 
120
124
  // Generates the example test.ts file
121
- const generateExampleTest = (contract, event, indexEvents, importTypes) => {
125
+ const generateExampleTest = (
126
+ contract: string,
127
+ event: any,
128
+ indexEvents: number,
129
+ importTypes: string,
130
+ ) => {
122
131
  const entity = indexEvents ? `${event._alias}` : 'ExampleEntity'
123
132
  const eventInputs = event.inputs
124
133
  const eventName = event._alias
@@ -141,7 +150,7 @@ const generateExampleTest = (contract, event, indexEvents, importTypes) => {
141
150
  beforeAll(() => {
142
151
  ${generateArguments(eventInputs)}
143
152
  let new${eventName}Event = create${eventName}Event(${eventInputs
144
- .map((input, index) => input.name || `param${index}`)
153
+ .map((input: any, index: number) => input.name || `param${index}`)
145
154
  .join(', ')});
146
155
  handle${eventName}(new${eventName}Event)
147
156
  })
@@ -167,7 +176,7 @@ const generateExampleTest = (contract, event, indexEvents, importTypes) => {
167
176
  }
168
177
 
169
178
  // Generates the utils helper file
170
- const generateTestHelper = (contract, events, importTypes) => {
179
+ const generateTestHelper = (contract: string, events: any[], importTypes: string) => {
171
180
  const eventsNames = events.map(event => event._alias)
172
181
 
173
182
  return `
@@ -178,20 +187,22 @@ const generateTestHelper = (contract, events, importTypes) => {
178
187
  ${generateMockedEvents(events).join('\n')}`
179
188
  }
180
189
 
181
- const generateMockedEvents = events =>
190
+ const generateMockedEvents = (events: any[]) =>
182
191
  events.reduce((acc, event) => acc.concat(generateMockedEvent(event)), [])
183
192
 
184
- const generateMockedEvent = event => {
193
+ const generateMockedEvent = (event: any) => {
185
194
  const varName = `${strings.camelCase(event._alias)}Event`
186
195
  const fnArgs = event.inputs.map(
187
- (input, index) =>
196
+ (input: any, index: number) =>
188
197
  `${input.name || `param${index}`}: ${ascTypeForEthereum(input.type)}`,
189
198
  )
190
199
  const ascToEth = event.inputs.map(
191
- (input, index) =>
192
- `${varName}.parameters.push(new ethereum.EventParam("${
193
- input.name || `param${index}`
194
- }", ${ethereumFromAsc(input.name || `param${index}`, input.type)}))`,
200
+ (input: any, index: number) =>
201
+ `${varName}.parameters.push(new ethereum.EventParam("${input.name ||
202
+ `param${index}`}", ${ethereumFromAsc(
203
+ input.name || `param${index}`,
204
+ input.type,
205
+ )}))`,
195
206
  )
196
207
 
197
208
  return `
@@ -206,5 +217,3 @@ const generateMockedEvent = event => {
206
217
  }
207
218
  `
208
219
  }
209
-
210
- export { generateTestsFiles }