@iflix/events-receiver-client
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.0-beta.2
@@ -7,2 +7,4 @@ import { Event } from '../types'; | ||
lockKey: LockKey; | ||
eventKeys: IDBKeyRange; | ||
lockKeys: IDBKeyRange; | ||
constructor(); | ||
@@ -9,0 +11,0 @@ queue(event: Event): Promise<void>; |
@@ -11,5 +11,3 @@ "use strict"; | ||
const EVENT_KEY_PREFIX = 'event!'; | ||
const EVENT_KEYS = IDBKeyRange.bound(EVENT_KEY_PREFIX, EVENT_KEY_PREFIX + '\uffff', false, false); | ||
const LOCK_KEY_PREFIX = 'lock!'; | ||
const LOCK_KEYS = IDBKeyRange.bound(LOCK_KEY_PREFIX, LOCK_KEY_PREFIX + '\uffff', false, false); | ||
function generateKey(event) { | ||
@@ -46,2 +44,5 @@ return `${EVENT_KEY_PREFIX}${event.timestamp}!${event.guid}`; | ||
this.lockKey = `${LOCK_KEY_PREFIX}${v4_1.default()}`; | ||
// These can't just be global constants because we may not have access to IDBKeyRange (on Node, for example) | ||
this.eventKeys = IDBKeyRange.bound(EVENT_KEY_PREFIX, EVENT_KEY_PREFIX + '\uffff', false, false); | ||
this.lockKeys = IDBKeyRange.bound(LOCK_KEY_PREFIX, LOCK_KEY_PREFIX + '\uffff', false, false); | ||
} | ||
@@ -52,3 +53,3 @@ async queue(event) { | ||
async peek(count) { | ||
return this.db.getAll(EVENT_KEYS, count); | ||
return this.db.getAll(this.eventKeys, count); | ||
} | ||
@@ -59,3 +60,3 @@ async dequeue(events) { | ||
async lock(durationMs) { | ||
const existingLocks = await this.db.getAll(LOCK_KEYS); | ||
const existingLocks = await this.db.getAll(this.lockKeys); | ||
const existingLock = winningLock(existingLocks); | ||
@@ -71,3 +72,3 @@ if (existingLock === this.lockKey) { | ||
await this.db.put(makeLock(this.lockKey, durationMs), this.lockKey); | ||
const locks = await this.db.getAll(LOCK_KEYS); | ||
const locks = await this.db.getAll(this.lockKeys); | ||
const winning = winningLock(locks); | ||
@@ -83,3 +84,3 @@ if (winning === this.lockKey) { | ||
async unlock() { | ||
const locks = await this.db.getAll(LOCK_KEYS); | ||
const locks = await this.db.getAll(this.lockKeys); | ||
if (winningLock(locks) !== this.lockKey) { | ||
@@ -86,0 +87,0 @@ console.warn(` (${this.lockKey}) unlocking but we weren't in charge`); |
@@ -19,2 +19,3 @@ "use strict"; | ||
const MemBuffer_1 = require("./buffer/MemBuffer"); | ||
const idb_1 = require("./utils/idb"); | ||
__export(require("./types")); | ||
@@ -31,3 +32,3 @@ exports.getDeviceId = deviceId_1.createDeviceIdGetter(); | ||
function createBuffer() { | ||
if (typeof indexedDB !== 'undefined') { | ||
if (idb_1.idbAvailable()) { | ||
console.info('detected indexeddb'); | ||
@@ -34,0 +35,0 @@ return new IndexedDbBuffer_1.IndexedDbBuffer(); // TODO params |
declare type Transactor<T> = (store: IDBObjectStore) => T; | ||
export declare function idbAvailable(): boolean; | ||
export declare class IdbKv { | ||
@@ -3,0 +4,0 @@ db: Promise<IDBDatabase>; |
@@ -44,2 +44,6 @@ "use strict"; | ||
} | ||
function idbAvailable() { | ||
return typeof indexedDB !== 'undefined'; | ||
} | ||
exports.idbAvailable = idbAvailable; | ||
class IdbKv { | ||
@@ -46,0 +50,0 @@ constructor(dbName, storeName) { |
{ | ||
"name": "@iflix/events-receiver-client", | ||
"version": "1.0.0-beta.1", | ||
"version": "1.0.0-beta.2", | ||
"description": "Decodes (and encodes) user tokens", | ||
@@ -5,0 +5,0 @@ "main": "built/src/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
50842
830