@@ -34,11 +34,12 @@ function getNeededInfoFromYarrrmlFile(yarrrmlFile) {
3434 * Gets all auth fetch functions (and the tokens used to create them)
3535 *
3636 * @param {Object } yarrrmlInfo key: webId; value: object: relevant properties per webId from YARRRML file
37- * @returns {Array } [0]: key: webID, value: token; [1]: key: webId, value: fetch function
37+ * @returns {Array } [0]: key: webID, value: token; [1]: key: webId, value: fetch function; [2]: key: webId, value: fetch function for Comunica
3838 */
3939async function getAllAuthFetchFunctions ( yarrrmlInfo ) {
4040 const tokens = { } ;
4141 const authFetchFunctions = { } ;
42+ const authFetchFunctionsForComunica = { } ;
4243 console . log ( 'Getting authenticated fetch functions.' ) ;
4344 for ( const infoObject of Object . values ( yarrrmlInfo ) ) {
4445 console . log ( ` Getting authenticated fetch function for ${ infoObject . webId } .` ) ;
@@ -47,21 +48,32 @@ async function getAllAuthFetchFunctions(yarrrmlInfo) {
4748 infoObject . password ,
4849 infoObject . oidcIssuer ,
4950 infoObject . webId ) ;
50- authFetchFunctions [ infoObject . webId ] = await getAuthenticatedFetch (
51+ const authFetchFunction = await getAuthenticatedFetch (
5152 tokens [ infoObject . webId ] ,
5253 infoObject . oidcIssuer ) ;
54+ // next function to present work around jsonld files for Comunica
55+ const authFetchFunctionForComunica = async ( arg ) => {
56+ const response = await authFetchFunction ( arg , {
57+ headers : {
58+ Accept : "application/n-quads,application/trig;q=0.9,text/turtle;q=0.8,application/n-triples;q=0.7,*/*;q=0.1"
59+ }
60+ } ) ;
61+ return response ;
62+ } ;
63+ authFetchFunctions [ infoObject . webId ] = authFetchFunction ;
64+ authFetchFunctionsForComunica [ infoObject . webId ] = authFetchFunctionForComunica ;
5365 }
54- return [ tokens , authFetchFunctions ] ;
66+ return [ tokens , authFetchFunctions , authFetchFunctionsForComunica ] ;
5567}
5668
5769/**
5870 * Gets all data sources
5971 *
6072 * @param {Object } yarrrmlInfo key: webId; value: object: relevant properties per webId from YARRRML file
61- * @param {Object } authFetchFunctions key: webId, value: fetch function
73+ * @param {Object } authFetchFunctionsForComunica key: webId, value: fetch function for Comunica
6274 * @returns {Object } key: webId, value: array of data sources
6375 */
64- async function getAllDataSources ( yarrrmlInfo , authFetchFunctions ) {
76+ async function getAllDataSources ( yarrrmlInfo , authFetchFunctionsForComunica ) {
6577 const defaultIndexQuery = `
6678PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
6779
@@ -76,20 +88,22 @@ WHERE {
7688 console . log ( ` Getting data sources for ${ infoObject . webId } .` ) ;
7789 const indexQuery = infoObject . indexQuery || defaultIndexQuery ;
7890 const context = {
79- fetch : authFetchFunctions [ infoObject . webId ] ,
91+ fetch : authFetchFunctionsForComunica [ infoObject . webId ] ,
8092 // start at the index in first iteration
8193 sources : [ infoObject . index ] ,
8294 lenient : true
8395 }
8496 let allSources = [ infoObject . index ] ;
8597 let newSources = [ ] ;
98+ let levelCountDown = 1 ;
8699 newEngine ( ) ;
87100 do {
88101 newSources = await queryTermsNotVariables ( indexQuery , context ) ;
89102 allSources = [ ...allSources , ...newSources ] ;
90103 // dig deeper in next iteration
91104 context . sources = newSources ;
92- } while ( newSources . length > 0 )
105+ levelCountDown -- ;
106+ } while ( levelCountDown > 0 && newSources . length > 0 )
93107 dataSources [ infoObject . webId ] = Array . from ( new Set ( allSources ) ) ;
94108 }
95109 return dataSources ;
@@ -138,7 +152,7 @@ async function prepareAllPods(status, authFetchFunctions) {
138152 * @param {String } webId the webId
139153 * @returns {Boolean }
140154 */
141- async function ownedBy ( resourceUrl , webId ) {
155+ async function isOwnedBy ( resourceUrl , webId ) {
142156 const podQuery = `
143157PREFIX pim: <http://www.w3.org/ns/pim/space#>
144158
@@ -148,13 +162,13 @@ WHERE {
148162}
149163` ;
150164 const pods = await queryTermsNotVariables ( podQuery , { sources : [ webId ] } ) ;
151- let owned = pods . some ( ( pod ) => resourceUrl . startsWith ( pod ) ) ;
152- if ( ! owned ) {
165+ let isOwned = pods . some ( ( pod ) => resourceUrl . startsWith ( pod ) ) ;
166+ if ( ! isOwned ) {
153167 // fallback for the case of no pim:storage predicate
154168 const pod = webId . substring ( 0 , webId . lastIndexOf ( 'profile/card' ) ) ;
155- owned = resourceUrl . startsWith ( pod ) ;
169+ isOwned = resourceUrl . startsWith ( pod ) ;
156170 }
157- return owned ;
171+ return isOwned ;
158172}
159173
160174/**
@@ -226,7 +240,7 @@ async function addAllVerifiableCredentials(status, authFetchFunctions) {
226240 const webId = infoObject . webId ;
227241 console . log ( ` Adding verifiable credentials for ${ webId } .` ) ;
228242 for ( const resourceUrl of status . newDataSources [ webId ] ) {
229- if ( await ownedBy ( resourceUrl , webId ) ) {
243+ if ( await isOwnedBy ( resourceUrl , webId ) ) {
230244 try {
231245 const [ contentTypeIn , text ] = await getResourceText ( resourceUrl , authFetchFunctions [ webId ] ) ;
232246 //console.log(`Read resource ${resourceUrl}; contentType: ${contentTypeIn}; text: ${text}.`);
@@ -260,7 +274,7 @@ async function verifyAllVerifiableCredentials(status, authFetchFunctions) {
260274 const webId = infoObject . webId ;
261275 console . log ( ` Verifying verifiable credentials for ${ webId } .` ) ;
262276 for ( const resourceUrl of status . newDataSources [ webId ] ) {
263- if ( await ownedBy ( resourceUrl , webId ) ) {
277+ if ( await isOwnedBy ( resourceUrl , webId ) ) {
264278 const [ contentTypeIn , text ] = await getResourceText ( resourceUrl , authFetchFunctions [ webId ] ) ;
265279 //console.log(`Read resource ${resourceUrl}; contentType: ${contentTypeIn}; text: ${text}.`);
266280 const res = await verifyVC ( text ) ;
@@ -295,7 +309,7 @@ async function deleteAllObsoleteDataSources(status, authFetchFunctions) {
295309 const newDataSources = status . newDataSources [ webId ] ;
296310 for ( const resourceUrl of originalDataSources ) {
297311 if ( ! newDataSources . includes ( resourceUrl ) ) {
298- if ( await ownedBy ( resourceUrl , webId ) ) {
312+ if ( await isOwnedBy ( resourceUrl , webId ) ) {
299313 try {
300314 await deleteResource ( resourceUrl , authFetchFunctions [ webId ] ) ;
301315 console . log ( ` Deleted resource ${ resourceUrl } .` ) ;
@@ -316,8 +330,8 @@ async function deleteAllObsoleteDataSources(status, authFetchFunctions) {
316330 */
317331export async function step1 ( yarrrmlFile , statusFile ) {
318332 const yarrrmlInfo = getNeededInfoFromYarrrmlFile ( yarrrmlFile ) ;
319- const [ tokens , authFetchFunctions ] = await getAllAuthFetchFunctions ( yarrrmlInfo ) ;
320- const originalDataSources = await getAllDataSources ( yarrrmlInfo , authFetchFunctions ) ;
333+ const [ tokens , authFetchFunctions , authFetchFunctionsForComunica ] = await getAllAuthFetchFunctions ( yarrrmlInfo ) ;
334+ const originalDataSources = await getAllDataSources ( yarrrmlInfo , authFetchFunctionsForComunica ) ;
321335 const status = {
322336 yarrrmlInfo : yarrrmlInfo ,
323337 originalDataSources : originalDataSources
@@ -337,8 +351,8 @@ export async function step1(yarrrmlFile, statusFile) {
337351export async function step2 ( statusFile , writeVCs , verifyVCs ) {
338352 const status = JSON . parse ( fs . readFileSync ( statusFile ) ) ;
339353 const yarrrmlInfo = status . yarrrmlInfo ;
340- const [ tokens , authFetchFunctions ] = await getAllAuthFetchFunctions ( yarrrmlInfo ) ;
341- const newDataSources = await getAllDataSources ( yarrrmlInfo , authFetchFunctions ) ;
354+ const [ tokens , authFetchFunctions , authFetchFunctionsForComunica ] = await getAllAuthFetchFunctions ( yarrrmlInfo ) ;
355+ const newDataSources = await getAllDataSources ( yarrrmlInfo , authFetchFunctionsForComunica ) ;
342356 status . newDataSources = newDataSources ;
343357 fs . writeFileSync ( statusFile , JSON . stringify ( status , null , 2 ) ) ;
344358 if ( writeVCs ) {
0 commit comments