| 1 |
import { |
| 2 |
AggregateOptions, |
| 3 |
AggregateRawReply, |
| 4 |
AggregateReply, |
| 5 |
transformArguments as transformAggregateArguments, |
| 6 |
transformReply as transformAggregateReply |
| 7 |
} from './AGGREGATE'; |
| 8 |
|
| 9 |
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './AGGREGATE'; |
| 10 |
|
| 11 |
interface AggregateWithCursorOptions extends AggregateOptions { |
| 12 |
COUNT?: number; |
| 13 |
} |
| 14 |
|
| 15 |
export function transformArguments( |
| 16 |
index: string, |
| 17 |
query: string, |
| 18 |
options?: AggregateWithCursorOptions |
| 19 |
) { |
| 20 |
const args = transformAggregateArguments(index, query, options); |
| 21 |
|
| 22 |
args.push('WITHCURSOR'); |
| 23 |
if (options?.COUNT) { |
| 24 |
args.push('COUNT', options.COUNT.toString()); |
| 25 |
} |
| 26 |
|
| 27 |
return args; |
| 28 |
} |
| 29 |
|
| 30 |
type AggregateWithCursorRawReply = [ |
| 31 |
result: AggregateRawReply, |
| 32 |
cursor: number |
| 33 |
]; |
| 34 |
|
| 35 |
interface AggregateWithCursorReply extends AggregateReply { |
| 36 |
cursor: number; |
| 37 |
} |
| 38 |
|
| 39 |
export function transformReply(reply: AggregateWithCursorRawReply): AggregateWithCursorReply { |
| 40 |
return { |
| 41 |
...transformAggregateReply(reply[0]), |
| 42 |
cursor: reply[1] |
| 43 |
}; |
| 44 |
} |