(cacheKey: ProjectCacheKey, project: gdProject)
| 192 | } |
| 193 | |
| 194 | async put(cacheKey: ProjectCacheKey, project: gdProject): Promise<void> { |
| 195 | const database = await this._initializeDatabase(); |
| 196 | |
| 197 | return new Promise((resolve, reject) => { |
| 198 | try { |
| 199 | const transaction = database.transaction(objectStoreScope, 'readwrite'); |
| 200 | const key = ProjectCache._stringifyCacheKey(cacheKey); |
| 201 | transaction.oncomplete = event => { |
| 202 | resolve(); |
| 203 | }; |
| 204 | transaction.onerror = event => { |
| 205 | console.error('An error occurred while writing to indexedDB:', event); |
| 206 | reject(event); |
| 207 | }; |
| 208 | transaction.objectStore(objectStoreScope).put({ |
| 209 | [keyName]: key, |
| 210 | project: serializeToJSON(project), |
| 211 | createdAt: Date.now(), |
| 212 | }); |
| 213 | } catch (error) { |
| 214 | // An error might occur when opening the transaction (if the object store |
| 215 | // does not exist for instance). |
| 216 | console.error('An error occurred while writing to indexedDB:', error); |
| 217 | reject(error); |
| 218 | } |
| 219 | }); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | export default ProjectCache; |
nothing calls this directly
no test coverage detected