@webtypen/webframez-core 0.1.3 → 0.1.5
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/Commands/ConsoleCommand.d.ts +14 -0
- package/dist/Commands/ConsoleCommand.js +68 -0
- package/dist/Commands/ConsoleProgressBar.d.ts +10 -0
- package/dist/Commands/ConsoleProgressBar.js +46 -0
- package/dist/ConsoleApplication.js +1 -1
- package/dist/Router/Request.d.ts +1 -0
- package/dist/Router/Request.js +1 -0
- package/dist/Router/Router.js +4 -1
- package/package.json +1 -1
- package/src/Commands/ConsoleCommand.ts +71 -0
- package/src/Commands/ConsoleProgressBar.ts +47 -0
- package/src/ConsoleApplication.ts +1 -1
- package/src/Router/Request.ts +1 -0
- package/src/Router/Router.ts +4 -1
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import readline from "readline";
|
|
3
|
+
import { ConsoleProgressBar } from "./ConsoleProgressBar";
|
|
1
4
|
export declare class ConsoleCommand {
|
|
2
5
|
static signature: string;
|
|
3
6
|
static description?: string;
|
|
7
|
+
rl: readline.Interface | null;
|
|
8
|
+
currentProgress: ConsoleProgressBar | null;
|
|
9
|
+
constructor();
|
|
4
10
|
handle(): Promise<void>;
|
|
11
|
+
handleSystem(): Promise<void>;
|
|
12
|
+
finallySystem(): Promise<void>;
|
|
13
|
+
write(message: string): this;
|
|
14
|
+
writeln(message: string): this;
|
|
15
|
+
ask(question: string): Promise<unknown>;
|
|
16
|
+
progress(count: number): this;
|
|
17
|
+
progressIncrement(): this;
|
|
18
|
+
progressFinish(): this;
|
|
5
19
|
}
|
|
@@ -8,11 +8,79 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.ConsoleCommand = void 0;
|
|
16
|
+
const os_1 = __importDefault(require("os"));
|
|
17
|
+
const readline_1 = __importDefault(require("readline"));
|
|
18
|
+
const ConsoleProgressBar_1 = require("./ConsoleProgressBar");
|
|
13
19
|
class ConsoleCommand {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.currentProgress = null;
|
|
22
|
+
this.rl = readline_1.default.createInterface({
|
|
23
|
+
input: process.stdin,
|
|
24
|
+
output: process.stdout,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
14
27
|
handle() {
|
|
15
28
|
return __awaiter(this, void 0, void 0, function* () { });
|
|
16
29
|
}
|
|
30
|
+
handleSystem() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
try {
|
|
33
|
+
yield this.handle();
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.error(e);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
yield this.finallySystem();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
finallySystem() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (this.rl) {
|
|
46
|
+
this.rl.close();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
write(message) {
|
|
51
|
+
process.stdout.write(message);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
writeln(message) {
|
|
55
|
+
process.stdout.write(message + os_1.default.EOL);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
ask(question) {
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
if (this.rl) {
|
|
61
|
+
this.rl.question(question, (answer) => {
|
|
62
|
+
resolve(answer);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
resolve(null);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
progress(count) {
|
|
69
|
+
this.currentProgress = new ConsoleProgressBar_1.ConsoleProgressBar(count);
|
|
70
|
+
this.currentProgress.render();
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
progressIncrement() {
|
|
74
|
+
if (this.currentProgress) {
|
|
75
|
+
this.currentProgress.increment();
|
|
76
|
+
}
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
progressFinish() {
|
|
80
|
+
if (this.currentProgress) {
|
|
81
|
+
this.currentProgress.finish();
|
|
82
|
+
}
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
17
85
|
}
|
|
18
86
|
exports.ConsoleCommand = ConsoleCommand;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ConsoleProgressBar = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
class ConsoleProgressBar {
|
|
9
|
+
constructor(total) {
|
|
10
|
+
this.total = 0;
|
|
11
|
+
this.current = 0;
|
|
12
|
+
this.barLength = 40;
|
|
13
|
+
this.total = total;
|
|
14
|
+
this.current = 0;
|
|
15
|
+
this.barLength = 40; // Länge der Fortschrittsanzeige in Zeichen
|
|
16
|
+
}
|
|
17
|
+
update(current) {
|
|
18
|
+
this.current = current;
|
|
19
|
+
this.render();
|
|
20
|
+
}
|
|
21
|
+
finish() {
|
|
22
|
+
const progressText = "█".repeat(this.barLength);
|
|
23
|
+
process.stdout.clearLine(0);
|
|
24
|
+
process.stdout.cursorTo(0);
|
|
25
|
+
process.stdout.write(`Progress: [${progressText}] | 100%` + os_1.default.EOL);
|
|
26
|
+
}
|
|
27
|
+
render() {
|
|
28
|
+
const percentage = this.current / this.total;
|
|
29
|
+
const progress = Math.round(this.barLength * percentage);
|
|
30
|
+
const emptyProgress = this.barLength - progress;
|
|
31
|
+
const progressText = "█".repeat(progress);
|
|
32
|
+
const emptyProgressText = "░".repeat(emptyProgress);
|
|
33
|
+
const percentageText = (percentage * 100).toFixed(2);
|
|
34
|
+
process.stdout.clearLine(0);
|
|
35
|
+
process.stdout.cursorTo(0);
|
|
36
|
+
process.stdout.write(`Progress: [${progressText}${emptyProgressText}] | ${percentageText}%`);
|
|
37
|
+
}
|
|
38
|
+
increment() {
|
|
39
|
+
this.current += 1;
|
|
40
|
+
if (this.current > this.total) {
|
|
41
|
+
this.current = this.total;
|
|
42
|
+
}
|
|
43
|
+
this.render();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ConsoleProgressBar = ConsoleProgressBar;
|
|
@@ -36,7 +36,7 @@ class ConsoleApplication {
|
|
|
36
36
|
}
|
|
37
37
|
consoleCommand.action(() => __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
const service = yield new command();
|
|
39
|
-
return yield service.
|
|
39
|
+
return yield service.handleSystem();
|
|
40
40
|
}));
|
|
41
41
|
program.addCommand(consoleCommand);
|
|
42
42
|
}
|
package/dist/Router/Request.d.ts
CHANGED
package/dist/Router/Request.js
CHANGED
package/dist/Router/Router.js
CHANGED
|
@@ -285,6 +285,8 @@ class RouterFacade {
|
|
|
285
285
|
else if (req && req instanceof http_1.IncomingMessage) {
|
|
286
286
|
const parsedBody = yield this.parseRequestBody(req);
|
|
287
287
|
const parsedUrl = req.url ? url_1.default.parse(req.url) : null;
|
|
288
|
+
const searchParams = parsedUrl && parsedUrl.query ? new URLSearchParams(parsedUrl.query) : null;
|
|
289
|
+
const queryParams = searchParams ? Object.fromEntries(searchParams.entries()) : {};
|
|
288
290
|
request.message = req;
|
|
289
291
|
request.bodyPlain = parsedBody ? parsedBody.plain : "";
|
|
290
292
|
request.body = parsedBody ? parsedBody.parsed : {};
|
|
@@ -293,7 +295,8 @@ class RouterFacade {
|
|
|
293
295
|
request.url = req.url ? req.url : "";
|
|
294
296
|
request.method = req.method ? req.method : "";
|
|
295
297
|
request.socket = req.socket;
|
|
296
|
-
request.query =
|
|
298
|
+
request.query = queryParams;
|
|
299
|
+
request.queryRaw = parsedUrl && parsedUrl.query ? parsedUrl.query : "";
|
|
297
300
|
request.pathname = parsedUrl ? parsedUrl.pathname : "";
|
|
298
301
|
}
|
|
299
302
|
return request;
|
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import readline from "readline";
|
|
3
|
+
import { ConsoleProgressBar } from "./ConsoleProgressBar";
|
|
4
|
+
|
|
1
5
|
export class ConsoleCommand {
|
|
2
6
|
static signature: string;
|
|
3
7
|
static description?: string;
|
|
4
8
|
|
|
9
|
+
rl: readline.Interface | null;
|
|
10
|
+
currentProgress: ConsoleProgressBar | null = null;
|
|
11
|
+
|
|
12
|
+
constructor() {
|
|
13
|
+
this.rl = readline.createInterface({
|
|
14
|
+
input: process.stdin,
|
|
15
|
+
output: process.stdout,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
5
19
|
async handle() {}
|
|
20
|
+
|
|
21
|
+
async handleSystem() {
|
|
22
|
+
try {
|
|
23
|
+
await this.handle();
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.error(e);
|
|
26
|
+
} finally {
|
|
27
|
+
await this.finallySystem();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async finallySystem() {
|
|
32
|
+
if (this.rl) {
|
|
33
|
+
this.rl.close();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
write(message: string) {
|
|
38
|
+
process.stdout.write(message);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
writeln(message: string) {
|
|
43
|
+
process.stdout.write(message + os.EOL);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ask(question: string) {
|
|
48
|
+
return new Promise((resolve) => {
|
|
49
|
+
if (this.rl) {
|
|
50
|
+
this.rl.question(question, (answer) => {
|
|
51
|
+
resolve(answer);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
resolve(null);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
progress(count: number) {
|
|
59
|
+
this.currentProgress = new ConsoleProgressBar(count);
|
|
60
|
+
this.currentProgress.render();
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
progressIncrement() {
|
|
65
|
+
if (this.currentProgress) {
|
|
66
|
+
this.currentProgress.increment();
|
|
67
|
+
}
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
progressFinish() {
|
|
72
|
+
if (this.currentProgress) {
|
|
73
|
+
this.currentProgress.finish();
|
|
74
|
+
}
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
6
77
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
|
|
3
|
+
export class ConsoleProgressBar {
|
|
4
|
+
total: number = 0;
|
|
5
|
+
current: number = 0;
|
|
6
|
+
barLength: number = 40;
|
|
7
|
+
|
|
8
|
+
constructor(total: number) {
|
|
9
|
+
this.total = total;
|
|
10
|
+
this.current = 0;
|
|
11
|
+
this.barLength = 40; // Länge der Fortschrittsanzeige in Zeichen
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
update(current: number) {
|
|
15
|
+
this.current = current;
|
|
16
|
+
this.render();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
finish() {
|
|
20
|
+
const progressText = "█".repeat(this.barLength);
|
|
21
|
+
process.stdout.clearLine(0);
|
|
22
|
+
process.stdout.cursorTo(0);
|
|
23
|
+
process.stdout.write(`Progress: [${progressText}] | 100%` + os.EOL);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
render() {
|
|
27
|
+
const percentage = this.current / this.total;
|
|
28
|
+
const progress = Math.round(this.barLength * percentage);
|
|
29
|
+
const emptyProgress = this.barLength - progress;
|
|
30
|
+
|
|
31
|
+
const progressText = "█".repeat(progress);
|
|
32
|
+
const emptyProgressText = "░".repeat(emptyProgress);
|
|
33
|
+
const percentageText = (percentage * 100).toFixed(2);
|
|
34
|
+
|
|
35
|
+
process.stdout.clearLine(0);
|
|
36
|
+
process.stdout.cursorTo(0);
|
|
37
|
+
process.stdout.write(`Progress: [${progressText}${emptyProgressText}] | ${percentageText}%`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
increment() {
|
|
41
|
+
this.current += 1;
|
|
42
|
+
if (this.current > this.total) {
|
|
43
|
+
this.current = this.total;
|
|
44
|
+
}
|
|
45
|
+
this.render();
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/Router/Request.ts
CHANGED
package/src/Router/Router.ts
CHANGED
|
@@ -322,6 +322,8 @@ class RouterFacade {
|
|
|
322
322
|
} else if (req && req instanceof IncomingMessage) {
|
|
323
323
|
const parsedBody: any = await this.parseRequestBody(req);
|
|
324
324
|
const parsedUrl = req.url ? url.parse(req.url) : null;
|
|
325
|
+
const searchParams = parsedUrl && parsedUrl.query ? new URLSearchParams(parsedUrl.query) : null;
|
|
326
|
+
const queryParams = searchParams ? Object.fromEntries(searchParams.entries()) : {};
|
|
325
327
|
|
|
326
328
|
request.message = req;
|
|
327
329
|
request.bodyPlain = parsedBody ? parsedBody.plain : "";
|
|
@@ -331,7 +333,8 @@ class RouterFacade {
|
|
|
331
333
|
request.url = req.url ? req.url : "";
|
|
332
334
|
request.method = req.method ? req.method : "";
|
|
333
335
|
request.socket = req.socket;
|
|
334
|
-
request.query =
|
|
336
|
+
request.query = queryParams;
|
|
337
|
+
request.queryRaw = parsedUrl && parsedUrl.query ? parsedUrl.query : "";
|
|
335
338
|
request.pathname = parsedUrl ? parsedUrl.pathname : "";
|
|
336
339
|
}
|
|
337
340
|
return request;
|