Expand description
The built-in nitr.* standard library for Nitr and its registration.
Every builtin mounts as a field of the global nitr namespace table
(nitr.json, nitr.fetch, nitr.db, …) — Nitr registers no other
globals, so scripts always read nitr.* and nothing is intermixed with
the Lua standard library.
Re-exports§
pub use cache::Cache;pub use cache::CacheOptions;
Modules§
- cache
nitr.cache: a bounded, Rust-owned cache shared by every pooled state.- clock
- The one clock the standard library reads, with an override for
nitr test(nitr.test.clock). - testing
- Test doubles for
nitr test: canned outbound responses and environment overrides, installed by a test as data and read by the standard library at the seams that honour them. - validation
- The validation engine as the server uses it: compiled schemas for route
inputdeclarations, text coercion, the error shape, and thenitr.Filehandle for validated uploads.
Structs§
- Builtins
- Built-in
nitr.*standard library modules that can be exposed to Lua scripts. - Builtins
Env - External resources required by some builtins:
templateneeds a templates directory anddba SQLite database file. - EnvOptions
- Read policy for the
nitr.envbuiltin. - Fetch
Options - Policy and limits applied to every outbound
fetchrequest. - Request
Cookies - Cookies parsed from a request’s
Cookieheader: values via indexing (req.cookies.session) and signed-cookie verification viareq.cookies:verify(name, secret). - Response
Cookies - Builder for response
Set-Cookieheaders, attached as thecookiesfield of helper-built response tables. The server serializes each entry into its ownSet-Cookieheader. - SetCookie
- One
Set-Cookieline as a client reads it: the pair plus every attribute,Expiresas unix seconds. - Sqlite
Pragmas - The pragma set applied to a connection when it is opened.
Enums§
- RunMode
- What a process is running as, decided by the server (
dev_mode) or the test runner and never by a script.
Constants§
- MAX_
PASSWORD_ BYTES - Upper bound on a password handed to
password_hash/password_verify, in bytes — the argon2 input cap, checked before any hashing work.
Functions§
- best_
match - Picks the best of
offeredmedia types for anAcceptheader value, honoring q-values andtype/*/*/*wildcards. More specific ranges win at equal quality; ties go to the earlier offer. - error_
lua_ value - Builds the structured error value the error model hands to Lua: the
table
on_errorreceives andnitr.errinforeturns. A plain table (it serializes to JSON for free) that stringifies — and concatenates — as the concisekind: message (source:line)form via a cached metatable. - json_
encode - Encodes a Lua value as JSON under the standard library’s bounds (depth, node count, UTF-8) — the encoder anything outside this crate uses for a script’s value, so deep nesting is an error rather than a stack overflow.
- parse_
set_ cookie - Parses one
Set-Cookieheader value, orNonewhen it has no validname=valuepair. The attribute grammar is thecookiecrate’s (the same crate that serializes Nitr’s own cookies), so a round trip cannot disagree with the writer. - register_
builtins - Registers the selected builtins on the global
nitrnamespace table, using theBuiltinsEnvfor the resources some of them need. - reset_
outbound_ budget Non- fetch - Resets the per-request outbound budget. A no-op without the
fetchfeature, so the server can call it unconditionally. - response_
table - Builds the skeleton of a helper response table: status, empty headers,
and an attached
ResponseCookiesbuilder. - set_
run_ mode - Overrides the mode of a state whose builtins are already registered:
the test runner boots a real server from the same configuration, and
its states must answer
testtoo, or a config script’sdevfallback would not apply undernitr test. - set_
trace_ context Non- fetch - Records the inbound request id for
traceparentpropagation. A no-op without thefetchfeature.