This is an automated email from the ASF dual-hosted git repository. dgrove pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-deno.git
The following commit(s) were added to refs/heads/master by this push: new ce4a603 Support array result include sequence action (#14) ce4a603 is described below commit ce4a603a7eec9da12e6d629b2d528f6055ce9a7b Author: ningyougang <415622...@qq.com> AuthorDate: Mon Aug 15 22:58:08 2022 +0800 Support array result include sequence action (#14) --- README.md | 20 ++++++++++++++ deno1.3.0/Dockerfile | 8 +++--- deno1.3.0/lib/launcher.js | 2 +- .../runtime/actionContainers/SingleTest.scala | 32 +++++++++++++++++++++- 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 92a4601..8fefca7 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,26 @@ export default (args: any) => { } } ``` +For the return result, not only support `dictionary` but also support `array` + +So a very simple `hello array` function would be: + +```ts +export default (args: any) => { + return ["a", "b"] +} +``` + +And support array result for sequence action as well, the first action's array result can be used as next action's input parameter. + +So the function can be: + +```ts +func main(args: Any) -> Any { + return args +} +``` +When invokes above action, we can pass an array object as the input parameter. ## Development diff --git a/deno1.3.0/Dockerfile b/deno1.3.0/Dockerfile index ef2c101..76cd4bb 100644 --- a/deno1.3.0/Dockerfile +++ b/deno1.3.0/Dockerfile @@ -16,7 +16,7 @@ # # build go proxy from source -FROM golang:1.15 AS builder_source +FROM golang:1.18 AS builder_source ARG GO_PROXY_GITHUB_USER=apache ARG GO_PROXY_GITHUB_BRANCH=master RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \ @@ -25,13 +25,13 @@ RUN git clone --branch ${GO_PROXY_GITHUB_BRANCH} \ mv proxy /bin/proxy # or build it from a release -FROM golang:1.15 AS builder_release -ARG GO_PROXY_RELEASE_VERSION=1.15@1.17.0 +FROM golang:1.18 AS builder_release +ARG GO_PROXY_RELEASE_VERSION=1.18@1.20.0 RUN curl -sL \ https://github.com/apache/openwhisk-runtime-go/archive/{$GO_PROXY_RELEASE_VERSION}.tar.gz\ | tar xzf -\ && cd openwhisk-runtime-go-*/main\ - && GO111MODULE=on go build -o /bin/proxy + && GO111MODULE=on CGO_ENABLED=0 go build -o /bin/proxy FROM hayd/alpine-deno:1.3.0 diff --git a/deno1.3.0/lib/launcher.js b/deno1.3.0/lib/launcher.js index 8c47d9a..a6ca143 100644 --- a/deno1.3.0/lib/launcher.js +++ b/deno1.3.0/lib/launcher.js @@ -38,7 +38,7 @@ for await (const line of readLines(Deno.stdin)) { if (await exists(sourceCode)) { const {default: main} = await import(sourceCode); response = await main(payload); - if (Object.prototype.toString.call(response) !== '[object Object]') { + if (Object.prototype.toString.call(response) !== '[object Object]' && Object.prototype.toString.call(response) !== '[object Array]') { response = { error: 'response returned by the function is not an object' }; diff --git a/tests/src/test/scala/runtime/actionContainers/SingleTest.scala b/tests/src/test/scala/runtime/actionContainers/SingleTest.scala index ac23661..ec47a71 100644 --- a/tests/src/test/scala/runtime/actionContainers/SingleTest.scala +++ b/tests/src/test/scala/runtime/actionContainers/SingleTest.scala @@ -21,7 +21,7 @@ import actionContainers.{ActionContainer, ActionProxyContainerTestUtils} import common.WskActorSystem import org.junit.runner.RunWith import org.scalatest.junit.JUnitRunner -import spray.json.{JsonParser} +import spray.json.{JsArray, JsObject, JsString, JsonParser} @RunWith(classOf[JUnitRunner]) class SingleTest extends ActionProxyContainerTestUtils with WskActorSystem { @@ -51,4 +51,34 @@ class SingleTest extends ActionProxyContainerTestUtils with WskActorSystem { runCode should be(200) } } + + it should "support return array result" in { + val helloArrayCode = + """|export default (args: any) => { + | return ["a", "b"] + |} + |""".stripMargin + val (out, err) = withActionContainer() { c => + val (initCode, _) = c.init(initPayload(helloArrayCode)) + initCode should be(200) + val (runCode, runRes) = c.runForJsArray(runPayload(JsObject())) + runCode should be(200) + runRes shouldBe Some(JsArray(JsString("a"), JsString("b"))) + } + } + + it should "support array as input param" in { + val helloArrayCode = + """|export default (args: any) => { + | return args + |} + |""".stripMargin + val (out, err) = withActionContainer() { c => + val (initCode, _) = c.init(initPayload(helloArrayCode)) + initCode should be(200) + val (runCode, runRes) = c.runForJsArray(runPayload(JsArray(JsString("a"), JsString("b")))) + runCode should be(200) + runRes shouldBe Some(JsArray(JsString("a"), JsString("b"))) + } + } }