@salesforce/lds-worker-api 1.142.0 → 1.143.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.142.0-7730e2a14
761
+ // version: 1.143.0-a6d2a998d
@@ -2988,18 +2988,22 @@ class Reader {
2988
2988
  }
2989
2989
 
2990
2990
  /**
2991
- * Maps a CachePolicy to a CachePolicyImplementation
2991
+ * Maps a CachePolicy to a CachePolicyImplementation. We don't necessarily trust
2992
+ * "cachePolicy" because that could come from userland code. But we do trust
2993
+ * "defaultCachePolicy" because that comes from our own library code and should
2994
+ * be a valid type, so this function will fall back to "defaultCachePolicy" if
2995
+ * "cachePolicy" is invalid.
2992
2996
  *
2993
2997
  * @param cachePolicy cache policy
2994
2998
  * @param defaultCachePolicy default cache policy
2995
- * @param luvio the luvio instance
2996
- * @returns cache policy implementation corresponnding to cachePolicy
2999
+ * @returns cache policy implementation corresponding to cachePolicy
2997
3000
  */
2998
3001
  function resolveCachePolicy(cachePolicy, defaultCachePolicy) {
2999
3002
  if (cachePolicy === undefined) {
3000
- return defaultCachePolicy;
3003
+ return resolveCachePolicy(defaultCachePolicy, defaultCachePolicy);
3001
3004
  }
3002
- switch (cachePolicy.type) {
3005
+ const { type } = cachePolicy;
3006
+ switch (type) {
3003
3007
  case 'cache-and-network':
3004
3008
  return buildCacheAndNetworkImplementation(cachePolicy.staleDurationSeconds);
3005
3009
  case 'cache-then-network':
@@ -3015,7 +3019,7 @@ function resolveCachePolicy(cachePolicy, defaultCachePolicy) {
3015
3019
  return buildValidAtImplementation(basePolicy, cachePolicy.timestamp);
3016
3020
  }
3017
3021
  default: {
3018
- return defaultCachePolicy;
3022
+ return resolveCachePolicy(defaultCachePolicy, defaultCachePolicy);
3019
3023
  }
3020
3024
  }
3021
3025
  }
@@ -3042,10 +3046,7 @@ class Environment {
3042
3046
  constructor(store, networkAdapter) {
3043
3047
  this.networkCount = 0;
3044
3048
  this.storeQueryEvaluator = undefined;
3045
- this.defaultCachePolicy = {
3046
- type: 'cache-then-network',
3047
- implementation: cacheThenNetworkImplementation,
3048
- };
3049
+ this.defaultCachePolicy = { type: 'cache-then-network' };
3049
3050
  this.store = store;
3050
3051
  this.networkAdapter = networkAdapter;
3051
3052
  this.adapterContextMap = create$a(null);
@@ -3055,6 +3056,9 @@ class Environment {
3055
3056
  this.createSnapshot = this.createSnapshot.bind(this);
3056
3057
  this.rebuildSnapshot = this.rebuildSnapshot.bind(this);
3057
3058
  }
3059
+ setDefaultCachePolicy(cachePolicy) {
3060
+ this.defaultCachePolicy = cachePolicy;
3061
+ }
3058
3062
  /**
3059
3063
  * Returns a resolved promise of a FetchResponse for ok http status codes.
3060
3064
  * Returns a rejected promise of an ErrorResponse of type "fetchResponse" for non-ok http status codes.
@@ -3319,17 +3323,14 @@ class Environment {
3319
3323
  applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot) {
3320
3324
  const { defaultCachePolicy } = this;
3321
3325
  const { cachePolicy, eventObservers } = adapterRequestContext;
3322
- let cachePolicyType = defaultCachePolicy.type;
3323
- if (cachePolicy !== undefined) {
3324
- cachePolicyType = cachePolicy.type;
3325
- }
3326
- let cachePolicyImpl = resolveCachePolicy(cachePolicy, defaultCachePolicy.implementation);
3326
+ let cachePolicyImpl = resolveCachePolicy(cachePolicy, defaultCachePolicy);
3327
3327
  const resolvePendingSnapshot = (snapshot) => this.resolvePendingSnapshot(snapshot);
3328
3328
  const storeLookup = (sel, refresh, ttlStrategy) => this.storeLookup(sel, this.createSnapshot, refresh, ttlStrategy);
3329
3329
  let wrappedBuildCacheSnapshot = buildCachedSnapshot;
3330
3330
  let wrappedBuildNetworkSnapshot = buildNetworkSnapshot;
3331
3331
  // if eventObservers are provided for the adapter, wrap calls in versions that emit events
3332
3332
  if (eventObservers !== undefined) {
3333
+ const cachePolicyType = cachePolicy === undefined ? defaultCachePolicy.type : cachePolicy.type;
3333
3334
  cachePolicyImpl = cachePolicyImplWithEvents(cachePolicyImpl, cachePolicyType, eventObservers);
3334
3335
  wrappedBuildCacheSnapshot = buildCachedSnapshotWithEvents(buildCachedSnapshot, eventObservers);
3335
3336
  wrappedBuildNetworkSnapshot = buildNetworkSnapshotWithEvents(buildNetworkSnapshot, eventObservers);
@@ -3672,7 +3673,7 @@ class Luvio {
3672
3673
  return this.environment.buildStructuredKey(namespace, representationName, idValues);
3673
3674
  }
3674
3675
  }
3675
- // engine version: 0.140.3-86f83ec8
3676
+ // engine version: 0.142.4-be29f4f3
3676
3677
 
3677
3678
  /**
3678
3679
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -3799,7 +3800,7 @@ function withDefaultLuvio(callback) {
3799
3800
  }
3800
3801
  callbacks.push(callback);
3801
3802
  }
3802
- // version: 1.142.0-7730e2a14
3803
+ // version: 1.143.0-a6d2a998d
3803
3804
 
3804
3805
  // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
3805
3806
  function instrumentAdapter$1(createFunction, _metadata) {
@@ -15223,7 +15224,7 @@ function parseAndVisit(source) {
15223
15224
  updateReferenceMapWithKnownKey(ast, luvioDocumentNode);
15224
15225
  return luvioDocumentNode;
15225
15226
  }
15226
- // version: 1.142.0-7730e2a14
15227
+ // version: 1.143.0-a6d2a998d
15227
15228
 
15228
15229
  function unwrap(data) {
15229
15230
  // The lwc-luvio bindings import a function from lwc called "unwrap".
@@ -16136,7 +16137,7 @@ function createGraphQLWireAdapterConstructor(luvio, adapter, metadata, astResolv
16136
16137
  const { apiFamily, name } = metadata;
16137
16138
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16138
16139
  }
16139
- // version: 1.142.0-7730e2a14
16140
+ // version: 1.143.0-a6d2a998d
16140
16141
 
16141
16142
  /**
16142
16143
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -16219,7 +16220,7 @@ var FragmentReadResultState;
16219
16220
  ({
16220
16221
  state: FragmentReadResultState.Missing,
16221
16222
  });
16222
- // engine version: 0.140.3-86f83ec8
16223
+ // engine version: 0.142.4-be29f4f3
16223
16224
 
16224
16225
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16225
16226
 
@@ -16567,7 +16568,7 @@ function getFetchResponseStatusText$1(status) {
16567
16568
  return `Unexpected HTTP Status Code: ${status}`;
16568
16569
  }
16569
16570
  }
16570
- function isUnfulfilledSnapshot$1(snapshot) {
16571
+ function isUnfulfilledSnapshot$1$1(snapshot) {
16571
16572
  return snapshot.state === SNAPSHOT_STATE_UNFULFILLED;
16572
16573
  }
16573
16574
  const keyPrefix$1 = 'UiApi';
@@ -22809,7 +22810,7 @@ function buildCachedSnapshotCachePolicy$I(context, storeLookup) {
22809
22810
  config,
22810
22811
  resolve: () => buildNetworkSnapshot$U(luvio, config, snapshotRefreshOptions$1)
22811
22812
  });
22812
- if (isUnfulfilledSnapshot$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
22813
+ if (isUnfulfilledSnapshot$1$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
22813
22814
  context.cacheSnapshot = cacheSnapshot;
22814
22815
  }
22815
22816
  return cacheSnapshot;
@@ -38255,7 +38256,7 @@ function buildCachedSnapshotCachePolicy$9(context, storeLookup) {
38255
38256
  config,
38256
38257
  resolve: () => buildNetworkSnapshot$h(luvio, config, snapshotRefreshOptions$1)
38257
38258
  });
38258
- if (isUnfulfilledSnapshot$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
38259
+ if (isUnfulfilledSnapshot$1$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
38259
38260
  context.cacheSnapshot = cacheSnapshot;
38260
38261
  }
38261
38262
  return cacheSnapshot;
@@ -40397,7 +40398,7 @@ function buildCachedSnapshotCachePolicy$3(context, storeLookup) {
40397
40398
  config,
40398
40399
  resolve: () => buildNetworkSnapshot$9(luvio, config, snapshotRefreshOptions$1)
40399
40400
  });
40400
- if (isUnfulfilledSnapshot$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
40401
+ if (isUnfulfilledSnapshot$1$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
40401
40402
  context.cacheSnapshot = cacheSnapshot;
40402
40403
  }
40403
40404
  return cacheSnapshot;
@@ -44006,7 +44007,7 @@ withDefaultLuvio((luvio) => {
44006
44007
  dropFunction: instrumentation$2.notifyRecordUpdateAvailableDropped,
44007
44008
  });
44008
44009
  });
44009
- // version: 1.142.0-9f43a65a3
44010
+ // version: 1.143.0-7a79bacc1
44010
44011
 
44011
44012
  var caseSensitiveUserId = '005B0000000GR4OIAW';
44012
44013
 
@@ -44081,6 +44082,33 @@ function formattingOptions(pattern) {
44081
44082
  return pattern;
44082
44083
  }
44083
44084
 
44085
+ var eagerEvalValidAt = {
44086
+ isOpen: function (e) {
44087
+ return e.fallback;
44088
+ },
44089
+ hasError: function () {
44090
+ return !0;
44091
+ },
44092
+ };
44093
+
44094
+ var eagerEvalStaleWhileRevalidate = {
44095
+ isOpen: function (e) {
44096
+ return e.fallback;
44097
+ },
44098
+ hasError: function () {
44099
+ return !0;
44100
+ },
44101
+ };
44102
+
44103
+ var eagerEvalDefaultCachePolicy = {
44104
+ isOpen: function (e) {
44105
+ return e.fallback;
44106
+ },
44107
+ hasError: function () {
44108
+ return !0;
44109
+ },
44110
+ };
44111
+
44084
44112
  /**
44085
44113
  * Copyright (c) 2022, Salesforce, Inc.,
44086
44114
  * All rights reserved.
@@ -44804,7 +44832,7 @@ class DurableTTLStore {
44804
44832
  }
44805
44833
  }
44806
44834
 
44807
- function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler) {
44835
+ function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations = []) {
44808
44836
  const durableRecords = create$5(null);
44809
44837
  const evictedRecords = create$5(null);
44810
44838
  const { records, metadata: storeMetadata, visitedIds, refreshedIds, } = store.fallbackStringKeyInMemoryStore;
@@ -44831,7 +44859,7 @@ function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStor
44831
44859
  };
44832
44860
  }
44833
44861
  }
44834
- const durableStoreOperations = [];
44862
+ const durableStoreOperations = additionalDurableStoreOperations;
44835
44863
  // publishes
44836
44864
  const recordKeys = keys$6(durableRecords);
44837
44865
  if (recordKeys.length > 0) {
@@ -44923,7 +44951,7 @@ async function reviveOrCreateContext(adapterId, durableStore, durableStoreErrorH
44923
44951
  }
44924
44952
  return contextReturn();
44925
44953
  }
44926
- function isUnfulfilledSnapshot(cachedSnapshotResult) {
44954
+ function isUnfulfilledSnapshot$1(cachedSnapshotResult) {
44927
44955
  if (cachedSnapshotResult === undefined) {
44928
44956
  return false;
44929
44957
  }
@@ -44934,7 +44962,8 @@ function isUnfulfilledSnapshot(cachedSnapshotResult) {
44934
44962
  }
44935
44963
  /**
44936
44964
  * Configures the environment to persist data into a durable store and attempt to resolve
44937
- * data from the persistent store before hitting the network.
44965
+ * data from the persistent store before hitting the network. Sets the default
44966
+ * cache policy to stale-while-revalidate with infinite staleDuration.
44938
44967
  *
44939
44968
  * @param environment The base environment
44940
44969
  * @param durableStore A DurableStore implementation
@@ -45074,12 +45103,12 @@ function makeDurable(environment, { durableStore, instrumentation }) {
45074
45103
  // call the base storeBroadcast
45075
45104
  return publishChangesToDurableStore();
45076
45105
  };
45077
- const publishChangesToDurableStore = function () {
45106
+ const publishChangesToDurableStore = function (additionalDurableStoreOperations) {
45078
45107
  validateNotDisposed();
45079
45108
  if (ingestStagingStore === null) {
45080
45109
  return Promise.resolve();
45081
45110
  }
45082
- const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler);
45111
+ const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations);
45083
45112
  ingestStagingStore = null;
45084
45113
  return promise;
45085
45114
  };
@@ -45206,7 +45235,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
45206
45235
  const snapshot = buildCachedSnapshot(injectedBuildSnapshotContext, injectedStoreLookup, luvio);
45207
45236
  // if the adapter attempted to do an L1 lookup and it was unfulfilled
45208
45237
  // then we can attempt an L2 lookup
45209
- if (isUnfulfilledSnapshot(snapshot)) {
45238
+ if (isUnfulfilledSnapshot$1(snapshot)) {
45210
45239
  const start = Date.now();
45211
45240
  emitDurableEnvironmentAdapterEvent({ type: 'l2-revive-start' }, adapterRequestContext.eventObservers);
45212
45241
  const revivedSnapshot = reviveSnapshot(environment, durableStore, snapshot, durableStoreErrorHandler, () => injectedStoreLookup(snapshot.select, snapshot.refresh)).then((result) => {
@@ -45359,10 +45388,11 @@ function makeDurable(environment, { durableStore, instrumentation }) {
45359
45388
  return entries;
45360
45389
  });
45361
45390
  };
45362
- environment.defaultCachePolicy = {
45391
+ // set the default cache policy of the base environment
45392
+ environment.setDefaultCachePolicy({
45363
45393
  type: 'stale-while-revalidate',
45364
- implementation: buildStaleWhileRevalidateImplementation(Number.MAX_SAFE_INTEGER),
45365
- };
45394
+ staleDurationSeconds: Number.MAX_SAFE_INTEGER,
45395
+ });
45366
45396
  return create$5(environment, {
45367
45397
  publishStoreMetadata: { value: publishStoreMetadata },
45368
45398
  storeIngest: { value: storeIngest },
@@ -56563,6 +56593,7 @@ function draftAwareGraphQLAdapterFactory(userId, objectInfoService, store, luvio
56563
56593
  query: injectedAST,
56564
56594
  },
56565
56595
  luvio,
56596
+ gqlEval: true,
56566
56597
  }, buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy));
56567
56598
  if (isErrorSnapshotThatShouldGetReturnedToCaller(nonEvaluatedSnapshot)) {
56568
56599
  return nonEvaluatedSnapshot;
@@ -59021,8 +59052,17 @@ function formatDisplayValue(value, datatype) {
59021
59052
  }
59022
59053
  }
59023
59054
 
59024
- //TODO: [W-12734162] - rebuild non-evaluated snapshot when graph rebuild is triggered. The dependency work on luvio needs to be done.
59055
+ function isUnfulfilledSnapshot(cachedSnapshotResult) {
59056
+ if (cachedSnapshotResult === undefined) {
59057
+ return false;
59058
+ }
59059
+ if ('then' in cachedSnapshotResult) {
59060
+ return false;
59061
+ }
59062
+ return cachedSnapshotResult.state === 'Unfulfilled';
59063
+ }
59025
59064
  function makeEnvironmentGraphqlAware(environment) {
59065
+ //TODO: [W-12734162] - rebuild non-evaluated snapshot when graph rebuild is triggered. The dependency work on luvio needs to be done.
59026
59066
  const rebuildSnapshot = function (snapshot, onRebuild) {
59027
59067
  if (isStoreEvalSnapshot(snapshot)) {
59028
59068
  snapshot.rebuildWithStoreEval(snapshot).then((rebuilt) => {
@@ -59038,8 +59078,64 @@ function makeEnvironmentGraphqlAware(environment) {
59038
59078
  }
59039
59079
  return environment.rebuildSnapshot(snapshot, onRebuild);
59040
59080
  };
59081
+ const applyCachePolicy = function (luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot) {
59082
+ // Early exit for non-evaluating adapters
59083
+ let graphqlBuildSnapshotContext = buildSnapshotContext;
59084
+ if (graphqlBuildSnapshotContext.gqlEval !== true) {
59085
+ return environment.applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot);
59086
+ }
59087
+ var localBuildCachedSnapshot = buildCachedSnapshot;
59088
+ const hoistUnfulfilledToStale = (context, storeLookup, luvio) => {
59089
+ const upstream = buildCachedSnapshot(context, storeLookup, luvio);
59090
+ if (upstream === undefined)
59091
+ return upstream;
59092
+ if (isUnfulfilledSnapshot(upstream)) {
59093
+ return {
59094
+ ...upstream,
59095
+ data: upstream.data || {},
59096
+ state: 'Stale',
59097
+ };
59098
+ }
59099
+ else if ('then' in upstream) {
59100
+ return upstream.then((snapshot) => {
59101
+ if (snapshot === undefined)
59102
+ return snapshot;
59103
+ if (isUnfulfilledSnapshot(snapshot)) {
59104
+ return {
59105
+ ...snapshot,
59106
+ data: snapshot.data || {},
59107
+ state: 'Stale',
59108
+ };
59109
+ }
59110
+ return snapshot;
59111
+ });
59112
+ }
59113
+ return upstream;
59114
+ };
59115
+ const { cachePolicy } = adapterRequestContext;
59116
+ if (eagerEvalValidAt.isOpen({ fallback: false }) &&
59117
+ cachePolicy &&
59118
+ cachePolicy.type === 'valid-at' &&
59119
+ cachePolicy.timestamp === 0 &&
59120
+ cachePolicy.basePolicy &&
59121
+ cachePolicy.basePolicy.type === 'stale-while-revalidate') {
59122
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
59123
+ }
59124
+ if (eagerEvalStaleWhileRevalidate.isOpen({ fallback: false }) &&
59125
+ cachePolicy &&
59126
+ cachePolicy.type === 'stale-while-revalidate' &&
59127
+ cachePolicy.staleDurationSeconds === Number.MAX_SAFE_INTEGER) {
59128
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
59129
+ }
59130
+ if (eagerEvalDefaultCachePolicy.isOpen({ fallback: false }) && cachePolicy === undefined) {
59131
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
59132
+ }
59133
+ return environment.applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, localBuildCachedSnapshot, buildNetworkSnapshot);
59134
+ };
59041
59135
  return create$6(environment, {
59042
59136
  rebuildSnapshot: { value: rebuildSnapshot },
59137
+ applyCachePolicy: { value: applyCachePolicy },
59138
+ setDefaultCachePolicy: { value: environment.setDefaultCachePolicy.bind(environment) },
59043
59139
  });
59044
59140
  }
59045
59141
 
@@ -59787,7 +59883,7 @@ register({
59787
59883
  id: '@salesforce/lds-network-adapter',
59788
59884
  instrument: instrument$1,
59789
59885
  });
59790
- // version: 1.142.0-7730e2a14
59886
+ // version: 1.143.0-a6d2a998d
59791
59887
 
59792
59888
  const { create: create$2, keys: keys$2 } = Object;
59793
59889
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -59901,6 +59997,20 @@ function buildQueryTypeStringKey(args) {
59901
59997
  return `${keyPrefix}::${schemaName}::${queryTypeName}[${serializeOperationNode$1(operationNode, variables, fragmentMap)}]`;
59902
59998
  }
59903
59999
 
60000
+ /**
60001
+ * @description Spec compliant way to retrieve the correct Operation from the Document that Luvio should operate on. https://spec.graphql.org/June2018/#sec-Named-Operation-Definitions
60002
+ * @param document
60003
+ * @param operationName
60004
+ * @returns The Operation in the GraphQL document we should use for the current call.
60005
+ */
60006
+ function getOperationFromDocument(document, operationName) {
60007
+ const operations = document.definitions.filter((def) => def.kind === 'OperationDefinition');
60008
+ if (operationName) {
60009
+ return operations.find((def) => def.name !== undefined && def.name.value === operationName);
60010
+ }
60011
+ return operations[0]; // If a named operation is not provided, we return the first one
60012
+ }
60013
+
59904
60014
  /**
59905
60015
  * Copyright (c) 2022, Salesforce, Inc.,
59906
60016
  * All rights reserved.
@@ -79312,43 +79422,38 @@ function getInContextFragmentType(fragment, fragmentMap) {
79312
79422
  const TTL = 900000;
79313
79423
  const VERSION$6 = "b440235e7e724631f92002fe50e3e096";
79314
79424
  const RepresentationType = 'GraphQLRepresentation';
79315
- function select$8(luvio, query, variables) {
79316
- const definitions = query.definitions === undefined ? [] : query.definitions;
79425
+ function select$8(luvio, document, variables, operationName) {
79426
+ const operationToExecute = getOperationFromDocument(document, operationName);
79317
79427
  return {
79318
79428
  kind: 'Fragment',
79319
79429
  synthetic: true,
79320
79430
  reader: true,
79321
79431
  read: (builder) => {
79322
79432
  builder.enterPath('data');
79323
- let sink = {};
79324
- const fragments = createFragmentMap(query);
79325
- for (let i = 0, len = definitions.length; i < len; i += 1) {
79326
- const def = definitions[i];
79327
- if (def.kind === 'OperationDefinition') {
79328
- const queryTypeRecordId = keyBuilder$4(luvio, def, variables, fragments);
79329
- const snapshot = builder.read({
79330
- recordId: queryTypeRecordId,
79331
- node: {
79332
- kind: 'Fragment',
79333
- private: [],
79334
- opaque: true,
79335
- version: VERSION$7
79336
- },
79337
- variables: {}
79338
- });
79339
- if (snapshot.data === undefined) {
79340
- builder.markMissingLink(queryTypeRecordId);
79341
- break;
79342
- }
79343
- const data = select$9(def, variables, fragments)(snapshot.data, builder, queryTypeRecordId);
79344
- sink = {
79345
- ...sink,
79346
- ...data,
79347
- };
79348
- }
79349
- }
79350
79433
  const gqlData = {};
79351
- builder.assignNonScalar(gqlData, 'data', sink);
79434
+ if (operationToExecute === undefined) {
79435
+ builder.markMissing(); // Never give a cache hit for an undefined operation
79436
+ return gqlData;
79437
+ }
79438
+ const fragments = createFragmentMap(document);
79439
+ const queryTypeRecordId = keyBuilder$4(luvio, operationToExecute, variables, fragments);
79440
+ const snapshot = builder.read({
79441
+ recordId: queryTypeRecordId,
79442
+ node: {
79443
+ kind: 'Fragment',
79444
+ private: [],
79445
+ opaque: true,
79446
+ version: VERSION$7
79447
+ },
79448
+ variables: {}
79449
+ });
79450
+ if (snapshot.data === undefined) {
79451
+ builder.markMissingLink(queryTypeRecordId);
79452
+ }
79453
+ else {
79454
+ const data = select$9(operationToExecute, variables, fragments)(snapshot.data, builder, queryTypeRecordId);
79455
+ builder.assignNonScalar(gqlData, 'data', data);
79456
+ }
79352
79457
  builder.exitPath();
79353
79458
  return gqlData;
79354
79459
  }
@@ -79368,10 +79473,10 @@ function ingestOperationNode(luvio, input, node, state) {
79368
79473
  });
79369
79474
  }
79370
79475
  }
79371
- const ingest = function GraphQLRepresentationIngest(query, variables) {
79476
+ const ingest = function GraphQLRepresentationIngest(document, variables, operationName) {
79372
79477
  return (input, path, luvio, store, timestamp) => {
79373
79478
  if (input.data) {
79374
- const fragments = createFragmentMap(query);
79479
+ const fragments = createFragmentMap(document);
79375
79480
  const state = {
79376
79481
  data: input.data,
79377
79482
  luvio,
@@ -79381,58 +79486,63 @@ const ingest = function GraphQLRepresentationIngest(query, variables) {
79381
79486
  variables,
79382
79487
  fragments,
79383
79488
  };
79384
- query.definitions.forEach((node) => {
79385
- if (node.kind === 'OperationDefinition') {
79386
- ingestOperationNode(luvio, input, node, state);
79387
- }
79388
- });
79489
+ const operationToExecute = getOperationFromDocument(document, operationName);
79490
+ if (operationToExecute !== undefined) {
79491
+ ingestOperationNode(luvio, input, operationToExecute, state);
79492
+ }
79389
79493
  }
79390
79494
  return {
79391
79495
  __ref: undefined
79392
79496
  };
79393
79497
  };
79394
79498
  };
79395
- function getTypeCacheKeys(luvio, query, variables, data) {
79499
+ function getTypeCacheKeys(luvio, document, variables, data, operationName) {
79396
79500
  const sink = new StoreKeyMap();
79397
79501
  if (data.data) {
79398
- const fragments = createFragmentMap(query);
79399
- query.definitions.forEach((node) => {
79400
- if (node.kind === 'OperationDefinition') {
79401
- const state = {
79402
- luvio,
79403
- variables,
79404
- fragments,
79405
- data: data.data,
79406
- path: {
79407
- parent: null,
79408
- propertyName: null,
79409
- fullPath: '' // TODO: W-13079691 - Need to take another pass at what we want to do for structured keys
79410
- }
79411
- };
79412
- sink.merge(getTypeCacheKeys$1(node, state));
79413
- }
79414
- });
79502
+ const fragments = createFragmentMap(document);
79503
+ const operationToExecute = getOperationFromDocument(document, operationName);
79504
+ if (operationToExecute !== undefined) {
79505
+ const state = {
79506
+ luvio,
79507
+ variables,
79508
+ fragments,
79509
+ data: data.data,
79510
+ path: {
79511
+ parent: null,
79512
+ propertyName: null,
79513
+ fullPath: '' // TODO: W-13079691 - Need to take another pass at what we want to do for structured keys
79514
+ }
79515
+ };
79516
+ sink.merge(getTypeCacheKeys$1(operationToExecute, state));
79517
+ }
79415
79518
  }
79416
79519
  return sink;
79417
79520
  }
79418
79521
 
79419
79522
  function select$7(luvio, config) {
79420
- const { query, variables } = config;
79421
- return select$8(luvio, query, variables);
79523
+ const { query, variables, operationName } = config;
79524
+ return select$8(luvio, query, variables, operationName);
79422
79525
  }
79423
79526
  function keyBuilder$3(luvio, params) {
79424
- return keyPrefix + '::' + 'GraphQLRepresentation';
79527
+ const { query, operationName, variables } = params.body;
79528
+ const operationToExecute = getOperationFromDocument(query, operationName);
79529
+ if (operationToExecute !== undefined) {
79530
+ const fragments = createFragmentMap(query);
79531
+ return keyBuilder$4(luvio, operationToExecute, variables || {}, fragments);
79532
+ }
79533
+ return `adapters_adapter$45$utils_keyPrefix::GraphQLRepresentation::InvalidOperation`;
79425
79534
  }
79426
79535
  function getResponseCacheKeys$1(luvio, resourceParams, response) {
79427
79536
  const query = resourceParams.body.query;
79428
79537
  const variables = resourceParams.body.variables || {};
79429
- return getTypeCacheKeys(luvio, query, variables, response);
79538
+ const operationName = resourceParams.body.operationName;
79539
+ return getTypeCacheKeys(luvio, query, variables, response, operationName);
79430
79540
  }
79431
79541
  function ingestSuccess$1(luvio, config, resourceParams, response, snapshotRefresh) {
79432
79542
  const { body } = response;
79433
- const key = keyBuilder$3();
79434
- const { query, variables } = resourceParams.body;
79435
- luvio.storeIngest(key, ingest(query, variables), body);
79543
+ const key = keyBuilder$3(luvio, resourceParams);
79544
+ const { query, variables, operationName } = resourceParams.body;
79545
+ luvio.storeIngest(key, ingest(query, variables, operationName), body);
79436
79546
  // revert the optimized pagination variables back to its original so that subsequent store lookup will include all records, not just the ones loaded by an optimized query
79437
79547
  // see optimizePagination for initial update to optimize the query
79438
79548
  revertPaginationOptimization(variables);
@@ -79444,7 +79554,7 @@ function ingestSuccess$1(luvio, config, resourceParams, response, snapshotRefres
79444
79554
  return snapshot;
79445
79555
  }
79446
79556
  function ingestError$1(luvio, config, params, error, snapshotRefresh) {
79447
- const key = keyBuilder$3();
79557
+ const key = keyBuilder$3(luvio, params);
79448
79558
  const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
79449
79559
  const storeMetadataParams = {
79450
79560
  ttl: TTL,
@@ -79527,8 +79637,8 @@ function createResourceParams$1(config) {
79527
79637
  return resourceParams;
79528
79638
  }
79529
79639
  function keyBuilder$2(luvio, config) {
79530
- createResourceParams$1(config);
79531
- return keyBuilder$3();
79640
+ const resourceParams = createResourceParams$1(config);
79641
+ return keyBuilder$3(luvio, resourceParams);
79532
79642
  }
79533
79643
  function typeCheckConfig$1(untrustedConfig) {
79534
79644
  const config = {};
@@ -79876,7 +79986,7 @@ function selectChildResourceParams(luvio, childResources, resourceParams) {
79876
79986
  reader.enterPath(i);
79877
79987
  reader.enterPath(envelopeBodyPath);
79878
79988
  const childResource = childResources[i];
79879
- const childKey = keyBuilder$3();
79989
+ const childKey = keyBuilder$3(luvio, childResource);
79880
79990
  const childFragment = select$7(luvio, childResource.body); // MUST read from the ORIGINAL config not injected
79881
79991
  const isMissingDataBeforeChildRead = reader.getIsDataMissing();
79882
79992
  const childSnapshot = reader.read({
@@ -79987,7 +80097,7 @@ function getResponseCacheKeys$2(luvio, resourceParams, response) {
79987
80097
  ObjectAssign(keys, childKeys);
79988
80098
  }
79989
80099
  else if (childStatusCode === 404) {
79990
- const childKey = keyBuilder$3();
80100
+ const childKey = keyBuilder$3(luvio, childResourceParams);
79991
80101
  keys.set(childKey, {
79992
80102
  namespace: keyPrefix,
79993
80103
  representationName: RepresentationType,
@@ -80005,7 +80115,7 @@ function ingestSuccessChildResourceParams(luvio, childConfigs, childResourcePara
80005
80115
  // There's an assumption here that the config and resource params aren't reordered.
80006
80116
  const childConfig = childConfigs[index];
80007
80117
  const childResourceParams = childResourceParamsArray[index];
80008
- const childKey = keyBuilder$3();
80118
+ const childKey = keyBuilder$3(luvio, childResourceParams);
80009
80119
  const result = childEnvelopes[index];
80010
80120
  const { statusCode: childStatusCode, result: childBody } = result;
80011
80121
  if (childStatusCode === 200 &&
@@ -80618,7 +80728,7 @@ register({
80618
80728
  configuration: { ...configurationForGraphQLAdapters },
80619
80729
  instrument,
80620
80730
  });
80621
- // version: 1.142.0-9f43a65a3
80731
+ // version: 1.143.0-7a79bacc1
80622
80732
 
80623
80733
  // On core the unstable adapters are re-exported with different names,
80624
80734
 
@@ -82802,6 +82912,12 @@ const graphQLAdapterFactory = (luvio) => {
82802
82912
  fragment,
82803
82913
  luvio,
82804
82914
  };
82915
+ // NOTE: For evaluating environments, set a context property to let the
82916
+ // environment detect that eval will happen and to check varous gates
82917
+ // for eval behavior customizations.
82918
+ if (storeEval !== undefined) {
82919
+ context.gqlEval = true;
82920
+ }
82805
82921
  const snapshotOrPromiseFromCachePolicy = luvio.applyCachePolicy(requestContext || {}, context, buildCachedSnapshot, buildNetworkSnapshotCachePolicy);
82806
82922
  if (storeEval !== undefined) {
82807
82923
  const observers = requestContext && requestContext.eventObservers
@@ -82850,7 +82966,7 @@ withDefaultLuvio((luvio) => {
82850
82966
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
82851
82967
  graphQLImperative = ldsAdapter;
82852
82968
  });
82853
- // version: 1.142.0-9f43a65a3
82969
+ // version: 1.143.0-7a79bacc1
82854
82970
 
82855
82971
  var gqlApi = /*#__PURE__*/Object.freeze({
82856
82972
  __proto__: null,
@@ -83539,4 +83655,4 @@ const { luvio } = getRuntime();
83539
83655
  setDefaultLuvio({ luvio });
83540
83656
 
83541
83657
  export { createPrimingSession, draftManager, draftQueue, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, registerReportObserver, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
83542
- // version: 1.142.0-7730e2a14
83658
+ // version: 1.143.0-a6d2a998d
@@ -2996,18 +2996,22 @@
2996
2996
  }
2997
2997
 
2998
2998
  /**
2999
- * Maps a CachePolicy to a CachePolicyImplementation
2999
+ * Maps a CachePolicy to a CachePolicyImplementation. We don't necessarily trust
3000
+ * "cachePolicy" because that could come from userland code. But we do trust
3001
+ * "defaultCachePolicy" because that comes from our own library code and should
3002
+ * be a valid type, so this function will fall back to "defaultCachePolicy" if
3003
+ * "cachePolicy" is invalid.
3000
3004
  *
3001
3005
  * @param cachePolicy cache policy
3002
3006
  * @param defaultCachePolicy default cache policy
3003
- * @param luvio the luvio instance
3004
- * @returns cache policy implementation corresponnding to cachePolicy
3007
+ * @returns cache policy implementation corresponding to cachePolicy
3005
3008
  */
3006
3009
  function resolveCachePolicy(cachePolicy, defaultCachePolicy) {
3007
3010
  if (cachePolicy === undefined) {
3008
- return defaultCachePolicy;
3011
+ return resolveCachePolicy(defaultCachePolicy, defaultCachePolicy);
3009
3012
  }
3010
- switch (cachePolicy.type) {
3013
+ const { type } = cachePolicy;
3014
+ switch (type) {
3011
3015
  case 'cache-and-network':
3012
3016
  return buildCacheAndNetworkImplementation(cachePolicy.staleDurationSeconds);
3013
3017
  case 'cache-then-network':
@@ -3023,7 +3027,7 @@
3023
3027
  return buildValidAtImplementation(basePolicy, cachePolicy.timestamp);
3024
3028
  }
3025
3029
  default: {
3026
- return defaultCachePolicy;
3030
+ return resolveCachePolicy(defaultCachePolicy, defaultCachePolicy);
3027
3031
  }
3028
3032
  }
3029
3033
  }
@@ -3050,10 +3054,7 @@
3050
3054
  constructor(store, networkAdapter) {
3051
3055
  this.networkCount = 0;
3052
3056
  this.storeQueryEvaluator = undefined;
3053
- this.defaultCachePolicy = {
3054
- type: 'cache-then-network',
3055
- implementation: cacheThenNetworkImplementation,
3056
- };
3057
+ this.defaultCachePolicy = { type: 'cache-then-network' };
3057
3058
  this.store = store;
3058
3059
  this.networkAdapter = networkAdapter;
3059
3060
  this.adapterContextMap = create$a(null);
@@ -3063,6 +3064,9 @@
3063
3064
  this.createSnapshot = this.createSnapshot.bind(this);
3064
3065
  this.rebuildSnapshot = this.rebuildSnapshot.bind(this);
3065
3066
  }
3067
+ setDefaultCachePolicy(cachePolicy) {
3068
+ this.defaultCachePolicy = cachePolicy;
3069
+ }
3066
3070
  /**
3067
3071
  * Returns a resolved promise of a FetchResponse for ok http status codes.
3068
3072
  * Returns a rejected promise of an ErrorResponse of type "fetchResponse" for non-ok http status codes.
@@ -3327,17 +3331,14 @@
3327
3331
  applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot) {
3328
3332
  const { defaultCachePolicy } = this;
3329
3333
  const { cachePolicy, eventObservers } = adapterRequestContext;
3330
- let cachePolicyType = defaultCachePolicy.type;
3331
- if (cachePolicy !== undefined) {
3332
- cachePolicyType = cachePolicy.type;
3333
- }
3334
- let cachePolicyImpl = resolveCachePolicy(cachePolicy, defaultCachePolicy.implementation);
3334
+ let cachePolicyImpl = resolveCachePolicy(cachePolicy, defaultCachePolicy);
3335
3335
  const resolvePendingSnapshot = (snapshot) => this.resolvePendingSnapshot(snapshot);
3336
3336
  const storeLookup = (sel, refresh, ttlStrategy) => this.storeLookup(sel, this.createSnapshot, refresh, ttlStrategy);
3337
3337
  let wrappedBuildCacheSnapshot = buildCachedSnapshot;
3338
3338
  let wrappedBuildNetworkSnapshot = buildNetworkSnapshot;
3339
3339
  // if eventObservers are provided for the adapter, wrap calls in versions that emit events
3340
3340
  if (eventObservers !== undefined) {
3341
+ const cachePolicyType = cachePolicy === undefined ? defaultCachePolicy.type : cachePolicy.type;
3341
3342
  cachePolicyImpl = cachePolicyImplWithEvents(cachePolicyImpl, cachePolicyType, eventObservers);
3342
3343
  wrappedBuildCacheSnapshot = buildCachedSnapshotWithEvents(buildCachedSnapshot, eventObservers);
3343
3344
  wrappedBuildNetworkSnapshot = buildNetworkSnapshotWithEvents(buildNetworkSnapshot, eventObservers);
@@ -3680,7 +3681,7 @@
3680
3681
  return this.environment.buildStructuredKey(namespace, representationName, idValues);
3681
3682
  }
3682
3683
  }
3683
- // engine version: 0.140.3-86f83ec8
3684
+ // engine version: 0.142.4-be29f4f3
3684
3685
 
3685
3686
  /**
3686
3687
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -3807,7 +3808,7 @@
3807
3808
  }
3808
3809
  callbacks.push(callback);
3809
3810
  }
3810
- // version: 1.142.0-7730e2a14
3811
+ // version: 1.143.0-a6d2a998d
3811
3812
 
3812
3813
  // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
3813
3814
  function instrumentAdapter$1(createFunction, _metadata) {
@@ -15231,7 +15232,7 @@
15231
15232
  updateReferenceMapWithKnownKey(ast, luvioDocumentNode);
15232
15233
  return luvioDocumentNode;
15233
15234
  }
15234
- // version: 1.142.0-7730e2a14
15235
+ // version: 1.143.0-a6d2a998d
15235
15236
 
15236
15237
  function unwrap(data) {
15237
15238
  // The lwc-luvio bindings import a function from lwc called "unwrap".
@@ -16144,7 +16145,7 @@
16144
16145
  const { apiFamily, name } = metadata;
16145
16146
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16146
16147
  }
16147
- // version: 1.142.0-7730e2a14
16148
+ // version: 1.143.0-a6d2a998d
16148
16149
 
16149
16150
  /**
16150
16151
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -16227,7 +16228,7 @@
16227
16228
  ({
16228
16229
  state: FragmentReadResultState.Missing,
16229
16230
  });
16230
- // engine version: 0.140.3-86f83ec8
16231
+ // engine version: 0.142.4-be29f4f3
16231
16232
 
16232
16233
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16233
16234
 
@@ -16575,7 +16576,7 @@
16575
16576
  return `Unexpected HTTP Status Code: ${status}`;
16576
16577
  }
16577
16578
  }
16578
- function isUnfulfilledSnapshot$1(snapshot) {
16579
+ function isUnfulfilledSnapshot$1$1(snapshot) {
16579
16580
  return snapshot.state === SNAPSHOT_STATE_UNFULFILLED;
16580
16581
  }
16581
16582
  const keyPrefix$1 = 'UiApi';
@@ -22817,7 +22818,7 @@
22817
22818
  config,
22818
22819
  resolve: () => buildNetworkSnapshot$U(luvio, config, snapshotRefreshOptions$1)
22819
22820
  });
22820
- if (isUnfulfilledSnapshot$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
22821
+ if (isUnfulfilledSnapshot$1$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
22821
22822
  context.cacheSnapshot = cacheSnapshot;
22822
22823
  }
22823
22824
  return cacheSnapshot;
@@ -38263,7 +38264,7 @@
38263
38264
  config,
38264
38265
  resolve: () => buildNetworkSnapshot$h(luvio, config, snapshotRefreshOptions$1)
38265
38266
  });
38266
- if (isUnfulfilledSnapshot$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
38267
+ if (isUnfulfilledSnapshot$1$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
38267
38268
  context.cacheSnapshot = cacheSnapshot;
38268
38269
  }
38269
38270
  return cacheSnapshot;
@@ -40405,7 +40406,7 @@
40405
40406
  config,
40406
40407
  resolve: () => buildNetworkSnapshot$9(luvio, config, snapshotRefreshOptions$1)
40407
40408
  });
40408
- if (isUnfulfilledSnapshot$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
40409
+ if (isUnfulfilledSnapshot$1$1(cacheSnapshot) && cacheSnapshot.data !== undefined) {
40409
40410
  context.cacheSnapshot = cacheSnapshot;
40410
40411
  }
40411
40412
  return cacheSnapshot;
@@ -44014,7 +44015,7 @@
44014
44015
  dropFunction: instrumentation$2.notifyRecordUpdateAvailableDropped,
44015
44016
  });
44016
44017
  });
44017
- // version: 1.142.0-9f43a65a3
44018
+ // version: 1.143.0-7a79bacc1
44018
44019
 
44019
44020
  var caseSensitiveUserId = '005B0000000GR4OIAW';
44020
44021
 
@@ -44089,6 +44090,33 @@
44089
44090
  return pattern;
44090
44091
  }
44091
44092
 
44093
+ var eagerEvalValidAt = {
44094
+ isOpen: function (e) {
44095
+ return e.fallback;
44096
+ },
44097
+ hasError: function () {
44098
+ return !0;
44099
+ },
44100
+ };
44101
+
44102
+ var eagerEvalStaleWhileRevalidate = {
44103
+ isOpen: function (e) {
44104
+ return e.fallback;
44105
+ },
44106
+ hasError: function () {
44107
+ return !0;
44108
+ },
44109
+ };
44110
+
44111
+ var eagerEvalDefaultCachePolicy = {
44112
+ isOpen: function (e) {
44113
+ return e.fallback;
44114
+ },
44115
+ hasError: function () {
44116
+ return !0;
44117
+ },
44118
+ };
44119
+
44092
44120
  /**
44093
44121
  * Copyright (c) 2022, Salesforce, Inc.,
44094
44122
  * All rights reserved.
@@ -44812,7 +44840,7 @@
44812
44840
  }
44813
44841
  }
44814
44842
 
44815
- function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler) {
44843
+ function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations = []) {
44816
44844
  const durableRecords = create$5(null);
44817
44845
  const evictedRecords = create$5(null);
44818
44846
  const { records, metadata: storeMetadata, visitedIds, refreshedIds, } = store.fallbackStringKeyInMemoryStore;
@@ -44839,7 +44867,7 @@
44839
44867
  };
44840
44868
  }
44841
44869
  }
44842
- const durableStoreOperations = [];
44870
+ const durableStoreOperations = additionalDurableStoreOperations;
44843
44871
  // publishes
44844
44872
  const recordKeys = keys$6(durableRecords);
44845
44873
  if (recordKeys.length > 0) {
@@ -44931,7 +44959,7 @@
44931
44959
  }
44932
44960
  return contextReturn();
44933
44961
  }
44934
- function isUnfulfilledSnapshot(cachedSnapshotResult) {
44962
+ function isUnfulfilledSnapshot$1(cachedSnapshotResult) {
44935
44963
  if (cachedSnapshotResult === undefined) {
44936
44964
  return false;
44937
44965
  }
@@ -44942,7 +44970,8 @@
44942
44970
  }
44943
44971
  /**
44944
44972
  * Configures the environment to persist data into a durable store and attempt to resolve
44945
- * data from the persistent store before hitting the network.
44973
+ * data from the persistent store before hitting the network. Sets the default
44974
+ * cache policy to stale-while-revalidate with infinite staleDuration.
44946
44975
  *
44947
44976
  * @param environment The base environment
44948
44977
  * @param durableStore A DurableStore implementation
@@ -45082,12 +45111,12 @@
45082
45111
  // call the base storeBroadcast
45083
45112
  return publishChangesToDurableStore();
45084
45113
  };
45085
- const publishChangesToDurableStore = function () {
45114
+ const publishChangesToDurableStore = function (additionalDurableStoreOperations) {
45086
45115
  validateNotDisposed();
45087
45116
  if (ingestStagingStore === null) {
45088
45117
  return Promise.resolve();
45089
45118
  }
45090
- const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler);
45119
+ const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations);
45091
45120
  ingestStagingStore = null;
45092
45121
  return promise;
45093
45122
  };
@@ -45214,7 +45243,7 @@
45214
45243
  const snapshot = buildCachedSnapshot(injectedBuildSnapshotContext, injectedStoreLookup, luvio);
45215
45244
  // if the adapter attempted to do an L1 lookup and it was unfulfilled
45216
45245
  // then we can attempt an L2 lookup
45217
- if (isUnfulfilledSnapshot(snapshot)) {
45246
+ if (isUnfulfilledSnapshot$1(snapshot)) {
45218
45247
  const start = Date.now();
45219
45248
  emitDurableEnvironmentAdapterEvent({ type: 'l2-revive-start' }, adapterRequestContext.eventObservers);
45220
45249
  const revivedSnapshot = reviveSnapshot(environment, durableStore, snapshot, durableStoreErrorHandler, () => injectedStoreLookup(snapshot.select, snapshot.refresh)).then((result) => {
@@ -45367,10 +45396,11 @@
45367
45396
  return entries;
45368
45397
  });
45369
45398
  };
45370
- environment.defaultCachePolicy = {
45399
+ // set the default cache policy of the base environment
45400
+ environment.setDefaultCachePolicy({
45371
45401
  type: 'stale-while-revalidate',
45372
- implementation: buildStaleWhileRevalidateImplementation(Number.MAX_SAFE_INTEGER),
45373
- };
45402
+ staleDurationSeconds: Number.MAX_SAFE_INTEGER,
45403
+ });
45374
45404
  return create$5(environment, {
45375
45405
  publishStoreMetadata: { value: publishStoreMetadata },
45376
45406
  storeIngest: { value: storeIngest },
@@ -56571,6 +56601,7 @@
56571
56601
  query: injectedAST,
56572
56602
  },
56573
56603
  luvio,
56604
+ gqlEval: true,
56574
56605
  }, buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy));
56575
56606
  if (isErrorSnapshotThatShouldGetReturnedToCaller(nonEvaluatedSnapshot)) {
56576
56607
  return nonEvaluatedSnapshot;
@@ -59029,8 +59060,17 @@
59029
59060
  }
59030
59061
  }
59031
59062
 
59032
- //TODO: [W-12734162] - rebuild non-evaluated snapshot when graph rebuild is triggered. The dependency work on luvio needs to be done.
59063
+ function isUnfulfilledSnapshot(cachedSnapshotResult) {
59064
+ if (cachedSnapshotResult === undefined) {
59065
+ return false;
59066
+ }
59067
+ if ('then' in cachedSnapshotResult) {
59068
+ return false;
59069
+ }
59070
+ return cachedSnapshotResult.state === 'Unfulfilled';
59071
+ }
59033
59072
  function makeEnvironmentGraphqlAware(environment) {
59073
+ //TODO: [W-12734162] - rebuild non-evaluated snapshot when graph rebuild is triggered. The dependency work on luvio needs to be done.
59034
59074
  const rebuildSnapshot = function (snapshot, onRebuild) {
59035
59075
  if (isStoreEvalSnapshot(snapshot)) {
59036
59076
  snapshot.rebuildWithStoreEval(snapshot).then((rebuilt) => {
@@ -59046,8 +59086,64 @@
59046
59086
  }
59047
59087
  return environment.rebuildSnapshot(snapshot, onRebuild);
59048
59088
  };
59089
+ const applyCachePolicy = function (luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot) {
59090
+ // Early exit for non-evaluating adapters
59091
+ let graphqlBuildSnapshotContext = buildSnapshotContext;
59092
+ if (graphqlBuildSnapshotContext.gqlEval !== true) {
59093
+ return environment.applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot);
59094
+ }
59095
+ var localBuildCachedSnapshot = buildCachedSnapshot;
59096
+ const hoistUnfulfilledToStale = (context, storeLookup, luvio) => {
59097
+ const upstream = buildCachedSnapshot(context, storeLookup, luvio);
59098
+ if (upstream === undefined)
59099
+ return upstream;
59100
+ if (isUnfulfilledSnapshot(upstream)) {
59101
+ return {
59102
+ ...upstream,
59103
+ data: upstream.data || {},
59104
+ state: 'Stale',
59105
+ };
59106
+ }
59107
+ else if ('then' in upstream) {
59108
+ return upstream.then((snapshot) => {
59109
+ if (snapshot === undefined)
59110
+ return snapshot;
59111
+ if (isUnfulfilledSnapshot(snapshot)) {
59112
+ return {
59113
+ ...snapshot,
59114
+ data: snapshot.data || {},
59115
+ state: 'Stale',
59116
+ };
59117
+ }
59118
+ return snapshot;
59119
+ });
59120
+ }
59121
+ return upstream;
59122
+ };
59123
+ const { cachePolicy } = adapterRequestContext;
59124
+ if (eagerEvalValidAt.isOpen({ fallback: false }) &&
59125
+ cachePolicy &&
59126
+ cachePolicy.type === 'valid-at' &&
59127
+ cachePolicy.timestamp === 0 &&
59128
+ cachePolicy.basePolicy &&
59129
+ cachePolicy.basePolicy.type === 'stale-while-revalidate') {
59130
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
59131
+ }
59132
+ if (eagerEvalStaleWhileRevalidate.isOpen({ fallback: false }) &&
59133
+ cachePolicy &&
59134
+ cachePolicy.type === 'stale-while-revalidate' &&
59135
+ cachePolicy.staleDurationSeconds === Number.MAX_SAFE_INTEGER) {
59136
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
59137
+ }
59138
+ if (eagerEvalDefaultCachePolicy.isOpen({ fallback: false }) && cachePolicy === undefined) {
59139
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
59140
+ }
59141
+ return environment.applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, localBuildCachedSnapshot, buildNetworkSnapshot);
59142
+ };
59049
59143
  return create$6(environment, {
59050
59144
  rebuildSnapshot: { value: rebuildSnapshot },
59145
+ applyCachePolicy: { value: applyCachePolicy },
59146
+ setDefaultCachePolicy: { value: environment.setDefaultCachePolicy.bind(environment) },
59051
59147
  });
59052
59148
  }
59053
59149
 
@@ -59795,7 +59891,7 @@
59795
59891
  id: '@salesforce/lds-network-adapter',
59796
59892
  instrument: instrument$1,
59797
59893
  });
59798
- // version: 1.142.0-7730e2a14
59894
+ // version: 1.143.0-a6d2a998d
59799
59895
 
59800
59896
  const { create: create$2, keys: keys$2 } = Object;
59801
59897
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -59909,6 +60005,20 @@
59909
60005
  return `${keyPrefix}::${schemaName}::${queryTypeName}[${serializeOperationNode$1(operationNode, variables, fragmentMap)}]`;
59910
60006
  }
59911
60007
 
60008
+ /**
60009
+ * @description Spec compliant way to retrieve the correct Operation from the Document that Luvio should operate on. https://spec.graphql.org/June2018/#sec-Named-Operation-Definitions
60010
+ * @param document
60011
+ * @param operationName
60012
+ * @returns The Operation in the GraphQL document we should use for the current call.
60013
+ */
60014
+ function getOperationFromDocument(document, operationName) {
60015
+ const operations = document.definitions.filter((def) => def.kind === 'OperationDefinition');
60016
+ if (operationName) {
60017
+ return operations.find((def) => def.name !== undefined && def.name.value === operationName);
60018
+ }
60019
+ return operations[0]; // If a named operation is not provided, we return the first one
60020
+ }
60021
+
59912
60022
  /**
59913
60023
  * Copyright (c) 2022, Salesforce, Inc.,
59914
60024
  * All rights reserved.
@@ -79320,43 +79430,38 @@
79320
79430
  const TTL = 900000;
79321
79431
  const VERSION$6 = "b440235e7e724631f92002fe50e3e096";
79322
79432
  const RepresentationType = 'GraphQLRepresentation';
79323
- function select$8(luvio, query, variables) {
79324
- const definitions = query.definitions === undefined ? [] : query.definitions;
79433
+ function select$8(luvio, document, variables, operationName) {
79434
+ const operationToExecute = getOperationFromDocument(document, operationName);
79325
79435
  return {
79326
79436
  kind: 'Fragment',
79327
79437
  synthetic: true,
79328
79438
  reader: true,
79329
79439
  read: (builder) => {
79330
79440
  builder.enterPath('data');
79331
- let sink = {};
79332
- const fragments = createFragmentMap(query);
79333
- for (let i = 0, len = definitions.length; i < len; i += 1) {
79334
- const def = definitions[i];
79335
- if (def.kind === 'OperationDefinition') {
79336
- const queryTypeRecordId = keyBuilder$4(luvio, def, variables, fragments);
79337
- const snapshot = builder.read({
79338
- recordId: queryTypeRecordId,
79339
- node: {
79340
- kind: 'Fragment',
79341
- private: [],
79342
- opaque: true,
79343
- version: VERSION$7
79344
- },
79345
- variables: {}
79346
- });
79347
- if (snapshot.data === undefined) {
79348
- builder.markMissingLink(queryTypeRecordId);
79349
- break;
79350
- }
79351
- const data = select$9(def, variables, fragments)(snapshot.data, builder, queryTypeRecordId);
79352
- sink = {
79353
- ...sink,
79354
- ...data,
79355
- };
79356
- }
79357
- }
79358
79441
  const gqlData = {};
79359
- builder.assignNonScalar(gqlData, 'data', sink);
79442
+ if (operationToExecute === undefined) {
79443
+ builder.markMissing(); // Never give a cache hit for an undefined operation
79444
+ return gqlData;
79445
+ }
79446
+ const fragments = createFragmentMap(document);
79447
+ const queryTypeRecordId = keyBuilder$4(luvio, operationToExecute, variables, fragments);
79448
+ const snapshot = builder.read({
79449
+ recordId: queryTypeRecordId,
79450
+ node: {
79451
+ kind: 'Fragment',
79452
+ private: [],
79453
+ opaque: true,
79454
+ version: VERSION$7
79455
+ },
79456
+ variables: {}
79457
+ });
79458
+ if (snapshot.data === undefined) {
79459
+ builder.markMissingLink(queryTypeRecordId);
79460
+ }
79461
+ else {
79462
+ const data = select$9(operationToExecute, variables, fragments)(snapshot.data, builder, queryTypeRecordId);
79463
+ builder.assignNonScalar(gqlData, 'data', data);
79464
+ }
79360
79465
  builder.exitPath();
79361
79466
  return gqlData;
79362
79467
  }
@@ -79376,10 +79481,10 @@
79376
79481
  });
79377
79482
  }
79378
79483
  }
79379
- const ingest = function GraphQLRepresentationIngest(query, variables) {
79484
+ const ingest = function GraphQLRepresentationIngest(document, variables, operationName) {
79380
79485
  return (input, path, luvio, store, timestamp) => {
79381
79486
  if (input.data) {
79382
- const fragments = createFragmentMap(query);
79487
+ const fragments = createFragmentMap(document);
79383
79488
  const state = {
79384
79489
  data: input.data,
79385
79490
  luvio,
@@ -79389,58 +79494,63 @@
79389
79494
  variables,
79390
79495
  fragments,
79391
79496
  };
79392
- query.definitions.forEach((node) => {
79393
- if (node.kind === 'OperationDefinition') {
79394
- ingestOperationNode(luvio, input, node, state);
79395
- }
79396
- });
79497
+ const operationToExecute = getOperationFromDocument(document, operationName);
79498
+ if (operationToExecute !== undefined) {
79499
+ ingestOperationNode(luvio, input, operationToExecute, state);
79500
+ }
79397
79501
  }
79398
79502
  return {
79399
79503
  __ref: undefined
79400
79504
  };
79401
79505
  };
79402
79506
  };
79403
- function getTypeCacheKeys(luvio, query, variables, data) {
79507
+ function getTypeCacheKeys(luvio, document, variables, data, operationName) {
79404
79508
  const sink = new StoreKeyMap();
79405
79509
  if (data.data) {
79406
- const fragments = createFragmentMap(query);
79407
- query.definitions.forEach((node) => {
79408
- if (node.kind === 'OperationDefinition') {
79409
- const state = {
79410
- luvio,
79411
- variables,
79412
- fragments,
79413
- data: data.data,
79414
- path: {
79415
- parent: null,
79416
- propertyName: null,
79417
- fullPath: '' // TODO: W-13079691 - Need to take another pass at what we want to do for structured keys
79418
- }
79419
- };
79420
- sink.merge(getTypeCacheKeys$1(node, state));
79421
- }
79422
- });
79510
+ const fragments = createFragmentMap(document);
79511
+ const operationToExecute = getOperationFromDocument(document, operationName);
79512
+ if (operationToExecute !== undefined) {
79513
+ const state = {
79514
+ luvio,
79515
+ variables,
79516
+ fragments,
79517
+ data: data.data,
79518
+ path: {
79519
+ parent: null,
79520
+ propertyName: null,
79521
+ fullPath: '' // TODO: W-13079691 - Need to take another pass at what we want to do for structured keys
79522
+ }
79523
+ };
79524
+ sink.merge(getTypeCacheKeys$1(operationToExecute, state));
79525
+ }
79423
79526
  }
79424
79527
  return sink;
79425
79528
  }
79426
79529
 
79427
79530
  function select$7(luvio, config) {
79428
- const { query, variables } = config;
79429
- return select$8(luvio, query, variables);
79531
+ const { query, variables, operationName } = config;
79532
+ return select$8(luvio, query, variables, operationName);
79430
79533
  }
79431
79534
  function keyBuilder$3(luvio, params) {
79432
- return keyPrefix + '::' + 'GraphQLRepresentation';
79535
+ const { query, operationName, variables } = params.body;
79536
+ const operationToExecute = getOperationFromDocument(query, operationName);
79537
+ if (operationToExecute !== undefined) {
79538
+ const fragments = createFragmentMap(query);
79539
+ return keyBuilder$4(luvio, operationToExecute, variables || {}, fragments);
79540
+ }
79541
+ return `adapters_adapter$45$utils_keyPrefix::GraphQLRepresentation::InvalidOperation`;
79433
79542
  }
79434
79543
  function getResponseCacheKeys$1(luvio, resourceParams, response) {
79435
79544
  const query = resourceParams.body.query;
79436
79545
  const variables = resourceParams.body.variables || {};
79437
- return getTypeCacheKeys(luvio, query, variables, response);
79546
+ const operationName = resourceParams.body.operationName;
79547
+ return getTypeCacheKeys(luvio, query, variables, response, operationName);
79438
79548
  }
79439
79549
  function ingestSuccess$1(luvio, config, resourceParams, response, snapshotRefresh) {
79440
79550
  const { body } = response;
79441
- const key = keyBuilder$3();
79442
- const { query, variables } = resourceParams.body;
79443
- luvio.storeIngest(key, ingest(query, variables), body);
79551
+ const key = keyBuilder$3(luvio, resourceParams);
79552
+ const { query, variables, operationName } = resourceParams.body;
79553
+ luvio.storeIngest(key, ingest(query, variables, operationName), body);
79444
79554
  // revert the optimized pagination variables back to its original so that subsequent store lookup will include all records, not just the ones loaded by an optimized query
79445
79555
  // see optimizePagination for initial update to optimize the query
79446
79556
  revertPaginationOptimization(variables);
@@ -79452,7 +79562,7 @@
79452
79562
  return snapshot;
79453
79563
  }
79454
79564
  function ingestError$1(luvio, config, params, error, snapshotRefresh) {
79455
- const key = keyBuilder$3();
79565
+ const key = keyBuilder$3(luvio, params);
79456
79566
  const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
79457
79567
  const storeMetadataParams = {
79458
79568
  ttl: TTL,
@@ -79535,8 +79645,8 @@
79535
79645
  return resourceParams;
79536
79646
  }
79537
79647
  function keyBuilder$2(luvio, config) {
79538
- createResourceParams$1(config);
79539
- return keyBuilder$3();
79648
+ const resourceParams = createResourceParams$1(config);
79649
+ return keyBuilder$3(luvio, resourceParams);
79540
79650
  }
79541
79651
  function typeCheckConfig$1(untrustedConfig) {
79542
79652
  const config = {};
@@ -79884,7 +79994,7 @@
79884
79994
  reader.enterPath(i);
79885
79995
  reader.enterPath(envelopeBodyPath);
79886
79996
  const childResource = childResources[i];
79887
- const childKey = keyBuilder$3();
79997
+ const childKey = keyBuilder$3(luvio, childResource);
79888
79998
  const childFragment = select$7(luvio, childResource.body); // MUST read from the ORIGINAL config not injected
79889
79999
  const isMissingDataBeforeChildRead = reader.getIsDataMissing();
79890
80000
  const childSnapshot = reader.read({
@@ -79995,7 +80105,7 @@
79995
80105
  ObjectAssign(keys, childKeys);
79996
80106
  }
79997
80107
  else if (childStatusCode === 404) {
79998
- const childKey = keyBuilder$3();
80108
+ const childKey = keyBuilder$3(luvio, childResourceParams);
79999
80109
  keys.set(childKey, {
80000
80110
  namespace: keyPrefix,
80001
80111
  representationName: RepresentationType,
@@ -80013,7 +80123,7 @@
80013
80123
  // There's an assumption here that the config and resource params aren't reordered.
80014
80124
  const childConfig = childConfigs[index];
80015
80125
  const childResourceParams = childResourceParamsArray[index];
80016
- const childKey = keyBuilder$3();
80126
+ const childKey = keyBuilder$3(luvio, childResourceParams);
80017
80127
  const result = childEnvelopes[index];
80018
80128
  const { statusCode: childStatusCode, result: childBody } = result;
80019
80129
  if (childStatusCode === 200 &&
@@ -80626,7 +80736,7 @@
80626
80736
  configuration: { ...configurationForGraphQLAdapters },
80627
80737
  instrument,
80628
80738
  });
80629
- // version: 1.142.0-9f43a65a3
80739
+ // version: 1.143.0-7a79bacc1
80630
80740
 
80631
80741
  // On core the unstable adapters are re-exported with different names,
80632
80742
 
@@ -82810,6 +82920,12 @@
82810
82920
  fragment,
82811
82921
  luvio,
82812
82922
  };
82923
+ // NOTE: For evaluating environments, set a context property to let the
82924
+ // environment detect that eval will happen and to check varous gates
82925
+ // for eval behavior customizations.
82926
+ if (storeEval !== undefined) {
82927
+ context.gqlEval = true;
82928
+ }
82813
82929
  const snapshotOrPromiseFromCachePolicy = luvio.applyCachePolicy(requestContext || {}, context, buildCachedSnapshot, buildNetworkSnapshotCachePolicy);
82814
82930
  if (storeEval !== undefined) {
82815
82931
  const observers = requestContext && requestContext.eventObservers
@@ -82858,7 +82974,7 @@
82858
82974
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
82859
82975
  graphQLImperative = ldsAdapter;
82860
82976
  });
82861
- // version: 1.142.0-9f43a65a3
82977
+ // version: 1.143.0-7a79bacc1
82862
82978
 
82863
82979
  var gqlApi = /*#__PURE__*/Object.freeze({
82864
82980
  __proto__: null,
@@ -83564,4 +83680,4 @@
83564
83680
  Object.defineProperty(exports, '__esModule', { value: true });
83565
83681
 
83566
83682
  }));
83567
- // version: 1.142.0-7730e2a14
83683
+ // version: 1.143.0-a6d2a998d
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-worker-api",
3
- "version": "1.142.0",
3
+ "version": "1.143.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "",
6
6
  "main": "dist/standalone/es/lds-worker-api.js",