-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
Description
Summary
applyN3Patch inserts new nodes at the document root level, but does not add them into nested arrays like schema:itemListElement. This means PATCHing a type index that nests registrations inside a property silently adds the node in the wrong place.
Root Cause
In n3-patch.js, insertTriple searches for the subject node in nodes (which is either doc['@graph'] or [doc]). When the subject is a new fragment ID like #reg-test2, it's not found, so a new node is pushed to the top-level nodes array:
if (!subjectNode) {
subjectNode = { '@id': subject };
nodes.push(subjectNode); // ← goes to root, not into nested arrays
}But in a type index structured like:
{
"@id": "#typeindex",
"schema:itemListElement": [
{ "@id": "#reg-tracker", ... },
{ "@id": "#reg-test", ... }
]
}The new node should be inserted into schema:itemListElement, not as a sibling of #typeindex.
Reproduction
const { parseN3Patch, applyN3Patch } = require('./src/patch/n3-patch.js');
const doc = {
"@id": "#typeindex",
"@type": "solid:TypeIndex",
"schema:itemListElement": [
{ "@id": "#reg-existing" }
]
};
const body = `@prefix solid: <http://www.w3.org/ns/solid/terms#>.
@prefix wf: <http://www.w3.org/2005/01/wf/flow#>.
_:patch a solid:InsertDeletePatch;
solid:inserts {
<#reg-new> a solid:TypeRegistration;
solid:forClass wf:Tracker;
solid:instance <https://example.com/todo.jsonld#this>.
}.`;
const patch = parseN3Patch(body, 'https://example.com/settings/typeIndex.json');
const result = applyN3Patch(doc, patch, 'https://example.com/settings/typeIndex.json');
// Expected: #reg-new inside schema:itemListElement
// Actual: #reg-new is a new top-level node, schema:itemListElement unchangedImpact
- PATCH returns 204 (success) but the registration is not discoverable
- The new node exists in the document but in the wrong location
- Clients reading
schema:itemListElementnever see it
Workaround
Read-modify-write using GET + PUT works correctly.
Related: #212
Reactions are currently unavailable