|
8 | 8 |
|
9 | 9 | class CLI extends Node |
10 | 10 | { |
| 11 | + private const array QUERY_FLAG_PARAMS = [ |
| 12 | + 'filtering' => ['filter', 'where', 'sortAsc', 'sortDesc', 'cursorAfter', 'cursorBefore'], |
| 13 | + 'pagination' => ['limit', 'offset'], |
| 14 | + 'select' => ['select'], |
| 15 | + ]; |
| 16 | + |
11 | 17 | /** |
12 | 18 | * List of functions to ignore for console preview. |
13 | 19 | */ |
@@ -230,32 +236,31 @@ private function getCliQueryConfig(array $method): array |
230 | 236 | { |
231 | 237 | $hasQueries = $this->hasArrayQueriesParameter($method); |
232 | 238 | $methodName = $method['name'] ?? ''; |
| 239 | + $parameterNames = array_map( |
| 240 | + fn (array $parameter): string => $parameter['name'] ?? '', |
| 241 | + $method['parameters']['all'] ?? [] |
| 242 | + ); |
| 243 | + $collides = fn (string $group): bool => array_intersect(self::QUERY_FLAG_PARAMS[$group], $parameterNames) !== []; |
233 | 244 | $hasOnlyLimitOffsetQueries = $hasQueries && $this->hasOnlyLimitOffsetQueries($method); |
234 | | - $hasSelectQueries = $hasQueries && in_array($methodName, ['listDocuments', 'getDocument', 'listRows', 'getRow'], true); |
| 245 | + $hasSelectQueries = $hasQueries && in_array($methodName, ['listDocuments', 'getDocument', 'listRows', 'getRow'], true) && !$collides('select'); |
235 | 246 | $hasSelectionOnlyQueries = $hasQueries && in_array($methodName, ['getDocument', 'getRow'], true); |
236 | | - $hasFilteringQueries = $hasQueries && !$hasOnlyLimitOffsetQueries && !$hasSelectionOnlyQueries; |
237 | | - $hasPaginationQueries = $hasQueries && !$hasSelectionOnlyQueries; |
| 247 | + $hasFilteringQueries = $hasQueries && !$hasOnlyLimitOffsetQueries && !$hasSelectionOnlyQueries && !$collides('filtering'); |
| 248 | + $hasPaginationQueries = $hasQueries && !$hasSelectionOnlyQueries && !$collides('pagination'); |
238 | 249 |
|
239 | 250 | $builderParams = []; |
240 | 251 | if ($hasQueries) { |
241 | 252 | $builderParams[] = 'queries'; |
242 | 253 |
|
243 | 254 | if ($hasFilteringQueries) { |
244 | | - $builderParams[] = 'filter'; |
245 | | - $builderParams[] = 'where'; |
246 | | - $builderParams[] = 'sortAsc'; |
247 | | - $builderParams[] = 'sortDesc'; |
248 | | - $builderParams[] = 'cursorAfter'; |
249 | | - $builderParams[] = 'cursorBefore'; |
| 255 | + $builderParams = array_merge($builderParams, self::QUERY_FLAG_PARAMS['filtering']); |
250 | 256 | } |
251 | 257 |
|
252 | 258 | if ($hasPaginationQueries) { |
253 | | - $builderParams[] = 'limit'; |
254 | | - $builderParams[] = 'offset'; |
| 259 | + $builderParams = array_merge($builderParams, self::QUERY_FLAG_PARAMS['pagination']); |
255 | 260 | } |
256 | 261 |
|
257 | 262 | if ($hasSelectQueries) { |
258 | | - $builderParams[] = 'select'; |
| 263 | + $builderParams = array_merge($builderParams, self::QUERY_FLAG_PARAMS['select']); |
259 | 264 | } |
260 | 265 | } |
261 | 266 |
|
|
0 commit comments