@faasjs/func 4.3.0 → 4.5.0
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 +1 -0
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +8 -5
- package/dist/index.mjs +8 -6
- package/package.json +5 -5
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -139,5 +139,25 @@ declare function usePlugin<T extends Plugin>(plugin: T & {
|
|
|
139
139
|
* ```
|
|
140
140
|
*/
|
|
141
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;
|
|
142
162
|
|
|
143
|
-
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, useFunc, usePlugin };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -139,5 +139,25 @@ declare function usePlugin<T extends Plugin>(plugin: T & {
|
|
|
139
139
|
* ```
|
|
140
140
|
*/
|
|
141
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;
|
|
142
162
|
|
|
143
|
-
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, useFunc, usePlugin };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var RunHandler = class {
|
|
|
26
26
|
data.response = error;
|
|
27
27
|
}
|
|
28
28
|
data.runHandler = true;
|
|
29
|
-
} else data.logger.warn("
|
|
29
|
+
} else data.logger.warn("handler has been run");
|
|
30
30
|
await next();
|
|
31
31
|
}
|
|
32
32
|
};
|
|
@@ -81,7 +81,7 @@ var Func = class {
|
|
|
81
81
|
let fn = list[i];
|
|
82
82
|
if (i === list.length) fn = next;
|
|
83
83
|
if (!fn) return Promise.resolve();
|
|
84
|
-
if (typeof fn.key === "undefined") fn.key = `
|
|
84
|
+
if (typeof fn.key === "undefined") fn.key = `uname#${i}`;
|
|
85
85
|
if (!data.context) data.context = /* @__PURE__ */ Object.create(null);
|
|
86
86
|
if (!data.context.request_at)
|
|
87
87
|
data.context.request_at = crypto.randomBytes(16).toString("hex");
|
|
@@ -120,7 +120,7 @@ var Func = class {
|
|
|
120
120
|
}
|
|
121
121
|
if (!data.config) data.config = this.config;
|
|
122
122
|
data.logger.debug(
|
|
123
|
-
`
|
|
123
|
+
`plugins: ${this.plugins.map((p) => `${p.type}#${p.name}`).join(",")}`
|
|
124
124
|
);
|
|
125
125
|
await this.compose("onMount")(data);
|
|
126
126
|
this.mounted = true;
|
|
@@ -150,8 +150,6 @@ var Func = class {
|
|
|
150
150
|
context.request_at = crypto.randomBytes(16).toString("hex");
|
|
151
151
|
context.callbackWaitsForEmptyEventLoop = false;
|
|
152
152
|
const logger$1 = new logger.Logger(context.request_id);
|
|
153
|
-
logger$1.debug("event: %j", event);
|
|
154
|
-
logger$1.debug("context: %j", context);
|
|
155
153
|
const data = {
|
|
156
154
|
event,
|
|
157
155
|
context,
|
|
@@ -197,7 +195,12 @@ function useFunc(handler) {
|
|
|
197
195
|
plugins = [];
|
|
198
196
|
return func;
|
|
199
197
|
}
|
|
198
|
+
function nameFunc(name, handler) {
|
|
199
|
+
Object.defineProperty(handler, "name", { value: name });
|
|
200
|
+
return handler;
|
|
201
|
+
}
|
|
200
202
|
|
|
201
203
|
exports.Func = Func;
|
|
204
|
+
exports.nameFunc = nameFunc;
|
|
202
205
|
exports.useFunc = useFunc;
|
|
203
206
|
exports.usePlugin = usePlugin;
|
package/dist/index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ var RunHandler = class {
|
|
|
24
24
|
data.response = error;
|
|
25
25
|
}
|
|
26
26
|
data.runHandler = true;
|
|
27
|
-
} else data.logger.warn("
|
|
27
|
+
} else data.logger.warn("handler has been run");
|
|
28
28
|
await next();
|
|
29
29
|
}
|
|
30
30
|
};
|
|
@@ -79,7 +79,7 @@ var Func = class {
|
|
|
79
79
|
let fn = list[i];
|
|
80
80
|
if (i === list.length) fn = next;
|
|
81
81
|
if (!fn) return Promise.resolve();
|
|
82
|
-
if (typeof fn.key === "undefined") fn.key = `
|
|
82
|
+
if (typeof fn.key === "undefined") fn.key = `uname#${i}`;
|
|
83
83
|
if (!data.context) data.context = /* @__PURE__ */ Object.create(null);
|
|
84
84
|
if (!data.context.request_at)
|
|
85
85
|
data.context.request_at = randomBytes(16).toString("hex");
|
|
@@ -118,7 +118,7 @@ var Func = class {
|
|
|
118
118
|
}
|
|
119
119
|
if (!data.config) data.config = this.config;
|
|
120
120
|
data.logger.debug(
|
|
121
|
-
`
|
|
121
|
+
`plugins: ${this.plugins.map((p) => `${p.type}#${p.name}`).join(",")}`
|
|
122
122
|
);
|
|
123
123
|
await this.compose("onMount")(data);
|
|
124
124
|
this.mounted = true;
|
|
@@ -148,8 +148,6 @@ var Func = class {
|
|
|
148
148
|
context.request_at = randomBytes(16).toString("hex");
|
|
149
149
|
context.callbackWaitsForEmptyEventLoop = false;
|
|
150
150
|
const logger = new Logger(context.request_id);
|
|
151
|
-
logger.debug("event: %j", event);
|
|
152
|
-
logger.debug("context: %j", context);
|
|
153
151
|
const data = {
|
|
154
152
|
event,
|
|
155
153
|
context,
|
|
@@ -195,5 +193,9 @@ function useFunc(handler) {
|
|
|
195
193
|
plugins = [];
|
|
196
194
|
return func;
|
|
197
195
|
}
|
|
196
|
+
function nameFunc(name, handler) {
|
|
197
|
+
Object.defineProperty(handler, "name", { value: name });
|
|
198
|
+
return handler;
|
|
199
|
+
}
|
|
198
200
|
|
|
199
|
-
export { Func, useFunc, usePlugin };
|
|
201
|
+
export { Func, nameFunc, useFunc, usePlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/func",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@faasjs/deep_merge": "4.
|
|
38
|
-
"@faasjs/logger": "4.
|
|
37
|
+
"@faasjs/deep_merge": "4.5.0",
|
|
38
|
+
"@faasjs/logger": "4.5.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@faasjs/deep_merge": "4.
|
|
42
|
-
"@faasjs/logger": "4.
|
|
41
|
+
"@faasjs/deep_merge": "4.5.0",
|
|
42
|
+
"@faasjs/logger": "4.5.0"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=22.0.0",
|