Skip to content

Commit 5d91417

Browse files
authored
✨ feat: enable plugin mechanism for async func (#70)
1 parent a32fa1c commit 5d91417

File tree

16 files changed

+1143
-62
lines changed

16 files changed

+1143
-62
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
**/node_modules
22
build/
33
test/data/esm_*
4+
test/data/plugins
45
docs/

docs/generated/api.json

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,88 @@
19131913
"endIndex": 2
19141914
}
19151915
},
1916+
{
1917+
"kind": "PropertySignature",
1918+
"canonicalReference": "@openfunction/functions-framework!OpenFunctionContext#postPlugins:member",
1919+
"docComment": "/**\n * Optional post function exec plugins.\n */\n",
1920+
"excerptTokens": [
1921+
{
1922+
"kind": "Content",
1923+
"text": "postPlugins?: "
1924+
},
1925+
{
1926+
"kind": "Reference",
1927+
"text": "Array",
1928+
"canonicalReference": "!Array:interface"
1929+
},
1930+
{
1931+
"kind": "Content",
1932+
"text": "<string | "
1933+
},
1934+
{
1935+
"kind": "Reference",
1936+
"text": "Plugin",
1937+
"canonicalReference": "@openfunction/functions-framework!Plugin:class"
1938+
},
1939+
{
1940+
"kind": "Content",
1941+
"text": " | undefined>"
1942+
},
1943+
{
1944+
"kind": "Content",
1945+
"text": ";"
1946+
}
1947+
],
1948+
"isReadonly": false,
1949+
"isOptional": true,
1950+
"releaseTag": "Public",
1951+
"name": "postPlugins",
1952+
"propertyTypeTokenRange": {
1953+
"startIndex": 1,
1954+
"endIndex": 5
1955+
}
1956+
},
1957+
{
1958+
"kind": "PropertySignature",
1959+
"canonicalReference": "@openfunction/functions-framework!OpenFunctionContext#prePlugins:member",
1960+
"docComment": "/**\n * Optional pre function exec plugins.\n */\n",
1961+
"excerptTokens": [
1962+
{
1963+
"kind": "Content",
1964+
"text": "prePlugins?: "
1965+
},
1966+
{
1967+
"kind": "Reference",
1968+
"text": "Array",
1969+
"canonicalReference": "!Array:interface"
1970+
},
1971+
{
1972+
"kind": "Content",
1973+
"text": "<string | "
1974+
},
1975+
{
1976+
"kind": "Reference",
1977+
"text": "Plugin",
1978+
"canonicalReference": "@openfunction/functions-framework!Plugin:class"
1979+
},
1980+
{
1981+
"kind": "Content",
1982+
"text": " | undefined>"
1983+
},
1984+
{
1985+
"kind": "Content",
1986+
"text": ";"
1987+
}
1988+
],
1989+
"isReadonly": false,
1990+
"isOptional": true,
1991+
"releaseTag": "Public",
1992+
"name": "prePlugins",
1993+
"propertyTypeTokenRange": {
1994+
"startIndex": 1,
1995+
"endIndex": 5
1996+
}
1997+
},
19161998
{
19171999
"kind": "PropertySignature",
19182000
"canonicalReference": "@openfunction/functions-framework!OpenFunctionContext#runtime:member",
@@ -2489,6 +2571,234 @@
24892571
],
24902572
"implementsTokenRanges": []
24912573
},
2574+
{
2575+
"kind": "Class",
2576+
"canonicalReference": "@openfunction/functions-framework!Plugin_2:class",
2577+
"docComment": "/**\n * The OpenFunction's plugin template.\n *\n * @public\n */\n",
2578+
"excerptTokens": [
2579+
{
2580+
"kind": "Content",
2581+
"text": "export declare class Plugin "
2582+
}
2583+
],
2584+
"releaseTag": "Public",
2585+
"name": "Plugin_2",
2586+
"preserveMemberOrder": false,
2587+
"members": [
2588+
{
2589+
"kind": "Method",
2590+
"canonicalReference": "@openfunction/functions-framework!Plugin_2#execPostHook:member(1)",
2591+
"docComment": "/**\n * post main function exec.\n *\n * @param ctx - The openfunction runtime .\n */\n",
2592+
"excerptTokens": [
2593+
{
2594+
"kind": "Content",
2595+
"text": "execPostHook(ctx?: "
2596+
},
2597+
{
2598+
"kind": "Reference",
2599+
"text": "OpenFunctionRuntime",
2600+
"canonicalReference": "@openfunction/functions-framework!OpenFunctionRuntime:class"
2601+
},
2602+
{
2603+
"kind": "Content",
2604+
"text": "): "
2605+
},
2606+
{
2607+
"kind": "Reference",
2608+
"text": "Promise",
2609+
"canonicalReference": "!Promise:interface"
2610+
},
2611+
{
2612+
"kind": "Content",
2613+
"text": "<void>"
2614+
},
2615+
{
2616+
"kind": "Content",
2617+
"text": ";"
2618+
}
2619+
],
2620+
"isStatic": false,
2621+
"returnTypeTokenRange": {
2622+
"startIndex": 3,
2623+
"endIndex": 5
2624+
},
2625+
"releaseTag": "Public",
2626+
"isProtected": false,
2627+
"overloadIndex": 1,
2628+
"parameters": [
2629+
{
2630+
"parameterName": "ctx",
2631+
"parameterTypeTokenRange": {
2632+
"startIndex": 1,
2633+
"endIndex": 2
2634+
},
2635+
"isOptional": true
2636+
}
2637+
],
2638+
"isOptional": false,
2639+
"name": "execPostHook"
2640+
},
2641+
{
2642+
"kind": "Method",
2643+
"canonicalReference": "@openfunction/functions-framework!Plugin_2#execPreHook:member(1)",
2644+
"docComment": "/**\n * pre main function exec.\n *\n * @param ctx - The openfunction runtime .\n */\n",
2645+
"excerptTokens": [
2646+
{
2647+
"kind": "Content",
2648+
"text": "execPreHook(ctx?: "
2649+
},
2650+
{
2651+
"kind": "Reference",
2652+
"text": "OpenFunctionRuntime",
2653+
"canonicalReference": "@openfunction/functions-framework!OpenFunctionRuntime:class"
2654+
},
2655+
{
2656+
"kind": "Content",
2657+
"text": "): "
2658+
},
2659+
{
2660+
"kind": "Reference",
2661+
"text": "Promise",
2662+
"canonicalReference": "!Promise:interface"
2663+
},
2664+
{
2665+
"kind": "Content",
2666+
"text": "<void>"
2667+
},
2668+
{
2669+
"kind": "Content",
2670+
"text": ";"
2671+
}
2672+
],
2673+
"isStatic": false,
2674+
"returnTypeTokenRange": {
2675+
"startIndex": 3,
2676+
"endIndex": 5
2677+
},
2678+
"releaseTag": "Public",
2679+
"isProtected": false,
2680+
"overloadIndex": 1,
2681+
"parameters": [
2682+
{
2683+
"parameterName": "ctx",
2684+
"parameterTypeTokenRange": {
2685+
"startIndex": 1,
2686+
"endIndex": 2
2687+
},
2688+
"isOptional": true
2689+
}
2690+
],
2691+
"isOptional": false,
2692+
"name": "execPreHook"
2693+
},
2694+
{
2695+
"kind": "Method",
2696+
"canonicalReference": "@openfunction/functions-framework!Plugin_2#get:member(1)",
2697+
"docComment": "/**\n * get instance filed value.\n *\n * @param filedName - the instace filedName\n *\n * @returns filed value.\n */\n",
2698+
"excerptTokens": [
2699+
{
2700+
"kind": "Content",
2701+
"text": "get(filedName: "
2702+
},
2703+
{
2704+
"kind": "Content",
2705+
"text": "string"
2706+
},
2707+
{
2708+
"kind": "Content",
2709+
"text": "): "
2710+
},
2711+
{
2712+
"kind": "Content",
2713+
"text": "string"
2714+
},
2715+
{
2716+
"kind": "Content",
2717+
"text": ";"
2718+
}
2719+
],
2720+
"isStatic": false,
2721+
"returnTypeTokenRange": {
2722+
"startIndex": 3,
2723+
"endIndex": 4
2724+
},
2725+
"releaseTag": "Public",
2726+
"isProtected": false,
2727+
"overloadIndex": 1,
2728+
"parameters": [
2729+
{
2730+
"parameterName": "filedName",
2731+
"parameterTypeTokenRange": {
2732+
"startIndex": 1,
2733+
"endIndex": 2
2734+
},
2735+
"isOptional": false
2736+
}
2737+
],
2738+
"isOptional": false,
2739+
"name": "get"
2740+
},
2741+
{
2742+
"kind": "Property",
2743+
"canonicalReference": "@openfunction/functions-framework!Plugin_2.OFN_PLUGIN_NAME:member",
2744+
"docComment": "",
2745+
"excerptTokens": [
2746+
{
2747+
"kind": "Content",
2748+
"text": "static OFN_PLUGIN_NAME: "
2749+
},
2750+
{
2751+
"kind": "Content",
2752+
"text": "string"
2753+
},
2754+
{
2755+
"kind": "Content",
2756+
"text": ";"
2757+
}
2758+
],
2759+
"isReadonly": false,
2760+
"isOptional": false,
2761+
"releaseTag": "Public",
2762+
"name": "OFN_PLUGIN_NAME",
2763+
"propertyTypeTokenRange": {
2764+
"startIndex": 1,
2765+
"endIndex": 2
2766+
},
2767+
"isStatic": true,
2768+
"isProtected": false
2769+
},
2770+
{
2771+
"kind": "Property",
2772+
"canonicalReference": "@openfunction/functions-framework!Plugin_2.OFN_PLUGIN_VERSION:member",
2773+
"docComment": "",
2774+
"excerptTokens": [
2775+
{
2776+
"kind": "Content",
2777+
"text": "static OFN_PLUGIN_VERSION: "
2778+
},
2779+
{
2780+
"kind": "Content",
2781+
"text": "string"
2782+
},
2783+
{
2784+
"kind": "Content",
2785+
"text": ";"
2786+
}
2787+
],
2788+
"isReadonly": false,
2789+
"isOptional": false,
2790+
"releaseTag": "Public",
2791+
"name": "OFN_PLUGIN_VERSION",
2792+
"propertyTypeTokenRange": {
2793+
"startIndex": 1,
2794+
"endIndex": 2
2795+
},
2796+
"isStatic": true,
2797+
"isProtected": false
2798+
}
2799+
],
2800+
"implementsTokenRanges": []
2801+
},
24922802
{
24932803
"kind": "Interface",
24942804
"canonicalReference": "@openfunction/functions-framework!Request_2:interface",

docs/generated/api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export interface OpenFunctionContext {
136136
name: string;
137137
outputs?: OpenFunctionBinding;
138138
port?: string;
139+
postPlugins?: Array<string | Plugin_2 | undefined>;
140+
prePlugins?: Array<string | Plugin_2 | undefined>;
139141
runtime: `${RuntimeType}` | `${Capitalize<RuntimeType>}` | `${Uppercase<RuntimeType>}`;
140142
version: string;
141143
}
@@ -158,6 +160,18 @@ export abstract class OpenFunctionRuntime {
158160
protected trigger?: OpenFunctionTrigger;
159161
}
160162

163+
// @public
164+
class Plugin_2 {
165+
execPostHook(ctx?: OpenFunctionRuntime): Promise<void>;
166+
execPreHook(ctx?: OpenFunctionRuntime): Promise<void>;
167+
get(filedName: string): string;
168+
// (undocumented)
169+
static OFN_PLUGIN_NAME: string;
170+
// (undocumented)
171+
static OFN_PLUGIN_VERSION: string;
172+
}
173+
export { Plugin_2 as Plugin }
174+
161175
// @public (undocumented)
162176
interface Request_2 extends Request_3 {
163177
rawBody?: Buffer;

0 commit comments

Comments
 (0)