@salesforce/lds-runtime-mobile 1.142.1 → 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.
package/dist/main.js CHANGED
@@ -27,6 +27,9 @@ import shortTimeFormat from '@salesforce/i18n/dateTime.shortTimeFormat';
27
27
  import shortDateTimeFormat from '@salesforce/i18n/dateTime.shortDateTimeFormat';
28
28
  import { getDateTimeFormat, getDateTimeISO8601Parser, getNumberFormat } from 'lightning/i18nService';
29
29
  import formattingOptions from 'lightning/i18nCldrOptions';
30
+ import eagerEvalValidAt from '@salesforce/gate/lds.eagerEvalValidAt';
31
+ import eagerEvalStaleWhileRevalidate from '@salesforce/gate/lds.eagerEvalStaleWhileRevalidate';
32
+ import eagerEvalDefaultCachePolicy from '@salesforce/gate/lds.eagerEvalDefaultCachePolicy';
30
33
 
31
34
  /**
32
35
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -877,7 +880,7 @@ async function reviveOrCreateContext(adapterId, durableStore, durableStoreErrorH
877
880
  }
878
881
  return contextReturn();
879
882
  }
880
- function isUnfulfilledSnapshot(cachedSnapshotResult) {
883
+ function isUnfulfilledSnapshot$1(cachedSnapshotResult) {
881
884
  if (cachedSnapshotResult === undefined) {
882
885
  return false;
883
886
  }
@@ -1161,7 +1164,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
1161
1164
  const snapshot = buildCachedSnapshot(injectedBuildSnapshotContext, injectedStoreLookup, luvio);
1162
1165
  // if the adapter attempted to do an L1 lookup and it was unfulfilled
1163
1166
  // then we can attempt an L2 lookup
1164
- if (isUnfulfilledSnapshot(snapshot)) {
1167
+ if (isUnfulfilledSnapshot$1(snapshot)) {
1165
1168
  const start = Date.now();
1166
1169
  emitDurableEnvironmentAdapterEvent({ type: 'l2-revive-start' }, adapterRequestContext.eventObservers);
1167
1170
  const revivedSnapshot = reviveSnapshot(environment, durableStore, snapshot, durableStoreErrorHandler, () => injectedStoreLookup(snapshot.select, snapshot.refresh)).then((result) => {
@@ -12533,6 +12536,7 @@ function draftAwareGraphQLAdapterFactory(userId, objectInfoService, store, luvio
12533
12536
  query: injectedAST,
12534
12537
  },
12535
12538
  luvio,
12539
+ gqlEval: true,
12536
12540
  }, buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy));
12537
12541
  if (isErrorSnapshotThatShouldGetReturnedToCaller(nonEvaluatedSnapshot)) {
12538
12542
  return nonEvaluatedSnapshot;
@@ -15114,8 +15118,17 @@ function formatDisplayValue(value, datatype) {
15114
15118
  }
15115
15119
  }
15116
15120
 
15117
- //TODO: [W-12734162] - rebuild non-evaluated snapshot when graph rebuild is triggered. The dependency work on luvio needs to be done.
15121
+ function isUnfulfilledSnapshot(cachedSnapshotResult) {
15122
+ if (cachedSnapshotResult === undefined) {
15123
+ return false;
15124
+ }
15125
+ if ('then' in cachedSnapshotResult) {
15126
+ return false;
15127
+ }
15128
+ return cachedSnapshotResult.state === 'Unfulfilled';
15129
+ }
15118
15130
  function makeEnvironmentGraphqlAware(environment) {
15131
+ //TODO: [W-12734162] - rebuild non-evaluated snapshot when graph rebuild is triggered. The dependency work on luvio needs to be done.
15119
15132
  const rebuildSnapshot = function (snapshot, onRebuild) {
15120
15133
  if (isStoreEvalSnapshot(snapshot)) {
15121
15134
  snapshot.rebuildWithStoreEval(snapshot).then((rebuilt) => {
@@ -15131,8 +15144,64 @@ function makeEnvironmentGraphqlAware(environment) {
15131
15144
  }
15132
15145
  return environment.rebuildSnapshot(snapshot, onRebuild);
15133
15146
  };
15147
+ const applyCachePolicy = function (luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot) {
15148
+ // Early exit for non-evaluating adapters
15149
+ let graphqlBuildSnapshotContext = buildSnapshotContext;
15150
+ if (graphqlBuildSnapshotContext.gqlEval !== true) {
15151
+ return environment.applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot);
15152
+ }
15153
+ var localBuildCachedSnapshot = buildCachedSnapshot;
15154
+ const hoistUnfulfilledToStale = (context, storeLookup, luvio) => {
15155
+ const upstream = buildCachedSnapshot(context, storeLookup, luvio);
15156
+ if (upstream === undefined)
15157
+ return upstream;
15158
+ if (isUnfulfilledSnapshot(upstream)) {
15159
+ return {
15160
+ ...upstream,
15161
+ data: upstream.data || {},
15162
+ state: 'Stale',
15163
+ };
15164
+ }
15165
+ else if ('then' in upstream) {
15166
+ return upstream.then((snapshot) => {
15167
+ if (snapshot === undefined)
15168
+ return snapshot;
15169
+ if (isUnfulfilledSnapshot(snapshot)) {
15170
+ return {
15171
+ ...snapshot,
15172
+ data: snapshot.data || {},
15173
+ state: 'Stale',
15174
+ };
15175
+ }
15176
+ return snapshot;
15177
+ });
15178
+ }
15179
+ return upstream;
15180
+ };
15181
+ const { cachePolicy } = adapterRequestContext;
15182
+ if (eagerEvalValidAt.isOpen({ fallback: false }) &&
15183
+ cachePolicy &&
15184
+ cachePolicy.type === 'valid-at' &&
15185
+ cachePolicy.timestamp === 0 &&
15186
+ cachePolicy.basePolicy &&
15187
+ cachePolicy.basePolicy.type === 'stale-while-revalidate') {
15188
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
15189
+ }
15190
+ if (eagerEvalStaleWhileRevalidate.isOpen({ fallback: false }) &&
15191
+ cachePolicy &&
15192
+ cachePolicy.type === 'stale-while-revalidate' &&
15193
+ cachePolicy.staleDurationSeconds === Number.MAX_SAFE_INTEGER) {
15194
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
15195
+ }
15196
+ if (eagerEvalDefaultCachePolicy.isOpen({ fallback: false }) && cachePolicy === undefined) {
15197
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
15198
+ }
15199
+ return environment.applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, localBuildCachedSnapshot, buildNetworkSnapshot);
15200
+ };
15134
15201
  return create(environment, {
15135
15202
  rebuildSnapshot: { value: rebuildSnapshot },
15203
+ applyCachePolicy: { value: applyCachePolicy },
15204
+ setDefaultCachePolicy: { value: environment.setDefaultCachePolicy.bind(environment) },
15136
15205
  });
15137
15206
  }
15138
15207
 
@@ -15885,4 +15954,4 @@ register({
15885
15954
  });
15886
15955
 
15887
15956
  export { getRuntime, registerReportObserver, reportGraphqlQueryParseError };
15888
- // version: 1.142.1-d514db71e
15957
+ // version: 1.143.0-a6d2a998d
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-mobile",
3
- "version": "1.142.1",
3
+ "version": "1.143.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS runtime for mobile/hybrid environments.",
6
6
  "main": "dist/main.js",
package/sfdc/main.js CHANGED
@@ -27,6 +27,9 @@ import shortTimeFormat from '@salesforce/i18n/dateTime.shortTimeFormat';
27
27
  import shortDateTimeFormat from '@salesforce/i18n/dateTime.shortDateTimeFormat';
28
28
  import { getDateTimeFormat, getDateTimeISO8601Parser, getNumberFormat } from 'lightning/i18nService';
29
29
  import formattingOptions from 'lightning/i18nCldrOptions';
30
+ import eagerEvalValidAt from '@salesforce/gate/lds.eagerEvalValidAt';
31
+ import eagerEvalStaleWhileRevalidate from '@salesforce/gate/lds.eagerEvalStaleWhileRevalidate';
32
+ import eagerEvalDefaultCachePolicy from '@salesforce/gate/lds.eagerEvalDefaultCachePolicy';
30
33
 
31
34
  /**
32
35
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -877,7 +880,7 @@ async function reviveOrCreateContext(adapterId, durableStore, durableStoreErrorH
877
880
  }
878
881
  return contextReturn();
879
882
  }
880
- function isUnfulfilledSnapshot(cachedSnapshotResult) {
883
+ function isUnfulfilledSnapshot$1(cachedSnapshotResult) {
881
884
  if (cachedSnapshotResult === undefined) {
882
885
  return false;
883
886
  }
@@ -1161,7 +1164,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
1161
1164
  const snapshot = buildCachedSnapshot(injectedBuildSnapshotContext, injectedStoreLookup, luvio);
1162
1165
  // if the adapter attempted to do an L1 lookup and it was unfulfilled
1163
1166
  // then we can attempt an L2 lookup
1164
- if (isUnfulfilledSnapshot(snapshot)) {
1167
+ if (isUnfulfilledSnapshot$1(snapshot)) {
1165
1168
  const start = Date.now();
1166
1169
  emitDurableEnvironmentAdapterEvent({ type: 'l2-revive-start' }, adapterRequestContext.eventObservers);
1167
1170
  const revivedSnapshot = reviveSnapshot(environment, durableStore, snapshot, durableStoreErrorHandler, () => injectedStoreLookup(snapshot.select, snapshot.refresh)).then((result) => {
@@ -12533,6 +12536,7 @@ function draftAwareGraphQLAdapterFactory(userId, objectInfoService, store, luvio
12533
12536
  query: injectedAST,
12534
12537
  },
12535
12538
  luvio,
12539
+ gqlEval: true,
12536
12540
  }, buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy));
12537
12541
  if (isErrorSnapshotThatShouldGetReturnedToCaller(nonEvaluatedSnapshot)) {
12538
12542
  return nonEvaluatedSnapshot;
@@ -15114,8 +15118,17 @@ function formatDisplayValue(value, datatype) {
15114
15118
  }
15115
15119
  }
15116
15120
 
15117
- //TODO: [W-12734162] - rebuild non-evaluated snapshot when graph rebuild is triggered. The dependency work on luvio needs to be done.
15121
+ function isUnfulfilledSnapshot(cachedSnapshotResult) {
15122
+ if (cachedSnapshotResult === undefined) {
15123
+ return false;
15124
+ }
15125
+ if ('then' in cachedSnapshotResult) {
15126
+ return false;
15127
+ }
15128
+ return cachedSnapshotResult.state === 'Unfulfilled';
15129
+ }
15118
15130
  function makeEnvironmentGraphqlAware(environment) {
15131
+ //TODO: [W-12734162] - rebuild non-evaluated snapshot when graph rebuild is triggered. The dependency work on luvio needs to be done.
15119
15132
  const rebuildSnapshot = function (snapshot, onRebuild) {
15120
15133
  if (isStoreEvalSnapshot(snapshot)) {
15121
15134
  snapshot.rebuildWithStoreEval(snapshot).then((rebuilt) => {
@@ -15131,8 +15144,64 @@ function makeEnvironmentGraphqlAware(environment) {
15131
15144
  }
15132
15145
  return environment.rebuildSnapshot(snapshot, onRebuild);
15133
15146
  };
15147
+ const applyCachePolicy = function (luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot) {
15148
+ // Early exit for non-evaluating adapters
15149
+ let graphqlBuildSnapshotContext = buildSnapshotContext;
15150
+ if (graphqlBuildSnapshotContext.gqlEval !== true) {
15151
+ return environment.applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot);
15152
+ }
15153
+ var localBuildCachedSnapshot = buildCachedSnapshot;
15154
+ const hoistUnfulfilledToStale = (context, storeLookup, luvio) => {
15155
+ const upstream = buildCachedSnapshot(context, storeLookup, luvio);
15156
+ if (upstream === undefined)
15157
+ return upstream;
15158
+ if (isUnfulfilledSnapshot(upstream)) {
15159
+ return {
15160
+ ...upstream,
15161
+ data: upstream.data || {},
15162
+ state: 'Stale',
15163
+ };
15164
+ }
15165
+ else if ('then' in upstream) {
15166
+ return upstream.then((snapshot) => {
15167
+ if (snapshot === undefined)
15168
+ return snapshot;
15169
+ if (isUnfulfilledSnapshot(snapshot)) {
15170
+ return {
15171
+ ...snapshot,
15172
+ data: snapshot.data || {},
15173
+ state: 'Stale',
15174
+ };
15175
+ }
15176
+ return snapshot;
15177
+ });
15178
+ }
15179
+ return upstream;
15180
+ };
15181
+ const { cachePolicy } = adapterRequestContext;
15182
+ if (eagerEvalValidAt.isOpen({ fallback: false }) &&
15183
+ cachePolicy &&
15184
+ cachePolicy.type === 'valid-at' &&
15185
+ cachePolicy.timestamp === 0 &&
15186
+ cachePolicy.basePolicy &&
15187
+ cachePolicy.basePolicy.type === 'stale-while-revalidate') {
15188
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
15189
+ }
15190
+ if (eagerEvalStaleWhileRevalidate.isOpen({ fallback: false }) &&
15191
+ cachePolicy &&
15192
+ cachePolicy.type === 'stale-while-revalidate' &&
15193
+ cachePolicy.staleDurationSeconds === Number.MAX_SAFE_INTEGER) {
15194
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
15195
+ }
15196
+ if (eagerEvalDefaultCachePolicy.isOpen({ fallback: false }) && cachePolicy === undefined) {
15197
+ localBuildCachedSnapshot = hoistUnfulfilledToStale;
15198
+ }
15199
+ return environment.applyCachePolicy(luvio, adapterRequestContext, buildSnapshotContext, localBuildCachedSnapshot, buildNetworkSnapshot);
15200
+ };
15134
15201
  return create(environment, {
15135
15202
  rebuildSnapshot: { value: rebuildSnapshot },
15203
+ applyCachePolicy: { value: applyCachePolicy },
15204
+ setDefaultCachePolicy: { value: environment.setDefaultCachePolicy.bind(environment) },
15136
15205
  });
15137
15206
  }
15138
15207
 
@@ -15885,4 +15954,4 @@ register({
15885
15954
  });
15886
15955
 
15887
15956
  export { getRuntime, registerReportObserver, reportGraphqlQueryParseError };
15888
- // version: 1.142.1-d514db71e
15957
+ // version: 1.143.0-a6d2a998d