Skip to content

Migrate session.xq query execution pipeline to REST API #16

@joewiz

Description

@joewiz

Open Question: session.xq migration

The legacy module migration has removed most modules/*.xq files, but session.xq is fundamentally different from the others and warrants discussion before migrating.

Current Architecture

session.xq is not a standalone endpoint — it's a view in eXist-db's URL-rewrite pipeline:

  1. POST execute — controller sends the user's query to XQueryServlet for evaluation, then pipes the results as a request attribute to session.xq, which stores them in the HTTP session and returns <result hits="N" elapsed="T"/>
  2. GET results/N — controller forwards to session.xq with a num parameter, which retrieves item N from the session and returns an HTML <div> with badges, copy buttons, and syntax highlighting

The frontend (eXide.js) expects:

  • XML <result> or <error> elements from execute
  • HTML fragments from results/N, rendered directly into the DOM

API Replacement (already written)

modules/api/query.xqm already provides JSON equivalents:

  • POST /api/query — executes via util:eval(), returns { id, count, elapsed, items[] }
  • GET /api/query/{id}/results?start=N&count=M — paginated JSON result retrieval

Key Differences & Concerns

Aspect session.xq (current) query.xqm (API)
Execution XQueryServlet (full context) util:eval()
Error handling XQueryServlet <error> elements, including null-description edge case try/catch with structured JSON errors
Result rendering Server-side HTML (<div> with badges, match highlights) Client-side rendering from JSON strings
Match highlights util:expand($item, "highlight-matches=both") Not yet implemented
Serialization modes html5, xhtml, xhtml5, json, text, xml, adaptive, microxml — non-XML modes bypass session and render directly in iframe All modes serialize to JSON string items
Module load path Set via xquery.module-load-path request attribute in controller Passed as base parameter to util:eval()

Questions

  1. XQueryServlet vs util:eval() — Are there meaningful behavioral differences? XQueryServlet sets up a full execution context via the URL rewrite chain. Does util:eval() with a base parameter provide equivalent module resolution?

  2. Match highlightingutil:expand() with highlight-matches=both is used in session.xq for full-text search result highlighting. Should this be added to query.xqm, or handled client-side?

  3. Non-XML serialization modes — Currently, non-standard output modes (html5, xhtml, etc.) bypass the session entirely and render raw output in an iframe. The API approach serializes everything to JSON strings. Is there a use case where raw iframe rendering is important?

  4. Migration scope — Moving to the API requires rewriting the frontend result rendering (currently receives HTML, would need to build DOM from JSON). Is this worth doing now, or should session.xq remain as-is until a larger editor refactor?

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions