@salesforce/nimbus-plugin-lds 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.
- package/LICENSE.txt +82 -0
- package/Readme.md +11 -0
- package/dist/index.js +361 -0
- package/dist/mocks/index.js +43 -0
- package/dist/types/BinaryStorePlugin.d.ts +82 -0
- package/dist/types/DraftQueue.d.ts +22 -0
- package/dist/types/InspectorPlugin.d.ts +8 -0
- package/dist/types/JsSqliteStorePlugin/JsSqliteStorePlugin.d.ts +23 -0
- package/dist/types/JsSqliteStorePlugin/JsSqliteStorePluginBase.d.ts +17 -0
- package/dist/types/JsSqliteStorePlugin/JsWorkerSqliteStorePlugin.d.ts +12 -0
- package/dist/types/JsSqliteStorePlugin/JsWorkerSqliteStorePlugin.worker.d.ts +24 -0
- package/dist/types/JsSqliteStorePlugin/PluginFunctions.d.ts +9 -0
- package/dist/types/NetworkAdapter.d.ts +89 -0
- package/dist/types/SqliteStorePlugin.d.ts +152 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/mocks/MockNimbusNetworkAdapter.d.ts +10 -0
- package/dist/types/mocks/index.d.ts +1 -0
- package/package.json +40 -0
- package/sql/240000.sql +70 -0
- package/sql/244000.sql +23 -0
- package/sql/Readme.md +15 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*eslint-env es2020 */
|
|
2
|
+
class MockNimbusNetworkAdapter {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.mockResponses = [];
|
|
5
|
+
this.sentRequests = [];
|
|
6
|
+
}
|
|
7
|
+
setMockResponse(mockResponse) {
|
|
8
|
+
this.mockResponses = [mockResponse];
|
|
9
|
+
}
|
|
10
|
+
setMockResponses(mockResponses) {
|
|
11
|
+
this.mockResponses = mockResponses;
|
|
12
|
+
}
|
|
13
|
+
sendRequest(request, onResponse, onError) {
|
|
14
|
+
this.sentRequests.push(request);
|
|
15
|
+
const mockResponse = this.mockResponses.shift();
|
|
16
|
+
// invoke callbacks on async tick to align with how real implementation works
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
if (mockResponse === undefined) {
|
|
19
|
+
onError({ type: 'unspecified', message: 'response not set' });
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
onResponse(mockResponse);
|
|
23
|
+
}
|
|
24
|
+
}, 0);
|
|
25
|
+
return Promise.resolve('mocked cancel token');
|
|
26
|
+
}
|
|
27
|
+
cancelRequest(_token) {
|
|
28
|
+
throw Error('Method not implemented.');
|
|
29
|
+
}
|
|
30
|
+
setAsGlobalNimbusPlugin() {
|
|
31
|
+
var _a;
|
|
32
|
+
globalThis.__nimbus = {
|
|
33
|
+
...(globalThis.__nimbus || {}),
|
|
34
|
+
plugins: {
|
|
35
|
+
// eslint-disable-next-line @salesforce/lds/no-optional-chaining
|
|
36
|
+
...(((_a = globalThis.__nimbus) === null || _a === void 0 ? void 0 : _a.plugins) || {}),
|
|
37
|
+
LdsNetworkAdapter: this,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { MockNimbusNetworkAdapter };
|
|
@@ -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 {};
|
|
@@ -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';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NetworkAdapter, NetworkError, Request, Response } from '../NetworkAdapter';
|
|
2
|
+
export declare class MockNimbusNetworkAdapter implements NetworkAdapter {
|
|
3
|
+
private mockResponses;
|
|
4
|
+
sentRequests: Request[];
|
|
5
|
+
setMockResponse(mockResponse: Response): void;
|
|
6
|
+
setMockResponses(mockResponses: Response[]): void;
|
|
7
|
+
sendRequest(request: Request, onResponse: (response: Response) => void, onError: (error: NetworkError) => void): Promise<string>;
|
|
8
|
+
cancelRequest(_token: string): void;
|
|
9
|
+
setAsGlobalNimbusPlugin(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MockNimbusNetworkAdapter } from './MockNimbusNetworkAdapter';
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@salesforce/nimbus-plugin-lds",
|
|
3
|
+
"version": "0.131.0",
|
|
4
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
|
+
"description": "Nimbus plugins for LDS on Mobile native integrations: durable store, networking, and draft queue.",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"sql"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/types/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./mocks": {
|
|
20
|
+
"types": "./dist/types/index.d.ts",
|
|
21
|
+
"import": "./dist/mocks/index.js",
|
|
22
|
+
"default": "./dist/mocks/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"prepare": "yarn build",
|
|
27
|
+
"clean": "rm -rf dist",
|
|
28
|
+
"build": "rollup --config rollup.config.js",
|
|
29
|
+
"test:unit": "NODE_ENV=production jest"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@rollup/plugin-wasm": "^5.2.0",
|
|
33
|
+
"@salesforce/lds-store-sql": "1.131.0-244.6",
|
|
34
|
+
"@types/sql.js": "1.4.4",
|
|
35
|
+
"nimbus-types": "^2.0.0-alpha1",
|
|
36
|
+
"rollup-plugin-string": "^3.0.0",
|
|
37
|
+
"rollup-plugin-web-worker-loader": "^1.6.1",
|
|
38
|
+
"sql.js": "^1.7.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/sql/240000.sql
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
-- The primary table for data in the DEFAULT segment
|
|
2
|
+
CREATE TABLE lds_data (
|
|
3
|
+
key TEXT PRIMARY KEY,
|
|
4
|
+
data TEXT NOT NULL,
|
|
5
|
+
metadata JSON
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
-- The primary table for data in segments other than DEFAULT
|
|
9
|
+
-- and which do not have a dedicated table
|
|
10
|
+
CREATE TABLE lds_internal (
|
|
11
|
+
namespace TEXT NOT NULL,
|
|
12
|
+
key TEXT NOT NULL,
|
|
13
|
+
data TEXT NOT NULL,
|
|
14
|
+
metadata JSON,
|
|
15
|
+
PRIMARY KEY (namespace, key)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
-- The table for draft actions created by the draft-aware mobile environment
|
|
19
|
+
CREATE TABLE lds_env_drafts (
|
|
20
|
+
key TEXT PRIMARY KEY,
|
|
21
|
+
data TEXT NOT NULL
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
-- The table for draft local to server id mappings
|
|
25
|
+
CREATE TABLE lds_env_draft_id_map (
|
|
26
|
+
key TEXT PRIMARY KEY,
|
|
27
|
+
data TEXT NOT NULL
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
CREATE INDEX idx_lds_data_uiapi_record_id
|
|
31
|
+
ON lds_data (json_extract(data, '$.id'))
|
|
32
|
+
WHERE
|
|
33
|
+
key LIKE 'UiApi::RecordRepresentation:%'
|
|
34
|
+
AND json_extract(data, '$.id') IS NOT NULL;
|
|
35
|
+
|
|
36
|
+
CREATE INDEX idx_lds_data_uiapi_record_apiname
|
|
37
|
+
ON lds_data (json_extract(data, '$.apiName'))
|
|
38
|
+
WHERE
|
|
39
|
+
key LIKE 'UiApi::RecordRepresentation:%'
|
|
40
|
+
AND json_extract(data, '$.apiName') IS NOT NULL;
|
|
41
|
+
|
|
42
|
+
CREATE INDEX idx_lds_data_uiapi_objectinfo_apiname
|
|
43
|
+
ON lds_data (json_extract(data, '$.apiName'))
|
|
44
|
+
WHERE
|
|
45
|
+
key LIKE 'UiApi::ObjectInfoRepresentation:%'
|
|
46
|
+
AND json_extract(data, '$.apiName') IS NOT NULL;
|
|
47
|
+
|
|
48
|
+
CREATE INDEX idx_lds_data_uiapi_objectinfo_keyprefix
|
|
49
|
+
ON lds_data (json_extract(data, '$.keyPrefix'))
|
|
50
|
+
WHERE
|
|
51
|
+
key LIKE 'UiApi::ObjectInfoRepresentation:%'
|
|
52
|
+
AND json_extract(data, '$.keyPrefix') IS NOT NULL;
|
|
53
|
+
|
|
54
|
+
CREATE INDEX idx_lds_data_uiapi_serviceresource_relatedrecordid
|
|
55
|
+
ON lds_data (json_extract(data, '$.fields.RelatedRecordId.value'))
|
|
56
|
+
WHERE
|
|
57
|
+
key LIKE 'UiApi::ObjectInfoRepresentation:%'
|
|
58
|
+
AND json_extract(data, '$.apiName') = 'ServiceResource';
|
|
59
|
+
|
|
60
|
+
CREATE INDEX idx_lds_data_uiapi_assigned_resource_service_appointment_id
|
|
61
|
+
ON lds_data(json_extract(data, '$.fields.ServiceAppointmentId.value'))
|
|
62
|
+
WHERE
|
|
63
|
+
key LIKE 'UiApi::ObjectInfoRepresentation:%'
|
|
64
|
+
AND json_extract(data, '$.apiName') = 'AssignedResource';
|
|
65
|
+
|
|
66
|
+
CREATE INDEX idx_lds_data_uiapi_assigned_resource_service_resource_id
|
|
67
|
+
ON lds_data(json_extract(data, '$.fields.ServiceResourceId.value'))
|
|
68
|
+
WHERE
|
|
69
|
+
key LIKE 'UiApi::ObjectInfoRepresentation:%'
|
|
70
|
+
AND json_extract(data, '$.apiName') = 'AssignedResource';
|
package/sql/244000.sql
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
DROP INDEX If EXISTS idx_lds_data_uiapi_serviceresource_relatedrecordid;
|
|
2
|
+
|
|
3
|
+
DROP INDEX If EXISTS idx_lds_data_uiapi_assigned_resource_service_appointment_id;
|
|
4
|
+
|
|
5
|
+
DROP INDEX If EXISTS idx_lds_data_uiapi_assigned_resource_service_resource_id;
|
|
6
|
+
|
|
7
|
+
CREATE INDEX If NOT EXISTS idx_lds_data_uiapi_serviceresource_relatedrecordid
|
|
8
|
+
ON lds_data (json_extract(data, '$.fields.RelatedRecordId.value'))
|
|
9
|
+
WHERE
|
|
10
|
+
key LIKE 'UiApi::RecordRepresentation:%'
|
|
11
|
+
AND json_extract(data, '$.apiName') = 'ServiceResource';
|
|
12
|
+
|
|
13
|
+
CREATE INDEX If NOT EXISTS idx_lds_data_uiapi_assignedresource_serviceappointmentid
|
|
14
|
+
ON lds_data(json_extract(data, '$.fields.ServiceAppointmentId.value'))
|
|
15
|
+
WHERE
|
|
16
|
+
key LIKE 'UiApi::RecordRepresentation:%'
|
|
17
|
+
AND json_extract(data, '$.apiName') = 'AssignedResource';
|
|
18
|
+
|
|
19
|
+
CREATE INDEX If NOT EXISTS idx_lds_data_uiapi_assignedresource_serviceresourceid
|
|
20
|
+
ON lds_data(json_extract(data, '$.fields.ServiceResourceId.value'))
|
|
21
|
+
WHERE
|
|
22
|
+
key LIKE 'UiApi::RecordRepresentation:%'
|
|
23
|
+
AND json_extract(data, '$.apiName') = 'AssignedResource';
|
package/sql/Readme.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
This folder holds the schema migrations for the LDS SqliteStore implementation.
|
|
2
|
+
|
|
3
|
+
Each migration file should use the following naming convention:
|
|
4
|
+
|
|
5
|
+
`<core release number><incrementing version number padded to three digits>`
|
|
6
|
+
|
|
7
|
+
e.g. `240000` -> `240001` -> `240002` -> `242000` -> `242001` and so on.
|
|
8
|
+
|
|
9
|
+
This easily lets us see in which core release schema changes were made. It's unlikely we
|
|
10
|
+
will make >1000 schema changes in any given core release.
|
|
11
|
+
|
|
12
|
+
An application should read its current schema version and execute any migration
|
|
13
|
+
scripts newer than the current version during initialization in numerically sorted
|
|
14
|
+
order. It should then set its schema version to the filename of the newest migration
|
|
15
|
+
file. In Sqlite this is typically done using `PRAGMA user_version = <the version>`.
|