JSPM

appwrite-function-utils

0.3.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 18
    • Score
      100M100P100Q42841F
    • License MIT

    Package Exports

    • appwrite-function-utils

    Readme

    Appwrite Function Utils

    This repository contains a set of utilities for Appwrite functions.

    Installation

    npm install --save appwrite-function-utils

    Features

    Function Handler Types

    Enabled type checking for your function handler by using the Function type.

    JavaScript

    /** type {import('appwrite-function-utils').Function} */
    const handler = async (context) => {
      // Your function code
    }
    
    export default handler

    TypeScript

    import { Function } from 'appwrite-function-utils'
    
    const handler: Function = async (context) => {
      // Your function code
    }
    
    export default handler

    Router

    The router function allows you to easily define routes for your function handler.

    import { router, HttpMethod } from 'appwrite-function-utils'
    
    export default router({
      routes: [
        {
          path: '/ping',
          methods: [HttpMethod.GET, HttpMethod.POST],
          handler: async (context) => {
            return context.res.send('Pong!')
          },
        },
      ],
      // override the default exception handler routes
      exception: {
        notFound: async (context) => {
          return context.res.send('Oopsy whoopsy doopsy no findy windy', 404)
        },
      },
    })

    Dev Server

    The appwrite-function-utils dev command will start a local server that will listen for incoming requests and execute your function handler. Assuming your function handler is located in src/main.js, add the following script to your package.json file:

    {
      "scripts": {
        "dev": "appwrite-function-utils dev src/main.js"
      }
    }

    You can use it in conjuction nodemon to automatically restart the server when you make changes to your function handler:

    npm install --save-dev nodemon
    {
      "scripts": {
        "dev": "nodemon --watch src --exec \"appwrite-function-utils dev src/main.js\""
      }
    }