@resapi/express 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resapi/express",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Express server adapter for resAPI contracts.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://resapi.dev",
@@ -32,9 +32,9 @@
32
32
  "rescript": "^12.3.1"
33
33
  },
34
34
  "dependencies": {
35
- "@resapi/core": "^0.3.0"
35
+ "@resapi/core": "^0.4.0"
36
36
  },
37
37
  "devDependencies": {
38
- "express": "5.2.1"
38
+ "express": "5.3.0"
39
39
  }
40
40
  }
package/src/Router.res CHANGED
@@ -17,6 +17,7 @@ type server
17
17
  @send external expressGet: (t, string, handler) => unit = "get"
18
18
  @send external expressPost: (t, string, handler) => unit = "post"
19
19
  @send external expressPut: (t, string, handler) => unit = "put"
20
+ @send external expressDelete: (t, string, handler) => unit = "delete"
20
21
  @send external expressAll: (t, string, handler) => unit = "all"
21
22
  @send external expressPostWith: (t, string, middleware, handler) => unit = "post"
22
23
  @send external expressPutWith: (t, string, middleware, handler) => unit = "put"
@@ -26,8 +27,9 @@ type server
26
27
  @send external listen: (t, int, unit => unit) => server = "listen"
27
28
  @send external close: server => unit = "close"
28
29
 
29
- // Express's error handler logs `err.stack`, which a raw ReScript exception lacks: it logs as
30
- // "[object Object]". Rethrowing it as an Error keeps the log readable. JS errors pass untouched.
30
+ // Express's error page reads `err.stack`, which a raw ReScript exception lacks: outside production it
31
+ // shows "[object Object]", and Express before 5.3 logs that too. Rethrowing it as an Error keeps both
32
+ // readable. JS errors pass untouched.
31
33
  let rethrowAsError = exn =>
32
34
  switch exn {
33
35
  | JsExn(e) => JsExn.throw(e)
@@ -58,6 +60,11 @@ let put = (router, path, handler) => {
58
60
  router
59
61
  }
60
62
 
63
+ let delete = (router, path, handler) => {
64
+ router->expressDelete(path, catchExceptions(handler))
65
+ router
66
+ }
67
+
61
68
  let all = (router, path, handler) => {
62
69
  router->expressAll(path, catchExceptions(handler))
63
70
  router
@@ -91,6 +98,7 @@ let register = (router, route: EndpointHandler.route) => {
91
98
  | Get => router->expressGet(route.path, route.run)
92
99
  | Post => router->expressPostWith(route.path, rawText, route.run)
93
100
  | Put => router->expressPutWith(route.path, rawText, route.run)
101
+ | Delete => router->expressDelete(route.path, route.run)
94
102
  }
95
103
  router
96
104
  }
package/src/Router.resi CHANGED
@@ -24,6 +24,7 @@ type server
24
24
  let get: (t, string, handler) => t
25
25
  let post: (t, string, handler) => t
26
26
  let put: (t, string, handler) => t
27
+ let delete: (t, string, handler) => t
27
28
 
28
29
  /** Runs for every request whose path starts with `~path` (default all), including unmatched routes.
29
30
  The first `use` is the outermost layer. */