UNPKG

@awhere/api

Version:

The awesome aWhere API for JavaScript.

353 lines 12.4 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var PrototypeBase_1 = __importDefault(require("../PrototypeBase")); var User_1 = __importDefault(require("../User")); var Permission_1 = __importDefault(require("./Permission")); var Watcher_1 = require("../Watcher"); var ItemBase = /** @class */ (function (_super) { __extends(ItemBase, _super); function ItemBase(props) { if (props === void 0) { props = {}; } var _this = _super.call(this, props) || this; _this._isNew = false; if (props._id) { _this._id = props._id; } else { _this._id = ItemBase.generateId(); _this._isNew = true; } if (typeof props.permission === 'object') { _this._permission = new Permission_1.default(props.permission); } else if (props.permission === undefined) { _this._permission = new Permission_1.default(); } _this._name = props.name; _this._description = props.description; if (props.type !== undefined) { _this._type = props.type; } if (props.subtype !== undefined) { _this._subtype = props.subtype; } if (typeof props.owner === 'object') { _this._owner = new User_1.default(props.owner); } else if (typeof props.owner === 'string') { _this._owner = props.owner; } if (typeof props.parent !== undefined) { _this._parent = props.parent; } _this._thumbnail = props.thumbnail; if (props.progress !== undefined) { _this._progress = props.progress; } else { _this._progress = 'done'; } if (props.trashed !== undefined) { _this._trashed = props.trashed; } else { _this._trashed = false; } if (props.lastModified !== undefined) { if (props.deletedAt instanceof Date) { _this._lastModified = props.lastModified; } else { _this._lastModified = new Date(props.lastModified); } } else { _this._lastModified = new Date(); } if (props.hidden !== undefined) { _this._hidden = props.hidden; } else { _this._hidden = false; } if (props.deletable !== undefined) { _this._deletable = props.deletable; } else { _this._deletable = true; } if (props.accessRole !== undefined) { _this._accessRole = props.accessRole; } if (props.importable !== undefined) { _this._importable = props.importable; } if (props.exportable !== undefined) { _this._exportable = props.exportable; } if (props.executable !== undefined) { _this._executable = props.executable; } return _this; } ItemBase.generateId = function () { return _super.generateId.call(this, 'awhere.core.item'); }; Object.defineProperty(ItemBase.prototype, "name", { get: function () { return this._name; }, set: function (value) { this._name = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "description", { get: function () { return this._description; }, set: function (value) { this._description = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "type", { get: function () { return this._type; }, set: function (value) { this._type = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "subtype", { get: function () { return this._subtype; }, set: function (value) { this._subtype = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "owner", { get: function () { return this._owner; }, set: function (value) { this._owner = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "parent", { get: function () { return this._parent; }, set: function (value) { this._parent = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "permission", { get: function () { return this._permission; }, set: function (value) { this._permission = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "thumbnail", { get: function () { return this._thumbnail; }, set: function (value) { this._thumbnail = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "progress", { get: function () { return this._progress; }, set: function (value) { this._progress = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "trashed", { get: function () { return this._trashed; }, set: function (value) { this._trashed = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "lastModified", { get: function () { return this._lastModified; }, set: function (value) { this._lastModified = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "deletable", { get: function () { return this._deletable; }, set: function (value) { this._deletable = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "hidden", { get: function () { return this._hidden; }, set: function (value) { this._hidden = value; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "accessRole", { get: function () { return this._accessRole; }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "importable", { get: function () { var _a; if (typeof this._importable === 'boolean') { return this._importable; } return !!((_a = this._props) === null || _a === void 0 ? void 0 : _a.importInfo); }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "exportable", { get: function () { var _a; if (typeof this._exportable === 'boolean') { return this._exportable; } return !!((_a = this._props) === null || _a === void 0 ? void 0 : _a.exportInfo); }, enumerable: false, configurable: true }); Object.defineProperty(ItemBase.prototype, "executable", { get: function () { var _a; if (typeof this._executable === 'boolean') { return this._executable; } return !!((_a = this._props) === null || _a === void 0 ? void 0 : _a.executeInfo); }, enumerable: false, configurable: true }); ItemBase.prototype.isOwner = function (profile) { var _a; if (typeof this._owner === 'string') { return this._owner === profile._id; } else { return ((_a = this._owner) === null || _a === void 0 ? void 0 : _a._id) === profile._id; } }; ItemBase.prototype.getAccessRole = function (user) { return this._accessRole; }; ItemBase.prototype.save = function () { if (this._isNew) { return this.request.put("/drive/create-item", this).then(function (res) { return res.data; }); } else { return this.request.put("/drive/update-item/".concat(this._id), this).then(function (res) { return res.data; }); } }; ItemBase.prototype.delete = function () { return this.request.put("/drive/delete", { ids: [this._id] }).then(function (res) { return res.data; }); }; ItemBase.prototype.toJSON = function () { var _a, _b, _c, _d, _e; return { _id: this._id, name: this.name, description: this.description, type: this.type, subtype: this.subtype, owner: typeof this.owner === 'string' ? this.owner : (_a = this.owner) === null || _a === void 0 ? void 0 : _a._id, parent: typeof this.parent === 'string' ? this.parent : (_b = this.parent) === null || _b === void 0 ? void 0 : _b._id, permission: this.permission instanceof Permission_1.default ? this.permission.toJSON() : this.permission, thumbnail: this.thumbnail, progress: this.progress, trashed: this.trashed, lastModified: this.lastModified ? this.lastModified.toISOString() : undefined, deletable: this.deletable, hidden: this.hidden, createdAt: this.createdAt ? this.createdAt.toISOString() : undefined, createdBy: typeof this.createdBy === 'string' ? this.createdBy : (_c = this.createdBy) === null || _c === void 0 ? void 0 : _c._id, updatedAt: this.updatedAt ? this.updatedAt.toISOString() : undefined, updatedBy: typeof this.updatedBy === 'string' ? this.updatedBy : (_d = this.updatedBy) === null || _d === void 0 ? void 0 : _d._id, deleted: this.deleted, deletedAt: this.deletedAt ? this.deletedAt.toISOString() : undefined, deletedBy: typeof this.deletedBy === 'string' ? this.deletedBy : (_e = this.deletedBy) === null || _e === void 0 ? void 0 : _e._id, props: this.props, extendedProps: this.extendedProps, organization: this.organization, accessRole: this.accessRole, importable: this.importable, exportable: this.exportable, executable: this.executable, }; }; ItemBase.prototype.watch = function () { var _this = this; return new Promise(function (resolve, reject) { var namespace = '/item'; _this.socket.open(); _this.socket.emit('call', "sub:".concat(namespace), _this._id, function (err) { err ? reject(err) : resolve(new Watcher_1.Watcher(_this.socket, namespace, _this._id)); }); }); }; return ItemBase; }(PrototypeBase_1.default)); exports.default = ItemBase; //# sourceMappingURL=ItemBase.js.map