Repository navigation
fix: store event data as published and validate it in the form the store keeps - #97
Merged
Merged
Conversation
publish stored the schema's output and the processor parsed it again as input. Dates under z.date() came back from JSON as strings and were dead-lettered on their first claim on Postgres, Redis and DynamoDB, transforms ran twice, and transforms whose output isn't valid input never delivered. The memory store kept Dates, so tests passed. Store the published input instead, validate it at publish in the form the store hands it back (new optional TxOBStore.roundTripData), give priority, key and defer functions the parsed output like handlers, and keep memory store data as JSON. Events stored by 0.6.0 parse as before.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #97 +/- ##
==========================================
+ Coverage 96.09% 96.13% +0.04%
==========================================
Files 33 34 +1
Lines 2253 2355 +102
Branches 455 478 +23
==========================================
+ Hits 2165 2264 +99
- Misses 71 74 +3
Partials 17 17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
dillonstreator
added a commit
that referenced
this pull request
Nov 28, 2026
Resolve the fan-out loop against the schema round-trip change from #97: computeDelivery now receives the parsed event, and events whose stored data fails the schema still get default deliveries. Both 0.6 -> 0.7 migration notes are kept.
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 was wrong
publishstored the schema's output, and the processor parsed that stored value again as input before every delivery. Three things followed for anyone using a real Zod/Valibot schema:z.date()events were dead-lettered on their first claim on Postgres, Redis and DynamoDB. Those stores keep data as JSON, so theDatecame back as an ISO string and failedz.date(). The handler never ran. The memory store keptDates (structuredClone), so unit tests passed and the problem only showed up in production.z.string().transform((s) => s + "!")delivered"bob!!".z.string().transform(Number)stored a number and failedz.string()at delivery, on every store including memory.On top of that,
priority,perKey.keyanddeferfunctions got the raw stored JSON, typed as the schema output (audit TXOB-CONS-002; verified High).What changed
The contract is now: validate at publish in the form the store will hand back, store the published input, and parse once per delivery.
publishstores the data it was given (the schema's input) and returns the parsed output as before. The processor parses the stored input once before fan-out functions and once per delivery, so transforms apply once and handlers andpriority/perKey/deferfunctions all get the output type their signatures already promised.TxOBStore.roundTripData(data)returns data as the store will read it back.publishvalidates that form. Postgres, Redis, DynamoDB and memory use a JSON round-trip. MongoDB uses a BSON round-trip with the collection'sbsonOptions, soDates survive andundefinedbecomesnull(as the driver stores it). Data the store can't keep (aDateunderz.date()in a JSON store) now throwsTxOBValidationErrorat publish, inside the caller's transaction, with a message that names the cause and suggestsz.coerce.date(). Before, it was dead-lettered later.onDeliveryDead).z.coerce.date(), deterministic defaults and transforms, custom stores), MIGRATING (0.6 → 0.7), changeset.Compatibility
txob_events.datarows hold the published input, not the output. This matters only to people who query that column directly.z.date()on Postgres) now throw. Defaults and transforms run at delivery: a.default(() => randomUUID())now gives each delivery a different value. Both are documented in README and MIGRATING.TxOBStoregains an optionalroundTripData.createOutboxaccepts it throughPick<TxOBStore, "insertEvent" | "roundTripData">.TxOBValidationErrorgets an optional third constructor argument. All additive.minor. The CHANGELOG has shipped behavior changes as pre-1.0 minors (0.5, 0.6), and this changes whatpublishaccepts and what it stores.How it was tested
Real backends in temporary containers: Postgres 17 (
postgres:17-alpine), MongoDB 9 single-node replica set, Redis 8 (redis:8-alpine), DynamoDB Local.pnpm install --frozen-lockfile,pnpm test:prepare,pnpm typecheck,pnpm build(ESM + CJS): pass. The repo has no lint script.z.date(),z.coerce.date(), a string transform and a type-changing transform:priority/perKey/deferfunctions get the output, with each transform applied once;z.date()data is rejected at publish on JSON stores and delivered as aDateon MongoDB; nothing is dead-lettered;src/reverted, 12 of the new contract runs fail (Postgres, DynamoDB, MongoDB, memory and all three Redis clients). With the fix, all pass.poc-dates.mjswith real zod 4.6.7:z.date()now throws at publish on the memory store as well as Postgres. Az.coerce.date()variant delivers aDateon Postgres, and the transform runs once ("bob!").For the reviewer to decide
Date, and it breaksz.coerce.date(), which the code comment shows was the intended way to get dates. The cost of my choice: defaults and transforms must be deterministic. It's documented, but say if you'd rather go the other way.src/processor.ts, and both add a "Migrating from 0.6 to 0.7" section. The conflicts are textual. Whichever merges second needs a rebase.Not in this PR
Orphaned deliveries,
perKeykeys, the fan-out cap anddeferopt-out are in a separate PR. Release, packaging, CI and docs hygiene are in another, and the fan-out/rolling-deploy proposal in a third. The PR descriptions list what was skipped.