tickets
All repositories: gitoria
6.1 KB
// lib/util.hl — small helpers every topic shares (env, storage path, URLs, lists, text checks, Vienna time).// Statics only; no topic logic here.import { env } from 'hl:proc'import { timestamp } from 'hl:time'// ---- env and storage -----------------------------------------------------------------------static envOr = (name, fallback) => {v = env(name)return v != null && v.trim() != '' ? v.trim() : fallback}// THE TABLE DIRECTORY of every hl:mpackdb table (storage/mpackdb/; TICKETS_STORAGE moves it — the gate runs on its// own). Relative paths resolve against the ENTRY SCRIPT's directory (project.hl's) — tools must pass an absolute one.static storageDir = env('TICKETS_STORAGE') != null ? env('TICKETS_STORAGE') : './storage/mpackdb'// ---- the URLs a person uses ------------------------------------------------------------------// ticket #25: a project's page is /<slug>, a ticket's /<slug>/<number> (the old /projects/… forms answer 301);// the API keeps its /api/projects/… pathsstatic ticketHref = (project, number) => { return '/' + project + '/' + number }static ticketApiHref = (project, number) => { return '/api/projects/' + project + '/tickets/' + number }static projectHrefOf = (project) => { return '/' + project }static settingsHrefOf = (project) => { return '/projects/' + project + '/settings' }// ---- lists and records -----------------------------------------------------------------------// an empty list written to hl:mpackdb comes back as an empty hybrid (`.length` null):// every read of a found list goes through herestatic countOf = (list) => {if (list == null) { return 0 }n = list.lengthreturn n == null ? 0 : n}static first = (list) => { return countOf(list) > 0 ? list[0] : null }// every record is written as a whole (hl:mpackdb's update replaces it)static merged = (rec, changes) => {out = {}for (k of rec.keys()) { out[k] = rec[k] }for (k of changes.keys()) { out[k] = changes[k] }return out}// insertion sorts (no list sort() in the language, hybriel #6) — stable; they sort their copy and return itstatic oldestFirst = (rows, field) => {let i = 1while (i < rows.length) {cur = rows[i]let j = i - 1while (j >= 0 && rows[j][field] > cur[field]) {rows[j + 1] = rows[j]j = j - 1}rows[j + 1] = curi = i + 1}return rows}static newestFirst = (rows, field) => {let i = 1while (i < rows.length) {cur = rows[i]let j = i - 1while (j >= 0 && rows[j][field] < cur[field]) {rows[j + 1] = rows[j]j = j - 1}rows[j + 1] = curi = i + 1}return rows}// ---- text ---------------------------------------------------------------------------------------static clean = (s) => { return s == null ? '' : ('' + s).trim() }// 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// 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// programs and agents read. (The summary and comments are the multi-line texts.)static oneLine = (s) => {t = clean(s)let out = ''let i = 0while (i < t.length) {c = t.charCodeAt(i)out = out + (c < 32 || c == 127 ? ' ' : t[i])i = i + 1}return out.trim()}// a query value, percent-encoded (encodeURIComponent is a global, hybriel#14)static encode = (s) => { return encodeURIComponent('' + s) }// a string of ASCII digits only (a ticket number in a URL); '' is notstatic isDigits = (s) => {if (s == null) { return false }t = '' + sif (t.length == 0 || t.length > 12) { return false }let i = 0while (i < t.length) {c = t.charCodeAt(i)if (c < 48 || c > 57) { return false }i = i + 1}return true}// only lowercase hex (ident's one-time codes are 48 hex)static isHex = (s, max) => {if (s == null || hlTypeName(s) != 'String' || s.length == 0 || s.length > max) { return false }let i = 0while (i < s.length) {c = s.charCodeAt(i)if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 102))) { return false }i = i + 1}return true}// a short one-line text: trimmed, at most `max` characters, no control charactersstatic plainError = (s, max, what) => {if (s == null || hlTypeName(s) != 'String') { return what + ' must be text' }t = s.trim()if (t.length > max) { return what + ' is too long (at most ' + max + ' characters)' }let i = 0while (i < t.length) {c = t.charCodeAt(i)if (c < 32 || c == 127) { return what + ' must be one line without control characters' }i = i + 1}return null}// ---- time: epoch ms → "YYYY-MM-DD HH:MM" in Europe/Vienna (ticket #10) ---------------------------// hl:time has no time zones (now() + a UTC timestamp() only; "timezones are a userland// concern" — its header). This is the smallest correct userland rule for Vienna: the EU// rule in force since 1996 — CEST (UTC+2) from the last Sunday of March 01:00 UTC to the// last Sunday of October 01:00 UTC, CET (UTC+1) otherwise. Storage stays epoch ms (UTC);// only the rendering shifts. Checked against node's Intl (tests/localtime.hl + the gate).static DAY = 86400000static HOUR = 3600000// integer division for a >= 0 (the language has `%` but no floor in the core)static idiv = (a, b) => { return (a - a % b) / b }// days since 1970-01-01 of a civil date (H. Hinnant's days_from_civil, years >= 1970)static daysFromCivil = (y, m, d) => {yy = m <= 2 ? y - 1 : yera = idiv(yy, 400)yoe = yy - era * 400mp = m > 2 ? m - 3 : m + 9doy = idiv(153 * mp + 2, 5) + d - 1doe = yoe * 365 + idiv(yoe, 4) - idiv(yoe, 100) + doyreturn era * 146097 + doe - 719468}// the last Sunday of a 31-day month (March, October), 01:00 UTC, as epoch msstatic lastSundayAt1 = (y, m) => {days = daysFromCivil(y, m, 31)wd = (days + 4) % 7 // 0 = Sunday: 1970-01-01 was a Thursdayreturn (days - wd) * DAY + HOUR}static viennaOffset = (ms) => {y = toNumber(timestamp(ms).slice(0, 4))return ms >= lastSundayAt1(y, 3) && ms < lastSundayAt1(y, 10) ? 2 * HOUR : HOUR}// "YYYY-MM-DD HH:MM", Vienna wall time — what a person readsstatic localStamp = (ms) => {t = timestamp(ms + viennaOffset(ms))return t.slice(0, 10) + ' ' + t.slice(11, 16)}
Branches
Latest commits
- 6a82097fTickets conductor: Arachne W228 on day35 flakemre
- 0ee5a6f2Tickets conductor: T36 resumedmre
- 9149c165Tickets conductor: T36 diagnosismre
- 91713313Tickets conductor: T36 report 1mre
- 756315d2Tickets conductor: T36 startedmre
- 0814ce6bTickets conductor: brief 025 tickets#36 style formmre
- 1b6916c4Tickets conductor: Atlas handover tickets#36mre
- aab95226Tickets conductor: worldapi-conductor paths, deploy blocker = read-only diskmre
- 6372b06dTickets conductor: worker port slotmre
- 836af31cTickets conductor: token pathsmre
- b03f11b6Tickets conductor: CONDUCTOR.md (project part), short STATUS.md, old STATUS to archive/2026-10-31mre
- a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
- cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
- 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
- b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
- f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
- 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
- 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
- d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
- afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre