mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Indicate caching on method name.
This commit is contained in:
parent
da5515d50d
commit
a572825909
@ -9,7 +9,7 @@ import { ensureTrailingSlash } from '../util/PathUtil';
|
|||||||
import { generateResourceQuads } from '../util/ResourceUtil';
|
import { generateResourceQuads } from '../util/ResourceUtil';
|
||||||
import { guardedStreamFrom } from '../util/StreamUtil';
|
import { guardedStreamFrom } from '../util/StreamUtil';
|
||||||
import { PIM, RDF } from '../util/UriConstants';
|
import { PIM, RDF } from '../util/UriConstants';
|
||||||
import { toNamedNode } from '../util/UriUtil';
|
import { toCachedNamedNode } from '../util/UriUtil';
|
||||||
import { Initializer } from './Initializer';
|
import { Initializer } from './Initializer';
|
||||||
import namedNode = DataFactory.namedNode;
|
import namedNode = DataFactory.namedNode;
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ export class RootContainerInitializer extends Initializer {
|
|||||||
|
|
||||||
// Make sure the root container is a pim:Storage
|
// Make sure the root container is a pim:Storage
|
||||||
// This prevents deletion of the root container as storage root containers can not be deleted
|
// This prevents deletion of the root container as storage root containers can not be deleted
|
||||||
metadata.add(RDF.type, toNamedNode(PIM.Storage));
|
metadata.add(RDF.type, toCachedNamedNode(PIM.Storage));
|
||||||
|
|
||||||
metadata.contentType = TEXT_TURTLE;
|
metadata.contentType = TEXT_TURTLE;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { DataFactory, Store } from 'n3';
|
import { DataFactory, Store } from 'n3';
|
||||||
import type { BlankNode, Literal, NamedNode, Quad, Term } from 'rdf-js';
|
import type { BlankNode, Literal, NamedNode, Quad, Term } from 'rdf-js';
|
||||||
import { getLoggerFor } from '../../logging/LogUtil';
|
import { getLoggerFor } from '../../logging/LogUtil';
|
||||||
import { toObjectTerm, toNamedNode, isTerm } from '../../util/UriUtil';
|
import { toObjectTerm, toCachedNamedNode, isTerm } from '../../util/UriUtil';
|
||||||
import type { ResourceIdentifier } from './ResourceIdentifier';
|
import type { ResourceIdentifier } from './ResourceIdentifier';
|
||||||
import { isResourceIdentifier } from './ResourceIdentifier';
|
import { isResourceIdentifier } from './ResourceIdentifier';
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ export class RepresentationMetadata {
|
|||||||
|
|
||||||
private setOverrides(overrides: Record<string, MetadataOverrideValue>): void {
|
private setOverrides(overrides: Record<string, MetadataOverrideValue>): void {
|
||||||
for (const predicate of Object.keys(overrides)) {
|
for (const predicate of Object.keys(overrides)) {
|
||||||
const namedPredicate = toNamedNode(predicate);
|
const namedPredicate = toCachedNamedNode(predicate);
|
||||||
this.removeAll(namedPredicate);
|
this.removeAll(namedPredicate);
|
||||||
|
|
||||||
let objects = overrides[predicate];
|
let objects = overrides[predicate];
|
||||||
@ -149,7 +149,7 @@ export class RepresentationMetadata {
|
|||||||
* @param object - Value to add.
|
* @param object - Value to add.
|
||||||
*/
|
*/
|
||||||
public add(predicate: NamedNode | string, object: NamedNode | Literal | string): this {
|
public add(predicate: NamedNode | string, object: NamedNode | Literal | string): this {
|
||||||
this.store.addQuad(this.id, toNamedNode(predicate), toObjectTerm(object));
|
this.store.addQuad(this.id, toCachedNamedNode(predicate), toObjectTerm(object));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ export class RepresentationMetadata {
|
|||||||
* @param object - Value to remove.
|
* @param object - Value to remove.
|
||||||
*/
|
*/
|
||||||
public remove(predicate: NamedNode | string, object: NamedNode | Literal | string): this {
|
public remove(predicate: NamedNode | string, object: NamedNode | Literal | string): this {
|
||||||
this.store.removeQuad(this.id, toNamedNode(predicate), toObjectTerm(object));
|
this.store.removeQuad(this.id, toCachedNamedNode(predicate), toObjectTerm(object));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ export class RepresentationMetadata {
|
|||||||
* @param predicate - Predicate to remove.
|
* @param predicate - Predicate to remove.
|
||||||
*/
|
*/
|
||||||
public removeAll(predicate: NamedNode | string): this {
|
public removeAll(predicate: NamedNode | string): this {
|
||||||
this.removeQuads(this.store.getQuads(this.id, toNamedNode(predicate), null, null));
|
this.removeQuads(this.store.getQuads(this.id, toCachedNamedNode(predicate), null, null));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ export class RepresentationMetadata {
|
|||||||
* @returns An array with all matches.
|
* @returns An array with all matches.
|
||||||
*/
|
*/
|
||||||
public getAll(predicate: NamedNode | string): Term[] {
|
public getAll(predicate: NamedNode | string): Term[] {
|
||||||
return this.store.getQuads(this.id, toNamedNode(predicate), null, null)
|
return this.store.getQuads(this.id, toCachedNamedNode(predicate), null, null)
|
||||||
.map((quad): Term => quad.object);
|
.map((quad): Term => quad.object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,10 +223,10 @@ export class RepresentationMetadata {
|
|||||||
* Shorthand for the CONTENT_TYPE predicate.
|
* Shorthand for the CONTENT_TYPE predicate.
|
||||||
*/
|
*/
|
||||||
public get contentType(): string | undefined {
|
public get contentType(): string | undefined {
|
||||||
return this.get(toNamedNode('contentType'))?.value;
|
return this.get(toCachedNamedNode('contentType'))?.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public set contentType(input) {
|
public set contentType(input) {
|
||||||
this.set(toNamedNode('contentType'), input);
|
this.set(toCachedNamedNode('contentType'), input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import { isContainerIdentifier } from '../../util/PathUtil';
|
|||||||
import { parseQuads, pushQuad, serializeQuads } from '../../util/QuadUtil';
|
import { parseQuads, pushQuad, serializeQuads } from '../../util/QuadUtil';
|
||||||
import { generateContainmentQuads, generateResourceQuads } from '../../util/ResourceUtil';
|
import { generateContainmentQuads, generateResourceQuads } from '../../util/ResourceUtil';
|
||||||
import { CONTENT_TYPE, DCTERMS, LDP, POSIX, RDF, XSD } from '../../util/UriConstants';
|
import { CONTENT_TYPE, DCTERMS, LDP, POSIX, RDF, XSD } from '../../util/UriConstants';
|
||||||
import { toNamedNode, toTypedLiteral } from '../../util/UriUtil';
|
import { toCachedNamedNode, toLiteral } from '../../util/UriUtil';
|
||||||
import type { FileIdentifierMapper, ResourceLink } from '../mapping/FileIdentifierMapper';
|
import type { FileIdentifierMapper, ResourceLink } from '../mapping/FileIdentifierMapper';
|
||||||
import type { DataAccessor } from './DataAccessor';
|
import type { DataAccessor } from './DataAccessor';
|
||||||
|
|
||||||
@ -210,9 +210,9 @@ export class FileDataAccessor implements DataAccessor {
|
|||||||
*/
|
*/
|
||||||
private async writeMetadata(link: ResourceLink, metadata: RepresentationMetadata): Promise<boolean> {
|
private async writeMetadata(link: ResourceLink, metadata: RepresentationMetadata): Promise<boolean> {
|
||||||
// These are stored by file system conventions
|
// These are stored by file system conventions
|
||||||
metadata.remove(RDF.type, toNamedNode(LDP.Resource));
|
metadata.remove(RDF.type, toCachedNamedNode(LDP.Resource));
|
||||||
metadata.remove(RDF.type, toNamedNode(LDP.Container));
|
metadata.remove(RDF.type, toCachedNamedNode(LDP.Container));
|
||||||
metadata.remove(RDF.type, toNamedNode(LDP.BasicContainer));
|
metadata.remove(RDF.type, toCachedNamedNode(LDP.BasicContainer));
|
||||||
metadata.removeAll(CONTENT_TYPE);
|
metadata.removeAll(CONTENT_TYPE);
|
||||||
const quads = metadata.quads();
|
const quads = metadata.quads();
|
||||||
const metadataLink = await this.getMetadataLink(link.identifier);
|
const metadataLink = await this.getMetadataLink(link.identifier);
|
||||||
@ -329,9 +329,9 @@ export class FileDataAccessor implements DataAccessor {
|
|||||||
*/
|
*/
|
||||||
private generatePosixQuads(subject: NamedNode, stats: Stats): Quad[] {
|
private generatePosixQuads(subject: NamedNode, stats: Stats): Quad[] {
|
||||||
const quads: Quad[] = [];
|
const quads: Quad[] = [];
|
||||||
pushQuad(quads, subject, toNamedNode(POSIX.size), toTypedLiteral(stats.size, XSD.integer));
|
pushQuad(quads, subject, toCachedNamedNode(POSIX.size), toLiteral(stats.size, XSD.integer));
|
||||||
pushQuad(quads, subject, toNamedNode(DCTERMS.modified), toTypedLiteral(stats.mtime.toISOString(), XSD.dateTime));
|
pushQuad(quads, subject, toCachedNamedNode(DCTERMS.modified), toLiteral(stats.mtime.toISOString(), XSD.dateTime));
|
||||||
pushQuad(quads, subject, toNamedNode(POSIX.mtime), toTypedLiteral(
|
pushQuad(quads, subject, toCachedNamedNode(POSIX.mtime), toLiteral(
|
||||||
Math.floor(stats.mtime.getTime() / 1000), XSD.integer,
|
Math.floor(stats.mtime.getTime() / 1000), XSD.integer,
|
||||||
));
|
));
|
||||||
return quads;
|
return quads;
|
||||||
|
@ -28,7 +28,7 @@ import type { Guarded } from '../../util/GuardedStream';
|
|||||||
import type { IdentifierStrategy } from '../../util/identifiers/IdentifierStrategy';
|
import type { IdentifierStrategy } from '../../util/identifiers/IdentifierStrategy';
|
||||||
import { isContainerIdentifier } from '../../util/PathUtil';
|
import { isContainerIdentifier } from '../../util/PathUtil';
|
||||||
import { CONTENT_TYPE, LDP } from '../../util/UriConstants';
|
import { CONTENT_TYPE, LDP } from '../../util/UriConstants';
|
||||||
import { toNamedNode } from '../../util/UriUtil';
|
import { toCachedNamedNode } from '../../util/UriUtil';
|
||||||
import type { DataAccessor } from './DataAccessor';
|
import type { DataAccessor } from './DataAccessor';
|
||||||
|
|
||||||
const { defaultGraph, namedNode, quad, variable } = DataFactory;
|
const { defaultGraph, namedNode, quad, variable } = DataFactory;
|
||||||
@ -226,7 +226,7 @@ export class SparqlDataAccessor implements DataAccessor {
|
|||||||
// Insert new metadata and containment triple
|
// Insert new metadata and containment triple
|
||||||
const insert: GraphQuads[] = [ this.sparqlUpdateGraph(metaName, metadata.quads()) ];
|
const insert: GraphQuads[] = [ this.sparqlUpdateGraph(metaName, metadata.quads()) ];
|
||||||
if (parent) {
|
if (parent) {
|
||||||
insert.push(this.sparqlUpdateGraph(parent, [ quad(parent, toNamedNode(LDP.contains), name) ]));
|
insert.push(this.sparqlUpdateGraph(parent, [ quad(parent, toCachedNamedNode(LDP.contains), name) ]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Necessary updates: delete metadata and insert new data
|
// Necessary updates: delete metadata and insert new data
|
||||||
@ -272,7 +272,7 @@ export class SparqlDataAccessor implements DataAccessor {
|
|||||||
if (parent) {
|
if (parent) {
|
||||||
update.updates.push({
|
update.updates.push({
|
||||||
updateType: 'delete',
|
updateType: 'delete',
|
||||||
delete: [ this.sparqlUpdateGraph(parent, [ quad(parent, toNamedNode(LDP.contains), name) ]) ],
|
delete: [ this.sparqlUpdateGraph(parent, [ quad(parent, toCachedNamedNode(LDP.contains), name) ]) ],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import type { NamedNode, Quad } from 'rdf-js';
|
|||||||
import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata';
|
import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata';
|
||||||
import { pushQuad } from './QuadUtil';
|
import { pushQuad } from './QuadUtil';
|
||||||
import { LDP, RDF } from './UriConstants';
|
import { LDP, RDF } from './UriConstants';
|
||||||
import { toNamedNode } from './UriUtil';
|
import { toCachedNamedNode } from './UriUtil';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to generate type quads for a Container or Resource.
|
* Helper function to generate type quads for a Container or Resource.
|
||||||
@ -15,10 +15,10 @@ import { toNamedNode } from './UriUtil';
|
|||||||
export const generateResourceQuads = (subject: NamedNode, isContainer: boolean): Quad[] => {
|
export const generateResourceQuads = (subject: NamedNode, isContainer: boolean): Quad[] => {
|
||||||
const quads: Quad[] = [];
|
const quads: Quad[] = [];
|
||||||
if (isContainer) {
|
if (isContainer) {
|
||||||
pushQuad(quads, subject, toNamedNode(RDF.type), toNamedNode(LDP.Container));
|
pushQuad(quads, subject, toCachedNamedNode(RDF.type), toCachedNamedNode(LDP.Container));
|
||||||
pushQuad(quads, subject, toNamedNode(RDF.type), toNamedNode(LDP.BasicContainer));
|
pushQuad(quads, subject, toCachedNamedNode(RDF.type), toCachedNamedNode(LDP.BasicContainer));
|
||||||
}
|
}
|
||||||
pushQuad(quads, subject, toNamedNode(RDF.type), toNamedNode(LDP.Resource));
|
pushQuad(quads, subject, toCachedNamedNode(RDF.type), toCachedNamedNode(LDP.Resource));
|
||||||
|
|
||||||
return quads;
|
return quads;
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,7 @@ export const isTerm = (input?: any): input is Term => input?.termType;
|
|||||||
* so only use this for internal constants!
|
* so only use this for internal constants!
|
||||||
* @param name - Predicate to potentially transform.
|
* @param name - Predicate to potentially transform.
|
||||||
*/
|
*/
|
||||||
export const toNamedNode = (name: NamedNode | string): NamedNode => {
|
export const toCachedNamedNode = (name: NamedNode | string): NamedNode => {
|
||||||
if (typeof name === 'string') {
|
if (typeof name === 'string') {
|
||||||
if (shorthands[name]) {
|
if (shorthands[name]) {
|
||||||
return shorthands[name];
|
return shorthands[name];
|
||||||
@ -47,5 +47,5 @@ export const toObjectTerm = (object: NamedNode | Literal | string): NamedNode |
|
|||||||
* @param object - Object value.
|
* @param object - Object value.
|
||||||
* @param dataType - Object data type (as string).
|
* @param dataType - Object data type (as string).
|
||||||
*/
|
*/
|
||||||
export const toTypedLiteral = (object: string | number, dataType: string): Literal =>
|
export const toLiteral = (object: string | number, dataType: string): Literal =>
|
||||||
DataFactory.literal(object, toNamedNode(dataType));
|
DataFactory.literal(object, toCachedNamedNode(dataType));
|
||||||
|
@ -2,14 +2,14 @@ import { createResponse } from 'node-mocks-http';
|
|||||||
import { LinkRelMetadataWriter } from '../../../../../src/ldp/http/metadata/LinkRelMetadataWriter';
|
import { LinkRelMetadataWriter } from '../../../../../src/ldp/http/metadata/LinkRelMetadataWriter';
|
||||||
import { RepresentationMetadata } from '../../../../../src/ldp/representation/RepresentationMetadata';
|
import { RepresentationMetadata } from '../../../../../src/ldp/representation/RepresentationMetadata';
|
||||||
import { LDP, RDF } from '../../../../../src/util/UriConstants';
|
import { LDP, RDF } from '../../../../../src/util/UriConstants';
|
||||||
import { toNamedNode } from '../../../../../src/util/UriUtil';
|
import { toCachedNamedNode } from '../../../../../src/util/UriUtil';
|
||||||
|
|
||||||
describe('A LinkRelMetadataWriter', (): void => {
|
describe('A LinkRelMetadataWriter', (): void => {
|
||||||
const writer = new LinkRelMetadataWriter({ [RDF.type]: 'type', dummy: 'dummy' });
|
const writer = new LinkRelMetadataWriter({ [RDF.type]: 'type', dummy: 'dummy' });
|
||||||
|
|
||||||
it('adds the correct link headers.', async(): Promise<void> => {
|
it('adds the correct link headers.', async(): Promise<void> => {
|
||||||
const response = createResponse();
|
const response = createResponse();
|
||||||
const metadata = new RepresentationMetadata({ [RDF.type]: toNamedNode(LDP.Resource), unused: 'text' });
|
const metadata = new RepresentationMetadata({ [RDF.type]: toCachedNamedNode(LDP.Resource), unused: 'text' });
|
||||||
await expect(writer.handle({ response, metadata })).resolves.toBeUndefined();
|
await expect(writer.handle({ response, metadata })).resolves.toBeUndefined();
|
||||||
expect(response.getHeaders()).toEqual({ link: `<${LDP.Resource}>; rel="type"` });
|
expect(response.getHeaders()).toEqual({ link: `<${LDP.Resource}>; rel="type"` });
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,7 @@ import { SingleRootIdentifierStrategy } from '../../../src/util/identifiers/Sing
|
|||||||
import * as quadUtil from '../../../src/util/QuadUtil';
|
import * as quadUtil from '../../../src/util/QuadUtil';
|
||||||
import { guardedStreamFrom } from '../../../src/util/StreamUtil';
|
import { guardedStreamFrom } from '../../../src/util/StreamUtil';
|
||||||
import { CONTENT_TYPE, HTTP, LDP, PIM, RDF } from '../../../src/util/UriConstants';
|
import { CONTENT_TYPE, HTTP, LDP, PIM, RDF } from '../../../src/util/UriConstants';
|
||||||
import { toNamedNode } from '../../../src/util/UriUtil';
|
import { toCachedNamedNode } from '../../../src/util/UriUtil';
|
||||||
import quad = DataFactory.quad;
|
import quad = DataFactory.quad;
|
||||||
import namedNode = DataFactory.namedNode;
|
import namedNode = DataFactory.namedNode;
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
|||||||
|
|
||||||
it('errors when trying to create a container with non-RDF data.', async(): Promise<void> => {
|
it('errors when trying to create a container with non-RDF data.', async(): Promise<void> => {
|
||||||
const resourceID = { path: root };
|
const resourceID = { path: root };
|
||||||
representation.metadata.add(RDF.type, toNamedNode(LDP.Container));
|
representation.metadata.add(RDF.type, toCachedNamedNode(LDP.Container));
|
||||||
await expect(store.addResource(resourceID, representation)).rejects.toThrow(BadRequestHttpError);
|
await expect(store.addResource(resourceID, representation)).rejects.toThrow(BadRequestHttpError);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
|||||||
const mock = jest.spyOn(quadUtil, 'parseQuads').mockImplementationOnce(async(): Promise<any> => {
|
const mock = jest.spyOn(quadUtil, 'parseQuads').mockImplementationOnce(async(): Promise<any> => {
|
||||||
throw 'apple';
|
throw 'apple';
|
||||||
});
|
});
|
||||||
representation.metadata.add(RDF.type, toNamedNode(LDP.Container));
|
representation.metadata.add(RDF.type, toCachedNamedNode(LDP.Container));
|
||||||
await expect(store.addResource(resourceID, representation)).rejects.toBe('apple');
|
await expect(store.addResource(resourceID, representation)).rejects.toBe('apple');
|
||||||
mock.mockRestore();
|
mock.mockRestore();
|
||||||
});
|
});
|
||||||
@ -186,7 +186,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
|||||||
|
|
||||||
it('can write containers.', async(): Promise<void> => {
|
it('can write containers.', async(): Promise<void> => {
|
||||||
const resourceID = { path: root };
|
const resourceID = { path: root };
|
||||||
representation.metadata.add(RDF.type, toNamedNode(LDP.Container));
|
representation.metadata.add(RDF.type, toCachedNamedNode(LDP.Container));
|
||||||
representation.metadata.contentType = 'text/turtle';
|
representation.metadata.contentType = 'text/turtle';
|
||||||
representation.data = guardedStreamFrom([ `<${`${root}resource/`}> a <coolContainer>.` ]);
|
representation.data = guardedStreamFrom([ `<${`${root}resource/`}> a <coolContainer>.` ]);
|
||||||
const result = await store.addResource(resourceID, representation);
|
const result = await store.addResource(resourceID, representation);
|
||||||
@ -269,14 +269,14 @@ describe('A DataAccessorBasedStore', (): void => {
|
|||||||
representation.metadata.identifier = DataFactory.namedNode(resourceID.path);
|
representation.metadata.identifier = DataFactory.namedNode(resourceID.path);
|
||||||
const newRepresentation = { ...representation };
|
const newRepresentation = { ...representation };
|
||||||
newRepresentation.metadata = new RepresentationMetadata(representation.metadata);
|
newRepresentation.metadata = new RepresentationMetadata(representation.metadata);
|
||||||
newRepresentation.metadata.add(RDF.type, toNamedNode(LDP.Container));
|
newRepresentation.metadata.add(RDF.type, toCachedNamedNode(LDP.Container));
|
||||||
await expect(store.setRepresentation(resourceID, newRepresentation))
|
await expect(store.setRepresentation(resourceID, newRepresentation))
|
||||||
.rejects.toThrow(new ConflictHttpError('Input resource type does not match existing resource type.'));
|
.rejects.toThrow(new ConflictHttpError('Input resource type does not match existing resource type.'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will error if the ending slash does not match its resource type.', async(): Promise<void> => {
|
it('will error if the ending slash does not match its resource type.', async(): Promise<void> => {
|
||||||
const resourceID = { path: `${root}resource` };
|
const resourceID = { path: `${root}resource` };
|
||||||
representation.metadata.add(RDF.type, toNamedNode(LDP.Container));
|
representation.metadata.add(RDF.type, toCachedNamedNode(LDP.Container));
|
||||||
await expect(store.setRepresentation(resourceID, representation)).rejects.toThrow(
|
await expect(store.setRepresentation(resourceID, representation)).rejects.toThrow(
|
||||||
new BadRequestHttpError('Containers should have a `/` at the end of their path, resources should not.'),
|
new BadRequestHttpError('Containers should have a `/` at the end of their path, resources should not.'),
|
||||||
);
|
);
|
||||||
@ -294,7 +294,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
|||||||
|
|
||||||
it('errors when trying to create a container with non-RDF data.', async(): Promise<void> => {
|
it('errors when trying to create a container with non-RDF data.', async(): Promise<void> => {
|
||||||
const resourceID = { path: `${root}container/` };
|
const resourceID = { path: `${root}container/` };
|
||||||
representation.metadata.add(RDF.type, toNamedNode(LDP.Container));
|
representation.metadata.add(RDF.type, toCachedNamedNode(LDP.Container));
|
||||||
await expect(store.setRepresentation(resourceID, representation)).rejects.toThrow(BadRequestHttpError);
|
await expect(store.setRepresentation(resourceID, representation)).rejects.toThrow(BadRequestHttpError);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -332,7 +332,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
|||||||
|
|
||||||
it('errors when trying to create a container with containment triples.', async(): Promise<void> => {
|
it('errors when trying to create a container with containment triples.', async(): Promise<void> => {
|
||||||
const resourceID = { path: `${root}container/` };
|
const resourceID = { path: `${root}container/` };
|
||||||
representation.metadata.add(RDF.type, toNamedNode(LDP.Container));
|
representation.metadata.add(RDF.type, toCachedNamedNode(LDP.Container));
|
||||||
representation.metadata.contentType = 'text/turtle';
|
representation.metadata.contentType = 'text/turtle';
|
||||||
representation.metadata.identifier = DataFactory.namedNode(`${root}resource/`);
|
representation.metadata.identifier = DataFactory.namedNode(`${root}resource/`);
|
||||||
representation.data = guardedStreamFrom(
|
representation.data = guardedStreamFrom(
|
||||||
@ -390,7 +390,7 @@ describe('A DataAccessorBasedStore', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('will error when deleting a root storage container.', async(): Promise<void> => {
|
it('will error when deleting a root storage container.', async(): Promise<void> => {
|
||||||
representation.metadata.add(RDF.type, toNamedNode(PIM.Storage));
|
representation.metadata.add(RDF.type, toCachedNamedNode(PIM.Storage));
|
||||||
accessor.data[`${root}container`] = representation;
|
accessor.data[`${root}container`] = representation;
|
||||||
await expect(store.deleteResource({ path: `${root}container` }))
|
await expect(store.deleteResource({ path: `${root}container` }))
|
||||||
.rejects.toThrow(new MethodNotAllowedHttpError('Cannot delete a root storage container.'));
|
.rejects.toThrow(new MethodNotAllowedHttpError('Cannot delete a root storage container.'));
|
||||||
|
@ -13,7 +13,7 @@ import { UnsupportedMediaTypeHttpError } from '../../../../src/util/errors/Unsup
|
|||||||
import type { Guarded } from '../../../../src/util/GuardedStream';
|
import type { Guarded } from '../../../../src/util/GuardedStream';
|
||||||
import { guardedStreamFrom, readableToString } from '../../../../src/util/StreamUtil';
|
import { guardedStreamFrom, readableToString } from '../../../../src/util/StreamUtil';
|
||||||
import { CONTENT_TYPE, DCTERMS, LDP, POSIX, RDF, XSD } from '../../../../src/util/UriConstants';
|
import { CONTENT_TYPE, DCTERMS, LDP, POSIX, RDF, XSD } from '../../../../src/util/UriConstants';
|
||||||
import { toNamedNode, toTypedLiteral } from '../../../../src/util/UriUtil';
|
import { toCachedNamedNode, toLiteral } from '../../../../src/util/UriUtil';
|
||||||
import { mockFs } from '../../../util/Util';
|
import { mockFs } from '../../../util/Util';
|
||||||
|
|
||||||
jest.mock('fs');
|
jest.mock('fs');
|
||||||
@ -98,9 +98,9 @@ describe('A FileDataAccessor', (): void => {
|
|||||||
expect(metadata.identifier.value).toBe(`${base}resource.ttl`);
|
expect(metadata.identifier.value).toBe(`${base}resource.ttl`);
|
||||||
expect(metadata.contentType).toBe('text/turtle');
|
expect(metadata.contentType).toBe('text/turtle');
|
||||||
expect(metadata.get(RDF.type)?.value).toBe(LDP.Resource);
|
expect(metadata.get(RDF.type)?.value).toBe(LDP.Resource);
|
||||||
expect(metadata.get(POSIX.size)).toEqualRdfTerm(toTypedLiteral('data'.length, XSD.integer));
|
expect(metadata.get(POSIX.size)).toEqualRdfTerm(toLiteral('data'.length, XSD.integer));
|
||||||
expect(metadata.get(DCTERMS.modified)).toEqualRdfTerm(toTypedLiteral(now.toISOString(), XSD.dateTime));
|
expect(metadata.get(DCTERMS.modified)).toEqualRdfTerm(toLiteral(now.toISOString(), XSD.dateTime));
|
||||||
expect(metadata.get(POSIX.mtime)).toEqualRdfTerm(toTypedLiteral(Math.floor(now.getTime() / 1000), XSD.integer));
|
expect(metadata.get(POSIX.mtime)).toEqualRdfTerm(toLiteral(Math.floor(now.getTime() / 1000), XSD.integer));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generates the metadata for a container and its non-meta children.', async(): Promise<void> => {
|
it('generates the metadata for a container and its non-meta children.', async(): Promise<void> => {
|
||||||
@ -108,22 +108,22 @@ describe('A FileDataAccessor', (): void => {
|
|||||||
metadata = await accessor.getMetadata({ path: `${base}container/` });
|
metadata = await accessor.getMetadata({ path: `${base}container/` });
|
||||||
expect(metadata.identifier.value).toBe(`${base}container/`);
|
expect(metadata.identifier.value).toBe(`${base}container/`);
|
||||||
expect(metadata.getAll(RDF.type)).toEqualRdfTermArray(
|
expect(metadata.getAll(RDF.type)).toEqualRdfTermArray(
|
||||||
[ toNamedNode(LDP.Container), toNamedNode(LDP.BasicContainer), toNamedNode(LDP.Resource) ],
|
[ toCachedNamedNode(LDP.Container), toCachedNamedNode(LDP.BasicContainer), toCachedNamedNode(LDP.Resource) ],
|
||||||
);
|
);
|
||||||
expect(metadata.get(POSIX.size)).toEqualRdfTerm(toTypedLiteral(0, XSD.integer));
|
expect(metadata.get(POSIX.size)).toEqualRdfTerm(toLiteral(0, XSD.integer));
|
||||||
expect(metadata.get(DCTERMS.modified)).toEqualRdfTerm(toTypedLiteral(now.toISOString(), XSD.dateTime));
|
expect(metadata.get(DCTERMS.modified)).toEqualRdfTerm(toLiteral(now.toISOString(), XSD.dateTime));
|
||||||
expect(metadata.get(POSIX.mtime)).toEqualRdfTerm(toTypedLiteral(Math.floor(now.getTime() / 1000), XSD.integer));
|
expect(metadata.get(POSIX.mtime)).toEqualRdfTerm(toLiteral(Math.floor(now.getTime() / 1000), XSD.integer));
|
||||||
expect(metadata.getAll(LDP.contains)).toEqualRdfTermArray(
|
expect(metadata.getAll(LDP.contains)).toEqualRdfTermArray(
|
||||||
[ toNamedNode(`${base}container/resource`), toNamedNode(`${base}container/container2/`) ],
|
[ toCachedNamedNode(`${base}container/resource`), toCachedNamedNode(`${base}container/container2/`) ],
|
||||||
);
|
);
|
||||||
|
|
||||||
const childQuads = metadata.quads().filter((quad): boolean =>
|
const childQuads = metadata.quads().filter((quad): boolean =>
|
||||||
quad.subject.value === `${base}container/resource`);
|
quad.subject.value === `${base}container/resource`);
|
||||||
const childMetadata = new RepresentationMetadata({ path: `${base}container/resource` }).addQuads(childQuads);
|
const childMetadata = new RepresentationMetadata({ path: `${base}container/resource` }).addQuads(childQuads);
|
||||||
expect(childMetadata.get(RDF.type)?.value).toBe(LDP.Resource);
|
expect(childMetadata.get(RDF.type)?.value).toBe(LDP.Resource);
|
||||||
expect(childMetadata.get(POSIX.size)).toEqualRdfTerm(toTypedLiteral('data'.length, XSD.integer));
|
expect(childMetadata.get(POSIX.size)).toEqualRdfTerm(toLiteral('data'.length, XSD.integer));
|
||||||
expect(childMetadata.get(DCTERMS.modified)).toEqualRdfTerm(toTypedLiteral(now.toISOString(), XSD.dateTime));
|
expect(childMetadata.get(DCTERMS.modified)).toEqualRdfTerm(toLiteral(now.toISOString(), XSD.dateTime));
|
||||||
expect(childMetadata.get(POSIX.mtime)).toEqualRdfTerm(toTypedLiteral(Math.floor(now.getTime() / 1000),
|
expect(childMetadata.get(POSIX.mtime)).toEqualRdfTerm(toLiteral(Math.floor(now.getTime() / 1000),
|
||||||
XSD.integer));
|
XSD.integer));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ describe('A FileDataAccessor', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not write metadata that is stored by the file system.', async(): Promise<void> => {
|
it('does not write metadata that is stored by the file system.', async(): Promise<void> => {
|
||||||
metadata.add(RDF.type, toNamedNode(LDP.Resource));
|
metadata.add(RDF.type, toCachedNamedNode(LDP.Resource));
|
||||||
await expect(accessor.writeDocument({ path: `${base}resource` }, data, metadata)).resolves.toBeUndefined();
|
await expect(accessor.writeDocument({ path: `${base}resource` }, data, metadata)).resolves.toBeUndefined();
|
||||||
expect(cache.data.resource).toBe('data');
|
expect(cache.data.resource).toBe('data');
|
||||||
expect(cache.data['resource.meta']).toBeUndefined();
|
expect(cache.data['resource.meta']).toBeUndefined();
|
||||||
@ -289,7 +289,7 @@ describe('A FileDataAccessor', (): void => {
|
|||||||
it('does not write metadata that is stored by the file system.', async(): Promise<void> => {
|
it('does not write metadata that is stored by the file system.', async(): Promise<void> => {
|
||||||
metadata = new RepresentationMetadata(
|
metadata = new RepresentationMetadata(
|
||||||
{ path: `${base}container/` },
|
{ path: `${base}container/` },
|
||||||
{ [RDF.type]: [ toNamedNode(LDP.BasicContainer), toNamedNode(LDP.Resource) ]},
|
{ [RDF.type]: [ toCachedNamedNode(LDP.BasicContainer), toCachedNamedNode(LDP.Resource) ]},
|
||||||
);
|
);
|
||||||
await expect(accessor.writeContainer({ path: `${base}container/` }, metadata)).resolves.toBeUndefined();
|
await expect(accessor.writeContainer({ path: `${base}container/` }, metadata)).resolves.toBeUndefined();
|
||||||
expect(cache.data.container).toEqual({});
|
expect(cache.data.container).toEqual({});
|
||||||
|
@ -7,7 +7,7 @@ import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError
|
|||||||
import type { Guarded } from '../../../../src/util/GuardedStream';
|
import type { Guarded } from '../../../../src/util/GuardedStream';
|
||||||
import { guardedStreamFrom, readableToString } from '../../../../src/util/StreamUtil';
|
import { guardedStreamFrom, readableToString } from '../../../../src/util/StreamUtil';
|
||||||
import { CONTENT_TYPE, LDP, RDF } from '../../../../src/util/UriConstants';
|
import { CONTENT_TYPE, LDP, RDF } from '../../../../src/util/UriConstants';
|
||||||
import { toNamedNode } from '../../../../src/util/UriUtil';
|
import { toCachedNamedNode } from '../../../../src/util/UriUtil';
|
||||||
|
|
||||||
describe('An InMemoryDataAccessor', (): void => {
|
describe('An InMemoryDataAccessor', (): void => {
|
||||||
const base = 'http://test.com/';
|
const base = 'http://test.com/';
|
||||||
@ -80,13 +80,13 @@ describe('An InMemoryDataAccessor', (): void => {
|
|||||||
await expect(accessor.writeContainer({ path: `${base}container/container2` }, metadata)).resolves.toBeUndefined();
|
await expect(accessor.writeContainer({ path: `${base}container/container2` }, metadata)).resolves.toBeUndefined();
|
||||||
metadata = await accessor.getMetadata({ path: `${base}container/` });
|
metadata = await accessor.getMetadata({ path: `${base}container/` });
|
||||||
expect(metadata.getAll(LDP.contains)).toEqualRdfTermArray(
|
expect(metadata.getAll(LDP.contains)).toEqualRdfTermArray(
|
||||||
[ toNamedNode(`${base}container/resource`), toNamedNode(`${base}container/container2/`) ],
|
[ toCachedNamedNode(`${base}container/resource`), toCachedNamedNode(`${base}container/container2/`) ],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds stored metadata when requesting document metadata.', async(): Promise<void> => {
|
it('adds stored metadata when requesting document metadata.', async(): Promise<void> => {
|
||||||
const identifier = { path: `${base}resource` };
|
const identifier = { path: `${base}resource` };
|
||||||
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toNamedNode(LDP.Resource) });
|
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toCachedNamedNode(LDP.Resource) });
|
||||||
await expect(accessor.writeDocument(identifier, data, inputMetadata)).resolves.toBeUndefined();
|
await expect(accessor.writeDocument(identifier, data, inputMetadata)).resolves.toBeUndefined();
|
||||||
metadata = await accessor.getMetadata(identifier);
|
metadata = await accessor.getMetadata(identifier);
|
||||||
expect(metadata.identifier.value).toBe(`${base}resource`);
|
expect(metadata.identifier.value).toBe(`${base}resource`);
|
||||||
@ -97,7 +97,7 @@ describe('An InMemoryDataAccessor', (): void => {
|
|||||||
|
|
||||||
it('adds stored metadata when requesting container metadata.', async(): Promise<void> => {
|
it('adds stored metadata when requesting container metadata.', async(): Promise<void> => {
|
||||||
const identifier = { path: `${base}container/` };
|
const identifier = { path: `${base}container/` };
|
||||||
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toNamedNode(LDP.Container) });
|
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toCachedNamedNode(LDP.Container) });
|
||||||
await expect(accessor.writeContainer(identifier, inputMetadata)).resolves.toBeUndefined();
|
await expect(accessor.writeContainer(identifier, inputMetadata)).resolves.toBeUndefined();
|
||||||
|
|
||||||
metadata = await accessor.getMetadata(identifier);
|
metadata = await accessor.getMetadata(identifier);
|
||||||
@ -109,7 +109,7 @@ describe('An InMemoryDataAccessor', (): void => {
|
|||||||
|
|
||||||
it('can overwrite the metadata of an existing container without overwriting children.', async(): Promise<void> => {
|
it('can overwrite the metadata of an existing container without overwriting children.', async(): Promise<void> => {
|
||||||
const identifier = { path: `${base}container/` };
|
const identifier = { path: `${base}container/` };
|
||||||
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toNamedNode(LDP.Container) });
|
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toCachedNamedNode(LDP.Container) });
|
||||||
await expect(accessor.writeContainer(identifier, inputMetadata)).resolves.toBeUndefined();
|
await expect(accessor.writeContainer(identifier, inputMetadata)).resolves.toBeUndefined();
|
||||||
const resourceMetadata = new RepresentationMetadata();
|
const resourceMetadata = new RepresentationMetadata();
|
||||||
await expect(accessor.writeDocument(
|
await expect(accessor.writeDocument(
|
||||||
@ -117,7 +117,7 @@ describe('An InMemoryDataAccessor', (): void => {
|
|||||||
)).resolves.toBeUndefined();
|
)).resolves.toBeUndefined();
|
||||||
|
|
||||||
const newMetadata = new RepresentationMetadata(inputMetadata);
|
const newMetadata = new RepresentationMetadata(inputMetadata);
|
||||||
newMetadata.add(RDF.type, toNamedNode(LDP.BasicContainer));
|
newMetadata.add(RDF.type, toCachedNamedNode(LDP.BasicContainer));
|
||||||
await expect(accessor.writeContainer(identifier, newMetadata)).resolves.toBeUndefined();
|
await expect(accessor.writeContainer(identifier, newMetadata)).resolves.toBeUndefined();
|
||||||
|
|
||||||
metadata = await accessor.getMetadata(identifier);
|
metadata = await accessor.getMetadata(identifier);
|
||||||
@ -135,7 +135,7 @@ describe('An InMemoryDataAccessor', (): void => {
|
|||||||
|
|
||||||
it('can write to the root container without overriding its children.', async(): Promise<void> => {
|
it('can write to the root container without overriding its children.', async(): Promise<void> => {
|
||||||
const identifier = { path: `${base}` };
|
const identifier = { path: `${base}` };
|
||||||
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toNamedNode(LDP.Container) });
|
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toCachedNamedNode(LDP.Container) });
|
||||||
await expect(accessor.writeContainer(identifier, inputMetadata)).resolves.toBeUndefined();
|
await expect(accessor.writeContainer(identifier, inputMetadata)).resolves.toBeUndefined();
|
||||||
const resourceMetadata = new RepresentationMetadata();
|
const resourceMetadata = new RepresentationMetadata();
|
||||||
await expect(accessor.writeDocument(
|
await expect(accessor.writeDocument(
|
||||||
|
@ -15,7 +15,7 @@ import type { Guarded } from '../../../../src/util/GuardedStream';
|
|||||||
import { SingleRootIdentifierStrategy } from '../../../../src/util/identifiers/SingleRootIdentifierStrategy';
|
import { SingleRootIdentifierStrategy } from '../../../../src/util/identifiers/SingleRootIdentifierStrategy';
|
||||||
import { guardedStreamFrom } from '../../../../src/util/StreamUtil';
|
import { guardedStreamFrom } from '../../../../src/util/StreamUtil';
|
||||||
import { CONTENT_TYPE, LDP, RDF } from '../../../../src/util/UriConstants';
|
import { CONTENT_TYPE, LDP, RDF } from '../../../../src/util/UriConstants';
|
||||||
import { toNamedNode } from '../../../../src/util/UriUtil';
|
import { toCachedNamedNode } from '../../../../src/util/UriUtil';
|
||||||
|
|
||||||
const { literal, namedNode, quad } = DataFactory;
|
const { literal, namedNode, quad } = DataFactory;
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ describe('A SparqlDataAccessor', (): void => {
|
|||||||
metadata = await accessor.getMetadata({ path: 'http://identifier' });
|
metadata = await accessor.getMetadata({ path: 'http://identifier' });
|
||||||
expect(metadata.quads()).toBeRdfIsomorphic([
|
expect(metadata.quads()).toBeRdfIsomorphic([
|
||||||
quad(namedNode('this'), namedNode('a'), namedNode('triple')),
|
quad(namedNode('this'), namedNode('a'), namedNode('triple')),
|
||||||
quad(namedNode('http://identifier'), toNamedNode(CONTENT_TYPE), literal(INTERNAL_QUADS)),
|
quad(namedNode('http://identifier'), toCachedNamedNode(CONTENT_TYPE), literal(INTERNAL_QUADS)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(fetchTriples).toHaveBeenCalledTimes(1);
|
expect(fetchTriples).toHaveBeenCalledTimes(1);
|
||||||
@ -135,7 +135,7 @@ describe('A SparqlDataAccessor', (): void => {
|
|||||||
|
|
||||||
it('overwrites the metadata when writing a container and updates parent.', async(): Promise<void> => {
|
it('overwrites the metadata when writing a container and updates parent.', async(): Promise<void> => {
|
||||||
metadata = new RepresentationMetadata({ path: 'http://test.com/container/' },
|
metadata = new RepresentationMetadata({ path: 'http://test.com/container/' },
|
||||||
{ [RDF.type]: [ toNamedNode(LDP.Resource), toNamedNode(LDP.Container) ]});
|
{ [RDF.type]: [ toCachedNamedNode(LDP.Resource), toCachedNamedNode(LDP.Container) ]});
|
||||||
await expect(accessor.writeContainer({ path: 'http://test.com/container/' }, metadata)).resolves.toBeUndefined();
|
await expect(accessor.writeContainer({ path: 'http://test.com/container/' }, metadata)).resolves.toBeUndefined();
|
||||||
|
|
||||||
expect(fetchUpdate).toHaveBeenCalledTimes(1);
|
expect(fetchUpdate).toHaveBeenCalledTimes(1);
|
||||||
@ -154,7 +154,7 @@ describe('A SparqlDataAccessor', (): void => {
|
|||||||
|
|
||||||
it('does not write containment triples when writing to a root container.', async(): Promise<void> => {
|
it('does not write containment triples when writing to a root container.', async(): Promise<void> => {
|
||||||
metadata = new RepresentationMetadata({ path: 'http://test.com/' },
|
metadata = new RepresentationMetadata({ path: 'http://test.com/' },
|
||||||
{ [RDF.type]: [ toNamedNode(LDP.Resource), toNamedNode(LDP.Container) ]});
|
{ [RDF.type]: [ toCachedNamedNode(LDP.Resource), toCachedNamedNode(LDP.Container) ]});
|
||||||
await expect(accessor.writeContainer({ path: 'http://test.com/' }, metadata)).resolves.toBeUndefined();
|
await expect(accessor.writeContainer({ path: 'http://test.com/' }, metadata)).resolves.toBeUndefined();
|
||||||
|
|
||||||
expect(fetchUpdate).toHaveBeenCalledTimes(1);
|
expect(fetchUpdate).toHaveBeenCalledTimes(1);
|
||||||
@ -172,7 +172,7 @@ describe('A SparqlDataAccessor', (): void => {
|
|||||||
|
|
||||||
it('overwrites the data and metadata when writing a resource and updates parent.', async(): Promise<void> => {
|
it('overwrites the data and metadata when writing a resource and updates parent.', async(): Promise<void> => {
|
||||||
metadata = new RepresentationMetadata({ path: 'http://test.com/container/resource' },
|
metadata = new RepresentationMetadata({ path: 'http://test.com/container/resource' },
|
||||||
{ [RDF.type]: [ toNamedNode(LDP.Resource) ]});
|
{ [RDF.type]: [ toCachedNamedNode(LDP.Resource) ]});
|
||||||
await expect(accessor.writeDocument({ path: 'http://test.com/container/resource' }, data, metadata))
|
await expect(accessor.writeDocument({ path: 'http://test.com/container/resource' }, data, metadata))
|
||||||
.resolves.toBeUndefined();
|
.resolves.toBeUndefined();
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ describe('A SparqlDataAccessor', (): void => {
|
|||||||
|
|
||||||
it('overwrites the data and metadata when writing an empty resource.', async(): Promise<void> => {
|
it('overwrites the data and metadata when writing an empty resource.', async(): Promise<void> => {
|
||||||
metadata = new RepresentationMetadata({ path: 'http://test.com/container/resource' },
|
metadata = new RepresentationMetadata({ path: 'http://test.com/container/resource' },
|
||||||
{ [RDF.type]: [ toNamedNode(LDP.Resource) ]});
|
{ [RDF.type]: [ toCachedNamedNode(LDP.Resource) ]});
|
||||||
const empty = guardedStreamFrom([]);
|
const empty = guardedStreamFrom([]);
|
||||||
await expect(accessor.writeDocument({ path: 'http://test.com/container/resource' }, empty, metadata))
|
await expect(accessor.writeDocument({ path: 'http://test.com/container/resource' }, empty, metadata))
|
||||||
.resolves.toBeUndefined();
|
.resolves.toBeUndefined();
|
||||||
@ -210,7 +210,7 @@ describe('A SparqlDataAccessor', (): void => {
|
|||||||
|
|
||||||
it('removes all references when deleting a resource.', async(): Promise<void> => {
|
it('removes all references when deleting a resource.', async(): Promise<void> => {
|
||||||
metadata = new RepresentationMetadata({ path: 'http://test.com/container/' },
|
metadata = new RepresentationMetadata({ path: 'http://test.com/container/' },
|
||||||
{ [RDF.type]: [ toNamedNode(LDP.Resource), toNamedNode(LDP.Container) ]});
|
{ [RDF.type]: [ toCachedNamedNode(LDP.Resource), toCachedNamedNode(LDP.Container) ]});
|
||||||
await expect(accessor.deleteResource({ path: 'http://test.com/container/' })).resolves.toBeUndefined();
|
await expect(accessor.deleteResource({ path: 'http://test.com/container/' })).resolves.toBeUndefined();
|
||||||
|
|
||||||
expect(fetchUpdate).toHaveBeenCalledTimes(1);
|
expect(fetchUpdate).toHaveBeenCalledTimes(1);
|
||||||
@ -224,7 +224,7 @@ describe('A SparqlDataAccessor', (): void => {
|
|||||||
|
|
||||||
it('does not try to remove containment triples when deleting a root container.', async(): Promise<void> => {
|
it('does not try to remove containment triples when deleting a root container.', async(): Promise<void> => {
|
||||||
metadata = new RepresentationMetadata({ path: 'http://test.com/' },
|
metadata = new RepresentationMetadata({ path: 'http://test.com/' },
|
||||||
{ [RDF.type]: [ toNamedNode(LDP.Resource), toNamedNode(LDP.Container) ]});
|
{ [RDF.type]: [ toCachedNamedNode(LDP.Resource), toCachedNamedNode(LDP.Container) ]});
|
||||||
await expect(accessor.deleteResource({ path: 'http://test.com/' })).resolves.toBeUndefined();
|
await expect(accessor.deleteResource({ path: 'http://test.com/' })).resolves.toBeUndefined();
|
||||||
|
|
||||||
expect(fetchUpdate).toHaveBeenCalledTimes(1);
|
expect(fetchUpdate).toHaveBeenCalledTimes(1);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'jest-rdf';
|
import 'jest-rdf';
|
||||||
import { literal, namedNode } from '@rdfjs/data-model';
|
import { literal, namedNode } from '@rdfjs/data-model';
|
||||||
import { CONTENT_TYPE, XSD } from '../../../src/util/UriConstants';
|
import { CONTENT_TYPE, XSD } from '../../../src/util/UriConstants';
|
||||||
import { toNamedNode, toObjectTerm, toTypedLiteral, isTerm } from '../../../src/util/UriUtil';
|
import { toCachedNamedNode, toObjectTerm, toLiteral, isTerm } from '../../../src/util/UriUtil';
|
||||||
|
|
||||||
describe('An UriUtil', (): void => {
|
describe('An UriUtil', (): void => {
|
||||||
describe('isTerm function', (): void => {
|
describe('isTerm function', (): void => {
|
||||||
@ -17,21 +17,21 @@ describe('An UriUtil', (): void => {
|
|||||||
describe('getNamedNode function', (): void => {
|
describe('getNamedNode function', (): void => {
|
||||||
it('returns the input if it was a named node.', async(): Promise<void> => {
|
it('returns the input if it was a named node.', async(): Promise<void> => {
|
||||||
const term = namedNode('name');
|
const term = namedNode('name');
|
||||||
expect(toNamedNode(term)).toBe(term);
|
expect(toCachedNamedNode(term)).toBe(term);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a named node when a string is used.', async(): Promise<void> => {
|
it('returns a named node when a string is used.', async(): Promise<void> => {
|
||||||
expect(toNamedNode('name')).toEqualRdfTerm(namedNode('name'));
|
expect(toCachedNamedNode('name')).toEqualRdfTerm(namedNode('name'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('caches generated named nodes.', async(): Promise<void> => {
|
it('caches generated named nodes.', async(): Promise<void> => {
|
||||||
const result = toNamedNode('name');
|
const result = toCachedNamedNode('name');
|
||||||
expect(result).toEqualRdfTerm(namedNode('name'));
|
expect(result).toEqualRdfTerm(namedNode('name'));
|
||||||
expect(toNamedNode('name')).toBe(result);
|
expect(toCachedNamedNode('name')).toBe(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports URI shorthands.', async(): Promise<void> => {
|
it('supports URI shorthands.', async(): Promise<void> => {
|
||||||
expect(toNamedNode('contentType')).toEqualRdfTerm(namedNode(CONTENT_TYPE));
|
expect(toCachedNamedNode('contentType')).toEqualRdfTerm(namedNode(CONTENT_TYPE));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ describe('An UriUtil', (): void => {
|
|||||||
describe('getTypedLiteral function', (): void => {
|
describe('getTypedLiteral function', (): void => {
|
||||||
it('converts the input to a valid literal with the given type.', async(): Promise<void> => {
|
it('converts the input to a valid literal with the given type.', async(): Promise<void> => {
|
||||||
const expected = literal('5', namedNode(XSD.integer));
|
const expected = literal('5', namedNode(XSD.integer));
|
||||||
expect(toTypedLiteral(5, XSD.integer)).toEqualRdfTerm(expected);
|
expect(toLiteral(5, XSD.integer)).toEqualRdfTerm(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user