1
1
import { CommandParser } from '@redis/client/dist/lib/client/parser' ;
2
- import { Command , RedisArgument , ReplyUnion } from " @redis/client/dist/lib/RESP/types" ;
3
- import { AggregateReply } from " ./AGGREGATE" ;
4
- import SEARCH , { FtSearchOptions , SearchRawReply , SearchReply , parseSearchOptions } from " ./SEARCH" ;
2
+ import { ArrayReply , Command , RedisArgument , ReplyUnion , Resp2Reply , TuplesReply , UnwrapReply } from ' @redis/client/dist/lib/RESP/types' ;
3
+ import { AggregateReply } from ' ./AGGREGATE' ;
4
+ import SEARCH , { FtSearchOptions , SearchRawReply , SearchReply , parseSearchOptions } from ' ./SEARCH' ;
5
5
6
- export type ProfileRawReply < T > = [
7
- results : T ,
8
- profile : [
9
- _ : string ,
10
- TotalProfileTime : string ,
11
- _ : string ,
12
- ParsingTime : string ,
13
- _ : string ,
14
- PipelineCreationTime : string ,
15
- _ : string ,
16
- IteratorsProfile : Array < any >
17
- ]
18
- ] ;
6
+ export type ProfileRawReply < T > = TuplesReply < [
7
+ T ,
8
+ ArrayReply < ReplyUnion >
9
+ ] > ;
10
+
11
+ export interface ProfileReply {
12
+ results : SearchReply | AggregateReply ;
13
+ profile : ReplyUnion ;
14
+ }
15
+ export interface TransformReplyType {
16
+ 2 : ( reply : UnwrapReply < Resp2Reply < ProfileRawReply < SearchRawReply > > > ) => ProfileReply ;
17
+ 3 : ( ) => ReplyUnion ;
18
+ }
19
19
20
20
type ProfileSearchRawReply = ProfileRawReply < SearchRawReply > ;
21
21
@@ -43,108 +43,13 @@ export default {
43
43
parseSearchOptions ( parser , options ) ;
44
44
} ,
45
45
transformReply : {
46
- 2 : ( reply : ProfileSearchRawReply , withoutDocuments : boolean ) : ProfileReply => {
46
+ 2 : ( reply : UnwrapReply < Resp2Reply < ProfileSearchRawReply > > ) : ProfileReply => {
47
47
return {
48
48
results : SEARCH . transformReply [ 2 ] ( reply [ 0 ] ) ,
49
- profile : transformProfile ( reply [ 1 ] )
50
- }
49
+ profile : reply [ 1 ]
50
+ } ;
51
51
} ,
52
52
3 : undefined as unknown as ( ) => ReplyUnion
53
- } ,
53
+ } as TransformReplyType ,
54
54
unstableResp3 : true
55
55
} as const satisfies Command ;
56
-
57
- export interface ProfileReply {
58
- results : SearchReply | AggregateReply ;
59
- profile : ProfileData ;
60
- }
61
-
62
- interface ChildIterator {
63
- type ?: string ,
64
- counter ?: number ,
65
- term ?: string ,
66
- size ?: number ,
67
- time ?: string ,
68
- childIterators ?: Array < ChildIterator >
69
- }
70
-
71
- interface IteratorsProfile {
72
- type ?: string ,
73
- counter ?: number ,
74
- queryType ?: string ,
75
- time ?: string ,
76
- childIterators ?: Array < ChildIterator >
77
- }
78
-
79
- interface ProfileData {
80
- totalProfileTime : string ,
81
- parsingTime : string ,
82
- pipelineCreationTime : string ,
83
- warning : string ,
84
- iteratorsProfile : IteratorsProfile
85
- }
86
-
87
- export function transformProfile ( reply : Array < any > ) : ProfileData {
88
- return {
89
- totalProfileTime : reply [ 0 ] [ 1 ] ,
90
- parsingTime : reply [ 1 ] [ 1 ] ,
91
- pipelineCreationTime : reply [ 2 ] [ 1 ] ,
92
- warning : reply [ 3 ] [ 1 ] ? reply [ 3 ] [ 1 ] : 'None' ,
93
- iteratorsProfile : transformIterators ( reply [ 4 ] [ 1 ] )
94
- } ;
95
- }
96
-
97
- function transformIterators ( IteratorsProfile : Array < any > ) : IteratorsProfile {
98
- var res : IteratorsProfile = { } ;
99
- for ( let i = 0 ; i < IteratorsProfile . length ; i += 2 ) {
100
- const value = IteratorsProfile [ i + 1 ] ;
101
- switch ( IteratorsProfile [ i ] ) {
102
- case 'Type' :
103
- res . type = value ;
104
- break ;
105
- case 'Counter' :
106
- res . counter = value ;
107
- break ;
108
- case 'Time' :
109
- res . time = value ;
110
- break ;
111
- case 'Query type' :
112
- res . queryType = value ;
113
- break ;
114
- case 'Child iterators' :
115
- res . childIterators = value . map ( transformChildIterators ) ;
116
- break ;
117
- }
118
- }
119
-
120
- return res ;
121
- }
122
-
123
- function transformChildIterators ( IteratorsProfile : Array < any > ) : ChildIterator {
124
- var res : ChildIterator = { } ;
125
- for ( let i = 1 ; i < IteratorsProfile . length ; i += 2 ) {
126
- const value = IteratorsProfile [ i + 1 ] ;
127
- switch ( IteratorsProfile [ i ] ) {
128
- case 'Type' :
129
- res . type = value ;
130
- break ;
131
- case 'Counter' :
132
- res . counter = value ;
133
- break ;
134
- case 'Time' :
135
- res . time = value ;
136
- break ;
137
- case 'Size' :
138
- res . size = value ;
139
- break ;
140
- case 'Term' :
141
- res . term = value ;
142
- break ;
143
- case 'Child iterators' :
144
- res . childIterators = value . map ( transformChildIterators ) ;
145
- break ;
146
- }
147
- }
148
-
149
- return res ;
150
- }
0 commit comments