Skip to content

Commit

Permalink
Merge branch 'master' into docs-travis-gha
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn authored Nov 1, 2023
2 parents d61987d + 14a566f commit 236c467
Show file tree
Hide file tree
Showing 75 changed files with 442 additions and 447 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"no-tabs": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"object-shorthand": ["error", "properties"],
"semi": ["error", "always"],
"curly": ["error", "all"],
"space-unary-ops": ["error", {"words": true}],
Expand Down
2 changes: 1 addition & 1 deletion bin/build-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function buildModule(filepath) {
var file = (isBrowser ? 'lib/index-browser' : 'lib/index') +
(format === 'es' ? '.es.js' : '.js');
return bundle.write({
format: format,
format,
file: path.resolve(filepath, file)
}).then(function () {
console.log(' \u2713' + ' wrote ' +
Expand Down
6 changes: 3 additions & 3 deletions bin/build-pouchdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ function doRollup(input, browser, formatsToFiles) {
var start = process.hrtime();
return rollup.rollup({
input: addPath('pouchdb', input),
external: external,
external,
plugins: rollupPlugins({
mainFields: ["module"],
browser: browser
browser
})
}).then(function (bundle) {
return Promise.all(Object.keys(formatsToFiles).map(function (format) {
var fileOut = formatsToFiles[format];
return bundle.generate({format: format}).then(function (bundle) {
return bundle.generate({format}).then(function (bundle) {
if (DEV_MODE) {
var ms = Math.round(process.hrtime(start)[1] / 1000000);
console.log(' took ' + ms + ' ms to rollup ' +
Expand Down
13 changes: 0 additions & 13 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,6 @@ <h4>{{ page.sub_title}}</h4>
>
</a>
</div>
<div class="col-xs-4 col-md-2">
<a
href="https://saucelabs.com"
target="_blank"
rel="noopener noreferrer"
>
<img
class="icon"
src="{{ site.baseurl}}/static/img/friends/saucelabs.svg"
alt="Saucelabs"
/>
</a>
</div>

</div>

Expand Down
1 change: 0 additions & 1 deletion docs/manifest.appcache
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ https://fonts.gstatic.com/s/opensans/v10/k3k702ZOKiLJc3WVjuplzBampu5_7CjHW5spxoe
/static/img/friends/couchdb.svg
/static/img/friends/github.svg
/static/img/friends/leveldb.svg
/static/img/friends/saucelabs.svg
/static/img/friends/twitter.svg

/static/img/browser-logos/android_32x32.png
Expand Down
4 changes: 0 additions & 4 deletions docs/static/img/friends/saucelabs.svg

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ async function createView(sourceDB, viewName, mapFun, reduceFun, temporary, loca
db.auto_compaction = true;
const view = {
name: depDbName,
db: db,
sourceDB: sourceDB,
db,
sourceDB,
adapter: sourceDB.adapter,
mapFun: mapFun,
reduceFun: reduceFun
mapFun,
reduceFun
};

let lastSeqDoc;
Expand Down
14 changes: 7 additions & 7 deletions packages/node_modules/pouchdb-abstract-mapreduce/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
try {
fun(doc);
} catch (e) {
emitError(db, e, {fun: fun, doc: doc});
emitError(db, e, {fun, doc});
}
}

Expand All @@ -107,7 +107,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
try {
return {output : fun(keys, values, rereduce)};
} catch (e) {
emitError(db, e, {fun: fun, keys: keys, values: values, rereduce: rereduce});
emitError(db, e, {fun, keys, values, rereduce});
return {error: e};
}
}
Expand Down Expand Up @@ -285,7 +285,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {

const response = await db.fetch('_design/' + parts[0] + '/_view/' + parts[1] + params, {
headers: new Headers({'Content-Type': 'application/json'}),
method: method,
method,
body: JSON.stringify(body)
});
ok = response.ok;
Expand Down Expand Up @@ -555,7 +555,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
let indexed_docs = 0;
const progress = {
view: view.name,
indexed_docs: indexed_docs
indexed_docs
};
view.sourceDB.emit('indexing', progress);

Expand Down Expand Up @@ -651,7 +651,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
view: view.name,
last_seq: response.last_seq,
results_count: results.length,
indexed_docs: indexed_docs
indexed_docs
};
view.sourceDB.emit('indexing', progress);
view.sourceDB.activeTasks.update(taskId, {completed_items: indexed_docs});
Expand Down Expand Up @@ -741,7 +741,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
groups.push({
keys: [[e.key, e.id]],
values: [e.value],
groupKey: groupKey
groupKey
});
});
results = [];
Expand Down Expand Up @@ -816,7 +816,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
finalResults = {
total_rows: totalRows,
offset: skip,
rows: rows
rows
};
} else {
// support limit, skip for keys query
Expand Down
4 changes: 2 additions & 2 deletions packages/node_modules/pouchdb-adapter-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ function HttpPouch(opts, callback) {

try {
const result = await fetchJSON(genDBUrl(host, '_all_docs' + paramStr), {
method: method,
method,
body: JSON.stringify(body)
});
if (opts.include_docs && opts.attachments && opts.binary) {
Expand Down Expand Up @@ -989,7 +989,7 @@ function HttpPouch(opts, callback) {
const url = genDBUrl(host, '_changes' + paramsToStr(params));
const fetchOpts = {
signal: controller.signal,
method: method,
method,
body: JSON.stringify(body)
};
lastFetchedSeq = since;
Expand Down
2 changes: 1 addition & 1 deletion packages/node_modules/pouchdb-adapter-idb/src/allDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function allDocsKeys(keys, docStore, onBatch) {
if (event.target.result) {
valuesBatch[index] = event.target.result;
} else {
valuesBatch[index] = {key: key, error: 'not_found'};
valuesBatch[index] = {key, error: 'not_found'};
}
count++;
if (count === keys.length) {
Expand Down
4 changes: 2 additions & 2 deletions packages/node_modules/pouchdb-adapter-idb/src/bulkDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) {
function add(att) {
var digest = docInfo.data._attachments[att].digest;
var req = attachAndSeqStore.put({
seq: seq,
seq,
digestSeq: digest + '::' + seq
});

Expand Down Expand Up @@ -390,7 +390,7 @@ function idbBulkDocs(dbOpts, req, opts, api, idb, callback) {
return callback(); // already exists
}
var newAtt = {
digest: digest,
digest,
body: data
};
var putReq = attachStore.put(newAtt);
Expand Down
2 changes: 1 addition & 1 deletion packages/node_modules/pouchdb-adapter-idb/src/changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function changes(opts, api, dbName, idb) {

function finish() {
opts.complete(null, {
results: results,
results,
last_seq: lastSeq
});
}
Expand Down
12 changes: 6 additions & 6 deletions packages/node_modules/pouchdb-adapter-idb/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function init(api, opts, callback) {
for (j = 0; j < digests.length; j++) {
var digest = digests[j];
attAndSeqStore.put({
seq: seq,
seq,
digestSeq: digest + '::' + seq
});
}
Expand Down Expand Up @@ -332,7 +332,7 @@ function init(api, opts, callback) {
}

function finish() {
callback(err, {doc: doc, metadata: metadata, ctx: txn});
callback(err, {doc, metadata, ctx: txn});
}

txn.objectStore(DOC_STORE).get(id).onsuccess = function (e) {
Expand Down Expand Up @@ -614,7 +614,7 @@ function init(api, opts, callback) {
callback(createError(MISSING_DOC));
} else {
oStore.delete(id);
ret = {ok: true, id: id, rev: '0-0'};
ret = {ok: true, id, rev: '0-0'};
if (opts.ctx) { // return immediately
callback(null, ret);
}
Expand Down Expand Up @@ -737,12 +737,12 @@ function init(api, opts, callback) {
}
api._meta = {
name: dbName,
instanceId: instanceId,
blobSupport: blobSupport
instanceId,
blobSupport
};

cachedDBs.set(dbName, {
idb: idb,
idb,
global: api._meta
});
callback(null, api);
Expand Down
6 changes: 3 additions & 3 deletions packages/node_modules/pouchdb-adapter-idb/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function idbError(callback) {
function encodeMetadata(metadata, winningRev, deleted) {
return {
data: safeJsonStringify(metadata),
winningRev: winningRev,
winningRev,
deletedOrLocal: deleted ? '1' : '0',
seq: metadata.seq, // highest seq for this doc
id: metadata.id
Expand Down Expand Up @@ -72,7 +72,7 @@ function decodeDoc(doc) {
function readBlobData(body, type, asBlob, callback) {
if (asBlob) {
if (!body) {
callback(createBlob([''], {type: type}));
callback(createBlob([''], {type}));
} else if (typeof body !== 'string') { // we have blob support
callback(body);
} else { // no blob support
Expand Down Expand Up @@ -143,7 +143,7 @@ function postProcessAttachments(results, asBlob) {
readBlobData(body, type, asBlob, function (data) {
row.doc._attachments[att] = Object.assign(
pick(attObj, ['digest', 'content_type']),
{data: data}
{data}
);
resolve();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function allDocsKeys(keys, docStore, allDocsInner) {
if (event.target.result) {
valuesBatch[index] = event.target.result;
} else {
valuesBatch[index] = {key: key, error: 'not_found'};
valuesBatch[index] = {key, error: 'not_found'};
}
count++;
if (count === keys.length) {
Expand Down
17 changes: 4 additions & 13 deletions packages/node_modules/pouchdb-adapter-indexeddb/src/bulkDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ export default function (api, req, opts, metadata, dbOpts, idbChanges, callback)
return doc.rev_tree[0].ids[1].status === 'missing';
}

function parseBase64(data) {
try {
return atob(data);
} catch (e) {
return {
error: createError(BAD_ARG, 'Attachment is not a valid base64 string')
};
}
}

// Reads the original doc from the store if available
// As in allDocs with keys option using multiple get calls is the fastest way
function fetchExistingDocs(txn, docs) {
Expand Down Expand Up @@ -327,9 +317,10 @@ export default function (api, req, opts, metadata, dbOpts, idbChanges, callback)

var binData;
if (typeof attachment.data === 'string') {
binData = parseBase64(attachment.data);
if (binData.error) {
return Promise.reject(binData.error);
try {
binData = atob(attachment.data);
} catch (e) {
return Promise.reject(createError(BAD_ARG, 'Attachment is not a valid base64 string'));
}
attachment.data = binStringToBlobOrBuffer(binData, attachment.content_type);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function (txn, idbChanges, api, dbOpts, opts) {
function onTxnComplete() {
Promise.all(processing).then(function () {
opts.complete(null, {
results: results,
results,
last_seq: lastSeq
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function query(idb, signature, opts, fallback) {

if (!cursor || limit === 0) {
return resolve({
rows: rows
rows
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var IDB_NULL = Number.MIN_SAFE_INTEGER;
var IDB_FALSE = Number.MIN_SAFE_INTEGER + 1;
var IDB_TRUE = Number.MIN_SAFE_INTEGER + 2;

// These are the same as bellow but without the global flag
// These are the same as below but without the global flag
// we want to use RegExp.test because it's really fast, but the global flag
// makes the regex const stateful (seriously) as it walked through all instances
var TEST_KEY_INVALID = /^[^a-zA-Z_$]|[^a-zA-Z0-9_$]+/;
Expand Down
20 changes: 13 additions & 7 deletions packages/node_modules/pouchdb-adapter-indexeddb/src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function upgradePouchDbSchema(db, pouchdbVersion) {
}

function openDatabase(openDatabases, api, opts, resolve, reject) {
var openReq = opts.versionchanged ?
var openReq = opts.versionChangedWhileOpen ?
indexedDB.open(opts.name) :
indexedDB.open(opts.name, createIdbVersion());

Expand Down Expand Up @@ -147,24 +147,30 @@ function openDatabase(openDatabases, api, opts, resolve, reject) {
idb.close();
};

// In IndexedDB you can only change the version, and thus the schema, when you are opening the database.
// versionChangedWhileOpen means that something else outside of our control has likely updated the version.
// One way this could happen is if you open multiple tabs, as the version number changes each time the database is opened.
// If we suspect this we close the db and tag it, so that next time it's accessed it reopens the DB with the current version
// as opposed to upping the version again
// This avoids infinite loops of version updates if you have multiple tabs open
idb.onversionchange = function () {
console.log('Database was made stale, closing handle');
openDatabases[opts.name].versionchanged = true;
openDatabases[opts.name].versionChangedWhileOpen = true;
idb.close();
};

idb.onclose = function () {
console.log('Database was made stale, closing handle');
if (opts.name in openDatabases) {
openDatabases[opts.name].versionchanged = true;
openDatabases[opts.name].versionChangedWhileOpen = true;
}
};

var metadata = {id: META_STORE};
var txn = idb.transaction([META_STORE], 'readwrite');

txn.oncomplete = function () {
resolve({idb: idb, metadata: metadata});
resolve({idb, metadata});
};

var metaStore = txn.objectStore(META_STORE);
Expand Down Expand Up @@ -199,9 +205,9 @@ function openDatabase(openDatabases, api, opts, resolve, reject) {
}

export default function (openDatabases, api, opts) {
if (!openDatabases[opts.name] || openDatabases[opts.name].versionchanged) {
opts.versionchanged = openDatabases[opts.name] &&
openDatabases[opts.name].versionchanged;
if (!openDatabases[opts.name] || openDatabases[opts.name].versionChangedWhileOpen) {
opts.versionChangedWhileOpen = openDatabases[opts.name] &&
openDatabases[opts.name].versionChangedWhileOpen;

openDatabases[opts.name] = new Promise(function (resolve, reject) {
openDatabase(openDatabases, api, opts, resolve, reject);
Expand Down
Loading

0 comments on commit 236c467

Please sign in to comment.