-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb539f1
commit bbdcff1
Showing
9 changed files
with
550 additions
and
188 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
import { | ||
Aqua, | ||
Call, | ||
Path, | ||
} from "@fluencelabs/aqua-api/aqua-api.js"; | ||
//@ts-check | ||
|
||
const aquaPath = new Path("test.aqua") | ||
// write function that we want to call and arguments | ||
const args = {num: 42} | ||
const call = new Call("getNumber(num)", args, aquaPath) | ||
import compile from '@fluencelabs/aqua-api' | ||
|
||
// compile call | ||
const compilationResult = await Aqua.compile(call, []) | ||
const compilationResult = await compile({ | ||
filePath: 'test.aqua', | ||
data: { num: 3 }, | ||
funcCall: 'getNumber(num)', | ||
}) | ||
|
||
const { | ||
errors, | ||
functionCall: { funcDef, script }, | ||
functions, | ||
generatedSources, | ||
services, | ||
} = compilationResult | ||
|
||
/* | ||
// Compilation result definition | ||
export class CompilationResult { | ||
// List of service definitions to register in Fluence JS Client | ||
services: Record<string, ServiceDef> | ||
// List of function definitions to call in Fluence JS Client | ||
functions: Record<string, AquaFunction> | ||
// Definition of wrapped function to call in Fluence JS Client | ||
functionCall?: AquaFunction | ||
// List of errors. All other fields will be empty if `errors` not empty | ||
errors: string[] | ||
} | ||
*/ | ||
|
||
// get function definition, that describes types of arguments and results of a function | ||
// and AIR script | ||
const {funcDef, script} = compilationResult.functionCall | ||
console.log(script) |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,67 +1,69 @@ | ||
import type { FunctionCallDef, ServiceDef } from "@fluencelabs/fluence/dist/internal/compilerSupport/v3impl/interface" | ||
import type { FunctionCallDef, ServiceDef } from "@fluencelabs/interfaces"; | ||
|
||
export class AquaConfig { | ||
constructor( | ||
logLevel?: string, | ||
constants?: string[], | ||
noXor?: boolean, | ||
noRelay?: boolean, | ||
targetType?: string, | ||
tracing?: boolean | ||
); | ||
constructor( | ||
logLevel?: string, | ||
constants?: string[], | ||
noXor?: boolean, | ||
noRelay?: boolean, | ||
targetType?: string, | ||
tracing?: boolean, | ||
); | ||
|
||
logLevel?: string | ||
constants?: string[] | ||
noXor?: boolean | ||
noRelay?: boolean | ||
targetType?: string | ||
tracing?: boolean | ||
logLevel?: string; | ||
constants?: string[]; | ||
noXor?: boolean; | ||
noRelay?: boolean; | ||
targetType?: string; | ||
tracing?: boolean; | ||
} | ||
|
||
export class AquaFunction { | ||
funcDef: FunctionCallDef | ||
script: string | ||
funcDef: FunctionCallDef; | ||
script: string; | ||
} | ||
|
||
export class GeneratedSource { | ||
name: string | ||
tsSource?: string | ||
jsSource?: string | ||
tsTypes?: string | ||
name: string; | ||
tsSource?: string; | ||
jsSource?: string; | ||
tsTypes?: string; | ||
} | ||
|
||
export class CompilationResult { | ||
services: Record<string, ServiceDef> | ||
functions: Record<string, AquaFunction> | ||
functionCall?: AquaFunction | ||
errors: string[] | ||
generatedSources: GeneratedSource[] | ||
services: Record<string, ServiceDef>; | ||
functions: Record<string, AquaFunction>; | ||
functionCall?: AquaFunction; | ||
errors: string[]; | ||
generatedSources: GeneratedSource[]; | ||
} | ||
|
||
export class Input { | ||
constructor(input: string); | ||
constructor(input: string); | ||
|
||
input: string | ||
input: string; | ||
} | ||
|
||
export class Path { | ||
constructor(path: string); | ||
constructor(path: string); | ||
|
||
path: string | ||
path: string; | ||
} | ||
|
||
export class Call { | ||
constructor(functionCall: string, | ||
arguments: any, | ||
input: Input | Path); | ||
constructor(functionCall: string, arguments: any, input: Input | Path); | ||
|
||
functionCall: string | ||
arguments: any | ||
input: Input | Path | ||
functionCall: string; | ||
arguments: any; | ||
input: Input | Path; | ||
} | ||
|
||
export class Compiler { | ||
compile(input: Input | Path | Call, imports: string[], config?: AquaConfig): Promise<CompilationResult>; | ||
compile( | ||
input: Input | Path | Call, | ||
imports: string[], | ||
config?: AquaConfig, | ||
): Promise<CompilationResult>; | ||
} | ||
|
||
export var Aqua: Compiler; |
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,39 @@ | ||
import { CompilationResult } from "./aqua-api"; | ||
|
||
type CommonArgs = { | ||
imports?: string[] | undefined; | ||
constants?: string[] | undefined; | ||
logLevel?: string | undefined; | ||
noRelay?: boolean | undefined; | ||
noXor?: boolean | undefined; | ||
targetType?: "ts" | "js" | "air"; | ||
tracing?: boolean | undefined; | ||
}; | ||
|
||
/** | ||
* Compile aqua code | ||
* | ||
* There are 3 ways to call the function: | ||
* | ||
* 1. Compile aqua code from string (use `code` field) | ||
* 1. Compile aqua code from file (use `filePath` field) | ||
* 1. Compile aqua function call from file (use `filePath`, `funcCall` and, optionally `data` fields) | ||
*/ | ||
declare function compile( | ||
arg: { | ||
code: string; | ||
} & CommonArgs, | ||
): Promise<CompilationResult>; | ||
declare function compile( | ||
arg: { | ||
filePath: string; | ||
} & CommonArgs, | ||
): Promise<CompilationResult>; | ||
declare function compile( | ||
arg: { | ||
filePath: string; | ||
funcCall: string; | ||
data?: Record<string, unknown> | undefined; | ||
} & CommonArgs, | ||
): Promise<Required<CompilationResult>>; | ||
export = compile; |
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,47 @@ | ||
// @ts-check | ||
const { AquaConfig, Aqua, Call, Input, Path } = require("./aqua-api.js"); | ||
|
||
async function compile({ | ||
funcCall, | ||
code, | ||
filePath, | ||
data = {}, | ||
imports = [], | ||
constants = [], | ||
logLevel = "info", | ||
noRelay = false, | ||
noXor = false, | ||
targetType = "air", | ||
tracing = false, | ||
}) { | ||
const config = new AquaConfig( | ||
logLevel, | ||
constants, | ||
noXor, | ||
noRelay, | ||
{ | ||
ts: "typescript", | ||
js: "javascript", | ||
air: "air", | ||
}[targetType], | ||
tracing, | ||
); | ||
|
||
if (typeof funcCall === "string" && filePath !== undefined) { | ||
const result = await Aqua.compile( | ||
new Call(funcCall, data, new Input(filePath)), | ||
imports, | ||
config, | ||
); | ||
|
||
return result; | ||
} | ||
|
||
if (typeof code === "string") { | ||
return Aqua.compile(new Input(code), imports, config); | ||
} | ||
|
||
return Aqua.compile(new Path(filePath), imports, config); | ||
} | ||
|
||
module.exports = compile; |
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
Oops, something went wrong.