This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3297 from trufflesuite/truffle-db
Merge `truffle-db` into `develop`
- Loading branch information
Showing
113 changed files
with
54,860 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
types/schema.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dist | ||
types/schema.d.ts | ||
node_modules | ||
src/loaders/schema/test/workflowCompileOutputMock | ||
src/loaders/schema/test/compilationSources/build/contracts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `@truffle/db` | ||
|
||
> TODO: description | ||
## Usage | ||
|
||
``` | ||
const { TruffleDB } = require('@truffle/db'); | ||
// TODO: DEMONSTRATE API | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
# stop if any commands fail | ||
set -ex | ||
|
||
mkdir -p dist/src/ | ||
cp ./src/schema.graphql ./dist/src/schema.graphql | ||
tsc --project tsconfig.codegen.json | ||
node ./bin/codegen.js | ||
tsc $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { generateNamespace } = require("@gql2ts/from-schema"); | ||
|
||
// for path setup | ||
require("@truffle/db"); | ||
|
||
const { schema } = require("@truffle/db/data/schema"); | ||
|
||
const dataModel = generateNamespace("DataModel", schema, { | ||
ignoreTypeNameDeclaration: true | ||
}); | ||
|
||
fs.writeFileSync(path.join(__dirname, "..", "types", "schema.d.ts"), dataModel); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { ApolloServer } = require("apollo-server"); | ||
|
||
const { TruffleDB } = require("@truffle/db"); | ||
const Config = require("@truffle/config"); | ||
|
||
const port = 4444; | ||
|
||
const config = Config.detect({ | ||
workingDirectory: process.argv[2] || process.cwd() | ||
}); | ||
|
||
const db = new TruffleDB(config); | ||
|
||
const { schema, context } = db; | ||
|
||
const server = new ApolloServer({ | ||
tracing: true, | ||
schema, | ||
context | ||
}); | ||
|
||
server.listen({ port }).then(({ url }) => { | ||
console.log(`🚀 Server ready at ${url}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"compilerOptions": { | ||
"sourceMap": true, | ||
"declaration": true, | ||
"esModuleInterop": true, | ||
"lib": ["esnext", "dom"], | ||
"target": "es6", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"module": "commonjs", | ||
"outDir": "../dist", | ||
"strictBindCallApply": true, | ||
"paths": { | ||
"@truffle/db": ["../src"], | ||
"@truffle/db/*": ["../src/*"], | ||
"test/*": ["../test/*"] | ||
}, | ||
"rootDir": "..", | ||
"baseUrl": ".", | ||
"types": [ | ||
"express", | ||
"jest", | ||
"node", | ||
"pouchdb" | ||
] | ||
}, | ||
"include": [ | ||
"src/**/*", | ||
"test/**/*" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{ | ||
"name": "@truffle/db", | ||
"version": "0.1.0-0", | ||
"description": "Smart contract data aggregation", | ||
"keywords": [ | ||
"truffle", | ||
"smart-contracts", | ||
"ethereum", | ||
"database" | ||
], | ||
"author": "g. nicholas d'andrea <gnidan@users.noreply.github.com>", | ||
"homepage": "https://github.com/trufflesuite/truffle#readme", | ||
"license": "MIT", | ||
"main": "dist/src/index.js", | ||
"directories": { | ||
"dist": "dist" | ||
}, | ||
"files": [ | ||
"dist", | ||
"types/schema.d.ts" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/trufflesuite/truffle.git" | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf ./dist ./types/schema.d.ts", | ||
"prepare": "yarn build", | ||
"build": "./bin/build", | ||
"start": "ts-node-dev -r tsconfig-paths/register ./bin/server", | ||
"start:debug": "DEBUG=pouchdb:api ts-node-dev -r tsconfig-paths/register ./bin/server", | ||
"start:drizzle": "ts-node-dev -r tsconfig-paths/register ./bin/server ./test/truffle-projects/drizzle-box", | ||
"start:drizzle:debug": "DEBUG=pouchdb:api ts-node-dev -r tsconfig-paths/register ./bin/server ./test/truffle-projects/drizzle-box", | ||
"test": "jest --verbose --detectOpenHandles" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/trufflesuite/truffle/issues" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.16.0", | ||
"@types/graphql": "^14.0.4", | ||
"@types/jest": "^23.3.11", | ||
"@types/node": "^10.12.18", | ||
"@types/pouchdb": "^6.3.2", | ||
"@types/pouchdb-adapter-leveldb": "^6.1.3", | ||
"@types/web3": "1.0.20", | ||
"ganache-core": "2.8.0", | ||
"gql2ts": "^1.10.1", | ||
"jest": "^23.6.0", | ||
"jsondown": "^1.0.0", | ||
"ts-jest": "^23.10.5", | ||
"ts-node-dev": "^1.0.0-pre.32", | ||
"tsconfig-paths": "^3.7.0", | ||
"typescript": "^3.6.3" | ||
}, | ||
"dependencies": { | ||
"@gnd/graphql-tools": "^4.0.5-fix.0", | ||
"@gnd/jsonschema2graphql": "^1.0.15", | ||
"@truffle/artifactor": "^4.0.74", | ||
"@truffle/compile-common": "^0.3.10", | ||
"@truffle/workflow-compile": "^3.0.0", | ||
"apollo-server": "^2.3.1", | ||
"fse": "^4.0.1", | ||
"graphql": "^14.0.2", | ||
"graphql-tag": "^2.10.1", | ||
"jsondown": "^1.0.0", | ||
"leveldown": "^5.2.0", | ||
"module-alias": "^2.1.0", | ||
"pascal-case": "^2.0.1", | ||
"pouchdb": "7.1.1", | ||
"pouchdb-adapter-memory": "^7.1.1", | ||
"pouchdb-adapter-node-websql": "^7.0.0", | ||
"pouchdb-debug": "^7.1.1", | ||
"pouchdb-find": "^7.0.0", | ||
"source-map-support": "^0.5.9", | ||
"web3": "1.2.2", | ||
"web3-utils": "1.2.2" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"js", | ||
"json", | ||
"node" | ||
], | ||
"testEnvironment": "node", | ||
"transform": { | ||
"^.+\\.ts$": "ts-jest" | ||
}, | ||
"globals": { | ||
"ts-jest": { | ||
"tsConfig": "<rootDir>/tsconfig.json", | ||
"diagnostics": true | ||
} | ||
}, | ||
"moduleNameMapper": { | ||
"^@truffle/db/(.*)": "<rootDir>/src/$1", | ||
"^@truffle/db$": "<rootDir>/src", | ||
"^test/(.*)": "<rootDir>/test/$1" | ||
}, | ||
"testMatch": [ | ||
"<rootDir>/src/**/test/index.(ts|js)", | ||
"<rootDir>/test/**/test/index.(ts|js)", | ||
"<rootDir>/src/**/test/*\\.(spec|test)\\.(ts|js)", | ||
"<rootDir>/test/**/test/*\\.(spec|test)\\.(ts|js)" | ||
] | ||
}, | ||
"_moduleAliases": { | ||
"@truffle/db": "db/dist/src" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { abiSchema } from "./json"; | ||
export { schema } from "./schema"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { schema, abiSchema } from "./schema"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import * as fse from "fs-extra"; | ||
import { Shims } from "@truffle/compile-common"; | ||
|
||
const TruffleResolver = require("@truffle/resolver"); | ||
|
||
export interface ITruffleResolver { | ||
require(name: string): any; | ||
} | ||
|
||
interface IContext { | ||
artifactsDirectory: string; | ||
workingDirectory?: string; | ||
} | ||
|
||
export const resolvers = { | ||
Query: { | ||
contract: { | ||
resolve(_, { name, networkId }, context: IContext) { | ||
const truffleResolver: ITruffleResolver = new TruffleResolver({ | ||
contracts_build_directory: context.artifactsDirectory, | ||
working_directory: context.workingDirectory || process.cwd() | ||
}); | ||
|
||
const artifact = truffleResolver.require(name)._json; | ||
|
||
const linkedBytecodeCreate = Shims.LegacyToNew.forBytecode( | ||
artifact.bytecode | ||
); | ||
const linkedBytecodeCall = Shims.LegacyToNew.forBytecode( | ||
artifact.deployedBytecode | ||
); | ||
|
||
const result = { | ||
...artifact, | ||
|
||
abi: { | ||
json: JSON.stringify(artifact.abi) | ||
}, | ||
ast: { | ||
json: JSON.stringify(artifact.ast) | ||
}, | ||
source: { | ||
contents: artifact.source, | ||
sourcePath: artifact.sourcePath | ||
}, | ||
bytecode: { | ||
bytes: linkedBytecodeCreate.bytes, | ||
linkReferences: linkedBytecodeCreate.linkReferences | ||
}, | ||
deployedBytecode: { | ||
bytes: linkedBytecodeCall.bytes, | ||
linkReferences: linkedBytecodeCall.linkReferences | ||
}, | ||
sourceMap: { | ||
json: JSON.stringify(artifact.sourceMap) | ||
} | ||
}; | ||
|
||
if (networkId) { | ||
return result.networks[networkId] | ||
? { | ||
...result, | ||
networks: { | ||
[networkId]: result.networks[networkId] | ||
} | ||
} | ||
: null; | ||
} | ||
return result; | ||
} | ||
}, | ||
contractNames: { | ||
resolve(_, {}, context: IContext): string[] { | ||
const contents = fse.readdirSync(context.artifactsDirectory); | ||
|
||
return contents | ||
.filter(filename => filename.endsWith(".json")) | ||
.map(filename => filename.slice(0, -5)); | ||
} | ||
} | ||
}, | ||
|
||
ContractObject: { | ||
networks: { | ||
resolve({ networks }) { | ||
return Object.entries(networks).map(([networkId, networkObject]) => ({ | ||
networkId, | ||
networkObject | ||
})); | ||
} | ||
} | ||
} | ||
}; |
Oops, something went wrong.