@salesforce/lds-worker-api 1.282.0 → 1.284.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 +84 -58
- package/dist/sfdc/es/types/executeAdapter.d.ts +16 -6
- package/dist/sfdc/es/types/main.d.ts +2 -2
- package/dist/standalone/es/lds-worker-api.js +367 -131
- package/dist/standalone/es/types/executeAdapter.d.ts +16 -6
- package/dist/standalone/es/types/main.d.ts +2 -2
- package/dist/standalone/umd/lds-worker-api.js +367 -130
- package/dist/standalone/umd/types/executeAdapter.d.ts +16 -6
- package/dist/standalone/umd/types/main.d.ts +2 -2
- package/package.json +13 -13
|
@@ -338,72 +338,75 @@ function invokeDmlAdapter(adapter, configObject, onResponse, nativeAdapterReques
|
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
/**
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
341
|
+
* @deprecated There is no situation in which any consumer actually wants to replace the draft.
|
|
342
|
+
* call {@link invokeAdapterWithDraftToMerge} instead`.
|
|
343
|
+
* Keep it for now for app back compatibility.
|
|
344
|
+
* Will be removed in future, ideally 2 releases later.
|
|
345
|
+
*/
|
|
346
|
+
function invokeAdapterWithDraftToReplace(adapterId, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
|
|
347
|
+
invokeAdapterWithDraftToMerge(adapterId, config, draftIdToReplace, onResponse, nativeAdapterRequestContext);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Executes the specified adapter with the given @param dapterId and @param config. Then
|
|
351
|
+
* it merge the draft with the given id with the draft generated by
|
|
352
|
+
* the mutating adapter. Will call onResult callback once with data or error.
|
|
344
353
|
*
|
|
345
354
|
* This function throws an error if the given adapterId cannot be found, or if the
|
|
346
|
-
* adapterId is not a mutating adapter
|
|
347
|
-
* fails to parse the given config string.
|
|
355
|
+
* adapterId is not a mutating adapter if a draft isn't created, or
|
|
356
|
+
* if it fails to parse the given config string.
|
|
357
|
+
*
|
|
358
|
+
* If the @param adapterId is deleteRecod, the invocation of it will generate a delele draft.
|
|
359
|
+
* The newly generated delete draft will replace the draft specified by @param targetDraftId
|
|
348
360
|
*/
|
|
349
|
-
function
|
|
361
|
+
function invokeAdapterWithDraftToMerge(adapterId, config, targetDraftId, onResponse, nativeAdapterRequestContext) {
|
|
362
|
+
const adapter = getDMLAdapterFromName(adapterId);
|
|
363
|
+
if (adapter === undefined) {
|
|
364
|
+
// Check if the adapter is non-mutating adapter and create proper error message.
|
|
365
|
+
const message = getImperativeAdapterFromName(imperativeAdapterKeyBuilder(adapterId)) !== undefined
|
|
366
|
+
? NON_MUTATING_ADAPTER_MESSAGE
|
|
367
|
+
: `adapter ${adapterId} not recognized`;
|
|
368
|
+
onResponse({
|
|
369
|
+
data: undefined,
|
|
370
|
+
error: createNativeFetchErrorResponse(message),
|
|
371
|
+
});
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
// deleteRecord adapter call will generate a delete draft and
|
|
375
|
+
// the newly generate draft will replace the target draft
|
|
376
|
+
if (adapterId === 'deleteRecord') {
|
|
377
|
+
invokeAdapterWithDraftToMergeDeleteRecord(adapter, config, targetDraftId, onResponse, nativeAdapterRequestContext);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
350
380
|
draftManager.getQueue().then((draftInfo) => {
|
|
351
381
|
const draftIds = draftInfo.items.map((draft) => draft.id);
|
|
352
|
-
if (draftIds.includes(
|
|
382
|
+
if (draftIds.includes(targetDraftId) === false) {
|
|
353
383
|
onResponse({
|
|
354
384
|
data: undefined,
|
|
355
385
|
error: createNativeFetchErrorResponse(DRAFT_DOESNT_EXIST_MESSAGE),
|
|
356
386
|
});
|
|
357
387
|
return;
|
|
358
388
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
389
|
+
invokeDmlAdapter(adapter, parse(config), (responseValue) => {
|
|
390
|
+
const draftIds = draftIdsForResponseValue(responseValue);
|
|
391
|
+
if (responseValue.error === undefined &&
|
|
392
|
+
draftIds !== undefined &&
|
|
393
|
+
draftIds.length > 0) {
|
|
394
|
+
const draftId = draftIds[draftIds.length - 1];
|
|
395
|
+
draftManager
|
|
396
|
+
.mergeActions(targetDraftId, draftId)
|
|
397
|
+
.then(() => {
|
|
398
|
+
onResponse(responseValue);
|
|
399
|
+
})
|
|
400
|
+
.catch((error) => {
|
|
401
|
+
onResponse(convertErrorIntoNativeFetchError(error, `Unknown error merging draft`));
|
|
367
402
|
});
|
|
368
|
-
return;
|
|
369
403
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
invokeDmlAdapter(adapter, parse(config), (responseValue) => {
|
|
377
|
-
const draftIds = draftIdsForResponseValue(responseValue);
|
|
378
|
-
if (responseValue.error === undefined &&
|
|
379
|
-
draftIds !== undefined &&
|
|
380
|
-
draftIds.length > 0) {
|
|
381
|
-
const draftId = draftIds[draftIds.length - 1];
|
|
382
|
-
draftManager
|
|
383
|
-
.replaceAction(draftIdToReplace, draftId)
|
|
384
|
-
.then(() => {
|
|
385
|
-
onResponse(responseValue);
|
|
386
|
-
})
|
|
387
|
-
.catch((error) => {
|
|
388
|
-
let message = 'Unknown error replacing draft';
|
|
389
|
-
if (error instanceof Error) {
|
|
390
|
-
message = error.message;
|
|
391
|
-
}
|
|
392
|
-
else if (typeof error === 'string') {
|
|
393
|
-
message = error;
|
|
394
|
-
}
|
|
395
|
-
onResponse({
|
|
396
|
-
error: createNativeFetchErrorResponse(message),
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
let response = responseValue;
|
|
402
|
-
response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
|
|
403
|
-
onResponse(response);
|
|
404
|
-
}
|
|
405
|
-
}, nativeAdapterRequestContext);
|
|
406
|
-
}
|
|
404
|
+
else {
|
|
405
|
+
let response = responseValue;
|
|
406
|
+
response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
|
|
407
|
+
onResponse(response);
|
|
408
|
+
}
|
|
409
|
+
}, nativeAdapterRequestContext);
|
|
407
410
|
});
|
|
408
411
|
}
|
|
409
412
|
/**
|
|
@@ -445,6 +448,9 @@ function invokeAdapterWithMetadata(adapterId, config, metadata, onResponse, nati
|
|
|
445
448
|
.setMetadata(draftId, { ...existingMetadata, ...metadata })
|
|
446
449
|
.then(() => {
|
|
447
450
|
onResponse(responseValue);
|
|
451
|
+
})
|
|
452
|
+
.catch((error) => {
|
|
453
|
+
onResponse(convertErrorIntoNativeFetchError(error, 'Unknown error setting metadata'));
|
|
448
454
|
});
|
|
449
455
|
}
|
|
450
456
|
else {
|
|
@@ -487,8 +493,13 @@ function invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResp
|
|
|
487
493
|
onResponse(response);
|
|
488
494
|
}
|
|
489
495
|
else {
|
|
490
|
-
draftManager
|
|
496
|
+
draftManager
|
|
497
|
+
.setMetadata(addedDrafts[0].id, metadata)
|
|
498
|
+
.then(() => {
|
|
491
499
|
onResponse(responseValue);
|
|
500
|
+
})
|
|
501
|
+
.catch((error) => {
|
|
502
|
+
onResponse(convertErrorIntoNativeFetchError(error, 'Unknown error setting metadata'));
|
|
492
503
|
});
|
|
493
504
|
}
|
|
494
505
|
});
|
|
@@ -503,11 +514,11 @@ function invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResp
|
|
|
503
514
|
}
|
|
504
515
|
/*
|
|
505
516
|
//TODO W-10284305: Remove this function in 238
|
|
506
|
-
This is a special case version of the
|
|
517
|
+
This is a special case version of the invokeAdapterWithDraftToMerge function
|
|
507
518
|
which should only be used for the deleteRecord wire adapter, since it does not
|
|
508
519
|
contain record data in the result and has to do special querying of the draft queue
|
|
509
520
|
*/
|
|
510
|
-
function
|
|
521
|
+
function invokeAdapterWithDraftToMergeDeleteRecord(adapter, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
|
|
511
522
|
const targetedRecordId = parse(config);
|
|
512
523
|
let priorDraftIds;
|
|
513
524
|
draftManager.getQueue().then((draftState) => {
|
|
@@ -537,6 +548,9 @@ function invokeAdapterWithDraftToReplaceDeleteRecord(adapter, config, draftIdToR
|
|
|
537
548
|
.replaceAction(draftIdToReplace, addedDrafts[0].id)
|
|
538
549
|
.then(() => {
|
|
539
550
|
onResponse(responseValue);
|
|
551
|
+
})
|
|
552
|
+
.catch((error) => {
|
|
553
|
+
onResponse(convertErrorIntoNativeFetchError(error, 'Unknown error replacing action'));
|
|
540
554
|
});
|
|
541
555
|
}
|
|
542
556
|
});
|
|
@@ -549,6 +563,18 @@ function invokeAdapterWithDraftToReplaceDeleteRecord(adapter, config, draftIdToR
|
|
|
549
563
|
}, nativeAdapterRequestContext);
|
|
550
564
|
});
|
|
551
565
|
}
|
|
566
|
+
function convertErrorIntoNativeFetchError(error, defaultMessage) {
|
|
567
|
+
let message = defaultMessage;
|
|
568
|
+
if (error instanceof Error) {
|
|
569
|
+
message = error.message;
|
|
570
|
+
}
|
|
571
|
+
else if (typeof error === 'string') {
|
|
572
|
+
message = error;
|
|
573
|
+
}
|
|
574
|
+
return {
|
|
575
|
+
error: createNativeFetchErrorResponse(message),
|
|
576
|
+
};
|
|
577
|
+
}
|
|
552
578
|
function draftIdsForResponseValue(response) {
|
|
553
579
|
if (response.data !== undefined &&
|
|
554
580
|
response.data.drafts !== undefined &&
|
|
@@ -1047,5 +1073,5 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1047
1073
|
});
|
|
1048
1074
|
}
|
|
1049
1075
|
|
|
1050
|
-
export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
|
|
1051
|
-
// version: 1.
|
|
1076
|
+
export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToMerge, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
|
|
1077
|
+
// version: 1.284.0-a7e8dc51c
|
|
@@ -47,15 +47,25 @@ export declare function buildAdapterRequestContext(nativeRequestContext: NativeA
|
|
|
47
47
|
*/
|
|
48
48
|
export declare function subscribeToAdapter(adapterId: string, config: string, onSnapshot: NativeOnSnapshot, nativeAdapterRequestContext?: NativeAdapterRequestContext): Unsubscribe;
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
50
|
+
* @deprecated There is no situation in which any consumer actually wants to replace the draft.
|
|
51
|
+
* call {@link invokeAdapterWithDraftToMerge} instead`.
|
|
52
|
+
* Keep it for now for app back compatibility.
|
|
53
|
+
* Will be removed in future, ideally 2 releases later.
|
|
54
|
+
*/
|
|
55
|
+
export declare function invokeAdapterWithDraftToReplace(adapterId: string, config: string, draftIdToReplace: string, onResponse: NativeOnResponse, nativeAdapterRequestContext?: NativeAdapterRequestContext): void;
|
|
56
|
+
/**
|
|
57
|
+
* Executes the specified adapter with the given @param dapterId and @param config. Then
|
|
58
|
+
* it merge the draft with the given id with the draft generated by
|
|
59
|
+
* the mutating adapter. Will call onResult callback once with data or error.
|
|
53
60
|
*
|
|
54
61
|
* This function throws an error if the given adapterId cannot be found, or if the
|
|
55
|
-
* adapterId is not a mutating adapter
|
|
56
|
-
* fails to parse the given config string.
|
|
62
|
+
* adapterId is not a mutating adapter if a draft isn't created, or
|
|
63
|
+
* if it fails to parse the given config string.
|
|
64
|
+
*
|
|
65
|
+
* If the @param adapterId is deleteRecod, the invocation of it will generate a delele draft.
|
|
66
|
+
* The newly generated delete draft will replace the draft specified by @param targetDraftId
|
|
57
67
|
*/
|
|
58
|
-
export declare function
|
|
68
|
+
export declare function invokeAdapterWithDraftToMerge(adapterId: string, config: string, targetDraftId: string, onResponse: NativeOnResponse, nativeAdapterRequestContext?: NativeAdapterRequestContext): void;
|
|
59
69
|
/**
|
|
60
70
|
* Executes the specified adapter with the given adapterId and config. Then
|
|
61
71
|
* it sets the given metadata on the draft created by the mutating adapter. Will call
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, executeAdapter, executeMutatingAdapter } from './executeAdapter';
|
|
1
|
+
import { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, invokeAdapterWithDraftToMerge, executeAdapter, executeMutatingAdapter } from './executeAdapter';
|
|
2
2
|
import { getImperativeAdapterNames } from './lightningAdapterApi';
|
|
3
3
|
import { nimbusDraftQueue } from './nimbusDraftQueue';
|
|
4
4
|
import { draftQueue, draftManager } from './draftQueueImplementation';
|
|
@@ -6,4 +6,4 @@ import { setUiApiRecordTTL, setMetadataTTL } from './ttl';
|
|
|
6
6
|
import { registerReportObserver } from '@salesforce/lds-runtime-mobile';
|
|
7
7
|
import { createPrimingSession } from './primingApi';
|
|
8
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, };
|
|
9
|
+
export { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, invokeAdapterWithDraftToMerge, executeAdapter, executeMutatingAdapter, nimbusDraftQueue, draftQueue, draftManager, setUiApiRecordTTL, setMetadataTTL, registerReportObserver, getImperativeAdapterNames, createPrimingSession, evictCacheRecordsByIds, evictExpiredCacheEntries, stopEviction, };
|