0.0.2 • Published 2 years ago

le-sls-typescript v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

LE-SLS-Typescript

Write serverless application on top of Typescript

Installation

To install the LE-SLS-Typescript library into an existing project, use the yarn CLI

yarn add le-sls-typescript 
yarn add serverless-webpack ls-sls-generate-functions -D

or the npm CLI

npm install le-sls-typescript
npm add serverless-webpack ls-sls-generate-functions -D

Examples

We have several examples on the website. Here is the first one to get you started

// ./src/hello/hello.service.ts

import { injectable } from 'le-sls-typescript'

@injectable()
export class HelloService {
  async hello() {
    return 'Hello world'
  }
}
// ./src/hello/hello.handler.ts

import { HelloService } from './hello.service'
import { handler, get, param } from 'le-sls-typescript'

@handler()
export class HelloHandler {
  constructor(private readonly helloService: HelloService) {
  }

  @get()
  async hello() {
    return this.helloService.hello()
  }
}
// ./src/hello/hello.module.ts

import { module } from 'le-sls-typescript'
import { HelloHandler } from './src/hello.handler'

@module({
  handlers: [HelloHandler],
  providers: [HelloService]
})
export class HelloModule {}
// ./handler.ts

import { module } from 'le-sls-typescript'
import { HelloModule } from './src/hello/hello.module'

@module({
  imports: [HelloModule],
})
export class Handler {
  static exports = exports
}

Add the plugin landsend-gen-functions to your serverless.yml file:

plugins:
  - serverless-dotenv-plugin
  - serverless-offline
  - serverless-webpack
  - ls-sls-generate-functions

After that, when you want to generate list functions. You can simply run the command line with option --gf:

sls offline --env staging --gf