firebase-rest-firestore 1.1.1 → 1.2.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.
Files changed (2) hide show
  1. package/dist/client.js +42 -0
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -152,6 +152,48 @@ class FirestoreClient {
152
152
  // 操作前に設定をチェック
153
153
  this.checkConfig();
154
154
  const url = `${(0, path_1.getFirestoreBasePath)(this.config.projectId, collectionName, this.config.databaseId)}/${documentId}`;
155
+ // 既存のドキュメントを取得してからマージする
156
+ const existingDoc = await this.get(collectionName, documentId);
157
+ if (existingDoc) {
158
+ // ネストしたフィールドの対応
159
+ // data内にドット記法のキーがあるかチェック (例: "favorites.color")
160
+ const updateData = { ...data };
161
+ const dotNotationKeys = Object.keys(data).filter(key => key.includes("."));
162
+ if (dotNotationKeys.length > 0) {
163
+ // スプレッド演算子でコピーして元のオブジェクトを変更しないようにする
164
+ const result = { ...existingDoc };
165
+ // 通常のキーを先に適用
166
+ Object.keys(data)
167
+ .filter(key => !key.includes("."))
168
+ .forEach(key => {
169
+ result[key] = data[key];
170
+ });
171
+ // ドット記法のキーを処理
172
+ dotNotationKeys.forEach(path => {
173
+ const parts = path.split(".");
174
+ let current = result;
175
+ // 最後のパーツ以外をたどってネストしたオブジェクトに到達
176
+ for (let i = 0; i < parts.length - 1; i++) {
177
+ const part = parts[i];
178
+ // パスが存在しない場合は新しいオブジェクトを作成
179
+ if (!current[part] || typeof current[part] !== "object") {
180
+ current[part] = {};
181
+ }
182
+ current = current[part];
183
+ }
184
+ // 最後のパーツに値を設定
185
+ const lastPart = parts[parts.length - 1];
186
+ current[lastPart] = data[path];
187
+ // 元のデータからドット記法のキーを削除
188
+ delete updateData[path];
189
+ });
190
+ data = result;
191
+ }
192
+ else {
193
+ // 通常のマージ
194
+ data = { ...existingDoc, ...data };
195
+ }
196
+ }
155
197
  const firestoreData = (0, converter_1.convertToFirestoreDocument)(data);
156
198
  const token = await this.getToken();
157
199
  const response = await fetch(url, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-rest-firestore",
3
- "version": "1.1.1",
3
+ "version": "1.2.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",