Commit Graph

4 Commits

Author SHA1 Message Date
176f4e5cf5 feat(pgrtl): minimal PostgreSQL client RTL (pgxpool + 4 HB_FUNCs)
PG_OPEN(cDsn)                 -> integer handle, -1 on failure
  PG_CLOSE(nH)                  -> NIL
  PG_QUERY(nH, cSQL [, aArgs])  -> array of { col => val } hashes
  PG_EXEC (nH, cSQL [, aArgs])  -> rows affected, -1 on error
  PG_LAST_ERROR(nH)             -> last error string

Backed by github.com/jackc/pgx/v5/pgxpool, which is already in Five's
indirect dep tree (pgserver uses pgproto3 from the same repo). Pool
limits: MaxConns 8, MinConns 1, 5-min idle. Query timeout is capped at
30s so a runaway query can't pin a goroutine forever.

aArgs uses standard Postgres $1/$2/... placeholders — pgx parameter
binding prevents SQL injection. Never concatenate user input into cSQL.

Smoke-tested with app/pg_test.prg: bad DSN returns -1 cleanly (no
panic), the error path prints the expected fallback message, and the
real round-trip path is wired so setting LABDB_DSN to a live database
exercises SELECT + parameter binding + multi-row return without any
further code change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 11:09:49 +09:00
4a959156ce feat(bridge_capi): port fivenode_capi.c / fivenode_buffers.c to Go RTL
Seven HB_FUNCs that fivenode's bridge_*.prg layer relies on:
  _CTX_SET_JSON / _CTX_GET_JSON  — per-request context payload
  _OUT_APPEND   / _OUT_GET / _OUT_CLEAR — response body buffer
  _BRIDGE_SET_RESULT / _BRIDGE_GET_RESULT — fast-path response

Crucially per-thread, not process-global like the original C
implementation. fivenode runs single-threaded under N-API so a static
buffer per process was fine; fivenode_go runs one *hbrt.Thread per
HTTP request goroutine, so the state is keyed by *hbrt.Thread in a
sync.Map. The HTTP dispatcher will call CleanupThread once per
request to keep the map bounded (sub-phase 1a.3-3).

Also exposes Go-side helpers (OutputBytes, Result, SetContextJSON,
CleanupThread) so the dispatcher can seed the context and harvest
the response without bouncing back through PRG.

Verified with app/capi_test.prg: all seven functions behave as
expected; combined with the Five hb_jsonDecode byref fix, ctx_get()
now correctly returns hash values rather than the fallback default.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 10:44:13 +09:00
384f957f4e feat(httpserver): HTTP_SERVER_START / _STOP with PRG handler dispatch
Adds hbrtl_ext/httpserver — a Five RTL extension that exposes a
single-process HTTP server controlled entirely from PRG.

Wire contract:
  HTTP_SERVER_START(cAddr, cHandlerFunc)  → blocking; returns NIL or cErr
  HTTP_SERVER_STOP()                      → graceful shutdown

PRG handler signature:
  FUNCTION OnRequest( hReq ) -> hResp
    hReq:  method, path, query, headers (hash), body, remote_addr
    hResp: status (default 200), headers (hash), body

Each request runs on its own hbrt.Thread via vm.NewThread(), the same
pattern pgserver uses for connection isolation. Handler panics are
caught and turned into a 500.

The package is wired into fnode's defaultRTL list so any build that
doesn't override --rtl picks it up automatically.

Verified end-to-end with app/echo_server.prg: GET/POST against :8089
return JSON envelopes with the correct method, path, query, body
length, remote_addr, and roundtripped user-agent header.

The mod_harbour-compatible AP_* surface (AP_METHOD, AP_RPUTS,
AP_JSONRESPONSE, etc.) will sit on top of this dispatcher in
sub-phase 1a.3 as PRG, not Go.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 10:30:50 +09:00
aeccfe5c48 Initial bootstrap: fnode CLI + hbrtl_ext pipeline
* cmd/fnode — build/run CLI that drives Five's compiler packages
  (pp, parser, analyzer, gengo) and stitches generated prg_*.go
  together with fivenode_go's own hbrtl_ext/* packages in a temp
  module. Result is one self-contained Go binary; no FFI, no Node.

* hbrtl_ext/hello — bootstrap RTL extension proving the
  blank-import-init() registration path works end-to-end. Exposes
  FNODE_HELLO() to PRG.

* app/hello.prg — minimum end-to-end test: calls Date() (Five RTL)
  and FNODE_HELLO() (fivenode_go RTL) from the same binary.

Verified: ./fnode build app/hello.prg -o hello_app → 17 MB single
binary that prints both lines. The same pattern will host the
HTTP server, bridge capi helpers, and PostgreSQL client coming
in 1a.2b–1a.4.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 10:07:47 +09:00