falkordb 6.2.6 → 6.2.7
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/dist/index.d.ts +3 -0
- package/dist/index.js +10 -0
- package/dist/src/clients/client.d.ts +32 -0
- package/dist/src/clients/client.js +2 -0
- package/dist/src/clients/cluster.d.ts +57 -0
- package/dist/src/clients/cluster.js +87 -0
- package/dist/src/clients/nullClient.d.ts +41 -0
- package/dist/src/clients/nullClient.js +68 -0
- package/dist/src/clients/sentinel.d.ts +13 -0
- package/dist/src/clients/sentinel.js +82 -0
- package/dist/src/clients/single.d.ts +52 -0
- package/dist/src/clients/single.js +99 -0
- package/dist/src/commands/CONFIG_GET.d.ts +8 -0
- package/dist/src/commands/CONFIG_GET.js +8 -0
- package/dist/src/commands/CONFIG_SET.d.ts +2 -0
- package/dist/src/commands/CONFIG_SET.js +11 -0
- package/dist/src/commands/CONSTRAINT_CREATE.d.ts +10 -0
- package/dist/src/commands/CONSTRAINT_CREATE.js +22 -0
- package/dist/src/commands/CONSTRAINT_DROP.d.ts +3 -0
- package/dist/src/commands/CONSTRAINT_DROP.js +11 -0
- package/dist/src/commands/COPY.d.ts +2 -0
- package/dist/src/commands/COPY.js +10 -0
- package/dist/src/commands/DELETE.d.ts +3 -0
- package/dist/src/commands/DELETE.js +8 -0
- package/dist/src/commands/EXPLAIN.d.ts +4 -0
- package/dist/src/commands/EXPLAIN.js +9 -0
- package/dist/src/commands/INFO.d.ts +3 -0
- package/dist/src/commands/INFO.js +12 -0
- package/dist/src/commands/LIST.d.ts +3 -0
- package/dist/src/commands/LIST.js +8 -0
- package/dist/src/commands/PROFILE.d.ts +4 -0
- package/dist/src/commands/PROFILE.js +9 -0
- package/dist/src/commands/QUERY.d.ts +25 -0
- package/dist/src/commands/QUERY.js +21 -0
- package/dist/src/commands/RO_QUERY.d.ts +6 -0
- package/dist/src/commands/RO_QUERY.js +13 -0
- package/dist/src/commands/SENTINEL_MASTER.d.ts +3 -0
- package/dist/src/commands/SENTINEL_MASTER.js +8 -0
- package/dist/src/commands/SENTINEL_MASTERS.d.ts +3 -0
- package/dist/src/commands/SENTINEL_MASTERS.js +8 -0
- package/dist/src/commands/SLOWLOG.d.ts +17 -0
- package/dist/src/commands/SLOWLOG.js +18 -0
- package/dist/src/commands/index.d.ts +59 -0
- package/dist/src/commands/index.js +104 -0
- package/dist/src/falkordb.d.ts +98 -0
- package/dist/src/falkordb.js +76 -0
- package/dist/src/graph.d.ts +41 -0
- package/dist/src/graph.js +270 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FalkorDB = exports.EntityType = exports.ConstraintType = exports.Graph = void 0;
|
|
4
|
+
var graph_1 = require("./src/graph");
|
|
5
|
+
Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return graph_1.default; } });
|
|
6
|
+
var graph_2 = require("./src/graph");
|
|
7
|
+
Object.defineProperty(exports, "ConstraintType", { enumerable: true, get: function () { return graph_2.ConstraintType; } });
|
|
8
|
+
Object.defineProperty(exports, "EntityType", { enumerable: true, get: function () { return graph_2.EntityType; } });
|
|
9
|
+
var falkordb_1 = require("./src/falkordb");
|
|
10
|
+
Object.defineProperty(exports, "FalkorDB", { enumerable: true, get: function () { return falkordb_1.default; } });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RedisCommandArgument } from "@redis/client/dist/lib/commands";
|
|
2
|
+
import { QueryOptions } from "../commands";
|
|
3
|
+
import { ConstraintType, EntityType } from "../graph";
|
|
4
|
+
import FalkorDB from "../falkordb";
|
|
5
|
+
import { SingleGraphConnection } from "./single";
|
|
6
|
+
export interface Client {
|
|
7
|
+
init(falkordb: FalkorDB): Promise<void>;
|
|
8
|
+
list(): Promise<Array<string>>;
|
|
9
|
+
configGet(configKey: string): Promise<(string | number)[] | (string | number)[][]>;
|
|
10
|
+
configSet(configKey: string, value: number | string): Promise<void>;
|
|
11
|
+
info(section?: string): Promise<(string | string[])[]>;
|
|
12
|
+
query<T>(graph: string, query: RedisCommandArgument, options?: QueryOptions, compact?: boolean): Promise<any>;
|
|
13
|
+
profile<T>(graph: string, query: RedisCommandArgument): Promise<any>;
|
|
14
|
+
roQuery<T>(graph: string, query: RedisCommandArgument, options?: QueryOptions, compact?: boolean): Promise<any>;
|
|
15
|
+
copy<T>(srcGraph: string, destGraph: string): Promise<any>;
|
|
16
|
+
delete(graph: string): Promise<void>;
|
|
17
|
+
explain(graph: string, query: string): Promise<any>;
|
|
18
|
+
slowLog(graph: string): Promise<{
|
|
19
|
+
timestamp: Date;
|
|
20
|
+
command: string;
|
|
21
|
+
query: string;
|
|
22
|
+
took: number;
|
|
23
|
+
}[]>;
|
|
24
|
+
constraintCreate(graph: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Promise<void>;
|
|
25
|
+
constraintDrop(graph: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use `disconnect` instead
|
|
28
|
+
*/
|
|
29
|
+
quit(): Promise<void>;
|
|
30
|
+
disconnect(): Promise<void>;
|
|
31
|
+
getConnection(): Promise<SingleGraphConnection>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Client } from "./client";
|
|
2
|
+
import { ConstraintType, EntityType } from "../graph";
|
|
3
|
+
import { RedisCommandArgument, RedisFunctions, RedisScripts } from "@redis/client/dist/lib/commands";
|
|
4
|
+
import commands, { QueryOptions } from "../commands";
|
|
5
|
+
import { RedisClusterType } from "@redis/client";
|
|
6
|
+
import FalkorDB from "../falkordb";
|
|
7
|
+
import { SingleGraphConnection } from "./single";
|
|
8
|
+
export type ClusterGraphConnection = RedisClusterType<{
|
|
9
|
+
falkordb: typeof commands;
|
|
10
|
+
}, RedisFunctions, RedisScripts>;
|
|
11
|
+
/**
|
|
12
|
+
* A client that connects to a Redis Cluster.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Cluster implements Client {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(client: SingleGraphConnection);
|
|
17
|
+
getConnection(): Promise<import("@redis/client").RedisClientType<{
|
|
18
|
+
falkordb: typeof commands;
|
|
19
|
+
}, RedisFunctions, RedisScripts>>;
|
|
20
|
+
init(falkordb: FalkorDB): Promise<void>;
|
|
21
|
+
query<T>(graph: string, query: RedisCommandArgument, options?: QueryOptions, compact?: boolean): Promise<{
|
|
22
|
+
headers: undefined;
|
|
23
|
+
data: undefined;
|
|
24
|
+
metadata: string[];
|
|
25
|
+
} | {
|
|
26
|
+
headers: string[];
|
|
27
|
+
data: (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[];
|
|
28
|
+
metadata: string[];
|
|
29
|
+
}>;
|
|
30
|
+
roQuery<T>(graph: string, query: RedisCommandArgument, options?: QueryOptions, compact?: boolean): Promise<{
|
|
31
|
+
headers: undefined;
|
|
32
|
+
data: undefined;
|
|
33
|
+
metadata: string[];
|
|
34
|
+
} | {
|
|
35
|
+
headers: string[];
|
|
36
|
+
data: (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[];
|
|
37
|
+
metadata: string[];
|
|
38
|
+
}>;
|
|
39
|
+
delete(graph: string): Promise<void>;
|
|
40
|
+
explain(graph: string, query: string): Promise<string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined>;
|
|
41
|
+
list(): Promise<Array<string>>;
|
|
42
|
+
configGet(configKey: string): Promise<(string | number)[] | (string | number)[][]>;
|
|
43
|
+
configSet(configKey: string, value: number | string): Promise<void>;
|
|
44
|
+
info(section?: string): Promise<(string | string[])[]>;
|
|
45
|
+
copy<_T>(srcGraph: string, destGraph: string): Promise<"OK">;
|
|
46
|
+
slowLog(graph: string): Promise<{
|
|
47
|
+
timestamp: Date;
|
|
48
|
+
command: string;
|
|
49
|
+
query: string;
|
|
50
|
+
took: number;
|
|
51
|
+
}[]>;
|
|
52
|
+
constraintCreate(graph: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Promise<void>;
|
|
53
|
+
constraintDrop(graph: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Promise<void>;
|
|
54
|
+
profile<_T>(graph: string, query: string): Promise<string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined>;
|
|
55
|
+
quit(): Promise<void>;
|
|
56
|
+
disconnect(): Promise<void>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cluster = void 0;
|
|
4
|
+
const client_1 = require("@redis/client");
|
|
5
|
+
const lodash = require("lodash");
|
|
6
|
+
/**
|
|
7
|
+
* A client that connects to a Redis Cluster.
|
|
8
|
+
*/
|
|
9
|
+
class Cluster {
|
|
10
|
+
#client;
|
|
11
|
+
constructor(client) {
|
|
12
|
+
// Convert the single client options to a cluster client options
|
|
13
|
+
const redisClusterOption = client.options;
|
|
14
|
+
redisClusterOption.rootNodes = [
|
|
15
|
+
client.options,
|
|
16
|
+
];
|
|
17
|
+
// Remove the URL from the defaults so it won't override the dynamic cluster URLs
|
|
18
|
+
const defaults = lodash.cloneDeep(client.options);
|
|
19
|
+
defaults?.url && delete defaults.url;
|
|
20
|
+
redisClusterOption.defaults = defaults;
|
|
21
|
+
redisClusterOption.maxCommandRedirections = 100000;
|
|
22
|
+
client.disconnect();
|
|
23
|
+
this.#client = (0, client_1.createCluster)(redisClusterOption);
|
|
24
|
+
}
|
|
25
|
+
async getConnection() {
|
|
26
|
+
const connection = this.#client.nodeClient(this.#client.getRandomNode());
|
|
27
|
+
return connection instanceof Promise ? await connection : connection;
|
|
28
|
+
}
|
|
29
|
+
async init(falkordb) {
|
|
30
|
+
await this.#client
|
|
31
|
+
.on("error", (err) => falkordb.emit("error", err)) // Forward errors
|
|
32
|
+
.connect();
|
|
33
|
+
}
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
35
|
+
async query(graph, query, options, compact = true) {
|
|
36
|
+
return this.#client.falkordb.query(graph, query, options, compact);
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
async roQuery(graph, query, options, compact = true) {
|
|
40
|
+
return this.#client.falkordb.roQuery(graph, query, options, compact);
|
|
41
|
+
}
|
|
42
|
+
async delete(graph) {
|
|
43
|
+
const reply = this.#client.falkordb.delete(graph);
|
|
44
|
+
return reply.then(() => { });
|
|
45
|
+
}
|
|
46
|
+
async explain(graph, query) {
|
|
47
|
+
return this.#client.falkordb.explain(graph, query);
|
|
48
|
+
}
|
|
49
|
+
async list() {
|
|
50
|
+
return this.#client.falkordb.list();
|
|
51
|
+
}
|
|
52
|
+
async configGet(configKey) {
|
|
53
|
+
return this.#client.falkordb.configGet(configKey);
|
|
54
|
+
}
|
|
55
|
+
async configSet(configKey, value) {
|
|
56
|
+
const reply = this.#client.falkordb.configSet(configKey, value);
|
|
57
|
+
return reply.then(() => { });
|
|
58
|
+
}
|
|
59
|
+
async info(section) {
|
|
60
|
+
return this.#client.falkordb.info(section);
|
|
61
|
+
}
|
|
62
|
+
async copy(srcGraph, destGraph) {
|
|
63
|
+
return this.#client.falkordb.copy(srcGraph, destGraph);
|
|
64
|
+
}
|
|
65
|
+
slowLog(graph) {
|
|
66
|
+
return this.#client.falkordb.slowLog(graph);
|
|
67
|
+
}
|
|
68
|
+
async constraintCreate(graph, constraintType, entityType, label, ...properties) {
|
|
69
|
+
const reply = this.#client.falkordb.constraintCreate(graph, constraintType, entityType, label, ...properties);
|
|
70
|
+
return reply.then(() => { });
|
|
71
|
+
}
|
|
72
|
+
async constraintDrop(graph, constraintType, entityType, label, ...properties) {
|
|
73
|
+
const reply = this.#client.falkordb.constraintDrop(graph, constraintType, entityType, label, ...properties);
|
|
74
|
+
return reply.then(() => { });
|
|
75
|
+
}
|
|
76
|
+
async profile(graph, query) {
|
|
77
|
+
return this.#client.falkordb.profile(graph, query);
|
|
78
|
+
}
|
|
79
|
+
async quit() {
|
|
80
|
+
return this.disconnect();
|
|
81
|
+
}
|
|
82
|
+
async disconnect() {
|
|
83
|
+
const reply = this.#client.disconnect();
|
|
84
|
+
return reply.then(() => { });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.Cluster = Cluster;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RedisCommandArgument } from "@redis/client/dist/lib/commands";
|
|
2
|
+
import { QueryOptions } from "../commands";
|
|
3
|
+
import FalkorDB from "../falkordb";
|
|
4
|
+
import { ConstraintType, EntityType } from "../graph";
|
|
5
|
+
import { Client } from "./client";
|
|
6
|
+
import { SingleGraphConnection } from "./single";
|
|
7
|
+
/**
|
|
8
|
+
* The `NullClient` class is a placeholder implementation of the `Client` interface.
|
|
9
|
+
*
|
|
10
|
+
* This class is designed to be used in scenarios where a client is required, but no actual
|
|
11
|
+
* implementation is available. All methods in this class throw a "Method not implemented."
|
|
12
|
+
* error, indicating that the functionality has not been provided.
|
|
13
|
+
*
|
|
14
|
+
* The `NullClient` can serve as a base class or a stub for future implementations, or as a
|
|
15
|
+
* fallback in cases where a functional client is not needed or cannot be instantiated.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export declare class NullClient implements Client {
|
|
19
|
+
getConnection(): Promise<SingleGraphConnection>;
|
|
20
|
+
init(_falkordb: FalkorDB): Promise<void>;
|
|
21
|
+
list(): Promise<Array<string>>;
|
|
22
|
+
configGet(_configKey: string): Promise<(string | number)[] | (string | number)[][]>;
|
|
23
|
+
configSet(_configKey: string, _value: number | string): Promise<void>;
|
|
24
|
+
info(_section?: string): Promise<(string | string[])[]>;
|
|
25
|
+
query<_T>(_graph: string, _query: RedisCommandArgument, _options?: QueryOptions): Promise<any>;
|
|
26
|
+
profile<_T>(_graph: string, _query: RedisCommandArgument): Promise<any>;
|
|
27
|
+
roQuery<_T>(_graph: string, _query: RedisCommandArgument, _options?: QueryOptions): Promise<any>;
|
|
28
|
+
copy<_T>(_srcGraph: string, _destGraph: string): Promise<any>;
|
|
29
|
+
delete(_graph: string): Promise<void>;
|
|
30
|
+
explain(_graph: string, _query: string): Promise<any>;
|
|
31
|
+
slowLog(_graph: string): Promise<{
|
|
32
|
+
timestamp: Date;
|
|
33
|
+
command: string;
|
|
34
|
+
query: string;
|
|
35
|
+
took: number;
|
|
36
|
+
}[]>;
|
|
37
|
+
constraintCreate(_graph: string, _constraintType: ConstraintType, _entityType: EntityType, _label: string, ..._properties: string[]): Promise<void>;
|
|
38
|
+
constraintDrop(_graph: string, _constraintType: ConstraintType, _entityType: EntityType, _label: string, ..._properties: string[]): Promise<void>;
|
|
39
|
+
quit(): Promise<void>;
|
|
40
|
+
disconnect(): Promise<void>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NullClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The `NullClient` class is a placeholder implementation of the `Client` interface.
|
|
6
|
+
*
|
|
7
|
+
* This class is designed to be used in scenarios where a client is required, but no actual
|
|
8
|
+
* implementation is available. All methods in this class throw a "Method not implemented."
|
|
9
|
+
* error, indicating that the functionality has not been provided.
|
|
10
|
+
*
|
|
11
|
+
* The `NullClient` can serve as a base class or a stub for future implementations, or as a
|
|
12
|
+
* fallback in cases where a functional client is not needed or cannot be instantiated.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
class NullClient {
|
|
16
|
+
getConnection() {
|
|
17
|
+
throw new Error("Method not implemented.");
|
|
18
|
+
}
|
|
19
|
+
init(_falkordb) {
|
|
20
|
+
throw new Error("Method not implemented.");
|
|
21
|
+
}
|
|
22
|
+
list() {
|
|
23
|
+
throw new Error("Method not implemented.");
|
|
24
|
+
}
|
|
25
|
+
configGet(_configKey) {
|
|
26
|
+
throw new Error("Method not implemented.");
|
|
27
|
+
}
|
|
28
|
+
configSet(_configKey, _value) {
|
|
29
|
+
throw new Error("Method not implemented.");
|
|
30
|
+
}
|
|
31
|
+
info(_section) {
|
|
32
|
+
throw new Error("Method not implemented.");
|
|
33
|
+
}
|
|
34
|
+
query(_graph, _query, _options) {
|
|
35
|
+
throw new Error("Method not implemented.");
|
|
36
|
+
}
|
|
37
|
+
profile(_graph, _query) {
|
|
38
|
+
throw new Error("Method not implemented.");
|
|
39
|
+
}
|
|
40
|
+
roQuery(_graph, _query, _options) {
|
|
41
|
+
throw new Error("Method not implemented.");
|
|
42
|
+
}
|
|
43
|
+
copy(_srcGraph, _destGraph) {
|
|
44
|
+
throw new Error("Method not implemented.");
|
|
45
|
+
}
|
|
46
|
+
delete(_graph) {
|
|
47
|
+
throw new Error("Method not implemented.");
|
|
48
|
+
}
|
|
49
|
+
explain(_graph, _query) {
|
|
50
|
+
throw new Error("Method not implemented.");
|
|
51
|
+
}
|
|
52
|
+
slowLog(_graph) {
|
|
53
|
+
throw new Error("Method not implemented.");
|
|
54
|
+
}
|
|
55
|
+
constraintCreate(_graph, _constraintType, _entityType, _label, ..._properties) {
|
|
56
|
+
throw new Error("Method not implemented.");
|
|
57
|
+
}
|
|
58
|
+
constraintDrop(_graph, _constraintType, _entityType, _label, ..._properties) {
|
|
59
|
+
throw new Error("Method not implemented.");
|
|
60
|
+
}
|
|
61
|
+
quit() {
|
|
62
|
+
throw new Error("Method not implemented.");
|
|
63
|
+
}
|
|
64
|
+
disconnect() {
|
|
65
|
+
throw new Error("Method not implemented.");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.NullClient = NullClient;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Single } from "./single";
|
|
2
|
+
import FalkorDB from "../falkordb";
|
|
3
|
+
export declare class Sentinel extends Single {
|
|
4
|
+
private sentinelClient;
|
|
5
|
+
init(falkordb: FalkorDB): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Connect to the server using the details from sentinel server
|
|
8
|
+
* Register error event to reconnect on error from the sentinel server
|
|
9
|
+
*/
|
|
10
|
+
private tryConnectSentinelServer;
|
|
11
|
+
quit(): Promise<void>;
|
|
12
|
+
disconnect(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sentinel = void 0;
|
|
4
|
+
const single_1 = require("./single");
|
|
5
|
+
const client_1 = require("@redis/client");
|
|
6
|
+
function extractDetails(masters) {
|
|
7
|
+
const allDetails = [];
|
|
8
|
+
for (const master of masters) {
|
|
9
|
+
const details = {};
|
|
10
|
+
for (let i = 0; i < master.length; i += 2) {
|
|
11
|
+
details[master[i]] = master[i + 1];
|
|
12
|
+
}
|
|
13
|
+
allDetails.push(details);
|
|
14
|
+
}
|
|
15
|
+
return allDetails;
|
|
16
|
+
}
|
|
17
|
+
class Sentinel extends single_1.Single {
|
|
18
|
+
sentinelClient;
|
|
19
|
+
init(falkordb) {
|
|
20
|
+
const redisOption = (this.client.options ?? {});
|
|
21
|
+
return this.tryConnectSentinelServer(this.client, redisOption, falkordb);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Connect to the server using the details from sentinel server
|
|
25
|
+
* Register error event to reconnect on error from the sentinel server
|
|
26
|
+
*/
|
|
27
|
+
async tryConnectSentinelServer(client, redisOption, falkordb) {
|
|
28
|
+
// TODO support multi sentinels
|
|
29
|
+
const masters = await client.falkordb.sentinelMasters();
|
|
30
|
+
const details = extractDetails(masters);
|
|
31
|
+
if (details.length > 1) {
|
|
32
|
+
throw new Error("Multiple masters are not supported");
|
|
33
|
+
}
|
|
34
|
+
// Connect to the server with the details from sentinel
|
|
35
|
+
const socketOptions = {
|
|
36
|
+
...redisOption.socket,
|
|
37
|
+
host: details[0]["ip"],
|
|
38
|
+
port: parseInt(details[0]["port"]),
|
|
39
|
+
};
|
|
40
|
+
const serverOptions = {
|
|
41
|
+
...redisOption,
|
|
42
|
+
socket: socketOptions,
|
|
43
|
+
};
|
|
44
|
+
const realClient = (0, client_1.createClient)(serverOptions);
|
|
45
|
+
// Save sentinel client to quit on quit()
|
|
46
|
+
this.sentinelClient = client;
|
|
47
|
+
// Set original client as sentinel and server client as client
|
|
48
|
+
this.client = realClient;
|
|
49
|
+
await realClient
|
|
50
|
+
.on("error", async (err) => {
|
|
51
|
+
console.debug("Error on server connection", err);
|
|
52
|
+
// Disconnect the client to avoid further errors and retries
|
|
53
|
+
realClient.disconnect();
|
|
54
|
+
// If error occurs on previous server connection, no need to reconnect
|
|
55
|
+
if (this.client !== realClient) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
await this.tryConnectSentinelServer(client, redisOption, falkordb);
|
|
60
|
+
console.debug("Connected to server");
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.debug("Error on server reconnect", e);
|
|
64
|
+
// Forward errors if reconnection fails
|
|
65
|
+
falkordb.emit("error", err);
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
.connect();
|
|
69
|
+
}
|
|
70
|
+
quit() {
|
|
71
|
+
return this.disconnect();
|
|
72
|
+
}
|
|
73
|
+
async disconnect() {
|
|
74
|
+
const promises = [super.disconnect()];
|
|
75
|
+
if (this.sentinelClient) {
|
|
76
|
+
const reply = this.sentinelClient.disconnect();
|
|
77
|
+
promises.push(reply.then(() => { }));
|
|
78
|
+
}
|
|
79
|
+
return Promise.all(promises).then(() => { });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.Sentinel = Sentinel;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Client } from "./client";
|
|
2
|
+
import { ConstraintType, EntityType } from "../graph";
|
|
3
|
+
import { RedisCommandArgument, RedisFunctions, RedisScripts } from "@redis/client/dist/lib/commands";
|
|
4
|
+
import commands, { QueryOptions } from "../commands";
|
|
5
|
+
import { RedisClientType } from "@redis/client";
|
|
6
|
+
import FalkorDB from "../falkordb";
|
|
7
|
+
export type SingleGraphConnection = RedisClientType<{
|
|
8
|
+
falkordb: typeof commands;
|
|
9
|
+
}, RedisFunctions, RedisScripts>;
|
|
10
|
+
export declare class Single implements Client {
|
|
11
|
+
#private;
|
|
12
|
+
protected client: SingleGraphConnection;
|
|
13
|
+
constructor(client: SingleGraphConnection);
|
|
14
|
+
init(_falkordb: FalkorDB): Promise<void>;
|
|
15
|
+
query<_T>(graph: string, query: RedisCommandArgument, options?: QueryOptions, compact?: boolean): Promise<{
|
|
16
|
+
headers: undefined;
|
|
17
|
+
data: undefined;
|
|
18
|
+
metadata: string[];
|
|
19
|
+
} | {
|
|
20
|
+
headers: string[];
|
|
21
|
+
data: (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[];
|
|
22
|
+
metadata: string[];
|
|
23
|
+
}>;
|
|
24
|
+
roQuery<_T>(graph: string, query: RedisCommandArgument, options?: QueryOptions, compact?: boolean): Promise<{
|
|
25
|
+
headers: undefined;
|
|
26
|
+
data: undefined;
|
|
27
|
+
metadata: string[];
|
|
28
|
+
} | {
|
|
29
|
+
headers: string[];
|
|
30
|
+
data: (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | /*elided*/ any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[];
|
|
31
|
+
metadata: string[];
|
|
32
|
+
}>;
|
|
33
|
+
delete(graph: string): Promise<void>;
|
|
34
|
+
explain(graph: string, query: string): Promise<string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined>;
|
|
35
|
+
profile<_T>(graph: string, query: string): Promise<string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | (string | number | /*elided*/ any | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined)[] | null | undefined>;
|
|
36
|
+
list(): Promise<string[]>;
|
|
37
|
+
configGet(configKey: string): Promise<(string | number)[] | (string | number)[][]>;
|
|
38
|
+
configSet(configKey: string, value: number | string): Promise<void>;
|
|
39
|
+
info(section?: string): Promise<(string | string[])[]>;
|
|
40
|
+
slowLog(graph: string): Promise<{
|
|
41
|
+
timestamp: Date;
|
|
42
|
+
command: string;
|
|
43
|
+
query: string;
|
|
44
|
+
took: number;
|
|
45
|
+
}[]>;
|
|
46
|
+
constraintCreate(graph: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Promise<void>;
|
|
47
|
+
constraintDrop(graph: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Promise<void>;
|
|
48
|
+
copy<_T>(srcGraph: string, destGraph: string): Promise<"OK">;
|
|
49
|
+
quit(): Promise<void>;
|
|
50
|
+
disconnect(): Promise<void>;
|
|
51
|
+
getConnection(): Promise<SingleGraphConnection>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Single = void 0;
|
|
4
|
+
class Single {
|
|
5
|
+
client;
|
|
6
|
+
#usePool;
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
this.#usePool = !!this.client.options?.isolationPoolOptions;
|
|
10
|
+
}
|
|
11
|
+
init(_falkordb) {
|
|
12
|
+
return Promise.resolve();
|
|
13
|
+
}
|
|
14
|
+
async query(graph, query, options, compact = true) {
|
|
15
|
+
const reply = this.#usePool
|
|
16
|
+
? await this.client.executeIsolated(async (isolatedClient) => {
|
|
17
|
+
return isolatedClient.falkordb.query(graph, query, options, compact);
|
|
18
|
+
})
|
|
19
|
+
: await this.client.falkordb.query(graph, query, options, compact);
|
|
20
|
+
return reply;
|
|
21
|
+
}
|
|
22
|
+
async roQuery(graph, query, options, compact = true) {
|
|
23
|
+
const reply = this.#usePool
|
|
24
|
+
? await this.client.executeIsolated(async (isolatedClient) => {
|
|
25
|
+
return isolatedClient.falkordb.roQuery(graph, query, options, compact);
|
|
26
|
+
})
|
|
27
|
+
: await this.client.falkordb.roQuery(graph, query, options, compact);
|
|
28
|
+
return reply;
|
|
29
|
+
}
|
|
30
|
+
async delete(graph) {
|
|
31
|
+
if (this.#usePool) {
|
|
32
|
+
return this.client.executeIsolated(async (isolatedClient) => {
|
|
33
|
+
const reply = isolatedClient.falkordb.delete(graph);
|
|
34
|
+
return reply.then(() => { });
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const reply = this.client.falkordb.delete(graph);
|
|
38
|
+
return reply.then(() => { });
|
|
39
|
+
}
|
|
40
|
+
async explain(graph, query) {
|
|
41
|
+
if (this.#usePool) {
|
|
42
|
+
return this.client.executeIsolated(async (isolatedClient) => {
|
|
43
|
+
return isolatedClient.falkordb.explain(graph, query);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return this.client.falkordb.explain(graph, query);
|
|
47
|
+
}
|
|
48
|
+
async profile(graph, query) {
|
|
49
|
+
if (this.#usePool) {
|
|
50
|
+
return this.client.executeIsolated(async (isolatedClient) => {
|
|
51
|
+
return isolatedClient.falkordb.profile(graph, query);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return this.client.falkordb.profile(graph, query);
|
|
55
|
+
}
|
|
56
|
+
async list() {
|
|
57
|
+
return this.client.falkordb.list();
|
|
58
|
+
}
|
|
59
|
+
async configGet(configKey) {
|
|
60
|
+
return this.client.falkordb.configGet(configKey);
|
|
61
|
+
}
|
|
62
|
+
async configSet(configKey, value) {
|
|
63
|
+
const reply = this.client.falkordb.configSet(configKey, value);
|
|
64
|
+
return reply.then(() => { });
|
|
65
|
+
}
|
|
66
|
+
async info(section) {
|
|
67
|
+
return this.client.falkordb.info(section);
|
|
68
|
+
}
|
|
69
|
+
async slowLog(graph) {
|
|
70
|
+
if (this.#usePool) {
|
|
71
|
+
return this.client.executeIsolated(async (isolatedClient) => {
|
|
72
|
+
return isolatedClient.falkordb.slowLog(graph);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return this.client.falkordb.slowLog(graph);
|
|
76
|
+
}
|
|
77
|
+
async constraintCreate(graph, constraintType, entityType, label, ...properties) {
|
|
78
|
+
const reply = this.client.falkordb.constraintCreate(graph, constraintType, entityType, label, ...properties);
|
|
79
|
+
return reply.then(() => { });
|
|
80
|
+
}
|
|
81
|
+
async constraintDrop(graph, constraintType, entityType, label, ...properties) {
|
|
82
|
+
const reply = this.client.falkordb.constraintDrop(graph, constraintType, entityType, label, ...properties);
|
|
83
|
+
return reply.then(() => { });
|
|
84
|
+
}
|
|
85
|
+
async copy(srcGraph, destGraph) {
|
|
86
|
+
return this.client.falkordb.copy(srcGraph, destGraph);
|
|
87
|
+
}
|
|
88
|
+
quit() {
|
|
89
|
+
return this.disconnect();
|
|
90
|
+
}
|
|
91
|
+
async disconnect() {
|
|
92
|
+
const reply = this.client.disconnect();
|
|
93
|
+
return reply.then(() => { });
|
|
94
|
+
}
|
|
95
|
+
async getConnection() {
|
|
96
|
+
return this.client;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.Single = Single;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const IS_READ_ONLY = true;
|
|
2
|
+
export declare function transformArguments(configKey: string): Array<string>;
|
|
3
|
+
type ConfigItem = [
|
|
4
|
+
configKey: string,
|
|
5
|
+
value: number
|
|
6
|
+
];
|
|
7
|
+
export declare function transformReply(): ConfigItem | Array<ConfigItem>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IS_READ_ONLY = void 0;
|
|
4
|
+
exports.transformArguments = transformArguments;
|
|
5
|
+
exports.IS_READ_ONLY = true;
|
|
6
|
+
function transformArguments(configKey) {
|
|
7
|
+
return ['GRAPH.CONFIG', 'GET', configKey];
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = transformArguments;
|
|
4
|
+
function transformArguments(configKey, value) {
|
|
5
|
+
return [
|
|
6
|
+
'GRAPH.CONFIG',
|
|
7
|
+
'SET',
|
|
8
|
+
configKey,
|
|
9
|
+
typeof value === "string" ? value : value.toString()
|
|
10
|
+
];
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare enum ConstraintType {
|
|
2
|
+
MANDATORY = "MANDATORY",
|
|
3
|
+
UNIQUE = "UNIQUE"
|
|
4
|
+
}
|
|
5
|
+
export declare enum EntityType {
|
|
6
|
+
NODE = "NODE",
|
|
7
|
+
RELATIONSHIP = "RELATIONSHIP"
|
|
8
|
+
}
|
|
9
|
+
export declare function transformArguments(key: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Array<string>;
|
|
10
|
+
export declare function transformReply(): 'PENDING';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityType = exports.ConstraintType = void 0;
|
|
4
|
+
exports.transformArguments = transformArguments;
|
|
5
|
+
var ConstraintType;
|
|
6
|
+
(function (ConstraintType) {
|
|
7
|
+
ConstraintType["MANDATORY"] = "MANDATORY";
|
|
8
|
+
ConstraintType["UNIQUE"] = "UNIQUE";
|
|
9
|
+
})(ConstraintType || (exports.ConstraintType = ConstraintType = {}));
|
|
10
|
+
var EntityType;
|
|
11
|
+
(function (EntityType) {
|
|
12
|
+
EntityType["NODE"] = "NODE";
|
|
13
|
+
EntityType["RELATIONSHIP"] = "RELATIONSHIP";
|
|
14
|
+
})(EntityType || (exports.EntityType = EntityType = {}));
|
|
15
|
+
// GRAPH.CONSTRAINT CREATE key constraintType {NODE label | RELATIONSHIP reltype} PROPERTIES propCount prop [prop...]
|
|
16
|
+
function transformArguments(key, constraintType, entityType, label, ...properties) {
|
|
17
|
+
return [
|
|
18
|
+
'GRAPH.CONSTRAINT', 'CREATE',
|
|
19
|
+
key, constraintType, entityType, label,
|
|
20
|
+
'PROPERTIES', properties.length.toString(), ...properties
|
|
21
|
+
];
|
|
22
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ConstraintType, EntityType } from "./CONSTRAINT_CREATE";
|
|
2
|
+
export declare function transformArguments(key: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Array<string>;
|
|
3
|
+
export declare function transformReply(): 'OK';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = transformArguments;
|
|
4
|
+
// GRAPH.CONSTRAINT DROP key constraintType {NODE label | RELATIONSHIP reltype} PROPERTIES propCount prop [prop...]
|
|
5
|
+
function transformArguments(key, constraintType, entityType, label, ...properties) {
|
|
6
|
+
return [
|
|
7
|
+
'GRAPH.CONSTRAINT', 'DROP',
|
|
8
|
+
key, constraintType, entityType, label,
|
|
9
|
+
'PROPERTIES', properties.length.toString(), ...properties
|
|
10
|
+
];
|
|
11
|
+
}
|