@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 CHANGED
@@ -930,6 +930,39 @@ function getSortedKeys(data, queryParams) {
930
930
  }
931
931
 
932
932
  // src/connection/View.ts
933
+ function expandPathKeys(obj) {
934
+ const result = {};
935
+ for (const [key, value] of Object.entries(obj)) {
936
+ if (key.includes("/")) {
937
+ const segments = key.split("/").filter((s) => s.length > 0);
938
+ let current = result;
939
+ for (let i = 0; i < segments.length - 1; i++) {
940
+ const segment = segments[i];
941
+ if (!(segment in current) || typeof current[segment] !== "object" || current[segment] === null) {
942
+ current[segment] = {};
943
+ }
944
+ current = current[segment];
945
+ }
946
+ current[segments[segments.length - 1]] = value;
947
+ } else {
948
+ result[key] = value;
949
+ }
950
+ }
951
+ return result;
952
+ }
953
+ function deepMerge(target, source) {
954
+ const result = { ...target };
955
+ for (const [key, value] of Object.entries(source)) {
956
+ if (value === null) {
957
+ delete result[key];
958
+ } else if (value !== null && typeof value === "object" && !Array.isArray(value) && result[key] !== null && typeof result[key] === "object" && !Array.isArray(result[key])) {
959
+ result[key] = deepMerge(result[key], value);
960
+ } else {
961
+ result[key] = value;
962
+ }
963
+ }
964
+ return result;
965
+ }
933
966
  var View = class {
934
967
  constructor(path, queryParams) {
935
968
  /** Event callbacks organized by event type */
@@ -1234,29 +1267,19 @@ var View = class {
1234
1267
  return this.setAtPath(base, relativePath, value);
1235
1268
  }
1236
1269
  if (operation === "update") {
1270
+ const expanded = expandPathKeys(value);
1237
1271
  if (relativePath === "/") {
1238
1272
  if (base === null || base === void 0 || typeof base !== "object") {
1239
1273
  base = {};
1240
1274
  }
1241
- const merged2 = { ...base, ...value };
1242
- for (const key of Object.keys(merged2)) {
1243
- if (merged2[key] === null) {
1244
- delete merged2[key];
1245
- }
1246
- }
1247
- return merged2;
1275
+ return deepMerge(base, expanded);
1248
1276
  }
1249
1277
  const current = getValueAtPath(base, relativePath);
1250
1278
  let merged;
1251
- if (current && typeof current === "object") {
1252
- merged = { ...current, ...value };
1253
- for (const key of Object.keys(merged)) {
1254
- if (merged[key] === null) {
1255
- delete merged[key];
1256
- }
1257
- }
1279
+ if (current && typeof current === "object" && !Array.isArray(current)) {
1280
+ merged = deepMerge(current, expanded);
1258
1281
  } else {
1259
- merged = value;
1282
+ merged = expanded;
1260
1283
  }
1261
1284
  return this.setAtPath(base, relativePath, merged);
1262
1285
  }
@@ -3250,6 +3273,7 @@ var DatabaseReference = class _DatabaseReference {
3250
3273
  while (retries < maxRetries) {
3251
3274
  const currentSnapshot = await this.once();
3252
3275
  const currentValue = currentSnapshot.val();
3276
+ const rawValue = currentSnapshot.exportVal();
3253
3277
  const newValue = updateFunction(currentValue);
3254
3278
  if (newValue === void 0) {
3255
3279
  return {
@@ -3258,13 +3282,18 @@ var DatabaseReference = class _DatabaseReference {
3258
3282
  };
3259
3283
  }
3260
3284
  let condition;
3261
- if (isPrimitive(currentValue)) {
3262
- condition = { o: "c", p: this._path, v: currentValue };
3285
+ if (isPrimitive(rawValue)) {
3286
+ condition = { o: "c", p: this._path, v: rawValue };
3263
3287
  } else {
3264
- const hash = await hashValue(currentValue);
3288
+ const hash = await hashValue(rawValue);
3265
3289
  condition = { o: "c", p: this._path, h: hash };
3266
3290
  }
3267
- const ops = [condition, { o: "s", p: this._path, v: newValue }];
3291
+ let valueToSet = newValue;
3292
+ const existingPriority = currentSnapshot.getPriority();
3293
+ if (existingPriority !== null && isPrimitive(newValue) && newValue !== null) {
3294
+ valueToSet = { ".priority": existingPriority, ".value": newValue };
3295
+ }
3296
+ const ops = [condition, { o: "s", p: this._path, v: valueToSet }];
3268
3297
  try {
3269
3298
  await this._db._sendTransaction(ops);
3270
3299
  const finalSnapshot = await this.once();
@@ -3855,7 +3884,10 @@ function stripPriorityMetadata(data) {
3855
3884
  if (key === ".priority") {
3856
3885
  continue;
3857
3886
  }
3858
- result[key] = stripPriorityMetadata(value);
3887
+ const stripped = stripPriorityMetadata(value);
3888
+ if (stripped !== null) {
3889
+ result[key] = stripped;
3890
+ }
3859
3891
  }
3860
3892
  return Object.keys(result).length > 0 ? result : null;
3861
3893
  }