From 12ffcffba5610faed3252cee42093099d498d531 Mon Sep 17 00:00:00 2001 From: Max Battcher Date: Thu, 8 Jun 2017 14:40:01 -0400 Subject: [PATCH] Update and lint pouchdb-replication --- types/pouchdb-replication/index.d.ts | 57 ++++++++----------- .../pouchdb-replication-tests.ts | 6 +- types/pouchdb-replication/tslint.json | 1 + 3 files changed, 29 insertions(+), 35 deletions(-) create mode 100644 types/pouchdb-replication/tslint.json diff --git a/types/pouchdb-replication/index.d.ts b/types/pouchdb-replication/index.d.ts index c88ebd4e23..ff9d0051ec 100644 --- a/types/pouchdb-replication/index.d.ts +++ b/types/pouchdb-replication/index.d.ts @@ -1,14 +1,16 @@ -// Type definitions for pouchdb-replication v6.1.2 +// Type definitions for pouchdb-replication 6.1 // Project: https://pouchdb.com/ // Definitions by: Jakub Navratil // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 /// +// TODO: Fixing this lint error will require a large refactor +/* tslint:disable:no-single-declare-module */ + declare namespace PouchDB { - namespace Replication { - interface ReplicateOptions { /** If true, starts subscribing to future changes in the source database and continue replicating them. */ live?: boolean; @@ -25,7 +27,7 @@ declare namespace PouchDB { * To use a view function, pass '_view' here and provide a reference to the view function in options.view. * See filtered changes for details. */ - filter?: string | {(doc: any, params: any): any}; + filter?: string | ((doc: any, params: any) => any); /** Only show changes for docs with these ids (array of strings). */ doc_ids?: string[]; @@ -76,38 +78,35 @@ declare namespace PouchDB { * Defaults to a function that chooses a random backoff between 0 and 2 seconds and doubles every time it fails to connect. * The default delay will never exceed 10 minutes. */ - back_off_function?: (delay: number) => number; + back_off_function?(delay: number): number; } - interface ReplicationEventEmitter extends EventEmitter { + interface ReplicationEventEmitter extends NodeJS.EventEmitter { on(event: 'change', listener: (info: C) => any): this; - on(event: 'paused', listener: (err: {}) => any): this; + on(event: 'paused' | 'denied' | 'error', listener: (err: {}) => any): this; on(event: 'active', listener: () => any): this; - on(event: 'denied', listener: (err: {}) => any): this; on(event: 'complete', listener: (info: F) => any): this; - on(event: 'error', listener: (err: {}) => any): this; cancel(): void; } - interface Replication + interface Replication extends ReplicationEventEmitter, ReplicationResultComplete>, Promise> { - } - interface ReplicationResult { + interface ReplicationResult { doc_write_failures: number; docs_read: number; docs_written: number; - last_seq: number, - start_time: Date, - ok: boolean, + last_seq: number; + start_time: Date; + ok: boolean; errors: any[]; - docs: Core.ExistingDocument[]; + docs: Array>; } - interface ReplicationResultComplete extends ReplicationResult { + interface ReplicationResultComplete extends ReplicationResult { end_time: Date; status: string; } @@ -117,26 +116,23 @@ declare namespace PouchDB { pull?: ReplicateOptions; } - interface Sync + interface Sync extends ReplicationEventEmitter, SyncResultComplete>, Promise> { - } - interface SyncResult { + interface SyncResult { direction: 'push' | 'pull'; change: ReplicationResult; } - interface SyncResultComplete { + interface SyncResultComplete { push?: ReplicationResultComplete; pull?: ReplicationResultComplete; } - } interface Static { - /** * Replicate data from source to target. Both the source and target can be a PouchDB instance or a string * representing a CouchDB database URL or the name of a local PouchDB database. If options.live is true, @@ -147,7 +143,7 @@ declare namespace PouchDB { source: string | Database, target: string | Database, options?: Replication.ReplicateOptions, - callback?: Core.Callback> + callback?: Core.Callback> ): Replication.Replication; /** @@ -163,13 +159,11 @@ declare namespace PouchDB { source: string | Database, target: string | Database, options?: Replication.SyncOptions, - callback?: Core.Callback> + callback?: Core.Callback> ): Replication.Sync; - } - interface Database { - + interface Database { replicate: { /** * Replicate data to `target`. Both the source and target can be a PouchDB instance @@ -180,7 +174,7 @@ declare namespace PouchDB { to( target: string | Database, options?: Replication.ReplicateOptions, - callback?: Core.Callback> + callback?: Core.Callback> ): Replication.Replication; /** @@ -192,7 +186,7 @@ declare namespace PouchDB { from( source: string | Database, options?: Replication.ReplicateOptions, - callback?: Core.Callback> + callback?: Core.Callback> ): Replication.Replication; }; @@ -208,9 +202,8 @@ declare namespace PouchDB { sync( remote: string | Database, options?: Replication.SyncOptions, - callback?: Core.Callback> + callback?: Core.Callback> ): Replication.Sync; - } } diff --git a/types/pouchdb-replication/pouchdb-replication-tests.ts b/types/pouchdb-replication/pouchdb-replication-tests.ts index 9cf352bed6..3eb4a0d86e 100644 --- a/types/pouchdb-replication/pouchdb-replication-tests.ts +++ b/types/pouchdb-replication/pouchdb-replication-tests.ts @@ -1,13 +1,13 @@ /** @todo make some real tests */ function testReplication() { - type Model = { foo: number }; + interface Model { + foo: number; + } const db = new PouchDB(); db.replicate.to('').then((res: PouchDB.Replication.ReplicationResultComplete) => { - }); db.replicate.from('').then((res: PouchDB.Replication.ReplicationResultComplete) => { - }); } diff --git a/types/pouchdb-replication/tslint.json b/types/pouchdb-replication/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/pouchdb-replication/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }