diff --git a/types/pouch-redux-middleware/index.d.ts b/types/pouch-redux-middleware/index.d.ts index e0e3691de6..a3b215e23d 100644 --- a/types/pouch-redux-middleware/index.d.ts +++ b/types/pouch-redux-middleware/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for pouch-redux-middleware 0.5 +// Type definitions for pouch-redux-middleware 1.2 // Project: https://github.com/pgte/pouch-redux-middleware // Definitions by: Adam Charron // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -7,27 +7,27 @@ import { Dispatch, Action, Middleware } from 'redux'; import * as PouchDB from 'pouchdb'; -export interface Document { - _id: any; - [field: string]: any; +export type Document = PouchDB.Core.IdMeta & T; + +export interface Path { + path: string; + db: PouchDB.Database; + scheduleRemove?(doc: Document): void; + scheduleInset?(doc: Document): void; + propagateDelete?(doc: Document, dispatch: Dispatch): void; + propagateBatchInsert?(doc: Array>, dispatch: Dispatch): void; + propagateInsert?(doc: Document, dispatch: Dispatch): void; + propagateUpdate?(doc: Document, dispatch: Dispatch): void; + handleResponse?(err: Error, data: any, errorCallback: (err: Error) => void): void; + initialBatchDispatched?(err?: Error): void; + queue?(...args: any[]): any; + docs?: any; + actions: { + remove(doc: Document): Action; + update(doc: Document): Action; + insert(doc: Document): Action; + batchInsert(docs: Array>): Action; + }; } -export interface Path { - path: string; - db: PouchDB.Database; - scheduleRemove?(doc: Document): void; - scheduleInset?(doc: Document): void; - propagateDelete?(doc: Document, dispatch: Dispatch): void; - propagateInsert?(doc: Document, dispatch: Dispatch): void; - propagateUpdate?(doc: Document, dispatch: Dispatch): void; - handleResponse?(err: Error, data: any, errorCallback: (err: Error) => void): void; - queue?(...args: any[]): any; - docs?: any; - actions: { - remove(doc: Document): Action; - update(doc: Document): Action; - insert(doc: Document): Action; - }; -} - -export default function PouchMiddlewareFactory(paths?: Path[] | Path): Middleware; +export default function PouchMiddlewareFactory(paths?: Array> | Path): Middleware; diff --git a/types/pouch-redux-middleware/pouch-redux-middleware-tests.ts b/types/pouch-redux-middleware/pouch-redux-middleware-tests.ts index a966a3edb8..fd110069c3 100644 --- a/types/pouch-redux-middleware/pouch-redux-middleware-tests.ts +++ b/types/pouch-redux-middleware/pouch-redux-middleware-tests.ts @@ -4,19 +4,22 @@ import PouchDB = require('pouchdb'); const types = { DELETE_TODO: 'delete-todo', + BATCH_INSERT_TODO: 'batch-insert-todo', INSERT_TODO: 'insert-todo', UPDATE_TODO: 'update-todo' }; -const path: Path = { +const path: Path<{}> = { path: "/test", db: new PouchDB('test'), actions: { remove: doc => ({ type: types.DELETE_TODO, id: doc._id }), + batchInsert: doc => ({ type: types.BATCH_INSERT_TODO, todo: doc }), insert: doc => ({ type: types.INSERT_TODO, todo: doc }), update: doc => ({ type: types.UPDATE_TODO, todo: doc }), - } + }, + initialBatchDispatched: (error?: Error) => {}, }; -const middleware: redux.Middleware = makePouchMiddleware(path); +const middleware: redux.Middleware = makePouchMiddleware<{}>(path); const otherMiddleware: redux.Middleware = makePouchMiddleware([path, path, path]);