0.0.11 • Published 5 years ago

tote-lib v0.0.11

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

tote-lib

tote-lib is a helper library for Tote.

API

tote-lib exports four items.

Func

Func is the class you use to setup your function. It includes several helper methods.

Example

// import dependencies
import { Func, joi } from 'tote-lib'

// create your function
class Hello extends Func {
  // define your schema
  schema = {
    // query parameters
    query: joi.object({
      number: joi.number()
    })
  }

  // define your function here
  invoke() {
    // get query params
    const {
      query: { number = 5 }
    } = this.request

    // return object
    return {
      hello: 'world',
      result: number * 2
    }
  }
}

// bootstrap and export
export default Func.bootstrap(Hello)

Options

NameTypeDescription
contextObjectAzure Function execution context
requestObjectRequest object. Contains body, headers, and query objects with any parameters
status<number>FunctionSet the HTTP status code
send<object>FunctionSet the JSON body
Usage

request

Get input parameters.

// get parameters
const {
  body: { foo },
  query: { name }
} = this.request

// use them

status

this.status(404)

send

You can just return the object from your function. But you can also use send.

this.send({
  foo: 'bar'
})

Exception

Exception extends Error and lets you throw sensible errors from your functions.

Parameters

NameTypeDescriptionDefault
messagestringError message or keyunknown_error
statusnumberHTTP status code500

Usage

throw new Exception('Email required', 400)

invoke

invoke is a helper for invoking functions when writing your tests.

Parameters

NameTypeDescription
namestringFunction name, should correspond to a directory
requestObjectOptional. Request object, may contain body, headers, and query objects

Usage

invoke('hello', {
  headers: {
    authorization: 'Bearer ...'
  },
  query: {
    name: 'Ali'
  }
})

joi

Look at Joi docs.

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago