jaseci 1.4.2.5__py3-none-any.whl → 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of jaseci might be problematic. Click here for more details.

Files changed (186) hide show
  1. jaseci/__init__.py +3 -37
  2. jaseci-2.0.0.dist-info/METADATA +65 -0
  3. jaseci-2.0.0.dist-info/RECORD +4 -0
  4. {jaseci-1.4.2.5.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
  5. jaseci/VERSION +0 -1
  6. jaseci/cli_tools/__init__.py +0 -0
  7. jaseci/cli_tools/book_tools.py +0 -457
  8. jaseci/cli_tools/jsctl.py +0 -500
  9. jaseci/cli_tools/tests/__init__.py +0 -0
  10. jaseci/cli_tools/tests/test_jsctl.py +0 -556
  11. jaseci/extens/__init__.py +0 -0
  12. jaseci/extens/act_lib/__init__.py +0 -0
  13. jaseci/extens/act_lib/date.py +0 -117
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -76
  16. jaseci/extens/act_lib/file_handler.py +0 -189
  17. jaseci/extens/act_lib/internal.py +0 -18
  18. jaseci/extens/act_lib/jaseci.py +0 -61
  19. jaseci/extens/act_lib/mail.py +0 -10
  20. jaseci/extens/act_lib/maths.py +0 -168
  21. jaseci/extens/act_lib/net.py +0 -191
  22. jaseci/extens/act_lib/rand.py +0 -82
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -169
  25. jaseci/extens/act_lib/std.py +0 -235
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -337
  28. jaseci/extens/act_lib/task.py +0 -13
  29. jaseci/extens/act_lib/tests/__init__.py +0 -0
  30. jaseci/extens/act_lib/tests/std_test_code.py +0 -37
  31. jaseci/extens/act_lib/tests/test_date.py +0 -26
  32. jaseci/extens/act_lib/tests/test_elastic.py +0 -159
  33. jaseci/extens/act_lib/tests/test_file.py +0 -116
  34. jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
  35. jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
  36. jaseci/extens/act_lib/tests/test_maths.py +0 -147
  37. jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
  38. jaseci/extens/act_lib/tests/test_regex.py +0 -61
  39. jaseci/extens/act_lib/tests/test_std.py +0 -51
  40. jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
  41. jaseci/extens/act_lib/tests/test_url.py +0 -32
  42. jaseci/extens/act_lib/tests/test_vector.py +0 -36
  43. jaseci/extens/act_lib/tests/test_webtool.py +0 -44
  44. jaseci/extens/act_lib/tests/test_zlib.py +0 -24
  45. jaseci/extens/act_lib/url.py +0 -79
  46. jaseci/extens/act_lib/vector.py +0 -157
  47. jaseci/extens/act_lib/webtool.py +0 -28
  48. jaseci/extens/act_lib/zip.py +0 -33
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -170
  51. jaseci/extens/api/alias_api.py +0 -139
  52. jaseci/extens/api/architype_api.py +0 -196
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -84
  55. jaseci/extens/api/graph_api.py +0 -167
  56. jaseci/extens/api/health_api.py +0 -20
  57. jaseci/extens/api/interface.py +0 -268
  58. jaseci/extens/api/jac_api.py +0 -171
  59. jaseci/extens/api/jsorc_api.py +0 -316
  60. jaseci/extens/api/logger_api.py +0 -89
  61. jaseci/extens/api/master_api.py +0 -133
  62. jaseci/extens/api/object_api.py +0 -101
  63. jaseci/extens/api/prometheus_api.py +0 -74
  64. jaseci/extens/api/queue_api.py +0 -140
  65. jaseci/extens/api/sentinel_api.py +0 -270
  66. jaseci/extens/api/super_api.py +0 -64
  67. jaseci/extens/api/tests/__init__.py +0 -0
  68. jaseci/extens/api/tests/test_architype_api.py +0 -66
  69. jaseci/extens/api/tests/test_global_api.py +0 -179
  70. jaseci/extens/api/tests/test_graph_api.py +0 -64
  71. jaseci/extens/api/tests/test_logger_api.py +0 -43
  72. jaseci/extens/api/tests/test_object_api.py +0 -20
  73. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  74. jaseci/extens/api/tests/test_uncommon.py +0 -107
  75. jaseci/extens/api/tests/test_user_api.py +0 -32
  76. jaseci/extens/api/tests/test_walker_api.py +0 -316
  77. jaseci/extens/api/user_api.py +0 -144
  78. jaseci/extens/api/walker_api.py +0 -298
  79. jaseci/extens/api/webhook_api.py +0 -74
  80. jaseci/extens/svc/__init__.py +0 -0
  81. jaseci/extens/svc/elastic_svc.py +0 -366
  82. jaseci/extens/svc/kube_svc.py +0 -432
  83. jaseci/extens/svc/mail_svc.py +0 -156
  84. jaseci/extens/svc/prome_svc.py +0 -378
  85. jaseci/extens/svc/redis_svc.py +0 -63
  86. jaseci/extens/svc/storage_svc.py +0 -193
  87. jaseci/extens/svc/stripe_svc.py +0 -51
  88. jaseci/extens/svc/task_svc.py +0 -155
  89. jaseci/extens/svc/tasks.py +0 -302
  90. jaseci/jac/__init__.py +0 -0
  91. jaseci/jac/interpreter/__init__.py +0 -0
  92. jaseci/jac/interpreter/architype_interp.py +0 -214
  93. jaseci/jac/interpreter/interp.py +0 -1783
  94. jaseci/jac/interpreter/sentinel_interp.py +0 -257
  95. jaseci/jac/interpreter/tests/__init__.py +0 -0
  96. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  97. jaseci/jac/interpreter/walker_interp.py +0 -248
  98. jaseci/jac/ir/__init__.py +0 -0
  99. jaseci/jac/ir/ast.py +0 -73
  100. jaseci/jac/ir/ast_builder.py +0 -249
  101. jaseci/jac/ir/jac_code.py +0 -152
  102. jaseci/jac/ir/passes/__init__.py +0 -6
  103. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  104. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  105. jaseci/jac/ir/passes/ir_pass.py +0 -29
  106. jaseci/jac/ir/passes/printer_pass.py +0 -23
  107. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  108. jaseci/jac/ir/passes/schedule.py +0 -23
  109. jaseci/jac/ir/passes/stats_pass.py +0 -16
  110. jaseci/jac/jac.g4 +0 -450
  111. jaseci/jac/jac_parse/__init__.py +0 -0
  112. jaseci/jac/jac_parse/jacLexer.py +0 -809
  113. jaseci/jac/jac_parse/jacListener.py +0 -853
  114. jaseci/jac/jac_parse/jacParser.py +0 -9192
  115. jaseci/jac/jac_set.py +0 -119
  116. jaseci/jac/jsci_vm/__init__.py +0 -0
  117. jaseci/jac/jsci_vm/disasm.py +0 -94
  118. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  119. jaseci/jac/jsci_vm/machine.py +0 -188
  120. jaseci/jac/jsci_vm/op_codes.py +0 -82
  121. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  122. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  123. jaseci/jac/machine/__init__.py +0 -0
  124. jaseci/jac/machine/jac_scope.py +0 -85
  125. jaseci/jac/machine/jac_value.py +0 -226
  126. jaseci/jac/machine/machine_state.py +0 -383
  127. jaseci/jac/tests/__init__.py +0 -0
  128. jaseci/jac/tests/book_code.py +0 -624
  129. jaseci/jac/tests/test_book.py +0 -380
  130. jaseci/jac/tests/test_lang_14.py +0 -49
  131. jaseci/jsorc/__init__.py +0 -7
  132. jaseci/jsorc/jsorc.py +0 -642
  133. jaseci/jsorc/jsorc_settings.py +0 -211
  134. jaseci/jsorc/jsorc_utils.py +0 -298
  135. jaseci/jsorc/live_actions.py +0 -364
  136. jaseci/jsorc/manifests/__init__.py +0 -0
  137. jaseci/jsorc/manifests/database.yaml +0 -109
  138. jaseci/jsorc/manifests/elastic.yaml +0 -6024
  139. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  140. jaseci/jsorc/manifests/redis.yaml +0 -64
  141. jaseci/jsorc/memory.py +0 -258
  142. jaseci/jsorc/redis.py +0 -139
  143. jaseci/jsorc/remote_actions.py +0 -157
  144. jaseci/jsorc/tests/__init__.py +0 -0
  145. jaseci/jsorc/tests/test_actions.py +0 -542
  146. jaseci/jsorc/tests/test_jsorc.py +0 -112
  147. jaseci/prim/__init__.py +0 -0
  148. jaseci/prim/ability.py +0 -93
  149. jaseci/prim/architype.py +0 -89
  150. jaseci/prim/edge.py +0 -172
  151. jaseci/prim/element.py +0 -233
  152. jaseci/prim/graph.py +0 -26
  153. jaseci/prim/master.py +0 -64
  154. jaseci/prim/node.py +0 -532
  155. jaseci/prim/obj_mixins.py +0 -235
  156. jaseci/prim/sentinel.py +0 -281
  157. jaseci/prim/super_master.py +0 -31
  158. jaseci/prim/walker.py +0 -261
  159. jaseci/svc/__init__.py +0 -0
  160. jaseci/tests/__init__.py +0 -0
  161. jaseci/tests/infer.py +0 -39
  162. jaseci/tests/jac_test_code.py +0 -1293
  163. jaseci/tests/jac_test_progs.py +0 -774
  164. jaseci/tests/test_core.py +0 -153
  165. jaseci/tests/test_jac.py +0 -824
  166. jaseci/tests/test_node.py +0 -89
  167. jaseci/tests/test_progs.py +0 -702
  168. jaseci/tests/test_stack.py +0 -220
  169. jaseci/tests/test_stripe.py +0 -225
  170. jaseci/utils/__init__.py +0 -0
  171. jaseci/utils/actions/__init__.py +0 -0
  172. jaseci/utils/actions/actions_manager.py +0 -254
  173. jaseci/utils/actions/actions_optimizer.py +0 -516
  174. jaseci/utils/actions/actions_state.py +0 -95
  175. jaseci/utils/file_handler.py +0 -171
  176. jaseci/utils/gprof2dot.py +0 -3786
  177. jaseci/utils/id_list.py +0 -168
  178. jaseci/utils/json_handler.py +0 -70
  179. jaseci/utils/log_utils.py +0 -57
  180. jaseci/utils/test_core.py +0 -62
  181. jaseci/utils/utils.py +0 -387
  182. jaseci-1.4.2.5.dist-info/LICENSE +0 -21
  183. jaseci-1.4.2.5.dist-info/METADATA +0 -39
  184. jaseci-1.4.2.5.dist-info/RECORD +0 -184
  185. jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
  186. jaseci-1.4.2.5.dist-info/top_level.txt +0 -1
jaseci/prim/ability.py DELETED
@@ -1,93 +0,0 @@
1
- """
2
- Action class for Jaseci
3
-
4
- Each action has an id, name, timestamp and it's set of edges.
5
- """
6
- from jaseci.prim.element import Element
7
- from jaseci.jsorc.live_actions import live_actions
8
- from jaseci.jac.jac_set import JacSet
9
- import inspect
10
- import time
11
-
12
- from jaseci.jsorc.jsorc import JsOrc
13
- from jaseci.utils.actions.actions_manager import ActionManager
14
- from jaseci.jac.ir.jac_code import JacCode
15
- from jaseci.jac.interpreter.interp import Interp
16
- from jaseci.jac.machine.jac_scope import JacScope
17
-
18
-
19
- class Ability(Element, JacCode, Interp):
20
- """
21
- Abilities class for Jaseci
22
- """
23
-
24
- def __init__(
25
- self, code_ir=None, preset_in_out=None, access_list=None, *args, **kwargs
26
- ):
27
- self.preset_in_out = preset_in_out # Not using _ids convention
28
- self.access_list = access_list
29
- Element.__init__(self, *args, **kwargs)
30
- JacCode.__init__(self, code_ir=code_ir)
31
- Interp.__init__(self)
32
-
33
- def run_ability(self, here, visitor):
34
- """
35
- Run ability
36
- """
37
- self.push_scope(
38
- JacScope(
39
- parent=self,
40
- name=f"a_run:{self.get_jac_ast().loc_str()}",
41
- has_obj=here,
42
- here=here,
43
- visitor=visitor,
44
- )
45
- )
46
- self.run_code_block(self.get_jac_ast())
47
- self.pop_scope()
48
-
49
- def run_action(self, param_list, scope, interp, jac_ast):
50
- """
51
- param_list should be passed as list of values to lib functions
52
- Also note that Jac stores preset_in_out as input/output list of hex
53
- ids since preset_in_out doesn't use _ids convention
54
- """
55
- action_name = self.name
56
- if not interp.check_builtin_action(action_name):
57
- interp.rt_error(f"Cannot execute {action_name} - Not Found", jac_ast)
58
- return None
59
- func = live_actions[action_name]
60
- args = inspect.getfullargspec(func)
61
- self.do_auto_conversions(args, param_list)
62
- args = args[0] + args[4]
63
-
64
- action_manager = JsOrc.get("action_manager", ActionManager)
65
- action_manager.pre_action_call_hook()
66
-
67
- ts = time.time()
68
- try:
69
- if "meta" in args:
70
- param_list["kwargs"]["meta"] = {
71
- "m_id": scope.parent._m_id,
72
- "h": scope.parent._h,
73
- "scope": scope,
74
- "interp": interp,
75
- }
76
- result = func(*param_list["args"], **param_list["kwargs"])
77
- except Exception as e:
78
- interp.rt_error(e, jac_ast, True)
79
- t = time.time() - ts
80
- action_manager.post_action_call_hook(action_name, t)
81
- return result
82
-
83
- def do_auto_conversions(self, args, params):
84
- """
85
- Automatically make conversions for jac to internal, e.g., list to jac_set
86
- """
87
- for i in args.annotations.keys():
88
- if args.annotations[i] == JacSet:
89
- idx = args.args.index(i)
90
- if idx < len(params["args"]):
91
- params["args"][idx] = JacSet(in_list=params["args"][idx])
92
- if i in params["kwargs"]:
93
- params["kwargs"][i] = JacSet(in_list=params["kwargs"][i])
jaseci/prim/architype.py DELETED
@@ -1,89 +0,0 @@
1
- """
2
- Architype class for Jaseci
3
-
4
- Each architype is a registered templatized version of instances of any Jaseci
5
- abstractions or collections of instances (e.g., subgraphs, etc)
6
- """
7
- from jaseci.prim.element import Element
8
- from jaseci.jac.interpreter.architype_interp import ArchitypeInterp
9
- from jaseci.jac.ir.jac_code import JacCode
10
- from jaseci.utils.id_list import IdList
11
-
12
-
13
- class Architype(Element, JacCode, ArchitypeInterp):
14
- """Architype class for Jaseci"""
15
-
16
- def __init__(self, code_ir=None, is_async=False, *args, **kwargs):
17
- self.super_archs = list()
18
- self.anchor_var = None
19
- self.private_vars = []
20
- self.has_vars = []
21
- self.entry_ability_ids = IdList(self)
22
- self.activity_ability_ids = IdList(self)
23
- self.exit_ability_ids = IdList(self)
24
-
25
- # async handling for walker
26
- self.is_async = is_async
27
-
28
- Element.__init__(self, *args, **kwargs)
29
- JacCode.__init__(self, code_ir)
30
- ArchitypeInterp.__init__(self)
31
-
32
- def run(self):
33
- """
34
- Create set of new object instances from architype if needed
35
- """
36
- return self.run_architype(jac_ast=self.get_jac_ast())
37
-
38
- def get_actions(self, action_types: list):
39
- actions = IdList(self, auto_save=False)
40
- for i in self.arch_with_supers():
41
- for j in action_types:
42
- actions += getattr(i, j)
43
- return actions
44
-
45
- def get_entry_abilities(self):
46
- return self.get_actions(["entry_ability_ids"])
47
-
48
- def get_activity_abilities(self):
49
- return self.get_actions(["activity_ability_ids"])
50
-
51
- def get_exit_abilities(self):
52
- return self.get_actions(["exit_ability_ids"])
53
-
54
- def get_all_abilities(self):
55
- return self.get_actions(
56
- ["entry_ability_ids", "activity_ability_ids", "exit_ability_ids"]
57
- )
58
-
59
- def arch_with_supers(self):
60
- archs = [self]
61
- for i in self.super_archs:
62
- obj = self.parent().arch_ids.get_obj_by_name(name=i, kind=self.kind)
63
- archs += obj.arch_with_supers()
64
- return archs
65
-
66
- def derived_types(self):
67
- names = []
68
- for i in self.arch_with_supers():
69
- names += i.super_archs + [i.name]
70
- return names
71
-
72
- def get_architype(self):
73
- return self
74
-
75
- def is_instance(self, name):
76
- return name in self.derived_types()
77
-
78
- def destroy(self):
79
- """
80
- Destroys self from memory and persistent storage
81
- """
82
- des = (
83
- self.activity_ability_ids.obj_list()
84
- + self.entry_ability_ids.obj_list()
85
- + self.exit_ability_ids.obj_list()
86
- )
87
- for i in des:
88
- i.destroy()
89
- super().destroy()
jaseci/prim/edge.py DELETED
@@ -1,172 +0,0 @@
1
- """
2
- Edge class for Jaseci
3
-
4
- Each edge has an id, name, timestamp, the from node at the element of the edge
5
- and the to node it is pointing to.
6
- """
7
- from jaseci.prim.element import Element
8
- from jaseci.prim.obj_mixins import Anchored
9
- from jaseci.utils.utils import logger
10
- import uuid
11
- import sys
12
-
13
-
14
- class Edge(Element, Anchored):
15
- """Edge class for Jaseci"""
16
-
17
- def __init__(self, **kwargs):
18
- self.from_node_id = None
19
- self.to_node_id = None
20
- self.bidirected: bool = False
21
- Anchored.__init__(self)
22
- Element.__init__(self, **kwargs)
23
-
24
- def from_node(self):
25
- """Returns node edge is pointing from"""
26
- ret = (
27
- self._h.get_obj(self._m_id, self.from_node_id)
28
- if self.from_node_id
29
- else None
30
- )
31
- if not ret:
32
- logger.critical(str(f"{self} disconnected from source node"))
33
- return None
34
- else:
35
- return ret
36
-
37
- def to_node(self):
38
- """Returns node edge is pointing to"""
39
- if not self.to_node_id:
40
- return None
41
- ret = self._h.get_obj(self._m_id, self.to_node_id) if self.to_node_id else None
42
- if not ret:
43
- logger.critical(str(f"{self} disconnected to target node"))
44
- return None
45
- else:
46
- return ret
47
-
48
- def nodes(self):
49
- """Returns both nodes connected to edge in a list"""
50
- return [self.to_node(), self.from_node()]
51
-
52
- def opposing_node(self, node_obj):
53
- """Returns opposite node edge is pointing from node_obj"""
54
- node_set = [self.to_node_id, self.from_node_id]
55
- try:
56
- node_set.remove(node_obj.jid)
57
- return self._h.get_obj(self._m_id, node_set[0])
58
- except ValueError:
59
- logger.critical(str(f"{self} disconnected to node {node_obj}"))
60
- return None
61
-
62
- def connect(self, source, target, bi_dir=False):
63
- """
64
- Connects both ends of the edge
65
- """
66
- self.from_node_id = source.jid
67
- self.to_node_id = target.jid
68
- source.smart_add_edge(self)
69
- target.smart_add_edge(self)
70
- self.set_bidirected(bi_dir)
71
- self.save()
72
- return True
73
-
74
- def set_bidirected(self, bidirected: bool):
75
- """Sets/unsets edge to be bidirected"""
76
- self.bidirected = bidirected
77
- self.save()
78
-
79
- def is_bidirected(self):
80
- """Check if edge is bidirected"""
81
- return self.bidirected
82
-
83
- def connects(self, source=None, target=None, ignore_direction=False):
84
- """Test if a node or nodes are connected by edge"""
85
- if not source and not target:
86
- return False
87
- if self.bidirected or ignore_direction:
88
- if source and source.jid not in [self.from_node_id, self.to_node_id]:
89
- return False
90
- if target and target.jid not in [self.from_node_id, self.to_node_id]:
91
- return False
92
- else:
93
- if source and source.jid != self.from_node_id:
94
- return False
95
- if target and target.jid != self.to_node_id:
96
- return False
97
- return True
98
-
99
- def is_fast(self):
100
- return sys.getsizeof(self.context) < 2000
101
-
102
- def save(self):
103
- """
104
- Write self through hook to persistent storage
105
- """
106
-
107
- if self.is_fast():
108
- self._persist = False
109
- if self.from_node_id:
110
- self.from_node().save()
111
- if self.to_node_id:
112
- self.to_node().save()
113
- super().save()
114
-
115
- def destroy(self):
116
- """
117
- Destroys self from memory and persistent storage
118
- """
119
- base = self.from_node()
120
- target = self.to_node()
121
- base.smart_remove_edge(self) if base else None
122
- target.smart_remove_edge(self) if target else None
123
- super().destroy()
124
-
125
- def dot_str(self, node_map=None, edge_map=None, detailed=False):
126
- """
127
- DOT representation
128
- from_node -> to_node [context_key=contect_value]
129
- """
130
-
131
- def handle_str(str):
132
- return str[:32].replace('"', '\\"')
133
-
134
- from_name = (
135
- uuid.UUID(self.from_node().jid).hex
136
- if node_map is None
137
- else node_map.index(self.from_node().jid)
138
- )
139
- to_name = (
140
- uuid.UUID(self.to_node().jid).hex
141
- if node_map is None
142
- else node_map.index(self.to_node().jid)
143
- )
144
- dstr = f'"n{from_name}" -> "n{to_name}" [ '
145
-
146
- if detailed:
147
- dstr += f'id="{uuid.UUID(self.jid).hex}", '
148
-
149
- label = ""
150
- if edge_map:
151
- label = f"e{edge_map.index(self.jid)}"
152
- if self.name != "generic":
153
- label += f":{self.name}"
154
-
155
- dstr += f'label="{label}"'
156
-
157
- if self.bidirected:
158
- dstr += ', dir="both"'
159
-
160
- edge_dict = self.context
161
- for i in self.private_values():
162
- edge_dict.pop(i)
163
-
164
- if edge_dict and detailed:
165
- for k, v in edge_dict.items():
166
- if not isinstance(v, str) or v == "":
167
- continue
168
- dstr += f', {k}="{handle_str(v)}"'
169
-
170
- dstr += " ]"
171
-
172
- return dstr + "\n"
jaseci/prim/element.py DELETED
@@ -1,233 +0,0 @@
1
- """
2
- Base Jaseci object class
3
-
4
- Naming conventions
5
- * '_ids', '_id' - appended to lists of ids as feilds of jaseci objects
6
- * 'obj' - used to represent a jaseci object
7
- * 'item' - Items are kv pairs derived from item class, dont use elsewhere
8
- * 'store' - refers to persistent store for hooks from engine, (dont use db)
9
- """
10
-
11
- import copy
12
- import json
13
- import uuid
14
- from datetime import datetime
15
-
16
- from jaseci.prim.obj_mixins import Hookable
17
- from jaseci.jsorc.memory import MemoryHook
18
- from jaseci.utils.id_list import IdList
19
- from jaseci.utils.json_handler import JaseciJsonEncoder, json_str_to_jsci_dict
20
- from jaseci.utils.utils import log_var_out, logger, camel_to_snake
21
-
22
- __version__ = "1.0.0"
23
- element_fields = None
24
-
25
-
26
- class Element(Hookable):
27
- """
28
- Base class for Jaseci for standard info shared across all objects types in
29
- Jaseci. This class also includes a method for dumping the non-general items
30
- as a single dictionary. The :meth:`jsci_payload` function automatically
31
- finds relevant non general fields and returns a dictionary of them.
32
-
33
- Keep in mind that when a valid hook is passed, the item writes itself on
34
- creation.
35
-
36
- Auto save should be faulse when loading from database so a new UUID is
37
- not randomly created and saved back to db on load
38
-
39
- TODO: Make below content a documentation variable and link in a few places
40
- Keep in mind the postfix of '_ids' on feilds of derived classes of element
41
- is a Jaseci convention for lists of uuids that are stored as hex and loaded
42
- as type UUID.
43
-
44
- NOTE: All fields of elements and it's derived classes are assumed to be
45
- json serializable types
46
- """
47
-
48
- def __init__(
49
- self,
50
- name="basic",
51
- kind="generic",
52
- auto_save=True,
53
- **kwargs,
54
- ):
55
- self.name = name
56
- self.kind = kind
57
- self.jid = uuid.uuid4().urn
58
- self.j_timestamp = datetime.utcnow().isoformat()
59
- self.j_type = camel_to_snake(type(self).__name__)
60
- Hookable.__init__(self, **kwargs)
61
- if self.is_master():
62
- self.set_master(self.jid)
63
- if auto_save:
64
- self.save()
65
-
66
- @property
67
- def id(self):
68
- return uuid.UUID(self.jid)
69
-
70
- @id.setter
71
- def id(self, obj):
72
- self.jid = obj.urn
73
-
74
- @property
75
- def timestamp(self):
76
- return datetime.fromisoformat(self.j_timestamp)
77
-
78
- @timestamp.setter
79
- def timestamp(self, obj):
80
- self.j_timestamp = obj.isoformat()
81
-
82
- def is_master(self, super_check=False, silent=True):
83
- """Check if self is a master"""
84
- ret = True
85
- if "master" not in self.j_type:
86
- ret = False
87
- if not silent:
88
- logger.error(f"{self} is not master")
89
- if super_check and "super" not in self.j_type:
90
- ret = False
91
- if not silent:
92
- logger.error(f"{self} does not have super master status")
93
- return ret
94
-
95
- def get_master(self):
96
- """Get the master of an element"""
97
- return self._h.get_obj(self._m_id, self.j_master)
98
-
99
- def duplicate(self, persist_dup: bool = False):
100
- """
101
- Duplicates elements by creating copy with new id
102
- Hook override to duplicate into mem / another store
103
- """
104
- kwargs = {"m_id": self._m_id, "h": self._h, "persist": persist_dup}
105
- dup = type(self)(**kwargs)
106
- id_save = dup.id
107
- for i in dup.__dict__.keys():
108
- if type(dup.__dict__[i]) == IdList:
109
- setattr(dup, i, IdList(parent_obj=dup, in_list=self.__dict__[i]))
110
- else:
111
- setattr(dup, i, self.__dict__[i])
112
- dup.id = id_save
113
- dup.timestamp = datetime.utcnow()
114
- dup.save()
115
- return dup
116
-
117
- def is_equivalent(self, obj):
118
- """
119
- Duplicates elements by creating copy with new id
120
- """
121
- if self.j_type != obj.j_type:
122
- return False
123
- for i in vars(self).keys():
124
- if not i.startswith("_") and not callable(getattr(self, i)):
125
- if i != "jid" and i != "j_timestamp":
126
- if getattr(self, i) != getattr(obj, i):
127
- return False
128
- return True
129
-
130
- def jsci_payload(self):
131
- """
132
- Returns all data fields and values of jaseci object as json string.
133
- This grabs any fields that are added into inherited objects. Useful for
134
- saving and loading item.
135
- """
136
- global element_fields
137
- if element_fields is None:
138
- element_fields = dir(Element(m_id=0, h=MemoryHook()))
139
- obj_fields = []
140
- for i in vars(self).keys():
141
- if not i.startswith("_") and i not in element_fields:
142
- obj_fields.append(i)
143
- obj_dict = {}
144
- for i in obj_fields:
145
- obj_dict[i] = getattr(self, i)
146
- return json.dumps(obj_dict, cls=JaseciJsonEncoder)
147
-
148
- def serialize(self, deep=0, detailed=False):
149
- """
150
- Serialize Jaseci object
151
- """
152
- jdict = {}
153
- key_fields = [
154
- "name",
155
- "kind",
156
- "jid",
157
- "j_type",
158
- "context",
159
- "code_sig",
160
- "j_timestamp",
161
- "version",
162
- "to_node_id",
163
- "from_node_id",
164
- ]
165
- for i in vars(self).keys():
166
- if not i.startswith("_"):
167
- if not detailed and i not in key_fields:
168
- continue
169
- jdict[i] = copy.copy(vars(self)[i])
170
- if not detailed and i == "context":
171
- for j in self.private_values():
172
- del jdict[i][j]
173
- if deep > 0 and isinstance(jdict[i], IdList):
174
- for j in range(len(jdict[i])):
175
- jdict[i][j] = copy.copy(
176
- self._h.get_obj(self._m_id, jdict[i][j]).serialize(deep - 1)
177
- )
178
- return jdict
179
-
180
- def json(self, deep=0, detailed=False):
181
- """
182
- Returns entire self object as Json string
183
-
184
- deep indicates number of levels to unwind uuids
185
- """
186
- return json.dumps(
187
- self.serialize(deep, detailed=detailed), indent=4, cls=JaseciJsonEncoder
188
- )
189
-
190
- def json_load(self, blob):
191
- """Loads self from json blob"""
192
- jdict = json_str_to_jsci_dict(blob, parent_obj=self)
193
- self.dict_load(jdict=jdict)
194
-
195
- def dict_load(self, jdict):
196
- """Loads self from dict"""
197
- for i in jdict.keys():
198
- if i in vars(self).keys():
199
- setattr(self, i, jdict[i])
200
-
201
- def get_deep_obj_list(self, objs=None):
202
- """Recursively get all contained Jaseci objects and return id_list"""
203
- if objs is None:
204
- objs = []
205
- objs.append(self)
206
- for i in self.__dict__.keys():
207
- if str(i).endswith("_ids") and isinstance(self.__dict__[i], IdList):
208
- for j in self.__dict__[i].obj_list():
209
- if j not in objs:
210
- j.get_deep_obj_list(objs=objs)
211
- return objs
212
-
213
- def propagate_access(self, set_access=None):
214
- """Propagate permission through id_lists hierarchy"""
215
- if set_access is None:
216
- set_access = self.j_access
217
- for i in self.get_deep_obj_list():
218
- i.j_access = set_access
219
-
220
- def log_output(self, val):
221
- """
222
- Utility to log out variable in pretty format
223
- """
224
- log_var_out(val)
225
-
226
- def __str__(self):
227
- """
228
- String representation is of the form type:name:kind
229
- """
230
- return self.j_type + ":" + self.kind + ":" + self.name + ":" + self.jid
231
-
232
- def __repr__(self):
233
- return self.__str__()
jaseci/prim/graph.py DELETED
@@ -1,26 +0,0 @@
1
- """
2
- Graph class for Jaseci
3
-
4
- """
5
- from jaseci.prim.node import Node
6
- from jaseci.utils.id_list import IdList
7
-
8
-
9
- class Graph(Node):
10
- """Graph class for Jaseci"""
11
-
12
- def __init__(self, **kwargs):
13
- self.hd_node_ids = IdList(self)
14
- Node.__init__(self, **kwargs)
15
- self.name = "root"
16
- self.kind = "node"
17
-
18
- # Node.__init__(self, name="root", kind="node", **kwargs)
19
-
20
- def destroy(self):
21
- """
22
- Destroys self from memory and persistent storage
23
- """
24
- for i in self.hd_node_ids.obj_list():
25
- i.destroy()
26
- super().destroy()
jaseci/prim/master.py DELETED
@@ -1,64 +0,0 @@
1
- """
2
- Main master handler for each user of Jaseci, serves as main interface between
3
- between user and Jaseci
4
- """
5
-
6
- from jaseci.prim.element import Element
7
- from jaseci.extens.api.alias_api import AliasAPI
8
- from jaseci.extens.api.object_api import ObjectApi
9
- from jaseci.extens.api.graph_api import GraphApi
10
- from jaseci.extens.api.sentinel_api import SentinelApi
11
- from jaseci.extens.api.walker_api import WalkerApi
12
- from jaseci.extens.api.architype_api import ArchitypeApi
13
- from jaseci.extens.api.config_api import ConfigApi
14
- from jaseci.extens.api.interface import Interface
15
- from jaseci.extens.api.master_api import MasterApi
16
- from jaseci.extens.api.jac_api import JacApi
17
- from jaseci.extens.api.user_api import UserApi
18
- from jaseci.extens.api.queue_api import QueueApi
19
- from jaseci.extens.api.webhook_api import WebhookApi
20
- from jaseci.extens.api.health_api import HealthApi
21
- from jaseci.jsorc.jsorc import JsOrc
22
-
23
-
24
- @JsOrc.context(name="master")
25
- class Master(
26
- Element,
27
- Interface,
28
- MasterApi,
29
- AliasAPI,
30
- GraphApi,
31
- ObjectApi,
32
- SentinelApi,
33
- WalkerApi,
34
- ArchitypeApi,
35
- JacApi,
36
- UserApi,
37
- QueueApi,
38
- WebhookApi,
39
- HealthApi,
40
- ):
41
- """Main class for master functions for user"""
42
-
43
- def __init__(self, head_master=None, *args, **kwargs):
44
- kwargs["m_id"] = None
45
-
46
- Element.__init__(self, kind="Jaseci Master", *args, **kwargs)
47
- MasterApi.__init__(self, head_master)
48
- AliasAPI.__init__(self)
49
- ConfigApi.__init__(self)
50
- ObjectApi.__init__(self)
51
- GraphApi.__init__(self)
52
- WalkerApi.__init__(self)
53
- SentinelApi.__init__(self)
54
- Interface.__init__(self)
55
-
56
- def destroy(self):
57
- """
58
- Destroys self from memory and persistent storage
59
- """
60
- GraphApi.destroy(self)
61
- SentinelApi.destroy(self)
62
- MasterApi.destroy(self)
63
- WalkerApi.destroy(self)
64
- super().destroy()