mcpField
F
firebase-functions

firebase-functions

github.com/bumgeunsong開発945 回インストール1 週間前に更新
リポジトリ

firebase-functions について

firebase-functionsは、Firebase Functionsプロジェクトの開発パターンをまとめたスキルです。TypeScript関数の構成、エラー処理、ビルドとテストの手順を扱い、Firestoreトリガーを保守する開発者向けです。

主な機能

  1. 01関数ディレクトリ構成の提示
  2. 02Firestoreトリガーの例
  3. 03エラー処理パターンの説明
  4. 04ビルドとJestテストのコマンド

活用シーン

  1. 01Firebase Functionsの構成を計画
  2. 02Firestore文書作成トリガーの実装
  3. 03非同期関数処理のエラー対応
  4. 04関数のビルドとテスト実行

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/bumgeunsong/daily-writing-friends --skill firebase-functions

インストール後、Claude Code で/firebase-functionsを入力して読み込まれたか確認します。

詳細

Firebase Functions のパターン

ディレクトリ構造

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

関数の構造

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;
  }
);

エラー処理

エラーをスローせず、関数を正常に完了させます:

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;

ビルドとテスト

cd functions && npm install   # Install deps
cd functions && npm run build # Compile TypeScript
cd functions && npm test      # Run Jest tests

コメント