UNPKG

@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
# ๐Ÿ“˜ 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