@koolbase/core 12.32.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.d.ts +6 -0
- package/dist/cjs/database.js +16 -0
- package/dist/esm/aggregate.d.ts +9 -0
- package/dist/esm/aggregate.js +0 -24
- package/dist/esm/database.d.ts +6 -0
- package/dist/esm/database.js +16 -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.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KbWhereNode } from './query-builder.js';
|
|
1
2
|
import { KoolbaseAggregateRequest, KoolbaseAggregateResult } from './aggregate.js';
|
|
2
3
|
import { KoolbaseConflict } from './conflict.js';
|
|
3
4
|
import { PendingWrite } from './pending-write.js';
|
|
@@ -376,6 +377,11 @@ export declare class KoolbaseDatabase {
|
|
|
376
377
|
where?: Record<string, unknown>;
|
|
377
378
|
mode?: SearchMode;
|
|
378
379
|
minSimilarity?: number;
|
|
380
|
+
/** The typed filter (#165, #173): the tree list queries take, applied
|
|
381
|
+
* inside the collection's read rule in every mode. Not with `where`. */
|
|
382
|
+
filter?: KbWhereNode;
|
|
383
|
+
/** The IANA zone the filter's days are read in; the device's if unset. */
|
|
384
|
+
timezone?: string;
|
|
379
385
|
}): Promise<SemanticSearchResult>;
|
|
380
386
|
syncPendingWrites(): Promise<void>;
|
|
381
387
|
}
|
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: {
|
|
@@ -1061,6 +1068,9 @@ class KoolbaseDatabase {
|
|
|
1061
1068
|
* server on lexical mode.
|
|
1062
1069
|
*/
|
|
1063
1070
|
async searchSemantic(opts) {
|
|
1071
|
+
if (opts.filter && opts.where && Object.keys(opts.where).length > 0) {
|
|
1072
|
+
throw new TypeError('searchSemantic: provide filter or where, not both.');
|
|
1073
|
+
}
|
|
1064
1074
|
const hasVector = Array.isArray(opts.queryVector) && opts.queryVector.length > 0;
|
|
1065
1075
|
const hasText = typeof opts.queryText === 'string' && opts.queryText.trim().length > 0;
|
|
1066
1076
|
if (!hasVector && !hasText) {
|
|
@@ -1093,6 +1103,12 @@ class KoolbaseDatabase {
|
|
|
1093
1103
|
if (opts.minSimilarity !== undefined) {
|
|
1094
1104
|
body.min_similarity = opts.minSimilarity;
|
|
1095
1105
|
}
|
|
1106
|
+
if (opts.filter) {
|
|
1107
|
+
body.filter = opts.filter;
|
|
1108
|
+
const zone = opts.timezone ?? (0, query_builder_js_1.deviceZone)();
|
|
1109
|
+
if (zone)
|
|
1110
|
+
body.timezone = zone;
|
|
1111
|
+
}
|
|
1096
1112
|
const raw = await this.request('POST', '/v1/sdk/db/search-semantic', body);
|
|
1097
1113
|
// A hit carries the complete public record, not a projection, so these are
|
|
1098
1114
|
// safe to cache as baselines. A trimmed record would be worse than none: an
|
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.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KbWhereNode } from './query-builder.js';
|
|
1
2
|
import { KoolbaseAggregateRequest, KoolbaseAggregateResult } from './aggregate.js';
|
|
2
3
|
import { KoolbaseConflict } from './conflict.js';
|
|
3
4
|
import { PendingWrite } from './pending-write.js';
|
|
@@ -376,6 +377,11 @@ export declare class KoolbaseDatabase {
|
|
|
376
377
|
where?: Record<string, unknown>;
|
|
377
378
|
mode?: SearchMode;
|
|
378
379
|
minSimilarity?: number;
|
|
380
|
+
/** The typed filter (#165, #173): the tree list queries take, applied
|
|
381
|
+
* inside the collection's read rule in every mode. Not with `where`. */
|
|
382
|
+
filter?: KbWhereNode;
|
|
383
|
+
/** The IANA zone the filter's days are read in; the device's if unset. */
|
|
384
|
+
timezone?: string;
|
|
379
385
|
}): Promise<SemanticSearchResult>;
|
|
380
386
|
syncPendingWrites(): Promise<void>;
|
|
381
387
|
}
|
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: {
|
|
@@ -1058,6 +1065,9 @@ export class KoolbaseDatabase {
|
|
|
1058
1065
|
* server on lexical mode.
|
|
1059
1066
|
*/
|
|
1060
1067
|
async searchSemantic(opts) {
|
|
1068
|
+
if (opts.filter && opts.where && Object.keys(opts.where).length > 0) {
|
|
1069
|
+
throw new TypeError('searchSemantic: provide filter or where, not both.');
|
|
1070
|
+
}
|
|
1061
1071
|
const hasVector = Array.isArray(opts.queryVector) && opts.queryVector.length > 0;
|
|
1062
1072
|
const hasText = typeof opts.queryText === 'string' && opts.queryText.trim().length > 0;
|
|
1063
1073
|
if (!hasVector && !hasText) {
|
|
@@ -1090,6 +1100,12 @@ export class KoolbaseDatabase {
|
|
|
1090
1100
|
if (opts.minSimilarity !== undefined) {
|
|
1091
1101
|
body.min_similarity = opts.minSimilarity;
|
|
1092
1102
|
}
|
|
1103
|
+
if (opts.filter) {
|
|
1104
|
+
body.filter = opts.filter;
|
|
1105
|
+
const zone = opts.timezone ?? deviceZone();
|
|
1106
|
+
if (zone)
|
|
1107
|
+
body.timezone = zone;
|
|
1108
|
+
}
|
|
1093
1109
|
const raw = await this.request('POST', '/v1/sdk/db/search-semantic', body);
|
|
1094
1110
|
// A hit carries the complete public record, not a projection, so these are
|
|
1095
1111
|
// safe to cache as baselines. A trimmed record would be worse than none: an
|
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",
|