@salesforce/lds-ads-bridge 1.340.0 → 1.342.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.
- package/dist/ads-bridge-perf.js +74 -4
- package/dist/adsBridge.js +74 -6
- package/dist/types/ads-bridge.d.ts +3 -2
- package/jest.config.js +36 -0
- package/package.json +7 -6
- package/src/__tests__/ads-bridge-mobile.spec.ts +1378 -0
- package/src/__tests__/ads-bridge.spec.ts +7 -2
- package/src/__tests__/test-utils.ts +8 -2
- package/src/ads-bridge.ts +98 -8
- package/src/main.ts +7 -1
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { Luvio, InMemoryStore, Environment } from '@luvio/engine';
|
|
2
|
-
import { keyBuilderRecord, ingestRecord } from '@salesforce/lds-adapters-uiapi';
|
|
2
|
+
import { keyBuilderRecord, ingestRecord, type Registration } from '@salesforce/lds-adapters-uiapi';
|
|
3
3
|
import { expect } from '@jest/globals';
|
|
4
4
|
|
|
5
5
|
import AdsBridge from '../ads-bridge';
|
|
6
6
|
import { isDMOEntity } from '../ads-bridge';
|
|
7
7
|
import { addObjectInfo, addRecord, createObjectInfo, createRecord } from './test-utils';
|
|
8
8
|
import { instrumentation } from '../instrumentation';
|
|
9
|
+
import { withRegistration } from '@salesforce/lds-default-luvio';
|
|
9
10
|
|
|
10
11
|
function createBridge() {
|
|
12
|
+
withRegistration<Registration>('@salesforce/lds-adapters-uiapi', (registration) => {
|
|
13
|
+
const { configuration } = registration;
|
|
14
|
+
configuration.setRecordRepresentationIngestionOverride(undefined);
|
|
15
|
+
});
|
|
11
16
|
const store = new InMemoryStore();
|
|
12
17
|
const environment = new Environment(store, jest.fn());
|
|
13
18
|
const luvio = new Luvio(environment);
|
|
14
|
-
const bridge = new AdsBridge(luvio);
|
|
19
|
+
const bridge = new AdsBridge(luvio, undefined);
|
|
15
20
|
|
|
16
21
|
return { store, luvio, bridge };
|
|
17
22
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Luvio } from '@luvio/engine';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getRecordIngestionOverride,
|
|
4
|
+
ingestObjectInfo,
|
|
5
|
+
ingestRecord,
|
|
6
|
+
} from '@salesforce/lds-adapters-uiapi';
|
|
3
7
|
|
|
4
8
|
export function createRecord(config: any = {}) {
|
|
5
9
|
return {
|
|
@@ -3256,7 +3260,9 @@ export function createObjectInfo(config: any = {}) {
|
|
|
3256
3260
|
}
|
|
3257
3261
|
|
|
3258
3262
|
export function addRecord(luvio: Luvio, data: any) {
|
|
3259
|
-
|
|
3263
|
+
const recordIngest =
|
|
3264
|
+
getRecordIngestionOverride() !== undefined ? getRecordIngestionOverride() : ingestRecord;
|
|
3265
|
+
luvio.storeIngest('', recordIngest!, data);
|
|
3260
3266
|
luvio.storeBroadcast();
|
|
3261
3267
|
}
|
|
3262
3268
|
|
package/src/ads-bridge.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import type { Luvio, ProxyGraphNode, GraphNode } from '@luvio/engine';
|
|
1
|
+
import type { Luvio, ProxyGraphNode, GraphNode, ResourceIngest } from '@luvio/engine';
|
|
2
2
|
import type {
|
|
3
|
-
RecordRepresentation,
|
|
4
|
-
RecordRepresentationNormalized,
|
|
5
3
|
ObjectInfoRepresentation,
|
|
6
4
|
FieldValueRepresentation,
|
|
7
5
|
FieldValueRepresentationNormalized,
|
|
6
|
+
RecordRepresentation,
|
|
7
|
+
RecordRepresentationNormalized,
|
|
8
8
|
} from '@salesforce/lds-adapters-uiapi';
|
|
9
|
+
import type {
|
|
10
|
+
RecordRepresentation as DenormalizedRecordRepresentation,
|
|
11
|
+
RecordRepresentationNormalized as DenormalizedRecordRepresentationNormalized,
|
|
12
|
+
} from '@salesforce/lds-runtime-mobile';
|
|
9
13
|
import {
|
|
10
|
-
ingestRecord,
|
|
11
14
|
keyBuilderRecord,
|
|
12
15
|
keyBuilderObjectInfo,
|
|
16
|
+
ingestRecord as ingestNormalizedRecordRepresentation,
|
|
13
17
|
} from '@salesforce/lds-adapters-uiapi';
|
|
14
18
|
|
|
15
19
|
import {
|
|
@@ -103,6 +107,82 @@ function isStoreKeyRecordId(key: string) {
|
|
|
103
107
|
return key.indexOf(RECORD_ID_PREFIX) > -1 && key.indexOf(RECORD_FIELDS_KEY_JUNCTION) === -1;
|
|
104
108
|
}
|
|
105
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Returns a shallow copy of a record with its field values if it is a scalar and a reference and a
|
|
112
|
+
* a RecordRepresentation with no field if the value if a spanning record.
|
|
113
|
+
* It returns null if the record contains any pending field.
|
|
114
|
+
*/
|
|
115
|
+
function getShallowRecordDenormalized(
|
|
116
|
+
luvio: Luvio,
|
|
117
|
+
storeRecordId: string
|
|
118
|
+
): DenormalizedRecordRepresentation | null {
|
|
119
|
+
const recordNode = luvio.getNode<
|
|
120
|
+
DenormalizedRecordRepresentationNormalized,
|
|
121
|
+
DenormalizedRecordRepresentation
|
|
122
|
+
>(storeRecordId);
|
|
123
|
+
|
|
124
|
+
if (!isGraphNode(recordNode)) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const fieldsCopy: DenormalizedRecordRepresentation['fields'] = {};
|
|
129
|
+
const copy: DenormalizedRecordRepresentation = {
|
|
130
|
+
...recordNode.retrieve(),
|
|
131
|
+
fields: fieldsCopy,
|
|
132
|
+
childRelationships: {},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const fieldsNode = recordNode.object('fields');
|
|
136
|
+
const fieldNames = fieldsNode.keys();
|
|
137
|
+
|
|
138
|
+
for (let i = 0, len = fieldNames.length; i < len; i++) {
|
|
139
|
+
let fieldCopy: FieldValueRepresentation;
|
|
140
|
+
|
|
141
|
+
const fieldName = fieldNames[i];
|
|
142
|
+
if (fieldsNode.isPending(fieldName) === true) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (fieldsNode.isMissing(fieldName) === true) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const fieldObject = fieldsNode.object(fieldName);
|
|
151
|
+
const { displayValue, value } = fieldObject.retrieve();
|
|
152
|
+
if (fieldObject.isScalar('value')) {
|
|
153
|
+
fieldCopy = {
|
|
154
|
+
displayValue: displayValue,
|
|
155
|
+
value: value as string | number | boolean | null,
|
|
156
|
+
};
|
|
157
|
+
} else {
|
|
158
|
+
const spanningRecordLink = fieldObject.link<
|
|
159
|
+
DenormalizedRecordRepresentationNormalized,
|
|
160
|
+
DenormalizedRecordRepresentation
|
|
161
|
+
>('value');
|
|
162
|
+
if (spanningRecordLink.isPending() === true) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const spanningRecordNode = spanningRecordLink.follow();
|
|
167
|
+
if (!isGraphNode(spanningRecordNode)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
fieldCopy = {
|
|
172
|
+
displayValue,
|
|
173
|
+
value: {
|
|
174
|
+
...spanningRecordNode.retrieve(),
|
|
175
|
+
fields: {},
|
|
176
|
+
childRelationships: {},
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
fieldsCopy[fieldName] = fieldCopy;
|
|
182
|
+
}
|
|
183
|
+
return copy;
|
|
184
|
+
}
|
|
185
|
+
|
|
106
186
|
/**
|
|
107
187
|
* Returns a shallow copy of a record with its field values if it is a scalar and a reference and a
|
|
108
188
|
* a RecordRepresentation with no field if the value if a spanning record.
|
|
@@ -176,7 +256,6 @@ function getShallowRecord(luvio: Luvio, storeRecordId: string): RecordRepresenta
|
|
|
176
256
|
|
|
177
257
|
fieldsCopy[fieldName] = fieldCopy;
|
|
178
258
|
}
|
|
179
|
-
|
|
180
259
|
return copy;
|
|
181
260
|
}
|
|
182
261
|
|
|
@@ -265,7 +344,10 @@ export default class AdsBridge {
|
|
|
265
344
|
private isRecordEmitLocked: boolean = false;
|
|
266
345
|
private watchUnsubscribe: Unsubscribe | undefined;
|
|
267
346
|
|
|
268
|
-
constructor(
|
|
347
|
+
constructor(
|
|
348
|
+
private luvio: Luvio,
|
|
349
|
+
private recordRepresentationIngestOverride: ResourceIngest | undefined
|
|
350
|
+
) {}
|
|
269
351
|
|
|
270
352
|
/**
|
|
271
353
|
* This setter invoked by recordLibrary to listen for records ingested by Luvio. The passed method
|
|
@@ -324,7 +406,12 @@ export default class AdsBridge {
|
|
|
324
406
|
// with the master record type. See W-7302870 for details.
|
|
325
407
|
fixRecordTypes(luvio, recordCopy);
|
|
326
408
|
|
|
327
|
-
|
|
409
|
+
const recordIngest =
|
|
410
|
+
this.recordRepresentationIngestOverride !== undefined
|
|
411
|
+
? this.recordRepresentationIngestOverride
|
|
412
|
+
: ingestNormalizedRecordRepresentation;
|
|
413
|
+
|
|
414
|
+
luvio.storeIngest(INGEST_KEY, recordIngest, recordCopy);
|
|
328
415
|
}
|
|
329
416
|
}
|
|
330
417
|
|
|
@@ -427,7 +514,10 @@ export default class AdsBridge {
|
|
|
427
514
|
continue;
|
|
428
515
|
}
|
|
429
516
|
|
|
430
|
-
const record =
|
|
517
|
+
const record =
|
|
518
|
+
this.recordRepresentationIngestOverride !== undefined
|
|
519
|
+
? getShallowRecordDenormalized(luvio, storeRecordId)
|
|
520
|
+
: getShallowRecord(luvio, storeRecordId);
|
|
431
521
|
if (record === null) {
|
|
432
522
|
continue;
|
|
433
523
|
}
|
package/src/main.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Luvio } from '@luvio/engine';
|
|
2
2
|
import AdsBridge from './ads-bridge';
|
|
3
3
|
|
|
4
|
+
import { getRecordIngestionOverride } from '@salesforce/lds-adapters-uiapi';
|
|
4
5
|
import { withDefaultLuvio } from '@salesforce/lds-default-luvio';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -16,7 +17,12 @@ let callbacks: Callback[] = [];
|
|
|
16
17
|
|
|
17
18
|
// create a new AdsBridge whenever the default Luvio is set/changed
|
|
18
19
|
withDefaultLuvio((luvio: Luvio) => {
|
|
19
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Cache the current value of ingestion override on startup.
|
|
22
|
+
* This needs be set prior to loading of the ADS bridge.
|
|
23
|
+
*/
|
|
24
|
+
const recordIngestionOverride = getRecordIngestionOverride();
|
|
25
|
+
adsBridge = new AdsBridge(luvio, recordIngestionOverride);
|
|
20
26
|
|
|
21
27
|
for (let i = 0; i < callbacks.length; ++i) {
|
|
22
28
|
callbacks[i](adsBridge);
|