Source: ogmneo-node.js

  1. 'use strict';
  2. const _ = require('lodash');
  3. const OGMNeoQuery = require('./ogmneo-query');
  4. const OGMNeoObjectParse = require('./ogmneo-parse');
  5. const { OGMNeoOperation, OGMNeoOperationBuilder } = require('./ogmneo-operation');
  6. const OGMNeoOperationExecuter = require('./ogmneo-operation-executer');
  7. /**
  8. * @class OGMNeoNode
  9. */
  10. class OGMNeoNode {
  11. /**
  12. * Creates a node on neo4j.
  13. *
  14. * @static
  15. * @param {object} node - The literal object with node propeperties.
  16. * @param {string} [label=null] - The label of the node. Default null is a node without label.
  17. * @returns {Promise<object|Error>} Created node literal object if fulfilled, or some neo4j error if rejected.
  18. */
  19. static create(node, label = null) {
  20. let operation = this.createOperation(node, label);
  21. return OGMNeoOperationExecuter.execute(operation);
  22. }
  23. /**
  24. * Operation that creates a node on neo4j.
  25. *
  26. * @static
  27. * @param {object} node - The literal object with node propeperties.
  28. * @param {string} [label=null] - The label of the node. Default null is a node without label.
  29. * @returns {OGMNeoOperation} Create node operation that can be executed later.
  30. */
  31. static createOperation(node, label = null) {
  32. let value = _.omitBy(node, _.isUndefined);
  33. OGMNeoObjectParse.parseProperties(value);
  34. let objectString = OGMNeoObjectParse.objectString(value);
  35. let labelCypher = (!_.isEmpty(label) && _.isString(label)) ? `:${label}` : '';
  36. let cypher = `CREATE (n${labelCypher} ${objectString}) RETURN n`;
  37. return OGMNeoOperationBuilder.create()
  38. .cypher(cypher)
  39. .object(value)
  40. .type(OGMNeoOperation.WRITE).then((result) => {
  41. let record = _.first(result.records);
  42. return OGMNeoObjectParse.parseRecordNode(record, 'n');
  43. }).build();
  44. }
  45. /**
  46. * Updates a node on neo4j.
  47. *
  48. * @static
  49. * @param {object} node - The literal object with node propeperties and required node.id.
  50. * @returns {Promise.<object|Error>} Updated node literal object if fulfilled, or error if node.id is invalid or some neo4j error if rejected.
  51. */
  52. static update(node) {
  53. try {
  54. let operation = this.updateOperation(node);
  55. return OGMNeoOperationExecuter.execute(operation);
  56. } catch (error) {
  57. return Promise.reject(error);
  58. }
  59. }
  60. /**
  61. * Operation that updates a node.
  62. *
  63. * @static
  64. * @param {object} node - The literal object with node propeperties and required node.id.
  65. * @returns {OGMNeoOperation} Update node operation that can be executed later.
  66. * @throws {Error} Will throw an error if the node.id was not integer or not exists.
  67. */
  68. static updateOperation(node) {
  69. let value = _.omitBy(node, _.isUndefined);
  70. OGMNeoObjectParse.parseProperties(value);
  71. if (value && value.id != undefined && _.isInteger(value.id)) {
  72. let objectString = OGMNeoObjectParse.objectString(value);
  73. let cypher = `MATCH (n) WHERE ID(n)=${node.id} SET n+=${objectString} RETURN n`;
  74. return OGMNeoOperationBuilder.create()
  75. .cypher(cypher)
  76. .object(value)
  77. .type(OGMNeoOperation.WRITE).then((result) => {
  78. let record = _.first(result.records);
  79. return OGMNeoObjectParse.parseRecordNode(record, 'n');
  80. }).build();
  81. } else {
  82. throw new Error('Node must have an integer id to be updated');
  83. }
  84. }
  85. /**
  86. * Update new properties on every node that matches the query.
  87. *
  88. * @static
  89. * @param {OGMNeoQuery} query - The query to filter the nodes.
  90. * @param {object} newProperties - NEW properties.
  91. * @returns {Promise.<array|Error>} Updated nodes if fulfilled or some neo4j error if rejected.
  92. */
  93. static updateMany(query, newProperties) {
  94. try {
  95. let operation = this.updateManyOperation(query, newProperties);
  96. return OGMNeoOperationExecuter.execute(operation);
  97. } catch (error) {
  98. return Promise.reject(error);
  99. }
  100. }
  101. /**
  102. * Returns an operation that updates new properties on every node that matches the query.
  103. *
  104. * @static
  105. * @param {OGMNeoQuery} query - The query to filter the nodes.
  106. * @param {object} newProperties - NEW properties.
  107. * @returns {OGMNeoOperation} Operation that updates new properties on every node that matches the query.
  108. * @throws {Error} Will throw an error if the query is not an instance of ogmneo.Query.
  109. * @throws {Error} Will throw an error if newProperties is not an object.
  110. * @throws {Error} Will throw an error if newProperties don't have at least one property with NO undefined values to update.
  111. */
  112. static updateManyOperation(query, newProperties) {
  113. if (_.isObject(newProperties)) {
  114. let value = _.omitBy(newProperties, _.isUndefined);
  115. if (!_.isEmpty(value)) {
  116. OGMNeoObjectParse.parseProperties(value);
  117. if (query instanceof OGMNeoQuery) {
  118. let objectString = OGMNeoObjectParse.objectString(value);
  119. let cypher = `${query.matchCypher()} SET n+=${objectString} RETURN n`;
  120. return OGMNeoOperationBuilder.create()
  121. .cypher(cypher)
  122. .object(value)
  123. .type(OGMNeoOperation.WRITE).then((result) => {
  124. return result.records.map(record => OGMNeoObjectParse.parseRecordNode(record, 'n'));
  125. }).build();
  126. } else {
  127. throw new Error('The query object must be an instance of OGMNeoQuery');
  128. }
  129. } else {
  130. throw new Error('You must provide at least one property with NO undefined values to update');
  131. }
  132. } else {
  133. throw new Error('The new properties must be an object');
  134. }
  135. }
  136. /**
  137. * Deletes a node on neo4j.
  138. *
  139. * @static
  140. * @param {object} node - The literal object with node propeperties and required node.id.
  141. * @returns {Promise.<boolean|Error>} True if fulfilled and found and delete node, false if not found object to delete, or error if node.id is invalid or some neo4j error if rejected.
  142. */
  143. static delete(node) {
  144. try {
  145. let operation = this.deleteOperation(node);
  146. return OGMNeoOperationExecuter.execute(operation);
  147. } catch (error) {
  148. return Promise.reject(error);
  149. }
  150. }
  151. /**
  152. * Operation that deletes a node on neo4j.
  153. *
  154. * @static
  155. * @param {object} node - The literal object with node propeperties and required node.id.
  156. * @returns {OGMNeoOperation} Operation that deletes a node.
  157. * @throws {Error} Will throw an error if the node.id was not integer or not exists.
  158. */
  159. static deleteOperation(node) {
  160. if (node && node.id != undefined && _.isInteger(node.id)) {
  161. let cypher = `MATCH (n) WHERE ID(n)=${node.id} DELETE n RETURN n`;
  162. return OGMNeoOperationBuilder.create()
  163. .cypher(cypher)
  164. .type(OGMNeoOperation.WRITE).then((result) => {
  165. return !_.isEmpty(result.records);
  166. }).build();
  167. } else {
  168. throw new Error('Node must to have an non-nil property id to be deleted');
  169. }
  170. }
  171. /**
  172. * Deletes a node and it's relation from database.
  173. *
  174. * @static
  175. * @param {object} node - The literal object with node propeperties and required node.id.
  176. * @returns {Promise.<boolean|Error>} True if fulfilled and found and delete node, false if not found object to delete, or error if node.id is invalid or some neo4j error if rejected.
  177. */
  178. static deleteCascade(node) {
  179. try {
  180. let operation = this.deleteCascadeOperation(node);
  181. return OGMNeoOperationExecuter.execute(operation);
  182. } catch (error) {
  183. return Promise.reject(error);
  184. }
  185. }
  186. /**
  187. * Operation that deletes a node and it's relation from database.
  188. *
  189. * @static
  190. * @param {object} node - The literal object with node propeperties and required node.id.
  191. * @returns {OGMNeoOperation} Operation that deletes a node.
  192. * @throws {Error} Will throw an error if the node.id was not integer or not exists.
  193. */
  194. static deleteCascadeOperation(node) {
  195. if (node && node.id != undefined && _.isInteger(node.id)) {
  196. let cypher = `MATCH (n) WHERE ID(n)=${node.id} DETACH DELETE n RETURN n`;
  197. return OGMNeoOperationBuilder.create()
  198. .cypher(cypher)
  199. .type(OGMNeoOperation.WRITE).then((result) => {
  200. return !_.isEmpty(result.records);
  201. }).build();
  202. } else {
  203. throw new Error('Node must to have an non-nil property id to be deleted');
  204. }
  205. }
  206. /**
  207. * Deletes every node that matches the ogmneo.Query.
  208. *
  209. * @static
  210. * @param {OGMNeoQuery} query - The query to filter the nodes.
  211. * @returns {Promise.<number|Error>} Number of nodes deleted if fulfilled or some neo4j error if rejected.
  212. */
  213. static deleteMany(query) {
  214. try {
  215. let operation = this.deleteManyOperation(query);
  216. return OGMNeoOperationExecuter.execute(operation);
  217. } catch (error) {
  218. return Promise.reject(error);
  219. }
  220. }
  221. /**
  222. * Creates an operation that deletes every node that matches the query.
  223. *
  224. * @static
  225. * @param {OGMNeoQuery} query - The query to filter the nodes.
  226. * @returns {OGMNeoOperation} Operation that deletes the matched nodes.
  227. * @throws {Error} Will throw an error if the query was not a instance of ogmneo.Query.
  228. */
  229. static deleteManyOperation(query) {
  230. if (query instanceof OGMNeoQuery) {
  231. let cypher = `${query.matchCypher()} DELETE n RETURN n`;
  232. return OGMNeoOperationBuilder.create()
  233. .cypher(cypher)
  234. .type(OGMNeoOperation.WRITE)
  235. .then((result) => {
  236. return result.records.length;
  237. }).build();
  238. } else {
  239. throw new Error('The query object must be an instance of OGMNeoQuery');
  240. }
  241. }
  242. /**
  243. * Retrive node with id.
  244. *
  245. * @static
  246. * @param {integer} id - The id of node that's wanted.
  247. * @returns {Promise.<object|Error>} Object if found fulfilled or null if not found fulfilled, or error if the id is invalid or some neo4j error if rejected.
  248. */
  249. static nodeWithId(id) {
  250. try {
  251. let operation = this.nodeWithIdOperation(id);
  252. return OGMNeoOperationExecuter.execute(operation);
  253. } catch (error) {
  254. return Promise.reject(error);
  255. }
  256. }
  257. /**
  258. * Creates a operation that retrives a node with id.
  259. *
  260. * @static
  261. * @param {integer} id - The id of node that's wanted.
  262. * @returns {OGMNeoOperation} Operation retrives a node.
  263. * @throws {Error} Will throw an error if id was not an integer value.
  264. */
  265. static nodeWithIdOperation(id) {
  266. if (_.isInteger(id)) {
  267. let cypher = `MATCH (n) WHERE ID(n)=${id} RETURN n`;
  268. return OGMNeoOperationBuilder.create()
  269. .cypher(cypher)
  270. .type(OGMNeoOperation.READ)
  271. .then((result) => {
  272. let record = _.first(result.records);
  273. return OGMNeoObjectParse.parseRecordNode(record, 'n');
  274. }).build();
  275. } else {
  276. throw new Error('You must provide an non-null integer id property to find the node');
  277. }
  278. }
  279. /**
  280. * Retrive nodes with ids.
  281. *
  282. * @static
  283. * @param {array} ids - The ids of nodes that are wanted.
  284. * @returns {Promise.<array|Error>} An array of nodes if found fulfilled or null if not found fulfilled, or error if the ids are invalid or some neo4j error if rejected.
  285. */
  286. static manyWithIds(ids) {
  287. try {
  288. let operation = this.manyWithIdsOperation(ids);
  289. return OGMNeoOperationExecuter.execute(operation);
  290. } catch (error) {
  291. return Promise.reject(error);
  292. }
  293. }
  294. /**
  295. * Operation to retrive nodes with ids.
  296. *
  297. * @static
  298. * @param {array} ids - The ids of nodes that are wanted.
  299. * @returns {OGMNeoOperation} Operation that query the nodes with the ids.
  300. * @throws {Error} Will throw an error if you don't provide any valid id to retrive.
  301. * @throws {Error} Will throw an error if the ids are not an array.
  302. */
  303. static manyWithIdsOperation(ids) {
  304. if (_.isArray(ids)) {
  305. let validIds = ids.filter(id => _.isInteger(id));
  306. if (_.isEmpty(validIds)) {
  307. throw new Error('You must provide at least one valid(integer) id to query');
  308. } else {
  309. let idsQuery = validIds.reduce((result, current) => {
  310. return result + ((result === '') ? '' : ',') + ` ${current}`;
  311. }, '');
  312. let cypher = `MATCH (n) WHERE ID(n) IN [${idsQuery}] RETURN n`;
  313. return OGMNeoOperationBuilder.create()
  314. .cypher(cypher)
  315. .type(OGMNeoOperation.READ)
  316. .then((result) => {
  317. return result.records.map(record => OGMNeoObjectParse.parseRecordNode(record, 'n'));
  318. }).build();
  319. }
  320. } else {
  321. throw new Error('The parameter must be an array of ids');
  322. }
  323. }
  324. /**
  325. * Count of nodes with the label.
  326. *
  327. * @static
  328. * @param {string} label - The label of nodes that have to be counted.
  329. * @returns {Promise.<integer|Error>} Count of nodes if fulfilled, some neo4j error if rejected.
  330. */
  331. static countWithLabel(label) {
  332. return this.count(new OGMNeoQuery(label));
  333. }
  334. /**
  335. * Count of nodes with the query.
  336. *
  337. * @static
  338. * @param {OGMNeoQuery} query - The query to filter nodes that have to be counted.
  339. * @returns {Promise.<integer|Error>} Count of nodes if fulfilled, some neo4j error if rejected.
  340. */
  341. static count(query) {
  342. try {
  343. let operation = this.countOperation(query);
  344. return OGMNeoOperationExecuter.execute(operation);
  345. } catch (error) {
  346. return Promise.reject(error);
  347. }
  348. }
  349. /**
  350. * Creates an operation count of nodes with a query object.
  351. *
  352. * @static
  353. * @param {OGMNeoQuery} query - The query to filter nodes that have to be counted.
  354. * @returns {OGMNeoOperation} Operation that query the count of the nodes with query.
  355. * @throws {Error} Will throw an error if the query was not a instance of ogmneo.Query.
  356. */
  357. static countOperation(query) {
  358. if (query && query instanceof OGMNeoQuery) {
  359. let cypher = query.countCypher();
  360. return OGMNeoOperationBuilder.create()
  361. .cypher(cypher)
  362. .type(OGMNeoOperation.READ)
  363. .then((result) => {
  364. let record = _.first(result.records);
  365. return (record != null) ? record.get('count').low : 0;
  366. }).build();
  367. } else {
  368. throw new Error('A OGMNeoQuery object must to be provided');
  369. }
  370. }
  371. /**
  372. * Find nodes filtered by query parameter.
  373. *
  374. * @static
  375. * @param {OGMNeoQuery} query - The query to filter nodes that have to be returned.
  376. * @returns {Promise.<array|Error>} Nodes if fulfilled, some neo4j error if rejected.
  377. */
  378. static find(query) {
  379. try {
  380. let operation = this.findOperation(query);
  381. return OGMNeoOperationExecuter.execute(operation);
  382. } catch (error) {
  383. return Promise.reject(error);
  384. }
  385. }
  386. /**
  387. * Operation for find nodes filtered by the query parameter.
  388. *
  389. * @static
  390. * @param {OGMNeoQuery} query - The query to filter nodes that have to be returned.
  391. * @returns {OGMNeoOperation} Operation that returns the nodes with query.
  392. * @throws {Error} Will throw an error if the query was not a instance of ogmneo.Query.
  393. */
  394. static findOperation(query) {
  395. if (query && query instanceof OGMNeoQuery) {
  396. let cypher = query.queryCypher();
  397. return OGMNeoOperationBuilder.create()
  398. .cypher(cypher)
  399. .type(OGMNeoOperation.READ)
  400. .then((result) => {
  401. return result.records.map((record) => OGMNeoObjectParse.parseRecordNode(record, 'n'));
  402. }).build();
  403. } else {
  404. throw new Error('A OGMNeoQuery object must to be provided');
  405. }
  406. }
  407. /**
  408. * Find one node filtered by query parameter. Will return the first node that it finds.
  409. *
  410. * @static
  411. * @param {OGMNeoQuery} query - The query to filter nodes that have to be returned.
  412. * @returns {Promise.<object|Error>} Node found if fulfilled, some neo4j error if rejected.
  413. */
  414. static findOne(query) {
  415. try {
  416. let operation = this.findOneOperation(query);
  417. return OGMNeoOperationExecuter.execute(operation);
  418. } catch (error) {
  419. return Promise.reject(error);
  420. }
  421. }
  422. /**
  423. * Operation that find one node filtered by query parameter.
  424. *
  425. * @static
  426. * @param {OGMNeoQuery} query The query to filter nodes that have to be returned.
  427. * @returns {OGMNeoOperation} Operation that returns the node with query.
  428. * @throws {Error} Will throw an error if the query was not a instance of ogmneo.Query.
  429. */
  430. static findOneOperation(query) {
  431. if (query && query instanceof OGMNeoQuery) {
  432. query.limit(1);
  433. return OGMNeoOperationBuilder.create()
  434. .cypher(query.queryCypher())
  435. .type(OGMNeoOperation.READ)
  436. .then((result) => {
  437. let record = _.first(result.records);
  438. return (record != null) ? OGMNeoObjectParse.parseRecordNode(record, 'n') : null;
  439. }).build();
  440. } else {
  441. throw new Error('A OGMNeoQuery object must to be provided');
  442. }
  443. }
  444. /**
  445. * Adding label to a node.
  446. *
  447. * @static
  448. * @param {string} label - The label to be added to the node.
  449. * @param {integer} nodeId - The id of the node to add the label.
  450. * @returns {Promise.<object|Error>} Node(if node exists) or null(if not exists) if fulfilled, some error if rejected.
  451. */
  452. static addLabelToNode(label, nodeId) {
  453. try {
  454. let operation = this.addLabelToNodeOperation(label, nodeId);
  455. return OGMNeoOperationExecuter.execute(operation);
  456. } catch (error) {
  457. return Promise.reject(error);
  458. }
  459. }
  460. /**
  461. * Operation to add a label to a node.
  462. *
  463. * @static
  464. * @param {string} label - The label to be added to the node.
  465. * @param {integer} nodeId - The id of the node to add the label.
  466. * @returns {OGMNeoOperation} Operation that adds a label.
  467. * @throws {Error} Will throw an error if the nodeId was not an integer value.
  468. * @throws {Error} Will throw an error if the label was anything diferent than an non-empty string.
  469. */
  470. static addLabelToNodeOperation(label, nodeId) {
  471. if (_.isInteger(nodeId)) {
  472. let operation = this.addLabelToNodesOperation(label, [nodeId]);
  473. operation.then = (result) => {
  474. let record = _.first(result.records);
  475. return (record != null) ? OGMNeoObjectParse.parseRecordNode(record, 'n') : null;
  476. };
  477. return operation;
  478. } else {
  479. throw new Error('The nodeId must be an integer value');
  480. }
  481. }
  482. /**
  483. * Remove label from a node.
  484. *
  485. * @static
  486. * @param {string} label - The label to be removed from the node.
  487. * @param {integer} nodeId - The id of the node to remove the label from.
  488. * @returns {Promise.<object|Error>} Node(if node exists) or null(if not exists) if fulfilled, some error if rejected.
  489. */
  490. static removeLabelFromNode(label, nodeId) {
  491. try {
  492. let operation = this.removeLabelFromNodeOperation(label, nodeId);
  493. return OGMNeoOperationExecuter.execute(operation);
  494. } catch (error) {
  495. return Promise.reject(error);
  496. }
  497. }
  498. /**
  499. * Operation to remove a label from a node.
  500. *
  501. * @static
  502. * @param {string} label - The label to be removed from the node.
  503. * @param {integer} nodeId - The id of the node to remove the label from.
  504. * @returns {OGMNeoOperation} Operation that removes a label.
  505. * @throws {Error} Will throw an error if the nodeId was not an integer value.
  506. * @throws {Error} Will throw an error if the label was anything diferent than an non-empty string.
  507. */
  508. static removeLabelFromNodeOperation(label, nodeId) {
  509. if (_.isInteger(nodeId)) {
  510. let operation = this.removeLabelFromNodesOperation(label, [nodeId]);
  511. operation.then = (result) => {
  512. let record = _.first(result.records);
  513. return (record != null) ? OGMNeoObjectParse.parseRecordNode(record, 'n') : null;
  514. };
  515. return operation;
  516. } else {
  517. throw new Error('The nodeId must be an integer value');
  518. }
  519. }
  520. /**
  521. * Adding label to nodes.
  522. *
  523. * @static
  524. * @param {string} label - The label to be added to the node.
  525. * @param {array} nodesIds - The ids of the nodes to add the label.
  526. * @returns {Promise<array|Error>} Nodes(if nodes exists) or null(if not exists) if fulfilled, some error if rejected.
  527. */
  528. static addLabelToNodes(label, nodesIds) {
  529. try {
  530. let operation = this.addLabelToNodesOperation(label, nodesIds);
  531. return OGMNeoOperationExecuter.execute(operation);
  532. } catch (error) {
  533. return Promise.reject(error);
  534. }
  535. }
  536. /**
  537. * Operation that adds a label to nodes.
  538. *
  539. * @static
  540. * @param {string} label - The label to be added to the node.
  541. * @param {array} nodesIds - The ids of the nodes to add the label.
  542. * @returns {OGMNeoOperation} Operation that removes a label.
  543. * @throws {Error} Will throw an error if you don't provide at least one valid id to this operation.
  544. * @throws {Error} Will throw an error if the label was anything diferent than an non-empty string.
  545. */
  546. static addLabelToNodesOperation(label, nodesIds) {
  547. if (_.isString(label) && !_.isEmpty(label)) {
  548. let params = this._validateAndBuildParams(nodesIds);
  549. if (params != null) {
  550. let cypher = `MATCH (n) WHERE ID(n) IN ${params} SET n:${label} RETURN n`;
  551. return OGMNeoOperationBuilder
  552. .create()
  553. .cypher(cypher)
  554. .type(OGMNeoOperation.WRITE)
  555. .then((result) => {
  556. return result.records.map(record => OGMNeoObjectParse.parseRecordNode(record, 'n'));
  557. }).build();
  558. } else {
  559. throw new Error('You must provide at least one valid id to this operation');
  560. }
  561. } else {
  562. throw new Error('label must be a non empty string');
  563. }
  564. }
  565. /**
  566. * Remove label from nodes.
  567. *
  568. * @static
  569. * @param {string} label - The label to be removed from the nodes.
  570. * @param {array} nodeIds - The ids of the nodes to remove the label from.
  571. * @returns {Promise.<array|Error>} Nodes(if nodes exists) or null(if not exists) if fulfilled, some error if rejected.
  572. */
  573. static removeLabelFromNodes(label, nodesIds) {
  574. try {
  575. let operation = this.removeLabelFromNodesOperation(label, nodesIds);
  576. return OGMNeoOperationExecuter.execute(operation);
  577. } catch (error) {
  578. return Promise.reject(error);
  579. }
  580. }
  581. /**
  582. * Operation that removes a label from nodes.
  583. *
  584. * @static
  585. * @param {string} label - The label to be removed from the nodes.
  586. * @param {array} nodeIds - The ids of the nodes to remove the label from.
  587. * @returns {OGMNeoOperation} Operation that removes a label from many nodes.
  588. * @throws {Error} Will throw an error if you don't provide at least one valid id to this operation.
  589. * @throws {Error} Will throw an error if the label was anything diferent than an non-empty string.
  590. */
  591. static removeLabelFromNodesOperation(label, nodesIds) {
  592. if (_.isString(label) && !_.isEmpty(label)) {
  593. let params = this._validateAndBuildParams(nodesIds);
  594. if (params) {
  595. let cypher = `MATCH (n:${label}) WHERE ID(n) IN ${params} REMOVE n:${label} RETURN n`;
  596. return OGMNeoOperationBuilder
  597. .create()
  598. .cypher(cypher)
  599. .type(OGMNeoOperation.WRITE)
  600. .then((result) => {
  601. return result.records.map(record => OGMNeoObjectParse.parseRecordNode(record, 'n'));
  602. }).build();
  603. } else {
  604. throw new Error('You must provide at least one valid id to this operation');
  605. }
  606. } else {
  607. throw new Error('label must be a non empty string');
  608. }
  609. }
  610. static _validateAndBuildParams(nodesIds) {
  611. if (_.isArray(nodesIds)) {
  612. let validIds = nodesIds.filter(id => _.isInteger(id));
  613. if (_.isEmpty(validIds)) {
  614. return null;
  615. } else {
  616. let parameters = validIds.reduce((result, current) => {
  617. return result + `${(result === '') ? '' : ','} ${current}`;
  618. }, '');
  619. return `[${parameters}]`;
  620. }
  621. } else {
  622. throw new Error('nodesIds must be an array');
  623. }
  624. }
  625. }
  626. module.exports = OGMNeoNode;