@salesforce/lds-worker-api 1.301.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.
@@ -1071,4 +1071,4 @@ if (process.env.NODE_ENV !== 'production') {
1071
1071
  }
1072
1072
 
1073
1073
  export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToMerge, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
1074
- // version: 1.301.0-ecd340c2e1
1074
+ // version: 1.303.0-a698c7cc67
@@ -835,14 +835,7 @@ class StringKeyInMemoryStore {
835
835
  // of the function, in case the reference changes (because of an unsubscribe)
836
836
  const { snapshotSubscriptions } = this;
837
837
  // read metadata for each key, and mark as expired
838
- const expirationTimestamp = Date.now();
839
- for (let i = 0, len = keys.length; i < len; i++) {
840
- const key = keys[i];
841
- const metadata = this.readMetadata(key);
842
- if (metadata !== undefined) {
843
- this.publishMetadata(key, { ...metadata, expirationTimestamp });
844
- }
845
- }
838
+ this.expirePossibleStaleRecords(keys);
846
839
  // Process snapshot subscriptions
847
840
  const pendingPromises = [];
848
841
  for (let i = 0, len = snapshotSubscriptions.length; i < len; i++) {
@@ -937,6 +930,16 @@ class StringKeyInMemoryStore {
937
930
  this.metadata[canonicalKey] = storeMetadata;
938
931
  }
939
932
  }
933
+ expirePossibleStaleRecords(keys) {
934
+ const expirationTimestamp = Date.now();
935
+ for (let i = 0, len = keys.length; i < len; i++) {
936
+ const key = keys[i];
937
+ const metadata = this.readMetadata(key);
938
+ if (metadata !== undefined) {
939
+ this.publishMetadata(key, { ...metadata, expirationTimestamp });
940
+ }
941
+ }
942
+ }
940
943
  setTTLOverride(namespace, representationName, ttl) {
941
944
  this.ttlOverrides[getTTLOverrideKey(namespace, representationName)] = ttl;
942
945
  }
@@ -1531,14 +1534,7 @@ class InMemoryStore {
1531
1534
  // of the function, in case the reference changes (because of an unsubscribe)
1532
1535
  const { snapshotSubscriptions } = this;
1533
1536
  // read metadata for each key, and mark as expired
1534
- const expirationTimestamp = Date.now();
1535
- for (let i = 0, len = keys.length; i < len; i++) {
1536
- const key = keys[i];
1537
- const metadata = this.readMetadata(key);
1538
- if (metadata !== undefined) {
1539
- this.publishMetadata(key, { ...metadata, expirationTimestamp });
1540
- }
1541
- }
1537
+ this.expirePossibleStaleRecords(keys);
1542
1538
  // Process snapshot subscriptions
1543
1539
  const pendingPromises = [];
1544
1540
  for (let i = 0, len = snapshotSubscriptions.length; i < len; i++) {
@@ -1661,6 +1657,19 @@ class InMemoryStore {
1661
1657
  this.metadataMap.set(canonicalKey, storeMetadata);
1662
1658
  }
1663
1659
  }
1660
+ expirePossibleStaleRecords(keys) {
1661
+ if (keys.length > 0 && typeof keys[0] === 'string') {
1662
+ return this.fallbackStringKeyInMemoryStore.expirePossibleStaleRecords(keys);
1663
+ }
1664
+ const expirationTimestamp = Date.now();
1665
+ for (let i = 0, len = keys.length; i < len; i++) {
1666
+ const key = keys[i];
1667
+ const metadata = this.readMetadata(key);
1668
+ if (metadata !== undefined) {
1669
+ this.publishMetadata(key, { ...metadata, expirationTimestamp });
1670
+ }
1671
+ }
1672
+ }
1664
1673
  setTTLOverride(namespace, representationName, ttl) {
1665
1674
  // Set the TTLs in both the stores
1666
1675
  this.fallbackStringKeyInMemoryStore.setTTLOverride(namespace, representationName, ttl);
@@ -2250,6 +2259,20 @@ class GraphNode {
2250
2259
  const value = this.data[propertyName];
2251
2260
  return typeof value !== 'object' || value === null;
2252
2261
  }
2262
+ isMissing(propertyName) {
2263
+ const value = this.data[propertyName];
2264
+ if (value && typeof value.__state === 'object' && value.__state !== null) {
2265
+ return !!value.__state.isMissing;
2266
+ }
2267
+ return false;
2268
+ }
2269
+ isPending(propertyName) {
2270
+ const value = this.data[propertyName];
2271
+ if (value && typeof value.__state === 'object' && value.__state !== null) {
2272
+ return !!value.__state.pending;
2273
+ }
2274
+ return false;
2275
+ }
2253
2276
  write(propertyName, value) {
2254
2277
  this.data[propertyName] = value;
2255
2278
  const canonicalKey = this.store.getCanonicalRecordId(this.storeKey);
@@ -3633,6 +3656,30 @@ class Environment {
3633
3656
  buildStructuredKey(namespace, representationName, idValues) {
3634
3657
  return this.store.buildStructuredKey(namespace, representationName, idValues);
3635
3658
  }
3659
+ /**
3660
+ * Take a list of keys and marks them as stale to be refreshed.
3661
+ * Then will be refreshed with the provided refresh function.
3662
+ * If no refresh and makeConfig functions are provided it will refresh
3663
+ * time that record is trying to be fetched
3664
+ *
3665
+ * Example: one record from graphql needs to be refreshed and not
3666
+ * the entire graphql query
3667
+ *
3668
+ * @param keys
3669
+ * @param makeConfig
3670
+ * @param refresh
3671
+ * @returns
3672
+ */
3673
+ expirePossibleStaleRecords(keys, config, refresh) {
3674
+ this.store.expirePossibleStaleRecords(keys);
3675
+ if (refresh !== undefined && config !== undefined) {
3676
+ return this.refreshPossibleStaleRecords(config, refresh);
3677
+ }
3678
+ return Promise.resolve();
3679
+ }
3680
+ refreshPossibleStaleRecords(config, refresh) {
3681
+ return Promise.resolve(refresh(config, { cachePolicy: { type: 'no-cache' } })).then(() => { });
3682
+ }
3636
3683
  }
3637
3684
 
3638
3685
  class Luvio {
@@ -3699,6 +3746,9 @@ class Luvio {
3699
3746
  storeCleanup() {
3700
3747
  this.environment.storeCleanup();
3701
3748
  }
3749
+ storeExpirePossibleStaleRecords(keys, config, refresh) {
3750
+ return this.environment.expirePossibleStaleRecords(keys, config, refresh);
3751
+ }
3702
3752
  createSnapshot(selector, refresh) {
3703
3753
  return this.environment.createSnapshot(selector, refresh);
3704
3754
  }
@@ -4087,7 +4137,7 @@ function createResourceParamsImpl(config, configMetadata) {
4087
4137
  }
4088
4138
  return resourceParams;
4089
4139
  }
4090
- // engine version: 0.155.1-284dbf66
4140
+ // engine version: 0.156.3-04c1a80e
4091
4141
 
4092
4142
  /**
4093
4143
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -4215,7 +4265,7 @@ function withDefaultLuvio(callback) {
4215
4265
  }
4216
4266
  callbacks.push(callback);
4217
4267
  }
4218
- // version: 1.301.0-ecd340c2e1
4268
+ // version: 1.303.0-a698c7cc67
4219
4269
 
4220
4270
  // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
4221
4271
  function instrumentAdapter$1(createFunction, _metadata) {
@@ -15714,7 +15764,7 @@ function gql(literals, ...subs) {
15714
15764
  }
15715
15765
  return superResult;
15716
15766
  }
15717
- // version: 1.301.0-ecd340c2e1
15767
+ // version: 1.303.0-a698c7cc67
15718
15768
 
15719
15769
  function unwrap(data) {
15720
15770
  // The lwc-luvio bindings import a function from lwc called "unwrap".
@@ -16643,7 +16693,7 @@ function createGraphQLWireAdapterConstructor(luvio, adapter, metadata, astResolv
16643
16693
  const { apiFamily, name } = metadata;
16644
16694
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16645
16695
  }
16646
- // version: 1.301.0-ecd340c2e1
16696
+ // version: 1.303.0-a698c7cc67
16647
16697
 
16648
16698
  /**
16649
16699
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -16742,7 +16792,7 @@ var TypeCheckShapes;
16742
16792
  TypeCheckShapes[TypeCheckShapes["Integer"] = 3] = "Integer";
16743
16793
  TypeCheckShapes[TypeCheckShapes["Unsupported"] = 4] = "Unsupported";
16744
16794
  })(TypeCheckShapes || (TypeCheckShapes = {}));
16745
- // engine version: 0.155.1-284dbf66
16795
+ // engine version: 0.156.3-04c1a80e
16746
16796
 
16747
16797
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16748
16798
 
@@ -18217,7 +18267,7 @@ const CHILD_RELATIONSHIP_SELECTION = {
18217
18267
  // be applied to a RecordRepresentation in environments configured with
18218
18268
  // drafts when the record has draft changes applied to it
18219
18269
  // TODO [W-8237087]: explore if this selection can only be added in environments where drafts are enabled
18220
- const DRAFTS_SELECTION = {
18270
+ const DRAFTS_SELECTION$1 = {
18221
18271
  kind: 'Object',
18222
18272
  opaque: true,
18223
18273
  name: 'drafts',
@@ -18231,7 +18281,7 @@ function createRecordSelection(fieldDefinition) {
18231
18281
  childRelationships: CHILD_RELATIONSHIP_SELECTION,
18232
18282
  fields: createPathSelection('fields', fieldDefinition),
18233
18283
  });
18234
- return [...sel.selections, DRAFTS_SELECTION];
18284
+ return [...sel.selections, DRAFTS_SELECTION$1];
18235
18285
  }
18236
18286
  /**
18237
18287
  * Convert a list of fields and optional fields into RecordRepresentation its equivalent
@@ -18248,7 +18298,7 @@ function buildSelectionFromRecord(record) {
18248
18298
  childRelationships: CHILD_RELATIONSHIP_SELECTION,
18249
18299
  fields: createPathSelectionFromValue(record.fields),
18250
18300
  });
18251
- return [...sel.selections, DRAFTS_SELECTION];
18301
+ return [...sel.selections, DRAFTS_SELECTION$1];
18252
18302
  }
18253
18303
 
18254
18304
  const MAX_RECORD_DEPTH = 5;
@@ -26503,6 +26553,12 @@ function keyBuilderFromType$r(luvio, object) {
26503
26553
  function normalize$A(input, existing, path, luvio, store, timestamp) {
26504
26554
  return input;
26505
26555
  }
26556
+ const DRAFTS_SELECTION = {
26557
+ kind: 'Object',
26558
+ opaque: true,
26559
+ name: 'drafts',
26560
+ required: false,
26561
+ };
26506
26562
  const select$1A = function QuickActionExecutionRepresentationSelect() {
26507
26563
  return {
26508
26564
  kind: 'Fragment',
@@ -26534,7 +26590,7 @@ const select$1A = function QuickActionExecutionRepresentationSelect() {
26534
26590
  {
26535
26591
  name: 'successMessage',
26536
26592
  kind: 'Scalar'
26537
- }
26593
+ }, DRAFTS_SELECTION,
26538
26594
  ]
26539
26595
  };
26540
26596
  };
@@ -44130,7 +44186,7 @@ withDefaultLuvio((luvio) => {
44130
44186
  throttle(60, 60000, setupNotifyAllListRecordUpdateAvailable(luvio));
44131
44187
  throttle(60, 60000, setupNotifyAllListInfoSummaryUpdateAvailable(luvio));
44132
44188
  });
44133
- // version: 1.301.0-4216dc9d10
44189
+ // version: 1.303.0-b6ed223d95
44134
44190
 
44135
44191
  var ldsIdempotencyWriteDisabled = {
44136
44192
  isOpen: function (e) {
@@ -45814,6 +45870,32 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
45814
45870
  }, revivingStore).finally(() => {
45815
45871
  });
45816
45872
  };
45873
+ const expirePossibleStaleRecords = async function (keys$1, config, refresh) {
45874
+ validateNotDisposed();
45875
+ const metadataKeys = keys$1.map(serializeStructuredKey);
45876
+ const now = Date.now();
45877
+ const entries = await durableStore.getMetadata(metadataKeys, DefaultDurableSegment);
45878
+ if (entries === undefined || keys$8(entries).length === 0) {
45879
+ return environment.expirePossibleStaleRecords(keys$1);
45880
+ }
45881
+ let metaDataChanged = false;
45882
+ const metadataEntries = metadataKeys.reduce((accu, key) => {
45883
+ const metadataEntry = entries[key];
45884
+ if (metadataEntry.metadata !== undefined) {
45885
+ const metadata = { ...metadataEntry.metadata, expirationTimestamp: now };
45886
+ accu[key] = { metadata };
45887
+ metaDataChanged = true;
45888
+ }
45889
+ return accu;
45890
+ }, {});
45891
+ if (metaDataChanged) {
45892
+ await durableStore.setMetadata(metadataEntries, DefaultDurableSegment);
45893
+ }
45894
+ if (config !== undefined && refresh !== undefined) {
45895
+ return environment.refreshPossibleStaleRecords(config, refresh);
45896
+ }
45897
+ return Promise.resolve();
45898
+ };
45817
45899
  // set the default cache policy of the base environment
45818
45900
  environment.setDefaultCachePolicy({
45819
45901
  type: 'stale-while-revalidate',
@@ -45846,6 +45928,7 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
45846
45928
  handleErrorResponse: { value: handleErrorResponse },
45847
45929
  getNotifyChangeStoreEntries: { value: getNotifyChangeStoreEntries },
45848
45930
  notifyStoreUpdateAvailable: { value: notifyStoreUpdateAvailable },
45931
+ expirePossibleStaleRecords: { value: expirePossibleStaleRecords },
45849
45932
  });
45850
45933
  }
45851
45934
 
@@ -49892,7 +49975,7 @@ class DurableDraftQueue {
49892
49975
  if (status === DraftActionStatus.Error) {
49893
49976
  this.state = DraftQueueState.Error;
49894
49977
  this.processingAction = undefined;
49895
- this.notifyChangedListeners({
49978
+ await this.notifyChangedListeners({
49896
49979
  type: DraftQueueEventType.ActionFailed,
49897
49980
  action: action,
49898
49981
  });
@@ -49908,7 +49991,7 @@ class DurableDraftQueue {
49908
49991
  if (this.state === DraftQueueState.Waiting) {
49909
49992
  this.state = DraftQueueState.Started;
49910
49993
  }
49911
- this.notifyChangedListeners({
49994
+ await this.notifyChangedListeners({
49912
49995
  type: DraftQueueEventType.ActionUploading,
49913
49996
  action: { ...action, status: DraftActionStatus.Uploading },
49914
49997
  });
@@ -50015,17 +50098,21 @@ class DurableDraftQueue {
50015
50098
  });
50016
50099
  return action;
50017
50100
  }
50018
- scheduleRetryWithSpecifiedDelay(retryDelayInMs) {
50101
+ async scheduleRetryWithSpecifiedDelay(retryDelayInMs) {
50102
+ await this.notifyChangedListeners({
50103
+ type: DraftQueueEventType.QueueStateChanged,
50104
+ state: DraftQueueState.Waiting,
50105
+ });
50019
50106
  this.timeoutHandler = setTimeout(() => {
50020
50107
  if (this.state !== DraftQueueState.Stopped) {
50021
50108
  this.processNextAction();
50022
50109
  }
50023
50110
  }, retryDelayInMs);
50024
50111
  }
50025
- scheduleRetry() {
50112
+ async scheduleRetry() {
50026
50113
  const newInterval = this.retryIntervalMilliseconds * 2;
50027
50114
  this.retryIntervalMilliseconds = Math.min(Math.max(newInterval, this.minimumRetryInterval), this.maximumRetryInterval);
50028
- this.scheduleRetryWithSpecifiedDelay(this.retryIntervalMilliseconds);
50115
+ return this.scheduleRetryWithSpecifiedDelay(this.retryIntervalMilliseconds);
50029
50116
  }
50030
50117
  async getActionsForReplaceOrMerge(targetActionId, sourceActionId) {
50031
50118
  const actions = await this.getQueueActions();
@@ -50151,7 +50238,8 @@ class DurableDraftStore {
50151
50238
  const actionArray = [];
50152
50239
  for (let i = 0, len = keys$1.length; i < len; i++) {
50153
50240
  const key = keys$1[i];
50154
- actionArray.push(draftStore[key]);
50241
+ // clone draft so we don't expose the internal draft store
50242
+ actionArray.push(clone$1(draftStore[key]));
50155
50243
  }
50156
50244
  return actionArray;
50157
50245
  });
@@ -50786,6 +50874,7 @@ var DraftQueueOperationType;
50786
50874
  DraftQueueOperationType["ItemUpdated"] = "updated";
50787
50875
  DraftQueueOperationType["QueueStarted"] = "started";
50788
50876
  DraftQueueOperationType["QueueStopped"] = "stopped";
50877
+ DraftQueueOperationType["QueueWaiting"] = "waiting";
50789
50878
  })(DraftQueueOperationType || (DraftQueueOperationType = {}));
50790
50879
  /**
50791
50880
  * Converts the internal DraftAction's ResourceRequest into
@@ -50828,6 +50917,16 @@ function toQueueState(queue) {
50828
50917
  };
50829
50918
  }
50830
50919
  class DraftManager {
50920
+ shouldEmitEvent(event) {
50921
+ // Waiting events cannot be emitted prior to 252 native clients
50922
+ // TODO [W-16102411]: we can safely remove this backwards compatible code in 256
50923
+ if (isDraftQueueStateChangeEvent(event) &&
50924
+ event.state === DraftQueueState.Waiting &&
50925
+ this.listenerVersion === undefined) {
50926
+ return false;
50927
+ }
50928
+ return this.draftEventsShouldBeEmitted.includes(event.type);
50929
+ }
50831
50930
  constructor(draftQueue) {
50832
50931
  this.listeners = [];
50833
50932
  this.draftEventsShouldBeEmitted = [
@@ -50841,7 +50940,7 @@ class DraftManager {
50841
50940
  ];
50842
50941
  this.draftQueue = draftQueue;
50843
50942
  draftQueue.registerOnChangedListener((event) => {
50844
- if (this.draftEventsShouldBeEmitted.includes(event.type)) {
50943
+ if (this.shouldEmitEvent(event)) {
50845
50944
  return this.callListeners(event);
50846
50945
  }
50847
50946
  return Promise.resolve();
@@ -50871,6 +50970,8 @@ class DraftManager {
50871
50970
  return DraftQueueOperationType.QueueStarted;
50872
50971
  case DraftQueueState.Stopped:
50873
50972
  return DraftQueueOperationType.QueueStopped;
50973
+ case DraftQueueState.Waiting:
50974
+ return DraftQueueOperationType.QueueWaiting;
50874
50975
  default:
50875
50976
  throw Error('Unsupported event type');
50876
50977
  }
@@ -50928,7 +51029,8 @@ class DraftManager {
50928
51029
  *
50929
51030
  * @param listener The listener closure to subscribe to changes
50930
51031
  */
50931
- registerDraftQueueChangedListener(listener) {
51032
+ registerDraftQueueChangedListener(listener, version = undefined) {
51033
+ this.listenerVersion = version;
50932
51034
  this.listeners.push(listener);
50933
51035
  return () => {
50934
51036
  this.listeners = this.listeners.filter((l) => {
@@ -52753,6 +52855,7 @@ class QuickActionExecutionRepresentationHandler extends AbstractResourceRequestA
52753
52855
  isCreated: true,
52754
52856
  isSuccess: true,
52755
52857
  successMessage: `record created.`,
52858
+ drafts: { draftActionId: action.id },
52756
52859
  });
52757
52860
  }
52758
52861
  getDraftMetadata(_key) {
@@ -52870,6 +52973,7 @@ class UpdateRecordQuickActionExecutionRepresentationHandler extends AbstractReso
52870
52973
  isCreated: false,
52871
52974
  isSuccess: true,
52872
52975
  successMessage: `record updated.`,
52976
+ drafts: { draftActionId: action.id },
52873
52977
  });
52874
52978
  }
52875
52979
  async getDraftMetadata(key) {
@@ -62603,7 +62707,7 @@ register$1({
62603
62707
  id: '@salesforce/lds-network-adapter',
62604
62708
  instrument: instrument$2,
62605
62709
  });
62606
- // version: 1.301.0-ecd340c2e1
62710
+ // version: 1.303.0-a698c7cc67
62607
62711
 
62608
62712
  const { create: create$3, keys: keys$3 } = Object;
62609
62713
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -82639,7 +82743,7 @@ register$1({
82639
82743
  configuration: { ...configurationForGraphQLAdapters$1 },
82640
82744
  instrument: instrument$1,
82641
82745
  });
82642
- // version: 1.301.0-4216dc9d10
82746
+ // version: 1.303.0-b6ed223d95
82643
82747
 
82644
82748
  // On core the unstable adapters are re-exported with different names,
82645
82749
  // we want to match them here.
@@ -84895,7 +84999,7 @@ withDefaultLuvio((luvio) => {
84895
84999
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
84896
85000
  graphQLImperative = ldsAdapter;
84897
85001
  });
84898
- // version: 1.301.0-4216dc9d10
85002
+ // version: 1.303.0-b6ed223d95
84899
85003
 
84900
85004
  var gqlApi = /*#__PURE__*/Object.freeze({
84901
85005
  __proto__: null,
@@ -85630,7 +85734,7 @@ const callbacks$1 = [];
85630
85734
  function register(r) {
85631
85735
  callbacks$1.forEach((callback) => callback(r));
85632
85736
  }
85633
- // version: 1.301.0-ecd340c2e1
85737
+ // version: 1.303.0-a698c7cc67
85634
85738
 
85635
85739
  /**
85636
85740
  * Returns true if the value acts like a Promise, i.e. has a "then" function,
@@ -90592,4 +90696,4 @@ const { luvio } = getRuntime();
90592
90696
  setDefaultLuvio({ luvio });
90593
90697
 
90594
90698
  export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToMerge, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, registerReportObserver, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
90595
- // version: 1.301.0-ecd340c2e1
90699
+ // version: 1.303.0-a698c7cc67
@@ -841,14 +841,7 @@
841
841
  // of the function, in case the reference changes (because of an unsubscribe)
842
842
  const { snapshotSubscriptions } = this;
843
843
  // read metadata for each key, and mark as expired
844
- const expirationTimestamp = Date.now();
845
- for (let i = 0, len = keys.length; i < len; i++) {
846
- const key = keys[i];
847
- const metadata = this.readMetadata(key);
848
- if (metadata !== undefined) {
849
- this.publishMetadata(key, { ...metadata, expirationTimestamp });
850
- }
851
- }
844
+ this.expirePossibleStaleRecords(keys);
852
845
  // Process snapshot subscriptions
853
846
  const pendingPromises = [];
854
847
  for (let i = 0, len = snapshotSubscriptions.length; i < len; i++) {
@@ -943,6 +936,16 @@
943
936
  this.metadata[canonicalKey] = storeMetadata;
944
937
  }
945
938
  }
939
+ expirePossibleStaleRecords(keys) {
940
+ const expirationTimestamp = Date.now();
941
+ for (let i = 0, len = keys.length; i < len; i++) {
942
+ const key = keys[i];
943
+ const metadata = this.readMetadata(key);
944
+ if (metadata !== undefined) {
945
+ this.publishMetadata(key, { ...metadata, expirationTimestamp });
946
+ }
947
+ }
948
+ }
946
949
  setTTLOverride(namespace, representationName, ttl) {
947
950
  this.ttlOverrides[getTTLOverrideKey(namespace, representationName)] = ttl;
948
951
  }
@@ -1537,14 +1540,7 @@
1537
1540
  // of the function, in case the reference changes (because of an unsubscribe)
1538
1541
  const { snapshotSubscriptions } = this;
1539
1542
  // read metadata for each key, and mark as expired
1540
- const expirationTimestamp = Date.now();
1541
- for (let i = 0, len = keys.length; i < len; i++) {
1542
- const key = keys[i];
1543
- const metadata = this.readMetadata(key);
1544
- if (metadata !== undefined) {
1545
- this.publishMetadata(key, { ...metadata, expirationTimestamp });
1546
- }
1547
- }
1543
+ this.expirePossibleStaleRecords(keys);
1548
1544
  // Process snapshot subscriptions
1549
1545
  const pendingPromises = [];
1550
1546
  for (let i = 0, len = snapshotSubscriptions.length; i < len; i++) {
@@ -1667,6 +1663,19 @@
1667
1663
  this.metadataMap.set(canonicalKey, storeMetadata);
1668
1664
  }
1669
1665
  }
1666
+ expirePossibleStaleRecords(keys) {
1667
+ if (keys.length > 0 && typeof keys[0] === 'string') {
1668
+ return this.fallbackStringKeyInMemoryStore.expirePossibleStaleRecords(keys);
1669
+ }
1670
+ const expirationTimestamp = Date.now();
1671
+ for (let i = 0, len = keys.length; i < len; i++) {
1672
+ const key = keys[i];
1673
+ const metadata = this.readMetadata(key);
1674
+ if (metadata !== undefined) {
1675
+ this.publishMetadata(key, { ...metadata, expirationTimestamp });
1676
+ }
1677
+ }
1678
+ }
1670
1679
  setTTLOverride(namespace, representationName, ttl) {
1671
1680
  // Set the TTLs in both the stores
1672
1681
  this.fallbackStringKeyInMemoryStore.setTTLOverride(namespace, representationName, ttl);
@@ -2256,6 +2265,20 @@
2256
2265
  const value = this.data[propertyName];
2257
2266
  return typeof value !== 'object' || value === null;
2258
2267
  }
2268
+ isMissing(propertyName) {
2269
+ const value = this.data[propertyName];
2270
+ if (value && typeof value.__state === 'object' && value.__state !== null) {
2271
+ return !!value.__state.isMissing;
2272
+ }
2273
+ return false;
2274
+ }
2275
+ isPending(propertyName) {
2276
+ const value = this.data[propertyName];
2277
+ if (value && typeof value.__state === 'object' && value.__state !== null) {
2278
+ return !!value.__state.pending;
2279
+ }
2280
+ return false;
2281
+ }
2259
2282
  write(propertyName, value) {
2260
2283
  this.data[propertyName] = value;
2261
2284
  const canonicalKey = this.store.getCanonicalRecordId(this.storeKey);
@@ -3639,6 +3662,30 @@
3639
3662
  buildStructuredKey(namespace, representationName, idValues) {
3640
3663
  return this.store.buildStructuredKey(namespace, representationName, idValues);
3641
3664
  }
3665
+ /**
3666
+ * Take a list of keys and marks them as stale to be refreshed.
3667
+ * Then will be refreshed with the provided refresh function.
3668
+ * If no refresh and makeConfig functions are provided it will refresh
3669
+ * time that record is trying to be fetched
3670
+ *
3671
+ * Example: one record from graphql needs to be refreshed and not
3672
+ * the entire graphql query
3673
+ *
3674
+ * @param keys
3675
+ * @param makeConfig
3676
+ * @param refresh
3677
+ * @returns
3678
+ */
3679
+ expirePossibleStaleRecords(keys, config, refresh) {
3680
+ this.store.expirePossibleStaleRecords(keys);
3681
+ if (refresh !== undefined && config !== undefined) {
3682
+ return this.refreshPossibleStaleRecords(config, refresh);
3683
+ }
3684
+ return Promise.resolve();
3685
+ }
3686
+ refreshPossibleStaleRecords(config, refresh) {
3687
+ return Promise.resolve(refresh(config, { cachePolicy: { type: 'no-cache' } })).then(() => { });
3688
+ }
3642
3689
  }
3643
3690
 
3644
3691
  class Luvio {
@@ -3705,6 +3752,9 @@
3705
3752
  storeCleanup() {
3706
3753
  this.environment.storeCleanup();
3707
3754
  }
3755
+ storeExpirePossibleStaleRecords(keys, config, refresh) {
3756
+ return this.environment.expirePossibleStaleRecords(keys, config, refresh);
3757
+ }
3708
3758
  createSnapshot(selector, refresh) {
3709
3759
  return this.environment.createSnapshot(selector, refresh);
3710
3760
  }
@@ -4093,7 +4143,7 @@
4093
4143
  }
4094
4144
  return resourceParams;
4095
4145
  }
4096
- // engine version: 0.155.1-284dbf66
4146
+ // engine version: 0.156.3-04c1a80e
4097
4147
 
4098
4148
  /**
4099
4149
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -4221,7 +4271,7 @@
4221
4271
  }
4222
4272
  callbacks.push(callback);
4223
4273
  }
4224
- // version: 1.301.0-ecd340c2e1
4274
+ // version: 1.303.0-a698c7cc67
4225
4275
 
4226
4276
  // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
4227
4277
  function instrumentAdapter$1(createFunction, _metadata) {
@@ -15720,7 +15770,7 @@
15720
15770
  }
15721
15771
  return superResult;
15722
15772
  }
15723
- // version: 1.301.0-ecd340c2e1
15773
+ // version: 1.303.0-a698c7cc67
15724
15774
 
15725
15775
  function unwrap(data) {
15726
15776
  // The lwc-luvio bindings import a function from lwc called "unwrap".
@@ -16649,7 +16699,7 @@
16649
16699
  const { apiFamily, name } = metadata;
16650
16700
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16651
16701
  }
16652
- // version: 1.301.0-ecd340c2e1
16702
+ // version: 1.303.0-a698c7cc67
16653
16703
 
16654
16704
  /**
16655
16705
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -16748,7 +16798,7 @@
16748
16798
  TypeCheckShapes[TypeCheckShapes["Integer"] = 3] = "Integer";
16749
16799
  TypeCheckShapes[TypeCheckShapes["Unsupported"] = 4] = "Unsupported";
16750
16800
  })(TypeCheckShapes || (TypeCheckShapes = {}));
16751
- // engine version: 0.155.1-284dbf66
16801
+ // engine version: 0.156.3-04c1a80e
16752
16802
 
16753
16803
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16754
16804
 
@@ -18223,7 +18273,7 @@
18223
18273
  // be applied to a RecordRepresentation in environments configured with
18224
18274
  // drafts when the record has draft changes applied to it
18225
18275
  // TODO [W-8237087]: explore if this selection can only be added in environments where drafts are enabled
18226
- const DRAFTS_SELECTION = {
18276
+ const DRAFTS_SELECTION$1 = {
18227
18277
  kind: 'Object',
18228
18278
  opaque: true,
18229
18279
  name: 'drafts',
@@ -18237,7 +18287,7 @@
18237
18287
  childRelationships: CHILD_RELATIONSHIP_SELECTION,
18238
18288
  fields: createPathSelection('fields', fieldDefinition),
18239
18289
  });
18240
- return [...sel.selections, DRAFTS_SELECTION];
18290
+ return [...sel.selections, DRAFTS_SELECTION$1];
18241
18291
  }
18242
18292
  /**
18243
18293
  * Convert a list of fields and optional fields into RecordRepresentation its equivalent
@@ -18254,7 +18304,7 @@
18254
18304
  childRelationships: CHILD_RELATIONSHIP_SELECTION,
18255
18305
  fields: createPathSelectionFromValue(record.fields),
18256
18306
  });
18257
- return [...sel.selections, DRAFTS_SELECTION];
18307
+ return [...sel.selections, DRAFTS_SELECTION$1];
18258
18308
  }
18259
18309
 
18260
18310
  const MAX_RECORD_DEPTH = 5;
@@ -26509,6 +26559,12 @@
26509
26559
  function normalize$A(input, existing, path, luvio, store, timestamp) {
26510
26560
  return input;
26511
26561
  }
26562
+ const DRAFTS_SELECTION = {
26563
+ kind: 'Object',
26564
+ opaque: true,
26565
+ name: 'drafts',
26566
+ required: false,
26567
+ };
26512
26568
  const select$1A = function QuickActionExecutionRepresentationSelect() {
26513
26569
  return {
26514
26570
  kind: 'Fragment',
@@ -26540,7 +26596,7 @@
26540
26596
  {
26541
26597
  name: 'successMessage',
26542
26598
  kind: 'Scalar'
26543
- }
26599
+ }, DRAFTS_SELECTION,
26544
26600
  ]
26545
26601
  };
26546
26602
  };
@@ -44136,7 +44192,7 @@
44136
44192
  throttle(60, 60000, setupNotifyAllListRecordUpdateAvailable(luvio));
44137
44193
  throttle(60, 60000, setupNotifyAllListInfoSummaryUpdateAvailable(luvio));
44138
44194
  });
44139
- // version: 1.301.0-4216dc9d10
44195
+ // version: 1.303.0-b6ed223d95
44140
44196
 
44141
44197
  var ldsIdempotencyWriteDisabled = {
44142
44198
  isOpen: function (e) {
@@ -45820,6 +45876,32 @@
45820
45876
  }, revivingStore).finally(() => {
45821
45877
  });
45822
45878
  };
45879
+ const expirePossibleStaleRecords = async function (keys$1, config, refresh) {
45880
+ validateNotDisposed();
45881
+ const metadataKeys = keys$1.map(serializeStructuredKey);
45882
+ const now = Date.now();
45883
+ const entries = await durableStore.getMetadata(metadataKeys, DefaultDurableSegment);
45884
+ if (entries === undefined || keys$8(entries).length === 0) {
45885
+ return environment.expirePossibleStaleRecords(keys$1);
45886
+ }
45887
+ let metaDataChanged = false;
45888
+ const metadataEntries = metadataKeys.reduce((accu, key) => {
45889
+ const metadataEntry = entries[key];
45890
+ if (metadataEntry.metadata !== undefined) {
45891
+ const metadata = { ...metadataEntry.metadata, expirationTimestamp: now };
45892
+ accu[key] = { metadata };
45893
+ metaDataChanged = true;
45894
+ }
45895
+ return accu;
45896
+ }, {});
45897
+ if (metaDataChanged) {
45898
+ await durableStore.setMetadata(metadataEntries, DefaultDurableSegment);
45899
+ }
45900
+ if (config !== undefined && refresh !== undefined) {
45901
+ return environment.refreshPossibleStaleRecords(config, refresh);
45902
+ }
45903
+ return Promise.resolve();
45904
+ };
45823
45905
  // set the default cache policy of the base environment
45824
45906
  environment.setDefaultCachePolicy({
45825
45907
  type: 'stale-while-revalidate',
@@ -45852,6 +45934,7 @@
45852
45934
  handleErrorResponse: { value: handleErrorResponse },
45853
45935
  getNotifyChangeStoreEntries: { value: getNotifyChangeStoreEntries },
45854
45936
  notifyStoreUpdateAvailable: { value: notifyStoreUpdateAvailable },
45937
+ expirePossibleStaleRecords: { value: expirePossibleStaleRecords },
45855
45938
  });
45856
45939
  }
45857
45940
 
@@ -49898,7 +49981,7 @@
49898
49981
  if (status === DraftActionStatus.Error) {
49899
49982
  this.state = DraftQueueState.Error;
49900
49983
  this.processingAction = undefined;
49901
- this.notifyChangedListeners({
49984
+ await this.notifyChangedListeners({
49902
49985
  type: DraftQueueEventType.ActionFailed,
49903
49986
  action: action,
49904
49987
  });
@@ -49914,7 +49997,7 @@
49914
49997
  if (this.state === DraftQueueState.Waiting) {
49915
49998
  this.state = DraftQueueState.Started;
49916
49999
  }
49917
- this.notifyChangedListeners({
50000
+ await this.notifyChangedListeners({
49918
50001
  type: DraftQueueEventType.ActionUploading,
49919
50002
  action: { ...action, status: DraftActionStatus.Uploading },
49920
50003
  });
@@ -50021,17 +50104,21 @@
50021
50104
  });
50022
50105
  return action;
50023
50106
  }
50024
- scheduleRetryWithSpecifiedDelay(retryDelayInMs) {
50107
+ async scheduleRetryWithSpecifiedDelay(retryDelayInMs) {
50108
+ await this.notifyChangedListeners({
50109
+ type: DraftQueueEventType.QueueStateChanged,
50110
+ state: DraftQueueState.Waiting,
50111
+ });
50025
50112
  this.timeoutHandler = setTimeout(() => {
50026
50113
  if (this.state !== DraftQueueState.Stopped) {
50027
50114
  this.processNextAction();
50028
50115
  }
50029
50116
  }, retryDelayInMs);
50030
50117
  }
50031
- scheduleRetry() {
50118
+ async scheduleRetry() {
50032
50119
  const newInterval = this.retryIntervalMilliseconds * 2;
50033
50120
  this.retryIntervalMilliseconds = Math.min(Math.max(newInterval, this.minimumRetryInterval), this.maximumRetryInterval);
50034
- this.scheduleRetryWithSpecifiedDelay(this.retryIntervalMilliseconds);
50121
+ return this.scheduleRetryWithSpecifiedDelay(this.retryIntervalMilliseconds);
50035
50122
  }
50036
50123
  async getActionsForReplaceOrMerge(targetActionId, sourceActionId) {
50037
50124
  const actions = await this.getQueueActions();
@@ -50157,7 +50244,8 @@
50157
50244
  const actionArray = [];
50158
50245
  for (let i = 0, len = keys$1.length; i < len; i++) {
50159
50246
  const key = keys$1[i];
50160
- actionArray.push(draftStore[key]);
50247
+ // clone draft so we don't expose the internal draft store
50248
+ actionArray.push(clone$1(draftStore[key]));
50161
50249
  }
50162
50250
  return actionArray;
50163
50251
  });
@@ -50792,6 +50880,7 @@
50792
50880
  DraftQueueOperationType["ItemUpdated"] = "updated";
50793
50881
  DraftQueueOperationType["QueueStarted"] = "started";
50794
50882
  DraftQueueOperationType["QueueStopped"] = "stopped";
50883
+ DraftQueueOperationType["QueueWaiting"] = "waiting";
50795
50884
  })(DraftQueueOperationType || (DraftQueueOperationType = {}));
50796
50885
  /**
50797
50886
  * Converts the internal DraftAction's ResourceRequest into
@@ -50834,6 +50923,16 @@
50834
50923
  };
50835
50924
  }
50836
50925
  class DraftManager {
50926
+ shouldEmitEvent(event) {
50927
+ // Waiting events cannot be emitted prior to 252 native clients
50928
+ // TODO [W-16102411]: we can safely remove this backwards compatible code in 256
50929
+ if (isDraftQueueStateChangeEvent(event) &&
50930
+ event.state === DraftQueueState.Waiting &&
50931
+ this.listenerVersion === undefined) {
50932
+ return false;
50933
+ }
50934
+ return this.draftEventsShouldBeEmitted.includes(event.type);
50935
+ }
50837
50936
  constructor(draftQueue) {
50838
50937
  this.listeners = [];
50839
50938
  this.draftEventsShouldBeEmitted = [
@@ -50847,7 +50946,7 @@
50847
50946
  ];
50848
50947
  this.draftQueue = draftQueue;
50849
50948
  draftQueue.registerOnChangedListener((event) => {
50850
- if (this.draftEventsShouldBeEmitted.includes(event.type)) {
50949
+ if (this.shouldEmitEvent(event)) {
50851
50950
  return this.callListeners(event);
50852
50951
  }
50853
50952
  return Promise.resolve();
@@ -50877,6 +50976,8 @@
50877
50976
  return DraftQueueOperationType.QueueStarted;
50878
50977
  case DraftQueueState.Stopped:
50879
50978
  return DraftQueueOperationType.QueueStopped;
50979
+ case DraftQueueState.Waiting:
50980
+ return DraftQueueOperationType.QueueWaiting;
50880
50981
  default:
50881
50982
  throw Error('Unsupported event type');
50882
50983
  }
@@ -50934,7 +51035,8 @@
50934
51035
  *
50935
51036
  * @param listener The listener closure to subscribe to changes
50936
51037
  */
50937
- registerDraftQueueChangedListener(listener) {
51038
+ registerDraftQueueChangedListener(listener, version = undefined) {
51039
+ this.listenerVersion = version;
50938
51040
  this.listeners.push(listener);
50939
51041
  return () => {
50940
51042
  this.listeners = this.listeners.filter((l) => {
@@ -52759,6 +52861,7 @@
52759
52861
  isCreated: true,
52760
52862
  isSuccess: true,
52761
52863
  successMessage: `record created.`,
52864
+ drafts: { draftActionId: action.id },
52762
52865
  });
52763
52866
  }
52764
52867
  getDraftMetadata(_key) {
@@ -52876,6 +52979,7 @@
52876
52979
  isCreated: false,
52877
52980
  isSuccess: true,
52878
52981
  successMessage: `record updated.`,
52982
+ drafts: { draftActionId: action.id },
52879
52983
  });
52880
52984
  }
52881
52985
  async getDraftMetadata(key) {
@@ -62609,7 +62713,7 @@
62609
62713
  id: '@salesforce/lds-network-adapter',
62610
62714
  instrument: instrument$2,
62611
62715
  });
62612
- // version: 1.301.0-ecd340c2e1
62716
+ // version: 1.303.0-a698c7cc67
62613
62717
 
62614
62718
  const { create: create$3, keys: keys$3 } = Object;
62615
62719
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -82645,7 +82749,7 @@
82645
82749
  configuration: { ...configurationForGraphQLAdapters$1 },
82646
82750
  instrument: instrument$1,
82647
82751
  });
82648
- // version: 1.301.0-4216dc9d10
82752
+ // version: 1.303.0-b6ed223d95
82649
82753
 
82650
82754
  // On core the unstable adapters are re-exported with different names,
82651
82755
  // we want to match them here.
@@ -84901,7 +85005,7 @@
84901
85005
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
84902
85006
  graphQLImperative = ldsAdapter;
84903
85007
  });
84904
- // version: 1.301.0-4216dc9d10
85008
+ // version: 1.303.0-b6ed223d95
84905
85009
 
84906
85010
  var gqlApi = /*#__PURE__*/Object.freeze({
84907
85011
  __proto__: null,
@@ -85636,7 +85740,7 @@
85636
85740
  function register(r) {
85637
85741
  callbacks$1.forEach((callback) => callback(r));
85638
85742
  }
85639
- // version: 1.301.0-ecd340c2e1
85743
+ // version: 1.303.0-a698c7cc67
85640
85744
 
85641
85745
  /**
85642
85746
  * Returns true if the value acts like a Promise, i.e. has a "then" function,
@@ -90617,4 +90721,4 @@
90617
90721
  exports.subscribeToAdapter = subscribeToAdapter;
90618
90722
 
90619
90723
  }));
90620
- // version: 1.301.0-ecd340c2e1
90724
+ // version: 1.303.0-a698c7cc67
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-worker-api",
3
- "version": "1.301.0",
3
+ "version": "1.303.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "",
6
6
  "main": "dist/standalone/es/lds-worker-api.js",
@@ -35,15 +35,15 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@oat-sa/rollup-plugin-wildcard-external": "^1.0.0",
38
- "@salesforce/lds-adapters-graphql": "^1.301.0",
39
- "@salesforce/lds-adapters-uiapi": "^1.301.0",
40
- "@salesforce/lds-default-luvio": "^1.301.0",
41
- "@salesforce/lds-drafts": "^1.301.0",
42
- "@salesforce/lds-graphql-parser": "^1.301.0",
43
- "@salesforce/lds-luvio-engine": "^1.301.0",
44
- "@salesforce/lds-priming": "^1.301.0",
45
- "@salesforce/lds-runtime-mobile": "^1.301.0",
46
- "@salesforce/nimbus-plugin-lds": "^1.301.0",
38
+ "@salesforce/lds-adapters-graphql": "^1.303.0",
39
+ "@salesforce/lds-adapters-uiapi": "^1.303.0",
40
+ "@salesforce/lds-default-luvio": "^1.303.0",
41
+ "@salesforce/lds-drafts": "^1.303.0",
42
+ "@salesforce/lds-graphql-parser": "^1.303.0",
43
+ "@salesforce/lds-luvio-engine": "^1.303.0",
44
+ "@salesforce/lds-priming": "^1.303.0",
45
+ "@salesforce/lds-runtime-mobile": "^1.303.0",
46
+ "@salesforce/nimbus-plugin-lds": "^1.303.0",
47
47
  "ajv": "^8.11.0",
48
48
  "glob": "^7.1.5",
49
49
  "nimbus-types": "^2.0.0-alpha1",