Skip to content

Add support for instrumentType field#8

Merged
leppa merged 1 commit intodevfrom
instrument-type
Mar 29, 2026
Merged

Add support for instrumentType field#8
leppa merged 1 commit intodevfrom
instrument-type

Conversation

@leppa
Copy link
Copy Markdown
Owner

@leppa leppa commented Mar 28, 2026

Description

  • Add instrumentType property to WealthfolioRecord and corresponding enum for type safety.
  • Add validation for instrumentType field: optional when symbol is present, ignored otherwise.
  • Update the Generic plugin to support the new field.
  • Update documentation, samples, and tests.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • New format plugin (adds support for a new CSV format)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Test improvements
  • Chore (project maintenance, build configuration, etc.)
  • Other (please describe):

Checklist

  • I have read the Code of Conduct and agree to abide by it
  • I agree that my contributions will be licensed under the BSD 3-Clause License
  • My code follows the project's coding style and conventions
  • I have added JSDoc documentation for any new functions, classes, or methods
  • I have updated relevant documentation (README, ChangeLog, docs/, etc.)
  • I have written tests for my changes
  • All new code has adequate test coverage
  • All existing tests pass locally
  • My commits have clear and descriptive commit messages
  • My commits are atomic, i.e. complete and self-contained units of change (else, meld the commits before submitting the PR)

Additional Notes

This field was added to Wealthfolio in March 2026 and is optional (see afadil/wealthfolio#666).


By submitting this pull request, I confirm that I have read and understood the contribution guidelines and that my contributions are my own work.

@leppa leppa added this to the v0.2.0 milestone Mar 28, 2026
@leppa leppa added the enhancement Issue or pull request related to a new feature label Mar 28, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 655e86cd-37c4-4e3c-9d8c-126d3f379401

📥 Commits

Reviewing files that changed from the base of the PR and between bf9355a and 2ba6196.

⛔ Files ignored due to path filters (1)
  • examples/sample-generic.csv is excluded by !**/*.csv
📒 Files selected for processing (12)
  • ChangeLog.md
  • README.md
  • docs/format-plugin-development-guide.md
  • docs/generic-format-user-guide.md
  • docs/technical-information.md
  • src/core/BaseFormat.ts
  • src/core/FieldRequirements.ts
  • src/formats/GenericFormat.ts
  • tests/core/BaseFormat.test.ts
  • tests/core/Converter.test.ts
  • tests/core/FieldRequirements.test.ts
  • tests/formats/GenericFormat.test.ts
✅ Files skipped from review due to trivial changes (4)
  • ChangeLog.md
  • README.md
  • tests/core/BaseFormat.test.ts
  • docs/technical-information.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/core/FieldRequirements.test.ts
  • src/formats/GenericFormat.ts

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added support for an Instrument Type field with categories: Equity, Crypto, FX, Option, Metal, Bond.
    • Generic CSV format: optional InstrumentType column; missing/unrecognized values output as empty/unknown.
  • Documentation

    • Updated user guides, examples, and README to document the InstrumentType column, accepted aliases, and example CSVs.

Walkthrough

Adds support for a new Wealthfolio instrumentType field: introduces an InstrumentType enum and WealthfolioRecord.instrumentType, updates field validation rules, extends the GenericFormat parser with mapInstrumentType() and schema changes, and updates documentation and tests accordingly.

Changes

Cohort / File(s) Summary
Documentation
ChangeLog.md, README.md, docs/format-plugin-development-guide.md, docs/generic-format-user-guide.md, docs/technical-information.md
Add changelog entry and user/developer docs for instrumentType; update example schemas, example conversions, TOC, CSV example file, and technical references to list supported instrument categories and alias mapping.
Core types & validation
src/core/BaseFormat.ts, src/core/FieldRequirements.ts
Add exported InstrumentType enum and new WealthfolioRecord.instrumentType property; update RECORD_FIELD_REQUIREMENTS to mark instrumentType Optional for Buy/Sell/Dividend/Split, conditionally Optional/Ignored for other activity types based on symbol, and Ignored for deposit/withdrawal/fee/tax/credit cases.
Generic format plugin
src/formats/GenericFormat.ts
Accept optional CSV InstrumentType column, add private mapInstrumentType(type?: string): InstrumentType to normalize and map aliases (equity/stock/etf, crypto, fx/forex, option/opt, metal/commodity, bond/fixed income/debt) to enum values, default to Unknown, and include column in getExpectedSchema().
Tests
tests/core/BaseFormat.test.ts, tests/core/Converter.test.ts, tests/core/FieldRequirements.test.ts, tests/formats/GenericFormat.test.ts
Update tests to import InstrumentType; set instrumentType in test records/fixtures; adjust expected CSV header length (+1); add tests for mapInstrumentType alias handling and for conditional validation/clearing behavior of instrumentType across activity types and symbol presence.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

chore

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding support for the instrumentType field across the codebase.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose, implementation details, and scope of the instrumentType feature addition.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e9939bf) to head (2ba6196).
⚠️ Report is 1 commits behind head on dev.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev        #8   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          493       516   +23     
  Branches       106       113    +7     
=========================================
+ Hits           493       516   +23     
Components Coverage Δ
Core 100.00% <100.00%> (ø)
Format Plugins 100.00% <100.00%> (ø)
Data Providers 100.00% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/formats/GenericFormat.ts (1)

150-187: Consider adding "futures" as an alias for instruments.

The mapInstrumentType implementation is well-structured with good normalization (trim + lowercase) and comprehensive alias coverage. The typo handling for "mutial fund" (Line 160) is a nice touch for user-friendly input tolerance.

One minor consideration: futures contracts are a common instrument type that could map to either Option (derivatives) or a separate category. If Wealthfolio's InstrumentType enum doesn't have a specific futures type, you might consider adding "futures" or "future" as an alias mapping to the most appropriate existing type.

tests/formats/GenericFormat.test.ts (1)

641-664: Consider adding "InstrumentType" to the schema assertion.

The getExpectedSchema test verifies expected column names but doesn't include the newly added InstrumentType column in the assertion array.

🔧 Proposed fix
       expect(columnNames).toEqual(
         expect.arrayContaining([
           "Date",
           "TransactionType",
           "TransactionSubtype",
+          "InstrumentType",
           "Symbol",
           "ISIN",
           "CUSIP",

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e69f2399-ea96-4103-97fc-517fc16edb00

📥 Commits

Reviewing files that changed from the base of the PR and between e9939bf and bf9355a.

⛔ Files ignored due to path filters (1)
  • examples/sample-generic.csv is excluded by !**/*.csv
📒 Files selected for processing (12)
  • ChangeLog.md
  • README.md
  • docs/format-plugin-development-guide.md
  • docs/generic-format-user-guide.md
  • docs/technical-information.md
  • src/core/BaseFormat.ts
  • src/core/FieldRequirements.ts
  • src/formats/GenericFormat.ts
  • tests/core/BaseFormat.test.ts
  • tests/core/Converter.test.ts
  • tests/core/FieldRequirements.test.ts
  • tests/formats/GenericFormat.test.ts

Comment thread docs/generic-format-user-guide.md Outdated
This field was added to Wealthfolio in March 2026 and is optional.

- Add `instrumentType` property to `WealthfolioRecord` and corresponding
  enum for type safety.
- Add validation for `instrumentType` field: optional when symbol is
  present, ignored otherwise.
- Update the Generic plugin to support the new field.
- Update documentation, samples, and tests.
@leppa leppa force-pushed the instrument-type branch from bf9355a to 2ba6196 Compare March 29, 2026 00:07
@sonarqubecloud
Copy link
Copy Markdown

@leppa leppa added the format plugin Issue or pull request related to a format plugin label Mar 29, 2026
@leppa leppa merged commit 0fe7141 into dev Mar 29, 2026
15 checks passed
@leppa leppa deleted the instrument-type branch March 29, 2026 01:51
@coderabbitai coderabbitai Bot mentioned this pull request Apr 7, 2026
29 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Issue or pull request related to a new feature format plugin Issue or pull request related to a format plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant