@faasjs/func 0.0.3-beta.38 → 0.0.3-beta.39

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
@@ -25,110 +25,7 @@ __export(src_exports, {
25
25
  usePlugin: () => usePlugin
26
26
  });
27
27
  module.exports = __toCommonJS(src_exports);
28
-
29
- // ../logger/src/index.ts
30
- var import_util = require("util");
31
- var LevelColor = ((LevelColor2) => {
32
- LevelColor2[LevelColor2["debug"] = 90 /* GRAY */] = "debug";
33
- LevelColor2[LevelColor2["info"] = 32 /* GREEN */] = "info";
34
- LevelColor2[LevelColor2["warn"] = 33 /* ORANGE */] = "warn";
35
- LevelColor2[LevelColor2["error"] = 31 /* RED */] = "error";
36
- return LevelColor2;
37
- })(LevelColor || {});
38
- var LevelPriority = {
39
- debug: 0,
40
- info: 1,
41
- warn: 2,
42
- error: 3
43
- };
44
- var Logger = class {
45
- constructor(label) {
46
- this.colorfyOutput = true;
47
- if (label)
48
- this.label = label;
49
- this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
50
- if (["remote", "mono"].includes(process.env.FaasMode))
51
- this.colorfyOutput = false;
52
- this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
53
- this.cachedTimers = {};
54
- this.size = 1e3;
55
- this.stdout = console.log;
56
- this.stderr = console.error;
57
- }
58
- debug(message, ...args) {
59
- this.log("debug", message, ...args);
60
- return this;
61
- }
62
- info(message, ...args) {
63
- this.log("info", message, ...args);
64
- return this;
65
- }
66
- warn(message, ...args) {
67
- this.log("warn", message, ...args);
68
- return this;
69
- }
70
- error(message, ...args) {
71
- let stack = false;
72
- [message].concat(Array.from(args)).forEach((e) => {
73
- if (e.stack) {
74
- stack = true;
75
- this.log("error", e.stack);
76
- }
77
- });
78
- if (!stack)
79
- this.log("error", message, ...args);
80
- return this;
81
- }
82
- time(key, level = "debug") {
83
- this.cachedTimers[key] = {
84
- level,
85
- time: new Date().getTime()
86
- };
87
- return this;
88
- }
89
- timeEnd(key, message, ...args) {
90
- if (this.cachedTimers[key]) {
91
- const timer = this.cachedTimers[key];
92
- message = message + " +%ims";
93
- args.push(new Date().getTime() - timer.time);
94
- this[timer.level](message, ...args);
95
- delete this.cachedTimers[key];
96
- } else {
97
- this.warn("timeEnd not found key %s", key);
98
- this.debug(message);
99
- }
100
- return this;
101
- }
102
- raw(message, ...args) {
103
- if (this.silent)
104
- return this;
105
- this.stdout((0, import_util.format)(message, ...args));
106
- return this;
107
- }
108
- colorfy(color, message) {
109
- return `\x1B[0${color}m${message}\x1B[39m`;
110
- }
111
- log(level, message, ...args) {
112
- if (this.silent)
113
- return this;
114
- if (LevelPriority[level] < this.level)
115
- return this;
116
- let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + (0, import_util.format)(message, ...args);
117
- if (this.colorfyOutput && level !== "error")
118
- output = this.colorfy(LevelColor[level], output);
119
- else if (!this.colorfyOutput)
120
- output = output.replace(/\n/g, "");
121
- if (!output)
122
- return this;
123
- if (output.length > this.size && !["error", "warn"].includes(level))
124
- output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
125
- if (level === "error")
126
- this.stderr(output);
127
- else
128
- this.stdout(output);
129
- return this;
130
- }
131
- };
28
+ var import_logger = require("@faasjs/logger");
132
29
 
133
30
  // src/plugins/run_handler/index.ts
134
31
  var RunHandler = class {
@@ -176,7 +73,7 @@ var Func = class {
176
73
  try {
177
74
  this.filename = new Error().stack.split("\n").find((s) => /[^/]\.func\.ts/.test(s)).match(/\((.*\.func\.ts).*\)/)[1];
178
75
  } catch (error) {
179
- new Logger("Func").warn(error.message);
76
+ new import_logger.Logger("Func").warn(error.message);
180
77
  }
181
78
  }
182
79
  compose(key) {
@@ -196,7 +93,7 @@ var Func = class {
196
93
  }
197
94
  return async function(data, next) {
198
95
  let index = -1;
199
- const logger = (data == null ? void 0 : data.logger) || new Logger();
96
+ const logger = (data == null ? void 0 : data.logger) || new import_logger.Logger();
200
97
  const dispatch = async function(i) {
201
98
  if (i <= index)
202
99
  return Promise.reject(Error("next() called multiple times"));
@@ -225,14 +122,14 @@ var Func = class {
225
122
  }
226
123
  deploy(data) {
227
124
  if (!data.logger)
228
- data.logger = new Logger("Func");
125
+ data.logger = new import_logger.Logger("Func");
229
126
  data.logger.debug("onDeploy");
230
127
  data.logger.debug("Plugins: " + this.plugins.map((p) => `${p.type}#${p.name}`).join(","));
231
128
  return this.compose("onDeploy")(data);
232
129
  }
233
130
  async mount(data) {
234
131
  if (!data.logger)
235
- data.logger = new Logger("Func");
132
+ data.logger = new import_logger.Logger("Func");
236
133
  data.logger.debug("onMount");
237
134
  if (this.mounted) {
238
135
  data.logger.warn("mount() has been called, skipped.");
@@ -273,7 +170,7 @@ var Func = class {
273
170
  if (!context.request_at)
274
171
  context.request_at = Math.round(new Date().getTime() / 1e3);
275
172
  context.callbackWaitsForEmptyEventLoop = false;
276
- const logger = new Logger(context.request_id);
173
+ const logger = new import_logger.Logger(context.request_id);
277
174
  logger.debug("event: %j", event);
278
175
  logger.debug("context: %j", context);
279
176
  const data = {
@@ -305,7 +202,7 @@ function usePlugin(plugin) {
305
202
  config: (data == null ? void 0 : data.config) || /* @__PURE__ */ Object.create(null),
306
203
  event: /* @__PURE__ */ Object.create(null),
307
204
  context: /* @__PURE__ */ Object.create(null),
308
- logger: new Logger(plugin.name)
205
+ logger: new import_logger.Logger(plugin.name)
309
206
  }, async () => Promise.resolve());
310
207
  return plugin;
311
208
  };
package/dist/index.mjs CHANGED
@@ -1,106 +1,5 @@
1
- // ../logger/src/index.ts
2
- import { format } from "util";
3
- var LevelColor = ((LevelColor2) => {
4
- LevelColor2[LevelColor2["debug"] = 90 /* GRAY */] = "debug";
5
- LevelColor2[LevelColor2["info"] = 32 /* GREEN */] = "info";
6
- LevelColor2[LevelColor2["warn"] = 33 /* ORANGE */] = "warn";
7
- LevelColor2[LevelColor2["error"] = 31 /* RED */] = "error";
8
- return LevelColor2;
9
- })(LevelColor || {});
10
- var LevelPriority = {
11
- debug: 0,
12
- info: 1,
13
- warn: 2,
14
- error: 3
15
- };
16
- var Logger = class {
17
- constructor(label) {
18
- this.colorfyOutput = true;
19
- if (label)
20
- this.label = label;
21
- this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
22
- if (["remote", "mono"].includes(process.env.FaasMode))
23
- this.colorfyOutput = false;
24
- this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
25
- this.cachedTimers = {};
26
- this.size = 1e3;
27
- this.stdout = console.log;
28
- this.stderr = console.error;
29
- }
30
- debug(message, ...args) {
31
- this.log("debug", message, ...args);
32
- return this;
33
- }
34
- info(message, ...args) {
35
- this.log("info", message, ...args);
36
- return this;
37
- }
38
- warn(message, ...args) {
39
- this.log("warn", message, ...args);
40
- return this;
41
- }
42
- error(message, ...args) {
43
- let stack = false;
44
- [message].concat(Array.from(args)).forEach((e) => {
45
- if (e.stack) {
46
- stack = true;
47
- this.log("error", e.stack);
48
- }
49
- });
50
- if (!stack)
51
- this.log("error", message, ...args);
52
- return this;
53
- }
54
- time(key, level = "debug") {
55
- this.cachedTimers[key] = {
56
- level,
57
- time: new Date().getTime()
58
- };
59
- return this;
60
- }
61
- timeEnd(key, message, ...args) {
62
- if (this.cachedTimers[key]) {
63
- const timer = this.cachedTimers[key];
64
- message = message + " +%ims";
65
- args.push(new Date().getTime() - timer.time);
66
- this[timer.level](message, ...args);
67
- delete this.cachedTimers[key];
68
- } else {
69
- this.warn("timeEnd not found key %s", key);
70
- this.debug(message);
71
- }
72
- return this;
73
- }
74
- raw(message, ...args) {
75
- if (this.silent)
76
- return this;
77
- this.stdout(format(message, ...args));
78
- return this;
79
- }
80
- colorfy(color, message) {
81
- return `\x1B[0${color}m${message}\x1B[39m`;
82
- }
83
- log(level, message, ...args) {
84
- if (this.silent)
85
- return this;
86
- if (LevelPriority[level] < this.level)
87
- return this;
88
- let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + format(message, ...args);
89
- if (this.colorfyOutput && level !== "error")
90
- output = this.colorfy(LevelColor[level], output);
91
- else if (!this.colorfyOutput)
92
- output = output.replace(/\n/g, "");
93
- if (!output)
94
- return this;
95
- if (output.length > this.size && !["error", "warn"].includes(level))
96
- output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
97
- if (level === "error")
98
- this.stderr(output);
99
- else
100
- this.stdout(output);
101
- return this;
102
- }
103
- };
1
+ // src/index.ts
2
+ import { Logger } from "@faasjs/logger";
104
3
 
105
4
  // src/plugins/run_handler/index.ts
106
5
  var RunHandler = class {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/func",
3
- "version": "0.0.3-beta.38",
3
+ "version": "0.0.3-beta.39",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,8 +22,8 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@faasjs/deep_merge": "^0.0.3-beta.38",
26
- "@faasjs/logger": "^0.0.3-beta.38"
25
+ "@faasjs/deep_merge": "^0.0.3-beta.39",
26
+ "@faasjs/logger": "^0.0.3-beta.39"
27
27
  },
28
28
  "engines": {
29
29
  "npm": ">=8.0.0",