@salesforce/lds-drafts 1.130.10 → 1.131.0-dev11
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/ldsDrafts.js +28 -48
- package/dist/types/DraftIdMapping.d.ts +1 -1
- package/dist/types/DraftStore.d.ts +1 -2
- package/dist/types/DurableDraftStore.d.ts +1 -2
- package/dist/types/actionHandlers/AbstractResourceRequestActionHandler.d.ts +1 -1
- package/dist/types/actionHandlers/ActionHandler.d.ts +1 -9
- package/package.json +4 -4
package/dist/ldsDrafts.js
CHANGED
|
@@ -231,7 +231,6 @@ function buildLuvioOverrideForDraftAdapters(luvio, handler, extractTargetIdFromC
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
const DraftIdMappingKeyPrefix240 = 'DraftIdMapping::';
|
|
234
|
-
const DraftKeyMappingKeyPrefix = 'DraftKeyMapping::V2::';
|
|
235
234
|
const DRAFT_ID_MAPPINGS_SEGMENT = 'DRAFT_ID_MAPPINGS';
|
|
236
235
|
function isLegacyDraftIdMapping(key, data) {
|
|
237
236
|
return key.startsWith(DraftIdMappingKeyPrefix240);
|
|
@@ -241,9 +240,6 @@ function isLegacyDraftIdMapping(key, data) {
|
|
|
241
240
|
function getRecordKeyForId(id) {
|
|
242
241
|
return `UiApi::RecordRepresentation:${id}`;
|
|
243
242
|
}
|
|
244
|
-
function generateDraftIdMappingKey(draftIdMapping) {
|
|
245
|
-
return `${DraftKeyMappingKeyPrefix}${draftIdMapping.draftKey}::${draftIdMapping.canonicalKey}`;
|
|
246
|
-
}
|
|
247
243
|
/**
|
|
248
244
|
*
|
|
249
245
|
* @param mappingIds (optional) requested mapping ids, if undefined all will be retrieved
|
|
@@ -277,6 +273,15 @@ async function getDraftIdMappings(durableStore, mappingIds) {
|
|
|
277
273
|
}
|
|
278
274
|
return mappings;
|
|
279
275
|
}
|
|
276
|
+
async function clearDraftIdSegment(durableStore) {
|
|
277
|
+
const entries = await durableStore.getAllEntries(DRAFT_ID_MAPPINGS_SEGMENT);
|
|
278
|
+
if (entries) {
|
|
279
|
+
const keys$1 = keys(entries);
|
|
280
|
+
if (keys$1.length > 0) {
|
|
281
|
+
await durableStore.evictEntries(keys$1, DRAFT_ID_MAPPINGS_SEGMENT);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
280
285
|
|
|
281
286
|
/**
|
|
282
287
|
* Generates a time-ordered, unique id to associate with a DraftAction. Ensures
|
|
@@ -367,9 +372,6 @@ function customActionHandler(executor, id, draftQueue) {
|
|
|
367
372
|
});
|
|
368
373
|
return queueOperations;
|
|
369
374
|
};
|
|
370
|
-
const getRedirectMappings = (_action) => {
|
|
371
|
-
return undefined;
|
|
372
|
-
};
|
|
373
375
|
return {
|
|
374
376
|
handlerId: id,
|
|
375
377
|
enqueue: (data) => {
|
|
@@ -381,7 +383,6 @@ function customActionHandler(executor, id, draftQueue) {
|
|
|
381
383
|
handleReplaceAction: () => {
|
|
382
384
|
throw Error('replaceAction not supported for custom actions');
|
|
383
385
|
},
|
|
384
|
-
getRedirectMappings,
|
|
385
386
|
handleActionRemoved: () => Promise.resolve(),
|
|
386
387
|
handleActionCompleted: () => Promise.resolve(),
|
|
387
388
|
handleActionEnqueued: () => Promise.resolve(),
|
|
@@ -556,17 +557,11 @@ class DurableDraftQueue {
|
|
|
556
557
|
const handler = this.getHandler(action.handler);
|
|
557
558
|
let queue = await this.getQueueActions();
|
|
558
559
|
const queueOperations = handler.getQueueOperationsForCompletingDrafts(queue, action);
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
: idAndKeyMappings.map((m) => {
|
|
563
|
-
return { draftKey: m.draftKey, canonicalKey: m.canonicalKey };
|
|
564
|
-
});
|
|
565
|
-
await this.draftStore.completeAction(queueOperations, keyMappings);
|
|
566
|
-
queue = await this.getQueueActions();
|
|
560
|
+
// write the queue operations to the store prior to ingesting the result
|
|
561
|
+
await this.draftStore.completeAction(queueOperations);
|
|
562
|
+
await handler.handleActionCompleted(action, queueOperations, values(this.handlers));
|
|
567
563
|
this.retryIntervalMilliseconds = 0;
|
|
568
564
|
this.uploadingActionId = undefined;
|
|
569
|
-
await handler.handleActionCompleted(action, queueOperations, queue, values(this.handlers));
|
|
570
565
|
await this.notifyChangedListeners({
|
|
571
566
|
type: DraftQueueEventType.ActionCompleted,
|
|
572
567
|
action,
|
|
@@ -885,7 +880,7 @@ class DurableDraftStore {
|
|
|
885
880
|
};
|
|
886
881
|
return this.enqueueAction(deleteAction);
|
|
887
882
|
}
|
|
888
|
-
completeAction(queueOperations
|
|
883
|
+
completeAction(queueOperations) {
|
|
889
884
|
const action = () => {
|
|
890
885
|
const durableStoreOperations = [];
|
|
891
886
|
const { draftStore } = this;
|
|
@@ -918,18 +913,6 @@ class DurableDraftStore {
|
|
|
918
913
|
});
|
|
919
914
|
}
|
|
920
915
|
}
|
|
921
|
-
if (mappings !== undefined) {
|
|
922
|
-
const entries = {};
|
|
923
|
-
for (const mapping of mappings) {
|
|
924
|
-
const mappingKey = generateDraftIdMappingKey(mapping);
|
|
925
|
-
entries[mappingKey] = { data: mapping };
|
|
926
|
-
}
|
|
927
|
-
durableStoreOperations.push({
|
|
928
|
-
entries,
|
|
929
|
-
type: 'setEntries',
|
|
930
|
-
segment: DRAFT_ID_MAPPINGS_SEGMENT,
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
916
|
return this.durableStore.batchOperations(durableStoreOperations);
|
|
934
917
|
};
|
|
935
918
|
return this.enqueueAction(action);
|
|
@@ -1208,7 +1191,7 @@ class AbstractResourceRequestActionHandler {
|
|
|
1208
1191
|
},
|
|
1209
1192
|
];
|
|
1210
1193
|
}
|
|
1211
|
-
async handleActionCompleted(action, queueOperations,
|
|
1194
|
+
async handleActionCompleted(action, queueOperations, allHandlers) {
|
|
1212
1195
|
const { data: request, tag } = action;
|
|
1213
1196
|
const { method } = request;
|
|
1214
1197
|
if (method === 'delete') {
|
|
@@ -1285,6 +1268,8 @@ class AbstractResourceRequestActionHandler {
|
|
|
1285
1268
|
};
|
|
1286
1269
|
// overlay metadata
|
|
1287
1270
|
merged.metadata = { ...targetMetadata, ...sourceMetadata };
|
|
1271
|
+
// put status back to pending to auto upload if queue is active and targed is at the head.
|
|
1272
|
+
merged.status = DraftActionStatus.Pending;
|
|
1288
1273
|
return merged;
|
|
1289
1274
|
}
|
|
1290
1275
|
shouldDeleteActionByTagOnRemoval(action) {
|
|
@@ -1320,11 +1305,18 @@ class AbstractResourceRequestActionHandler {
|
|
|
1320
1305
|
async ingestResponses(responses, action) {
|
|
1321
1306
|
const luvio = this.getLuvio();
|
|
1322
1307
|
await luvio.handleSuccessResponse(() => {
|
|
1308
|
+
if (action.status === DraftActionStatus.Completed) {
|
|
1309
|
+
const mappings = this.getRedirectMappings(action);
|
|
1310
|
+
if (mappings) {
|
|
1311
|
+
mappings.forEach((mapping) => {
|
|
1312
|
+
luvio.storeRedirect(mapping.draftKey, mapping.canonicalKey);
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1323
1316
|
for (const entry of responses) {
|
|
1324
1317
|
const { response, synchronousIngest } = entry;
|
|
1325
1318
|
synchronousIngest(response, action);
|
|
1326
1319
|
}
|
|
1327
|
-
// must call base broadcast
|
|
1328
1320
|
return luvio.storeBroadcast();
|
|
1329
1321
|
},
|
|
1330
1322
|
// getTypeCacheKeysRecord uses the response, not the full path factory
|
|
@@ -1652,6 +1644,8 @@ class DraftManager {
|
|
|
1652
1644
|
|
|
1653
1645
|
function makeEnvironmentDraftAware(luvio, env, durableStore, handlers, draftQueue) {
|
|
1654
1646
|
const draftMetadata = {};
|
|
1647
|
+
// in 246 luvio took charge of persisting redirect mappings, this needs to stick around
|
|
1648
|
+
// for a couple of releases to support older environments
|
|
1655
1649
|
// setup existing store redirects when bootstrapping the environment
|
|
1656
1650
|
(async () => {
|
|
1657
1651
|
const mappings = await getDraftIdMappings(durableStore);
|
|
@@ -1659,23 +1653,9 @@ function makeEnvironmentDraftAware(luvio, env, durableStore, handlers, draftQueu
|
|
|
1659
1653
|
const { draftKey, canonicalKey } = mapping;
|
|
1660
1654
|
env.storeRedirect(draftKey, canonicalKey);
|
|
1661
1655
|
});
|
|
1656
|
+
await env.storeBroadcast(env.rebuildSnapshot, env.snapshotAvailable);
|
|
1657
|
+
await clearDraftIdSegment(durableStore);
|
|
1662
1658
|
})();
|
|
1663
|
-
durableStore.registerOnChangedListener(async (changes) => {
|
|
1664
|
-
const draftIdMappingsIds = [];
|
|
1665
|
-
for (let i = 0, len = changes.length; i < len; i++) {
|
|
1666
|
-
const change = changes[i];
|
|
1667
|
-
if (change.segment === DRAFT_ID_MAPPINGS_SEGMENT) {
|
|
1668
|
-
draftIdMappingsIds.push(...change.ids);
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
if (draftIdMappingsIds.length > 0) {
|
|
1672
|
-
const mappings = await getDraftIdMappings(durableStore, draftIdMappingsIds);
|
|
1673
|
-
mappings.forEach((mapping) => {
|
|
1674
|
-
const { draftKey, canonicalKey } = mapping;
|
|
1675
|
-
env.storeRedirect(draftKey, canonicalKey);
|
|
1676
|
-
});
|
|
1677
|
-
}
|
|
1678
|
-
});
|
|
1679
1659
|
const handleSuccessResponse = async function (ingestAndBroadcastFunc, getResponseCacheKeysFunc) {
|
|
1680
1660
|
const queue = await draftQueue.getQueueActions();
|
|
1681
1661
|
if (queue.length === 0) {
|
|
@@ -4,9 +4,9 @@ export interface DraftKeyMapping {
|
|
|
4
4
|
canonicalKey: string;
|
|
5
5
|
}
|
|
6
6
|
export declare const DRAFT_ID_MAPPINGS_SEGMENT = "DRAFT_ID_MAPPINGS";
|
|
7
|
-
export declare function generateDraftIdMappingKey(draftIdMapping: DraftKeyMapping): string;
|
|
8
7
|
/**
|
|
9
8
|
*
|
|
10
9
|
* @param mappingIds (optional) requested mapping ids, if undefined all will be retrieved
|
|
11
10
|
*/
|
|
12
11
|
export declare function getDraftIdMappings(durableStore: DurableStore, mappingIds?: string[]): Promise<DraftKeyMapping[]>;
|
|
12
|
+
export declare function clearDraftIdSegment(durableStore: DurableStore): Promise<void>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { DraftAction, QueueOperation } from './DraftQueue';
|
|
2
|
-
import type { DraftKeyMapping } from './DraftIdMapping';
|
|
3
2
|
/**
|
|
4
3
|
* Defines the store where drafts are persisted
|
|
5
4
|
*/
|
|
@@ -8,5 +7,5 @@ export interface DraftStore {
|
|
|
8
7
|
getAllDrafts(): Promise<DraftAction<unknown, unknown>[]>;
|
|
9
8
|
deleteDraft(actionId: string): Promise<void>;
|
|
10
9
|
deleteByTag(tag: string): Promise<void>;
|
|
11
|
-
completeAction(queueOperations: QueueOperation[]
|
|
10
|
+
completeAction(queueOperations: QueueOperation[]): Promise<void>;
|
|
12
11
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { DurableStore } from '@luvio/environments';
|
|
2
|
-
import type { DraftKeyMapping } from './DraftIdMapping';
|
|
3
2
|
import type { DraftAction, QueueOperation } from './DraftQueue';
|
|
4
3
|
import type { DraftStore } from './DraftStore';
|
|
5
4
|
/**
|
|
@@ -21,7 +20,7 @@ export declare class DurableDraftStore implements DraftStore {
|
|
|
21
20
|
getAllDrafts<_R, _D>(): Promise<DraftAction<unknown, unknown>[]>;
|
|
22
21
|
deleteDraft(id: string): Promise<void>;
|
|
23
22
|
deleteByTag(tag: string): Promise<void>;
|
|
24
|
-
completeAction(queueOperations: QueueOperation[]
|
|
23
|
+
completeAction(queueOperations: QueueOperation[]): Promise<void>;
|
|
25
24
|
/**
|
|
26
25
|
* Runs a write operation against the draft store, if the initial
|
|
27
26
|
* revive is still in progress, the action gets enqueued to run once the
|
|
@@ -22,7 +22,7 @@ export declare abstract class AbstractResourceRequestActionHandler<ResponseType,
|
|
|
22
22
|
handleActionRemoved(action: DraftAction<ResourceRequest, ResponseType>): Promise<void>;
|
|
23
23
|
getQueueOperationsForCompletingDrafts(queue: DraftAction<unknown, unknown>[], action: CompletedDraftAction<ResourceRequest, ResponseType>): QueueOperation[];
|
|
24
24
|
getRedirectMappings(action: CompletedDraftAction<ResourceRequest, ResponseType>): DraftIdAndKeyMapping[] | undefined;
|
|
25
|
-
handleActionCompleted(action: CompletedDraftAction<ResourceRequest, ResponseType>, queueOperations: QueueOperation[],
|
|
25
|
+
handleActionCompleted(action: CompletedDraftAction<ResourceRequest, ResponseType>, queueOperations: QueueOperation[], allHandlers: ActionHandler<unknown, unknown, unknown>[]): Promise<void>;
|
|
26
26
|
handleReplaceAction(targetAction: DraftAction<ResourceRequest, ResponseType>, sourceAction: DraftAction<ResourceRequest, ResponseType>): DraftAction<ResourceRequest, ResponseType>;
|
|
27
27
|
mergeActions(targetAction: DraftAction<ResourceRequest, ResponseType>, sourceAction: DraftAction<ResourceRequest, ResponseType>): DraftAction<ResourceRequest, ResponseType>;
|
|
28
28
|
shouldDeleteActionByTagOnRemoval(action: DraftAction<ResourceRequest, ResponseType>): boolean;
|
|
@@ -72,20 +72,12 @@ export interface ActionHandler<Data, DraftMetadata, Type> {
|
|
|
72
72
|
* @param action
|
|
73
73
|
*/
|
|
74
74
|
getQueueOperationsForCompletingDrafts(queue: DraftAction<unknown, unknown>[], action: CompletedDraftAction<Data, Type>): QueueOperation[];
|
|
75
|
-
/**
|
|
76
|
-
* Invoked by the draft queue when an action is completing. Sometimes after an action completes we
|
|
77
|
-
* need to perform a key redirect (i.e. an object that used to have a draft id now has a real id and it needs to redirect the old id)
|
|
78
|
-
* This function returns an array of mappings if necessary or undefined if no redirect is necessary as a result of the completed operation
|
|
79
|
-
* @param action
|
|
80
|
-
*/
|
|
81
|
-
getRedirectMappings(action: CompletedDraftAction<Data, Type>): DraftIdAndKeyMapping[] | undefined;
|
|
82
75
|
/**
|
|
83
76
|
* Invoked by the draft queue after an action completes and is removed from the queue
|
|
84
77
|
* @param action The completed action
|
|
85
78
|
* @param queueOperations The queue modification operations that were executes with the completed action
|
|
86
|
-
* @param queue The updated queue with the completed action removed
|
|
87
79
|
*/
|
|
88
|
-
handleActionCompleted(action: CompletedDraftAction<Data, Type>, queueOperations: QueueOperation[],
|
|
80
|
+
handleActionCompleted(action: CompletedDraftAction<Data, Type>, queueOperations: QueueOperation[], allHandlers: ActionHandler<unknown, unknown, unknown>[]): Promise<void>;
|
|
89
81
|
/**
|
|
90
82
|
* Replace the targetAction's data with the sourceAction's data and return
|
|
91
83
|
* the targetAction. Also sets the targetAction's status to Pending.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/lds-drafts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.131.0-dev11",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"description": "LDS Drafts",
|
|
6
6
|
"main": "dist/ldsDrafts.js",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"release:corejar": "yarn build && ../core-build/scripts/core.js --adapter=lds-drafts"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@luvio/engine": "0.138.8",
|
|
28
|
-
"@luvio/environments": "0.138.8",
|
|
29
|
-
"@salesforce/lds-utils-adapters": "
|
|
27
|
+
"@luvio/engine": "0.138.8-244.1",
|
|
28
|
+
"@luvio/environments": "0.138.8-244.1",
|
|
29
|
+
"@salesforce/lds-utils-adapters": "1.131.0-dev11"
|
|
30
30
|
}
|
|
31
31
|
}
|