diff --git a/CHANGELOG.md b/CHANGELOG.md index f0d7ec66..d294ed1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.7.0](https://www.github.com/netlify/functions-js/compare/v0.6.0...v0.7.0) (2021-04-14) + + +### Features + +* add type to builder wrapper ([#48](https://www.github.com/netlify/functions-js/issues/48)) ([0af5b04](https://www.github.com/netlify/functions-js/commit/0af5b04c2b1241f64a56394317371a08781e881d)) + ## [0.6.0](https://www.github.com/netlify/functions-js/compare/v0.5.0...v0.6.0) (2021-04-12) diff --git a/README.md b/README.md index cf0e632a..52d3b4a9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Coverage Status](https://codecov.io/gh/netlify/functions-js/branch/main/graph/badge.svg)](https://codecov.io/gh/netlify/functions-js) [![Node](https://img.shields.io/node/v/@netlify/functions.svg?logo=node.js)](https://www.npmjs.com/package/@netlify/functions) -JavaScript utilities for Netlify Functions. +Development utilities for Netlify Functions. ## Installation @@ -14,10 +14,12 @@ npm install @netlify/functions ## Usage -### Builder Functions +### On-demand Builders + +To use On-demand Builders, wrap your function handler with the `builder` function. ```js -const { builderFunction } = require('@netlify/functions') +const { builder } = require('@netlify/functions') const handler = async (event, context) => { return { @@ -26,9 +28,34 @@ const handler = async (event, context) => { } } -exports.handler = builderFunction(handler) +exports.handler = builder(handler) ``` +### TypeScript typings + +This module exports typings for authoring Netlify Functions in TypeScript. + +```ts +import { Handler } from '@netlify/functions' + +const handler: Handler = async (event, context) => { + return { + statusCode: 200, + body: JSON.stringify({ message: "Hello World" }) + } +} + +export { handler } +``` + +The following types are exported: + +- `Handler` +- `HandlerCallback` +- `HandlerContext` +- `HandlerEvent` +- `HandlerResponse` + ## Contributors Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for instructions on how to set up and work on this repository. Thanks diff --git a/package-lock.json b/package-lock.json index 1fa234fc..7daa00d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@netlify/functions", - "version": "0.6.0", + "version": "0.7.0", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 52128ac5..e4ab0048 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@netlify/functions", "main": "./src/main.js", "types": "./src/main.d.ts", - "version": "0.6.0", + "version": "0.7.0", "description": "JavaScript utilities for Netlify Functions", "files": [ "src/**/*.js", diff --git a/src/lib/builder.ts b/src/lib/builder.ts new file mode 100644 index 00000000..7493156c --- /dev/null +++ b/src/lib/builder.ts @@ -0,0 +1,7 @@ +import { Handler } from '../function/handler' + +export interface Builder { + (handler: Handler): Handler +} + +export declare const builder: Builder diff --git a/src/main.d.ts b/src/main.d.ts index d14af30e..8d0a8a5a 100644 --- a/src/main.d.ts +++ b/src/main.d.ts @@ -1 +1,2 @@ +export * from './lib/builder' export * from './function'