@pgxsinkit/client 0.6.3 → 0.6.5

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
@@ -7402,6 +7402,13 @@ function rowKey(row, pkColumns) {
7402
7402
  }
7403
7403
  return JSON.stringify(row);
7404
7404
  }
7405
+ function keylessOccurrenceKey(key, rows, duplicates) {
7406
+ if (!rows.has(key))
7407
+ return key;
7408
+ const occurrence = (duplicates.get(key) ?? 0) + 1;
7409
+ duplicates.set(key, occurrence);
7410
+ return `${key}${KEY_SEP}${occurrence}`;
7411
+ }
7405
7412
  function rowsEqual(a, b) {
7406
7413
  const aKeys = Object.keys(a);
7407
7414
  const bKeys = Object.keys(b);
@@ -7415,8 +7422,12 @@ function rowsEqual(a, b) {
7415
7422
  }
7416
7423
  function seedLiveDiffState(rows, pkColumns) {
7417
7424
  const previous = new Map;
7418
- for (const row of rows)
7419
- previous.set(rowKey(row, pkColumns), row);
7425
+ const duplicates = pkColumns?.length ? undefined : new Map;
7426
+ for (const row of rows) {
7427
+ const baseKey = rowKey(row, pkColumns);
7428
+ const key = duplicates ? keylessOccurrenceKey(baseKey, previous, duplicates) : baseKey;
7429
+ previous.set(key, row);
7430
+ }
7420
7431
  return { ...pkColumns ? { pkColumns } : {}, previous };
7421
7432
  }
7422
7433
  function computeLiveDiff(state, nextRows) {
@@ -7424,10 +7435,12 @@ function computeLiveDiff(state, nextRows) {
7424
7435
  const added = [];
7425
7436
  const changed = [];
7426
7437
  const nextMap = new Map;
7438
+ const duplicates = state.pkColumns?.length ? undefined : new Map;
7427
7439
  for (const row of nextRows) {
7428
- const key = rowKey(row, state.pkColumns);
7429
- if (nextMap.has(key))
7440
+ const baseKey = rowKey(row, state.pkColumns);
7441
+ if (!duplicates && nextMap.has(baseKey))
7430
7442
  continue;
7443
+ const key = duplicates ? keylessOccurrenceKey(baseKey, nextMap, duplicates) : baseKey;
7431
7444
  nextMap.set(key, row);
7432
7445
  order.push(key);
7433
7446
  const prior = state.previous.get(key);
@@ -7456,8 +7469,10 @@ class LiveRowsMaterializer {
7456
7469
  seed(initialRows) {
7457
7470
  this.byKey = new Map;
7458
7471
  this.rows = [];
7472
+ const duplicates = this.pkColumns?.length ? undefined : new Map;
7459
7473
  for (const row of initialRows) {
7460
- const key = rowKey(row, this.pkColumns);
7474
+ const baseKey = rowKey(row, this.pkColumns);
7475
+ const key = duplicates ? keylessOccurrenceKey(baseKey, this.byKey, duplicates) : baseKey;
7461
7476
  this.byKey.set(key, row);
7462
7477
  this.rows.push(row);
7463
7478
  }
@@ -13069,4 +13084,4 @@ export {
13069
13084
  wrapLiveQueryForMaterialization
13070
13085
  };
13071
13086
 
13072
- //# debugId=F8970E1C5B37AF6B64756E2164756E21
13087
+ //# debugId=2BAD2E3CD9D523C664756E2164756E21