milkio 0.0.1 ā 0.0.2
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/c.ts +10 -10
- package/defines/define-api-test-handler.ts +4 -4
- package/defines/define-http-handler.ts +6 -6
- package/index.ts +2 -2
- package/kernel/config.ts +2 -2
- package/kernel/context.ts +2 -2
- package/kernel/fail.ts +3 -3
- package/kernel/middleware.ts +2 -2
- package/kernel/{loongbao.ts ā milkio.ts} +21 -20
- package/package.json +1 -1
- package/scripts/build-dto.ts +2 -2
- package/scripts/generate/generate-app-partial.ts +1 -1
- package/scripts/generate/generate-app.ts +2 -2
- package/scripts/generate-database.ts +2 -2
- package/scripts/generate-partial.ts +2 -2
- package/scripts/generate.ts +2 -2
- package/templates/api.ts +1 -1
- package/types.ts +3 -3
- package/utils/handle-catch-error.ts +2 -2
package/c.ts
CHANGED
|
@@ -14,18 +14,18 @@ const params = argv.slice(3) as Parameters<(typeof commands)[keyof typeof comman
|
|
|
14
14
|
|
|
15
15
|
const commands = {
|
|
16
16
|
async gen() {
|
|
17
|
-
await exec(rootPath, ["bun", "./node_modules/
|
|
17
|
+
await exec(rootPath, ["bun", "./node_modules/milkio/scripts/generate.ts"]);
|
|
18
18
|
},
|
|
19
19
|
async "gen:database"() {
|
|
20
|
-
await exec(rootPath, ["bun", "./node_modules/
|
|
20
|
+
await exec(rootPath, ["bun", "./node_modules/milkio/scripts/generate-database.ts"]);
|
|
21
21
|
},
|
|
22
22
|
async "build:cookbook"() {
|
|
23
|
-
await exec(rootPath, ["bun", "./node_modules/
|
|
23
|
+
await exec(rootPath, ["bun", "./node_modules/milkio/scripts/build-cookbook.ts"]);
|
|
24
24
|
},
|
|
25
25
|
async "build:dto"() {
|
|
26
26
|
await exec(join(rootPath, "packages", "dto"), ["bun", "i"]);
|
|
27
|
-
await exec(rootPath, ["bun", "./node_modules/
|
|
28
|
-
await exec(rootPath, ["bun", "./node_modules/
|
|
27
|
+
await exec(rootPath, ["bun", "./node_modules/milkio/scripts/generate.ts"]);
|
|
28
|
+
await exec(rootPath, ["bun", "./node_modules/milkio/scripts/build-dto.ts"]);
|
|
29
29
|
},
|
|
30
30
|
async test(files?: string, reserved?: string) {
|
|
31
31
|
const run = async () => {
|
|
@@ -34,19 +34,19 @@ const commands = {
|
|
|
34
34
|
// Therefore, temporarily switch to another implementation.
|
|
35
35
|
// await $`${{ raw: packageJson.scripts.start }}`.env({
|
|
36
36
|
// ...env,
|
|
37
|
-
//
|
|
38
|
-
//
|
|
37
|
+
// milkio_RUN_MODE: "API_TEST",
|
|
38
|
+
// milkio_TEST: files ?? "1"
|
|
39
39
|
// });
|
|
40
40
|
//
|
|
41
41
|
await exec(rootPath, ["bash", "-c", packageJson.scripts.start as string], {
|
|
42
42
|
env: {
|
|
43
43
|
...env,
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
milkio_RUN_MODE: "API_TEST",
|
|
45
|
+
milkio_TEST: files ?? "1"
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
|
-
if (!env.
|
|
49
|
+
if (!env.milkio_TEST_RESERVED && reserved !== "1") {
|
|
50
50
|
// Normal test
|
|
51
51
|
await run();
|
|
52
52
|
} else {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-argument, no-console, @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { exit } from "node:process";
|
|
3
3
|
import schema from "../../../generate/api-schema";
|
|
4
|
-
import { type
|
|
4
|
+
import { type milkioApp } from "..";
|
|
5
5
|
|
|
6
|
-
export const defineApiTestHandler = async <Paths extends Array<keyof (typeof schema)["apiTestsSchema"]>>(app:
|
|
7
|
-
console.log(`š§
|
|
6
|
+
export const defineApiTestHandler = async <Paths extends Array<keyof (typeof schema)["apiTestsSchema"]>>(app: milkioApp, paths: Paths | string | 1 | undefined) => {
|
|
7
|
+
console.log(`š§ Milkio Api Testing..\n`);
|
|
8
8
|
|
|
9
9
|
if (!paths) {
|
|
10
10
|
console.log("š§ No paths specified.");
|
|
@@ -65,6 +65,6 @@ export const defineApiTestHandler = async <Paths extends Array<keyof (typeof sch
|
|
|
65
65
|
const endedAt = new Date().getTime();
|
|
66
66
|
|
|
67
67
|
console.log(`\nā
All tests passed.`);
|
|
68
|
-
console.log(`š§
|
|
68
|
+
console.log(`š§ Milkio Api Testing took ${((endedAt - startedAt) / 1000).toFixed(2)}s\n`);
|
|
69
69
|
exit(0);
|
|
70
70
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { configFramework, loggerPushTags, loggerSubmit, useLogger, loggerSubmitAll, runtime, MiddlewareEvent } from "..";
|
|
3
|
-
import type { ExecuteId,
|
|
3
|
+
import type { ExecuteId, milkioApp, Mixin } from "..";
|
|
4
4
|
import { hanldeCatchError } from "../utils/handle-catch-error";
|
|
5
5
|
import { routerHandler } from "../../../src/router";
|
|
6
6
|
import schema from "../../../generate/api-schema";
|
|
@@ -20,7 +20,7 @@ export type ExecuteHttpServerOptions = {
|
|
|
20
20
|
executeIdGenerator?: (request: Request) => string | Promise<string>;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export function defineHttpHandler(app:
|
|
23
|
+
export function defineHttpHandler(app: milkioApp, options: ExecuteHttpServerOptions = {}) {
|
|
24
24
|
// If an unexpected error occurs, exit the process.
|
|
25
25
|
// For modern production environments such as Serverless, Kubernetes, or Docker Compose:
|
|
26
26
|
// The process will automatically restart after exiting.
|
|
@@ -33,7 +33,7 @@ export function defineHttpHandler(app: LoongbaoApp, options: ExecuteHttpServerOp
|
|
|
33
33
|
exit(1);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
const fetch = async (request:
|
|
36
|
+
const fetch = async (request: milkioHTTPRequest) => {
|
|
37
37
|
const fullurl = new URL(request.request.url, `http://${request.request.headers.get("host") ?? "localhost"}`);
|
|
38
38
|
const executeId = (options?.executeIdGenerator ? await options.executeIdGenerator(request.request) : createUlid()) as ExecuteId;
|
|
39
39
|
runtime.execute.executeIds.add(executeId);
|
|
@@ -50,7 +50,7 @@ export function defineHttpHandler(app: LoongbaoApp, options: ExecuteHttpServerOp
|
|
|
50
50
|
timein: new Date().getTime()
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
const response:
|
|
53
|
+
const response: milkioHTTPResponse = {
|
|
54
54
|
body: "",
|
|
55
55
|
status: 200,
|
|
56
56
|
headers: {
|
|
@@ -188,11 +188,11 @@ export function defineHttpHandler(app: LoongbaoApp, options: ExecuteHttpServerOp
|
|
|
188
188
|
return fetch;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
export type
|
|
191
|
+
export type milkioHTTPRequest = {
|
|
192
192
|
request: Request;
|
|
193
193
|
};
|
|
194
194
|
|
|
195
|
-
export type
|
|
195
|
+
export type milkioHTTPResponse = Mixin<
|
|
196
196
|
ResponseInit,
|
|
197
197
|
{
|
|
198
198
|
//
|
package/index.ts
CHANGED
package/kernel/config.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { envToBoolean, envToNumber, envToString } from "..";
|
|
|
4
4
|
export const configFramework = {
|
|
5
5
|
cwd: cwd(),
|
|
6
6
|
port: envToNumber(env.PORT, 9000),
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
milkioRunMode: envToString(env.milkio_RUN_MODE, "DEFAULT"),
|
|
8
|
+
milkioTest: envToString(env.milkio_TEST, ""),
|
|
9
9
|
debug: envToBoolean(env.DEBUG, false),
|
|
10
10
|
redisUrl: envToString(env.REDIS_URL, "redis://:123456@your-not-redis-url:6379"),
|
|
11
11
|
ignorePathLevel: envToNumber(env.IGNORE_PATH_LEVEL, 0),
|
package/kernel/context.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { URL } from "node:url";
|
|
2
|
-
import type { ExecuteId, Logger,
|
|
2
|
+
import type { ExecuteId, Logger, milkioHTTPResponse } from "..";
|
|
3
3
|
|
|
4
4
|
export type FrameworkContext = {
|
|
5
5
|
path: string;
|
|
@@ -20,5 +20,5 @@ export type FrameworkHTTPDetail = {
|
|
|
20
20
|
fullurl: URL;
|
|
21
21
|
ip: string;
|
|
22
22
|
request: Request;
|
|
23
|
-
response:
|
|
23
|
+
response: milkioHTTPResponse;
|
|
24
24
|
};
|
package/kernel/fail.ts
CHANGED
|
@@ -4,7 +4,7 @@ export function reject<Code extends keyof typeof failCode, FailData extends (typ
|
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
|
|
5
5
|
const message = failCode[code]?.(data as any) ?? "";
|
|
6
6
|
const error = {
|
|
7
|
-
name: "
|
|
7
|
+
name: "milkioReject",
|
|
8
8
|
code,
|
|
9
9
|
message,
|
|
10
10
|
data,
|
|
@@ -16,7 +16,7 @@ export function reject<Code extends keyof typeof failCode, FailData extends (typ
|
|
|
16
16
|
return error;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export type
|
|
19
|
+
export type milkioReject = ReturnType<typeof reject>;
|
|
20
20
|
|
|
21
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
export type
|
|
22
|
+
export type milkioFailCode = Record<string, (arg: any) => string>;
|
package/kernel/middleware.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import type { Context } from "../../../src/context";
|
|
4
4
|
import type { FrameworkHTTPDetail } from "./context";
|
|
5
|
-
import { type
|
|
5
|
+
import { type milkioApp } from "milkio";
|
|
6
6
|
|
|
7
|
-
export type BootstrapMiddleware = (
|
|
7
|
+
export type BootstrapMiddleware = (milkio: milkioApp) => Promise<void> | void;
|
|
8
8
|
export type BeforeExecuteMiddleware = (context: Context) => Promise<void> | void;
|
|
9
9
|
export type AfterExecuteMiddleware = (context: Context, response: { value: unknown }) => Promise<void> | void;
|
|
10
10
|
export type AfterHTTPRequestMiddleware = (headers: Headers, detail: FrameworkHTTPDetail) => Promise<void> | void;
|
|
@@ -10,17 +10,17 @@ import { _validate } from "./validate";
|
|
|
10
10
|
import { cwd, exit } from "node:process";
|
|
11
11
|
import { createUlid } from "../utils/create-ulid";
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type milkioAppOptions = {
|
|
14
14
|
/**
|
|
15
15
|
* bootstraps
|
|
16
16
|
* @description
|
|
17
|
-
* When
|
|
17
|
+
* When Milkio is launched, all methods in this array will run **in parallel**.
|
|
18
18
|
*/
|
|
19
19
|
bootstraps?: () => Array</* This type is long, and its intention is to prevent someone from forgetting to add parentheses when adding bootstraps. Therefore, it allows all types except methods */ Promise<unknown> | void | string | number | boolean | null | undefined | Record<string | number | symbol, unknown> | Array<unknown>>;
|
|
20
20
|
/**
|
|
21
21
|
* middlewares
|
|
22
22
|
* @description
|
|
23
|
-
* When
|
|
23
|
+
* When Milkio is launched, the closer it is to the front of the array, the more it is on the outer layer of the "onion".
|
|
24
24
|
*/
|
|
25
25
|
middlewares?: () => Array<MiddlewareOptions>;
|
|
26
26
|
/**
|
|
@@ -34,44 +34,44 @@ export type LoongbaoAppOptions = {
|
|
|
34
34
|
* maxRunningTime (minutes)
|
|
35
35
|
* @description
|
|
36
36
|
* When the function runs for a long time, it is possible that the memory will continuously expand (not necessarily due to memory leaks, but also possibly due to having a large number of routes).
|
|
37
|
-
* Set the maximum running time (in minutes). When
|
|
37
|
+
* Set the maximum running time (in minutes). When milkio's running time reaches this value, terminate the process and automatically restart it from outside (K8S or other means).
|
|
38
38
|
*/
|
|
39
39
|
enableMaxRunningTimeoutLimit?: number | null | undefined;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export async function
|
|
43
|
-
if (
|
|
44
|
-
runtime.maxRequest.expected =
|
|
42
|
+
export async function createMilkioApp(milkioAppOptions: milkioAppOptions = {}) {
|
|
43
|
+
if (milkioAppOptions?.enableMaxRequestLimit && milkioAppOptions.enableMaxRequestLimit >= 1) {
|
|
44
|
+
runtime.maxRequest.expected = milkioAppOptions.enableMaxRequestLimit;
|
|
45
45
|
runtime.maxRequest.enable = true;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
if (
|
|
48
|
+
if (milkioAppOptions.enableMaxRunningTimeoutLimit && milkioAppOptions.enableMaxRunningTimeoutLimit >= 1) {
|
|
49
49
|
setTimeout(() => {
|
|
50
|
-
console.log('ā
|
|
50
|
+
console.log('ā milkio reached the limit of "maxRunningTimeout" in the options and automatically exited.');
|
|
51
51
|
exit(0);
|
|
52
|
-
},
|
|
52
|
+
}, milkioAppOptions.enableMaxRunningTimeoutLimit * 60 * 1000);
|
|
53
53
|
runtime.maxRunningTimeout.enable = true;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const
|
|
56
|
+
const milkioApp = {
|
|
57
57
|
execute: _execute,
|
|
58
58
|
executeToJson: _executeToJson,
|
|
59
59
|
_executeCore,
|
|
60
60
|
_executeCoreToJson
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
if (
|
|
64
|
-
await Promise.all(
|
|
63
|
+
if (milkioAppOptions.bootstraps) {
|
|
64
|
+
await Promise.all(milkioAppOptions.bootstraps());
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
if (
|
|
67
|
+
if (milkioAppOptions.middlewares) {
|
|
68
68
|
MiddlewareEvent.define("bootstrap", (a, b) => a.index - b.index);
|
|
69
69
|
MiddlewareEvent.define("beforeExecute", (a, b) => a.index - b.index);
|
|
70
70
|
MiddlewareEvent.define("afterExecute", (a, b) => b.index - a.index);
|
|
71
71
|
MiddlewareEvent.define("afterHTTPRequest", (a, b) => a.index - b.index);
|
|
72
72
|
MiddlewareEvent.define("beforeHTTPResponse", (a, b) => b.index - a.index);
|
|
73
73
|
|
|
74
|
-
const middlewares =
|
|
74
|
+
const middlewares = milkioAppOptions.middlewares();
|
|
75
75
|
|
|
76
76
|
for (let index = 0; index < middlewares.length; index++) {
|
|
77
77
|
const middlewareOptions = middlewares[index];
|
|
@@ -87,12 +87,12 @@ export async function createLoongbaoApp(loongbaoAppOptions: LoongbaoAppOptions =
|
|
|
87
87
|
}
|
|
88
88
|
MiddlewareEvent._sort();
|
|
89
89
|
|
|
90
|
-
await MiddlewareEvent.handle("bootstrap", [
|
|
90
|
+
await MiddlewareEvent.handle("bootstrap", [milkioApp]);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
console.log(`š§
|
|
93
|
+
console.log(`š§ Milkio is running on : ${cwd()}`);
|
|
94
94
|
|
|
95
|
-
return
|
|
95
|
+
return milkioApp;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
async function _execute<Path extends keyof (typeof schema)["apiMethodsTypeSchema"], Result extends Awaited<ReturnType<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>>>(path: Path, params: Parameters<(typeof schema)["apiMethodsTypeSchema"][Path]["api"]["action"]>[0] | string, headersInit: Record<string, string> | Headers = {}, options?: ExecuteOptions): Promise<ExecuteResult<Result>> {
|
|
@@ -126,7 +126,7 @@ async function _execute<Path extends keyof (typeof schema)["apiMethodsTypeSchema
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
|
-
* executeCore is a low-level API that is useful only when you want to execute the
|
|
129
|
+
* executeCore is a low-level API that is useful only when you want to execute the Milkio Api without using execute or httpServer.
|
|
130
130
|
* It only does the most basic thing internally, which is calling the API. The external handling of functions such as making executeId, logging, middleware, etc., are all handled externally.
|
|
131
131
|
* Both execute and httpServer essentially call executeCore.
|
|
132
132
|
*/
|
|
@@ -137,7 +137,7 @@ async function _executeCore<Path extends keyof (typeof schema)["apiMethodsTypeSc
|
|
|
137
137
|
|
|
138
138
|
if (runtime.maxRequest.enable) {
|
|
139
139
|
if (runtime.maxRequest.counter >= runtime.maxRequest.expected) {
|
|
140
|
-
console.log("ā
|
|
140
|
+
console.log("ā milkio reached the limit of 'maxRequest' in the options and automatically exited.");
|
|
141
141
|
exit(0);
|
|
142
142
|
}
|
|
143
143
|
runtime.maxRequest.counter++;
|
|
@@ -185,6 +185,7 @@ async function _executeCore<Path extends keyof (typeof schema)["apiMethodsTypeSc
|
|
|
185
185
|
|
|
186
186
|
// check type
|
|
187
187
|
// @ts-ignore
|
|
188
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
188
189
|
_validate(await (await schema.apiValidator.validate[path]()).params(params));
|
|
189
190
|
|
|
190
191
|
// execute api
|
package/package.json
CHANGED
package/scripts/build-dto.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { join } from "node:path";
|
|
|
6
6
|
import { copyFile, mkdir } from "node:fs/promises";
|
|
7
7
|
|
|
8
8
|
export async function buildDTO() {
|
|
9
|
-
console.log("š§
|
|
9
|
+
console.log("š§ milkio DTO Building..");
|
|
10
10
|
|
|
11
11
|
removeDir(join(cwd(), "packages", "dto", "dist"));
|
|
12
12
|
removeDir(join(cwd(), "packages", "dto", "generate"));
|
|
@@ -36,7 +36,7 @@ export async function buildDTO() {
|
|
|
36
36
|
|
|
37
37
|
const root = join(cwd(), "packages", "dto");
|
|
38
38
|
|
|
39
|
-
console.log("š§
|
|
39
|
+
console.log("š§ milkio DTO Build Finished");
|
|
40
40
|
console.log("\x1B[2m");
|
|
41
41
|
console.log("Now, your latest code (including changes to your interface) is built to the latest version and waiting for your release!");
|
|
42
42
|
console.log("");
|
|
@@ -53,7 +53,7 @@ export async function generateAppPartial(path?: string) {
|
|
|
53
53
|
importPath = importPath + "src/apps";
|
|
54
54
|
const template = `
|
|
55
55
|
import typia from "typia";
|
|
56
|
-
import { _validate, type ExecuteResultSuccess } from "
|
|
56
|
+
import { _validate, type ExecuteResultSuccess } from "milkio";
|
|
57
57
|
import { type TSONEncode } from "@southern-aurora/tson";
|
|
58
58
|
import type * as <%= utils.camel(path.slice(0, -3).replaceAll('/', '$')) %> from '${importPath}/<%= path.slice(0, -3) %>';
|
|
59
59
|
|
|
@@ -21,7 +21,7 @@ export async function generateApp() {
|
|
|
21
21
|
} catch (error) {} // Maybe the file does not exist
|
|
22
22
|
|
|
23
23
|
if (!existsSync(join("generate", "README.md"))) {
|
|
24
|
-
await writeFile(join("generate", "README.md"), "ā ļø All files in this directory are generated by
|
|
24
|
+
await writeFile(join("generate", "README.md"), "ā ļø All files in this directory are generated by milkio. Please do not modify the content, otherwise your modifications will be overwritten in the next generation.");
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// Write a basic framework to ensure that there are no errors when reading later
|
|
@@ -81,7 +81,7 @@ export async function generateApp() {
|
|
|
81
81
|
importPath = importPath + "src/apps";
|
|
82
82
|
const template = `
|
|
83
83
|
import typia from "typia";
|
|
84
|
-
import { _validate, type ExecuteResultSuccess } from "
|
|
84
|
+
import { _validate, type ExecuteResultSuccess } from "milkio";
|
|
85
85
|
import { type TSONEncode } from "@southern-aurora/tson";
|
|
86
86
|
import type * as <%= utils.camel(path.slice(0, -3).replaceAll('/', '$')) %> from '${importPath}/<%= path.slice(0, -3) %>';
|
|
87
87
|
|
|
@@ -14,10 +14,10 @@ export async function generate() {
|
|
|
14
14
|
await generateDatabase();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
console.log("
|
|
17
|
+
console.log("milkio Database Generating..");
|
|
18
18
|
|
|
19
19
|
await generate();
|
|
20
20
|
|
|
21
|
-
console.log("\nā
|
|
21
|
+
console.log("\nā
milkio Database Generated!\n");
|
|
22
22
|
|
|
23
23
|
exit(0);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { argv, exit } from "node:process";
|
|
4
4
|
import { generateApp } from "./generate/generate-app";
|
|
5
|
-
console.log("
|
|
5
|
+
console.log("milkio Quick Generating..");
|
|
6
6
|
|
|
7
7
|
export async function generatePartial(path?: string) {
|
|
8
8
|
await generateApp();
|
|
@@ -10,6 +10,6 @@ export async function generatePartial(path?: string) {
|
|
|
10
10
|
|
|
11
11
|
await generatePartial(...(argv.slice(3) as any));
|
|
12
12
|
|
|
13
|
-
console.log("\nā
|
|
13
|
+
console.log("\nā
milkio Generated!");
|
|
14
14
|
|
|
15
15
|
exit(0);
|
package/scripts/generate.ts
CHANGED
|
@@ -14,10 +14,10 @@ export async function generate() {
|
|
|
14
14
|
await generateApp();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
console.log("
|
|
17
|
+
console.log("milkio Generating..");
|
|
18
18
|
|
|
19
19
|
await generate();
|
|
20
20
|
|
|
21
|
-
console.log("\nā
|
|
21
|
+
console.log("\nā
milkio Generated!");
|
|
22
22
|
|
|
23
23
|
exit(0);
|
package/templates/api.ts
CHANGED
|
@@ -5,7 +5,7 @@ await createTemplate(async (tools) => {
|
|
|
5
5
|
return {
|
|
6
6
|
path: join(tools.directory, `${tools.hyphen(tools.name)}.ts`),
|
|
7
7
|
content: `
|
|
8
|
-
import { defineApi, defineApiTest } from "
|
|
8
|
+
import { defineApi, defineApiTest } from "milkio";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* ${tools.hyphen(tools.name)}
|
package/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any */
|
|
2
2
|
|
|
3
|
-
import { type
|
|
3
|
+
import { type createMilkioApp } from ".";
|
|
4
4
|
import type { failCode } from "../../src/fail-code";
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export type milkioApp = Awaited<ReturnType<typeof createMilkioApp>>;
|
|
7
7
|
|
|
8
8
|
export type ExecuteId = string | "global";
|
|
9
9
|
|
|
@@ -19,7 +19,7 @@ export type Fail<FailCode extends keyof FailEnumerates> = {
|
|
|
19
19
|
data: Parameters<FailEnumerates[FailCode]>[0];
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export type
|
|
22
|
+
export type milkioMeta = {
|
|
23
23
|
//
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -9,8 +9,8 @@ export function hanldeCatchError(error: any, executeId: ExecuteId): ExecuteResul
|
|
|
9
9
|
if (error.stack) logger.error("\nError Stack: ", error.stack);
|
|
10
10
|
else logger.error("\nError Stack: ", error);
|
|
11
11
|
|
|
12
|
-
if (error.name !== "
|
|
13
|
-
// If it is not
|
|
12
|
+
if (error.name !== "milkioReject") {
|
|
13
|
+
// If it is not milkioReject, it is considered an internal server error that should not be exposed
|
|
14
14
|
logger.error(`FailCode: internal-server-error`);
|
|
15
15
|
|
|
16
16
|
return {
|