firebase-functions
19
总安装量
2
周安装量
#18657
全站排名
安装命令
npx skills add https://github.com/bumgeunsong/daily-writing-friends --skill firebase-functions
Agent 安装分布
claude-code
2
amp
1
openclaw
1
kimi-cli
1
codex
1
Skill 文档
Firebase Functions Patterns
Directory Structure
functions/
âââ src/
â âââ index.ts # Function exports
â âââ admin.ts # Firebase Admin SDK init
â âââ backfill/ # Data migration scripts
â âââ commentSuggestion/ # AI comment features
â âââ commentings/ # Comment activity tracking
â âââ notifications/ # Push notification functions
â âââ postings/ # Post activity tracking
â âââ replyings/ # Reply activity tracking
â âââ shared/ # Shared utilities
Function Structure
import { onDocumentCreated } from 'firebase-functions/v2/firestore';
import admin from '../admin';
import { Post } from '../types/Post';
export const createPosting = onDocumentCreated(
'boards/{boardId}/posts/{postId}',
async (event) => {
const postData = event.data?.data() as Post;
const { boardId, postId } = event.params;
if (!postData) {
console.error('No post data found.');
return null;
}
try {
await admin.firestore()
.collection('users')
.doc(postData.authorId)
.collection('postings')
.add(postingData);
console.log(`Created posting for user ${postData.authorId}`);
} catch (error) {
console.error('Error writing posting:', error);
}
return null;
}
);
Error Handling
Don’t throw – let function complete gracefully:
try {
await admin.firestore().collection('...').add(data);
console.log(`Successfully created ${resourceType}`);
} catch (error) {
console.error(`Error creating ${resourceType}:`, error);
// Don't throw - function should complete
}
return null;
Build & Test
cd functions && npm install # Install deps
cd functions && npm run build # Compile TypeScript
cd functions && npm test # Run Jest tests