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

@rockerjs/dao

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rockerjs/dao

Database access object framework, support transaction

  • 1.0.0-1
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-75%
Maintainers
2
Weekly downloads
 
Created
Source

ROCKER-MVC

一、快速上手

初始化项目目录

  • 安装 Node.js(v8.9.3+)

    https://nodejs.org/en/

  • 安装 vbuilder 命令行

    [sudo] npm i @vdian/vbuilder-cli --registry http://npm.idcvdian.com
    
  • 进入项目目录(名称任意)

    mkdir rocker-mvc-project
    
    cd rocker-mvc-project
    
  • 执行命令 v,根据提示依次完成:项目初始化、启动本地开发环境

    项目初始化完成后,也可以执行 npm run dev 启动本地开发环境

启动开发环境

npm run dev

二、API

所有 API 挂载在引入的 MVC 对象下,而且可以串行调用

MVC.route({
    '/home': import('./home')
}).start()

start

接收参数:

  • { port: number }

在添加路由以及中间件后启动服务

MVC.pipe(middleWare).route({ }).start()

route

接收参数:

  • RouterMap => { [index: string]: Function } | { [index: string]: Promise };
  • RouterRegType => { all: RouterMap, render?: { start: string, end: string } }

为应用添加路由处理方法,参数示例如下:

// 1. RouterMap
MVC.route({
    '/home': import('./home'),
    '/about': import('./about')
})

// 2. RouterRegType
// 为所有的路由添加公有的 header 和 footer 脚本
MVC.route({
    all: {
        '/home': import('./home'),
        '/about': import('./about')
    },
    render: {
        start: './header.ejs',
        end: './footer.ejs'
    }
})

pipe

接收参数:

  • Koa 中间件

Rocker MVC 可以任意使用Koa的中间件,示例如下:

编写 logRequest 中间件

function log( ctx ) {
    console.log( ctx.method, ctx.header.host + ctx.url )
}

export default function () {
    return async function ( ctx, next ) {
        log(ctx);
        await next()
    }
}

通过 pipe 来引入中间件

import logRequest from './logRequest'

MVC.pipe(logRequest()).route({ }).start()

三、TypeScript 介绍

全局安装 typescript 编译器

npm i -g typescript

编写 ts 配置文件 tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noImplicitAny": false,
        "allowJs": true,
        "inlineSourceMap": true
    },
    "exclude": [
        "node_modules",
        "coverage"
    ]
}

执行编译操作

tsc .

四、TODO

  • route 现在只接收 import 进来的模块
  • 完善单元测试
  • 添加测试覆盖率
  • push 前挂载集成测试钩子

Keywords

FAQs

Package last updated on 12 Apr 2019

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