@accounter/shaam-uniform-format-generator
Version:
Fully typed application that generates, parses, and validates SHAAM uniform format tax reports (INI.TXT and BKMVDATA.TXT).
207 lines (152 loc) โข 5.1 kB
Markdown
# ๐ Project Specification: SHAAM Uniform Format Generator & Parser
**Name (suggested):** @accounter/shaam-uniform-format-generator **Version:** 0.1.0 **Target
environment:** Node.js + TypeScript **Tech stack:**
- **TypeScript** (strict mode)
- **Zod** for validation
- **Vitest** for testing
- **Vite** as test runner/bundler
## ๐งฉ Goal
Develop a TypeScript package that:
1. **Generates** `INI.TXT` and `BKMVDATA.TXT` files from a high-level JSON object.
2. **Parses** those files back into structured, validated JSON.
3. Performs full spec-compliant formatting (field widths, padding, CRLF endings).
4. Offers excellent developer experience (autocompletion, strict typing, helpful errors).
5. Is file system agnostic โ returns content + virtual `File` objects, but does not write to disk.
## ๐ File & Record Types
The tool must support the following **record types** (from SHAAM 1.31 spec):
### `INI.TXT`
- `A000` โ Header
- `B100`, `B110`, `C100`, `D110`, `D120`, `M100` โ Count summary records
### `BKMVDATA.TXT`
- `A100` โ Opening
- `C100` โ Document header
- `D110` โ Document line
- `D120` โ Payment/receipt
- `B100` โ Journal entry line
- `B110` โ Account
- `M100` โ Inventory item
- `Z900` โ Closing
## ๐ฅ Input Structure (High-Level Semantic Model)
```ts
interface ReportInput {
business: BusinessMetadata // from INI.TXT and A100
documents: Document[] // C100 + D110 + D120
journalEntries: JournalEntry[] // B100s
accounts: Account[] // B110s
inventory: InventoryItem[] // M100s
}
```
- All values are **explicitly supplied** by the user
- No derived or default fields; timestamps, metadata, and file info must be included
- Values are validated against **embedded enums** and **field constraints**
### Notable Constraints
- A `document` may contain zero D110s or D120s
- `accounts` must include only **active accounts**
- `inventory` should contain **aggregated totals**, not raw logs
## ๐ค Output Structure
```ts
interface ReportOutput {
iniText: string
dataText: string
iniFile: File
dataFile: File
summary: {
totalRecords: number
perType: Record<string, number>
errors?: ValidationError[]
}
}
```
- Line endings are `\r\n`
- Fields are fixed-width with spec-correct padding
- Output is **not saved** โ just returned in memory
## ๐ ๏ธ Public API
### Main Function
```ts
generateUniformFormatReport(
input: ReportInput,
options?: {
validationMode?: 'fail-fast' | 'collect-all';
fileNameBase?: string; // Optional override for file names
}
): ReportOutput
```
## ๐งช Testing Strategy
Use **Vitest** with the following principles:
### โ
Unit Tests
- Every record module (`C100`, `D110`, etc.):
- Schema validation
- Encode โ Decode roundtrip
- Encode output matches fixed-width spec
- Invalid inputs throw expected errors
### โ
Integration Tests
- Full `ReportInput` โ `INI.TXT` + `BKMVDATA.TXT` generation
- Parse real INI/DATA files into valid JSON
- Compare against SHAAM spec examples
### โ
Type Safety Tests
- Use `expect-type` to confirm exported types match developer expectations
- All enums (e.g. `DocumentType`, `CurrencyCode`) strictly typed and exported
## ๐งฑ Architecture & File Layout
```
src/
โโโ index.ts // Public API
โโโ types/
โ โโโ input-schema.ts // Zod + TypeScript input
โ โโโ enums.ts // Document types, currencies, countries, etc.
โโโ records/ // Each spec-defined record
โ โโโ C100.ts
โ โโโ D110.ts
โ โโโ ...
โโโ format/
โ โโโ encoder.ts // Fixed-width encoding helpers
โ โโโ decoder.ts // Record parsing
โโโ validation/
โ โโโ validateInput.ts
โ โโโ errors.ts
โโโ utils/
โ โโโ fileHelpers.ts
โ โโโ dateHelpers.ts
โโโ config/
โโโ document-types.ts // Spec appendix values
โโโ currency-codes.ts
```
Each `record/*.ts` module should export:
```ts
export const C100Schema: z.ZodType<C100>
export function encodeC100(input: C100): string
export function parseC100(line: string): C100
```
## ๐ Error Handling
Validation errors will follow this structure:
```ts
interface ValidationError {
recordType: string
recordIndex: number
field: string
message: string
}
```
- If `fail-fast` mode: throw immediately on first error
- If `collect-all`: return all errors in `ReportOutput.summary.errors`
## ๐ง Developer Experience (DX)
- All schemas and enums are exported
- Record types are available via:
```ts
import { DocumentType } from '@your-org/shaam-ufgen'
```
- Types align closely with real business use cases (no cryptic field names)
- Tool is composable โ every record can be encoded/decoded standalone
## ๐ง Future Extensions
- Add support for newer SHAAM versions (e.g. 1.32)
- Allow partial file generation (e.g. just accounts)
- Provide CLI for local testing and report diffing