@salesforce/lds-runtime-aura 1.344.0 → 1.346.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.
Files changed (2) hide show
  1. package/dist/ldsEngineCreator.js +253 -24
  2. package/package.json +30 -29
@@ -73,7 +73,7 @@ class NetworkCommand extends BaseCommand {
73
73
  return this.fetch();
74
74
  }
75
75
  }
76
- function buildServiceDescriptor$a() {
76
+ function buildServiceDescriptor$b() {
77
77
  return {
78
78
  type: 'networkCommandBaseClass',
79
79
  version: '1.0',
@@ -219,6 +219,54 @@ function rejectedPromiseLike(reason) {
219
219
  function isPromiseLike(x) {
220
220
  return typeof x === 'object' && typeof (x === null || x === void 0 ? void 0 : x.then) === 'function';
221
221
  }
222
+
223
+ /**
224
+ * Recursively compares two values and indicates if they are equal.
225
+ *
226
+ * @param x first value
227
+ * @param y second value
228
+ * @returns true if x and y are recursively equal to each other; false if not
229
+ */
230
+ function deepEquals$1(x, y) {
231
+ if (x === undefined) {
232
+ return y === undefined;
233
+ }
234
+ else if (x === null) {
235
+ return y === null;
236
+ }
237
+ else if (y === null) {
238
+ return x === null;
239
+ }
240
+ else if (isArray$2(x)) {
241
+ if (!isArray$2(y) || x.length !== y.length) {
242
+ return false;
243
+ }
244
+ for (let i = 0; i < x.length; ++i) {
245
+ if (!deepEquals$1(x[i], y[i])) {
246
+ return false;
247
+ }
248
+ }
249
+ return true;
250
+ }
251
+ else if (typeof x === 'object') {
252
+ if (typeof y !== 'object') {
253
+ return false;
254
+ }
255
+ const xkeys = Object.keys(x);
256
+ const ykeys = Object.keys(y);
257
+ if (xkeys.length !== ykeys.length) {
258
+ return false;
259
+ }
260
+ for (let i = 0; i < xkeys.length; ++i) {
261
+ const key = xkeys[i];
262
+ if (!deepEquals$1(x[key], y[key])) {
263
+ return false;
264
+ }
265
+ }
266
+ return true;
267
+ }
268
+ return x === y;
269
+ }
222
270
  /**
223
271
  * A deterministic JSON stringify implementation. Heavily adapted from https://github.com/epoberezkin/fast-json-stable-stringify.
224
272
  * This is needed because insertion order for JSON.stringify(object) affects output:
@@ -354,7 +402,7 @@ class AuraNetworkCommand extends NetworkCommand {
354
402
  }
355
403
  }
356
404
 
357
- function buildServiceDescriptor$9() {
405
+ function buildServiceDescriptor$a() {
358
406
  return {
359
407
  type: 'auraNetworkCommandBaseClass',
360
408
  version: '1.0',
@@ -380,17 +428,107 @@ class CacheControlCommand extends BaseCommand {
380
428
  constructor(services) {
381
429
  super();
382
430
  this.services = services;
431
+ this.keyUnsubscribe = () => { };
432
+ this.subscriptions = [];
383
433
  }
384
434
  execute() {
385
- return this.services.cacheController.execute(this.cacheControlStrategyConfig, (cache) => this.buildRequestRunner(cache));
435
+ this.keyUnsubscribe();
436
+ const resultPromise = this.services.cacheController.execute(this.cacheControlStrategyConfig, (cache) => this.buildRequestRunner(cache));
437
+ return resultPromise;
438
+ }
439
+ // TODO: This should likely be abstract in v2. For v1, provide default comparison logic.
440
+ equals(result1, result2) {
441
+ return deepEquals$1(result1, result2);
386
442
  }
387
443
  buildRequestRunner(cache) {
388
444
  return {
389
- readFromCache: () => this.readFromCache(cache),
445
+ readFromCache: () => this.buildResultWithSubscribe(cache),
390
446
  requestFromNetwork: () => this.requestFromNetwork(),
391
- writeToCache: (networkResult) => this.writeToCache(cache, networkResult),
447
+ writeToCache: (networkResult) => this.writeToCacheAndPublish(cache, networkResult),
392
448
  };
393
449
  }
450
+ // TODO: This is added as a temporary measure for ensuring that cache write events are
451
+ // published to pubSub. A follow-up will be required to find the right home for this logic.
452
+ writeToCacheAndPublish(cache, networkResult) {
453
+ const recordableCache = cache.record();
454
+ const writeResult = this.writeToCache(recordableCache, networkResult);
455
+ if (this.services.pubSub) {
456
+ this.services.pubSub.publish({
457
+ type: 'cacheUpdate',
458
+ data: recordableCache.keysUpdated,
459
+ });
460
+ }
461
+ return writeResult;
462
+ }
463
+ buildResultWithSubscribe(cache) {
464
+ const recordableCache = cache.record();
465
+ const result = this.readFromCache(recordableCache);
466
+ return result.then((readResult) => {
467
+ if (readResult.isErr()) {
468
+ return err(readResult.error);
469
+ }
470
+ else {
471
+ const data = readResult.value;
472
+ if (data !== undefined) {
473
+ this.subscribeToKeys(recordableCache.keysRead, data);
474
+ return ok({
475
+ data,
476
+ subscribe: this.buildSubscribe(),
477
+ });
478
+ }
479
+ return ok(undefined);
480
+ }
481
+ });
482
+ }
483
+ /**
484
+ * Builds a function that subscribes to cache changes via the pubsub service. Whenever
485
+ * relevant cache updates occur, it re-reads the data and compares it against
486
+ * the last known value. If a change is detected, the provided
487
+ * callback is invoked.
488
+ *
489
+ * @param keysRead - keys of interest that were read during readFromCache
490
+ * @returns an unsubscribe function to stop watching for updates
491
+ */
492
+ buildSubscribe() {
493
+ return (consumerCallback) => {
494
+ this.subscriptions.push(consumerCallback);
495
+ return () => {
496
+ this.subscriptions = this.subscriptions.filter((cb) => cb !== consumerCallback);
497
+ };
498
+ };
499
+ }
500
+ subscribeToKeys(keysRead, lastResult) {
501
+ if (this.services.pubSub === undefined) {
502
+ return;
503
+ }
504
+ this.keyUnsubscribe = this.services.pubSub.subscribe({
505
+ type: 'cacheUpdate',
506
+ predicate: (event) => event.data.overlaps(keysRead),
507
+ callback: () => keyChangedCallback(),
508
+ });
509
+ const keyChangedCallback = () => {
510
+ const newResultPromise = this.execute();
511
+ return newResultPromise.then((result) => {
512
+ if (result.isErr()) {
513
+ this.invokeConsumerCallbacks(result);
514
+ return;
515
+ }
516
+ if (!this.equals(lastResult, result.value.data)) {
517
+ this.invokeConsumerCallbacks(ok(result.value.data));
518
+ }
519
+ });
520
+ };
521
+ }
522
+ invokeConsumerCallbacks(data) {
523
+ this.subscriptions.forEach((cb) => {
524
+ try {
525
+ cb(data);
526
+ }
527
+ catch (error) {
528
+ // TODO: Add logging here
529
+ }
530
+ });
531
+ }
394
532
  }
395
533
 
396
534
  /**
@@ -461,7 +599,7 @@ class AuraResourceCacheControlCommand extends CacheControlCommand {
461
599
  }
462
600
  }
463
601
 
464
- function buildServiceDescriptor$8() {
602
+ function buildServiceDescriptor$9() {
465
603
  return {
466
604
  type: 'auraResourceCacheControlCommand',
467
605
  version: '1.0',
@@ -502,7 +640,7 @@ class FetchNetworkCommand extends NetworkCommand {
502
640
  }
503
641
  }
504
642
 
505
- function buildServiceDescriptor$7() {
643
+ function buildServiceDescriptor$8() {
506
644
  return {
507
645
  type: 'fetchNetworkCommandBaseClass',
508
646
  version: '1.0',
@@ -540,7 +678,7 @@ class StreamingCommand extends BaseCommand {
540
678
  }
541
679
  }
542
680
 
543
- function buildServiceDescriptor$6() {
681
+ function buildServiceDescriptor$7() {
544
682
  return {
545
683
  type: 'streamingCommandBaseClass',
546
684
  version: '1.0',
@@ -656,7 +794,7 @@ class SSEParsingStream extends TransformStream {
656
794
  }
657
795
  }
658
796
 
659
- function buildServiceDescriptor$5() {
797
+ function buildServiceDescriptor$6() {
660
798
  return {
661
799
  type: 'SSECommandBaseClass',
662
800
  version: '1.0',
@@ -706,7 +844,7 @@ function buildInstrumentCommand(services) {
706
844
  };
707
845
  }
708
846
 
709
- function buildServiceDescriptor$4(instrumentation) {
847
+ function buildServiceDescriptor$5(instrumentation) {
710
848
  return {
711
849
  type: 'instrumentCommand',
712
850
  version: '1.0',
@@ -960,7 +1098,7 @@ class O11yInstrumentation {
960
1098
  this.metrics = new O11yOTelMetricsAPI(this.services);
961
1099
  }
962
1100
  }
963
- function buildServiceDescriptor$3(logger) {
1101
+ function buildServiceDescriptor$4(logger) {
964
1102
  return {
965
1103
  type: 'instrumentation',
966
1104
  version: '1.0',
@@ -1042,6 +1180,7 @@ class DefaultRecordableCache {
1042
1180
  this.keysRead = new KeySetImpl();
1043
1181
  this.missingKeysRead = new KeySetImpl();
1044
1182
  this.keysUpdated = new KeySetImpl();
1183
+ this.metadataKeysUpdated = new KeySetImpl();
1045
1184
  }
1046
1185
  delete(key) {
1047
1186
  this.keysUpdated.add(key);
@@ -1060,8 +1199,13 @@ class DefaultRecordableCache {
1060
1199
  }
1061
1200
  set(key, value) {
1062
1201
  this.keysUpdated.add(key);
1202
+ this.metadataKeysUpdated.add(key);
1063
1203
  this.baseCache.set(key, value);
1064
1204
  }
1205
+ setMetadata(key, cacheControlMetadata) {
1206
+ this.metadataKeysUpdated.add(key);
1207
+ this.baseCache.setMetadata(key, cacheControlMetadata);
1208
+ }
1065
1209
  length() {
1066
1210
  return this.baseCache.length();
1067
1211
  }
@@ -1103,6 +1247,9 @@ class DefaultFilteredCache {
1103
1247
  set(key, value) {
1104
1248
  this.baseCache.set(key, value);
1105
1249
  }
1250
+ setMetadata(key, cacheControlMetadata) {
1251
+ this.baseCache.setMetadata(key, cacheControlMetadata);
1252
+ }
1106
1253
  length() {
1107
1254
  return this.getFilteredKeys().length;
1108
1255
  }
@@ -1163,6 +1310,18 @@ class DefaultCache {
1163
1310
  delete(key) {
1164
1311
  delete this.data[key];
1165
1312
  }
1313
+ /**
1314
+ * Sets the metadata for the specified key if the key is in cache.
1315
+ * If the key doesn't exist, it does nothing.
1316
+ *
1317
+ * @param key key at which to store metadata
1318
+ * @param cacheControlMetadata metadata to be stored
1319
+ */
1320
+ setMetadata(key, cacheControlMetadata) {
1321
+ if (key in this.data) {
1322
+ this.data[key].metadata.cacheControl = cacheControlMetadata;
1323
+ }
1324
+ }
1166
1325
  length() {
1167
1326
  return this.keys().length;
1168
1327
  }
@@ -1180,7 +1339,7 @@ class DefaultCache {
1180
1339
  }
1181
1340
  }
1182
1341
 
1183
- function buildServiceDescriptor$2() {
1342
+ function buildServiceDescriptor$3() {
1184
1343
  return {
1185
1344
  type: 'cache',
1186
1345
  version: '1.0',
@@ -1283,7 +1442,7 @@ class CacheController {
1283
1442
  }
1284
1443
  }
1285
1444
 
1286
- function buildServiceDescriptor$1(cache) {
1445
+ function buildServiceDescriptor$2(cache) {
1287
1446
  return {
1288
1447
  type: 'cacheController',
1289
1448
  version: '1.0',
@@ -1291,6 +1450,75 @@ function buildServiceDescriptor$1(cache) {
1291
1450
  };
1292
1451
  }
1293
1452
 
1453
+ /**
1454
+ * Copyright (c) 2022, Salesforce, Inc.,
1455
+ * All rights reserved.
1456
+ * For full license text, see the LICENSE.txt file
1457
+ */
1458
+
1459
+
1460
+ const EventTypeWildcard = Symbol('EventTypeWildcard');
1461
+
1462
+ /**
1463
+ * A simple implementation of PubSubService.
1464
+ */
1465
+ class DefaultPubSubService {
1466
+ constructor() {
1467
+ this.subscriptions = new Map();
1468
+ }
1469
+ subscribe(subscription) {
1470
+ let eventTypeSubscriptions = this.subscriptions.get(subscription.type);
1471
+ if (eventTypeSubscriptions === undefined) {
1472
+ eventTypeSubscriptions = [];
1473
+ this.subscriptions.set(subscription.type, eventTypeSubscriptions);
1474
+ }
1475
+ eventTypeSubscriptions.push(subscription);
1476
+ return () => {
1477
+ this.subscriptions.set(subscription.type, eventTypeSubscriptions.filter((value) => value !== subscription));
1478
+ };
1479
+ }
1480
+ publish(event) {
1481
+ const eventTypeSubscriptions = this.subscriptions.get(event.type);
1482
+ const wildcardSubscriptions = this.subscriptions.get(EventTypeWildcard);
1483
+ if (eventTypeSubscriptions === undefined && wildcardSubscriptions === undefined) {
1484
+ return resolvedPromiseLike(undefined);
1485
+ }
1486
+ let matchingSubscriptions = [];
1487
+ if (eventTypeSubscriptions !== undefined) {
1488
+ matchingSubscriptions = eventTypeSubscriptions.filter((subscription) => {
1489
+ if (subscription.predicate) {
1490
+ return subscription.predicate(event);
1491
+ }
1492
+ return true;
1493
+ });
1494
+ }
1495
+ matchingSubscriptions = [...matchingSubscriptions, ...(wildcardSubscriptions || [])];
1496
+ const promises = [];
1497
+ matchingSubscriptions.forEach((subscription) => {
1498
+ const returnVal = subscription.callback(event);
1499
+ if (isPromiseLike(returnVal)) {
1500
+ promises.push(returnVal);
1501
+ }
1502
+ });
1503
+ if (promises.length > 0) {
1504
+ return Promise.all(promises).then(() => undefined);
1505
+ }
1506
+ return resolvedPromiseLike(undefined);
1507
+ }
1508
+ }
1509
+ /**
1510
+ * Constructs a default PubSubService
1511
+ *
1512
+ * @returns default PubSubServiceDescriptor
1513
+ */
1514
+ function buildServiceDescriptor$1() {
1515
+ return {
1516
+ type: 'pubSub',
1517
+ version: '1.0',
1518
+ service: new DefaultPubSubService(),
1519
+ };
1520
+ }
1521
+
1294
1522
  /**
1295
1523
  * Copyright (c) 2022, Salesforce, Inc.,
1296
1524
  * All rights reserved.
@@ -1841,7 +2069,7 @@ var TypeCheckShapes;
1841
2069
  TypeCheckShapes[TypeCheckShapes["Integer"] = 3] = "Integer";
1842
2070
  TypeCheckShapes[TypeCheckShapes["Unsupported"] = 4] = "Unsupported";
1843
2071
  })(TypeCheckShapes || (TypeCheckShapes = {}));
1844
- // engine version: 0.156.5-f5fd8c7a
2072
+ // engine version: 0.156.6-042d5d87
1845
2073
 
1846
2074
  const { keys: keys$1 } = Object;
1847
2075
 
@@ -4790,7 +5018,7 @@ function getEnvironmentSetting(name) {
4790
5018
  }
4791
5019
  return undefined;
4792
5020
  }
4793
- // version: 1.344.0-455da7ef74
5021
+ // version: 1.346.0-1b813009ec
4794
5022
 
4795
5023
  const forceRecordTransactionsDisabled = getEnvironmentSetting(EnvironmentSettings.ForceRecordTransactionsDisabled);
4796
5024
  //TODO: Some duplication here that can be most likely moved to a util class
@@ -5441,22 +5669,23 @@ function initializeLDS() {
5441
5669
  // Initializes OneStore in LEX
5442
5670
  function initializeOneStore() {
5443
5671
  const loggerService = new ConsoleLogger$1('ERROR');
5444
- const cacheServiceDescriptor = buildServiceDescriptor$2();
5445
- const instrumentationServiceDescriptor = buildServiceDescriptor$3(loggerService);
5672
+ const cacheServiceDescriptor = buildServiceDescriptor$3();
5673
+ const instrumentationServiceDescriptor = buildServiceDescriptor$4(loggerService);
5446
5674
  const services = [
5447
5675
  instrumentationServiceDescriptor,
5448
5676
  buildUnauthorizedFetchServiceDescriptor(),
5449
5677
  buildJwtAuthorizedSfapFetchServiceDescriptor(loggerService),
5450
5678
  buildCopilotFetchServiceDescriptor(loggerService),
5451
5679
  buildAuraNetworkService(),
5452
- buildServiceDescriptor$4(instrumentationServiceDescriptor.service),
5453
- buildServiceDescriptor$1(cacheServiceDescriptor.service),
5454
- buildServiceDescriptor$9(),
5455
- buildServiceDescriptor$7(),
5680
+ buildServiceDescriptor$5(instrumentationServiceDescriptor.service),
5681
+ buildServiceDescriptor$2(cacheServiceDescriptor.service),
5456
5682
  buildServiceDescriptor$a(),
5457
- buildServiceDescriptor$6(),
5458
- buildServiceDescriptor$5(),
5459
5683
  buildServiceDescriptor$8(),
5684
+ buildServiceDescriptor$b(),
5685
+ buildServiceDescriptor$7(),
5686
+ buildServiceDescriptor$6(),
5687
+ buildServiceDescriptor$9(),
5688
+ buildServiceDescriptor$1(),
5460
5689
  ];
5461
5690
  setServices(services);
5462
5691
  }
@@ -5479,4 +5708,4 @@ function ldsEngineCreator() {
5479
5708
  }
5480
5709
 
5481
5710
  export { LexRequestStrategy, PdlRequestPriority, buildPredictorForContext, ldsEngineCreator as default, initializeLDS, initializeOneStore, registerRequestStrategy, saveRequestAsPrediction, unregisterRequestStrategy, whenPredictionsReady };
5482
- // version: 1.344.0-5dd845c684
5711
+ // version: 1.346.0-43bf38de66
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-aura",
3
- "version": "1.344.0",
3
+ "version": "1.346.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS engine for Aura runtime",
6
6
  "main": "dist/ldsEngineCreator.js",
@@ -34,43 +34,44 @@
34
34
  "release:corejar": "yarn build && ../core-build/scripts/core.js --name=lds-runtime-aura"
35
35
  },
36
36
  "devDependencies": {
37
- "@luvio/service-provisioner": "5.27.1",
38
- "@salesforce/lds-adapters-apex": "^1.344.0",
39
- "@salesforce/lds-adapters-uiapi": "^1.344.0",
37
+ "@luvio/service-provisioner": "5.29.0",
38
+ "@salesforce/lds-adapters-apex": "^1.346.0",
39
+ "@salesforce/lds-adapters-uiapi": "^1.346.0",
40
40
  "@salesforce/lds-adapters-uiapi-lex": "^1.302.0",
41
- "@salesforce/lds-ads-bridge": "^1.344.0",
42
- "@salesforce/lds-aura-storage": "^1.344.0",
43
- "@salesforce/lds-bindings": "^1.344.0",
44
- "@salesforce/lds-instrumentation": "^1.344.0",
45
- "@salesforce/lds-network-aura": "^1.344.0",
46
- "@salesforce/lds-network-fetch": "^1.344.0",
41
+ "@salesforce/lds-ads-bridge": "^1.346.0",
42
+ "@salesforce/lds-aura-storage": "^1.346.0",
43
+ "@salesforce/lds-bindings": "^1.346.0",
44
+ "@salesforce/lds-instrumentation": "^1.346.0",
45
+ "@salesforce/lds-network-aura": "^1.346.0",
46
+ "@salesforce/lds-network-fetch": "^1.346.0",
47
47
  "jwt-encode": "1.0.1"
48
48
  },
49
49
  "dependencies": {
50
- "@luvio/command-aura-network": "5.27.1",
51
- "@luvio/command-aura-resource-cache-control": "5.27.1",
52
- "@luvio/command-fetch-network": "5.27.1",
53
- "@luvio/command-network": "5.27.1",
54
- "@luvio/command-sse": "5.27.1",
55
- "@luvio/command-streaming": "5.27.1",
56
- "@luvio/network-adapter-composable": "0.156.5",
57
- "@luvio/network-adapter-fetch": "0.156.5",
58
- "@luvio/service-aura-network": "5.27.1",
59
- "@luvio/service-cache": "5.27.1",
60
- "@luvio/service-cache-control": "5.27.1",
61
- "@luvio/service-fetch-network": "5.27.1",
62
- "@luvio/service-instrument-command": "5.27.1",
63
- "@luvio/service-store": "5.27.1",
64
- "@luvio/utils": "5.27.1",
65
- "@salesforce/lds-adapters-uiapi-lex": "^1.344.0"
50
+ "@luvio/command-aura-network": "5.29.0",
51
+ "@luvio/command-aura-resource-cache-control": "5.29.0",
52
+ "@luvio/command-fetch-network": "5.29.0",
53
+ "@luvio/command-network": "5.29.0",
54
+ "@luvio/command-sse": "5.29.0",
55
+ "@luvio/command-streaming": "5.29.0",
56
+ "@luvio/network-adapter-composable": "0.156.6",
57
+ "@luvio/network-adapter-fetch": "0.156.6",
58
+ "@luvio/service-aura-network": "5.29.0",
59
+ "@luvio/service-cache": "5.29.0",
60
+ "@luvio/service-cache-control": "5.29.0",
61
+ "@luvio/service-fetch-network": "5.29.0",
62
+ "@luvio/service-instrument-command": "5.29.0",
63
+ "@luvio/service-pubsub": "5.29.0",
64
+ "@luvio/service-store": "5.29.0",
65
+ "@luvio/utils": "5.29.0",
66
+ "@salesforce/lds-adapters-uiapi-lex": "^1.346.0"
66
67
  },
67
68
  "luvioBundlesize": [
68
69
  {
69
70
  "path": "./dist/ldsEngineCreator.js",
70
71
  "maxSize": {
71
- "none": "207 kB",
72
- "min": "86 kB",
73
- "compressed": "36.5 kB"
72
+ "none": "215 kB",
73
+ "min": "89 kB",
74
+ "compressed": "38 kB"
74
75
  }
75
76
  }
76
77
  ],