| 74 | * @hidden |
| 75 | */ |
| 76 | export class IndexedDBRWTransaction extends IndexedDBROTransaction implements AsyncKeyValueRWTransaction, AsyncKeyValueROTransaction { |
| 77 | constructor(tx: IDBTransaction, store: IDBObjectStore) { |
| 78 | super(tx, store); |
| 79 | } |
| 80 | |
| 81 | public put(key: string, data: Buffer, overwrite: boolean, cb: BFSCallback<boolean>): void { |
| 82 | try { |
| 83 | const arraybuffer = buffer2ArrayBuffer(data); |
| 84 | let r: IDBRequest; |
| 85 | if (overwrite) { |
| 86 | r = this.store.put(arraybuffer, key); |
| 87 | } else { |
| 88 | // 'add' will never overwrite an existing key. |
| 89 | r = this.store.add(arraybuffer, key); |
| 90 | } |
| 91 | // XXX: NEED TO RETURN FALSE WHEN ADD HAS A KEY CONFLICT. NO ERROR. |
| 92 | r.onerror = onErrorHandler(cb); |
| 93 | r.onsuccess = (event) => { |
| 94 | cb(null, true); |
| 95 | }; |
| 96 | } catch (e) { |
| 97 | cb(convertError(e)); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | public del(key: string, cb: BFSOneArgCallback): void { |
| 102 | try { |
| 103 | // NOTE: IE8 has a bug with identifiers named 'delete' unless used as a string |
| 104 | // like this. |
| 105 | // http://stackoverflow.com/a/26479152 |
| 106 | const r: IDBRequest = this.store['delete'](key); |
| 107 | r.onerror = onErrorHandler(cb); |
| 108 | r.onsuccess = (event) => { |
| 109 | cb(); |
| 110 | }; |
| 111 | } catch (e) { |
| 112 | cb(convertError(e)); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | public commit(cb: BFSOneArgCallback): void { |
| 117 | // Return to the event loop to commit the transaction. |
| 118 | setTimeout(cb, 0); |
| 119 | } |
| 120 | |
| 121 | public abort(cb: BFSOneArgCallback): void { |
| 122 | let _e: ApiError | null = null; |
| 123 | try { |
| 124 | this.tx.abort(); |
| 125 | } catch (e) { |
| 126 | _e = convertError(e); |
| 127 | } finally { |
| 128 | cb(_e); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | export class IndexedDBStore implements AsyncKeyValueStore { |
nothing calls this directly
no outgoing calls
no test coverage detected