|
| 1 | +/// <reference types="node" /> |
| 2 | +/// <reference types="winston" /> |
| 3 | +/// <reference types="@accordproject/concerto-core" /> |
| 4 | + |
| 5 | +import { Logger, LeveledLogMethod } from 'winston'; |
| 6 | +import { BaseFileException, Factory, Introspector, ModelManager, Serializer } from '@accordproject/concerto-core' |
| 7 | + |
| 8 | +// Winston logger |
| 9 | + |
| 10 | +declare module 'winston' { |
| 11 | + interface Logger { |
| 12 | + setup(fn: (process: any, env: string, logDir: string) => void): void; |
| 13 | + entry: LeveledLogMethod; |
| 14 | + exit: LeveledLogMethod; |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +// Utils |
| 19 | + |
| 20 | +declare namespace Util { |
| 21 | + function momentToJson(): any; |
| 22 | + function setCurrentTime(currentTime: string): any; |
| 23 | +} |
| 24 | + |
| 25 | +// Version |
| 26 | + |
| 27 | +declare const version: string |
| 28 | + |
| 29 | +// Exceptions |
| 30 | + |
| 31 | +declare interface FileLocation { |
| 32 | + start: { line: number, column: number }; |
| 33 | + end: { line: number, column: number }; |
| 34 | +} |
| 35 | + |
| 36 | +declare class CompilerException extends BaseFileException { |
| 37 | + constructor(message: string, fileLocation?: FileLocation, fullMessage?: string, fileName?: string, component?: string); |
| 38 | +} |
| 39 | + |
| 40 | +declare class TypeException extends CompilerException { |
| 41 | + constructor(message: string, fileLocation?: FileLocation, fullMessage?: string, fileName?: string, component?: string); |
| 42 | +} |
| 43 | + |
| 44 | +// Target |
| 45 | + |
| 46 | +declare type Target = 'cicero' | 'es5' | 'es6' | 'java'; |
| 47 | + |
| 48 | +// Source |
| 49 | + |
| 50 | +declare interface Source { |
| 51 | + name: string; |
| 52 | + content: string; |
| 53 | +} |
| 54 | + |
| 55 | +// Ergo Input |
| 56 | +declare interface Input { |
| 57 | + $class: string; |
| 58 | +} |
| 59 | + |
| 60 | +// AP Model Manager |
| 61 | + |
| 62 | +declare abstract class APModelManager extends ModelManager { |
| 63 | + getModels(): { name: string; content: string; }[]; |
| 64 | +} |
| 65 | + |
| 66 | +// Function Declaration |
| 67 | + |
| 68 | +declare class FunctionDeclaration { |
| 69 | + constructor( |
| 70 | + modelManager: ModelManager, |
| 71 | + language: string, |
| 72 | + name: string, |
| 73 | + visibility: string, |
| 74 | + returnType: string, |
| 75 | + throws: string, |
| 76 | + parameterNames: string[], |
| 77 | + parameterTypes: string[], |
| 78 | + decorators: string[], |
| 79 | + functionText: string |
| 80 | + ); |
| 81 | + getFunctionText(): string; |
| 82 | + getThrows(): string; |
| 83 | + getLanguage(): string; |
| 84 | + getDecorators(): string[]; |
| 85 | + getVisibility(): string; |
| 86 | + getReturnType(): string; |
| 87 | + getName(): string; |
| 88 | + getParameterNames(): string[]; |
| 89 | + getParameterTypes(): string[]; |
| 90 | +} |
| 91 | + |
| 92 | +// Script |
| 93 | + |
| 94 | +declare class Script { |
| 95 | + constructor( |
| 96 | + modelManager: ModelManager, |
| 97 | + identifier: string, |
| 98 | + language: string, |
| 99 | + contents: string, |
| 100 | + contractName: string |
| 101 | + ); |
| 102 | + getIdentifier(): string; |
| 103 | + getContractName(): string; |
| 104 | + getLanguage(): string; |
| 105 | + getContents(): string; |
| 106 | + getFunctionDeclarations(): FunctionDeclaration[]; |
| 107 | + getTokens(): any[]; |
| 108 | +} |
| 109 | + |
| 110 | +// ScriptManager |
| 111 | + |
| 112 | +declare interface ScriptManagerOptions { |
| 113 | + warnings?: boolean |
| 114 | +} |
| 115 | + |
| 116 | +declare class ScriptManager { |
| 117 | + constructor(target: Target, modelManager: ModelManager, options: ScriptManagerOptions); |
| 118 | + changeTarget(target: Target, recompile: boolean): void; |
| 119 | + createScript(identifier: string, language: string, contents: string): Script; |
| 120 | + modifyScript(identifier: string, language: string, contents: string): void; |
| 121 | + addTemplateFile(templateFile: string, fileName: string): void |
| 122 | + addScript(script: Script): void; |
| 123 | + updateScript(script: Script): void; |
| 124 | + deleteScript(identifier: string): void; |
| 125 | + getScripts(): Script[]; |
| 126 | + getAllScripts(): Script[]; |
| 127 | + getCombinedScripts(): string; |
| 128 | + getTargetKind(target: Target): '.js' | '.ergo' | '.java'; |
| 129 | + getScriptsForTarget(target: Target): Script[]; |
| 130 | + getLogic(): Source[]; |
| 131 | + clearScripts(): void; |
| 132 | + private getScript(identifier: string): Script; |
| 133 | + private getCompiledScript(): Script; |
| 134 | + private getCompiledJavaScript(): string; |
| 135 | + getScriptIdentifiers(): string[]; |
| 136 | + compileLogic(force: boolean): Script; |
| 137 | + allFunctionDeclarations(): FunctionDeclaration[]; |
| 138 | + hasFunctionDeclaration(name: string): void; |
| 139 | + hasDispatch(): void; |
| 140 | + hasInit(): void; |
| 141 | + |
| 142 | + static _throwCompilerException(error: any): void; |
| 143 | +} |
| 144 | + |
| 145 | +// Logic Manager |
| 146 | + |
| 147 | +declare interface LogicManagerOptions { |
| 148 | + warnings?: boolean |
| 149 | +} |
| 150 | + |
| 151 | +declare class LogicManager { |
| 152 | + constructor(target: Target, options: LogicManagerOptions); |
| 153 | + getTarget(): Target; |
| 154 | + setTarget(target: Target, recompile: boolean): void; |
| 155 | + setContractName(contractName: string): void; |
| 156 | + getContractName(): string; |
| 157 | + private getDispatchCall(): string; |
| 158 | + private getInvokeCall(clauseName: string): string |
| 159 | + getIntrospector(): Introspector; |
| 160 | + getFactory(): Factory; |
| 161 | + getSerializer(): Serializer; |
| 162 | + getScriptManager(): ScriptManager; |
| 163 | + getModelManager(): ModelManager; |
| 164 | + addLogicFile(logicFile: string, fileName: string): void; |
| 165 | + addTemplateFile(modelFile: string, fileName: string): void; |
| 166 | + addModelFile(modelFile: string, fileName: string): void; |
| 167 | + addModelFiles(modelFiles: string[], modelFileNames?: string[]): void; |
| 168 | + validateModelFiles(): void; |
| 169 | + registerCompiledLogicSync(): void; |
| 170 | + compileLogicSync(force: boolean): Script; |
| 171 | + compileLogic(force: boolean): Promise<void>; |
| 172 | + addErgoBuiltin(): void; |
| 173 | + validateInput(input: any): any; |
| 174 | + validateContract(contract: any, options: any): any; |
| 175 | + validateInputRecord(input: any): any; |
| 176 | + validateOutput(output: any): any; |
| 177 | + validateOutputArray(outputArray: any[]): any[]; |
| 178 | + updateModel(content: string, name: string): void; |
| 179 | + updateLogic(content: string, name: string): void; |
| 180 | +} |
| 181 | + |
| 182 | +// Compiler |
| 183 | + |
| 184 | +declare class Compiler { |
| 185 | + static parseCTOtoJSON(ctoContent: string): any; |
| 186 | + static contractCallName(contractName: string): string; |
| 187 | + static contractCallNamePromise(contractName: string): string; |
| 188 | + |
| 189 | + static compileToJavaScript( |
| 190 | + ergoSources: Source[], |
| 191 | + ctoSources: Source[], |
| 192 | + target: string, |
| 193 | + link: boolean, |
| 194 | + warnings: boolean |
| 195 | + ): string; |
| 196 | + |
| 197 | + static compile( |
| 198 | + ergoSources: Source[], |
| 199 | + ctoSources: Source[], |
| 200 | + target: string, |
| 201 | + link: boolean, |
| 202 | + warnings: boolean |
| 203 | + ): any; |
| 204 | + |
| 205 | + static ergoErrorToString(error: any): string; |
| 206 | + static ergoVerboseErrorToString(error: any): string; |
| 207 | + static availableTargets(): string[]; |
| 208 | + static isValidTarget(target: string): boolean; |
| 209 | +} |
| 210 | + |
| 211 | +// File Loader |
| 212 | + |
| 213 | +declare class FileLoader { |
| 214 | + static loadZipFileContents(zip: any, path: string, json?: boolean, required?: boolean): Promise<string>; |
| 215 | + static loadZipFilesContents(zip: any, regex: RegExp): Promise<any[]>; |
| 216 | + static loadZipFileBuffer(zip: any, path: string, required?: boolean): Promise<Buffer>; |
| 217 | + static loadFileContents(path: string, fileName: string, json?: boolean, required?: boolean): Promise<string>; |
| 218 | + static loadFileBuffer(path: string, fileName: string, required?: boolean): Promise<Buffer>; |
| 219 | + static loadFilesContents(path: string, regex: RegExp): Promise<any[]> |
| 220 | + static normalizeNLs(input: string): string; |
| 221 | +} |
| 222 | + |
| 223 | +// Ergo Loader |
| 224 | + |
| 225 | +declare class ErgoLoader { |
| 226 | + static fromDirectory(path: string, options: LogicManagerOptions): Promise<LogicManager>; |
| 227 | + static fromZip(buffer: Buffer, options: LogicManagerOptions): Promise<LogicManager>; |
| 228 | + static fromFiles(files: string[], options: LogicManagerOptions): Promise<LogicManager>; |
| 229 | +} |
| 230 | + |
| 231 | +// Exports |
| 232 | + |
| 233 | +export { |
| 234 | + TypeException, |
| 235 | + CompilerException, |
| 236 | + APModelManager, |
| 237 | + ScriptManager, |
| 238 | + LogicManager, |
| 239 | + Compiler, |
| 240 | + FileLoader, |
| 241 | + ErgoLoader, |
| 242 | + Util, |
| 243 | + Logger, |
| 244 | + version, |
| 245 | +} |
| 246 | + |
| 247 | +declare module '@accordproject/ergo-compiler' { |
| 248 | + export { |
| 249 | + TypeException, |
| 250 | + CompilerException, |
| 251 | + APModelManager, |
| 252 | + ScriptManager, |
| 253 | + LogicManager, |
| 254 | + Compiler, |
| 255 | + FileLoader, |
| 256 | + ErgoLoader, |
| 257 | + Util, |
| 258 | + Logger, |
| 259 | + version, |
| 260 | + } |
| 261 | +} |
0 commit comments