Skip to content

Commit

Permalink
test(@sirutils/wizard): reverst
Browse files Browse the repository at this point in the history
  • Loading branch information
siaeyy committed Oct 19, 2024
1 parent d207972 commit c0330c0
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 55 deletions.
18 changes: 17 additions & 1 deletion packages/wizard/test/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import './handler'
import './middlewares/auth'
import './services/users'
import './services/mails'
import './wizard'

// import fs from 'node:fs'
// import { logger } from '../src/internal/logger'
// import { wizard } from './wizard'

// const result = await wizard.api.call(
// '[email protected]#create',
// {
// name: 'alice',
// },
// {
// stream: [fs.createReadStream('.env'), fs.createReadStream('tsconfig.json')],
// }
// )

// logger.log(result)
46 changes: 0 additions & 46 deletions packages/wizard/test/middlewares/auth.ts

This file was deleted.

51 changes: 51 additions & 0 deletions packages/wizard/test/services/mails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { unwrap } from '@sirutils/core'

import { parsePlainTextFile } from '../../src/utils/parsers'
import { wizard } from '../wizard'

const mailsService = await wizard.api.service({
name: 'mails',
version: '0.1.1',
description: 'mails api',

actions: {
test: wizard.api.createAction(
{
body: {
name: 'string',
},
queries: {
id: 'string',
},
rest: true,
stream: true,
multipart: true,
},
async ctx => {
if (ctx.streams) {
for (const [stream, options] of ctx.streams) {
// biome-ignore lint/style/noNonNullAssertion: <explanation>
ctx.logger.info(unwrap(await parsePlainTextFile(stream!)), options)
}
}

return 'as' as const
}
),
},

created: ctx => {
ctx.logger.info('hi')

return true
},
})

declare global {
// biome-ignore lint/style/noNamespace: <explanation>
namespace Sirutils {
interface WizardServices {
'[email protected]': typeof mailsService
}
}
}
28 changes: 20 additions & 8 deletions packages/wizard/test/services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,42 @@ import { wizard } from '../wizard'

const usersService = await wizard.api.service({
name: 'users',
version: '0.0.1',
version: '0.1.1',
description: 'users api',

actions: {
get: wizard.api.createAction(
create: wizard.api.createAction(
{
rest: 'GET /',
middlewares: ['auth'],
body: {
name: 'string',
},
rest: true,
stream: true,
multipart: true,
},
ctx => {
//biome-ignore lint/suspicious/noConsole: <explanation>
console.log(ctx.share?.user)
if (ctx.streams) {
// biome-ignore lint/suspicious/noConsole: <explanation>
console.log(ctx.streams)
}

return JSON.stringify(ctx.share?.user)
return 'sa' as const
}
),
},

created: ctx => {
ctx.logger.info('hi')

return true
},
})

declare global {
// biome-ignore lint/style/noNamespace: <explanation>
namespace Sirutils {
interface WizardServices {
'users@0.0.1': typeof usersService
'users@0.1.1': typeof usersService
}
}
}

0 comments on commit c0330c0

Please sign in to comment.