@eventferry/postgres 3.3.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/package.json +5 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,261 @@
1
+ # @eventferry/postgres
2
+
3
+ ## 3.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 3c33f71: **chore: ship `CHANGELOG.md` inside the npm tarball**
8
+
9
+ Previously, each package's `files` allowlist contained only `"dist"` (and `"sql"` for `@eventferry/postgres`), so the auto-generated `CHANGELOG.md` was never published. Users browsing the package on npmjs.com or unpacking the tarball couldn't see release notes — they had to navigate to the GitHub repo.
10
+
11
+ This release adds `"CHANGELOG.md"` to the `files` array of every publishable package. Starting with this version, the per-version release notes are accessible:
12
+
13
+ - Directly in `node_modules/@eventferry/<pkg>/CHANGELOG.md` after `npm install`
14
+ - In the file listing on npmjs.com (under the "Code" / "Files" tab, depending on the npm UI)
15
+ - Inside the tarball downloaded from `https://registry.npmjs.org/...`
16
+
17
+ No code or API surface changes.
18
+
19
+ - Updated dependencies [3c33f71]
20
+ - @eventferry/core@3.3.1
21
+
22
+ ## 3.3.0
23
+
24
+ ### Minor Changes
25
+
26
+ - cdc20cf: **feat: DLQ enrichment + backpressure runtime + quota multiplier — Tier 1 of the reliability gap closed**
27
+
28
+ ### DLQ enrichment
29
+
30
+ Records routed to the dead-letter queue now carry the full context an operator needs to triage:
31
+
32
+ | Header | Set by | Note |
33
+ | --------------------------- | --------- | ------------------------------------------------------------------------------------------------ |
34
+ | `original-topic` | relay | already existed |
35
+ | `dlq-reason` | publisher | already existed (`error.message`) |
36
+ | `dlq-failed-at` | publisher | already existed (ISO timestamp) |
37
+ | `dlq-error-class` | publisher | **new** — `error.name` / constructor name |
38
+ | `dlq-attempts` | relay | **new** — string-encoded `attempts` count |
39
+ | `dlq-original-aggregate-id` | relay | **new** — for joining with business state |
40
+ | `dlq-original-message-id` | relay | **new** — for dedup / idempotency lookups |
41
+ | `dlq-error-stack` | relay | **new** — opt-in via `DlqConfig.includeStackTraces`, truncated to `maxStackBytes` (default 4 KB) |
42
+
43
+ ```ts
44
+ new Relay({
45
+ store,
46
+ publisher,
47
+ dlq: { topic: "orders.dlq", includeStackTraces: true, maxStackBytes: 4096 },
48
+ });
49
+ ```
50
+
51
+ ### Backpressure runtime behavior
52
+
53
+ When the driver classifies a failure as `errorKind: "backpressure"` (client-side producer queue full), the relay no longer treats it like a regular retriable failure. Instead:
54
+
55
+ - The record is re-queued via the new `OutboxStore.requeue(id, retryAt)` method,
56
+ - `attempts` is **not incremented** — the buffer being full is a "slow down" signal, not the record's fault,
57
+ - The retry is scheduled `RetryConfig.backpressureDelayMs` ms ahead (default 1000 ms).
58
+
59
+ Stores that don't implement `requeue` fall back to `markFailed` (with attempts++); both `@eventferry/postgres` and `@eventferry/mysql` ship a real implementation.
60
+
61
+ ### Quota multiplier
62
+
63
+ When the driver classifies a failure as `errorKind: "quota"` (broker `THROTTLING_QUOTA_EXCEEDED`), the scheduled retry delay is multiplied by `RetryConfig.quotaMultiplier` (default 5) so the producer gives the broker breathing room. Quota failures DO count as attempts — after the budget is exhausted the record routes to DLQ + `dead`.
64
+
65
+ ### New / changed types
66
+
67
+ - `RetryConfig` gains `backpressureDelayMs?` and `quotaMultiplier?`.
68
+ - `DlqConfig` gains `includeStackTraces?` and `maxStackBytes?`.
69
+ - `OutboxStore.requeue?(recordId, retryAt)` is a new **optional** method. Stores without it fall through to `markFailed`.
70
+
71
+ ### Backward compatibility
72
+
73
+ Pure-additive everywhere. Default behavior matches the prior release:
74
+
75
+ - A `RetryConfig` without `backpressureDelayMs` uses 1000 ms (sensible default).
76
+ - A `DlqConfig` without `includeStackTraces` keeps DLQ messages small (default off).
77
+ - An `OutboxStore` without `requeue` falls back to `markFailed` — same as before, just with a documented quirk.
78
+
79
+ This closes the last three Tier 1 items in `docs/kafka-gap-analysis/reliability.md`. Phase A reliability surface is now ~100% complete.
80
+
81
+ ### Patch Changes
82
+
83
+ - Updated dependencies [cdc20cf]
84
+ - @eventferry/core@3.3.0
85
+
86
+ ## 3.2.1
87
+
88
+ ### Patch Changes
89
+
90
+ - 9beb3e2: **chore: migrate to independent versioning (Astro pattern)**
91
+
92
+ Fixes the major-version inflation that produced four consecutive surprise majors (`1.0.4 → 2.0.0`, `2.0.0 → 3.0.0`, `3.0.0 → 4.0.0 corrected to 3.1.0`, `3.1.0 → 4.0.0 corrected to 3.2.0`) from changesets whose frontmatter only asked for `minor`.
93
+
94
+ **Root cause** (cited in [changesets/changesets#1759](https://github.com/changesets/changesets/issues/1759) and [docs/decisions.md](https://github.com/changesets/changesets/blob/main/docs/decisions.md)): the adapters listed `@eventferry/core` as a `peerDependency` with `workspace:*`. Changesets' documented rule is that an internal bump of a peer forces a major bump on the dependent — and the `fixed: [["@eventferry/*"]]` group reconciler then propagated that major across every package in the group.
95
+
96
+ **Fix** (exactly the [Astro config](https://github.com/withastro/astro/blob/main/.changeset/config.json)):
97
+
98
+ 1. `.changeset/config.json` — drop `fixed`, set `linked: []`, enable
99
+ `___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH.onlyUpdatePeerDependentsWhenOutOfRange: true`.
100
+ 2. Move `@eventferry/core` from `peerDependencies` to `dependencies` in
101
+ `@eventferry/postgres`, `@eventferry/mysql`, `@eventferry/kafka`, and
102
+ `@eventferry/schema-registry`. External user-facing peers (`pg`,
103
+ `mysql2`, `kafkajs`, `@confluentinc/kafka-javascript`,
104
+ `@kafkajs/confluent-schema-registry`) stay unchanged.
105
+
106
+ **Effect on releases.** Packages now evolve at independent semver tempos: a `core: minor` changeset produces `core@3.3.0` alongside `postgres@3.2.1` (patch, from "Updated dependencies"). No more major surprises. No more manual force-push corrections.
107
+
108
+ **Effect on consumers.** Pure-additive at the install boundary: `npm i @eventferry/kafka` now resolves `@eventferry/core` automatically (it's a regular dep). Previously consumers had to install it themselves as a peer; the typical flow already did this. No source-code changes required.
109
+
110
+ - Updated dependencies [9beb3e2]
111
+ - @eventferry/core@3.2.1
112
+
113
+ ## 3.2.0
114
+
115
+ ### Patch Changes
116
+
117
+ - @eventferry/core@3.2.0
118
+
119
+ ## 3.1.0
120
+
121
+ ### Patch Changes
122
+
123
+ - Updated dependencies [da39b08]
124
+ - @eventferry/core@3.1.0
125
+
126
+ ## 3.0.0
127
+
128
+ ### Patch Changes
129
+
130
+ - Updated dependencies [f0c7483]
131
+ - @eventferry/core@3.0.0
132
+
133
+ ## 2.0.0
134
+
135
+ ### Patch Changes
136
+
137
+ - @eventferry/core@2.0.0
138
+
139
+ ## 1.0.4
140
+
141
+ ### Patch Changes
142
+
143
+ - Updated dependencies [64d115d]
144
+ - @eventferry/core@1.0.4
145
+
146
+ ## 1.0.3
147
+
148
+ ### Patch Changes
149
+
150
+ - Updated dependencies [aaca9a2]
151
+ - @eventferry/core@1.0.3
152
+
153
+ ## 1.0.2
154
+
155
+ ### Patch Changes
156
+
157
+ - 89f1867: Declare `engines.node` (>=18) so npm shows the supported Node version and tooling can warn on unsupported runtimes.
158
+ - Updated dependencies [89f1867]
159
+ - @eventferry/core@1.0.2
160
+
161
+ ## 1.0.1
162
+
163
+ ### Patch Changes
164
+
165
+ - docs: polish per-package READMEs (npm page content). No code changes.
166
+ - Updated dependencies
167
+ - @eventferry/core@1.0.1
168
+
169
+ ## 1.0.0
170
+
171
+ ### Minor Changes
172
+
173
+ - b06f8ec: Add a low-latency notify-driven relay (Postgres `LISTEN`/`NOTIFY`).
174
+
175
+ - **core:** new `Waker` interface and an optional `Relay({ waker })`. The relay's
176
+ idle wait is now interruptible — when the waker signals, it claims immediately
177
+ instead of sleeping out `pollIntervalMs`. With no waker, behavior is unchanged.
178
+ - **postgres:** `PostgresNotifyWaker` holds a dedicated `LISTEN` connection and
179
+ wakes the relay on each notification, reconnecting with backoff if it drops.
180
+ `createNotifyTriggerSql(table, channel)` emits an `AFTER INSERT FOR EACH STATEMENT`
181
+ trigger that `pg_notify`s on commit (empty payload — the relay re-claims).
182
+ - Polling remains the safety net: a missed notification is caught by the next poll,
183
+ so no event is lost. All ordering/retry/DLQ/crash-recovery guarantees are unchanged.
184
+ - No new dependencies (`LISTEN`/`NOTIFY` is native to `pg`).
185
+
186
+ - b06f8ec: Add a retention helper: `PostgresStore.purgeDone({ olderThanMs, batchSize?, maxRows? })`.
187
+
188
+ Batch-deletes `done` rows whose `processed_at` is older than the cutoff and returns the
189
+ total removed, keeping the outbox table from growing unbounded. Run it periodically
190
+ (your own scheduler). Only `done` rows are purged.
191
+
192
+ Also adds `createRetentionIndexSql(table)` — an optional partial index over done rows
193
+ (`WHERE status = 2`) that speeds up the purge scan on high-volume tables; the default
194
+ indexes intentionally exclude done rows, so add this only if retention scans get slow.
195
+
196
+ - b06f8ec: Add a streaming relay that publishes straight from the Postgres WAL (logical replication).
197
+
198
+ - **postgres:** `PostgresStreamingRelay` consumes INSERTs on the outbox table via
199
+ `pg-logical-replication` + `pgoutput` (built-in, no DB extension) and publishes them
200
+ with no claim query on the happy path — lower DB load than the notify waker. A failed
201
+ publish is demoted to `failed`; an internal claim-based retry loop drains it with the
202
+ existing backoff / DLQ / dead handling. `pg-logical-replication` is a new **optional**
203
+ peer dependency, loaded only in streaming mode.
204
+ - **postgres:** `PostgresStore` gains `claimFailedOnly` (claims only `failed`/timed-out
205
+ `processing` rows, never `pending`) so the stream owns pending rows with no duplication.
206
+ `createPublicationSql(table, publication)` emits an idempotent insert-only publication.
207
+ - **core:** the record→message builder is extracted as `buildPublishable(record,
208
+ serializer)` and shared by `Relay` and the streaming relay (no behavior change).
209
+ - **At-least-once:** the slot's LSN is acknowledged only after a batch's side effects
210
+ commit; a crash re-streams and re-publishes (idempotent consumers absorb the duplicate).
211
+ - **Ordering:** streaming is best-effort per-aggregate (a retried failure may land after
212
+ later same-aggregate rows). Use the polling relay for the strict head-of-aggregate
213
+ guarantee. Requires `wal_level = logical`.
214
+
215
+ - b06f8ec: Strict per-aggregate ordering, crash recovery, and driver/packaging fixes.
216
+
217
+ - **postgres:** the claim query now enforces strict per-aggregate ordering by
218
+ only taking the _head_ of each aggregate (no earlier unfinished row for the
219
+ same `aggregateId`). At most one in-flight message per aggregate; failed
220
+ messages block their successors until resolved.
221
+ - **postgres:** added a `claimed_at` column and a visibility-timeout reaper
222
+ (`claimTimeoutMs`, default 60s) so rows orphaned by a crashed relay are
223
+ reclaimed instead of stuck in `processing` forever. Migration is upgrade-safe
224
+ (`ADD COLUMN IF NOT EXISTS`); the partial indexes were retuned for the new
225
+ ordered, reaper-aware claim.
226
+ - **core:** dead-lettered messages now carry the real `original-topic` header
227
+ (previously always empty); `ConsoleLogger` routes warn/error to the matching
228
+ `console` methods.
229
+ - **kafka:** the confluent driver now honors `acks` and `compression` (it
230
+ silently ignored them before), matching the kafkajs driver.
231
+ - **packaging:** the `@eventferry/postgres/migrations` subpath export now
232
+ advertises its types; `pnpm-workspace.yaml` dropped an invalid placeholder
233
+ block.
234
+
235
+ Note: `claimTimeoutMs` should exceed your worst-case publish latency. This is
236
+ an at-least-once system — pair it with idempotent producers/consumers.
237
+
238
+ - b06f8ec: Add W3C trace propagation (OpenTelemetry-compatible), dependency-free.
239
+
240
+ - **core:** new `Tracing` interface (`inject(carrier)`), the shape of an OpenTelemetry
241
+ `TextMapPropagator` — the library depends on no tracing package.
242
+ - **postgres:** `PostgresStore({ tracing })` captures the active W3C
243
+ `traceparent`/`tracestate` into the row's headers at `enqueue`, so it rides along to
244
+ the published message (on every path — polling, notify, streaming — since headers
245
+ already pass through) and the consumer can continue the trace.
246
+ - The caller's `headers` object is never mutated. With no `tracing` configured,
247
+ behavior is unchanged. The existing `trace-id` header stays for simple correlation.
248
+ - OpenTelemetry/Datadog/custom integrate via a ~5-line adapter (documented, not bundled).
249
+
250
+ ### Patch Changes
251
+
252
+ - b06f8ec: The streaming relay now creates its persistent logical replication slot on start if
253
+ it does not already exist (via `pg_create_logical_replication_slot`). Previously it
254
+ assumed the slot was pre-created and `subscribe` would fail otherwise. (Caught by the
255
+ new integration suite against real Postgres.)
256
+ - Updated dependencies [b06f8ec]
257
+ - Updated dependencies [b06f8ec]
258
+ - Updated dependencies [b06f8ec]
259
+ - Updated dependencies [b06f8ec]
260
+ - Updated dependencies [b06f8ec]
261
+ - @eventferry/core@1.0.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventferry/postgres",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "PostgreSQL store for @eventferry (polling + lock-free claim)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -20,7 +20,8 @@
20
20
  },
21
21
  "files": [
22
22
  "dist",
23
- "sql"
23
+ "sql",
24
+ "CHANGELOG.md"
24
25
  ],
25
26
  "keywords": [
26
27
  "outbox",
@@ -53,7 +54,7 @@
53
54
  "node": ">=18"
54
55
  },
55
56
  "dependencies": {
56
- "@eventferry/core": "3.3.0"
57
+ "@eventferry/core": "3.3.1"
57
58
  },
58
59
  "peerDependencies": {
59
60
  "pg": "^8.0.0",
@@ -71,7 +72,7 @@
71
72
  "tsup": "^8.3.5",
72
73
  "typescript": "^5.7.2",
73
74
  "vitest": "^2.1.8",
74
- "@eventferry/core": "3.3.0"
75
+ "@eventferry/core": "3.3.1"
75
76
  },
76
77
  "scripts": {
77
78
  "build": "tsup",