@graphprotocol/graph-cli 0.24.1 → 0.25.3
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/examples/basic-event-handlers/node_modules/chalk/node_modules/supports-color/index.js +50 -0
- package/examples/basic-event-handlers/node_modules/chalk/node_modules/supports-color/license +21 -0
- package/examples/basic-event-handlers/node_modules/chalk/node_modules/supports-color/package.json +49 -0
- package/examples/basic-event-handlers/node_modules/chalk/node_modules/supports-color/readme.md +36 -0
- package/examples/basic-event-handlers/node_modules/cliui/node_modules/ansi-regex/index.js +10 -0
- package/examples/basic-event-handlers/node_modules/cliui/node_modules/ansi-regex/license +9 -0
- package/examples/basic-event-handlers/node_modules/cliui/node_modules/ansi-regex/package.json +53 -0
- package/examples/basic-event-handlers/node_modules/cliui/node_modules/ansi-regex/readme.md +46 -0
- package/examples/basic-event-handlers/node_modules/cliui/node_modules/strip-ansi/index.js +4 -0
- package/examples/basic-event-handlers/node_modules/cliui/node_modules/strip-ansi/license +9 -0
- package/examples/basic-event-handlers/node_modules/cliui/node_modules/strip-ansi/package.json +52 -0
- package/examples/basic-event-handlers/node_modules/cliui/node_modules/strip-ansi/readme.md +39 -0
- package/examples/basic-event-handlers/node_modules/keccak/build/Makefile +342 -0
- package/examples/basic-event-handlers/node_modules/keccak/build/Release/.deps/Release/obj.target/keccak/src/addon.o.d.raw +27 -0
- package/examples/basic-event-handlers/node_modules/keccak/build/binding.Makefile +6 -0
- package/examples/basic-event-handlers/node_modules/keccak/build/config.gypi +207 -0
- package/examples/basic-event-handlers/node_modules/keccak/build/gyp-mac-tool +615 -0
- package/examples/basic-event-handlers/node_modules/keccak/build/keccak.target.mk +209 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/.coveralls.yml +1 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/.eslintrc +14 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/.travis.yml +20 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/CHANGELOG.md +395 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/LICENSE +19 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/Makefile +58 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/README.md +368 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/karma.conf.js +70 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/node.js +1 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/package.json +43 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/src/browser.js +195 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/src/debug.js +225 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/src/index.js +10 -0
- package/examples/basic-event-handlers/node_modules/mocha/node_modules/debug/src/node.js +186 -0
- package/examples/basic-event-handlers/node_modules/rimraf/node_modules/glob/LICENSE +15 -0
- package/examples/basic-event-handlers/node_modules/rimraf/node_modules/glob/README.md +368 -0
- package/examples/basic-event-handlers/node_modules/rimraf/node_modules/glob/changelog.md +67 -0
- package/examples/basic-event-handlers/node_modules/rimraf/node_modules/glob/common.js +240 -0
- package/examples/basic-event-handlers/node_modules/rimraf/node_modules/glob/glob.js +790 -0
- package/examples/basic-event-handlers/node_modules/rimraf/node_modules/glob/package.json +43 -0
- package/examples/basic-event-handlers/node_modules/rimraf/node_modules/glob/sync.js +486 -0
- package/examples/basic-event-handlers/node_modules/string-width/node_modules/ansi-regex/index.js +10 -0
- package/examples/basic-event-handlers/node_modules/string-width/node_modules/ansi-regex/license +9 -0
- package/examples/basic-event-handlers/node_modules/string-width/node_modules/ansi-regex/package.json +53 -0
- package/examples/basic-event-handlers/node_modules/string-width/node_modules/ansi-regex/readme.md +46 -0
- package/examples/basic-event-handlers/node_modules/string-width/node_modules/strip-ansi/index.js +4 -0
- package/examples/basic-event-handlers/node_modules/string-width/node_modules/strip-ansi/license +9 -0
- package/examples/basic-event-handlers/node_modules/string-width/node_modules/strip-ansi/package.json +52 -0
- package/examples/basic-event-handlers/node_modules/string-width/node_modules/strip-ansi/readme.md +39 -0
- package/examples/basic-event-handlers/node_modules/wrap-ansi/node_modules/is-fullwidth-code-point/index.js +46 -0
- package/examples/basic-event-handlers/node_modules/wrap-ansi/node_modules/is-fullwidth-code-point/license +21 -0
- package/examples/basic-event-handlers/node_modules/wrap-ansi/node_modules/is-fullwidth-code-point/package.json +45 -0
- package/examples/basic-event-handlers/node_modules/wrap-ansi/node_modules/is-fullwidth-code-point/readme.md +39 -0
- package/examples/basic-event-handlers/node_modules/wrap-ansi/node_modules/string-width/index.js +37 -0
- package/examples/basic-event-handlers/node_modules/wrap-ansi/node_modules/string-width/license +21 -0
- package/examples/basic-event-handlers/node_modules/wrap-ansi/node_modules/string-width/package.json +56 -0
- package/examples/basic-event-handlers/node_modules/wrap-ansi/node_modules/string-width/readme.md +42 -0
- package/package.json +2 -2
- package/src/codegen/schema.js +15 -5
- package/src/codegen/schema.test.js +368 -0
- package/src/codegen/types/defaults.js +34 -0
- package/src/codegen/types/index.js +8 -1
- package/src/codegen/typescript.js +7 -11
- package/src/command-helpers/scaffold.js +66 -0
- package/src/command-helpers/version.js +1 -1
- package/src/command-helpers/version.test.js +1 -1
- package/src/commands/init.js +129 -92
- package/src/commands/test.js +210 -27
- package/src/protocols/ethereum/contract.js +22 -0
- package/src/protocols/ethereum/scaffold/manifest.js +32 -0
- package/src/protocols/ethereum/scaffold/mapping.js +76 -0
- package/src/protocols/ethereum/subgraph.js +0 -14
- package/src/protocols/index.js +94 -12
- package/src/protocols/near/contract.js +46 -0
- package/src/protocols/near/scaffold/manifest.js +16 -0
- package/src/protocols/near/scaffold/mapping.js +39 -0
- package/src/protocols/near/subgraph.js +1 -23
- package/src/{scaffold.test.js → scaffold/ethereum.test.js} +27 -19
- package/src/scaffold/index.js +149 -0
- package/src/scaffold/mapping.js +49 -0
- package/src/scaffold/near.test.js +89 -0
- package/src/scaffold/schema.js +62 -0
- package/src/subgraph.js +8 -0
- package/src/validation/contract.js +56 -0
- package/src/validation/index.js +2 -1
- package/src/validation/manifest.js +0 -29
- package/tests/cli/init/{abis → ethereum/abis}/Marketplace.json +0 -0
- package/tests/cli/init/{abis → ethereum/abis}/OverloadedElements.json +0 -0
- package/tests/cli/init/{abis → ethereum/abis}/SoloMargin.json +0 -0
- package/tests/cli/init/{from-contract-with-abi-and-structs.stderr → ethereum/from-contract-with-abi-and-structs.stderr} +1 -1
- package/tests/cli/init/{from-contract-with-abi-and-structs.stdout → ethereum/from-contract-with-abi-and-structs.stdout} +0 -0
- package/tests/cli/init/{from-contract-with-abi.stderr → ethereum/from-contract-with-abi.stderr} +1 -1
- package/tests/cli/init/{from-contract-with-abi.stdout → ethereum/from-contract-with-abi.stdout} +0 -0
- package/tests/cli/init/{from-contract-with-overloaded-elements.stderr → ethereum/from-contract-with-overloaded-elements.stderr} +1 -1
- package/tests/cli/init/{from-contract-with-overloaded-elements.stdout → ethereum/from-contract-with-overloaded-elements.stdout} +0 -0
- package/tests/cli/init/{from-contract.stderr → ethereum/from-contract.stderr} +1 -1
- package/tests/cli/init/{from-contract.stdout → ethereum/from-contract.stdout} +0 -0
- package/tests/cli/init/{from-example.stderr → ethereum/from-example.stderr} +0 -0
- package/tests/cli/init/{from-example.stdout → ethereum/from-example.stdout} +0 -0
- package/tests/cli/init/near/from-contract.stderr +12 -0
- package/tests/cli/init/near/from-contract.stdout +12 -0
- package/tests/cli/init.test.js +143 -112
- package/tests/cli/util.js +56 -41
- package/tests/cli/validation/near-is-valid/subgraph.yaml +1 -0
- package/examples/basic-event-handlers/node_modules/mocha/lib/reporters/base.js.orig +0 -498
- package/examples/basic-event-handlers/node_modules/node-fetch/lib/index.js +0 -1416
- package/src/scaffold.js +0 -364
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
const prettier = require('prettier')
|
|
2
|
+
const graphql = require('graphql/language')
|
|
3
|
+
const immutable = require('immutable')
|
|
4
|
+
const SchemaCodeGenerator = require('./schema')
|
|
5
|
+
const {
|
|
6
|
+
Class,
|
|
7
|
+
Method,
|
|
8
|
+
StaticMethod,
|
|
9
|
+
Param,
|
|
10
|
+
NamedType,
|
|
11
|
+
NullableType,
|
|
12
|
+
ArrayType,
|
|
13
|
+
} = require('./typescript')
|
|
14
|
+
|
|
15
|
+
const formatTS = code =>
|
|
16
|
+
prettier.format(
|
|
17
|
+
code,
|
|
18
|
+
{ parser: 'typescript', semi: false }
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
const createSchemaCodeGen = schema =>
|
|
22
|
+
new SchemaCodeGenerator({
|
|
23
|
+
ast: immutable.fromJS(graphql.parse(schema)),
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const testEntity = (generatedTypes, expectedEntity) => {
|
|
27
|
+
const entity = generatedTypes.find(type => type.name === expectedEntity.name)
|
|
28
|
+
|
|
29
|
+
expect(entity instanceof Class).toBe(true)
|
|
30
|
+
expect(entity.extends).toBe('Entity')
|
|
31
|
+
expect(entity.export).toBe(true)
|
|
32
|
+
|
|
33
|
+
const { members, methods } = entity
|
|
34
|
+
|
|
35
|
+
expect(members).toStrictEqual(expectedEntity.members)
|
|
36
|
+
|
|
37
|
+
for (const expectedMethod of expectedEntity.methods) {
|
|
38
|
+
const method = methods.find(method => method.name === expectedMethod.name)
|
|
39
|
+
|
|
40
|
+
expectedMethod.static
|
|
41
|
+
? expect(method instanceof StaticMethod).toBe(true)
|
|
42
|
+
: expect(method instanceof Method).toBe(true)
|
|
43
|
+
|
|
44
|
+
expect(method.params).toStrictEqual(expectedMethod.params)
|
|
45
|
+
expect(method.returnType).toStrictEqual(expectedMethod.returnType)
|
|
46
|
+
expect(formatTS(method.body)).toBe(formatTS(expectedMethod.body))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
expect(methods.length).toBe(expectedEntity.methods.length)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe('Schema code generator', () => {
|
|
53
|
+
test('Should generate nothing for non entity types', () => {
|
|
54
|
+
const codegen = createSchemaCodeGen(`
|
|
55
|
+
type Foo {
|
|
56
|
+
foobar: Int
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type Bar {
|
|
60
|
+
barfoo: Int
|
|
61
|
+
}
|
|
62
|
+
`)
|
|
63
|
+
|
|
64
|
+
expect(codegen.generateTypes().size).toBe(0)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
describe('Should generate correct classes for each entity', () => {
|
|
68
|
+
const codegen = createSchemaCodeGen(`
|
|
69
|
+
# just to be sure nothing will be generated from non-entity types alongside regular ones
|
|
70
|
+
type Foo {
|
|
71
|
+
foobar: Int
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type Account @entity {
|
|
75
|
+
id: ID!
|
|
76
|
+
|
|
77
|
+
# two non primitive types
|
|
78
|
+
description: String
|
|
79
|
+
name: String!
|
|
80
|
+
|
|
81
|
+
# two primitive types (i32)
|
|
82
|
+
age: Int
|
|
83
|
+
count: Int!
|
|
84
|
+
|
|
85
|
+
# derivedFrom
|
|
86
|
+
wallets: [Wallet!] @derivedFrom(field: "account")
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
type Wallet @entity {
|
|
90
|
+
id: ID!
|
|
91
|
+
amount: BigInt!
|
|
92
|
+
account: Account!
|
|
93
|
+
}
|
|
94
|
+
`)
|
|
95
|
+
|
|
96
|
+
const generatedTypes = codegen.generateTypes()
|
|
97
|
+
|
|
98
|
+
test('Foo is NOT an entity', () => {
|
|
99
|
+
const foo = generatedTypes.find(type => type.name === 'Foo')
|
|
100
|
+
expect(foo).toBe(undefined)
|
|
101
|
+
// Account and Wallet
|
|
102
|
+
expect(generatedTypes.size).toBe(2)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('Account is an entity with the correct methods', () => {
|
|
106
|
+
testEntity(generatedTypes, {
|
|
107
|
+
name: 'Account',
|
|
108
|
+
members: [],
|
|
109
|
+
methods: [
|
|
110
|
+
{
|
|
111
|
+
name: 'constructor',
|
|
112
|
+
params: [new Param('id', new NamedType('string'))],
|
|
113
|
+
returnType: undefined,
|
|
114
|
+
body: `
|
|
115
|
+
super()
|
|
116
|
+
this.set('id', Value.fromString(id))
|
|
117
|
+
|
|
118
|
+
this.set('name', Value.fromString(''))
|
|
119
|
+
this.set('count', Value.fromI32(0))
|
|
120
|
+
`,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'save',
|
|
124
|
+
params: [],
|
|
125
|
+
returnType: new NamedType('void'),
|
|
126
|
+
body: `
|
|
127
|
+
let id = this.get('id')
|
|
128
|
+
assert(id != null, 'Cannot save Account entity without an ID')
|
|
129
|
+
if (id) {
|
|
130
|
+
assert(
|
|
131
|
+
id.kind == ValueKind.STRING,
|
|
132
|
+
'Cannot save Account entity with non-string ID. ' +
|
|
133
|
+
'Considering using .toHex() to convert the "id" to a string.'
|
|
134
|
+
)
|
|
135
|
+
store.set('Account', id.toString(), this)
|
|
136
|
+
}
|
|
137
|
+
`,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: 'load',
|
|
141
|
+
static: true,
|
|
142
|
+
params: [new Param('id', new NamedType('string'))],
|
|
143
|
+
returnType: new NullableType(new NamedType('Account')),
|
|
144
|
+
body: `
|
|
145
|
+
return changetype<Account | null>(store.get('Account', id))
|
|
146
|
+
`,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: 'get id',
|
|
150
|
+
params: [],
|
|
151
|
+
returnType: new NamedType('string'),
|
|
152
|
+
body: `
|
|
153
|
+
let value = this.get('id')
|
|
154
|
+
return value!.toString()
|
|
155
|
+
`,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: 'set id',
|
|
159
|
+
params: [new Param('value', new NamedType('string'))],
|
|
160
|
+
returnType: undefined,
|
|
161
|
+
body: `
|
|
162
|
+
this.set('id', Value.fromString(value))
|
|
163
|
+
`,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: 'get description',
|
|
167
|
+
params: [],
|
|
168
|
+
returnType: new NullableType(new NamedType('string')),
|
|
169
|
+
body: `
|
|
170
|
+
let value = this.get('description')
|
|
171
|
+
if (!value || value.kind == ValueKind.NULL) {
|
|
172
|
+
return null
|
|
173
|
+
} else {
|
|
174
|
+
return value.toString()
|
|
175
|
+
}
|
|
176
|
+
`,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: 'set description',
|
|
180
|
+
params: [new Param('value', new NullableType(new NamedType('string')))],
|
|
181
|
+
returnType: undefined,
|
|
182
|
+
body: `
|
|
183
|
+
if (!value) {
|
|
184
|
+
this.unset('description')
|
|
185
|
+
} else {
|
|
186
|
+
this.set('description', Value.fromString(<string>value))
|
|
187
|
+
}
|
|
188
|
+
`,
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: 'get name',
|
|
192
|
+
params: [],
|
|
193
|
+
returnType: new NamedType('string'),
|
|
194
|
+
body: `
|
|
195
|
+
let value = this.get('name')
|
|
196
|
+
return value!.toString()
|
|
197
|
+
`,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: 'set name',
|
|
201
|
+
params: [new Param('value', new NamedType('string'))],
|
|
202
|
+
returnType: undefined,
|
|
203
|
+
body: `
|
|
204
|
+
this.set('name', Value.fromString(value))
|
|
205
|
+
`,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: 'get age',
|
|
209
|
+
params: [],
|
|
210
|
+
returnType: new NamedType('i32'),
|
|
211
|
+
body: `
|
|
212
|
+
let value = this.get('age')
|
|
213
|
+
return value!.toI32()
|
|
214
|
+
`,
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: 'set age',
|
|
218
|
+
params: [new Param('value', new NamedType('i32'))],
|
|
219
|
+
returnType: undefined,
|
|
220
|
+
body: `
|
|
221
|
+
this.set('age', Value.fromI32(value))
|
|
222
|
+
`,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: 'get count',
|
|
226
|
+
params: [],
|
|
227
|
+
returnType: new NamedType('i32'),
|
|
228
|
+
body: `
|
|
229
|
+
let value = this.get('count')
|
|
230
|
+
return value!.toI32()
|
|
231
|
+
`,
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
name: 'set count',
|
|
235
|
+
params: [new Param('value', new NamedType('i32'))],
|
|
236
|
+
returnType: undefined,
|
|
237
|
+
body: `
|
|
238
|
+
this.set('count', Value.fromI32(value))
|
|
239
|
+
`,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: 'get wallets',
|
|
243
|
+
params: [],
|
|
244
|
+
returnType: new NullableType(new ArrayType(new NamedType('string'))),
|
|
245
|
+
body: `
|
|
246
|
+
let value = this.get('wallets')
|
|
247
|
+
if (!value || value.kind == ValueKind.NULL) {
|
|
248
|
+
return null
|
|
249
|
+
} else {
|
|
250
|
+
return value.toStringArray()
|
|
251
|
+
}
|
|
252
|
+
`,
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
name: 'set wallets',
|
|
256
|
+
params: [new Param('value', new NullableType(new ArrayType(new NamedType('string'))))],
|
|
257
|
+
returnType: undefined,
|
|
258
|
+
body: `
|
|
259
|
+
if (!value) {
|
|
260
|
+
this.unset('wallets')
|
|
261
|
+
} else {
|
|
262
|
+
this.set('wallets', Value.fromStringArray(<Array<string>>value))
|
|
263
|
+
}
|
|
264
|
+
`,
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
test('Wallet is an entity with the correct methods', () => {
|
|
271
|
+
testEntity(generatedTypes, {
|
|
272
|
+
name: 'Wallet',
|
|
273
|
+
members: [],
|
|
274
|
+
methods: [
|
|
275
|
+
{
|
|
276
|
+
name: 'constructor',
|
|
277
|
+
params: [new Param('id', new NamedType('string'))],
|
|
278
|
+
returnType: undefined,
|
|
279
|
+
body: `
|
|
280
|
+
super()
|
|
281
|
+
this.set('id', Value.fromString(id))
|
|
282
|
+
|
|
283
|
+
this.set('amount', Value.fromBigInt(BigInt.zero()))
|
|
284
|
+
this.set('account', Value.fromString(''))
|
|
285
|
+
`,
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
name: 'save',
|
|
289
|
+
params: [],
|
|
290
|
+
returnType: new NamedType('void'),
|
|
291
|
+
body: `
|
|
292
|
+
let id = this.get('id')
|
|
293
|
+
assert(id != null, 'Cannot save Wallet entity without an ID')
|
|
294
|
+
if (id) {
|
|
295
|
+
assert(
|
|
296
|
+
id.kind == ValueKind.STRING,
|
|
297
|
+
'Cannot save Wallet entity with non-string ID. ' +
|
|
298
|
+
'Considering using .toHex() to convert the "id" to a string.'
|
|
299
|
+
)
|
|
300
|
+
store.set('Wallet', id.toString(), this)
|
|
301
|
+
}
|
|
302
|
+
`,
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: 'load',
|
|
306
|
+
static: true,
|
|
307
|
+
params: [new Param('id', new NamedType('string'))],
|
|
308
|
+
returnType: new NullableType(new NamedType('Wallet')),
|
|
309
|
+
body: `
|
|
310
|
+
return changetype<Wallet | null>(store.get('Wallet', id))
|
|
311
|
+
`,
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
name: 'get id',
|
|
315
|
+
params: [],
|
|
316
|
+
returnType: new NamedType('string'),
|
|
317
|
+
body: `
|
|
318
|
+
let value = this.get('id')
|
|
319
|
+
return value!.toString()
|
|
320
|
+
`,
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
name: 'set id',
|
|
324
|
+
params: [new Param('value', new NamedType('string'))],
|
|
325
|
+
returnType: undefined,
|
|
326
|
+
body: `
|
|
327
|
+
this.set('id', Value.fromString(value))
|
|
328
|
+
`,
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
name: 'get amount',
|
|
332
|
+
params: [],
|
|
333
|
+
returnType: new NamedType('BigInt'),
|
|
334
|
+
body: `
|
|
335
|
+
let value = this.get('amount')
|
|
336
|
+
return value!.toBigInt()
|
|
337
|
+
`,
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
name: 'set amount',
|
|
341
|
+
params: [new Param('value', new NamedType('BigInt'))],
|
|
342
|
+
returnType: undefined,
|
|
343
|
+
body: `
|
|
344
|
+
this.set('amount', Value.fromBigInt(value))
|
|
345
|
+
`,
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
name: 'get account',
|
|
349
|
+
params: [],
|
|
350
|
+
returnType: new NamedType('string'),
|
|
351
|
+
body: `
|
|
352
|
+
let value = this.get('account')
|
|
353
|
+
return value!.toString()
|
|
354
|
+
`,
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
name: 'set account',
|
|
358
|
+
params: [new Param('value', new NamedType('string'))],
|
|
359
|
+
returnType: undefined,
|
|
360
|
+
body: `
|
|
361
|
+
this.set('account', Value.fromString(value))
|
|
362
|
+
`,
|
|
363
|
+
},
|
|
364
|
+
],
|
|
365
|
+
})
|
|
366
|
+
})
|
|
367
|
+
})
|
|
368
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const immutable = require('immutable')
|
|
2
|
+
|
|
3
|
+
// TODO: kill me
|
|
4
|
+
const EMPTY_ARRAY = 'new Array(0)'
|
|
5
|
+
|
|
6
|
+
const ASC_DEFAULTS = [
|
|
7
|
+
// Scalar values
|
|
8
|
+
|
|
9
|
+
['Address', 'Address.zero()'],
|
|
10
|
+
['Bytes', 'Bytes.empty()'],
|
|
11
|
+
['boolean', 'false'],
|
|
12
|
+
['i32', '0'],
|
|
13
|
+
['string', '""'],
|
|
14
|
+
['BigInt', 'BigInt.zero()'],
|
|
15
|
+
['BigDecimal', 'BigDecimal.zero()'],
|
|
16
|
+
|
|
17
|
+
// Arrays
|
|
18
|
+
|
|
19
|
+
['Array<Address>', EMPTY_ARRAY],
|
|
20
|
+
['Array<Bytes>', EMPTY_ARRAY],
|
|
21
|
+
['Array<boolean>', EMPTY_ARRAY],
|
|
22
|
+
['Array<i32>', EMPTY_ARRAY],
|
|
23
|
+
['Array<string>', EMPTY_ARRAY],
|
|
24
|
+
['Array<BigInt>', EMPTY_ARRAY],
|
|
25
|
+
['Array<BigDecimal>', EMPTY_ARRAY],
|
|
26
|
+
['Array<string | null>', EMPTY_ARRAY],
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
module.exports = immutable.fromJS({
|
|
30
|
+
AssemblyScript: ASC_DEFAULTS,
|
|
31
|
+
})
|
|
32
|
+
// TODO: use me:
|
|
33
|
+
// [/Array<.*>/, 'new Array(0)'],
|
|
34
|
+
// [/Array\<.*\>/, 'new Array(0)'],
|
|
@@ -89,8 +89,12 @@ const findInitializationForType = (fromTypeSystem, toTypeSystem, ascType) => {
|
|
|
89
89
|
|
|
90
90
|
// High-level type system API
|
|
91
91
|
|
|
92
|
+
const ascTypeForProtocol = (protocol, protocolType) =>
|
|
93
|
+
findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn(['to', 'type'])
|
|
94
|
+
|
|
95
|
+
// TODO: this can be removed/replaced by the function above
|
|
92
96
|
const ascTypeForEthereum = ethereumType =>
|
|
93
|
-
|
|
97
|
+
ascTypeForProtocol('ethereum', ethereumType)
|
|
94
98
|
|
|
95
99
|
const ethereumTypeForAsc = ascType =>
|
|
96
100
|
findConversionFromType('AssemblyScript', 'ethereum', ascType).getIn(['to', 'type'])
|
|
@@ -120,6 +124,9 @@ const initializedValueFromAsc = ascType =>
|
|
|
120
124
|
findInitializationForType('AssemblyScript', 'Value', ascType)
|
|
121
125
|
|
|
122
126
|
module.exports = {
|
|
127
|
+
// protocol <-> AssemblyScript
|
|
128
|
+
ascTypeForProtocol,
|
|
129
|
+
|
|
123
130
|
// ethereum <-> AssemblyScript
|
|
124
131
|
ascTypeForEthereum,
|
|
125
132
|
ethereumTypeForAsc,
|
|
@@ -12,17 +12,6 @@ class Param {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
class ReturnType {
|
|
16
|
-
constructor(name, type) {
|
|
17
|
-
this.name = name
|
|
18
|
-
this.type = type
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
toString() {
|
|
22
|
-
return `${this.type.toString()}`
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
15
|
class Method {
|
|
27
16
|
constructor(name, params, returnType, body) {
|
|
28
17
|
this.name = name
|
|
@@ -185,8 +174,15 @@ const GENERATED_FILE_NOTE = `
|
|
|
185
174
|
|
|
186
175
|
module.exports = {
|
|
187
176
|
// Types
|
|
177
|
+
Param,
|
|
178
|
+
Method,
|
|
179
|
+
StaticMethod,
|
|
180
|
+
Class,
|
|
181
|
+
ClassMember,
|
|
182
|
+
NamedType,
|
|
188
183
|
NullableType,
|
|
189
184
|
ArrayType,
|
|
185
|
+
ModuleImports,
|
|
190
186
|
|
|
191
187
|
// Code generators
|
|
192
188
|
namedType,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const fs = require('fs-extra')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
const { step } = require('./spinner')
|
|
5
|
+
const Scaffold = require('../scaffold')
|
|
6
|
+
|
|
7
|
+
const generateScaffold = async (
|
|
8
|
+
{
|
|
9
|
+
protocolInstance,
|
|
10
|
+
abi,
|
|
11
|
+
contract,
|
|
12
|
+
network,
|
|
13
|
+
subgraphName,
|
|
14
|
+
indexEvents,
|
|
15
|
+
contractName = 'Contract',
|
|
16
|
+
node,
|
|
17
|
+
},
|
|
18
|
+
spinner,
|
|
19
|
+
) => {
|
|
20
|
+
step(spinner, 'Generate subgraph')
|
|
21
|
+
|
|
22
|
+
const scaffold = new Scaffold({
|
|
23
|
+
protocol: protocolInstance,
|
|
24
|
+
abi,
|
|
25
|
+
indexEvents,
|
|
26
|
+
contract,
|
|
27
|
+
network,
|
|
28
|
+
contractName,
|
|
29
|
+
subgraphName,
|
|
30
|
+
node,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return scaffold.generate()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const writeScaffoldDirectory = async (scaffold, directory, spinner) => {
|
|
37
|
+
// Create directory itself
|
|
38
|
+
await fs.mkdirs(directory)
|
|
39
|
+
|
|
40
|
+
let promises = Object.keys(scaffold).map(async basename => {
|
|
41
|
+
let content = scaffold[basename]
|
|
42
|
+
let filename = path.join(directory, basename)
|
|
43
|
+
|
|
44
|
+
// Write file or recurse into subdirectory
|
|
45
|
+
if (typeof content === 'string') {
|
|
46
|
+
await fs.writeFile(filename, content, { encoding: 'utf-8' })
|
|
47
|
+
} else if (content == null) {
|
|
48
|
+
return // continue loop
|
|
49
|
+
} else {
|
|
50
|
+
writeScaffoldDirectory(content, path.join(directory, basename), spinner)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
await Promise.all(promises)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const writeScaffold = async (scaffold, directory, spinner) => {
|
|
58
|
+
step(spinner, `Write subgraph to directory`)
|
|
59
|
+
await writeScaffoldDirectory(scaffold, directory, spinner)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = {
|
|
63
|
+
...module.exports,
|
|
64
|
+
generateScaffold,
|
|
65
|
+
writeScaffold,
|
|
66
|
+
}
|
|
@@ -57,7 +57,7 @@ const assertGraphTsVersion = async (sourceDir, minimumGraphTsVersion) => {
|
|
|
57
57
|
if (graphTsVersion && semver.lt(semver.coerce(graphTsVersion), minimumGraphTsVersion)) {
|
|
58
58
|
throw new Error(
|
|
59
59
|
`To use this version of the graph-cli you must upgrade the graph-ts dependency to a version greater than or equal to ${minimumGraphTsVersion}
|
|
60
|
-
Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://
|
|
60
|
+
Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://thegraph.com/docs/developer/assemblyscript-migration-guide`
|
|
61
61
|
)
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -197,7 +197,7 @@ describe('Version Command Helpers', () => {
|
|
|
197
197
|
.rejects
|
|
198
198
|
.toThrow(new Error(
|
|
199
199
|
`To use this version of the graph-cli you must upgrade the graph-ts dependency to a version greater than or equal to ${minimumGraphTsVersion}
|
|
200
|
-
Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://
|
|
200
|
+
Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://thegraph.com/docs/developer/assemblyscript-migration-guide`
|
|
201
201
|
))
|
|
202
202
|
})
|
|
203
203
|
test('When the installed graph-ts version is a supported one', async () => {
|