@salesforce/lds-drafts 1.314.0 → 1.316.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/ldsDrafts.js CHANGED
@@ -385,6 +385,11 @@ class DurableDraftQueue {
385
385
  this.userState = DraftQueueState.Stopped;
386
386
  this.uploadingActionId = undefined;
387
387
  this.timeoutHandler = undefined;
388
+ this.logger = typeof __nimbus !== 'undefined' &&
389
+ __nimbus.plugins !== undefined &&
390
+ __nimbus.plugins.JSLoggerPlugin !== undefined
391
+ ? __nimbus.plugins.JSLoggerPlugin
392
+ : undefined;
388
393
  this.handlers = {};
389
394
  this.draftStore = draftStore;
390
395
  this.workerPool = new AsyncWorkerPool(1);
@@ -425,12 +430,13 @@ class DurableDraftQueue {
425
430
  await this.notifyChangedListeners({
426
431
  type: DraftQueueEventType.QueueStateChanged,
427
432
  state: this.state,
433
+ draftCount: this.draftStore.getCount(),
428
434
  });
429
435
  const result = await this.processNextAction();
430
436
  switch (result) {
431
437
  case ProcessActionResult.BLOCKED_ON_ERROR:
432
438
  this.state = DraftQueueState.Error;
433
- return Promise.reject();
439
+ return Promise.reject('Unable to start queue - first action is in error state');
434
440
  default:
435
441
  return Promise.resolve();
436
442
  }
@@ -441,16 +447,22 @@ class DurableDraftQueue {
441
447
  // Do nothing if the queue state is already stopped
442
448
  return Promise.resolve();
443
449
  }
444
- this.stopQueueManually();
450
+ this.stopQueueManually(false);
445
451
  return this.notifyChangedListeners({
446
452
  type: DraftQueueEventType.QueueStateChanged,
447
453
  state: DraftQueueState.Stopped,
454
+ draftCount: this.draftStore.getCount(),
448
455
  });
449
456
  }
450
457
  /**
451
458
  * Used to stop the queue within DraftQueue without user interaction
452
459
  */
453
- stopQueueManually() {
460
+ stopQueueManually(internalReason) {
461
+ if (this.logger) {
462
+ this.logger.logInfo(internalReason
463
+ ? 'Draft queue stopped for internal reason'
464
+ : 'Draft queue stopped by app');
465
+ }
454
466
  if (this.timeoutHandler) {
455
467
  clearTimeout(this.timeoutHandler);
456
468
  this.timeoutHandler = undefined;
@@ -493,6 +505,7 @@ class DurableDraftQueue {
493
505
  await this.notifyChangedListeners({
494
506
  type: DraftQueueEventType.ActionAdded,
495
507
  action: pendingAction,
508
+ draftCount: this.draftStore.getCount(),
496
509
  });
497
510
  await handler.handleActionEnqueued(pendingAction, queue);
498
511
  if (this.state === DraftQueueState.Started) {
@@ -525,6 +538,7 @@ class DurableDraftQueue {
525
538
  await this.notifyChangedListeners({
526
539
  type: DraftQueueEventType.ActionCompleted,
527
540
  action,
541
+ draftCount: this.draftStore.getCount(),
528
542
  });
529
543
  if (this.state === DraftQueueState.Started) {
530
544
  this.processNextAction();
@@ -574,6 +588,7 @@ class DurableDraftQueue {
574
588
  await this.notifyChangedListeners({
575
589
  type: DraftQueueEventType.ActionFailed,
576
590
  action: action,
591
+ draftCount: this.draftStore.getCount(),
577
592
  });
578
593
  return ProcessActionResult.BLOCKED_ON_ERROR;
579
594
  }
@@ -590,6 +605,7 @@ class DurableDraftQueue {
590
605
  await this.notifyChangedListeners({
591
606
  type: DraftQueueEventType.ActionUploading,
592
607
  action: { ...action, status: DraftActionStatus.Uploading },
608
+ draftCount: this.draftStore.getCount(),
593
609
  });
594
610
  return this.handle(action);
595
611
  }
@@ -611,6 +627,7 @@ class DurableDraftQueue {
611
627
  return this.notifyChangedListeners({
612
628
  type: DraftQueueEventType.ActionFailed,
613
629
  action: errorAction,
630
+ draftCount: this.draftStore.getCount(),
614
631
  });
615
632
  }
616
633
  async notifyChangedListeners(event) {
@@ -657,6 +674,7 @@ class DurableDraftQueue {
657
674
  await this.notifyChangedListeners({
658
675
  type: DraftQueueEventType.ActionDeleted,
659
676
  action,
677
+ draftCount: this.draftStore.getCount(),
660
678
  });
661
679
  if (this.userState === DraftQueueState.Started &&
662
680
  this.state !== DraftQueueState.Started &&
@@ -666,7 +684,7 @@ class DurableDraftQueue {
666
684
  }
667
685
  async updateDraftAction(action) {
668
686
  // stop queue manually
669
- this.stopQueueManually();
687
+ this.stopQueueManually(true);
670
688
  const actionStatus = await this.statusOfAction(action.id);
671
689
  if (actionStatus === DraftActionStatus.Uploading) {
672
690
  return Promise.reject('cannot update an uploading action');
@@ -696,7 +714,7 @@ class DurableDraftQueue {
696
714
  return this.replaceOrMergeActions(targetActionId, sourceActionId, true);
697
715
  }
698
716
  async retryAction(actionId) {
699
- this.stopQueueManually();
717
+ this.stopQueueManually(true);
700
718
  const actions = await this.getQueueActions();
701
719
  const target = actions[0];
702
720
  if (!target || target.id !== actionId) {
@@ -714,6 +732,7 @@ class DurableDraftQueue {
714
732
  await this.notifyChangedListeners({
715
733
  type: DraftQueueEventType.ActionUpdated,
716
734
  action: pendingAction,
735
+ draftCount: this.draftStore.getCount(),
717
736
  });
718
737
  await this.startQueueSafe();
719
738
  return pendingAction;
@@ -739,6 +758,7 @@ class DurableDraftQueue {
739
758
  await this.notifyChangedListeners({
740
759
  type: DraftQueueEventType.ActionUpdated,
741
760
  action: action,
761
+ draftCount: this.draftStore.getCount(),
742
762
  });
743
763
  return action;
744
764
  }
@@ -746,6 +766,7 @@ class DurableDraftQueue {
746
766
  await this.notifyChangedListeners({
747
767
  type: DraftQueueEventType.QueueStateChanged,
748
768
  state: DraftQueueState.Waiting,
769
+ draftCount: this.draftStore.getCount(),
749
770
  });
750
771
  this.timeoutHandler = setTimeout(() => {
751
772
  if (this.state !== DraftQueueState.Stopped) {
@@ -804,7 +825,7 @@ class DurableDraftQueue {
804
825
  if (this.replacingAction !== undefined) {
805
826
  throw Error('Cannot replace/merge actions while a replace/merge action operation is in progress.');
806
827
  }
807
- this.stopQueueManually();
828
+ this.stopQueueManually(true);
808
829
  const promise = this.getActionsForReplaceOrMerge(targetActionId, sourceActionId).then(async ({ target, source }) => {
809
830
  // put in a try/finally block so we don't leave this.replacingAction
810
831
  // indefinitely set
@@ -820,6 +841,7 @@ class DurableDraftQueue {
820
841
  await this.notifyChangedListeners({
821
842
  type: DraftQueueEventType.ActionUpdated,
822
843
  action: updatedTarget,
844
+ draftCount: this.draftStore.getCount(),
823
845
  });
824
846
  // remove the source from queue
825
847
  await this.removeDraftAction(sourceActionId);
@@ -958,6 +980,9 @@ class DurableDraftStore {
958
980
  };
959
981
  return this.enqueueAction(action);
960
982
  }
983
+ getCount() {
984
+ return keys(this.draftStore).length;
985
+ }
961
986
  /**
962
987
  * Runs a write operation against the draft store, if the initial
963
988
  * revive is still in progress, the action gets enqueued to run once the
@@ -1761,16 +1786,17 @@ class DraftManager {
1761
1786
  return Promise.reject('cannot edit incompatible action type or uploading actions');
1762
1787
  }
1763
1788
  action.data.body.fields = { ...action.data.body.fields, ...fields };
1789
+ action.status = DraftActionStatus.Pending;
1764
1790
  await this.draftQueue.updateDraftAction(action);
1765
1791
  return this.buildDraftQueueItem(action);
1766
1792
  }
1767
1793
  isValidFieldMap(fields) {
1768
1794
  const keys$1 = keys(fields);
1769
- const validTypes = ['string', 'number', 'null', 'boolean'];
1795
+ const validTypes = ['string', 'number', 'boolean'];
1770
1796
  for (let i = 0; i < keys$1.length; i++) {
1771
1797
  const key = keys$1[i];
1772
1798
  const value = fields[key];
1773
- if (!validTypes.includes(typeof value)) {
1799
+ if (!validTypes.includes(typeof value) && value !== null) {
1774
1800
  return false;
1775
1801
  }
1776
1802
  }
@@ -1798,6 +1824,7 @@ class DraftManager {
1798
1824
  }
1799
1825
  const data = action.data;
1800
1826
  data.body.fields = { ...data.body.fields, ...fields };
1827
+ action.status = DraftActionStatus.Pending;
1801
1828
  await this.draftQueue.updateDraftAction(action);
1802
1829
  return this.buildDraftQueueItem(action);
1803
1830
  }
@@ -103,31 +103,36 @@ export declare enum DraftQueueEventType {
103
103
  */
104
104
  QueueStateChanged = "state"
105
105
  }
106
- export interface DraftQueueAddEvent {
106
+ export interface DraftQueueStats {
107
+ draftCount: number;
108
+ }
109
+ export interface DraftQueueAddEvent extends DraftQueueStats {
107
110
  type: DraftQueueEventType.ActionAdded;
108
111
  action: PendingDraftAction<unknown>;
109
112
  }
110
- export interface DraftQueueUploadingEvent {
113
+ export interface DraftQueueUploadingEvent extends DraftQueueStats {
111
114
  type: DraftQueueEventType.ActionUploading;
112
115
  action: UploadingDraftAction<unknown>;
116
+ draftCount: number;
113
117
  }
114
- export interface DraftQueueDeleteEvent {
118
+ export interface DraftQueueDeleteEvent extends DraftQueueStats {
115
119
  type: DraftQueueEventType.ActionDeleted;
116
120
  action: DraftAction<unknown, unknown>;
121
+ draftCount: number;
117
122
  }
118
- export interface DraftQueueCompleteEvent {
123
+ export interface DraftQueueCompleteEvent extends DraftQueueStats {
119
124
  type: DraftQueueEventType.ActionCompleted;
120
125
  action: CompletedDraftAction<unknown, unknown>;
121
126
  }
122
- export interface DraftQueueActionFailedEvent {
127
+ export interface DraftQueueActionFailedEvent extends DraftQueueStats {
123
128
  type: DraftQueueEventType.ActionFailed;
124
129
  action: ErrorDraftAction<unknown>;
125
130
  }
126
- export interface DraftQueueActionUpdatedEvent {
131
+ export interface DraftQueueActionUpdatedEvent extends DraftQueueStats {
127
132
  type: DraftQueueEventType.ActionUpdated;
128
133
  action: DraftAction<unknown, unknown>;
129
134
  }
130
- export interface DraftQueueStateChangedEvent {
135
+ export interface DraftQueueStateChangedEvent extends DraftQueueStats {
131
136
  type: DraftQueueEventType.QueueStateChanged;
132
137
  state: DraftQueueState;
133
138
  }
@@ -8,4 +8,5 @@ export interface DraftStore {
8
8
  deleteDraft(actionId: string): Promise<void>;
9
9
  deleteByTag(tag: string): Promise<void>;
10
10
  completeAction(queueOperations: QueueOperation[]): Promise<void>;
11
+ getCount(): number;
11
12
  }
@@ -16,6 +16,7 @@ export declare class DurableDraftQueue implements DraftQueue {
16
16
  private replacingAction?;
17
17
  private uploadingActionId?;
18
18
  private timeoutHandler;
19
+ private logger;
19
20
  private workerPool;
20
21
  private handlers;
21
22
  private getHandler;
@@ -21,6 +21,7 @@ export declare class DurableDraftStore implements DraftStore {
21
21
  deleteDraft(id: string): Promise<void>;
22
22
  deleteByTag(tag: string): Promise<void>;
23
23
  completeAction(queueOperations: QueueOperation[]): Promise<void>;
24
+ getCount(): number;
24
25
  /**
25
26
  * Runs a write operation against the draft store, if the initial
26
27
  * revive is still in progress, the action gets enqueued to run once the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-drafts",
3
- "version": "1.314.0",
3
+ "version": "1.316.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS Drafts",
6
6
  "main": "dist/ldsDrafts.js",
@@ -26,7 +26,10 @@
26
26
  "dependencies": {
27
27
  "@luvio/engine": "0.156.4",
28
28
  "@luvio/environments": "0.156.4",
29
- "@salesforce/lds-utils-adapters": "^1.314.0"
29
+ "@salesforce/lds-utils-adapters": "^1.316.0"
30
+ },
31
+ "devDependencies": {
32
+ "@salesforce/nimbus-plugin-lds": "^1.316.0"
30
33
  },
31
34
  "volta": {
32
35
  "extends": "../../package.json"