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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cheetah.js/core

v0.1.35

Published

Cheetah.js is a framework for building web applications object oriented with TypeScript and Bun.sh.

Downloads

276

Readme

Cheetah.js

Cheetah.js is a simple object-oriented framework for Bun still in development. Check the ORM documentation here.

Menu

Installation

For install Cheetah.js, run the command below:

bun install @cheetah.js/core

Your tsconfig.json should have the following settings:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Start the server

import { Cheetah } from '@cheetah.js/core';

new Cheetah().listen();

Controller and Routes

In Cheetah.js, all classes in dependency injection are considered providers, including controllers.

Example:

import { Controller, Get, Cheetah } from '@cheetah.js/core';

@Controller()
export class HomeController {
  @Get('/')
  index() {
    return 'Hello World!';
  }
}

new Cheetah({ 
    providers: [ HomeController ]
}).listen();

To receive parameters in the route, simply add the ":" before the parameter name. And to receive it in the method, just use the @Param decorator.

import { Controller, Get } from '@cheetah.js/core';

@Controller()
export class HomeController {
  @Get(':name')
  index(@Param('name') name: string) {
    return `Hello ${name}!`;
  }
}

Validation

Cheetah.js validates route parameters using class-validator. Simply add the DTO as a method parameter and Cheetah.js will validate the route parameters.

Exemplo:

import { Controller, Get, Query } from '@cheetah.js/core';

export class UserDto {
  @IsString()
  name: string;
}

@Controller()
export class HomeController {
  @Get()
  index(@Query() user: UserDto) {
    return `Hello ${user.name}!`;
  }
}

To configure the validator, simply pass the options in the Cheetah.js constructor:

import { Cheetah } from '@cheetah.js/core';

new Cheetah({ 
    validator: {
        whitelist: true
    }
}).listen();

Dependency injection

Cheetah.js provides support for dependency injection using the @Service decorator. The available scopes are Singleton (default), request and instance. You can define services to handle business logic and inject them into controllers or other services as needed.

Example:

import { Service } from '@cheetah.js/core';

@Service() // Default scope is Singleton
export class UserService {
    create() {
        return 'User created!';
    }
}


@Service()
export class AnotherService {
    constructor(userService: UserService) {
        console.log(userService.create()); // User created!
    }
}

Middleware

Cheetah.js supports the use of middleware to process requests before they reach their defined routes. This allows you to perform additional logic and manipulate context. Middlewares can be added to the class or method and all middleware must be in the scope of dependency injection.

Example:

import { Context, Middleware, Service, CheetahMiddleware, CheetahClosure } from '@cheetah.js/core';

@Service
export class LoggerMiddleware implements CheetahMiddleware {
    handle(context: Context, next: CheetahClosure) {
        next();
    }
}

@Middleware(LoggerMiddleware)
@Controller()
export class HomeController {
    @Get('/')
    index() {
        return 'Hello World!';
    }
}

Logging

We provide the LoggerService service, it uses pinojs to log.

import { Cheetah, LoggerService, Controller } from '@cheetah.js/core';

@Controller()
export class HomeController {
    constructor(logger: LoggerService) {
        this.logger.info("Hello World!")
    }
}

new Cheetah({logger: {level: 'info'}}).listen();

If you need to customize the logger, it can be configured:

import { Cheetah } from '@cheetah.js/core';

new Cheetah().useLogger(CustomServiceLogger)

Contributing

Contributions are welcome! Feel free to open issues and submit pull requests.