Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { default as Graph } from './src/graph';
export { ConstraintType, EntityType } from './src/graph';
export { ConstraintType, EntityType } from './src/commands/CONSTRAINT_CREATE';
export { default as FalkorDB } from './src/falkordb';


Expand Down
6 changes: 2 additions & 4 deletions src/clients/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { RedisCommandArgument } from "@redis/client/dist/lib/commands";
import { QueryOptions } from "../commands";
import { ConstraintType, EntityType } from "../graph";
import FalkorDB from "../falkordb";
import { SingleGraphConnection } from "./single";
import { MemoryUsageOptions, MemoryUsageReply } from "../commands/MEMORY_USAGE";
import { ConstraintType, EntityType } from "../enums";
import { MemoryUsageOptions, MemoryUsageReply, QueryOptions, SingleGraphConnection } from "../types";

// A generic client interface for Redis clients
export interface Client {
Expand Down
24 changes: 13 additions & 11 deletions src/clients/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { Client } from "./client";
import { ConstraintType, EntityType } from "../graph";

import {
RedisCommandArgument,
RedisFunctions,
RedisScripts,
} from "@redis/client/dist/lib/commands";
import commands, { QueryOptions } from "../commands";
import { createCluster, RedisClusterType } from "@redis/client";
import FalkorDB, { TypedRedisClusterClientOptions } from "../falkordb";
import { SingleGraphConnection } from "./single";
import commands from "../commands";
import { createCluster } from "@redis/client";
import FalkorDB, { } from "../falkordb";
import { RedisClusterClientOptions } from "@redis/client/dist/lib/cluster";
import * as lodash from "lodash";
import { MemoryUsageOptions, MemoryUsageReply } from "../commands/MEMORY_USAGE";
export type ClusterGraphConnection = RedisClusterType<
{ falkordb: typeof commands },
RedisFunctions,
RedisScripts
>;
import {
ClusterGraphConnection,
MemoryUsageOptions,
MemoryUsageReply,
QueryOptions,
SingleGraphConnection,
TypedRedisClusterClientOptions
} from "../types";
import { ConstraintType, EntityType } from "../enums";

/**
* A client that connects to a Redis Cluster.
Expand Down
6 changes: 2 additions & 4 deletions src/clients/nullClient.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { RedisCommandArgument } from "@redis/client/dist/lib/commands";
import { QueryOptions } from "../commands";
import FalkorDB from "../falkordb";
import { ConstraintType, EntityType } from "../graph";
import { Client } from "./client";
import { SingleGraphConnection } from "./single";
import { MemoryUsageOptions, MemoryUsageReply } from "../commands/MEMORY_USAGE";
import { ConstraintType, EntityType } from "../enums";
import { MemoryUsageOptions, MemoryUsageReply, QueryOptions, SingleGraphConnection } from "../types";

/**
* The `NullClient` class is a placeholder implementation of the `Client` interface.
Expand Down
5 changes: 3 additions & 2 deletions src/clients/sentinel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as tls from "tls";
import { Single, SingleGraphConnection } from "./single";
import FalkorDB, { TypedRedisClientOptions } from "../falkordb";
import { Single } from "./single";
import FalkorDB from "../falkordb";
import { createClient, RedisFunctions, RedisScripts } from "@redis/client";
import commands from "../commands";
import { SingleGraphConnection, TypedRedisClientOptions } from "../types";

function extractDetails(masters: Array<Array<string>>) {
const allDetails: Record<string, string>[] = [];
Expand Down
14 changes: 2 additions & 12 deletions src/clients/single.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { Client } from "./client";
import { ConstraintType, EntityType } from "../graph";
import {
RedisCommandArgument,
RedisFunctions,
RedisScripts,
} from "@redis/client/dist/lib/commands";
import commands, { QueryOptions } from "../commands";
import { RedisClientType } from "@redis/client";
import FalkorDB from "../falkordb";
import { MemoryUsageOptions, MemoryUsageReply } from "../commands/MEMORY_USAGE";

export type SingleGraphConnection = RedisClientType<
{ falkordb: typeof commands },
RedisFunctions,
RedisScripts
>;
import { ConstraintType, EntityType } from "../enums";
import { MemoryUsageOptions, MemoryUsageReply, QueryOptions, SingleGraphConnection } from "../types";

export class Single implements Client {
protected client: SingleGraphConnection;
Expand Down
7 changes: 2 additions & 5 deletions src/commands/CONFIG_GET.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { ConfigItem } from "../types";

export const IS_READ_ONLY = true;

export function transformArguments(configKey: string): Array<string> {
return ['GRAPH.CONFIG', 'GET', configKey];
}

type ConfigItem = [
configKey: string,
value: number
];

export declare function transformReply(): ConfigItem | Array<ConfigItem>;
11 changes: 1 addition & 10 deletions src/commands/CONSTRAINT_CREATE.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@

export enum ConstraintType {
MANDATORY = "MANDATORY",
UNIQUE = "UNIQUE"
}

export enum EntityType {
NODE = "NODE",
RELATIONSHIP = "RELATIONSHIP"
}
import { ConstraintType, EntityType } from "../enums";

// GRAPH.CONSTRAINT CREATE key constraintType {NODE label | RELATIONSHIP reltype} PROPERTIES propCount prop [prop...]
export function transformArguments(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/CONSTRAINT_DROP.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConstraintType, EntityType } from "./CONSTRAINT_CREATE";
import { ConstraintType, EntityType } from "../enums";

// GRAPH.CONSTRAINT DROP key constraintType {NODE label | RELATIONSHIP reltype} PROPERTIES propCount prop [prop...]
export function transformArguments(
Expand Down
6 changes: 1 addition & 5 deletions src/commands/MEMORY_USAGE.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export interface MemoryUsageOptions {
SAMPLES?: number
}
import { MemoryUsageOptions, MemoryUsageReply } from "../types";

export function transformArguments(
key: string,
Expand All @@ -10,6 +8,4 @@ export function transformArguments(
return options?.SAMPLES ? [...args, String(options.SAMPLES)] : [...args];
}

export type MemoryUsageReply = Array<string | number | MemoryUsageReply>;

export declare function transformReply(): MemoryUsageReply;
27 changes: 2 additions & 25 deletions src/commands/QUERY.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
import { pushQueryArguments, QueryOptionsBackwardCompatible } from '.';
import { pushQueryArguments } from '.';
import { QueryOptionsBackwardCompatible, QueryRawReply, QueryReply } from '../types';

export const FIRST_KEY_INDEX = 1;

Expand All @@ -18,30 +19,6 @@ export function transformArguments(
);
}

type Headers = Array<string>;

type Data = Array<string | number | null | Data>;

type Metadata = Array<string>;

type QueryRawReply = [
headers: Headers,
data: Data,
metadata: Metadata
] | [
metadata: Metadata
];

export type QueryReply = {
headers: undefined;
data: undefined;
metadata: Metadata;
} | {
headers: Headers;
data: Data;
metadata: Metadata;
};

export function transformReply(reply: QueryRawReply): QueryReply {
return reply.length === 1 ? {
headers: undefined,
Expand Down
16 changes: 2 additions & 14 deletions src/commands/SLOWLOG.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SlowLogRawReply, SlowLogReply } from "../types";

export const IS_READ_ONLY = true;

export const FIRST_KEY_INDEX = 1;
Expand All @@ -6,20 +8,6 @@ export function transformArguments(key: string) {
return ['GRAPH.SLOWLOG', key];
}

type SlowLogRawReply = Array<[
timestamp: string,
command: string,
query: string,
took: string
]>;

type SlowLogReply = Array<{
timestamp: Date;
command: string;
query: string;
took: number;
}>;

export function transformReply(logs: SlowLogRawReply): SlowLogReply {
return logs.map(([timestamp, command, query, took]) => ({
timestamp: new Date(Number(timestamp) * 1000),
Expand Down
14 changes: 1 addition & 13 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as SENTINEL_MASTERS from './SENTINEL_MASTERS';
import * as MEMORY_USAGE from './MEMORY_USAGE';

import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
import { QueryOptionsBackwardCompatible, QueryParam, QueryParams } from '../types';

export default {
CONFIG_GET,
Expand Down Expand Up @@ -52,19 +53,6 @@ export default {
memoryUsage: MEMORY_USAGE,
};

type QueryParam = null | string | number | boolean | QueryParams | Array<QueryParam>;

type QueryParams = {
[key: string]: QueryParam;
};

export interface QueryOptions {
params?: QueryParams;
TIMEOUT?: number;
}

export type QueryOptionsBackwardCompatible = QueryOptions | number;

export function pushQueryArguments(
args: RedisCommandArguments,
graph: RedisCommandArgument,
Expand Down
5 changes: 5 additions & 0 deletions src/enums/constraint-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum ConstraintType {
MANDATORY = "MANDATORY",
UNIQUE = "UNIQUE"
}

4 changes: 4 additions & 0 deletions src/enums/entity-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum EntityType {
NODE = "NODE",
RELATIONSHIP = "RELATIONSHIP"
}
20 changes: 20 additions & 0 deletions src/enums/graph-value-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// https://github.com/FalkorDB/FalkorDB/blob/master/src/resultset/formatters/resultset_formatter.h#L20
export enum GraphValueTypes {
UNKNOWN = 0,
NULL = 1,
STRING = 2,
INTEGER = 3,
BOOLEAN = 4,
DOUBLE = 5,
ARRAY = 6,
EDGE = 7,
NODE = 8,
PATH = 9,
MAP = 10,
POINT = 11,
VECTORF32 = 12,
DATETIME = 13,
DATE = 14,
TIME = 15,
DURATION = 16,
}
3 changes: 3 additions & 0 deletions src/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './graph-value-types'
export * from './entity-type'
export * from './constraint-type'
Loading