milkio 0.4.1 โ†’ 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 ADDED
@@ -0,0 +1,2 @@
1
+ ["general"]
2
+ includes = ["co:bun"]
package/api-test/index.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  import schema from "../../../generated/api-schema";
2
- import { useLogger, type MilkioApp } from "..";
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(`๐Ÿฅ› Milkio Api Testing..\n`);
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
- tests.push(
25
- // @ts-ignore
26
- (async () => {
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
- const clear = setTimeout(() => {
35
- console.error(`------`);
36
- console.error(`โŒ TIMEOUT -- More than ${cs.timeout ?? 8192}ms`);
37
- console.error(` ${cs.name} | Path: src/apps/${path as string}.ts | Case: ${i}`);
38
- console.error(`------`);
39
- throw new Error("");
40
- }, cs.timeout ?? 8192);
41
- await cs.handler({
42
- ...((await apiTestHooks.default.onBefore()) ?? {}),
43
- log: (...args: Array<unknown>) => console.log(...args),
44
- // @ts-ignore
45
- execute: async (options?: any) => app.execute((path as any), options),
46
- executeOther: async (path: any, options?: any) => app.execute((path as any), options),
47
- executeStream: async (options?: any) => app.executeStream((path as any), options),
48
- randParams: () => app.randParams(path as any),
49
- randOtherParams: (path: any) => app.randParams(path),
50
- reject: (message?: string) => {
51
- console.error(`------`);
52
- console.error(`โŒ REJECT -- ${message ?? "Test not satisfied"}`);
53
- console.error(` ${cs.name} | Path: src/apps/${path as string}.ts | Case: ${i} | Time: ${new Date().getTime() - csStartedAt}ms`);
54
- console.error(`------`);
55
- throw new Error("");
56
- },
57
- } as any);
58
- clearTimeout(clear);
59
- console.log(`โœ… DIRECT -- ${cs.name} | Path: src/apps/${path as string}.ts | Case: ${i} | Time: ${new Date().getTime() - csStartedAt}ms`);
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
- console.log(`\nโœ… All tests passed.`);
70
- console.log(`๐Ÿฅ› Milkio Api Testing took ${((endedAt - startedAt) / 1000).toFixed(2)}s\n`);
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 { $ } from "bun";
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
  };
@@ -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.4.1",
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
- "ulidx": "^2.3.0",
15
+ "chalk": "^5.3.0",
16
+ "ejs": "^3.1.9",
16
17
  "typia": "5.5.5",
17
- "ejs": "^3.1.9"
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(`\nError Data: ${JSON.stringify(error)}`);
11
- if (error.stack) logger.error("\nError Stack: ", error.stack);
12
- else logger.error("\nError Stack: ", 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") {