react-native-onyx 2.0.12 → 2.0.14
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/dist/Logger.d.ts +12 -7
- package/dist/Logger.js +1 -7
- package/dist/Str.d.ts +7 -8
- package/dist/Str.js +5 -18
- package/dist/createDeferredTask.d.ts +6 -7
- package/dist/createDeferredTask.js +0 -3
- package/dist/storage/__mocks__/index.js +1 -0
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.js +81 -20
- package/dist/storage/providers/IDBKeyValProvider.js +4 -0
- package/dist/storage/providers/NoopProvider.d.ts +3 -0
- package/dist/storage/providers/NoopProvider.js +89 -0
- package/dist/storage/providers/SQLiteProvider.js +4 -0
- package/dist/storage/providers/types.d.ts +5 -1
- package/package.json +1 -1
- package/dist/SyncQueue.d.ts +0 -32
- package/dist/SyncQueue.js +0 -57
- package/dist/compose.d.ts +0 -19
- package/dist/compose.js +0 -31
package/dist/Logger.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
type LogData = {
|
|
2
2
|
message: string;
|
|
3
3
|
level: 'alert' | 'info';
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
type LoggerCallback = (data: LogData) => void;
|
|
6
6
|
/**
|
|
7
7
|
* Register the logging callback
|
|
8
|
-
*
|
|
9
|
-
* @param callback
|
|
10
8
|
*/
|
|
11
|
-
declare function registerLogger(callback:
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
declare function registerLogger(callback: LoggerCallback): void;
|
|
10
|
+
/**
|
|
11
|
+
* Send an alert message to the logger
|
|
12
|
+
*/
|
|
13
|
+
declare function logAlert(message: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Send an info message to the logger
|
|
16
|
+
*/
|
|
17
|
+
declare function logInfo(message: string): void;
|
|
18
|
+
export { registerLogger, logInfo, logAlert };
|
package/dist/Logger.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.logAlert = exports.logInfo = exports.registerLogger = void 0;
|
|
4
|
-
//
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
5
5
|
let logger = () => { };
|
|
6
6
|
/**
|
|
7
7
|
* Register the logging callback
|
|
8
|
-
*
|
|
9
|
-
* @param {Function} callback
|
|
10
8
|
*/
|
|
11
9
|
function registerLogger(callback) {
|
|
12
10
|
logger = callback;
|
|
@@ -14,8 +12,6 @@ function registerLogger(callback) {
|
|
|
14
12
|
exports.registerLogger = registerLogger;
|
|
15
13
|
/**
|
|
16
14
|
* Send an alert message to the logger
|
|
17
|
-
*
|
|
18
|
-
* @param {String} message
|
|
19
15
|
*/
|
|
20
16
|
function logAlert(message) {
|
|
21
17
|
logger({ message: `[Onyx] ${message}`, level: 'alert' });
|
|
@@ -23,8 +19,6 @@ function logAlert(message) {
|
|
|
23
19
|
exports.logAlert = logAlert;
|
|
24
20
|
/**
|
|
25
21
|
* Send an info message to the logger
|
|
26
|
-
*
|
|
27
|
-
* @param {String} message
|
|
28
22
|
*/
|
|
29
23
|
function logInfo(message) {
|
|
30
24
|
logger({ message: `[Onyx] ${message}`, level: 'info' });
|
package/dist/Str.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns true if the haystack begins with the needle
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
6
|
-
* @return
|
|
4
|
+
* @param haystack The full string to be searched
|
|
5
|
+
* @param needle The case-sensitive string to search for
|
|
6
|
+
* @return Returns true if the haystack starts with the needle.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
declare function startsWith(haystack: string, needle: string): boolean;
|
|
9
9
|
/**
|
|
10
10
|
* Checks if parameter is a string or function.
|
|
11
11
|
* If it is a string, then we will just return it.
|
|
12
12
|
* If it is a function, then we will call it with
|
|
13
13
|
* any additional arguments and return the result.
|
|
14
|
-
*
|
|
15
|
-
* @param {String|Function} parameter
|
|
16
|
-
* @returns {*}
|
|
17
14
|
*/
|
|
18
|
-
|
|
15
|
+
declare function result(parameter: string): string;
|
|
16
|
+
declare function result<TFunction extends (...a: TArgs) => unknown, TArgs extends unknown[]>(parameter: TFunction, ...args: TArgs): ReturnType<TFunction>;
|
|
17
|
+
export { startsWith, result };
|
package/dist/Str.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.result = exports.startsWith = void 0;
|
|
7
|
-
const underscore_1 = __importDefault(require("underscore"));
|
|
8
4
|
/**
|
|
9
5
|
* Returns true if the haystack begins with the needle
|
|
10
6
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @return
|
|
7
|
+
* @param haystack The full string to be searched
|
|
8
|
+
* @param needle The case-sensitive string to search for
|
|
9
|
+
* @return Returns true if the haystack starts with the needle.
|
|
14
10
|
*/
|
|
15
11
|
function startsWith(haystack, needle) {
|
|
16
|
-
return
|
|
12
|
+
return typeof haystack === 'string' && typeof needle === 'string' && haystack.startsWith(needle);
|
|
17
13
|
}
|
|
18
14
|
exports.startsWith = startsWith;
|
|
19
|
-
/**
|
|
20
|
-
* Checks if parameter is a string or function.
|
|
21
|
-
* If it is a string, then we will just return it.
|
|
22
|
-
* If it is a function, then we will call it with
|
|
23
|
-
* any additional arguments and return the result.
|
|
24
|
-
*
|
|
25
|
-
* @param {String|Function} parameter
|
|
26
|
-
* @returns {*}
|
|
27
|
-
*/
|
|
28
15
|
function result(parameter, ...args) {
|
|
29
|
-
return
|
|
16
|
+
return typeof parameter === 'function' ? parameter(...args) : parameter;
|
|
30
17
|
}
|
|
31
18
|
exports.result = result;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
type DeferredTask = {
|
|
2
|
+
promise: Promise<void>;
|
|
3
|
+
resolve?: () => void;
|
|
4
|
+
};
|
|
1
5
|
/**
|
|
2
6
|
* Create a deferred task that can be resolved when we call `resolve()`
|
|
3
7
|
* The returned promise will complete when we call `resolve`
|
|
4
8
|
* Useful when we want to wait for a tasks that is resolved from an external action
|
|
5
|
-
*
|
|
6
|
-
* @template T
|
|
7
|
-
* @returns {{ resolve: function(*), promise: Promise<T|void> }}
|
|
8
9
|
*/
|
|
9
|
-
export default function createDeferredTask
|
|
10
|
-
|
|
11
|
-
promise: Promise<void | T>;
|
|
12
|
-
};
|
|
10
|
+
export default function createDeferredTask(): DeferredTask;
|
|
11
|
+
export {};
|
|
@@ -4,9 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
* Create a deferred task that can be resolved when we call `resolve()`
|
|
5
5
|
* The returned promise will complete when we call `resolve`
|
|
6
6
|
* Useful when we want to wait for a tasks that is resolved from an external action
|
|
7
|
-
*
|
|
8
|
-
* @template T
|
|
9
|
-
* @returns {{ resolve: function(*), promise: Promise<T|void> }}
|
|
10
7
|
*/
|
|
11
8
|
function createDeferredTask() {
|
|
12
9
|
const deferred = {};
|
package/dist/storage/index.d.ts
CHANGED
package/dist/storage/index.js
CHANGED
|
@@ -1,12 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const Logger = __importStar(require("../Logger"));
|
|
6
30
|
const platforms_1 = __importDefault(require("./platforms"));
|
|
7
31
|
const InstanceSync_1 = __importDefault(require("./InstanceSync"));
|
|
8
|
-
const
|
|
32
|
+
const NoopProvider_1 = __importDefault(require("./providers/NoopProvider"));
|
|
33
|
+
let provider = platforms_1.default;
|
|
9
34
|
let shouldKeepInstancesSync = false;
|
|
35
|
+
let finishInitalization;
|
|
36
|
+
const initPromise = new Promise((resolve) => {
|
|
37
|
+
finishInitalization = resolve;
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Degrade performance by removing the storage provider and only using cache
|
|
41
|
+
*/
|
|
42
|
+
function degradePerformance(error) {
|
|
43
|
+
Logger.logAlert(`Error while using ${provider.name}. Falling back to only using cache and dropping storage.`);
|
|
44
|
+
console.error(error);
|
|
45
|
+
provider = NoopProvider_1.default;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Runs a piece of code and degrades performance if certain errors are thrown
|
|
49
|
+
*/
|
|
50
|
+
function tryOrDegradePerformance(fn) {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
initPromise.then(() => {
|
|
53
|
+
try {
|
|
54
|
+
resolve(fn());
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
// Test for known critical errors that the storage provider throws, e.g. when storage is full
|
|
58
|
+
if (error instanceof Error) {
|
|
59
|
+
// IndexedDB error when storage is full (https://github.com/Expensify/App/issues/29403)
|
|
60
|
+
if (error.message.includes('Internal error opening backing store for indexedDB.open')) {
|
|
61
|
+
degradePerformance(error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
reject(error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
10
69
|
const Storage = {
|
|
11
70
|
/**
|
|
12
71
|
* Returns the storage provider currently in use
|
|
@@ -19,90 +78,92 @@ const Storage = {
|
|
|
19
78
|
* and enables fallback providers if necessary
|
|
20
79
|
*/
|
|
21
80
|
init() {
|
|
22
|
-
provider.init()
|
|
81
|
+
tryOrDegradePerformance(provider.init).finally(() => {
|
|
82
|
+
finishInitalization();
|
|
83
|
+
});
|
|
23
84
|
},
|
|
24
85
|
/**
|
|
25
86
|
* Get the value of a given key or return `null` if it's not available
|
|
26
87
|
*/
|
|
27
|
-
getItem: (key) => provider.getItem(key),
|
|
88
|
+
getItem: (key) => tryOrDegradePerformance(() => provider.getItem(key)),
|
|
28
89
|
/**
|
|
29
90
|
* Get multiple key-value pairs for the give array of keys in a batch
|
|
30
91
|
*/
|
|
31
|
-
multiGet: (keys) => provider.multiGet(keys),
|
|
92
|
+
multiGet: (keys) => tryOrDegradePerformance(() => provider.multiGet(keys)),
|
|
32
93
|
/**
|
|
33
94
|
* Sets the value for a given key. The only requirement is that the value should be serializable to JSON string
|
|
34
95
|
*/
|
|
35
|
-
setItem: (key, value) => {
|
|
96
|
+
setItem: (key, value) => tryOrDegradePerformance(() => {
|
|
36
97
|
const promise = provider.setItem(key, value);
|
|
37
98
|
if (shouldKeepInstancesSync) {
|
|
38
99
|
return promise.then(() => InstanceSync_1.default.setItem(key));
|
|
39
100
|
}
|
|
40
101
|
return promise;
|
|
41
|
-
},
|
|
102
|
+
}),
|
|
42
103
|
/**
|
|
43
104
|
* Stores multiple key-value pairs in a batch
|
|
44
105
|
*/
|
|
45
|
-
multiSet: (pairs) => provider.multiSet(pairs),
|
|
106
|
+
multiSet: (pairs) => tryOrDegradePerformance(() => provider.multiSet(pairs)),
|
|
46
107
|
/**
|
|
47
108
|
* Merging an existing value with a new one
|
|
48
109
|
*/
|
|
49
|
-
mergeItem: (key, changes, modifiedData) => {
|
|
110
|
+
mergeItem: (key, changes, modifiedData) => tryOrDegradePerformance(() => {
|
|
50
111
|
const promise = provider.mergeItem(key, changes, modifiedData);
|
|
51
112
|
if (shouldKeepInstancesSync) {
|
|
52
113
|
return promise.then(() => InstanceSync_1.default.mergeItem(key));
|
|
53
114
|
}
|
|
54
115
|
return promise;
|
|
55
|
-
},
|
|
116
|
+
}),
|
|
56
117
|
/**
|
|
57
118
|
* Multiple merging of existing and new values in a batch
|
|
58
119
|
* This function also removes all nested null values from an object.
|
|
59
120
|
*/
|
|
60
|
-
multiMerge: (pairs) => provider.multiMerge(pairs),
|
|
121
|
+
multiMerge: (pairs) => tryOrDegradePerformance(() => provider.multiMerge(pairs)),
|
|
61
122
|
/**
|
|
62
123
|
* Removes given key and its value
|
|
63
124
|
*/
|
|
64
|
-
removeItem: (key) => {
|
|
125
|
+
removeItem: (key) => tryOrDegradePerformance(() => {
|
|
65
126
|
const promise = provider.removeItem(key);
|
|
66
127
|
if (shouldKeepInstancesSync) {
|
|
67
128
|
return promise.then(() => InstanceSync_1.default.removeItem(key));
|
|
68
129
|
}
|
|
69
130
|
return promise;
|
|
70
|
-
},
|
|
131
|
+
}),
|
|
71
132
|
/**
|
|
72
133
|
* Remove given keys and their values
|
|
73
134
|
*/
|
|
74
|
-
removeItems: (keys) => {
|
|
135
|
+
removeItems: (keys) => tryOrDegradePerformance(() => {
|
|
75
136
|
const promise = provider.removeItems(keys);
|
|
76
137
|
if (shouldKeepInstancesSync) {
|
|
77
138
|
return promise.then(() => InstanceSync_1.default.removeItems(keys));
|
|
78
139
|
}
|
|
79
140
|
return promise;
|
|
80
|
-
},
|
|
141
|
+
}),
|
|
81
142
|
/**
|
|
82
143
|
* Clears everything
|
|
83
144
|
*/
|
|
84
|
-
clear: () => {
|
|
145
|
+
clear: () => tryOrDegradePerformance(() => {
|
|
85
146
|
if (shouldKeepInstancesSync) {
|
|
86
147
|
return InstanceSync_1.default.clear(() => provider.clear());
|
|
87
148
|
}
|
|
88
149
|
return provider.clear();
|
|
89
|
-
},
|
|
150
|
+
}),
|
|
90
151
|
// This is a noop for now in order to keep clients from crashing see https://github.com/Expensify/Expensify/issues/312438
|
|
91
|
-
setMemoryOnlyKeys: () => provider.setMemoryOnlyKeys(),
|
|
152
|
+
setMemoryOnlyKeys: () => tryOrDegradePerformance(() => provider.setMemoryOnlyKeys()),
|
|
92
153
|
/**
|
|
93
154
|
* Returns all available keys
|
|
94
155
|
*/
|
|
95
|
-
getAllKeys: () => provider.getAllKeys(),
|
|
156
|
+
getAllKeys: () => tryOrDegradePerformance(() => provider.getAllKeys()),
|
|
96
157
|
/**
|
|
97
158
|
* Gets the total bytes of the store
|
|
98
159
|
*/
|
|
99
|
-
getDatabaseSize: () => provider.getDatabaseSize(),
|
|
160
|
+
getDatabaseSize: () => tryOrDegradePerformance(() => provider.getDatabaseSize()),
|
|
100
161
|
/**
|
|
101
162
|
* @param onStorageKeyChanged - Storage synchronization mechanism keeping all opened tabs in sync (web only)
|
|
102
163
|
*/
|
|
103
164
|
keepInstancesSync(onStorageKeyChanged) {
|
|
104
165
|
// If InstanceSync is null, it means we're on a native platform and we don't need to keep instances in sync
|
|
105
|
-
if (InstanceSync_1.default
|
|
166
|
+
if (InstanceSync_1.default === null)
|
|
106
167
|
return;
|
|
107
168
|
shouldKeepInstancesSync = true;
|
|
108
169
|
InstanceSync_1.default.init(onStorageKeyChanged);
|
|
@@ -9,6 +9,10 @@ const utils_1 = __importDefault(require("../../utils"));
|
|
|
9
9
|
// which might not be available in certain environments that load the bundle (e.g. electron main process).
|
|
10
10
|
let idbKeyValStore;
|
|
11
11
|
const provider = {
|
|
12
|
+
/**
|
|
13
|
+
* The name of the provider that can be printed to the logs
|
|
14
|
+
*/
|
|
15
|
+
name: 'IDBKeyValProvider',
|
|
12
16
|
/**
|
|
13
17
|
* Initializes the storage provider
|
|
14
18
|
*/
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const provider = {
|
|
4
|
+
/**
|
|
5
|
+
* The name of the provider that can be printed to the logs
|
|
6
|
+
*/
|
|
7
|
+
name: 'NoopProvider',
|
|
8
|
+
/**
|
|
9
|
+
* Initializes the storage provider
|
|
10
|
+
*/
|
|
11
|
+
init() {
|
|
12
|
+
// do nothing
|
|
13
|
+
},
|
|
14
|
+
/**
|
|
15
|
+
* Get the value of a given key or return `null` if it's not available in memory
|
|
16
|
+
* @param {String} key
|
|
17
|
+
* @return {Promise<*>}
|
|
18
|
+
*/
|
|
19
|
+
getItem() {
|
|
20
|
+
return Promise.resolve(null);
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Get multiple key-value pairs for the give array of keys in a batch.
|
|
24
|
+
*/
|
|
25
|
+
multiGet() {
|
|
26
|
+
return Promise.resolve([]);
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* Sets the value for a given key. The only requirement is that the value should be serializable to JSON string
|
|
30
|
+
*/
|
|
31
|
+
setItem() {
|
|
32
|
+
return Promise.resolve();
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Stores multiple key-value pairs in a batch
|
|
36
|
+
*/
|
|
37
|
+
multiSet() {
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Merging an existing value with a new one
|
|
42
|
+
*/
|
|
43
|
+
mergeItem() {
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* Multiple merging of existing and new values in a batch
|
|
48
|
+
* This function also removes all nested null values from an object.
|
|
49
|
+
*/
|
|
50
|
+
multiMerge() {
|
|
51
|
+
return Promise.resolve([]);
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* Remove given key and it's value from memory
|
|
55
|
+
*/
|
|
56
|
+
removeItem() {
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Remove given keys and their values from memory
|
|
61
|
+
*/
|
|
62
|
+
removeItems() {
|
|
63
|
+
return Promise.resolve();
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Clear everything from memory
|
|
67
|
+
*/
|
|
68
|
+
clear() {
|
|
69
|
+
return Promise.resolve();
|
|
70
|
+
},
|
|
71
|
+
// This is a noop for now in order to keep clients from crashing see https://github.com/Expensify/Expensify/issues/312438
|
|
72
|
+
setMemoryOnlyKeys() {
|
|
73
|
+
// do nothing
|
|
74
|
+
},
|
|
75
|
+
/**
|
|
76
|
+
* Returns all keys available in memory
|
|
77
|
+
*/
|
|
78
|
+
getAllKeys() {
|
|
79
|
+
return Promise.resolve([]);
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Gets the total bytes of the store.
|
|
83
|
+
* `bytesRemaining` will always be `Number.POSITIVE_INFINITY` since we don't have a hard limit on memory.
|
|
84
|
+
*/
|
|
85
|
+
getDatabaseSize() {
|
|
86
|
+
return Promise.resolve({ bytesRemaining: Number.POSITIVE_INFINITY, bytesUsed: 0 });
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
exports.default = provider;
|
|
@@ -9,6 +9,10 @@ const utils_1 = __importDefault(require("../../utils"));
|
|
|
9
9
|
const DB_NAME = 'OnyxDB';
|
|
10
10
|
let db;
|
|
11
11
|
const provider = {
|
|
12
|
+
/**
|
|
13
|
+
* The name of the provider that can be printed to the logs
|
|
14
|
+
*/
|
|
15
|
+
name: 'SQLiteProvider',
|
|
12
16
|
/**
|
|
13
17
|
* Initializes the storage provider
|
|
14
18
|
*/
|
|
@@ -6,6 +6,10 @@ type KeyList = Key[];
|
|
|
6
6
|
type KeyValuePairList = KeyValuePair[];
|
|
7
7
|
type OnStorageKeyChanged = (key: Key, value: Value | null) => void;
|
|
8
8
|
type StorageProvider = {
|
|
9
|
+
/**
|
|
10
|
+
* The name of the provider that can be printed to the logs
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
9
13
|
/**
|
|
10
14
|
* Initializes the storage provider
|
|
11
15
|
*/
|
|
@@ -69,4 +73,4 @@ type StorageProvider = {
|
|
|
69
73
|
keepInstancesSync?: (onStorageKeyChanged: OnStorageKeyChanged) => void;
|
|
70
74
|
};
|
|
71
75
|
export default StorageProvider;
|
|
72
|
-
export type { Value, Key, KeyList, KeyValuePairList, OnStorageKeyChanged };
|
|
76
|
+
export type { Value, Key, KeyList, KeyValuePair, KeyValuePairList, OnStorageKeyChanged };
|
package/package.json
CHANGED
package/dist/SyncQueue.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Synchronous queue that can be used to ensure promise based tasks are run in sequence.
|
|
3
|
-
* Pass to the constructor a function that returns a promise to run the task then add data.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
*
|
|
7
|
-
* const queue = new SyncQueue(({key, val}) => {
|
|
8
|
-
* return someAsyncProcess(key, val);
|
|
9
|
-
* });
|
|
10
|
-
*
|
|
11
|
-
* queue.push({key: 1, val: '1'});
|
|
12
|
-
* queue.push({key: 2, val: '2'});
|
|
13
|
-
*/
|
|
14
|
-
export default class SyncQueue {
|
|
15
|
-
/**
|
|
16
|
-
* @param {Function} run - must return a promise
|
|
17
|
-
*/
|
|
18
|
-
constructor(run: Function);
|
|
19
|
-
queue: any[];
|
|
20
|
-
isProcessing: boolean;
|
|
21
|
-
run: Function;
|
|
22
|
-
/**
|
|
23
|
-
* Stop the queue from being processed and clear out any existing tasks
|
|
24
|
-
*/
|
|
25
|
-
abort(): void;
|
|
26
|
-
process(): void;
|
|
27
|
-
/**
|
|
28
|
-
* @param {*} data
|
|
29
|
-
* @returns {Promise}
|
|
30
|
-
*/
|
|
31
|
-
push(data: any): Promise<any>;
|
|
32
|
-
}
|
package/dist/SyncQueue.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Synchronous queue that can be used to ensure promise based tasks are run in sequence.
|
|
5
|
-
* Pass to the constructor a function that returns a promise to run the task then add data.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
*
|
|
9
|
-
* const queue = new SyncQueue(({key, val}) => {
|
|
10
|
-
* return someAsyncProcess(key, val);
|
|
11
|
-
* });
|
|
12
|
-
*
|
|
13
|
-
* queue.push({key: 1, val: '1'});
|
|
14
|
-
* queue.push({key: 2, val: '2'});
|
|
15
|
-
*/
|
|
16
|
-
class SyncQueue {
|
|
17
|
-
/**
|
|
18
|
-
* @param {Function} run - must return a promise
|
|
19
|
-
*/
|
|
20
|
-
constructor(run) {
|
|
21
|
-
this.queue = [];
|
|
22
|
-
this.isProcessing = false;
|
|
23
|
-
this.run = run;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Stop the queue from being processed and clear out any existing tasks
|
|
27
|
-
*/
|
|
28
|
-
abort() {
|
|
29
|
-
this.queue = [];
|
|
30
|
-
this.isProcessing = false;
|
|
31
|
-
}
|
|
32
|
-
process() {
|
|
33
|
-
if (this.isProcessing || this.queue.length === 0) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
this.isProcessing = true;
|
|
37
|
-
const { data, resolve, reject } = this.queue.shift();
|
|
38
|
-
this.run(data)
|
|
39
|
-
.then(resolve)
|
|
40
|
-
.catch(reject)
|
|
41
|
-
.finally(() => {
|
|
42
|
-
this.isProcessing = false;
|
|
43
|
-
this.process();
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @param {*} data
|
|
48
|
-
* @returns {Promise}
|
|
49
|
-
*/
|
|
50
|
-
push(data) {
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
this.queue.push({ resolve, reject, data });
|
|
53
|
-
this.process();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.default = SyncQueue;
|
package/dist/compose.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a utility function taken directly from Redux. (We don't want to add Redux as a dependency)
|
|
3
|
-
* It enables functional composition, useful for the chaining/composition of HOCs.
|
|
4
|
-
*
|
|
5
|
-
* For example, instead of:
|
|
6
|
-
*
|
|
7
|
-
* export default hoc1(config1, hoc2(config2, hoc3(config3)))(Component);
|
|
8
|
-
*
|
|
9
|
-
* Use this instead:
|
|
10
|
-
*
|
|
11
|
-
* export default compose(
|
|
12
|
-
* hoc1(config1),
|
|
13
|
-
* hoc2(config2),
|
|
14
|
-
* hoc3(config3),
|
|
15
|
-
* )(Component)
|
|
16
|
-
*
|
|
17
|
-
* @returns {Function}
|
|
18
|
-
*/
|
|
19
|
-
export default function compose(...funcs: any[]): Function;
|
package/dist/compose.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* This is a utility function taken directly from Redux. (We don't want to add Redux as a dependency)
|
|
5
|
-
* It enables functional composition, useful for the chaining/composition of HOCs.
|
|
6
|
-
*
|
|
7
|
-
* For example, instead of:
|
|
8
|
-
*
|
|
9
|
-
* export default hoc1(config1, hoc2(config2, hoc3(config3)))(Component);
|
|
10
|
-
*
|
|
11
|
-
* Use this instead:
|
|
12
|
-
*
|
|
13
|
-
* export default compose(
|
|
14
|
-
* hoc1(config1),
|
|
15
|
-
* hoc2(config2),
|
|
16
|
-
* hoc3(config3),
|
|
17
|
-
* )(Component)
|
|
18
|
-
*
|
|
19
|
-
* @returns {Function}
|
|
20
|
-
*/
|
|
21
|
-
function compose(...funcs) {
|
|
22
|
-
if (funcs.length === 0) {
|
|
23
|
-
return (arg) => arg;
|
|
24
|
-
}
|
|
25
|
-
if (funcs.length === 1) {
|
|
26
|
-
return funcs[0];
|
|
27
|
-
}
|
|
28
|
-
// eslint-disable-next-line rulesdir/prefer-underscore-method
|
|
29
|
-
return funcs.reduce((a, b) => (...args) => a(b(...args)));
|
|
30
|
-
}
|
|
31
|
-
exports.default = compose;
|