@aws-amplify/core 6.0.11 → 6.0.12-unstable.70a435e.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/dist/cjs/Platform/version.js +1 -1
- package/dist/cjs/Platform/version.js.map +1 -1
- package/dist/cjs/utils/queuedStorage/constants.js +9 -0
- package/dist/cjs/utils/queuedStorage/constants.js.map +1 -0
- package/dist/cjs/utils/queuedStorage/createQueuedStorage.js +134 -0
- package/dist/cjs/utils/queuedStorage/createQueuedStorage.js.map +1 -0
- package/dist/cjs/utils/queuedStorage/createQueuedStorage.native.js +105 -0
- package/dist/cjs/utils/queuedStorage/createQueuedStorage.native.js.map +1 -0
- package/dist/cjs/utils/queuedStorage/getAddItemBytesSize.js +9 -0
- package/dist/cjs/utils/queuedStorage/getAddItemBytesSize.js.map +1 -0
- package/dist/cjs/utils/queuedStorage/index.js +9 -0
- package/dist/cjs/utils/queuedStorage/index.js.map +1 -0
- package/dist/cjs/utils/queuedStorage/types.js +6 -0
- package/dist/cjs/utils/queuedStorage/types.js.map +1 -0
- package/dist/esm/Hub/types/AuthTypes.d.ts +3 -0
- package/dist/esm/Platform/version.d.ts +1 -1
- package/dist/esm/Platform/version.mjs +1 -1
- package/dist/esm/Platform/version.mjs.map +1 -1
- package/dist/esm/utils/queuedStorage/constants.d.ts +2 -0
- package/dist/esm/utils/queuedStorage/constants.mjs +7 -0
- package/dist/esm/utils/queuedStorage/constants.mjs.map +1 -0
- package/dist/esm/utils/queuedStorage/createQueuedStorage.d.ts +2 -0
- package/dist/esm/utils/queuedStorage/createQueuedStorage.mjs +132 -0
- package/dist/esm/utils/queuedStorage/createQueuedStorage.mjs.map +1 -0
- package/dist/esm/utils/queuedStorage/createQueuedStorage.native.d.ts +3 -0
- package/dist/esm/utils/queuedStorage/createQueuedStorage.native.mjs +103 -0
- package/dist/esm/utils/queuedStorage/createQueuedStorage.native.mjs.map +1 -0
- package/dist/esm/utils/queuedStorage/getAddItemBytesSize.d.ts +2 -0
- package/dist/esm/utils/queuedStorage/getAddItemBytesSize.mjs +6 -0
- package/dist/esm/utils/queuedStorage/getAddItemBytesSize.mjs.map +1 -0
- package/dist/esm/utils/queuedStorage/index.d.ts +1 -0
- package/dist/esm/utils/queuedStorage/index.mjs +2 -0
- package/dist/esm/utils/queuedStorage/index.mjs.map +1 -0
- package/dist/esm/utils/queuedStorage/types.d.ts +32 -0
- package/dist/esm/utils/queuedStorage/types.mjs +2 -0
- package/dist/esm/utils/queuedStorage/types.mjs.map +1 -0
- package/package.json +3 -3
- package/src/Hub/types/AuthTypes.ts +1 -1
- package/src/Platform/version.ts +1 -1
- package/src/utils/queuedStorage/constants.ts +5 -0
- package/src/utils/queuedStorage/createQueuedStorage.native.ts +134 -0
- package/src/utils/queuedStorage/createQueuedStorage.ts +171 -0
- package/src/utils/queuedStorage/getAddItemBytesSize.ts +9 -0
- package/src/utils/queuedStorage/index.ts +4 -0
- package/src/utils/queuedStorage/types.ts +45 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sources":["../../../src/Platform/version.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.version = void 0;\n// generated by genversion\nexports.version = '6.0.
|
|
1
|
+
{"version":3,"file":"version.js","sources":["../../../src/Platform/version.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.version = void 0;\n// generated by genversion\nexports.version = '6.0.12-unstable.70a435e.0+70a435e';\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC;AACzB;AACA,OAAO,CAAC,OAAO,GAAG,mCAAmC;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.STORE_NAME = exports.DATABASE_NAME = void 0;
|
|
7
|
+
exports.DATABASE_NAME = 'amplify_logging_cloudwatch';
|
|
8
|
+
exports.STORE_NAME = 'logging_cached_logs';
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/utils/queuedStorage/constants.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.STORE_NAME = exports.DATABASE_NAME = void 0;\nexports.DATABASE_NAME = 'amplify_logging_cloudwatch';\nexports.STORE_NAME = 'logging_cached_logs';\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AACpD,OAAO,CAAC,aAAa,GAAG,4BAA4B,CAAC;AACrD,OAAO,CAAC,UAAU,GAAG,qBAAqB;;"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createQueuedStorage = void 0;
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
const getAddItemBytesSize_1 = require("./getAddItemBytesSize");
|
|
9
|
+
const createQueuedStorage = () => {
|
|
10
|
+
let currentBytesSize = 0;
|
|
11
|
+
let error;
|
|
12
|
+
const openDBPromise = new Promise((resolve, reject) => {
|
|
13
|
+
const { indexedDB } = window;
|
|
14
|
+
const openRequest = indexedDB.open(constants_1.DATABASE_NAME, 1);
|
|
15
|
+
openRequest.onupgradeneeded = () => {
|
|
16
|
+
const db = openRequest.result;
|
|
17
|
+
if (!db.objectStoreNames.contains(constants_1.STORE_NAME)) {
|
|
18
|
+
db.createObjectStore(constants_1.STORE_NAME, {
|
|
19
|
+
keyPath: 'id',
|
|
20
|
+
autoIncrement: true,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
openRequest.onsuccess = async () => {
|
|
25
|
+
const db = openRequest.result;
|
|
26
|
+
const transaction = db.transaction(constants_1.STORE_NAME, 'readonly');
|
|
27
|
+
const request = transaction.objectStore(constants_1.STORE_NAME).getAll();
|
|
28
|
+
await promisifyIDBRequest(request);
|
|
29
|
+
for (const item of request.result) {
|
|
30
|
+
currentBytesSize += item.bytesSize;
|
|
31
|
+
}
|
|
32
|
+
resolve(openRequest.result);
|
|
33
|
+
};
|
|
34
|
+
openRequest.onerror = () => {
|
|
35
|
+
reject(openRequest.error);
|
|
36
|
+
};
|
|
37
|
+
}).catch(err => {
|
|
38
|
+
error = err;
|
|
39
|
+
return undefined;
|
|
40
|
+
});
|
|
41
|
+
const getDB = async () => {
|
|
42
|
+
const db = await openDBPromise;
|
|
43
|
+
if (!db) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
return db;
|
|
47
|
+
};
|
|
48
|
+
const getStore = async () => {
|
|
49
|
+
const db = await getDB();
|
|
50
|
+
const transaction = db.transaction(constants_1.STORE_NAME, 'readwrite');
|
|
51
|
+
return transaction.objectStore(constants_1.STORE_NAME);
|
|
52
|
+
};
|
|
53
|
+
const _peek = async (n) => {
|
|
54
|
+
const store = await getStore();
|
|
55
|
+
const request = store.getAll(undefined, n);
|
|
56
|
+
await promisifyIDBRequest(request);
|
|
57
|
+
return request.result.map(item => item);
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
async add(item, { dequeueBeforeEnqueue } = { dequeueBeforeEnqueue: false }) {
|
|
61
|
+
if (dequeueBeforeEnqueue) {
|
|
62
|
+
const itemsToDelete = await this.peek(1);
|
|
63
|
+
await this.delete(itemsToDelete);
|
|
64
|
+
}
|
|
65
|
+
const store = await getStore();
|
|
66
|
+
const itemBytesSize = (0, getAddItemBytesSize_1.getAddItemBytesSize)(item);
|
|
67
|
+
const queuedItem = {
|
|
68
|
+
...item,
|
|
69
|
+
bytesSize: itemBytesSize,
|
|
70
|
+
};
|
|
71
|
+
const request = store.add(queuedItem);
|
|
72
|
+
await promisifyIDBRequest(request);
|
|
73
|
+
currentBytesSize += itemBytesSize;
|
|
74
|
+
},
|
|
75
|
+
async peek(n) {
|
|
76
|
+
return _peek(n);
|
|
77
|
+
},
|
|
78
|
+
async peekAll() {
|
|
79
|
+
return _peek();
|
|
80
|
+
},
|
|
81
|
+
async delete(items) {
|
|
82
|
+
if (!items.length) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const store = await getStore();
|
|
86
|
+
// delete by range to improve performance
|
|
87
|
+
const keyRangesToDelete = findRanges(items
|
|
88
|
+
.map(item => item.id)
|
|
89
|
+
.filter((id) => id !== undefined)).map(([lower, upper]) => IDBKeyRange.bound(lower, upper));
|
|
90
|
+
await Promise.all(keyRangesToDelete.map(range => promisifyIDBRequest(store.delete(range))));
|
|
91
|
+
for (const item of items) {
|
|
92
|
+
currentBytesSize -= item.bytesSize;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async clear() {
|
|
96
|
+
const store = await getStore();
|
|
97
|
+
await store.clear();
|
|
98
|
+
currentBytesSize = 0;
|
|
99
|
+
},
|
|
100
|
+
isFull(maxBytesSizeInMiB) {
|
|
101
|
+
return currentBytesSize >= maxBytesSizeInMiB * 1024 * 1024;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
exports.createQueuedStorage = createQueuedStorage;
|
|
106
|
+
const promisifyIDBRequest = (request) => new Promise((resolve, reject) => {
|
|
107
|
+
request.onsuccess = () => {
|
|
108
|
+
resolve();
|
|
109
|
+
};
|
|
110
|
+
request.onerror = () => {
|
|
111
|
+
reject(request.error);
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
const findRanges = (input) => {
|
|
115
|
+
const nums = input.concat().sort((a, b) => a - b);
|
|
116
|
+
const result = [];
|
|
117
|
+
let rangeLength = 1;
|
|
118
|
+
for (let i = 1; i <= nums.length; i++) {
|
|
119
|
+
if (i === nums.length || nums[i] - nums[i - 1] !== 1) {
|
|
120
|
+
if (rangeLength === 1) {
|
|
121
|
+
result.push([nums[i - rangeLength], nums[i - rangeLength]]);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
result.push([nums[i - rangeLength], nums[i - 1]]);
|
|
125
|
+
}
|
|
126
|
+
rangeLength = 1;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
rangeLength += 1;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=createQueuedStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueuedStorage.js","sources":["../../../../src/utils/queuedStorage/createQueuedStorage.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createQueuedStorage = void 0;\nconst constants_1 = require(\"./constants\");\nconst getAddItemBytesSize_1 = require(\"./getAddItemBytesSize\");\nconst createQueuedStorage = () => {\n let currentBytesSize = 0;\n let error;\n const openDBPromise = new Promise((resolve, reject) => {\n const { indexedDB } = window;\n const openRequest = indexedDB.open(constants_1.DATABASE_NAME, 1);\n openRequest.onupgradeneeded = () => {\n const db = openRequest.result;\n if (!db.objectStoreNames.contains(constants_1.STORE_NAME)) {\n db.createObjectStore(constants_1.STORE_NAME, {\n keyPath: 'id',\n autoIncrement: true,\n });\n }\n };\n openRequest.onsuccess = async () => {\n const db = openRequest.result;\n const transaction = db.transaction(constants_1.STORE_NAME, 'readonly');\n const request = transaction.objectStore(constants_1.STORE_NAME).getAll();\n await promisifyIDBRequest(request);\n for (const item of request.result) {\n currentBytesSize += item.bytesSize;\n }\n resolve(openRequest.result);\n };\n openRequest.onerror = () => {\n reject(openRequest.error);\n };\n }).catch(err => {\n error = err;\n return undefined;\n });\n const getDB = async () => {\n const db = await openDBPromise;\n if (!db) {\n throw error;\n }\n return db;\n };\n const getStore = async () => {\n const db = await getDB();\n const transaction = db.transaction(constants_1.STORE_NAME, 'readwrite');\n return transaction.objectStore(constants_1.STORE_NAME);\n };\n const _peek = async (n) => {\n const store = await getStore();\n const request = store.getAll(undefined, n);\n await promisifyIDBRequest(request);\n return request.result.map(item => item);\n };\n return {\n async add(item, { dequeueBeforeEnqueue } = { dequeueBeforeEnqueue: false }) {\n if (dequeueBeforeEnqueue) {\n const itemsToDelete = await this.peek(1);\n await this.delete(itemsToDelete);\n }\n const store = await getStore();\n const itemBytesSize = (0, getAddItemBytesSize_1.getAddItemBytesSize)(item);\n const queuedItem = {\n ...item,\n bytesSize: itemBytesSize,\n };\n const request = store.add(queuedItem);\n await promisifyIDBRequest(request);\n currentBytesSize += itemBytesSize;\n },\n async peek(n) {\n return _peek(n);\n },\n async peekAll() {\n return _peek();\n },\n async delete(items) {\n if (!items.length) {\n return;\n }\n const store = await getStore();\n // delete by range to improve performance\n const keyRangesToDelete = findRanges(items\n .map(item => item.id)\n .filter((id) => id !== undefined)).map(([lower, upper]) => IDBKeyRange.bound(lower, upper));\n await Promise.all(keyRangesToDelete.map(range => promisifyIDBRequest(store.delete(range))));\n for (const item of items) {\n currentBytesSize -= item.bytesSize;\n }\n },\n async clear() {\n const store = await getStore();\n await store.clear();\n currentBytesSize = 0;\n },\n isFull(maxBytesSizeInMiB) {\n return currentBytesSize >= maxBytesSizeInMiB * 1024 * 1024;\n },\n };\n};\nexports.createQueuedStorage = createQueuedStorage;\nconst promisifyIDBRequest = (request) => new Promise((resolve, reject) => {\n request.onsuccess = () => {\n resolve();\n };\n request.onerror = () => {\n reject(request.error);\n };\n});\nconst findRanges = (input) => {\n const nums = input.concat().sort((a, b) => a - b);\n const result = [];\n let rangeLength = 1;\n for (let i = 1; i <= nums.length; i++) {\n if (i === nums.length || nums[i] - nums[i - 1] !== 1) {\n if (rangeLength === 1) {\n result.push([nums[i - rangeLength], nums[i - rangeLength]]);\n }\n else {\n result.push([nums[i - rangeLength], nums[i - 1]]);\n }\n rangeLength = 1;\n }\n else {\n rangeLength += 1;\n }\n }\n return result;\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,mBAAmB,GAAG,KAAK,CAAC,CAAC;AACrC,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC3C,MAAM,qBAAqB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAC/D,MAAM,mBAAmB,GAAG,MAAM;AAClC,IAAI,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAC7B,IAAI,IAAI,KAAK,CAAC;AACd,IAAI,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAC3D,QAAQ,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;AACrC,QAAQ,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;AACzE,QAAQ,WAAW,CAAC,eAAe,GAAG,MAAM;AAC5C,YAAY,MAAM,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC;AAC1C,YAAY,IAAI,CAAC,EAAE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AI,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAC5E,aAAa;AACb,iBAAiB;AACjB,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,aAAa;AACb,YAAY,WAAW,GAAG,CAAC,CAAC;AAC5B,SAAS;AACT,aAAa;AACb,YAAY,WAAW,IAAI,CAAC,CAAC;AAC7B,SAAS;AACT,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;;"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createQueuedStorage = exports.keyPrefix = void 0;
|
|
7
|
+
const react_native_1 = require("@aws-amplify/react-native");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
const getAddItemBytesSize_1 = require("./getAddItemBytesSize");
|
|
10
|
+
exports.keyPrefix = `@${constants_1.DATABASE_NAME}`;
|
|
11
|
+
const createQueuedStorage = () => {
|
|
12
|
+
let currentBytesSize = 0;
|
|
13
|
+
let error;
|
|
14
|
+
const openDBPromise = new Promise((resolve, _) => {
|
|
15
|
+
try {
|
|
16
|
+
const asyncStorage = (0, react_native_1.loadAsyncStorage)();
|
|
17
|
+
getQueuedItemKeys(asyncStorage)
|
|
18
|
+
.then(keys => getQueuedItems(asyncStorage, keys))
|
|
19
|
+
.then(items => {
|
|
20
|
+
for (const item of items) {
|
|
21
|
+
currentBytesSize += item.bytesSize;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
})
|
|
25
|
+
.then(_ => {
|
|
26
|
+
resolve(asyncStorage);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
error = err;
|
|
31
|
+
resolve(undefined);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const getAsyncStorage = async () => {
|
|
35
|
+
const as = await openDBPromise;
|
|
36
|
+
if (!as) {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
return as;
|
|
40
|
+
};
|
|
41
|
+
const _peek = async (n) => {
|
|
42
|
+
const as = await getAsyncStorage();
|
|
43
|
+
const queuedItemKeys = await getQueuedItemKeys(as, true);
|
|
44
|
+
const keysToGetValues = queuedItemKeys.slice(0, n);
|
|
45
|
+
return getQueuedItems(as, keysToGetValues);
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
async add(item, { dequeueBeforeEnqueue } = { dequeueBeforeEnqueue: false }) {
|
|
49
|
+
if (dequeueBeforeEnqueue) {
|
|
50
|
+
const itemsToDelete = await this.peek(1);
|
|
51
|
+
await this.delete(itemsToDelete);
|
|
52
|
+
}
|
|
53
|
+
const as = await getAsyncStorage();
|
|
54
|
+
const itemBytesSize = (0, getAddItemBytesSize_1.getAddItemBytesSize)(item);
|
|
55
|
+
const key = `${exports.keyPrefix}_${Date.now()}`;
|
|
56
|
+
const queuedItem = {
|
|
57
|
+
...item,
|
|
58
|
+
bytesSize: itemBytesSize,
|
|
59
|
+
key,
|
|
60
|
+
};
|
|
61
|
+
await as.setItem(key, JSON.stringify(queuedItem));
|
|
62
|
+
currentBytesSize += itemBytesSize;
|
|
63
|
+
},
|
|
64
|
+
async peek(n) {
|
|
65
|
+
return _peek(n);
|
|
66
|
+
},
|
|
67
|
+
async peekAll() {
|
|
68
|
+
return _peek();
|
|
69
|
+
},
|
|
70
|
+
async delete(items) {
|
|
71
|
+
const as = await getAsyncStorage();
|
|
72
|
+
const keysToDelete = items
|
|
73
|
+
.map(item => item.key)
|
|
74
|
+
.filter((id) => id !== undefined);
|
|
75
|
+
await as.multiRemove(keysToDelete);
|
|
76
|
+
for (const item of items) {
|
|
77
|
+
currentBytesSize -= item.bytesSize;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
async clear() {
|
|
81
|
+
const as = await getAsyncStorage();
|
|
82
|
+
const keysToDelete = await getQueuedItemKeys(as);
|
|
83
|
+
await as.multiRemove(keysToDelete);
|
|
84
|
+
currentBytesSize = 0;
|
|
85
|
+
},
|
|
86
|
+
isFull(maxBytesSizeInMiB) {
|
|
87
|
+
return currentBytesSize >= maxBytesSizeInMiB * 1024 * 1024;
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
exports.createQueuedStorage = createQueuedStorage;
|
|
92
|
+
const getQueuedItemKeys = async (as, sortKeys = false) => {
|
|
93
|
+
const keys = (await as.getAllKeys()).filter(key => key.startsWith(exports.keyPrefix));
|
|
94
|
+
return sortKeys
|
|
95
|
+
? keys.sort((a, b) => {
|
|
96
|
+
const timestampA = a.split('_').pop();
|
|
97
|
+
const timestampB = b.split('_').pop();
|
|
98
|
+
return parseInt(timestampA) - parseInt(timestampB);
|
|
99
|
+
})
|
|
100
|
+
: keys;
|
|
101
|
+
};
|
|
102
|
+
const getQueuedItems = async (as, keys) => (await as.multiGet(keys))
|
|
103
|
+
.filter((item) => item[1] !== null)
|
|
104
|
+
.map(([_, value]) => JSON.parse(value));
|
|
105
|
+
//# sourceMappingURL=createQueuedStorage.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueuedStorage.native.js","sources":["../../../../src/utils/queuedStorage/createQueuedStorage.native.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createQueuedStorage = exports.keyPrefix = void 0;\nconst react_native_1 = require(\"@aws-amplify/react-native\");\nconst constants_1 = require(\"./constants\");\nconst getAddItemBytesSize_1 = require(\"./getAddItemBytesSize\");\nexports.keyPrefix = `@${constants_1.DATABASE_NAME}`;\nconst createQueuedStorage = () => {\n let currentBytesSize = 0;\n let error;\n const openDBPromise = new Promise((resolve, _) => {\n try {\n const asyncStorage = (0, react_native_1.loadAsyncStorage)();\n getQueuedItemKeys(asyncStorage)\n .then(keys => getQueuedItems(asyncStorage, keys))\n .then(items => {\n for (const item of items) {\n currentBytesSize += item.bytesSize;\n }\n return undefined;\n })\n .then(_ => {\n resolve(asyncStorage);\n });\n }\n catch (err) {\n error = err;\n resolve(undefined);\n }\n });\n const getAsyncStorage = async () => {\n const as = await openDBPromise;\n if (!as) {\n throw error;\n }\n return as;\n };\n const _peek = async (n) => {\n const as = await getAsyncStorage();\n const queuedItemKeys = await getQueuedItemKeys(as, true);\n const keysToGetValues = queuedItemKeys.slice(0, n);\n return getQueuedItems(as, keysToGetValues);\n };\n return {\n async add(item, { dequeueBeforeEnqueue } = { dequeueBeforeEnqueue: false }) {\n if (dequeueBeforeEnqueue) {\n const itemsToDelete = await this.peek(1);\n await this.delete(itemsToDelete);\n }\n const as = await getAsyncStorage();\n const itemBytesSize = (0, getAddItemBytesSize_1.getAddItemBytesSize)(item);\n const key = `${exports.keyPrefix}_${Date.now()}`;\n const queuedItem = {\n ...item,\n bytesSize: itemBytesSize,\n key,\n };\n await as.setItem(key, JSON.stringify(queuedItem));\n currentBytesSize += itemBytesSize;\n },\n async peek(n) {\n return _peek(n);\n },\n async peekAll() {\n return _peek();\n },\n async delete(items) {\n const as = await getAsyncStorage();\n const keysToDelete = items\n .map(item => item.key)\n .filter((id) => id !== undefined);\n await as.multiRemove(keysToDelete);\n for (const item of items) {\n currentBytesSize -= item.bytesSize;\n }\n },\n async clear() {\n const as = await getAsyncStorage();\n const keysToDelete = await getQueuedItemKeys(as);\n await as.multiRemove(keysToDelete);\n currentBytesSize = 0;\n },\n isFull(maxBytesSizeInMiB) {\n return currentBytesSize >= maxBytesSizeInMiB * 1024 * 1024;\n },\n };\n};\nexports.createQueuedStorage = createQueuedStorage;\nconst getQueuedItemKeys = async (as, sortKeys = false) => {\n const keys = (await as.getAllKeys()).filter(key => key.startsWith(exports.keyPrefix));\n return sortKeys\n ? keys.sort((a, b) => {\n const timestampA = a.split('_').pop();\n const timestampB = b.split('_').pop();\n return parseInt(timestampA) - parseInt(timestampB);\n })\n : keys;\n};\nconst getQueuedItems = async (as, keys) => (await as.multiGet(keys))\n .filter((item) => item[1] !== null)\n .map(([_, value]) => JSON.parse(value));\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC;AACzD,MAAM,cAAc,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAC5D,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC3C,MAAM,qBAAqB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAC/D,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;AACpD,MAAM,mBAAmB,GAAG,MAAM;AAClC,IAAI,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAC7B,IAAI,IAAI,KAAK,CAAC;AACd,IAAI,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK;AACtD,QAAQ,IAAI;AACZ,YAAY,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,gBAAgB,GAAG,CAAC;AACxE,YAAY,iBAAiB,CAAC,YAAY,CAAC;AAC3C,iBAAiB,IAAI,CAAC,IAAI,IAAI,cAAc,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACjE,iBAAiB,IAAI,CAAC,KAAK,IAAI;AAC/B,gBAAgB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;A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,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AACvC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAddItemBytesSize = void 0;
|
|
7
|
+
const getAddItemBytesSize = ({ content, timestamp, }) => content.length + timestamp.length + 8;
|
|
8
|
+
exports.getAddItemBytesSize = getAddItemBytesSize;
|
|
9
|
+
//# sourceMappingURL=getAddItemBytesSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAddItemBytesSize.js","sources":["../../../../src/utils/queuedStorage/getAddItemBytesSize.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getAddItemBytesSize = void 0;\nconst getAddItemBytesSize = ({ content, timestamp, }) => content.length + timestamp.length + 8;\nexports.getAddItemBytesSize = getAddItemBytesSize;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,mBAAmB,GAAG,KAAK,CAAC,CAAC;AACrC,MAAM,mBAAmB,GAAG,CAAC,EAAE,OAAO,EAAE,SAAS,GAAG,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;AAC/F,OAAO,CAAC,mBAAmB,GAAG,mBAAmB;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createQueuedStorage = void 0;
|
|
7
|
+
var createQueuedStorage_1 = require("./createQueuedStorage");
|
|
8
|
+
Object.defineProperty(exports, "createQueuedStorage", { enumerable: true, get: function () { return createQueuedStorage_1.createQueuedStorage; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/utils/queuedStorage/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createQueuedStorage = void 0;\nvar createQueuedStorage_1 = require(\"./createQueuedStorage\");\nObject.defineProperty(exports, \"createQueuedStorage\", { enumerable: true, get: function () { return createQueuedStorage_1.createQueuedStorage; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,mBAAmB,GAAG,KAAK,CAAC,CAAC;AACrC,IAAI,qBAAqB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAC7D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,qBAAqB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,qBAAqB,CAAC,mBAAmB,CAAC,EAAE,EAAE,CAAC;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../../src/utils/queuedStorage/types.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;;"}
|
|
@@ -26,6 +26,9 @@ export type AuthHubEventData =
|
|
|
26
26
|
/** Dispatched when there is an error in the refresh of tokens.*/
|
|
27
27
|
| {
|
|
28
28
|
event: 'tokenRefresh_failure';
|
|
29
|
+
data: {
|
|
30
|
+
error?: AuthError;
|
|
31
|
+
};
|
|
29
32
|
}
|
|
30
33
|
/** Dispatched when there is a customState passed in the options of the `signInWithRedirect` API.*/
|
|
31
34
|
| {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "6.0.
|
|
1
|
+
export declare const version = "6.0.12-unstable.70a435e.0+70a435e";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","sources":["../../../src/Platform/version.ts"],"sourcesContent":["// generated by genversion\nexport const version = '6.0.
|
|
1
|
+
{"version":3,"file":"version.mjs","sources":["../../../src/Platform/version.ts"],"sourcesContent":["// generated by genversion\nexport const version = '6.0.12-unstable.70a435e.0+70a435e';\n"],"names":[],"mappings":"AAAA;AACY,MAAC,OAAO,GAAG;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
const DATABASE_NAME = 'amplify_logging_cloudwatch';
|
|
4
|
+
const STORE_NAME = 'logging_cached_logs';
|
|
5
|
+
|
|
6
|
+
export { DATABASE_NAME, STORE_NAME };
|
|
7
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","sources":["../../../../src/utils/queuedStorage/constants.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const DATABASE_NAME = 'amplify_logging_cloudwatch';\nexport const STORE_NAME = 'logging_cached_logs';\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,aAAa,GAAG,6BAA6B;AAC9C,MAAC,UAAU,GAAG;;;;"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { DATABASE_NAME, STORE_NAME } from './constants.mjs';
|
|
2
|
+
import { getAddItemBytesSize } from './getAddItemBytesSize.mjs';
|
|
3
|
+
|
|
4
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
const createQueuedStorage = () => {
|
|
7
|
+
let currentBytesSize = 0;
|
|
8
|
+
let error;
|
|
9
|
+
const openDBPromise = new Promise((resolve, reject) => {
|
|
10
|
+
const { indexedDB } = window;
|
|
11
|
+
const openRequest = indexedDB.open(DATABASE_NAME, 1);
|
|
12
|
+
openRequest.onupgradeneeded = () => {
|
|
13
|
+
const db = openRequest.result;
|
|
14
|
+
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
|
15
|
+
db.createObjectStore(STORE_NAME, {
|
|
16
|
+
keyPath: 'id',
|
|
17
|
+
autoIncrement: true,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
openRequest.onsuccess = async () => {
|
|
22
|
+
const db = openRequest.result;
|
|
23
|
+
const transaction = db.transaction(STORE_NAME, 'readonly');
|
|
24
|
+
const request = transaction.objectStore(STORE_NAME).getAll();
|
|
25
|
+
await promisifyIDBRequest(request);
|
|
26
|
+
for (const item of request.result) {
|
|
27
|
+
currentBytesSize += item.bytesSize;
|
|
28
|
+
}
|
|
29
|
+
resolve(openRequest.result);
|
|
30
|
+
};
|
|
31
|
+
openRequest.onerror = () => {
|
|
32
|
+
reject(openRequest.error);
|
|
33
|
+
};
|
|
34
|
+
}).catch(err => {
|
|
35
|
+
error = err;
|
|
36
|
+
return undefined;
|
|
37
|
+
});
|
|
38
|
+
const getDB = async () => {
|
|
39
|
+
const db = await openDBPromise;
|
|
40
|
+
if (!db) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
return db;
|
|
44
|
+
};
|
|
45
|
+
const getStore = async () => {
|
|
46
|
+
const db = await getDB();
|
|
47
|
+
const transaction = db.transaction(STORE_NAME, 'readwrite');
|
|
48
|
+
return transaction.objectStore(STORE_NAME);
|
|
49
|
+
};
|
|
50
|
+
const _peek = async (n) => {
|
|
51
|
+
const store = await getStore();
|
|
52
|
+
const request = store.getAll(undefined, n);
|
|
53
|
+
await promisifyIDBRequest(request);
|
|
54
|
+
return request.result.map(item => item);
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
async add(item, { dequeueBeforeEnqueue } = { dequeueBeforeEnqueue: false }) {
|
|
58
|
+
if (dequeueBeforeEnqueue) {
|
|
59
|
+
const itemsToDelete = await this.peek(1);
|
|
60
|
+
await this.delete(itemsToDelete);
|
|
61
|
+
}
|
|
62
|
+
const store = await getStore();
|
|
63
|
+
const itemBytesSize = getAddItemBytesSize(item);
|
|
64
|
+
const queuedItem = {
|
|
65
|
+
...item,
|
|
66
|
+
bytesSize: itemBytesSize,
|
|
67
|
+
};
|
|
68
|
+
const request = store.add(queuedItem);
|
|
69
|
+
await promisifyIDBRequest(request);
|
|
70
|
+
currentBytesSize += itemBytesSize;
|
|
71
|
+
},
|
|
72
|
+
async peek(n) {
|
|
73
|
+
return _peek(n);
|
|
74
|
+
},
|
|
75
|
+
async peekAll() {
|
|
76
|
+
return _peek();
|
|
77
|
+
},
|
|
78
|
+
async delete(items) {
|
|
79
|
+
if (!items.length) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const store = await getStore();
|
|
83
|
+
// delete by range to improve performance
|
|
84
|
+
const keyRangesToDelete = findRanges(items
|
|
85
|
+
.map(item => item.id)
|
|
86
|
+
.filter((id) => id !== undefined)).map(([lower, upper]) => IDBKeyRange.bound(lower, upper));
|
|
87
|
+
await Promise.all(keyRangesToDelete.map(range => promisifyIDBRequest(store.delete(range))));
|
|
88
|
+
for (const item of items) {
|
|
89
|
+
currentBytesSize -= item.bytesSize;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
async clear() {
|
|
93
|
+
const store = await getStore();
|
|
94
|
+
await store.clear();
|
|
95
|
+
currentBytesSize = 0;
|
|
96
|
+
},
|
|
97
|
+
isFull(maxBytesSizeInMiB) {
|
|
98
|
+
return currentBytesSize >= maxBytesSizeInMiB * 1024 * 1024;
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const promisifyIDBRequest = (request) => new Promise((resolve, reject) => {
|
|
103
|
+
request.onsuccess = () => {
|
|
104
|
+
resolve();
|
|
105
|
+
};
|
|
106
|
+
request.onerror = () => {
|
|
107
|
+
reject(request.error);
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
const findRanges = (input) => {
|
|
111
|
+
const nums = input.concat().sort((a, b) => a - b);
|
|
112
|
+
const result = [];
|
|
113
|
+
let rangeLength = 1;
|
|
114
|
+
for (let i = 1; i <= nums.length; i++) {
|
|
115
|
+
if (i === nums.length || nums[i] - nums[i - 1] !== 1) {
|
|
116
|
+
if (rangeLength === 1) {
|
|
117
|
+
result.push([nums[i - rangeLength], nums[i - rangeLength]]);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
result.push([nums[i - rangeLength], nums[i - 1]]);
|
|
121
|
+
}
|
|
122
|
+
rangeLength = 1;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
rangeLength += 1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export { createQueuedStorage };
|
|
132
|
+
//# sourceMappingURL=createQueuedStorage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueuedStorage.mjs","sources":["../../../../src/utils/queuedStorage/createQueuedStorage.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { DATABASE_NAME, STORE_NAME } from './constants';\nimport { getAddItemBytesSize } from './getAddItemBytesSize';\nexport const createQueuedStorage = () => {\n let currentBytesSize = 0;\n let error;\n const openDBPromise = new Promise((resolve, reject) => {\n const { indexedDB } = window;\n const openRequest = indexedDB.open(DATABASE_NAME, 1);\n openRequest.onupgradeneeded = () => {\n const db = openRequest.result;\n if (!db.objectStoreNames.contains(STORE_NAME)) {\n db.createObjectStore(STORE_NAME, {\n keyPath: 'id',\n autoIncrement: true,\n });\n }\n };\n openRequest.onsuccess = async () => {\n const db = openRequest.result;\n const transaction = db.transaction(STORE_NAME, 'readonly');\n const request = transaction.objectStore(STORE_NAME).getAll();\n await promisifyIDBRequest(request);\n for (const item of request.result) {\n currentBytesSize += item.bytesSize;\n }\n resolve(openRequest.result);\n };\n openRequest.onerror = () => {\n reject(openRequest.error);\n };\n }).catch(err => {\n error = err;\n return undefined;\n });\n const getDB = async () => {\n const db = await openDBPromise;\n if (!db) {\n throw error;\n }\n return db;\n };\n const getStore = async () => {\n const db = await getDB();\n const transaction = db.transaction(STORE_NAME, 'readwrite');\n return transaction.objectStore(STORE_NAME);\n };\n const _peek = async (n) => {\n const store = await getStore();\n const request = store.getAll(undefined, n);\n await promisifyIDBRequest(request);\n return request.result.map(item => item);\n };\n return {\n async add(item, { dequeueBeforeEnqueue } = { dequeueBeforeEnqueue: false }) {\n if (dequeueBeforeEnqueue) {\n const itemsToDelete = await this.peek(1);\n await this.delete(itemsToDelete);\n }\n const store = await getStore();\n const itemBytesSize = getAddItemBytesSize(item);\n const queuedItem = {\n ...item,\n bytesSize: itemBytesSize,\n };\n const request = store.add(queuedItem);\n await promisifyIDBRequest(request);\n currentBytesSize += itemBytesSize;\n },\n async peek(n) {\n return _peek(n);\n },\n async peekAll() {\n return _peek();\n },\n async delete(items) {\n if (!items.length) {\n return;\n }\n const store = await getStore();\n // delete by range to improve performance\n const keyRangesToDelete = findRanges(items\n .map(item => item.id)\n .filter((id) => id !== undefined)).map(([lower, upper]) => IDBKeyRange.bound(lower, upper));\n await Promise.all(keyRangesToDelete.map(range => promisifyIDBRequest(store.delete(range))));\n for (const item of items) {\n currentBytesSize -= item.bytesSize;\n }\n },\n async clear() {\n const store = await getStore();\n await store.clear();\n currentBytesSize = 0;\n },\n isFull(maxBytesSizeInMiB) {\n return currentBytesSize >= maxBytesSizeInMiB * 1024 * 1024;\n },\n };\n};\nconst promisifyIDBRequest = (request) => new Promise((resolve, reject) => {\n request.onsuccess = () => {\n resolve();\n };\n request.onerror = () => {\n reject(request.error);\n };\n});\nconst findRanges = (input) => {\n const nums = input.concat().sort((a, b) => a - b);\n const result = [];\n let rangeLength = 1;\n for (let i = 1; i <= nums.length; i++) {\n if (i === nums.length || nums[i] - nums[i - 1] !== 1) {\n if (rangeLength === 1) {\n result.push([nums[i - rangeLength], nums[i - rangeLength]]);\n }\n else {\n result.push([nums[i - rangeLength], nums[i - 1]]);\n }\n rangeLength = 1;\n }\n else {\n rangeLength += 1;\n }\n }\n return result;\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGY,MAAC,mBAAmB,GAAG,MAAM;AACzC,IAAI,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAC7B,IAAI,IAAI,KAAK,CAAC;AACd,IAAI,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAC3D,QAAQ,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;AACrC,QAAQ,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;AAC7D,QAAQ,WAAW,CAAC,eAAe,GAAG,MAAM;AAC5C,YAAY,MAAM,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC;AAC1C,YAAY,IAAI,CAAC,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GAAG,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,aAAa;AACb,YAAY,WAAW,GAAG,CAAC,CAAC;AAC5B,SAAS;AACT,aAAa;AACb,YAAY,WAAW,IAAI,CAAC,CAAC;AAC7B,SAAS;AACT,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;;;;"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { loadAsyncStorage } from '@aws-amplify/react-native';
|
|
2
|
+
import { DATABASE_NAME } from './constants.mjs';
|
|
3
|
+
import { getAddItemBytesSize } from './getAddItemBytesSize.mjs';
|
|
4
|
+
|
|
5
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
const keyPrefix = `@${DATABASE_NAME}`;
|
|
8
|
+
const createQueuedStorage = () => {
|
|
9
|
+
let currentBytesSize = 0;
|
|
10
|
+
let error;
|
|
11
|
+
const openDBPromise = new Promise((resolve, _) => {
|
|
12
|
+
try {
|
|
13
|
+
const asyncStorage = loadAsyncStorage();
|
|
14
|
+
getQueuedItemKeys(asyncStorage)
|
|
15
|
+
.then(keys => getQueuedItems(asyncStorage, keys))
|
|
16
|
+
.then(items => {
|
|
17
|
+
for (const item of items) {
|
|
18
|
+
currentBytesSize += item.bytesSize;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
})
|
|
22
|
+
.then(_ => {
|
|
23
|
+
resolve(asyncStorage);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
error = err;
|
|
28
|
+
resolve(undefined);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const getAsyncStorage = async () => {
|
|
32
|
+
const as = await openDBPromise;
|
|
33
|
+
if (!as) {
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
return as;
|
|
37
|
+
};
|
|
38
|
+
const _peek = async (n) => {
|
|
39
|
+
const as = await getAsyncStorage();
|
|
40
|
+
const queuedItemKeys = await getQueuedItemKeys(as, true);
|
|
41
|
+
const keysToGetValues = queuedItemKeys.slice(0, n);
|
|
42
|
+
return getQueuedItems(as, keysToGetValues);
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
async add(item, { dequeueBeforeEnqueue } = { dequeueBeforeEnqueue: false }) {
|
|
46
|
+
if (dequeueBeforeEnqueue) {
|
|
47
|
+
const itemsToDelete = await this.peek(1);
|
|
48
|
+
await this.delete(itemsToDelete);
|
|
49
|
+
}
|
|
50
|
+
const as = await getAsyncStorage();
|
|
51
|
+
const itemBytesSize = getAddItemBytesSize(item);
|
|
52
|
+
const key = `${keyPrefix}_${Date.now()}`;
|
|
53
|
+
const queuedItem = {
|
|
54
|
+
...item,
|
|
55
|
+
bytesSize: itemBytesSize,
|
|
56
|
+
key,
|
|
57
|
+
};
|
|
58
|
+
await as.setItem(key, JSON.stringify(queuedItem));
|
|
59
|
+
currentBytesSize += itemBytesSize;
|
|
60
|
+
},
|
|
61
|
+
async peek(n) {
|
|
62
|
+
return _peek(n);
|
|
63
|
+
},
|
|
64
|
+
async peekAll() {
|
|
65
|
+
return _peek();
|
|
66
|
+
},
|
|
67
|
+
async delete(items) {
|
|
68
|
+
const as = await getAsyncStorage();
|
|
69
|
+
const keysToDelete = items
|
|
70
|
+
.map(item => item.key)
|
|
71
|
+
.filter((id) => id !== undefined);
|
|
72
|
+
await as.multiRemove(keysToDelete);
|
|
73
|
+
for (const item of items) {
|
|
74
|
+
currentBytesSize -= item.bytesSize;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
async clear() {
|
|
78
|
+
const as = await getAsyncStorage();
|
|
79
|
+
const keysToDelete = await getQueuedItemKeys(as);
|
|
80
|
+
await as.multiRemove(keysToDelete);
|
|
81
|
+
currentBytesSize = 0;
|
|
82
|
+
},
|
|
83
|
+
isFull(maxBytesSizeInMiB) {
|
|
84
|
+
return currentBytesSize >= maxBytesSizeInMiB * 1024 * 1024;
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const getQueuedItemKeys = async (as, sortKeys = false) => {
|
|
89
|
+
const keys = (await as.getAllKeys()).filter(key => key.startsWith(keyPrefix));
|
|
90
|
+
return sortKeys
|
|
91
|
+
? keys.sort((a, b) => {
|
|
92
|
+
const timestampA = a.split('_').pop();
|
|
93
|
+
const timestampB = b.split('_').pop();
|
|
94
|
+
return parseInt(timestampA) - parseInt(timestampB);
|
|
95
|
+
})
|
|
96
|
+
: keys;
|
|
97
|
+
};
|
|
98
|
+
const getQueuedItems = async (as, keys) => (await as.multiGet(keys))
|
|
99
|
+
.filter((item) => item[1] !== null)
|
|
100
|
+
.map(([_, value]) => JSON.parse(value));
|
|
101
|
+
|
|
102
|
+
export { createQueuedStorage, keyPrefix };
|
|
103
|
+
//# sourceMappingURL=createQueuedStorage.native.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueuedStorage.native.mjs","sources":["../../../../src/utils/queuedStorage/createQueuedStorage.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { loadAsyncStorage } from '@aws-amplify/react-native';\nimport { DATABASE_NAME } from './constants';\nimport { getAddItemBytesSize } from './getAddItemBytesSize';\nexport const keyPrefix = `@${DATABASE_NAME}`;\nexport const createQueuedStorage = () => {\n let currentBytesSize = 0;\n let error;\n const openDBPromise = new Promise((resolve, _) => {\n try {\n const asyncStorage = loadAsyncStorage();\n getQueuedItemKeys(asyncStorage)\n .then(keys => getQueuedItems(asyncStorage, keys))\n .then(items => {\n for (const item of items) {\n currentBytesSize += item.bytesSize;\n }\n return undefined;\n })\n .then(_ => {\n resolve(asyncStorage);\n });\n }\n catch (err) {\n error = err;\n resolve(undefined);\n }\n });\n const getAsyncStorage = async () => {\n const as = await openDBPromise;\n if (!as) {\n throw error;\n }\n return as;\n };\n const _peek = async (n) => {\n const as = await getAsyncStorage();\n const queuedItemKeys = await getQueuedItemKeys(as, true);\n const keysToGetValues = queuedItemKeys.slice(0, n);\n return getQueuedItems(as, keysToGetValues);\n };\n return {\n async add(item, { dequeueBeforeEnqueue } = { dequeueBeforeEnqueue: false }) {\n if (dequeueBeforeEnqueue) {\n const itemsToDelete = await this.peek(1);\n await this.delete(itemsToDelete);\n }\n const as = await getAsyncStorage();\n const itemBytesSize = getAddItemBytesSize(item);\n const key = `${keyPrefix}_${Date.now()}`;\n const queuedItem = {\n ...item,\n bytesSize: itemBytesSize,\n key,\n };\n await as.setItem(key, JSON.stringify(queuedItem));\n currentBytesSize += itemBytesSize;\n },\n async peek(n) {\n return _peek(n);\n },\n async peekAll() {\n return _peek();\n },\n async delete(items) {\n const as = await getAsyncStorage();\n const keysToDelete = items\n .map(item => item.key)\n .filter((id) => id !== undefined);\n await as.multiRemove(keysToDelete);\n for (const item of items) {\n currentBytesSize -= item.bytesSize;\n }\n },\n async clear() {\n const as = await getAsyncStorage();\n const keysToDelete = await getQueuedItemKeys(as);\n await as.multiRemove(keysToDelete);\n currentBytesSize = 0;\n },\n isFull(maxBytesSizeInMiB) {\n return currentBytesSize >= maxBytesSizeInMiB * 1024 * 1024;\n },\n };\n};\nconst getQueuedItemKeys = async (as, sortKeys = false) => {\n const keys = (await as.getAllKeys()).filter(key => key.startsWith(keyPrefix));\n return sortKeys\n ? keys.sort((a, b) => {\n const timestampA = a.split('_').pop();\n const timestampB = b.split('_').pop();\n return parseInt(timestampA) - parseInt(timestampB);\n })\n : keys;\n};\nconst getQueuedItems = async (as, keys) => (await as.multiGet(keys))\n .filter((item) => item[1] !== null)\n .map(([_, value]) => JSON.parse(value));\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIY,MAAC,SAAS,GAAG,CAAC,CAAC,EAAE,aAAa,CAAC,EAAE;AACjC,MAAC,mBAAmB,GAAG,MAAM;AACzC,IAAI,I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AG,CAAC,CAAC,GAAG,EAAE,CAAC;AAClD,YAAY,OAAO,QAAQ,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC/D,SAAS,CAAC;AACV,UAAU,IAAI,CAAC;AACf,CAAC,CAAC;AACF,MAAM,cAAc,GAAG,OAAO,EAAE,EAAE,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnE,KAAK,MAAM,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AACvC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
const getAddItemBytesSize = ({ content, timestamp, }) => content.length + timestamp.length + 8;
|
|
4
|
+
|
|
5
|
+
export { getAddItemBytesSize };
|
|
6
|
+
//# sourceMappingURL=getAddItemBytesSize.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAddItemBytesSize.mjs","sources":["../../../../src/utils/queuedStorage/getAddItemBytesSize.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const getAddItemBytesSize = ({ content, timestamp, }) => content.length + timestamp.length + 8;\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,mBAAmB,GAAG,CAAC,EAAE,OAAO,EAAE,SAAS,GAAG,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,GAAG;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createQueuedStorage } from './createQueuedStorage';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
interface WithBytesSize {
|
|
2
|
+
readonly bytesSize: number;
|
|
3
|
+
}
|
|
4
|
+
export interface ItemToAdd {
|
|
5
|
+
readonly content: string;
|
|
6
|
+
readonly timestamp: string;
|
|
7
|
+
}
|
|
8
|
+
export interface QueuedItemWeb extends ItemToAdd, WithBytesSize {
|
|
9
|
+
readonly id: number;
|
|
10
|
+
readonly key?: never;
|
|
11
|
+
}
|
|
12
|
+
export interface QueuedItemNative extends ItemToAdd, WithBytesSize {
|
|
13
|
+
readonly id?: never;
|
|
14
|
+
readonly key: string;
|
|
15
|
+
}
|
|
16
|
+
export type QueuedItem = QueuedItemWeb | QueuedItemNative;
|
|
17
|
+
export interface AddItemWithAuthPropertiesWeb extends ItemToAdd, WithBytesSize {
|
|
18
|
+
}
|
|
19
|
+
export interface AddItemWithAuthPropertiesNative extends ItemToAdd, WithBytesSize {
|
|
20
|
+
key: QueuedItemNative['key'];
|
|
21
|
+
}
|
|
22
|
+
export interface QueuedStorage {
|
|
23
|
+
add(item: ItemToAdd, options?: {
|
|
24
|
+
dequeueBeforeEnqueue: boolean;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
peek(n?: number): Promise<QueuedItem[]>;
|
|
27
|
+
peekAll(): Promise<QueuedItem[]>;
|
|
28
|
+
delete(items: QueuedItem[]): Promise<void>;
|
|
29
|
+
clear(): Promise<void>;
|
|
30
|
+
isFull(maxBytesSizeInMiB: number): boolean;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/core",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.12-unstable.70a435e.0+70a435e",
|
|
4
4
|
"description": "Core category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"uuid": "^9.0.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@aws-amplify/react-native": "1.0.
|
|
63
|
+
"@aws-amplify/react-native": "1.0.12-unstable.70a435e.0+70a435e",
|
|
64
64
|
"@rollup/plugin-typescript": "11.1.5",
|
|
65
65
|
"@types/js-cookie": "3.0.2",
|
|
66
66
|
"genversion": "^2.2.0",
|
|
@@ -194,5 +194,5 @@
|
|
|
194
194
|
]
|
|
195
195
|
}
|
|
196
196
|
},
|
|
197
|
-
"gitHead": "
|
|
197
|
+
"gitHead": "70a435ef94185dcee937a20640e5367f92a44efe"
|
|
198
198
|
}
|
|
@@ -21,7 +21,7 @@ export type AuthHubEventData =
|
|
|
21
21
|
/** Dispatched when auth tokens are successfully refreshed.*/
|
|
22
22
|
| { event: 'tokenRefresh' }
|
|
23
23
|
/** Dispatched when there is an error in the refresh of tokens.*/
|
|
24
|
-
| { event: 'tokenRefresh_failure' }
|
|
24
|
+
| { event: 'tokenRefresh_failure'; data: { error?: AuthError } }
|
|
25
25
|
/** Dispatched when there is a customState passed in the options of the `signInWithRedirect` API.*/
|
|
26
26
|
| { event: 'customOAuthState'; data: string }
|
|
27
27
|
/** Dispatched when the user is signed-in.*/
|
package/src/Platform/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '6.0.
|
|
2
|
+
export const version = '6.0.12-unstable.70a435e.0+70a435e';
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { loadAsyncStorage } from '@aws-amplify/react-native';
|
|
5
|
+
import {
|
|
6
|
+
AddItemWithAuthPropertiesNative,
|
|
7
|
+
QueuedItem,
|
|
8
|
+
QueuedStorage,
|
|
9
|
+
} from './types';
|
|
10
|
+
import { DATABASE_NAME } from './constants';
|
|
11
|
+
import { getAddItemBytesSize } from './getAddItemBytesSize';
|
|
12
|
+
|
|
13
|
+
export const keyPrefix = `@${DATABASE_NAME}`;
|
|
14
|
+
|
|
15
|
+
export const createQueuedStorage = (): QueuedStorage => {
|
|
16
|
+
let currentBytesSize = 0;
|
|
17
|
+
let error: Error | undefined;
|
|
18
|
+
|
|
19
|
+
const openDBPromise = new Promise<
|
|
20
|
+
ReturnType<typeof loadAsyncStorage> | undefined
|
|
21
|
+
>((resolve, _) => {
|
|
22
|
+
try {
|
|
23
|
+
const asyncStorage = loadAsyncStorage();
|
|
24
|
+
|
|
25
|
+
getQueuedItemKeys(asyncStorage)
|
|
26
|
+
.then(keys => getQueuedItems(asyncStorage, keys))
|
|
27
|
+
.then(items => {
|
|
28
|
+
for (const item of items) {
|
|
29
|
+
currentBytesSize += item.bytesSize;
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
})
|
|
33
|
+
.then(_ => {
|
|
34
|
+
resolve(asyncStorage);
|
|
35
|
+
});
|
|
36
|
+
} catch (err) {
|
|
37
|
+
error = err as Error;
|
|
38
|
+
resolve(undefined);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const getAsyncStorage = async () => {
|
|
43
|
+
const as = await openDBPromise;
|
|
44
|
+
|
|
45
|
+
if (!as) {
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return as;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const _peek = async (n?: number): Promise<QueuedItem[]> => {
|
|
53
|
+
const as = await getAsyncStorage();
|
|
54
|
+
const queuedItemKeys = await getQueuedItemKeys(as, true);
|
|
55
|
+
const keysToGetValues = queuedItemKeys.slice(0, n);
|
|
56
|
+
|
|
57
|
+
return getQueuedItems(as, keysToGetValues);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
async add(
|
|
62
|
+
item,
|
|
63
|
+
{ dequeueBeforeEnqueue } = { dequeueBeforeEnqueue: false }
|
|
64
|
+
) {
|
|
65
|
+
if (dequeueBeforeEnqueue) {
|
|
66
|
+
const itemsToDelete = await this.peek(1);
|
|
67
|
+
await this.delete(itemsToDelete);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const as = await getAsyncStorage();
|
|
71
|
+
const itemBytesSize = getAddItemBytesSize(item);
|
|
72
|
+
const key = `${keyPrefix}_${Date.now()}`;
|
|
73
|
+
const queuedItem: AddItemWithAuthPropertiesNative = {
|
|
74
|
+
...item,
|
|
75
|
+
bytesSize: itemBytesSize,
|
|
76
|
+
key,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
await as.setItem(key, JSON.stringify(queuedItem));
|
|
80
|
+
|
|
81
|
+
currentBytesSize += itemBytesSize;
|
|
82
|
+
},
|
|
83
|
+
async peek(n) {
|
|
84
|
+
return _peek(n);
|
|
85
|
+
},
|
|
86
|
+
async peekAll() {
|
|
87
|
+
return _peek();
|
|
88
|
+
},
|
|
89
|
+
async delete(items) {
|
|
90
|
+
const as = await getAsyncStorage();
|
|
91
|
+
const keysToDelete = items
|
|
92
|
+
.map(item => item.key)
|
|
93
|
+
.filter((id): id is string => id !== undefined);
|
|
94
|
+
|
|
95
|
+
await as.multiRemove(keysToDelete);
|
|
96
|
+
|
|
97
|
+
for (const item of items) {
|
|
98
|
+
currentBytesSize -= item.bytesSize;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
async clear() {
|
|
102
|
+
const as = await getAsyncStorage();
|
|
103
|
+
const keysToDelete = await getQueuedItemKeys(as);
|
|
104
|
+
await as.multiRemove(keysToDelete);
|
|
105
|
+
currentBytesSize = 0;
|
|
106
|
+
},
|
|
107
|
+
isFull(maxBytesSizeInMiB) {
|
|
108
|
+
return currentBytesSize >= maxBytesSizeInMiB * 1024 * 1024;
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const getQueuedItemKeys = async (
|
|
114
|
+
as: ReturnType<typeof loadAsyncStorage>,
|
|
115
|
+
sortKeys: boolean = false
|
|
116
|
+
): Promise<string[]> => {
|
|
117
|
+
const keys = (await as.getAllKeys()).filter(key => key.startsWith(keyPrefix));
|
|
118
|
+
|
|
119
|
+
return sortKeys
|
|
120
|
+
? keys.sort((a, b) => {
|
|
121
|
+
const timestampA = a.split('_').pop() as string;
|
|
122
|
+
const timestampB = b.split('_').pop() as string;
|
|
123
|
+
return parseInt(timestampA) - parseInt(timestampB);
|
|
124
|
+
})
|
|
125
|
+
: keys;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const getQueuedItems = async (
|
|
129
|
+
as: ReturnType<typeof loadAsyncStorage>,
|
|
130
|
+
keys: string[]
|
|
131
|
+
): Promise<QueuedItem[]> =>
|
|
132
|
+
(await as.multiGet(keys))
|
|
133
|
+
.filter((item): item is [string, string] => item[1] !== null)
|
|
134
|
+
.map(([_, value]) => JSON.parse(value) as QueuedItem);
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { DATABASE_NAME, STORE_NAME } from './constants';
|
|
5
|
+
import { getAddItemBytesSize } from './getAddItemBytesSize';
|
|
6
|
+
import {
|
|
7
|
+
AddItemWithAuthPropertiesWeb,
|
|
8
|
+
QueuedItem,
|
|
9
|
+
QueuedStorage,
|
|
10
|
+
} from './types';
|
|
11
|
+
|
|
12
|
+
export const createQueuedStorage = (): QueuedStorage => {
|
|
13
|
+
let currentBytesSize = 0;
|
|
14
|
+
let error: DOMException | undefined;
|
|
15
|
+
|
|
16
|
+
const openDBPromise = new Promise<IDBDatabase>((resolve, reject) => {
|
|
17
|
+
const { indexedDB } = window;
|
|
18
|
+
const openRequest = indexedDB.open(DATABASE_NAME, 1);
|
|
19
|
+
|
|
20
|
+
openRequest.onupgradeneeded = () => {
|
|
21
|
+
const db = openRequest.result;
|
|
22
|
+
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
|
23
|
+
db.createObjectStore(STORE_NAME, {
|
|
24
|
+
keyPath: 'id',
|
|
25
|
+
autoIncrement: true,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
openRequest.onsuccess = async () => {
|
|
31
|
+
const db = openRequest.result;
|
|
32
|
+
const transaction = db.transaction(STORE_NAME, 'readonly');
|
|
33
|
+
const request = transaction.objectStore(STORE_NAME).getAll();
|
|
34
|
+
|
|
35
|
+
await promisifyIDBRequest(request);
|
|
36
|
+
|
|
37
|
+
for (const item of request.result) {
|
|
38
|
+
currentBytesSize += (item as QueuedItem).bytesSize;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
resolve(openRequest.result);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
openRequest.onerror = () => {
|
|
45
|
+
reject(openRequest.error);
|
|
46
|
+
};
|
|
47
|
+
}).catch(err => {
|
|
48
|
+
error = err;
|
|
49
|
+
return undefined;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const getDB = async () => {
|
|
53
|
+
const db = await openDBPromise;
|
|
54
|
+
|
|
55
|
+
if (!db) {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return db;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const getStore = async (): Promise<IDBObjectStore> => {
|
|
63
|
+
const db = await getDB();
|
|
64
|
+
const transaction = db.transaction(STORE_NAME, 'readwrite');
|
|
65
|
+
return transaction.objectStore(STORE_NAME);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const _peek = async (n?: number): Promise<QueuedItem[]> => {
|
|
69
|
+
const store = await getStore();
|
|
70
|
+
const request = store.getAll(undefined, n);
|
|
71
|
+
|
|
72
|
+
await promisifyIDBRequest(request);
|
|
73
|
+
|
|
74
|
+
return request.result.map(item => item as QueuedItem);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
async add(
|
|
79
|
+
item,
|
|
80
|
+
{ dequeueBeforeEnqueue } = { dequeueBeforeEnqueue: false }
|
|
81
|
+
) {
|
|
82
|
+
if (dequeueBeforeEnqueue) {
|
|
83
|
+
const itemsToDelete = await this.peek(1);
|
|
84
|
+
await this.delete(itemsToDelete);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const store = await getStore();
|
|
88
|
+
|
|
89
|
+
const itemBytesSize = getAddItemBytesSize(item);
|
|
90
|
+
const queuedItem: AddItemWithAuthPropertiesWeb = {
|
|
91
|
+
...item,
|
|
92
|
+
bytesSize: itemBytesSize,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const request = store.add(queuedItem);
|
|
96
|
+
|
|
97
|
+
await promisifyIDBRequest(request);
|
|
98
|
+
|
|
99
|
+
currentBytesSize += itemBytesSize;
|
|
100
|
+
},
|
|
101
|
+
async peek(n) {
|
|
102
|
+
return _peek(n);
|
|
103
|
+
},
|
|
104
|
+
async peekAll() {
|
|
105
|
+
return _peek();
|
|
106
|
+
},
|
|
107
|
+
async delete(items) {
|
|
108
|
+
if (!items.length) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const store = await getStore();
|
|
113
|
+
|
|
114
|
+
// delete by range to improve performance
|
|
115
|
+
const keyRangesToDelete = findRanges(
|
|
116
|
+
items
|
|
117
|
+
.map(item => item.id)
|
|
118
|
+
.filter((id): id is number => id !== undefined)
|
|
119
|
+
).map(([lower, upper]) => IDBKeyRange.bound(lower, upper));
|
|
120
|
+
|
|
121
|
+
await Promise.all(
|
|
122
|
+
keyRangesToDelete.map(range => promisifyIDBRequest(store.delete(range)))
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
for (const item of items) {
|
|
126
|
+
currentBytesSize -= item.bytesSize;
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
async clear() {
|
|
130
|
+
const store = await getStore();
|
|
131
|
+
await store.clear();
|
|
132
|
+
currentBytesSize = 0;
|
|
133
|
+
},
|
|
134
|
+
isFull(maxBytesSizeInMiB) {
|
|
135
|
+
return currentBytesSize >= maxBytesSizeInMiB * 1024 * 1024;
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const promisifyIDBRequest = <T>(request: IDBRequest<T>): Promise<void> =>
|
|
141
|
+
new Promise<void>((resolve, reject) => {
|
|
142
|
+
request.onsuccess = () => {
|
|
143
|
+
resolve();
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
request.onerror = () => {
|
|
147
|
+
reject(request.error);
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const findRanges = (input: number[]): [number, number][] => {
|
|
152
|
+
const nums = input.concat().sort((a, b) => a - b);
|
|
153
|
+
const result: [number, number][] = [];
|
|
154
|
+
|
|
155
|
+
let rangeLength = 1;
|
|
156
|
+
|
|
157
|
+
for (let i = 1; i <= nums.length; i++) {
|
|
158
|
+
if (i === nums.length || nums[i] - nums[i - 1] !== 1) {
|
|
159
|
+
if (rangeLength === 1) {
|
|
160
|
+
result.push([nums[i - rangeLength], nums[i - rangeLength]]);
|
|
161
|
+
} else {
|
|
162
|
+
result.push([nums[i - rangeLength], nums[i - 1]]);
|
|
163
|
+
}
|
|
164
|
+
rangeLength = 1;
|
|
165
|
+
} else {
|
|
166
|
+
rangeLength += 1;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return result;
|
|
171
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ItemToAdd } from './types';
|
|
5
|
+
|
|
6
|
+
export const getAddItemBytesSize = ({
|
|
7
|
+
content,
|
|
8
|
+
timestamp,
|
|
9
|
+
}: ItemToAdd): number => content.length + timestamp.length + 8;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
interface WithBytesSize {
|
|
5
|
+
readonly bytesSize: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ItemToAdd {
|
|
9
|
+
readonly content: string;
|
|
10
|
+
readonly timestamp: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface QueuedItemWeb extends ItemToAdd, WithBytesSize {
|
|
14
|
+
readonly id: number;
|
|
15
|
+
readonly key?: never;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface QueuedItemNative extends ItemToAdd, WithBytesSize {
|
|
19
|
+
readonly id?: never;
|
|
20
|
+
readonly key: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type QueuedItem = QueuedItemWeb | QueuedItemNative;
|
|
24
|
+
|
|
25
|
+
export interface AddItemWithAuthPropertiesWeb
|
|
26
|
+
extends ItemToAdd,
|
|
27
|
+
WithBytesSize {}
|
|
28
|
+
|
|
29
|
+
export interface AddItemWithAuthPropertiesNative
|
|
30
|
+
extends ItemToAdd,
|
|
31
|
+
WithBytesSize {
|
|
32
|
+
key: QueuedItemNative['key'];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface QueuedStorage {
|
|
36
|
+
add(
|
|
37
|
+
item: ItemToAdd,
|
|
38
|
+
options?: { dequeueBeforeEnqueue: boolean }
|
|
39
|
+
): Promise<void>;
|
|
40
|
+
peek(n?: number): Promise<QueuedItem[]>;
|
|
41
|
+
peekAll(): Promise<QueuedItem[]>;
|
|
42
|
+
delete(items: QueuedItem[]): Promise<void>;
|
|
43
|
+
clear(): Promise<void>;
|
|
44
|
+
isFull(maxBytesSizeInMiB: number): boolean;
|
|
45
|
+
}
|