Jelajahi Sumber

mejorado la carga de datos y compatibilidad de la aplicacion

robert2206 8 tahun lalu
induk
melakukan
b4bfba8945

+ 59 - 58
config.xml

@@ -1,59 +1,60 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<?xml version='1.0' encoding='utf-8'?>
 <widget id="com.eiru.odoo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
-  <name>Odoo by Eiru</name>
-  <description>Odoo Mobile</description>
-  <author email="robert.gauto@gmail.com" href="http://ionicframework.com/">Robert Alexis GAuto</author>
-  <content src="index.html"/>
-  <access origin="*"/>
-  <allow-intent href="http://*/*"/>
-  <allow-intent href="https://*/*"/>
-  <allow-intent href="tel:*"/>
-  <allow-intent href="sms:*"/>
-  <allow-intent href="mailto:*"/>
-  <allow-intent href="geo:*"/>
-  <platform name="android">
-    <allow-intent href="market:*"/>
-    <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
-    <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
-    <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
-    <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
-    <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
-    <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
-    <splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
-    <splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
-    <splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
-    <splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
-    <splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/>
-    <splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/>
-    <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
-    <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
-    <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
-    <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
-    <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
-    <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
-  </platform>
-  <platform name="ios">
-    <allow-intent href="itms:*"/>
-    <allow-intent href="itms-apps:*"/>
-  </platform>
-  <preference name="webviewbounce" value="false"/>
-  <preference name="UIWebViewBounce" value="false"/>
-  <preference name="DisallowOverscroll" value="true"/>
-  <preference name="android-minSdkVersion" value="19"/>
-  <preference name="BackupWebStorage" value="none"/>
-  <preference name="SplashScreenDelay" value="1000"/>
-  <preference name="FadeSplashScreen" value="true"/>
-  <preference name="FadeSplashScreenDuration" value="500"/>
-  <preference name="SplashScreenBackgroundColor" value="0xFFFFFFFF"/>
-  <preference name="SplashScreen" value="screen"/>
-  <feature name="StatusBar">
-    <param name="ios-package" onload="true" value="CDVStatusBar"/>
-  </feature>
-  <plugin name="cordova-plugin-device" spec="~1.1.3"/>
-  <plugin name="cordova-plugin-console" spec="~1.0.4"/>
-  <plugin name="cordova-plugin-whitelist" spec="~1.3.0"/>
-  <plugin name="cordova-plugin-splashscreen" spec="~4.0.0"/>
-  <plugin name="cordova-plugin-statusbar" spec="~2.2.0"/>
-  <plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
-  <icon src="resources/android/icon/drawable-xhdpi-icon.png"/>
-</widget>
+    <name>Odoo by Eiru</name>
+    <description>Odoo Mobile</description>
+    <author email="robert.gauto@gmail.com" href="http://ionicframework.com/">Robert Alexis GAuto</author>
+    <content src="index.html" />
+    <access origin="*" />
+    <allow-intent href="http://*/*" />
+    <allow-intent href="https://*/*" />
+    <allow-intent href="tel:*" />
+    <allow-intent href="sms:*" />
+    <allow-intent href="mailto:*" />
+    <allow-intent href="geo:*" />
+    <platform name="android">
+        <allow-intent href="market:*" />
+        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
+        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
+        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
+        <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
+        <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
+        <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
+        <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
+        <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
+        <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
+        <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
+        <splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
+        <splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />
+        <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
+        <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
+        <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
+        <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
+        <splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
+        <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
+    </platform>
+    <platform name="ios">
+        <allow-intent href="itms:*" />
+        <allow-intent href="itms-apps:*" />
+    </platform>
+    <preference name="webviewbounce" value="false" />
+    <preference name="UIWebViewBounce" value="false" />
+    <preference name="DisallowOverscroll" value="true" />
+    <preference name="android-minSdkVersion" value="19" />
+    <preference name="BackupWebStorage" value="none" />
+    <preference name="SplashScreenDelay" value="1000" />
+    <preference name="FadeSplashScreen" value="true" />
+    <preference name="FadeSplashScreenDuration" value="500" />
+    <preference name="SplashScreenBackgroundColor" value="0xFFFFFFFF" />
+    <preference name="SplashScreen" value="screen" />
+    <feature name="StatusBar">
+        <param name="ios-package" onload="true" value="CDVStatusBar" />
+    </feature>
+    <plugin name="cordova-plugin-device" spec="~1.1.3" />
+    <plugin name="cordova-plugin-console" spec="~1.0.4" />
+    <plugin name="cordova-plugin-whitelist" spec="~1.3.0" />
+    <plugin name="cordova-plugin-splashscreen" spec="~4.0.0" />
+    <plugin name="cordova-plugin-statusbar" spec="~2.2.0" />
+    <plugin name="ionic-plugin-keyboard" spec="~2.2.1" />
+    <icon src="resources/android/icon/drawable-xhdpi-icon.png" />
+    <plugin name="cordova-sqlite-storage" spec="~1.4.8" />
+</widget>

+ 5 - 3
package.json

@@ -19,8 +19,10 @@
     "ionic-angular": "^2.0.0-rc.0",
     "ionic-native": "^2.0.3",
     "ionicons": "^3.0.0",
-    "pouchdb": "^6.0.6",
-    "pouchdb-node": "^6.0.6",
+    "pouchdb": "^6.0.7",
+    "pouchdb-adapter-cordova-sqlite": "^2.0.0",
+    "pouchdb-adapter-websql-core": "^6.0.7",
+    "pouchdb-core": "^6.0.7",
     "relational-pouch": "^1.4.4",
     "rollup-plugin-node-builtins": "^2.0.0",
     "rollup-plugin-node-globals": "^1.0.9"
@@ -28,6 +30,7 @@
   "devDependencies": {
     "@ionic/app-scripts": "^0.0.23",
     "ng2-chartjs2": "^1.2.0",
+    "node-sass": "^3.13.0",
     "typescript": "^2.0.3"
   },
   "description": "odoo_mobile: An Ionic project",
@@ -38,7 +41,6 @@
     "cordova-plugin-splashscreen",
     "cordova-plugin-statusbar",
     "ionic-plugin-keyboard",
-    "ionic-plugin-keyboard",
     "cordova-plugin-crosswalk-webview"
   ],
   "cordovaPlatforms": [

+ 17 - 8
src/defaults/default-listable.ts

@@ -2,15 +2,15 @@ import { IListable } from '../interfaces/listable-interface';
 
 export abstract class DefaultListable<T> implements IListable<T> {
 
-    private isForSearch: boolean;
+    private _search: boolean;
     private _elements: Array<T>;
     private _elementsAux: Array<T>;
     private _visibleElements: Array<T>;
-    private _visibleRange: [number, number] = [0, 50];
+    private _visibleRange: [number, number] = [0, 20];
 
     constructor(
     ) {
-        this.isForSearch = false;
+        this._search = false;
         this._elements = [];
         this._elementsAux = [];
         this._visibleElements = [];
@@ -83,6 +83,14 @@ export abstract class DefaultListable<T> implements IListable<T> {
     search(event: any): void {
         let value: string = event.target.value;
 
+        if (!value) {
+            return;
+        }
+
+        if (value.length < 3) {
+            return;
+        }
+
         this.visibleElements = this.elements.filter(item => {
             return (item as any).name.toLowerCase().indexOf(value.toLowerCase()) > -1;
         });
@@ -92,9 +100,9 @@ export abstract class DefaultListable<T> implements IListable<T> {
      *
      */
     toggleSearch(): void {
-        this.isForSearch = !this.isForSearch;
+        this._search = !this._search;
 
-        if (this.isForSearch) {
+        if (this._search) {
             this._elementsAux = this.visibleElements;
         } else {
             this.visibleElements = this._elementsAux;
@@ -104,8 +112,8 @@ export abstract class DefaultListable<T> implements IListable<T> {
     /**
      *
      */
-    isSearching(): boolean {
-        return this.isForSearch;
+    isSearchMode(): boolean {
+        return this._search;
     }
 
     /**
@@ -113,9 +121,10 @@ export abstract class DefaultListable<T> implements IListable<T> {
      */
     seekRange(): void {
         this._visibleRange[0] = this._visibleRange[1];
-        this._visibleRange[1] = this._visibleRange[1] + 50;
+        this._visibleRange[1] = this._visibleRange[1] + 20;
 
         this._visibleElements = this._visibleElements.concat(this._elements.slice(this._visibleRange[0], this._visibleRange[1]));
+        console.info("seeking");
     }
 
     /**

+ 1 - 1
src/interfaces/searchable-interface.ts

@@ -13,5 +13,5 @@ export interface ISearchable<T> {
     /**
      *
      */
-    isSearching(): boolean;
+    isSearchMode(): boolean;
 }

+ 5 - 4
src/pages/product-list/product-list.html

@@ -16,8 +16,8 @@
 
 </ion-header>
 
-<ion-toolbar color="primary" *ngIf="isSearching()">
-    <ion-searchbar placeholder="Buscar" (ionInput)="search($event)"></ion-searchbar>
+<ion-toolbar color="primary" *ngIf="isSearchMode()">
+    <ion-searchbar placeholder="Buscar" debounce="1000" (ionInput)="search($event)"></ion-searchbar>
     <ion-buttons end>
         <button ion-button (click)="toggleSearch()">
             <ion-icon name="arrow-forward"></ion-icon>
@@ -38,12 +38,12 @@
 
             <p>
                 <strong>Precio:</strong>
-                {{ (p.list_price | number) || 0 }}
+                {{ p.list_price | number }}
             </p>
 
             <p>
                 <strong>Cantidad:</strong>
-                {{ p.qty_available || 0 }}
+                {{ p.qty_available }}
             </p>
 
             <button ion-button primary clear item-right (click)="showOptions($event, p)">
@@ -71,4 +71,5 @@
             <ion-icon name="add" color="light"></ion-icon>
         </button>
     </ion-fab>
+    
 </ion-content>

+ 9 - 18
src/pages/product-list/product-list.ts

@@ -6,6 +6,8 @@ import { Product } from '../../models/product';
 import { ProductDetailsPage } from '../product-details/product-details';
 import { ProductOptions } from './product-options';
 import { DataProvider } from '../../providers/data-provider';
+import filter from 'async/filter';
+
 
 @Component({
     selector: 'page-product-list',
@@ -48,19 +50,6 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
         });
     }
 
-    /**
-     *
-     */
-    loadMore(e) {
-        this.seekRange();
-
-        if (this.isToSeek()) {
-            e.enable(false);
-        }
-
-        e.complete();
-    }
-
     /**
      * Goto page
      */
@@ -72,9 +61,7 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
      *
      */
     showOptions(e, item) {
-        this.popover = this.popoverCtrl.create(ProductOptions, {
-            item: item
-        });
+        this.popover = this.popoverCtrl.create(ProductOptions);
 
         this.popover.present({
             ev: e
@@ -83,13 +70,14 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
         this.popover.onDidDismiss(data => {
             switch (data.role) {
                 case "open":
-                    this.openItem(data.item);
+                    this.openItem(item);
                     break;
                 case "delete":
                     this.askIfRemoveItem(item);
                     break;
             
                 default:
+                    this.openItem(item);
                     break;
             }
             
@@ -100,7 +88,10 @@ export class ProductListPage extends DefaultListable<Product> implements INaviga
      *
      */
     openItem(item: any) {
-        this.navCtrl.push(ProductDetailsPage, item);
+        this.navCtrl.push(ProductDetailsPage, item, data => {
+            console.log(data);
+            
+        });
     }    
 
     /**

+ 1 - 2
src/pages/product-list/product-options.ts

@@ -16,8 +16,7 @@ export class ProductOptions {
      */
     click(role: string): void {
         this.viewCtrl.dismiss({
-            role: role,
-            item: this.nav.data.item
+            role: role
         });
     }
 }

+ 39 - 26
src/providers/data-provider.ts

@@ -1,25 +1,34 @@
 import { Injectable } from '@angular/core';
+import { Platform } from 'ionic-angular';
 import PouchDB from 'pouchdb';
-import each from 'async/each';
 import * as Relational from 'relational-pouch';
+import * as Sqlite from 'pouchdb-adapter-cordova-sqlite';
+import each from 'async/each';
 
-PouchDB.plugin(Relational);
+PouchDB.plugin(Relational).plugin(Sqlite);
 
 @Injectable()
 export class DataProvider {
 
     data: any;
 
-    constructor() {
-        this.initialize();
+    constructor(
+        public platform: Platform
+    ) {
+        platform.ready().then(r => {
+            this.initialize();
+        });
     }
 
     /**
      *
      */
     private initialize(): void {
-        this.data = new PouchDB('odoo');
-
+        this.data = new PouchDB('odoo', {
+            auto_compaction: true,
+            adapter: this.platform.is('core') ? 'idb' : 'websql'
+        });
+        
         this.data.setSchema([
             {
                 singular: 'partner',
@@ -83,27 +92,27 @@ export class DataProvider {
      */
     save(type: string, data: any): Promise<any> {
         return new Promise((resolve, reject) => {
-           
-            if (data instanceof Array) {
+            this.platform.ready().then(r => {
+                if (data instanceof Array) {
 
-                each(data, (i, c) => { 
-                    this.data.rel.save(type, i).then(() => { 
-                        c();
-                    }).catch(e => { 
-                        c(e);
+                    each(data, (i, c) => {
+                        this.data.rel.save(type, i).then(() => {
+                            c();
+                        }).catch(e => {
+                            c(e);
+                        });
+                    }, e => {
+                        if (e) {
+                            reject(e);
+                        } else {
+                            resolve();
+                        }
                     });
-                }, e => { 
-                    if (e) {
-                        reject(e);
-                    } else {
-                        resolve();
-                    }
-                });
-
-            } else {
-                 resolve(this.data.rel.save(type, data));
-            }
 
+                } else {
+                    resolve(this.data.rel.save(type, data));
+                }
+            });
         });
     }
 
@@ -112,7 +121,9 @@ export class DataProvider {
      */
     delete(type: string, data: any): any {
         return new Promise((resolve, reject) => {
-            resolve(data.remote_id ? this.save(type, data) : this.data.rel.del(type, data));
+            this.platform.ready().then(r => {
+                resolve(data.remote_id ? this.save(type, data) : this.data.rel.del(type, data));
+            });    
         });
     }
 
@@ -146,7 +157,9 @@ export class DataProvider {
      */
     getAll(type: string): Promise<any> {
         return new Promise((resolve, reject) => {
-            resolve(this.data.rel.find(type));
+            this.platform.ready().then(r => {
+                resolve(this.data.rel.find(type));
+            });
         });
         
     }

+ 1 - 1
src/providers/odoo-provider.ts

@@ -26,7 +26,7 @@ export class OdooProvider {
      *
      */
     private normalizeUrl(): void {
-        this.url = (this.url.startsWith('http://') ? this.url : 'http://' + this.url) + '/api/';
+        this.url = (this.url.startsWith('http://') || this.url.startsWith('https://')  ? this.url : 'http://' + this.url) + '/api/';
     }
 
     /**

+ 5 - 5
src/providers/token-service.ts

@@ -11,9 +11,9 @@ import 'rxjs/add/observable/throw'
 @Injectable()
 export class TokenService {
 
-    username: string = 'admin';
-    password: string = 'admin';
-    url: string = '192.168.88.123:8069';
+    username: string = 'Shopping';
+    password: string = 'Ping_@3040/paraguaY';
+    url: string = 'https://tienda.maluquina.com.py';
 
     constructor(
         private http: Http,
@@ -74,14 +74,14 @@ export class TokenService {
      * Handle error if ocurred
      */
     private normalizeCheckUrl(url: string): string {
-        return (url.startsWith('http://') ? url : 'http://' + url) + '/api/check';
+        return (url.startsWith('http://') || url.startsWith('https://')  ? url : 'http://' + url) + '/api/check';
     }
 
     /**
      * Normalize provide url
      */
     private normalizeJwtUrl(url: string): string {
-        return (url.startsWith('http://') ? url : 'http://' + url) + '/api/jwt';
+        return (url.startsWith('http://') || url.startsWith('https://') ? url : 'http://' + url) + '/api/jwt';
     }
 
     /**

+ 2 - 1
typings.json

@@ -1,6 +1,7 @@
 {
     "globalDependencies": {
         "pouchdb": "registry:dt/pouchdb#5.4.4+20160724064500",
-        "pouchdb-adapter-websql": "registry:dt/pouchdb-adapter-websql#5.4.4+20160724064500"
+        "pouchdb-adapter-websql": "registry:dt/pouchdb-adapter-websql#5.4.4+20160724064500",
+        "pouchdb-core": "registry:dt/pouchdb-core#5.4.4+20160919190957"
     }
 }

+ 0 - 31
typings/globals/pouchdb-adapter-websql/index.d.ts

@@ -1,31 +0,0 @@
-// Generated by typings
-// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/a396c170ba4b6a7f45b20fccbdba0d2b81cc8833/pouchdb-adapter-websql/pouchdb-adapter-websql.d.ts
-declare namespace PouchDB {
-    namespace Core {
-        interface DatabaseInfo {
-            sqlite_plugin?: boolean;
-            websql_encoding?: 'UTF-8' | 'UTF-16';
-        }
-    }
-
-    namespace AdapterWebSql {
-        interface Configuration
-                extends Configuration.LocalDatabaseConfiguration {
-            /**
-             * Amount in MB to request for storage.
-             */
-            size?: number;
-            adapter: 'websql';
-        }
-    }
-
-    interface Static {
-        new<Content extends Core.Encodable>(name: string | void,
-            options: AdapterWebSql.Configuration): Database<Content>;
-    }
-}
-
-declare module 'pouchdb-adapter-websql' {
-    const plugin: PouchDB.Plugin;
-    export = plugin;
-}

+ 0 - 8
typings/globals/pouchdb-adapter-websql/typings.json

@@ -1,8 +0,0 @@
-{
-  "resolution": "main",
-  "tree": {
-    "src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/a396c170ba4b6a7f45b20fccbdba0d2b81cc8833/pouchdb-adapter-websql/pouchdb-adapter-websql.d.ts",
-    "raw": "registry:dt/pouchdb-adapter-websql#5.4.4+20160724064500",
-    "typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/a396c170ba4b6a7f45b20fccbdba0d2b81cc8833/pouchdb-adapter-websql/pouchdb-adapter-websql.d.ts"
-  }
-}

+ 360 - 0
typings/globals/pouchdb-core/index.d.ts

@@ -0,0 +1,360 @@
+// Generated by typings
+// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/0fa2d359311a996084dc3bb67a80365992e3ba42/pouchdb-core/pouchdb-core.d.ts
+declare namespace PouchDB {
+    namespace Core {
+        interface Error {
+        }
+        interface Callback<E, R> {
+            (error: E | void, result: R | void): void;
+        }
+        type AnyCallback = Callback<any, any>;
+        type DocumentId = string;
+        type DocumentKey = string;
+        type RevisionId = string;
+        type Availability = 'available' | 'compacted' | 'not compacted' | 'missing';
+        type Attachment = string | ArrayBuffer;
+        type Encodable = { [propertyName: string]: any };
+
+        interface Options {
+          ajax?: Configuration.RemoteRequesterConfiguration;
+        }
+
+        interface BasicResponse {
+            /** `true` if the operation was successful; `false` otherwise */
+            ok: boolean;
+        }
+        interface Response extends BasicResponse {
+            /** id of the targeted document */
+            id: DocumentId;
+            /** resulting revision of the targeted document */
+            rev: RevisionId;
+        }
+
+        interface DatabaseInfo {
+        }
+
+        interface Revision<Content> {
+            ok: Document<Content> & RevisionIdMeta;
+        }
+        interface RevisionInfo {
+            rev: RevisionId;
+            status: Availability;
+        }
+
+        interface IdMeta {
+            _id: DocumentId;
+        }
+        interface RevisionIdMeta {
+            _rev: RevisionId;
+        }
+        interface GetMeta {
+            /** Conflicting leaf revisions.
+             *
+             * Only present if `GetOptions.conflicts` is `true`
+             */
+            _conflicts?: RevisionId[];
+            _rev?: RevisionId;
+            /** Only present if `GetOptions.revs` is `true` */
+            _revs_info?: RevisionInfo[];
+            /** Only present if `GetOptions.revs_info` is `true` */
+            _revisions?: {
+                ids: RevisionId[];
+                start: number;
+            }
+        }
+        type NewDocument<Content extends Encodable> = Content;
+        type Document<Content extends Encodable> = Content & IdMeta;
+        type ExistingDocument<Content extends Encodable> =
+                Document<Content> & RevisionIdMeta;
+
+        interface AllDocsOptions extends Options {
+            /** Include attachment data for each document.
+             *
+             * Requires `include_docs` to be `true`.
+             *
+             * By default, attachments are Base64-encoded.
+             * @see binary
+             */
+            attachments?: boolean;
+            /** Return attachments as Buffers.
+             *
+             * Requires `include_docs` to be `true`.
+             * Requires `attachments` to be `true`. */
+            binary?: boolean;
+            /** Include conflict information for each document.
+             *
+             * Requires `include_docs` to be `true`. */
+            conflicts?: boolean;
+            /** Reverse ordering of results. */
+            descending?: boolean;
+            /** Include contents for each document. */
+            include_docs?: boolean;
+            /** Maximum number of documents to return. */
+            limit?: number;
+            /** Number of documents to skip before returning.
+             *
+             * Causes poor performance on IndexedDB and LevelDB. */
+            skip?: number;
+        }
+        interface AllDocsWithKeyOptions extends AllDocsOptions {
+            /** Constrain results to documents matching this key. */
+            key: DocumentKey;
+        }
+        interface AllDocsWithKeysOptions extends AllDocsOptions {
+            /** Constrains results to documents matching any of these keys. */
+            keys: DocumentId[];
+        }
+        interface AllDocsWithinRangeOptions extends AllDocsOptions {
+            /** Low end of range, or high end if `descending` is `true`. */
+            startkey: DocumentKey;
+            /** High end of range, or low end if `descending` is `true`. */
+            endkey: DocumentKey;
+            /** Include any documents identified by `endkey`.
+             *
+             * Defaults to `true`. */
+            inclusive_end?: boolean;
+        }
+        interface AllDocsMeta {
+            _attachments?: {
+                [attachmentId: string]: Attachment;
+            };
+        }
+        interface AllDocsResponse<Content extends Core.Encodable> {
+            /** The `skip` if provided, or in CouchDB the actual offset */
+            offset: number;
+            total_rows: number;
+            rows: {
+                /** Only present if `include_docs` was `true`. */
+                doc?: Document<Content & AllDocsMeta>;
+                id: DocumentId;
+                key: DocumentKey;
+                value: {
+                    rev: RevisionId;
+                }
+            }[];
+        }
+
+        interface DestroyOptions extends Options {
+        }
+
+        interface GetOptions extends Options {
+            /** Include list of conflicting leaf revisions. */
+            conflicts?: boolean;
+            /** Specific revision to fetch */
+            rev?: RevisionId;
+            /** Include revision history of the document. */
+            revs?: boolean;
+            /** Include a list of revisions of the document, and their
+             * availability. */
+            revs_info?: boolean;
+        }
+        interface GetOpenRevisions extends Options {
+            /** Fetch all leaf revisions if open_revs="all" or fetch all leaf
+             * revisions specified in open_revs array. Leaves will be returned
+             * in the same order as specified in input array. */
+            open_revs: 'all' | Core.RevisionId[];
+        }
+
+        /** @todo does this have any other properties? */
+        interface PutOptions extends Options {
+        }
+        interface PostOptions extends PutOptions {
+        }
+
+        interface CompactOptions extends Core.Options {
+          interval?: number;
+        }
+
+        interface InfoOptions extends Options {
+        }
+    }
+
+    /**
+     * Pass this to `PouchDB.plugin()`.
+     */
+    export type Plugin = 'This should be passed to PouchDB.plugin()';
+
+    namespace Configuration {
+        interface CommonDatabaseConfiguration {
+            /**
+             * Database name.
+             */
+            name?: string;
+            /**
+             * Database adapter to use.
+             *
+             * If unspecified, PouchDB will infer this automatically, preferring
+             * IndexedDB to WebSQL in browsers that support both (i.e. Chrome,
+             * Opera and Android 4.4+).
+             */
+            adapter?: string;
+        }
+
+        interface LocalDatabaseConfiguration extends CommonDatabaseConfiguration {
+            /**
+             * Enables auto compaction, which means compact() is called after
+             * every change to the database.
+             *
+             * Defaults to false.
+             */
+            auto_compaction?: boolean;
+            /**
+             * How many old revisions we keep track (not a copy) of.
+             */
+            revs_limit?: number;
+        }
+
+        interface RemoteRequesterConfiguration {
+            /**
+             * Time before HTTP requests time out (in ms).
+             */
+            timeout?: number;
+            /**
+             * Appends a random string to the end of all HTTP GET requests to avoid
+             * them being cached on IE. Set this to true to prevent this happening.
+             */
+            cache?: boolean;
+            /**
+             * HTTP headers to add to requests.
+             */
+            headers?: {
+                [name: string]: string;
+            }
+            username?: string;
+            password?: string;
+            /**
+             * Enables transferring cookies and HTTP Authorization information.
+             *
+             * Defaults to true.
+             */
+            withCredentials?: boolean;
+            /**
+             * Disables automatic creation of databases.
+             */
+            skip_setup?: boolean;
+        }
+
+        interface RemoteDatabaseConfiguration extends CommonDatabaseConfiguration {
+            ajax?: RemoteRequesterConfiguration;
+        }
+
+        type DatabaseConfiguration = LocalDatabaseConfiguration |
+                RemoteDatabaseConfiguration;
+    }
+
+
+
+    interface Static {
+        plugin(plugin: Plugin): Static;
+
+        new<Content extends Core.Encodable>(name?: string,
+            options?: Configuration.DatabaseConfiguration): Database<Content>;
+    }
+
+    interface Database<Content extends Core.Encodable>  {
+        /** Fetch all documents matching the given key. */
+        allDocs(options: Core.AllDocsWithKeyOptions):
+            Promise<Core.AllDocsResponse<Content>>;
+        /** Fetch all documents matching any of the given keys. */
+        allDocs(options: Core.AllDocsWithKeysOptions):
+            Promise<Core.AllDocsResponse<Content>>;
+        /** Fetch all documents matching the given key range. */
+        allDocs(options: Core.AllDocsWithinRangeOptions):
+            Promise<Core.AllDocsResponse<Content>>;
+        /** Fetch all documents. */
+        allDocs(options?: Core.AllDocsOptions):
+            Promise<Core.AllDocsResponse<Content>>;
+
+        bulkDocs(docs: Core.Document<Content>[],
+                 options: Core.PutOptions | void,
+                 callback: Core.Callback<Core.Error, Core.Response[]>): void;
+        bulkDocs(docs: Core.Document<Content>[],
+                 options?: Core.PutOptions): Promise<Core.Response[]>;
+
+        /** Compact the database */
+        compact(options?: Core.CompactOptions): Promise<Core.Response>;
+        compact(options: Core.CompactOptions,
+                callback: Core.Callback<Core.Error, Core.Response>): void;
+
+        /** Destroy the database */
+        destroy(options: Core.DestroyOptions | void,
+            callback: Core.AnyCallback): void;
+        destroy(options?: Core.DestroyOptions | void): Promise<void>;
+
+        /** Fetch a document */
+        get(docId: Core.DocumentId,
+            options: Core.GetOpenRevisions): Promise<Core.Revision<Content>[]>;
+        get(docId: Core.DocumentId,
+            options: Core.GetOpenRevisions,
+            callback: Core.Callback<any,
+            Core.Revision<Content>[]>): void;
+        get(docId: Core.DocumentId,
+            options: Core.GetOptions
+            ): Promise<Core.Document<Content> & Core.GetMeta>;
+        get(docId: Core.DocumentId,
+            options: Core.GetOptions,
+            callback: Core.Callback<any, Core.Document<Content> & Core.GetMeta>
+            ): void;
+        get(docId: Core.DocumentId,
+            options: void,
+            callback: Core.Callback<any, Core.Document<Content>>): void;
+        get(docId: Core.DocumentId): Promise<Core.Document<Content>>;
+
+        /** Create a new document without providing an id.
+         *
+         * You should prefer put() to post(), because when you post(), you are
+         * missing an opportunity to use allDocs() to sort documents by _id
+         * (because your _ids are random).
+         *
+         * @see {@link https://pouchdb.com/2014/06/17/12-pro-tips-for-better-code-with-pouchdb.html|PouchDB Pro Tips}
+         * */
+        post(doc: Core.NewDocument<Content>,
+            options: Core.PostOptions | void,
+            callback: Core.Callback<Core.Error, Core.Response>): void;
+        post(doc: Core.NewDocument<Content>,
+            options?: Core.PostOptions): Promise<Core.Response>;
+
+        /** Create a new document or update an existing document.
+         *
+         * If the document already exists, you must specify its revision _rev,
+         * otherwise a conflict will occur.
+         * There are some restrictions on valid property names of the documents.
+         * If you try to store non-JSON data (for instance Date objects) you may
+         * see inconsistent results. */
+        put(doc: Core.Document<Content>,
+            id: Core.DocumentId | void,
+            revision: Core.RevisionId | void,
+            options: Core.PutOptions | void,
+            callback: Core.Callback<Core.Error, Core.Response>): void;
+        put(doc: Core.Document<Content>,
+            id?: Core.DocumentId,
+            revision?: Core.RevisionId,
+            options?: Core.PutOptions): Promise<Core.Response>;
+
+        /** Remove a doc from the database */
+        remove(doc: Core.Document<Content>,
+               options: Core.Options,
+               callback: Core.Callback<Core.Error, Core.Response>): void;
+        remove(docId: Core.DocumentId,
+               revision: Core.RevisionId,
+               options: Core.Options,
+               callback: Core.Callback<Core.Error, Core.Response>): void;
+        remove(doc: Core.Document<Content>,
+               options?: Core.Options): Promise<Core.Response>;
+        remove(docId: Core.DocumentId,
+               revision: Core.RevisionId,
+               options?: Core.Options): Promise<Core.Response>;
+
+        /** Get database information */
+        info(options: Core.InfoOptions | void,
+            callback: Core.Callback<any, Core.DatabaseInfo>): void;
+        info(options?: Core.InfoOptions): Promise<Core.DatabaseInfo>;
+    }
+}
+
+declare module 'pouchdb-core' {
+  const PouchDb: PouchDB.Static;
+  export = PouchDb;
+}
+
+declare var PouchDB: PouchDB.Static;

+ 8 - 0
typings/globals/pouchdb-core/typings.json

@@ -0,0 +1,8 @@
+{
+  "resolution": "main",
+  "tree": {
+    "src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/0fa2d359311a996084dc3bb67a80365992e3ba42/pouchdb-core/pouchdb-core.d.ts",
+    "raw": "registry:dt/pouchdb-core#5.4.4+20160919190957",
+    "typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/0fa2d359311a996084dc3bb67a80365992e3ba42/pouchdb-core/pouchdb-core.d.ts"
+  }
+}

+ 1 - 1
typings/index.d.ts

@@ -1,3 +1,3 @@
-/// <reference path="globals/pouchdb-adapter-websql/index.d.ts" />
+/// <reference path="globals/pouchdb-core/index.d.ts" />
 /// <reference path="globals/pouchdb/index.d.ts" />
 /// <reference path="modules/async/index.d.ts" />