@faasjs/func 8.0.0-beta.6 → 8.0.0-beta.8

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/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { Logger } from '@faasjs/logger';
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
- * [![License: MIT](https://img.shields.io/npm/l/@faasjs/func.svg)](https://github.com/faasjs/faasjs/blob/main/packages/func/LICENSE)
28
- * [![NPM Version](https://img.shields.io/npm/v/@faasjs/func.svg)](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
- [key: string]: any;
48
- readonly type: string;
49
- readonly name: string;
50
- onMount?: (data: MountData, next: Next) => Promise<void>;
51
- onInvoke?: (data: InvokeData, next: Next) => Promise<void>;
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
- [key: string]: any;
55
- plugins?: {
56
- [key: string]: {
57
- [key: string]: any;
58
- type?: string;
59
- config?: {
60
- [key: string]: any;
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
- [key: string]: any;
67
- config: Config;
68
- event: any;
69
- context: any;
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
- [key: string]: any;
73
- event: TEvent;
74
- context: TContext;
75
- callback: any;
76
- response: any;
77
- logger: Logger;
78
- handler?: Handler<TEvent, TContext, TResult>;
79
- config: Config;
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
- plugins?: Plugin[];
84
- handler?: Handler<TEvent, TContext, TResult>;
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
- [key: string]: any;
139
- plugins: Plugin[];
140
- handler?: Handler<TEvent, TContext, TResult>;
141
- config: Config;
142
- mounted: boolean;
143
- filename?: string;
144
- private readonly autoLoadPluginsFromConfig;
145
- private loadedConfigPlugins;
146
- private cachedFunctions;
147
- /**
148
- * Create a cloud function
149
- * @param config {object} config
150
- * @param config.plugins {Plugin[]} plugins list
151
- * @param config.handler {Handler} business logic
152
- */
153
- constructor(config: FuncConfig<TEvent, TContext>);
154
- private insertPluginBeforeRunHandler;
155
- private resolvePluginConstructor;
156
- private loadPluginsFromConfig;
157
- private compose;
158
- /**
159
- * First time mount the function
160
- */
161
- mount(data?: {
162
- event: TEvent;
163
- context: TContext;
164
- config?: Config;
165
- logger?: Logger;
166
- }): Promise<void>;
167
- /**
168
- * Invoke the function
169
- * @param data {object} data
170
- */
171
- invoke(data: InvokeData<TEvent, TContext, TResult>): Promise<void>;
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
- mount: (data?: MountData) => Promise<T>;
154
+ mount: (data?: MountData) => Promise<T>;
181
155
  };
182
156
  declare function usePlugin<T extends Plugin>(plugin: T & {
183
- mount?: (data?: MountData) => Promise<T>;
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
- * Create a cloud function from business logic and auto-load plugins from
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 };