Skip to content

Commit 37f635a

Browse files
build, lint, prettier
1 parent 81e3ee4 commit 37f635a

2 files changed

Lines changed: 79 additions & 51 deletions

File tree

movies/vanilla/src/example.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@ import { fetchList, Interpretation } from './main.js';
55
let authenticatedFetch: Awaited<ReturnType<typeof v7.getAuthenticatedFetch>>;
66

77
try {
8-
authenticatedFetch = await v7.getAuthenticatedFetch({
9-
email: process.env.SOLID_EMAIL,
10-
password: process.env.SOLID_PASSWORD,
11-
provider: process.env.SOLID_SERVER,
12-
});
13-
} catch(e) {
14-
console.log('Could not connect to your pod');
8+
authenticatedFetch = await v7.getAuthenticatedFetch({
9+
email: process.env.SOLID_EMAIL,
10+
password: process.env.SOLID_PASSWORD,
11+
provider: process.env.SOLID_SERVER,
12+
});
13+
} catch (e) {
14+
console.error('Could not connect to your pod', e);
1515
}
1616

1717
let interpretation: Interpretation;
1818
try {
19-
20-
const listUrl = 'https://michielbdejong.solidcommunity.net/movies/';
21-
interpretation = await fetchList(listUrl, authenticatedFetch);
22-
} catch(e) {
23-
console.error('Could not fetch your movies folder');
19+
const listUrl = 'https://michielbdejong.solidcommunity.net/movies/';
20+
interpretation = await fetchList(listUrl, authenticatedFetch);
21+
} catch (e) {
22+
console.error('Could not fetch your movies folder', e);
2423
}
25-
interpretation.listings.forEach(listing => console.log(listing));
26-
interpretation.watchActions.forEach(watchAction => console.log(watchAction));
27-
24+
interpretation.listings.forEach((listing) => console.log(listing));
25+
interpretation.watchActions.forEach((watchAction) => console.log(watchAction));

movies/vanilla/src/movies.ts

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { getJsonLdDateField, getJsonLdLinkField, getJsonLdStringField } from './jsonld.js';
1+
import {
2+
getJsonLdDateField,
3+
getJsonLdLinkField,
4+
getJsonLdStringField,
5+
} from './jsonld.js';
26

37
export type Listing = {
48
created: Date;
@@ -9,22 +13,24 @@ export type Listing = {
913
image: string;
1014
name: string;
1115
sameAs: string[];
12-
}
13-
}
16+
};
17+
};
1418
export type WatchAction = {
1519
created: Date;
1620
startTime: Date;
1721
endTime: Date;
1822
listingUr: string;
19-
}
23+
};
2024

2125
export type Interpretation = {
2226
listings: Listing[];
2327
watchActions: WatchAction[];
24-
}
28+
};
2529

26-
async function getJsonLd(uri: string,
27-
authenticatedFetcher: typeof globalThis.fetch): Promise<object[]> {
30+
async function getJsonLd(
31+
uri: string,
32+
authenticatedFetcher: typeof globalThis.fetch,
33+
): Promise<object[]> {
2834
const res = await authenticatedFetcher(uri, {
2935
headers: {
3036
Accept: 'application/ld+json',
@@ -43,35 +49,59 @@ export async function fetchList(
4349
watchActions: [],
4450
};
4551

46-
await Promise.all(index.map(async (entry: object) => {
47-
if (entry['@id'] === folderUri) {
48-
return;
49-
}
50-
const listing = await getJsonLd(entry['@id'], aFetch);
51-
listing.forEach(thing => {
52-
if (thing['@type'].indexOf('https://schema.org/Movie') !== -1) {
53-
ret.listings.push({
54-
created: getJsonLdDateField(thing, 'http://purl.org/dc/terms/created'),
55-
modified: getJsonLdDateField(thing, 'http://purl.org/dc/terms/modified'),
56-
movie: {
57-
published: getJsonLdDateField(thing, 'https://schema.org/datePublished'),
58-
description: getJsonLdStringField(thing, 'https://schema.org/description'),
59-
image: getJsonLdStringField(thing, 'https://schema.org/image'), // sic: string instead of link here
60-
name: getJsonLdStringField(thing, 'https://schema.org/name'),
61-
sameAs: thing['https://schema.org/sameAs'].map(x => x['@value']) as string[], // sic: string instead of link here
62-
}
63-
});
64-
} else if (thing['@type'].indexOf('https://schema.org/WatchAction') !== -1) {
65-
ret.watchActions.push({
66-
created: getJsonLdDateField(thing, 'http://purl.org/dc/terms/created'),
67-
startTime: getJsonLdDateField(thing, 'https://schema.org/startTime'),
68-
endTime: getJsonLdDateField(thing, 'https://schema.org/endTime'),
69-
listingId: getJsonLdLinkField(thing, 'https://schema.org/object'),
70-
});
71-
} else {
72-
console.log('thing type not recognised', thing);
52+
await Promise.all(
53+
index.map(async (entry: object) => {
54+
if (entry['@id'] === folderUri) {
55+
return;
7356
}
74-
})
75-
}));
57+
const listing = await getJsonLd(entry['@id'], aFetch);
58+
listing.forEach((thing) => {
59+
if (thing['@type'].indexOf('https://schema.org/Movie') !== -1) {
60+
ret.listings.push({
61+
created: getJsonLdDateField(
62+
thing,
63+
'http://purl.org/dc/terms/created',
64+
),
65+
modified: getJsonLdDateField(
66+
thing,
67+
'http://purl.org/dc/terms/modified',
68+
),
69+
movie: {
70+
published: getJsonLdDateField(
71+
thing,
72+
'https://schema.org/datePublished',
73+
),
74+
description: getJsonLdStringField(
75+
thing,
76+
'https://schema.org/description',
77+
),
78+
image: getJsonLdStringField(thing, 'https://schema.org/image'), // sic: string instead of link here
79+
name: getJsonLdStringField(thing, 'https://schema.org/name'),
80+
sameAs: thing['https://schema.org/sameAs'].map(
81+
(x) => x['@value'],
82+
) as string[], // sic: string instead of link here
83+
},
84+
});
85+
} else if (
86+
thing['@type'].indexOf('https://schema.org/WatchAction') !== -1
87+
) {
88+
ret.watchActions.push({
89+
created: getJsonLdDateField(
90+
thing,
91+
'http://purl.org/dc/terms/created',
92+
),
93+
startTime: getJsonLdDateField(
94+
thing,
95+
'https://schema.org/startTime',
96+
),
97+
endTime: getJsonLdDateField(thing, 'https://schema.org/endTime'),
98+
listingId: getJsonLdLinkField(thing, 'https://schema.org/object'),
99+
});
100+
} else {
101+
console.log('thing type not recognised', thing);
102+
}
103+
});
104+
}),
105+
);
76106
return ret;
77107
}

0 commit comments

Comments
 (0)