@enonic-types/core 7.12.0-B1 → 7.12.0-RC1

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.
Files changed (2) hide show
  1. package/index.d.ts +44 -18
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -283,27 +283,23 @@ export type SortDsl = FieldSortDsl | GeoDistanceSortDsl;
283
283
  //
284
284
  // START AGGREGATIONS, FILTERS
285
285
  //
286
- export interface Bucket {
287
- [subAggregationName: string]: AggregationsResult | string | number | undefined;
288
-
286
+ export type Bucket<SubAggregations extends Aggregations = Record<never, never>> = AggregationsToAggregationResults<SubAggregations> & {
289
287
  key: string;
290
288
  docCount: number;
291
- }
289
+ };
292
290
 
293
- export interface NumericBucket
294
- extends Bucket {
291
+ export type NumericBucket<SubAggregations extends Aggregations = Record<never, never>> = Bucket<SubAggregations> & {
295
292
  from?: number;
296
293
  to?: number;
297
- }
294
+ };
298
295
 
299
- export interface DateBucket
300
- extends Bucket {
296
+ export type DateBucket<SubAggregations extends Aggregations = Record<never, never>> = Bucket<SubAggregations> & {
301
297
  from?: string;
302
298
  to?: string;
303
- }
299
+ };
304
300
 
305
- export interface BucketsAggregationResult {
306
- buckets: (DateBucket | NumericBucket)[];
301
+ export interface BucketsAggregationResult<SubAggregations extends Aggregations = Record<never, never>> {
302
+ buckets: (DateBucket<SubAggregations> | NumericBucket<SubAggregations>)[];
307
303
  }
308
304
 
309
305
  export interface StatsAggregationResult {
@@ -318,7 +314,35 @@ export interface SingleValueMetricAggregationResult {
318
314
  value: number;
319
315
  }
320
316
 
321
- export type AggregationsResult = BucketsAggregationResult | StatsAggregationResult | SingleValueMetricAggregationResult;
317
+ export type AggregationsResult<SubAggregations extends Aggregations = Record<never, never>> =
318
+ | BucketsAggregationResult<SubAggregations>
319
+ | StatsAggregationResult
320
+ | SingleValueMetricAggregationResult;
321
+
322
+ export type AggregationsToAggregationResults<AggregationInput extends Aggregations = never> = {
323
+ [Key in keyof AggregationInput]: AggregationToAggregationResult<AggregationInput[Key]>;
324
+ };
325
+
326
+ export type AggregationToAggregationResult<Type extends Aggregation> = Type extends BucketsAggregationsUnion
327
+ ? BucketsAggregationResult<Type['aggregations']>
328
+ : Type extends SingleValueMetricAggregationsUnion
329
+ ? SingleValueMetricAggregationResult
330
+ : Type extends StatsAggregation
331
+ ? StatsAggregationResult
332
+ : never;
333
+
334
+ export type BucketsAggregationsUnion =
335
+ | TermsAggregation
336
+ | GeoDistanceAggregation
337
+ | NumericRangeAggregation
338
+ | DateRangeAggregation
339
+ | HistogramAggregation
340
+ | DateHistogramAggregation;
341
+
342
+ export type SingleValueMetricAggregationsUnion =
343
+ | MinAggregation
344
+ | MaxAggregation
345
+ | ValueCountAggregation;
322
346
 
323
347
  export type Aggregation =
324
348
  | TermsAggregation
@@ -332,6 +356,8 @@ export type Aggregation =
332
356
  | MaxAggregation
333
357
  | ValueCountAggregation;
334
358
 
359
+ export type Aggregations = Record<string, Aggregation>;
360
+
335
361
  export interface TermsAggregation {
336
362
  terms: {
337
363
  field: string;
@@ -339,7 +365,7 @@ export interface TermsAggregation {
339
365
  size?: number;
340
366
  minDocCount?: number;
341
367
  };
342
- aggregations?: Record<string, Aggregation>;
368
+ aggregations?: Aggregations;
343
369
  }
344
370
 
345
371
  export interface HistogramAggregation {
@@ -351,7 +377,7 @@ export interface HistogramAggregation {
351
377
  extendedBoundMax?: number;
352
378
  minDocCount?: number;
353
379
  };
354
- aggregations?: Record<string, Aggregation>;
380
+ aggregations?: Aggregations;
355
381
  }
356
382
 
357
383
  export interface DateHistogramAggregation {
@@ -361,7 +387,7 @@ export interface DateHistogramAggregation {
361
387
  minDocCount?: number;
362
388
  format: string;
363
389
  };
364
- aggregations?: Record<string, Aggregation>;
390
+ aggregations?: Aggregations;
365
391
  }
366
392
 
367
393
  export interface NumericRange {
@@ -375,7 +401,7 @@ export interface NumericRangeAggregation {
375
401
  field: string;
376
402
  ranges?: NumericRange[];
377
403
  };
378
- aggregations?: Record<string, Aggregation>;
404
+ aggregations?: Aggregations;
379
405
  }
380
406
 
381
407
  export interface DateRange {
@@ -390,7 +416,7 @@ export interface DateRangeAggregation {
390
416
  format: string;
391
417
  ranges: DateRange[];
392
418
  };
393
- aggregations?: Record<string, Aggregation>;
419
+ aggregations?: Aggregations;
394
420
  }
395
421
 
396
422
  export interface StatsAggregation {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enonic-types/core",
3
- "version": "7.12.0-B1",
3
+ "version": "7.12.0-RC1",
4
4
  "description": "Shared type definition for core libraries.",
5
5
  "types": "index.d.ts",
6
6
  "files": [