using Invercargill; using Invercargill.DataStructures; using Astralis; namespace Statum { /** * The per-request Statum context, shared by page, entrypoint and action * handlers. */ public class StatumRequest : Object { /** The request URI (e.g. the page's `` or an action URI). */ public string uri { get; set; } /** Route parameters captured from the matched {@link EndpointRoute}. */ public ReadOnlyAssociative route_params { get; set; default = new Dictionary(); } /** Held slots, indexed by type name. */ public ReadOnlyAssociative held { get; set; default = new Dictionary(); } /** The request's query parameters. */ public Catalogue query { get; set; } /** * Action-private data decrypted from the `X-Statum-Private` header, or * `null` for non-action requests. */ public Properties? action_private { get; set; } /** Parsed form body for POST/PUT/PATCH actions, or `null`. */ public FormData? form { get; set; } /** * Reads a held slot's public data as a typed model, or `null` if the slot * is not held or cannot be mapped. */ public TPublic? held_as(string type_name) { HeldSlot slot; if (!held.try_get(type_name, out slot) || slot == null) { return null; } try { return GObjectMapping.from_properties_typed(typeof(TPublic), ((!)slot).@public); } catch (GLib.Error e) { return null; } } /** Raw route parameter (from a `` template like `/cats/{species}`), or `null`. */ public string? route(string name) { return route_params.get_or_default(name); } } }