Monorepo containing core modules of Zeichen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
691 B

  1. import Storage, { Collection } from '../core/storage'
  2. import Engine from './Engine'
  3. export default class RemoteStorage<T> implements Storage<T> {
  4. private readonly engine: Engine<T, Collection<T>>
  5. constructor(
  6. private ownerId: string,
  7. private baseUrl: string,
  8. private collectionId: string,
  9. ) {
  10. this.engine = new Engine(baseUrl)
  11. }
  12. async deleteItem(item: T) {
  13. return this.engine.removeItem(this.collectionId, item)
  14. }
  15. async queryItems() {
  16. const response = await this.engine.getCollection(this.collectionId) as Collection<T>;
  17. return response.items;
  18. }
  19. async saveItem(newItem: T) {
  20. return this.engine.setItem(this.collectionId, newItem)
  21. }
  22. }