actionsuperhero
TypeScript icon, indicating that this package has built-in type declarations

1.0.13 • Public • Published

ActionSuperHero

Typescript decorators for working with actionhero framework.

Getting Started

npm install actionsuperhero

Setup Typescript compiler

Alter tsconfig.json to support decorators and emit node modules (unlike ES6 modules)

"compilerOptions": {
        "module": "none",
        "target": "es6",
        "noImplicitAny": true,
        "inlineSourceMap": true,
        "noImplicitReturns": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "outDir": "dist",
        "sourceRoot": "src",
        "moduleResolution": "node"
    }

Config action path

Edit config/api.js and add the following to the paths array

paths: [
...
'superObjects': [path.join(__dirname, '/../dist')]
...
],

Setup initializer

Create a file actionsuperhero.js under the initializers directory of your actionhero project, with the following content

'use strict'

const actionsuperhero = require("actionsuperhero");

actionsuperhero.setupInitializer(module);

Hello World Action

Create a file HelloWorld.ts under the src directory with the following content

import {Action, Api, ChainedFunction, IAction, IActionRequestData, Input} from "actionsuperhero";

@Action({
    actionName: "helloworld",
    description: "Just says hello world",
})
@Input({
    name: "user",
    required: false,
})
@Route({
    path: "helloworld",
    method: "get",
})
export class HelloWorld implements IAction {
    public run(api: Api, data: IActionRequestData, next: ChainedFunction): void {
        const name = data.params.user || "World";
        data.response.message = `Hello ${name}`;
        next();
    }
}

Package Sidebar

Install

npm i actionsuperhero

Weekly Downloads

1

Version

1.0.13

License

MIT

Last publish

Collaborators

  • sdamodharan