@salesforce/lds-runtime-bridge 1.287.0-dev15 → 1.287.0-dev17

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.
@@ -1075,6 +1075,32 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
1075
1075
  }, revivingStore).finally(() => {
1076
1076
  });
1077
1077
  };
1078
+ const expirePossibleStaleRecords = async function (keys$1, config, refresh) {
1079
+ validateNotDisposed();
1080
+ const metadataKeys = keys$1.map(serializeStructuredKey);
1081
+ const now = Date.now();
1082
+ const entries = await durableStore.getMetadata(metadataKeys, DefaultDurableSegment);
1083
+ if (entries === undefined || keys$3(entries).length === 0) {
1084
+ return environment.expirePossibleStaleRecords(keys$1);
1085
+ }
1086
+ let metaDataChanged = false;
1087
+ const metadataEntries = metadataKeys.reduce((accu, key) => {
1088
+ const metadataEntry = entries[key];
1089
+ if (metadataEntry.metadata !== undefined) {
1090
+ const metadata = { ...metadataEntry.metadata, expirationTimestamp: now };
1091
+ accu[key] = { metadata };
1092
+ metaDataChanged = true;
1093
+ }
1094
+ return accu;
1095
+ }, {});
1096
+ if (metaDataChanged) {
1097
+ await durableStore.setMetadata(metadataEntries, DefaultDurableSegment);
1098
+ }
1099
+ if (config !== undefined && refresh !== undefined) {
1100
+ return environment.refreshPossibleStaleRecords(config, refresh);
1101
+ }
1102
+ return Promise.resolve();
1103
+ };
1078
1104
  // set the default cache policy of the base environment
1079
1105
  environment.setDefaultCachePolicy({
1080
1106
  type: 'stale-while-revalidate',
@@ -1107,6 +1133,7 @@ function makeDurable(environment, { durableStore, instrumentation, useRevivingSt
1107
1133
  handleErrorResponse: { value: handleErrorResponse },
1108
1134
  getNotifyChangeStoreEntries: { value: getNotifyChangeStoreEntries },
1109
1135
  notifyStoreUpdateAvailable: { value: notifyStoreUpdateAvailable },
1136
+ expirePossibleStaleRecords: { value: expirePossibleStaleRecords },
1110
1137
  });
1111
1138
  }
1112
1139
 
@@ -2369,7 +2396,6 @@ function isTodayStartOfWeek() {
2369
2396
 
2370
2397
  const JSON_EXTRACT_PATH_INGESTION_TIMESTAMP = '$.ingestionTimestamp';
2371
2398
  const JSON_EXTRACT_PATH_INGESTION_APINAME = '$.apiName';
2372
- const JSON_EXTRACT_PATH_DRAFTS = '$.drafts';
2373
2399
 
2374
2400
  const MultiPickListValueSeparator = ';';
2375
2401
  function filterToPredicates(where, recordType, alias, objectInfoMap, joins, draftFunctions) {
@@ -2899,18 +2925,11 @@ function buildQuery(config) {
2899
2925
  const joins = buildJoins(config);
2900
2926
  const predicates = buildPredicates(config);
2901
2927
  const orderBy = buildOrderBy(config);
2902
- const staleRecordsSql = excludeStaleRecordsGate.isOpen({ fallback: false })
2903
- ? `AND (
2904
- json_extract("${config.alias}".metadata, '${JSON_EXTRACT_PATH_INGESTION_TIMESTAMP}') >= ?
2905
- OR json_extract("${config.alias}".data, '${JSON_EXTRACT_PATH_DRAFTS}') IS NOT NULL
2906
- )`
2907
- : '';
2908
2928
  const sql = `
2909
- SELECT "${config.alias}".data
2929
+ SELECT "${config.alias}".data, "${config.alias}".metadata
2910
2930
  FROM lds_data "${config.alias}" ${joins.sql}
2911
2931
  WHERE "${config.alias}".key like 'UiApi::RecordRepresentation:%'
2912
2932
  AND json_extract("${config.alias}".data, '${JSON_EXTRACT_PATH_INGESTION_APINAME}') = '${config.alias}'
2913
- ${staleRecordsSql}
2914
2933
  ${predicates.sql}
2915
2934
  ${orderBy.sql}
2916
2935
  LIMIT ?
@@ -2921,7 +2940,6 @@ function buildQuery(config) {
2921
2940
  const bindings = [
2922
2941
  // bindings from predicates on joins
2923
2942
  ...joins.bindings,
2924
- ...(excludeStaleRecordsGate.isOpen({ fallback: false }) ? [config.ingestionTimestamp] : []),
2925
2943
  // where clause and parent scope bindings
2926
2944
  ...predicates.bindings,
2927
2945
  // limit binding
@@ -2947,33 +2965,19 @@ function buildJoins(config) {
2947
2965
  if (allJoins.length === 0)
2948
2966
  return { sql, bindings };
2949
2967
  sql = allJoins.reduce((joinAccumulator, join) => {
2950
- let timestampAdded = false;
2951
2968
  const joinConditions = join.conditions.reduce((conditionAccumulator, condition) => {
2952
2969
  let joined_sql;
2953
- const joinMetadataTimestamp = excludeStaleRecordsGate.isOpen({ fallback: false })
2954
- ? ` AND (json_extract("${join.alias}".metadata, '${JSON_EXTRACT_PATH_INGESTION_TIMESTAMP}') >= ? OR json_extract("${join.alias}".data, '${JSON_EXTRACT_PATH_DRAFTS}') IS NOT NULL)`
2955
- : '';
2956
2970
  // predicate on a value, use the newly joined table
2957
2971
  if ('type' in condition) {
2958
2972
  const { sql, binding } = predicateToSQL(condition, join.alias);
2959
- joined_sql = ` AND ${sql}${timestampAdded ? '' : joinMetadataTimestamp}`;
2973
+ joined_sql = ` AND ${sql}`;
2960
2974
  bindings.push(...binding);
2961
- if (excludeStaleRecordsGate.isOpen({ fallback: false }) &&
2962
- timestampAdded === false) {
2963
- bindings.push(config.ingestionTimestamp);
2964
- timestampAdded = true;
2965
- }
2966
2975
  }
2967
2976
  else {
2968
2977
  // predicate on a path
2969
2978
  const left = ` AND json_extract("${join.to}".data, '${condition.leftPath}')`;
2970
2979
  const right = `json_extract("${join.alias}".data, '${condition.rightPath}')`;
2971
- joined_sql = `${left} = ${right}${timestampAdded ? '' : joinMetadataTimestamp}`;
2972
- if (excludeStaleRecordsGate.isOpen({ fallback: false }) &&
2973
- timestampAdded === false) {
2974
- bindings.push(config.ingestionTimestamp);
2975
- timestampAdded = true;
2976
- }
2980
+ joined_sql = `${left} = ${right}`;
2977
2981
  }
2978
2982
  conditionAccumulator += joined_sql;
2979
2983
  return conditionAccumulator;
@@ -3345,8 +3349,7 @@ function addResolversToSchema(schema, polyFields) {
3345
3349
  for (const field of fields) {
3346
3350
  if (field.name === 'node') {
3347
3351
  field.resolve = function nodeResolver(obj, _args, { seenRecordIds }) {
3348
- const { record, ingestionTimestamp } = obj;
3349
- const recordRepresentation = parse(record);
3352
+ const { recordRepresentation, ingestionTimestamp } = obj;
3350
3353
  seenRecordIds.add(recordRepresentation.id);
3351
3354
  return { recordRepresentation, ingestionTimestamp };
3352
3355
  };
@@ -3560,16 +3563,30 @@ async function connectionEdgeResolver(obj, _args, context) {
3560
3563
  predicates,
3561
3564
  orderBy: orderByToPredicate(parentArgs.orderBy, alias, alias, context.objectInfos),
3562
3565
  limit: parentArgs.first,
3563
- ingestionTimestamp,
3564
3566
  };
3565
3567
  const { sql, bindings } = buildQuery(queryConfig);
3566
3568
  const results = await query(sql, bindings);
3567
3569
  //map each sql result with the ingestion timestamp to pass it down a level
3568
- return results.rows
3569
- .map((row) => row[0])
3570
- .map((record) => {
3570
+ return results.rows.map((row) => {
3571
+ const recordMetadataResult = {
3572
+ recordRepresentation: parse(row[0]),
3573
+ metadata: parse(row[1]),
3574
+ };
3575
+ const { recordRepresentation, metadata } = recordMetadataResult;
3576
+ context.seenRecordIds.add(recordRepresentation.id);
3577
+ if (metadata.ingestionTimestamp < ingestionTimestamp &&
3578
+ recordRepresentation.drafts === undefined) {
3579
+ if (context.possibleStaleRecordMap.has(recordRepresentation.apiName) === false) {
3580
+ context.possibleStaleRecordMap.set(recordRepresentation.apiName, []);
3581
+ }
3582
+ const ids = context.possibleStaleRecordMap.get(recordRepresentation.apiName);
3583
+ if (ids !== undefined) {
3584
+ ids.push(recordRepresentation.id);
3585
+ context.possibleStaleRecordMap.set(recordRepresentation.apiName, ids);
3586
+ }
3587
+ }
3571
3588
  return {
3572
- record,
3589
+ recordRepresentation,
3573
3590
  ingestionTimestamp,
3574
3591
  };
3575
3592
  });
@@ -4147,4 +4164,4 @@ function ldsRuntimeBridge() {
4147
4164
  }
4148
4165
 
4149
4166
  export { ldsRuntimeBridge as default };
4150
- // version: 1.287.0-dev15-a292df40d2
4167
+ // version: 1.287.0-dev17-670374cbf3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-bridge",
3
- "version": "1.287.0-dev15",
3
+ "version": "1.287.0-dev17",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS runtime for bridge.app.",
6
6
  "main": "dist/ldsRuntimeBridge.js",
@@ -34,17 +34,17 @@
34
34
  "release:corejar": "yarn build && ../core-build/scripts/core.js --name=lds-runtime-bridge"
35
35
  },
36
36
  "dependencies": {
37
- "@salesforce/lds-adapters-uiapi": "^1.287.0-dev15",
38
- "@salesforce/lds-instrumentation": "^1.287.0-dev15",
37
+ "@salesforce/lds-adapters-uiapi": "^1.287.0-dev17",
38
+ "@salesforce/lds-instrumentation": "^1.287.0-dev17",
39
39
  "@salesforce/user": "0.0.21",
40
40
  "o11y": "250.7.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@salesforce/lds-drafts-adapters-uiapi": "^1.287.0-dev15",
44
- "@salesforce/lds-network-aura": "^1.287.0-dev15",
45
- "@salesforce/lds-runtime-aura": "^1.287.0-dev15",
46
- "@salesforce/lds-store-nimbus": "^1.287.0-dev15",
47
- "@salesforce/nimbus-plugin-lds": "^1.287.0-dev15",
43
+ "@salesforce/lds-drafts-adapters-uiapi": "^1.287.0-dev17",
44
+ "@salesforce/lds-network-aura": "^1.287.0-dev17",
45
+ "@salesforce/lds-runtime-aura": "^1.287.0-dev17",
46
+ "@salesforce/lds-store-nimbus": "^1.287.0-dev17",
47
+ "@salesforce/nimbus-plugin-lds": "^1.287.0-dev17",
48
48
  "babel-plugin-dynamic-import-node": "^2.3.3"
49
49
  },
50
50
  "luvioBundlesize": [