@salesforce/lds-worker-api 1.266.0-dev25 → 1.266.0-dev26

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.
@@ -1048,4 +1048,4 @@ if (process.env.NODE_ENV !== 'production') {
1048
1048
  }
1049
1049
 
1050
1050
  export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
1051
- // version: 1.266.0-dev25-c260f46ec
1051
+ // version: 1.266.0-dev26-c7c66cb1b
@@ -20,7 +20,7 @@ var SnapshotState$3;
20
20
  SnapshotState["Stale"] = "Stale";
21
21
  })(SnapshotState$3 || (SnapshotState$3 = {}));
22
22
 
23
- const { create: create$b, entries: entries$5, freeze: freeze$6, keys: keys$c, values: values$5, assign: assign$a } = Object;
23
+ const { create: create$b, entries: entries$6, freeze: freeze$6, keys: keys$c, values: values$5, assign: assign$a } = Object;
24
24
  const { hasOwnProperty: hasOwnProperty$3 } = Object.prototype;
25
25
  const { isArray: isArray$9 } = Array;
26
26
  const { push: push$5, indexOf, slice: slice$2 } = Array.prototype;
@@ -521,6 +521,25 @@ class StoreKeySet {
521
521
  }
522
522
  }
523
523
 
524
+ function defaultTrimPolicy(data, deallocateFn) {
525
+ return new Promise((resolve) => {
526
+ let deallocatedCount = 0;
527
+ const { pendingTrimKeys, retainedIds, metadata } = data;
528
+ const now = Date.now();
529
+ pendingTrimKeys.forEach((key) => {
530
+ const recordExpiration = metadata[key];
531
+ if (retainedIds[key] !== undefined ||
532
+ recordExpiration === undefined ||
533
+ (recordExpiration !== undefined && recordExpiration.expirationTimestamp >= now)) {
534
+ return;
535
+ }
536
+ deallocateFn(key);
537
+ deallocatedCount++;
538
+ });
539
+ resolve({ deallocatedCount });
540
+ });
541
+ }
542
+
524
543
  const Serialized_StringKey_Version = '1';
525
544
  function hasOverlappingIds$1(snapshot, visitedIds) {
526
545
  const { length: len } = visitedIds;
@@ -589,6 +608,7 @@ class StringKeyInMemoryStore {
589
608
  if (options.initialData) {
590
609
  this.deserialize(options.initialData, options.resetInitialDataTtls);
591
610
  }
611
+ this.trimPolicy = options.customTrimPolicy || defaultTrimPolicy;
592
612
  }
593
613
  // interface methods
594
614
  readEntry(key) {
@@ -878,6 +898,9 @@ class StringKeyInMemoryStore {
878
898
  delete this.records[canonicalKey];
879
899
  this.markVisited(canonicalKey);
880
900
  }
901
+ cleanup() {
902
+ this.scheduleTrim();
903
+ }
881
904
  /**
882
905
  * Deallocates data at the canonical key location for in-memory (L1) cache
883
906
  * @param key key to deallocate
@@ -959,22 +982,15 @@ class StringKeyInMemoryStore {
959
982
  scheduleTrim() {
960
983
  if (this.trimTask === null) {
961
984
  this.trimTask = () => {
962
- const { metadata, retainedIds, pendingTrimKeys } = this;
963
- let deallocCount = 0;
964
- const now = Date.now();
965
- pendingTrimKeys.forEach((key) => {
966
- const recordExpiration = metadata[key];
967
- if (retainedIds[key] !== undefined ||
968
- recordExpiration === undefined ||
969
- (recordExpiration !== undefined &&
970
- recordExpiration.expirationTimestamp >= now)) {
971
- return;
985
+ const { metadata, pendingTrimKeys, retainedIds, records: storeRecords, dealloc, } = this;
986
+ return this.trimPolicy({ metadata, pendingTrimKeys, retainedIds, storeRecords }, dealloc.bind(this)).then((result) => {
987
+ this.pendingTrimKeys.clear();
988
+ const { trimKeysSkipped } = result;
989
+ if (trimKeysSkipped !== undefined) {
990
+ this.pendingTrimKeys = trimKeysSkipped;
972
991
  }
973
- this.dealloc(key);
974
- deallocCount++;
992
+ return result;
975
993
  });
976
- pendingTrimKeys.clear();
977
- return deallocCount;
978
994
  };
979
995
  this.scheduler(this.trimTask, () => {
980
996
  this.trimTask = null;
@@ -1584,6 +1600,11 @@ class InMemoryStore {
1584
1600
  this.recordsMap.delete(canonicalKey);
1585
1601
  this.markVisited(canonicalKey);
1586
1602
  }
1603
+ cleanup() {
1604
+ if (this.fallbackStringKeyInMemoryStore.pendingTrimKeys.size > 0) {
1605
+ this.fallbackStringKeyInMemoryStore.cleanup();
1606
+ }
1607
+ }
1587
1608
  /**
1588
1609
  * Deallocates data at the canonical key location for in-memory (L1) cache
1589
1610
  * @param key key to deallocate
@@ -1707,7 +1728,7 @@ class InMemoryStore {
1707
1728
  deallocCount++;
1708
1729
  });
1709
1730
  pendingTrims.clear();
1710
- return deallocCount;
1731
+ return Promise.resolve({ deallocatedCount: deallocCount });
1711
1732
  };
1712
1733
  this.scheduler(this.trimTask, () => {
1713
1734
  this.trimTask = null;
@@ -3383,6 +3404,9 @@ class Environment {
3383
3404
  storeLookup(sel, createSnapshot, refresh, ttlStrategy) {
3384
3405
  return this.store.lookup(sel, createSnapshot, refresh, ttlStrategy);
3385
3406
  }
3407
+ storeCleanup() {
3408
+ this.store.cleanup();
3409
+ }
3386
3410
  storeEvict(key) {
3387
3411
  this.store.evict(key);
3388
3412
  }
@@ -3649,6 +3673,9 @@ class Luvio {
3649
3673
  storeEvict(key) {
3650
3674
  this.environment.storeEvict(key);
3651
3675
  }
3676
+ storeCleanup() {
3677
+ this.environment.storeCleanup();
3678
+ }
3652
3679
  createSnapshot(selector, refresh) {
3653
3680
  return this.environment.createSnapshot(selector, refresh);
3654
3681
  }
@@ -4037,7 +4064,7 @@ function createResourceParamsImpl(config, configMetadata) {
4037
4064
  }
4038
4065
  return resourceParams;
4039
4066
  }
4040
- // engine version: 0.154.7-dev8-fca5df34
4067
+ // engine version: 0.154.7-dev9-5ece5bc9
4041
4068
 
4042
4069
  /**
4043
4070
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -4165,7 +4192,7 @@ function withDefaultLuvio(callback) {
4165
4192
  }
4166
4193
  callbacks.push(callback);
4167
4194
  }
4168
- // version: 1.266.0-dev25-c260f46ec
4195
+ // version: 1.266.0-dev26-c7c66cb1b
4169
4196
 
4170
4197
  // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
4171
4198
  function instrumentAdapter$1(createFunction, _metadata) {
@@ -15673,7 +15700,7 @@ function gql(literals, ...subs) {
15673
15700
  }
15674
15701
  return superResult;
15675
15702
  }
15676
- // version: 1.266.0-dev25-c260f46ec
15703
+ // version: 1.266.0-dev26-c7c66cb1b
15677
15704
 
15678
15705
  function unwrap(data) {
15679
15706
  // The lwc-luvio bindings import a function from lwc called "unwrap".
@@ -16331,12 +16358,16 @@ function createImperativeAdapter(luvio, adapter, metadata) {
16331
16358
  callback(snapshotToTuple$1(snapshotOrPromise));
16332
16359
  return;
16333
16360
  }
16334
- snapshotOrPromise.then((snapshot) => {
16361
+ snapshotOrPromise
16362
+ .then((snapshot) => {
16335
16363
  if (snapshot === null) {
16336
16364
  callback(createInvalidConfigError$1());
16337
16365
  return;
16338
16366
  }
16339
16367
  callback(snapshotToTuple$1(snapshot));
16368
+ })
16369
+ .finally(() => {
16370
+ luvio.storeCleanup();
16340
16371
  });
16341
16372
  };
16342
16373
  defineProperty(imperativeAdapterInvoke, 'name', {
@@ -16598,7 +16629,7 @@ function createGraphQLWireAdapterConstructor(luvio, adapter, metadata, astResolv
16598
16629
  const { apiFamily, name } = metadata;
16599
16630
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16600
16631
  }
16601
- // version: 1.266.0-dev25-c260f46ec
16632
+ // version: 1.266.0-dev26-c7c66cb1b
16602
16633
 
16603
16634
  /**
16604
16635
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -16697,7 +16728,7 @@ var TypeCheckShapes;
16697
16728
  TypeCheckShapes[TypeCheckShapes["Integer"] = 3] = "Integer";
16698
16729
  TypeCheckShapes[TypeCheckShapes["Unsupported"] = 4] = "Unsupported";
16699
16730
  })(TypeCheckShapes || (TypeCheckShapes = {}));
16700
- // engine version: 0.154.7-dev8-fca5df34
16731
+ // engine version: 0.154.7-dev9-5ece5bc9
16701
16732
 
16702
16733
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16703
16734
 
@@ -43181,7 +43212,7 @@ withDefaultLuvio((luvio) => {
43181
43212
  throttle(60, 60000, createLDSAdapter(luvio, 'notifyListInfoUpdateAvailable', notifyUpdateAvailableFactory$1));
43182
43213
  throttle(60, 60000, createLDSAdapter(luvio, 'notifyQuickActionDefaultsUpdateAvailable', notifyUpdateAvailableFactory));
43183
43214
  });
43184
- // version: 1.266.0-dev25-12da0454b
43215
+ // version: 1.266.0-dev26-e2c3862e4
43185
43216
 
43186
43217
  var ldsIdempotencyWriteDisabled = {
43187
43218
  isOpen: function (e) {
@@ -43340,6 +43371,15 @@ var ldsPrimingGraphqlBatch = {
43340
43371
  },
43341
43372
  };
43342
43373
 
43374
+ var aggressiveTrimLowLimitGate = {
43375
+ isOpen: function (e) {
43376
+ return e.fallback;
43377
+ },
43378
+ hasError: function () {
43379
+ return !0;
43380
+ },
43381
+ };
43382
+
43343
43383
  var ldsMetadataRefreshEnabled = {
43344
43384
  isOpen: function (e) {
43345
43385
  return e.fallback;
@@ -43366,7 +43406,7 @@ var ldsMetadataRefreshEnabled = {
43366
43406
  const { parse: parse$6, stringify: stringify$6 } = JSON;
43367
43407
  const { join: join$2, push: push$2, unshift } = Array.prototype;
43368
43408
  const { isArray: isArray$5 } = Array;
43369
- const { entries: entries$4, keys: keys$8 } = Object;
43409
+ const { entries: entries$5, keys: keys$8 } = Object;
43370
43410
 
43371
43411
  const UI_API_BASE_URI = '/services/data/v60.0/ui-api';
43372
43412
 
@@ -43673,7 +43713,7 @@ function getFulfillingRequest(inflightRequests, resourceRequest) {
43673
43713
  if (fulfill === undefined) {
43674
43714
  return null;
43675
43715
  }
43676
- const handlersMap = entries$4(inflightRequests);
43716
+ const handlersMap = entries$5(inflightRequests);
43677
43717
  for (let i = 0, len = handlersMap.length; i < len; i += 1) {
43678
43718
  const [transactionKey, handlers] = handlersMap[i];
43679
43719
  // check fulfillment against only the first handler ([0]) because it's equal or
@@ -44486,7 +44526,7 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
44486
44526
  // because we do not want some other code attempting to use the
44487
44527
  // in-memory values before the durable store onChanged handler
44488
44528
  // calls back and revives the values to in-memory
44489
- environment.storeEvict(key);
44529
+ environment.storeDealloc(key);
44490
44530
  };
44491
44531
  const publishStoreMetadata = function (recordId, storeMetadata) {
44492
44532
  validateNotDisposed();
@@ -50456,7 +50496,7 @@ function isArrayLike(x) {
50456
50496
  (x.length === 0 || (x.length > 0 && Object.prototype.hasOwnProperty.call(x, x.length - 1))));
50457
50497
  }
50458
50498
 
50459
- const { create: create$4, keys: keys$4, values: values$2, entries: entries$3, assign: assign$4 } = Object;
50499
+ const { create: create$4, keys: keys$4, values: values$2, entries: entries$4, assign: assign$4 } = Object;
50460
50500
  const { stringify: stringify$4, parse: parse$4 } = JSON;
50461
50501
  const { isArray: isArray$2$1, from: from$2 } = Array;
50462
50502
 
@@ -51188,7 +51228,7 @@ function filterToPredicates(where, recordType, alias, objectInfoMap, joins, draf
51188
51228
  }
51189
51229
  else {
51190
51230
  //`field` match the filedInfo's apiName
51191
- for (const [op, value] of entries$3(where[field])) {
51231
+ for (const [op, value] of entries$4(where[field])) {
51192
51232
  const operator = operatorToSql(op);
51193
51233
  /**
51194
51234
  Two types ID processing might be needed. Draft ID swapping is optional, which depends on DraftFunctions existence.
@@ -55025,7 +55065,7 @@ function referenceIdFieldForRelationship(relationshipName) {
55025
55065
  */
55026
55066
 
55027
55067
 
55028
- const { keys: keys$3$1, values: values$1, create: create$3$1, assign: assign$3, freeze: freeze$3 } = Object;
55068
+ const { keys: keys$3$1, values: values$1, create: create$3$1, assign: assign$3, freeze: freeze$3, entries: entries$3 } = Object;
55029
55069
  const { stringify: stringify$3, parse: parse$3 } = JSON;
55030
55070
  const { shift } = Array.prototype;
55031
55071
  const { isArray: isArray$1$1, from: from$1 } = Array;
@@ -56354,7 +56394,7 @@ function getDenormalizedKey(originalKey, recordId, luvio) {
56354
56394
  }
56355
56395
  return keyBuilder$20(luvio, { recordId });
56356
56396
  }
56357
- function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecords, getStoreMetadata, getStore) {
56397
+ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecords, getStoreMetadata, getStore, sqlStore) {
56358
56398
  const getEntries = function (entries, segment) {
56359
56399
  // this HOF only inspects records in the default segment
56360
56400
  if (segment !== DefaultDurableSegment) {
@@ -56416,7 +56456,10 @@ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecord
56416
56456
  });
56417
56457
  };
56418
56458
  const denormalizeEntries = function (entries) {
56459
+ let hasEntries = false;
56460
+ let hasMetadata = false;
56419
56461
  const putEntries = create$3$1(null);
56462
+ const putMetadata = create$3$1(null);
56420
56463
  const keys$1 = keys$3$1(entries);
56421
56464
  const putRecords = {};
56422
56465
  const putRecordViews = {};
@@ -56459,6 +56502,7 @@ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecord
56459
56502
  putRecords[recordId] = true;
56460
56503
  }
56461
56504
  if (isStoreRecordError(record)) {
56505
+ hasEntries = true;
56462
56506
  putEntries[recordKey] = value;
56463
56507
  continue;
56464
56508
  }
@@ -56471,24 +56515,43 @@ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecord
56471
56515
  }
56472
56516
  const denormalizedRecord = buildDurableRecordRepresentation(record, storeRecords, recordEntries, store);
56473
56517
  if (denormalizedRecord !== undefined) {
56518
+ hasEntries = true;
56474
56519
  putEntries[recordKey] = {
56475
56520
  data: denormalizedRecord,
56476
56521
  metadata,
56477
56522
  };
56523
+ // if undefined then it is pending
56524
+ // we should still update metadata on pending records
56525
+ }
56526
+ else {
56527
+ hasMetadata = true;
56528
+ metadata.expirationTimestamp = metadata.ingestionTimestamp;
56529
+ putMetadata[recordKey] = {
56530
+ metadata,
56531
+ };
56478
56532
  }
56479
56533
  }
56480
56534
  else {
56535
+ hasEntries = true;
56481
56536
  putEntries[key] = value;
56482
56537
  }
56483
56538
  }
56484
- return putEntries;
56539
+ return { putEntries, putMetadata, hasEntries, hasMetadata };
56485
56540
  };
56486
56541
  const setEntries = function (entries, segment) {
56487
56542
  if (segment !== DefaultDurableSegment) {
56488
56543
  return durableStore.setEntries(entries, segment);
56489
56544
  }
56490
- const putEntries = denormalizeEntries(entries);
56491
- return durableStore.setEntries(putEntries, segment);
56545
+ const { putEntries, putMetadata, hasEntries, hasMetadata } = denormalizeEntries(entries);
56546
+ const promises = [
56547
+ hasEntries ? durableStore.setEntries(putEntries, segment) : undefined,
56548
+ ];
56549
+ if (sqlStore !== undefined && sqlStore.isBatchUpdateSupported()) {
56550
+ promises.push(hasMetadata && sqlStore !== undefined
56551
+ ? durableStore.setMetadata(putMetadata, segment)
56552
+ : undefined);
56553
+ }
56554
+ return Promise.all(promises).then(() => { });
56492
56555
  };
56493
56556
  const batchOperations = function (operations) {
56494
56557
  const operationsWithDenormedRecords = [];
@@ -56505,10 +56568,20 @@ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecord
56505
56568
  // this is determined by the plugin supporting update batch calls before it gets to this HOF.
56506
56569
  // so we only need to check one entry to confirm this for performance
56507
56570
  if (firstEntry.data !== undefined) {
56571
+ const { putEntries, putMetadata, hasMetadata } = denormalizeEntries(operation.entries);
56508
56572
  operationsWithDenormedRecords.push({
56509
56573
  ...operation,
56510
- entries: denormalizeEntries(operation.entries),
56574
+ entries: putEntries,
56511
56575
  });
56576
+ if (hasMetadata &&
56577
+ sqlStore !== undefined &&
56578
+ sqlStore.isBatchUpdateSupported() === true) {
56579
+ operationsWithDenormedRecords.push({
56580
+ ...operation,
56581
+ entries: putMetadata,
56582
+ type: 'setMetadata',
56583
+ });
56584
+ }
56512
56585
  }
56513
56586
  else {
56514
56587
  operationsWithDenormedRecords.push(operation);
@@ -56520,10 +56593,20 @@ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecord
56520
56593
  operationsWithDenormedRecords.push(operation);
56521
56594
  continue;
56522
56595
  }
56596
+ const { putEntries, putMetadata, hasMetadata } = denormalizeEntries(operation.entries);
56523
56597
  operationsWithDenormedRecords.push({
56524
56598
  ...operation,
56525
- entries: denormalizeEntries(operation.entries),
56599
+ entries: putEntries,
56526
56600
  });
56601
+ if (hasMetadata &&
56602
+ sqlStore !== undefined &&
56603
+ sqlStore.isBatchUpdateSupported() === true) {
56604
+ operationsWithDenormedRecords.push({
56605
+ ...operation,
56606
+ entries: putMetadata,
56607
+ type: 'setMetadata',
56608
+ });
56609
+ }
56527
56610
  }
56528
56611
  return durableStore.batchOperations(operationsWithDenormedRecords);
56529
56612
  };
@@ -59445,6 +59528,9 @@ class NimbusSqliteStore {
59445
59528
  isEvalSupported() {
59446
59529
  return true;
59447
59530
  }
59531
+ isBatchUpdateSupported() {
59532
+ return this.supportsBatchUpdates;
59533
+ }
59448
59534
  query(sql, params) {
59449
59535
  return new Promise((resolve, reject) => {
59450
59536
  this.plugin.query(sql, params, (result) => {
@@ -59487,6 +59573,7 @@ class NimbusSqliteStore {
59487
59573
  return this.batchOperationAsPromise([operation]);
59488
59574
  }
59489
59575
  batchOperations(operations) {
59576
+ let fallbackSetMetadata = [];
59490
59577
  const sqliteOperations = operations.reduce((acc, cur) => {
59491
59578
  if (cur.type === 'setEntries') {
59492
59579
  const table = this.getTable(cur.segment);
@@ -59510,7 +59597,14 @@ class NimbusSqliteStore {
59510
59597
  }
59511
59598
  return acc;
59512
59599
  }, []);
59513
- return this.batchOperationAsPromise(sqliteOperations);
59600
+ return this.batchOperationAsPromise(sqliteOperations).then(() => {
59601
+ if (fallbackSetMetadata.length > 0) {
59602
+ return Promise.all(fallbackSetMetadata.map((fallback) => {
59603
+ const { entries, segment } = fallback;
59604
+ return this.setMetadata(entries, segment);
59605
+ })).then(() => { });
59606
+ }
59607
+ });
59514
59608
  }
59515
59609
  evictEntries(entryIds, segment) {
59516
59610
  const sqliteOperation = this.idsToDeleteOperation(entryIds, segment);
@@ -60979,6 +61073,76 @@ function primingSessionFactory(config) {
60979
61073
  return instrumentPrimingSession(session);
60980
61074
  }
60981
61075
 
61076
+ const DEFAULT_MAX_RECORD_COUNT = aggressiveTrimLowLimitGate.isOpen({ fallback: false })
61077
+ ? 20000
61078
+ : 200000;
61079
+ const DEFAULT_MAX_BATCH_SIZE = 200;
61080
+ async function aggressiveTrim(data, deallocateFn, options = {}) {
61081
+ const maxStoreRecords = options.maxStoreRecords !== undefined ? options.maxStoreRecords : DEFAULT_MAX_RECORD_COUNT;
61082
+ const batchSize = options.batchSize !== undefined ? options.batchSize : DEFAULT_MAX_BATCH_SIZE;
61083
+ let deallocatedCount = 0;
61084
+ const { pendingTrimKeys, retainedIds, storeRecords } = data;
61085
+ const storeKeyLength = keys$1$1(storeRecords).length;
61086
+ if (storeKeyLength <= maxStoreRecords) {
61087
+ return { deallocatedCount, trimKeysSkipped: pendingTrimKeys };
61088
+ }
61089
+ const overFlowSize = storeKeyLength - maxStoreRecords;
61090
+ if (overFlowSize <= 0) {
61091
+ return { deallocatedCount, trimKeysSkipped: pendingTrimKeys };
61092
+ }
61093
+ const trimKeys = new Set();
61094
+ for (const key of pendingTrimKeys) {
61095
+ if (storeKeyLength - trimKeys.size <= maxStoreRecords) {
61096
+ break;
61097
+ }
61098
+ if ((retainedIds[key] === undefined && storeRecords[key] !== undefined) ||
61099
+ (retainedIds[key] !== undefined && retainedIds[key] <= 1)) {
61100
+ trimKeys.add(key);
61101
+ }
61102
+ }
61103
+ const batches = batchKeys(trimKeys, batchSize).map((batch) => {
61104
+ return () => batchToPromise(batch, deallocateFn);
61105
+ });
61106
+ for (const batch of batches) {
61107
+ // execute each batch between ticks
61108
+ const count = await batch();
61109
+ deallocatedCount = deallocatedCount + count;
61110
+ }
61111
+ const trimKeysSkipped = makeSetFilteredFromDifference(pendingTrimKeys, (key) => trimKeys.has(key) === false);
61112
+ return {
61113
+ deallocatedCount,
61114
+ trimKeysSkipped,
61115
+ };
61116
+ }
61117
+ function batchToPromise(batch, deallocateFn) {
61118
+ return new Promise((resolve) => {
61119
+ let count = 0;
61120
+ batch.forEach((key) => {
61121
+ deallocateFn(key);
61122
+ count++;
61123
+ });
61124
+ resolve(count);
61125
+ });
61126
+ }
61127
+ function batchKeys(keys, batchSize) {
61128
+ const keyArray = Array.from(keys);
61129
+ const batches = [];
61130
+ for (let i = 0, len = keyArray.length; i < len; i += batchSize) {
61131
+ const batch = keyArray.slice(i, i + batchSize);
61132
+ batches.push(batch);
61133
+ }
61134
+ return batches;
61135
+ }
61136
+ function makeSetFilteredFromDifference(setToFilter, diff) {
61137
+ let filteredSet = new Set();
61138
+ setToFilter.forEach((t) => {
61139
+ if (diff(t)) {
61140
+ filteredSet.add(t);
61141
+ }
61142
+ });
61143
+ return filteredSet;
61144
+ }
61145
+
60982
61146
  // so eslint doesn't complain about nimbus
60983
61147
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
60984
61148
  /* global __nimbus */
@@ -61007,7 +61171,11 @@ function getRuntime() {
61007
61171
  // user id centric record ID generator
61008
61172
  const { newRecordId, isGenerated } = recordIdGenerator(userId);
61009
61173
  // non-draft-aware base services
61010
- const store = new InMemoryStore();
61174
+ let storeOptions = {};
61175
+ {
61176
+ storeOptions.customTrimPolicy = aggressiveTrim;
61177
+ }
61178
+ const store = new InMemoryStore(storeOptions);
61011
61179
  lazyNetworkAdapter = platformNetworkAdapter(makeNetworkAdapterChunkRecordFields(NimbusNetworkAdapter, {
61012
61180
  reportChunkCandidateUrlLength: reportChunkCandidateUrlLength,
61013
61181
  }));
@@ -61034,7 +61202,7 @@ function getRuntime() {
61034
61202
  let getIngestRecords;
61035
61203
  let getIngestMetadata;
61036
61204
  let getIngestStore;
61037
- const recordDenormingStore = makeRecordDenormalizingDurableStore(lazyLuvio, lazyBaseDurableStore, () => (getIngestRecords !== undefined ? getIngestRecords() : {}), () => (getIngestMetadata !== undefined ? getIngestMetadata() : {}), () => (getIngestStore !== undefined ? getIngestStore() : undefined));
61205
+ const recordDenormingStore = makeRecordDenormalizingDurableStore(lazyLuvio, lazyBaseDurableStore, () => (getIngestRecords !== undefined ? getIngestRecords() : {}), () => (getIngestMetadata !== undefined ? getIngestMetadata() : {}), () => (getIngestStore !== undefined ? getIngestStore() : undefined), lazyBaseDurableStore);
61038
61206
  const baseEnv = new Environment(store, lazyNetworkAdapter);
61039
61207
  const gqlEnv = makeEnvironmentGraphqlAware(baseEnv);
61040
61208
  const durableEnv = makeDurable(gqlEnv, {
@@ -61142,7 +61310,7 @@ register$1({
61142
61310
  id: '@salesforce/lds-network-adapter',
61143
61311
  instrument: instrument$2,
61144
61312
  });
61145
- // version: 1.266.0-dev25-c260f46ec
61313
+ // version: 1.266.0-dev26-c7c66cb1b
61146
61314
 
61147
61315
  const { create: create$3, keys: keys$3 } = Object;
61148
61316
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -79543,7 +79711,7 @@ register$1({
79543
79711
  configuration: { ...configurationForGraphQLAdapters$1 },
79544
79712
  instrument: instrument$1,
79545
79713
  });
79546
- // version: 1.266.0-dev25-12da0454b
79714
+ // version: 1.266.0-dev26-e2c3862e4
79547
79715
 
79548
79716
  // On core the unstable adapters are re-exported with different names,
79549
79717
  // we want to match them here.
@@ -81797,7 +81965,7 @@ withDefaultLuvio((luvio) => {
81797
81965
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
81798
81966
  graphQLImperative = ldsAdapter;
81799
81967
  });
81800
- // version: 1.266.0-dev25-12da0454b
81968
+ // version: 1.266.0-dev26-e2c3862e4
81801
81969
 
81802
81970
  var gqlApi = /*#__PURE__*/Object.freeze({
81803
81971
  __proto__: null,
@@ -82509,7 +82677,7 @@ const callbacks$1 = [];
82509
82677
  function register(r) {
82510
82678
  callbacks$1.forEach((callback) => callback(r));
82511
82679
  }
82512
- // version: 1.266.0-dev25-c260f46ec
82680
+ // version: 1.266.0-dev26-c7c66cb1b
82513
82681
 
82514
82682
  /**
82515
82683
  * Returns true if the value acts like a Promise, i.e. has a "then" function,
@@ -87420,4 +87588,4 @@ const { luvio } = getRuntime();
87420
87588
  setDefaultLuvio({ luvio });
87421
87589
 
87422
87590
  export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, registerReportObserver, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
87423
- // version: 1.266.0-dev25-c260f46ec
87591
+ // version: 1.266.0-dev26-c7c66cb1b
@@ -26,7 +26,7 @@
26
26
  SnapshotState["Stale"] = "Stale";
27
27
  })(SnapshotState$3 || (SnapshotState$3 = {}));
28
28
 
29
- const { create: create$b, entries: entries$5, freeze: freeze$6, keys: keys$c, values: values$5, assign: assign$a } = Object;
29
+ const { create: create$b, entries: entries$6, freeze: freeze$6, keys: keys$c, values: values$5, assign: assign$a } = Object;
30
30
  const { hasOwnProperty: hasOwnProperty$3 } = Object.prototype;
31
31
  const { isArray: isArray$9 } = Array;
32
32
  const { push: push$5, indexOf, slice: slice$2 } = Array.prototype;
@@ -527,6 +527,25 @@
527
527
  }
528
528
  }
529
529
 
530
+ function defaultTrimPolicy(data, deallocateFn) {
531
+ return new Promise((resolve) => {
532
+ let deallocatedCount = 0;
533
+ const { pendingTrimKeys, retainedIds, metadata } = data;
534
+ const now = Date.now();
535
+ pendingTrimKeys.forEach((key) => {
536
+ const recordExpiration = metadata[key];
537
+ if (retainedIds[key] !== undefined ||
538
+ recordExpiration === undefined ||
539
+ (recordExpiration !== undefined && recordExpiration.expirationTimestamp >= now)) {
540
+ return;
541
+ }
542
+ deallocateFn(key);
543
+ deallocatedCount++;
544
+ });
545
+ resolve({ deallocatedCount });
546
+ });
547
+ }
548
+
530
549
  const Serialized_StringKey_Version = '1';
531
550
  function hasOverlappingIds$1(snapshot, visitedIds) {
532
551
  const { length: len } = visitedIds;
@@ -595,6 +614,7 @@
595
614
  if (options.initialData) {
596
615
  this.deserialize(options.initialData, options.resetInitialDataTtls);
597
616
  }
617
+ this.trimPolicy = options.customTrimPolicy || defaultTrimPolicy;
598
618
  }
599
619
  // interface methods
600
620
  readEntry(key) {
@@ -884,6 +904,9 @@
884
904
  delete this.records[canonicalKey];
885
905
  this.markVisited(canonicalKey);
886
906
  }
907
+ cleanup() {
908
+ this.scheduleTrim();
909
+ }
887
910
  /**
888
911
  * Deallocates data at the canonical key location for in-memory (L1) cache
889
912
  * @param key key to deallocate
@@ -965,22 +988,15 @@
965
988
  scheduleTrim() {
966
989
  if (this.trimTask === null) {
967
990
  this.trimTask = () => {
968
- const { metadata, retainedIds, pendingTrimKeys } = this;
969
- let deallocCount = 0;
970
- const now = Date.now();
971
- pendingTrimKeys.forEach((key) => {
972
- const recordExpiration = metadata[key];
973
- if (retainedIds[key] !== undefined ||
974
- recordExpiration === undefined ||
975
- (recordExpiration !== undefined &&
976
- recordExpiration.expirationTimestamp >= now)) {
977
- return;
991
+ const { metadata, pendingTrimKeys, retainedIds, records: storeRecords, dealloc, } = this;
992
+ return this.trimPolicy({ metadata, pendingTrimKeys, retainedIds, storeRecords }, dealloc.bind(this)).then((result) => {
993
+ this.pendingTrimKeys.clear();
994
+ const { trimKeysSkipped } = result;
995
+ if (trimKeysSkipped !== undefined) {
996
+ this.pendingTrimKeys = trimKeysSkipped;
978
997
  }
979
- this.dealloc(key);
980
- deallocCount++;
998
+ return result;
981
999
  });
982
- pendingTrimKeys.clear();
983
- return deallocCount;
984
1000
  };
985
1001
  this.scheduler(this.trimTask, () => {
986
1002
  this.trimTask = null;
@@ -1590,6 +1606,11 @@
1590
1606
  this.recordsMap.delete(canonicalKey);
1591
1607
  this.markVisited(canonicalKey);
1592
1608
  }
1609
+ cleanup() {
1610
+ if (this.fallbackStringKeyInMemoryStore.pendingTrimKeys.size > 0) {
1611
+ this.fallbackStringKeyInMemoryStore.cleanup();
1612
+ }
1613
+ }
1593
1614
  /**
1594
1615
  * Deallocates data at the canonical key location for in-memory (L1) cache
1595
1616
  * @param key key to deallocate
@@ -1713,7 +1734,7 @@
1713
1734
  deallocCount++;
1714
1735
  });
1715
1736
  pendingTrims.clear();
1716
- return deallocCount;
1737
+ return Promise.resolve({ deallocatedCount: deallocCount });
1717
1738
  };
1718
1739
  this.scheduler(this.trimTask, () => {
1719
1740
  this.trimTask = null;
@@ -3389,6 +3410,9 @@
3389
3410
  storeLookup(sel, createSnapshot, refresh, ttlStrategy) {
3390
3411
  return this.store.lookup(sel, createSnapshot, refresh, ttlStrategy);
3391
3412
  }
3413
+ storeCleanup() {
3414
+ this.store.cleanup();
3415
+ }
3392
3416
  storeEvict(key) {
3393
3417
  this.store.evict(key);
3394
3418
  }
@@ -3655,6 +3679,9 @@
3655
3679
  storeEvict(key) {
3656
3680
  this.environment.storeEvict(key);
3657
3681
  }
3682
+ storeCleanup() {
3683
+ this.environment.storeCleanup();
3684
+ }
3658
3685
  createSnapshot(selector, refresh) {
3659
3686
  return this.environment.createSnapshot(selector, refresh);
3660
3687
  }
@@ -4043,7 +4070,7 @@
4043
4070
  }
4044
4071
  return resourceParams;
4045
4072
  }
4046
- // engine version: 0.154.7-dev8-fca5df34
4073
+ // engine version: 0.154.7-dev9-5ece5bc9
4047
4074
 
4048
4075
  /**
4049
4076
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -4171,7 +4198,7 @@
4171
4198
  }
4172
4199
  callbacks.push(callback);
4173
4200
  }
4174
- // version: 1.266.0-dev25-c260f46ec
4201
+ // version: 1.266.0-dev26-c7c66cb1b
4175
4202
 
4176
4203
  // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
4177
4204
  function instrumentAdapter$1(createFunction, _metadata) {
@@ -15679,7 +15706,7 @@
15679
15706
  }
15680
15707
  return superResult;
15681
15708
  }
15682
- // version: 1.266.0-dev25-c260f46ec
15709
+ // version: 1.266.0-dev26-c7c66cb1b
15683
15710
 
15684
15711
  function unwrap(data) {
15685
15712
  // The lwc-luvio bindings import a function from lwc called "unwrap".
@@ -16337,12 +16364,16 @@
16337
16364
  callback(snapshotToTuple$1(snapshotOrPromise));
16338
16365
  return;
16339
16366
  }
16340
- snapshotOrPromise.then((snapshot) => {
16367
+ snapshotOrPromise
16368
+ .then((snapshot) => {
16341
16369
  if (snapshot === null) {
16342
16370
  callback(createInvalidConfigError$1());
16343
16371
  return;
16344
16372
  }
16345
16373
  callback(snapshotToTuple$1(snapshot));
16374
+ })
16375
+ .finally(() => {
16376
+ luvio.storeCleanup();
16346
16377
  });
16347
16378
  };
16348
16379
  defineProperty(imperativeAdapterInvoke, 'name', {
@@ -16604,7 +16635,7 @@
16604
16635
  const { apiFamily, name } = metadata;
16605
16636
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16606
16637
  }
16607
- // version: 1.266.0-dev25-c260f46ec
16638
+ // version: 1.266.0-dev26-c7c66cb1b
16608
16639
 
16609
16640
  /**
16610
16641
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -16703,7 +16734,7 @@
16703
16734
  TypeCheckShapes[TypeCheckShapes["Integer"] = 3] = "Integer";
16704
16735
  TypeCheckShapes[TypeCheckShapes["Unsupported"] = 4] = "Unsupported";
16705
16736
  })(TypeCheckShapes || (TypeCheckShapes = {}));
16706
- // engine version: 0.154.7-dev8-fca5df34
16737
+ // engine version: 0.154.7-dev9-5ece5bc9
16707
16738
 
16708
16739
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16709
16740
 
@@ -43187,7 +43218,7 @@
43187
43218
  throttle(60, 60000, createLDSAdapter(luvio, 'notifyListInfoUpdateAvailable', notifyUpdateAvailableFactory$1));
43188
43219
  throttle(60, 60000, createLDSAdapter(luvio, 'notifyQuickActionDefaultsUpdateAvailable', notifyUpdateAvailableFactory));
43189
43220
  });
43190
- // version: 1.266.0-dev25-12da0454b
43221
+ // version: 1.266.0-dev26-e2c3862e4
43191
43222
 
43192
43223
  var ldsIdempotencyWriteDisabled = {
43193
43224
  isOpen: function (e) {
@@ -43346,6 +43377,15 @@
43346
43377
  },
43347
43378
  };
43348
43379
 
43380
+ var aggressiveTrimLowLimitGate = {
43381
+ isOpen: function (e) {
43382
+ return e.fallback;
43383
+ },
43384
+ hasError: function () {
43385
+ return !0;
43386
+ },
43387
+ };
43388
+
43349
43389
  var ldsMetadataRefreshEnabled = {
43350
43390
  isOpen: function (e) {
43351
43391
  return e.fallback;
@@ -43372,7 +43412,7 @@
43372
43412
  const { parse: parse$6, stringify: stringify$6 } = JSON;
43373
43413
  const { join: join$2, push: push$2, unshift } = Array.prototype;
43374
43414
  const { isArray: isArray$5 } = Array;
43375
- const { entries: entries$4, keys: keys$8 } = Object;
43415
+ const { entries: entries$5, keys: keys$8 } = Object;
43376
43416
 
43377
43417
  const UI_API_BASE_URI = '/services/data/v60.0/ui-api';
43378
43418
 
@@ -43679,7 +43719,7 @@
43679
43719
  if (fulfill === undefined) {
43680
43720
  return null;
43681
43721
  }
43682
- const handlersMap = entries$4(inflightRequests);
43722
+ const handlersMap = entries$5(inflightRequests);
43683
43723
  for (let i = 0, len = handlersMap.length; i < len; i += 1) {
43684
43724
  const [transactionKey, handlers] = handlersMap[i];
43685
43725
  // check fulfillment against only the first handler ([0]) because it's equal or
@@ -44492,7 +44532,7 @@
44492
44532
  // because we do not want some other code attempting to use the
44493
44533
  // in-memory values before the durable store onChanged handler
44494
44534
  // calls back and revives the values to in-memory
44495
- environment.storeEvict(key);
44535
+ environment.storeDealloc(key);
44496
44536
  };
44497
44537
  const publishStoreMetadata = function (recordId, storeMetadata) {
44498
44538
  validateNotDisposed();
@@ -50462,7 +50502,7 @@
50462
50502
  (x.length === 0 || (x.length > 0 && Object.prototype.hasOwnProperty.call(x, x.length - 1))));
50463
50503
  }
50464
50504
 
50465
- const { create: create$4, keys: keys$4, values: values$2, entries: entries$3, assign: assign$4 } = Object;
50505
+ const { create: create$4, keys: keys$4, values: values$2, entries: entries$4, assign: assign$4 } = Object;
50466
50506
  const { stringify: stringify$4, parse: parse$4 } = JSON;
50467
50507
  const { isArray: isArray$2$1, from: from$2 } = Array;
50468
50508
 
@@ -51194,7 +51234,7 @@
51194
51234
  }
51195
51235
  else {
51196
51236
  //`field` match the filedInfo's apiName
51197
- for (const [op, value] of entries$3(where[field])) {
51237
+ for (const [op, value] of entries$4(where[field])) {
51198
51238
  const operator = operatorToSql(op);
51199
51239
  /**
51200
51240
  Two types ID processing might be needed. Draft ID swapping is optional, which depends on DraftFunctions existence.
@@ -55031,7 +55071,7 @@
55031
55071
  */
55032
55072
 
55033
55073
 
55034
- const { keys: keys$3$1, values: values$1, create: create$3$1, assign: assign$3, freeze: freeze$3 } = Object;
55074
+ const { keys: keys$3$1, values: values$1, create: create$3$1, assign: assign$3, freeze: freeze$3, entries: entries$3 } = Object;
55035
55075
  const { stringify: stringify$3, parse: parse$3 } = JSON;
55036
55076
  const { shift } = Array.prototype;
55037
55077
  const { isArray: isArray$1$1, from: from$1 } = Array;
@@ -56360,7 +56400,7 @@
56360
56400
  }
56361
56401
  return keyBuilder$20(luvio, { recordId });
56362
56402
  }
56363
- function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecords, getStoreMetadata, getStore) {
56403
+ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecords, getStoreMetadata, getStore, sqlStore) {
56364
56404
  const getEntries = function (entries, segment) {
56365
56405
  // this HOF only inspects records in the default segment
56366
56406
  if (segment !== DefaultDurableSegment) {
@@ -56422,7 +56462,10 @@
56422
56462
  });
56423
56463
  };
56424
56464
  const denormalizeEntries = function (entries) {
56465
+ let hasEntries = false;
56466
+ let hasMetadata = false;
56425
56467
  const putEntries = create$3$1(null);
56468
+ const putMetadata = create$3$1(null);
56426
56469
  const keys$1 = keys$3$1(entries);
56427
56470
  const putRecords = {};
56428
56471
  const putRecordViews = {};
@@ -56465,6 +56508,7 @@
56465
56508
  putRecords[recordId] = true;
56466
56509
  }
56467
56510
  if (isStoreRecordError(record)) {
56511
+ hasEntries = true;
56468
56512
  putEntries[recordKey] = value;
56469
56513
  continue;
56470
56514
  }
@@ -56477,24 +56521,43 @@
56477
56521
  }
56478
56522
  const denormalizedRecord = buildDurableRecordRepresentation(record, storeRecords, recordEntries, store);
56479
56523
  if (denormalizedRecord !== undefined) {
56524
+ hasEntries = true;
56480
56525
  putEntries[recordKey] = {
56481
56526
  data: denormalizedRecord,
56482
56527
  metadata,
56483
56528
  };
56529
+ // if undefined then it is pending
56530
+ // we should still update metadata on pending records
56531
+ }
56532
+ else {
56533
+ hasMetadata = true;
56534
+ metadata.expirationTimestamp = metadata.ingestionTimestamp;
56535
+ putMetadata[recordKey] = {
56536
+ metadata,
56537
+ };
56484
56538
  }
56485
56539
  }
56486
56540
  else {
56541
+ hasEntries = true;
56487
56542
  putEntries[key] = value;
56488
56543
  }
56489
56544
  }
56490
- return putEntries;
56545
+ return { putEntries, putMetadata, hasEntries, hasMetadata };
56491
56546
  };
56492
56547
  const setEntries = function (entries, segment) {
56493
56548
  if (segment !== DefaultDurableSegment) {
56494
56549
  return durableStore.setEntries(entries, segment);
56495
56550
  }
56496
- const putEntries = denormalizeEntries(entries);
56497
- return durableStore.setEntries(putEntries, segment);
56551
+ const { putEntries, putMetadata, hasEntries, hasMetadata } = denormalizeEntries(entries);
56552
+ const promises = [
56553
+ hasEntries ? durableStore.setEntries(putEntries, segment) : undefined,
56554
+ ];
56555
+ if (sqlStore !== undefined && sqlStore.isBatchUpdateSupported()) {
56556
+ promises.push(hasMetadata && sqlStore !== undefined
56557
+ ? durableStore.setMetadata(putMetadata, segment)
56558
+ : undefined);
56559
+ }
56560
+ return Promise.all(promises).then(() => { });
56498
56561
  };
56499
56562
  const batchOperations = function (operations) {
56500
56563
  const operationsWithDenormedRecords = [];
@@ -56511,10 +56574,20 @@
56511
56574
  // this is determined by the plugin supporting update batch calls before it gets to this HOF.
56512
56575
  // so we only need to check one entry to confirm this for performance
56513
56576
  if (firstEntry.data !== undefined) {
56577
+ const { putEntries, putMetadata, hasMetadata } = denormalizeEntries(operation.entries);
56514
56578
  operationsWithDenormedRecords.push({
56515
56579
  ...operation,
56516
- entries: denormalizeEntries(operation.entries),
56580
+ entries: putEntries,
56517
56581
  });
56582
+ if (hasMetadata &&
56583
+ sqlStore !== undefined &&
56584
+ sqlStore.isBatchUpdateSupported() === true) {
56585
+ operationsWithDenormedRecords.push({
56586
+ ...operation,
56587
+ entries: putMetadata,
56588
+ type: 'setMetadata',
56589
+ });
56590
+ }
56518
56591
  }
56519
56592
  else {
56520
56593
  operationsWithDenormedRecords.push(operation);
@@ -56526,10 +56599,20 @@
56526
56599
  operationsWithDenormedRecords.push(operation);
56527
56600
  continue;
56528
56601
  }
56602
+ const { putEntries, putMetadata, hasMetadata } = denormalizeEntries(operation.entries);
56529
56603
  operationsWithDenormedRecords.push({
56530
56604
  ...operation,
56531
- entries: denormalizeEntries(operation.entries),
56605
+ entries: putEntries,
56532
56606
  });
56607
+ if (hasMetadata &&
56608
+ sqlStore !== undefined &&
56609
+ sqlStore.isBatchUpdateSupported() === true) {
56610
+ operationsWithDenormedRecords.push({
56611
+ ...operation,
56612
+ entries: putMetadata,
56613
+ type: 'setMetadata',
56614
+ });
56615
+ }
56533
56616
  }
56534
56617
  return durableStore.batchOperations(operationsWithDenormedRecords);
56535
56618
  };
@@ -59451,6 +59534,9 @@
59451
59534
  isEvalSupported() {
59452
59535
  return true;
59453
59536
  }
59537
+ isBatchUpdateSupported() {
59538
+ return this.supportsBatchUpdates;
59539
+ }
59454
59540
  query(sql, params) {
59455
59541
  return new Promise((resolve, reject) => {
59456
59542
  this.plugin.query(sql, params, (result) => {
@@ -59493,6 +59579,7 @@
59493
59579
  return this.batchOperationAsPromise([operation]);
59494
59580
  }
59495
59581
  batchOperations(operations) {
59582
+ let fallbackSetMetadata = [];
59496
59583
  const sqliteOperations = operations.reduce((acc, cur) => {
59497
59584
  if (cur.type === 'setEntries') {
59498
59585
  const table = this.getTable(cur.segment);
@@ -59516,7 +59603,14 @@
59516
59603
  }
59517
59604
  return acc;
59518
59605
  }, []);
59519
- return this.batchOperationAsPromise(sqliteOperations);
59606
+ return this.batchOperationAsPromise(sqliteOperations).then(() => {
59607
+ if (fallbackSetMetadata.length > 0) {
59608
+ return Promise.all(fallbackSetMetadata.map((fallback) => {
59609
+ const { entries, segment } = fallback;
59610
+ return this.setMetadata(entries, segment);
59611
+ })).then(() => { });
59612
+ }
59613
+ });
59520
59614
  }
59521
59615
  evictEntries(entryIds, segment) {
59522
59616
  const sqliteOperation = this.idsToDeleteOperation(entryIds, segment);
@@ -60985,6 +61079,76 @@
60985
61079
  return instrumentPrimingSession(session);
60986
61080
  }
60987
61081
 
61082
+ const DEFAULT_MAX_RECORD_COUNT = aggressiveTrimLowLimitGate.isOpen({ fallback: false })
61083
+ ? 20000
61084
+ : 200000;
61085
+ const DEFAULT_MAX_BATCH_SIZE = 200;
61086
+ async function aggressiveTrim(data, deallocateFn, options = {}) {
61087
+ const maxStoreRecords = options.maxStoreRecords !== undefined ? options.maxStoreRecords : DEFAULT_MAX_RECORD_COUNT;
61088
+ const batchSize = options.batchSize !== undefined ? options.batchSize : DEFAULT_MAX_BATCH_SIZE;
61089
+ let deallocatedCount = 0;
61090
+ const { pendingTrimKeys, retainedIds, storeRecords } = data;
61091
+ const storeKeyLength = keys$1$1(storeRecords).length;
61092
+ if (storeKeyLength <= maxStoreRecords) {
61093
+ return { deallocatedCount, trimKeysSkipped: pendingTrimKeys };
61094
+ }
61095
+ const overFlowSize = storeKeyLength - maxStoreRecords;
61096
+ if (overFlowSize <= 0) {
61097
+ return { deallocatedCount, trimKeysSkipped: pendingTrimKeys };
61098
+ }
61099
+ const trimKeys = new Set();
61100
+ for (const key of pendingTrimKeys) {
61101
+ if (storeKeyLength - trimKeys.size <= maxStoreRecords) {
61102
+ break;
61103
+ }
61104
+ if ((retainedIds[key] === undefined && storeRecords[key] !== undefined) ||
61105
+ (retainedIds[key] !== undefined && retainedIds[key] <= 1)) {
61106
+ trimKeys.add(key);
61107
+ }
61108
+ }
61109
+ const batches = batchKeys(trimKeys, batchSize).map((batch) => {
61110
+ return () => batchToPromise(batch, deallocateFn);
61111
+ });
61112
+ for (const batch of batches) {
61113
+ // execute each batch between ticks
61114
+ const count = await batch();
61115
+ deallocatedCount = deallocatedCount + count;
61116
+ }
61117
+ const trimKeysSkipped = makeSetFilteredFromDifference(pendingTrimKeys, (key) => trimKeys.has(key) === false);
61118
+ return {
61119
+ deallocatedCount,
61120
+ trimKeysSkipped,
61121
+ };
61122
+ }
61123
+ function batchToPromise(batch, deallocateFn) {
61124
+ return new Promise((resolve) => {
61125
+ let count = 0;
61126
+ batch.forEach((key) => {
61127
+ deallocateFn(key);
61128
+ count++;
61129
+ });
61130
+ resolve(count);
61131
+ });
61132
+ }
61133
+ function batchKeys(keys, batchSize) {
61134
+ const keyArray = Array.from(keys);
61135
+ const batches = [];
61136
+ for (let i = 0, len = keyArray.length; i < len; i += batchSize) {
61137
+ const batch = keyArray.slice(i, i + batchSize);
61138
+ batches.push(batch);
61139
+ }
61140
+ return batches;
61141
+ }
61142
+ function makeSetFilteredFromDifference(setToFilter, diff) {
61143
+ let filteredSet = new Set();
61144
+ setToFilter.forEach((t) => {
61145
+ if (diff(t)) {
61146
+ filteredSet.add(t);
61147
+ }
61148
+ });
61149
+ return filteredSet;
61150
+ }
61151
+
60988
61152
  // so eslint doesn't complain about nimbus
60989
61153
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
60990
61154
  /* global __nimbus */
@@ -61013,7 +61177,11 @@
61013
61177
  // user id centric record ID generator
61014
61178
  const { newRecordId, isGenerated } = recordIdGenerator(userId);
61015
61179
  // non-draft-aware base services
61016
- const store = new InMemoryStore();
61180
+ let storeOptions = {};
61181
+ {
61182
+ storeOptions.customTrimPolicy = aggressiveTrim;
61183
+ }
61184
+ const store = new InMemoryStore(storeOptions);
61017
61185
  lazyNetworkAdapter = platformNetworkAdapter(makeNetworkAdapterChunkRecordFields(NimbusNetworkAdapter, {
61018
61186
  reportChunkCandidateUrlLength: reportChunkCandidateUrlLength,
61019
61187
  }));
@@ -61040,7 +61208,7 @@
61040
61208
  let getIngestRecords;
61041
61209
  let getIngestMetadata;
61042
61210
  let getIngestStore;
61043
- const recordDenormingStore = makeRecordDenormalizingDurableStore(lazyLuvio, lazyBaseDurableStore, () => (getIngestRecords !== undefined ? getIngestRecords() : {}), () => (getIngestMetadata !== undefined ? getIngestMetadata() : {}), () => (getIngestStore !== undefined ? getIngestStore() : undefined));
61211
+ const recordDenormingStore = makeRecordDenormalizingDurableStore(lazyLuvio, lazyBaseDurableStore, () => (getIngestRecords !== undefined ? getIngestRecords() : {}), () => (getIngestMetadata !== undefined ? getIngestMetadata() : {}), () => (getIngestStore !== undefined ? getIngestStore() : undefined), lazyBaseDurableStore);
61044
61212
  const baseEnv = new Environment(store, lazyNetworkAdapter);
61045
61213
  const gqlEnv = makeEnvironmentGraphqlAware(baseEnv);
61046
61214
  const durableEnv = makeDurable(gqlEnv, {
@@ -61148,7 +61316,7 @@
61148
61316
  id: '@salesforce/lds-network-adapter',
61149
61317
  instrument: instrument$2,
61150
61318
  });
61151
- // version: 1.266.0-dev25-c260f46ec
61319
+ // version: 1.266.0-dev26-c7c66cb1b
61152
61320
 
61153
61321
  const { create: create$3, keys: keys$3 } = Object;
61154
61322
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -79549,7 +79717,7 @@
79549
79717
  configuration: { ...configurationForGraphQLAdapters$1 },
79550
79718
  instrument: instrument$1,
79551
79719
  });
79552
- // version: 1.266.0-dev25-12da0454b
79720
+ // version: 1.266.0-dev26-e2c3862e4
79553
79721
 
79554
79722
  // On core the unstable adapters are re-exported with different names,
79555
79723
  // we want to match them here.
@@ -81803,7 +81971,7 @@
81803
81971
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
81804
81972
  graphQLImperative = ldsAdapter;
81805
81973
  });
81806
- // version: 1.266.0-dev25-12da0454b
81974
+ // version: 1.266.0-dev26-e2c3862e4
81807
81975
 
81808
81976
  var gqlApi = /*#__PURE__*/Object.freeze({
81809
81977
  __proto__: null,
@@ -82515,7 +82683,7 @@
82515
82683
  function register(r) {
82516
82684
  callbacks$1.forEach((callback) => callback(r));
82517
82685
  }
82518
- // version: 1.266.0-dev25-c260f46ec
82686
+ // version: 1.266.0-dev26-c7c66cb1b
82519
82687
 
82520
82688
  /**
82521
82689
  * Returns true if the value acts like a Promise, i.e. has a "then" function,
@@ -87444,4 +87612,4 @@
87444
87612
  exports.subscribeToAdapter = subscribeToAdapter;
87445
87613
 
87446
87614
  }));
87447
- // version: 1.266.0-dev25-c260f46ec
87615
+ // version: 1.266.0-dev26-c7c66cb1b
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-worker-api",
3
- "version": "1.266.0-dev25",
3
+ "version": "1.266.0-dev26",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "",
6
6
  "main": "dist/standalone/es/lds-worker-api.js",
@@ -35,15 +35,15 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@oat-sa/rollup-plugin-wildcard-external": "^1.0.0",
38
- "@salesforce/lds-adapters-graphql": "^1.266.0-dev25",
39
- "@salesforce/lds-adapters-uiapi": "^1.266.0-dev25",
40
- "@salesforce/lds-default-luvio": "^1.266.0-dev25",
41
- "@salesforce/lds-drafts": "^1.266.0-dev25",
42
- "@salesforce/lds-graphql-parser": "^1.266.0-dev25",
43
- "@salesforce/lds-luvio-engine": "^1.266.0-dev25",
44
- "@salesforce/lds-priming": "^1.266.0-dev25",
45
- "@salesforce/lds-runtime-mobile": "^1.266.0-dev25",
46
- "@salesforce/nimbus-plugin-lds": "^1.266.0-dev25",
38
+ "@salesforce/lds-adapters-graphql": "^1.266.0-dev26",
39
+ "@salesforce/lds-adapters-uiapi": "^1.266.0-dev26",
40
+ "@salesforce/lds-default-luvio": "^1.266.0-dev26",
41
+ "@salesforce/lds-drafts": "^1.266.0-dev26",
42
+ "@salesforce/lds-graphql-parser": "^1.266.0-dev26",
43
+ "@salesforce/lds-luvio-engine": "^1.266.0-dev26",
44
+ "@salesforce/lds-priming": "^1.266.0-dev26",
45
+ "@salesforce/lds-runtime-mobile": "^1.266.0-dev26",
46
+ "@salesforce/nimbus-plugin-lds": "^1.266.0-dev26",
47
47
  "ajv": "^8.11.0",
48
48
  "glob": "^7.1.5",
49
49
  "nimbus-types": "^2.0.0-alpha1",