code wiki / wiki / nx_wiki_page_save.nx

nx_wiki_page_save.nx

buildroot/runtime/wiki/nx_wiki_page_save.nx

15931 B345 linesdepth 15pulls 46 transitivereach 9 importersview sourcekind librarytopic wiki
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_modern_auth_flow.nx nx_wiki_index_builder.nx nx_seg_store.nx nx_wiki_page_save.nx nx_wiki_edit_handler.nx nx_wiki_main.nx nx_wiki_version.nx

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

44const NX_WPS_OK: i64 = 0
45const NX_WPS_REFUSED: i64 = 2900 // auth gate refused (no/invalid token)
46const NX_WPS_BAD_INPUT: i64 = 2901
47const NX_WPS_PERSIST_FAILED: i64 = 2902
48const NX_WPS_STORE_FAILED: i64 = 2903 // in-memory doc-store update failed
49const NX_WPS_OVERFLOW: i64 = 2904
52const NX_WPS_PREFIX: *u8 = "knowledge/store/wikipage-" as *u8
53const NX_WPS_MAX_SLUG_LEN: i64 = 200
54const NX_WPS_MAX_CONTENT_LEN: i64 = 262144 // 256 KB per page edit
55const NX_WPS_DEFAULT_AUTHOR: *u8 = "elderwesto" as *u8
56const NX_WPS_DEFAULT_AUTHOR_N: i64 = 10
57const NX_WPS_KEY_CAP: i64 = 320 // "wikirev:" + slug + ":" + epoch
58const NX_WPS_URL_CAP: i64 = 256 // "/wiki/" + slug

functions

61func nx_wps_prefix() -> *u8 { return NX_WPS_PREFIX }
66func _wps_cat(dst: *u8, off: i64, src: *u8) -> i64 {
73func _wps_catb(dst: *u8, off: i64, src: *u8, n: i64) -> i64 {
80func _wps_catn(dst: *u8, off: i64, v: i64) -> i64 {
94func nx_wps_cur_key(slug: *u8, slug_n: i64, out: *u8) -> i64 {
103func nx_wps_rev_key(slug: *u8, slug_n: i64, epoch: i64, out: *u8) -> i64 {
115func nx_wps_url(slug: *u8, slug_n: i64, out: *u8) -> i64 {
126func nx_wps_next_segid(prefix: *u8) -> i64 {
called by 1: nx_wiki_page_save calls 1: ss_next_segid
143func nx_wps_doc_store_put(store: *NxWikiDocStore,
204func nx_wiki_page_save(
274func nx_wiki_page_load_current(slug: *u8, slug_n: i64,
305func nx_wiki_page_overlay_store(store: *NxWikiDocStore) -> i64 {