@formancy/report-spec 0.2.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/README.md +552 -17
- package/dist/index.d.mts +1729 -752
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3593 -517
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -28,9 +28,19 @@ 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
|
-
|
|
33
|
-
|
|
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);
|
|
34
44
|
- a QR code of no runs, which would encode nothing;
|
|
35
45
|
- a fixed size the page cannot hold, a QR code's and an EPC QR code's
|
|
36
46
|
square measured against `squareRoom`;
|
|
@@ -52,7 +62,53 @@ if (!outcome.valid) {
|
|
|
52
62
|
make a valid invoice; lines that are not what the table over the detail
|
|
53
63
|
dataset prints; a QR-bill or an EPC QR code that asks to be paid to
|
|
54
64
|
another account, or a QR-bill in another currency; or a title holding
|
|
55
|
-
`&`, `<` or
|
|
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`).
|
|
84
|
+
|
|
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.
|
|
56
112
|
|
|
57
113
|
A message names the field and the rule, and never quotes a payment code's
|
|
58
114
|
text. It reports up to `MAX_ERRORS` errors and says when there were more.
|
|
@@ -60,6 +116,75 @@ It checks structure, and what a payment code's literal texts say: whether
|
|
|
60
116
|
an expression compiles, what a code's data resolves to, and whether the
|
|
61
117
|
rendered output fits, are the runtime's and the renderer's questions.
|
|
62
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
|
+
|
|
63
188
|
## A QR-bill
|
|
64
189
|
|
|
65
190
|
A report may carry one payment part, `paymentPart`: a Swiss QR-bill, printed
|
|
@@ -103,6 +228,15 @@ refused only by a render, in the same words. What they do not check:
|
|
|
103
228
|
no pattern tells from a country whose codes begin with letters;
|
|
104
229
|
- the code's 997 characters, which only the whole bill has.
|
|
105
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
|
+
|
|
106
240
|
## An EPC QR code
|
|
107
241
|
|
|
108
242
|
A component, `epcQrCode`, prints the code a SEPA credit transfer is
|
|
@@ -173,7 +307,7 @@ What they do not check:
|
|
|
173
307
|
|
|
174
308
|
A report may carry one e-invoice, `eInvoice`: an EN 16931 invoice, which the
|
|
175
309
|
runtime writes as Factur-X 1.09.2 / ZUGFeRD 2.5.2 CII in the EN 16931 profile
|
|
176
|
-
([0027](../../docs/decisions/0027-a-report-carries-one-en-16931-invoice-written-from-the-values-its-page-prints.md)). It is of kind `facturX`, type 380, in euro, its VAT categories
|
|
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
|
|
177
311
|
standard rated, exempt or reverse-charged, with no allowances or charges: a
|
|
178
312
|
discount is a line of negative quantity at a positive price. Its seller, its
|
|
179
313
|
buyer, their addresses and its payment instructions are runs, as a
|
|
@@ -185,8 +319,17 @@ quantity, net price and net amount, so the page and the XML read one
|
|
|
185
319
|
evaluation of each line, and reads the line's identifier, unit and VAT
|
|
186
320
|
category from each row.
|
|
187
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
|
+
|
|
188
331
|
```ts
|
|
189
|
-
import { checkCountryCode, checkEInvoiceDecimal, checkEInvoiceText, checkVatIdentifier, checkVatRate, FACTUR_X, FACTUR_X_PROFILES, sellerIdentificationBreaks, vatCategoryBreaks } from '@formancy/report-spec'
|
|
332
|
+
import { checkAddressScheme, checkCountryCode, checkEInvoiceDecimal, checkEInvoiceText, checkVatIdentifier, checkVatRate, FACTUR_X, FACTUR_X_PROFILES, sellerIdentificationBreaks, vatCategoryBreaks } from '@formancy/report-spec'
|
|
190
333
|
|
|
191
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)" }
|
|
192
335
|
checkVatIdentifier('DE 123 456 789') // { ok: true, value: 'DE123456789' }
|
|
@@ -199,13 +342,16 @@ checkVatRate('S', '19.00') // { ok: true, value: '19' }: compared by value
|
|
|
199
342
|
checkVatRate('S', '0.4') // { ok: false, rule: 'is below 0.5, which BR-CO-17 rounds to 0, ... (BR-CO-17)' }
|
|
200
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)' }
|
|
201
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)" }
|
|
202
347
|
vatCategoryBreaks([{ code: 'S', rate: '19' }, { code: 'S', rate: '19.00' }]) // [{ index: 1, field: 'rate', rule: '... (BR-S-08)' }]
|
|
203
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)']
|
|
204
349
|
FACTUR_X_PROFILES.en16931.guideline // 'urn:cen.eu:en16931:2017': BT-24
|
|
205
350
|
FACTUR_X.fileName // 'factur-x.xml'
|
|
206
351
|
```
|
|
207
352
|
|
|
208
|
-
`en16931.ts`
|
|
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
|
|
209
355
|
the value the XML is written with or the rule broken, named by its business
|
|
210
356
|
term and its business rule and never by the value. The validator applies
|
|
211
357
|
them to a literal; the runtime applies the same functions to what the data
|
|
@@ -222,7 +368,18 @@ CEN's: the seller's and the buyer's street, post code and city, which
|
|
|
222
368
|
only the country; and an identifier or a code the XSD types as a token,
|
|
223
369
|
which holds no tab, line break, double space or space at either end, since
|
|
224
370
|
a schema-aware reader collapses them. The payment account and its BIC are
|
|
225
|
-
the EPC QR code's rules.
|
|
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
|
|
226
383
|
runtime computes them once.
|
|
227
384
|
|
|
228
385
|
A report that is an e-invoice gives its expressions three names beside
|
|
@@ -241,7 +398,10 @@ and held to CEN's 1.3.17 and the pinned 1.3.16 lists on 17 October 2026:
|
|
|
241
398
|
counts, times, weighs and measures in; `COUNTRY_CODES`, the
|
|
242
399
|
EU's members, the EEA's, Switzerland and the United Kingdom; `VAT_PREFIXES`,
|
|
243
400
|
those and Greece's `EL`, which CEN's 1.3.16 takes and its 1.3.17 does not;
|
|
244
|
-
and `SCHEME_IDS`, SIREN, SIRET, D-U-N-S and GLN
|
|
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
|
|
245
405
|
below 100 with two decimals at most, and a standard rate 0.5 or more, which
|
|
246
406
|
BR-CO-17 would otherwise round to 0. `FACTUR_X` and `FACTUR_X_PROFILES` are
|
|
247
407
|
the names the PDF carries -- the file, its relationship and the XMP's values
|
|
@@ -256,7 +416,248 @@ What they do not check:
|
|
|
256
416
|
- the amount a payment code asks for, which is an expression: the render
|
|
257
417
|
compares it with the amount due;
|
|
258
418
|
- an account, a date or a total read from the data, before a render;
|
|
259
|
-
-
|
|
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.
|
|
260
661
|
|
|
261
662
|
## An SVG asset
|
|
262
663
|
|
|
@@ -341,8 +742,9 @@ What a cleaned SVG holds, in `svg-allow.ts`'s tables:
|
|
|
341
742
|
a shape's, and the points the converter draws its outlines with, an
|
|
342
743
|
arc's grown to reach its ends among them -- and how deep it nests the
|
|
343
744
|
graphics state. Nothing is refused by it here; the renderer holds an
|
|
344
|
-
image in
|
|
345
|
-
2,147,483,647 and the nesting to 28
|
|
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)).
|
|
346
748
|
|
|
347
749
|
Cleaning is a fixed point: `cleanSvg` of what it wrote gives the same bytes
|
|
348
750
|
with nothing removed, which is what `checkSvg` tests for.
|
|
@@ -366,13 +768,14 @@ refuse at every print, and names the image as the validator reads a name
|
|
|
366
768
|
(0033):
|
|
367
769
|
|
|
368
770
|
```ts
|
|
369
|
-
import { assetDigest, imageHeader, sniffImage } from '@formancy/report-spec'
|
|
771
|
+
import { assetDigest, imageHeader, isDigest, sniffImage } from '@formancy/report-spec'
|
|
370
772
|
|
|
371
773
|
sniffImage(bytes) // 'image/png', 'image/jpeg' or 'image/svg+xml', by the first bytes alone; undefined for anything else
|
|
372
774
|
imageHeader(png) // { ok: true, mediaType: 'image/png', width: 120, height: 40, bitsPerPixel: 32, interlaced: false, data: every IDAT chunk's bytes, joined }
|
|
373
|
-
imageHeader(jpeg) // { ok: true, mediaType: 'image/jpeg', width: 40, height: 120, components: 3 }: as it is shown, after its Exif turn
|
|
775
|
+
imageHeader(jpeg) // { ok: true, mediaType: 'image/jpeg', width: 40, height: 120, components: 3, orientation: 6 }: as it is shown, after its Exif turn
|
|
374
776
|
imageHeader(wide) // { ok: false, code: 'too-large', message: 'is 5000 × 300 pixels; the limit is 4096 pixels a side', width: 5000, height: 300 }
|
|
375
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
|
|
376
779
|
```
|
|
377
780
|
|
|
378
781
|
- **`sniffImage`** judges by a PNG's signature, a JPEG's start of image,
|
|
@@ -383,7 +786,12 @@ assetDigest(bytes) // 'sha256:' and 64 lower-case hex digits, what an asset's di
|
|
|
383
786
|
- **`imageHeader`** reads a PNG's chunks, each with its length and CRC,
|
|
384
787
|
the header, the palette it needs and the end chunk with nothing after
|
|
385
788
|
it; and a JPEG's segments up to its scan, the frame header where PDFKit
|
|
386
|
-
reads it, the first Exif block's orientation and the end marker.
|
|
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
|
|
387
795
|
refusals, `IMAGE_REFUSAL_CODES`, are in the words the renderer says them
|
|
388
796
|
in after an asset's name, and one of a picture's size carries the size.
|
|
389
797
|
A picture is held to `MAX_ASSET_SIDE` pixels a side, and every reader of
|
|
@@ -396,12 +804,121 @@ assetDigest(bytes) // 'sha256:' and 64 lower-case hex digits, what an asset's di
|
|
|
396
804
|
- **`assetDigest`** is `@noble/hashes`' SHA-256, synchronous, on the
|
|
397
805
|
caller's thread: Web Crypto's is asynchronous and no part of this
|
|
398
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.
|
|
399
811
|
|
|
400
812
|
What it does not do: inflate a PNG's image data, which needs a
|
|
401
813
|
decompressor ES2023 does not have. The renderer does at print, so a PNG
|
|
402
814
|
whose data does not inflate to the scanlines its header promises passes
|
|
403
815
|
here and is refused there. Nothing decodes a JPEG's scan.
|
|
404
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
|
+
|
|
405
922
|
## Hash
|
|
406
923
|
|
|
407
924
|
```ts
|
|
@@ -418,7 +935,7 @@ validator refuses: only a valid report has a hash.
|
|
|
418
935
|
## Start, find and measure
|
|
419
936
|
|
|
420
937
|
```ts
|
|
421
|
-
import { componentAt, emptyReport, mmToPt, printableArea, squareRoom, walkComponents } from '@formancy/report-spec'
|
|
938
|
+
import { componentAt, emptyReport, heldRegions, mmToPt, printableArea, squareRoom, walkComponents } from '@formancy/report-spec'
|
|
422
939
|
|
|
423
940
|
const blank = emptyReport('site-visit', 'Site visit', 'de-CH') // A4 portrait, 20 mm margins
|
|
424
941
|
const margin = mmToPt(15) // 42.52: lengths are points, stored to the hundredth
|
|
@@ -426,12 +943,30 @@ const { width } = printableArea(blank.page) // what the margins leave
|
|
|
426
943
|
const { side, length } = squareRoom(printableArea(blank.page)) // the largest square, a QR code's room
|
|
427
944
|
for (const { component, path, depth } of walkComponents(blank)) console.log(depth, path, component.id)
|
|
428
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']
|
|
429
947
|
```
|
|
430
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
|
+
|
|
431
963
|
`REPORT_SPEC_VERSION` is `0`, the draft: nothing written under it is promised
|
|
432
964
|
to be read by a later release. Nor by an earlier one: a kind the draft gains
|
|
433
965
|
is refused as `unknown-kind` by a release that predates it, never skipped. A
|
|
434
966
|
report with a `qrCode` or an `epcQrCode` is refused so by 0.1.0, and one
|
|
435
|
-
with a `paymentPart` or an `eInvoice` as `unknown-property
|
|
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`.
|
|
436
971
|
|
|
437
972
|
Source-available, not open source: see [`LICENSE.md`](../../LICENSE.md).
|