@lark-sh/client 0.1.12 → 0.1.13
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/index.js +52 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -885,6 +885,39 @@ function getSortedKeys(data, queryParams) {
|
|
|
885
885
|
}
|
|
886
886
|
|
|
887
887
|
// src/connection/View.ts
|
|
888
|
+
function expandPathKeys(obj) {
|
|
889
|
+
const result = {};
|
|
890
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
891
|
+
if (key.includes("/")) {
|
|
892
|
+
const segments = key.split("/").filter((s) => s.length > 0);
|
|
893
|
+
let current = result;
|
|
894
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
895
|
+
const segment = segments[i];
|
|
896
|
+
if (!(segment in current) || typeof current[segment] !== "object" || current[segment] === null) {
|
|
897
|
+
current[segment] = {};
|
|
898
|
+
}
|
|
899
|
+
current = current[segment];
|
|
900
|
+
}
|
|
901
|
+
current[segments[segments.length - 1]] = value;
|
|
902
|
+
} else {
|
|
903
|
+
result[key] = value;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return result;
|
|
907
|
+
}
|
|
908
|
+
function deepMerge(target, source) {
|
|
909
|
+
const result = { ...target };
|
|
910
|
+
for (const [key, value] of Object.entries(source)) {
|
|
911
|
+
if (value === null) {
|
|
912
|
+
delete result[key];
|
|
913
|
+
} else if (value !== null && typeof value === "object" && !Array.isArray(value) && result[key] !== null && typeof result[key] === "object" && !Array.isArray(result[key])) {
|
|
914
|
+
result[key] = deepMerge(result[key], value);
|
|
915
|
+
} else {
|
|
916
|
+
result[key] = value;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return result;
|
|
920
|
+
}
|
|
888
921
|
var View = class {
|
|
889
922
|
constructor(path, queryParams) {
|
|
890
923
|
/** Event callbacks organized by event type */
|
|
@@ -1189,29 +1222,19 @@ var View = class {
|
|
|
1189
1222
|
return this.setAtPath(base, relativePath, value);
|
|
1190
1223
|
}
|
|
1191
1224
|
if (operation === "update") {
|
|
1225
|
+
const expanded = expandPathKeys(value);
|
|
1192
1226
|
if (relativePath === "/") {
|
|
1193
1227
|
if (base === null || base === void 0 || typeof base !== "object") {
|
|
1194
1228
|
base = {};
|
|
1195
1229
|
}
|
|
1196
|
-
|
|
1197
|
-
for (const key of Object.keys(merged2)) {
|
|
1198
|
-
if (merged2[key] === null) {
|
|
1199
|
-
delete merged2[key];
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
return merged2;
|
|
1230
|
+
return deepMerge(base, expanded);
|
|
1203
1231
|
}
|
|
1204
1232
|
const current = getValueAtPath(base, relativePath);
|
|
1205
1233
|
let merged;
|
|
1206
|
-
if (current && typeof current === "object") {
|
|
1207
|
-
merged =
|
|
1208
|
-
for (const key of Object.keys(merged)) {
|
|
1209
|
-
if (merged[key] === null) {
|
|
1210
|
-
delete merged[key];
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1234
|
+
if (current && typeof current === "object" && !Array.isArray(current)) {
|
|
1235
|
+
merged = deepMerge(current, expanded);
|
|
1213
1236
|
} else {
|
|
1214
|
-
merged =
|
|
1237
|
+
merged = expanded;
|
|
1215
1238
|
}
|
|
1216
1239
|
return this.setAtPath(base, relativePath, merged);
|
|
1217
1240
|
}
|
|
@@ -3205,6 +3228,7 @@ var DatabaseReference = class _DatabaseReference {
|
|
|
3205
3228
|
while (retries < maxRetries) {
|
|
3206
3229
|
const currentSnapshot = await this.once();
|
|
3207
3230
|
const currentValue = currentSnapshot.val();
|
|
3231
|
+
const rawValue = currentSnapshot.exportVal();
|
|
3208
3232
|
const newValue = updateFunction(currentValue);
|
|
3209
3233
|
if (newValue === void 0) {
|
|
3210
3234
|
return {
|
|
@@ -3213,13 +3237,18 @@ var DatabaseReference = class _DatabaseReference {
|
|
|
3213
3237
|
};
|
|
3214
3238
|
}
|
|
3215
3239
|
let condition;
|
|
3216
|
-
if (isPrimitive(
|
|
3217
|
-
condition = { o: "c", p: this._path, v:
|
|
3240
|
+
if (isPrimitive(rawValue)) {
|
|
3241
|
+
condition = { o: "c", p: this._path, v: rawValue };
|
|
3218
3242
|
} else {
|
|
3219
|
-
const hash = await hashValue(
|
|
3243
|
+
const hash = await hashValue(rawValue);
|
|
3220
3244
|
condition = { o: "c", p: this._path, h: hash };
|
|
3221
3245
|
}
|
|
3222
|
-
|
|
3246
|
+
let valueToSet = newValue;
|
|
3247
|
+
const existingPriority = currentSnapshot.getPriority();
|
|
3248
|
+
if (existingPriority !== null && isPrimitive(newValue) && newValue !== null) {
|
|
3249
|
+
valueToSet = { ".priority": existingPriority, ".value": newValue };
|
|
3250
|
+
}
|
|
3251
|
+
const ops = [condition, { o: "s", p: this._path, v: valueToSet }];
|
|
3223
3252
|
try {
|
|
3224
3253
|
await this._db._sendTransaction(ops);
|
|
3225
3254
|
const finalSnapshot = await this.once();
|
|
@@ -3810,7 +3839,10 @@ function stripPriorityMetadata(data) {
|
|
|
3810
3839
|
if (key === ".priority") {
|
|
3811
3840
|
continue;
|
|
3812
3841
|
}
|
|
3813
|
-
|
|
3842
|
+
const stripped = stripPriorityMetadata(value);
|
|
3843
|
+
if (stripped !== null) {
|
|
3844
|
+
result[key] = stripped;
|
|
3845
|
+
}
|
|
3814
3846
|
}
|
|
3815
3847
|
return Object.keys(result).length > 0 ? result : null;
|
|
3816
3848
|
}
|