Skip to content

Commit

Permalink
Merge pull request #606 from FalkorDB/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
AviAvni authored Jan 15, 2025
2 parents 1a894e6 + 99d06e2 commit f8d1e06
Show file tree
Hide file tree
Showing 91 changed files with 8,133 additions and 5,138 deletions.
15 changes: 15 additions & 0 deletions app/GTM.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use client"

import { useEffect } from "react";
import TagManager from "react-gtm-module";

export default function GTM() {
useEffect(() => {
const gtmId = process.env.NEXT_PUBLIC_GTM_ID
if (gtmId) {
TagManager.initialize({ gtmId });
}
}, []);

return null;
}
6 changes: 3 additions & 3 deletions app/api/graph/[graph]/[node]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { NextRequest, NextResponse } from "next/server";
import { getClient } from "@/app/api/auth/[...nextauth]/options";

// eslint-disable-next-line import/prefer-default-export
export async function GET(request: NextRequest, { params }: { params: { graph: string, node: string } }) {
export async function GET(request: NextRequest, { params }: { params: Promise<{ graph: string, node: string }> }) {

const client = await getClient()
if (client instanceof NextResponse) {
return client
}

const nodeId = parseInt(params.node, 10);
const graphId = params.graph;
const { graph: graphId, node: nodeId } = await params

const graph = client.selectGraph(graphId);

Expand All @@ -23,6 +22,7 @@ export async function GET(request: NextRequest, { params }: { params: { graph: s
const result = await graph.query(query, { params: { nodeId } });
return NextResponse.json({ result }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
8 changes: 4 additions & 4 deletions app/api/graph/[graph]/export/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { NextRequest, NextResponse } from "next/server";
import { commandOptions } from "redis";

// eslint-disable-next-line import/prefer-default-export
export async function GET(request: NextRequest, { params } : { params : { graph: string } }) {
export async function GET(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {

const client = await getClient()
if (client instanceof NextResponse) {
return client
}

const graphId = params.graph
const { graph: graphId } = await params

try {

const result = await (await client.connection).dump(
commandOptions({ returnBuffers: true }),
graphId
)
if (!result) throw new Error(`Failed to retrieve graph data for ID: ${graphId}`)

return new NextResponse(result, {
status: 200,
headers: {
Expand Down
56 changes: 27 additions & 29 deletions app/api/graph/[graph]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { getClient } from "@/app/api/auth/[...nextauth]/options";
import { prepareArg, securedFetch } from "@/lib/utils";

// eslint-disable-next-line import/prefer-default-export
export async function DELETE(request: NextRequest, { params }: { params: { graph: string } }) {
export async function DELETE(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {

const client = await getClient()
if (client instanceof NextResponse) {
return client
}

const graphId = params.graph;
const { graph: graphId } = await params;

try {
if (graphId) {
Expand All @@ -22,58 +22,52 @@ export async function DELETE(request: NextRequest, { params }: { params: { graph
return NextResponse.json({ message: `${graphId} graph deleted` })
}
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}

// eslint-disable-next-line import/prefer-default-export
export async function POST(request: NextRequest, { params }: { params: { graph: string } }) {
export async function POST(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {

const client = await getClient()
if (client instanceof NextResponse) {
return client
}

const graphId = params.graph;
const { graph: name } = await params;
const sourceName = request.nextUrl.searchParams.get("sourceName")

try {
if (sourceName) {
const graph = client.selectGraph(sourceName);
const success = await graph.copy(graphId)
const success = await graph.copy(name)
if (!success) throw new Error("Failed to copy graph")
return NextResponse.json({ success }, { status: 200 })
}

const type = request.nextUrl.searchParams.get("type")
const key = request.nextUrl.searchParams.get("key")
const openaikey = request.nextUrl.searchParams.get("key")
const srcs = await request.json()

if (!key) console.error("Missing parameter 'key'")

if (!srcs) console.error("Missing parameter 'srcs'")

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const socket = (await client.connection).options?.socket as any

if (!socket) console.error("socket not found")
const { host, port } = (await client.connection).options?.socket as any

const data = {
host: socket.host,
port: socket.port,
name: graphId,
srcs,
openaikey: key,
}

if (!type) console.error("Missing parameter 'type'")
if (!openaikey || !srcs || !host || !port || !type) throw new Error("Missing parameters")

const res = await securedFetch(`http://localhost:5000/${prepareArg(type!)}`, {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
body: JSON.stringify({
host,
port,
name,
srcs,
openaikey,
})
})

const result = await res.json()
Expand All @@ -82,42 +76,45 @@ export async function POST(request: NextRequest, { params }: { params: { graph:

return NextResponse.json({ result }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}

// eslint-disable-next-line import/prefer-default-export
export async function PATCH(request: NextRequest, { params }: { params: { graph: string } }) {
export async function PATCH(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {

const client = await getClient()
if (client instanceof NextResponse) {
return client
}

const graphId = params.graph;
const { graph: graphId } = await params;
const sourceName = request.nextUrl.searchParams.get("sourceName")

try {
if (!sourceName) throw (new Error("Missing parameter 'sourceName'"))
if (!sourceName) throw new Error("Missing parameter sourceName")

const data = await (await client.connection).renameNX(sourceName, graphId);

if (!data) throw new Error(`${graphId} already exists`)

return NextResponse.json({ data })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}

export async function GET(request: NextRequest, { params }: { params: { graph: string } }) {
export async function GET(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {

const client = await getClient()
if (client instanceof NextResponse) {
return client
}

const graphId = params.graph
const { graph: graphId } = await params

const ID = request.nextUrl.searchParams.get("ID")

try {
Expand All @@ -134,7 +131,7 @@ export async function GET(request: NextRequest, { params }: { params: { graph: s
const create = request.nextUrl.searchParams.get("create")
const role = request.nextUrl.searchParams.get("role")

if (!query) throw new Error("Missing parameter 'query'")
if (!query) throw new Error("Missing parameter query")

if (create === "false" && !(await client.list()).some((g) => g === graphId))
return NextResponse.json({}, { status: 200 })
Expand All @@ -145,10 +142,11 @@ export async function GET(request: NextRequest, { params }: { params: { graph: s
? await graph.roQuery(query)
: await graph.query(query)

if (!result) throw new Error("something went wrong")
if (!result) throw new Error("Something went wrong")

return NextResponse.json({ result }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
Loading

1 comment on commit f8d1e06

@vercel
Copy link

@vercel vercel bot commented on f8d1e06 Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.