Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,15 @@ exclude-result-prefixes="#all"
<xsl:function name="ldh:load-object-metadata" as="map(*)" ixsl:updating="yes">
<xsl:param name="context" as="map(*)"/>
<xsl:param name="response-key" as="xs:string"/>
<xsl:variable name="response" select="$context($response-key)" as="map(*)"/>
<xsl:variable name="endpoint" select="$context('endpoint')" as="xs:anyURI"/>
<!-- prefer caller-supplied object-uris in context (form flows compute these from $resource or $body upstream); fall back to extracting from the named response (block flows) -->
<xsl:variable name="object-uris" as="xs:string*" select="
if ($response?status = 200 and $response?media-type = 'application/rdf+xml')
then distinct-values($response?body/rdf:RDF/rdf:Description/*/@rdf:resource[not(key('resources', .))])
else ()"/>
if (map:contains($context, 'object-uris')) then $context('object-uris')
else
let $response := $context($response-key)
return if ($response?status = 200 and $response?media-type = 'application/rdf+xml')
then distinct-values($response?body/rdf:RDF/rdf:Description/*/@rdf:resource[not(key('resources', .))])
else ()"/>
<xsl:variable name="query-string" select="$object-metadata-query || ' VALUES $this { ' || string-join(for $uri in $object-uris return '&lt;' || $uri || '&gt;', ' ') || ' }'" as="xs:string"/>
<xsl:variable name="request" select="map{ 'method': 'POST', 'href': ldh:href($endpoint), 'media-type': 'application/sparql-query', 'body': $query-string, 'headers': map{ 'Accept': 'application/rdf+xml' } }" as="map(*)"/>

Expand Down Expand Up @@ -704,11 +707,14 @@ exclude-result-prefixes="#all"
<xsl:function name="ldh:load-property-metadata" as="map(*)" ixsl:updating="yes">
<xsl:param name="context" as="map(*)"/>
<xsl:param name="response-key" as="xs:string"/>
<xsl:variable name="response" select="$context($response-key)" as="map(*)"/>
<!-- prefer caller-supplied property-uris in context (form flows compute these from $resource or $body upstream); fall back to extracting from the named response (block flows) -->
<xsl:variable name="property-uris" as="xs:string*" select="
if ($response?status = 200 and $response?media-type = 'application/rdf+xml')
then distinct-values($response?body/rdf:RDF/rdf:Description/*/concat(namespace-uri(), local-name()))
else ()"/>
if (map:contains($context, 'property-uris')) then $context('property-uris')
else
let $response := $context($response-key)
return if ($response?status = 200 and $response?media-type = 'application/rdf+xml')
then distinct-values($response?body/rdf:RDF/rdf:Description/*/concat(namespace-uri(), local-name()))
else ()"/>
<xsl:variable name="query-string" select="$property-metadata-query || ' VALUES $Type { ' || string-join(for $uri in $property-uris return '&lt;' || $uri || '&gt;', ' ') || ' }'" as="xs:string"/>
<xsl:variable name="request" select="map{ 'method': 'POST', 'href': ldh:href(resolve-uri('ns', ldt:base())), 'media-type': 'application/sparql-query', 'body': $query-string, 'headers': map{ 'Accept': 'application/rdf+xml' } }" as="map(*)"/>

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,52 @@ exclude-result-prefixes="#all"
</xsl:for-each>
</xsl:function>

<!-- Parallel load/set pair runner. $pairs is a single array whose members are 4-element arrays [load-fn, request-key, response-key, set-fn]; load-fn is a pure context-transformer that populates context($request-key). The helper folds every load-fn over $context (collecting all request specs), fans out one http-request → rethread → handle → set per pair via ixsl:all, then merges all per-branch contexts back into one. ixsl:all is fail-fast — first rejected branch propagates through on-failure of the enclosing chain. -->
<xsl:function name="ldh:fire-load-set-parallel" as="item()*" ixsl:updating="yes">
<xsl:param name="context" as="map(*)"/>
<xsl:param name="pairs" as="array(*)"/>

<xsl:variable name="ctx-with-requests" as="map(*)" select="
array:fold-left($pairs, $context, function($ctx as item()*, $pair as item()*) as item()* { $pair?1($ctx) })
"/>

<xsl:variable name="promises" as="array(*)" select="
array {
for $pair in $pairs?* return
ixsl:http-request($ctx-with-requests($pair?2))
=> ixsl:then(ldh:rethread-response($ctx-with-requests, ?, $pair?3))
=> ixsl:then(ldh:handle-response(?, $pair?3))
=> ixsl:then($pair?4)
}
"/>

<xsl:sequence select="
ixsl:all($promises)
=> ixsl:then(function($results as item()*) as item()* {
array:fold-left($results, $ctx-with-requests, function($acc as item()*, $r as item()*) as item()* {
map:merge(($acc, $r), map{ 'duplicates': 'use-last' })
})
})
"/>
</xsl:function>

<!-- Promise-chain cleanup callback for ixsl:finally — resets the body cursor. ixsl:finally requires a 0-arg handler and ignores its return value (the original promise outcome flows through to on-failure / on-completion). Idempotent with ldh:promise-failure's own cursor reset, so chains that use both don't conflict. -->
<xsl:function name="ldh:reset-cursor" ixsl:updating="yes">
<ixsl:set-style name="cursor" select="'default'" object="ixsl:page()//body"/>
</xsl:function>

<!-- Composes the seed shape shared by chains whose initial GET is against the edited resource: http-request → rethread → handle → load-edited-resource. After this resolves, context has types/property-uris/object-uris populated and a GET-style type-metadata-request pre-baked, so downstream parallel pairs should use an identity load-fn for type-metadata (otherwise ldh:load-type-metadata would overwrite the request with its POST variant). -->
<xsl:function name="ldh:fetch-and-load-edited-resource" as="item()*" ixsl:updating="yes">
<xsl:param name="context" as="map(*)"/>

<xsl:sequence select="
ixsl:http-request($context('request'))
=> ixsl:then(ldh:rethread-response($context, ?))
=> ixsl:then(ldh:handle-response#1)
=> ixsl:then(ldh:load-edited-resource#1)
"/>
</xsl:function>

<xsl:function name="ldh:promise-failure" ixsl:updating="yes">
<xsl:param name="error" as="map(*)"/>

Expand Down
Loading
Loading