@salesforce/lds-durable-storage 1.421.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 +8 -0
- package/babel.config.js +1 -0
- package/dist/ldsDurableStorage.js +37 -0
- package/dist/types/main.d.ts +32 -0
- package/jest.config.js +7 -0
- package/package.json +19 -0
- package/rollup.config.js +42 -0
- package/src/__tests__/main.spec.ts +104 -0
- package/src/main.ts +56 -0
- package/tsconfig.json +4 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Terms of Use
|
|
2
|
+
|
|
3
|
+
Copyright 2026 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
package/babel.config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../babel.config');
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* ATTENTION!
|
|
9
|
+
* THIS IS A GENERATED FILE FROM https://github.com/salesforce-experience-platform-emu/lds-lightning-platform
|
|
10
|
+
* If you would like to contribute to LDS, please follow the steps outlined in the git repo.
|
|
11
|
+
* Any changes made to this file in p4 will be automatically overwritten.
|
|
12
|
+
* *******************************************************************************************
|
|
13
|
+
*/
|
|
14
|
+
/* proxy-compat-disable */
|
|
15
|
+
function createStorage(config) {
|
|
16
|
+
return getDurableStorageImplementation().createStorage(config);
|
|
17
|
+
}
|
|
18
|
+
function clearStorages() {
|
|
19
|
+
return getDurableStorageImplementation().clearStorages();
|
|
20
|
+
}
|
|
21
|
+
let DurableStorageImplRef;
|
|
22
|
+
function setDurableStorageImplementation(impl) {
|
|
23
|
+
DurableStorageImplRef = impl;
|
|
24
|
+
}
|
|
25
|
+
function getDurableStorageImplementation() {
|
|
26
|
+
if (DurableStorageImplRef) {
|
|
27
|
+
return DurableStorageImplRef;
|
|
28
|
+
}
|
|
29
|
+
// Default no-op implementation to avoid crashes if not set
|
|
30
|
+
return {
|
|
31
|
+
createStorage: () => null,
|
|
32
|
+
clearStorages: () => Promise.resolve([]),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { clearStorages, createStorage, getDurableStorageImplementation, setDurableStorageImplementation };
|
|
37
|
+
// version: 1.421.0-2828c95aef
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface Storage {
|
|
2
|
+
name: string;
|
|
3
|
+
get(key: string): Promise<unknown>;
|
|
4
|
+
getAll(keys?: string[]): Promise<Record<string, unknown>>;
|
|
5
|
+
set(key: string, value: unknown): Promise<void>;
|
|
6
|
+
setAll(values: object): Promise<void>;
|
|
7
|
+
getSize(): Promise<number>;
|
|
8
|
+
clear(): Promise<void>;
|
|
9
|
+
remove(key: string): Promise<unknown>;
|
|
10
|
+
removeAll(keys: string[]): Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface StorageConfig {
|
|
13
|
+
name: string;
|
|
14
|
+
persistent?: boolean;
|
|
15
|
+
secure?: boolean;
|
|
16
|
+
maxSize?: number;
|
|
17
|
+
expiration?: number;
|
|
18
|
+
clearOnInit?: boolean;
|
|
19
|
+
debugLogging?: boolean;
|
|
20
|
+
version?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function createStorage(config: StorageConfig): Storage | null;
|
|
23
|
+
export declare function clearStorages(): Promise<void[]>;
|
|
24
|
+
type DurableStorageCreateFn = (config: any) => unknown | null;
|
|
25
|
+
type DurableStorageClearFn = () => Promise<unknown[]>;
|
|
26
|
+
type DurableStorageImplementation = {
|
|
27
|
+
createStorage: DurableStorageCreateFn;
|
|
28
|
+
clearStorages: DurableStorageClearFn;
|
|
29
|
+
};
|
|
30
|
+
export declare function setDurableStorageImplementation(impl: DurableStorageImplementation): void;
|
|
31
|
+
export declare function getDurableStorageImplementation(): DurableStorageImplementation;
|
|
32
|
+
export {};
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@salesforce/lds-durable-storage",
|
|
3
|
+
"version": "1.421.0",
|
|
4
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
|
+
"description": "LDS Durable Storage",
|
|
6
|
+
"main": "dist/ldsDurableStorage.js",
|
|
7
|
+
"module": "dist/ldsDurableStorage.js",
|
|
8
|
+
"types": "dist/types/main.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"prepare": "yarn build",
|
|
11
|
+
"build": "rollup --bundleConfigAsCjs --config rollup.config.js",
|
|
12
|
+
"clean": "rm -rf dist",
|
|
13
|
+
"test:unit": "jest",
|
|
14
|
+
"test:debug": "node --inspect-brk ../../node_modules/.bin/jest --runInBand"
|
|
15
|
+
},
|
|
16
|
+
"volta": {
|
|
17
|
+
"extends": "../../package.json"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
+
import typescript from '@rollup/plugin-typescript';
|
|
3
|
+
import replace from '@rollup/plugin-replace';
|
|
4
|
+
|
|
5
|
+
import * as packageJson from './package.json';
|
|
6
|
+
import {
|
|
7
|
+
buildBanner,
|
|
8
|
+
buildFooter,
|
|
9
|
+
copyrightHeaderPlugin,
|
|
10
|
+
readGitHash,
|
|
11
|
+
} from '../../scripts/rollup/rollup-utils';
|
|
12
|
+
|
|
13
|
+
const banner = buildBanner(true);
|
|
14
|
+
const footer = buildFooter(packageJson.version);
|
|
15
|
+
const hash = readGitHash();
|
|
16
|
+
|
|
17
|
+
const ldsDurableStorage = {
|
|
18
|
+
input: './src/main.ts',
|
|
19
|
+
|
|
20
|
+
external: [],
|
|
21
|
+
|
|
22
|
+
output: {
|
|
23
|
+
file: 'dist/ldsDurableStorage.js',
|
|
24
|
+
format: 'esm',
|
|
25
|
+
banner,
|
|
26
|
+
footer,
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
plugins: [
|
|
30
|
+
copyrightHeaderPlugin,
|
|
31
|
+
resolve(),
|
|
32
|
+
typescript({
|
|
33
|
+
declarationDir: 'types',
|
|
34
|
+
}),
|
|
35
|
+
replace({
|
|
36
|
+
'process.env.VERSION': JSON.stringify(hash),
|
|
37
|
+
preventAssignment: true,
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default [ldsDurableStorage];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
beforeEach(() => {
|
|
2
|
+
jest.resetModules();
|
|
3
|
+
});
|
|
4
|
+
|
|
5
|
+
describe('@salesforce/lds-durable-storage', () => {
|
|
6
|
+
describe('getDurableStorageImplementation', () => {
|
|
7
|
+
it('returns an implementation with createStorage and clearStorages', () => {
|
|
8
|
+
const { getDurableStorageImplementation } = require('../main');
|
|
9
|
+
const impl = getDurableStorageImplementation();
|
|
10
|
+
expect(impl).toHaveProperty('createStorage');
|
|
11
|
+
expect(impl).toHaveProperty('clearStorages');
|
|
12
|
+
expect(typeof impl.createStorage).toBe('function');
|
|
13
|
+
expect(typeof impl.clearStorages).toBe('function');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('returns default no-op when no custom implementation is set', () => {
|
|
17
|
+
const { getDurableStorageImplementation } = require('../main');
|
|
18
|
+
const impl = getDurableStorageImplementation();
|
|
19
|
+
expect(impl.createStorage({})).toBeNull();
|
|
20
|
+
return expect(impl.clearStorages()).resolves.toEqual([]);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('setDurableStorageImplementation', () => {
|
|
25
|
+
it('replaces the implementation returned by getDurableStorageImplementation', () => {
|
|
26
|
+
const {
|
|
27
|
+
setDurableStorageImplementation,
|
|
28
|
+
getDurableStorageImplementation,
|
|
29
|
+
} = require('../main');
|
|
30
|
+
const customCreateStorage = jest.fn().mockReturnValue({ storage: true });
|
|
31
|
+
const customClearStorages = jest.fn().mockResolvedValue([]);
|
|
32
|
+
setDurableStorageImplementation({
|
|
33
|
+
createStorage: customCreateStorage,
|
|
34
|
+
clearStorages: customClearStorages,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const impl = getDurableStorageImplementation();
|
|
38
|
+
expect(impl.createStorage).toBe(customCreateStorage);
|
|
39
|
+
expect(impl.clearStorages).toBe(customClearStorages);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('createStorage', () => {
|
|
44
|
+
it('delegates to the current implementation and returns its result', () => {
|
|
45
|
+
const { createStorage, setDurableStorageImplementation } = require('../main');
|
|
46
|
+
const mockStorage = { get: jest.fn(), set: jest.fn() };
|
|
47
|
+
const createStorageImpl = jest.fn().mockReturnValue(mockStorage);
|
|
48
|
+
setDurableStorageImplementation({
|
|
49
|
+
createStorage: createStorageImpl,
|
|
50
|
+
clearStorages: () => Promise.resolve([]),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const config = { name: 'test', maxSize: 1024 };
|
|
54
|
+
const result = createStorage(config);
|
|
55
|
+
|
|
56
|
+
expect(createStorageImpl).toHaveBeenCalledWith(config);
|
|
57
|
+
expect(result).toBe(mockStorage);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('returns undefined when implementation returns undefined', () => {
|
|
61
|
+
const { createStorage, setDurableStorageImplementation } = require('../main');
|
|
62
|
+
setDurableStorageImplementation({
|
|
63
|
+
createStorage: () => undefined,
|
|
64
|
+
clearStorages: () => Promise.resolve([]),
|
|
65
|
+
});
|
|
66
|
+
const result = createStorage({});
|
|
67
|
+
expect(result).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('clearStorages', () => {
|
|
72
|
+
it('delegates to the current implementation and returns its promise', async () => {
|
|
73
|
+
const { clearStorages, setDurableStorageImplementation } = require('../main');
|
|
74
|
+
const resolvedValues = [undefined, undefined];
|
|
75
|
+
const clearStoragesImpl = jest.fn().mockResolvedValue(resolvedValues);
|
|
76
|
+
setDurableStorageImplementation({
|
|
77
|
+
createStorage: () => null,
|
|
78
|
+
clearStorages: clearStoragesImpl,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const result = await clearStorages();
|
|
82
|
+
|
|
83
|
+
expect(clearStoragesImpl).toHaveBeenCalled();
|
|
84
|
+
expect(result).toEqual(resolvedValues);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('returns resolved empty array when using default no-op implementation', async () => {
|
|
88
|
+
const { clearStorages } = require('../main');
|
|
89
|
+
const result = await clearStorages();
|
|
90
|
+
expect(result).toEqual([]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('propagates rejection from implementation', async () => {
|
|
94
|
+
const { clearStorages, setDurableStorageImplementation } = require('../main');
|
|
95
|
+
const error = new Error('clear failed');
|
|
96
|
+
setDurableStorageImplementation({
|
|
97
|
+
createStorage: () => null,
|
|
98
|
+
clearStorages: () => Promise.reject(error),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await expect(clearStorages()).rejects.toThrow('clear failed');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Public API delegates to shared utilities
|
|
2
|
+
export interface Storage {
|
|
3
|
+
name: string;
|
|
4
|
+
get(key: string): Promise<unknown>;
|
|
5
|
+
getAll(keys?: string[]): Promise<Record<string, unknown>>;
|
|
6
|
+
set(key: string, value: unknown): Promise<void>;
|
|
7
|
+
setAll(values: object): Promise<void>;
|
|
8
|
+
getSize(): Promise<number>;
|
|
9
|
+
clear(): Promise<void>;
|
|
10
|
+
remove(key: string): Promise<unknown>;
|
|
11
|
+
removeAll(keys: string[]): Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface StorageConfig {
|
|
15
|
+
name: string;
|
|
16
|
+
persistent?: boolean;
|
|
17
|
+
secure?: boolean;
|
|
18
|
+
maxSize?: number;
|
|
19
|
+
expiration?: number;
|
|
20
|
+
clearOnInit?: boolean;
|
|
21
|
+
debugLogging?: boolean;
|
|
22
|
+
version?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createStorage(config: StorageConfig): Storage | null {
|
|
26
|
+
return getDurableStorageImplementation().createStorage(config) as Storage | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function clearStorages(): Promise<void[]> {
|
|
30
|
+
return getDurableStorageImplementation().clearStorages() as Promise<void[]>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Durable Storage implementation registry
|
|
34
|
+
type DurableStorageCreateFn = (config: any) => unknown | null;
|
|
35
|
+
type DurableStorageClearFn = () => Promise<unknown[]>;
|
|
36
|
+
type DurableStorageImplementation = {
|
|
37
|
+
createStorage: DurableStorageCreateFn;
|
|
38
|
+
clearStorages: DurableStorageClearFn;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let DurableStorageImplRef: DurableStorageImplementation | undefined;
|
|
42
|
+
|
|
43
|
+
export function setDurableStorageImplementation(impl: DurableStorageImplementation): void {
|
|
44
|
+
DurableStorageImplRef = impl;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getDurableStorageImplementation(): DurableStorageImplementation {
|
|
48
|
+
if (DurableStorageImplRef) {
|
|
49
|
+
return DurableStorageImplRef;
|
|
50
|
+
}
|
|
51
|
+
// Default no-op implementation to avoid crashes if not set
|
|
52
|
+
return {
|
|
53
|
+
createStorage: () => null,
|
|
54
|
+
clearStorages: () => Promise.resolve([]),
|
|
55
|
+
};
|
|
56
|
+
}
|
package/tsconfig.json
ADDED