@salesforce/lds-drafts 1.100.4 → 1.100.5

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.
@@ -144,15 +144,19 @@ export interface UpdateQueueOperation {
144
144
  action: DraftAction<unknown, unknown>;
145
145
  }
146
146
  export type QueueOperation = UpdateQueueOperation | AddQueueOperation | DeleteQueueOperation;
147
+ export interface EnqueueResult<Data, Response> {
148
+ action: PendingDraftAction<Data>;
149
+ data: Response;
150
+ }
147
151
  export interface DraftQueue {
148
152
  /**
149
153
  * Enqueues a draft action into the DraftQueue
150
154
  * @param handlerId the id of the handler associated with the data
151
155
  * @param data the data the handler will use to create the draft action with
152
- * @returns A promise including the pending action created for the request
156
+ * @returns A promise including the pending action created for the request and the data associated with the action
153
157
  * @throws {Error} An error when a proper action handler is not found or conditions are not met to enqueue the action
154
158
  */
155
- enqueue<Response>(handlerId: string, data: unknown): Promise<PendingDraftAction<Response>>;
159
+ enqueue<Data, Response>(handlerId: string, data: Data): Promise<EnqueueResult<Data, Response>>;
156
160
  /**
157
161
  * add a new handler to the draft queue to process the data in the actions
158
162
  * @param id identifier to the handler
@@ -225,11 +229,5 @@ export interface DraftQueue {
225
229
  * @param metadata The metadata to set on the specified action
226
230
  */
227
231
  setMetadata(actionId: string, metadata: DraftActionMetadata): Promise<DraftAction<unknown, unknown>>;
228
- /**
229
- * Gets the data associated with the passed in action. This data will have drafts applied to it
230
- * @param action
231
- * @returns the data for the given action or undefined if the data no longer exists
232
- */
233
- getDataForAction<T>(action: DraftAction<T, unknown>): Promise<T | undefined>;
234
232
  }
235
233
  export {};
@@ -1,4 +1,4 @@
1
- import type { DraftQueue, DraftAction, CompletedDraftAction, PendingDraftAction, DraftQueueChangeListener, DraftActionMetadata } from './DraftQueue';
1
+ import type { DraftQueue, DraftAction, CompletedDraftAction, DraftQueueChangeListener, DraftActionMetadata, EnqueueResult } from './DraftQueue';
2
2
  import { ProcessActionResult, DraftQueueState } from './DraftQueue';
3
3
  import type { CustomActionExecutor } from './actionHandlers/CustomActionHandler';
4
4
  import type { ActionHandler } from './actionHandlers/ActionHandler';
@@ -23,7 +23,6 @@ export declare class DurableDraftQueue implements DraftQueue {
23
23
  addHandler<Data>(handler: ActionHandler<Data, unknown, unknown>): Promise<void>;
24
24
  removeHandler(id: string): Promise<void>;
25
25
  addCustomHandler(id: string, executor: CustomActionExecutor): Promise<void>;
26
- getDataForAction<T>(action: DraftAction<T, unknown>): Promise<T | undefined>;
27
26
  getQueueState(): DraftQueueState;
28
27
  startQueue(): Promise<void>;
29
28
  stopQueue(): Promise<void>;
@@ -32,7 +31,7 @@ export declare class DurableDraftQueue implements DraftQueue {
32
31
  */
33
32
  private stopQueueManually;
34
33
  getQueueActions<Data = unknown, Response = unknown>(): Promise<DraftAction<Data, Response>[]>;
35
- enqueue<Data>(handlerId: string, data: unknown): Promise<PendingDraftAction<Data>>;
34
+ enqueue<Data, Response>(handlerId: string, data: unknown): Promise<EnqueueResult<Data, Response>>;
36
35
  registerOnChangedListener(listener: DraftQueueChangeListener): () => Promise<void>;
37
36
  actionCompleted(action: CompletedDraftAction<unknown, unknown>): Promise<void>;
38
37
  actionFailed(action: DraftAction<unknown, unknown>, retry: boolean): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import type { NetworkAdapter, ResourceRequest, Luvio, DurableStoreKeyMetadataMap } from '@luvio/engine';
2
- import type { DraftAction, CompletedDraftAction, QueueOperation, PendingDraftAction, DraftActionMetadata, DraftQueue } from '../DraftQueue';
2
+ import type { DraftAction, CompletedDraftAction, QueueOperation, PendingDraftAction, DraftActionMetadata, DraftQueue, EnqueueResult } from '../DraftQueue';
3
3
  import { ProcessActionResult } from '../DraftQueue';
4
4
  import type { ActionHandler, DraftIdAndKeyMapping, ReplacingActions } from './ActionHandler';
5
5
  export type ResponseIngestionEntry<T = unknown> = {
@@ -15,7 +15,7 @@ export declare abstract class AbstractResourceRequestActionHandler<ResponseType,
15
15
  [key: string]: string;
16
16
  };
17
17
  constructor(draftQueue: DraftQueue, networkAdapter: NetworkAdapter, getLuvio: () => Luvio);
18
- enqueue(data: ResourceRequest): Promise<PendingDraftAction<ResourceRequest>>;
18
+ enqueue(data: ResourceRequest): Promise<EnqueueResult<ResourceRequest, ResponseType>>;
19
19
  handleAction(action: DraftAction<ResourceRequest, ResponseType>, actionCompleted: (action: CompletedDraftAction<ResourceRequest, ResponseType>) => Promise<void>, actionErrored: (action: DraftAction<ResourceRequest, ResponseType>, retry: boolean) => Promise<void>): Promise<ProcessActionResult>;
20
20
  buildPendingAction(request: ResourceRequest, queue: DraftAction<unknown, unknown>[]): Promise<PendingDraftAction<ResourceRequest>>;
21
21
  handleActionEnqueued(action: PendingDraftAction<ResourceRequest>): Promise<void>;
@@ -1,4 +1,4 @@
1
- import type { CompletedDraftAction, DraftAction, DraftActionMetadata, PendingDraftAction, ProcessActionResult, QueueOperation } from '../DraftQueue';
1
+ import type { CompletedDraftAction, DraftAction, DraftActionMetadata, EnqueueResult, PendingDraftAction, ProcessActionResult, QueueOperation } from '../DraftQueue';
2
2
  import type { DraftKeyMapping } from '../DraftIdMapping';
3
3
  export interface ReplacingActions<Response, Data> {
4
4
  original: DraftAction<Response, Data>;
@@ -36,7 +36,7 @@ export interface ActionHandler<Data, DraftMetadata, Type> {
36
36
  * Enqueues an action to the draft queue
37
37
  * @param data the data that will get added to the draft action
38
38
  */
39
- enqueue(data: Data): Promise<PendingDraftAction<Data>>;
39
+ enqueue(data: Data): Promise<EnqueueResult<Data, Type>>;
40
40
  /**
41
41
  * Used to build a PendingDraftAction that is specific to the type of Data and Response.
42
42
  * @param data
package/dist/ldsDrafts.js CHANGED
@@ -191,14 +191,13 @@ const { isArray } = Array;
191
191
  function buildLuvioOverrideForDraftAdapters(luvio, handler, extractTargetIdFromCacheKey, options = {}) {
192
192
  // override this to create and enqueue a new draft action, and return synthetic response
193
193
  const dispatchResourceRequest = async function (resourceRequest, _context) {
194
- const action = await handler.enqueue(resourceRequest).catch((err) => {
194
+ const { data } = await handler.enqueue(resourceRequest).catch((err) => {
195
195
  throw transformErrorToDraftSynthesisError(err);
196
196
  });
197
- const record = await handler.getDataForAction(action);
198
- if (record === undefined) {
197
+ if (data === undefined) {
199
198
  return Promise.reject(createDraftSynthesisErrorResponse());
200
199
  }
201
- return createOkResponse(record);
200
+ return createOkResponse(data);
202
201
  };
203
202
  // override this to use an infinitely large ttl so the cache entry never expires
204
203
  const publishStoreMetadata = function (key, storeMetadataParams) {
@@ -443,10 +442,6 @@ class DurableDraftQueue {
443
442
  const handler = customActionHandler(executor, id, this);
444
443
  return this.addHandler(handler);
445
444
  }
446
- async getDataForAction(action) {
447
- const handler = this.getHandler(action.handler);
448
- return handler.getDataForAction(action);
449
- }
450
445
  getQueueState() {
451
446
  return this.state;
452
447
  }
@@ -539,7 +534,11 @@ class DurableDraftQueue {
539
534
  if (this.state === DraftQueueState.Started) {
540
535
  this.processNextAction();
541
536
  }
542
- return pendingAction;
537
+ const actionData = (await handler.getDataForAction(pendingAction));
538
+ return {
539
+ action: pendingAction,
540
+ data: actionData,
541
+ };
543
542
  });
544
543
  }
545
544
  registerOnChangedListener(listener) {
@@ -1483,7 +1482,9 @@ class DraftManager {
1483
1482
  targetId,
1484
1483
  tag,
1485
1484
  })
1486
- .then(this.buildDraftQueueItem);
1485
+ .then((result) => {
1486
+ return this.buildDraftQueueItem(result.action);
1487
+ });
1487
1488
  }
1488
1489
  /**
1489
1490
  * Get the current state of each of the DraftActions in the DraftQueue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-drafts",
3
- "version": "1.100.4",
3
+ "version": "1.100.5",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS Drafts",
6
6
  "main": "dist/ldsDrafts.js",
@@ -26,6 +26,6 @@
26
26
  "dependencies": {
27
27
  "@luvio/engine": "0.135.4",
28
28
  "@luvio/environments": "0.135.4",
29
- "@salesforce/lds-utils-adapters": "^1.100.4"
29
+ "@salesforce/lds-utils-adapters": "^1.100.5"
30
30
  }
31
31
  }