@salesforce/lds-worker-api 1.246.0 → 1.248.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.
@@ -916,36 +916,47 @@ var DraftQueueOperationType;
916
916
 
917
917
  var EvictStatus;
918
918
  (function (EvictStatus) {
919
- EvictStatus["InProgress"] = "InProgress";
919
+ EvictStatus["Started"] = "Started";
920
+ EvictStatus["Running"] = "Running";
921
+ EvictStatus["Evicted"] = "Evicted";
920
922
  EvictStatus["Succeeded"] = "Succeeded";
921
923
  EvictStatus["Error"] = "Error";
922
- EvictStatus["Cancelled"] = "Cancelled";
924
+ EvictStatus["Canceled"] = "Canceled";
923
925
  })(EvictStatus || (EvictStatus = {}));
924
926
  const MessagingDurableSegmentName = 'MESSAGING';
925
927
  const DEFAULT_MAX_ENTRIES_PER_OPERATION = 500;
928
+ const EVICTION_IN_PROGESS_MESSAGE = `Cache eviction in progress. Can't start another until it is finished or canceled.`;
926
929
  /**
927
- * Keep tracking of ongoing eviction id to a flag to trigger eviction cancellation.
928
- * false in the begining, set to true when cancelEviction is called.
930
+ * Only one eviction is allowed at a time. running status is return when evictCacheRecordsByIds or
931
+ * evictExpiredCacheEntries is called if there's already an eviction in progress.
929
932
  */
930
- const evictionCancellationFlag = new Map();
933
+ var currentEvictionId = '';
934
+ var cancelCurrentEviction = false;
931
935
  /**
932
936
  * Purging records specified by an array of record id from durable store
933
937
  * @param recordIds record id array
934
938
  * @onProgressUpdate call back to report evict progress
935
939
  *
936
- * @returns evictId, call cancelEviction with it to abort the eviction.
940
+ * @returns started or already running based whether there's an active eviction going on or not.
937
941
  *
938
942
  * The record will not be purged if the record has draft.
939
943
  */
940
944
  function evictCacheRecordsByIds(recordIds, onProgressUpdate) {
941
- const evictionId = uuidv4();
942
- evictionCancellationFlag.set(evictionId, false);
945
+ // Send error back if an eviction is going on.
946
+ if (currentEvictionId) {
947
+ return {
948
+ status: EvictStatus.Running,
949
+ message: EVICTION_IN_PROGESS_MESSAGE,
950
+ };
951
+ }
952
+ currentEvictionId = uuidv4();
953
+ cancelCurrentEviction = false;
943
954
  const evictAChunk = () => {
944
955
  evictChunksOfRecord(recordIds).then(onEvicted);
945
956
  };
946
- const onEvicted = getOnEvictedCallback(onProgressUpdate, evictionId, evictAChunk);
957
+ const onEvicted = getOnEvictedCallback(onProgressUpdate, evictAChunk);
947
958
  evictAChunk();
948
- return evictionId;
959
+ return { status: EvictStatus.Started };
949
960
  }
950
961
  /**
951
962
  * Purging the db entries which passed expired time by specified days
@@ -953,49 +964,53 @@ function evictCacheRecordsByIds(recordIds, onProgressUpdate) {
953
964
  * @param expiredByDays
954
965
  * @param onProgressUpdate
955
966
  *
956
- * @returns an evictId, call cancelEviction with it to abort the eviction.
967
+ * @returns started or already running based whether there's an active eviction going on or not.
957
968
  *
958
969
  * Important: records with draft, objectInfo entries will not be purged even expired by the specified days.
959
970
  */
960
971
  function evictExpiredCacheEntries(expiredByDays, onProgressUpdate) {
961
- const evictionId = uuidv4();
962
- evictionCancellationFlag.set(evictionId, false);
972
+ // Send error back if an eviction is going on.
973
+ if (currentEvictionId) {
974
+ return {
975
+ status: EvictStatus.Running,
976
+ message: EVICTION_IN_PROGESS_MESSAGE,
977
+ };
978
+ }
979
+ currentEvictionId = uuidv4();
980
+ cancelCurrentEviction = false;
963
981
  const overdueExpirationTimeStamp = Date.now() - expiredByDays * 24 * 3600 * 1000;
964
982
  const evictAChunk = () => {
965
983
  evictChunkOfOverdueEntries(overdueExpirationTimeStamp).then(onEvicted);
966
984
  };
967
- const onEvicted = getOnEvictedCallback(onProgressUpdate, evictionId, evictAChunk);
985
+ const onEvicted = getOnEvictedCallback(onProgressUpdate, evictAChunk);
968
986
  evictAChunk();
969
- return evictionId;
987
+ return { status: EvictStatus.Started };
970
988
  }
971
989
  /**
972
- * Cancel the eviction by specified id.
973
- * Signal to cancel the eviction if the eviction is going on.
974
- * @param evictionId
990
+ * Signal to stop current eviction if there's an active eviction going on.
975
991
  */
976
- function cancelEviction(evictionId) {
977
- if (evictionCancellationFlag.has(evictionId)) {
978
- evictionCancellationFlag.set(evictionId, true);
992
+ function stopEviction() {
993
+ if (currentEvictionId) {
994
+ cancelCurrentEviction = true;
979
995
  }
980
996
  }
981
997
  /**
982
998
  * Get a callback function when a chunk of records or entries are removed.
983
999
  * @param onProgressUpdate
984
- * @param evictionId
985
1000
  * @param evictAChunk
986
1001
  * @returns a callback to call when a chunk of records or entries are removed.
987
1002
  */
988
- function getOnEvictedCallback(onProgressUpdate, evictionId, evictAChunk) {
1003
+ function getOnEvictedCallback(onProgressUpdate, evictAChunk) {
989
1004
  return (progress) => {
990
1005
  onProgressUpdate(progress);
991
1006
  const { status } = progress;
992
1007
  if (status === EvictStatus.Succeeded || status === EvictStatus.Error) {
993
- evictionCancellationFlag.delete(evictionId);
1008
+ currentEvictionId = '';
994
1009
  }
995
- if (status === EvictStatus.InProgress) {
996
- if (evictionCancellationFlag.get(evictionId)) {
997
- evictionCancellationFlag.delete(evictionId);
998
- onProgressUpdate({ status: EvictStatus.Cancelled });
1010
+ if (status === EvictStatus.Evicted) {
1011
+ if (cancelCurrentEviction) {
1012
+ currentEvictionId = '';
1013
+ onProgressUpdate({ status: EvictStatus.Canceled });
999
1014
  }
1000
1015
  else {
1001
1016
  evictAChunk();
@@ -1032,7 +1047,7 @@ function evictChunksOfRecord(ids) {
1032
1047
  nimbusSqliteStore.setEntries({ notifyStoreUpdateAvailable: { data: evictedEntries } }, MessagingDurableSegmentName);
1033
1048
  }
1034
1049
  resolve({
1035
- status: EvictStatus.InProgress,
1050
+ status: EvictStatus.Evicted,
1036
1051
  evictedEntries,
1037
1052
  skippedEntries,
1038
1053
  });
@@ -1085,7 +1100,7 @@ function evictChunkOfOverdueEntries(overdueExpirationTimestamp) {
1085
1100
  // broadcast entries evicted
1086
1101
  nimbusSqliteStore.setEntries({ notifyStoreUpdateAvailable: { data: evictedEntries } }, MessagingDurableSegmentName);
1087
1102
  resolve({
1088
- status: EvictStatus.InProgress,
1103
+ status: EvictStatus.Evicted,
1089
1104
  evictedEntries,
1090
1105
  skippedEntries: [],
1091
1106
  });
@@ -1119,5 +1134,5 @@ if (process.env.NODE_ENV !== 'production') {
1119
1134
  });
1120
1135
  }
1121
1136
 
1122
- export { cancelEviction, createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
1123
- // version: 1.246.0-8357100fc
1137
+ export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
1138
+ // version: 1.248.0-1f7f01112
@@ -1,11 +1,20 @@
1
1
  declare enum EvictStatus {
2
- InProgress = "InProgress",
2
+ Started = "Started",
3
+ Running = "Running",
4
+ Evicted = "Evicted",
3
5
  Succeeded = "Succeeded",
4
6
  Error = "Error",
5
- Cancelled = "Cancelled"
7
+ Canceled = "Canceled"
6
8
  }
7
- interface EvictInProgress {
8
- status: EvictStatus.InProgress;
9
+ interface EvictStarted {
10
+ status: EvictStatus.Started;
11
+ }
12
+ interface EvictRunning {
13
+ status: EvictStatus.Running;
14
+ message: string;
15
+ }
16
+ interface BatchEvicted {
17
+ status: EvictStatus.Evicted;
9
18
  skippedEntries?: string[];
10
19
  evictedEntries?: string[];
11
20
  }
@@ -17,35 +26,33 @@ interface EvictError {
17
26
  message: string;
18
27
  }
19
28
  interface EvictCancelled {
20
- status: EvictStatus.Cancelled;
29
+ status: EvictStatus.Canceled;
21
30
  }
22
- export type EvictProgress = EvictInProgress | EvictSucceeded | EvictError | EvictCancelled;
31
+ export type EvictProgress = BatchEvicted | EvictSucceeded | EvictError | EvictCancelled;
23
32
  export type ProgressUpdateCallback = (progess: EvictProgress) => void;
24
33
  /**
25
34
  * Purging records specified by an array of record id from durable store
26
35
  * @param recordIds record id array
27
36
  * @onProgressUpdate call back to report evict progress
28
37
  *
29
- * @returns evictId, call cancelEviction with it to abort the eviction.
38
+ * @returns started or already running based whether there's an active eviction going on or not.
30
39
  *
31
40
  * The record will not be purged if the record has draft.
32
41
  */
33
- export declare function evictCacheRecordsByIds(recordIds: string[], onProgressUpdate: ProgressUpdateCallback): string;
42
+ export declare function evictCacheRecordsByIds(recordIds: string[], onProgressUpdate: ProgressUpdateCallback): EvictStarted | EvictRunning;
34
43
  /**
35
44
  * Purging the db entries which passed expired time by specified days
36
45
  * from durable store.
37
46
  * @param expiredByDays
38
47
  * @param onProgressUpdate
39
48
  *
40
- * @returns an evictId, call cancelEviction with it to abort the eviction.
49
+ * @returns started or already running based whether there's an active eviction going on or not.
41
50
  *
42
51
  * Important: records with draft, objectInfo entries will not be purged even expired by the specified days.
43
52
  */
44
- export declare function evictExpiredCacheEntries(expiredByDays: number, onProgressUpdate: ProgressUpdateCallback): string;
53
+ export declare function evictExpiredCacheEntries(expiredByDays: number, onProgressUpdate: ProgressUpdateCallback): EvictStarted | EvictRunning;
45
54
  /**
46
- * Cancel the eviction by specified id.
47
- * Signal to cancel the eviction if the eviction is going on.
48
- * @param evictionId
55
+ * Signal to stop current eviction if there's an active eviction going on.
49
56
  */
50
- export declare function cancelEviction(evictionId: string): void;
57
+ export declare function stopEviction(): void;
51
58
  export {};
@@ -5,5 +5,5 @@ import { draftQueue, draftManager } from './draftQueueImplementation';
5
5
  import { setUiApiRecordTTL, setMetadataTTL } from './ttl';
6
6
  import { registerReportObserver } from '@salesforce/lds-runtime-mobile';
7
7
  import { createPrimingSession } from './primingApi';
8
- import { evictCacheRecordsByIds, evictExpiredCacheEntries, cancelEviction } from './cachePurging';
9
- export { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, executeAdapter, executeMutatingAdapter, nimbusDraftQueue, draftQueue, draftManager, setUiApiRecordTTL, setMetadataTTL, registerReportObserver, getImperativeAdapterNames, createPrimingSession, evictCacheRecordsByIds, evictExpiredCacheEntries, cancelEviction, };
8
+ import { evictCacheRecordsByIds, evictExpiredCacheEntries, stopEviction } from './cachePurging';
9
+ export { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, executeAdapter, executeMutatingAdapter, nimbusDraftQueue, draftQueue, draftManager, setUiApiRecordTTL, setMetadataTTL, registerReportObserver, getImperativeAdapterNames, createPrimingSession, evictCacheRecordsByIds, evictExpiredCacheEntries, stopEviction, };