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

@mvx/typeorm-adapter

v4.0.0-beta5

Published

@mvx/typeorm-adapter is typeorm adapter orm for mvc, type-mvc is base on koa. Decorator, Ioc, AOP mvc frameworker on server.

Downloads

118

Readme

packaged @mvx/typeorm-adapter

This repo is for distribution on npm. The source for this module is in the main repo.

@mvx/typeorm-adapter is model parser for MVC frameworker. base on ioc @tsdi. help you develop your project easily.

Install

You can install this package either with npm

npm


npm install @mvx/typeorm-adapter

Documentation

create application

import { MvcApplication, DefaultMvcMiddlewares, MvcModule, MvcServer } from '@mvx/mvc';
import { TypeOrmModule }  from '@mvx/typeorm-adapter';

// 1. use MvcHostBuilder to boot application.
MvcApplication.run();

// 2. use bootstrap module to boot application

@MvcModule({
    // baseURL: __dirname,
    imports: [
        TypeOrmModule
        //...  you service, or controller, some extends module.
    ],
    debug: true
})
class MvcApi {
    constructor() {
        console.log('boot application');
    }
}


// 3. use MvcHostBuilder to boot application module.

@MvcModule({
    imports: [
        TypeOrmModule
        // ... /...  you service, or controller, some extends module.
        // DebugLogAspect
    ],
    middlewares: DefaultMvcMiddlewares,
    // bootstrap: MvcServer
})
class MvcApi {

}

MvcApplication.run(MvcApi);


//4. use bootstrap module to boot application by main.
@MvcModule({
    imports: [
        TypeOrmModule
        // ...
    ],
    // bootstrap: MvcServer,
    debug: true
})
class MvcApi {
    constructor() {
        console.log('boot application');
    }

    static main() {
        console.log('run mvc api...');
        MvcApplication.run(MvcApi);
    }
}

Define Controller

default setting load controllers in your project folder /controllers

  • Each Controller action should return type ResultValue, also you can return base type or object, it deal with JsonResult.
  • The action can be async or sync. Have provide FileResult, JsonResult, RedirectResult, ViewResult.
  • Also, you can extend with BaseController, it has implements some mothod to create the ResultValue types.
  • Model can auto create in action, it auto load value from request body.
  • Restfull params or Query String params can auto set to Controller action(Controller method) via the name of param matched.
  • Cors by @Cors decorator in class or method.

define as:

import { Controller, Get, Post, IContext, ContextToken,  RequestMethod, Model, Field, Cors } from '@mvx/mvc';
import { Inject } from '@tsdi/core';
import { Mywork } from '../bi/Mywork';
import { User } from '../models';

@Cors
@Controller('/users')
export class UserController {

    // @Inject(symbols.IContext)
    // context: IContext;
    constructor(private work: Mywork) {

    }

    @Get('')
    index() {
        console.log('home index invorked', this.work);
        return this.work.workA();
    }

    // @Cors([RequestMethod.Post])
    // also can define as below
    // @Cors(['Post','Get'])
    // @Cors('POST,GET')
    @Post('/add')
    async addUser(user: User, @Inject(ContextToken) ctx: IContext) {
        console.log('user:', user);
        console.log('request body', ctx.request.body);
        return this.work.save(user);
    }

    @Get('/sub')
    sub() {
        return this.work.workB();
    }

    @Get('/:name')
    getPerson(name: string) {
        return this.work.find(name);
    }

    @Get('/find/:name')
    query(name: string, @Inject(ContextToken) ctx) {
        console.log(ctx);
        return this.work.find(name);
    }

    @Get('/test/:id')
    parmtest(id: number) {
        if (id === 1) {
            return this.work.workA();
        } else if (id === 2) {
            return this.work.workB();
        } else {
            return 'notFound';
        }
    }

    @Post('/posttest/:id')
    postTest(id: number) {
        return {
            id: id
        }
    }

}


@Controller('/')
export class HomeController extends BaseController {

    // @Inject(ContextToken)
    // context: IContext;
    constructor() {
        super();
    }

    @Get('')
    index(): ResultValue {
        return this.view('index.html');
    }

    @Get('/index2')
    home2(): ResultValue {
        return this.view('index2.html');
    }

    @Post('/goto/:pageName')
    gotoPage(pageName: string): ResultValue {
        return this.redirect( '/' + pageName);
    }
}

Define AOP

Auto load Aspect service from folder /aop in your project.

see simple demo

import { Aspect, Around, Joinpoint, Before } from '@tsdi/aop';

@Aspect
export class DebugLog {
    @Around('execution(*Controller.*)')
    log(joinPoint: Joinpoint) {
        console.log('aspect append log, method name:', joinPoint.fullName, ' state:', joinPoint.state, ' Args:', joinPoint.args ,  ' returning:', joinPoint.returning, ' throwing:', joinPoint.throwing);
    }

    @Before(/Controller.\*$/)
    Beforlog(joinPoint: Joinpoint) {
        console.log('aspect Befor log:', joinPoint.fullName);
    }
}

Define Middlewares

default setting load middlewares in your project folder /middlewares

import { Middleware, IMiddleware, Application, Configuration } from '@mvx/mvc';
import { IContainer, Injectable } from '@tsdi/core';


@Middleware('logger')
export class Logger implements IMiddleware {

    constructor() {

    }

    async execute (ctx, next) {
        let start = Date.now();
        await next();
        const ms = Date.now() - start;
        console.log(`mylog: ${ctx.method} ${ctx.url} - ${ms}ms`);
        let end = new Date();
    }

}

changes

  • 1.0.1

    1. add useServer to add Server Middleware features.
  • 0.6.3

    1. update compile task, zip lib.
    2. update tsioc for fix bug when inherit class with classAnnations
  • 0.5.5

    1. fix ConsoleLog error console.debug in nuix will not console.
    2. update components for route.
  • v0.5.3

    1. fix bug in nuix linux load .d.ts file raise error, set default comfig load module with !./**/*.d.ts exclude.
  • v0.5.1

    1. add Log aop aspect service. for Log easy. default user console to log, can config logLib,logConfig in your config.js to use third logger lib. eg. { logLib: 'log4js', logConfig:{...} }. has implements log4js adapter see code

    2. DebugAspect, config debug: true, in your config.js, will auto log debug info.

    3. AnnotationLogerAspect @annotation(Logger), logger some state via @Logger decorator config.

    4. add Annotation Auth aspect service AuthAspect to support yourself auth check easy. eg.

@Aspect
export class YourSecrityAspect {
    // before AuthAspect.auth check some.
    @Before('execution(AuthAspect.auth)', 'authAnnotation')
    sessionCheck(authAnnotation: AuthorizationMetadata[], joinPoint: Joinpoint) {
        //TODO: you check by authAnnotation
    }
}
  • v0.4.1 fix assertUrlRegExp bug.
  • v0.3.20 New Feature:
    1. Router and Cors middleware will check url is right route or not. add default route Url check in Configuartion. isRouteUrl method and routeUrlRegExp field.
  • v0.3.19 New Feature: Fix bug, reset context middleware order to fix 500 error, when some time request.
  • v0.3.18 New Feature:
    1. update tsioc to improvement method invoker.
    2. fix Model not register bug. get Model return empty object.
  • v0.3.17 New Feature:
    1. add hostname for http or https to listen.
  • v0.3.12 New Feature:
    1. es5 support. enable config https http server.
  • v0.3.10 New Feature:
    1. Restfull params or Query String params can auto set to Controller action(Controller method) via the name of param matched.

Simples

see simples

License

MIT © Houjun