@nodii/outbox-dispatcher 0.15.0 → 0.16.0

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.
package/README.md CHANGED
@@ -344,6 +344,121 @@ await sweepUnpublishedOutbox({ pool: pgPool, dispatcher, telemetry });
344
344
  This is distinct from the subscriber-side `replication_dlq` (`09 § 8.1`), which
345
345
  handles consume-side poison applies and is unaffected.
346
346
 
347
+ ## Retention: prune published rows, bound streams by age (RETENTION-FIX-4, LIBS-72)
348
+
349
+ Outbox payloads can hold personal data, and nothing else ever deletes a
350
+ published row. Wire the prune job **once** in your worker process and run its
351
+ handler daily:
352
+
353
+ ```ts
354
+ import { makeOutboxPruneJob } from "@nodii/outbox-dispatcher";
355
+
356
+ const dispatcher = defineDispatcher({ serviceName: "tenant", streamFor /* , orderPerAggregate */ });
357
+ worker.schedule(makeOutboxPruneJob({ dispatcher, pool: ownerSql, redis }));
358
+ // { name: "tenant.outbox-prune", intervalMs: 86_400_000, pool: "owner", handler }
359
+ ```
360
+
361
+ Passing the `dispatcher` gives the job its `serviceName`, `outboxTable` and
362
+ `orderPerAggregate`; each can also be given on its own.
363
+ Python: `make_outbox_prune_job(dispatcher=dispatcher, pool=owner_pool, redis=redis)`.
364
+ Go: `outbox.MakeOutboxPruneJob(outbox.OutboxPruneJobConfig{Dispatcher: &d, Pool: ownerPool, Redis: redisClient})`.
365
+
366
+ Each run:
367
+
368
+ - **Deletes published rows** whose `dispatched_at` is older than `retentionMs`
369
+ (default **30 days**, operator ruling of 20 Nov 2026), `batchSize` (1,000)
370
+ rows per `DELETE`, until a `DELETE` removes nothing (a short batch is not
371
+ the end: `SKIP LOCKED` may have passed over rows a drain holds), at most
372
+ `maxBatchesPerRun` (1,000) statements.
373
+ - **With `orderPerAggregate`, keeps each aggregate's latest published row.** The
374
+ ordered claim reads the aggregate's previous row to detect a version gap; if
375
+ the prune removed the aggregate's whole history, a v7 committing before v6
376
+ would publish at once. So a row is deleted only while a newer published row
377
+ of its aggregate exists, and the kept latest row, once past the retention,
378
+ is scrubbed (`payload = '{}'`, trace, telemetry and error columns NULL):
379
+ its version survives, its personal data does not
380
+ (`outbox.prune.scrubbed_rows`). Without `orderPerAggregate` every aged
381
+ published row goes, so one-shot aggregates do not pile up. As a fail-safe, a
382
+ table that carries the aggregate-order index (`idx_aggregate_order_<table>`,
383
+ from `buildOrderPerAggregateIndexSql`) is treated as ordered even when the
384
+ job was built from `serviceName` rather than the `dispatcher`.
385
+ - **Never deletes an unpublished row** (`dispatched_at IS NULL`), however old
386
+ and however often its publish failed. D401 keeps it as the source of truth;
387
+ once repaired it publishes, and it is deleted 30 days after that.
388
+ - **Trims the streams you list**, and only those, to `XTRIM <stream> MINID ~
389
+ <now - 14 days>` (per-stream `retentionMs`, default **14 days**). Trimming
390
+ is **opt-in per stream**: a new consumer group, or one whose cursor points
391
+ at a trimmed entry, starts mid-stream, so list a stream only when every
392
+ consumer group on it can hydrate from a snapshot on cold start (or starts
393
+ at `$` by design). Streams whose consumers replay from `0` with no snapshot
394
+ stay unlisted.
395
+ - **Never trims past an entry a consumer group still needs**: the trim point is
396
+ held at each group's lowest pending id, else its last-delivered id. A group
397
+ that stopped reading holds its stream back; the job logs the group and sets
398
+ `outbox.stream_trim.held_back{service,stream}` to 1. Pass
399
+ `respectConsumerGroups: false` only for a stream whose groups are disposable.
400
+
401
+ ```ts
402
+ makeOutboxPruneJob({
403
+ serviceName: "tenant",
404
+ pool: ownerSql,
405
+ redis,
406
+ streams: [
407
+ "tenant.custom_domain", // 14 days
408
+ { stream: "tenant.role", retentionMs: 30 * 86_400_000 },
409
+ ],
410
+ });
411
+ ```
412
+
413
+ One replica runs at a time, under the fenced lease
414
+ `nodii:lease:<service>:outbox-prune` (`LIB-EVT-20`). The fence is checked before
415
+ every `DELETE` batch and every `XTRIM`; a run whose lease is taken stops and
416
+ returns `leaseLost: true`. A replica that finds the lease held returns
417
+ `ran: false`. A failed run (a lease-backend outage at acquire, a database
418
+ error) is counted as `outcome=error` with the rows it already deleted, then
419
+ thrown, so nothing is deleted blind. A run is `complete` only when the DELETE
420
+ loop ended on an empty batch and every listed stream's trim finished within
421
+ its call budget. The `DELETE` bypasses tenant RLS, so pass the **owner** pool.
422
+
423
+ **The event-id dedupe window becomes the outbox retention.**
424
+ `writeOutboxEventOnce` skips a write whose `event_id` conflicts with a row
425
+ still in the table. Once the prune deletes the published row (30 days after
426
+ publish by default), a retried command with the same `event_id` inserts again
427
+ and is published again. A caller that needs a longer dedupe window must keep
428
+ its own idempotency record (for example `@nodii/idempotency`) or raise
429
+ `retentionMs` to cover it.
430
+
431
+ The job writes no audit event (`AUDT-49`). It reports through logs and metrics:
432
+ `outbox.prune.runs{service,outcome}` (`complete` / `partial` / `lease_lost` /
433
+ `skipped` / `error`), `outbox.prune.deleted_rows{service,table}`,
434
+ `outbox.prune.scrubbed_rows{service,table}`,
435
+ `outbox.stream_trim.entries{service,stream}`,
436
+ `outbox.stream_trim.held_back{service,stream}` and
437
+ `outbox.stream_trim.errors{service,stream}`.
438
+
439
+ The library owns only your outbox table. `saga_outbox` belongs to
440
+ `@nodii/saga` and `replication_dlq` to `@nodii/replica-consumer`; neither is
441
+ pruned here. For a large outbox, add the prune's index once, outside a transaction
442
+ (it is built `CONCURRENTLY`, so producers' INSERTs are never blocked); the
443
+ prune works without it, scanning the table per batch:
444
+
445
+ ```ts
446
+ await sql.unsafe(buildPruneIndexSql("outbox"));
447
+ // CREATE INDEX CONCURRENTLY IF NOT EXISTS "idx_prune_outbox" ON "outbox" (dispatched_at) WHERE dispatched_at IS NOT NULL
448
+ ```
449
+
450
+ Python `build_prune_index_sql`, Go `BuildPruneIndexSQL`. It is not in the
451
+ table migration, because a plain `CREATE INDEX` there would lock an existing
452
+ outbox against writes while it builds. If a concurrent build fails (cancelled, lock
453
+ timeout), Postgres leaves an INVALID `idx_prune_<table>` that `IF NOT EXISTS`
454
+ then skips: check `SELECT indisvalid FROM pg_index WHERE indexrelid =
455
+ 'idx_prune_outbox'::regclass`, and if it is false run `DROP INDEX CONCURRENTLY
456
+ IF EXISTS "idx_prune_outbox"` and build it again.
457
+
458
+ A stream whose trim fails (a non-stream key under the name, a Redis error) is
459
+ returned with `error`, counted in `outbox.stream_trim.errors{service,stream}`,
460
+ and does not stop the next stream or the run's report.
461
+
347
462
  ## Metrics (§ 5.6)
348
463
 
349
464
  `outbox.depth{topic}` · `outbox.lag_seconds{topic}` · `outbox.dispatch_rate{topic}`
@@ -1,2 +1,2 @@
1
- export declare const PACKAGE_VERSION = "0.15.0";
1
+ export declare const PACKAGE_VERSION = "0.16.0";
2
2
  //# sourceMappingURL=package-version.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // GENERATED by scripts/embed-package-versions.mjs. Do not edit.
2
- export const PACKAGE_VERSION = "0.15.0";
2
+ export const PACKAGE_VERSION = "0.16.0";
3
3
  //# sourceMappingURL=package-version.js.map
package/dist/index.d.ts CHANGED
@@ -7,7 +7,8 @@ export { buildEnvelope, DEFAULT_STREAM_MAXLEN, serializeEnvelope, xaddEnvelope,
7
7
  export { compareStreamIds, HwmTracker } from "./hwm.js";
8
8
  export { type LeaseHandle, type LeaseOpts, tryAcquireLease } from "./lease.js";
9
9
  export { applyOutboxDispatcherMigrations, getOutboxDispatcherMigrationSQL, } from "./migrations/index.js";
10
- export { buildClaimBatchSql, type ClaimSqlOptions, DEFAULT_AGGREGATE_GAP_WAIT_MS, MAX_AGGREGATE_GAP_WAIT_MS, MAX_ORDERED_TABLE_NAME_LENGTH, buildDepthByTopicSql, buildInsertOutboxSql, buildMarkDispatchedSql, buildOrderPerAggregateIndexSql, buildPendingTenantIndexSql, buildRecordFailureSql, buildTenantColumnCheckSql, buildUnpublishedSweepSql, quoteIdent, } from "./sql-builders.js";
10
+ export { buildClaimBatchSql, type ClaimSqlOptions, DEFAULT_AGGREGATE_GAP_WAIT_MS, MAX_AGGREGATE_GAP_WAIT_MS, MAX_ORDERED_TABLE_NAME_LENGTH, buildDepthByTopicSql, buildInsertOutboxSql, buildMarkDispatchedSql, buildOrderPerAggregateIndexSql, buildPendingTenantIndexSql, buildPruneIndexSql, buildPrunePublishedSql, buildScrubPublishedSql, type PruneSqlOptions, MAX_PRUNE_INDEX_TABLE_NAME_LENGTH, buildRecordFailureSql, buildTenantColumnCheckSql, buildUnpublishedSweepSql, quoteIdent, } from "./sql-builders.js";
11
+ export { consumerGroupFloor, DEFAULT_OUTBOX_PRUNE_BATCH_SIZE, DEFAULT_OUTBOX_PRUNE_INTERVAL_MS, DEFAULT_OUTBOX_PRUNE_LEASE_TTL_MS, DEFAULT_OUTBOX_PRUNE_MAX_BATCHES, DEFAULT_OUTBOX_RETENTION_MS, DEFAULT_STREAM_RETENTION_MS, DEFAULT_STREAM_TRIM_MAX_CALLS, makeOutboxPruneJob, MAX_OUTBOX_PRUNE_BATCH_SIZE, OUTBOX_PRUNE_LEASE_SCOPE, type OutboxPruneJob, type OutboxPruneJobOpts, type OutboxPruneResult, outboxPruneJobName, prunePublishedOutbox, type StreamRetention, type StreamTrimRedisLike, type StreamTrimResult, trimStreamByAge, } from "./prune.js";
11
12
  export { type DispatcherHandle, startDispatcher } from "./start.js";
12
13
  export { DEFAULT_UNPUBLISHED_SWEEP_LIMIT, DEFAULT_UNPUBLISHED_SWEEP_THRESHOLD_SECONDS, sweepUnpublishedOutbox, type UnpublishedRow, } from "./sweep.js";
13
14
  export { DispatcherNotWired, InvalidAggregateKind, InvalidDispatcherConfig, InvalidOutboxEventId, InvalidOutboxTelemetryEnvelope, InvalidOutboxTenant, OutboxDispatcherError, OutboxTenantMismatch, UnregisteredAggregateKind, } from "./types.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,QAAQ,sBAAsB,CAAC;AAC5C,eAAO,MAAM,OAAO,EAAE,MAAwB,CAAC;AAE/C,OAAO,EACL,KAAK,qBAAqB,EAC1B,oBAAoB,GAC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@@ -30,7 +30,8 @@ export { buildEnvelope, DEFAULT_STREAM_MAXLEN, serializeEnvelope, xaddEnvelope,
30
30
  export { compareStreamIds, HwmTracker } from "./hwm.js";
31
31
  export { tryAcquireLease } from "./lease.js";
32
32
  export { applyOutboxDispatcherMigrations, getOutboxDispatcherMigrationSQL, } from "./migrations/index.js";
33
- export { buildClaimBatchSql, DEFAULT_AGGREGATE_GAP_WAIT_MS, MAX_AGGREGATE_GAP_WAIT_MS, MAX_ORDERED_TABLE_NAME_LENGTH, buildDepthByTopicSql, buildInsertOutboxSql, buildMarkDispatchedSql, buildOrderPerAggregateIndexSql, buildPendingTenantIndexSql, buildRecordFailureSql, buildTenantColumnCheckSql, buildUnpublishedSweepSql, quoteIdent, } from "./sql-builders.js";
33
+ export { buildClaimBatchSql, DEFAULT_AGGREGATE_GAP_WAIT_MS, MAX_AGGREGATE_GAP_WAIT_MS, MAX_ORDERED_TABLE_NAME_LENGTH, buildDepthByTopicSql, buildInsertOutboxSql, buildMarkDispatchedSql, buildOrderPerAggregateIndexSql, buildPendingTenantIndexSql, buildPruneIndexSql, buildPrunePublishedSql, buildScrubPublishedSql, MAX_PRUNE_INDEX_TABLE_NAME_LENGTH, buildRecordFailureSql, buildTenantColumnCheckSql, buildUnpublishedSweepSql, quoteIdent, } from "./sql-builders.js";
34
+ export { consumerGroupFloor, DEFAULT_OUTBOX_PRUNE_BATCH_SIZE, DEFAULT_OUTBOX_PRUNE_INTERVAL_MS, DEFAULT_OUTBOX_PRUNE_LEASE_TTL_MS, DEFAULT_OUTBOX_PRUNE_MAX_BATCHES, DEFAULT_OUTBOX_RETENTION_MS, DEFAULT_STREAM_RETENTION_MS, DEFAULT_STREAM_TRIM_MAX_CALLS, makeOutboxPruneJob, MAX_OUTBOX_PRUNE_BATCH_SIZE, OUTBOX_PRUNE_LEASE_SCOPE, outboxPruneJobName, prunePublishedOutbox, trimStreamByAge, } from "./prune.js";
34
35
  export { startDispatcher } from "./start.js";
35
36
  export { DEFAULT_UNPUBLISHED_SWEEP_LIMIT, DEFAULT_UNPUBLISHED_SWEEP_THRESHOLD_SECONDS, sweepUnpublishedOutbox, } from "./sweep.js";
36
37
  export { DispatcherNotWired, InvalidAggregateKind, InvalidDispatcherConfig, InvalidOutboxEventId, InvalidOutboxTelemetryEnvelope, InvalidOutboxTenant, OutboxDispatcherError, OutboxTenantMismatch, UnregisteredAggregateKind, } from "./types.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,EAAE;AACF,gFAAgF;AAChF,4DAA4D;AAC5D,kEAAkE;AAClE,EAAE;AACF,WAAW;AACX,4DAA4D;AAC5D,mEAAmE;AACnE,oDAAoD;AACpD,kDAAkD;AAClD,4DAA4D;AAC5D,2EAA2E;AAC3E,6EAA6E;AAC7E,gFAAgF;AAChF,6EAA6E;AAC7E,kFAAkF;AAClF,8EAA8E;AAC9E,4DAA4D;AAC5D,uDAAuD;AACvD,uDAAuD;AACvD,aAAa;AAEb,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,MAAM,CAAC,MAAM,QAAQ,GAAG,mBAAmB,CAAC;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAW,eAAe,CAAC;AAE/C,OAAO,EAEL,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,8BAA8B,EAC9B,oBAAoB,EACpB,eAAe,EACf,4BAA4B,EAC5B,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,4BAA4B,EAE5B,WAAW,EACX,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,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EAC/B,2CAA2C,EAC3C,sBAAsB,GAEvB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,8BAA8B,EAC9B,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AAepB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAIL,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,261 @@
1
+ import { type LeaseRedisLike } from "@nodii/telemetry/worker";
2
+ import { type ResolvedDispatcher, type SqlExecutor, type TelemetryAdapter } from "./types.js";
3
+ /** Published outbox rows are kept 30 days after publish (operator ruling 3). */
4
+ export declare const DEFAULT_OUTBOX_RETENTION_MS: number;
5
+ /** A listed stream keeps 14 days of entries (LIBS-72, operator 10 Nov). */
6
+ export declare const DEFAULT_STREAM_RETENTION_MS: number;
7
+ /** The job runs daily. */
8
+ export declare const DEFAULT_OUTBOX_PRUNE_INTERVAL_MS: number;
9
+ /** Rows deleted per DELETE statement. */
10
+ export declare const DEFAULT_OUTBOX_PRUNE_BATCH_SIZE = 1000;
11
+ /** Upper bound on DELETE statements per run (the orderPerAggregate scrub gets as many again). */
12
+ export declare const DEFAULT_OUTBOX_PRUNE_MAX_BATCHES = 1000;
13
+ /** Largest accepted batch size. */
14
+ export declare const MAX_OUTBOX_PRUNE_BATCH_SIZE = 10000;
15
+ /** XTRIM calls per stream per run, at most. */
16
+ export declare const DEFAULT_STREAM_TRIM_MAX_CALLS = 1000;
17
+ /** Lease scope: `nodii:lease:<service>:outbox-prune`. */
18
+ export declare const OUTBOX_PRUNE_LEASE_SCOPE = "outbox-prune";
19
+ /** Lease TTL; it renews at half this for as long as the run lasts. */
20
+ export declare const DEFAULT_OUTBOX_PRUNE_LEASE_TTL_MS = 30000;
21
+ /** The job's name for a service: `<service>.outbox-prune`. */
22
+ export declare function outboxPruneJobName(serviceName: string): string;
23
+ /** The Redis calls the stream trim makes. ioredis has them, but its overloaded
24
+ * commands need narrowing to these signatures (cast each method, as the
25
+ * synthetic consumer's `asPruneRedis` does). */
26
+ export interface StreamTrimRedisLike {
27
+ xtrim(key: string, ...args: (string | number)[]): Promise<unknown>;
28
+ xinfo(...args: (string | number)[]): Promise<unknown>;
29
+ xpending(key: string, group: string): Promise<unknown>;
30
+ }
31
+ /** One stream the job trims, with its own retention (default 14 days). */
32
+ export interface StreamRetention {
33
+ stream: string;
34
+ /** Entries older than this are trimmed. Default `DEFAULT_STREAM_RETENTION_MS`. */
35
+ retentionMs?: number;
36
+ }
37
+ export interface OutboxPruneJobOpts {
38
+ /**
39
+ * The dispatcher this job prunes for. Supplies `serviceName`, `outboxTable`
40
+ * and `orderPerAggregate` unless they are given here. Prefer it: it keeps
41
+ * the prune's aggregate-order handling in step with the dispatcher's.
42
+ */
43
+ dispatcher?: Pick<ResolvedDispatcher, "serviceName" | "outboxTable" | "orderPerAggregate">;
44
+ /** The producing service: the lease key's service segment and a metric label. */
45
+ serviceName?: string;
46
+ /**
47
+ * An OWNER-pool executor (the DELETE bypasses tenant RLS). postgres.js
48
+ * `sql` fits.
49
+ */
50
+ pool: SqlExecutor;
51
+ /**
52
+ * Redis for the lease, and for the trim when `streams` is non-empty (then
53
+ * it must also have `xtrim`, `xinfo` and `xpending`). ioredis has them;
54
+ * narrow its overloaded commands to these signatures.
55
+ */
56
+ redis: LeaseRedisLike & Partial<StreamTrimRedisLike>;
57
+ /** Outbox table. Default `outbox`. */
58
+ outboxTable?: string;
59
+ /**
60
+ * The dispatcher publishes each aggregate in version order. Keeps each
61
+ * aggregate's highest-version published row (scrubbed past the retention)
62
+ * for its gap check. Default: the dispatcher's value, else false. A
63
+ * dispatcher's `true` is never overridden by a `false` here. A job for an
64
+ * ordered dispatcher MUST be built from `dispatcher` or set this to true:
65
+ * the aggregate-order index the prune also looks for is optional, so
66
+ * without either the prune can delete an aggregate's whole published
67
+ * history and break the dispatcher's gap check.
68
+ */
69
+ orderPerAggregate?: boolean;
70
+ /** Published rows older than this are deleted. Default 30 days. */
71
+ retentionMs?: number;
72
+ /** Rows per DELETE. Default 1000, at most 10000. */
73
+ batchSize?: number;
74
+ /** DELETE statements per run (the orderPerAggregate scrub gets as many again). Default 1000. */
75
+ maxBatchesPerRun?: number;
76
+ /**
77
+ * Streams to bound by age. Default none: a stream is trimmed only when
78
+ * listed here. A bare string uses the 14-day default.
79
+ */
80
+ streams?: ReadonlyArray<string | StreamRetention>;
81
+ /**
82
+ * Hold each stream's trim point at the oldest entry a consumer group still
83
+ * needs. Default true. Turn off only for a stream whose groups are known
84
+ * to be disposable.
85
+ */
86
+ respectConsumerGroups?: boolean;
87
+ /** Job interval. Default 24 hours. */
88
+ intervalMs?: number;
89
+ /** Lease TTL. Default 30000, at least 2000. */
90
+ leaseTtlMs?: number;
91
+ /** Logs and metrics. */
92
+ telemetry?: TelemetryAdapter;
93
+ }
94
+ /** What one stream's trim did. */
95
+ export interface StreamTrimResult {
96
+ stream: string;
97
+ retentionMs: number;
98
+ /** The last `MINID` passed to XTRIM, or null when the stream does not exist. */
99
+ minId: string | null;
100
+ /** Entries XTRIM removed. */
101
+ trimmed: number;
102
+ /** The group that held the last trim point below the age cutoff, if any. */
103
+ heldBackBy: string | null;
104
+ /** False when the trim stopped at `maxCalls` with entries still to remove,
105
+ * or failed. */
106
+ complete: boolean;
107
+ /**
108
+ * Set only by the job when this stream's trim failed (Redis error, a
109
+ * non-stream key under the name, a group removed mid-trim). The job logs
110
+ * it, counts `outbox.stream_trim.errors` and goes on to the next stream.
111
+ */
112
+ error?: string;
113
+ }
114
+ /** What one run did. */
115
+ export interface OutboxPruneResult {
116
+ /** False when another replica held the lease: this run did nothing. */
117
+ ran: boolean;
118
+ deletedRows: number;
119
+ /** Kept latest-per-aggregate rows whose payload was scrubbed
120
+ * (`orderPerAggregate` only). */
121
+ scrubbedRows: number;
122
+ /** DELETE and scrub statements run. */
123
+ batches: number;
124
+ /** False when the run stopped at `maxBatchesPerRun`, a stream trim was
125
+ * incomplete or failed, or the lease was lost. */
126
+ complete: boolean;
127
+ /** True when the lease was lost (or could not be checked) mid-run. */
128
+ leaseLost: boolean;
129
+ streams: StreamTrimResult[];
130
+ ranAt: string;
131
+ }
132
+ /** The framework-agnostic job a worker schedules: `{ name, intervalMs, pool, handler }`. */
133
+ export interface OutboxPruneJob {
134
+ name: string;
135
+ intervalMs: number;
136
+ /** The DELETE runs on the owner pool. */
137
+ pool: "owner";
138
+ handler: () => Promise<OutboxPruneResult>;
139
+ }
140
+ /** Resolved prune-batch options: the one validator both entry points share. */
141
+ export interface ResolvedPruneBatchOpts {
142
+ outboxTable: string;
143
+ retentionMs: number;
144
+ batchSize: number;
145
+ maxBatches: number;
146
+ orderPerAggregate: boolean;
147
+ }
148
+ /** Resolved stream-trim options. */
149
+ export interface ResolvedTrimOpts {
150
+ retentionMs: number;
151
+ maxCalls: number;
152
+ respectConsumerGroups: boolean;
153
+ approximate: boolean;
154
+ }
155
+ export interface ResolvedPruneOpts {
156
+ serviceName: string;
157
+ batch: ResolvedPruneBatchOpts;
158
+ streams: Array<Required<StreamRetention>>;
159
+ respectConsumerGroups: boolean;
160
+ intervalMs: number;
161
+ leaseTtlMs: number;
162
+ }
163
+ /**
164
+ * Validate and default the prune-batch options. A retention or batch size of
165
+ * 0 or less is refused: a retention of 0 would delete rows published a moment
166
+ * ago, and a batch size of 0 would loop without deleting.
167
+ */
168
+ export declare function resolvePruneBatchOpts(opts: {
169
+ outboxTable?: string;
170
+ retentionMs?: number;
171
+ batchSize?: number;
172
+ maxBatches?: number;
173
+ orderPerAggregate?: boolean;
174
+ }): ResolvedPruneBatchOpts;
175
+ /** Validate and default the stream-trim options (retention and maxCalls of
176
+ * 0 or less are refused). */
177
+ export declare function resolveTrimOpts(opts: {
178
+ retentionMs?: number;
179
+ maxCalls?: number;
180
+ respectConsumerGroups?: boolean;
181
+ approximate?: boolean;
182
+ }): ResolvedTrimOpts;
183
+ /** Validate and default the job options. Throws `InvalidDispatcherConfig`. */
184
+ export declare function resolveOutboxPruneOpts(opts: Omit<OutboxPruneJobOpts, "pool" | "redis" | "telemetry">): ResolvedPruneOpts;
185
+ /** Hooks a caller passes to the batch loops. */
186
+ interface BatchHooks {
187
+ /** Runs before each statement (the job passes the fence check). */
188
+ beforeBatch?: () => Promise<void>;
189
+ /** Runs after each statement with the rows it touched, so a caller keeps
190
+ * the count when a later `beforeBatch` throws. */
191
+ onBatch?: (rows: number, kind: "deleted" | "scrubbed") => void;
192
+ /** Runs once when the prune runs ordered on a table without the full
193
+ * aggregate-order index, with the statement that creates it. */
194
+ onMissingOrderIndex?: (createIndexSql: string) => void;
195
+ }
196
+ /**
197
+ * Delete published rows older than `retentionMs`, `batchSize` at a time, up to
198
+ * `maxBatches` statements, until a statement deletes nothing. Unpublished rows
199
+ * are never selected. With `orderPerAggregate`, each aggregate's
200
+ * highest-version published row is kept, and scrubbed once past the retention.
201
+ */
202
+ export declare function prunePublishedOutbox(args: {
203
+ pool: SqlExecutor;
204
+ outboxTable?: string;
205
+ retentionMs?: number;
206
+ batchSize?: number;
207
+ maxBatches?: number;
208
+ orderPerAggregate?: boolean;
209
+ } & BatchHooks): Promise<{
210
+ deletedRows: number;
211
+ scrubbedRows: number;
212
+ batches: number;
213
+ complete: boolean;
214
+ }>;
215
+ /**
216
+ * The oldest entry any consumer group of `stream` still needs: per group its
217
+ * lowest pending id, else its last-delivered id; the minimum over groups. A
218
+ * group with nothing pending that has read up to the stream's newest id
219
+ * (`last-generated-id`) needs nothing and does not count. Returns undefined
220
+ * when the stream does not exist, null when no group needs anything.
221
+ * The groups' XPENDING summaries are read concurrently.
222
+ */
223
+ export declare function consumerGroupFloor(redis: StreamTrimRedisLike, stream: string): Promise<{
224
+ floor: string;
225
+ group: string;
226
+ } | null | undefined>;
227
+ /**
228
+ * Trim `stream` to the entries newer than `retentionMs` with
229
+ * `XTRIM MINID ~`, never past an entry a consumer group still needs (unless
230
+ * `respectConsumerGroups` is false). `beforeTrim` runs right before each XTRIM.
231
+ * `complete` is false when `maxCalls` ran out with entries still to remove.
232
+ */
233
+ export declare function trimStreamByAge(args: {
234
+ redis: StreamTrimRedisLike;
235
+ stream: string;
236
+ retentionMs?: number;
237
+ respectConsumerGroups?: boolean;
238
+ /** `~` (default true): Redis trims whole nodes only, cheaply. */
239
+ approximate?: boolean;
240
+ nowMs?: number;
241
+ /** XTRIM calls at most. Default `DEFAULT_STREAM_TRIM_MAX_CALLS`. */
242
+ maxCalls?: number;
243
+ beforeTrim?: () => Promise<void>;
244
+ }): Promise<StreamTrimResult>;
245
+ /**
246
+ * Build the outbox retention job. A service wires it with one call in its
247
+ * worker process and runs `handler()` every `intervalMs` (daily):
248
+ *
249
+ * ```ts
250
+ * worker.schedule(makeOutboxPruneJob({ dispatcher, pool: ownerSql, redis }));
251
+ * ```
252
+ *
253
+ * Each run, under the lease `nodii:lease:<service>:outbox-prune`, deletes the
254
+ * published rows older than 30 days, then trims each listed stream to 14 days.
255
+ * A run that finds the lease held by another replica returns `ran: false`. A
256
+ * failed run (a lease-backend outage at acquire, a database error) records
257
+ * `outcome=error` and throws: nothing is deleted blind.
258
+ */
259
+ export declare function makeOutboxPruneJob(opts: OutboxPruneJobOpts): OutboxPruneJob;
260
+ export {};
261
+ //# sourceMappingURL=prune.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../src/prune.ts"],"names":[],"mappings":"AAkEA,OAAO,EAGL,KAAK,cAAc,EAEpB,MAAM,yBAAyB,CAAC;AAWjC,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAIpB,gFAAgF;AAChF,eAAO,MAAM,2BAA2B,QAAc,CAAC;AACvD,2EAA2E;AAC3E,eAAO,MAAM,2BAA2B,QAAc,CAAC;AACvD,0BAA0B;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