Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

Commit ade5700

Browse files
committed
types definitions
Signed-off-by: Giacomo Minighin <[email protected]>
1 parent e297da1 commit ade5700

File tree

7 files changed

+353
-10
lines changed

7 files changed

+353
-10
lines changed

package-lock.json

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ergo-compiler/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
"url": "https://github.com/accordproject/ergo"
88
},
99
"main": "index.js",
10+
"typings": "types/index.d.ts",
1011
"scripts": {
1112
"pretest": "npm run lint",
1213
"lint": "eslint .",
1314
"postlint": "npm run licchk",
1415
"licchk": "license-check",
1516
"test": "mocha",
16-
"test:cov": "nyc npm run test"
17+
"test:cov": "nyc npm run test",
18+
"types:check": "tsc -p types/tsconfig.json"
1719
},
1820
"contributors": [
1921
{
@@ -38,6 +40,7 @@
3840
"winston": "3.2.1"
3941
},
4042
"devDependencies": {
43+
"@types/node": "^14.14.6",
4144
"chai": "4.2.0",
4245
"chai-as-promised": "7.1.1",
4346
"chai-things": "0.2.0",
@@ -47,7 +50,8 @@
4750
"mocha": "5.2.0",
4851
"nyc": "13.3.0",
4952
"sinon": "6.3.5",
50-
"sinon-chai": "3.2.0"
53+
"sinon-chai": "3.2.0",
54+
"typescript": "^4.0.5"
5155
},
5256
"license-check-config": {
5357
"src": [
@@ -88,4 +92,4 @@
8892
"lines": 93
8993
},
9094
"gitHead": "bf65386e8590dff56f8b9bc0bb657263ff049437"
91-
}
95+
}
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
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+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"moduleResolution": "node",
4+
"noEmit": true,
5+
}
6+
}

packages/ergo-engine/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"url": "https://github.com/accordproject/ergo"
88
},
99
"main": "index.js",
10+
"typings": "types/index.d.ts",
1011
"scripts": {
1112
"webpack": "webpack --config webpack.config.js --mode production",
1213
"prepublishOnly": "npm run webpack",
@@ -15,7 +16,8 @@
1516
"postlint": "npm run licchk",
1617
"licchk": "license-check",
1718
"test": "mocha",
18-
"test:cov": "nyc npm run test"
19+
"test:cov": "nyc npm run test",
20+
"types:check": "tsc -p types/tsconfig.json"
1921
},
2022
"contributors": [
2123
{
@@ -54,6 +56,7 @@
5456
"mocha": "5.2.0",
5557
"nyc": "13.3.0",
5658
"raw-loader": "0.5.1",
59+
"typescript": "^4.0.5",
5760
"webpack": "4.16.3",
5861
"webpack-cli": "3.1.0"
5962
},
@@ -92,4 +95,4 @@
9295
"lines": 93
9396
},
9497
"gitHead": "bf65386e8590dff56f8b9bc0bb657263ff049437"
95-
}
98+
}

0 commit comments

Comments
 (0)