Skip to content

Commit da606dd

Browse files
committed
👔 refactor: add openfunction signature type
Signed-off-by: Haili Zhang <haili.zhang@outlook.com>
1 parent 63b7b79 commit da606dd

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

src/function_wrappers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const wrapHttpFunction = (execute: HttpFunction): RequestHandler => {
131131
};
132132
};
133133

134-
const wrapHttpAsyncFunction = (
134+
const wrapOpenFunction = (
135135
userFunction: OpenFunction,
136136
context: OpenFunctionContext
137137
): RequestHandler => {
@@ -247,12 +247,12 @@ export const wrapUserFunction = <T = unknown>(
247247
): RequestHandler => {
248248
switch (signatureType) {
249249
case 'http':
250-
if (!isEmpty((context as OpenFunctionContext)?.outputs))
251-
return wrapHttpAsyncFunction(
252-
userFunction as OpenFunction,
253-
context as OpenFunctionContext
254-
);
255250
return wrapHttpFunction(userFunction as HttpFunction);
251+
case 'openfunction':
252+
return wrapOpenFunction(
253+
userFunction as OpenFunction,
254+
context as OpenFunctionContext
255+
);
256256
case 'event':
257257
// Callback style if user function has more than 2 arguments.
258258
if (userFunction!.length > 2) {

src/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ export const FUNCTION_STATUS_HEADER_FIELD = 'X-Google-Status';
1919
/**
2020
* List of function signature types that are supported by the framework.
2121
*/
22-
export const SignatureType = ['http', 'event', 'cloudevent'] as const;
22+
export const SignatureType = [
23+
'http',
24+
'event',
25+
'cloudevent',
26+
'openfunction',
27+
] as const;
2328

2429
/**
2530
* Union type of all valid function SignatureType values.

test/conformance/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"wait-on": "file:../../node_modules/wait-on"
88
},
99
"scripts": {
10-
"start": "functions-framework",
10+
"start": "functions-framework --target=writeHttp",
1111
"knative:async": "concurrently npm:knative:async:run:* npm:knative:async:test",
12-
"knative:async:run:func": "cross-env DEBUG=test:*,common:*,ofn:* env-cmd -e knative functions-framework --target=tryKnativeAsync",
12+
"knative:async:run:func": "cross-env DEBUG=test:*,common:*,ofn:* env-cmd -e knative functions-framework --signature-type=openfunction --target=tryKnativeAsync",
1313
"knative:async:run:dapr": "dapr run -H 3500 -d ../data/components/http --log-level warn",
1414
"knative:async:test": "wait-on tcp:3500 tcp:8080 && curl -s -d '{\"data\": \"hello\"}' -H 'Content-Type: application/json' localhost:8080",
1515
"async": "concurrently npm:async:run:*",

test/integration/http_binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('OpenFunction - HTTP Binding', () => {
8686
await ctx.send(data);
8787
return ctx.response(data);
8888
},
89-
'http',
89+
'openfunction',
9090
context
9191
);
9292

0 commit comments

Comments
 (0)