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