firebase-rest-firestore 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -361,5 +361,21 @@ export declare class WriteResult {
361
361
  * 新しいFirestoreクライアントインスタンスを作成
362
362
  * @param config Firestore設定オブジェクト
363
363
  * @returns FirestoreClientインスタンス
364
+ *
365
+ * @example
366
+ * // デフォルトデータベースに接続
367
+ * const db = createFirestoreClient({
368
+ * projectId: 'your-project-id',
369
+ * privateKey: 'your-private-key',
370
+ * clientEmail: 'your-client-email'
371
+ * });
372
+ *
373
+ * // 異なる名前のデータベースに接続
374
+ * const customDb = createFirestoreClient({
375
+ * projectId: 'your-project-id',
376
+ * privateKey: 'your-private-key',
377
+ * clientEmail: 'your-client-email',
378
+ * databaseId: 'your-database-id'
379
+ * });
364
380
  */
365
381
  export declare function createFirestoreClient(config: FirestoreConfig): FirestoreClient;
package/dist/client.js CHANGED
@@ -98,7 +98,7 @@ class FirestoreClient {
98
98
  async add(collectionName, data) {
99
99
  // 操作前に設定をチェック
100
100
  this.checkConfig();
101
- const url = (0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName);
101
+ const url = (0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName, this.config.databaseId);
102
102
  const firestoreData = (0, converter_1.convertToFirestoreDocument)(data);
103
103
  const token = await this.getToken();
104
104
  const response = await fetch(url, {
@@ -124,7 +124,7 @@ class FirestoreClient {
124
124
  async get(collectionName, documentId) {
125
125
  // 操作前に設定をチェック
126
126
  this.checkConfig();
127
- const url = `${(0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName)}/${documentId}`;
127
+ const url = `${(0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName, this.config.databaseId)}/${documentId}`;
128
128
  const token = await this.getToken();
129
129
  const response = await fetch(url, {
130
130
  method: "GET",
@@ -151,7 +151,7 @@ class FirestoreClient {
151
151
  async update(collectionName, documentId, data) {
152
152
  // 操作前に設定をチェック
153
153
  this.checkConfig();
154
- const url = `${(0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName)}/${documentId}`;
154
+ const url = `${(0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName, this.config.databaseId)}/${documentId}`;
155
155
  const firestoreData = (0, converter_1.convertToFirestoreDocument)(data);
156
156
  const token = await this.getToken();
157
157
  const response = await fetch(url, {
@@ -177,7 +177,7 @@ class FirestoreClient {
177
177
  async delete(collectionName, documentId) {
178
178
  // 操作前に設定をチェック
179
179
  this.checkConfig();
180
- const url = `${(0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName)}/${documentId}`;
180
+ const url = `${(0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName, this.config.databaseId)}/${documentId}`;
181
181
  const token = await this.getToken();
182
182
  const response = await fetch(url, {
183
183
  method: "DELETE",
@@ -205,7 +205,7 @@ class FirestoreClient {
205
205
  // e.g) パス形式: collectionPath = "/users/123/items" の場合は、collectionPaths = ["users", "123", "items"], collectionName = "items", basePath += "/users/123"
206
206
  // e.g) 単一形式: collectionPath = "items" の場合は、collectionPaths = ["items"], collectionName = "items", basePath += ""
207
207
  const collectionPaths = collectionPath.split("/");
208
- let basePath = `https://firestore.googleapis.com/v1/projects/${this.config.projectId}/databases/(default)/documents`;
208
+ let basePath = `https://firestore.googleapis.com/v1/projects/${this.config.projectId}/databases/${this.config.databaseId || "(default)"}/documents`;
209
209
  let collectionName = collectionPath;
210
210
  if (collectionPaths.length > 1) {
211
211
  basePath = `${basePath}/${collectionPaths.slice(0, -1).join("/")}`;
@@ -844,6 +844,22 @@ exports.WriteResult = WriteResult;
844
844
  * 新しいFirestoreクライアントインスタンスを作成
845
845
  * @param config Firestore設定オブジェクト
846
846
  * @returns FirestoreClientインスタンス
847
+ *
848
+ * @example
849
+ * // デフォルトデータベースに接続
850
+ * const db = createFirestoreClient({
851
+ * projectId: 'your-project-id',
852
+ * privateKey: 'your-private-key',
853
+ * clientEmail: 'your-client-email'
854
+ * });
855
+ *
856
+ * // 異なる名前のデータベースに接続
857
+ * const customDb = createFirestoreClient({
858
+ * projectId: 'your-project-id',
859
+ * privateKey: 'your-private-key',
860
+ * clientEmail: 'your-client-email',
861
+ * databaseId: 'your-database-id'
862
+ * });
847
863
  */
848
864
  function createFirestoreClient(config) {
849
865
  // 秘密鍵のフォーマットを確認
package/dist/types.d.ts CHANGED
@@ -5,6 +5,7 @@ export interface FirestoreConfig {
5
5
  projectId: string;
6
6
  privateKey: string;
7
7
  clientEmail: string;
8
+ databaseId?: string;
8
9
  }
9
10
  /**
10
11
  * Firestoreの値型定義
@@ -2,9 +2,10 @@
2
2
  * Firestoreのベースパスを取得
3
3
  * @param projectId プロジェクトID
4
4
  * @param collectionName コレクション名(省略可)
5
+ * @param databaseId データベースID(省略時は'(default)')
5
6
  * @returns Firestoreのベースパス
6
7
  */
7
- export declare function getFirestoreBasePath(projectId: string, collectionName?: string): string;
8
+ export declare function getFirestoreBasePath(projectId: string, collectionName?: string, databaseId?: string): string;
8
9
  /**
9
10
  * ドキュメントパスからIDを抽出
10
11
  * @param path ドキュメントパス
@@ -6,10 +6,12 @@ exports.getDocumentId = getDocumentId;
6
6
  * Firestoreのベースパスを取得
7
7
  * @param projectId プロジェクトID
8
8
  * @param collectionName コレクション名(省略可)
9
+ * @param databaseId データベースID(省略時は'(default)')
9
10
  * @returns Firestoreのベースパス
10
11
  */
11
- function getFirestoreBasePath(projectId, collectionName) {
12
- const basePath = `https://firestore.googleapis.com/v1/projects/${projectId}/databases/(default)/documents`;
12
+ function getFirestoreBasePath(projectId, collectionName, databaseId) {
13
+ const dbId = databaseId || "(default)";
14
+ const basePath = `https://firestore.googleapis.com/v1/projects/${projectId}/databases/${dbId}/documents`;
13
15
  return collectionName ? `${basePath}/${collectionName}` : basePath;
14
16
  }
15
17
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-rest-firestore",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Firebase Firestore REST API client for Edge runtime environments",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",