@accounter/opcn1214-generator 0.0.0-bootstrap.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bob/cjs/api/generate.d.ts +44 -0
- package/.bob/cjs/api/generate.js +115 -0
- package/.bob/cjs/api/parse.d.ts +28 -0
- package/.bob/cjs/api/parse.js +38 -0
- package/.bob/cjs/api/response.d.ts +24 -0
- package/.bob/cjs/api/response.js +75 -0
- package/.bob/cjs/api/validate.d.ts +16 -0
- package/.bob/cjs/api/validate.js +15 -0
- package/.bob/cjs/codec/boolean.d.ts +7 -0
- package/.bob/cjs/codec/boolean.js +49 -0
- package/.bob/cjs/codec/date.d.ts +6 -0
- package/.bob/cjs/codec/date.js +68 -0
- package/.bob/cjs/codec/enum.d.ts +4 -0
- package/.bob/cjs/codec/enum.js +26 -0
- package/.bob/cjs/codec/numeric.d.ts +56 -0
- package/.bob/cjs/codec/numeric.js +186 -0
- package/.bob/cjs/codec/padding.d.ts +10 -0
- package/.bob/cjs/codec/padding.js +26 -0
- package/.bob/cjs/codec/percent.d.ts +6 -0
- package/.bob/cjs/codec/percent.js +33 -0
- package/.bob/cjs/codec/phone.d.ts +4 -0
- package/.bob/cjs/codec/phone.js +48 -0
- package/.bob/cjs/codec/record.d.ts +18 -0
- package/.bob/cjs/codec/record.js +176 -0
- package/.bob/cjs/codec/registry.d.ts +8 -0
- package/.bob/cjs/codec/registry.js +27 -0
- package/.bob/cjs/codec/sections.d.ts +41 -0
- package/.bob/cjs/codec/sections.js +177 -0
- package/.bob/cjs/codec/text.d.ts +5 -0
- package/.bob/cjs/codec/text.js +29 -0
- package/.bob/cjs/codec/types.d.ts +36 -0
- package/.bob/cjs/codec/types.js +16 -0
- package/.bob/cjs/codec/windows1255.d.ts +9 -0
- package/.bob/cjs/codec/windows1255.js +38 -0
- package/.bob/cjs/errors.d.ts +32 -0
- package/.bob/cjs/errors.js +103 -0
- package/.bob/cjs/file/assemble.d.ts +17 -0
- package/.bob/cjs/file/assemble.js +28 -0
- package/.bob/cjs/file/control.d.ts +13 -0
- package/.bob/cjs/file/control.js +45 -0
- package/.bob/cjs/file/parse.d.ts +18 -0
- package/.bob/cjs/file/parse.js +478 -0
- package/.bob/cjs/file/split.d.ts +17 -0
- package/.bob/cjs/file/split.js +71 -0
- package/.bob/cjs/index.d.ts +16 -0
- package/.bob/cjs/index.js +28 -0
- package/.bob/cjs/layout/2024/layout.generated.d.ts +6919 -0
- package/.bob/cjs/layout/2024/layout.generated.js +7224 -0
- package/.bob/cjs/layout/2025/index.d.ts +6 -0
- package/.bob/cjs/layout/2025/index.js +10 -0
- package/.bob/cjs/layout/capital-gains.d.ts +9 -0
- package/.bob/cjs/layout/capital-gains.js +15 -0
- package/.bob/cjs/layout/countries.d.ts +5 -0
- package/.bob/cjs/layout/countries.js +10 -0
- package/.bob/cjs/layout/freeze.d.ts +5 -0
- package/.bob/cjs/layout/freeze.js +16 -0
- package/.bob/cjs/layout/registry.d.ts +10 -0
- package/.bob/cjs/layout/registry.js +32 -0
- package/.bob/cjs/layout/types.d.ts +82 -0
- package/.bob/cjs/layout/types.js +35 -0
- package/.bob/cjs/model/codes.generated.d.ts +48 -0
- package/.bob/cjs/model/codes.generated.js +628 -0
- package/.bob/cjs/model/index.d.ts +3 -0
- package/.bob/cjs/model/index.js +5 -0
- package/.bob/cjs/model/input.d.ts +543 -0
- package/.bob/cjs/model/input.js +24 -0
- package/.bob/cjs/model/normalized.d.ts +43 -0
- package/.bob/cjs/model/normalized.js +0 -0
- package/.bob/cjs/model/options.d.ts +14 -0
- package/.bob/cjs/model/options.js +0 -0
- package/.bob/cjs/model/schema.d.ts +594 -0
- package/.bob/cjs/model/schema.js +339 -0
- package/.bob/cjs/normalize/canonical.d.ts +13 -0
- package/.bob/cjs/normalize/canonical.js +288 -0
- package/.bob/cjs/normalize/capital-gains/assets.d.ts +37 -0
- package/.bob/cjs/normalize/capital-gains/assets.js +94 -0
- package/.bob/cjs/normalize/capital-gains/index.d.ts +61 -0
- package/.bob/cjs/normalize/capital-gains/index.js +149 -0
- package/.bob/cjs/normalize/capital-gains/no-withholding.d.ts +18 -0
- package/.bob/cjs/normalize/capital-gains/no-withholding.js +36 -0
- package/.bob/cjs/normalize/capital-gains/other.d.ts +54 -0
- package/.bob/cjs/normalize/capital-gains/other.js +122 -0
- package/.bob/cjs/normalize/capital-gains/section6.d.ts +7 -0
- package/.bob/cjs/normalize/capital-gains/section6.js +13 -0
- package/.bob/cjs/normalize/capital-gains/securities.d.ts +26 -0
- package/.bob/cjs/normalize/capital-gains/securities.js +58 -0
- package/.bob/cjs/normalize/denormalize.d.ts +42 -0
- package/.bob/cjs/normalize/denormalize.js +359 -0
- package/.bob/cjs/normalize/derive.d.ts +57 -0
- package/.bob/cjs/normalize/derive.js +111 -0
- package/.bob/cjs/normalize/enums.d.ts +58 -0
- package/.bob/cjs/normalize/enums.js +69 -0
- package/.bob/cjs/normalize/fields.d.ts +28 -0
- package/.bob/cjs/normalize/fields.js +86 -0
- package/.bob/cjs/normalize/foreign.d.ts +22 -0
- package/.bob/cjs/normalize/foreign.js +85 -0
- package/.bob/cjs/normalize/main.d.ts +24 -0
- package/.bob/cjs/normalize/main.js +208 -0
- package/.bob/cjs/normalize/paths.d.ts +74 -0
- package/.bob/cjs/normalize/paths.js +169 -0
- package/.bob/cjs/normalize/phone.d.ts +12 -0
- package/.bob/cjs/normalize/phone.js +35 -0
- package/.bob/cjs/normalize/rd-investments.d.ts +10 -0
- package/.bob/cjs/normalize/rd-investments.js +25 -0
- package/.bob/cjs/normalize/related-companies.d.ts +10 -0
- package/.bob/cjs/normalize/related-companies.js +25 -0
- package/.bob/cjs/normalize/report.d.ts +9 -0
- package/.bob/cjs/normalize/report.js +53 -0
- package/.bob/cjs/normalize/shareholders.d.ts +10 -0
- package/.bob/cjs/normalize/shareholders.js +30 -0
- package/.bob/cjs/normalize/text.d.ts +11 -0
- package/.bob/cjs/normalize/text.js +41 -0
- package/.bob/cjs/normalize/today.d.ts +4 -0
- package/.bob/cjs/normalize/today.js +14 -0
- package/.bob/cjs/pipeline.d.ts +13 -0
- package/.bob/cjs/pipeline.js +37 -0
- package/.bob/cjs/response/codes.d.ts +2 -0
- package/.bob/cjs/response/codes.js +31 -0
- package/.bob/cjs/validate/capital-gains-rules.d.ts +6 -0
- package/.bob/cjs/validate/capital-gains-rules.js +162 -0
- package/.bob/cjs/validate/check-digit.d.ts +10 -0
- package/.bob/cjs/validate/check-digit.js +26 -0
- package/.bob/cjs/validate/engine.d.ts +5 -0
- package/.bob/cjs/validate/engine.js +35 -0
- package/.bob/cjs/validate/field-rules.d.ts +4 -0
- package/.bob/cjs/validate/field-rules.js +331 -0
- package/.bob/cjs/validate/foreign-rules.d.ts +6 -0
- package/.bob/cjs/validate/foreign-rules.js +171 -0
- package/.bob/cjs/validate/issue.d.ts +51 -0
- package/.bob/cjs/validate/issue.js +78 -0
- package/.bob/cjs/validate/main-rules.d.ts +24 -0
- package/.bob/cjs/validate/main-rules.js +425 -0
- package/.bob/cjs/validate/parse-rules.d.ts +31 -0
- package/.bob/cjs/validate/parse-rules.js +114 -0
- package/.bob/cjs/validate/rules.d.ts +746 -0
- package/.bob/cjs/validate/rules.js +680 -0
- package/.bob/cjs/validate/shape.d.ts +19 -0
- package/.bob/cjs/validate/shape.js +231 -0
- package/.bob/cjs/validate/shareholder-rules.d.ts +6 -0
- package/.bob/cjs/validate/shareholder-rules.js +83 -0
- package/.bob/cjs/validate/structure-rules.d.ts +26 -0
- package/.bob/cjs/validate/structure-rules.js +130 -0
- package/.bob/esm/api/generate.d.ts +44 -0
- package/.bob/esm/api/generate.js +111 -0
- package/.bob/esm/api/parse.d.ts +28 -0
- package/.bob/esm/api/parse.js +34 -0
- package/.bob/esm/api/response.d.ts +24 -0
- package/.bob/esm/api/response.js +72 -0
- package/.bob/esm/api/validate.d.ts +16 -0
- package/.bob/esm/api/validate.js +11 -0
- package/.bob/esm/codec/boolean.d.ts +7 -0
- package/.bob/esm/codec/boolean.js +46 -0
- package/.bob/esm/codec/date.d.ts +6 -0
- package/.bob/esm/codec/date.js +64 -0
- package/.bob/esm/codec/enum.d.ts +4 -0
- package/.bob/esm/codec/enum.js +23 -0
- package/.bob/esm/codec/numeric.d.ts +56 -0
- package/.bob/esm/codec/numeric.js +175 -0
- package/.bob/esm/codec/padding.d.ts +10 -0
- package/.bob/esm/codec/padding.js +21 -0
- package/.bob/esm/codec/percent.d.ts +6 -0
- package/.bob/esm/codec/percent.js +30 -0
- package/.bob/esm/codec/phone.d.ts +4 -0
- package/.bob/esm/codec/phone.js +45 -0
- package/.bob/esm/codec/record.d.ts +18 -0
- package/.bob/esm/codec/record.js +172 -0
- package/.bob/esm/codec/registry.d.ts +8 -0
- package/.bob/esm/codec/registry.js +23 -0
- package/.bob/esm/codec/sections.d.ts +41 -0
- package/.bob/esm/codec/sections.js +170 -0
- package/.bob/esm/codec/text.d.ts +5 -0
- package/.bob/esm/codec/text.js +26 -0
- package/.bob/esm/codec/types.d.ts +36 -0
- package/.bob/esm/codec/types.js +12 -0
- package/.bob/esm/codec/windows1255.d.ts +9 -0
- package/.bob/esm/codec/windows1255.js +32 -0
- package/.bob/esm/errors.d.ts +32 -0
- package/.bob/esm/errors.js +94 -0
- package/.bob/esm/file/assemble.d.ts +17 -0
- package/.bob/esm/file/assemble.js +25 -0
- package/.bob/esm/file/control.d.ts +13 -0
- package/.bob/esm/file/control.js +41 -0
- package/.bob/esm/file/parse.d.ts +18 -0
- package/.bob/esm/file/parse.js +474 -0
- package/.bob/esm/file/split.d.ts +17 -0
- package/.bob/esm/file/split.js +68 -0
- package/.bob/esm/index.d.ts +16 -0
- package/.bob/esm/index.js +11 -0
- package/.bob/esm/layout/2024/layout.generated.d.ts +6919 -0
- package/.bob/esm/layout/2024/layout.generated.js +7221 -0
- package/.bob/esm/layout/2025/index.d.ts +6 -0
- package/.bob/esm/layout/2025/index.js +7 -0
- package/.bob/esm/layout/capital-gains.d.ts +9 -0
- package/.bob/esm/layout/capital-gains.js +11 -0
- package/.bob/esm/layout/countries.d.ts +5 -0
- package/.bob/esm/layout/countries.js +7 -0
- package/.bob/esm/layout/freeze.d.ts +5 -0
- package/.bob/esm/layout/freeze.js +13 -0
- package/.bob/esm/layout/registry.d.ts +10 -0
- package/.bob/esm/layout/registry.js +27 -0
- package/.bob/esm/layout/types.d.ts +82 -0
- package/.bob/esm/layout/types.js +32 -0
- package/.bob/esm/model/codes.generated.d.ts +48 -0
- package/.bob/esm/model/codes.generated.js +625 -0
- package/.bob/esm/model/index.d.ts +3 -0
- package/.bob/esm/model/index.js +2 -0
- package/.bob/esm/model/input.d.ts +543 -0
- package/.bob/esm/model/input.js +21 -0
- package/.bob/esm/model/normalized.d.ts +43 -0
- package/.bob/esm/model/normalized.js +0 -0
- package/.bob/esm/model/options.d.ts +14 -0
- package/.bob/esm/model/options.js +0 -0
- package/.bob/esm/model/schema.d.ts +594 -0
- package/.bob/esm/model/schema.js +335 -0
- package/.bob/esm/normalize/canonical.d.ts +13 -0
- package/.bob/esm/normalize/canonical.js +285 -0
- package/.bob/esm/normalize/capital-gains/assets.d.ts +37 -0
- package/.bob/esm/normalize/capital-gains/assets.js +87 -0
- package/.bob/esm/normalize/capital-gains/index.d.ts +61 -0
- package/.bob/esm/normalize/capital-gains/index.js +142 -0
- package/.bob/esm/normalize/capital-gains/no-withholding.d.ts +18 -0
- package/.bob/esm/normalize/capital-gains/no-withholding.js +31 -0
- package/.bob/esm/normalize/capital-gains/other.d.ts +54 -0
- package/.bob/esm/normalize/capital-gains/other.js +112 -0
- package/.bob/esm/normalize/capital-gains/section6.d.ts +7 -0
- package/.bob/esm/normalize/capital-gains/section6.js +9 -0
- package/.bob/esm/normalize/capital-gains/securities.d.ts +26 -0
- package/.bob/esm/normalize/capital-gains/securities.js +52 -0
- package/.bob/esm/normalize/denormalize.d.ts +42 -0
- package/.bob/esm/normalize/denormalize.js +354 -0
- package/.bob/esm/normalize/derive.d.ts +57 -0
- package/.bob/esm/normalize/derive.js +99 -0
- package/.bob/esm/normalize/enums.d.ts +58 -0
- package/.bob/esm/normalize/enums.js +64 -0
- package/.bob/esm/normalize/fields.d.ts +28 -0
- package/.bob/esm/normalize/fields.js +81 -0
- package/.bob/esm/normalize/foreign.d.ts +22 -0
- package/.bob/esm/normalize/foreign.js +81 -0
- package/.bob/esm/normalize/main.d.ts +24 -0
- package/.bob/esm/normalize/main.js +204 -0
- package/.bob/esm/normalize/paths.d.ts +74 -0
- package/.bob/esm/normalize/paths.js +161 -0
- package/.bob/esm/normalize/phone.d.ts +12 -0
- package/.bob/esm/normalize/phone.js +32 -0
- package/.bob/esm/normalize/rd-investments.d.ts +10 -0
- package/.bob/esm/normalize/rd-investments.js +22 -0
- package/.bob/esm/normalize/related-companies.d.ts +10 -0
- package/.bob/esm/normalize/related-companies.js +22 -0
- package/.bob/esm/normalize/report.d.ts +9 -0
- package/.bob/esm/normalize/report.js +50 -0
- package/.bob/esm/normalize/shareholders.d.ts +10 -0
- package/.bob/esm/normalize/shareholders.js +27 -0
- package/.bob/esm/normalize/text.d.ts +11 -0
- package/.bob/esm/normalize/text.js +37 -0
- package/.bob/esm/normalize/today.d.ts +4 -0
- package/.bob/esm/normalize/today.js +11 -0
- package/.bob/esm/pipeline.d.ts +13 -0
- package/.bob/esm/pipeline.js +34 -0
- package/.bob/esm/response/codes.d.ts +2 -0
- package/.bob/esm/response/codes.js +28 -0
- package/.bob/esm/validate/capital-gains-rules.d.ts +6 -0
- package/.bob/esm/validate/capital-gains-rules.js +159 -0
- package/.bob/esm/validate/check-digit.d.ts +10 -0
- package/.bob/esm/validate/check-digit.js +23 -0
- package/.bob/esm/validate/engine.d.ts +5 -0
- package/.bob/esm/validate/engine.js +32 -0
- package/.bob/esm/validate/field-rules.d.ts +4 -0
- package/.bob/esm/validate/field-rules.js +328 -0
- package/.bob/esm/validate/foreign-rules.d.ts +6 -0
- package/.bob/esm/validate/foreign-rules.js +168 -0
- package/.bob/esm/validate/issue.d.ts +51 -0
- package/.bob/esm/validate/issue.js +72 -0
- package/.bob/esm/validate/main-rules.d.ts +24 -0
- package/.bob/esm/validate/main-rules.js +420 -0
- package/.bob/esm/validate/parse-rules.d.ts +31 -0
- package/.bob/esm/validate/parse-rules.js +110 -0
- package/.bob/esm/validate/rules.d.ts +746 -0
- package/.bob/esm/validate/rules.js +676 -0
- package/.bob/esm/validate/shape.d.ts +19 -0
- package/.bob/esm/validate/shape.js +227 -0
- package/.bob/esm/validate/shareholder-rules.d.ts +6 -0
- package/.bob/esm/validate/shareholder-rules.js +80 -0
- package/.bob/esm/validate/structure-rules.d.ts +26 -0
- package/.bob/esm/validate/structure-rules.js +122 -0
- package/.bob/tsconfig.tsbuildinfo +1 -0
- package/.gitattributes +1 -0
- package/CLAUDE.md +39 -0
- package/README.md +337 -0
- package/dist/cjs/index.js +28 -0
- package/dist/esm/index.js +11 -0
- package/documentation/IMPLEMENTATION_PLAN.md +2258 -0
- package/documentation/SPEC.md +1803 -0
- package/documentation/layout/2024/codes.csv +261 -0
- package/documentation/layout/2024/countries.csv +256 -0
- package/documentation/layout/2024/fields.csv +271 -0
- package/documentation/layout/2024/records.csv +18 -0
- package/documentation/layout/README.md +87 -0
- package/documentation/specifications/1214-2024.pdf +0 -0
- package/documentation/tools/extract_layout.py +191 -0
- package/package.json +77 -0
- package/scripts/generate-layout.ts +23 -0
- package/scripts/layout/csv.ts +111 -0
- package/scripts/layout/derived-codes.ts +12 -0
- package/scripts/layout/render.ts +364 -0
- package/scripts/layout/sources.ts +51 -0
- package/scripts/layout/values.ts +42 -0
- package/scripts/render-rules-table.ts +66 -0
- package/src/api/generate.ts +169 -0
- package/src/api/parse.ts +58 -0
- package/src/api/response.ts +110 -0
- package/src/api/validate.ts +26 -0
- package/src/codec/boolean.ts +62 -0
- package/src/codec/date.ts +75 -0
- package/src/codec/enum.ts +28 -0
- package/src/codec/numeric.ts +208 -0
- package/src/codec/padding.ts +33 -0
- package/src/codec/percent.ts +35 -0
- package/src/codec/phone.ts +54 -0
- package/src/codec/record.ts +206 -0
- package/src/codec/registry.ts +27 -0
- package/src/codec/sections.ts +208 -0
- package/src/codec/text.ts +31 -0
- package/src/codec/types.ts +47 -0
- package/src/codec/windows1255.ts +38 -0
- package/src/errors.ts +114 -0
- package/src/file/assemble.ts +42 -0
- package/src/file/control.ts +59 -0
- package/src/file/parse.ts +620 -0
- package/src/file/split.ts +86 -0
- package/src/index.ts +70 -0
- package/src/layout/2024/layout.generated.ts +7238 -0
- package/src/layout/2025/index.ts +9 -0
- package/src/layout/capital-gains.ts +20 -0
- package/src/layout/countries.ts +7 -0
- package/src/layout/freeze.ts +13 -0
- package/src/layout/registry.ts +33 -0
- package/src/layout/types.ts +134 -0
- package/src/model/codes.generated.ts +1190 -0
- package/src/model/index.ts +4 -0
- package/src/model/input.ts +594 -0
- package/src/model/normalized.ts +38 -0
- package/src/model/options.ts +17 -0
- package/src/model/schema.ts +381 -0
- package/src/normalize/canonical.ts +374 -0
- package/src/normalize/capital-gains/assets.ts +112 -0
- package/src/normalize/capital-gains/index.ts +212 -0
- package/src/normalize/capital-gains/no-withholding.ts +46 -0
- package/src/normalize/capital-gains/other.ts +153 -0
- package/src/normalize/capital-gains/section6.ts +14 -0
- package/src/normalize/capital-gains/securities.ts +73 -0
- package/src/normalize/denormalize.ts +426 -0
- package/src/normalize/derive.ts +136 -0
- package/src/normalize/enums.ts +87 -0
- package/src/normalize/fields.ts +110 -0
- package/src/normalize/foreign.ts +114 -0
- package/src/normalize/main.ts +284 -0
- package/src/normalize/paths.ts +184 -0
- package/src/normalize/phone.ts +45 -0
- package/src/normalize/rd-investments.ts +38 -0
- package/src/normalize/related-companies.ts +37 -0
- package/src/normalize/report.ts +59 -0
- package/src/normalize/shareholders.ts +42 -0
- package/src/normalize/text.ts +40 -0
- package/src/normalize/today.ts +15 -0
- package/src/pipeline.ts +42 -0
- package/src/response/codes.ts +30 -0
- package/src/validate/capital-gains-rules.ts +199 -0
- package/src/validate/check-digit.ts +25 -0
- package/src/validate/engine.ts +45 -0
- package/src/validate/field-rules.ts +383 -0
- package/src/validate/foreign-rules.ts +274 -0
- package/src/validate/issue.ts +121 -0
- package/src/validate/main-rules.ts +678 -0
- package/src/validate/parse-rules.ts +169 -0
- package/src/validate/rules.ts +747 -0
- package/src/validate/shape.ts +278 -0
- package/src/validate/shareholder-rules.ts +92 -0
- package/src/validate/structure-rules.ts +136 -0
- package/tests/api/batch.test.ts +227 -0
- package/tests/api/exports.test.ts +355 -0
- package/tests/api/generate.test.ts +409 -0
- package/tests/api/parse.test.ts +789 -0
- package/tests/api/response.test.ts +152 -0
- package/tests/api/validate.test.ts +86 -0
- package/tests/codec/numeric.test.ts +325 -0
- package/tests/codec/record.test.ts +318 -0
- package/tests/codec/registry.test.ts +17 -0
- package/tests/codec/sections.test.ts +333 -0
- package/tests/codec/text.test.ts +454 -0
- package/tests/codec/windows1255.test.ts +46 -0
- package/tests/docs/readme.test.ts +69 -0
- package/tests/edge-cases.test.ts +359 -0
- package/tests/errors.test.ts +138 -0
- package/tests/file/assemble.test.ts +188 -0
- package/tests/file/split.test.ts +61 -0
- package/tests/fixtures/builders.ts +512 -0
- package/tests/fixtures/files.ts +78 -0
- package/tests/fixtures/golden/README.md +37 -0
- package/tests/fixtures/golden/VERIFICATION.md +72 -0
- package/tests/fixtures/golden/batch-50.input.ts +92 -0
- package/tests/fixtures/golden/batch-50.opcn +150 -0
- package/tests/fixtures/golden/capital-gains-max.input.ts +177 -0
- package/tests/fixtures/golden/capital-gains-max.opcn +17 -0
- package/tests/fixtures/golden/cg-27.input.ts +63 -0
- package/tests/fixtures/golden/cg-27.opcn +4 -0
- package/tests/fixtures/golden/cg-50.input.ts +59 -0
- package/tests/fixtures/golden/cg-50.opcn +4 -0
- package/tests/fixtures/golden/cg-51.input.ts +60 -0
- package/tests/fixtures/golden/cg-51.opcn +4 -0
- package/tests/fixtures/golden/cg-54.input.ts +53 -0
- package/tests/fixtures/golden/cg-54.opcn +4 -0
- package/tests/fixtures/golden/cg-60.input.ts +77 -0
- package/tests/fixtures/golden/cg-60.opcn +4 -0
- package/tests/fixtures/golden/cg-63.input.ts +51 -0
- package/tests/fixtures/golden/cg-63.opcn +4 -0
- package/tests/fixtures/golden/cg-64.input.ts +62 -0
- package/tests/fixtures/golden/cg-64.opcn +4 -0
- package/tests/fixtures/golden/cg-65.input.ts +79 -0
- package/tests/fixtures/golden/cg-65.opcn +4 -0
- package/tests/fixtures/golden/cg-66.input.ts +53 -0
- package/tests/fixtures/golden/cg-66.opcn +4 -0
- package/tests/fixtures/golden/cg-77.input.ts +109 -0
- package/tests/fixtures/golden/cg-77.opcn +4 -0
- package/tests/fixtures/golden/foreign.input.ts +202 -0
- package/tests/fixtures/golden/foreign.opcn +27 -0
- package/tests/fixtures/golden/hebrew-edge.input.ts +90 -0
- package/tests/fixtures/golden/hebrew-edge.opcn +8 -0
- package/tests/fixtures/golden/kibbutz.input.ts +31 -0
- package/tests/fixtures/golden/kibbutz.opcn +2 -0
- package/tests/fixtures/golden/main-full.input.ts +780 -0
- package/tests/fixtures/golden/main-full.opcn +101 -0
- package/tests/fixtures/golden/minimal.input.ts +37 -0
- package/tests/fixtures/golden/minimal.opcn +3 -0
- package/tests/fixtures/golden/related-and-rd.input.ts +59 -0
- package/tests/fixtures/golden/related-and-rd.opcn +11 -0
- package/tests/fixtures/random.ts +843 -0
- package/tests/golden/fixtures.test.ts +627 -0
- package/tests/golden/golden.test.ts +95 -0
- package/tests/helpers/coverage.ts +18 -0
- package/tests/helpers/sample-values.ts +114 -0
- package/tests/layout/codegen-sync.test.ts +19 -0
- package/tests/layout/integrity.test.ts +232 -0
- package/tests/layout/registry.test.ts +98 -0
- package/tests/model/code-unions.test.ts +91 -0
- package/tests/model/schema.test.ts +1031 -0
- package/tests/normalize/canonical.test.ts +728 -0
- package/tests/normalize/capital-gains.test.ts +1850 -0
- package/tests/normalize/coverage.test.ts +88 -0
- package/tests/normalize/denormalize.test.ts +318 -0
- package/tests/normalize/enums.test.ts +118 -0
- package/tests/normalize/foreign.test.ts +273 -0
- package/tests/normalize/main.test.ts +839 -0
- package/tests/normalize/paths.test.ts +257 -0
- package/tests/normalize/rd-investments.test.ts +99 -0
- package/tests/normalize/related-companies.test.ts +106 -0
- package/tests/normalize/shareholders.test.ts +117 -0
- package/tests/normalize/text.test.ts +86 -0
- package/tests/pipeline.test.ts +96 -0
- package/tests/roundtrip/determinism.test.ts +207 -0
- package/tests/roundtrip/property.test.ts +126 -0
- package/tests/roundtrip/roundtrip.test.ts +573 -0
- package/tests/rules/cases.ts +873 -0
- package/tests/rules/rules.test.ts +69 -0
- package/tests/rules/spec-sync.test.ts +80 -0
- package/tests/scripts/csv.test.ts +78 -0
- package/tests/scripts/values.test.ts +80 -0
- package/tests/validate/capital-gains-rules.test.ts +307 -0
- package/tests/validate/check-digit.test.ts +42 -0
- package/tests/validate/field-rules.test.ts +867 -0
- package/tests/validate/foreign-rules.test.ts +255 -0
- package/tests/validate/issue.test.ts +96 -0
- package/tests/validate/main-rules.test.ts +761 -0
- package/tests/validate/parse-rules.test.ts +293 -0
- package/tests/validate/shareholder-rules.test.ts +143 -0
- package/tsconfig.json +10 -0
- package/tsconfig.typecheck.json +9 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { format, resolveConfig } from 'prettier';
|
|
4
|
+
import { RULES } from '../src/validate/rules.js';
|
|
5
|
+
|
|
6
|
+
/** The README holds the rendered table between these markers. */
|
|
7
|
+
export const RULES_START = '<!-- rules:start -->';
|
|
8
|
+
export const RULES_END = '<!-- rules:end -->';
|
|
9
|
+
|
|
10
|
+
export const README_URL = new URL('../README.md', import.meta.url);
|
|
11
|
+
|
|
12
|
+
const SEVERITY = { error: 'E', warning: 'W' } as const;
|
|
13
|
+
|
|
14
|
+
/** One markdown table cell: pipes escaped, whitespace collapsed. */
|
|
15
|
+
function cell(text: string): string {
|
|
16
|
+
return text
|
|
17
|
+
.replaceAll(/\s+/g, ' ')
|
|
18
|
+
.trim()
|
|
19
|
+
.replaceAll('|', String.raw`\|`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The rule catalogue (RULES, SPEC §10) as a markdown table, formatted with the repository's
|
|
24
|
+
* prettier configuration for the README, so `yarn prettier --check` keeps it unchanged.
|
|
25
|
+
*/
|
|
26
|
+
export async function renderRulesTable(): Promise<string> {
|
|
27
|
+
const rows = [
|
|
28
|
+
'| Rule ID | Sev | Source | Scope | Description |',
|
|
29
|
+
'| --- | --- | --- | --- | --- |',
|
|
30
|
+
...RULES.map(
|
|
31
|
+
rule =>
|
|
32
|
+
`| \`${rule.id}\` | ${SEVERITY[rule.severity]} | ${rule.source} | ${rule.scope} | ${cell(rule.description)} |`,
|
|
33
|
+
),
|
|
34
|
+
];
|
|
35
|
+
const filepath = fileURLToPath(README_URL);
|
|
36
|
+
const options = await resolveConfig(filepath);
|
|
37
|
+
return format(`${rows.join('\n')}\n`, { ...options, filepath });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The text between the README markers (exclusive), or undefined when a marker is missing. */
|
|
41
|
+
export function readmeRulesSection(readme: string): string | undefined {
|
|
42
|
+
const start = readme.indexOf(RULES_START);
|
|
43
|
+
const end = readme.indexOf(RULES_END);
|
|
44
|
+
if (start === -1 || end < start) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return readme.slice(start + RULES_START.length, end);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** `readme` with the rendered `table` between the markers. */
|
|
51
|
+
export function withRulesTable(readme: string, table: string): string {
|
|
52
|
+
const start = readme.indexOf(RULES_START);
|
|
53
|
+
const end = readme.indexOf(RULES_END);
|
|
54
|
+
if (start === -1 || end < start) {
|
|
55
|
+
throw new Error(`README.md must contain ${RULES_START} followed by ${RULES_END}`);
|
|
56
|
+
}
|
|
57
|
+
return `${readme.slice(0, start + RULES_START.length)}\n\n${table}\n${readme.slice(end)}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Run as a script (`yarn workspace @accounter/opcn1214-generator render:rules`): rewrites the rule
|
|
61
|
+
// table of README.md from RULES.
|
|
62
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
63
|
+
const readme = readFileSync(README_URL, 'utf8');
|
|
64
|
+
writeFileSync(README_URL, withRulesTable(readme, await renderRulesTable()));
|
|
65
|
+
console.log(`updated the rule table in ${README_URL.pathname}`);
|
|
66
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/** generate1214 and generate1214Batch (SPEC §6.1, §8.1): validation, then the file. */
|
|
2
|
+
import { Opcn1214InternalError, Opcn1214ValidationError } from '../errors.js';
|
|
3
|
+
import { renderReport, type RenderedReport } from '../file/assemble.js';
|
|
4
|
+
import { REPORTS_PER_FILE } from '../layout/registry.js';
|
|
5
|
+
import type { RecordType } from '../layout/types.js';
|
|
6
|
+
import type { Report1214Input } from '../model/input.js';
|
|
7
|
+
import type { NormalizedReport } from '../model/normalized.js';
|
|
8
|
+
import type { GenerateOptions } from '../model/options.js';
|
|
9
|
+
import { runPipeline } from '../pipeline.js';
|
|
10
|
+
import { compareIssues, makeIssue, type Issue } from '../validate/issue.js';
|
|
11
|
+
import { splitIssues } from './validate.js';
|
|
12
|
+
|
|
13
|
+
/** The outcome of generate1214 (SPEC §6.2). */
|
|
14
|
+
export interface GenerateResult {
|
|
15
|
+
/** The file as a JS string (CRLF line endings). */
|
|
16
|
+
text: string;
|
|
17
|
+
/** windows-1255: the artifact to upload. */
|
|
18
|
+
bytes: Uint8Array;
|
|
19
|
+
/**
|
|
20
|
+
* Suggestion: `1214_<fileNumber>_<taxYear>.txt`, with the 9-digit file number as written; for a
|
|
21
|
+
* batch, `1214_batch_<n>.txt`.
|
|
22
|
+
*/
|
|
23
|
+
fileName: string;
|
|
24
|
+
/** Warnings of the report (of every report of a batch, each with its `reportIndex`). */
|
|
25
|
+
warnings: Issue[];
|
|
26
|
+
summary: {
|
|
27
|
+
reports: number;
|
|
28
|
+
/** Records per type, 9999 included (summed over the reports of a batch). */
|
|
29
|
+
records: Partial<Record<RecordType, number>>;
|
|
30
|
+
/** Code-amount pairs written in record 1000 (of 61); for a batch, the most of any report. */
|
|
31
|
+
mainCodePairs: number;
|
|
32
|
+
/** Zero values left out of the file (SPEC §4.5); `reportIndex` in a batch only. */
|
|
33
|
+
omittedZeroCodes: Array<{
|
|
34
|
+
record: RecordType;
|
|
35
|
+
recordIndex: number;
|
|
36
|
+
code: string;
|
|
37
|
+
reportIndex?: number;
|
|
38
|
+
}>;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const FILE_NUMBER_KEY = 'company.fileNumber';
|
|
43
|
+
|
|
44
|
+
/** The file number exactly as `mainLine` (the encoded 1000 record) holds it. */
|
|
45
|
+
function writtenFileNumber(report: NormalizedReport, mainLine: string): string {
|
|
46
|
+
const field = report.layout.records['1000'].fields.find(def => def.key === FILE_NUMBER_KEY);
|
|
47
|
+
if (!field) {
|
|
48
|
+
throw new Opcn1214InternalError(`Record 1000 has no ${FILE_NUMBER_KEY} field`);
|
|
49
|
+
}
|
|
50
|
+
return mainLine.slice(field.position - 1, field.position - 1 + field.length);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function countRecords(
|
|
54
|
+
report: NormalizedReport,
|
|
55
|
+
records: Partial<Record<RecordType, number>> = {},
|
|
56
|
+
): Partial<Record<RecordType, number>> {
|
|
57
|
+
for (const recordType of [...report.records.map(record => record.recordType), '9999' as const]) {
|
|
58
|
+
records[recordType] = (records[recordType] ?? 0) + 1;
|
|
59
|
+
}
|
|
60
|
+
return records;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A validated report and its file content. */
|
|
64
|
+
interface GeneratedReport {
|
|
65
|
+
report: NormalizedReport;
|
|
66
|
+
rendered: RenderedReport;
|
|
67
|
+
/** Code-amount pairs of record 1000. */
|
|
68
|
+
mainCodePairs: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Renders a report that has no errors. Throws Opcn1214InternalError when it has no record 1000.
|
|
73
|
+
*/
|
|
74
|
+
function generateValid(report: NormalizedReport): GeneratedReport {
|
|
75
|
+
const rendered = renderReport(report);
|
|
76
|
+
const main = report.records.find(record => record.recordType === '1000');
|
|
77
|
+
if (!main || rendered.lines[0] === undefined) {
|
|
78
|
+
throw new Opcn1214InternalError('A valid report has no record 1000');
|
|
79
|
+
}
|
|
80
|
+
return { report, rendered, mainCodePairs: main.codes.size };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Validates, then generates. Throws Opcn1214ValidationError carrying every error and warning
|
|
85
|
+
* (errors first) if any error-severity issue exists.
|
|
86
|
+
*/
|
|
87
|
+
export function generate1214(input: Report1214Input, options?: GenerateOptions): GenerateResult {
|
|
88
|
+
const { report, issues } = runPipeline(input, options);
|
|
89
|
+
const { errors, warnings } = splitIssues(issues);
|
|
90
|
+
if (errors.length > 0 || !report) {
|
|
91
|
+
throw new Opcn1214ValidationError([...errors, ...warnings]);
|
|
92
|
+
}
|
|
93
|
+
const { rendered, mainCodePairs } = generateValid(report);
|
|
94
|
+
return {
|
|
95
|
+
text: rendered.text,
|
|
96
|
+
bytes: rendered.bytes,
|
|
97
|
+
fileName: `1214_${writtenFileNumber(report, rendered.lines[0] ?? '')}_${report.taxYear}.txt`,
|
|
98
|
+
warnings,
|
|
99
|
+
summary: {
|
|
100
|
+
reports: 1,
|
|
101
|
+
records: countRecords(report),
|
|
102
|
+
mainCodePairs,
|
|
103
|
+
omittedZeroCodes: report.omittedZeroCodes.map(entry => ({ ...entry })),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function concatBytes(parts: readonly Uint8Array[]): Uint8Array {
|
|
109
|
+
const bytes = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
110
|
+
let offset = 0;
|
|
111
|
+
for (const part of parts) {
|
|
112
|
+
bytes.set(part, offset);
|
|
113
|
+
offset += part.length;
|
|
114
|
+
}
|
|
115
|
+
return bytes;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* OPCN batch (SPEC §3.1, §8.1): validates each report independently, then writes the reports in
|
|
120
|
+
* input order, each with its own 9999 record. Issues carry the 0-based `reportIndex` of their
|
|
121
|
+
* report. Throws Opcn1214ValidationError carrying struct.batch.size for 0 or more than 50 reports,
|
|
122
|
+
* or every error and warning of every report (errors first) if any report has an error.
|
|
123
|
+
*/
|
|
124
|
+
export function generate1214Batch(
|
|
125
|
+
inputs: readonly Report1214Input[],
|
|
126
|
+
options?: GenerateOptions,
|
|
127
|
+
): GenerateResult {
|
|
128
|
+
if (inputs.length === 0 || inputs.length > REPORTS_PER_FILE) {
|
|
129
|
+
throw new Opcn1214ValidationError([
|
|
130
|
+
makeIssue('struct.batch.size', {
|
|
131
|
+
message: `A batch holds 1 to ${REPORTS_PER_FILE} reports, not ${inputs.length}.`,
|
|
132
|
+
path: '',
|
|
133
|
+
value: inputs.length,
|
|
134
|
+
expected: `1 to ${REPORTS_PER_FILE}`,
|
|
135
|
+
specRef: { page: 1 },
|
|
136
|
+
}),
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
const validated = inputs.map((input, reportIndex) => {
|
|
140
|
+
const { report, issues } = runPipeline(input, options);
|
|
141
|
+
return { report, issues: issues.map(issue => ({ ...issue, reportIndex })) };
|
|
142
|
+
});
|
|
143
|
+
const { errors, warnings } = splitIssues(
|
|
144
|
+
validated.flatMap(({ issues }) => issues).sort(compareIssues),
|
|
145
|
+
);
|
|
146
|
+
const reports = validated.map(({ report }) => report);
|
|
147
|
+
if (errors.length > 0 || !reports.every(report => report !== undefined)) {
|
|
148
|
+
throw new Opcn1214ValidationError([...errors, ...warnings]);
|
|
149
|
+
}
|
|
150
|
+
const generated = reports.map(generateValid);
|
|
151
|
+
const records: Partial<Record<RecordType, number>> = {};
|
|
152
|
+
for (const { report } of generated) {
|
|
153
|
+
countRecords(report, records);
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
text: generated.map(({ rendered }) => rendered.text).join(''),
|
|
157
|
+
bytes: concatBytes(generated.map(({ rendered }) => rendered.bytes)),
|
|
158
|
+
fileName: `1214_batch_${generated.length}.txt`,
|
|
159
|
+
warnings,
|
|
160
|
+
summary: {
|
|
161
|
+
reports: generated.length,
|
|
162
|
+
records,
|
|
163
|
+
mainCodePairs: Math.max(...generated.map(({ mainCodePairs }) => mainCodePairs)),
|
|
164
|
+
omittedZeroCodes: generated.flatMap(({ report }, reportIndex) =>
|
|
165
|
+
report.omittedZeroCodes.map(entry => ({ ...entry, reportIndex })),
|
|
166
|
+
),
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
package/src/api/parse.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** parse1214 and parse1214Batch (SPEC §6.1, §8.2): files back to the public input. */
|
|
2
|
+
import { parseBatchLines, parseLines } from '../file/parse.js';
|
|
3
|
+
import { splitFile } from '../file/split.js';
|
|
4
|
+
import type { IsoDate, Report1214Input } from '../model/input.js';
|
|
5
|
+
import type { NormalizedReport } from '../model/normalized.js';
|
|
6
|
+
import type { ParseOptions } from '../model/options.js';
|
|
7
|
+
import { denormalize } from '../normalize/denormalize.js';
|
|
8
|
+
import { runRules } from '../validate/engine.js';
|
|
9
|
+
import type { Issue } from '../validate/issue.js';
|
|
10
|
+
|
|
11
|
+
/** The outcome of parse1214 (SPEC §6.2). */
|
|
12
|
+
export interface ParseResult {
|
|
13
|
+
/** Canonical form (SPEC §8.4). */
|
|
14
|
+
report: Report1214Input;
|
|
15
|
+
/** Validation of the parsed content (errors and warnings), sorted (SPEC §9.1). */
|
|
16
|
+
issues: Issue[];
|
|
17
|
+
/** From 1000@165; '' when the file has none (field.required is then in `issues`). */
|
|
18
|
+
saveDate: IsoDate;
|
|
19
|
+
/** From 1000@150; '' when the file has none (field.required is then in `issues`). */
|
|
20
|
+
softwareName: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The ParseResult of a parsed report; its issues carry `reportIndex` when one is given. */
|
|
24
|
+
function parseResult(normalized: NormalizedReport, reportIndex?: number): ParseResult {
|
|
25
|
+
const report = denormalize(normalized);
|
|
26
|
+
const issues = runRules(normalized);
|
|
27
|
+
return {
|
|
28
|
+
report,
|
|
29
|
+
issues: reportIndex === undefined ? issues : issues.map(issue => ({ ...issue, reportIndex })),
|
|
30
|
+
saveDate: report.meta?.saveDate ?? '',
|
|
31
|
+
softwareName: report.meta?.softwareName ?? '',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Parses a single-report file. Business-rule issues of the parsed content are returned as
|
|
37
|
+
* `issues`, not thrown. Structural problems (SPEC §8.2 steps 1–6, an unsupported tax year
|
|
38
|
+
* included) throw Opcn1214ParseError carrying every problem of the file; so does a file with more
|
|
39
|
+
* than one report (parse.multipleReports).
|
|
40
|
+
*/
|
|
41
|
+
export function parse1214(content: string | Uint8Array, options?: ParseOptions): ParseResult {
|
|
42
|
+
return parseResult(parseLines(splitFile(content, options)));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Parses an OPCN batch file (1–50 reports, SPEC §3.1): one ParseResult per report, in file order,
|
|
47
|
+
* each with the issues of its report carrying its `reportIndex`. Structural problems of any report
|
|
48
|
+
* throw Opcn1214ParseError carrying every problem of the file, each with its file line and
|
|
49
|
+
* `reportIndex`.
|
|
50
|
+
*/
|
|
51
|
+
export function parse1214Batch(
|
|
52
|
+
content: string | Uint8Array,
|
|
53
|
+
options?: ParseOptions,
|
|
54
|
+
): ParseResult[] {
|
|
55
|
+
return parseBatchLines(splitFile(content, options)).map((report, reportIndex) =>
|
|
56
|
+
parseResult(report, reportIndex),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** parseResponseFile (SPEC §6.1): SHAAM's response file shumot.shg (SPEC §3.9). */
|
|
2
|
+
import { Opcn1214ParseError } from '../errors.js';
|
|
3
|
+
import { splitFile } from '../file/split.js';
|
|
4
|
+
import { responseMeaning } from '../response/codes.js';
|
|
5
|
+
import type { Issue } from '../validate/issue.js';
|
|
6
|
+
import { parseIssue } from '../validate/parse-rules.js';
|
|
7
|
+
|
|
8
|
+
/** One line of a response file (SPEC §6.2). */
|
|
9
|
+
export interface ResponseRecord {
|
|
10
|
+
/** 9 digits, as written in the file. */
|
|
11
|
+
fileNumber: string;
|
|
12
|
+
taxYear: number;
|
|
13
|
+
/** The 2-character response code: '00', '05', … */
|
|
14
|
+
code: string;
|
|
15
|
+
/** English text from SPEC §3.9; 'General error; notify SHAAM' for an unlisted code. */
|
|
16
|
+
meaning: string;
|
|
17
|
+
/** code === '00' */
|
|
18
|
+
accepted: boolean;
|
|
19
|
+
/** Trailing text after the code (codes 08 / 33), trailing spaces trimmed; absent when empty. */
|
|
20
|
+
detail?: string;
|
|
21
|
+
/** 1-based line number in the file. */
|
|
22
|
+
line: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Field positions of a response line (SPEC §3.9), as 0-based offsets. */
|
|
26
|
+
const FILE_NUMBER = { start: 0, end: 9 } as const;
|
|
27
|
+
const TAX_YEAR = { start: 9, end: 13 } as const;
|
|
28
|
+
const CODE = { start: 13, end: 15 } as const;
|
|
29
|
+
const NON_DIGIT = /\D/;
|
|
30
|
+
const BLANK = /^\s*$/;
|
|
31
|
+
|
|
32
|
+
/** The parse.numeric issue of a field of `text` holding a non-digit; undefined when it has none. */
|
|
33
|
+
function numericIssue(
|
|
34
|
+
text: string,
|
|
35
|
+
lineNumber: number,
|
|
36
|
+
field: { start: number; end: number },
|
|
37
|
+
name: string,
|
|
38
|
+
): Issue | undefined {
|
|
39
|
+
const value = text.slice(field.start, field.end);
|
|
40
|
+
const offset = value.search(NON_DIGIT);
|
|
41
|
+
if (offset === -1) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return parseIssue(
|
|
45
|
+
'parse.numeric',
|
|
46
|
+
`${name} "${value}" is not a number.`,
|
|
47
|
+
{ line: lineNumber, column: field.start + offset + 1 },
|
|
48
|
+
{ value },
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The structural problems of a non-blank response line, by column. */
|
|
53
|
+
function lineIssues(text: string, lineNumber: number): Issue[] {
|
|
54
|
+
const issues = [
|
|
55
|
+
numericIssue(text, lineNumber, FILE_NUMBER, 'File number'),
|
|
56
|
+
numericIssue(text, lineNumber, TAX_YEAR, 'Tax year'),
|
|
57
|
+
].filter(issue => issue !== undefined);
|
|
58
|
+
if (text.length < CODE.end) {
|
|
59
|
+
issues.push(
|
|
60
|
+
parseIssue(
|
|
61
|
+
'parse.lineLength',
|
|
62
|
+
`A response line must have at least ${CODE.end} characters, not ${text.length}.`,
|
|
63
|
+
{ line: lineNumber, column: text.length + 1 },
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
return issues;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function responseRecord(text: string, line: number): ResponseRecord {
|
|
71
|
+
const code = text.slice(CODE.start, CODE.end);
|
|
72
|
+
const detail = text.slice(CODE.end).trimEnd();
|
|
73
|
+
return {
|
|
74
|
+
fileNumber: text.slice(FILE_NUMBER.start, FILE_NUMBER.end),
|
|
75
|
+
taxYear: Number(text.slice(TAX_YEAR.start, TAX_YEAR.end)),
|
|
76
|
+
code,
|
|
77
|
+
meaning: responseMeaning(code),
|
|
78
|
+
accepted: code === '00',
|
|
79
|
+
...(detail === '' ? {} : { detail }),
|
|
80
|
+
line,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Parses SHAAM's response file shumot.shg (SPEC §3.9): one ResponseRecord per non-blank line, in
|
|
86
|
+
* file order. Bytes are decoded as windows-1255; lines end with CRLF or LF; blank lines are
|
|
87
|
+
* skipped and an empty file gives []. A line shorter than 15 characters (parse.lineLength) or with
|
|
88
|
+
* a non-digit in its file number or tax year (parse.numeric) throws Opcn1214ParseError carrying
|
|
89
|
+
* the problems of every such line, sorted by line and column.
|
|
90
|
+
*/
|
|
91
|
+
export function parseResponseFile(content: string | Uint8Array): ResponseRecord[] {
|
|
92
|
+
const records: ResponseRecord[] = [];
|
|
93
|
+
const issues: Issue[] = [];
|
|
94
|
+
for (const [index, { text }] of splitFile(content).entries()) {
|
|
95
|
+
if (BLANK.test(text)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const line = index + 1;
|
|
99
|
+
const problems = lineIssues(text, line);
|
|
100
|
+
if (problems.length > 0) {
|
|
101
|
+
issues.push(...problems);
|
|
102
|
+
} else {
|
|
103
|
+
records.push(responseRecord(text, line));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (issues.length > 0) {
|
|
107
|
+
throw new Opcn1214ParseError(issues);
|
|
108
|
+
}
|
|
109
|
+
return records;
|
|
110
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** validate1214 (SPEC §6.1): validation without generation. */
|
|
2
|
+
import type { ValidateOptions } from '../model/options.js';
|
|
3
|
+
import { runPipeline } from '../pipeline.js';
|
|
4
|
+
import type { Issue } from '../validate/issue.js';
|
|
5
|
+
|
|
6
|
+
/** The outcome of validate1214 (SPEC §6.2). */
|
|
7
|
+
export interface ValidationResult {
|
|
8
|
+
/** True exactly when `errors` is empty. */
|
|
9
|
+
valid: boolean;
|
|
10
|
+
/** Severity 'error', sorted (SPEC §9.1). */
|
|
11
|
+
errors: Issue[];
|
|
12
|
+
/** Severity 'warning', sorted (SPEC §9.1). */
|
|
13
|
+
warnings: Issue[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** `issues` (already sorted) split by severity; the order is kept within each part. */
|
|
17
|
+
export function splitIssues(issues: readonly Issue[]): ValidationResult {
|
|
18
|
+
const errors = issues.filter(issue => issue.severity === 'error');
|
|
19
|
+
const warnings = issues.filter(issue => issue.severity === 'warning');
|
|
20
|
+
return { valid: errors.length === 0, errors, warnings };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Validates without generating. Never throws for bad input; returns every issue found. */
|
|
24
|
+
export function validate1214(input: unknown, options?: ValidateOptions): ValidationResult {
|
|
25
|
+
return splitIssues(runPipeline(input, options).issues);
|
|
26
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Boolean codecs (SPEC §4.2 flag, yesNo; §15 A-20). */
|
|
2
|
+
import type { CodeKind, FieldKind } from '../layout/types.js';
|
|
3
|
+
import { invalid, pad, readDigits } from './numeric.js';
|
|
4
|
+
import { CodecDecodeError, type Codec, type FieldShape, type Primitive } from './types.js';
|
|
5
|
+
|
|
6
|
+
/** Digit written for each boolean state; `absent` is also the decode result for undefined. */
|
|
7
|
+
interface BooleanDigits {
|
|
8
|
+
readonly true: string;
|
|
9
|
+
readonly false: string;
|
|
10
|
+
readonly absent: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The value a decoded digit string stands for, or `null` when it is not one of `digits`. */
|
|
14
|
+
function fromDigits(text: string, digits: BooleanDigits): Primitive | null {
|
|
15
|
+
const value = Number(text);
|
|
16
|
+
if (value === Number(digits.true)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (value === Number(digits.false)) {
|
|
20
|
+
return digits.false === digits.absent ? undefined : false;
|
|
21
|
+
}
|
|
22
|
+
if (value === Number(digits.absent)) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function booleanCodec(digits: BooleanDigits): Codec {
|
|
29
|
+
return {
|
|
30
|
+
encode(value, shape) {
|
|
31
|
+
if (value === undefined) {
|
|
32
|
+
return pad(digits.absent, shape);
|
|
33
|
+
}
|
|
34
|
+
if (typeof value !== 'boolean') {
|
|
35
|
+
throw invalid(value, shape, 'a boolean');
|
|
36
|
+
}
|
|
37
|
+
return pad(value ? digits.true : digits.false, shape);
|
|
38
|
+
},
|
|
39
|
+
decode(raw: string, shape: FieldShape) {
|
|
40
|
+
const text = readDigits(raw, shape);
|
|
41
|
+
if (text === undefined) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const value = fromDigits(text, digits);
|
|
45
|
+
if (value === null) {
|
|
46
|
+
throw new CodecDecodeError(
|
|
47
|
+
'format',
|
|
48
|
+
raw.indexOf(text),
|
|
49
|
+
`Unexpected value "${raw}" for ${shape.kind}`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const BOOLEAN_CODECS = {
|
|
58
|
+
/** `true` → 1, `false`/absent → 0; 0 decodes to undefined (SPEC §8.4: false flags are lossy). */
|
|
59
|
+
flag: booleanCodec({ true: '1', false: '0', absent: '0' }),
|
|
60
|
+
/** `true` → 1, `false` → 2, absent → 0 (SPEC §15 A-20). */
|
|
61
|
+
yesNo: booleanCodec({ true: '1', false: '2', absent: '0' }),
|
|
62
|
+
} as const satisfies Partial<Record<FieldKind | CodeKind, Codec>>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** Date codec (SPEC §4.2): ISO `YYYY-MM-DD` in the model, `DD/MM/YYYY` in the file. */
|
|
2
|
+
import type { CodeKind, FieldKind } from '../layout/types.js';
|
|
3
|
+
import { blank, checkLength, invalid } from './numeric.js';
|
|
4
|
+
import { CodecDecodeError, type Codec, type Primitive } from './types.js';
|
|
5
|
+
|
|
6
|
+
const ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
7
|
+
/** `d` is a digit, any other character must match literally. */
|
|
8
|
+
const FILE_DATE_PATTERN = 'dd/dd/dddd';
|
|
9
|
+
|
|
10
|
+
function isLeapYear(year: number): boolean {
|
|
11
|
+
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function daysInMonth(year: number, month: number): number {
|
|
15
|
+
if (month === 2) {
|
|
16
|
+
return isLeapYear(year) ? 29 : 28;
|
|
17
|
+
}
|
|
18
|
+
return [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isCalendarDate(year: number, month: number, day: number): boolean {
|
|
22
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= daysInMonth(year, month);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** True for a real calendar date in ISO `YYYY-MM-DD` form (SPEC §4.2; field.date). */
|
|
26
|
+
export function isIsoDate(value: Primitive): value is string {
|
|
27
|
+
const match = typeof value === 'string' ? ISO_DATE.exec(value) : null;
|
|
28
|
+
return match !== null && isCalendarDate(Number(match[1]), Number(match[2]), Number(match[3]));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function invalidDate(raw: string, offset: number): CodecDecodeError {
|
|
32
|
+
return new CodecDecodeError('date', offset, `Invalid DD/MM/YYYY date "${raw}"`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const dateCodec: Codec = {
|
|
36
|
+
encode(value, shape) {
|
|
37
|
+
if (value === undefined) {
|
|
38
|
+
return blank(shape);
|
|
39
|
+
}
|
|
40
|
+
if (!isIsoDate(value) || shape.length !== FILE_DATE_PATTERN.length) {
|
|
41
|
+
throw invalid(value, shape, `a real calendar date YYYY-MM-DD in a field of width 10`);
|
|
42
|
+
}
|
|
43
|
+
const [year, month, day] = value.split('-');
|
|
44
|
+
return `${day}/${month}/${year}`;
|
|
45
|
+
},
|
|
46
|
+
decode(raw, shape) {
|
|
47
|
+
checkLength(raw, shape);
|
|
48
|
+
if (shape.type === 'alphanumeric' && raw.trim() === '') {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
for (let index = 0; index < FILE_DATE_PATTERN.length; index++) {
|
|
52
|
+
const expected = FILE_DATE_PATTERN[index];
|
|
53
|
+
const char = raw[index];
|
|
54
|
+
const ok =
|
|
55
|
+
char !== undefined && (expected === 'd' ? char >= '0' && char <= '9' : char === expected);
|
|
56
|
+
if (!ok) {
|
|
57
|
+
throw invalidDate(raw, index);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (raw.length !== FILE_DATE_PATTERN.length) {
|
|
61
|
+
throw invalidDate(raw, FILE_DATE_PATTERN.length);
|
|
62
|
+
}
|
|
63
|
+
const day = raw.slice(0, 2);
|
|
64
|
+
const month = raw.slice(3, 5);
|
|
65
|
+
const year = raw.slice(6, 10);
|
|
66
|
+
if (!isCalendarDate(Number(year), Number(month), Number(day))) {
|
|
67
|
+
throw invalidDate(raw, 0);
|
|
68
|
+
}
|
|
69
|
+
return `${year}-${month}-${day}`;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const DATE_CODECS = {
|
|
74
|
+
date: dateCodec,
|
|
75
|
+
} as const satisfies Partial<Record<FieldKind | CodeKind, Codec>>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Enum codec (SPEC §4.2): the model holds the mapped numeric value. */
|
|
2
|
+
import type { CodeKind, FieldKind } from '../layout/types.js';
|
|
3
|
+
import { blank, encodeInteger, invalid, readDigits } from './numeric.js';
|
|
4
|
+
import type { Codec } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* enum: the value must be one of `shape.values` when encoding. Decoding returns any number, so
|
|
8
|
+
* values outside the list reach `field.enum` instead of failing the parse.
|
|
9
|
+
*/
|
|
10
|
+
const enumCodec: Codec = {
|
|
11
|
+
encode(value, shape) {
|
|
12
|
+
if (value === undefined) {
|
|
13
|
+
return blank(shape);
|
|
14
|
+
}
|
|
15
|
+
if (typeof value !== 'number' || !shape.values?.some(allowed => allowed.value === value)) {
|
|
16
|
+
throw invalid(value, shape, 'one of the allowed values');
|
|
17
|
+
}
|
|
18
|
+
return encodeInteger(value, shape);
|
|
19
|
+
},
|
|
20
|
+
decode(raw, shape) {
|
|
21
|
+
const digits = readDigits(raw, shape);
|
|
22
|
+
return digits === undefined ? undefined : Number(digits);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const ENUM_CODECS = {
|
|
27
|
+
enum: enumCodec,
|
|
28
|
+
} as const satisfies Partial<Record<FieldKind | CodeKind, Codec>>;
|