Skip to content

Instantly share code, notes, and snippets.

@mhoangvslev
Last active June 26, 2019 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhoangvslev/3c39a887ff12e4604a88d56a69c4e21c to your computer and use it in GitHub Desktop.
Save mhoangvslev/3c39a887ff12e4604a88d56a69c4e21c to your computer and use it in GitHub Desktop.
import { ethers } from "ethers";
export declare interface Strategies {
DataExtractionStrategy: DataExtractionStrategies;
PersistenceStrategy: PersistenceStrategies;
}
export interface DataExtractionStrategies { [iteration: number]: DataExtractionStrategy; }
export declare interface DataExtractionStrategy {
propName: string;
strategy: ContractCall | FromData;
}
export interface Strategy {
process?: Process;
}
export interface ContractCall extends Strategy {
funcName: string;
args: { [eidsAttr: string]: CallbackFunction };
resAttr?: string;
}
export declare interface FromData extends Strategy {
attrName: string;
}
interface Bucket<T> {
[name: string]: T;
}
type CallbackFunction = (data: any) => any;
export type Process = (data: any, contractFunctions: Bucket<ethers.ContractFunction>) => Promise<any>;
export declare interface PersistenceStrategies {
NodeStrategies: { [iteration: number]: NodeStrategy };
RelationshipStrategies: { [iteration: number]: RelationshipStrategy };
}
export declare interface RelationshipStrategy {
relType: string;
relAlias: string;
direction: string;
source: string;
target: string;
createStrategy: CreateStrategy;
}
export declare interface NodeStrategy {
nodeType: string;
nodeAlias: string;
mergeStrategy: MergeStrategy;
createStrategy: CreateStrategy;
}
// For each dbProp, use an entry from the extracted data struct
export interface MergeStrategy { [dbProp: string]: string; }
export interface CreateStrategy { [dbProp: string]: string; }
export async function defaultDataProcess(data: any, contractFunctions: Bucket<ethers.ContractFunction>) {
return data.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment