;; lib/dream/api.sx — Dream-on-SX public facade.
;; Loaded last; bundles the modules into a batteries-included surface. The full
;; public API is the `dream-*` functions across types/router/middleware/session/
;; flash/form/websocket/static/error/cors/json/run; this file adds convenience
;; app builders. Depends on all other dream modules.

(define dream-version "0.1.0")

;; standard middleware stack (pure — no IO): error catch outermost, then
;; content-type sniffing. Logger is opt-in since it performs host IO.
(define
  dream-defaults
  (fn
    (handler)
    (dream-pipeline (list dream-catch dream-content-type) handler)))

;; build a complete app handler from a route list with the default stack
(define
  dream-make-app
  (fn (routes) (dream-defaults (dream-router routes))))

;; build an app and wrap it with extra middleware (outermost first)
(define
  dream-make-app-with
  (fn
    (middlewares routes)
    (dream-pipeline middlewares (dream-make-app routes))))

;; one-call serve: routes + opts -> installed on the host
(define
  dream-serve
  (fn (routes opts) (dream-run-opts (dream-make-app routes) opts)))
(define dream-serve-port (fn (routes port) (dream-serve routes {:port port})))
