@faasjs/func 5.0.0-beta.1 → 5.0.0-beta.2
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/package.json +6 -6
- package/dist/index.d.cts +0 -163
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/func",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"import": {
|
|
12
|
-
"types": "./dist/index.d.
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
13
|
"default": "./dist/index.mjs"
|
|
14
14
|
},
|
|
15
15
|
"require": {
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@faasjs/deep_merge": "5.0.0-beta.
|
|
39
|
-
"@faasjs/logger": "5.0.0-beta.
|
|
38
|
+
"@faasjs/deep_merge": "5.0.0-beta.2",
|
|
39
|
+
"@faasjs/logger": "5.0.0-beta.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@faasjs/deep_merge": "5.0.0-beta.
|
|
43
|
-
"@faasjs/logger": "5.0.0-beta.
|
|
42
|
+
"@faasjs/deep_merge": "5.0.0-beta.2",
|
|
43
|
+
"@faasjs/logger": "5.0.0-beta.2"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=22.0.0",
|
package/dist/index.d.cts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@faasjs/logger';
|
|
2
|
-
|
|
3
|
-
type Handler<TEvent = any, TContext = any, TResult = any> = (data: InvokeData<TEvent, TContext>) => Promise<TResult>;
|
|
4
|
-
type Next = () => Promise<void>;
|
|
5
|
-
type ExportedHandler<TEvent = any, TContext = any, TResult = any> = (event?: TEvent, context?: TContext, callback?: (...args: any) => any) => Promise<TResult>;
|
|
6
|
-
type Plugin = {
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
readonly type: string;
|
|
9
|
-
readonly name: string;
|
|
10
|
-
onMount?: (data: MountData, next: Next) => Promise<void>;
|
|
11
|
-
onInvoke?: (data: InvokeData, next: Next) => Promise<void>;
|
|
12
|
-
};
|
|
13
|
-
type Config = {
|
|
14
|
-
[key: string]: any;
|
|
15
|
-
plugins?: {
|
|
16
|
-
[key: string]: {
|
|
17
|
-
[key: string]: any;
|
|
18
|
-
type: string;
|
|
19
|
-
config?: {
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
type MountData = {
|
|
26
|
-
[key: string]: any;
|
|
27
|
-
config: Config;
|
|
28
|
-
event: any;
|
|
29
|
-
context: any;
|
|
30
|
-
};
|
|
31
|
-
type InvokeData<TEvent = any, TContext = any, TResult = any> = {
|
|
32
|
-
[key: string]: any;
|
|
33
|
-
event: TEvent;
|
|
34
|
-
context: TContext;
|
|
35
|
-
callback: any;
|
|
36
|
-
response: any;
|
|
37
|
-
logger: Logger;
|
|
38
|
-
handler?: Handler<TEvent, TContext, TResult>;
|
|
39
|
-
config: Config;
|
|
40
|
-
};
|
|
41
|
-
type LifeCycleKey = 'onMount' | 'onInvoke';
|
|
42
|
-
type FuncConfig<TEvent = any, TContext = any, TResult = any> = {
|
|
43
|
-
plugins?: Plugin[];
|
|
44
|
-
handler?: Handler<TEvent, TContext, TResult>;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Get the event type of a func
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```ts
|
|
51
|
-
* import { useFunc, type FuncEventType } from '@faasjs/func'
|
|
52
|
-
*
|
|
53
|
-
* const func = useFunc<{ counter: number }>(() => async () => {})
|
|
54
|
-
*
|
|
55
|
-
* FuncEventType<typeof func> // => { counter: number }
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
type FuncEventType<T extends Func<any, any, any>> = T extends Func<infer P, any, any> ? P : any;
|
|
59
|
-
/**
|
|
60
|
-
* Get the return type of a func
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* import { useFunc, type FuncReturnType } from '@faasjs/func'
|
|
65
|
-
*
|
|
66
|
-
* const func = useFunc(() => async () => 1)
|
|
67
|
-
*
|
|
68
|
-
* FuncReturnType<typeof func> // => number
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
type FuncReturnType<T extends Func<any, any, any>> = T extends Func<any, any, infer R> ? R : any;
|
|
72
|
-
declare class Func<TEvent = any, TContext = any, TResult = any> {
|
|
73
|
-
[key: string]: any;
|
|
74
|
-
plugins: Plugin[];
|
|
75
|
-
handler?: Handler<TEvent, TContext, TResult>;
|
|
76
|
-
config: Config;
|
|
77
|
-
mounted: boolean;
|
|
78
|
-
filename?: string;
|
|
79
|
-
private cachedFunctions;
|
|
80
|
-
/**
|
|
81
|
-
* Create a cloud function
|
|
82
|
-
* @param config {object} config
|
|
83
|
-
* @param config.plugins {Plugin[]} plugins list
|
|
84
|
-
* @param config.handler {Handler} business logic
|
|
85
|
-
*/
|
|
86
|
-
constructor(config: FuncConfig<TEvent, TContext>);
|
|
87
|
-
private compose;
|
|
88
|
-
/**
|
|
89
|
-
* First time mount the function
|
|
90
|
-
*/
|
|
91
|
-
mount(data?: {
|
|
92
|
-
event: TEvent;
|
|
93
|
-
context: TContext;
|
|
94
|
-
config?: Config;
|
|
95
|
-
logger?: Logger;
|
|
96
|
-
}): Promise<void>;
|
|
97
|
-
/**
|
|
98
|
-
* Invoke the function
|
|
99
|
-
* @param data {object} data
|
|
100
|
-
*/
|
|
101
|
-
invoke(data: InvokeData<TEvent, TContext, TResult>): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
* Export the function
|
|
104
|
-
*/
|
|
105
|
-
export(): {
|
|
106
|
-
handler: ExportedHandler<TEvent, TContext, TResult>;
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
type UseifyPlugin<T> = T & {
|
|
110
|
-
mount: (data?: MountData) => Promise<T>;
|
|
111
|
-
};
|
|
112
|
-
declare function usePlugin<T extends Plugin>(plugin: T & {
|
|
113
|
-
mount?: (data?: MountData) => Promise<T>;
|
|
114
|
-
}): UseifyPlugin<T>;
|
|
115
|
-
/**
|
|
116
|
-
* Create a cloud function.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* // pure function
|
|
121
|
-
* export default useFunc(() => {
|
|
122
|
-
* return () => {
|
|
123
|
-
* return 'Hello World'
|
|
124
|
-
* }
|
|
125
|
-
* })
|
|
126
|
-
*
|
|
127
|
-
* // with http
|
|
128
|
-
* import { useHttp } from '@faasjs/http'
|
|
129
|
-
*
|
|
130
|
-
* export default useFunc<{
|
|
131
|
-
* params: { name: string }
|
|
132
|
-
* }>(() => {
|
|
133
|
-
* useHttp()
|
|
134
|
-
*
|
|
135
|
-
* return ({ event }) => {
|
|
136
|
-
* return `Hello ${event.params.name}`
|
|
137
|
-
* }
|
|
138
|
-
* })
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
declare function useFunc<TEvent = any, TContext = any, TResult = any>(handler: () => Handler<TEvent, TContext, TResult>): Func<TEvent, TContext, TResult>;
|
|
142
|
-
/**
|
|
143
|
-
* Assigns a name to a given function handler, which will be displayed in logs and error messages.
|
|
144
|
-
*
|
|
145
|
-
* @template T - The type of the function handler.
|
|
146
|
-
* @param {string} name - The name to assign to the function handler.
|
|
147
|
-
* @param {T} handler - The function handler to which the name will be assigned.
|
|
148
|
-
* @returns {T} - The original function handler with the assigned name.
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```ts
|
|
152
|
-
* import { nameFunc } from '@faasjs/func'
|
|
153
|
-
*
|
|
154
|
-
* const handler = nameFunc('myHandler', () => {
|
|
155
|
-
* return 'Hello World'
|
|
156
|
-
* })
|
|
157
|
-
*
|
|
158
|
-
* console.log(handler.name) // => 'myHandler'
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
declare function nameFunc<T extends (...args: any[]) => any>(name: string, handler: T): T;
|
|
162
|
-
|
|
163
|
-
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, nameFunc, useFunc, usePlugin };
|