Appearance
Functions Package
The @mmv3/functions package is not designed to be imported by other packages or applications. Instead, it serves as the entry point for serverless functions, such as AWS Lambda functions or Cloudflare Workers.
Purpose
- Entrypoints only: Each file or subdirectory in
src/represents a function entry point. - No business logic: Business logic should not be implemented directly in these function files. Instead, import and use logic from other packages (e.g.,
@mmv3/core,@mmv3/data, etc.). - Composition: This keeps function code minimal, focused on wiring, and makes business logic reusable and testable.
Structure
- Each file in
src/(or its subdirectories) is a function entry point. - Example:
src/ api/ token.ts loans.ts ... reports/ index.ts migrator.ts - These files are deployed as individual serverless functions.
Exports
- The
exportsfield inpackage.jsonis set to expose all files insrc/:json"exports": { "./*": "./src/*.ts" } - This is for compatibility with deployment tools, not for importing from other packages.
Best Practices
- Keep function files thin: Only handle request/response logic, authentication, and orchestration.
- Import business logic: All core logic should live in other packages (e.g.,
@mmv3/core). - Suffix files appropriately: If a function is only safe for the server, use
.server.ts(though in this package, all code is server-only by nature).
Example
ts
// src/api/token.ts
import { getToken } from "@mmv3/core/auth";
export default async function handler(event) {
return getToken(event);
}