-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.jac
269 lines (229 loc) · 5.16 KB
/
main.jac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
"""Example of simple walker walking nodes."""
import:py from jaclang_jaseci, FastAPI, start;
import:py from jaclang_jaseci.types, File, Files, OptFile, OptFiles;
import:py from jaclang_jaseci.models, User as BaseUser;
import:py from jaclang_jaseci.plugins, specs, DocAnchor;
import:py from jaclang_jaseci.utils, SendGridEmailer;
node boy {
has val1: str,
val2: str;
has val3: str;
}
node girl {
has val: str;
}
node someone {
has val: list = [];
}
walker create_sample_graph {
can enter with `root entry {
b = boy(val1="a", val2="b");
g = girl(val="b");
b ++> g;
root ++> b;
return True;
}
obj Specs {}
}
walker visit_sample_graph {
can enter1 with `root entry {
print("where ami");
report root;
boys = [-->];
report boys[0];
visit boys;
return 1;
}
can enter2 with boy entry {
girls = [-->];
report girls[0];
visit girls;
return 2;
}
can enter3 with girl entry {
anyone = [-->];
report anyone;
visit anyone;
return 3;
}
}
walker update_sample_graph {
can enter1 with `root entry {
boys = [-->];
visit boys;
}
can enter2 with boy entry {
old = [-->];
report old[0];
new = girl(val="new");
here ++> new;
old[0].destroy();
report ([-->])[0];
}
obj Specs {}
}
walker create_list_field {
can enter1 with `root entry {
a = someone();
root ++> a;
report a;
}
obj Specs {}
}
walker update_list_field {
can enter2 with someone entry {
here.val.append(1);
report here;
visit [-->];
}
obj Specs {}
}
walker get_list_field {
can enter2 with someone entry {
report here;
report [-->];
}
obj Specs {}
}
walker allow_other {
has root_id: str = None,
node_id: str = None,
write: bool = False;
can enter2 with someone entry {
if self.root_id {
here.allow_root(DocAnchor.ref(self.root_id), self.write);
}
if self.node_id {
here.allow_node(DocAnchor.ref(self.node_id), self.write);
}
report here;
}
obj Specs {}
}
walker disallow_other {
has root_id: str = None,
node_id: str = None;
can enter2 with someone entry {
if self.root_id {
here.disallow_root(DocAnchor.ref(self.root_id));
}
if self.node_id {
here.disallow_node(DocAnchor.ref(self.node_id));
}
report here;
}
obj Specs {}
}
walker connect_other_node {
has node_id: str = None;
can enter2 with someone entry {
if self.node_id {
other_node = DocAnchor.ref(self.node_id).connect(here);
here ++> other_node;
}
report here;
}
obj Specs {}
}
walker post_no_body {}
# walker post_with_body {
# has a: str;
# }
walker get_no_body {
obj Specs {
static has methods: list = ["get"];
}
}
walker get_with_query {
has a: str;
obj Specs {
static has methods: list = ["get"],
as_query: list = ["a"];
}
}
walker get_all_query {
has a: str;
has b: str;
obj Specs {
static has methods: list = ["get"],
as_query: list = "*",
auth: bool = False;
}
}
walker combination {
has a: str;
has b: str;
has c: str;
obj Specs {
static has methods: list = ["post", "get"],
as_query: list = ["a", "b"];
}
}
walker post_path_var {
has a: str;
obj Specs {
static has path: str = "/{a}",
methods: list = ["post", "get"];
}
}
walker combination2 {
has a: str;
has b: str;
has c: str;
obj Specs {
static has path: str = "/{a}",
methods: list = ["post", "get", "put", "patch", "delete", "head", "trace", "options"],
as_query: list = ["b"];
}
}
walker post_with_file {
has single: File;
has multiple: Files;
has singleOptional: OptFile = None;
has multipleOptional: OptFiles = None;
can enter with `root entry {
print(self.single);
print(self.multiple);
print(self.singleOptional);
print(self.multipleOptional);
}
obj Specs {}
}
walker post_with_body_and_file {
has val: int;
has single: File;
has multiple: Files;
has optional_val: int = 0;
can enter with `root entry {
print(self.val);
print(self.optional_val);
print(self.single);
print(self.multiple);
}
obj Specs {
static has auth: bool = False;
}
}
walker nested1 {
has sample: str = "";
can enter with `root entry {
self.sample = "nested1";
}
obj Specs {
static has private: bool = True;
}
}
walker nested2 {
can enter with `root entry {
wlk = here spawn nested1();
report wlk.sample;
report "nested2";
}
obj Specs {
static has auth: bool = False;
}
}
with entry:__main__ {
# SendGridEmailer.start();
start(host="0.0.0.0", port=8000);
}