@salesforce/nimbus-plugin-lds 1.100.2
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/Readme.md +11 -0
- package/dist/BinaryStorePlugin.d.ts +82 -0
- package/dist/DraftQueue.d.ts +22 -0
- package/dist/InspectorPlugin.d.ts +8 -0
- package/dist/JsSqliteStorePlugin/JsSqliteStorePlugin.d.ts +23 -0
- package/dist/JsSqliteStorePlugin/JsSqliteStorePluginBase.d.ts +17 -0
- package/dist/JsSqliteStorePlugin/JsWorkerSqliteStorePlugin.d.ts +12 -0
- package/dist/JsSqliteStorePlugin/JsWorkerSqliteStorePlugin.worker.d.ts +24 -0
- package/dist/JsSqliteStorePlugin/PluginFunctions.d.ts +9 -0
- package/dist/NetworkAdapter.d.ts +89 -0
- package/dist/SqliteStorePlugin.d.ts +152 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +358 -0
- package/package.json +35 -0
- package/sql/240000.sql +70 -0
- package/sql/Readme.md +15 -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.
|
package/Readme.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
declare module 'nimbus-types' {
|
|
2
|
+
interface NimbusPlugins {
|
|
3
|
+
LdsBinaryStorePlugin: BinaryStorePlugin;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A nimbus plugin for interacting with a binary file store.
|
|
8
|
+
*
|
|
9
|
+
* The implementation can be used as a "store" where the file in the store is the only
|
|
10
|
+
* copy and there is essentially no expiration (the file is never stale). Or it can be
|
|
11
|
+
* used as a "cache" where the canonical copy of the file exists somewhere else (like
|
|
12
|
+
* on a remote server).
|
|
13
|
+
*
|
|
14
|
+
* The caching behavior should follow the "stale-while-revalidate" pattern, where
|
|
15
|
+
* a cached file (which has a non-null expiration and a canonical URI) should always
|
|
16
|
+
* return the cached version, and if the file is past expiration (ie: "stale") then
|
|
17
|
+
* the implementation should attempt to re-downloaded the file from the canonical
|
|
18
|
+
* URI in the background.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export interface BinaryStorePlugin {
|
|
22
|
+
/**
|
|
23
|
+
* Stores a binary file in the store. The file will not have a TTL. This is
|
|
24
|
+
* meant to store local-only files.
|
|
25
|
+
*
|
|
26
|
+
* @param data The data of the binary file to put into the store.
|
|
27
|
+
* @param type The MIME type of the binary file. Ex: "image/png".
|
|
28
|
+
* @param size The number of bytes of data contained within the file.
|
|
29
|
+
* @param onSuccess Callback to call with the string representing the URI of
|
|
30
|
+
* the binary file.
|
|
31
|
+
* @param onError Callback to call if there was an error.
|
|
32
|
+
*/
|
|
33
|
+
storeBinary(data: Uint8Array, type: string, size: number, onSuccess: (uri: string) => void, onError: (errorMessage: string) => void): void;
|
|
34
|
+
/**
|
|
35
|
+
* Caches a binary file in the store. This is meant to locally cache a file
|
|
36
|
+
* thats source-of-truth exists at the given URL.
|
|
37
|
+
*
|
|
38
|
+
* If the file is unable to be downloaded the onError callback will be called.
|
|
39
|
+
*
|
|
40
|
+
* This method should return a URI to the file, which may or may not be the
|
|
41
|
+
* same as the remote URL. In other words, the URI returned to callers should
|
|
42
|
+
* be treated as opaque by the callers.
|
|
43
|
+
*
|
|
44
|
+
* @param url The URL of the file.
|
|
45
|
+
* @param ttlSeconds The TTL in seconds for this file. The file's expiration
|
|
46
|
+
* should be calculated by Date.now + ttlSeconds.
|
|
47
|
+
* @param onSuccess Callback to call with the string representing the URI of
|
|
48
|
+
* the binary file.
|
|
49
|
+
* @param onError Callback to call if there was an error.
|
|
50
|
+
*/
|
|
51
|
+
cacheBinary(url: string, ttlSeconds: number, onSuccess: (uri: string) => void, onError: (errorMessage: string) => void): void;
|
|
52
|
+
/**
|
|
53
|
+
* Removes the binary file given its URI.
|
|
54
|
+
*
|
|
55
|
+
* @param uri The URI of the binary file
|
|
56
|
+
* @param onSuccess Callback to be called once finished. The wasFound
|
|
57
|
+
* parameter will be true if the file existed and has been removed, or
|
|
58
|
+
* false if the file does not exist.
|
|
59
|
+
* @param onError Callback to call if there was an unexpected error.
|
|
60
|
+
*/
|
|
61
|
+
removeBinary(uri: string, onSuccess: (wasFound: boolean) => void, onError: (errorMessage: string) => void): void;
|
|
62
|
+
/**
|
|
63
|
+
* Set the canonical URL for the file at the given uri. The file will immediately
|
|
64
|
+
* be marked as stale (since we know the file's source of truth has changed).
|
|
65
|
+
*
|
|
66
|
+
* If there is no file at the given URI then this method will immediately cache
|
|
67
|
+
* the file at the canonicalUrl (essentially the same as calling {@link cacheBinary}).
|
|
68
|
+
*
|
|
69
|
+
* This method should return a URI to the file, which may or may not be
|
|
70
|
+
* different from the original URI, and may or may not be the same as the
|
|
71
|
+
* canonicalUrl.
|
|
72
|
+
*
|
|
73
|
+
* @param uri The URI of the existing, local binary file
|
|
74
|
+
* @param canonicalUrl The new, canonical URL (a URL is a type of URI) of the file
|
|
75
|
+
* @param ttlSeconds The TTL in seconds for this file. The file's expiration
|
|
76
|
+
* should be calculated by Date.now + ttlSeconds.
|
|
77
|
+
* @param onSuccess Callback to call with the string representing the new URI
|
|
78
|
+
* to the file, which may or may not be the same as canonicalUrl.
|
|
79
|
+
* @param onError Callback to call if there was an error.
|
|
80
|
+
*/
|
|
81
|
+
setCanonicalUrl(uri: string, canonicalUrl: string, ttlSeconds: number, onSuccess: (uri: string) => void, onError: (errorMessage: string) => void): void;
|
|
82
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare module 'nimbus-types' {
|
|
2
|
+
interface NimbusPlugins {
|
|
3
|
+
LdsDraftQueue: DraftQueue;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Defines the DraftQueue that allows LDS running in the webview to interact with the
|
|
8
|
+
* DraftQueue instance running in JSCore. Since the method parameters are opaque
|
|
9
|
+
* to the native container everything passed into the nimbus plugin is serialized
|
|
10
|
+
* and the jscore-side of the plugin implementation will perform the
|
|
11
|
+
* serialization/deserialization of the parameters
|
|
12
|
+
*/
|
|
13
|
+
export interface DraftQueue {
|
|
14
|
+
/**
|
|
15
|
+
* A generic proxy method to invoke various methods on the draft queue
|
|
16
|
+
* @param methodName The name of the proxy method to invoke
|
|
17
|
+
* @param serializedArgsArray A serialized array of arguments
|
|
18
|
+
* @param resultCallback Success callback containing serialized result
|
|
19
|
+
* @param errorCallback Error callback containing serialized error
|
|
20
|
+
*/
|
|
21
|
+
callProxyMethod(methodName: string, serializedArgsArray: string, resultCallback: (serializedResult: string) => void, errorCallback: (serializedError: string) => void): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SqliteType, SqliteResult } from '@salesforce/lds-store-sql';
|
|
2
|
+
import type { Database } from 'sql.js';
|
|
3
|
+
import type { SqliteOperation, SqliteStorePlugin } from '../SqliteStorePlugin';
|
|
4
|
+
import { JsSqliteStorePluginBase } from './JsSqliteStorePluginBase';
|
|
5
|
+
type DatabaseFactory = () => Promise<Database>;
|
|
6
|
+
/**
|
|
7
|
+
* A class that implements the {@link SqliteStorePlugin} interface based on
|
|
8
|
+
* sql.js (https://sql.js.org/)
|
|
9
|
+
*/
|
|
10
|
+
export declare class JsSqliteStorePlugin extends JsSqliteStorePluginBase implements SqliteStorePlugin {
|
|
11
|
+
private db;
|
|
12
|
+
private readonly dbFactory;
|
|
13
|
+
/**
|
|
14
|
+
* @param factory A factory that returns a Promise to a sql.js Database object
|
|
15
|
+
*/
|
|
16
|
+
constructor(factory: DatabaseFactory);
|
|
17
|
+
private factoryPromise;
|
|
18
|
+
private getDatabase;
|
|
19
|
+
resetDatabase(): void;
|
|
20
|
+
query(sql: string, params: SqliteType[], onResult: (result: SqliteResult) => void, onError: (message: string) => void): Promise<void>;
|
|
21
|
+
batchOperations(operations: SqliteOperation[], onCompletion: (error: string | null) => void): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SqliteType, SqliteResult } from '@salesforce/lds-store-sql';
|
|
2
|
+
import type { SqliteOperation, SqliteStoreChange, SqliteStorePlugin } from '../SqliteStorePlugin';
|
|
3
|
+
type ListenerMap = Map<string, (changes: SqliteStoreChange[]) => void>;
|
|
4
|
+
export declare abstract class JsSqliteStorePluginBase implements SqliteStorePlugin {
|
|
5
|
+
private listenerCounter;
|
|
6
|
+
protected listeners: ListenerMap;
|
|
7
|
+
abstract query(sql: string, params: SqliteType[], onResult: (result: SqliteResult) => void, onError: (message: string) => void): Promise<void>;
|
|
8
|
+
abstract batchOperations(operations: SqliteOperation[], onCompletion: (error: string | null) => void): Promise<void>;
|
|
9
|
+
registerOnChangedListener(listener: (changes: SqliteStoreChange[]) => void): Promise<string>;
|
|
10
|
+
unsubscribeOnChangedListener(id: string): Promise<void>;
|
|
11
|
+
protected notifyListeners(operations: SqliteOperation[]): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* This function takes an unknown error and normalizes it to an Error object
|
|
15
|
+
*/
|
|
16
|
+
export declare function normalizeError(error: unknown): Error;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SqliteType, SqliteResult } from '@salesforce/lds-store-sql';
|
|
2
|
+
import { JsSqliteStorePluginBase } from './JsSqliteStorePluginBase';
|
|
3
|
+
import type { SqliteOperation, SqliteStorePlugin } from '../SqliteStorePlugin';
|
|
4
|
+
export declare class JsSqliteStoreWebWorkerPlugin extends JsSqliteStorePluginBase implements SqliteStorePlugin {
|
|
5
|
+
private callbackId;
|
|
6
|
+
private readonly queryCallbackMap;
|
|
7
|
+
private readonly batchCallbackMap;
|
|
8
|
+
private readonly worker;
|
|
9
|
+
constructor();
|
|
10
|
+
query(sql: string, params: SqliteType[], onResult: (result: SqliteResult) => void, onError: (message: string) => void): Promise<void>;
|
|
11
|
+
batchOperations(operations: SqliteOperation[], onCompletion: (error: string | null) => void): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { SqliteType } from '@salesforce/lds-store-sql';
|
|
2
|
+
import type { SqliteOperation } from '../SqliteStorePlugin';
|
|
3
|
+
export type QueryRequest = {
|
|
4
|
+
functionName: 'query';
|
|
5
|
+
sql: string;
|
|
6
|
+
params: SqliteType[];
|
|
7
|
+
callbackId: number;
|
|
8
|
+
};
|
|
9
|
+
export type BatchOperationsRequest = {
|
|
10
|
+
functionName: 'batchOperations';
|
|
11
|
+
operations: SqliteOperation[];
|
|
12
|
+
callbackId: number;
|
|
13
|
+
};
|
|
14
|
+
export type Response<T, E = Error> = {
|
|
15
|
+
callbackId: number;
|
|
16
|
+
functionName: 'query' | 'batchOperations';
|
|
17
|
+
result: T;
|
|
18
|
+
error: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
callbackId: number;
|
|
21
|
+
functionName: 'query' | 'batchOperations';
|
|
22
|
+
result: undefined;
|
|
23
|
+
error: E;
|
|
24
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SqliteType, SqliteResult } from '@salesforce/lds-store-sql';
|
|
2
|
+
import type { Database } from 'sql.js';
|
|
3
|
+
import type { SqliteOperation } from '../SqliteStorePlugin';
|
|
4
|
+
export declare function query(database: Database, sql: string, params: SqliteType[], onResult: (result: SqliteResult) => void, onError: (message: string) => void): void;
|
|
5
|
+
/**
|
|
6
|
+
* Performs the operations on the DB. NOTE: this function does not do anything
|
|
7
|
+
* with notifying change listeners. Callers need to handle that.
|
|
8
|
+
*/
|
|
9
|
+
export declare function batchOperations(database: Database, operations: SqliteOperation[]): void;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
declare module 'nimbus-types' {
|
|
2
|
+
interface NimbusPlugins {
|
|
3
|
+
LdsNetworkAdapter: NetworkAdapter;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* ObservabilityContext helps us trace the path of a request
|
|
8
|
+
* through the Native and JS layers
|
|
9
|
+
*/
|
|
10
|
+
export interface ObservabilityContext {
|
|
11
|
+
/**
|
|
12
|
+
* Uniquely identify a root activity like Priming, Navigation etc
|
|
13
|
+
* Multiple adapter calls can be tied to one root activity
|
|
14
|
+
*
|
|
15
|
+
* Optional
|
|
16
|
+
*/
|
|
17
|
+
rootId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Should we transmit the activity from the client side
|
|
20
|
+
*
|
|
21
|
+
* Required if rootId is provided.
|
|
22
|
+
*/
|
|
23
|
+
isRootActivitySampled?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Uniquely identifies each adapter call
|
|
26
|
+
*
|
|
27
|
+
* Optional
|
|
28
|
+
*/
|
|
29
|
+
traceId?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A `NetworkError` represents a type of transient request error and an associated message
|
|
33
|
+
* if one is available.
|
|
34
|
+
*/
|
|
35
|
+
export interface NetworkError {
|
|
36
|
+
type: 'timeout' | 'unspecified';
|
|
37
|
+
message: string | null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A `NetworkAdapter` is capable of handling `Request`s and generating `Response`s.
|
|
41
|
+
*/
|
|
42
|
+
export interface NetworkAdapter {
|
|
43
|
+
/**
|
|
44
|
+
* Send the request, returning a token that can be used to cancel the request.
|
|
45
|
+
*
|
|
46
|
+
* @param request the request to handle
|
|
47
|
+
* @param onResponse called when a Response is received
|
|
48
|
+
* @param onError called when there is an error handling the `Request`. The `error`
|
|
49
|
+
* is a NetworkError describing what caused the error.
|
|
50
|
+
* @returns {Promise<string>} A promise resolving to a token for this request
|
|
51
|
+
*/
|
|
52
|
+
sendRequest(request: Request, onResponse: (response: Response) => void, onError: (error: NetworkError) => void): Promise<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Attempt to cancel a request associated with the specified token.
|
|
55
|
+
*
|
|
56
|
+
* @param token a token returned from `sendRequest`
|
|
57
|
+
* @returns {void}
|
|
58
|
+
*/
|
|
59
|
+
cancelRequest(token: string): void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* An HTTP request
|
|
63
|
+
*/
|
|
64
|
+
export interface Request {
|
|
65
|
+
method: 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE';
|
|
66
|
+
priority: 'background' | 'normal' | 'high';
|
|
67
|
+
path: string;
|
|
68
|
+
headers: {
|
|
69
|
+
[key: string]: string;
|
|
70
|
+
};
|
|
71
|
+
queryParams: {
|
|
72
|
+
[key: string]: string;
|
|
73
|
+
};
|
|
74
|
+
body: string | null;
|
|
75
|
+
observabilityContext: ObservabilityContext | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* An HTTP response
|
|
79
|
+
*/
|
|
80
|
+
export interface Response {
|
|
81
|
+
status: number;
|
|
82
|
+
headers: {
|
|
83
|
+
[key: string]: string;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* A string-encoded object or null.
|
|
87
|
+
*/
|
|
88
|
+
body: string | null;
|
|
89
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
declare module 'nimbus-types' {
|
|
2
|
+
interface NimbusPlugins {
|
|
3
|
+
LdsSqliteStore: SqliteStorePlugin;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
import type { SqliteResult, SqliteType } from '@salesforce/lds-store-sql';
|
|
7
|
+
/**
|
|
8
|
+
* A plugin interface that is backed by a sqlite database and
|
|
9
|
+
* used by a `SqliteStore`.
|
|
10
|
+
*/
|
|
11
|
+
export interface SqliteStorePlugin {
|
|
12
|
+
/**
|
|
13
|
+
* @see SqliteStore.query
|
|
14
|
+
*/
|
|
15
|
+
query(sql: string, params: SqliteType[], onResult: (result: SqliteResult) => void, onError: (message: string) => void): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Perform a set of operations on the underlying database.
|
|
18
|
+
*/
|
|
19
|
+
batchOperations(operations: SqliteOperation[], onCompletion: (error: string | null) => void): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Setup a listener to be notified of changes to the Durable Store
|
|
22
|
+
*
|
|
23
|
+
* @param listener callback taking an array of store changes
|
|
24
|
+
* @returns {Promise<string>} a generated id of the listener to unsubscribe with
|
|
25
|
+
*/
|
|
26
|
+
registerOnChangedListener(listener: (changes: SqliteStoreChange[]) => void): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param id the identifier given from registerOnChangedListener
|
|
30
|
+
*/
|
|
31
|
+
unsubscribeOnChangedListener(id: string): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* An operation to perform on the database.
|
|
35
|
+
*/
|
|
36
|
+
interface SqliteOperationBase {
|
|
37
|
+
table: 'lds_data' | 'lds_internal' | 'lds_env_drafts' | 'lds_env_draft_id_map';
|
|
38
|
+
keyColumn: string;
|
|
39
|
+
context: SqliteOperationContext;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* An upsert attempts to insert rows into the database. If
|
|
43
|
+
* there is a primary key or unique constraint violation it
|
|
44
|
+
* can attempt to update the existing rows.
|
|
45
|
+
*
|
|
46
|
+
* ex:
|
|
47
|
+
* ```javascript
|
|
48
|
+
* let operation = {
|
|
49
|
+
* type: "upsert",
|
|
50
|
+
* table: "luvio_internal",
|
|
51
|
+
* columns: ["key", "namespace", "data", "metadata"],
|
|
52
|
+
* keyColumn: "key",
|
|
53
|
+
* conflictColumns: ["key", "namespace"],
|
|
54
|
+
* rows: [
|
|
55
|
+
* ["001002003004005001", "ADAPTER_CONTEXT", "{'a': 1, 'b': 2}", "{}"],
|
|
56
|
+
* ["001002003004005002", "ADAPTER_CONTEXT", "{'a': 3, 'b': 5}", "{}"]
|
|
57
|
+
* ],
|
|
58
|
+
* context: {
|
|
59
|
+
* segment: "ADAPTER_CONTEXT"
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* ```sql
|
|
65
|
+
* insert into luvio_internal (key, namespace, data, metadata)
|
|
66
|
+
* values (?, ?, ?, ?)
|
|
67
|
+
* on conflict (key, namespace) do
|
|
68
|
+
* update set value = excluded.value, metada = excluded.metadata
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
interface SqliteUpsert extends SqliteOperationBase {
|
|
72
|
+
type: 'upsert';
|
|
73
|
+
conflictColumns: string[];
|
|
74
|
+
columns: string[];
|
|
75
|
+
rows: SqliteType[][];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Delete rows from the database.
|
|
79
|
+
*
|
|
80
|
+
* ex:
|
|
81
|
+
* ```javascript
|
|
82
|
+
* let operation = {
|
|
83
|
+
* type: "delete",
|
|
84
|
+
* table: "luvio_data",
|
|
85
|
+
* keyColumn: "key",
|
|
86
|
+
* ids: ["001002003004005001", "001002003004005002"],
|
|
87
|
+
* context: {
|
|
88
|
+
* segment: "DEFAULT"
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* ```sql
|
|
94
|
+
* delete from luvio_data where key in ("001002003004005001", "001002003004005002")
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
interface SqliteDelete extends SqliteOperationBase {
|
|
98
|
+
type: 'delete';
|
|
99
|
+
ids: string[];
|
|
100
|
+
}
|
|
101
|
+
export type SqliteOperation = SqliteDelete | SqliteUpsert;
|
|
102
|
+
export declare function isUpsertOperation(operation: SqliteOperation): operation is SqliteUpsert;
|
|
103
|
+
/**
|
|
104
|
+
* Operations can pass any context object along with the operation.
|
|
105
|
+
* This context is opaque to the plugin and will be included in any
|
|
106
|
+
* change notifications generated from the operation.
|
|
107
|
+
*/
|
|
108
|
+
export type SqliteOperationContext = {
|
|
109
|
+
[s: string]: SqliteType;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* A change from the underlying sqlite database triggered by executing a set of operations.
|
|
113
|
+
*
|
|
114
|
+
* Example:
|
|
115
|
+
*
|
|
116
|
+
* The following operation:
|
|
117
|
+
*
|
|
118
|
+
* ```javascript
|
|
119
|
+
* let operation = {
|
|
120
|
+
* type: "delete",
|
|
121
|
+
* table: "luvio_data",
|
|
122
|
+
* keyColumn: "key",
|
|
123
|
+
* ids: ["001", "002"],
|
|
124
|
+
* context: {
|
|
125
|
+
* segment: "DEFAULT"
|
|
126
|
+
* }
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* should trigger the following change:
|
|
131
|
+
* ```javascript
|
|
132
|
+
* {
|
|
133
|
+
* type: "delete",
|
|
134
|
+
* table: "luvio_data",
|
|
135
|
+
* keys: ["001", "002"],
|
|
136
|
+
* context: {
|
|
137
|
+
* segment: "DEFAULT"
|
|
138
|
+
* }
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export interface SqliteStoreChange {
|
|
143
|
+
type: SqliteOperation['type'];
|
|
144
|
+
table: string;
|
|
145
|
+
keys: SqliteType[];
|
|
146
|
+
context: SqliteOperationContext;
|
|
147
|
+
}
|
|
148
|
+
export declare const sortedSchemaMigrations: Array<{
|
|
149
|
+
version: number;
|
|
150
|
+
sql: string;
|
|
151
|
+
}>;
|
|
152
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as NimbusTypes from 'nimbus-types';
|
|
2
|
+
export type { NimbusTypes };
|
|
3
|
+
export type { NetworkAdapter, Request, Response, NetworkError, ObservabilityContext, } from './NetworkAdapter';
|
|
4
|
+
export type { DraftQueue } from './DraftQueue';
|
|
5
|
+
export type { SqliteStorePlugin, SqliteOperation } from './SqliteStorePlugin';
|
|
6
|
+
export type { BinaryStorePlugin } from './BinaryStorePlugin';
|
|
7
|
+
export type { InspectorPlugin } from './InspectorPlugin';
|
|
8
|
+
export { sortedSchemaMigrations, isUpsertOperation } from './SqliteStorePlugin';
|
|
9
|
+
export { JsSqliteStorePlugin } from './JsSqliteStorePlugin/JsSqliteStorePlugin';
|
|
10
|
+
export { JsSqliteStoreWebWorkerPlugin } from './JsSqliteStorePlugin/JsWorkerSqliteStorePlugin';
|