fix: JS-client bugs and tech debt [fixes DXJ-520] (#374)

Fix various bugs and a pair of TODO's
This commit is contained in:
Akim
2023-11-06 17:42:24 +07:00
committed by GitHub
parent 2589e39113
commit b460491fbd
28 changed files with 121 additions and 210 deletions

View File

@ -16,7 +16,7 @@
import { promises as fs } from "fs";
import * as api from "@fluencelabs/aqua-api/aqua-api.js";
import { Path, Aqua } from "@fluencelabs/aqua-api/aqua-api.js";
import {
FunctionCallDef,
JSONArray,
@ -68,11 +68,16 @@ export type CompiledFile = {
services: { [key: string]: ServiceDef };
};
interface FunctionInfo {
script: string;
funcDef: FunctionCallDef;
}
export const compileAqua = async (aquaFile: string): Promise<CompiledFile> => {
await fs.access(aquaFile);
const compilationResult = await api.Aqua.compile(
new api.Path(aquaFile),
const compilationResult = await Aqua.compile(
new Path(aquaFile),
[],
undefined,
);
@ -84,12 +89,10 @@ export const compileAqua = async (aquaFile: string): Promise<CompiledFile> => {
}
const functions = Object.entries(compilationResult.functions)
.map(([name, fnInfo]) => {
.map(([name, fnInfo]: [string, FunctionInfo]) => {
const callFn = (peer: FluencePeer, args: PassedArgs) => {
return callAquaFunction({
// TODO: Set our compiler here and fix this
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
def: fnInfo.funcDef as FunctionCallDef,
def: fnInfo.funcDef,
script: fnInfo.script,
config: {},
peer: peer,
@ -105,9 +108,7 @@ export const compileAqua = async (aquaFile: string): Promise<CompiledFile> => {
return {
functions,
// TODO: set our compiler here and fix this
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
services: compilationResult.services as Record<string, ServiceDef>,
services: compilationResult.services,
};
};