Skip to content

Support array result include sequence action #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions deno1.3.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion deno1.3.0/lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
Expand Down
32 changes: 31 additions & 1 deletion tests/src/test/scala/runtime/actionContainers/SingleTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")))
}
}
}