src/contracts.bend checks
raw source on the hub · import 0x4ee0ec16258e9b8ad6ef37e5b8c4f95e/src/contracts.bend as Contracts
1 import
import Base
Types
type Param source · line 3 · raw
Data
Param@name:String -> @value:String -> Param
type Match source · line 6 · raw
Data
Matched@params:List<&2, Param> -> Match
NoMatchMatch
type Route source · line 63 · raw
Data
Metadata is data, not an effectful handler registry. IDs are application-owned.
Route@id:Nat -> @method:String -> @pattern:String -> @protected:Bool -> @statuses:List<&2, Nat> -> Route
type Selection source · line 66 · raw
Data
Found@route:Route -> @params:List<&2, Param> -> Selection
MissingSelection
WrongMethod@methods:List<&2, String> -> Selection
type Response source · line 71 · raw
@-B:Data -> Data
Reply@-B:Data -> @status:Nat -> @body:B -> Response<B>
Error@-B:Data -> @status:Nat -> @code:String -> @allow:List<&2, String> -> Response<B>
type Decision source · line 75 · raw
@-S:Data -> @-B:Data -> Data
Decision@-S:Data -> @-B:Data -> @state:S -> @response:Response<B> -> Decision<S, B>
Definitions
def prepend source · line 10 · raw
@name:String -> @value:String -> @result:Match -> Match
def literal source · line 15 · raw
@same:Bool -> @next:(@_:Unit -> Match) -> Match
def capture source · line 20 · raw
@parameter:Bool -> @pattern:String -> @+name:String -> @+value:String -> @next:(@_:Unit -> Match) -> Match
def segment source · line 26 · raw
@pattern:String -> @+value:String -> @next:(@_:Unit -> Match) -> Match
def values source · line 32 · raw
@patterns:List<&2, String> -> @path:List<&2, String> -> Match
def match_path source · line 38 · raw
@pattern:String -> @path:String -> Match
def param_step source · line 41 · raw
@found:Bool -> @value:String -> @next:(@_:Unit -> Maybe<&1, String>) -> Maybe<&1, String>
def param source · line 46 · raw
@+name:String -> @params:List<&2, Param> -> Maybe<&1, String>
def has_method source · line 52 · raw
@+name:String -> @names:List<&2, String> -> Bool
def unique source · line 57 · raw
@found:Bool -> @name:String -> @names:List<&2, String> -> List<&2, String>
def add_allowed source · line 78 · raw
@+method:String -> @result:Selection -> Selection
def chosen source · line 84 · raw
@same:Bool -> @+route:Route -> @params:List<&2, Param> -> @rest:Selection -> Selection
def matched source · line 91 · raw
@result:Match -> @same:Bool -> @route:Route -> @rest:Selection -> Selection
def select source · line 96 · raw
@routes:List<&2, Route> -> @+method:String -> @+path:String -> Selection
def readonly source · line 104 · raw
@+method:String -> Bool
def preserve source · line 108 · raw
@-S:Data -> @-B:Data -> @read:Bool -> @original:S -> @proposed:Decision<S, B> -> Decision<S, B>
Restore the complete modeled state for reads. There are no effects to undo.
def authorize source · line 116 · raw
@-S:Data -> @-B:Data -> @protected:Bool -> @valid:Bool -> @+state:S -> @next:(@_:S -> Decision<S, B>) -> Decision<S, B>
The guard receives a pure continuation, never IO. Denial cannot execute it.
def run source · line 121 · raw
@-S:Data -> @-B:Data -> @selection:Selection -> @read:Bool -> @valid:Bool -> @+state:S -> @next:(@_:Route -> @_:List<&2, Param> -> @_:S -> Decision<S, B>) -> Decision<S, B>
def dispatch source · line 131 · raw
@-S:Data -> @-B:Data -> @routes:List<&2, Route> -> @+method:String -> @path:String -> @valid:Bool -> @state:S -> @next:(@_:Route -> @_:List<&2, Param> -> @_:S -> Decision<S, B>) -> Decision<S, B>
def state source · line 135 · raw
@-S:Data -> @-B:Data -> @decision:Decision<S, B> -> S
def response source · line 139 · raw
@-S:Data -> @-B:Data -> @decision:Decision<S, B> -> Response<B>
def status source · line 143 · raw
@-B:Data -> @response:Response<B> -> Nat
def contains source · line 148 · raw
@statuses:List<&2, Nat> -> @+status:Nat -> Bool
def declared source · line 155 · raw
@-B:Data -> @route:Route -> @response:Response<B> -> Bool
Declare 401 on protected routes; 404/405 belong to the router, not a handler. This observation does not repair a wrong status: prove it True in app laws.