diff --git a/.circleci/config.yml b/.circleci/config.yml index bf3749fd7c..ef33b03140 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/package.json b/package.json index e097b1a2f6..e001e8a86b 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/src/edge.js b/src/edge.js index ec9a52dc07..da769ffc72 100644 --- a/src/edge.js +++ b/src/edge.js @@ -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) { @@ -21,7 +21,7 @@ class Edge { /** * Sets the edge ID. - * @param {int} id + * @param {number} id (integer) */ setId(id) { this.id = id; diff --git a/src/graph.js b/src/graph.js index 659f778cd5..929bf84c24 100644 --- a/src/graph.js +++ b/src/graph.js @@ -1,5 +1,6 @@ "use strict"; const redis = require("redis"), + // @ts-ignore util = require("util"), ResultSet = require("./resultSet"); @@ -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 */ constructor(graphId, host, port, options) { this._graphId = graphId; // Graph ID @@ -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) { @@ -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) { @@ -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} a promise contains a result set */ async query(query, params) { if (params) { @@ -118,7 +119,7 @@ class Graph { /** * Deletes the entire graph * @async - * @returns {ResultSet} a promise contains the delete operation running time statistics + * @returns {Promise} a promise contains the delete operation running time statistics */ async deleteGraph() { var res = await this._sendCommand("graph.DELETE", [this._graphId]); @@ -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} a promise contains the procedure result set data */ callProcedure(procedure, args = new Array(), y = new Array()) { let q = "CALL " + procedure + "(" + args.join(",") + ")" + y.join(" "); @@ -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) { @@ -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 label. */ async fetchAndGetLabel(id) { await this.labels(); @@ -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]; @@ -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 relationship type. */ async fetchAndGetRelationship(id) { await this.relationshipTypes(); @@ -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) { @@ -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 property. */ async fetchAndGetProperty(id) { await this.propertyKeys(); diff --git a/src/label.js b/src/label.js index af8a41e8fe..fc8d32cd04 100644 --- a/src/label.js +++ b/src/label.js @@ -1,6 +1,8 @@ "use strict"; /** * Different Statistics labels + * @readonly + * @enum {string} */ var Label = Object.freeze({ LABELS_ADDED: "Labels added", diff --git a/src/node.js b/src/node.js index 8b40ba856e..ef17945d13 100644 --- a/src/node.js +++ b/src/node.js @@ -17,7 +17,7 @@ class Node { /** * Sets the node id. - * @param {int} id + * @param {number} id (integer) */ setId(id) { this.id = id; diff --git a/src/path.js b/src/path.js index 1dde85936d..7a7bfc36ef 100644 --- a/src/path.js +++ b/src/path.js @@ -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; @@ -12,7 +12,7 @@ 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; @@ -20,7 +20,7 @@ class Path { /** * Returns the path's edges as list. - * @returns {Edge[]} paths' edges. + * @returns {import('./edge')[]} paths' edges. */ get Edges() { return this.edges; @@ -28,8 +28,8 @@ class Path { /** * 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]; @@ -37,8 +37,8 @@ class Path { /** * 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]; @@ -46,7 +46,7 @@ class Path { /** * Returns the path's first node. - * @returns {Node} first node. + * @returns {import('./node')} first node. */ get firstNode() { return this.nodes[0]; @@ -54,7 +54,7 @@ class Path { /** * 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]; @@ -62,7 +62,7 @@ class Path { /** * 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; @@ -70,7 +70,7 @@ class Path { /** * 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; diff --git a/src/record.js b/src/record.js index ac8f0a7657..d0d5b3da1b 100644 --- a/src/record.js +++ b/src/record.js @@ -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) { @@ -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) { @@ -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; diff --git a/src/resultSet.js b/src/resultSet.js index 8ec5675dd8..d4a830eb64 100644 --- a/src/resultSet.js +++ b/src/resultSet.js @@ -6,6 +6,10 @@ const Statistics = require("./statistics"), Path = require("./path"), ReplyError = require("redis").ReplyError; +/** + * @enum {number} + * @readonly + */ const ResultSetColumnTypes = { COLUMN_UNKNOWN: 0, COLUMN_SCALAR: 1, @@ -13,6 +17,10 @@ const ResultSetColumnTypes = { COLUMN_RELATION: 3, }; +/** + * @enum {number} + * @readonly + */ const ResultSetValueTypes = { VALUE_UNKNOWN: 0, VALUE_NULL: 1, @@ -34,7 +42,7 @@ class ResultSet { /** * Builds an empty ResultSet object. * @constructor - * @param {Graph} graph + * @param {import('./graph')} graph */ constructor(graph) { this._graph = graph; //_graph is graph api @@ -132,7 +140,7 @@ class ResultSet { * Parse raw entity properties representation into a Map * @async * @param {object[]} props raw properties representation - * @returns {Map} Map with the parsed properties. + * @returns {Promise} Map with the parsed properties. */ async parseEntityProperties(props) { // [[name, value, value type] X N] @@ -163,7 +171,7 @@ class ResultSet { * Parse raw node representation into a Node object. * @async * @param {object[]} cell raw node representation. - * @returns {Node} Node object. + * @returns {Promise} Node object. */ async parseNode(cell) { // Node ID (integer), @@ -193,7 +201,7 @@ class ResultSet { * Parse a raw edge representation into an Edge object. * @async * @param {object[]} cell raw edge representation - * @returns {Edge} Edge object. + * @returns {Promise} Edge object. */ async parseEdge(cell) { // Edge ID (integer), @@ -228,7 +236,7 @@ class ResultSet { * Parse and in-place replace raw array into an array of values or objects. * @async * @param {object[]} rawArray raw array representation - * @returns {object[]} Parsed array. + * @returns {Promise} Parsed array. */ async parseArray(rawArray) { for (var i = 0; i < rawArray.length; i++) { @@ -241,7 +249,7 @@ class ResultSet { * Parse a raw path representation into Path object. * @async * @param {object[]} rawPath raw path representation - * @returns {Path} Path object. + * @returns {Promise} Path object. */ async parsePath(rawPath) { let nodes = await this.parseScalar(rawPath[0]); @@ -253,7 +261,7 @@ class ResultSet { * Parse a raw map representation into Map object. * @async * @param {object[]} rawMap raw map representation - * @returns {Map} Map object. + * @returns {Promise} Map object. */ async parseMap(rawMap) { let m = {}; @@ -269,7 +277,7 @@ class ResultSet { * Parse a raw value into its actual value. * @async * @param {object[]} cell raw value representation - * @returns {object} Actual value - scalar, array, Node, Edge, Path + * @returns {Promise} Actual value - scalar, array, Node, Edge, Path */ async parseScalar(cell) { let scalar_type = cell[0]; @@ -349,7 +357,7 @@ class ResultSet { } /** - * @returns {int} Result set size. + * @returns {number} Result set size. (integer) */ size() { return this._resultsCount; diff --git a/src/statistics.js b/src/statistics.js index 98c4c786be..891b5685ec 100644 --- a/src/statistics.js +++ b/src/statistics.js @@ -13,7 +13,7 @@ class Statistics { /** * Returns a statistics value according to the statistics label. - * @param {Label} label - Statistics label. + * @param {import('./label')} label - Statistics label. */ getStringValue(label) { return this.getStatistics()[label]; @@ -21,7 +21,7 @@ class Statistics { /** * Return the query statistics - * @return {Statistics} statistics object + * @return {Object} statistics object */ getStatistics() { if (!this._statistics) { @@ -36,8 +36,8 @@ class Statistics { /** * Returns the integer value of a requested label. - * @param {Label} label - * @returns {int} The actual value if exists, 0 otherwise. + * @param {import('./label')} label + * @returns {number} The actual value if exists, 0 otherwise. (integer) */ getIntValue(label) { let value = this.getStringValue(label); @@ -46,8 +46,8 @@ class Statistics { /** * Returns the float value of a requested label. - * @param {Label} label - * @returns {float} The actual value if exists, 0 otherwise. + * @param {import('./label')} label + * @returns {number} The actual value if exists, 0 otherwise. */ getFloatValue(label) { let value = this.getStringValue(label); @@ -55,56 +55,56 @@ class Statistics { } /** - * @returns {int} The amount of nodes created by th query. + * @returns {number} The amount of nodes created by th query. (integer) */ nodesCreated() { return this.getIntValue(Label.NODES_CREATED); } /** - * @returns {int} The amount of nodes deleted by the query. + * @returns {number} The amount of nodes deleted by the query. (integer) */ nodesDeleted() { return this.getIntValue(Label.NODES_DELETED); } /** - * @returns {int} The amount of labels created by the query. + * @returns {number} The amount of labels created by the query. (integer) */ labelsAdded() { return this.getIntValue(Label.LABELS_ADDED); } /** - * @returns {int} The amount of relationships deleted by the query. + * @returns {number} The amount of relationships deleted by the query. (integer) */ relationshipsDeleted() { return this.getIntValue(Label.RELATIONSHIPS_DELETED); } /** - * @returns {int} The amount of relationships created by the query. + * @returns {number} The amount of relationships created by the query. (integer) */ relationshipsCreated() { return this.getIntValue(Label.RELATIONSHIPS_CREATED); } /** - * @returns {int} The amount of properties set by the query. + * @returns {number} The amount of properties set by the query. (integer) */ propertiesSet() { return this.getIntValue(Label.PROPERTIES_SET); } /** - * @returns {int} The amount of indices created by the query. + * @returns {number} The amount of indices created by the query. (integer) */ indicesCreated() { return this.getIntValue(Label.INDICES_CREATED); } /** - * @returns {int} The amount of indices deleted by the query. + * @returns {number} The amount of indices deleted by the query. (integer) */ indicesDeleted() { return this.getIntValue(Label.INDICES_DELETED); @@ -118,7 +118,7 @@ class Statistics { } /** - * @returns {float} The query execution time in ms. + * @returns {number} The query execution time in ms. */ queryExecutionTime() { return this.getFloatValue(Label.QUERY_INTERNAL_EXECUTION_TIME); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..4de9e88a55 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "files": ["./index.js"], + "compilerOptions": { + "target": "ESNext", + "allowJs": true, + "checkJs": true, + "moduleResolution": "node", + "alwaysStrict": true, + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "./types" + } +} diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000000..1182c7f9a4 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,6 @@ +import Record = require("./src/record"); +import Graph = require("./src/graph"); +import ResultSet = require("./src/resultSet"); +import Statistics = require("./src/statistics"); +import Label = require("./src/label"); +export { Record, Graph, ResultSet, Statistics, Label }; diff --git a/types/src/edge.d.ts b/types/src/edge.d.ts new file mode 100644 index 0000000000..56086f9d0f --- /dev/null +++ b/types/src/edge.d.ts @@ -0,0 +1,26 @@ +export = Edge; +declare class Edge { + /** + * Builds an Edge object. + * @constructor + * @param {import('./node')} srcNode - Source node of the edge. + * @param {string} relation - Relationship type of the edge. + * @param {import('./node')} destNode - Destination node of the edge. + * @param {Map} properties - Properties map of the edge. + */ + constructor(srcNode: import('./node'), relation: string, destNode: import('./node'), properties: Map); + id: number; + relation: string; + srcNode: import("./node"); + destNode: import("./node"); + properties: Map; + /** + * Sets the edge ID. + * @param {number} id (integer) + */ + setId(id: number): void; + /** + * @returns The string representation of the edge. + */ + toString(): string; +} diff --git a/types/src/graph.d.ts b/types/src/graph.d.ts new file mode 100644 index 0000000000..c152c00a2b --- /dev/null +++ b/types/src/graph.d.ts @@ -0,0 +1,124 @@ +export = Graph; +/** + * RedisGraph client + */ +declare class Graph { + /** + * Creates a client to a specific graph running on the specific host/post + * See: node_redis for more options on createClient + * + * @param {string} graphId the graph id + * @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 + */ + constructor(graphId: string, host?: string | import('redis').RedisClient, port?: string | number, options?: any); + _graphId: string; + _labels: any[]; + _relationshipTypes: any[]; + _properties: any[]; + _labelsPromise: Promise; + _propertyPromise: Promise; + _relationshipPromise: Promise; + _client: any; + _sendCommand: any; + /** + * Closes the client. + */ + close(): void; + /** + * Auxiliary function to extract string(s) data from procedures such as: + * db.labels, db.propertyKeys and db.relationshipTypes + * @param {import('./resultSet')} resultSet - a procedure result set + * @returns {string[]} strings array. + */ + _extractStrings(resultSet: import('./resultSet')): string[]; + /** + * Transforms a parameter value to string. + * @param {*} paramValue + * @returns {string} the string representation of paramValue. + */ + paramToString(paramValue: any): string; + /** + * Extracts parameters from dictionary into cypher parameters string. + * @param {Map} params parameters dictionary. + * @return {string} a cypher parameters string. + */ + buildParamsHeader(params: Map): string; + /** + * Execute a Cypher query + * @async + * @param {string} query Cypher query + * @param {Map} [params] Parameters map + * @returns {Promise} a promise contains a result set + */ + query(query: string, params?: Map): Promise; + /** + * Deletes the entire graph + * @async + * @returns {Promise} a promise contains the delete operation running time statistics + */ + deleteGraph(): Promise; + /** + * Calls procedure + * @param {string} procedure Procedure to call + * @param {string[]} [args] Arguments to pass + * @param {string[]} [y] Yield outputs + * @returns {Promise} a promise contains the procedure result set data + */ + callProcedure(procedure: string, args?: string[], y?: string[]): Promise; + /** + * Retrieves all labels in graph. + * @async + */ + labels(): Promise; + /** + * Retrieves all relationship types in graph. + * @async + */ + relationshipTypes(): Promise; + /** + * Retrieves all properties in graph. + * @async + */ + propertyKeys(): Promise; + /** + * Retrieves label by ID. + * @param {number} id internal ID of label. (integer) + * @returns {string} String label. + */ + getLabel(id: number): string; + /** + * Retrieve all the labels from the graph and returns the wanted label + * @async + * @param {number} id internal ID of label. (integer) + * @returns {Promise} String label. + */ + fetchAndGetLabel(id: number): Promise; + /** + * Retrieves relationship type by ID. + * @param {number} id internal ID of relationship type. (integer) + * @returns {string} relationship type. + */ + getRelationship(id: number): string; + /** + * Retrieves al the relationships types from the graph, and returns the wanted type + * @async + * @param {number} id internal ID of relationship type. (integer) + * @returns {Promise} String relationship type. + */ + fetchAndGetRelationship(id: number): Promise; + /** + * Retrieves property name by ID. + * @param {number} id internal ID of property. (integer) + * @returns {string} String property. + */ + getProperty(id: number): string; + /** + * Retrieves al the properties from the graph, and returns the wanted property + * @asyncTODO + * @param {number} id internal ID of property. (integer) + * @returns {Promise} String property. + */ + fetchAndGetProperty(id: number): Promise; +} diff --git a/types/src/label.d.ts b/types/src/label.d.ts new file mode 100644 index 0000000000..5d384947fd --- /dev/null +++ b/types/src/label.d.ts @@ -0,0 +1,22 @@ +export = Label; +/** + * Different Statistics labels + */ +type Label = string; +/** + * Different Statistics labels + * @readonly + * @enum {string} + */ +declare var Label: Readonly<{ + LABELS_ADDED: string; + NODES_CREATED: string; + NODES_DELETED: string; + RELATIONSHIPS_DELETED: string; + PROPERTIES_SET: string; + RELATIONSHIPS_CREATED: string; + INDICES_CREATED: string; + INDICES_DELETED: string; + CACHED_EXECUTION: string; + QUERY_INTERNAL_EXECUTION_TIME: string; +}>; diff --git a/types/src/node.d.ts b/types/src/node.d.ts new file mode 100644 index 0000000000..4115aae93a --- /dev/null +++ b/types/src/node.d.ts @@ -0,0 +1,25 @@ +export = Node; +/** + * A node within the garph. + */ +declare class Node { + /** + * Builds a node object. + * @constructor + * @param {string} label - node label. + * @param {Map} properties - properties map. + */ + constructor(label: string, properties: Map); + id: number; + label: string; + properties: Map; + /** + * Sets the node id. + * @param {number} id (integer) + */ + setId(id: number): void; + /** + * @returns {string} The string representation of the node. + */ + toString(): string; +} diff --git a/types/src/path.d.ts b/types/src/path.d.ts new file mode 100644 index 0000000000..0c54fcb982 --- /dev/null +++ b/types/src/path.d.ts @@ -0,0 +1,58 @@ +export = Path; +declare class Path { + /** + * @constructor + * @param {import('./node')[]} nodes - path's node list. + * @param {import('./edge')[]} edges - path's edge list. + */ + constructor(nodes: import('./node')[], edges: import('./edge')[]); + nodes: import("./node")[]; + edges: import("./edge")[]; + /** + * Returns the path's nodes as list. + * @returns {import('./node')[]} path's nodes. + */ + get Nodes(): import("./node")[]; + /** + * Returns the path's edges as list. + * @returns {import('./edge')[]} paths' edges. + */ + get Edges(): import("./edge")[]; + /** + * Returns a node in a given index. + * @param {number} index (integer) + * @returns {import('./node')} node in the given index. + */ + getNode(index: number): import('./node'); + /** + * Returns an edge in a given index. + * @param {number} index (integer) + * @returns {import('./edge')} edge in a given index. + */ + getEdge(index: number): import('./edge'); + /** + * Returns the path's first node. + * @returns {import('./node')} first node. + */ + get firstNode(): import("./node"); + /** + * Returns the last node of the path. + * @returns {import('./node')} last node. + */ + get lastNode(): import("./node"); + /** + * Returns the amount of nodes in th path. + * @returns {number} amount of nodes. (integer) + */ + get nodeCount(): number; + /** + * Returns the amount of edges in the path. + * @returns {number} amount of edges. (integer) + */ + get edgeCount(): number; + /** + * Returns the path string representation. + * @returns {string} path string representation. + */ + toString(): string; +} diff --git a/types/src/record.d.ts b/types/src/record.d.ts new file mode 100644 index 0000000000..5ac08e3bcd --- /dev/null +++ b/types/src/record.d.ts @@ -0,0 +1,45 @@ +export = Record; +/** + * Hold a query record + */ +declare class Record { + /** + * Builds a Record object + * @constructor + * @param {string[]} header + * @param {object[]} values + */ + constructor(header: string[], values: object[]); + _header: string[]; + _values: any[]; + /** + * Returns a value of the given schema key or in the given position. + * @param {string | number} key (integer) + * @returns {object} Requested value. + */ + get(key: string | number): object; + /** + * Returns a string representation for the value of the given schema key or in the given position. + * @param {string | number} key (integer) + * @returns {string} Requested string representation of the value. + */ + getString(key: string | number): string; + /** + * @returns {string[]} The record header - List of strings. + */ + keys(): string[]; + /** + * @returns {object[]} The record values - List of values. + */ + values(): object[]; + /** + * Returns if the header contains a given key. + * @param {string} key + * @returns {boolean} true if header contains key. + */ + containsKey(key: string): boolean; + /** + * @returns {number} The amount of values in the record. (integer) + */ + size(): number; +} diff --git a/types/src/resultSet.d.ts b/types/src/resultSet.d.ts new file mode 100644 index 0000000000..d9f0434e4c --- /dev/null +++ b/types/src/resultSet.d.ts @@ -0,0 +1,117 @@ +export = ResultSet; +/** + * Hold a query result + */ +declare class ResultSet { + /** + * Builds an empty ResultSet object. + * @constructor + * @param {import('./graph')} graph + */ + constructor(graph: import('./graph')); + _graph: import("./graph"); + _position: number; + _resultsCount: number; + _header: any[]; + _results: any[]; + /** + * Parse raw response data to ResultSet object. + * @async + * @param {object[]} resp - raw response representation - the raw representation of response is at most 3 lists of objects. + * The last list is the statistics list. + */ + parseResponse(resp: object[]): Promise; + _statistics: Statistics; + /** + * Parse a raw response body into header an records. + * @async + * @param {object[]} resp raw response + */ + parseResults(resp: object[]): Promise; + /** + * A raw representation of a header (query response schema) is a list. + * Each entry in the list is a tuple (list of size 2). + * tuple[0] represents the type of the column, and tuple[1] represents the name of the column. + * @param {object[]} rawHeader raw header + */ + parseHeader(rawHeader: object[]): void; + _typelessHeader: any[]; + /** + * The raw representation of response is at most 3 lists of objects. rawResultSet[1] contains the data records. + * Each entry in the record can be either a node, an edge or a scalar + * @async + * @param {object[]} rawResultSet raw result set representation + */ + parseRecords(rawResultSet: object[]): Promise; + /** + * Parse raw entity properties representation into a Map + * @async + * @param {object[]} props raw properties representation + * @returns {Promise} Map with the parsed properties. + */ + parseEntityProperties(props: object[]): Promise; + /** + * Parse raw node representation into a Node object. + * @async + * @param {object[]} cell raw node representation. + * @returns {Promise} Node object. + */ + parseNode(cell: object[]): Promise; + /** + * Parse a raw edge representation into an Edge object. + * @async + * @param {object[]} cell raw edge representation + * @returns {Promise} Edge object. + */ + parseEdge(cell: object[]): Promise; + /** + * Parse and in-place replace raw array into an array of values or objects. + * @async + * @param {object[]} rawArray raw array representation + * @returns {Promise} Parsed array. + */ + parseArray(rawArray: object[]): Promise; + /** + * Parse a raw path representation into Path object. + * @async + * @param {object[]} rawPath raw path representation + * @returns {Promise} Path object. + */ + parsePath(rawPath: object[]): Promise; + /** + * Parse a raw map representation into Map object. + * @async + * @param {object[]} rawMap raw map representation + * @returns {Promise} Map object. + */ + parseMap(rawMap: object[]): Promise; + /** + * Parse a raw value into its actual value. + * @async + * @param {object[]} cell raw value representation + * @returns {Promise} Actual value - scalar, array, Node, Edge, Path + */ + parseScalar(cell: object[]): Promise; + /** + * @returns {string[] }ResultSet's header. + */ + getHeader(): string[]; + /** + * @returns {boolean} If the ResultSet object can return additional records. + */ + hasNext(): boolean; + /** + * @returns {Record} The current record. + */ + next(): Record; + /** + * @returns {Statistics} ResultsSet's statistics. + */ + getStatistics(): Statistics; + /** + * @returns {number} Result set size. (integer) + */ + size(): number; +} +import Statistics = require("./statistics"); +import Record = require("./record"); diff --git a/types/src/statistics.d.ts b/types/src/statistics.d.ts new file mode 100644 index 0000000000..76e51a976f --- /dev/null +++ b/types/src/statistics.d.ts @@ -0,0 +1,75 @@ +export = Statistics; +declare class Statistics { + /** + * Builds a query statistics object out of raw data. + * @constructor + * @param {object[]} raw - raw data. + */ + constructor(raw: object[]); + _raw: any[]; + /** + * Returns a statistics value according to the statistics label. + * @param {import('./label')} label - Statistics label. + */ + getStringValue(label: import('./label')): string; + /** + * Return the query statistics + * @return {Object} statistics object + */ + getStatistics(): { + [x: string]: string; + }; + _statistics: {}; + /** + * Returns the integer value of a requested label. + * @param {import('./label')} label + * @returns {number} The actual value if exists, 0 otherwise. (integer) + */ + getIntValue(label: import('./label')): number; + /** + * Returns the float value of a requested label. + * @param {import('./label')} label + * @returns {number} The actual value if exists, 0 otherwise. + */ + getFloatValue(label: import('./label')): number; + /** + * @returns {number} The amount of nodes created by th query. (integer) + */ + nodesCreated(): number; + /** + * @returns {number} The amount of nodes deleted by the query. (integer) + */ + nodesDeleted(): number; + /** + * @returns {number} The amount of labels created by the query. (integer) + */ + labelsAdded(): number; + /** + * @returns {number} The amount of relationships deleted by the query. (integer) + */ + relationshipsDeleted(): number; + /** + * @returns {number} The amount of relationships created by the query. (integer) + */ + relationshipsCreated(): number; + /** + * @returns {number} The amount of properties set by the query. (integer) + */ + propertiesSet(): number; + /** + * @returns {number} The amount of indices created by the query. (integer) + */ + indicesCreated(): number; + /** + * @returns {number} The amount of indices deleted by the query. (integer) + */ + indicesDeleted(): number; + /** + * @returns {boolean} The execution plan was cached on RedisGraph. + */ + cachedExecution(): boolean; + /** + * @returns {number} The query execution time in ms. + */ + queryExecutionTime(): number; +}