Skip to content

Commit 530d043

Browse files
authored
fix #5 - add TS types definitions (#62)
* fix #5 - add TS types definitions * install dev dep in build script * fix build script * add empty line at the end of tsconfig.json
1 parent e8bf88d commit 530d043

20 files changed

+594
-66
lines changed

.circleci/config.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ jobs:
4242
paths:
4343
- node_modules
4444
key: v1-dependencies-{{ checksum "package.json" }}
45-
45+
46+
47+
# generate types
48+
- run: ./node_modules/.bin/tsc
49+
4650
# run tests!
4751
- run: sudo npm install -g istanbul codecov
4852
- run: istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec --exit

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
"redis": "^3.0.2"
1414
},
1515
"devDependencies": {
16-
"mocha": "^7.0.1"
16+
"mocha": "^7.0.1",
17+
"typescript": "^4.1.5"
1718
},
1819
"scripts": {
1920
"test": "mocha --exit"
2021
},
21-
"main": "index.js"
22+
"main": "index.js",
23+
"types": "./types"
2224
}

src/edge.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"use strict";
2-
/**
2+
/*
33
* An edge connecting two nodes.
44
*/
55
class Edge {
66
/**
77
* Builds an Edge object.
88
* @constructor
9-
* @param {Node} srcNode - Source node of the edge.
9+
* @param {import('./node')} srcNode - Source node of the edge.
1010
* @param {string} relation - Relationship type of the edge.
11-
* @param {Node} destNode - Destination node of the edge.
11+
* @param {import('./node')} destNode - Destination node of the edge.
1212
* @param {Map} properties - Properties map of the edge.
1313
*/
1414
constructor(srcNode, relation, destNode, properties) {
@@ -21,7 +21,7 @@ class Edge {
2121

2222
/**
2323
* Sets the edge ID.
24-
* @param {int} id
24+
* @param {number} id (integer)
2525
*/
2626
setId(id) {
2727
this.id = id;

src/graph.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
const redis = require("redis"),
3+
// @ts-ignore
34
util = require("util"),
45
ResultSet = require("./resultSet");
56

@@ -12,9 +13,9 @@ class Graph {
1213
* See: node_redis for more options on createClient
1314
*
1415
* @param {string} graphId the graph id
15-
* @param {string | RedisClient} [host] Redis host or node_redis client
16-
* @param {string | int} [port] Redis port
17-
* @param {ClientOpts} [options] node_redis options
16+
* @param {string | import('redis').RedisClient} [host] Redis host or node_redis client
17+
* @param {string | number} [port] Redis port (integer)
18+
* @param {Object} [options] node_redis options
1819
*/
1920
constructor(graphId, host, port, options) {
2021
this._graphId = graphId; // Graph ID
@@ -42,7 +43,7 @@ class Graph {
4243
/**
4344
* Auxiliary function to extract string(s) data from procedures such as:
4445
* db.labels, db.propertyKeys and db.relationshipTypes
45-
* @param {ResultSet} resultSet - a procedure result set
46+
* @param {import('./resultSet')} resultSet - a procedure result set
4647
* @returns {string[]} strings array.
4748
*/
4849
_extractStrings(resultSet) {
@@ -55,7 +56,7 @@ class Graph {
5556

5657
/**
5758
* Transforms a parameter value to string.
58-
* @param {object} paramValue
59+
* @param {*} paramValue
5960
* @returns {string} the string representation of paramValue.
6061
*/
6162
paramToString(paramValue) {
@@ -100,7 +101,7 @@ class Graph {
100101
* @async
101102
* @param {string} query Cypher query
102103
* @param {Map} [params] Parameters map
103-
* @returns {ResultSet} a promise contains a result set
104+
* @returns {Promise<import('./resultSet')>} a promise contains a result set
104105
*/
105106
async query(query, params) {
106107
if (params) {
@@ -118,7 +119,7 @@ class Graph {
118119
/**
119120
* Deletes the entire graph
120121
* @async
121-
* @returns {ResultSet} a promise contains the delete operation running time statistics
122+
* @returns {Promise<import('./resultSet')>} a promise contains the delete operation running time statistics
122123
*/
123124
async deleteGraph() {
124125
var res = await this._sendCommand("graph.DELETE", [this._graphId]);
@@ -135,7 +136,7 @@ class Graph {
135136
* @param {string} procedure Procedure to call
136137
* @param {string[]} [args] Arguments to pass
137138
* @param {string[]} [y] Yield outputs
138-
* @returns {ResultSet} a promise contains the procedure result set data
139+
* @returns {Promise<import('./resultSet')>} a promise contains the procedure result set data
139140
*/
140141
callProcedure(procedure, args = new Array(), y = new Array()) {
141142
let q = "CALL " + procedure + "(" + args.join(",") + ")" + y.join(" ");
@@ -198,7 +199,7 @@ class Graph {
198199

199200
/**
200201
* Retrieves label by ID.
201-
* @param {int} id internal ID of label.
202+
* @param {number} id internal ID of label. (integer)
202203
* @returns {string} String label.
203204
*/
204205
getLabel(id) {
@@ -208,8 +209,8 @@ class Graph {
208209
/**
209210
* Retrieve all the labels from the graph and returns the wanted label
210211
* @async
211-
* @param {int} id internal ID of label.
212-
* @returns {string} String label.
212+
* @param {number} id internal ID of label. (integer)
213+
* @returns {Promise<string>} String label.
213214
*/
214215
async fetchAndGetLabel(id) {
215216
await this.labels();
@@ -218,8 +219,8 @@ class Graph {
218219

219220
/**
220221
* Retrieves relationship type by ID.
221-
* @param {int} id internal ID of relationship type.
222-
* @return String relationship type.
222+
* @param {number} id internal ID of relationship type. (integer)
223+
* @returns {string} relationship type.
223224
*/
224225
getRelationship(id) {
225226
return this._relationshipTypes[id];
@@ -228,8 +229,8 @@ class Graph {
228229
/**
229230
* Retrieves al the relationships types from the graph, and returns the wanted type
230231
* @async
231-
* @param {int} id internal ID of relationship type.
232-
* @returns {string} String relationship type.
232+
* @param {number} id internal ID of relationship type. (integer)
233+
* @returns {Promise<string>} String relationship type.
233234
*/
234235
async fetchAndGetRelationship(id) {
235236
await this.relationshipTypes();
@@ -238,7 +239,7 @@ class Graph {
238239

239240
/**
240241
* Retrieves property name by ID.
241-
* @param {int} id internal ID of property.
242+
* @param {number} id internal ID of property. (integer)
242243
* @returns {string} String property.
243244
*/
244245
getProperty(id) {
@@ -247,9 +248,9 @@ class Graph {
247248

248249
/**
249250
* Retrieves al the properties from the graph, and returns the wanted property
250-
* @async
251-
* @param {int} id internal ID of property.
252-
* @returns {string} String property.
251+
* @asyncTODO
252+
* @param {number} id internal ID of property. (integer)
253+
* @returns {Promise<string>} String property.
253254
*/
254255
async fetchAndGetProperty(id) {
255256
await this.propertyKeys();

src/label.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"use strict";
22
/**
33
* Different Statistics labels
4+
* @readonly
5+
* @enum {string}
46
*/
57
var Label = Object.freeze({
68
LABELS_ADDED: "Labels added",

src/node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Node {
1717

1818
/**
1919
* Sets the node id.
20-
* @param {int} id
20+
* @param {number} id (integer)
2121
*/
2222
setId(id) {
2323
this.id = id;

src/path.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
class Path {
33
/**
44
* @constructor
5-
* @param {Node[]} nodes - path's node list.
6-
* @param {Edge[]} edges - path's edge list.
5+
* @param {import('./node')[]} nodes - path's node list.
6+
* @param {import('./edge')[]} edges - path's edge list.
77
*/
88
constructor(nodes, edges) {
99
this.nodes = nodes;
@@ -12,65 +12,65 @@ class Path {
1212

1313
/**
1414
* Returns the path's nodes as list.
15-
* @returns {Node[]} path's nodes.
15+
* @returns {import('./node')[]} path's nodes.
1616
*/
1717
get Nodes() {
1818
return this.nodes;
1919
}
2020

2121
/**
2222
* Returns the path's edges as list.
23-
* @returns {Edge[]} paths' edges.
23+
* @returns {import('./edge')[]} paths' edges.
2424
*/
2525
get Edges() {
2626
return this.edges;
2727
}
2828

2929
/**
3030
* Returns a node in a given index.
31-
* @param {int} index
32-
* @returns {Node} node in the given index.
31+
* @param {number} index (integer)
32+
* @returns {import('./node')} node in the given index.
3333
*/
3434
getNode(index) {
3535
return this.nodes[index];
3636
}
3737

3838
/**
3939
* Returns an edge in a given index.
40-
* @param {int} index
41-
* @returns {Edge} edge in a given index.
40+
* @param {number} index (integer)
41+
* @returns {import('./edge')} edge in a given index.
4242
*/
4343
getEdge(index) {
4444
return this.edges[index];
4545
}
4646

4747
/**
4848
* Returns the path's first node.
49-
* @returns {Node} first node.
49+
* @returns {import('./node')} first node.
5050
*/
5151
get firstNode() {
5252
return this.nodes[0];
5353
}
5454

5555
/**
5656
* Returns the last node of the path.
57-
* @returns {Node} last node.
57+
* @returns {import('./node')} last node.
5858
*/
5959
get lastNode() {
6060
return this.nodes[this.nodes.length - 1];
6161
}
6262

6363
/**
6464
* Returns the amount of nodes in th path.
65-
* @returns {int} amount of nodes.
65+
* @returns {number} amount of nodes. (integer)
6666
*/
6767
get nodeCount() {
6868
return this.nodes.length;
6969
}
7070

7171
/**
7272
* Returns the amount of edges in the path.
73-
* @returns {int} amount of edges.
73+
* @returns {number} amount of edges. (integer)
7474
*/
7575
get edgeCount() {
7676
return this.edges.length;

src/record.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Record {
1616

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

3030
/**
3131
* Returns a string representation for the value of the given schema key or in the given position.
32-
* @param {string | int} key
32+
* @param {string | number} key (integer)
3333
* @returns {string} Requested string representation of the value.
3434
*/
3535
getString(key) {
@@ -70,7 +70,7 @@ class Record {
7070
}
7171

7272
/**
73-
* @returns {int} The amount of values in the record.
73+
* @returns {number} The amount of values in the record. (integer)
7474
*/
7575
size() {
7676
return this._header.length;

0 commit comments

Comments
 (0)