Skip to content

fix #5 - add TS types definitions #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ jobs:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}



# generate types
- run: ./node_modules/.bin/tsc

# run tests!
- run: sudo npm install -g istanbul codecov
- run: istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec --exit
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"redis": "^3.0.2"
},
"devDependencies": {
"mocha": "^7.0.1"
"mocha": "^7.0.1",
"typescript": "^4.1.5"
},
"scripts": {
"test": "mocha --exit"
},
"main": "index.js"
"main": "index.js",
"types": "./types"
}
8 changes: 4 additions & 4 deletions src/edge.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use strict";
/**
/*
* An edge connecting two nodes.
*/
class Edge {
/**
* Builds an Edge object.
* @constructor
* @param {Node} srcNode - Source node of the edge.
* @param {import('./node')} srcNode - Source node of the edge.
* @param {string} relation - Relationship type of the edge.
* @param {Node} destNode - Destination node of the edge.
* @param {import('./node')} destNode - Destination node of the edge.
* @param {Map} properties - Properties map of the edge.
*/
constructor(srcNode, relation, destNode, properties) {
Expand All @@ -21,7 +21,7 @@ class Edge {

/**
* Sets the edge ID.
* @param {int} id
* @param {number} id (integer)
*/
setId(id) {
this.id = id;
Expand Down
39 changes: 20 additions & 19 deletions src/graph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
const redis = require("redis"),
// @ts-ignore
util = require("util"),
ResultSet = require("./resultSet");

Expand All @@ -12,9 +13,9 @@ class Graph {
* See: node_redis for more options on createClient
*
* @param {string} graphId the graph id
* @param {string | RedisClient} [host] Redis host or node_redis client
* @param {string | int} [port] Redis port
* @param {ClientOpts} [options] node_redis options
* @param {string | import('redis').RedisClient} [host] Redis host or node_redis client
* @param {string | number} [port] Redis port (integer)
* @param {Object} [options] node_redis options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't import this object to here?

*/
constructor(graphId, host, port, options) {
this._graphId = graphId; // Graph ID
Expand Down Expand Up @@ -42,7 +43,7 @@ class Graph {
/**
* Auxiliary function to extract string(s) data from procedures such as:
* db.labels, db.propertyKeys and db.relationshipTypes
* @param {ResultSet} resultSet - a procedure result set
* @param {import('./resultSet')} resultSet - a procedure result set
* @returns {string[]} strings array.
*/
_extractStrings(resultSet) {
Expand All @@ -55,7 +56,7 @@ class Graph {

/**
* Transforms a parameter value to string.
* @param {object} paramValue
* @param {*} paramValue
* @returns {string} the string representation of paramValue.
*/
paramToString(paramValue) {
Expand Down Expand Up @@ -100,7 +101,7 @@ class Graph {
* @async
* @param {string} query Cypher query
* @param {Map} [params] Parameters map
* @returns {ResultSet} a promise contains a result set
* @returns {Promise<import('./resultSet')>} a promise contains a result set
*/
async query(query, params) {
if (params) {
Expand All @@ -118,7 +119,7 @@ class Graph {
/**
* Deletes the entire graph
* @async
* @returns {ResultSet} a promise contains the delete operation running time statistics
* @returns {Promise<import('./resultSet')>} a promise contains the delete operation running time statistics
*/
async deleteGraph() {
var res = await this._sendCommand("graph.DELETE", [this._graphId]);
Expand All @@ -135,7 +136,7 @@ class Graph {
* @param {string} procedure Procedure to call
* @param {string[]} [args] Arguments to pass
* @param {string[]} [y] Yield outputs
* @returns {ResultSet} a promise contains the procedure result set data
* @returns {Promise<import('./resultSet')>} a promise contains the procedure result set data
*/
callProcedure(procedure, args = new Array(), y = new Array()) {
let q = "CALL " + procedure + "(" + args.join(",") + ")" + y.join(" ");
Expand Down Expand Up @@ -198,7 +199,7 @@ class Graph {

/**
* Retrieves label by ID.
* @param {int} id internal ID of label.
* @param {number} id internal ID of label. (integer)
* @returns {string} String label.
*/
getLabel(id) {
Expand All @@ -208,8 +209,8 @@ class Graph {
/**
* Retrieve all the labels from the graph and returns the wanted label
* @async
* @param {int} id internal ID of label.
* @returns {string} String label.
* @param {number} id internal ID of label. (integer)
* @returns {Promise<string>} String label.
*/
async fetchAndGetLabel(id) {
await this.labels();
Expand All @@ -218,8 +219,8 @@ class Graph {

/**
* Retrieves relationship type by ID.
* @param {int} id internal ID of relationship type.
* @return String relationship type.
* @param {number} id internal ID of relationship type. (integer)
* @returns {string} relationship type.
*/
getRelationship(id) {
return this._relationshipTypes[id];
Expand All @@ -228,8 +229,8 @@ class Graph {
/**
* Retrieves al the relationships types from the graph, and returns the wanted type
* @async
* @param {int} id internal ID of relationship type.
* @returns {string} String relationship type.
* @param {number} id internal ID of relationship type. (integer)
* @returns {Promise<string>} String relationship type.
*/
async fetchAndGetRelationship(id) {
await this.relationshipTypes();
Expand All @@ -238,7 +239,7 @@ class Graph {

/**
* Retrieves property name by ID.
* @param {int} id internal ID of property.
* @param {number} id internal ID of property. (integer)
* @returns {string} String property.
*/
getProperty(id) {
Expand All @@ -247,9 +248,9 @@ class Graph {

/**
* Retrieves al the properties from the graph, and returns the wanted property
* @async
* @param {int} id internal ID of property.
* @returns {string} String property.
* @asyncTODO
* @param {number} id internal ID of property. (integer)
* @returns {Promise<string>} String property.
*/
async fetchAndGetProperty(id) {
await this.propertyKeys();
Expand Down
2 changes: 2 additions & 0 deletions src/label.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";
/**
* Different Statistics labels
* @readonly
* @enum {string}
*/
var Label = Object.freeze({
LABELS_ADDED: "Labels added",
Expand Down
2 changes: 1 addition & 1 deletion src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Node {

/**
* Sets the node id.
* @param {int} id
* @param {number} id (integer)
*/
setId(id) {
this.id = id;
Expand Down
24 changes: 12 additions & 12 deletions src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
class Path {
/**
* @constructor
* @param {Node[]} nodes - path's node list.
* @param {Edge[]} edges - path's edge list.
* @param {import('./node')[]} nodes - path's node list.
* @param {import('./edge')[]} edges - path's edge list.
*/
constructor(nodes, edges) {
this.nodes = nodes;
Expand All @@ -12,65 +12,65 @@ class Path {

/**
* Returns the path's nodes as list.
* @returns {Node[]} path's nodes.
* @returns {import('./node')[]} path's nodes.
*/
get Nodes() {
return this.nodes;
}

/**
* Returns the path's edges as list.
* @returns {Edge[]} paths' edges.
* @returns {import('./edge')[]} paths' edges.
*/
get Edges() {
return this.edges;
}

/**
* Returns a node in a given index.
* @param {int} index
* @returns {Node} node in the given index.
* @param {number} index (integer)
* @returns {import('./node')} node in the given index.
*/
getNode(index) {
return this.nodes[index];
}

/**
* Returns an edge in a given index.
* @param {int} index
* @returns {Edge} edge in a given index.
* @param {number} index (integer)
* @returns {import('./edge')} edge in a given index.
*/
getEdge(index) {
return this.edges[index];
}

/**
* Returns the path's first node.
* @returns {Node} first node.
* @returns {import('./node')} first node.
*/
get firstNode() {
return this.nodes[0];
}

/**
* Returns the last node of the path.
* @returns {Node} last node.
* @returns {import('./node')} last node.
*/
get lastNode() {
return this.nodes[this.nodes.length - 1];
}

/**
* Returns the amount of nodes in th path.
* @returns {int} amount of nodes.
* @returns {number} amount of nodes. (integer)
*/
get nodeCount() {
return this.nodes.length;
}

/**
* Returns the amount of edges in the path.
* @returns {int} amount of edges.
* @returns {number} amount of edges. (integer)
*/
get edgeCount() {
return this.edges.length;
Expand Down
6 changes: 3 additions & 3 deletions src/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Record {

/**
* Returns a value of the given schema key or in the given position.
* @param {string | int} key
* @param {string | number} key (integer)
* @returns {object} Requested value.
*/
get(key) {
Expand All @@ -29,7 +29,7 @@ class Record {

/**
* Returns a string representation for the value of the given schema key or in the given position.
* @param {string | int} key
* @param {string | number} key (integer)
* @returns {string} Requested string representation of the value.
*/
getString(key) {
Expand Down Expand Up @@ -70,7 +70,7 @@ class Record {
}

/**
* @returns {int} The amount of values in the record.
* @returns {number} The amount of values in the record. (integer)
*/
size() {
return this._header.length;
Expand Down
Loading