Skip to content

Commit b06d5fd

Browse files
Simplify JSON-LD format: no @graph, single subject with schema:mainEntityOfPage
1 parent e864607 commit b06d5fd

2 files changed

Lines changed: 31 additions & 23 deletions

File tree

src/rdf/turtle.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,41 @@ function quadsToJsonLd(quads, baseUri, prefixes = {}) {
151151
nodes.push(jsonNode);
152152
}
153153

154-
// Build result
154+
// Build result - return array if multiple nodes, single object otherwise
155155
const context = buildContext(prefixes);
156156

157157
if (nodes.length === 1) {
158158
return { '@context': context, ...nodes[0] };
159159
}
160160

161-
return { '@context': context, '@graph': nodes };
161+
// Multiple nodes: return as array (no @graph)
162+
return nodes.map((node, i) => i === 0 ? { '@context': context, ...node } : node);
162163
}
163164

164165
/**
165166
* Convert JSON-LD to N3.js quads
166167
*/
167168
function jsonLdToQuads(jsonLd, baseUri) {
168169
const quads = [];
169-
const context = jsonLd['@context'] || {};
170170

171-
// Handle @graph or single object
172-
const nodes = jsonLd['@graph'] || [jsonLd];
171+
// Handle array of JSON-LD objects (e.g., from multiple PATCH operations)
172+
const documents = Array.isArray(jsonLd) ? jsonLd : [jsonLd];
173+
174+
// Merge all contexts and collect all nodes
175+
let mergedContext = {};
176+
let nodes = [];
177+
178+
for (const doc of documents) {
179+
if (doc['@context']) {
180+
mergedContext = { ...mergedContext, ...doc['@context'] };
181+
}
182+
// Each document with @id is a node (no @graph needed)
183+
if (doc['@id']) {
184+
nodes.push(doc);
185+
}
186+
}
187+
188+
const context = mergedContext;
173189

174190
for (const node of nodes) {
175191
if (!node['@id']) continue;

src/webid/profile.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,17 @@ export function generateProfileJsonLd({ webId, name, podUri, issuer }) {
3333
'inbox': { '@id': 'ldp:inbox', '@type': '@id' },
3434
'storage': { '@id': 'pim:storage', '@type': '@id' },
3535
'oidcIssuer': { '@id': 'solid:oidcIssuer', '@type': '@id' },
36-
'preferencesFile': { '@id': 'pim:preferencesFile', '@type': '@id' }
36+
'preferencesFile': { '@id': 'pim:preferencesFile', '@type': '@id' },
37+
'mainEntityOfPage': { '@id': 'schema:mainEntityOfPage', '@type': '@id' }
3738
},
38-
'@graph': [
39-
{
40-
'@id': profileDoc,
41-
'@type': 'foaf:PersonalProfileDocument',
42-
'foaf:maker': { '@id': webId },
43-
'foaf:primaryTopic': { '@id': webId }
44-
},
45-
{
46-
'@id': webId,
47-
'@type': ['foaf:Person', 'schema:Person'],
48-
'foaf:name': name,
49-
'inbox': `${pod}inbox/`,
50-
'storage': pod,
51-
'oidcIssuer': issuer,
52-
'preferencesFile': `${pod}settings/prefs`
53-
}
54-
]
39+
'@id': webId,
40+
'@type': ['foaf:Person', 'schema:Person'],
41+
'foaf:name': name,
42+
'mainEntityOfPage': profileDoc,
43+
'inbox': `${pod}inbox/`,
44+
'storage': pod,
45+
'oidcIssuer': issuer,
46+
'preferencesFile': `${pod}settings/prefs`
5547
};
5648
}
5749

0 commit comments

Comments
 (0)