Skip to content

Commit c0330c0

Browse files
committed
test(@sirutils/wizard): reverst
1 parent d207972 commit c0330c0

File tree

4 files changed

+88
-55
lines changed

4 files changed

+88
-55
lines changed

packages/wizard/test/app.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
import './handler'
2-
import './middlewares/auth'
32
import './services/users'
3+
import './services/mails'
44
import './wizard'
5+
6+
// import fs from 'node:fs'
7+
// import { logger } from '../src/internal/logger'
8+
// import { wizard } from './wizard'
9+
10+
// const result = await wizard.api.call(
11+
// 'users@0.1.1#create',
12+
// {
13+
// name: 'alice',
14+
// },
15+
// {
16+
// stream: [fs.createReadStream('.env'), fs.createReadStream('tsconfig.json')],
17+
// }
18+
// )
19+
20+
// logger.log(result)

packages/wizard/test/middlewares/auth.ts

-46
This file was deleted.
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { unwrap } from '@sirutils/core'
2+
3+
import { parsePlainTextFile } from '../../src/utils/parsers'
4+
import { wizard } from '../wizard'
5+
6+
const mailsService = await wizard.api.service({
7+
name: 'mails',
8+
version: '0.1.1',
9+
description: 'mails api',
10+
11+
actions: {
12+
test: wizard.api.createAction(
13+
{
14+
body: {
15+
name: 'string',
16+
},
17+
queries: {
18+
id: 'string',
19+
},
20+
rest: true,
21+
stream: true,
22+
multipart: true,
23+
},
24+
async ctx => {
25+
if (ctx.streams) {
26+
for (const [stream, options] of ctx.streams) {
27+
// biome-ignore lint/style/noNonNullAssertion: <explanation>
28+
ctx.logger.info(unwrap(await parsePlainTextFile(stream!)), options)
29+
}
30+
}
31+
32+
return 'as' as const
33+
}
34+
),
35+
},
36+
37+
created: ctx => {
38+
ctx.logger.info('hi')
39+
40+
return true
41+
},
42+
})
43+
44+
declare global {
45+
// biome-ignore lint/style/noNamespace: <explanation>
46+
namespace Sirutils {
47+
interface WizardServices {
48+
'mails@0.1.1': typeof mailsService
49+
}
50+
}
51+
}

packages/wizard/test/services/users.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,42 @@ import { wizard } from '../wizard'
22

33
const usersService = await wizard.api.service({
44
name: 'users',
5-
version: '0.0.1',
5+
version: '0.1.1',
66
description: 'users api',
77

88
actions: {
9-
get: wizard.api.createAction(
9+
create: wizard.api.createAction(
1010
{
11-
rest: 'GET /',
12-
middlewares: ['auth'],
11+
body: {
12+
name: 'string',
13+
},
14+
rest: true,
15+
stream: true,
16+
multipart: true,
1317
},
1418
ctx => {
15-
//biome-ignore lint/suspicious/noConsole: <explanation>
16-
console.log(ctx.share?.user)
19+
if (ctx.streams) {
20+
// biome-ignore lint/suspicious/noConsole: <explanation>
21+
console.log(ctx.streams)
22+
}
1723

18-
return JSON.stringify(ctx.share?.user)
24+
return 'sa' as const
1925
}
2026
),
2127
},
28+
29+
created: ctx => {
30+
ctx.logger.info('hi')
31+
32+
return true
33+
},
2234
})
2335

2436
declare global {
2537
// biome-ignore lint/style/noNamespace: <explanation>
2638
namespace Sirutils {
2739
interface WizardServices {
28-
'users@0.0.1': typeof usersService
40+
'users@0.1.1': typeof usersService
2941
}
3042
}
3143
}

0 commit comments

Comments
 (0)