# @kenote/core

> The core library of the Kenote.js.

Latest version **1.0.47** (published 2023-07-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kenote/core
pnpm add @kenote/core
yarn add @kenote/core
bun add @kenote/core
```

Provides the command `kenci`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.47 |
| Published | 2023-07-06 |
| First published | 2020-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 10 |
| Unpacked size | 122.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | thondery |
| Maintainers | thondery |
| Keywords | kenote.js |

## Links

- npm: https://www.npmjs.com/package/@kenote/core
- Repository: https://github.com/kenote/kenote.js
- Homepage: https://github.com/kenote/kenote.js#readme
- Issues: https://github.com/kenote/kenote.js/issues
- npm.io page: https://npm.io/package/@kenote/core

## Dependencies (10)

- [nodemon](https://npm.io/package/nodemon.md) ^2.0.19
- [ts-node](https://npm.io/package/ts-node.md) ^10.9.1
- [tscpaths](https://npm.io/package/tscpaths.md) ^0.0.9
- [immutable](https://npm.io/package/immutable.md) ^4.1.0
- [runscript](https://npm.io/package/runscript.md) ^1.5.2
- [@kenote/common](https://npm.io/package/@kenote/common.md) latest
- [@kenote/config](https://npm.io/package/@kenote/config.md) latest
- [@types/nodemon](https://npm.io/package/@types/nodemon.md) ^1.19.2
- [tsconfig-paths](https://npm.io/package/tsconfig-paths.md) ^4.1.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Recent versions

- 1.0.47 (latest) — 2023-07-06
- 1.0.44 — 2022-09-20
- 1.0.42 — 2022-08-19
- 1.0.41 — 2022-08-19
- 1.0.34 — 2022-03-28
- 1.0.32 — 2022-02-23
- 1.0.31 — 2022-02-18
- 1.0.30 — 2021-11-23
- 1.0.27 — 2021-08-04
- 1.0.21 — 2021-03-29
- 1.0.20 — 2021-03-29
- 1.0.19 — 2021-03-11
- 1.0.13 — 2021-01-25
- 1.0.12 — 2021-01-22
- 1.0.11 — 2021-01-21
- … 4 more at https://npm.io/package/@kenote/core/versions

## README

# @kenote/core

The core library of the Kenote.js.

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Gratipay][licensed-image]][licensed-url]

[npm-image]: https://img.shields.io/npm/v/@kenote/core.svg
[npm-url]: https://www.npmjs.com/package/@kenote/core
[downloads-image]: https://img.shields.io/npm/dm/@kenote/core.svg
[downloads-url]: https://www.npmjs.com/package/@kenote/core
[licensed-image]: https://img.shields.io/badge/license-MIT-blue.svg
[licensed-url]: https://github.com/kenote/kenote.js/blob/main/LICENSE

## Usage

```ts
import { Module, ServerFactory } from '@kenote/core'
import { ServiceEngine } from '@kenote/koa'

@Module({
  imports: [],
  plugins: [],
  middlewares: [],
  httpException: {
    notFound: (ctx: Context) => {
      return ctx.status(404)
    },
    exception: (err: any, ctx: Context) => {
      ctx.renderException('error', { message: 'This page could internal server error' })
    }
  }
})
class AppModule {}

async bootstarp () {
  let factory = await ServerFactory(new ServiceEngine()).create(AppModule)
  factory.server.listen(4000)
}
```

### Controller

```ts
import { Context, Controller, Get, NextHandler, Post } from '@kenote/core'


@Controller()
class MainController {

  @Get('/path')
  async handle (ctx: Context, next: NextHandler) {
    // ...
  }

  @Post('/path')
  async handle (ctx: Context, next: NextHandler) {
    // ...
  }

  @Put('/path')
  async handle (ctx: Context, next: NextHandler) {
    // ...
  }

  @Delete('/path')
  async handle (ctx: Context, next: NextHandler) {
    // ...
  }
}
```

### Middleware

```ts
import { Middleware, Action, Context, Property } from '@kenote/core'
import { HttpError } from 'http-errors'

const service = {
  // ...
}

@Middleware()
class Restful {

  @Action()
  api (ctx: Context) {
    return (data: any, error?: HttpError) => {
      if (error != null) {
        let { message } = error
        ctx.json({ error: message })
      } else {
        ctx.json({ data })
      }
    }
  }

  @Property()
  service (ctx: Context) {
    return service
  }
}

declare module '@kenote/core' {
  interface Context {

    api (data: any, error?: HttpError): void
    
    service: typeof service
  }
}
```


---
MIT License.

---
_Source: https://npm.io/package/@kenote/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
