| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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 `<pstm-uri>` or an action URI). */
- public string uri { get; set; }
- /** Route parameters captured from the matched {@link EndpointRoute}. */
- public ReadOnlyAssociative<string, string> route_params { get; set; default = new Dictionary<string, string>(); }
- /** Held slots, indexed by type name. */
- public ReadOnlyAssociative<string, HeldSlot> held { get; set; default = new Dictionary<string, HeldSlot>(); }
- /** The request's query parameters. */
- public Catalogue<string, string> 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<TPublic>(string type_name) {
- HeldSlot slot;
- if (!held.try_get(type_name, out slot) || slot == null) {
- return null;
- }
- try {
- return GObjectMapping.from_properties_typed<TPublic>(typeof(TPublic), ((!)slot).@public);
- } catch (GLib.Error e) {
- return null;
- }
- }
- /** Raw route parameter (from a `<pstm-uri>` template like `/cats/{species}`), or `null`. */
- public string? route(string name) {
- return route_params.get_or_default(name);
- }
- }
- }
|