Skip to content

Commit d930391

Browse files
committed
Revert "Make typing changes in response to review"
This reverts commit 9c1ea29.
1 parent 866f99e commit d930391

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

src/collections/aggregate/index.ts

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

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

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>;
2220
};
2321

2422
export type GroupByAggregate<T> = {
25-
property: PropertyOf<T>;
23+
property: keyof T & string;
2624
limit?: number;
2725
};
2826

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

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

33-
export type AggregateNearOptions<M> = AggregateBaseOptions<M> & {
31+
export type AggregateNearOptions<T, M> = AggregateBaseOptions<T, M> & {
3432
certainty?: number;
3533
distance?: number;
3634
objectLimit?: number;
3735
targetVector?: string;
3836
};
3937

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>;
4240
};
4341

4442
export type AggregateBoolean = {
@@ -128,11 +126,11 @@ export type AggregateMetrics<M> = {
128126
[K in keyof M]: M[K] extends true ? number : never;
129127
};
130128

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

133131
export const metrics = <T>() => {
134132
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),
136134
};
137135
};
138136

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

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

154152
constructor(property: P) {
@@ -421,7 +419,11 @@ class AggregateManager<T> implements Aggregate<T> {
421419
return new Aggregator(this.connection);
422420
}
423421

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

490492
async nearImage<M extends PropertiesMetrics<T>>(
491493
image: string | Buffer,
492-
opts?: AggregateNearOptions<M>
494+
opts?: AggregateNearOptions<T, M>
493495
): Promise<AggregateResult<T, M>> {
494496
const builder = this.base(opts?.returnMetrics, opts?.filters).withNearImage({
495497
image: await toBase64FromMedia(image),
@@ -505,7 +507,7 @@ class AggregateManager<T> implements Aggregate<T> {
505507

506508
nearObject<M extends PropertiesMetrics<T>>(
507509
id: string,
508-
opts?: AggregateNearOptions<M>
510+
opts?: AggregateNearOptions<T, M>
509511
): Promise<AggregateResult<T, M>> {
510512
const builder = this.base(opts?.returnMetrics, opts?.filters).withNearObject({
511513
id: id,
@@ -521,7 +523,7 @@ class AggregateManager<T> implements Aggregate<T> {
521523

522524
nearText<M extends PropertiesMetrics<T>>(
523525
query: string | string[],
524-
opts?: AggregateNearOptions<M>
526+
opts?: AggregateNearOptions<T, M>
525527
): Promise<AggregateResult<T, M>> {
526528
const builder = this.base(opts?.returnMetrics, opts?.filters).withNearText({
527529
concepts: Array.isArray(query) ? query : [query],
@@ -537,7 +539,7 @@ class AggregateManager<T> implements Aggregate<T> {
537539

538540
nearVector<M extends PropertiesMetrics<T>>(
539541
vector: number[],
540-
opts?: AggregateNearOptions<M>
542+
opts?: AggregateNearOptions<T, M>
541543
): Promise<AggregateResult<T, M>> {
542544
const builder = this.base(opts?.returnMetrics, opts?.filters).withNearVector({
543545
vector: vector,
@@ -551,7 +553,7 @@ class AggregateManager<T> implements Aggregate<T> {
551553
return this.do(builder);
552554
}
553555

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>> {
555557
const builder = this.base(opts?.returnMetrics, opts?.filters);
556558
return this.do(builder);
557559
}
@@ -613,7 +615,7 @@ export interface Aggregate<T> {
613615
*/
614616
nearImage<M extends PropertiesMetrics<T>>(
615617
image: string | Buffer,
616-
opts?: AggregateNearOptions<M>
618+
opts?: AggregateNearOptions<T, M>
617619
): Promise<AggregateResult<T, M>>;
618620
/**
619621
* Aggregate metrics over the objects returned by a near object search on this collection.
@@ -628,7 +630,7 @@ export interface Aggregate<T> {
628630
*/
629631
nearObject<M extends PropertiesMetrics<T>>(
630632
id: string,
631-
opts?: AggregateNearOptions<M>
633+
opts?: AggregateNearOptions<T, M>
632634
): Promise<AggregateResult<T, M>>;
633635
/**
634636
* Aggregate metrics over the objects returned by a near vector search on this collection.
@@ -643,7 +645,7 @@ export interface Aggregate<T> {
643645
*/
644646
nearText<M extends PropertiesMetrics<T>>(
645647
query: string | string[],
646-
opts?: AggregateNearOptions<M>
648+
opts?: AggregateNearOptions<T, M>
647649
): Promise<AggregateResult<T, M>>;
648650
/**
649651
* Aggregate metrics over the objects returned by a near vector search on this collection.
@@ -658,15 +660,15 @@ export interface Aggregate<T> {
658660
*/
659661
nearVector<M extends PropertiesMetrics<T>>(
660662
vector: number[],
661-
opts?: AggregateNearOptions<M>
663+
opts?: AggregateNearOptions<T, M>
662664
): Promise<AggregateResult<T, M>>;
663665
/**
664666
* Aggregate metrics over all the objects in this collection without any vector search.
665667
*
666668
* @param {AggregateOptions<T, M>} [opts] The options for the request.
667669
* @returns {Promise<AggregateResult<T, M>[]>} The aggregated metrics for the objects in the collection.
668670
*/
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>>;
670672
}
671673

672674
export interface AggregateGroupBy<T> {

0 commit comments

Comments
 (0)