mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Only accept NamedNodes as predicates for metadata
* refactor: move toCachedNamedNode (private) * chore: only NamedNodes predicates in removes * feat: enforce NamedNode predicates in most cases * feat: getAll only accepts NamedNodes * feat: toCachedNamedNode only accepts string arg * tests: use NamedNodes for getAll calls * test: remove unnecessary string check for coverage * tests: fix NamedNodes in new tests after rebase * feat: metadatawriters store NamedNodes * refactor: toCachedNamedNode as utility function * fix: double write of linkRelMap * test: use the CONTENT_TYPE constant
This commit is contained in:
@@ -29,7 +29,6 @@ import {
|
||||
import { parseQuads } from '../util/QuadUtil';
|
||||
import { addResourceMetadata, updateModifiedDate } from '../util/ResourceUtil';
|
||||
import {
|
||||
CONTENT_TYPE,
|
||||
DC,
|
||||
SOLID_HTTP,
|
||||
LDP,
|
||||
@@ -39,6 +38,7 @@ import {
|
||||
XSD,
|
||||
SOLID_META,
|
||||
PREFERRED_PREFIX_TERM,
|
||||
CONTENT_TYPE_TERM,
|
||||
} from '../util/Vocabularies';
|
||||
import type { DataAccessor } from './accessors/DataAccessor';
|
||||
import type { Conditions } from './Conditions';
|
||||
@@ -435,7 +435,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
}
|
||||
|
||||
// Input content type doesn't matter anymore
|
||||
representation.metadata.removeAll(CONTENT_TYPE);
|
||||
representation.metadata.removeAll(CONTENT_TYPE_TERM);
|
||||
|
||||
// Container data is stored in the metadata
|
||||
representation.metadata.addQuads(quads);
|
||||
@@ -516,8 +516,8 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
Promise<ResourceIdentifier> {
|
||||
// Get all values needed for naming the resource
|
||||
const isContainer = this.isContainerType(metadata);
|
||||
const slug = metadata.get(SOLID_HTTP.slug)?.value;
|
||||
metadata.removeAll(SOLID_HTTP.slug);
|
||||
const slug = metadata.get(SOLID_HTTP.terms.slug)?.value;
|
||||
metadata.removeAll(SOLID_HTTP.terms.slug);
|
||||
|
||||
let newID: ResourceIdentifier = this.createURI(container, isContainer, slug);
|
||||
|
||||
@@ -544,7 +544,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
* @param metadata - Metadata of the (new) resource.
|
||||
*/
|
||||
protected isContainerType(metadata: RepresentationMetadata): boolean {
|
||||
return this.hasContainerType(metadata.getAll(RDF.type));
|
||||
return this.hasContainerType(metadata.getAll(RDF.terms.type));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -558,7 +558,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
* Verifies if this is the metadata of a root storage container.
|
||||
*/
|
||||
protected isRootStorage(metadata: RepresentationMetadata): boolean {
|
||||
return metadata.getAll(RDF.type).some((term): boolean => term.value === PIM.Storage);
|
||||
return metadata.getAll(RDF.terms.type).some((term): boolean => term.value === PIM.Storage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@ import { joinFilePath, isContainerIdentifier } from '../../util/PathUtil';
|
||||
import { parseQuads, serializeQuads } from '../../util/QuadUtil';
|
||||
import { addResourceMetadata, updateModifiedDate } from '../../util/ResourceUtil';
|
||||
import { toLiteral, toNamedTerm } from '../../util/TermUtil';
|
||||
import { CONTENT_TYPE, DC, IANA, LDP, POSIX, RDF, SOLID_META, XSD } from '../../util/Vocabularies';
|
||||
import { CONTENT_TYPE_TERM, DC, IANA, LDP, POSIX, RDF, SOLID_META, XSD } from '../../util/Vocabularies';
|
||||
import type { FileIdentifierMapper, ResourceLink } from '../mapping/FileIdentifierMapper';
|
||||
import type { DataAccessor } from './DataAccessor';
|
||||
|
||||
@@ -174,7 +174,7 @@ export class FileDataAccessor implements DataAccessor {
|
||||
private async getFileMetadata(link: ResourceLink, stats: Stats):
|
||||
Promise<RepresentationMetadata> {
|
||||
return (await this.getBaseMetadata(link, stats, false))
|
||||
.set(CONTENT_TYPE, link.contentType);
|
||||
.set(CONTENT_TYPE_TERM, link.contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,7 +202,7 @@ export class FileDataAccessor implements DataAccessor {
|
||||
metadata.remove(RDF.terms.type, LDP.terms.Container);
|
||||
metadata.remove(RDF.terms.type, LDP.terms.BasicContainer);
|
||||
metadata.removeAll(DC.terms.modified);
|
||||
metadata.removeAll(CONTENT_TYPE);
|
||||
metadata.removeAll(CONTENT_TYPE_TERM);
|
||||
const quads = metadata.quads();
|
||||
const metadataLink = await this.resourceMapper.mapUrlToFilePath(link.identifier, true);
|
||||
let wroteMetadata: boolean;
|
||||
|
||||
@@ -27,7 +27,7 @@ import { guardStream } from '../../util/GuardedStream';
|
||||
import type { Guarded } from '../../util/GuardedStream';
|
||||
import type { IdentifierStrategy } from '../../util/identifiers/IdentifierStrategy';
|
||||
import { isContainerIdentifier } from '../../util/PathUtil';
|
||||
import { CONTENT_TYPE, LDP } from '../../util/Vocabularies';
|
||||
import { LDP, CONTENT_TYPE_TERM } from '../../util/Vocabularies';
|
||||
import type { DataAccessor } from './DataAccessor';
|
||||
|
||||
const { defaultGraph, namedNode, quad, variable } = DataFactory;
|
||||
@@ -132,7 +132,7 @@ export class SparqlDataAccessor implements DataAccessor {
|
||||
}
|
||||
|
||||
// Not relevant since all content is triples
|
||||
metadata.removeAll(CONTENT_TYPE);
|
||||
metadata.removeAll(CONTENT_TYPE_TERM);
|
||||
|
||||
return this.sendSparqlUpdate(this.sparqlInsert(name, metadata, parent, triples));
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ export class PodQuotaStrategy extends QuotaStrategy {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const hasPimStorageMetadata = metadata!.getAll(RDF.type)
|
||||
const hasPimStorageMetadata = metadata!.getAll(RDF.terms.type)
|
||||
.some((term): boolean => term.value === PIM.Storage);
|
||||
|
||||
return hasPimStorageMetadata ? identifier : this.searchPimStorage(parent);
|
||||
|
||||
Reference in New Issue
Block a user