Created
September 22, 2018 15:51
-
-
Save dperetti/60b7cc6f4241858fd3855f15fa831d1b to your computer and use it in GitHub Desktop.
PouchDB Flowtype definitions (WIP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
export type PouchDBPostResponse = { ok: true, id: string, rev: string } | |
export type PouchDBUpsertResponse = { updated: true, id: string, rev: string } | { updated: false } | |
export type PouchDBRemoveResponse = { ok: true, id: string, rev: string, } | { ok: false } | |
export type PouchDBFindResponse<T> = { docs: Array<T>, warning?: string } | |
export type PouchDBAllDocsResponse<T> = { rows: Array<{ doc: T, id: string, key: string, value: { rev: string } }>, total_rows: number } | |
export type PouchError = { // empirically found | |
docId: string, | |
error: boolean, | |
message: string, | |
name: string, | |
reason: string, | |
status: number | |
} | |
declare module 'pouchdb-browser' { | |
declare export default typeof PouchDB | |
declare class PouchDB<K> { | |
static plugin(any): void; | |
constructor(name: string): void; | |
destroy(): void; | |
allDocs({ includeDocs?: boolean }): Promise<PouchDBAllDocsResponse<K>>; | |
get(docId: string): K; | |
remove(docId: string): Promise<PouchDBRemoveResponse>; | |
post(doc: K, options?: {}): Promise<PouchDBPostResponse>; | |
find({ | |
selector: { | |
[$Keys<K>]: { $eq: any } // more to add, of course! | |
} | |
}): Promise<PouchDBFindResponse<K>>; | |
// requires pouchd-upsert | |
upsert(docId: string, (doc: K) => K | false): Promise<PouchDBUpsertResponse>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To be used like this: