Skip to content

Instantly share code, notes, and snippets.

@whitetigle
Last active December 21, 2017 11:13
Show Gist options
  • Save whitetigle/01d172a01eab5ca87d894063e46ee1c5 to your computer and use it in GitHub Desktop.
Save whitetigle/01d172a01eab5ca87d894063e46ee1c5 to your computer and use it in GitHub Desktop.
PouchDB wrappers for fable. WIP
namespace Fable.Import
open System
open System.Text.RegularExpressions
open Fable.Core
open Fable.Import.JS
open Fable.Import.Browser
type [<AllowNullLiteral>] Buffer =
inherit Uint8Array
abstract write: string: string * ?offset: float * ?length: float * ?encoding: string -> float
abstract toString: ?encoding: string * ?start: float * ?``end``: float -> string
abstract toJSON: unit -> obj
abstract equals: otherBuffer: Buffer -> bool
abstract compare: otherBuffer: Buffer * ?targetStart: float * ?targetEnd: float * ?sourceStart: float * ?sourceEnd: float -> float
abstract copy: targetBuffer: Buffer * ?targetStart: float * ?sourceStart: float * ?sourceEnd: float -> float
abstract slice: ?start: float * ?``end``: float -> Buffer
abstract writeUIntLE: value: float * offset: float * byteLength: float * ?noAssert: bool -> float
abstract writeUIntBE: value: float * offset: float * byteLength: float * ?noAssert: bool -> float
abstract writeIntLE: value: float * offset: float * byteLength: float * ?noAssert: bool -> float
abstract writeIntBE: value: float * offset: float * byteLength: float * ?noAssert: bool -> float
abstract readUIntLE: offset: float * byteLength: float * ?noAssert: bool -> float
abstract readUIntBE: offset: float * byteLength: float * ?noAssert: bool -> float
abstract readIntLE: offset: float * byteLength: float * ?noAssert: bool -> float
abstract readIntBE: offset: float * byteLength: float * ?noAssert: bool -> float
abstract readUInt8: offset: float * ?noAssert: bool -> float
abstract readUInt16LE: offset: float * ?noAssert: bool -> float
abstract readUInt16BE: offset: float * ?noAssert: bool -> float
abstract readUInt32LE: offset: float * ?noAssert: bool -> float
abstract readUInt32BE: offset: float * ?noAssert: bool -> float
abstract readInt8: offset: float * ?noAssert: bool -> float
abstract readInt16LE: offset: float * ?noAssert: bool -> float
abstract readInt16BE: offset: float * ?noAssert: bool -> float
abstract readInt32LE: offset: float * ?noAssert: bool -> float
abstract readInt32BE: offset: float * ?noAssert: bool -> float
abstract readFloatLE: offset: float * ?noAssert: bool -> float
abstract readFloatBE: offset: float * ?noAssert: bool -> float
abstract readDoubleLE: offset: float * ?noAssert: bool -> float
abstract readDoubleBE: offset: float * ?noAssert: bool -> float
abstract swap16: unit -> Buffer
abstract swap32: unit -> Buffer
abstract swap64: unit -> Buffer
abstract writeUInt8: value: float * offset: float * ?noAssert: bool -> float
abstract writeUInt16LE: value: float * offset: float * ?noAssert: bool -> float
abstract writeUInt16BE: value: float * offset: float * ?noAssert: bool -> float
abstract writeUInt32LE: value: float * offset: float * ?noAssert: bool -> float
abstract writeUInt32BE: value: float * offset: float * ?noAssert: bool -> float
abstract writeInt8: value: float * offset: float * ?noAssert: bool -> float
abstract writeInt16LE: value: float * offset: float * ?noAssert: bool -> float
abstract writeInt16BE: value: float * offset: float * ?noAssert: bool -> float
abstract writeInt32LE: value: float * offset: float * ?noAssert: bool -> float
abstract writeInt32BE: value: float * offset: float * ?noAssert: bool -> float
abstract writeFloatLE: value: float * offset: float * ?noAssert: bool -> float
abstract writeFloatBE: value: float * offset: float * ?noAssert: bool -> float
abstract writeDoubleLE: value: float * offset: float * ?noAssert: bool -> float
abstract writeDoubleBE: value: float * offset: float * ?noAssert: bool -> float
abstract fill: value: obj * ?offset: float * ?``end``: float -> obj
abstract indexOf: value: U3<string, float, Buffer> * ?byteOffset: float * ?encoding: string -> float
abstract lastIndexOf: value: U3<string, float, Buffer> * ?byteOffset: float * ?encoding: string -> float
abstract entries: unit -> IterableIterator<float * float>
abstract includes: value: U3<string, float, Buffer> * ?byteOffset: float * ?encoding: string -> bool
abstract keys: unit -> IterableIterator<float>
abstract values: unit -> IterableIterator<float>
and [<AllowNullLiteral>] EventEmitter =
abstract addListener: ``event``: U2<string, Symbol> * listener: Function -> obj
abstract on: ``event``: U2<string, Symbol> * listener: Function -> obj
abstract once: ``event``: U2<string, Symbol> * listener: Function -> obj
abstract removeListener: ``event``: U2<string, Symbol> * listener: Function -> obj
abstract removeAllListeners: ?``event``: U2<string, Symbol> -> obj
abstract setMaxListeners: n: float -> obj
abstract getMaxListeners: unit -> float
abstract listeners: ``event``: U2<string, Symbol> -> ResizeArray<Function>
abstract emit: ``event``: U2<string, Symbol> * [<ParamArray>] args: obj[] -> bool
abstract listenerCount: ``type``: U2<string, Symbol> -> float
abstract prependListener: ``event``: U2<string, Symbol> * listener: Function -> obj
abstract prependOnceListener: ``event``: U2<string, Symbol> * listener: Function -> obj
abstract eventNames: unit -> ResizeArray<U2<string, Symbol>>
module PouchDB =
type Plugin =
obj
module Configuration =
type [<AllowNullLiteral>] CommonDatabaseConfiguration =
abstract name: string option with get, set
abstract adapter: string option with get, set
and [<AllowNullLiteral>] LocalDatabaseConfiguration =
inherit CommonDatabaseConfiguration
abstract auto_compaction: bool option with get, set
abstract revs_limit: float option with get, set
and [<AllowNullLiteral>] RemoteRequesterConfiguration =
abstract timeout: float option with get, set
abstract cache: bool option with get, set
abstract headers: obj option with get, set
abstract withCredentials: bool option with get, set
and [<AllowNullLiteral>] RemoteDatabaseConfiguration =
inherit CommonDatabaseConfiguration
abstract ajax: RemoteRequesterConfiguration option with get, set
abstract auth: obj option with get, set
abstract skip_setup: bool option with get, set
and DatabaseConfiguration =
U2<LocalDatabaseConfiguration, RemoteDatabaseConfiguration>
module Core =
type [<AllowNullLiteral>] Error =
abstract status: float option with get, set
abstract name: string option with get, set
abstract message: string option with get, set
abstract reason: string option with get, set
abstract error: U2<string, bool> option with get, set
abstract id: string option with get, set
abstract rev: RevisionId option with get, set
and Callback<'R> =
Func<U2<Error, obj>, U2<'R, obj>, unit>
and DocumentId =
string
and DocumentKey =
string
and AttachmentId =
string
and RevisionId =
string
and [<StringEnum>] Availability = | Available | Compacted | ``Not compacted`` | Missing
and AttachmentData =
U3<string, Blob, Buffer>
and Options =
abstract ajax: Configuration.RemoteRequesterConfiguration option with get, set
and [<AllowNullLiteral>] BasicResponse =
abstract ok: bool with get, set
and [<AllowNullLiteral>] Response =
inherit BasicResponse
abstract id: DocumentId with get, set
abstract rev: RevisionId with get, set
and [<AllowNullLiteral>] DatabaseInfo =
abstract db_name: string with get, set
abstract doc_count: float with get, set
abstract update_seq: U2<float, string> with get, set
and [<AllowNullLiteral>] Revision<'Content> =
abstract ok: obj with get, set
and [<AllowNullLiteral>] RevisionInfo =
abstract rev: RevisionId with get, set
abstract status: Availability with get, set
and [<AllowNullLiteral>] RevisionDiffOptions =
[<Emit("$0[$1]{{=$2}}")>] abstract Item: DocumentId: string -> ResizeArray<string> with get, set
and [<AllowNullLiteral>] RevisionDiff =
abstract missing: ResizeArray<string> option with get, set
abstract possible_ancestors: ResizeArray<string> option with get, set
and [<AllowNullLiteral>] RevisionDiffResponse =
[<Emit("$0[$1]{{=$2}}")>] abstract Item: DocumentId: string -> RevisionDiff with get, set
and [<AllowNullLiteral>] IdMeta =
abstract _id: DocumentId with get, set
and [<AllowNullLiteral>] RevisionIdMeta =
abstract _rev: RevisionId with get, set
and [<AllowNullLiteral>] GetMeta =
abstract _conflicts: ResizeArray<RevisionId> option with get, set
abstract _rev: RevisionId with get, set
abstract _revs_info: ResizeArray<RevisionInfo> option with get, set
abstract _revisions: obj option with get, set
abstract _attachments: Attachments option with get, set
and [<AllowNullLiteral>] StubAttachment =
abstract content_type: string with get, set
abstract digest: string with get, set
abstract stub: obj with get, set
abstract ``true``: obj with get, set
abstract length: float with get, set
and [<AllowNullLiteral>] FullAttachment =
abstract content_type: string with get, set
abstract digest: string option with get, set
abstract data: AttachmentData with get, set
and Attachment =
U2<StubAttachment, FullAttachment>
and [<AllowNullLiteral>] Attachments =
[<Emit("$0[$1]{{=$2}}")>] abstract Item: attachmentId: string -> Attachment with get, set
and NewDocument= obj
and Document = obj
and ExistingDocument= obj
and RemoveDocument = obj
and PostDocument = obj
and PutDocument=obj
and AllDocsOptions =
inherit Options
abstract attachments: bool option with get, set
abstract binary: bool option with get, set
abstract conflicts: bool option with get, set
abstract descending: bool option with get, set
abstract include_docs: bool option with get, set
abstract limit: float option with get, set
abstract skip: float option with get, set
and AllDocsWithKeyOptions =
inherit AllDocsOptions
abstract key: DocumentKey with get, set
and AllDocsWithKeysOptions =
inherit AllDocsOptions
abstract keys: ResizeArray<DocumentId> with get, set
and AllDocsWithinRangeOptions =
inherit AllDocsOptions
abstract startkey: DocumentKey with get, set
abstract endkey: DocumentKey with get, set
abstract inclusive_end: bool option with get, set
and [<AllowNullLiteral>] AllDocsMeta =
abstract _conflicts: ResizeArray<RevisionId> option with get, set
abstract _attachments: Attachments option with get, set
and [<AllowNullLiteral>] AllDocsResponse<'Content> =
abstract offset: float with get, set
abstract total_rows: float with get, set
abstract rows: ResizeArray<obj> with get, set
and BulkDocsOptions =
inherit Options
abstract new_edits: bool option with get, set
and BulkGetOptions =
inherit Options
abstract docs: ResizeArray<obj> with get, set
abstract revs: bool option with get, set
abstract attachments: bool option with get, set
abstract binary: bool option with get, set
and [<AllowNullLiteral>] BulkGetResponse<'Content> =
abstract results: obj with get, set
and [<AllowNullLiteral>] ChangesMeta =
abstract _conflicts: ResizeArray<RevisionId> option with get, set
abstract _deleted: bool option with get, set
abstract _attachments: Attachments option with get, set
and [<AllowNullLiteral>] ChangesOptions =
abstract live: bool option with get, set
abstract since: (* TODO StringEnum now | | *) string option with get, set
abstract timeout: U2<float, obj> option with get, set
abstract include_docs: bool option with get, set
abstract limit: U2<float, obj> option with get, set
abstract conflicts: bool option with get, set
abstract attachments: bool option with get, set
abstract binary: bool option with get, set
abstract descending: bool option with get, set
abstract heartbeat: U2<float, obj> option with get, set
abstract filter: U2<string, Func<obj, obj, obj>> option with get, set
abstract doc_ids: ResizeArray<string> option with get, set
abstract query_params: obj option with get, set
abstract view: string option with get, set
and [<AllowNullLiteral>] ChangesResponseChange<'Content> =
abstract id: string with get, set
abstract seq: U2<float, string> with get, set
abstract changes: ResizeArray<obj> with get, set
abstract deleted: bool option with get, set
abstract doc: ExistingDocument option with get, set
and [<AllowNullLiteral>] ChangesResponse =
abstract status: string with get, set
abstract last_seq: U2<float, string> with get, set
abstract results: ResizeArray<ChangesResponseChange<'Content>> with get, set
and [<AllowNullLiteral>] Changes =
inherit EventEmitter
inherit Promise<ChangesResponse>
[<Emit("$0.on('change',$1...)")>] abstract on_change: listener: Func<ChangesResponseChange<'Content>, obj> -> obj
[<Emit("$0.on('complete',$1...)")>] abstract on_complete: listener: Func<ChangesResponse, obj> -> obj
[<Emit("$0.on('error',$1...)")>] abstract on_error: listener: Func<obj, obj> -> obj
abstract cancel: unit -> unit
and GetOptions =
inherit Options
abstract conflicts: bool option with get, set
abstract rev: RevisionId option with get, set
abstract revs: bool option with get, set
abstract revs_info: bool option with get, set
abstract attachments: bool option with get, set
abstract binary: bool option with get, set
abstract latest: bool option with get, set
and GetOpenRevisions =
inherit Options
abstract open_revs: (* TODO StringEnum all | *) string with get, set
abstract revs: bool option with get, set
and CompactOptions =
inherit Options
abstract interval: float option with get, set
and RemoveAttachmentResponse =
inherit BasicResponse
abstract id: DocumentId with get, set
abstract rev: RevisionId with get, set
module Find =
type IConditionOperators =
[<Emit("$0.$lt{{=$1}}")>] abstract lt: obj with get, set
[<Emit("$0.$gt{{=$1}}")>] abstract gt: obj with get, set
[<Emit("$0.$lte{{=$1}}")>] abstract lte: obj with get, set
[<Emit("$0.$gte{{=$1}}")>] abstract gte: obj with get, set
[<Emit("$0.$eq{{=$1}}")>] abstract eq: obj with get, set
[<Emit("$0.$ne{{=$1}}")>] abstract ne: obj with get, set
[<Emit("$0.$exists{{=$1}}")>] abstract exists: bool with get, set
[<Emit("$0.$type{{=$1}}")>] abstract ``type``: (* TODO StringEnum null | boolean | number | string | array | object *) string with get, set
[<Emit("$0.$in{{=$1}}")>] abstract ``in``: ResizeArray<obj> with get, set
[<Emit("$0.$nin{{=$1}}")>] abstract nin: ResizeArray<obj> with get, set
[<Emit("$0.$size{{=$1}}")>] abstract size: float with get, set
[<Emit("$0.$mod{{=$1}}")>] abstract ``mod``: float * float with get, set
[<Emit("$0.$regex{{=$1}}")>] abstract regex: string with get, set
[<Emit("$0.$all{{=$1}}")>] abstract all: ResizeArray<obj> with get, set
[<Emit("$0.$elemMatch{{=$1}}")>] abstract elemMatch: IConditionOperators with get, set
and [<AllowNullLiteral>] ICombinationOperators =
[<Emit("$0.$and{{=$1}}")>] abstract ``and``: ResizeArray<Selector> with get, set
[<Emit("$0.$or{{=$1}}")>]abstract ``or``: ResizeArray<Selector> with get, set
[<Emit("$0.$not{{=$1}}")>]abstract ``not``: Selector with get, set
[<Emit("$0.$nor{{=$1}}")>]abstract ``nor``: ResizeArray<Selector> with get, set
and [<AllowNullLiteral>] Selector =
inherit ICombinationOperators
[<Emit("$0[$1]{{=$2}}")>] abstract Item: field: string -> U4<Selector, ResizeArray<Selector>, IConditionOperators, obj> with get, set
abstract _id: IConditionOperators option with get, set
and [<AllowNullLiteral>] FindRequest =
abstract selector: Selector with get, set
abstract fields: ResizeArray<string> option with get, set
abstract sort: ResizeArray<U2<string, obj>> option with get, set
abstract limit: float option with get, set
abstract skip: float option with get, set
abstract use_index: U2<string, string * string> option with get, set
and [<AllowNullLiteral>] FindResponse =
abstract docs: ResizeArray<Core.Document> with get, set
// manually added
and [<AllowNullLiteral>] CreateIndexRequest =
abstract fields: ResizeArray<string> option with get, set
and [<AllowNullLiteral>] CreateIndexOptions =
abstract index: CreateIndexRequest with get, set
and [<AllowNullLiteral>] CreateIndexResponse =
abstract result: string with get, set
and [<AllowNullLiteral>] Index =
abstract name: string with get, set
abstract ddoc: U2<string, obj> with get, set
abstract ``null``: obj with get, set
abstract ``type``: string with get, set
abstract def: obj with get, set
and [<AllowNullLiteral>] GetIndexesResponse =
abstract indexes: ResizeArray<Index> with get, set
and [<AllowNullLiteral>] DeleteIndexOptions =
abstract name: string with get, set
abstract ddoc: string with get, set
abstract ``type``: string option with get, set
and [<AllowNullLiteral>] DeleteIndexResponse<'Content> =
[<Emit("$0[$1]{{=$2}}")>] abstract Item: propertyName: string -> obj with get, set
// manually added
type Database =
abstract put: doc:Core.PutDocument * ?options:Core.Options-> Promise<Core.Response>
abstract get: docId:Core.DocumentId * ?options:Core.Options-> Promise<Core.Document>
abstract find: request:Find.FindRequest -> Promise<Find.FindResponse>
abstract createIndex: index:Find.CreateIndexOptions -> Promise<Find.CreateIndexResponse>
and [<AllowNullLiteral>] Static =
inherit EventEmitter
abstract version: string with get, set
// abstract debug: debug.IDebug with get, set
abstract plugin: plugin: Plugin -> Static
abstract on: ``event``: (* TODO StringEnum created | destroyed *) string * listener: Func<string, obj> -> obj
[<Emit("new $0($1...)")>] abstract Create: U2<string,unit> -> Database
type [<Erase>]Globals =
[<Global>] static member PouchDB with get(): PouchDB.Static = jsNative and set(v: PouchDB.Static): unit = jsNative
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment