@koolbase/core 12.51.0 → 12.52.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/cjs/aggregate.d.ts +32 -0
- package/dist/cjs/database.js +8 -0
- package/dist/esm/aggregate.d.ts +32 -0
- package/dist/esm/database.js +8 -0
- package/package.json +1 -1
package/dist/cjs/aggregate.d.ts
CHANGED
|
@@ -53,14 +53,31 @@ export type KoolbaseGroupBy = {
|
|
|
53
53
|
* `count` counts RECORDS, so it takes no field and skips nothing. The others
|
|
54
54
|
* read a field, and a record whose value is missing or not a number is
|
|
55
55
|
* skipped and reported in the result's accounting.
|
|
56
|
+
*
|
|
57
|
+
* `sum_product` adds up the product of two fields -- amount times
|
|
58
|
+
* probability -- over the records where BOTH are numbers. `byScale: 100`
|
|
59
|
+
* says `by` is a percentage stored 0 to 100, so 40 multiplies as 0.4; when
|
|
60
|
+
* the field is declared a percent or probability, its declared scale is used
|
|
61
|
+
* and need not be sent.
|
|
56
62
|
*/
|
|
57
63
|
export type KoolbaseMeasure = {
|
|
58
64
|
aggregate: 'count';
|
|
59
65
|
field?: never;
|
|
66
|
+
by?: never;
|
|
67
|
+
byScale?: never;
|
|
60
68
|
as: string;
|
|
61
69
|
} | {
|
|
62
70
|
aggregate: 'sum' | 'avg' | 'min' | 'max';
|
|
63
71
|
field: string;
|
|
72
|
+
by?: never;
|
|
73
|
+
byScale?: never;
|
|
74
|
+
as: string;
|
|
75
|
+
} | {
|
|
76
|
+
aggregate: 'sum_product';
|
|
77
|
+
field: string;
|
|
78
|
+
/** The second field: each record contributes field times by. */
|
|
79
|
+
by: string;
|
|
80
|
+
byScale?: 1 | 100;
|
|
64
81
|
as: string;
|
|
65
82
|
};
|
|
66
83
|
/** One aggregation request. */
|
|
@@ -87,6 +104,15 @@ export interface KoolbaseAggregateGroup {
|
|
|
87
104
|
category: string;
|
|
88
105
|
/** Keyed by each measure's `as`. Null where a group had nothing to measure. */
|
|
89
106
|
values: Record<string, number | null>;
|
|
107
|
+
/**
|
|
108
|
+
* Every value as an exact decimal string, computed without floating point:
|
|
109
|
+
* `"1234.50"`, never 1234.4999999. Same keys and the same nulls as
|
|
110
|
+
* `values`. Read money from here, and format the string: do not turn it
|
|
111
|
+
* back into a number first. A sum, min, max and sum_product are exact; an
|
|
112
|
+
* average is given to 12 decimal places; a count is an integer. Empty
|
|
113
|
+
* against an API from before exact totals.
|
|
114
|
+
*/
|
|
115
|
+
exact: Record<string, string | null>;
|
|
90
116
|
/**
|
|
91
117
|
* The collection's count minimum (#299), when this group's count was below
|
|
92
118
|
* it: every value is null, and what to show is "Fewer than N" -- never 0,
|
|
@@ -107,6 +133,12 @@ export interface KoolbaseAggregateAccounting {
|
|
|
107
133
|
skipped: number;
|
|
108
134
|
/** Present when skipped > 0. */
|
|
109
135
|
skippedReason?: 'missing' | 'not_numeric' | 'mixed';
|
|
136
|
+
/**
|
|
137
|
+
* `sum_product` only, when skipped > 0: how many skipped records had no
|
|
138
|
+
* usable number in each of its two fields. A record lacking both counts
|
|
139
|
+
* under both.
|
|
140
|
+
*/
|
|
141
|
+
skippedByField?: Record<string, number>;
|
|
110
142
|
}
|
|
111
143
|
/** The whole answer, including what could not be counted. */
|
|
112
144
|
export interface KoolbaseAggregateResult {
|
package/dist/cjs/database.js
CHANGED
|
@@ -718,6 +718,9 @@ class KoolbaseDatabase {
|
|
|
718
718
|
measures: request.measures.map((m) => ({
|
|
719
719
|
aggregate: m.aggregate,
|
|
720
720
|
...(m.field ? { field: m.field } : {}),
|
|
721
|
+
// sum_product: the second field, and its scale when given.
|
|
722
|
+
...(m.by ? { by: m.by } : {}),
|
|
723
|
+
...(m.byScale ? { by_scale: m.byScale } : {}),
|
|
721
724
|
as: m.as,
|
|
722
725
|
})),
|
|
723
726
|
});
|
|
@@ -727,12 +730,17 @@ class KoolbaseDatabase {
|
|
|
727
730
|
counted: Number(a.counted ?? 0),
|
|
728
731
|
skipped: Number(a.skipped ?? 0),
|
|
729
732
|
skippedReason: a.skipped_reason,
|
|
733
|
+
...(a.skipped_by_field && typeof a.skipped_by_field === 'object'
|
|
734
|
+
? { skippedByField: a.skipped_by_field }
|
|
735
|
+
: {}),
|
|
730
736
|
};
|
|
731
737
|
}
|
|
732
738
|
return {
|
|
733
739
|
groups: (raw.groups ?? []).map((g) => ({
|
|
734
740
|
category: String(g.category ?? ''),
|
|
735
741
|
values: g.values ?? {},
|
|
742
|
+
// Exact decimals, as strings (C5): money is read from here.
|
|
743
|
+
exact: g.exact ?? {},
|
|
736
744
|
// Below the collection's count minimum (#299): "Fewer than N".
|
|
737
745
|
...(typeof g.fewer_than === 'number' ? { fewerThan: g.fewer_than } : {}),
|
|
738
746
|
})),
|
package/dist/esm/aggregate.d.ts
CHANGED
|
@@ -53,14 +53,31 @@ export type KoolbaseGroupBy = {
|
|
|
53
53
|
* `count` counts RECORDS, so it takes no field and skips nothing. The others
|
|
54
54
|
* read a field, and a record whose value is missing or not a number is
|
|
55
55
|
* skipped and reported in the result's accounting.
|
|
56
|
+
*
|
|
57
|
+
* `sum_product` adds up the product of two fields -- amount times
|
|
58
|
+
* probability -- over the records where BOTH are numbers. `byScale: 100`
|
|
59
|
+
* says `by` is a percentage stored 0 to 100, so 40 multiplies as 0.4; when
|
|
60
|
+
* the field is declared a percent or probability, its declared scale is used
|
|
61
|
+
* and need not be sent.
|
|
56
62
|
*/
|
|
57
63
|
export type KoolbaseMeasure = {
|
|
58
64
|
aggregate: 'count';
|
|
59
65
|
field?: never;
|
|
66
|
+
by?: never;
|
|
67
|
+
byScale?: never;
|
|
60
68
|
as: string;
|
|
61
69
|
} | {
|
|
62
70
|
aggregate: 'sum' | 'avg' | 'min' | 'max';
|
|
63
71
|
field: string;
|
|
72
|
+
by?: never;
|
|
73
|
+
byScale?: never;
|
|
74
|
+
as: string;
|
|
75
|
+
} | {
|
|
76
|
+
aggregate: 'sum_product';
|
|
77
|
+
field: string;
|
|
78
|
+
/** The second field: each record contributes field times by. */
|
|
79
|
+
by: string;
|
|
80
|
+
byScale?: 1 | 100;
|
|
64
81
|
as: string;
|
|
65
82
|
};
|
|
66
83
|
/** One aggregation request. */
|
|
@@ -87,6 +104,15 @@ export interface KoolbaseAggregateGroup {
|
|
|
87
104
|
category: string;
|
|
88
105
|
/** Keyed by each measure's `as`. Null where a group had nothing to measure. */
|
|
89
106
|
values: Record<string, number | null>;
|
|
107
|
+
/**
|
|
108
|
+
* Every value as an exact decimal string, computed without floating point:
|
|
109
|
+
* `"1234.50"`, never 1234.4999999. Same keys and the same nulls as
|
|
110
|
+
* `values`. Read money from here, and format the string: do not turn it
|
|
111
|
+
* back into a number first. A sum, min, max and sum_product are exact; an
|
|
112
|
+
* average is given to 12 decimal places; a count is an integer. Empty
|
|
113
|
+
* against an API from before exact totals.
|
|
114
|
+
*/
|
|
115
|
+
exact: Record<string, string | null>;
|
|
90
116
|
/**
|
|
91
117
|
* The collection's count minimum (#299), when this group's count was below
|
|
92
118
|
* it: every value is null, and what to show is "Fewer than N" -- never 0,
|
|
@@ -107,6 +133,12 @@ export interface KoolbaseAggregateAccounting {
|
|
|
107
133
|
skipped: number;
|
|
108
134
|
/** Present when skipped > 0. */
|
|
109
135
|
skippedReason?: 'missing' | 'not_numeric' | 'mixed';
|
|
136
|
+
/**
|
|
137
|
+
* `sum_product` only, when skipped > 0: how many skipped records had no
|
|
138
|
+
* usable number in each of its two fields. A record lacking both counts
|
|
139
|
+
* under both.
|
|
140
|
+
*/
|
|
141
|
+
skippedByField?: Record<string, number>;
|
|
110
142
|
}
|
|
111
143
|
/** The whole answer, including what could not be counted. */
|
|
112
144
|
export interface KoolbaseAggregateResult {
|
package/dist/esm/database.js
CHANGED
|
@@ -715,6 +715,9 @@ export class KoolbaseDatabase {
|
|
|
715
715
|
measures: request.measures.map((m) => ({
|
|
716
716
|
aggregate: m.aggregate,
|
|
717
717
|
...(m.field ? { field: m.field } : {}),
|
|
718
|
+
// sum_product: the second field, and its scale when given.
|
|
719
|
+
...(m.by ? { by: m.by } : {}),
|
|
720
|
+
...(m.byScale ? { by_scale: m.byScale } : {}),
|
|
718
721
|
as: m.as,
|
|
719
722
|
})),
|
|
720
723
|
});
|
|
@@ -724,12 +727,17 @@ export class KoolbaseDatabase {
|
|
|
724
727
|
counted: Number(a.counted ?? 0),
|
|
725
728
|
skipped: Number(a.skipped ?? 0),
|
|
726
729
|
skippedReason: a.skipped_reason,
|
|
730
|
+
...(a.skipped_by_field && typeof a.skipped_by_field === 'object'
|
|
731
|
+
? { skippedByField: a.skipped_by_field }
|
|
732
|
+
: {}),
|
|
727
733
|
};
|
|
728
734
|
}
|
|
729
735
|
return {
|
|
730
736
|
groups: (raw.groups ?? []).map((g) => ({
|
|
731
737
|
category: String(g.category ?? ''),
|
|
732
738
|
values: g.values ?? {},
|
|
739
|
+
// Exact decimals, as strings (C5): money is read from here.
|
|
740
|
+
exact: g.exact ?? {},
|
|
733
741
|
// Below the collection's count minimum (#299): "Fewer than N".
|
|
734
742
|
...(typeof g.fewer_than === 'number' ? { fewerThan: g.fewer_than } : {}),
|
|
735
743
|
})),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.52.0",
|
|
4
4
|
"description": "Koolbase SDK core — shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"react-native": "./dist/esm/index.js",
|