{"version":3,"file":"memgraph_graph.cjs","names":["Neo4jGraph"],"sources":["../../src/graphs/memgraph_graph.ts"],"sourcesContent":["import { Neo4jGraph } from \"./neo4j_graph.js\";\n\ninterface MemgraphGraphConfig {\n  url: string;\n  username: string;\n  password: string;\n  database?: string;\n}\n\nconst rawSchemaQuery = `\nCALL llm_util.schema(\"raw\")\nYIELD *\nRETURN *\n`;\n\n/**\n * @security *Security note*: Make sure that the database connection uses credentials\n * that are narrowly-scoped to only include necessary permissions.\n * Failure to do so may result in data corruption or loss, since the calling\n * code may attempt commands that would result in deletion, mutation\n * of data if appropriately prompted or reading sensitive data if such\n * data is present in the database.\n * The best way to guard against such negative outcomes is to (as appropriate)\n * limit the permissions granted to the credentials used with this tool.\n * For example, creating read only users for the database is a good way to\n * ensure that the calling code cannot mutate or delete data.\n *\n * @link See https://js.langchain.com/docs/security for more information.\n */\nclass MemgraphGraph extends Neo4jGraph {\n  constructor({\n    url,\n    username,\n    password,\n    database = \"memgraph\",\n  }: MemgraphGraphConfig) {\n    super({ url, username, password, database });\n  }\n\n  static async initialize(config: MemgraphGraphConfig): Promise<MemgraphGraph> {\n    const graph = new MemgraphGraph(config);\n\n    try {\n      await graph.verifyConnectivity();\n    } catch {\n      console.error(\"Failed to verify connection.\");\n    }\n\n    try {\n      await graph.refreshSchema();\n      console.debug(\"Schema refreshed successfully.\");\n      // oxlint-disable-next-line typescript/no-explicit-any\n    } catch (error: any) {\n      throw new Error(error.message);\n    }\n\n    return graph;\n  }\n\n  async refreshSchema() {\n    const rawSchemaQueryResult = await this.query(rawSchemaQuery);\n    if (rawSchemaQueryResult?.[0]?.schema) {\n      const rawSchema = rawSchemaQueryResult?.[0]?.schema;\n\n      this.structuredSchema = {\n        nodeProps: rawSchema.node_props,\n        relProps: rawSchema.rel_props,\n        relationships: rawSchema.relationships,\n      };\n\n      // Format node properties\n      const formattedNodeProps = Object.entries(rawSchema.node_props)\n        .map(([nodeName, properties]) => {\n          const propertiesStr = JSON.stringify(properties);\n          return `Node name: '${nodeName}', Node properties: ${propertiesStr}`;\n        })\n        .join(\"\\n\");\n\n      // Format relationship properties\n      const formattedRelProps = Object.entries(rawSchema.rel_props)\n        .map(([relationshipName, properties]) => {\n          const propertiesStr = JSON.stringify(properties);\n          return `Relationship name: '${relationshipName}', Relationship properties: ${propertiesStr}`;\n        })\n        .join(\"\\n\");\n\n      // Format relationships\n      const formattedRels = rawSchema.relationships\n        ?.map(\n          (el: { end: string; start: string; type: string }) =>\n            `(:${el.start})-[:${el.type}]->(:${el.end})`\n        )\n        .join(\"\\n\");\n\n      // Combine all formatted elements into a single string\n      this.schema = [\n        \"Node properties are the following:\",\n        formattedNodeProps,\n        \"Relationship properties are the following:\",\n        formattedRelProps,\n        \"The relationships are the following:\",\n        formattedRels,\n      ].join(\"\\n\");\n    }\n  }\n}\n\nexport { MemgraphGraph };\n"],"mappings":";;;;;AASA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;AAoBvB,IAAM,gBAAN,MAAM,sBAAsBA,2BAAAA,WAAW;CACrC,YAAY,EACV,KACA,UACA,UACA,WAAW,cACW;AACtB,QAAM;GAAE;GAAK;GAAU;GAAU;GAAU,CAAC;;CAG9C,aAAa,WAAW,QAAqD;EAC3E,MAAM,QAAQ,IAAI,cAAc,OAAO;AAEvC,MAAI;AACF,SAAM,MAAM,oBAAoB;UAC1B;AACN,WAAQ,MAAM,+BAA+B;;AAG/C,MAAI;AACF,SAAM,MAAM,eAAe;AAC3B,WAAQ,MAAM,iCAAiC;WAExC,OAAY;AACnB,SAAM,IAAI,MAAM,MAAM,QAAQ;;AAGhC,SAAO;;CAGT,MAAM,gBAAgB;EACpB,MAAM,uBAAuB,MAAM,KAAK,MAAM,eAAe;AAC7D,MAAI,uBAAuB,IAAI,QAAQ;GACrC,MAAM,YAAY,uBAAuB,IAAI;AAE7C,QAAK,mBAAmB;IACtB,WAAW,UAAU;IACrB,UAAU,UAAU;IACpB,eAAe,UAAU;IAC1B;AA2BD,QAAK,SAAS;IACZ;IAzByB,OAAO,QAAQ,UAAU,WAAW,CAC5D,KAAK,CAAC,UAAU,gBAAgB;AAE/B,YAAO,eAAe,SAAS,sBADT,KAAK,UAAU,WAAW;MAEhD,CACD,KAAK,KAAK;IAsBX;IAnBwB,OAAO,QAAQ,UAAU,UAAU,CAC1D,KAAK,CAAC,kBAAkB,gBAAgB;AAEvC,YAAO,uBAAuB,iBAAiB,8BADzB,KAAK,UAAU,WAAW;MAEhD,CACD,KAAK,KAAK;IAgBX;IAboB,UAAU,eAC5B,KACC,OACC,KAAK,GAAG,MAAM,MAAM,GAAG,KAAK,OAAO,GAAG,IAAI,GAC7C,CACA,KAAK,KAAK;IAUZ,CAAC,KAAK,KAAK"}