Skip to content

Commit

Permalink
Merge pull request #125 from robitar/indexeddb-30
Browse files Browse the repository at this point in the history
Align IndexedDB bindings with the current spec
  • Loading branch information
MangelMaxime authored Sep 18, 2023
2 parents 8503ee2 + e710a32 commit fca2075
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 26 deletions.
96 changes: 72 additions & 24 deletions src/IndexedDB/Browser.IndexedDB.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace rec Browser.Types

open System
open Fable.Core

[<Erase>]
Expand All @@ -14,6 +13,25 @@ type IDBRequestReadyState =
| Pending
| Done

[<StringEnum>]
type IDBTransactionMode =
| Readonly
| Readwrite
| Versionchange

[<StringEnum>]
type IDBTransactionDuarability =
| Strict
| Relaxed
| Default

[<StringEnum>]
type IDBCursorDirection =
| Next
| Nextunique
| Prev
| Prevunique

type [<AllowNullLiteral>] DatabasesType =
abstract name: string
abstract version: string
Expand All @@ -32,24 +50,37 @@ type [<AllowNullLiteral; Global>] IDBIndex =
abstract getKey: ?key: obj -> IDBRequest
abstract getAll: ?query: obj * ?count: int -> IDBRequest
abstract getAllKeys: ?query: obj * ?count: int -> IDBRequest
abstract openCursor: ?range: obj * ?direction: string -> IDBRequest
abstract openKeyCursor: unit -> IDBRequest
abstract openCursor: ?range: obj * ?direction: IDBCursorDirection -> IDBRequest
abstract openKeyCursor: ?range: obj * ?direction: IDBCursorDirection -> IDBRequest

type [<AllowNullLiteral; Global>] IDBVersionChangeEvent =
inherit Event

abstract oldVersion: int64 with get
abstract newVersion: int64 with get

type [<AllowNullLiteral; Global>] IDBKeyRange =
type [<AbstractClass; AllowNullLiteral; Global>] IDBKeyRange =
abstract lower: obj with get
abstract upper: obj with get
abstract lowerOpen: obj with get
abstract upperOpen: obj with get
abstract lowerOpen: bool with get
abstract upperOpen: bool with get
abstract includes: obj -> bool

[<Emit("IDBKeyRange.bound($0, $1, $2, $3)")>]
static member bound(lower: obj, upper: obj, ?lowerOpen: bool, ?upperOpen: bool) = jsNative<IDBKeyRange>

[<Emit("IDBKeyRange.only($0)")>]
static member only(only: obj) = jsNative<IDBKeyRange>

[<Emit("IDBKeyRange.lowerBound($0, $1)")>]
static member lowerBound(lower: obj, ?``open``: bool) = jsNative<IDBKeyRange>

[<Emit("IDBKeyRange.upperBound($0, $1)")>]
static member upperBound(upper: obj, ?``open``: bool) = jsNative<IDBKeyRange>

type [<AllowNullLiteral; Global>] IDBCursor =
abstract source: IDBObjectStore with get
abstract direction: string with get
abstract direction: IDBCursorDirection with get
abstract key: obj option with get
abstract primaryKey: obj option with get
abstract request: IDBRequest with get
Expand All @@ -66,10 +97,12 @@ type [<AllowNullLiteral; Global>] IDBCursorWithValue =
abstract value: obj option with get

type [<AllowNullLiteral; Global>] IDBTransaction =
inherit EventTarget

abstract db: IDBDatabase with get
abstract durability: obj with get
abstract durability: IDBTransactionDuarability with get
abstract error: DOMException with get
abstract mode: string with get
abstract mode: IDBTransactionMode with get
abstract objectStoreNames: DOMStringList with get

abstract abort: unit -> unit
Expand All @@ -78,6 +111,7 @@ type [<AllowNullLiteral; Global>] IDBTransaction =

abstract oncomplete: (Event -> unit) with get, set
abstract onerror: (Event -> unit) with get, set
abstract onabort: (Event -> unit) with get, set

type [<AllowNullLiteral; Global>] IDBRequest =
inherit EventTarget
Expand All @@ -91,6 +125,10 @@ type [<AllowNullLiteral; Global>] IDBRequest =
abstract onerror: (Event -> unit) with get, set
abstract onsuccess: (Event -> unit) with get, set

type [<AllowNullLiteral; Global>] IDBCreateIndexOptions =
abstract unique: bool with get, set
abstract multiEntry: bool with get, set

type [<AllowNullLiteral; Global>] IDBObjectStore =
abstract indexNames: DOMStringList with get
abstract keyPath: obj with get
Expand All @@ -100,18 +138,25 @@ type [<AllowNullLiteral; Global>] IDBObjectStore =

abstract add: value: obj * ?key: obj -> IDBRequest
abstract clear: unit -> IDBRequest
abstract count: unit -> IDBRequest
abstract createIndex: indexName: string * keyPath: string * ?objectParameters: obj -> IDBRequest
abstract delete: unit -> IDBRequest
abstract count: ?query: IDBKeyRange -> IDBRequest
abstract createIndex: indexName: string * keyPath: string * ?options: IDBCreateIndexOptions -> IDBRequest
abstract delete: key: obj -> IDBRequest
abstract deleteIndex: unit -> IDBRequest
abstract get: obj -> IDBRequest
abstract getKey: unit -> IDBRequest
abstract getAll: unit -> IDBRequest
abstract getAllKeys: unit -> IDBRequest
abstract get: key: obj -> IDBRequest
abstract getKey: key: obj -> IDBRequest
abstract getAll: ?query: IDBKeyRange * ?count: int -> IDBRequest
abstract getAllKeys: ?query: IDBKeyRange * ?count: int -> IDBRequest
abstract index: string -> IDBIndex
abstract openCursor: ?query: IDBKeyRange -> IDBRequest
abstract openKeyCursor: unit -> IDBRequest
abstract put: unit -> IDBRequest
abstract openCursor: ?range: IDBKeyRange * ?direction: IDBCursorDirection -> IDBRequest
abstract openKeyCursor: ?range: IDBKeyRange * ?direction: IDBCursorDirection -> IDBRequest
abstract put: item: obj * ?key: obj -> IDBRequest

type [<AllowNullLiteral; Global>] IDBCreateStoreOptions =
abstract keyPath: obj with get, set
abstract autoIncrement: bool with get, set

type [<AllowNullLiteral; Global>] IDBTransactionOptions =
abstract durability: IDBTransactionDuarability with get, set

type [<AllowNullLiteral; Global>] IDBDatabase =
inherit EventTarget
Expand All @@ -121,21 +166,24 @@ type [<AllowNullLiteral; Global>] IDBDatabase =
abstract objectStoreNames: DOMStringList with get

abstract close: unit -> unit
abstract createObjectStore: name: string * ?options: obj -> IDBObjectStore
abstract createObjectStore: name: string * ?options: IDBCreateStoreOptions -> IDBObjectStore
abstract deleteObjectStore: name: string -> unit
abstract transaction: storeNames: #seq<string> * ?mode: string * ?options: obj -> IDBTransaction
abstract transaction: storeNames: string * ?mode: string * ?options: obj -> IDBTransaction
abstract transaction: storeNames: #seq<string> * ?mode: IDBTransactionMode * ?options: IDBTransactionOptions -> IDBTransaction
abstract transaction: storeNames: string * ?mode: IDBTransactionMode * ?options: IDBTransactionOptions -> IDBTransaction

abstract onclose: (Event -> unit) with get, set
abstract onversionchange: (Event -> unit) with get, set
abstract onabort: (Event -> unit) with get, set
abstract onerror: (Event -> unit) with get, set

type [<AllowNullLiteral; Global>] IDBOpenDBRequest =
inherit IDBRequest

abstract blocked: (Event -> unit) with get, set
abstract onupgradeneeded: (Event -> unit) with get, set
abstract onupgradeneeded: (IDBVersionChangeEvent -> unit) with get, set

type [<AllowNullLiteral; Global>] IDBFactory =
abstract ``open``: name: string * ?version: int64 -> IDBOpenDBRequest
abstract ``open``: name: string * ?version: int -> IDBOpenDBRequest
abstract cmp: first: 'T * second: 'T -> int
abstract deleteDatabase: name: string -> IDBOpenDBRequest
abstract databases: unit -> JS.Promise<DatabasesType array>
4 changes: 2 additions & 2 deletions src/IndexedDB/Browser.IndexedDB.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<PackageId>Fable.Browser.IndexedDB</PackageId>
<Version>1.0.0</Version>
<PackageVersion>1.0.0</PackageVersion>
<Version>2.0.0</Version>
<PackageVersion>2.0.0</PackageVersion>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Tags>fable;fable-binding;fable-javascript</Tags>
Expand Down

0 comments on commit fca2075

Please sign in to comment.