Skip to content

feat: typed, documented constants for message types and variants (#39)#40

Merged
benjamineckstein merged 1 commit into
mainfrom
feature/39-typed-message-type-constants
Jun 5, 2026
Merged

feat: typed, documented constants for message types and variants (#39)#40
benjamineckstein merged 1 commit into
mainfrom
feature/39-typed-message-type-constants

Conversation

@benjamineckstein

Copy link
Copy Markdown
Contributor

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), and DirectDebitVariant (pain.008.* versions) as as const objects with derived type aliases. Constant-based narrowing is now possible alongside the still-supported raw string literals, enabling clearer intent in code like writeDirectDebit({ variant: SDD_V08 }) instead of magic strings. Modern defaults named SCT_V09 / SDD_V08 (version-counter mnemonics).

Usage Examples

Before: raw strings, no constants

const doc = writeCreditTransfer(model, { variant: 'pain.001.001.09' });

After: with constants (or still with raw strings, both work)

import { SCT_V09, SDD_V08 } from 'sepa-xml-ts';

const doc = writeCreditTransfer(model, { variant: SCT_V09 });  // constant-based, narrowed
const dd = writeDirectDebit(model, { variant: SDD_V08 });      // type-safe defaults
const legacyDoc = writeCreditTransfer(model, { variant: 'pain.001.001.03' });  // raw strings still work

Notes

  • NON-BREAKING: resolved string-literal unions are byte-identical to raw strings; all existing code continues to type-check without modification.
  • 687 tests green, clean typecheck.
  • Quality review verdict: SHIP (cosmetic non-blocking notes only).

Testing

All tests pass locally:

pnpm test       # 687 green
pnpm typecheck  # clean
pnpm build      # clean

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.
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Fallow audit report

No GitHub PR/MR findings.

Generated by fallow.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Fallow audit report

0 inline findings selected for GitHub review.

@benjamineckstein benjamineckstein merged commit 2967f49 into main Jun 5, 2026
2 checks passed
@benjamineckstein benjamineckstein deleted the feature/39-typed-message-type-constants branch June 5, 2026 12:13
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export typed, documented constants for message types and variants (no more magic strings)

1 participant