Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update project and enable object store queries by key range #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
setup.data
setup.log
_build
.merlin
41 changes: 0 additions & 41 deletions Makefile

This file was deleted.

16 changes: 0 additions & 16 deletions _oasis

This file was deleted.

27 changes: 0 additions & 27 deletions configure

This file was deleted.

20 changes: 20 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(lang dune 2.5)
(name indexeddb)

(generate_opam_files true)
(authors "Thomas Leonard <[email protected]>, Vasilis Papavasileiou, Boris D. <[email protected]>")
(maintainers "Ocsigen Team <[email protected]>")
(source (github ocsigen/ocaml-indexeddb))
(license ISC)

(package
(name indexeddb)
(synopsis "OCaml bindings for IndexedDB")
(depends
(ocaml (>= 4.08.0))
(dune (and :build (>= 2.5)))
(webtest (and :with-test (>= 2.0)))
(webtest-js (and :with-test (>= 2.0)))
(lwt (>= 5.2))
(js_of_ocaml (> 3.4.0))
(js_of_ocaml-lwt (> 3.4.0))))
34 changes: 34 additions & 0 deletions indexeddb.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "OCaml bindings for IndexedDB"
maintainer: ["Ocsigen Team <[email protected]>"]
authors: [
"Thomas Leonard <[email protected]>, Vasilis Papavasileiou, Boris D. <[email protected]>"
]
license: "ISC"
homepage: "https://github.com/ocsigen/ocaml-indexeddb"
bug-reports: "https://github.com/ocsigen/ocaml-indexeddb/issues"
depends: [
"ocaml" {>= "4.08.0"}
"dune" {build & >= "2.5"}
"webtest" {with-test & >= "2.0"}
"webtest-js" {with-test & >= "2.0"}
"lwt" {>= "5.2"}
"js_of_ocaml" {> "3.4.0"}
"js_of_ocaml-lwt" {> "3.4.0"}
]
build: [
["dune" "subst"] {pinned}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/ocsigen/ocaml-indexeddb.git"
13 changes: 13 additions & 0 deletions lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(library
(public_name indexeddb)
(name indexeddb)
(modes byte)
(modules_without_implementation idb_sigs)
(libraries
lwt
js_of_ocaml
js_of_ocaml-lwt)
(preprocess
(pps
lwt_ppx
js_of_ocaml-ppx)))
74 changes: 63 additions & 11 deletions lib/idb_js_api.ml → lib/idb.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@
Currently only covers the bits needed for CueKeeper.
IndexedDB_lwt provides a more friendly API. *)

(* Note: we currently assume all keys and values are strings. This
will always be the case for entries added using this interface. *)
open Js_of_ocaml

(* Note: we currently assume all keys are strings. This will always
be the case for entries added using this interface. *)
type key = Js.js_string Js.t
type _ store_name = Js.js_string Js.t
type mode = Js.js_string Js.t

class type versionChangeEvent = object
inherit Dom_html.event

method oldVersion : int Js.readonly_prop
method newVersion : int Js.readonly_prop
end

class type ['a] errorEvent = object
inherit ['a] Dom.event
end

class type completeEvent = object
inherit Dom_html.event
end

class type successEvent = object
inherit Dom_html.event
end
Expand All @@ -40,22 +44,20 @@ class type ['a] cursorWithValue = object
method value : 'a Js.readonly_prop
end

class type dom_exception = object
class type domException = object
(* Being a bit paranoid marking all these as optdef *)
method name : Js.js_string Js.t Js.Optdef.t Js.readonly_prop
method message : Js.js_string Js.t Js.Optdef.t Js.readonly_prop
method code : int Js.Optdef.t Js.readonly_prop
end

class type request = object
method error : dom_exception Js.t Js.Opt.t Js.readonly_prop
method onerror :
('self Js.t, request errorEvent Js.t) Dom.event_listener Js.prop
method onsuccess :
('self Js.t, successEvent Js.t) Dom.event_listener Js.prop
method error : domException Js.t Js.Opt.t Js.readonly_prop
method onerror : ('self Js.t, request errorEvent Js.t) Dom.event_listener Js.prop
method onsuccess : ('self Js.t, successEvent Js.t) Dom.event_listener Js.prop
end

class type ['a] getRequest = object ('self)
class type ['a] requestWithResult = object
inherit request
method result : 'a Js.Optdef.t Js.readonly_prop
end
Expand All @@ -65,12 +67,59 @@ class type ['a] openCursorRequest = object
method result : 'a cursorWithValue Js.t Js.Opt.t Js.readonly_prop
end

class type createObjectStoreOptions = object
method keyPath : Js.js_string Js.t Js.writeonly_prop
method autoIncrement : bool Js.t Js.writeonly_prop
end

let createObjectStoreOptions () : createObjectStoreOptions Js.t =
Js.Unsafe.obj [||]

class type keyRange = object
method lower : key Js.Optdef.t Js.readonly_prop
method upper : key Js.Optdef.t Js.readonly_prop
method lowerOpen : bool Js.t Js.readonly_prop
method upperOpen : bool Js.t Js.readonly_prop
method includes : key -> bool Js.t Js.meth
end

class type keyRange_constr = object
method bound : key -> key -> keyRange Js.t Js.meth
method bound_lowerOpen : key -> key -> bool Js.t -> keyRange Js.t Js.meth
method bound_lowerAndUpperOpen :
key -> key -> bool Js.t -> bool Js.t -> keyRange Js.t Js.meth
method lowerBound : key -> keyRange Js.t Js.meth
method lowerBound_open : key -> bool Js.t -> keyRange Js.t Js.meth
method upperBound : key -> keyRange Js.t Js.meth
method upperBound_open : key -> bool Js.t -> keyRange Js.t Js.meth
method only : key -> keyRange Js.t Js.meth
end

let keyRange_constr = Js.Unsafe.global##._IDBKeyRange

let keyRange : keyRange_constr Js.t = keyRange_constr

class type ['a] objectStore = object
method keyPath : key Js.readonly_prop
method autoIncrement : bool Js.t Js.readonly_prop
method add : 'a Js.t -> key -> request Js.t Js.meth
method put : 'a Js.t -> key -> request Js.t Js.meth
method delete : key -> request Js.t Js.meth
method get : key -> 'a Js.t getRequest Js.t Js.meth
method get : key -> 'a Js.t requestWithResult Js.t Js.meth
method openCursor : 'a Js.t openCursorRequest Js.t Js.meth
method openCursor_query :
keyRange Js.t -> 'a Js.t openCursorRequest Js.t Js.meth
method openCursor_queryAndDirection :
keyRange Js.t Js.Opt.t -> Js.js_string Js.t ->
'a Js.t openCursorRequest Js.t Js.meth
method add_object : 'a Js.t -> key requestWithResult Js.t Js.meth
method put_object : 'a Js.t -> key requestWithResult Js.t Js.meth
method getAll : 'a Js.t Js.js_array Js.t requestWithResult Js.t Js.meth
method getAll_query :
keyRange Js.t -> 'a Js.t Js.js_array Js.t requestWithResult Js.t Js.meth
method getAll_queryAndCount :
keyRange Js.t Js.Opt.t -> int ->
'a Js.t Js.js_array Js.t requestWithResult Js.t Js.meth
end

class type ['a] transaction = object
Expand All @@ -86,6 +135,9 @@ class type database = object
method close : unit Js.meth
method createObjectStore :
'a . 'a store_name -> 'a objectStore Js.t Js.meth
method createObjectStore_withOptions :
'a . 'a store_name -> createObjectStoreOptions Js.t ->
'a objectStore Js.t Js.meth
method deleteObjectStore :
'a . 'a store_name -> unit Js.meth
method onerror :
Expand Down
Loading