-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27a5711
commit 998296a
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { Patch } from '../ldp/http/Patch'; | ||
import type { Representation } from '../ldp/representation/Representation'; | ||
import type { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; | ||
import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; | ||
import { NotImplementedHttpError } from '../util/errors/NotImplementedHttpError'; | ||
import type { Conditions } from './Conditions'; | ||
import type { ResourceStore } from './ResourceStore'; | ||
|
||
/** | ||
* Base implementation of ResourceStore for implementers of custom stores. | ||
*/ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
export class BaseResourceStore implements ResourceStore { | ||
public async addResource(container: ResourceIdentifier, representation: Representation, | ||
conditions?: Conditions): Promise<ResourceIdentifier> { | ||
throw new NotImplementedHttpError(); | ||
} | ||
|
||
public async deleteResource(identifier: ResourceIdentifier, conditions?: Conditions): Promise<void> { | ||
throw new NotImplementedHttpError(); | ||
} | ||
|
||
public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences, | ||
conditions?: Conditions): Promise<Representation> { | ||
throw new NotImplementedHttpError(); | ||
} | ||
|
||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise<void> { | ||
throw new NotImplementedHttpError(); | ||
} | ||
|
||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation, | ||
conditions?: Conditions): Promise<void> { | ||
throw new NotImplementedHttpError(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { BaseResourceStore } from '../../../src/storage/BaseResourceStore'; | ||
import { NotImplementedHttpError } from '../../../src/util/errors/NotImplementedHttpError'; | ||
|
||
const any: any = {}; | ||
|
||
describe('A BaseResourceStore', (): void => { | ||
const store = new BaseResourceStore(); | ||
it('errors on getRepresentation.', async(): Promise<void> => { | ||
await expect(store.getRepresentation(any, any)).rejects.toThrow(NotImplementedHttpError); | ||
}); | ||
|
||
it('errors on addResource.', async(): Promise<void> => { | ||
await expect(store.addResource(any, any)).rejects.toThrow(NotImplementedHttpError); | ||
}); | ||
|
||
it('errors on setRepresentation.', async(): Promise<void> => { | ||
await expect(store.setRepresentation(any, any)).rejects.toThrow(NotImplementedHttpError); | ||
}); | ||
|
||
it('errors on deleteResource.', async(): Promise<void> => { | ||
await expect(store.deleteResource(any, any)).rejects.toThrow(NotImplementedHttpError); | ||
}); | ||
|
||
it('errors on modifyResource.', async(): Promise<void> => { | ||
await expect(store.modifyResource(any, any)).rejects.toThrow(NotImplementedHttpError); | ||
}); | ||
}); |
998296a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the typical use case where someone would want to
class X extends BaseResourceStore
instead ofclass X implements ResourceStore
?998296a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a store that only implements part of the functionality but wants to error in case the function is not supported instead of passing it along (like a PassthroughStore does). But perhaps @RubenVerborgh had a specific case in mind.
998296a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthieubosquet I've done a couple of commits like these, based on my first experiences as an external module developer. This cuts like 10–15 lines: RubenVerborgh/solid-hue@0ea7ffe#diff-fed75016ea0a947acb8e85047bc43ab685e8dc5a07e15b0ccf510ce957d6224d
The reason this matters is it looks much harder than it was to implement a store. Compare:
And not just the code but also the imports and knowledge. What should I do when I don't support
deleteResource
? With this base class, you don't even have to care.