mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Allow quad data for containers
This prevents the container data check from throwing an error when converting to quads if the incoming data already is quads.
This commit is contained in:
parent
7011b766b4
commit
d5bf4e1e67
@ -1,3 +1,4 @@
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import { DataFactory } from 'n3';
|
||||
import type { Quad } from 'rdf-js';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
@ -240,7 +241,12 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
protected async handleContainerData(representation: Representation): Promise<void> {
|
||||
let quads: Quad[];
|
||||
try {
|
||||
// No need to parse the data if it already contains internal/quads
|
||||
if (representation.metadata.contentType === INTERNAL_QUADS) {
|
||||
quads = await arrayifyStream(representation.data);
|
||||
} else {
|
||||
quads = await parseQuads(representation.data);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
throw new BadRequestHttpError(`Can only create containers with RDF data. ${error.message}`);
|
||||
|
@ -17,6 +17,8 @@ import * as quadUtil from '../../../src/util/QuadUtil';
|
||||
import { guardedStreamFrom } from '../../../src/util/StreamUtil';
|
||||
import { CONTENT_TYPE, HTTP, LDP, RDF } from '../../../src/util/UriConstants';
|
||||
import { toNamedNode } from '../../../src/util/UriUtil';
|
||||
import quad = DataFactory.quad;
|
||||
import namedNode = DataFactory.namedNode;
|
||||
|
||||
class SimpleDataAccessor implements DataAccessor {
|
||||
public readonly data: Record<string, Representation> = {};
|
||||
@ -295,6 +297,20 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
expect(accessor.data[resourceID.path].metadata.contentType).toBeUndefined();
|
||||
});
|
||||
|
||||
it('can write containers with quad data.', async(): Promise<void> => {
|
||||
const resourceID = { path: `${root}container/` };
|
||||
|
||||
// Generate based on URI
|
||||
representation.metadata.removeAll(RDF.type);
|
||||
representation.metadata.contentType = 'internal/quads';
|
||||
representation.data = guardedStreamFrom(
|
||||
[ quad(namedNode(`${root}resource/`), namedNode('a'), namedNode('coolContainer')) ],
|
||||
);
|
||||
await expect(store.setRepresentation(resourceID, representation)).resolves.toBeUndefined();
|
||||
expect(accessor.data[resourceID.path]).toBeTruthy();
|
||||
expect(accessor.data[resourceID.path].metadata.contentType).toBeUndefined();
|
||||
});
|
||||
|
||||
it('errors when trying to create a container with containment triples.', async(): Promise<void> => {
|
||||
const resourceID = { path: `${root}container/` };
|
||||
representation.metadata.add(RDF.type, toNamedNode(LDP.Container));
|
||||
|
Loading…
x
Reference in New Issue
Block a user