diff --git a/example/copy_packages.sh b/example/copy_packages.sh index bcac012..8ed3380 100644 --- a/example/copy_packages.sh +++ b/example/copy_packages.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash echo "Copy packages" -cp ../packages/pouchdb-adapter-leveldb-core-rn/src/*.* ./node_modules/pouchdb-adapter-leveldb-core-rn/src -cp ../packages/pouchdb-adapter-leveldb-core-rn/*.* ./node_modules/pouchdb-adapter-leveldb-core-rn -cp ../packages/pouchdb-adapter-asyncstorage/*.* ./node_modules/pouchdb-adapter-asyncstorage cp ../packages/pouchdb-react-native/*.* ./node_modules/pouchdb-react-native -cp ../packages/pouchdb-adapter-asyncstorage-pure/*.* ./node_modules/pouchdb-adapter-asyncstorage-pure -cp ../packages/pouchdb-adapter-asyncstorage-pure/src/*.* ./node_modules/pouchdb-adapter-asyncstorage-pure/src +cp ../packages/pouchdb-adapter-asyncstorage/*.* ./node_modules/pouchdb-adapter-asyncstorage +cp ../packages/pouchdb-adapter-asyncstorage/src/*.* ./node_modules/pouchdb-adapter-asyncstorage/src diff --git a/example/package.json b/example/package.json index ef64b7b..9d7580a 100644 --- a/example/package.json +++ b/example/package.json @@ -1,6 +1,6 @@ { "name": "example", - "version": "5.4.20", + "version": "5.5.0-beta-2", "author": "Christoph Stock (@stockulus)", "description": "small example app for pouchdb-react-native", "license": "MIT", @@ -18,8 +18,7 @@ "postinstall": "npm run copy-packages" }, "dependencies": { - "pouchdb-adapter-asyncstorage-pure": "5.4.20", - "pouchdb-react-native": "5.4.20", + "pouchdb-react-native": "5.5.0-beta-2", "react": "15.3.1", "react-native": "0.32.0", "react-native-action-button": "2.0.1" diff --git a/packages/pouchdb-adapter-asyncstorage-pure/package.json b/packages/pouchdb-adapter-asyncstorage-pure/package.json deleted file mode 100644 index b3ddbb7..0000000 --- a/packages/pouchdb-adapter-asyncstorage-pure/package.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "name": "pouchdb-adapter-asyncstorage-pure", - "version": "5.4.20", - "description": "asyncstorage adapter for PouchDB", - "main": "./src/index.js", - "repository": { - "type": "git", - "url": "git+https://github.com/stockulus/pouchdb-react-native.git" - }, - "keywords": [ - "pouchdb", - "react-native", - "asyncstorage", - "offlinefirst" - ], - "scripts": { - "updtr": "updtr --save-exact" - }, - "author": "Christoph Stock (@stockulus)", - "license": "MIT", - "bugs": { - "url": "https://github.com/stockulus/pouchdb-react-native/issues" - }, - "homepage": "https://github.com/stockulus/pouchdb-react-native#readme", - "dependencies": { - "atob": "2.0.3", - "blob-polyfill": "1.0.20150320", - "btoa": "1.1.2", - "buffer": "4.9.1", - "left-pad": "1.1.1", - "pouchdb-adapter-utils": "5.4.5", - "pouchdb-binary-utils": "5.4.5", - "pouchdb-errors": "5.4.5", - "pouchdb-md5": "5.4.5", - "pouchdb-merge": "5.4.5", - "pouchdb-utils": "5.4.5" - }, - "devDependencies": {}, - "peerDependencies": {}, - "standard": { - "ignore": [ - "node_modules/**" - ] - } -} diff --git a/packages/pouchdb-adapter-asyncstorage-pure/readme.md b/packages/pouchdb-adapter-asyncstorage-pure/readme.md deleted file mode 100644 index 0fafdd8..0000000 --- a/packages/pouchdb-adapter-asyncstorage-pure/readme.md +++ /dev/null @@ -1,31 +0,0 @@ -![Logo](https://raw.githubusercontent.com/stockulus/pouchdb-react-native/master/static/pouchdb-react-native.png) - -pouchdb-adapter-asyncstorage-pure -====== - -This is Work in Progress / Do not use now - -PouchDB adapter using AsyncStorage as its data store. Designed to run in ReactNative. Its adapter name is `'asyncstorage'`. - -[![bitHound Overall Score](https://www.bithound.io/github/stockulus/pouchdb-react-native/badges/score.svg)](https://www.bithound.io/github/stockulus/pouchdb-react-native) [![npm Package](https://img.shields.io/npm/dm/pouchdb-adapter-asyncstorage-pure.svg)](https://www.npmjs.com/package/pouchdb-adapter-asyncstorage-pure) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![license](https://img.shields.io/npm/l/pouchdb-adapter-asyncstorage-pure.svg?maxAge=2592000)](https://opensource.org/licenses/MIT) -### Usage - -```bash -npm install pouchdb-adapter-asyncstorage-pure --save -``` - -```js -import PouchDB from 'pouchdb-core' -PouchDB.plugin(require('pouchdb-adapter-asyncstorage').default) -const db = new PouchDB('mydb', {adapter: 'asyncstorage'}) - -// use PouchDB -db.get('4711') - .then(doc => console.log(doc)) - -``` - -For full API documentation and guides on PouchDB, see [PouchDB.com](http://pouchdb.com/). For details on PouchDB sub-packages, see the [Custom Builds documentation](http://pouchdb.com/custom.html). - ---- -[![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&maxAge=2592000)](https://twitter.com/stockulus) [![GitHub stars](https://img.shields.io/github/stars/stockulus/pouchdb-react-native.svg?style=social&label=Star)](https://github.com/stockulus/pouchdb-react-native) diff --git a/packages/pouchdb-adapter-asyncstorage/index.js b/packages/pouchdb-adapter-asyncstorage/index.js deleted file mode 100644 index 5228eaf..0000000 --- a/packages/pouchdb-adapter-asyncstorage/index.js +++ /dev/null @@ -1,20 +0,0 @@ -import './polyfill' - -import asyncstorageDown from 'asyncstorage-down' -import CoreLevelPouch from 'pouchdb-adapter-leveldb-core-rn' -import { extend } from 'js-extend' - -function AsyncStoragePouch (opts, callback) { - const _opts = extend({ - db: asyncstorageDown - }, opts) - - CoreLevelPouch.call(this, _opts, callback) -} - -AsyncStoragePouch.valid = () => true -AsyncStoragePouch.use_prefix = false - -export default function (PouchDB) { - PouchDB.adapter('asyncstorage', AsyncStoragePouch, true) -} diff --git a/packages/pouchdb-adapter-asyncstorage/package.json b/packages/pouchdb-adapter-asyncstorage/package.json index 6020b4b..0ac2444 100644 --- a/packages/pouchdb-adapter-asyncstorage/package.json +++ b/packages/pouchdb-adapter-asyncstorage/package.json @@ -1,8 +1,8 @@ { "name": "pouchdb-adapter-asyncstorage", - "version": "5.4.20", + "version": "5.5.0-beta-2", "description": "asyncstorage adapter for PouchDB", - "main": "index.js", + "main": "./src/index.js", "repository": { "type": "git", "url": "git+https://github.com/stockulus/pouchdb-react-native.git" @@ -23,26 +23,18 @@ }, "homepage": "https://github.com/stockulus/pouchdb-react-native#readme", "dependencies": { - "argsarray": "0.0.1", - "asyncstorage-down": "2.4.1", "atob": "2.0.3", "blob-polyfill": "1.0.20150320", "btoa": "1.1.2", "buffer": "4.9.1", - "core-util-is": "1.0.2", - "double-ended-queue": "2.1.0-0", "events": "1.1.1", - "fs": "0.0.2", - "inherits": "2.0.1", - "js-extend": "1.0.1", - "leveldown": "1.4.6", - "lie": "3.1.0", - "path": "0.12.7", - "pouchdb-adapter-leveldb-core-rn": "5.4.20", - "stream": "0.0.2", - "through2": "2.0.1", - "util": "0.10.3", - "vuvuzela": "1.0.3" + "left-pad": "1.1.1", + "pouchdb-adapter-utils": "5.4.5", + "pouchdb-binary-utils": "5.4.5", + "pouchdb-errors": "5.4.5", + "pouchdb-md5": "5.4.5", + "pouchdb-merge": "5.4.5", + "pouchdb-utils": "5.4.5" }, "devDependencies": {}, "peerDependencies": {}, diff --git a/packages/pouchdb-adapter-asyncstorage/polyfill.js b/packages/pouchdb-adapter-asyncstorage/polyfill.js deleted file mode 100644 index 05075e4..0000000 --- a/packages/pouchdb-adapter-asyncstorage/polyfill.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -global.Buffer = global.Buffer || require('buffer').Buffer -global.atob = global.atob || require('atob') -global.btoa = global.btoa || require('btoa') - -require('blob-polyfill') - -if (!process.version) process.version = 'v0.10' -process.nextTick = process.nextTick || setImmediate diff --git a/packages/pouchdb-adapter-asyncstorage/readme.md b/packages/pouchdb-adapter-asyncstorage/readme.md index 1d26c32..738dd71 100644 --- a/packages/pouchdb-adapter-asyncstorage/readme.md +++ b/packages/pouchdb-adapter-asyncstorage/readme.md @@ -5,8 +5,7 @@ pouchdb-adapter-asyncstorage PouchDB adapter using AsyncStorage as its data store. Designed to run in ReactNative. Its adapter name is `'asyncstorage'`. -[![bitHound Overall Score](https://www.bithound.io/github/stockulus/pouchdb-react-native/badges/score.svg)](https://www.bithound.io/github/stockulus/pouchdb-react-native) [![npm Package](https://img.shields.io/npm/dm/pouchdb-adapter-asyncstorage.svg)](https://www.npmjs.com/package/pouchdb-adapter-asyncstorage) [![travis-ci.org](https://travis-ci.org/stockulus/pouchdb-react-native.svg)](https://travis-ci.org/stockulus/pouchdb-react-native) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![license](https://img.shields.io/npm/l/pouchdb-adapter-asyncstorage.svg?maxAge=2592000)](https://opensource.org/licenses/MIT) - +[![bitHound Overall Score](https://www.bithound.io/github/stockulus/pouchdb-react-native/badges/score.svg)](https://www.bithound.io/github/stockulus/pouchdb-react-native) [![npm Package](https://img.shields.io/npm/dm/pouchdb-adapter-asyncstorage.svg)](https://www.npmjs.com/package/pouchdb-adapter-asyncstorage) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![license](https://img.shields.io/npm/l/pouchdb-adapter-asyncstorage.svg?maxAge=2592000)](https://opensource.org/licenses/MIT) ### Usage ```bash diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/all_docs.js b/packages/pouchdb-adapter-asyncstorage/src/all_docs.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/all_docs.js rename to packages/pouchdb-adapter-asyncstorage/src/all_docs.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/asyncstorage_core.js b/packages/pouchdb-adapter-asyncstorage/src/asyncstorage_core.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/asyncstorage_core.js rename to packages/pouchdb-adapter-asyncstorage/src/asyncstorage_core.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/bulk_docs.js b/packages/pouchdb-adapter-asyncstorage/src/bulk_docs.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/bulk_docs.js rename to packages/pouchdb-adapter-asyncstorage/src/bulk_docs.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/changes.js b/packages/pouchdb-adapter-asyncstorage/src/changes.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/changes.js rename to packages/pouchdb-adapter-asyncstorage/src/changes.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/databases.js b/packages/pouchdb-adapter-asyncstorage/src/databases.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/databases.js rename to packages/pouchdb-adapter-asyncstorage/src/databases.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/destroy.js b/packages/pouchdb-adapter-asyncstorage/src/destroy.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/destroy.js rename to packages/pouchdb-adapter-asyncstorage/src/destroy.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/do_compaction.js b/packages/pouchdb-adapter-asyncstorage/src/do_compaction.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/do_compaction.js rename to packages/pouchdb-adapter-asyncstorage/src/do_compaction.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/get.js b/packages/pouchdb-adapter-asyncstorage/src/get.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/get.js rename to packages/pouchdb-adapter-asyncstorage/src/get.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/get_attachment.js b/packages/pouchdb-adapter-asyncstorage/src/get_attachment.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/get_attachment.js rename to packages/pouchdb-adapter-asyncstorage/src/get_attachment.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/get_revision_tree.js b/packages/pouchdb-adapter-asyncstorage/src/get_revision_tree.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/get_revision_tree.js rename to packages/pouchdb-adapter-asyncstorage/src/get_revision_tree.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/index.js b/packages/pouchdb-adapter-asyncstorage/src/index.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/index.js rename to packages/pouchdb-adapter-asyncstorage/src/index.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/info.js b/packages/pouchdb-adapter-asyncstorage/src/info.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/info.js rename to packages/pouchdb-adapter-asyncstorage/src/info.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/keys.js b/packages/pouchdb-adapter-asyncstorage/src/keys.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/keys.js rename to packages/pouchdb-adapter-asyncstorage/src/keys.js diff --git a/packages/pouchdb-adapter-asyncstorage-pure/src/polyfill.js b/packages/pouchdb-adapter-asyncstorage/src/polyfill.js similarity index 100% rename from packages/pouchdb-adapter-asyncstorage-pure/src/polyfill.js rename to packages/pouchdb-adapter-asyncstorage/src/polyfill.js diff --git a/packages/pouchdb-adapter-leveldb-core-rn/LICENSE b/packages/pouchdb-adapter-leveldb-core-rn/LICENSE deleted file mode 100644 index f6cd2bc..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/packages/pouchdb-adapter-leveldb-core-rn/README.md b/packages/pouchdb-adapter-leveldb-core-rn/README.md deleted file mode 100644 index e991cb5..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/README.md +++ /dev/null @@ -1,24 +0,0 @@ -pouchdb-adapter-leveldb-core ![semver non-compliant](https://img.shields.io/badge/semver-non--compliant-red.svg) -====== - -Underlying adapter code for LevelDOWN-based PouchDB adapters (such as `pouchdb-adapter-leveldb`). Most likely you should not use this package unless you are trying to build your own PouchDB adapter based on a *DOWN database. - -### Usage - -```bash -npm install --save-exact pouchdb-adapter-leveldb-core -``` - -For full API documentation and guides on PouchDB, see [PouchDB.com](http://pouchdb.com/). For details on PouchDB sub-packages, see the [Custom Builds documentation](http://pouchdb.com/custom.html). - -### Warning: semver-free zone! - -This package is conceptually an internal API used by PouchDB or its plugins. It does not follow semantic versioning (semver), and rather its version is pegged to PouchDB's. Use exact versions when installing, e.g. with `--save-exact`. - -### Source - -PouchDB and its sub-packages are distributed as a [monorepo](https://github.com/babel/babel/blob/master/doc/design/monorepo.md). - -For a full list of packages, see [the GitHub source](https://github.com/pouchdb/pouchdb/tree/master/packages). - - diff --git a/packages/pouchdb-adapter-leveldb-core-rn/package.json b/packages/pouchdb-adapter-leveldb-core-rn/package.json deleted file mode 100644 index e888802..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "pouchdb-adapter-leveldb-core-rn", - "version": "5.4.20", - "description": "React Native Copy of Core PouchDB adapter code for LevelDOWN-based adapters", - "main": "./src/index.js", - "keywords": [], - "author": "Dale Harvey / Christoph Stock (@stockulus)", - "license": "Apache-2.0", - "repository": { - "type": "git", - "url": "git+https://github.com/stockulus/pouchdb-react-native.git" - }, - "files": [ - "src" - ], - "scripts": { - "updtr": "updtr --save-exact" - }, - "dependencies": { - "argsarray": "0.0.1", - "double-ended-queue": "2.1.0-0", - "level-write-stream": "1.0.0", - "levelup": "1.3.2", - "pouchdb-adapter-utils": "5.4.5", - "pouchdb-binary-utils": "5.4.5", - "pouchdb-collections": "1.0.1", - "pouchdb-errors": "5.4.5", - "pouchdb-json": "5.4.5", - "pouchdb-md5": "5.4.5", - "pouchdb-merge": "5.4.5", - "pouchdb-promise": "5.4.5", - "pouchdb-utils": "5.4.5", - "sublevel-pouchdb": "1.0.1", - "through2": "2.0.1" - } -} diff --git a/packages/pouchdb-adapter-leveldb-core-rn/src/createEmptyBlobOrBuffer-browser.js b/packages/pouchdb-adapter-leveldb-core-rn/src/createEmptyBlobOrBuffer-browser.js deleted file mode 100755 index 6a9791b..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/src/createEmptyBlobOrBuffer-browser.js +++ /dev/null @@ -1,7 +0,0 @@ -import { blob as createBlob } from 'pouchdb-binary-utils'; - -function createEmptyBlobOrBuffer(type) { - return createBlob([''], {type: type}); -} - -export default createEmptyBlobOrBuffer; \ No newline at end of file diff --git a/packages/pouchdb-adapter-leveldb-core-rn/src/createEmptyBlobOrBuffer.js b/packages/pouchdb-adapter-leveldb-core-rn/src/createEmptyBlobOrBuffer.js deleted file mode 100755 index cc1fce9..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/src/createEmptyBlobOrBuffer.js +++ /dev/null @@ -1,7 +0,0 @@ -import { typedBuffer } from 'pouchdb-binary-utils'; - -function createEmptyBlobOrBuffer(type) { - return typedBuffer('', 'binary', type); -} - -export default createEmptyBlobOrBuffer; \ No newline at end of file diff --git a/packages/pouchdb-adapter-leveldb-core-rn/src/index.js b/packages/pouchdb-adapter-leveldb-core-rn/src/index.js deleted file mode 100755 index fc94943..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/src/index.js +++ /dev/null @@ -1,1477 +0,0 @@ -import levelup from 'levelup'; -import sublevel from 'sublevel-pouchdb'; -import { obj as through } from 'through2'; -import getArguments from 'argsarray'; -import { Map, Set } from 'pouchdb-collections'; -import migrate from './migrate'; -import Deque from 'double-ended-queue'; -import Promise from 'pouchdb-promise'; -import { - clone, - changesHandler as Changes, - filterChange, - functionName, - uuid -} from 'pouchdb-utils'; -import { - isDeleted, - isLocalId, - parseDoc, - processDocs -} from 'pouchdb-adapter-utils'; -import { - winningRev as calculateWinningRev, - traverseRevTree, - compactTree, - collectConflicts -} from 'pouchdb-merge'; -import { - safeJsonParse, - safeJsonStringify -} from 'pouchdb-json'; - -import { - binaryMd5 -} from 'pouchdb-md5'; - -import { - atob, - binaryStringToBlobOrBuffer as binStringToBluffer -} from 'pouchdb-binary-utils'; - -import readAsBluffer from './readAsBlobOrBuffer'; -import prepareAttachmentForStorage from './prepareAttachmentForStorage'; -import createEmptyBluffer from './createEmptyBlobOrBuffer'; - -import LevelTransaction from './transaction'; - -import { - MISSING_DOC, - REV_CONFLICT, - NOT_OPEN, - BAD_ARG, - MISSING_STUB, - createError -} from 'pouchdb-errors'; - -var DOC_STORE = 'document-store'; -var BY_SEQ_STORE = 'by-sequence'; -var ATTACHMENT_STORE = 'attach-store'; -var BINARY_STORE = 'attach-binary-store'; -var LOCAL_STORE = 'local-store'; -var META_STORE = 'meta-store'; - -// leveldb barks if we try to open a db multiple times -// so we cache opened connections here for initstore() -var dbStores = new Map(); - -// store the value of update_seq in the by-sequence store the key name will -// never conflict, since the keys in the by-sequence store are integers -var UPDATE_SEQ_KEY = '_local_last_update_seq'; -var DOC_COUNT_KEY = '_local_doc_count'; -var UUID_KEY = '_local_uuid'; - -var MD5_PREFIX = 'md5-'; - -var safeJsonEncoding = { - encode: safeJsonStringify, - decode: safeJsonParse, - buffer: false, - type: 'cheap-json' -}; - -var levelChanges = new Changes(); - -// winningRev and deleted are performance-killers, but -// in newer versions of PouchDB, they are cached on the metadata -function getWinningRev(metadata) { - return 'winningRev' in metadata ? - metadata.winningRev : calculateWinningRev(metadata); -} - -function getIsDeleted(metadata, winningRev) { - return 'deleted' in metadata ? - metadata.deleted : isDeleted(metadata, winningRev); -} - -function fetchAttachment(att, stores, opts) { - var type = att.content_type; - return new Promise(function (resolve, reject) { - stores.binaryStore.get(att.digest, function (err, buffer) { - var data; - if (err) { - /* istanbul ignore if */ - if (err.name !== 'NotFoundError') { - return reject(err); - } else { - // empty - if (!opts.binary) { - data = ''; - } else { - data = binStringToBluffer('', type); - } - } - } else { // non-empty - if (opts.binary) { - data = readAsBluffer(buffer, type); - } else { - data = buffer.toString('base64'); - } - } - delete att.stub; - delete att.length; - att.data = data; - resolve(); - }); - }); -} - -function fetchAttachments(results, stores, opts) { - var atts = []; - results.forEach(function (row) { - if (!(row.doc && row.doc._attachments)) { - return; - } - var attNames = Object.keys(row.doc._attachments); - attNames.forEach(function (attName) { - var att = row.doc._attachments[attName]; - if (!('data' in att)) { - atts.push(att); - } - }); - }); - - return Promise.all(atts.map(function (att) { - return fetchAttachment(att, stores, opts); - })); -} - -function LevelPouch(opts, callback) { - opts = clone(opts); - var api = this; - var instanceId; - var stores = {}; - var revLimit = opts.revs_limit; - var db; - var name = opts.name; - // TODO: this is undocumented and unused probably - /* istanbul ignore else */ - if (typeof opts.createIfMissing === 'undefined') { - opts.createIfMissing = true; - } - - var leveldown = opts.db; - - var dbStore; - var leveldownName = functionName(leveldown); - if (dbStores.has(leveldownName)) { - dbStore = dbStores.get(leveldownName); - } else { - dbStore = new Map(); - dbStores.set(leveldownName, dbStore); - } - if (dbStore.has(name)) { - db = dbStore.get(name); - afterDBCreated(); - } else { - dbStore.set(name, sublevel(levelup(name, opts, function (err) { - /* istanbul ignore if */ - if (err) { - dbStore.delete(name); - return callback(err); - } - db = dbStore.get(name); - db._docCount = -1; - db._queue = new Deque(); - /* istanbul ignore else */ - if (opts.migrate) { // migration for leveldown - migrate.toSublevel(name, db, afterDBCreated); - } else { - afterDBCreated(); - } - }))); - } - - function afterDBCreated() { - stores.docStore = db.sublevel(DOC_STORE, {valueEncoding: safeJsonEncoding}); - stores.bySeqStore = db.sublevel(BY_SEQ_STORE, {valueEncoding: 'json'}); - stores.attachmentStore = - db.sublevel(ATTACHMENT_STORE, {valueEncoding: 'json'}); - stores.binaryStore = db.sublevel(BINARY_STORE, {valueEncoding: 'binary'}); - stores.localStore = db.sublevel(LOCAL_STORE, {valueEncoding: 'json'}); - stores.metaStore = db.sublevel(META_STORE, {valueEncoding: 'json'}); - migrate.localAndMetaStores(db, stores, function () { - stores.metaStore.get(UPDATE_SEQ_KEY, function (err, value) { - if (typeof db._updateSeq === 'undefined') { - db._updateSeq = value || 0; - } - stores.metaStore.get(DOC_COUNT_KEY, function (err, value) { - db._docCount = !err ? value : 0; - stores.metaStore.get(UUID_KEY, function (err, value) { - instanceId = !err ? value : uuid(); - stores.metaStore.put(UUID_KEY, instanceId, function () { - process.nextTick(function () { - callback(null, api); - }); - }); - }); - }); - }); - }); - } - - function countDocs(callback) { - /* istanbul ignore if */ - if (db.isClosed()) { - return callback(new Error('database is closed')); - } - return callback(null, db._docCount); // use cached value - } - - api.type = function () { - return 'leveldb'; - }; - - api._id = function (callback) { - callback(null, instanceId); - }; - - api._info = function (callback) { - var res = { - doc_count: db._docCount, - update_seq: db._updateSeq, - backend_adapter: functionName(leveldown) - }; - return process.nextTick(function () { - callback(null, res); - }); - }; - - function tryCode(fun, args) { - try { - fun.apply(null, args); - } catch (err) { - args[args.length - 1](err); - } - } - - function executeNext() { - var firstTask = db._queue.peekFront(); - - if (firstTask.type === 'read') { - runReadOperation(firstTask); - } else { // write, only do one at a time - runWriteOperation(firstTask); - } - } - - function runReadOperation(firstTask) { - // do multiple reads at once simultaneously, because it's safe - - var readTasks = [firstTask]; - var i = 1; - var nextTask = db._queue.get(i); - while (typeof nextTask !== 'undefined' && nextTask.type === 'read') { - readTasks.push(nextTask); - i++; - nextTask = db._queue.get(i); - } - - var numDone = 0; - - readTasks.forEach(function (readTask) { - var args = readTask.args; - var callback = args[args.length - 1]; - args[args.length - 1] = getArguments(function (cbArgs) { - callback.apply(null, cbArgs); - if (++numDone === readTasks.length) { - process.nextTick(function () { - // all read tasks have finished - readTasks.forEach(function () { - db._queue.shift(); - }); - if (db._queue.length) { - executeNext(); - } - }); - } - }); - tryCode(readTask.fun, args); - }); - } - - function runWriteOperation(firstTask) { - var args = firstTask.args; - var callback = args[args.length - 1]; - args[args.length - 1] = getArguments(function (cbArgs) { - callback.apply(null, cbArgs); - process.nextTick(function () { - db._queue.shift(); - if (db._queue.length) { - executeNext(); - } - }); - }); - tryCode(firstTask.fun, args); - } - - // all read/write operations to the database are done in a queue, - // similar to how websql/idb works. this avoids problems such - // as e.g. compaction needing to have a lock on the database while - // it updates stuff. in the future we can revisit this. - function writeLock(fun) { - return getArguments(function (args) { - db._queue.push({ - fun: fun, - args: args, - type: 'write' - }); - - if (db._queue.length === 1) { - process.nextTick(executeNext); - } - }); - } - - // same as the writelock, but multiple can run at once - function readLock(fun) { - return getArguments(function (args) { - db._queue.push({ - fun: fun, - args: args, - type: 'read' - }); - - if (db._queue.length === 1) { - process.nextTick(executeNext); - } - }); - } - - function formatSeq(n) { - return ('0000000000000000' + n).slice(-16); - } - - function parseSeq(s) { - return parseInt(s, 10); - } - - api._get = readLock(function (id, opts, callback) { - opts = clone(opts); - - stores.docStore.get(id, function (err, metadata) { - - if (err || !metadata) { - return callback(createError(MISSING_DOC, 'missing')); - } - - var rev = getWinningRev(metadata); - var deleted = getIsDeleted(metadata, rev); - if (deleted && !opts.rev) { - return callback(createError(MISSING_DOC, "deleted")); - } - - rev = opts.rev ? opts.rev : rev; - - var seq = metadata.rev_map[rev]; - - stores.bySeqStore.get(formatSeq(seq), function (err, doc) { - if (!doc) { - return callback(createError(MISSING_DOC)); - } - /* istanbul ignore if */ - if ('_id' in doc && doc._id !== metadata.id) { - // this failing implies something very wrong - return callback(new Error('wrong doc returned')); - } - doc._id = metadata.id; - if ('_rev' in doc) { - /* istanbul ignore if */ - if (doc._rev !== rev) { - // this failing implies something very wrong - return callback(new Error('wrong doc returned')); - } - } else { - // we didn't always store this - doc._rev = rev; - } - return callback(null, {doc: doc, metadata: metadata}); - }); - }); - }); - - // not technically part of the spec, but if putAttachment has its own - // method... - api._getAttachment = function (docId, attachId, attachment, opts, callback) { - var digest = attachment.digest; - var type = attachment.content_type; - - stores.binaryStore.get(digest, function (err, attach) { - if (err) { - /* istanbul ignore if */ - if (err.name !== 'NotFoundError') { - return callback(err); - } - // Empty attachment - return callback(null, opts.binary ? createEmptyBluffer(type) : ''); - } - - if (opts.binary) { - callback(null, readAsBluffer(attach, type)); - } else { - callback(null, attach.toString('base64')); - } - }); - }; - - api._bulkDocs = writeLock(function (req, opts, callback) { - var newEdits = opts.new_edits; - var results = new Array(req.docs.length); - var fetchedDocs = new Map(); - var stemmedRevs = new Map(); - - var txn = new LevelTransaction(); - var docCountDelta = 0; - var newUpdateSeq = db._updateSeq; - - // parse the docs and give each a sequence number - var userDocs = req.docs; - var docInfos = userDocs.map(function (doc) { - if (doc._id && isLocalId(doc._id)) { - return doc; - } - var newDoc = parseDoc(doc, newEdits); - - if (newDoc.metadata && !newDoc.metadata.rev_map) { - newDoc.metadata.rev_map = {}; - } - - return newDoc; - }); - var infoErrors = docInfos.filter(function (doc) { - return doc.error; - }); - - if (infoErrors.length) { - return callback(infoErrors[0]); - } - - // verify any stub attachments as a precondition test - - function verifyAttachment(digest, callback) { - txn.get(stores.attachmentStore, digest, function (levelErr) { - if (levelErr) { - var err = createError(MISSING_STUB, - 'unknown stub attachment with digest ' + - digest); - callback(err); - } else { - callback(); - } - }); - } - - function verifyAttachments(finish) { - var digests = []; - userDocs.forEach(function (doc) { - if (doc && doc._attachments) { - Object.keys(doc._attachments).forEach(function (filename) { - var att = doc._attachments[filename]; - if (att.stub) { - digests.push(att.digest); - } - }); - } - }); - if (!digests.length) { - return finish(); - } - var numDone = 0; - var err; - - digests.forEach(function (digest) { - verifyAttachment(digest, function (attErr) { - if (attErr && !err) { - err = attErr; - } - - if (++numDone === digests.length) { - finish(err); - } - }); - }); - } - - function fetchExistingDocs(finish) { - var numDone = 0; - var overallErr; - function checkDone() { - if (++numDone === userDocs.length) { - return finish(overallErr); - } - } - - userDocs.forEach(function (doc) { - if (doc._id && isLocalId(doc._id)) { - // skip local docs - return checkDone(); - } - txn.get(stores.docStore, doc._id, function (err, info) { - if (err) { - /* istanbul ignore if */ - if (err.name !== 'NotFoundError') { - overallErr = err; - } - } else { - fetchedDocs.set(doc._id, info); - } - checkDone(); - }); - }); - } - - function compact(revsMap, callback) { - var promise = Promise.resolve(); - revsMap.forEach(function (revs, docId) { - // TODO: parallelize, for now need to be sequential to - // pass orphaned attachment tests - promise = promise.then(function () { - return new Promise(function (resolve, reject) { - api._doCompactionNoLock(docId, revs, {ctx: txn}, function (err) { - /* istanbul ignore if */ - if (err) { - return reject(err); - } - resolve(); - }); - }); - }); - }); - - promise.then(function () { - callback(); - }, callback); - } - - function autoCompact(callback) { - var revsMap = new Map(); - fetchedDocs.forEach(function (metadata, docId) { - revsMap.set(docId, compactTree(metadata)); - }); - compact(revsMap, callback); - } - - function finish() { - compact(stemmedRevs, function (error) { - /* istanbul ignore if */ - if (error) { - complete(error); - } - if (api.auto_compaction) { - return autoCompact(complete); - } - complete(); - }); - } - - function writeDoc(docInfo, winningRev, winningRevIsDeleted, newRevIsDeleted, - isUpdate, delta, resultsIdx, callback2) { - docCountDelta += delta; - - var err = null; - var recv = 0; - - docInfo.metadata.winningRev = winningRev; - docInfo.metadata.deleted = winningRevIsDeleted; - - docInfo.data._id = docInfo.metadata.id; - docInfo.data._rev = docInfo.metadata.rev; - - if (newRevIsDeleted) { - docInfo.data._deleted = true; - } - - if (docInfo.stemmedRevs.length) { - stemmedRevs.set(docInfo.metadata.id, docInfo.stemmedRevs); - } - - var attachments = docInfo.data._attachments ? - Object.keys(docInfo.data._attachments) : - []; - - function attachmentSaved(attachmentErr) { - recv++; - if (!err) { - /* istanbul ignore if */ - if (attachmentErr) { - err = attachmentErr; - callback2(err); - } else if (recv === attachments.length) { - finish(); - } - } - } - - function onMD5Load(doc, key, data, attachmentSaved) { - return function (result) { - saveAttachment(doc, MD5_PREFIX + result, key, data, attachmentSaved); - }; - } - - function doMD5(doc, key, attachmentSaved) { - return function (data) { - binaryMd5(data, onMD5Load(doc, key, data, attachmentSaved)); - }; - } - - for (var i = 0; i < attachments.length; i++) { - var key = attachments[i]; - var att = docInfo.data._attachments[key]; - - if (att.stub) { - // still need to update the refs mapping - var id = docInfo.data._id; - var rev = docInfo.data._rev; - saveAttachmentRefs(id, rev, att.digest, attachmentSaved); - continue; - } - var data; - if (typeof att.data === 'string') { - // input is assumed to be a base64 string - try { - data = atob(att.data); - } catch (e) { - callback(createError(BAD_ARG, - 'Attachment is not a valid base64 string')); - return; - } - doMD5(docInfo, key, attachmentSaved)(data); - } else { - prepareAttachmentForStorage(att.data, - doMD5(docInfo, key, attachmentSaved)); - } - } - - function finish() { - var seq = docInfo.metadata.rev_map[docInfo.metadata.rev]; - /* istanbul ignore if */ - if (seq) { - // check that there aren't any existing revisions with the same - // revision id, else we shouldn't do anything - return callback2(); - } - seq = ++newUpdateSeq; - docInfo.metadata.rev_map[docInfo.metadata.rev] = - docInfo.metadata.seq = seq; - var seqKey = formatSeq(seq); - var batch = [{ - key: seqKey, - value: docInfo.data, - prefix: stores.bySeqStore, - type: 'put' - }, { - key: docInfo.metadata.id, - value: docInfo.metadata, - prefix: stores.docStore, - type: 'put' - }]; - txn.batch(batch); - results[resultsIdx] = { - ok: true, - id: docInfo.metadata.id, - rev: winningRev - }; - fetchedDocs.set(docInfo.metadata.id, docInfo.metadata); - callback2(); - } - - if (!attachments.length) { - finish(); - } - } - - // attachments are queued per-digest, otherwise the refs could be - // overwritten by concurrent writes in the same bulkDocs session - var attachmentQueues = {}; - - function saveAttachmentRefs(id, rev, digest, callback) { - - function fetchAtt() { - return new Promise(function (resolve, reject) { - txn.get(stores.attachmentStore, digest, function (err, oldAtt) { - /* istanbul ignore if */ - if (err && err.name !== 'NotFoundError') { - return reject(err); - } - resolve(oldAtt); - }); - }); - } - - function saveAtt(oldAtt) { - var ref = [id, rev].join('@'); - var newAtt = {}; - - if (oldAtt) { - if (oldAtt.refs) { - // only update references if this attachment already has them - // since we cannot migrate old style attachments here without - // doing a full db scan for references - newAtt.refs = oldAtt.refs; - newAtt.refs[ref] = true; - } - } else { - newAtt.refs = {}; - newAtt.refs[ref] = true; - } - - return new Promise(function (resolve) { - txn.batch([{ - type: 'put', - prefix: stores.attachmentStore, - key: digest, - value: newAtt - }]); - resolve(!oldAtt); - }); - } - - // put attachments in a per-digest queue, to avoid two docs with the same - // attachment overwriting each other - var queue = attachmentQueues[digest] || Promise.resolve(); - attachmentQueues[digest] = queue.then(function () { - return fetchAtt().then(saveAtt).then(function (isNewAttachment) { - callback(null, isNewAttachment); - }, callback); - }); - } - - function saveAttachment(docInfo, digest, key, data, callback) { - var att = docInfo.data._attachments[key]; - delete att.data; - att.digest = digest; - att.length = data.length; - var id = docInfo.metadata.id; - var rev = docInfo.metadata.rev; - att.revpos = parseInt(rev, 10); - - saveAttachmentRefs(id, rev, digest, function (err, isNewAttachment) { - /* istanbul ignore if */ - if (err) { - return callback(err); - } - // do not try to store empty attachments - if (data.length === 0) { - return callback(err); - } - if (!isNewAttachment) { - // small optimization - don't bother writing it again - return callback(err); - } - txn.batch([{ - type: 'put', - prefix: stores.binaryStore, - key: digest, - value: new Buffer(data, 'binary') - }]); - callback(); - }); - } - - function complete(err) { - /* istanbul ignore if */ - if (err) { - return process.nextTick(function () { - callback(err); - }); - } - txn.batch([ - { - prefix: stores.metaStore, - type: 'put', - key: UPDATE_SEQ_KEY, - value: newUpdateSeq - }, - { - prefix: stores.metaStore, - type: 'put', - key: DOC_COUNT_KEY, - value: db._docCount + docCountDelta - } - ]); - txn.execute(db, function (err) { - /* istanbul ignore if */ - if (err) { - return callback(err); - } - db._docCount += docCountDelta; - db._updateSeq = newUpdateSeq; - levelChanges.notify(name); - process.nextTick(function () { - callback(null, results); - }); - }); - } - - if (!docInfos.length) { - return callback(null, []); - } - - verifyAttachments(function (err) { - if (err) { - return callback(err); - } - fetchExistingDocs(function (err) { - /* istanbul ignore if */ - if (err) { - return callback(err); - } - processDocs(revLimit, docInfos, api, fetchedDocs, txn, results, - writeDoc, opts, finish); - }); - }); - }); - api._allDocs = readLock(function (opts, callback) { - opts = clone(opts); - countDocs(function (err, docCount) { - /* istanbul ignore if */ - if (err) { - return callback(err); - } - var readstreamOpts = {}; - var skip = opts.skip || 0; - if (opts.startkey) { - readstreamOpts.gte = opts.startkey; - } - if (opts.endkey) { - readstreamOpts.lte = opts.endkey; - } - if (opts.key) { - readstreamOpts.gte = readstreamOpts.lte = opts.key; - } - if (opts.descending) { - readstreamOpts.reverse = true; - // switch start and ends - var tmp = readstreamOpts.lte; - readstreamOpts.lte = readstreamOpts.gte; - readstreamOpts.gte = tmp; - } - var limit; - if (typeof opts.limit === 'number') { - limit = opts.limit; - } - if (limit === 0 || - ('start' in readstreamOpts && 'end' in readstreamOpts && - readstreamOpts.start > readstreamOpts.end)) { - // should return 0 results when start is greater than end. - // normally level would "fix" this for us by reversing the order, - // so short-circuit instead - return callback(null, { - total_rows: docCount, - offset: opts.skip, - rows: [] - }); - } - var results = []; - var docstream = stores.docStore.readStream(readstreamOpts); - - var throughStream = through(function (entry, _, next) { - var metadata = entry.value; - // winningRev and deleted are performance-killers, but - // in newer versions of PouchDB, they are cached on the metadata - var winningRev = getWinningRev(metadata); - var deleted = getIsDeleted(metadata, winningRev); - if (!deleted) { - if (skip-- > 0) { - next(); - return; - } else if (typeof limit === 'number' && limit-- <= 0) { - docstream.unpipe(); - docstream.destroy(); - next(); - return; - } - } else if (opts.deleted !== 'ok') { - next(); - return; - } - function allDocsInner(data) { - var doc = { - id: metadata.id, - key: metadata.id, - value: { - rev: winningRev - } - }; - if (opts.include_docs) { - doc.doc = data; - doc.doc._rev = doc.value.rev; - if (opts.conflicts) { - doc.doc._conflicts = collectConflicts(metadata); - } - for (var att in doc.doc._attachments) { - if (doc.doc._attachments.hasOwnProperty(att)) { - doc.doc._attachments[att].stub = true; - } - } - } - if (opts.inclusive_end === false && metadata.id === opts.endkey) { - return next(); - } else if (deleted) { - if (opts.deleted === 'ok') { - doc.value.deleted = true; - doc.doc = null; - } else { - /* istanbul ignore next */ - return next(); - } - } - results.push(doc); - next(); - } - if (opts.include_docs) { - var seq = metadata.rev_map[winningRev]; - stores.bySeqStore.get(formatSeq(seq), function (err, data) { - if (!err) { - allDocsInner(data); - } - }); - } - else { - allDocsInner(); - } - }, function (next) { - Promise.resolve().then(function () { - if (opts.include_docs && opts.attachments) { - return fetchAttachments(results, stores, opts); - } - }).then(function () { - callback(null, { - total_rows: docCount, - offset: opts.skip, - rows: results - }); - }, callback); - next(); - }).on('unpipe', function () { - throughStream.end(); - }); - - docstream.on('error', callback); - - docstream.pipe(throughStream); - }); - }); - - api._changes = function (opts) { - opts = clone(opts); - - if (opts.continuous) { - var id = name + ':' + uuid(); - levelChanges.addListener(name, id, api, opts); - levelChanges.notify(name); - return { - cancel: function () { - levelChanges.removeListener(name, id); - } - }; - } - - var descending = opts.descending; - var results = []; - var lastSeq = opts.since || 0; - var called = 0; - var streamOpts = { - reverse: descending - }; - var limit; - if ('limit' in opts && opts.limit > 0) { - limit = opts.limit; - } - if (!streamOpts.reverse) { - streamOpts.start = formatSeq(opts.since || 0); - } - - var docIds = opts.doc_ids && new Set(opts.doc_ids); - var filter = filterChange(opts); - var docIdsToMetadata = new Map(); - - var returnDocs; - if ('return_docs' in opts) { - returnDocs = opts.return_docs; - } else if ('returnDocs' in opts) { - // TODO: Remove 'returnDocs' in favor of 'return_docs' in a future release - returnDocs = opts.returnDocs; - } else { - returnDocs = true; - } - - function complete() { - opts.done = true; - if (returnDocs && opts.limit) { - /* istanbul ignore if */ - if (opts.limit < results.length) { - results.length = opts.limit; - } - } - changeStream.unpipe(throughStream); - changeStream.destroy(); - if (!opts.continuous && !opts.cancelled) { - if (opts.include_docs && opts.attachments) { - fetchAttachments(results, stores, opts).then(function () { - opts.complete(null, {results: results, last_seq: lastSeq}); - }); - } else { - opts.complete(null, {results: results, last_seq: lastSeq}); - } - } - } - var changeStream = stores.bySeqStore.readStream(streamOpts); - var throughStream = through(function (data, _, next) { - if (limit && called >= limit) { - complete(); - return next(); - } - if (opts.cancelled || opts.done) { - return next(); - } - - var seq = parseSeq(data.key); - var doc = data.value; - - if (seq === opts.since && !descending) { - // couchdb ignores `since` if descending=true - return next(); - } - - if (docIds && !docIds.has(doc._id)) { - return next(); - } - - var metadata; - - function onGetMetadata(metadata) { - var winningRev = getWinningRev(metadata); - - function onGetWinningDoc(winningDoc) { - - var change = opts.processChange(winningDoc, metadata, opts); - change.seq = metadata.seq; - - var filtered = filter(change); - if (typeof filtered === 'object') { - return opts.complete(filtered); - } - - if (filtered) { - called++; - - if (opts.attachments && opts.include_docs) { - // fetch attachment immediately for the benefit - // of live listeners - fetchAttachments([change], stores, opts).then(function () { - opts.onChange(change); - }); - } else { - opts.onChange(change); - } - - if (returnDocs) { - results.push(change); - } - } - next(); - } - - if (metadata.seq !== seq) { - // some other seq is later - return next(); - } - - lastSeq = seq; - - if (winningRev === doc._rev) { - return onGetWinningDoc(doc); - } - - // fetch the winner - - var winningSeq = metadata.rev_map[winningRev]; - - stores.bySeqStore.get(formatSeq(winningSeq), function (err, doc) { - onGetWinningDoc(doc); - }); - } - - metadata = docIdsToMetadata.get(doc._id); - if (metadata) { // cached - return onGetMetadata(metadata); - } - // metadata not cached, have to go fetch it - stores.docStore.get(doc._id, function (err, metadata) { - /* istanbul ignore if */ - if (opts.cancelled || opts.done || db.isClosed() || - isLocalId(metadata.id)) { - return next(); - } - docIdsToMetadata.set(doc._id, metadata); - onGetMetadata(metadata); - }); - }, function (next) { - if (opts.cancelled) { - return next(); - } - if (returnDocs && opts.limit) { - /* istanbul ignore if */ - if (opts.limit < results.length) { - results.length = opts.limit; - } - } - - next(); - }).on('unpipe', function () { - throughStream.end(); - complete(); - }); - changeStream.pipe(throughStream); - return { - cancel: function () { - opts.cancelled = true; - complete(); - } - }; - }; - - api._close = function (callback) { - /* istanbul ignore if */ - if (db.isClosed()) { - return callback(createError(NOT_OPEN)); - } - db.close(function (err) { - /* istanbul ignore if */ - if (err) { - callback(err); - } else { - dbStore.delete(name); - callback(); - } - }); - }; - - api._getRevisionTree = function (docId, callback) { - stores.docStore.get(docId, function (err, metadata) { - if (err) { - callback(createError(MISSING_DOC)); - } else { - callback(null, metadata.rev_tree); - } - }); - }; - - api._doCompaction = writeLock(function (docId, revs, opts, callback) { - api._doCompactionNoLock(docId, revs, opts, callback); - }); - - // the NoLock version is for use by bulkDocs - api._doCompactionNoLock = function (docId, revs, opts, callback) { - if (typeof opts === 'function') { - callback = opts; - opts = {}; - } - - if (!revs.length) { - return callback(); - } - var txn = opts.ctx || new LevelTransaction(); - - txn.get(stores.docStore, docId, function (err, metadata) { - /* istanbul ignore if */ - if (err) { - return callback(err); - } - var seqs = revs.map(function (rev) { - var seq = metadata.rev_map[rev]; - delete metadata.rev_map[rev]; - return seq; - }); - traverseRevTree(metadata.rev_tree, function (isLeaf, pos, - revHash, ctx, opts) { - var rev = pos + '-' + revHash; - if (revs.indexOf(rev) !== -1) { - opts.status = 'missing'; - } - }); - - var batch = []; - batch.push({ - key: metadata.id, - value: metadata, - type: 'put', - prefix: stores.docStore - }); - - var digestMap = {}; - var numDone = 0; - var overallErr; - function checkDone(err) { - /* istanbul ignore if */ - if (err) { - overallErr = err; - } - if (++numDone === revs.length) { // done - /* istanbul ignore if */ - if (overallErr) { - return callback(overallErr); - } - deleteOrphanedAttachments(); - } - } - - function finish(err) { - /* istanbul ignore if */ - if (err) { - return callback(err); - } - txn.batch(batch); - if (opts.ctx) { - // don't execute immediately - return callback(); - } - txn.execute(db, callback); - } - - function deleteOrphanedAttachments() { - var possiblyOrphanedAttachments = Object.keys(digestMap); - if (!possiblyOrphanedAttachments.length) { - return finish(); - } - var numDone = 0; - var overallErr; - function checkDone(err) { - /* istanbul ignore if */ - if (err) { - overallErr = err; - } - if (++numDone === possiblyOrphanedAttachments.length) { - finish(overallErr); - } - } - var refsToDelete = new Map(); - revs.forEach(function (rev) { - refsToDelete.set(docId + '@' + rev, true); - }); - possiblyOrphanedAttachments.forEach(function (digest) { - txn.get(stores.attachmentStore, digest, function (err, attData) { - /* istanbul ignore if */ - if (err) { - if (err.name === 'NotFoundError') { - return checkDone(); - } else { - return checkDone(err); - } - } - var refs = Object.keys(attData.refs || {}).filter(function (ref) { - return !refsToDelete.has(ref); - }); - var newRefs = {}; - refs.forEach(function (ref) { - newRefs[ref] = true; - }); - if (refs.length) { // not orphaned - batch.push({ - key: digest, - type: 'put', - value: {refs: newRefs}, - prefix: stores.attachmentStore - }); - } else { // orphaned, can safely delete - batch = batch.concat([{ - key: digest, - type: 'del', - prefix: stores.attachmentStore - }, { - key: digest, - type: 'del', - prefix: stores.binaryStore - }]); - } - checkDone(); - }); - }); - } - - seqs.forEach(function (seq) { - batch.push({ - key: formatSeq(seq), - type: 'del', - prefix: stores.bySeqStore - }); - txn.get(stores.bySeqStore, formatSeq(seq), function (err, doc) { - /* istanbul ignore if */ - if (err) { - if (err.name === 'NotFoundError') { - return checkDone(); - } else { - return checkDone(err); - } - } - var atts = Object.keys(doc._attachments || {}); - atts.forEach(function (attName) { - var digest = doc._attachments[attName].digest; - digestMap[digest] = true; - }); - checkDone(); - }); - }); - }); - }; - - api._getLocal = function (id, callback) { - stores.localStore.get(id, function (err, doc) { - if (err) { - callback(createError(MISSING_DOC)); - } else { - callback(null, doc); - } - }); - }; - - api._putLocal = function (doc, opts, callback) { - if (typeof opts === 'function') { - callback = opts; - opts = {}; - } - if (opts.ctx) { - api._putLocalNoLock(doc, opts, callback); - } else { - api._putLocalWithLock(doc, opts, callback); - } - }; - - api._putLocalWithLock = writeLock(function (doc, opts, callback) { - api._putLocalNoLock(doc, opts, callback); - }); - - // the NoLock version is for use by bulkDocs - api._putLocalNoLock = function (doc, opts, callback) { - delete doc._revisions; // ignore this, trust the rev - var oldRev = doc._rev; - var id = doc._id; - - var txn = opts.ctx || new LevelTransaction(); - - txn.get(stores.localStore, id, function (err, resp) { - if (err && oldRev) { - return callback(createError(REV_CONFLICT)); - } - if (resp && resp._rev !== oldRev) { - return callback(createError(REV_CONFLICT)); - } - doc._rev = - oldRev ? '0-' + (parseInt(oldRev.split('-')[1], 10) + 1) : '0-1'; - var batch = [ - { - type: 'put', - prefix: stores.localStore, - key: id, - value: doc - } - ]; - - txn.batch(batch); - var ret = {ok: true, id: doc._id, rev: doc._rev}; - - if (opts.ctx) { - // don't execute immediately - return callback(null, ret); - } - txn.execute(db, function (err) { - /* istanbul ignore if */ - if (err) { - return callback(err); - } - callback(null, ret); - }); - }); - }; - - api._removeLocal = function (doc, opts, callback) { - if (typeof opts === 'function') { - callback = opts; - opts = {}; - } - if (opts.ctx) { - api._removeLocalNoLock(doc, opts, callback); - } else { - api._removeLocalWithLock(doc, opts, callback); - } - }; - - api._removeLocalWithLock = writeLock(function (doc, opts, callback) { - api._removeLocalNoLock(doc, opts, callback); - }); - - // the NoLock version is for use by bulkDocs - api._removeLocalNoLock = function (doc, opts, callback) { - var txn = opts.ctx || new LevelTransaction(); - txn.get(stores.localStore, doc._id, function (err, resp) { - if (err) { - /* istanbul ignore if */ - if (err.name !== 'NotFoundError') { - return callback(err); - } else { - return callback(createError(MISSING_DOC)); - } - } - if (resp._rev !== doc._rev) { - return callback(createError(REV_CONFLICT)); - } - txn.batch([{ - prefix: stores.localStore, - type: 'del', - key: doc._id - }]); - var ret = {ok: true, id: doc._id, rev: '0-0'}; - if (opts.ctx) { - // don't execute immediately - return callback(null, ret); - } - txn.execute(db, function (err) { - /* istanbul ignore if */ - if (err) { - return callback(err); - } - callback(null, ret); - }); - }); - }; - - // close and delete open leveldb stores - api._destroy = function (opts, callback) { - var dbStore; - var leveldownName = functionName(leveldown); - /* istanbul ignore else */ - if (dbStores.has(leveldownName)) { - dbStore = dbStores.get(leveldownName); - } else { - return callDestroy(name, callback); - } - - /* istanbul ignore else */ - if (dbStore.has(name)) { - levelChanges.removeAllListeners(name); - - dbStore.get(name).close(function () { - dbStore.delete(name); - callDestroy(name, callback); - }); - } else { - callDestroy(name, callback); - } - }; - function callDestroy(name, cb) { - leveldown.destroy(name, cb); - } -} - -export default LevelPouch; diff --git a/packages/pouchdb-adapter-leveldb-core-rn/src/migrate-browser.js b/packages/pouchdb-adapter-leveldb-core-rn/src/migrate-browser.js deleted file mode 100755 index bd5f071..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/src/migrate-browser.js +++ /dev/null @@ -1,18 +0,0 @@ -// in the browser, LevelAlt doesn't need the -// pre-2.2.0 LevelDB-specific migrations -var toSublevel = function (name, db, callback) { - process.nextTick(function () { - callback(); - }); -}; - -var localAndMetaStores = function (db, stores, callback) { - process.nextTick(function () { - callback(); - }); -}; - -export default { - toSublevel: toSublevel, - localAndMetaStores: localAndMetaStores -}; diff --git a/packages/pouchdb-adapter-leveldb-core-rn/src/migrate.js b/packages/pouchdb-adapter-leveldb-core-rn/src/migrate.js deleted file mode 100755 index 2576a74..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/src/migrate.js +++ /dev/null @@ -1,194 +0,0 @@ -import fs from 'fs'; -import path from 'path'; -import { isLocalId, winningRev } from 'pouchdb-merge'; -import levelup from 'levelup'; -import { obj as through } from 'through2'; -import LevelWriteStream from 'level-write-stream'; - -var stores = [ - 'document-store', - 'by-sequence', - 'attach-store', - 'attach-binary-store' -]; -function formatSeq(n) { - return ('0000000000000000' + n).slice(-16); -} -var UPDATE_SEQ_KEY = '_local_last_update_seq'; -var DOC_COUNT_KEY = '_local_doc_count'; -var UUID_KEY = '_local_uuid'; - -var toSublevel = function (name, db, callback) { - // local require to prevent crashing if leveldown isn't installed. - var leveldown = require("leveldown"); - - var base = path.resolve(name); - function move(store, index, cb) { - var storePath = path.join(base, store); - var opts; - if (index === 3) { - opts = { - valueEncoding: 'binary' - }; - } else { - opts = { - valueEncoding: 'json' - }; - } - var sub = db.sublevel(store, opts); - var orig = levelup(storePath, opts); - var from = orig.createReadStream(); - var writeStream = new LevelWriteStream(sub); - var to = writeStream(); - from.on('end', function () { - orig.close(function (err) { - cb(err, storePath); - }); - }); - from.pipe(to); - } - fs.unlink(base + '.uuid', function (err) { - if (err) { - return callback(); - } - var todo = 4; - var done = []; - stores.forEach(function (store, i) { - move(store, i, function (err, storePath) { - /* istanbul ignore if */ - if (err) { - return callback(err); - } - done.push(storePath); - if (!(--todo)) { - done.forEach(function (item) { - leveldown.destroy(item, function () { - if (++todo === done.length) { - fs.rmdir(base, callback); - } - }); - }); - } - }); - }); - }); -}; -var localAndMetaStores = function (db, stores, callback) { - var batches = []; - stores.bySeqStore.get(UUID_KEY, function (err, value) { - if (err) { - // no uuid key, so don't need to migrate; - return callback(); - } - batches.push({ - key: UUID_KEY, - value: value, - prefix: stores.metaStore, - type: 'put', - valueEncoding: 'json' - }); - batches.push({ - key: UUID_KEY, - prefix: stores.bySeqStore, - type: 'del' - }); - stores.bySeqStore.get(DOC_COUNT_KEY, function (err, value) { - if (value) { - // if no doc count key, - // just skip - // we can live with this - batches.push({ - key: DOC_COUNT_KEY, - value: value, - prefix: stores.metaStore, - type: 'put', - valueEncoding: 'json' - }); - batches.push({ - key: DOC_COUNT_KEY, - prefix: stores.bySeqStore, - type: 'del' - }); - } - stores.bySeqStore.get(UPDATE_SEQ_KEY, function (err, value) { - if (value) { - // if no UPDATE_SEQ_KEY - // just skip - // we've gone to far to stop. - batches.push({ - key: UPDATE_SEQ_KEY, - value: value, - prefix: stores.metaStore, - type: 'put', - valueEncoding: 'json' - }); - batches.push({ - key: UPDATE_SEQ_KEY, - prefix: stores.bySeqStore, - type: 'del' - }); - } - var deletedSeqs = {}; - stores.docStore.createReadStream({ - startKey: '_', - endKey: '_\xFF' - }).pipe(through(function (ch, _, next) { - if (!isLocalId(ch.key)) { - return next(); - } - batches.push({ - key: ch.key, - prefix: stores.docStore, - type: 'del' - }); - var winner = winningRev(ch.value); - Object.keys(ch.value.rev_map).forEach(function (key) { - if (key !== 'winner') { - this.push(formatSeq(ch.value.rev_map[key])); - } - }, this); - var winningSeq = ch.value.rev_map[winner]; - stores.bySeqStore.get(formatSeq(winningSeq), function (err, value) { - if (!err) { - batches.push({ - key: ch.key, - value: value, - prefix: stores.localStore, - type: 'put', - valueEncoding: 'json' - }); - } - next(); - }); - - })).pipe(through(function (seq, _, next) { - /* istanbul ignore if */ - if (deletedSeqs[seq]) { - return next(); - } - deletedSeqs[seq] = true; - stores.bySeqStore.get(seq, function (err, resp) { - /* istanbul ignore if */ - if (err || !isLocalId(resp._id)) { - return next(); - } - batches.push({ - key: seq, - prefix: stores.bySeqStore, - type: 'del' - }); - next(); - }); - }, function () { - db.batch(batches, callback); - })); - }); - }); - }); - -}; - -export default { - toSublevel: toSublevel, - localAndMetaStores: localAndMetaStores -}; diff --git a/packages/pouchdb-adapter-leveldb-core-rn/src/prepareAttachmentForStorage-browser.js b/packages/pouchdb-adapter-leveldb-core-rn/src/prepareAttachmentForStorage-browser.js deleted file mode 100755 index 625726f..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/src/prepareAttachmentForStorage-browser.js +++ /dev/null @@ -1,8 +0,0 @@ -import { readAsBinaryString } from 'pouchdb-binary-utils'; - -// In the browser, we store a binary string -function prepareAttachmentForStorage(attData, cb) { - readAsBinaryString(attData, cb); -} - -export default prepareAttachmentForStorage; \ No newline at end of file diff --git a/packages/pouchdb-adapter-leveldb-core-rn/src/prepareAttachmentForStorage.js b/packages/pouchdb-adapter-leveldb-core-rn/src/prepareAttachmentForStorage.js deleted file mode 100755 index 5fd5e5b..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/src/prepareAttachmentForStorage.js +++ /dev/null @@ -1,6 +0,0 @@ -// in Node, we store the buffer directly -function prepareAttachmentForStorage(attData, cb) { - cb(attData); -} - -export default prepareAttachmentForStorage; \ No newline at end of file diff --git a/packages/pouchdb-adapter-leveldb-core-rn/src/readAsBlobOrBuffer-browser.js b/packages/pouchdb-adapter-leveldb-core-rn/src/readAsBlobOrBuffer-browser.js deleted file mode 100755 index 393c38a..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/src/readAsBlobOrBuffer-browser.js +++ /dev/null @@ -1,11 +0,0 @@ -import { blob as createBlob } from 'pouchdb-binary-utils'; - -function readAsBlobOrBuffer(storedObject, type) { - // In the browser, we've stored a binary string. This now comes back as a - // browserified Node-style Buffer (implemented as a typed array), - // but we want a Blob instead. - var byteArray = new Uint8Array(storedObject); - return createBlob([byteArray], {type: type}); -} - -export default readAsBlobOrBuffer; \ No newline at end of file diff --git a/packages/pouchdb-adapter-leveldb-core-rn/src/readAsBlobOrBuffer.js b/packages/pouchdb-adapter-leveldb-core-rn/src/readAsBlobOrBuffer.js deleted file mode 100755 index d478528..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/src/readAsBlobOrBuffer.js +++ /dev/null @@ -1,7 +0,0 @@ -function readAsBlobOrBuffer(storedObject, type) { - // In Node, we've stored a buffer - storedObject.type = type; // non-standard, but used for consistency - return storedObject; -} - -export default readAsBlobOrBuffer; \ No newline at end of file diff --git a/packages/pouchdb-adapter-leveldb-core-rn/src/transaction.js b/packages/pouchdb-adapter-leveldb-core-rn/src/transaction.js deleted file mode 100755 index 66f9cb2..0000000 --- a/packages/pouchdb-adapter-leveldb-core-rn/src/transaction.js +++ /dev/null @@ -1,84 +0,0 @@ -// similar to an idb or websql transaction object -// designed to be passed around. basically just caches -// things in-memory and then does a big batch() operation -// when you're done - -import { Map, Set } from 'pouchdb-collections'; - -function getCacheFor(transaction, store) { - var prefix = store.prefix()[0]; - var cache = transaction._cache; - var subCache = cache.get(prefix); - if (!subCache) { - subCache = new Map(); - cache.set(prefix, subCache); - } - return subCache; -} - -function LevelTransaction() { - this._batch = []; - this._cache = new Map(); -} - -LevelTransaction.prototype.get = function (store, key, callback) { - var cache = getCacheFor(this, store); - var exists = cache.get(key); - if (exists) { - return process.nextTick(function () { - callback(null, exists); - }); - } else if (exists === null) { // deleted marker - /* istanbul ignore next */ - return process.nextTick(function () { - callback({name: 'NotFoundError'}); - }); - } - store.get(key, function (err, res) { - if (err) { - /* istanbul ignore else */ - if (err.name === 'NotFoundError') { - cache.set(key, null); - } - return callback(err); - } - cache.set(key, res); - callback(null, res); - }); -}; - -LevelTransaction.prototype.batch = function (batch) { - for (var i = 0, len = batch.length; i < len; i++) { - var operation = batch[i]; - - var cache = getCacheFor(this, operation.prefix); - - if (operation.type === 'put') { - cache.set(operation.key, operation.value); - } else { - cache.set(operation.key, null); - } - } - this._batch = this._batch.concat(batch); -}; - -LevelTransaction.prototype.execute = function (db, callback) { - - var keys = new Set(); - var uniqBatches = []; - - // remove duplicates; last one wins - for (var i = this._batch.length - 1; i >= 0; i--) { - var operation = this._batch[i]; - var lookupKey = operation.prefix.prefix()[0] + '\xff' + operation.key; - if (keys.has(lookupKey)) { - continue; - } - keys.add(lookupKey); - uniqBatches.push(operation); - } - - db.batch(uniqBatches, callback); -}; - -export default LevelTransaction; diff --git a/packages/pouchdb-react-native/index.js b/packages/pouchdb-react-native/index.js index acdf173..b10533b 100644 --- a/packages/pouchdb-react-native/index.js +++ b/packages/pouchdb-react-native/index.js @@ -1,8 +1,7 @@ 'use strict' import PouchDB from 'pouchdb-core' -// import AsyncStoragePouch from 'pouchdb-adapter-asyncstorage' -import AsyncStoragePouch from 'pouchdb-adapter-asyncstorage-pure' +import AsyncStoragePouch from 'pouchdb-adapter-asyncstorage' import HttpPouch from 'pouchdb-adapter-http' import mapreduce from 'pouchdb-mapreduce' import replication from 'pouchdb-replication' diff --git a/packages/pouchdb-react-native/package.json b/packages/pouchdb-react-native/package.json index 2924b15..24bb47f 100644 --- a/packages/pouchdb-react-native/package.json +++ b/packages/pouchdb-react-native/package.json @@ -1,6 +1,6 @@ { "name": "pouchdb-react-native", - "version": "5.4.20", + "version": "5.5.0-beta-2", "description": "PouchDB Bundle for ReactNative", "main": "index.js", "repository": { @@ -23,8 +23,7 @@ }, "homepage": "https://github.com/stockulus/pouchdb-react-native#readme", "dependencies": { - "pouchdb-adapter-asyncstorage": "5.4.20", - "pouchdb-adapter-asyncstorage-pure": "5.4.20", + "pouchdb-adapter-asyncstorage": "5.5.0-beta-2", "pouchdb-adapter-http": "5.4.5", "pouchdb-core": "5.4.5", "pouchdb-mapreduce": "5.4.5", diff --git a/tests/setup.js b/tests/setup.js index 821ace8..90ca9d3 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -21,8 +21,6 @@ const _require = Module.prototype.require const reqPouch = () => _require.call(null, require.resolve('./pouchdb-for-coverage/')).default const reqPouchModule = name => _require.call(null, require.resolve(`../pouchdb-original/packages/node_modules/${name}`)) const reqAdapter = () => _require.call(null, require.resolve('../packages/pouchdb-adapter-asyncstorage')).default -const reqAdapterPure = () => _require.call(null, require.resolve('../packages/pouchdb-adapter-asyncstorage-pure')).default -const reqLevelAdapter = () => _require.call(null, require.resolve('../packages/pouchdb-adapter-leveldb-core-rn')).default const map = fs .readdirSync(__dirname + '/../pouchdb-original/packages/node_modules') @@ -32,9 +30,7 @@ const map = fs }, { '../../packages/node_modules/pouchdb-for-coverage': reqPouch, '../../packages/node_modules/pouchdb': reqPouch, - 'pouchdb-adapter-asyncstorage': reqAdapter, - 'pouchdb-adapter-asyncstorage-pure': reqAdapterPure, - 'pouchdb-adapter-leveldb-core-rn': reqLevelAdapter + 'pouchdb-adapter-asyncstorage': reqAdapter }) Module.prototype.require = function patchedRequire (name) {