@salesforce/lds-runtime-aura 1.354.0-dev2 → 1.354.0-dev20
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/ldsEngineCreator.js +520 -281
- package/package.json +34 -33
package/dist/ldsEngineCreator.js
CHANGED
|
@@ -151,7 +151,7 @@ function resolvedPromiseLike(result) {
|
|
|
151
151
|
}
|
|
152
152
|
return {
|
|
153
153
|
then: (onFulfilled, _onRejected) => {
|
|
154
|
-
if (onFulfilled) {
|
|
154
|
+
if (typeof onFulfilled === 'function') {
|
|
155
155
|
try {
|
|
156
156
|
return resolvedPromiseLike(onFulfilled(result));
|
|
157
157
|
}
|
|
@@ -176,7 +176,7 @@ function rejectedPromiseLike(reason) {
|
|
|
176
176
|
}
|
|
177
177
|
return {
|
|
178
178
|
then: (_onFulfilled, onRejected) => {
|
|
179
|
-
if (onRejected) {
|
|
179
|
+
if (typeof onRejected === 'function') {
|
|
180
180
|
try {
|
|
181
181
|
return resolvedPromiseLike(onRejected(reason));
|
|
182
182
|
}
|
|
@@ -411,7 +411,7 @@ class NetworkCommand extends BaseCommand {
|
|
|
411
411
|
}
|
|
412
412
|
async afterRequestHooks(_options) { }
|
|
413
413
|
}
|
|
414
|
-
function buildServiceDescriptor$
|
|
414
|
+
function buildServiceDescriptor$e() {
|
|
415
415
|
return {
|
|
416
416
|
type: 'networkCommandBaseClass',
|
|
417
417
|
version: '1.0',
|
|
@@ -473,7 +473,7 @@ class AuraNetworkCommand extends NetworkCommand {
|
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
|
|
476
|
-
function buildServiceDescriptor$
|
|
476
|
+
function buildServiceDescriptor$d() {
|
|
477
477
|
return {
|
|
478
478
|
type: 'auraNetworkCommandBaseClass',
|
|
479
479
|
version: '1.0',
|
|
@@ -518,65 +518,130 @@ class CacheControlCommand extends BaseCommand {
|
|
|
518
518
|
constructor(services) {
|
|
519
519
|
super();
|
|
520
520
|
this.services = services;
|
|
521
|
+
this.keysUsed = new Set();
|
|
522
|
+
this.keysUpdated = undefined;
|
|
521
523
|
this.operationType = 'query';
|
|
522
|
-
this.rebuildUnsubscribe = () => { };
|
|
523
|
-
this.refreshUnsubscribe = () => { };
|
|
524
524
|
this.lastEmittedData = undefined;
|
|
525
|
-
this.
|
|
526
|
-
this.unsubscribeFromKeys = () => undefined;
|
|
525
|
+
this.unsubscribeFromKeysImpl = () => undefined;
|
|
527
526
|
this.subscriptions = [];
|
|
528
527
|
this.instantiationTime = Date.now() / 1000; // in seconds
|
|
529
528
|
}
|
|
530
529
|
execute(overrides) {
|
|
530
|
+
this.keysUpdated = undefined;
|
|
531
531
|
this.unsubscribeFromKeys();
|
|
532
|
-
this.subscribeToKeys = () => undefined;
|
|
533
532
|
const mergedCacheControlConfig = mergeCacheControlConfigs(this.cacheControlStrategyConfig, overrides);
|
|
534
|
-
|
|
533
|
+
let returnData;
|
|
534
|
+
let returnError;
|
|
535
|
+
const requestRunner = {
|
|
536
|
+
readFromCache: (cache) => {
|
|
537
|
+
const resultPromise = this.buildResultWithSubscribe(cache);
|
|
538
|
+
return resultPromise.then((result) => {
|
|
539
|
+
if (result.isErr()) {
|
|
540
|
+
return err(result.error);
|
|
541
|
+
}
|
|
542
|
+
returnData = result;
|
|
543
|
+
return ok(undefined);
|
|
544
|
+
});
|
|
545
|
+
},
|
|
546
|
+
requestFromNetwork: () => {
|
|
547
|
+
const that = this;
|
|
548
|
+
return (async function* () {
|
|
549
|
+
const result = await that.requestFromNetwork();
|
|
550
|
+
if (result.isErr()) {
|
|
551
|
+
returnError = result;
|
|
552
|
+
}
|
|
553
|
+
yield result;
|
|
554
|
+
})();
|
|
555
|
+
},
|
|
556
|
+
writeToCache: (cache, networkResult) => {
|
|
557
|
+
return this.writeToCacheAndRecordKeys(cache, networkResult);
|
|
558
|
+
},
|
|
559
|
+
};
|
|
560
|
+
const resultPromise = this.services.cacheController.execute(mergedCacheControlConfig, requestRunner, {
|
|
535
561
|
instrumentationAttributes: this.instrumentationAttributes,
|
|
536
562
|
});
|
|
537
563
|
return resultPromise.then((result) => {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
564
|
+
return this.publishUpdatedKeys().then(() => {
|
|
565
|
+
// First check if there was an error from the network
|
|
566
|
+
if (returnError) {
|
|
567
|
+
return returnError;
|
|
568
|
+
}
|
|
569
|
+
// Then return other errors from read/write
|
|
570
|
+
if (result.isErr()) {
|
|
571
|
+
return err(result.error);
|
|
572
|
+
}
|
|
573
|
+
if (this.subscriptions.length > 0) {
|
|
574
|
+
this.subscribeToKeysUsed();
|
|
575
|
+
}
|
|
576
|
+
if (returnData === undefined) {
|
|
577
|
+
return err(new Error('Cache miss after fetching from network'));
|
|
578
|
+
}
|
|
579
|
+
if (returnData.isOk() && this.lastEmittedData === undefined) {
|
|
580
|
+
this.lastEmittedData = returnData.value.data;
|
|
581
|
+
}
|
|
582
|
+
return returnData;
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
publishUpdatedKeys() {
|
|
587
|
+
if (this.services.pubSub) {
|
|
588
|
+
if (this.keysUpdated !== undefined && this.keysUpdated.size > 0) {
|
|
589
|
+
return this.services.pubSub.publish({
|
|
590
|
+
type: 'cacheUpdate',
|
|
591
|
+
data: this.keysUpdated,
|
|
592
|
+
});
|
|
543
593
|
}
|
|
544
|
-
|
|
594
|
+
}
|
|
595
|
+
return resolvedPromiseLike(undefined);
|
|
596
|
+
}
|
|
597
|
+
subscribeToKeysUsed() {
|
|
598
|
+
this.unsubscribeFromKeys();
|
|
599
|
+
const { pubSub } = this.services;
|
|
600
|
+
if (!pubSub) {
|
|
601
|
+
this.unsubscribeFromKeysImpl = () => undefined;
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
const rebuildUnsubscribe = pubSub.subscribe({
|
|
605
|
+
type: 'cacheUpdate',
|
|
606
|
+
predicate: (event) => setOverlaps(event.data, this.keysUsed),
|
|
607
|
+
callback: () => this.rerun({ now: this.instantiationTime }).then(() => undefined),
|
|
608
|
+
keys: this.keysUsed,
|
|
609
|
+
});
|
|
610
|
+
const refreshUnsubscribe = pubSub.subscribe({
|
|
611
|
+
type: 'cacheInvalidation',
|
|
612
|
+
predicate: (event) => setOverlaps(event.data, this.keysUsed),
|
|
613
|
+
callback: () => this.rerun().then(() => undefined),
|
|
614
|
+
keys: this.keysUsed,
|
|
545
615
|
});
|
|
616
|
+
this.unsubscribeFromKeysImpl = () => {
|
|
617
|
+
rebuildUnsubscribe();
|
|
618
|
+
refreshUnsubscribe();
|
|
619
|
+
};
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
unsubscribeFromKeys() {
|
|
623
|
+
this.unsubscribeFromKeysImpl();
|
|
546
624
|
}
|
|
547
625
|
// TODO: This should likely be abstract in v2. For v1, provide default comparison logic.
|
|
548
626
|
equals(result1, result2) {
|
|
549
627
|
return deepEquals$1(result1, result2);
|
|
550
628
|
}
|
|
551
|
-
buildRequestRunner(cache) {
|
|
552
|
-
return {
|
|
553
|
-
readFromCache: () => this.buildResultWithSubscribe(cache),
|
|
554
|
-
requestFromNetwork: () => this.requestFromNetwork(),
|
|
555
|
-
writeToCache: (networkResult) => this.writeToCacheAndPublish(cache, networkResult),
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
629
|
async afterRequestHooks(_options) { }
|
|
559
630
|
refresh() {
|
|
560
631
|
return this.rerun({ cacheControlConfig: { type: 'no-cache' } }).then((result) => {
|
|
561
632
|
if (result.isErr()) {
|
|
562
|
-
return result;
|
|
633
|
+
return err(result.error);
|
|
563
634
|
}
|
|
564
635
|
return ok(undefined);
|
|
565
636
|
});
|
|
566
637
|
}
|
|
567
|
-
|
|
568
|
-
// published to pubSub. A follow-up will be required to find the right home for this logic.
|
|
569
|
-
writeToCacheAndPublish(cache, networkResult) {
|
|
638
|
+
writeToCacheAndRecordKeys(cache, networkResult) {
|
|
570
639
|
const recordableCache = cache.record();
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
data: recordableCache.keysUpdated,
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
return writeResult;
|
|
640
|
+
return this.writeToCache(recordableCache, networkResult).then((result) => {
|
|
641
|
+
this.instantiationTime = Date.now() / 1000;
|
|
642
|
+
this.keysUpdated = recordableCache.keysUpdated;
|
|
643
|
+
return ok(result);
|
|
644
|
+
});
|
|
580
645
|
}
|
|
581
646
|
buildResultWithSubscribe(cache) {
|
|
582
647
|
const recordableCache = cache.record();
|
|
@@ -587,15 +652,12 @@ class CacheControlCommand extends BaseCommand {
|
|
|
587
652
|
}
|
|
588
653
|
else {
|
|
589
654
|
const data = readResult.value;
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
return ok(undefined);
|
|
655
|
+
this.keysUsed = recordableCache.keysRead;
|
|
656
|
+
return ok({
|
|
657
|
+
data,
|
|
658
|
+
subscribe: this.buildSubscribe(),
|
|
659
|
+
refresh: () => this.refresh(),
|
|
660
|
+
});
|
|
599
661
|
}
|
|
600
662
|
});
|
|
601
663
|
}
|
|
@@ -611,7 +673,7 @@ class CacheControlCommand extends BaseCommand {
|
|
|
611
673
|
buildSubscribe() {
|
|
612
674
|
return (consumerCallback) => {
|
|
613
675
|
if (this.subscriptions.length === 0 && this.operationType === 'query') {
|
|
614
|
-
this.
|
|
676
|
+
this.subscribeToKeysUsed();
|
|
615
677
|
}
|
|
616
678
|
this.subscriptions.push(consumerCallback);
|
|
617
679
|
return () => {
|
|
@@ -635,27 +697,6 @@ class CacheControlCommand extends BaseCommand {
|
|
|
635
697
|
return result;
|
|
636
698
|
});
|
|
637
699
|
}
|
|
638
|
-
subscribeToKeySet(keysRead) {
|
|
639
|
-
const { pubSub } = this.services;
|
|
640
|
-
if (!pubSub) {
|
|
641
|
-
return;
|
|
642
|
-
}
|
|
643
|
-
const createKeySubscriber = (type, callback) => pubSub.subscribe({
|
|
644
|
-
type,
|
|
645
|
-
predicate: (event) => setOverlaps(event.data, keysRead),
|
|
646
|
-
callback,
|
|
647
|
-
});
|
|
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
|
-
};
|
|
658
|
-
}
|
|
659
700
|
invokeConsumerCallbacks(data) {
|
|
660
701
|
this.subscriptions.forEach((cb) => {
|
|
661
702
|
try {
|
|
@@ -771,13 +812,19 @@ class AuraResourceCacheControlCommand extends AuraCacheControlCommand {
|
|
|
771
812
|
}
|
|
772
813
|
readFromCache(cache) {
|
|
773
814
|
var _a;
|
|
774
|
-
|
|
815
|
+
const data = (_a = cache.get(this.buildKey())) === null || _a === void 0 ? void 0 : _a.value;
|
|
816
|
+
if (data === undefined) {
|
|
817
|
+
return resolvedPromiseLike(err(new Error('Failed to find data in cache')));
|
|
818
|
+
}
|
|
819
|
+
return resolvedPromiseLike(ok(data));
|
|
775
820
|
}
|
|
776
821
|
writeToCache(cache, networkResult) {
|
|
777
822
|
if (networkResult.isOk()) {
|
|
778
823
|
cache.set(this.buildKey(), {
|
|
779
824
|
value: networkResult.value,
|
|
780
|
-
metadata: {
|
|
825
|
+
metadata: {
|
|
826
|
+
cacheControl: this.buildCacheControlMetadata(networkResult.value),
|
|
827
|
+
},
|
|
781
828
|
});
|
|
782
829
|
}
|
|
783
830
|
return resolvedPromiseLike(undefined);
|
|
@@ -787,7 +834,7 @@ class AuraResourceCacheControlCommand extends AuraCacheControlCommand {
|
|
|
787
834
|
}
|
|
788
835
|
}
|
|
789
836
|
|
|
790
|
-
function buildServiceDescriptor$
|
|
837
|
+
function buildServiceDescriptor$c() {
|
|
791
838
|
return {
|
|
792
839
|
type: 'auraResourceCacheControlCommand',
|
|
793
840
|
version: '1.0',
|
|
@@ -829,7 +876,7 @@ class AuraNormalizedCacheControlCommand extends AuraCacheControlCommand {
|
|
|
829
876
|
}
|
|
830
877
|
}
|
|
831
878
|
|
|
832
|
-
function buildServiceDescriptor$
|
|
879
|
+
function buildServiceDescriptor$b() {
|
|
833
880
|
return {
|
|
834
881
|
type: 'auraNormalizedCacheControlCommand',
|
|
835
882
|
version: '1.0',
|
|
@@ -928,7 +975,7 @@ class HttpNormalizedCacheControlCommand extends HttpCacheControlCommand {
|
|
|
928
975
|
}
|
|
929
976
|
}
|
|
930
977
|
|
|
931
|
-
function buildServiceDescriptor$
|
|
978
|
+
function buildServiceDescriptor$a() {
|
|
932
979
|
return {
|
|
933
980
|
type: 'httpNormalizedCacheControlCommand',
|
|
934
981
|
version: '1.0',
|
|
@@ -986,7 +1033,7 @@ class FetchNetworkCommand extends NetworkCommand {
|
|
|
986
1033
|
}
|
|
987
1034
|
}
|
|
988
1035
|
|
|
989
|
-
function buildServiceDescriptor$
|
|
1036
|
+
function buildServiceDescriptor$9() {
|
|
990
1037
|
return {
|
|
991
1038
|
type: 'fetchNetworkCommandBaseClass',
|
|
992
1039
|
version: '1.0',
|
|
@@ -1024,7 +1071,7 @@ class StreamingCommand extends BaseCommand {
|
|
|
1024
1071
|
}
|
|
1025
1072
|
}
|
|
1026
1073
|
|
|
1027
|
-
function buildServiceDescriptor$
|
|
1074
|
+
function buildServiceDescriptor$8() {
|
|
1028
1075
|
return {
|
|
1029
1076
|
type: 'streamingCommandBaseClass',
|
|
1030
1077
|
version: '1.0',
|
|
@@ -1068,6 +1115,10 @@ const sseRegex = /^(?<field>[^:]*?)(: ?(?<value>.*?))?(?:\r\n?|\n)/;
|
|
|
1068
1115
|
// | ": value", or ": comment" if no field name (optional)
|
|
1069
1116
|
// |
|
|
1070
1117
|
// field name (optional); can be entire line if no ":"
|
|
1118
|
+
/**
|
|
1119
|
+
* A TransformStream that parses server-sent event (SSE) data according to the SSE spec:
|
|
1120
|
+
* https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
1121
|
+
*/
|
|
1071
1122
|
class SSEParsingStream extends TransformStream {
|
|
1072
1123
|
constructor() {
|
|
1073
1124
|
let ignoreLeadingLF = false, partialLine = '', data = '', event = '', id = '', retry;
|
|
@@ -1140,7 +1191,7 @@ class SSEParsingStream extends TransformStream {
|
|
|
1140
1191
|
}
|
|
1141
1192
|
}
|
|
1142
1193
|
|
|
1143
|
-
function buildServiceDescriptor$
|
|
1194
|
+
function buildServiceDescriptor$7() {
|
|
1144
1195
|
return {
|
|
1145
1196
|
type: 'SSECommandBaseClass',
|
|
1146
1197
|
version: '1.0',
|
|
@@ -1190,7 +1241,7 @@ function buildInstrumentCommand(services) {
|
|
|
1190
1241
|
};
|
|
1191
1242
|
}
|
|
1192
1243
|
|
|
1193
|
-
function buildServiceDescriptor$
|
|
1244
|
+
function buildServiceDescriptor$6(instrumentation) {
|
|
1194
1245
|
return {
|
|
1195
1246
|
type: 'instrumentCommand',
|
|
1196
1247
|
version: '1.0',
|
|
@@ -1456,7 +1507,7 @@ class O11yInstrumentation {
|
|
|
1456
1507
|
this.metrics = new O11yOTelMetricsAPI(this.services);
|
|
1457
1508
|
}
|
|
1458
1509
|
}
|
|
1459
|
-
function buildServiceDescriptor$
|
|
1510
|
+
function buildServiceDescriptor$5(logger) {
|
|
1460
1511
|
return {
|
|
1461
1512
|
type: 'instrumentation',
|
|
1462
1513
|
version: '1.0',
|
|
@@ -1715,7 +1766,7 @@ class DefaultCache {
|
|
|
1715
1766
|
}
|
|
1716
1767
|
}
|
|
1717
1768
|
|
|
1718
|
-
function buildServiceDescriptor$
|
|
1769
|
+
function buildServiceDescriptor$4() {
|
|
1719
1770
|
return {
|
|
1720
1771
|
type: 'cache',
|
|
1721
1772
|
version: '1.0',
|
|
@@ -1731,18 +1782,14 @@ function buildServiceDescriptor$3() {
|
|
|
1731
1782
|
|
|
1732
1783
|
|
|
1733
1784
|
class CacheControlStrategy {
|
|
1734
|
-
constructor(services, config,
|
|
1785
|
+
constructor(services, config, requestRunner) {
|
|
1735
1786
|
this.services = services;
|
|
1736
1787
|
this.config = config;
|
|
1737
|
-
|
|
1788
|
+
this.requestRunner = requestRunner;
|
|
1789
|
+
this.filteredCache = this.services.cache.filter((_, entry) => {
|
|
1738
1790
|
const { cacheControl } = entry.metadata;
|
|
1739
1791
|
return !this.expiredChecks.some((check) => check(cacheControl));
|
|
1740
1792
|
});
|
|
1741
|
-
this.requestRunner = buildRequestRunner(requestRunnerCache);
|
|
1742
|
-
}
|
|
1743
|
-
isCacheHit(cacheReadValue) {
|
|
1744
|
-
const isCacheMiss = cacheReadValue.isErr() || cacheReadValue.value === undefined;
|
|
1745
|
-
return !isCacheMiss;
|
|
1746
1793
|
}
|
|
1747
1794
|
get expiredChecks() {
|
|
1748
1795
|
return [
|
|
@@ -1750,49 +1797,96 @@ class CacheControlStrategy {
|
|
|
1750
1797
|
this.config.now > cacheControlMetadata.generatedTime + cacheControlMetadata.maxAge,
|
|
1751
1798
|
(cacheControlMetadata) => cacheControlMetadata.type === 'max-age' && cacheControlMetadata.maxAge <= 0,
|
|
1752
1799
|
(cacheControlMetadata) => cacheControlMetadata.type === 'no-store',
|
|
1800
|
+
(cacheControlMetadata) => cacheControlMetadata.type === 'no-cache' &&
|
|
1801
|
+
cacheControlMetadata.generatedTime < this.config.now,
|
|
1753
1802
|
];
|
|
1754
1803
|
}
|
|
1755
1804
|
}
|
|
1756
1805
|
|
|
1806
|
+
class NoCacheCacheControlStrategy extends CacheControlStrategy {
|
|
1807
|
+
execute() {
|
|
1808
|
+
// TODO - should be using wrapper here that suppresses no-store writes
|
|
1809
|
+
const tempCache = this.filteredCache;
|
|
1810
|
+
return new Promise(async (resolve, reject) => {
|
|
1811
|
+
try {
|
|
1812
|
+
let readResult = ok(undefined);
|
|
1813
|
+
for await (const rfnResult of this.requestRunner.requestFromNetwork()) {
|
|
1814
|
+
if (rfnResult) {
|
|
1815
|
+
const result = await this.services.cacheInclusionPolicy.write({
|
|
1816
|
+
l1: tempCache,
|
|
1817
|
+
writeToL1: (l1) => this.requestRunner.writeToCache(l1, rfnResult),
|
|
1818
|
+
});
|
|
1819
|
+
if (result.isErr()) {
|
|
1820
|
+
return resolve(result);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
// give readFromCache another shot at the cache
|
|
1824
|
+
readResult = await this.services.cacheInclusionPolicy.read({
|
|
1825
|
+
l1: tempCache,
|
|
1826
|
+
readFromL1: (l1) => this.requestRunner.readFromCache(l1),
|
|
1827
|
+
});
|
|
1828
|
+
if (readResult.isOk()) {
|
|
1829
|
+
resolve(readResult);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
return resolve(readResult);
|
|
1833
|
+
}
|
|
1834
|
+
catch (error) {
|
|
1835
|
+
return reject(error);
|
|
1836
|
+
}
|
|
1837
|
+
});
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1757
1841
|
class MaxAgeCacheControlStrategy extends CacheControlStrategy {
|
|
1758
1842
|
execute(options) {
|
|
1759
1843
|
const startTime = this.services.instrumentation
|
|
1760
1844
|
? this.services.instrumentation.currentTimeMs()
|
|
1761
1845
|
: 0;
|
|
1762
|
-
return this.
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
}
|
|
1767
|
-
return this.handleCacheMiss(startTime, options === null || options === void 0 ? void 0 : options.instrumentationAttributes);
|
|
1768
|
-
});
|
|
1769
|
-
}
|
|
1770
|
-
handleCacheMiss(startTime, instrumentationAttributes) {
|
|
1771
|
-
let error;
|
|
1772
|
-
return this.requestRunner
|
|
1773
|
-
.requestFromNetwork()
|
|
1774
|
-
.then((value) => {
|
|
1775
|
-
if (value.isErr()) {
|
|
1776
|
-
error = value;
|
|
1777
|
-
return resolvedPromiseLike(null);
|
|
1778
|
-
}
|
|
1779
|
-
return this.requestRunner.writeToCache(value);
|
|
1780
|
-
})
|
|
1781
|
-
.then(() => {
|
|
1782
|
-
if (error) {
|
|
1783
|
-
return resolvedPromiseLike(null);
|
|
1784
|
-
}
|
|
1785
|
-
return this.requestRunner.readFromCache();
|
|
1846
|
+
return this.services.cacheInclusionPolicy
|
|
1847
|
+
.read({
|
|
1848
|
+
l1: this.filteredCache,
|
|
1849
|
+
readFromL1: (l1) => this.requestRunner.readFromCache(l1),
|
|
1786
1850
|
})
|
|
1787
1851
|
.then((value) => {
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
return err(new Error('Cache miss after fetching from network'));
|
|
1852
|
+
// ignore error from initial cache read
|
|
1853
|
+
if (value.isOk()) {
|
|
1854
|
+
this.collectCacheHitInstrumentation(startTime, options === null || options === void 0 ? void 0 : options.instrumentationAttributes);
|
|
1855
|
+
return ok(undefined);
|
|
1793
1856
|
}
|
|
1794
|
-
this.collectCacheMissInstrumentation(startTime, instrumentationAttributes);
|
|
1795
|
-
|
|
1857
|
+
this.collectCacheMissInstrumentation(startTime, options === null || options === void 0 ? void 0 : options.instrumentationAttributes);
|
|
1858
|
+
// initial cache read failed, awaits are ok beyond this point since the data
|
|
1859
|
+
// must come from network requests
|
|
1860
|
+
const tempCache = this.filteredCache;
|
|
1861
|
+
return new Promise(async (resolve, reject) => {
|
|
1862
|
+
try {
|
|
1863
|
+
let readResult = ok(undefined);
|
|
1864
|
+
for await (const rfnResult of this.requestRunner.requestFromNetwork()) {
|
|
1865
|
+
// async generator has a value to ingest
|
|
1866
|
+
if (rfnResult) {
|
|
1867
|
+
const result = await this.services.cacheInclusionPolicy.write({
|
|
1868
|
+
l1: tempCache,
|
|
1869
|
+
writeToL1: (l1) => this.requestRunner.writeToCache(l1, rfnResult),
|
|
1870
|
+
});
|
|
1871
|
+
if (result.isErr()) {
|
|
1872
|
+
return resolve(err(result.error));
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
// give readFromCache another shot at the cache
|
|
1876
|
+
readResult = await this.services.cacheInclusionPolicy.read({
|
|
1877
|
+
l1: tempCache,
|
|
1878
|
+
readFromL1: (l1) => this.requestRunner.readFromCache(l1),
|
|
1879
|
+
});
|
|
1880
|
+
if (readResult.isOk()) {
|
|
1881
|
+
resolve(ok(undefined));
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
return resolve(readResult);
|
|
1885
|
+
}
|
|
1886
|
+
catch (e) {
|
|
1887
|
+
return reject(e);
|
|
1888
|
+
}
|
|
1889
|
+
});
|
|
1796
1890
|
});
|
|
1797
1891
|
}
|
|
1798
1892
|
collectCacheHitInstrumentation(startTime, instrumentationAttributes) {
|
|
@@ -1828,118 +1922,6 @@ class MaxAgeCacheControlStrategy extends CacheControlStrategy {
|
|
|
1828
1922
|
}
|
|
1829
1923
|
}
|
|
1830
1924
|
|
|
1831
|
-
class NoCacheCacheControlStrategy extends CacheControlStrategy {
|
|
1832
|
-
execute() {
|
|
1833
|
-
return this.requestRunner.requestFromNetwork().then((networkResult) => {
|
|
1834
|
-
if (networkResult.isErr()) {
|
|
1835
|
-
return networkResult;
|
|
1836
|
-
}
|
|
1837
|
-
// Attempt to write to the cache
|
|
1838
|
-
return this.requestRunner
|
|
1839
|
-
.writeToCache(networkResult)
|
|
1840
|
-
.then(() => this.requestRunner.readFromCache())
|
|
1841
|
-
.then((cachedResult) => {
|
|
1842
|
-
if (!this.isCacheHit(cachedResult)) {
|
|
1843
|
-
return err(new Error('Cache miss after saving network result'));
|
|
1844
|
-
}
|
|
1845
|
-
return cachedResult;
|
|
1846
|
-
});
|
|
1847
|
-
});
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
const isAndQuery = (query) => '$and' in query;
|
|
1852
|
-
const isOrQuery = (query) => '$or' in query;
|
|
1853
|
-
const isNotQuery = (query) => '$not' in query;
|
|
1854
|
-
const matchesMetadata = (metadataQuery, cacheControl) => {
|
|
1855
|
-
var _a;
|
|
1856
|
-
if ('cacheControlType' in metadataQuery &&
|
|
1857
|
-
cacheControl.type !== metadataQuery.cacheControlType.$eq) {
|
|
1858
|
-
return false;
|
|
1859
|
-
}
|
|
1860
|
-
if ('maxAge' in metadataQuery && cacheControl.type === 'max-age') {
|
|
1861
|
-
const maxAge = (_a = cacheControl.maxAge) !== null && _a !== void 0 ? _a : 0;
|
|
1862
|
-
if ((metadataQuery.maxAge.$gte !== undefined && maxAge < metadataQuery.maxAge.$gte) ||
|
|
1863
|
-
(metadataQuery.maxAge.$lte !== undefined && maxAge > metadataQuery.maxAge.$lte)) {
|
|
1864
|
-
return false;
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
return true;
|
|
1868
|
-
};
|
|
1869
|
-
function queryToPredicate(query) {
|
|
1870
|
-
return (key, entry) => {
|
|
1871
|
-
if (!query)
|
|
1872
|
-
return false;
|
|
1873
|
-
if (isAndQuery(query))
|
|
1874
|
-
return query.$and.every((subQuery) => queryToPredicate(subQuery)(key, entry));
|
|
1875
|
-
if (isOrQuery(query))
|
|
1876
|
-
return query.$or.some((subQuery) => queryToPredicate(subQuery)(key, entry));
|
|
1877
|
-
if (isNotQuery(query))
|
|
1878
|
-
return !queryToPredicate(query.$not)(key, entry);
|
|
1879
|
-
if ('key' in query)
|
|
1880
|
-
return matchesKey(query.key, key);
|
|
1881
|
-
if ('metadata' in query)
|
|
1882
|
-
return matchesMetadata(query.metadata, entry.metadata.cacheControl);
|
|
1883
|
-
if ('value' in query)
|
|
1884
|
-
return false; // TODO: Not implemented
|
|
1885
|
-
throw new Error('Unknown Query Operation');
|
|
1886
|
-
};
|
|
1887
|
-
}
|
|
1888
|
-
function matchesKey(keyQuery, key) {
|
|
1889
|
-
if ('$regex' in keyQuery) {
|
|
1890
|
-
return keyQuery.$regex.test(key);
|
|
1891
|
-
}
|
|
1892
|
-
return false;
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
/**
|
|
1896
|
-
* Processes a cache update operation and determines the appropriate modification.
|
|
1897
|
-
*
|
|
1898
|
-
* This function analyzes the provided `update` and the `existing` cache entry
|
|
1899
|
-
* to determine the necessary update type. It returns one of three possible outcomes:
|
|
1900
|
-
*
|
|
1901
|
-
* - `{ type: 'entry', entry }`: A full cache entry update, including both value and metadata.
|
|
1902
|
-
* - `{ type: 'metadata', metadata }`: A metadata-only update, leaving the value unchanged.
|
|
1903
|
-
* - `{ type: 'no-op' }`: No changes are needed, and the cache should remain as is.
|
|
1904
|
-
*
|
|
1905
|
-
* @param update - The cache update operation to apply.
|
|
1906
|
-
* @param existing - The existing cache entry being modified.
|
|
1907
|
-
* @returns An object indicating the type of update:
|
|
1908
|
-
* - A full cache entry update (`type: 'entry'`)
|
|
1909
|
-
* - A metadata-only update (`type: 'metadata'`)
|
|
1910
|
-
* - A no-op (`type: 'no-op'`) if no changes are required.
|
|
1911
|
-
*/
|
|
1912
|
-
function buildUpdate(update, existing) {
|
|
1913
|
-
switch (update.type) {
|
|
1914
|
-
case 'invalidate':
|
|
1915
|
-
const updatedCacheControl = buildInvalidatedCacheControl(existing.metadata.cacheControl);
|
|
1916
|
-
return updatedCacheControl !== undefined
|
|
1917
|
-
? { type: 'metadata', metadata: updatedCacheControl }
|
|
1918
|
-
: { type: 'no-op' };
|
|
1919
|
-
default:
|
|
1920
|
-
throw new Error(`Invalid update operation: ${update.type}`);
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
/**
|
|
1924
|
-
* Builds an updated CacheControlMetadata object that invalidates the cache entry.
|
|
1925
|
-
*
|
|
1926
|
-
* @param existingCacheControl - The current CacheControlMetadata.
|
|
1927
|
-
* @returns A new CacheControlMetadata object with `maxAge` set to `0`, or undefined if no changes are needed.
|
|
1928
|
-
*/
|
|
1929
|
-
function buildInvalidatedCacheControl(existingCacheControl) {
|
|
1930
|
-
switch (existingCacheControl.type) {
|
|
1931
|
-
case 'max-age':
|
|
1932
|
-
case 'stale-while-revalidate':
|
|
1933
|
-
if (existingCacheControl.maxAge !== 0) {
|
|
1934
|
-
return {
|
|
1935
|
-
...existingCacheControl,
|
|
1936
|
-
maxAge: 0,
|
|
1937
|
-
};
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
return undefined; // No-op: no changes
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1943
1925
|
/**
|
|
1944
1926
|
* A class that allows the execution of requested cache control strategies,
|
|
1945
1927
|
* while also enforcing the canonical cache control metadata.
|
|
@@ -1948,16 +1930,16 @@ class CacheController {
|
|
|
1948
1930
|
constructor(services) {
|
|
1949
1931
|
this.services = services;
|
|
1950
1932
|
}
|
|
1951
|
-
execute(config,
|
|
1952
|
-
const strategy = this.getCacheControlStrategy(config,
|
|
1933
|
+
execute(config, requestRunner, options) {
|
|
1934
|
+
const strategy = this.getCacheControlStrategy(config, requestRunner);
|
|
1953
1935
|
return strategy.execute(options);
|
|
1954
1936
|
}
|
|
1955
|
-
getCacheControlStrategy(config,
|
|
1937
|
+
getCacheControlStrategy(config, requestRunner) {
|
|
1956
1938
|
if (config.type === 'max-age') {
|
|
1957
|
-
return new MaxAgeCacheControlStrategy(this.services, config,
|
|
1939
|
+
return new MaxAgeCacheControlStrategy(this.services, config, requestRunner);
|
|
1958
1940
|
}
|
|
1959
1941
|
else if (config.type === 'no-cache') {
|
|
1960
|
-
return new NoCacheCacheControlStrategy(this.services, config,
|
|
1942
|
+
return new NoCacheCacheControlStrategy(this.services, config, requestRunner);
|
|
1961
1943
|
}
|
|
1962
1944
|
throw new Error(`Unknown cache control strategy ${config.type}`);
|
|
1963
1945
|
}
|
|
@@ -1966,39 +1948,22 @@ class CacheController {
|
|
|
1966
1948
|
* Returns an async generator that yields `[key, entry]`.
|
|
1967
1949
|
*/
|
|
1968
1950
|
async *find(query) {
|
|
1969
|
-
|
|
1970
|
-
const predicate = queryToPredicate(query);
|
|
1971
|
-
const filteredEntries = cache.filter(predicate).entries();
|
|
1972
|
-
for (const entry of filteredEntries) {
|
|
1973
|
-
yield entry;
|
|
1974
|
-
}
|
|
1951
|
+
yield* this.services.cacheInclusionPolicy.find(query);
|
|
1975
1952
|
}
|
|
1976
1953
|
/**
|
|
1977
1954
|
* Finds and modifies cache entries that match the given query.
|
|
1978
1955
|
* Extends `find(query)` and returns an async generator of modified keys.
|
|
1979
1956
|
*/
|
|
1980
1957
|
async *findAndModify(query, cacheUpdate) {
|
|
1981
|
-
|
|
1982
|
-
const update = buildUpdate(cacheUpdate, value);
|
|
1983
|
-
switch (update.type) {
|
|
1984
|
-
case 'entry':
|
|
1985
|
-
this.services.cache.set(key, update.entry);
|
|
1986
|
-
yield key;
|
|
1987
|
-
break;
|
|
1988
|
-
case 'metadata':
|
|
1989
|
-
this.services.cache.setMetadata(key, update.metadata);
|
|
1990
|
-
yield key;
|
|
1991
|
-
break;
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1958
|
+
yield* this.services.cacheInclusionPolicy.findAndModify(query, cacheUpdate);
|
|
1994
1959
|
}
|
|
1995
1960
|
}
|
|
1996
1961
|
|
|
1997
|
-
function buildServiceDescriptor$
|
|
1962
|
+
function buildServiceDescriptor$3(cache, cacheInclusionPolicy) {
|
|
1998
1963
|
return {
|
|
1999
1964
|
type: 'cacheController',
|
|
2000
1965
|
version: '1.0',
|
|
2001
|
-
service: new CacheController({ cache }),
|
|
1966
|
+
service: new CacheController({ cache, cacheInclusionPolicy }),
|
|
2002
1967
|
};
|
|
2003
1968
|
}
|
|
2004
1969
|
|
|
@@ -2026,14 +1991,33 @@ class DefaultPubSubService {
|
|
|
2026
1991
|
}
|
|
2027
1992
|
eventTypeSubscriptions.push(subscription);
|
|
2028
1993
|
return () => {
|
|
2029
|
-
this.subscriptions.set(subscription.type,
|
|
1994
|
+
this.subscriptions.set(subscription.type, this.subscriptions.get(subscription.type).filter((value) => value !== subscription));
|
|
2030
1995
|
};
|
|
2031
1996
|
}
|
|
2032
1997
|
publish(event) {
|
|
1998
|
+
const promises = [];
|
|
1999
|
+
const subscriptions = this.getSubscriptions(event);
|
|
2000
|
+
subscriptions.forEach((subscription) => {
|
|
2001
|
+
// need to check that the subscription hasn't been unsubscribed during one of the callbacks
|
|
2002
|
+
if (!this.getSubscriptions(event).includes(subscription)) {
|
|
2003
|
+
return;
|
|
2004
|
+
}
|
|
2005
|
+
// Ensure callback maintains its context
|
|
2006
|
+
const returnVal = subscription.callback.call(subscription, event);
|
|
2007
|
+
if (isPromiseLike(returnVal)) {
|
|
2008
|
+
promises.push(returnVal);
|
|
2009
|
+
}
|
|
2010
|
+
});
|
|
2011
|
+
if (promises.length > 0) {
|
|
2012
|
+
return Promise.all(promises).then(() => undefined);
|
|
2013
|
+
}
|
|
2014
|
+
return resolvedPromiseLike(undefined);
|
|
2015
|
+
}
|
|
2016
|
+
getSubscriptions(event) {
|
|
2033
2017
|
const eventTypeSubscriptions = this.subscriptions.get(event.type);
|
|
2034
2018
|
const wildcardSubscriptions = this.subscriptions.get(EventTypeWildcard);
|
|
2035
2019
|
if (eventTypeSubscriptions === undefined && wildcardSubscriptions === undefined) {
|
|
2036
|
-
return
|
|
2020
|
+
return [];
|
|
2037
2021
|
}
|
|
2038
2022
|
let matchingSubscriptions = [];
|
|
2039
2023
|
if (eventTypeSubscriptions !== undefined) {
|
|
@@ -2045,17 +2029,7 @@ class DefaultPubSubService {
|
|
|
2045
2029
|
});
|
|
2046
2030
|
}
|
|
2047
2031
|
matchingSubscriptions = [...matchingSubscriptions, ...(wildcardSubscriptions || [])];
|
|
2048
|
-
|
|
2049
|
-
matchingSubscriptions.forEach((subscription) => {
|
|
2050
|
-
const returnVal = subscription.callback(event);
|
|
2051
|
-
if (isPromiseLike(returnVal)) {
|
|
2052
|
-
promises.push(returnVal);
|
|
2053
|
-
}
|
|
2054
|
-
});
|
|
2055
|
-
if (promises.length > 0) {
|
|
2056
|
-
return Promise.all(promises).then(() => undefined);
|
|
2057
|
-
}
|
|
2058
|
-
return resolvedPromiseLike(undefined);
|
|
2032
|
+
return matchingSubscriptions;
|
|
2059
2033
|
}
|
|
2060
2034
|
}
|
|
2061
2035
|
/**
|
|
@@ -2063,7 +2037,7 @@ class DefaultPubSubService {
|
|
|
2063
2037
|
*
|
|
2064
2038
|
* @returns default PubSubServiceDescriptor
|
|
2065
2039
|
*/
|
|
2066
|
-
function buildServiceDescriptor$
|
|
2040
|
+
function buildServiceDescriptor$2() {
|
|
2067
2041
|
return {
|
|
2068
2042
|
type: 'pubSub',
|
|
2069
2043
|
version: '1.0',
|
|
@@ -2071,6 +2045,83 @@ function buildServiceDescriptor$1() {
|
|
|
2071
2045
|
};
|
|
2072
2046
|
}
|
|
2073
2047
|
|
|
2048
|
+
/**
|
|
2049
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
2050
|
+
* All rights reserved.
|
|
2051
|
+
* For full license text, see the LICENSE.txt file
|
|
2052
|
+
*/
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
/**
|
|
2056
|
+
* An implementation of StreamingCommand that handles NDJSON streams.
|
|
2057
|
+
*/
|
|
2058
|
+
class NDJSONCommand extends StreamingCommand {
|
|
2059
|
+
constructor(services) {
|
|
2060
|
+
super(services);
|
|
2061
|
+
this.services = services;
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* Decodes the bytes returned by fetch into the correct shape.
|
|
2065
|
+
*
|
|
2066
|
+
* @param byteStream ReadableStream<Uint8Array> returned by fetch
|
|
2067
|
+
* @returns ReadableStream<T> that will be the result of the Command
|
|
2068
|
+
*/
|
|
2069
|
+
decodeByteStream(byteStream) {
|
|
2070
|
+
return this.decodeNDJSONStream(byteStream
|
|
2071
|
+
// eslint-disable-next-line no-undef
|
|
2072
|
+
.pipeThrough(new TextDecoderStream())
|
|
2073
|
+
.pipeThrough(new NDJSONParsingStream()));
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
/**
|
|
2077
|
+
* A TransformStream that parses NDJSON data according to the NDJSON spec:
|
|
2078
|
+
* https://github.com/ndjson/ndjson-spec
|
|
2079
|
+
*/
|
|
2080
|
+
class NDJSONParsingStream extends TransformStream {
|
|
2081
|
+
constructor() {
|
|
2082
|
+
let partialLine = '';
|
|
2083
|
+
super({
|
|
2084
|
+
transform(chunk, controller) {
|
|
2085
|
+
const text = partialLine + chunk;
|
|
2086
|
+
const lines = text.split(/\r?\n/);
|
|
2087
|
+
partialLine = lines.pop() || '';
|
|
2088
|
+
for (const line of lines) {
|
|
2089
|
+
const trimmed = line.trim();
|
|
2090
|
+
if (trimmed === '')
|
|
2091
|
+
continue;
|
|
2092
|
+
try {
|
|
2093
|
+
const parsed = JSON.parse(trimmed);
|
|
2094
|
+
controller.enqueue(parsed);
|
|
2095
|
+
}
|
|
2096
|
+
catch (e) {
|
|
2097
|
+
throw new Error(`Invalid NDJSON line: ${line}`);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
},
|
|
2101
|
+
flush(controller) {
|
|
2102
|
+
const trimmed = partialLine.trim();
|
|
2103
|
+
if (trimmed !== '') {
|
|
2104
|
+
try {
|
|
2105
|
+
const parsed = JSON.parse(trimmed);
|
|
2106
|
+
controller.enqueue(parsed);
|
|
2107
|
+
}
|
|
2108
|
+
catch (e) {
|
|
2109
|
+
throw new Error(`Invalid NDJSON final line: ${partialLine}`);
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
},
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
function buildServiceDescriptor$1() {
|
|
2118
|
+
return {
|
|
2119
|
+
type: 'NDJSONCommandBaseClass',
|
|
2120
|
+
version: '1.0',
|
|
2121
|
+
service: NDJSONCommand,
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2074
2125
|
/**
|
|
2075
2126
|
* Copyright (c) 2022, Salesforce, Inc.,
|
|
2076
2127
|
* All rights reserved.
|
|
@@ -2621,7 +2672,7 @@ var TypeCheckShapes;
|
|
|
2621
2672
|
TypeCheckShapes[TypeCheckShapes["Integer"] = 3] = "Integer";
|
|
2622
2673
|
TypeCheckShapes[TypeCheckShapes["Unsupported"] = 4] = "Unsupported";
|
|
2623
2674
|
})(TypeCheckShapes || (TypeCheckShapes = {}));
|
|
2624
|
-
// engine version: 0.
|
|
2675
|
+
// engine version: 0.157.1-dev5-f6578042
|
|
2625
2676
|
|
|
2626
2677
|
const { keys: keys$1 } = Object;
|
|
2627
2678
|
|
|
@@ -2873,7 +2924,9 @@ function buildCopilotFetchServiceDescriptor(logger) {
|
|
|
2873
2924
|
if (!body.instanceConfig) {
|
|
2874
2925
|
body.instanceConfig = {};
|
|
2875
2926
|
}
|
|
2876
|
-
body.instanceConfig.endpoint
|
|
2927
|
+
if (!body.instanceConfig.endpoint) {
|
|
2928
|
+
body.instanceConfig.endpoint = token.decodedInfo.iss;
|
|
2929
|
+
}
|
|
2877
2930
|
}
|
|
2878
2931
|
return [
|
|
2879
2932
|
args[0],
|
|
@@ -5606,7 +5659,7 @@ function getEnvironmentSetting(name) {
|
|
|
5606
5659
|
}
|
|
5607
5660
|
return undefined;
|
|
5608
5661
|
}
|
|
5609
|
-
// version: 1.354.0-
|
|
5662
|
+
// version: 1.354.0-dev20-c23c23e6bf
|
|
5610
5663
|
|
|
5611
5664
|
const forceRecordTransactionsDisabled = getEnvironmentSetting(EnvironmentSettings.ForceRecordTransactionsDisabled);
|
|
5612
5665
|
//TODO: Some duplication here that can be most likely moved to a util class
|
|
@@ -6017,6 +6070,190 @@ class PredictionsReadyManager {
|
|
|
6017
6070
|
}
|
|
6018
6071
|
}
|
|
6019
6072
|
|
|
6073
|
+
/**
|
|
6074
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
6075
|
+
* All rights reserved.
|
|
6076
|
+
* For full license text, see the LICENSE.txt file
|
|
6077
|
+
*/
|
|
6078
|
+
|
|
6079
|
+
|
|
6080
|
+
/**
|
|
6081
|
+
* CacheInclusionPolicy is an interface for accessing the cache
|
|
6082
|
+
* and synchronizing the cache data with another external cache.
|
|
6083
|
+
*
|
|
6084
|
+
* https://en.wikipedia.org/wiki/Cache_inclusion_policy
|
|
6085
|
+
*/
|
|
6086
|
+
class CacheInclusionPolicyService {
|
|
6087
|
+
}
|
|
6088
|
+
|
|
6089
|
+
const isAndQuery = (query) => '$and' in query;
|
|
6090
|
+
const isOrQuery = (query) => '$or' in query;
|
|
6091
|
+
const isNotQuery = (query) => '$not' in query;
|
|
6092
|
+
const matchesMetadata = (metadataQuery, cacheControl) => {
|
|
6093
|
+
var _a;
|
|
6094
|
+
if ('cacheControlType' in metadataQuery &&
|
|
6095
|
+
cacheControl.type !== metadataQuery.cacheControlType.$eq) {
|
|
6096
|
+
return false;
|
|
6097
|
+
}
|
|
6098
|
+
if ('maxAge' in metadataQuery && cacheControl.type === 'max-age') {
|
|
6099
|
+
const maxAge = (_a = cacheControl.maxAge) !== null && _a !== void 0 ? _a : 0;
|
|
6100
|
+
if ((metadataQuery.maxAge.$gte !== undefined && maxAge < metadataQuery.maxAge.$gte) ||
|
|
6101
|
+
(metadataQuery.maxAge.$lte !== undefined && maxAge > metadataQuery.maxAge.$lte)) {
|
|
6102
|
+
return false;
|
|
6103
|
+
}
|
|
6104
|
+
}
|
|
6105
|
+
return true;
|
|
6106
|
+
};
|
|
6107
|
+
function queryToPredicate(query) {
|
|
6108
|
+
return (key, entry) => {
|
|
6109
|
+
if (!query)
|
|
6110
|
+
return false;
|
|
6111
|
+
if (isAndQuery(query))
|
|
6112
|
+
return query.$and.every((subQuery) => queryToPredicate(subQuery)(key, entry));
|
|
6113
|
+
if (isOrQuery(query))
|
|
6114
|
+
return query.$or.some((subQuery) => queryToPredicate(subQuery)(key, entry));
|
|
6115
|
+
if (isNotQuery(query))
|
|
6116
|
+
return !queryToPredicate(query.$not)(key, entry);
|
|
6117
|
+
if ('key' in query)
|
|
6118
|
+
return matchesKey(query.key, key);
|
|
6119
|
+
if ('metadata' in query)
|
|
6120
|
+
return matchesMetadata(query.metadata, entry.metadata.cacheControl);
|
|
6121
|
+
if ('value' in query)
|
|
6122
|
+
return false; // TODO: Not implemented
|
|
6123
|
+
throw new Error('Unknown Query Operation');
|
|
6124
|
+
};
|
|
6125
|
+
}
|
|
6126
|
+
function matchesKey(keyQuery, key) {
|
|
6127
|
+
if ('$regex' in keyQuery) {
|
|
6128
|
+
return keyQuery.$regex.test(key);
|
|
6129
|
+
}
|
|
6130
|
+
return false;
|
|
6131
|
+
}
|
|
6132
|
+
|
|
6133
|
+
/**
|
|
6134
|
+
* Processes a cache update operation and determines the appropriate modification.
|
|
6135
|
+
*
|
|
6136
|
+
* This function analyzes the provided `update` and the `existing` cache entry
|
|
6137
|
+
* to determine the necessary update type. It returns one of three possible outcomes:
|
|
6138
|
+
*
|
|
6139
|
+
* - `{ type: 'entry', entry }`: A full cache entry update, including both value and metadata.
|
|
6140
|
+
* - `{ type: 'metadata', metadata }`: A metadata-only update, leaving the value unchanged.
|
|
6141
|
+
* - `{ type: 'no-op' }`: No changes are needed, and the cache should remain as is.
|
|
6142
|
+
*
|
|
6143
|
+
* @param update - The cache update operation to apply.
|
|
6144
|
+
* @param existing - The existing cache entry being modified.
|
|
6145
|
+
* @returns An object indicating the type of update:
|
|
6146
|
+
* - A full cache entry update (`type: 'entry'`)
|
|
6147
|
+
* - A metadata-only update (`type: 'metadata'`)
|
|
6148
|
+
* - A no-op (`type: 'no-op'`) if no changes are required.
|
|
6149
|
+
*/
|
|
6150
|
+
function buildUpdate(update, existing) {
|
|
6151
|
+
switch (update.type) {
|
|
6152
|
+
case 'invalidate':
|
|
6153
|
+
const updatedCacheControl = buildInvalidatedCacheControl(existing.metadata.cacheControl);
|
|
6154
|
+
return updatedCacheControl !== undefined
|
|
6155
|
+
? { type: 'metadata', metadata: updatedCacheControl }
|
|
6156
|
+
: { type: 'no-op' };
|
|
6157
|
+
default:
|
|
6158
|
+
throw new Error(`Invalid update operation: ${update.type}`);
|
|
6159
|
+
}
|
|
6160
|
+
}
|
|
6161
|
+
/**
|
|
6162
|
+
* Builds an updated CacheControlMetadata object that invalidates the cache entry.
|
|
6163
|
+
*
|
|
6164
|
+
* @param existingCacheControl - The current CacheControlMetadata.
|
|
6165
|
+
* @returns A new CacheControlMetadata object with `maxAge` set to `0`, or undefined if no changes are needed.
|
|
6166
|
+
*/
|
|
6167
|
+
function buildInvalidatedCacheControl(existingCacheControl) {
|
|
6168
|
+
switch (existingCacheControl.type) {
|
|
6169
|
+
case 'max-age':
|
|
6170
|
+
case 'stale-while-revalidate':
|
|
6171
|
+
if (existingCacheControl.maxAge !== 0) {
|
|
6172
|
+
return {
|
|
6173
|
+
...existingCacheControl,
|
|
6174
|
+
maxAge: 0,
|
|
6175
|
+
};
|
|
6176
|
+
}
|
|
6177
|
+
}
|
|
6178
|
+
return undefined; // No-op: no changes
|
|
6179
|
+
}
|
|
6180
|
+
|
|
6181
|
+
/**
|
|
6182
|
+
* Implementation of CacheInclusionPolicy that uses a single level, in memory,
|
|
6183
|
+
* synchronous L1 cache.
|
|
6184
|
+
*/
|
|
6185
|
+
class InMemoryCacheInclusionPolicy extends CacheInclusionPolicyService {
|
|
6186
|
+
constructor(services) {
|
|
6187
|
+
super();
|
|
6188
|
+
this.services = services;
|
|
6189
|
+
}
|
|
6190
|
+
/**
|
|
6191
|
+
* Reads data out of a single level in memory store.
|
|
6192
|
+
*/
|
|
6193
|
+
read(options) {
|
|
6194
|
+
const { l1, readFromL1 } = options;
|
|
6195
|
+
// l1 is all we've got
|
|
6196
|
+
return readFromL1(l1);
|
|
6197
|
+
}
|
|
6198
|
+
/**
|
|
6199
|
+
* Writes data to a single level in memory store.
|
|
6200
|
+
*/
|
|
6201
|
+
write(options) {
|
|
6202
|
+
const { l1, writeToL1 } = options;
|
|
6203
|
+
return writeToL1(l1);
|
|
6204
|
+
}
|
|
6205
|
+
/**
|
|
6206
|
+
* Finds cache entries that match the given query.
|
|
6207
|
+
* Returns an async generator that yields `[key, entry]`.
|
|
6208
|
+
*/
|
|
6209
|
+
async *find(query) {
|
|
6210
|
+
const cache = this.services.cache;
|
|
6211
|
+
const predicate = queryToPredicate(query);
|
|
6212
|
+
const filteredEntries = cache.filter(predicate).entries();
|
|
6213
|
+
for (const entry of filteredEntries) {
|
|
6214
|
+
yield entry;
|
|
6215
|
+
}
|
|
6216
|
+
}
|
|
6217
|
+
/**
|
|
6218
|
+
* Finds and modifies cache entries that match the given query.
|
|
6219
|
+
* Extends `find(query)` and returns an async generator of modified keys.
|
|
6220
|
+
*/
|
|
6221
|
+
async *findAndModify(query, cacheUpdate) {
|
|
6222
|
+
const cache = this.services.cache;
|
|
6223
|
+
for await (const [key, value] of this.find(query)) {
|
|
6224
|
+
const update = buildUpdate(cacheUpdate, value);
|
|
6225
|
+
switch (update.type) {
|
|
6226
|
+
case 'entry':
|
|
6227
|
+
this.write({
|
|
6228
|
+
l1: cache,
|
|
6229
|
+
writeToL1: (l1) => resolvedPromiseLike(ok(l1.set(key, update.entry))),
|
|
6230
|
+
});
|
|
6231
|
+
yield key;
|
|
6232
|
+
break;
|
|
6233
|
+
case 'metadata':
|
|
6234
|
+
this.write({
|
|
6235
|
+
l1: cache,
|
|
6236
|
+
writeToL1: (l1) => resolvedPromiseLike(ok(l1.setMetadata(key, update.metadata))),
|
|
6237
|
+
});
|
|
6238
|
+
yield key;
|
|
6239
|
+
break;
|
|
6240
|
+
}
|
|
6241
|
+
}
|
|
6242
|
+
}
|
|
6243
|
+
}
|
|
6244
|
+
/**
|
|
6245
|
+
* Constructs an in-memory-only CacheInclusionPolicy.
|
|
6246
|
+
*
|
|
6247
|
+
* @returns in-memory-only CacheInclusionPolicy
|
|
6248
|
+
*/
|
|
6249
|
+
function buildInMemoryCacheInclusionPolicyService(cache) {
|
|
6250
|
+
return {
|
|
6251
|
+
service: new InMemoryCacheInclusionPolicy({ cache }),
|
|
6252
|
+
type: 'cacheInclusionPolicy',
|
|
6253
|
+
version: '1.0',
|
|
6254
|
+
};
|
|
6255
|
+
}
|
|
6256
|
+
|
|
6020
6257
|
// This code *should* be in lds-network-adapter, but when combined with the Aura
|
|
6021
6258
|
// component test workaround in lds-default-luvio it creates a circular dependecy
|
|
6022
6259
|
// between lds-default-luvio and lds-network-adapter. We do the register on behalf
|
|
@@ -6257,25 +6494,27 @@ function initializeLDS() {
|
|
|
6257
6494
|
// Initializes OneStore in LEX
|
|
6258
6495
|
function initializeOneStore() {
|
|
6259
6496
|
const loggerService = new ConsoleLogger$1('ERROR');
|
|
6260
|
-
const cacheServiceDescriptor = buildServiceDescriptor$
|
|
6261
|
-
const instrumentationServiceDescriptor = buildServiceDescriptor$
|
|
6497
|
+
const cacheServiceDescriptor = buildServiceDescriptor$4();
|
|
6498
|
+
const instrumentationServiceDescriptor = buildServiceDescriptor$5(loggerService);
|
|
6499
|
+
const inMemoryCacheInclusionPolicyServiceDescriptor = buildInMemoryCacheInclusionPolicyService(cacheServiceDescriptor.service);
|
|
6262
6500
|
const services = [
|
|
6263
6501
|
instrumentationServiceDescriptor,
|
|
6264
6502
|
buildUnauthorizedFetchServiceDescriptor(),
|
|
6265
6503
|
buildJwtAuthorizedSfapFetchServiceDescriptor(loggerService),
|
|
6266
6504
|
buildCopilotFetchServiceDescriptor(loggerService),
|
|
6267
6505
|
buildAuraNetworkService(),
|
|
6268
|
-
buildServiceDescriptor$
|
|
6269
|
-
buildServiceDescriptor$
|
|
6270
|
-
buildServiceDescriptor$c(),
|
|
6271
|
-
buildServiceDescriptor$8(),
|
|
6506
|
+
buildServiceDescriptor$6(instrumentationServiceDescriptor.service),
|
|
6507
|
+
buildServiceDescriptor$3(cacheServiceDescriptor.service, inMemoryCacheInclusionPolicyServiceDescriptor.service),
|
|
6272
6508
|
buildServiceDescriptor$d(),
|
|
6509
|
+
buildServiceDescriptor$1(),
|
|
6510
|
+
buildServiceDescriptor$9(),
|
|
6511
|
+
buildServiceDescriptor$e(),
|
|
6512
|
+
buildServiceDescriptor$8(),
|
|
6273
6513
|
buildServiceDescriptor$7(),
|
|
6274
|
-
buildServiceDescriptor$
|
|
6514
|
+
buildServiceDescriptor$c(),
|
|
6275
6515
|
buildServiceDescriptor$b(),
|
|
6276
6516
|
buildServiceDescriptor$a(),
|
|
6277
|
-
buildServiceDescriptor$
|
|
6278
|
-
buildServiceDescriptor$1(),
|
|
6517
|
+
buildServiceDescriptor$2(),
|
|
6279
6518
|
];
|
|
6280
6519
|
setServices(services);
|
|
6281
6520
|
}
|
|
@@ -6298,4 +6537,4 @@ function ldsEngineCreator() {
|
|
|
6298
6537
|
}
|
|
6299
6538
|
|
|
6300
6539
|
export { LexRequestStrategy, PdlRequestPriority, buildPredictorForContext, ldsEngineCreator as default, initializeLDS, initializeOneStore, registerRequestStrategy, saveRequestAsPrediction, unregisterRequestStrategy, whenPredictionsReady };
|
|
6301
|
-
// version: 1.354.0-
|
|
6540
|
+
// version: 1.354.0-dev20-152e5f8922
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/lds-runtime-aura",
|
|
3
|
-
"version": "1.354.0-
|
|
3
|
+
"version": "1.354.0-dev20",
|
|
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,48 @@
|
|
|
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.
|
|
38
|
-
"@luvio/tools-core": "5.
|
|
39
|
-
"@salesforce/lds-adapters-apex": "^1.354.0-
|
|
40
|
-
"@salesforce/lds-adapters-uiapi": "^1.354.0-
|
|
37
|
+
"@luvio/service-provisioner": " 5.40.3-dev2",
|
|
38
|
+
"@luvio/tools-core": " 5.40.3-dev2",
|
|
39
|
+
"@salesforce/lds-adapters-apex": "^1.354.0-dev20",
|
|
40
|
+
"@salesforce/lds-adapters-uiapi": "^1.354.0-dev20",
|
|
41
41
|
"@salesforce/lds-adapters-uiapi-lex": "^1.302.0",
|
|
42
|
-
"@salesforce/lds-ads-bridge": "^1.354.0-
|
|
43
|
-
"@salesforce/lds-aura-storage": "^1.354.0-
|
|
44
|
-
"@salesforce/lds-bindings": "^1.354.0-
|
|
45
|
-
"@salesforce/lds-instrumentation": "^1.354.0-
|
|
46
|
-
"@salesforce/lds-network-aura": "^1.354.0-
|
|
47
|
-
"@salesforce/lds-network-fetch": "^1.354.0-
|
|
42
|
+
"@salesforce/lds-ads-bridge": "^1.354.0-dev20",
|
|
43
|
+
"@salesforce/lds-aura-storage": "^1.354.0-dev20",
|
|
44
|
+
"@salesforce/lds-bindings": "^1.354.0-dev20",
|
|
45
|
+
"@salesforce/lds-instrumentation": "^1.354.0-dev20",
|
|
46
|
+
"@salesforce/lds-network-aura": "^1.354.0-dev20",
|
|
47
|
+
"@salesforce/lds-network-fetch": "^1.354.0-dev20",
|
|
48
48
|
"jwt-encode": "1.0.1"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@luvio/command-aura-network": "5.
|
|
52
|
-
"@luvio/command-aura-normalized-cache-control": "5.
|
|
53
|
-
"@luvio/command-aura-resource-cache-control": "5.
|
|
54
|
-
"@luvio/command-fetch-network": "5.
|
|
55
|
-
"@luvio/command-http-normalized-cache-control": "5.
|
|
56
|
-
"@luvio/command-
|
|
57
|
-
"@luvio/command-
|
|
58
|
-
"@luvio/command-
|
|
59
|
-
"@luvio/
|
|
60
|
-
"@luvio/network-adapter-
|
|
61
|
-
"@luvio/
|
|
62
|
-
"@luvio/service-
|
|
63
|
-
"@luvio/service-cache
|
|
64
|
-
"@luvio/service-
|
|
65
|
-
"@luvio/service-
|
|
66
|
-
"@luvio/service-
|
|
67
|
-
"@luvio/service-
|
|
68
|
-
"@luvio/
|
|
69
|
-
"@
|
|
51
|
+
"@luvio/command-aura-network": " 5.40.3-dev2",
|
|
52
|
+
"@luvio/command-aura-normalized-cache-control": " 5.40.3-dev2",
|
|
53
|
+
"@luvio/command-aura-resource-cache-control": " 5.40.3-dev2",
|
|
54
|
+
"@luvio/command-fetch-network": " 5.40.3-dev2",
|
|
55
|
+
"@luvio/command-http-normalized-cache-control": " 5.40.3-dev2",
|
|
56
|
+
"@luvio/command-ndjson": " 5.40.3-dev2",
|
|
57
|
+
"@luvio/command-network": " 5.40.3-dev2",
|
|
58
|
+
"@luvio/command-sse": " 5.40.3-dev2",
|
|
59
|
+
"@luvio/command-streaming": " 5.40.3-dev2",
|
|
60
|
+
"@luvio/network-adapter-composable": "0.157.1-dev5",
|
|
61
|
+
"@luvio/network-adapter-fetch": "0.157.1-dev5",
|
|
62
|
+
"@luvio/service-aura-network": " 5.40.3-dev2",
|
|
63
|
+
"@luvio/service-cache": " 5.40.3-dev2",
|
|
64
|
+
"@luvio/service-cache-control": " 5.40.3-dev2",
|
|
65
|
+
"@luvio/service-fetch-network": " 5.40.3-dev2",
|
|
66
|
+
"@luvio/service-instrument-command": " 5.40.3-dev2",
|
|
67
|
+
"@luvio/service-pubsub": " 5.40.3-dev2",
|
|
68
|
+
"@luvio/service-store": " 5.40.3-dev2",
|
|
69
|
+
"@luvio/utils": " 5.40.3-dev2",
|
|
70
|
+
"@salesforce/lds-adapters-uiapi-lex": "^1.354.0-dev20"
|
|
70
71
|
},
|
|
71
72
|
"luvioBundlesize": [
|
|
72
73
|
{
|
|
73
74
|
"path": "./dist/ldsEngineCreator.js",
|
|
74
75
|
"maxSize": {
|
|
75
|
-
"none": "
|
|
76
|
-
"min": "
|
|
77
|
-
"compressed": "
|
|
76
|
+
"none": "243 kB",
|
|
77
|
+
"min": "100 kB",
|
|
78
|
+
"compressed": "41 kB"
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
],
|