npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@fncdev/route-composer

v1.0.21

Published

Generate a routing layer for an application from decorated controllers.

Readme

Installation

Install with npm

npm install @fncdev/route-composer

Or yarn

yarn add @fncdev/route-composer

About

this plugin used for well documented, typed, easy to use application creation

Quick Start

initialize composer instance


import { routeComposer, TPaths } from '@fncdev/route-composer'

const containerFiles: TPaths = {
  asClass: ['./controller/*.ts'],
}

export const routeComposerInstance = routeComposer({ containerFiles })

routeComposer properties

| Name | Description | | ----------------- | ----------- | | containerFiles | glob path to the modules for awilix di container: asClass , asValue |

routeComposerInstance returned methods and properties

| Name | Description | | ----------------- | ----------- | | renderRoutes | fastify plugin | | container | awilix container |

register plugin

  fastify.register(routeComposerInstance.renderRoutes, {
    path: './controller/*.ts',
  })

decorate controller that match glob path


export class User {
 @DataProp<string>({ required: true })
 name: string
}


class Params {
 @DataProp<number>({ required: true })
 id: number
}

@Controller('/test')
export default class TestController {
  constructor() {
    autoBind(this)
  }
  
  @Get('/users')
  async get(@Params params: Params): Promise<SuccessResponse<User>> {
    return { statusCode: httpStatus.OK, response: { name: 'test' } }
  }
  
}

Decorators

Route decorators

@Controller

required decorator(add controller to plugin) with base path



@Controller('/path') // 
class TestController {
  @Get('/') // get http method
  get() {}


}

HTTP Methods

@Controller('/path') 
class TestController {
  @Get('/') // get http method
  get() {}

  @Post('/')
  post() {}

  @Put('/:id')
  put() {}

    
  @Patch('/')
  patch() {}

  @Head('/')
  head() {}

  @Options('/')
  options() {}

  @Delete('/')
  deleteOne() {}
}

@Guard

auth middleware function for authorized requests return user object that can be cached by @User param decorator


@Guard(guard)
class TestController {
  @Get('/') 
  get(@User user: UserType) {}
    
}

@Roles

access roles that will be used in @Guard function(optional)


@Guard(guard) 
@Controller('/path') 
class TestController {
    
  @Post('/')
  @Roles(['testRole'])
  post() {}


}

@ApiResponse

fastify schema response decorator


@Guard(guard) 
@Controller('/path')
class TestController {
    
    @Patch('/')
    @ApiResponse({ statusCode: 404, type: FailedResponse })
    patch() {}
    
    // array
    @Get('/')
    @ApiResponse({ statusCode: 404, type: User, isArray: true })
    patch() {}
    
}

@RouteOptions

fastify router object additional options

@Controller('/path')
class TestController {
    
  @Post('/')
  @RoutesOptions({ attachValidation: false, exposeHeadRoute: false })
  post() {}
}

Param decorators

use @Query , @Body, @Params , @Headers decorators to enable swagger documentation

class TestController {
  get(@Request req: object, @Response res: object) {}

  post(@Headers headers: object, @Query query: object, @Body body: object) {}

  put(@Params params: object, @User user: string) {}
}

Parser decorators

@ObjectOptions

ajv object validation additional properties

@ObjectOptions({ additionalProperties: true, maxProperties: 1}) 
class Test {}

@DataProp


class Test {
@DataProp<string>()
data: string
}

array validation require type definition in items property

  class Test {
      @DataProp<AnotherDecoratedObject[]>({ required: true, items: { type: AnotherDecoratedObject }, maxItems: 1 })
      data: AnotherDecoratedObject[]
    }

swagger props also supported

    class Test {
      @DataProp<string>({ required: true, example: 'some string' })
      data: string
}

@NativeAJV

you can also use native schema ajv validation decorator


class Test {
  @NativeAJV<string>({ type: 'string' }) 
  data: string
}

to set required combine with @DataProp

class Test {
@NativeAJV<string>({ type: 'string' })
@DataProp<string>({ required: true })
data: string
}