SlotDto.vala 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Invercargill;
  2. using Invercargill.Mapping;
  3. namespace Statum.Model {
  4. /**
  5. * A Statum slot.
  6. *
  7. * A slot is an addressable container for a single snapshot. Its `key` is a
  8. * server-issued identifier used on the wire (in headers and directives),
  9. * its `scope` controls client-side persistence, and its `slot_type` is an
  10. * application-defined name under which the frontend exposes the slot's
  11. * current {@link SnapshotDto.public} data.
  12. *
  13. * Statum assumes at most one slot per type on the client.
  14. */
  15. public class SlotDto : Object {
  16. /** Server-issued identifier for the slot. */
  17. public string key { get; set; }
  18. /** Client-side persistence scope for the slot. */
  19. public Scope scope { get; set; }
  20. /**
  21. * Application-defined type name for the slot.
  22. *
  23. * Named `slot_type` (rather than `type`) because GObject reserves a
  24. * property named `type`; the JSON key remains `type` via the mapper.
  25. */
  26. public string slot_type { get; set; }
  27. /**
  28. * The {@link PropertyMapper} used to (de)serialise a {@link SlotDto}
  29. * to/from a {@link Invercargill.Properties} object (and therefore
  30. * JSON via Invercargill-Json).
  31. */
  32. public static PropertyMapper<SlotDto> get_mapper() {
  33. return PropertyMapper.build_for<SlotDto>(cfg => {
  34. cfg.map<string>("key", o => o.key, (o, v) => o.key = v);
  35. cfg.map<string>("scope", o => o.scope.to_string(), (o, v) => o.scope = Scope.parse(v));
  36. cfg.map<string>("type", o => o.slot_type, (o, v) => o.slot_type = v);
  37. cfg.set_constructor(() => new SlotDto());
  38. });
  39. }
  40. }
  41. }