pouchdb-adapter-idb
Advanced tools
Comparing version 8.0.1 to 9.0.0
@@ -1,8 +0,7 @@ | ||
import { preprocessAttachments, processDocs, isLocalId, parseDoc } from 'pouchdb-adapter-utils'; | ||
import { safeJsonParse, safeJsonStringify } from 'pouchdb-json'; | ||
import { btoa, readAsBinaryString, base64StringToBlobOrBuffer, blob } from 'pouchdb-binary-utils'; | ||
import { compactTree, collectConflicts, isDeleted, isLocalId as isLocalId$1, traverseRevTree, winningRev, latest } from 'pouchdb-merge'; | ||
import { btoa, readAsBinaryString, base64StringToBlobOrBuffer, blob } from 'pouchdb-binary-utils'; | ||
import { preprocessAttachments, processDocs, isLocalId, parseDoc, checkBlobSupport } from 'pouchdb-adapter-utils'; | ||
import { createError, IDB_ERROR, MISSING_STUB, MISSING_DOC, REV_CONFLICT } from 'pouchdb-errors'; | ||
import { Map, Set } from 'pouchdb-collections'; | ||
import { assign, pick, changesHandler, nextTick, clone, filterChange, uuid, guardedConsole, toPromise, hasLocalStorage } from 'pouchdb-utils'; | ||
import { pick, changesHandler, nextTick, clone, filterChange, uuid, guardedConsole, toPromise, hasLocalStorage } from 'pouchdb-utils'; | ||
@@ -91,3 +90,3 @@ // IndexedDB requires a versioned database structure, so we use the | ||
if (!body) { | ||
callback(blob([''], {type: type})); | ||
callback(blob([''], {type})); | ||
} else if (typeof body !== 'string') { // we have blob support | ||
@@ -161,5 +160,5 @@ callback(body); | ||
readBlobData(body, type, asBlob, function (data) { | ||
row.doc._attachments[att] = assign( | ||
row.doc._attachments[att] = Object.assign( | ||
pick(attObj, ['digest', 'content_type']), | ||
{data: data} | ||
{data} | ||
); | ||
@@ -581,3 +580,3 @@ resolve(); | ||
var req = attachAndSeqStore.put({ | ||
seq: seq, | ||
seq, | ||
digestSeq: digest + '::' + seq | ||
@@ -611,3 +610,3 @@ }); | ||
var newAtt = { | ||
digest: digest, | ||
digest, | ||
body: data | ||
@@ -732,3 +731,3 @@ }; | ||
function allDocsKeys(keys, docStore, onBatch) { | ||
// It's not guaranted to be returned in right order | ||
// It's not guaranteed to be returned in right order | ||
var valuesBatch = new Array(keys.length); | ||
@@ -741,3 +740,3 @@ var count = 0; | ||
} else { | ||
valuesBatch[index] = {key: key, error: 'not_found'}; | ||
valuesBatch[index] = {key, error: 'not_found'}; | ||
} | ||
@@ -785,3 +784,3 @@ count++; | ||
var key = 'key' in opts ? opts.key : false; | ||
var keys = 'keys' in opts ? opts.keys : false; | ||
var keys = 'keys' in opts ? opts.keys : false; | ||
var skip = opts.skip || 0; | ||
@@ -791,3 +790,3 @@ var limit = typeof opts.limit === 'number' ? opts.limit : -1; | ||
var keyRange ; | ||
var keyRange ; | ||
var keyRangeError; | ||
@@ -797,3 +796,3 @@ if (!keys) { | ||
keyRangeError = keyRange && keyRange.error; | ||
if (keyRangeError && | ||
if (keyRangeError && | ||
!(keyRangeError.name === "DataError" && keyRangeError.code === 0)) { | ||
@@ -833,23 +832,9 @@ // DataError with error code 0 indicates start is less than end, so | ||
if (opts.update_seq) { | ||
getMaxUpdateSeq(seqStore, function (e) { | ||
if (e.target.result && e.target.result.length > 0) { | ||
updateSeq = e.target.result[0]; | ||
} | ||
}); | ||
} | ||
function getMaxUpdateSeq(objectStore, onSuccess) { | ||
function onCursor(e) { | ||
// get max updateSeq | ||
seqStore.openKeyCursor(null, 'prev').onsuccess = e => { | ||
var cursor = e.target.result; | ||
var maxKey = undefined; | ||
if (cursor && cursor.key) { | ||
maxKey = cursor.key; | ||
} | ||
return onSuccess({ | ||
target: { | ||
result: [maxKey] | ||
} | ||
}); | ||
} | ||
objectStore.openCursor(null, 'prev').onsuccess = onCursor; | ||
updateSeq = cursor.key; | ||
} | ||
}; | ||
} | ||
@@ -938,3 +923,3 @@ | ||
}; | ||
/* istanbul ignore if */ | ||
@@ -960,3 +945,3 @@ if (opts.update_seq && updateSeq !== undefined) { | ||
if (keys) { | ||
return allDocsKeys(opts.keys, docStore, onBatch); | ||
return allDocsKeys(keys, docStore, onBatch); | ||
} | ||
@@ -971,40 +956,2 @@ if (limit === -1) { // just fetch everything | ||
// | ||
// Blobs are not supported in all versions of IndexedDB, notably | ||
// Chrome <37 and Android <5. In those versions, storing a blob will throw. | ||
// | ||
// Various other blob bugs exist in Chrome v37-42 (inclusive). | ||
// Detecting them is expensive and confusing to users, and Chrome 37-42 | ||
// is at very low usage worldwide, so we do a hacky userAgent check instead. | ||
// | ||
// content-type bug: https://code.google.com/p/chromium/issues/detail?id=408120 | ||
// 404 bug: https://code.google.com/p/chromium/issues/detail?id=447916 | ||
// FileReader bug: https://code.google.com/p/chromium/issues/detail?id=447836 | ||
// | ||
function checkBlobSupport(txn) { | ||
return new Promise(function (resolve) { | ||
var blob$$1 = blob(['']); | ||
var req = txn.objectStore(DETECT_BLOB_SUPPORT_STORE).put(blob$$1, 'key'); | ||
req.onsuccess = function () { | ||
var matchedChrome = navigator.userAgent.match(/Chrome\/(\d+)/); | ||
var matchedEdge = navigator.userAgent.match(/Edge\//); | ||
// MS Edge pretends to be Chrome 42: | ||
// https://msdn.microsoft.com/en-us/library/hh869301%28v=vs.85%29.aspx | ||
resolve(matchedEdge || !matchedChrome || | ||
parseInt(matchedChrome[1], 10) >= 43); | ||
}; | ||
req.onerror = txn.onabort = function (e) { | ||
// If the transaction aborts now its due to not being able to | ||
// write to the database, likely due to the disk being full | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
resolve(false); | ||
}; | ||
}).catch(function () { | ||
return false; // error, so assume unsupported | ||
}); | ||
} | ||
function countDocs(txn, cb) { | ||
@@ -1209,3 +1156,3 @@ var index = txn.objectStore(DOC_STORE).index('deletedOrLocal'); | ||
opts.complete(null, { | ||
results: results, | ||
results, | ||
last_seq: lastSeq | ||
@@ -1416,3 +1363,3 @@ }); | ||
attAndSeqStore.put({ | ||
seq: seq, | ||
seq, | ||
digestSeq: digest + '::' + seq | ||
@@ -1530,3 +1477,3 @@ }); | ||
function finish() { | ||
callback(err, {doc: doc, metadata: metadata, ctx: txn}); | ||
callback(err, {doc, metadata, ctx: txn}); | ||
} | ||
@@ -1610,3 +1557,3 @@ | ||
}; | ||
txn.objectStore(BY_SEQ_STORE).openCursor(null, 'prev').onsuccess = function (e) { | ||
txn.objectStore(BY_SEQ_STORE).openKeyCursor(null, 'prev').onsuccess = function (e) { | ||
var cursor = e.target.result; | ||
@@ -1814,3 +1761,3 @@ updateSeq = cursor ? cursor.key : 0; | ||
oStore.delete(id); | ||
ret = {ok: true, id: id, rev: '0-0'}; | ||
ret = {ok: true, id, rev: '0-0'}; | ||
if (opts.ctx) { // return immediately | ||
@@ -1938,8 +1885,8 @@ callback(null, ret); | ||
name: dbName, | ||
instanceId: instanceId, | ||
blobSupport: blobSupport | ||
instanceId, | ||
blobSupport | ||
}; | ||
cachedDBs.set(dbName, { | ||
idb: idb, | ||
idb, | ||
global: api._meta | ||
@@ -1985,3 +1932,3 @@ }); | ||
// make sure blob support is only checked once | ||
blobSupportPromise = checkBlobSupport(txn); | ||
blobSupportPromise = checkBlobSupport(txn, DETECT_BLOB_SUPPORT_STORE, 'key'); | ||
} | ||
@@ -1988,0 +1935,0 @@ |
121
lib/index.js
'use strict'; | ||
var pouchdbAdapterUtils = require('pouchdb-adapter-utils'); | ||
var pouchdbJson = require('pouchdb-json'); | ||
var pouchdbBinaryUtils = require('pouchdb-binary-utils'); | ||
var pouchdbMerge = require('pouchdb-merge'); | ||
var pouchdbBinaryUtils = require('pouchdb-binary-utils'); | ||
var pouchdbAdapterUtils = require('pouchdb-adapter-utils'); | ||
var pouchdbErrors = require('pouchdb-errors'); | ||
var pouchdbCollections = require('pouchdb-collections'); | ||
var pouchdbUtils = require('pouchdb-utils'); | ||
@@ -56,3 +55,3 @@ | ||
data: pouchdbJson.safeJsonStringify(metadata), | ||
winningRev: winningRev, | ||
winningRev, | ||
deletedOrLocal: deleted ? '1' : '0', | ||
@@ -94,3 +93,3 @@ seq: metadata.seq, // highest seq for this doc | ||
if (!body) { | ||
callback(pouchdbBinaryUtils.blob([''], {type: type})); | ||
callback(pouchdbBinaryUtils.blob([''], {type})); | ||
} else if (typeof body !== 'string') { // we have blob support | ||
@@ -164,5 +163,5 @@ callback(body); | ||
readBlobData(body, type, asBlob, function (data) { | ||
row.doc._attachments[att] = pouchdbUtils.assign( | ||
row.doc._attachments[att] = Object.assign( | ||
pouchdbUtils.pick(attObj, ['digest', 'content_type']), | ||
{data: data} | ||
{data} | ||
); | ||
@@ -281,3 +280,3 @@ resolve(); | ||
var results = new Array(docInfos.length); | ||
var fetchedDocs = new pouchdbCollections.Map(); | ||
var fetchedDocs = new Map(); | ||
var preconditionErrored = false; | ||
@@ -585,3 +584,3 @@ var blobType = api._meta.blobSupport ? 'blob' : 'base64'; | ||
var req = attachAndSeqStore.put({ | ||
seq: seq, | ||
seq, | ||
digestSeq: digest + '::' + seq | ||
@@ -615,3 +614,3 @@ }); | ||
var newAtt = { | ||
digest: digest, | ||
digest, | ||
body: data | ||
@@ -736,3 +735,3 @@ }; | ||
function allDocsKeys(keys, docStore, onBatch) { | ||
// It's not guaranted to be returned in right order | ||
// It's not guaranteed to be returned in right order | ||
var valuesBatch = new Array(keys.length); | ||
@@ -745,3 +744,3 @@ var count = 0; | ||
} else { | ||
valuesBatch[index] = {key: key, error: 'not_found'}; | ||
valuesBatch[index] = {key, error: 'not_found'}; | ||
} | ||
@@ -789,3 +788,3 @@ count++; | ||
var key = 'key' in opts ? opts.key : false; | ||
var keys = 'keys' in opts ? opts.keys : false; | ||
var keys = 'keys' in opts ? opts.keys : false; | ||
var skip = opts.skip || 0; | ||
@@ -795,3 +794,3 @@ var limit = typeof opts.limit === 'number' ? opts.limit : -1; | ||
var keyRange ; | ||
var keyRange ; | ||
var keyRangeError; | ||
@@ -801,3 +800,3 @@ if (!keys) { | ||
keyRangeError = keyRange && keyRange.error; | ||
if (keyRangeError && | ||
if (keyRangeError && | ||
!(keyRangeError.name === "DataError" && keyRangeError.code === 0)) { | ||
@@ -837,23 +836,9 @@ // DataError with error code 0 indicates start is less than end, so | ||
if (opts.update_seq) { | ||
getMaxUpdateSeq(seqStore, function (e) { | ||
if (e.target.result && e.target.result.length > 0) { | ||
updateSeq = e.target.result[0]; | ||
} | ||
}); | ||
} | ||
function getMaxUpdateSeq(objectStore, onSuccess) { | ||
function onCursor(e) { | ||
// get max updateSeq | ||
seqStore.openKeyCursor(null, 'prev').onsuccess = e => { | ||
var cursor = e.target.result; | ||
var maxKey = undefined; | ||
if (cursor && cursor.key) { | ||
maxKey = cursor.key; | ||
} | ||
return onSuccess({ | ||
target: { | ||
result: [maxKey] | ||
} | ||
}); | ||
} | ||
objectStore.openCursor(null, 'prev').onsuccess = onCursor; | ||
updateSeq = cursor.key; | ||
} | ||
}; | ||
} | ||
@@ -942,3 +927,3 @@ | ||
}; | ||
/* istanbul ignore if */ | ||
@@ -964,3 +949,3 @@ if (opts.update_seq && updateSeq !== undefined) { | ||
if (keys) { | ||
return allDocsKeys(opts.keys, docStore, onBatch); | ||
return allDocsKeys(keys, docStore, onBatch); | ||
} | ||
@@ -975,40 +960,2 @@ if (limit === -1) { // just fetch everything | ||
// | ||
// Blobs are not supported in all versions of IndexedDB, notably | ||
// Chrome <37 and Android <5. In those versions, storing a blob will throw. | ||
// | ||
// Various other blob bugs exist in Chrome v37-42 (inclusive). | ||
// Detecting them is expensive and confusing to users, and Chrome 37-42 | ||
// is at very low usage worldwide, so we do a hacky userAgent check instead. | ||
// | ||
// content-type bug: https://code.google.com/p/chromium/issues/detail?id=408120 | ||
// 404 bug: https://code.google.com/p/chromium/issues/detail?id=447916 | ||
// FileReader bug: https://code.google.com/p/chromium/issues/detail?id=447836 | ||
// | ||
function checkBlobSupport(txn) { | ||
return new Promise(function (resolve) { | ||
var blob = pouchdbBinaryUtils.blob(['']); | ||
var req = txn.objectStore(DETECT_BLOB_SUPPORT_STORE).put(blob, 'key'); | ||
req.onsuccess = function () { | ||
var matchedChrome = navigator.userAgent.match(/Chrome\/(\d+)/); | ||
var matchedEdge = navigator.userAgent.match(/Edge\//); | ||
// MS Edge pretends to be Chrome 42: | ||
// https://msdn.microsoft.com/en-us/library/hh869301%28v=vs.85%29.aspx | ||
resolve(matchedEdge || !matchedChrome || | ||
parseInt(matchedChrome[1], 10) >= 43); | ||
}; | ||
req.onerror = txn.onabort = function (e) { | ||
// If the transaction aborts now its due to not being able to | ||
// write to the database, likely due to the disk being full | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
resolve(false); | ||
}; | ||
}).catch(function () { | ||
return false; // error, so assume unsupported | ||
}); | ||
} | ||
function countDocs(txn, cb) { | ||
@@ -1072,3 +1019,3 @@ var index = txn.objectStore(DOC_STORE).index('deletedOrLocal'); | ||
var docIds = opts.doc_ids && new pouchdbCollections.Set(opts.doc_ids); | ||
var docIds = opts.doc_ids && new Set(opts.doc_ids); | ||
@@ -1086,3 +1033,3 @@ opts.since = opts.since || 0; | ||
var filter = pouchdbUtils.filterChange(opts); | ||
var docIdsToMetadata = new pouchdbCollections.Map(); | ||
var docIdsToMetadata = new Map(); | ||
@@ -1215,3 +1162,3 @@ var txn; | ||
opts.complete(null, { | ||
results: results, | ||
results, | ||
last_seq: lastSeq | ||
@@ -1253,5 +1200,5 @@ }); | ||
var cachedDBs = new pouchdbCollections.Map(); | ||
var cachedDBs = new Map(); | ||
var blobSupportPromise; | ||
var openReqList = new pouchdbCollections.Map(); | ||
var openReqList = new Map(); | ||
@@ -1423,3 +1370,3 @@ function IdbPouch(opts, callback) { | ||
attAndSeqStore.put({ | ||
seq: seq, | ||
seq, | ||
digestSeq: digest + '::' + seq | ||
@@ -1537,3 +1484,3 @@ }); | ||
function finish() { | ||
callback(err, {doc: doc, metadata: metadata, ctx: txn}); | ||
callback(err, {doc, metadata, ctx: txn}); | ||
} | ||
@@ -1617,3 +1564,3 @@ | ||
}; | ||
txn.objectStore(BY_SEQ_STORE).openCursor(null, 'prev').onsuccess = function (e) { | ||
txn.objectStore(BY_SEQ_STORE).openKeyCursor(null, 'prev').onsuccess = function (e) { | ||
var cursor = e.target.result; | ||
@@ -1821,3 +1768,3 @@ updateSeq = cursor ? cursor.key : 0; | ||
oStore.delete(id); | ||
ret = {ok: true, id: id, rev: '0-0'}; | ||
ret = {ok: true, id, rev: '0-0'}; | ||
if (opts.ctx) { // return immediately | ||
@@ -1945,8 +1892,8 @@ callback(null, ret); | ||
name: dbName, | ||
instanceId: instanceId, | ||
blobSupport: blobSupport | ||
instanceId, | ||
blobSupport | ||
}; | ||
cachedDBs.set(dbName, { | ||
idb: idb, | ||
idb, | ||
global: api._meta | ||
@@ -1992,3 +1939,3 @@ }); | ||
// make sure blob support is only checked once | ||
blobSupportPromise = checkBlobSupport(txn); | ||
blobSupportPromise = pouchdbAdapterUtils.checkBlobSupport(txn, DETECT_BLOB_SUPPORT_STORE, 'key'); | ||
} | ||
@@ -1995,0 +1942,0 @@ |
{ | ||
"name": "pouchdb-adapter-idb", | ||
"version": "8.0.1", | ||
"version": "9.0.0", | ||
"description": "PouchDB adapter using IndexedDB as its data store.", | ||
@@ -14,18 +14,15 @@ "main": "./lib/index.js", | ||
}, | ||
"jsnext:main": "./lib/index.es.js", | ||
"module": "./lib/index.es.js", | ||
"dependencies": { | ||
"pouchdb-adapter-utils": "8.0.1", | ||
"pouchdb-binary-utils": "8.0.1", | ||
"pouchdb-collections": "8.0.1", | ||
"pouchdb-errors": "8.0.1", | ||
"pouchdb-json": "8.0.1", | ||
"pouchdb-merge": "8.0.1", | ||
"pouchdb-utils": "8.0.1" | ||
"pouchdb-adapter-utils": "9.0.0", | ||
"pouchdb-binary-utils": "9.0.0", | ||
"pouchdb-errors": "9.0.0", | ||
"pouchdb-json": "9.0.0", | ||
"pouchdb-merge": "9.0.0", | ||
"pouchdb-utils": "9.0.0" | ||
}, | ||
"module": "./lib/index.es.js", | ||
"files": [ | ||
"lib", | ||
"dist", | ||
"tonic-example.js" | ||
"dist" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6
123835
3441
+ Addedpouchdb-adapter-utils@9.0.0(transitive)
+ Addedpouchdb-binary-utils@9.0.0(transitive)
+ Addedpouchdb-errors@9.0.0(transitive)
+ Addedpouchdb-json@9.0.0(transitive)
+ Addedpouchdb-md5@9.0.0(transitive)
+ Addedpouchdb-merge@9.0.0(transitive)
+ Addedpouchdb-utils@9.0.0(transitive)
- Removedpouchdb-collections@8.0.1
- Removedbuffer-from@1.1.2(transitive)
- Removedclone-buffer@1.0.0(transitive)
- Removedimmediate@3.3.0(transitive)
- Removedpouchdb-adapter-utils@8.0.1(transitive)
- Removedpouchdb-binary-utils@8.0.1(transitive)
- Removedpouchdb-collections@8.0.1(transitive)
- Removedpouchdb-errors@8.0.1(transitive)
- Removedpouchdb-json@8.0.1(transitive)
- Removedpouchdb-md5@8.0.1(transitive)
- Removedpouchdb-merge@8.0.1(transitive)
- Removedpouchdb-utils@8.0.1(transitive)
Updatedpouchdb-adapter-utils@9.0.0
Updatedpouchdb-binary-utils@9.0.0
Updatedpouchdb-errors@9.0.0
Updatedpouchdb-json@9.0.0
Updatedpouchdb-merge@9.0.0
Updatedpouchdb-utils@9.0.0