@faasjs/request 0.0.3-beta.70 → 0.0.3-beta.72

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
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
8
  var __export = (target, all) => {
12
9
  for (var name in all)
13
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -21,207 +18,11 @@ var __copyProps = (to, from, except, desc) => {
21
18
  return to;
22
19
  };
23
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
21
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
22
  mod
30
23
  ));
31
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
25
 
33
- // ../logger/dist/index.js
34
- var require_dist = __commonJS({
35
- "../logger/dist/index.js"(exports, module2) {
36
- "use strict";
37
- var __defProp2 = Object.defineProperty;
38
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
39
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
40
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
41
- var __export2 = (target, all) => {
42
- for (var name in all)
43
- __defProp2(target, name, { get: all[name], enumerable: true });
44
- };
45
- var __copyProps2 = (to, from, except, desc) => {
46
- if (from && typeof from === "object" || typeof from === "function") {
47
- for (let key of __getOwnPropNames2(from))
48
- if (!__hasOwnProp2.call(to, key) && key !== except)
49
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
50
- }
51
- return to;
52
- };
53
- var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
54
- var src_exports2 = {};
55
- __export2(src_exports2, {
56
- Color: () => Color,
57
- Logger: () => Logger2
58
- });
59
- module2.exports = __toCommonJS2(src_exports2);
60
- var import_util = require("util");
61
- var Color = /* @__PURE__ */ ((Color2) => {
62
- Color2[Color2["DEFAULT"] = 39] = "DEFAULT";
63
- Color2[Color2["BLACK"] = 30] = "BLACK";
64
- Color2[Color2["RED"] = 31] = "RED";
65
- Color2[Color2["GREEN"] = 32] = "GREEN";
66
- Color2[Color2["ORANGE"] = 33] = "ORANGE";
67
- Color2[Color2["BLUE"] = 34] = "BLUE";
68
- Color2[Color2["MAGENTA"] = 35] = "MAGENTA";
69
- Color2[Color2["CYAN"] = 36] = "CYAN";
70
- Color2[Color2["GRAY"] = 90] = "GRAY";
71
- return Color2;
72
- })(Color || {});
73
- var LevelColor = ((LevelColor2) => {
74
- LevelColor2[
75
- LevelColor2["debug"] = 90
76
- /* GRAY */
77
- ] = "debug";
78
- LevelColor2[
79
- LevelColor2["info"] = 32
80
- /* GREEN */
81
- ] = "info";
82
- LevelColor2[
83
- LevelColor2["warn"] = 33
84
- /* ORANGE */
85
- ] = "warn";
86
- LevelColor2[
87
- LevelColor2["error"] = 31
88
- /* RED */
89
- ] = "error";
90
- return LevelColor2;
91
- })(LevelColor || {});
92
- var LevelPriority = {
93
- debug: 0,
94
- info: 1,
95
- warn: 2,
96
- error: 3
97
- };
98
- var Logger2 = class {
99
- /**
100
- * @param label {string} Prefix label
101
- */
102
- constructor(label) {
103
- this.colorfyOutput = true;
104
- if (label)
105
- this.label = label;
106
- this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
107
- if (["remote", "mono"].includes(process.env.FaasMode))
108
- this.colorfyOutput = false;
109
- this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
110
- this.cachedTimers = {};
111
- this.size = 1e3;
112
- this.stdout = console.log;
113
- this.stderr = console.error;
114
- }
115
- /**
116
- * @param message {string} message
117
- * @param args {...any=} arguments
118
- */
119
- debug(message, ...args) {
120
- this.log("debug", message, ...args);
121
- return this;
122
- }
123
- /**
124
- * @param message {string} message
125
- * @param args {...any=} arguments
126
- */
127
- info(message, ...args) {
128
- this.log("info", message, ...args);
129
- return this;
130
- }
131
- /**
132
- * @param message {string} message
133
- * @param args {...any=} arguments
134
- */
135
- warn(message, ...args) {
136
- this.log("warn", message, ...args);
137
- return this;
138
- }
139
- /**
140
- * @param message {any} message or Error object
141
- * @param args {...any=} arguments
142
- */
143
- error(message, ...args) {
144
- let stack = false;
145
- [message].concat(Array.from(args)).forEach((e) => {
146
- if (e.stack) {
147
- stack = true;
148
- this.log("error", e.stack);
149
- }
150
- });
151
- if (!stack)
152
- this.log("error", message, ...args);
153
- return this;
154
- }
155
- /**
156
- * @param key {string} timer's label
157
- * @param level [string=debug] 日志级别,支持 debug、info、warn、error
158
- */
159
- time(key, level = "debug") {
160
- this.cachedTimers[key] = {
161
- level,
162
- time: (/* @__PURE__ */ new Date()).getTime()
163
- };
164
- return this;
165
- }
166
- /**
167
- * @param key {string} timer's label
168
- * @param message {string} message
169
- * @param args {...any=} arguments
170
- */
171
- timeEnd(key, message, ...args) {
172
- if (this.cachedTimers[key]) {
173
- const timer = this.cachedTimers[key];
174
- message = message + " +%ims";
175
- args.push((/* @__PURE__ */ new Date()).getTime() - timer.time);
176
- this[timer.level](message, ...args);
177
- delete this.cachedTimers[key];
178
- } else {
179
- this.warn("timeEnd not found key %s", key);
180
- this.debug(message);
181
- }
182
- return this;
183
- }
184
- /**
185
- * @param message {string} message
186
- * @param args {...any=} arguments
187
- */
188
- raw(message, ...args) {
189
- if (this.silent)
190
- return this;
191
- this.stdout((0, import_util.format)(message, ...args));
192
- return this;
193
- }
194
- /**
195
- * @param color {number} color code
196
- * @param message {string} message
197
- */
198
- colorfy(color, message) {
199
- return `\x1B[0${color}m${message}\x1B[39m`;
200
- }
201
- log(level, message, ...args) {
202
- if (this.silent)
203
- return this;
204
- if (LevelPriority[level] < this.level)
205
- return this;
206
- let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + (0, import_util.format)(message, ...args);
207
- if (this.colorfyOutput && level !== "error")
208
- output = this.colorfy(LevelColor[level], output);
209
- else if (!this.colorfyOutput)
210
- output = output.replace(/\n/g, "");
211
- if (!output)
212
- return this;
213
- if (output.length > this.size && !["error", "warn"].includes(level))
214
- output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
215
- if (level === "error")
216
- this.stderr(output);
217
- else
218
- this.stdout(output);
219
- return this;
220
- }
221
- };
222
- }
223
- });
224
-
225
26
  // src/index.ts
226
27
  var src_exports = {};
227
28
  __export(src_exports, {
@@ -235,7 +36,7 @@ var https = __toESM(require("https"));
235
36
  var import_url = require("url");
236
37
  var import_fs = require("fs");
237
38
  var import_path = require("path");
238
- var import_logger = __toESM(require_dist());
39
+ var import_logger = require("@faasjs/logger");
239
40
  var mock = null;
240
41
  function setMock(handler) {
241
42
  mock = handler;
package/dist/index.mjs CHANGED
@@ -1,235 +1,10 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined")
11
- return require.apply(this, arguments);
12
- throw new Error('Dynamic require of "' + x + '" is not supported');
13
- });
14
- var __commonJS = (cb, mod) => function __require2() {
15
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
- };
17
- var __copyProps = (to, from, except, desc) => {
18
- if (from && typeof from === "object" || typeof from === "function") {
19
- for (let key of __getOwnPropNames(from))
20
- if (!__hasOwnProp.call(to, key) && key !== except)
21
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
- }
23
- return to;
24
- };
25
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
- // If the importer is in node compatibility mode or this is not an ESM
27
- // file that has been converted to a CommonJS file using a Babel-
28
- // compatible transform (i.e. "__esModule" has not been set), then set
29
- // "default" to the CommonJS "module.exports" for node compatibility.
30
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
- mod
32
- ));
33
-
34
- // ../logger/dist/index.js
35
- var require_dist = __commonJS({
36
- "../logger/dist/index.js"(exports, module) {
37
- "use strict";
38
- var __defProp2 = Object.defineProperty;
39
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
40
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
41
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
42
- var __export = (target, all) => {
43
- for (var name in all)
44
- __defProp2(target, name, { get: all[name], enumerable: true });
45
- };
46
- var __copyProps2 = (to, from, except, desc) => {
47
- if (from && typeof from === "object" || typeof from === "function") {
48
- for (let key of __getOwnPropNames2(from))
49
- if (!__hasOwnProp2.call(to, key) && key !== except)
50
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
51
- }
52
- return to;
53
- };
54
- var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
55
- var src_exports = {};
56
- __export(src_exports, {
57
- Color: () => Color,
58
- Logger: () => Logger2
59
- });
60
- module.exports = __toCommonJS(src_exports);
61
- var import_util = __require("util");
62
- var Color = /* @__PURE__ */ ((Color2) => {
63
- Color2[Color2["DEFAULT"] = 39] = "DEFAULT";
64
- Color2[Color2["BLACK"] = 30] = "BLACK";
65
- Color2[Color2["RED"] = 31] = "RED";
66
- Color2[Color2["GREEN"] = 32] = "GREEN";
67
- Color2[Color2["ORANGE"] = 33] = "ORANGE";
68
- Color2[Color2["BLUE"] = 34] = "BLUE";
69
- Color2[Color2["MAGENTA"] = 35] = "MAGENTA";
70
- Color2[Color2["CYAN"] = 36] = "CYAN";
71
- Color2[Color2["GRAY"] = 90] = "GRAY";
72
- return Color2;
73
- })(Color || {});
74
- var LevelColor = ((LevelColor2) => {
75
- LevelColor2[
76
- LevelColor2["debug"] = 90
77
- /* GRAY */
78
- ] = "debug";
79
- LevelColor2[
80
- LevelColor2["info"] = 32
81
- /* GREEN */
82
- ] = "info";
83
- LevelColor2[
84
- LevelColor2["warn"] = 33
85
- /* ORANGE */
86
- ] = "warn";
87
- LevelColor2[
88
- LevelColor2["error"] = 31
89
- /* RED */
90
- ] = "error";
91
- return LevelColor2;
92
- })(LevelColor || {});
93
- var LevelPriority = {
94
- debug: 0,
95
- info: 1,
96
- warn: 2,
97
- error: 3
98
- };
99
- var Logger2 = class {
100
- /**
101
- * @param label {string} Prefix label
102
- */
103
- constructor(label) {
104
- this.colorfyOutput = true;
105
- if (label)
106
- this.label = label;
107
- this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
108
- if (["remote", "mono"].includes(process.env.FaasMode))
109
- this.colorfyOutput = false;
110
- this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
111
- this.cachedTimers = {};
112
- this.size = 1e3;
113
- this.stdout = console.log;
114
- this.stderr = console.error;
115
- }
116
- /**
117
- * @param message {string} message
118
- * @param args {...any=} arguments
119
- */
120
- debug(message, ...args) {
121
- this.log("debug", message, ...args);
122
- return this;
123
- }
124
- /**
125
- * @param message {string} message
126
- * @param args {...any=} arguments
127
- */
128
- info(message, ...args) {
129
- this.log("info", message, ...args);
130
- return this;
131
- }
132
- /**
133
- * @param message {string} message
134
- * @param args {...any=} arguments
135
- */
136
- warn(message, ...args) {
137
- this.log("warn", message, ...args);
138
- return this;
139
- }
140
- /**
141
- * @param message {any} message or Error object
142
- * @param args {...any=} arguments
143
- */
144
- error(message, ...args) {
145
- let stack = false;
146
- [message].concat(Array.from(args)).forEach((e) => {
147
- if (e.stack) {
148
- stack = true;
149
- this.log("error", e.stack);
150
- }
151
- });
152
- if (!stack)
153
- this.log("error", message, ...args);
154
- return this;
155
- }
156
- /**
157
- * @param key {string} timer's label
158
- * @param level [string=debug] 日志级别,支持 debug、info、warn、error
159
- */
160
- time(key, level = "debug") {
161
- this.cachedTimers[key] = {
162
- level,
163
- time: (/* @__PURE__ */ new Date()).getTime()
164
- };
165
- return this;
166
- }
167
- /**
168
- * @param key {string} timer's label
169
- * @param message {string} message
170
- * @param args {...any=} arguments
171
- */
172
- timeEnd(key, message, ...args) {
173
- if (this.cachedTimers[key]) {
174
- const timer = this.cachedTimers[key];
175
- message = message + " +%ims";
176
- args.push((/* @__PURE__ */ new Date()).getTime() - timer.time);
177
- this[timer.level](message, ...args);
178
- delete this.cachedTimers[key];
179
- } else {
180
- this.warn("timeEnd not found key %s", key);
181
- this.debug(message);
182
- }
183
- return this;
184
- }
185
- /**
186
- * @param message {string} message
187
- * @param args {...any=} arguments
188
- */
189
- raw(message, ...args) {
190
- if (this.silent)
191
- return this;
192
- this.stdout((0, import_util.format)(message, ...args));
193
- return this;
194
- }
195
- /**
196
- * @param color {number} color code
197
- * @param message {string} message
198
- */
199
- colorfy(color, message) {
200
- return `\x1B[0${color}m${message}\x1B[39m`;
201
- }
202
- log(level, message, ...args) {
203
- if (this.silent)
204
- return this;
205
- if (LevelPriority[level] < this.level)
206
- return this;
207
- let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + (0, import_util.format)(message, ...args);
208
- if (this.colorfyOutput && level !== "error")
209
- output = this.colorfy(LevelColor[level], output);
210
- else if (!this.colorfyOutput)
211
- output = output.replace(/\n/g, "");
212
- if (!output)
213
- return this;
214
- if (output.length > this.size && !["error", "warn"].includes(level))
215
- output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
216
- if (level === "error")
217
- this.stderr(output);
218
- else
219
- this.stdout(output);
220
- return this;
221
- }
222
- };
223
- }
224
- });
225
-
226
1
  // src/index.ts
227
- var import_logger = __toESM(require_dist());
228
2
  import * as http from "http";
229
3
  import * as https from "https";
230
4
  import { URL } from "url";
231
5
  import { readFileSync } from "fs";
232
6
  import { basename } from "path";
7
+ import { Logger } from "@faasjs/logger";
233
8
  var mock = null;
234
9
  function setMock(handler) {
235
10
  mock = handler;
@@ -269,7 +44,7 @@ async function request(url, {
269
44
  logger
270
45
  } = { headers: {} }) {
271
46
  if (!logger)
272
- logger = new import_logger.Logger("request");
47
+ logger = new Logger("request");
273
48
  if (mock)
274
49
  return mock(url, {
275
50
  headers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/request",
3
- "version": "0.0.3-beta.70",
3
+ "version": "0.0.3-beta.72",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "dist"
22
22
  ],
23
23
  "dependencies": {
24
- "@faasjs/logger": "^0.0.3-beta.70"
24
+ "@faasjs/logger": "^0.0.3-beta.72"
25
25
  },
26
26
  "engines": {
27
27
  "npm": ">=8.0.0",