-
Notifications
You must be signed in to change notification settings - Fork 121
/
ResourceUtil.ts
33 lines (30 loc) · 1.29 KB
/
ResourceUtil.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { DataFactory } from 'n3';
import type { NamedNode, Quad } from 'rdf-js';
import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata';
import { pushQuad } from './QuadUtil';
import { LDP, RDF } from './Vocabularies';
/**
* Helper function to generate type quads for a Container or Resource.
* @param subject - Subject for the new quads.
* @param isContainer - If the identifier corresponds to a container.
*
* @returns The generated quads.
*/
export const generateResourceQuads = (subject: NamedNode, isContainer: boolean): Quad[] => {
const quads: Quad[] = [];
if (isContainer) {
pushQuad(quads, subject, RDF.terms.type, LDP.terms.Container);
pushQuad(quads, subject, RDF.terms.type, LDP.terms.BasicContainer);
}
pushQuad(quads, subject, RDF.terms.type, LDP.terms.Resource);
return quads;
};
/**
* Helper function to generate the quads describing that the resource URIs are children of the container URI.
* @param containerURI - The URI of the container.
* @param childURIs - The URI of the child resources.
*
* @returns The generated quads.
*/
export const generateContainmentQuads = (containerURI: NamedNode, childURIs: string[]): Quad[] =>
new RepresentationMetadata(containerURI, { [LDP.contains]: childURIs.map(DataFactory.namedNode) }).quads();