falkordb 6.2.0 → 6.2.1

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.
@@ -2,6 +2,7 @@ import { RedisCommandArgument } from "@redis/client/dist/lib/commands";
2
2
  import { QueryOptions } from "../commands";
3
3
  import { ConstraintType, EntityType } from "../graph";
4
4
  import FalkorDB from "../falkordb";
5
+ import { SingleGraphConnection } from "./single";
5
6
  export interface Client {
6
7
  init(falkordb: FalkorDB): Promise<void>;
7
8
  list(): Promise<Array<string>>;
@@ -23,4 +24,5 @@ export interface Client {
23
24
  constraintCreate(graph: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Promise<void>;
24
25
  constraintDrop(graph: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Promise<void>;
25
26
  quit(): Promise<void>;
27
+ getConnection(): Promise<SingleGraphConnection>;
26
28
  }
@@ -14,6 +14,9 @@ export type ClusterGraphConnection = RedisClusterType<{
14
14
  export declare class Cluster implements Client {
15
15
  #private;
16
16
  constructor(client: SingleGraphConnection);
17
+ getConnection(): Promise<import("@redis/client").RedisClientType<{
18
+ falkordb: typeof commands;
19
+ }, RedisFunctions, RedisScripts>>;
17
20
  init(falkordb: FalkorDB): Promise<void>;
18
21
  query<T>(graph: string, query: RedisCommandArgument, options?: QueryOptions): Promise<{
19
22
  headers: undefined;
@@ -20,6 +20,10 @@ class Cluster {
20
20
  client.disconnect();
21
21
  this.#client = (0, client_1.createCluster)(redisClusterOption);
22
22
  }
23
+ async getConnection() {
24
+ const connection = this.#client.nodeClient(this.#client.getRandomNode());
25
+ return connection instanceof Promise ? await connection : connection;
26
+ }
23
27
  async init(falkordb) {
24
28
  await this.#client
25
29
  .on('error', err => falkordb.emit('error', err)) // Forward errors
@@ -3,6 +3,7 @@ import { QueryOptions } from "../commands";
3
3
  import FalkorDB from "../falkordb";
4
4
  import { ConstraintType, EntityType } from "../graph";
5
5
  import { Client } from "./client";
6
+ import { SingleGraphConnection } from "./single";
6
7
  /**
7
8
  * The `NullClient` class is a placeholder implementation of the `Client` interface.
8
9
  *
@@ -15,6 +16,7 @@ import { Client } from "./client";
15
16
  *
16
17
  */
17
18
  export declare class NullClient implements Client {
19
+ getConnection(): Promise<SingleGraphConnection>;
18
20
  init(falkordb: FalkorDB): Promise<void>;
19
21
  list(): Promise<Array<string>>;
20
22
  configGet(configKey: string): Promise<(string | number)[] | (string | number)[][]>;
@@ -13,6 +13,9 @@ exports.NullClient = void 0;
13
13
  *
14
14
  */
15
15
  class NullClient {
16
+ getConnection() {
17
+ throw new Error("Method not implemented.");
18
+ }
16
19
  init(falkordb) {
17
20
  throw new Error("Method not implemented.");
18
21
  }
@@ -47,4 +47,5 @@ export declare class Single implements Client {
47
47
  constraintDrop(graph: string, constraintType: ConstraintType, entityType: EntityType, label: string, ...properties: string[]): Promise<void>;
48
48
  copy<T>(srcGraph: string, destGraph: string): Promise<"OK">;
49
49
  quit(): Promise<void>;
50
+ getConnection(): Promise<SingleGraphConnection>;
50
51
  }
@@ -91,5 +91,8 @@ class Single {
91
91
  const reply = this.client.quit();
92
92
  return reply.then(() => { });
93
93
  }
94
+ async getConnection() {
95
+ return this.client;
96
+ }
94
97
  }
95
98
  exports.Single = Single;
@@ -6,7 +6,7 @@ import Graph from './graph';
6
6
  import commands from './commands';
7
7
  import { RedisClusterOptions } from '@redis/client';
8
8
  import { Options as PoolOptions } from 'generic-pool';
9
- import { Client } from './clients/client';
9
+ import { SingleGraphConnection } from './clients/single';
10
10
  type NetSocketOptions = Partial<net.SocketConnectOpts> & {
11
11
  tls?: false;
12
12
  };
@@ -85,7 +85,7 @@ export default class FalkorDB extends EventEmitter {
85
85
  #private;
86
86
  static connect(options?: FalkorDBOptions): Promise<FalkorDB>;
87
87
  selectGraph(graphId: string): Graph;
88
- get connection(): Client;
88
+ get connection(): Promise<SingleGraphConnection>;
89
89
  list(): Promise<string[]>;
90
90
  configGet(configKey: string): Promise<(string | number)[] | (string | number)[][]>;
91
91
  configSet(configKey: string, value: number | string): Promise<void>;
@@ -52,7 +52,7 @@ class FalkorDB extends events_1.EventEmitter {
52
52
  return new graph_1.default(this.#client, graphId);
53
53
  }
54
54
  get connection() {
55
- return this.#client;
55
+ return this.#client.getConnection();
56
56
  }
57
57
  async list() {
58
58
  return this.#client.list();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "falkordb",
3
- "version": "6.2.0",
3
+ "version": "6.2.1",
4
4
  "description": "A FalkorDB javascript library",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",