Skip to content

Commit aae4d2b

Browse files
committed
Inline some cursor docs
1 parent 2fbe689 commit aae4d2b

File tree

2 files changed

+56
-86
lines changed

2 files changed

+56
-86
lines changed

docs/Drivers/JS/Reference/Cursor.md

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -14,83 +14,6 @@ assert.equal(value, 1);
1414
// remaining result list: [2, 3, 4, 5]
1515
```
1616

17-
## cursor.count
18-
19-
`cursor.count: number`
20-
21-
The total number of documents in the query result. This is only available if the
22-
`count` option was used.
23-
24-
## cursor.all
25-
26-
`async cursor.all(): Array<any>`
27-
28-
Exhausts the cursor, then returns an array containing all values in the cursor's
29-
remaining result list.
30-
31-
**Examples**
32-
33-
```js
34-
const cursor = await db.query(aql`FOR x IN 1..5 RETURN x`);
35-
const result = await cursor.all();
36-
// result is an array containing the entire query result
37-
assert.deepEqual(result, [1, 2, 3, 4, 5]);
38-
assert.equal(cursor.hasNext, false);
39-
```
40-
41-
## cursor.next
42-
43-
`async cursor.next(): any | undefined`
44-
45-
Advances the cursor and returns the next value in the cursor's remaining result
46-
list. If the cursor has already been exhausted, returns `undefined` instead.
47-
48-
**Examples**
49-
50-
```js
51-
// query result list: [1, 2, 3, 4, 5]
52-
const val = await cursor.next();
53-
assert.equal(val, 1);
54-
// remaining result list: [2, 3, 4, 5]
55-
56-
const val2 = await cursor.next();
57-
assert.equal(val2, 2);
58-
// remaining result list: [3, 4, 5]
59-
```
60-
61-
## cursor.hasNext
62-
63-
`cursor.hasNext: boolean`
64-
65-
Returns `true` if the cursor has more values or `false` if the cursor has been
66-
exhausted.
67-
68-
**Examples**
69-
70-
```js
71-
await cursor.all(); // exhausts the cursor
72-
assert.equal(cursor.hasNext, false);
73-
```
74-
75-
## cursor.nextBatch
76-
77-
`async cursor.nextBatch(): Array<any> | undefined`
78-
79-
Advances the cursor and returns all remaining values in the cursor's current
80-
batch. If the current batch has already been exhausted, fetches the next batch
81-
from the server and returns it. If no more batches are available, returns
82-
`undefined` instead.
83-
84-
**Examples**
85-
86-
```js
87-
const cursor = await db.query(aql`FOR i IN 1..10 RETURN i`, { batchSize: 5 });
88-
await cursor.nextBatch(); // [1, 2, 3, 4, 5]
89-
await cursor.next(); // 6
90-
await cursor.nextBatch(); // [7, 8, 9, 10]
91-
cursor.hasNext; // false
92-
```
93-
9417
## cursor.each
9518

9619
`async cursor.each(fn): any`

src/cursor.ts

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,36 @@ export class ArrayCursor<T = any> {
8080
}
8181

8282
/**
83-
* TODO
83+
* The total number of documents in the query result. Only available if the
84+
* `count` option was used.
8485
*/
85-
get count() {
86+
get count(): number | undefined {
8687
return this._count;
8788
}
8889

8990
/**
90-
* TODO
91+
* Whether the cursor has any remaining batches that haven't yet been
92+
* fetched. If set to `false`, all batches have been fetched and no
93+
* additional requests to the server will be made when consuming any
94+
* remaining items from this cursor.
9195
*/
9296
get hasMore(): boolean {
9397
return this._hasMore;
9498
}
9599

96100
/**
97-
* TODO
101+
* Whether the cursor has more values. If set to `false`, the cursor has
102+
* already been depleted and contains no more items.
98103
*/
99104
get hasNext(): boolean {
100105
return this.hasMore || Boolean(this._result.length);
101106
}
102107

103108
/**
104-
* Enables use with `for await` to exhaust the cursor by asynchronously
109+
* Enables use with `for await` to deplete the cursor by asynchronously
105110
* yielding every value in the cursor's remaining result set.
106111
*
107-
* **Note**: If the result set spans multiple batches, any unfetched batches
112+
* **Note**: If the result set spans multiple batches, any remaining batches
108113
* will only be fetched on demand. Depending on the cursor's TTL and the
109114
* processing speed, this may result in the server discarding the cursor
110115
* before it is fully depleted.
@@ -129,7 +134,14 @@ export class ArrayCursor<T = any> {
129134
}
130135

131136
/**
132-
* TODO
137+
* Depletes the cursor, then returns an array containing all values in the
138+
* cursor's remaining result list.
139+
*
140+
* @example
141+
* ```js
142+
* const cursor = await db.query(aql`FOR x IN 1..5 RETURN x`);
143+
* const result = await cursor.all(); // [1, 2, 3, 4, 5]
144+
* console.log(cursor.hasNext); // false
133145
*/
134146
async all(): Promise<T[]> {
135147
await this._drain();
@@ -139,7 +151,22 @@ export class ArrayCursor<T = any> {
139151
}
140152

141153
/**
142-
* TODO
154+
* Advances the cursor and returns the next value in the cursor's remaining
155+
* result list, or `undefined` if the cursor has been depleted.
156+
*
157+
* **Note**: If the result set spans multiple batches, any remaining batches
158+
* will only be fetched on demand. Depending on the cursor's TTL and the
159+
* processing speed, this may result in the server discarding the cursor
160+
* before it is fully depleted.
161+
*
162+
* @example
163+
* ```js
164+
* const cursor = await db.query(aql`FOR x IN 1..3 RETURN x`);
165+
* const one = await cursor.next(); // 1
166+
* const two = await cursor.next(); // 2
167+
* const three = await cursor.next(); // 3
168+
* const empty = await cursor.next(); // undefined
169+
* ```
143170
*/
144171
async next(): Promise<T | undefined> {
145172
while (!this._result.length && this.hasMore) {
@@ -152,7 +179,27 @@ export class ArrayCursor<T = any> {
152179
}
153180

154181
/**
155-
* TODO
182+
* Advances the cursor and returns all remaining values in the cursor's
183+
* current batch. If the current batch has already been exhausted, fetches
184+
* the next batch from the server and returns it, or `undefined` if the
185+
* cursor has been depleted.
186+
*
187+
* **Note**: If the result set spans multiple batches, any remaining batches
188+
* will only be fetched on demand. Depending on the cursor's TTL and the
189+
* processing speed, this may result in the server discarding the cursor
190+
* before it is fully depleted.
191+
*
192+
* @example
193+
* ```js
194+
* const cursor = await db.query(
195+
* aql`FOR i IN 1..10 RETURN i`,
196+
* { batchSize: 5 }
197+
* );
198+
* const firstBatch = await cursor.nextBatch(); // [1, 2, 3, 4, 5]
199+
* await cursor.next(); // 6
200+
* const lastBatch = await cursor.nextBatch(); // [7, 8, 9, 10]
201+
* console.log(cursor.hasNext); // false
202+
* ```
156203
*/
157204
async nextBatch(): Promise<any[] | undefined> {
158205
while (!this._result.length && this.hasMore) {

0 commit comments

Comments
 (0)