@formancy/report-spec 0.1.0 → 0.3.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/NOTICE +8 -0
- package/README.md +912 -6
- package/dist/index.d.mts +2531 -174
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +11543 -1395
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -28,13 +28,897 @@ if (!outcome.valid) {
|
|
|
28
28
|
- anything a shape does not have, and every reference to something the
|
|
29
29
|
report does not declare;
|
|
30
30
|
- a value standing where it has none: a detail field outside the table's
|
|
31
|
-
cells, a page number outside the page header and footer
|
|
32
|
-
|
|
31
|
+
cells, a page number outside the page header and footer -- in the first
|
|
32
|
+
page's own header too, which is drawn before pages are counted -- or
|
|
33
|
+
anywhere in a QR code, an EPC QR code or a QR-bill, whose content is
|
|
34
|
+
resolved before there are pages; and a run set below or above the line
|
|
35
|
+
anywhere but in a text's paragraph (`misplaced-baseline`): see
|
|
36
|
+
[A run below or above the line](#a-run-below-or-above-the-line);
|
|
37
|
+
- more than `MAX_TABLES` tables, counted in every region and container,
|
|
38
|
+
the one past the bound refused at its own path (`too-many`); a
|
|
39
|
+
table's own total, `over: 'table'`, outside its total rows and its
|
|
40
|
+
group's header and footer (`misplaced-table-aggregate`); and, in a
|
|
41
|
+
report that is an e-invoice, a second table (`second-detail-table`)
|
|
42
|
+
or a condition on its lines' table (`invalid-e-invoice`): see
|
|
43
|
+
[Several tables](#several-tables);
|
|
44
|
+
- a QR code of no runs, which would encode nothing;
|
|
45
|
+
- a fixed size the page cannot hold, a QR code's and an EPC QR code's
|
|
46
|
+
square measured against `squareRoom`;
|
|
47
|
+
- a payment part on a page other than A4 in portrait, or whose top margin
|
|
48
|
+
reaches past the slip's top (`QR_BILL_TOP`, 544.25 pt), refused as
|
|
49
|
+
`payment-part-page` on `/page` or `/page/margins/top`; and a text of its
|
|
50
|
+
QR-bill, written in literal runs, that SIX's rules refuse
|
|
51
|
+
(`invalid-qr-bill`);
|
|
52
|
+
- an EPC QR code that the EPC's rules refuse where it is written
|
|
53
|
+
(`invalid-epc-qr-code`): a literal text that breaks its rule, a reference
|
|
54
|
+
and a text together, a BIC its IBAN does not go with or none where one is
|
|
55
|
+
needed, literal texts already past 331 bytes, or, with Austria's caption,
|
|
56
|
+
a size in which no version prints the modules the PSA allows with a
|
|
57
|
+
symbol as tall as the caption beside it;
|
|
58
|
+
- an e-invoice that EN 16931's rules, or this version's narrower ones,
|
|
59
|
+
refuse where it is written (`invalid-e-invoice`), each refusal naming the
|
|
60
|
+
business term and the rule: a literal text, code or rate that breaks its
|
|
61
|
+
rule; parties, a time of supply, a period or VAT categories that cannot
|
|
62
|
+
make a valid invoice; lines that are not what the table over the detail
|
|
63
|
+
dataset prints; a QR-bill or an EPC QR code that asks to be paid to
|
|
64
|
+
another account, or a QR-bill in another currency; or a title holding
|
|
65
|
+
`&`, `<` or `>`;
|
|
66
|
+
- a chart that is no chart of the detail rows -- a category that is not a
|
|
67
|
+
detail field of text, a date or a number, or that may be null and has no
|
|
68
|
+
label for its rows without one, and a series that totals what is not a
|
|
69
|
+
number -- or that would draw what no reader could use (`invalid-chart`):
|
|
70
|
+
see [A chart](#a-chart);
|
|
71
|
+
- a dataset read from a formancy form's submissions
|
|
72
|
+
([0042](../../docs/decisions/0042-a-report-reads-a-formancy-forms-submissions-against-the-exact-version-that-collected-them-as-the-host-hands-them-over.md))
|
|
73
|
+
that is not read whole -- a field of it that says nowhere it is read, or
|
|
74
|
+
one dataset read from a form beside one that is not
|
|
75
|
+
(`incomplete-form-binding`) -- or that reads what it is not: the header
|
|
76
|
+
rows, the detail one record, or a header beside a detail of one row per
|
|
77
|
+
submission (`misplaced-form-binding`); a data path or a repeater that is
|
|
78
|
+
not field keys joined by dots, at most `MAX_FORM_PATH_KEYS` of them, or
|
|
79
|
+
an empty member (`invalid-form-path`); a field that says how a
|
|
80
|
+
choice prints but is no string (`binding-type-mismatch`); and an
|
|
81
|
+
override for a form version that says both a path and nothing, or
|
|
82
|
+
neither, or prints nothing of a field that may not be null
|
|
83
|
+
(`invalid-form-override`).
|
|
33
84
|
|
|
34
|
-
|
|
35
|
-
|
|
85
|
+
**Read from a form.** A dataset contract may say what of a formancy
|
|
86
|
+
form's submissions it reads, and each of its fields where:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
{ id: 'visit', form: { kind: 'submission' }, fields: [{ id: 'inspector', type: 'string', label: 'Inspector', nullable: true, form: { path: 'inspector.name' } }] }
|
|
90
|
+
{ id: 'findings', form: { kind: 'repeater', repeater: 'findings' }, fields: [{ id: 'severity', type: 'string', label: 'Severity', nullable: true, form: { path: 'severity', read: 'value' } }] }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
A path is in the dataset's scope, the submission's or a repeater row's; a
|
|
94
|
+
`member` names a matrix row or an option of ticked boxes; a choice prints
|
|
95
|
+
its label, or its stored value with `read: 'value'`. The label has no
|
|
96
|
+
spelling of its own, and `read: 'label'` is refused, so that one binding
|
|
97
|
+
has one hash. The binding names no form, and is part of the report's hash. Whether a version of a
|
|
98
|
+
form holds a field there is `@formancy/report-forms`' to say, per render;
|
|
99
|
+
`isFormPath` is the syntax a path is held to.
|
|
100
|
+
|
|
101
|
+
**Overridden per version.** A review of a form version
|
|
102
|
+
([0048](../../docs/decisions/0048-a-form-version-that-removes-moves-or-retypes-a-field-a-report-reads-blocks-that-reports-submissions-of-it-until-reviewed-anything-else-prints.md))
|
|
103
|
+
writes what it decided on the binding, keyed by the version's
|
|
104
|
+
`schemaHash`: a field's `overrides` read it at a path in that version,
|
|
105
|
+
`{ path }`, or print nothing of it from that version, `{ omit: true }`,
|
|
106
|
+
which only a field that may be null takes (`FieldFormOverride`); the
|
|
107
|
+
detail's read its rows from a repeater, `{ repeater }`. Every version not
|
|
108
|
+
named reads the binding's own path, and an override may read that own
|
|
109
|
+
path too: a followed rename names so the version it moved the binding
|
|
110
|
+
to. At least one override, at most `MAX_FORM_OVERRIDES`, each key a hash,
|
|
111
|
+
and all of them part of the report's hash, in no order.
|
|
112
|
+
|
|
113
|
+
A message names the field and the rule, and never quotes a payment code's
|
|
114
|
+
text. It reports up to `MAX_ERRORS` errors and says when there were more.
|
|
115
|
+
It checks structure, and what a payment code's literal texts say: whether
|
|
116
|
+
an expression compiles, what a code's data resolves to, and whether the
|
|
36
117
|
rendered output fits, are the runtime's and the renderer's questions.
|
|
37
118
|
|
|
119
|
+
## Several tables
|
|
120
|
+
|
|
121
|
+
A report may hold up to `MAX_TABLES` tables over its detail dataset
|
|
122
|
+
([0062](../../docs/decisions/0062-a-report-holds-several-tables-over-its-detail-rows-each-printing-and-totalling-the-rows-its-condition-selects.md)), each where a table may stand: in the body and the
|
|
123
|
+
summary, and in a section there. Each prints the detail rows its own
|
|
124
|
+
`rowsWhen` selects, an expression read once a row in the row's scope,
|
|
125
|
+
before anything is ordered; absent, every row. Its sort keys, group,
|
|
126
|
+
empty text and totals act on those rows alone:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
{
|
|
130
|
+
id: 'services',
|
|
131
|
+
kind: 'table',
|
|
132
|
+
dataset: 'detail',
|
|
133
|
+
rowsWhen: { cel: 'row.kind == "service"' },
|
|
134
|
+
columns: [/* its own */],
|
|
135
|
+
sort: [{ field: { dataset: 'detail', field: 'amount' }, direction: 'desc' }],
|
|
136
|
+
totals: [{ cells: [{ column: 'amount', value: { kind: 'aggregate', aggregate: 'net', over: 'table' } }] }],
|
|
137
|
+
emptyText: 'No services on this order.',
|
|
138
|
+
repeatHeader: true,
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
A table's total rows are read in a scope of their own, `table`
|
|
143
|
+
(`VALUE_SCOPES`), which binds what the report's scope binds and
|
|
144
|
+
`table`: each declared aggregate over the rows the table prints. A
|
|
145
|
+
group's header and footer read `table` too (`EXPRESSION_NAMES`), and an
|
|
146
|
+
aggregate run is taken `over: 'table'` (`AGGREGATE_SCOPES`) there and
|
|
147
|
+
nowhere else. `totals` is every detail row's wherever it is read. A
|
|
148
|
+
report that is an e-invoice holds one table, which selects every row,
|
|
149
|
+
since its lines are every detail row. A release that predates it, 0.2.0
|
|
150
|
+
among them, refuses a second table as `second-detail-table`, a condition
|
|
151
|
+
as `unknown-property` and a total over a table as `not-one-of`.
|
|
152
|
+
|
|
153
|
+
## A table's group
|
|
154
|
+
|
|
155
|
+
A table groups the rows it prints by one detail field, one level in
|
|
156
|
+
version 0: its `group` names the field (`by`) and its order, a
|
|
157
|
+
header of runs read once per group, its style, and the footer rows that
|
|
158
|
+
total the group. A group header is kept on its page with the group's first
|
|
159
|
+
row; `keepWithRows` states how many of its first rows instead
|
|
160
|
+
([0059](../../docs/decisions/0059-a-group-header-is-kept-on-its-page-with-as-many-of-its-groups-first-rows-as-the-report-states-or-as-fit.md)).
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
import { MAX_KEEP_WITH_ROWS } from '@formancy/report-spec'
|
|
164
|
+
|
|
165
|
+
// An order's lines, grouped by delivery:
|
|
166
|
+
const group = {
|
|
167
|
+
by: { dataset: 'detail', field: 'delivery' },
|
|
168
|
+
direction: 'asc',
|
|
169
|
+
header: [{ kind: 'field', field: { dataset: 'detail', field: 'delivery' } }],
|
|
170
|
+
keepWithRows: 3,
|
|
171
|
+
footer: [],
|
|
172
|
+
} as const
|
|
173
|
+
// keepWithRows 0 or 33: out-of-range at /group/keepWithRows. 2.5: not-an-integer. '3': wrong-type.
|
|
174
|
+
MAX_KEEP_WITH_ROWS // 32: chosen, not measured
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
- **A whole number from 1 to `MAX_KEEP_WITH_ROWS`**; absent, it is one,
|
|
178
|
+
the rule every group header has had. One written out is accepted, as a
|
|
179
|
+
flag's default is, and hashes apart from the member's absence.
|
|
180
|
+
- **The group's own**, so that each level of a later nesting states its
|
|
181
|
+
own; on the table it is `unknown-property`.
|
|
182
|
+
|
|
183
|
+
What it does not check: whether that many rows fit on a page under the
|
|
184
|
+
table's column header, which only the data says. 0059 has the runtime
|
|
185
|
+
resolve the count against the group it made, and the renderer keep as many
|
|
186
|
+
of them as fit.
|
|
187
|
+
|
|
188
|
+
## A QR-bill
|
|
189
|
+
|
|
190
|
+
A report may carry one payment part, `paymentPart`: a Swiss QR-bill, printed
|
|
191
|
+
at the foot of its last page
|
|
192
|
+
([0022](../../docs/decisions/0022-a-report-carries-one-swiss-qr-bill-at-the-foot-of-its-last-page.md)).
|
|
193
|
+
Its texts are runs, as a paragraph's: the account, both parties' structured
|
|
194
|
+
addresses, the reference, the message and the billing information. Its
|
|
195
|
+
amount is an expression; its language is one of SIX's five, its currency
|
|
196
|
+
CHF or EUR.
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import { checkQrBillAccount, checkQrBillAmount, checkQrBillReference, checkQrBillText, emptyReport, QR_BILL_ADDRESS_RULES, QR_BILL_SIZE, QR_BILL_TOP, qrBillPageBreak, qrBillPairing } from '@formancy/report-spec'
|
|
200
|
+
|
|
201
|
+
checkQrBillAccount('CH44 3199 9123 0008 8901 2') // { ok: true, value: { iban: 'CH4431999123000889012', qrIban: true } }
|
|
202
|
+
checkQrBillReference('RF18 5390 0754 7034') // { ok: true, value: { type: 'SCOR', reference: 'RF18539007547034' } }
|
|
203
|
+
checkQrBillText('Seldwyla ', QR_BILL_ADDRESS_RULES.town) // { ok: true, value: 'Seldwyla' }
|
|
204
|
+
checkQrBillAmount('1191.005') // { ok: false, rule: 'has more than two decimals; ...' }
|
|
205
|
+
qrBillPairing('qrIban', 'SCOR', 'CHF') // [{ field: 'reference', rule: 'a QR-IBAN is paid to with a QR reference, ...' }]
|
|
206
|
+
QR_BILL_SIZE // { width: 595.28, height: 297.64 }: 210 by 105 mm
|
|
207
|
+
QR_BILL_TOP // 544.25: the slip's top, in points down the A4 page
|
|
208
|
+
const { page } = emptyReport('invoice', 'Rechnung', 'de-CH') // A4 portrait, 20 mm margins
|
|
209
|
+
qrBillPageBreak(page) // undefined: the slip has its room
|
|
210
|
+
qrBillPageBreak({ ...page, margins: { ...page.margins, top: 544.26 } }) // { field: 'topMargin', rule: "the top margin reaches 544.26 pt down the page, past the top of the QR-bill's slip at 544.25 pt, ..." }
|
|
211
|
+
qrBillPageBreak(page, 500) // the same rule, 500 pt a render measured above the slip counted with the margin: 'the top margin, with the page header ..., reaches 556.69 pt ...'
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
These are the rules of SIX's Swiss Implementation Guidelines for the
|
|
215
|
+
QR-bill, version 2.3, and version 2.4's QR-IBAN and QR reference for CHF
|
|
216
|
+
only. The validator applies them to a text no data can change; the runtime
|
|
217
|
+
applies the same functions to what the data resolves a text to. A rule
|
|
218
|
+
broken is said without the value. `qrBillPageBreak` is the page's rule:
|
|
219
|
+
the validator passes the page alone, and the renderer, which reaches it
|
|
220
|
+
through the runtime, adds the page header's height and the instruction to
|
|
221
|
+
separate above the slip, so a header that reaches into the slip is
|
|
222
|
+
refused only by a render, in the same words. What they do not check:
|
|
223
|
+
|
|
224
|
+
- that a country code is one ISO 3166-1 assigns, beyond two capitals;
|
|
225
|
+
- the syntax of the billing information past its leading `//` and the
|
|
226
|
+
two characters that name it;
|
|
227
|
+
- a postal code written with its country's prefix, which SIX forbids and
|
|
228
|
+
no pattern tells from a country whose codes begin with letters;
|
|
229
|
+
- the code's 997 characters, which only the whole bill has.
|
|
230
|
+
|
|
231
|
+
`QR_BILL_EXAMPLE_ACCOUNTS` lists the accounts of SIX's examples (IG 2.4,
|
|
232
|
+
Annex A), as the code holds them: accounts to test with, which pay no
|
|
233
|
+
creditor. `QR_BILL_EXAMPLE` is what a builder starts a bill from, as SIX
|
|
234
|
+
prints it: example 3's account and creditor, example 1's debtor, and
|
|
235
|
+
example 1's QR reference, which a bill whose account is made a QR-IBAN is
|
|
236
|
+
given. report-core warns of a bill that holds any of them, written in the
|
|
237
|
+
report
|
|
238
|
+
([0039](../../docs/decisions/0039-a-person-selects-a-reports-qr-bill-and-edits-it-field-by-field-in-either-builder.md)).
|
|
239
|
+
|
|
240
|
+
## An EPC QR code
|
|
241
|
+
|
|
242
|
+
A component, `epcQrCode`, prints the code a SEPA credit transfer is
|
|
243
|
+
initiated from: the European Payments Council's EPC069-12, version 3.1
|
|
244
|
+
([0025](../../docs/decisions/0025-a-report-prints-an-epc-qr-code-held-to-the-epc-rules-beside-the-qr-bill.md)).
|
|
245
|
+
It stands wherever a QR code may; Austria's PSA asks for the lower edge of
|
|
246
|
+
the page, where the author puts it. Its beneficiary, IBAN, BIC, reference,
|
|
247
|
+
text and information are runs, as a paragraph's; its amount is an
|
|
248
|
+
expression; its purpose is four capital letters; and its `caption`,
|
|
249
|
+
`'zahlenMitCode'`, draws Austria's frame and "Zahlen mit Code" inside its
|
|
250
|
+
square. A reference and a text are never both given.
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
import { checkEpcAmount, checkEpcField, checkEpcIban, checkEpcReference, epcCaptionBreak, epcLeastVersion, epcPairing, epcPayload } from '@formancy/report-spec'
|
|
254
|
+
|
|
255
|
+
checkEpcIban('de71 1102 2033 0123 4567 89') // { ok: true, value: 'DE71110220330123456789' }
|
|
256
|
+
checkEpcIban('FO2000400440116243') // { ok: false, rule: 'is not the IBAN of an account in SEPA: ...' }
|
|
257
|
+
checkEpcIban('CH44 3199 9123 0008 8901 2') // { ok: false, rule: 'is a QR-IBAN, which SIX keeps for QR-bills in francs ...' }
|
|
258
|
+
checkEpcReference('rf18 5390 0754 7034') // { ok: true, value: 'RF18539007547034' }: the QR-bill's own check, then capitals
|
|
259
|
+
checkEpcField('information', ' ') // { ok: false, rule: 'is blank, and an element the code holds has one character at least ...' }
|
|
260
|
+
checkEpcAmount('184.60') // { ok: true, value: '184.6' }: as short as it can be written
|
|
261
|
+
epcPairing('CH9300762011623852957', null) // [{ field: 'bic', rule: "an account outside the EEA is paid to with its bank's BIC: ..." }]
|
|
262
|
+
epcPayload({ bic: 'BHBLDEHHXXX', beneficiary: 'Franz Mustermänn', iban: 'DE71110220330123456789', amount: '12.3', purpose: 'GDDS', reference: 'RF18539007547034' })
|
|
263
|
+
// 'BCD\n001\n1\nSCT\nBHBLDEHHXXX\nFranz Mustermänn\n...\nRF18539007547034': the EPC's first sample, byte for byte
|
|
264
|
+
epcCaptionBreak(68.05) // 'with the caption, a code needs a square of at least 68.06 pt, and this one is 68.05 pt: ...'
|
|
265
|
+
epcLeastVersion(85.04, 'zahlenMitCode') // 8: version 7's modules would be 0.515 mm
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
What the code holds is SCT in euro, in UTF-8, at most 331 bytes, version
|
|
269
|
+
002 without a BIC and 001 with one. An IBAN is of a country of SEPA, of
|
|
270
|
+
its length and with its check digits right, and no QR-IBAN, which SIX
|
|
271
|
+
keeps for QR-bills in francs; a BIC is of a bank in SEPA, of the IBAN's
|
|
272
|
+
country -- this module's inference from EPC409-09's territory codes --
|
|
273
|
+
and given for an account outside the EEA. Which countries those are, and
|
|
274
|
+
each IBAN's length, is one table, recorded from EPC409-09 version 8.0 and,
|
|
275
|
+
for the lengths, python-stdnum's copy of release 101 of SWIFT's IBAN
|
|
276
|
+
Registry; SWIFT's own file was not read. The IBAN's check digits and the
|
|
277
|
+
creditor reference are checked by the QR-bill's own functions, and the
|
|
278
|
+
QR-IBAN's range is the QR-bill's; the IBAN and the reference are written
|
|
279
|
+
in capitals. An amount is from 0.01 to 999999999.99, never rounded, and
|
|
280
|
+
written as the PSA writes one: `EUR45`, `EUR184.6`. A free text holds no
|
|
281
|
+
control character or line break, which would end its line of the code.
|
|
282
|
+
No text is blank: `checkEpcField` refuses a blank name or IBAN as needed,
|
|
283
|
+
and a blank optional text as the text left out, by `EPC_TEXT_FIELDS`, the
|
|
284
|
+
one table of the code's texts the validator and the runtime read.
|
|
285
|
+
With the caption, `epcModule` and `epcCaptionBreak` hold the modules to
|
|
286
|
+
15 to 20 mil and the symbol to at least the caption's length, 51.36 pt in
|
|
287
|
+
Liberation Sans at 7 pt, since the caption stands beside it: the validator
|
|
288
|
+
refuses a size in which no version does both, which leaves squares of
|
|
289
|
+
68.06 to 118.6 pt, and the renderer the version it encodes. A payload too
|
|
290
|
+
short for its square is drawn in a larger version of itself, from
|
|
291
|
+
`epcLeastVersion`, rather than refused.
|
|
292
|
+
|
|
293
|
+
What they do not check:
|
|
294
|
+
|
|
295
|
+
- a purpose code against ISO 20022's list, beyond four capitals;
|
|
296
|
+
- that the amount a template binds is in euro: it is a decimal, and has no
|
|
297
|
+
currency;
|
|
298
|
+
- that a payer's bank is in the EEA, where a code without a BIC may be
|
|
299
|
+
refused outside it;
|
|
300
|
+
- a structured reference other than a creditor reference: a Belgian
|
|
301
|
+
structured communication is refused, and goes in the text;
|
|
302
|
+
- the payload's bytes before a render, beyond what the literal texts
|
|
303
|
+
write alone;
|
|
304
|
+
- that a bank's app accepts the code, which nothing here can show.
|
|
305
|
+
|
|
306
|
+
## An e-invoice
|
|
307
|
+
|
|
308
|
+
A report may carry one e-invoice, `eInvoice`: an EN 16931 invoice, which the
|
|
309
|
+
runtime writes as Factur-X 1.09.2 / ZUGFeRD 2.5.2 CII in the EN 16931 profile
|
|
310
|
+
([0027](../../docs/decisions/0027-a-report-carries-one-en-16931-invoice-written-from-the-values-its-page-prints.md)). It is of kind `facturX`, or of kind `xrechnung` (below), type 380, in euro, its VAT categories
|
|
311
|
+
standard rated, exempt or reverse-charged, with no allowances or charges: a
|
|
312
|
+
discount is a line of negative quantity at a positive price. Its seller, its
|
|
313
|
+
buyer, their addresses and its payment instructions are runs, as a
|
|
314
|
+
paragraph's, read in the report's scope and written into the XML, so none
|
|
315
|
+
holds a page number or count; its dates and its paid amount are
|
|
316
|
+
expressions. Its lines are the rows of the table over the detail dataset:
|
|
317
|
+
`lines` names that table and the four columns that print each line's name,
|
|
318
|
+
quantity, net price and net amount, so the page and the XML read one
|
|
319
|
+
evaluation of each line, and reads the line's identifier, unit and VAT
|
|
320
|
+
category from each row.
|
|
321
|
+
|
|
322
|
+
It may name four things a German B2B invoice does not need, and XRechnung
|
|
323
|
+
does ([0037](../../docs/decisions/0037-an-e-invoice-may-name-electronic-addresses-the-sellers-contact-and-its-business-process-none-needed-for-german-b2b.md)): its business process (`businessProcess`, BT-23), the
|
|
324
|
+
seller's and the buyer's electronic addresses (`electronicAddress`, BT-34
|
|
325
|
+
and BT-49, each an identifier and a scheme of `ADDRESS_SCHEMES`), and the
|
|
326
|
+
seller's contact (`contact`, BG-6: its name, telephone number and email
|
|
327
|
+
address, all three or none). The types are `ElectronicAddress`,
|
|
328
|
+
`AddressScheme` and `SellerContact`. An invoice that names none is written
|
|
329
|
+
as before, byte for byte.
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
import { checkAddressScheme, checkCountryCode, checkEInvoiceDecimal, checkEInvoiceText, checkVatIdentifier, checkVatRate, FACTUR_X, FACTUR_X_PROFILES, sellerIdentificationBreaks, vatCategoryBreaks } from '@formancy/report-spec'
|
|
333
|
+
|
|
334
|
+
checkCountryCode('UK') // { ok: false, rule: "is not a country code of those this release takes, a list narrower than ISO 3166-1's (BR-CL-14)" }
|
|
335
|
+
checkVatIdentifier('DE 123 456 789') // { ok: true, value: 'DE123456789' }
|
|
336
|
+
checkEInvoiceText('BT-1', ' ') // { ok: false, rule: 'is empty, and an e-invoice needs it (BR-02)' }
|
|
337
|
+
checkEInvoiceText('BT-84', 'DE83 0123 4567 0012 3456 78') // { ok: true, value: 'DE83012345670012345678' }: the EPC QR code's account rule
|
|
338
|
+
checkEInvoiceDecimal('BT-131', '10.500') // { ok: true, value: '10.50' }
|
|
339
|
+
checkEInvoiceDecimal('BT-131', '10.505') // { ok: false, rule: 'is not a whole number of cents, ... (BR-DEC-23)' }: never rounded
|
|
340
|
+
checkEInvoiceDecimal('BT-146', '-1') // { ok: false, rule: 'is negative, and a net price never is: ... (BR-27)' }
|
|
341
|
+
checkVatRate('S', '19.00') // { ok: true, value: '19' }: compared by value
|
|
342
|
+
checkVatRate('S', '0.4') // { ok: false, rule: 'is below 0.5, which BR-CO-17 rounds to 0, ... (BR-CO-17)' }
|
|
343
|
+
checkEInvoiceText('BT-37', ' ') // { ok: false, rule: 'is empty, and a German invoice gives the full address ... (§ 14 Abs. 4 Satz 1 Nr. 1 UStG)' }
|
|
344
|
+
checkEInvoiceText('BT-1', 'RE-2026 0820') // { ok: false, rule: 'holds white space the XML would not keep: ...' }: a token
|
|
345
|
+
checkAddressScheme('0060') // { ok: false, rule: "is not an electronic address scheme of those this release takes, ... (BR-CL-25)" }
|
|
346
|
+
checkEInvoiceText('BT-42', 'Zentrale') // { ok: false, rule: "has fewer than three digits, which a telephone number has at least (XRechnung's BR-DE-27)" }
|
|
347
|
+
vatCategoryBreaks([{ code: 'S', rate: '19' }, { code: 'S', rate: '19.00' }]) // [{ index: 1, field: 'rate', rule: '... (BR-S-08)' }]
|
|
348
|
+
sellerIdentificationBreaks({ vatId: false, taxNumber: true, legalId: false }, ['S']) // ['the seller has neither a VAT identifier (BT-31) nor a legal registration identifier (BT-30), ... (BR-CO-26)']
|
|
349
|
+
FACTUR_X_PROFILES.en16931.guideline // 'urn:cen.eu:en16931:2017': BT-24
|
|
350
|
+
FACTUR_X.fileName // 'factur-x.xml'
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
`en16931.ts` and the `en16931-*.ts` beside it, one for each kind of term,
|
|
354
|
+
hold EN 16931's rules as functions over text, each answering
|
|
355
|
+
the value the XML is written with or the rule broken, named by its business
|
|
356
|
+
term and its business rule and never by the value. The validator applies
|
|
357
|
+
them to a literal; the runtime applies the same functions to what the data
|
|
358
|
+
resolves a text to, and names its refusals by the same tables,
|
|
359
|
+
`E_INVOICE_TEXTS`, `E_INVOICE_DECIMALS` and `E_INVOICE_DATES`, and
|
|
360
|
+
reads which term each text is by where it stands from one table,
|
|
361
|
+
`E_INVOICE_TEXT_TERMS`, as each line term names its own; a date
|
|
362
|
+
the data resolved is held to a day on the calendar by `checkEInvoiceDate`,
|
|
363
|
+
since the editing core types a date term as any text.
|
|
364
|
+
`EN16931_RULES` is every rule they name, and the e-invoice gate holds each
|
|
365
|
+
to a fatal rule of its pinned schematron. Two things they hold are not
|
|
366
|
+
CEN's: the seller's and the buyer's street, post code and city, which
|
|
367
|
+
§ 14 Abs. 4 Satz 1 Nr. 1 UStG asks for (`FULL_ADDRESS`), where CEN asks
|
|
368
|
+
only the country; and an identifier or a code the XSD types as a token,
|
|
369
|
+
which holds no tab, line break, double space or space at either end, since
|
|
370
|
+
a schema-aware reader collapses them. The payment account and its BIC are
|
|
371
|
+
the EPC QR code's rules. A contact's telephone number and email address
|
|
372
|
+
are held to the shapes XRechnung warns of, BR-DE-27 and BR-DE-28, in every
|
|
373
|
+
e-invoice: each the pinned schematron's own XPath expression, exported as
|
|
374
|
+
`XRECHNUNG_PATTERNS`, its rule id in `XRECHNUNG_RULES`, which the
|
|
375
|
+
e-invoice gate holds, with the test that reads each expression, to KoSIT's
|
|
376
|
+
XRechnung schematron as it holds `EN16931_RULES` to CEN's. The email
|
|
377
|
+
address's expression runs as XPath reads it; the telephone number's three
|
|
378
|
+
ASCII digits are counted, which is what its expression asks, since the
|
|
379
|
+
expression run as written takes time that grows with the square of a
|
|
380
|
+
text's length, and a test holds the count to the expression on every
|
|
381
|
+
short text. Both are reached through `checkEInvoiceText('BT-42', …)` and
|
|
382
|
+
`('BT-43', …)`. The totals and the VAT breakdown are not here: the
|
|
383
|
+
runtime computes them once.
|
|
384
|
+
|
|
385
|
+
A report that is an e-invoice gives its expressions three names beside
|
|
386
|
+
`EXPRESSION_NAMES`'s, and no other report has them (`E_INVOICE_NAMES`):
|
|
387
|
+
`invoice`, whose members `INVOICE_TOTALS` names by business term, and
|
|
388
|
+
`vatBasis` and `vatAmount`, each declared category's taxable and tax
|
|
389
|
+
amount by its id (`VAT_BREAKDOWN`). Whether an expression reads them
|
|
390
|
+
where it may is the editing core's to check, as every name is.
|
|
391
|
+
`E_INVOICE_LINE_COLUMNS` and `E_INVOICE_LINE_CODES` say which types of
|
|
392
|
+
field each term of a line is read from: the validator holds a field to
|
|
393
|
+
them, and the editing core an expression.
|
|
394
|
+
|
|
395
|
+
The codes come from closed lists that someone chose, narrower than CEN's,
|
|
396
|
+
and held to CEN's 1.3.17 and the pinned 1.3.16 lists on 17 October 2026:
|
|
397
|
+
`UNIT_CODES`, the units of UN/ECE Recommendation 20 a German invoice
|
|
398
|
+
counts, times, weighs and measures in; `COUNTRY_CODES`, the
|
|
399
|
+
EU's members, the EEA's, Switzerland and the United Kingdom; `VAT_PREFIXES`,
|
|
400
|
+
those and Greece's `EL`, which CEN's 1.3.16 takes and its 1.3.17 does not;
|
|
401
|
+
and `SCHEME_IDS`, SIREN, SIRET, D-U-N-S and GLN; and, since 0037,
|
|
402
|
+
`ADDRESS_SCHEMES`, an electronic address's: an email address, the
|
|
403
|
+
Leitweg-ID, France's addressing scheme, a German VAT identifier and a GLN.
|
|
404
|
+
A rate is a percentage
|
|
405
|
+
below 100 with two decimals at most, and a standard rate 0.5 or more, which
|
|
406
|
+
BR-CO-17 would otherwise round to 0. `FACTUR_X` and `FACTUR_X_PROFILES` are
|
|
407
|
+
the names the PDF carries -- the file, its relationship and the XMP's values
|
|
408
|
+
-- which rest on a transcription of the specification, not on the
|
|
409
|
+
specification itself, until the owner's copy is read.
|
|
410
|
+
|
|
411
|
+
What they do not check:
|
|
412
|
+
|
|
413
|
+
- that a VAT identifier is one its country issued, past its prefix;
|
|
414
|
+
- that a rate is one a country applies, or the right one for a line;
|
|
415
|
+
- that an exemption reason says what the law says;
|
|
416
|
+
- the amount a payment code asks for, which is an expression: the render
|
|
417
|
+
compares it with the amount due;
|
|
418
|
+
- an account, a date or a total read from the data, before a render;
|
|
419
|
+
- that an electronic address is of its scheme's form, a GLN's check digit
|
|
420
|
+
among it, but for a Leitweg-ID's under 0204 (below);
|
|
421
|
+
- France's rules (BR-FR).
|
|
422
|
+
|
|
423
|
+
## An XRechnung
|
|
424
|
+
|
|
425
|
+
An e-invoice of kind `xrechnung` is an XRechnung 3.0, KoSIT's CIUS of EN
|
|
426
|
+
16931 a German public buyer asks for, written as CII alone
|
|
427
|
+
([0038](../../docs/decisions/0038-a-reports-e-invoice-may-be-an-xrechnung-3-0-whose-xml-a-host-takes-and-whose-pdf-is-its-labelled-copy.md)). It holds
|
|
428
|
+
every term a Factur-X invoice does, by the same rules, with `version`, of
|
|
429
|
+
`XRECHNUNG_VERSIONS`, where Factur-X has its profile; `XRECHNUNG` names
|
|
430
|
+
each version's specification identifier (BT-24), KoSIT's `XR-CIUS-ID`, the
|
|
431
|
+
release of KoSIT's it was read from, 3.0.2, and its syntax. The type is
|
|
432
|
+
`XRechnungInvoice`, and the terms both kinds hold `EInvoiceTerms`.
|
|
433
|
+
|
|
434
|
+
It needs what XRechnung's schematron needs past EN 16931, each refused
|
|
435
|
+
where it is missing by the fatal rule that needs it (`XRECHNUNG_NEEDS`):
|
|
436
|
+
the business process (PEPPOL-EN16931-R001), the buyer's reference, a
|
|
437
|
+
public buyer's Leitweg-ID (BR-DE-15), the payment instructions (BR-DE-1),
|
|
438
|
+
the seller's contact (BR-DE-2) and both electronic addresses
|
|
439
|
+
(PEPPOL-EN16931-R020, -R010); and each of those texts, and the contact's
|
|
440
|
+
three (BR-DE-5 to -7), to say something (`XRECHNUNG_TEXT_NEEDS`). Its texts
|
|
441
|
+
are held by `E_INVOICE_KIND_TEXTS.xrechnung`, EN 16931's table with those
|
|
442
|
+
needed and its payment terms held to BR-DE-18: no line of them may begin
|
|
443
|
+
with `#`, which XRechnung reads as a Skonto line of its own syntax, and
|
|
444
|
+
this release writes no Skonto (`skontoBreak`). A refusal names the rule as
|
|
445
|
+
XRechnung's, `(XRechnung's BR-DE-15)`. The rules no refusal names, since
|
|
446
|
+
nothing the format can say breaks them, are in `XRECHNUNG_HELD`, each with
|
|
447
|
+
what holds it; the e-invoice gate holds every id of both lists to a rule of
|
|
448
|
+
KoSIT's pinned XRechnung schematron, the test of each rule a need names to
|
|
449
|
+
the element the runtime writes the term as, and the context and test of
|
|
450
|
+
each held rule to the ones its reason was read against, so that one KoSIT
|
|
451
|
+
rewrites fails the gate; and `XRECHNUNG`'s guideline and release to the
|
|
452
|
+
schematron's `XR-CIUS-ID` and to the release the register pins.
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
import { checkEInvoiceText, checkElectronicAddress, leitwegIdBreak, skontoBreak, XRECHNUNG } from '@formancy/report-spec'
|
|
456
|
+
|
|
457
|
+
XRECHNUNG['3.0'].guideline // 'urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0'
|
|
458
|
+
checkEInvoiceText('BT-10', ' ', 'xrechnung') // { ok: false, rule: "is empty, and an XRechnung needs it (XRechnung's BR-DE-15)" }
|
|
459
|
+
checkEInvoiceText('BT-10', ' ') // { ok: false, rule: 'is blank: a term the e-invoice does not hold is left out of it' }: a Factur-X invoice may leave it out
|
|
460
|
+
skontoBreak('Zahlbar binnen 14 Tagen\n#SKONTO#TAGE=14#PROZENT=2.00#\n') // "hold a line that begins with #, ... (XRechnung's BR-DE-18)"
|
|
461
|
+
checkElectronicAddress('BT-49', '0204', '991-33333TEST-34') // { ok: false, rule: "is under 0204, a Leitweg-ID, and has check digits that do not match the rest of it (the Leitweg-ID's check digits, ISO/IEC 7064 MOD 97-10)" }
|
|
462
|
+
leitwegIdBreak('991-33333TEST-33') // undefined: KoSIT's own test value
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
**A Leitweg-ID** is checked where scheme `0204` says an electronic address
|
|
466
|
+
is one, in an e-invoice of either kind: a coarse address of 2 to 12
|
|
467
|
+
digits, a fine address of up to 30 letters and digits where it has one,
|
|
468
|
+
and two check digits by ISO/IEC 7064 MOD 97-10, joined by hyphens
|
|
469
|
+
(`leitwegIdBreak`). The buyer's reference is not: a business buyer's
|
|
470
|
+
XRechnung carries an order number there, and BR-DE-15 asks only that it be
|
|
471
|
+
given. Neither validator the gate runs checks a Leitweg-ID's digits; the
|
|
472
|
+
format specification could not be read when this was written, so its
|
|
473
|
+
shape rests on FeRD's description of it and on KoSIT's test suite, whose
|
|
474
|
+
every Leitweg-ID with right digits it takes, and whose three with wrong
|
|
475
|
+
digits, which KoSIT's validator takes, it refuses. The expression is
|
|
476
|
+
anchored at both ends and its repeats bounded, so a text of any length is
|
|
477
|
+
decided within its first 46 characters.
|
|
478
|
+
|
|
479
|
+
What it does not do:
|
|
480
|
+
|
|
481
|
+
- **UBL.** CII alone: KoSIT's configuration has UBL scenarios, which a
|
|
482
|
+
second writer of one invoice would need.
|
|
483
|
+
- **A Skonto.** XRechnung 3.0's `#SKONTO#` lines are refused, not written;
|
|
484
|
+
a structured discount waits for XRechnung 4.0.
|
|
485
|
+
- **XRechnung 4.0**, the extension and CVD scenarios, credit notes, and
|
|
486
|
+
anything EN 16931's terms here do not hold.
|
|
487
|
+
- That a Leitweg-ID belongs to a buyer, or that a portal takes the file.
|
|
488
|
+
|
|
489
|
+
## A run below or above the line
|
|
490
|
+
|
|
491
|
+
A run of a text's paragraph may be set below the line, a formula's digit,
|
|
492
|
+
or above it, a unit's power, an exponent or a footnote's mark, in any
|
|
493
|
+
character its face draws
|
|
494
|
+
([0061](../../docs/decisions/0061-a-paragraphs-run-may-be-set-below-or-above-the-line-in-any-character-its-face-draws-and-prints-only-beside-a-run-on-the-line.md)):
|
|
495
|
+
|
|
496
|
+
```ts
|
|
497
|
+
import { BASELINE_SHIFTS } from '@formancy/report-spec'
|
|
498
|
+
|
|
499
|
+
BASELINE_SHIFTS // ['subscript', 'superscript']
|
|
500
|
+
const formula = {
|
|
501
|
+
id: 'formula', kind: 'text',
|
|
502
|
+
content: [
|
|
503
|
+
{ kind: 'text', text: 'H' },
|
|
504
|
+
{ kind: 'text', text: '2', baseline: 'subscript' },
|
|
505
|
+
{ kind: 'text', text: 'O, 10' },
|
|
506
|
+
{ kind: 'field', field: { dataset: 'header', field: 'exponent' }, baseline: 'superscript' },
|
|
507
|
+
],
|
|
508
|
+
} as const
|
|
509
|
+
// In a table column's value: misplaced-baseline at /regions/body/0/columns/0/value/baseline.
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
- **A property of the run.** Literal text, a field, a parameter, an
|
|
513
|
+
expression and an aggregate take an optional `baseline`, one of
|
|
514
|
+
`BASELINE_SHIFTS`; absent, the run stands on the line. A page number and
|
|
515
|
+
a page count take none (`unknown-property`).
|
|
516
|
+
- **In a paragraph alone**, in any region. What a QR code, an EPC QR code,
|
|
517
|
+
a QR-bill or an e-invoice encodes is its text alone, and a table's cell,
|
|
518
|
+
footer cell, totals cell or group header prints one string at one size,
|
|
519
|
+
so a `baseline` there is refused as `misplaced-baseline`, whatever its
|
|
520
|
+
value.
|
|
521
|
+
- **Part of the hash.** A report that sets none validates and hashes as it
|
|
522
|
+
did.
|
|
523
|
+
|
|
524
|
+
What it does not check: whether the run prints beside a run on the line,
|
|
525
|
+
which only the data and the engine's line breaks say, and the size and the
|
|
526
|
+
move it prints at, which are not the format's but the resolved document's,
|
|
527
|
+
report-runtime's `SHIFTED_SIZE` and `SHIFTED_RISE`.
|
|
528
|
+
|
|
529
|
+
## A chart
|
|
530
|
+
|
|
531
|
+
A component, `chart`, is a bar, line or pie chart of the detail rows
|
|
532
|
+
([0052](../../docs/decisions/0052-a-report-draws-a-bar-line-or-pie-chart-of-its-detail-rows-each-series-a-total-of-one-field-per-category.md)).
|
|
533
|
+
Its categories are the values of one detail field, and each of its series
|
|
534
|
+
a total of one detail field for each category, by a function an aggregate
|
|
535
|
+
takes. Its types and lists are `chart.ts`'s, and `validate-chart.ts` holds
|
|
536
|
+
a chart to them where it is written.
|
|
537
|
+
|
|
538
|
+
```ts
|
|
539
|
+
import { CHART_PALETTE, MAX_CHART_SERIES, MIN_CHART_SIDE, PIE_FUNCTIONS } from '@formancy/report-spec'
|
|
540
|
+
|
|
541
|
+
// In the body, over a detail dataset whose `area` is a string that may be null and whose `hours` is a decimal:
|
|
542
|
+
const chart = {
|
|
543
|
+
id: 'hours-by-area', kind: 'chart', chart: 'bar', dataset: 'detail', width: 400, height: 200,
|
|
544
|
+
category: { field: { dataset: 'detail', field: 'area' }, order: 'data', nullLabel: 'No area' },
|
|
545
|
+
series: [
|
|
546
|
+
{ id: 'hours', label: 'Hours', fn: 'sum', of: { dataset: 'detail', field: 'hours' } },
|
|
547
|
+
{ id: 'findings', label: 'Findings', fn: 'count' },
|
|
548
|
+
],
|
|
549
|
+
valueFormat: { kind: 'number', scale: 2, grouping: true },
|
|
550
|
+
emptyText: 'No findings.',
|
|
551
|
+
} as const
|
|
552
|
+
// Without `nullLabel`: missing-property at /category/nullLabel. As a pie of two series: invalid-chart at /series.
|
|
553
|
+
CHART_PALETTE[1] // '#d95f02': the second series' colour, unless the chart names a palette of its own
|
|
554
|
+
MAX_CHART_SERIES // 8: a series a colour of the palette
|
|
555
|
+
MIN_CHART_SIDE // 72: an inch, the least a side may be
|
|
556
|
+
PIE_FUNCTIONS // ['sum', 'count']: a pie is the shares of one total
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
- **Its kind of chart is a property**, `chart`, of `CHART_KINDS`, so a bar
|
|
560
|
+
chart becomes a line chart in place.
|
|
561
|
+
- **Its box** is `width` and `height` in points, each at least
|
|
562
|
+
`MIN_CHART_SIDE` and within the printable area, as an image's. It
|
|
563
|
+
stands in the body and the summary, and in a section, a columns block or
|
|
564
|
+
a keep-together block there.
|
|
565
|
+
- **Its category** is a detail field of `CHART_CATEGORY_TYPES` -- text, a
|
|
566
|
+
date, an integer or a decimal -- in the order the data first gives each
|
|
567
|
+
(`data`) or sorted by it (`asc`, `desc`), and printed in a format that
|
|
568
|
+
displays its type. A field that may be null asks for `nullLabel`, the
|
|
569
|
+
label its rows without one print under, never blank.
|
|
570
|
+
- **Its series**, one to `MAX_CHART_SERIES`, each with an id unique in the
|
|
571
|
+
chart, are `{ id, label, fn, of?, rounding? }`: one of the aggregates'
|
|
572
|
+
functions over a detail field, a count of rows where `of` is left out,
|
|
573
|
+
a sum, an average, a minimum or a maximum of an integer or a decimal,
|
|
574
|
+
and an average with its rounding. A series is no reference to a
|
|
575
|
+
declared aggregate.
|
|
576
|
+
- **Its values** print in one number or currency format, `valueFormat`,
|
|
577
|
+
read where the report is: a currency is a literal or a header field,
|
|
578
|
+
never a detail field.
|
|
579
|
+
- **Its colours** are `CHART_PALETTE`'s, a series' at its place and a
|
|
580
|
+
pie's slice at its category's: eight, each at least 3:1 against white
|
|
581
|
+
paper, which `chart.test.ts` computes. A chart's own `palette` of one to
|
|
582
|
+
eight colours replaces it, read the same way; a bar or a line chart's
|
|
583
|
+
has a colour for each series.
|
|
584
|
+
- **`invalid-chart`** refuses a blank series label, `emptyText` or
|
|
585
|
+
`nullLabel`, a palette that names a colour twice or, in a bar or a line
|
|
586
|
+
chart, has fewer colours than the chart has series, a pie of more than
|
|
587
|
+
one series, of a function outside `PIE_FUNCTIONS` or with an axis title,
|
|
588
|
+
and value labels on a line chart of several series. Its messages never
|
|
589
|
+
quote a label, a title or a value.
|
|
590
|
+
|
|
591
|
+
What they do not check:
|
|
592
|
+
|
|
593
|
+
- whether a chart's categories fit its box, or how many a pie has, and
|
|
594
|
+
so whether a pie's own palette has a colour for each slice, which only
|
|
595
|
+
the data says: the runtime refuses a pie of more categories than its
|
|
596
|
+
palette has colours when it renders
|
|
597
|
+
([0055](../../docs/decisions/0055-the-runtime-resolves-a-chart-exactly-its-totals-as-every-total-and-every-word-it-prints.md));
|
|
598
|
+
- what a chart prints, which the runtime resolves, and whether its words
|
|
599
|
+
fit its box, which the renderer reads once it has laid the chart out
|
|
600
|
+
([0058](../../docs/decisions/0058-the-renderer-lays-a-chart-out-with-apache-echarts-and-prints-its-marks-and-its-words-where-echarts-placed-them.md)).
|
|
601
|
+
|
|
602
|
+
## A report in several languages
|
|
603
|
+
|
|
604
|
+
A report is written in its own `locale`, and may declare `translations`:
|
|
605
|
+
for each other language, its words written in that language, each looked
|
|
606
|
+
up by its exact text in the report's own, and each expression that
|
|
607
|
+
prints words by its exact source ([0063](../../docs/decisions/0063-a-reports-own-words-are-written-in-each-language-it-declares-and-a-render-names-the-one-it-prints-in.md)). Its types and its
|
|
608
|
+
walk are `translation.ts`'s, the report written in one of its languages
|
|
609
|
+
`report-in.ts`'s, and `validate-translations.ts` holds a translation to
|
|
610
|
+
what it may be.
|
|
611
|
+
|
|
612
|
+
```ts
|
|
613
|
+
import { declaredLocales, isWord, MAX_LANGUAGES, MAX_WORDS, renderLocale, reportIn, reportWords, writtenIn } from '@formancy/report-spec'
|
|
614
|
+
import type { ReportDefinition, Translation } from '@formancy/report-spec'
|
|
615
|
+
|
|
616
|
+
const french: Translation = {
|
|
617
|
+
locale: 'fr-CH',
|
|
618
|
+
words: [{ word: 'Quantity', text: 'Quantité' }, { word: 'No lines.', text: 'Aucune ligne.' }],
|
|
619
|
+
expressions: [{ cel: 'row.count == 1 ? "item" : "items"', expression: { cel: 'row.count == 1 ? "article" : "articles"' } }],
|
|
620
|
+
}
|
|
621
|
+
declare const report: ReportDefinition // one the validator accepts, its translations [french]
|
|
622
|
+
reportWords(report) // each word at each place it stands: { path, text, componentId?, columnId? }
|
|
623
|
+
declaredLocales(report) // ['de-CH', 'fr-CH']: the report's own first
|
|
624
|
+
renderLocale(report, 'fr') // { ok: false, message: '"fr" is not a locale this report is written in; ...' }
|
|
625
|
+
reportIn(report, 'fr-CH') // the report in French, whole, locale 'fr-CH', no translations; throws where a word is missing
|
|
626
|
+
writtenIn(report, 'fr-CH') // the same, a missing word left in the report's own: what each language is validated as
|
|
627
|
+
isWord('12.50') // false: a text with no letter prints as written in every language
|
|
628
|
+
MAX_LANGUAGES // 24, the report's own among them
|
|
629
|
+
MAX_WORDS // 1024 words, and as many expressions, in each translation
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
- **The words** are the title; each literal run of a text, of a table's
|
|
633
|
+
cells, its group's header and its footer rows' cells; a table's column
|
|
634
|
+
headers and its empty text; a chart's titles, its empty text, the label
|
|
635
|
+
of its rows without a category and each series' label; and a QR-bill's
|
|
636
|
+
message. A literal is a word only where it holds a letter. Every other
|
|
637
|
+
string prints as written in every language -- a QR code's content, an
|
|
638
|
+
EPC QR code's texts, a bill's account, parties, reference and billing
|
|
639
|
+
information, an e-invoice's texts, a field's and a parameter's label, a
|
|
640
|
+
parameter's default, a table's row condition, so that a render selects
|
|
641
|
+
the same rows in every language -- and `NOT_WORDS`, beside the walk,
|
|
642
|
+
names each, which `words.test.ts` holds every string of the format to.
|
|
643
|
+
- **An expression run where a word stands** is translated whole, by its
|
|
644
|
+
source; which of them print words, report-core's diagnostics say.
|
|
645
|
+
- **The validator** holds a translation's shape: a locale written as the
|
|
646
|
+
report's is, never the report's own nor twice (`duplicate-language`), a
|
|
647
|
+
word that holds a letter (`not-a-word`), once in a language
|
|
648
|
+
(`duplicate-word`), and never translated blank (`blank-translation`).
|
|
649
|
+
Then it writes the report in each language and reads it again, so that
|
|
650
|
+
a translation is held to every rule each place of its word holds the
|
|
651
|
+
word to, and an error is reported at the translation, naming the place
|
|
652
|
+
and the language.
|
|
653
|
+
- **In a translation's locale** the QR-bill's headings are printed in that
|
|
654
|
+
locale's language where SIX has headings in it, and in the bill's own
|
|
655
|
+
where it has none. In the report's own locale the report prints as it
|
|
656
|
+
did, without its translations.
|
|
657
|
+
|
|
658
|
+
What they do not check: whether a language holds every word, which
|
|
659
|
+
report-core's `languageDiagnostics` says, and the runtime refuses a render
|
|
660
|
+
for.
|
|
661
|
+
|
|
662
|
+
## An SVG asset
|
|
663
|
+
|
|
664
|
+
An image asset may be `image/svg+xml`, held to one form: what `cleanSvg`
|
|
665
|
+
writes ([0030](../../docs/decisions/0030-an-image-asset-may-be-an-svg-of-drawing-elements-alone-cleaned-once-and-refused-at-print-in-any-other-form.md)).
|
|
666
|
+
A host approves a customer's SVG by cleaning it and keeping the bytes
|
|
667
|
+
`cleanSvg` returns, whose digest the asset carries; the renderer draws an
|
|
668
|
+
SVG only when `checkSvg` finds it already in that form, and refuses it
|
|
669
|
+
otherwise, so nothing is cleaned, dropped or rewritten at print.
|
|
670
|
+
|
|
671
|
+
```ts
|
|
672
|
+
import { checkSvg, cleanSvg } from '@formancy/report-spec'
|
|
673
|
+
|
|
674
|
+
const approved = cleanSvg(file) // the file's bytes; there is no TextDecoder in this package's world, and none is needed
|
|
675
|
+
// { ok: true, bytes: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><circle cx="20" cy="20" r="18" fill="#1f4e79"/></svg>,
|
|
676
|
+
// viewBox: { x: 0, y: 0, width: 40, height: 40 }, segments: 20, groups: 0, drawn: { lines: 2, curves: 6, elements: 2, stops: 0 },
|
|
677
|
+
// extent: { groups: { inverse: 0, origin: 0 }, patterns: { linear: 0, offset: 0 }, local: 0, own: 39.11426010499247, nesting: 3 },
|
|
678
|
+
// removed: [declaration, attribute width, attribute height, element title], removedMore: 0 }
|
|
679
|
+
checkSvg(approved.bytes) // { ok: true, … }: what cleanSvg wrote, unchanged
|
|
680
|
+
checkSvg(file) // { ok: false, code: 'unsupported', message: 'the drawing holds a declaration, which cleaning removes; clean it with cleanSvg first' }
|
|
681
|
+
cleanSvg(lettered) // { ok: false, code: 'text', message: 'svg/text is text; convert the text to outlines' }
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
What a cleaned SVG holds, in `svg-allow.ts`'s tables:
|
|
685
|
+
|
|
686
|
+
- **Drawing elements alone**, `SVG_ELEMENTS`: `g`, `defs`, the seven
|
|
687
|
+
shapes, linear and radial gradients and their stops, clip paths of
|
|
688
|
+
shapes. Text, embedded pictures, `use`, `symbol`, patterns, masks,
|
|
689
|
+
markers, filters, `foreignObject`, `switch` and a nested `svg` are
|
|
690
|
+
refused. Every refusal says what to do after what it found -- convert
|
|
691
|
+
the text to outlines, add the picture as an asset of its own, save it
|
|
692
|
+
without Illustrator's editing capabilities -- or, where it knows nothing
|
|
693
|
+
more particular, its code's own advice.
|
|
694
|
+
- **What never draws is removed and listed** -- comments, the declaration,
|
|
695
|
+
a plain DOCTYPE, titles, metadata, scripts, animations, an editor's
|
|
696
|
+
elements and attributes in their own namespaces, event handlers, data and
|
|
697
|
+
accessibility attributes, rendering hints, text and vendor-prefixed
|
|
698
|
+
properties, what draws nowhere on the element it is written on (paint
|
|
699
|
+
and clips on a gradient, a stop or `defs`, a stop's colour anywhere
|
|
700
|
+
else), hidden elements, shapes of no size, what nothing that draws
|
|
701
|
+
refers to, ids nothing refers to --
|
|
702
|
+
by name and count, never by value, the first `MAX_SVG_REMOVED_NAMES`
|
|
703
|
+
names and a count of the rest. A link is the group it draws as, its
|
|
704
|
+
address removed.
|
|
705
|
+
- **CSS flattened into attributes**: a `style` attribute and `<style>`
|
|
706
|
+
rules of types, classes, ids and their compounds, in CSS's cascade. A
|
|
707
|
+
combinator, an at-rule, `!important` or an escape is refused.
|
|
708
|
+
- **Colours as `#rrggbb`**, from `#rgb`, `#rrggbb`, `rgb()` and CSS
|
|
709
|
+
Color 4's names; one with an alpha, `hsl()`, `transparent` and the system
|
|
710
|
+
colours are refused. `currentColor` is written as the colour it stands
|
|
711
|
+
for.
|
|
712
|
+
- **References inside the file alone**: a fill or a stroke may name a
|
|
713
|
+
gradient, a clip path a clip path; a gradient's `href` chain is flattened
|
|
714
|
+
into it. Anything else that names anything is refused, so nothing outside
|
|
715
|
+
the file is ever read. A clip rule a clip path would inherit from what
|
|
716
|
+
holds it is written on it, so that its clip never rests on `defs`.
|
|
717
|
+
- **Absolute numbers in one written form**: path data in absolute commands
|
|
718
|
+
whose relative steps sum exactly, transforms composed into one matrix,
|
|
719
|
+
units converted, nothing below a millionth, and nothing past
|
|
720
|
+
`MAX_SVG_COORDINATE`: no number, no transform composed from the root and
|
|
721
|
+
no inverse of one, which the converter computes for every clip, and no
|
|
722
|
+
matrix a gradient is drawn under in any box inside its shape's, which
|
|
723
|
+
the converter's box of a curve is. The root keeps its namespace and its
|
|
724
|
+
viewBox alone; its paint and transform move onto a group inside it, so a
|
|
725
|
+
transform can never move the drawing off the report's box.
|
|
726
|
+
- **Bounded**: `MAX_SVG_BYTES` in and out, `MAX_SVG_DEPTH`,
|
|
727
|
+
`MAX_SVG_ELEMENTS`, `MAX_SVG_STOPS`, `MAX_SVG_DASHES`, `MAX_SVG_RULES`,
|
|
728
|
+
the cascade's work (`MAX_SVG_CASCADE`), and what a reader will paint:
|
|
729
|
+
`MAX_SVG_SEGMENTS` weighted segments, a clip path counted for every
|
|
730
|
+
element it clips and a gradient's stops for every shape painted with it,
|
|
731
|
+
and `MAX_SVG_GROUPS` units of page-sized transparency groups. Each bound
|
|
732
|
+
but `MAX_SVG_REMOVED_NAMES` says in `limits.ts` how it was measured, and
|
|
733
|
+
the reader's time is linear in the bytes: a mebibyte of each shape of
|
|
734
|
+
value a pattern could have made quadratic is cleaned in a test's
|
|
735
|
+
ceiling.
|
|
736
|
+
- **Its extent measured, `SvgExtent`** (`svg-extent.ts`): how far the
|
|
737
|
+
numbers svg-to-pdfkit writes for the drawing reach wherever it is
|
|
738
|
+
placed -- the inverses of the matrices its page-sized groups are drawn
|
|
739
|
+
under and where they take the viewBox's origin, the matrices its
|
|
740
|
+
gradients are drawn under outside a group and inside one, and the box
|
|
741
|
+
a clip in objectBoundingBox units clips to, each over every box inside
|
|
742
|
+
a shape's, and the points the converter draws its outlines with, an
|
|
743
|
+
arc's grown to reach its ends among them -- and how deep it nests the
|
|
744
|
+
graphics state. Nothing is refused by it here; the renderer holds an
|
|
745
|
+
image in a PDF/A to it, an e-invoice's PDF/A-3b or the PDF/A-2b a host
|
|
746
|
+
asks for, which holds an integer to 2,147,483,647 and the nesting to 28
|
|
747
|
+
([0057](../../docs/decisions/0057-a-report-that-is-no-e-invoice-is-drawn-as-a-pdf-a-2b-where-the-host-asks-for-one.md)).
|
|
748
|
+
|
|
749
|
+
Cleaning is a fixed point: `cleanSvg` of what it wrote gives the same bytes
|
|
750
|
+
with nothing removed, which is what `checkSvg` tests for.
|
|
751
|
+
|
|
752
|
+
**A host shows the approver the cleaned drawing, or the PDF, never the
|
|
753
|
+
file as uploaded.** A browser draws the file as it came, with what
|
|
754
|
+
cleaning removes: an animation runs to its end, where the PDF shows the
|
|
755
|
+
drawing before it starts, and a script may change what is drawn. The
|
|
756
|
+
cleaned bytes are what prints, and what an approver says yes to.
|
|
757
|
+
|
|
758
|
+
What it does not do: draw text, inline `use`, convert
|
|
759
|
+
a colour with an alpha into an opacity, or follow a reference out of the
|
|
760
|
+
file; and that a browser draws the cleaned drawing as the PDF does is held
|
|
761
|
+
by the tables and review, not by comparing the two.
|
|
762
|
+
|
|
763
|
+
## An image's bytes
|
|
764
|
+
|
|
765
|
+
What an image a person adds is, and the digest a report pins it by, are
|
|
766
|
+
read here, so that a builder refuses at the door what the renderer would
|
|
767
|
+
refuse at every print, and names the image as the validator reads a name
|
|
768
|
+
(0033):
|
|
769
|
+
|
|
770
|
+
```ts
|
|
771
|
+
import { assetDigest, imageHeader, isDigest, sniffImage } from '@formancy/report-spec'
|
|
772
|
+
|
|
773
|
+
sniffImage(bytes) // 'image/png', 'image/jpeg' or 'image/svg+xml', by the first bytes alone; undefined for anything else
|
|
774
|
+
imageHeader(png) // { ok: true, mediaType: 'image/png', width: 120, height: 40, bitsPerPixel: 32, interlaced: false, data: every IDAT chunk's bytes, joined }
|
|
775
|
+
imageHeader(jpeg) // { ok: true, mediaType: 'image/jpeg', width: 40, height: 120, components: 3, orientation: 6 }: as it is shown, after its Exif turn
|
|
776
|
+
imageHeader(wide) // { ok: false, code: 'too-large', message: 'is 5000 × 300 pixels; the limit is 4096 pixels a side', width: 5000, height: 300 }
|
|
777
|
+
assetDigest(bytes) // 'sha256:' and 64 lower-case hex digits, what an asset's digest is
|
|
778
|
+
isDigest(value) // true where value is such a digest, by the rule a declaration is validated by
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
- **`sniffImage`** judges by a PNG's signature, a JPEG's start of image,
|
|
782
|
+
and `<` after an optional UTF-8 byte order mark and white space, never by
|
|
783
|
+
a file's name or a type a browser guessed. A UTF-16 or UTF-32 byte order
|
|
784
|
+
mark is an SVG too, so that `cleanSvg` can tell the person to save it as
|
|
785
|
+
UTF-8. A sniff is no check: the bytes are read whole next.
|
|
786
|
+
- **`imageHeader`** reads a PNG's chunks, each with its length and CRC,
|
|
787
|
+
the header, the palette it needs and the end chunk with nothing after
|
|
788
|
+
it; and a JPEG's segments up to its scan, the frame header where PDFKit
|
|
789
|
+
reads it, the first Exif block's orientation and the end marker. A
|
|
790
|
+
JPEG that block turns or mirrors says how, `orientation`, 2 to 8, with
|
|
791
|
+
its sides already the turned picture's, and an upright one says none:
|
|
792
|
+
the PDF draws it turned, and a writer that embeds the bytes as they are
|
|
793
|
+
and cannot say what its reader does with the tag, the Word writer,
|
|
794
|
+
refuses one that has it (0068). Its
|
|
795
|
+
refusals, `IMAGE_REFUSAL_CODES`, are in the words the renderer says them
|
|
796
|
+
in after an asset's name, and one of a picture's size carries the size.
|
|
797
|
+
A picture is held to `MAX_ASSET_SIDE` pixels a side, and every reader of
|
|
798
|
+
an asset's bytes to `MAX_ASSET_BYTES`. A PNG's image data comes back in
|
|
799
|
+
one array, copied once however many chunks it was split over, and
|
|
800
|
+
nothing of a chunk is kept but its length: a person's 20 MiB file can
|
|
801
|
+
hold 1,747,622 empty ones, which a view kept of each held in 237 MB of
|
|
802
|
+
heap, and which are now read in 38 ms keeping nothing (Node 24.21.0 on
|
|
803
|
+
an Intel i9-10900K, 19 October 2026).
|
|
804
|
+
- **`assetDigest`** is `@noble/hashes`' SHA-256, synchronous, on the
|
|
805
|
+
caller's thread: Web Crypto's is asynchronous and no part of this
|
|
806
|
+
package's library. A TypeError for anything that is not a `Uint8Array`.
|
|
807
|
+
- **`isDigest`** is the syntax alone, the one rule for it: the report
|
|
808
|
+
server judges the digits a path carries by it, with `sha256:` put back,
|
|
809
|
+
and its store names a file by it (0049), so that nothing a declaration
|
|
810
|
+
accepts is a digest the store refuses.
|
|
811
|
+
|
|
812
|
+
What it does not do: inflate a PNG's image data, which needs a
|
|
813
|
+
decompressor ES2023 does not have. The renderer does at print, so a PNG
|
|
814
|
+
whose data does not inflate to the scanlines its header promises passes
|
|
815
|
+
here and is refused there. Nothing decodes a JPEG's scan.
|
|
816
|
+
|
|
817
|
+
## A font's bytes
|
|
818
|
+
|
|
819
|
+
What a font is, whether its licence bits allow it to be embedded, and
|
|
820
|
+
which characters it draws, are read here, once: today for the renderer,
|
|
821
|
+
which reads its own faces' character maps here, and for a builder where a
|
|
822
|
+
person adds a font and a host where it approves one once they take fonts
|
|
823
|
+
([0040](../../docs/decisions/0040-a-font-is-read-by-report-specs-own-reader-which-says-what-it-may-be-embedded-as-and-which-characters-it-draws.md)):
|
|
824
|
+
|
|
825
|
+
```ts
|
|
826
|
+
import { characterMap, readFont } from '@formancy/report-spec'
|
|
827
|
+
|
|
828
|
+
readFont(ttf)
|
|
829
|
+
// { ok: true,
|
|
830
|
+
// names: { family: 'Liberation Sans', subfamily: 'Regular', postScriptName: 'LiberationSans', postScriptNames: ['LiberationSans'], version: 'Version 2.1.5', licence: '...', ... },
|
|
831
|
+
// embedding: 'installable', fsType: 0,
|
|
832
|
+
// metrics: { unitsPerEm: 2048, ascender: 1854, descender: -434, lineGap: 67 },
|
|
833
|
+
// style: { weight: 400, italic: false, bold: false, regular: true },
|
|
834
|
+
// glyphs: 2620, characters: Set(2327) { 0x20, 0x21, ... } }
|
|
835
|
+
readFont(otf) // { ok: false, code: 'cff', message: 'is an OpenType font with CFF outlines; use the TrueType edition of the font (.ttf), ...' }
|
|
836
|
+
readFont(restricted) // { ok: false, code: 'embedding', embedding: 'restricted', message: 'allows Restricted License embedding alone (fsType 0x0002), ...' }
|
|
837
|
+
characterMap(ttf) // { ok: true, characters: Set(2327) { ... } }: the character map alone, of any sfnt
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
- **Accepted:** one static TrueType font, an sfnt of 0x00010000 or Apple's
|
|
841
|
+
`true`, with TrueType outlines, the eight tables every OpenType font
|
|
842
|
+
needs, a Unicode character map in format 4 or 12, and an OS/2 fsType
|
|
843
|
+
that allows embedding a subset of its outlines: Installable, Preview &
|
|
844
|
+
Print, since a PDF is opened read-only, or Editable.
|
|
845
|
+
- **Refused**, each with one of `FONT_REFUSAL_CODES` and what to do: a
|
|
846
|
+
collection, WOFF, WOFF2, EOT and Type 1 (`format`, naming which of
|
|
847
|
+
`FONT_FORMATS`); CFF and CFF2 outlines (`cff`); a variable font; a
|
|
848
|
+
colour font, whose glyphs PDFKit would print as their outlines alone; a
|
|
849
|
+
font of bitmaps alone; Restricted License, No subsetting and Bitmap only,
|
|
850
|
+
and an fsType the specification does not define for its OS/2 version
|
|
851
|
+
(`embedding`, naming which of `FONT_EMBEDDING_REFUSALS`), with no
|
|
852
|
+
override; no Unicode map, or one fontkit takes in another format
|
|
853
|
+
(`character-map`); what is malformed; and a font past `MAX_FONT_BYTES`,
|
|
854
|
+
mapping more than `MAX_FONT_CHARACTERS` characters, with a glyph of more
|
|
855
|
+
than `MAX_FONT_GLYPH_WORK` points times contours, or whose glyphs hold
|
|
856
|
+
more than `MAX_FONT_POINTS` points, `MAX_FONT_OUTLINE_WORK` points times
|
|
857
|
+
contours or `MAX_FONT_COMPONENTS` composite components together, which
|
|
858
|
+
is what a subset of them can cost PDFKit (`too-large`, 0043).
|
|
859
|
+
- **A line pdfmake can lay out**: the horizontal header's ascender above
|
|
860
|
+
the baseline, its descender at it or below, and the line they make
|
|
861
|
+
`MIN_FONT_LINE` to `MAX_FONT_LINE` ems tall, a range that holds every one
|
|
862
|
+
of the 425 fonts measured on one machine on 22 October 2026 with a
|
|
863
|
+
margin, since pdfmake lays every line of
|
|
864
|
+
a face out by it and a line of nothing let a report far past its page
|
|
865
|
+
limit print on one page (`malformed`, 0040).
|
|
866
|
+
- **The characters are fontkit's**, which PDFKit lays text out with: the
|
|
867
|
+
subtable it takes, (3, 10) first and (0, 0) last, whatever the order of
|
|
868
|
+
the records, its segments or groups sorted and apart so that a walk finds
|
|
869
|
+
what its binary search finds, and a code point mapped where its glyph is
|
|
870
|
+
not glyph 0. `readFont` holds every glyph a character maps to to the
|
|
871
|
+
glyph count, and the variation sequences fontkit reads beside the map to
|
|
872
|
+
the file; `characterMap` reads the map alone, whatever length the
|
|
873
|
+
directory records for it, holds no glyph to a count it does not read,
|
|
874
|
+
and is what the renderer reads its own faces with: a font a host brings
|
|
875
|
+
is held to `readFont`'s characters.
|
|
876
|
+
- **The names are handed back as the font states them, never judged**,
|
|
877
|
+
each the best record's, Windows English first, and the typographic family
|
|
878
|
+
before the family; where a font states both, the family of name ID 1 is
|
|
879
|
+
handed back beside it, `legacyFamily`, the name an application that
|
|
880
|
+
lists four faces to a family knows the face by, Word among them (0068).
|
|
881
|
+
The licence description and its address are the
|
|
882
|
+
customer's to read. The PostScript name, which PDFKit writes into the PDF
|
|
883
|
+
as it stands, is held in every record to printable ASCII with none of
|
|
884
|
+
`[ ] ( ) { } < > / % #`, a space admitted, since PDFKit writes it as an
|
|
885
|
+
underscore, and every record to an encoding fontkit decodes as this does;
|
|
886
|
+
a record fontkit could not decode the naming table with is refused. Every
|
|
887
|
+
name the records hold is handed back too, once each, as
|
|
888
|
+
`postScriptNames`, since fontkit names a font by its last English record
|
|
889
|
+
and PDFKit keeps a document's faces by that name (0043).
|
|
890
|
+
- **A font is untrusted bytes**: every table's offset and length is held
|
|
891
|
+
to them and every read checked against them, a count against the bytes
|
|
892
|
+
it counts before anything is read by it, every loop bounded by them,
|
|
893
|
+
nothing recursing on what a font holds, and nothing the font chose
|
|
894
|
+
repeated in a refusal but a number the reader decoded. A table is read
|
|
895
|
+
where its record says, as fontkit reads it: refused where its recorded
|
|
896
|
+
length is 0, since fontkit then sees no table, and an index to location
|
|
897
|
+
held to the offsets its recorded length holds, since fontkit reads them
|
|
898
|
+
to there. The bounds were measured, as `limits.ts` says: the costliest
|
|
899
|
+
font they admit read in 15 ms in Node, and the costliest subset found
|
|
900
|
+
under them took PDFKit 1.3 to 1.4 s to embed.
|
|
901
|
+
|
|
902
|
+
What it does not do: read the layout tables fontkit runs at print, GSUB,
|
|
903
|
+
GPOS, kern and morx, a crafted one of which can make a render throw or
|
|
904
|
+
never end -- the renderer strips them from a host face before it embeds it
|
|
905
|
+
(0043); judge what an outline draws; read a font's licence, which may
|
|
906
|
+
forbid what its fsType allows.
|
|
907
|
+
|
|
908
|
+
A report **maps** its font tokens to the fonts a host approved (0043): the
|
|
909
|
+
definition's `fonts` is `{ sans?, serif?, mono? }`, each `{ normal, bold?,
|
|
910
|
+
italic?, boldItalic? }` of asset ids, the assets `font/ttf` and pinned by
|
|
911
|
+
digest like an image. `validateReport` refuses a face mapped to an image
|
|
912
|
+
(`asset-not-a-font`), an image that draws a font (`asset-not-an-image`) and
|
|
913
|
+
a print style that sets bold or italic in a mapped family without that face
|
|
914
|
+
(`missing-face`); `reportHash` covers the map. `PRINTED_BLOCKS`,
|
|
915
|
+
`BIDI_CONTROLS` and `refusedCharacter` are the characters a report prints,
|
|
916
|
+
by code point, which the renderer applies in every face: the Latin, Greek
|
|
917
|
+
and Cyrillic blocks and the punctuation, symbols and marks written with
|
|
918
|
+
them, from Unicode's `Blocks.txt` 18.0.0, but for the bidirectional
|
|
919
|
+
controls of its `PropList.txt`; every other character is refused, its
|
|
920
|
+
script being one nothing here has proved.
|
|
921
|
+
|
|
38
922
|
## Hash
|
|
39
923
|
|
|
40
924
|
```ts
|
|
@@ -51,16 +935,38 @@ validator refuses: only a valid report has a hash.
|
|
|
51
935
|
## Start, find and measure
|
|
52
936
|
|
|
53
937
|
```ts
|
|
54
|
-
import { componentAt, emptyReport, mmToPt, printableArea, walkComponents } from '@formancy/report-spec'
|
|
938
|
+
import { componentAt, emptyReport, heldRegions, mmToPt, printableArea, squareRoom, walkComponents } from '@formancy/report-spec'
|
|
55
939
|
|
|
56
940
|
const blank = emptyReport('site-visit', 'Site visit', 'de-CH') // A4 portrait, 20 mm margins
|
|
57
941
|
const margin = mmToPt(15) // 42.52: lengths are points, stored to the hundredth
|
|
58
942
|
const { width } = printableArea(blank.page) // what the margins leave
|
|
943
|
+
const { side, length } = squareRoom(printableArea(blank.page)) // the largest square, a QR code's room
|
|
59
944
|
for (const { component, path, depth } of walkComponents(blank)) console.log(depth, path, component.id)
|
|
60
945
|
componentAt(blank, 'title') // where a component is, by id: the path its errors use
|
|
946
|
+
heldRegions(blank.regions).map(([region]) => region) // ['reportHeader', 'pageHeader', 'body', 'pageFooter', 'summary']
|
|
61
947
|
```
|
|
62
948
|
|
|
949
|
+
A report holds five regions, and may hold a sixth (`REGION_NAMES`, in the
|
|
950
|
+
order a reader meets them): `firstPageHeader`, which page 1 prints in place
|
|
951
|
+
of the page header, the page header then printing from page 2 on
|
|
952
|
+
([0060](../../docs/decisions/0060-a-reports-first-page-may-print-a-header-of-its-own-or-none-in-place-of-the-page-header.md)).
|
|
953
|
+
Its presence is the choice: absent, page 1 prints the page header; present
|
|
954
|
+
and empty, page 1 prints no header. `OPTIONAL_REGIONS` names it, and
|
|
955
|
+
`Regions` holds it optionally, so `report.regions[name]` over
|
|
956
|
+
`REGION_NAMES` may be `undefined`; `heldRegions` gives the regions a report
|
|
957
|
+
holds, each with its components, and the walk visits those alone. What
|
|
958
|
+
stands in it is what the page header holds -- no table, chart, page break
|
|
959
|
+
or keep-together block -- but no page number or count, refused as
|
|
960
|
+
`misplaced-page-counter`: page 1's number and count print in the page
|
|
961
|
+
footer.
|
|
962
|
+
|
|
63
963
|
`REPORT_SPEC_VERSION` is `0`, the draft: nothing written under it is promised
|
|
64
|
-
to be read by a later release.
|
|
964
|
+
to be read by a later release. Nor by an earlier one: a kind the draft gains
|
|
965
|
+
is refused as `unknown-kind` by a release that predates it, never skipped. A
|
|
966
|
+
report with a `qrCode` or an `epcQrCode` is refused so by 0.1.0, and one
|
|
967
|
+
with a `paymentPart` or an `eInvoice` as `unknown-property`; a report with
|
|
968
|
+
a `chart` is refused so by 0.2.0, and one whose table's group states
|
|
969
|
+
`keepWithRows`, or with a `firstPageHeader` or a run's `baseline`, as
|
|
970
|
+
`unknown-property`.
|
|
65
971
|
|
|
66
972
|
Source-available, not open source: see [`LICENSE.md`](../../LICENSE.md).
|