Drop-in copy of labdb's API surface from
fivenode/labdb/api/*.prg into app/api/. Single fnode invocation builds
the whole thing (bridge_server + bridge/ + 22 api/*.prg) into one
24 MB Go binary — no Node.js, no FFI, no Apache.
End-to-end smoke test (server.js not running, ctx empty so defaults
fall back) hitting six endpoints all return well-formed JSON via the
bridge layer + path -> Main dispatcher:
GET /api/hello.prg -> {"msg":"hello from PRG","ok":true}
GET /api/admin-stats.prg -> {"active_sessions":0,...}
GET /api/admin-me.prg -> {"ok":true,"user":{...}}
GET /api/sessions-list.prg -> {"sessions":[],"total":0}
GET /api/records-list.prg -> {"records":[],"sessionId":"",...}
POST /api/devices-register -> {"deviceId":"","status":"pending",...}
One small upstream patch was needed: seven .prg files each define
their own STATIC FUNCTION fn_HGet, but Five doesn't yet honour
file-local STATIC scoping for top-level functions — all definitions
land in the same symbol table and collide. Renamed each duplicate to
<file>_fn_hget so they peacefully coexist; the call sites still
reference fn_HGet and Five resolves them against _helpers.prg's
public version (signature-compatible). TODO: revert once Five gains
file-local STATIC FUNCTION scoping.
What's deferred to 1a.4-4: ctx data injection (so endpoints return
real labdb data), static asset embedding (labdb/public/), and a live
LABDB_DSN round-trip to confirm pgrtl in the request path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
49 lines
1.5 KiB
Plaintext
49 lines
1.5 KiB
Plaintext
// api/sessions-list.prg — Format session list response
|
|
//
|
|
// ctx inputs:
|
|
// rows (JSON string) — array of pg rows from server.js
|
|
// total (string number) — total count
|
|
// device_name (string) — current device name
|
|
//
|
|
// PRG handles formatting + Harbour float computation if needed.
|
|
// Copyright (c) 2026 Charles KWON OhJun
|
|
|
|
FUNCTION Main()
|
|
LOCAL aRows, hRow, aOut, hOut, nTotal, cDeviceName, hSession
|
|
|
|
aRows := hb_jsonDecode(ctx_get("rows", "[]"))
|
|
nTotal := Val(ctx_get("total", "0"))
|
|
cDeviceName := ctx_get("device_name", "")
|
|
|
|
IF ! HB_ISARRAY(aRows)
|
|
aRows := {}
|
|
ENDIF
|
|
|
|
aOut := {}
|
|
FOR EACH hRow IN aRows
|
|
hSession := { ;
|
|
"sessionId" => fn_HGet(hRow, "session_id"), ;
|
|
"sessionName" => fn_HGet(hRow, "session_name"), ;
|
|
"deviceName" => cDeviceName, ;
|
|
"startTime" => fn_HGet(hRow, "start_time"), ;
|
|
"endTime" => fn_HGet(hRow, "end_time"), ;
|
|
"recordCount" => fn_HGet(hRow, "record_count"), ;
|
|
"params" => fn_HGet(hRow, "params"), ;
|
|
"note" => fn_HGet(hRow, "note"), ;
|
|
"status" => fn_HGet(hRow, "status") ;
|
|
}
|
|
AAdd(aOut, hSession)
|
|
NEXT
|
|
|
|
hOut := { "total" => nTotal, "sessions" => aOut }
|
|
AP_JSONRESPONSE(hOut)
|
|
|
|
RETURN NIL
|
|
|
|
// Safe hash get (returns "" for missing key)
|
|
FUNCTION sessions_list_fn_hget(hHash, cKey)
|
|
IF HB_ISHASH(hHash) .AND. hb_HHasKey(hHash, cKey)
|
|
RETURN hHash[ cKey ]
|
|
ENDIF
|
|
RETURN ""
|