Files
rose-ash/shared
giles 5b100cac17 HS runtime + generator: make, Values, toggle styles, scoped storage, array ops, fetch coercion, scripts in PW bodies
Runtime (lib/hyperscript/ + shared/static/wasm/sx/hs-*.sx):
- make: parser accepts `<tag.class#id/>` selectors and `from <expr>,…`; compiler
  emits via scoped-set so `called <name>` persists; `called $X` lands on
  window; runtime dispatches element vs host-new constructor by type.
- Values: `x as Values` walks form inputs/selects/textareas, producing
  {name: value | [value,…]}; duplicates promote to array; multi-select and
  checkbox/radio handled.
- toggle *display/*visibility/*opacity: paired with sensible inline defaults
  in the mock DOM so toggle flips block/visible/1 ↔ none/hidden/0.
- add/remove/put at array: emit-set paths route list mutations back through
  the scoped binding; add hs-put-at! / hs-splice-at! / hs-dict-without.
- remove OBJ.KEY / KEY of OBJ: rebuild dict via hs-dict-without and reassign,
  since SX dicts are copy-on-read across the bridge.
- dom-set-data: use (host-new "Object") rather than (dict) so element-local
  storage actually persists between reads.
- fetch: hs-fetch normalizes JSON/Object/Text/Response format aliases;
  compiler sets `the-result` when wrapping a fetch in the `let ((it …))`
  chain, and __get-cmd shares one evaluation via __hs-g.

Mock DOM (tests/hs-run-filtered.js):
- parseHTMLFragments accepts void elements (<input>, <br>, …);
- setAttribute tracks name/type/checked/selected/multiple;
- select.options populated on appendChild;
- insertAdjacentHTML parses fragments and inserts real El children into the
  parent so HS-activated handlers attach.

Generator (tests/playwright/generate-sx-tests.py):
- process_hs_val strips `//` / `--` line comments before newline→then
  collapse, and strips spurious `then` before else/end/catch/finally.
- parse_dev_body interleaves window-setup ops and DOM resets between
  actions/assertions; pre-html setups still emit up front.
- generate_test_pw compiles any `<script type=text/hyperscript>` (flattened
  across JS string-concat) under guard, exposing def blocks.
- Ordered ops for `run()`-style tests check window.obj.prop via new
  _js_window_expr_to_sx; add DOM-constructing evaluate + _hyperscript
  pattern for `as Values` tests (result.key[i].toBe(…)).
- js_val_to_sx handles backticks and escapes embedded quotes.

Net delta across suites:
- if 16→18, make 0→8, toggle 12→21, add 9→10, remove 11→16, put 29→31,
  fetch 11→15, repeat 14→26, expressions/asExpression 20→25, set 27→28,
  core/scoping 12→14, when 39→39 (no regression).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 16:08:07 +00:00
..

Shared

Shared infrastructure, models, contracts, services, and templates used by all five Rose Ash microservices (blog, market, cart, events, federation). Included as a git submodule in each app.

Structure

shared/
  db/
    base.py                 # SQLAlchemy declarative Base
    session.py              # Async session factory (get_session, register_db)
  models/                   # Canonical domain models
    user.py                 # User
    magic_link.py           # MagicLink (auth tokens)
    (domain_event.py removed — table dropped, see migration n4l2i8j0k1)
    kv.py                   # KeyValue (key-value store)
    menu_item.py            # MenuItem (deprecated — use MenuNode)
    menu_node.py            # MenuNode (navigation tree)
    container_relation.py   # ContainerRelation (parent-child content)
    ghost_membership_entities.py  # GhostNewsletter, UserNewsletter
    federation.py           # ActorProfile, APActivity, APFollower, APFollowing,
                            # RemoteActor, APRemotePost, APLocalPost,
                            # APInteraction, APNotification, APAnchor, IPFSPin
  contracts/
    dtos.py                 # Frozen dataclasses for cross-domain data transfer
    protocols.py            # Service protocols (Blog, Calendar, Market, Cart, Federation)
    widgets.py              # Widget types (NavWidget, CardWidget, AccountPageWidget)
  services/
    registry.py             # Typed singleton: services.blog, .calendar, .market, .cart, .federation
    blog_impl.py            # SqlBlogService
    calendar_impl.py        # SqlCalendarService
    market_impl.py          # SqlMarketService
    cart_impl.py            # SqlCartService
    federation_impl.py      # SqlFederationService
    federation_publish.py   # try_publish() — inline AP publication helper
    stubs.py                # No-op stubs for absent domains
    navigation.py           # get_navigation_tree()
    relationships.py        # attach_child, get_children, detach_child
    widget_registry.py      # Widget registry singleton
    widgets/                # Per-domain widget registration
  infrastructure/
    factory.py              # create_base_app() — Quart app factory
    cart_identity.py        # current_cart_identity() (user_id or session_id)
    cart_loader.py          # Cart data loader for context processors
    context.py              # Jinja2 context processors
    jinja_setup.py          # Jinja2 template environment setup
    urls.py                 # URL helpers (blog_url, market_url, etc.)
    user_loader.py          # Load current user from session
    http_utils.py           # HTTP utility functions
  events/
    bus.py                  # emit_activity(), register_activity_handler()
    processor.py            # EventProcessor (polls ap_activities, runs handlers)
    handlers/               # Shared activity handlers
      container_handlers.py #   Navigation rebuild on attach/detach
      login_handlers.py     #   Cart/entry adoption on login
      order_handlers.py     #   Order lifecycle events
      ap_delivery_handler.py #  AP activity delivery to follower inboxes (wildcard)
  utils/
    __init__.py
    calendar_helpers.py     # Calendar period/entry utilities
    http_signatures.py      # RSA keypair generation, HTTP signature signing/verification
    ipfs_client.py          # Async IPFS client (add_bytes, add_json, pin_cid)
    anchoring.py            # Merkle trees + OpenTimestamps Bitcoin anchoring
    webfinger.py            # WebFinger actor resolution
  browser/
    app/                    # Middleware, CSRF, errors, Redis caching, authz, filters
    templates/              # ~300 Jinja2 templates shared across all apps
  containers.py             # ContainerType, container_filter, content_filter helpers
  config.py                 # YAML config loader
  log_config/setup.py       # Logging configuration (JSON formatter)
  static/                   # Shared static assets (CSS, JS, images, FontAwesome)
  editor/                   # Koenig (Ghost) rich text editor build
  alembic/                  # Database migrations

Key Patterns

  • App factory: All apps call create_base_app() which sets up DB sessions, CSRF, error handling, event processing, logging, widget registration, and domain service wiring.
  • Service contracts: Cross-domain communication via typed Protocols + frozen DTO dataclasses. Apps call services.calendar.method(), never import models from other domains.
  • Service registry: Typed singleton (services.blog, .calendar, .market, .cart, .federation). Apps wire their own domain + stubs for others via register_domain_services().
  • Activity bus: emit_activity() writes to ap_activities table in the caller's transaction. EventProcessor polls pending activities and dispatches to registered handlers. Internal events use visibility="internal"; federation activities use visibility="public" and are delivered to follower inboxes by the wildcard delivery handler.
  • Widget registry: Domain services register widgets (nav, card, account); templates consume via widgets.container_nav, widgets.container_cards.
  • Cart identity: current_cart_identity() returns {"user_id": int|None, "session_id": str|None} from the request session.

Alembic Migrations

All apps share one PostgreSQL database. Migrations are managed here and run from the blog app's entrypoint (other apps skip migrations on startup).

alembic -c shared/alembic.ini upgrade head