UNPKG

devshare

Version:

Library to communicate with devshare development sharing platform.

65 lines (49 loc) 2.54 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _isArray2 = require('lodash/isArray'); var _isArray3 = _interopRequireDefault(_isArray2); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _firebaser = require('../../utils/firebaser'); var _firebaser2 = _interopRequireDefault(_firebaser); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = function (projectPath, entityPath, entityType) { var pathArray = (0, _isArray3.default)(entityPath) ? entityPath : entityPath.split('/'); var path = pathArray.join('/'); var name = pathArray[pathArray.length - 1]; var fullPath = projectPath.concat(pathArray); // console.log('project path:', { projectPath, fullPath }) var methods = { firebaseUrl: function firebaseUrl() { return (0, _firebaser.createFirebaseUrl)(fullPath)(); }, firebaseRef: function firebaseRef() { return (0, _firebaser.createFirebaseRef)(fullPath)(); }, add: function add(original) { return ( // Check to see if file with matching name already exists (0, _firebaser.get)(fullPath)().then(function (file) { return file ? Promise.reject(new Error('File with a matching name already exists')) : original ? (0, _firebaser.set)(fullPath)({ meta: { name: name, path: path, entityType: entityType, original: original } }) : (0, _firebaser.set)(fullPath)({ meta: { name: name, path: path, entityType: entityType } }); }) ); }, getMeta: function getMeta() { return (0, _firebaser.get)(fullPath)().then(function (entity) { return entity.meta; }); }, move: function move(newPath) { return (0, _firebaser.get)(fullPath)().then(function (originalEntity) { return (0, _firebaser.set)(pathArray.concat(newPath))(originalEntity); }).then((0, _firebaser.remove)(fullPath)()); }, // TODO: Set in new location instead of just changing name rename: function rename(name) { return (0, _firebaser.update)(fullPath)({ name: name }); } }; return _extends({}, { entityType: entityType, name: name, path: path, pathArray: pathArray }, (0, _firebaser2.default)(fullPath, ['get', 'update', 'remove', 'getChild']), methods); }; module.exports = exports['default'];