Skip to content

Commit d617c96

Browse files
sample blueprints for testing
1 parent d4987f8 commit d617c96

File tree

7 files changed

+102
-23
lines changed

7 files changed

+102
-23
lines changed

blueprints/global/communication/chat/models/conversation.model.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"attributes":{
99
"id": {"type":"id", "required":true},
1010
"name": {"type":"str", "max":50, "required":true},
11-
"users":{"many":true,"type":"__user", "required":true},
12-
"read_by":{"many":true, "type":"__user", "required":true}
11+
"users":{"many":true,"type":"__user", "required":true}
1312
},
1413
"create":{
1514
"__extends":{

blueprints/global/communication/chat/models/message.model.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"id": {"type":"id", "required":true},
99
"conversation": {"type":"conversation", "required":true},
1010
"user":{"type":"__user", "required":true},
11-
"content":{"type":"str", "required":true}
11+
"content":{"type":"str", "required":true},
12+
"read_by":{"many":true, "type":"__user", "required":true}
1213
},
1314
"create":{
1415
"__extends":{

blueprints/global/utils/auth/user/models/user.model.json

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,39 @@
66
"password":{"type":"password", "max":100, "required":false}
77
},
88
"create":{
9-
"__extends":{
10-
"from":"attributes",
11-
"__excludes":["id"]
9+
"request":{
10+
"__extends":{
11+
"from":"attributes",
12+
"__excludes":["id"]
13+
}
14+
},
15+
"response":{
16+
"__extends":{
17+
"from":"attributes",
18+
"__includes":["id"]
19+
}
1220
}
1321
},
1422
"list":{
15-
"__extends":{
16-
"from":"attributes",
17-
"__excludes":["password"]
23+
"response":{
24+
"__extends":{
25+
"from":"attributes",
26+
"__excludes":["password"]
27+
}
1828
}
1929
},
2030
"get":{
21-
"__extends":{
22-
"from":"create",
23-
"__excludes":[ "id"]
31+
"request":{
32+
"__extends":{
33+
"from":"attributes",
34+
"__includes":["id"]
35+
}
36+
},
37+
"response":{
38+
"__extends":{
39+
"from":"attributes",
40+
"__includes":["id"]
41+
}
2442
}
2543
}
2644
}

compiler/compiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ def main():
1818
return
1919

2020
main()
21-
# python .\compiler.py c "json.v1" ../blueprints/examples/facebook/main.app.json
21+
# python .\compiler.py c "json.v1" ../blueprints/examples/facebook/main.app.json
22+
# python .\compiler.py c "json.v1" ./sample_blueprints/samples/import.app.json

compiler/json_compiler/Compiler.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,36 @@
1010
def load_json_as_dict(file_name):
1111
with open(file_name, "r") as f:
1212
return json.load(f)
13-
def special_flags_processing(json_dict, args = {}, *, base_folder=None, base_dict={}):
13+
def special_flags_processing(json_dict, args = {}, *, base_folder=None, base_dict={}, object_route=""):
1414
if SPECIAL_FIELD_FLAG+"constructor" in json_dict:
1515
json_dict.pop(SPECIAL_FIELD_FLAG+"constructor")
1616
if SPECIAL_FIELD_FLAG+"extends" in json_dict:
1717
extends_from = json_dict[SPECIAL_FIELD_FLAG+"extends"]["from"].split(".")
18+
attr_build = {}
1819
if len(extends_from) == 1:
1920
if extends_from[0] in base_dict:
20-
attr_build = special_flags_processing(base_dict[extends_from[0]], base_dict=base_dict)
21-
json_dict.update(attr_build)
21+
attr_build = special_flags_processing(base_dict[extends_from[0]], base_dict=base_dict, object_route = object_route+"."+extends_from[0])
2222
else:
23-
raise NameError("ERROR: Attribute not found "+extends_from[0]+"\n"+str(base_dict))
23+
raise NameError(f"ERROR: Attribute not found {object_route}.{extends_from[0]}\n{base_dict}")
2424
else:
2525
attr_file_name = search_json(json_dict[SPECIAL_FIELD_FLAG+"extends"]["from"], base_folder=base_folder)
2626
if not attr_file_name:
2727
raise NameError(f"ERROR! {json_dict[SPECIAL_FIELD_FLAG+'extends']['from']} path does not exists in")
2828
attr_json = load_json_as_dict(attr_file_name)
29-
attr_build = json_global_compile(attr_json, base_folder = os.path.dirname(attr_file_name))
30-
json_dict.update(attr_build)
29+
attr_build = json_global_compile(attr_json, base_folder = os.path.dirname(attr_file_name),object_route=json_dict[SPECIAL_FIELD_FLAG+"extends"]["from"])
30+
for exclude in json_dict[SPECIAL_FIELD_FLAG+"extends"].get(SPECIAL_FIELD_FLAG+"excludes",[]):
31+
if exclude in attr_build:
32+
print("EXCLUDES",exclude)
33+
attr_build.pop(exclude)
34+
json_dict.update(attr_build)
3135
json_dict.pop(SPECIAL_FIELD_FLAG+"extends")
3236
for attribute in json_dict:
3337
if type(json_dict[attribute]) == dict:
34-
json_dict[attribute] = special_flags_processing(json_dict[attribute], args, base_folder=base_folder, base_dict=base_dict)
38+
json_dict[attribute] = special_flags_processing(json_dict[attribute], args, base_folder=base_folder, base_dict=base_dict, object_route=f"{object_route}.{attribute}")
3539
return json_dict
3640

37-
def json_global_compile(json_dict, args = {}, *, base_folder=None, base_dict={}):# Should deep copy
38-
data = special_flags_processing(json_dict, args, base_folder=base_folder, base_dict=json_dict)
41+
def json_global_compile(json_dict, args = {}, *, base_folder=None, base_dict={}, object_route= ""):
42+
data = special_flags_processing(json_dict, args, base_folder=base_folder, base_dict=json_dict, object_route=object_route)
3943
return data
4044
class Compiler:
4145
blueprint: dict = {}
@@ -49,6 +53,8 @@ def compile_models(self):
4953
if MODELS_FIELD not in self.blueprint and EXTENDS_FIELD not in self.blueprint:
5054
raise NameError("models is not defined")
5155
build = json_global_compile(self.blueprint)
56+
pp = pprint.PrettyPrinter(indent=2)
57+
pp.pprint(build)
5258
for model in build["models"].copy():
5359
model_file_name = self.main_file
5460
if type(model) == str:
@@ -61,7 +67,7 @@ def compile_models(self):
6167
model_json = load_json_as_dict(model_file_name)
6268
elif type(model) == dict:
6369
model_json = model
64-
model_build = json_global_compile(model_json, base_folder = os.path.dirname(model_file_name))
70+
model_build = json_global_compile(model_json, base_folder = os.path.dirname(model_file_name), object_route=model)
6571
build["models"][model] = model_build
6672
pp = pprint.PrettyPrinter(indent=2)
6773
pp.pprint(build)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "imports",
3+
"models": {
4+
"user":{
5+
"attributes":{
6+
"id": {"type":"id"},
7+
"name":{"type":"str", "max":20, "required":true},
8+
"email":{"type":"email", "max":20, "required":true},
9+
"password":{"type":"password", "max":100, "required":false}
10+
},
11+
"create":{
12+
"request":{
13+
"name":{"type":"str", "max":20, "required":true},
14+
"email":{"type":"email", "max":20, "required":true},
15+
"password":{"type":"password", "max":100, "required":false}
16+
},
17+
"response":{
18+
"id": {"type":"id"}
19+
}
20+
},
21+
"list":{
22+
"response":{
23+
"id": {"type":"id"},
24+
"name":{"type":"str", "max":20, "required":true},
25+
"email":{"type":"email", "max":20, "required":true}
26+
}
27+
},
28+
"get":{
29+
"request":{
30+
"name":{"type":"str", "max":20, "required":true},
31+
"email":{"type":"email", "max":20, "required":true},
32+
"password":{"type":"password", "max":100, "required":false}
33+
},
34+
"response":{
35+
"name":{"type":"str", "max":20, "required":true},
36+
"email":{"type":"email", "max":20, "required":true},
37+
"password":{"type":"password", "max":100, "required":false}
38+
}
39+
}
40+
}
41+
},
42+
"services": {
43+
"user":"global.utils.services.user"
44+
}
45+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "imports",
3+
"models": {
4+
"user":"global.utils.auth.user.models.user"
5+
},
6+
"services": {
7+
"user":"global.utils.services.user"
8+
}
9+
}

0 commit comments

Comments
 (0)