diff --git a/packages/codegen/README.md b/packages/codegen/README.md index 17647a35..aeb3a61f 100644 --- a/packages/codegen/README.md +++ b/packages/codegen/README.md @@ -43,11 +43,19 @@ ## Demo -* Install required packages: +* In root of the repository: - ```bash - yarn - ``` + * Install required packages: + + ```bash + yarn + ``` + + * Build files: + + ```bash + yarn build + ``` * Generate a watcher from a contract file: diff --git a/packages/codegen/package.json b/packages/codegen/package.json index 383b0a4b..6c925ec8 100644 --- a/packages/codegen/package.json +++ b/packages/codegen/package.json @@ -24,6 +24,8 @@ "graphql": "^15.5.0", "graphql-compose": "^9.0.3", "handlebars": "^4.7.7", + "js-yaml": "^4.0.0", + "lodash": "^4.17.21", "node-fetch": "^2", "solc": "^0.8.7-fixed", "ts-node": "^10.2.1", @@ -32,6 +34,7 @@ }, "devDependencies": { "@openzeppelin/contracts": "^4.3.2", + "@types/js-yaml": "^4.0.3", "@types/node": "^16.9.0", "@typescript-eslint/eslint-plugin": "^4.25.0", "@typescript-eslint/parser": "^4.25.0", diff --git a/packages/codegen/src/data/entities/BlockProgress.yaml b/packages/codegen/src/data/entities/BlockProgress.yaml new file mode 100644 index 00000000..ba0307d8 --- /dev/null +++ b/packages/codegen/src/data/entities/BlockProgress.yaml @@ -0,0 +1,66 @@ +className: BlockProgress +implements: BlockProgressInterface +indexOn: + - columns: + - blockHash + unique: true + - columns: + - blockNumber + - columns: + - parentHash +columns: + - name: blockHash + pgType: varchar + tsType: string + columnType: Column + columnOptions: + - option: length + value: 66 + - name: parentHash + pgType: varchar + tsType: string + columnType: Column + columnOptions: + - option: length + value: 66 + - name: blockNumber + pgType: integer + tsType: number + columnType: Column + - name: blockTimestamp + pgType: integer + tsType: number + columnType: Column + - name: numEvents + pgType: integer + tsType: number + columnType: Column + - name: numProcessedEvents + pgType: integer + tsType: number + columnType: Column + - name: lastProcessedEventIndex + pgType: integer + tsType: number + columnType: Column + - name: isComplete + pgType: boolean + tsType: boolean + columnType: Column + - name: isPruned + pgType: boolean + tsType: boolean + columnType: Column + columnOptions: + - option: default + value: false +imports: + - toImport: + - Entity + - PrimaryGeneratedColumn + - Column + - Index + from: typeorm + - toImport: + - BlockProgressInterface + from: '@vulcanize/util' diff --git a/packages/codegen/src/data/entities/Contract.yaml b/packages/codegen/src/data/entities/Contract.yaml new file mode 100644 index 00000000..e7019fbf --- /dev/null +++ b/packages/codegen/src/data/entities/Contract.yaml @@ -0,0 +1,31 @@ +className: Contract +indexOn: + - columns: + - address + unique: true +columns: + - name: address + pgType: varchar + tsType: string + columnType: Column + columnOptions: + - option: length + value: 42 + - name: kind + pgType: varchar + tsType: string + columnType: Column + columnOptions: + - option: length + value: 8 + - name: startingBlock + pgType: integer + tsType: number + columnType: Column +imports: + - toImport: + - Entity + - PrimaryGeneratedColumn + - Column + - Index + from: typeorm diff --git a/packages/codegen/src/data/entities/Event.yaml b/packages/codegen/src/data/entities/Event.yaml new file mode 100644 index 00000000..bee57e7b --- /dev/null +++ b/packages/codegen/src/data/entities/Event.yaml @@ -0,0 +1,63 @@ +className: Event +indexOn: + - columns: + - block + - contract + - columns: + - block + - contract + - eventName +columns: + - name: block + tsType: BlockProgress + columnType: ManyToOne + lhs: () + rhs: BlockProgress + - name: txHash + pgType: varchar + tsType: string + columnType: Column + columnOptions: + - option: length + value: 66 + - name: index + pgType: integer + tsType: number + columnType: Column + - name: contract + pgType: varchar + tsType: string + columnType: Column + columnOptions: + - option: length + value: 42 + - name: eventName + pgType: varchar + tsType: string + columnType: Column + columnOptions: + - option: length + value: 256 + - name: eventInfo + pgType: text + tsType: string + columnType: Column + - name: extraInfo + pgType: text + tsType: string + columnType: Column + - name: proof + pgType: text + tsType: string + columnType: Column +imports: + - toImport: + - Entity + - PrimaryGeneratedColumn + - Column + - Index + - ManyToOne + from: typeorm + - toImport: + - BlockProgress + from: ./BlockProgress diff --git a/packages/codegen/src/data/entities/SyncStatus.yaml b/packages/codegen/src/data/entities/SyncStatus.yaml new file mode 100644 index 00000000..cd415c3c --- /dev/null +++ b/packages/codegen/src/data/entities/SyncStatus.yaml @@ -0,0 +1,46 @@ +className: SyncStatus +implements: SyncStatusInterface +indexOn: [] +columns: + - name: chainHeadBlockHash + pgType: varchar + tsType: string + columnType: Column + columnOptions: + - option: length + value: 66 + - name: chainHeadBlockNumber + pgType: integer + tsType: number + columnType: Column + - name: latestIndexedBlockHash + pgType: varchar + tsType: string + columnType: Column + columnOptions: + - option: length + value: 66 + - name: latestIndexedBlockNumber + pgType: integer + tsType: number + columnType: Column + - name: latestCanonicalBlockHash + pgType: varchar + tsType: string + columnType: Column + columnOptions: + - option: length + value: 66 + - name: latestCanonicalBlockNumber + pgType: integer + tsType: number + columnType: Column +imports: + - toImport: + - Entity + - PrimaryGeneratedColumn + - Column + from: typeorm + - toImport: + - SyncStatusInterface + from: '@vulcanize/util' diff --git a/packages/codegen/src/entity.ts b/packages/codegen/src/entity.ts index 1f7a0c5e..5b7f3b4b 100644 --- a/packages/codegen/src/entity.ts +++ b/packages/codegen/src/entity.ts @@ -5,6 +5,7 @@ import fs from 'fs'; import path from 'path'; import assert from 'assert'; +import yaml from 'js-yaml'; import Handlebars from 'handlebars'; import { Writable } from 'stream'; @@ -12,6 +13,7 @@ import { getTsForSol, getPgForTs } from './utils/type-mappings'; import { Param } from './utils/types'; const TEMPLATE_FILE = './templates/entity-template.handlebars'; +const TABLES_DIR = './data/entities'; export class Entity { _entities: Array; @@ -44,7 +46,7 @@ export class Entity { entityObject.imports.push( { - toImport: ['Entity', 'PrimaryGeneratedColumn', 'Column', 'Index'], + toImport: new Set(['Entity', 'PrimaryGeneratedColumn', 'Column', 'Index']), from: 'typeorm' } ); @@ -106,16 +108,6 @@ export class Entity { ); } - // Use bigintTransformer for bigint types. - if (tsType === 'bigint') { - columnOptions.push( - { - option: 'transformer', - value: 'bigintTransformer' - } - ); - } - return { name, pgType, @@ -136,7 +128,8 @@ export class Entity { name: 'value', pgType: pgReturnType, tsType: tsReturnType, - columnType: 'Column' + columnType: 'Column', + columnOptions: [] }); entityObject.columns.push({ @@ -152,6 +145,31 @@ export class Entity { ] }); + entityObject.columns.forEach((column: any) => { + if (column.tsType === 'bigint') { + column.columnOptions.push( + { + option: 'transformer', + value: 'bigintTransformer' + } + ); + const importObject = entityObject.imports.find((element: any) => { + return element.from === '@vulcanize/util'; + }); + + if (importObject) { + importObject.toImport.add('bigintTransformer'); + } else { + entityObject.imports.push( + { + toImport: new Set(['bigintTransformer']), + from: '@vulcanize/util' + } + ); + } + } + }); + this._entities.push(entityObject); } @@ -176,362 +194,22 @@ export class Entity { } _addEventEntity (): void { - const entity: any = { - className: 'Event', - indexOn: [], - columns: [], - imports: [] - }; - - entity.imports.push( - { - toImport: ['Entity', 'PrimaryGeneratedColumn', 'Column', 'Index', 'ManyToOne'], - from: 'typeorm' - }, - { - toImport: ['BlockProgress'], - from: './BlockProgress' - } - ); - - entity.indexOn.push( - { - columns: ['block', 'contract'] - }, - { - columns: ['block', 'contract', 'eventName'] - } - ); - - entity.columns.push({ - name: 'block', - tsType: 'BlockProgress', - columnType: 'ManyToOne', - lhs: '()', - rhs: 'BlockProgress' - }); - - entity.columns.push({ - name: 'txHash', - pgType: 'varchar', - tsType: 'string', - columnType: 'Column', - columnOptions: [ - { - option: 'length', - value: 66 - } - ] - }); - - entity.columns.push({ - name: 'index', - pgType: 'integer', - tsType: 'number', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'contract', - pgType: 'varchar', - tsType: 'string', - columnType: 'Column', - columnOptions: [ - { - option: 'length', - value: 42 - } - ] - }); - - entity.columns.push({ - name: 'eventName', - pgType: 'varchar', - tsType: 'string', - columnType: 'Column', - columnOptions: [ - { - option: 'length', - value: 256 - } - ] - }); - - entity.columns.push({ - name: 'eventInfo', - pgType: 'text', - tsType: 'string', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'extraInfo', - pgType: 'text', - tsType: 'string', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'proof', - pgType: 'text', - tsType: 'string', - columnType: 'Column' - }); - + const entity = yaml.load(fs.readFileSync(path.resolve(__dirname, TABLES_DIR, 'Event.yaml'), 'utf8')); this._entities.push(entity); } _addSyncStatusEntity (): void { - const entity: any = { - className: 'SyncStatus', - implements: 'SyncStatusInterface', - indexOn: [], - columns: [], - imports: [] - }; - - entity.imports.push({ - toImport: ['Entity', 'PrimaryGeneratedColumn', 'Column'], - from: 'typeorm' - }); - - entity.imports.push({ - toImport: ['SyncStatusInterface'], - from: '@vulcanize/util' - }); - - entity.columns.push({ - name: 'chainHeadBlockHash', - pgType: 'varchar', - tsType: 'string', - columnType: 'Column', - columnOptions: [ - { - option: 'length', - value: 66 - } - ] - }); - - entity.columns.push({ - name: 'chainHeadBlockNumber', - pgType: 'integer', - tsType: 'number', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'latestIndexedBlockHash', - pgType: 'varchar', - tsType: 'string', - columnType: 'Column', - columnOptions: [ - { - option: 'length', - value: 66 - } - ] - }); - - entity.columns.push({ - name: 'latestIndexedBlockNumber', - pgType: 'integer', - tsType: 'number', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'latestCanonicalBlockHash', - pgType: 'varchar', - tsType: 'string', - columnType: 'Column', - columnOptions: [ - { - option: 'length', - value: 66 - } - ] - }); - - entity.columns.push({ - name: 'latestCanonicalBlockNumber', - pgType: 'integer', - tsType: 'number', - columnType: 'Column' - }); - + const entity = yaml.load(fs.readFileSync(path.resolve(__dirname, TABLES_DIR, 'SyncStatus.yaml'), 'utf8')); this._entities.push(entity); } _addContractEntity (): void { - const entity: any = { - className: 'Contract', - indexOn: [], - columns: [], - imports: [] - }; - - entity.imports.push({ - toImport: ['Entity', 'PrimaryGeneratedColumn', 'Column', 'Index'], - from: 'typeorm' - }); - - entity.indexOn.push( - { - columns: ['address'], - unique: true - } - ); - - entity.columns.push({ - name: 'address', - pgType: 'varchar', - tsType: 'string', - columnType: 'Column', - columnOptions: [ - { - option: 'length', - value: 42 - } - ] - }); - - entity.columns.push({ - name: 'kind', - pgType: 'varchar', - tsType: 'string', - columnType: 'Column', - columnOptions: [ - { - option: 'length', - value: 8 - } - ] - }); - - entity.columns.push({ - name: 'startingBlock', - pgType: 'integer', - tsType: 'number', - columnType: 'Column' - }); - + const entity = yaml.load(fs.readFileSync(path.resolve(__dirname, TABLES_DIR, 'Contract.yaml'), 'utf8')); this._entities.push(entity); } _addBlockProgressEntity (): void { - const entity: any = { - className: 'BlockProgress', - implements: 'BlockProgressInterface', - indexOn: [], - columns: [], - imports: [] - }; - - entity.imports.push({ - toImport: ['Entity', 'PrimaryGeneratedColumn', 'Column', 'Index'], - from: 'typeorm' - }); - - entity.imports.push({ - toImport: ['BlockProgressInterface'], - from: '@vulcanize/util' - }); - - entity.indexOn.push( - { - columns: ['blockHash'], - unique: true - }, - { - columns: ['blockNumber'] - }, - { - columns: ['parentHash'] - } - ); - - entity.columns.push({ - name: 'blockHash', - pgType: 'varchar', - tsType: 'string', - columnType: 'Column', - columnOptions: [ - { - option: 'length', - value: 66 - } - ] - }); - - entity.columns.push({ - name: 'parentHash', - pgType: 'varchar', - tsType: 'string', - columnType: 'Column', - columnOptions: [ - { - option: 'length', - value: 66 - } - ] - }); - - entity.columns.push({ - name: 'blockNumber', - pgType: 'integer', - tsType: 'number', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'blockTimestamp', - pgType: 'integer', - tsType: 'number', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'numEvents', - pgType: 'integer', - tsType: 'number', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'numProcessedEvents', - pgType: 'integer', - tsType: 'number', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'lastProcessedEventIndex', - pgType: 'integer', - tsType: 'number', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'isComplete', - pgType: 'boolean', - tsType: 'boolean', - columnType: 'Column' - }); - - entity.columns.push({ - name: 'isPruned', - pgType: 'boolean', - tsType: 'boolean', - columnType: 'Column', - columnOptions: [ - { - option: 'default', - value: false - } - ] - }); - + const entity = yaml.load(fs.readFileSync(path.resolve(__dirname, TABLES_DIR, 'BlockProgress.yaml'), 'utf8')); this._entities.push(entity); } } diff --git a/packages/codegen/src/generate-code.ts b/packages/codegen/src/generate-code.ts index babd361d..b995d78f 100644 --- a/packages/codegen/src/generate-code.ts +++ b/packages/codegen/src/generate-code.ts @@ -22,6 +22,7 @@ import { exportReadme } from './readme'; import { exportEvents } from './events'; import { exportJobRunner } from './job-runner'; import { exportWatchContract } from './watch-contract'; +import { exportLint } from './lint'; import { registerHandlebarHelpers } from './utils/handlebar-helpers'; const main = async (): Promise => { @@ -196,6 +197,17 @@ function generateWatcher (data: string, visitor: Visitor, argv: any) { ? fs.createWriteStream(path.join(outputDir, 'src/cli/watch-contract.ts')) : process.stdout; exportWatchContract(outStream); + + let rcOutStream; + let ignoreOutStream; + if (outputDir) { + rcOutStream = fs.createWriteStream(path.join(outputDir, '.eslintrc.json')); + ignoreOutStream = fs.createWriteStream(path.join(outputDir, '.eslintignore')); + } else { + rcOutStream = process.stdout; + ignoreOutStream = process.stdout; + } + exportLint(rcOutStream, ignoreOutStream); } main().catch(err => { diff --git a/packages/codegen/src/lint.ts b/packages/codegen/src/lint.ts new file mode 100644 index 00000000..849777fb --- /dev/null +++ b/packages/codegen/src/lint.ts @@ -0,0 +1,28 @@ +// +// Copyright 2021 Vulcanize, Inc. +// + +import fs from 'fs'; +import path from 'path'; +import Handlebars from 'handlebars'; +import { Writable } from 'stream'; + +const RC_TEMPLATE_FILE = './templates/eslintrc-template.handlebars'; +const IGNORE_TEMPLATE_FILE = './templates/eslintignore-template.handlebars'; + +/** + * Writes the .eslintrc.json and .eslintignore file generated from a template to respective streams. + * @param rcOutStream A writable output stream to write the .eslintrc.json file to. + * @param ignoreOutStream A writable output stream to write the .eslintignore file to. + */ +export function exportLint (rcOutStream: Writable, ignoreOutStream: Writable): void { + const rcTemplateString = fs.readFileSync(path.resolve(__dirname, RC_TEMPLATE_FILE)).toString(); + const rcTemplate = Handlebars.compile(rcTemplateString); + const rcString = rcTemplate({}); + rcOutStream.write(rcString); + + const ignoreTemplateString = fs.readFileSync(path.resolve(__dirname, IGNORE_TEMPLATE_FILE)).toString(); + const ignoreTemplate = Handlebars.compile(ignoreTemplateString); + const ignoreString = ignoreTemplate({}); + ignoreOutStream.write(ignoreString); +} diff --git a/packages/codegen/src/templates/database-template.handlebars b/packages/codegen/src/templates/database-template.handlebars index 14f512b6..71fdab89 100644 --- a/packages/codegen/src/templates/database-template.handlebars +++ b/packages/codegen/src/templates/database-template.handlebars @@ -44,6 +44,10 @@ export class Database { } {{#each queries as | query |}} + // eslint-disable-next-line camelcase + {{#if (banTypeCheck (capitalize query.name tillIndex=1)) }} + // eslint-disable-next-line @typescript-eslint/ban-types + {{/if}} async get{{capitalize query.name tillIndex=1}} ({ blockHash, contractAddress {{~#each query.params}}, {{this.name~}} {{/each}} }: { blockHash: string, contractAddress: string {{~#each query.params}}, {{this.name~}}: {{this.type~}} {{/each}} }): Promise<{{capitalize query.name tillIndex=1}} | undefined> { @@ -54,14 +58,18 @@ export class Database { {{#each query.params}} {{this.name}}{{#unless @last}},{{/unless}} {{/each}} - }) + }); } {{/each}} {{~#each queries as | query |}} + // eslint-disable-next-line camelcase + {{#if (banTypeCheck (capitalize query.name tillIndex=1)) }} + // eslint-disable-next-line @typescript-eslint/ban-types + {{/if}} async save{{capitalize query.name tillIndex=1}} ({ blockHash, contractAddress - {{~#each query.params}}, {{this.name~}} {{/each}}, value, proof}: DeepPartial<{{capitalize query.name tillIndex=1}}>): Promise<{{capitalize query.name tillIndex=1}}> { + {{~#each query.params}}, {{this.name~}} {{/each}}, value, proof }: DeepPartial<{{capitalize query.name tillIndex=1}}>): Promise<{{capitalize query.name tillIndex=1}}> { const repo = this._conn.getRepository({{capitalize query.name tillIndex=1}}); const entity = repo.create({ blockHash, contractAddress {{~#each query.params}}, {{this.name~}} {{/each}}, value, proof }); @@ -184,9 +192,9 @@ export class Database { }, new Map()); } - _setPropColMaps () { + _setPropColMaps (): void { {{#each queries as | query |}} - this._propColMaps['{{capitalize query.name tillIndex=1}}'] = this._getPropertyColumnMapForEntity('{{capitalize query.name tillIndex=1}}'); + this._propColMaps.{{capitalize query.name tillIndex=1}} = this._getPropertyColumnMapForEntity('{{capitalize query.name tillIndex=1}}'); {{/each}} } } diff --git a/packages/codegen/src/templates/entity-template.handlebars b/packages/codegen/src/templates/entity-template.handlebars index 438d9510..eedb7299 100644 --- a/packages/codegen/src/templates/entity-template.handlebars +++ b/packages/codegen/src/templates/entity-template.handlebars @@ -6,8 +6,6 @@ import { {{~#each import.toImport}} {{this}} {{~#unless @last}}, {{~/unless}} {{~/each}} } from '{{import.from}}'; {{/each}} -import { bigintTransformer } from '@vulcanize/util'; - @Entity() {{#each indexOn as | index |}} {{#if index.columns}} diff --git a/packages/codegen/src/templates/eslintignore-template.handlebars b/packages/codegen/src/templates/eslintignore-template.handlebars new file mode 100644 index 00000000..55cb5225 --- /dev/null +++ b/packages/codegen/src/templates/eslintignore-template.handlebars @@ -0,0 +1,2 @@ +# Don't lint build output. +dist diff --git a/packages/codegen/src/templates/eslintrc-template.handlebars b/packages/codegen/src/templates/eslintrc-template.handlebars new file mode 100644 index 00000000..476d529d --- /dev/null +++ b/packages/codegen/src/templates/eslintrc-template.handlebars @@ -0,0 +1,27 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "semistandard", + "plugin:@typescript-eslint/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/explicit-module-boundary-types": [ + "warn", + { + "allowArgumentsExplicitlyTypedAsAny": true + } + ] + } +} diff --git a/packages/codegen/src/templates/indexer-template.handlebars b/packages/codegen/src/templates/indexer-template.handlebars index 820c0bf2..260d4fd5 100644 --- a/packages/codegen/src/templates/indexer-template.handlebars +++ b/packages/codegen/src/templates/indexer-template.handlebars @@ -7,11 +7,11 @@ import debug from 'debug'; import { JsonFragment } from '@ethersproject/abi'; import { DeepPartial } from 'typeorm'; import JSONbig from 'json-bigint'; -import { BigNumber, ethers } from 'ethers'; +import { ethers } from 'ethers'; import { BaseProvider } from '@ethersproject/providers'; import { EthClient } from '@vulcanize/ipld-eth-client'; -import { getStorageValue, GetStorageAt, StorageLayout } from '@vulcanize/solidity-mapper'; +import { StorageLayout } from '@vulcanize/solidity-mapper'; import { EventInterface, Indexer as BaseIndexer, ValueResult, UNKNOWN_EVENT_NAME } from '@vulcanize/util'; import { Database } from './database'; @@ -101,7 +101,6 @@ export class Indexer { {{#each queries as | query |}} async {{query.name}} (blockHash: string, contractAddress: string {{~#each query.params}}, {{this.name~}}: {{this.type~}} {{/each}}): Promise { - const entity = await this._db.get{{capitalize query.name tillIndex=1}}({ blockHash, contractAddress {{~#each query.params}}, {{this.name~}} {{~/each}} }); if (entity) { @@ -119,21 +118,22 @@ export class Indexer { const contract = new ethers.Contract(contractAddress, this._abi, this._ethProvider); const { block: { number } } = await this._ethClient.getBlockByHash(blockHash); - const blockNumber = BigNumber.from(number).toNumber(); + const blockNumber = ethers.BigNumber.from(number).toNumber(); + + {{#if (compare query.returnType 'bigint')}} let value = await contract.{{query.name}}( {{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockNumber }); - - {{~#if (compare query.returnType 'bigint')}} - value = value.toString(); value = BigInt(value); + {{else}} + const value = await contract.{{query.name}}( + {{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockNumber }); {{/if}} const result: ValueResult = { value }; {{/if}} {{~#if (compare query.mode @root.constants.MODE_STORAGE)}} - const result = await this._baseIndexer.getStorageValue( this._storageLayout, blockHash, @@ -152,9 +152,9 @@ export class Indexer { } {{/each}} - async triggerIndexingOnEvent (event: Event): Promise { // TODO: Implement custom hooks. + assert(event); } async processEvent (event: Event): Promise { diff --git a/packages/codegen/src/templates/package-template.handlebars b/packages/codegen/src/templates/package-template.handlebars index fbc7247a..0e50699e 100644 --- a/packages/codegen/src/templates/package-template.handlebars +++ b/packages/codegen/src/templates/package-template.handlebars @@ -5,6 +5,7 @@ "private": true, "main": "dist/index.js", "scripts": { + "lint": "eslint .", "build": "tsc", "server": "DEBUG=vulcanize:* ts-node src/server.ts", "job-runner": "DEBUG=vulcanize:* ts-node src/job-runner.ts", @@ -21,7 +22,7 @@ }, "homepage": "https://github.com/vulcanize/watcher-ts#readme", "dependencies": { - "@apollo/client": "^3.3.19", + "@ethersproject/providers": "5.3.0", "@vulcanize/cache": "^0.1.0", "@vulcanize/ipld-eth-client": "^0.1.0", "@vulcanize/solidity-mapper": "^0.1.0", @@ -33,13 +34,24 @@ "express": "^4.17.1", "graphql": "^15.5.0", "graphql-import-node": "^0.0.4", + "json-bigint": "^1.0.0", "reflect-metadata": "^0.1.13", + "typeorm": "^0.2.32", "yargs": "^17.0.1" }, "devDependencies": { "@ethersproject/abi": "^5.3.0", "@types/express": "^4.17.11", "@types/yargs": "^17.0.0", + "@typescript-eslint/eslint-plugin": "^4.25.0", + "@typescript-eslint/parser": "^4.25.0", + "eslint": "^7.27.0", + "eslint-config-semistandard": "^15.0.1", + "eslint-config-standard": "^16.0.3", + "eslint-plugin-import": "^2.23.3", + "eslint-plugin-node": "^11.1.0", + "eslint-plugin-promise": "^5.1.0", + "eslint-plugin-standard": "^5.0.0", "ts-node": "^10.0.0", "typescript": "^4.3.2" } diff --git a/packages/codegen/src/utils/handlebar-helpers.ts b/packages/codegen/src/utils/handlebar-helpers.ts index 87c8dfe9..abcaacf1 100644 --- a/packages/codegen/src/utils/handlebar-helpers.ts +++ b/packages/codegen/src/utils/handlebar-helpers.ts @@ -5,9 +5,12 @@ import assert from 'assert'; import Handlebars from 'handlebars'; +import { bannedTypes } from './types'; + export function registerHandlebarHelpers (): void { Handlebars.registerHelper('compare', compareHelper); Handlebars.registerHelper('capitalize', capitalizeHelper); + Handlebars.registerHelper('banTypeCheck', banTypeCheckHelper); } /** @@ -50,3 +53,7 @@ function capitalizeHelper (value: string, options: any): string { return result; } + +function banTypeCheckHelper (value: string): boolean { + return bannedTypes.has(value); +} diff --git a/packages/codegen/src/utils/types.ts b/packages/codegen/src/utils/types.ts index 2a99ad6b..af4ba2a0 100644 --- a/packages/codegen/src/utils/types.ts +++ b/packages/codegen/src/utils/types.ts @@ -6,3 +6,7 @@ export interface Param { name: string; type: string; } + +export const bannedTypes = new Set([ + 'Symbol' +]); diff --git a/packages/erc20-watcher/package.json b/packages/erc20-watcher/package.json index aecbf9c4..88f2c0b5 100644 --- a/packages/erc20-watcher/package.json +++ b/packages/erc20-watcher/package.json @@ -40,6 +40,7 @@ "homepage": "https://github.com/vulcanize/watcher-ts#readme", "dependencies": { "@apollo/client": "^3.3.19", + "@ethersproject/providers": "5.3.0", "@types/lodash": "^4.14.168", "@vulcanize/cache": "^0.1.0", "@vulcanize/ipld-eth-client": "^0.1.0", @@ -63,7 +64,6 @@ "@ethersproject/abi": "^5.3.0", "@nomiclabs/hardhat-ethers": "^2.0.2", "@nomiclabs/hardhat-waffle": "^2.0.1", - "@openzeppelin/contracts": "^4.3.1", "@types/express": "^4.17.11", "@types/json-bigint": "^1.0.0", "@types/yargs": "^17.0.0", diff --git a/yarn.lock b/yarn.lock index da8adca3..969d8573 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1979,11 +1979,6 @@ resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-3.4.1-solc-0.7-2.tgz#371c67ebffe50f551c3146a9eec5fe6ffe862e92" integrity sha512-tAG9LWg8+M2CMu7hIsqHPaTyG4uDzjr6mhvH96LvOpLZZj6tgzTluBt+LsCf1/QaYrlis6pITvpIaIhE+iZB+Q== -"@openzeppelin/contracts@^4.3.1": - version "4.3.1" - resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.3.1.tgz#c01f791ce6c9d3989ac1a643267501dbe336b9e3" - integrity sha512-QjgbPPlmDK2clK1hzjw2ROfY8KA5q+PfhDUUxZFEBCZP9fi6d5FuNoh/Uq0oCTMEKPmue69vhX2jcl0N/tFKGw== - "@openzeppelin/contracts@^4.3.2": version "4.3.2" resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.3.2.tgz#ff80affd6d352dbe1bbc5b4e1833c41afd6283b6" @@ -2400,6 +2395,11 @@ resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-1.8.0.tgz#682477dbbbd07cd032731cb3b0e7eaee3d026b69" integrity sha512-2aoSC4UUbHDj2uCsCxcG/vRMXey/m17bC7UwitVm5hn22nI8O8Y9iDpA76Orc+DWkQ4zZrOKEshCqR/jSuXAHA== +"@types/js-yaml@^4.0.3": + version "4.0.3" + resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.3.tgz#9f33cd6fbf0d5ec575dc8c8fc69c7fec1b4eb200" + integrity sha512-5t9BhoORasuF5uCPr+d5/hdB++zRFUTMIZOzbNkr+jZh3yQht4HYbRDyj9fY8n2TZT30iW9huzav73x4NikqWg== + "@types/json-bigint@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@types/json-bigint/-/json-bigint-1.0.0.tgz#7a4726540cc6fe47cfa54b9b3022b89cf7fe1517"