Skip to content

Commit

Permalink
Revert "Remove build file, e2e docs from git"
Browse files Browse the repository at this point in the history
This reverts commit a2dd49c.
  • Loading branch information
hieu-w committed Jan 23, 2025
1 parent c3f6e31 commit 89b0c00
Show file tree
Hide file tree
Showing 78 changed files with 178,598 additions and 10,755 deletions.
1,320 changes: 1,320 additions & 0 deletions dist/broadcastChannel.cjs.js

Large diffs are not rendered by default.

1,200 changes: 1,200 additions & 0 deletions dist/broadcastChannel.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/broadcastChannel.umd.min.js

Large diffs are not rendered by default.

26 changes: 11 additions & 15 deletions dist/esbrowser/broadcast-channel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable promise/catch-or-return */
import { chooseMethod } from "./method-chooser.js";
import { fillOptionsWithDefaults } from "./options.js";
import { isPromise, PROMISE_RESOLVED_VOID } from "./util.js";
import { isPromise, PROMISE_RESOLVED_VOID } from './util.js';
import { chooseMethod } from './method-chooser.js';
import { fillOptionsWithDefaults } from './options.js';

/**
* Contains all open channels,
Expand Down Expand Up @@ -81,29 +80,29 @@ export function enforceOptions(options) {
BroadcastChannel.prototype = {
postMessage: function postMessage(msg) {
if (this.closed) {
throw new Error("BroadcastChannel.postMessage(): " + "Cannot post message after channel has closed " +
throw new Error('BroadcastChannel.postMessage(): ' + 'Cannot post message after channel has closed ' +
/**
* In the past when this error appeared, it was realy hard to debug.
* So now we log the msg together with the error so it at least
* gives some clue about where in your application this happens.
*/
JSON.stringify(msg));
}
return _post(this, "message", msg);
return _post(this, 'message', msg);
},
postInternal: function postInternal(msg) {
return _post(this, "internal", msg);
return _post(this, 'internal', msg);
},
set onmessage(fn) {
var time = this.method.microSeconds();
var listenObj = {
time: time,
fn: fn
};
_removeListenerObject(this, "message", this._onML);
if (fn && typeof fn === "function") {
_removeListenerObject(this, 'message', this._onML);
if (fn && typeof fn === 'function') {
this._onML = listenObj;
_addListenerObject(this, "message", listenObj);
_addListenerObject(this, 'message', listenObj);
} else {
this._onML = null;
}
Expand Down Expand Up @@ -145,7 +144,7 @@ BroadcastChannel.prototype = {
})
// close the channel
.then(function () {
return _this.method.close ? _this.method.close(_this._state) : Promise.resolve();
return _this.method.close(_this._state);
});
},
get type() {
Expand Down Expand Up @@ -173,7 +172,6 @@ function _post(broadcastChannel, type, msg) {

// add/remove to unsend messages list
broadcastChannel._uMP.add(sendPromise);
// eslint-disable-next-line promise/valid-params
sendPromise["catch"]().then(function () {
return broadcastChannel._uMP["delete"](sendPromise);
});
Expand All @@ -190,7 +188,6 @@ function _prepareChannel(channel) {
await new Promise(res => setTimeout(res, this.options.prepareDelay));
}*/
channel._state = s;
return;
});
} else {
channel._state = maybePromise;
Expand Down Expand Up @@ -231,7 +228,7 @@ function _startListening(channel) {

if (msgObj.time >= listenerObject.time) {
listenerObject.fn(msgObj.data);
} else if (channel.method.type === "server") {
} else if (channel.method.type === 'server') {
// server msg might lag based on connection.
listenerObject.fn(msgObj.data);
}
Expand All @@ -242,7 +239,6 @@ function _startListening(channel) {
channel._prepP.then(function () {
channel._iL = true;
channel.method.onMessage(channel._state, listenerFn, time);
return;
});
} else {
channel._iL = true;
Expand Down
6 changes: 3 additions & 3 deletions dist/esbrowser/index-umd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decode, encode, fromBase64, toBase64, toBuffer } from "base64url";
import { BroadcastChannel } from "./broadcast-channel";
if (typeof window !== "undefined") {
import { BroadcastChannel } from './broadcast-channel';
import { encode, decode, toBase64, fromBase64, toBuffer } from 'base64url';
if (typeof window !== 'undefined') {
window.broadcastChannelLib = {};
window.broadcastChannelLib.BroadcastChannel = BroadcastChannel;
window.base64urlLib = {};
Expand Down
14 changes: 7 additions & 7 deletions dist/esbrowser/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as IndexedDbMethod from "./methods/indexed-db";
import * as LocalstorageMethod from "./methods/localstorage";
import * as NativeMethod from "./methods/native";
import * as ServerMethod from "./methods/server";
export { BroadcastChannel, enforceOptions, OPEN_BROADCAST_CHANNELS } from "./broadcast-channel";
export * from "./method-chooser";
export { IndexedDbMethod, LocalstorageMethod, NativeMethod, ServerMethod };
import * as NativeMethod from './methods/native';
import * as IndexedDbMethod from './methods/indexed-db';
import * as LocalstorageMethod from './methods/localstorage';
import * as ServerMethod from './methods/server';
export { BroadcastChannel, enforceOptions, OPEN_BROADCAST_CHANNELS } from './broadcast-channel';
export * from './method-chooser';
export { NativeMethod, IndexedDbMethod, LocalstorageMethod, ServerMethod };
16 changes: 8 additions & 8 deletions dist/esbrowser/method-chooser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as IndexeDbMethod from "./methods/indexed-db.js";
import * as LocalstorageMethod from "./methods/localstorage.js";
import * as NativeMethod from "./methods/native.js";
import * as ServerMethod from "./methods/server.js";
import * as SimulateMethod from "./methods/simulate.js";
import * as NativeMethod from './methods/native.js';
import * as IndexeDbMethod from './methods/indexed-db.js';
import * as LocalstorageMethod from './methods/localstorage.js';
import * as ServerMethod from './methods/server.js';
import * as SimulateMethod from './methods/simulate.js';

// order is important
var METHODS = [NativeMethod,
Expand All @@ -13,14 +13,14 @@ export function chooseMethod(options) {

// directly chosen
if (options.type) {
if (options.type === "simulate") {
if (options.type === 'simulate') {
// only use simulate-method if directly chosen
return SimulateMethod;
}
var ret = chooseMethods.find(function (m) {
return m.type === options.type;
});
if (!ret) throw new Error("method-type " + options.type + " not found");else return ret;
if (!ret) throw new Error('method-type ' + options.type + ' not found');else return ret;
}

/**
Expand All @@ -29,7 +29,7 @@ export function chooseMethod(options) {
*/
if (!options.webWorkerSupport) {
chooseMethods = chooseMethods.filter(function (m) {
return m.type !== "idb";
return m.type !== 'idb';
});
}
var useMethod = chooseMethods.find(function (method) {
Expand Down
79 changes: 38 additions & 41 deletions dist/esbrowser/methods/indexed-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
* @link https://rxdb.info/slow-indexeddb.html
*/

import { microSeconds as micro, PROMISE_RESOLVED_VOID, randomInt, randomToken, sleep } from "../util.js";
import { sleep, randomInt, randomToken, microSeconds as micro, PROMISE_RESOLVED_VOID } from '../util.js';
export var microSeconds = micro;
import { ObliviousSet } from "oblivious-set";
import { fillOptionsWithDefaults } from "../options";
var DB_PREFIX = "pubkey.broadcast-channel-0-";
var OBJECT_STORE_ID = "messages";
import { ObliviousSet } from 'oblivious-set';
import { fillOptionsWithDefaults } from '../options';
var DB_PREFIX = 'pubkey.broadcast-channel-0-';
var OBJECT_STORE_ID = 'messages';

/**
* Use relaxed durability for faster performance on all transactions.
* @link https://nolanlawson.com/2021/08/22/speeding-up-indexeddb-reads-and-writes/
*/
export var TRANSACTION_SETTINGS = {
durability: "relaxed"
durability: 'relaxed'
};
export var type = "idb";
export var type = 'idb';
export function getIdb() {
if (typeof indexedDB !== "undefined") return indexedDB;
if (typeof window !== "undefined") {
if (typeof window.mozIndexedDB !== "undefined") return window.mozIndexedDB;
if (typeof window.webkitIndexedDB !== "undefined") return window.webkitIndexedDB;
if (typeof window.msIndexedDB !== "undefined") return window.msIndexedDB;
if (typeof indexedDB !== 'undefined') return indexedDB;
if (typeof window !== 'undefined') {
if (typeof window.mozIndexedDB !== 'undefined') return window.mozIndexedDB;
if (typeof window.webkitIndexedDB !== 'undefined') return window.webkitIndexedDB;
if (typeof window.msIndexedDB !== 'undefined') return window.msIndexedDB;
}
return false;
}
Expand Down Expand Up @@ -57,16 +57,16 @@ export function createDatabase(channelName) {
openRequest.onupgradeneeded = function (ev) {
var db = ev.target.result;
db.createObjectStore(OBJECT_STORE_ID, {
keyPath: "id",
keyPath: 'id',
autoIncrement: true
});
};
var dbPromise = new Promise(function (resolve, reject) {
var dbPromise = new Promise(function (res, rej) {
openRequest.onerror = function (ev) {
return reject(ev);
return rej(ev);
};
openRequest.onsuccess = function () {
resolve(openRequest.result);
res(openRequest.result);
};
});
return dbPromise;
Expand All @@ -83,24 +83,24 @@ export function writeMessage(db, readerUuid, messageJson) {
time: time,
data: messageJson
};
var tx = db.transaction([OBJECT_STORE_ID], "readwrite", TRANSACTION_SETTINGS);
return new Promise(function (resolve, reject) {
var tx = db.transaction([OBJECT_STORE_ID], 'readwrite', TRANSACTION_SETTINGS);
return new Promise(function (res, rej) {
tx.oncomplete = function () {
return resolve();
return res();
};
tx.onerror = function (ev) {
return reject(ev);
return rej(ev);
};
var objectStore = tx.objectStore(OBJECT_STORE_ID);
objectStore.add(writeObject);
commitIndexedDBTransaction(tx);
});
}
export function getAllMessages(db) {
var tx = db.transaction(OBJECT_STORE_ID, "readonly", TRANSACTION_SETTINGS);
var tx = db.transaction(OBJECT_STORE_ID, 'readonly', TRANSACTION_SETTINGS);
var objectStore = tx.objectStore(OBJECT_STORE_ID);
var ret = [];
return new Promise(function (resolve) {
return new Promise(function (res) {
objectStore.openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;
if (cursor) {
Expand All @@ -109,13 +109,13 @@ export function getAllMessages(db) {
cursor["continue"]();
} else {
commitIndexedDBTransaction(tx);
resolve(ret);
res(ret);
}
};
});
}
export function getMessagesHigherThan(db, lastCursorId) {
var tx = db.transaction(OBJECT_STORE_ID, "readonly", TRANSACTION_SETTINGS);
var tx = db.transaction(OBJECT_STORE_ID, 'readonly', TRANSACTION_SETTINGS);
var objectStore = tx.objectStore(OBJECT_STORE_ID);
var ret = [];
var keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
Expand All @@ -127,12 +127,12 @@ export function getMessagesHigherThan(db, lastCursorId) {
*/
if (objectStore.getAll) {
var getAllRequest = objectStore.getAll(keyRangeValue);
return new Promise(function (resolve, reject) {
return new Promise(function (res, rej) {
getAllRequest.onerror = function (err) {
return reject(err);
return rej(err);
};
getAllRequest.onsuccess = function (e) {
resolve(e.target.result);
res(e.target.result);
};
});
}
Expand All @@ -143,14 +143,14 @@ export function getMessagesHigherThan(db, lastCursorId) {
try {
keyRangeValue = IDBKeyRange.bound(lastCursorId + 1, Infinity);
return objectStore.openCursor(keyRangeValue);
} catch (_unused) {
} catch (e) {
return objectStore.openCursor();
}
}
return new Promise(function (resolve, reject) {
return new Promise(function (res, rej) {
var openCursorRequest = openCursor();
openCursorRequest.onerror = function (err) {
return reject(err);
return rej(err);
};
openCursorRequest.onsuccess = function (ev) {
var cursor = ev.target.result;
Expand All @@ -163,29 +163,29 @@ export function getMessagesHigherThan(db, lastCursorId) {
}
} else {
commitIndexedDBTransaction(tx);
resolve(ret);
res(ret);
}
};
});
}
export function removeMessagesById(db, ids) {
var tx = db.transaction([OBJECT_STORE_ID], "readwrite", TRANSACTION_SETTINGS);
var tx = db.transaction([OBJECT_STORE_ID], 'readwrite', TRANSACTION_SETTINGS);
var objectStore = tx.objectStore(OBJECT_STORE_ID);
return Promise.all(ids.map(function (id) {
var deleteRequest = objectStore["delete"](id);
return new Promise(function (resolve) {
return new Promise(function (res) {
deleteRequest.onsuccess = function () {
return resolve();
return res();
};
});
}));
}
export function getOldMessages(db, ttl) {
var olderThen = Date.now() - ttl;
var tx = db.transaction(OBJECT_STORE_ID, "readonly", TRANSACTION_SETTINGS);
var tx = db.transaction(OBJECT_STORE_ID, 'readonly', TRANSACTION_SETTINGS);
var objectStore = tx.objectStore(OBJECT_STORE_ID);
var ret = [];
return new Promise(function (resolve) {
return new Promise(function (res) {
objectStore.openCursor().onsuccess = function (ev) {
var cursor = ev.target.result;
if (cursor) {
Expand All @@ -197,11 +197,11 @@ export function getOldMessages(db, ttl) {
} else {
// no more old messages,
commitIndexedDBTransaction(tx);
resolve(ret);
res(ret);
return;
}
} else {
resolve(ret);
res(ret);
}
};
});
Expand Down Expand Up @@ -258,8 +258,6 @@ export function create(channelName, options) {
}
function _readLoop(state) {
if (state.closed) return;

// eslint-disable-next-line promise/catch-or-return
readNewMessages(state).then(function () {
return sleep(state.options.idb.fallbackInterval);
}).then(function () {
Expand Down Expand Up @@ -317,7 +315,6 @@ export function postMessage(channelState, messageJson) {
channelState.writeBlockPromise = channelState.writeBlockPromise.then(function () {
return writeMessage(channelState.db, channelState.uuid, messageJson);
}).then(function () {
// eslint-disable-next-line promise/always-return
if (randomInt(0, 10) === 0) {
/* await (do not await) */
cleanOldMessages(channelState.db, channelState.options.idb.ttl);
Expand Down
Loading

0 comments on commit 89b0c00

Please sign in to comment.