amelinium.common

added in 1.0.0

Common helpers for amelinium.

acceptable-identity-type

(acceptable-identity-type identity-type)(acceptable-identity-type identity-type acceptable-tag)

For the given identity type identity-type and optional acceptable type tag acceptable-type (amelinium.identity/standard by default), returns that type as keyword, or nil if the type is not acceptable.

add-header

macro

(add-header req header-name & body)

Adds a header header to :response/headers map of the req using built-in function qassoc. If a header name argument is a literal keyword, a character, a number, or a literal string, it will be converted to a string literal and placed as qassoc argument. Otherwise it will be left as is and wrapped into a call to io.randomseed.utils/some-str to ensure the result is a string run-time. All arguments of the body are used to calculate a value of the header. Assumes that req is always a map.

add-headers

macro

(add-headers req header-name header-value)(add-headers req header-name header-value & more)

Adds headers with associated values to :response/headers map of the req using built-in function qassoc. If any header name argument is a literal keyword, a character, a number, or a literal string, it will be converted to a string literal and placed as an argument passed to qassoc. Otherwise it will be left as is and wrapped in a call to io.randomseed.utils/some-str to ensure at run-time that the result will be a string. Missing header value, if any, will be padded with nil.

add-json-event-header

(add-json-event-header req header-name event-name)(add-json-event-header req header-name event-name param-key param-value)(add-json-event-header req header-name event-name param-key param-value replace?)

add-missing-lang

(add-missing-lang body req translation-keys)

For the given body map it adds a language under the :lang key if it does not exists yet. The language is obtained from the request map req by reading a value associated with the :language/id key.

add-missing-translation

(add-missing-translation body new-k k sub-translation-fn)(add-missing-translation body new-k k suffix sub-translation-fn)

For the given body map, a new key new-k, a key k and a translation function sub-translation-fn, tries to add a translation of the key k as a value under the given key new-k, if it does not exist yet in body. Optional suffix argument is used to add suffix to a key name.

add-session-hx-header

(add-session-hx-header req sess)

Adds HX-Trigger server response header to :response/headers map of the given req map by putting a JSON in the following form:

{"setSession":{"session-id": "SID"}}

where the session-id string is obtained from session’s ID field (using amelinium.http.middleware.session/id-field) and SID is replaced with session ID (obtained with amelinium.http.middleware.session/any-id).

If the HX-Trigger header already exists but it does not contain setSession trigger name, it will be modified. If it already contains it, it will be left as is.

add-session-id-header

(add-session-id-header req sess)(add-session-id-header req sess replace?)

Adds session ID header to the :response/headers map of the given req map. Name of the header is obtained from session ID field (by calling amelinium.http.middleware.session/id-field) and its value is set to session ID (obtained by calling amelinium.http.middleware.session/any-id). If the header already exists it is not added.

add-slash

(add-slash uri)

Adds trailing slash to a path unless it already exists.

add-status

macro

(add-status req & body)

Adds response status to a request map req under its key :response/status using qassoc. The status is a result of evaluating expressions passed as additional arguments. Returns updated req. Assumes that req is always a map.

auth-page

(auth-page req)(auth-page req lang-id)

Returns a path for the authentication page. The page must have ID of :user/welcome.

auth-page?

(auth-page? req)(auth-page? req ring-match)

Returns true if the current (or given as a match) page is an authentication page (has :auth-page? route data set to a truthy value).

config+session

(config+session req)(config+session req session-key)

Gets a session map and a session config map from the given request map. Returns a two-element vector.

created

(created)(created req)(created url)(created req url)(created req name-or-path)(created req name-or-path path-params)(created req name-or-path path-params query-params)(created req name-or-path lang)(created req name-or-path lang path-params)(created req name-or-path lang path-params query-params)(created req name-or-path lang path-params query-params & more)

Uses the page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 201 to it using resp/created. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

current-page

(current-page req)

Returns a path of the current page.

current-page-id

(current-page-id req-or-match)

Returns an identifier of a current page if it is defined for a HTTP route.

current-page-id-or-path

(current-page-id-or-path req)

Returns an identifier of a current page if it is defined for a HTTP route or a path if the page name is not defined.

def-localized-redirect

macro

(def-localized-redirect name f)(def-localized-redirect name f http-code)(def-localized-redirect name doc f)

Generates a language-parameterized redirect function which acts like localized-redirect.

def-redirect

macro

(def-redirect name f)(def-redirect name f http-code)(def-redirect name doc f)

Generates a language-parameterized redirect function which acts like redirect.

default-contexts-labeler

(default-contexts-labeler _ ids)

early-hints

(early-hints)(early-hints body)

103 Early Hints The server sends some response headers (e.g. HTML resource links) before final HTTP message.

empty-session-id-header

(empty-session-id-header req sess)(empty-session-id-header req sess headers-key)

Adds session ID header with an empty string to the :response/headers map of the given req map. Name of the header is obtained from session ID field (by calling amelinium.http.middleware.session/id-field). If the header already exists it is replaced.

fast-url-matcher

found

(found)(found req)(found url)(found req url)(found req name-or-path)(found req name-or-path path-params)(found req name-or-path path-params query-params)(found req name-or-path lang)(found req name-or-path lang path-params)(found req name-or-path lang path-params query-params)(found req name-or-path lang path-params query-params & more)

Uses the page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 302 to it using resp/found. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

get-session-id-header

(get-session-id-header req id-field)

For the given request map req it tries to get a request header identified by a name id-field, and then checks if it is valid session identifier. Returns a session identifier or nil if the obtained value is not valid session ID or the header is not found.

go-to

(go-to)(go-to req)(go-to url)(go-to req url)(go-to req name-or-path)(go-to req name-or-path path-params)(go-to req name-or-path path-params query-params)(go-to req name-or-path lang)(go-to req name-or-path lang path-params)(go-to req name-or-path lang path-params query-params)(go-to req name-or-path lang path-params query-params & more)

Uses the localized-page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 303 to it using resp/see-other. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil.

guess-identity-type

(guess-identity-type src)(guess-identity-type src identity-type)(guess-identity-type src id identity-type)(guess-identity-type src id identity-type acceptable-tag)

Detects an identity type and checks if it is assigned to a tag :amelinium.identity/standard or to a tag passed as acceptable-tag argument. To accept any valid identity type the :amelinium.identity/valid must be explicitly given.

The src may be a map or a single value. If it is a map, the keys :identity, :user/identity and :id are looked up to get the identity of a user, keys :id-type and :identity/type are used to look up to get already established identity type. If it is a single value then it should contain the identity source (a string, a phone number, a number, etc).

When the optional id argument is given, it is tried before any lookup in a source map and even before getting it from src directly (in case it is a single value).

If the identity type was obtained (from the optional identity-type argument or a map entry, if any), it is checked whether it is acceptable. If the identity type was not obtained, it is guessed by analyzing the identity value (and also checked against the acceptable types).

If the identity type cannot be established or it is not acceptable, nil is returned.

guess-lang-param

(guess-lang-param)(guess-lang-param src)

For the given src argument, tries to obtain a language ID. If it’s a map it looks for :param key and for :language/settings if that fails. If :language/settings is found, it will try to get :param, assuming it’s a map too. If the argument is not a map it will simply convert it into a keyword (without a namespace). If all of that fails (e.g. the src is nil) then the :lang keyword is returned.

hard-lock-time

(hard-lock-time user)

Gets a hard-lock time for a given user specified by a map having the :locked key.

hard-locked?

(hard-locked? user)

Returns true if the given user map contains the :locked key and a value associated with it is not nil. Does not connect to a database.

has-any-role?

(has-any-role? req role)

has-param?

(has-param? match param)

Checks if the given route match can be parameterized with a parameter of the given id.

has-role?

(has-role? req role)(has-role? req role context)

hx-request?

(hx-request? req)

Returns true if the client request has HX-Request header set to any value but false or an empty string.

hx-target

(hx-target req)

Returns a string from HX-Target header set by a client. If the header does not exist, it returns nil. If the header exists but contains an empty string, it returns nil.

id-type->url-type

(id-type->url-type id-type reason)

Returns URL type identifier which matches the given identity type and confirmation reason. Used to generate confirmation link which is to be sent in verification message.

If id-type is :user/email or :email and reason is :change or “change”, the result is :url/update-email.

If id-type is :user/email or :email and reason is :recovery or “recovery”, the result is :url/update-password.

If id-type is :user/email or :email and reason is not of any above, the result is :url/create.

If id-type is :user/phone or :phone and reason is :recovery or “recovery”, the result is :url/update-password.

If id-type is :user/phone or :phone, and reason is not of any above, the result is :url/update-phone.

In all other cases :url/update-email is returned.

identity-and-type

(identity-and-type user-identity)(identity-and-type user-identity identity-type)(identity-and-type user-identity identity-type acceptable-tag)

Detects an identity type and checks if it is assigned to a tag :amelinium.identity/standard or to a tag passed as acceptable-tag argument.

To accept any valid identity type the :amelinium.identity/valid must be explicitly given as acceptable-tag argument.

If identity-type is not given, is set to nil or to :amelinium.identity/any, it is guessed by analyzing user-identity.

Returns a 2-element vector containing original value of user-identity argument and detected identity type.

If user-identity is nil or false then only the given identity-type is checked whether it is acceptable. If it is not, nil is returned instead of vector.

If user-identity is given but it is not matching the given identity type or its identity type is not acceptable, nil is returned instead of vector.

If user-identity is given but identity-type is nil or :amelinium.identity/any, the type of user identity is extracted and checked whether it is acceptable.

User identity is only tested, never transformed, even if it is not an Identity object. Identity type is extracted from identity object (given or ad-hoc created).

im-a-teapot

(im-a-teapot)(im-a-teapot body)

418 I’m a teapot The server cannot brew coffee because it is, permanently, a teapot.

is-url?

(is-url? s)

kv-json-str

macro

(kv-json-str k v)

lang-config

(lang-config req)

lang-from-req

(lang-from-req req)

lang-id

(lang-id req)

lang-id-or-nil

(lang-id-or-nil req)

lang-param

(lang-param req)

lang-query-string

(lang-query-string req)

lang-redir

(lang-redir req)

Redirects to a best-suited language version of the URI. Uses :browser pickers chain to get the right language if the path is language-parameterized.

lang-str

(lang-str req)

lang-str-or-nil

(lang-str-or-nil req)

lang-url

(lang-url router req path-or-name lang localized? path-params)(lang-url router req path-or-name lang localized?)(lang-url router req path-or-name lang)(lang-url router req path-or-name)(lang-url router req)(lang-url req)(lang-url req path-or-name lang localized? path-params query-params lang-param)(lang-url router req path-or-name lang localized? path-params query-params lang-param)

localized-created

(localized-created)(localized-created req)(localized-created url)(localized-created req url)(localized-created req name-or-path)(localized-created req name-or-path path-params)(localized-created req name-or-path path-params query-params)(localized-created req name-or-path lang)(localized-created req name-or-path lang path-params)(localized-created req name-or-path lang path-params query-params)(localized-created req name-or-path lang path-params query-params & more)

Uses the localized-page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 201 to it using resp/created. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil.

localized-found

(localized-found)(localized-found req)(localized-found url)(localized-found req url)(localized-found req name-or-path)(localized-found req name-or-path path-params)(localized-found req name-or-path path-params query-params)(localized-found req name-or-path lang)(localized-found req name-or-path lang path-params)(localized-found req name-or-path lang path-params query-params)(localized-found req name-or-path lang path-params query-params & more)

Uses the localized-page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 302 to it using resp/found. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil.

localized-moved-permanently

(localized-moved-permanently)(localized-moved-permanently req)(localized-moved-permanently url)(localized-moved-permanently req url)(localized-moved-permanently req name-or-path)(localized-moved-permanently req name-or-path path-params)(localized-moved-permanently req name-or-path path-params query-params)(localized-moved-permanently req name-or-path lang)(localized-moved-permanently req name-or-path lang path-params)(localized-moved-permanently req name-or-path lang path-params query-params)(localized-moved-permanently req name-or-path lang path-params query-params & more)

Uses the localized-page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 301 to it using resp/moved-permanently. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil.

localized-multiple-choices

(localized-multiple-choices)(localized-multiple-choices req)(localized-multiple-choices url)(localized-multiple-choices req url)(localized-multiple-choices req name-or-path)(localized-multiple-choices req name-or-path path-params)(localized-multiple-choices req name-or-path path-params query-params)(localized-multiple-choices req name-or-path lang)(localized-multiple-choices req name-or-path lang path-params)(localized-multiple-choices req name-or-path lang path-params query-params)(localized-multiple-choices req name-or-path lang path-params query-params & more)

Uses the localized-page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 300 to it using resp/multiple-choices. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil.

localized-not-modified

(localized-not-modified)(localized-not-modified req)(localized-not-modified req & more)

localized-page

(localized-page req)(localized-page req name-or-path)(localized-page req name-or-path path-params)(localized-page req name-or-path path-params query-params)(localized-page req name-or-path lang)(localized-page req name-or-path lang path-params)(localized-page req name-or-path lang path-params query-params)(localized-page req name-or-path lang lang-required?)(localized-page req name-or-path lang path-params lang-required?)(localized-page req name-or-path lang path-params query-params lang-required?)(localized-page req name-or-path lang path-params query-params lang-required? name-path-fallback?)(localized-page req name-or-path lang path-params query-params lang-required? name-path-fallback? router)(localized-page _ name-or-path lang path-params query-params lang-required? name-path-fallback? router language-settings-or-param)

Generates a page path for the given page identifier and language identifier. When called with just a request map, returns a path of the current page but re-generated to support current language in use (taken from :language/str key of the request map).

The optional name-path-fallback? argument, when set to a truthy value (true by default), causes non-matching route identifier to be retried by extracting its path and calling this function for that path given as a string.

The optional lang-required? argument (set to false when not given) enables extra check eliminating pages which do not support the given language parameter. Example:

(localized-page req :login-page :pl true)

will fail if there is no parameter :lang handled by the route named :login-page.

When the given path is already parameterized with language then re-parameterized path is generated and checked if it exists, unless the value of the parameter is the same as the existing one. In such case the path is returned after a quick existence check.

Additional path parameters (path-params) can be given to be used when matching by name. Giving extra (unknown to route) parameters does not affect lookup. Giving path-params when matching by path causes them to be silently ignored.

Additional query parameters (query-params) can be given. They will be used when generating path. If the path was given and it already contains query parameters, they will be replaced.

If the path is given instead of a route identifier, it must exist (after being equipped with any extra parameters, if needed, using path-params).

When the lang-required? is set to false (default) and a path is given but it does not require language parameter, a path will be generated by testing whether it exists for regular and for slash-stripped or slash-added variant (the original variant goes first).

When the lang-required? is set to false (default) and a path is given but it does not require language parameter plus the name-path-fallback? argument is set to :brute-force, all possible path variants (with language parameter injected within its succesive segments) will be tried in hope that one will exist, regardless of parameter name that matches. Use it with caution as it may give weird matches; if for example, there is a route path /users/:id defined, and the given path is /users/ with language set to :pl, then it will match /users/pl even though the parameter is not related to a language.

When the lang-required? is set to true and a path is given but it does not require a language parameter, all possible path variants (with parameter injected within its succesive segments) will be tried in hope that one will match, being a path that requires language parameter.

localized-path

(localized-path)(localized-path req)(localized-path req name-or-path)(localized-path req name-or-path lang)(localized-path req name-or-path lang params)(localized-path req name-or-path lang params query-params)(localized-path name-or-path lang params query-params router language-settings-or-param)

Creates a URL on a basis of route name or a path.

Uses very optimistic matching algorithm. Tries to obtain language from user settings and client settings if the path does not contain language information. Uses the :default language picker.

Non-matching route identifier is retried by extracting its path and calling the localized-page function for that path given as a string.

If a page found does not have a language parameter it is accepted too.

When the given path is already parameterized with language then re-parameterized path is generated and checked if it exists, unless the value of the parameter is the same as the existing one. In such case the path is returned after a quick existence check.

Additional path parameters (params) can be given to be used when matching by name. Giving extra (unknown to route) parameters does not affect lookup. Giving params when matching by path causes them to be silently ignored.

Additional query parameters (query-params) can be given. They will be used when generating path. If the path was given and it already contains query parameters, they will be replaced.

If the path is given instead of a route identifier, it must exist (after being equipped with any extra parameters, if needed, using params).

When a path is given but it does not require language parameter, a path will be generated by testing whether it exists for regular and for slash-stripped or slash-added variant (the original variant goes first).

localized-permanent-redirect

(localized-permanent-redirect)(localized-permanent-redirect req)(localized-permanent-redirect url)(localized-permanent-redirect req url)(localized-permanent-redirect req name-or-path)(localized-permanent-redirect req name-or-path path-params)(localized-permanent-redirect req name-or-path path-params query-params)(localized-permanent-redirect req name-or-path lang)(localized-permanent-redirect req name-or-path lang path-params)(localized-permanent-redirect req name-or-path lang path-params query-params)(localized-permanent-redirect req name-or-path lang path-params query-params & more)

Uses the localized-page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 308 to it using resp/permanent-redirect. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil.

localized-redirect

(localized-redirect f)(localized-redirect f req)(localized-redirect f url)(localized-redirect f req url)(localized-redirect f req name-or-path)(localized-redirect f req name-or-path path-params)(localized-redirect f req name-or-path path-params query-params)(localized-redirect f req name-or-path lang)(localized-redirect f req name-or-path lang path-params)(localized-redirect f req name-or-path lang path-params query-params)(localized-redirect f req name-or-path lang path-params query-params & more)

Generic redirect wrapper. The f should be a function which takes a request map and returns a response; should take at least one single argument which should be a URL. The URL will be parameterized with a language. Works almost the same way as the redirect but it will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that localized path will be produced, or nil.

localized-see-other

(localized-see-other)(localized-see-other req)(localized-see-other url)(localized-see-other req url)(localized-see-other req name-or-path)(localized-see-other req name-or-path path-params)(localized-see-other req name-or-path path-params query-params)(localized-see-other req name-or-path lang)(localized-see-other req name-or-path lang path-params)(localized-see-other req name-or-path lang path-params query-params)(localized-see-other req name-or-path lang path-params query-params & more)

Uses the localized-page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 303 to it using resp/see-other. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil.

localized-temporary-redirect

(localized-temporary-redirect)(localized-temporary-redirect req)(localized-temporary-redirect url)(localized-temporary-redirect req url)(localized-temporary-redirect req name-or-path)(localized-temporary-redirect req name-or-path path-params)(localized-temporary-redirect req name-or-path path-params query-params)(localized-temporary-redirect req name-or-path lang)(localized-temporary-redirect req name-or-path lang path-params)(localized-temporary-redirect req name-or-path lang path-params query-params)(localized-temporary-redirect req name-or-path lang path-params query-params & more)

Uses the localized-page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 307 to it using resp/temporary-redirect. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil.

localized-use-proxy

(localized-use-proxy)(localized-use-proxy req)(localized-use-proxy url)(localized-use-proxy req url)(localized-use-proxy req name-or-path)(localized-use-proxy req name-or-path path-params)(localized-use-proxy req name-or-path path-params query-params)(localized-use-proxy req name-or-path lang)(localized-use-proxy req name-or-path lang path-params)(localized-use-proxy req name-or-path lang path-params query-params)(localized-use-proxy req name-or-path lang path-params query-params & more)

Uses the localized-page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 305 to it using resp/use-proxy. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil.

lock-wait

(lock-wait auth-config-or-lock-wait)

Returns lock-wait configuration option taken from the authentication configuration map or given as a time duration. Does not connect to a database.

lock-wait-default

login-auth-state

(login-auth-state req)(login-auth-state req ring-match)(login-auth-state req login-page-data auth-page-data)(login-auth-state req ring-match login-page-data auth-page-data)

Helper which returns 2-element vector telling if the current (or given as a match) page is a login page (1st element) and/or an auth page (2nd element).

login-page

(login-page req)(login-page req lang-id)

Returns a path for the login page. The page must have ID of :user/login.

login-page?

(login-page? req)(login-page? req ring-match)

Returns true if the current (or given as a match) page is a login page (has :login-page? route data set to a truthy value).

max-url-len

misdirected-request

(misdirected-request)(misdirected-request body)

421 Misdirected Request The request was directed at a server that is not able to produce a response (e.g. network balancer forwarded traffic to a wrong server).

mobile-agent?

(mobile-agent? req)

move-to

(move-to)(move-to req)(move-to url)(move-to req url)(move-to req name-or-path)(move-to req name-or-path path-params)(move-to req name-or-path path-params query-params)(move-to req name-or-path lang)(move-to req name-or-path lang path-params)(move-to req name-or-path lang path-params query-params)(move-to req name-or-path lang path-params query-params & more)

Uses the localized-page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 307 to it using resp/temporary-redirect. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

The difference between this function and its regular counterpart (if defined) is in binary variants of them (when a request map and a name or a path are given as arguments). The regular function will fail to generate a redirect if there is no language parameter and the given path does not point to an existing page. On the contrary, this function will generate a localized path using a language obtained from a request (under :language/str key) and if there will be no language-parameterized variant of the path, it will fail. Use this function to make sure that a localized path will be produced, or nil.

moved-permanently

(moved-permanently)(moved-permanently req)(moved-permanently url)(moved-permanently req url)(moved-permanently req name-or-path)(moved-permanently req name-or-path path-params)(moved-permanently req name-or-path path-params query-params)(moved-permanently req name-or-path lang)(moved-permanently req name-or-path lang path-params)(moved-permanently req name-or-path lang path-params query-params)(moved-permanently req name-or-path lang path-params query-params & more)

Uses the page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 301 to it using resp/moved-permanently. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

multiple-choices

(multiple-choices)(multiple-choices req)(multiple-choices url)(multiple-choices req url)(multiple-choices req name-or-path)(multiple-choices req name-or-path path-params)(multiple-choices req name-or-path path-params query-params)(multiple-choices req name-or-path lang)(multiple-choices req name-or-path lang path-params)(multiple-choices req name-or-path lang path-params query-params)(multiple-choices req name-or-path lang path-params query-params & more)

Uses the page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 300 to it using resp/multiple-choices. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

not-modified

(not-modified)(not-modified req)(not-modified req & more)

on-page?

(on-page?)(on-page? req)(on-page? req page-id-or-path)(on-page? req page-id-or-path & more)

Checks if a current page matches the given route name (if an identifier is given) or the exact path. For multiple page names or paths, it returns true when any of them matches.

on-slash

oplog

(oplog req-or-match & message)

Logs operation using operations logger. First argument should be a request map or a Match object containing configuration associated with the current route data under the :oplog/config key.

oplog-config

(oplog-config req-or-match)

Returns operations logger configuration obtained from a request or a Match object.

oplog-logger

(oplog-logger req-or-match)

Retrieves operations logger function from a current route data (via :oplog/config key and then the :fn/reporter key), and if that fails, tries to retrieve it using :oplog/config key of the request map (and :fn/reporter sub-key). When everything fails it will fall back to a global variable amelinium.common.oplog.auth/log. The given argument can be either a request map or a Match object.

oplog-logger-from-route-data

(oplog-logger-from-route-data route-data)

Retrieves operations logger function from a given route data map (via :oplog/config key and then the :fn/reporter key) and creates a wrapper for handling keyword arguments.

oplog-logger-populated

(oplog-logger-populated req)(oplog-logger-populated req route-data)

Creates operations logging function on a basis of operations logger retrieved by getting :oplog/logger key of the request (req), and if that fails by calling oplog-logger-from-route-data (when route-data is given), and if that fails by calling oplog-logger function on a req (which falls back to amelinium.common.oplog.auth/log).

page

(page req)(page req name-or-path)(page req name-or-path path-params)(page req name-or-path path-params query-params)(page req name-or-path lang)(page req name-or-path lang path-params)(page req name-or-path lang path-params query-params)(page req name-or-path lang lang-required?)(page req name-or-path lang path-params lang-required?)(page req name-or-path lang path-params query-params lang-required?)(page req name-or-path lang path-params query-params lang-required? name-path-fallback?)(page _ _ name-or-path path-params query-params router hint-lang lang-settings-or-param)(page _ name-or-path lang path-params query-params lang-required? name-path-fallback? router lang-settings-or-param)

Generates a page path for the given page identifier (a route name) or a path, and optional language identifier. When called with just a request map, returns a path of the current page.

It tries to be optimistic. When called for a page identified by its name (expressed as an identifier, usually a keyword) and with a language parameter to be found (so it cannot be looked up using just a name alone), it will use currently detected language obtained from the given request map (key :language/str), and will use it.

Additional query parameters (query-params) can be given. They will be used when generating path with localized-page. If the path was given and it already contains query parameters, they will be replaced.

Additional path parameters (path-params) may be given. Giving extra (unknown to route) parameters does not affect lookup. Giving path-params when matching by path causes them to be silently ignored.

When invoked with a language parameter, calls localized-page internally.

When invoked with a language parameter, the lang-required? argument may be used (by default set to false) to check if a matching route is parameterized with a language parameter. This is to ensure that only a localized route is used.

When invoked with a language parameter, the optional name-path-fallback? argument may be used (set to true by default) to cause non-matching route identifier to be retried by extracting its path and calling localized-page function for that path expressed as a string.

If the path is given instead of a route identifier, it must exist (after being equipped with any extra parameters, if needed, using path-params).

When invoked with a language parameter, the lang-required? is set to false (default), and a path is given but it does not require language parameter, a path will be generated by testing whether it exists for regular and for slash-stripped or slash-added variant (the original variant goes first).

When invoked with a language parameter, the lang-required? is set to false (default), and a path is given but it does not require language parameter plus the name-path-fallback? argument is set to :brute-force, all possible path variants (with language parameter injected within its succesive segments) will be tried in hope that one will exist, regardless of parameter name that matches. Use it with caution as it may give weird matches; if for example, there is a route path /users/:id defined, and the given path is /users/ with language set to :pl, then it will match /users/pl even though the parameter is not related to a language.

When invoked with a language parameter, the lang-required? is set to true, and a path is given but it does not require a language parameter, all possible path variants (with language parameter injected within its succesive segments) will be tried in hope that one will match, being a path that requires language parameter.

page-cache-len

parameterized-page

(parameterized-page)(parameterized-page req)(parameterized-page req name-or-path)(parameterized-page req name-or-path param param-value)(parameterized-page req name-or-path param param-value path-params)(parameterized-page req name-or-path param param-value path-params query-params)(parameterized-page req name-or-path param param-value require-param?)(parameterized-page req name-or-path param param-value path-params require-param?)(parameterized-page req name-or-path param param-value path-params query-params require-param?)(parameterized-page req name-or-path param param-value path-params query-params require-param? name-path-fallback?)(parameterized-page _ name-or-path param param-value path-params query-params require-param? name-path-fallback? router)

Generates a path for the given page identifier (which may be a name expressed with an identifier, preferably a keyword, or a path expressed as a string) and a parameter with the given value.

Optional path parameters may be given. They will be used to match a page by name if it requires additional parameters to be present.

Examples:

(parameterized-page req) (parameterized-page req :login-page) (parameterized-page req :login-page :lang :pl) (parameterized-page req :login-page :lang :pl {:client "wow-corp"}) (parameterized-page req "/login/page/") (parameterized-page req "/login/page/" :lang :pl) (parameterized-page req "/en/login/page/" :lang :pl)

When called with just a request map, returns a path of the current page if the page exists. When called with a page name or path, it returns a path if the page exists.

The optional name-path-fallback? argument, when set to a truthy value (default is false), causes non-matching route identifier to be retried by extracting its path and calling this function for that path given as a string.

The optional require-param? argument (set to false when not given) enables extra check eliminating pages which do not support the given parameter, yet would be matched. Example:

(parameterized-page req :login-page :lang :pl true)

will fail if there is no parameter :lang handled by the route named :login-page.

When the given path is already parameterized then re-parameterized path is generated and checked if it exists, unless the value of the parameter is the same as the existing one. In such case the path is returned after a quick existence check.

Additional path parameters (path-params) can be given to be used when matching by name. Giving extra (unknown to route) parameters does not affect lookup. Giving path-params when matching by path causes them to be silently ignored.

Additional query parameters (query-params) can be given. They will be used when generating path. If the path was given and it already contains query parameters, they will be replaced.

If the path is given instead of a route identifier, it must exist (after being equipped with any extra parameters, if needed, using path-params).

When the require-param? is set to false (default) and a path is given but it does not require this parameter, a path will be generated by testing whether it exists for regular and for slash-stripped or slash-added variant (the original variant goes first).

When the require-param? is set to false (default) and a path is given but it does not require this parameter plus the name-path-fallback? argument is set to :brute-force, all possible path variants (with parameter injected within its succesive segments) will be tried in hope that one will exist, regardless of parameter name that matches. Use it with caution as it may give weird matches; if for example, there is a route path /users/:id defined, and the given path is /users/ with :lang parameter set to :pl, then it will match /users/pl even though the parameter name is different.

When the require-param? is set to true and a path is given but it does not require this parameter, all possible path variants (with parameter injected within its succesive segments) will be tried in hope that one will match, being a path that requires this parameter.

parse-query-params

(parse-query-params req qstr)

Parses query params string qstr using Ring’s ring.util.codec/form-decode. The given request map req is used internally to get the current character encoding (with fallback to UTF-8).

path

(path)(path req)(path req name-or-path)(path req name-or-path lang)(path req name-or-path lang params)(path req name-or-path lang params query-params)(path name-or-path lang params query-params router language-settings-or-param)

Creates a URL on a basis of route name or a path.

If a page found does not have a language parameter it is accepted too.

When the given path is already parameterized with language then re-parameterized path is generated and checked if it exists, unless the value of the parameter is the same as the existing one. In such case the path is returned after a quick existence check.

Additional path parameters (params) can be given to be used when matching by name. Giving extra (unknown to route) parameters does not affect lookup. Giving params when matching by path causes them to be silently ignored.

Additional query parameters (query-params) can be given. They will be used when generating path. If the path was given and it already contains query parameters, they will be replaced.

If the path is given instead of a route identifier, it must exist (after being equipped with any extra parameters, if needed, using params).

When a path is given but it does not require language parameter, a path will be generated by testing whether it exists for regular and for slash-stripped or slash-added variant (the original variant goes first).

path-language

(path-language req)(path-language req-or-match path-or-lang-settings)(path-language req path router)(path-language _ path router language-settings-or-param)

Returns a language string if the given path contains a language parameter. Otherwise it returns nil.

path-param

(path-param req-or-match param)(path-param req path param)(path-param _ path param router)

Returns a parameter if the given path contains it and it is set. Otherwise it returns nil.

path-params

(path-params req-or-match)(path-params req path)(path-params _ path router)

Returns a map of parameters if the given path contains it. Otherwise it returns nil.

path-slash-variants

(path-slash-variants uri)

Returns a 2-element vector of a path containing its two variants: with and without a trailing slash. The original path is always placed first.

If the path is empty, vector of an empty string and a slash is returned. If the path is a slash, vector of a slash and an empty string is returned.

If the path is nil, it returns nil.

path-splitter

path-template-with-param

(path-template-with-param match required-param)(path-template-with-param match required-param short-circuit)

Returns a path template for the given match if the route supports the given parameter.

path-variants

(path-variants path lang-id)(path-variants path lang suffix)

Generates a list of all possible language variants of a path.

permanent-redirect

(permanent-redirect)(permanent-redirect req)(permanent-redirect url)(permanent-redirect req url)(permanent-redirect req name-or-path)(permanent-redirect req name-or-path path-params)(permanent-redirect req name-or-path path-params query-params)(permanent-redirect req name-or-path lang)(permanent-redirect req name-or-path lang path-params)(permanent-redirect req name-or-path lang path-params query-params)(permanent-redirect req name-or-path lang path-params query-params & more)

Uses the page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 308 to it using resp/permanent-redirect. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

pick-language

(pick-language req)(pick-language req pickers)(pick-language req picker-id)(pick-language req pickers picker-id)

Tries to pick the best language for a known user or a visitor. To be used (among other scenarios) after a successful log-in to show the right language version of a welcome page. Does not use pre-calculated values from a request map, instead triggers configured pickers from a default or given chain. Returns a keyword.

pick-language-str

(pick-language-str req)(pick-language-str req pickers)(pick-language-str req picker-id)(pick-language-str req pickers picker-id)

Tries to pick the best language for a known user or a visitor. To be used (among other scenarios) after a successful log-in to show the right language version of a welcome page. Does not use pre-calculated values from a request map, instead triggers configured pickers from a default or given chain. Returns a string.

pick-language-str-without-fallback

(pick-language-str-without-fallback req)(pick-language-str-without-fallback req pickers)(pick-language-str-without-fallback req picker-id)(pick-language-str-without-fallback req pickers picker-id)

Tries to pick the best language for a known user or a visitor. To be used (among other scenarios) after a successful log-in to show the right language version of a welcome page. Does not use pre-calculated values from a request map, instead triggers configured pickers from a default or given chain. When a language cannot be found it simply returns nil instead of a default language. Returns a string.

pick-language-without-fallback

(pick-language-without-fallback req)(pick-language-without-fallback req pickers)(pick-language-without-fallback req picker-id)(pick-language-without-fallback req pickers picker-id)

Tries to pick the best language for a known user or a visitor. To be used (among other scenarios) after a successful log-in to show the right language version of a welcome page. Does not use pre-calculated values from a request map, instead triggers configured pickers from a default or given chain. When a language cannot be found it simply returns nil instead of a default language. Returns a keyword.

pick-params

(pick-params params)(pick-params params ns)(pick-params params keys)(pick-params params key-map)(pick-params params new-ns ns)(pick-params params new-ns keys)

Removes namespaces from keys in params or renames keys according to the given key-map.

The keys argument should be a sequence of keys to be found in params. Only the entries identified by these keys will be preserved, with keys stripped from their namespaces. When new-ns is present then the keys in generated map will have their namespace set to this value (which should be a string or any object convertible to a string).

The key-map argument should be a map of keys to be found in params mapped to their new names. Only the entries from params identified by the keys from key-map will be preserved and renamed to corresponding values.

The ns argument should be a string or an object which can be converted to a string. It will be used to select the entries from params by the given namespace and to remove this namespace when producing the result. When new-ns is present then the keys in generated map will have their namespace set to this value (which should be a string or any object convertible to a string).

When only params argument is given, it will simply rename all keys from namespaced to simple keywords.

When params argument is given, then ns is set to nil, and new-ns is set, it will strip all keys from their namespaces replacing it with the given namespace in a resulting map.

query-string-encode

(query-string-encode params)(query-string-encode req params)

redirect

(redirect f)(redirect f req)(redirect f url)(redirect f req url)(redirect f req name-or-path)(redirect f req name-or-path path-params)(redirect f req name-or-path path-params query-params)(redirect f req name-or-path lang)(redirect f req name-or-path lang path-params)(redirect f req name-or-path lang path-params query-params)(redirect f req name-or-path lang path-params query-params & more)

Generic redirect wrapper. The f should be a function which takes a request map and returns a response; should take at least one single argument which should be a URL. The URL will be parameterized with a language if required. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

reflect-session-hx-header

(reflect-session-hx-header req sess)

Tries to obtain session ID from the given sess object, and if that fails from the request header with name same as session ID field (obtained by calling amelinium.http.middleware.session/id-field on sess) from the req map. Then it uses add-json-event-handler to set HX-Trigger response header in a similar way the add-session-hx-header does.

reflect-session-id-header

(reflect-session-id-header req sess)

Adds session ID header to the :response/headers map of the given req map. Name of the header is obtained from session ID field (by calling amelinium.http.middleware.session/id-field) and its value is set to session ID (obtained by calling amelinium.http.middleware.session/any-id, and if that fails by getting the value of client request header with the same name using get-session-id-header). If the header already exists it is not added.

remove-body-params

(remove-body-params m param)(remove-body-params m param & more)

Removes the given parameter or parameters from a request map locations: [:parameters :body], :body-params and :params. All parameters must be either keywords or strings, they cannot be mixed.

remove-form-params

(remove-form-params m param)(remove-form-params m param & more)

Removes the given parameter or parameters from a request map locations: [:parameters :form], :form-params and :params. All parameters must be either keywords or strings, they cannot be mixed.

remove-params

(remove-params m params-key parameters-sub-key combined? param)(remove-params m params-key parameters-sub-key combined? param & more)

Removes the given parameter or parameters from a request map locations: - from a map associated with parameters-sub-key key within a map associated with :parameters key in m, - from a map associated with params-key key in m, - from a map associated with :params key in m (if combined? is truthy). All parameters must be either keywords or strings, they cannot be mixed. Parameter type params-key and parameters-sub-key should be keywords. If params-key or parameters-sub-key is nil then the removal within a specific location(s) will be skipped.

remove-path-params

(remove-path-params m param)(remove-path-params m param & more)

Removes the given parameter or parameters from a request map locations: [:parameters :path], :path-params and :params. All parameters must be either keywords or strings, they cannot be mixed.

remove-query-params

(remove-query-params m param)(remove-query-params m param & more)

Removes the given parameter or parameters from a request map locations: [:parameters :query], :query-params and :params. All parameters must be either keywords or strings, they cannot be mixed.

remove-status

macro

(remove-status req)

Removes :response/status from req using clojure.core/dissoc.

render

(render resp-fn)(render resp-fn req)(render resp-fn req a)(render resp-fn req a b)(render resp-fn req a b c)(render resp-fn req a b c & more)

Universal response renderer. Returns the result of calling the resp-fn with headers attached (from :response/headers key of the req) unless the req is already a valid response. Arguments from the third are passed to resp-fn function.

render-force

(render-force resp-fn)(render-force resp-fn req)(render-force resp-fn req a)(render-force resp-fn req a b)(render-force resp-fn req a b c)(render-force resp-fn req a b c & more)

Universal body-less response renderer. Returns the result of calling the resp-fn with headers attached (from :response/headers key of the req). Arguments from the third are passed to resp-fn function.

replace-session-hx-header

(replace-session-hx-header req sess)

Adds HX-Trigger server response header to :response/headers map of the given req map by putting a JSON in the following form:

{"setSession":{"session-id": "SID"}}

where the session-id string is obtained from session’s ID field (using amelinium.http.middleware.session/id-field) and SID is replaced with session ID (obtained with amelinium.http.middleware.session/any-id).

If the HX-Trigger header already exists, it will be modified and any value associated with setSession key will be modified.

replace-session-id-header

(replace-session-id-header req sess)

Adds session ID header to the :response/headers map of the given req map. Name of the header is obtained from session ID field (by calling amelinium.http.middleware.session/id-field) and its value is set to session ID (obtained by calling amelinium.http.middleware.session/any-id). If the header already exists it is replaced.

role-required!

(role-required! req role)

roles-for-context

(roles-for-context req user-id context)(roles-for-context req context)(roles-for-context req)

roles-for-contexts

(roles-for-contexts req user-id)(roles-for-contexts req)

roles-matrix

(roles-matrix req)(roles-matrix req opts)

roles-refresh

(roles-refresh req)

roles-tabler

(roles-tabler req)(roles-tabler {{:keys [global-context], :or {global-context :!}} :roles/config, :as req} {:keys [user-id effective? include-global? include-self? present-label missing-label global-label global-marker global-present-label context-label contexts-labeler], :or {present-label "YES", missing-label "—", global-label "global", context-label "Context", contexts-labeler default-contexts-labeler, include-global? (not effective?), include-self? false}, :as opts})

router-match?

(router-match? v)

Returns true if the given argument is Reitit’s Match object.

see-other

(see-other)(see-other req)(see-other url)(see-other req url)(see-other req name-or-path)(see-other req name-or-path path-params)(see-other req name-or-path path-params query-params)(see-other req name-or-path lang)(see-other req name-or-path lang path-params)(see-other req name-or-path lang path-params query-params)(see-other req name-or-path lang path-params query-params & more)

Uses the page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 303 to it using resp/see-other. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

session

(session req)(session req session-key)

Gets a session map from the given request map.

session-config

(session-config req)(session-config req session-key)

Gets a session config map from the given request map.

session-inject

(session-inject req smap)(session-inject req smap session-key)

Adds session data to a request map. Session key is obtained from the config field of smap or (if given) from a session-key argument.

session-variable-get-failed?

(session-variable-get-failed? v)

slash-break

slash-redir

(slash-redir req)

Redirects to a slash-trailed version of the same URI. If the URI already has a slash, it returns a req.

soft-lock-passed

(soft-lock-passed user time)

Returns the time duration between soft lock and the given moment. If the duration is zero or negative, it returns nil.

soft-lock-remains

(soft-lock-remains lock-passed auth-config-or-lw)(soft-lock-remains user auth-config-or-lw time)

Returns the amount of time left before reaching lock-wait. If the amount is negative or zero, it returns nil. Does not connect to a database.

soft-lock-time

(soft-lock-time user)

Gets a soft lock time for the given user specified by a map having :soft-locked key.

soft-locked?

(soft-locked? lock-passed auth-config-or-lw)(soft-locked? user auth-config-or-lw time)

Returns true if the given user account is soft-locked (the time amount which passed from the lock till the given time is lesser than the soft lock wait configuration option). Does not connect to a database.

split-qparams

split-query-params

(split-query-params path)

Splits path into 3 string components: path, location and query params. Returns a vector.

split-query-params-simple

(split-query-params-simple path)

Splits path into 2 components: path string and location / query params string. Returns a sequence.

strictly-localized-page

(strictly-localized-page req)(strictly-localized-page req name-or-path)(strictly-localized-page req name-or-path lang)(strictly-localized-page req name-or-path lang params)(strictly-localized-page req name-or-path lang params query-params)(strictly-localized-page name-or-path lang params query-params router lang-param)

Same as localized-page with lang-required? always set to true, name-path-fallback? set to false, and with less arities supported. When the language version of a page identified by its name is not present it will return nil.

template-path

(template-path match params)(template-path match params query-params)(template-path path template params _)

Replaces parameters in the given path using a template.

temporary-redirect

(temporary-redirect)(temporary-redirect req)(temporary-redirect url)(temporary-redirect req url)(temporary-redirect req name-or-path)(temporary-redirect req name-or-path path-params)(temporary-redirect req name-or-path path-params query-params)(temporary-redirect req name-or-path lang)(temporary-redirect req name-or-path lang path-params)(temporary-redirect req name-or-path lang path-params query-params)(temporary-redirect req name-or-path lang path-params query-params & more)

Uses the page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 307 to it using resp/temporary-redirect. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

translator

(translator req)(translator req lang-id)

Generates a translation function using populated values from :i18n/translator or :i18n/translator-nd (variant which returns nil for missing keys, used when i18n/*handle-missing-keys* is set to a falsy value).

Falls back to i18n/translator if predefined functions are not populated in the request map or if a language was specified as an optional lang argument and it differs from the language stored in req under :language/id (or :language/default).

translator-sub

(translator-sub req)(translator-sub req lang-id)

untranslatable?

(untranslatable? v)

Returns true if the given argument cannot be used as a translation key.

url->uri+params

(url->uri+params req u)

Takes a request map req and URI (u) and tries to decompose it into 2-element vector with first element being a URI and second a query params map. If there is a processing exception during the operation, string-converted u is returned unmodified and query params slot is set to be nil. The request map is used internally to get the current character encoding (with fallback to UTF-8).

use-hx?

(use-hx? req)(use-hx? req route-data)(use-hx? req route-data extra-key)

Returns true if response should be HTMX-compatible, false if it should not. Uses optional route-data or gets it from the req to look for (optional) extra-key first, and if it is not given or has falsy value then gets a value associated with the :use-htmx? key.

  • If the obtained value is false, it will return false.
  • If the obtained value is true or any non-nil value, it will return true.
  • If the obtained value is nil, or there is no route data nor any of the mentioned keys can be found in route data, it will try to auto-detect HTMX using hx-request? function which analyzes the HX-Request request header.

use-proxy

(use-proxy)(use-proxy req)(use-proxy url)(use-proxy req url)(use-proxy req name-or-path)(use-proxy req name-or-path path-params)(use-proxy req name-or-path path-params query-params)(use-proxy req name-or-path lang)(use-proxy req name-or-path lang path-params)(use-proxy req name-or-path lang path-params query-params)(use-proxy req name-or-path lang path-params query-params & more)

Uses the page function to calculate the destination path on a basis of page name (identifier) or a path (a string) and performs a redirect with code 305 to it using resp/use-proxy. If the language is given it uses the localized-page function. If there is no language given but the page identified by its name requires a language parameter to be set, it will be obtained from the given request map (under the key :language/str).

with-role-only!

macro

(with-role-only! req role & body)