fix(db): disable useDefineForClassFields so entity updates stay updates#206
Merged
Merged
Conversation
The es2022 target bump (e18f05a) flipped useDefineForClassFields to true, so entities from repo.create() carry every declared column as an own undefined property. The Object.assign(dbEntity, freshEntity) update pattern then wipes the loaded row's id and save() inserts a duplicate row instead of updating. Restores the pre-bump Set semantics and pins them with a regression spec. Root cause of #205.
TaprootFreak
approved these changes
Jul 16, 2026
TaprootFreak
left a comment
Contributor
There was a problem hiding this comment.
Reviewed: explicitly disabling define-style class fields restores the pre-ES2022 entity semantics across all affected Object.assign update paths, and the regression test pins both the own-property and preserved-id behavior. CI is green. The required duplicate-row cleanup remains tracked in #205, now assigned to Danswar: #205.
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.
Root-cause fix for #205 (the data cleanup follow-up stays tracked there).
What
One line in
tsconfig.json—"useDefineForClassFields": false— plus a regression spec that pins the semantics.Why
Commit e18f05a (#84) bumped
targetfromes2017toes2022, which silently flips TypeScript'suseDefineForClassFieldsdefault totrue. Since then, every entity produced byrepo.create()/new Entity()carries all declared columns — includingid— as own properties initialized toundefined. The update helpers merge withObject.assign(dbEntity, freshEntity), which copiesid: undefinedonto the loaded row, sosave()issues an INSERT instead of an UPDATE:transaction_onchainhasUNIQUE ("transaction")→ the 02:00 nightly sync has aborted withUQ_8a233973duplicate-key errors every night since 2025-11-11 (verified in Loki: 55 dup-key errors/night on PRD, 3/night on DEV — exactly the table row counts — and zerosyncOnchainTransactions: runtime=success lines in 30 days).transaction_lightninghas no unique constraint → the same pattern silently inserts duplicate rows: the 03:00 sync'sentries=count compounded 369 → 1250/night over the last week, and websocket state transitions create new rows instead of updating.Setting the flag back to Set semantics restores exactly the behavior the codebase ran with before November and fixes all four
Object.assign-merge sites at once (lightning-transaction.service.ts×2,lightning-wallet.service.ts,user-boltcard.service.ts).Verification
idgets wiped toundefined) and passes with the fix; ts-jest compiles specs with the repo tsconfig, so it also guards against a future re-flip.npm run build,npm run test(30/30),npm run lintall green locally.Error during processSyncOnchainTransactionsshould disappear and asyncOnchainTransactions: runtime=line should appear;transaction_lightningshould stop growing at the sync rate.Not in this PR
transaction_lightningrows accumulated since November (needs FK remap ofuser_transaction.lightningTransactionId) — follow-up per Entity updates broken since es2022 target bump: nightly onchain sync aborts on dup-key, transaction_lightning silently accumulates duplicate rows #205.UNIQUE (type, transaction)ontransaction_lightning— only possible after the cleanup.