@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
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@accounter/opcn1214-generator",
|
|
3
|
+
"version": "0.0.0-bootstrap.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Fully typed application that generates, parses, and validates OPCN 1214 tax reports.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Urigo/accounter-fullstack.git",
|
|
9
|
+
"directory": "packages/opcn1214-generator"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/Urigo/accounter-fullstack/packages/opcn1214-generator#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Urigo/accounter-fullstack/issues"
|
|
14
|
+
},
|
|
15
|
+
"author": "Gil Gardosh <gilgardosh@gmail.com>",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": "^20.0.0 || >= 22"
|
|
19
|
+
},
|
|
20
|
+
"main": "dist/cjs/index.js",
|
|
21
|
+
"module": "dist/esm/index.js",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/typings/index.d.cts",
|
|
26
|
+
"default": "./dist/cjs/index.js"
|
|
27
|
+
},
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/typings/index.d.ts",
|
|
30
|
+
"default": "./dist/esm/index.js"
|
|
31
|
+
},
|
|
32
|
+
"default": {
|
|
33
|
+
"types": "./dist/typings/index.d.ts",
|
|
34
|
+
"default": "./dist/esm/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"typings": "dist/typings/index.d.ts",
|
|
40
|
+
"keywords": [
|
|
41
|
+
"1214",
|
|
42
|
+
"opcn",
|
|
43
|
+
"shaam",
|
|
44
|
+
"accountancy",
|
|
45
|
+
"israeli-tax",
|
|
46
|
+
"tax-forms",
|
|
47
|
+
"accounter"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "yarn lint && bob build",
|
|
51
|
+
"generate:layout": "tsx scripts/generate-layout.ts",
|
|
52
|
+
"lint": "eslint './src/**/*.{js,ts,tsx}' --ignore-pattern '**/*.generated.ts' --quiet --fix",
|
|
53
|
+
"render:rules": "tsx scripts/render-rules-table.ts",
|
|
54
|
+
"test": "vitest",
|
|
55
|
+
"test:watch": "vitest --watch",
|
|
56
|
+
"typecheck": "tsc -p tsconfig.typecheck.json"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"iconv-lite": "0.7.3",
|
|
60
|
+
"zod": "4.6.7"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"bob-the-bundler": "7.0.1",
|
|
64
|
+
"eslint": "10.15.0",
|
|
65
|
+
"prettier": "3.10.1",
|
|
66
|
+
"tsx": "4.23.15",
|
|
67
|
+
"typescript": "6.0.3",
|
|
68
|
+
"vitest": "5.1.0"
|
|
69
|
+
},
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"registry": "https://registry.npmjs.org",
|
|
72
|
+
"access": "public"
|
|
73
|
+
},
|
|
74
|
+
"typescript": {
|
|
75
|
+
"definition": "dist/typings/index.d.ts"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { renderCodesModule, renderLayoutModule } from './layout/render.js';
|
|
3
|
+
import {
|
|
4
|
+
codesModuleUrl,
|
|
5
|
+
latestLayoutYear,
|
|
6
|
+
layoutModuleUrl,
|
|
7
|
+
layoutYears,
|
|
8
|
+
readLayoutSources,
|
|
9
|
+
} from './layout/sources.js';
|
|
10
|
+
|
|
11
|
+
function write(target: URL, source: string): void {
|
|
12
|
+
mkdirSync(new URL('.', target), { recursive: true });
|
|
13
|
+
writeFileSync(target, source);
|
|
14
|
+
console.log(`generated ${target.pathname}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Regenerates src/layout/<year>/layout.generated.ts for every documentation/layout/<year>/, and
|
|
18
|
+
// src/model/codes.generated.ts (year-independent code unions) from the newest year.
|
|
19
|
+
for (const year of layoutYears()) {
|
|
20
|
+
write(layoutModuleUrl(year), await renderLayoutModule(year, readLayoutSources(year)));
|
|
21
|
+
}
|
|
22
|
+
const latest = latestLayoutYear();
|
|
23
|
+
write(codesModuleUrl(), await renderCodesModule(latest, readLayoutSources(latest)));
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal RFC 4180 CSV parser for the layout data files (no dependency).
|
|
3
|
+
*
|
|
4
|
+
* Fields are separated by commas; a field may be wrapped in double quotes, in which case it may
|
|
5
|
+
* contain commas, line breaks and doubled quotes (`""` → `"`). Rows end with CRLF or LF; a final
|
|
6
|
+
* line break is optional.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type CsvRow = Record<string, string>;
|
|
10
|
+
|
|
11
|
+
interface ParsedRow {
|
|
12
|
+
/** 1-based physical line on which the row starts. */
|
|
13
|
+
line: number;
|
|
14
|
+
fields: string[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function parseRows(text: string): ParsedRow[] {
|
|
18
|
+
const rows: ParsedRow[] = [];
|
|
19
|
+
let fields: string[] = [];
|
|
20
|
+
let field = '';
|
|
21
|
+
let line = 1;
|
|
22
|
+
let rowLine = 1;
|
|
23
|
+
let i = 0;
|
|
24
|
+
|
|
25
|
+
const endRow = () => {
|
|
26
|
+
fields.push(field);
|
|
27
|
+
rows.push({ line: rowLine, fields });
|
|
28
|
+
fields = [];
|
|
29
|
+
field = '';
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
while (i < text.length) {
|
|
33
|
+
const char = text[i];
|
|
34
|
+
if (char === '"' && field === '') {
|
|
35
|
+
const quoteLine = line;
|
|
36
|
+
i++;
|
|
37
|
+
for (;;) {
|
|
38
|
+
if (i >= text.length) {
|
|
39
|
+
throw new Error(`CSV line ${quoteLine}: unterminated quoted field`);
|
|
40
|
+
}
|
|
41
|
+
const quoted = text[i];
|
|
42
|
+
if (quoted === '"') {
|
|
43
|
+
if (text[i + 1] === '"') {
|
|
44
|
+
field += '"';
|
|
45
|
+
i += 2;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
i++;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
if (quoted === '\n') line++;
|
|
52
|
+
field += quoted;
|
|
53
|
+
i++;
|
|
54
|
+
}
|
|
55
|
+
const next = text[i];
|
|
56
|
+
if (next !== undefined && next !== ',' && next !== '\n' && next !== '\r') {
|
|
57
|
+
throw new Error(`CSV line ${line}: unexpected text after a closing quote`);
|
|
58
|
+
}
|
|
59
|
+
if (next === undefined) break;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (char === ',') {
|
|
63
|
+
fields.push(field);
|
|
64
|
+
field = '';
|
|
65
|
+
i++;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (char === '\r' && text[i + 1] === '\n') {
|
|
69
|
+
i++;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (char === '\n') {
|
|
73
|
+
endRow();
|
|
74
|
+
i++;
|
|
75
|
+
line++;
|
|
76
|
+
rowLine = line;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
field += char;
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (field !== '' || fields.length > 0 || (text.length > 0 && !text.endsWith('\n'))) {
|
|
84
|
+
endRow();
|
|
85
|
+
}
|
|
86
|
+
return rows;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Parses CSV text into rows of fields. */
|
|
90
|
+
export function parseCsv(text: string): string[][] {
|
|
91
|
+
return parseRows(text).map(row => row.fields);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Parses CSV text whose first row is a header into one object per data row, keyed by the header
|
|
96
|
+
* names. Throws, naming the physical line, for a row whose column count differs from the header's.
|
|
97
|
+
*/
|
|
98
|
+
export function parseCsvRecords(text: string): CsvRow[] {
|
|
99
|
+
const [header, ...rows] = parseRows(text);
|
|
100
|
+
if (!header) {
|
|
101
|
+
throw new Error('CSV: missing header row');
|
|
102
|
+
}
|
|
103
|
+
return rows.map(row => {
|
|
104
|
+
if (row.fields.length !== header.fields.length) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`CSV line ${row.line}: expected ${header.fields.length} columns, got ${row.fields.length}`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return Object.fromEntries(header.fields.map((name, index) => [name, row.fields[index] ?? '']));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codes whose values the package derives from other input (SPEC §7.4, "Derived values"); callers
|
|
3
|
+
* never pass them (`input.derivedCode`). codes.csv has no column for this, so it is kept here and
|
|
4
|
+
* becomes `CodeDef.derived` in the generated layout.
|
|
5
|
+
*/
|
|
6
|
+
export const DERIVED_CODES: Readonly<Record<string, readonly string[]>> = {
|
|
7
|
+
/** 008 accounting standards, 028 forms attached, 273 declarations 1029/1030, 277/278/280 bank
|
|
8
|
+
* account, 297 form 6111 obligation. */
|
|
9
|
+
'1000': ['008', '028', '273', '277', '278', '280', '297'],
|
|
10
|
+
/** "Code 50 – improvement N", from `improvements[i].code50Amount`. */
|
|
11
|
+
'3077': ['501', '502', '503', '504', '505'],
|
|
12
|
+
};
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { format, resolveConfig } from 'prettier';
|
|
3
|
+
import { countryKey } from '../../src/layout/countries.js';
|
|
4
|
+
import { CODE_KINDS, FIELD_KINDS, type CodeKind, type FieldKind } from '../../src/layout/types.js';
|
|
5
|
+
import type { CsvRow } from './csv.js';
|
|
6
|
+
import { DERIVED_CODES } from './derived-codes.js';
|
|
7
|
+
import { codesModuleUrl, layoutModuleUrl, type LayoutSources } from './sources.js';
|
|
8
|
+
import { parseValues } from './values.js';
|
|
9
|
+
|
|
10
|
+
const DERIVED_PREFIX = '(derived) ';
|
|
11
|
+
|
|
12
|
+
/** YearLayout.limits (SPEC §3.1, §3.5–§3.7); the same for every tax year so far. */
|
|
13
|
+
const LIMITS = {
|
|
14
|
+
reportsPerFile: 50,
|
|
15
|
+
capitalGainsAppendices: 14,
|
|
16
|
+
mainCodePairs: 61,
|
|
17
|
+
countriesPerRecord: 10,
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
/** Section entry limits fixed by the spec; every other section holds at most one entry per code. */
|
|
21
|
+
const SECTION_MAX_ENTRIES: Readonly<Record<string, number>> = {
|
|
22
|
+
'1000': LIMITS.mainCodePairs,
|
|
23
|
+
'2200': LIMITS.countriesPerRecord,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function column(row: CsvRow, name: string): string {
|
|
27
|
+
const value = row[name];
|
|
28
|
+
if (value === undefined) {
|
|
29
|
+
throw new Error(`layout CSV: missing column "${name}"`);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function integer(row: CsvRow, name: string): number {
|
|
35
|
+
const value = column(row, name);
|
|
36
|
+
if (!/^\d+$/.test(value)) {
|
|
37
|
+
throw new Error(`layout CSV: column "${name}" must be a non-negative integer, got "${value}"`);
|
|
38
|
+
}
|
|
39
|
+
return Number(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function oneOf<T extends string>(row: CsvRow, name: string, allowed: readonly T[]): T {
|
|
43
|
+
const value = column(row, name);
|
|
44
|
+
const match = allowed.find(candidate => candidate === value);
|
|
45
|
+
if (match === undefined) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`layout CSV: column "${name}" must be one of ${allowed.join(', ')}, got "${value}"`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return match;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function yesNo(row: CsvRow, name: string): boolean {
|
|
54
|
+
return oneOf(row, name, ['yes', 'no']) === 'yes';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface CodeData {
|
|
58
|
+
record: string;
|
|
59
|
+
code: string;
|
|
60
|
+
derived: boolean;
|
|
61
|
+
perCountryBreakdown: boolean;
|
|
62
|
+
notesHe: string;
|
|
63
|
+
/** The CodeDef literal emitted into the layout module. */
|
|
64
|
+
def: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function toCode(row: CsvRow): CodeData {
|
|
68
|
+
const record = column(row, 'record');
|
|
69
|
+
const code = column(row, 'code');
|
|
70
|
+
if (!/^\d{3}$/.test(code)) {
|
|
71
|
+
throw new Error(`codes.csv: code "${code}" of record ${record} must have 3 digits`);
|
|
72
|
+
}
|
|
73
|
+
const length = integer(row, 'length');
|
|
74
|
+
if (length < 1 || length > 12) {
|
|
75
|
+
throw new Error(`codes.csv: code ${record}:${code} must be 1–12 wide, got ${length}`);
|
|
76
|
+
}
|
|
77
|
+
const values = parseValues(column(row, 'values'));
|
|
78
|
+
const derived = DERIVED_CODES[record]?.includes(code) ?? false;
|
|
79
|
+
const perCountryBreakdown = yesNo(row, 'perCountryBreakdown');
|
|
80
|
+
const notesHe = column(row, 'notesHe');
|
|
81
|
+
return {
|
|
82
|
+
record,
|
|
83
|
+
code,
|
|
84
|
+
derived,
|
|
85
|
+
perCountryBreakdown,
|
|
86
|
+
notesHe,
|
|
87
|
+
def: {
|
|
88
|
+
record,
|
|
89
|
+
code,
|
|
90
|
+
length,
|
|
91
|
+
required: oneOf(row, 'required', ['yes', 'no', 'conditional']),
|
|
92
|
+
kind: oneOf<CodeKind>(row, 'kind', CODE_KINDS),
|
|
93
|
+
...(values ? { values } : {}),
|
|
94
|
+
zeroAllowed: yesNo(row, 'zeroAllowed'),
|
|
95
|
+
perCountryBreakdown,
|
|
96
|
+
derived,
|
|
97
|
+
notesHe,
|
|
98
|
+
specPage: integer(row, 'specPage'),
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Parses codes.csv into the codes of each record, sorted by code. Every code must belong to a
|
|
105
|
+
* record with a code-amount section, codes are unique per record, and every derived code of
|
|
106
|
+
* scripts/layout/derived-codes.ts must exist.
|
|
107
|
+
*/
|
|
108
|
+
function codesByRecord(sources: LayoutSources): Map<string, CodeData[]> {
|
|
109
|
+
const codeAmountRecords = new Set(
|
|
110
|
+
sources.records
|
|
111
|
+
.filter(row => column(row, 'sectionKind') === 'codeAmount')
|
|
112
|
+
.map(row => column(row, 'record')),
|
|
113
|
+
);
|
|
114
|
+
const result = new Map<string, CodeData[]>();
|
|
115
|
+
for (const row of sources.codes) {
|
|
116
|
+
const code = toCode(row);
|
|
117
|
+
if (!codeAmountRecords.has(code.record)) {
|
|
118
|
+
throw new Error(`codes.csv: record "${code.record}" has no code-amount section`);
|
|
119
|
+
}
|
|
120
|
+
const codes = result.get(code.record) ?? [];
|
|
121
|
+
if (codes.some(existing => existing.code === code.code)) {
|
|
122
|
+
throw new Error(`codes.csv: duplicate code ${code.record}:${code.code}`);
|
|
123
|
+
}
|
|
124
|
+
codes.push(code);
|
|
125
|
+
result.set(code.record, codes);
|
|
126
|
+
}
|
|
127
|
+
for (const [record, derived] of Object.entries(DERIVED_CODES)) {
|
|
128
|
+
for (const code of derived) {
|
|
129
|
+
if (!result.get(record)?.some(existing => existing.code === code)) {
|
|
130
|
+
throw new Error(`derived-codes: ${record}:${code} is not in codes.csv`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const codes of result.values()) {
|
|
135
|
+
codes.sort((a, b) => a.code.localeCompare(b.code));
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Parses countries.csv into [key, Hebrew name] pairs, in file order (keys via `countryKey`). */
|
|
141
|
+
function countryEntries(sources: LayoutSources): Array<[string, string]> {
|
|
142
|
+
const entries = sources.countries.map((row): [string, string] => {
|
|
143
|
+
const code = column(row, 'code');
|
|
144
|
+
if (code !== '-88' && !/^\d{1,3}$/.test(code)) {
|
|
145
|
+
throw new Error(`countries.csv: invalid country code "${code}"`);
|
|
146
|
+
}
|
|
147
|
+
return [countryKey(code), column(row, 'nameHe')];
|
|
148
|
+
});
|
|
149
|
+
const keys = new Set(entries.map(([key]) => key));
|
|
150
|
+
if (keys.size !== entries.length) {
|
|
151
|
+
throw new Error('countries.csv: duplicate country codes');
|
|
152
|
+
}
|
|
153
|
+
return entries;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function toField(row: CsvRow): Record<string, unknown> {
|
|
157
|
+
const csvKey = column(row, 'key');
|
|
158
|
+
const derived = csvKey.startsWith(DERIVED_PREFIX);
|
|
159
|
+
const values = parseValues(column(row, 'values'));
|
|
160
|
+
return {
|
|
161
|
+
record: column(row, 'record'),
|
|
162
|
+
position: integer(row, 'position'),
|
|
163
|
+
length: integer(row, 'length'),
|
|
164
|
+
type: oneOf(row, 'type', ['numeric', 'alphanumeric']),
|
|
165
|
+
required: oneOf(row, 'required', ['yes', 'no', 'conditional']),
|
|
166
|
+
key: derived ? csvKey.slice(DERIVED_PREFIX.length) : csvKey,
|
|
167
|
+
derived,
|
|
168
|
+
kind: oneOf<FieldKind>(row, 'kind', FIELD_KINDS),
|
|
169
|
+
...(values ? { values } : {}),
|
|
170
|
+
nameHe: column(row, 'nameHe'),
|
|
171
|
+
specPage: integer(row, 'specPage'),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function toRecord(
|
|
176
|
+
row: CsvRow,
|
|
177
|
+
fieldRows: readonly CsvRow[],
|
|
178
|
+
codes: readonly CodeData[],
|
|
179
|
+
): Record<string, unknown> {
|
|
180
|
+
const type = column(row, 'record');
|
|
181
|
+
const sectionKind = column(row, 'sectionKind');
|
|
182
|
+
const fields = fieldRows
|
|
183
|
+
.filter(field => column(field, 'record') === type)
|
|
184
|
+
.map(toField)
|
|
185
|
+
.sort((a, b) => Number(a['position']) - Number(b['position']));
|
|
186
|
+
return {
|
|
187
|
+
type,
|
|
188
|
+
order: integer(row, 'order'),
|
|
189
|
+
length: integer(row, 'length'),
|
|
190
|
+
headerLength: integer(row, 'headerLength'),
|
|
191
|
+
...(sectionKind === ''
|
|
192
|
+
? {}
|
|
193
|
+
: {
|
|
194
|
+
section: {
|
|
195
|
+
kind: oneOf(row, 'sectionKind', ['codeAmount', 'countryAmount']),
|
|
196
|
+
start: integer(row, 'sectionStart'),
|
|
197
|
+
length: integer(row, 'sectionLength'),
|
|
198
|
+
maxEntries: SECTION_MAX_ENTRIES[type] ?? codes.length,
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
minOccurs: integer(row, 'minOccurs'),
|
|
202
|
+
maxOccurs: integer(row, 'maxOccurs'),
|
|
203
|
+
fields,
|
|
204
|
+
codes: codes.map(code => code.def),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Serializes plain data (objects, arrays, strings, numbers, booleans) as a TS literal. */
|
|
209
|
+
function toLiteral(value: unknown): string {
|
|
210
|
+
if (Array.isArray(value)) {
|
|
211
|
+
return `[${value.map(toLiteral).join(',')}]`;
|
|
212
|
+
}
|
|
213
|
+
if (typeof value === 'object' && value !== null) {
|
|
214
|
+
const entries = Object.entries(value).map(
|
|
215
|
+
([key, item]) =>
|
|
216
|
+
`${/^[A-Za-z_$][\w$]*$/.test(key) ? key : JSON.stringify(key)}:${toLiteral(item)}`,
|
|
217
|
+
);
|
|
218
|
+
return `{${entries.join(',')}}`;
|
|
219
|
+
}
|
|
220
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
221
|
+
return JSON.stringify(value);
|
|
222
|
+
}
|
|
223
|
+
throw new Error(`layout render: cannot serialize ${String(value)}`);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Renders src/layout/<year>/layout.generated.ts from the parsed CSVs of
|
|
228
|
+
* documentation/layout/<year>/, formatted with the repository's prettier configuration.
|
|
229
|
+
*/
|
|
230
|
+
export async function renderLayoutModule(year: number, sources: LayoutSources): Promise<string> {
|
|
231
|
+
const recordTypes = new Set(sources.records.map(row => column(row, 'record')));
|
|
232
|
+
for (const field of sources.fields) {
|
|
233
|
+
if (!recordTypes.has(column(field, 'record'))) {
|
|
234
|
+
throw new Error(`layout CSV: field of unknown record "${column(field, 'record')}"`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const codes = codesByRecord(sources);
|
|
238
|
+
const records = Object.fromEntries(
|
|
239
|
+
[...sources.records]
|
|
240
|
+
.sort((a, b) => integer(a, 'order') - integer(b, 'order'))
|
|
241
|
+
.map(row => {
|
|
242
|
+
const type = column(row, 'record');
|
|
243
|
+
return [type, toRecord(row, sources.fields, codes.get(type) ?? [])];
|
|
244
|
+
}),
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
// disableLint: the layout data trips unicorn/numeric-separators-style (999999964, 999999998).
|
|
248
|
+
const source = `${moduleHeader(year, { disableLint: true })}
|
|
249
|
+
import type { YearLayout } from '../types.js';
|
|
250
|
+
|
|
251
|
+
export const LAYOUT_${year} = {
|
|
252
|
+
taxYear: ${year},
|
|
253
|
+
records: ${toLiteral(records)},
|
|
254
|
+
countries: new Map<string, string>(${toLiteral(countryEntries(sources))}),
|
|
255
|
+
limits: ${toLiteral(LIMITS)},
|
|
256
|
+
} as const satisfies YearLayout;
|
|
257
|
+
`;
|
|
258
|
+
|
|
259
|
+
return formatModule(source, layoutModuleUrl(year));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Header of a generated module. `disableLint` adds `/* eslint-disable *\/` for modules whose data
|
|
264
|
+
* trips a lint rule; it is opt-in so the root lint never reports an unused directive.
|
|
265
|
+
*/
|
|
266
|
+
function moduleHeader(year: number, { disableLint }: { disableLint: boolean }): string {
|
|
267
|
+
const header = `// Generated by scripts/generate-layout.ts from documentation/layout/${year}/ — do not edit.`;
|
|
268
|
+
return disableLint ? `${header}\n/* eslint-disable */` : header;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function formatModule(source: string, target: URL): Promise<string> {
|
|
272
|
+
const filepath = fileURLToPath(target);
|
|
273
|
+
const options = await resolveConfig(filepath);
|
|
274
|
+
return format(source, { ...options, filepath });
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** A one-line JSDoc comment, or nothing for an empty text. */
|
|
278
|
+
function jsDoc(text: string): string {
|
|
279
|
+
const line = text.replaceAll(/\s+/g, ' ').trim().replaceAll('*/', '*\\/');
|
|
280
|
+
return line === '' ? '' : `/** ${line} */ `;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** A literal union of string codes, each preceded by its JSDoc note. */
|
|
284
|
+
function codeUnion(entries: ReadonlyArray<{ code: string; note: string }>): string {
|
|
285
|
+
return entries.map(({ code, note }) => `| ${jsDoc(note)}${JSON.stringify(code)}`).join('\n');
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function codeArray(codes: readonly string[]): string {
|
|
289
|
+
return `[${codes.map(code => JSON.stringify(code)).join(',')}]`;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Renders src/model/codes.generated.ts: the year-independent literal unions of codes (SPEC §5.3,
|
|
294
|
+
* §7.2) and matching `as const` arrays, generated from the newest layout year.
|
|
295
|
+
*/
|
|
296
|
+
export async function renderCodesModule(year: number, sources: LayoutSources): Promise<string> {
|
|
297
|
+
const codes = codesByRecord(sources);
|
|
298
|
+
const of = (record: string, predicate: (code: CodeData) => boolean = () => true) =>
|
|
299
|
+
(codes.get(record) ?? []).filter(predicate);
|
|
300
|
+
const withNotes = (list: readonly CodeData[]) =>
|
|
301
|
+
list.map(code => ({ code: code.code, note: code.notesHe }));
|
|
302
|
+
const main = of('1000');
|
|
303
|
+
const derivedMain = of('1000', code => code.derived);
|
|
304
|
+
const inputMain = of('1000', code => !code.derived);
|
|
305
|
+
const foreign = of('2000');
|
|
306
|
+
const breakdown = of('2000', code => code.perCountryBreakdown);
|
|
307
|
+
const symbols = sources.records
|
|
308
|
+
.map(row => column(row, 'record'))
|
|
309
|
+
.filter(type => /^30\d{2}$/.test(type))
|
|
310
|
+
.map(type => Number(type.slice(2)))
|
|
311
|
+
.sort((a, b) => a - b);
|
|
312
|
+
const countries = countryEntries(sources);
|
|
313
|
+
|
|
314
|
+
const source = `${moduleHeader(year, { disableLint: false })}
|
|
315
|
+
|
|
316
|
+
/** Codes of the record 1000 code-amount section (main form, SPEC §3.5). */
|
|
317
|
+
export type MainFormCode = ${codeUnion(withNotes(main))};
|
|
318
|
+
|
|
319
|
+
/** Main-form codes the package derives (SPEC §7.4); never passed by the caller. */
|
|
320
|
+
export type DerivedMainCode = ${codeUnion(withNotes(derivedMain))};
|
|
321
|
+
|
|
322
|
+
/** Main-form codes the caller may pass in \`amounts\`. */
|
|
323
|
+
export type MainFormInputCode = Exclude<MainFormCode, DerivedMainCode>;
|
|
324
|
+
|
|
325
|
+
/** Codes of the record 2000 code-amount section (foreign appendix). */
|
|
326
|
+
export type ForeignAppendixCode = ${codeUnion(withNotes(foreign))};
|
|
327
|
+
|
|
328
|
+
/** Foreign-appendix codes that require a per-country breakdown (record 2200, SPEC §3.6). */
|
|
329
|
+
export type CountryBreakdownCode = ${codeUnion(withNotes(breakdown))};
|
|
330
|
+
|
|
331
|
+
/** Transaction symbols of the capital-gains appendices (record 30xx = symbol xx). */
|
|
332
|
+
export type CapitalGainsSymbol = ${symbols.join(' | ')};
|
|
333
|
+
|
|
334
|
+
interface CapitalGainsCodeMap {
|
|
335
|
+
${symbols.map(symbol => `${symbol}: ${codeUnion(withNotes(of(`30${symbol}`)))};`).join('\n')}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** Codes of the code-amount section of the capital-gains appendix of a symbol. */
|
|
339
|
+
export type CapitalGainsCode<S extends CapitalGainsSymbol> = CapitalGainsCodeMap[S];
|
|
340
|
+
|
|
341
|
+
/** Country codes of record 2200 (SPEC §3.6); \`-88\` = country unknown. */
|
|
342
|
+
export type CountryCode = ${codeUnion(countries.map(([code, name]) => ({ code, note: name })))};
|
|
343
|
+
|
|
344
|
+
export const MAIN_FORM_CODES = ${codeArray(main.map(code => code.code))} as const satisfies readonly MainFormCode[];
|
|
345
|
+
|
|
346
|
+
export const DERIVED_MAIN_CODES = ${codeArray(derivedMain.map(code => code.code))} as const satisfies readonly DerivedMainCode[];
|
|
347
|
+
|
|
348
|
+
export const MAIN_FORM_INPUT_CODES = ${codeArray(inputMain.map(code => code.code))} as const satisfies readonly MainFormInputCode[];
|
|
349
|
+
|
|
350
|
+
export const FOREIGN_APPENDIX_CODES = ${codeArray(foreign.map(code => code.code))} as const satisfies readonly ForeignAppendixCode[];
|
|
351
|
+
|
|
352
|
+
export const COUNTRY_BREAKDOWN_CODES = ${codeArray(breakdown.map(code => code.code))} as const satisfies readonly CountryBreakdownCode[];
|
|
353
|
+
|
|
354
|
+
export const CAPITAL_GAINS_SYMBOLS = [${symbols.join(',')}] as const satisfies readonly CapitalGainsSymbol[];
|
|
355
|
+
|
|
356
|
+
export const CAPITAL_GAINS_CODES = {
|
|
357
|
+
${symbols.map(symbol => `${symbol}: ${codeArray(of(`30${symbol}`).map(code => code.code))},`).join('\n')}
|
|
358
|
+
} as const satisfies { readonly [S in CapitalGainsSymbol]: readonly CapitalGainsCode<S>[] };
|
|
359
|
+
|
|
360
|
+
export const COUNTRY_CODES = ${codeArray(countries.map(([code]) => code))} as const satisfies readonly CountryCode[];
|
|
361
|
+
`;
|
|
362
|
+
|
|
363
|
+
return formatModule(source, codesModuleUrl());
|
|
364
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { parseCsvRecords, type CsvRow } from './csv.js';
|
|
3
|
+
|
|
4
|
+
/** Parsed CSV rows of one year's layout directory. */
|
|
5
|
+
export interface LayoutSources {
|
|
6
|
+
records: CsvRow[];
|
|
7
|
+
fields: CsvRow[];
|
|
8
|
+
codes: CsvRow[];
|
|
9
|
+
countries: CsvRow[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const LAYOUT_DATA_DIR = new URL('../../documentation/layout/', import.meta.url);
|
|
13
|
+
|
|
14
|
+
/** Tax years that have a documentation/layout/<year>/ directory, ascending. */
|
|
15
|
+
export function layoutYears(): number[] {
|
|
16
|
+
return readdirSync(LAYOUT_DATA_DIR, { withFileTypes: true })
|
|
17
|
+
.filter(entry => entry.isDirectory() && /^\d{4}$/.test(entry.name))
|
|
18
|
+
.map(entry => Number(entry.name))
|
|
19
|
+
.sort((a, b) => a - b);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The newest tax year with a layout directory (source of the year-independent code unions). */
|
|
23
|
+
export function latestLayoutYear(): number {
|
|
24
|
+
const year = layoutYears().at(-1);
|
|
25
|
+
if (year === undefined) {
|
|
26
|
+
throw new Error('layout: no documentation/layout/<year>/ directory');
|
|
27
|
+
}
|
|
28
|
+
return year;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Reads and parses documentation/layout/<year>/{records,fields,codes,countries}.csv. */
|
|
32
|
+
export function readLayoutSources(year: number): LayoutSources {
|
|
33
|
+
const read = (file: string) =>
|
|
34
|
+
parseCsvRecords(readFileSync(new URL(`${year}/${file}`, LAYOUT_DATA_DIR), 'utf8'));
|
|
35
|
+
return {
|
|
36
|
+
records: read('records.csv'),
|
|
37
|
+
fields: read('fields.csv'),
|
|
38
|
+
codes: read('codes.csv'),
|
|
39
|
+
countries: read('countries.csv'),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Location of the generated layout module of a year. */
|
|
44
|
+
export function layoutModuleUrl(year: number): URL {
|
|
45
|
+
return new URL(`../../src/layout/${year}/layout.generated.ts`, import.meta.url);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Location of the generated, year-independent code unions module. */
|
|
49
|
+
export function codesModuleUrl(): URL {
|
|
50
|
+
return new URL('../../src/model/codes.generated.ts', import.meta.url);
|
|
51
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { EnumValue } from '../../src/layout/types.js';
|
|
2
|
+
|
|
3
|
+
const NUMBER = /^\d+$/;
|
|
4
|
+
const RANGE = /^(\d+)\.\.(\d+)$/;
|
|
5
|
+
|
|
6
|
+
function parseNumber(text: string, item: string): number {
|
|
7
|
+
if (!NUMBER.test(text)) {
|
|
8
|
+
throw new Error(`values: "${item}" is not a non-negative integer`);
|
|
9
|
+
}
|
|
10
|
+
return Number(text);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Parses the `values` column of the layout CSVs (SPEC §4.2): `;`-separated items, each `n`,
|
|
15
|
+
* `n..m` (inclusive range) or `n=label` (split on the first `=` only, so labels may contain `=`).
|
|
16
|
+
* An empty cell means "no listed values" and yields undefined; anything else malformed throws.
|
|
17
|
+
*/
|
|
18
|
+
export function parseValues(text: string): EnumValue[] | undefined {
|
|
19
|
+
if (text === '') {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return text.split(';').flatMap((item): EnumValue[] => {
|
|
23
|
+
const separator = item.indexOf('=');
|
|
24
|
+
if (separator !== -1) {
|
|
25
|
+
const label = item.slice(separator + 1);
|
|
26
|
+
if (label === '') {
|
|
27
|
+
throw new Error(`values: "${item}" has an empty label`);
|
|
28
|
+
}
|
|
29
|
+
return [{ value: parseNumber(item.slice(0, separator), item), label }];
|
|
30
|
+
}
|
|
31
|
+
const range = RANGE.exec(item);
|
|
32
|
+
if (range) {
|
|
33
|
+
const from = Number(range[1]);
|
|
34
|
+
const to = Number(range[2]);
|
|
35
|
+
if (from > to) {
|
|
36
|
+
throw new Error(`values: range "${item}" is empty`);
|
|
37
|
+
}
|
|
38
|
+
return Array.from({ length: to - from + 1 }, (_, offset) => ({ value: from + offset }));
|
|
39
|
+
}
|
|
40
|
+
return [{ value: parseNumber(item, item) }];
|
|
41
|
+
});
|
|
42
|
+
}
|