@salesforce/lds-ads-bridge 0.1.0-dev1

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.
@@ -0,0 +1,438 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ /*
8
+ * ATTENTION!
9
+ * THIS IS A GENERATED FILE FROM https://github.com/salesforce-experience-platform-emu/lds-lightning-platform
10
+ * If you would like to contribute to LDS, please follow the steps outlined in the git repo.
11
+ * Any changes made to this file in p4 will be automatically overwritten.
12
+ * *******************************************************************************************
13
+ */
14
+ /* proxy-compat-disable */
15
+ import { ingestRecord, keyBuilderRecord, keyBuilderObjectInfo, getRecordIngestionOverride } from 'force/ldsAdaptersUiapi';
16
+ import { withDefaultLuvio } from 'force/ldsEngine';
17
+
18
+ const { push } = Array.prototype;
19
+ const { keys } = Object;
20
+ const { hasOwnProperty } = Object.prototype;
21
+ const { parse, stringify } = JSON;
22
+
23
+ const ADS_BRIDGE_ADD_RECORDS_DURATION = 'ads-bridge-add-records-duration';
24
+ const ADS_BRIDGE_EMIT_RECORD_CHANGED_DURATION = 'ads-bridge-emit-record-changed-duration';
25
+ const ADS_BRIDGE_EVICT_DURATION = 'ads-bridge-evict-duration';
26
+
27
+ // For use by callers within this module to instrument interesting things.
28
+ let instrumentation = {
29
+ timerMetricAddDuration: (_metricName, _valueInMs) => { },
30
+ };
31
+ /**
32
+ * Allows external modules (typically a runtime environment) to set
33
+ * instrumentation hooks for this module. Note that the hooks are
34
+ * incremental - hooks not suppiled in newInstrumentation will retain
35
+ * their previous values. The default instrumentation hooks are no-ops.
36
+ *
37
+ * @param newInstrumentation instrumentation hooks to be overridden
38
+ */
39
+ function instrument(newInstrumentation) {
40
+ instrumentation = Object.assign(instrumentation, newInstrumentation);
41
+ }
42
+
43
+ // No need to pass the actual record key `luvio.ingestStore`. The `RecordRepresentation.ts#ingest`
44
+ // function extracts the appropriate record id from the ingested record.
45
+ const INGEST_KEY = '';
46
+ const MAIN_RECORD_TYPE_ID = '012000000000000AAA';
47
+ const DMO_API_NAME_SUFFIX = '__dlm';
48
+ const API_NAMESPACE = 'UiApi';
49
+ const RECORD_REPRESENTATION_NAME = 'RecordRepresentation';
50
+ const RECORD_ID_PREFIX = `${API_NAMESPACE}::${RECORD_REPRESENTATION_NAME}:`;
51
+ const RECORD_FIELDS_KEY_JUNCTION = '__fields__';
52
+ function isGraphNode(node) {
53
+ return node !== null && node.type === 'Node';
54
+ }
55
+ function isSpanningRecord(fieldValue) {
56
+ return fieldValue !== null && typeof fieldValue === 'object' && !Array.isArray(fieldValue);
57
+ }
58
+ function isStoreKeyRecordId(key) {
59
+ return key.indexOf(RECORD_ID_PREFIX) > -1 && key.indexOf(RECORD_FIELDS_KEY_JUNCTION) === -1;
60
+ }
61
+ /**
62
+ * Returns a shallow copy of a record with its field values if it is a scalar and a reference and a
63
+ * a RecordRepresentation with no field if the value if a spanning record.
64
+ * It returns null if the record contains any pending field.
65
+ */
66
+ function getShallowRecordDenormalized(luvio, storeRecordId) {
67
+ const recordNode = luvio.getNode(storeRecordId);
68
+ if (!isGraphNode(recordNode)) {
69
+ return null;
70
+ }
71
+ const fieldsCopy = {};
72
+ const copy = {
73
+ ...recordNode.retrieve(),
74
+ fields: fieldsCopy,
75
+ childRelationships: {},
76
+ };
77
+ const fieldsNode = recordNode.object('fields');
78
+ const fieldNames = fieldsNode.keys();
79
+ for (let i = 0, len = fieldNames.length; i < len; i++) {
80
+ let fieldCopy;
81
+ const fieldName = fieldNames[i];
82
+ if (fieldsNode.isPending(fieldName) === true) {
83
+ return null;
84
+ }
85
+ if (fieldsNode.isMissing(fieldName) === true) {
86
+ continue;
87
+ }
88
+ const fieldObject = fieldsNode.object(fieldName);
89
+ const { displayValue, value } = fieldObject.retrieve();
90
+ if (fieldObject.isScalar('value') || Array.isArray(fieldObject.data?.value)) {
91
+ fieldCopy = {
92
+ displayValue: displayValue,
93
+ value: value,
94
+ };
95
+ }
96
+ else {
97
+ const spanningRecordLink = fieldObject.link('value');
98
+ if (spanningRecordLink.isPending() === true) {
99
+ return null;
100
+ }
101
+ const spanningRecordNode = spanningRecordLink.follow();
102
+ if (!isGraphNode(spanningRecordNode)) {
103
+ continue;
104
+ }
105
+ fieldCopy = {
106
+ displayValue,
107
+ value: {
108
+ ...spanningRecordNode.retrieve(),
109
+ fields: {},
110
+ childRelationships: {},
111
+ },
112
+ };
113
+ }
114
+ fieldsCopy[fieldName] = fieldCopy;
115
+ }
116
+ return copy;
117
+ }
118
+ /**
119
+ * Returns a shallow copy of a record with its field values if it is a scalar and a reference and a
120
+ * a RecordRepresentation with no field if the value if a spanning record.
121
+ * It returns null if the record contains any pending field.
122
+ */
123
+ function getShallowRecord(luvio, storeRecordId) {
124
+ const recordNode = luvio.getNode(storeRecordId);
125
+ if (!isGraphNode(recordNode)) {
126
+ return null;
127
+ }
128
+ const fieldsCopy = {};
129
+ const copy = {
130
+ ...recordNode.retrieve(),
131
+ fields: fieldsCopy,
132
+ childRelationships: {},
133
+ };
134
+ const fieldsNode = recordNode.object('fields');
135
+ const fieldNames = fieldsNode.keys();
136
+ for (let i = 0, len = fieldNames.length; i < len; i++) {
137
+ let fieldCopy;
138
+ const fieldName = fieldNames[i];
139
+ const fieldLink = fieldsNode.link(fieldName);
140
+ if (fieldLink.isPending() === true) {
141
+ return null;
142
+ }
143
+ const fieldNode = fieldLink.follow();
144
+ if (!isGraphNode(fieldNode)) {
145
+ continue;
146
+ }
147
+ const { displayValue, value } = fieldNode.retrieve();
148
+ if (fieldNode.isScalar('value') || Array.isArray(fieldNode.data?.value)) {
149
+ fieldCopy = {
150
+ displayValue: displayValue,
151
+ value: value,
152
+ };
153
+ }
154
+ else {
155
+ const spanningRecordLink = fieldNode.link('value');
156
+ if (spanningRecordLink.isPending() === true) {
157
+ return null;
158
+ }
159
+ const spanningRecordNode = spanningRecordLink.follow();
160
+ if (!isGraphNode(spanningRecordNode)) {
161
+ continue;
162
+ }
163
+ fieldCopy = {
164
+ displayValue,
165
+ value: {
166
+ ...spanningRecordNode.retrieve(),
167
+ fields: {},
168
+ childRelationships: {},
169
+ },
170
+ };
171
+ }
172
+ fieldsCopy[fieldName] = fieldCopy;
173
+ }
174
+ return copy;
175
+ }
176
+ /**
177
+ * Returns the ADS object metadata representation for a specific record.
178
+ */
179
+ function getObjectMetadata(luvio, record) {
180
+ const { data: objectInfo } = luvio.storeLookup({
181
+ recordId: keyBuilderObjectInfo(luvio, { apiName: record.apiName }),
182
+ node: {
183
+ kind: 'Fragment',
184
+ private: ['eTag'],
185
+ opaque: true,
186
+ },
187
+ variables: {},
188
+ });
189
+ if (objectInfo !== undefined) {
190
+ let nameField = 'Name';
191
+ // Extract the entity name field from the object info. In the case where there are multiple
192
+ // field names then pick up the first one.
193
+ if (objectInfo.nameFields.length !== 0 && objectInfo.nameFields.indexOf('Name') === -1) {
194
+ nameField = objectInfo.nameFields[0];
195
+ }
196
+ return {
197
+ _nameField: nameField,
198
+ _entityLabel: objectInfo.label,
199
+ _keyPrefix: objectInfo.keyPrefix,
200
+ };
201
+ }
202
+ return {
203
+ _nameField: 'Name',
204
+ _entityLabel: record.apiName,
205
+ _keyPrefix: record.id.substring(0, 3),
206
+ };
207
+ }
208
+ /**
209
+ * RecordGvp can send records back to ADS with record types incorrectly set to the master
210
+ * record type. Since there are no known legitimate scenarios where a record can change from a
211
+ * non-master record type back to the master record type, we assume such a transition
212
+ * indicates a RecordGvp mistake. This function checks for that scenario and overwrites the
213
+ * incoming ADS record type information with what we already have in the store when it
214
+ * occurs.
215
+ *
216
+ * @param luvio Luvio
217
+ * @param record record from ADS, will be fixed in situ
218
+ */
219
+ function fixRecordTypes(luvio, record) {
220
+ // non-master record types should always be correct
221
+ if (record.recordTypeId === MAIN_RECORD_TYPE_ID) {
222
+ const key = keyBuilderRecord(luvio, { recordId: record.id });
223
+ const recordNode = luvio.getNode(key);
224
+ if (isGraphNode(recordNode) && recordNode.scalar('recordTypeId') !== MAIN_RECORD_TYPE_ID) {
225
+ // ignore bogus incoming record type information & keep what we have
226
+ record.recordTypeId = recordNode.scalar('recordTypeId');
227
+ record.recordTypeInfo = recordNode.object('recordTypeInfo').data;
228
+ }
229
+ }
230
+ // recurse on nested records
231
+ const fieldKeys = keys(record.fields);
232
+ const fieldKeysLen = fieldKeys.length;
233
+ for (let i = 0; i < fieldKeysLen; ++i) {
234
+ const fieldValue = record.fields[fieldKeys[i]].value;
235
+ if (isSpanningRecord(fieldValue)) {
236
+ fixRecordTypes(luvio, fieldValue);
237
+ }
238
+ }
239
+ }
240
+ /**
241
+ * Returns whether or not a the record is a DMO entity.
242
+ * @param record - The record.
243
+ * @returns True if DMO, false otherwise.
244
+ */
245
+ function isDMOEntity(record) {
246
+ return record.apiName.endsWith(DMO_API_NAME_SUFFIX);
247
+ }
248
+ class AdsBridge {
249
+ constructor(luvio, recordRepresentationIngestOverride) {
250
+ this.luvio = luvio;
251
+ this.recordRepresentationIngestOverride = recordRepresentationIngestOverride;
252
+ this.isRecordEmitLocked = false;
253
+ }
254
+ /**
255
+ * This setter invoked by recordLibrary to listen for records ingested by Luvio. The passed method
256
+ * is invoked whenever a record is ingested. It may be via getRecord, getRecordUi, getListUi, ...
257
+ */
258
+ set receiveFromLdsCallback(callback) {
259
+ // Unsubscribe if there is an existing subscription.
260
+ if (this.watchUnsubscribe !== undefined) {
261
+ this.watchUnsubscribe();
262
+ this.watchUnsubscribe = undefined;
263
+ }
264
+ if (callback !== undefined) {
265
+ this.watchUnsubscribe = this.luvio.storeWatch(RECORD_ID_PREFIX, (entries) => {
266
+ if (this.isRecordEmitLocked === true) {
267
+ return;
268
+ }
269
+ this.emitRecordChanged(entries, callback);
270
+ });
271
+ }
272
+ }
273
+ /**
274
+ * This method is invoked when a record has been ingested by ADS.
275
+ *
276
+ * ADS may invoke this method with records that are not UIAPI allowlisted so not refreshable by
277
+ * Luvio. Luvio filters the provided list so it ingests only UIAPI allowlisted records.
278
+ */
279
+ addRecords(records, uiApiEntityAllowlist) {
280
+ const startTime = Date.now();
281
+ const { luvio } = this;
282
+ let didIngestRecord = false;
283
+ return this.lockLdsRecordEmit(() => {
284
+ for (let i = 0; i < records.length; i++) {
285
+ const record = records[i];
286
+ const { apiName } = record;
287
+ // Ingest the record if no allowlist is passed or the entity name is allowlisted.
288
+ if (uiApiEntityAllowlist === undefined ||
289
+ uiApiEntityAllowlist[apiName] !== 'false') {
290
+ didIngestRecord = true;
291
+ // Deep-copy the record to ingest and ingest the record copy. This avoids
292
+ // corrupting the ADS cache since ingestion mutates the passed record.
293
+ const recordCopy = parse(stringify(record));
294
+ // Don't let incorrect ADS/RecordGVP recordTypeIds replace a valid record type in our store
295
+ // with the master record type. See W-7302870 for details.
296
+ fixRecordTypes(luvio, recordCopy);
297
+ const recordIngest = this.recordRepresentationIngestOverride !== undefined
298
+ ? this.recordRepresentationIngestOverride
299
+ : ingestRecord;
300
+ luvio.storeIngest(INGEST_KEY, recordIngest, recordCopy);
301
+ }
302
+ }
303
+ if (didIngestRecord === true) {
304
+ luvio.storeBroadcast();
305
+ }
306
+ instrumentation.timerMetricAddDuration(ADS_BRIDGE_ADD_RECORDS_DURATION, Date.now() - startTime);
307
+ });
308
+ }
309
+ /**
310
+ * This method is invoked whenever a record has been evicted from ADS.
311
+ */
312
+ evict(recordId) {
313
+ const startTime = Date.now();
314
+ const { luvio } = this;
315
+ const key = keyBuilderRecord(luvio, { recordId });
316
+ return this.lockLdsRecordEmit(() => {
317
+ luvio.storeEvict(key);
318
+ luvio.storeBroadcast();
319
+ instrumentation.timerMetricAddDuration(ADS_BRIDGE_EVICT_DURATION, Date.now() - startTime);
320
+ return Promise.resolve();
321
+ });
322
+ }
323
+ /**
324
+ * Gets the list of fields of a record that Luvio has in its store. The field list doesn't
325
+ * contains the spanning record fields. ADS uses this list when it loads a record from the
326
+ * server. This is an optimization to make a single roundtrip it queries for all fields required
327
+ * by ADS and Luvio.
328
+ */
329
+ getTrackedFieldsForRecord(recordId) {
330
+ const { luvio } = this;
331
+ const storeRecordId = keyBuilderRecord(luvio, { recordId });
332
+ const recordNode = luvio.getNode(storeRecordId);
333
+ if (!isGraphNode(recordNode)) {
334
+ return Promise.resolve([]);
335
+ }
336
+ const apiName = recordNode.scalar('apiName');
337
+ const fieldNames = recordNode.object('fields').keys();
338
+ // Prefix all the fields with the record API name.
339
+ const qualifiedFieldNames = [];
340
+ for (let i = 0, len = fieldNames.length; i < len; i++) {
341
+ push.call(qualifiedFieldNames, `${apiName}.${fieldNames[i]}`);
342
+ }
343
+ return Promise.resolve(qualifiedFieldNames);
344
+ }
345
+ /**
346
+ * Prevents the bridge to emit record change during the execution of the callback.
347
+ * This methods should wrap all the Luvio store mutation done by the bridge. It prevents Luvio store
348
+ * mutations triggered by ADS to be emit back to ADS.
349
+ */
350
+ lockLdsRecordEmit(callback) {
351
+ this.isRecordEmitLocked = true;
352
+ try {
353
+ return callback();
354
+ }
355
+ finally {
356
+ this.isRecordEmitLocked = false;
357
+ }
358
+ }
359
+ /**
360
+ * This method retrieves queries the store with with passed record ids to retrieve their
361
+ * associated records and object info. Note that the passed ids are not Salesforce record id
362
+ * but rather Luvio internals store ids.
363
+ */
364
+ emitRecordChanged(updatedEntries, callback) {
365
+ const startTime = Date.now();
366
+ const { luvio } = this;
367
+ let shouldEmit = false;
368
+ const adsRecordMap = {};
369
+ const adsObjectMap = {};
370
+ for (let i = 0; i < updatedEntries.length; i++) {
371
+ const storeRecordId = updatedEntries[i].id;
372
+ // Exclude all the store record ids not matching with the record id pattern.
373
+ // Note: FieldValueRepresentation have the same prefix than RecordRepresentation so we
374
+ // need to filter them out.
375
+ if (!isStoreKeyRecordId(storeRecordId)) {
376
+ continue;
377
+ }
378
+ const record = this.recordRepresentationIngestOverride !== undefined
379
+ ? getShallowRecordDenormalized(luvio, storeRecordId)
380
+ : getShallowRecord(luvio, storeRecordId);
381
+ if (record === null) {
382
+ continue;
383
+ }
384
+ // W-9978523
385
+ if (isDMOEntity(record) === true) {
386
+ continue;
387
+ }
388
+ const { id, apiName } = record;
389
+ shouldEmit = true;
390
+ adsRecordMap[id] = {
391
+ [apiName]: {
392
+ isPrimary: true,
393
+ record,
394
+ },
395
+ };
396
+ // Extract and add the object metadata to the map if not already present.
397
+ if (!hasOwnProperty.call(adsObjectMap, apiName)) {
398
+ adsObjectMap[apiName] = getObjectMetadata(luvio, record);
399
+ }
400
+ }
401
+ if (shouldEmit === true) {
402
+ callback(adsRecordMap, adsObjectMap);
403
+ }
404
+ instrumentation.timerMetricAddDuration(ADS_BRIDGE_EMIT_RECORD_CHANGED_DURATION, Date.now() - startTime);
405
+ }
406
+ }
407
+
408
+ // most recently created AdsBridge
409
+ let adsBridge;
410
+ // callbacks to be invoked when AdsBridge is set/changed
411
+ let callbacks = [];
412
+ // create a new AdsBridge whenever the default Luvio is set/changed
413
+ withDefaultLuvio((luvio) => {
414
+ /**
415
+ * Cache the current value of ingestion override on startup.
416
+ * This needs be set prior to loading of the ADS bridge.
417
+ */
418
+ const recordIngestionOverride = getRecordIngestionOverride();
419
+ adsBridge = new AdsBridge(luvio, recordIngestionOverride);
420
+ for (let i = 0; i < callbacks.length; ++i) {
421
+ callbacks[i](adsBridge);
422
+ }
423
+ });
424
+ /**
425
+ * Registers a callback to be invoked with the AdsBridge instance. Note that the
426
+ * callback may be invoked multiple times if the default Luvio changes.
427
+ *
428
+ * @param callback callback to be invoked with the AdsBridge
429
+ */
430
+ function withAdsBridge(callback) {
431
+ if (adsBridge) {
432
+ callback(adsBridge);
433
+ }
434
+ callbacks.push(callback);
435
+ }
436
+
437
+ export { instrument, withAdsBridge };
438
+ // version: 0.1.0-dev1-54c03dd38c
@@ -0,0 +1,88 @@
1
+ import type { Luvio, ResourceIngest } from '@luvio/engine';
2
+ import type { RecordRepresentation } from '@salesforce/lds-adapters-uiapi';
3
+ interface AdsRecord {
4
+ /**
5
+ * True if the passed record is a primary record, otherwise false.
6
+ *
7
+ * The Salesforce APIs may represent different records with the same record id. All the
8
+ * records returned by the UI API are primary records.
9
+ */
10
+ isPrimary: boolean;
11
+ /** The actual record data */
12
+ record: RecordRepresentation;
13
+ }
14
+ interface AdsRecordMap {
15
+ [recordId: string]: {
16
+ [objectApiName: string]: AdsRecord;
17
+ };
18
+ }
19
+ interface ObjectMetadata {
20
+ /**
21
+ * The entity key prefix.
22
+ * This originally was typed as simply a "string",
23
+ * however, "keyPrefix" can be null on ObjectInfoRepresentation
24
+ * and existing behavior simply passes ObjectInfoRepresentation.keyPrefix
25
+ * straight to ADS. This type has been updated to capture that
26
+ * a string or null can be passed here.
27
+ * */
28
+ _keyPrefix: string | null;
29
+ /** The entity field name. */
30
+ _nameField: string;
31
+ /** The entity label. */
32
+ _entityLabel: string;
33
+ }
34
+ interface AdsObjectMetadataMap {
35
+ [objectApiName: string]: ObjectMetadata;
36
+ }
37
+ type LdsRecordChangedCallback = (record: AdsRecordMap, objectMetadata: AdsObjectMetadataMap) => any;
38
+ /**
39
+ * Returns whether or not a the record is a DMO entity.
40
+ * @param record - The record.
41
+ * @returns True if DMO, false otherwise.
42
+ */
43
+ export declare function isDMOEntity(record: RecordRepresentation): boolean;
44
+ export default class AdsBridge {
45
+ private luvio;
46
+ private recordRepresentationIngestOverride;
47
+ private isRecordEmitLocked;
48
+ private watchUnsubscribe;
49
+ constructor(luvio: Luvio, recordRepresentationIngestOverride: ResourceIngest | undefined);
50
+ /**
51
+ * This setter invoked by recordLibrary to listen for records ingested by Luvio. The passed method
52
+ * is invoked whenever a record is ingested. It may be via getRecord, getRecordUi, getListUi, ...
53
+ */
54
+ set receiveFromLdsCallback(callback: LdsRecordChangedCallback | undefined);
55
+ /**
56
+ * This method is invoked when a record has been ingested by ADS.
57
+ *
58
+ * ADS may invoke this method with records that are not UIAPI allowlisted so not refreshable by
59
+ * Luvio. Luvio filters the provided list so it ingests only UIAPI allowlisted records.
60
+ */
61
+ addRecords(records: RecordRepresentation[], uiApiEntityAllowlist?: {
62
+ [name: string]: 'false' | undefined;
63
+ }): void;
64
+ /**
65
+ * This method is invoked whenever a record has been evicted from ADS.
66
+ */
67
+ evict(recordId: string): Promise<void>;
68
+ /**
69
+ * Gets the list of fields of a record that Luvio has in its store. The field list doesn't
70
+ * contains the spanning record fields. ADS uses this list when it loads a record from the
71
+ * server. This is an optimization to make a single roundtrip it queries for all fields required
72
+ * by ADS and Luvio.
73
+ */
74
+ getTrackedFieldsForRecord(recordId: string): Promise<string[]>;
75
+ /**
76
+ * Prevents the bridge to emit record change during the execution of the callback.
77
+ * This methods should wrap all the Luvio store mutation done by the bridge. It prevents Luvio store
78
+ * mutations triggered by ADS to be emit back to ADS.
79
+ */
80
+ private lockLdsRecordEmit;
81
+ /**
82
+ * This method retrieves queries the store with with passed record ids to retrieve their
83
+ * associated records and object info. Note that the passed ids are not Salesforce record id
84
+ * but rather Luvio internals store ids.
85
+ */
86
+ private emitRecordChanged;
87
+ }
88
+ export {};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Instrumentation hooks exposed by this module.
3
+ */
4
+ export interface AdsBridgeInstrumentation {
5
+ /**
6
+ * Called at the end of execution for a function to track latency
7
+ * Current functions tracked: packages/lds-ads-bridge/src/utils/metric-keys.ts
8
+ */
9
+ timerMetricAddDuration?: (metricName: string, valueInMs: number) => void;
10
+ }
11
+ export declare let instrumentation: {
12
+ timerMetricAddDuration: (_metricName: string, _valueInMs: number) => void;
13
+ };
14
+ /**
15
+ * Allows external modules (typically a runtime environment) to set
16
+ * instrumentation hooks for this module. Note that the hooks are
17
+ * incremental - hooks not suppiled in newInstrumentation will retain
18
+ * their previous values. The default instrumentation hooks are no-ops.
19
+ *
20
+ * @param newInstrumentation instrumentation hooks to be overridden
21
+ */
22
+ export declare function instrument(newInstrumentation: AdsBridgeInstrumentation): void;
@@ -0,0 +1,13 @@
1
+ import AdsBridge from './ads-bridge';
2
+ /**
3
+ * Callback used to inform interested parties that a new default Luvio has been set.
4
+ */
5
+ export type Callback = (adsBridge: AdsBridge) => void;
6
+ /**
7
+ * Registers a callback to be invoked with the AdsBridge instance. Note that the
8
+ * callback may be invoked multiple times if the default Luvio changes.
9
+ *
10
+ * @param callback callback to be invoked with the AdsBridge
11
+ */
12
+ export declare function withAdsBridge(callback: Callback): void;
13
+ export { instrument, AdsBridgeInstrumentation } from './instrumentation';
@@ -0,0 +1,11 @@
1
+ declare const push: (...items: any[]) => number;
2
+ declare const keys: {
3
+ (o: object): string[];
4
+ (o: {}): string[];
5
+ };
6
+ declare const hasOwnProperty: (v: PropertyKey) => boolean;
7
+ declare const parse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any, stringify: {
8
+ (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
9
+ (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
10
+ };
11
+ export { push as ArrayPrototypePush, keys as ObjectKeys, hasOwnProperty as ObjectPrototypeHasOwnProperty, parse as JSONParse, stringify as JSONStringify, };
@@ -0,0 +1,3 @@
1
+ export declare const ADS_BRIDGE_ADD_RECORDS_DURATION = "ads-bridge-add-records-duration";
2
+ export declare const ADS_BRIDGE_EMIT_RECORD_CHANGED_DURATION = "ads-bridge-emit-record-changed-duration";
3
+ export declare const ADS_BRIDGE_EVICT_DURATION = "ads-bridge-evict-duration";
package/jest.config.js ADDED
@@ -0,0 +1,43 @@
1
+ const baseConfig = require('../../scripts/jest/base.config');
2
+
3
+ module.exports = {
4
+ ...baseConfig,
5
+
6
+ displayName: '@salesforce/lds-ads-bridge',
7
+ roots: ['<rootDir>/src'],
8
+
9
+ moduleNameMapper: {
10
+ ...baseConfig.moduleNameMapper,
11
+ 'o11y/client': require.resolve('../lds-worker-api/src/standalone-stubs/o11y.ts'),
12
+ '@salesforce/user/Id': require.resolve(
13
+ '../lds-runtime-mobile/src/__mocks__/@salesforce/user/Id.js'
14
+ ),
15
+ '@salesforce/i18n/locale': require.resolve(
16
+ '../lds-runtime-mobile/src/__mocks__/@salesforce/i18n/locale.js'
17
+ ),
18
+ '@salesforce/i18n/firstDayOfWeek': require.resolve(
19
+ '../lds-runtime-mobile/src/__mocks__/@salesforce/i18n/firstDayOfWeek.js'
20
+ ),
21
+ '@salesforce/i18n/currency': require.resolve(
22
+ '../lds-runtime-mobile/src/__mocks__/@salesforce/i18n/currency.js'
23
+ ),
24
+ '@salesforce/i18n/timeZone': require.resolve(
25
+ '../lds-runtime-mobile/src/__mocks__/@salesforce/i18n/timeZone.js'
26
+ ),
27
+ 'lightning/i18nService': require.resolve(
28
+ '../lds-runtime-mobile/src/__mocks__/lightning/i18nService.js'
29
+ ),
30
+ 'lightning/i18nCldrOptions': require.resolve(
31
+ '../lds-runtime-mobile/src/__mocks__/lightning/i18nCldrOptions.js'
32
+ ),
33
+ '@salesforce/i18n/dateTime.shortDateFormat': require.resolve(
34
+ '../lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateFormat.js'
35
+ ),
36
+ '@salesforce/i18n/dateTime.shortTimeFormat': require.resolve(
37
+ '../lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortTimeFormat.js'
38
+ ),
39
+ '@salesforce/i18n/dateTime.shortDateTimeFormat': require.resolve(
40
+ '../lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateTimeFormat.js'
41
+ ),
42
+ },
43
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@salesforce/lds-ads-bridge",
3
+ "version": "0.1.0-dev1",
4
+ "license": "SEE LICENSE IN LICENSE.txt",
5
+ "description": "Bridge to sync data between LDS and ADS",
6
+ "main": "dist/adsBridge.js",
7
+ "module": "dist/adsBridge.js",
8
+ "types": "dist/types/main.d.ts",
9
+ "sfdc": {
10
+ "path": "forcelds/adsBridge/",
11
+ "publishedFileName": "adsBridge.js",
12
+ "overrides": {
13
+ "artifactDirectory": "dist",
14
+ "outputModuleName": "adsBridge",
15
+ "artifacts": {
16
+ "ads-bridge-perf.js": {
17
+ "ignore": true
18
+ }
19
+ }
20
+ }
21
+ },
22
+ "scripts": {
23
+ "prepare": "yarn build",
24
+ "build": "rollup --bundleConfigAsCjs --config rollup.config.js",
25
+ "clean": "rm -rf dist",
26
+ "test:perf": "best",
27
+ "test:size": "luvioBundlesize",
28
+ "test:unit": "jest",
29
+ "test:unit:debug": "node --inspect-brk ../../node_modules/.bin/jest --runInBand",
30
+ "release:corejar": "yarn build && ../core-build/scripts/core.js --name=lds-ads-bridge"
31
+ },
32
+ "devDependencies": {
33
+ "@salesforce/lds-adapters-uiapi": "^0.1.0-dev1",
34
+ "@salesforce/lds-runtime-mobile": "^0.1.0-dev1",
35
+ "@salesforce/lds-uiapi-record-utils-mobile": "^0.1.0-dev1"
36
+ },
37
+ "volta": {
38
+ "extends": "../../package.json"
39
+ },
40
+ "luvioBundlesize": [
41
+ {
42
+ "path": "./dist/adsBridge.js",
43
+ "maxSize": {
44
+ "none": "17 kB",
45
+ "min": "5.51 kB",
46
+ "compressed": "4 kB"
47
+ }
48
+ }
49
+ ]
50
+ }