@faasjs/func 8.0.0-beta.5 → 8.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -1
- package/dist/index.cjs +251 -308
- package/dist/index.d.ts +91 -104
- package/dist/index.mjs +250 -305
- package/package.json +4 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Logger } from
|
|
1
|
+
import { Logger } from "@faasjs/logger";
|
|
2
2
|
|
|
3
|
+
//#region src/utils.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Assigns a name to a given function handler, which will be displayed in logs and error messages.
|
|
5
6
|
*
|
|
@@ -20,69 +21,50 @@ import { Logger } from '@faasjs/logger';
|
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
23
|
declare function nameFunc<T extends (...args: any[]) => any>(name: string, handler: T): T;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* FaasJS's function module.
|
|
26
|
-
*
|
|
27
|
-
* [](https://github.com/faasjs/faasjs/blob/main/packages/func/LICENSE)
|
|
28
|
-
* [](https://www.npmjs.com/package/@faasjs/func)
|
|
29
|
-
*
|
|
30
|
-
* ## Install
|
|
31
|
-
*
|
|
32
|
-
* ```sh
|
|
33
|
-
* npm install @faasjs/func
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* ## Usage
|
|
37
|
-
*
|
|
38
|
-
* @see {@link useFunc}
|
|
39
|
-
*
|
|
40
|
-
* @packageDocumentation
|
|
41
|
-
*/
|
|
42
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/index.d.ts
|
|
43
26
|
type Handler<TEvent = any, TContext = any, TResult = any> = (data: InvokeData<TEvent, TContext>) => Promise<TResult>;
|
|
44
27
|
type Next = () => Promise<void>;
|
|
45
28
|
type ExportedHandler<TEvent = any, TContext = any, TResult = any> = (event?: TEvent, context?: TContext, callback?: (...args: any) => any) => Promise<TResult>;
|
|
46
29
|
type Plugin = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
readonly type: string;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
onMount?: (data: MountData, next: Next) => Promise<void>;
|
|
34
|
+
onInvoke?: (data: InvokeData, next: Next) => Promise<void>;
|
|
52
35
|
};
|
|
53
36
|
type Config = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
plugins?: {
|
|
39
|
+
[key: string]: {
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
type?: string;
|
|
42
|
+
config?: {
|
|
43
|
+
[key: string]: any;
|
|
44
|
+
};
|
|
63
45
|
};
|
|
46
|
+
};
|
|
64
47
|
};
|
|
65
48
|
type MountData = {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
config: Config;
|
|
51
|
+
event: any;
|
|
52
|
+
context: any;
|
|
70
53
|
};
|
|
71
54
|
type InvokeData<TEvent = any, TContext = any, TResult = any> = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
event: TEvent;
|
|
57
|
+
context: TContext;
|
|
58
|
+
callback: any;
|
|
59
|
+
response: any;
|
|
60
|
+
logger: Logger;
|
|
61
|
+
handler?: Handler<TEvent, TContext, TResult>;
|
|
62
|
+
config: Config;
|
|
80
63
|
};
|
|
81
64
|
type LifeCycleKey = 'onMount' | 'onInvoke';
|
|
82
65
|
type FuncConfig<TEvent = any, TContext = any, TResult = any> = {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
autoLoadPluginsFromConfig?: boolean;
|
|
66
|
+
plugins?: Plugin[];
|
|
67
|
+
handler?: Handler<TEvent, TContext, TResult>;
|
|
86
68
|
};
|
|
87
69
|
/**
|
|
88
70
|
* Get the event type of a func
|
|
@@ -110,54 +92,69 @@ type FuncEventType<T extends Func<any, any, any>> = T extends Func<infer P, any,
|
|
|
110
92
|
* ```
|
|
111
93
|
*/
|
|
112
94
|
type FuncReturnType<T extends Func<any, any, any>> = T extends Func<any, any, infer R> ? R : any;
|
|
95
|
+
type NormalizePluginType<TType extends string> = TType extends `npm:${infer Name}` ? Name : TType extends `@faasjs/${infer Name}` ? Name : TType;
|
|
96
|
+
type UnionToIntersection<T> = (T extends unknown ? (arg: T) => void : never) extends ((arg: infer TResult) => void) ? TResult : never;
|
|
97
|
+
type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
98
|
+
/**
|
|
99
|
+
* Plugin event augmentation map.
|
|
100
|
+
*
|
|
101
|
+
* Extend this interface in plugin packages to describe which event fields are
|
|
102
|
+
* injected when the plugin is enabled through `faas.yaml`.
|
|
103
|
+
*/
|
|
104
|
+
interface FaasPluginEventMap {}
|
|
105
|
+
type ResolvePluginEvent<TType extends string> = NormalizePluginType<TType> extends keyof FaasPluginEventMap ? FaasPluginEventMap[NormalizePluginType<TType>] : Record<never, never>;
|
|
106
|
+
/**
|
|
107
|
+
* Infer event type from plugin type names.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* type Event = InferPluginEvent<['http']>
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
type InferPluginEvent<TPlugins extends readonly string[]> = Simplify<Record<string, any> & UnionToIntersection<ResolvePluginEvent<TPlugins[number]>>>;
|
|
113
115
|
declare function parseFuncFilenameFromStack(stack?: string): string | undefined;
|
|
114
116
|
declare class Func<TEvent = any, TContext = any, TResult = any> {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
* Export the function
|
|
151
|
-
*/
|
|
152
|
-
export(): {
|
|
153
|
-
handler: ExportedHandler<TEvent, TContext, TResult>;
|
|
154
|
-
};
|
|
117
|
+
[key: string]: any;
|
|
118
|
+
plugins: Plugin[];
|
|
119
|
+
handler?: Handler<TEvent, TContext, TResult>;
|
|
120
|
+
config: Config;
|
|
121
|
+
mounted: boolean;
|
|
122
|
+
filename?: string;
|
|
123
|
+
private cachedFunctions;
|
|
124
|
+
/**
|
|
125
|
+
* Create a cloud function
|
|
126
|
+
* @param config {object} config
|
|
127
|
+
* @param config.plugins {Plugin[]} plugins list
|
|
128
|
+
* @param config.handler {Handler} business logic
|
|
129
|
+
*/
|
|
130
|
+
constructor(config: FuncConfig<TEvent, TContext>);
|
|
131
|
+
private compose;
|
|
132
|
+
/**
|
|
133
|
+
* First time mount the function
|
|
134
|
+
*/
|
|
135
|
+
mount(data?: {
|
|
136
|
+
event: TEvent;
|
|
137
|
+
context: TContext;
|
|
138
|
+
config?: Config;
|
|
139
|
+
logger?: Logger;
|
|
140
|
+
}): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Invoke the function
|
|
143
|
+
* @param data {object} data
|
|
144
|
+
*/
|
|
145
|
+
invoke(data: InvokeData<TEvent, TContext, TResult>): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Export the function
|
|
148
|
+
*/
|
|
149
|
+
export(): {
|
|
150
|
+
handler: ExportedHandler<TEvent, TContext, TResult>;
|
|
151
|
+
};
|
|
155
152
|
}
|
|
156
153
|
type UseifyPlugin<T> = T & {
|
|
157
|
-
|
|
154
|
+
mount: (data?: MountData) => Promise<T>;
|
|
158
155
|
};
|
|
159
156
|
declare function usePlugin<T extends Plugin>(plugin: T & {
|
|
160
|
-
|
|
157
|
+
mount?: (data?: MountData) => Promise<T>;
|
|
161
158
|
}): UseifyPlugin<T>;
|
|
162
159
|
/**
|
|
163
160
|
* Create a cloud function.
|
|
@@ -186,15 +183,5 @@ declare function usePlugin<T extends Plugin>(plugin: T & {
|
|
|
186
183
|
* ```
|
|
187
184
|
*/
|
|
188
185
|
declare function useFunc<TEvent = any, TContext = any, TResult = any>(handler: () => Handler<TEvent, TContext, TResult>): Func<TEvent, TContext, TResult>;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
* `func.config.plugins`.
|
|
192
|
-
*
|
|
193
|
-
* `defineFunc` receives business logic directly (no wrapper function), and
|
|
194
|
-
* resolves plugin modules during the first mount based on config from
|
|
195
|
-
* `faas.yaml` (already loaded into `func.config` by `@faasjs/load`,
|
|
196
|
-
* `@faasjs/server`, or `@faasjs/dev`).
|
|
197
|
-
*/
|
|
198
|
-
declare function defineFunc<TEvent = any, TContext = any, TResult = any>(handler: Handler<TEvent, TContext, TResult>): Func<TEvent, TContext, TResult>;
|
|
199
|
-
|
|
200
|
-
export { type Config, type ExportedHandler, Func, type FuncConfig, type FuncEventType, type FuncReturnType, type Handler, type InvokeData, type LifeCycleKey, type MountData, type Next, type Plugin, type UseifyPlugin, defineFunc, nameFunc, parseFuncFilenameFromStack, useFunc, usePlugin };
|
|
186
|
+
//#endregion
|
|
187
|
+
export { Config, ExportedHandler, FaasPluginEventMap, Func, FuncConfig, FuncEventType, FuncReturnType, Handler, InferPluginEvent, InvokeData, LifeCycleKey, MountData, Next, NormalizePluginType, Plugin, ResolvePluginEvent, Simplify, UnionToIntersection, UseifyPlugin, nameFunc, parseFuncFilenameFromStack, useFunc, usePlugin };
|