@salesforce/lds-worker-api 1.461.0 → 1.463.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.
@@ -359,19 +359,7 @@ function invokeDmlAdapter(adapter, configObject, onResponse, nativeAdapterReques
359
359
  function invokeAdapterWithDraftToReplace(adapterId, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
360
360
  invokeAdapterWithDraftToMerge(adapterId, config, draftIdToReplace, onResponse, nativeAdapterRequestContext);
361
361
  }
362
- /**
363
- * Executes the specified adapter with the given @param adapterId and @param config. Then
364
- * it merges the draft with the given id with the draft generated by
365
- * the mutating adapter. Will call onResult callback once with data or error.
366
- *
367
- * This function returns an error if the given adapterId cannot be found, or if the
368
- * adapterId is not a mutating adapter if a draft isn't created, or
369
- * if it fails to parse the given config string.
370
- *
371
- * If the @param adapterId is deleteRecod, the invocation of it will generate a delele draft.
372
- * The newly generated delete draft will replace the draft specified by @param targetDraftId
373
- */
374
- function invokeAdapterWithDraftToMerge(adapterId, config, targetDraftId, onResponse, nativeAdapterRequestContext) {
362
+ function invokeAdapterWithDraftToMergeAndMetadata(adapterId, config, targetDraftId, metadata, onResponse, nativeAdapterRequestContext) {
375
363
  const adapter = getDMLAdapterFromName(adapterId);
376
364
  if (adapter === undefined) {
377
365
  // Check if the adapter is non-mutating adapter and create proper error message.
@@ -387,10 +375,12 @@ function invokeAdapterWithDraftToMerge(adapterId, config, targetDraftId, onRespo
387
375
  // deleteRecord adapter call will generate a delete draft and
388
376
  // the newly generate draft will replace the target draft
389
377
  if (adapterId === 'deleteRecord') {
390
- invokeAdapterWithDraftToMergeDeleteRecord(adapter, config, targetDraftId, onResponse, nativeAdapterRequestContext);
378
+ invokeAdapterWithDraftToMergeDeleteRecord(adapter, config, targetDraftId, metadata, onResponse, nativeAdapterRequestContext);
391
379
  return;
392
380
  }
393
- draftManager.getQueue().then((draftInfo) => {
381
+ draftManager
382
+ .getQueue()
383
+ .then((draftInfo) => {
394
384
  const draftIds = draftInfo.items.map((draft) => draft.id);
395
385
  if (draftIds.includes(targetDraftId) === false) {
396
386
  onResponse({
@@ -407,14 +397,32 @@ function invokeAdapterWithDraftToMerge(adapterId, config, targetDraftId, onRespo
407
397
  const draftId = draftIds[draftIds.length - 1];
408
398
  draftManager
409
399
  .mergeActions(targetDraftId, draftId)
410
- .then(() => {
400
+ .then(async () => {
411
401
  if (responseValue.data === undefined ||
412
402
  responseValue.data.drafts === undefined) {
413
403
  onResponse(responseValue);
414
404
  return;
415
405
  }
416
406
  const newResponse = removeDraftNodeActionId(draftId, responseValue);
417
- onResponse(newResponse);
407
+ if (metadata !== undefined) {
408
+ const mergedState = await draftManager.getQueue();
409
+ const mergedItem = mergedState.items.find((item) => item.id === targetDraftId);
410
+ const mergedMetadata = mergedItem?.metadata ?? {};
411
+ draftManager
412
+ .setMetadata(targetDraftId, {
413
+ ...mergedMetadata,
414
+ ...metadata,
415
+ })
416
+ .then(() => {
417
+ onResponse(newResponse);
418
+ })
419
+ .catch((error) => {
420
+ onResponse(convertErrorIntoNativeFetchError(error, 'Unable to set metadata on draft'));
421
+ });
422
+ }
423
+ else {
424
+ onResponse(newResponse);
425
+ }
418
426
  })
419
427
  .catch((error) => {
420
428
  onResponse(convertErrorIntoNativeFetchError(error, `Unknown error merging draft`));
@@ -426,8 +434,26 @@ function invokeAdapterWithDraftToMerge(adapterId, config, targetDraftId, onRespo
426
434
  onResponse(response);
427
435
  }
428
436
  }, nativeAdapterRequestContext);
437
+ })
438
+ .catch((error) => {
439
+ onResponse(convertErrorIntoNativeFetchError(error, 'Unable to get draft queue'));
429
440
  });
430
441
  }
442
+ /**
443
+ * Executes the specified adapter with the given @param adapterId and @param config. Then
444
+ * it merges the draft with the given id with the draft generated by
445
+ * the mutating adapter. Will call onResult callback once with data or error.
446
+ *
447
+ * This function returns an error if the given adapterId cannot be found, or if the
448
+ * adapterId is not a mutating adapter if a draft isn't created, or
449
+ * if it fails to parse the given config string.
450
+ *
451
+ * If the @param adapterId is deleteRecod, the invocation of it will generate a delele draft.
452
+ * The newly generated delete draft will replace the draft specified by @param targetDraftId
453
+ */
454
+ function invokeAdapterWithDraftToMerge(adapterId, config, targetDraftId, onResponse, nativeAdapterRequestContext) {
455
+ invokeAdapterWithDraftToMergeAndMetadata(adapterId, config, targetDraftId, undefined, onResponse, nativeAdapterRequestContext);
456
+ }
431
457
  /**
432
458
  * Executes the specified adapter with the given adapterId and config. Then
433
459
  * it sets the given metadata on the draft created by the mutating adapter. Will call
@@ -563,18 +589,20 @@ This is a special case version of the invokeAdapterWithDraftToMerge function
563
589
  which should only be used for the deleteRecord wire adapter, since it does not
564
590
  contain record data in the result and has to do special querying of the draft queue
565
591
  */
566
- function invokeAdapterWithDraftToMergeDeleteRecord(adapter, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
592
+ function invokeAdapterWithDraftToMergeDeleteRecord(adapter, config, draftIdToReplace, metadata, onResponse, nativeAdapterRequestContext) {
567
593
  const targetedRecordId = parse(config);
568
594
  let priorDraftIds;
569
- draftManager.getQueue().then((draftState) => {
570
- priorDraftIds = draftState.items.map((item) => {
571
- return item.id;
572
- });
595
+ draftManager
596
+ .getQueue()
597
+ .then((draftState) => {
598
+ priorDraftIds = draftState.items.map((item) => item.id);
573
599
  invokeDmlAdapter(adapter, parse(config), (responseValue) => {
574
600
  if (responseValue.error === undefined &&
575
601
  responseValue.errors === undefined &&
576
602
  responseValue.data === undefined) {
577
- draftManager.getQueue().then((newState) => {
603
+ draftManager
604
+ .getQueue()
605
+ .then((newState) => {
578
606
  const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
579
607
  const newDrafts = newState.items;
580
608
  const addedDrafts = newDrafts.filter((item) => {
@@ -591,13 +619,35 @@ function invokeAdapterWithDraftToMergeDeleteRecord(adapter, config, draftIdToRep
591
619
  else {
592
620
  draftManager
593
621
  .replaceAction(draftIdToReplace, addedDrafts[0].id)
594
- .then(() => {
595
- onResponse(responseValue);
622
+ .then((replacedDraft) => {
623
+ if (metadata !== undefined) {
624
+ // Spread the metadata returned by replaceAction
625
+ // (not the pre-replace snapshot) so that keys the
626
+ // replacement clears — notably retryCount — stay
627
+ // cleared instead of being reintroduced here.
628
+ draftManager
629
+ .setMetadata(draftIdToReplace, {
630
+ ...replacedDraft.metadata,
631
+ ...metadata,
632
+ })
633
+ .then(() => {
634
+ onResponse(responseValue);
635
+ })
636
+ .catch((error) => {
637
+ onResponse(convertErrorIntoNativeFetchError(error, 'Unable to set metadata on draft'));
638
+ });
639
+ }
640
+ else {
641
+ onResponse(responseValue);
642
+ }
596
643
  })
597
644
  .catch((error) => {
598
645
  onResponse(convertErrorIntoNativeFetchError(error, 'Unknown error replacing action'));
599
646
  });
600
647
  }
648
+ })
649
+ .catch((error) => {
650
+ onResponse(convertErrorIntoNativeFetchError(error, 'Unable to get draft queue'));
601
651
  });
602
652
  }
603
653
  else {
@@ -606,6 +656,9 @@ function invokeAdapterWithDraftToMergeDeleteRecord(adapter, config, draftIdToRep
606
656
  onResponse(response);
607
657
  }
608
658
  }, nativeAdapterRequestContext);
659
+ })
660
+ .catch((error) => {
661
+ onResponse(convertErrorIntoNativeFetchError(error, 'Unable to get draft queue'));
609
662
  });
610
663
  }
611
664
  function removeDraftNodeActionId(targetDraftId, responseValue) {
@@ -1372,5 +1425,5 @@ if (process.env.NODE_ENV !== 'production') {
1372
1425
  });
1373
1426
  }
1374
1427
 
1375
- export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, importLuvioAdapterModule, importOneStoreAdapterModule, invokeAdapter, invokeAdapterWithDraftToMerge, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
1376
- // version: 1.461.0-37b1c9d1cb
1428
+ export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, importLuvioAdapterModule, importOneStoreAdapterModule, invokeAdapter, invokeAdapterWithDraftToMerge, invokeAdapterWithDraftToMergeAndMetadata, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
1429
+ // version: 1.463.0-ea9ecd17fc
@@ -57,6 +57,7 @@ export declare function subscribeToAdapter(adapterId: string, config: string, on
57
57
  * Will be removed in future, ideally 2 releases later.
58
58
  */
59
59
  export declare function invokeAdapterWithDraftToReplace(adapterId: string, config: string, draftIdToReplace: string, onResponse: NativeOnResponse, nativeAdapterRequestContext?: NativeAdapterRequestContext): void;
60
+ export declare function invokeAdapterWithDraftToMergeAndMetadata(adapterId: string, config: string, targetDraftId: string, metadata: DraftQueueItemMetadata | undefined, onResponse: NativeOnResponse, nativeAdapterRequestContext?: NativeAdapterRequestContext): void;
60
61
  /**
61
62
  * Executes the specified adapter with the given @param adapterId and @param config. Then
62
63
  * it merges the draft with the given id with the draft generated by
@@ -1,4 +1,4 @@
1
- import { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, invokeAdapterWithDraftToMerge, executeAdapter, executeMutatingAdapter } from './executeAdapter';
1
+ import { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, invokeAdapterWithDraftToMerge, invokeAdapterWithDraftToMergeAndMetadata, executeAdapter, executeMutatingAdapter } from './executeAdapter';
2
2
  import { getImperativeAdapterNames } from './lightningAdapterApi';
3
3
  import { nimbusDraftQueue } from './nimbusDraftQueue';
4
4
  import { draftQueue, draftManager } from './draftQueueImplementation';
@@ -8,4 +8,4 @@ import { createPrimingSession } from './primingApi';
8
8
  import { evictCacheRecordsByIds, evictExpiredCacheEntries, stopEviction } from './cachePurging';
9
9
  import { importLuvioAdapterModule } from './customLuvioAdapter';
10
10
  import { importOneStoreAdapterModule } from './customOneStoreAdapter';
11
- export { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, invokeAdapterWithDraftToMerge, executeAdapter, executeMutatingAdapter, nimbusDraftQueue, draftQueue, draftManager, setUiApiRecordTTL, setMetadataTTL, registerReportObserver, getImperativeAdapterNames, createPrimingSession, evictCacheRecordsByIds, evictExpiredCacheEntries, stopEviction, importLuvioAdapterModule, importOneStoreAdapterModule, };
11
+ export { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, invokeAdapterWithDraftToMerge, invokeAdapterWithDraftToMergeAndMetadata, executeAdapter, executeMutatingAdapter, nimbusDraftQueue, draftQueue, draftManager, setUiApiRecordTTL, setMetadataTTL, registerReportObserver, getImperativeAdapterNames, createPrimingSession, evictCacheRecordsByIds, evictExpiredCacheEntries, stopEviction, importLuvioAdapterModule, importOneStoreAdapterModule, };