@salesforce/lds-runtime-mobile 1.302.0 → 1.303.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.
Files changed (3) hide show
  1. package/dist/main.js +57 -9
  2. package/package.json +18 -18
  3. package/sfdc/main.js +57 -9
package/dist/main.js CHANGED
@@ -1575,6 +1575,32 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
1575
1575
  }, revivingStore).finally(() => {
1576
1576
  });
1577
1577
  };
1578
+ const expirePossibleStaleRecords = async function (keys$1, config, refresh) {
1579
+ validateNotDisposed();
1580
+ const metadataKeys = keys$1.map(serializeStructuredKey);
1581
+ const now = Date.now();
1582
+ const entries = await durableStore.getMetadata(metadataKeys, DefaultDurableSegment);
1583
+ if (entries === undefined || keys$8(entries).length === 0) {
1584
+ return environment.expirePossibleStaleRecords(keys$1);
1585
+ }
1586
+ let metaDataChanged = false;
1587
+ const metadataEntries = metadataKeys.reduce((accu, key) => {
1588
+ const metadataEntry = entries[key];
1589
+ if (metadataEntry.metadata !== undefined) {
1590
+ const metadata = { ...metadataEntry.metadata, expirationTimestamp: now };
1591
+ accu[key] = { metadata };
1592
+ metaDataChanged = true;
1593
+ }
1594
+ return accu;
1595
+ }, {});
1596
+ if (metaDataChanged) {
1597
+ await durableStore.setMetadata(metadataEntries, DefaultDurableSegment);
1598
+ }
1599
+ if (config !== undefined && refresh !== undefined) {
1600
+ return environment.refreshPossibleStaleRecords(config, refresh);
1601
+ }
1602
+ return Promise.resolve();
1603
+ };
1578
1604
  // set the default cache policy of the base environment
1579
1605
  environment.setDefaultCachePolicy({
1580
1606
  type: 'stale-while-revalidate',
@@ -1607,6 +1633,7 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
1607
1633
  handleErrorResponse: { value: handleErrorResponse },
1608
1634
  getNotifyChangeStoreEntries: { value: getNotifyChangeStoreEntries },
1609
1635
  notifyStoreUpdateAvailable: { value: notifyStoreUpdateAvailable },
1636
+ expirePossibleStaleRecords: { value: expirePossibleStaleRecords },
1610
1637
  });
1611
1638
  }
1612
1639
 
@@ -5655,7 +5682,7 @@ class DurableDraftQueue {
5655
5682
  if (status === DraftActionStatus.Error) {
5656
5683
  this.state = DraftQueueState.Error;
5657
5684
  this.processingAction = undefined;
5658
- this.notifyChangedListeners({
5685
+ await this.notifyChangedListeners({
5659
5686
  type: DraftQueueEventType.ActionFailed,
5660
5687
  action: action,
5661
5688
  });
@@ -5671,7 +5698,7 @@ class DurableDraftQueue {
5671
5698
  if (this.state === DraftQueueState.Waiting) {
5672
5699
  this.state = DraftQueueState.Started;
5673
5700
  }
5674
- this.notifyChangedListeners({
5701
+ await this.notifyChangedListeners({
5675
5702
  type: DraftQueueEventType.ActionUploading,
5676
5703
  action: { ...action, status: DraftActionStatus.Uploading },
5677
5704
  });
@@ -5778,17 +5805,21 @@ class DurableDraftQueue {
5778
5805
  });
5779
5806
  return action;
5780
5807
  }
5781
- scheduleRetryWithSpecifiedDelay(retryDelayInMs) {
5808
+ async scheduleRetryWithSpecifiedDelay(retryDelayInMs) {
5809
+ await this.notifyChangedListeners({
5810
+ type: DraftQueueEventType.QueueStateChanged,
5811
+ state: DraftQueueState.Waiting,
5812
+ });
5782
5813
  this.timeoutHandler = setTimeout(() => {
5783
5814
  if (this.state !== DraftQueueState.Stopped) {
5784
5815
  this.processNextAction();
5785
5816
  }
5786
5817
  }, retryDelayInMs);
5787
5818
  }
5788
- scheduleRetry() {
5819
+ async scheduleRetry() {
5789
5820
  const newInterval = this.retryIntervalMilliseconds * 2;
5790
5821
  this.retryIntervalMilliseconds = Math.min(Math.max(newInterval, this.minimumRetryInterval), this.maximumRetryInterval);
5791
- this.scheduleRetryWithSpecifiedDelay(this.retryIntervalMilliseconds);
5822
+ return this.scheduleRetryWithSpecifiedDelay(this.retryIntervalMilliseconds);
5792
5823
  }
5793
5824
  async getActionsForReplaceOrMerge(targetActionId, sourceActionId) {
5794
5825
  const actions = await this.getQueueActions();
@@ -5914,7 +5945,8 @@ class DurableDraftStore {
5914
5945
  const actionArray = [];
5915
5946
  for (let i = 0, len = keys$1.length; i < len; i++) {
5916
5947
  const key = keys$1[i];
5917
- actionArray.push(draftStore[key]);
5948
+ // clone draft so we don't expose the internal draft store
5949
+ actionArray.push(clone$1(draftStore[key]));
5918
5950
  }
5919
5951
  return actionArray;
5920
5952
  });
@@ -6563,6 +6595,7 @@ var DraftQueueOperationType;
6563
6595
  DraftQueueOperationType["ItemUpdated"] = "updated";
6564
6596
  DraftQueueOperationType["QueueStarted"] = "started";
6565
6597
  DraftQueueOperationType["QueueStopped"] = "stopped";
6598
+ DraftQueueOperationType["QueueWaiting"] = "waiting";
6566
6599
  })(DraftQueueOperationType || (DraftQueueOperationType = {}));
6567
6600
  /**
6568
6601
  * Converts the internal DraftAction's ResourceRequest into
@@ -6605,6 +6638,16 @@ function toQueueState(queue) {
6605
6638
  };
6606
6639
  }
6607
6640
  class DraftManager {
6641
+ shouldEmitEvent(event) {
6642
+ // Waiting events cannot be emitted prior to 252 native clients
6643
+ // TODO [W-16102411]: we can safely remove this backwards compatible code in 256
6644
+ if (isDraftQueueStateChangeEvent(event) &&
6645
+ event.state === DraftQueueState.Waiting &&
6646
+ this.listenerVersion === undefined) {
6647
+ return false;
6648
+ }
6649
+ return this.draftEventsShouldBeEmitted.includes(event.type);
6650
+ }
6608
6651
  constructor(draftQueue) {
6609
6652
  this.listeners = [];
6610
6653
  this.draftEventsShouldBeEmitted = [
@@ -6618,7 +6661,7 @@ class DraftManager {
6618
6661
  ];
6619
6662
  this.draftQueue = draftQueue;
6620
6663
  draftQueue.registerOnChangedListener((event) => {
6621
- if (this.draftEventsShouldBeEmitted.includes(event.type)) {
6664
+ if (this.shouldEmitEvent(event)) {
6622
6665
  return this.callListeners(event);
6623
6666
  }
6624
6667
  return Promise.resolve();
@@ -6648,6 +6691,8 @@ class DraftManager {
6648
6691
  return DraftQueueOperationType.QueueStarted;
6649
6692
  case DraftQueueState.Stopped:
6650
6693
  return DraftQueueOperationType.QueueStopped;
6694
+ case DraftQueueState.Waiting:
6695
+ return DraftQueueOperationType.QueueWaiting;
6651
6696
  default:
6652
6697
  throw Error('Unsupported event type');
6653
6698
  }
@@ -6705,7 +6750,8 @@ class DraftManager {
6705
6750
  *
6706
6751
  * @param listener The listener closure to subscribe to changes
6707
6752
  */
6708
- registerDraftQueueChangedListener(listener) {
6753
+ registerDraftQueueChangedListener(listener, version = undefined) {
6754
+ this.listenerVersion = version;
6709
6755
  this.listeners.push(listener);
6710
6756
  return () => {
6711
6757
  this.listeners = this.listeners.filter((l) => {
@@ -8530,6 +8576,7 @@ class QuickActionExecutionRepresentationHandler extends AbstractResourceRequestA
8530
8576
  isCreated: true,
8531
8577
  isSuccess: true,
8532
8578
  successMessage: `record created.`,
8579
+ drafts: { draftActionId: action.id },
8533
8580
  });
8534
8581
  }
8535
8582
  getDraftMetadata(_key) {
@@ -8647,6 +8694,7 @@ class UpdateRecordQuickActionExecutionRepresentationHandler extends AbstractReso
8647
8694
  isCreated: false,
8648
8695
  isSuccess: true,
8649
8696
  successMessage: `record updated.`,
8697
+ drafts: { draftActionId: action.id },
8650
8698
  });
8651
8699
  }
8652
8700
  async getDraftMetadata(key) {
@@ -18530,4 +18578,4 @@ register({
18530
18578
  });
18531
18579
 
18532
18580
  export { O11Y_NAMESPACE_LDS_MOBILE, getRuntime, registerReportObserver, reportGraphqlQueryParseError };
18533
- // version: 1.302.0-e45992a1f4
18581
+ // version: 1.303.0-a698c7cc67
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-mobile",
3
- "version": "1.302.0",
3
+ "version": "1.303.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS runtime for mobile/hybrid environments.",
6
6
  "main": "dist/main.js",
@@ -32,27 +32,27 @@
32
32
  "release:corejar": "yarn build && ../core-build/scripts/core.js --name=lds-runtime-mobile"
33
33
  },
34
34
  "dependencies": {
35
- "@salesforce/lds-adapters-uiapi-mobile": "^1.302.0",
36
- "@salesforce/lds-bindings": "^1.302.0",
37
- "@salesforce/lds-instrumentation": "^1.302.0",
38
- "@salesforce/lds-priming": "^1.302.0",
35
+ "@salesforce/lds-adapters-uiapi-mobile": "^1.303.0",
36
+ "@salesforce/lds-bindings": "^1.303.0",
37
+ "@salesforce/lds-instrumentation": "^1.303.0",
38
+ "@salesforce/lds-priming": "^1.303.0",
39
39
  "@salesforce/user": "0.0.21",
40
40
  "o11y": "250.7.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@salesforce/lds-adapters-graphql": "^1.302.0",
44
- "@salesforce/lds-drafts": "^1.302.0",
45
- "@salesforce/lds-drafts-adapters-uiapi": "^1.302.0",
46
- "@salesforce/lds-durable-records": "^1.302.0",
47
- "@salesforce/lds-graphql-eval": "^1.302.0",
48
- "@salesforce/lds-graphql-local-evaluation": "^1.302.0",
49
- "@salesforce/lds-network-adapter": "^1.302.0",
50
- "@salesforce/lds-network-nimbus": "^1.302.0",
51
- "@salesforce/lds-store-binary": "^1.302.0",
52
- "@salesforce/lds-store-nimbus": "^1.302.0",
53
- "@salesforce/lds-store-sql": "^1.302.0",
54
- "@salesforce/lds-utils-adapters": "^1.302.0",
55
- "@salesforce/nimbus-plugin-lds": "^1.302.0",
43
+ "@salesforce/lds-adapters-graphql": "^1.303.0",
44
+ "@salesforce/lds-drafts": "^1.303.0",
45
+ "@salesforce/lds-drafts-adapters-uiapi": "^1.303.0",
46
+ "@salesforce/lds-durable-records": "^1.303.0",
47
+ "@salesforce/lds-graphql-eval": "^1.303.0",
48
+ "@salesforce/lds-graphql-local-evaluation": "^1.303.0",
49
+ "@salesforce/lds-network-adapter": "^1.303.0",
50
+ "@salesforce/lds-network-nimbus": "^1.303.0",
51
+ "@salesforce/lds-store-binary": "^1.303.0",
52
+ "@salesforce/lds-store-nimbus": "^1.303.0",
53
+ "@salesforce/lds-store-sql": "^1.303.0",
54
+ "@salesforce/lds-utils-adapters": "^1.303.0",
55
+ "@salesforce/nimbus-plugin-lds": "^1.303.0",
56
56
  "babel-plugin-dynamic-import-node": "^2.3.3",
57
57
  "wait-for-expect": "^3.0.2"
58
58
  },
package/sfdc/main.js CHANGED
@@ -1575,6 +1575,32 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
1575
1575
  }, revivingStore).finally(() => {
1576
1576
  });
1577
1577
  };
1578
+ const expirePossibleStaleRecords = async function (keys$1, config, refresh) {
1579
+ validateNotDisposed();
1580
+ const metadataKeys = keys$1.map(serializeStructuredKey);
1581
+ const now = Date.now();
1582
+ const entries = await durableStore.getMetadata(metadataKeys, DefaultDurableSegment);
1583
+ if (entries === undefined || keys$8(entries).length === 0) {
1584
+ return environment.expirePossibleStaleRecords(keys$1);
1585
+ }
1586
+ let metaDataChanged = false;
1587
+ const metadataEntries = metadataKeys.reduce((accu, key) => {
1588
+ const metadataEntry = entries[key];
1589
+ if (metadataEntry.metadata !== undefined) {
1590
+ const metadata = { ...metadataEntry.metadata, expirationTimestamp: now };
1591
+ accu[key] = { metadata };
1592
+ metaDataChanged = true;
1593
+ }
1594
+ return accu;
1595
+ }, {});
1596
+ if (metaDataChanged) {
1597
+ await durableStore.setMetadata(metadataEntries, DefaultDurableSegment);
1598
+ }
1599
+ if (config !== undefined && refresh !== undefined) {
1600
+ return environment.refreshPossibleStaleRecords(config, refresh);
1601
+ }
1602
+ return Promise.resolve();
1603
+ };
1578
1604
  // set the default cache policy of the base environment
1579
1605
  environment.setDefaultCachePolicy({
1580
1606
  type: 'stale-while-revalidate',
@@ -1607,6 +1633,7 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
1607
1633
  handleErrorResponse: { value: handleErrorResponse },
1608
1634
  getNotifyChangeStoreEntries: { value: getNotifyChangeStoreEntries },
1609
1635
  notifyStoreUpdateAvailable: { value: notifyStoreUpdateAvailable },
1636
+ expirePossibleStaleRecords: { value: expirePossibleStaleRecords },
1610
1637
  });
1611
1638
  }
1612
1639
 
@@ -5655,7 +5682,7 @@ class DurableDraftQueue {
5655
5682
  if (status === DraftActionStatus.Error) {
5656
5683
  this.state = DraftQueueState.Error;
5657
5684
  this.processingAction = undefined;
5658
- this.notifyChangedListeners({
5685
+ await this.notifyChangedListeners({
5659
5686
  type: DraftQueueEventType.ActionFailed,
5660
5687
  action: action,
5661
5688
  });
@@ -5671,7 +5698,7 @@ class DurableDraftQueue {
5671
5698
  if (this.state === DraftQueueState.Waiting) {
5672
5699
  this.state = DraftQueueState.Started;
5673
5700
  }
5674
- this.notifyChangedListeners({
5701
+ await this.notifyChangedListeners({
5675
5702
  type: DraftQueueEventType.ActionUploading,
5676
5703
  action: { ...action, status: DraftActionStatus.Uploading },
5677
5704
  });
@@ -5778,17 +5805,21 @@ class DurableDraftQueue {
5778
5805
  });
5779
5806
  return action;
5780
5807
  }
5781
- scheduleRetryWithSpecifiedDelay(retryDelayInMs) {
5808
+ async scheduleRetryWithSpecifiedDelay(retryDelayInMs) {
5809
+ await this.notifyChangedListeners({
5810
+ type: DraftQueueEventType.QueueStateChanged,
5811
+ state: DraftQueueState.Waiting,
5812
+ });
5782
5813
  this.timeoutHandler = setTimeout(() => {
5783
5814
  if (this.state !== DraftQueueState.Stopped) {
5784
5815
  this.processNextAction();
5785
5816
  }
5786
5817
  }, retryDelayInMs);
5787
5818
  }
5788
- scheduleRetry() {
5819
+ async scheduleRetry() {
5789
5820
  const newInterval = this.retryIntervalMilliseconds * 2;
5790
5821
  this.retryIntervalMilliseconds = Math.min(Math.max(newInterval, this.minimumRetryInterval), this.maximumRetryInterval);
5791
- this.scheduleRetryWithSpecifiedDelay(this.retryIntervalMilliseconds);
5822
+ return this.scheduleRetryWithSpecifiedDelay(this.retryIntervalMilliseconds);
5792
5823
  }
5793
5824
  async getActionsForReplaceOrMerge(targetActionId, sourceActionId) {
5794
5825
  const actions = await this.getQueueActions();
@@ -5914,7 +5945,8 @@ class DurableDraftStore {
5914
5945
  const actionArray = [];
5915
5946
  for (let i = 0, len = keys$1.length; i < len; i++) {
5916
5947
  const key = keys$1[i];
5917
- actionArray.push(draftStore[key]);
5948
+ // clone draft so we don't expose the internal draft store
5949
+ actionArray.push(clone$1(draftStore[key]));
5918
5950
  }
5919
5951
  return actionArray;
5920
5952
  });
@@ -6563,6 +6595,7 @@ var DraftQueueOperationType;
6563
6595
  DraftQueueOperationType["ItemUpdated"] = "updated";
6564
6596
  DraftQueueOperationType["QueueStarted"] = "started";
6565
6597
  DraftQueueOperationType["QueueStopped"] = "stopped";
6598
+ DraftQueueOperationType["QueueWaiting"] = "waiting";
6566
6599
  })(DraftQueueOperationType || (DraftQueueOperationType = {}));
6567
6600
  /**
6568
6601
  * Converts the internal DraftAction's ResourceRequest into
@@ -6605,6 +6638,16 @@ function toQueueState(queue) {
6605
6638
  };
6606
6639
  }
6607
6640
  class DraftManager {
6641
+ shouldEmitEvent(event) {
6642
+ // Waiting events cannot be emitted prior to 252 native clients
6643
+ // TODO [W-16102411]: we can safely remove this backwards compatible code in 256
6644
+ if (isDraftQueueStateChangeEvent(event) &&
6645
+ event.state === DraftQueueState.Waiting &&
6646
+ this.listenerVersion === undefined) {
6647
+ return false;
6648
+ }
6649
+ return this.draftEventsShouldBeEmitted.includes(event.type);
6650
+ }
6608
6651
  constructor(draftQueue) {
6609
6652
  this.listeners = [];
6610
6653
  this.draftEventsShouldBeEmitted = [
@@ -6618,7 +6661,7 @@ class DraftManager {
6618
6661
  ];
6619
6662
  this.draftQueue = draftQueue;
6620
6663
  draftQueue.registerOnChangedListener((event) => {
6621
- if (this.draftEventsShouldBeEmitted.includes(event.type)) {
6664
+ if (this.shouldEmitEvent(event)) {
6622
6665
  return this.callListeners(event);
6623
6666
  }
6624
6667
  return Promise.resolve();
@@ -6648,6 +6691,8 @@ class DraftManager {
6648
6691
  return DraftQueueOperationType.QueueStarted;
6649
6692
  case DraftQueueState.Stopped:
6650
6693
  return DraftQueueOperationType.QueueStopped;
6694
+ case DraftQueueState.Waiting:
6695
+ return DraftQueueOperationType.QueueWaiting;
6651
6696
  default:
6652
6697
  throw Error('Unsupported event type');
6653
6698
  }
@@ -6705,7 +6750,8 @@ class DraftManager {
6705
6750
  *
6706
6751
  * @param listener The listener closure to subscribe to changes
6707
6752
  */
6708
- registerDraftQueueChangedListener(listener) {
6753
+ registerDraftQueueChangedListener(listener, version = undefined) {
6754
+ this.listenerVersion = version;
6709
6755
  this.listeners.push(listener);
6710
6756
  return () => {
6711
6757
  this.listeners = this.listeners.filter((l) => {
@@ -8530,6 +8576,7 @@ class QuickActionExecutionRepresentationHandler extends AbstractResourceRequestA
8530
8576
  isCreated: true,
8531
8577
  isSuccess: true,
8532
8578
  successMessage: `record created.`,
8579
+ drafts: { draftActionId: action.id },
8533
8580
  });
8534
8581
  }
8535
8582
  getDraftMetadata(_key) {
@@ -8647,6 +8694,7 @@ class UpdateRecordQuickActionExecutionRepresentationHandler extends AbstractReso
8647
8694
  isCreated: false,
8648
8695
  isSuccess: true,
8649
8696
  successMessage: `record updated.`,
8697
+ drafts: { draftActionId: action.id },
8650
8698
  });
8651
8699
  }
8652
8700
  async getDraftMetadata(key) {
@@ -18530,4 +18578,4 @@ register({
18530
18578
  });
18531
18579
 
18532
18580
  export { O11Y_NAMESPACE_LDS_MOBILE, getRuntime, registerReportObserver, reportGraphqlQueryParseError };
18533
- // version: 1.302.0-e45992a1f4
18581
+ // version: 1.303.0-a698c7cc67