Package Exports
- @dwk/ldn
- @dwk/ldn/discovery
Readme
@dwk/ldn
Linked Data Notifications (W3C LDN) primitives. A
pure, RDF-only, protocol-agnostic library: it implements the three LDN roles
as plain-data functions over @dwk/rdf's flat StoredQuad
representation, with no Cloudflare bindings, no transport, and no Solid/WAC
assumptions. The same primitives back the @dwk/solid-pod
inbox (discovery) and the @dwk/activitypub inbox
(advertisement) without either standard leaking into the other.
See the spec for the authoritative requirements.
What it does
- Discovery — advertise an inbox with
inboxLinkHeader(inboxIri)(anldp:inboxLinkvalue) orinboxTriple(subject, inbox)(the in-body triple), and find one from the consumer side withparseInboxLinks(header)ordiscoverInboxIris(quads, subject?). - Receiver —
parseNotification(body, contentType, { baseIRI })validates a posted RDF notification, throwing aNotificationProblemthat carries the HTTP status to answer (415for a non-RDF media type,400for a body that does not parse or has no triples) and otherwise returning the parsedStoredQuads. - Consumer —
inboxListingQuads(inbox, members)builds theldp:Container+ldp:containslisting triples;listInboxMembers(quads, inbox?)reads them back.
Authorization, deduplication, and storage are the caller's concern — this library only speaks RDF and the LDN vocabulary.
Usage
import {
inboxLinkHeader,
parseNotification,
NotificationProblem,
} from "@dwk/ldn";
// Producer: advertise the inbox on a target resource's response.
response.headers.set("link", inboxLinkHeader("https://alice.example/inbox/"));
// Receiver: validate an inbound notification before persisting it.
try {
const { quads } = await parseNotification(
await request.text(),
request.headers.get("content-type"),
{ baseIRI: inboxIri },
);
// …authorize, dedup, and store `quads`…
} catch (error) {
if (error instanceof NotificationProblem) {
return new Response(error.message, { status: error.status });
}
throw error;
}