mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 13:27:15 +08:00
Pouchdb (#10171)
* Started definitions for multi-module PouchDB * Fixed whitespace * Updated PouchDB definitions for v5.4.4.
This commit is contained in:
@@ -1,142 +0,0 @@
|
||||
/// <reference path="pouch.d.ts" />
|
||||
|
||||
window.alert = function (thing?: string) {
|
||||
var div = document.createElement('div');
|
||||
div.appendChild(document.createTextNode(thing));
|
||||
document.getElementsByTagName('body')[0].appendChild(div);
|
||||
}
|
||||
|
||||
var pouch: PouchDB;
|
||||
|
||||
function pouchTests() {
|
||||
new PouchDB('testdb', function (err: PouchError, res: PouchDB) {
|
||||
if (err) {
|
||||
alert('Error ' + err.status + ' occurred ' + err.error + ' - ' + err.reason);
|
||||
}
|
||||
else {
|
||||
pouch = res;
|
||||
alert("database opened");
|
||||
runTests();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var tests = [
|
||||
setupTests,
|
||||
testId,
|
||||
testAllDocs,
|
||||
testGet,
|
||||
testUpdate,
|
||||
testDelete,
|
||||
deleteDb
|
||||
];
|
||||
|
||||
var testIndex;
|
||||
|
||||
var revs: any = {};
|
||||
|
||||
function runTests() {
|
||||
testIndex = 0;
|
||||
tests[testIndex++]();
|
||||
}
|
||||
|
||||
// each test function except the last one needs to call nextTest when it is finished doing its thing.
|
||||
function nextTest() {
|
||||
alert("starting test " + testIndex);
|
||||
tests[testIndex++]();
|
||||
}
|
||||
|
||||
function setupTests() {
|
||||
alert('setupTests');
|
||||
pouch.bulkDocs({
|
||||
docs: [{ _id: '1', name: 'record 1' },
|
||||
{ _id: '2', name: 'record 2' },
|
||||
{ _id: '3', name: 'record 3' }
|
||||
]
|
||||
}, function (err: PouchError, res: PouchUpdateResponse[]) {
|
||||
if (err) {
|
||||
alert('Error ' + err.status + ' occurred ' + err.error + ' - ' + err.reason);
|
||||
}
|
||||
else {
|
||||
for (var i = 0; i < res.length; i++) {
|
||||
if (res[i].ok) {
|
||||
revs[res[i].id] = res[i].rev;
|
||||
}
|
||||
}
|
||||
alert("test records loaded");
|
||||
}
|
||||
nextTest();
|
||||
});
|
||||
}
|
||||
|
||||
function testId() {
|
||||
alert('testId');
|
||||
var id = pouch.id();
|
||||
alert('Database Id = ' + id);
|
||||
nextTest();
|
||||
}
|
||||
|
||||
function testGet() {
|
||||
alert('testGet');
|
||||
pouch.get('1', function (err: PouchError, res: PouchGetResponse) {
|
||||
if (err) {
|
||||
alert('Error ' + err.status + ' occurred ' + err.error + ' - ' + err.reason);
|
||||
}
|
||||
else {
|
||||
alert('Retrieved record with id=1, name=[' + res['name'] + ']');
|
||||
}
|
||||
nextTest();
|
||||
});
|
||||
}
|
||||
|
||||
function testAllDocs() {
|
||||
alert('testAllDocs');
|
||||
pouch.allDocs(function (err: PouchError, res: PouchAllDocsResponse) {
|
||||
alert('allDocs resulted in ' + res.total_rows + ' results');
|
||||
for (var i = 0; i < res.total_rows; i++) {
|
||||
alert('Retrieved record with id=' + res.rows[i].id + ', rev=[' + res.rows[i].value.rev + ']');
|
||||
}
|
||||
nextTest();
|
||||
});
|
||||
}
|
||||
|
||||
function testUpdate() {
|
||||
alert('testUpdate');
|
||||
pouch.put({ _id: '2', _rev: revs['2'], name: 'record 2 updated' }, function (err: PouchError, res: PouchUpdateResponse) {
|
||||
if (err) {
|
||||
alert('Error ' + err.status + ' occurred ' + err.error + ' - ' + err.reason);
|
||||
}
|
||||
else {
|
||||
alert('record updated id=' + res.id + ', rev=[' + res.rev + ']');
|
||||
}
|
||||
testAllDocs(); // spit out the db contents and then go on
|
||||
});
|
||||
}
|
||||
|
||||
function testDelete() {
|
||||
alert('testDelete');
|
||||
pouch.remove({ _id: '3', _rev: revs['3'] }, function (err: PouchError, res: PouchUpdateResponse) {
|
||||
if (err) {
|
||||
alert('Error ' + err.status + ' occurred ' + err.error + ' - ' + err.reason);
|
||||
}
|
||||
else {
|
||||
alert('record deleted id=' + res.id + ', rev=[' + res.rev + ']');
|
||||
}
|
||||
testAllDocs(); // spit out the db contents and then go on
|
||||
});
|
||||
}
|
||||
|
||||
function deleteDb() {
|
||||
alert('deleteDb');
|
||||
if (pouch) {
|
||||
pouch = null;
|
||||
PouchDB.destroy('testdb', function (err: PouchError) {
|
||||
if (err) {
|
||||
alert('Error ' + err.status + ' occurred ' + err.error + ' - ' + err.reason);
|
||||
}
|
||||
else {
|
||||
alert("database destroyed");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
232
pouchDB/pouch.d.ts
vendored
232
pouchDB/pouch.d.ts
vendored
@@ -1,232 +0,0 @@
|
||||
// Type definitions for Pouch 0.1
|
||||
// Project: http://pouchdb.com
|
||||
// Definitions by: Bill Sears <https://github.com/MrBigDog2U/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
interface PouchError {
|
||||
status: number;
|
||||
error: string;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
interface PouchApi {
|
||||
type(): string;
|
||||
id(): string;
|
||||
close(callback: () => void): void;
|
||||
}
|
||||
|
||||
interface PouchInfoResponse {
|
||||
db_name: string;
|
||||
doc_count: number;
|
||||
update_seq: string;
|
||||
}
|
||||
|
||||
interface PouchApi {
|
||||
info(callback: (err: PouchError, res: PouchInfoResponse) => void): void;
|
||||
}
|
||||
|
||||
interface PouchGetOptions {
|
||||
rev?: string;
|
||||
revs?: boolean;
|
||||
revs_info?: boolean;
|
||||
conflicts?: boolean;
|
||||
attachments?: boolean;
|
||||
}
|
||||
|
||||
interface PouchGetResponse {
|
||||
_id: string;
|
||||
_rev: string;
|
||||
_attachments: any;
|
||||
}
|
||||
|
||||
interface PouchAllDocsOptions {
|
||||
startkey?: string;
|
||||
endKey?: string;
|
||||
descending?: boolean;
|
||||
include_docs?: boolean;
|
||||
conflicts?: boolean;
|
||||
}
|
||||
|
||||
interface PouchAllDocsItem {
|
||||
id: string;
|
||||
key: string;
|
||||
value: any;
|
||||
doc: any;
|
||||
}
|
||||
|
||||
interface PouchAllDocsResponse {
|
||||
total_rows: number;
|
||||
rows: PouchAllDocsItem[];
|
||||
}
|
||||
|
||||
interface PouchApi {
|
||||
//
|
||||
// get == select by id
|
||||
//
|
||||
get(id: string, opts: PouchGetOptions, callback: (err: PouchError, res: PouchGetResponse) => void): void;
|
||||
get(id: string, callback: (err: PouchError, res: PouchGetResponse) => void): void;
|
||||
allDocs(opts: PouchAllDocsOptions, callback: (err: PouchError, res: PouchAllDocsResponse) => void): void;
|
||||
allDocs(callback: (err: PouchError, res: PouchAllDocsResponse) => void): void;
|
||||
}
|
||||
|
||||
interface PouchBulkDocsRequest {
|
||||
docs: any[];
|
||||
}
|
||||
|
||||
interface PouchUpdateOptions {
|
||||
new_edits?: boolean;
|
||||
}
|
||||
|
||||
interface PouchUpdateResponse {
|
||||
ok: boolean;
|
||||
id: string;
|
||||
rev: string;
|
||||
}
|
||||
|
||||
interface PouchApi {
|
||||
bulkDocs(req: PouchBulkDocsRequest, opts: PouchUpdateOptions, callback: (err: PouchError, res: PouchUpdateResponse[]) => void): void;
|
||||
bulkDocs(req: PouchBulkDocsRequest, callback: (err: PouchError, res: PouchUpdateResponse[]) => void): void;
|
||||
//
|
||||
// post == insert (doc does not contain an _id)
|
||||
//
|
||||
post(doc: any, opts: PouchUpdateOptions, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
|
||||
post(doc: any, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
|
||||
//
|
||||
// put == update (doc DOES contain an _id)
|
||||
//
|
||||
put(doc: any, opts: PouchUpdateOptions, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
|
||||
put(doc: any, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
|
||||
//
|
||||
// remove == delete
|
||||
//
|
||||
remove(doc: any, opts: PouchUpdateOptions, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
|
||||
remove(doc: any, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
|
||||
}
|
||||
|
||||
interface PouchFilter {
|
||||
map: (doc: any) => void;
|
||||
reduce?: (key: string, value: any) => any;
|
||||
}
|
||||
|
||||
interface PouchQueryOptions {
|
||||
complete?: any;
|
||||
include_docs?: boolean;
|
||||
error?: (err: PouchError) => void;
|
||||
descending?: boolean;
|
||||
reduce?: boolean;
|
||||
}
|
||||
|
||||
interface PouchQueryResponse {
|
||||
rows: any[];
|
||||
}
|
||||
|
||||
interface PouchApi {
|
||||
//
|
||||
// query == select by other criteria
|
||||
//
|
||||
query(fun: string, opts: PouchQueryOptions, callback: (err: PouchError, res: PouchQueryResponse) => void): void;
|
||||
query(fun: string, callback: (err: PouchError, res: PouchQueryResponse) => void): void;
|
||||
query(fun: PouchFilter, opts: PouchQueryOptions, callback: (err: PouchError, res: PouchQueryResponse) => void): void;
|
||||
query(fun: PouchFilter, callback: (err: PouchError, res: PouchQueryResponse) => void): void;
|
||||
}
|
||||
|
||||
interface PouchAttachmentOptions {
|
||||
decode?: boolean;
|
||||
}
|
||||
|
||||
interface PouchApi {
|
||||
getAttachment(id: string, opts: PouchAttachmentOptions, callback: (err: PouchError, res: any) => void): void;
|
||||
getAttachment(id: string, callback: (err: PouchError, res: any) => void): void;
|
||||
putAttachment(id: string, rev: string, doc: any, type: string, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
|
||||
removeAttachment(id: string, rev: string, callback: (err: PouchError, res: PouchUpdateResponse) => void): void;
|
||||
}
|
||||
|
||||
interface PouchCancellable {
|
||||
cancel: () => void;
|
||||
}
|
||||
|
||||
interface PouchChangesOptions {
|
||||
onChange: (change: PouchChange) => void;
|
||||
complete?: (err: PouchError, res: PouchChanges) => void;
|
||||
seq?: number;
|
||||
since?: number;
|
||||
descending?: boolean;
|
||||
filter?: PouchFilter;
|
||||
continuous?: boolean;
|
||||
include_docs?: boolean;
|
||||
conflicts?: boolean;
|
||||
}
|
||||
|
||||
interface PouchChange {
|
||||
changes: any;
|
||||
doc: PouchGetResponse;
|
||||
id: string;
|
||||
seq: number;
|
||||
}
|
||||
|
||||
interface PouchChanges {
|
||||
results: PouchChange[];
|
||||
}
|
||||
|
||||
interface PouchApi {
|
||||
changes(opts: PouchChangesOptions, callback: (err: PouchError, res: PouchChanges) => void): PouchCancellable;
|
||||
changes(callback: (err: PouchError, res: PouchChanges) => void): PouchCancellable;
|
||||
}
|
||||
|
||||
interface PouchRevsDiffOptions {
|
||||
}
|
||||
|
||||
interface PouchReplicateOptions {
|
||||
continuous?: boolean;
|
||||
onChange?: (e: any) => void;
|
||||
filter?: any; // Can be either string or PouchFilter
|
||||
complete?: (err: PouchError, res: PouchChanges) => void;
|
||||
}
|
||||
|
||||
interface PouchReplicateResponse {
|
||||
ok: boolean;
|
||||
start_time: Date;
|
||||
end_time: Date;
|
||||
docs_read: number;
|
||||
docs_written: number;
|
||||
}
|
||||
|
||||
interface PouchReplicate {
|
||||
from(url: string, opts: PouchReplicateOptions, callback: (err: PouchError, res: PouchReplicateResponse) => void): PouchCancellable;
|
||||
from(url: string, callback: (err: PouchError, res: PouchReplicateResponse) => void): PouchCancellable;
|
||||
to(dbName: string, opts: PouchReplicateOptions, callback: (err: PouchError, res: PouchReplicateResponse) => void): PouchCancellable;
|
||||
to(dbName: string, callback: (err: PouchError, res: PouchReplicateResponse) => void): PouchCancellable;
|
||||
}
|
||||
|
||||
interface PouchApi {
|
||||
revsDiff(req: any, opts: PouchRevsDiffOptions, callback: (missing: any) => void): void;
|
||||
revsDiff(req: any, callback: (missing: any) => void): void;
|
||||
replicate: PouchReplicate;
|
||||
}
|
||||
|
||||
interface PouchOptions {
|
||||
name?: string;
|
||||
adapter?: string;
|
||||
skip_setup?: boolean;
|
||||
}
|
||||
|
||||
interface PouchDB extends PouchApi {
|
||||
new (name: string, opts: PouchOptions, callback: (err: PouchError, res: PouchDB) => void): PouchDB;
|
||||
new (name: string, callback: (err: PouchError, res: PouchDB) => void): PouchDB;
|
||||
new (name: string, opts: PouchOptions): PouchDB;
|
||||
new (name: string): PouchDB;
|
||||
destroy(name: string, callback: (err: PouchError) => void): void;
|
||||
}
|
||||
|
||||
declare var PouchDB: PouchDB;
|
||||
|
||||
// Support AMD require
|
||||
declare module 'pouchdb' {
|
||||
export = PouchDB;
|
||||
}
|
||||
|
||||
//
|
||||
// emit is the function that the PouchFilter.map function should call in order to add a particular item to
|
||||
// a filter view.
|
||||
//
|
||||
declare function emit(key: any, value: any): void;
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
18
pouchdb-adapter-fruitdown/pouchdb-adapter-fruitdown-tests.ts
Normal file
18
pouchdb-adapter-fruitdown/pouchdb-adapter-fruitdown-tests.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-adapter-fruitdown.d.ts" />
|
||||
|
||||
namespace PouchDBAdapterFruitdownTests {
|
||||
function testConstructor() {
|
||||
type MyModel = { numericProperty: number };
|
||||
let model: PouchDB.Core.Document<MyModel>;
|
||||
|
||||
let db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'fruitdown',
|
||||
});
|
||||
db.get('model').then((result) => model);
|
||||
db = new PouchDB<MyModel>('myDb', {
|
||||
adapter: 'fruitdown',
|
||||
});
|
||||
db.get('model').then((result) => model);
|
||||
}
|
||||
}
|
||||
26
pouchdb-adapter-fruitdown/pouchdb-adapter-fruitdown.d.ts
vendored
Normal file
26
pouchdb-adapter-fruitdown/pouchdb-adapter-fruitdown.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Type definitions for pouchdb-adapter-fruitdown v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
|
||||
declare namespace PouchDB {
|
||||
namespace FruitDOWNAdapter {
|
||||
interface FruitDOWNAdapterConfiguration
|
||||
extends Configuration.LocalDatabaseConfiguration {
|
||||
adapter: 'fruitdown';
|
||||
}
|
||||
}
|
||||
|
||||
interface Static {
|
||||
new<Content extends Core.Encodable>(name: string | void,
|
||||
options: FruitDOWNAdapter.FruitDOWNAdapterConfiguration
|
||||
): Database<Content>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'pouchdb-adapter-fruitdown' {
|
||||
const plugin: PouchDB.Plugin;
|
||||
export = plugin;
|
||||
}
|
||||
8
pouchdb-adapter-http/pouchdb-adapter-http-tests.ts
Normal file
8
pouchdb-adapter-http/pouchdb-adapter-http-tests.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-adapter-http.d.ts" />
|
||||
|
||||
function testHttpDbCreation() {
|
||||
const basicDB = new PouchDB('basic', {
|
||||
adapter: 'http'
|
||||
});
|
||||
}
|
||||
26
pouchdb-adapter-http/pouchdb-adapter-http.d.ts
vendored
Normal file
26
pouchdb-adapter-http/pouchdb-adapter-http.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Type definitions for pouchdb-http v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
|
||||
declare namespace PouchDB {
|
||||
namespace HttpAdapter {
|
||||
interface HttpAdapterConfiguration
|
||||
extends Configuration.RemoteDatabaseConfiguration {
|
||||
adapter: 'http';
|
||||
}
|
||||
}
|
||||
|
||||
interface Static {
|
||||
new<Content extends Core.Encodable>(name: string | void,
|
||||
options: HttpAdapter.HttpAdapterConfiguration
|
||||
): Database<Content>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'pouchdb-adapter-http' {
|
||||
const plugin: PouchDB.Plugin;
|
||||
export = plugin;
|
||||
}
|
||||
16
pouchdb-adapter-idb/pouchdb-adapter-idb-tests.ts
Normal file
16
pouchdb-adapter-idb/pouchdb-adapter-idb-tests.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-adapter-idb.d.ts" />
|
||||
|
||||
function testIdbDbCreation() {
|
||||
const basicDB = new PouchDB('basic', {
|
||||
adapter: 'idb'
|
||||
});
|
||||
const persistentDb = new PouchDB('persistent', {
|
||||
adapter: 'idb',
|
||||
storage: 'persistent'
|
||||
});
|
||||
const temporaryDb = new PouchDB('temporary', {
|
||||
adapter: 'idb',
|
||||
storage: 'temporary'
|
||||
});
|
||||
}
|
||||
38
pouchdb-adapter-idb/pouchdb-adapter-idb.d.ts
vendored
Normal file
38
pouchdb-adapter-idb/pouchdb-adapter-idb.d.ts
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// Type definitions for pouchdb-adapter-idb v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
|
||||
declare namespace PouchDB {
|
||||
namespace Core {
|
||||
interface DatabaseInfo {
|
||||
idb_attachment_format?: 'base64' | 'binary';
|
||||
}
|
||||
}
|
||||
|
||||
namespace IdbAdapter {
|
||||
interface IdbAdapterConfiguration
|
||||
extends Configuration.LocalDatabaseConfiguration {
|
||||
/**
|
||||
* Configures storage persistence.
|
||||
*
|
||||
* Only works in Firefox 26+.
|
||||
*/
|
||||
storage?: 'persistent' | 'temporary';
|
||||
adapter: 'idb';
|
||||
}
|
||||
}
|
||||
|
||||
interface Static {
|
||||
new<Content extends Core.Encodable>(name: string | void,
|
||||
options: IdbAdapter.IdbAdapterConfiguration
|
||||
): Database<Content>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'pouchdb-adapter-idb' {
|
||||
const plugin: PouchDB.Plugin;
|
||||
export = plugin;
|
||||
}
|
||||
15
pouchdb-adapter-leveldb/pouchdb-adapter-leveldb-tests.ts
Normal file
15
pouchdb-adapter-leveldb/pouchdb-adapter-leveldb-tests.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-adapter-leveldb.d.ts" />
|
||||
|
||||
namespace PouchDBAdapterLevelDBTests {
|
||||
function testConstructor() {
|
||||
type MyModel = { numericProperty: number };
|
||||
|
||||
let db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'leveldb',
|
||||
});
|
||||
db = new PouchDB<MyModel>('myDb', {
|
||||
adapter: 'leveldb',
|
||||
});
|
||||
}
|
||||
}
|
||||
25
pouchdb-adapter-leveldb/pouchdb-adapter-leveldb.d.ts
vendored
Normal file
25
pouchdb-adapter-leveldb/pouchdb-adapter-leveldb.d.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// Type definitions for pouchdb-adapter-leveldb v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
|
||||
declare namespace PouchDB {
|
||||
namespace LevelDbAdapter {
|
||||
interface LevelDbAdapterConfiguration extends Configuration.LocalDatabaseConfiguration {
|
||||
adapter: 'leveldb';
|
||||
}
|
||||
}
|
||||
|
||||
interface Static {
|
||||
new<Content extends Core.Encodable>(name: string | void,
|
||||
options: LevelDbAdapter.LevelDbAdapterConfiguration
|
||||
): Database<Content>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'pouchdb-adapter-leveldb' {
|
||||
const plugin: PouchDB.Plugin;
|
||||
export = plugin;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-adapter-localstorage.d.ts" />
|
||||
|
||||
namespace PouchDBAdapterLocalStorageyTests {
|
||||
function testConstructor() {
|
||||
type MyModel = { numericProperty: number };
|
||||
|
||||
let db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'localstorage',
|
||||
});
|
||||
db = new PouchDB<MyModel>('myDb', {
|
||||
adapter: 'localstorage',
|
||||
});
|
||||
}
|
||||
}
|
||||
26
pouchdb-adapter-localstorage/pouchdb-adapter-localstorage.d.ts
vendored
Normal file
26
pouchdb-adapter-localstorage/pouchdb-adapter-localstorage.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Type definitions for pouchdb-adapter-localstorage v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
|
||||
declare namespace PouchDB {
|
||||
namespace LocalStorageAdapter {
|
||||
interface LocalStorageAdapterConfiguration
|
||||
extends Configuration.LocalDatabaseConfiguration {
|
||||
adapter: 'localstorage';
|
||||
}
|
||||
}
|
||||
|
||||
interface Static {
|
||||
new<Content extends Core.Encodable>(name: string | void,
|
||||
options: LocalStorageAdapter.LocalStorageAdapterConfiguration
|
||||
): Database<Content>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'pouchdb-adapter-localstorage' {
|
||||
const plugin: PouchDB.Plugin;
|
||||
export = plugin;
|
||||
}
|
||||
15
pouchdb-adapter-memory/pouchdb-adapter-memory-tests.ts
Normal file
15
pouchdb-adapter-memory/pouchdb-adapter-memory-tests.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-adapter-memory.d.ts" />
|
||||
|
||||
namespace PouchDBAdapterMemoryTests {
|
||||
function testConstructor() {
|
||||
type MyModel = { numericProperty: number };
|
||||
|
||||
let db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'memory',
|
||||
});
|
||||
db = new PouchDB<MyModel>('myDb', {
|
||||
adapter: 'memory',
|
||||
});
|
||||
}
|
||||
}
|
||||
26
pouchdb-adapter-memory/pouchdb-adapter-memory.d.ts
vendored
Normal file
26
pouchdb-adapter-memory/pouchdb-adapter-memory.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Type definitions for pouchdb-adapter-memory v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
|
||||
declare namespace PouchDB {
|
||||
namespace MemoryAdapter {
|
||||
interface MemoryAdapterConfiguration
|
||||
extends Configuration.LocalDatabaseConfiguration {
|
||||
adapter: 'memory';
|
||||
}
|
||||
}
|
||||
|
||||
interface Static {
|
||||
new<Content extends Core.Encodable>(name: string | void,
|
||||
options: MemoryAdapter.MemoryAdapterConfiguration
|
||||
): Database<Content>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'pouchdb-adapter-memory' {
|
||||
const plugin: PouchDB.Plugin;
|
||||
export = plugin;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-adapter-node-websql.d.ts" />
|
||||
|
||||
namespace PouchDBAdapterNodeWebSQLTests {
|
||||
function isBoolean(someBoolean: boolean) {
|
||||
}
|
||||
function isNumber(someNumber: number) {
|
||||
}
|
||||
function isString(someString: string) {
|
||||
}
|
||||
|
||||
function testConstructor() {
|
||||
type MyModel = { numericProperty: number };
|
||||
|
||||
let db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'websql',
|
||||
size: 5,
|
||||
});
|
||||
db = new PouchDB<MyModel>('myDb', {
|
||||
adapter: 'websql',
|
||||
});
|
||||
|
||||
db.info().then((info) => {
|
||||
isBoolean(info.sqlite_plugin);
|
||||
isString(info.websql_encoding);
|
||||
});
|
||||
}
|
||||
}
|
||||
12
pouchdb-adapter-node-websql/pouchdb-adapter-node-websql.d.ts
vendored
Normal file
12
pouchdb-adapter-node-websql/pouchdb-adapter-node-websql.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// Type definitions for pouchdb-adapter-node-websql v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="../pouchdb-adapter-websql/pouchdb-adapter-websql.d.ts" />
|
||||
|
||||
declare module 'pouchdb-adapter-node-websql' {
|
||||
const plugin: PouchDB.Plugin;
|
||||
export = plugin;
|
||||
}
|
||||
29
pouchdb-adapter-websql/pouchdb-adapter-websql-tests.ts
Normal file
29
pouchdb-adapter-websql/pouchdb-adapter-websql-tests.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-adapter-websql.d.ts" />
|
||||
|
||||
namespace PouchDBAdapterWebSQLTests {
|
||||
function isBoolean(someBoolean: boolean) {
|
||||
}
|
||||
function isNumber(someNumber: number) {
|
||||
}
|
||||
function isString(someString: string) {
|
||||
}
|
||||
|
||||
function testConstructor() {
|
||||
type MyModel = { numericProperty: number };
|
||||
|
||||
let db = new PouchDB('basic');
|
||||
db = new PouchDB(null, {
|
||||
adapter: 'websql'
|
||||
});
|
||||
db = new PouchDB('sized', {
|
||||
adapter: 'websql',
|
||||
size: 10
|
||||
});
|
||||
|
||||
db.info().then((info) => {
|
||||
isBoolean(info.sqlite_plugin);
|
||||
isString(info.websql_encoding);
|
||||
});
|
||||
}
|
||||
}
|
||||
36
pouchdb-adapter-websql/pouchdb-adapter-websql.d.ts
vendored
Normal file
36
pouchdb-adapter-websql/pouchdb-adapter-websql.d.ts
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// Type definitions for pouchdb-adapter-websql v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.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;
|
||||
}
|
||||
19
pouchdb-browser/pouchdb-browser-tests.ts
Normal file
19
pouchdb-browser/pouchdb-browser-tests.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-browser.d.ts" />
|
||||
|
||||
namespace PouchDBBrowserTests {
|
||||
function testConstructor() {
|
||||
type MyModel = { numericProperty: number };
|
||||
let model: PouchDB.Core.Document<MyModel>;
|
||||
|
||||
let db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'idb',
|
||||
});
|
||||
db = new PouchDB<MyModel>('myDb', {
|
||||
adapter: 'http',
|
||||
});
|
||||
db.get('model').then((result) => model);
|
||||
db.viewCleanup().catch((error) => {
|
||||
});
|
||||
}
|
||||
}
|
||||
15
pouchdb-browser/pouchdb-browser.d.ts
vendored
Normal file
15
pouchdb-browser/pouchdb-browser.d.ts
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// Type definitions for pouchdb-browser v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="../pouchdb-adapter-idb/pouchdb-adapter-idb.d.ts" />
|
||||
/// <reference path="../pouchdb-adapter-http/pouchdb-adapter-http.d.ts" />
|
||||
/// <reference path="../pouchdb-mapreduce/pouchdb-mapreduce.d.ts" />
|
||||
/// <reference path="../pouchdb-replication/pouchdb-replication.d.ts" />
|
||||
|
||||
declare module 'pouchdb-browser' {
|
||||
const PouchDb: PouchDB.Static;
|
||||
export = PouchDb;
|
||||
}
|
||||
78
pouchdb-core/pouchdb-core-tests.ts
Normal file
78
pouchdb-core/pouchdb-core-tests.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
/// <reference path="./pouchdb-core.d.ts" />
|
||||
|
||||
namespace PouchDBCoreTests {
|
||||
function isString(someString: string) {
|
||||
}
|
||||
function isNumber(someNumber: number) {
|
||||
}
|
||||
|
||||
function testAllDocs() {
|
||||
const db = new PouchDB<{ foo: number }>();
|
||||
|
||||
db.allDocs().then(({ offset, total_rows, rows }) => {
|
||||
isNumber(offset);
|
||||
isNumber(total_rows);
|
||||
|
||||
rows.forEach(({ id, key, value, doc }) => {
|
||||
isString(id);
|
||||
isString(key);
|
||||
isString(value.rev);
|
||||
|
||||
// check document property
|
||||
isNumber(doc.foo);
|
||||
})
|
||||
});
|
||||
|
||||
db.allDocs({ startkey: "a", endkey: "b" });
|
||||
db.allDocs({ startkey: "a", endkey: "b", inclusive_end: true });
|
||||
db.allDocs({ keys: ["a", "b", "c" ]});
|
||||
db.allDocs({ key: "a" });
|
||||
db.allDocs({
|
||||
attachments: true,
|
||||
binary: true,
|
||||
conflicts: true,
|
||||
descending: true,
|
||||
include_docs: true,
|
||||
limit: 5,
|
||||
skip: 1
|
||||
});
|
||||
}
|
||||
|
||||
function testDestroy() {
|
||||
const db = new PouchDB<{}>();
|
||||
|
||||
db.destroy({}, (error) => {
|
||||
});
|
||||
db.destroy().then(() => {
|
||||
}).catch((error) => {
|
||||
});
|
||||
}
|
||||
|
||||
function testBasics() {
|
||||
type MyModel = { property: 'someProperty '};
|
||||
let model: PouchDB.Core.Document<MyModel>;
|
||||
const id = 'model';
|
||||
|
||||
const db = new PouchDB<MyModel>();
|
||||
|
||||
db.post(model).then((result) => {
|
||||
isString(result.id);
|
||||
});
|
||||
db.post(model, null, (error, response) => {
|
||||
});
|
||||
|
||||
db.get(id).then((result) => model = result);
|
||||
db.get(id, null, (error, result) => {
|
||||
});
|
||||
|
||||
db.put(model).then((error) => {
|
||||
});
|
||||
db.put(model, null, null, null, (error) => {
|
||||
});
|
||||
|
||||
db.info().then((info) => {
|
||||
});
|
||||
db.info({ ajax: { cache: true }}, (error, result) => {
|
||||
});
|
||||
}
|
||||
}
|
||||
334
pouchdb-core/pouchdb-core.d.ts
vendored
Normal file
334
pouchdb-core/pouchdb-core.d.ts
vendored
Normal file
@@ -0,0 +1,334 @@
|
||||
// Type definitions for pouchdb-core v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
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 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>>;
|
||||
|
||||
/** 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>;
|
||||
|
||||
/** 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;
|
||||
14
pouchdb-http/pouchdb-http-tests.ts
Normal file
14
pouchdb-http/pouchdb-http-tests.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-http.d.ts" />
|
||||
|
||||
namespace PouchDBHttpTests {
|
||||
function testConstructor() {
|
||||
type MyModel = { numericProperty: number };
|
||||
let model: PouchDB.Core.Document<MyModel>;
|
||||
|
||||
let db = new PouchDB<MyModel>('myDb', {
|
||||
adapter: 'http',
|
||||
});
|
||||
db.get('model').then((result) => model);
|
||||
}
|
||||
}
|
||||
12
pouchdb-http/pouchdb-http.d.ts
vendored
Normal file
12
pouchdb-http/pouchdb-http.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// Type definitions for pouchdb-http v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="../pouchdb-adapter-http/pouchdb-adapter-http.d.ts" />
|
||||
|
||||
declare module 'pouchdb-http' {
|
||||
const PouchDb: PouchDB.Static;
|
||||
export = PouchDb;
|
||||
}
|
||||
12
pouchdb-mapreduce/pouchdb-mapreduce-tests.ts
Normal file
12
pouchdb-mapreduce/pouchdb-mapreduce-tests.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/// <reference path="../pouchdb-mapreduce/pouchdb-mapreduce.d.ts" />
|
||||
|
||||
namespace PouchDBBrowserTests {
|
||||
function testConstructor() {
|
||||
type MyModel = { numericProperty: number };
|
||||
let model: PouchDB.Core.Document<MyModel>;
|
||||
|
||||
let db = new PouchDB<MyModel>('mydb');
|
||||
db.viewCleanup().catch((error) => {
|
||||
});
|
||||
}
|
||||
}
|
||||
26
pouchdb-mapreduce/pouchdb-mapreduce.d.ts
vendored
Normal file
26
pouchdb-mapreduce/pouchdb-mapreduce.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Type definitions for pouchdb-mapreduce v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
|
||||
declare namespace PouchDB {
|
||||
export interface Database<Content extends Core.Encodable> {
|
||||
/**
|
||||
* Cleans up any stale map/reduce indexes.
|
||||
*
|
||||
* As design docs are deleted or modified, their associated index
|
||||
* files(in CouchDB) or companion databases (in local PouchDBs) continue
|
||||
* to take up space on disk. viewCleanup() removes these unnecessary
|
||||
* index files.
|
||||
*/
|
||||
viewCleanup(callback: PouchDB.Core.Callback<any,void>): void;
|
||||
viewCleanup(): Promise<void>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'pouchdb-adapter-mapreduce' {
|
||||
const plugin: PouchDB.Plugin;
|
||||
export = plugin;
|
||||
}
|
||||
19
pouchdb-node/pouchdb-node-tests.ts
Normal file
19
pouchdb-node/pouchdb-node-tests.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="./pouchdb-node.d.ts" />
|
||||
|
||||
namespace PouchDBBrowserTests {
|
||||
function testConstructor() {
|
||||
type MyModel = { numericProperty: number };
|
||||
let model: PouchDB.Core.Document<MyModel>;
|
||||
|
||||
let db = new PouchDB<MyModel>('myDb', {
|
||||
adapter: 'http',
|
||||
});
|
||||
db = new PouchDB<MyModel>('myDb', {
|
||||
adapter: 'leveldb',
|
||||
});
|
||||
db.get('model').then((result) => model);
|
||||
db.viewCleanup().catch((error) => {
|
||||
});
|
||||
}
|
||||
}
|
||||
24
pouchdb-node/pouchdb-node.d.ts
vendored
Normal file
24
pouchdb-node/pouchdb-node.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
// Type definitions for pouchdb-node v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
/// <reference path="../pouchdb-adapter-leveldb/pouchdb-adapter-leveldb.d.ts" />
|
||||
/// <reference path="../pouchdb-adapter-http/pouchdb-adapter-http.d.ts" />
|
||||
/// <reference path="../pouchdb-mapreduce/pouchdb-mapreduce.d.ts" />
|
||||
/// <reference path="../pouchdb-replication/pouchdb-replication.d.ts" />
|
||||
|
||||
declare namespace PouchDB {
|
||||
namespace Core {
|
||||
interface DatabaseInfo {
|
||||
/** The backend *DOWN adapter being used (MemDOWN, RiakDOWN, …). */
|
||||
backend_adapter?: string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'pouchdb-node' {
|
||||
const PouchDb: PouchDB.Static;
|
||||
export = PouchDb;
|
||||
}
|
||||
1
pouchdb-replication/pouchdb-replication-tests.ts
Normal file
1
pouchdb-replication/pouchdb-replication-tests.ts
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference path="./pouchdb-replication.d.ts" />
|
||||
23
pouchdb-replication/pouchdb-replication.d.ts
vendored
Normal file
23
pouchdb-replication/pouchdb-replication.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Type definitions for pouchdb-replication v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path="../pouchdb-core/pouchdb-core.d.ts" />
|
||||
|
||||
declare namespace PouchDB {
|
||||
namespace Replication {
|
||||
/** @todo When is this present? */
|
||||
interface ReplicationMeta {
|
||||
_replication_id: string;
|
||||
_replication_state: string;
|
||||
_replication_state_time: number;
|
||||
_replication_stats: {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'pouchdb-replication' {
|
||||
const plugin: PouchDB.Plugin;
|
||||
export = plugin;
|
||||
}
|
||||
106
pouchdb/pouchdb-tests.ts
Normal file
106
pouchdb/pouchdb-tests.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
/// <reference path="./pouchdb.d.ts" />
|
||||
|
||||
namespace PouchDBTests {
|
||||
function isString(someString: string) {
|
||||
}
|
||||
function isNumber(someNumber: number) {
|
||||
}
|
||||
|
||||
function testAllDocs() {
|
||||
const db = new PouchDB<{ foo: number }>();
|
||||
|
||||
db.allDocs().then(({ offset, total_rows, rows }) => {
|
||||
isNumber(offset);
|
||||
isNumber(total_rows);
|
||||
|
||||
rows.forEach(({ id, key, value, doc }) => {
|
||||
isString(id);
|
||||
isString(key);
|
||||
isString(value.rev);
|
||||
|
||||
// check document property
|
||||
isNumber(doc.foo);
|
||||
})
|
||||
});
|
||||
|
||||
db.allDocs({ startkey: "a", endkey: "b" });
|
||||
db.allDocs({ startkey: "a", endkey: "b", inclusive_end: true });
|
||||
db.allDocs({ keys: ["a", "b", "c" ]});
|
||||
db.allDocs({ key: "a" });
|
||||
db.allDocs({
|
||||
attachments: true,
|
||||
binary: true,
|
||||
conflicts: true,
|
||||
descending: true,
|
||||
include_docs: true,
|
||||
limit: 5,
|
||||
skip: 1
|
||||
});
|
||||
}
|
||||
|
||||
function testDestroy() {
|
||||
const db = new PouchDB<{}>();
|
||||
|
||||
db.destroy({}, (error) => {
|
||||
});
|
||||
db.destroy().then(() => {
|
||||
}).catch((error) => {
|
||||
});
|
||||
}
|
||||
|
||||
function testBasics() {
|
||||
type MyModel = { property: 'someProperty '};
|
||||
let model: PouchDB.Core.Document<MyModel>;
|
||||
const id = 'model';
|
||||
|
||||
let db = new PouchDB<MyModel>();
|
||||
db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'fruitdown'
|
||||
});
|
||||
db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'http'
|
||||
});
|
||||
db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'idb'
|
||||
});
|
||||
db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'leveldb'
|
||||
});
|
||||
db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'localstorage'
|
||||
});
|
||||
db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'memory'
|
||||
});
|
||||
db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'websql'
|
||||
});
|
||||
db = new PouchDB<MyModel>(null, {
|
||||
adapter: 'websql',
|
||||
size: 100
|
||||
});
|
||||
|
||||
db.post(model).then((result) => {
|
||||
isString(result.id);
|
||||
});
|
||||
db.post(model, null, (error, response) => {
|
||||
});
|
||||
|
||||
db.get(id).then((result) => model = result);
|
||||
db.get(id, null, (error, result) => {
|
||||
});
|
||||
|
||||
db.put(model).then((error) => {
|
||||
});
|
||||
db.put(model, null, null, null, (error) => {
|
||||
});
|
||||
|
||||
db.info().then((info) => {
|
||||
});
|
||||
db.info({ ajax: { cache: true }}, (error, result) => {
|
||||
});
|
||||
|
||||
db.viewCleanup().catch((error) => {
|
||||
});
|
||||
}
|
||||
}
|
||||
24
pouchdb/pouchdb.d.ts
vendored
Normal file
24
pouchdb/pouchdb.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
// Type definitions for pouchdb v5.4.4
|
||||
// Project: https://pouchdb.com/
|
||||
// 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
|
||||
|
||||
/// <reference path='../pouchdb-adapter-fruitdown/pouchdb-adapter-fruitdown.d.ts' />
|
||||
/// <reference path='../pouchdb-adapter-http/pouchdb-adapter-http.d.ts' />
|
||||
/// <reference path='../pouchdb-adapter-idb/pouchdb-adapter-idb.d.ts' />
|
||||
/// <reference path='../pouchdb-adapter-leveldb/pouchdb-adapter-leveldb.d.ts' />
|
||||
/// <reference path='../pouchdb-adapter-localstorage/pouchdb-adapter-localstorage.d.ts' />
|
||||
/// <reference path='../pouchdb-adapter-memory/pouchdb-adapter-memory.d.ts' />
|
||||
/// <reference path='../pouchdb-adapter-node-websql/pouchdb-adapter-node-websql.d.ts' />
|
||||
/// <reference path='../pouchdb-adapter-websql/pouchdb-adapter-websql.d.ts' />
|
||||
/// <reference path='../pouchdb-browser/pouchdb-browser.d.ts' />
|
||||
/// <reference path='../pouchdb-core/pouchdb-core.d.ts' />
|
||||
/// <reference path='../pouchdb-http/pouchdb-http.d.ts' />
|
||||
/// <reference path='../pouchdb-mapreduce/pouchdb-mapreduce.d.ts' />
|
||||
/// <reference path='../pouchdb-node/pouchdb-node.d.ts' />
|
||||
/// <reference path='../pouchdb-replication/pouchdb-replication.d.ts' />
|
||||
|
||||
declare module 'pouchdb' {
|
||||
const plugin: PouchDB.Static;
|
||||
export = plugin;
|
||||
}
|
||||
Reference in New Issue
Block a user