package irmin-indexeddb

  1. Overview
  2. Docs

Source file js_api.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(* Copyright (C) 2015, Thomas Leonard.
 * See the README file for details. *)

(** js_of_ocaml type declarations for the w3c IndexedDB spec: http://www.w3.org/TR/IndexedDB/
 * Currently only covers the bits needed for CueKeeper.
 * IndexedDB_lwt provides a more friendly API. *)

open Js_of_ocaml

(* Note: we currently assume all keys and values are strings.
 * This will always be the case for entries added using this interface. *)
type key = Js.js_string Js.t
type value = 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 Js.Opt.t
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

class type cursor = object
  method key : key Js.readonly_prop
  method continue : unit Js.meth
end
class type cursorWithValue = object
  inherit cursor
  method value : value Js.readonly_prop
end

class type dom_exception = 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
end

class type getRequest = object ('self)
  inherit request
  method result : value Js.Optdef.t Js.readonly_prop
end

class type openCursorRequest = object
  inherit request
  method result : cursorWithValue Js.t Js.Opt.t Js.readonly_prop
end

class type objectStore = object
  method add : value -> key -> request Js.t Js.meth
  method put : value -> key -> request Js.t Js.meth
  method delete : key -> request Js.t Js.meth
  method get : key -> getRequest Js.t Js.meth
  method openCursor : openCursorRequest Js.t Js.meth
end

class type transaction = object
  method oncomplete : ('self Js.t, completeEvent Js.t) Dom.event_listener Js.prop
  method onerror : ('self Js.t, request errorEvent Js.t) Dom.event_listener Js.prop
  method objectStore : store_name -> objectStore Js.t Js.meth
  method abort : unit Js.meth
end

class type database = object
  method close : unit Js.meth
  method createObjectStore : store_name -> objectStore Js.t Js.meth
  method deleteObjectStore : store_name -> unit Js.meth
  method onerror : ('self Js.t, request errorEvent Js.t) Dom.event_listener Js.prop
  method transaction : store_name Js.js_array Js.t -> mode -> transaction Js.t Js.meth
end

class type openDBRequest = object ('self)
  inherit request
  method onupgradeneeded : ('self Js.t, versionChangeEvent Js.t) Dom_html.event_listener Js.prop
  method onblocked : ('self Js.t, versionChangeEvent Js.t) Dom_html.event_listener Js.prop
  method result : database Js.t Js.readonly_prop
end

class type factory = object
  method _open : Js.js_string Js.t -> int -> openDBRequest Js.t Js.meth
  method deleteDatabase : Js.js_string Js.t -> openDBRequest Js.t Js.meth
end
OCaml

Innovation. Community. Security.