Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
gkorland committed Mar 17, 2024
1 parent 0a19457 commit 9acc1f9
Show file tree
Hide file tree
Showing 8 changed files with 5,783 additions and 139 deletions.
5,706 changes: 5,669 additions & 37 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"falkordb"
],
"devDependencies": {
"@tsconfig/node14": "^14.1.0",
"gh-pages": "^6.0.0",
"release-it": "^16.1.5",
"@types/node": "^20.11.28",
"typescript": "^5.4.2"
},
Expand Down
10 changes: 5 additions & 5 deletions src/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import Node from "./node";
export default class Edge {

private _id: number;
private _relationshipId: number;
private _relationshipType: string;
private _srcNode: Node;
private _destNode: Node;
private _properties: Map<string, any>;

/**
* Builds an Edge object.
* @param {Node} srcNode - Source node of the edge.
* @param {number} relationshipId - Relationship type of the edge.
* @param {string} relationshipType - Relationship type of the edge.
* @param {Node} destNode - Destination node of the edge.
* @param {Map} properties - Properties map of the edge.
*/
constructor(id: number, srcNode: Node, relationshipId: number, destNode: Node, properties: Map<string, any>) {
constructor(id: number, srcNode: Node, relationshipType: string, destNode: Node, properties: Map<string, any>) {
this._id = id; //edge's id - set by RedisGraph
this._relationshipId = relationshipId; //edge's relationship type
this._relationshipType = relationshipType; //edge's relationship type
this._srcNode = srcNode; //edge's source node
this._destNode = destNode; //edge's destination node
this._properties = properties; //edge's list of properties (list of Key:Value)
Expand All @@ -31,7 +31,7 @@ export default class Edge {
}

public get relationshipId() {
return this._relationshipId;
return this._relationshipType;
}

public get srcNode() {
Expand Down
71 changes: 37 additions & 34 deletions src/graph.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RedisClientType } from 'redis';
import ResultSet from './resultset';

/**
Expand All @@ -6,32 +7,32 @@ import ResultSet from './resultset';
export default class Graph {

private _graphId: string; // Graph ID
private _labels; // List of node labels.
private _relationshipTypes; // List of relation types.
private _properties; // List of properties.
private _labels: string[]; // List of node labels.
private _relationshipTypes: string[]; // List of relation types.
private _properties: string[]; // List of properties.

private _labelsPromise; // used as a synchronization mechanizom for labels retrival
private _propertyPromise; // used as a synchronization mechanizom for property names retrival
private _relationshipPromise; // used as a synchronization mechanizom for relationship types retrival
private _client;
private _sendCommand;
private _labelsPromise: Promise<string[]> | null; // used as a synchronization mechanizom for labels retrival
private _propertyPromise: Promise<string[]> | null; // used as a synchronization mechanizom for property names retrival
private _relationshipPromise: Promise<string[]> | null; // used as a synchronization mechanizom for relationship types retrival
private _client: RedisClientType;
private _sendCommand: any;

/**
* Creates a client to a specific graph
*
* @param {string} graphId the graph id
* @param {RedisClient} [client] Redis host or node_redis client or ioredis client
*/
constructor(client, graphId: string) {
constructor(client: RedisClientType, graphId: string) {
this._client = client;
this._graphId = graphId; // Graph ID
this._labels = []; // List of node labels.
this._relationshipTypes = []; // List of relation types.
this._properties = []; // List of properties.

this._labelsPromise = undefined; // used as a synchronization mechanizom for labels retrival
this._propertyPromise = undefined; // used as a synchronization mechanizom for property names retrival
this._relationshipPromise = undefined; // used as a synchronization mechanizom for relationship types retrival
this._labelsPromise = null; // used as a synchronization mechanizom for labels retrival
this._propertyPromise = null; // used as a synchronization mechanizom for property names retrival
this._relationshipPromise = null; // used as a synchronization mechanizom for relationship types retrival

// this._client =
// host && typeof host.send_command === 'function' // check if it's an instance of `redis` or `ioredis`
Expand All @@ -46,10 +47,12 @@ export default class Graph {
* @param {ResultSet} resultSet - a procedure result set
* @returns {string[]} strings array.
*/
_extractStrings(resultSet) {
var strings = [];
_extractStrings(resultSet: ResultSet) {
var strings: string[] = [];
while (resultSet.hasNext()) {
strings.push(resultSet.next().getString(0));

// TODO handle null values
strings.push(resultSet.next().getString(0)?? "");
}
return strings;
}
Expand All @@ -59,7 +62,7 @@ export default class Graph {
* @param {*} paramValue
* @returns {string} the string representation of paramValue.
*/
paramToString(paramValue) {
paramToString(paramValue: any) {
if (paramValue == null) return "null";
let paramType = typeof paramValue;
if (paramType == "string") {
Expand All @@ -85,11 +88,11 @@ export default class Graph {
* @param {Map} params parameters dictionary.
* @return {string} a cypher parameters string.
*/
buildParamsHeader(params) {
buildParamsHeader(params: Map<string, any>) {
let paramsArray = ["CYPHER"];

for (var key in params) {
let value = this.paramToString(params[key]);
let value = this.paramToString(params.get(key));
paramsArray.push(`${key}=${value}`);
}
paramsArray.push(" ");
Expand All @@ -103,7 +106,7 @@ export default class Graph {
* @param {Map} [params] Parameters map
* @returns {Promise<ResultSet>} a promise contains a result set
*/
query(query, params) {
query(query: string, params?: Map<string, any>) {
return this._query("graph.QUERY", query, params);
}

Expand All @@ -115,7 +118,7 @@ export default class Graph {
*
* @returns {Promise<ResultSet>} a promise contains a result set
*/
readonlyQuery(query, params) {
readonlyQuery(query: string, params: Map<string, any>) {
return this._query("graph.RO_QUERY", query, params);
}

Expand All @@ -129,7 +132,7 @@ export default class Graph {
*
* @returns {Promise<ResultSet>} a promise contains a result set
*/
async _query(command, query, params) {
async _query(command: string, query: string, params?: Map<string, any>) {
if (params) {
query = this.buildParamsHeader(params) + query;
}
Expand Down Expand Up @@ -164,7 +167,7 @@ export default class Graph {
* @param {string[]} [y] Yield outputs
* @returns {Promise<ResultSet>} a promise contains the procedure result set data
*/
callProcedure(procedure, args = new Array(), y = new Array()) {
callProcedure(procedure: string, args = new Array(), y = new Array()) {
let q = "CALL " + procedure + "(" + args.join(",") + ")" + y.join(" ");
return this.query(q);
}
Expand All @@ -174,14 +177,14 @@ export default class Graph {
* @async
*/
async labels() {
if (this._labelsPromise == undefined) {
if (this._labelsPromise == null) {
this._labelsPromise = this.callProcedure("db.labels").then(
response => {
return this._extractStrings(response);
}
);
this._labels = await this._labelsPromise;
this._labelsPromise = undefined;
this._labelsPromise = null;
} else {
await this._labelsPromise;
}
Expand All @@ -192,14 +195,14 @@ export default class Graph {
* @async
*/
async relationshipTypes() {
if (this._relationshipPromise == undefined) {
if (this._relationshipPromise == null) {
this._relationshipPromise = this.callProcedure(
"db.relationshipTypes"
).then(response => {
return this._extractStrings(response);
});
this._relationshipTypes = await this._relationshipPromise;
this._relationshipPromise = undefined;
this._relationshipPromise = null;
} else {
await this._relationshipPromise;
}
Expand All @@ -210,14 +213,14 @@ export default class Graph {
* @async
*/
async propertyKeys() {
if (this._propertyPromise == undefined) {
if (this._propertyPromise == null) {
this._propertyPromise = this.callProcedure("db.propertyKeys").then(
response => {
return this._extractStrings(response);
}
);
this._properties = await this._propertyPromise;
this._propertyPromise = undefined;
this._propertyPromise = null;
} else {
await this._propertyPromise;
}
Expand All @@ -228,7 +231,7 @@ export default class Graph {
* @param {number} id internal ID of label. (integer)
* @returns {string} String label.
*/
getLabel(id) {
getLabel(id: number) : string {
return this._labels[id];
}

Expand All @@ -238,7 +241,7 @@ export default class Graph {
* @param {number} id internal ID of label. (integer)
* @returns {Promise<string>} String label.
*/
async fetchAndGetLabel(id) {
async fetchAndGetLabel(id: number){
await this.labels();
return this._labels[id];
}
Expand All @@ -248,7 +251,7 @@ export default class Graph {
* @param {number} id internal ID of relationship type. (integer)
* @returns {string} relationship type.
*/
getRelationship(id) {
getRelationship(id: number) {
return this._relationshipTypes[id];
}

Expand All @@ -258,7 +261,7 @@ export default class Graph {
* @param {number} id internal ID of relationship type. (integer)
* @returns {Promise<string>} String relationship type.
*/
async fetchAndGetRelationship(id) {
async fetchAndGetRelationship(id: number) {
await this.relationshipTypes();
return this._relationshipTypes[id];
}
Expand All @@ -268,7 +271,7 @@ export default class Graph {
* @param {number} id internal ID of property. (integer)
* @returns {string} String property.
*/
getProperty(id) {
getProperty(id: number) {
return this._properties[id];
}

Expand All @@ -278,7 +281,7 @@ export default class Graph {
* @param {number} id internal ID of property. (integer)
* @returns {Promise<string>} String property.
*/
async fetchAndGetProperty(id) {
async fetchAndGetProperty(id: number) {
await this.propertyKeys();
return this._properties[id];
}
Expand Down
10 changes: 5 additions & 5 deletions src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
export default class Node {

private _id: number;
private _labelIds: number[];
private _labels: string[];
private _properties: Map<string, any>;

/**
* Builds a node object.
*
* @param {number} id - label id
* @param {number[]} labelIds - node labels.
* @param {string[]} labels - node labels.
* @param {Map} properties - properties map.
*/
constructor(id: number, labelIds: number[], properties: Map<string, any>) {
constructor(id: number, labels: string[], properties: Map<string, any>) {
this._id = id; //node's id - set by FalkorDB
this._labelIds = labelIds; //node's label
this._labels = labels; //node's label
this._properties = properties; //node's list of properties (list of Key:Value)
}

Expand All @@ -25,7 +25,7 @@ export default class Node {
}

public get labelIds() {
return this._labelIds;
return this._labels;
}

public get propeties() {
Expand Down
15 changes: 4 additions & 11 deletions src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ export default class Record {
* @returns {object} Requested value.
*/
get(key: string|number): object {
let index = key;
if (typeof key === "string") {
index = this._header.indexOf(key);
}
let index = typeof key === "string" ? this._header.indexOf(key) : key;
return this._values[index];
}

Expand All @@ -35,12 +32,8 @@ export default class Record {
* @param {string | number} key (integer)
* @returns {string} Requested string representation of the value.
*/
getString(key) {
let index = key;
if (typeof key === "string") {
index = this._header.indexOf(key);
}

getString(key: string|number) {
let index = typeof key === "string" ? this._header.indexOf(key) : key
let value = this._values[index];
if (value !== undefined && value !== null) {
return value.toString();
Expand Down Expand Up @@ -68,7 +61,7 @@ export default class Record {
* @param {string} key
* @returns {boolean} true if header contains key.
*/
containsKey(key) {
containsKey(key: string) {
return this._header.includes(key);
}

Expand Down
Loading

0 comments on commit 9acc1f9

Please sign in to comment.