Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koatty_cli

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koatty_cli

Koatty command line tool.

  • 3.11.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

koatty_cli

Koatty command line tool.

Usage

Create koatty project

koatty new projectName

cd ./projectName

yarn install  // or npm i

npm start

Create a module in the koatty project

  • 1.Create a Controller
// http controller
kt controller test

// grpc controller
kt controller -t grpc test

// websocket controller
kt controller -t websocket test

  • 2.Create a Service
kt service test

// service with interface
kt service -i test

  • 3.Create a Middleware
kt middleware test

  • 4.Create a Model

//default use typeorm
kt model test

  • 5.Create a Aspect

定义切面类:


kt aspect test

使用切面:

@Controller()
@BeforeEach("TestAspect")  //类的每一个方法执行之前执行
export class TestController {
    app: App;

    @RequestMapping("/test", RequestMethod.ALL)
    @After("TestAspect") //test方法执行之前执行
    async test() {
        const info = await this.testService.test();
        return this.body(info);
    }
}

  • 6.Create a DTO class

定义数据验证类:


kt dto test

修改数据验证类:

export class TestDTO {
    @IsNotEmpty()
    name: string;

    @Min(0)
    @Max(120)
    age: number;
}

使用实体类进行验证:

@Controller()
export class TestController {
    app: App;

    @RequestMapping("/test", RequestMethod.ALL)
    @Validated() // <== 开启验证   
    async test(@Get() param: TestDTO) { // <== 指定DTO
        const info = await this.testService.test();
        return this.body(info);
    }
}

Create Koatty Extension Project

  • 1、Create a Middleware Project
kt new projectName -t middleware

cd ./projectName

yarn install  // or npm i

npm start
  • 2、Create a Plugin Project
kt new projectName -t plugin

cd ./projectName

yarn install  // or npm i

npm start

FAQs

Package last updated on 14 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc