@mincloudx/faas
v0.4.2
Published
A more user-friendly Node.js cloud function development framework.
Downloads
7
Maintainers
Readme
@mincloudx/faas
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 missingevent.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.