Skip to content

chore: bump node-pg-migrate to ^7.9.1 - #29

Closed
juhovuo wants to merge 103 commits into
samihult:mainfrom
telia-oss:chore/node-pg-migrate-7
Closed

juhovuo wants to merge 103 commits into
samihult:mainfrom
telia-oss:chore/node-pg-migrate-7

Conversation

@juhovuo

@juhovuo juhovuo commented Sep 15, 2026

Copy link
Copy Markdown

node-pg-migrate@6.x is deprecated on npm and shows up as a warning in every consumer install. 7.9.1 is the last major that ships CJS and keeps the default-export runner and the dbClient/checkOrder/noLock/singleTransaction options we use, so this is a version-only change.

8+ is ESM-only with the default export removed; not worth it while these packages compile to CommonJS.

Verified: build, lint, unit tests, and the three -pg smoke suites against a local Postgres 16.

Juha Mustonen and others added 30 commits July 22, 2025 12:49
Add support for PGLite to support testing and development
Simulate event sending failures or other non-normal situations. See XJogSimulator file for details and usage.
 - @samihult/xjog@0.0.317
 - @samihult/xjog-core-persistence@0.0.39
 - @samihult/xjog-core-pg@0.0.63
 - @samihult/xjog-core-pglite@0.1.1
 - @samihult/xjog-digest-persistence@0.0.25
 - @samihult/xjog-digest-pg@0.0.118
 - @samihult/xjog-digest-reader@0.0.30
 - @samihult/xjog-digest-writer@0.0.17
 - @samihult/xjog-journal-persistence@0.0.53
 - @samihult/xjog-journal-pg@0.0.117
 - @samihult/xjog-journal-reader@0.0.55
 - @samihult/xjog-journal-writer@0.0.71
 - @samihult/xjog-util@0.0.34
Also change the parameter from eventName to event
 - @samihult/xjog@0.0.318
 - @samihult/xjog-journal-reader@0.0.56
 - @samihult/xjog-journal-writer@0.0.72
Add support for simulator wildcards
 - @samihult/xjog@0.0.319
 - @samihult/xjog-core-persistence@0.0.40
 - @samihult/xjog-core-pg@0.0.64
 - @samihult/xjog-core-pglite@0.1.2
 - @samihult/xjog-digest-persistence@0.0.26
 - @samihult/xjog-digest-pg@0.0.119
 - @samihult/xjog-digest-reader@0.0.31
 - @samihult/xjog-digest-writer@0.0.18
 - @samihult/xjog-journal-persistence@0.0.54
 - @samihult/xjog-journal-pg@0.0.118
 - @samihult/xjog-journal-reader@0.0.57
 - @samihult/xjog-journal-writer@0.0.73
 - @samihult/xjog-util@0.0.35
Change simulator percentage from number to string
 - @samihult/xjog@0.0.320
 - @samihult/xjog-core-persistence@0.0.41
 - @samihult/xjog-core-pg@0.0.65
 - @samihult/xjog-core-pglite@0.1.3
 - @samihult/xjog-digest-persistence@0.0.27
 - @samihult/xjog-digest-pg@0.0.120
 - @samihult/xjog-digest-reader@0.0.32
 - @samihult/xjog-digest-writer@0.0.19
 - @samihult/xjog-journal-persistence@0.0.55
 - @samihult/xjog-journal-pg@0.0.119
 - @samihult/xjog-journal-reader@0.0.58
 - @samihult/xjog-journal-writer@0.0.74
 - @samihult/xjog-util@0.0.36
Move and copy migrations into package
This reverts commit 05d2b56.
Add PGlite support for digest and journal adapters
Re-enabling XJogDeferredManager testing and fixing PGlite support
Warn about the simulation in action
juhovuo added 28 commits July 4, 2026 18:05
Hard-fork ownership: rename all 15 packages, workspace deps, and imports to the
@telia-oss scope; minor bump to 0.2.0 via changeset. Delete 12 fossil per-package
.npmrc files (routed @samihult to GitHub Packages, overriding root config); add
@telia-oss:registry to the root .npmrc. Update metadata and docs. No runtime
logic changes.

BREAKING CHANGE: import paths change from @samihult/xjog-* to @telia-oss/xjog-*.
* Rewrite README: drop xjog.io banner, reflect @telia-oss packages and current features

* Refresh development.md; graduate docs from alpha to beta (0.2.0)
* Fix correctness bugs and remove dead code across core and adapters

Core:
- destroy() releases the chart mutex and completes persistence cleanup
  even when an update hook throws; hooks that throw synchronously are
  logged like rejected ones in create/send/destroy
- Await final-state done data before notifying the parent chart (the
  parent previously received a Promise object as event data)
- Await persistence call in dropExternalId (floating promise)
- Fix always-true typeof misuse in sendTo activity existence check
- Chart cache evicts down to the size limit and releases the cache
  mutex on error paths
- Activity manager releases its DB mutex when persistence calls throw
- Forced chart adoption survives transient DB errors instead of
  causing an unhandled rejection
- Parallelize independent after-action presence checks

Persistence adapters:
- core-pg/core-pglite: drop non-transactional destroyChart overrides
  (which also had a missing await) in favour of the transactional base
- journal-pglite: remove broken record() override (no journal entries
  written, failed on second call per chart); rebuild queryEntries/
  queryFullStates parameter binding, replacing hand-escaped literals
  with parameterized VALUES lists; decode bytea rows as UTF-8; log
  notification handler failures instead of crashing; fix pg_notify cast
- journal-persistence: rethrow the caught error in record(), not the
  logging closure
- digest-pg: fix malformed quoted identifier in the digest SELECT list
- digest-pg/digest-pglite: key readByChart results by digest key, fix
  copy-pasted 'updated after' binding key
- digest-pglite: implement filter expression bindings in queryDigests
  and fix positional parameter desync

Writers and util:
- journal-writer/digest-writer: expose uninstall() for the update hook
- util: isActivityRef(null/undefined) returns false instead of
  throwing; delete unused and broken BurstController
- Document the actual (best-effort) update hook semantics

Includes regression tests for the journal record path, digest query
binding and readByChart keying, destroy-with-failing-hook, done-data
resolution, and isActivityRef guards.

* Address review: deepen fixes and add regression tests

Follow-up to the correctness batch, resolving PR review findings:

- digest-pg, digest-pglite: stop embedding the raw digest key in filter
  binding names; keys with hyphens/dots/digits truncated the :name token and
  mis-bound the query. The recursion prefix already makes names unique.
- core-persistence: forciblyAdoptCharts claims/clears each chart resiliently
  so a transient error on one chart cannot strand already-claimed charts.
- core (XJogChart.send): a throwing final-state data mapper is now a logged
  best-effort skip instead of rejecting an already-committed transition.
- journal-pg: log notification-handler failures instead of crashing on an
  unhandled rejection (matching journal-pglite).
- core (XJogMachine.cleanCache): evict only idle charts, avoiding the
  self-eviction deadlock and head-of-line blocking under the cache mutex.
- core: extract XJog.runUpdateHooks; util: add createPositionalParameters,
  a shared positional-placeholder binder for the PGlite query builders.
- Regression tests: digest non-word-char key filter and "updated after"
  filter; send() not rejecting when the final-state data mapper throws.
…#56)

The static filterQuery(expression, prefix) builder was duplicated
verbatim in PostgresDigestPersistenceAdapter and
PGliteDigestPersistenceAdapter, differing only in a comment and the
class name used for recursive calls. Extract it as a standalone
function in digest-persistence and have both adapters call the shared
implementation.
Move the execution-duration histogram machinery out of XJog into a
composed XJogProfiler, and add profiling.enabled (default true) so
timeExecution can short-circuit to a plain call/await, skipping
performance.now() and the log-bucket math, when profiling is disabled.
Public timeExecution/getProfilingMetrics signatures are unchanged.
packages/core-sqlite only contained package._json (never a valid
package.json), so it was never wired into the workspace or published.
Delete the directory and scrub the AGENTS.md architecture/dependency-flow
references to core-sqlite.
Local variables named PersistedDeferredEvent shadowed the imported
type of the same name. Renamed the value bindings to deferredEvent
across defer, scheduleUpcoming, cancelAllForChart, unschedule, and
cancel. Pure rename, no behavior change.
chartCacheStore (plain object) and chartCacheKeys (Set for insertion
order) represented one concept split across two coordinated fields.
Replace both with a single Map<string, XJogChart>, which natively
preserves insertion order and needs no separate key-ordering
structure. Eviction remains oldest-first via Map.keys() iteration
order, and the try/finally mutex structure is unchanged.
Buffer notifications from newDigestEntriesSubject for a configurable
window (default 50ms, via new notificationDebounceMs option) before
re-querying, deduplicating by chart so bursts of notifications for the
same chart collapse into a single queryDigests call instead of one per
notification. Distinct charts within a burst are still each re-queried
once. The initial queryDigests call on subscribe is unaffected.

Adds jest test infra to the package (mirroring core's jestconfig.js
setup) to cover the immediate-first-emission and coalescing behavior
with fake timers.
Drop the unused TContext/TEvent generic type parameters (they never
appeared in the signature or body, and had no callers to bind them).
Reuse a single working copy across the state/context diff fold instead
of deep-cloning on every journal entry via nullSafeApplyJsonDiff,
falling back to a defensive clone only when a value is aliased to data
we don't own (e.g. a patch's root-replace value) or on the final fold
step (so the returned state/previousState never end up sharing a
reference). Replace truthiness checks on previousState/previousContext
with explicit !== null checks so falsy-but-valid values are handled
correctly.

Adds jest+@swc test coverage for the package (previously untested),
including a differential fuzz test comparing the optimized fold
against a reference clone-per-step implementation across randomized
chains.
Extracts each switch branch (Send, Cancel, Start, Stop, Log) of
executeAction into its own private method, taking the same locals
as explicit parameters instead of closing over them. The dispatch
switch is now a thin call-through with identical await/break order.

Also removes dead commented-out code flagged in the correctness
audit: the unreachable sendTo branch in the Send case, the unused
receivers set in spawnCallback, the observer/sendEvent placeholders
in spawnUnregisteredMachine, and the isSpawnedActor/isBehavior stubs
in spawn().

No behavior change.
digest-pg and digest-pglite duplicated ~85-90% identical SQL for the
digest persistence methods. Move the pure-SQL logic (upsert, delete,
read, query, notify) into a single AbstractPostgresDigestPersistenceAdapter
in digest-persistence, written once against $N positional placeholders
over a minimal PostgresQueryRunner driver shim. Each adapter now only
supplies connect/disconnect/listen plumbing and a runQuery hook that
adapts its driver's query() result shape.

digest-pg no longer needs pg-bind now that its SQL is positional, so
the dependency and its type shim are removed.
…art.send (#65)

Splits the top-of-send simulator short-circuit and the bottom done-state
notification / auto-forward calls into private helpers
(interceptWithSimulator, notifyOwnerIfDone, autoForwardToChildren). No
behavior change; the mutex/transition core in the middle of send() is
untouched.
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.
Same pattern as the digest/journal extractions: the ~40 pure-SQL core
persistence methods (instances, charts, ongoing activities, deferred
events, external ids) are written once against $N positional
placeholders in an abstract base that stays generic over ConnectionType,
so core-pg and core-pglite keep their own connection type and
withTransaction signature unchanged. Each driver now only implements
runQuery plus its connection/transaction/death-note-polling layer.

State bytea decoding is unified via decodeBytea in the base instead of
being duplicated per driver. Removes pg-bind from core-pg now that all
queries use positional parameters.
…68)

15 of the 18 XJogStateChange*Action variants were empty '// TODO ?' stubs
whose only field was 'type', and mapActions never populated anything else
for them. Collapse them into a single XJogStateChangePlainAction with a
narrowed XJogStateChangePlainActionType union; the serialized shape of
journaled actions is unchanged.

Also make XJogActionTypes a real enum (it was 'declare enum', so
XJogActionTypes.Unknown did not exist at runtime), use it in mapActions
instead of a hardcoded 'xjog.unknown' literal, drop the blanket
@ts-expect-error now that the mapping type-checks, and add unit tests
covering every branch of mapActions.

Resolves TODO item C6.
* Add real-Postgres driver smoke tests for core-pg, journal-pg, digest-pg

PGlite covers all SQL for the core/journal/digest Postgres adapters, but
none of the three -pg packages had any test exercising the actual
node-postgres driver: real connection pooling, node-pg-migrate migrations
against a live server, transaction commit/rollback, and LISTEN/NOTIFY.

Add one *.smoke.test.ts per package, wired the same way as the -pglite
packages (jest.config.js + test script). Each suite creates its own
throwaway database in beforeAll and drops it in afterAll so the three
suites' node-pg-migrate migration-tracking tables never collide, and skips
entirely (describe.skip) when PG_TEST_URL/DATABASE_URL isn't set so local
`pnpm test` and the existing CI `check` job stay dependency-free.

Add a `pg-smoke` job to check-pr.yml that runs only these three suites
against a postgres:16-alpine service container.

Fixes found by actually running against real Postgres:
- pg's Pool/Client give `connectionString` priority over a co-supplied
  `database` field, so the per-suite database override was silently
  ignored; the test helper now parses the connection string into discrete
  fields instead.
- turbo's default strict env mode stripped PG_TEST_URL/DATABASE_URL from
  the test task; declared them in turbo.json.
- PostgresDigestPersistenceAdapter.connect() never released the pool
  client it opened to warm the connection, which made pool.end() (and
  therefore disconnect()) hang forever for any real caller.

* Add changeset for the digest-pg connect() pool-client release fix
…on (#70)

* fix(journal-pg): serialize notification reads on shared read connection

The journal-entry notification handler fired queryEntries and queryFullStates
in parallel, but both route through runReadQuery on the single shared read
connection. A pg.Client can only run one query at a time, so overlapping them
triggered pg's "client is already executing a query" deprecation warning
(a hard throw in pg@9). Await the two reads sequentially instead.

* Bump @telia-oss/xjog-journal-pg to 0.3.1
* fix(util): decode bytea columns that are still TEXT

Databases provisioned before the chart and journal payload columns were
declared BYTEA still hold them as TEXT. Their initial migration is already
recorded as applied, so no later migration converts the columns, and pg
returns those rows as strings.

TextDecoder rejects a string with ERR_INVALID_ARG_TYPE, so extracting the
shared AbstractPostgresPersistenceAdapter — which replaced row.state.toString()
with decodeBytea(row.state) — turned every chart read against such a database
into a failed event send. The old toString() call sites tolerated both shapes.

Pass strings through unchanged and keep decoding Buffer and Uint8Array as
UTF-8. A null value still throws.

The util package had no test script, so its two existing test files never ran;
add the jest config and script alongside the regression test.

* Update packages
6.x is deprecated on npm. 7.x keeps the CJS default export and runner options; 8+ is ESM-only.
@juhovuo juhovuo closed this Sep 15, 2026
@juhovuo
juhovuo deleted the chore/node-pg-migrate-7 branch September 15, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants