Skip to content

Commit 3d181db

Browse files
committed
feat: remove immutable
1 parent 09b4c2a commit 3d181db

33 files changed

+801
-852
lines changed

packages/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"glob": "7.1.6",
1717
"gluegun": "https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep",
1818
"graphql": "15.5.0",
19-
"immutable": "3.8.2",
2019
"ipfs-http-client": "34.0.0",
2120
"jayson": "3.6.6",
2221
"js-yaml": "3.13.1",

packages/cli/src/codegen/schema.js

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
1-
const immutable = require('immutable')
2-
31
const tsCodegen = require('./typescript')
42
const typesCodegen = require('./types')
53

6-
const List = immutable.List
74

85
class IdField {
9-
static BYTES = Symbol("Bytes")
10-
static STRING = Symbol("String")
6+
static BYTES = Symbol('Bytes')
7+
static STRING = Symbol('String')
118

129
constructor(idField) {
1310
const typeName = idField.getIn(['type', 'type', 'name', 'value'])
14-
this.kind = typeName === "Bytes" ? IdField.BYTES : IdField.STRING
11+
this.kind = typeName === 'Bytes' ? IdField.BYTES : IdField.STRING
1512
}
1613

1714
typeName() {
18-
return this.kind === IdField.BYTES ? "Bytes" : "string"
15+
return this.kind === IdField.BYTES ? 'Bytes' : 'string'
1916
}
2017

2118
gqlTypeName() {
22-
return this.kind === IdField.BYTES ? "Bytes" : "String"
19+
return this.kind === IdField.BYTES ? 'Bytes' : 'String'
2320
}
2421

2522
tsNamedType() {
2623
return tsCodegen.namedType(this.typeName())
2724
}
2825

2926
tsValueFrom() {
30-
return this.kind === IdField.BYTES ? "Value.fromBytes(id)" : "Value.fromString(id)"
27+
return this.kind === IdField.BYTES ? 'Value.fromBytes(id)' : 'Value.fromString(id)'
3128
}
3229

3330
tsValueKind() {
34-
return this.kind === IdField.BYTES ? "ValueKind.BYTES" : "ValueKind.STRING"
31+
return this.kind === IdField.BYTES ? 'ValueKind.BYTES' : 'ValueKind.STRING'
3532
}
3633

3734
tsValueToString() {
38-
return this.kind == IdField.BYTES ? "id.toBytes().toHexString()" : "id.toString()"
35+
return this.kind == IdField.BYTES ? 'id.toBytes().toHexString()' : 'id.toString()'
3936
}
4037

4138
tsToString() {
42-
return this.kind == IdField.BYTES ? "id.toHexString()" : "id"
39+
return this.kind == IdField.BYTES ? 'id.toHexString()' : 'id'
4340
}
4441

4542
static fromFields(fields) {
@@ -48,7 +45,7 @@ class IdField {
4845
}
4946

5047
static fromTypeDef(def) {
51-
return IdField.fromFields(def.get("fields"))
48+
return IdField.fromFields(def.get('fields'))
5249
}
5350
}
5451

@@ -117,7 +114,7 @@ module.exports = class SchemaCodeGenerator {
117114
.get('fields')
118115
.reduce(
119116
(methods, field) => methods.concat(this._generateEntityFieldMethods(def, field)),
120-
List(),
117+
[],
121118
)
122119
.forEach(method => klass.addMethod(method))
123120

@@ -138,7 +135,7 @@ module.exports = class SchemaCodeGenerator {
138135
}
139136

140137
_generateStoreMethods(entityName, idField) {
141-
return List.of(
138+
return [
142139
tsCodegen.method(
143140
'save',
144141
[],
@@ -162,14 +159,14 @@ module.exports = class SchemaCodeGenerator {
162159
return changetype<${entityName} | null>(store.get('${entityName}', ${idField.tsToString()}))
163160
`,
164161
),
165-
)
162+
]
166163
}
167164

168165
_generateEntityFieldMethods(entityDef, fieldDef) {
169-
return List([
166+
return [
170167
this._generateEntityFieldGetter(entityDef, fieldDef),
171168
this._generateEntityFieldSetter(entityDef, fieldDef),
172-
])
169+
]
173170
}
174171

175172
_generateEntityFieldGetter(entityDef, fieldDef) {
@@ -206,17 +203,13 @@ module.exports = class SchemaCodeGenerator {
206203
let paramTypeString = isNullable ? paramType.inner.toString() : paramType.toString()
207204
let isArray = paramType instanceof tsCodegen.ArrayType
208205

209-
if (
210-
isArray &&
211-
paramType.inner instanceof tsCodegen.NullableType
212-
) {
206+
if (isArray && paramType.inner instanceof tsCodegen.NullableType) {
213207
let baseType = this._baseType(gqlType)
214208

215209
throw new Error(`
216210
GraphQL schema can't have List's with Nullable members.
217211
Error in '${name}' field of type '[${baseType}]'.
218-
Suggestion: add an '!' to the member type of the List, change from '[${baseType}]' to '[${baseType}!]'`
219-
)
212+
Suggestion: add an '!' to the member type of the List, change from '[${baseType}]' to '[${baseType}!]'`)
220213
}
221214

222215
let setNonNullable = `
@@ -246,8 +239,13 @@ Suggestion: add an '!' to the member type of the List, change from '[${baseType}
246239

247240
// If this is a reference to another type, the field has the type of
248241
// the referred type's id field
249-
const typeDef = this.schema.ast.get("definitions").
250-
find(def => (this._isEntityTypeDefinition(def) || this._isInterfaceDefinition(def)) && def.getIn(["name", "value"]) === typeName)
242+
const typeDef = this.schema.ast
243+
.get('definitions')
244+
.find(
245+
def =>
246+
(this._isEntityTypeDefinition(def) || this._isInterfaceDefinition(def)) &&
247+
def.getIn(['name', 'value']) === typeName,
248+
)
251249
if (typeDef) {
252250
return IdField.fromTypeDef(typeDef).typeName()
253251
} else {

packages/cli/src/codegen/schema.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const prettier = require('prettier')
22
const graphql = require('graphql/language')
3-
const immutable = require('immutable')
43
const SchemaCodeGenerator = require('./schema')
54
const {
65
Class,
@@ -20,7 +19,7 @@ const formatTS = code =>
2019

2120
const createSchemaCodeGen = schema =>
2221
new SchemaCodeGenerator({
23-
ast: immutable.fromJS(graphql.parse(schema)),
22+
ast: graphql.parse(schema),
2423
})
2524

2625
const testEntity = (generatedTypes, expectedEntity) => {

packages/cli/src/codegen/template.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const immutable = require('immutable')
21
const IpfsFileTemplateCodeGen = require('../protocols/ipfs/codegen/file_template')
32

43
const tsCodegen = require('./typescript')
@@ -29,7 +28,7 @@ module.exports = class DataSourceTemplateCodeGenerator {
2928
}
3029

3130
generateTypes() {
32-
return immutable.List([this._generateTemplateType()])
31+
return [this._generateTemplateType()]
3332
}
3433

3534
_generateTemplateType() {

packages/cli/src/codegen/types/conversions.js

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const immutable = require('immutable')
2-
31
/**
42
* ethereum.Value -> AssemblyScript conversions
53
*/
@@ -55,29 +53,56 @@ const ETHEREUM_VALUE_TO_ASSEMBLYSCRIPT = [
5553

5654
// Multi dimensional arrays
5755

58-
[/^address\[([0-9]+)?\]\[([0-9]+)?\]$/, 'Array<Array<Address>>', code => `${code}.toAddressMatrix()`],
59-
[/^bool\[([0-9]+)?\]\[([0-9]+)?\]$/, 'Array<Array<boolean>>', code => `${code}.toBooleanMatrix()`],
60-
[/^byte\[([0-9]+)?\]\[([0-9]+)?\]$/, 'Array<Array<Bytes>>', code => `${code}.toBytesMatrix()`],
56+
[
57+
/^address\[([0-9]+)?\]\[([0-9]+)?\]$/,
58+
'Array<Array<Address>>',
59+
code => `${code}.toAddressMatrix()`,
60+
],
61+
[
62+
/^bool\[([0-9]+)?\]\[([0-9]+)?\]$/,
63+
'Array<Array<boolean>>',
64+
code => `${code}.toBooleanMatrix()`,
65+
],
66+
[
67+
/^byte\[([0-9]+)?\]\[([0-9]+)?\]$/,
68+
'Array<Array<Bytes>>',
69+
code => `${code}.toBytesMatrix()`,
70+
],
6171
[
6272
/^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]+)?\]\[([0-9]+)?\]$/,
6373
'Array<Array<Bytes>>',
6474
code => `${code}.toBytesMatrix()`,
6575
],
66-
[/^int(8|16|24|32)\[([0-9]+)?\]\[([0-9]+)?\]$/, 'Array<Array<i32>>', code => `${code}.toI32Matrix()`],
67-
[/^uint(8|16|24)\[([0-9]+)?\]\[([0-9]+)?\]$/, 'Array<Array<i32>>', code => `${code}.toI32Matrix()`],
68-
[/^uint32\[([0-9]+)?\]\[([0-9]+)?\]$/, 'Array<Array<BigInt>>', code => `${code}.toBigIntMatrix()`],
76+
[
77+
/^int(8|16|24|32)\[([0-9]+)?\]\[([0-9]+)?\]$/,
78+
'Array<Array<i32>>',
79+
code => `${code}.toI32Matrix()`,
80+
],
81+
[
82+
/^uint(8|16|24)\[([0-9]+)?\]\[([0-9]+)?\]$/,
83+
'Array<Array<i32>>',
84+
code => `${code}.toI32Matrix()`,
85+
],
86+
[
87+
/^uint32\[([0-9]+)?\]\[([0-9]+)?\]$/,
88+
'Array<Array<BigInt>>',
89+
code => `${code}.toBigIntMatrix()`,
90+
],
6991
[
7092
/^u?int(40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)\[([0-9]+)?\]\[([0-9]+)?\]$/,
7193
'Array<Array<BigInt>>',
7294
code => `${code}.toBigIntMatrix()`,
7395
],
74-
[/^string\[([0-9]+)?\]\[([0-9]+)?\]$/, 'Array<Array<string>>', code => `${code}.toStringMatrix()`],
96+
[
97+
/^string\[([0-9]+)?\]\[([0-9]+)?\]$/,
98+
'Array<Array<string>>',
99+
code => `${code}.toStringMatrix()`,
100+
],
75101
[
76102
/^tuple\[([0-9]+)?\]\[([0-9]+)?\]$/,
77103
'Array<Array<ethereum.Tuple>>',
78104
(code, type) => `${code}.toTupleMatrix<${type}>()`,
79105
],
80-
81106
]
82107

83108
/**
@@ -178,7 +203,7 @@ const ASSEMBLYSCRIPT_TO_ETHEREUM_VALUE = [
178203
/^tuple\[([0-9]+)?\]$/,
179204
code => `ethereum.Value.fromTupleArray(${code})`,
180205
],
181-
206+
182207
// Multi dimentional arrays
183208

184209
[
@@ -282,9 +307,13 @@ const ASSEMBLYSCRIPT_TO_VALUE = [
282307
['Array<Array<BigInt>>', '[[BigInt]]', code => `Value.fromBigIntMatrix(${code})`],
283308
['Array<Array<string>>', '[[String]]', code => `Value.fromStringMatrix(${code})`],
284309
['Array<Array<string>>', '[[ID]]', code => `Value.fromStringMatrix(${code})`],
285-
['Array<Array<BigDecimal>>', '[[BigDecimal]]', code => `Value.fromBigDecimalMatrix(${code})`],
310+
[
311+
'Array<Array<BigDecimal>>',
312+
'[[BigDecimal]]',
313+
code => `Value.fromBigDecimalMatrix(${code})`,
314+
],
286315
['Array<Array<string>>', /\[\[.*\]\]/, code => `Value.fromStringMatrix(${code})`],
287-
['Array<Array<string | null>>', null, code => `Value.fromStringMatrix(${code})`],// is this overwriting the Array null below?
316+
['Array<Array<string | null>>', null, code => `Value.fromStringMatrix(${code})`], // is this overwriting the Array null below?
288317

289318
// Arrays
290319

@@ -315,7 +344,7 @@ const ASSEMBLYSCRIPT_TO_VALUE = [
315344
/**
316345
* Type conversions
317346
*/
318-
module.exports = immutable.fromJS({
347+
module.exports = Object.freeze({
319348
ethereum: {
320349
AssemblyScript: ETHEREUM_VALUE_TO_ASSEMBLYSCRIPT,
321350
},

packages/cli/src/codegen/types/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const immutable = require('immutable')
2-
31
const TYPE_CONVERSIONS = require('./conversions')
42

53
// Conversion utilities
@@ -15,7 +13,7 @@ const conversionsForTypeSystems = (fromTypeSystem, toTypeSystem) => {
1513
}
1614

1715
const objectifyConversion = (fromTypeSystem, toTypeSystem, conversion) => {
18-
return immutable.fromJS({
16+
return Object.freeze({
1917
from: {
2018
typeSystem: fromTypeSystem,
2119
type: conversion.get(0),
@@ -72,8 +70,7 @@ const ascTypeForProtocol = (protocol, protocolType) =>
7270
findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn(['to', 'type'])
7371

7472
// TODO: this can be removed/replaced by the function above
75-
const ascTypeForEthereum = ethereumType =>
76-
ascTypeForProtocol('ethereum', ethereumType)
73+
const ascTypeForEthereum = ethereumType => ascTypeForProtocol('ethereum', ethereumType)
7774

7875
const ethereumTypeForAsc = ascType =>
7976
findConversionFromType('AssemblyScript', 'ethereum', ascType).getIn(['to', 'type'])

packages/cli/src/codegen/typescript.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
let immutable = require('immutable')
2-
let Map = immutable.Map
3-
41
class Param {
52
constructor(name, type) {
63
this.name = name

packages/cli/src/command-helpers/abi.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { withSpinner } = require('./spinner')
22
const fetch = require('node-fetch')
3-
const immutable = require('immutable')
43

54
const loadAbiFromEtherscan = async (ABI, network, address) =>
65
await withSpinner(
@@ -18,7 +17,7 @@ const loadAbiFromEtherscan = async (ABI, network, address) =>
1817
// a `result` field. The `status` is '0' in case of errors and '1' in
1918
// case of success
2019
if (json.status === '1') {
21-
return new ABI('Contract', undefined, immutable.fromJS(JSON.parse(json.result)))
20+
return new ABI('Contract', undefined, JSON.parse(json.result))
2221
} else {
2322
throw new Error('ABI not found, try loading it from a local file')
2423
}
@@ -42,7 +41,7 @@ const loadAbiFromBlockScout = async (ABI, network, address) =>
4241
// a `result` field. The `status` is '0' in case of errors and '1' in
4342
// case of success
4443
if (json.status === '1') {
45-
return new ABI('Contract', undefined, immutable.fromJS(JSON.parse(json.result)))
44+
return new ABI('Contract', undefined, JSON.parse(json.result))
4645
} else {
4746
throw new Error('ABI not found, try loading it from a local file')
4847
}

packages/cli/src/command-helpers/data-sources.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const immutable = require('immutable')
21
const { loadManifest } = require('../migrations/util/load-manifest')
32

43
// Loads manifest from file path and returns all:
@@ -13,15 +12,15 @@ const fromFilePath = async manifestPath => {
1312

1413
const extractDataSourceByType = (manifest, dataSourceType, protocol) =>
1514
manifest
16-
.get(dataSourceType, immutable.List())
15+
.get(dataSourceType, [])
1716
.reduce(
1817
(dataSources, dataSource, dataSourceIndex) =>
1918
protocol.isValidKindName(dataSource.get('kind'))
2019
? dataSources.push(
21-
immutable.Map({ path: [dataSourceType, dataSourceIndex], dataSource }),
20+
{ path: [dataSourceType, dataSourceIndex], dataSource },
2221
)
2322
: dataSources,
24-
immutable.List(),
23+
[]
2524
)
2625

2726
// Extracts data sources and templates from a immutable manifest data structure

0 commit comments

Comments
 (0)