@salesforce/lds-worker-api 1.145.0 → 1.146.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.
@@ -758,4 +758,4 @@ if (process.env.NODE_ENV !== 'production') {
758
758
  }
759
759
 
760
760
  export { createPrimingSession, draftManager, draftQueue, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
761
- // version: 1.145.0-a93c76713
761
+ // version: 1.146.0-6ca270a7a
@@ -657,7 +657,8 @@ class StringKeyInMemoryStore {
657
657
  if (key === canonicalKey) {
658
658
  throw new Error('cannot redirect a key to itself');
659
659
  }
660
- if (reverseRedirectKeys[canonicalKey] !== undefined) {
660
+ if (reverseRedirectKeys[canonicalKey] !== undefined &&
661
+ reverseRedirectKeys[canonicalKey] !== key) {
661
662
  throw new Error('cannot have multiple redirects keys point to the same canonical key');
662
663
  }
663
664
  if (redirectKeys[canonicalKey] !== undefined) {
@@ -3673,7 +3674,7 @@ class Luvio {
3673
3674
  return this.environment.buildStructuredKey(namespace, representationName, idValues);
3674
3675
  }
3675
3676
  }
3676
- // engine version: 0.142.4-be29f4f3
3677
+ // engine version: 0.143.0-384dfa26
3677
3678
 
3678
3679
  /**
3679
3680
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -3800,7 +3801,7 @@ function withDefaultLuvio(callback) {
3800
3801
  }
3801
3802
  callbacks.push(callback);
3802
3803
  }
3803
- // version: 1.145.0-a93c76713
3804
+ // version: 1.146.0-6ca270a7a
3804
3805
 
3805
3806
  // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
3806
3807
  function instrumentAdapter$1(createFunction, _metadata) {
@@ -15224,7 +15225,7 @@ function parseAndVisit(source) {
15224
15225
  updateReferenceMapWithKnownKey(ast, luvioDocumentNode);
15225
15226
  return luvioDocumentNode;
15226
15227
  }
15227
- // version: 1.145.0-a93c76713
15228
+ // version: 1.146.0-6ca270a7a
15228
15229
 
15229
15230
  function unwrap(data) {
15230
15231
  // The lwc-luvio bindings import a function from lwc called "unwrap".
@@ -16137,7 +16138,7 @@ function createGraphQLWireAdapterConstructor(luvio, adapter, metadata, astResolv
16137
16138
  const { apiFamily, name } = metadata;
16138
16139
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16139
16140
  }
16140
- // version: 1.145.0-a93c76713
16141
+ // version: 1.146.0-6ca270a7a
16141
16142
 
16142
16143
  /**
16143
16144
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -16220,7 +16221,7 @@ var FragmentReadResultState;
16220
16221
  ({
16221
16222
  state: FragmentReadResultState.Missing,
16222
16223
  });
16223
- // engine version: 0.142.4-be29f4f3
16224
+ // engine version: 0.143.0-384dfa26
16224
16225
 
16225
16226
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16226
16227
 
@@ -44007,7 +44008,7 @@ withDefaultLuvio((luvio) => {
44007
44008
  dropFunction: instrumentation$2.notifyRecordUpdateAvailableDropped,
44008
44009
  });
44009
44010
  });
44010
- // version: 1.145.0-5ff081cdd
44011
+ // version: 1.146.0-83a1d3266
44011
44012
 
44012
44013
  var caseSensitiveUserId = '005B0000000GR4OIAW';
44013
44014
 
@@ -44592,6 +44593,7 @@ function isDeprecatedDurableStoreEntry(durableRecord) {
44592
44593
  return false;
44593
44594
  }
44594
44595
  const DefaultDurableSegment = 'DEFAULT';
44596
+ const RedirectDurableSegment = 'REDIRECT_KEYS';
44595
44597
 
44596
44598
  const { keys: keys$6, create: create$5, assign: assign$4, freeze: freeze$1$1 } = Object;
44597
44599
 
@@ -44832,7 +44834,7 @@ class DurableTTLStore {
44832
44834
  }
44833
44835
  }
44834
44836
 
44835
- function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations = []) {
44837
+ function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, redirects, additionalDurableStoreOperations = []) {
44836
44838
  const durableRecords = create$5(null);
44837
44839
  const evictedRecords = create$5(null);
44838
44840
  const { records, metadata: storeMetadata, visitedIds, refreshedIds, } = store.fallbackStringKeyInMemoryStore;
@@ -44869,6 +44871,18 @@ function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStor
44869
44871
  segment: DefaultDurableSegment,
44870
44872
  });
44871
44873
  }
44874
+ // redirects
44875
+ redirects.forEach((value, key) => {
44876
+ durableStoreOperations.push({
44877
+ type: 'setEntries',
44878
+ entries: {
44879
+ [key]: {
44880
+ data: { key, redirect: value },
44881
+ },
44882
+ },
44883
+ segment: RedirectDurableSegment,
44884
+ });
44885
+ });
44872
44886
  // evicts
44873
44887
  const evictedKeys = keys$6(evictedRecords);
44874
44888
  if (evictedKeys.length > 0) {
@@ -44914,6 +44928,19 @@ function buildIngestStagingStore(environment) {
44914
44928
  return environment.storeBuildIngestionStagingStore();
44915
44929
  }
44916
44930
 
44931
+ async function reviveRedirects(durableStore, env) {
44932
+ const entries = await durableStore.getAllEntries(RedirectDurableSegment);
44933
+ if (entries) {
44934
+ for (const durableEntry of Object.keys(entries)) {
44935
+ const entry = entries[durableEntry];
44936
+ const { data: { key, redirect }, } = entry;
44937
+ if (entry) {
44938
+ env.storeRedirect(key, redirect);
44939
+ }
44940
+ }
44941
+ }
44942
+ }
44943
+
44917
44944
  const AdapterContextSegment = 'ADAPTER-CONTEXT';
44918
44945
  const ADAPTER_CONTEXT_ID_SUFFIX = '__NAMED_CONTEXT';
44919
44946
  async function reviveOrCreateContext(adapterId, durableStore, durableStoreErrorHandler, contextStores, pendingContextStoreKeys, onContextLoaded) {
@@ -44977,13 +45004,18 @@ function makeDurable(environment, { durableStore, instrumentation }) {
44977
45004
  // event. If this instance of makeDurable caused that L2 write we can ignore that
44978
45005
  // on change event. This Set helps us do that.
44979
45006
  const pendingContextStoreKeys = new Set();
45007
+ // redirects that need to be flushed to the durable store
45008
+ const pendingStoreRedirects = new Map();
44980
45009
  const contextStores = create$5(null);
44981
45010
  let initializationPromise = new Promise((resolve) => {
44982
45011
  const finish = () => {
44983
45012
  resolve();
44984
45013
  initializationPromise = undefined;
44985
45014
  };
44986
- reviveTTLOverrides(durableTTLStore, environment).then(finish);
45015
+ Promise.all([
45016
+ reviveTTLOverrides(durableTTLStore, environment),
45017
+ reviveRedirects(durableStore, environment),
45018
+ ]).then(finish);
44987
45019
  });
44988
45020
  //instrumentation for durable store errors
44989
45021
  const durableStoreErrorHandler = handleDurableStoreRejection(instrumentation);
@@ -44996,6 +45028,8 @@ function makeDurable(environment, { durableStore, instrumentation }) {
44996
45028
  const unsubscribe = durableStore.registerOnChangedListener(async (changes) => {
44997
45029
  const defaultSegmentKeys = [];
44998
45030
  const adapterContextSegmentKeys = [];
45031
+ const redirectSegmentKeys = [];
45032
+ let shouldBroadcast = false;
44999
45033
  for (let i = 0, len = changes.length; i < len; i++) {
45000
45034
  const change = changes[i];
45001
45035
  // we only care about changes to the data which is stored in the default
@@ -45006,6 +45040,20 @@ function makeDurable(environment, { durableStore, instrumentation }) {
45006
45040
  else if (change.segment === AdapterContextSegment) {
45007
45041
  adapterContextSegmentKeys.push(...change.ids);
45008
45042
  }
45043
+ else if (change.segment === RedirectDurableSegment) {
45044
+ redirectSegmentKeys.push(...change.ids);
45045
+ }
45046
+ }
45047
+ if (redirectSegmentKeys.length > 0) {
45048
+ const redirectEntries = await durableStore.getEntries(redirectSegmentKeys, RedirectDurableSegment);
45049
+ if (redirectEntries !== undefined) {
45050
+ const redirectKeys = Object.keys(redirectEntries);
45051
+ for (const key of redirectKeys) {
45052
+ const redirectData = redirectEntries[key];
45053
+ environment.storeRedirect(redirectData.data.key, redirectData.data.redirect);
45054
+ shouldBroadcast = true;
45055
+ }
45056
+ }
45009
45057
  }
45010
45058
  // process adapter context changes
45011
45059
  const adapterContextKeysFromDifferentInstance = [];
@@ -45042,10 +45090,6 @@ function makeDurable(environment, { durableStore, instrumentation }) {
45042
45090
  if (defaultSegmentKeysLength > 0) {
45043
45091
  for (let i = 0; i < defaultSegmentKeysLength; i++) {
45044
45092
  const key = defaultSegmentKeys[i];
45045
- const canonical = environment.storeGetCanonicalKey(key);
45046
- if (canonical !== key) {
45047
- continue;
45048
- }
45049
45093
  // TODO: W-8909393 If expiration is the only thing that changed we should not evict the data... so
45050
45094
  // if we stored expiration and data at different keys (or same keys in different segments)
45051
45095
  // then we could know if only the expiration has changed and we wouldn't need to evict
@@ -45053,6 +45097,9 @@ function makeDurable(environment, { durableStore, instrumentation }) {
45053
45097
  // call base environment storeEvict so this evict is not tracked for durable deletion
45054
45098
  environment.storeEvict(key);
45055
45099
  }
45100
+ shouldBroadcast = true;
45101
+ }
45102
+ if (shouldBroadcast) {
45056
45103
  await environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
45057
45104
  }
45058
45105
  });
@@ -45108,7 +45155,8 @@ function makeDurable(environment, { durableStore, instrumentation }) {
45108
45155
  if (ingestStagingStore === null) {
45109
45156
  return Promise.resolve();
45110
45157
  }
45111
- const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations);
45158
+ const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler, new Map(pendingStoreRedirects), additionalDurableStoreOperations);
45159
+ pendingStoreRedirects.clear();
45112
45160
  ingestStagingStore = null;
45113
45161
  return promise;
45114
45162
  };
@@ -45190,6 +45238,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
45190
45238
  };
45191
45239
  const storeRedirect = function (existingKey, canonicalKey) {
45192
45240
  validateNotDisposed();
45241
+ pendingStoreRedirects.set(existingKey, canonicalKey);
45193
45242
  // call redirect on staging store so "old" keys are removed from L2 on
45194
45243
  // the next publishChangesToDurableStore. NOTE: we don't need to call
45195
45244
  // redirect on the base environment store because staging store and base
@@ -48901,7 +48950,6 @@ function buildLuvioOverrideForDraftAdapters(luvio, handler, extractTargetIdFromC
48901
48950
  }
48902
48951
 
48903
48952
  const DraftIdMappingKeyPrefix240 = 'DraftIdMapping::';
48904
- const DraftKeyMappingKeyPrefix = 'DraftKeyMapping::V2::';
48905
48953
  const DRAFT_ID_MAPPINGS_SEGMENT = 'DRAFT_ID_MAPPINGS';
48906
48954
  function isLegacyDraftIdMapping(key, data) {
48907
48955
  return key.startsWith(DraftIdMappingKeyPrefix240);
@@ -48911,9 +48959,6 @@ function isLegacyDraftIdMapping(key, data) {
48911
48959
  function getRecordKeyForId$1(id) {
48912
48960
  return `UiApi::RecordRepresentation:${id}`;
48913
48961
  }
48914
- function generateDraftIdMappingKey(draftIdMapping) {
48915
- return `${DraftKeyMappingKeyPrefix}${draftIdMapping.draftKey}::${draftIdMapping.canonicalKey}`;
48916
- }
48917
48962
  /**
48918
48963
  *
48919
48964
  * @param mappingIds (optional) requested mapping ids, if undefined all will be retrieved
@@ -48947,6 +48992,15 @@ async function getDraftIdMappings(durableStore, mappingIds) {
48947
48992
  }
48948
48993
  return mappings;
48949
48994
  }
48995
+ async function clearDraftIdSegment(durableStore) {
48996
+ const entries = await durableStore.getAllEntries(DRAFT_ID_MAPPINGS_SEGMENT);
48997
+ if (entries) {
48998
+ const keys$1 = keys$4(entries);
48999
+ if (keys$1.length > 0) {
49000
+ await durableStore.evictEntries(keys$1, DRAFT_ID_MAPPINGS_SEGMENT);
49001
+ }
49002
+ }
49003
+ }
48950
49004
 
48951
49005
  /**
48952
49006
  * Generates a time-ordered, unique id to associate with a DraftAction. Ensures
@@ -49037,9 +49091,6 @@ function customActionHandler(executor, id, draftQueue) {
49037
49091
  });
49038
49092
  return queueOperations;
49039
49093
  };
49040
- const getRedirectMappings = (_action) => {
49041
- return undefined;
49042
- };
49043
49094
  return {
49044
49095
  handlerId: id,
49045
49096
  enqueue: (data) => {
@@ -49051,7 +49102,6 @@ function customActionHandler(executor, id, draftQueue) {
49051
49102
  handleReplaceAction: () => {
49052
49103
  throw Error('replaceAction not supported for custom actions');
49053
49104
  },
49054
- getRedirectMappings,
49055
49105
  handleActionRemoved: () => Promise.resolve(),
49056
49106
  handleActionCompleted: () => Promise.resolve(),
49057
49107
  handleActionEnqueued: () => Promise.resolve(),
@@ -49226,17 +49276,11 @@ class DurableDraftQueue {
49226
49276
  const handler = this.getHandler(action.handler);
49227
49277
  let queue = await this.getQueueActions();
49228
49278
  const queueOperations = handler.getQueueOperationsForCompletingDrafts(queue, action);
49229
- const idAndKeyMappings = handler.getRedirectMappings(action);
49230
- const keyMappings = idAndKeyMappings === undefined
49231
- ? undefined
49232
- : idAndKeyMappings.map((m) => {
49233
- return { draftKey: m.draftKey, canonicalKey: m.canonicalKey };
49234
- });
49235
- await this.draftStore.completeAction(queueOperations, keyMappings);
49236
- queue = await this.getQueueActions();
49279
+ // write the queue operations to the store prior to ingesting the result
49280
+ await this.draftStore.completeAction(queueOperations);
49281
+ await handler.handleActionCompleted(action, queueOperations, values$1(this.handlers));
49237
49282
  this.retryIntervalMilliseconds = 0;
49238
49283
  this.uploadingActionId = undefined;
49239
- await handler.handleActionCompleted(action, queueOperations, queue, values$1(this.handlers));
49240
49284
  await this.notifyChangedListeners({
49241
49285
  type: DraftQueueEventType.ActionCompleted,
49242
49286
  action,
@@ -49559,7 +49603,7 @@ class DurableDraftStore {
49559
49603
  };
49560
49604
  return this.enqueueAction(deleteAction);
49561
49605
  }
49562
- completeAction(queueOperations, mappings) {
49606
+ completeAction(queueOperations) {
49563
49607
  const action = () => {
49564
49608
  const durableStoreOperations = [];
49565
49609
  const { draftStore } = this;
@@ -49592,18 +49636,6 @@ class DurableDraftStore {
49592
49636
  });
49593
49637
  }
49594
49638
  }
49595
- if (mappings !== undefined) {
49596
- const entries = {};
49597
- for (const mapping of mappings) {
49598
- const mappingKey = generateDraftIdMappingKey(mapping);
49599
- entries[mappingKey] = { data: mapping };
49600
- }
49601
- durableStoreOperations.push({
49602
- entries,
49603
- type: 'setEntries',
49604
- segment: DRAFT_ID_MAPPINGS_SEGMENT,
49605
- });
49606
- }
49607
49639
  return this.durableStore.batchOperations(durableStoreOperations);
49608
49640
  };
49609
49641
  return this.enqueueAction(action);
@@ -49868,7 +49900,7 @@ class AbstractResourceRequestActionHandler {
49868
49900
  },
49869
49901
  ];
49870
49902
  }
49871
- async handleActionCompleted(action, queueOperations, _queue, allHandlers) {
49903
+ async handleActionCompleted(action, queueOperations, allHandlers) {
49872
49904
  const { data: request, tag } = action;
49873
49905
  const { method } = request;
49874
49906
  if (method === 'delete') {
@@ -49982,11 +50014,18 @@ class AbstractResourceRequestActionHandler {
49982
50014
  async ingestResponses(responses, action) {
49983
50015
  const luvio = this.getLuvio();
49984
50016
  await luvio.handleSuccessResponse(() => {
50017
+ if (action.status === DraftActionStatus.Completed) {
50018
+ const mappings = this.getRedirectMappings(action);
50019
+ if (mappings) {
50020
+ mappings.forEach((mapping) => {
50021
+ luvio.storeRedirect(mapping.draftKey, mapping.canonicalKey);
50022
+ });
50023
+ }
50024
+ }
49985
50025
  for (const entry of responses) {
49986
50026
  const { response, synchronousIngest } = entry;
49987
50027
  synchronousIngest(response, action);
49988
50028
  }
49989
- // must call base broadcast
49990
50029
  return luvio.storeBroadcast();
49991
50030
  },
49992
50031
  // getTypeCacheKeysRecord uses the response, not the full path factory
@@ -50315,6 +50354,8 @@ class DraftManager {
50315
50354
 
50316
50355
  function makeEnvironmentDraftAware(luvio, env, durableStore, handlers, draftQueue) {
50317
50356
  const draftMetadata = {};
50357
+ // in 246 luvio took charge of persisting redirect mappings, this needs to stick around
50358
+ // for a couple of releases to support older environments
50318
50359
  // setup existing store redirects when bootstrapping the environment
50319
50360
  (async () => {
50320
50361
  const mappings = await getDraftIdMappings(durableStore);
@@ -50322,23 +50363,9 @@ function makeEnvironmentDraftAware(luvio, env, durableStore, handlers, draftQueu
50322
50363
  const { draftKey, canonicalKey } = mapping;
50323
50364
  env.storeRedirect(draftKey, canonicalKey);
50324
50365
  });
50366
+ await env.storeBroadcast(env.rebuildSnapshot, env.snapshotAvailable);
50367
+ await clearDraftIdSegment(durableStore);
50325
50368
  })();
50326
- durableStore.registerOnChangedListener(async (changes) => {
50327
- const draftIdMappingsIds = [];
50328
- for (let i = 0, len = changes.length; i < len; i++) {
50329
- const change = changes[i];
50330
- if (change.segment === DRAFT_ID_MAPPINGS_SEGMENT) {
50331
- draftIdMappingsIds.push(...change.ids);
50332
- }
50333
- }
50334
- if (draftIdMappingsIds.length > 0) {
50335
- const mappings = await getDraftIdMappings(durableStore, draftIdMappingsIds);
50336
- mappings.forEach((mapping) => {
50337
- const { draftKey, canonicalKey } = mapping;
50338
- env.storeRedirect(draftKey, canonicalKey);
50339
- });
50340
- }
50341
- });
50342
50369
  const handleSuccessResponse = async function (ingestAndBroadcastFunc, getResponseCacheKeysFunc) {
50343
50370
  const queue = await draftQueue.getQueueActions();
50344
50371
  if (queue.length === 0) {
@@ -58948,7 +58975,7 @@ class NimbusSqliteStore {
58948
58975
  registerOnChangedListener(listener) {
58949
58976
  let unsubscribeId = undefined;
58950
58977
  this.plugin
58951
- .registerOnChangedListener((changes) => {
58978
+ .registerOnChangedListener(async (changes) => {
58952
58979
  const durableChanges = changes.map((c) => {
58953
58980
  return {
58954
58981
  type: c.type === 'upsert' ? 'setEntries' : 'evictEntries',
@@ -58957,7 +58984,7 @@ class NimbusSqliteStore {
58957
58984
  segment: c.context.segment,
58958
58985
  };
58959
58986
  });
58960
- listener(durableChanges);
58987
+ await listener(durableChanges);
58961
58988
  })
58962
58989
  .then((unsub) => {
58963
58990
  unsubscribeId = unsub;
@@ -59894,7 +59921,7 @@ register({
59894
59921
  id: '@salesforce/lds-network-adapter',
59895
59922
  instrument: instrument$1,
59896
59923
  });
59897
- // version: 1.145.0-a93c76713
59924
+ // version: 1.146.0-6ca270a7a
59898
59925
 
59899
59926
  const { create: create$2, keys: keys$2 } = Object;
59900
59927
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -80739,7 +80766,7 @@ register({
80739
80766
  configuration: { ...configurationForGraphQLAdapters },
80740
80767
  instrument,
80741
80768
  });
80742
- // version: 1.145.0-5ff081cdd
80769
+ // version: 1.146.0-83a1d3266
80743
80770
 
80744
80771
  // On core the unstable adapters are re-exported with different names,
80745
80772
 
@@ -82977,7 +83004,7 @@ withDefaultLuvio((luvio) => {
82977
83004
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
82978
83005
  graphQLImperative = ldsAdapter;
82979
83006
  });
82980
- // version: 1.145.0-5ff081cdd
83007
+ // version: 1.146.0-83a1d3266
82981
83008
 
82982
83009
  var gqlApi = /*#__PURE__*/Object.freeze({
82983
83010
  __proto__: null,
@@ -83666,4 +83693,4 @@ const { luvio } = getRuntime();
83666
83693
  setDefaultLuvio({ luvio });
83667
83694
 
83668
83695
  export { createPrimingSession, draftManager, draftQueue, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, registerReportObserver, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
83669
- // version: 1.145.0-a93c76713
83696
+ // version: 1.146.0-6ca270a7a
@@ -665,7 +665,8 @@
665
665
  if (key === canonicalKey) {
666
666
  throw new Error('cannot redirect a key to itself');
667
667
  }
668
- if (reverseRedirectKeys[canonicalKey] !== undefined) {
668
+ if (reverseRedirectKeys[canonicalKey] !== undefined &&
669
+ reverseRedirectKeys[canonicalKey] !== key) {
669
670
  throw new Error('cannot have multiple redirects keys point to the same canonical key');
670
671
  }
671
672
  if (redirectKeys[canonicalKey] !== undefined) {
@@ -3681,7 +3682,7 @@
3681
3682
  return this.environment.buildStructuredKey(namespace, representationName, idValues);
3682
3683
  }
3683
3684
  }
3684
- // engine version: 0.142.4-be29f4f3
3685
+ // engine version: 0.143.0-384dfa26
3685
3686
 
3686
3687
  /**
3687
3688
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -3808,7 +3809,7 @@
3808
3809
  }
3809
3810
  callbacks.push(callback);
3810
3811
  }
3811
- // version: 1.145.0-a93c76713
3812
+ // version: 1.146.0-6ca270a7a
3812
3813
 
3813
3814
  // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
3814
3815
  function instrumentAdapter$1(createFunction, _metadata) {
@@ -15232,7 +15233,7 @@
15232
15233
  updateReferenceMapWithKnownKey(ast, luvioDocumentNode);
15233
15234
  return luvioDocumentNode;
15234
15235
  }
15235
- // version: 1.145.0-a93c76713
15236
+ // version: 1.146.0-6ca270a7a
15236
15237
 
15237
15238
  function unwrap(data) {
15238
15239
  // The lwc-luvio bindings import a function from lwc called "unwrap".
@@ -16145,7 +16146,7 @@
16145
16146
  const { apiFamily, name } = metadata;
16146
16147
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16147
16148
  }
16148
- // version: 1.145.0-a93c76713
16149
+ // version: 1.146.0-6ca270a7a
16149
16150
 
16150
16151
  /**
16151
16152
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -16228,7 +16229,7 @@
16228
16229
  ({
16229
16230
  state: FragmentReadResultState.Missing,
16230
16231
  });
16231
- // engine version: 0.142.4-be29f4f3
16232
+ // engine version: 0.143.0-384dfa26
16232
16233
 
16233
16234
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16234
16235
 
@@ -44015,7 +44016,7 @@
44015
44016
  dropFunction: instrumentation$2.notifyRecordUpdateAvailableDropped,
44016
44017
  });
44017
44018
  });
44018
- // version: 1.145.0-5ff081cdd
44019
+ // version: 1.146.0-83a1d3266
44019
44020
 
44020
44021
  var caseSensitiveUserId = '005B0000000GR4OIAW';
44021
44022
 
@@ -44600,6 +44601,7 @@
44600
44601
  return false;
44601
44602
  }
44602
44603
  const DefaultDurableSegment = 'DEFAULT';
44604
+ const RedirectDurableSegment = 'REDIRECT_KEYS';
44603
44605
 
44604
44606
  const { keys: keys$6, create: create$5, assign: assign$4, freeze: freeze$1$1 } = Object;
44605
44607
 
@@ -44840,7 +44842,7 @@
44840
44842
  }
44841
44843
  }
44842
44844
 
44843
- function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations = []) {
44845
+ function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, redirects, additionalDurableStoreOperations = []) {
44844
44846
  const durableRecords = create$5(null);
44845
44847
  const evictedRecords = create$5(null);
44846
44848
  const { records, metadata: storeMetadata, visitedIds, refreshedIds, } = store.fallbackStringKeyInMemoryStore;
@@ -44877,6 +44879,18 @@
44877
44879
  segment: DefaultDurableSegment,
44878
44880
  });
44879
44881
  }
44882
+ // redirects
44883
+ redirects.forEach((value, key) => {
44884
+ durableStoreOperations.push({
44885
+ type: 'setEntries',
44886
+ entries: {
44887
+ [key]: {
44888
+ data: { key, redirect: value },
44889
+ },
44890
+ },
44891
+ segment: RedirectDurableSegment,
44892
+ });
44893
+ });
44880
44894
  // evicts
44881
44895
  const evictedKeys = keys$6(evictedRecords);
44882
44896
  if (evictedKeys.length > 0) {
@@ -44922,6 +44936,19 @@
44922
44936
  return environment.storeBuildIngestionStagingStore();
44923
44937
  }
44924
44938
 
44939
+ async function reviveRedirects(durableStore, env) {
44940
+ const entries = await durableStore.getAllEntries(RedirectDurableSegment);
44941
+ if (entries) {
44942
+ for (const durableEntry of Object.keys(entries)) {
44943
+ const entry = entries[durableEntry];
44944
+ const { data: { key, redirect }, } = entry;
44945
+ if (entry) {
44946
+ env.storeRedirect(key, redirect);
44947
+ }
44948
+ }
44949
+ }
44950
+ }
44951
+
44925
44952
  const AdapterContextSegment = 'ADAPTER-CONTEXT';
44926
44953
  const ADAPTER_CONTEXT_ID_SUFFIX = '__NAMED_CONTEXT';
44927
44954
  async function reviveOrCreateContext(adapterId, durableStore, durableStoreErrorHandler, contextStores, pendingContextStoreKeys, onContextLoaded) {
@@ -44985,13 +45012,18 @@
44985
45012
  // event. If this instance of makeDurable caused that L2 write we can ignore that
44986
45013
  // on change event. This Set helps us do that.
44987
45014
  const pendingContextStoreKeys = new Set();
45015
+ // redirects that need to be flushed to the durable store
45016
+ const pendingStoreRedirects = new Map();
44988
45017
  const contextStores = create$5(null);
44989
45018
  let initializationPromise = new Promise((resolve) => {
44990
45019
  const finish = () => {
44991
45020
  resolve();
44992
45021
  initializationPromise = undefined;
44993
45022
  };
44994
- reviveTTLOverrides(durableTTLStore, environment).then(finish);
45023
+ Promise.all([
45024
+ reviveTTLOverrides(durableTTLStore, environment),
45025
+ reviveRedirects(durableStore, environment),
45026
+ ]).then(finish);
44995
45027
  });
44996
45028
  //instrumentation for durable store errors
44997
45029
  const durableStoreErrorHandler = handleDurableStoreRejection(instrumentation);
@@ -45004,6 +45036,8 @@
45004
45036
  const unsubscribe = durableStore.registerOnChangedListener(async (changes) => {
45005
45037
  const defaultSegmentKeys = [];
45006
45038
  const adapterContextSegmentKeys = [];
45039
+ const redirectSegmentKeys = [];
45040
+ let shouldBroadcast = false;
45007
45041
  for (let i = 0, len = changes.length; i < len; i++) {
45008
45042
  const change = changes[i];
45009
45043
  // we only care about changes to the data which is stored in the default
@@ -45014,6 +45048,20 @@
45014
45048
  else if (change.segment === AdapterContextSegment) {
45015
45049
  adapterContextSegmentKeys.push(...change.ids);
45016
45050
  }
45051
+ else if (change.segment === RedirectDurableSegment) {
45052
+ redirectSegmentKeys.push(...change.ids);
45053
+ }
45054
+ }
45055
+ if (redirectSegmentKeys.length > 0) {
45056
+ const redirectEntries = await durableStore.getEntries(redirectSegmentKeys, RedirectDurableSegment);
45057
+ if (redirectEntries !== undefined) {
45058
+ const redirectKeys = Object.keys(redirectEntries);
45059
+ for (const key of redirectKeys) {
45060
+ const redirectData = redirectEntries[key];
45061
+ environment.storeRedirect(redirectData.data.key, redirectData.data.redirect);
45062
+ shouldBroadcast = true;
45063
+ }
45064
+ }
45017
45065
  }
45018
45066
  // process adapter context changes
45019
45067
  const adapterContextKeysFromDifferentInstance = [];
@@ -45050,10 +45098,6 @@
45050
45098
  if (defaultSegmentKeysLength > 0) {
45051
45099
  for (let i = 0; i < defaultSegmentKeysLength; i++) {
45052
45100
  const key = defaultSegmentKeys[i];
45053
- const canonical = environment.storeGetCanonicalKey(key);
45054
- if (canonical !== key) {
45055
- continue;
45056
- }
45057
45101
  // TODO: W-8909393 If expiration is the only thing that changed we should not evict the data... so
45058
45102
  // if we stored expiration and data at different keys (or same keys in different segments)
45059
45103
  // then we could know if only the expiration has changed and we wouldn't need to evict
@@ -45061,6 +45105,9 @@
45061
45105
  // call base environment storeEvict so this evict is not tracked for durable deletion
45062
45106
  environment.storeEvict(key);
45063
45107
  }
45108
+ shouldBroadcast = true;
45109
+ }
45110
+ if (shouldBroadcast) {
45064
45111
  await environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
45065
45112
  }
45066
45113
  });
@@ -45116,7 +45163,8 @@
45116
45163
  if (ingestStagingStore === null) {
45117
45164
  return Promise.resolve();
45118
45165
  }
45119
- const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations);
45166
+ const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler, new Map(pendingStoreRedirects), additionalDurableStoreOperations);
45167
+ pendingStoreRedirects.clear();
45120
45168
  ingestStagingStore = null;
45121
45169
  return promise;
45122
45170
  };
@@ -45198,6 +45246,7 @@
45198
45246
  };
45199
45247
  const storeRedirect = function (existingKey, canonicalKey) {
45200
45248
  validateNotDisposed();
45249
+ pendingStoreRedirects.set(existingKey, canonicalKey);
45201
45250
  // call redirect on staging store so "old" keys are removed from L2 on
45202
45251
  // the next publishChangesToDurableStore. NOTE: we don't need to call
45203
45252
  // redirect on the base environment store because staging store and base
@@ -48909,7 +48958,6 @@
48909
48958
  }
48910
48959
 
48911
48960
  const DraftIdMappingKeyPrefix240 = 'DraftIdMapping::';
48912
- const DraftKeyMappingKeyPrefix = 'DraftKeyMapping::V2::';
48913
48961
  const DRAFT_ID_MAPPINGS_SEGMENT = 'DRAFT_ID_MAPPINGS';
48914
48962
  function isLegacyDraftIdMapping(key, data) {
48915
48963
  return key.startsWith(DraftIdMappingKeyPrefix240);
@@ -48919,9 +48967,6 @@
48919
48967
  function getRecordKeyForId$1(id) {
48920
48968
  return `UiApi::RecordRepresentation:${id}`;
48921
48969
  }
48922
- function generateDraftIdMappingKey(draftIdMapping) {
48923
- return `${DraftKeyMappingKeyPrefix}${draftIdMapping.draftKey}::${draftIdMapping.canonicalKey}`;
48924
- }
48925
48970
  /**
48926
48971
  *
48927
48972
  * @param mappingIds (optional) requested mapping ids, if undefined all will be retrieved
@@ -48955,6 +49000,15 @@
48955
49000
  }
48956
49001
  return mappings;
48957
49002
  }
49003
+ async function clearDraftIdSegment(durableStore) {
49004
+ const entries = await durableStore.getAllEntries(DRAFT_ID_MAPPINGS_SEGMENT);
49005
+ if (entries) {
49006
+ const keys$1 = keys$4(entries);
49007
+ if (keys$1.length > 0) {
49008
+ await durableStore.evictEntries(keys$1, DRAFT_ID_MAPPINGS_SEGMENT);
49009
+ }
49010
+ }
49011
+ }
48958
49012
 
48959
49013
  /**
48960
49014
  * Generates a time-ordered, unique id to associate with a DraftAction. Ensures
@@ -49045,9 +49099,6 @@
49045
49099
  });
49046
49100
  return queueOperations;
49047
49101
  };
49048
- const getRedirectMappings = (_action) => {
49049
- return undefined;
49050
- };
49051
49102
  return {
49052
49103
  handlerId: id,
49053
49104
  enqueue: (data) => {
@@ -49059,7 +49110,6 @@
49059
49110
  handleReplaceAction: () => {
49060
49111
  throw Error('replaceAction not supported for custom actions');
49061
49112
  },
49062
- getRedirectMappings,
49063
49113
  handleActionRemoved: () => Promise.resolve(),
49064
49114
  handleActionCompleted: () => Promise.resolve(),
49065
49115
  handleActionEnqueued: () => Promise.resolve(),
@@ -49234,17 +49284,11 @@
49234
49284
  const handler = this.getHandler(action.handler);
49235
49285
  let queue = await this.getQueueActions();
49236
49286
  const queueOperations = handler.getQueueOperationsForCompletingDrafts(queue, action);
49237
- const idAndKeyMappings = handler.getRedirectMappings(action);
49238
- const keyMappings = idAndKeyMappings === undefined
49239
- ? undefined
49240
- : idAndKeyMappings.map((m) => {
49241
- return { draftKey: m.draftKey, canonicalKey: m.canonicalKey };
49242
- });
49243
- await this.draftStore.completeAction(queueOperations, keyMappings);
49244
- queue = await this.getQueueActions();
49287
+ // write the queue operations to the store prior to ingesting the result
49288
+ await this.draftStore.completeAction(queueOperations);
49289
+ await handler.handleActionCompleted(action, queueOperations, values$1(this.handlers));
49245
49290
  this.retryIntervalMilliseconds = 0;
49246
49291
  this.uploadingActionId = undefined;
49247
- await handler.handleActionCompleted(action, queueOperations, queue, values$1(this.handlers));
49248
49292
  await this.notifyChangedListeners({
49249
49293
  type: DraftQueueEventType.ActionCompleted,
49250
49294
  action,
@@ -49567,7 +49611,7 @@
49567
49611
  };
49568
49612
  return this.enqueueAction(deleteAction);
49569
49613
  }
49570
- completeAction(queueOperations, mappings) {
49614
+ completeAction(queueOperations) {
49571
49615
  const action = () => {
49572
49616
  const durableStoreOperations = [];
49573
49617
  const { draftStore } = this;
@@ -49600,18 +49644,6 @@
49600
49644
  });
49601
49645
  }
49602
49646
  }
49603
- if (mappings !== undefined) {
49604
- const entries = {};
49605
- for (const mapping of mappings) {
49606
- const mappingKey = generateDraftIdMappingKey(mapping);
49607
- entries[mappingKey] = { data: mapping };
49608
- }
49609
- durableStoreOperations.push({
49610
- entries,
49611
- type: 'setEntries',
49612
- segment: DRAFT_ID_MAPPINGS_SEGMENT,
49613
- });
49614
- }
49615
49647
  return this.durableStore.batchOperations(durableStoreOperations);
49616
49648
  };
49617
49649
  return this.enqueueAction(action);
@@ -49876,7 +49908,7 @@
49876
49908
  },
49877
49909
  ];
49878
49910
  }
49879
- async handleActionCompleted(action, queueOperations, _queue, allHandlers) {
49911
+ async handleActionCompleted(action, queueOperations, allHandlers) {
49880
49912
  const { data: request, tag } = action;
49881
49913
  const { method } = request;
49882
49914
  if (method === 'delete') {
@@ -49990,11 +50022,18 @@
49990
50022
  async ingestResponses(responses, action) {
49991
50023
  const luvio = this.getLuvio();
49992
50024
  await luvio.handleSuccessResponse(() => {
50025
+ if (action.status === DraftActionStatus.Completed) {
50026
+ const mappings = this.getRedirectMappings(action);
50027
+ if (mappings) {
50028
+ mappings.forEach((mapping) => {
50029
+ luvio.storeRedirect(mapping.draftKey, mapping.canonicalKey);
50030
+ });
50031
+ }
50032
+ }
49993
50033
  for (const entry of responses) {
49994
50034
  const { response, synchronousIngest } = entry;
49995
50035
  synchronousIngest(response, action);
49996
50036
  }
49997
- // must call base broadcast
49998
50037
  return luvio.storeBroadcast();
49999
50038
  },
50000
50039
  // getTypeCacheKeysRecord uses the response, not the full path factory
@@ -50323,6 +50362,8 @@
50323
50362
 
50324
50363
  function makeEnvironmentDraftAware(luvio, env, durableStore, handlers, draftQueue) {
50325
50364
  const draftMetadata = {};
50365
+ // in 246 luvio took charge of persisting redirect mappings, this needs to stick around
50366
+ // for a couple of releases to support older environments
50326
50367
  // setup existing store redirects when bootstrapping the environment
50327
50368
  (async () => {
50328
50369
  const mappings = await getDraftIdMappings(durableStore);
@@ -50330,23 +50371,9 @@
50330
50371
  const { draftKey, canonicalKey } = mapping;
50331
50372
  env.storeRedirect(draftKey, canonicalKey);
50332
50373
  });
50374
+ await env.storeBroadcast(env.rebuildSnapshot, env.snapshotAvailable);
50375
+ await clearDraftIdSegment(durableStore);
50333
50376
  })();
50334
- durableStore.registerOnChangedListener(async (changes) => {
50335
- const draftIdMappingsIds = [];
50336
- for (let i = 0, len = changes.length; i < len; i++) {
50337
- const change = changes[i];
50338
- if (change.segment === DRAFT_ID_MAPPINGS_SEGMENT) {
50339
- draftIdMappingsIds.push(...change.ids);
50340
- }
50341
- }
50342
- if (draftIdMappingsIds.length > 0) {
50343
- const mappings = await getDraftIdMappings(durableStore, draftIdMappingsIds);
50344
- mappings.forEach((mapping) => {
50345
- const { draftKey, canonicalKey } = mapping;
50346
- env.storeRedirect(draftKey, canonicalKey);
50347
- });
50348
- }
50349
- });
50350
50377
  const handleSuccessResponse = async function (ingestAndBroadcastFunc, getResponseCacheKeysFunc) {
50351
50378
  const queue = await draftQueue.getQueueActions();
50352
50379
  if (queue.length === 0) {
@@ -58956,7 +58983,7 @@
58956
58983
  registerOnChangedListener(listener) {
58957
58984
  let unsubscribeId = undefined;
58958
58985
  this.plugin
58959
- .registerOnChangedListener((changes) => {
58986
+ .registerOnChangedListener(async (changes) => {
58960
58987
  const durableChanges = changes.map((c) => {
58961
58988
  return {
58962
58989
  type: c.type === 'upsert' ? 'setEntries' : 'evictEntries',
@@ -58965,7 +58992,7 @@
58965
58992
  segment: c.context.segment,
58966
58993
  };
58967
58994
  });
58968
- listener(durableChanges);
58995
+ await listener(durableChanges);
58969
58996
  })
58970
58997
  .then((unsub) => {
58971
58998
  unsubscribeId = unsub;
@@ -59902,7 +59929,7 @@
59902
59929
  id: '@salesforce/lds-network-adapter',
59903
59930
  instrument: instrument$1,
59904
59931
  });
59905
- // version: 1.145.0-a93c76713
59932
+ // version: 1.146.0-6ca270a7a
59906
59933
 
59907
59934
  const { create: create$2, keys: keys$2 } = Object;
59908
59935
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -80747,7 +80774,7 @@
80747
80774
  configuration: { ...configurationForGraphQLAdapters },
80748
80775
  instrument,
80749
80776
  });
80750
- // version: 1.145.0-5ff081cdd
80777
+ // version: 1.146.0-83a1d3266
80751
80778
 
80752
80779
  // On core the unstable adapters are re-exported with different names,
80753
80780
 
@@ -82985,7 +83012,7 @@
82985
83012
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
82986
83013
  graphQLImperative = ldsAdapter;
82987
83014
  });
82988
- // version: 1.145.0-5ff081cdd
83015
+ // version: 1.146.0-83a1d3266
82989
83016
 
82990
83017
  var gqlApi = /*#__PURE__*/Object.freeze({
82991
83018
  __proto__: null,
@@ -83691,4 +83718,4 @@
83691
83718
  Object.defineProperty(exports, '__esModule', { value: true });
83692
83719
 
83693
83720
  }));
83694
- // version: 1.145.0-a93c76713
83721
+ // version: 1.146.0-6ca270a7a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-worker-api",
3
- "version": "1.145.0",
3
+ "version": "1.146.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "",
6
6
  "main": "dist/standalone/es/lds-worker-api.js",