firebase-rest-firestore 0.3.0 → 0.3.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/README.ja.md +71 -0
- package/README.md +17 -38
- package/dist/client.d.ts +4 -4
- package/dist/client.js +7 -8
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -218,6 +218,77 @@ export default {
|
|
|
218
218
|
};
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
+
## クイックスタート
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { createFirestoreClient } from "firebase-rest-firestore";
|
|
225
|
+
|
|
226
|
+
// 設定オブジェクトでクライアントを初期化
|
|
227
|
+
const firestore = createFirestoreClient({
|
|
228
|
+
projectId: "your-project-id",
|
|
229
|
+
privateKey: "your-private-key",
|
|
230
|
+
clientEmail: "your-client-email",
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// ドキュメントの追加
|
|
234
|
+
const newDoc = await firestore.add("collection", {
|
|
235
|
+
name: "テストドキュメント",
|
|
236
|
+
value: 100,
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// ドキュメントの取得
|
|
240
|
+
const doc = await firestore.get("collection", newDoc.id);
|
|
241
|
+
|
|
242
|
+
// ドキュメントの更新
|
|
243
|
+
await firestore.update("collection", newDoc.id, { value: 200 });
|
|
244
|
+
|
|
245
|
+
// ドキュメントのクエリ
|
|
246
|
+
const querySnapshot = await firestore
|
|
247
|
+
.collection("games")
|
|
248
|
+
.where("score", ">", 50)
|
|
249
|
+
.where("active", "==", true)
|
|
250
|
+
.orderBy("score", "desc")
|
|
251
|
+
.limit(10)
|
|
252
|
+
.get();
|
|
253
|
+
|
|
254
|
+
const games = [];
|
|
255
|
+
querySnapshot.forEach(doc => {
|
|
256
|
+
games.push({
|
|
257
|
+
id: doc.id,
|
|
258
|
+
...doc.data(),
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
console.log("Games with score > 50:", games);
|
|
262
|
+
|
|
263
|
+
// ドキュメントの削除
|
|
264
|
+
await firestore.delete("collection", newDoc.id);
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## 設定
|
|
268
|
+
|
|
269
|
+
Firestore の権限を持つ Firebase サービスアカウントが必要です:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
createFirestoreClient({
|
|
273
|
+
projectId: "your-project-id",
|
|
274
|
+
privateKey: "your-private-key", // エスケープされた改行(\\n)を含む場合、自動的にフォーマットされます
|
|
275
|
+
clientEmail: "your-client-email",
|
|
276
|
+
});
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## API リファレンス
|
|
280
|
+
|
|
281
|
+
### add(collectionName, data)
|
|
282
|
+
|
|
283
|
+
コレクションに新しいドキュメントを追加します。
|
|
284
|
+
|
|
285
|
+
パラメータ:
|
|
286
|
+
|
|
287
|
+
- `collectionName`: コレクション名
|
|
288
|
+
- `data`: 追加するドキュメントデータ
|
|
289
|
+
|
|
290
|
+
戻り値: 自動生成された ID を持つ追加されたドキュメント。
|
|
291
|
+
|
|
221
292
|
## ライセンス
|
|
222
293
|
|
|
223
294
|
MIT
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Firebase Firestore REST API client for Edge runtime environments like Cloudflare
|
|
|
19
19
|
npm install firebase-rest-firestore
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Quick Start
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
25
|
import { createFirestoreClient } from "firebase-rest-firestore";
|
|
@@ -31,33 +31,17 @@ const firestore = createFirestoreClient({
|
|
|
31
31
|
clientEmail: "your-client-email",
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
createdAt: new Date(),
|
|
39
|
-
score: 100,
|
|
40
|
-
active: true,
|
|
41
|
-
});
|
|
42
|
-
console.log("Created game ID:", gameRef.id);
|
|
43
|
-
|
|
44
|
-
// Create a document with specific ID
|
|
45
|
-
await firestore.collection("games").doc("game123").set({
|
|
46
|
-
name: "Specific Game",
|
|
47
|
-
createdAt: new Date(),
|
|
34
|
+
// Add a document
|
|
35
|
+
const newDoc = await firestore.add("collection", {
|
|
36
|
+
name: "Test Document",
|
|
37
|
+
value: 100,
|
|
48
38
|
});
|
|
49
39
|
|
|
50
40
|
// Get a document
|
|
51
|
-
const
|
|
52
|
-
if (gameDoc.exists) {
|
|
53
|
-
console.log("Fetched game:", gameDoc.data());
|
|
54
|
-
}
|
|
41
|
+
const doc = await firestore.get("collection", newDoc.id);
|
|
55
42
|
|
|
56
43
|
// Update a document
|
|
57
|
-
await firestore.
|
|
58
|
-
name: "Updated Game Name",
|
|
59
|
-
updatedAt: new Date(),
|
|
60
|
-
});
|
|
44
|
+
await firestore.update("collection", newDoc.id, { value: 200 });
|
|
61
45
|
|
|
62
46
|
// Query documents
|
|
63
47
|
const querySnapshot = await firestore
|
|
@@ -79,19 +63,7 @@ querySnapshot.forEach(doc => {
|
|
|
79
63
|
console.log("Games with score > 50:", games);
|
|
80
64
|
|
|
81
65
|
// Delete a document
|
|
82
|
-
await firestore.
|
|
83
|
-
|
|
84
|
-
// Working with subcollections
|
|
85
|
-
const commentRef = firestore
|
|
86
|
-
.collection("games")
|
|
87
|
-
.doc("game123")
|
|
88
|
-
.collection("comments")
|
|
89
|
-
.doc();
|
|
90
|
-
|
|
91
|
-
await commentRef.set({
|
|
92
|
-
text: "Great game!",
|
|
93
|
-
createdAt: new Date(),
|
|
94
|
-
});
|
|
66
|
+
await firestore.delete("collection", newDoc.id);
|
|
95
67
|
```
|
|
96
68
|
|
|
97
69
|
## Configuration
|
|
@@ -151,9 +123,16 @@ Queries documents in a collection with filtering, ordering, and pagination.
|
|
|
151
123
|
|
|
152
124
|
Creates a new FirestoreClient instance with the provided configuration.
|
|
153
125
|
|
|
154
|
-
|
|
126
|
+
#### add(collectionName, data)
|
|
127
|
+
|
|
128
|
+
Adds a new document to the specified collection.
|
|
129
|
+
|
|
130
|
+
Parameters:
|
|
131
|
+
|
|
132
|
+
- `collectionName`: Name of the collection
|
|
133
|
+
- `data`: Document data to be added
|
|
155
134
|
|
|
156
|
-
|
|
135
|
+
Returns: The added document with auto-generated ID.
|
|
157
136
|
|
|
158
137
|
## Error Handling
|
|
159
138
|
|
package/dist/client.d.ts
CHANGED
|
@@ -34,12 +34,12 @@ export declare class FirestoreClient {
|
|
|
34
34
|
*/
|
|
35
35
|
doc(path: string): DocumentReference;
|
|
36
36
|
/**
|
|
37
|
-
* Firestore
|
|
37
|
+
* Firestoreにドキュメントを追加
|
|
38
38
|
* @param collectionName コレクション名
|
|
39
|
-
* @param data
|
|
40
|
-
* @returns
|
|
39
|
+
* @param data 追加するデータ
|
|
40
|
+
* @returns 追加されたドキュメント
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
add(collectionName: string, data: Record<string, any>): Promise<Record<string, any> & {
|
|
43
43
|
id: string;
|
|
44
44
|
}>;
|
|
45
45
|
/**
|
package/dist/client.js
CHANGED
|
@@ -82,12 +82,12 @@ class FirestoreClient {
|
|
|
82
82
|
return new DocumentReference(this, collectionPath, docId);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
|
-
* Firestore
|
|
85
|
+
* Firestoreにドキュメントを追加
|
|
86
86
|
* @param collectionName コレクション名
|
|
87
|
-
* @param data
|
|
88
|
-
* @returns
|
|
87
|
+
* @param data 追加するデータ
|
|
88
|
+
* @returns 追加されたドキュメント
|
|
89
89
|
*/
|
|
90
|
-
async
|
|
90
|
+
async add(collectionName, data) {
|
|
91
91
|
// 操作前に設定をチェック
|
|
92
92
|
this.checkConfig();
|
|
93
93
|
const url = (0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName);
|
|
@@ -246,11 +246,10 @@ class FirestoreClient {
|
|
|
246
246
|
structuredQuery.offset = options.offset;
|
|
247
247
|
}
|
|
248
248
|
const token = await this.getToken();
|
|
249
|
-
//
|
|
249
|
+
// 修正: structuredQueryをラップしたリクエストボディを作成
|
|
250
250
|
const requestBody = {
|
|
251
251
|
structuredQuery: structuredQuery,
|
|
252
252
|
};
|
|
253
|
-
console.log("クエリURL:", url);
|
|
254
253
|
console.log("クエリリクエスト:", JSON.stringify(requestBody, null, 2));
|
|
255
254
|
try {
|
|
256
255
|
const response = await fetch(url, {
|
|
@@ -307,7 +306,7 @@ class CollectionReference {
|
|
|
307
306
|
* @returns 作成されたドキュメントのリファレンス
|
|
308
307
|
*/
|
|
309
308
|
async add(data) {
|
|
310
|
-
const result = await this.client.
|
|
309
|
+
const result = await this.client.add(this.path, data);
|
|
311
310
|
const docId = result.id;
|
|
312
311
|
return new DocumentReference(this.client, this.path, docId);
|
|
313
312
|
}
|
|
@@ -481,7 +480,7 @@ class DocumentReference {
|
|
|
481
480
|
else {
|
|
482
481
|
// 新規作成
|
|
483
482
|
const newData = { ...data, id: this.docId };
|
|
484
|
-
await this.client.
|
|
483
|
+
await this.client.add(this.collectionPath, newData);
|
|
485
484
|
}
|
|
486
485
|
return new WriteResult();
|
|
487
486
|
}
|