Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
36 changes: 36 additions & 0 deletions components/neo4j_auradb/actions/create-node/create-node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { parseObject } from "../../common/utils.mjs";
import app from "../../neo4j_auradb.app.mjs";

export default {
key: "neo4j_auradb-create-node",
name: "Create Node",
description: "Creates a new node in the Neo4j AuraDB instance. [See the documentation](https://neo4j.com/docs/query-api/current/query/)",
version: "0.0.1",
type: "action",
props: {
app,
nodeLabel: {
type: "string",
label: "Node Label",
description: "The label of the node to filter events for new node creation.",
},
nodeProperties: {
type: "object",
label: "Create Node Properties",
description: "Anobject representing the properties of the node to create.",
},
},
async run({ $ }) {
const response = await this.app.createNode({
$,
label: this.nodeLabel,
properties: parseObject(this.nodeProperties),
});

const elementId = response.data?.values?.[0]?.[0]?.elementId;
$.export("$summary", elementId
? `Created node with id ${elementId}`
: "Node created successfully");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { parseObject } from "../../common/utils.mjs";
import app from "../../neo4j_auradb.app.mjs";

export default {
key: "neo4j_auradb-create-relationship",
name: "Create Relationship",
description: "Creates a relationship between two existing nodes. [See the documentation](https://neo4j.com/docs/query-api/current/query/)",
version: "0.0.1",
type: "action",
props: {
app,
relationshipType: {
type: "string",
label: "Create Relationship Type",
description: "The name of the relationship to create.",
},
startNode: {
type: "object",
label: "Start Node Identifier",
description: "An object containing any fields used to identify the start node.",
},
endNode: {
type: "object",
label: "End Node Identifier",
description: "An object containing any fields used to identify the end node.",
},
relationshipProperties: {
type: "object",
label: "Create Relationship Properties",
description: "An object representing the properties of the relationship to create.",
optional: true,
},
},
async run({ $ }) {
const response = await this.app.createRelationship({
$,
relationshipType: this.relationshipType,
startNode: parseObject(this.startNode),
endNode: parseObject(this.endNode),
relationshipProperties: parseObject(this.relationshipProperties),
});
$.export(
"$summary",
`Created relationship '${this.relationshipType}' between nodes`,
);
return response;
},
};
25 changes: 25 additions & 0 deletions components/neo4j_auradb/actions/run-query/run-query.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import app from "../../neo4j_auradb.app.mjs";

export default {
key: "neo4j_auradb-run-query",
name: "Run Cypher Query",
description: "Executes a Cypher query against the Neo4j AuraDB instance. [See the documentation](https://neo4j.com/docs/query-api/current/query/)",
version: "0.0.1",
type: "action",
props: {
app,
cypherQuery: {
type: "string",
label: "Execute Cypher Query",
description: "A valid Cypher query to execute against the Neo4j AuraDB instance.",
},
},
async run({ $ }) {
const response = await this.app.executeCypherQuery({
$,
cypherQuery: this.cypherQuery,
});
$.export("$summary", "Executed Cypher query successfully");
return response;
},
};
16 changes: 16 additions & 0 deletions components/neo4j_auradb/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const LIMIT = 100;

export const ORDER_TYPE_OPTIONS = [
{
label: "DateTime",
value: "datetime",
},
{
label: "Sequencial (integer)",
value: "sequencial",
},
{
label: "Other",
value: "other",
},
];
24 changes: 24 additions & 0 deletions components/neo4j_auradb/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
104 changes: 101 additions & 3 deletions components/neo4j_auradb/neo4j_auradb.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,109 @@
import { axios } from "@pipedream/platform";
import { LIMIT } from "./common/constants.mjs";

export default {
type: "app",
app: "neo4j_auradb",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return `${this.$auth.api_url}`;
},
_auth() {
return {
username: `${this.$auth.username}`,
password: `${this.$auth.password}`,
};
},
_makeRequest({
$ = this, path = "", ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
auth: this._auth(),
...opts,
});
},
createNode({
label, properties, ...opts
}) {
const cypher = `CREATE (n:${label} $properties) RETURN n AS Node`;
return this._makeRequest({
method: "POST",
data: {
statement: cypher,
parameters: {
properties,
},
},
...opts,
});
},
createRelationship({
relationshipType,
startNode,
endNode,
relationshipProperties = {},
...opts
}) {
const stringStartNode = JSON.stringify(startNode).replace(/"[^"]*":/g, (match) => match.replace(/"/g, ""));
const stringEndNode = JSON.stringify(endNode).replace(/"[^"]*":/g, (match) => match.replace(/"/g, ""));
const cypher = `
MATCH (a ${stringStartNode})
MATCH (b ${stringEndNode})
CREATE (a)-[r:${relationshipType} $properties]->(b)
RETURN r
`;
return this._makeRequest({
method: "POST",
data: {
statement: cypher,
parameters: {
startNode,
endNode,
properties: relationshipProperties,
},
},
...opts,
});
},
executeCypherQuery({
cypherQuery, ...opts
}) {
return this._makeRequest({
method: "POST",
data: {
statement: cypherQuery,
},
...opts,
});
},
async *paginate({
query, maxResults = null,
}) {
let hasMore = false;
let count = 0;
let page = 0;
let cypherQuery = "";

do {
cypherQuery = `${query} Skip ${LIMIT * page} LIMIT ${LIMIT}`;
page++;

const { data: { values } } = await this.executeCypherQuery({
cypherQuery,
});
for (const d of values) {
yield d[0];

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = values.length;

} while (hasMore);
},
},
};
7 changes: 5 additions & 2 deletions components/neo4j_auradb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/neo4j_auradb",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Neo4j AuraDB Components",
"main": "neo4j_auradb.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
Loading
Loading