Skip to main content

Crate nitr_std

Crate nitr_std 

Source
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 input declarations, text coercion, the error shape, and the nitr.File handle for validated uploads.

Structs§

Builtins
Built-in nitr.* standard library modules that can be exposed to Lua scripts.
BuiltinsEnv
External resources required by some builtins: template needs a templates directory and db a SQLite database file.
EnvOptions
Read policy for the nitr.env builtin.
FetchOptions
Policy and limits applied to every outbound fetch request.
RequestCookies
Cookies parsed from a request’s Cookie header: values via indexing (req.cookies.session) and signed-cookie verification via req.cookies:verify(name, secret).
ResponseCookies
Builder for response Set-Cookie headers, attached as the cookies field of helper-built response tables. The server serializes each entry into its own Set-Cookie header.
SetCookie
One Set-Cookie line as a client reads it: the pair plus every attribute, Expires as unix seconds.
SqlitePragmas
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 offered media types for an Accept header value, honoring q-values and type/* / */* 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_error receives and nitr.errinfo returns. A plain table (it serializes to JSON for free) that stringifies — and concatenates — as the concise kind: 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-Cookie header value, or None when it has no valid name=value pair. The attribute grammar is the cookie crate’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 nitr namespace table, using the BuiltinsEnv for the resources some of them need.
reset_outbound_budgetNon-fetch
Resets the per-request outbound budget. A no-op without the fetch feature, so the server can call it unconditionally.
response_table
Builds the skeleton of a helper response table: status, empty headers, and an attached ResponseCookies builder.
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 test too, or a config script’s dev fallback would not apply under nitr test.
set_trace_contextNon-fetch
Records the inbound request id for traceparent propagation. A no-op without the fetch feature.