@salesforce/lds-worker-api 1.247.0 → 1.249.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.
@@ -778,174 +778,49 @@ function removeEventHandler(session, handler) {
778
778
  }
779
779
  }
780
780
 
781
- /**
782
- * Copyright (c) 2022, Salesforce, Inc.,
783
- * All rights reserved.
784
- * For full license text, see the LICENSE.txt file
785
- */
786
-
787
-
788
- var DraftActionStatus;
789
- (function (DraftActionStatus) {
790
- DraftActionStatus["Pending"] = "pending";
791
- DraftActionStatus["Uploading"] = "uploading";
792
- DraftActionStatus["Error"] = "error";
793
- DraftActionStatus["Completed"] = "completed";
794
- })(DraftActionStatus || (DraftActionStatus = {}));
795
- var ProcessActionResult;
796
- (function (ProcessActionResult) {
797
- // non-2xx network error, requires user intervention
798
- ProcessActionResult["ACTION_ERRORED"] = "ERROR";
799
- // upload succeeded
800
- ProcessActionResult["ACTION_SUCCEEDED"] = "SUCCESS";
801
- // queue is empty
802
- ProcessActionResult["NO_ACTION_TO_PROCESS"] = "NO_ACTION_TO_PROCESS";
803
- // network request is in flight
804
- ProcessActionResult["ACTION_ALREADY_PROCESSING"] = "ACTION_ALREADY_PROCESSING";
805
- // network call failed (offline)
806
- ProcessActionResult["NETWORK_ERROR"] = "NETWORK_ERROR";
807
- // queue is blocked on an error that requires user intervention
808
- ProcessActionResult["BLOCKED_ON_ERROR"] = "BLOCKED_ON_ERROR";
809
- //waiting for user to execute custom action
810
- ProcessActionResult["CUSTOM_ACTION_WAITING"] = "CUSTOM_ACTION_WAITING";
811
- })(ProcessActionResult || (ProcessActionResult = {}));
812
- var DraftQueueState;
813
- (function (DraftQueueState) {
814
- /** Currently processing an item in the queue or queue is empty and waiting to process the next item. */
815
- DraftQueueState["Started"] = "started";
816
- /**
817
- * The queue is stopped and will not attempt to upload any drafts until startDraftQueue() is called.
818
- * This is the initial state when the DraftQueue gets instantiated.
819
- */
820
- DraftQueueState["Stopped"] = "stopped";
821
- /**
822
- * The queue is stopped due to a blocking error from the last upload attempt.
823
- * The queue will not run again until startDraftQueue() is called.
824
- */
825
- DraftQueueState["Error"] = "error";
826
- /**
827
- * There was a network error and the queue will attempt to upload again shortly.
828
- * To attempt to force an upload now call startDraftQueue().
829
- */
830
- DraftQueueState["Waiting"] = "waiting";
831
- })(DraftQueueState || (DraftQueueState = {}));
832
- var DraftQueueEventType;
833
- (function (DraftQueueEventType) {
834
- /**
835
- * Triggered after an action had been added to the queue
836
- */
837
- DraftQueueEventType["ActionAdded"] = "added";
838
- /**
839
- * Triggered when starting to upload and process an action
840
- */
841
- DraftQueueEventType["ActionUploading"] = "uploading";
842
- /**
843
- * Triggered once an action failed
844
- */
845
- DraftQueueEventType["ActionFailed"] = "failed";
846
- /**
847
- * Triggered after an action has been deleted from the queue
848
- */
849
- DraftQueueEventType["ActionDeleted"] = "deleted";
850
- /**
851
- * Triggered after an action has been completed and after it has been removed from the queue
852
- */
853
- DraftQueueEventType["ActionCompleted"] = "completed";
854
- /**
855
- * Triggered after an action has been updated by the updateAction API
856
- */
857
- DraftQueueEventType["ActionUpdated"] = "updated";
858
- /**
859
- * Triggered after the Draft Queue state changes
860
- */
861
- DraftQueueEventType["QueueStateChanged"] = "state";
862
- })(DraftQueueEventType || (DraftQueueEventType = {}));
863
- var QueueOperationType;
864
- (function (QueueOperationType) {
865
- QueueOperationType["Add"] = "add";
866
- QueueOperationType["Delete"] = "delete";
867
- QueueOperationType["Update"] = "update";
868
- })(QueueOperationType || (QueueOperationType = {}));
869
- /**
870
- Use Math.random to generate v4 RFC4122 compliant uuid
871
- */
872
- function uuidv4() {
873
- const uuid = [];
874
- for (let i = 0; i < 32; i++) {
875
- const random = (Math.random() * 16) | 0;
876
- if (i === 8 || i === 12 || i === 16 || i === 20) {
877
- uuid.push('-');
878
- }
879
- uuid.push((i === 12 ? 4 : i === 16 ? (random & 3) | 8 : random).toString(16));
880
- }
881
- return uuid.join('');
882
- }
883
-
884
- var CustomActionResultType;
885
- (function (CustomActionResultType) {
886
- CustomActionResultType["SUCCESS"] = "SUCCESS";
887
- CustomActionResultType["FAILURE"] = "FAILURE";
888
- })(CustomActionResultType || (CustomActionResultType = {}));
889
- var CustomActionErrorType;
890
- (function (CustomActionErrorType) {
891
- CustomActionErrorType["NETWORK_ERROR"] = "NETWORK_ERROR";
892
- CustomActionErrorType["CLIENT_ERROR"] = "CLIENT_ERROR";
893
- })(CustomActionErrorType || (CustomActionErrorType = {}));
894
-
895
- /**
896
- * Denotes what kind of operation a DraftQueueItem represents.
897
- */
898
- var DraftActionOperationType;
899
- (function (DraftActionOperationType) {
900
- DraftActionOperationType["Create"] = "create";
901
- DraftActionOperationType["Update"] = "update";
902
- DraftActionOperationType["Delete"] = "delete";
903
- DraftActionOperationType["Custom"] = "custom";
904
- })(DraftActionOperationType || (DraftActionOperationType = {}));
905
- var DraftQueueOperationType;
906
- (function (DraftQueueOperationType) {
907
- DraftQueueOperationType["ItemAdded"] = "added";
908
- DraftQueueOperationType["ItemUploading"] = "uploading";
909
- DraftQueueOperationType["ItemDeleted"] = "deleted";
910
- DraftQueueOperationType["ItemCompleted"] = "completed";
911
- DraftQueueOperationType["ItemFailed"] = "failed";
912
- DraftQueueOperationType["ItemUpdated"] = "updated";
913
- DraftQueueOperationType["QueueStarted"] = "started";
914
- DraftQueueOperationType["QueueStopped"] = "stopped";
915
- })(DraftQueueOperationType || (DraftQueueOperationType = {}));
916
-
917
781
  var EvictStatus;
918
782
  (function (EvictStatus) {
919
- EvictStatus["InProgress"] = "InProgress";
783
+ EvictStatus["Started"] = "Started";
784
+ EvictStatus["Running"] = "Running";
785
+ EvictStatus["Evicted"] = "Evicted";
920
786
  EvictStatus["Succeeded"] = "Succeeded";
921
787
  EvictStatus["Error"] = "Error";
922
- EvictStatus["Cancelled"] = "Cancelled";
788
+ EvictStatus["Canceled"] = "Canceled";
923
789
  })(EvictStatus || (EvictStatus = {}));
924
790
  const MessagingDurableSegmentName = 'MESSAGING';
925
791
  const DEFAULT_MAX_ENTRIES_PER_OPERATION = 500;
792
+ const EVICTION_IN_PROGESS_MESSAGE = `Cache eviction in progress. Can't start another until it is finished or canceled.`;
926
793
  /**
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.
794
+ * Only one eviction is allowed at a time. running status is return when evictCacheRecordsByIds or
795
+ * evictExpiredCacheEntries is called if there's already an eviction in progress.
929
796
  */
930
- const evictionCancellationFlag = new Map();
797
+ var activeEvictionInProgress = false;
798
+ var cancelCurrentEviction = false;
931
799
  /**
932
800
  * Purging records specified by an array of record id from durable store
933
801
  * @param recordIds record id array
934
802
  * @onProgressUpdate call back to report evict progress
935
803
  *
936
- * @returns evictId, call cancelEviction with it to abort the eviction.
804
+ * @returns started or already running based whether there's an active eviction going on or not.
937
805
  *
938
806
  * The record will not be purged if the record has draft.
939
807
  */
940
808
  function evictCacheRecordsByIds(recordIds, onProgressUpdate) {
941
- const evictionId = uuidv4();
942
- evictionCancellationFlag.set(evictionId, false);
809
+ // Send error back if an eviction is going on.
810
+ if (activeEvictionInProgress) {
811
+ return {
812
+ status: EvictStatus.Running,
813
+ message: EVICTION_IN_PROGESS_MESSAGE,
814
+ };
815
+ }
816
+ activeEvictionInProgress = true;
817
+ cancelCurrentEviction = false;
943
818
  const evictAChunk = () => {
944
819
  evictChunksOfRecord(recordIds).then(onEvicted);
945
820
  };
946
- const onEvicted = getOnEvictedCallback(onProgressUpdate, evictionId, evictAChunk);
821
+ const onEvicted = getOnEvictedCallback(onProgressUpdate, evictAChunk);
947
822
  evictAChunk();
948
- return evictionId;
823
+ return { status: EvictStatus.Started };
949
824
  }
950
825
  /**
951
826
  * Purging the db entries which passed expired time by specified days
@@ -953,49 +828,53 @@ function evictCacheRecordsByIds(recordIds, onProgressUpdate) {
953
828
  * @param expiredByDays
954
829
  * @param onProgressUpdate
955
830
  *
956
- * @returns an evictId, call cancelEviction with it to abort the eviction.
831
+ * @returns started or already running based whether there's an active eviction going on or not.
957
832
  *
958
833
  * Important: records with draft, objectInfo entries will not be purged even expired by the specified days.
959
834
  */
960
835
  function evictExpiredCacheEntries(expiredByDays, onProgressUpdate) {
961
- const evictionId = uuidv4();
962
- evictionCancellationFlag.set(evictionId, false);
836
+ // Send error back if an eviction is going on.
837
+ if (activeEvictionInProgress) {
838
+ return {
839
+ status: EvictStatus.Running,
840
+ message: EVICTION_IN_PROGESS_MESSAGE,
841
+ };
842
+ }
843
+ activeEvictionInProgress = true;
844
+ cancelCurrentEviction = false;
963
845
  const overdueExpirationTimeStamp = Date.now() - expiredByDays * 24 * 3600 * 1000;
964
846
  const evictAChunk = () => {
965
847
  evictChunkOfOverdueEntries(overdueExpirationTimeStamp).then(onEvicted);
966
848
  };
967
- const onEvicted = getOnEvictedCallback(onProgressUpdate, evictionId, evictAChunk);
849
+ const onEvicted = getOnEvictedCallback(onProgressUpdate, evictAChunk);
968
850
  evictAChunk();
969
- return evictionId;
851
+ return { status: EvictStatus.Started };
970
852
  }
971
853
  /**
972
- * Cancel the eviction by specified id.
973
- * Signal to cancel the eviction if the eviction is going on.
974
- * @param evictionId
854
+ * Signal to stop current eviction if there's an active eviction going on.
975
855
  */
976
- function cancelEviction(evictionId) {
977
- if (evictionCancellationFlag.has(evictionId)) {
978
- evictionCancellationFlag.set(evictionId, true);
856
+ function stopEviction() {
857
+ if (activeEvictionInProgress) {
858
+ cancelCurrentEviction = true;
979
859
  }
980
860
  }
981
861
  /**
982
862
  * Get a callback function when a chunk of records or entries are removed.
983
863
  * @param onProgressUpdate
984
- * @param evictionId
985
864
  * @param evictAChunk
986
865
  * @returns a callback to call when a chunk of records or entries are removed.
987
866
  */
988
- function getOnEvictedCallback(onProgressUpdate, evictionId, evictAChunk) {
867
+ function getOnEvictedCallback(onProgressUpdate, evictAChunk) {
989
868
  return (progress) => {
990
869
  onProgressUpdate(progress);
991
870
  const { status } = progress;
992
871
  if (status === EvictStatus.Succeeded || status === EvictStatus.Error) {
993
- evictionCancellationFlag.delete(evictionId);
872
+ activeEvictionInProgress = false;
994
873
  }
995
- if (status === EvictStatus.InProgress) {
996
- if (evictionCancellationFlag.get(evictionId)) {
997
- evictionCancellationFlag.delete(evictionId);
998
- onProgressUpdate({ status: EvictStatus.Cancelled });
874
+ if (status === EvictStatus.Evicted) {
875
+ if (cancelCurrentEviction) {
876
+ activeEvictionInProgress = false;
877
+ onProgressUpdate({ status: EvictStatus.Canceled });
999
878
  }
1000
879
  else {
1001
880
  evictAChunk();
@@ -1032,7 +911,7 @@ function evictChunksOfRecord(ids) {
1032
911
  nimbusSqliteStore.setEntries({ notifyStoreUpdateAvailable: { data: evictedEntries } }, MessagingDurableSegmentName);
1033
912
  }
1034
913
  resolve({
1035
- status: EvictStatus.InProgress,
914
+ status: EvictStatus.Evicted,
1036
915
  evictedEntries,
1037
916
  skippedEntries,
1038
917
  });
@@ -1070,7 +949,8 @@ function evictChunkOfOverdueEntries(overdueExpirationTimestamp) {
1070
949
  WHERE key NOT LIKE 'UiApi::ObjectInfoRepresentation:%'
1071
950
  AND
1072
951
  (
1073
- key NOT LIKE 'UiApi::RecordRepresentation:%'
952
+ key NOT LIKE 'UiApi::RecordRepresentation:%' AND
953
+ JSON_EXTRACT(metadata, '$.expirationTimestamp') < ${overdueExpirationTimestamp}
1074
954
  OR
1075
955
  key LIKE 'UiApi::RecordRepresentation:%' AND
1076
956
  JSON_EXTRACT(data, '$.drafts') IS NULL AND
@@ -1085,7 +965,7 @@ function evictChunkOfOverdueEntries(overdueExpirationTimestamp) {
1085
965
  // broadcast entries evicted
1086
966
  nimbusSqliteStore.setEntries({ notifyStoreUpdateAvailable: { data: evictedEntries } }, MessagingDurableSegmentName);
1087
967
  resolve({
1088
- status: EvictStatus.InProgress,
968
+ status: EvictStatus.Evicted,
1089
969
  evictedEntries,
1090
970
  skippedEntries: [],
1091
971
  });
@@ -1119,5 +999,5 @@ if (process.env.NODE_ENV !== 'production') {
1119
999
  });
1120
1000
  }
1121
1001
 
1122
- export { cancelEviction, createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
1123
- // version: 1.247.0-4fe38c091
1002
+ export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
1003
+ // version: 1.249.0-11c3e1ed5
@@ -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, };