Type for Cordova SQLite pouchdb adapter (#36395)

* Types for pouchdb cordova sqlite adapter

* Tests

* Remove empty interface

* Formatting tweak

* Fix whitespace

* Link to specific package

* Corrected heading comment

* Matching version number style from build

* Missing reference from main index

* Increment version
This commit is contained in:
Matt
2019-07-01 16:26:15 +01:00
committed by Ben Lichtman
parent 622d32ca3f
commit fd5ddb9e4b
5 changed files with 103 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
// Type definitions for pouchdb-adapter-sqlite 1.0
// Project: https://pouchdb.com/, https://github.com/pouchdb/pouchdb, https://github.com/pouchdb-community/pouchdb-adapter-cordova-sqlite
// Definitions by: Simon Paulger <https://github.com/spaulg>, Brian Geppert <https://github.com/geppy>, Frederico Galvão <https://github.com/fredgalvao>, Matthew Paul <https://github.com/coffeymatt>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="pouchdb-core" />
declare namespace PouchDB {
namespace AdapterCordovaSqlite {
interface Configuration extends Configuration.LocalDatabaseConfiguration {
/**
* Location of database e.g. 'Default'.
*/
location?: string;
/**
* Location of database e.g. 'Default'. Only use 'location' or 'iosDatabaseLocation' not both.
*/
iosDatabaseLocation?: string;
/**
* Version of android database to use.
*/
androidDatabaseImplementation?: number;
/**
* Enable autocompation of database.
*/
auto_compaction?: boolean;
adapter: 'cordova-sqlite';
}
}
interface Static {
new<Content extends {}>(name: string | null,
options: AdapterCordovaSqlite.Configuration): Database<Content>;
}
}
declare module 'pouchdb-adapter-cordova-sqlite' {
const plugin: PouchDB.Plugin;
export = plugin;
}

View File

@@ -0,0 +1,24 @@
function testConstructor() {
let db = new PouchDB('basic');
db = new PouchDB(null, {
adapter: 'cordova-sqlite'
});
db = new PouchDB('location', {
adapter: 'cordova-sqlite',
location: 'default'
});
db = new PouchDB('ioslocation', {
adapter: 'cordova-sqlite',
iosDatabaseLocation: 'default'
});
db = new PouchDB('androidDatabaseImplementation', {
adapter: 'cordova-sqlite',
location: 'default',
androidDatabaseImplementation: 2
});
db = new PouchDB('auto_compaction', {
adapter: 'cordova-sqlite',
location: 'default',
auto_compaction: true
});
}

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"pouchdb-adapter-cordova-sqlite-tests.ts"
]
}

View File

@@ -0,0 +1,8 @@
{
"extends": "dtslint/dt.json",
"rules": {
"no-declare-current-package": false,
"no-unnecessary-generics": false,
"no-single-declare-module": false
}
}

View File

@@ -1,9 +1,10 @@
// Type definitions for pouchdb 6.3
// Type definitions for pouchdb 6.4
// Project: https://pouchdb.com/, https://github.com/pouchdb/pouchdb
// Definitions by: Andy Brown <https://github.com/AGBrown>, Brian Geppert <https://github.com/geppy>, Frederico Galvão <https://github.com/fredgalvao>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types='pouchdb-adapter-cordova-sqlite' />
/// <reference types='pouchdb-adapter-fruitdown' />
/// <reference types='pouchdb-adapter-http' />
/// <reference types='pouchdb-adapter-idb' />