Get unlimited public & private packages + team-based management with npm Teams.Learn more »

koatty

1.14.5 • Public • Published

koatty

Koa2 + Typescript = koatty.

Use Typescript's decorator implement auto injection and AOP, just like SpringBoot.

Version npmnpm Downloads

New features

  • New: @Scheduled("0 0/1 * * * ?") ✔️ 1.9.2
  • New: replace koa-router to @koa/router ✔️ 1.10.0
  • New: AOP:@Aspect()、@Before()、@After()、@BeforeEach()、@AfterEach() ✔️ 1.11.2
  • New: @Validated: Use class-validator for entity class validation, and support auto create Apidoc. ✔️ 1.12.4
  • New: @Transactional() with ThinkORM. ✔️ ThinkORM@4.3.0
  • New: Scheduled tasks support redis-based distributed locks. ✔️ 1.14.1
  • New: koatty-grpc server & think_grpc middleware.
  • New: koatty-cloud for nacos
  • New: koatty-cloud for SpringCloud
  • New: GraphQL
  • New: SSR

Documentation

koatty_doc_CN (In progress💪)

[koatty_doc_EN] come soon...

Installation

npm i -g koatty_cli

Quick Start

1.Create Project

koatty new projectName
 
cd ./projectName
 
yarn install
 
npm start

2.Create a Controller

koatty controller test
 

3.Create a Service

koatty service test
 

3.Create a Middleware

koatty middleware test
 

4.Create a Model

Supports thinkorm and typeorm. Please expand other ORM by yourself.

//thinkorm
koatty middleware test
 
//typeorm
koatty middleware -o typeorm test
 

5.Define TestController

import { Controller, BaseController, Autowired, GetMaping, RequestBody, PathVariable, PostMaping, RequestMapping, RequestMethod, Valid } from "koatty";
import { TestDTO } from "../model/dto/TestDTO";
import { TestService } from "../service/TestService";
import { App } from "../App";
 
@Controller()
export class IndexController extends BaseController {
    app: App;
 
    @Autowired()
    private testService: TestService;
 
    init() {
        this.cache = {};
    }
 
    @RequestMapping("/", RequestMethod.ALL)
    async default(@PathVariable("test") @Valid("IsNotEmpty") test: string) {
        const info = await this.testService.sayHello();
        return this.ok(test, info);
    }
 
    @PostMaping("/test")
    @Validated()
    test(@RequestBody() body: TestDTO) {
        return this.ok("test", body);
    }
}

How to debug

if you use vscode , edit the .vscode/launch.json , like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "TS Program",
            "args": [
                "${workspaceRoot}/src/App.ts" 
            ],
            "runtimeArgs": [
                "--nolazy",
                "-r",
                "ts-node/register"
            ],
            "sourceMaps": true,
            "cwd": "${workspaceRoot}",
            "protocol": "inspector",
            "internalConsoleOptions": "neverOpen"
        }
    ]
}

Select TS Program to debug run. Try to call http://localhost:3000/ .

Example

Check out the quick start example.

Install

npm i koatty

DownloadsWeekly Downloads

266

Version

1.14.5

License

MIT

Unpacked Size

240 kB

Total Files

84

Last publish

Collaborators

  • avatar