@@ -96,11 +96,11 @@ export type InterpretedComment = {
9696
9797export type InterpretedIssue = {
9898 uri : string ;
99- author : string ;
100- title : string ;
101- created : Date ;
99+ author ? : string ;
100+ title ? : string ;
101+ created ? : Date ;
102102 description : string ;
103- trackerIndexUri : string ;
103+ trackerIndexUri ? : string ;
104104 commentUris : string [ ] ;
105105} ;
106106
@@ -115,7 +115,7 @@ export type InterpretedTracker = {
115115} ;
116116
117117export type Interpretation = {
118- tracker : InterpretedTracker ;
118+ tracker ? : InterpretedTracker ;
119119 issues : {
120120 [ uri : string ] : InterpretedIssue ;
121121 } ;
@@ -240,16 +240,23 @@ function interpret({
240240 return ret ;
241241}
242242
243- export async function fetchTracker (
243+ async function getJsonLd (
244244 uri : string ,
245245 authenticatedFetcher : typeof globalThis . fetch ,
246- ) : Promise < Interpretation > {
247- const indexRet = await authenticatedFetcher ( uri , {
246+ ) : Promise < object [ ] > {
247+ const res = await authenticatedFetcher ( uri , {
248248 headers : {
249249 Accept : 'application/ld+json' ,
250250 } ,
251251 } ) ;
252- const index : TrackerIndex = await indexRet . json ( ) ;
252+ return res . json ( ) ;
253+ }
254+
255+ export async function fetchTracker (
256+ uri : string ,
257+ authenticatedFetcher : typeof globalThis . fetch ,
258+ ) : Promise < Interpretation > {
259+ const index = await getJsonLd ( uri , authenticatedFetcher ) as TrackerIndex ;
253260 const stateDocUri =
254261 index [ 0 ] [ 'http://www.w3.org/2005/01/wf/flow#stateStore' ] [ 0 ] [ '@id' ] ;
255262 const stateRet = await authenticatedFetcher ( stateDocUri , {
@@ -265,13 +272,40 @@ export async function fetchContainer(
265272 uri : string ,
266273 authenticatedFetcher : typeof globalThis . fetch ,
267274) : Promise < Interpretation > {
268- const indexRet = await authenticatedFetcher ( uri , {
269- headers : {
270- Accept : 'application/ld+json' ,
271- } ,
275+ const jsonld = await getJsonLd ( uri , authenticatedFetcher ) ;
276+ const docs = jsonld . map ( entry => entry [ '@id' ] ) ;
277+ const ret : Interpretation = {
278+ issues : { } ,
279+ } ;
280+ await Promise . all ( docs . map ( async docUri => {
281+ if ( ( docUri === uri ) || ( docUri === `${ uri } index.ttl` ) || ( docUri === `${ uri } state.ttl` ) ) {
282+ return ;
283+ }
284+ const docContents = await getJsonLd ( docUri , authenticatedFetcher ) ;
285+ docContents . forEach ( thing => {
286+ const uri = getJsonLdId ( thing ) ;
287+ if ( typeof uri === 'string' && getJsonLdType ( thing ) === 'https://schema.org/Action' ) {
288+ ret . issues [ uri ] = {
289+ uri,
290+ description : getJsonLdStringField ( thing , 'https://schema.org/description' ) ,
291+ commentUris : [ ] ,
292+ } ;
293+ }
294+ } )
295+ } ) ) ;
296+ return ret ;
297+ }
298+
299+ export async function fetchContainerAndTracker (
300+ uri : string ,
301+ authenticatedFetcher : typeof globalThis . fetch ,
302+ ) : Promise < Interpretation > {
303+ const ret = await fetchTracker ( `${ uri } index.ttl#this` , authenticatedFetcher ) ;
304+ const fromContainer = await fetchContainer ( uri , authenticatedFetcher ) ;
305+ Object . keys ( fromContainer . issues ) . forEach ( key => {
306+ ret . issues [ key ] = fromContainer . issues [ key ] ;
272307 } ) ;
273- const docs = await indexRet . json ( ) ;
274- return docs ;
308+ return ret ;
275309}
276310
277311export async function addIssue (
0 commit comments