Skip to content

Commit 9c1ea29

Browse files
committed
Make typing changes in response to review
1 parent 9d27f2f commit 9c1ea29

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

src/collections/aggregate/index.ts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,35 @@ import { Aggregator } from '../../graphql/index.js';
1010
import { toBase64FromMedia } from '../../index.js';
1111
import { Serialize } from '../serialize/index.js';
1212

13-
export type AggregateBaseOptions<T, M> = {
13+
export type AggregateBaseOptions<M> = {
1414
filters?: FilterValue;
1515
returnMetrics?: M;
1616
};
1717

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>;
2022
};
2123

2224
export type GroupByAggregate<T> = {
23-
property: keyof T & string;
25+
property: PropertyOf<T>;
2426
limit?: number;
2527
};
2628

27-
export type AggregateOptions<T, M> = AggregateBaseOptions<T, M>;
29+
export type AggregateOptions<M> = AggregateBaseOptions<M>;
2830

29-
export type AggregateBaseOverAllOptions<T, M> = AggregateBaseOptions<T, M>;
31+
export type AggregateBaseOverAllOptions<M> = AggregateBaseOptions<M>;
3032

31-
export type AggregateNearOptions<T, M> = AggregateBaseOptions<T, M> & {
33+
export type AggregateNearOptions<M> = AggregateBaseOptions<M> & {
3234
certainty?: number;
3335
distance?: number;
3436
objectLimit?: number;
3537
targetVector?: string;
3638
};
3739

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>;
4042
};
4143

4244
export type AggregateBoolean = {
@@ -126,11 +128,11 @@ export type AggregateMetrics<M> = {
126128
[K in keyof M]: M[K] extends true ? number : never;
127129
};
128130

129-
export type MetricsProperty<T> = T extends undefined ? string : keyof T & string;
131+
export type MetricsProperty<T> = PropertyOf<T>;
130132

131133
export const metrics = <T>() => {
132134
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),
134136
};
135137
};
136138

@@ -143,10 +145,10 @@ export interface Metrics<T> {
143145
144146
See [the docs](https://weaviate.io/developers/weaviate/search/aggregate) for more details!
145147
*/
146-
aggregate: <P extends MetricsProperty<T>>(property: P) => MetricsManager<T, P>;
148+
aggregate: <P extends PropertyOf<T>>(property: P) => MetricsManager<T, P>;
147149
}
148150

149-
export class MetricsManager<T, P extends MetricsProperty<T>> {
151+
export class MetricsManager<T, P extends PropertyOf<T>> {
150152
private propertyName: P;
151153

152154
constructor(property: P) {
@@ -419,11 +421,7 @@ class AggregateManager<T> implements Aggregate<T> {
419421
return new Aggregator(this.connection);
420422
}
421423

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>) {
427425
let fields = 'meta { count }';
428426
let builder = this.query().withClassName(this.name);
429427
if (metrics) {
@@ -491,7 +489,7 @@ class AggregateManager<T> implements Aggregate<T> {
491489

492490
async nearImage<M extends PropertiesMetrics<T>>(
493491
image: string | Buffer,
494-
opts?: AggregateNearOptions<T, M>
492+
opts?: AggregateNearOptions<M>
495493
): Promise<AggregateResult<T, M>> {
496494
const builder = this.base(opts?.returnMetrics, opts?.filters).withNearImage({
497495
image: await toBase64FromMedia(image),
@@ -507,7 +505,7 @@ class AggregateManager<T> implements Aggregate<T> {
507505

508506
nearObject<M extends PropertiesMetrics<T>>(
509507
id: string,
510-
opts?: AggregateNearOptions<T, M>
508+
opts?: AggregateNearOptions<M>
511509
): Promise<AggregateResult<T, M>> {
512510
const builder = this.base(opts?.returnMetrics, opts?.filters).withNearObject({
513511
id: id,
@@ -523,7 +521,7 @@ class AggregateManager<T> implements Aggregate<T> {
523521

524522
nearText<M extends PropertiesMetrics<T>>(
525523
query: string | string[],
526-
opts?: AggregateNearOptions<T, M>
524+
opts?: AggregateNearOptions<M>
527525
): Promise<AggregateResult<T, M>> {
528526
const builder = this.base(opts?.returnMetrics, opts?.filters).withNearText({
529527
concepts: Array.isArray(query) ? query : [query],
@@ -539,7 +537,7 @@ class AggregateManager<T> implements Aggregate<T> {
539537

540538
nearVector<M extends PropertiesMetrics<T>>(
541539
vector: number[],
542-
opts?: AggregateNearOptions<T, M>
540+
opts?: AggregateNearOptions<M>
543541
): Promise<AggregateResult<T, M>> {
544542
const builder = this.base(opts?.returnMetrics, opts?.filters).withNearVector({
545543
vector: vector,
@@ -553,7 +551,7 @@ class AggregateManager<T> implements Aggregate<T> {
553551
return this.do(builder);
554552
}
555553

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>> {
557555
const builder = this.base(opts?.returnMetrics, opts?.filters);
558556
return this.do(builder);
559557
}
@@ -615,7 +613,7 @@ export interface Aggregate<T> {
615613
*/
616614
nearImage<M extends PropertiesMetrics<T>>(
617615
image: string | Buffer,
618-
opts?: AggregateNearOptions<T, M>
616+
opts?: AggregateNearOptions<M>
619617
): Promise<AggregateResult<T, M>>;
620618
/**
621619
* Aggregate metrics over the objects returned by a near object search on this collection.
@@ -630,7 +628,7 @@ export interface Aggregate<T> {
630628
*/
631629
nearObject<M extends PropertiesMetrics<T>>(
632630
id: string,
633-
opts?: AggregateNearOptions<T, M>
631+
opts?: AggregateNearOptions<M>
634632
): Promise<AggregateResult<T, M>>;
635633
/**
636634
* Aggregate metrics over the objects returned by a near vector search on this collection.
@@ -645,7 +643,7 @@ export interface Aggregate<T> {
645643
*/
646644
nearText<M extends PropertiesMetrics<T>>(
647645
query: string | string[],
648-
opts?: AggregateNearOptions<T, M>
646+
opts?: AggregateNearOptions<M>
649647
): Promise<AggregateResult<T, M>>;
650648
/**
651649
* Aggregate metrics over the objects returned by a near vector search on this collection.
@@ -660,15 +658,15 @@ export interface Aggregate<T> {
660658
*/
661659
nearVector<M extends PropertiesMetrics<T>>(
662660
vector: number[],
663-
opts?: AggregateNearOptions<T, M>
661+
opts?: AggregateNearOptions<M>
664662
): Promise<AggregateResult<T, M>>;
665663
/**
666664
* Aggregate metrics over all the objects in this collection without any vector search.
667665
*
668666
* @param {AggregateOptions<T, M>} [opts] The options for the request.
669667
* @returns {Promise<AggregateResult<T, M>[]>} The aggregated metrics for the objects in the collection.
670668
*/
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>>;
672670
}
673671

674672
export interface AggregateGroupBy<T> {

0 commit comments

Comments
 (0)