lightspeed/framework/verified_routes

Verified-route-style compile-time path helpers and router-index verification.

Types

Phantom method marker for DELETE routes.

pub type DeleteTag {
  DeleteTag
}

Constructors

  • DeleteTag

Phantom method marker for GET routes.

pub type GetTag {
  GetTag
}

Constructors

  • GetTag

One router-indexed route with typed params and typed method marker.

pub opaque type IndexedRoute(params, method)

Phantom method marker for PATCH routes.

pub type PatchTag {
  PatchTag
}

Constructors

  • PatchTag

Phantom method marker for POST routes.

pub type PostTag {
  PostTag
}

Constructors

  • PostTag

Phantom method marker for PUT routes.

pub type PutTag {
  PutTag
}

Constructors

  • PutTag

Deterministic route compile diagnostic.

pub type RouteDiagnostic {
  UnknownRoute(name: String)
  MethodMismatch(
    name: String,
    expected: RouteMethod,
    actual: RouteMethod,
  )
  ParamMismatch(
    name: String,
    expected: List(String),
    actual: List(String),
  )
}

Constructors

  • UnknownRoute(name: String)
  • MethodMismatch(
      name: String,
      expected: RouteMethod,
      actual: RouteMethod,
    )
  • ParamMismatch(
      name: String,
      expected: List(String),
      actual: List(String),
    )

Route method used by strict route references.

pub type RouteMethod {
  MethodGet
  MethodPost
  MethodPut
  MethodPatch
  MethodDelete
}

Constructors

  • MethodGet
  • MethodPost
  • MethodPut
  • MethodPatch
  • MethodDelete

Unchecked route reference used by compile fixtures.

pub type RouteReference {
  RouteReference(
    name: String,
    method: RouteMethod,
    param_names: List(String),
  )
}

Constructors

  • RouteReference(
      name: String,
      method: RouteMethod,
      param_names: List(String),
    )

Strict route index used for deterministic reference verification fixtures.

pub opaque type RouterIndex

One verified route helper carrying a type-safe parameter contract.

pub opaque type VerifiedRoute(params)

Values

pub fn as_verified_route(
  route: IndexedRoute(params, method),
) -> VerifiedRoute(params)

Access one indexed route as a legacy verified route.

pub fn compile_reference(
  index: RouterIndex,
  reference: RouteReference,
) -> Result(Nil, RouteDiagnostic)

Verify one unchecked reference against the indexed route table.

This models compile-time route verification fixtures with deterministic diagnostics.

pub fn diagnostic_label(diagnostic: RouteDiagnostic) -> String

Stable compile diagnostic label for fixture assertions.

pub fn index_get0(
  index: RouterIndex,
  name: String,
  pattern: String,
) -> #(RouterIndex, IndexedRoute(Nil, GetTag))

Register a named GET zero-param route in the router index.

pub fn index_get1(
  index: RouterIndex,
  name: String,
  pattern: String,
  param: String,
) -> #(RouterIndex, IndexedRoute(String, GetTag))

Register a named GET one-param route in the router index.

pub fn index_get2(
  index: RouterIndex,
  name: String,
  pattern: String,
  first_param: String,
  second_param: String,
) -> #(RouterIndex, IndexedRoute(#(String, String), GetTag))

Register a named GET two-param route in the router index.

pub fn index_post0(
  index: RouterIndex,
  name: String,
  pattern: String,
) -> #(RouterIndex, IndexedRoute(Nil, PostTag))

Register a named POST zero-param route in the router index.

pub fn index_post1(
  index: RouterIndex,
  name: String,
  pattern: String,
  param: String,
) -> #(RouterIndex, IndexedRoute(String, PostTag))

Register a named POST one-param route in the router index.

pub fn index_signature(index: RouterIndex) -> String

Stable router-index signature for deterministic fixture assertions.

pub fn indexed_method(
  route: IndexedRoute(params, method),
) -> RouteMethod

Indexed route method.

pub fn indexed_name(
  route: IndexedRoute(params, method),
) -> String

Indexed route label.

pub fn method_label(method: RouteMethod) -> String

Stable method label.

pub fn new_index() -> RouterIndex

Create an empty router index.

pub fn param_names(route: VerifiedRoute(params)) -> List(String)

Route param-name contract for deterministic verification checks.

pub fn path(
  route: VerifiedRoute(params),
  params: params,
) -> String

Render path for one verified route.

pub fn path_from_indexed(
  route: IndexedRoute(params, method),
  params: params,
) -> String

Render path for one indexed route.

pub fn path_with_query(
  route: VerifiedRoute(params),
  params: params,
  query: List(#(String, String)),
) -> String

Render path with query pairs. Empty query emits no ?.

pub fn path_with_query_from_indexed(
  route: IndexedRoute(params, method),
  params: params,
  query: List(#(String, String)),
) -> String

Render path with query for one indexed route.

pub fn pattern(route: VerifiedRoute(params)) -> String

Route pattern string.

pub fn reference0(
  name: String,
  method: RouteMethod,
) -> RouteReference

Build a zero-parameter unchecked reference.

pub fn reference1(
  name: String,
  method: RouteMethod,
  param: String,
) -> RouteReference

Build a one-parameter unchecked reference.

pub fn reference2(
  name: String,
  method: RouteMethod,
  first_param: String,
  second_param: String,
) -> RouteReference

Build a two-parameter unchecked reference.

pub fn route0(pattern: String) -> VerifiedRoute(Nil)

Build a zero-parameter route helper.

pub fn route1(
  pattern: String,
  param: String,
) -> VerifiedRoute(String)

Build a one-parameter route helper.

Example: route1("/posts/:id", "id")

pub fn route2(
  pattern: String,
  first_param: String,
  second_param: String,
) -> VerifiedRoute(#(String, String))

Build a two-parameter route helper.

Example: route2("/teams/:team_id/members/:id", "team_id", "id")

pub fn static_path(route: IndexedRoute(params, method)) -> String

Indexed route static pattern path.

Search Document