@salesforce/lds-drafts 1.100.1
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/LICENSE.txt +82 -0
- package/dist/DraftAwareAdapter.d.ts +6 -0
- package/dist/DraftFetchResponse.d.ts +28 -0
- package/dist/DraftIdMapping.d.ts +12 -0
- package/dist/DraftManager.d.ts +161 -0
- package/dist/DraftQueue.d.ts +235 -0
- package/dist/DraftStore.d.ts +12 -0
- package/dist/DraftSynthesisError.d.ts +6 -0
- package/dist/DurableDraftQueue.d.ts +52 -0
- package/dist/DurableDraftStore.d.ts +44 -0
- package/dist/actionHandlers/AbstractResourceRequestActionHandler.d.ts +50 -0
- package/dist/actionHandlers/ActionHandler.d.ts +149 -0
- package/dist/actionHandlers/CustomActionHandler.d.ts +33 -0
- package/dist/ldsDrafts.js +1712 -0
- package/dist/main.d.ts +15 -0
- package/dist/makeEnvironmentDraftAware.d.ts +4 -0
- package/dist/utils/adapter.d.ts +2 -0
- package/dist/utils/clone.d.ts +1 -0
- package/dist/utils/id.d.ts +5 -0
- package/dist/utils/language.d.ts +24 -0
- package/package.json +30 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Terms of Use
|
|
2
|
+
|
|
3
|
+
Copyright 2022 Salesforce, Inc. All rights reserved.
|
|
4
|
+
|
|
5
|
+
These Terms of Use govern the download, installation, and/or use of this
|
|
6
|
+
software provided by Salesforce, Inc. ("Salesforce") (the "Software"), were
|
|
7
|
+
last updated on April 15, 2022, and constitute a legally binding
|
|
8
|
+
agreement between you and Salesforce. If you do not agree to these Terms of
|
|
9
|
+
Use, do not install or use the Software.
|
|
10
|
+
|
|
11
|
+
Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free
|
|
12
|
+
copyright license to reproduce, prepare derivative works of, publicly
|
|
13
|
+
display, publicly perform, sublicense, and distribute the Software and
|
|
14
|
+
derivative works subject to these Terms. These Terms shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
Subject to the limited rights expressly granted hereunder, Salesforce
|
|
18
|
+
reserves all rights, title, and interest in and to all intellectual
|
|
19
|
+
property subsisting in the Software. No rights are granted to you hereunder
|
|
20
|
+
other than as expressly set forth herein. Users residing in countries on
|
|
21
|
+
the United States Office of Foreign Assets Control sanction list, or which
|
|
22
|
+
are otherwise subject to a US export embargo, may not use the Software.
|
|
23
|
+
|
|
24
|
+
Implementation of the Software may require development work, for which you
|
|
25
|
+
are responsible. The Software may contain bugs, errors and
|
|
26
|
+
incompatibilities and is made available on an AS IS basis without support,
|
|
27
|
+
updates, or service level commitments.
|
|
28
|
+
|
|
29
|
+
Salesforce reserves the right at any time to modify, suspend, or
|
|
30
|
+
discontinue, the Software (or any part thereof) with or without notice. You
|
|
31
|
+
agree that Salesforce shall not be liable to you or to any third party for
|
|
32
|
+
any modification, suspension, or discontinuance.
|
|
33
|
+
|
|
34
|
+
You agree to defend Salesforce against any claim, demand, suit or
|
|
35
|
+
proceeding made or brought against Salesforce by a third party arising out
|
|
36
|
+
of or accruing from (a) your use of the Software, and (b) any application
|
|
37
|
+
you develop with the Software that infringes any copyright, trademark,
|
|
38
|
+
trade secret, trade dress, patent, or other intellectual property right of
|
|
39
|
+
any person or defames any person or violates their rights of publicity or
|
|
40
|
+
privacy (each a "Claim Against Salesforce"), and will indemnify Salesforce
|
|
41
|
+
from any damages, attorney fees, and costs finally awarded against
|
|
42
|
+
Salesforce as a result of, or for any amounts paid by Salesforce under a
|
|
43
|
+
settlement approved by you in writing of, a Claim Against Salesforce,
|
|
44
|
+
provided Salesforce (x) promptly gives you written notice of the Claim
|
|
45
|
+
Against Salesforce, (y) gives you sole control of the defense and
|
|
46
|
+
settlement of the Claim Against Salesforce (except that you may not settle
|
|
47
|
+
any Claim Against Salesforce unless it unconditionally releases Salesforce
|
|
48
|
+
of all liability), and (z) gives you all reasonable assistance, at your
|
|
49
|
+
expense.
|
|
50
|
+
|
|
51
|
+
WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT
|
|
52
|
+
SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
53
|
+
IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES,
|
|
54
|
+
INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
|
55
|
+
PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA,
|
|
56
|
+
OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN
|
|
57
|
+
CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU
|
|
58
|
+
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
59
|
+
|
|
60
|
+
These Terms of Use shall be governed exclusively by the internal laws of
|
|
61
|
+
the State of California, without regard to its conflicts of laws
|
|
62
|
+
rules. Each party hereby consents to the exclusive jurisdiction of the
|
|
63
|
+
state and federal courts located in San Francisco County, California to
|
|
64
|
+
adjudicate any dispute arising out of or relating to these Terms of Use and
|
|
65
|
+
the download, installation, and/or use of the Software. Except as expressly
|
|
66
|
+
stated herein, these Terms of Use constitute the entire agreement between
|
|
67
|
+
the parties, and supersede all prior and contemporaneous agreements,
|
|
68
|
+
proposals, or representations, written or oral, concerning their subject
|
|
69
|
+
matter. No modification, amendment, or waiver of any provision of these
|
|
70
|
+
Terms of Use shall be effective unless it is by an update to these Terms of
|
|
71
|
+
Use that Salesforce makes available, or is in writing and signed by the
|
|
72
|
+
party against whom the modification, amendment, or waiver is to be
|
|
73
|
+
asserted.
|
|
74
|
+
|
|
75
|
+
Data Privacy: Salesforce may collect, process, and store device,
|
|
76
|
+
system, and other information related to your use of the Software. This
|
|
77
|
+
information includes, but is not limited to, IP address, user metrics, and
|
|
78
|
+
other data ("Usage Data"). Salesforce may use Usage Data for analytics,
|
|
79
|
+
product development, and marketing purposes. You acknowledge that files
|
|
80
|
+
generated in conjunction with the Software may contain sensitive or
|
|
81
|
+
confidential data, and you are solely responsible for anonymizing and
|
|
82
|
+
protecting such data.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DispatchResourceRequestContext, Luvio, Snapshot } from '@luvio/engine';
|
|
2
|
+
import type { AbstractResourceRequestActionHandler } from './actionHandlers/AbstractResourceRequestActionHandler';
|
|
3
|
+
export type AdapterBuildNetworkSnapshot<Config, Response> = (luvio: Luvio, config: Config, dispatchResourceRequestContext?: DispatchResourceRequestContext) => Promise<Snapshot<Response>>;
|
|
4
|
+
export declare function buildLuvioOverrideForDraftAdapters<ResponseType = unknown, DraftMetadata = unknown>(luvio: Luvio, handler: AbstractResourceRequestActionHandler<ResponseType, DraftMetadata>, extractTargetIdFromCacheKey: (cacheKey: string) => string | undefined, options?: {
|
|
5
|
+
forDeleteAdapter?: boolean;
|
|
6
|
+
}): Luvio;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FetchErrorResponse, FetchResponse, Headers } from '@luvio/engine';
|
|
2
|
+
import { HttpStatusCode } from '@luvio/engine';
|
|
3
|
+
import type { DraftSynthesisErrorType, DraftSynthesisError } from './DraftSynthesisError';
|
|
4
|
+
export declare const DRAFT_ERROR_CODE = "DRAFT_ERROR";
|
|
5
|
+
export declare class DraftFetchResponse<T> implements FetchResponse<T> {
|
|
6
|
+
status: HttpStatusCode;
|
|
7
|
+
body: T;
|
|
8
|
+
headers: Headers;
|
|
9
|
+
constructor(status: HttpStatusCode, body: T);
|
|
10
|
+
get statusText(): string;
|
|
11
|
+
get ok(): boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class DraftErrorFetchResponse implements FetchErrorResponse {
|
|
14
|
+
status: HttpStatusCode;
|
|
15
|
+
body: unknown;
|
|
16
|
+
ok: boolean;
|
|
17
|
+
headers: Headers;
|
|
18
|
+
errorType: 'fetchResponse';
|
|
19
|
+
constructor(status: HttpStatusCode.BadRequest | HttpStatusCode.ServerError | HttpStatusCode.NotFound, body: unknown);
|
|
20
|
+
get statusText(): string;
|
|
21
|
+
}
|
|
22
|
+
export declare function createOkResponse<T>(body: T): DraftFetchResponse<T>;
|
|
23
|
+
export declare function createBadRequestResponse(body: unknown): DraftErrorFetchResponse;
|
|
24
|
+
export declare function createNotFoundResponse(body: unknown): DraftErrorFetchResponse;
|
|
25
|
+
export declare function transformErrorToDraftSynthesisError(error: Error | DraftSynthesisError<unknown>): DraftErrorFetchResponse;
|
|
26
|
+
export declare function createDraftSynthesisErrorResponse(message?: string, errorType?: DraftSynthesisErrorType): DraftErrorFetchResponse;
|
|
27
|
+
export declare function createDeletedResponse(): DraftFetchResponse<void>;
|
|
28
|
+
export declare function createInternalErrorResponse(): DraftErrorFetchResponse;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DurableStore } from '@luvio/environments';
|
|
2
|
+
export interface DraftKeyMapping {
|
|
3
|
+
draftKey: string;
|
|
4
|
+
canonicalKey: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const DRAFT_ID_MAPPINGS_SEGMENT = "DRAFT_ID_MAPPINGS";
|
|
7
|
+
export declare function generateDraftIdMappingKey(draftIdMapping: DraftKeyMapping): string;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param mappingIds (optional) requested mapping ids, if undefined all will be retrieved
|
|
11
|
+
*/
|
|
12
|
+
export declare function getDraftIdMappings(durableStore: DurableStore, mappingIds?: string[]): Promise<DraftKeyMapping[]>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { CustomActionResult } from './actionHandlers/CustomActionHandler';
|
|
2
|
+
import type { DraftActionStatus, DraftQueue, DraftActionMetadata } from './DraftQueue';
|
|
3
|
+
import { DraftQueueState } from './DraftQueue';
|
|
4
|
+
/**
|
|
5
|
+
* Representation of the current state of the draft queue.
|
|
6
|
+
* Includes the overall state as well as a list of draft
|
|
7
|
+
* items that are currently in the queue.
|
|
8
|
+
*/
|
|
9
|
+
export interface DraftManagerState {
|
|
10
|
+
queueState: DraftQueueState;
|
|
11
|
+
items: DraftQueueItem[];
|
|
12
|
+
}
|
|
13
|
+
export type DraftQueueItemMetadata = {
|
|
14
|
+
[key: string]: string;
|
|
15
|
+
};
|
|
16
|
+
export type DraftManagerCustomActionExecutor = (item: DraftQueueItem, completed: (result: CustomActionResult) => void) => void;
|
|
17
|
+
/**
|
|
18
|
+
* An item in the draft queue that loosely maps to
|
|
19
|
+
* a DraftAction
|
|
20
|
+
*/
|
|
21
|
+
export interface DraftQueueItem {
|
|
22
|
+
/** The id of the Draft Action Item */
|
|
23
|
+
id: string;
|
|
24
|
+
/** The unique id of the target item */
|
|
25
|
+
targetId?: string;
|
|
26
|
+
/** The current status of this item */
|
|
27
|
+
state: DraftActionStatus;
|
|
28
|
+
/** The type of operation this item represents */
|
|
29
|
+
operationType: DraftActionOperationType;
|
|
30
|
+
/** Timestamp as unix epoch time */
|
|
31
|
+
timestamp: number;
|
|
32
|
+
/** undefined unless item is in an error state */
|
|
33
|
+
error?: undefined | DraftQueueItemError;
|
|
34
|
+
/** The stored metadata for the draft queue item */
|
|
35
|
+
metadata: DraftQueueItemMetadata;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* An error of a draft action that was submitted and failed
|
|
39
|
+
*/
|
|
40
|
+
export interface DraftQueueItemError {
|
|
41
|
+
/** The status code of the response */
|
|
42
|
+
status: number;
|
|
43
|
+
/** The headers of the response */
|
|
44
|
+
headers: {
|
|
45
|
+
[key: string]: string;
|
|
46
|
+
};
|
|
47
|
+
/** A flag representing the status of the response */
|
|
48
|
+
ok: boolean;
|
|
49
|
+
/** A summary of the response */
|
|
50
|
+
statusText: string;
|
|
51
|
+
/** A stringified object representing the body of the response */
|
|
52
|
+
bodyString: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Denotes what kind of operation a DraftQueueItem represents.
|
|
56
|
+
*/
|
|
57
|
+
export declare enum DraftActionOperationType {
|
|
58
|
+
Create = "create",
|
|
59
|
+
Update = "update",
|
|
60
|
+
Delete = "delete",
|
|
61
|
+
Custom = "custom"
|
|
62
|
+
}
|
|
63
|
+
export declare enum DraftQueueOperationType {
|
|
64
|
+
ItemAdded = "added",
|
|
65
|
+
ItemDeleted = "deleted",
|
|
66
|
+
ItemCompleted = "completed",
|
|
67
|
+
ItemFailed = "failed",
|
|
68
|
+
ItemUpdated = "updated",
|
|
69
|
+
QueueStarted = "started",
|
|
70
|
+
QueueStopped = "stopped"
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A closure that draft queue change listeners pass to
|
|
74
|
+
* receive updates when the draft queue changes.
|
|
75
|
+
*/
|
|
76
|
+
export declare type DraftQueueListener = (state: DraftManagerState, operationType: DraftQueueOperationType, queueItem?: DraftQueueItem) => void;
|
|
77
|
+
export declare class DraftManager {
|
|
78
|
+
private draftQueue;
|
|
79
|
+
private listeners;
|
|
80
|
+
constructor(draftQueue: DraftQueue);
|
|
81
|
+
private shouldEmitDraftEvent;
|
|
82
|
+
private draftQueueEventTypeToOperationType;
|
|
83
|
+
private draftQueueStateToOperationType;
|
|
84
|
+
/**
|
|
85
|
+
* Enqueue a custom action on the DraftQueue for a handler
|
|
86
|
+
* @param handler the handler's id
|
|
87
|
+
* @param targetId
|
|
88
|
+
* @param tag - the key to group with in durable store
|
|
89
|
+
* @param metadata
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
addCustomAction(handler: string, targetId: string, tag: string, metadata: DraftActionMetadata): Promise<DraftQueueItem>;
|
|
93
|
+
/**
|
|
94
|
+
* Get the current state of each of the DraftActions in the DraftQueue
|
|
95
|
+
* @returns A promise of an array of the state of each item in the DraftQueue
|
|
96
|
+
*/
|
|
97
|
+
getQueue(): Promise<DraftManagerState>;
|
|
98
|
+
/**
|
|
99
|
+
* Starts the draft queue and begins processing the first item in the queue.
|
|
100
|
+
*/
|
|
101
|
+
startQueue(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Stops the draft queue from processing more draft items after any current
|
|
104
|
+
* in progress items are finished.
|
|
105
|
+
*/
|
|
106
|
+
stopQueue(): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Subscribes the listener to changes to the draft queue.
|
|
109
|
+
*
|
|
110
|
+
* Returns a closure to invoke in order to unsubscribe the listener
|
|
111
|
+
* from changes to the draft queue.
|
|
112
|
+
*
|
|
113
|
+
* @param listener The listener closure to subscribe to changes
|
|
114
|
+
*/
|
|
115
|
+
registerDraftQueueChangedListener(listener: DraftQueueListener): () => Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Creates a custom action handler for the given handler
|
|
118
|
+
* @param handlerId
|
|
119
|
+
* @param executor
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
setCustomActionExecutor(handlerId: string, executor: DraftManagerCustomActionExecutor): Promise<() => Promise<void>>;
|
|
123
|
+
private buildDraftQueueItem;
|
|
124
|
+
private callListeners;
|
|
125
|
+
/**
|
|
126
|
+
* Removes the draft action identified by actionId from the draft queue.
|
|
127
|
+
*
|
|
128
|
+
* @param actionId The action identifier
|
|
129
|
+
*
|
|
130
|
+
* @returns The current state of the draft queue
|
|
131
|
+
*/
|
|
132
|
+
removeDraftAction(actionId: string): Promise<DraftManagerState>;
|
|
133
|
+
/**
|
|
134
|
+
* Replaces the resource request of `withAction` for the resource request
|
|
135
|
+
* of `actionId`. Action ids cannot be equal. Both actions must be acting
|
|
136
|
+
* on the same target object, and neither can currently be in progress.
|
|
137
|
+
*
|
|
138
|
+
* @param actionId The id of the draft action to replace
|
|
139
|
+
* @param withActionId The id of the draft action that will replace the other
|
|
140
|
+
*/
|
|
141
|
+
replaceAction(actionId: string, withActionId: string): Promise<DraftQueueItem>;
|
|
142
|
+
/**
|
|
143
|
+
* Merges two actions into a single target action. The target action maintains
|
|
144
|
+
* its position in the queue, while the source action is removed from the queue.
|
|
145
|
+
* Action ids cannot be equal. Both actions must be acting on the same target
|
|
146
|
+
* object, and neither can currently be in progress.
|
|
147
|
+
*
|
|
148
|
+
* @param targetActionId The draft action id of the target action. This action
|
|
149
|
+
* will be replaced with the merged result.
|
|
150
|
+
* @param sourceActionId The draft action id to merge onto the target. This
|
|
151
|
+
* action will be removed after the merge.
|
|
152
|
+
*/
|
|
153
|
+
mergeAction(targetActionId: string, sourceActionId: string): Promise<DraftQueueItem>;
|
|
154
|
+
/**
|
|
155
|
+
* Sets the metadata object of the specified action to the
|
|
156
|
+
* provided metadata
|
|
157
|
+
* @param actionId The id of the action to set the metadata on
|
|
158
|
+
* @param metadata The metadata to set on the specified action
|
|
159
|
+
*/
|
|
160
|
+
setMetadata(actionId: string, metadata: DraftQueueItemMetadata): Promise<DraftQueueItem>;
|
|
161
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { FetchResponse } from '@luvio/engine';
|
|
2
|
+
import type { ActionHandler } from './actionHandlers/ActionHandler';
|
|
3
|
+
import type { CustomActionExecutor } from './actionHandlers/CustomActionHandler';
|
|
4
|
+
export declare enum DraftActionStatus {
|
|
5
|
+
Pending = "pending",
|
|
6
|
+
Uploading = "uploading",
|
|
7
|
+
Error = "error",
|
|
8
|
+
Completed = "completed"
|
|
9
|
+
}
|
|
10
|
+
export type DraftActionMetadata = {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
};
|
|
13
|
+
interface BaseDraftAction<Data> {
|
|
14
|
+
status: DraftActionStatus;
|
|
15
|
+
id: string;
|
|
16
|
+
/** Timestamp as unix epoch time */
|
|
17
|
+
timestamp: number;
|
|
18
|
+
metadata: DraftActionMetadata;
|
|
19
|
+
/** typically the cache key */
|
|
20
|
+
targetId: string;
|
|
21
|
+
/** typically the unique record ID */
|
|
22
|
+
tag: string;
|
|
23
|
+
/** the handlerId */
|
|
24
|
+
handler: string;
|
|
25
|
+
/** the data being enqueued */
|
|
26
|
+
data: Data;
|
|
27
|
+
version: '242.0.0';
|
|
28
|
+
}
|
|
29
|
+
export interface CompletedDraftAction<Data, Response> extends BaseDraftAction<Data> {
|
|
30
|
+
status: DraftActionStatus.Completed;
|
|
31
|
+
response: FetchResponse<Response>;
|
|
32
|
+
}
|
|
33
|
+
export interface PendingDraftAction<Data> extends BaseDraftAction<Data> {
|
|
34
|
+
status: DraftActionStatus.Pending;
|
|
35
|
+
}
|
|
36
|
+
export interface ErrorDraftAction<Data> extends BaseDraftAction<Data> {
|
|
37
|
+
status: DraftActionStatus.Error;
|
|
38
|
+
error: any;
|
|
39
|
+
}
|
|
40
|
+
export interface UploadingDraftAction<Data> extends BaseDraftAction<Data> {
|
|
41
|
+
status: DraftActionStatus.Uploading;
|
|
42
|
+
}
|
|
43
|
+
export declare function isDraftCompleted<Data, Response>(draft: BaseDraftAction<Data>): draft is CompletedDraftAction<Data, Response>;
|
|
44
|
+
export declare function isDraftError<Data>(draft: BaseDraftAction<Data>): draft is ErrorDraftAction<Data>;
|
|
45
|
+
export declare function isDraftQueueStateChangeEvent(event: DraftQueueEvent): event is DraftQueueStateChangedEvent;
|
|
46
|
+
export type DraftAction<Data, Response> = CompletedDraftAction<Data, Response> | PendingDraftAction<Data> | ErrorDraftAction<Data> | UploadingDraftAction<Data>;
|
|
47
|
+
export type DraftQueueChangeListener = (event: DraftQueueEvent) => Promise<void>;
|
|
48
|
+
export declare enum ProcessActionResult {
|
|
49
|
+
ACTION_ERRORED = "ERROR",
|
|
50
|
+
ACTION_SUCCEEDED = "SUCCESS",
|
|
51
|
+
NO_ACTION_TO_PROCESS = "NO_ACTION_TO_PROCESS",
|
|
52
|
+
ACTION_ALREADY_PROCESSING = "ACTION_ALREADY_PROCESSING",
|
|
53
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
54
|
+
BLOCKED_ON_ERROR = "BLOCKED_ON_ERROR",
|
|
55
|
+
CUSTOM_ACTION_WAITING = "CUSTOM_ACTION_WAITING"
|
|
56
|
+
}
|
|
57
|
+
export declare enum DraftQueueState {
|
|
58
|
+
/** Currently processing an item in the queue or queue is empty and waiting to process the next item. */
|
|
59
|
+
Started = "started",
|
|
60
|
+
/**
|
|
61
|
+
* The queue is stopped and will not attempt to upload any drafts until startDraftQueue() is called.
|
|
62
|
+
* This is the initial state when the DraftQueue gets instantiated.
|
|
63
|
+
*/
|
|
64
|
+
Stopped = "stopped",
|
|
65
|
+
/**
|
|
66
|
+
* The queue is stopped due to a blocking error from the last upload attempt.
|
|
67
|
+
* The queue will not run again until startDraftQueue() is called.
|
|
68
|
+
*/
|
|
69
|
+
Error = "error",
|
|
70
|
+
/**
|
|
71
|
+
* There was a network error and the queue will attempt to upload again shortly.
|
|
72
|
+
* To attempt to force an upload now call startDraftQueue().
|
|
73
|
+
*/
|
|
74
|
+
Waiting = "waiting"
|
|
75
|
+
}
|
|
76
|
+
export declare enum DraftQueueEventType {
|
|
77
|
+
/**
|
|
78
|
+
* Triggered after an action had been added to the queue
|
|
79
|
+
*/
|
|
80
|
+
ActionAdded = "added",
|
|
81
|
+
/**
|
|
82
|
+
* Triggered once an action failed
|
|
83
|
+
*/
|
|
84
|
+
ActionFailed = "failed",
|
|
85
|
+
/**
|
|
86
|
+
* Triggered after an action has been deleted from the queue
|
|
87
|
+
*/
|
|
88
|
+
ActionDeleted = "deleted",
|
|
89
|
+
/**
|
|
90
|
+
* Triggered after an action has been completed and after it has been removed from the queue
|
|
91
|
+
*/
|
|
92
|
+
ActionCompleted = "completed",
|
|
93
|
+
/**
|
|
94
|
+
* Triggered after an action has been updated by the updateAction API
|
|
95
|
+
*/
|
|
96
|
+
ActionUpdated = "updated",
|
|
97
|
+
/**
|
|
98
|
+
* Triggered after the Draft Queue state changes
|
|
99
|
+
*/
|
|
100
|
+
QueueStateChanged = "state"
|
|
101
|
+
}
|
|
102
|
+
export interface DraftQueueAddEvent {
|
|
103
|
+
type: DraftQueueEventType.ActionAdded;
|
|
104
|
+
action: PendingDraftAction<unknown>;
|
|
105
|
+
}
|
|
106
|
+
export interface DraftQueueDeleteEvent {
|
|
107
|
+
type: DraftQueueEventType.ActionDeleted;
|
|
108
|
+
action: DraftAction<unknown, unknown>;
|
|
109
|
+
}
|
|
110
|
+
export interface DraftQueueCompleteEvent {
|
|
111
|
+
type: DraftQueueEventType.ActionCompleted;
|
|
112
|
+
action: CompletedDraftAction<unknown, unknown>;
|
|
113
|
+
}
|
|
114
|
+
export interface DraftQueueActionFailedEvent {
|
|
115
|
+
type: DraftQueueEventType.ActionFailed;
|
|
116
|
+
action: ErrorDraftAction<unknown>;
|
|
117
|
+
}
|
|
118
|
+
export interface DraftQueueActionUpdatedEvent {
|
|
119
|
+
type: DraftQueueEventType.ActionUpdated;
|
|
120
|
+
action: DraftAction<unknown, unknown>;
|
|
121
|
+
}
|
|
122
|
+
export interface DraftQueueStateChangedEvent {
|
|
123
|
+
type: DraftQueueEventType.QueueStateChanged;
|
|
124
|
+
state: DraftQueueState;
|
|
125
|
+
}
|
|
126
|
+
export type DraftQueueItemEvent = DraftQueueAddEvent | DraftQueueCompleteEvent | DraftQueueDeleteEvent | DraftQueueActionFailedEvent | DraftQueueActionUpdatedEvent;
|
|
127
|
+
export type DraftQueueEvent = DraftQueueStateChangedEvent | DraftQueueItemEvent;
|
|
128
|
+
export declare enum QueueOperationType {
|
|
129
|
+
Add = "add",
|
|
130
|
+
Delete = "delete",
|
|
131
|
+
Update = "update"
|
|
132
|
+
}
|
|
133
|
+
export interface AddQueueOperation {
|
|
134
|
+
type: QueueOperationType.Add;
|
|
135
|
+
action: DraftAction<unknown, unknown>;
|
|
136
|
+
}
|
|
137
|
+
export interface DeleteQueueOperation {
|
|
138
|
+
type: QueueOperationType.Delete;
|
|
139
|
+
id: string;
|
|
140
|
+
}
|
|
141
|
+
export interface UpdateQueueOperation {
|
|
142
|
+
type: QueueOperationType.Update;
|
|
143
|
+
id: string;
|
|
144
|
+
action: DraftAction<unknown, unknown>;
|
|
145
|
+
}
|
|
146
|
+
export type QueueOperation = UpdateQueueOperation | AddQueueOperation | DeleteQueueOperation;
|
|
147
|
+
export interface DraftQueue {
|
|
148
|
+
/**
|
|
149
|
+
* Enqueues a draft action into the DraftQueue
|
|
150
|
+
* @param handlerId the id of the handler associated with the data
|
|
151
|
+
* @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
|
|
153
|
+
* @throws {Error} An error when a proper action handler is not found or conditions are not met to enqueue the action
|
|
154
|
+
*/
|
|
155
|
+
enqueue<Response>(handlerId: string, data: unknown): Promise<PendingDraftAction<Response>>;
|
|
156
|
+
/**
|
|
157
|
+
* add a new handler to the draft queue to process the data in the actions
|
|
158
|
+
* @param id identifier to the handler
|
|
159
|
+
* @param handler ActionHandler to process action
|
|
160
|
+
*/
|
|
161
|
+
addHandler<Data, Type>(handler: ActionHandler<Data, unknown, Type>): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Creates a ActionHandler<CustomActionData> with a callback to let the DraftQueue know when it has been processed
|
|
164
|
+
* @param id identifier of the handler
|
|
165
|
+
* @param executor callback to inform DraftQueue it is complete
|
|
166
|
+
*/
|
|
167
|
+
addCustomHandler(id: string, executor: CustomActionExecutor): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Removes an added ActionHandler
|
|
170
|
+
* @param id identifier of the handler
|
|
171
|
+
*/
|
|
172
|
+
removeHandler(id: string): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Registers a listener to be notified when the Draft Queue changes
|
|
175
|
+
* @param listener Listener to notify when the draft queue changes, with an optional parameter
|
|
176
|
+
* for a completed DraftAction that triggered the change.
|
|
177
|
+
*/
|
|
178
|
+
registerOnChangedListener(listener: DraftQueueChangeListener): () => Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Processes the next action in the draft queue
|
|
181
|
+
*/
|
|
182
|
+
processNextAction(): Promise<ProcessActionResult>;
|
|
183
|
+
/**
|
|
184
|
+
* Get the current list of draft actions in queue
|
|
185
|
+
*/
|
|
186
|
+
getQueueActions(): Promise<DraftAction<unknown, unknown>[]>;
|
|
187
|
+
/** The current state of the DraftQueue */
|
|
188
|
+
getQueueState(): DraftQueueState;
|
|
189
|
+
/**
|
|
190
|
+
* Removes the draft action identified by actionId from the draft queue.
|
|
191
|
+
*
|
|
192
|
+
* @param actionId The action identifier
|
|
193
|
+
*/
|
|
194
|
+
removeDraftAction(actionId: string): Promise<void>;
|
|
195
|
+
/**
|
|
196
|
+
* Replaces the resource request of `withActionId` for the resource request
|
|
197
|
+
* of `actionId`. Action ids cannot be equal. Both actions must be acting
|
|
198
|
+
* on the same target object, and neither can currently be in progress.
|
|
199
|
+
*
|
|
200
|
+
* @param actionId The id of the draft action to replace
|
|
201
|
+
* @param withActionId The id of the draft action that will replace the other
|
|
202
|
+
*/
|
|
203
|
+
replaceAction(actionId: string, withActionId: string): Promise<DraftAction<unknown, unknown>>;
|
|
204
|
+
/**
|
|
205
|
+
* Merges two actions into a single target action. The target action maintains
|
|
206
|
+
* its position in the queue, while the source action is removed from the queue.
|
|
207
|
+
* Action ids cannot be equal. Both actions must be acting on the same target
|
|
208
|
+
* object, and neither can currently be in progress.
|
|
209
|
+
*
|
|
210
|
+
* @param targetActionId The draft action id of the target action. This action
|
|
211
|
+
* will be replaced with the merged result.
|
|
212
|
+
* @param sourceActionId The draft action id to merge onto the target. This
|
|
213
|
+
* action will be removed after the merge.
|
|
214
|
+
*/
|
|
215
|
+
mergeAction<Data, Response>(targetActionId: string, sourceActionId: string): Promise<DraftAction<Data, Response>>;
|
|
216
|
+
/** Set the draft queue state to Started and process the next item */
|
|
217
|
+
startQueue(): Promise<void>;
|
|
218
|
+
/** Set the draft queue state to Stopped and don't let another item begin */
|
|
219
|
+
stopQueue(): Promise<void>;
|
|
220
|
+
/**
|
|
221
|
+
* Sets the metadata object of the specified action to the
|
|
222
|
+
* provided metadata
|
|
223
|
+
*
|
|
224
|
+
* @param actionId The id of the draft action to set metadata on
|
|
225
|
+
* @param metadata The metadata to set on the specified action
|
|
226
|
+
*/
|
|
227
|
+
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
|
+
}
|
|
235
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DraftAction, QueueOperation } from './DraftQueue';
|
|
2
|
+
import type { DraftKeyMapping } from './DraftIdMapping';
|
|
3
|
+
/**
|
|
4
|
+
* Defines the store where drafts are persisted
|
|
5
|
+
*/
|
|
6
|
+
export interface DraftStore {
|
|
7
|
+
writeAction(action: DraftAction<unknown, unknown>): Promise<void>;
|
|
8
|
+
getAllDrafts(): Promise<DraftAction<unknown, unknown>[]>;
|
|
9
|
+
deleteDraft(actionId: string): Promise<void>;
|
|
10
|
+
deleteByTag(tag: string): Promise<void>;
|
|
11
|
+
completeAction(queueOperations: QueueOperation[], mappings: DraftKeyMapping[] | undefined): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type DraftSynthesisErrorType = 'MISSING_ID' | 'OBJECT_INFO_MISSING' | 'REFERENCED_RECORDS_MISSING' | 'UNEXPECTED_FIELDS' | 'RECORD_NOT_CACHED' | 'UNKNOWN';
|
|
2
|
+
export declare class DraftSynthesisError<T> extends Error {
|
|
3
|
+
errorType: T;
|
|
4
|
+
constructor(message: string, errorType: T);
|
|
5
|
+
}
|
|
6
|
+
export declare function isDraftSynthesisError<T>(error: Error): error is DraftSynthesisError<T>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { DraftQueue, DraftAction, CompletedDraftAction, PendingDraftAction, DraftQueueChangeListener, DraftActionMetadata } from './DraftQueue';
|
|
2
|
+
import { ProcessActionResult, DraftQueueState } from './DraftQueue';
|
|
3
|
+
import type { CustomActionExecutor } from './actionHandlers/CustomActionHandler';
|
|
4
|
+
import type { ActionHandler } from './actionHandlers/ActionHandler';
|
|
5
|
+
import type { DraftStore } from './DraftStore';
|
|
6
|
+
export declare const DRAFT_SEGMENT = "DRAFT";
|
|
7
|
+
export declare class DurableDraftQueue implements DraftQueue {
|
|
8
|
+
private retryIntervalMilliseconds;
|
|
9
|
+
private minimumRetryInterval;
|
|
10
|
+
private maximumRetryInterval;
|
|
11
|
+
private draftStore;
|
|
12
|
+
private draftQueueChangedListeners;
|
|
13
|
+
private state;
|
|
14
|
+
private userState;
|
|
15
|
+
private processingAction?;
|
|
16
|
+
private replacingAction?;
|
|
17
|
+
private uploadingActionId?;
|
|
18
|
+
private timeoutHandler;
|
|
19
|
+
private handlers;
|
|
20
|
+
private getHandler;
|
|
21
|
+
constructor(draftStore: DraftStore);
|
|
22
|
+
addHandler<Data>(handler: ActionHandler<Data, unknown, unknown>): Promise<void>;
|
|
23
|
+
removeHandler(id: string): Promise<void>;
|
|
24
|
+
addCustomHandler(id: string, executor: CustomActionExecutor): Promise<void>;
|
|
25
|
+
getDataForAction<T>(action: DraftAction<T, unknown>): Promise<T | undefined>;
|
|
26
|
+
getQueueState(): DraftQueueState;
|
|
27
|
+
startQueue(): Promise<void>;
|
|
28
|
+
stopQueue(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Used to stop the queue within DraftQueue without user interaction
|
|
31
|
+
*/
|
|
32
|
+
private stopQueueManually;
|
|
33
|
+
getQueueActions<Data = unknown, Response = unknown>(): Promise<DraftAction<Data, Response>[]>;
|
|
34
|
+
enqueue<Data>(handlerId: string, data: unknown): Promise<PendingDraftAction<Data>>;
|
|
35
|
+
registerOnChangedListener(listener: DraftQueueChangeListener): () => Promise<void>;
|
|
36
|
+
actionCompleted(action: CompletedDraftAction<unknown, unknown>): Promise<void>;
|
|
37
|
+
actionFailed(action: DraftAction<unknown, unknown>, retry: boolean): Promise<void>;
|
|
38
|
+
handle(action: DraftAction<unknown, unknown>): Promise<ProcessActionResult>;
|
|
39
|
+
processNextAction(): Promise<ProcessActionResult>;
|
|
40
|
+
private handleServerError;
|
|
41
|
+
private notifyChangedListeners;
|
|
42
|
+
/**
|
|
43
|
+
* only starts the queue if user state is "Started" and if queue not already
|
|
44
|
+
* started
|
|
45
|
+
*/
|
|
46
|
+
private startQueueSafe;
|
|
47
|
+
removeDraftAction(actionId: string): Promise<void>;
|
|
48
|
+
replaceAction(actionId: string, withActionId: string): Promise<DraftAction<unknown, unknown>>;
|
|
49
|
+
mergeAction<Data, Response>(targetActionId: string, sourceActionId: string): Promise<DraftAction<Data, Response>>;
|
|
50
|
+
setMetadata(actionId: string, metadata: DraftActionMetadata): Promise<DraftAction<unknown, unknown>>;
|
|
51
|
+
private scheduleRetry;
|
|
52
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { DurableStore } from '@luvio/environments';
|
|
2
|
+
import type { DraftKeyMapping } from './DraftIdMapping';
|
|
3
|
+
import type { DraftAction, QueueOperation } from './DraftQueue';
|
|
4
|
+
import type { DraftStore } from './DraftStore';
|
|
5
|
+
/**
|
|
6
|
+
* Implements a write-through InMemoryStore for Drafts, storing all drafts in a
|
|
7
|
+
* in-memory store with a write through to the DurableStore.
|
|
8
|
+
*
|
|
9
|
+
* Before any reads or writes come in from the draft queue, we need to revive the draft
|
|
10
|
+
* queue into memory. During this initial revive, any writes are queued up and operated on the
|
|
11
|
+
* queue once it's in memory. Similarly any reads are delayed until the queue is in memory.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare class DurableDraftStore implements DraftStore {
|
|
15
|
+
private durableStore;
|
|
16
|
+
private draftStore;
|
|
17
|
+
private syncPromise;
|
|
18
|
+
private writeQueue;
|
|
19
|
+
constructor(durableStore: DurableStore);
|
|
20
|
+
writeAction(action: DraftAction<unknown, unknown>): Promise<void>;
|
|
21
|
+
getAllDrafts<_R, _D>(): Promise<DraftAction<unknown, unknown>[]>;
|
|
22
|
+
deleteDraft(id: string): Promise<void>;
|
|
23
|
+
deleteByTag(tag: string): Promise<void>;
|
|
24
|
+
completeAction(queueOperations: QueueOperation[], mappings: DraftKeyMapping[] | undefined): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Runs a write operation against the draft store, if the initial
|
|
27
|
+
* revive is still in progress, the action gets enqueued to run once the
|
|
28
|
+
* initial revive is complete
|
|
29
|
+
* @param action
|
|
30
|
+
* @returns a promise that is resolved once the action has run
|
|
31
|
+
*/
|
|
32
|
+
private enqueueAction;
|
|
33
|
+
/**
|
|
34
|
+
* Revives the draft store from the durable store. Once the draft store is
|
|
35
|
+
* revived, executes any queued up draft store operations that came in while
|
|
36
|
+
* reviving
|
|
37
|
+
*/
|
|
38
|
+
private resyncDraftStore;
|
|
39
|
+
/**
|
|
40
|
+
* Runs the operations that were queued up while reviving the
|
|
41
|
+
* draft store from the durable store
|
|
42
|
+
*/
|
|
43
|
+
private runQueuedOperations;
|
|
44
|
+
}
|