@faasjs/request 0.0.3-beta.64 → 0.0.3-beta.65
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 +2 -147
- package/dist/index.mjs +1 -142
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -18,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
21
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
22
|
mod
|
|
27
23
|
));
|
|
@@ -40,148 +36,7 @@ var https = __toESM(require("https"));
|
|
|
40
36
|
var import_url = require("url");
|
|
41
37
|
var import_fs = require("fs");
|
|
42
38
|
var import_path = require("path");
|
|
43
|
-
|
|
44
|
-
// ../logger/src/index.ts
|
|
45
|
-
var import_util = require("util");
|
|
46
|
-
var LevelColor = ((LevelColor2) => {
|
|
47
|
-
LevelColor2[LevelColor2["debug"] = 90 /* GRAY */] = "debug";
|
|
48
|
-
LevelColor2[LevelColor2["info"] = 32 /* GREEN */] = "info";
|
|
49
|
-
LevelColor2[LevelColor2["warn"] = 33 /* ORANGE */] = "warn";
|
|
50
|
-
LevelColor2[LevelColor2["error"] = 31 /* RED */] = "error";
|
|
51
|
-
return LevelColor2;
|
|
52
|
-
})(LevelColor || {});
|
|
53
|
-
var LevelPriority = {
|
|
54
|
-
debug: 0,
|
|
55
|
-
info: 1,
|
|
56
|
-
warn: 2,
|
|
57
|
-
error: 3
|
|
58
|
-
};
|
|
59
|
-
var Logger = class {
|
|
60
|
-
/**
|
|
61
|
-
* @param label {string} Prefix label
|
|
62
|
-
*/
|
|
63
|
-
constructor(label) {
|
|
64
|
-
this.colorfyOutput = true;
|
|
65
|
-
if (label)
|
|
66
|
-
this.label = label;
|
|
67
|
-
this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
|
|
68
|
-
if (["remote", "mono"].includes(process.env.FaasMode))
|
|
69
|
-
this.colorfyOutput = false;
|
|
70
|
-
this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
|
|
71
|
-
this.cachedTimers = {};
|
|
72
|
-
this.size = 1e3;
|
|
73
|
-
this.stdout = console.log;
|
|
74
|
-
this.stderr = console.error;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @param message {string} message
|
|
78
|
-
* @param args {...any=} arguments
|
|
79
|
-
*/
|
|
80
|
-
debug(message, ...args) {
|
|
81
|
-
this.log("debug", message, ...args);
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* @param message {string} message
|
|
86
|
-
* @param args {...any=} arguments
|
|
87
|
-
*/
|
|
88
|
-
info(message, ...args) {
|
|
89
|
-
this.log("info", message, ...args);
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* @param message {string} message
|
|
94
|
-
* @param args {...any=} arguments
|
|
95
|
-
*/
|
|
96
|
-
warn(message, ...args) {
|
|
97
|
-
this.log("warn", message, ...args);
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* @param message {any} message or Error object
|
|
102
|
-
* @param args {...any=} arguments
|
|
103
|
-
*/
|
|
104
|
-
error(message, ...args) {
|
|
105
|
-
let stack = false;
|
|
106
|
-
[message].concat(Array.from(args)).forEach((e) => {
|
|
107
|
-
if (e.stack) {
|
|
108
|
-
stack = true;
|
|
109
|
-
this.log("error", e.stack);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
if (!stack)
|
|
113
|
-
this.log("error", message, ...args);
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @param key {string} timer's label
|
|
118
|
-
* @param level [string=debug] 日志级别,支持 debug、info、warn、error
|
|
119
|
-
*/
|
|
120
|
-
time(key, level = "debug") {
|
|
121
|
-
this.cachedTimers[key] = {
|
|
122
|
-
level,
|
|
123
|
-
time: (/* @__PURE__ */ new Date()).getTime()
|
|
124
|
-
};
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* @param key {string} timer's label
|
|
129
|
-
* @param message {string} message
|
|
130
|
-
* @param args {...any=} arguments
|
|
131
|
-
*/
|
|
132
|
-
timeEnd(key, message, ...args) {
|
|
133
|
-
if (this.cachedTimers[key]) {
|
|
134
|
-
const timer = this.cachedTimers[key];
|
|
135
|
-
message = message + " +%ims";
|
|
136
|
-
args.push((/* @__PURE__ */ new Date()).getTime() - timer.time);
|
|
137
|
-
this[timer.level](message, ...args);
|
|
138
|
-
delete this.cachedTimers[key];
|
|
139
|
-
} else {
|
|
140
|
-
this.warn("timeEnd not found key %s", key);
|
|
141
|
-
this.debug(message);
|
|
142
|
-
}
|
|
143
|
-
return this;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* @param message {string} message
|
|
147
|
-
* @param args {...any=} arguments
|
|
148
|
-
*/
|
|
149
|
-
raw(message, ...args) {
|
|
150
|
-
if (this.silent)
|
|
151
|
-
return this;
|
|
152
|
-
this.stdout((0, import_util.format)(message, ...args));
|
|
153
|
-
return this;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* @param color {number} color code
|
|
157
|
-
* @param message {string} message
|
|
158
|
-
*/
|
|
159
|
-
colorfy(color, message) {
|
|
160
|
-
return `\x1B[0${color}m${message}\x1B[39m`;
|
|
161
|
-
}
|
|
162
|
-
log(level, message, ...args) {
|
|
163
|
-
if (this.silent)
|
|
164
|
-
return this;
|
|
165
|
-
if (LevelPriority[level] < this.level)
|
|
166
|
-
return this;
|
|
167
|
-
let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + (0, import_util.format)(message, ...args);
|
|
168
|
-
if (this.colorfyOutput && level !== "error")
|
|
169
|
-
output = this.colorfy(LevelColor[level], output);
|
|
170
|
-
else if (!this.colorfyOutput)
|
|
171
|
-
output = output.replace(/\n/g, "");
|
|
172
|
-
if (!output)
|
|
173
|
-
return this;
|
|
174
|
-
if (output.length > this.size && !["error", "warn"].includes(level))
|
|
175
|
-
output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
|
|
176
|
-
if (level === "error")
|
|
177
|
-
this.stderr(output);
|
|
178
|
-
else
|
|
179
|
-
this.stdout(output);
|
|
180
|
-
return this;
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
// src/index.ts
|
|
39
|
+
var import_logger = require("@faasjs/logger");
|
|
185
40
|
var mock = null;
|
|
186
41
|
function setMock(handler) {
|
|
187
42
|
mock = handler;
|
|
@@ -221,7 +76,7 @@ async function request(url, {
|
|
|
221
76
|
logger
|
|
222
77
|
} = { headers: {} }) {
|
|
223
78
|
if (!logger)
|
|
224
|
-
logger = new Logger("request");
|
|
79
|
+
logger = new import_logger.Logger("request");
|
|
225
80
|
if (mock)
|
|
226
81
|
return mock(url, {
|
|
227
82
|
headers,
|
package/dist/index.mjs
CHANGED
|
@@ -4,148 +4,7 @@ import * as https from "https";
|
|
|
4
4
|
import { URL } from "url";
|
|
5
5
|
import { readFileSync } from "fs";
|
|
6
6
|
import { basename } from "path";
|
|
7
|
-
|
|
8
|
-
// ../logger/src/index.ts
|
|
9
|
-
import { format } from "util";
|
|
10
|
-
var LevelColor = ((LevelColor2) => {
|
|
11
|
-
LevelColor2[LevelColor2["debug"] = 90 /* GRAY */] = "debug";
|
|
12
|
-
LevelColor2[LevelColor2["info"] = 32 /* GREEN */] = "info";
|
|
13
|
-
LevelColor2[LevelColor2["warn"] = 33 /* ORANGE */] = "warn";
|
|
14
|
-
LevelColor2[LevelColor2["error"] = 31 /* RED */] = "error";
|
|
15
|
-
return LevelColor2;
|
|
16
|
-
})(LevelColor || {});
|
|
17
|
-
var LevelPriority = {
|
|
18
|
-
debug: 0,
|
|
19
|
-
info: 1,
|
|
20
|
-
warn: 2,
|
|
21
|
-
error: 3
|
|
22
|
-
};
|
|
23
|
-
var Logger = class {
|
|
24
|
-
/**
|
|
25
|
-
* @param label {string} Prefix label
|
|
26
|
-
*/
|
|
27
|
-
constructor(label) {
|
|
28
|
-
this.colorfyOutput = true;
|
|
29
|
-
if (label)
|
|
30
|
-
this.label = label;
|
|
31
|
-
this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
|
|
32
|
-
if (["remote", "mono"].includes(process.env.FaasMode))
|
|
33
|
-
this.colorfyOutput = false;
|
|
34
|
-
this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
|
|
35
|
-
this.cachedTimers = {};
|
|
36
|
-
this.size = 1e3;
|
|
37
|
-
this.stdout = console.log;
|
|
38
|
-
this.stderr = console.error;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @param message {string} message
|
|
42
|
-
* @param args {...any=} arguments
|
|
43
|
-
*/
|
|
44
|
-
debug(message, ...args) {
|
|
45
|
-
this.log("debug", message, ...args);
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @param message {string} message
|
|
50
|
-
* @param args {...any=} arguments
|
|
51
|
-
*/
|
|
52
|
-
info(message, ...args) {
|
|
53
|
-
this.log("info", message, ...args);
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* @param message {string} message
|
|
58
|
-
* @param args {...any=} arguments
|
|
59
|
-
*/
|
|
60
|
-
warn(message, ...args) {
|
|
61
|
-
this.log("warn", message, ...args);
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* @param message {any} message or Error object
|
|
66
|
-
* @param args {...any=} arguments
|
|
67
|
-
*/
|
|
68
|
-
error(message, ...args) {
|
|
69
|
-
let stack = false;
|
|
70
|
-
[message].concat(Array.from(args)).forEach((e) => {
|
|
71
|
-
if (e.stack) {
|
|
72
|
-
stack = true;
|
|
73
|
-
this.log("error", e.stack);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
if (!stack)
|
|
77
|
-
this.log("error", message, ...args);
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* @param key {string} timer's label
|
|
82
|
-
* @param level [string=debug] 日志级别,支持 debug、info、warn、error
|
|
83
|
-
*/
|
|
84
|
-
time(key, level = "debug") {
|
|
85
|
-
this.cachedTimers[key] = {
|
|
86
|
-
level,
|
|
87
|
-
time: (/* @__PURE__ */ new Date()).getTime()
|
|
88
|
-
};
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* @param key {string} timer's label
|
|
93
|
-
* @param message {string} message
|
|
94
|
-
* @param args {...any=} arguments
|
|
95
|
-
*/
|
|
96
|
-
timeEnd(key, message, ...args) {
|
|
97
|
-
if (this.cachedTimers[key]) {
|
|
98
|
-
const timer = this.cachedTimers[key];
|
|
99
|
-
message = message + " +%ims";
|
|
100
|
-
args.push((/* @__PURE__ */ new Date()).getTime() - timer.time);
|
|
101
|
-
this[timer.level](message, ...args);
|
|
102
|
-
delete this.cachedTimers[key];
|
|
103
|
-
} else {
|
|
104
|
-
this.warn("timeEnd not found key %s", key);
|
|
105
|
-
this.debug(message);
|
|
106
|
-
}
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* @param message {string} message
|
|
111
|
-
* @param args {...any=} arguments
|
|
112
|
-
*/
|
|
113
|
-
raw(message, ...args) {
|
|
114
|
-
if (this.silent)
|
|
115
|
-
return this;
|
|
116
|
-
this.stdout(format(message, ...args));
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* @param color {number} color code
|
|
121
|
-
* @param message {string} message
|
|
122
|
-
*/
|
|
123
|
-
colorfy(color, message) {
|
|
124
|
-
return `\x1B[0${color}m${message}\x1B[39m`;
|
|
125
|
-
}
|
|
126
|
-
log(level, message, ...args) {
|
|
127
|
-
if (this.silent)
|
|
128
|
-
return this;
|
|
129
|
-
if (LevelPriority[level] < this.level)
|
|
130
|
-
return this;
|
|
131
|
-
let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + format(message, ...args);
|
|
132
|
-
if (this.colorfyOutput && level !== "error")
|
|
133
|
-
output = this.colorfy(LevelColor[level], output);
|
|
134
|
-
else if (!this.colorfyOutput)
|
|
135
|
-
output = output.replace(/\n/g, "");
|
|
136
|
-
if (!output)
|
|
137
|
-
return this;
|
|
138
|
-
if (output.length > this.size && !["error", "warn"].includes(level))
|
|
139
|
-
output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
|
|
140
|
-
if (level === "error")
|
|
141
|
-
this.stderr(output);
|
|
142
|
-
else
|
|
143
|
-
this.stdout(output);
|
|
144
|
-
return this;
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// src/index.ts
|
|
7
|
+
import { Logger } from "@faasjs/logger";
|
|
149
8
|
var mock = null;
|
|
150
9
|
function setMock(handler) {
|
|
151
10
|
mock = handler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/request",
|
|
3
|
-
"version": "0.0.3-beta.
|
|
3
|
+
"version": "0.0.3-beta.65",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@faasjs/logger": "^0.0.3-beta.
|
|
25
|
+
"@faasjs/logger": "^0.0.3-beta.65"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
28
28
|
"npm": ">=8.0.0",
|