refactor: extract shared model schemas, profile and parser helpers#38
Merged
Conversation
…preserving)
Priority 1 (model): IBANSchema and BICSchema were byte-for-byte identical in
schema.ts and pain008.ts. Extracted into src/model/shared.ts and imported by
both. sepaText and sepaIdentifier were NOT merged: their error messages differ
(schema.ts carries the long charset hint, pain008.ts uses the short form), so
they are not true duplicates per the CLAUDE.md rule.
Priority 2 (profiles): Extracted two private helpers in profiles.ts:
- checkBicPresent: encapsulates the "if bic undefined, push issue" pattern
used 4 times across requireBic.checkCreditTransfer and .checkDirectDebit.
- checkIbanBicCountryConsistency: encapsulates the IBAN/BIC country mismatch
check used 4 times across ibanBicCountryMatch.checkCreditTransfer and
.checkDirectDebit. Exact same issue messages, same logic, behavior identical.
Priority 3 (parser): Extracted extractGrpHdr() helper from the 30-line block
that was byte-for-byte identical in parsePain001 and parsePain008 (GrpHdr nav,
MsgId, CreDtTm, InitgPty/Nm, PmtInf array guard). Returns a discriminated union
GrpHdrExtracted | ParseFailure; callers branch on .ok. All error messages and
extraction order are preserved. Parser round-trip tests (xsd-oracle, coexistence)
cover this path; 8-run stress shows zero flakes.
Duplication: 17.2% -> 16.6%. 668 tests pass. Golden snapshots byte-exact.
src/index.ts unchanged.
Contributor
Fallow audit reportFound 4 findings. Details
Generated by fallow. |
| CategoryPurposeSchema, | ||
| } from './schema.js' | ||
| import { isValidCreditorId } from './creditor-id.js' | ||
| import { IBANSchema, BICSchema } from './shared.js' |
Contributor
There was a problem hiding this comment.
warn fallow/code-duplication: Code clone group 1 (46 lines, 2 instances)
| import { isValidIban, isValidIso11649Ref } from './iban.js' | ||
| import { isValidIso11649Ref } from './iban.js' | ||
| import { isSepaCharset } from './charset.js' | ||
| import { IBANSchema, BICSchema } from './shared.js' |
Contributor
There was a problem hiding this comment.
warn fallow/code-duplication: Code clone group 1 (46 lines, 2 instances)
| message: 'BIC is required by the selected bank profile but is missing on the creditor', | ||
| }) | ||
| } | ||
| checkBicPresent(issues, 'creditor.bic', doc.creditor.bic, 'creditor') |
Contributor
There was a problem hiding this comment.
warn fallow/code-duplication: Code clone group 2 (11 lines, 2 instances)
| checkIbanBicCountryConsistency( | ||
| issues, | ||
| 'creditor', | ||
| doc.creditor.iban, |
Contributor
There was a problem hiding this comment.
warn fallow/code-duplication: Code clone group 2 (11 lines, 2 instances)
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.
Summary
Extraction of duplicated code blocks across model, profile, and parser modules. No behavior changes: golden snapshots byte-exact, validation/parse behavior identical, public API untouched.
Changes
Model: Extracted IBANSchema + BICSchema (byte-identical in schema.ts and pain008.ts) into new src/model/shared.ts. Deliberately LEFT sepaText/sepaIdentifier un-merged because their error messages differ (not true duplicates).
Profiles: Extracted checkBicPresent + checkIbanBicCountryConsistency helpers, de-duplicating 4 sites each in requireBic and ibanBicCountryMatch. Identical messages preserved.
Parser: Extracted extractGrpHdr (30-line GrpHdr navigation block that was byte-identical in parsePain001 and parsePain008). Every error string and extraction path preserved verbatim.
Verification
Testing
pnpm testto verify all suites pass