@milkio/astra 1.0.0-alpha.41 → 1.0.0-alpha.43
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/index.ts +154 -152
- package/package.json +5 -5
- package/tsconfig.json +8 -8
- package/utils/cookbook-dto-checks.ts +18 -18
- package/utils/cookbook-dto-types.ts +13 -13
package/index.ts
CHANGED
|
@@ -1,258 +1,260 @@
|
|
|
1
|
-
import { join, dirname } from
|
|
2
|
-
import { fileURLToPath } from
|
|
3
|
-
import { existsSync } from
|
|
4
|
-
import { readFile } from
|
|
5
|
-
import { cwd } from
|
|
6
|
-
import { load } from
|
|
7
|
-
import { TSON } from
|
|
8
|
-
import { format } from
|
|
9
|
-
import type { CookbookOptions } from
|
|
1
|
+
import { join, dirname } from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { existsSync } from 'node:fs'
|
|
4
|
+
import { readFile } from 'node:fs/promises'
|
|
5
|
+
import { cwd } from 'node:process'
|
|
6
|
+
import { load } from 'js-toml'
|
|
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
|
-
export
|
|
12
|
-
stargate: { $types: any
|
|
13
|
-
bootstrap: () => Promise<Record<string, any
|
|
14
|
-
}
|
|
11
|
+
export interface AstraOptionsInit {
|
|
12
|
+
stargate: { $types: any, execute: any, ping: any, cookbook: any }
|
|
13
|
+
bootstrap: () => Promise<Record<string, any>>
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
type GeneratorGeneric<T> = T extends AsyncGenerator<infer I> ? I : never
|
|
16
|
+
type GeneratorGeneric<T> = T extends AsyncGenerator<infer I> ? I : never
|
|
17
17
|
|
|
18
|
-
type Mixin<T, U> = U & Omit<T, keyof U
|
|
18
|
+
type Mixin<T, U> = U & Omit<T, keyof U>
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
headers?: Record<string, string
|
|
22
|
-
timeout?: number
|
|
23
|
-
type?:
|
|
24
|
-
}
|
|
20
|
+
interface ExecuteOptions {
|
|
21
|
+
headers?: Record<string, string>
|
|
22
|
+
timeout?: number
|
|
23
|
+
type?: 'action' | 'stream'
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
interface ExecuteResultsOption { executeId: string }
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
logger: Logger
|
|
30
|
-
}
|
|
28
|
+
interface Context {
|
|
29
|
+
logger: Logger
|
|
30
|
+
}
|
|
31
31
|
|
|
32
|
-
|
|
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
|
-
}
|
|
32
|
+
interface 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
|
+
}
|
|
39
39
|
|
|
40
|
-
type Log = [string /* executeId */,
|
|
40
|
+
type Log = [string /* executeId */, '[DEBUG]' | '[INFO]' | '[WARN]' | '[ERROR]' | '[RESPONSE]', string, string, ...Array<unknown>]
|
|
41
41
|
|
|
42
|
-
type Reject = (description: string, ...params: Array<unknown>) => Error
|
|
42
|
+
type Reject = (description: string, ...params: Array<unknown>) => Error
|
|
43
43
|
|
|
44
|
-
export
|
|
45
|
-
if (!existsSync(join(cwd(),
|
|
46
|
-
|
|
44
|
+
export async function createAstra<AstraOptions extends AstraOptionsInit, Generated extends AstraOptions['stargate']['$types']['generated']>(astraOptions: AstraOptions) {
|
|
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.`)
|
|
46
|
+
const cookbookOptions = load((await readFile(join(cwd(), 'cookbook.toml'))).toString()) as CookbookOptions
|
|
47
47
|
// wait for all milkio projects to start and can be accessed
|
|
48
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
|
|
49
49
|
await Promise.all([
|
|
50
50
|
...(() => {
|
|
51
|
-
const projectStatus = new Map<string, { promise: Promise<undefined
|
|
51
|
+
const projectStatus = new Map<string, { promise: Promise<undefined>, resolve: (value?: undefined | PromiseLike<undefined>) => void, reject: (reason?: any) => void }>()
|
|
52
52
|
for (const projectName in cookbookOptions.projects) {
|
|
53
|
-
const project = cookbookOptions.projects[projectName]
|
|
54
|
-
if (project.type !==
|
|
55
|
-
projectStatus.set(projectName, withResolvers())
|
|
56
|
-
let counter = 256
|
|
53
|
+
const project = cookbookOptions.projects[projectName]
|
|
54
|
+
if (project.type !== 'milkio') continue
|
|
55
|
+
projectStatus.set(projectName, withResolvers())
|
|
56
|
+
let counter = 256
|
|
57
57
|
let timer: Timer | null = setInterval(async () => {
|
|
58
58
|
if (--counter <= 0) {
|
|
59
|
-
clearInterval(timer!)
|
|
60
|
-
timer = null
|
|
61
|
-
console.warn(`[cookbook] Your project ${projectName} (http://localhost:${project.port}/) HTTP server hasn't started for too long.`)
|
|
62
|
-
projectStatus.get(projectName)!.resolve(undefined)
|
|
63
|
-
return
|
|
59
|
+
clearInterval(timer!)
|
|
60
|
+
timer = null
|
|
61
|
+
console.warn(`[cookbook] Your project ${projectName} (http://localhost:${project.port}/) HTTP server hasn't started for too long.`)
|
|
62
|
+
projectStatus.get(projectName)!.resolve(undefined)
|
|
63
|
+
return
|
|
64
64
|
}
|
|
65
65
|
try {
|
|
66
|
-
const response = await fetchWithTimeout(`http://localhost:${project.port}/generate_204`, { method:
|
|
66
|
+
const response = await fetchWithTimeout(`http://localhost:${project.port}/generate_204`, { method: 'HEAD', timeout: 1024 })
|
|
67
67
|
if (response.status === 204) {
|
|
68
|
-
if (timer) clearTimeout(timer)
|
|
69
|
-
timer = null
|
|
70
|
-
return projectStatus.get(projectName)!.resolve(undefined)
|
|
68
|
+
if (timer) clearTimeout(timer)
|
|
69
|
+
timer = null
|
|
70
|
+
return projectStatus.get(projectName)!.resolve(undefined)
|
|
71
71
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
72
|
+
}
|
|
73
|
+
catch (error) {}
|
|
74
|
+
}, 100)
|
|
74
75
|
}
|
|
75
|
-
return Array.from(projectStatus.values()).map(
|
|
76
|
+
return Array.from(projectStatus.values()).map(v => v.promise)
|
|
76
77
|
})(),
|
|
77
|
-
])
|
|
78
|
+
])
|
|
78
79
|
|
|
79
|
-
type Execute = <Path extends keyof Generated[
|
|
80
|
+
type Execute = <Path extends keyof Generated['routeSchema']>(
|
|
80
81
|
path: Path,
|
|
81
82
|
options?: Mixin<
|
|
82
83
|
ExecuteOptions,
|
|
83
84
|
| {
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
params?: Generated['routeSchema'][Path]['types']['params']
|
|
86
|
+
}
|
|
86
87
|
| {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
params?: Partial<Generated['routeSchema'][Path]['types']['params']>
|
|
89
|
+
generateParams: true
|
|
90
|
+
}
|
|
90
91
|
>,
|
|
91
92
|
) => Promise<
|
|
92
|
-
Generated[
|
|
93
|
+
Generated['routeSchema'][Path]['types']['🐣'] extends boolean
|
|
93
94
|
? // action
|
|
94
|
-
[Partial<Generated[
|
|
95
|
+
[Partial<Generated['rejectCode']>, null, ExecuteResultsOption] | [null, Generated['routeSchema'][Path]['types']['result'], ExecuteResultsOption]
|
|
95
96
|
: // stream
|
|
96
|
-
[Partial<Generated[
|
|
97
|
-
|
|
97
|
+
[Partial<Generated['rejectCode']>, null, ExecuteResultsOption] | [null, AsyncGenerator<[Partial<Generated['rejectCode']>, null] | [null, GeneratorGeneric<Generated['routeSchema'][Path]['types']['result']>], ExecuteResultsOption>]
|
|
98
|
+
>
|
|
98
99
|
|
|
99
100
|
type MirrorWorld = Mixin<
|
|
100
|
-
Awaited<ReturnType<AstraOptions[
|
|
101
|
+
Awaited<ReturnType<AstraOptions['bootstrap']>>,
|
|
101
102
|
{
|
|
102
|
-
paths: { cwd: string
|
|
103
|
-
execute: Execute
|
|
103
|
+
paths: { cwd: string, milkio: string, generated: string }
|
|
104
|
+
execute: Execute
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
+
>
|
|
106
107
|
|
|
107
108
|
return {
|
|
108
109
|
options: astraOptions,
|
|
109
110
|
async createMirrorWorld(importMetaUrl: string): Promise<[Context, Reject, MirrorWorld]> {
|
|
110
|
-
const thisFilePath = join(fileURLToPath(importMetaUrl))
|
|
111
|
-
const thisFileDirPath = join(dirname(thisFilePath)).replaceAll(
|
|
112
|
-
const thisFileDirPathArr = thisFileDirPath.split(
|
|
113
|
-
let projectName: string =
|
|
111
|
+
const thisFilePath = join(fileURLToPath(importMetaUrl))
|
|
112
|
+
const thisFileDirPath = join(dirname(thisFilePath)).replaceAll('\\', '/')
|
|
113
|
+
const thisFileDirPathArr = thisFileDirPath.split('/')
|
|
114
|
+
let projectName: string = ''
|
|
114
115
|
|
|
115
116
|
await (async () => {
|
|
116
|
-
let isProjectsDirectory = false
|
|
117
|
+
let isProjectsDirectory = false
|
|
117
118
|
for (let i = 0; i < thisFileDirPathArr.length; i++) {
|
|
118
|
-
if (thisFileDirPathArr[i] ===
|
|
119
|
-
isProjectsDirectory = true
|
|
120
|
-
continue
|
|
119
|
+
if (thisFileDirPathArr[i] === 'projects') {
|
|
120
|
+
isProjectsDirectory = true
|
|
121
|
+
continue
|
|
121
122
|
}
|
|
122
|
-
if (isProjectsDirectory === false) continue
|
|
123
|
-
projectName = thisFileDirPathArr[i]
|
|
124
|
-
break
|
|
123
|
+
if (isProjectsDirectory === false) continue
|
|
124
|
+
projectName = thisFileDirPathArr[i]
|
|
125
|
+
break
|
|
125
126
|
}
|
|
126
|
-
if (projectName ===
|
|
127
|
-
let projectNameChecked = false
|
|
127
|
+
if (projectName === '') throw new Error('Unable to determine the path of the current test, make sure the test is under a milkio project.')
|
|
128
|
+
let projectNameChecked = false
|
|
128
129
|
for (const projectNameForCookbookOptions in cookbookOptions.projects) {
|
|
129
130
|
if (projectNameForCookbookOptions === projectName) {
|
|
130
|
-
projectNameChecked = true
|
|
131
|
-
break
|
|
131
|
+
projectNameChecked = true
|
|
132
|
+
break
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
|
-
if (projectNameChecked === false) throw new Error(`Project name "${projectName}" not found in "cookbook.toml" in "projects.${projectName}".`)
|
|
135
|
-
})()
|
|
135
|
+
if (projectNameChecked === false) throw new Error(`Project name "${projectName}" not found in "cookbook.toml" in "projects.${projectName}".`)
|
|
136
|
+
})()
|
|
136
137
|
|
|
137
138
|
const paths = {
|
|
138
|
-
cwd: join(cwd(),
|
|
139
|
-
milkio: join(cwd(),
|
|
140
|
-
generated: join(cwd(),
|
|
141
|
-
}
|
|
139
|
+
cwd: join(cwd(), 'projects', projectName),
|
|
140
|
+
milkio: join(cwd(), 'projects', projectName, '.milkio'),
|
|
141
|
+
generated: join(cwd(), 'projects', projectName, '.milkio'),
|
|
142
|
+
}
|
|
142
143
|
|
|
143
|
-
const execute = async (path: Parameters<MirrorWorld[
|
|
144
|
-
|
|
144
|
+
const execute = async (path: Parameters<MirrorWorld['execute']>[0], optionsInit?: Parameters<MirrorWorld['execute']>[1]) => {
|
|
145
|
+
const options = (optionsInit as any) ?? {}
|
|
145
146
|
if (options?.generateParams === true) {
|
|
146
|
-
if (!options?.params) options.params = {}
|
|
147
|
-
options.params.$milkioGenerateParams =
|
|
147
|
+
if (!options?.params) options.params = {}
|
|
148
|
+
options.params.$milkioGenerateParams = 'enable'
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
const results = await this.options.stargate.cookbook.subscribe(`http://localhost:${cookbookOptions.general.cookbookPort}`)
|
|
151
|
+
const results = await this.options.stargate.cookbook.subscribe(`http://localhost:${cookbookOptions.general.cookbookPort}`)
|
|
151
152
|
void (async () => {
|
|
152
153
|
for await (const result of results) {
|
|
153
|
-
if (result.type !==
|
|
154
|
-
console.log(
|
|
154
|
+
if (result.type !== 'milkio@logger') continue
|
|
155
|
+
console.log('\n[MILKIO]', ...(result.log ?? []))
|
|
155
156
|
}
|
|
156
|
-
})()
|
|
157
|
+
})()
|
|
157
158
|
|
|
158
|
-
const response = await this.options.stargate.execute(path, options)
|
|
159
|
+
const response = await this.options.stargate.execute(path, options)
|
|
159
160
|
|
|
160
|
-
await new Promise(
|
|
161
|
-
context.logger.response(path as string, `\nerror - ${TSON.stringify(response[0])}`, `\nresult - ${typeof response[1]?.next ===
|
|
161
|
+
await new Promise(resolve => setTimeout(resolve, 40))
|
|
162
|
+
context.logger.response(path as string, `\nerror - ${TSON.stringify(response[0])}`, `\nresult - ${typeof response[1]?.next === 'function' ? 'AsyncGenerator' : TSON.stringify(response[1])}`)
|
|
162
163
|
|
|
163
|
-
return response
|
|
164
|
-
}
|
|
164
|
+
return response
|
|
165
|
+
}
|
|
165
166
|
|
|
166
|
-
const getNow = () => format(new Date(),
|
|
167
|
+
const getNow = () => format(new Date(), '(yyyy-MM-dd hh:mm:ss)')
|
|
167
168
|
const onLoggerInserting = (log: Log) => {
|
|
168
|
-
log = [...log]
|
|
169
|
-
log[0] = `\n${log[0]}` as any
|
|
170
|
-
console.log(...log)
|
|
171
|
-
return true
|
|
172
|
-
}
|
|
169
|
+
log = [...log]
|
|
170
|
+
log[0] = `\n${log[0]}` as any
|
|
171
|
+
console.log(...log)
|
|
172
|
+
return true
|
|
173
|
+
}
|
|
173
174
|
|
|
174
175
|
const context = {
|
|
175
176
|
logger: {
|
|
176
177
|
debug: (description: string, ...params: Array<unknown>): Log => {
|
|
177
|
-
const log: Log = [
|
|
178
|
-
onLoggerInserting(log)
|
|
179
|
-
return log
|
|
178
|
+
const log: Log = ['[TEST]', '[DEBUG]', description, getNow(), ...params]
|
|
179
|
+
onLoggerInserting(log)
|
|
180
|
+
return log
|
|
180
181
|
},
|
|
181
182
|
info: (description: string, ...params: Array<unknown>): Log => {
|
|
182
|
-
const log: Log = [
|
|
183
|
-
onLoggerInserting(log)
|
|
184
|
-
return log
|
|
183
|
+
const log: Log = ['[TEST]', '[INFO]', description, getNow(), ...params]
|
|
184
|
+
onLoggerInserting(log)
|
|
185
|
+
return log
|
|
185
186
|
},
|
|
186
187
|
warn: (description: string, ...params: Array<unknown>): Log => {
|
|
187
|
-
const log: Log = [
|
|
188
|
-
onLoggerInserting(log)
|
|
189
|
-
return log
|
|
188
|
+
const log: Log = ['[TEST]', '[WARN]', description, getNow(), ...params]
|
|
189
|
+
onLoggerInserting(log)
|
|
190
|
+
return log
|
|
190
191
|
},
|
|
191
192
|
error: (description: string, ...params: Array<unknown>): Log => {
|
|
192
|
-
const log: Log = [
|
|
193
|
-
onLoggerInserting(log)
|
|
194
|
-
return log
|
|
193
|
+
const log: Log = ['[TEST]', '[ERROR]', description, getNow(), ...params]
|
|
194
|
+
onLoggerInserting(log)
|
|
195
|
+
return log
|
|
195
196
|
},
|
|
196
197
|
response: (path: string, ...params: Array<unknown>): Log => {
|
|
197
|
-
const log: Log = [
|
|
198
|
-
onLoggerInserting(log)
|
|
199
|
-
return log
|
|
198
|
+
const log: Log = ['[TEST]', '[RESPONSE]', path, getNow(), ...params]
|
|
199
|
+
onLoggerInserting(log)
|
|
200
|
+
return log
|
|
200
201
|
},
|
|
201
202
|
},
|
|
202
|
-
} as Context
|
|
203
|
+
} as Context
|
|
203
204
|
|
|
204
205
|
const world = {
|
|
205
206
|
...(await astraOptions.bootstrap()),
|
|
206
207
|
paths,
|
|
207
208
|
execute,
|
|
208
|
-
} as any
|
|
209
|
+
} as any
|
|
209
210
|
|
|
210
211
|
const reject = (...params: Array<unknown>): Error => {
|
|
211
212
|
const output: Array<any> = [
|
|
212
|
-
|
|
213
|
+
'[REJECT]',
|
|
213
214
|
...params.map((param) => {
|
|
214
215
|
try {
|
|
215
|
-
const result = TSON.stringify(param)
|
|
216
|
-
return result
|
|
217
|
-
}
|
|
218
|
-
|
|
216
|
+
const result = TSON.stringify(param)
|
|
217
|
+
return result
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
return error?.toString?.() ?? typeof error
|
|
219
221
|
}
|
|
220
222
|
}),
|
|
221
|
-
]
|
|
222
|
-
console.log(...output)
|
|
223
|
+
]
|
|
224
|
+
console.log(...output)
|
|
223
225
|
for (let index = 1; index < output.length; index++) {
|
|
224
|
-
if (typeof output[index] ===
|
|
225
|
-
output[index] = output[index].toString()
|
|
226
|
+
if (typeof output[index] === 'object') {
|
|
227
|
+
output[index] = output[index].toString()
|
|
226
228
|
}
|
|
227
229
|
}
|
|
228
|
-
const message = output.join(
|
|
229
|
-
return new Error(message)
|
|
230
|
-
}
|
|
230
|
+
const message = output.join(' ')
|
|
231
|
+
return new Error(message)
|
|
232
|
+
}
|
|
231
233
|
|
|
232
|
-
return [context, reject, world]
|
|
234
|
+
return [context, reject, world]
|
|
233
235
|
},
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
236
238
|
|
|
237
239
|
export async function fetchWithTimeout(url: string, options: FetchRequestInit & { timeout?: number } = {}) {
|
|
238
|
-
const { timeout = 8000 } = options
|
|
240
|
+
const { timeout = 8000 } = options
|
|
239
241
|
|
|
240
|
-
const controller = new AbortController()
|
|
241
|
-
const id = setTimeout(() => controller.abort(), timeout)
|
|
242
|
+
const controller = new AbortController()
|
|
243
|
+
const id = setTimeout(() => controller.abort(), timeout)
|
|
242
244
|
const response = await fetch(url, {
|
|
243
245
|
...options,
|
|
244
246
|
signal: controller.signal,
|
|
245
|
-
})
|
|
246
|
-
clearTimeout(id)
|
|
247
|
-
return response
|
|
247
|
+
})
|
|
248
|
+
clearTimeout(id)
|
|
249
|
+
return response
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
function withResolvers<T = any>(): PromiseWithResolvers<T> {
|
|
251
|
-
let resolve: PromiseWithResolvers<T>[
|
|
252
|
-
let reject: PromiseWithResolvers<T>[
|
|
253
|
+
let resolve: PromiseWithResolvers<T>['resolve']
|
|
254
|
+
let reject: PromiseWithResolvers<T>['reject']
|
|
253
255
|
const promise = new Promise<T>((res, rej) => {
|
|
254
|
-
resolve = res
|
|
255
|
-
reject = rej
|
|
256
|
-
})
|
|
257
|
-
return { promise, resolve: resolve!, reject: reject! }
|
|
256
|
+
resolve = res
|
|
257
|
+
reject = rej
|
|
258
|
+
})
|
|
259
|
+
return { promise, resolve: resolve!, reject: reject! }
|
|
258
260
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkio/astra",
|
|
3
|
-
"module": "index.ts",
|
|
4
|
-
"version": "1.0.0-alpha.41",
|
|
5
3
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
},
|
|
4
|
+
"version": "1.0.0-alpha.43",
|
|
5
|
+
"module": "index.ts",
|
|
9
6
|
"dependencies": {
|
|
10
7
|
"@southern-aurora/tson": "*",
|
|
11
8
|
"date-fns": "^4.1.0",
|
|
12
9
|
"js-toml": "^1.0.0"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@types/bun": "latest"
|
|
13
13
|
}
|
|
14
14
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"jsx": "react-jsx",
|
|
3
5
|
// Enable latest features
|
|
4
6
|
"lib": ["ESNext", "DOM"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "ESNext",
|
|
7
7
|
"moduleDetection": "force",
|
|
8
|
-
"
|
|
9
|
-
"allowJs": true,
|
|
8
|
+
"module": "ESNext",
|
|
10
9
|
|
|
11
10
|
// Bundler mode
|
|
12
11
|
"moduleResolution": "bundler",
|
|
13
12
|
"allowImportingTsExtensions": true,
|
|
14
|
-
"
|
|
15
|
-
"noEmit": true,
|
|
13
|
+
"allowJs": true,
|
|
16
14
|
|
|
17
15
|
// Best practices
|
|
18
16
|
"strict": true,
|
|
19
|
-
"skipLibCheck": true,
|
|
20
17
|
"noFallthroughCasesInSwitch": true,
|
|
21
18
|
|
|
19
|
+
"noPropertyAccessFromIndexSignature": false,
|
|
22
20
|
// Some stricter flags (disabled by default)
|
|
23
21
|
"noUnusedLocals": false,
|
|
24
22
|
"noUnusedParameters": false,
|
|
25
|
-
"
|
|
23
|
+
"noEmit": true,
|
|
24
|
+
"verbatimModuleSyntax": true,
|
|
25
|
+
"skipLibCheck": true
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
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
4
|
*/
|
|
5
5
|
|
|
6
|
-
import typia from
|
|
7
|
-
import type { CookbookActionParams, CookbookOptions, CookbookSubscribeEmits } from
|
|
8
|
-
export
|
|
6
|
+
import typia from 'typia';
|
|
7
|
+
import type { CookbookActionParams, CookbookOptions, CookbookSubscribeEmits } from './cookbook-dto-types';
|
|
8
|
+
export async function checkCookbookOptions(cookbookTomlParsed: any): Promise<[
|
|
9
9
|
Record<any, any> & {
|
|
10
10
|
message: string;
|
|
11
11
|
stack: string;
|
|
@@ -14,8 +14,8 @@ export const checkCookbookOptions = async (cookbookTomlParsed: any): Promise<[
|
|
|
14
14
|
] | [
|
|
15
15
|
null,
|
|
16
16
|
CookbookOptions
|
|
17
|
-
]>
|
|
18
|
-
|
|
17
|
+
]> {
|
|
18
|
+
const cookbookToml = { ...cookbookTomlParsed };
|
|
19
19
|
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) => {
|
|
20
20
|
if (["projects", "general"].some((prop: any) => key === prop))
|
|
21
21
|
return true;
|
|
@@ -206,7 +206,7 @@ export const checkCookbookOptions = async (cookbookTomlParsed: any): Promise<[
|
|
|
206
206
|
data: input
|
|
207
207
|
} as any;
|
|
208
208
|
}; })()(cookbookTomlParsed);
|
|
209
|
-
|
|
209
|
+
const error = null;
|
|
210
210
|
if (!checkResult.success) {
|
|
211
211
|
const error: any = checkResult.errors.at(0)!;
|
|
212
212
|
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.`;
|
|
@@ -214,8 +214,8 @@ export const checkCookbookOptions = async (cookbookTomlParsed: any): Promise<[
|
|
|
214
214
|
cookbookTomlParsed = null;
|
|
215
215
|
}
|
|
216
216
|
return [error, cookbookToml];
|
|
217
|
-
}
|
|
218
|
-
export
|
|
217
|
+
}
|
|
218
|
+
export async function checkCookbookActionParams(resultsRaw: any): Promise<[
|
|
219
219
|
Record<any, any> & {
|
|
220
220
|
message: string;
|
|
221
221
|
stack: string;
|
|
@@ -224,10 +224,10 @@ export const checkCookbookActionParams = async (resultsRaw: any): Promise<[
|
|
|
224
224
|
] | [
|
|
225
225
|
null,
|
|
226
226
|
CookbookActionParams
|
|
227
|
-
]>
|
|
227
|
+
]> {
|
|
228
228
|
let results = { ...resultsRaw };
|
|
229
|
-
if (typeof Bun ===
|
|
230
|
-
throw new Error(
|
|
229
|
+
if (typeof Bun === 'undefined')
|
|
230
|
+
throw new Error('Bun is not defined');
|
|
231
231
|
const checkResult = (() => { const $throws = (typia.misc.validatePrune as any).throws; const $io0 = (input: any): boolean => "milkio@logger" === input.type && Array.isArray(input.log); const $io1 = (input: any): boolean => "milkio@template" === input.type && "string" === typeof input.name && "string" === typeof input.fsPath && "string" === typeof input.template; const $iu0 = (input: any): any => (() => {
|
|
232
232
|
if ("milkio@logger" === input.type)
|
|
233
233
|
return $io0(input);
|
|
@@ -326,7 +326,7 @@ export const checkCookbookActionParams = async (resultsRaw: any): Promise<[
|
|
|
326
326
|
__prune(input);
|
|
327
327
|
return result;
|
|
328
328
|
}; })()(resultsRaw);
|
|
329
|
-
|
|
329
|
+
const error = null;
|
|
330
330
|
if (!checkResult.success) {
|
|
331
331
|
const error: any = checkResult.errors.at(0)!;
|
|
332
332
|
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.`;
|
|
@@ -334,8 +334,8 @@ export const checkCookbookActionParams = async (resultsRaw: any): Promise<[
|
|
|
334
334
|
results = null;
|
|
335
335
|
}
|
|
336
336
|
return [error, results];
|
|
337
|
-
}
|
|
338
|
-
export
|
|
337
|
+
}
|
|
338
|
+
export async function checkCookbookSubscribeEmits(results: any): Promise<[
|
|
339
339
|
Record<any, any> & {
|
|
340
340
|
message: string;
|
|
341
341
|
stack: string;
|
|
@@ -344,8 +344,8 @@ export const checkCookbookSubscribeEmits = async (results: any): Promise<[
|
|
|
344
344
|
] | [
|
|
345
345
|
null,
|
|
346
346
|
CookbookSubscribeEmits
|
|
347
|
-
]>
|
|
348
|
-
const typia = await import(
|
|
347
|
+
]> {
|
|
348
|
+
const typia = await import('typia');
|
|
349
349
|
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 => (() => {
|
|
350
350
|
if ("workers@stdout" === input.type)
|
|
351
351
|
return $io0(input);
|
|
@@ -492,7 +492,7 @@ export const checkCookbookSubscribeEmits = async (results: any): Promise<[
|
|
|
492
492
|
__prune(input);
|
|
493
493
|
return result;
|
|
494
494
|
}; })()(results);
|
|
495
|
-
|
|
495
|
+
const error = null;
|
|
496
496
|
if (!checkResult.success) {
|
|
497
497
|
const error: any = checkResult.errors.at(0)!;
|
|
498
498
|
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.`;
|
|
@@ -500,4 +500,4 @@ export const checkCookbookSubscribeEmits = async (results: any): Promise<[
|
|
|
500
500
|
results = null;
|
|
501
501
|
}
|
|
502
502
|
return [error, results];
|
|
503
|
-
}
|
|
503
|
+
}
|
|
@@ -3,15 +3,15 @@
|
|
|
3
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
4
|
*/
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export interface CookbookOptions {
|
|
7
7
|
projects: Record<string, {
|
|
8
|
-
type:
|
|
8
|
+
type: 'milkio' | 'other';
|
|
9
9
|
port: number;
|
|
10
10
|
start: Array<string>;
|
|
11
11
|
build: Array<string>;
|
|
12
12
|
watch?: boolean;
|
|
13
13
|
lazyRoutes?: boolean;
|
|
14
|
-
typiaMode?:
|
|
14
|
+
typiaMode?: 'generation' | 'bundler';
|
|
15
15
|
significant?: Array<string>;
|
|
16
16
|
insignificant?: Array<string>;
|
|
17
17
|
}>;
|
|
@@ -19,30 +19,30 @@ export type CookbookOptions = {
|
|
|
19
19
|
start: string;
|
|
20
20
|
cookbookPort: number;
|
|
21
21
|
};
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
23
|
export type CookbookActionParams = {
|
|
24
|
-
type:
|
|
24
|
+
type: 'milkio@logger';
|
|
25
25
|
log: Array<any>;
|
|
26
26
|
} | {
|
|
27
|
-
type:
|
|
27
|
+
type: 'milkio@template';
|
|
28
28
|
name: string;
|
|
29
29
|
fsPath: string;
|
|
30
30
|
template: string;
|
|
31
31
|
};
|
|
32
32
|
export type CookbookSubscribeEmits = {
|
|
33
|
-
type:
|
|
33
|
+
type: 'workers@stdout';
|
|
34
34
|
key: string;
|
|
35
35
|
chunk: string;
|
|
36
36
|
} | {
|
|
37
|
-
type:
|
|
37
|
+
type: 'workers@state';
|
|
38
38
|
key: string;
|
|
39
|
-
state:
|
|
40
|
-
code: number | null |
|
|
39
|
+
state: 'running' | 'stopped';
|
|
40
|
+
code: number | null | 'kill' | 'running';
|
|
41
41
|
} | {
|
|
42
|
-
type:
|
|
43
|
-
event:
|
|
42
|
+
type: 'watcher@change';
|
|
43
|
+
event: 'rename' | 'change';
|
|
44
44
|
path: string;
|
|
45
45
|
} | {
|
|
46
|
-
type:
|
|
46
|
+
type: 'milkio@logger';
|
|
47
47
|
log: Array<any>;
|
|
48
48
|
};
|