Skip to content

Latest commit

 

History

History

purescript-function

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

PureScript Example Function

This is an example function for Airsequel Functions written in PureScript.

Usage

  1. Install all dependencies:
    npm install
  2. Write your code in src/Main.purs
  3. Create the JavaScript bundle:
    make bundle
  4. Copy and paste the content of index.js to your Airsequel function

    ![NOTE] We'll add a script to upload the function directly to Airsequel in the future

How it Works

Since the bundle generated by Spago (PureScript's package manager) is not fully compatible with Airsequel Functions, following additional steps are executed by make bundle:

  1.  npx spago bundle \
       --platform node \
       --bundle-type module \
       --minify
  2. Prefix imports with node::
    - import __module from 'module';
    - import __path from 'path';
    - import __url from 'url';
    + import __module from 'node:module'
    + import __path from 'node:path'
    + import __url from 'node:url'
  3. Remove useless const … at the beginning:
    - const require = …
    - const __dirname = …
    - const __filename = …
  4. Export a default wrapper function:
    - export { x as main };
    + export default async function main(context) {
    +   return x(context)()
    + }