@salesforce/lds-durable-records 1.332.0-dev2 → 1.332.0-dev21
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.
|
@@ -5,13 +5,19 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { DefaultDurableSegment, DURABLE_METADATA_VERSION } from '@luvio/environments';
|
|
8
|
-
import {
|
|
8
|
+
import { RECORD_VIEW_ENTITY_ID_PREFIX, API_NAMESPACE, isStoreKeyRecordViewEntity, extractRecordIdFromStoreKey, keyBuilderRecord, RECORD_FIELDS_KEY_JUNCTION, RECORD_ID_PREFIX } from '@salesforce/lds-adapters-uiapi';
|
|
9
9
|
|
|
10
10
|
const { keys, values, create, assign, freeze, entries } = Object;
|
|
11
11
|
|
|
12
|
+
const RECORD_TEMPLATE_CREATE_REPRESENTATION_NAME = 'RecordTemplateCreateRepresentation';
|
|
13
|
+
const RECORD_TEMPLATE_CREATE_REPRESENTATION_PREFIX = `${API_NAMESPACE}::${RECORD_TEMPLATE_CREATE_REPRESENTATION_NAME}:`;
|
|
12
14
|
function buildRecordFieldStoreKey(recordKey, fieldName) {
|
|
13
15
|
return `${recordKey}${RECORD_FIELDS_KEY_JUNCTION}${fieldName}`;
|
|
14
16
|
}
|
|
17
|
+
function isStoreKeyRecordTemplateId(key) {
|
|
18
|
+
return (key.indexOf(RECORD_TEMPLATE_CREATE_REPRESENTATION_PREFIX) > -1 &&
|
|
19
|
+
key.indexOf(RECORD_FIELDS_KEY_JUNCTION) === -1);
|
|
20
|
+
}
|
|
15
21
|
function isStoreKeyRecordId(key) {
|
|
16
22
|
return key.indexOf(RECORD_ID_PREFIX) > -1 && key.indexOf(RECORD_FIELDS_KEY_JUNCTION) === -1;
|
|
17
23
|
}
|
|
@@ -23,7 +29,9 @@ function isStoreRecordError(storeRecord) {
|
|
|
23
29
|
}
|
|
24
30
|
function isEntryDurableRecordRepresentation(entry, key) {
|
|
25
31
|
// Either a DurableRecordRepresentation or StoreRecordError can live at a record key
|
|
26
|
-
return ((isStoreKeyRecordId(key) ||
|
|
32
|
+
return ((isStoreKeyRecordId(key) ||
|
|
33
|
+
isStoreKeyRecordViewEntity(key) ||
|
|
34
|
+
isStoreKeyRecordTemplateId(key)) &&
|
|
27
35
|
entry.data.__type === undefined);
|
|
28
36
|
}
|
|
29
37
|
/**
|
|
@@ -132,6 +140,29 @@ function buildDurableRecordRepresentation(normalizedRecord, records, pendingEntr
|
|
|
132
140
|
fields: filteredFields,
|
|
133
141
|
};
|
|
134
142
|
}
|
|
143
|
+
// We have a local version of this that calls the imported version because
|
|
144
|
+
// we need to check for a prefix that is defined in this file
|
|
145
|
+
function extractRecordIdFromStoreKeyWithRecordTemplate(key) {
|
|
146
|
+
const superResult = extractRecordIdFromStoreKey(key);
|
|
147
|
+
if (superResult) {
|
|
148
|
+
return superResult;
|
|
149
|
+
}
|
|
150
|
+
if (key === undefined || key.indexOf(RECORD_TEMPLATE_CREATE_REPRESENTATION_PREFIX) === -1) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
const parts = key.split(':');
|
|
154
|
+
return parts[parts.length - 1].split('_')[0];
|
|
155
|
+
}
|
|
156
|
+
function buildRecordTemplateCreateKeyFromId(recordId, apiName) {
|
|
157
|
+
return `${RECORD_TEMPLATE_CREATE_REPRESENTATION_PREFIX}${apiName}:${recordId}`;
|
|
158
|
+
}
|
|
159
|
+
function extractAPINameFromRecordTemplateKey(originalKey) {
|
|
160
|
+
if (originalKey.indexOf(RECORD_TEMPLATE_CREATE_REPRESENTATION_PREFIX) !== -1) {
|
|
161
|
+
const trimmed = originalKey.substring(RECORD_TEMPLATE_CREATE_REPRESENTATION_PREFIX.length);
|
|
162
|
+
return trimmed.split(':')[0];
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
135
166
|
function getDenormalizedKey(originalKey, recordId, luvio) {
|
|
136
167
|
// this will likely need to be handled when moving to structured keys
|
|
137
168
|
// note record view entities dont have an associated keybuilder. They get ingested as records to a different key format
|
|
@@ -139,6 +170,11 @@ function getDenormalizedKey(originalKey, recordId, luvio) {
|
|
|
139
170
|
if (originalKey.startsWith(RECORD_VIEW_ENTITY_ID_PREFIX)) {
|
|
140
171
|
return RECORD_VIEW_ENTITY_ID_PREFIX + recordId;
|
|
141
172
|
}
|
|
173
|
+
// if key starts with record template, return that plus record id and api name
|
|
174
|
+
const apiName = extractAPINameFromRecordTemplateKey(originalKey);
|
|
175
|
+
if (originalKey.startsWith(RECORD_TEMPLATE_CREATE_REPRESENTATION_PREFIX) && apiName) {
|
|
176
|
+
return buildRecordTemplateCreateKeyFromId(recordId, apiName);
|
|
177
|
+
}
|
|
142
178
|
return keyBuilderRecord(luvio, { recordId });
|
|
143
179
|
}
|
|
144
180
|
function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecords, getStoreMetadata, getStore, sqlStore) {
|
|
@@ -156,9 +192,10 @@ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecord
|
|
|
156
192
|
// map of records to avoid requesting duplicate record keys when requesting both records and fields
|
|
157
193
|
const recordEntries = {};
|
|
158
194
|
const recordViewEntries = {};
|
|
195
|
+
const recordTemplateEntries = {};
|
|
159
196
|
for (let i = 0, len = entriesLength; i < len; i++) {
|
|
160
197
|
const id = entries[i];
|
|
161
|
-
const recordId =
|
|
198
|
+
const recordId = extractRecordIdFromStoreKeyWithRecordTemplate(id);
|
|
162
199
|
if (recordId !== undefined) {
|
|
163
200
|
if (id.startsWith(RECORD_VIEW_ENTITY_ID_PREFIX)) {
|
|
164
201
|
if (recordViewEntries[recordId] === undefined) {
|
|
@@ -167,6 +204,13 @@ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecord
|
|
|
167
204
|
filteredEntryIds.push(key);
|
|
168
205
|
}
|
|
169
206
|
}
|
|
207
|
+
else if (id.startsWith(RECORD_TEMPLATE_CREATE_REPRESENTATION_PREFIX)) {
|
|
208
|
+
if (recordTemplateEntries[recordId] === undefined) {
|
|
209
|
+
const key = getDenormalizedKey(id, recordId, luvio);
|
|
210
|
+
recordTemplateEntries[recordId] = true;
|
|
211
|
+
filteredEntryIds.push(key);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
170
214
|
else {
|
|
171
215
|
if (recordEntries[recordId] === undefined) {
|
|
172
216
|
const key = getDenormalizedKey(id, recordId, luvio);
|
|
@@ -210,21 +254,29 @@ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecord
|
|
|
210
254
|
const keys$1 = keys(entries);
|
|
211
255
|
const putRecords = {};
|
|
212
256
|
const putRecordViews = {};
|
|
257
|
+
const putRecordTemplateViews = {};
|
|
213
258
|
const storeRecords = getStoreRecords !== undefined ? getStoreRecords() : {};
|
|
214
259
|
const storeMetadata = getStoreMetadata !== undefined ? getStoreMetadata() : {};
|
|
215
260
|
const store = getStore();
|
|
216
261
|
for (let i = 0, len = keys$1.length; i < len; i++) {
|
|
217
262
|
const key = keys$1[i];
|
|
218
263
|
let value = entries[key];
|
|
219
|
-
const recordId =
|
|
264
|
+
const recordId = extractRecordIdFromStoreKeyWithRecordTemplate(key);
|
|
220
265
|
// do not put normalized field values
|
|
221
266
|
if (recordId !== undefined) {
|
|
222
267
|
const isRecordView = key.startsWith(RECORD_VIEW_ENTITY_ID_PREFIX);
|
|
268
|
+
const isRecordTemplateView = key.startsWith(RECORD_TEMPLATE_CREATE_REPRESENTATION_PREFIX);
|
|
269
|
+
// put a record view in there for record templates
|
|
223
270
|
if (isRecordView) {
|
|
224
271
|
if (putRecordViews[recordId] === true) {
|
|
225
272
|
continue;
|
|
226
273
|
}
|
|
227
274
|
}
|
|
275
|
+
else if (isRecordTemplateView) {
|
|
276
|
+
if (putRecordTemplateViews[recordId] === true) {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
228
280
|
else {
|
|
229
281
|
if (putRecords[recordId] === true) {
|
|
230
282
|
continue;
|
|
@@ -245,6 +297,9 @@ function makeRecordDenormalizingDurableStore(luvio, durableStore, getStoreRecord
|
|
|
245
297
|
if (isRecordView) {
|
|
246
298
|
putRecordViews[recordId] = true;
|
|
247
299
|
}
|
|
300
|
+
else if (isRecordTemplateView) {
|
|
301
|
+
putRecordTemplateViews[recordId] = true;
|
|
302
|
+
}
|
|
248
303
|
else {
|
|
249
304
|
putRecords[recordId] = true;
|
|
250
305
|
}
|
|
@@ -2,6 +2,10 @@ import type { RecordSource, InMemoryStore, Luvio, StoreRecordError } from '@luvi
|
|
|
2
2
|
import type { DurableStore, DurableStoreEntry } from '@luvio/environments';
|
|
3
3
|
import type { NimbusSqliteStore } from '@salesforce/lds-store-nimbus';
|
|
4
4
|
import type { DurableRecordRepresentation } from './main';
|
|
5
|
+
export declare const RECORD_TEMPLATE_CREATE_REPRESENTATION_NAME = "RecordTemplateCreateRepresentation";
|
|
6
|
+
export declare const RECORD_TEMPLATE_CREATE_REPRESENTATION_PREFIX: string;
|
|
7
|
+
export declare function isStoreKeyRecordTemplateId(key: string): boolean;
|
|
5
8
|
export declare function isStoreRecordError(storeRecord: object): storeRecord is StoreRecordError;
|
|
6
9
|
export declare function isEntryDurableRecordRepresentation(entry: DurableStoreEntry<any>, key: string): entry is DurableStoreEntry<DurableRecordRepresentation>;
|
|
10
|
+
export declare function extractAPINameFromRecordTemplateKey(originalKey: string): string | undefined;
|
|
7
11
|
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.332.0-
|
|
3
|
+
"version": "1.332.0-dev21",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"description": "LDS Record Utilities",
|
|
6
6
|
"main": "dist/ldsDurableRecords.js",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@luvio/engine": "0.156.5",
|
|
27
27
|
"@luvio/environments": "0.156.5",
|
|
28
|
-
"@salesforce/lds-adapters-uiapi": "^1.332.0-
|
|
28
|
+
"@salesforce/lds-adapters-uiapi": "^1.332.0-dev21"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@salesforce/lds-store-nimbus": "^1.332.0-
|
|
31
|
+
"@salesforce/lds-store-nimbus": "^1.332.0-dev21"
|
|
32
32
|
}
|
|
33
33
|
}
|