UNPKG

waterbase

Version:
59 lines (58 loc) 2.16 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); }; var _collection, _client; class Document { constructor(client, collection, id = '', data = {}) { this.id = ''; _collection.set(this, ''); _client.set(this, void 0); /** * Updates the selected doc * * @param update object * * @return Promise<any> */ this.update = (update) => new Promise((res, rej) => { __classPrivateFieldGet(this, _client).call('put', `/database/update/${__classPrivateFieldGet(this, _collection)}`, { 'content-type': 'application/json', }, { query: { _id: this.id }, update: { $set: update } }) .then((value) => { res(value); }) .catch(rej); }); /** * Deletes the selected doc * * @return Promise<any> */ this.delete = () => new Promise((res, rej) => { __classPrivateFieldGet(this, _client).call('delete', `/database/delete/${__classPrivateFieldGet(this, _collection)}`, { 'content-type': 'application/json', }, { query: { _id: this.id } }) .then((value) => { res(value); }) .catch(rej); }); __classPrivateFieldSet(this, _client, client); __classPrivateFieldSet(this, _collection, collection); this.id = id; this.data = data; } } _collection = new WeakMap(), _client = new WeakMap(); module.exports = Document;