feat: typed, documented constants for message types and variants (#39)#40
Merged
Merged
Conversation
Adds MessageType, CreditTransferVariant, and DirectDebitVariant as documented const objects (as const, not enum) so consumers get autocomplete and TSDoc on each member without breaking existing raw string usage. Single source of truth lives in src/message-types.ts. The writer files and parser types now derive from it: CreditTransferVariant and DirectDebitVariant types in writer.ts / direct-debit.ts are replaced by re-exports; ParseSuccess001.type / ParseSuccess008.type use typeof MessageType.CreditTransfer / typeof MessageType.DirectDebit, which resolve to the same 'pain.001' / 'pain.008' literals. All three objects are exported from src/index.ts via a single export statement (const export exposes both value and type alias via declaration merging). No breaking change: string literals remain accepted everywhere. Variant names: SCT_V09 (pain.001.001.09, ISO version .09), SCT_Legacy (pain.001.001.03), SCT_DK (pain.001.003.03), SDD_V08 (pain.008.001.08, ISO version .08), SDD_DK (pain.008.003.02). Adds 16 new tests in test/message-types.test.ts covering value equality, discriminator narrowing, constant vs raw-string write output, and type assignability. Total: 687 tests passing. README updated to show MessageType in the parse snippet and CreditTransferVariant / DirectDebitVariant in all three variant sections.
Contributor
Fallow audit reportNo GitHub PR/MR findings. Generated by fallow. |
Contributor
Fallow audit report0 inline findings selected for GitHub review. |
benjamineckstein
added a commit
that referenced
this pull request
Jun 5, 2026
The Current state section was stale (claimed 0.1.0/0.2.0 published with 0.3.0 unpushed). The package is at 1.1.0 with the public API frozen since 1.0.0. Update the version reality, the pre-1.0 dev/release notes, and add the typed message-type constants (#40) to the shipped-features list.
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.
Closes #39
Summary
Adds typed, self-documenting constants for SEPA message types and variants as a single source of truth. Exports
MessageType(credit transfer vs direct debit),CreditTransferVariant(pain.001.* versions), andDirectDebitVariant(pain.008.* versions) asas constobjects with derived type aliases. Constant-based narrowing is now possible alongside the still-supported raw string literals, enabling clearer intent in code likewriteDirectDebit({ variant: SDD_V08 })instead of magic strings. Modern defaults namedSCT_V09/SDD_V08(version-counter mnemonics).Usage Examples
Before: raw strings, no constants
After: with constants (or still with raw strings, both work)
Notes
Testing
All tests pass locally: