@koolbase/core 12.33.0 → 12.34.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 +9 -0
- package/dist/cjs/aggregate.js +0 -24
- package/dist/cjs/database.js +7 -0
- package/dist/esm/aggregate.d.ts +9 -0
- package/dist/esm/aggregate.js +0 -24
- package/dist/esm/database.js +7 -0
- package/package.json +1 -1
package/dist/cjs/aggregate.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KbWhereNode } from './query-builder.js';
|
|
1
2
|
/**
|
|
2
3
|
* Asking "how many" and "how much" over a collection, correctly.
|
|
3
4
|
*
|
|
@@ -67,6 +68,14 @@ export interface KoolbaseAggregateRequest {
|
|
|
67
68
|
collection: string;
|
|
68
69
|
/** AND-ed record filters on top of the read rule. */
|
|
69
70
|
where?: KoolbaseAggregateFilter[];
|
|
71
|
+
/**
|
|
72
|
+
* The typed filter a list's query takes (#165): and/or groups, ranges,
|
|
73
|
+
* dates, relative times -- so "upcoming events" counts what the list
|
|
74
|
+
* shows. Not with `where`.
|
|
75
|
+
*/
|
|
76
|
+
filter?: KbWhereNode;
|
|
77
|
+
/** The IANA zone the filter's relative times resolve in; the server's default if unset. */
|
|
78
|
+
timezone?: string;
|
|
70
79
|
/** Absent means one group: the measures over everything. */
|
|
71
80
|
groupBy?: KoolbaseGroupBy;
|
|
72
81
|
/** At least one. */
|
package/dist/cjs/aggregate.js
CHANGED
|
@@ -1,26 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Asking "how many" and "how much" over a collection, correctly.
|
|
4
|
-
*
|
|
5
|
-
* Correct means the whole authorized set — never the first page — with the
|
|
6
|
-
* caller's read rule applied inside the query, and never a bare number:
|
|
7
|
-
* collections are schemaless, so a total that quietly excluded three
|
|
8
|
-
* malformed rows would be a wrong number that looks right. Every result
|
|
9
|
-
* carries its accounting.
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const r = await Koolbase.db.aggregate({
|
|
13
|
-
* collection: 'orders',
|
|
14
|
-
* groupBy: { field: 'created_at', bucket: 'month', timezone: 'Africa/Accra' },
|
|
15
|
-
* measures: [{ aggregate: 'sum', field: 'total', as: 'revenue' }],
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* for (const g of r.groups) {
|
|
19
|
-
* console.log(g.category, g.values.revenue);
|
|
20
|
-
* }
|
|
21
|
-
* if (r.accounting.revenue.skipped > 0) {
|
|
22
|
-
* // some orders had a total that was not a number — say so
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/cjs/database.js
CHANGED
|
@@ -596,9 +596,16 @@ class KoolbaseDatabase {
|
|
|
596
596
|
* 23:30 sale belongs to.
|
|
597
597
|
*/
|
|
598
598
|
async aggregate(request) {
|
|
599
|
+
if (request.filter && request.where?.length) {
|
|
600
|
+
throw new TypeError('aggregate: provide filter or where, not both.');
|
|
601
|
+
}
|
|
599
602
|
const raw = await this.request('POST', '/v1/sdk/db/aggregate', {
|
|
600
603
|
collection: request.collection,
|
|
601
604
|
...(request.where?.length ? { where: request.where } : {}),
|
|
605
|
+
// The typed filter, as a list sends it: `where` as an object.
|
|
606
|
+
...(request.filter
|
|
607
|
+
? { where: request.filter, ...(request.timezone ? { timezone: request.timezone } : {}) }
|
|
608
|
+
: {}),
|
|
602
609
|
...(request.groupBy
|
|
603
610
|
? {
|
|
604
611
|
group_by: {
|
package/dist/esm/aggregate.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KbWhereNode } from './query-builder.js';
|
|
1
2
|
/**
|
|
2
3
|
* Asking "how many" and "how much" over a collection, correctly.
|
|
3
4
|
*
|
|
@@ -67,6 +68,14 @@ export interface KoolbaseAggregateRequest {
|
|
|
67
68
|
collection: string;
|
|
68
69
|
/** AND-ed record filters on top of the read rule. */
|
|
69
70
|
where?: KoolbaseAggregateFilter[];
|
|
71
|
+
/**
|
|
72
|
+
* The typed filter a list's query takes (#165): and/or groups, ranges,
|
|
73
|
+
* dates, relative times -- so "upcoming events" counts what the list
|
|
74
|
+
* shows. Not with `where`.
|
|
75
|
+
*/
|
|
76
|
+
filter?: KbWhereNode;
|
|
77
|
+
/** The IANA zone the filter's relative times resolve in; the server's default if unset. */
|
|
78
|
+
timezone?: string;
|
|
70
79
|
/** Absent means one group: the measures over everything. */
|
|
71
80
|
groupBy?: KoolbaseGroupBy;
|
|
72
81
|
/** At least one. */
|
package/dist/esm/aggregate.js
CHANGED
|
@@ -1,25 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asking "how many" and "how much" over a collection, correctly.
|
|
3
|
-
*
|
|
4
|
-
* Correct means the whole authorized set — never the first page — with the
|
|
5
|
-
* caller's read rule applied inside the query, and never a bare number:
|
|
6
|
-
* collections are schemaless, so a total that quietly excluded three
|
|
7
|
-
* malformed rows would be a wrong number that looks right. Every result
|
|
8
|
-
* carries its accounting.
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* const r = await Koolbase.db.aggregate({
|
|
12
|
-
* collection: 'orders',
|
|
13
|
-
* groupBy: { field: 'created_at', bucket: 'month', timezone: 'Africa/Accra' },
|
|
14
|
-
* measures: [{ aggregate: 'sum', field: 'total', as: 'revenue' }],
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* for (const g of r.groups) {
|
|
18
|
-
* console.log(g.category, g.values.revenue);
|
|
19
|
-
* }
|
|
20
|
-
* if (r.accounting.revenue.skipped > 0) {
|
|
21
|
-
* // some orders had a total that was not a number — say so
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
1
|
export {};
|
package/dist/esm/database.js
CHANGED
|
@@ -593,9 +593,16 @@ export class KoolbaseDatabase {
|
|
|
593
593
|
* 23:30 sale belongs to.
|
|
594
594
|
*/
|
|
595
595
|
async aggregate(request) {
|
|
596
|
+
if (request.filter && request.where?.length) {
|
|
597
|
+
throw new TypeError('aggregate: provide filter or where, not both.');
|
|
598
|
+
}
|
|
596
599
|
const raw = await this.request('POST', '/v1/sdk/db/aggregate', {
|
|
597
600
|
collection: request.collection,
|
|
598
601
|
...(request.where?.length ? { where: request.where } : {}),
|
|
602
|
+
// The typed filter, as a list sends it: `where` as an object.
|
|
603
|
+
...(request.filter
|
|
604
|
+
? { where: request.filter, ...(request.timezone ? { timezone: request.timezone } : {}) }
|
|
605
|
+
: {}),
|
|
599
606
|
...(request.groupBy
|
|
600
607
|
? {
|
|
601
608
|
group_by: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.34.0",
|
|
4
4
|
"description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|