File tree Expand file tree Collapse file tree 12 files changed +195
-20
lines changed
global/communication/chat/services Expand file tree Collapse file tree 12 files changed +195
-20
lines changed Original file line number Diff line number Diff line change @@ -24,4 +24,56 @@ defines all the models for a specific entity and its different variants dependin
24
24
### Service component
25
25
Denoted with the extension ".service.json" (ex: "auth.service.json")
26
26
27
- defines the inputs, input processing and outputs of a certain request
27
+ defines the inputs, input processing and outputs of a certain request
28
+
29
+ ## Global special attributes
30
+
31
+ ### __ constructor
32
+ lets you specify wich attributes can be modified and are required
33
+
34
+ use case:
35
+
36
+ ``` js
37
+ // basic_math_service.service.json
38
+ {
39
+ " __constructor" : {
40
+ " number_a" : {
41
+ " description" : " first number to be operated"
42
+ " default" : 1
43
+ },
44
+ " number_a" : {
45
+ " description" : " second number to be operated"
46
+ " default" : 2
47
+ }
48
+ },
49
+ " endpoints" : {
50
+ " sum numbers" : {
51
+ " request" : {
52
+ " __number_a" : {
53
+ " type" : " int" ,
54
+ },
55
+ " __number_b" : {
56
+ " type" : " int" ,
57
+ }
58
+ },
59
+ " response" : {
60
+ " answer" : {" type" : " int" }
61
+ }
62
+ },
63
+ }
64
+ }
65
+ ```
66
+
67
+ now you can call it like
68
+ ``` js
69
+ // main.app.json
70
+ {
71
+ " services" : {
72
+ " math" : {
73
+ " __from" : " basic_math_service.service.json"
74
+ " number_a" : 3 ,
75
+ " number_b" : 4 ,
76
+ }
77
+ }
78
+ }
79
+ ```
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " calculator" ,
3
+ "models" : {
4
+ },
5
+ "services" : {
6
+ "operate" :{
7
+ "endpoints" : {
8
+ "sum" :{
9
+ "request" :{"a" :{"type" :" int" }, "b" :{"type" :" int" }},
10
+ "response" :{"a" :{"type" :" int" }, "b" :{"type" :" int" }},
11
+ "processing" :{
12
+ "engine" : " python3.8" ,
13
+ "code" : [
14
+ " print(f\" summing\" {a} + {b})" ,
15
+ " return a+b"
16
+ ]
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " calculator" ,
3
+ "models" : {
4
+ },
5
+ "services" : {
6
+ "operate" :{
7
+ "endpoints" : {
8
+ "sum" :{
9
+ "request" :{"a" :{"type" :" int" }, "b" :{"type" :" int" }},
10
+ "response" :{"a" :{"type" :" int" }, "b" :{"type" :" int" }},
11
+ "processing" :{
12
+ "engine" : " python3.8" ,
13
+ "code" : [
14
+ " print(f\" summing\" {a} + {b})" ,
15
+ " return a+b"
16
+ ]
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "endpoints" : {
3
+ "sum" :{
4
+ "request" :{"a" :{"type" :" int" }, "b" :{"type" :" int" }},
5
+ "response" :{"a" :{"type" :" int" }, "b" :{"type" :" int" }},
6
+ "processing" :{
7
+ "from" : " processing.operations.sum" ,
8
+ "number_a" : " a" ,
9
+ "number_b" : " b" ,
10
+ "message" : " calculating sum"
11
+ }
12
+ }
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "engine" : " python3.8" ,
3
+ "__constructor" :{
4
+ "description" : " what seams like a simple sum" ,
5
+ "number_a" :{"type" :" str" , "default" :" number_a" },
6
+ "number_b" :{"type" :" str" , "default" :" number_b" },
7
+ "message" :{"type" :" str" , "default" :" adding {__number_a} to {__number_b}" }
8
+ },
9
+ "inputs" :{
10
+ "__number_a" :{"type" :" str" , "required" :true },
11
+ "__number_b" :{"type" :" str" , "required" :true }
12
+ },
13
+ "code" : [
14
+ {
15
+ "type" : " function" ,
16
+ "name" : " print" ,
17
+ "args" : [" f\" __message\" " ]
18
+ },
19
+ {
20
+ "type" : " variable" ,
21
+ "variable_type" : " str" ,
22
+ "name" : " sum_result" ,
23
+ "equals" : [" __number_a+number_b" ]
24
+ },
25
+ {
26
+ "type" : " return" ,
27
+ "args" : [" sum_result" ]
28
+ }
29
+ ]
30
+ }
Original file line number Diff line number Diff line change 2
2
"name" : " facebook" ,
3
3
"models" : {
4
4
"user" :" global.models.user" ,
5
- "conversation" :" global.comunication .chat.models.conversation" ,
6
- "message" :" global.comunication .chat.feed.models.message"
5
+ "conversation" :" global.communication .chat.models.conversation" ,
6
+ "message" :" global.communication .chat.feed.models.message"
7
7
},
8
8
"services" : {
9
- "user" :" global.utils.services.user"
9
+ "user" :" global.utils.services.user" ,
10
+ "conversation" :" global.communication.chat.services.conversation" ,
11
+ "message" :" global.communication.chat.services.message"
10
12
}
11
13
}
Original file line number Diff line number Diff line change
1
+ {
2
+
3
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+
3
+ }
Original file line number Diff line number Diff line change 1
1
from json_compiler .Compiler import Compiler as json_compiler
2
2
import sys
3
3
COMPILERS = {
4
- "django-postgres" : "under development" ,
5
- "flask-mongo" : "under development" ,
6
- "nodejs-mongo" : "under development" ,
7
- "json" : json_compiler
4
+ "django-postgres.v1 " : "under development" ,
5
+ "flask-mongo.v1 " : "under development" ,
6
+ "nodejs-mongo.v1 " : "under development" ,
7
+ "json.v1 " : json_compiler
8
8
}
9
9
def compile (compiler_name , project_name ):
10
10
compiler = COMPILERS [compiler_name ](project_name )
@@ -18,4 +18,4 @@ def main():
18
18
return
19
19
20
20
main ()
21
- #python .\compiler.py c json ../blueprints/examples/facebook/main.app.json
21
+ #python .\compiler.py c " json.v1" ../blueprints/examples/facebook/main.app.json
Original file line number Diff line number Diff line change 1
1
import json
2
- from searcher import search_json
2
+ from utils . searcher import search_json
3
3
MODELS_FIELD = "models"
4
- EXTENDS_FIELD = "__extends"
4
+ SPECIAL_FIELD_FLAG = "__"
5
+ EXTENDS_FIELD = SPECIAL_FIELD_FLAG + "extends"
6
+
5
7
6
8
class Compiler :
7
9
blueprint :dict = {}
@@ -13,8 +15,12 @@ def compile_models(self):
13
15
if MODELS_FIELD not in self .blueprint and EXTENDS_FIELD not in self .blueprint :
14
16
raise NameError ("models is not defined" )
15
17
for model in self .blueprint ["models" ]:
16
- print (model )
18
+ if model .startswith (SPECIAL_FIELD_FLAG ):
19
+ if model == "__extends" :
20
+ print ("extends!" )
21
+ # Extend
22
+ continue
17
23
if type (model ) == str :
18
- search_json (model , self .main_file )
24
+ print ( "model" , search_json (self . blueprint [ "models" ][ model ] , self .main_file ) )
19
25
def compile (self ):
20
26
self .compile_models ()
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import os
2
+ GLOBAL_ROUTE = "../blueprints"
3
+ def get_dir (path ):
4
+ return [ x .split ("." ) for x in os .listdir (path )]
5
+ def get_json_file (splitted_route , dir_path ):
6
+ files_names = get_dir (dir_path )
7
+ for file_name in files_names :
8
+ if splitted_route [0 ] == file_name [0 ]:
9
+ new_path = dir_path + "/" + "." .join (file_name )
10
+ if os .path .isfile (new_path ):
11
+ return new_path
12
+ else :
13
+ new_splitted_route = splitted_route [1 :]
14
+ nested = get_json_file (new_splitted_route , new_path )
15
+ return nested
16
+
17
+ #get_json(file_name.)
18
+ return False
19
+ def search_json (route , base_file ):
20
+ splitted_route = route .split ("." )
21
+ # Local Path
22
+ json_component = get_json_file (splitted_route , (os .path .dirname (base_file )))
23
+ if json_component :
24
+ return json_component
25
+ # Global Path
26
+ json_component = get_json_file (splitted_route , GLOBAL_ROUTE )
27
+ if json_component :
28
+ return json_component
You can’t perform that action at this time.
0 commit comments