@salesforce/lds-drafts 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,112 @@
1
+ import type { CompletedDraftAction, DraftAction, DraftActionMetadata, PendingDraftAction, ProcessActionResult, QueueOperation } from '../DraftQueue';
2
+ export interface ReplacingActions<Response, Data> {
3
+ original: DraftAction<Response, Data>;
4
+ actionToReplace: DraftAction<Response, Data>;
5
+ replacingAction: DraftAction<Response, Data>;
6
+ }
7
+ /**
8
+ * A Handler that knows what the Data and Response type expected are in a DraftAction.
9
+ * It knows how to process and set them up.
10
+ *
11
+ * The action handler is registered both with the DraftQueue and the Draft environment to handle
12
+ * all draft application logic to a particular type
13
+ */
14
+ export interface ActionHandler<Data, Type> {
15
+ /**
16
+ * The id for this handler. Every action in the queue will have a handlerId property
17
+ * associated with it which specifies which handler knows how to handle that draft action
18
+ */
19
+ handlerId: string;
20
+ /**
21
+ * Enqueues an action to the draft queue
22
+ * @param data the data that will get added to the draft action
23
+ */
24
+ enqueue(data: Data): Promise<PendingDraftAction<Data>>;
25
+ /**
26
+ * Used to build a PendingDraftAction that is specific to the type of Data and Response.
27
+ * @param data
28
+ * @param queue
29
+ *
30
+ * @throws {Error} if any preconditions to building the draft action are not satisfied
31
+ */
32
+ buildPendingAction(data: unknown, queue: DraftAction<unknown, unknown>[]): Promise<PendingDraftAction<Data>>;
33
+ /**
34
+ * Invoked after an action is enqueued into the draft queue
35
+ * @param action The action that was just enqueued
36
+ * @param queue The queue with the new action now inserted
37
+ */
38
+ handleActionEnqueued(action: PendingDraftAction<Data>, queue: DraftAction<unknown, unknown>[]): Promise<void>;
39
+ /**
40
+ * Invoked by the draft queue when it is this actions turn to execute.
41
+ * @param action: the action that is executing
42
+ * @param actionCompleted callback function when the action completes successfully
43
+ * @param actionErrored callback function invoked when the action errors
44
+ */
45
+ handleAction(action: DraftAction<Data, Type>, actionCompleted: (action: CompletedDraftAction<Data, Type>) => Promise<void>, actionErrored: (action: DraftAction<Data, Type>, retry: boolean, retryDelayInMs?: number, actionDataChanged?: boolean) => Promise<void>): Promise<ProcessActionResult>;
46
+ /**
47
+ * Invoked by the draft queue after an action for this handler is removed from the queue
48
+ * @param action: the removed action
49
+ * @param queue: the queue with the action removed
50
+ */
51
+ handleActionRemoved(action: DraftAction<Data, Type>, queue: DraftAction<unknown, unknown>[]): Promise<void>;
52
+ /**
53
+ * Invoked by the draft queue while an action is completing successfully and returns
54
+ * a set of queue modification operations that should be performed as a result of the
55
+ * action completing
56
+ * @param queue
57
+ * @param action
58
+ */
59
+ getQueueOperationsForCompletingDrafts(queue: DraftAction<unknown, unknown>[], action: CompletedDraftAction<Data, Type>): QueueOperation[];
60
+ /**
61
+ * Invoked by the draft queue after an action completes and is removed from the queue
62
+ * @param action The completed action
63
+ * @param queueOperations The queue modification operations that were executes with the completed action
64
+ */
65
+ handleActionCompleted(action: CompletedDraftAction<Data, Type>, queueOperations: QueueOperation[], allHandlers: ActionHandler<unknown, unknown>[]): Promise<void>;
66
+ /**
67
+ * Replace the targetAction's data with the sourceAction's data and return
68
+ * the targetAction. Also sets the targetAction's status to Pending.
69
+ *
70
+ * NOTE: this method mutates the targetAction.
71
+ *
72
+ * Implementations can assume the caller has already ensured the given draft
73
+ * actions have the same targetId, same tag, same version, and are not currently
74
+ * being uploaded.
75
+ *
76
+ * Replacing draft actions with different targetIds or different tags will result
77
+ * in an error.
78
+ */
79
+ handleReplaceAction(targetAction: DraftAction<Data, Type>, sourceAction: DraftAction<Data, Type>): DraftAction<Data, Type>;
80
+ /**
81
+ * Invoked by the draft queue when a request to remove an action is made. This tells the queue whether it should just
82
+ * delete the requested action or any action with the same tag. This is helpful in examples where other related queue items no longer
83
+ * make sense with this action removed.
84
+ * @param action The action being removed
85
+ */
86
+ shouldDeleteActionByTagOnRemoval(action: DraftAction<Data, Type>): boolean;
87
+ /**
88
+ * Invoked by the draft queue when a request to update an actions metadata is made. This allows the handler to mutate the incoming
89
+ * metadata if necessary
90
+ * @param existingMetadata
91
+ * @param incomingMetadata
92
+ * @returns the metadata that will be persisted
93
+ */
94
+ updateMetadata(existingMetadata: DraftActionMetadata, incomingMetadata: DraftActionMetadata): DraftActionMetadata;
95
+ /**
96
+ * Merges two actions, overlaying the source over the target (ie: the data from
97
+ * both actions will be combined, if there are conflicts the source's data will
98
+ * be used).
99
+ *
100
+ * Implementations can assume the caller has already ensured the given draft
101
+ * actions have the same targetId, same tag, same version, and are not currently
102
+ * being uploaded.
103
+ *
104
+ * NOTE: the resulting merged action will use the target's timestamp and id.
105
+ */
106
+ mergeActions(targetAction: DraftAction<Data, Type>, sourceAction: DraftAction<Data, Type>): DraftAction<Data, Type>;
107
+ /**
108
+ * Invoked when an action is replaced
109
+ * @param action
110
+ */
111
+ handleActionReplaced(target: DraftAction<Data, Type>, source: DraftAction<Data, Type>): Promise<void>;
112
+ }
@@ -0,0 +1,33 @@
1
+ import type { DraftAction, DraftQueue } from '../DraftQueue';
2
+ import type { ActionHandler } from './ActionHandler';
3
+ export declare enum CustomActionResultType {
4
+ SUCCESS = "SUCCESS",
5
+ FAILURE = "FAILURE"
6
+ }
7
+ export declare enum CustomActionErrorType {
8
+ NETWORK_ERROR = "NETWORK_ERROR",
9
+ CLIENT_ERROR = "CLIENT_ERROR"
10
+ }
11
+ export interface CustomActionError {
12
+ type: CustomActionErrorType;
13
+ message: string;
14
+ }
15
+ interface BaseCustomActionResult {
16
+ id: string;
17
+ type: CustomActionResultType;
18
+ }
19
+ export interface CustomActionSuccess extends BaseCustomActionResult {
20
+ type: CustomActionResultType.SUCCESS;
21
+ }
22
+ export interface CustomActionFailed extends BaseCustomActionResult {
23
+ type: CustomActionResultType.FAILURE;
24
+ error: CustomActionError;
25
+ }
26
+ export type CustomActionResult = CustomActionSuccess | CustomActionFailed;
27
+ export type CustomActionExecutor = (action: DraftAction<unknown, unknown>, completed: (result: CustomActionResult) => void) => void;
28
+ export type CustomActionCompletionResponse = (result: CustomActionResult) => void;
29
+ export interface CustomActionData {
30
+ [key: string]: string;
31
+ }
32
+ export declare function customActionHandler(executor: CustomActionExecutor, id: string, draftQueue: DraftQueue): ActionHandler<CustomActionData, unknown>;
33
+ export {};
@@ -0,0 +1,12 @@
1
+ export { DraftQueue, DraftQueueState, DraftAction, ErrorDraftAction, PendingDraftAction, CompletedDraftAction, DraftActionStatus, ProcessActionResult, DraftQueueChangeListener, DraftActionMetadata, DraftQueueEventType, QueueOperation, UpdateQueueOperation, QueueOperationType, type DraftQueueEvent, type DraftQueueActionFailedEvent, } from './DraftQueue';
2
+ export { DurableDraftQueue, DRAFT_SEGMENT } from './DurableDraftQueue';
3
+ export { generateUniqueDraftActionId, uuidv4 } from './utils/id';
4
+ export { DurableDraftStore } from './DurableDraftStore';
5
+ export { DraftStore } from './DraftStore';
6
+ export { DraftManager, DraftManagerState, DraftActionOperationType, DraftQueueItem, DraftQueueItemMetadata, } from './DraftManager';
7
+ export { ActionHandler, ReplacingActions } from './actionHandlers/ActionHandler';
8
+ export type { CustomActionResult } from './actionHandlers/CustomActionHandler';
9
+ export { CustomActionResultType, CustomActionExecutor } from './actionHandlers/CustomActionHandler';
10
+ export * from './DraftFetchResponse';
11
+ export { DraftSynthesisErrorType, DraftSynthesisError, isDraftSynthesisError, } from './DraftSynthesisError';
12
+ export { transformErrorToDraftSynthesisError } from './DraftFetchResponse';
@@ -0,0 +1,2 @@
1
+ import type { Adapter } from '@luvio/engine';
2
+ export declare function getAdapterData<Config, Data>(adapter: Adapter<Config, Data>, config: Config): Promise<Data | undefined>;
@@ -0,0 +1 @@
1
+ export declare function clone<T>(obj: T): T;
@@ -0,0 +1,6 @@
1
+ export { uuidv4 } from '@salesforce/lds-utils-adapters';
2
+ /**
3
+ * Generates a time-ordered, unique id to associate with a DraftAction. Ensures
4
+ * no collisions with existing draft action IDs.
5
+ */
6
+ export declare function generateUniqueDraftActionId(existingIds: string[]): string;
@@ -0,0 +1,24 @@
1
+ declare const keys: {
2
+ (o: object): string[];
3
+ (o: {}): string[];
4
+ }, create: {
5
+ (o: object | null): any;
6
+ (o: object | null, properties: PropertyDescriptorMap & ThisType<any>): any;
7
+ }, assign: {
8
+ <T extends {}, U>(target: T, source: U): T & U;
9
+ <T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
10
+ <T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
11
+ (target: object, ...sources: any[]): any;
12
+ }, values: {
13
+ <T>(o: {
14
+ [s: string]: T;
15
+ } | ArrayLike<T>): T[];
16
+ (o: {}): any[];
17
+ };
18
+ declare const stringify: {
19
+ (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
20
+ (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
21
+ }, parse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any;
22
+ declare const shift: () => any;
23
+ declare const isArray: (arg: any) => arg is any[];
24
+ export { keys as ObjectKeys, create as ObjectCreate, assign as ObjectAssign, values as ObjectValues, stringify as JSONStringify, parse as JSONParse, shift as ArrayPrototypeShift, isArray as ArrayIsArray, };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@salesforce/lds-drafts",
3
+ "version": "0.1.0-dev1",
4
+ "license": "SEE LICENSE IN LICENSE.txt",
5
+ "description": "LDS Drafts",
6
+ "main": "dist/ldsDrafts.js",
7
+ "module": "dist/ldsDrafts.js",
8
+ "types": "dist/types/main.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/types/main.d.ts",
15
+ "import": "./dist/ldsDrafts.js",
16
+ "default": "./dist/ldsDrafts.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "prepare": "yarn build",
21
+ "build": "rollup --bundleConfigAsCjs --config rollup.config.js",
22
+ "clean": "rm -rf dist",
23
+ "test:unit": "NODE_ENV=production jest",
24
+ "release:corejar": "yarn build && ../core-build/scripts/core.js --adapter=lds-drafts"
25
+ },
26
+ "dependencies": {
27
+ "@luvio/engine": "0.158.7",
28
+ "@luvio/environments": "0.158.7",
29
+ "@salesforce/lds-utils-adapters": "^0.1.0-dev1"
30
+ },
31
+ "devDependencies": {
32
+ "@salesforce/nimbus-plugin-lds": "^0.1.0-dev1"
33
+ },
34
+ "volta": {
35
+ "extends": "../../package.json"
36
+ }
37
+ }