firebase-rest-firestore 1.1.2 → 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.
- package/dist/client.js +38 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -155,7 +155,44 @@ class FirestoreClient {
|
|
|
155
155
|
// 既存のドキュメントを取得してからマージする
|
|
156
156
|
const existingDoc = await this.get(collectionName, documentId);
|
|
157
157
|
if (existingDoc) {
|
|
158
|
-
|
|
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
|
+
}
|
|
159
196
|
}
|
|
160
197
|
const firestoreData = (0, converter_1.convertToFirestoreDocument)(data);
|
|
161
198
|
const token = await this.getToken();
|