1.2.0 • Published 7 months ago

bunex v1.2.0

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

Bunex Setup

const bunex = new Bunex()
bunex.cors()
bunex.timeout('1m')
bunex.use(({ req, res }) => {})
bunex.useApollo({ resolvers: '**/resolvers/*.resolver.ts' })
bunex.useRoutes({ expose: '/routes', routes: '**/routes/*.route.ts' })
bunex.useTypegoose({ uri, dbName })
bunex.runner.limit(1000).concurrency(2)
bunex.runner.bypassheader('BYPASS', 'TRUE')
bunex.runner.safepasstime('30s')
bunex.status.maxtime('10s').maxstack(1000)
bunex.status.extrastatus({ server: 'Servername' })
bunex.status.extratraffic(ctx => ({ user: ctx.user }))
bunex.status.dump(data => console.log(data))
bunex.listen(5000)

Collections

export class CatusCollection {
  @prop({ type: String }) public name!: string
  @prop({ type: String }) public sex!: string
  @prop({ type: String }) public location!: string
}

export const CatusModel = getModelForClass(CatusCollection)

Resolvers

interface UserCtx {
  name: string
  age: number
  sex: 'male' | 'female'
}

@ObjectType()
class Catus {
  @Field(() => String) name!: string
  @Field(() => Int) age!: number
  @Field(() => String) sex!: string
}

@Resolver()
export default class CatusResolver {
  @Query(() => Catus)
  @Use<BunexContext<{}, UserCtx>>(({ req, ctx }) => {
    ctx.user = { name: 'Jawad', age: 23, sex: 'male' }
  })
  async catus(
    @Context() ctx: BunexContext<{}, UserCtx>,
    @User() user: UserCtx,
    @Arg('name', () => String) name: string
  ): Promise<Catus> {
    return { ...user }
  }
}

Routes

export const route = new Route(() => Fields)
route.method('POST')
route.prefix('catus')
route.timeout('2m')
route.bunnycdn().perma().secure()
route.use(({ ctx }) => {
  ctx.user = { name: 'Nova', age: 22 }
})

class Fields {
  @Param(String, { bunnysecure: true }) name!: string
  @Query(String) que!: string
  @Body(String) body!: string
  @File() file!: BunexFile
  @Files(3) files!: BunexFile[]
}

route.serve(async ({ ctx, fields, res }) => {
  return { ...ctx }
})