@webtypen/webframez-core 0.3.30 → 0.3.31
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/dev/storage/test-storage-check/a.txt +1 -0
- package/dist/BaseKernelWeb.js +1 -0
- package/dist/Commands/ConsoleCommand.js +10 -1
- package/dist/Commands/QueueStopCommand.js +1 -1
- package/dist/Commands/QueueWorkerCommand.js +38 -1
- package/dist/ConsoleApplication.js +26 -4
- package/dist/DataBuilder/DataBuilder.js +9 -0
- package/dist/ErrorHandling/ErrorHandler.d.ts +46 -0
- package/dist/ErrorHandling/ErrorHandler.js +79 -0
- package/dist/Facades/Storage.d.ts +7 -30
- package/dist/Facades/Storage.js +14 -10
- package/dist/Facades/StorageDrivers/LocalStorageDriver.d.ts +1 -0
- package/dist/Facades/StorageDrivers/LocalStorageDriver.js +29 -12
- package/dist/LambdaApplication.js +9 -0
- package/dist/Queue/QueueJobsRegisty.d.ts +4 -0
- package/dist/Queue/QueueJobsRegisty.js +35 -2
- package/dist/Router/Router.d.ts +9 -0
- package/dist/Router/Router.js +131 -26
- package/dist/WebApplication.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -2
- package/dist/info.js +1 -1
- package/package.json +1 -1
- package/src/BaseKernelWeb.ts +1 -1
- package/src/Commands/ConsoleCommand.ts +10 -1
- package/src/Commands/QueueStopCommand.ts +3 -3
- package/src/Commands/QueueWorkerCommand.ts +38 -1
- package/src/ConsoleApplication.ts +25 -4
- package/src/DataBuilder/DataBuilder.ts +26 -16
- package/src/ErrorHandling/ErrorHandler.ts +109 -0
- package/src/Facades/Storage.ts +15 -10
- package/src/Facades/StorageDrivers/LocalStorageDriver.ts +35 -11
- package/src/LambdaApplication.ts +9 -0
- package/src/Queue/QueueJobsRegisty.ts +43 -2
- package/src/Router/Router.ts +154 -27
- package/src/WebApplication.ts +9 -0
- package/src/index.ts +2 -2
- package/src/info.ts +1 -1
- package/src/Telemetry/SigNozTelemetry.ts +0 -268
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hello
|
package/dist/BaseKernelWeb.js
CHANGED
|
@@ -16,6 +16,7 @@ exports.ConsoleCommand = void 0;
|
|
|
16
16
|
const readline_1 = __importDefault(require("readline"));
|
|
17
17
|
const ConsoleProgressBar_1 = require("./ConsoleProgressBar");
|
|
18
18
|
const ConsoleOutputHelper_1 = require("./ConsoleOutputHelper");
|
|
19
|
+
const ErrorHandler_1 = require("../ErrorHandling/ErrorHandler");
|
|
19
20
|
class ConsoleCommand {
|
|
20
21
|
constructor(args) {
|
|
21
22
|
this.rl = null;
|
|
@@ -41,7 +42,15 @@ class ConsoleCommand {
|
|
|
41
42
|
yield this.handle();
|
|
42
43
|
}
|
|
43
44
|
catch (e) {
|
|
44
|
-
|
|
45
|
+
yield ErrorHandler_1.ErrorHandler.report(e, {
|
|
46
|
+
scope: "command",
|
|
47
|
+
source: "console.command.handleSystem",
|
|
48
|
+
command: {
|
|
49
|
+
signature: this.constructor.signature,
|
|
50
|
+
className: this.constructor.name,
|
|
51
|
+
args: this.args,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
45
54
|
}
|
|
46
55
|
finally {
|
|
47
56
|
yield this.finallySystem();
|
|
@@ -63,7 +63,7 @@ class QueueStopCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
63
63
|
let promises = [];
|
|
64
64
|
for (let worker of stopping) {
|
|
65
65
|
if (!worker || !worker.worker || !worker.pid)
|
|
66
|
-
|
|
66
|
+
continue;
|
|
67
67
|
promises.push(new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
68
68
|
try {
|
|
69
69
|
yield this.stopWorker(worker.worker, worker.pid);
|
|
@@ -23,6 +23,7 @@ const StringFunctions_1 = require("../Functions/StringFunctions");
|
|
|
23
23
|
const Config_1 = require("../Config");
|
|
24
24
|
const DBConnection_1 = require("../Database/DBConnection");
|
|
25
25
|
const DateFunctions_1 = require("../Functions/DateFunctions");
|
|
26
|
+
const ErrorHandler_1 = require("../ErrorHandling/ErrorHandler");
|
|
26
27
|
class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
27
28
|
constructor() {
|
|
28
29
|
super(...arguments);
|
|
@@ -70,6 +71,18 @@ class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
70
71
|
yield this.run();
|
|
71
72
|
}
|
|
72
73
|
catch (e) {
|
|
74
|
+
yield ErrorHandler_1.ErrorHandler.report(e, {
|
|
75
|
+
scope: "command",
|
|
76
|
+
source: "queue.worker.run",
|
|
77
|
+
command: {
|
|
78
|
+
signature: this.constructor.signature,
|
|
79
|
+
className: this.constructor.name,
|
|
80
|
+
args: this.args,
|
|
81
|
+
},
|
|
82
|
+
metadata: {
|
|
83
|
+
worker: this.workerKey,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
73
86
|
this.error(`Queue run failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
74
87
|
}
|
|
75
88
|
finally {
|
|
@@ -354,7 +367,18 @@ class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
354
367
|
}
|
|
355
368
|
}
|
|
356
369
|
catch (e) {
|
|
357
|
-
|
|
370
|
+
yield ErrorHandler_1.ErrorHandler.report(e, {
|
|
371
|
+
scope: "command",
|
|
372
|
+
source: "queue.worker.automation",
|
|
373
|
+
command: {
|
|
374
|
+
signature: this.constructor.signature,
|
|
375
|
+
className: this.constructor.name,
|
|
376
|
+
args: this.args,
|
|
377
|
+
},
|
|
378
|
+
metadata: {
|
|
379
|
+
worker: this.workerKey,
|
|
380
|
+
},
|
|
381
|
+
});
|
|
358
382
|
}
|
|
359
383
|
});
|
|
360
384
|
}
|
|
@@ -500,6 +524,19 @@ class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
500
524
|
this.log(`Finished Job #${job.number} - ${job.jobclass} - ${(job.executions[0].duration_ms / 1000).toFixed(2)}s`);
|
|
501
525
|
}
|
|
502
526
|
catch (e) {
|
|
527
|
+
yield ErrorHandler_1.ErrorHandler.report(e, {
|
|
528
|
+
scope: "job",
|
|
529
|
+
source: "queue.worker.job.handle",
|
|
530
|
+
job: {
|
|
531
|
+
id: job && job._id ? job._id.toString() : undefined,
|
|
532
|
+
number: job && job.number ? job.number : undefined,
|
|
533
|
+
jobclass: job && job.jobclass ? job.jobclass : undefined,
|
|
534
|
+
worker: this.workerKey,
|
|
535
|
+
},
|
|
536
|
+
metadata: {
|
|
537
|
+
executionKey: executionKey,
|
|
538
|
+
},
|
|
539
|
+
});
|
|
503
540
|
const errorMessage = e instanceof Error ? e.stack || e.message : String(e);
|
|
504
541
|
const endedAt = new Date();
|
|
505
542
|
job.status = "failed";
|
|
@@ -23,6 +23,7 @@ const QueueStopCommand_1 = require("./Commands/QueueStopCommand");
|
|
|
23
23
|
const QueueLogCommand_1 = require("./Commands/QueueLogCommand");
|
|
24
24
|
const QueueWorkerAutorestartCommand_1 = require("./Commands/QueueWorkerAutorestartCommand");
|
|
25
25
|
const info_1 = require("./info");
|
|
26
|
+
const ErrorHandler_1 = require("./ErrorHandling/ErrorHandler");
|
|
26
27
|
class ConsoleApplication {
|
|
27
28
|
constructor() {
|
|
28
29
|
this.systemCommands = [
|
|
@@ -44,6 +45,14 @@ class ConsoleApplication {
|
|
|
44
45
|
Config_1.Config.register(key, options.config[key]);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
48
|
+
if (options && options.errorHandler) {
|
|
49
|
+
if (Array.isArray(options.errorHandler)) {
|
|
50
|
+
ErrorHandler_1.ErrorHandler.setHandlers(options.errorHandler);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
ErrorHandler_1.ErrorHandler.setHandler(options.errorHandler);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
47
56
|
// if (options && options.signoz) {
|
|
48
57
|
// void SigNozTelemetry.init(options.signoz);
|
|
49
58
|
// }
|
|
@@ -62,10 +71,23 @@ class ConsoleApplication {
|
|
|
62
71
|
return;
|
|
63
72
|
}
|
|
64
73
|
(() => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
try {
|
|
75
|
+
const commandInstance = new command(args);
|
|
76
|
+
yield commandInstance.handleSystem();
|
|
77
|
+
if (options && options.onEnd) {
|
|
78
|
+
yield options.onEnd(command.signature);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
yield ErrorHandler_1.ErrorHandler.report(e, {
|
|
83
|
+
scope: "command",
|
|
84
|
+
source: "console.application.boot",
|
|
85
|
+
command: {
|
|
86
|
+
signature: command.signature,
|
|
87
|
+
className: command.name,
|
|
88
|
+
args: args,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
69
91
|
}
|
|
70
92
|
}))();
|
|
71
93
|
}
|
|
@@ -220,6 +220,15 @@ class DataBuilder {
|
|
|
220
220
|
else if (type.forms[form].fields) {
|
|
221
221
|
newData.forms[form].fields = JSON.parse(JSON.stringify(type.forms[form].fields));
|
|
222
222
|
}
|
|
223
|
+
if (typeof newData.forms[form].pageActions === "function") {
|
|
224
|
+
newData.forms[form].pageActions = yield newData.forms[form].pageActions(req);
|
|
225
|
+
}
|
|
226
|
+
if (typeof newData.forms[form].fields === "function") {
|
|
227
|
+
newData.forms[form].fields = yield newData.forms[form].fields(req);
|
|
228
|
+
}
|
|
229
|
+
if (typeof newData.forms[form].backLink === "function") {
|
|
230
|
+
newData.forms[form].backLink = yield newData.forms[form].backLink(req);
|
|
231
|
+
}
|
|
223
232
|
if (!newData.forms[form].fields || newData.forms[form].fields.length < 1) {
|
|
224
233
|
continue;
|
|
225
234
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type WebframezErrorScope = "controller" | "command" | "job";
|
|
2
|
+
export type WebframezErrorContext = {
|
|
3
|
+
scope: WebframezErrorScope;
|
|
4
|
+
source?: string;
|
|
5
|
+
metadata?: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
command?: {
|
|
9
|
+
signature?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
args?: {
|
|
12
|
+
arguments: string[];
|
|
13
|
+
options: {
|
|
14
|
+
[key: string]: boolean | string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
controller?: {
|
|
19
|
+
routePath?: string;
|
|
20
|
+
method?: string;
|
|
21
|
+
url?: string;
|
|
22
|
+
};
|
|
23
|
+
job?: {
|
|
24
|
+
id?: string;
|
|
25
|
+
number?: number;
|
|
26
|
+
jobclass?: string;
|
|
27
|
+
worker?: string | null;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export type WebframezErrorEvent = WebframezErrorContext & {
|
|
31
|
+
timestamp: Date;
|
|
32
|
+
error: Error;
|
|
33
|
+
originalError: any;
|
|
34
|
+
};
|
|
35
|
+
export type WebframezGlobalErrorHandler = (event: WebframezErrorEvent) => void | Promise<void>;
|
|
36
|
+
declare class ErrorHandlerFacade {
|
|
37
|
+
private handlers;
|
|
38
|
+
private normalizeToError;
|
|
39
|
+
setHandler(handler: WebframezGlobalErrorHandler | null | undefined): this;
|
|
40
|
+
setHandlers(handlers: WebframezGlobalErrorHandler[] | null | undefined): this;
|
|
41
|
+
addHandler(handler: WebframezGlobalErrorHandler | null | undefined): this;
|
|
42
|
+
clearHandlers(): this;
|
|
43
|
+
report(error: any, context: WebframezErrorContext): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export declare const ErrorHandler: ErrorHandlerFacade;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ErrorHandler = void 0;
|
|
13
|
+
class ErrorHandlerFacade {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.handlers = [];
|
|
16
|
+
}
|
|
17
|
+
normalizeToError(error) {
|
|
18
|
+
if (error instanceof Error) {
|
|
19
|
+
return error;
|
|
20
|
+
}
|
|
21
|
+
if (typeof error === "string") {
|
|
22
|
+
return new Error(error);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return new Error(JSON.stringify(error));
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
return new Error(String(error));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
setHandler(handler) {
|
|
32
|
+
this.handlers = [];
|
|
33
|
+
if (handler && typeof handler === "function") {
|
|
34
|
+
this.handlers.push(handler);
|
|
35
|
+
}
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
setHandlers(handlers) {
|
|
39
|
+
this.handlers = [];
|
|
40
|
+
if (handlers && Array.isArray(handlers) && handlers.length > 0) {
|
|
41
|
+
for (const handler of handlers) {
|
|
42
|
+
if (handler && typeof handler === "function") {
|
|
43
|
+
this.handlers.push(handler);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
addHandler(handler) {
|
|
50
|
+
if (handler && typeof handler === "function") {
|
|
51
|
+
this.handlers.push(handler);
|
|
52
|
+
}
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
clearHandlers() {
|
|
56
|
+
this.handlers = [];
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
report(error, context) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const normalizedError = this.normalizeToError(error);
|
|
62
|
+
const event = Object.assign({ timestamp: new Date(), error: normalizedError, originalError: error }, context);
|
|
63
|
+
if (!this.handlers || this.handlers.length < 1) {
|
|
64
|
+
console.error(normalizedError);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
for (const handler of this.handlers) {
|
|
68
|
+
try {
|
|
69
|
+
yield handler(event);
|
|
70
|
+
}
|
|
71
|
+
catch (handlerError) {
|
|
72
|
+
const handlerErrorMessage = this.normalizeToError(handlerError);
|
|
73
|
+
console.error("[webframez:error-handler] Handler failed:", handlerErrorMessage);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.ErrorHandler = new ErrorHandlerFacade();
|
|
@@ -19,11 +19,7 @@ declare class StorageFileInstance {
|
|
|
19
19
|
filepath: string | string[];
|
|
20
20
|
payload?: any;
|
|
21
21
|
}>;
|
|
22
|
-
extension(
|
|
23
|
-
status: string;
|
|
24
|
-
filepath: string | string[];
|
|
25
|
-
payload?: any;
|
|
26
|
-
}>;
|
|
22
|
+
extension(): Promise<string | null>;
|
|
27
23
|
mime(): Promise<string | null>;
|
|
28
24
|
}
|
|
29
25
|
declare class StorageDisk {
|
|
@@ -59,16 +55,8 @@ declare class StorageDisk {
|
|
|
59
55
|
dirpath: string;
|
|
60
56
|
payload?: any;
|
|
61
57
|
}>;
|
|
62
|
-
isDir(filepath: string): Promise<
|
|
63
|
-
|
|
64
|
-
dirpath: string;
|
|
65
|
-
payload?: any;
|
|
66
|
-
}>;
|
|
67
|
-
isFile(filepath: string): Promise<{
|
|
68
|
-
status: string;
|
|
69
|
-
dirpath: string;
|
|
70
|
-
payload?: any;
|
|
71
|
-
}>;
|
|
58
|
+
isDir(filepath: string): Promise<boolean>;
|
|
59
|
+
isFile(filepath: string): Promise<boolean>;
|
|
72
60
|
file(filepath: string): Promise<StorageFileInstance>;
|
|
73
61
|
readDir(dirpath: string, options: StorageReadDirOptions): Promise<any[]>;
|
|
74
62
|
}
|
|
@@ -107,16 +95,8 @@ declare class StorageFacade {
|
|
|
107
95
|
dirpath: string;
|
|
108
96
|
payload?: any;
|
|
109
97
|
}>;
|
|
110
|
-
isDir(filepath: string): Promise<
|
|
111
|
-
|
|
112
|
-
dirpath: string;
|
|
113
|
-
payload?: any;
|
|
114
|
-
}>;
|
|
115
|
-
isFile(filepath: string): Promise<{
|
|
116
|
-
status: string;
|
|
117
|
-
dirpath: string;
|
|
118
|
-
payload?: any;
|
|
119
|
-
}>;
|
|
98
|
+
isDir(filepath: string): Promise<boolean>;
|
|
99
|
+
isFile(filepath: string): Promise<boolean>;
|
|
120
100
|
file(filepath: string): Promise<StorageFileInstance>;
|
|
121
101
|
readDir(dirpath: string, options: StorageReadDirOptions): Promise<any[]>;
|
|
122
102
|
upload(req: any, options: {
|
|
@@ -128,6 +108,7 @@ declare class StorageFacade {
|
|
|
128
108
|
declare class StorageFileFacade {
|
|
129
109
|
storage: StorageFacade;
|
|
130
110
|
constructor(storage: StorageFacade);
|
|
111
|
+
private createFileInstance;
|
|
131
112
|
exists(filepath: string, diskKey?: string): Promise<boolean>;
|
|
132
113
|
isDir(filepath: string, diskKey?: string): Promise<boolean>;
|
|
133
114
|
isFile(filepath: string, diskKey?: string): Promise<boolean>;
|
|
@@ -136,11 +117,7 @@ declare class StorageFileFacade {
|
|
|
136
117
|
filepath: string | string[];
|
|
137
118
|
payload?: any;
|
|
138
119
|
}>;
|
|
139
|
-
extension(filepath: string, diskKey?: string): Promise<
|
|
140
|
-
status: string;
|
|
141
|
-
filepath: string | string[];
|
|
142
|
-
payload?: any;
|
|
143
|
-
}>;
|
|
120
|
+
extension(filepath: string, diskKey?: string): Promise<string | null>;
|
|
144
121
|
mime(filepath: string, diskKey?: string): Promise<string | null>;
|
|
145
122
|
}
|
|
146
123
|
export declare const Storage: StorageFacade;
|
package/dist/Facades/Storage.js
CHANGED
|
@@ -49,9 +49,9 @@ class StorageFileInstance {
|
|
|
49
49
|
return this.driver.delete(this.filepath, options);
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
extension(
|
|
52
|
+
extension() {
|
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
return this.driver.
|
|
54
|
+
return this.driver.extension(this.filepath);
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
mime() {
|
|
@@ -116,14 +116,14 @@ class StorageDisk {
|
|
|
116
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
117
|
if (!this.driver)
|
|
118
118
|
throw new Error(`[STORAGE ERROR] No driver configured for disk '${this.diskKey}'.`);
|
|
119
|
-
return yield this.driver.
|
|
119
|
+
return yield this.driver.isDir(filepath);
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
isFile(filepath) {
|
|
123
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
124
|
if (!this.driver)
|
|
125
125
|
throw new Error(`[STORAGE ERROR] No driver configured for disk '${this.diskKey}'.`);
|
|
126
|
-
return yield this.driver.
|
|
126
|
+
return yield this.driver.isFile(filepath);
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
file(filepath) {
|
|
@@ -209,34 +209,38 @@ class StorageFileFacade {
|
|
|
209
209
|
constructor(storage) {
|
|
210
210
|
this.storage = storage;
|
|
211
211
|
}
|
|
212
|
+
createFileInstance(filepath, diskKey) {
|
|
213
|
+
const disk = this.storage.disk(diskKey);
|
|
214
|
+
return new StorageFileInstance(filepath, disk.driver);
|
|
215
|
+
}
|
|
212
216
|
exists(filepath, diskKey) {
|
|
213
217
|
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
-
return
|
|
218
|
+
return this.createFileInstance(filepath, diskKey).exists();
|
|
215
219
|
});
|
|
216
220
|
}
|
|
217
221
|
isDir(filepath, diskKey) {
|
|
218
222
|
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
-
return
|
|
223
|
+
return this.createFileInstance(filepath, diskKey).isDir();
|
|
220
224
|
});
|
|
221
225
|
}
|
|
222
226
|
isFile(filepath, diskKey) {
|
|
223
227
|
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
-
return
|
|
228
|
+
return this.createFileInstance(filepath, diskKey).isFile();
|
|
225
229
|
});
|
|
226
230
|
}
|
|
227
231
|
delete(filepath, options, diskKey) {
|
|
228
232
|
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
-
return
|
|
233
|
+
return this.createFileInstance(filepath, diskKey).delete(options);
|
|
230
234
|
});
|
|
231
235
|
}
|
|
232
236
|
extension(filepath, diskKey) {
|
|
233
237
|
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
-
return
|
|
238
|
+
return this.createFileInstance(filepath, diskKey).extension();
|
|
235
239
|
});
|
|
236
240
|
}
|
|
237
241
|
mime(filepath, diskKey) {
|
|
238
242
|
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
-
return
|
|
243
|
+
return this.createFileInstance(filepath, diskKey).mime();
|
|
240
244
|
});
|
|
241
245
|
}
|
|
242
246
|
}
|
|
@@ -6,6 +6,7 @@ export declare class LocalStorageDriver implements BaseStorageDriver {
|
|
|
6
6
|
basepath: string;
|
|
7
7
|
constructor(conf: any);
|
|
8
8
|
path(...args: string[]): string;
|
|
9
|
+
private resolveHandlers;
|
|
9
10
|
put(filepath: string, contents: string | Buffer, payload?: any): Promise<{
|
|
10
11
|
status: string;
|
|
11
12
|
filepath: string;
|
|
@@ -26,8 +26,26 @@ class LocalStorageDriver {
|
|
|
26
26
|
path(...args) {
|
|
27
27
|
return path_1.default.join(this.basepath, ...args);
|
|
28
28
|
}
|
|
29
|
+
resolveHandlers(entry) {
|
|
30
|
+
if (!entry) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
if (typeof entry === "function") {
|
|
34
|
+
return [entry];
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(entry)) {
|
|
37
|
+
return entry.filter((handler) => typeof handler === "function");
|
|
38
|
+
}
|
|
39
|
+
if (entry.handlers) {
|
|
40
|
+
const handlers = Array.isArray(entry.handlers) ? entry.handlers : Object.values(entry.handlers);
|
|
41
|
+
return handlers.filter((handler) => typeof handler === "function");
|
|
42
|
+
}
|
|
43
|
+
if (typeof entry === "object") {
|
|
44
|
+
return Object.values(entry).filter((handler) => typeof handler === "function");
|
|
45
|
+
}
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
29
48
|
put(filepath, contents, payload) {
|
|
30
|
-
var _a;
|
|
31
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
50
|
const p = this.path(filepath);
|
|
33
51
|
// @ts-ignore
|
|
@@ -43,12 +61,10 @@ class LocalStorageDriver {
|
|
|
43
61
|
}
|
|
44
62
|
return key === mime;
|
|
45
63
|
});
|
|
46
|
-
if (configKey
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
yield handler(p, contents, payload);
|
|
51
|
-
}
|
|
64
|
+
if (configKey) {
|
|
65
|
+
const handlers = this.resolveHandlers(this.config.fileHandlers[configKey]);
|
|
66
|
+
for (const handler of handlers) {
|
|
67
|
+
yield handler(p, contents, payload);
|
|
52
68
|
}
|
|
53
69
|
}
|
|
54
70
|
}
|
|
@@ -164,9 +180,9 @@ class LocalStorageDriver {
|
|
|
164
180
|
}
|
|
165
181
|
let fileOptions = null;
|
|
166
182
|
let filepath = null;
|
|
167
|
-
busboy.on("file", (fieldname, file,
|
|
168
|
-
if (fileOptions === null &&
|
|
169
|
-
fileOptions =
|
|
183
|
+
busboy.on("file", (fieldname, file, opts) => __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
if (fileOptions === null && opts) {
|
|
185
|
+
fileOptions = opts;
|
|
170
186
|
}
|
|
171
187
|
filepath = path_1.default.join(dir, options.storageFilename);
|
|
172
188
|
const writeStream = fs_1.default.createWriteStream(filepath);
|
|
@@ -188,8 +204,9 @@ class LocalStorageDriver {
|
|
|
188
204
|
}
|
|
189
205
|
return key === mime;
|
|
190
206
|
});
|
|
191
|
-
if (configKey
|
|
192
|
-
|
|
207
|
+
if (configKey) {
|
|
208
|
+
const handlers = this.resolveHandlers(this.config.fileHandlers[configKey]);
|
|
209
|
+
for (const handler of handlers) {
|
|
193
210
|
yield handler(filepath, fs_1.default.readFileSync(filepath), options.payload);
|
|
194
211
|
}
|
|
195
212
|
}
|
|
@@ -5,6 +5,7 @@ const Config_1 = require("./Config");
|
|
|
5
5
|
const DatatableRegistry_1 = require("./Datatable/DatatableRegistry");
|
|
6
6
|
const QueueJobsRegisty_1 = require("./Queue/QueueJobsRegisty");
|
|
7
7
|
const Router_1 = require("./Router/Router");
|
|
8
|
+
const ErrorHandler_1 = require("./ErrorHandling/ErrorHandler");
|
|
8
9
|
class LambdaApplication {
|
|
9
10
|
/**
|
|
10
11
|
* Init the routes and handle the request
|
|
@@ -15,6 +16,14 @@ class LambdaApplication {
|
|
|
15
16
|
Config_1.Config.register(key, options.config[key]);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
19
|
+
if (options && options.errorHandler) {
|
|
20
|
+
if (Array.isArray(options.errorHandler)) {
|
|
21
|
+
ErrorHandler_1.ErrorHandler.setHandlers(options.errorHandler);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
ErrorHandler_1.ErrorHandler.setHandler(options.errorHandler);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
18
27
|
Router_1.Router.init({
|
|
19
28
|
mode: "aws-lambda",
|
|
20
29
|
kernel: options && options.kernel ? options.kernel : null,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
declare class QueueJobsRegistyFacade {
|
|
2
2
|
private jobs;
|
|
3
|
+
private registeredByKey;
|
|
4
|
+
private registeredByReference;
|
|
3
5
|
getJobs(): any[];
|
|
6
|
+
private getJobKey;
|
|
7
|
+
private addJob;
|
|
4
8
|
registerJob(data: any): this;
|
|
5
9
|
}
|
|
6
10
|
export declare const QueueJobsRegisty: QueueJobsRegistyFacade;
|
|
@@ -4,18 +4,51 @@ exports.QueueJobsRegisty = void 0;
|
|
|
4
4
|
class QueueJobsRegistyFacade {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.jobs = [];
|
|
7
|
+
this.registeredByKey = {};
|
|
8
|
+
this.registeredByReference = new Set();
|
|
7
9
|
}
|
|
8
10
|
getJobs() {
|
|
9
11
|
return this.jobs;
|
|
10
12
|
}
|
|
13
|
+
getJobKey(job) {
|
|
14
|
+
if (!job) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (typeof job === "function" && job.name && job.name.trim() !== "") {
|
|
18
|
+
return "function:" + job.name.trim();
|
|
19
|
+
}
|
|
20
|
+
if (job.name && typeof job.name === "string" && job.name.trim() !== "") {
|
|
21
|
+
return "name:" + job.name.trim();
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
addJob(job) {
|
|
26
|
+
if (!job) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const key = this.getJobKey(job);
|
|
30
|
+
if (key) {
|
|
31
|
+
if (this.registeredByKey[key]) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.registeredByKey[key] = true;
|
|
35
|
+
this.jobs.push(job);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (this.registeredByReference.has(job)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.registeredByReference.add(job);
|
|
42
|
+
this.jobs.push(job);
|
|
43
|
+
}
|
|
11
44
|
registerJob(data) {
|
|
12
45
|
if (Array.isArray(data)) {
|
|
13
46
|
for (let el of data) {
|
|
14
|
-
this.
|
|
47
|
+
this.addJob(el);
|
|
15
48
|
}
|
|
16
49
|
}
|
|
17
50
|
else {
|
|
18
|
-
this.
|
|
51
|
+
this.addJob(data);
|
|
19
52
|
}
|
|
20
53
|
return this;
|
|
21
54
|
}
|
package/dist/Router/Router.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ type RouteObject = {
|
|
|
12
12
|
};
|
|
13
13
|
params: object;
|
|
14
14
|
};
|
|
15
|
+
type MiddlewareRejectSignal = {
|
|
16
|
+
__middlewareReject: true;
|
|
17
|
+
reason?: any;
|
|
18
|
+
};
|
|
15
19
|
declare class RouterFacade {
|
|
16
20
|
/**
|
|
17
21
|
* Basename
|
|
@@ -25,6 +29,7 @@ declare class RouterFacade {
|
|
|
25
29
|
* Mode
|
|
26
30
|
*/
|
|
27
31
|
mode: any | null;
|
|
32
|
+
maxRequestBodySizeBytes: number | null;
|
|
28
33
|
/**
|
|
29
34
|
* GET Route Store
|
|
30
35
|
*/
|
|
@@ -105,6 +110,10 @@ declare class RouterFacade {
|
|
|
105
110
|
* @returns {Object} - Ein Objekt mit den extrahierten Parametern.
|
|
106
111
|
*/
|
|
107
112
|
extractParams(path: string, match: any): any;
|
|
113
|
+
escapeRegexPart(value: string): string;
|
|
114
|
+
buildRouteRegex(path: string): RegExp;
|
|
115
|
+
createMiddlewareRejectSignal(reason?: any): MiddlewareRejectSignal;
|
|
116
|
+
isMiddlewareRejectSignal(error: any): error is MiddlewareRejectSignal;
|
|
108
117
|
/**
|
|
109
118
|
* Dissolves the matching route based on the request-url and an object of routes
|
|
110
119
|
*
|