@faasjs/http 0.0.3-beta.71 → 0.0.3-beta.73

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.
Files changed (3) hide show
  1. package/dist/index.js +18 -662
  2. package/dist/index.mjs +24 -664
  3. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -5,6 +5,9 @@ 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 __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
8
11
  var __commonJS = (cb, mod) => function __require() {
9
12
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
13
  };
@@ -21,465 +24,22 @@ var __copyProps = (to, from, except, desc) => {
21
24
  return to;
22
25
  };
23
26
  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
27
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
28
  mod
30
29
  ));
31
30
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
31
 
33
- // ../func/dist/index.js
34
- var require_dist = __commonJS({
35
- "../func/dist/index.js"(exports, module2) {
36
- "use strict";
37
- var __create2 = Object.create;
38
- var __defProp2 = Object.defineProperty;
39
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
40
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
41
- var __getProtoOf2 = Object.getPrototypeOf;
42
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
43
- var __commonJS2 = (cb, mod) => function __require() {
44
- return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
45
- };
46
- var __export2 = (target, all) => {
47
- for (var name in all)
48
- __defProp2(target, name, { get: all[name], enumerable: true });
49
- };
50
- var __copyProps2 = (to, from, except, desc) => {
51
- if (from && typeof from === "object" || typeof from === "function") {
52
- for (let key of __getOwnPropNames2(from))
53
- if (!__hasOwnProp2.call(to, key) && key !== except)
54
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
55
- }
56
- return to;
57
- };
58
- var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
59
- // If the importer is in node compatibility mode or this is not an ESM
60
- // file that has been converted to a CommonJS file using a Babel-
61
- // compatible transform (i.e. "__esModule" has not been set), then set
62
- // "default" to the CommonJS "module.exports" for node compatibility.
63
- isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
64
- mod
65
- ));
66
- var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
67
- var require_dist4 = __commonJS2({
68
- "../logger/dist/index.js"(exports2, module22) {
69
- "use strict";
70
- var __defProp22 = Object.defineProperty;
71
- var __getOwnPropDesc22 = Object.getOwnPropertyDescriptor;
72
- var __getOwnPropNames22 = Object.getOwnPropertyNames;
73
- var __hasOwnProp22 = Object.prototype.hasOwnProperty;
74
- var __export22 = (target, all) => {
75
- for (var name in all)
76
- __defProp22(target, name, { get: all[name], enumerable: true });
77
- };
78
- var __copyProps22 = (to, from, except, desc) => {
79
- if (from && typeof from === "object" || typeof from === "function") {
80
- for (let key of __getOwnPropNames22(from))
81
- if (!__hasOwnProp22.call(to, key) && key !== except)
82
- __defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc22(from, key)) || desc.enumerable });
83
- }
84
- return to;
85
- };
86
- var __toCommonJS22 = (mod) => __copyProps22(__defProp22({}, "__esModule", { value: true }), mod);
87
- var src_exports22 = {};
88
- __export22(src_exports22, {
89
- Color: () => Color,
90
- Logger: () => Logger2
91
- });
92
- module22.exports = __toCommonJS22(src_exports22);
93
- var import_util = require("util");
94
- var Color = /* @__PURE__ */ ((Color2) => {
95
- Color2[Color2["DEFAULT"] = 39] = "DEFAULT";
96
- Color2[Color2["BLACK"] = 30] = "BLACK";
97
- Color2[Color2["RED"] = 31] = "RED";
98
- Color2[Color2["GREEN"] = 32] = "GREEN";
99
- Color2[Color2["ORANGE"] = 33] = "ORANGE";
100
- Color2[Color2["BLUE"] = 34] = "BLUE";
101
- Color2[Color2["MAGENTA"] = 35] = "MAGENTA";
102
- Color2[Color2["CYAN"] = 36] = "CYAN";
103
- Color2[Color2["GRAY"] = 90] = "GRAY";
104
- return Color2;
105
- })(Color || {});
106
- var LevelColor = ((LevelColor2) => {
107
- LevelColor2[
108
- LevelColor2["debug"] = 90
109
- /* GRAY */
110
- ] = "debug";
111
- LevelColor2[
112
- LevelColor2["info"] = 32
113
- /* GREEN */
114
- ] = "info";
115
- LevelColor2[
116
- LevelColor2["warn"] = 33
117
- /* ORANGE */
118
- ] = "warn";
119
- LevelColor2[
120
- LevelColor2["error"] = 31
121
- /* RED */
122
- ] = "error";
123
- return LevelColor2;
124
- })(LevelColor || {});
125
- var LevelPriority = {
126
- debug: 0,
127
- info: 1,
128
- warn: 2,
129
- error: 3
130
- };
131
- var Logger2 = class {
132
- /**
133
- * @param label {string} Prefix label
134
- */
135
- constructor(label) {
136
- this.colorfyOutput = true;
137
- if (label)
138
- this.label = label;
139
- this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
140
- if (["remote", "mono"].includes(process.env.FaasMode))
141
- this.colorfyOutput = false;
142
- this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
143
- this.cachedTimers = {};
144
- this.size = 1e3;
145
- this.stdout = console.log;
146
- this.stderr = console.error;
147
- }
148
- /**
149
- * @param message {string} message
150
- * @param args {...any=} arguments
151
- */
152
- debug(message, ...args) {
153
- this.log("debug", message, ...args);
154
- return this;
155
- }
156
- /**
157
- * @param message {string} message
158
- * @param args {...any=} arguments
159
- */
160
- info(message, ...args) {
161
- this.log("info", message, ...args);
162
- return this;
163
- }
164
- /**
165
- * @param message {string} message
166
- * @param args {...any=} arguments
167
- */
168
- warn(message, ...args) {
169
- this.log("warn", message, ...args);
170
- return this;
171
- }
172
- /**
173
- * @param message {any} message or Error object
174
- * @param args {...any=} arguments
175
- */
176
- error(message, ...args) {
177
- let stack = false;
178
- [message].concat(Array.from(args)).forEach((e) => {
179
- if (e.stack) {
180
- stack = true;
181
- this.log("error", e.stack);
182
- }
183
- });
184
- if (!stack)
185
- this.log("error", message, ...args);
186
- return this;
187
- }
188
- /**
189
- * @param key {string} timer's label
190
- * @param level [string=debug] 日志级别,支持 debug、info、warn、error
191
- */
192
- time(key, level = "debug") {
193
- this.cachedTimers[key] = {
194
- level,
195
- time: (/* @__PURE__ */ new Date()).getTime()
196
- };
197
- return this;
198
- }
199
- /**
200
- * @param key {string} timer's label
201
- * @param message {string} message
202
- * @param args {...any=} arguments
203
- */
204
- timeEnd(key, message, ...args) {
205
- if (this.cachedTimers[key]) {
206
- const timer = this.cachedTimers[key];
207
- message = message + " +%ims";
208
- args.push((/* @__PURE__ */ new Date()).getTime() - timer.time);
209
- this[timer.level](message, ...args);
210
- delete this.cachedTimers[key];
211
- } else {
212
- this.warn("timeEnd not found key %s", key);
213
- this.debug(message);
214
- }
215
- return this;
216
- }
217
- /**
218
- * @param message {string} message
219
- * @param args {...any=} arguments
220
- */
221
- raw(message, ...args) {
222
- if (this.silent)
223
- return this;
224
- this.stdout((0, import_util.format)(message, ...args));
225
- return this;
226
- }
227
- /**
228
- * @param color {number} color code
229
- * @param message {string} message
230
- */
231
- colorfy(color, message) {
232
- return `\x1B[0${color}m${message}\x1B[39m`;
233
- }
234
- log(level, message, ...args) {
235
- if (this.silent)
236
- return this;
237
- if (LevelPriority[level] < this.level)
238
- return this;
239
- let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + (0, import_util.format)(message, ...args);
240
- if (this.colorfyOutput && level !== "error")
241
- output = this.colorfy(LevelColor[level], output);
242
- else if (!this.colorfyOutput)
243
- output = output.replace(/\n/g, "");
244
- if (!output)
245
- return this;
246
- if (output.length > this.size && !["error", "warn"].includes(level))
247
- output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
248
- if (level === "error")
249
- this.stderr(output);
250
- else
251
- this.stdout(output);
252
- return this;
253
- }
254
- };
255
- }
256
- });
257
- var src_exports2 = {};
258
- __export2(src_exports2, {
259
- Func: () => Func,
260
- useFunc: () => useFunc,
261
- usePlugin: () => usePlugin2
262
- });
263
- module2.exports = __toCommonJS2(src_exports2);
264
- var import_logger2 = __toESM2(require_dist4());
265
- var RunHandler = class {
266
- constructor() {
267
- this.type = "handler";
268
- this.name = "handler";
269
- }
270
- async onInvoke(data, next) {
271
- if (data.handler)
272
- if (!data.runHandler) {
273
- try {
274
- data.response = await new Promise(function(resolve, reject) {
275
- data.callback = function(error, result) {
276
- if (error)
277
- reject(error);
278
- else
279
- resolve(result);
280
- };
281
- Promise.resolve(data.handler(data)).then(resolve).catch(reject);
282
- });
283
- } catch (error) {
284
- data.logger.error(error);
285
- data.response = error;
286
- }
287
- data.runHandler = true;
288
- } else
289
- data.logger.warn("[RunHandler] handler has been run");
290
- await next();
291
- }
292
- };
293
- var import_crypto2 = require("crypto");
294
- var Func = class {
295
- /**
296
- * Create a cloud function
297
- * @param config {object} config
298
- * @param config.plugins {Plugin[]} plugins list
299
- * @param config.handler {Handler} business logic
300
- */
301
- constructor(config) {
302
- this.handler = config.handler;
303
- this.plugins = config.plugins || [];
304
- this.plugins.push(new RunHandler());
305
- this.config = {
306
- providers: /* @__PURE__ */ Object.create(null),
307
- plugins: /* @__PURE__ */ Object.create(null)
308
- };
309
- this.mounted = false;
310
- this.cachedFunctions = /* @__PURE__ */ Object.create(null);
311
- try {
312
- this.filename = new Error().stack.split("\n").find((s) => /[^/]\.func\.ts/.test(s)).match(/\((.*\.func\.ts).*\)/)[1];
313
- } catch (error) {
314
- new import_logger2.Logger("Func").warn(error.message);
315
- }
316
- }
317
- compose(key) {
318
- let list = [];
319
- if (this.cachedFunctions[key])
320
- list = this.cachedFunctions[key];
321
- else {
322
- for (const plugin of this.plugins) {
323
- const handler = plugin[key];
324
- if (typeof handler === "function")
325
- list.push({
326
- key: plugin.name,
327
- handler: handler.bind(plugin)
328
- });
329
- }
330
- this.cachedFunctions[key] = list;
331
- }
332
- return async function(data, next) {
333
- let index = -1;
334
- const logger = (data == null ? void 0 : data.logger) || new import_logger2.Logger();
335
- const dispatch = async function(i) {
336
- if (i <= index)
337
- return Promise.reject(Error("next() called multiple times"));
338
- index = i;
339
- let fn = list[i];
340
- if (i === list.length)
341
- fn = next;
342
- if (!fn)
343
- return Promise.resolve();
344
- if (typeof fn.key === "undefined")
345
- fn.key = `UnNamedPlugin#${i}`;
346
- logger.debug("[%s][%s] begin", fn.key, key);
347
- logger.time(fn.key);
348
- try {
349
- const res = await Promise.resolve(fn.handler(data, dispatch.bind(null, i + 1)));
350
- logger.timeEnd(fn.key, "[%s][%s] end", fn.key, key);
351
- return res;
352
- } catch (err) {
353
- logger.timeEnd(fn.key, "[%s][%s] failed", fn.key, key);
354
- logger.error(err);
355
- return Promise.reject(err);
356
- }
357
- };
358
- return await dispatch(0);
359
- };
360
- }
361
- /**
362
- * Deploy the function
363
- * @param data {object} data
364
- * @param data.root {string} root path
365
- * @param data.filename {string} filename
366
- * @param data.env {string} environment
367
- */
368
- deploy(data) {
369
- if (!data.logger)
370
- data.logger = new import_logger2.Logger("Func");
371
- data.logger.debug("onDeploy");
372
- data.logger.debug("Plugins: " + this.plugins.map((p) => `${p.type}#${p.name}`).join(","));
373
- return this.compose("onDeploy")(data);
374
- }
375
- /**
376
- * First time mount the function
377
- */
378
- async mount(data) {
379
- if (!data.logger)
380
- data.logger = new import_logger2.Logger("Func");
381
- data.logger.debug("onMount");
382
- if (this.mounted) {
383
- data.logger.warn("mount() has been called, skipped.");
384
- return;
385
- }
386
- if (!data.config)
387
- data.config = this.config;
388
- try {
389
- data.logger.time("mount");
390
- data.logger.debug("Plugins: " + this.plugins.map((p) => `${p.type}#${p.name}`).join(","));
391
- await this.compose("onMount")(data);
392
- this.mounted = true;
393
- } finally {
394
- data.logger.timeEnd("mount", "mounted");
395
- }
396
- }
397
- /**
398
- * Invoke the function
399
- * @param data {object} data
400
- */
401
- async invoke(data) {
402
- if (!this.mounted)
403
- await this.mount({
404
- event: data.event,
405
- context: data.context,
406
- config: data.config,
407
- logger: data.logger
408
- });
409
- try {
410
- await this.compose("onInvoke")(data);
411
- } catch (error) {
412
- data.logger.error(error);
413
- data.response = error;
414
- }
415
- }
416
- /**
417
- * Export the function
418
- */
419
- export() {
420
- const handler = async (event, context, callback) => {
421
- if (typeof context === "undefined")
422
- context = {};
423
- if (!context.request_id)
424
- context.request_id = (0, import_crypto2.randomBytes)(16).toString("hex");
425
- if (!context.request_at)
426
- context.request_at = Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3);
427
- context.callbackWaitsForEmptyEventLoop = false;
428
- const logger = new import_logger2.Logger(context.request_id);
429
- logger.debug("event: %j", event);
430
- logger.debug("context: %j", context);
431
- const data = {
432
- event,
433
- context,
434
- callback,
435
- response: void 0,
436
- handler: this.handler,
437
- logger,
438
- config: this.config
439
- };
440
- await this.invoke(data);
441
- if (Object.prototype.toString.call(data.response) === "[object Error]")
442
- throw data.response;
443
- return data.response;
444
- };
445
- handler.bind(this);
446
- return { handler };
447
- }
448
- };
449
- var plugins = [];
450
- function usePlugin2(plugin) {
451
- if (!plugins.find((p) => p.name === plugin.name))
452
- plugins.push(plugin);
453
- if (!plugin.mount)
454
- plugin.mount = async function(data) {
455
- if (plugin.onMount)
456
- await plugin.onMount({
457
- config: (data == null ? void 0 : data.config) || /* @__PURE__ */ Object.create(null),
458
- event: /* @__PURE__ */ Object.create(null),
459
- context: /* @__PURE__ */ Object.create(null),
460
- logger: new import_logger2.Logger(plugin.name)
461
- }, async () => Promise.resolve());
462
- return plugin;
463
- };
464
- return plugin;
465
- }
466
- function useFunc(handler) {
467
- plugins = [];
468
- const invokeHandler = handler();
469
- const func = new Func({
470
- plugins,
471
- handler: invokeHandler
472
- });
473
- plugins = [];
474
- return func;
475
- }
32
+ // ../../node_modules/tsup/assets/cjs_shims.js
33
+ var init_cjs_shims = __esm({
34
+ "../../node_modules/tsup/assets/cjs_shims.js"() {
476
35
  }
477
36
  });
478
37
 
479
38
  // ../deep_merge/dist/index.js
480
- var require_dist2 = __commonJS({
39
+ var require_dist = __commonJS({
481
40
  "../deep_merge/dist/index.js"(exports, module2) {
482
41
  "use strict";
42
+ init_cjs_shims();
483
43
  var __defProp2 = Object.defineProperty;
484
44
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
485
45
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
@@ -530,198 +90,6 @@ var require_dist2 = __commonJS({
530
90
  }
531
91
  });
532
92
 
533
- // ../logger/dist/index.js
534
- var require_dist3 = __commonJS({
535
- "../logger/dist/index.js"(exports, module2) {
536
- "use strict";
537
- var __defProp2 = Object.defineProperty;
538
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
539
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
540
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
541
- var __export2 = (target, all) => {
542
- for (var name in all)
543
- __defProp2(target, name, { get: all[name], enumerable: true });
544
- };
545
- var __copyProps2 = (to, from, except, desc) => {
546
- if (from && typeof from === "object" || typeof from === "function") {
547
- for (let key of __getOwnPropNames2(from))
548
- if (!__hasOwnProp2.call(to, key) && key !== except)
549
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
550
- }
551
- return to;
552
- };
553
- var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
554
- var src_exports2 = {};
555
- __export2(src_exports2, {
556
- Color: () => Color,
557
- Logger: () => Logger2
558
- });
559
- module2.exports = __toCommonJS2(src_exports2);
560
- var import_util = require("util");
561
- var Color = /* @__PURE__ */ ((Color2) => {
562
- Color2[Color2["DEFAULT"] = 39] = "DEFAULT";
563
- Color2[Color2["BLACK"] = 30] = "BLACK";
564
- Color2[Color2["RED"] = 31] = "RED";
565
- Color2[Color2["GREEN"] = 32] = "GREEN";
566
- Color2[Color2["ORANGE"] = 33] = "ORANGE";
567
- Color2[Color2["BLUE"] = 34] = "BLUE";
568
- Color2[Color2["MAGENTA"] = 35] = "MAGENTA";
569
- Color2[Color2["CYAN"] = 36] = "CYAN";
570
- Color2[Color2["GRAY"] = 90] = "GRAY";
571
- return Color2;
572
- })(Color || {});
573
- var LevelColor = ((LevelColor2) => {
574
- LevelColor2[
575
- LevelColor2["debug"] = 90
576
- /* GRAY */
577
- ] = "debug";
578
- LevelColor2[
579
- LevelColor2["info"] = 32
580
- /* GREEN */
581
- ] = "info";
582
- LevelColor2[
583
- LevelColor2["warn"] = 33
584
- /* ORANGE */
585
- ] = "warn";
586
- LevelColor2[
587
- LevelColor2["error"] = 31
588
- /* RED */
589
- ] = "error";
590
- return LevelColor2;
591
- })(LevelColor || {});
592
- var LevelPriority = {
593
- debug: 0,
594
- info: 1,
595
- warn: 2,
596
- error: 3
597
- };
598
- var Logger2 = class {
599
- /**
600
- * @param label {string} Prefix label
601
- */
602
- constructor(label) {
603
- this.colorfyOutput = true;
604
- if (label)
605
- this.label = label;
606
- this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
607
- if (["remote", "mono"].includes(process.env.FaasMode))
608
- this.colorfyOutput = false;
609
- this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
610
- this.cachedTimers = {};
611
- this.size = 1e3;
612
- this.stdout = console.log;
613
- this.stderr = console.error;
614
- }
615
- /**
616
- * @param message {string} message
617
- * @param args {...any=} arguments
618
- */
619
- debug(message, ...args) {
620
- this.log("debug", message, ...args);
621
- return this;
622
- }
623
- /**
624
- * @param message {string} message
625
- * @param args {...any=} arguments
626
- */
627
- info(message, ...args) {
628
- this.log("info", message, ...args);
629
- return this;
630
- }
631
- /**
632
- * @param message {string} message
633
- * @param args {...any=} arguments
634
- */
635
- warn(message, ...args) {
636
- this.log("warn", message, ...args);
637
- return this;
638
- }
639
- /**
640
- * @param message {any} message or Error object
641
- * @param args {...any=} arguments
642
- */
643
- error(message, ...args) {
644
- let stack = false;
645
- [message].concat(Array.from(args)).forEach((e) => {
646
- if (e.stack) {
647
- stack = true;
648
- this.log("error", e.stack);
649
- }
650
- });
651
- if (!stack)
652
- this.log("error", message, ...args);
653
- return this;
654
- }
655
- /**
656
- * @param key {string} timer's label
657
- * @param level [string=debug] 日志级别,支持 debug、info、warn、error
658
- */
659
- time(key, level = "debug") {
660
- this.cachedTimers[key] = {
661
- level,
662
- time: (/* @__PURE__ */ new Date()).getTime()
663
- };
664
- return this;
665
- }
666
- /**
667
- * @param key {string} timer's label
668
- * @param message {string} message
669
- * @param args {...any=} arguments
670
- */
671
- timeEnd(key, message, ...args) {
672
- if (this.cachedTimers[key]) {
673
- const timer = this.cachedTimers[key];
674
- message = message + " +%ims";
675
- args.push((/* @__PURE__ */ new Date()).getTime() - timer.time);
676
- this[timer.level](message, ...args);
677
- delete this.cachedTimers[key];
678
- } else {
679
- this.warn("timeEnd not found key %s", key);
680
- this.debug(message);
681
- }
682
- return this;
683
- }
684
- /**
685
- * @param message {string} message
686
- * @param args {...any=} arguments
687
- */
688
- raw(message, ...args) {
689
- if (this.silent)
690
- return this;
691
- this.stdout((0, import_util.format)(message, ...args));
692
- return this;
693
- }
694
- /**
695
- * @param color {number} color code
696
- * @param message {string} message
697
- */
698
- colorfy(color, message) {
699
- return `\x1B[0${color}m${message}\x1B[39m`;
700
- }
701
- log(level, message, ...args) {
702
- if (this.silent)
703
- return this;
704
- if (LevelPriority[level] < this.level)
705
- return this;
706
- let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + (0, import_util.format)(message, ...args);
707
- if (this.colorfyOutput && level !== "error")
708
- output = this.colorfy(LevelColor[level], output);
709
- else if (!this.colorfyOutput)
710
- output = output.replace(/\n/g, "");
711
- if (!output)
712
- return this;
713
- if (output.length > this.size && !["error", "warn"].includes(level))
714
- output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
715
- if (level === "error")
716
- this.stderr(output);
717
- else
718
- this.stdout(output);
719
- return this;
720
- }
721
- };
722
- }
723
- });
724
-
725
93
  // src/index.ts
726
94
  var src_exports = {};
727
95
  __export(src_exports, {
@@ -734,11 +102,16 @@ __export(src_exports, {
734
102
  useHttp: () => useHttp
735
103
  });
736
104
  module.exports = __toCommonJS(src_exports);
737
- var import_func = __toESM(require_dist());
738
- var import_deep_merge2 = __toESM(require_dist2());
739
- var import_logger = __toESM(require_dist3());
105
+ init_cjs_shims();
106
+ var import_func = require("@faasjs/func");
107
+ var import_deep_merge2 = __toESM(require_dist());
108
+ var import_logger = require("@faasjs/logger");
109
+
110
+ // src/cookie.ts
111
+ init_cjs_shims();
740
112
 
741
113
  // src/session.ts
114
+ init_cjs_shims();
742
115
  var import_crypto = require("crypto");
743
116
  var Session = class {
744
117
  constructor(cookie, config) {
@@ -829,7 +202,7 @@ var Session = class {
829
202
  };
830
203
 
831
204
  // src/cookie.ts
832
- var import_deep_merge = __toESM(require_dist2());
205
+ var import_deep_merge = __toESM(require_dist());
833
206
  var Cookie = class {
834
207
  constructor(config) {
835
208
  this.config = (0, import_deep_merge.deepMerge)({
@@ -895,6 +268,7 @@ var Cookie = class {
895
268
  };
896
269
 
897
270
  // src/validator.ts
271
+ init_cjs_shims();
898
272
  var Validator = class {
899
273
  constructor(config) {
900
274
  this.paramsConfig = config.params;
@@ -1248,20 +622,10 @@ var Http = class {
1248
622
  delete data.response.headers["Content-Encoding"];
1249
623
  }
1250
624
  }
1251
- /**
1252
- * set header
1253
- * @param key {string} key
1254
- * @param value {*} value
1255
- */
1256
625
  setHeader(key, value) {
1257
626
  this.response.headers[key] = value;
1258
627
  return this;
1259
628
  }
1260
- /**
1261
- * set Content-Type
1262
- * @param type {string} 类型
1263
- * @param charset {string} 编码
1264
- */
1265
629
  setContentType(type, charset = "utf-8") {
1266
630
  if (ContentType[type])
1267
631
  this.setHeader("Content-Type", `${ContentType[type]}; charset=${charset}`);
@@ -1269,18 +633,10 @@ var Http = class {
1269
633
  this.setHeader("Content-Type", `${type}; charset=${charset}`);
1270
634
  return this;
1271
635
  }
1272
- /**
1273
- * set status code
1274
- * @param code {number} 状态码
1275
- */
1276
636
  setStatusCode(code) {
1277
637
  this.response.statusCode = code;
1278
638
  return this;
1279
639
  }
1280
- /**
1281
- * set body
1282
- * @param body {*} 内容
1283
- */
1284
640
  setBody(body) {
1285
641
  this.response.body = body;
1286
642
  return this;