0.0.0-468fd8b • Published 7 days ago

@bluish/core v0.0.0-468fd8b

Weekly downloads
-
License
-
Repository
-
Last release
7 days ago

Bluish Core

Bluish is a framework for creating azure function triggers programmatically through typescript with decorators.

It helps to write azure trigger functions directly in your class, without the need for auxiliary files and gives you autonomy to create interceptors to help and focus specifically on what the function has to deliver.

Getting started

To start using bluish read the repositor README.

Triggers

The makers of bluish triggers want to make their code as readable as possible!

Http

The http trigger can be defined with the Http decorator that @bluish/core provides.

import { Http } from '@bluish/core'

export class Users {
  @Http.Get('/users')
  public list(
    @Http.Query() query: unknown.
  ) {}

  @Http.Post('/users')
  public create(
    @Http.Body() body: unknown
  ) {}

  @Http.Patch('/users/{userId}')
  public create(
    @Http.Param('userId') userId: string,
    @Http.Body() body: unknown
  ) {}

  @Http.Delete('/users/{userId}')
  public create(
    @Http.Param('userId') userId: string,
  ) {}
}

For more details about the template see the Http documentation

Timer

import { Timer } from '@bluish/core'

export class Class {
  @Timer('0 */1 * * * *')
  public timer() {
    console.log('doing')
  }
}

EventGrid

import { EventGrid } from '@bluish/core'

export class Class {
  @EventGrid()
  public observer() {
    console.log('event')
  }
}

Events

The events are used to infiltrate the flow of the bluish runner.

OnInitialize

The initialization hook happens before actually entering your trigger, it helps you create custom validations and parsers.

import { OnInitialize, Http, HttpContext } from '@bluish/core'

export class Users {
  @Http.Get('/users')
  @OnInitialize(async (context: HttpContext) => {
    if (!isAuthorizedToReadUser(context.headers.authorization))
      throw new UnauthorizedError()
  })
  public async list() {}
}

see the OnInitialize documentation.

OnDestroy

Com ele você pode se conectar ao fluxo de destruição do gatilho, útil para limpeza e fechamento de conexões.

import { OnInitialize, Http } from '@bluish/core'

@OnInitialize(async () => await connection.connect())
@OnDestroy(async () => await connection.end())
export class Users {
  @Http.Get('/users')
  public async list() {}
}

OnError

Also with the same polymorphism as OnInitialize and OnDestroy, on OnError is always executed when an error is thrown during initialization and trigger execution. It can also be used for error handling.

@OnInitialize((context: HttpContext) => {
  if (!isAuthorizedToWriteUser(context.headers.authorization))
    throw new UnauthorizedError()
})
@OnError((error: unknown, context: HttpContext) => {
  if (error instanceof UnauthorizedError)
    return { status: 400, body: { message: 'unauthorized' } }
})
export class Users {
  @Http.Post('/users')
  public async create() {}

  @Http.Patch('/users')
  public async update() {}
}

OnSuccess

Finally the OnSuccess call from the context with the generated payload, it works differently from the others because each result of each OnSuccess call is analyzed and given as an "official" answer. Example:

import { OnSuccess } from '@bluish/core'

export class Users {
  @OnSuccess(users => ({ status: 200, body: users }))
  public list() {
    const users = []
    return users
  }
}

Basically, you can transform the method's return into a response with other characteristics, or even transform the body's content, in short, it's up to your creativity.

Under the hood

Trigger

see Trigger documentation.

Context

see Context documentation.

Runner

see Runner documentation.

0.0.0-468fd8b

7 days ago

0.0.0-72735d5

1 month ago

0.0.0-9830012

1 month ago

0.0.0-5878335

1 month ago

0.0.0-fcb7b57

6 months ago

0.0.0-fc08d23.0

6 months ago

0.0.0-a033a75

2 months ago

0.0.0-075ff10

6 months ago

0.0.0-8482469

6 months ago

0.0.0-ebebcfe

6 months ago

0.0.0-6e88a60

6 months ago

0.0.0-fc08d23

6 months ago

0.0.1-alpha.6

1 year ago

0.0.1-alpha.5

1 year ago

0.0.1-alpha.4

1 year ago

0.0.1-alpha.3

1 year ago

0.0.1-alpha.2

1 year ago

0.0.1-alpha.1

1 year ago

0.0.1-alpha.0

1 year ago