123
This commit is contained in:
34
node_modules/@redis/graph/README.md
generated
vendored
Normal file
34
node_modules/@redis/graph/README.md
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
# @redis/graph
|
||||
|
||||
Example usage:
|
||||
```javascript
|
||||
import { createClient, Graph } from 'redis';
|
||||
|
||||
const client = createClient();
|
||||
client.on('error', (err) => console.log('Redis Client Error', err));
|
||||
|
||||
await client.connect();
|
||||
|
||||
const graph = new Graph(client, 'graph');
|
||||
|
||||
await graph.query(
|
||||
'CREATE (:Rider { name: $riderName })-[:rides]->(:Team { name: $teamName })',
|
||||
{
|
||||
params: {
|
||||
riderName: 'Buzz Aldrin',
|
||||
teamName: 'Apollo'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const result = await graph.roQuery(
|
||||
'MATCH (r:Rider)-[:rides]->(t:Team { name: $name }) RETURN r.name AS name',
|
||||
{
|
||||
params: {
|
||||
name: 'Apollo'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
console.log(result.data); // [{ name: 'Buzz Aldrin' }]
|
||||
```
|
||||
8
node_modules/@redis/graph/dist/commands/CONFIG_GET.d.ts
generated
vendored
Normal file
8
node_modules/@redis/graph/dist/commands/CONFIG_GET.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
export declare const IS_READ_ONLY = true;
|
||||
export declare function transformArguments(configKey: string): Array<string>;
|
||||
type ConfigItem = [
|
||||
configKey: string,
|
||||
value: number
|
||||
];
|
||||
export declare function transformReply(): ConfigItem | Array<ConfigItem>;
|
||||
export {};
|
||||
8
node_modules/@redis/graph/dist/commands/CONFIG_GET.js
generated
vendored
Normal file
8
node_modules/@redis/graph/dist/commands/CONFIG_GET.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformArguments = exports.IS_READ_ONLY = void 0;
|
||||
exports.IS_READ_ONLY = true;
|
||||
function transformArguments(configKey) {
|
||||
return ['GRAPH.CONFIG', 'GET', configKey];
|
||||
}
|
||||
exports.transformArguments = transformArguments;
|
||||
2
node_modules/@redis/graph/dist/commands/CONFIG_SET.d.ts
generated
vendored
Normal file
2
node_modules/@redis/graph/dist/commands/CONFIG_SET.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export declare function transformArguments(configKey: string, value: number): Array<string>;
|
||||
export declare function transformReply(): 'OK';
|
||||
12
node_modules/@redis/graph/dist/commands/CONFIG_SET.js
generated
vendored
Normal file
12
node_modules/@redis/graph/dist/commands/CONFIG_SET.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformArguments = void 0;
|
||||
function transformArguments(configKey, value) {
|
||||
return [
|
||||
'GRAPH.CONFIG',
|
||||
'SET',
|
||||
configKey,
|
||||
value.toString()
|
||||
];
|
||||
}
|
||||
exports.transformArguments = transformArguments;
|
||||
3
node_modules/@redis/graph/dist/commands/DELETE.d.ts
generated
vendored
Normal file
3
node_modules/@redis/graph/dist/commands/DELETE.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export declare const FIRST_KEY_INDEX = 1;
|
||||
export declare function transformArguments(key: string): Array<string>;
|
||||
export declare function transformReply(): string;
|
||||
8
node_modules/@redis/graph/dist/commands/DELETE.js
generated
vendored
Normal file
8
node_modules/@redis/graph/dist/commands/DELETE.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
||||
exports.FIRST_KEY_INDEX = 1;
|
||||
function transformArguments(key) {
|
||||
return ['GRAPH.DELETE', key];
|
||||
}
|
||||
exports.transformArguments = transformArguments;
|
||||
4
node_modules/@redis/graph/dist/commands/EXPLAIN.d.ts
generated
vendored
Normal file
4
node_modules/@redis/graph/dist/commands/EXPLAIN.d.ts
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
export declare const FIRST_KEY_INDEX = 1;
|
||||
export declare const IS_READ_ONLY = true;
|
||||
export declare function transformArguments(key: string, query: string): Array<string>;
|
||||
export declare function transformReply(): Array<string>;
|
||||
9
node_modules/@redis/graph/dist/commands/EXPLAIN.js
generated
vendored
Normal file
9
node_modules/@redis/graph/dist/commands/EXPLAIN.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0;
|
||||
exports.FIRST_KEY_INDEX = 1;
|
||||
exports.IS_READ_ONLY = true;
|
||||
function transformArguments(key, query) {
|
||||
return ['GRAPH.EXPLAIN', key, query];
|
||||
}
|
||||
exports.transformArguments = transformArguments;
|
||||
3
node_modules/@redis/graph/dist/commands/LIST.d.ts
generated
vendored
Normal file
3
node_modules/@redis/graph/dist/commands/LIST.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export declare const IS_READ_ONLY = true;
|
||||
export declare function transformArguments(): Array<string>;
|
||||
export declare function transformReply(): Array<string>;
|
||||
8
node_modules/@redis/graph/dist/commands/LIST.js
generated
vendored
Normal file
8
node_modules/@redis/graph/dist/commands/LIST.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformArguments = exports.IS_READ_ONLY = void 0;
|
||||
exports.IS_READ_ONLY = true;
|
||||
function transformArguments() {
|
||||
return ['GRAPH.LIST'];
|
||||
}
|
||||
exports.transformArguments = transformArguments;
|
||||
4
node_modules/@redis/graph/dist/commands/PROFILE.d.ts
generated
vendored
Normal file
4
node_modules/@redis/graph/dist/commands/PROFILE.d.ts
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
export declare const FIRST_KEY_INDEX = 1;
|
||||
export declare const IS_READ_ONLY = true;
|
||||
export declare function transformArguments(key: string, query: string): Array<string>;
|
||||
export declare function transformReply(): Array<string>;
|
||||
9
node_modules/@redis/graph/dist/commands/PROFILE.js
generated
vendored
Normal file
9
node_modules/@redis/graph/dist/commands/PROFILE.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0;
|
||||
exports.FIRST_KEY_INDEX = 1;
|
||||
exports.IS_READ_ONLY = true;
|
||||
function transformArguments(key, query) {
|
||||
return ['GRAPH.PROFILE', key, query];
|
||||
}
|
||||
exports.transformArguments = transformArguments;
|
||||
25
node_modules/@redis/graph/dist/commands/QUERY.d.ts
generated
vendored
Normal file
25
node_modules/@redis/graph/dist/commands/QUERY.d.ts
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands/index';
|
||||
import { QueryOptionsBackwardCompatible } from '.';
|
||||
export declare const FIRST_KEY_INDEX = 1;
|
||||
export declare function transformArguments(graph: RedisCommandArgument, query: RedisCommandArgument, options?: QueryOptionsBackwardCompatible, compact?: boolean): RedisCommandArguments;
|
||||
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 declare function transformReply(reply: QueryRawReply): QueryReply;
|
||||
export {};
|
||||
21
node_modules/@redis/graph/dist/commands/QUERY.js
generated
vendored
Normal file
21
node_modules/@redis/graph/dist/commands/QUERY.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
||||
const _1 = require(".");
|
||||
exports.FIRST_KEY_INDEX = 1;
|
||||
function transformArguments(graph, query, options, compact) {
|
||||
return (0, _1.pushQueryArguments)(['GRAPH.QUERY'], graph, query, options, compact);
|
||||
}
|
||||
exports.transformArguments = transformArguments;
|
||||
function transformReply(reply) {
|
||||
return reply.length === 1 ? {
|
||||
headers: undefined,
|
||||
data: undefined,
|
||||
metadata: reply[0]
|
||||
} : {
|
||||
headers: reply[0],
|
||||
data: reply[1],
|
||||
metadata: reply[2]
|
||||
};
|
||||
}
|
||||
exports.transformReply = transformReply;
|
||||
6
node_modules/@redis/graph/dist/commands/RO_QUERY.d.ts
generated
vendored
Normal file
6
node_modules/@redis/graph/dist/commands/RO_QUERY.d.ts
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
|
||||
import { QueryOptionsBackwardCompatible } from '.';
|
||||
export { FIRST_KEY_INDEX } from './QUERY';
|
||||
export declare const IS_READ_ONLY = true;
|
||||
export declare function transformArguments(graph: RedisCommandArgument, query: RedisCommandArgument, options?: QueryOptionsBackwardCompatible, compact?: boolean): RedisCommandArguments;
|
||||
export { transformReply } from './QUERY';
|
||||
13
node_modules/@redis/graph/dist/commands/RO_QUERY.js
generated
vendored
Normal file
13
node_modules/@redis/graph/dist/commands/RO_QUERY.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformReply = exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0;
|
||||
const _1 = require(".");
|
||||
var QUERY_1 = require("./QUERY");
|
||||
Object.defineProperty(exports, "FIRST_KEY_INDEX", { enumerable: true, get: function () { return QUERY_1.FIRST_KEY_INDEX; } });
|
||||
exports.IS_READ_ONLY = true;
|
||||
function transformArguments(graph, query, options, compact) {
|
||||
return (0, _1.pushQueryArguments)(['GRAPH.RO_QUERY'], graph, query, options, compact);
|
||||
}
|
||||
exports.transformArguments = transformArguments;
|
||||
var QUERY_2 = require("./QUERY");
|
||||
Object.defineProperty(exports, "transformReply", { enumerable: true, get: function () { return QUERY_2.transformReply; } });
|
||||
17
node_modules/@redis/graph/dist/commands/SLOWLOG.d.ts
generated
vendored
Normal file
17
node_modules/@redis/graph/dist/commands/SLOWLOG.d.ts
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
export declare const IS_READ_ONLY = true;
|
||||
export declare const FIRST_KEY_INDEX = 1;
|
||||
export declare function transformArguments(key: string): string[];
|
||||
type SlowLogRawReply = Array<[
|
||||
timestamp: string,
|
||||
command: string,
|
||||
query: string,
|
||||
took: string
|
||||
]>;
|
||||
type SlowLogReply = Array<{
|
||||
timestamp: Date;
|
||||
command: string;
|
||||
query: string;
|
||||
took: number;
|
||||
}>;
|
||||
export declare function transformReply(logs: SlowLogRawReply): SlowLogReply;
|
||||
export {};
|
||||
18
node_modules/@redis/graph/dist/commands/SLOWLOG.js
generated
vendored
Normal file
18
node_modules/@redis/graph/dist/commands/SLOWLOG.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = exports.IS_READ_ONLY = void 0;
|
||||
exports.IS_READ_ONLY = true;
|
||||
exports.FIRST_KEY_INDEX = 1;
|
||||
function transformArguments(key) {
|
||||
return ['GRAPH.SLOWLOG', key];
|
||||
}
|
||||
exports.transformArguments = transformArguments;
|
||||
function transformReply(logs) {
|
||||
return logs.map(([timestamp, command, query, took]) => ({
|
||||
timestamp: new Date(Number(timestamp) * 1000),
|
||||
command,
|
||||
query,
|
||||
took: Number(took)
|
||||
}));
|
||||
}
|
||||
exports.transformReply = transformReply;
|
||||
41
node_modules/@redis/graph/dist/commands/index.d.ts
generated
vendored
Normal file
41
node_modules/@redis/graph/dist/commands/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
import * as CONFIG_GET from './CONFIG_GET';
|
||||
import * as CONFIG_SET from './CONFIG_SET';
|
||||
import * as DELETE from './DELETE';
|
||||
import * as EXPLAIN from './EXPLAIN';
|
||||
import * as LIST from './LIST';
|
||||
import * as PROFILE from './PROFILE';
|
||||
import * as QUERY from './QUERY';
|
||||
import * as RO_QUERY from './RO_QUERY';
|
||||
import * as SLOWLOG from './SLOWLOG';
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
|
||||
declare const _default: {
|
||||
CONFIG_GET: typeof CONFIG_GET;
|
||||
configGet: typeof CONFIG_GET;
|
||||
CONFIG_SET: typeof CONFIG_SET;
|
||||
configSet: typeof CONFIG_SET;
|
||||
DELETE: typeof DELETE;
|
||||
delete: typeof DELETE;
|
||||
EXPLAIN: typeof EXPLAIN;
|
||||
explain: typeof EXPLAIN;
|
||||
LIST: typeof LIST;
|
||||
list: typeof LIST;
|
||||
PROFILE: typeof PROFILE;
|
||||
profile: typeof PROFILE;
|
||||
QUERY: typeof QUERY;
|
||||
query: typeof QUERY;
|
||||
RO_QUERY: typeof RO_QUERY;
|
||||
roQuery: typeof RO_QUERY;
|
||||
SLOWLOG: typeof SLOWLOG;
|
||||
slowLog: typeof SLOWLOG;
|
||||
};
|
||||
export default _default;
|
||||
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 declare function pushQueryArguments(args: RedisCommandArguments, graph: RedisCommandArgument, query: RedisCommandArgument, options?: QueryOptionsBackwardCompatible, compact?: boolean): RedisCommandArguments;
|
||||
88
node_modules/@redis/graph/dist/commands/index.js
generated
vendored
Normal file
88
node_modules/@redis/graph/dist/commands/index.js
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.pushQueryArguments = void 0;
|
||||
const CONFIG_GET = require("./CONFIG_GET");
|
||||
const CONFIG_SET = require("./CONFIG_SET");
|
||||
;
|
||||
const DELETE = require("./DELETE");
|
||||
const EXPLAIN = require("./EXPLAIN");
|
||||
const LIST = require("./LIST");
|
||||
const PROFILE = require("./PROFILE");
|
||||
const QUERY = require("./QUERY");
|
||||
const RO_QUERY = require("./RO_QUERY");
|
||||
const SLOWLOG = require("./SLOWLOG");
|
||||
exports.default = {
|
||||
CONFIG_GET,
|
||||
configGet: CONFIG_GET,
|
||||
CONFIG_SET,
|
||||
configSet: CONFIG_SET,
|
||||
DELETE,
|
||||
delete: DELETE,
|
||||
EXPLAIN,
|
||||
explain: EXPLAIN,
|
||||
LIST,
|
||||
list: LIST,
|
||||
PROFILE,
|
||||
profile: PROFILE,
|
||||
QUERY,
|
||||
query: QUERY,
|
||||
RO_QUERY,
|
||||
roQuery: RO_QUERY,
|
||||
SLOWLOG,
|
||||
slowLog: SLOWLOG
|
||||
};
|
||||
function pushQueryArguments(args, graph, query, options, compact) {
|
||||
args.push(graph);
|
||||
if (typeof options === 'number') {
|
||||
args.push(query);
|
||||
pushTimeout(args, options);
|
||||
}
|
||||
else {
|
||||
args.push(options?.params ?
|
||||
`CYPHER ${queryParamsToString(options.params)} ${query}` :
|
||||
query);
|
||||
if (options?.TIMEOUT !== undefined) {
|
||||
pushTimeout(args, options.TIMEOUT);
|
||||
}
|
||||
}
|
||||
if (compact) {
|
||||
args.push('--compact');
|
||||
}
|
||||
return args;
|
||||
}
|
||||
exports.pushQueryArguments = pushQueryArguments;
|
||||
function pushTimeout(args, timeout) {
|
||||
args.push('TIMEOUT', timeout.toString());
|
||||
}
|
||||
function queryParamsToString(params) {
|
||||
const parts = [];
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
parts.push(`${key}=${queryParamToString(value)}`);
|
||||
}
|
||||
return parts.join(' ');
|
||||
}
|
||||
function queryParamToString(param) {
|
||||
if (param === null) {
|
||||
return 'null';
|
||||
}
|
||||
switch (typeof param) {
|
||||
case 'string':
|
||||
return `"${param.replace(/["\\]/g, '\\$&')}"`;
|
||||
case 'number':
|
||||
case 'boolean':
|
||||
return param.toString();
|
||||
}
|
||||
if (Array.isArray(param)) {
|
||||
return `[${param.map(queryParamToString).join(',')}]`;
|
||||
}
|
||||
else if (typeof param === 'object') {
|
||||
const body = [];
|
||||
for (const [key, value] of Object.entries(param)) {
|
||||
body.push(`${key}:${queryParamToString(value)}`);
|
||||
}
|
||||
return `{${body.join(',')}}`;
|
||||
}
|
||||
else {
|
||||
throw new TypeError(`Unexpected param type ${typeof param} ${param}`);
|
||||
}
|
||||
}
|
||||
19
node_modules/@redis/graph/dist/graph.d.ts
generated
vendored
Normal file
19
node_modules/@redis/graph/dist/graph.d.ts
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
import { RedisClientType } from '@redis/client/dist/lib/client/index';
|
||||
import { RedisCommandArgument, RedisFunctions, RedisScripts } from '@redis/client/dist/lib/commands';
|
||||
import { QueryOptions } from './commands';
|
||||
import { QueryReply } from './commands/QUERY';
|
||||
export type GraphReply<T> = Omit<QueryReply, 'headers' | 'data'> & {
|
||||
data?: Array<T>;
|
||||
};
|
||||
export type GraphClientType = RedisClientType<{
|
||||
graph: {
|
||||
query: typeof import('./commands/QUERY');
|
||||
roQuery: typeof import('./commands/RO_QUERY');
|
||||
};
|
||||
}, RedisFunctions, RedisScripts>;
|
||||
export default class Graph {
|
||||
#private;
|
||||
constructor(client: GraphClientType, name: string);
|
||||
query<T>(query: RedisCommandArgument, options?: QueryOptions): Promise<GraphReply<T>>;
|
||||
roQuery<T>(query: RedisCommandArgument, options?: QueryOptions): Promise<GraphReply<T>>;
|
||||
}
|
||||
173
node_modules/@redis/graph/dist/graph.js
generated
vendored
Normal file
173
node_modules/@redis/graph/dist/graph.js
generated
vendored
Normal file
@ -0,0 +1,173 @@
|
||||
"use strict";
|
||||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var _Graph_instances, _Graph_client, _Graph_name, _Graph_metadata, _Graph_setMetadataPromise, _Graph_updateMetadata, _Graph_setMetadata, _Graph_cleanMetadataArray, _Graph_getMetadata, _Graph_getMetadataAsync, _Graph_parseReply, _Graph_parseValue, _Graph_parseEdge, _Graph_parseNode, _Graph_parseProperties;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// https://github.com/RedisGraph/RedisGraph/blob/master/src/resultset/formatters/resultset_formatter.h#L20
|
||||
var GraphValueTypes;
|
||||
(function (GraphValueTypes) {
|
||||
GraphValueTypes[GraphValueTypes["UNKNOWN"] = 0] = "UNKNOWN";
|
||||
GraphValueTypes[GraphValueTypes["NULL"] = 1] = "NULL";
|
||||
GraphValueTypes[GraphValueTypes["STRING"] = 2] = "STRING";
|
||||
GraphValueTypes[GraphValueTypes["INTEGER"] = 3] = "INTEGER";
|
||||
GraphValueTypes[GraphValueTypes["BOOLEAN"] = 4] = "BOOLEAN";
|
||||
GraphValueTypes[GraphValueTypes["DOUBLE"] = 5] = "DOUBLE";
|
||||
GraphValueTypes[GraphValueTypes["ARRAY"] = 6] = "ARRAY";
|
||||
GraphValueTypes[GraphValueTypes["EDGE"] = 7] = "EDGE";
|
||||
GraphValueTypes[GraphValueTypes["NODE"] = 8] = "NODE";
|
||||
GraphValueTypes[GraphValueTypes["PATH"] = 9] = "PATH";
|
||||
GraphValueTypes[GraphValueTypes["MAP"] = 10] = "MAP";
|
||||
GraphValueTypes[GraphValueTypes["POINT"] = 11] = "POINT";
|
||||
})(GraphValueTypes || (GraphValueTypes = {}));
|
||||
class Graph {
|
||||
constructor(client, name) {
|
||||
_Graph_instances.add(this);
|
||||
_Graph_client.set(this, void 0);
|
||||
_Graph_name.set(this, void 0);
|
||||
_Graph_metadata.set(this, void 0);
|
||||
_Graph_setMetadataPromise.set(this, void 0);
|
||||
__classPrivateFieldSet(this, _Graph_client, client, "f");
|
||||
__classPrivateFieldSet(this, _Graph_name, name, "f");
|
||||
}
|
||||
async query(query, options) {
|
||||
return __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseReply).call(this, await __classPrivateFieldGet(this, _Graph_client, "f").graph.query(__classPrivateFieldGet(this, _Graph_name, "f"), query, options, true));
|
||||
}
|
||||
async roQuery(query, options) {
|
||||
return __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseReply).call(this, await __classPrivateFieldGet(this, _Graph_client, "f").graph.roQuery(__classPrivateFieldGet(this, _Graph_name, "f"), query, options, true));
|
||||
}
|
||||
}
|
||||
_Graph_client = new WeakMap(), _Graph_name = new WeakMap(), _Graph_metadata = new WeakMap(), _Graph_setMetadataPromise = new WeakMap(), _Graph_instances = new WeakSet(), _Graph_updateMetadata = function _Graph_updateMetadata() {
|
||||
__classPrivateFieldSet(this, _Graph_setMetadataPromise, __classPrivateFieldGet(this, _Graph_setMetadataPromise, "f") ?? __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_setMetadata).call(this)
|
||||
.finally(() => __classPrivateFieldSet(this, _Graph_setMetadataPromise, undefined, "f")), "f");
|
||||
return __classPrivateFieldGet(this, _Graph_setMetadataPromise, "f");
|
||||
}, _Graph_setMetadata =
|
||||
// DO NOT use directly, use #updateMetadata instead
|
||||
async function _Graph_setMetadata() {
|
||||
const [labels, relationshipTypes, propertyKeys] = await Promise.all([
|
||||
__classPrivateFieldGet(this, _Graph_client, "f").graph.roQuery(__classPrivateFieldGet(this, _Graph_name, "f"), 'CALL db.labels()'),
|
||||
__classPrivateFieldGet(this, _Graph_client, "f").graph.roQuery(__classPrivateFieldGet(this, _Graph_name, "f"), 'CALL db.relationshipTypes()'),
|
||||
__classPrivateFieldGet(this, _Graph_client, "f").graph.roQuery(__classPrivateFieldGet(this, _Graph_name, "f"), 'CALL db.propertyKeys()')
|
||||
]);
|
||||
__classPrivateFieldSet(this, _Graph_metadata, {
|
||||
labels: __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_cleanMetadataArray).call(this, labels.data),
|
||||
relationshipTypes: __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_cleanMetadataArray).call(this, relationshipTypes.data),
|
||||
propertyKeys: __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_cleanMetadataArray).call(this, propertyKeys.data)
|
||||
}, "f");
|
||||
return __classPrivateFieldGet(this, _Graph_metadata, "f");
|
||||
}, _Graph_cleanMetadataArray = function _Graph_cleanMetadataArray(arr) {
|
||||
return arr.map(([value]) => value);
|
||||
}, _Graph_getMetadata = function _Graph_getMetadata(key, id) {
|
||||
return __classPrivateFieldGet(this, _Graph_metadata, "f")?.[key][id] ?? __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_getMetadataAsync).call(this, key, id);
|
||||
}, _Graph_getMetadataAsync =
|
||||
// DO NOT use directly, use #getMetadata instead
|
||||
async function _Graph_getMetadataAsync(key, id) {
|
||||
const value = (await __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_updateMetadata).call(this))[key][id];
|
||||
if (value === undefined)
|
||||
throw new Error(`Cannot find value from ${key}[${id}]`);
|
||||
return value;
|
||||
}, _Graph_parseReply = async function _Graph_parseReply(reply) {
|
||||
if (!reply.data)
|
||||
return reply;
|
||||
const promises = [], parsed = {
|
||||
metadata: reply.metadata,
|
||||
data: reply.data.map((row) => {
|
||||
const data = {};
|
||||
for (let i = 0; i < row.length; i++) {
|
||||
data[reply.headers[i][1]] = __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseValue).call(this, row[i], promises);
|
||||
}
|
||||
return data;
|
||||
})
|
||||
};
|
||||
if (promises.length)
|
||||
await Promise.all(promises);
|
||||
return parsed;
|
||||
}, _Graph_parseValue = function _Graph_parseValue([valueType, value], promises) {
|
||||
switch (valueType) {
|
||||
case GraphValueTypes.NULL:
|
||||
return null;
|
||||
case GraphValueTypes.STRING:
|
||||
case GraphValueTypes.INTEGER:
|
||||
return value;
|
||||
case GraphValueTypes.BOOLEAN:
|
||||
return value === 'true';
|
||||
case GraphValueTypes.DOUBLE:
|
||||
return parseFloat(value);
|
||||
case GraphValueTypes.ARRAY:
|
||||
return value.map(x => __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseValue).call(this, x, promises));
|
||||
case GraphValueTypes.EDGE:
|
||||
return __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseEdge).call(this, value, promises);
|
||||
case GraphValueTypes.NODE:
|
||||
return __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseNode).call(this, value, promises);
|
||||
case GraphValueTypes.PATH:
|
||||
return {
|
||||
nodes: value[0][1].map(([, node]) => __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseNode).call(this, node, promises)),
|
||||
edges: value[1][1].map(([, edge]) => __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseEdge).call(this, edge, promises))
|
||||
};
|
||||
case GraphValueTypes.MAP:
|
||||
const map = {};
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
map[value[i++]] = __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseValue).call(this, value[i], promises);
|
||||
}
|
||||
return map;
|
||||
case GraphValueTypes.POINT:
|
||||
return {
|
||||
latitude: parseFloat(value[0]),
|
||||
longitude: parseFloat(value[1])
|
||||
};
|
||||
default:
|
||||
throw new Error(`unknown scalar type: ${valueType}`);
|
||||
}
|
||||
}, _Graph_parseEdge = function _Graph_parseEdge([id, relationshipTypeId, sourceId, destinationId, properties], promises) {
|
||||
const edge = {
|
||||
id,
|
||||
sourceId,
|
||||
destinationId,
|
||||
properties: __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseProperties).call(this, properties, promises)
|
||||
};
|
||||
const relationshipType = __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_getMetadata).call(this, 'relationshipTypes', relationshipTypeId);
|
||||
if (relationshipType instanceof Promise) {
|
||||
promises.push(relationshipType.then(value => edge.relationshipType = value));
|
||||
}
|
||||
else {
|
||||
edge.relationshipType = relationshipType;
|
||||
}
|
||||
return edge;
|
||||
}, _Graph_parseNode = function _Graph_parseNode([id, labelIds, properties], promises) {
|
||||
const labels = new Array(labelIds.length);
|
||||
for (let i = 0; i < labelIds.length; i++) {
|
||||
const value = __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_getMetadata).call(this, 'labels', labelIds[i]);
|
||||
if (value instanceof Promise) {
|
||||
promises.push(value.then(value => labels[i] = value));
|
||||
}
|
||||
else {
|
||||
labels[i] = value;
|
||||
}
|
||||
}
|
||||
return {
|
||||
id,
|
||||
labels,
|
||||
properties: __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseProperties).call(this, properties, promises)
|
||||
};
|
||||
}, _Graph_parseProperties = function _Graph_parseProperties(raw, promises) {
|
||||
const parsed = {};
|
||||
for (const [id, type, value] of raw) {
|
||||
const parsedValue = __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_parseValue).call(this, [type, value], promises), key = __classPrivateFieldGet(this, _Graph_instances, "m", _Graph_getMetadata).call(this, 'propertyKeys', id);
|
||||
if (key instanceof Promise) {
|
||||
promises.push(key.then(key => parsed[key] = parsedValue));
|
||||
}
|
||||
else {
|
||||
parsed[key] = parsedValue;
|
||||
}
|
||||
}
|
||||
return parsed;
|
||||
};
|
||||
exports.default = Graph;
|
||||
2
node_modules/@redis/graph/dist/index.d.ts
generated
vendored
Normal file
2
node_modules/@redis/graph/dist/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export { default } from './commands';
|
||||
export { default as Graph } from './graph';
|
||||
7
node_modules/@redis/graph/dist/index.js
generated
vendored
Normal file
7
node_modules/@redis/graph/dist/index.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Graph = exports.default = void 0;
|
||||
var commands_1 = require("./commands");
|
||||
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return commands_1.default; } });
|
||||
var graph_1 = require("./graph");
|
||||
Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return graph_1.default; } });
|
||||
41
node_modules/@redis/graph/package.json
generated
vendored
Normal file
41
node_modules/@redis/graph/package.json
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "@redis/graph",
|
||||
"version": "1.1.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "nyc -r text-summary -r lcov mocha -r source-map-support/register -r ts-node/register './lib/**/*.spec.ts'",
|
||||
"build": "tsc",
|
||||
"documentation": "typedoc"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@redis/client": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
||||
"@redis/test-utils": "*",
|
||||
"@types/node": "^20.6.2",
|
||||
"nyc": "^15.1.0",
|
||||
"release-it": "^16.1.5",
|
||||
"source-map-support": "^0.5.21",
|
||||
"ts-node": "^10.9.1",
|
||||
"typedoc": "^0.25.1",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/redis/node-redis.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/redis/node-redis/issues"
|
||||
},
|
||||
"homepage": "https://github.com/redis/node-redis/tree/master/packages/graph",
|
||||
"keywords": [
|
||||
"redis",
|
||||
"RedisGraph"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user