Guest User

Untitled

a guest
Sep 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. // @flow
  2.  
  3. export type PouchDBPostResponse = { ok: true, id: string, rev: string }
  4. export type PouchDBUpsertResponse = { updated: true, id: string, rev: string } | { updated: false }
  5. export type PouchDBRemoveResponse = { ok: true, id: string, rev: string, } | { ok: false }
  6. export type PouchDBFindResponse<T> = { docs: Array<T>, warning?: string }
  7. export type PouchDBAllDocsResponse<T> = { rows: Array<{ doc: T, id: string, key: string, value: { rev: string } }>, total_rows: number }
  8.  
  9. export type PouchError = { // empirically found
  10. docId: string,
  11. error: boolean,
  12. message: string,
  13. name: string,
  14. reason: string,
  15. status: number
  16. }
  17.  
  18. declare module 'pouchdb-browser' {
  19. declare export default typeof PouchDB
  20.  
  21. declare class PouchDB<K> {
  22. static plugin(any): void;
  23.  
  24. constructor(name: string): void;
  25.  
  26. destroy(): void;
  27.  
  28. allDocs({ includeDocs?: boolean }): Promise<PouchDBAllDocsResponse<K>>;
  29.  
  30. get(docId: string): K;
  31.  
  32. remove(docId: string): Promise<PouchDBRemoveResponse>;
  33.  
  34. post(doc: K, options?: {}): Promise<PouchDBPostResponse>;
  35.  
  36. find({
  37. selector: {
  38. [$Keys<K>]: { $eq: any } // more to add, of course!
  39. }
  40. }): Promise<PouchDBFindResponse<K>>;
  41.  
  42. // requires pouchd-upsert
  43. upsert(docId: string, (doc: K) => K | false): Promise<PouchDBUpsertResponse>;
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment