tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

registry-lambda.tri (1176B)


      1 !import prelude *
      2 !import io *
      3 !import http as H
      4 !import consumers_registry_path as Paths
      5 !export *
      6 -- Same bounded registry routes through ordinary tricu lambda/library code.
      7 -- Both versions receive an already parsed (method, target) request and use
      8 -- the same path helper, HTTP response encoder, and ReadFile host operation.
      9 
     10 prefixRest_ self input prefix =
     11   lazyList (_ : lazyList (_ : just t) (_ _ : nothing) prefix)
     12     (ih ir : lazyList (_ : just input)
     13       (ph pr : lazyBool (_ : self ir pr) (_ : nothing) (equal? ih ph)) prefix)
     14     input
     15 prefixRest prefix input = y prefixRest_ input prefix
     16 
     17 lambdaGet root target =
     18   lazyBool (_ : pure (H.okResponse "OK\n"))
     19     (_ : lazyMaybe
     20     (_ : pure H.notFoundResponse)
     21     (hash : onResult_ (readFile (Paths.bundleObjectPath root hash))
     22       (problem : pure (H.errorResponse 404 problem))
     23       (bytes : pure (H.response 200 "application/vnd.arboricx.bundle" bytes)))
     24     (prefixRest "/_arboricx/bundle/hash/" target))
     25     (equal? target "/_arboricx/health")
     26 lambdaRoute root request = matchPair (method target : lazyBool
     27   (_ : lambdaGet root target)
     28   (_ : pure H.notFoundResponse)
     29   (equal? method "GET")) request