Home

Firebaseの権限をIAMで管理する

November 28, 2021

Google 公式の説明を引用しつつ適宜補足します。 基本的に Firebase の権限を管理するには Firebase IAM を利用します。Firebase IAM で可能な粒度よりもさらに細かく設定 ...

Firestoreを定期バックアップする

November 27, 2021

Google 公式の手引きに従って実施ください、の一言で終わってしまいそうですが、備忘録もかねて記載します。 公式ドキュメント データのエクスポートをスケジ ...

GitHub ActionsでTypeScriptとESLintとPrettierの検査を行う

November 20, 2021

以下を参考に package.json 及びワークフロー定義を作成してください。 package.json # package.json { "scripts": { "lint:tsc": "tsc --noEmit", "lint:eslint": "eslint src --ext .js,.jsx,.ts,.tsx", "lint:prettier": "prettier --check src" } } 上記は src ディレクトリ下に検査対象のファイルが配 ...

GitHub ActionsでNext.jsをS3にデプロイする

November 13, 2021

Next.js の Static HTML Export で生成した資産を Amazon S3 にデプロイする方法について。 昔初めて作った上記ワークフローが見つかったので、削除する前に思い出として残しておき ...

TypeScriptで引数に応じて戻り値の型を変える

November 10, 2021

引数に応じて戻り値の型は変化しない # 例えば以下の関数と実行結果があるとして、age の型は何になるでしょうか? const getAge = (shouldString: boolean) => { return shouldString ? '20' : 20; }; const age ...

TypeScript:シードデータ生成などで使える便利関数

November 3, 2021

ダミーデータを作る際、基本的には何らかのライブラリを使うことが多いのではないでしょうか。 私はよく Faker.js を利用しています。 Marak/faker.js: generate massive amounts of realistic fake data in Node.js and the ...

TypeScriptやESLintのエラーを無効化する魔法の呪文

November 1, 2021

自分用にメモ。どう書くのだっけと都度微妙にググり作業が発生しているので。 TypeScript # 次の1行を無視: @ts-ignore # let x = 1; // @ts-ignore x = 'a'; FYI: TypeScript: Documentation - TypeScript 2.6 - @ts-ignore ファイル内 ...

Next.js(TypeScript)にESLintとPrettierを入れる手順

October 17, 2021

自分用の備忘録です。頻繁に実施するものでもなく、記憶が薄れがちなので。 パッケージをインストール # ESLint をインストール # eslint npm install --save-dev eslint ESLint の Parser をインスト ...

The way to split the file of Cloud Firestore Security Rules

September 26, 2021

This article is a translation of a Japanese article I posted earlier. Original article firestore.rules in the Firebase project generated by the Firebase CLI is the file that defines the security rules. The initial contents are as follows. rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if false; } } } All the security rules will be written in this file, but it’s not hard to imagine that the content of this file will become so large that you will get tired of it one day. ...

The way to split the file of Cloud Functions Triggers

September 25, 2021

This article is a translation of a Japanese article I posted earlier. Original article After init of the Firebase CLI, the files related to Cloud Functions will be as follows (In the case of TypeScript). └ functions/ ├ (ohter files) ├ lib/ └ src/ └ index.ts All you have to do is write the trigger function in index.ts However, if you create a lot of triggers, you will definitely be tempted to split the files, right? ...

The way to convert all Timestamps to Date after getting data from Firestore

September 24, 2021

This article is a translation of a Japanese article I posted earlier. Original article One of the Firestore data types is the Timestamp type. This is a proprietary type of Firestore. Timestamp has a toDate() method that can be called to convert data to Date type of JavaScript. After getting data on the client side, it is a common practice to call toDate() first when using the data. If all Timestamps in a document can be treated as Date type on the client side, it is useful to make a function that execute toDate() on all Timestamp fields of the getting document. ...

Cloud Firestoreのセキュリティルールファイルを分割する

September 18, 2021

Firebase CLI で生成された Firebase プロジェクト内の firestore.rules がセキュリティルールを定義するファイルです。 初期状態の内容は以下です。 rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if false; ...

Cloud Functionsのトリガーファイルを分割する

September 17, 2021

Firebase CLI の init 後の初期状態では Cloud Functions 関連のファイルは以下となっているはずです。(TypeScript の場合) └ functions/ ├ その他ファイルたち ├ lib/ └ src/ └ index.ts あと ...

Firestoreの全ドキュメントを削除する処理

September 15, 2021

例えばローカルのエミュレータ環境の Firestore へシードデータを流す際、シーディングの初期化処理としてデータを全削除したいというシチュエーションはよくあ ...

TypeScriptで関数の引数や戻り値から型を取得する

August 28, 2021

関数の引数から型を取得 # Parameters<typeof (function name)> const greet = (name: string, word: 'Hello' | 'Good Bye') => { return `${word}, ${name}!`; }; type Args = Parameters<typeof greet>; // [name: string, word: "Hello" | "Good Bye"] type firstArg = Args['0']; // string type secondArg = Args['1']; // "Hello" | "Good Bye" 関数の戻り値から型を取 ...