diff --git a/package.json b/package.json index 32fa82f0..958464e5 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,10 @@ "name": "watcher-ts", "license": "AGPL-3.0", "private": true, - "workspaces": [ - "packages/*" - ], + "workspaces": { + "packages": ["packages/*"], + "nohoist": ["**/@graphprotocol/graph-ts"] + }, "devDependencies": { "depcheck": "^1.4.2", "husky": "^7.0.2", diff --git a/packages/graph-node/assembly/index.ts b/packages/graph-node/assembly/index.ts index a866864c..baa95b2e 100644 --- a/packages/graph-node/assembly/index.ts +++ b/packages/graph-node/assembly/index.ts @@ -1,5 +1,39 @@ -// The entry file of your WebAssembly module. +import { + // ethereum, + // store, + log + // ipfs, + // json, + // crypto, -export function add (a: i32, b: i32): i32 { - return a + b; + // dataSource, + // ens, + + // typeConversion, + + // bigDecimal, + // bigInt, + + // Address, + // BigDecimal, + // BigInt, + // ByteArray, + // Bytes, + // DataSourceContext, + // DataSourceTemplate, + // Entity, + // JSONValue, + // JSONValueKind, + // JSONValuePayload, + // Result, + // TypedMap, + // TypedMapEntry, + // Value, + // ValueKind, + // ValuePayload, + // Wrapped +} from '@graphprotocol/graph-ts'; + +export function callGraphAPI (): void { + log.debug('hello {}', ['world']); } diff --git a/packages/graph-node/package.json b/packages/graph-node/package.json index 3ea694f6..3202b29d 100644 --- a/packages/graph-node/package.json +++ b/packages/graph-node/package.json @@ -4,6 +4,7 @@ "main": "index.js", "license": "AGPL-3.0", "devDependencies": { + "@graphprotocol/graph-ts": "^0.22.0", "@typescript-eslint/eslint-plugin": "^4.25.0", "@typescript-eslint/parser": "^4.25.0", "assemblyscript": "^0.19.16", @@ -14,17 +15,17 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.1.0", "eslint-plugin-standard": "^5.0.0", - "typescript": "^4.3.2", "nodemon": "^2.0.7", - "ts-node": "^10.0.0" + "ts-node": "^10.0.0", + "typescript": "^4.3.2" }, "scripts": { "lint": "eslint .", "build": "tsc", - "asbuild:debug": "asc assembly/index.ts --target debug", - "asbuild:release": "asc assembly/index.ts --target release", + "asbuild:debug": "asc assembly/index.ts --lib ./node_modules --target debug", + "asbuild:release": "asc assembly/index.ts --lib ./node_modules --target release", "asbuild": "yarn asbuild:debug && yarn asbuild:release", - "test": "mocha src/**/*.test.ts" + "test": "yarn asbuild:debug && mocha src/**/*.test.ts" }, "dependencies": { "@assemblyscript/loader": "^0.19.16" diff --git a/packages/graph-node/src/index.test.ts b/packages/graph-node/src/index.test.ts index 5f6ecd75..8f8b63eb 100644 --- a/packages/graph-node/src/index.test.ts +++ b/packages/graph-node/src/index.test.ts @@ -2,16 +2,14 @@ // Copyright 2021 Vulcanize, Inc. // -import { expect } from 'chai'; import path from 'path'; -import 'mocha'; -import { getExports } from './index'; +import { instantiate } from './index'; const WASM_FILE_PATH = '../build/debug.wasm'; it('should execute exported function', async () => { const filePath = path.resolve(__dirname, WASM_FILE_PATH); - const { exports } = await getExports(filePath); - expect(exports.add(1, 2)).to.equal(3); + const { exports } = await instantiate(filePath); + exports.callGraphAPI(); }); diff --git a/packages/graph-node/src/index.ts b/packages/graph-node/src/index.ts index 86f2ae4d..fe1898f9 100644 --- a/packages/graph-node/src/index.ts +++ b/packages/graph-node/src/index.ts @@ -5,9 +5,76 @@ import fs from 'fs/promises'; import loader from '@assemblyscript/loader'; -const imports = { /* imports go here */ }; +const imports = { + index: { + 'store.get': () => { + console.log('store.get'); + }, + 'store.set': () => { + console.log('store.set'); + }, -export const getExports = async (filePath: string): Promise => { + 'typeConversion.stringToH160': () => { + console.log('typeConversion.stringToH160'); + }, + 'typeConversion.bytesToHex': () => { + console.log('typeConversion.bytesToHex'); + }, + 'typeConversion.bytesToString': () => { + console.log('typeConversion.bytesToString'); + }, + 'typeConversion.bigIntToString': () => { + console.log('typeConversion.bigIntToString'); + }, + + 'bigDecimal.fromString': () => { + console.log('bigDecimal.fromString'); + }, + 'bigDecimal.times': () => { + console.log('bigDecimal.times'); + }, + 'bigDecimal.dividedBy': () => { + console.log('bigDecimal.dividedBy'); + }, + 'bigDecimal.plus': () => { + console.log('bigDecimal.plus'); + }, + 'bigDecimal.minus': () => { + console.log('bigDecimal.minus'); + }, + + 'bigInt.plus': () => { + console.log('bigInt.plus'); + }, + 'bigInt.minus': () => { + console.log('bigInt.minus'); + }, + 'bigInt.times': () => { + console.log('bigInt.times'); + }, + 'bigInt.dividedBy': () => { + console.log('bigInt.dividedBy'); + }, + 'bigInt.mod': () => { + console.log('bigInt.mod'); + }, + + 'log.log': () => { + console.log('log.log'); + }, + + 'dataSource.create': () => { + console.log('dataSource.create'); + } + }, + ethereum: { + 'ethereum.call': () => { + console.log('ethereum.call'); + } + } +}; + +export const instantiate = async (filePath: string): Promise => { const buffer = await fs.readFile(filePath); return loader.instantiate(buffer, imports); }; diff --git a/yarn.lock b/yarn.lock index 5ef294db..a14df5e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1100,6 +1100,13 @@ "@ethersproject/properties" "^5.3.0" "@ethersproject/strings" "^5.3.0" +"@graphprotocol/graph-ts@^0.22.0": + version "0.22.0" + resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.22.0.tgz#5280513d1c8a162077f82ce7f9a492bb5783d6f4" + integrity sha512-kJIBL73xBxj0+NJdRABukAtcrc3Mb8jt31s0tCLPe6c57rQXEf7KR9oYrFdzE1ZsJCP6j+MX+A2+sj1Pj3aJtQ== + dependencies: + assemblyscript "0.19.10" + "@graphql-typed-document-node/core@^3.0.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.0.tgz#0eee6373e11418bfe0b5638f654df7a4ca6a3950" @@ -3465,6 +3472,14 @@ asn1@~0.2.3: dependencies: safer-buffer "~2.1.0" +assemblyscript@0.19.10: + version "0.19.10" + resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.19.10.tgz#7ede6d99c797a219beb4fa4614c3eab9e6343c8e" + integrity sha512-HavcUBXB3mBTRGJcpvaQjmnmaqKHBGREjSPNsIvnAk2f9dj78y4BkMaSSdvBQYWcDDzsHQjyUC8stICFkD1Odg== + dependencies: + binaryen "101.0.0-nightly.20210723" + long "^4.0.0" + assemblyscript@^0.19.16: version "0.19.16" resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.19.16.tgz#fc06c9892755775e8e31a59249fbc361fd49e1d1" @@ -4161,6 +4176,11 @@ bindings@^1.2.1: dependencies: file-uri-to-path "1.0.0" +binaryen@101.0.0-nightly.20210723: + version "101.0.0-nightly.20210723" + resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-101.0.0-nightly.20210723.tgz#b6bb7f3501341727681a03866c0856500eec3740" + integrity sha512-eioJNqhHlkguVSbblHOtLqlhtC882SOEPKmNFZaDuz1hzQjolxZ+eu3/kaS10n3sGPONsIZsO7R9fR00UyhEUA== + binaryen@101.0.0-nightly.20210904: version "101.0.0-nightly.20210904" resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-101.0.0-nightly.20210904.tgz#58a7990d6d64b16567f376a1fe47d8aea6698b14"