Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/apps/interplane-forge/server/json.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / apps / interplane-forge / server / json.om` 642 lines ยท 11310 bytes Raw Blame History 1 note forged server/json.om: the machine form of /explore (schema forge/explore/1) and of the repo 2 note home (schema forge/repo/1), docs/API.md. A request gets JSON when its path ends in .json 3 note (/explore.json, //.json) or its Accept header names application/json and not 4 note text/html (/, /explore, //). Same data as the HTML page; keys are stable; ids are 5 note RIDs (rad:...) and full commit shas; times are ISO-8601 UTC. HTML stays the default. 6 global facc uchar 512 7 global faccl ulong 1 8 note fjalt: the HTML page offers its JSON form in : 0 none, 1 explore, 2 the repo fridx 9 global fjalt ulong 1 10 note fjt: the bytes of one JSON string, as large as the response body (fob, 8 MiB): a string that fits 11 note the response is written whole; a longer one cannot be sent, so fjtc marks the body (fobtr) and the 12 note answer is the whole 500 of fovfl, never a string cut short inside a 200. 13 global fjt uchar `8388608` 14 global fjtl ulong 1 15 text tfjctype "application/json; charset=utf-8" 16 text tfjaj "application/json" 17 text tfjth "text/html" 18 text tfjnull "null" 19 text tfjrep "\\ufffd" 20 text tfjbq "\\\"" 21 text tfjbb "\\\\" 22 text tfju00 "\\u00" 23 text tfjtrue "true" 24 text tfjfals "false" 25 note ---- Accept negotiation 26 fn fjhasat t view uchar * s ulong to bool 27 for k ulong len t bound 512 28 if ne flow get facc add s k get t k 29 ret false 30 end 31 end 32 ret true 33 end 34 fn fjhas t view uchar * to bool 35 n = get faccl 0 36 m = len t 37 if gt m n 38 ret false 39 end 40 for s ulong add sub n m 1 bound 512 41 if fjhasat t s 42 ret true 43 end 44 end 45 ret false 46 end 47 fn fjwant to bool 48 if not fjhas tfjaj 49 ret false 50 end 51 ret not fjhas tfjth 52 end 53 note ---- string building: fjt holds the bytes, fjstr writes them as one JSON string 54 fn fjtb to void 55 put fjtl 0 0 56 end 57 fn fjtc c uchar to void 58 n = get fjtl 0 59 if lt n len fjt 60 put fjt n c 61 put fjtl 0 add n 1 62 else 63 put fobtr 0 1 64 end 65 end 66 fn fjhex v ulong to uchar 67 if lt v 10 68 ret uchar add v 48 69 end 70 ret uchar add v 87 71 end 72 fn fjasc c uchar to void 73 if eq c 34 74 fput tfjbq 75 ret 76 end 77 if eq c 92 78 fput tfjbb 79 ret 80 end 81 if or or lt c 32 eq c 127 or or eq c 60 eq c 62 eq c 38 82 fput tfju00 83 fputc fjhex shr ulong c 4 84 fputc fjhex and ulong c 15 85 ret 86 end 87 fputc c 88 end 89 fn fjcont i ulong to bool 90 if ge i get fjtl 0 91 ret false 92 end 93 c = get fjt i 94 ret and ge c 128 le c 191 95 end 96 fn fjul3 i ulong c uchar to ulong 97 if not fjcont add i 1 98 ret 0 99 end 100 if not fjcont add i 2 101 ret 0 102 end 103 d = get fjt add i 1 104 if and eq c 224 lt d 160 105 ret 0 106 end 107 if and eq c 237 gt d 159 108 ret 0 109 end 110 ret 3 111 end 112 fn fjul4 i ulong c uchar to ulong 113 if not fjcont add i 1 114 ret 0 115 end 116 if not fjcont add i 2 117 ret 0 118 end 119 if not fjcont add i 3 120 ret 0 121 end 122 d = get fjt add i 1 123 if and eq c 240 lt d 144 124 ret 0 125 end 126 if and eq c 244 gt d 143 127 ret 0 128 end 129 ret 4 130 end 131 note fjulen: length of the well-formed UTF-8 sequence at fjt[i] (1..4), 0 when it is not well formed 132 fn fjulen i ulong to ulong 133 c = get fjt i 134 if lt c 128 135 ret 1 136 end 137 if and ge c 194 le c 223 138 if fjcont add i 1 139 ret 2 140 end 141 ret 0 142 end 143 if and ge c 224 le c 239 144 ret fjul3 i c 145 end 146 if and ge c 240 le c 244 147 ret fjul4 i c 148 end 149 ret 0 150 end 151 note fjstr: "..." with JSON escapes; ill-formed UTF-8 bytes become U+FFFD, so the body is valid JSON 152 fn fjstr to void 153 fputc 34 154 n = get fjtl 0 155 i = ulong 0 156 for it ulong n bound `8388608` 157 if ge i n 158 break 159 end 160 l = fjulen i 161 if eq l 0 162 fput tfjrep 163 i = add i 1 164 continue 165 end 166 if eq l 1 167 fjasc get fjt i 168 i = add i 1 169 continue 170 end 171 for k ulong l bound 4 172 fputc get fjt add i k 173 end 174 i = add i l 175 end 176 fputc 34 177 end 178 fn fjtxt t view uchar * to void 179 fjtb 180 for k ulong len t bound 4096 181 fjtc get t k 182 end 183 fjstr 184 end 185 note fjfx: fxo[a, a+n) as a JSON string 186 fn fjfx a ulong n ulong to void 187 fjtb 188 note the bound is the size of fxo: a file name or a path can be longer than 65,536 bytes, and bound 189 note 65536 was trap 4 (exit 104) on one. A string over 8 MiB is the whole 500 (fjtc). 190 for k ulong n bound `16777216` 191 fjtc get fxo add a k 192 end 193 fjstr 194 end 195 note ---- times: ISO-8601 UTC from an epoch (days to civil date, proleptic Gregorian) 196 fn fj2 v ulong to void 197 fputc uchar add div v 10 48 198 fputc uchar add rem v 10 48 199 end 200 fn fj4 v ulong to void 201 fj2 div v 100 202 fj2 rem v 100 203 end 204 fn fjyoe doe ulong to ulong 205 a = sub doe div doe 1460 206 b = add a div doe 36524 207 ret div sub b div doe 146096 365 208 end 209 fn fjdate dd ulong to void 210 z = add dd 719468 211 era = div z 146097 212 doe = sub z mul era 146097 213 yoe = fjyoe doe 214 y = add yoe mul era 400 215 doy = sub doe sub add mul 365 yoe div yoe 4 div yoe 100 216 mp = div add mul 5 doy 2 153 217 d = add sub doy div add mul 153 mp 2 5 1 218 m = ulong 0 219 if lt mp 10 220 m = add mp 3 221 else 222 m = sub mp 9 223 end 224 if le m 2 225 y = add y 1 226 end 227 fj4 y 228 fputc 45 229 fj2 m 230 fputc 45 231 fj2 d 232 end 233 note fjisob: YYYY-MM-DDTHH:MM:SSZ (no quotes); fjiso: the same as a JSON string, or null for 0 234 fn fjisob t ulong to void 235 s = rem t 86400 236 fjdate div t 86400 237 fputc 84 238 fj2 div s 3600 239 fputc 58 240 fj2 div rem s 3600 60 241 fputc 58 242 fj2 rem s 60 243 fputc 90 244 end 245 fn fjiso t ulong to void 246 if eq t 0 247 fput tfjnull 248 ret 249 end 250 fputc 34 251 fjisob t 252 fputc 34 253 end 254 note fjday: YYYY-MM-DD (UTC) for the HTML pages 255 fn fjday t ulong to void 256 fjdate div t 86400 257 end 258 note ---- fields shared by explore items and the repo object 259 text tfjo1 "\"owner\":\"" 260 text tfjo2 "\",\"name\":" 261 text tfjo3 ",\"rid\":\"" 262 text tfjo4 "\",\"path\":\"" 263 text tfjo5 "\",\"json\":\"" 264 text tfjo6 ".json\",\"description\":" 265 text tfjo7 ",\"default_branch\":\"" 266 text tfjo8 "\",\"stars\":" 267 text tfjo9 ",\"last_commit\":" 268 text tfjlc1 "{\"sha\":\"" 269 text tfjlc2 "\",\"time\":" 270 text tfjlc3 ",\"subject\":" 271 fn fjpath i ulong to void 272 fputb 273 fput tfowner 274 fputc 47 275 for k ulong get fanl i bound 128 276 fputc frnbyte i k 277 end 278 end 279 fn fjtdesc i ulong to void 280 fjtb 281 o = get fado i 282 for k ulong get fadl i bound 4096 283 fjtc get fadesc add o k 284 end 285 end 286 fn fjtname i ulong to void 287 fjtb 288 for k ulong get fanl i bound 128 289 fjtc frnbyte i k 290 end 291 end 292 note fjsubj: the subject from falc "%cs %h %s" (after the second space) 293 fn fjsubj i ulong to void 294 fjtb 295 o = get falco i 296 n = get falcl i 297 sp = ulong 0 298 for k ulong n bound 1024 299 c = get falc add o k 300 if lt sp 2 301 if eq c 32 302 sp = add sp 1 303 end 304 continue 305 end 306 fjtc c 307 end 308 fjstr 309 end 310 fn fjlast i ulong to void 311 if ne get falsl i 40 312 fput tfjnull 313 ret 314 end 315 fput tfjlc1 316 o = mul i 40 317 for k ulong 40 318 fputc get falsh add o k 319 end 320 fput tfjlc2 321 fjiso get falct i 322 fput tfjlc3 323 fjsubj i 324 fputc 125 325 end 326 fn fjcore i ulong to void 327 fput tfjo1 328 fput tfowner 329 fput tfjo2 330 fjtname i 331 fjstr 332 fput tfjo3 333 fputid i 334 fput tfjo4 335 fjpath i 336 fput tfjo5 337 fjpath i 338 fput tfjo6 339 if eq get fadl i 0 340 fput tfjnull 341 else 342 fjtdesc i 343 fjstr 344 end 345 fput tfjo7 346 o = get fabo i 347 for k ulong get fabl i bound 64 348 fputc get fabr add o k 349 end 350 fput tfjo8 351 fnum sostarn i 352 fput tfjo9 353 fjlast i 354 end 355 note ---- /explore.json (also / and /explore with Accept: application/json) 356 text tfjex1 "{\"schema\":\"forge/explore/1\",\"base\":\"" 357 text tfjex2 "\",\"count\":" 358 text tfjex3 ",\"repos\":[\n" 359 text tfjex4 "\n]}\n" 360 text tfjsep ",\n" 361 fn fjstart to void 362 put fkind 0 1 363 put fobl 0 0 364 fsetct tfjctype 365 end 366 fn fjexplore to void 367 fjstart 368 fput tfjex1 369 fputb 370 fput tfjex2 371 fnum get fan 0 372 fput tfjex3 373 for i ulong get fan 0 bound FAMAX 374 if gt i 0 375 fput tfjsep 376 end 377 fputc 123 378 fjcore i 379 fputc 125 380 end 381 fput tfjex4 382 end 383 note ---- //.json (also // with Accept: application/json) 384 text tfjr1 "{\"schema\":\"forge/repo/1\",\n" 385 text tfjr2 ",\n\"favorites\":" 386 text tfjar1 ",\n\"archives\":{\"zip\":\"" 387 text tfjarh "/archive/refs/heads/" 388 text tfjar2 ".zip\",\"tar_gz\":\"" 389 text tfjar3 ".tar.gz\"}" 390 text tfjr3 ",\n\"counts\":" 391 text tfjr4 "\n}\n" 392 fn fjrepo to void 393 i = get fridx 0 394 fjstart 395 fput tfjr1 396 fjcore i 397 fput tfjr2 398 fnum sofavn i 399 fjclone i 400 fput tfjar1 401 fjarch i 402 fput tfjar2 403 fjarch i 404 fput tfjar3 405 fjfiles i 406 fput tfjr3 407 fzjson i 408 fput tfjr4 409 end 410 fn fjarch i ulong to void 411 fjpath i 412 fput tfjarh 413 fputbr i 414 end 415 note ---- top-level files of the default branch: git ls-tree -z -l (the browse home's list) 416 text tfjlst "ls-tree" 417 text tfjz "-z" 418 text tfjl "-l" 419 text tfjf1 ",\n\"files\":" 420 text tfjf2 "[\n" 421 text tfjf3 "\n]" 422 text tfjf4 "{\"name\":" 423 text tfjf5 ",\"type\":\"" 424 text tfjf6 "\",\"sha\":\"" 425 text tfjf7 "\",\"size\":" 426 text tfjf8 ",\n\"files_truncated\":" 427 text tfjrm1 ",\n\"readme\":" 428 text tfjrm2 "{\"name\":" 429 text tfjrm3 ",\"html\":\"" 430 text tfjblob "/blob/" 431 text tfjrm4 "\",\"raw\":\"" 432 text tfjraw "/raw/" 433 text tfjrm5 "\"}" 434 text tfjrdm "readme" 435 text tfjrdmd "readme.md" 436 global fjrda ulong 1 437 global fjrdn ulong 1 438 global fjrdq ulong 1 439 fn fjlsarg i ulong ns ulong to void 440 fkgiti i 441 fka tfjlst 442 fka tfjz 443 fka tfjl 444 fkopen 445 if eq ns 1 446 fkt tfrns 447 fkt tfnid 448 fkt tfrnsh 449 else 450 fkt tfrh 451 end 452 o = get fabo i 453 for k ulong get fabl i bound 64 454 fkc get fabr add o k 455 end 456 end 457 fn fjfiles i ulong to void 458 put fjrdq 0 0 459 fjlsarg i 0 460 st = fexec `5000000000` 461 if ne st 0 462 fjlsarg i 1 463 st = fexec `5000000000` 464 end 465 fput tfjf1 466 if ne st 0 467 fput tfjnull 468 fput tfjrm1 469 fput tfjnull 470 ret 471 end 472 fput tfjf2 473 ln = get fxol 0 474 p = ulong 0 475 n = ulong 0 476 for it ulong 100000 477 if ge p ln 478 break 479 end 480 e = fjnul p ln 481 note a listing cut by fxo ends in a name without its NUL: that piece is not an entry 482 if and ge e ln ne get fxotr 0 0 483 break 484 end 485 if lt n 1000 486 if gt n 0 487 fput tfjsep 488 end 489 fjent p e 490 end 491 n = add n 1 492 p = add e 1 493 end 494 fput tfjf3 495 fput tfjf8 496 note truncated: more than the 1000 entries listed, or a listing longer than fxo (entries past it unknown) 497 if or gt n 1000 ne get fxotr 0 0 498 fput tfjtrue 499 else 500 fput tfjfals 501 end 502 fput tfjrm1 503 fjrdme i 504 end 505 fn fjnul p ulong ln ulong to ulong 506 j = p 507 for it ulong sub ln p bound `16777216` 508 if eq get fxo j 0 509 ret j 510 end 511 j = add j 1 512 end 513 ret ln 514 end 515 fn fjch a ulong e ulong c uchar to ulong 516 j = a 517 for it ulong sub e a bound `16777216` 518 if eq get fxo j c 519 ret j 520 end 521 j = add j 1 522 end 523 ret e 524 end 525 note fjent: one ls-tree -l record " \t" in fxo[p, e) 526 fn fjent p ulong e ulong to void 527 s1 = fjch p e 32 528 s2 = fjch add s1 1 e 32 529 s3 = fjch add s2 1 e 32 530 tb = fjch add s3 1 e 9 531 if ge tb e 532 fput tfjnull 533 ret 534 end 535 fput tfjf4 536 fjfx add tb 1 sub sub e tb 1 537 fput tfjf5 538 fxput add s1 1 sub sub s2 s1 1 539 fput tfjf6 540 fxput add s2 1 sub sub s3 s2 1 541 fput tfjf7 542 fjsize add s3 1 tb 543 fputc 125 544 fjrdsee add s1 1 add tb 1 e 545 end 546 fn fjsize a ulong e ulong to void 547 v = ulong 0 548 d = ulong 0 549 m = hmin sub e a 64 550 for k ulong m bound 64 551 c = get fxo add a k 552 if fisdig c 553 v = add mul v 10 ulong sub c 48 554 d = add d 1 555 end 556 end 557 if eq d 0 558 fput tfjnull 559 ret 560 end 561 fnum v 562 end 563 note fjrdsee: remember the README among the blobs (readme.md first, then any name starting readme) 564 fn fjrdsee t ulong a ulong e ulong to void 565 if ne get fxo t 98 566 ret 567 end 568 n = sub e a 569 q = fjrdkind a n 570 if eq q 0 571 ret 572 end 573 r = get fjrdq 0 574 if and ne r 0 le r q 575 ret 576 end 577 put fjrdq 0 q 578 put fjrda 0 a 579 put fjrdn 0 n 580 end 581 fn fjrdkind a ulong n ulong to ulong 582 if lt n len tfjrdm 583 ret 0 584 end 585 for k ulong len tfjrdm 586 if ne flow get fxo add a k get tfjrdm k 587 ret 0 588 end 589 end 590 if ne n len tfjrdmd 591 ret 2 592 end 593 for k ulong len tfjrdmd 594 if ne flow get fxo add a k get tfjrdmd k 595 ret 2 596 end 597 end 598 ret 1 599 end 600 fn fjrdme i ulong to void 601 if eq get fjrdq 0 0 602 fput tfjnull 603 ret 604 end 605 a = get fjrda 0 606 n = get fjrdn 0 607 fput tfjrm2 608 fjfx a n 609 fput tfjrm3 610 fjpath i 611 fput tfjblob 612 fputbr i 613 fputc 47 614 fjpct a n 615 fput tfjrm4 616 fjpath i 617 fput tfjraw 618 fputbr i 619 fputc 47 620 fjpct a n 621 fput tfjrm5 622 end 623 note fjpct: fxo[a, a+n) percent-encoded for a URL path (unreserved bytes kept) 624 fn fjpct a ulong n ulong to void 625 m = hmin n 4096 626 for k ulong m bound 4096 627 c = get fxo add a k 628 if or fisaln c or or eq c 46 eq c 45 eq c 95 629 fputc c 630 else 631 fputc 37 632 fputc fjhexu shr ulong c 4 633 fputc fjhexu and ulong c 15 634 end 635 end 636 end 637 fn fjhexu v ulong to uchar 638 if lt v 10 639 ret uchar add v 48 640 end 641 ret uchar add v 55 642 end