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