falkordb 6.0.2 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/src/commands/SENTINEL_MASTER.js +0 -1
- package/dist/src/commands/SENTINEL_MASTERS.js +0 -1
- package/dist/src/commands/index.d.ts +6 -0
- package/dist/src/commands/index.js +7 -1
- package/dist/src/falkordb.d.ts +1 -0
- package/dist/src/falkordb.js +60 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
# falkordb-ts
|
|
2
|
-
|
|
3
1
|
[](https://github.com/falkordb/falkordb-ts/actions/workflows/node.js.yml)
|
|
4
2
|
[](https://codecov.io/gh/falkordb/falkordb-ts)
|
|
5
3
|
[](https://github.com/falkordb/falkordb-ts/blob/main/LICENSE)
|
|
6
|
-
|
|
7
4
|
[](https://discord.com/invite/99y2Ubh6tg)
|
|
8
5
|
[](https://twitter.com/falkordb)
|
|
9
6
|
|
|
7
|
+
# falkordb-ts
|
|
8
|
+
|
|
9
|
+
[](https://app.falkordb.cloud)
|
|
10
|
+
|
|
10
11
|
`falkordb` is a [FalkorDB](https://www.falkordb.com) client for Node.js.
|
|
11
12
|
|
|
12
13
|
## Installation
|
|
@@ -11,6 +11,8 @@ import * as SLOWLOG from './SLOWLOG';
|
|
|
11
11
|
import * as CONSTRAINT_CREATE from './CONSTRAINT_CREATE';
|
|
12
12
|
import * as CONSTRAINT_DROP from './CONSTRAINT_DROP';
|
|
13
13
|
import * as COPY from './COPY';
|
|
14
|
+
import * as SENTINEL_MASTER from './SENTINEL_MASTER';
|
|
15
|
+
import * as SENTINEL_MASTERS from './SENTINEL_MASTERS';
|
|
14
16
|
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
|
|
15
17
|
declare const _default: {
|
|
16
18
|
CONFIG_GET: typeof CONFIG_GET;
|
|
@@ -39,6 +41,10 @@ declare const _default: {
|
|
|
39
41
|
constraintDrop: typeof CONSTRAINT_DROP;
|
|
40
42
|
COPY: typeof COPY;
|
|
41
43
|
copy: typeof COPY;
|
|
44
|
+
SENTINEL_MASTER: typeof SENTINEL_MASTER;
|
|
45
|
+
sentinelMaster: typeof SENTINEL_MASTER;
|
|
46
|
+
SENTINEL_MASTERS: typeof SENTINEL_MASTERS;
|
|
47
|
+
sentinelMasters: typeof SENTINEL_MASTERS;
|
|
42
48
|
};
|
|
43
49
|
export default _default;
|
|
44
50
|
type QueryParam = null | string | number | boolean | QueryParams | Array<QueryParam>;
|
|
@@ -14,6 +14,8 @@ const SLOWLOG = require("./SLOWLOG");
|
|
|
14
14
|
const CONSTRAINT_CREATE = require("./CONSTRAINT_CREATE");
|
|
15
15
|
const CONSTRAINT_DROP = require("./CONSTRAINT_DROP");
|
|
16
16
|
const COPY = require("./COPY");
|
|
17
|
+
const SENTINEL_MASTER = require("./SENTINEL_MASTER");
|
|
18
|
+
const SENTINEL_MASTERS = require("./SENTINEL_MASTERS");
|
|
17
19
|
exports.default = {
|
|
18
20
|
CONFIG_GET,
|
|
19
21
|
configGet: CONFIG_GET,
|
|
@@ -40,7 +42,11 @@ exports.default = {
|
|
|
40
42
|
CONSTRAINT_DROP,
|
|
41
43
|
constraintDrop: CONSTRAINT_DROP,
|
|
42
44
|
COPY,
|
|
43
|
-
copy: COPY
|
|
45
|
+
copy: COPY,
|
|
46
|
+
SENTINEL_MASTER,
|
|
47
|
+
sentinelMaster: SENTINEL_MASTER,
|
|
48
|
+
SENTINEL_MASTERS,
|
|
49
|
+
sentinelMasters: SENTINEL_MASTERS
|
|
44
50
|
};
|
|
45
51
|
function pushQueryArguments(args, graph, query, options, compact) {
|
|
46
52
|
args.push(graph);
|
package/dist/src/falkordb.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export interface FalkorDBOptions {
|
|
|
72
72
|
export default class FalkorDB extends EventEmitter {
|
|
73
73
|
#private;
|
|
74
74
|
private constructor();
|
|
75
|
+
private connectServer;
|
|
75
76
|
static connect(options?: FalkorDBOptions): Promise<FalkorDB>;
|
|
76
77
|
selectGraph(graphId: string): Graph;
|
|
77
78
|
get connection(): GraphConnection;
|
package/dist/src/falkordb.js
CHANGED
|
@@ -4,12 +4,66 @@ const events_1 = require("events");
|
|
|
4
4
|
const redis_1 = require("redis");
|
|
5
5
|
const graph_1 = require("./graph");
|
|
6
6
|
const commands_1 = require("./commands");
|
|
7
|
+
function extractDetails(masters) {
|
|
8
|
+
const allDetails = [];
|
|
9
|
+
for (const master of masters) {
|
|
10
|
+
const details = {};
|
|
11
|
+
for (let i = 0; i < master.length; i += 2) {
|
|
12
|
+
details[master[i]] = master[i + 1];
|
|
13
|
+
}
|
|
14
|
+
allDetails.push(details);
|
|
15
|
+
}
|
|
16
|
+
return allDetails;
|
|
17
|
+
}
|
|
7
18
|
class FalkorDB extends events_1.EventEmitter {
|
|
8
19
|
#client;
|
|
20
|
+
#sentinel;
|
|
9
21
|
constructor(client) {
|
|
10
22
|
super();
|
|
11
23
|
this.#client = client;
|
|
12
24
|
}
|
|
25
|
+
async connectServer(client, redisOption) {
|
|
26
|
+
// If not connected to sentinel, throws an error on missing command
|
|
27
|
+
const masters = await client.falkordb.sentinelMasters();
|
|
28
|
+
const details = extractDetails(masters);
|
|
29
|
+
if (details.length > 1) {
|
|
30
|
+
throw new Error('Multiple masters are not supported');
|
|
31
|
+
}
|
|
32
|
+
// Connect to the server with the details from sentinel
|
|
33
|
+
const socketOptions = {
|
|
34
|
+
...redisOption.socket,
|
|
35
|
+
host: details[0]['ip'],
|
|
36
|
+
port: parseInt(details[0]['port'])
|
|
37
|
+
};
|
|
38
|
+
const serverOptions = {
|
|
39
|
+
...redisOption,
|
|
40
|
+
socket: socketOptions
|
|
41
|
+
};
|
|
42
|
+
const realClient = (0, redis_1.createClient)(serverOptions);
|
|
43
|
+
// Set original client as sentinel and server client as client
|
|
44
|
+
this.#sentinel = client;
|
|
45
|
+
this.#client = realClient;
|
|
46
|
+
await realClient
|
|
47
|
+
.on('error', async (err) => {
|
|
48
|
+
console.debug('Error on server connection', err);
|
|
49
|
+
// Disconnect the client to avoid further errors and retries
|
|
50
|
+
realClient.disconnect();
|
|
51
|
+
// If error occurs on previous server connection, no need to reconnect
|
|
52
|
+
if (this.#client !== realClient) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
await this.connectServer(client, redisOption);
|
|
57
|
+
console.debug('Connected to server');
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.debug('Error on server reconnect', e);
|
|
61
|
+
// Forward errors if reconnection fails
|
|
62
|
+
this.emit('error', err);
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
.connect();
|
|
66
|
+
}
|
|
13
67
|
static async connect(options) {
|
|
14
68
|
const redisOption = (options ?? {});
|
|
15
69
|
// If the URL is provided, and the protocol is `falkor` replaces it with `redis` for the underline redis client
|
|
@@ -25,6 +79,12 @@ class FalkorDB extends events_1.EventEmitter {
|
|
|
25
79
|
await client
|
|
26
80
|
.on('error', err => falkordb.emit('error', err)) // Forward errors
|
|
27
81
|
.connect();
|
|
82
|
+
try {
|
|
83
|
+
await falkordb.connectServer(client, redisOption);
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
console.debug('Error in connecting to sentinel, connecting to server directly');
|
|
87
|
+
}
|
|
28
88
|
return falkordb;
|
|
29
89
|
}
|
|
30
90
|
selectGraph(graphId) {
|