diff --git a/packages/cache/.eslintignore b/packages/cache/.eslintignore new file mode 100644 index 00000000..653874b5 --- /dev/null +++ b/packages/cache/.eslintignore @@ -0,0 +1,5 @@ +# Don't lint node_modules. +node_modules + +# Don't lint build output. +dist diff --git a/packages/cache/.eslintrc.json b/packages/cache/.eslintrc.json new file mode 100644 index 00000000..86e5d97a --- /dev/null +++ b/packages/cache/.eslintrc.json @@ -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": [ + "error", + { + "allowArgumentsExplicitlyTypedAsAny": true + } + ] + } +} diff --git a/packages/cache/package.json b/packages/cache/package.json index 7ee1eff9..11dae296 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -1,45 +1,59 @@ { - "name": "@vulcanize/cache", - "version": "0.1.0", - "description": "Generic object cache", - "private": true, - "main": "index.ts", - "scripts": { - "test": "mocha -r ts-node/register src/**/*.spec.ts" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/vulcanize/erc20-watcher.git" - }, - "author": "", - "license": "UNLICENSED", - "bugs": { - "url": "https://github.com/vulcanize/erc20-watcher/issues" - }, - "homepage": "https://github.com/vulcanize/erc20-watcher#readme", - "dependencies": { - "@types/lodash": "^4.14.168", - "apollo-type-bigint": "^0.1.3", - "canonical-json": "^0.0.4", - "debug": "^4.3.1", - "ethers": "^5.2.0", - "express": "^4.17.1", - "express-graphql": "^0.12.0", - "fs-extra": "^10.0.0", - "graphql": "^15.5.0", - "graphql-import-node": "^0.0.4", - "graphql-request": "^3.4.0", - "graphql-tools": "^7.0.4", - "left-pad": "^1.3.0", - "level": "^7.0.0", - "lodash": "^4.17.21", - "toml": "^3.0.0", - "yargs": "^17.0.1" - }, - "devDependencies": { - "@types/express": "^4.17.11", - "@types/yargs": "^17.0.0", - "nodemon": "^2.0.7", - "ts-node": "^10.0.0" - } + "name": "@vulcanize/cache", + "version": "0.1.0", + "description": "Generic object cache", + "private": true, + "main": "index.ts", + "scripts": { + "test": "mocha -r ts-node/register src/**/*.spec.ts", + "build": "tsc", + "lint": "eslint ." + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vulcanize/erc20-watcher.git" + }, + "author": "", + "license": "UNLICENSED", + "bugs": { + "url": "https://github.com/vulcanize/erc20-watcher/issues" + }, + "homepage": "https://github.com/vulcanize/erc20-watcher#readme", + "dependencies": { + "@types/lodash": "^4.14.168", + "apollo-type-bigint": "^0.1.3", + "canonical-json": "^0.0.4", + "debug": "^4.3.1", + "ethers": "^5.2.0", + "express": "^4.17.1", + "express-graphql": "^0.12.0", + "fs-extra": "^10.0.0", + "graphql": "^15.5.0", + "graphql-import-node": "^0.0.4", + "graphql-request": "^3.4.0", + "graphql-tools": "^7.0.4", + "left-pad": "^1.3.0", + "level": "^7.0.0", + "lodash": "^4.17.21", + "toml": "^3.0.0", + "yargs": "^17.0.1" + }, + "devDependencies": { + "@types/debug": "^4.1.5", + "@types/express": "^4.17.11", + "@types/fs-extra": "^9.0.11", + "@types/level": "^6.0.0", + "@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", + "nodemon": "^2.0.7", + "ts-node": "^10.0.0" } +} diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index 18136f19..75fd4e9e 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -8,12 +8,18 @@ import debug from 'debug'; const log = debug('vulcanize:cache'); -export const getCache = async (config) => { +interface Config { + name: string; + enabled: boolean; + deleteOnStart: boolean; +} + +export const getCache = async (config: Config): Promise => { let cache; // Cache is optional. if (config) { - log("config", JSON.stringify(config, null, 2)); + log('config', JSON.stringify(config, null, 2)); const { name, enabled, deleteOnStart } = config; @@ -37,23 +43,22 @@ export const getCache = async (config) => { }; export class Cache { - _db: any; _name: string; - constructor(name, dirPath) { + constructor (name: string, dirPath: string) { assert(name); assert(dirPath); this._name = name; - this._db = level(dirPath, { valueEncoding: 'json' });; + this._db = level(dirPath, { valueEncoding: 'json' }); } - key(obj) { + key (obj: any): string { return this._cacheKey(obj); } - async get(obj) { + async get (obj: any): Promise<[any, boolean] | undefined> { const key = this._cacheKey(obj); try { @@ -66,16 +71,16 @@ export class Cache { log(`${this._name}: cache miss ${key}`); if (err.notFound) { - return [undefined, false] + return [undefined, false]; } } } - async put(obj, value) { + async put (obj: any, value: any): Promise { await this._db.put(this._cacheKey(obj), value); } - _cacheKey(obj) { + _cacheKey (obj: any): string { return ethers.utils.keccak256(Buffer.from(canonicalStringify(obj))); } } diff --git a/packages/cache/tsconfig.json b/packages/cache/tsconfig.json new file mode 100644 index 00000000..13f92c39 --- /dev/null +++ b/packages/cache/tsconfig.json @@ -0,0 +1,75 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "dist", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ + + /* Module Resolution Options */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + "typeRoots": [ + "./types" + ], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + }, + "exclude": ["src/**/*.test.ts", "dist"] +} diff --git a/packages/cache/types/common/main.d.ts b/packages/cache/types/common/main.d.ts new file mode 100644 index 00000000..43580f17 --- /dev/null +++ b/packages/cache/types/common/main.d.ts @@ -0,0 +1,2 @@ +// https://medium.com/@steveruiz/using-a-javascript-library-without-type-declarations-in-a-typescript-project-3643490015f3 +declare module 'canonical-json' diff --git a/packages/cache/types/common/package.json b/packages/cache/types/common/package.json new file mode 100644 index 00000000..2bf0efa4 --- /dev/null +++ b/packages/cache/types/common/package.json @@ -0,0 +1,5 @@ +{ + "name": "common", + "version": "0.1.0", + "typings": "main.d.ts" +} diff --git a/packages/ipld-eth-client/.eslintignore b/packages/ipld-eth-client/.eslintignore new file mode 100644 index 00000000..653874b5 --- /dev/null +++ b/packages/ipld-eth-client/.eslintignore @@ -0,0 +1,5 @@ +# Don't lint node_modules. +node_modules + +# Don't lint build output. +dist diff --git a/packages/ipld-eth-client/.eslintrc.json b/packages/ipld-eth-client/.eslintrc.json new file mode 100644 index 00000000..476d529d --- /dev/null +++ b/packages/ipld-eth-client/.eslintrc.json @@ -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/ipld-eth-client/package.json b/packages/ipld-eth-client/package.json index b80688cd..b22e9e22 100644 --- a/packages/ipld-eth-client/package.json +++ b/packages/ipld-eth-client/package.json @@ -1,46 +1,56 @@ { - "name": "@vulcanize/ipld-eth-client", - "version": "0.1.0", - "description": "IPLD ETH Client", - "private": true, - "main": "index.ts", - "scripts": { - "test": "mocha -r ts-node/register src/**/*.spec.ts" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/vulcanize/erc20-watcher.git" - }, - "author": "", - "license": "UNLICENSED", - "bugs": { - "url": "https://github.com/vulcanize/erc20-watcher/issues" - }, - "homepage": "https://github.com/vulcanize/erc20-watcher#readme", - "dependencies": { - "@types/lodash": "^4.14.168", - "@vulcanize/cache": "^0.1.0", - "apollo-type-bigint": "^0.1.3", - "canonical-json": "^0.0.4", - "debug": "^4.3.1", - "ethers": "^5.2.0", - "express": "^4.17.1", - "express-graphql": "^0.12.0", - "fs-extra": "^10.0.0", - "graphql": "^15.5.0", - "graphql-import-node": "^0.0.4", - "graphql-request": "^3.4.0", - "graphql-tools": "^7.0.4", - "left-pad": "^1.3.0", - "level": "^7.0.0", - "lodash": "^4.17.21", - "toml": "^3.0.0", - "yargs": "^17.0.1" - }, - "devDependencies": { - "@types/express": "^4.17.11", - "@types/yargs": "^17.0.0", - "nodemon": "^2.0.7", - "ts-node": "^10.0.0" - } + "name": "@vulcanize/ipld-eth-client", + "version": "0.1.0", + "description": "IPLD ETH Client", + "private": true, + "main": "index.ts", + "scripts": { + "test": "mocha -r ts-node/register src/**/*.spec.ts", + "build": "tsc", + "lint": "eslint ." + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vulcanize/erc20-watcher.git" + }, + "author": "", + "license": "UNLICENSED", + "bugs": { + "url": "https://github.com/vulcanize/erc20-watcher/issues" + }, + "homepage": "https://github.com/vulcanize/erc20-watcher#readme", + "dependencies": { + "@types/lodash": "^4.14.168", + "@vulcanize/cache": "^0.1.0", + "apollo-type-bigint": "^0.1.3", + "debug": "^4.3.1", + "ethers": "^5.2.0", + "express": "^4.17.1", + "express-graphql": "^0.12.0", + "fs-extra": "^10.0.0", + "graphql": "^15.5.0", + "graphql-import-node": "^0.0.4", + "graphql-request": "^3.4.0", + "graphql-tools": "^7.0.4", + "left-pad": "^1.3.0", + "level": "^7.0.0", + "lodash": "^4.17.21", + "toml": "^3.0.0", + "yargs": "^17.0.1" + }, + "devDependencies": { + "@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", + "nodemon": "^2.0.7", + "ts-node": "^10.0.0" } +} diff --git a/packages/ipld-eth-client/src/eth-client.ts b/packages/ipld-eth-client/src/eth-client.ts index e4b88c4a..5598cfd9 100644 --- a/packages/ipld-eth-client/src/eth-client.ts +++ b/packages/ipld-eth-client/src/eth-client.ts @@ -6,13 +6,23 @@ import { Cache } from '@vulcanize/cache'; import ethQueries from './eth-queries'; import { padKey } from './utils'; -export class EthClient { +interface Config { + gqlEndpoint: string; + cache: Cache; +} - _config: any; - _client: any; +interface Vars { + blockHash: string; + contract: string; + slot?: string; +} + +export class EthClient { + _config: Config; + _client: GraphQLClient; _cache: Cache; - constructor(config) { + constructor (config: Config) { this._config = config; const { gqlEndpoint, cache } = config; @@ -22,7 +32,7 @@ export class EthClient { this._cache = cache; } - async getStorageAt({ blockHash, contract, slot }) { + async getStorageAt ({ blockHash, contract, slot }: { blockHash: string, contract: string, slot: string }): Promise<{ value: string, proof: { data: string } }> { slot = `0x${padKey(slot)}`; const result = await this._getCachedOrFetch('getStorageAt', { blockHash, contract, slot }); @@ -46,14 +56,14 @@ export class EthClient { }; } - async getLogs(vars) { + async getLogs (vars: Vars): Promise { const result = await this._getCachedOrFetch('getLogs', vars); const { getLogs: logs } = result; return logs; } - async _getCachedOrFetch(queryName, vars) { + async _getCachedOrFetch (queryName: keyof typeof ethQueries, vars: Vars): Promise { const keyObj = { queryName, vars @@ -61,7 +71,7 @@ export class EthClient { // Check if request cached in db, if cache is enabled. if (this._cache) { - const [value, found] = await this._cache.get(keyObj); + const [value, found] = await this._cache.get(keyObj) || [undefined, false]; if (found) { return value; } diff --git a/packages/ipld-eth-client/src/utils.ts b/packages/ipld-eth-client/src/utils.ts index 4484c04a..22138c25 100644 --- a/packages/ipld-eth-client/src/utils.ts +++ b/packages/ipld-eth-client/src/utils.ts @@ -1,21 +1,21 @@ import leftPad from 'left-pad'; import { ethers } from 'ethers'; -export const padKey = input => +export const padKey = (input: string): string => leftPad(ethers.utils.hexlify(input).replace('0x', ''), 64, '0'); -export const getMappingSlot = (mappingSlot, key) => { +export const getMappingSlot = (mappingSlot: string, key: string): string => { const mappingSlotPadded = padKey(mappingSlot); const keyPadded = padKey(key); const fullKey = keyPadded.concat(mappingSlotPadded); const slot = ethers.utils.keccak256(`0x${fullKey}`); - return slot + return slot; }; -export const getStorageLeafKey = (slot) => ethers.utils.keccak256(slot); +export const getStorageLeafKey = (slot: string): string => ethers.utils.keccak256(slot); -export const topictoAddress = (topic) => { +export const topictoAddress = (topic: string): string => { return ethers.utils.getAddress( ethers.utils.hexZeroPad( ethers.utils.hexStripZeros(topic), 20 diff --git a/packages/ipld-eth-client/tsconfig.json b/packages/ipld-eth-client/tsconfig.json new file mode 100644 index 00000000..077ac21d --- /dev/null +++ b/packages/ipld-eth-client/tsconfig.json @@ -0,0 +1,75 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "dist", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ + + /* Module Resolution Options */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + "typeRoots": [ + "./types" + ], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + }, + "exclude": ["src/**/*.test.ts", "dist", "**/node_modules"] +} diff --git a/packages/ipld-eth-client/types/common/main.d.ts b/packages/ipld-eth-client/types/common/main.d.ts new file mode 100644 index 00000000..43580f17 --- /dev/null +++ b/packages/ipld-eth-client/types/common/main.d.ts @@ -0,0 +1,2 @@ +// https://medium.com/@steveruiz/using-a-javascript-library-without-type-declarations-in-a-typescript-project-3643490015f3 +declare module 'canonical-json' diff --git a/packages/ipld-eth-client/types/common/package.json b/packages/ipld-eth-client/types/common/package.json new file mode 100644 index 00000000..2bf0efa4 --- /dev/null +++ b/packages/ipld-eth-client/types/common/package.json @@ -0,0 +1,5 @@ +{ + "name": "common", + "version": "0.1.0", + "typings": "main.d.ts" +} diff --git a/packages/watcher/package.json b/packages/watcher/package.json index fb05c20d..c588318c 100644 --- a/packages/watcher/package.json +++ b/packages/watcher/package.json @@ -46,6 +46,7 @@ "devDependencies": { "@types/es6-shim": "^0.31.41", "@types/express": "^4.17.11", + "@types/fs-extra": "^9.0.11", "@types/yargs": "^17.0.0", "nodemon": "^2.0.7", "ts-node": "^10.0.0" diff --git a/packages/watcher/src/server.ts b/packages/watcher/src/server.ts index f6bde7fc..130a0935 100644 --- a/packages/watcher/src/server.ts +++ b/packages/watcher/src/server.ts @@ -24,12 +24,12 @@ export const createServer = async () => { const configFile = argv['configFile']; const configFilePath = path.resolve(configFile); - const fileExists = await fs.exists(configFilePath); + const fileExists = await fs.pathExists(configFilePath); if (!fileExists) { throw new Error(`Config file not found: ${configFilePath}`); } - var config = toml.parse(await fs.readFile(configFilePath)); + var config = toml.parse(await fs.readFile(configFilePath, 'utf8')); log("config", JSON.stringify(config, null, 2)); assert(config.server, 'Missing server config'); diff --git a/yarn.lock b/yarn.lock index c9b0c472..a2cf6298 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1506,6 +1506,19 @@ dependencies: "@types/node" "*" +"@types/debug@^4.1.5": + version "4.1.5" + resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd" + integrity sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ== + +"@types/encoding-down@*": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@types/encoding-down/-/encoding-down-5.0.0.tgz#0b5b90b93ac3aa75148f19508044e7bd36463557" + integrity sha512-G0MlS/+/U2RIQLcSEhhAcoMrXw3hXUCFSKbhbeEljoKMra2kq+NPX6tfOveSWQLX2hJXBo+YrvKgAGe+tFL1Aw== + dependencies: + "@types/abstract-leveldown" "*" + "@types/level-codec" "*" + "@types/es6-shim@^0.31.41": version "0.31.41" resolved "https://registry.yarnpkg.com/@types/es6-shim/-/es6-shim-0.31.41.tgz#6c0610500de36a4be69c734335a2997f6ff79e51" @@ -1530,6 +1543,13 @@ "@types/qs" "*" "@types/serve-static" "*" +"@types/fs-extra@^9.0.11": + version "9.0.11" + resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.11.tgz#8cc99e103499eab9f347dbc6ca4e99fb8d2c2b87" + integrity sha512-mZsifGG4QeQ7hlkhO56u7zt/ycBgGxSVsFI/6lGTU34VtwkiqrrSDgw0+ygs8kFGWcXnFQWMrzF2h7TtDFNixA== + dependencies: + "@types/node" "*" + "@types/json-schema@^7.0.3": version "7.0.7" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad" @@ -1540,7 +1560,21 @@ resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4= -"@types/levelup@^4.3.0": +"@types/level-codec@*": + version "9.0.0" + resolved "https://registry.yarnpkg.com/@types/level-codec/-/level-codec-9.0.0.tgz#9f1dc7f9017b6fba094a450602ec0b91cc384059" + integrity sha512-SWYkVJylo1dqblkhrr7UtmsQh4wdZA9bV1y3QJSywMPSqGfW0p1w37N1EayZtKbg1dGReIIQEEOtxk4wZvGrWQ== + +"@types/level@^6.0.0": + version "6.0.0" + resolved "https://registry.yarnpkg.com/@types/level/-/level-6.0.0.tgz#0bc0aaf1106598e1774e1dc5b69f0d58885d9d34" + integrity sha512-NjaUpukKfCvnV4Wk0jUaodFi2/66HxgpYghc2aV8iP+zk2NMt/9ps1eVlifqOU/+eLzMlDIY69NWkbPaAstukQ== + dependencies: + "@types/abstract-leveldown" "*" + "@types/encoding-down" "*" + "@types/levelup" "*" + +"@types/levelup@*", "@types/levelup@^4.3.0": version "4.3.1" resolved "https://registry.yarnpkg.com/@types/levelup/-/levelup-4.3.1.tgz#7a53b9fd510716e11b2065332790fdf5f9b950b9" integrity sha512-n//PeTpbHLjMLTIgW5B/g06W/6iuTBHuvUka2nFL9APMSVMNe2r4enADfu3CIE9IyV9E+uquf9OEQQqrDeg24A==