firebase-rest-firestore 0.3.0 → 1.0.0
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 +64 -7
- package/dist/client.js +174 -25
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/package.json +5 -2
- package/dist/cjs/index.d.ts +0 -59
- package/dist/cjs/index.js +0 -388
- package/dist/esm/index.d.ts +0 -59
- package/dist/esm/index.js +0 -349
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,18 @@ export declare class FirestoreClient {
|
|
|
34
34
|
*/
|
|
35
35
|
doc(path: string): DocumentReference;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* コレクショングループリファレンスを取得
|
|
38
|
+
* @param path コレクショングループのID
|
|
39
|
+
* @returns CollectionGroupインスタンス
|
|
40
|
+
*/
|
|
41
|
+
collectionGroup(path: string): CollectionGroup;
|
|
42
|
+
/**
|
|
43
|
+
* Firestoreにドキュメントを追加
|
|
38
44
|
* @param collectionName コレクション名
|
|
39
|
-
* @param data
|
|
40
|
-
* @returns
|
|
45
|
+
* @param data 追加するデータ
|
|
46
|
+
* @returns 追加されたドキュメント
|
|
41
47
|
*/
|
|
42
|
-
|
|
48
|
+
add(collectionName: string, data: Record<string, any>): Promise<Record<string, any> & {
|
|
43
49
|
id: string;
|
|
44
50
|
}>;
|
|
45
51
|
/**
|
|
@@ -70,11 +76,12 @@ export declare class FirestoreClient {
|
|
|
70
76
|
delete(collectionName: string, documentId: string): Promise<boolean>;
|
|
71
77
|
/**
|
|
72
78
|
* コレクションのドキュメントを検索
|
|
73
|
-
* @param
|
|
79
|
+
* @param collectionPath コレクションパス
|
|
74
80
|
* @param options クエリオプション
|
|
81
|
+
* @param allDescendants 子孫コレクションを含むかどうか
|
|
75
82
|
* @returns 検索結果のドキュメント配列
|
|
76
83
|
*/
|
|
77
|
-
query(
|
|
84
|
+
query(collectionPath: string, options: QueryOptions | undefined, allDescendants: boolean): Promise<(Record<string, any> & {
|
|
78
85
|
id: string;
|
|
79
86
|
})[]>;
|
|
80
87
|
}
|
|
@@ -86,6 +93,10 @@ export declare class CollectionReference {
|
|
|
86
93
|
private path;
|
|
87
94
|
private _queryConstraints;
|
|
88
95
|
constructor(client: FirestoreClient, path: string);
|
|
96
|
+
/**
|
|
97
|
+
* すべての子孫コレクションを含むかどうか
|
|
98
|
+
*/
|
|
99
|
+
get allDescendants(): boolean;
|
|
89
100
|
/**
|
|
90
101
|
* ドキュメントリファレンスを取得
|
|
91
102
|
* @param documentPath ドキュメントID(省略時は自動生成)
|
|
@@ -184,12 +195,58 @@ export declare class DocumentReference {
|
|
|
184
195
|
*/
|
|
185
196
|
delete(): Promise<WriteResult>;
|
|
186
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* コレクショングループ
|
|
200
|
+
*/
|
|
201
|
+
export declare class CollectionGroup {
|
|
202
|
+
private client;
|
|
203
|
+
private path;
|
|
204
|
+
private _queryConstraints;
|
|
205
|
+
constructor(client: FirestoreClient, path: string);
|
|
206
|
+
/**
|
|
207
|
+
* すべての子孫コレクションを含むかどうか
|
|
208
|
+
*/
|
|
209
|
+
get allDescendants(): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* フィルター条件を追加
|
|
212
|
+
* @param fieldPath フィールドパス
|
|
213
|
+
* @param opStr 演算子
|
|
214
|
+
* @param value 値
|
|
215
|
+
* @returns Queryインスタンス
|
|
216
|
+
*/
|
|
217
|
+
where(fieldPath: string, opStr: string, value: any): Query;
|
|
218
|
+
/**
|
|
219
|
+
* 並べ替え条件を追加
|
|
220
|
+
* @param fieldPath フィールドパス
|
|
221
|
+
* @param directionStr 並べ替え方向('asc'または'desc')
|
|
222
|
+
* @returns Queryインスタンス
|
|
223
|
+
*/
|
|
224
|
+
orderBy(fieldPath: string, directionStr?: "asc" | "desc"): Query;
|
|
225
|
+
/**
|
|
226
|
+
* 取得件数の制限を設定
|
|
227
|
+
* @param limit 最大件数
|
|
228
|
+
* @returns Queryインスタンス
|
|
229
|
+
*/
|
|
230
|
+
limit(limit: number): Query;
|
|
231
|
+
/**
|
|
232
|
+
* スキップ件数を設定
|
|
233
|
+
* @param offset スキップ件数
|
|
234
|
+
* @returns Queryインスタンス
|
|
235
|
+
*/
|
|
236
|
+
offset(offset: number): Query;
|
|
237
|
+
/**
|
|
238
|
+
* クエリを実行
|
|
239
|
+
* @returns QuerySnapshotインスタンス
|
|
240
|
+
*/
|
|
241
|
+
get(): Promise<QuerySnapshot>;
|
|
242
|
+
}
|
|
187
243
|
/**
|
|
188
244
|
* クエリクラス
|
|
189
245
|
*/
|
|
190
246
|
export declare class Query {
|
|
191
247
|
private client;
|
|
192
248
|
private collectionPath;
|
|
249
|
+
private allDescendants;
|
|
193
250
|
_queryConstraints: {
|
|
194
251
|
where: Array<{
|
|
195
252
|
field: string;
|
|
@@ -211,7 +268,7 @@ export declare class Query {
|
|
|
211
268
|
orderDirection?: string;
|
|
212
269
|
limit?: number;
|
|
213
270
|
offset?: number;
|
|
214
|
-
});
|
|
271
|
+
}, allDescendants: boolean);
|
|
215
272
|
/**
|
|
216
273
|
* フィルター条件を追加
|
|
217
274
|
* @param fieldPath フィールドパス
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WriteResult = exports.DocumentSnapshot = exports.QuerySnapshot = exports.Query = exports.DocumentReference = exports.CollectionReference = exports.FirestoreClient = void 0;
|
|
3
|
+
exports.WriteResult = exports.DocumentSnapshot = exports.QuerySnapshot = exports.Query = exports.CollectionGroup = exports.DocumentReference = exports.CollectionReference = exports.FirestoreClient = void 0;
|
|
4
4
|
exports.createFirestoreClient = createFirestoreClient;
|
|
5
5
|
const auth_1 = require("./utils/auth");
|
|
6
6
|
const converter_1 = require("./utils/converter");
|
|
@@ -82,12 +82,20 @@ class FirestoreClient {
|
|
|
82
82
|
return new DocumentReference(this, collectionPath, docId);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
|
-
*
|
|
85
|
+
* コレクショングループリファレンスを取得
|
|
86
|
+
* @param path コレクショングループのID
|
|
87
|
+
* @returns CollectionGroupインスタンス
|
|
88
|
+
*/
|
|
89
|
+
collectionGroup(path) {
|
|
90
|
+
return new CollectionGroup(this, path);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Firestoreにドキュメントを追加
|
|
86
94
|
* @param collectionName コレクション名
|
|
87
|
-
* @param data
|
|
88
|
-
* @returns
|
|
95
|
+
* @param data 追加するデータ
|
|
96
|
+
* @returns 追加されたドキュメント
|
|
89
97
|
*/
|
|
90
|
-
async
|
|
98
|
+
async add(collectionName, data) {
|
|
91
99
|
// 操作前に設定をチェック
|
|
92
100
|
this.checkConfig();
|
|
93
101
|
const url = (0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName);
|
|
@@ -184,20 +192,35 @@ class FirestoreClient {
|
|
|
184
192
|
}
|
|
185
193
|
/**
|
|
186
194
|
* コレクションのドキュメントを検索
|
|
187
|
-
* @param
|
|
195
|
+
* @param collectionPath コレクションパス
|
|
188
196
|
* @param options クエリオプション
|
|
197
|
+
* @param allDescendants 子孫コレクションを含むかどうか
|
|
189
198
|
* @returns 検索結果のドキュメント配列
|
|
190
199
|
*/
|
|
191
|
-
async query(
|
|
200
|
+
async query(collectionPath, options = {}, allDescendants) {
|
|
192
201
|
// 操作前に設定をチェック
|
|
193
202
|
this.checkConfig();
|
|
194
|
-
// 修正: URLの形式を修正
|
|
195
203
|
// :runQueryはコレクション単位ではなく、ドキュメントルート単位で実行
|
|
196
|
-
|
|
204
|
+
// コレクション名パス形式の場合は、endpointをドキュメントルートに置き換える。collectionNameはコレクションIDにする
|
|
205
|
+
// e.g) パス形式: collectionPath = "/users/123/items" の場合は、collectionPaths = ["users", "123", "items"], collectionName = "items", basePath += "/users/123"
|
|
206
|
+
// e.g) 単一形式: collectionPath = "items" の場合は、collectionPaths = ["items"], collectionName = "items", basePath += ""
|
|
207
|
+
const collectionPaths = collectionPath.split("/");
|
|
208
|
+
let basePath = `https://firestore.googleapis.com/v1/projects/${this.config.projectId}/databases/(default)/documents`;
|
|
209
|
+
let collectionName = collectionPath;
|
|
210
|
+
if (collectionPaths.length > 1) {
|
|
211
|
+
basePath = `${basePath}/${collectionPaths.slice(0, -1).join("/")}`;
|
|
212
|
+
collectionName = collectionPaths[collectionPaths.length - 1];
|
|
213
|
+
}
|
|
197
214
|
const url = `${basePath}:runQuery`;
|
|
198
215
|
// クエリ構築
|
|
216
|
+
//allDescendants: falseの場合は直下のcollectionを参照。trueの場合は子孫コレクションも参照
|
|
199
217
|
const structuredQuery = {
|
|
200
|
-
from: [
|
|
218
|
+
from: [
|
|
219
|
+
{
|
|
220
|
+
collectionId: collectionName,
|
|
221
|
+
allDescendants,
|
|
222
|
+
},
|
|
223
|
+
],
|
|
201
224
|
};
|
|
202
225
|
// フィルター条件
|
|
203
226
|
if (options.where && options.where.length > 0) {
|
|
@@ -246,11 +269,10 @@ class FirestoreClient {
|
|
|
246
269
|
structuredQuery.offset = options.offset;
|
|
247
270
|
}
|
|
248
271
|
const token = await this.getToken();
|
|
249
|
-
//
|
|
272
|
+
// 修正: structuredQueryをラップしたリクエストボディを作成
|
|
250
273
|
const requestBody = {
|
|
251
274
|
structuredQuery: structuredQuery,
|
|
252
275
|
};
|
|
253
|
-
console.log("クエリURL:", url);
|
|
254
276
|
console.log("クエリリクエスト:", JSON.stringify(requestBody, null, 2));
|
|
255
277
|
try {
|
|
256
278
|
const response = await fetch(url, {
|
|
@@ -292,6 +314,12 @@ class CollectionReference {
|
|
|
292
314
|
where: [],
|
|
293
315
|
};
|
|
294
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* すべての子孫コレクションを含むかどうか
|
|
319
|
+
*/
|
|
320
|
+
get allDescendants() {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
295
323
|
/**
|
|
296
324
|
* ドキュメントリファレンスを取得
|
|
297
325
|
* @param documentPath ドキュメントID(省略時は自動生成)
|
|
@@ -307,7 +335,7 @@ class CollectionReference {
|
|
|
307
335
|
* @returns 作成されたドキュメントのリファレンス
|
|
308
336
|
*/
|
|
309
337
|
async add(data) {
|
|
310
|
-
const result = await this.client.
|
|
338
|
+
const result = await this.client.add(this.path, data);
|
|
311
339
|
const docId = result.id;
|
|
312
340
|
return new DocumentReference(this.client, this.path, docId);
|
|
313
341
|
}
|
|
@@ -321,7 +349,7 @@ class CollectionReference {
|
|
|
321
349
|
where(fieldPath, opStr, value) {
|
|
322
350
|
const query = new Query(this.client, this.path, {
|
|
323
351
|
...this._queryConstraints,
|
|
324
|
-
});
|
|
352
|
+
}, this.allDescendants);
|
|
325
353
|
// 演算子の変換
|
|
326
354
|
let firestoreOp;
|
|
327
355
|
switch (opStr) {
|
|
@@ -374,7 +402,7 @@ class CollectionReference {
|
|
|
374
402
|
orderBy(fieldPath, directionStr = "asc") {
|
|
375
403
|
const query = new Query(this.client, this.path, {
|
|
376
404
|
...this._queryConstraints,
|
|
377
|
-
});
|
|
405
|
+
}, this.allDescendants);
|
|
378
406
|
query._queryConstraints.orderBy = fieldPath;
|
|
379
407
|
query._queryConstraints.orderDirection =
|
|
380
408
|
directionStr === "asc" ? "ASCENDING" : "DESCENDING";
|
|
@@ -388,7 +416,7 @@ class CollectionReference {
|
|
|
388
416
|
limit(limit) {
|
|
389
417
|
const query = new Query(this.client, this.path, {
|
|
390
418
|
...this._queryConstraints,
|
|
391
|
-
});
|
|
419
|
+
}, this.allDescendants);
|
|
392
420
|
query._queryConstraints.limit = limit;
|
|
393
421
|
return query;
|
|
394
422
|
}
|
|
@@ -400,7 +428,7 @@ class CollectionReference {
|
|
|
400
428
|
offset(offset) {
|
|
401
429
|
const query = new Query(this.client, this.path, {
|
|
402
430
|
...this._queryConstraints,
|
|
403
|
-
});
|
|
431
|
+
}, this.allDescendants);
|
|
404
432
|
query._queryConstraints.offset = offset;
|
|
405
433
|
return query;
|
|
406
434
|
}
|
|
@@ -409,7 +437,7 @@ class CollectionReference {
|
|
|
409
437
|
* @returns QuerySnapshotインスタンス
|
|
410
438
|
*/
|
|
411
439
|
async get() {
|
|
412
|
-
const results = await this.client.query(this.path, this._queryConstraints);
|
|
440
|
+
const results = await this.client.query(this.path, this._queryConstraints, this.allDescendants);
|
|
413
441
|
return new QuerySnapshot(results);
|
|
414
442
|
}
|
|
415
443
|
/**
|
|
@@ -481,7 +509,7 @@ class DocumentReference {
|
|
|
481
509
|
else {
|
|
482
510
|
// 新規作成
|
|
483
511
|
const newData = { ...data, id: this.docId };
|
|
484
|
-
await this.client.
|
|
512
|
+
await this.client.add(this.collectionPath, newData);
|
|
485
513
|
}
|
|
486
514
|
return new WriteResult();
|
|
487
515
|
}
|
|
@@ -504,14 +532,135 @@ class DocumentReference {
|
|
|
504
532
|
}
|
|
505
533
|
}
|
|
506
534
|
exports.DocumentReference = DocumentReference;
|
|
535
|
+
/**
|
|
536
|
+
* コレクショングループ
|
|
537
|
+
*/
|
|
538
|
+
class CollectionGroup {
|
|
539
|
+
constructor(client, path) {
|
|
540
|
+
this.client = client;
|
|
541
|
+
this.path = path;
|
|
542
|
+
this._queryConstraints = {
|
|
543
|
+
where: [],
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* すべての子孫コレクションを含むかどうか
|
|
548
|
+
*/
|
|
549
|
+
get allDescendants() {
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* フィルター条件を追加
|
|
554
|
+
* @param fieldPath フィールドパス
|
|
555
|
+
* @param opStr 演算子
|
|
556
|
+
* @param value 値
|
|
557
|
+
* @returns Queryインスタンス
|
|
558
|
+
*/
|
|
559
|
+
where(fieldPath, opStr, value) {
|
|
560
|
+
const query = new Query(this.client, this.path, {
|
|
561
|
+
...this._queryConstraints,
|
|
562
|
+
}, this.allDescendants);
|
|
563
|
+
// 演算子の変換
|
|
564
|
+
let firestoreOp;
|
|
565
|
+
switch (opStr) {
|
|
566
|
+
case "==":
|
|
567
|
+
firestoreOp = "EQUAL";
|
|
568
|
+
break;
|
|
569
|
+
case "!=":
|
|
570
|
+
firestoreOp = "NOT_EQUAL";
|
|
571
|
+
break;
|
|
572
|
+
case "<":
|
|
573
|
+
firestoreOp = "LESS_THAN";
|
|
574
|
+
break;
|
|
575
|
+
case "<=":
|
|
576
|
+
firestoreOp = "LESS_THAN_OR_EQUAL";
|
|
577
|
+
break;
|
|
578
|
+
case ">":
|
|
579
|
+
firestoreOp = "GREATER_THAN";
|
|
580
|
+
break;
|
|
581
|
+
case ">=":
|
|
582
|
+
firestoreOp = "GREATER_THAN_OR_EQUAL";
|
|
583
|
+
break;
|
|
584
|
+
case "array-contains":
|
|
585
|
+
firestoreOp = "ARRAY_CONTAINS";
|
|
586
|
+
break;
|
|
587
|
+
case "in":
|
|
588
|
+
firestoreOp = "IN";
|
|
589
|
+
break;
|
|
590
|
+
case "array-contains-any":
|
|
591
|
+
firestoreOp = "ARRAY_CONTAINS_ANY";
|
|
592
|
+
break;
|
|
593
|
+
case "not-in":
|
|
594
|
+
firestoreOp = "NOT_IN";
|
|
595
|
+
break;
|
|
596
|
+
default:
|
|
597
|
+
firestoreOp = opStr;
|
|
598
|
+
}
|
|
599
|
+
query._queryConstraints.where.push({
|
|
600
|
+
field: fieldPath,
|
|
601
|
+
op: firestoreOp,
|
|
602
|
+
value,
|
|
603
|
+
});
|
|
604
|
+
return query;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* 並べ替え条件を追加
|
|
608
|
+
* @param fieldPath フィールドパス
|
|
609
|
+
* @param directionStr 並べ替え方向('asc'または'desc')
|
|
610
|
+
* @returns Queryインスタンス
|
|
611
|
+
*/
|
|
612
|
+
orderBy(fieldPath, directionStr = "asc") {
|
|
613
|
+
const query = new Query(this.client, this.path, {
|
|
614
|
+
...this._queryConstraints,
|
|
615
|
+
}, this.allDescendants);
|
|
616
|
+
query._queryConstraints.orderBy = fieldPath;
|
|
617
|
+
query._queryConstraints.orderDirection =
|
|
618
|
+
directionStr === "asc" ? "ASCENDING" : "DESCENDING";
|
|
619
|
+
return query;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* 取得件数の制限を設定
|
|
623
|
+
* @param limit 最大件数
|
|
624
|
+
* @returns Queryインスタンス
|
|
625
|
+
*/
|
|
626
|
+
limit(limit) {
|
|
627
|
+
const query = new Query(this.client, this.path, {
|
|
628
|
+
...this._queryConstraints,
|
|
629
|
+
}, this.allDescendants);
|
|
630
|
+
query._queryConstraints.limit = limit;
|
|
631
|
+
return query;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* スキップ件数を設定
|
|
635
|
+
* @param offset スキップ件数
|
|
636
|
+
* @returns Queryインスタンス
|
|
637
|
+
*/
|
|
638
|
+
offset(offset) {
|
|
639
|
+
const query = new Query(this.client, this.path, {
|
|
640
|
+
...this._queryConstraints,
|
|
641
|
+
}, this.allDescendants);
|
|
642
|
+
query._queryConstraints.offset = offset;
|
|
643
|
+
return query;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* クエリを実行
|
|
647
|
+
* @returns QuerySnapshotインスタンス
|
|
648
|
+
*/
|
|
649
|
+
async get() {
|
|
650
|
+
const results = await this.client.query(this.path, this._queryConstraints, this.allDescendants);
|
|
651
|
+
return new QuerySnapshot(results);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
exports.CollectionGroup = CollectionGroup;
|
|
507
655
|
/**
|
|
508
656
|
* クエリクラス
|
|
509
657
|
*/
|
|
510
658
|
class Query {
|
|
511
|
-
constructor(client, collectionPath, constraints) {
|
|
659
|
+
constructor(client, collectionPath, constraints, allDescendants) {
|
|
512
660
|
this.client = client;
|
|
513
661
|
this.collectionPath = collectionPath;
|
|
514
662
|
this._queryConstraints = constraints;
|
|
663
|
+
this.allDescendants = allDescendants;
|
|
515
664
|
}
|
|
516
665
|
/**
|
|
517
666
|
* フィルター条件を追加
|
|
@@ -523,7 +672,7 @@ class Query {
|
|
|
523
672
|
where(fieldPath, opStr, value) {
|
|
524
673
|
const query = new Query(this.client, this.collectionPath, {
|
|
525
674
|
...this._queryConstraints,
|
|
526
|
-
});
|
|
675
|
+
}, this.allDescendants);
|
|
527
676
|
// 演算子の変換
|
|
528
677
|
let firestoreOp;
|
|
529
678
|
switch (opStr) {
|
|
@@ -576,7 +725,7 @@ class Query {
|
|
|
576
725
|
orderBy(fieldPath, directionStr = "asc") {
|
|
577
726
|
const query = new Query(this.client, this.collectionPath, {
|
|
578
727
|
...this._queryConstraints,
|
|
579
|
-
});
|
|
728
|
+
}, this.allDescendants);
|
|
580
729
|
query._queryConstraints.orderBy = fieldPath;
|
|
581
730
|
query._queryConstraints.orderDirection =
|
|
582
731
|
directionStr === "asc" ? "ASCENDING" : "DESCENDING";
|
|
@@ -590,7 +739,7 @@ class Query {
|
|
|
590
739
|
limit(limit) {
|
|
591
740
|
const query = new Query(this.client, this.collectionPath, {
|
|
592
741
|
...this._queryConstraints,
|
|
593
|
-
});
|
|
742
|
+
}, this.allDescendants);
|
|
594
743
|
query._queryConstraints.limit = limit;
|
|
595
744
|
return query;
|
|
596
745
|
}
|
|
@@ -602,7 +751,7 @@ class Query {
|
|
|
602
751
|
offset(offset) {
|
|
603
752
|
const query = new Query(this.client, this.collectionPath, {
|
|
604
753
|
...this._queryConstraints,
|
|
605
|
-
});
|
|
754
|
+
}, this.allDescendants);
|
|
606
755
|
query._queryConstraints.offset = offset;
|
|
607
756
|
return query;
|
|
608
757
|
}
|
|
@@ -611,7 +760,7 @@ class Query {
|
|
|
611
760
|
* @returns QuerySnapshotインスタンス
|
|
612
761
|
*/
|
|
613
762
|
async get() {
|
|
614
|
-
const results = await this.client.query(this.collectionPath, this._queryConstraints);
|
|
763
|
+
const results = await this.client.query(this.collectionPath, this._queryConstraints, this.allDescendants);
|
|
615
764
|
return new QuerySnapshot(results);
|
|
616
765
|
}
|
|
617
766
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./types";
|
|
2
|
-
import { FirestoreClient, createFirestoreClient, CollectionReference, DocumentReference, Query, QuerySnapshot, DocumentSnapshot, WriteResult } from "./client";
|
|
2
|
+
import { FirestoreClient, createFirestoreClient, CollectionReference, DocumentReference, CollectionGroup, Query, QuerySnapshot, DocumentSnapshot, WriteResult } from "./client";
|
|
3
3
|
export { getFirestoreToken } from "./utils/auth";
|
|
4
4
|
export { convertToFirestoreValue, convertFromFirestoreValue, convertToFirestoreDocument, convertFromFirestoreDocument, } from "./utils/converter";
|
|
5
5
|
export { getFirestoreBasePath, getDocumentId } from "./utils/path";
|
|
6
6
|
export { formatPrivateKey, formatConfig } from "./utils/config";
|
|
7
|
-
export { FirestoreClient, createFirestoreClient, CollectionReference, DocumentReference, Query, QuerySnapshot, DocumentSnapshot, WriteResult, };
|
|
7
|
+
export { FirestoreClient, createFirestoreClient, CollectionReference, DocumentReference, CollectionGroup, Query, QuerySnapshot, DocumentSnapshot, WriteResult, };
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.WriteResult = exports.DocumentSnapshot = exports.QuerySnapshot = exports.Query = exports.DocumentReference = exports.CollectionReference = exports.createFirestoreClient = exports.FirestoreClient = exports.formatConfig = exports.formatPrivateKey = exports.getDocumentId = exports.getFirestoreBasePath = exports.convertFromFirestoreDocument = exports.convertToFirestoreDocument = exports.convertFromFirestoreValue = exports.convertToFirestoreValue = exports.getFirestoreToken = void 0;
|
|
17
|
+
exports.WriteResult = exports.DocumentSnapshot = exports.QuerySnapshot = exports.Query = exports.CollectionGroup = exports.DocumentReference = exports.CollectionReference = exports.createFirestoreClient = exports.FirestoreClient = exports.formatConfig = exports.formatPrivateKey = exports.getDocumentId = exports.getFirestoreBasePath = exports.convertFromFirestoreDocument = exports.convertToFirestoreDocument = exports.convertFromFirestoreValue = exports.convertToFirestoreValue = exports.getFirestoreToken = void 0;
|
|
18
18
|
// 型定義のエクスポート
|
|
19
19
|
__exportStar(require("./types"), exports);
|
|
20
20
|
// クライアントのエクスポート
|
|
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "FirestoreClient", { enumerable: true, get: funct
|
|
|
23
23
|
Object.defineProperty(exports, "createFirestoreClient", { enumerable: true, get: function () { return client_1.createFirestoreClient; } });
|
|
24
24
|
Object.defineProperty(exports, "CollectionReference", { enumerable: true, get: function () { return client_1.CollectionReference; } });
|
|
25
25
|
Object.defineProperty(exports, "DocumentReference", { enumerable: true, get: function () { return client_1.DocumentReference; } });
|
|
26
|
+
Object.defineProperty(exports, "CollectionGroup", { enumerable: true, get: function () { return client_1.CollectionGroup; } });
|
|
26
27
|
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return client_1.Query; } });
|
|
27
28
|
Object.defineProperty(exports, "QuerySnapshot", { enumerable: true, get: function () { return client_1.QuerySnapshot; } });
|
|
28
29
|
Object.defineProperty(exports, "DocumentSnapshot", { enumerable: true, get: function () { return client_1.DocumentSnapshot; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebase-rest-firestore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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",
|
|
@@ -29,13 +29,16 @@
|
|
|
29
29
|
"jose": "^4.14.4"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
33
|
+
"@semantic-release/git": "^10.0.1",
|
|
32
34
|
"@types/node": "^18.16.0",
|
|
33
35
|
"dotenv": "^16.4.7",
|
|
36
|
+
"semantic-release": "^24.2.3",
|
|
34
37
|
"typescript": "^5.0.4",
|
|
35
38
|
"vitest": "^3.0.9"
|
|
36
39
|
},
|
|
37
40
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
41
|
+
"node": ">=20.8.1"
|
|
39
42
|
},
|
|
40
43
|
"repository": {
|
|
41
44
|
"type": "git",
|