nx_wiki_page_save.nx
buildroot/runtime/wiki/nx_wiki_page_save.nx
about
nx_wiki_page_save.nx -- wiki R1: the AUTH-GATED page EDIT + SAVE backbone.
Adds the ability to EDIT a wiki page and SAVE it, persisted to the sovereign
append-only seg_store, so the new content renders + is searchable, and every
save is an IMMUTABLE revision (this is R2 versioning's history substrate).
SECURITY-CRITICAL: a save is permitted ONLY when the caller presents a VALID
session token. The auth gate REUSES the proven validator already shipping in
the wiki -- hub/nx_modern_auth_flow::nx_modern_auth_validate_session (the
exact OPAQUE/no-cookie Ed25519 session check nx_wiki_admin_handle uses on
every protected request). NO new/weaker auth is invented here. An
unauthenticated edit is REFUSED and persists NOTHING.
COMPOSES (avoid-duplicate-primitives cardinal; each imported ONCE):
hub/nx_modern_auth_flow nx_modern_auth_validate_session (the auth gate)
wiki/nx_wiki_index_builder NxWikiDocStore (+ find_by_url, lookup, add,
the new update_body_by_url) -- in-memory store
the read/render/search paths already consult
nx_seg_store ss_begin / ss_add / ss_commit (persist) +
ss_open / ss_hget (read overlay back)
COMPOSED BY:
wiki/nx_wiki_edit_handler GET/POST /wiki/<slug>/edit HTTP handlers
wiki/nx_wiki_main startup overlay loader (seg_store > .md)
runtime/_hdl_build/_wiki_edit_gate unit gate (authed save, unauth refuse,
readback, revision)
PERSISTENCE MODEL (additive-data law, cardinal 13):
prefix "knowledge/store/wikipage-"
key wikicur:<slug> value = current markdown bytes
key wikirev:<slug>:<epoch> value = "author=<a>\nepoch=<e>\n" + content
Every save = a NEW segment (ss_commit). Old segments are never mutated or
deleted; wikicur:<slug>'s LATEST put wins on read (ss_hget), the wikirev:*
rows accumulate as the immutable revision log R2 walks.
Status: R1. 2026-06-14. license_tier: ORIGINAL
dependencies 4 imports · 3 importers
imports: nx_syscalls.nxnx_modern_auth_flow.nxnx_wiki_index_builder.nxnx_seg_store.nx
imported by: nx_wiki_edit_handler.nxnx_wiki_main.nxnx_wiki_version.nx
structs
| none |
consts
| 44 | const NX_WPS_OK: i64 = 0 |
| 45 | const NX_WPS_REFUSED: i64 = 2900 // auth gate refused (no/invalid token) |
| 46 | const NX_WPS_BAD_INPUT: i64 = 2901 |
| 47 | const NX_WPS_PERSIST_FAILED: i64 = 2902 |
| 48 | const NX_WPS_STORE_FAILED: i64 = 2903 // in-memory doc-store update failed |
| 49 | const NX_WPS_OVERFLOW: i64 = 2904 |
| 52 | const NX_WPS_PREFIX: *u8 = "knowledge/store/wikipage-" as *u8 |
| 53 | const NX_WPS_MAX_SLUG_LEN: i64 = 200 |
| 54 | const NX_WPS_MAX_CONTENT_LEN: i64 = 262144 // 256 KB per page edit |
| 55 | const NX_WPS_DEFAULT_AUTHOR: *u8 = "elderwesto" as *u8 |
| 56 | const NX_WPS_DEFAULT_AUTHOR_N: i64 = 10 |
| 57 | const NX_WPS_KEY_CAP: i64 = 320 // "wikirev:" + slug + ":" + epoch |
| 58 | const NX_WPS_URL_CAP: i64 = 256 // "/wiki/" + slug |
functions
| 61 | func nx_wps_prefix() -> *u8 { return NX_WPS_PREFIX } |
| 66 | func _wps_cat(dst: *u8, off: i64, src: *u8) -> i64 { |
| 73 | func _wps_catb(dst: *u8, off: i64, src: *u8, n: i64) -> i64 { |
| 80 | func _wps_catn(dst: *u8, off: i64, v: i64) -> i64 { |
| 94 | func nx_wps_cur_key(slug: *u8, slug_n: i64, out: *u8) -> i64 {
called by 3: nx_wiki_page_savenx_wiki_page_load_currentnx_wiki_page_overlay_store calls 2: _wps_cat_wps_catb |
| 103 | func nx_wps_rev_key(slug: *u8, slug_n: i64, epoch: i64, out: *u8) -> i64 { |
| 115 | func nx_wps_url(slug: *u8, slug_n: i64, out: *u8) -> i64 { |
| 126 | func nx_wps_next_segid(prefix: *u8) -> i64 { |
| 143 | func nx_wps_doc_store_put(store: *NxWikiDocStore, |
| 204 | func nx_wiki_page_save( |
| 274 | func nx_wiki_page_load_current(slug: *u8, slug_n: i64, |
| 305 | func nx_wiki_page_overlay_store(store: *NxWikiDocStore) -> i64 { |