@milkio/astra 1.0.0-alpha.0 → 1.0.0-alpha.1
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/.publish/publish.json +0 -0
- package/README.md +1 -1
- package/index.ts +64 -16
- package/package.json +1 -1
- package/tsconfig.json +0 -0
- package/utils/cookbook-dto-checks.ts +443 -0
- package/utils/cookbook-dto-types.ts +41 -0
package/.publish/publish.json
CHANGED
|
File without changes
|
package/README.md
CHANGED
package/index.ts
CHANGED
|
@@ -1,36 +1,49 @@
|
|
|
1
1
|
import { join, dirname } from "node:path";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { format } from "date-fns";
|
|
4
3
|
import { existsSync } from "node:fs";
|
|
5
4
|
import { readFile } from "node:fs/promises";
|
|
6
5
|
import { cwd } from "node:process";
|
|
7
6
|
import { load } from "js-toml";
|
|
8
|
-
import typia from "typia";
|
|
9
7
|
import { TSON } from "@southern-aurora/tson";
|
|
8
|
+
import { format } from "date-fns";
|
|
9
|
+
import type { CookbookOptions } from "./utils/cookbook-dto-types";
|
|
10
10
|
|
|
11
11
|
export type AstraOptionsInit = {
|
|
12
12
|
stargate: { $types: any; execute: any; ping: any; cookbook: any };
|
|
13
13
|
bootstrap: () => Promise<Record<string, any>>;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
type GeneratorGeneric<T> = T extends AsyncGenerator<infer I> ? I : never;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
type Mixin<T, U> = U & Omit<T, keyof U>;
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
type ExecuteOptions = {
|
|
21
21
|
headers?: Record<string, string>;
|
|
22
22
|
timeout?: number;
|
|
23
23
|
type?: "action" | "stream";
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
type ExecuteResultsOption = { executeId: string };
|
|
27
|
+
|
|
28
|
+
type Context = {
|
|
29
|
+
logger: Logger;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type Logger = {
|
|
33
|
+
debug: (description: string, ...params: Array<unknown>) => Log;
|
|
34
|
+
info: (description: string, ...params: Array<unknown>) => Log;
|
|
35
|
+
warn: (description: string, ...params: Array<unknown>) => Log;
|
|
36
|
+
error: (description: string, ...params: Array<unknown>) => Log;
|
|
37
|
+
response: (description: string, ...params: Array<unknown>) => Log;
|
|
38
|
+
};
|
|
27
39
|
|
|
28
|
-
|
|
40
|
+
type Log = [string /* executeId */, "[DEBUG]" | "[INFO]" | "[WARN]" | "[ERROR]" | "[RESPONSE]", string, string, ...Array<unknown>];
|
|
41
|
+
|
|
42
|
+
type Reject = (description: string, ...params: Array<unknown>) => Error;
|
|
29
43
|
|
|
30
44
|
export const createAstra = async <AstraOptions extends AstraOptionsInit, Generated extends AstraOptions["stargate"]["$types"]["generated"]>(astraOptions: AstraOptions) => {
|
|
31
|
-
let cookbookOptions: any = undefined;
|
|
32
45
|
if (!existsSync(join(cwd(), "cookbook.toml"))) throw new Error(`The "cookbook.toml" file does not exist in the current directory. If you are running the test with the VS Code extension, make sure it exists in the root directory of the folder you are opening with VS Code.`);
|
|
33
|
-
cookbookOptions = load((await readFile(join(cwd(), "cookbook.toml"))).toString());
|
|
46
|
+
let cookbookOptions = load((await readFile(join(cwd(), "cookbook.toml"))).toString()) as CookbookOptions;
|
|
34
47
|
// wait for all milkio projects to start and can be accessed
|
|
35
48
|
// the reason why stargate's ping method is not used directly is that even if only one project is tested, it is necessary to wait for all milkio projects to start
|
|
36
49
|
await Promise.all([
|
|
@@ -93,7 +106,7 @@ export const createAstra = async <AstraOptions extends AstraOptionsInit, Generat
|
|
|
93
106
|
|
|
94
107
|
return {
|
|
95
108
|
options: astraOptions,
|
|
96
|
-
async createMirrorWorld(importMetaUrl: string): Promise<[
|
|
109
|
+
async createMirrorWorld(importMetaUrl: string): Promise<[Context, Reject, MirrorWorld]> {
|
|
97
110
|
const thisFilePath = join(fileURLToPath(importMetaUrl));
|
|
98
111
|
const thisFileDirPath = join(dirname(thisFilePath)).replaceAll("\\", "/");
|
|
99
112
|
const thisFileDirPathArr = thisFileDirPath.split("/");
|
|
@@ -135,24 +148,59 @@ export const createAstra = async <AstraOptions extends AstraOptionsInit, Generat
|
|
|
135
148
|
}
|
|
136
149
|
|
|
137
150
|
const results = await this.options.stargate.cookbook.subscribe(`http://localhost:${cookbookOptions.general.cookbookPort}`);
|
|
138
|
-
console.log("[MILKIO]", "--- server logs start ---");
|
|
139
151
|
void (async () => {
|
|
140
152
|
for await (const result of results) {
|
|
141
153
|
if (result.type !== "milkio@logger") continue;
|
|
142
|
-
console.log("[MILKIO]", ...(result.log ?? []));
|
|
154
|
+
console.log("\n[MILKIO]", ...(result.log ?? []));
|
|
143
155
|
}
|
|
144
156
|
})();
|
|
145
157
|
|
|
146
158
|
const response = await this.options.stargate.execute(path, options);
|
|
147
159
|
|
|
148
160
|
await new Promise((resolve) => setTimeout(resolve, 40));
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
console.log("[MILKIO]", "--- server logs end ---");
|
|
161
|
+
context.logger.response(path as string, `\nerror - ${TSON.stringify(response[0])}`, `\nresult - ${typeof response[1]?.next === "function" ? "AsyncGenerator" : TSON.stringify(response[1])}`);
|
|
152
162
|
|
|
153
163
|
return response;
|
|
154
164
|
};
|
|
155
165
|
|
|
166
|
+
const getNow = () => format(new Date(), "(yyyy-MM-dd hh:mm:ss)");
|
|
167
|
+
const onLoggerInserting = (log: Log) => {
|
|
168
|
+
log = [...log];
|
|
169
|
+
log[0] = `\n${log[0]}` as any;
|
|
170
|
+
console.log(...log);
|
|
171
|
+
return true;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const context = {
|
|
175
|
+
logger: {
|
|
176
|
+
debug: (description: string, ...params: Array<unknown>): Log => {
|
|
177
|
+
const log: Log = ["[TEST]", "[DEBUG]", description, getNow(), ...params];
|
|
178
|
+
onLoggerInserting(log);
|
|
179
|
+
return log;
|
|
180
|
+
},
|
|
181
|
+
info: (description: string, ...params: Array<unknown>): Log => {
|
|
182
|
+
const log: Log = ["[TEST]", "[INFO]", description, getNow(), ...params];
|
|
183
|
+
onLoggerInserting(log);
|
|
184
|
+
return log;
|
|
185
|
+
},
|
|
186
|
+
warn: (description: string, ...params: Array<unknown>): Log => {
|
|
187
|
+
const log: Log = ["[TEST]", "[WARN]", description, getNow(), ...params];
|
|
188
|
+
onLoggerInserting(log);
|
|
189
|
+
return log;
|
|
190
|
+
},
|
|
191
|
+
error: (description: string, ...params: Array<unknown>): Log => {
|
|
192
|
+
const log: Log = ["[TEST]", "[ERROR]", description, getNow(), ...params];
|
|
193
|
+
onLoggerInserting(log);
|
|
194
|
+
return log;
|
|
195
|
+
},
|
|
196
|
+
response: (path: string, ...params: Array<unknown>): Log => {
|
|
197
|
+
const log: Log = ["[TEST]", "[RESPONSE]", path, getNow(), ...params];
|
|
198
|
+
onLoggerInserting(log);
|
|
199
|
+
return log;
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
} as Context;
|
|
203
|
+
|
|
156
204
|
const world = {
|
|
157
205
|
...(await astraOptions.bootstrap()),
|
|
158
206
|
paths,
|
|
@@ -175,7 +223,7 @@ export const createAstra = async <AstraOptions extends AstraOptionsInit, Generat
|
|
|
175
223
|
return new Error(message);
|
|
176
224
|
};
|
|
177
225
|
|
|
178
|
-
return [
|
|
226
|
+
return [context, reject, world];
|
|
179
227
|
},
|
|
180
228
|
};
|
|
181
229
|
};
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
|
File without changes
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The content of this file is automatically generated by Typia.
|
|
3
|
+
* It can be edited in the /packages/cookbook-dto/src/* file, and each time you run bun run dev, the generated file will be synced to another location based on the content of the /develop.ts.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import typia from "typia";
|
|
7
|
+
import type { CookbookActionParams, CookbookOptions, CookbookSubscribeEmits } from "./cookbook-dto-types";
|
|
8
|
+
export const checkCookbookOptions = async (cookbookTomlParsed: any): Promise<[
|
|
9
|
+
Record<any, any> & {
|
|
10
|
+
message: string;
|
|
11
|
+
stack: string;
|
|
12
|
+
},
|
|
13
|
+
null
|
|
14
|
+
] | [
|
|
15
|
+
null,
|
|
16
|
+
CookbookOptions
|
|
17
|
+
]> => {
|
|
18
|
+
const checkResult = (() => { const $join = (typia.validateEquals as any).join; const $io0 = (input: any, _exceptionable: boolean = true): boolean => "object" === typeof input.projects && null !== input.projects && false === Array.isArray(input.projects) && $io1(input.projects, true && _exceptionable) && ("object" === typeof input.general && null !== input.general && $io3(input.general, true && _exceptionable)) && (2 === Object.keys(input).length || Object.keys(input).every((key: any) => {
|
|
19
|
+
if (["projects", "general"].some((prop: any) => key === prop))
|
|
20
|
+
return true;
|
|
21
|
+
const value = input[key];
|
|
22
|
+
if (undefined === value)
|
|
23
|
+
return true;
|
|
24
|
+
return false;
|
|
25
|
+
})); const $io1 = (input: any, _exceptionable: boolean = true): boolean => Object.keys(input).every((key: any) => {
|
|
26
|
+
const value = input[key];
|
|
27
|
+
if (undefined === value)
|
|
28
|
+
return true;
|
|
29
|
+
return "object" === typeof value && null !== value && $io2(value, true && _exceptionable);
|
|
30
|
+
}); const $io2 = (input: any, _exceptionable: boolean = true): boolean => ("milkio" === input.type || "other" === input.type) && "number" === typeof input.port && (Array.isArray(input.start) && input.start.every((elem: any, _index1: number) => "string" === typeof elem)) && (Array.isArray(input.build) && input.build.every((elem: any, _index2: number) => "string" === typeof elem)) && (undefined === input.lazyRoutes || "boolean" === typeof input.lazyRoutes) && (undefined === input.typiaMode || "generation" === input.typiaMode || "bundler" === input.typiaMode) && (undefined === input.significant || Array.isArray(input.significant) && input.significant.every((elem: any, _index3: number) => "string" === typeof elem)) && (undefined === input.insignificant || Array.isArray(input.insignificant) && input.insignificant.every((elem: any, _index4: number) => "string" === typeof elem)) && (4 === Object.keys(input).length || Object.keys(input).every((key: any) => {
|
|
31
|
+
if (["type", "port", "start", "build", "lazyRoutes", "typiaMode", "significant", "insignificant"].some((prop: any) => key === prop))
|
|
32
|
+
return true;
|
|
33
|
+
const value = input[key];
|
|
34
|
+
if (undefined === value)
|
|
35
|
+
return true;
|
|
36
|
+
return false;
|
|
37
|
+
})); const $io3 = (input: any, _exceptionable: boolean = true): boolean => "number" === typeof input.cookbookPort && (1 === Object.keys(input).length || Object.keys(input).every((key: any) => {
|
|
38
|
+
if (["cookbookPort"].some((prop: any) => key === prop))
|
|
39
|
+
return true;
|
|
40
|
+
const value = input[key];
|
|
41
|
+
if (undefined === value)
|
|
42
|
+
return true;
|
|
43
|
+
return false;
|
|
44
|
+
})); const $vo0 = (input: any, _path: string, _exceptionable: boolean = true): boolean => [("object" === typeof input.projects && null !== input.projects && false === Array.isArray(input.projects) || $report(_exceptionable, {
|
|
45
|
+
path: _path + ".projects",
|
|
46
|
+
expected: "Record<string, __type>",
|
|
47
|
+
value: input.projects
|
|
48
|
+
})) && $vo1(input.projects, _path + ".projects", true && _exceptionable) || $report(_exceptionable, {
|
|
49
|
+
path: _path + ".projects",
|
|
50
|
+
expected: "Record<string, __type>",
|
|
51
|
+
value: input.projects
|
|
52
|
+
}), ("object" === typeof input.general && null !== input.general || $report(_exceptionable, {
|
|
53
|
+
path: _path + ".general",
|
|
54
|
+
expected: "__type.o1",
|
|
55
|
+
value: input.general
|
|
56
|
+
})) && $vo3(input.general, _path + ".general", true && _exceptionable) || $report(_exceptionable, {
|
|
57
|
+
path: _path + ".general",
|
|
58
|
+
expected: "__type.o1",
|
|
59
|
+
value: input.general
|
|
60
|
+
}), 2 === Object.keys(input).length || (false === _exceptionable || Object.keys(input).map((key: any) => {
|
|
61
|
+
if (["projects", "general"].some((prop: any) => key === prop))
|
|
62
|
+
return true;
|
|
63
|
+
const value = input[key];
|
|
64
|
+
if (undefined === value)
|
|
65
|
+
return true;
|
|
66
|
+
return $report(_exceptionable, {
|
|
67
|
+
path: _path + $join(key),
|
|
68
|
+
expected: "undefined",
|
|
69
|
+
value: value
|
|
70
|
+
});
|
|
71
|
+
}).every((flag: boolean) => flag))].every((flag: boolean) => flag); const $vo1 = (input: any, _path: string, _exceptionable: boolean = true): boolean => [false === _exceptionable || Object.keys(input).map((key: any) => {
|
|
72
|
+
const value = input[key];
|
|
73
|
+
if (undefined === value)
|
|
74
|
+
return true;
|
|
75
|
+
return ("object" === typeof value && null !== value || $report(_exceptionable, {
|
|
76
|
+
path: _path + $join(key),
|
|
77
|
+
expected: "__type",
|
|
78
|
+
value: value
|
|
79
|
+
})) && $vo2(value, _path + $join(key), true && _exceptionable) || $report(_exceptionable, {
|
|
80
|
+
path: _path + $join(key),
|
|
81
|
+
expected: "__type",
|
|
82
|
+
value: value
|
|
83
|
+
});
|
|
84
|
+
}).every((flag: boolean) => flag)].every((flag: boolean) => flag); const $vo2 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ["milkio" === input.type || "other" === input.type || $report(_exceptionable, {
|
|
85
|
+
path: _path + ".type",
|
|
86
|
+
expected: "(\"milkio\" | \"other\")",
|
|
87
|
+
value: input.type
|
|
88
|
+
}), "number" === typeof input.port || $report(_exceptionable, {
|
|
89
|
+
path: _path + ".port",
|
|
90
|
+
expected: "number",
|
|
91
|
+
value: input.port
|
|
92
|
+
}), (Array.isArray(input.start) || $report(_exceptionable, {
|
|
93
|
+
path: _path + ".start",
|
|
94
|
+
expected: "Array<string>",
|
|
95
|
+
value: input.start
|
|
96
|
+
})) && input.start.map((elem: any, _index5: number) => "string" === typeof elem || $report(_exceptionable, {
|
|
97
|
+
path: _path + ".start[" + _index5 + "]",
|
|
98
|
+
expected: "string",
|
|
99
|
+
value: elem
|
|
100
|
+
})).every((flag: boolean) => flag) || $report(_exceptionable, {
|
|
101
|
+
path: _path + ".start",
|
|
102
|
+
expected: "Array<string>",
|
|
103
|
+
value: input.start
|
|
104
|
+
}), (Array.isArray(input.build) || $report(_exceptionable, {
|
|
105
|
+
path: _path + ".build",
|
|
106
|
+
expected: "Array<string>",
|
|
107
|
+
value: input.build
|
|
108
|
+
})) && input.build.map((elem: any, _index6: number) => "string" === typeof elem || $report(_exceptionable, {
|
|
109
|
+
path: _path + ".build[" + _index6 + "]",
|
|
110
|
+
expected: "string",
|
|
111
|
+
value: elem
|
|
112
|
+
})).every((flag: boolean) => flag) || $report(_exceptionable, {
|
|
113
|
+
path: _path + ".build",
|
|
114
|
+
expected: "Array<string>",
|
|
115
|
+
value: input.build
|
|
116
|
+
}), undefined === input.lazyRoutes || "boolean" === typeof input.lazyRoutes || $report(_exceptionable, {
|
|
117
|
+
path: _path + ".lazyRoutes",
|
|
118
|
+
expected: "(boolean | undefined)",
|
|
119
|
+
value: input.lazyRoutes
|
|
120
|
+
}), undefined === input.typiaMode || "generation" === input.typiaMode || "bundler" === input.typiaMode || $report(_exceptionable, {
|
|
121
|
+
path: _path + ".typiaMode",
|
|
122
|
+
expected: "(\"bundler\" | \"generation\" | undefined)",
|
|
123
|
+
value: input.typiaMode
|
|
124
|
+
}), undefined === input.significant || (Array.isArray(input.significant) || $report(_exceptionable, {
|
|
125
|
+
path: _path + ".significant",
|
|
126
|
+
expected: "(Array<string> | undefined)",
|
|
127
|
+
value: input.significant
|
|
128
|
+
})) && input.significant.map((elem: any, _index7: number) => "string" === typeof elem || $report(_exceptionable, {
|
|
129
|
+
path: _path + ".significant[" + _index7 + "]",
|
|
130
|
+
expected: "string",
|
|
131
|
+
value: elem
|
|
132
|
+
})).every((flag: boolean) => flag) || $report(_exceptionable, {
|
|
133
|
+
path: _path + ".significant",
|
|
134
|
+
expected: "(Array<string> | undefined)",
|
|
135
|
+
value: input.significant
|
|
136
|
+
}), undefined === input.insignificant || (Array.isArray(input.insignificant) || $report(_exceptionable, {
|
|
137
|
+
path: _path + ".insignificant",
|
|
138
|
+
expected: "(Array<string> | undefined)",
|
|
139
|
+
value: input.insignificant
|
|
140
|
+
})) && input.insignificant.map((elem: any, _index8: number) => "string" === typeof elem || $report(_exceptionable, {
|
|
141
|
+
path: _path + ".insignificant[" + _index8 + "]",
|
|
142
|
+
expected: "string",
|
|
143
|
+
value: elem
|
|
144
|
+
})).every((flag: boolean) => flag) || $report(_exceptionable, {
|
|
145
|
+
path: _path + ".insignificant",
|
|
146
|
+
expected: "(Array<string> | undefined)",
|
|
147
|
+
value: input.insignificant
|
|
148
|
+
}), 4 === Object.keys(input).length || (false === _exceptionable || Object.keys(input).map((key: any) => {
|
|
149
|
+
if (["type", "port", "start", "build", "lazyRoutes", "typiaMode", "significant", "insignificant"].some((prop: any) => key === prop))
|
|
150
|
+
return true;
|
|
151
|
+
const value = input[key];
|
|
152
|
+
if (undefined === value)
|
|
153
|
+
return true;
|
|
154
|
+
return $report(_exceptionable, {
|
|
155
|
+
path: _path + $join(key),
|
|
156
|
+
expected: "undefined",
|
|
157
|
+
value: value
|
|
158
|
+
});
|
|
159
|
+
}).every((flag: boolean) => flag))].every((flag: boolean) => flag); const $vo3 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ["number" === typeof input.cookbookPort || $report(_exceptionable, {
|
|
160
|
+
path: _path + ".cookbookPort",
|
|
161
|
+
expected: "number",
|
|
162
|
+
value: input.cookbookPort
|
|
163
|
+
}), 1 === Object.keys(input).length || (false === _exceptionable || Object.keys(input).map((key: any) => {
|
|
164
|
+
if (["cookbookPort"].some((prop: any) => key === prop))
|
|
165
|
+
return true;
|
|
166
|
+
const value = input[key];
|
|
167
|
+
if (undefined === value)
|
|
168
|
+
return true;
|
|
169
|
+
return $report(_exceptionable, {
|
|
170
|
+
path: _path + $join(key),
|
|
171
|
+
expected: "undefined",
|
|
172
|
+
value: value
|
|
173
|
+
});
|
|
174
|
+
}).every((flag: boolean) => flag))].every((flag: boolean) => flag); const __is = (input: any, _exceptionable: boolean = true): input is CookbookOptions => "object" === typeof input && null !== input && $io0(input, true); let errors: any; let $report: any; return (input: any): typia.IValidation<CookbookOptions> => {
|
|
175
|
+
if (false === __is(input)) {
|
|
176
|
+
errors = [];
|
|
177
|
+
$report = (typia.validateEquals as any).report(errors);
|
|
178
|
+
((input: any, _path: string, _exceptionable: boolean = true) => ("object" === typeof input && null !== input || $report(true, {
|
|
179
|
+
path: _path + "",
|
|
180
|
+
expected: "CookbookOptions",
|
|
181
|
+
value: input
|
|
182
|
+
})) && $vo0(input, _path + "", true) || $report(true, {
|
|
183
|
+
path: _path + "",
|
|
184
|
+
expected: "CookbookOptions",
|
|
185
|
+
value: input
|
|
186
|
+
}))(input, "$input", true);
|
|
187
|
+
const success = 0 === errors.length;
|
|
188
|
+
return {
|
|
189
|
+
success,
|
|
190
|
+
errors,
|
|
191
|
+
data: success ? input : undefined
|
|
192
|
+
} as any;
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
success: true,
|
|
196
|
+
errors: [],
|
|
197
|
+
data: input
|
|
198
|
+
} as any;
|
|
199
|
+
}; })()(cookbookTomlParsed);
|
|
200
|
+
let error = null;
|
|
201
|
+
if (!checkResult.success) {
|
|
202
|
+
const error: any = checkResult.errors.at(0)!;
|
|
203
|
+
error.message = `The "cookbook.toml" format is incorrect, [${error.path.slice(7)}] should be ${error.expected}, but it is actually ${error.value}. You may be missing some properties in the configuration item, or adding some properties that will not be used. If you have extra properties, these properties are likely due to a misspelling.`;
|
|
204
|
+
Error.captureStackTrace(error);
|
|
205
|
+
cookbookTomlParsed = null;
|
|
206
|
+
}
|
|
207
|
+
return [error, cookbookTomlParsed];
|
|
208
|
+
};
|
|
209
|
+
export const checkCookbookActionParams = async (results: any): Promise<[
|
|
210
|
+
Record<any, any> & {
|
|
211
|
+
message: string;
|
|
212
|
+
stack: string;
|
|
213
|
+
},
|
|
214
|
+
null
|
|
215
|
+
] | [
|
|
216
|
+
null,
|
|
217
|
+
CookbookActionParams
|
|
218
|
+
]> => {
|
|
219
|
+
if (typeof Bun === "undefined")
|
|
220
|
+
throw new Error("Bun is not defined");
|
|
221
|
+
const checkResult = (() => { const $io0 = (input: any): boolean => "milkio@logger" === input.type && Array.isArray(input.log); const $vo0 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ["milkio@logger" === input.type || $report(_exceptionable, {
|
|
222
|
+
path: _path + ".type",
|
|
223
|
+
expected: "\"milkio@logger\"",
|
|
224
|
+
value: input.type
|
|
225
|
+
}), Array.isArray(input.log) || $report(_exceptionable, {
|
|
226
|
+
path: _path + ".log",
|
|
227
|
+
expected: "Array<any>",
|
|
228
|
+
value: input.log
|
|
229
|
+
})].every((flag: boolean) => flag); const $po0 = (input: any): any => {
|
|
230
|
+
for (const key of Object.keys(input)) {
|
|
231
|
+
if ("type" === key || "log" === key)
|
|
232
|
+
continue;
|
|
233
|
+
delete input[key];
|
|
234
|
+
}
|
|
235
|
+
}; const __is = (input: any): input is CookbookActionParams => "object" === typeof input && null !== input && $io0(input); let errors: any; let $report: any; const __validate = (input: any): typia.IValidation<CookbookActionParams> => {
|
|
236
|
+
if (false === __is(input)) {
|
|
237
|
+
errors = [];
|
|
238
|
+
$report = (typia.misc.validatePrune as any).report(errors);
|
|
239
|
+
((input: any, _path: string, _exceptionable: boolean = true) => ("object" === typeof input && null !== input || $report(true, {
|
|
240
|
+
path: _path + "",
|
|
241
|
+
expected: "CookbookActionParams",
|
|
242
|
+
value: input
|
|
243
|
+
})) && $vo0(input, _path + "", true) || $report(true, {
|
|
244
|
+
path: _path + "",
|
|
245
|
+
expected: "CookbookActionParams",
|
|
246
|
+
value: input
|
|
247
|
+
}))(input, "$input", true);
|
|
248
|
+
const success = 0 === errors.length;
|
|
249
|
+
return {
|
|
250
|
+
success,
|
|
251
|
+
errors,
|
|
252
|
+
data: success ? input : undefined
|
|
253
|
+
} as any;
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
success: true,
|
|
257
|
+
errors: [],
|
|
258
|
+
data: input
|
|
259
|
+
} as any;
|
|
260
|
+
}; const __prune = (input: CookbookActionParams): void => {
|
|
261
|
+
if ("object" === typeof input && null !== input)
|
|
262
|
+
$po0(input);
|
|
263
|
+
}; return (input: any): typia.IValidation<CookbookActionParams> => {
|
|
264
|
+
const result = __validate(input);
|
|
265
|
+
if (result.success)
|
|
266
|
+
__prune(input);
|
|
267
|
+
return result;
|
|
268
|
+
}; })()(results);
|
|
269
|
+
let error = null;
|
|
270
|
+
if (!checkResult.success) {
|
|
271
|
+
const error: any = checkResult.errors.at(0)!;
|
|
272
|
+
error.message = `The "cookbook.toml" format is incorrect, [${error.path.slice(7)}] should be ${error.expected}, but it is actually ${error.value}. You may be missing some properties in the configuration item, or adding some properties that will not be used. If you have extra properties, these properties are likely due to a misspelling.`;
|
|
273
|
+
Error.captureStackTrace(error);
|
|
274
|
+
results = null;
|
|
275
|
+
}
|
|
276
|
+
return [error, results];
|
|
277
|
+
};
|
|
278
|
+
export const checkCookbookSubscribeEmits = async (results: any): Promise<[
|
|
279
|
+
Record<any, any> & {
|
|
280
|
+
message: string;
|
|
281
|
+
stack: string;
|
|
282
|
+
},
|
|
283
|
+
null
|
|
284
|
+
] | [
|
|
285
|
+
null,
|
|
286
|
+
CookbookSubscribeEmits
|
|
287
|
+
]> => {
|
|
288
|
+
const typia = await import("typia");
|
|
289
|
+
const checkResult = (() => { const $throws = (typia.misc.validatePrune as any).throws; const $io0 = (input: any): boolean => "workers@stdout" === input.type && "string" === typeof input.key && "string" === typeof input.chunk; const $io1 = (input: any): boolean => "workers@state" === input.type && "string" === typeof input.key && ("running" === input.state || "stopped" === input.state) && (null === input.code || "running" === input.code || "kill" === input.code || "number" === typeof input.code); const $io2 = (input: any): boolean => "watcher@change" === input.type && ("rename" === input.event || "change" === input.event) && "string" === typeof input.path; const $io3 = (input: any): boolean => "milkio@logger" === input.type && Array.isArray(input.log); const $iu0 = (input: any): any => (() => {
|
|
290
|
+
if ("workers@stdout" === input.type)
|
|
291
|
+
return $io0(input);
|
|
292
|
+
else if ("workers@state" === input.type)
|
|
293
|
+
return $io1(input);
|
|
294
|
+
else if ("watcher@change" === input.type)
|
|
295
|
+
return $io2(input);
|
|
296
|
+
else if ("milkio@logger" === input.type)
|
|
297
|
+
return $io3(input);
|
|
298
|
+
else
|
|
299
|
+
return false;
|
|
300
|
+
})(); const $vo0 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ["workers@stdout" === input.type || $report(_exceptionable, {
|
|
301
|
+
path: _path + ".type",
|
|
302
|
+
expected: "\"workers@stdout\"",
|
|
303
|
+
value: input.type
|
|
304
|
+
}), "string" === typeof input.key || $report(_exceptionable, {
|
|
305
|
+
path: _path + ".key",
|
|
306
|
+
expected: "string",
|
|
307
|
+
value: input.key
|
|
308
|
+
}), "string" === typeof input.chunk || $report(_exceptionable, {
|
|
309
|
+
path: _path + ".chunk",
|
|
310
|
+
expected: "string",
|
|
311
|
+
value: input.chunk
|
|
312
|
+
})].every((flag: boolean) => flag); const $vo1 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ["workers@state" === input.type || $report(_exceptionable, {
|
|
313
|
+
path: _path + ".type",
|
|
314
|
+
expected: "\"workers@state\"",
|
|
315
|
+
value: input.type
|
|
316
|
+
}), "string" === typeof input.key || $report(_exceptionable, {
|
|
317
|
+
path: _path + ".key",
|
|
318
|
+
expected: "string",
|
|
319
|
+
value: input.key
|
|
320
|
+
}), "running" === input.state || "stopped" === input.state || $report(_exceptionable, {
|
|
321
|
+
path: _path + ".state",
|
|
322
|
+
expected: "(\"running\" | \"stopped\")",
|
|
323
|
+
value: input.state
|
|
324
|
+
}), null === input.code || "running" === input.code || "kill" === input.code || "number" === typeof input.code || $report(_exceptionable, {
|
|
325
|
+
path: _path + ".code",
|
|
326
|
+
expected: "(\"kill\" | \"running\" | null | number)",
|
|
327
|
+
value: input.code
|
|
328
|
+
})].every((flag: boolean) => flag); const $vo2 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ["watcher@change" === input.type || $report(_exceptionable, {
|
|
329
|
+
path: _path + ".type",
|
|
330
|
+
expected: "\"watcher@change\"",
|
|
331
|
+
value: input.type
|
|
332
|
+
}), "rename" === input.event || "change" === input.event || $report(_exceptionable, {
|
|
333
|
+
path: _path + ".event",
|
|
334
|
+
expected: "(\"change\" | \"rename\")",
|
|
335
|
+
value: input.event
|
|
336
|
+
}), "string" === typeof input.path || $report(_exceptionable, {
|
|
337
|
+
path: _path + ".path",
|
|
338
|
+
expected: "string",
|
|
339
|
+
value: input.path
|
|
340
|
+
})].every((flag: boolean) => flag); const $vo3 = (input: any, _path: string, _exceptionable: boolean = true): boolean => ["milkio@logger" === input.type || $report(_exceptionable, {
|
|
341
|
+
path: _path + ".type",
|
|
342
|
+
expected: "\"milkio@logger\"",
|
|
343
|
+
value: input.type
|
|
344
|
+
}), Array.isArray(input.log) || $report(_exceptionable, {
|
|
345
|
+
path: _path + ".log",
|
|
346
|
+
expected: "Array<any>",
|
|
347
|
+
value: input.log
|
|
348
|
+
})].every((flag: boolean) => flag); const $vu0 = (input: any, _path: string, _exceptionable: boolean = true): any => (() => {
|
|
349
|
+
if ("workers@stdout" === input.type)
|
|
350
|
+
return $vo0(input, _path, true && _exceptionable);
|
|
351
|
+
else if ("workers@state" === input.type)
|
|
352
|
+
return $vo1(input, _path, true && _exceptionable);
|
|
353
|
+
else if ("watcher@change" === input.type)
|
|
354
|
+
return $vo2(input, _path, true && _exceptionable);
|
|
355
|
+
else if ("milkio@logger" === input.type)
|
|
356
|
+
return $vo3(input, _path, true && _exceptionable);
|
|
357
|
+
else
|
|
358
|
+
return $report(_exceptionable, {
|
|
359
|
+
path: _path,
|
|
360
|
+
expected: "(__type | __type.o1 | __type.o2 | __type.o3)",
|
|
361
|
+
value: input
|
|
362
|
+
});
|
|
363
|
+
})(); const $po0 = (input: any): any => {
|
|
364
|
+
for (const key of Object.keys(input)) {
|
|
365
|
+
if ("type" === key || "key" === key || "chunk" === key)
|
|
366
|
+
continue;
|
|
367
|
+
delete input[key];
|
|
368
|
+
}
|
|
369
|
+
}; const $po1 = (input: any): any => {
|
|
370
|
+
for (const key of Object.keys(input)) {
|
|
371
|
+
if ("type" === key || "key" === key || "state" === key || "code" === key)
|
|
372
|
+
continue;
|
|
373
|
+
delete input[key];
|
|
374
|
+
}
|
|
375
|
+
}; const $po2 = (input: any): any => {
|
|
376
|
+
for (const key of Object.keys(input)) {
|
|
377
|
+
if ("type" === key || "event" === key || "path" === key)
|
|
378
|
+
continue;
|
|
379
|
+
delete input[key];
|
|
380
|
+
}
|
|
381
|
+
}; const $po3 = (input: any): any => {
|
|
382
|
+
for (const key of Object.keys(input)) {
|
|
383
|
+
if ("type" === key || "log" === key)
|
|
384
|
+
continue;
|
|
385
|
+
delete input[key];
|
|
386
|
+
}
|
|
387
|
+
}; const $pu0 = (input: any): any => (() => {
|
|
388
|
+
if ("workers@stdout" === input.type)
|
|
389
|
+
return $po0(input);
|
|
390
|
+
else if ("workers@state" === input.type)
|
|
391
|
+
return $po1(input);
|
|
392
|
+
else if ("watcher@change" === input.type)
|
|
393
|
+
return $po2(input);
|
|
394
|
+
else if ("milkio@logger" === input.type)
|
|
395
|
+
return $po3(input);
|
|
396
|
+
else
|
|
397
|
+
$throws({
|
|
398
|
+
expected: "(__type | __type.o1 | __type.o2 | __type.o3)",
|
|
399
|
+
value: input
|
|
400
|
+
});
|
|
401
|
+
})(); const __is = (input: any): input is CookbookSubscribeEmits => "object" === typeof input && null !== input && $iu0(input); let errors: any; let $report: any; const __validate = (input: any): typia.IValidation<CookbookSubscribeEmits> => {
|
|
402
|
+
if (false === __is(input)) {
|
|
403
|
+
errors = [];
|
|
404
|
+
$report = (typia.misc.validatePrune as any).report(errors);
|
|
405
|
+
((input: any, _path: string, _exceptionable: boolean = true) => ("object" === typeof input && null !== input || $report(true, {
|
|
406
|
+
path: _path + "",
|
|
407
|
+
expected: "(__type | __type.o1 | __type.o2 | __type.o3)",
|
|
408
|
+
value: input
|
|
409
|
+
})) && $vu0(input, _path + "", true) || $report(true, {
|
|
410
|
+
path: _path + "",
|
|
411
|
+
expected: "(__type | __type.o1 | __type.o2 | __type.o3)",
|
|
412
|
+
value: input
|
|
413
|
+
}))(input, "$input", true);
|
|
414
|
+
const success = 0 === errors.length;
|
|
415
|
+
return {
|
|
416
|
+
success,
|
|
417
|
+
errors,
|
|
418
|
+
data: success ? input : undefined
|
|
419
|
+
} as any;
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
success: true,
|
|
423
|
+
errors: [],
|
|
424
|
+
data: input
|
|
425
|
+
} as any;
|
|
426
|
+
}; const __prune = (input: CookbookSubscribeEmits): void => {
|
|
427
|
+
if ("object" === typeof input && null !== input)
|
|
428
|
+
$pu0(input);
|
|
429
|
+
}; return (input: any): typia.IValidation<CookbookSubscribeEmits> => {
|
|
430
|
+
const result = __validate(input);
|
|
431
|
+
if (result.success)
|
|
432
|
+
__prune(input);
|
|
433
|
+
return result;
|
|
434
|
+
}; })()(results);
|
|
435
|
+
let error = null;
|
|
436
|
+
if (!checkResult.success) {
|
|
437
|
+
const error: any = checkResult.errors.at(0)!;
|
|
438
|
+
error.message = `The "cookbook.toml" format is incorrect, [${error.path.slice(7)}] should be ${error.expected}, but it is actually ${error.value}. You may be missing some properties in the configuration item, or adding some properties that will not be used. If you have extra properties, these properties are likely due to a misspelling.`;
|
|
439
|
+
Error.captureStackTrace(error);
|
|
440
|
+
results = null;
|
|
441
|
+
}
|
|
442
|
+
return [error, results];
|
|
443
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The content of this file is automatically generated by Typia.
|
|
3
|
+
* It can be edited in the /packages/cookbook-dto/src/* file, and each time you run bun run dev, the generated file will be synced to another location based on the content of the /develop.ts.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type CookbookOptions = {
|
|
7
|
+
projects: Record<string, {
|
|
8
|
+
type: "milkio" | "other";
|
|
9
|
+
port: number;
|
|
10
|
+
start: Array<string>;
|
|
11
|
+
build: Array<string>;
|
|
12
|
+
lazyRoutes?: boolean;
|
|
13
|
+
typiaMode?: "generation" | "bundler";
|
|
14
|
+
significant?: Array<string>;
|
|
15
|
+
insignificant?: Array<string>;
|
|
16
|
+
}>;
|
|
17
|
+
general: {
|
|
18
|
+
cookbookPort: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export type CookbookActionParams = {
|
|
22
|
+
type: "milkio@logger";
|
|
23
|
+
log: Array<any>;
|
|
24
|
+
};
|
|
25
|
+
export type CookbookSubscribeEmits = {
|
|
26
|
+
type: "workers@stdout";
|
|
27
|
+
key: string;
|
|
28
|
+
chunk: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: "workers@state";
|
|
31
|
+
key: string;
|
|
32
|
+
state: "running" | "stopped";
|
|
33
|
+
code: number | null | "kill" | "running";
|
|
34
|
+
} | {
|
|
35
|
+
type: "watcher@change";
|
|
36
|
+
event: "rename" | "change";
|
|
37
|
+
path: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "milkio@logger";
|
|
40
|
+
log: Array<any>;
|
|
41
|
+
};
|