@salesforce/lds-runtime-aura 1.351.1 → 1.353.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 +218 -76
  2. package/package.json +31 -30
@@ -40,48 +40,6 @@ import { createStorage, clearStorages } from 'force/ldsStorage';
40
40
  import useHttpInsteadAuraTransport from '@salesforce/gate/lds.useHttpInsteadAuraTransport';
41
41
  import { ThirdPartyTracker } from 'instrumentation:beaconLib';
42
42
 
43
- /**
44
- * Copyright (c) 2022, Salesforce, Inc.,
45
- * All rights reserved.
46
- * For full license text, see the LICENSE.txt file
47
- */
48
-
49
- /**
50
- * BaseCommand is an abstract implementation of SubscribableCommand. It adds the
51
- * notions of typed configuration, request context, and a set of runtime services
52
- * to the contract defined by Command/SubscribableCommand.
53
- */
54
- class BaseCommand {
55
- }
56
-
57
- /**
58
- * Copyright (c) 2022, Salesforce, Inc.,
59
- * All rights reserved.
60
- * For full license text, see the LICENSE.txt file
61
- */
62
-
63
-
64
- /**
65
- * An implementation of BaseCommand that makes network requests but does not try to
66
- * use the store.
67
- */
68
- class NetworkCommand extends BaseCommand {
69
- constructor(services) {
70
- super();
71
- this.services = services;
72
- }
73
- execute() {
74
- return this.fetch();
75
- }
76
- }
77
- function buildServiceDescriptor$d() {
78
- return {
79
- type: 'networkCommandBaseClass',
80
- version: '1.0',
81
- service: NetworkCommand,
82
- };
83
- }
84
-
85
43
  /**
86
44
  * Copyright (c) 2022, Salesforce, Inc.,
87
45
  * All rights reserved.
@@ -159,6 +117,26 @@ class Err {
159
117
  }
160
118
  const ok = (value) => new Ok(value);
161
119
  const err = (err) => new Err(err);
120
+ function isSubscribableResult(x) {
121
+ if (typeof x !== 'object' || x === null) {
122
+ return false;
123
+ }
124
+ if ('isOk' in x && typeof x.isOk === 'function') {
125
+ if (x.isOk()) {
126
+ return ('value' in x &&
127
+ typeof x.value === 'object' &&
128
+ x.value !== null &&
129
+ 'subscribe' in x.value &&
130
+ typeof x.value.subscribe === 'function' &&
131
+ 'refresh' in x.value &&
132
+ typeof x.value.refresh === 'function');
133
+ }
134
+ else {
135
+ return 'error' in x;
136
+ }
137
+ }
138
+ return false;
139
+ }
162
140
 
163
141
  /**
164
142
  * Returns a PromiseLike object that resolves with the specified result.
@@ -358,6 +336,89 @@ var HttpStatusCode$2;
358
336
  HttpStatusCode[HttpStatusCode["GatewayTimeout"] = 504] = "GatewayTimeout";
359
337
  })(HttpStatusCode$2 || (HttpStatusCode$2 = {}));
360
338
 
339
+ /**
340
+ * Copyright (c) 2022, Salesforce, Inc.,
341
+ * All rights reserved.
342
+ * For full license text, see the LICENSE.txt file
343
+ */
344
+
345
+ /**
346
+ * BaseCommand is an abstract implementation of SubscribableCommand. It adds the
347
+ * notions of typed configuration, request context, and a set of runtime services
348
+ * to the contract defined by Command/SubscribableCommand.
349
+ */
350
+ class BaseCommand {
351
+ }
352
+
353
+ /**
354
+ * Copyright (c) 2022, Salesforce, Inc.,
355
+ * All rights reserved.
356
+ * For full license text, see the LICENSE.txt file
357
+ */
358
+
359
+
360
+ /**
361
+ * An implementation of BaseCommand that makes network requests but does not try to
362
+ * use the store.
363
+ */
364
+ class NetworkCommand extends BaseCommand {
365
+ constructor(services) {
366
+ super();
367
+ this.services = services;
368
+ this.subscriptions = [];
369
+ this.exposeSubscribeAndRefresh = false;
370
+ }
371
+ execute() {
372
+ const result = this.fetch();
373
+ if (this.exposeSubscribeAndRefresh) {
374
+ return this.fetchSubscribableResult(result);
375
+ }
376
+ return result;
377
+ }
378
+ fetchSubscribableResult(res) {
379
+ return res.then((networkResult) => {
380
+ if (networkResult.isErr()) {
381
+ return err(networkResult.error);
382
+ }
383
+ else {
384
+ const data = networkResult.value;
385
+ return ok({
386
+ data,
387
+ subscribe: (cb) => {
388
+ this.subscriptions.push(cb);
389
+ return () => {
390
+ this.subscriptions = this.subscriptions.filter((cb2) => cb2 !== cb);
391
+ };
392
+ },
393
+ refresh: () => this.refresh(),
394
+ });
395
+ }
396
+ });
397
+ }
398
+ refresh() {
399
+ return this.execute().then((newResult) => {
400
+ if (newResult.isOk()) {
401
+ if (isSubscribableResult(newResult)) {
402
+ const value = newResult.value;
403
+ this.subscriptions.forEach((cb) => {
404
+ cb(ok(value.data));
405
+ });
406
+ }
407
+ return ok(undefined);
408
+ }
409
+ return err(newResult.error);
410
+ });
411
+ }
412
+ async afterRequestHooks(_options) { }
413
+ }
414
+ function buildServiceDescriptor$d() {
415
+ return {
416
+ type: 'networkCommandBaseClass',
417
+ version: '1.0',
418
+ service: NetworkCommand,
419
+ };
420
+ }
421
+
361
422
  /**
362
423
  * Copyright (c) 2022, Salesforce, Inc.,
363
424
  * All rights reserved.
@@ -385,17 +446,26 @@ class AuraNetworkCommand extends NetworkCommand {
385
446
  convertAuraResponseToData(responsePromise, coerceError) {
386
447
  return responsePromise
387
448
  .then((response) => {
388
- 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);
389
455
  })
390
456
  .catch((error) => {
391
457
  if (!error || !error.getError) {
392
458
  return err(toError('Failed to get error from response'));
393
459
  }
394
- const actionErrors = error.getError();
395
- if (actionErrors.length > 0) {
396
- 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
+ }
397
468
  }
398
- return err(toError('Error fetching component'));
399
469
  });
400
470
  }
401
471
  fetch() {
@@ -429,19 +499,31 @@ class CacheControlCommand extends BaseCommand {
429
499
  constructor(services) {
430
500
  super();
431
501
  this.services = services;
502
+ this.operationType = 'query';
432
503
  this.rebuildUnsubscribe = () => { };
433
504
  this.refreshUnsubscribe = () => { };
505
+ this.lastEmittedData = undefined;
506
+ this.subscribeToMostRecentKeys = () => undefined;
434
507
  this.subscriptions = [];
435
508
  this.instantiationTime = Date.now() / 1000; // in seconds
436
509
  }
437
510
  execute(overrides) {
511
+ this.subscribeToMostRecentKeys = () => undefined;
438
512
  this.rebuildUnsubscribe();
439
513
  this.refreshUnsubscribe();
440
514
  const mergedCacheControlConfig = mergeCacheControlConfigs(this.cacheControlStrategyConfig, overrides);
441
515
  const resultPromise = this.services.cacheController.execute(mergedCacheControlConfig, (cache) => this.buildRequestRunner(cache), {
442
516
  instrumentationAttributes: this.instrumentationAttributes,
443
517
  });
444
- return resultPromise;
518
+ return resultPromise.then((result) => {
519
+ if (this.operationType === 'query') {
520
+ this.subscribeToMostRecentKeys();
521
+ }
522
+ if (result.isOk() && this.lastEmittedData === undefined) {
523
+ this.lastEmittedData = result.value.data;
524
+ }
525
+ return result;
526
+ });
445
527
  }
446
528
  // TODO: This should likely be abstract in v2. For v1, provide default comparison logic.
447
529
  equals(result1, result2) {
@@ -454,6 +536,15 @@ class CacheControlCommand extends BaseCommand {
454
536
  writeToCache: (networkResult) => this.writeToCacheAndPublish(cache, networkResult),
455
537
  };
456
538
  }
539
+ async afterRequestHooks(_options) { }
540
+ refresh() {
541
+ return this.rerun({ cacheControlConfig: { type: 'no-cache' } }).then((result) => {
542
+ if (result.isErr()) {
543
+ return result;
544
+ }
545
+ return ok(undefined);
546
+ });
547
+ }
457
548
  // TODO: This is added as a temporary measure for ensuring that cache write events are
458
549
  // published to pubSub. A follow-up will be required to find the right home for this logic.
459
550
  writeToCacheAndPublish(cache, networkResult) {
@@ -478,10 +569,11 @@ class CacheControlCommand extends BaseCommand {
478
569
  else {
479
570
  const data = readResult.value;
480
571
  if (data !== undefined) {
481
- this.subscribeToKeys(recordableCache.keysRead, data);
572
+ this.subscribeToMostRecentKeys = () => this.subscribeToKeys(recordableCache.keysRead);
482
573
  return ok({
483
574
  data,
484
575
  subscribe: this.buildSubscribe(),
576
+ refresh: () => this.refresh(),
485
577
  });
486
578
  }
487
579
  return ok(undefined);
@@ -505,29 +597,36 @@ class CacheControlCommand extends BaseCommand {
505
597
  };
506
598
  };
507
599
  }
508
- subscribeToKeys(keysRead, lastResult) {
600
+ rerun(overrides) {
601
+ return this.execute(overrides).then((result) => {
602
+ if (result.isErr()) {
603
+ this.invokeConsumerCallbacks(result);
604
+ return result;
605
+ }
606
+ if (!this.equals(this.lastEmittedData, result.value.data)) {
607
+ this.lastEmittedData = result.value.data;
608
+ this.invokeConsumerCallbacks(ok(result.value.data));
609
+ }
610
+ return result;
611
+ });
612
+ }
613
+ subscribeToKeys(keysRead) {
509
614
  const { pubSub } = this.services;
510
615
  if (!pubSub) {
511
616
  return;
512
617
  }
513
- const executeAndHandleResult = (overrides) => {
514
- return this.execute(overrides).then((result) => {
515
- if (result.isErr()) {
516
- this.invokeConsumerCallbacks(result);
517
- return;
518
- }
519
- if (!this.equals(lastResult, result.value.data)) {
520
- this.invokeConsumerCallbacks(ok(result.value.data));
521
- }
522
- });
523
- };
524
618
  const createKeySubscriber = (type, callback) => pubSub.subscribe({
525
619
  type,
526
620
  predicate: (event) => setOverlaps(event.data, keysRead),
527
621
  callback,
528
622
  });
529
- this.rebuildUnsubscribe = createKeySubscriber('cacheUpdate', () => executeAndHandleResult({ now: this.instantiationTime }));
530
- this.refreshUnsubscribe = createKeySubscriber('cacheInvalidation', () => executeAndHandleResult());
623
+ // Unsubscribe to be sure that this command didn't re-execute and re-subscribe in between the start of command execution and now
624
+ // it shouldn't be possible for this command to resubscribe between the beginning of execution and now
625
+ // ...but lets be defensive.
626
+ this.rebuildUnsubscribe();
627
+ this.refreshUnsubscribe();
628
+ this.rebuildUnsubscribe = createKeySubscriber('cacheUpdate', () => this.rerun({ now: this.instantiationTime }).then(() => undefined));
629
+ this.refreshUnsubscribe = createKeySubscriber('cacheInvalidation', () => this.rerun().then(() => undefined));
531
630
  }
532
631
  invokeConsumerCallbacks(data) {
533
632
  this.subscriptions.forEach((cb) => {
@@ -614,17 +713,26 @@ class AuraCacheControlCommand extends CacheControlCommand {
614
713
  convertAuraResponseToData(responsePromise, coerceError) {
615
714
  return responsePromise
616
715
  .then((response) => {
617
- return ok(response.getReturnValue());
716
+ const auraReturnValue = response.getReturnValue();
717
+ try {
718
+ this.afterRequestHooks({ statusCode: 200 }); // Treat all aura success as 200
719
+ }
720
+ catch (e) { }
721
+ return ok(auraReturnValue);
618
722
  })
619
723
  .catch((error) => {
620
724
  if (!error || !error.getError) {
621
725
  return err(toError('Failed to get error from response'));
622
726
  }
623
- const actionErrors = error.getError();
624
- if (actionErrors.length > 0) {
625
- return err(coerceError(actionErrors));
727
+ else {
728
+ const actionErrors = error.getError();
729
+ if (actionErrors.length > 0) {
730
+ return err(coerceError(actionErrors));
731
+ }
732
+ else {
733
+ return err(toError('Error fetching component'));
734
+ }
626
735
  }
627
- return err(toError('Error fetching component'));
628
736
  });
629
737
  }
630
738
  }
@@ -750,10 +858,27 @@ class HttpCacheControlCommand extends CacheControlCommand {
750
858
  convertFetchResponseToData(response) {
751
859
  return response.then((response) => {
752
860
  if (response.ok) {
753
- return response.json().then((json) => ok(json), (reason) => err(toError(reason)));
861
+ return response
862
+ .json()
863
+ .then((json) => ok(json), (reason) => err(toError(reason)))
864
+ .finally(() => {
865
+ try {
866
+ this.afterRequestHooks({ statusCode: response.status });
867
+ }
868
+ catch (e) { }
869
+ });
754
870
  }
755
871
  else {
756
- return this.coerceError(response).then((coercedError) => err(coercedError));
872
+ return this.coerceError(response)
873
+ .then((coercedError) => {
874
+ return err(coercedError);
875
+ })
876
+ .finally(() => {
877
+ try {
878
+ this.afterRequestHooks({ statusCode: response.status });
879
+ }
880
+ catch (e) { }
881
+ });
757
882
  }
758
883
  }, (reason) => err(toError(reason)));
759
884
  }
@@ -825,10 +950,27 @@ class FetchNetworkCommand extends NetworkCommand {
825
950
  convertFetchResponseToData(response) {
826
951
  return response.then((response) => {
827
952
  if (response.ok) {
828
- return response.json().then((json) => ok(json), (reason) => err(toError(reason)));
953
+ return response
954
+ .json()
955
+ .then((json) => ok(json), (reason) => err(toError(reason)))
956
+ .finally(() => {
957
+ try {
958
+ this.afterRequestHooks({ statusCode: response.status });
959
+ }
960
+ catch (e) { }
961
+ });
829
962
  }
830
963
  else {
831
- return this.coerceError(response).then((coercedError) => err(coercedError));
964
+ return this.coerceError(response)
965
+ .then((coercedError) => {
966
+ return err(coercedError);
967
+ })
968
+ .finally(() => {
969
+ try {
970
+ this.afterRequestHooks({ statusCode: response.status });
971
+ }
972
+ catch (e) { }
973
+ });
832
974
  }
833
975
  }, (reason) => err(toError(reason)));
834
976
  }
@@ -1596,8 +1738,8 @@ class CacheControlStrategy {
1596
1738
  return [
1597
1739
  (cacheControlMetadata) => cacheControlMetadata.type === 'max-age' &&
1598
1740
  this.config.now > cacheControlMetadata.generatedTime + cacheControlMetadata.maxAge,
1599
- (cacheControlMetadata) => cacheControlMetadata.type === 'no-cache' ||
1600
- cacheControlMetadata.type === 'no-store',
1741
+ (cacheControlMetadata) => cacheControlMetadata.type === 'max-age' && cacheControlMetadata.maxAge <= 0,
1742
+ (cacheControlMetadata) => cacheControlMetadata.type === 'no-store',
1601
1743
  ];
1602
1744
  }
1603
1745
  }
@@ -5454,7 +5596,7 @@ function getEnvironmentSetting(name) {
5454
5596
  }
5455
5597
  return undefined;
5456
5598
  }
5457
- // version: 1.351.1-3c191568b9
5599
+ // version: 1.353.0-330d59cfcb
5458
5600
 
5459
5601
  const forceRecordTransactionsDisabled = getEnvironmentSetting(EnvironmentSettings.ForceRecordTransactionsDisabled);
5460
5602
  //TODO: Some duplication here that can be most likely moved to a util class
@@ -6146,4 +6288,4 @@ function ldsEngineCreator() {
6146
6288
  }
6147
6289
 
6148
6290
  export { LexRequestStrategy, PdlRequestPriority, buildPredictorForContext, ldsEngineCreator as default, initializeLDS, initializeOneStore, registerRequestStrategy, saveRequestAsPrediction, unregisterRequestStrategy, whenPredictionsReady };
6149
- // version: 1.351.1-fe0298cc85
6291
+ // version: 1.353.0-cc9b469dc4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-aura",
3
- "version": "1.351.1",
3
+ "version": "1.353.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS engine for Aura runtime",
6
6
  "main": "dist/ldsEngineCreator.js",
@@ -34,46 +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.35.0",
38
- "@salesforce/lds-adapters-apex": "^1.351.1",
39
- "@salesforce/lds-adapters-uiapi": "^1.351.1",
37
+ "@luvio/service-provisioner": "5.38.0",
38
+ "@luvio/tools-core": "5.38.0",
39
+ "@salesforce/lds-adapters-apex": "^1.353.0",
40
+ "@salesforce/lds-adapters-uiapi": "^1.353.0",
40
41
  "@salesforce/lds-adapters-uiapi-lex": "^1.302.0",
41
- "@salesforce/lds-ads-bridge": "^1.351.1",
42
- "@salesforce/lds-aura-storage": "^1.351.1",
43
- "@salesforce/lds-bindings": "^1.351.1",
44
- "@salesforce/lds-instrumentation": "^1.351.1",
45
- "@salesforce/lds-network-aura": "^1.351.1",
46
- "@salesforce/lds-network-fetch": "^1.351.1",
42
+ "@salesforce/lds-ads-bridge": "^1.353.0",
43
+ "@salesforce/lds-aura-storage": "^1.353.0",
44
+ "@salesforce/lds-bindings": "^1.353.0",
45
+ "@salesforce/lds-instrumentation": "^1.353.0",
46
+ "@salesforce/lds-network-aura": "^1.353.0",
47
+ "@salesforce/lds-network-fetch": "^1.353.0",
47
48
  "jwt-encode": "1.0.1"
48
49
  },
49
50
  "dependencies": {
50
- "@luvio/command-aura-network": "5.35.0",
51
- "@luvio/command-aura-normalized-cache-control": "5.35.0",
52
- "@luvio/command-aura-resource-cache-control": "5.35.0",
53
- "@luvio/command-fetch-network": "5.35.0",
54
- "@luvio/command-http-normalized-cache-control": "5.35.0",
55
- "@luvio/command-network": "5.35.0",
56
- "@luvio/command-sse": "5.35.0",
57
- "@luvio/command-streaming": "5.35.0",
51
+ "@luvio/command-aura-network": "5.38.0",
52
+ "@luvio/command-aura-normalized-cache-control": "5.38.0",
53
+ "@luvio/command-aura-resource-cache-control": "5.38.0",
54
+ "@luvio/command-fetch-network": "5.38.0",
55
+ "@luvio/command-http-normalized-cache-control": "5.38.0",
56
+ "@luvio/command-network": "5.38.0",
57
+ "@luvio/command-sse": "5.38.0",
58
+ "@luvio/command-streaming": "5.38.0",
58
59
  "@luvio/network-adapter-composable": "0.156.7",
59
60
  "@luvio/network-adapter-fetch": "0.156.7",
60
- "@luvio/service-aura-network": "5.35.0",
61
- "@luvio/service-cache": "5.35.0",
62
- "@luvio/service-cache-control": "5.35.0",
63
- "@luvio/service-fetch-network": "5.35.0",
64
- "@luvio/service-instrument-command": "5.35.0",
65
- "@luvio/service-pubsub": "5.35.0",
66
- "@luvio/service-store": "5.35.0",
67
- "@luvio/utils": "5.35.0",
68
- "@salesforce/lds-adapters-uiapi-lex": "^1.351.1"
61
+ "@luvio/service-aura-network": "5.38.0",
62
+ "@luvio/service-cache": "5.38.0",
63
+ "@luvio/service-cache-control": "5.38.0",
64
+ "@luvio/service-fetch-network": "5.38.0",
65
+ "@luvio/service-instrument-command": "5.38.0",
66
+ "@luvio/service-pubsub": "5.38.0",
67
+ "@luvio/service-store": "5.38.0",
68
+ "@luvio/utils": "5.38.0",
69
+ "@salesforce/lds-adapters-uiapi-lex": "^1.353.0"
69
70
  },
70
71
  "luvioBundlesize": [
71
72
  {
72
73
  "path": "./dist/ldsEngineCreator.js",
73
74
  "maxSize": {
74
- "none": "229.5 kB",
75
- "min": "94.7 kB",
76
- "compressed": "39.5 kB"
75
+ "none": "235 kB",
76
+ "min": "97 kB",
77
+ "compressed": "40 kB"
77
78
  }
78
79
  }
79
80
  ],