Skip to content

Commit 269d2e2

Browse files
fetch from container and tracker
1 parent 4aa3723 commit 269d2e2

3 files changed

Lines changed: 52 additions & 18 deletions

File tree

tasks/vanilla/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solid-data-module-tasks",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Solid Data Module for tasks and issue tracking",
55
"type": "module",
66
"engines": {

tasks/vanilla/src/example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import 'dotenv/config';
22
import { v7 } from 'css-authn';
3-
import { fetchContainer } from 'solid-data-module-tasks';
3+
import { fetchContainerAndTracker } from 'solid-data-module-tasks';
44

55
const authenticatedFetch = await v7.getAuthenticatedFetch({
66
email: process.env.SOLID_EMAIL,
77
password: process.env.SOLID_PASSWORD,
88
provider: process.env.SOLID_SERVER,
99
});
1010
const containerUrl = 'https://michielbdejong.solidcommunity.net/tasks/';
11-
const output = await fetchContainer(containerUrl, authenticatedFetch);
11+
const output = await fetchContainerAndTracker(containerUrl, authenticatedFetch);
1212
console.log(output);

tasks/vanilla/src/tasks.ts

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ export type InterpretedComment = {
9696

9797
export 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

117117
export 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

277311
export async function addIssue(

0 commit comments

Comments
 (0)