milkio 0.4.2 โ 0.5.0
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/.co.toml +2 -0
- package/api-test/index.ts +52 -47
- package/c.ts +5 -5
- package/defines/define-http-handler.ts +0 -7
- package/kernel/validate.ts +3 -0
- package/package.json +5 -3
- package/utils/handle-catch-error.ts +3 -3
package/.co.toml
ADDED
package/api-test/index.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import schema from "../../../generated/api-schema";
|
|
2
|
-
import {
|
|
2
|
+
import { ExecuteResultFail, type MilkioApp } from "..";
|
|
3
|
+
import { cwd } from "node:process";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import { handleCatchError } from "../utils/handle-catch-error.ts";
|
|
3
6
|
|
|
4
7
|
export const executeApiTests = async <Path extends Array<keyof (typeof schema)["apiTestsSchema"]>>(app: MilkioApp, path: Path | string | true | 1 | undefined) => {
|
|
5
|
-
console.log(
|
|
8
|
+
console.log(`${chalk.hex("#81C7D4")(`๐ง test running on`)} ${chalk.hex("#999A9E").underline(cwd())}`);
|
|
6
9
|
|
|
7
10
|
let pathArr = [] as Array<string>;
|
|
8
11
|
if (!path || path === "1" || path === 1 || path === true) {
|
|
@@ -11,61 +14,63 @@ export const executeApiTests = async <Path extends Array<keyof (typeof schema)["
|
|
|
11
14
|
pathArr = [path] as Path;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
const tests = [];
|
|
15
17
|
const startedAt = new Date().getTime();
|
|
16
|
-
|
|
17
18
|
const apiTestHooks = await import("../../../src/api-test.ts");
|
|
18
19
|
await apiTestHooks.default.onBootstrap();
|
|
20
|
+
const results: Array<{ path: string, case: number, fail: boolean, failMessage?: string }> = [];
|
|
21
|
+
console.log(chalk.hex("#0B346E")(`โโโโโโโโ`));
|
|
19
22
|
|
|
20
23
|
for (const pathRaw of pathArr) {
|
|
21
24
|
let path = pathRaw.replaceAll("\\", "/");
|
|
22
25
|
if (path.startsWith("/")) path = path.slice(1) as Path[number];
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
const module = await schema.apiTestsSchema[path]().module;
|
|
29
|
+
const cases = module.test.getCases();
|
|
30
|
+
let i = 0;
|
|
31
|
+
for (const cs of cases) {
|
|
32
|
+
++i;
|
|
33
|
+
const csStartedAt = new Date().getTime();
|
|
34
|
+
let fail = false;
|
|
35
|
+
let failMessage: string | undefined = undefined;
|
|
36
|
+
try {
|
|
37
|
+
await cs.handler({
|
|
38
|
+
...((await apiTestHooks.default.onBefore()) ?? {}),
|
|
39
|
+
log: (...args: Array<unknown>) => console.log(...args),
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
execute: async (options?: any) => app.execute((path as any), options),
|
|
42
|
+
executeOther: async (path: any, options?: any) => app.execute((path as any), options),
|
|
43
|
+
executeStream: async (options?: any) => app.executeStream((path as any), options),
|
|
44
|
+
randParams: () => app.randParams(path as any),
|
|
45
|
+
randOtherParams: (path: any) => app.randParams(path),
|
|
46
|
+
reject: (message?: string) => {
|
|
47
|
+
fail = true;
|
|
48
|
+
failMessage = message;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
} catch (e: any) {
|
|
52
|
+
const response = handleCatchError(e, 'no-execute-id') as ExecuteResultFail;
|
|
53
|
+
fail = true;
|
|
54
|
+
failMessage = response.fail.message;
|
|
55
|
+
}
|
|
56
|
+
if (fail) {
|
|
57
|
+
console.log(`${chalk.hex("#D75455")(`\nrejected`)}${chalk.hex("#999A9E")(` ยท ${cs.name} | path: src/apps/${path as string}.ts | case: ${i} | time: ${new Date().getTime() - csStartedAt}ms`)}`);
|
|
58
|
+
console.log(chalk.hex("#999A9E")(failMessage ?? "Test not satisfied"));
|
|
59
|
+
} else {
|
|
60
|
+
console.log(`${chalk.hex("#1B813E")(`directed`)}${chalk.hex("#999A9E")(` ยท ${cs.name} | path: src/apps/${path as string}.ts | case: ${i} | time: ${new Date().getTime() - csStartedAt}ms`)}`);
|
|
61
|
+
}
|
|
62
|
+
results.push({ path, case: i, fail, failMessage });
|
|
63
|
+
console.log(chalk.hex("#0B346E")(`โโโโโโโโ`));
|
|
64
|
+
await new Promise(resolve => setTimeout(resolve, 64));
|
|
65
|
+
}
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
await Promise.all(tests);
|
|
66
|
-
|
|
67
68
|
const endedAt = new Date().getTime();
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const failTotal = results.filter(r => r.fail).length;
|
|
71
|
+
const passTotal = results.length - failTotal;
|
|
72
|
+
|
|
73
|
+
console.log("");
|
|
74
|
+
if (failTotal === 0) console.log(chalk.hex("#1B813E")(`๐ฅณ all tests ${chalk.hex("#1B813E")(`passed`)} ${chalk.hex("#999A9E")(`๐ milkio testing took ${((endedAt - startedAt) / 1000).toFixed(2)}s\n`)}`));
|
|
75
|
+
else console.log(chalk.hex("#999A9E")(`๐ค๏ธ๏ธ ${failTotal} test${failTotal > 1 ? "s" : ""} ${chalk.hex("#D75455")(`failed`)}${passTotal > 0 ? `, and ${results.length - failTotal} ${chalk.hex("#1B813E")(`passed`)}` : ''} ${chalk.hex("#999A9E")(`๐ milkio testing took ${((endedAt - startedAt) / 1000).toFixed(2)}s`)}`));
|
|
71
76
|
};
|
package/c.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
3
|
import { argv, exit } from "node:process";
|
|
4
|
-
import {
|
|
4
|
+
import { $, env } from "bun";
|
|
5
5
|
|
|
6
6
|
const method = argv[2] as keyof typeof commands;
|
|
7
7
|
const params = argv.slice(3) as Parameters<(typeof commands)[keyof typeof commands]>;
|
|
@@ -26,14 +26,14 @@ const commands = {
|
|
|
26
26
|
async EAR(commandBase64ed: string) {
|
|
27
27
|
try {
|
|
28
28
|
console.clear();
|
|
29
|
-
} catch (e) {}
|
|
29
|
+
} catch (e) { }
|
|
30
30
|
const command = Buffer.from(commandBase64ed, "base64").toString("utf-8");
|
|
31
31
|
console.log("\x1B[2m%s\x1B[0m", `$ ${command}`);
|
|
32
32
|
console.log(``);
|
|
33
33
|
try {
|
|
34
|
-
await $`${{ raw: command }}
|
|
35
|
-
} catch (e) {}
|
|
36
|
-
process.on("SIGINT", () => {}); // prevent users from exiting by pressing ctrl + c
|
|
34
|
+
await $`${{ raw: command }}`.env({ ...env, FORCE_COLOR: "3" });
|
|
35
|
+
} catch (e) { }
|
|
36
|
+
process.on("SIGINT", () => { }); // prevent users from exiting by pressing ctrl + c
|
|
37
37
|
while (true) await new Promise((resolve) => process.stdin.on("keypress", resolve));
|
|
38
38
|
},
|
|
39
39
|
};
|
|
@@ -148,13 +148,6 @@ export function defineHttpHandler(app: MilkioApp, options: ExecuteHttpServerOpti
|
|
|
148
148
|
|
|
149
149
|
const resultsRaw = await app._call(mode, pathstr, params, headers, { executeId, logger, detail });
|
|
150
150
|
|
|
151
|
-
if (resultsRaw.$result.success === false) {
|
|
152
|
-
if (resultsRaw.$result.fail.code === "TYPE_SAFE_ERROR") {
|
|
153
|
-
if (((resultsRaw.$result.fail.data as any).value) === undefined) (resultsRaw.$result.fail.data as any).value === "undefined";
|
|
154
|
-
if (((resultsRaw.$result.fail.data as any).value) === null) (resultsRaw.$result.fail.data as any).value === "null";
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
151
|
let fn: any;
|
|
159
152
|
try {
|
|
160
153
|
fn = await schema.apiValidator.validate[pathstr]();
|
package/kernel/validate.ts
CHANGED
|
@@ -5,6 +5,9 @@ export function _validate(validator: IValidation.IFailure | IValidation.ISuccess
|
|
|
5
5
|
if (validator.success) return validator.data;
|
|
6
6
|
const error = validator.errors[0];
|
|
7
7
|
|
|
8
|
+
if ((error.value) === undefined) error.value === "undefined";
|
|
9
|
+
if ((error.value) === null) error.value === "null";
|
|
10
|
+
|
|
8
11
|
throw reject("TYPE_SAFE_ERROR", {
|
|
9
12
|
path: error.path,
|
|
10
13
|
expected: error.expected,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "milkio",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"module": "index.ts",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.5.0",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"typescript": "^5.4.2"
|
|
8
8
|
},
|
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@poech/camel-hump-under": "^1.1.0",
|
|
14
14
|
"@southern-aurora/tson": "2.0.2",
|
|
15
|
-
"
|
|
15
|
+
"chalk": "^5.3.0",
|
|
16
|
+
"ejs": "^3.1.9",
|
|
16
17
|
"typia": "5.5.5",
|
|
17
|
-
"
|
|
18
|
+
"ulidx": "^2.3.0"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@types/bun": "latest",
|
|
22
|
+
"@types/node": "latest",
|
|
21
23
|
"@types/ejs": "^3.1.5",
|
|
22
24
|
"@types/js-beautify": "^1.14.3",
|
|
23
25
|
"ts-patch": "^3.1.2",
|
|
@@ -7,9 +7,9 @@ export function handleCatchError(error: any, executeId: ExecuteId): ExecuteResul
|
|
|
7
7
|
const logger = useLogger(executeId);
|
|
8
8
|
|
|
9
9
|
if (configMilkio.debug === true) {
|
|
10
|
-
logger.error(
|
|
11
|
-
if (error.stack) logger.error("
|
|
12
|
-
else logger.error("
|
|
10
|
+
logger.error(`Error Data: ${JSON.stringify(error)}`);
|
|
11
|
+
if (error.stack) logger.error("Error Stack: ", error.stack);
|
|
12
|
+
else logger.error("Error Stack: ", error);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if (error.name !== "MilkioReject") {
|