mirror of
https://github.com/fluencelabs/aqua.git
synced 2025-06-24 12:01:34 +00:00
feat: wrap aqua api (#807)
This commit is contained in:
76
api/api-npm/aqua-api.d.ts
vendored
76
api/api-npm/aqua-api.d.ts
vendored
@ -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;
|
||||
|
50
api/api-npm/index.d.ts
vendored
Normal file
50
api/api-npm/index.d.ts
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
import { type CompilationResult } from "./aqua-api.js";
|
||||
|
||||
/** Common arguments for all compile functions */
|
||||
type CommonArgs = {
|
||||
/** Paths to directories, which you want to import .aqua files from. Example: ["./path/to/dir"] */
|
||||
imports?: string[] | undefined;
|
||||
/** Constants to be passed to the compiler. Example: ["CONSTANT1=1", "CONSTANT2=2"] */
|
||||
constants?: string[] | undefined;
|
||||
/** Set log level for the compiler. Must be one of: Must be one of: all, trace, debug, info, warn, error, off. Default: info */
|
||||
logLevel?: string | undefined;
|
||||
/** Do not generate a pass through the relay node. Default: false */
|
||||
noRelay?: boolean | undefined;
|
||||
/** Do not generate a wrapper that catches and displays errors. Default: false */
|
||||
noXor?: boolean | undefined;
|
||||
/** Target type for the compiler. Must be one of: ts, js, air. Default: air */
|
||||
targetType?: "ts" | "js" | "air" | undefined;
|
||||
/** Compile aqua in tracing mode (for debugging purposes). Default: false */
|
||||
tracing?: boolean | undefined;
|
||||
};
|
||||
|
||||
type CodeString = {
|
||||
/** Aqua code to be compiled */
|
||||
code: string;
|
||||
}
|
||||
|
||||
/** Compile aqua code from a string */
|
||||
export declare function compileFromString(args: CommonArgs & CodeString): Promise<Omit<CompilationResult, 'funcCall'>>
|
||||
|
||||
type FilePath = {
|
||||
/** Path to the aqua file to be compiled */
|
||||
filePath: string;
|
||||
}
|
||||
|
||||
/** Compile aqua code from a file */
|
||||
export declare function compileFromPath(args: CommonArgs & FilePath): Promise<Omit<CompilationResult, 'funcCall'>>
|
||||
|
||||
type FuncCall = {
|
||||
/** Function call you want to compile. Example: someFunc("someArg") */
|
||||
funcCall: string;
|
||||
/** Args to be passed to the function (record with keys named as args you want to pass to the function) Example: { someArg: 1 } */
|
||||
data?: Record<string, unknown> | undefined;
|
||||
}
|
||||
|
||||
/** Compile aqua function call from a string */
|
||||
export declare function compileAquaCallFromString(args: CommonArgs & CodeString & FuncCall): Promise<Required<CompilationResult>>
|
||||
|
||||
/** Compile aqua function call from a file */
|
||||
export declare function compileAquaCallFromPath(args: CommonArgs & FilePath & FuncCall): Promise<Required<CompilationResult>>
|
||||
|
||||
export {}
|
66
api/api-npm/index.js
Normal file
66
api/api-npm/index.js
Normal file
@ -0,0 +1,66 @@
|
||||
// @ts-check
|
||||
import { AquaConfig, Aqua, Call, Input, Path } from "./aqua-api.js";
|
||||
|
||||
function getConfig({
|
||||
constants = [],
|
||||
logLevel = "info",
|
||||
noRelay = false,
|
||||
noXor = false,
|
||||
targetType = "air",
|
||||
tracing = false,
|
||||
}) {
|
||||
return new AquaConfig(
|
||||
logLevel,
|
||||
constants,
|
||||
noXor,
|
||||
noRelay,
|
||||
{
|
||||
ts: "typescript",
|
||||
js: "javascript",
|
||||
air: "air",
|
||||
}[targetType],
|
||||
tracing,
|
||||
);
|
||||
}
|
||||
|
||||
export function compileFromString({ code, ...commonArgs }) {
|
||||
const config = getConfig(commonArgs);
|
||||
const { imports = [] } = commonArgs;
|
||||
return Aqua.compile(new Input(code), imports, config);
|
||||
}
|
||||
|
||||
export function compileFromPath({ filePath, ...commonArgs }) {
|
||||
const config = getConfig(commonArgs);
|
||||
const { imports = [] } = commonArgs;
|
||||
return Aqua.compile(new Path(filePath), imports, config);
|
||||
}
|
||||
|
||||
export function compileAquaCallFromString({
|
||||
code,
|
||||
funcCall,
|
||||
data,
|
||||
...commonArgs
|
||||
}) {
|
||||
const config = getConfig(commonArgs);
|
||||
const { imports = [] } = commonArgs;
|
||||
return Aqua.compile(
|
||||
new Call(funcCall, data, new Input(code)),
|
||||
imports,
|
||||
config,
|
||||
);
|
||||
}
|
||||
|
||||
export function compileAquaCallFromPath({
|
||||
filePath,
|
||||
funcCall,
|
||||
data,
|
||||
...commonArgs
|
||||
}) {
|
||||
const config = getConfig(commonArgs);
|
||||
const { imports = [] } = commonArgs;
|
||||
return Aqua.compile(
|
||||
new Call(funcCall, data, new Input(filePath)),
|
||||
imports,
|
||||
config,
|
||||
);
|
||||
}
|
@ -2,12 +2,16 @@
|
||||
"name": "@fluencelabs/aqua-api",
|
||||
"version": "0.11.8",
|
||||
"description": "Aqua API",
|
||||
"type": "commonjs",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"aqua-api.js",
|
||||
"aqua-api.d.ts",
|
||||
"meta-utils.js"
|
||||
],
|
||||
"prettier": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/fluencelabs/aqua.git"
|
||||
@ -23,6 +27,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/fluencelabs/aqua#readme",
|
||||
"devDependencies": {
|
||||
"@fluencelabs/fluence": "0.28.0"
|
||||
"@fluencelabs/interfaces": "^0.8.0",
|
||||
"prettier": "3.0.0"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user