Repository navigation
Extract shared AbstractPostgresJournalPersistenceAdapter + decodeBytea (TODO A3) - #66
Merged
Merged
Conversation
Mirrors the digest A2 pattern: journal-pg and journal-pglite now share one implementation of insertEntry, updateFullState, readEntry, queryEntries, readFullState, queryFullStates, deleteByChart, getCurrentTime, emitJournalEntryNotification and the row parsers, written once against $N positional SQL in journal-persistence. journal-pg keeps its 4-connection topology; the base routes to it via three role-based hooks (runWriteQuery/runUpdateQuery/runReadQuery) instead of a single query runner. The pg adapter's pg-bind bind(...) calls and escapeLiteral string interpolation are replaced by the parameterized VALUES-list approach already used in journal-pglite, and pg-bind is dropped from journal-pg's dependencies. Adds a shared decodeBytea helper to xjog-util so bytea columns are decoded consistently across both drivers (pg's Buffer and PGlite's Uint8Array), fixing the same String()-coercion drift previously fixed for digests. Also fixes a latent bug where journal-pg's full-state SELECT omitted the ownerId column.
This was referenced Jul 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Second of the three adapter-base extractions (after digest A2 #64). Moves all pure-SQL journal methods into a shared
AbstractPostgresJournalPersistenceAdapterin@telia-oss/xjog-journal-persistence, written once with$Npositional SQL, and adds the shareddecodeByteahelper to@telia-oss/xjog-util.Details
runWriteQuery(insertEntry, updateFullState),runUpdateQuery(emitJournalEntryNotification, deleteByChart),runReadQuery(readEntry, queryEntries, readFullState, queryFullStates, getCurrentTime). journal-pg maps these to its write/update/readClients; journal-pglite maps all three to its single connection. The 4new Client(...)connections, connect/disconnect,pg-listensubscription, and notification→re-query loop are unchanged.$Nnumbering via the sharedcreatePositionalParameters, and parameterizedJOIN (VALUES …)for the (machineId, chartId) array queries. This removes journal-pg'spg-bindbind(...)and itsreadConnection.escapeLiteral(...)string interpolation (SQL-injection-safer).pg-binddropped from journal-pg's deps.decodeBytea(value: Buffer | Uint8Array): string(TextDecoder) in util, used uniformly in the base row parsers. This is the exact drift class Fix correctness bugs and remove dead code across core and adapters #55 fixed —String(uint8array)yields"123,34,…"for PGlite'sUint8Array, whileBuffercoerces fine; the helper handles both.Both fall out of the "canonical = pglite" directive and fix latent pg bugs:
fullJournalStatesreads now include"ownerId". pg's full-state SELECT list was missingownerId(pg wrote it but never read it back, soFullStateEntry.ownerIdwasundefinedfor pg). The base uses pglite's field list, which includes it. pglite behavior unchanged.eventparsing is now null-guarded (row.event ? … : null). pg previously parsedeventunconditionally; the guard is required fordecodeByteaand matches pglite. (For a nullevent, the old pg path already producednullviaJSON.parse(String(null)), so this is equivalent in practice.)Verification
build+testgreen across journal-persistence/pg/pglite/util; the pglite regression suite (repeated-record()append + full-state advance, and the chart-reference array-query) passes unchanged; full-repoturbo run build test= 22/22.lintclean. Changeset:minorfor util + the three journal packages.Implements TODO item A3. (A4 — the core family — is gated on this merging.)