@faasjs/func 8.0.0-beta.6 → 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 +0 -1
- package/dist/index.cjs +251 -308
- package/dist/index.d.ts +74 -110
- 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
|
|
@@ -111,18 +93,15 @@ type FuncEventType<T extends Func<any, any, any>> = T extends Func<infer P, any,
|
|
|
111
93
|
*/
|
|
112
94
|
type FuncReturnType<T extends Func<any, any, any>> = T extends Func<any, any, infer R> ? R : any;
|
|
113
95
|
type NormalizePluginType<TType extends string> = TType extends `npm:${infer Name}` ? Name : TType extends `@faasjs/${infer Name}` ? Name : TType;
|
|
114
|
-
type UnionToIntersection<T> = (T extends unknown ? (arg: T) => void : never) extends (arg: infer TResult) => void ? TResult : never;
|
|
115
|
-
type Simplify<T> = {
|
|
116
|
-
[K in keyof T]: T[K];
|
|
117
|
-
} & {};
|
|
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] } & {};
|
|
118
98
|
/**
|
|
119
99
|
* Plugin event augmentation map.
|
|
120
100
|
*
|
|
121
101
|
* Extend this interface in plugin packages to describe which event fields are
|
|
122
102
|
* injected when the plugin is enabled through `faas.yaml`.
|
|
123
103
|
*/
|
|
124
|
-
interface FaasPluginEventMap {
|
|
125
|
-
}
|
|
104
|
+
interface FaasPluginEventMap {}
|
|
126
105
|
type ResolvePluginEvent<TType extends string> = NormalizePluginType<TType> extends keyof FaasPluginEventMap ? FaasPluginEventMap[NormalizePluginType<TType>] : Record<never, never>;
|
|
127
106
|
/**
|
|
128
107
|
* Infer event type from plugin type names.
|
|
@@ -135,52 +114,47 @@ type ResolvePluginEvent<TType extends string> = NormalizePluginType<TType> exten
|
|
|
135
114
|
type InferPluginEvent<TPlugins extends readonly string[]> = Simplify<Record<string, any> & UnionToIntersection<ResolvePluginEvent<TPlugins[number]>>>;
|
|
136
115
|
declare function parseFuncFilenameFromStack(stack?: string): string | undefined;
|
|
137
116
|
declare class Func<TEvent = any, TContext = any, TResult = any> {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
* Export the function
|
|
174
|
-
*/
|
|
175
|
-
export(): {
|
|
176
|
-
handler: ExportedHandler<TEvent, TContext, TResult>;
|
|
177
|
-
};
|
|
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
|
+
};
|
|
178
152
|
}
|
|
179
153
|
type UseifyPlugin<T> = T & {
|
|
180
|
-
|
|
154
|
+
mount: (data?: MountData) => Promise<T>;
|
|
181
155
|
};
|
|
182
156
|
declare function usePlugin<T extends Plugin>(plugin: T & {
|
|
183
|
-
|
|
157
|
+
mount?: (data?: MountData) => Promise<T>;
|
|
184
158
|
}): UseifyPlugin<T>;
|
|
185
159
|
/**
|
|
186
160
|
* Create a cloud function.
|
|
@@ -209,15 +183,5 @@ declare function usePlugin<T extends Plugin>(plugin: T & {
|
|
|
209
183
|
* ```
|
|
210
184
|
*/
|
|
211
185
|
declare function useFunc<TEvent = any, TContext = any, TResult = any>(handler: () => Handler<TEvent, TContext, TResult>): Func<TEvent, TContext, TResult>;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
* `func.config.plugins`.
|
|
215
|
-
*
|
|
216
|
-
* `defineFunc` receives business logic directly (no wrapper function), and
|
|
217
|
-
* resolves plugin modules during the first mount based on config from
|
|
218
|
-
* `faas.yaml` (already loaded into `func.config` by `@faasjs/load`,
|
|
219
|
-
* `@faasjs/server`, or `@faasjs/dev`).
|
|
220
|
-
*/
|
|
221
|
-
declare function defineFunc<TEvent = any, TContext = any, TResult = any>(handler: Handler<TEvent, TContext, TResult>): Func<TEvent, TContext, TResult>;
|
|
222
|
-
|
|
223
|
-
export { type Config, type ExportedHandler, type FaasPluginEventMap, Func, type FuncConfig, type FuncEventType, type FuncReturnType, type Handler, type InferPluginEvent, type InvokeData, type LifeCycleKey, type MountData, type Next, type NormalizePluginType, type Plugin, type ResolvePluginEvent, type Simplify, type UnionToIntersection, 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 };
|