interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / interplane-forge / server / jsonp.om

339 lines · 6837 bytes Raw Blame History
1note forged server/jsonp.om: shared pieces of the machine form of every repo and user page (ForgeServer,
2note prefix fy / tfy; docs/API.md). A slice answers JSON when fjwant is true (Accept names
3note application/json and not text/html) at the same URL as its HTML page, and sets fjalt 3 on the HTML
4note page so the layout names that URL as its JSON alternate. Errors of a JSON request (any 4xx/5xx a
5note handler leaves with an empty fob, including the server's 404 for a repo not in the public table)
6note are a forge/error/1 document (ferrpage calls fyerr).
7text tfyuser "forge/user/1"
8text tfyerr1 "{\"schema\":\"forge/error/1\",\"status\":"
9text tfyerr2 ",\"error\":"
10text tfyerr3 ",\"message\":"
11text tfyrmvg ",\"reason\":\"moving\""
12text tfyend "}\n"
13text tfyh1 "{\"schema\":\""
14text tfyh2 "\",\"base\":\""
15text tfyh3 "\",\"repo\":{\"owner\":\""
16text tfyh4 "\",\"name\":\""
17text tfyh5 "\",\"rid\":\""
18text tfyh6 "\",\"path\":\""
19text tfyh7 "\",\"json\":\""
20text tfyh8 ".json\"}"
21text tfyu1 "{\"schema\":\""
22text tfyu2 "\",\"base\":\""
23text tfyu3 "\",\"user\":"
24note fyerr: the JSON error document for status st; the HTML title and message of the error page
25fn fyerr st ulong to void
26put fjalt 0 0
27ferrti st
28fjstart
29fput tfyerr1
30fnum st
31fput tfyerr2
32fjtb
33for i ulong get ftil 0 bound 256
34fjtc get fti i
35end
36fjstr
37fput tfyerr3
38a = get fobl 0
39ferrmsg st
40b = get fobl 0
41fjtb
42for k ulong sub b a bound 65536
43fjtc get fob add a k
44end
45put fobl 0 a
46fjstr
47if and eq st 503 ne get fmvng 0 0
48fput tfyrmvg
49end
50fput tfyend
51end
52note fyrhead t: open a repo page document: {"schema":"<t>","base":"<base>","repo":{owner, name, rid,
53note path, json}; the caller adds ,"key":value pairs (fyk) and closes it with fyend
54fn fyrhead t view uchar * to void
55i = get fridx 0
56fjstart
57fput tfyh1
58fput t
59fput tfyh2
60fputb
61fput tfyh3
62fput tfowner
63fput tfyh4
64for k ulong get fanl i bound 128
65fputc frnbyte i k
66end
67fput tfyh5
68fputid i
69fput tfyh6
70fjpath i
71fput tfyh7
72fjpath i
73fput tfyh8
74end
75note fyuhead t: open a user page document: {"schema":"<t>","base":"<base>","user":"<fown>"
76fn fyuhead t view uchar * to void
77fjstart
78fput tfyu1
79fput t
80fput tfyu2
81fputb
82fput tfyu3
83fjtb
84for k ulong get fownl 0 bound 64
85fjtc get fown k
86end
87fjstr
88end
89note fyk t: ,"<t>": (t is a plain ASCII key)
90fn fyk t view uchar * to void
91fputc 44
92fputc 34
93fput t
94fputc 34
95fputc 58
96end
97note fyk0 t: "<t>": without the comma (first key of an object)
98fn fyk0 t view uchar * to void
99fputc 34
100fput t
101fputc 34
102fputc 58
103end
104fn fyend to void
105fput tfyend
106end
107fn fybool b bool to void
108if b
109fput tfjtrue
110ret
111end
112fput tfjfals
113end
114fn fynull to void
115fput tfjnull
116end
117note fysx a n: fxo[a, a+n) as a JSON string (fjfx, named here for the slices)
118fn fysx a ulong n ulong to void
119fjfx a n
120end
121note fysv s: the bytes of s as a JSON string
122fn fysv s view uchar * to void
123fjtb
124for k ulong len s bound 65536
125fjtc get s k
126end
127fjstr
128end
129note fyself: this page's own URL as a JSON string: "<base><path without its first />[?<query>]"
130fn fyself to void
131fjtb
132for k ulong get fbasel 0 bound 64
133fjtc get fbase k
134end
135n = get fpathl 0
136for k ulong sub n 1 bound 4096
137fjtc get fpath add k 1
138end
139if gt get fqsl 0 0
140fjtc 63
141for k ulong get fqsl 0 bound 4096
142fjtc get fqs k
143end
144end
145fjstr
146end
147note fyalt: the HTML page names its own URL as the JSON alternate (fhalt in pages.om)
148fn fyalt to void
149put fjalt 0 3
150end
151note fypct a n: fxo[a, a+n) percent-encoded for a URL path; unreserved bytes and / are kept (the
152note bytes written are URL- and JSON-safe)
153fn fypct a ulong n ulong to void
154m = hmin n 4096
155for k ulong m bound 4096
156fypcc get fxo add a k
157end
158end
159note fypcc c: one byte of a URL path: unreserved and / as is, else %XX
160fn fypcc c uchar to void
161if fypok c
162fputc c
163ret
164end
165fputc 37
166fputc fjhexu shr ulong c 4
167fputc fjhexu and ulong c 15
168end
169fn fypok c uchar to bool
170if or fisaln c eq c 47
171ret true
172end
173if or eq c 46 eq c 45
174ret true
175end
176ret or eq c 95 eq c 126
177end
178note ---- /search?q= (forge/search/1): the repositories whose name or description holds q, then the
179note code matches of q on each default branch (git grep, at most 5 per repo and 100 in all), as fsearch
180text tfysr1 "{\"schema\":\"forge/search/1\",\"base\":\""
181text tfysr2 "\",\"query\":"
182text tfysr3 ",\n\"repos\":["
183text tfysr4 "],\n\"code\":["
184text tfysr5 "],\n\"code_truncated\":"
185text tfysc1 "{\"repo\":"
186text tfysc2 ",\"rid\":\""
187text tfysc3 "\",\"path\":"
188text tfysc4 ",\"line\":"
189text tfysc5 ",\"text\":"
190text tfysc6 ",\"html\":\""
191text tfysc7 "/blob/"
192text tfysc8 "#L"
193text tfysc9 "\"}"
194fn fyjsrch to void
195fjstart
196fput tfysr1
197fputb
198fput tfysr2
199q = get fql 0
200if eq q 0
201fynull
202else
203fjtb
204for k ulong q bound 256
205fjtc get fq k
206end
207fjstr
208end
209fput tfysr3
210n = ulong 0
211if gt q 0
212for i ulong get fan 0 bound FAMAX
213if fsrmatch i
214if gt n 0
215fput tfjsep
216end
217fputc 123
218fjcore i
219fputc 125
220n = add n 1
221end
222end
223end
224fput tfysr4
225put fhits 0 0
226if gt q 0
227for i ulong get fan 0 bound FAMAX
228if lt get fhits 0 100
229fyjcsr i
230end
231end
232end
233fput tfysr5
234fybool ge get fhits 0 100
235fyend
236end
237note fyjcsr: the code matches of repo i (the lines fcsrepo shows)
238fn fyjcsr i ulong to void
239fgreparg i
240st = fexec 10000000000
241if ne st 0
242ret
243end
244ln = get fxol 0
245p = ulong 0
246for it ulong 100000
247if ge p ln
248break
249end
250if ge get fhits 0 100
251break
252end
253e = fleol p ln
254fyjchit i p e
255p = add e 1
256end
257end
258note fyjchit: one line "refs/heads/<b>:<path>:<line>:<text>" as fcshit reads it; text cut at 300 bytes
259fn fyjchit i ulong p ulong e ulong to void
260a = add add p 12 get fabl i
261if ge a e
262ret
263end
264c1 = fcolon a e
265if ge c1 e
266ret
267end
268c2 = fcolon add c1 1 e
269if ge c2 e
270ret
271end
272if gt get fhits 0 0
273fputc 44
274end
275put fhits 0 add get fhits 0 1
276fput tfysc1
277fjtname i
278fjstr
279fput tfysc2
280fputid i
281fput tfysc3
282fjfx a sub c1 a
283fput tfysc4
284fjsize add c1 1 c2
285fput tfysc5
286m = hmin sub sub e c2 1 300
287fjfx add c2 1 m
288fput tfysc6
289fjpath i
290fput tfysc7
291fyjbr i
292fputc 47
293fypct a sub c1 a
294fput tfysc8
295fxput add c1 1 sub sub c2 c1 1
296fput tfysc9
297end
298note fyjbr: the default branch of repo i, percent-encoded like a path
299fn fyjbr i ulong to void
300o = get fabo i
301for k ulong get fabl i bound 64
302fypcc get fabr add o k
303end
304end
305note ---- /<owner> (forge/user/1) for the forge owner: the page fprofile renders (its follow counts, star
306note and favorite sums, repositories and starred repositories); every other profile view is social's
307text tfypr1 ",\"did\":\"did:key:"
308text tfypr2 "\",\"followers\":"
309text tfypr3 ",\"following\":"
310text tfypr4 ",\"tab\":\"stars\",\n\"repos\":["
311text tfypr5 "],\n\"stars_received\":"
312text tfypr6 ",\"favorites_received\":"
313text tfypr7 ",\n\"starred\":"
314text tfypr8 ",\n\"users\":null}\n"
315fn fyjprof to void
316fyuhead tfyuser
317fput tfypr1
318fput tfnid
319fput tfypr2
320fnum sofolln
321fput tfypr3
322fnum sofollg
323fput tfypr4
324for i ulong get fan 0 bound FAMAX
325if gt i 0
326fput tfjsep
327end
328fputc 123
329fjcore i
330fputc 125
331end
332fput tfypr5
333fnum fstarsum
334fput tfypr6
335fnum ffavsum
336fput tfypr7
337sojstars
338fput tfypr8
339end