gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8a69999c8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre8a69999c/lib/util.hl

6.1 KB

  1. // lib/util.hl — small helpers every topic shares (env, storage path, URLs, lists, text checks, Vienna time).
  2. // Statics only; no topic logic here.
  3. import { env } from 'hl:proc'
  4. import { timestamp } from 'hl:time'
  5. // ---- env and storage -----------------------------------------------------------------------
  6. static envOr = (name, fallback) => {
  7. v = env(name)
  8. return v != null && v.trim() != '' ? v.trim() : fallback
  9. }
  10. // THE TABLE DIRECTORY of every hl:mpackdb table (storage/mpackdb/; TICKETS_STORAGE moves it — the gate runs on its
  11. // own). Relative paths resolve against the ENTRY SCRIPT's directory (project.hl's) — tools must pass an absolute one.
  12. static storageDir = env('TICKETS_STORAGE') != null ? env('TICKETS_STORAGE') : './storage/mpackdb'
  13. // ---- the URLs a person uses ------------------------------------------------------------------
  14. // ticket #25: a project's page is /<slug>, a ticket's /<slug>/<number> (the old /projects/… forms answer 301);
  15. // the API keeps its /api/projects/… paths
  16. static ticketHref = (project, number) => { return '/' + project + '/' + number }
  17. static ticketApiHref = (project, number) => { return '/api/projects/' + project + '/tickets/' + number }
  18. static projectHrefOf = (project) => { return '/' + project }
  19. static settingsHrefOf = (project) => { return '/projects/' + project + '/settings' }
  20. // ---- lists and records -----------------------------------------------------------------------
  21. // an empty list written to hl:mpackdb comes back as an empty hybrid (`.length` null):
  22. // every read of a found list goes through here
  23. static countOf = (list) => {
  24. if (list == null) { return 0 }
  25. n = list.length
  26. return n == null ? 0 : n
  27. }
  28. static first = (list) => { return countOf(list) > 0 ? list[0] : null }
  29. // every record is written as a whole (hl:mpackdb's update replaces it)
  30. static merged = (rec, changes) => {
  31. out = {}
  32. for (k of rec.keys()) { out[k] = rec[k] }
  33. for (k of changes.keys()) { out[k] = changes[k] }
  34. return out
  35. }
  36. // insertion sorts (no list sort() in the language, hybriel #6) — stable; they sort their copy and return it
  37. static oldestFirst = (rows, field) => {
  38. let i = 1
  39. while (i < rows.length) {
  40. let cur = rows[i]
  41. let j = i - 1
  42. while (j >= 0 && rows[j][field] > cur[field]) {
  43. rows[j + 1] = rows[j]
  44. j = j - 1
  45. }
  46. rows[j + 1] = cur
  47. i = i + 1
  48. }
  49. return rows
  50. }
  51. static newestFirst = (rows, field) => {
  52. let i = 1
  53. while (i < rows.length) {
  54. let cur = rows[i]
  55. let j = i - 1
  56. while (j >= 0 && rows[j][field] < cur[field]) {
  57. rows[j + 1] = rows[j]
  58. j = j - 1
  59. }
  60. rows[j + 1] = cur
  61. i = i + 1
  62. }
  63. return rows
  64. }
  65. // ---- text ---------------------------------------------------------------------------------------
  66. static clean = (s) => { return s == null ? '' : ('' + s).trim() }
  67. // a SUBJECT is one line (mission ST): a line break or other control character in it becomes a space — it stands in a heading of the
  68. // Markdown view, in list rows, in a <title>, in a mail subject; a break there let a writer start their own heading / lines in what
  69. // programs and agents read. (The summary and comments are the multi-line texts.)
  70. static oneLine = (s) => {
  71. t = clean(s)
  72. let out = ''
  73. let i = 0
  74. while (i < t.length) {
  75. let c = t.charCodeAt(i)
  76. out = out + (c < 32 || c == 127 ? ' ' : t[i])
  77. i = i + 1
  78. }
  79. return out.trim()
  80. }
  81. // a query value, percent-encoded (encodeURIComponent is a global, hybriel#14)
  82. static encode = (s) => { return encodeURIComponent('' + s) }
  83. // a string of ASCII digits only (a ticket number in a URL); '' is not
  84. static isDigits = (s) => {
  85. if (s == null) { return false }
  86. t = '' + s
  87. if (t.length == 0 || t.length > 12) { return false }
  88. let i = 0
  89. while (i < t.length) {
  90. let c = t.charCodeAt(i)
  91. if (c < 48 || c > 57) { return false }
  92. i = i + 1
  93. }
  94. return true
  95. }
  96. // only lowercase hex (ident's one-time codes are 48 hex)
  97. static isHex = (s, max) => {
  98. if (s == null || hlTypeName(s) != 'String' || s.length == 0 || s.length > max) { return false }
  99. let i = 0
  100. while (i < s.length) {
  101. let c = s.charCodeAt(i)
  102. if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 102))) { return false }
  103. i = i + 1
  104. }
  105. return true
  106. }
  107. // a short one-line text: trimmed, at most `max` characters, no control characters
  108. static plainError = (s, max, what) => {
  109. if (s == null || hlTypeName(s) != 'String') { return what + ' must be text' }
  110. t = s.trim()
  111. if (t.length > max) { return what + ' is too long (at most ' + max + ' characters)' }
  112. let i = 0
  113. while (i < t.length) {
  114. let c = t.charCodeAt(i)
  115. if (c < 32 || c == 127) { return what + ' must be one line without control characters' }
  116. i = i + 1
  117. }
  118. return null
  119. }
  120. // ---- time: epoch ms → "YYYY-MM-DD HH:MM" in Europe/Vienna (ticket #10) ---------------------------
  121. // hl:time has no time zones (now() + a UTC timestamp() only; "timezones are a userland
  122. // concern" — its header). This is the smallest correct userland rule for Vienna: the EU
  123. // rule in force since 1996 — CEST (UTC+2) from the last Sunday of March 01:00 UTC to the
  124. // last Sunday of October 01:00 UTC, CET (UTC+1) otherwise. Storage stays epoch ms (UTC);
  125. // only the rendering shifts. Checked against node's Intl (tests/localtime.hl + the gate).
  126. static DAY = 86400000
  127. static HOUR = 3600000
  128. // integer division for a >= 0 (the language has `%` but no floor in the core)
  129. static idiv = (a, b) => { return (a - a % b) / b }
  130. // days since 1970-01-01 of a civil date (H. Hinnant's days_from_civil, years >= 1970)
  131. static daysFromCivil = (y, m, d) => {
  132. yy = m <= 2 ? y - 1 : y
  133. era = idiv(yy, 400)
  134. yoe = yy - era * 400
  135. mp = m > 2 ? m - 3 : m + 9
  136. doy = idiv(153 * mp + 2, 5) + d - 1
  137. doe = yoe * 365 + idiv(yoe, 4) - idiv(yoe, 100) + doy
  138. return era * 146097 + doe - 719468
  139. }
  140. // the last Sunday of a 31-day month (March, October), 01:00 UTC, as epoch ms
  141. static lastSundayAt1 = (y, m) => {
  142. days = daysFromCivil(y, m, 31)
  143. wd = (days + 4) % 7 // 0 = Sunday: 1970-01-01 was a Thursday
  144. return (days - wd) * DAY + HOUR
  145. }
  146. static viennaOffset = (ms) => {
  147. y = toNumber(timestamp(ms).slice(0, 4))
  148. return ms >= lastSundayAt1(y, 3) && ms < lastSundayAt1(y, 10) ? 2 * HOUR : HOUR
  149. }
  150. // "YYYY-MM-DD HH:MM", Vienna wall time — what a person reads
  151. static localStamp = (ms) => {
  152. t = timestamp(ms + viennaOffset(ms))
  153. return t.slice(0, 10) + ' ' + t.slice(11, 16)
  154. }

Branches

Latest commits

  • 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
  • 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
  • 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre
  • 8179d287tickets: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
  • 0398145ctickets: the table grid rule is marked functional for check-thememre
  • 40fddc20tickets takes components e54f83a: tables get thin grey lines from the theme, desktop toolbar stays one row with the Table button, F4 check counts 11 buttonsmre
  • c1b77d61tickets#35: text typed before the editor is built is taken in once by the build (the input handler no longer writes it to the field first, which doubled the first letters); the gate failure shows the surfacemre
  • 32bf1873tickets#35: the gate types right after the load with the CPU slowed, no waitingmre
  • 64ea9ca2tickets#35: text typed into the reply editor before the page has finished starting is kept; the gate types right after loadmre
  • ccd3a327tickets: the security gate expects frame-src to be exactly the ident address (the sign-in frame), still no wildcard or selfmre
  • 4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 66ef3005Merge branch 'iw-ident-widget'mre
  • bc0ad663tickets: a gap between your name and Log out in the phone header (they touched); gate checks itmre
  • 2f818d46UX2: report, LOG line, e2e fixes, gate pause after loadmre
  • af3ef7c4gate: the legacy state line says progressmre
  • 62480a00tickets#33: a state change with a note is a comment card in the feed (same framework rendering, can be liked, edited, deleted), its state line stands alone; gate checks for a new comment with and without a state change, at once and after a reloadmre
  • 4ae80007UX: Respond is one composer (state in its footer, button says what happens); New ticket / New project windows in the list heading row; project form shared; theme copied from layouts; gates and a lisbeth e2emre
  • f03b438atickets header: the selector alone top right plus your name and Log out as before the theme missions; the user icon is gonemre
  • 81f10e4eident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • e9f428e7tools: reown-authors (tracker#36: every author that is not Caramboleyo or Apollo becomes the project's conductor; antcolony, miserit-anthar, hybrilior, termuplex stay) and a read-only author surveymre