@salesforce/lds-durable-records 1.299.0 → 1.300.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.
|
@@ -36,7 +36,7 @@ function isEntryDurableRecordRepresentation(entry, key) {
|
|
|
36
36
|
function normalizeRecordFields(key, entry) {
|
|
37
37
|
const { data: record } = entry;
|
|
38
38
|
const { fields, links } = record;
|
|
39
|
-
const missingFieldLinks = keys(links);
|
|
39
|
+
const missingFieldLinks = links === undefined ? [] : keys(links);
|
|
40
40
|
const fieldNames = keys(fields);
|
|
41
41
|
const normalizedFields = {};
|
|
42
42
|
const returnEntries = {};
|
|
@@ -44,6 +44,10 @@ function normalizeRecordFields(key, entry) {
|
|
|
44
44
|
for (let i = 0, len = fieldNames.length; i < len; i++) {
|
|
45
45
|
const fieldName = fieldNames[i];
|
|
46
46
|
const field = fields[fieldName];
|
|
47
|
+
if (field.__state !== undefined && field.__state.isMissing === true) {
|
|
48
|
+
normalizedFields[fieldName] = { isMissing: true, __ref: undefined };
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
47
51
|
const fieldKey = buildRecordFieldStoreKey(key, fieldName);
|
|
48
52
|
returnEntries[fieldKey] = { data: field };
|
|
49
53
|
normalizedFields[fieldName] = createLink(fieldKey);
|
|
@@ -75,7 +79,6 @@ function normalizeRecordFields(key, entry) {
|
|
|
75
79
|
function buildDurableRecordRepresentation(normalizedRecord, records, pendingEntries, store) {
|
|
76
80
|
const fields = normalizedRecord.fields;
|
|
77
81
|
const filteredFields = {};
|
|
78
|
-
const links = {};
|
|
79
82
|
const fieldNames = keys(fields);
|
|
80
83
|
for (let i = 0, len = fieldNames.length; i < len; i++) {
|
|
81
84
|
const fieldName = fieldNames[i];
|
|
@@ -117,13 +120,16 @@ function buildDurableRecordRepresentation(normalizedRecord, records, pendingEntr
|
|
|
117
120
|
}
|
|
118
121
|
// we want to preserve fields that are missing nodes
|
|
119
122
|
if (field.isMissing === true) {
|
|
120
|
-
|
|
123
|
+
filteredFields[fieldName] = {
|
|
124
|
+
value: undefined,
|
|
125
|
+
displayValue: undefined,
|
|
126
|
+
__state: { isMissing: true },
|
|
127
|
+
};
|
|
121
128
|
}
|
|
122
129
|
}
|
|
123
130
|
return {
|
|
124
131
|
...normalizedRecord,
|
|
125
132
|
fields: filteredFields,
|
|
126
|
-
links,
|
|
127
133
|
};
|
|
128
134
|
}
|
|
129
135
|
function getDenormalizedKey(originalKey, recordId, luvio) {
|
|
@@ -351,36 +357,66 @@ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecord
|
|
|
351
357
|
}
|
|
352
358
|
return durableStore.batchOperations(operationsWithDenormedRecords);
|
|
353
359
|
};
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
360
|
+
return create(durableStore, {
|
|
361
|
+
getEntries: { value: getEntries, writable: true },
|
|
362
|
+
setEntries: { value: setEntries, writable: true },
|
|
363
|
+
batchOperations: { value: batchOperations, writable: true },
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// TODO [W-15983267]: this is here for backwards compatibility from <252 and can be removed in 256
|
|
368
|
+
// This HOF ensures that missing links that are stored in the "links" property in the durable store get restored to the "fields" property.
|
|
369
|
+
// this code is necessary for backwards compatibility with records that were stored in the durable store before the "links" property was removed.
|
|
370
|
+
function makeDurableStoreBackwardsCompatible(durableStore) {
|
|
371
|
+
const getEntries = function (entries, segment) {
|
|
372
|
+
// this HOF only inspects records in the default segment
|
|
373
|
+
if (segment !== DefaultDurableSegment) {
|
|
374
|
+
return durableStore.getEntries(entries, segment);
|
|
375
|
+
}
|
|
376
|
+
const { length: entriesLength } = entries;
|
|
377
|
+
if (entriesLength === 0) {
|
|
378
|
+
return Promise.resolve({});
|
|
379
|
+
}
|
|
380
|
+
// call base getEntries
|
|
381
|
+
return durableStore.getEntries(entries, segment).then((durableEntries) => {
|
|
382
|
+
if (durableEntries === undefined) {
|
|
368
383
|
return undefined;
|
|
369
384
|
}
|
|
370
|
-
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
385
|
+
const returnEntries = create(null);
|
|
386
|
+
const keys$1 = keys(durableEntries);
|
|
387
|
+
for (let i = 0, len = keys$1.length; i < len; i++) {
|
|
388
|
+
const key = keys$1[i];
|
|
389
|
+
const value = durableEntries[key];
|
|
390
|
+
if (value === undefined) {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (isEntryDurableRecordRepresentation(value, key)) {
|
|
394
|
+
const record = value.data;
|
|
395
|
+
const { links } = record;
|
|
396
|
+
if (links !== undefined) {
|
|
397
|
+
const missingLinks = keys(links);
|
|
398
|
+
for (let j = 0, len = missingLinks.length; j < len; j++) {
|
|
399
|
+
const fieldName = missingLinks[j];
|
|
400
|
+
const link = links[fieldName];
|
|
401
|
+
if (link !== undefined && link.isMissing === true) {
|
|
402
|
+
record.fields[fieldName] = {
|
|
403
|
+
__state: { isMissing: true },
|
|
404
|
+
value: undefined,
|
|
405
|
+
displayValue: undefined,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
delete record.links;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
returnEntries[key] = value;
|
|
374
413
|
}
|
|
375
|
-
return
|
|
414
|
+
return returnEntries;
|
|
376
415
|
});
|
|
377
416
|
};
|
|
378
417
|
return create(durableStore, {
|
|
379
418
|
getEntries: { value: getEntries, writable: true },
|
|
380
|
-
setEntries: { value: setEntries, writable: true },
|
|
381
|
-
batchOperations: { value: batchOperations, writable: true },
|
|
382
|
-
getDenormalizedRecord: { value: getDenormalizedRecord, writable: true },
|
|
383
419
|
});
|
|
384
420
|
}
|
|
385
421
|
|
|
386
|
-
export { makeRecordDenormalizingDurableStore };
|
|
422
|
+
export { makeDurableStoreBackwardsCompatible, makeRecordDenormalizingDurableStore };
|
package/dist/types/main.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { makeRecordDenormalizingDurableStore
|
|
1
|
+
export { makeRecordDenormalizingDurableStore } from './makeRecordDenormalizingDurableStore';
|
|
2
|
+
export { makeDurableStoreBackwardsCompatible } from './makeDurableStoreBackwardsCompatible';
|
|
2
3
|
export interface DurableRecordRepresentation {
|
|
3
4
|
drafts?: {
|
|
4
5
|
created: boolean;
|
|
@@ -11,13 +12,17 @@ export interface DurableRecordRepresentation {
|
|
|
11
12
|
draftActionIds: string[];
|
|
12
13
|
latestDraftActionId: string;
|
|
13
14
|
};
|
|
14
|
-
links
|
|
15
|
+
links?: Record<string, DurableStoreLink>;
|
|
15
16
|
apiName: string;
|
|
16
17
|
childRelationships: Record<string, DurableStoreLink>;
|
|
17
18
|
eTag: string;
|
|
18
19
|
fields: Record<string, {
|
|
19
|
-
value: ScalarFieldType | DurableStoreLink;
|
|
20
|
-
displayValue: string | null;
|
|
20
|
+
value: ScalarFieldType | DurableStoreLink | undefined;
|
|
21
|
+
displayValue: string | null | undefined;
|
|
22
|
+
__state?: {
|
|
23
|
+
isMissing?: true;
|
|
24
|
+
pending?: true;
|
|
25
|
+
};
|
|
21
26
|
}>;
|
|
22
27
|
id: string;
|
|
23
28
|
lastModifiedById: string | null;
|
|
@@ -4,11 +4,4 @@ import type { NimbusSqliteStore } from '@salesforce/lds-store-nimbus';
|
|
|
4
4
|
import type { DurableRecordRepresentation } from './main';
|
|
5
5
|
export declare function isStoreRecordError(storeRecord: object): storeRecord is StoreRecordError;
|
|
6
6
|
export declare function isEntryDurableRecordRepresentation(entry: DurableStoreEntry<any>, key: string): entry is DurableStoreEntry<DurableRecordRepresentation>;
|
|
7
|
-
export
|
|
8
|
-
/**
|
|
9
|
-
* Gets a record with denormalized scalar fields from the durable store (references are still normalized)
|
|
10
|
-
* @param key Record key
|
|
11
|
-
*/
|
|
12
|
-
getDenormalizedRecord(key: string): Promise<DurableRecordRepresentation | undefined>;
|
|
13
|
-
}
|
|
14
|
-
export declare function makeRecordDenormalizingDurableStore(luvio: Luvio, durableStore: DurableStore, getStoreRecords: () => RecordSource, getStoreMetadata: () => InMemoryStore['fallbackStringKeyInMemoryStore']['metadata'], getStore: () => InMemoryStore['fallbackStringKeyInMemoryStore'] | undefined, sqlStore?: NimbusSqliteStore): RecordDenormalizingDurableStore;
|
|
7
|
+
export declare function makeRecordDenormalizingDurableStore(luvio: Luvio, durableStore: DurableStore, getStoreRecords: () => RecordSource, getStoreMetadata: () => InMemoryStore['fallbackStringKeyInMemoryStore']['metadata'], getStore: () => InMemoryStore['fallbackStringKeyInMemoryStore'] | undefined, sqlStore?: NimbusSqliteStore): DurableStore;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/lds-durable-records",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.300.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"description": "LDS Record Utilities",
|
|
6
6
|
"main": "dist/ldsDurableRecords.js",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"test:unit": "jest"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@luvio/engine": "0.
|
|
27
|
-
"@luvio/environments": "0.
|
|
28
|
-
"@salesforce/lds-adapters-uiapi": "^1.
|
|
26
|
+
"@luvio/engine": "0.155.1",
|
|
27
|
+
"@luvio/environments": "0.155.1",
|
|
28
|
+
"@salesforce/lds-adapters-uiapi": "^1.300.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@salesforce/lds-store-nimbus": "^1.
|
|
31
|
+
"@salesforce/lds-store-nimbus": "^1.300.0"
|
|
32
32
|
}
|
|
33
33
|
}
|