@@ -10,33 +10,35 @@ import { Aggregator } from '../../graphql/index.js';
10
10
import { toBase64FromMedia } from '../../index.js' ;
11
11
import { Serialize } from '../serialize/index.js' ;
12
12
13
- export type AggregateBaseOptions < T , M > = {
13
+ export type AggregateBaseOptions < M > = {
14
14
filters ?: FilterValue ;
15
15
returnMetrics ?: M ;
16
16
} ;
17
17
18
- export type AggregateGroupByOptions < T , M > = AggregateOptions < T , M > & {
19
- groupBy : ( keyof T & string ) | GroupByAggregate < T > ;
18
+ export type PropertyOf < T > = T extends undefined ? string : keyof T & string ;
19
+
20
+ export type AggregateGroupByOptions < T , M > = AggregateOptions < M > & {
21
+ groupBy : PropertyOf < T > | GroupByAggregate < T > ;
20
22
} ;
21
23
22
24
export type GroupByAggregate < T > = {
23
- property : keyof T & string ;
25
+ property : PropertyOf < T > ;
24
26
limit ?: number ;
25
27
} ;
26
28
27
- export type AggregateOptions < T , M > = AggregateBaseOptions < T , M > ;
29
+ export type AggregateOptions < M > = AggregateBaseOptions < M > ;
28
30
29
- export type AggregateBaseOverAllOptions < T , M > = AggregateBaseOptions < T , M > ;
31
+ export type AggregateBaseOverAllOptions < M > = AggregateBaseOptions < M > ;
30
32
31
- export type AggregateNearOptions < T , M > = AggregateBaseOptions < T , M > & {
33
+ export type AggregateNearOptions < M > = AggregateBaseOptions < M > & {
32
34
certainty ?: number ;
33
35
distance ?: number ;
34
36
objectLimit ?: number ;
35
37
targetVector ?: string ;
36
38
} ;
37
39
38
- export type AggregateGroupByNearOptions < T , M > = AggregateNearOptions < T , M > & {
39
- groupBy : ( keyof T & string ) | GroupByAggregate < T > ;
40
+ export type AggregateGroupByNearOptions < T , M > = AggregateNearOptions < M > & {
41
+ groupBy : PropertyOf < T > | GroupByAggregate < T > ;
40
42
} ;
41
43
42
44
export type AggregateBoolean = {
@@ -126,11 +128,11 @@ export type AggregateMetrics<M> = {
126
128
[ K in keyof M ] : M [ K ] extends true ? number : never ;
127
129
} ;
128
130
129
- export type MetricsProperty < T > = T extends undefined ? string : keyof T & string ;
131
+ export type MetricsProperty < T > = PropertyOf < T > ;
130
132
131
133
export const metrics = < T > ( ) => {
132
134
return {
133
- aggregate : < P extends MetricsProperty < T > > ( property : P ) => new MetricsManager < T , P > ( property ) ,
135
+ aggregate : < P extends PropertyOf < T > > ( property : P ) => new MetricsManager < T , P > ( property ) ,
134
136
} ;
135
137
} ;
136
138
@@ -143,10 +145,10 @@ export interface Metrics<T> {
143
145
144
146
See [the docs](https://weaviate.io/developers/weaviate/search/aggregate) for more details!
145
147
*/
146
- aggregate : < P extends MetricsProperty < T > > ( property : P ) => MetricsManager < T , P > ;
148
+ aggregate : < P extends PropertyOf < T > > ( property : P ) => MetricsManager < T , P > ;
147
149
}
148
150
149
- export class MetricsManager < T , P extends MetricsProperty < T > > {
151
+ export class MetricsManager < T , P extends PropertyOf < T > > {
150
152
private propertyName : P ;
151
153
152
154
constructor ( property : P ) {
@@ -419,11 +421,7 @@ class AggregateManager<T> implements Aggregate<T> {
419
421
return new Aggregator ( this . connection ) ;
420
422
}
421
423
422
- base (
423
- metrics ?: PropertiesMetrics < T > ,
424
- filters ?: FilterValue ,
425
- groupBy ?: ( keyof T & string ) | GroupByAggregate < T >
426
- ) {
424
+ base ( metrics ?: PropertiesMetrics < T > , filters ?: FilterValue , groupBy ?: PropertyOf < T > | GroupByAggregate < T > ) {
427
425
let fields = 'meta { count }' ;
428
426
let builder = this . query ( ) . withClassName ( this . name ) ;
429
427
if ( metrics ) {
@@ -491,7 +489,7 @@ class AggregateManager<T> implements Aggregate<T> {
491
489
492
490
async nearImage < M extends PropertiesMetrics < T > > (
493
491
image : string | Buffer ,
494
- opts ?: AggregateNearOptions < T , M >
492
+ opts ?: AggregateNearOptions < M >
495
493
) : Promise < AggregateResult < T , M > > {
496
494
const builder = this . base ( opts ?. returnMetrics , opts ?. filters ) . withNearImage ( {
497
495
image : await toBase64FromMedia ( image ) ,
@@ -507,7 +505,7 @@ class AggregateManager<T> implements Aggregate<T> {
507
505
508
506
nearObject < M extends PropertiesMetrics < T > > (
509
507
id : string ,
510
- opts ?: AggregateNearOptions < T , M >
508
+ opts ?: AggregateNearOptions < M >
511
509
) : Promise < AggregateResult < T , M > > {
512
510
const builder = this . base ( opts ?. returnMetrics , opts ?. filters ) . withNearObject ( {
513
511
id : id ,
@@ -523,7 +521,7 @@ class AggregateManager<T> implements Aggregate<T> {
523
521
524
522
nearText < M extends PropertiesMetrics < T > > (
525
523
query : string | string [ ] ,
526
- opts ?: AggregateNearOptions < T , M >
524
+ opts ?: AggregateNearOptions < M >
527
525
) : Promise < AggregateResult < T , M > > {
528
526
const builder = this . base ( opts ?. returnMetrics , opts ?. filters ) . withNearText ( {
529
527
concepts : Array . isArray ( query ) ? query : [ query ] ,
@@ -539,7 +537,7 @@ class AggregateManager<T> implements Aggregate<T> {
539
537
540
538
nearVector < M extends PropertiesMetrics < T > > (
541
539
vector : number [ ] ,
542
- opts ?: AggregateNearOptions < T , M >
540
+ opts ?: AggregateNearOptions < M >
543
541
) : Promise < AggregateResult < T , M > > {
544
542
const builder = this . base ( opts ?. returnMetrics , opts ?. filters ) . withNearVector ( {
545
543
vector : vector ,
@@ -553,7 +551,7 @@ class AggregateManager<T> implements Aggregate<T> {
553
551
return this . do ( builder ) ;
554
552
}
555
553
556
- overAll < M extends PropertiesMetrics < T > > ( opts ?: AggregateOptions < T , M > ) : Promise < AggregateResult < T , M > > {
554
+ overAll < M extends PropertiesMetrics < T > > ( opts ?: AggregateOptions < M > ) : Promise < AggregateResult < T , M > > {
557
555
const builder = this . base ( opts ?. returnMetrics , opts ?. filters ) ;
558
556
return this . do ( builder ) ;
559
557
}
@@ -615,7 +613,7 @@ export interface Aggregate<T> {
615
613
*/
616
614
nearImage < M extends PropertiesMetrics < T > > (
617
615
image : string | Buffer ,
618
- opts ?: AggregateNearOptions < T , M >
616
+ opts ?: AggregateNearOptions < M >
619
617
) : Promise < AggregateResult < T , M > > ;
620
618
/**
621
619
* Aggregate metrics over the objects returned by a near object search on this collection.
@@ -630,7 +628,7 @@ export interface Aggregate<T> {
630
628
*/
631
629
nearObject < M extends PropertiesMetrics < T > > (
632
630
id : string ,
633
- opts ?: AggregateNearOptions < T , M >
631
+ opts ?: AggregateNearOptions < M >
634
632
) : Promise < AggregateResult < T , M > > ;
635
633
/**
636
634
* Aggregate metrics over the objects returned by a near vector search on this collection.
@@ -645,7 +643,7 @@ export interface Aggregate<T> {
645
643
*/
646
644
nearText < M extends PropertiesMetrics < T > > (
647
645
query : string | string [ ] ,
648
- opts ?: AggregateNearOptions < T , M >
646
+ opts ?: AggregateNearOptions < M >
649
647
) : Promise < AggregateResult < T , M > > ;
650
648
/**
651
649
* Aggregate metrics over the objects returned by a near vector search on this collection.
@@ -660,15 +658,15 @@ export interface Aggregate<T> {
660
658
*/
661
659
nearVector < M extends PropertiesMetrics < T > > (
662
660
vector : number [ ] ,
663
- opts ?: AggregateNearOptions < T , M >
661
+ opts ?: AggregateNearOptions < M >
664
662
) : Promise < AggregateResult < T , M > > ;
665
663
/**
666
664
* Aggregate metrics over all the objects in this collection without any vector search.
667
665
*
668
666
* @param {AggregateOptions<T, M> } [opts] The options for the request.
669
667
* @returns {Promise<AggregateResult<T, M>[]> } The aggregated metrics for the objects in the collection.
670
668
*/
671
- overAll < M extends PropertiesMetrics < T > > ( opts ?: AggregateOptions < T , M > ) : Promise < AggregateResult < T , M > > ;
669
+ overAll < M extends PropertiesMetrics < T > > ( opts ?: AggregateOptions < M > ) : Promise < AggregateResult < T , M > > ;
672
670
}
673
671
674
672
export interface AggregateGroupBy < T > {
0 commit comments