(values: T)
| 98 | } |
| 99 | |
| 100 | function prepareSyncStorage<T extends {[key: string]: any}>(values: T): {[key: string]: any} { |
| 101 | for (const key in values) { |
| 102 | const value = values[key]; |
| 103 | const string = JSON.stringify(value); |
| 104 | // The maximum size of any one item that each extension is allowed to store in the sync storage area, |
| 105 | // as measured by the JSON stringification of the item's value plus the length of its key. |
| 106 | // Source: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync |
| 107 | const totalLength = string.length + key.length; |
| 108 | if (totalLength > chrome.storage.sync.QUOTA_BYTES_PER_ITEM) { |
| 109 | // This length limit permits us to store up to 1000 = (parseInt('rr', 36) + 1) records. |
| 110 | const maxLength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - key.length - 1 - 2; |
| 111 | const minimalKeysNeeded = Math.ceil(string.length / maxLength); |
| 112 | for (let i = 0; i < minimalKeysNeeded; i++) { |
| 113 | (values as any)[`${key}_${i.toString(36)}`] = string.substring(i * maxLength, (i + 1) * maxLength); |
| 114 | } |
| 115 | (values as any)[key] = { |
| 116 | __meta_split_count: minimalKeysNeeded, |
| 117 | }; |
| 118 | } |
| 119 | } |
| 120 | return values; |
| 121 | } |
| 122 | |
| 123 | export async function writeSyncStorage<T extends {[key: string]: any}>(values: T): Promise<void> { |
| 124 | return new Promise<void>((resolve, reject) => { |
no outgoing calls
no test coverage detected
searching dependent graphs…