@salesforce/lds-runtime-aura 1.256.0 → 1.258.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.
@@ -211,10 +211,17 @@ class ApplicationPredictivePrefetcher {
211
211
  this.queuedPredictionRequests.push(...predictedRequests);
212
212
  return Promise.all(predictedRequests.map((request) => this.requestRunner.runRequest(request))).then();
213
213
  }
214
- async getSimilarPageRequests() {
214
+ hasPredictions() {
215
+ const exactPageRequests = this.repository.getPageRequests(this.context) || [];
216
+ const similarPageRequests = this.page.similarContext !== undefined
217
+ ? this.repository.getPageRequests(this.page.similarContext)
218
+ : [];
219
+ return exactPageRequests.length > 0 || similarPageRequests.length > 0;
220
+ }
221
+ getSimilarPageRequests() {
215
222
  let resolvedSimilarPageRequests = [];
216
223
  if (this.page.similarContext !== undefined) {
217
- const similarPageRequests = await this.repository.getPageRequests(this.page.similarContext);
224
+ const similarPageRequests = this.repository.getPageRequests(this.page.similarContext);
218
225
  if (similarPageRequests !== undefined) {
219
226
  resolvedSimilarPageRequests = similarPageRequests.map((request) => this.page.resolveSimilarRequest(request));
220
227
  }
@@ -363,13 +370,12 @@ class PrefetchRepository {
363
370
  });
364
371
  this.requestBuffer.set(identifier, batchForKey);
365
372
  }
366
- async getPage(key) {
373
+ getPage(key) {
367
374
  const identifier = stableJSONStringify$1(key);
368
- const rawPage = await this.storage.get(identifier);
369
- return rawPage;
375
+ return this.storage.get(identifier);
370
376
  }
371
- async getPageRequests(key) {
372
- const page = await this.getPage(key);
377
+ getPageRequests(key) {
378
+ const page = this.getPage(key);
373
379
  if (page === undefined) {
374
380
  return [];
375
381
  }
@@ -703,7 +709,7 @@ class InMemoryPrefetchStorage {
703
709
  return Promise.resolve();
704
710
  }
705
711
  get(key) {
706
- return Promise.resolve(this.data[key]);
712
+ return this.data[key];
707
713
  }
708
714
  }
709
715
 
@@ -732,6 +738,18 @@ class AuraPrefetchStorage {
732
738
  constructor(auraStorage, inMemoryStorage) {
733
739
  this.auraStorage = auraStorage;
734
740
  this.inMemoryStorage = inMemoryStorage;
741
+ /**
742
+ * Because of aura is an event loop hog and we therefore need to minimize asynchronicity in LEX,
743
+ * we need need to preload predictions and treat read operations sync. Not making it sync, will cause
744
+ * some request to be sent the network when they could be dedupe against those from the predictions.
745
+ *
746
+ * Drawbacks of this approach:
747
+ * 1. Loading all of aura storage into memory and then updating it based on changes to that in memory
748
+ * representation means that updates to predictions in aura storage across different tabs will result
749
+ * in overwrites, not graceful merges of predictions.
750
+ * 2. If whoever is consuming this tries to get and run predictions before this is done loading,
751
+ * then they will (potentially incorrectly) think that we don't have any predictions.
752
+ */
735
753
  auraStorage.getAll().then((results) => {
736
754
  ObjectKeys(results).forEach((key) => this.inMemoryStorage.set(key, results[key]));
737
755
  });
@@ -746,10 +764,9 @@ class AuraPrefetchStorage {
746
764
  });
747
765
  return inMemoryResult;
748
766
  }
749
- async get(key) {
767
+ get(key) {
750
768
  // we never read from the AuraStorage, except in construction.
751
- const result = await this.inMemoryStorage.get(key);
752
- return result ? result : undefined;
769
+ return this.inMemoryStorage.get(key);
753
770
  }
754
771
  }
755
772
 
@@ -1495,7 +1512,12 @@ function setupPredictivePrefetcher(luvio) {
1495
1512
  registerPrefetcher(luvio, prefetcher);
1496
1513
  __lexPrefetcher = prefetcher;
1497
1514
  }
1498
- // Triggers a payload.
1515
+ /**
1516
+ * @deprecated This function is deprecated in favor of `buildPredictorForContext`.
1517
+ * We only keep it so if the lds.usePredictiveLoading gate is open the existing functionality
1518
+ * on LASR don't break.
1519
+ * Note: we don't want to make it a noop either because then the gate toggle will be meaningless.
1520
+ */
1499
1521
  async function predictiveLoadPage(preloadProps, runPredictions) {
1500
1522
  // the gate is disabled and the prefetcher was not setup.
1501
1523
  if (__lexPrefetcher === undefined) {
@@ -1517,6 +1539,52 @@ async function predictiveLoadPage(preloadProps, runPredictions) {
1517
1539
  });
1518
1540
  return runPredictions ? __lexPrefetcher.predict() : Promise.resolve();
1519
1541
  }
1542
+ /**
1543
+ * @typedef {Object} RecordHomePageContext
1544
+ * @property {string} objectApiName - The API name of the object.
1545
+ * @property {string} recordId - The unique identifier for the record.
1546
+ * @property {string} actionName - The name of the action being performed.
1547
+ * @property {'recordPage'} type - The type of the context, specifically for a record page.
1548
+ */
1549
+ /**
1550
+ * Builds a predictor for a given record home page context. This predictor is responsible for
1551
+ * preloading data based on predictions for the current context and create new predictions based
1552
+ * on page requests of this context.
1553
+ *
1554
+ * @param {RecordHomePageContext} context - The context for which the predictor is to be built.
1555
+ * @returns {{
1556
+ * hasPredictions: () => boolean,
1557
+ * watchPageLoadForPredictions: () => void,
1558
+ * runPredictions: () => ReturnType<Promise<void>>
1559
+ * }} An object containing methods to handle predictions:
1560
+ * - hasPredictions: Checks if there are any predictions available.
1561
+ * - watchPageLoadForPredictions: Starts recording the page request for prediction purposes.
1562
+ * - runPredictions: Executes the predictions based on the recorded data and returns a promise
1563
+ * of when those predictions are completed.
1564
+ */
1565
+ function buildPredictorForContext(context) {
1566
+ // the gate is disabled and the prefetcher was not setup.
1567
+ if (__lexPrefetcher === undefined) {
1568
+ return;
1569
+ }
1570
+ // // This chunk configures which page we're going to use to try and preload.
1571
+ __lexPrefetcher.context = context;
1572
+ return {
1573
+ hasPredictions() {
1574
+ return __lexPrefetcher.hasPredictions();
1575
+ },
1576
+ watchPageLoadForPredictions() {
1577
+ // This chunk tells the prefetcher to receive events, send off any predictions we have from previous loads, then setup idle detection to stop predicting.
1578
+ __lexPrefetcher.startRecording();
1579
+ onIdleDetected(() => {
1580
+ __lexPrefetcher.stopRecording();
1581
+ });
1582
+ },
1583
+ runPredictions() {
1584
+ return __lexPrefetcher.predict();
1585
+ },
1586
+ };
1587
+ }
1520
1588
  // LDS initialization logic, invoked directly by Aura component tests
1521
1589
  function initializeLDS() {
1522
1590
  const storeOptions = {
@@ -1542,5 +1610,5 @@ function ldsEngineCreator() {
1542
1610
  return { name: 'ldsEngineCreator' };
1543
1611
  }
1544
1612
 
1545
- export { ldsEngineCreator as default, initializeLDS, predictiveLoadPage };
1546
- // version: 1.256.0-ad6a66c18
1613
+ export { buildPredictorForContext, ldsEngineCreator as default, initializeLDS, predictiveLoadPage };
1614
+ // version: 1.258.0-69570a3e6
@@ -1,3 +1,4 @@
1
+ import { type RecordHomePageContext } from './predictive-loading';
1
2
  type PreloadProps = {
2
3
  context: {
3
4
  objectApiName: string;
@@ -13,7 +14,41 @@ type LexPageReference = {
13
14
  state: any;
14
15
  type: string;
15
16
  };
17
+ /**
18
+ * @deprecated This function is deprecated in favor of `buildPredictorForContext`.
19
+ * We only keep it so if the lds.usePredictiveLoading gate is open the existing functionality
20
+ * on LASR don't break.
21
+ * Note: we don't want to make it a noop either because then the gate toggle will be meaningless.
22
+ */
16
23
  export declare function predictiveLoadPage(preloadProps: PreloadProps, runPredictions: true): Promise<void>;
24
+ /**
25
+ * @typedef {Object} RecordHomePageContext
26
+ * @property {string} objectApiName - The API name of the object.
27
+ * @property {string} recordId - The unique identifier for the record.
28
+ * @property {string} actionName - The name of the action being performed.
29
+ * @property {'recordPage'} type - The type of the context, specifically for a record page.
30
+ */
31
+ /**
32
+ * Builds a predictor for a given record home page context. This predictor is responsible for
33
+ * preloading data based on predictions for the current context and create new predictions based
34
+ * on page requests of this context.
35
+ *
36
+ * @param {RecordHomePageContext} context - The context for which the predictor is to be built.
37
+ * @returns {{
38
+ * hasPredictions: () => boolean,
39
+ * watchPageLoadForPredictions: () => void,
40
+ * runPredictions: () => ReturnType<Promise<void>>
41
+ * }} An object containing methods to handle predictions:
42
+ * - hasPredictions: Checks if there are any predictions available.
43
+ * - watchPageLoadForPredictions: Starts recording the page request for prediction purposes.
44
+ * - runPredictions: Executes the predictions based on the recorded data and returns a promise
45
+ * of when those predictions are completed.
46
+ */
47
+ export declare function buildPredictorForContext(context: RecordHomePageContext): {
48
+ hasPredictions(): boolean;
49
+ watchPageLoadForPredictions(): void;
50
+ runPredictions(): Promise<void>;
51
+ } | undefined;
17
52
  export declare function initializeLDS(): void;
18
53
  declare function ldsEngineCreator(): {
19
54
  name: string;
@@ -16,5 +16,6 @@ export declare abstract class ApplicationPredictivePrefetcher<Request, Context e
16
16
  startRecording(): void;
17
17
  saveRequest(request: Request): Promise<void>;
18
18
  predict(): Promise<void>;
19
- getSimilarPageRequests(): Promise<Request[]>;
19
+ hasPredictions(): boolean;
20
+ getSimilarPageRequests(): Request[];
20
21
  }
@@ -21,7 +21,7 @@ export declare class PrefetchRepository {
21
21
  clearRequestBuffer(): void;
22
22
  flushRequestsToStorage(): Promise<void>;
23
23
  saveRequest<Request>(key: Key, request: Request): Promise<void>;
24
- getPage<Request>(key: Key): Promise<PageEntry<Request> | undefined>;
25
- getPageRequests<Request>(key: Key): Promise<Request[]>;
24
+ getPage<Request>(key: Key): PageEntry<Request> | undefined;
25
+ getPageRequests<Request>(key: Key): Request[];
26
26
  }
27
27
  export {};
@@ -15,5 +15,5 @@ export declare class AuraPrefetchStorage implements PrefetchStorage {
15
15
  private inMemoryStorage;
16
16
  constructor(auraStorage: AuraStorage, inMemoryStorage: InMemoryPrefetchStorage);
17
17
  set<T>(key: string, value: T): Promise<void>;
18
- get<T>(key: string): Promise<T | undefined>;
18
+ get<T>(key: string): T | undefined;
19
19
  }
@@ -2,5 +2,5 @@ import type { PrefetchStorage } from '.';
2
2
  export declare class InMemoryPrefetchStorage implements PrefetchStorage {
3
3
  data: Record<string, any>;
4
4
  set<T>(key: string, value: T): Promise<void>;
5
- get<T>(key: string): Promise<T | undefined>;
5
+ get<T>(key: string): T | undefined;
6
6
  }
@@ -1,5 +1,5 @@
1
1
  export type PrefetchStorage = {
2
- get<T>(key: string): Promise<T | undefined>;
2
+ get<T>(key: string): T | undefined;
3
3
  set<T>(key: string, value: T): Promise<void>;
4
4
  };
5
5
  export * from './in-memory-prefetch-storage';
@@ -3,5 +3,5 @@ export declare class LocalPrefetchStorage implements PrefetchStorage {
3
3
  private localStorage;
4
4
  constructor(localStorage: typeof window.localStorage);
5
5
  set<T>(key: string, value: T): Promise<void>;
6
- get<T>(key: string): Promise<T | undefined>;
6
+ get<T>(key: string): T | undefined;
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-aura",
3
- "version": "1.256.0",
3
+ "version": "1.258.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS engine for Aura runtime",
6
6
  "main": "dist/ldsEngineCreator.js",
@@ -34,16 +34,16 @@
34
34
  "release:corejar": "yarn build && ../core-build/scripts/core.js --name=lds-runtime-aura"
35
35
  },
36
36
  "devDependencies": {
37
- "@salesforce/lds-adapters-uiapi": "^1.256.0",
38
- "@salesforce/lds-ads-bridge": "^1.256.0",
39
- "@salesforce/lds-aura-storage": "^1.256.0",
40
- "@salesforce/lds-bindings": "^1.256.0",
41
- "@salesforce/lds-instrumentation": "^1.256.0",
42
- "@salesforce/lds-network-aura": "^1.256.0",
43
- "@salesforce/lds-network-fetch-with-jwt": "^1.256.0"
37
+ "@salesforce/lds-adapters-uiapi": "^1.258.0",
38
+ "@salesforce/lds-ads-bridge": "^1.258.0",
39
+ "@salesforce/lds-aura-storage": "^1.258.0",
40
+ "@salesforce/lds-bindings": "^1.258.0",
41
+ "@salesforce/lds-instrumentation": "^1.258.0",
42
+ "@salesforce/lds-network-aura": "^1.258.0",
43
+ "@salesforce/lds-network-fetch-with-jwt": "^1.258.0"
44
44
  },
45
45
  "dependencies": {
46
- "@luvio/network-adapter-composable": "0.154.3"
46
+ "@luvio/network-adapter-composable": "0.154.4"
47
47
  },
48
48
  "luvioBundlesize": [
49
49
  {
@@ -51,7 +51,7 @@
51
51
  "maxSize": {
52
52
  "none": "63 kB",
53
53
  "min": "28 kB",
54
- "compressed": "12 kB"
54
+ "compressed": "13 kB"
55
55
  }
56
56
  }
57
57
  ],