@formancy/report-core 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/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- import { AggregateDef, AssetRef, Component, ComponentKind, DatasetContract, DatasetRole, FieldContract, FieldType, GROUP_KEY, Margins, Orientation, PageSizeName, ParameterDef, PrintStyle, RegionName, ReportDefinition, ReportError, SortKey, TableColumn, TableFooterCell, TableFooterRow, TableGroup, ValueScope } from "@formancy/report-spec";
1
+ import { AggregateDef, AssetRef, ChartSeries, Component, ComponentKind, DatasetContract, DatasetRole, EInvoice, Expression, FacturXInvoice, FieldContract, FieldType, Format, Margins, Orientation, PageSizeName, ParameterDef, PaymentPart, PrintStyle, RegionName, ReportDefinition, ReportError, SortKey, TableColumn, TableFooterCell, TableFooterRow, TableGroup, ValueScope, WordExpressionSite, XRechnungInvoice } from "@formancy/report-spec";
2
2
  import { DeclaredType, Program, SourceSpan } from "@formancy/expressions";
3
- //#region src/outcome.d.ts
4
3
  /**
5
4
  * Why an edit was refused, as stable codes. A code is for a program -- the
6
5
  * builder decides what to say and where -- and the message is for a person.
@@ -8,7 +7,7 @@ import { DeclaredType, Program, SourceSpan } from "@formancy/expressions";
8
7
  * new reason gets a new code. Each has a case in `outcome.test.ts` that is
9
8
  * refused with it, which does not compile while one is missing.
10
9
  */
11
- export declare const REFUSAL_CODES: readonly ["not-found", "not-a-container", "invalid-location", "index-out-of-range", "into-itself", "kind-mismatch", "immutable-property", "unknown-command", "invalid-arguments", "invalid-document", "stale-document"];
10
+ export declare const REFUSAL_CODES: readonly ["not-found", "not-a-container", "invalid-location", "index-out-of-range", "into-itself", "kind-mismatch", "immutable-property", "already-declared", "unknown-command", "invalid-arguments", "invalid-document", "stale-document", "read-from-data", "read-by-part"];
12
11
  type RefusalCode = (typeof REFUSAL_CODES)[number];
13
12
  interface Refusal {
14
13
  readonly ok: false;
@@ -28,8 +27,6 @@ type CommandOutcome<E extends object = object> = ({
28
27
  } & Readonly<E>) | Refusal;
29
28
  /** An edit, bound to its arguments: what the session applies. */
30
29
  type Command<E extends object = object> = (report: ReportDefinition) => CommandOutcome<E>;
31
- //#endregion
32
- //#region src/lists.d.ts
33
30
  /**
34
31
  * A change to some of an object's properties. A value sets a property;
35
32
  * `null` removes one that is optional. A required property cannot be given
@@ -40,8 +37,6 @@ type Command<E extends object = object> = (report: ReportDefinition) => CommandO
40
37
  * removal written with undefined would arrive as no change at all.
41
38
  */
42
39
  type Patch<T> = { readonly [K in keyof T]?: undefined extends T[K] ? Exclude<T[K], undefined> | null : T[K]; };
43
- //#endregion
44
- //#region src/tree.d.ts
45
40
  /**
46
41
  * Where a component goes: a position in a region's list, or in the list a
47
42
  * container holds -- a section's, a keep-together block's, or one column's
@@ -55,8 +50,6 @@ interface Location {
55
50
  readonly column?: number;
56
51
  readonly index: number;
57
52
  }
58
- //#endregion
59
- //#region src/commands/components.d.ts
60
53
  /**
61
54
  * A change to a component of kind `K`: any of its own properties, but never
62
55
  * its id or its kind. Typed per kind, so a patch for a text cannot carry a
@@ -93,8 +86,6 @@ export declare function nextComponentId(report: ReportDefinition, prefix: string
93
86
  export declare function duplicateComponent(report: ReportDefinition, id: string): CommandOutcome<{
94
87
  readonly id: string;
95
88
  }>;
96
- //#endregion
97
- //#region src/commands/declarations.d.ts
98
89
  export declare function putStyle(report: ReportDefinition, id: string, style: Omit<PrintStyle, 'id'>): CommandOutcome;
99
90
  export declare function removeStyle(report: ReportDefinition, id: string): CommandOutcome;
100
91
  export declare function putParameter(report: ReportDefinition, id: string, parameter: Omit<ParameterDef, 'id'>): CommandOutcome;
@@ -102,6 +93,20 @@ export declare function removeParameter(report: ReportDefinition, id: string): C
102
93
  /** The parameter `id` moved so that it ends at `index`: the order the parameter form shows. */
103
94
  export declare function moveParameter(report: ReportDefinition, id: string, index: number): CommandOutcome;
104
95
  export declare function putAsset(report: ReportDefinition, id: string, asset: Omit<AssetRef, 'id'>): CommandOutcome;
96
+ /** The asset appended under `id`; refused as `already-declared` when the report declares one under it already. */
97
+ export declare function addAsset(report: ReportDefinition, id: string, asset: Omit<AssetRef, 'id'>): CommandOutcome;
98
+ /**
99
+ * An id no asset of `report` has, and none of `handed`: `base` itself when
100
+ * it is free, and otherwise `base-2`, `base-3` and so on, shortened so that
101
+ * its number fits, as a new component's is. The base is a file's name,
102
+ * folded, so a number it ends in is its own and is numbered too:
103
+ * `img-4711` taken gives `img-4711-2`. Assets are a namespace of their own
104
+ * (0007), so a component's id does not count; `handed` holds the ids a
105
+ * builder has handed a host already, which an undo may declare again for
106
+ * the bytes it handed under them (0033). Throws a RangeError for a base
107
+ * that is not an identifier.
108
+ */
109
+ export declare function nextAssetId(report: ReportDefinition, base: string, handed?: ReadonlySet<string>): string;
105
110
  export declare function removeAsset(report: ReportDefinition, id: string): CommandOutcome;
106
111
  export declare function putAggregate(report: ReportDefinition, id: string, aggregate: Omit<AggregateDef, 'id'>): CommandOutcome;
107
112
  export declare function removeAggregate(report: ReportDefinition, id: string): CommandOutcome;
@@ -110,8 +115,6 @@ export declare function putDataset(report: ReportDefinition, slot: DatasetRole,
110
115
  export declare function removeDataset(report: ReportDefinition, slot: DatasetRole): CommandOutcome;
111
116
  export declare function putField(report: ReportDefinition, slot: DatasetRole, fieldId: string, field: Omit<FieldContract, 'id'>): CommandOutcome;
112
117
  export declare function removeField(report: ReportDefinition, slot: DatasetRole, fieldId: string): CommandOutcome;
113
- //#endregion
114
- //#region src/commands/document.d.ts
115
118
  export declare function setTitle(report: ReportDefinition, title: string): CommandOutcome;
116
119
  export declare function setLocale(report: ReportDefinition, locale: string): CommandOutcome;
117
120
  /** A change to the page: its size, its orientation, any of its margins. */
@@ -127,8 +130,94 @@ export declare function setPage(report: ReportDefinition, patch: PagePatch): Com
127
130
  * records it as one undo step like any other.
128
131
  */
129
132
  export declare function replaceDocument(_report: ReportDefinition, next: ReportDefinition): CommandOutcome;
130
- //#endregion
131
- //#region src/commands/table.d.ts
133
+ /**
134
+ * A change to some of an e-invoice's terms, but never its kind: `null`
135
+ * removes an optional one, as JSON carries a removal. A term of the other
136
+ * kind -- an XRechnung's version in a Factur-X invoice -- is the
137
+ * validator's to refuse.
138
+ */
139
+ type EInvoicePatch = Patch<Omit<FacturXInvoice, 'kind'>> & Patch<Pick<XRechnungInvoice, 'version'>>;
140
+ /** The report with `invoice` for its e-invoice: added where it has none, in place of the one it has otherwise. */
141
+ export declare function putEInvoice(report: ReportDefinition, invoice: EInvoice): CommandOutcome;
142
+ /** The report without its e-invoice. */
143
+ export declare function removeEInvoice(report: ReportDefinition): CommandOutcome;
144
+ /** The report's e-invoice with `patch` applied; its kind never changes in place. */
145
+ export declare function updateEInvoice(report: ReportDefinition, patch: EInvoicePatch): CommandOutcome;
146
+ /**
147
+ * The report with `account` as the account its e-invoice names (BT-84)
148
+ * and every payment code printed with it asks to be paid to -- its
149
+ * QR-bill's and each EPC QR code's, shown or hidden -- each as one literal
150
+ * run, as typed: one edit, so one undo step, where an edit of any one of
151
+ * them alone is refused, since report-spec holds each code to BT-84 (0027).
152
+ * Refused where the report has no e-invoice, whose codes share no account,
153
+ * or one that names no account; and where one of them reads its account
154
+ * from the data, which this would write over. Whether the account is one
155
+ * each place takes -- an IBAN of SEPA's, a QR-bill's of Switzerland or
156
+ * Liechtenstein, no QR-IBAN in euro -- the validator says, each place by
157
+ * its own rule. A BIC is left as it is: no rule holds a code's to BT-86.
158
+ */
159
+ export declare function setPaymentAccount(report: ReportDefinition, account: string): CommandOutcome;
160
+ /** The report with `components` for page 1's own header: added where it has none, in place of the one it has otherwise; none, page 1 prints no header. */
161
+ export declare function putFirstPageHeader(report: ReportDefinition, components: readonly Component[]): CommandOutcome;
162
+ /** The report without page 1's own header, what it holds with it: page 1 prints the page header again. */
163
+ export declare function removeFirstPageHeader(report: ReportDefinition): CommandOutcome;
164
+ /** A change to some of a bill's properties, but never its kind: `null` removes an optional one, as JSON carries a removal. */
165
+ type PaymentPartPatch = Patch<Omit<PaymentPart, 'kind'>>;
166
+ /** The report with `part` for its payment part: added where it has none, in place of the one it has otherwise. */
167
+ export declare function putPaymentPart(report: ReportDefinition, part: PaymentPart): CommandOutcome;
168
+ /** The report without its payment part. */
169
+ export declare function removePaymentPart(report: ReportDefinition): CommandOutcome;
170
+ /** The report's payment part with `patch` applied; its kind never changes in place. */
171
+ export declare function updatePaymentPart(report: ReportDefinition, patch: PaymentPartPatch): CommandOutcome;
172
+ /** What reads each field of one report, from one walk of it and one reading of each of its expressions (0048). */
173
+ interface FieldReaders {
174
+ /** The field removed with everything that reads it: what `removeFieldWithReaders` gives, without walking the report again. */
175
+ readonly removal: (slot: DatasetRole, fieldId: string) => CommandOutcome<{
176
+ readonly removed: readonly string[];
177
+ }>;
178
+ /**
179
+ * The expressions, by the JSON Pointer to their `cel`, whose compilation
180
+ * a change of the field's type, or of whether it may be null, can
181
+ * change: each that reads it, each that reads an aggregate that reads
182
+ * it, in turn, and, for a field a table is grouped by, each that reads
183
+ * that table's group's key (0062). `compileReport(report, them)`
184
+ * compiles them alone.
185
+ */
186
+ readonly expressions: (slot: DatasetRole, fieldId: string) => ReadonlySet<string>;
187
+ }
188
+ /** What reads each field of `report`, walked once and its expressions read once, for a review that asks of many fields. */
189
+ export declare function fieldReaders(report: ReportDefinition): FieldReaders;
190
+ /**
191
+ * The field `fieldId` of the dataset in `slot` removed, with every
192
+ * component, column, style rule, footer cell and row, sort key, group and
193
+ * aggregate that reads it, and every reader of such an aggregate, as one
194
+ * edit; and what went, as JSON Pointers into the report before it, in
195
+ * document order, the aggregates and the field last. Refused as
196
+ * `not-found` for a field the dataset does not declare, and as
197
+ * `read-by-part` for one the payment part or the e-invoice reads.
198
+ */
199
+ export declare function removeFieldWithReaders(report: ReportDefinition, slot: DatasetRole, fieldId: string): CommandOutcome<{
200
+ readonly removed: readonly string[];
201
+ }>;
202
+ /** A language added, its words not yet written: every word is then missing in it, which the diagnostics say. Refused for the report's own and for one it has. */
203
+ export declare function addLanguage(report: ReportDefinition, locale: string): CommandOutcome;
204
+ /** A language removed with its words; the last leaves the report without translations. */
205
+ export declare function removeLanguage(report: ReportDefinition, locale: string): CommandOutcome;
206
+ /**
207
+ * `word` -- a word of the report's own language -- written as `text` in
208
+ * `locale`, or, for null, its translation there taken back. A word the
209
+ * report prints nowhere is refused, unless its translation is taken back:
210
+ * one kept for a word the report no longer prints is said unused, and
211
+ * removed by this.
212
+ */
213
+ export declare function translateWord(report: ReportDefinition, locale: string, word: string, text: string | null): CommandOutcome;
214
+ /**
215
+ * The expression whose source is `cel`, standing where a word does,
216
+ * written as `expression` in `locale`, or, for null, its translation
217
+ * there taken back. Whether it prints words, and whether the translation
218
+ * prints what it does, the diagnostics say (0063).
219
+ */
220
+ export declare function translateExpression(report: ReportDefinition, locale: string, cel: string, expression: Expression | null): CommandOutcome;
132
221
  /** Which footer rows: those under the whole table, or those under each group. */
133
222
  type FooterRows = 'totals' | 'groupFooter';
134
223
  export declare function insertColumn(report: ReportDefinition, tableId: string, index: number, column: TableColumn): CommandOutcome;
@@ -151,9 +240,60 @@ export declare function updateFooterRow(report: ReportDefinition, tableId: strin
151
240
  /** Puts the cell of `cell.column` into a footer row: replacing that column's cell where it is, or appending it. */
152
241
  export declare function putFooterCell(report: ReportDefinition, tableId: string, which: FooterRows, rowIndex: number, cell: TableFooterCell): CommandOutcome;
153
242
  export declare function removeFooterCell(report: ReportDefinition, tableId: string, which: FooterRows, rowIndex: number, columnId: string): CommandOutcome;
154
- //#endregion
155
- //#region src/commands/registry.d.ts
243
+ /** Every command a batch may hold: every command but the batch. */
244
+ declare const STEPS: Readonly<{
245
+ setTitle: typeof setTitle;
246
+ setLocale: typeof setLocale;
247
+ setPage: typeof setPage;
248
+ replaceDocument: typeof replaceDocument;
249
+ putStyle: typeof putStyle;
250
+ removeStyle: typeof removeStyle;
251
+ putDataset: typeof putDataset;
252
+ removeDataset: typeof removeDataset;
253
+ putField: typeof putField;
254
+ removeField: typeof removeField;
255
+ putParameter: typeof putParameter;
256
+ removeParameter: typeof removeParameter;
257
+ moveParameter: typeof moveParameter;
258
+ addAsset: typeof addAsset;
259
+ putAsset: typeof putAsset;
260
+ removeAsset: typeof removeAsset;
261
+ putAggregate: typeof putAggregate;
262
+ removeAggregate: typeof removeAggregate;
263
+ insertComponent: typeof insertComponent;
264
+ removeComponent: typeof removeComponent;
265
+ moveComponent: typeof moveComponent;
266
+ updateComponent: typeof updateComponent;
267
+ duplicateComponent: typeof duplicateComponent;
268
+ insertColumn: typeof insertColumn;
269
+ removeColumn: typeof removeColumn;
270
+ moveColumn: typeof moveColumn;
271
+ updateColumn: typeof updateColumn;
272
+ setGroup: typeof setGroup;
273
+ setSort: typeof setSort;
274
+ insertFooterRow: typeof insertFooterRow;
275
+ removeFooterRow: typeof removeFooterRow;
276
+ moveFooterRow: typeof moveFooterRow;
277
+ updateFooterRow: typeof updateFooterRow;
278
+ putFooterCell: typeof putFooterCell;
279
+ removeFooterCell: typeof removeFooterCell;
280
+ putFirstPageHeader: typeof putFirstPageHeader;
281
+ removeFirstPageHeader: typeof removeFirstPageHeader;
282
+ putPaymentPart: typeof putPaymentPart;
283
+ updatePaymentPart: typeof updatePaymentPart;
284
+ removePaymentPart: typeof removePaymentPart;
285
+ putEInvoice: typeof putEInvoice;
286
+ updateEInvoice: typeof updateEInvoice;
287
+ removeEInvoice: typeof removeEInvoice;
288
+ setPaymentAccount: typeof setPaymentAccount;
289
+ removeFieldWithReaders: typeof removeFieldWithReaders;
290
+ addLanguage: typeof addLanguage;
291
+ removeLanguage: typeof removeLanguage;
292
+ translateWord: typeof translateWord;
293
+ translateExpression: typeof translateExpression;
294
+ }>;
156
295
  export declare const COMMANDS: Readonly<{
296
+ batch: typeof batch;
157
297
  setTitle: typeof setTitle;
158
298
  setLocale: typeof setLocale;
159
299
  setPage: typeof setPage;
@@ -167,6 +307,7 @@ export declare const COMMANDS: Readonly<{
167
307
  putParameter: typeof putParameter;
168
308
  removeParameter: typeof removeParameter;
169
309
  moveParameter: typeof moveParameter;
310
+ addAsset: typeof addAsset;
170
311
  putAsset: typeof putAsset;
171
312
  removeAsset: typeof removeAsset;
172
313
  putAggregate: typeof putAggregate;
@@ -188,8 +329,44 @@ export declare const COMMANDS: Readonly<{
188
329
  updateFooterRow: typeof updateFooterRow;
189
330
  putFooterCell: typeof putFooterCell;
190
331
  removeFooterCell: typeof removeFooterCell;
332
+ putFirstPageHeader: typeof putFirstPageHeader;
333
+ removeFirstPageHeader: typeof removeFirstPageHeader;
334
+ putPaymentPart: typeof putPaymentPart;
335
+ updatePaymentPart: typeof updatePaymentPart;
336
+ removePaymentPart: typeof removePaymentPart;
337
+ putEInvoice: typeof putEInvoice;
338
+ updateEInvoice: typeof updateEInvoice;
339
+ removeEInvoice: typeof removeEInvoice;
340
+ setPaymentAccount: typeof setPaymentAccount;
341
+ removeFieldWithReaders: typeof removeFieldWithReaders;
342
+ addLanguage: typeof addLanguage;
343
+ removeLanguage: typeof removeLanguage;
344
+ translateWord: typeof translateWord;
345
+ translateExpression: typeof translateExpression;
191
346
  }>;
192
347
  type CommandName = keyof typeof COMMANDS;
348
+ /** A command a batch may hold: any but a batch. */
349
+ type StepName = keyof typeof STEPS;
350
+ /**
351
+ * The commands that may change each part a report holds at its own level,
352
+ * in no region: its payment part (0022, 0039), by the three made to edit
353
+ * it, and its e-invoice (0027, 0044), by its own three; both by
354
+ * `setPaymentAccount`, which changes the account an e-invoice and its
355
+ * payment codes share in one edit; and either by `replaceDocument`, a
356
+ * paste, an import or a proposal that rewrote the report, whose document
357
+ * may hold another part than the one it replaces. Every other command
358
+ * keeps each part the very object it found; registry.test.ts holds both
359
+ * halves, reading which commands are which from here. A proposal that
360
+ * names one of these may change whom a payment reaches -- a replacement
361
+ * whatever else it changes, and `setPaymentAccount` always -- which 0039
362
+ * and 0044 ask a proposal's review to show above every other change, the
363
+ * part compared whole for a replacement, once proposals are reviewed. A
364
+ * batch may hold any of them, so it is listed for both (0048).
365
+ */
366
+ export declare const PART_COMMANDS: Readonly<{
367
+ paymentPart: readonly ["putPaymentPart", "updatePaymentPart", "removePaymentPart", "setPaymentAccount", "replaceDocument", "batch"];
368
+ eInvoice: readonly ["putEInvoice", "updateEInvoice", "removeEInvoice", "setPaymentAccount", "replaceDocument", "batch"];
369
+ }>;
193
370
  /** A command's arguments after the report. */
194
371
  type ArgumentsOf<F> = F extends ((report: ReportDefinition, ...rest: infer A) => unknown) ? A : never;
195
372
  /** A command as data: its name and its arguments after the report, typed per command. */
@@ -197,6 +374,18 @@ type CommandDescriptor = { readonly [N in CommandName]: {
197
374
  readonly command: N;
198
375
  readonly args: Readonly<ArgumentsOf<(typeof COMMANDS)[N]>>;
199
376
  }; }[CommandName];
377
+ /** A command a batch may hold, as data. */
378
+ type StepDescriptor = Exclude<CommandDescriptor, {
379
+ readonly command: 'batch';
380
+ }>;
381
+ /**
382
+ * Commands one batch holds. Chosen, not measured, as a proposal's bound
383
+ * (plan 16): the largest batch a review writes is a relabel, a command for
384
+ * the field and one for each text that says its label, far fewer; and a
385
+ * batch read from JSON is refused past it before any of it runs. What a
386
+ * batch at the bound costs is measured in 0048.
387
+ */
388
+ export declare const MAX_BATCH_COMMANDS = 1000;
200
389
  declare function isObject(value: unknown): value is Readonly<Record<string, unknown>>;
201
390
  declare function isLocation(value: unknown): boolean;
202
391
  /**
@@ -211,6 +400,10 @@ declare const SHAPES: {
211
400
  readonly is: (value: unknown) => value is string;
212
401
  readonly said: "a string";
213
402
  };
403
+ readonly textOrNull: {
404
+ readonly is: (value: unknown) => value is string | null;
405
+ readonly said: "a string, or null to remove it";
406
+ };
214
407
  readonly index: {
215
408
  readonly is: (value: unknown) => value is number;
216
409
  readonly said: "a number";
@@ -227,6 +420,10 @@ declare const SHAPES: {
227
420
  readonly is: (value: unknown) => value is any[] | null;
228
421
  readonly said: "a list, or null to remove it";
229
422
  };
423
+ readonly list: {
424
+ readonly is: (value: unknown) => value is any[];
425
+ readonly said: "a list";
426
+ };
230
427
  readonly location: {
231
428
  readonly is: typeof isLocation;
232
429
  readonly said: "a location: a region, an index, and a parent id and a column where it names them";
@@ -261,8 +458,20 @@ export declare const ARGUMENTS: { readonly [N in CommandName]: readonly Shape[];
261
458
  * the validator, as any edit's result does.
262
459
  */
263
460
  export declare function describedCommand(descriptor: CommandDescriptor): Command;
264
- //#endregion
265
- //#region src/draft.d.ts
461
+ /**
462
+ * The commands `steps` describe, run one after the other as one command:
463
+ * the report the last leaves, which the session then validates once, as a
464
+ * transaction's end; or the first refusal, word for word, and nothing
465
+ * after it runs. A step is checked as any descriptor is, and one that is
466
+ * no object, or is a batch itself, is refused; so is a batch of more than
467
+ * `MAX_BATCH_COMMANDS` commands, before any runs. Never throws on what a
468
+ * batch read from JSON holds: a step runs on the report the steps before
469
+ * it left, which nothing has validated yet -- a document replaced by one
470
+ * of nothing, a table inserted with no columns -- and a command written
471
+ * for a report the validator accepts may throw on that; such a step is
472
+ * refused, the batch with it.
473
+ */
474
+ export declare function batch(report: ReportDefinition, steps: readonly StepDescriptor[]): CommandOutcome;
266
475
  /** The working document inside a transaction, and the way to edit it. */
267
476
  interface Draft {
268
477
  /** The document as the edits so far have left it, which need not be valid. */
@@ -285,16 +494,12 @@ type Synchronous<R> = R & (R extends PromiseLike<unknown> ? never : unknown);
285
494
  * and `report` is left as it was. Throws as `drafted` does.
286
495
  */
287
496
  export declare function tryEdit<R>(report: ReportDefinition, run: (draft: Draft) => Synchronous<R>): CommandOutcome;
288
- //#endregion
289
- //#region src/snapshot.d.ts
290
497
  /**
291
498
  * Snapshots: the frozen documents a session holds, and the mutable copies
292
499
  * it hands out.
293
500
  */
294
501
  /** A deeply mutable copy of a readonly type: what `exportDocument` returns. */
295
502
  type Mutable<T> = T extends readonly (infer U)[] ? Mutable<U>[] : T extends object ? { -readonly [K in keyof T]: Mutable<T[K]>; } : T;
296
- //#endregion
297
- //#region src/session.d.ts
298
503
  /**
299
504
  * Undo steps a session keeps unless told otherwise; past it, the oldest is
300
505
  * dropped. Chosen, not measured: two hundred steps is longer than an
@@ -318,18 +523,18 @@ interface EditOptions {
318
523
  }
319
524
  interface ReportSession {
320
525
  /** The current document: frozen, and the same object until the next change. */
321
- document(): ReportDefinition;
526
+ document(this: void): ReportDefinition;
322
527
  /** Counts changes: one per committed edit, undo or redo. A refused edit, or one that changed nothing, is not one. */
323
528
  revision(): number;
324
529
  /** `reportHash` of the current document, what a save or a proposal is bound to. */
325
- hash(): string;
530
+ hash(this: void): string;
326
531
  /**
327
532
  * Calls `listener` after every change, synchronously, until the function
328
533
  * returned is called. A listener that throws does not stop the others;
329
534
  * once all have run, its error is thrown from the call that made the
330
535
  * change -- which has been made -- or an AggregateError when several threw.
331
536
  */
332
- subscribe(listener: () => void): () => void;
537
+ subscribe(this: void, listener: () => void): () => void;
333
538
  /**
334
539
  * Runs a command against the document and commits the result if the
335
540
  * validator accepts it. A command returns the next report and never edits
@@ -376,8 +581,6 @@ type SessionOpening = {
376
581
  * that is not a whole number from 0.
377
582
  */
378
583
  export declare function openReportSession(document: unknown, options?: SessionOptions): SessionOpening;
379
- //#endregion
380
- //#region src/locations.d.ts
381
584
  /**
382
585
  * Where the component `id` stands, as the location `moveComponent` and
383
586
  * `insertComponent` take: a move to it puts the component back where it
@@ -385,9 +588,11 @@ export declare function openReportSession(document: unknown, options?: SessionOp
385
588
  */
386
589
  export declare function locationOf(report: ReportDefinition, id: string): Location | undefined;
387
590
  /**
388
- * Every place a component could be put, in reading order: before each
389
- * component and at the end of each list, a container's places right after
390
- * the place before the container. Each is a location `insertComponent`
591
+ * Every place a component could be put, in reading order, in every region
592
+ * the report holds: before each component and at the end of each list, a
593
+ * container's places right after the place before the container. A region
594
+ * the report leaves out has none; it is given one by its own command
595
+ * (0060). Each is a location `insertComponent`
391
596
  * takes; whether the validator accepts what is put there is
392
597
  * `validLocations`' question.
393
598
  */
@@ -398,27 +603,25 @@ export declare function locations(report: ReportDefinition): Location[];
398
603
  * id of one the report holds, each location a move of it to gives one --
399
604
  * read, as `moveComponent` reads it, in the report without it. None for an
400
605
  * id the report lacks, or a component no place accepts, such as a second
401
- * detail table or one whose id is taken.
606
+ * table in a report that is an e-invoice (0062) or one whose id is taken.
402
607
  *
403
608
  * It validates the whole report once per place, so its cost is the
404
609
  * report's size times its number of places: a builder asks it when a drag
405
610
  * starts, not on every pointer move.
406
611
  */
407
612
  export declare function validLocations(report: ReportDefinition, subject: Component | string): Location[];
408
- //#endregion
409
- //#region src/diagnostics/codes.d.ts
410
613
  export declare const DIAGNOSTIC_SEVERITIES: {
411
614
  /** An expression that does not parse. */
412
615
  readonly 'expression-syntax': "error";
413
616
  /** An expression past a structural limit of `@formancy/expressions`: too deep, too many nodes, too long a list. */
414
617
  readonly 'expression-limit': "error";
415
- /** An expression whose types do not meet, each member read as the type it is declared: an integer parameter added to a string, a decimal field compared with an integer, a decimal converted with dec() again. */
618
+ /** An expression whose types do not meet, each member read as the type it is declared: an integer parameter added to a string, a decimal field compared with an integer, a decimal converted with dec() again; a QR-bill's or an EPC QR code's amount that gives anything but a decimal or null; or an e-invoice's date, paid amount or line term that gives what its term is not. */
416
619
  readonly 'expression-type': "error";
417
620
  /** An expression its place does not allow: a condition that is not a boolean, a function its kind forbids. */
418
621
  readonly 'expression-policy': "error";
419
- /** An expression that reads a name, or a member of one, that nothing declares, or a member of a single value. */
622
+ /** An expression that reads a name, or a member of one, that nothing declares, or a member of a single value; or an e-invoice's total where there is none, or where it is computed from. */
420
623
  readonly 'expression-unknown-name': "error";
421
- /** An expression that reads `row` or `group` where there is no row or group. */
624
+ /** An expression that reads `row`, `table` or `group` where there is no row, table or group. */
422
625
  readonly 'expression-out-of-scope': "error";
423
626
  /** An expression that reads an image field, which is drawn and never read. */
424
627
  readonly 'expression-unreadable-field': "error";
@@ -434,10 +637,18 @@ export declare const DIAGNOSTIC_SEVERITIES: {
434
637
  readonly 'expression-aggregate-type': "error";
435
638
  /** An aggregate whose expression reads its own total, directly or through other aggregates, or reads one that does: none of them can be computed. */
436
639
  readonly 'aggregate-cycle': "error";
437
- /** A number or currency format that prints a total at fewer places than its declared rounding keeps, so the total is rounded twice and the second rounding ignores the declared mode. */
640
+ /** A number or currency format that prints a total at fewer places than its declared rounding keeps -- an aggregate's, or a chart's series' -- so the total is rounded twice and the second rounding ignores the declared mode. */
438
641
  readonly 'format-rounds-again': "error";
439
- /** A rounding declared on an aggregate that computes an integer, a date or an instant, which have no places to round: the runtime refuses it. */
642
+ /** A rounding declared on an aggregate that computes an integer, a date or an instant, or on a chart's series that totals an integer, which have no places to round: the runtime refuses it. */
440
643
  readonly 'rounding-not-decimal': "error";
644
+ /** A total an e-invoice's XML holds -- a document total, or a declared VAT category's basis or amount -- that no text or table of the page prints: the page would show another invoice than the one it carries. */
645
+ readonly 'e-invoice-total-unprinted': "error";
646
+ /** A format that prints what an e-invoice's XML holds otherwise: a total or a line's net amount at fewer than two places, or in another currency than the e-invoice's; a line's net price in another currency; a line's name in another case. The page would show another invoice than the one it carries. */
647
+ readonly 'e-invoice-format-differs': "error";
648
+ /** A word of the report, or an expression that prints words, that a language it declares does not translate: a render in that language is refused, and never prints it in another (0063). */
649
+ readonly 'word-missing': "error";
650
+ /** A translated expression that would print another thing than the expression it translates: another type, other reads, or a value where the expression prints no words (0063). */
651
+ readonly 'translation-differs': "error";
441
652
  /** A print style nothing uses. */
442
653
  readonly 'unused-style': "warning";
443
654
  /** An asset nothing draws. */
@@ -452,6 +663,12 @@ export declare const DIAGNOSTIC_SEVERITIES: {
452
663
  readonly 'empty-body': "warning";
453
664
  /** A text that prints nothing: no runs, or only empty literal ones. */
454
665
  readonly 'empty-text': "warning";
666
+ /** A translation of a word, or of an expression, the report no longer prints: kept for nothing, and never printed (0063). */
667
+ readonly 'unused-translation': "warning";
668
+ /** A payment part that holds, written in the report, one of SIX's example accounts, or the creditor, the debtor or the QR reference a builder puts in from SIX's examples, which are no one's (0039). */
669
+ readonly 'example-payment-part': "warning";
670
+ /** A total row, under a table that prints only the rows its condition selects, that prints a total over every detail row: an aggregate over the report, or an expression that reads `totals` and not `table` (0062). Printed under those rows, it reads as theirs. */
671
+ readonly 'total-of-every-row': "warning";
455
672
  };
456
673
  type DiagnosticCode = keyof typeof DIAGNOSTIC_SEVERITIES;
457
674
  type DiagnosticSeverity = (typeof DIAGNOSTIC_SEVERITIES)[DiagnosticCode];
@@ -471,9 +688,9 @@ interface Diagnostic {
471
688
  readonly position?: SourceSpan;
472
689
  /** For an expression, what `@formancy/expressions` suggests writing instead, when it suggests something. */
473
690
  readonly hint?: string;
691
+ /** The language it is about, where it is one a translation declares: an error that names one refuses a render in that language alone (0063). */
692
+ readonly language?: string;
474
693
  }
475
- //#endregion
476
- //#region src/diagnostics/parts.d.ts
477
694
  /** An expression and how to compile it: the names its scope binds, and the policy of what it is for. */
478
695
  interface ExpressionSite {
479
696
  readonly cel: string;
@@ -486,11 +703,30 @@ interface ExpressionSite {
486
703
  readonly componentId?: string;
487
704
  /** The table column it belongs to, for a column's value, condition or style rule. */
488
705
  readonly columnId?: string;
706
+ /** What the expression is the amount of, when it is a payment code's -- a decimal, or null to leave it for the payer. */
707
+ readonly amount?: PaymentAmount;
708
+ /**
709
+ * For an expression an e-invoice is written from -- one of the e-invoice's
710
+ * own, or the value of a column that prints a term of each line -- the
711
+ * term it gives the XML. Such an expression is part of what the
712
+ * e-invoice's totals are computed from or written with, so it never
713
+ * reads them.
714
+ */
715
+ readonly term?: InvoiceTerm;
716
+ /** For an expression a run holds, the format the run prints its value with, where it has one. */
717
+ readonly format?: Format;
718
+ }
719
+ /** What an expression gives an e-invoice's XML. */
720
+ interface InvoiceTerm {
721
+ /** As a message names it: "the issue date (BT-2)", or, for a run of one of the e-invoice's texts, "a text of the e-invoice". */
722
+ readonly what: string;
723
+ /** The types of field it may be, given as an expression reads each -- for a line's term, report-spec's own -- absent for a run, which gives text whatever it computes. */
724
+ readonly types?: readonly FieldType[];
489
725
  }
726
+ /** The payment codes an amount is printed in, as a message names each. */
727
+ type PaymentAmount = 'a QR-bill' | 'an EPC QR code';
490
728
  /** Every expression in the report, each with the scope it is compiled in and what it is for. */
491
729
  export declare function expressionSites(report: ReportDefinition): readonly ExpressionSite[];
492
- //#endregion
493
- //#region src/expressions/members.d.ts
494
730
  /**
495
731
  * The type an expression reads each readable field and parameter type as.
496
732
  *
@@ -516,13 +752,21 @@ interface ExpressionMember {
516
752
  readonly type: DeclaredType;
517
753
  readonly nullable: boolean;
518
754
  }
519
- /** Every name the format binds, in some scope. A test holds this to the union of `EXPRESSION_NAMES`. */
520
- export declare const SCOPE_NAMES: readonly ["params", "header", "row", "totals", "group"];
755
+ /** Every name the format binds, in some scope or in an e-invoice. A test holds this to the union of `EXPRESSION_NAMES` and `E_INVOICE_NAMES`. */
756
+ export declare const SCOPE_NAMES: readonly ["params", "header", "row", "totals", "table", "group", "invoice", "vatBasis", "vatAmount"];
521
757
  type ScopeName = (typeof SCOPE_NAMES)[number];
522
- /** What each name holds in one report, member by member, in declaration order. */
523
- type Members = { readonly [N in ScopeName]: ReadonlyMap<string, ExpressionMember>; };
524
- //#endregion
525
- //#region src/expressions/compile-site.d.ts
758
+ /**
759
+ * What each name holds in one report, member by member, in declaration
760
+ * order; `group` the aggregates alone. A group's key, `group.key`, is its
761
+ * own table's, and two tables may group by fields of two types (0062), so
762
+ * each table that groups has its key in `groupKeys`, by the table's id,
763
+ * and a group's header and footer are compiled with their table's.
764
+ */
765
+ type Members = { readonly [N in ScopeName]: ReadonlyMap<string, ExpressionMember>; } & {
766
+ readonly groupKeys: ReadonlyMap<string, ExpressionMember>;
767
+ };
768
+ /** What a chart's `series` computes: the compiler's type of an aggregate of its function over the detail field it names. */
769
+ export declare function seriesType(report: ReportDefinition, series: ChartSeries): ExpressionMember;
526
770
  /** A member an expression reads, and how the runtime binds it. */
527
771
  interface ExpressionRead {
528
772
  /** The name and the member as the expression writes them: `row` and `amount` for `row.amount`. */
@@ -541,8 +785,6 @@ interface CompiledExpression {
541
785
  readonly program: Program;
542
786
  readonly reads: readonly ExpressionRead[];
543
787
  }
544
- //#endregion
545
- //#region src/expressions/compile-report.d.ts
546
788
  interface ReportCompilation {
547
789
  /** What each name holds in this report: every member an expression can read, with the type it is checked and bound as. */
548
790
  readonly members: Members;
@@ -553,10 +795,15 @@ interface ReportCompilation {
553
795
  /** Every reason an expression cannot be evaluated, in document order, the aggregates' last: what the runtime refuses the report for. */
554
796
  readonly diagnostics: readonly Diagnostic[];
555
797
  }
556
- /** Every expression in `report` -- a report the validator accepts -- compiled where it stands. */
557
- export declare function compileReport(report: ReportDefinition): ReportCompilation;
558
- //#endregion
559
- //#region src/expressions/values.d.ts
798
+ /**
799
+ * Every expression in `report` -- a report the validator accepts --
800
+ * compiled where it stands; or, with `only`, the expressions at those
801
+ * pointers to their `cel` alone, with every aggregate's and the
802
+ * e-invoice's paid amount, which what they read is computed from: what a
803
+ * review compiles of a resolution that changes one field's type, the
804
+ * expressions that change can reach (`fieldReaders`, 0048).
805
+ */
806
+ export declare function compileReport(report: ReportDefinition, only?: ReadonlySet<string>): ReportCompilation;
560
807
  /**
561
808
  * The data one evaluation reads, by name and member: `{ row: { amount:
562
809
  * '12.50' } }`. Each value as the format writes it -- an integer and a
@@ -580,21 +827,35 @@ type ExpressionValues = {
580
827
  * a defect, and is said as one: naming the member, never quoting the value.
581
828
  */
582
829
  export declare function expressionValues(expression: CompiledExpression, values: ExpressionValues): Record<string, unknown>;
583
- //#endregion
584
- //#region src/expressions/reproducible.d.ts
830
+ /** The name an expression reads each dataset's fields under: `header.<id>`, `row.<id>`. */
831
+ export declare const READ_AS: { readonly [R in DatasetRole]: 'header' | 'row'; };
585
832
  /** The functions whose value is not a function of the report's data. */
586
833
  export declare const UNREPRODUCIBLE_FUNCTIONS: readonly ["now", "today", "random"];
587
834
  type UnreproducibleFunction = (typeof UNREPRODUCIBLE_FUNCTIONS)[number];
588
- //#endregion
589
- //#region src/diagnostics/diagnose.d.ts
590
835
  /**
591
836
  * Every diagnostic for `report`, a report the validator accepts -- a
592
- * session's document is one. Expressions first, in document order, the
593
- * aggregates' last, then roundings, then content, then unused declarations
594
- * in the order they are declared. The expressions' are `compileReport`'s,
595
- * so the editor reports exactly what the runtime refuses.
837
+ * session's document is one: its own language's first, in `diagnosis`'s
838
+ * order, then each translation's, in the order the report declares them,
839
+ * each naming its `language` (0063). An error that names none refuses
840
+ * every render; one that names a language refuses a render in that
841
+ * language alone.
596
842
  */
597
843
  export declare function diagnose(report: ReportDefinition): Diagnostic[];
598
- //#endregion
599
- export type { Command, CommandDescriptor, CommandName, CommandOutcome, CompiledExpression, ComponentPatch, Diagnostic, DiagnosticCode, DiagnosticSeverity, Draft, EditOptions, ExpressionMember, ExpressionRead, ExpressionSite, ExpressionValues, FooterRows, Location, Members, Mutable, PagePatch, Patch, Refusal, RefusalCode, ReportCompilation, ReportSession, ScopeName, SessionOpening, SessionOptions, Synchronous, UnreproducibleFunction };
844
+ /**
845
+ * Every expression run of `report` -- a report the validator accepts --
846
+ * where a word stands that prints words, in document order: what a
847
+ * language translates, as `word-missing` says of each, and what the
848
+ * builders mark and edit as a word (0063). The one verdict the diagnostics
849
+ * give, so that the two never disagree.
850
+ */
851
+ export declare function wordExpressions(report: ReportDefinition): readonly WordExpressionSite[];
852
+ /**
853
+ * Every diagnostic of `report` -- a report the validator accepts -- in
854
+ * `locale`, a language its translations declare, each naming it: what a
855
+ * render in that language is refused for, beside the report's own errors,
856
+ * which refuse every render. None for the report's own language, whose
857
+ * are `diagnose`'s, or for one it does not declare.
858
+ */
859
+ export declare function languageDiagnostics(report: ReportDefinition, locale: string): Diagnostic[];
860
+ export type { Command, CommandDescriptor, CommandName, CommandOutcome, CompiledExpression, ComponentPatch, Diagnostic, DiagnosticCode, DiagnosticSeverity, Draft, EInvoicePatch, EditOptions, ExpressionMember, ExpressionRead, ExpressionSite, ExpressionValues, FieldReaders, FooterRows, Location, Members, Mutable, PagePatch, Patch, PaymentPartPatch, Refusal, RefusalCode, ReportCompilation, ReportSession, ScopeName, SessionOpening, SessionOptions, StepDescriptor, StepName, Synchronous, UnreproducibleFunction };
600
861
  //# sourceMappingURL=index.d.mts.map