feat: Create structs with stream maps [fixes LNG-244] (#893)

This commit is contained in:
Dima 2023-09-27 14:07:22 +02:00 committed by GitHub
parent b2ca1d35bf
commit 878990a837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
75 changed files with 1134 additions and 764 deletions

View File

@ -1,12 +1,26 @@
service Console("run-console"):
print(s: string)
aqua M
func main():
ss: *string
dd: *string
peerId = "peerId"
relay = "relay"
parsec s <- ss on peerId via relay:
Console.print(s)
for d <- dd par:
Console.print(d)
export getObj
service OpNum("op"):
identity(n: u32) -> u32
service OpStr("op"):
identity(n: string) -> string
service OpArr("op"):
identity(arr: []string) -> []string
data InnerObj:
arr: []string
num: u32
data SomeObj:
str: string
num: u64
inner: InnerObj
func getObj() -> SomeObj:
b = SomeObj(str = OpStr.identity("some str"), num = 5, inner = InnerObj(arr = ["a", "b", "c"], num = 6))
c = b.copy(str = "new str", inner = b.inner.copy(num = 3))
<- c

View File

@ -110,6 +110,8 @@ object Air {
case class Call(triplet: Triplet, args: List[DataView], result: Option[String])
extends Air(Keyword.Call)
case class ApStreamMap(key: DataView, op: DataView, result: String) extends Air(Keyword.Ap)
case class Ap(op: DataView, result: String) extends Air(Keyword.Ap)
case class Fail(op: DataView) extends Air(Keyword.Fail)
@ -147,6 +149,7 @@ object Air {
case Air.Call(triplet, args, res)
s" ${triplet.show} [${args.map(_.show).mkString(" ")}]${res.fold("")(" " + _)}"
case Air.Ap(operand, result) s" ${operand.show} $result"
case Air.ApStreamMap(key, operand, result) s" (${key.show} ${operand.show}) $result"
case Air.Fail(operand) => s" ${operand.show}"
case Air.Canon(operand, peerId, result) s" ${peerId.show} ${operand.show} $result"
case Air.Comment(_, _) => ";; Should not be displayed"

View File

@ -3,7 +3,7 @@ package aqua.backend.air
import aqua.model.*
import aqua.raw.ops.Call
import aqua.res.*
import aqua.types.{ArrayType, CanonStreamType, StreamType, Type}
import aqua.types.{ArrayType, CanonStreamType, StreamMapType, StreamType, Type}
import cats.Eval
import cats.data.Chain
import cats.free.Cofree
@ -30,6 +30,7 @@ object AirGen extends Logging {
(`type` match {
case _: StreamType => "$" + name
case _: CanonStreamType => "#" + name
case _: StreamMapType => "%" + name
case _ => name
}).replace('.', '_')
@ -54,10 +55,8 @@ object AirGen extends Logging {
}
def exportToString(exportTo: CallModel.Export): String = (exportTo match {
case CallModel.Export(name, _: StreamType) => "$" + name
case CallModel.Export(name, _: CanonStreamType) => "#" + name
case CallModel.Export(name, _) => name
}).replace('.', '_')
case CallModel.Export(name, t) => varNameToString(name, t)
})
private def folder(op: ResolvedOp, ops: Chain[AirGen]): Eval[AirGen] =
op match {
@ -113,6 +112,10 @@ object AirGen extends Logging {
)
)
case ApStreamMapRes(key, value, exportTo) =>
Eval.later(
ApStreamMapGen(valueToData(key), valueToData(value), exportToString(exportTo))
)
case ApRes(operand, exportTo) =>
Eval.later(
ApGen(valueToData(operand), exportToString(exportTo))
@ -163,6 +166,12 @@ case class CommentGen(comment: String, op: AirGen) extends AirGen {
Air.Comment(comment, op.generate)
}
case class ApStreamMapGen(key: DataView, operand: DataView, result: String) extends AirGen {
override def generate: Air =
Air.ApStreamMap(key, operand, result)
}
case class ApGen(operand: DataView, result: String) extends AirGen {
override def generate: Air =

View File

@ -56,7 +56,9 @@ object TypeScriptCommon {
case BottomType => "nothing"
// impossible. Made to avoid compilation warning
case t: CanonStreamType => "any"
case _: CanonStreamType => "any"
case _: StreamMapType => "any"
case _: ServiceType => "any"
}
// TODO: handle cases if there is already peer_ or config_ variable defined

View File

@ -1,6 +1,6 @@
aqua StructCreation declares getObj, getObjRelay, getObjAssign
export getObj, getObjRelay, getObjAssign
export getObj, getObjRelay, getObjAssign, getObjFor
import "@fluencelabs/aqua-lib/builtin.aqua"
@ -37,4 +37,26 @@ func getObjAssign() -> SomeObj, SomeObj, u32:
inner = InnerObj(arr = ["d", "e", "f"], num = 7)
)
copiedObj = obj.copy(str = "some str", inner = obj.inner.copy(arr = ["a", "b", "c"])).copy(num = 6)
<- obj, copiedObj, copiedObj.inner.copy(arr = ["g"]).arr.length
<- obj, copiedObj, copiedObj.inner.copy(arr = ["g"]).arr.length
func getObjFor() -> []SomeObj:
all: *SomeObj
arr = [
SomeObj(str = "first", num = OpNum.identity(1), inner = InnerObj(arr = ["1", "1", "1"], num = 11)),
SomeObj(str = "second", num = OpNum.identity(2), inner = InnerObj(arr = ["2", "2", "2"], num = 22)),
SomeObj(str = "third", num = OpNum.identity(3), inner = InnerObj(arr = ["3", "3", "3"], num = 33))
]
for obj <- arr:
copied = obj.copy(str = Op.concat_strings(obj.str, " copied"), inner = obj.inner.copy(arr = ["copy"]))
all <<- copied
arri = [1, 2, 3]
for i <- arri:
obj = SomeObj(str = "for", num = OpNum.identity(i), inner = InnerObj(arr = [], num = i))
all <<- obj
<- all

View File

@ -25,6 +25,7 @@
"compile-aqua": "ts-node ./src/compile.ts",
"compile-aqua:air": "aqua -i ./aqua/ -o ./compiled-air -a",
"prettify-compiled": "prettier --write src/compiled",
"prettify": "prettier --write src",
"aqua": "aqua",
"do": "aqua dist deploy --addr /dns4/kras-04.fluence.dev/tcp/19001/wss/p2p/12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi --config-path deploy.json --service tsOracle"
},
@ -33,6 +34,7 @@
"@fluencelabs/aqua-api": "0.12.2",
"@fluencelabs/aqua-dht": "0.2.5",
"@fluencelabs/aqua-lib": "0.7.3",
"prettier": "3.0.3",
"@types/jest": "29.5.2",
"@types/node": "18.11.18",
"jest": "29.5.0",

View File

@ -3,6 +3,7 @@ import {
getObjAssignCall,
getObjCall,
getObjRelayCall,
getObjForCall,
} from "../examples/objectCall.js";
import {
callArrowCall,
@ -358,6 +359,61 @@ describe("Testing examples", () => {
});
});
it("object creation in 'for' instruction getObjFor", async () => {
const result = await getObjForCall();
const res = [
{
str: "first copied",
num: 1,
inner: {
arr: ["copy"],
num: 11,
},
},
{
str: "second copied",
num: 2,
inner: {
arr: ["copy"],
num: 22,
},
},
{
str: "third copied",
num: 3,
inner: {
arr: ["copy"],
num: 33,
},
},
{
str: "for",
num: 1,
inner: {
arr: [],
num: 1,
},
},
{
str: "for",
num: 2,
inner: {
arr: [],
num: 2,
},
},
{
str: "for",
num: 3,
inner: {
arr: [],
num: 3,
},
},
];
expect(result).toEqual(res);
});
it("object creation getObjAssign", async () => {
let result = await getObjAssignCall();
expect(result).toEqual([

View File

@ -1,51 +1,73 @@
import { krasnodar, stage, testNet } from '@fluencelabs/fluence-network-environment';
import { local } from './local-nodes.js';
import {
krasnodar,
stage,
testNet,
} from "@fluencelabs/fluence-network-environment";
import { local } from "./local-nodes.js";
declare global {
namespace NodeJS {
interface ProcessEnv {
FLUENCE_ENV?: string;
}
namespace NodeJS {
interface ProcessEnv {
FLUENCE_ENV?: string;
}
}
}
function setConfig(env) {
switch (env) {
case 'krasnodar':
return { config: krasnodarConfig, isEphemeral: false };
case 'testnet':
return { config: testNetConfig, isEphemeral: false };
case 'ephemeral':
return { config: null, isEphemeral: true };
case 'local':
return { config: localConfig, isEphemeral: false };
default:
return { config: stageConfig, isEphemeral: false };
}
switch (env) {
case "krasnodar":
return { config: krasnodarConfig, isEphemeral: false };
case "testnet":
return { config: testNetConfig, isEphemeral: false };
case "ephemeral":
return { config: null, isEphemeral: true };
case "local":
return { config: localConfig, isEphemeral: false };
default:
return { config: stageConfig, isEphemeral: false };
}
}
export const krasnodarConfig = {
relays: krasnodar,
externalAddressesRelay1: ['/ip4/164.90.171.139/tcp/7770', '/ip4/164.90.171.139/tcp/9990/ws'],
externalAddressesRelay2: ['/ip4/164.90.164.229/tcp/7001', '/ip4/164.90.164.229/tcp/9001/ws'],
tryCatchError:
"Local service error, ret_code is 1, error message is '\"Service with id 'unex' not found (function getStr)\"'",
relays: krasnodar,
externalAddressesRelay1: [
"/ip4/164.90.171.139/tcp/7770",
"/ip4/164.90.171.139/tcp/9990/ws",
],
externalAddressesRelay2: [
"/ip4/164.90.164.229/tcp/7001",
"/ip4/164.90.164.229/tcp/9001/ws",
],
tryCatchError:
"Local service error, ret_code is 1, error message is '\"Service with id 'unex' not found (function getStr)\"'",
};
export const stageConfig = {
relays: stage,
externalAddressesRelay1: ['/ip4/134.209.186.43/tcp/7001', '/ip4/134.209.186.43/tcp/9001/ws'],
externalAddressesRelay2: ['/ip4/134.209.186.43/tcp/7770', '/ip4/134.209.186.43/tcp/9990/ws'],
tryCatchError:
"Local service error, ret_code is 1, error message is '\"Service with id 'unex' not found (function getStr)\"'",
relays: stage,
externalAddressesRelay1: [
"/ip4/134.209.186.43/tcp/7001",
"/ip4/134.209.186.43/tcp/9001/ws",
],
externalAddressesRelay2: [
"/ip4/134.209.186.43/tcp/7770",
"/ip4/134.209.186.43/tcp/9990/ws",
],
tryCatchError:
"Local service error, ret_code is 1, error message is '\"Service with id 'unex' not found (function getStr)\"'",
};
export const testNetConfig = {
relays: testNet,
externalAddressesRelay1: ['/ip4/165.227.164.206/tcp/7001', '/ip4/165.227.164.206/tcp/9001/ws'],
externalAddressesRelay2: ['/ip4/142.93.169.49/tcp/7001', '/ip4/142.93.169.49/tcp/9001/ws'],
tryCatchError:
"Local service error, ret_code is 1, error message is '\"Service with id 'unex' not found (function getStr)\"'",
relays: testNet,
externalAddressesRelay1: [
"/ip4/165.227.164.206/tcp/7001",
"/ip4/165.227.164.206/tcp/9001/ws",
],
externalAddressesRelay2: [
"/ip4/142.93.169.49/tcp/7001",
"/ip4/142.93.169.49/tcp/9001/ws",
],
tryCatchError:
"Local service error, ret_code is 1, error message is '\"Service with id 'unex' not found (function getStr)\"'",
};
// export const ephemeralConfig = {
@ -60,21 +82,21 @@ export const testNetConfig = {
// };
export const localConfig = {
relays: local,
externalAddressesRelay1: [
'/ip4/10.50.10.10/tcp/7771',
'/ip4/10.50.10.10/tcp/9991/ws',
'/dns4/nox-1/tcp/7771',
'/dns4/nox-1/tcp/9991/ws',
],
externalAddressesRelay2: [
'/ip4/10.50.10.60/tcp/7776',
'/ip4/10.50.10.60/tcp/9996/ws',
'/dns4/nox-6/tcp/7776',
'/dns4/nox-6/tcp/9996/ws',
],
tryCatchError:
"Local service error, ret_code is 1, error message is '\"Service with id 'unex' not found (function getStr)\"'",
relays: local,
externalAddressesRelay1: [
"/ip4/10.50.10.10/tcp/7771",
"/ip4/10.50.10.10/tcp/9991/ws",
"/dns4/nox-1/tcp/7771",
"/dns4/nox-1/tcp/9991/ws",
],
externalAddressesRelay2: [
"/ip4/10.50.10.60/tcp/7776",
"/ip4/10.50.10.60/tcp/9996/ws",
"/dns4/nox-6/tcp/7776",
"/dns4/nox-6/tcp/9996/ws",
],
tryCatchError:
"Local service error, ret_code is 1, error message is '\"Service with id 'unex' not found (function getStr)\"'",
};
export const { config, isEphemeral } = setConfig('local');
export const { config, isEphemeral } = setConfig("local");

View File

@ -1,19 +1,24 @@
import {handleAb, registerSomeService, bug214, checkAbCalls} from "../compiled/examples/abilities";
import {
handleAb,
registerSomeService,
bug214,
checkAbCalls,
} from "../compiled/examples/abilities";
export async function abilityCall(): Promise<[string, string, string, number]> {
registerSomeService({
getStr: (s: string) => {
return s + "123"
}
})
registerSomeService({
getStr: (s: string) => {
return s + "123";
},
});
return await handleAb("some_string")
return await handleAb("some_string");
}
export async function complexAbilityCall(): Promise<[boolean, boolean]> {
return await bug214()
return await bug214();
}
export async function checkAbCallsCall(): Promise<[boolean, boolean]> {
return await checkAbCalls()
return await checkAbCalls();
}

View File

@ -1,5 +1,5 @@
import { doSmth } from '../compiled/examples/assignment.js';
import { doSmth } from "../compiled/examples/assignment.js";
export async function assignmentCall(): Promise<string[]> {
return await doSmth({ value: 'abc' }, { ttl: 6000 });
return await doSmth({ value: "abc" }, { ttl: 6000 });
}

View File

@ -1,20 +1,28 @@
import { main, compareStreams, compareStructs, registerEffector } from '../compiled/examples/boolAlgebra.js';
import {
main,
compareStreams,
compareStructs,
registerEffector,
} from "../compiled/examples/boolAlgebra.js";
export async function boolAlgebraCall(relay: string): Promise<boolean[]> {
registerEffector({
effect(name, _) {
if (name == 'true') return Promise.resolve(true);
else return Promise.reject(`unknown effect: ${name}`);
},
});
registerEffector({
effect(name, _) {
if (name == "true") return Promise.resolve(true);
else return Promise.reject(`unknown effect: ${name}`);
},
});
return await main(relay);
return await main(relay);
}
export async function compareStreamsCall(relay: string): Promise<boolean> {
return await compareStreams(relay);
return await compareStreams(relay);
}
export async function compareStructsCall(relay: string, str: string): Promise<boolean> {
return await compareStructs(relay, str);
export async function compareStructsCall(
relay: string,
str: string,
): Promise<boolean> {
return await compareStructs(relay, str);
}

View File

@ -1,20 +1,28 @@
import {passFunctionAsArg, reproArgsBug426} from '../compiled/examples/callArrow.js';
import {
passFunctionAsArg,
reproArgsBug426,
} from "../compiled/examples/callArrow.js";
export async function callArrowCall(relayPeerId: string): Promise<string> {
return new Promise<string>((resolve, reject) => {
passFunctionAsArg(relayPeerId, 'callArrow call', (a: string) => {
let result = 'Hello, ' + a + '!';
console.log(result)
resolve(result);
return result;
}, {ttl: 10000});
});
return new Promise<string>((resolve, reject) => {
passFunctionAsArg(
relayPeerId,
"callArrow call",
(a: string) => {
let result = "Hello, " + a + "!";
console.log(result);
resolve(result);
return result;
},
{ ttl: 10000 },
);
});
}
export async function reproArgsBug426Call(): Promise<string> {
return new Promise<string>((resolve, reject) => {
reproArgsBug426((a: string) => {
resolve(a);
}, "privet");
});
return new Promise<string>((resolve, reject) => {
reproArgsBug426((a: string) => {
resolve(a);
}, "privet");
});
}

View File

@ -1,12 +1,15 @@
import {bugLng79, registerSer} from "../compiled/examples/canon.js";
import { bugLng79, registerSer } from "../compiled/examples/canon.js";
export async function bugLng79Call(pid: string, relay: string): Promise<number> {
registerSer({
getRecord: () => {
return {peer_id: pid, relay_id: [relay]};
}
})
return await bugLng79((s) => {
console.log(s)
});
export async function bugLng79Call(
pid: string,
relay: string,
): Promise<number> {
registerSer({
getRecord: () => {
return { peer_id: pid, relay_id: [relay] };
},
});
return await bugLng79((s) => {
console.log(s);
});
}

View File

@ -1,10 +1,8 @@
import {
lng193Bug
} from '../compiled/examples/closureReturnRename.js';
import { config } from '../config.js'
import { lng193Bug } from "../compiled/examples/closureReturnRename.js";
import { config } from "../config.js";
const relays = config.relays
const relays = config.relays;
export async function lng193BugCall(): Promise<number> {
return lng193Bug(relays[4].peerId, relays[5].peerId)
return lng193Bug(relays[4].peerId, relays[5].peerId);
}

View File

@ -1,31 +1,34 @@
import {
closureIn,
closureOut,
closureBig,
registerLocalSrv,
closureOut2,
lng58Bug
} from '../compiled/examples/closures.js';
import { config } from '../config.js'
closureIn,
closureOut,
closureBig,
registerLocalSrv,
closureOut2,
lng58Bug,
} from "../compiled/examples/closures.js";
import { config } from "../config.js";
const relays = config.relays
const relays = config.relays;
export async function closuresCall(): Promise<[string, string[], string[], [string, string]]> {
export async function closuresCall(): Promise<
[string, string[], string[], [string, string]]
> {
registerLocalSrv({ inside: () => console.log("call inside") });
registerLocalSrv({inside: () => console.log("call inside")})
console.log("closurein");
const resIn = await closureIn(relays[4].peerId, { ttl: 25000 });
console.log("closureout");
const resOut = await closureOut(relays[5].peerId, { ttl: 25000 });
console.log("closureout2");
const resOut2 = await closureOut2(relays[5].peerId, { ttl: 25000 });
console.log("closurebig");
const resBig = await closureBig(relays[4].peerId, relays[5].peerId, {
ttl: 25000,
});
console.log("closurein")
const resIn = await closureIn(relays[4].peerId, {ttl: 25000})
console.log("closureout")
const resOut = await closureOut(relays[5].peerId, {ttl: 25000})
console.log("closureout2")
const resOut2 = await closureOut2(relays[5].peerId, {ttl: 25000})
console.log("closurebig")
const resBig = await closureBig(relays[4].peerId, relays[5].peerId, {ttl: 25000})
return [resIn, resOut.external_addresses, resOut2.external_addresses, resBig]
return [resIn, resOut.external_addresses, resOut2.external_addresses, resBig];
}
export async function lng58CBugCall(): Promise<string> {
return lng58Bug()
return lng58Bug();
}

View File

@ -1,17 +1,21 @@
import { parFunc } from '../compiled/examples/par.js';
import { registerCoService } from '../compiled/examples/co.js';
import {relay1} from "../__test__/examples.spec.js";
import { parFunc } from "../compiled/examples/par.js";
import { registerCoService } from "../compiled/examples/co.js";
import { relay1 } from "../__test__/examples.spec.js";
export async function coCall(): Promise<string[]> {
registerCoService({
call: () => {
return 'hello';
},
});
registerCoService({
call: () => {
return "hello";
},
});
return new Promise<string[]>((resolve, reject) => {
parFunc(relay1.peerId, (c) => {
resolve(c.external_addresses);
}, {ttl: 60000});
});
return new Promise<string[]>((resolve, reject) => {
parFunc(
relay1.peerId,
(c) => {
resolve(c.external_addresses);
},
{ ttl: 60000 },
);
});
}

View File

@ -1,31 +1,32 @@
import {
arraySugar,
bugLNG59,
optionSugar,
registerGetArr,
streamSugar
arraySugar,
bugLNG59,
optionSugar,
registerGetArr,
streamSugar,
} from "../compiled/examples/collectionSugar.js";
export async function arraySugarCall(): Promise<[number[], number[]]> {
return await arraySugar(3, 6)
return await arraySugar(3, 6);
}
export async function streamSugarCall(): Promise<[number[], number[]]> {
return await streamSugar(3, 6)
return await streamSugar(3, 6);
}
export async function optionSugarCall(): Promise<[number[], string[], string[]]> {
return await optionSugar(1, "some", null, null)
export async function optionSugarCall(): Promise<
[number[], string[], string[]]
> {
return await optionSugar(1, "some", null, null);
}
export async function bugLNG59Call(nodes: string[]): Promise<string> {
registerGetArr({
getArr: () => {
return nodes;
},
});
registerGetArr({
getArr: () => {
return nodes
}
})
const a = await bugLNG59()
return a
}
const a = await bugLNG59();
return a;
}

View File

@ -1,15 +1,22 @@
import { doStuff, registerTestS } from '../compiled/examples/complex.js';
import { doStuff, registerTestS } from "../compiled/examples/complex.js";
export async function complexCall(selfPeerId: string, relayPeerId: string) {
registerTestS({
t: (arg0) => {
return arg0;
},
multiline: (a, b, c) => {
return b;
},
});
registerTestS({
t: (arg0) => {
return arg0;
},
multiline: (a, b, c) => {
return b;
},
});
return await doStuff(relayPeerId, selfPeerId, true, true, ['1', '2'], ['3', '4'], 'some str');
return await doStuff(
relayPeerId,
selfPeerId,
true,
true,
["1", "2"],
["3", "4"],
"some str",
);
}

View File

@ -1,16 +1,21 @@
import {callConstant, registerGetter, timestampAndTtl} from '../compiled/examples/constants.js';
import {
callConstant,
registerGetter,
timestampAndTtl,
} from "../compiled/examples/constants.js";
export async function constantsCall(): Promise<string[]> {
registerGetter({
createStr: (arg0) => {
return '' + arg0;
},
});
registerGetter({
createStr: (arg0) => {
return "" + arg0;
},
});
return await callConstant();
return await callConstant();
}
export async function particleTtlAndTimestampCall(ttl: number): Promise<[number, number]> {
return await timestampAndTtl({ttl: ttl});
export async function particleTtlAndTimestampCall(
ttl: number,
): Promise<[number, number]> {
return await timestampAndTtl({ ttl: ttl });
}

View File

@ -1,14 +1,17 @@
import { getAliasedData, registerNodeIdGetter } from '../compiled/examples/dataAlias.js';
import {
getAliasedData,
registerNodeIdGetter,
} from "../compiled/examples/dataAlias.js";
export async function dataAliasCall() {
registerNodeIdGetter({
get: () => {
return {
peerId: 'peer id str',
name: 'name str',
};
},
});
registerNodeIdGetter({
get: () => {
return {
peerId: "peer id str",
name: "name str",
};
},
});
return await getAliasedData();
return await getAliasedData();
}

View File

@ -1,23 +1,26 @@
import { concat_foobars, registerStringService } from '../compiled/examples/imports_exports/imports.js';
import { registerMyExportSrv } from '../compiled/examples/imports_exports/exports.js';
import { registerSuperFoo } from '../compiled/examples/imports_exports/declare.js';
import {
concat_foobars,
registerStringService,
} from "../compiled/examples/imports_exports/imports.js";
import { registerMyExportSrv } from "../compiled/examples/imports_exports/exports.js";
import { registerSuperFoo } from "../compiled/examples/imports_exports/declare.js";
export async function declareCall() {
registerSuperFoo({
small_foo: () => {
return 'small_foo';
},
});
registerSuperFoo({
small_foo: () => {
return "small_foo";
},
});
registerStringService({
concat: (a, b) => {
return a + b;
},
});
registerMyExportSrv({
another_str: () => {
return 'str_from_my_export_srv';
},
});
return await concat_foobars();
registerStringService({
concat: (a, b) => {
return a + b;
},
});
registerMyExportSrv({
another_str: () => {
return "str_from_my_export_srv";
},
});
return await concat_foobars();
}

View File

@ -1,16 +1,27 @@
import {forBug499, iterateAndPrint, iterateAndPrintParallel} from '../compiled/examples/fold.js';
import {
forBug499,
iterateAndPrint,
iterateAndPrintParallel,
} from "../compiled/examples/fold.js";
export async function foldCall(relayPeerId: string) {
await iterateAndPrint([relayPeerId], {ttl: 10000});
await iterateAndPrint([relayPeerId], { ttl: 10000 });
return new Promise<string[]>((resolve, reject) => {
iterateAndPrintParallel([relayPeerId], (c) => {
console.log('iterateAndPrintParallel. external addresses: ' + c.external_addresses);
resolve(c.external_addresses);
}, {ttl: 10000});
});
return new Promise<string[]>((resolve, reject) => {
iterateAndPrintParallel(
[relayPeerId],
(c) => {
console.log(
"iterateAndPrintParallel. external addresses: " +
c.external_addresses,
);
resolve(c.external_addresses);
},
{ ttl: 10000 },
);
});
}
export async function foldBug499Call(): Promise<number[]> {
return forBug499()
return forBug499();
}

View File

@ -1,5 +1,5 @@
import { getTwoResults } from '../compiled/examples/foldJoin.js';
import { getTwoResults } from "../compiled/examples/foldJoin.js";
export async function foldJoinCall(relayPeerId: string): Promise<number[]> {
return await getTwoResults(relayPeerId, {ttl: 16000});
return await getTwoResults(relayPeerId, { ttl: 16000 });
}

View File

@ -1,11 +1,11 @@
import { testFunc, registerTestSrv } from '../compiled/examples/func.js';
import { testFunc, registerTestSrv } from "../compiled/examples/func.js";
export async function funcCall() {
registerTestSrv({
str: () => {
return `some str`;
},
});
registerTestSrv({
str: () => {
return `some str`;
},
});
return await testFunc();
return await testFunc();
}

View File

@ -1,26 +1,31 @@
import {main, registerA, calc, calc2, ifCalc} from '../compiled/examples/funcs.js';
import {
main,
registerA,
calc,
calc2,
ifCalc,
} from "../compiled/examples/funcs.js";
export async function funcsCall() {
registerA({
getJ: (n) => {
return n;
},
});
registerA({
getJ: (n) => {
return n
}
})
let res1 = await main((c, arr) => {
console.log(c + ": " + arr);
});
let res1 = await main((c, arr) => {
console.log(c + ": " + arr)
})
let res2 = await calc((c, arr) => {
console.log(c + ": " + arr);
});
let res2 = await calc((c, arr) => {
console.log(c + ": " + arr)
})
let res3 = await calc2((c, arr) => {
console.log(c + ": " + arr);
});
let res3 = await calc2((c, arr) => {
console.log(c + ": " + arr)
})
let res4 = await ifCalc();
let res4 = await ifCalc()
return [res1, res2, res3, res4]
}
return [res1, res2, res3, res4];
}

View File

@ -1,5 +1,5 @@
import {lng119Bug} from "../compiled/examples/functors.js";
import { lng119Bug } from "../compiled/examples/functors.js";
export async function bugLng119Call(): Promise<number[]> {
return lng119Bug();
}
return lng119Bug();
}

View File

@ -1,12 +1,15 @@
import { helloWorld, registerStringExtra } from '../compiled/examples/helloWorld.js';
import {
helloWorld,
registerStringExtra,
} from "../compiled/examples/helloWorld.js";
export async function helloWorldCall() {
// helloWorld.aqua
registerStringExtra({
addNameToHello: (args0) => {
return `Hello, ${args0}!`;
},
});
// helloWorld.aqua
registerStringExtra({
addNameToHello: (args0) => {
return `Hello, ${args0}!`;
},
});
return await helloWorld('NAME');
return await helloWorld("NAME");
}

View File

@ -1,17 +1,22 @@
import {bugLNG69, ifCorrectXorWrap, ifElseCall, ifElseNumCall} from '../compiled/examples/if.js';
import {
bugLNG69,
ifCorrectXorWrap,
ifElseCall,
ifElseNumCall,
} from "../compiled/examples/if.js";
export async function ifCall() {
await ifElseCall(false);
await ifElseCall(true);
await ifElseCall(false);
await ifElseCall(true);
await ifElseNumCall(1);
await ifElseNumCall(5);
await ifElseNumCall(1);
await ifElseNumCall(5);
}
export async function ifWrapCall(node: string) {
return ifCorrectXorWrap(node)
return ifCorrectXorWrap(node);
}
export async function bugNG69Call(node: string): Promise<boolean> {
return bugLNG69(node)
return bugLNG69(node);
}

View File

@ -1,19 +1,17 @@
import { registerOneMore } from '../compiled/examples/imports_exports/gen/OneMore.js';
import { barfoo, wrap } from '../compiled/examples/imports_exports/import2.js';
import { registerOneMore } from "../compiled/examples/imports_exports/gen/OneMore.js";
import { barfoo, wrap } from "../compiled/examples/imports_exports/import2.js";
export async function import2Call() {
registerOneMore('hello', {
more_call: () => {
},
});
registerOneMore("hello", {
more_call: () => {},
});
registerOneMore('ohmygod', {
more_call: () => {
},
});
registerOneMore("ohmygod", {
more_call: () => {},
});
let first = await wrap();
let second = await barfoo();
let first = await wrap();
let second = await barfoo();
return { first, second };
return { first, second };
}

View File

@ -1,22 +1,38 @@
import {joinIdx, joinIdxLocal, joinIdxRelay} from "../compiled/examples/join.js";
import { config } from '../config.js';
import {
joinIdx,
joinIdxLocal,
joinIdxRelay,
} from "../compiled/examples/join.js";
import { config } from "../config.js";
const relays = config.relays
const relays = config.relays;
export async function joinIdxCall(relayPeerId: string) {
// join.aqua
// join.aqua
return await joinIdx(1, [relayPeerId, relays[2].peerId, relays[4].peerId, relays[5].peerId], {ttl: 10000});
return await joinIdx(
1,
[relayPeerId, relays[2].peerId, relays[4].peerId, relays[5].peerId],
{ ttl: 10000 },
);
}
export async function joinIdxLocalCall(relayPeerId: string) {
// join.aqua
// join.aqua
return await joinIdxLocal(2, [relayPeerId, relays[2].peerId, relays[4].peerId]);
return await joinIdxLocal(2, [
relayPeerId,
relays[2].peerId,
relays[4].peerId,
]);
}
export async function joinIdxRelayCall(relayPeerId: string) {
// join.aqua
// join.aqua
return await joinIdxRelay(2, [relayPeerId, relays[2].peerId, relays[4].peerId], {ttl: 30000});
return await joinIdxRelay(
2,
[relayPeerId, relays[2].peerId, relays[4].peerId],
{ ttl: 30000 },
);
}

View File

@ -1,25 +1,32 @@
import {test1, test2, testI16, testI32, testI64, testU64} from '../compiled/examples/math.js';
import {
test1,
test2,
testI16,
testI32,
testI64,
testU64,
} from "../compiled/examples/math.js";
export async function mathTest1Call(): Promise<number> {
return await test1();
return await test1();
}
export async function mathTest2Call(): Promise<number> {
return await test2();
return await test2();
}
export async function mathTestI16Call(peer: string): Promise<number[]> {
return await testI16(peer);
return await testI16(peer);
}
export async function mathTestI32Call(peer: string): Promise<number[]> {
return await testI32(peer);
return await testI32(peer);
}
export async function mathTestI64Call(peer: string): Promise<number[]> {
return await testI64(peer);
return await testI64(peer);
}
export async function mathTestU64Call(peer: string): Promise<number[]> {
return await testU64(peer);
}
return await testU64(peer);
}

View File

@ -1,17 +1,23 @@
import { multiReturnFunc, registerGetStr, registerGetNum } from '../compiled/examples/multiReturn.js';
import {
multiReturnFunc,
registerGetStr,
registerGetNum,
} from "../compiled/examples/multiReturn.js";
export async function multiReturnCall(): Promise<[string[], number, string, number[], string | null, number]> {
registerGetStr({
retStr: (args0) => {
return args0;
},
});
export async function multiReturnCall(): Promise<
[string[], number, string, number[], string | null, number]
> {
registerGetStr({
retStr: (args0) => {
return args0;
},
});
registerGetNum({
retNum: () => {
return 10;
},
});
registerGetNum({
retNum: () => {
return 10;
},
});
return await multiReturnFunc([1, 2], null);
return await multiReturnFunc([1, 2], null);
}

View File

@ -1,24 +1,28 @@
import {test, registerTest, TestResult} from '../compiled/examples/nestedData.js';
import {
test,
registerTest,
TestResult,
} from "../compiled/examples/nestedData.js";
export async function nestedDataCall(): Promise<TestResult> {
let nested = {
let nested = {
one: {
val: "hello",
},
};
registerTest({
test1: () => {
return nested;
},
test2: (arg1: { val: string }, arg2: string) => {
let res = {
one: {
val: "hello"
}
}
registerTest({
test1: () => {
return nested;
val: arg1.val + arg2,
},
test2: (arg1: { val: string; }, arg2: string) => {
let res = {
one: {
val: (arg1.val + arg2)
}
}
return res
}
});
};
return res;
},
});
return await test();
return await test();
}

View File

@ -1,11 +1,11 @@
import { d, registerOpH } from '../compiled/examples/nestedFuncs.js';
import { d, registerOpH } from "../compiled/examples/nestedFuncs.js";
export async function nestedFuncsCall(): Promise<string> {
registerOpH({
identity: (args0) => {
return args0;
},
});
registerOpH({
identity: (args0) => {
return args0;
},
});
return await d('some-str');
return await d("some-str");
}

View File

@ -1,13 +1,22 @@
import {getObj, getObjAssign, getObjRelay} from "../compiled/examples/object.js";
import {
getObj,
getObjAssign,
getObjRelay,
getObjFor,
} from "../compiled/examples/object.js";
export async function getObjCall() {
return await getObj();
return await getObj();
}
export async function getObjRelayCall() {
return await getObjRelay();
return await getObjRelay();
}
export async function getObjAssignCall() {
return await getObjAssign();
return await getObjAssign();
}
export async function getObjForCall() {
return await getObjFor();
}

View File

@ -1,5 +1,5 @@
import { getPeerExternalAddresses } from '../compiled/examples/on.js';
import { getPeerExternalAddresses } from "../compiled/examples/on.js";
export async function onCall(relayPeerId: string): Promise<string[]> {
return await getPeerExternalAddresses(relayPeerId);
return await getPeerExternalAddresses(relayPeerId);
}

View File

@ -1,43 +1,51 @@
import {IFluenceClient} from '@fluencelabs/js-client';
import {registerTest, onPropagate, nestedOnPropagate, seqOnPropagate} from "../compiled/examples/onErrorPropagation.js"
import { IFluenceClient } from "@fluencelabs/js-client";
import {
registerTest,
onPropagate,
nestedOnPropagate,
seqOnPropagate,
} from "../compiled/examples/onErrorPropagation.js";
export async function onPropagateCall(peer2: IFluenceClient, relay2: string): Promise<number> {
registerTest(peer2, {
fail(err, callParams) {
return Promise.reject(err);
},
})
export async function onPropagateCall(
peer2: IFluenceClient,
relay2: string,
): Promise<number> {
registerTest(peer2, {
fail(err, callParams) {
return Promise.reject(err);
},
});
return onPropagate(peer2.getPeerId(), relay2)
return onPropagate(peer2.getPeerId(), relay2);
}
export async function nestedOnPropagateCall(
peer2: IFluenceClient,
relay2: string,
iPeer: string,
iRelay: string,
friend: string
): Promise<number> {
registerTest(peer2, {
fail(err, callParams) {
return Promise.reject(err);
},
})
peer2: IFluenceClient,
relay2: string,
iPeer: string,
iRelay: string,
friend: string,
): Promise<number> {
registerTest(peer2, {
fail(err, callParams) {
return Promise.reject(err);
},
});
return nestedOnPropagate(peer2.getPeerId(), relay2, iPeer, iRelay, friend)
return nestedOnPropagate(peer2.getPeerId(), relay2, iPeer, iRelay, friend);
}
export async function seqOnPropagateCall(
peer2: IFluenceClient,
relay2: string,
iPeer: string,
iRelay: string
): Promise<number> {
registerTest(peer2, {
fail(err, callParams) {
return Promise.reject(err);
},
})
peer2: IFluenceClient,
relay2: string,
iPeer: string,
iRelay: string,
): Promise<number> {
registerTest(peer2, {
fail(err, callParams) {
return Promise.reject(err);
},
});
return seqOnPropagate(peer2.getPeerId(), relay2, iPeer, iRelay)
}
return seqOnPropagate(peer2.getPeerId(), relay2, iPeer, iRelay);
}

View File

@ -1,21 +1,26 @@
import {checkEmpty, checkNoneEmpty, emptyString, registerOptionString} from "../compiled/examples/options/option_gen.js";
import {
checkEmpty,
checkNoneEmpty,
emptyString,
registerOptionString,
} from "../compiled/examples/options/option_gen.js";
export async function genOptions(): Promise<[string, string]> {
registerOptionString({
checkOption: (str: string | null) => {
if (str) {
return "some"
} else {
return "none"
}
}
})
registerOptionString({
checkOption: (str: string | null) => {
if (str) {
return "some";
} else {
return "none";
}
},
});
const a = await checkEmpty();
const b = await checkNoneEmpty("some_string");
return [a, b]
const a = await checkEmpty();
const b = await checkNoneEmpty("some_string");
return [a, b];
}
export async function genOptionsEmptyString(): Promise<string | null> {
return await emptyString();
}
return await emptyString();
}

View File

@ -1,27 +1,31 @@
import {parFunc, registerParService, testTimeout} from '../compiled/examples/par.js';
import {config} from "../config.js";
import {
parFunc,
registerParService,
testTimeout,
} from "../compiled/examples/par.js";
import { config } from "../config.js";
export async function parCall(relayPeerId: string) {
let promise = new Promise<string>((resolve, reject) => {
registerParService({
call: () => {
console.log('hello from parservice-id');
let result = 'hello';
resolve(result);
return result;
},
});
let promise = new Promise<string>((resolve, reject) => {
registerParService({
call: () => {
console.log("hello from parservice-id");
let result = "hello";
resolve(result);
return result;
},
});
});
await parFunc(relayPeerId, (c) => {
console.log('parFunc. external addresses par: ' + c.external_addresses);
});
await parFunc(relayPeerId, (c) => {
console.log("parFunc. external addresses par: " + c.external_addresses);
});
return promise;
return promise;
}
const relays = config.relays
const relays = config.relays;
export async function testTimeoutCall() {
return testTimeout([relays[3].peerId, relays[4].peerId])
return testTimeout([relays[3].peerId, relays[4].peerId]);
}

View File

@ -1,15 +1,19 @@
import {bugLNG60, create_client_util, registerAquaDHT} from '../compiled/examples/passArgs.js';
import {
bugLNG60,
create_client_util,
registerAquaDHT,
} from "../compiled/examples/passArgs.js";
export async function passArgsCall() {
registerAquaDHT({
put_host_value: (args0, args1) => {
return args0 + args1;
},
});
registerAquaDHT({
put_host_value: (args0, args1) => {
return args0 + args1;
},
});
return await create_client_util('sid');
return await create_client_util("sid");
}
export async function bugLNG60Call(relayPeerId: string): Promise<boolean> {
return bugLNG60(relayPeerId, {ttl: 10000})
return bugLNG60(relayPeerId, { ttl: 10000 });
}

View File

@ -1,11 +1,11 @@
import { get_results, registerOpA } from '../compiled/examples/pushToStream.js';
import { get_results, registerOpA } from "../compiled/examples/pushToStream.js";
export async function pushToStreamCall() {
registerOpA({
get_str: () => {
return 'get_string';
},
});
registerOpA({
get_str: () => {
return "get_string";
},
});
return await get_results();
return await get_results();
}

View File

@ -1,20 +1,22 @@
import {recursiveStream, registerYesNoService} from "../compiled/examples/recursiveStreams.js";
import {
recursiveStream,
registerYesNoService,
} from "../compiled/examples/recursiveStreams.js";
export async function recursiveStreamsCall(): Promise<[string[], string[]]> {
let i = 0;
registerYesNoService({
get: () => {
i++;
if (i > 3) {
console.log("return no")
return "no"
} else {
console.log("return yes")
return "yes"
}
let i = 0;
registerYesNoService({
get: () => {
i++;
if (i > 3) {
console.log("return no");
return "no";
} else {
console.log("return yes");
return "yes";
}
},
});
}
})
return await recursiveStream()
}
return await recursiveStream();
}

View File

@ -1,5 +1,5 @@
import { rename_s } from '../compiled/examples/renameVars.js';
import { rename_s } from "../compiled/examples/renameVars.js";
export async function renameVarsCall(): Promise<string[]> {
return await rename_s();
return await rename_s();
}

View File

@ -1,9 +1,14 @@
import {callReturnedArrow, callReturnedChainArrow} from "../compiled/examples/returnArrow.js";
import {
callReturnedArrow,
callReturnedChainArrow,
} from "../compiled/examples/returnArrow.js";
export async function returnArrowCall(): Promise<[string, string]> {
return await callReturnedArrow("arg for func ", "arg for closure ")
return await callReturnedArrow("arg for func ", "arg for closure ");
}
export async function returnArrowChainCall(): Promise<[string, string, string, string, string, string, string, string]> {
return await callReturnedChainArrow("arg for func1 ", "arg for func2 ")
}
export async function returnArrowChainCall(): Promise<
[string, string, string, string, string, string, string, string]
> {
return await callReturnedChainArrow("arg for func1 ", "arg for func2 ");
}

View File

@ -1,5 +1,5 @@
import { returnLiteral } from '../compiled/examples/returnLiteral.js';
import { returnLiteral } from "../compiled/examples/returnLiteral.js";
export async function literalCall() {
return returnLiteral();
return returnLiteral();
}

View File

@ -1,11 +1,14 @@
import { retrieve_records, registerTestService } from '../compiled/examples/streamArgs.js';
import {
retrieve_records,
registerTestService,
} from "../compiled/examples/streamArgs.js";
export async function streamArgsCall() {
registerTestService({
get_records: (key) => {
return [key, key];
},
});
registerTestService({
get_records: (key) => {
return [key, key];
},
});
return await retrieve_records('peer_id');
return await retrieve_records("peer_id");
}

View File

@ -1,54 +1,59 @@
import {
checkStreams,
registerStringer, returnNilLength, returnNilLiteral,
returnStreamFromFunc, streamAssignment,
streamFunctor, streamIntFunctor, streamJoin,
stringNil,
stringNone
} from '../compiled/examples/stream.js';
checkStreams,
registerStringer,
returnNilLength,
returnNilLiteral,
returnStreamFromFunc,
streamAssignment,
streamFunctor,
streamIntFunctor,
streamJoin,
stringNil,
stringNone,
} from "../compiled/examples/stream.js";
export async function streamCall() {
registerStringer({
returnString: (args0) => {
return args0 + ' updated';
},
});
registerStringer({
returnString: (args0) => {
return args0 + " updated";
},
});
return checkStreams(['third', 'fourth']);
return checkStreams(["third", "fourth"]);
}
export async function returnNilCall() {
return stringNil()
return stringNil();
}
export async function returnNoneCall() {
return stringNone()
return stringNone();
}
export async function streamReturnFromInnerFunc() {
return await returnStreamFromFunc();
return await returnStreamFromFunc();
}
export async function streamFunctorCall() {
return await streamFunctor(["333"]);
return await streamFunctor(["333"]);
}
export async function streamJoinCall() {
return await streamJoin(["444"]);
return await streamJoin(["444"]);
}
export async function streamAssignmentCall() {
return await streamAssignment(["333"]);
return await streamAssignment(["333"]);
}
export async function nilLiteralCall() {
return await returnNilLiteral();
return await returnNilLiteral();
}
export async function nilLengthCall() {
return await returnNilLength();
return await returnNilLength();
}
export async function streamIntFunctorCall() {
return await streamIntFunctor([0]);
return await streamIntFunctor([0]);
}

View File

@ -1,9 +1,9 @@
import {someFunc} from "../compiled/examples/streamCallback.js";
import { someFunc } from "../compiled/examples/streamCallback.js";
export async function streamCallbackCall(): Promise<string[]> {
return new Promise<string[]>((resolve, reject) => {
someFunc((a: string[]) => {
resolve(a);
})
return new Promise<string[]>((resolve, reject) => {
someFunc((a: string[]) => {
resolve(a);
});
});
}

View File

@ -1,17 +1,22 @@
import {accumRes, bugLNG63, bugLNG63_2, bugLNG63_3} from "../compiled/examples/streamCan.js";
import {
accumRes,
bugLNG63,
bugLNG63_2,
bugLNG63_3,
} from "../compiled/examples/streamCan.js";
export async function streamCanCall() {
return await accumRes();
return await accumRes();
}
export async function bugLNG63Call(): Promise<string> {
return await bugLNG63();
return await bugLNG63();
}
export async function bugLNG63_2Call(): Promise<[string, string[], string[]]> {
return await bugLNG63_2();
return await bugLNG63_2();
}
export async function bugLNG63_3Call(): Promise<[string, number, number[]]> {
return await bugLNG63_3();
return await bugLNG63_3();
}

View File

@ -1,9 +1,12 @@
import { testStreamCaptureSimple, testStreamCaptureReturn } from '../compiled/examples/streamCapture.js';
import {
testStreamCaptureSimple,
testStreamCaptureReturn,
} from "../compiled/examples/streamCapture.js";
export async function streamCaptureSimpleCall() {
return await testStreamCaptureSimple();
return await testStreamCaptureSimple();
}
export async function streamCaptureReturnCall() {
return await testStreamCaptureReturn();
return await testStreamCaptureReturn();
}

View File

@ -1,5 +1,5 @@
import { streamRes } from '../compiled/examples/streamRestriction.js';
import { streamRes } from "../compiled/examples/streamRestriction.js";
export async function streamResCall(): Promise<any> {
return await streamRes(["a", "b", "c"]);
return await streamRes(["a", "b", "c"]);
}

View File

@ -1,13 +1,16 @@
import { use_name2, registerDTGetter } from '../compiled/examples/streamResults.js';
import {
use_name2,
registerDTGetter,
} from "../compiled/examples/streamResults.js";
export async function streamResultsCall() {
registerDTGetter({
get_dt: (args0) => {
return {
field: args0,
};
},
});
registerDTGetter({
get_dt: (args0) => {
return {
field: args0,
};
},
});
return await use_name2('new_name');
return await use_name2("new_name");
}

View File

@ -1,5 +1,5 @@
import { testReturnStream } from '../compiled/examples/streamReturn.js';
import { testReturnStream } from "../compiled/examples/streamReturn.js";
export async function streamReturnCall() {
return await testReturnStream();
return await testReturnStream();
}

View File

@ -1,35 +1,35 @@
import {
streamIf,
streamTry,
streamFor,
streamComplex,
registerFailureSrv,
} from '../compiled/examples/streamScopes.js';
streamIf,
streamTry,
streamFor,
streamComplex,
registerFailureSrv,
} from "../compiled/examples/streamScopes.js";
export async function streamIfCall() {
return await streamIf();
return await streamIf();
}
export async function streamTryCall() {
registerFailureSrv({
fail: (msg) => {
return Promise.reject(msg);
},
});
registerFailureSrv({
fail: (msg) => {
return Promise.reject(msg);
},
});
return await streamTry();
return await streamTry();
}
export async function streamForCall() {
return await streamFor();
return await streamFor();
}
export async function streamComplexCall() {
registerFailureSrv({
fail: (msg) => {
return Promise.reject(msg);
},
});
registerFailureSrv({
fail: (msg) => {
return Promise.reject(msg);
},
});
return await streamComplex();
return await streamComplex();
}

View File

@ -1,5 +1,5 @@
import {structuralTypingTest} from "../compiled/examples/structuraltyping";
import { structuralTypingTest } from "../compiled/examples/structuraltyping";
export async function structuralTypingCall(): Promise<string> {
return await structuralTypingTest();
return await structuralTypingTest();
}

View File

@ -1,24 +1,27 @@
import { registerSubService } from '../compiled/examples/imports_exports/subImport.js';
import { registerConcatSubs, subImportUsage } from '../compiled/examples/subImportUsage.js';
import { registerSubService } from "../compiled/examples/imports_exports/subImport.js";
import {
registerConcatSubs,
subImportUsage,
} from "../compiled/examples/subImportUsage.js";
export async function subImportCall() {
// helloWorld.aqua
registerSubService({
sub: (s) => {
return {
one: s,
two: 42,
};
},
});
registerConcatSubs({
get_some: (s, sr) => {
return {
one: s,
two: sr.two,
};
},
});
// helloWorld.aqua
registerSubService({
sub: (s) => {
return {
one: s,
two: 42,
};
},
});
registerConcatSubs({
get_some: (s, sr) => {
return {
one: s,
two: sr.two,
};
},
});
return await subImportUsage('random_string');
return await subImportUsage("random_string");
}

View File

@ -1,45 +1,68 @@
import { IFluenceClient } from '@fluencelabs/js-client';
import { IFluenceClient } from "@fluencelabs/js-client";
import {
topologyTest,
registerTesto,
registerLocalPrint,
topologyBug205,
topologyBug394, topologyBug427
} from '../compiled/examples/topology.js';
topologyTest,
registerTesto,
registerLocalPrint,
topologyBug205,
topologyBug394,
topologyBug427,
} from "../compiled/examples/topology.js";
export async function topologyBug394Call(peer1: string, relay1: string, peer2: string, relay2: string): Promise<string> {
return topologyBug394(relay1, peer2, relay2)
export async function topologyBug394Call(
peer1: string,
relay1: string,
peer2: string,
relay2: string,
): Promise<string> {
return topologyBug394(relay1, peer2, relay2);
}
export async function topologyBug205Call(relay1: string, relay2: string): Promise<string[]> {
return topologyBug205(relay1, relay2)
export async function topologyBug205Call(
relay1: string,
relay2: string,
): Promise<string[]> {
return topologyBug205(relay1, relay2);
}
export async function topologyBug427Call(relay1: string, relay2: string): Promise<string[]> {
return topologyBug427([relay1, relay2])
export async function topologyBug427Call(
relay1: string,
relay2: string,
): Promise<string[]> {
return topologyBug427([relay1, relay2]);
}
export async function topologyCall(peer1: IFluenceClient, relay1: string, peer2: IFluenceClient, relay2: string): Promise<string> {
const relayPeerId = relay1;
const selfPeerId = peer1.getPeerId();
export async function topologyCall(
peer1: IFluenceClient,
relay1: string,
peer2: IFluenceClient,
relay2: string,
): Promise<string> {
const relayPeerId = relay1;
const selfPeerId = peer1.getPeerId();
const relayPeerId2 = relay2;
const selfPeerId2 = peer2.getPeerId();
const relayPeerId2 = relay2;
const selfPeerId2 = peer2.getPeerId();
registerTesto(peer2, {
getString: (args0) => {
console.log('hello from client2: ' + args0);
return 'hello from client2: ' + args0;
},
});
registerTesto(peer2, {
getString: (args0) => {
console.log("hello from client2: " + args0);
return "hello from client2: " + args0;
},
});
registerLocalPrint({
print: (args0) => {
console.log('print on client1: ' + args0);
},
});
registerLocalPrint({
print: (args0) => {
console.log("print on client1: " + args0);
},
});
return await topologyTest(selfPeerId, relayPeerId, selfPeerId2, relayPeerId2, {
ttl: 10000,
});
return await topologyTest(
selfPeerId,
relayPeerId,
selfPeerId2,
relayPeerId2,
{
ttl: 10000,
},
);
}

View File

@ -1,5 +1,5 @@
import { tryCatchTest } from '../compiled/examples/tryCatch.js';
import { tryCatchTest } from "../compiled/examples/tryCatch.js";
export async function tryCatchCall(relayPeerId: string): Promise<string[]> {
return await tryCatchTest(relayPeerId, {ttl: 60000});
return await tryCatchTest(relayPeerId, { ttl: 60000 });
}

View File

@ -1,5 +1,5 @@
import { tryOtherwiseTest } from '../compiled/examples/tryOtherwise.js';
import { tryOtherwiseTest } from "../compiled/examples/tryOtherwise.js";
export async function tryOtherwiseCall(relayPeerId: string): Promise<string> {
return await tryOtherwiseTest(relayPeerId, {ttl: 60000});
return await tryOtherwiseTest(relayPeerId, { ttl: 60000 });
}

View File

@ -1,30 +1,33 @@
import { returnNone, returnOptional, useOptional, registerSomeS } from '../compiled/examples/option.js';
import {
returnNone,
returnOptional,
useOptional,
registerSomeS,
} from "../compiled/examples/option.js";
export function registerHandlers(): void {
registerSomeS({
getStr: (arg0) => {
return arg0;
},
getStr1: () => {
return 'optional';
},
getStr2: (arg0) => {
return arg0;
},
checkU32: (arg) => {
}
});
registerSomeS({
getStr: (arg0) => {
return arg0;
},
getStr1: () => {
return "optional";
},
getStr2: (arg0) => {
return arg0;
},
checkU32: (arg) => {},
});
}
export async function useOptionalCall(): Promise<string> {
return await useOptional('hello');
return await useOptional("hello");
}
export async function returnOptionalCall(): Promise<string | null> {
return await returnOptional();
return await returnOptional();
}
export async function returnNull(): Promise<string | null> {
return await returnNone();
return await returnNone();
}

View File

@ -1,31 +1,43 @@
import { viaArr, viaOpt, viaStream } from '../compiled/examples/via.js';
import { config } from '../config.js';
import { viaArr, viaOpt, viaStream } from "../compiled/examples/via.js";
import { config } from "../config.js";
const relays = config.relays
const relays = config.relays;
export async function viaArrCall(): Promise<string[]> {
let res = await viaArr(relays[4].peerId, [relays[2].peerId, relays[1].peerId], {ttl: 30000});
let res = await viaArr(
relays[4].peerId,
[relays[2].peerId, relays[1].peerId],
{ ttl: 30000 },
);
return res.external_addresses;
return res.external_addresses;
}
export async function viaOptCall(relayPeerId: string): Promise<string[]> {
let res2 = await viaOpt(relayPeerId, relays[4].peerId, relays[2].peerId, {
ttl: 30000,
});
let res2 = await viaOpt(relayPeerId, relays[4].peerId, relays[2].peerId, {ttl: 30000});
return res2.external_addresses;
return res2.external_addresses;
}
export async function viaOptNullCall(relayPeerId: string): Promise<string[]> {
let res3 = await viaOpt(
relayPeerId,
relays[4].peerId,
relays[2].peerId || null,
{ ttl: 30000 },
);
let res3 = await viaOpt(relayPeerId, relays[4].peerId, relays[2].peerId || null, {ttl: 30000});
return res3.external_addresses;
return res3.external_addresses;
}
export async function viaStreamCall(relayPeerId: string): Promise<string[]> {
let res4 = await viaStream(
relays[4].peerId,
[relays[2].peerId, relays[1].peerId],
{ ttl: 30000 },
);
let res4 = await viaStream(relays[4].peerId, [relays[2].peerId, relays[1].peerId], {ttl: 30000});
return res4.external_addresses;
return res4.external_addresses;
}

View File

@ -1,10 +1,10 @@
#!/usr/bin/env node
const main = async () => {
process.exit(0);
process.exit(0);
};
main().catch((err) => {
console.log(err);
process.exit(1);
console.log(err);
process.exit(1);
});

View File

@ -1,27 +1,33 @@
export type Node = { peerId: string; multiaddr: string };
export const local: Node[] = [
{
multiaddr: '/ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR',
peerId: '12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR'
multiaddr:
"/ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR",
peerId: "12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR",
},
{
multiaddr: '/ip4/127.0.0.1/tcp/9992/ws/p2p/12D3KooWQdpukY3p2DhDfUfDgphAqsGu5ZUrmQ4mcHSGrRag6gQK',
peerId: '12D3KooWQdpukY3p2DhDfUfDgphAqsGu5ZUrmQ4mcHSGrRag6gQK'
multiaddr:
"/ip4/127.0.0.1/tcp/9992/ws/p2p/12D3KooWQdpukY3p2DhDfUfDgphAqsGu5ZUrmQ4mcHSGrRag6gQK",
peerId: "12D3KooWQdpukY3p2DhDfUfDgphAqsGu5ZUrmQ4mcHSGrRag6gQK",
},
{
multiaddr: '/ip4/127.0.0.1/tcp/9993/ws/p2p/12D3KooWRT8V5awYdEZm6aAV9HWweCEbhWd7df4wehqHZXAB7yMZ',
peerId: '12D3KooWRT8V5awYdEZm6aAV9HWweCEbhWd7df4wehqHZXAB7yMZ'
multiaddr:
"/ip4/127.0.0.1/tcp/9993/ws/p2p/12D3KooWRT8V5awYdEZm6aAV9HWweCEbhWd7df4wehqHZXAB7yMZ",
peerId: "12D3KooWRT8V5awYdEZm6aAV9HWweCEbhWd7df4wehqHZXAB7yMZ",
},
{
multiaddr: '/ip4/127.0.0.1/tcp/9994/ws/p2p/12D3KooWBzLSu9RL7wLP6oUowzCbkCj2AGBSXkHSJKuq4wwTfwof',
peerId: '12D3KooWBzLSu9RL7wLP6oUowzCbkCj2AGBSXkHSJKuq4wwTfwof'
multiaddr:
"/ip4/127.0.0.1/tcp/9994/ws/p2p/12D3KooWBzLSu9RL7wLP6oUowzCbkCj2AGBSXkHSJKuq4wwTfwof",
peerId: "12D3KooWBzLSu9RL7wLP6oUowzCbkCj2AGBSXkHSJKuq4wwTfwof",
},
{
multiaddr: '/ip4/127.0.0.1/tcp/9995/ws/p2p/12D3KooWBf6hFgrnXwHkBnwPGMysP3b1NJe5HGtAWPYfwmQ2MBiU',
peerId: '12D3KooWBf6hFgrnXwHkBnwPGMysP3b1NJe5HGtAWPYfwmQ2MBiU'
multiaddr:
"/ip4/127.0.0.1/tcp/9995/ws/p2p/12D3KooWBf6hFgrnXwHkBnwPGMysP3b1NJe5HGtAWPYfwmQ2MBiU",
peerId: "12D3KooWBf6hFgrnXwHkBnwPGMysP3b1NJe5HGtAWPYfwmQ2MBiU",
},
{
multiaddr: '/ip4/127.0.0.1/tcp/9996/ws/p2p/12D3KooWPisGn7JhooWhggndz25WM7vQ2JmA121EV8jUDQ5xMovJ',
peerId: '12D3KooWPisGn7JhooWhggndz25WM7vQ2JmA121EV8jUDQ5xMovJ'
}
multiaddr:
"/ip4/127.0.0.1/tcp/9996/ws/p2p/12D3KooWPisGn7JhooWhggndz25WM7vQ2JmA121EV8jUDQ5xMovJ",
peerId: "12D3KooWPisGn7JhooWhggndz25WM7vQ2JmA121EV8jUDQ5xMovJ",
},
];

View File

@ -1,49 +1,61 @@
package aqua.model.inline
import aqua.model.{
CallModel,
CallServiceModel,
LiteralModel,
OpModel,
SeqModel,
ValueModel,
VarModel
}
import aqua.model.inline.RawValueInliner.unfold
import aqua.model.inline.raw.RawInliner
import aqua.model.inline.state.{Arrows, Exports, Mangler}
import aqua.raw.value.{LiteralRaw, MakeStructRaw}
import aqua.model.inline.Inline
import aqua.model.inline.RawValueInliner.{unfold, valueToModel}
import aqua.types.ScalarType
import aqua.model.*
import aqua.raw.value.MakeStructRaw
import aqua.types.{StreamMapType, StructType}
import cats.data.Chain
import cats.data.{NonEmptyMap, State}
import cats.syntax.traverse.*
import cats.syntax.monoid.*
import cats.syntax.functor.*
import cats.syntax.flatMap.*
import cats.syntax.apply.*
import cats.data.{Chain, NonEmptyMap, State}
import cats.syntax.foldable.*
import cats.syntax.bifunctor.*
import cats.syntax.functor.*
object MakeStructRawInliner extends RawInliner[MakeStructRaw] {
/**
* Creates structure using stream map.
* @param mapName stream map name
* @param mapType stream map type
* @param result variable with structure
* @param fields fields to insert
* @param prefix operations that must be inside stream map restriction
* @return tree with traversed fields and tree with structure creation.
* They are split to combine it later with other trees in a more natural way.
*/
def constructThroughMap[S: Mangler](
mapName: String,
mapType: StreamMapType,
result: CallModel.Export,
fields: NonEmptyMap[String, ValueModel],
prefix: List[OpModel.Tree] = Nil
): State[S, OpModel.Tree] = {
fields.nonEmptyTraverse(TagInliner.canonicalizeIfStream(_)).map { fieldsTraversed =>
val (values, ops) = fieldsTraversed.toNel.map { case (name, (model, ops)) =>
(name -> model, ops)
}.unzip.bimap(_.toList, _.toList.flatten)
val models = values.map { case (k, v) =>
InsertKeyValueModel(LiteralModel.quote(k), v, mapName, mapType).leaf
}
val toResult =
CanonicalizeModel(VarModel(mapName, mapType), result).leaf
RestrictionModel(mapName, mapType).wrap(ops ++ prefix ++ models :+ toResult)
}
}
private def createObj[S: Mangler](
fields: NonEmptyMap[String, ValueModel],
result: VarModel
resultName: String,
resultType: StructType
): State[S, OpModel.Tree] = {
fields.toSortedMap.toList.flatMap { case (name, value) =>
LiteralModel.quote(name) :: value :: Nil
}.traverse(TagInliner.canonicalizeIfStream(_)).map { argsWithOps =>
val (args, ops) = argsWithOps.unzip
val createOp =
CallServiceModel(
"json",
"obj",
args,
result
).leaf
SeqModel.wrap(ops.flatten :+ createOp)
}
val mapType = StreamMapType.top()
val mapName = resultName + "_map"
constructThroughMap(mapName, mapType, CallModel.Export(resultName, resultType), fields)
}
override def apply[S: Mangler: Exports: Arrows](
@ -56,7 +68,7 @@ object MakeStructRawInliner extends RawInliner[MakeStructRaw] {
varModel = VarModel(name, raw.baseType)
valsInline = foldedFields.foldMap { case (_, inline) => inline }.desugar
fields = foldedFields.map { case (vm, _) => vm }
objCreation <- createObj(fields, varModel)
objCreation <- createObj(fields, name, raw.structType)
} yield {
(
varModel,

View File

@ -1,72 +1,72 @@
package aqua.model.inline.raw
import aqua.model.{
CallModel,
CallServiceModel,
LiteralModel,
OpModel,
SeqModel,
ValueModel,
VarModel
}
import aqua.errors.Errors.internalError
import aqua.model.*
import aqua.model.inline.Inline.MergeMode.*
import aqua.model.inline.{Inline, TagInliner}
import aqua.model.inline.MakeStructRawInliner.createObj
import aqua.model.inline.RawValueInliner.unfold
import aqua.model.inline.state.{Arrows, Exports, Mangler}
import aqua.raw.value.{IntoCopyRaw, LiteralRaw}
import aqua.types.ScalarType
import aqua.model.inline.{Inline, MakeStructRawInliner}
import aqua.raw.value.IntoCopyRaw
import aqua.types.{StreamMapType, StructType}
import cats.data.{Chain, NonEmptyMap, State}
import scribe.Logging
import cats.syntax.traverse.*
import cats.syntax.monoid.*
import cats.syntax.functor.*
import cats.syntax.flatMap.*
import cats.syntax.apply.*
import cats.syntax.foldable.*
import cats.syntax.functor.*
import scribe.Logging
object ApplyIntoCopyRawInliner extends Logging {
private def copyObj[S: Mangler](
value: VarModel,
fields: NonEmptyMap[String, ValueModel],
result: VarModel
oldValue: VarModel,
resultName: String,
resultType: StructType,
fields: NonEmptyMap[String, ValueModel]
): State[S, OpModel.Tree] = {
fields.toSortedMap.toList.flatMap { case (name, value) =>
LiteralModel.quote(name) :: value :: Nil
}.traverse(TagInliner.canonicalizeIfStream(_)).map { argsWithOps =>
val (args, ops) = argsWithOps.unzip
val copyOp = CallServiceModel(
"json",
"puts",
value +: args,
result
).leaf
SeqModel.wrap(ops.flatten :+ copyOp)
val mapType = StreamMapType.top()
val mapName = resultName + "_map"
val nonCopiedValues = resultType.fields.toNel.filterNot { case (k, _) =>
fields.contains(k)
}.flatMap { case (k, _) =>
oldValue
.intoField(k)
.map(vm =>
InsertKeyValueModel(
LiteralModel.quote(k),
vm,
mapName,
mapType
).leaf
)
}
MakeStructRawInliner
.constructThroughMap(mapName, mapType, CallModel.Export(resultName, resultType), fields, nonCopiedValues)
}
def apply[S: Mangler: Exports: Arrows](
value: VarModel,
intoCopy: IntoCopyRaw
): State[S, (VarModel, Inline)] = {
for {
name <- Mangler[S].findAndForbidName(value.name + "_obj_copy")
foldedFields <- intoCopy.fields.nonEmptyTraverse(unfold(_))
varModel = VarModel(name, value.baseType)
valsInline = foldedFields.toList.foldMap { case (_, inline) => inline }.desugar
fields = foldedFields.map(_._1)
objCopy <- copyObj(value, fields, varModel)
} yield {
(
varModel,
Inline(
Chain.one(SeqModel.wrap(valsInline.predo :+ objCopy)),
SeqMode
)
)
value.`type` match {
case st: StructType =>
for {
resultName <- Mangler[S].findAndForbidName(st.name + "_obj_copy")
foldedFields <- intoCopy.fields.nonEmptyTraverse(unfold(_))
varModel = VarModel(resultName, st)
valsInline = foldedFields.toList.foldMap { case (_, inline) => inline }.desugar
fields = foldedFields.map(_._1)
objCopy <- copyObj(value, resultName, st, fields)
} yield {
(
varModel,
Inline(
Chain.one(SeqModel.wrap(valsInline.predo :+ objCopy)),
SeqMode
)
)
}
case _ =>
internalError("Unreachable. Cannot copy a value that is not a data type")
}
}

View File

@ -161,10 +161,10 @@ object ApplyPropertiesRawInliner extends RawInliner[ApplyPropertyRaw] with Loggi
if (varModel.properties.nonEmpty) removeProperties(varModel)
else State.pure(varModel, Inline.empty)
(flatten, inline) = flattenVI
newVI <- ApplyIntoCopyRawInliner(varModel, ic)
newVI <- ApplyIntoCopyRawInliner(flatten, ic)
} yield {
newVI._1 -> Inline(
inline.predo ++ newVI._2.predo,
Chain.one(SeqModel.wrap(inline.predo ++ newVI._2.predo)),
mergeMode = SeqMode
)
}

View File

@ -1,21 +1,16 @@
package aqua.model.inline.raw
import aqua.errors.Errors.internalError
import aqua.model.inline.Inline.parDesugarPrefixOpt
import aqua.model.{CallServiceModel, FuncArrow, MetaModel, SeqModel, ValueModel, VarModel}
import aqua.model.inline.{ArrowInliner, Inline, TagInliner}
import aqua.model.*
import aqua.model.inline.RawValueInliner.{callToModel, valueToModel}
import aqua.model.inline.state.{Arrows, Exports, Mangler}
import aqua.model.inline.{ArrowInliner, Inline, TagInliner}
import aqua.raw.ops.Call
import aqua.types.ArrowType
import aqua.raw.value.CallArrowRaw
import cats.syntax.traverse.*
import cats.data.{Chain, State}
import cats.syntax.traverse.*
import scribe.Logging
import scala.collection.immutable.ListMap
object CallArrowRawInliner extends RawInliner[CallArrowRaw] with Logging {
private[inline] def unfoldArrow[S: Mangler: Exports: Arrows](

View File

@ -5,7 +5,7 @@ import aqua.model.inline.raw.{ApplyIntoCopyRawInliner, CollectionRawInliner}
import aqua.model.inline.state.InliningState
import aqua.raw.ops.*
import aqua.raw.value.{CollectionRaw, LiteralRaw, MakeStructRaw, VarRaw}
import aqua.types.{CanonStreamType, OptionType, ScalarType, StreamType, StructType}
import aqua.types.{CanonStreamType, OptionType, ScalarType, StreamMapType, StreamType, StructType}
import cats.data.{NonEmptyList, NonEmptyMap}
import cats.syntax.show.*
import org.scalatest.flatspec.AnyFlatSpec
@ -32,18 +32,17 @@ class CollectionRawInlinerSpec extends AnyFlatSpec with Matchers {
v shouldBe resultValue
val streamMapType = StreamMapType.top()
val streamMapVar = VarModel("nested_type_obj_map", streamMapType)
val expected =
RestrictionModel("option-inline", StreamType(nestedType)).wrap( // create a stream
SeqModel.wrap(
// create an object
CallServiceModel(
"json",
"obj",
LiteralModel.fromRaw(LiteralRaw.quote("field1")) :: LiteralModel.fromRaw(
LiteralRaw.number(3)
) :: Nil,
VarModel("nested_type_obj", nestedType)
).leaf,
RestrictionModel(streamMapVar.name, streamMapType).wrap(
InsertKeyValueModel(LiteralModel.quote("field1"), LiteralModel.number(3), streamMapVar.name, streamMapType).leaf,
CanonicalizeModel(streamMapVar, CallModel.Export("nested_type_obj", nestedType)).leaf
),
XorModel.wrap(
SeqModel.wrap(
// push object to the stream

View File

@ -16,7 +16,7 @@ class CopyInlinerSpec extends AnyFlatSpec with Matchers {
"copy inliner" should "unfold values in parallel" in {
val structType = StructType(
"struct_type",
"some_struct",
NonEmptyMap.of("field1" -> ScalarType.u32, "field2" -> ScalarType.string)
)
@ -45,6 +45,9 @@ class CopyInlinerSpec extends AnyFlatSpec with Matchers {
val lengthModel = FunctorModel("length", ScalarType.u32)
val streamMapName = "some_struct_obj_copy_map"
val streamMapType = StreamMapType.top()
tree.get.equalsOrShowDiff(
SeqModel.wrap(
ParModel.wrap(
@ -59,16 +62,11 @@ class CopyInlinerSpec extends AnyFlatSpec with Matchers {
VarModel("get_field", ScalarType.string)
).leaf
),
CallServiceModel(
"json",
"puts",
VarModel(varName, structType) :: LiteralModel.fromRaw(
LiteralRaw.quote("field1")
) :: VarModel("l_length", ScalarType.u32) :: LiteralModel.fromRaw(
LiteralRaw.quote("field2")
) :: VarModel("get_field", ScalarType.string) :: Nil,
result
).leaf
RestrictionModel(streamMapName, streamMapType).wrap(
InsertKeyValueModel(LiteralModel.quote("field1"), VarModel("l_length", ScalarType.u32), streamMapName, streamMapType).leaf,
InsertKeyValueModel(LiteralModel.quote("field2"), VarModel("get_field", ScalarType.string), streamMapName, streamMapType).leaf,
CanonicalizeModel(VarModel(streamMapName, streamMapType), CallModel.Export(result.name, result.`type`)).leaf
)
)
) shouldBe true

View File

@ -44,6 +44,9 @@ class MakeStructInlinerSpec extends AnyFlatSpec with Matchers {
val lengthModel = FunctorModel("length", ScalarType.u32)
val streamMapName = "struct_type_obj_map"
val streamMapType = StreamMapType.top()
tree.get.equalsOrShowDiff(
SeqModel.wrap(
ParModel.wrap(
@ -58,16 +61,11 @@ class MakeStructInlinerSpec extends AnyFlatSpec with Matchers {
VarModel("get_field", ScalarType.string)
).leaf
),
CallServiceModel(
"json",
"obj",
LiteralModel.fromRaw(
LiteralRaw.quote("field1")
) :: VarModel("l_length", ScalarType.u32) :: LiteralModel.fromRaw(
LiteralRaw.quote("field2")
) :: VarModel("get_field", ScalarType.string) :: Nil,
result
).leaf
RestrictionModel(streamMapName, streamMapType).wrap(
InsertKeyValueModel(LiteralModel.quote("field1"), VarModel("l_length", ScalarType.u32), streamMapName, streamMapType).leaf,
InsertKeyValueModel(LiteralModel.quote("field2"), VarModel("get_field", ScalarType.string), streamMapName, streamMapType).leaf,
CanonicalizeModel(VarModel(streamMapName, streamMapType), CallModel.Export(result.name, result.`type`)).leaf
)
)
) shouldBe true

View File

@ -72,6 +72,8 @@ object MakeRes {
orInit(currentPeerId),
exportTo
).leaf
case InsertKeyValueModel(key, value, assignTo, assignToType) =>
ApStreamMapRes(key, value, CallModel.Export(assignTo, assignToType)).leaf
case FlattenModel(operand @ VarModel(_, CanonStreamType(el), _), assignTo) =>
ApRes(operand, CallModel.Export(assignTo, ArrayType(el))).leaf
case FlattenModel(operand, assignTo) =>

View File

@ -1,6 +1,6 @@
package aqua.res
import aqua.model.{CallModel, ForModel, ValueModel, VarModel}
import aqua.model.{CallModel, ForModel, LiteralModel, ValueModel, VarModel}
import aqua.raw.ops.Call
import aqua.tree.{TreeNode, TreeNodeCompanion}
import aqua.types.DataType
@ -50,6 +50,10 @@ case class CallServiceRes(
override def toString: String = s"(call $peerId ($serviceId $funcName) $call)"
}
case class ApStreamMapRes(key: ValueModel, value: ValueModel, exportTo: CallModel.Export) extends ResolvedOp {
override def toString: String = s"(ap ($key $value) $exportTo)"
}
case class ApRes(operand: ValueModel, exportTo: CallModel.Export) extends ResolvedOp {
override def toString: String = s"(ap $operand $exportTo)"
}

View File

@ -174,6 +174,13 @@ case class DeclareStreamModel(value: ValueModel) extends NoExecModel {
override def usesVarNames: Set[String] = value.usesVarNames
}
// key must be only string or number
case class InsertKeyValueModel(key: ValueModel, value: ValueModel, assignTo: String, assignToType: StreamMapType) extends OpModel {
override def usesVarNames: Set[String] = value.usesVarNames
override def exportsVarNames: Set[String] = Set(assignTo)
}
case class FlattenModel(value: ValueModel, assignTo: String) extends OpModel {
override def usesVarNames: Set[String] = value.usesVarNames

9
pnpm-lock.yaml generated
View File

@ -54,6 +54,9 @@ importers:
jest:
specifier: 29.5.0
version: 29.5.0(@types/node@18.11.18)(ts-node@10.9.1)
prettier:
specifier: 3.0.3
version: 3.0.3
ts-jest:
specifier: 29.1.0
version: 29.1.0(@babel/core@7.22.5)(jest@29.5.0)(typescript@5.1.3)
@ -3309,6 +3312,12 @@ packages:
hasBin: true
dev: true
/prettier@3.0.3:
resolution: {integrity: sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==}
engines: {node: '>=14'}
hasBin: true
dev: true
/pretty-format@29.5.0:
resolution: {integrity: sha512-V2mGkI31qdttvTFX7Mt4efOqHXqJWMu4/r66Xh3Z3BwZaPfPJgp6/gbwoujRpPUtfEF6AUUWx3Jim3GCw5g/Qw==}
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}

View File

@ -323,6 +323,16 @@ case class StructType(name: String, fields: NonEmptyMap[String, Type])
s"$name{${fields.map(_.toString).toNel.toList.map(kv => kv._1 + ": " + kv._2).mkString(", ")}}"
}
case class StreamMapType(element: Type)
extends DataType {
override def toString: String = s"%$element"
}
object StreamMapType {
def top(): StreamMapType = StreamMapType(TopType)
}
case class ServiceType(name: String, fields: NonEmptyMap[String, ArrowType]) extends NamedType {
override def toString: String =