-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DATASOURCE]: Persistent data handler update #478
base: main
Are you sure you want to change the base?
Conversation
715c00a
to
d677938
Compare
0511d22
to
770d8b5
Compare
ab10a4e
to
a70412a
Compare
bad20f1
to
30232ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am okay with merging this. @marsninja if you sign off, we can 🚢 this.
f611dbc
to
0e8e210
Compare
id_uuid = UUID(int=0) | ||
else: | ||
id_uuid = UUID(id) | ||
super_root = jctx.super_root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we can call this system_root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can rename it, tho my initial idea is super_root can be attached to a user. If we rename it to system_root, the implication is it's a non user type root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we should change this to system_root
jaclang/cli/cli.py
Outdated
{ | ||
"session": session, | ||
"root": NodeAnchor.ref(root), | ||
"entry": NodeAnchor.ref(node), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure we should be using a free form dictionary here, should perhaps be a type ExecCtxOptions or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the initial code here has fixed parameters before. However, as I integrate it, the fields there are too dynamic.
If I set it on Jac specs, will I able to override it on plugin ?
on jaclang args are session, root, entry
jaclang-jaseci request, root, entry (different classes)
def __eq__(self, other: object) -> bool: | ||
"""Support string comparator.""" | ||
if isinstance(other, str): | ||
return self.name == other | ||
return super().__eq__(other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there somethign fishy here 😜
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ow actually, this is just a workaround since I don't know how the parser works before
but the issue is, disconnect uses string EdgeDir while edge_ref uses the Enum EdgeDir
I realign both on Jac Implementation side to use the Enum
and adding this changes allow it to still support the parser on disconnect using string edgedir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discuss with @marsninja
def new_init( | ||
self: Architype, | ||
*args: object, | ||
__jac__: Optional[Anchor] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you already have the jac, let say anchor is from the db, it will reuse it instead of creation a new one
def __eq__(self, other: object) -> bool: | ||
"""Support string comparator.""" | ||
if isinstance(other, str): | ||
return self.name == other | ||
return super().__eq__(other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there somethign fishy here 😜
909c47c
to
a1f032b
Compare
e988be6
to
410bebb
Compare
45b082f
to
b9cc829
Compare
6d4c897
to
6b2ced7
Compare
1667520
to
5d68ea5
Compare
Auto Await reference |
if self.whitelist: | ||
return self.whitelist, self.anchors.get(anchor, -1) | ||
else: | ||
return self.whitelist, self.anchors.get(anchor, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use Enum for the access level instead of integer? It will be much more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will check it
|
||
def populate_dataclasses(cls: type, attributes: dict[str, Any]) -> dict[str, Any]: | ||
"""Populate nested dataclasses.""" | ||
from dacite import from_dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does introduce a new core dependency dacite
for jaclang so i wonder if @marsninja is okay with it.
@amadolid do we have to use this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, although we can create our own. This is to support edge case where attributes are nested dataclasses
# ): Access(**value) | ||
# for key, value in types.items() | ||
# }, | ||
# nodes=Access(**data.get("nodes", {})), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the code for the types-based permission for now? it will probably take more than just uncomment these to get it to work when we do want to introduce this later. So for now, I'd like to keep the code cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove it
|
||
@staticmethod | ||
def ref(ref_id: str) -> Optional[Anchor]: | ||
"""Return ObjectAnchor instance if .""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finish this docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will update 😅
and self.state.connected == other.state.connected | ||
) | ||
elif isinstance(other, Architype): | ||
return self == other.__jac__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the same comment @marsninja had before -- why do we need to create custom eq for anchor? When do we need to compare anchor with architype?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in context, anchor act as description of a architype. Comparing with anchor is like checking if it only has the same description as it can resync anytime with the latest values (if its on "unloaded" state)
return f"{self.type.value}:{self.name}:{self.id}" | ||
|
||
@staticmethod | ||
def ref(ref_id: str) -> Optional[Anchor]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it looks like this ref
is overriden for each specific anchor type. So do we still need this one here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anchor.ref is like a non restricted way of referencing. NodeAnchor.ref will only allow node reference id
(same mechanism with Edge and Walker)
This is to support "blind" referencing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is an example scenario where this is usedful?
|
||
def sync(self, node: Optional["NodeAnchor"] = None) -> Optional[NodeArchitype]: | ||
"""Retrieve the Architype from db and return.""" | ||
return cast(Optional[NodeArchitype], super().sync(node)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to cast to the parent class? instead of just using the inherited function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't revisit it again.
But initially, this is only for forcing the type hinting base on their current class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah take a look. We might not need this i feel like.
"""Retrieve the Architype from db and return.""" | ||
return cast(Optional[NodeArchitype], super().sync(node)) | ||
|
||
def connect_node(self, nd: NodeAnchor, edg: EdgeAnchor) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edg
--> edge
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it looks like we are using nd
in some places and node
in others. We should unify them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, will update it
|
||
|
||
class Architype: | ||
"""Architype Protocol.""" | ||
|
||
_jac_entry_funcs_: list[DSFunc] | ||
_jac_exit_funcs_: list[DSFunc] | ||
__jac_classes__: dict[str, type[Architype]] | ||
__jac_hintings__: dict[str, type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm what are these for? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jac_classes is similar to subclasses but converted to dict and cached
applicable only on NodeArchitype, EdgeArchitype and WalkerArchitype
jac_hintings is a cached typing.get_type_hints used for walker api generations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what purpose do they server?
self.jac_machine = JacMachine(base_path) | ||
self.datasource: ShelfStorage = ShelfStorage(session) | ||
self.reports: list[Any] = [] | ||
self.super_root = self.load( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change this to system_root
? @marsninja left this comment before. I like system_root better too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change it to system root tho my concern is, will that imply that its a non user type root?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its okay. It will be like a user is assuming the role of the system and this is their root. I think that still works.
id_uuid = UUID(int=0) | ||
else: | ||
id_uuid = UUID(id) | ||
super_root = jctx.super_root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we should change this to system_root
"root": NodeAnchor.ref(root), | ||
"entry": NodeAnchor.ref(node), | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Carrying over this comment from the last review -- there was concern of using free form dictionary here. we should discuss
@@ -0,0 +1,31 @@ | |||
node A { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is great. But, can we add some more test cases to increase coverage?
- Update nodes
- Create connection for nodes (test the
connect
permission) - some common sharing permission scenarios. Are sharing part of jaclang? Or its going to be in jaseci only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its partially supported.
its supposed to be with plugin function but we can add unit test with manual trigger for now
|
||
|
||
class Architype: | ||
"""Architype Protocol.""" | ||
|
||
_jac_entry_funcs_: list[DSFunc] | ||
_jac_exit_funcs_: list[DSFunc] | ||
__jac_classes__: dict[str, type[Architype]] | ||
__jac_hintings__: dict[str, type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what purpose do they server?
self.jac_machine = JacMachine(base_path) | ||
self.datasource: ShelfStorage = ShelfStorage(session) | ||
self.reports: list[Any] = [] | ||
self.super_root = self.load( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its okay. It will be like a user is assuming the role of the system and this is their root. I think that still works.
CHANGES:
!!! IMPORTANT !!!
!!! --------- !!!
!!! TO FOLLOW !!!
!!! --------- !!!