Skip to content

Commit 714df5d

Browse files
committed
split dream runtime into a separate package
1 parent 400cbbf commit 714df5d

14 files changed

+89
-24
lines changed

browser/runtime/dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(libraries melange-fetch))
77

88
(copy_files#
9-
(files ../../native/runtime/ppx_deriving_router_witness.ml*))
9+
(files ../../native/runtime_dream/ppx_deriving_router_witness.ml*))
1010

1111
(copy_files#
12-
(files ../../native/runtime/ppx_deriving_router_primitives.ml*))
12+
(files ../../native/runtime_dream/ppx_deriving_router_primitives.ml*))

dune-project

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,19 @@
2323
ppxlib
2424
containers
2525
routes
26-
dream
2726
melange
2827
melange-fetch
2928
ppx_deriving_json
3029
uri))
30+
31+
(package
32+
(name ppx_deriving_router_dream)
33+
(synopsis "Dream runtime")
34+
(depends
35+
(ocaml
36+
(>= 4.14))
37+
dune
38+
routes
39+
dream
40+
ppx_deriving_json
41+
uri))

native/lib/dune

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
(public_name ppx_deriving_router)
66
(libraries uri ppxlib containers ppx_deriving_json.native)
77
(kind ppx_deriver)
8-
(ppx_runtime_libraries ppx_deriving_router.runtime)
98
(preprocess
109
(pps ppxlib.metaquot)))
1110

native/lib/ppx_deriving_router.ml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module Derive_encode_response = struct
1616
td_newtype td (fun typ ->
1717
let value_typ =
1818
match typ with
19-
| None -> [%type: Dream.response]
19+
| None -> [%type: Ppx_deriving_router_runtime.response]
2020
| Some txt -> ptyp_constr ~loc { loc; txt = Lident txt } []
2121
in
2222
[%type: [%t value_typ] -> Ppx_deriving_router_runtime.json])
@@ -74,17 +74,19 @@ let td_to_ty_handler param td =
7474
[ { loc; txt = param_name } ]
7575
[%type:
7676
[%t td_to_ty (Some param) td] ->
77-
Dream.request ->
77+
Ppx_deriving_router_runtime.request ->
7878
[%t param] Lwt.t]
7979
| None ->
8080
[%type:
81-
[%t td_to_ty param td] -> Dream.request -> Dream.response Lwt.t]
81+
[%t td_to_ty param td] ->
82+
Ppx_deriving_router_runtime.request ->
83+
Ppx_deriving_router_runtime.response Lwt.t]
8284

8385
let td_to_ty_enc param td =
8486
let loc = td.ptype_loc in
8587
let result =
8688
match param with
87-
| None -> [%type: Dream.response]
89+
| None -> [%type: Ppx_deriving_router_runtime.response]
8890
| Some param -> param
8991
in
9092
[%type: [%t result] Ppx_deriving_router_runtime.encode]
@@ -192,7 +194,8 @@ let derive_path td (exemplar, ctors) =
192194
let value =
193195
[%expr
194196
let v =
195-
Dream.queries [%e req] [%e estring ~loc name]
197+
Ppx_deriving_router_runtime.queries [%e req]
198+
[%e estring ~loc name]
196199
in
197200
match [%e of_url] v with
198201
| Some v -> v
@@ -233,7 +236,7 @@ let derive_path td (exemplar, ctors) =
233236
let args = (name, ebody) :: args in
234237
[%expr
235238
Lwt.bind
236-
(Dream.body [%e req])
239+
(Ppx_deriving_router_runtime.body [%e req])
237240
(fun [%p pbody] ->
238241
let [%p pbody] =
239242
try Yojson.Basic.from_string [%e ebody]
@@ -254,8 +257,11 @@ let derive_path td (exemplar, ctors) =
254257
in
255258
let make =
256259
[%expr
257-
fun ([%p preq] : Dream.request) ->
258-
[%e pexp_match ~loc [%expr Dream.method_ [%e req]] by_method]]
260+
fun ([%p preq] : Ppx_deriving_router_runtime.request) ->
261+
[%e
262+
pexp_match ~loc
263+
[%expr Ppx_deriving_router_runtime.method_ [%e req]]
264+
by_method]]
259265
in
260266
List.fold_left (List.rev params) ~init:make ~f:(fun body param ->
261267
pexp_fun ~loc Nolabel None (pvar ~loc param) body)

native/runtime/dune

Lines changed: 0 additions & 4 deletions
This file was deleted.

native/runtime_dream/dune

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(library
2+
(name ppx_deriving_router_runtime_dream)
3+
(public_name ppx_deriving_router_dream)
4+
(wrapped false)
5+
(libraries containers dream routes ppx_deriving_json.native_runtime))

native/runtime/ppx_deriving_router_runtime.ml renamed to native/runtime_dream/ppx_deriving_router_runtime.ml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
type json = Ppx_deriving_json_runtime.t
2+
type response = Dream.response
3+
type request = Dream.request
4+
5+
let queries = Dream.queries
6+
let body = Dream.body
7+
8+
let method_ req =
9+
match Dream.method_ req with
10+
| `GET -> `GET
11+
| `POST -> `POST
12+
| `PUT -> `PUT
13+
| `DELETE -> `DELETE
14+
| _ -> failwith "Unsupported method"
15+
116
module Witness = Ppx_deriving_router_witness
217
module Primitives = Ppx_deriving_router_primitives
318

@@ -34,9 +49,6 @@ let prefix_route prefix f (Route (path, a, g)) =
3449

3550
let to_route (Route (path, a, f)) = Routes.(map f (route path a))
3651

37-
type json = Ppx_deriving_json_runtime.t
38-
type response = Dream.response
39-
4052
type _ encode =
4153
| Encode_raw : response encode
4254
| Encode_json : ('a -> json) -> 'a encode

native/runtime/ppx_deriving_router_runtime.mli renamed to native/runtime_dream/ppx_deriving_router_runtime.mli

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
type json = Ppx_deriving_json_runtime.t
2+
type request = Dream.request
3+
type response = Dream.response
4+
5+
val queries : request -> string -> string list
6+
val body : request -> string Lwt.t
7+
val method_ : request -> [ `DELETE | `GET | `POST | `PUT ]
8+
19
(** REQUEST DECODING *)
210

311
type 'a url_path_encoder = 'a -> string
@@ -18,9 +26,6 @@ val encode_path : Buffer.t -> string -> unit
1826
val encode_query_key : Buffer.t -> string -> unit
1927
val encode_query_value : Buffer.t -> string -> unit
2028

21-
type response = Dream.response
22-
type json = Ppx_deriving_json_runtime.t
23-
2429
type _ encode =
2530
| Encode_raw : response encode
2631
| Encode_json : ('a -> json) -> 'a encode

0 commit comments

Comments
 (0)