0.2.6 • Published 1 year ago
@adaliszk/fission v0.2.6
Types for Node.js Fission Functions
Usage
- Install the package
pnpm install -D @adaliszk/fission
- Annotate your function with types
- Build your typescript function into Node.js
- Create the function:
fission function create --name hallo --code dist/hello.js --env nodejs
Types
FunctionHandler<T>
: Combined type for any function handler exportimport { FunctionHandler } from '@adaliszk/fission' export const handler1: FunctionHandler<string> = (context) => { return { status: 200, body: 'OK', } } export const handler2: FunctionHandler<string> = (context, callback) => { callback(200, 'OK') } export const handler3: FunctionHandler = (socket, clients) => { socket.on('message', (data) => { console.log('received: %s', data); }) }
FunctionCallbackHandler<T>
: Callback-style handler functionimport { FunctionCallbackHandler } from '@adaliszk/fission' export const handler: FunctionCallbackHandler<string> = (context, callback) => { callback(200, 'OK') }
FunctionResponseHandler<T>
: Generic Request-Response handlerimport { FunctionResponseHandler } from '@adaliszk/fission' export const handler: FunctionResponseHandler<string> = (context) => { return { status: 200, body: 'OK', } }
FunctionSocketHandler<T>
: Websocket functionimport { FunctionSocketHandler } from '@adaliszk/fission' export const handler: FunctionSocketHandler = (socket, clients) => { socket.on('message', (data) => { console.log('received: %s', data); }) }