mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Rename resourceExists to hasResource
The function was also moved to the smaller interface ResourceSet.
This commit is contained in:
@@ -42,7 +42,7 @@ export class PatchOperationHandler extends OperationHandler {
|
||||
// RFC7231, §4.3.4: If the target resource does not have a current representation and the
|
||||
// PUT successfully creates one, then the origin server MUST inform the
|
||||
// user agent by sending a 201 (Created) response.
|
||||
const exists = await this.store.resourceExists(operation.target, operation.conditions);
|
||||
const exists = await this.store.hasResource(operation.target);
|
||||
await this.store.modifyResource(operation.target, operation.body as Patch, operation.conditions);
|
||||
if (exists) {
|
||||
return new ResetResponseDescription();
|
||||
|
||||
@@ -38,7 +38,7 @@ export class PutOperationHandler extends OperationHandler {
|
||||
}
|
||||
// A more efficient approach would be to have the server return metadata indicating if a resource was new
|
||||
// See https://github.com/solid/community-server/issues/632
|
||||
const exists = await this.store.resourceExists(operation.target, operation.conditions);
|
||||
const exists = await this.store.hasResource(operation.target);
|
||||
await this.store.setRepresentation(operation.target, operation.body, operation.conditions);
|
||||
if (exists) {
|
||||
return new ResetResponseDescription();
|
||||
|
||||
@@ -358,6 +358,7 @@ export * from './storage/PassthroughStore';
|
||||
export * from './storage/PatchingStore';
|
||||
export * from './storage/ReadOnlyStore';
|
||||
export * from './storage/RepresentationConvertingStore';
|
||||
export * from './storage/ResourceSet';
|
||||
export * from './storage/ResourceStore';
|
||||
export * from './storage/RoutingResourceStore';
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export class GeneratedPodManager implements PodManager {
|
||||
*/
|
||||
public async createPod(identifier: ResourceIdentifier, settings: PodSettings, overwrite: boolean): Promise<void> {
|
||||
this.logger.info(`Creating pod ${identifier.path}`);
|
||||
if (!overwrite && await this.store.resourceExists(identifier)) {
|
||||
if (!overwrite && await this.store.hasResource(identifier)) {
|
||||
throw new ConflictHttpError(`There already is a resource at ${identifier.path}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import type { ResourceStore } from './ResourceStore';
|
||||
*/
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
export class BaseResourceStore implements ResourceStore {
|
||||
public async resourceExists(identifier: ResourceIdentifier, conditions?: Conditions): Promise<boolean> {
|
||||
public async hasResource(identifier: ResourceIdentifier): Promise<boolean> {
|
||||
throw new NotImplementedHttpError();
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
this.auxiliaryStrategy = auxiliaryStrategy;
|
||||
}
|
||||
|
||||
public async resourceExists(identifier: ResourceIdentifier): Promise<boolean> {
|
||||
public async hasResource(identifier: ResourceIdentifier): Promise<boolean> {
|
||||
try {
|
||||
this.validateIdentifier(identifier);
|
||||
await this.accessor.getMetadata(identifier);
|
||||
@@ -530,7 +530,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
// Make sure we don't already have a resource with this exact name (or with differing trailing slash)
|
||||
const withSlash = { path: ensureTrailingSlash(newID.path) };
|
||||
const withoutSlash = { path: trimTrailingSlashes(newID.path) };
|
||||
if (await this.resourceExists(withSlash) || await this.resourceExists(withoutSlash)) {
|
||||
if (await this.hasResource(withSlash) || await this.hasResource(withoutSlash)) {
|
||||
newID = this.createURI(container, isContainer);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ export class LockingResourceStore implements AtomicResourceStore {
|
||||
this.auxiliaryStrategy = auxiliaryStrategy;
|
||||
}
|
||||
|
||||
public async resourceExists(identifier: ResourceIdentifier, conditions?: Conditions): Promise<boolean> {
|
||||
public async hasResource(identifier: ResourceIdentifier): Promise<boolean> {
|
||||
return this.locks.withReadLock(this.getLockIdentifier(identifier),
|
||||
async(): Promise<boolean> => this.source.resourceExists(identifier, conditions));
|
||||
async(): Promise<boolean> => this.source.hasResource(identifier));
|
||||
}
|
||||
|
||||
public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences,
|
||||
|
||||
@@ -19,8 +19,8 @@ export class MonitoringStore<T extends ResourceStore = ResourceStore>
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public async resourceExists(identifier: ResourceIdentifier, conditions?: Conditions): Promise<boolean> {
|
||||
return this.source.resourceExists(identifier, conditions);
|
||||
public async hasResource(identifier: ResourceIdentifier): Promise<boolean> {
|
||||
return this.source.hasResource(identifier);
|
||||
}
|
||||
|
||||
public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences,
|
||||
|
||||
@@ -17,8 +17,8 @@ export class PassthroughStore<T extends ResourceStore = ResourceStore> implement
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public async resourceExists(identifier: ResourceIdentifier, conditions?: Conditions): Promise<boolean> {
|
||||
return this.source.resourceExists(identifier, conditions);
|
||||
public async hasResource(identifier: ResourceIdentifier): Promise<boolean> {
|
||||
return this.source.hasResource(identifier);
|
||||
}
|
||||
|
||||
public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences,
|
||||
|
||||
14
src/storage/ResourceSet.ts
Normal file
14
src/storage/ResourceSet.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { ResourceIdentifier } from '../http/representation/ResourceIdentifier';
|
||||
|
||||
/**
|
||||
* A set containing resources.
|
||||
*/
|
||||
export interface ResourceSet {
|
||||
/**
|
||||
* Check if a resource exists in this ResourceSet.
|
||||
* @param identifier - Identifier of resource to check.
|
||||
*
|
||||
* @returns A promise resolving if the resource already exists.
|
||||
*/
|
||||
hasResource: (identifier: ResourceIdentifier) => Promise<boolean>;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import type { Representation } from '../http/representation/Representation';
|
||||
import type { RepresentationPreferences } from '../http/representation/RepresentationPreferences';
|
||||
import type { ResourceIdentifier } from '../http/representation/ResourceIdentifier';
|
||||
import type { Conditions } from './Conditions';
|
||||
import type { ResourceSet } from './ResourceSet';
|
||||
|
||||
/**
|
||||
* A ResourceStore represents a collection of resources.
|
||||
@@ -15,16 +16,7 @@ import type { Conditions } from './Conditions';
|
||||
* ResourceStores are also responsible for taking auxiliary resources into account
|
||||
* should those be relevant to the store.
|
||||
*/
|
||||
export interface ResourceStore {
|
||||
|
||||
/**
|
||||
* Check if a resource exists.
|
||||
* @param identifier - Identifier of resource to check.
|
||||
*
|
||||
* @returns A promise resolving if the resource already exists
|
||||
*/
|
||||
resourceExists: (identifier: ResourceIdentifier, conditions?: Conditions) => Promise<boolean>;
|
||||
|
||||
export interface ResourceStore extends ResourceSet {
|
||||
/**
|
||||
* Retrieves a representation of a resource.
|
||||
* @param identifier - Identifier of the resource to read.
|
||||
|
||||
@@ -20,9 +20,9 @@ export class RoutingResourceStore implements ResourceStore {
|
||||
this.rule = rule;
|
||||
}
|
||||
|
||||
public async resourceExists(identifier: ResourceIdentifier, conditions?: Conditions):
|
||||
public async hasResource(identifier: ResourceIdentifier):
|
||||
Promise<boolean> {
|
||||
return (await this.getStore(identifier)).resourceExists(identifier, conditions);
|
||||
return (await this.getStore(identifier)).hasResource(identifier);
|
||||
}
|
||||
|
||||
public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences,
|
||||
|
||||
@@ -42,7 +42,7 @@ export class JsonResourceStorage implements KeyValueStorage<string, unknown> {
|
||||
|
||||
public async has(key: string): Promise<boolean> {
|
||||
const identifier = this.createIdentifier(key);
|
||||
return await this.source.resourceExists(identifier);
|
||||
return await this.source.hasResource(identifier);
|
||||
}
|
||||
|
||||
public async set(key: string, value: unknown): Promise<this> {
|
||||
|
||||
@@ -39,7 +39,7 @@ export class ConvertingRouterRule extends RouterRule {
|
||||
entry.supportChecker.supports({ identifier, representation }));
|
||||
} else {
|
||||
// No content-type given so we can only check if one of the stores has data for the identifier
|
||||
store = await this.findStore(async(entry): Promise<boolean> => entry.store.resourceExists(identifier));
|
||||
store = await this.findStore(async(entry): Promise<boolean> => entry.store.hasResource(identifier));
|
||||
}
|
||||
return store;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user