Files
mono/events/queries.sx
giles 1f36987f77 Replace inter-service _handlers dicts with declarative sx defquery/defaction
The inter-service data layer (fetch_data/call_action) was the least
structured part of the codebase — Python _handlers dicts with ad-hoc
param extraction scattered across 16 route files. This replaces them
with declarative .sx query/action definitions that make the entire
inter-service protocol self-describing and greppable.

Infrastructure:
- defquery/defaction special forms in the sx evaluator
- Query/action registry with load, lookup, and schema introspection
- Query executor using async_eval with I/O primitives
- Blueprint factories (create_data_blueprint/create_action_blueprint)
  with sx-first dispatch and Python fallback
- /internal/schema endpoint on every service
- parse-datetime and split-ids primitives for type coercion

Service extractions:
- LikesService (toggle, is_liked, liked_slugs, liked_ids)
- PageConfigService (ensure, get_by_container, get_by_id, get_batch, update)
- RelationsService (wraps module-level functions)
- AccountDataService (user_by_email, newsletters)
- CartItemsService, MarketDataService (raw SQLAlchemy lookups)

50 of 54 handlers converted to sx, 4 Python fallbacks remain
(ghost-sync/push-member, clear-cart-for-order, create-order).
Net: -1,383 lines Python, +251 lines modified.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 08:13:50 +00:00

58 lines
2.4 KiB
Plaintext

;; Events service — inter-service data queries
;;
;; Each defquery replaces a Python handler in bp/data/routes.py.
;; The (service ...) primitive calls the registered CalendarService method
;; with g.s (async session) + keyword args, and auto-converts DTOs to dicts.
(defquery pending-entries (&key user-id session-id)
"Calendar entries in pending state for a user or session."
(service "calendar" "pending-entries"
:user-id user-id :session-id session-id))
(defquery pending-tickets (&key user-id session-id)
"Tickets in pending state for a user or session."
(service "calendar" "pending-tickets"
:user-id user-id :session-id session-id))
(defquery entries-for-page (&key page-id user-id session-id)
"Calendar entries for a specific page."
(service "calendar" "entries-for-page"
:page-id page-id :user-id user-id :session-id session-id))
(defquery tickets-for-page (&key page-id user-id session-id)
"Tickets for a specific page."
(service "calendar" "tickets-for-page"
:page-id page-id :user-id user-id :session-id session-id))
(defquery entries-for-order (&key order-id)
"Calendar entries claimed by an order."
(service "calendar" "get-entries-for-order" :order-id order-id))
(defquery tickets-for-order (&key order-id)
"Tickets claimed by an order."
(service "calendar" "get-tickets-for-order" :order-id order-id))
(defquery entry-ids-for-content (&key content-type content-id)
"Entry IDs associated with a content item."
(service "calendar" "entry-ids-for-content"
:content-type content-type :content-id content-id))
(defquery associated-entries (&key content-type content-id page)
"Entries associated with content, paginated."
(let ((result (service "calendar" "associated-entries"
:content-type content-type :content-id content-id :page page)))
{"entries" (nth result 0) "has_more" (nth result 1)}))
(defquery calendars-for-container (&key type id)
"Calendars attached to a container (page, marketplace, etc)."
(service "calendar" "calendars-for-container"
:container-type type :container-id id))
(defquery visible-entries-for-period (&key calendar-id period-start period-end user-id session-id)
"Visible entries within a date range for a calendar."
(service "calendar" "visible-entries-for-period"
:calendar-id calendar-id
:period-start (parse-datetime period-start)
:period-end (parse-datetime period-end)
:user-id user-id :is-admin false :session-id session-id))