From ec5d6da7beb7e19e6fb13265e172b9ece6c753e4 Mon Sep 17 00:00:00 2001 From: Yuval Naveh Date: Mon, 20 Jul 2020 23:20:08 -0400 Subject: [PATCH 1/4] Added an external test application --- .vscode/launch.json | 8 ++ test-jay-gee-eff/.gitignore | 1 + test-jay-gee-eff/.vscode/launch.json | 14 +++ test-jay-gee-eff/index.js | 47 ++++++++ test-jay-gee-eff/package-lock.json | 153 +++++++++++++++++++++++++++ test-jay-gee-eff/package.json | 17 +++ 6 files changed, 240 insertions(+) create mode 100644 test-jay-gee-eff/.gitignore create mode 100644 test-jay-gee-eff/.vscode/launch.json create mode 100644 test-jay-gee-eff/index.js create mode 100644 test-jay-gee-eff/package-lock.json create mode 100644 test-jay-gee-eff/package.json diff --git a/.vscode/launch.json b/.vscode/launch.json index 8f601b5..336a998 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,6 +19,14 @@ "name": "Run NBA graph demo", "args": [], "program": "${workspaceFolder}/demo/nba-demo.js" + }, + { + "type": "node", + "request": "launch", + "name": "Run external module tester", + "cwd": "${workspaceFolder}/test-jay-gee-eff", + "args": [], + "program": "${workspaceFolder}/test-jay-gee-eff/index.js" } ] } \ No newline at end of file diff --git a/test-jay-gee-eff/.gitignore b/test-jay-gee-eff/.gitignore new file mode 100644 index 0000000..6caf68a --- /dev/null +++ b/test-jay-gee-eff/.gitignore @@ -0,0 +1 @@ +output \ No newline at end of file diff --git a/test-jay-gee-eff/.vscode/launch.json b/test-jay-gee-eff/.vscode/launch.json new file mode 100644 index 0000000..58f56b1 --- /dev/null +++ b/test-jay-gee-eff/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}\\index.js" + } + ] +} \ No newline at end of file diff --git a/test-jay-gee-eff/index.js b/test-jay-gee-eff/index.js new file mode 100644 index 0000000..5a4ce8e --- /dev/null +++ b/test-jay-gee-eff/index.js @@ -0,0 +1,47 @@ +/* eslint-disable no-console */ +const { JGFContainer } = require('jay-gee-eff'); +const path = require('path'); + +const program = async () => { + // eslint-disable-next-line global-require + const { version: moduleVersion } = require('./node_modules/jay-gee-eff/package.json'); + console.log(`jay-gee-eff, version: ${moduleVersion}`); + console.log('------------------------------------'); + + console.log('Building the NBA JGF Graph...'); + const container = new JGFContainer(true); + const { graph } = container; + graph.type = 'sports'; + graph.label = 'NBA Demo Graph'; + + const node1Id = 'LeBron James'; + const node1Label = 'NBAPlayer'; + + const node2Id = 'LA Lakers'; + const node2Label = 'NBATeam'; + + const playerContractLabel = 'Plays for'; + + console.log('Adding two nodes...'); + graph.addNode(node1Id, node1Label); + graph.addNode(node2Id, node2Label); + + console.log('Adding an edge...'); + graph.addEdge(node1Id, node2Id, playerContractLabel); + + const filename = path.join(path.dirname(__filename), 'output/nba-graph.json'); + console.log(`Saving to file -> ${filename}`); + await container.saveToFile(filename, true); + + console.log('Loading saved file...'); + const container2 = new JGFContainer(true); + + await container2.loadFromFile('output/nba-graph.json'); + console.log(`Container loaded, container2: Nodes = ${Object.keys(container2.graph.nodes).length}`); + + console.log('-- DONE --'); +}; + +(async () => { + await program(); +})(); diff --git a/test-jay-gee-eff/package-lock.json b/test-jay-gee-eff/package-lock.json new file mode 100644 index 0000000..c4dd3c5 --- /dev/null +++ b/test-jay-gee-eff/package-lock.json @@ -0,0 +1,153 @@ +{ + "name": "test-jay-gee-eff", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "at-least-node": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", + "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==" + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "check-types": { + "version": "11.1.2", + "resolved": "https://registry.npmjs.org/check-types/-/check-types-11.1.2.tgz", + "integrity": "sha512-tzWzvgePgLORb9/3a0YenggReLKAIb2owL03H2Xdoe5pKcUyWRSEQ8xfCar8t2SIAuEDwtmx2da1YB52YuHQMQ==" + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "fast-clone": { + "version": "1.5.13", + "resolved": "https://registry.npmjs.org/fast-clone/-/fast-clone-1.5.13.tgz", + "integrity": "sha512-0ez7coyFBQFjZtId+RJqJ+EQs61w9xARfqjqK0AD9vIUkSxWD4HvPt80+5evebZ1tTnv1GYKrPTipx7kOW5ipA==" + }, + "fs-extra": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz", + "integrity": "sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==", + "requires": { + "at-least-node": "^1.0.0", + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^1.0.0" + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "graceful-fs": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", + "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==" + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "jay-gee-eff": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/jay-gee-eff/-/jay-gee-eff-2.1.0.tgz", + "integrity": "sha512-H8IWAW8zz7t786wJ5Orz1zLowXl/Ct5xTAlbhOmrYzKHDd8k7W88O5Jmmr/mOybJzV/3aWLRYkscaS2vwzTifw==", + "requires": { + "check-types": "^11.1.2", + "fast-clone": "^1.5.13", + "fs-extra": "^9.0.1", + "glob": "^7.1.6", + "jsonschema": "^1.2.6", + "lodash": "^4.17.19" + } + }, + "jsonfile": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.0.1.tgz", + "integrity": "sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^1.0.0" + } + }, + "jsonschema": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/jsonschema/-/jsonschema-1.2.6.tgz", + "integrity": "sha512-SqhURKZG07JyKKeo/ir24QnS4/BV7a6gQy93bUSe4lUdNp0QNpIz2c9elWJQ9dpc5cQYY6cvCzgRwy0MQCLyqA==" + }, + "lodash": { + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", + "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==" + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "universalify": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz", + "integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==" + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + } + } +} diff --git a/test-jay-gee-eff/package.json b/test-jay-gee-eff/package.json new file mode 100644 index 0000000..0b8e24f --- /dev/null +++ b/test-jay-gee-eff/package.json @@ -0,0 +1,17 @@ +{ + "name": "test-jay-gee-eff", + "description": "Tester for jay-gee-eff npm external module", + "version": "1.0.0", + "main": "index.js", + "private": true, + "scripts": { + "start": "node index.js", + "test": "node index.js" + }, + "keywords": [], + "author": "Bigman73", + "license": "ISC", + "dependencies": { + "jay-gee-eff": "^2.1.0" + } +} From f788f85ba94f43f23c492a5e490bf0df0d9a3044 Mon Sep 17 00:00:00 2001 From: Yuval Naveh Date: Tue, 21 Jul 2020 00:07:46 -0400 Subject: [PATCH 2/4] Added eslint jsdoc enforcement Fixed all eslint issues --- .eslintrc.json | 6 ++++- CHANGELOG.md | 7 +++++- package-lock.json | 52 ++++++++++++++++++++++++++++++++++++++- package.json | 3 ++- src/common.js | 1 + src/jgfContainer.js | 16 ++++++++++-- src/jgfGraph.js | 37 +++++++++++++++++++++++----- src/misc.js | 1 + test-jay-gee-eff/index.js | 4 +++ 9 files changed, 115 insertions(+), 12 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index f59fc82..2484e39 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,7 +6,11 @@ "mocha": true }, "extends": [ - "airbnb-base" + "airbnb-base", + "plugin:jsdoc/recommended" + ], + "plugins": [ + "jsdoc" ], "globals": { "Atomics": "readonly", diff --git a/CHANGELOG.md b/CHANGELOG.md index e4421fe..8be0264 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,12 @@ All notable changes to this project will be documented in this file. ## [Released] -## [2.1.0] - TBD +## [2.2.0] - 2020-07-26 +- Added eslint jsdoc enforcement +- Fixed all eslint issues +- Added: Test application that uses the npm module (also a demo app) + +## [2.1.0] - 2020-07-19 - Refactor code in src folder - Add support for legacy v1 schema, loadFromFileV1 - Fixed: Added missing jgfSchemaV1.json, jgfSchemaV2.json to package diff --git a/package-lock.json b/package-lock.json index 2979fb6..5b629c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "jay-gee-eff", - "version": "2.1.0", + "version": "2.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -352,6 +352,12 @@ "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, + "comment-parser": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-0.7.5.tgz", + "integrity": "sha512-iH9YA35ccw94nx5244GVkpyC9eVTsL71jZz6iz5w6RIf79JLF2AsXHXq9p6Oaohyl3sx5qSMnGsWUDFIAfWL4w==", + "dev": true + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -648,6 +654,38 @@ } } }, + "eslint-plugin-jsdoc": { + "version": "30.0.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-30.0.3.tgz", + "integrity": "sha512-EviSu0Hgc9Bhz00WhA6829KYC9BaP6JWoycOTA1xFxjQ/2XguRlB3r6nGNA/jkmMDQp5dTQ22s1kAJIaC+dE8Q==", + "dev": true, + "requires": { + "comment-parser": "^0.7.5", + "debug": "^4.1.1", + "jsdoctypeparser": "^8.0.0", + "lodash": "^4.17.15", + "regextras": "^0.7.1", + "semver": "^7.3.2", + "spdx-expression-parse": "^3.0.1" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, "eslint-scope": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.0.tgz", @@ -1115,6 +1153,12 @@ "esprima": "^4.0.0" } }, + "jsdoctypeparser": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/jsdoctypeparser/-/jsdoctypeparser-8.0.0.tgz", + "integrity": "sha512-eLCs6s4JqN8TjFJfgdiLHRvogLhOAJz+5RIA2FtoMe6ZDyuvghvppnlIToqAEnVbxRqLMrfnNXpW8FpmR6IMBw==", + "dev": true + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -1637,6 +1681,12 @@ "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==", "dev": true }, + "regextras": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/regextras/-/regextras-0.7.1.tgz", + "integrity": "sha512-9YXf6xtW+qzQ+hcMQXx95MOvfqXFgsKDZodX3qZB0x2n5Z94ioetIITsBtvJbiOyxa/6s9AtyweBLCdPmPko/w==", + "dev": true + }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", diff --git a/package.json b/package.json index df45382..7d57248 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jay-gee-eff", - "version": "2.1.0", + "version": "2.2.0", "description": "JGF - JSON Graph Format manipulation module. Reads and writes JGF files.", "main": "index.js", "files": [ @@ -45,6 +45,7 @@ "eslint": "^7.5.0", "eslint-config-airbnb-base": "^14.2.0", "eslint-plugin-import": "^2.22.0", + "eslint-plugin-jsdoc": "^30.0.3", "mocha": "^8.0.1" }, "dependencies": { diff --git a/src/common.js b/src/common.js index 73a3cde..7a7ace2 100644 --- a/src/common.js +++ b/src/common.js @@ -5,6 +5,7 @@ const fastClone = require('fast-clone'); * Clones an object (using fast clone) * * @param {object} obj source object o clone + * @returns {object} cloned object */ const cloneObject = (obj) => fastClone(obj); diff --git a/src/jgfContainer.js b/src/jgfContainer.js index 13d65d9..6f9c6f8 100644 --- a/src/jgfContainer.js +++ b/src/jgfContainer.js @@ -33,7 +33,8 @@ const readJGFSchemaV2 = async () => { class JGFContainer { /** * Constructor - * @param {*} singleGraph true for single-graph mode, false for multi-graph mode + * + * @param {boolean} singleGraph true for single-graph mode, false for multi-graph mode */ constructor(singleGraph = true) { this.JGFSchemaValidator = new Validator(); @@ -47,6 +48,8 @@ class JGFContainer { /** * Returns all graphs, in Multi-Graph mode + * + * @returns {Array} List of graphs */ get graphs() { if (this.isSingleGraph) { @@ -58,6 +61,8 @@ class JGFContainer { /** * Returns the graph, in Single-Graph mode + * + * @returns {object} The single graph */ get graph() { if (!this.isSingleGraph) { @@ -68,7 +73,9 @@ class JGFContainer { } /** - * Returns true if the container is in Multi-Graph mode + * Multi-Graph mode flag + * + * @returns {boolean} Returns true if the container is in Multi-Graph mode, otherwise false */ get isMultiGraph() { return !this.isSingleGraph; @@ -76,6 +83,8 @@ class JGFContainer { /** * Adds an empty graph + * + * @returns {object} Empty graph */ addEmptyGraph() { const graph = new JGFGraph(); @@ -167,6 +176,8 @@ class JGFContainer { * Loads multiple partial graph files into a single merged in-memory graph * * @param {string} filenameWildcard pattern to use for partial JGF files + * @param {string} type Graph type + * @param {string} label Graph label */ async loadFromPartialFiles(filenameWildcard, type, label) { try { @@ -240,6 +251,7 @@ class JGFContainer { * Saves the in memory JSON graph into a JGF file * * @param {string} filename JGF filename + * @param {boolean} prettyPrint true to output a easy to read JSON, false for a compact JSON */ async saveToFile(filename, prettyPrint = false) { try { diff --git a/src/jgfGraph.js b/src/jgfGraph.js index 328ab43..042afee 100644 --- a/src/jgfGraph.js +++ b/src/jgfGraph.js @@ -15,6 +15,7 @@ class JGFGraph { * @param {string} type graph classification * @param {string} label a text display for the graph * @param {boolean} directed true for a directed graph, false for an undirected graph + * @param {object} metadata Graph meta data attributes */ constructor(id = '', type = '', label = '', directed = true, metadata = null) { this.validator = new Validator(); @@ -68,6 +69,8 @@ class JGFGraph { /** * Returns the isPartial flag + * + * @returns {boolean} true if partial graph, otherwise false */ get isPartial() { return this._isPartial; @@ -82,6 +85,8 @@ class JGFGraph { /** * Returns the graph id + * + * @returns {string} graph id */ get id() { return this._id; @@ -96,6 +101,8 @@ class JGFGraph { /** * Returns the graph type + * + * @returns {string} Graph type */ get type() { return this._type; @@ -110,6 +117,8 @@ class JGFGraph { /** * Returns the graph label + * + * @returns {string} Graph label */ get label() { return this._label; @@ -124,6 +133,8 @@ class JGFGraph { /** * Returns the graph meta data + * + * @returns {object} Graph meta data attribute */ get metadata() { return this._metadata; @@ -138,6 +149,8 @@ class JGFGraph { /** * Returns all nodes + * + * @returns {Array} List of all nodes */ get nodes() { return cloneObject(this._nodes); @@ -145,6 +158,8 @@ class JGFGraph { /** * Returns all edges + * + * @returns {Array} List of all edges */ get edges() { return cloneObject(this._edges); @@ -152,6 +167,8 @@ class JGFGraph { /** * Returns the graph as JGF Json + * + * @returns {object} Graph as JGF JSON object */ get json() { const json = { @@ -192,6 +209,7 @@ class JGFGraph { * * @param {string} id Node id * @param {string} label Node label + * @param {object} metadata Node meta data attributes */ addNode(id, label, metadata = null) { if (id in this._nodes) { @@ -212,7 +230,7 @@ class JGFGraph { /** * Adds multiple nodes, for legacy V1 JGF Schema * - * @param {*} nodes A collection of JGF node objects + * @param {Array} nodes A collection of JGF node objects */ addNodesV1(nodes) { for (const node of nodes) { @@ -227,7 +245,7 @@ class JGFGraph { /** * Adds multiple nodes * - * @param {*} nodes A collection of JGF node objects + * @param {Array} nodes A collection of JGF node objects */ addNodes(nodes) { for (const [nodeId, node] of Object.entries(nodes)) { @@ -244,7 +262,7 @@ class JGFGraph { * * @param {string} nodeId Node id * @param {string} label Updated node label - * @param {object} metadata Updated node meta data + * @param {object} metadata Updated node meta data attributes */ updateNode(nodeId, label, metadata = null) { if (!(nodeId in this._nodes)) { @@ -279,6 +297,7 @@ class JGFGraph { * Lookup a node by a node id * * @param {string} nodeId Unique node id + * @returns {object} Graph node */ getNode(nodeId) { if (!(nodeId in this._nodes)) { @@ -345,6 +364,7 @@ class JGFGraph { /** * Adds multiple edges + * * @param {*} edges A collection of JGF edge objects */ addEdges(edges) { @@ -361,6 +381,7 @@ class JGFGraph { /** * Removes existing graph edges + * * @param {string} source Source node id * @param {string} target Target node id * @param {string} relation Specific edge relation type to remove. @@ -374,9 +395,11 @@ class JGFGraph { /** * Get edges between source node and target node, with an optional edge relation - * @param {string} source - * @param {string} target - * @param {string} relation + * + * @param {string} source Node source id + * @param {string} target Node target id + * @param {string} relation Relationship name + * @returns {Array} List of matching edges */ getEdges(source, target, relation = '') { if (!this.isPartial) { @@ -398,6 +421,8 @@ class JGFGraph { /** * Returns the graph dimensions - Number of nodes and edges + * + * @returns {object} Graph dimensions */ get graphDimensions() { const dimensions = { diff --git a/src/misc.js b/src/misc.js index 7f92939..f6c9f21 100644 --- a/src/misc.js +++ b/src/misc.js @@ -4,6 +4,7 @@ const glob = require('glob'); * Returns all files matching the wild card pattern * * @param {string} filenameWildcard filename wildcard pattern + * @returns {Array} list of files */ const getMatchingFiles = (filenameWildcard) => new Promise((resolve, reject) => { glob(filenameWildcard, (err, files) => { diff --git a/test-jay-gee-eff/index.js b/test-jay-gee-eff/index.js index 5a4ce8e..befd851 100644 --- a/test-jay-gee-eff/index.js +++ b/test-jay-gee-eff/index.js @@ -2,6 +2,9 @@ const { JGFContainer } = require('jay-gee-eff'); const path = require('path'); +/** + * Main test program + */ const program = async () => { // eslint-disable-next-line global-require const { version: moduleVersion } = require('./node_modules/jay-gee-eff/package.json'); @@ -13,6 +16,7 @@ const program = async () => { const { graph } = container; graph.type = 'sports'; graph.label = 'NBA Demo Graph'; + graph.id = 'nba'; const node1Id = 'LeBron James'; const node1Label = 'NBAPlayer'; From d791410521933c0c3639d77feef4b47426cf57d9 Mon Sep 17 00:00:00 2001 From: Yuval Naveh Date: Tue, 21 Jul 2020 23:03:15 -0400 Subject: [PATCH 3/4] improved README for loadFromFileV1 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ddbbfcf..5c5ff8c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ A library that provides the following features: 6. Support the JGF v2 Schema ## Important note -The JGF Schema has changed from v1 to v2. v2 is not backward compatible with v1. jay-gee-eff up to version 1.3.1 supported JGF Schema v1. Starting from jay-gee-eff v2 there is support for JGF Schema v2 which is a breaking change. Files generated with jay-gee-eff v1.* would not read properly with jay-gee-eff v2.* +The JGF Schema has changed from v1 to v2. v2 is not backward compatible with v1. jay-gee-eff up to version 1.3.1 supported JGF Schema v1. Starting from jay-gee-eff version 2.0.0 there is support for JGF Schema v2 which is a breaking change. +Files previously generated with jay-gee-eff v1.* can be read with the special function *JGFContainer.loadFromFileV1()* # Installation ``` From 6524248288930cf5bfbd4ad718b1dd92b2a04322 Mon Sep 17 00:00:00 2001 From: Yuval Naveh Date: Tue, 21 Jul 2020 23:06:38 -0400 Subject: [PATCH 4/4] Added latest info to change log --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8be0264..5cab22f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,10 @@ All notable changes to this project will be documented in this file. ## [Released] -## [2.2.0] - 2020-07-26 +## [2.2.0] - 2020-07-21 - Added eslint jsdoc enforcement - Fixed all eslint issues +- Added: loadFromFileV1() function for backward compatibility with files generated with v1 schema - Added: Test application that uses the npm module (also a demo app) ## [2.1.0] - 2020-07-19