Skip to content

Run the import-ontology transform client-side; delete the /transform endpoint - #344

Open
namedgraph wants to merge 2 commits into
developfrom
ft-client-transform-comunica
Open

Run the import-ontology transform client-side; delete the /transform endpoint#344
namedgraph wants to merge 2 commits into
developfrom
ft-client-transform-comunica

Conversation

@namedgraph

Copy link
Copy Markdown
Member

Summary

Moves the "Import ontology" CONSTRUCT transform off the server on both the browser and CLI paths, so the /transform endpoint is deleted. This removes the last bespoke server-side fetch/SSRF surface (pen-test LNK-002) after /add and /generate were moved client-side, and completes the "until a client-side SPARQL engine lands" caveat from the graph-writes work.

Changes

Browser — client-orchestrated transform

The import-ontology submit handler (modal.xsl) now mirrors the add/clone flow, with an in-browser CONSTRUCT inserted:

add/clone:        GET source (?uri= proxy) ─────────────────────────→ POST target → navigate
import-ontology:  fetch query sp:text → Comunica CONSTRUCT(proxied source) → POST target → navigate
  • Fetches the construct-constructors query, extracts sp:text, runs it in-browser over the ?uri=-proxied dct:source, and GSP-appends the Turtle result to the local sd:name target.
  • New callbacks ldh:transform-query-response / ldh:transform-construct-response parallel ldh:add-data-source-response.
  • The cross-origin-target locality guard from the add/clone variant is carried over.

Client-side SPARQL engine (bundled, lazy)

  • Vendors comunica-browser.js (Comunica, prebuilt browser bundle) alongside three.min.js etc.
  • Thin wrapper SPARQLTransform.js exposes LinkedDataHub.construct(engineSrc, sourceURL, queryString) → Promise<Turtle> and lazily loads the 2.2 MB engine bundle on first use — nothing heavy loads on ordinary pages. Loaded in the $load-sparql-builder block.

CLI — symmetric local transform

  • bin/admin/ontologies/import-ontology.sh no longer POSTs to /transform. It fetches the query, runs the CONSTRUCT locally via Jena arq, and POSTs the result to the target graph. (Requires arq + perl on $PATH.)

Removals

  • Transform.java, its Dispatcher locator, and the 4 /transform HTTP tests.
  • The now-unreachable generic form-clone-data RDF/POST submit template (its only caller was the transform variant's xsl:next-match).

⚠️ Verification status

Implemented but not yet exercised in a browser/stack (no runtime in the authoring environment). Confirmed here: both stylesheets XML-well-formed, CLI passes bash -n, no lingering Transform refs, Java change is a trivial locator+import removal. Needs in-browser confirmation of:

  • The ixsl:call(...) => ixsl:then(...) bridge — awaiting a plain JS-library promise from Saxon-JS. Documented contract, but no precedent in this codebase.
  • Comunica browser API shape (engine.query()resultToString(result, 'text/turtle') → stream read); the wrapper has an async-iterable fallback but verify.
  • mvn -Pstandalone clean package (SEF compile) and a live Import ontology run (e.g. SKOS).

🤖 Generated with Claude Code

namedgraph and others added 2 commits August 10, 2026 08:33
…endpoint

Move the "Import ontology" CONSTRUCT transform off the server, removing the last
bespoke server-side fetch/SSRF surface (pen-test LNK-002) after /add and /generate.

- Browser: the import-ontology submit handler fetches the construct-constructors
  query (sp:text), runs it in-browser over the ?uri=-proxied dct:source via a bundled
  SPARQL engine (Comunica, lazily loaded on first use), and GSP-appends the Turtle
  result to the local sd:name target -- structurally identical to the add/clone flow
  (ldh:transform-query-response / ldh:transform-construct-response).
- CLI: import-ontology.sh no longer POSTs to /transform; it fetches the query,
  transforms the source locally with Jena arq, and POSTs the result to the graph.
- Delete Transform.java, its Dispatcher locator, and the /transform HTTP tests.
- Remove the now-unreachable generic form-clone-data RDF/POST submit template (its
  only caller was the transform variant's xsl:next-match).

Bundle SPARQLTransform.js (thin wrapper) + comunica-browser.js (engine), loaded in
the $load-sparql-builder block. CHANGELOG updated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
import-ontology.sh pulls sp:text with a `sparql` SELECT over the fetched query
document, emitted as SPARQL Results XML and read with `xmllint --xpath string(//literal)`
to recover the exact multi-line query -- the XML parser decodes entities and preserves
newlines, so no serialization regex or manual unescaping. Both the extraction and the
transform run through `sparql`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant