@salesforce/lds-worker-api 1.142.0 → 1.142.1

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.142.1-d514db71e
@@ -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.3-97d0da6c
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.142.1-d514db71e
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.142.1-d514db71e
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.142.1-d514db71e
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.3-97d0da6c
16223
16224
 
16224
16225
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16225
16226
 
@@ -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.142.1-1511d83f4
44010
44011
 
44011
44012
  var caseSensitiveUserId = '005B0000000GR4OIAW';
44012
44013
 
@@ -44804,7 +44805,7 @@ class DurableTTLStore {
44804
44805
  }
44805
44806
  }
44806
44807
 
44807
- function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler) {
44808
+ function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations = []) {
44808
44809
  const durableRecords = create$5(null);
44809
44810
  const evictedRecords = create$5(null);
44810
44811
  const { records, metadata: storeMetadata, visitedIds, refreshedIds, } = store.fallbackStringKeyInMemoryStore;
@@ -44831,7 +44832,7 @@ function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStor
44831
44832
  };
44832
44833
  }
44833
44834
  }
44834
- const durableStoreOperations = [];
44835
+ const durableStoreOperations = additionalDurableStoreOperations;
44835
44836
  // publishes
44836
44837
  const recordKeys = keys$6(durableRecords);
44837
44838
  if (recordKeys.length > 0) {
@@ -44934,7 +44935,8 @@ function isUnfulfilledSnapshot(cachedSnapshotResult) {
44934
44935
  }
44935
44936
  /**
44936
44937
  * Configures the environment to persist data into a durable store and attempt to resolve
44937
- * data from the persistent store before hitting the network.
44938
+ * data from the persistent store before hitting the network. Sets the default
44939
+ * cache policy to stale-while-revalidate with infinite staleDuration.
44938
44940
  *
44939
44941
  * @param environment The base environment
44940
44942
  * @param durableStore A DurableStore implementation
@@ -45074,12 +45076,12 @@ function makeDurable(environment, { durableStore, instrumentation }) {
45074
45076
  // call the base storeBroadcast
45075
45077
  return publishChangesToDurableStore();
45076
45078
  };
45077
- const publishChangesToDurableStore = function () {
45079
+ const publishChangesToDurableStore = function (additionalDurableStoreOperations) {
45078
45080
  validateNotDisposed();
45079
45081
  if (ingestStagingStore === null) {
45080
45082
  return Promise.resolve();
45081
45083
  }
45082
- const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler);
45084
+ const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations);
45083
45085
  ingestStagingStore = null;
45084
45086
  return promise;
45085
45087
  };
@@ -45359,10 +45361,11 @@ function makeDurable(environment, { durableStore, instrumentation }) {
45359
45361
  return entries;
45360
45362
  });
45361
45363
  };
45362
- environment.defaultCachePolicy = {
45364
+ // set the default cache policy of the base environment
45365
+ environment.setDefaultCachePolicy({
45363
45366
  type: 'stale-while-revalidate',
45364
- implementation: buildStaleWhileRevalidateImplementation(Number.MAX_SAFE_INTEGER),
45365
- };
45367
+ staleDurationSeconds: Number.MAX_SAFE_INTEGER,
45368
+ });
45366
45369
  return create$5(environment, {
45367
45370
  publishStoreMetadata: { value: publishStoreMetadata },
45368
45371
  storeIngest: { value: storeIngest },
@@ -59787,7 +59790,7 @@ register({
59787
59790
  id: '@salesforce/lds-network-adapter',
59788
59791
  instrument: instrument$1,
59789
59792
  });
59790
- // version: 1.142.0-7730e2a14
59793
+ // version: 1.142.1-d514db71e
59791
59794
 
59792
59795
  const { create: create$2, keys: keys$2 } = Object;
59793
59796
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -59901,6 +59904,20 @@ function buildQueryTypeStringKey(args) {
59901
59904
  return `${keyPrefix}::${schemaName}::${queryTypeName}[${serializeOperationNode$1(operationNode, variables, fragmentMap)}]`;
59902
59905
  }
59903
59906
 
59907
+ /**
59908
+ * @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
59909
+ * @param document
59910
+ * @param operationName
59911
+ * @returns The Operation in the GraphQL document we should use for the current call.
59912
+ */
59913
+ function getOperationFromDocument(document, operationName) {
59914
+ const operations = document.definitions.filter((def) => def.kind === 'OperationDefinition');
59915
+ if (operationName) {
59916
+ return operations.find((def) => def.name !== undefined && def.name.value === operationName);
59917
+ }
59918
+ return operations[0]; // If a named operation is not provided, we return the first one
59919
+ }
59920
+
59904
59921
  /**
59905
59922
  * Copyright (c) 2022, Salesforce, Inc.,
59906
59923
  * All rights reserved.
@@ -79312,43 +79329,38 @@ function getInContextFragmentType(fragment, fragmentMap) {
79312
79329
  const TTL = 900000;
79313
79330
  const VERSION$6 = "b440235e7e724631f92002fe50e3e096";
79314
79331
  const RepresentationType = 'GraphQLRepresentation';
79315
- function select$8(luvio, query, variables) {
79316
- const definitions = query.definitions === undefined ? [] : query.definitions;
79332
+ function select$8(luvio, document, variables, operationName) {
79333
+ const operationToExecute = getOperationFromDocument(document, operationName);
79317
79334
  return {
79318
79335
  kind: 'Fragment',
79319
79336
  synthetic: true,
79320
79337
  reader: true,
79321
79338
  read: (builder) => {
79322
79339
  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
79340
  const gqlData = {};
79351
- builder.assignNonScalar(gqlData, 'data', sink);
79341
+ if (operationToExecute === undefined) {
79342
+ builder.markMissing(); // Never give a cache hit for an undefined operation
79343
+ return gqlData;
79344
+ }
79345
+ const fragments = createFragmentMap(document);
79346
+ const queryTypeRecordId = keyBuilder$4(luvio, operationToExecute, variables, fragments);
79347
+ const snapshot = builder.read({
79348
+ recordId: queryTypeRecordId,
79349
+ node: {
79350
+ kind: 'Fragment',
79351
+ private: [],
79352
+ opaque: true,
79353
+ version: VERSION$7
79354
+ },
79355
+ variables: {}
79356
+ });
79357
+ if (snapshot.data === undefined) {
79358
+ builder.markMissingLink(queryTypeRecordId);
79359
+ }
79360
+ else {
79361
+ const data = select$9(operationToExecute, variables, fragments)(snapshot.data, builder, queryTypeRecordId);
79362
+ builder.assignNonScalar(gqlData, 'data', data);
79363
+ }
79352
79364
  builder.exitPath();
79353
79365
  return gqlData;
79354
79366
  }
@@ -79368,10 +79380,10 @@ function ingestOperationNode(luvio, input, node, state) {
79368
79380
  });
79369
79381
  }
79370
79382
  }
79371
- const ingest = function GraphQLRepresentationIngest(query, variables) {
79383
+ const ingest = function GraphQLRepresentationIngest(document, variables, operationName) {
79372
79384
  return (input, path, luvio, store, timestamp) => {
79373
79385
  if (input.data) {
79374
- const fragments = createFragmentMap(query);
79386
+ const fragments = createFragmentMap(document);
79375
79387
  const state = {
79376
79388
  data: input.data,
79377
79389
  luvio,
@@ -79381,44 +79393,42 @@ const ingest = function GraphQLRepresentationIngest(query, variables) {
79381
79393
  variables,
79382
79394
  fragments,
79383
79395
  };
79384
- query.definitions.forEach((node) => {
79385
- if (node.kind === 'OperationDefinition') {
79386
- ingestOperationNode(luvio, input, node, state);
79387
- }
79388
- });
79396
+ const operationToExecute = getOperationFromDocument(document, operationName);
79397
+ if (operationToExecute !== undefined) {
79398
+ ingestOperationNode(luvio, input, operationToExecute, state);
79399
+ }
79389
79400
  }
79390
79401
  return {
79391
79402
  __ref: undefined
79392
79403
  };
79393
79404
  };
79394
79405
  };
79395
- function getTypeCacheKeys(luvio, query, variables, data) {
79406
+ function getTypeCacheKeys(luvio, document, variables, data, operationName) {
79396
79407
  const sink = new StoreKeyMap();
79397
79408
  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
- });
79409
+ const fragments = createFragmentMap(document);
79410
+ const operationToExecute = getOperationFromDocument(document, operationName);
79411
+ if (operationToExecute !== undefined) {
79412
+ const state = {
79413
+ luvio,
79414
+ variables,
79415
+ fragments,
79416
+ data: data.data,
79417
+ path: {
79418
+ parent: null,
79419
+ propertyName: null,
79420
+ fullPath: '' // TODO: W-13079691 - Need to take another pass at what we want to do for structured keys
79421
+ }
79422
+ };
79423
+ sink.merge(getTypeCacheKeys$1(operationToExecute, state));
79424
+ }
79415
79425
  }
79416
79426
  return sink;
79417
79427
  }
79418
79428
 
79419
79429
  function select$7(luvio, config) {
79420
- const { query, variables } = config;
79421
- return select$8(luvio, query, variables);
79430
+ const { query, variables, operationName } = config;
79431
+ return select$8(luvio, query, variables, operationName);
79422
79432
  }
79423
79433
  function keyBuilder$3(luvio, params) {
79424
79434
  return keyPrefix + '::' + 'GraphQLRepresentation';
@@ -79426,13 +79436,14 @@ function keyBuilder$3(luvio, params) {
79426
79436
  function getResponseCacheKeys$1(luvio, resourceParams, response) {
79427
79437
  const query = resourceParams.body.query;
79428
79438
  const variables = resourceParams.body.variables || {};
79429
- return getTypeCacheKeys(luvio, query, variables, response);
79439
+ const operationName = resourceParams.body.operationName;
79440
+ return getTypeCacheKeys(luvio, query, variables, response, operationName);
79430
79441
  }
79431
79442
  function ingestSuccess$1(luvio, config, resourceParams, response, snapshotRefresh) {
79432
79443
  const { body } = response;
79433
79444
  const key = keyBuilder$3();
79434
- const { query, variables } = resourceParams.body;
79435
- luvio.storeIngest(key, ingest(query, variables), body);
79445
+ const { query, variables, operationName } = resourceParams.body;
79446
+ luvio.storeIngest(key, ingest(query, variables, operationName), body);
79436
79447
  // 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
79448
  // see optimizePagination for initial update to optimize the query
79438
79449
  revertPaginationOptimization(variables);
@@ -80618,7 +80629,7 @@ register({
80618
80629
  configuration: { ...configurationForGraphQLAdapters },
80619
80630
  instrument,
80620
80631
  });
80621
- // version: 1.142.0-9f43a65a3
80632
+ // version: 1.142.1-1511d83f4
80622
80633
 
80623
80634
  // On core the unstable adapters are re-exported with different names,
80624
80635
 
@@ -82850,7 +82861,7 @@ withDefaultLuvio((luvio) => {
82850
82861
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
82851
82862
  graphQLImperative = ldsAdapter;
82852
82863
  });
82853
- // version: 1.142.0-9f43a65a3
82864
+ // version: 1.142.1-1511d83f4
82854
82865
 
82855
82866
  var gqlApi = /*#__PURE__*/Object.freeze({
82856
82867
  __proto__: null,
@@ -83539,4 +83550,4 @@ const { luvio } = getRuntime();
83539
83550
  setDefaultLuvio({ luvio });
83540
83551
 
83541
83552
  export { createPrimingSession, draftManager, draftQueue, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, registerReportObserver, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
83542
- // version: 1.142.0-7730e2a14
83553
+ // version: 1.142.1-d514db71e
@@ -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.3-97d0da6c
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.142.1-d514db71e
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.142.1-d514db71e
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.142.1-d514db71e
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.3-97d0da6c
16231
16232
 
16232
16233
  const { keys: ObjectKeys$3, create: ObjectCreate$3 } = Object;
16233
16234
 
@@ -44014,7 +44015,7 @@
44014
44015
  dropFunction: instrumentation$2.notifyRecordUpdateAvailableDropped,
44015
44016
  });
44016
44017
  });
44017
- // version: 1.142.0-9f43a65a3
44018
+ // version: 1.142.1-1511d83f4
44018
44019
 
44019
44020
  var caseSensitiveUserId = '005B0000000GR4OIAW';
44020
44021
 
@@ -44812,7 +44813,7 @@
44812
44813
  }
44813
44814
  }
44814
44815
 
44815
- function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler) {
44816
+ function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations = []) {
44816
44817
  const durableRecords = create$5(null);
44817
44818
  const evictedRecords = create$5(null);
44818
44819
  const { records, metadata: storeMetadata, visitedIds, refreshedIds, } = store.fallbackStringKeyInMemoryStore;
@@ -44839,7 +44840,7 @@
44839
44840
  };
44840
44841
  }
44841
44842
  }
44842
- const durableStoreOperations = [];
44843
+ const durableStoreOperations = additionalDurableStoreOperations;
44843
44844
  // publishes
44844
44845
  const recordKeys = keys$6(durableRecords);
44845
44846
  if (recordKeys.length > 0) {
@@ -44942,7 +44943,8 @@
44942
44943
  }
44943
44944
  /**
44944
44945
  * Configures the environment to persist data into a durable store and attempt to resolve
44945
- * data from the persistent store before hitting the network.
44946
+ * data from the persistent store before hitting the network. Sets the default
44947
+ * cache policy to stale-while-revalidate with infinite staleDuration.
44946
44948
  *
44947
44949
  * @param environment The base environment
44948
44950
  * @param durableStore A DurableStore implementation
@@ -45082,12 +45084,12 @@
45082
45084
  // call the base storeBroadcast
45083
45085
  return publishChangesToDurableStore();
45084
45086
  };
45085
- const publishChangesToDurableStore = function () {
45087
+ const publishChangesToDurableStore = function (additionalDurableStoreOperations) {
45086
45088
  validateNotDisposed();
45087
45089
  if (ingestStagingStore === null) {
45088
45090
  return Promise.resolve();
45089
45091
  }
45090
- const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler);
45092
+ const promise = flushInMemoryStoreValuesToDurableStore(ingestStagingStore, durableStore, durableStoreErrorHandler, additionalDurableStoreOperations);
45091
45093
  ingestStagingStore = null;
45092
45094
  return promise;
45093
45095
  };
@@ -45367,10 +45369,11 @@
45367
45369
  return entries;
45368
45370
  });
45369
45371
  };
45370
- environment.defaultCachePolicy = {
45372
+ // set the default cache policy of the base environment
45373
+ environment.setDefaultCachePolicy({
45371
45374
  type: 'stale-while-revalidate',
45372
- implementation: buildStaleWhileRevalidateImplementation(Number.MAX_SAFE_INTEGER),
45373
- };
45375
+ staleDurationSeconds: Number.MAX_SAFE_INTEGER,
45376
+ });
45374
45377
  return create$5(environment, {
45375
45378
  publishStoreMetadata: { value: publishStoreMetadata },
45376
45379
  storeIngest: { value: storeIngest },
@@ -59795,7 +59798,7 @@
59795
59798
  id: '@salesforce/lds-network-adapter',
59796
59799
  instrument: instrument$1,
59797
59800
  });
59798
- // version: 1.142.0-7730e2a14
59801
+ // version: 1.142.1-d514db71e
59799
59802
 
59800
59803
  const { create: create$2, keys: keys$2 } = Object;
59801
59804
  const { stringify: stringify$1, parse: parse$1 } = JSON;
@@ -59909,6 +59912,20 @@
59909
59912
  return `${keyPrefix}::${schemaName}::${queryTypeName}[${serializeOperationNode$1(operationNode, variables, fragmentMap)}]`;
59910
59913
  }
59911
59914
 
59915
+ /**
59916
+ * @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
59917
+ * @param document
59918
+ * @param operationName
59919
+ * @returns The Operation in the GraphQL document we should use for the current call.
59920
+ */
59921
+ function getOperationFromDocument(document, operationName) {
59922
+ const operations = document.definitions.filter((def) => def.kind === 'OperationDefinition');
59923
+ if (operationName) {
59924
+ return operations.find((def) => def.name !== undefined && def.name.value === operationName);
59925
+ }
59926
+ return operations[0]; // If a named operation is not provided, we return the first one
59927
+ }
59928
+
59912
59929
  /**
59913
59930
  * Copyright (c) 2022, Salesforce, Inc.,
59914
59931
  * All rights reserved.
@@ -79320,43 +79337,38 @@
79320
79337
  const TTL = 900000;
79321
79338
  const VERSION$6 = "b440235e7e724631f92002fe50e3e096";
79322
79339
  const RepresentationType = 'GraphQLRepresentation';
79323
- function select$8(luvio, query, variables) {
79324
- const definitions = query.definitions === undefined ? [] : query.definitions;
79340
+ function select$8(luvio, document, variables, operationName) {
79341
+ const operationToExecute = getOperationFromDocument(document, operationName);
79325
79342
  return {
79326
79343
  kind: 'Fragment',
79327
79344
  synthetic: true,
79328
79345
  reader: true,
79329
79346
  read: (builder) => {
79330
79347
  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
79348
  const gqlData = {};
79359
- builder.assignNonScalar(gqlData, 'data', sink);
79349
+ if (operationToExecute === undefined) {
79350
+ builder.markMissing(); // Never give a cache hit for an undefined operation
79351
+ return gqlData;
79352
+ }
79353
+ const fragments = createFragmentMap(document);
79354
+ const queryTypeRecordId = keyBuilder$4(luvio, operationToExecute, variables, fragments);
79355
+ const snapshot = builder.read({
79356
+ recordId: queryTypeRecordId,
79357
+ node: {
79358
+ kind: 'Fragment',
79359
+ private: [],
79360
+ opaque: true,
79361
+ version: VERSION$7
79362
+ },
79363
+ variables: {}
79364
+ });
79365
+ if (snapshot.data === undefined) {
79366
+ builder.markMissingLink(queryTypeRecordId);
79367
+ }
79368
+ else {
79369
+ const data = select$9(operationToExecute, variables, fragments)(snapshot.data, builder, queryTypeRecordId);
79370
+ builder.assignNonScalar(gqlData, 'data', data);
79371
+ }
79360
79372
  builder.exitPath();
79361
79373
  return gqlData;
79362
79374
  }
@@ -79376,10 +79388,10 @@
79376
79388
  });
79377
79389
  }
79378
79390
  }
79379
- const ingest = function GraphQLRepresentationIngest(query, variables) {
79391
+ const ingest = function GraphQLRepresentationIngest(document, variables, operationName) {
79380
79392
  return (input, path, luvio, store, timestamp) => {
79381
79393
  if (input.data) {
79382
- const fragments = createFragmentMap(query);
79394
+ const fragments = createFragmentMap(document);
79383
79395
  const state = {
79384
79396
  data: input.data,
79385
79397
  luvio,
@@ -79389,44 +79401,42 @@
79389
79401
  variables,
79390
79402
  fragments,
79391
79403
  };
79392
- query.definitions.forEach((node) => {
79393
- if (node.kind === 'OperationDefinition') {
79394
- ingestOperationNode(luvio, input, node, state);
79395
- }
79396
- });
79404
+ const operationToExecute = getOperationFromDocument(document, operationName);
79405
+ if (operationToExecute !== undefined) {
79406
+ ingestOperationNode(luvio, input, operationToExecute, state);
79407
+ }
79397
79408
  }
79398
79409
  return {
79399
79410
  __ref: undefined
79400
79411
  };
79401
79412
  };
79402
79413
  };
79403
- function getTypeCacheKeys(luvio, query, variables, data) {
79414
+ function getTypeCacheKeys(luvio, document, variables, data, operationName) {
79404
79415
  const sink = new StoreKeyMap();
79405
79416
  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
- });
79417
+ const fragments = createFragmentMap(document);
79418
+ const operationToExecute = getOperationFromDocument(document, operationName);
79419
+ if (operationToExecute !== undefined) {
79420
+ const state = {
79421
+ luvio,
79422
+ variables,
79423
+ fragments,
79424
+ data: data.data,
79425
+ path: {
79426
+ parent: null,
79427
+ propertyName: null,
79428
+ fullPath: '' // TODO: W-13079691 - Need to take another pass at what we want to do for structured keys
79429
+ }
79430
+ };
79431
+ sink.merge(getTypeCacheKeys$1(operationToExecute, state));
79432
+ }
79423
79433
  }
79424
79434
  return sink;
79425
79435
  }
79426
79436
 
79427
79437
  function select$7(luvio, config) {
79428
- const { query, variables } = config;
79429
- return select$8(luvio, query, variables);
79438
+ const { query, variables, operationName } = config;
79439
+ return select$8(luvio, query, variables, operationName);
79430
79440
  }
79431
79441
  function keyBuilder$3(luvio, params) {
79432
79442
  return keyPrefix + '::' + 'GraphQLRepresentation';
@@ -79434,13 +79444,14 @@
79434
79444
  function getResponseCacheKeys$1(luvio, resourceParams, response) {
79435
79445
  const query = resourceParams.body.query;
79436
79446
  const variables = resourceParams.body.variables || {};
79437
- return getTypeCacheKeys(luvio, query, variables, response);
79447
+ const operationName = resourceParams.body.operationName;
79448
+ return getTypeCacheKeys(luvio, query, variables, response, operationName);
79438
79449
  }
79439
79450
  function ingestSuccess$1(luvio, config, resourceParams, response, snapshotRefresh) {
79440
79451
  const { body } = response;
79441
79452
  const key = keyBuilder$3();
79442
- const { query, variables } = resourceParams.body;
79443
- luvio.storeIngest(key, ingest(query, variables), body);
79453
+ const { query, variables, operationName } = resourceParams.body;
79454
+ luvio.storeIngest(key, ingest(query, variables, operationName), body);
79444
79455
  // 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
79456
  // see optimizePagination for initial update to optimize the query
79446
79457
  revertPaginationOptimization(variables);
@@ -80626,7 +80637,7 @@
80626
80637
  configuration: { ...configurationForGraphQLAdapters },
80627
80638
  instrument,
80628
80639
  });
80629
- // version: 1.142.0-9f43a65a3
80640
+ // version: 1.142.1-1511d83f4
80630
80641
 
80631
80642
  // On core the unstable adapters are re-exported with different names,
80632
80643
 
@@ -82858,7 +82869,7 @@
82858
82869
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
82859
82870
  graphQLImperative = ldsAdapter;
82860
82871
  });
82861
- // version: 1.142.0-9f43a65a3
82872
+ // version: 1.142.1-1511d83f4
82862
82873
 
82863
82874
  var gqlApi = /*#__PURE__*/Object.freeze({
82864
82875
  __proto__: null,
@@ -83564,4 +83575,4 @@
83564
83575
  Object.defineProperty(exports, '__esModule', { value: true });
83565
83576
 
83566
83577
  }));
83567
- // version: 1.142.0-7730e2a14
83578
+ // version: 1.142.1-d514db71e
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.142.1",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "",
6
6
  "main": "dist/standalone/es/lds-worker-api.js",