@salesforce/lds-drafts 0.131.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.
@@ -0,0 +1,148 @@
1
+ import type { CompletedDraftAction, DraftAction, DraftActionMetadata, EnqueueResult, PendingDraftAction, ProcessActionResult, QueueOperation } from '../DraftQueue';
2
+ import type { DraftKeyMapping } from '../DraftIdMapping';
3
+ export interface ReplacingActions<Response, Data> {
4
+ original: DraftAction<Response, Data>;
5
+ actionToReplace: DraftAction<Response, Data>;
6
+ replacingAction: DraftAction<Response, Data>;
7
+ }
8
+ export interface DraftIdAndKeyMapping extends DraftKeyMapping {
9
+ draftId: string;
10
+ canonicalId: string;
11
+ }
12
+ /**
13
+ * A Handler that knows what the Data and Response type expected are in a DraftAction.
14
+ * It knows how to process and set them up.
15
+ *
16
+ * The action handler is registered both with the DraftQueue and the Draft environment to handle
17
+ * all draft application logic to a particular type
18
+ */
19
+ export interface ActionHandler<Data, DraftMetadata, Type> {
20
+ /**
21
+ * The id for this handler. Every action in the queue will have a handlerId property
22
+ * associated with it which specifies which handler knows how to handle that draft action
23
+ */
24
+ handlerId: string;
25
+ /**
26
+ * Invoked by the draft environment while ingesting incoming data to determine if the handler knows how to apply drafts to the incoming key
27
+ * @param key
28
+ */
29
+ canHandlePublish(key: string): boolean;
30
+ /**
31
+ * Invoked by the draft environment prior to ingesting to determine if the representation type can potentially have draft metadata
32
+ * @param representationName
33
+ */
34
+ canRepresentationContainDraftMetadata(representationName: string): boolean;
35
+ /**
36
+ * Enqueues an action to the draft queue
37
+ * @param data the data that will get added to the draft action
38
+ */
39
+ enqueue(data: Data): Promise<EnqueueResult<Data, Type>>;
40
+ /**
41
+ * Used to build a PendingDraftAction that is specific to the type of Data and Response.
42
+ * @param data
43
+ * @param queue
44
+ *
45
+ * @throws {Error} if any preconditions to building the draft action are not satisfied
46
+ */
47
+ buildPendingAction(data: unknown, queue: DraftAction<unknown, unknown>[]): Promise<PendingDraftAction<Data>>;
48
+ /**
49
+ * Invoked after an action is enqueued into the draft queue
50
+ * @param action The action that was just enqueued
51
+ * @param queue The queue with the new action now inserted
52
+ */
53
+ handleActionEnqueued(action: PendingDraftAction<Data>, queue: DraftAction<unknown, unknown>[]): Promise<void>;
54
+ /**
55
+ * Invoked by the draft queue when it is this actions turn to execute.
56
+ * @param action: the action that is executing
57
+ * @param actionCompleted callback function when the action completes successfully
58
+ * @param actionErrored callback function invoked when the action errors
59
+ */
60
+ handleAction(action: DraftAction<Data, Type>, actionCompleted: (action: CompletedDraftAction<Data, Type>) => Promise<void>, actionErrored: (action: DraftAction<Data, Type>, retry: boolean) => Promise<void>): Promise<ProcessActionResult>;
61
+ /**
62
+ * Invoked by the draft queue after an action for this handler is removed from the queue
63
+ * @param action: the removed action
64
+ * @param queue: the queue with the action removed
65
+ */
66
+ handleActionRemoved(action: DraftAction<Data, Type>, queue: DraftAction<unknown, unknown>[]): Promise<void>;
67
+ /**
68
+ * Invoked by the draft queue while an action is completing successfully and returns
69
+ * a set of queue modification operations that should be performed as a result of the
70
+ * action completing
71
+ * @param queue
72
+ * @param action
73
+ */
74
+ getQueueOperationsForCompletingDrafts(queue: DraftAction<unknown, unknown>[], action: CompletedDraftAction<Data, Type>): QueueOperation[];
75
+ /**
76
+ * Invoked by the draft queue after an action completes and is removed from the queue
77
+ * @param action The completed action
78
+ * @param queueOperations The queue modification operations that were executes with the completed action
79
+ */
80
+ handleActionCompleted(action: CompletedDraftAction<Data, Type>, queueOperations: QueueOperation[], allHandlers: ActionHandler<unknown, unknown, unknown>[]): Promise<void>;
81
+ /**
82
+ * Replace the targetAction's data with the sourceAction's data and return
83
+ * the targetAction. Also sets the targetAction's status to Pending.
84
+ *
85
+ * NOTE: this method mutates the targetAction.
86
+ *
87
+ * Implementations can assume the caller has already ensured the given draft
88
+ * actions have the same targetId, same tag, same version, and are not currently
89
+ * being uploaded.
90
+ *
91
+ * Replacing draft actions with different targetIds or different tags will result
92
+ * in an error.
93
+ */
94
+ handleReplaceAction(targetAction: DraftAction<Data, Type>, sourceAction: DraftAction<Data, Type>): DraftAction<Data, Type>;
95
+ /**
96
+ * Invoked by the durable store and the draft environment to get the data that is associated with this draft action
97
+ * The data should include all drafts applied to it (if any)
98
+ * @param action The action to get data for
99
+ * @param queue The draft queue
100
+ *
101
+ * @returns the data with the up to date draft changes applied. returns undefined if after replaying drafts there is no
102
+ * data to return (i.e. a draft-created record had it's post action removed)
103
+ */
104
+ getDataForAction(action: DraftAction<Data, Type>): Promise<Type | undefined>;
105
+ /**
106
+ * Asynchronous function to fetch any necessary metadata required to apply drafts during ingest
107
+ * Note that since ingest is synchronous any necessary metadata that requires asynchronicity must be fetch prior to ingest commencing
108
+ * @param key
109
+ * @returns the metadata or undefined if there's no drafts associated or no metadata for this key
110
+ */
111
+ getDraftMetadata(key: string): Promise<DraftMetadata | undefined>;
112
+ /**
113
+ * Invoked by the draft environment while ingesting normalized data that may contain drafts.
114
+ * Note that this function is synchronous since ingestion is synchronous (see note in getDraftMetadata)
115
+ * @param key The key being ingested
116
+ * @param data The normalized data being ingested
117
+ * @param draftMetadata The metadata that was previously fetched using getDraftMetadata
118
+ * @param publishFn The environment's publish method to publish the data once drafts have been applied
119
+ */
120
+ applyDraftsToIncomingData(key: string, data: unknown, draftMetadata: DraftMetadata | undefined, publishFn: (key: string, data: any) => void): void;
121
+ /**
122
+ * Invoked by the draft queue when a request to remove an action is made. This tells the queue whether it should just
123
+ * delete the requested action or any action with the same tag. This is helpful in examples where other related queue items no longer
124
+ * make sense with this action removed.
125
+ * @param action The action being removed
126
+ */
127
+ shouldDeleteActionByTagOnRemoval(action: DraftAction<Data, Type>): boolean;
128
+ /**
129
+ * Invoked by the draft queue when a request to update an actions metadata is made. This allows the handler to mutate the incoming
130
+ * metadata if necessary
131
+ * @param existingMetadata
132
+ * @param incomingMetadata
133
+ * @returns the metadata that will be persisted
134
+ */
135
+ updateMetadata(existingMetadata: DraftActionMetadata, incomingMetadata: DraftActionMetadata): DraftActionMetadata;
136
+ /**
137
+ * Merges two actions, overlaying the source over the target (ie: the data from
138
+ * both actions will be combined, if there are conflicts the source's data will
139
+ * be used).
140
+ *
141
+ * Implementations can assume the caller has already ensured the given draft
142
+ * actions have the same targetId, same tag, same version, and are not currently
143
+ * being uploaded.
144
+ *
145
+ * NOTE: the resulting merged action will use the target's timestamp and id.
146
+ */
147
+ mergeActions(targetAction: DraftAction<Data, Type>, sourceAction: DraftAction<Data, Type>): DraftAction<Data, Type>;
148
+ }
@@ -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, unknown>;
33
+ export {};
@@ -0,0 +1,15 @@
1
+ export { DraftQueue, DraftQueueState, DraftAction, ErrorDraftAction, PendingDraftAction, CompletedDraftAction, DraftActionStatus, ProcessActionResult, DraftQueueChangeListener, DraftActionMetadata, DraftQueueEventType, QueueOperation, } from './DraftQueue';
2
+ export { AdapterBuildNetworkSnapshot, buildLuvioOverrideForDraftAdapters, } from './DraftAwareAdapter';
3
+ export { DRAFT_ID_MAPPINGS_SEGMENT, DraftKeyMapping } from './DraftIdMapping';
4
+ export { DurableDraftQueue, DRAFT_SEGMENT } from './DurableDraftQueue';
5
+ export { generateUniqueDraftActionId } from './utils/id';
6
+ export { DurableDraftStore } from './DurableDraftStore';
7
+ export { DraftStore } from './DraftStore';
8
+ export { DraftManager, DraftManagerState, DraftActionOperationType, DraftQueueItem, DraftQueueItemMetadata, } from './DraftManager';
9
+ export { ActionHandler, ReplacingActions, DraftIdAndKeyMapping, } from './actionHandlers/ActionHandler';
10
+ export type { CustomActionResult } from './actionHandlers/CustomActionHandler';
11
+ export { CustomActionResultType, CustomActionExecutor } from './actionHandlers/CustomActionHandler';
12
+ export { AbstractResourceRequestActionHandler, ResponseIngestionEntry, } from './actionHandlers/AbstractResourceRequestActionHandler';
13
+ export { makeEnvironmentDraftAware } from './makeEnvironmentDraftAware';
14
+ export * from './DraftFetchResponse';
15
+ export { DraftSynthesisErrorType, DraftSynthesisError, isDraftSynthesisError, } from './DraftSynthesisError';
@@ -0,0 +1,4 @@
1
+ import type { Luvio, ResourceRequest } from '@luvio/engine';
2
+ import type { DurableEnvironment, DurableStore } from '@luvio/environments';
3
+ import type { ActionHandler, DraftQueue } from './main';
4
+ export declare function makeEnvironmentDraftAware(luvio: Luvio, env: DurableEnvironment, durableStore: DurableStore, handlers: ActionHandler<ResourceRequest, any, any>[], draftQueue: DraftQueue): DurableEnvironment;
@@ -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,5 @@
1
+ /**
2
+ * Generates a time-ordered, unique id to associate with a DraftAction. Ensures
3
+ * no collisions with existing draft action IDs.
4
+ */
5
+ 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,31 @@
1
+ {
2
+ "name": "@salesforce/lds-drafts",
3
+ "version": "0.131.0",
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
+ "import": "./dist/ldsDrafts.js",
15
+ "types": "./dist/types/main.d.ts",
16
+ "default": "./dist/ldsDrafts.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "prepare": "yarn build",
21
+ "build": "rollup --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.138.8-244.1",
28
+ "@luvio/environments": "0.138.8-244.1",
29
+ "@salesforce/lds-utils-adapters": "1.131.0-244.6"
30
+ }
31
+ }