@faasjs/func 2.3.1 → 2.4.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/dist/index.js CHANGED
@@ -17,10 +17,8 @@ var RunHandler = class {
17
17
  try {
18
18
  data.response = await new Promise((resolve, reject) => {
19
19
  data.callback = (error, result) => {
20
- if (error)
21
- reject(error);
22
- else
23
- resolve(result);
20
+ if (error) reject(error);
21
+ else resolve(result);
24
22
  };
25
23
  Promise.resolve(data.handler(data)).then(resolve).catch(reject);
26
24
  });
@@ -29,8 +27,7 @@ var RunHandler = class {
29
27
  data.response = error;
30
28
  }
31
29
  data.runHandler = true;
32
- } else
33
- data.logger.warn("[RunHandler] handler has been run");
30
+ } else data.logger.warn("[RunHandler] handler has been run");
34
31
  await next();
35
32
  }
36
33
  };
@@ -58,8 +55,7 @@ var Func = class {
58
55
  }
59
56
  compose(key) {
60
57
  let list = [];
61
- if (this.cachedFunctions[key])
62
- list = this.cachedFunctions[key];
58
+ if (this.cachedFunctions[key]) list = this.cachedFunctions[key];
63
59
  else {
64
60
  for (const plugin of this.plugins) {
65
61
  const handler = plugin[key];
@@ -79,12 +75,9 @@ var Func = class {
79
75
  return Promise.reject(Error("next() called multiple times"));
80
76
  index = i;
81
77
  let fn = list[i];
82
- if (i === list.length)
83
- fn = next;
84
- if (!fn)
85
- return Promise.resolve();
86
- if (typeof fn.key === "undefined")
87
- fn.key = `UnNamedPlugin#${i}`;
78
+ if (i === list.length) fn = next;
79
+ if (!fn) return Promise.resolve();
80
+ if (typeof fn.key === "undefined") fn.key = `UnNamedPlugin#${i}`;
88
81
  logger$1.debug("[%s] [%s] begin", fn.key, key);
89
82
  logger$1.time(fn.key);
90
83
  try {
@@ -110,8 +103,7 @@ var Func = class {
110
103
  * @param data.env {string} environment
111
104
  */
112
105
  deploy(data) {
113
- if (!data.logger)
114
- data.logger = new logger.Logger("Func");
106
+ if (!data.logger) data.logger = new logger.Logger("Func");
115
107
  data.logger.debug("onDeploy");
116
108
  data.logger.debug(
117
109
  `Plugins: ${this.plugins.map((p) => `${p.type}#${p.name}`).join(",")}`
@@ -123,18 +115,15 @@ var Func = class {
123
115
  */
124
116
  async mount(data) {
125
117
  var _a;
126
- if (!data.logger)
127
- data.logger = new logger.Logger("Func");
118
+ if (!data.logger) data.logger = new logger.Logger("Func");
128
119
  const logger$1 = new logger.Logger(((_a = data.logger) == null ? void 0 : _a.label) || "Func");
129
- if (!logger$1.label.endsWith("Func"))
130
- logger$1.label = `${logger$1.label}] [Func`;
120
+ if (!logger$1.label.endsWith("Func")) logger$1.label = `${logger$1.label}] [Func`;
131
121
  logger$1.debug("onMount");
132
122
  if (this.mounted) {
133
123
  logger$1.warn("mount() has been called, skipped.");
134
124
  return;
135
125
  }
136
- if (!data.config)
137
- data.config = this.config;
126
+ if (!data.config) data.config = this.config;
138
127
  try {
139
128
  logger$1.time("mount");
140
129
  logger$1.debug(
@@ -171,8 +160,7 @@ var Func = class {
171
160
  export() {
172
161
  const handler = async (event, context, callback) => {
173
162
  var _a;
174
- if (typeof context === "undefined")
175
- context = {};
163
+ if (typeof context === "undefined") context = {};
176
164
  if (!context.request_id)
177
165
  context.request_id = ((_a = event == null ? void 0 : event.headers) == null ? void 0 : _a["x-faasjs-request-id"]) || crypto.randomBytes(16).toString("hex");
178
166
  if (!context.request_at)
@@ -201,8 +189,7 @@ var Func = class {
201
189
  };
202
190
  var plugins = [];
203
191
  function usePlugin(plugin) {
204
- if (!plugins.find((p) => p.name === plugin.name))
205
- plugins.push(plugin);
192
+ if (!plugins.find((p) => p.name === plugin.name)) plugins.push(plugin);
206
193
  if (!plugin.mount)
207
194
  plugin.mount = async (data) => {
208
195
  if (plugin.onMount)
package/dist/index.mjs CHANGED
@@ -15,10 +15,8 @@ var RunHandler = class {
15
15
  try {
16
16
  data.response = await new Promise((resolve, reject) => {
17
17
  data.callback = (error, result) => {
18
- if (error)
19
- reject(error);
20
- else
21
- resolve(result);
18
+ if (error) reject(error);
19
+ else resolve(result);
22
20
  };
23
21
  Promise.resolve(data.handler(data)).then(resolve).catch(reject);
24
22
  });
@@ -27,8 +25,7 @@ var RunHandler = class {
27
25
  data.response = error;
28
26
  }
29
27
  data.runHandler = true;
30
- } else
31
- data.logger.warn("[RunHandler] handler has been run");
28
+ } else data.logger.warn("[RunHandler] handler has been run");
32
29
  await next();
33
30
  }
34
31
  };
@@ -56,8 +53,7 @@ var Func = class {
56
53
  }
57
54
  compose(key) {
58
55
  let list = [];
59
- if (this.cachedFunctions[key])
60
- list = this.cachedFunctions[key];
56
+ if (this.cachedFunctions[key]) list = this.cachedFunctions[key];
61
57
  else {
62
58
  for (const plugin of this.plugins) {
63
59
  const handler = plugin[key];
@@ -77,12 +73,9 @@ var Func = class {
77
73
  return Promise.reject(Error("next() called multiple times"));
78
74
  index = i;
79
75
  let fn = list[i];
80
- if (i === list.length)
81
- fn = next;
82
- if (!fn)
83
- return Promise.resolve();
84
- if (typeof fn.key === "undefined")
85
- fn.key = `UnNamedPlugin#${i}`;
76
+ if (i === list.length) fn = next;
77
+ if (!fn) return Promise.resolve();
78
+ if (typeof fn.key === "undefined") fn.key = `UnNamedPlugin#${i}`;
86
79
  logger.debug("[%s] [%s] begin", fn.key, key);
87
80
  logger.time(fn.key);
88
81
  try {
@@ -108,8 +101,7 @@ var Func = class {
108
101
  * @param data.env {string} environment
109
102
  */
110
103
  deploy(data) {
111
- if (!data.logger)
112
- data.logger = new Logger("Func");
104
+ if (!data.logger) data.logger = new Logger("Func");
113
105
  data.logger.debug("onDeploy");
114
106
  data.logger.debug(
115
107
  `Plugins: ${this.plugins.map((p) => `${p.type}#${p.name}`).join(",")}`
@@ -121,18 +113,15 @@ var Func = class {
121
113
  */
122
114
  async mount(data) {
123
115
  var _a;
124
- if (!data.logger)
125
- data.logger = new Logger("Func");
116
+ if (!data.logger) data.logger = new Logger("Func");
126
117
  const logger = new Logger(((_a = data.logger) == null ? void 0 : _a.label) || "Func");
127
- if (!logger.label.endsWith("Func"))
128
- logger.label = `${logger.label}] [Func`;
118
+ if (!logger.label.endsWith("Func")) logger.label = `${logger.label}] [Func`;
129
119
  logger.debug("onMount");
130
120
  if (this.mounted) {
131
121
  logger.warn("mount() has been called, skipped.");
132
122
  return;
133
123
  }
134
- if (!data.config)
135
- data.config = this.config;
124
+ if (!data.config) data.config = this.config;
136
125
  try {
137
126
  logger.time("mount");
138
127
  logger.debug(
@@ -169,8 +158,7 @@ var Func = class {
169
158
  export() {
170
159
  const handler = async (event, context, callback) => {
171
160
  var _a;
172
- if (typeof context === "undefined")
173
- context = {};
161
+ if (typeof context === "undefined") context = {};
174
162
  if (!context.request_id)
175
163
  context.request_id = ((_a = event == null ? void 0 : event.headers) == null ? void 0 : _a["x-faasjs-request-id"]) || randomBytes(16).toString("hex");
176
164
  if (!context.request_at)
@@ -199,8 +187,7 @@ var Func = class {
199
187
  };
200
188
  var plugins = [];
201
189
  function usePlugin(plugin) {
202
- if (!plugins.find((p) => p.name === plugin.name))
203
- plugins.push(plugin);
190
+ if (!plugins.find((p) => p.name === plugin.name)) plugins.push(plugin);
204
191
  if (!plugin.mount)
205
192
  plugin.mount = async (data) => {
206
193
  if (plugin.onMount)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/func",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,8 +21,8 @@
21
21
  "dist"
22
22
  ],
23
23
  "dependencies": {
24
- "@faasjs/deep_merge": "2.3.1",
25
- "@faasjs/logger": "2.3.1"
24
+ "@faasjs/deep_merge": "2.4.0",
25
+ "@faasjs/logger": "2.4.0"
26
26
  },
27
27
  "engines": {
28
28
  "npm": ">=9.0.0",