Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/storage/accessors/InMemoryDataAccessor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Readable } from 'node:stream';
import arrayifyStream from 'arrayify-stream';
import { DataFactory } from 'n3';
import { RepresentationMetadata } from '../../http/representation/RepresentationMetadata';
import type { ResourceIdentifier } from '../../http/representation/ResourceIdentifier';
import type { SingleThreaded } from '../../init/cluster/SingleThreaded';
Expand Down Expand Up @@ -53,8 +54,11 @@ export class InMemoryDataAccessor implements DataAccessor, SingleThreaded {
public async* getChildren(identifier: ResourceIdentifier): AsyncIterableIterator<RepresentationMetadata> {
const entry = this.getEntry(identifier);
if (!this.isDataEntry(entry)) {
const childNames = Object.keys(entry.entries);
yield* childNames.map((name): RepresentationMetadata => new RepresentationMetadata({ path: name }));
yield* Object.entries(entry.entries).map(([ path, child ]): RepresentationMetadata => {
const metadata = new RepresentationMetadata(DataFactory.namedNode(path));
metadata.addQuads(child.metadata.quads());
return metadata;
});
}
}

Expand Down
26 changes: 25 additions & 1 deletion test/unit/storage/accessors/InMemoryDataAccessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError
import type { Guarded } from '../../../../src/util/GuardedStream';
import { BaseIdentifierStrategy } from '../../../../src/util/identifiers/BaseIdentifierStrategy';
import { guardedStreamFrom, readableToString } from '../../../../src/util/StreamUtil';
import { CONTENT_TYPE, LDP, POSIX, RDF } from '../../../../src/util/Vocabularies';
import { toLiteral } from '../../../../src/util/TermUtil';
import { CONTENT_TYPE, DC, LDP, POSIX, RDF, XSD } from '../../../../src/util/Vocabularies';

const { namedNode } = DataFactory;

Expand Down Expand Up @@ -103,6 +104,29 @@ describe('An InMemoryDataAccessor', (): void => {
expect(children[1].identifier.value).toBe(`${base}container/container2/`);
});

it('generates metadata for container child resources.', async(): Promise<void> => {
const now = new Date();
await expect(accessor.writeContainer({ path: `${base}container/` }, metadata)).resolves.toBeUndefined();
await expect(accessor.writeDocument({ path: `${base}container/resource` }, data, new RepresentationMetadata(
{ path: `${base}container/resource` },
{
[RDF.type]: LDP.terms.Resource,
[DC.modified]: toLiteral(now.toISOString(), XSD.terms.dateTime),
[CONTENT_TYPE]: 'text/turtle',
},
))).resolves.toBeUndefined();

const children = [];
for await (const child of accessor.getChildren({ path: `${base}container/` })) {
children.push(child);
}
expect(children).toHaveLength(1);
expect(children[0].identifier.value).toBe(`${base}container/resource`);
expect(children[0].get(DC.terms.modified))
.toEqualRdfTerm(toLiteral(now.toISOString(), XSD.terms.dateTime));
expect(children[0].get(RDF.terms.type)).toEqual(LDP.terms.Resource);
});

it('adds stored metadata when requesting document metadata.', async(): Promise<void> => {
const identifier = { path: `${base}resource` };
const inputMetadata = new RepresentationMetadata(identifier, {
Expand Down
Loading