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