Jaseci-Labs / jaseci

The Official Jaseci Code Repository
https://jaseci.org
156 stars 214 forks source link

Auto CRUD APIs for every Node & Edge Archetype #1301

Open ChrisIsKing opened 2 months ago

ChrisIsKing commented 2 months ago

Nodes and edges when instantiated on a graph typically are used as custom objects for persisting and representing data concepts. Managing these objects when created typically always requires devs to write CRUD walkers. e.g

node agent {
    has name: str;
    has description: str = "";
    has descriptor: str = "";
    has meta: dict = {};
    has published: bool = True;
}

walker get_agent {
    has name;

    can find_agent with `root entry {
        visit [-->](`?agent)(?name == self.name)
    }

    can return_agent on agent {
        return here;
    }

walker delete_agent {
    has name;

    can delete_agent with `root entry {
        agent_node = [-->](`?agent)(?name == self.name);
        here del--> agent_node;
    }
}

It would be ideal if for every node and edge defined there is the automatic construction of CRUD walkers to facilitate its management via API. e.g node example_node {} would result in the auto-creation of 4 walkers: create_example_node(), get_example_node, update_example_node, delete_example_node. The 3 non-creation walkers with all rely on the param _id to be passed when called to identify the node. The custom walkers can then be exposed via jac-cloud as:

URL/walker/create_{nodename} URL/walker/read{node_name}/{nodeid} URL/walker/update{node_name}/{nodeid} URL/walker/delete{node_name}/{node_id}

ChrisIsKing commented 1 month ago

Closing as a non-priority.

amadolid commented 1 month ago

As optional and not by default, yes this could be a good option.

for security, we usually don't recommend usage of the class connected to DB (data model - node/edge/walker) as request class or response class. This is to avoid exposing your data structure outside.

ChrisIsKing commented 1 month ago

@amadolid Yh that's understandable. I'm fine without create & update. I do think a default fetch & delete would be appropriate though.