@salesforce/lds-drafts 1.114.0 → 1.114.2

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.
@@ -150,7 +150,7 @@ export declare class DraftManager {
150
150
  * @param sourceActionId The draft action id to merge onto the target. This
151
151
  * action will be removed after the merge.
152
152
  */
153
- mergeAction(targetActionId: string, sourceActionId: string): Promise<DraftQueueItem>;
153
+ mergeActions(targetActionId: string, sourceActionId: string): Promise<DraftQueueItem>;
154
154
  /**
155
155
  * Sets the metadata object of the specified action to the
156
156
  * provided metadata
@@ -216,7 +216,7 @@ export interface DraftQueue {
216
216
  * @param sourceActionId The draft action id to merge onto the target. This
217
217
  * action will be removed after the merge.
218
218
  */
219
- mergeAction<Data, Response>(targetActionId: string, sourceActionId: string): Promise<DraftAction<Data, Response>>;
219
+ mergeActions<Data, Response>(targetActionId: string, sourceActionId: string): Promise<DraftAction<Data, Response>>;
220
220
  /** Set the draft queue state to Started and process the next item */
221
221
  startQueue(): Promise<void>;
222
222
  /** Set the draft queue state to Stopped and don't let another item begin */
@@ -46,7 +46,7 @@ export declare class DurableDraftQueue implements DraftQueue {
46
46
  private startQueueSafe;
47
47
  removeDraftAction(actionId: string): Promise<void>;
48
48
  replaceAction(actionId: string, withActionId: string): Promise<DraftAction<unknown, unknown>>;
49
- mergeAction<Data, Response>(targetActionId: string, sourceActionId: string): Promise<DraftAction<Data, Response>>;
49
+ mergeActions<Data, Response>(targetActionId: string, sourceActionId: string): Promise<DraftAction<Data, Response>>;
50
50
  setMetadata(actionId: string, metadata: DraftActionMetadata): Promise<DraftAction<unknown, unknown>>;
51
51
  private scheduleRetry;
52
52
  }
package/dist/ldsDrafts.js CHANGED
@@ -712,23 +712,31 @@ class DurableDraftQueue {
712
712
  await this.startQueueSafe();
713
713
  return Promise.reject('No action to replace');
714
714
  }
715
- const { actionToReplace, replacingAction } = this.getHandler(first.handler).handleReplaceAction(actionId, withActionId, this.uploadingActionId, actions);
716
- // TODO [W-8873834]: Will add batching support to durable store
717
- // we should use that here to remove and set both actions in one operation
718
- await this.removeDraftAction(replacingAction.id);
719
- await this.draftStore.writeAction(actionToReplace);
720
- await this.notifyChangedListeners({
721
- type: DraftQueueEventType.ActionUpdated,
722
- action: actionToReplace,
723
- });
724
- this.replacingAction = undefined;
715
+ // put in a try/finally block so we don't leave this.replacingAction
716
+ // indefinitely set
717
+ let actionToReplace;
718
+ try {
719
+ const replaceResult = this.getHandler(first.handler).handleReplaceAction(actionId, withActionId, this.uploadingActionId, actions);
720
+ actionToReplace = replaceResult.actionToReplace;
721
+ // TODO [W-8873834]: Will add batching support to durable store
722
+ // we should use that here to remove and set both actions in one operation
723
+ await this.removeDraftAction(replaceResult.replacingAction.id);
724
+ await this.draftStore.writeAction(actionToReplace);
725
+ await this.notifyChangedListeners({
726
+ type: DraftQueueEventType.ActionUpdated,
727
+ action: actionToReplace,
728
+ });
729
+ }
730
+ finally {
731
+ this.replacingAction = undefined;
732
+ }
725
733
  await this.startQueueSafe();
726
734
  return actionToReplace;
727
735
  });
728
736
  this.replacingAction = replacing;
729
737
  return replacing;
730
738
  }
731
- mergeAction(targetActionId, sourceActionId) {
739
+ mergeActions(targetActionId, sourceActionId) {
732
740
  // ids must be unique
733
741
  if (targetActionId === sourceActionId) {
734
742
  return Promise.reject(new Error('target and source action ids cannot be the same'));
@@ -751,16 +759,23 @@ class DurableDraftQueue {
751
759
  await this.startQueueSafe();
752
760
  throw Error('No action to replace');
753
761
  }
754
- const merged = this.getHandler(target.handler).mergeActions(target, source);
755
- // update the target
756
- await this.draftStore.writeAction(merged);
757
- await this.notifyChangedListeners({
758
- type: DraftQueueEventType.ActionUpdated,
759
- action: merged,
760
- });
761
- // remove the source from queue
762
- await this.removeDraftAction(sourceActionId);
763
- this.replacingAction = undefined;
762
+ // put in a try/finally block so we don't leave this.replacingAction
763
+ // indefinitely set
764
+ let merged;
765
+ try {
766
+ merged = this.getHandler(target.handler).mergeActions(target, source);
767
+ // update the target
768
+ await this.draftStore.writeAction(merged);
769
+ await this.notifyChangedListeners({
770
+ type: DraftQueueEventType.ActionUpdated,
771
+ action: merged,
772
+ });
773
+ // remove the source from queue
774
+ await this.removeDraftAction(sourceActionId);
775
+ }
776
+ finally {
777
+ this.replacingAction = undefined;
778
+ }
764
779
  await this.startQueueSafe();
765
780
  return merged;
766
781
  });
@@ -1628,8 +1643,8 @@ class DraftManager {
1628
1643
  * @param sourceActionId The draft action id to merge onto the target. This
1629
1644
  * action will be removed after the merge.
1630
1645
  */
1631
- mergeAction(targetActionId, sourceActionId) {
1632
- return this.draftQueue.mergeAction(targetActionId, sourceActionId).then((merged) => {
1646
+ mergeActions(targetActionId, sourceActionId) {
1647
+ return this.draftQueue.mergeActions(targetActionId, sourceActionId).then((merged) => {
1633
1648
  return this.buildDraftQueueItem(merged);
1634
1649
  });
1635
1650
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-drafts",
3
- "version": "1.114.0",
3
+ "version": "1.114.2",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS Drafts",
6
6
  "main": "dist/ldsDrafts.js",
@@ -26,6 +26,6 @@
26
26
  "dependencies": {
27
27
  "@luvio/engine": "0.137.1",
28
28
  "@luvio/environments": "0.137.1",
29
- "@salesforce/lds-utils-adapters": "^1.114.0"
29
+ "@salesforce/lds-utils-adapters": "^1.114.2"
30
30
  }
31
31
  }