@faasjs/func 0.0.3-beta.99 → 0.0.4-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/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)) => `void` \| `Promise`<`void`\> |
243
- | `onInvoke?` | (`data`: [`InvokeData`](#invokedata), `next`: [`Next`](#next)) => `void` \| `Promise`<`void`\> |
244
- | `onMount?` | (`data`: [`MountData`](#mountdata), `next`: [`Next`](#next)) => `void` \| `Promise`<`void`\> |
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) => void | Promise<void>;
11
- onMount?: (data: MountData, next: Next) => void | Promise<void>;
12
- onInvoke?: (data: InvokeData, next: Next) => void | Promise<void>;
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) => void | Promise<void>;
11
- onMount?: (data: MountData, next: Next) => void | Promise<void>;
12
- onInvoke?: (data: InvokeData, next: Next) => void | Promise<void>;
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(fn.handler(data, dispatch.bind(null, i + 1)));
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,7 +114,9 @@ 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("Plugins: " + this.plugins.map((p) => `${p.type}#${p.name}`).join(","));
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
  /**
@@ -130,7 +134,9 @@ var Func = class {
130
134
  data.config = this.config;
131
135
  try {
132
136
  data.logger.time("mount");
133
- data.logger.debug("Plugins: " + this.plugins.map((p) => `${p.type}#${p.name}`).join(","));
137
+ data.logger.debug(
138
+ `Plugins: ${this.plugins.map((p) => `${p.type}#${p.name}`).join(",")}`
139
+ );
134
140
  await this.compose("onMount")(data);
135
141
  this.mounted = true;
136
142
  } finally {
@@ -161,10 +167,11 @@ var Func = class {
161
167
  */
162
168
  export() {
163
169
  const handler = async (event, context, callback) => {
170
+ var _a;
164
171
  if (typeof context === "undefined")
165
172
  context = {};
166
173
  if (!context.request_id)
167
- context.request_id = crypto.randomBytes(16).toString("hex");
174
+ context.request_id = ((_a = event == null ? void 0 : event.headers) == null ? void 0 : _a["x-faasjs-request-id"]) || crypto.randomBytes(16).toString("hex");
168
175
  if (!context.request_at)
169
176
  context.request_at = Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3);
170
177
  context.callbackWaitsForEmptyEventLoop = false;
@@ -196,12 +203,15 @@ function usePlugin(plugin) {
196
203
  if (!plugin.mount)
197
204
  plugin.mount = async function(data) {
198
205
  if (plugin.onMount)
199
- await plugin.onMount({
200
- config: (data == null ? void 0 : data.config) || /* @__PURE__ */ Object.create(null),
201
- event: /* @__PURE__ */ Object.create(null),
202
- context: /* @__PURE__ */ Object.create(null),
203
- logger: new logger.Logger(plugin.name)
204
- }, async () => Promise.resolve());
206
+ await plugin.onMount(
207
+ {
208
+ config: (data == null ? void 0 : data.config) || /* @__PURE__ */ Object.create(null),
209
+ event: /* @__PURE__ */ Object.create(null),
210
+ context: /* @__PURE__ */ Object.create(null),
211
+ logger: new logger.Logger(plugin.name)
212
+ },
213
+ async () => Promise.resolve()
214
+ );
205
215
  return plugin;
206
216
  };
207
217
  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(fn.handler(data, dispatch.bind(null, i + 1)));
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,7 +112,9 @@ 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("Plugins: " + this.plugins.map((p) => `${p.type}#${p.name}`).join(","));
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
  /**
@@ -128,7 +132,9 @@ var Func = class {
128
132
  data.config = this.config;
129
133
  try {
130
134
  data.logger.time("mount");
131
- data.logger.debug("Plugins: " + this.plugins.map((p) => `${p.type}#${p.name}`).join(","));
135
+ data.logger.debug(
136
+ `Plugins: ${this.plugins.map((p) => `${p.type}#${p.name}`).join(",")}`
137
+ );
132
138
  await this.compose("onMount")(data);
133
139
  this.mounted = true;
134
140
  } finally {
@@ -159,10 +165,11 @@ var Func = class {
159
165
  */
160
166
  export() {
161
167
  const handler = async (event, context, callback) => {
168
+ var _a;
162
169
  if (typeof context === "undefined")
163
170
  context = {};
164
171
  if (!context.request_id)
165
- context.request_id = randomBytes(16).toString("hex");
172
+ context.request_id = ((_a = event == null ? void 0 : event.headers) == null ? void 0 : _a["x-faasjs-request-id"]) || randomBytes(16).toString("hex");
166
173
  if (!context.request_at)
167
174
  context.request_at = Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3);
168
175
  context.callbackWaitsForEmptyEventLoop = false;
@@ -194,12 +201,15 @@ function usePlugin(plugin) {
194
201
  if (!plugin.mount)
195
202
  plugin.mount = async function(data) {
196
203
  if (plugin.onMount)
197
- await plugin.onMount({
198
- config: (data == null ? void 0 : data.config) || /* @__PURE__ */ Object.create(null),
199
- event: /* @__PURE__ */ Object.create(null),
200
- context: /* @__PURE__ */ Object.create(null),
201
- logger: new Logger(plugin.name)
202
- }, async () => Promise.resolve());
204
+ await plugin.onMount(
205
+ {
206
+ config: (data == null ? void 0 : data.config) || /* @__PURE__ */ Object.create(null),
207
+ event: /* @__PURE__ */ Object.create(null),
208
+ context: /* @__PURE__ */ Object.create(null),
209
+ logger: new Logger(plugin.name)
210
+ },
211
+ async () => Promise.resolve()
212
+ );
203
213
  return plugin;
204
214
  };
205
215
  return plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/func",
3
- "version": "0.0.3-beta.99",
3
+ "version": "0.0.4-beta.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,12 +20,16 @@
20
20
  "files": [
21
21
  "dist"
22
22
  ],
23
- "dependencies": {
24
- "@faasjs/deep_merge": "0.0.3-beta.99",
25
- "@faasjs/logger": "0.0.3-beta.99"
23
+ "peerDependencies": {
24
+ "@faasjs/deep_merge": "0.0.4-beta.2",
25
+ "@faasjs/logger": "0.0.4-beta.2"
26
+ },
27
+ "devDependencies": {
28
+ "@faasjs/deep_merge": "0.0.4-beta.2",
29
+ "@faasjs/logger": "0.0.4-beta.2"
26
30
  },
27
31
  "engines": {
28
- "npm": ">=8.0.0",
29
- "node": ">=16.0.0"
32
+ "npm": ">=9.0.0",
33
+ "node": ">=18.0.0"
30
34
  }
31
35
  }