@refactorlabs/recount 0.9.1 → 0.11.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 +3 -1
- package/dist/index.cjs +1310 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +343 -10
- package/dist/index.d.ts +343 -10
- package/dist/index.js +1304 -38
- package/dist/index.js.map +1 -1
- package/llms.md +108 -19
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
type JsonObject = Record<string, unknown> | unknown[];
|
|
2
2
|
type Metadata = Record<string, string | number | boolean | null>;
|
|
3
3
|
type TableHighlight = 'danger' | 'warn' | 'success' | 'info' | 'muted';
|
|
4
|
-
type
|
|
4
|
+
type CellFormat = 'money' | 'number' | 'percent' | 'integer' | 'text';
|
|
5
|
+
/** How Recount formats a number: in a column, a typed cell or a calculation. */
|
|
6
|
+
type CellFormatOptions = {
|
|
7
|
+
format?: CellFormat;
|
|
8
|
+
/** ISO 4217 code, such as `'AUD'`. */
|
|
9
|
+
currency?: string;
|
|
10
|
+
unit?: string;
|
|
11
|
+
/** Decimal places shown, 0-6. */
|
|
12
|
+
places?: number;
|
|
13
|
+
};
|
|
14
|
+
type SignHighlight = {
|
|
15
|
+
positive?: TableHighlight;
|
|
16
|
+
negative?: TableHighlight;
|
|
17
|
+
zero?: TableHighlight;
|
|
18
|
+
};
|
|
19
|
+
type TableColumn = string | ({
|
|
5
20
|
label: string;
|
|
6
21
|
span?: number;
|
|
7
22
|
highlight?: TableHighlight;
|
|
8
|
-
|
|
23
|
+
/** Colours each numeric cell by its sign. */
|
|
24
|
+
signHighlight?: SignHighlight;
|
|
25
|
+
} & CellFormatOptions);
|
|
26
|
+
/** A cell carrying its own format, for key/value tables where each row has its own unit. */
|
|
27
|
+
type TableTypedCell = {
|
|
28
|
+
readonly __cell: true;
|
|
29
|
+
readonly value: number | string | boolean | null | {
|
|
30
|
+
__redacted: true;
|
|
31
|
+
};
|
|
32
|
+
readonly span?: number;
|
|
33
|
+
} & Readonly<CellFormatOptions>;
|
|
9
34
|
type TableCellSpan = {
|
|
10
35
|
readonly __cellSpan: true;
|
|
11
36
|
readonly span: number;
|
|
@@ -22,7 +47,8 @@ type TableSection = {
|
|
|
22
47
|
cellHighlights?: (TableHighlight | null)[][];
|
|
23
48
|
summary?: TableSummaryStat[];
|
|
24
49
|
};
|
|
25
|
-
|
|
50
|
+
/** A table of rows or sections. */
|
|
51
|
+
type TableRowsData = {
|
|
26
52
|
title?: string;
|
|
27
53
|
columns: TableColumn[];
|
|
28
54
|
/** Flat rows - required when `sections` is not provided. */
|
|
@@ -32,11 +58,96 @@ type TableData = {
|
|
|
32
58
|
summary?: TableSummaryStat[];
|
|
33
59
|
/** Named sections sharing the same columns. Mutually exclusive with `rows`. */
|
|
34
60
|
sections?: [TableSection, ...TableSection[]];
|
|
61
|
+
calculations?: never;
|
|
62
|
+
};
|
|
63
|
+
/** A table drawn by Recount from calculations. It can't also have columns, rows or sections. */
|
|
64
|
+
type TableCalculationData = {
|
|
65
|
+
title?: string;
|
|
66
|
+
calculations: Calculation[];
|
|
67
|
+
columns?: never;
|
|
68
|
+
rows?: never;
|
|
69
|
+
sections?: never;
|
|
35
70
|
};
|
|
71
|
+
type TableData = TableRowsData | TableCalculationData;
|
|
36
72
|
/** TableData with flat rows guaranteed present. Returned by build(), tableFromObject(), tableFromRecords(). */
|
|
37
|
-
type TableDataFlat =
|
|
73
|
+
type TableDataFlat = TableRowsData & {
|
|
38
74
|
rows: unknown[][];
|
|
39
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* A value an input or line holds: a number, a decimal string (`'0.0316'`)
|
|
78
|
+
* that keeps more precision than a float, text, a boolean, `null` (not
|
|
79
|
+
* calculated) or redacted.
|
|
80
|
+
*/
|
|
81
|
+
type CalculationValue = number | string | boolean | null | {
|
|
82
|
+
__redacted: true;
|
|
83
|
+
};
|
|
84
|
+
type CalculationAlerts = 'none' | 'warn' | 'error';
|
|
85
|
+
type CalculationLineKind = 'charge' | 'step' | 'working' | 'subtotal' | 'total' | 'info';
|
|
86
|
+
/** An absolute amount in the line's unit (`0.01`), or a percentage (`'0.1%'`). */
|
|
87
|
+
type CalculationTolerance = number | `${number}%`;
|
|
88
|
+
/** A figure from another system that a line should match. */
|
|
89
|
+
type CalculationExpected = {
|
|
90
|
+
value: CalculationValue;
|
|
91
|
+
source?: string;
|
|
92
|
+
tolerance?: CalculationTolerance;
|
|
93
|
+
/** Opts this reconciliation alone into alerts. */
|
|
94
|
+
level?: SpanAlertLevel;
|
|
95
|
+
reason?: string;
|
|
96
|
+
};
|
|
97
|
+
type CalculationInput = {
|
|
98
|
+
key: string;
|
|
99
|
+
label?: string;
|
|
100
|
+
value: CalculationValue;
|
|
101
|
+
unit?: string;
|
|
102
|
+
places?: number;
|
|
103
|
+
source?: string;
|
|
104
|
+
sourceSpan?: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
};
|
|
107
|
+
type CalculationLine = {
|
|
108
|
+
key: string;
|
|
109
|
+
label?: string;
|
|
110
|
+
/** The engine's figure. Left out on a derived line, Recount works it out. */
|
|
111
|
+
value?: CalculationValue;
|
|
112
|
+
/** What the value is derived from, which Recount checks. `null` = stated. */
|
|
113
|
+
formula?: string | null;
|
|
114
|
+
/** A number or formula; `null` when it wasn't calculated, so the line isn't either. */
|
|
115
|
+
quantity?: number | string | null;
|
|
116
|
+
rate?: number | string | null;
|
|
117
|
+
times?: number | string | null;
|
|
118
|
+
quantityUnit?: string;
|
|
119
|
+
rateUnit?: string;
|
|
120
|
+
unit?: string;
|
|
121
|
+
places?: number;
|
|
122
|
+
kind?: CalculationLineKind;
|
|
123
|
+
primary?: boolean;
|
|
124
|
+
tags?: string[];
|
|
125
|
+
highlight?: TableHighlight;
|
|
126
|
+
detail?: string;
|
|
127
|
+
explain?: string;
|
|
128
|
+
source?: string;
|
|
129
|
+
sourceSpan?: string;
|
|
130
|
+
expected?: CalculationExpected;
|
|
131
|
+
tolerance?: CalculationTolerance;
|
|
132
|
+
alerts?: CalculationAlerts;
|
|
133
|
+
};
|
|
134
|
+
type CalculationLayout = 'charges' | 'steps';
|
|
135
|
+
type CalculationColumnLabels = Partial<Record<'charge' | 'quantity' | 'rate' | 'amount' | 'step' | 'working' | 'value', string>>;
|
|
136
|
+
type Calculation = {
|
|
137
|
+
version?: 1;
|
|
138
|
+
key: string;
|
|
139
|
+
title?: string;
|
|
140
|
+
layout?: CalculationLayout;
|
|
141
|
+
currency?: string;
|
|
142
|
+
places?: number;
|
|
143
|
+
tolerance?: CalculationTolerance;
|
|
144
|
+
alerts?: CalculationAlerts;
|
|
145
|
+
columnLabels?: CalculationColumnLabels;
|
|
146
|
+
inputs?: CalculationInput[];
|
|
147
|
+
lines: CalculationLine[];
|
|
148
|
+
notes?: string[];
|
|
149
|
+
summary?: TableSummaryStat[];
|
|
150
|
+
};
|
|
40
151
|
type ChartType = 'line' | 'bar' | 'pie' | 'scatter';
|
|
41
152
|
type ChartSeries = {
|
|
42
153
|
name?: string;
|
|
@@ -174,6 +285,10 @@ type TableSpanOptions = SpanBaseOptions & {
|
|
|
174
285
|
input?: TableData;
|
|
175
286
|
output?: TableData;
|
|
176
287
|
};
|
|
288
|
+
type CalculationSpanOptions = SpanBaseOptions & {
|
|
289
|
+
/** Which side of the table span holds the calculations. Defaults to `'output'`. */
|
|
290
|
+
side?: 'input' | 'output';
|
|
291
|
+
};
|
|
177
292
|
type ChartSpanOptions = SpanBaseOptions & {
|
|
178
293
|
input?: ChartData;
|
|
179
294
|
output?: ChartData;
|
|
@@ -254,6 +369,187 @@ type IngestResult = {
|
|
|
254
369
|
traceId: string;
|
|
255
370
|
};
|
|
256
371
|
|
|
372
|
+
/** A number, a decimal object, or a formula of earlier keys (`'days'`, `'daily_usage * 365.25'`). */
|
|
373
|
+
type Operand = number | string | DecimalLike;
|
|
374
|
+
/** A decimal library's value, such as a decimal.js `Decimal` or a big.js `Big`. */
|
|
375
|
+
type DecimalLike = {
|
|
376
|
+
toFixed(): string;
|
|
377
|
+
};
|
|
378
|
+
type CalculationOptions = {
|
|
379
|
+
title?: string;
|
|
380
|
+
/** `'charges'` (Charge, Quantity, Rate, Amount) or `'steps'` (Step, Working, Value). */
|
|
381
|
+
layout?: CalculationLayout;
|
|
382
|
+
/** ISO 4217 code: the unit of charges-layout lines that give none. */
|
|
383
|
+
currency?: string;
|
|
384
|
+
/** Decimal places money is shown to, 0-6. Defaults to 2. */
|
|
385
|
+
places?: number;
|
|
386
|
+
/** How far a stated value may be from its formula and still pass. */
|
|
387
|
+
tolerance?: CalculationTolerance;
|
|
388
|
+
/** Opts into alerts for failed checks, and into showing checks in portals. */
|
|
389
|
+
alerts?: CalculationAlerts;
|
|
390
|
+
columnLabels?: CalculationColumnLabels;
|
|
391
|
+
summary?: TableSummaryStat[];
|
|
392
|
+
};
|
|
393
|
+
type InputOptions = {
|
|
394
|
+
label?: string;
|
|
395
|
+
unit?: string;
|
|
396
|
+
places?: number;
|
|
397
|
+
/** Where it came from, such as `'Extracted bill'`. */
|
|
398
|
+
source?: string;
|
|
399
|
+
/** The name of the span that produced it. */
|
|
400
|
+
sourceSpan?: string;
|
|
401
|
+
description?: string;
|
|
402
|
+
/** Sends the value as redacted. */
|
|
403
|
+
redact?: boolean;
|
|
404
|
+
};
|
|
405
|
+
type LineOptions = {
|
|
406
|
+
/** The engine's figure. Leave it out and Recount works it out from the formula. */
|
|
407
|
+
value?: unknown;
|
|
408
|
+
unit?: string;
|
|
409
|
+
quantityUnit?: string;
|
|
410
|
+
rateUnit?: string;
|
|
411
|
+
places?: number;
|
|
412
|
+
/** The calculation's headline figure. */
|
|
413
|
+
primary?: boolean;
|
|
414
|
+
tags?: string[];
|
|
415
|
+
/** Adds the `tax_free` tag, which `taxIncluded()` leaves out by default. */
|
|
416
|
+
taxFree?: boolean;
|
|
417
|
+
highlight?: TableHighlight;
|
|
418
|
+
/** A second line under the label. `{key}` placeholders are filled in. */
|
|
419
|
+
detail?: string;
|
|
420
|
+
/** The steps layout's Working text, such as `'{monthly_bill} ÷ {days} days'`. */
|
|
421
|
+
explain?: string;
|
|
422
|
+
source?: string;
|
|
423
|
+
sourceSpan?: string;
|
|
424
|
+
/** A figure from another system this line should match. */
|
|
425
|
+
expected?: CalculationExpected;
|
|
426
|
+
tolerance?: CalculationTolerance;
|
|
427
|
+
alerts?: CalculationAlerts;
|
|
428
|
+
/** Sends the value as redacted. */
|
|
429
|
+
redact?: boolean;
|
|
430
|
+
};
|
|
431
|
+
type ChargeOptions = LineOptions & {
|
|
432
|
+
quantity: Operand;
|
|
433
|
+
rate: Operand;
|
|
434
|
+
times?: Operand;
|
|
435
|
+
};
|
|
436
|
+
type StatedOptions = LineOptions & {
|
|
437
|
+
/** Shown only: a stated line's quantity and rate aren't checked. */
|
|
438
|
+
quantity?: Operand;
|
|
439
|
+
rate?: Operand;
|
|
440
|
+
times?: Operand;
|
|
441
|
+
kind?: CalculationLineKind;
|
|
442
|
+
};
|
|
443
|
+
type TierBand = {
|
|
444
|
+
/** How much of the quantity this band takes per period; `null` takes the rest. */
|
|
445
|
+
size: number | string | DecimalLike | null;
|
|
446
|
+
rate: Operand;
|
|
447
|
+
label?: string;
|
|
448
|
+
/** The engine's figure for this band, when it has one. */
|
|
449
|
+
value?: unknown;
|
|
450
|
+
};
|
|
451
|
+
type TiersOptions = Omit<LineOptions, 'unit' | 'quantityUnit' | 'explain'> & {
|
|
452
|
+
label?: string;
|
|
453
|
+
/** The quantity per period that's split across the bands, such as `'daily_usage'`. */
|
|
454
|
+
quantity: Operand;
|
|
455
|
+
/** How many periods the bands apply over, such as `'days'`. Defaults to 1. */
|
|
456
|
+
periods?: Operand;
|
|
457
|
+
bands: TierBand[];
|
|
458
|
+
/** The quantity's unit, such as `'MJ'`. */
|
|
459
|
+
unit?: string;
|
|
460
|
+
/** The period the band sizes are per, such as `'day'`, for labels. */
|
|
461
|
+
per?: string;
|
|
462
|
+
/** `'last'` charges anything beyond the last band at its rate. */
|
|
463
|
+
overflow?: 'none' | 'last';
|
|
464
|
+
};
|
|
465
|
+
type PercentOfOptions = LineOptions & {
|
|
466
|
+
/** The line keys the percentage is of. */
|
|
467
|
+
of: string | string[];
|
|
468
|
+
/** A fraction (`-0.03` for a 3% discount) or the key of one. */
|
|
469
|
+
rate: Operand;
|
|
470
|
+
};
|
|
471
|
+
type TaxIncludedOptions = LineOptions & {
|
|
472
|
+
/** The line keys that include the tax. Defaults to every charge above not tagged `tax_free`. */
|
|
473
|
+
of?: string | string[];
|
|
474
|
+
/** Instead of `of`: every line above with this tag. */
|
|
475
|
+
tagged?: string;
|
|
476
|
+
/** The tax rate as a fraction, such as `0.1`, or the key of one. */
|
|
477
|
+
rate: Operand;
|
|
478
|
+
};
|
|
479
|
+
type BuiltCalculation = {
|
|
480
|
+
/** Undefined when there's nothing to send, such as no lines. */
|
|
481
|
+
calculation: Calculation | undefined;
|
|
482
|
+
problems: string[];
|
|
483
|
+
};
|
|
484
|
+
type Defined<NK> = Exclude<NK, undefined>;
|
|
485
|
+
declare class CalculationBuilder<K extends string = never> {
|
|
486
|
+
#private;
|
|
487
|
+
constructor(key: string, options?: CalculationOptions);
|
|
488
|
+
/** A value the calculation starts from: a usage, a rate, or a constant like 365.25 days. */
|
|
489
|
+
input<NK extends string>(key: NK, value: unknown, options?: InputOptions): CalculationBuilder<K | NK>;
|
|
490
|
+
/** A charge: `quantity * rate` (`* times`), checked against `value`. */
|
|
491
|
+
charge<NK extends string | undefined>(key: NK, label: string, options: ChargeOptions): CalculationBuilder<K | Defined<NK>>;
|
|
492
|
+
/** One step of a workings chain, with the formula it's derived by. */
|
|
493
|
+
step<NK extends string | undefined>(key: NK, label: string, formula: string, valueOrOptions?: unknown, options?: LineOptions): CalculationBuilder<K | Defined<NK>>;
|
|
494
|
+
/** An intermediate quantity, shown muted and left out of `sum_kind()`. */
|
|
495
|
+
working<NK extends string | undefined>(key: NK, label: string, formula: string, options?: LineOptions): CalculationBuilder<K | Defined<NK>>;
|
|
496
|
+
/** A value the engine gives with no formula. Its quantity and rate are shown, not checked. */
|
|
497
|
+
stated<NK extends string | undefined>(key: NK, label: string, options: StatedOptions): CalculationBuilder<K | Defined<NK>>;
|
|
498
|
+
/** A subtotal, such as charges before discounts. `null` formula = stated. */
|
|
499
|
+
subtotal<NK extends string | undefined>(key: NK, label: string, formula: string | null, options?: LineOptions): CalculationBuilder<K | Defined<NK>>;
|
|
500
|
+
/** A total, such as `round(sum_kind('charge'), 2)`. `null` formula = stated. */
|
|
501
|
+
total<NK extends string | undefined>(key: NK, label: string, formula: string | null, options?: LineOptions): CalculationBuilder<K | Defined<NK>>;
|
|
502
|
+
/** A muted line that isn't summed, such as tax included or a % difference. */
|
|
503
|
+
info<NK extends string | undefined>(key: NK, label: string, formula: string | null, options?: LineOptions): CalculationBuilder<K | Defined<NK>>;
|
|
504
|
+
/**
|
|
505
|
+
* A tiered charge: a charge per band, then a subtotal keyed `key` that's
|
|
506
|
+
* checked against `value`. Band n's quantity is the formula
|
|
507
|
+
* `clamp(quantity - before_n, 0, size_n) * periods`.
|
|
508
|
+
*/
|
|
509
|
+
tiers<NK extends string | undefined>(key: NK, options: TiersOptions): CalculationBuilder<K | Defined<NK>>;
|
|
510
|
+
/** A percentage of other lines, such as a discount: `rate * sum(of)`. */
|
|
511
|
+
percentOf<NK extends string | undefined>(key: NK, label: string, options: PercentOfOptions): CalculationBuilder<K | Defined<NK>>;
|
|
512
|
+
/** The tax a total includes: `sum(of) * rate / (1 + rate)`. */
|
|
513
|
+
taxIncluded<NK extends string | undefined>(key: NK, label: string, options: TaxIncludedOptions): CalculationBuilder<K | Defined<NK>>;
|
|
514
|
+
/** A line in the wire shape, for anything the helpers don't cover. */
|
|
515
|
+
line<NK extends string>(line: CalculationLine & {
|
|
516
|
+
key: NK;
|
|
517
|
+
}): CalculationBuilder<K | NK>;
|
|
518
|
+
/** A muted row under the lines. `{key}` placeholders are filled in. */
|
|
519
|
+
note(text: string): this;
|
|
520
|
+
/** A key, checked by TypeScript, for writing formulas: `` `${c.ref('days')} * 2` ``. */
|
|
521
|
+
ref<P extends K>(key: P): P;
|
|
522
|
+
/** Every key given so far, for editor completion: `c.keys.days`. */
|
|
523
|
+
get keys(): {
|
|
524
|
+
readonly [P in K]: P;
|
|
525
|
+
};
|
|
526
|
+
/** What's wrong with the calculation, such as a formula naming an unknown key. */
|
|
527
|
+
get problems(): readonly string[];
|
|
528
|
+
/** The calculation as it's sent. Attach calls build it for you. */
|
|
529
|
+
build(): Calculation;
|
|
530
|
+
/** @internal Builds once, never throws. */
|
|
531
|
+
compile(): BuiltCalculation;
|
|
532
|
+
}
|
|
533
|
+
/** Starts a calculation: inputs, then lines in display order. */
|
|
534
|
+
declare function calculation(key: string, options?: CalculationOptions): CalculationBuilder;
|
|
535
|
+
type CalculationLike = CalculationBuilder<string> | Calculation;
|
|
536
|
+
/**
|
|
537
|
+
* The units Recount formats specially. Any other unit is free text, such as
|
|
538
|
+
* `'kWh'` or `'MJ'`, and is shown as given. A currency code (`'AUD'`) is
|
|
539
|
+
* formatted as money, and `'AUD/kWh'` as a money rate.
|
|
540
|
+
*/
|
|
541
|
+
declare const units: {
|
|
542
|
+
/** A fraction shown as a percentage: `0.03` is `3%`. */
|
|
543
|
+
readonly percent: "%";
|
|
544
|
+
/** Counts: singular at 1 ("1 day"), and per one in a rate ("$0.67/day"). */
|
|
545
|
+
readonly days: "days";
|
|
546
|
+
readonly months: "months";
|
|
547
|
+
readonly years: "years";
|
|
548
|
+
readonly hours: "hours";
|
|
549
|
+
/** A rate per something: `units.per('AUD', 'kWh')` is `'AUD/kWh'`. */
|
|
550
|
+
readonly per: (unit: string, per: string) => string;
|
|
551
|
+
};
|
|
552
|
+
|
|
257
553
|
declare class SpanGroup {
|
|
258
554
|
#private;
|
|
259
555
|
span(type: 'table', name: string, options?: TableSpanOptions): this;
|
|
@@ -268,8 +564,10 @@ declare class SpanGroup {
|
|
|
268
564
|
}): this;
|
|
269
565
|
span(type: Exclude<SpanType, 'group'>, name: string, options?: SpanOptions): this;
|
|
270
566
|
addMessage(name: string, text?: string, opts?: MessageSpanOptions): this;
|
|
567
|
+
/** A table span holding these calculations, as a child of the group. */
|
|
568
|
+
calculation(name: string, calcs: CalculationLike | CalculationLike[], options?: CalculationSpanOptions): this;
|
|
271
569
|
alert(label: string, level: SpanAlertLevel, options?: SpanAlertOptions): this;
|
|
272
|
-
_flush(push: (type: string, name: string, opts?: SpanOptions) => void, options?: Pick<GroupSpanOptions, 'limit' | 'sample' | 'sampleThreshold'
|
|
570
|
+
_flush(push: (type: string, name: string, opts?: SpanOptions) => void, options?: Pick<GroupSpanOptions, 'limit' | 'sample' | 'sampleThreshold'>, log?: (msg: string) => void): void;
|
|
273
571
|
}
|
|
274
572
|
declare class Trace {
|
|
275
573
|
#private;
|
|
@@ -288,6 +586,8 @@ declare class Trace {
|
|
|
288
586
|
group(name: string, builder: (g: SpanGroup) => void, options?: GroupSpanOptions): this;
|
|
289
587
|
alert(label: string, level: SpanAlertLevel, options?: SpanAlertOptions): this;
|
|
290
588
|
addMessage(name: string, text?: string, opts?: MessageSpanOptions): this;
|
|
589
|
+
/** A table span holding these calculations. Pass builders without `.build()`. */
|
|
590
|
+
calculation(name: string, calcs: CalculationLike | CalculationLike[], options?: CalculationSpanOptions): this;
|
|
291
591
|
addMetadata(data: Metadata): this;
|
|
292
592
|
setEnvironment(environment: string): this;
|
|
293
593
|
/**
|
|
@@ -313,6 +613,13 @@ declare class Recount {
|
|
|
313
613
|
}
|
|
314
614
|
|
|
315
615
|
declare function spanCell(value: unknown, span: number): TableCellSpan;
|
|
616
|
+
/**
|
|
617
|
+
* A cell Recount formats itself, for key/value tables where each row has
|
|
618
|
+
* its own unit: `cell(18481.65, { format: 'number', unit: 'MJ' })`.
|
|
619
|
+
*/
|
|
620
|
+
declare function cell(value: TableTypedCell['value'], options?: CellFormatOptions & {
|
|
621
|
+
span?: number;
|
|
622
|
+
}): TableTypedCell;
|
|
316
623
|
declare class TableBuilder {
|
|
317
624
|
private _title?;
|
|
318
625
|
private _source?;
|
|
@@ -329,6 +636,8 @@ declare class TableBuilder {
|
|
|
329
636
|
private _extraRows;
|
|
330
637
|
private _summary?;
|
|
331
638
|
private _redactFields;
|
|
639
|
+
private _formats;
|
|
640
|
+
private _signHighlights;
|
|
332
641
|
constructor(title?: string);
|
|
333
642
|
redact(fields: string[]): this;
|
|
334
643
|
private _shouldRedact;
|
|
@@ -336,6 +645,17 @@ declare class TableBuilder {
|
|
|
336
645
|
fromRecords<T extends Record<string, unknown>>(data: T[]): this;
|
|
337
646
|
pick(...keys: string[]): this;
|
|
338
647
|
label(map: Record<string, string>): this;
|
|
648
|
+
/**
|
|
649
|
+
* Has Recount format these columns (records) or rows (objects), so send
|
|
650
|
+
* the numbers as they are: `.format({ cost: { format: 'money', currency: 'AUD' } })`.
|
|
651
|
+
* Formatted values aren't affected by `.round()`.
|
|
652
|
+
*/
|
|
653
|
+
format(map: Record<string, CellFormatOptions>): this;
|
|
654
|
+
/**
|
|
655
|
+
* Colours a column's numbers (records) or a row (objects) by sign:
|
|
656
|
+
* `.signHighlight('saving', { positive: 'success', negative: 'danger' })`.
|
|
657
|
+
*/
|
|
658
|
+
signHighlight(key: string, highlight: SignHighlight): this;
|
|
339
659
|
round(decimals: number): this;
|
|
340
660
|
transformValues(map: Record<string, (v: unknown) => unknown>): this;
|
|
341
661
|
spanColumn(key: string, span: number): this;
|
|
@@ -344,13 +664,14 @@ declare class TableBuilder {
|
|
|
344
664
|
highlightCells(key: string, fn: (value: unknown) => TableHighlight | null): this;
|
|
345
665
|
appendRow(cells: unknown[], highlight?: TableHighlight): this;
|
|
346
666
|
summary(stats: TableSummaryStat[]): this;
|
|
347
|
-
build():
|
|
667
|
+
build(): TableRowsData & {
|
|
348
668
|
rows: unknown[][];
|
|
349
669
|
};
|
|
350
670
|
buildSection(): TableSection;
|
|
351
671
|
private _build;
|
|
352
672
|
private _resolveLabel;
|
|
353
673
|
private _resolveColumn;
|
|
674
|
+
private _finalValue;
|
|
354
675
|
private _mergeRowHighlights;
|
|
355
676
|
private _buildRowHighlights;
|
|
356
677
|
private _buildFromObject;
|
|
@@ -360,20 +681,20 @@ declare function table(title?: string): TableBuilder;
|
|
|
360
681
|
declare function tableFromObject({ title, data }: {
|
|
361
682
|
title?: string;
|
|
362
683
|
data: Record<string, unknown>;
|
|
363
|
-
}):
|
|
684
|
+
}): TableRowsData & {
|
|
364
685
|
rows: unknown[][];
|
|
365
686
|
};
|
|
366
687
|
declare function tableFromRecords<T extends Record<string, unknown>>({ title, data }: {
|
|
367
688
|
title?: string;
|
|
368
689
|
data: T[];
|
|
369
|
-
}):
|
|
690
|
+
}): TableRowsData & {
|
|
370
691
|
rows: unknown[][];
|
|
371
692
|
};
|
|
372
693
|
declare function tableSections({ title, columns, sections }: {
|
|
373
694
|
title?: string;
|
|
374
695
|
columns?: TableColumn[];
|
|
375
696
|
sections: [TableSection | TableBuilder, ...(TableSection | TableBuilder)[]];
|
|
376
|
-
}):
|
|
697
|
+
}): TableRowsData & {
|
|
377
698
|
sections: [TableSection, ...TableSection[]];
|
|
378
699
|
};
|
|
379
700
|
|
|
@@ -422,6 +743,7 @@ declare function addSpan<T>(type: Exclude<SpanType, 'group'>, name: string, fn:
|
|
|
422
743
|
declare function addSpan<T>(type: Exclude<SpanType, 'group'>, name: string, opts: SpanOptions, fn: () => Promise<T>): Promise<T>;
|
|
423
744
|
declare function addGroup(name: string, builder: (g: SpanGroup) => void, options?: GroupSpanOptions): void;
|
|
424
745
|
declare function addMessage(name: string, text?: string, opts?: MessageSpanOptions): void;
|
|
746
|
+
declare function addCalculation(name: string, calcs: CalculationLike | CalculationLike[], opts?: CalculationSpanOptions): void;
|
|
425
747
|
declare function addAlert(label: string, level: SpanAlertLevel, opts?: SpanAlertOptions): void;
|
|
426
748
|
declare function named<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
427
749
|
declare function addMetadata(data: Metadata): void;
|
|
@@ -437,6 +759,7 @@ declare const recount: {
|
|
|
437
759
|
addSpan: typeof addSpan;
|
|
438
760
|
addGroup: typeof addGroup;
|
|
439
761
|
addMessage: typeof addMessage;
|
|
762
|
+
addCalculation: typeof addCalculation;
|
|
440
763
|
addAlert: typeof addAlert;
|
|
441
764
|
addMetadata: typeof addMetadata;
|
|
442
765
|
fetch: typeof fetch;
|
|
@@ -445,11 +768,21 @@ declare const recount: {
|
|
|
445
768
|
tableFromRecords: typeof tableFromRecords;
|
|
446
769
|
tableSections: typeof tableSections;
|
|
447
770
|
spanCell: typeof spanCell;
|
|
771
|
+
cell: typeof cell;
|
|
772
|
+
calculation: typeof calculation;
|
|
448
773
|
chart: typeof chart;
|
|
449
774
|
chartFromRecords: typeof chartFromRecords;
|
|
775
|
+
units: {
|
|
776
|
+
readonly percent: "%";
|
|
777
|
+
readonly days: "days";
|
|
778
|
+
readonly months: "months";
|
|
779
|
+
readonly years: "years";
|
|
780
|
+
readonly hours: "hours";
|
|
781
|
+
readonly per: (unit: string, per: string) => string;
|
|
782
|
+
};
|
|
450
783
|
REDACTED: {
|
|
451
784
|
readonly __redacted: true;
|
|
452
785
|
};
|
|
453
786
|
};
|
|
454
787
|
|
|
455
|
-
export { type ChartData, type ChartReferenceLine, type ChartSeries, type ChartSpanOptions, type ChartType, type DbParamValue, type DbSpanMetadata, type DbSpanOptions, type GroupSpanOptions, type HttpContentType, type HttpMethod, type HttpRequestInput, type HttpResponseOutput, type HttpSpanOptions, type ImageSpanData, type ImageSpanOptions, type IngestPayload, type IngestResult, type JsonObject, type JsonSpanOptions, type LlmMessage, type LlmSpanInput, type LlmSpanOptions, type LlmSpanOutput, type MessageSpanLevel, type MessageSpanOptions, type Metadata, REDACTED, Recount, RecountError, type RecountOptions, type RetentionPeriod, type Span, type SpanAlert, type SpanAlertCheck, type SpanAlertLevel, type SpanAlertOptions, type SpanBaseOptions, SpanGroup, type SpanOptions, type SpanType, type TableCellSpan, type TableColumn, type TableData, type TableDataFlat, type TableHighlight, type TableSection, type TableSpanOptions, type TableSummaryStat, type TraceOptions, addAlert, addGroup, addMessage, addMetadata, addSpan, chart, chartFromRecords, recount as default, fetch, init, named, spanCell, startTrace, table, tableFromObject, tableFromRecords, tableSections };
|
|
788
|
+
export { type Calculation, type CalculationAlerts, CalculationBuilder, type CalculationColumnLabels, type CalculationExpected, type CalculationInput, type CalculationLayout, type CalculationLike, type CalculationLine, type CalculationLineKind, type CalculationOptions, type CalculationSpanOptions, type CalculationTolerance, type CalculationValue, type CellFormat, type CellFormatOptions, type ChargeOptions, type ChartData, type ChartReferenceLine, type ChartSeries, type ChartSpanOptions, type ChartType, type DbParamValue, type DbSpanMetadata, type DbSpanOptions, type DecimalLike, type GroupSpanOptions, type HttpContentType, type HttpMethod, type HttpRequestInput, type HttpResponseOutput, type HttpSpanOptions, type ImageSpanData, type ImageSpanOptions, type IngestPayload, type IngestResult, type InputOptions, type JsonObject, type JsonSpanOptions, type LineOptions, type LlmMessage, type LlmSpanInput, type LlmSpanOptions, type LlmSpanOutput, type MessageSpanLevel, type MessageSpanOptions, type Metadata, type Operand, type PercentOfOptions, REDACTED, Recount, RecountError, type RecountOptions, type RetentionPeriod, type SignHighlight, type Span, type SpanAlert, type SpanAlertCheck, type SpanAlertLevel, type SpanAlertOptions, type SpanBaseOptions, SpanGroup, type SpanOptions, type SpanType, type StatedOptions, type TableCalculationData, type TableCellSpan, type TableColumn, type TableData, type TableDataFlat, type TableHighlight, type TableRowsData, type TableSection, type TableSpanOptions, type TableSummaryStat, type TableTypedCell, type TaxIncludedOptions, type TierBand, type TiersOptions, type TraceOptions, addAlert, addCalculation, addGroup, addMessage, addMetadata, addSpan, calculation, cell, chart, chartFromRecords, recount as default, fetch, init, named, spanCell, startTrace, table, tableFromObject, tableFromRecords, tableSections, units };
|