@salesforce/lds-runtime-aura 1.352.0 → 1.353.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.
Files changed (2) hide show
  1. package/dist/ldsEngineCreator.js +140 -56
  2. package/package.json +31 -31
@@ -409,6 +409,7 @@ class NetworkCommand extends BaseCommand {
409
409
  return err(newResult.error);
410
410
  });
411
411
  }
412
+ async afterRequestHooks(_options) { }
412
413
  }
413
414
  function buildServiceDescriptor$d() {
414
415
  return {
@@ -445,17 +446,26 @@ class AuraNetworkCommand extends NetworkCommand {
445
446
  convertAuraResponseToData(responsePromise, coerceError) {
446
447
  return responsePromise
447
448
  .then((response) => {
448
- return ok(response.getReturnValue());
449
+ const auraReturnValue = response.getReturnValue();
450
+ try {
451
+ this.afterRequestHooks({ statusCode: 200 }); // Treat all aura success as 200
452
+ }
453
+ catch (e) { }
454
+ return ok(auraReturnValue);
449
455
  })
450
456
  .catch((error) => {
451
457
  if (!error || !error.getError) {
452
458
  return err(toError('Failed to get error from response'));
453
459
  }
454
- const actionErrors = error.getError();
455
- if (actionErrors.length > 0) {
456
- return err(coerceError(actionErrors));
460
+ else {
461
+ const actionErrors = error.getError();
462
+ if (actionErrors.length > 0) {
463
+ return err(coerceError(actionErrors));
464
+ }
465
+ else {
466
+ return err(toError('Error fetching component'));
467
+ }
457
468
  }
458
- return err(toError('Error fetching component'));
459
469
  });
460
470
  }
461
471
  fetch() {
@@ -478,6 +488,25 @@ function buildServiceDescriptor$c() {
478
488
  */
479
489
 
480
490
 
491
+ // Needs TS 2023+ (esnext) AND node 20+ to remove
492
+ function setOverlaps(setA, setB) {
493
+ if (setA.size > setB.size) {
494
+ for (const key of setB.keys()) {
495
+ if (setA.has(key)) {
496
+ return true;
497
+ }
498
+ }
499
+ }
500
+ else {
501
+ for (const key of setA) {
502
+ if (setB.has(key)) {
503
+ return true;
504
+ }
505
+ }
506
+ }
507
+ return false;
508
+ }
509
+
481
510
  /**
482
511
  * An implementation of BaseCommand that allows for extending abstract cache methods
483
512
  *
@@ -489,19 +518,31 @@ class CacheControlCommand extends BaseCommand {
489
518
  constructor(services) {
490
519
  super();
491
520
  this.services = services;
521
+ this.operationType = 'query';
492
522
  this.rebuildUnsubscribe = () => { };
493
523
  this.refreshUnsubscribe = () => { };
524
+ this.lastEmittedData = undefined;
525
+ this.subscribeToKeys = () => undefined;
526
+ this.unsubscribeFromKeys = () => undefined;
494
527
  this.subscriptions = [];
495
528
  this.instantiationTime = Date.now() / 1000; // in seconds
496
529
  }
497
530
  execute(overrides) {
498
- this.rebuildUnsubscribe();
499
- this.refreshUnsubscribe();
531
+ this.unsubscribeFromKeys();
532
+ this.subscribeToKeys = () => undefined;
500
533
  const mergedCacheControlConfig = mergeCacheControlConfigs(this.cacheControlStrategyConfig, overrides);
501
534
  const resultPromise = this.services.cacheController.execute(mergedCacheControlConfig, (cache) => this.buildRequestRunner(cache), {
502
535
  instrumentationAttributes: this.instrumentationAttributes,
503
536
  });
504
- return resultPromise;
537
+ return resultPromise.then((result) => {
538
+ if (this.subscriptions.length > 0) {
539
+ this.subscribeToKeys();
540
+ }
541
+ if (result.isOk() && this.lastEmittedData === undefined) {
542
+ this.lastEmittedData = result.value.data;
543
+ }
544
+ return result;
545
+ });
505
546
  }
506
547
  // TODO: This should likely be abstract in v2. For v1, provide default comparison logic.
507
548
  equals(result1, result2) {
@@ -514,12 +555,13 @@ class CacheControlCommand extends BaseCommand {
514
555
  writeToCache: (networkResult) => this.writeToCacheAndPublish(cache, networkResult),
515
556
  };
516
557
  }
558
+ async afterRequestHooks(_options) { }
517
559
  refresh() {
518
- return this.execute({ cacheControlConfig: { type: 'no-cache' } }).then((res) => {
519
- if (res.isOk()) {
520
- return ok(undefined);
560
+ return this.rerun({ cacheControlConfig: { type: 'no-cache' } }).then((result) => {
561
+ if (result.isErr()) {
562
+ return result;
521
563
  }
522
- return err(res.error);
564
+ return ok(undefined);
523
565
  });
524
566
  }
525
567
  // TODO: This is added as a temporary measure for ensuring that cache write events are
@@ -546,7 +588,7 @@ class CacheControlCommand extends BaseCommand {
546
588
  else {
547
589
  const data = readResult.value;
548
590
  if (data !== undefined) {
549
- this.subscribeToKeys(recordableCache.keysRead, data);
591
+ this.subscribeToKeys = () => this.subscribeToKeySet(recordableCache.keysRead);
550
592
  return ok({
551
593
  data,
552
594
  subscribe: this.buildSubscribe(),
@@ -568,35 +610,51 @@ class CacheControlCommand extends BaseCommand {
568
610
  */
569
611
  buildSubscribe() {
570
612
  return (consumerCallback) => {
613
+ if (this.subscriptions.length === 0 && this.operationType === 'query') {
614
+ this.subscribeToKeys();
615
+ }
571
616
  this.subscriptions.push(consumerCallback);
572
617
  return () => {
573
618
  this.subscriptions = this.subscriptions.filter((cb) => cb !== consumerCallback);
619
+ if (this.subscriptions.length === 0) {
620
+ this.unsubscribeFromKeys();
621
+ }
574
622
  };
575
623
  };
576
624
  }
577
- subscribeToKeys(keysRead, lastResult) {
625
+ rerun(overrides) {
626
+ return this.execute(overrides).then((result) => {
627
+ if (result.isErr()) {
628
+ this.invokeConsumerCallbacks(result);
629
+ return result;
630
+ }
631
+ if (!this.equals(this.lastEmittedData, result.value.data)) {
632
+ this.lastEmittedData = result.value.data;
633
+ this.invokeConsumerCallbacks(ok(result.value.data));
634
+ }
635
+ return result;
636
+ });
637
+ }
638
+ subscribeToKeySet(keysRead) {
578
639
  const { pubSub } = this.services;
579
640
  if (!pubSub) {
580
641
  return;
581
642
  }
582
- const executeAndHandleResult = (overrides) => {
583
- return this.execute(overrides).then((result) => {
584
- if (result.isErr()) {
585
- this.invokeConsumerCallbacks(result);
586
- return;
587
- }
588
- if (!this.equals(lastResult, result.value.data)) {
589
- this.invokeConsumerCallbacks(ok(result.value.data));
590
- }
591
- });
592
- };
593
643
  const createKeySubscriber = (type, callback) => pubSub.subscribe({
594
644
  type,
595
645
  predicate: (event) => setOverlaps(event.data, keysRead),
596
646
  callback,
597
647
  });
598
- this.rebuildUnsubscribe = createKeySubscriber('cacheUpdate', () => executeAndHandleResult({ now: this.instantiationTime }));
599
- this.refreshUnsubscribe = createKeySubscriber('cacheInvalidation', () => executeAndHandleResult());
648
+ // Unsubscribe to be sure that this command didn't re-execute and re-subscribe in between the start of command execution and now
649
+ // it shouldn't be possible for this command to resubscribe between the beginning of execution and now
650
+ // ...but lets be defensive.
651
+ this.unsubscribeFromKeys();
652
+ const rebuildUnsubscribe = createKeySubscriber('cacheUpdate', () => this.rerun({ now: this.instantiationTime }).then(() => undefined));
653
+ const refreshUnsubscribe = createKeySubscriber('cacheInvalidation', () => this.rerun().then(() => undefined));
654
+ this.unsubscribeFromKeys = () => {
655
+ rebuildUnsubscribe();
656
+ refreshUnsubscribe();
657
+ };
600
658
  }
601
659
  invokeConsumerCallbacks(data) {
602
660
  this.subscriptions.forEach((cb) => {
@@ -630,24 +688,6 @@ function mergeCacheControlConfigs(baseConfig, overrides) {
630
688
  now,
631
689
  };
632
690
  }
633
- // Needs TS 2023+ (esnext) AND node 20+ to remove
634
- function setOverlaps(setA, setB) {
635
- if (setA.size > setB.size) {
636
- for (const key of setB.keys()) {
637
- if (setA.has(key)) {
638
- return true;
639
- }
640
- }
641
- }
642
- else {
643
- for (const key of setA) {
644
- if (setB.has(key)) {
645
- return true;
646
- }
647
- }
648
- }
649
- return false;
650
- }
651
691
 
652
692
  /**
653
693
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -683,17 +723,26 @@ class AuraCacheControlCommand extends CacheControlCommand {
683
723
  convertAuraResponseToData(responsePromise, coerceError) {
684
724
  return responsePromise
685
725
  .then((response) => {
686
- return ok(response.getReturnValue());
726
+ const auraReturnValue = response.getReturnValue();
727
+ try {
728
+ this.afterRequestHooks({ statusCode: 200 }); // Treat all aura success as 200
729
+ }
730
+ catch (e) { }
731
+ return ok(auraReturnValue);
687
732
  })
688
733
  .catch((error) => {
689
734
  if (!error || !error.getError) {
690
735
  return err(toError('Failed to get error from response'));
691
736
  }
692
- const actionErrors = error.getError();
693
- if (actionErrors.length > 0) {
694
- return err(coerceError(actionErrors));
737
+ else {
738
+ const actionErrors = error.getError();
739
+ if (actionErrors.length > 0) {
740
+ return err(coerceError(actionErrors));
741
+ }
742
+ else {
743
+ return err(toError('Error fetching component'));
744
+ }
695
745
  }
696
- return err(toError('Error fetching component'));
697
746
  });
698
747
  }
699
748
  }
@@ -819,10 +868,27 @@ class HttpCacheControlCommand extends CacheControlCommand {
819
868
  convertFetchResponseToData(response) {
820
869
  return response.then((response) => {
821
870
  if (response.ok) {
822
- return response.json().then((json) => ok(json), (reason) => err(toError(reason)));
871
+ return response
872
+ .json()
873
+ .then((json) => ok(json), (reason) => err(toError(reason)))
874
+ .finally(() => {
875
+ try {
876
+ this.afterRequestHooks({ statusCode: response.status });
877
+ }
878
+ catch (e) { }
879
+ });
823
880
  }
824
881
  else {
825
- return this.coerceError(response).then((coercedError) => err(coercedError));
882
+ return this.coerceError(response)
883
+ .then((coercedError) => {
884
+ return err(coercedError);
885
+ })
886
+ .finally(() => {
887
+ try {
888
+ this.afterRequestHooks({ statusCode: response.status });
889
+ }
890
+ catch (e) { }
891
+ });
826
892
  }
827
893
  }, (reason) => err(toError(reason)));
828
894
  }
@@ -894,10 +960,27 @@ class FetchNetworkCommand extends NetworkCommand {
894
960
  convertFetchResponseToData(response) {
895
961
  return response.then((response) => {
896
962
  if (response.ok) {
897
- return response.json().then((json) => ok(json), (reason) => err(toError(reason)));
963
+ return response
964
+ .json()
965
+ .then((json) => ok(json), (reason) => err(toError(reason)))
966
+ .finally(() => {
967
+ try {
968
+ this.afterRequestHooks({ statusCode: response.status });
969
+ }
970
+ catch (e) { }
971
+ });
898
972
  }
899
973
  else {
900
- return this.coerceError(response).then((coercedError) => err(coercedError));
974
+ return this.coerceError(response)
975
+ .then((coercedError) => {
976
+ return err(coercedError);
977
+ })
978
+ .finally(() => {
979
+ try {
980
+ this.afterRequestHooks({ statusCode: response.status });
981
+ }
982
+ catch (e) { }
983
+ });
901
984
  }
902
985
  }, (reason) => err(toError(reason)));
903
986
  }
@@ -1665,6 +1748,7 @@ class CacheControlStrategy {
1665
1748
  return [
1666
1749
  (cacheControlMetadata) => cacheControlMetadata.type === 'max-age' &&
1667
1750
  this.config.now > cacheControlMetadata.generatedTime + cacheControlMetadata.maxAge,
1751
+ (cacheControlMetadata) => cacheControlMetadata.type === 'max-age' && cacheControlMetadata.maxAge <= 0,
1668
1752
  (cacheControlMetadata) => cacheControlMetadata.type === 'no-store',
1669
1753
  ];
1670
1754
  }
@@ -5522,7 +5606,7 @@ function getEnvironmentSetting(name) {
5522
5606
  }
5523
5607
  return undefined;
5524
5608
  }
5525
- // version: 1.352.0-abe5da40fa
5609
+ // version: 1.353.1-4693659f9b
5526
5610
 
5527
5611
  const forceRecordTransactionsDisabled = getEnvironmentSetting(EnvironmentSettings.ForceRecordTransactionsDisabled);
5528
5612
  //TODO: Some duplication here that can be most likely moved to a util class
@@ -6214,4 +6298,4 @@ function ldsEngineCreator() {
6214
6298
  }
6215
6299
 
6216
6300
  export { LexRequestStrategy, PdlRequestPriority, buildPredictorForContext, ldsEngineCreator as default, initializeLDS, initializeOneStore, registerRequestStrategy, saveRequestAsPrediction, unregisterRequestStrategy, whenPredictionsReady };
6217
- // version: 1.352.0-9307541b03
6301
+ // version: 1.353.1-eeb55fde9b
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-aura",
3
- "version": "1.352.0",
3
+ "version": "1.353.1",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS engine for Aura runtime",
6
6
  "main": "dist/ldsEngineCreator.js",
@@ -34,47 +34,47 @@
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.36.0",
38
- "@luvio/tools-core": "5.36.0",
39
- "@salesforce/lds-adapters-apex": "^1.352.0",
40
- "@salesforce/lds-adapters-uiapi": "^1.352.0",
37
+ "@luvio/service-provisioner": "5.38.2",
38
+ "@luvio/tools-core": "5.38.2",
39
+ "@salesforce/lds-adapters-apex": "^1.353.1",
40
+ "@salesforce/lds-adapters-uiapi": "^1.353.1",
41
41
  "@salesforce/lds-adapters-uiapi-lex": "^1.302.0",
42
- "@salesforce/lds-ads-bridge": "^1.352.0",
43
- "@salesforce/lds-aura-storage": "^1.352.0",
44
- "@salesforce/lds-bindings": "^1.352.0",
45
- "@salesforce/lds-instrumentation": "^1.352.0",
46
- "@salesforce/lds-network-aura": "^1.352.0",
47
- "@salesforce/lds-network-fetch": "^1.352.0",
42
+ "@salesforce/lds-ads-bridge": "^1.353.1",
43
+ "@salesforce/lds-aura-storage": "^1.353.1",
44
+ "@salesforce/lds-bindings": "^1.353.1",
45
+ "@salesforce/lds-instrumentation": "^1.353.1",
46
+ "@salesforce/lds-network-aura": "^1.353.1",
47
+ "@salesforce/lds-network-fetch": "^1.353.1",
48
48
  "jwt-encode": "1.0.1"
49
49
  },
50
50
  "dependencies": {
51
- "@luvio/command-aura-network": "5.36.0",
52
- "@luvio/command-aura-normalized-cache-control": "5.36.0",
53
- "@luvio/command-aura-resource-cache-control": "5.36.0",
54
- "@luvio/command-fetch-network": "5.36.0",
55
- "@luvio/command-http-normalized-cache-control": "5.36.0",
56
- "@luvio/command-network": "5.36.0",
57
- "@luvio/command-sse": "5.36.0",
58
- "@luvio/command-streaming": "5.36.0",
51
+ "@luvio/command-aura-network": "5.38.2",
52
+ "@luvio/command-aura-normalized-cache-control": "5.38.2",
53
+ "@luvio/command-aura-resource-cache-control": "5.38.2",
54
+ "@luvio/command-fetch-network": "5.38.2",
55
+ "@luvio/command-http-normalized-cache-control": "5.38.2",
56
+ "@luvio/command-network": "5.38.2",
57
+ "@luvio/command-sse": "5.38.2",
58
+ "@luvio/command-streaming": "5.38.2",
59
59
  "@luvio/network-adapter-composable": "0.156.7",
60
60
  "@luvio/network-adapter-fetch": "0.156.7",
61
- "@luvio/service-aura-network": "5.36.0",
62
- "@luvio/service-cache": "5.36.0",
63
- "@luvio/service-cache-control": "5.36.0",
64
- "@luvio/service-fetch-network": "5.36.0",
65
- "@luvio/service-instrument-command": "5.36.0",
66
- "@luvio/service-pubsub": "5.36.0",
67
- "@luvio/service-store": "5.36.0",
68
- "@luvio/utils": "5.36.0",
69
- "@salesforce/lds-adapters-uiapi-lex": "^1.352.0"
61
+ "@luvio/service-aura-network": "5.38.2",
62
+ "@luvio/service-cache": "5.38.2",
63
+ "@luvio/service-cache-control": "5.38.2",
64
+ "@luvio/service-fetch-network": "5.38.2",
65
+ "@luvio/service-instrument-command": "5.38.2",
66
+ "@luvio/service-pubsub": "5.38.2",
67
+ "@luvio/service-store": "5.38.2",
68
+ "@luvio/utils": "5.38.2",
69
+ "@salesforce/lds-adapters-uiapi-lex": "^1.353.1"
70
70
  },
71
71
  "luvioBundlesize": [
72
72
  {
73
73
  "path": "./dist/ldsEngineCreator.js",
74
74
  "maxSize": {
75
- "none": "232 kB",
76
- "min": "96 kB",
77
- "compressed": "39.7 kB"
75
+ "none": "235 kB",
76
+ "min": "97 kB",
77
+ "compressed": "40 kB"
78
78
  }
79
79
  }
80
80
  ],