milkio 0.0.33 → 0.0.35
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/package.json +1 -1
- package/utils/handle-catch-error.ts +14 -6
- package/templates/api.ts +0 -45
- package/utils/create-template.ts +0 -42
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { failCode } from "../../../src/fail-code"
|
|
2
2
|
import { useLogger, type ExecuteId, type ExecuteResult } from ".."
|
|
3
|
+
import { configMilkio } from "../../../src/config/milkio"
|
|
3
4
|
|
|
4
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
6
|
export function hanldeCatchError(error: any, executeId: ExecuteId): ExecuteResult<any> {
|
|
6
7
|
const logger = useLogger(executeId)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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)
|
|
13
|
+
}
|
|
11
14
|
|
|
12
15
|
if (error.name !== "MilkioReject") {
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
if (configMilkio.debug === true) {
|
|
17
|
+
// If it is not MilkioReject, it is considered an internal server error that should not be exposed
|
|
18
|
+
logger.error(`FailCode: INTERNAL_SERVER_ERROR`)
|
|
19
|
+
}
|
|
15
20
|
|
|
16
21
|
return {
|
|
17
22
|
executeId,
|
|
@@ -23,7 +28,10 @@ export function hanldeCatchError(error: any, executeId: ExecuteId): ExecuteResul
|
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
30
|
} else {
|
|
26
|
-
|
|
31
|
+
if (configMilkio.debug === true) {
|
|
32
|
+
logger.error(`FailCode: ${error.code}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
return {
|
|
28
36
|
executeId,
|
|
29
37
|
success: false,
|
package/templates/api.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { createTemplate } from "../utils/create-template"
|
|
2
|
-
import { join } from "path"
|
|
3
|
-
|
|
4
|
-
await createTemplate(async (tools) => {
|
|
5
|
-
return {
|
|
6
|
-
path: join(tools.directory, `${tools.hyphen(tools.name)}.ts`),
|
|
7
|
-
content: `
|
|
8
|
-
import { defineApi, defineApiTest } from "milkio"
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* ${tools.name}
|
|
12
|
-
*/
|
|
13
|
-
export const api = defineApi({
|
|
14
|
-
meta: {
|
|
15
|
-
// your meta..
|
|
16
|
-
},
|
|
17
|
-
async action(
|
|
18
|
-
params: {
|
|
19
|
-
// your params..
|
|
20
|
-
},
|
|
21
|
-
context
|
|
22
|
-
) {
|
|
23
|
-
const message = \`hello world!\`
|
|
24
|
-
|
|
25
|
-
// your code..
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
say: message
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
export const test = defineApiTest(api, [
|
|
34
|
-
{
|
|
35
|
-
name: "Basic",
|
|
36
|
-
handler: async (test) => {
|
|
37
|
-
const result = await test.execute(await test.randParams())
|
|
38
|
-
|
|
39
|
-
if (!result.success) return test.reject(\`The result was not success\`)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
])
|
|
43
|
-
`.trim()
|
|
44
|
-
}
|
|
45
|
-
})
|
package/utils/create-template.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { argv } from "node:process"
|
|
2
|
-
import { camel, hump, hyphen } from "@poech/camel-hump-under"
|
|
3
|
-
|
|
4
|
-
export type CreateTemplateTools = {
|
|
5
|
-
name: string;
|
|
6
|
-
directory: string;
|
|
7
|
-
src: () => string;
|
|
8
|
-
camel: (str: string) => string;
|
|
9
|
-
hump: (str: string) => string;
|
|
10
|
-
hyphen: (str: string) => string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type CreateTemplateFn = (tools: CreateTemplateTools) =>
|
|
14
|
-
| {
|
|
15
|
-
path: string;
|
|
16
|
-
content: string;
|
|
17
|
-
}
|
|
18
|
-
| Promise<{
|
|
19
|
-
path: string;
|
|
20
|
-
content: string;
|
|
21
|
-
}>;
|
|
22
|
-
|
|
23
|
-
export async function createTemplate(fn: CreateTemplateFn) {
|
|
24
|
-
const tools = {
|
|
25
|
-
name: argv[2],
|
|
26
|
-
directory: argv[3],
|
|
27
|
-
src: () => {
|
|
28
|
-
const patharr = argv[3].split("/")
|
|
29
|
-
const i = patharr.length - patharr.findIndex((str: string) => str.startsWith("src")) - 1
|
|
30
|
-
let path = ''
|
|
31
|
-
for (let j = 0; j < i; j++) {
|
|
32
|
-
path += "../"
|
|
33
|
-
}
|
|
34
|
-
return path
|
|
35
|
-
},
|
|
36
|
-
camel: (str: string) => camel(str).replaceAll("-", "").replaceAll("_", ""),
|
|
37
|
-
hump: (str: string) => hump(str).replaceAll("-", "").replaceAll("_", ""),
|
|
38
|
-
hyphen: (str: string) => hyphen(str).replaceAll("_", "")
|
|
39
|
-
}
|
|
40
|
-
const file = await fn(tools)
|
|
41
|
-
await Bun.write(file.path, file.content)
|
|
42
|
-
}
|