@mincloudx/faas
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

@mincloudx/faas

Version TypeScript

A more user-friendly Node.js cloud function development framework, designed to simplify interactions with Backend-as-a-Service (BaaS) and ensure consistent response structures.

Features

  • Default Parameter Handling: Automatically transforms null or missing event.data into an empty object, ensuring your function always receives a valid event object.
  • Unified Return Format: Standardizes the return format of cloud functions. Non-object returns are wrapped as {data: value}, while object returns are passed through as-is.
  • BaaS SDK Version Management: By default, uses the latest SDK version available but allows for explicit version setting or opting out of version updates.

Usage

Installation

pnpm install @mincloudx/faas

Creating a Cloud Function

In your cloud function file, import and use createFaas to wrap your main function. This not only standardizes the behavior of your cloud function but also handles BaaS SDK version management and event data preprocessing.

import { createFaas, FAAS_LATEST_SDK_VERSION } from '@mincloudx/faas';

async function main(event) {
  // Your function logic here
  console.log(`event:`, event);

  return { status: 'ok' };
}

export default createFaas(main, {
  updateVersion: true, // Optional: Ensures the BaaS SDK is always up-to-date. Default is true.
  version: 'specific-version', // Optional: Set a specific BaaS SDK version if required.
});

Test

Ensure the reliability and correctness of your functions by testing with Jest. The framework provides a streamlined way to test various scenarios, such as default parameter handling, unified return format, and BaaS SDK version management.

pnpm run test

Development

Compiling TypeScript

Prepare your package for use by compiling TypeScript files.

pnpm run tsc

Watch Mode

Automatically recompile TypeScript files upon changes for efficient development.

pnpm run watch

This improved README incorporates details from the test cases, emphasizing the utility and flexibility of createFaas. It clarifies how users can manage BaaS SDK versions and the behavior of cloud functions with respect to input and return values, providing a comprehensive guide for both usage and development.

Package Sidebar

Install

npm i @mincloudx/faas

Weekly Downloads

0

Version

0.4.0

License

MIT

Unpacked Size

17.7 kB

Total Files

24

Last publish

Collaborators

  • anran758