@salesforce/lds-worker-api 1.243.0 → 1.245.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.
- package/dist/sfdc/es/ldsWorkerApi.js +242 -3
- package/dist/sfdc/es/types/cachePurging.d.ts +39 -0
- package/dist/sfdc/es/types/main.d.ts +2 -1
- package/dist/standalone/es/lds-worker-api.js +987 -613
- package/dist/standalone/es/types/cachePurging.d.ts +39 -0
- package/dist/standalone/es/types/main.d.ts +2 -1
- package/dist/standalone/umd/lds-worker-api.js +988 -612
- package/dist/standalone/umd/types/cachePurging.d.ts +39 -0
- package/dist/standalone/umd/types/main.d.ts +2 -1
- package/package.json +4 -4
|
@@ -36,7 +36,7 @@ import * as gqlApi from 'force/ldsAdaptersGraphql';
|
|
|
36
36
|
import { getRuntime, reportGraphqlQueryParseError } from 'native/ldsRuntimeMobile';
|
|
37
37
|
export { registerReportObserver } from 'native/ldsRuntimeMobile';
|
|
38
38
|
import { HttpStatusCode } from 'force/luvioEngine';
|
|
39
|
-
import { API_NAMESPACE, RECORD_REPRESENTATION_NAME } from 'force/ldsAdaptersUiapi';
|
|
39
|
+
import { API_NAMESPACE, RECORD_REPRESENTATION_NAME, keyBuilderRecord } from 'force/ldsAdaptersUiapi';
|
|
40
40
|
import { withDefaultLuvio } from 'native/ldsEngineMobile';
|
|
41
41
|
|
|
42
42
|
const { create, keys } = Object;
|
|
@@ -778,6 +778,245 @@ 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
|
+
var EvictStatus;
|
|
918
|
+
(function (EvictStatus) {
|
|
919
|
+
EvictStatus["InProgress"] = "InProgress";
|
|
920
|
+
EvictStatus["Succeeded"] = "Succeeded";
|
|
921
|
+
EvictStatus["Error"] = "Error";
|
|
922
|
+
EvictStatus["Cancelled"] = "Cancelled";
|
|
923
|
+
})(EvictStatus || (EvictStatus = {}));
|
|
924
|
+
const MessagingDurableSegmentName = 'MESSAGING';
|
|
925
|
+
const DEFAULT_MAX_ENTRIES_PER_OPERATION = 500;
|
|
926
|
+
/**
|
|
927
|
+
* Keep tracking of ongoing eviction id to a flag to trigger eviction cancellation.
|
|
928
|
+
* false in the begining, set to false when cancelEviction is called.
|
|
929
|
+
*/
|
|
930
|
+
const inProgressEvictions = new Map();
|
|
931
|
+
/**
|
|
932
|
+
* Purging records specified by an array of record id from durable store
|
|
933
|
+
* @param recordIds record id array
|
|
934
|
+
* @onProgressUpdate call back to report evict progress
|
|
935
|
+
*
|
|
936
|
+
* @returns a function to cancel the eviction
|
|
937
|
+
*
|
|
938
|
+
* The record will not be purged if the record has draft.
|
|
939
|
+
*/
|
|
940
|
+
function evictCacheRecordsByIds(recordIds, onProgressUpdate) {
|
|
941
|
+
const evictionId = uuidv4();
|
|
942
|
+
inProgressEvictions.set(evictionId, false);
|
|
943
|
+
const onEvicted = (progress) => {
|
|
944
|
+
onProgressUpdate(progress);
|
|
945
|
+
const { status } = progress;
|
|
946
|
+
if (status === EvictStatus.Succeeded || status === EvictStatus.Error) {
|
|
947
|
+
inProgressEvictions.delete(evictionId);
|
|
948
|
+
}
|
|
949
|
+
if (status === EvictStatus.InProgress) {
|
|
950
|
+
if (inProgressEvictions.get(evictionId)) {
|
|
951
|
+
inProgressEvictions.delete(evictionId);
|
|
952
|
+
onProgressUpdate({ status: EvictStatus.Cancelled });
|
|
953
|
+
}
|
|
954
|
+
else {
|
|
955
|
+
evictAChunk();
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
const evictAChunk = () => {
|
|
960
|
+
evictChunksOfRecord(recordIds).then(onEvicted);
|
|
961
|
+
};
|
|
962
|
+
evictAChunk();
|
|
963
|
+
return evictionId;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Cancel the eviction by specified id.
|
|
967
|
+
* @param evictionId
|
|
968
|
+
*/
|
|
969
|
+
function cancelEviction(evictionId) {
|
|
970
|
+
inProgressEvictions.set(evictionId, true);
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* pull a chunk of record id, evict status back in a promise.
|
|
974
|
+
* @param ids the list of record ids.
|
|
975
|
+
* @returns
|
|
976
|
+
*/
|
|
977
|
+
function evictChunksOfRecord(ids) {
|
|
978
|
+
const chunk = ids.splice(0, DEFAULT_MAX_ENTRIES_PER_OPERATION);
|
|
979
|
+
if (chunk.length === 0) {
|
|
980
|
+
return Promise.resolve({ status: EvictStatus.Succeeded });
|
|
981
|
+
}
|
|
982
|
+
return new Promise((resolve) => {
|
|
983
|
+
// evict the chunk
|
|
984
|
+
const { luvio, nimbusSqliteStore } = getRuntime();
|
|
985
|
+
const paramTemplate = chunk.map((_) => '?').join(',');
|
|
986
|
+
const params = chunk.map((recordId) => keyBuilderRecord(luvio, { recordId }));
|
|
987
|
+
try {
|
|
988
|
+
nimbusSqliteStore
|
|
989
|
+
.query(`DELETE FROM lds_data
|
|
990
|
+
WHERE key IN (${paramTemplate}) AND JSON_EXTRACT(data,'$.drafts') IS NULL
|
|
991
|
+
RETURNING key
|
|
992
|
+
`, params)
|
|
993
|
+
.then((result) => {
|
|
994
|
+
const evictedEntries = result.rows.map((row) => row[0]);
|
|
995
|
+
const skippedEntries = params.filter((entryKey) => evictedEntries.indexOf(entryKey) === -1);
|
|
996
|
+
// broadcast entries evicted
|
|
997
|
+
nimbusSqliteStore.setEntries({ notifyStoreUpdateAvailable: { data: evictedEntries } }, MessagingDurableSegmentName);
|
|
998
|
+
resolve({
|
|
999
|
+
status: EvictStatus.InProgress,
|
|
1000
|
+
evictedEntries,
|
|
1001
|
+
skippedEntries,
|
|
1002
|
+
});
|
|
1003
|
+
})
|
|
1004
|
+
.catch((reason) => {
|
|
1005
|
+
resolve({
|
|
1006
|
+
status: EvictStatus.Error,
|
|
1007
|
+
message: JSON.stringify(reason),
|
|
1008
|
+
});
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
catch (reason) {
|
|
1012
|
+
resolve({
|
|
1013
|
+
status: EvictStatus.Error,
|
|
1014
|
+
message: JSON.stringify(reason),
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
|
|
781
1020
|
if (process.env.NODE_ENV !== 'production') {
|
|
782
1021
|
// eslint-disable-next-line no-undef
|
|
783
1022
|
withDefaultLuvio((luvio) => {
|
|
@@ -787,5 +1026,5 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
787
1026
|
});
|
|
788
1027
|
}
|
|
789
1028
|
|
|
790
|
-
export { createPrimingSession, draftManager, draftQueue, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
|
|
791
|
-
// version: 1.
|
|
1029
|
+
export { cancelEviction, createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
|
|
1030
|
+
// version: 1.245.0-0ea124370
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
declare enum EvictStatus {
|
|
2
|
+
InProgress = "InProgress",
|
|
3
|
+
Succeeded = "Succeeded",
|
|
4
|
+
Error = "Error",
|
|
5
|
+
Cancelled = "Cancelled"
|
|
6
|
+
}
|
|
7
|
+
interface EvictInProgress {
|
|
8
|
+
status: EvictStatus.InProgress;
|
|
9
|
+
skippedEntries?: string[];
|
|
10
|
+
evictedEntries?: string[];
|
|
11
|
+
}
|
|
12
|
+
interface EvictSucceeded {
|
|
13
|
+
status: EvictStatus.Succeeded;
|
|
14
|
+
}
|
|
15
|
+
interface EvictError {
|
|
16
|
+
status: EvictStatus.Error;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
interface EvictCancelled {
|
|
20
|
+
status: EvictStatus.Cancelled;
|
|
21
|
+
}
|
|
22
|
+
export type EvictProgress = EvictInProgress | EvictSucceeded | EvictError | EvictCancelled;
|
|
23
|
+
export type ProgressUpdateCallback = (progess: EvictProgress) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Purging records specified by an array of record id from durable store
|
|
26
|
+
* @param recordIds record id array
|
|
27
|
+
* @onProgressUpdate call back to report evict progress
|
|
28
|
+
*
|
|
29
|
+
* @returns a function to cancel the eviction
|
|
30
|
+
*
|
|
31
|
+
* The record will not be purged if the record has draft.
|
|
32
|
+
*/
|
|
33
|
+
export declare function evictCacheRecordsByIds(recordIds: string[], onProgressUpdate: ProgressUpdateCallback): string;
|
|
34
|
+
/**
|
|
35
|
+
* Cancel the eviction by specified id.
|
|
36
|
+
* @param evictionId
|
|
37
|
+
*/
|
|
38
|
+
export declare function cancelEviction(evictionId: string): void;
|
|
39
|
+
export {};
|
|
@@ -5,4 +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
|
-
|
|
8
|
+
import { evictCacheRecordsByIds, cancelEviction } from './cachePurging';
|
|
9
|
+
export { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, executeAdapter, executeMutatingAdapter, nimbusDraftQueue, draftQueue, draftManager, setUiApiRecordTTL, setMetadataTTL, registerReportObserver, getImperativeAdapterNames, createPrimingSession, evictCacheRecordsByIds, cancelEviction, };
|