0.8.12 • Published 7 years ago

typed-framework v0.8.12

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
7 years ago

I'm working hard to test this against production, once it's ready, I will release the 1.0.0, please stay tuned.

NPM version Downloads Build Status Dependency status Dev Dependency status Coverage Status

Enterprise ready spring like framework build on Typescript and Express

  • Dependency Injection (constructor injection and property injection)
  • Service class
  • Rest route and controller, param data injection support
  • Middleware
  • Filter
  • Log support
  • DB support
@ApplicationSettings({rootDir: `${__dirname}/../`})
class Application extends ApplicationLoader {

    public static initialize() {
        return new Application().start();
    }
}

Application
    .initialize()
    .catch(e => {
        throw e
    });

Support ApplicationSettings options:

interface SettingOptions {
    // Required
    rootDir: string;

    srcDir?: string;

    publicDir?: string;

    logDir?: string;

    configDir?: string;

    dbDir?: string;

    env?: string;

    port?: string|number;
}
@RestController()
// RestController support baseUrl options, for example: @RestController("/users")
export class HomeController {

    @Get("/")
    public indexAction(@Data() data: any, @Res() res: Express.Response) {
        res.send(data);
    }

}

Support parameter types:

@PathParam
@QueryParam
@BodyParam
@HeaderParam
@CookieParam
@Req
@Res
@Next
@Err
@Data

Support Http request method:

@Get 
@Post
@Put
@Patch
@Delete
@Head
@Options
@Filter()
export class CurrentUser implements IMiddleware {

    constructor(private userService: UserService) {
    }

    public async use(@Data() data: any, @Next() next: Express.NextFunction) {

        data.user = await this.userService.findById(1);

        next();
    }
}

@RestController()
@BeforeFilter(CurrentUser) 
// also support options only and except, for example: 
// @BeforeFilter(CurrentUser, only: ['indexAction'])
// @BeforeFilter(CurrentUser, except: ['indexAction'])
// @AfterFilter(CurrentUser) only, except options as well
export class HomeController {

    @Get("/")
    public indexAction(@Data() data: any, @Res() res: Express.Response) {
        res.send(data);
    }

}
@Middleware({order: 0}) 
// middleware support two options: order and baseUrl
export class Middleware1 implements IMiddleware {

    public use(@Data() data: any, @Next() next: Express.NextFunction) {
        data.message = "global middleware";
        next();
    }
}
@ErrorMiddleware()
// error middleware support two options: order and baseUrl
export class ErrMiddleware implements IMiddleware {

    public use(@Err() err: any, @Res() res: Express.Response) {
        res.send(err.message);
    }
}
@Service()
export class UserService {

    public findById(id: number) {

        const userFromDB = {
            uuid: "123",
            created_at: Date.now()
        };
        
        return userFromDB;
    }
}

@RestController()
export class HomeController {
    
    constructor(private userService: UserService) {
    }

}
@RestController()
export class HomeController {
    
    private connection = ConnectionFactory.getConnection(); // Database connection is Knex instance 
    private logger = LogFactory.getLogger(); // Logger is winston instance

}
class User {

    // decorate the property you want to convert
    @Property()
    public name: string;

    // if it is an array or an map, you need to provide the baseType
    @Property({baseType: Number})
    public ids: number[];

    // provide an alias name, or pass in {name: "created_at"} is also valid
    @Property("created_at")
    public createdAt: Date;

}


@RestController()
export class UserController {

    @Post("/users")
    public createAction(@BodyParam("user") user: User) {
        user instanceof User // true
        ...
    }
}

Support @BodyParam, @PathParam, @QueryParam, based on the type you provided, the converter service will automatic convert the data from user to the type. !! Must use @Property to decorate the property you want to convert

const userObj = {
    name: "tester",
    ids: [1, 2, 3],
    created_at: "2017-04-17T00:59:56.729Z"
}

class UserService {
    constructor(private converter: ConverterService) {}

    public findUser() {

        // first parameter is the data need to convert
        // second parameter is the target type
        // if second parameter is Array or Map, you need provide the baseType in the third parameter
        const user = this.converter.convert(userObj, User);

        user instanceof User // true
    }
}

Quick start example: link

Full feature example: link

for 2.0, please go to 2.0 Roadmap

Version CodeTarget DateRelease DateDescription
0.1.02017-02-172017-02-17controller/server/service api
0.2.02017-03-052017-03-12middleware/plugin system
0.3.02017-03-122017-03-13enrich controller api
0.4.02017-03-192017-03-14global and error middleware
0.5.02017-03-262017-03-14stable api/pre-production version
1.0.02017-04-01enrich document

v0.8.0 (2017-04-18)

  • add test solution: use bootstrap function
  • add PropertyInherited decorator

v0.7.0 (2017-04-17)

  • add type convert in controller parameters
  • add ConverterService to convert data
  • add Property decorator

v0.6.0 (2017-03-17)

  • add required parameter options
  • add @Head, @Options http request

v0.5.0 (2017-03-14)

  • add logger config

v0.4.0 (2017-03-14)

  • @Middleware and @ErrorMiddleware support
  • middleware order and base url support

v0.3.0 (2017-03-13)

  • Support @Filter decorator to decorate a class as a Filter
  • Support @BeforeFilter, @AfterFilter to filter for a controller, add options: only, except
  • Support @Data param type to inject data for the controller and filters

v0.2.0 (2017-03-12)

  • Support @Middleware decorator to inject for controllers
  • Support Middleware, Controller parameter injections, now your middleware have the same ability as Controller to inject not only Req, Res, and BodyParam, PathParam and so on.
  • Support new @ApplicationSettings and ApplicationLoader for new start up application way
  • Support convert class to object and object to class by Converter, and provide template ability

v0.1.0 (2017-02-17)

  • Spring like routes and controller support based on express
  • Build in support for log based on winston
  • Build in support for query builder based on knex
  • Best practice middlewares preinstalled
  • Best practice project structure
  • Easy server initialization
  • Dependency Injection
0.8.12

7 years ago

0.8.10

7 years ago

0.8.9

7 years ago

0.8.8

7 years ago

0.8.7

7 years ago

0.8.6

7 years ago

0.8.5

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.7.5

7 years ago

0.7.4

7 years ago

0.7.3

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.12

7 years ago

0.6.11

7 years ago

0.6.10

7 years ago

0.6.9

7 years ago

0.6.8

7 years ago

0.6.7

7 years ago

0.6.6

7 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.108

7 years ago

0.0.107

7 years ago

0.0.106

7 years ago

0.0.105

7 years ago

0.0.103

7 years ago

0.0.102

7 years ago

0.0.101

7 years ago

0.0.100

7 years ago

0.0.99

7 years ago

0.0.98

7 years ago

0.0.97

7 years ago

0.0.96

7 years ago

0.0.95

7 years ago

0.0.94

7 years ago

0.0.93

7 years ago

0.0.92

7 years ago

0.0.91

7 years ago

0.0.90

7 years ago

0.0.89

7 years ago

0.0.88

7 years ago

0.0.87

7 years ago

0.0.85

7 years ago

0.0.83

7 years ago

0.0.82

7 years ago

0.0.81

7 years ago

0.0.80

7 years ago

0.0.79

7 years ago

0.0.78

7 years ago

0.0.77

7 years ago

0.0.75

7 years ago

0.0.74

7 years ago

0.0.73

7 years ago

0.0.72

7 years ago

0.0.71

7 years ago

0.0.70

7 years ago

0.0.69

7 years ago

0.0.67

7 years ago

0.0.66

7 years ago

0.0.64

7 years ago

0.0.65

7 years ago

0.0.63

7 years ago

0.0.62

7 years ago

0.0.61

7 years ago

0.0.60

7 years ago

0.0.58

7 years ago

0.0.56

7 years ago

0.0.55

7 years ago

0.0.54

7 years ago

0.0.52

7 years ago

0.0.51

7 years ago

0.0.50

7 years ago

0.0.48

7 years ago

0.0.47

7 years ago

0.0.46

7 years ago

0.0.45

7 years ago

0.0.44

7 years ago

0.0.43

7 years ago

0.0.42

7 years ago

0.0.40

7 years ago

0.0.39

7 years ago

0.0.37

7 years ago

0.0.36

7 years ago

0.0.34

7 years ago

0.0.33

7 years ago

0.0.32

7 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.27

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.1

7 years ago