Support array result include sequence action (#14)
diff --git a/README.md b/README.md
index 92a4601..8fefca7 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,26 @@
}
}
```
+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 @@
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 @@
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 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 @@
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")))
+ }
+ }
}