mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
change: Make RepresentationMetadata accept a ResourceIdentifier.
Closes https://github.com/solid/community-server/issues/388
This commit is contained in:
committed by
Joachim Van Herwegen
parent
6ee56a6d67
commit
accfc2e58d
@@ -2,7 +2,10 @@ import { DataFactory, Store } from 'n3';
|
||||
import type { BlankNode, Literal, NamedNode, Quad, Term } from 'rdf-js';
|
||||
import { getLoggerFor } from '../../logging/LogUtil';
|
||||
import { toObjectTerm, toNamedNode, isTerm } from '../../util/UriUtil';
|
||||
import type { ResourceIdentifier } from './ResourceIdentifier';
|
||||
import { isResourceIdentifier } from './ResourceIdentifier';
|
||||
|
||||
export type MetadataIdentifier = ResourceIdentifier | NamedNode | BlankNode;
|
||||
export type MetadataOverrideValue = NamedNode | Literal | string | (NamedNode | Literal | string)[];
|
||||
|
||||
/**
|
||||
@@ -23,7 +26,7 @@ export class RepresentationMetadata {
|
||||
*
|
||||
* `@ignored` tag is necessary for Components-Generator.js
|
||||
*/
|
||||
public constructor(identifier?: NamedNode | BlankNode | string, overrides?: Record<string, MetadataOverrideValue>);
|
||||
public constructor(identifier?: MetadataIdentifier, overrides?: Record<string, MetadataOverrideValue>);
|
||||
|
||||
/**
|
||||
* @param metadata - Starts as a copy of the input metadata.
|
||||
@@ -38,12 +41,12 @@ export class RepresentationMetadata {
|
||||
public constructor(overrides?: Record<string, MetadataOverrideValue>);
|
||||
|
||||
public constructor(
|
||||
input?: NamedNode | BlankNode | string | RepresentationMetadata | Record<string, MetadataOverrideValue>,
|
||||
input?: MetadataIdentifier | RepresentationMetadata | Record<string, MetadataOverrideValue>,
|
||||
overrides?: Record<string, MetadataOverrideValue>,
|
||||
) {
|
||||
this.store = new Store();
|
||||
if (typeof input === 'string') {
|
||||
this.id = DataFactory.namedNode(input);
|
||||
if (isResourceIdentifier(input)) {
|
||||
this.id = DataFactory.namedNode(input.path);
|
||||
} else if (isTerm(input)) {
|
||||
this.id = input;
|
||||
} else if (input instanceof RepresentationMetadata) {
|
||||
|
||||
@@ -7,3 +7,10 @@ export interface ResourceIdentifier {
|
||||
*/
|
||||
path: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the object is a `ResourceIdentifier`.
|
||||
*/
|
||||
export const isResourceIdentifier = function(object: any): object is ResourceIdentifier {
|
||||
return object && (typeof object.path === 'string');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user