Skip to content

formidablejs/ts-ports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ts-ports

ts-ports enables TypeScript support in the Formidable framework.

Build npm GitHub

Requirements

Install

Recommended

formidable new <app-name> [...args] --ts

Existing Project

npm:

npm i @formidablejs/ts-ports --save

yarn:

yarn add @formidablejs/ts-ports --save

Configuration

Open the package.json file and add "language": "TypeScript":

{
  ...
  "language": "TypeScript",
  ...
}

Finaly, open the config/app.ts config file and add TypeScriptPortsServiceResolver under resolvers:

...
import { TypeScriptPortsServiceResolver } from '@formidablejs/ts-ports';

export default {
  ...
  resolvers: {
    ...,
    TypeScriptPortsServiceResolver,
    ...

Usage

@use Decorator

The use decorator in @formidablejs/ts-ports works the same way as the use decorator in @formidablejs/framework. To get started, just import the use decorator from @formidablejs/ts-ports and add it next to any of your class functions:

import { use } from "@formidablejs/ts-ports";
import { Controller } from "./Controller";

export class UserController extends Controller {
  @use("table:users")
  public async show(user: Promise<User | null>): Promise<User | void> {
    return (await user) || this.notFound("User not found.");
  }
}

Commands

ts-ports also adds 2 new commands to your application.

make:interface

node craftsman make:interface IUserController

make:type

node craftsman make:type User

types:generate

node craftsman types:generate

This will generate types based on the rules of your requests.

Works with TypeScript only

Security

If you discover any security related issues, please email donaldpakkies@gmail.com instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

Releases

No releases published

Packages

No packages published