@@ -10,8 +10,8 @@ import { isUri } from 'valid-url'
1010const literalValueRegex = / ^ " (?< value > .+ ) " ( @ | \^ \^ ) ? ( (?< = @ ) (?< language > .* ) ) ? ( (?< = \^ \^ ) (?< datatype > .* ) ) ? $ /
1111const TRUE = $rdf . literal ( 'true' , xsd . boolean )
1212
13- function createTermFromVariable ( { template , value } : { template : GraphPointer ; value : string } ) {
14- if ( ! hydra . ExplicitRepresentation . equals ( template . out ( hydra . variableRepresentation ) . term ) ) {
13+ function createTermFromVariable ( { variableRepresentation , value } : { variableRepresentation : Term | undefined ; value : string } ) {
14+ if ( ! hydra . ExplicitRepresentation . equals ( variableRepresentation ) ) {
1515 return value
1616 }
1717
@@ -30,19 +30,21 @@ function createTermFromVariable({ template, value }: {template: GraphPointer; va
3030
3131export function toPointer ( template : GraphPointer , queryParams : ParsedQs ) : GraphPointer < BlankNode , DatasetExt > {
3232 const templateParams = clownface ( { dataset : $rdf . dataset ( ) } ) . blankNode ( )
33+ const templateVariableRepresentation = template . out ( hydra . variableRepresentation ) . term
3334
34- const variablePropertyMap = new Map < string , Term > ( )
35+ const variablePropertyMap = new Map < string , { property : Term ; variableRepresentation : Term | undefined } > ( )
3536 template . out ( hydra . mapping ) . forEach ( mapping => {
3637 const variable = mapping . out ( hydra . variable ) . value
3738 const property = mapping . out ( hydra . property ) . term
3839 const required = mapping . out ( hydra . required ) . term ?. equals ( TRUE )
40+ const variableRepresentation = mapping . out ( hydra . variableRepresentation ) . term
3941
4042 if ( variable && required && ! queryParams [ variable ] ) {
4143 throw new httpError . BadRequest ( `Missing required template variable ${ variable } ` )
4244 }
4345
4446 if ( variable && property ) {
45- variablePropertyMap . set ( variable , property )
47+ variablePropertyMap . set ( variable , { property, variableRepresentation } )
4648 }
4749 } )
4850
@@ -53,14 +55,18 @@ export function toPointer(template: GraphPointer, queryParams: ParsedQs): GraphP
5355 ? param . map ( ( item : any ) => item . toString ( ) )
5456 : [ ]
5557
56- const property = variablePropertyMap . get ( key )
58+ const mapping = variablePropertyMap . get ( key )
5759
58- if ( ! property ) {
60+ if ( ! mapping ) {
5961 return
6062 }
6163
62- const terms = values . map ( value => createTermFromVariable ( { template, value } ) )
63- templateParams . addOut ( property , terms )
64+ const variableRepresentation = mapping . variableRepresentation || templateVariableRepresentation
65+ const terms = values . map ( value => createTermFromVariable ( {
66+ variableRepresentation,
67+ value,
68+ } ) )
69+ templateParams . addOut ( mapping . property , terms )
6470 } )
6571
6672 return templateParams
0 commit comments