@faasjs/knex 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.
package/dist/index.mjs CHANGED
@@ -1,9 +1,3 @@
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
1
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
2
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
3
  }) : x)(function(x) {
@@ -11,722 +5,13 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
11
5
  return require.apply(this, arguments);
12
6
  throw new Error('Dynamic require of "' + x + '" is not supported');
13
7
  });
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
- // ../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_crypto = __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_crypto.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
- }
477
- }
478
- });
479
-
480
- // ../logger/dist/index.js
481
- var require_dist2 = __commonJS({
482
- "../logger/dist/index.js"(exports, module) {
483
- "use strict";
484
- var __defProp2 = Object.defineProperty;
485
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
486
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
487
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
488
- var __export = (target, all) => {
489
- for (var name in all)
490
- __defProp2(target, name, { get: all[name], enumerable: true });
491
- };
492
- var __copyProps2 = (to, from, except, desc) => {
493
- if (from && typeof from === "object" || typeof from === "function") {
494
- for (let key of __getOwnPropNames2(from))
495
- if (!__hasOwnProp2.call(to, key) && key !== except)
496
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
497
- }
498
- return to;
499
- };
500
- var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
501
- var src_exports = {};
502
- __export(src_exports, {
503
- Color: () => Color,
504
- Logger: () => Logger2
505
- });
506
- module.exports = __toCommonJS(src_exports);
507
- var import_util = __require("util");
508
- var Color = /* @__PURE__ */ ((Color2) => {
509
- Color2[Color2["DEFAULT"] = 39] = "DEFAULT";
510
- Color2[Color2["BLACK"] = 30] = "BLACK";
511
- Color2[Color2["RED"] = 31] = "RED";
512
- Color2[Color2["GREEN"] = 32] = "GREEN";
513
- Color2[Color2["ORANGE"] = 33] = "ORANGE";
514
- Color2[Color2["BLUE"] = 34] = "BLUE";
515
- Color2[Color2["MAGENTA"] = 35] = "MAGENTA";
516
- Color2[Color2["CYAN"] = 36] = "CYAN";
517
- Color2[Color2["GRAY"] = 90] = "GRAY";
518
- return Color2;
519
- })(Color || {});
520
- var LevelColor = ((LevelColor2) => {
521
- LevelColor2[
522
- LevelColor2["debug"] = 90
523
- /* GRAY */
524
- ] = "debug";
525
- LevelColor2[
526
- LevelColor2["info"] = 32
527
- /* GREEN */
528
- ] = "info";
529
- LevelColor2[
530
- LevelColor2["warn"] = 33
531
- /* ORANGE */
532
- ] = "warn";
533
- LevelColor2[
534
- LevelColor2["error"] = 31
535
- /* RED */
536
- ] = "error";
537
- return LevelColor2;
538
- })(LevelColor || {});
539
- var LevelPriority = {
540
- debug: 0,
541
- info: 1,
542
- warn: 2,
543
- error: 3
544
- };
545
- var Logger2 = class {
546
- /**
547
- * @param label {string} Prefix label
548
- */
549
- constructor(label) {
550
- this.colorfyOutput = true;
551
- if (label)
552
- this.label = label;
553
- this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
554
- if (["remote", "mono"].includes(process.env.FaasMode))
555
- this.colorfyOutput = false;
556
- this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
557
- this.cachedTimers = {};
558
- this.size = 1e3;
559
- this.stdout = console.log;
560
- this.stderr = console.error;
561
- }
562
- /**
563
- * @param message {string} message
564
- * @param args {...any=} arguments
565
- */
566
- debug(message, ...args) {
567
- this.log("debug", message, ...args);
568
- return this;
569
- }
570
- /**
571
- * @param message {string} message
572
- * @param args {...any=} arguments
573
- */
574
- info(message, ...args) {
575
- this.log("info", message, ...args);
576
- return this;
577
- }
578
- /**
579
- * @param message {string} message
580
- * @param args {...any=} arguments
581
- */
582
- warn(message, ...args) {
583
- this.log("warn", message, ...args);
584
- return this;
585
- }
586
- /**
587
- * @param message {any} message or Error object
588
- * @param args {...any=} arguments
589
- */
590
- error(message, ...args) {
591
- let stack = false;
592
- [message].concat(Array.from(args)).forEach((e) => {
593
- if (e.stack) {
594
- stack = true;
595
- this.log("error", e.stack);
596
- }
597
- });
598
- if (!stack)
599
- this.log("error", message, ...args);
600
- return this;
601
- }
602
- /**
603
- * @param key {string} timer's label
604
- * @param level [string=debug] 日志级别,支持 debug、info、warn、error
605
- */
606
- time(key, level = "debug") {
607
- this.cachedTimers[key] = {
608
- level,
609
- time: (/* @__PURE__ */ new Date()).getTime()
610
- };
611
- return this;
612
- }
613
- /**
614
- * @param key {string} timer's label
615
- * @param message {string} message
616
- * @param args {...any=} arguments
617
- */
618
- timeEnd(key, message, ...args) {
619
- if (this.cachedTimers[key]) {
620
- const timer = this.cachedTimers[key];
621
- message = message + " +%ims";
622
- args.push((/* @__PURE__ */ new Date()).getTime() - timer.time);
623
- this[timer.level](message, ...args);
624
- delete this.cachedTimers[key];
625
- } else {
626
- this.warn("timeEnd not found key %s", key);
627
- this.debug(message);
628
- }
629
- return this;
630
- }
631
- /**
632
- * @param message {string} message
633
- * @param args {...any=} arguments
634
- */
635
- raw(message, ...args) {
636
- if (this.silent)
637
- return this;
638
- this.stdout((0, import_util.format)(message, ...args));
639
- return this;
640
- }
641
- /**
642
- * @param color {number} color code
643
- * @param message {string} message
644
- */
645
- colorfy(color, message) {
646
- return `\x1B[0${color}m${message}\x1B[39m`;
647
- }
648
- log(level, message, ...args) {
649
- if (this.silent)
650
- return this;
651
- if (LevelPriority[level] < this.level)
652
- return this;
653
- let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + (0, import_util.format)(message, ...args);
654
- if (this.colorfyOutput && level !== "error")
655
- output = this.colorfy(LevelColor[level], output);
656
- else if (!this.colorfyOutput)
657
- output = output.replace(/\n/g, "");
658
- if (!output)
659
- return this;
660
- if (output.length > this.size && !["error", "warn"].includes(level))
661
- output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
662
- if (level === "error")
663
- this.stderr(output);
664
- else
665
- this.stdout(output);
666
- return this;
667
- }
668
- };
669
- }
670
- });
671
-
672
- // ../deep_merge/dist/index.js
673
- var require_dist3 = __commonJS({
674
- "../deep_merge/dist/index.js"(exports, module) {
675
- "use strict";
676
- var __defProp2 = Object.defineProperty;
677
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
678
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
679
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
680
- var __export = (target, all) => {
681
- for (var name in all)
682
- __defProp2(target, name, { get: all[name], enumerable: true });
683
- };
684
- var __copyProps2 = (to, from, except, desc) => {
685
- if (from && typeof from === "object" || typeof from === "function") {
686
- for (let key of __getOwnPropNames2(from))
687
- if (!__hasOwnProp2.call(to, key) && key !== except)
688
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
689
- }
690
- return to;
691
- };
692
- var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
693
- var src_exports = {};
694
- __export(src_exports, {
695
- deepMerge: () => deepMerge2
696
- });
697
- module.exports = __toCommonJS(src_exports);
698
- var shouldMerge = function(item) {
699
- const type = Object.prototype.toString.call(item);
700
- return type === "[object Object]" || type === "[object Array]";
701
- };
702
- function deepMerge2(...sources) {
703
- let acc = /* @__PURE__ */ Object.create(null);
704
- for (const source of sources)
705
- if (source instanceof Array) {
706
- if (!(acc instanceof Array))
707
- acc = [];
708
- acc = [...new Set(source.concat(...acc))];
709
- } else if (shouldMerge(source))
710
- for (const [key, value] of Object.entries(source)) {
711
- let val;
712
- if (shouldMerge(value))
713
- val = deepMerge2(acc[key], value);
714
- else
715
- val = value;
716
- acc = {
717
- ...acc,
718
- [key]: val
719
- };
720
- }
721
- return acc;
722
- }
723
- }
724
- });
725
8
 
726
9
  // src/index.ts
727
- var import_func = __toESM(require_dist());
728
- var import_logger = __toESM(require_dist2());
729
- var import_deep_merge = __toESM(require_dist3());
10
+ import {
11
+ usePlugin
12
+ } from "@faasjs/func";
13
+ import { Logger } from "@faasjs/logger";
14
+ import { deepMerge } from "@faasjs/deep_merge";
730
15
  import knex from "knex";
731
16
  var Name = "knex";
732
17
  if (!global["FaasJS_Knex"]) {
@@ -753,7 +38,7 @@ var Knex = class {
753
38
  data.dependencies["better-sqlite3"] = "*";
754
39
  else
755
40
  data.dependencies[client] = "*";
756
- new import_logger.Logger(this.name).debug("add dependencies: " + client);
41
+ new Logger(this.name).debug("add dependencies: " + client);
757
42
  await next();
758
43
  }
759
44
  async onMount(data, next) {
@@ -781,7 +66,7 @@ var Knex = class {
781
66
  this.config[key] = value;
782
67
  }
783
68
  if (data.config.plugins && ((_a = data.config.plugins[this.name]) == null ? void 0 : _a.config))
784
- this.config = (0, import_deep_merge.deepMerge)(data.config.plugins[this.name].config, this.config);
69
+ this.config = deepMerge(data.config.plugins[this.name].config, this.config);
785
70
  if (this.config.client === "sqlite3")
786
71
  this.config.client = "better-sqlite3";
787
72
  if (this.config.client === "pg" && typeof ((_b = this.config.pool) == null ? void 0 : _b.propagateCreateError) === "undefined") {
@@ -873,8 +158,8 @@ var Knex = class {
873
158
  function useKnex(config) {
874
159
  const name = (config == null ? void 0 : config.name) || Name;
875
160
  if (global.FaasJS_Knex[name])
876
- return (0, import_func.usePlugin)(global.FaasJS_Knex[name]);
877
- return (0, import_func.usePlugin)(new Knex(config));
161
+ return usePlugin(global.FaasJS_Knex[name]);
162
+ return usePlugin(new Knex(config));
878
163
  }
879
164
  function query(table) {
880
165
  return useKnex().query(table);