@faasjs/func 0.0.3-beta.99 → 0.0.4-beta.10
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 +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +28 -14
- package/dist/index.mjs +28 -14
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -239,9 +239,9 @@ ___
|
|
|
239
239
|
| Name | Type |
|
|
240
240
|
| :------ | :------ |
|
|
241
241
|
| `name` | `string` |
|
|
242
|
-
| `onDeploy?` | (`data`: [`DeployData`](#deploydata), `next`: [`Next`](#next)) => `
|
|
243
|
-
| `onInvoke?` | (`data`: [`InvokeData`](#invokedata), `next`: [`Next`](#next)) => `
|
|
244
|
-
| `onMount?` | (`data`: [`MountData`](#mountdata), `next`: [`Next`](#next)) => `
|
|
242
|
+
| `onDeploy?` | (`data`: [`DeployData`](#deploydata), `next`: [`Next`](#next)) => `Promise`<`void`\> |
|
|
243
|
+
| `onInvoke?` | (`data`: [`InvokeData`](#invokedata), `next`: [`Next`](#next)) => `Promise`<`void`\> |
|
|
244
|
+
| `onMount?` | (`data`: [`MountData`](#mountdata), `next`: [`Next`](#next)) => `Promise`<`void`\> |
|
|
245
245
|
| `type` | `string` |
|
|
246
246
|
|
|
247
247
|
___
|
package/dist/index.d.mts
CHANGED
|
@@ -7,9 +7,9 @@ type Plugin = {
|
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
readonly type: string;
|
|
9
9
|
readonly name: string;
|
|
10
|
-
onDeploy?: (data: DeployData, next: Next) =>
|
|
11
|
-
onMount?: (data: MountData, next: Next) =>
|
|
12
|
-
onInvoke?: (data: InvokeData, next: Next) =>
|
|
10
|
+
onDeploy?: (data: DeployData, next: Next) => Promise<void>;
|
|
11
|
+
onMount?: (data: MountData, next: Next) => Promise<void>;
|
|
12
|
+
onInvoke?: (data: InvokeData, next: Next) => Promise<void>;
|
|
13
13
|
};
|
|
14
14
|
type ProviderConfig = {
|
|
15
15
|
type: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ type Plugin = {
|
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
readonly type: string;
|
|
9
9
|
readonly name: string;
|
|
10
|
-
onDeploy?: (data: DeployData, next: Next) =>
|
|
11
|
-
onMount?: (data: MountData, next: Next) =>
|
|
12
|
-
onInvoke?: (data: InvokeData, next: Next) =>
|
|
10
|
+
onDeploy?: (data: DeployData, next: Next) => Promise<void>;
|
|
11
|
+
onMount?: (data: MountData, next: Next) => Promise<void>;
|
|
12
|
+
onInvoke?: (data: InvokeData, next: Next) => Promise<void>;
|
|
13
13
|
};
|
|
14
14
|
type ProviderConfig = {
|
|
15
15
|
type: string;
|
package/dist/index.js
CHANGED
|
@@ -89,7 +89,9 @@ var Func = class {
|
|
|
89
89
|
logger$1.debug("[%s][%s] begin", fn.key, key);
|
|
90
90
|
logger$1.time(fn.key);
|
|
91
91
|
try {
|
|
92
|
-
const res = await Promise.resolve(
|
|
92
|
+
const res = await Promise.resolve(
|
|
93
|
+
fn.handler(data, dispatch.bind(null, i + 1))
|
|
94
|
+
);
|
|
93
95
|
logger$1.timeEnd(fn.key, "[%s][%s] end", fn.key, key);
|
|
94
96
|
return res;
|
|
95
97
|
} catch (err) {
|
|
@@ -112,29 +114,37 @@ var Func = class {
|
|
|
112
114
|
if (!data.logger)
|
|
113
115
|
data.logger = new logger.Logger("Func");
|
|
114
116
|
data.logger.debug("onDeploy");
|
|
115
|
-
data.logger.debug(
|
|
117
|
+
data.logger.debug(
|
|
118
|
+
`Plugins: ${this.plugins.map((p) => `${p.type}#${p.name}`).join(",")}`
|
|
119
|
+
);
|
|
116
120
|
return this.compose("onDeploy")(data);
|
|
117
121
|
}
|
|
118
122
|
/**
|
|
119
123
|
* First time mount the function
|
|
120
124
|
*/
|
|
121
125
|
async mount(data) {
|
|
126
|
+
var _a;
|
|
122
127
|
if (!data.logger)
|
|
123
128
|
data.logger = new logger.Logger("Func");
|
|
124
|
-
data.logger.
|
|
129
|
+
const logger$1 = new logger.Logger(((_a = data.logger) == null ? void 0 : _a.label) || "Func");
|
|
130
|
+
if (!logger$1.label.endsWith("Func"))
|
|
131
|
+
logger$1.label = `${logger$1.label}] [Func`;
|
|
132
|
+
logger$1.debug("onMount");
|
|
125
133
|
if (this.mounted) {
|
|
126
|
-
|
|
134
|
+
logger$1.warn("mount() has been called, skipped.");
|
|
127
135
|
return;
|
|
128
136
|
}
|
|
129
137
|
if (!data.config)
|
|
130
138
|
data.config = this.config;
|
|
131
139
|
try {
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
logger$1.time("mount");
|
|
141
|
+
logger$1.debug(
|
|
142
|
+
`Plugins: ${this.plugins.map((p) => `${p.type}#${p.name}`).join(",")}`
|
|
143
|
+
);
|
|
134
144
|
await this.compose("onMount")(data);
|
|
135
145
|
this.mounted = true;
|
|
136
146
|
} finally {
|
|
137
|
-
|
|
147
|
+
logger$1.timeEnd("mount", "mounted");
|
|
138
148
|
}
|
|
139
149
|
}
|
|
140
150
|
/**
|
|
@@ -161,10 +171,11 @@ var Func = class {
|
|
|
161
171
|
*/
|
|
162
172
|
export() {
|
|
163
173
|
const handler = async (event, context, callback) => {
|
|
174
|
+
var _a;
|
|
164
175
|
if (typeof context === "undefined")
|
|
165
176
|
context = {};
|
|
166
177
|
if (!context.request_id)
|
|
167
|
-
context.request_id = crypto.randomBytes(16).toString("hex");
|
|
178
|
+
context.request_id = ((_a = event == null ? void 0 : event.headers) == null ? void 0 : _a["x-faasjs-request-id"]) || crypto.randomBytes(16).toString("hex");
|
|
168
179
|
if (!context.request_at)
|
|
169
180
|
context.request_at = Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
170
181
|
context.callbackWaitsForEmptyEventLoop = false;
|
|
@@ -196,12 +207,15 @@ function usePlugin(plugin) {
|
|
|
196
207
|
if (!plugin.mount)
|
|
197
208
|
plugin.mount = async function(data) {
|
|
198
209
|
if (plugin.onMount)
|
|
199
|
-
await plugin.onMount(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
210
|
+
await plugin.onMount(
|
|
211
|
+
{
|
|
212
|
+
config: (data == null ? void 0 : data.config) || /* @__PURE__ */ Object.create(null),
|
|
213
|
+
event: /* @__PURE__ */ Object.create(null),
|
|
214
|
+
context: /* @__PURE__ */ Object.create(null),
|
|
215
|
+
logger: new logger.Logger(plugin.name)
|
|
216
|
+
},
|
|
217
|
+
async () => Promise.resolve()
|
|
218
|
+
);
|
|
205
219
|
return plugin;
|
|
206
220
|
};
|
|
207
221
|
return plugin;
|
package/dist/index.mjs
CHANGED
|
@@ -87,7 +87,9 @@ var Func = class {
|
|
|
87
87
|
logger.debug("[%s][%s] begin", fn.key, key);
|
|
88
88
|
logger.time(fn.key);
|
|
89
89
|
try {
|
|
90
|
-
const res = await Promise.resolve(
|
|
90
|
+
const res = await Promise.resolve(
|
|
91
|
+
fn.handler(data, dispatch.bind(null, i + 1))
|
|
92
|
+
);
|
|
91
93
|
logger.timeEnd(fn.key, "[%s][%s] end", fn.key, key);
|
|
92
94
|
return res;
|
|
93
95
|
} catch (err) {
|
|
@@ -110,29 +112,37 @@ var Func = class {
|
|
|
110
112
|
if (!data.logger)
|
|
111
113
|
data.logger = new Logger("Func");
|
|
112
114
|
data.logger.debug("onDeploy");
|
|
113
|
-
data.logger.debug(
|
|
115
|
+
data.logger.debug(
|
|
116
|
+
`Plugins: ${this.plugins.map((p) => `${p.type}#${p.name}`).join(",")}`
|
|
117
|
+
);
|
|
114
118
|
return this.compose("onDeploy")(data);
|
|
115
119
|
}
|
|
116
120
|
/**
|
|
117
121
|
* First time mount the function
|
|
118
122
|
*/
|
|
119
123
|
async mount(data) {
|
|
124
|
+
var _a;
|
|
120
125
|
if (!data.logger)
|
|
121
126
|
data.logger = new Logger("Func");
|
|
122
|
-
data.logger.
|
|
127
|
+
const logger = new Logger(((_a = data.logger) == null ? void 0 : _a.label) || "Func");
|
|
128
|
+
if (!logger.label.endsWith("Func"))
|
|
129
|
+
logger.label = `${logger.label}] [Func`;
|
|
130
|
+
logger.debug("onMount");
|
|
123
131
|
if (this.mounted) {
|
|
124
|
-
|
|
132
|
+
logger.warn("mount() has been called, skipped.");
|
|
125
133
|
return;
|
|
126
134
|
}
|
|
127
135
|
if (!data.config)
|
|
128
136
|
data.config = this.config;
|
|
129
137
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
138
|
+
logger.time("mount");
|
|
139
|
+
logger.debug(
|
|
140
|
+
`Plugins: ${this.plugins.map((p) => `${p.type}#${p.name}`).join(",")}`
|
|
141
|
+
);
|
|
132
142
|
await this.compose("onMount")(data);
|
|
133
143
|
this.mounted = true;
|
|
134
144
|
} finally {
|
|
135
|
-
|
|
145
|
+
logger.timeEnd("mount", "mounted");
|
|
136
146
|
}
|
|
137
147
|
}
|
|
138
148
|
/**
|
|
@@ -159,10 +169,11 @@ var Func = class {
|
|
|
159
169
|
*/
|
|
160
170
|
export() {
|
|
161
171
|
const handler = async (event, context, callback) => {
|
|
172
|
+
var _a;
|
|
162
173
|
if (typeof context === "undefined")
|
|
163
174
|
context = {};
|
|
164
175
|
if (!context.request_id)
|
|
165
|
-
context.request_id = randomBytes(16).toString("hex");
|
|
176
|
+
context.request_id = ((_a = event == null ? void 0 : event.headers) == null ? void 0 : _a["x-faasjs-request-id"]) || randomBytes(16).toString("hex");
|
|
166
177
|
if (!context.request_at)
|
|
167
178
|
context.request_at = Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
168
179
|
context.callbackWaitsForEmptyEventLoop = false;
|
|
@@ -194,12 +205,15 @@ function usePlugin(plugin) {
|
|
|
194
205
|
if (!plugin.mount)
|
|
195
206
|
plugin.mount = async function(data) {
|
|
196
207
|
if (plugin.onMount)
|
|
197
|
-
await plugin.onMount(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
208
|
+
await plugin.onMount(
|
|
209
|
+
{
|
|
210
|
+
config: (data == null ? void 0 : data.config) || /* @__PURE__ */ Object.create(null),
|
|
211
|
+
event: /* @__PURE__ */ Object.create(null),
|
|
212
|
+
context: /* @__PURE__ */ Object.create(null),
|
|
213
|
+
logger: new Logger(plugin.name)
|
|
214
|
+
},
|
|
215
|
+
async () => Promise.resolve()
|
|
216
|
+
);
|
|
203
217
|
return plugin;
|
|
204
218
|
};
|
|
205
219
|
return plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/func",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4-beta.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@faasjs/deep_merge": "0.0.
|
|
25
|
-
"@faasjs/logger": "0.0.
|
|
24
|
+
"@faasjs/deep_merge": "0.0.4-beta.10",
|
|
25
|
+
"@faasjs/logger": "0.0.4-beta.10"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
|
-
"npm": ">=
|
|
29
|
-
"node": ">=
|
|
28
|
+
"npm": ">=9.0.0",
|
|
29
|
+
"node": ">=18.0.0"
|
|
30
30
|
}
|
|
31
31
|
}
|