2.0.0-alpha.2 • Published 3 years ago

@travetto/generator-app v2.0.0-alpha.2

Weekly downloads
98
License
MIT
Repository
github
Last release
3 years ago

Yeoman Generator

Yeoman app generator for the Travetto framework

Install: @travetto/generator-app

npm install @travetto/generator-app

A simple yeoman generator for scaffolding a reference project. To get started, you need to make sure:

Install: Setting up yeoman and the generator

$ npm i -g yo #Ensure yeoman is installed globally
$ npm i -g @travetto/generator-app #Ensure this yeoman generator is installed
$ git config --global.username <Username> #Set your git username

Once installed you can invoke the scaffolding by running

Terminal: Running Generator

$ yo @travetto/app

The generator will ask about enabling the following features:

Restful Architecture

The RESTful API provides the necessary integration for exposing restful apis. When selecting the rest feature, you will need to specify which backend you want to include with your application, the default being express. Currently you can select from:

The code will establish some basic routes, specifically, GET / as the root endpoint. This will return the contents of your package.json as an identification operation.

Additional Rest Features

In addition to the core functionality, the rest feature has some useful sub-features. Specifically:

OpenAPI Specification support for the restful api. This will automatically expose a openapi.yml endpoint, and provide the necessary plumbing to support client generation.

Logging support for better formatting, debug like support, and colorized output. This is generally useful for server logs, especially during development.

Authentication

Authentication is also supported on the Restful endpoints by selecting Rest Auth during setup. This will support basic authentication running out of local memory, with user REST Sessions.

Testing

Testing can also be configured out of the box to provide simple test cases for the data model.

Data Modelling and Storage

The Data Modeling Core allows for modeling of application data, and provides mechanisms for storage and retrieval. When setting up your application, you will need to select which database backend you want to use:

A default model is constructed, a Todo class:

Code: Todo Model

import { Model, ModelCore } from '@travetto/model';

@Model()
export class Todo implements ModelCore {
  id?: string;
  text: string;
  completed?: boolean;
}

Basic tests are also included for the model to verify that database interaction and functionality is working properly.

Rest + Model

In the case both rest and model features are enabled, the code will produce a controller that exposes the Todo model via restful patterns.

Code: Todo controller

import { AppError } from '@travetto/base';
import { Controller, Get, Put, Post, Delete, Path } from '@travetto/rest';
import { Inject } from '@travetto/di';
import { ModelService, ModelQuery } from '@travetto/model';
import { SchemaBody, SchemaQuery, Schema } from '@travetto/schema';

import { Todo } from '../model/todo';

@Schema()
class Query {
  q: any = {};
}

/**
 * Controller for managing all aspects of the Todo lifecycle
 */
@Controller('/todo')
export class TodoController {

  @Inject()
  source: ModelService;

  /**
   * Get all Todos
   */
  @Get('/')
  async getAll(@SchemaQuery() query: Query): Promise<Todo[]> {
    query.q = query.q || {};
    return this.source.getAllByQuery(Todo, { where: query.q });
  }

  /**
   * Get Todo by id
   */
  @Get('/:id')
  async getOne(@Path() id: string): Promise<Todo> {
    const q: ModelQuery<Todo> = { where: { id } };
    return this.source.getByQuery(Todo, q);
  }

  /**
   * Create a Todo
   */
  @Post('/')
  async save(@SchemaBody() todo: Todo): Promise<Todo> {
    return this.source.save(Todo, todo);
  }

  /**
   * Update a Todo
   */
  @Put('/:id')
  async update(@SchemaBody() todo: Todo): Promise<Todo> {
    return this.source.update(Todo, todo);
  }

  /**
   * Delete a Todo
   */
  @Delete('/:id')
  async remove(@Path() id: string): Promise<void> {
    const q: ModelQuery<Todo> = { where: { id } };
    if (await this.source.deleteByQuery(Todo, q) !== 1) {
      throw new AppError('Not found by id', 'notfound');
    }
  }
}

Running

Once finished the application will reflect the modules chosen, and will be ready for execution, if you have configured a runnable application. Currently, this requires the rest feature to be selected.

Terminal: Starting the App

npm start
2.0.0-alpha.2

3 years ago

2.0.0-alpha.1

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.0-rc.0

4 years ago

1.1.0-alpha.6

4 years ago

1.1.0-alpha.5

4 years ago

1.1.0-alpha.3

4 years ago

1.1.0-alpha.4

4 years ago

1.1.0-alpha.1

4 years ago

1.1.0-alpha.2

4 years ago

1.1.0-alpha.0

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-rc.10

4 years ago

1.0.0-rc.9

4 years ago

1.0.0-rc.7

4 years ago

1.0.0-rc.8

4 years ago

1.0.0-rc.6

4 years ago

1.0.0-rc.5

4 years ago

1.0.0-rc.4

4 years ago

1.0.0-rc.3

4 years ago

1.0.0-rc.2

4 years ago

1.0.0-rc.1

4 years ago

1.0.0-rc.0

4 years ago

1.0.0-beta.1

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.1-alpha.11

5 years ago

0.7.1-alpha.10

5 years ago

0.7.1-alpha.9

5 years ago

0.7.1-alpha.8

5 years ago

0.7.1-alpha.7

5 years ago

0.7.1-alpha.6

5 years ago

0.7.1-alpha.5

5 years ago

0.7.1-alpha.4

5 years ago

0.7.1-alpha.3

5 years ago

0.7.1-alpha.2

5 years ago

0.7.1-alpha.1

5 years ago

0.7.1-alpha.0

5 years ago

0.7.0-alpha.0

5 years ago

0.6.11

5 years ago

0.6.10

5 years ago

0.6.9

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.6.0-rc.13

5 years ago

0.6.0-rc.12

5 years ago

0.6.0-rc.11

5 years ago

0.6.0-rc.10

5 years ago

0.6.0-rc.9

5 years ago

0.6.0-rc.8

5 years ago

0.6.0-rc.7

5 years ago

0.6.0-rc.5

5 years ago

0.6.0-rc.4

5 years ago

0.6.0-rc.3

5 years ago

0.6.0-rc.2

5 years ago

0.6.0-rc.1

5 years ago

0.6.0-rc.0

5 years ago

0.5.8

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.11

6 years ago

0.3.10

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago