AGGREGATE.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
  2. import { Params, PropertyName, SortByProperty } from '.';
  3. export declare enum AggregateSteps {
  4. GROUPBY = "GROUPBY",
  5. SORTBY = "SORTBY",
  6. APPLY = "APPLY",
  7. LIMIT = "LIMIT",
  8. FILTER = "FILTER"
  9. }
  10. interface AggregateStep<T extends AggregateSteps> {
  11. type: T;
  12. }
  13. export declare enum AggregateGroupByReducers {
  14. COUNT = "COUNT",
  15. COUNT_DISTINCT = "COUNT_DISTINCT",
  16. COUNT_DISTINCTISH = "COUNT_DISTINCTISH",
  17. SUM = "SUM",
  18. MIN = "MIN",
  19. MAX = "MAX",
  20. AVG = "AVG",
  21. STDDEV = "STDDEV",
  22. QUANTILE = "QUANTILE",
  23. TOLIST = "TOLIST",
  24. TO_LIST = "TOLIST",
  25. FIRST_VALUE = "FIRST_VALUE",
  26. RANDOM_SAMPLE = "RANDOM_SAMPLE"
  27. }
  28. interface GroupByReducer<T extends AggregateGroupByReducers> {
  29. type: T;
  30. AS?: string;
  31. }
  32. type CountReducer = GroupByReducer<AggregateGroupByReducers.COUNT>;
  33. interface CountDistinctReducer extends GroupByReducer<AggregateGroupByReducers.COUNT_DISTINCT> {
  34. property: PropertyName;
  35. }
  36. interface CountDistinctishReducer extends GroupByReducer<AggregateGroupByReducers.COUNT_DISTINCTISH> {
  37. property: PropertyName;
  38. }
  39. interface SumReducer extends GroupByReducer<AggregateGroupByReducers.SUM> {
  40. property: PropertyName;
  41. }
  42. interface MinReducer extends GroupByReducer<AggregateGroupByReducers.MIN> {
  43. property: PropertyName;
  44. }
  45. interface MaxReducer extends GroupByReducer<AggregateGroupByReducers.MAX> {
  46. property: PropertyName;
  47. }
  48. interface AvgReducer extends GroupByReducer<AggregateGroupByReducers.AVG> {
  49. property: PropertyName;
  50. }
  51. interface StdDevReducer extends GroupByReducer<AggregateGroupByReducers.STDDEV> {
  52. property: PropertyName;
  53. }
  54. interface QuantileReducer extends GroupByReducer<AggregateGroupByReducers.QUANTILE> {
  55. property: PropertyName;
  56. quantile: number;
  57. }
  58. interface ToListReducer extends GroupByReducer<AggregateGroupByReducers.TOLIST> {
  59. property: PropertyName;
  60. }
  61. interface FirstValueReducer extends GroupByReducer<AggregateGroupByReducers.FIRST_VALUE> {
  62. property: PropertyName;
  63. BY?: PropertyName | {
  64. property: PropertyName;
  65. direction?: 'ASC' | 'DESC';
  66. };
  67. }
  68. interface RandomSampleReducer extends GroupByReducer<AggregateGroupByReducers.RANDOM_SAMPLE> {
  69. property: PropertyName;
  70. sampleSize: number;
  71. }
  72. type GroupByReducers = CountReducer | CountDistinctReducer | CountDistinctishReducer | SumReducer | MinReducer | MaxReducer | AvgReducer | StdDevReducer | QuantileReducer | ToListReducer | FirstValueReducer | RandomSampleReducer;
  73. interface GroupByStep extends AggregateStep<AggregateSteps.GROUPBY> {
  74. properties?: PropertyName | Array<PropertyName>;
  75. REDUCE: GroupByReducers | Array<GroupByReducers>;
  76. }
  77. interface SortStep extends AggregateStep<AggregateSteps.SORTBY> {
  78. BY: SortByProperty | Array<SortByProperty>;
  79. MAX?: number;
  80. }
  81. interface ApplyStep extends AggregateStep<AggregateSteps.APPLY> {
  82. expression: string;
  83. AS: string;
  84. }
  85. interface LimitStep extends AggregateStep<AggregateSteps.LIMIT> {
  86. from: number;
  87. size: number;
  88. }
  89. interface FilterStep extends AggregateStep<AggregateSteps.FILTER> {
  90. expression: string;
  91. }
  92. type LoadField = PropertyName | {
  93. identifier: PropertyName;
  94. AS?: string;
  95. };
  96. export interface AggregateOptions {
  97. VERBATIM?: true;
  98. LOAD?: LoadField | Array<LoadField>;
  99. STEPS?: Array<GroupByStep | SortStep | ApplyStep | LimitStep | FilterStep>;
  100. PARAMS?: Params;
  101. DIALECT?: number;
  102. TIMEOUT?: number;
  103. }
  104. export declare const FIRST_KEY_INDEX = 1;
  105. export declare const IS_READ_ONLY = true;
  106. export declare function transformArguments(index: string, query: string, options?: AggregateOptions): RedisCommandArguments;
  107. export declare function pushAggregatehOptions(args: RedisCommandArguments, options?: AggregateOptions): RedisCommandArguments;
  108. export type AggregateRawReply = [
  109. total: number,
  110. ...results: Array<Array<RedisCommandArgument>>
  111. ];
  112. export interface AggregateReply {
  113. total: number;
  114. results: Array<Record<string, RedisCommandArgument>>;
  115. }
  116. export declare function transformReply(rawReply: AggregateRawReply): AggregateReply;
  117. export {};