From 878990a8370718b64bd26663d7813a972e7cdd49 Mon Sep 17 00:00:00 2001 From: Dima Date: Wed, 27 Sep 2023 14:07:22 +0200 Subject: [PATCH] feat: Create structs with stream maps [fixes LNG-244] (#893) --- aqua-src/antithesis.aqua | 36 ++++-- .../src/main/scala/aqua/backend/air/Air.scala | 3 + .../main/scala/aqua/backend/air/AirGen.scala | 19 ++- .../aqua/backend/ts/TypeScriptCommon.scala | 4 +- integration-tests/aqua/examples/object.aqua | 26 +++- integration-tests/package.json | 2 + .../src/__test__/examples.spec.ts | 56 ++++++++ integration-tests/src/config.ts | 120 +++++++++++------- integration-tests/src/examples/abilityCall.ts | 23 ++-- integration-tests/src/examples/assignment.ts | 4 +- integration-tests/src/examples/boolAlgebra.ts | 30 +++-- .../src/examples/callArrowCall.ts | 36 ++++-- integration-tests/src/examples/canonCall.ts | 23 ++-- .../src/examples/closureReturnRename.ts | 10 +- integration-tests/src/examples/closures.ts | 47 +++---- integration-tests/src/examples/coCall.ts | 30 +++-- .../src/examples/collectionSugarCall.ts | 37 +++--- integration-tests/src/examples/complex.ts | 29 +++-- .../src/examples/constantsCall.ts | 25 ++-- .../src/examples/dataAliasCall.ts | 23 ++-- integration-tests/src/examples/declareCall.ts | 41 +++--- integration-tests/src/examples/foldCall.ts | 29 +++-- .../src/examples/foldJoinCall.ts | 4 +- integration-tests/src/examples/funcCall.ts | 14 +- integration-tests/src/examples/funcsCall.ts | 43 ++++--- .../src/examples/functorsCall.ts | 6 +- .../src/examples/helloWorldCall.ts | 19 +-- integration-tests/src/examples/ifCall.ts | 19 ++- integration-tests/src/examples/import2Call.ts | 24 ++-- integration-tests/src/examples/joinCall.ts | 34 +++-- integration-tests/src/examples/mathCall.ts | 23 ++-- .../src/examples/multiReturnCall.ts | 32 +++-- .../src/examples/nestedDataCall.ts | 40 +++--- .../src/examples/nestedFuncsCall.ts | 14 +- integration-tests/src/examples/objectCall.ts | 17 ++- integration-tests/src/examples/onCall.ts | 4 +- .../src/examples/onErrorPropagation.ts | 74 ++++++----- integration-tests/src/examples/optionsCall.ts | 35 ++--- integration-tests/src/examples/parCall.ts | 38 +++--- .../src/examples/passArgsCall.ts | 20 +-- .../src/examples/pushToStreamCall.ts | 14 +- .../src/examples/recursiveStreamsCall.ts | 36 +++--- integration-tests/src/examples/renameVars.ts | 4 +- .../src/examples/returnArrowCall.ts | 15 ++- .../src/examples/returnLiteralCall.ts | 4 +- .../src/examples/streamArgsCall.ts | 17 ++- integration-tests/src/examples/streamCall.ts | 49 +++---- .../src/examples/streamCallback.ts | 10 +- .../src/examples/streamCanCall.ts | 15 ++- .../src/examples/streamCapture.ts | 9 +- .../src/examples/streamRestrictionsCall.ts | 4 +- .../src/examples/streamResultsCall.ts | 21 +-- .../src/examples/streamReturn.ts | 4 +- .../src/examples/streamScopes.ts | 40 +++--- .../src/examples/structuralTypingCall.ts | 4 +- .../src/examples/subImportUsageCall.ts | 43 ++++--- .../src/examples/topologyCall.ts | 87 ++++++++----- .../src/examples/tryCatchCall.ts | 4 +- .../src/examples/tryOtherwiseCall.ts | 4 +- .../src/examples/useOptionalCall.ts | 39 +++--- integration-tests/src/examples/viaCall.ts | 40 ++++-- integration-tests/src/index.ts | 6 +- integration-tests/src/local-nodes.ts | 32 +++-- .../model/inline/MakeStructRawInliner.scala | 82 +++++++----- .../inline/raw/ApplyIntoCopyRawInliner.scala | 98 +++++++------- .../raw/ApplyPropertiesRawInliner.scala | 4 +- .../inline/raw/CallArrowRawInliner.scala | 11 +- .../inline/CollectionRawInlinerSpec.scala | 17 ++- .../aqua/model/inline/CopyInlinerSpec.scala | 20 ++- .../model/inline/MakeStructInlinerSpec.scala | 18 ++- .../res/src/main/scala/aqua/res/MakeRes.scala | 2 + .../src/main/scala/aqua/res/ResolvedOp.scala | 6 +- model/src/main/scala/aqua/model/OpModel.scala | 7 + pnpm-lock.yaml | 9 ++ types/src/main/scala/aqua/types/Type.scala | 10 ++ 75 files changed, 1134 insertions(+), 764 deletions(-) diff --git a/aqua-src/antithesis.aqua b/aqua-src/antithesis.aqua index 72ac4e01..afcdd748 100644 --- a/aqua-src/antithesis.aqua +++ b/aqua-src/antithesis.aqua @@ -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 diff --git a/backend/air/src/main/scala/aqua/backend/air/Air.scala b/backend/air/src/main/scala/aqua/backend/air/Air.scala index 84052e68..0333711f 100644 --- a/backend/air/src/main/scala/aqua/backend/air/Air.scala +++ b/backend/air/src/main/scala/aqua/backend/air/Air.scala @@ -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" diff --git a/backend/air/src/main/scala/aqua/backend/air/AirGen.scala b/backend/air/src/main/scala/aqua/backend/air/AirGen.scala index 97ec846f..40b93695 100644 --- a/backend/air/src/main/scala/aqua/backend/air/AirGen.scala +++ b/backend/air/src/main/scala/aqua/backend/air/AirGen.scala @@ -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 = diff --git a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptCommon.scala b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptCommon.scala index f64d16bd..5541d83e 100644 --- a/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptCommon.scala +++ b/backend/ts/src/main/scala/aqua/backend/ts/TypeScriptCommon.scala @@ -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 diff --git a/integration-tests/aqua/examples/object.aqua b/integration-tests/aqua/examples/object.aqua index ee41a3fe..2745ab5b 100644 --- a/integration-tests/aqua/examples/object.aqua +++ b/integration-tests/aqua/examples/object.aqua @@ -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 \ No newline at end of file + <- 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 + + diff --git a/integration-tests/package.json b/integration-tests/package.json index 7d199b40..af8bd317 100644 --- a/integration-tests/package.json +++ b/integration-tests/package.json @@ -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", diff --git a/integration-tests/src/__test__/examples.spec.ts b/integration-tests/src/__test__/examples.spec.ts index 4ad134ea..d30037ff 100644 --- a/integration-tests/src/__test__/examples.spec.ts +++ b/integration-tests/src/__test__/examples.spec.ts @@ -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([ diff --git a/integration-tests/src/config.ts b/integration-tests/src/config.ts index 627c84f0..756477fb 100644 --- a/integration-tests/src/config.ts +++ b/integration-tests/src/config.ts @@ -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"); diff --git a/integration-tests/src/examples/abilityCall.ts b/integration-tests/src/examples/abilityCall.ts index 1e84c4cb..a4422420 100644 --- a/integration-tests/src/examples/abilityCall.ts +++ b/integration-tests/src/examples/abilityCall.ts @@ -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(); } diff --git a/integration-tests/src/examples/assignment.ts b/integration-tests/src/examples/assignment.ts index f3de7a42..41556fc3 100644 --- a/integration-tests/src/examples/assignment.ts +++ b/integration-tests/src/examples/assignment.ts @@ -1,5 +1,5 @@ -import { doSmth } from '../compiled/examples/assignment.js'; +import { doSmth } from "../compiled/examples/assignment.js"; export async function assignmentCall(): Promise { - return await doSmth({ value: 'abc' }, { ttl: 6000 }); + return await doSmth({ value: "abc" }, { ttl: 6000 }); } diff --git a/integration-tests/src/examples/boolAlgebra.ts b/integration-tests/src/examples/boolAlgebra.ts index 2ff2444e..5c49638e 100644 --- a/integration-tests/src/examples/boolAlgebra.ts +++ b/integration-tests/src/examples/boolAlgebra.ts @@ -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 { - 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 { - return await compareStreams(relay); + return await compareStreams(relay); } -export async function compareStructsCall(relay: string, str: string): Promise { - return await compareStructs(relay, str); +export async function compareStructsCall( + relay: string, + str: string, +): Promise { + return await compareStructs(relay, str); } diff --git a/integration-tests/src/examples/callArrowCall.ts b/integration-tests/src/examples/callArrowCall.ts index e9bd059a..6ab6c114 100644 --- a/integration-tests/src/examples/callArrowCall.ts +++ b/integration-tests/src/examples/callArrowCall.ts @@ -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 { - return new Promise((resolve, reject) => { - passFunctionAsArg(relayPeerId, 'callArrow call', (a: string) => { - let result = 'Hello, ' + a + '!'; - console.log(result) - resolve(result); - return result; - }, {ttl: 10000}); - }); + return new Promise((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 { - return new Promise((resolve, reject) => { - reproArgsBug426((a: string) => { - resolve(a); - }, "privet"); - }); + return new Promise((resolve, reject) => { + reproArgsBug426((a: string) => { + resolve(a); + }, "privet"); + }); } diff --git a/integration-tests/src/examples/canonCall.ts b/integration-tests/src/examples/canonCall.ts index 8ec96e85..ed33851a 100644 --- a/integration-tests/src/examples/canonCall.ts +++ b/integration-tests/src/examples/canonCall.ts @@ -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 { - 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 { + registerSer({ + getRecord: () => { + return { peer_id: pid, relay_id: [relay] }; + }, + }); + return await bugLng79((s) => { + console.log(s); + }); } diff --git a/integration-tests/src/examples/closureReturnRename.ts b/integration-tests/src/examples/closureReturnRename.ts index 70e4c24e..60874bdf 100644 --- a/integration-tests/src/examples/closureReturnRename.ts +++ b/integration-tests/src/examples/closureReturnRename.ts @@ -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 { - return lng193Bug(relays[4].peerId, relays[5].peerId) + return lng193Bug(relays[4].peerId, relays[5].peerId); } diff --git a/integration-tests/src/examples/closures.ts b/integration-tests/src/examples/closures.ts index 5a0cd738..6efe8f07 100644 --- a/integration-tests/src/examples/closures.ts +++ b/integration-tests/src/examples/closures.ts @@ -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 { - return lng58Bug() + return lng58Bug(); } diff --git a/integration-tests/src/examples/coCall.ts b/integration-tests/src/examples/coCall.ts index 574c4938..e0e59840 100644 --- a/integration-tests/src/examples/coCall.ts +++ b/integration-tests/src/examples/coCall.ts @@ -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 { - registerCoService({ - call: () => { - return 'hello'; - }, - }); + registerCoService({ + call: () => { + return "hello"; + }, + }); - return new Promise((resolve, reject) => { - parFunc(relay1.peerId, (c) => { - resolve(c.external_addresses); - }, {ttl: 60000}); - }); + return new Promise((resolve, reject) => { + parFunc( + relay1.peerId, + (c) => { + resolve(c.external_addresses); + }, + { ttl: 60000 }, + ); + }); } diff --git a/integration-tests/src/examples/collectionSugarCall.ts b/integration-tests/src/examples/collectionSugarCall.ts index d81b8410..1c56c342 100644 --- a/integration-tests/src/examples/collectionSugarCall.ts +++ b/integration-tests/src/examples/collectionSugarCall.ts @@ -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 { + registerGetArr({ + getArr: () => { + return nodes; + }, + }); - registerGetArr({ - getArr: () => { - return nodes - } - }) - - const a = await bugLNG59() - return a -} \ No newline at end of file + const a = await bugLNG59(); + return a; +} diff --git a/integration-tests/src/examples/complex.ts b/integration-tests/src/examples/complex.ts index 378ccdf4..4c37efc7 100644 --- a/integration-tests/src/examples/complex.ts +++ b/integration-tests/src/examples/complex.ts @@ -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", + ); } diff --git a/integration-tests/src/examples/constantsCall.ts b/integration-tests/src/examples/constantsCall.ts index b132fee9..aa92ad31 100644 --- a/integration-tests/src/examples/constantsCall.ts +++ b/integration-tests/src/examples/constantsCall.ts @@ -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 { - 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 }); } diff --git a/integration-tests/src/examples/dataAliasCall.ts b/integration-tests/src/examples/dataAliasCall.ts index d30de240..8299ea98 100644 --- a/integration-tests/src/examples/dataAliasCall.ts +++ b/integration-tests/src/examples/dataAliasCall.ts @@ -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(); } diff --git a/integration-tests/src/examples/declareCall.ts b/integration-tests/src/examples/declareCall.ts index 5539b3b8..f6dbadd9 100644 --- a/integration-tests/src/examples/declareCall.ts +++ b/integration-tests/src/examples/declareCall.ts @@ -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(); } diff --git a/integration-tests/src/examples/foldCall.ts b/integration-tests/src/examples/foldCall.ts index 0a304920..105aeab8 100644 --- a/integration-tests/src/examples/foldCall.ts +++ b/integration-tests/src/examples/foldCall.ts @@ -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((resolve, reject) => { - iterateAndPrintParallel([relayPeerId], (c) => { - console.log('iterateAndPrintParallel. external addresses: ' + c.external_addresses); - resolve(c.external_addresses); - }, {ttl: 10000}); - }); + return new Promise((resolve, reject) => { + iterateAndPrintParallel( + [relayPeerId], + (c) => { + console.log( + "iterateAndPrintParallel. external addresses: " + + c.external_addresses, + ); + resolve(c.external_addresses); + }, + { ttl: 10000 }, + ); + }); } export async function foldBug499Call(): Promise { - return forBug499() + return forBug499(); } diff --git a/integration-tests/src/examples/foldJoinCall.ts b/integration-tests/src/examples/foldJoinCall.ts index 13181f14..54d15a30 100644 --- a/integration-tests/src/examples/foldJoinCall.ts +++ b/integration-tests/src/examples/foldJoinCall.ts @@ -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 { - return await getTwoResults(relayPeerId, {ttl: 16000}); + return await getTwoResults(relayPeerId, { ttl: 16000 }); } diff --git a/integration-tests/src/examples/funcCall.ts b/integration-tests/src/examples/funcCall.ts index 8ebc243d..119af421 100644 --- a/integration-tests/src/examples/funcCall.ts +++ b/integration-tests/src/examples/funcCall.ts @@ -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(); } diff --git a/integration-tests/src/examples/funcsCall.ts b/integration-tests/src/examples/funcsCall.ts index 48867a08..a10ca665 100644 --- a/integration-tests/src/examples/funcsCall.ts +++ b/integration-tests/src/examples/funcsCall.ts @@ -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] -} \ No newline at end of file + return [res1, res2, res3, res4]; +} diff --git a/integration-tests/src/examples/functorsCall.ts b/integration-tests/src/examples/functorsCall.ts index 6202c9ed..773839dd 100644 --- a/integration-tests/src/examples/functorsCall.ts +++ b/integration-tests/src/examples/functorsCall.ts @@ -1,5 +1,5 @@ -import {lng119Bug} from "../compiled/examples/functors.js"; +import { lng119Bug } from "../compiled/examples/functors.js"; export async function bugLng119Call(): Promise { - return lng119Bug(); -} \ No newline at end of file + return lng119Bug(); +} diff --git a/integration-tests/src/examples/helloWorldCall.ts b/integration-tests/src/examples/helloWorldCall.ts index b516f715..3713a50d 100644 --- a/integration-tests/src/examples/helloWorldCall.ts +++ b/integration-tests/src/examples/helloWorldCall.ts @@ -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"); } diff --git a/integration-tests/src/examples/ifCall.ts b/integration-tests/src/examples/ifCall.ts index 8678404c..67241d5c 100644 --- a/integration-tests/src/examples/ifCall.ts +++ b/integration-tests/src/examples/ifCall.ts @@ -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 { - return bugLNG69(node) + return bugLNG69(node); } diff --git a/integration-tests/src/examples/import2Call.ts b/integration-tests/src/examples/import2Call.ts index dd9b5078..847f466a 100644 --- a/integration-tests/src/examples/import2Call.ts +++ b/integration-tests/src/examples/import2Call.ts @@ -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 }; } diff --git a/integration-tests/src/examples/joinCall.ts b/integration-tests/src/examples/joinCall.ts index 00a62042..8d82a8ab 100644 --- a/integration-tests/src/examples/joinCall.ts +++ b/integration-tests/src/examples/joinCall.ts @@ -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 }, + ); } diff --git a/integration-tests/src/examples/mathCall.ts b/integration-tests/src/examples/mathCall.ts index ac57c9e5..99f2af1d 100644 --- a/integration-tests/src/examples/mathCall.ts +++ b/integration-tests/src/examples/mathCall.ts @@ -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 { - return await test1(); + return await test1(); } export async function mathTest2Call(): Promise { - return await test2(); + return await test2(); } export async function mathTestI16Call(peer: string): Promise { - return await testI16(peer); + return await testI16(peer); } export async function mathTestI32Call(peer: string): Promise { - return await testI32(peer); + return await testI32(peer); } export async function mathTestI64Call(peer: string): Promise { - return await testI64(peer); + return await testI64(peer); } export async function mathTestU64Call(peer: string): Promise { - return await testU64(peer); -} \ No newline at end of file + return await testU64(peer); +} diff --git a/integration-tests/src/examples/multiReturnCall.ts b/integration-tests/src/examples/multiReturnCall.ts index 1e658bd8..b5319ca8 100644 --- a/integration-tests/src/examples/multiReturnCall.ts +++ b/integration-tests/src/examples/multiReturnCall.ts @@ -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); } diff --git a/integration-tests/src/examples/nestedDataCall.ts b/integration-tests/src/examples/nestedDataCall.ts index 3d6925e3..7ccd3df8 100644 --- a/integration-tests/src/examples/nestedDataCall.ts +++ b/integration-tests/src/examples/nestedDataCall.ts @@ -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 { - 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(); } diff --git a/integration-tests/src/examples/nestedFuncsCall.ts b/integration-tests/src/examples/nestedFuncsCall.ts index 99bbdf7c..76a34d46 100644 --- a/integration-tests/src/examples/nestedFuncsCall.ts +++ b/integration-tests/src/examples/nestedFuncsCall.ts @@ -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 { - registerOpH({ - identity: (args0) => { - return args0; - }, - }); + registerOpH({ + identity: (args0) => { + return args0; + }, + }); - return await d('some-str'); + return await d("some-str"); } diff --git a/integration-tests/src/examples/objectCall.ts b/integration-tests/src/examples/objectCall.ts index 07515316..4571f3bd 100644 --- a/integration-tests/src/examples/objectCall.ts +++ b/integration-tests/src/examples/objectCall.ts @@ -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(); } diff --git a/integration-tests/src/examples/onCall.ts b/integration-tests/src/examples/onCall.ts index f3a46287..94528525 100644 --- a/integration-tests/src/examples/onCall.ts +++ b/integration-tests/src/examples/onCall.ts @@ -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 { - return await getPeerExternalAddresses(relayPeerId); + return await getPeerExternalAddresses(relayPeerId); } diff --git a/integration-tests/src/examples/onErrorPropagation.ts b/integration-tests/src/examples/onErrorPropagation.ts index f047c6f0..f6c9eb96 100644 --- a/integration-tests/src/examples/onErrorPropagation.ts +++ b/integration-tests/src/examples/onErrorPropagation.ts @@ -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 { - registerTest(peer2, { - fail(err, callParams) { - return Promise.reject(err); - }, - }) +export async function onPropagateCall( + peer2: IFluenceClient, + relay2: string, +): Promise { + 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 { - registerTest(peer2, { - fail(err, callParams) { - return Promise.reject(err); - }, - }) + peer2: IFluenceClient, + relay2: string, + iPeer: string, + iRelay: string, + friend: string, +): Promise { + 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 { - registerTest(peer2, { - fail(err, callParams) { - return Promise.reject(err); - }, - }) + peer2: IFluenceClient, + relay2: string, + iPeer: string, + iRelay: string, +): Promise { + registerTest(peer2, { + fail(err, callParams) { + return Promise.reject(err); + }, + }); - return seqOnPropagate(peer2.getPeerId(), relay2, iPeer, iRelay) -} \ No newline at end of file + return seqOnPropagate(peer2.getPeerId(), relay2, iPeer, iRelay); +} diff --git a/integration-tests/src/examples/optionsCall.ts b/integration-tests/src/examples/optionsCall.ts index 6bcab60c..9c5d55c6 100644 --- a/integration-tests/src/examples/optionsCall.ts +++ b/integration-tests/src/examples/optionsCall.ts @@ -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 { - return await emptyString(); -} \ No newline at end of file + return await emptyString(); +} diff --git a/integration-tests/src/examples/parCall.ts b/integration-tests/src/examples/parCall.ts index b16d629f..6294a460 100644 --- a/integration-tests/src/examples/parCall.ts +++ b/integration-tests/src/examples/parCall.ts @@ -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((resolve, reject) => { - registerParService({ - call: () => { - console.log('hello from parservice-id'); - let result = 'hello'; - resolve(result); - return result; - }, - }); + let promise = new Promise((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]); } diff --git a/integration-tests/src/examples/passArgsCall.ts b/integration-tests/src/examples/passArgsCall.ts index d4e25921..2776f742 100644 --- a/integration-tests/src/examples/passArgsCall.ts +++ b/integration-tests/src/examples/passArgsCall.ts @@ -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 { - return bugLNG60(relayPeerId, {ttl: 10000}) + return bugLNG60(relayPeerId, { ttl: 10000 }); } diff --git a/integration-tests/src/examples/pushToStreamCall.ts b/integration-tests/src/examples/pushToStreamCall.ts index 35e379ef..fdf093e2 100644 --- a/integration-tests/src/examples/pushToStreamCall.ts +++ b/integration-tests/src/examples/pushToStreamCall.ts @@ -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(); } diff --git a/integration-tests/src/examples/recursiveStreamsCall.ts b/integration-tests/src/examples/recursiveStreamsCall.ts index 2cefa911..de3bd1a5 100644 --- a/integration-tests/src/examples/recursiveStreamsCall.ts +++ b/integration-tests/src/examples/recursiveStreamsCall.ts @@ -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() -} \ No newline at end of file + return await recursiveStream(); +} diff --git a/integration-tests/src/examples/renameVars.ts b/integration-tests/src/examples/renameVars.ts index d092167c..d8514b9f 100644 --- a/integration-tests/src/examples/renameVars.ts +++ b/integration-tests/src/examples/renameVars.ts @@ -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 { - return await rename_s(); + return await rename_s(); } diff --git a/integration-tests/src/examples/returnArrowCall.ts b/integration-tests/src/examples/returnArrowCall.ts index 6dc9cad5..99775cb8 100644 --- a/integration-tests/src/examples/returnArrowCall.ts +++ b/integration-tests/src/examples/returnArrowCall.ts @@ -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 ") -} \ No newline at end of file +export async function returnArrowChainCall(): Promise< + [string, string, string, string, string, string, string, string] +> { + return await callReturnedChainArrow("arg for func1 ", "arg for func2 "); +} diff --git a/integration-tests/src/examples/returnLiteralCall.ts b/integration-tests/src/examples/returnLiteralCall.ts index 06fb8703..182216d8 100644 --- a/integration-tests/src/examples/returnLiteralCall.ts +++ b/integration-tests/src/examples/returnLiteralCall.ts @@ -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(); } diff --git a/integration-tests/src/examples/streamArgsCall.ts b/integration-tests/src/examples/streamArgsCall.ts index f08db323..920297da 100644 --- a/integration-tests/src/examples/streamArgsCall.ts +++ b/integration-tests/src/examples/streamArgsCall.ts @@ -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"); } diff --git a/integration-tests/src/examples/streamCall.ts b/integration-tests/src/examples/streamCall.ts index 32a01cd9..3604330e 100644 --- a/integration-tests/src/examples/streamCall.ts +++ b/integration-tests/src/examples/streamCall.ts @@ -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]); } diff --git a/integration-tests/src/examples/streamCallback.ts b/integration-tests/src/examples/streamCallback.ts index 8ebd3c4b..b68fbd09 100644 --- a/integration-tests/src/examples/streamCallback.ts +++ b/integration-tests/src/examples/streamCallback.ts @@ -1,9 +1,9 @@ -import {someFunc} from "../compiled/examples/streamCallback.js"; +import { someFunc } from "../compiled/examples/streamCallback.js"; export async function streamCallbackCall(): Promise { - return new Promise((resolve, reject) => { - someFunc((a: string[]) => { - resolve(a); - }) + return new Promise((resolve, reject) => { + someFunc((a: string[]) => { + resolve(a); }); + }); } diff --git a/integration-tests/src/examples/streamCanCall.ts b/integration-tests/src/examples/streamCanCall.ts index 0888ca44..7ad9af7e 100644 --- a/integration-tests/src/examples/streamCanCall.ts +++ b/integration-tests/src/examples/streamCanCall.ts @@ -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 { - 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(); } diff --git a/integration-tests/src/examples/streamCapture.ts b/integration-tests/src/examples/streamCapture.ts index 2326f257..8bac9162 100644 --- a/integration-tests/src/examples/streamCapture.ts +++ b/integration-tests/src/examples/streamCapture.ts @@ -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(); } diff --git a/integration-tests/src/examples/streamRestrictionsCall.ts b/integration-tests/src/examples/streamRestrictionsCall.ts index a5e3b92b..8ec71d7d 100644 --- a/integration-tests/src/examples/streamRestrictionsCall.ts +++ b/integration-tests/src/examples/streamRestrictionsCall.ts @@ -1,5 +1,5 @@ -import { streamRes } from '../compiled/examples/streamRestriction.js'; +import { streamRes } from "../compiled/examples/streamRestriction.js"; export async function streamResCall(): Promise { - return await streamRes(["a", "b", "c"]); + return await streamRes(["a", "b", "c"]); } diff --git a/integration-tests/src/examples/streamResultsCall.ts b/integration-tests/src/examples/streamResultsCall.ts index c7c67e7c..7ef9fd20 100644 --- a/integration-tests/src/examples/streamResultsCall.ts +++ b/integration-tests/src/examples/streamResultsCall.ts @@ -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"); } diff --git a/integration-tests/src/examples/streamReturn.ts b/integration-tests/src/examples/streamReturn.ts index dd7b5ed5..52d02e75 100644 --- a/integration-tests/src/examples/streamReturn.ts +++ b/integration-tests/src/examples/streamReturn.ts @@ -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(); } diff --git a/integration-tests/src/examples/streamScopes.ts b/integration-tests/src/examples/streamScopes.ts index eb3308e0..b7cb86f4 100644 --- a/integration-tests/src/examples/streamScopes.ts +++ b/integration-tests/src/examples/streamScopes.ts @@ -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(); } diff --git a/integration-tests/src/examples/structuralTypingCall.ts b/integration-tests/src/examples/structuralTypingCall.ts index 2bb175d9..cbef5b8e 100644 --- a/integration-tests/src/examples/structuralTypingCall.ts +++ b/integration-tests/src/examples/structuralTypingCall.ts @@ -1,5 +1,5 @@ -import {structuralTypingTest} from "../compiled/examples/structuraltyping"; +import { structuralTypingTest } from "../compiled/examples/structuraltyping"; export async function structuralTypingCall(): Promise { - return await structuralTypingTest(); + return await structuralTypingTest(); } diff --git a/integration-tests/src/examples/subImportUsageCall.ts b/integration-tests/src/examples/subImportUsageCall.ts index c3092802..ab04163e 100644 --- a/integration-tests/src/examples/subImportUsageCall.ts +++ b/integration-tests/src/examples/subImportUsageCall.ts @@ -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"); } diff --git a/integration-tests/src/examples/topologyCall.ts b/integration-tests/src/examples/topologyCall.ts index 5e69d567..e7707f70 100644 --- a/integration-tests/src/examples/topologyCall.ts +++ b/integration-tests/src/examples/topologyCall.ts @@ -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 { - return topologyBug394(relay1, peer2, relay2) +export async function topologyBug394Call( + peer1: string, + relay1: string, + peer2: string, + relay2: string, +): Promise { + return topologyBug394(relay1, peer2, relay2); } -export async function topologyBug205Call(relay1: string, relay2: string): Promise { - return topologyBug205(relay1, relay2) +export async function topologyBug205Call( + relay1: string, + relay2: string, +): Promise { + return topologyBug205(relay1, relay2); } -export async function topologyBug427Call(relay1: string, relay2: string): Promise { - return topologyBug427([relay1, relay2]) +export async function topologyBug427Call( + relay1: string, + relay2: string, +): Promise { + return topologyBug427([relay1, relay2]); } -export async function topologyCall(peer1: IFluenceClient, relay1: string, peer2: IFluenceClient, relay2: string): Promise { - const relayPeerId = relay1; - const selfPeerId = peer1.getPeerId(); +export async function topologyCall( + peer1: IFluenceClient, + relay1: string, + peer2: IFluenceClient, + relay2: string, +): Promise { + 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, + }, + ); } diff --git a/integration-tests/src/examples/tryCatchCall.ts b/integration-tests/src/examples/tryCatchCall.ts index ed66a5d1..57344234 100644 --- a/integration-tests/src/examples/tryCatchCall.ts +++ b/integration-tests/src/examples/tryCatchCall.ts @@ -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 { - return await tryCatchTest(relayPeerId, {ttl: 60000}); + return await tryCatchTest(relayPeerId, { ttl: 60000 }); } diff --git a/integration-tests/src/examples/tryOtherwiseCall.ts b/integration-tests/src/examples/tryOtherwiseCall.ts index 201d110b..25537f26 100644 --- a/integration-tests/src/examples/tryOtherwiseCall.ts +++ b/integration-tests/src/examples/tryOtherwiseCall.ts @@ -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 { - return await tryOtherwiseTest(relayPeerId, {ttl: 60000}); + return await tryOtherwiseTest(relayPeerId, { ttl: 60000 }); } diff --git a/integration-tests/src/examples/useOptionalCall.ts b/integration-tests/src/examples/useOptionalCall.ts index 065713a2..0861a4dd 100644 --- a/integration-tests/src/examples/useOptionalCall.ts +++ b/integration-tests/src/examples/useOptionalCall.ts @@ -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 { - return await useOptional('hello'); + return await useOptional("hello"); } export async function returnOptionalCall(): Promise { - return await returnOptional(); + return await returnOptional(); } export async function returnNull(): Promise { - return await returnNone(); + return await returnNone(); } diff --git a/integration-tests/src/examples/viaCall.ts b/integration-tests/src/examples/viaCall.ts index 3751a834..c50187dd 100644 --- a/integration-tests/src/examples/viaCall.ts +++ b/integration-tests/src/examples/viaCall.ts @@ -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 { - 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 { + 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 { + 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 { + 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; } diff --git a/integration-tests/src/index.ts b/integration-tests/src/index.ts index 1c7f7059..3f97b3a9 100644 --- a/integration-tests/src/index.ts +++ b/integration-tests/src/index.ts @@ -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); }); diff --git a/integration-tests/src/local-nodes.ts b/integration-tests/src/local-nodes.ts index 525c8a4f..da575870 100644 --- a/integration-tests/src/local-nodes.ts +++ b/integration-tests/src/local-nodes.ts @@ -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", + }, ]; diff --git a/model/inline/src/main/scala/aqua/model/inline/MakeStructRawInliner.scala b/model/inline/src/main/scala/aqua/model/inline/MakeStructRawInliner.scala index 6076ac00..d8fdc133 100644 --- a/model/inline/src/main/scala/aqua/model/inline/MakeStructRawInliner.scala +++ b/model/inline/src/main/scala/aqua/model/inline/MakeStructRawInliner.scala @@ -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, diff --git a/model/inline/src/main/scala/aqua/model/inline/raw/ApplyIntoCopyRawInliner.scala b/model/inline/src/main/scala/aqua/model/inline/raw/ApplyIntoCopyRawInliner.scala index 0a19ccb7..a4dabc1d 100644 --- a/model/inline/src/main/scala/aqua/model/inline/raw/ApplyIntoCopyRawInliner.scala +++ b/model/inline/src/main/scala/aqua/model/inline/raw/ApplyIntoCopyRawInliner.scala @@ -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") } } diff --git a/model/inline/src/main/scala/aqua/model/inline/raw/ApplyPropertiesRawInliner.scala b/model/inline/src/main/scala/aqua/model/inline/raw/ApplyPropertiesRawInliner.scala index 2f90f6c3..bd5130f9 100644 --- a/model/inline/src/main/scala/aqua/model/inline/raw/ApplyPropertiesRawInliner.scala +++ b/model/inline/src/main/scala/aqua/model/inline/raw/ApplyPropertiesRawInliner.scala @@ -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 ) } diff --git a/model/inline/src/main/scala/aqua/model/inline/raw/CallArrowRawInliner.scala b/model/inline/src/main/scala/aqua/model/inline/raw/CallArrowRawInliner.scala index a9f8a5ee..1074b8e2 100644 --- a/model/inline/src/main/scala/aqua/model/inline/raw/CallArrowRawInliner.scala +++ b/model/inline/src/main/scala/aqua/model/inline/raw/CallArrowRawInliner.scala @@ -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]( diff --git a/model/inline/src/test/scala/aqua/model/inline/CollectionRawInlinerSpec.scala b/model/inline/src/test/scala/aqua/model/inline/CollectionRawInlinerSpec.scala index 07a23e02..5af8b5fb 100644 --- a/model/inline/src/test/scala/aqua/model/inline/CollectionRawInlinerSpec.scala +++ b/model/inline/src/test/scala/aqua/model/inline/CollectionRawInlinerSpec.scala @@ -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 diff --git a/model/inline/src/test/scala/aqua/model/inline/CopyInlinerSpec.scala b/model/inline/src/test/scala/aqua/model/inline/CopyInlinerSpec.scala index bdfd805b..ab0e7436 100644 --- a/model/inline/src/test/scala/aqua/model/inline/CopyInlinerSpec.scala +++ b/model/inline/src/test/scala/aqua/model/inline/CopyInlinerSpec.scala @@ -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 diff --git a/model/inline/src/test/scala/aqua/model/inline/MakeStructInlinerSpec.scala b/model/inline/src/test/scala/aqua/model/inline/MakeStructInlinerSpec.scala index dd02e7ee..9d147370 100644 --- a/model/inline/src/test/scala/aqua/model/inline/MakeStructInlinerSpec.scala +++ b/model/inline/src/test/scala/aqua/model/inline/MakeStructInlinerSpec.scala @@ -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 diff --git a/model/res/src/main/scala/aqua/res/MakeRes.scala b/model/res/src/main/scala/aqua/res/MakeRes.scala index 9e94063c..4e978cc4 100644 --- a/model/res/src/main/scala/aqua/res/MakeRes.scala +++ b/model/res/src/main/scala/aqua/res/MakeRes.scala @@ -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) => diff --git a/model/res/src/main/scala/aqua/res/ResolvedOp.scala b/model/res/src/main/scala/aqua/res/ResolvedOp.scala index 9a9dc612..d66632b7 100644 --- a/model/res/src/main/scala/aqua/res/ResolvedOp.scala +++ b/model/res/src/main/scala/aqua/res/ResolvedOp.scala @@ -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)" } diff --git a/model/src/main/scala/aqua/model/OpModel.scala b/model/src/main/scala/aqua/model/OpModel.scala index 9a7e247c..3874ffd8 100644 --- a/model/src/main/scala/aqua/model/OpModel.scala +++ b/model/src/main/scala/aqua/model/OpModel.scala @@ -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 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8afac456..a738bd2a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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} diff --git a/types/src/main/scala/aqua/types/Type.scala b/types/src/main/scala/aqua/types/Type.scala index a33cea1b..218a4e3b 100644 --- a/types/src/main/scala/aqua/types/Type.scala +++ b/types/src/main/scala/aqua/types/Type.scala @@ -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 =