Save and load notes in Zeichen using an external API.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

28 linhas
703 B

  1. import Storage, { Collection } from '../../core/src/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. }