options.sport = _.isInteger(options.ssl) ? options.ssl : 443; options.moreHttpPorts.push(options.sport); options.ssl = true;
constructor({logDir, logLevelConsole = 'warn', logLevel = 'debug', logName = 'lando'} = {}) { if (_.isInteger(logLevelConsole)) logLevelConsole = logLevels[logLevelConsole];
/** * Add limit constraint to this query object. * * @param {integer} value - The max number of values that should be returned. * @returns {OGMNeoQuery} This instance of query. */ limit(value) { if (_.isInteger(value)) { this._limit = value; } return this; }
static _validateAndBuildParams(nodesIds) { if (_.isArray(nodesIds)) { let validIds = nodesIds.filter(id => _.isInteger(id)); if (_.isEmpty(validIds)) { return null; } else { let parameters = validIds.reduce((result, current) => { return result + `${(result === '') ? '' : ','} ${current}`; }, ''); return `[${parameters}]`; } } else { throw new Error('nodesIds must be an array'); } }
_.uniq(query.ids.filter(x => !_.isEmpty(x) || _.isInteger(x)).map(x => x.toString()))
/** * Operation that deletes a node on neo4j. * * @static * @param {object} node - The literal object with node propeperties and required node.id. * @returns {OGMNeoOperation} Operation that deletes a node. * @throws {Error} Will throw an error if the node.id was not integer or not exists. */ static deleteOperation(node) { if (node && node.id != undefined && _.isInteger(node.id)) { let cypher = `MATCH (n) WHERE ID(n)=${node.id} DELETE n RETURN n`; return OGMNeoOperationBuilder.create() .cypher(cypher) .type(OGMNeoOperation.WRITE).then((result) => { return !_.isEmpty(result.records); }).build(); } else { throw new Error('Node must to have an non-nil property id to be deleted'); } }
/** * Operation that updates a node. * * @static * @param {object} node - The literal object with node propeperties and required node.id. * @returns {OGMNeoOperation} Update node operation that can be executed later. * @throws {Error} Will throw an error if the node.id was not integer or not exists. */ static updateOperation(node) { let value = _.omitBy(node, _.isUndefined); OGMNeoObjectParse.parseProperties(value); if (value && value.id != undefined && _.isInteger(value.id)) { let objectString = OGMNeoObjectParse.objectString(value); let cypher = `MATCH (n) WHERE ID(n)=${node.id} SET n+=${objectString} RETURN n`; return OGMNeoOperationBuilder.create() .cypher(cypher) .object(value) .type(OGMNeoOperation.WRITE).then((result) => { let record = _.first(result.records); return OGMNeoObjectParse.parseRecordNode(record, 'n'); }).build(); } else { throw new Error('Node must have an integer id to be updated'); } }
/** * Creates a operation that retrives a node with id. * * @static * @param {integer} id - The id of node that's wanted. * @returns {OGMNeoOperation} Operation retrives a node. * @throws {Error} Will throw an error if id was not an integer value. */ static nodeWithIdOperation(id) { if (_.isInteger(id)) { let cypher = `MATCH (n) WHERE ID(n)=${id} RETURN n`; return OGMNeoOperationBuilder.create() .cypher(cypher) .type(OGMNeoOperation.READ) .then((result) => { let record = _.first(result.records); return OGMNeoObjectParse.parseRecordNode(record, 'n'); }).build(); } else { throw new Error('You must provide an non-null integer id property to find the node'); } }
/** * Operation to add a label to a node. * * @static * @param {string} label - The label to be added to the node. * @param {integer} nodeId - The id of the node to add the label. * @returns {OGMNeoOperation} Operation that adds a label. * @throws {Error} Will throw an error if the nodeId was not an integer value. * @throws {Error} Will throw an error if the label was anything diferent than an non-empty string. */ static addLabelToNodeOperation(label, nodeId) { if (_.isInteger(nodeId)) { let operation = this.addLabelToNodesOperation(label, [nodeId]); operation.then = (result) => { let record = _.first(result.records); return (record != null) ? OGMNeoObjectParse.parseRecordNode(record, 'n') : null; }; return operation; } else { throw new Error('The nodeId must be an integer value'); } }
/** * Add ID and Label constraints to the startNode. * * @param {integer} nodeId - Node id constraint. * @param {string} label - Label constraint. * @returns {OGMNeoRelationQuery} This instance of query. */ startNode(nodeId, label) { if (_.isInteger(nodeId)) { this._startNodeId = nodeId; } if (_.isString(label)) { this._startNodeLabel = label; } return this; }
/** * Operation that deletes a relation by id. * * @static * @param {integer} relationId - relation node id. * @returns {OGMNeoOperation} Operation that deletes a node with id. * @throws {Error} Will throw an error if the relation id was not an integer value. */ static deleteRelationOperation(relationId) { if (_.isInteger(relationId)) { let cypher = `MATCH p=(n1)-[r]->(n2) WHERE ID(r)=${relationId} DELETE r RETURN r`; return OGMNeoOperationBuilder.create().cypher(cypher) .type(OGMNeoOperation.WRITE) .then((result) => { let record = _.first(result.records); return (record != null) ? OGMNeoObjectParse.recordToRelation(record) : null; }).build(); } else { throw new Error('Relation id must to be an integer number'); } }
/** * Add limit constraint to this query object. * * @param {integer} value - The max number of values that should be returned. * @returns {OGMNeoRelationQuery} This instance of query. */ limit(limit) { if (_.isInteger(limit)) { this._limit = limit; } return this; }
function isValidType(value) { return _.isInteger(value); }
/** * Add ID and Label constraints to the endNode. * * @param {integer} nodeId - Node id constraint. * @param {string} label - Label constraint. * @returns {OGMNeoRelationQuery} This instance of query. */ endNode(nodeId, label) { if (_.isInteger(nodeId)) { this._endNodeId = nodeId; } if (_.isString(label)) { this._endNodeLabel = label; } return this; }
/** * Operation that deletes a node and it's relation from database. * * @static * @param {object} node - The literal object with node propeperties and required node.id. * @returns {OGMNeoOperation} Operation that deletes a node. * @throws {Error} Will throw an error if the node.id was not integer or not exists. */ static deleteCascadeOperation(node) { if (node && node.id != undefined && _.isInteger(node.id)) { let cypher = `MATCH (n) WHERE ID(n)=${node.id} DETACH DELETE n RETURN n`; return OGMNeoOperationBuilder.create() .cypher(cypher) .type(OGMNeoOperation.WRITE).then((result) => { return !_.isEmpty(result.records); }).build(); } else { throw new Error('Node must to have an non-nil property id to be deleted'); } }