@ibm-cloud/cloudant 0.12.4 → 0.12.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +648 -74
  2. package/cloudant/features/changesFollower.js +3 -2
  3. package/cloudant/features/changesFollower.js.map +1 -1
  4. package/cloudant/features/pagination/allDocsBasePageIterator.d.ts +29 -0
  5. package/cloudant/features/pagination/allDocsBasePageIterator.js +47 -0
  6. package/cloudant/features/pagination/allDocsBasePageIterator.js.map +1 -0
  7. package/cloudant/features/pagination/allDocsPageIterator.d.ts +21 -0
  8. package/cloudant/features/pagination/allDocsPageIterator.js +30 -0
  9. package/cloudant/features/pagination/allDocsPageIterator.js.map +1 -0
  10. package/cloudant/features/pagination/allDocsPartitionPageIterator.d.ts +21 -0
  11. package/cloudant/features/pagination/allDocsPartitionPageIterator.js +30 -0
  12. package/cloudant/features/pagination/allDocsPartitionPageIterator.js.map +1 -0
  13. package/cloudant/features/pagination/basePageIterator.d.ts +39 -0
  14. package/cloudant/features/pagination/basePageIterator.js +84 -0
  15. package/cloudant/features/pagination/basePageIterator.js.map +1 -0
  16. package/cloudant/features/pagination/bookmarkPageIterator.d.ts +25 -0
  17. package/cloudant/features/pagination/bookmarkPageIterator.js +37 -0
  18. package/cloudant/features/pagination/bookmarkPageIterator.js.map +1 -0
  19. package/cloudant/features/pagination/designDocsPageIterator.d.ts +21 -0
  20. package/cloudant/features/pagination/designDocsPageIterator.js +30 -0
  21. package/cloudant/features/pagination/designDocsPageIterator.js.map +1 -0
  22. package/cloudant/features/pagination/findBasePageIterator.d.ts +23 -0
  23. package/cloudant/features/pagination/findBasePageIterator.js +36 -0
  24. package/cloudant/features/pagination/findBasePageIterator.js.map +1 -0
  25. package/cloudant/features/pagination/findPageIterator.d.ts +21 -0
  26. package/cloudant/features/pagination/findPageIterator.js +30 -0
  27. package/cloudant/features/pagination/findPageIterator.js.map +1 -0
  28. package/cloudant/features/pagination/findPartitionPageIterator.d.ts +21 -0
  29. package/cloudant/features/pagination/findPartitionPageIterator.js +30 -0
  30. package/cloudant/features/pagination/findPartitionPageIterator.js.map +1 -0
  31. package/cloudant/features/pagination/iteratorPager.d.ts +32 -0
  32. package/cloudant/features/pagination/iteratorPager.js +58 -0
  33. package/cloudant/features/pagination/iteratorPager.js.map +1 -0
  34. package/cloudant/features/pagination/keyPageIterator.d.ts +33 -0
  35. package/cloudant/features/pagination/keyPageIterator.js +75 -0
  36. package/cloudant/features/pagination/keyPageIterator.js.map +1 -0
  37. package/cloudant/features/{changesResultItemStream.d.ts → pagination/pageIterator.d.ts} +4 -7
  38. package/cloudant/features/pagination/pageIterator.js +3 -0
  39. package/cloudant/features/pagination/pageIterator.js.map +1 -0
  40. package/cloudant/features/pagination/pager.d.ts +28 -0
  41. package/cloudant/features/pagination/pager.js +18 -0
  42. package/cloudant/features/pagination/pager.js.map +1 -0
  43. package/cloudant/features/pagination/pagination.d.ts +185 -0
  44. package/cloudant/features/pagination/pagination.js +148 -0
  45. package/cloudant/features/pagination/pagination.js.map +1 -0
  46. package/cloudant/features/pagination/searchBasePageIterator.d.ts +22 -0
  47. package/cloudant/features/pagination/searchBasePageIterator.js +30 -0
  48. package/cloudant/features/pagination/searchBasePageIterator.js.map +1 -0
  49. package/cloudant/features/pagination/searchPageIterator.d.ts +22 -0
  50. package/cloudant/features/pagination/searchPageIterator.js +40 -0
  51. package/cloudant/features/pagination/searchPageIterator.js.map +1 -0
  52. package/cloudant/features/pagination/searchPartitionPageIterator.d.ts +21 -0
  53. package/cloudant/features/pagination/searchPartitionPageIterator.js +30 -0
  54. package/cloudant/features/pagination/searchPartitionPageIterator.js.map +1 -0
  55. package/cloudant/features/pagination/viewBasePageIterator.d.ts +25 -0
  56. package/cloudant/features/pagination/viewBasePageIterator.js +57 -0
  57. package/cloudant/features/pagination/viewBasePageIterator.js.map +1 -0
  58. package/cloudant/features/pagination/viewPageIterator.d.ts +21 -0
  59. package/cloudant/features/pagination/viewPageIterator.js +30 -0
  60. package/cloudant/features/pagination/viewPageIterator.js.map +1 -0
  61. package/cloudant/features/pagination/viewPartitionPageIterator.d.ts +21 -0
  62. package/cloudant/features/pagination/viewPartitionPageIterator.js +30 -0
  63. package/cloudant/features/pagination/viewPartitionPageIterator.js.map +1 -0
  64. package/cloudant/features/stream.d.ts +4 -3
  65. package/cloudant/features/stream.js +6 -3
  66. package/cloudant/features/stream.js.map +1 -1
  67. package/index.d.ts +3 -1
  68. package/index.js +5 -2
  69. package/index.js.map +1 -1
  70. package/package.json +15 -15
  71. package/cloudant/features/changesResultItemStream.js +0 -40
  72. package/cloudant/features/changesResultItemStream.js.map +0 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  [![Release](https://img.shields.io/github/v/release/IBM/cloudant-node-sdk?include_prereleases&sort=semver)](https://github.com/IBM/cloudant-node-sdk/releases/latest)
3
3
  [![Docs](https://img.shields.io/static/v1?label=TypeDoc&message=latest&color=blue)](https://ibm.github.io/cloudant-node-sdk/)
4
4
 
5
- # IBM Cloudant Node.js SDK Version 0.12.4
5
+ # IBM Cloudant Node.js SDK Version 0.12.6
6
6
 
7
7
  IBM Cloudant Node.js SDK is a client library that interacts with the
8
8
  [IBM Cloudant APIs](https://cloud.ibm.com/apidocs/cloudant?code=node).
@@ -29,6 +29,7 @@ to avoid surprises.
29
29
  - [IAM API key authentication](#iam-api-key-authentication)
30
30
  - [IAM Trusted profile (container) authentication](#iam-trusted-profile-container-authentication)
31
31
  - [IAM Trusted profile (VPC) authentication](#iam-trusted-profile-vpc-authentication)
32
+ - [IAM Trusted profile (assume identity) authentication](#iam-trusted-profile-assume-identity-authentication)
32
33
  - [Session cookie authentication](#session-cookie-authentication)
33
34
  + [Authentication with external configuration](#authentication-with-external-configuration)
34
35
  + [Programmatic authentication](#programmatic-authentication)
@@ -46,13 +47,13 @@ to avoid surprises.
46
47
  * [Browser usage](#browser-usage)
47
48
  + [Polyfills](#polyfills)
48
49
  + [CORS](#cors)
49
- * [Changes feed follower (beta)](#changes-feed-follower-beta)
50
+ * [Changes feed follower](#changes-feed-follower)
50
51
  + [Introduction](#introduction)
51
52
  + [Modes of operation](#modes-of-operation)
52
53
  + [Configuring the changes follower](#configuring-the-changes-follower)
53
54
  + [Error suppression](#error-suppression)
54
55
  + [Follower operation](#follower-operation)
55
- + [Checkpointing](#checkpointing)
56
+ + [Checkpoints](#checkpoints)
56
57
  + [Code examples](#code-examples-1)
57
58
  - [Initializing a changes follower](#initializing-a-changes-follower)
58
59
  - [Starting the changes follower](#starting-the-changes-follower)
@@ -62,6 +63,23 @@ to avoid surprises.
62
63
  * [Process continuous changes](#process-continuous-changes)
63
64
  * [Process one-off changes](#process-one-off-changes)
64
65
  - [Stopping the changes follower](#stopping-the-changes-follower)
66
+ * [Pagination (beta)](#pagination-beta)
67
+ + [Introduction](#introduction-1)
68
+ + [Limitations](#limitations)
69
+ + [Capacity considerations](#capacity-considerations)
70
+ + [Available operations](#available-operations)
71
+ + [Creating a pagination](#creating-a-pagination)
72
+ - [Initialize the service](#initialize-the-service)
73
+ - [Set the options](#set-the-options)
74
+ - [Create the pagination](#create-the-pagination)
75
+ + [Using pagination](#using-pagination)
76
+ - [Stream pages](#stream-pages)
77
+ - [Stream rows](#stream-rows)
78
+ - [Iterate pages](#iterate-pages)
79
+ - [Iterate rows](#iterate-rows)
80
+ - [Pager](#pager)
81
+ * [Get each page from a pager](#get-each-page-from-a-pager)
82
+ * [Get all results from a pager](#get-all-results-from-a-pager)
65
83
  - [Questions](#questions)
66
84
  - [Issues](#issues)
67
85
  - [Versioning and LTS support](#versioning-and-lts-support)
@@ -96,7 +114,8 @@ project:
96
114
  - Handles the authentication.
97
115
  - Familiar user experience with IBM Cloud SDKs.
98
116
  - Flexibility to use either built-in models or byte-based requests and responses for documents.
99
- - Built-in [Changes feed follower](#changes-feed-follower-beta) (beta)
117
+ - Built-in [Changes feed follower](#changes-feed-follower)
118
+ - Built-in [Pagination](#pagination-beta) (beta)
100
119
  - `Promise` based design with asynchronous HTTP requests.
101
120
  - Use either as native JavaScript or take advantage of TypeScript models.
102
121
  - Transparently compresses request and response bodies.
@@ -137,47 +156,41 @@ Examples for other configuration methods are available by following the provided
137
156
 
138
157
 
139
158
  This library requires credentials to authenticate with IBM Cloudant. These credentials may be:
140
- * IBM Cloud IAM credentials (can be used with authentication types `CONTAINER`, `VPC` and `IAM`)
159
+ * IBM Cloud IAM credentials (with authentication types `CONTAINER`, `VPC`, `IAMASSUME` and `IAM`)
141
160
  * [IBM Cloud account](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-managing-access-for-cloudant#introduction-iam-ai) user, service ID or trusted profile credentials
142
- that have been granted access to the IBM Cloud Cloudant resource instance.
161
+ that have access granted to the IBM Cloud Cloudant resource instance.
143
162
  * [IBM Cloudant service credentials](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-locating-your-service-credentials) generated by the IBM Cloud Cloudant resource instance.
144
- * Username and password credentials (can be used with authentication types `COUCHDB_SESSION` and `BASIC`)
163
+ * Username and password credentials (with authentication types `COUCHDB_SESSION` and `BASIC`)
145
164
  * [IBM Cloudant service credentials](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-locating-your-service-credentials) generated for an IBM Cloud Cloudant resource instance not configured as `IAM only`.
146
- * IBM Cloudant [legacy credentials](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-work-with-your-account#basic-authentication) (i.e. username and password) for instances not in IBM Cloud.
165
+ * IBM Cloudant [legacy credentials](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-work-with-your-account#basic-authentication) (username and password) for instances not in IBM Cloud.
147
166
  * IBM Cloudant [legacy API keys](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-work-with-your-account#api-keys).
148
167
 
149
- For other compatible APIs that are not Cloudant accounts (e.g. Apache CouchDB) non-IAM based authentication types
150
- must be used.
151
-
152
- This table summarizes the available authentication types.
153
- The authentication types are listed in order of recommendation, preferably use the authentication type
154
- from the first row in the table that is compatible with your environment.
155
-
156
168
  | Authentication type | Recommended for | `AUTH_TYPE` | Description |
157
169
  | --- | --- | --- | --- |
158
- | IAM Trusted Profiles compute resource ([container](https://github.com/IBM/node-sdk-core/blob/main/Authentication.md#container-authentication)) | Cloudant<BR>(SDK running in IBM Cloud IKS) | `CONTAINER` | Obtains a compute resource (CR) token from the container.<BR>Exchanges the CR token for an IAM `access_token`.<BR>Adds an `Authorization: Bearer <access_token>` header to each HTTP request.<BR>Automatically renews the access token when needed. |
159
- | IAM Trusted Profiles compute resource ([VPC](https://github.com/IBM/node-sdk-core/blob/main/Authentication.md#vpc-instance-authentication)) | Cloudant<BR>(SDK running in IBM Cloud VPC) | `VPC` | Obtains an identity token from the VPC instance metadata.<BR>Exchanges the identity token for an IAM `access_token`.<BR>Adds an `Authorization: Bearer <access_token>` header to each HTTP request.<BR>Automatically renews the access token when needed. |
160
- | [IAM API key](https://github.com/IBM/node-sdk-core/blob/main/Authentication.md#identity-and-access-management-iam-authentication) | Cloudant | `IAM` | Exchanges an IAM API key for an IAM `access_token`.<BR>Adds an `Authorization: Bearer <access_token>` header to each HTTP request.<BR>Automatically renews the access token when needed. |
170
+ | IAM Trusted Profiles (compute resource [container](https://github.com/IBM/node-sdk-core/blob/main/Authentication.md#container-authentication)) | Cloudant<BR>(SDK running in IBM Cloud IKS) | `CONTAINER` | Obtains a compute resource (CR) token from the container.<BR>Exchanges the CR token for an IAM `access_token`.<BR>Adds an `Authorization: Bearer <access_token>` header to each HTTP request.<BR>Automatically renews the access token when needed. |
171
+ | IAM Trusted Profiles (compute resource [VPC](https://github.com/IBM/node-sdk-core/blob/main/Authentication.md#vpc-instance-authentication)) | Cloudant<BR>(SDK running in IBM Cloud VPC) | `VPC` | Obtains an identity token from the VPC instance metadata.<BR>Exchanges the identity token for an IAM `access_token`.<BR>Adds an `Authorization: Bearer <access_token>` header to each HTTP request.<BR>Automatically renews the access token when needed. |
172
+ | IAM Trusted Profiles ([assume identity](https://github.com/IBM/node-sdk-core/blob/main/Authentication.md#identity-and-access-management-iam-authentication-grant-type-assume)) | Cloudant | `IAMASSUME` | Exchanges an IAM API key for an IAM `access_token` (same as `IAM` auth type).<BR>Uses that initial token to obtain a second `access_token` from IAM with the assumed identity information.<BR>Adds an `Authorization: Bearer <access_token>` header to each HTTP request.<BR>Automatically renews the access token when needed. |
173
+ | [IAM API key](https://github.com/IBM/node-sdk-core/blob/main/Authentication.md#identity-and-access-management-iam-authentication-grant-type-apikey) | Cloudant | `IAM` | Exchanges an IAM API key for an IAM `access_token`.<BR>Adds an `Authorization: Bearer <access_token>` header to each HTTP request.<BR>Automatically renews the access token when needed. |
161
174
  | [Session cookie](#session-cookie-authentication) | [Cloudant](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-work-with-your-account#cookie-authentication)<BR>(legacy credentials & instances without IAM)<BR><BR>[Apache CouchDB](https://docs.couchdb.org/en/stable/api/server/authn.html#cookie-authentication) | `COUCHDB_SESSION` | Exchanges credentials with `/_session` endpoint to retrieve a cookie.<BR>Adds `Cookie` header and content to each HTTP request.<BR>Automatically renews session when needed. |
162
175
  | [Bearer token](https://github.com/IBM/node-sdk-core/blob/main/Authentication.md#bearer-token-authentication) | [Apache CouchDB](https://docs.couchdb.org/en/stable/api/server/authn.html#jwt-authentication)<BR>(using JWT authentication) | `BEARERTOKEN` | Adds an `Authorization: Bearer <token>` to each HTTP request.<BR>No token management or renewal.<BR>Also compatible with IAM access tokens managed independently of the SDK. |
163
176
  | [Basic](https://github.com/IBM/node-sdk-core/blob/main/Authentication.md#basic-authentication) | [Apache CouchDB](https://docs.couchdb.org/en/stable/api/server/authn.html#basic-authentication)<BR>(if cookies are not enabled) | `BASIC` | Adds an `Authorization: Basic <encoded username and password>` header to each HTTP request. |
164
177
  | [None](https://github.com/IBM/node-sdk-core/blob/main/Authentication.md#no-auth-authentication) | - | `NOAUTH` | Note that this authentication type only works for operations against a database allowing access for unauthenticated users. |
165
178
 
166
- The default authentication type for the SDK is `CONTAINER` unless `APIKEY` configuration is supplied, which changes the default authentication type to `IAM`.
179
+ The default authentication type for the SDK is `CONTAINER` unless supplying `APIKEY` configuration, which changes the default authentication type to `IAM`.
167
180
 
168
181
  #### Authentication with environment variables
169
182
 
170
- The default service name is `CLOUDANT` so `CLOUDANT_` prefixed names are used in these examples.
183
+ The default service name is `CLOUDANT` so these examples use `CLOUDANT_` prefixed names.
171
184
 
172
- Any custom service name prefix can be used as long as the matching name is used to instantiate the SDK client
173
- and the same prefix is used for all configuration options.
185
+ Any custom service name prefix is valid, provided it matches the name used to instantiate the SDK client
186
+ and applied to all configuration options.
174
187
 
175
188
  ##### IAM API key authentication
176
189
 
177
190
  For Cloudant *IAM API key authentication*, set the following environmental variables by
178
191
  replacing the `<url>` and `<apikey>` with your proper
179
192
  [service credentials](https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-locating-your-service-credentials). There is no need to set
180
- `CLOUDANT_AUTH_TYPE` to `IAM` because it is the default when an `APIKEY` is set.
193
+ `CLOUDANT_AUTH_TYPE` to `IAM` because it is the default when supplying an `APIKEY`.
181
194
 
182
195
  ```bash
183
196
  CLOUDANT_URL=<url>
@@ -195,7 +208,8 @@ CLOUDANT_URL=<url>
195
208
  CLOUDANT_IAM_PROFILE_ID=<id>
196
209
  ```
197
210
 
198
- Alternatively a profile name may be used instead of an ID by replacing `CLOUDANT_IAM_PROFILE_ID` with `CLOUDANT_IAM_PROFILE_NAME`.
211
+ Alternatives to `CLOUDANT_IAM_PROFILE_ID`:
212
+ * `CLOUDANT_IAM_PROFILE_NAME`
199
213
 
200
214
  ##### IAM Trusted profile (VPC) authentication
201
215
 
@@ -208,7 +222,24 @@ CLOUDANT_URL=<url>
208
222
  CLOUDANT_IAM_PROFILE_ID=<id>
209
223
  ```
210
224
 
211
- Alternatively a profile CRN may be used instead of an ID by replacing `CLOUDANT_IAM_PROFILE_ID` with `CLOUDANT_IAM_PROFILE_CRN`.
225
+ Alternatives to `CLOUDANT_IAM_PROFILE_ID`:
226
+ * `CLOUDANT_IAM_PROFILE_CRN`
227
+ * No profile information (uses the default trusted profile linked to the compute resource)
228
+
229
+ ##### IAM Trusted profile (assume identity) authentication
230
+
231
+ For Cloudant *IAM Trusted profile assume authentication*, set the following environmental variables by
232
+ replacing the `<url>` and `<id>` with your values.
233
+
234
+ ```bash
235
+ CLOUDANT_AUTH_TYPE=IAMASSUME
236
+ CLOUDANT_URL=<url>
237
+ CLOUDANT_IAM_PROFILE_ID=<id>
238
+ ```
239
+
240
+ Alternatives to `CLOUDANT_IAM_PROFILE_ID`:
241
+ * `CLOUDANT_IAM_PROFILE_CRN`
242
+ * `CLOUDANT_IAM_PROFILE_NAME` *and* `CLOUDANT_IAM_ACCOUNT_ID` (ID of the account that contains the named trusted profile)
212
243
 
213
244
  ##### Session cookie authentication
214
245
 
@@ -225,11 +256,10 @@ CLOUDANT_PASSWORD=<password>
225
256
 
226
257
  #### Authentication with external configuration
227
258
 
228
- To use an external configuration file, the
259
+ For more information about using an external configuration file, see the related documentation in
229
260
  [Cloudant API docs](https://cloud.ibm.com/apidocs/cloudant?code=node#authentication-with-external-configuration),
230
261
  or the
231
- [general SDK usage information](https://github.com/IBM/ibm-cloud-sdk-common#using-external-configuration)
232
- will guide you.
262
+ [general SDK usage information](https://github.com/IBM/ibm-cloud-sdk-common#using-external-configuration).
233
263
 
234
264
  #### Programmatic authentication
235
265
 
@@ -281,6 +311,7 @@ Once the environment variables are set, you can try out the code examples.
281
311
  ```ts
282
312
  import { CloudantV1 } from '@ibm-cloud/cloudant';
283
313
  ```
314
+
284
315
  ```ts
285
316
  interface OrderDocument extends CloudantV1.Document {
286
317
  name?: string;
@@ -352,6 +383,7 @@ createDb.then(() => {
352
383
  });
353
384
  });
354
385
  ```
386
+
355
387
  </details>
356
388
 
357
389
  <details>
@@ -360,6 +392,7 @@ createDb.then(() => {
360
392
  ```js
361
393
  import { CloudantV1 } from '@ibm-cloud/cloudant';
362
394
  ```
395
+
363
396
  ```js
364
397
  const createDbAndDoc = async () => {
365
398
  // 1. Create a client with `CLOUDANT` default service name ====================
@@ -427,6 +460,7 @@ if (require.main === module) {
427
460
  createDbAndDoc();
428
461
  }
429
462
  ```
463
+
430
464
  </details>
431
465
 
432
466
  When you run the code, you see a result similar to the following output.
@@ -459,6 +493,7 @@ database or 'example' document was not found."
459
493
  ```ts
460
494
  import { CloudantV1 } from '@ibm-cloud/cloudant';
461
495
  ```
496
+
462
497
  ```ts
463
498
  // 1. Create a client with `CLOUDANT` default service name =====================
464
499
  const client = CloudantV1.newInstance({});
@@ -499,6 +534,7 @@ client.getDocument(getDocParams).then((documentExample) => {
499
534
  );
500
535
  });
501
536
  ```
537
+
502
538
  </details>
503
539
 
504
540
  <details>
@@ -507,6 +543,7 @@ client.getDocument(getDocParams).then((documentExample) => {
507
543
  ```js
508
544
  import { CloudantV1 } from '@ibm-cloud/cloudant';
509
545
  ```
546
+
510
547
  ```js
511
548
  const getInfoFromExistingDatabase = async () => {
512
549
  // 1. Create a client with `CLOUDANT` default service name ===================
@@ -583,6 +620,7 @@ database or 'example' document was not found."
583
620
  ```ts
584
621
  import { CloudantV1 } from '@ibm-cloud/cloudant';
585
622
  ```
623
+
586
624
  ```ts
587
625
  interface OrderDocument extends CloudantV1.Document {
588
626
  address?: string;
@@ -669,6 +707,7 @@ client
669
707
  }
670
708
  });
671
709
  ```
710
+
672
711
  </details>
673
712
 
674
713
  <details>
@@ -677,6 +716,7 @@ client
677
716
  ```js
678
717
  import { CloudantV1 } from '@ibm-cloud/cloudant';
679
718
  ```
719
+
680
720
  ```js
681
721
  const updateDoc = async () => {
682
722
  // 1. Create a client with `CLOUDANT` default service name ====================
@@ -766,6 +806,7 @@ if (require.main === module) {
766
806
  updateDoc();
767
807
  }
768
808
  ```
809
+
769
810
  </details>
770
811
 
771
812
  </details>
@@ -798,6 +839,7 @@ database or 'example' document was not found."
798
839
  ```ts
799
840
  import { CloudantV1 } from '@ibm-cloud/cloudant';
800
841
  ```
842
+
801
843
  ```ts
802
844
  interface OrderDocument extends CloudantV1.Document {
803
845
  name?: string;
@@ -845,6 +887,7 @@ client
845
887
  }
846
888
  });
847
889
  ```
890
+
848
891
  </details>
849
892
 
850
893
  <details>
@@ -853,6 +896,7 @@ client
853
896
  ```js
854
897
  import { CloudantV1 } from '@ibm-cloud/cloudant';
855
898
  ```
899
+
856
900
  ```js
857
901
  const deleteDoc = async () => {
858
902
  // 1. Create a client with `CLOUDANT` default service name ====================
@@ -892,6 +936,7 @@ if (require.main === module) {
892
936
  deleteDoc();
893
937
  }
894
938
  ```
939
+
895
940
  </details>
896
941
 
897
942
  </details>
@@ -903,7 +948,7 @@ You have deleted the document.
903
948
 
904
949
  #### Further code examples
905
950
 
906
- For a complete list of code examples, see the [examples directory](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.4/examples#examples-for-node).
951
+ For a complete list of code examples, see the [examples directory](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/examples#examples-for-node).
907
952
 
908
953
  ### Error handling
909
954
 
@@ -1014,13 +1059,13 @@ To allow CORS requests from the SDK in the browser:
1014
1059
  service.setEnableGzipCompression(false);
1015
1060
  ```
1016
1061
 
1017
- ### Changes feed follower (beta)
1062
+ ### Changes feed follower
1018
1063
 
1019
1064
  #### Introduction
1020
1065
 
1021
- The SDK provides a changes feed follower utility (currently beta).
1066
+ The SDK provides a changes feed follower utility.
1022
1067
  This helper utility connects to the `_changes` endpoint and returns the individual change items.
1023
- It removes some of the complexity of using the `_changes` endpoint by setting some options automatically
1068
+ It removes some complexity of using the `_changes` endpoint by setting some options automatically
1024
1069
  and providing error suppression and retries.
1025
1070
 
1026
1071
  *Tip: the changes feed often does not meet user expectations or assumptions.*
@@ -1032,18 +1077,18 @@ to get a better understanding of the limitations and suitable use-cases before u
1032
1077
 
1033
1078
  There are two modes of operation:
1034
1079
  * Start mode
1035
- * Fetches the changes from the supplied `since` sequence (by default the feed will start from `now`).
1080
+ * Fetches the changes from the supplied `since` sequence (in this mode follower defaults to reading the feed from `now`).
1036
1081
  * Fetches all available changes and then continues listening for new changes indefinitely unless encountering an end condition.
1037
1082
  * An example use case for this mode is event driven workloads.
1038
1083
  * Start one-off mode
1039
- * Fetches the changes from the supplied `since` sequence (by default the feed will start from the beginning).
1084
+ * Fetches the changes from the supplied `since` sequence (in this mode follower defaults to reading the feed from the beginning).
1040
1085
  * Fetches all available changes and then stops when either there are no further changes pending or encountering an end condition.
1041
1086
  * An example use case for this mode is ETL style workloads.
1042
1087
 
1043
1088
  #### Configuring the changes follower
1044
1089
 
1045
1090
  The SDK's model of changes feed options is also used to configure the follower.
1046
- However, a subset of the options are invalid as they are configured internally by the implementation.
1091
+ However, a subset of the options used internally by the follower implementation are invalid.
1047
1092
  Supplying these options when instantiating the follower causes an error.
1048
1093
  The invalid options are:
1049
1094
  * `descending`
@@ -1051,33 +1096,33 @@ The invalid options are:
1051
1096
  * `heartbeat`
1052
1097
  * `lastEventId` - use `since` instead
1053
1098
  * `timeout`
1054
- * Only the value of `_selector` is permitted for the `filter` option. This restriction is because selector
1055
- based filters perform better than JavaScript backed filters. Configuring a non-selector based filter will
1056
- cause the follower to error.
1099
+ * Follower permits only the value `_selector` for the `filter` option. This restriction is because selector
1100
+ based filters perform better than JavaScript backed filters. Configuring a non-selector based filter
1101
+ causes the follower to error.
1057
1102
 
1058
- Note that the `limit` parameter will terminate the follower at the given number of changes in either
1103
+ Note that the `limit` parameter terminates the follower at the given number of changes in either
1059
1104
  operating mode.
1060
1105
 
1061
- The changes follower requires the client to have HTTP timeouts of at least 1 minute and will error during
1106
+ The changes follower requires the client to have HTTP timeouts of at least 1 minute and errors during
1062
1107
  instantiation if it is insufficient. The default client configuration has sufficiently long timeouts.
1063
1108
 
1064
- For use-cases where these configuration limitations are deemed too restrictive then it is recommended to
1065
- write code to use the SDK's [POST `_changes` API](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.4/examples#postchanges) instead of the follower.
1109
+ For use-cases where these configuration limitations are too restrictive then write code to use the SDK's
1110
+ [POST `_changes` API](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/examples#postchanges) instead of the follower.
1066
1111
 
1067
1112
  #### Error suppression
1068
1113
 
1069
- By default, the changes follower will suppress transient errors indefinitely and attempt to run to completion or listen forever as
1114
+ By default, the changes follower suppresses transient errors indefinitely and attempts to run to completion or listen forever as
1070
1115
  dictated by the operating mode.
1071
- For applications where that is not desirable an optional error tolerance duration may be specified to control the time since
1072
- the last successful response that transient errors will be suppressed. This can be used, for example, by applications as a grace period
1116
+ For applications where that is not desirable configure the optional error tolerance duration. This controls the time since
1117
+ the last successful response that the follower suppresses transient errors. An example usage is an application grace period
1073
1118
  before reporting an error and requiring intervention.
1074
1119
 
1075
1120
  There are some additional points to consider for error suppression:
1076
- * Errors considered terminal, for example, the database not existing or invalid credentials are never suppressed and will error immediately.
1077
- * The error suppression duration is not guaranteed to fire immediately after lapsing and should be considered a minimum suppression time.
1078
- * The changes follower will back-off between retries and as such may remain paused for a short while after the transient errors have resolved.
1079
- * If the underlying SDK client used to initialize the follower also has retries configured then errors could be suppressed for significantly
1080
- longer than the follower's configured error tolerance duration depending on the configuration options.
1121
+ * Errors considered terminal, for example, the database not existing or invalid credentials are never suppressed and error immediately.
1122
+ * The error suppression duration is not guaranteed to fire immediately after lapsing and is a minimum suppression time.
1123
+ * The changes follower backs-off between retries and as such may remain paused for a short while after the transient errors have resolved.
1124
+ * If the underlying SDK client used to initialize the follower also has retries configured then suppression of errors may last
1125
+ significantly longer than the follower's configured error tolerance duration depending on the specific options.
1081
1126
 
1082
1127
  #### Follower operation
1083
1128
 
@@ -1086,41 +1131,41 @@ For both modes:
1086
1131
  * A terminal error (HTTP codes `400`, `401`, `403` `404`).
1087
1132
  * Transient errors occur for longer than the error tolerance duration. Transient errors are all other HTTP status codes and connection errors.
1088
1133
  * The number of changes received reaches the configured `limit`.
1089
- * The feed is terminated early by calling stop.
1134
+ * The application calls stop to terminate the feed early.
1090
1135
 
1091
- As is true for the `_changes` endpoint change items have *at least once* delivery and an individual item
1092
- may be received multiple times. When using the follower change items may be repeated even within a limited
1093
- number of changes (i.e. using the `limit` option) this is a minor difference from using `limit` on the HTTP native API.
1136
+ As is true for the `_changes` endpoint change items have *at least once* delivery and callers may receive
1137
+ an individual item multiple times. When using the follower change items may repeat even within a limited
1138
+ number of changes (that is using the `limit` option) this is a minor difference from using `limit` on the HTTP native API.
1094
1139
 
1095
1140
  The follower is not optimized for some use cases and it is not recommended to use it in cases where:
1096
1141
  * Setting `include_docs` and larger document sizes (for example > 10 kiB).
1097
- * The volume of changes is very high (if the rate of changes in the database exceeds the follower's rate of pulling them it will never catch-up).
1142
+ * The volume of changes is very high (if the rate of changes in the database exceeds the follower's rate of pulling them it can never catch-up).
1098
1143
 
1099
- In these cases use-case specific control over the number of change requests made and the content size of the responses
1100
- may be achieved by using the SDK's [POST `_changes` API](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.4/examples#postchanges).
1144
+ In these use-cases use the SDK's [POST `_changes` API](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/examples#postchanges)
1145
+ for specific control over the number of change requests made and the content size of the responses.
1101
1146
 
1102
- #### Checkpointing
1147
+ #### Checkpoints
1103
1148
 
1104
- The changes follower does not checkpoint since it has no information about whether a change item has been
1105
- processed by the consuming application after being received. It is the application developer's responsibility
1149
+ The changes follower does not checkpoint since it has no information about whether the consuming application
1150
+ has processed a change item after delivery. It is the application developer's responsibility
1106
1151
  to store the sequence IDs to have appropriate checkpoints and to re-initialize the follower with the required
1107
1152
  `since` value after, for example, the application restarts.
1108
1153
 
1109
- The frequency and conditions for checkpointing are application specific and some applications may be tolerant
1110
- of dropped changes. This section is intended only to provide general guidance on how to avoid missing changes.
1154
+ The frequency and conditions for checkpoints are application specific and some applications may be tolerant
1155
+ of dropped changes. This section provides only general guidance on how to avoid missing changes.
1111
1156
 
1112
- To guarantee processing of all changes the sequence ID from a change item must not be persisted until *after*
1113
- the processing of the change item by the application has completed. As indicated previously change items are
1114
- delivered *at least once* so application code must be able to handle repeated changes already and it is
1157
+ To guarantee processing of all changes do not persist the sequence ID from a change item until *after*
1158
+ the processing of the change item by the application has completed. As indicated previously change item
1159
+ delivery is *at least once* so application code must be able to handle repeated changes already. It is
1115
1160
  preferable to restart from an older `since` value and receive changes again than risk missing them.
1116
1161
 
1117
- The sequence IDs are available on each change item by default, but may be omitted from some change items when
1118
- using the `seq_interval` configuration option. Infrequent sequence IDs may improve performance by reducing
1119
- the amount of data that needs to be transferred, but the trade-off is that more changes will be repeated if
1120
- it is necessary to resume the changes follower.
1162
+ The sequence IDs are available on each change item by default. However, the server omits sequence IDs from
1163
+ some change items when using the `seq_interval` configuration option.
1164
+ Infrequent sequence IDs may improve performance by reducing the amount of data transfer and server load,
1165
+ but the tradeoff is repeating more changes if it is necessary to resume the changes follower.
1121
1166
 
1122
- Extreme care should be taken with persisting sequences if choosing to process change items in parallel as there
1123
- is a considerable risk of missing changes on a restart if the sequence is recorded out of order.
1167
+ Take extreme care persisting sequences if choosing to process change items in parallel as there
1168
+ is a considerable risk of missing changes on a restart if the recorded sequence is out of order.
1124
1169
 
1125
1170
  #### Code examples
1126
1171
 
@@ -1132,6 +1177,7 @@ is a considerable risk of missing changes on a restart if the sequence is record
1132
1177
  import { ChangesFollower, CloudantV1 } from '@ibm-cloud/cloudant';
1133
1178
  import { PostChangesParams } from '@ibm-cloud/cloudant/cloudant/v1';
1134
1179
  ```
1180
+
1135
1181
  ```ts
1136
1182
  const client = CloudantV1.newInstance({});
1137
1183
  const changesParams: PostChangesParams = {
@@ -1146,6 +1192,7 @@ const changesFollower: ChangesFollower = new ChangesFollower(
1146
1192
  10000 // Optional: suppress transient errors for at least 10 seconds before terminating.
1147
1193
  );
1148
1194
  ```
1195
+
1149
1196
  </details>
1150
1197
 
1151
1198
  <details>
@@ -1154,6 +1201,7 @@ const changesFollower: ChangesFollower = new ChangesFollower(
1154
1201
  ```js
1155
1202
  import { ChangesFollower, CloudantV1 } from '@ibm-cloud/cloudant';
1156
1203
  ```
1204
+
1157
1205
  ```js
1158
1206
  const client = CloudantV1.newInstance();
1159
1207
  const changesParams = {
@@ -1167,6 +1215,7 @@ const changesFollower = new ChangesFollower(
1167
1215
  10000 // Optional: suppress transient errors for at least 10 seconds before terminating.
1168
1216
  );
1169
1217
  ```
1218
+
1170
1219
  </details>
1171
1220
 
1172
1221
  ##### Starting the changes follower
@@ -1179,6 +1228,7 @@ const changesFollower = new ChangesFollower(
1179
1228
  import { ChangesFollower, CloudantV1, Stream } from '@ibm-cloud/cloudant';
1180
1229
  import { ChangesResultItem, PostChangesParams } from '@ibm-cloud/cloudant/cloudant/v1';
1181
1230
  ```
1231
+
1182
1232
  ```ts
1183
1233
  const client = CloudantV1.newInstance({});
1184
1234
  const changesParams: PostChangesParams = {
@@ -1189,6 +1239,7 @@ const changesItemsStream: Stream<ChangesResultItem> = changesFollower.start();
1189
1239
  // Create for-async-loop or pipeline to begin the flow of changes
1190
1240
  // e.g. pipeline(changesItemsStream, destinationStream).then(() => { ... }).catch((err) => { ... });
1191
1241
  ```
1242
+
1192
1243
  </details>
1193
1244
 
1194
1245
  <details>
@@ -1197,6 +1248,7 @@ const changesItemsStream: Stream<ChangesResultItem> = changesFollower.start();
1197
1248
  ```js
1198
1249
  import { ChangesFollower, CloudantV1 } from '@ibm-cloud/cloudant';
1199
1250
  ```
1251
+
1200
1252
  ```js
1201
1253
  const client = CloudantV1.newInstance();
1202
1254
  const changesParams = {
@@ -1207,6 +1259,7 @@ const changesItemsStream = changesFollower.start();
1207
1259
  // Create for-async-loop or pipeline to begin the flow of changes
1208
1260
  // e.g. pipeline(changesItemsStream, destinationStream).then(() => { ... }).catch((err) => { ... });
1209
1261
  ```
1262
+
1210
1263
  </details>
1211
1264
 
1212
1265
  ###### Start mode for one-off fetching
@@ -1217,6 +1270,7 @@ const changesItemsStream = changesFollower.start();
1217
1270
  import { ChangesFollower, CloudantV1, Stream } from '@ibm-cloud/cloudant';
1218
1271
  import { ChangesResultItem, PostChangesParams } from '@ibm-cloud/cloudant/cloudant/v1';
1219
1272
  ```
1273
+
1220
1274
  ```ts
1221
1275
  const client = CloudantV1.newInstance({});
1222
1276
  const changesParams: PostChangesParams = {
@@ -1227,6 +1281,7 @@ const changesItemsStream: Stream<ChangesResultItem> = changesFollower.startOneOf
1227
1281
  // Create for-async-loop or pipeline to begin the flow of changes
1228
1282
  // e.g. pipeline(changesItemsStream, destinationStream).then(() => { ... }).catch((err) => { ... });
1229
1283
  ```
1284
+
1230
1285
  </details>
1231
1286
 
1232
1287
  <details>
@@ -1235,6 +1290,7 @@ const changesItemsStream: Stream<ChangesResultItem> = changesFollower.startOneOf
1235
1290
  ```js
1236
1291
  import { ChangesFollower, CloudantV1 } from '@ibm-cloud/cloudant';
1237
1292
  ```
1293
+
1238
1294
  ```js
1239
1295
  const client = CloudantV1.newInstance();
1240
1296
  const changesParams = {
@@ -1245,6 +1301,7 @@ const changesItemsStream = changesFollower.startOneOff();
1245
1301
  // Create for-async-loop or pipeline to begin the flow of changes
1246
1302
  // e.g. pipeline(changesItemsStream, destinationStream).then(() => { ... }).catch((err) => { ... });
1247
1303
  ```
1304
+
1248
1305
  </details>
1249
1306
 
1250
1307
  ##### Processing changes
@@ -1259,6 +1316,7 @@ import { ChangesResultItem, PostChangesParams } from '@ibm-cloud/cloudant/clouda
1259
1316
  import { Writable } from 'node:stream';
1260
1317
  import { pipeline } from 'node:stream/promises';
1261
1318
  ```
1319
+
1262
1320
  ```ts
1263
1321
  const client = CloudantV1.newInstance({});
1264
1322
  // Start from a previously persisted seq
@@ -1297,6 +1355,7 @@ pipeline(changesItemsStream, destinationStream)
1297
1355
  console.log(err);
1298
1356
  });
1299
1357
  ```
1358
+
1300
1359
  </details>
1301
1360
 
1302
1361
  <details>
@@ -1307,6 +1366,7 @@ import { ChangesFollower, CloudantV1 } from '@ibm-cloud/cloudant';
1307
1366
  import { Writable } from 'node:stream';
1308
1367
  import { pipeline } from 'node:stream/promises';
1309
1368
  ```
1369
+
1310
1370
  ```js
1311
1371
  const client = CloudantV1.newInstance();
1312
1372
  // Start from a previously persisted seq
@@ -1345,6 +1405,7 @@ pipeline(changesItemsStream, destinationStream)
1345
1405
  console.log(err);
1346
1406
  });
1347
1407
  ```
1408
+
1348
1409
  </details>
1349
1410
 
1350
1411
  ###### Process one-off changes
@@ -1357,6 +1418,7 @@ import { ChangesResultItem, PostChangesParams } from '@ibm-cloud/cloudant/clouda
1357
1418
  import { Writable } from 'node:stream';
1358
1419
  import { pipeline } from 'node:stream/promises';
1359
1420
  ```
1421
+
1360
1422
  ```ts
1361
1423
  const client = CloudantV1.newInstance({});
1362
1424
  // Start from a previously persisted seq
@@ -1413,6 +1475,7 @@ async function getChangesFromFollower(changesItemsStream: Stream<CloudantV1.Chan
1413
1475
  }
1414
1476
  */
1415
1477
  ```
1478
+
1416
1479
  </details>
1417
1480
 
1418
1481
  <details>
@@ -1423,6 +1486,7 @@ import { ChangesFollower, CloudantV1 } from '@ibm-cloud/cloudant';
1423
1486
  import { Writable } from 'node:stream';
1424
1487
  import { pipeline } from 'node:stream/promises';
1425
1488
  ```
1489
+
1426
1490
  ```js
1427
1491
  const client = CloudantV1.newInstance();
1428
1492
  // Start from a previously persisted seq
@@ -1479,6 +1543,7 @@ async function getChangesFromFollower(changesItemsStream) {
1479
1543
  }
1480
1544
  */
1481
1545
  ```
1546
+
1482
1547
  </details>
1483
1548
 
1484
1549
  ##### Stopping the changes follower
@@ -1491,6 +1556,7 @@ import { ChangesResultItem, PostChangesParams } from '@ibm-cloud/cloudant/clouda
1491
1556
  import { Writable } from 'node:stream';
1492
1557
  import { pipeline } from 'node:stream/promises';
1493
1558
  ```
1559
+
1494
1560
  ```ts
1495
1561
  const client = CloudantV1.newInstance({});
1496
1562
  const changesParams: PostChangesParams = {
@@ -1528,6 +1594,7 @@ setTimeout(() => {
1528
1594
  changesFollower.stop();
1529
1595
  }, 60000);
1530
1596
  ```
1597
+
1531
1598
  </details>
1532
1599
 
1533
1600
  <details>
@@ -1538,6 +1605,7 @@ import { ChangesFollower, CloudantV1 } from '@ibm-cloud/cloudant';
1538
1605
  import { Writable } from 'node:stream';
1539
1606
  import { pipeline } from 'node:stream/promises';
1540
1607
  ```
1608
+
1541
1609
  ```js
1542
1610
  const client = CloudantV1.newInstance();
1543
1611
  const changesParams = {
@@ -1575,6 +1643,512 @@ setTimeout(() => {
1575
1643
  changesFollower.stop();
1576
1644
  }, 60000);
1577
1645
  ```
1646
+
1647
+ </details>
1648
+
1649
+ ### Pagination (beta)
1650
+
1651
+ #### Introduction
1652
+
1653
+ The pagination feature (currently beta) accepts options for a single operation and automatically
1654
+ creates the multiple requests to the server necessary to page through the results a fixed number at a time.
1655
+
1656
+ Pagination is a best-practice to break apart large queries into multiple server requests.
1657
+ This has a number of advantages:
1658
+ * Keeping requests within server imposed limits, for example
1659
+ * `200` max results for text search
1660
+ * `2000` max results for partitioned queries
1661
+ * Fetching only the necessary data, for example
1662
+ * User finds required result on first page, no need to continue fetching results
1663
+ * Reducing the duration of any individual query
1664
+ * Reduce risk of query timing out on the server
1665
+ * Reduce risk of network request timeouts
1666
+
1667
+ #### Limitations
1668
+
1669
+ Limitations of pagination:
1670
+ * Forward only, no backwards paging
1671
+ * Limitations on `_all_docs` and `_design_docs` operations
1672
+ * No pagination for `key` option.
1673
+ There is no need to paginate as IDs are unique and this returns only a single row.
1674
+ This is better achieved with a single document get request.
1675
+ * No pagination for `keys` option.
1676
+ * Limitations on `_view` operations
1677
+ * No pagination for `key` option. Pass the same `key` as a start and end key instead.
1678
+ * No pagination for `keys` option.
1679
+ * Views that emit multiple identical keys (with the same or different values)
1680
+ from the same document cannot paginate if those key rows with the same ID
1681
+ span a page boundary.
1682
+ The pagination feature detects this condition and an error occurs.
1683
+ It may be possible to workaround using a different page size.
1684
+ * Limitations on `_search` operations
1685
+ * No pagination of grouped results.
1686
+ * No pagination of faceted `counts` or `ranges` results.
1687
+
1688
+ #### Capacity considerations
1689
+
1690
+ Pagination can make many requests rapidly from a single program call.
1691
+
1692
+ For IBM Cloudant take care to ensure you have appropriate plan capacity
1693
+ in place to avoid consuming all the permitted requests.
1694
+ If there is no remaining plan allowance and retries are not enabled or insufficient
1695
+ then a `429 Too Many Requests` error occurs.
1696
+
1697
+ #### Available operations
1698
+
1699
+ Pagination is available for these operations:
1700
+ * Query all documents [global](https://cloud.ibm.com/apidocs/cloudant?code=node#postalldocs)
1701
+ and [partitioned](https://cloud.ibm.com/apidocs/cloudant?code=node#postpartitionalldocs)
1702
+ * [Global all documents examples](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/test/examples/src/features/pagination/ts/allDocsPagination.ts)
1703
+ * [Partitioned all documents examples](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/test/examples/src/features/pagination/ts/partitionAllDocsPagination.ts)
1704
+ * Query all [design documents](https://cloud.ibm.com/apidocs/cloudant?code=node#postdesigndocs)
1705
+ * [Design documents examples](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/test/examples/src/features/pagination/ts/designDocsPagination.ts)
1706
+ * Query with selector syntax [global](https://cloud.ibm.com/apidocs/cloudant?code=node#postfind)
1707
+ and [partitioned](https://cloud.ibm.com/apidocs/cloudant?code=node#postpartitionfind)
1708
+ * [Global find selector query examples](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/test/examples/src/features/pagination/ts/findPagination.ts)
1709
+ * [Partitioned find selector query examples](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/test/examples/src/features/pagination/ts/partitionFindPagination.ts)
1710
+ * Query a search index [global](https://cloud.ibm.com/apidocs/cloudant?code=node#postsearch)
1711
+ and [partitioned](https://cloud.ibm.com/apidocs/cloudant?code=node#postpartitionsearch)
1712
+ * [Global search examples](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/test/examples/src/features/pagination/ts/searchPagination.ts)
1713
+ * [Partitioned search examples](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/test/examples/src/features/pagination/ts/partitionSearchPagination.ts)
1714
+ * Query a MapReduce view [global](https://cloud.ibm.com/apidocs/cloudant?code=node#postview)
1715
+ and [partitioned](https://cloud.ibm.com/apidocs/cloudant?code=node#postpartitionview)
1716
+ * [Global view examples](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/test/examples/src/features/pagination/ts/viewPagination.ts)
1717
+ * [Partitioned view examples](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/test/examples/src/features/pagination/ts/partitionViewPagination.ts)
1718
+
1719
+ The examples presented in this `README` are for all documents in a partition.
1720
+ The links in the list are to equivalent examples for each of the other available operations.
1721
+
1722
+ #### Creating a pagination
1723
+
1724
+ Make a new pagination from a client
1725
+ and the options for the chosen operation.
1726
+ Use the `limit` option to configure the page size (default and maximum `200`).
1727
+
1728
+ Imports required for these examples:
1729
+
1730
+ <details open>
1731
+ <summary>TypeScript:</summary>
1732
+
1733
+ ```ts
1734
+ import {
1735
+ CloudantV1,
1736
+ PagerType,
1737
+ Pagination,
1738
+ Pager,
1739
+ Stream,
1740
+ } from '@ibm-cloud/cloudant';
1741
+ import { Writable } from 'node:stream';
1742
+ import { pipeline } from 'node:stream/promises';
1743
+ ```
1744
+
1745
+ </details>
1746
+
1747
+ <details>
1748
+ <summary>JavaScript:</summary>
1749
+
1750
+ ```js
1751
+ import { Pagination, PagerType } from '@ibm-cloud/cloudant';
1752
+ import { Writable } from 'node:stream';
1753
+ import { pipeline } from 'node:stream/promises';
1754
+ ```
1755
+
1756
+ </details>
1757
+
1758
+ ##### Initialize the service
1759
+
1760
+ <details open>
1761
+ <summary>TypeScript:</summary>
1762
+
1763
+ ```ts
1764
+ // Initialize service
1765
+ const client: CloudantV1 = CloudantV1.newInstance({});
1766
+ ```
1767
+
1768
+ </details>
1769
+
1770
+ <details>
1771
+ <summary>JavaScript:</summary>
1772
+
1773
+ ```js
1774
+ // Initialize service
1775
+ const client = CloudantV1.newInstance();
1776
+ ```
1777
+
1778
+ </details>
1779
+
1780
+ ##### Set the options
1781
+
1782
+ <details open>
1783
+ <summary>TypeScript:</summary>
1784
+
1785
+ ```ts
1786
+ // Setup params
1787
+ const paginationParams: CloudantV1.PostPartitionAllDocsParams = {
1788
+ db: 'events', // Required: the database name.
1789
+ limit: 50, // Optional: limit parameter sets the page size. Default and max is 200.
1790
+ partitionKey: 'ns1HJS13AMkK', // query only this partition
1791
+ };
1792
+ ```
1793
+
1794
+ </details>
1795
+
1796
+ <details>
1797
+ <summary>JavaScript:</summary>
1798
+
1799
+ ```js
1800
+ // Setup params
1801
+ const paginationParams = {
1802
+ db: 'events', // Required: the database name.
1803
+ limit: 50, // Optional: limit parameter sets the page size. Default and max is 200.
1804
+ partitionKey: 'ns1HJS13AMkK', // query only this partition
1805
+ };
1806
+ ```
1807
+
1808
+ </details>
1809
+
1810
+ ##### Create the pagination
1811
+
1812
+ <details open>
1813
+ <summary>TypeScript:</summary>
1814
+
1815
+ ```ts
1816
+ // Create pagination
1817
+ // pagination can be reused without side-effects as a factory for async iterables, streams or pagers
1818
+ const pagination: Pagination<CloudantV1.DocsResultRow> =
1819
+ Pagination.newPagination(
1820
+ client, // Required: the Cloudant service client instance.
1821
+ PagerType.POST_PARTITION_ALL_DOCS, // Required: Pager type
1822
+ paginationParams // Required: pagination configuration params are fixed at pagination creation time
1823
+ );
1824
+ ```
1825
+
1826
+ </details>
1827
+
1828
+ <details>
1829
+ <summary>JavaScript:</summary>
1830
+
1831
+ ```js
1832
+ // Create pagination
1833
+ // pagination can be reused without side-effects as a factory for async iterables, streams or pagers
1834
+ const pagination = Pagination.newPagination(
1835
+ client, // Required: the Cloudant service client instance.
1836
+ PagerType.POST_PARTITION_ALL_DOCS, // Required: Pager type
1837
+ paginationParams // Required: pagination configuration params are fixed at pagination creation time
1838
+ );
1839
+ ```
1840
+
1841
+ </details>
1842
+
1843
+ #### Using pagination
1844
+
1845
+ Once you have a pagination factory there are multiple options available.
1846
+ * Stream pages
1847
+ * Stream rows
1848
+ * Iterate pages
1849
+ * Iterate rows
1850
+ * Get each page from a pager
1851
+ * Get all results from a pager
1852
+
1853
+ All the paging styles produce equivalent results and make identical page requests.
1854
+ The style of paging to choose depends on the use case requirements
1855
+ in particular whether to process a page at a time or a row at a time.
1856
+
1857
+ The pagination factory is reusable and can repeatedly produce new instances
1858
+ of the same or different pagination styles for the same operation options.
1859
+
1860
+ Here are examples for each paging style.
1861
+
1862
+ ##### Stream pages
1863
+
1864
+ Streaming pages is ideal for lazy processing of pages
1865
+ and leveraging Node.js's built-in stream utilities.
1866
+
1867
+ <details open>
1868
+ <summary>TypeScript:</summary>
1869
+
1870
+ ```ts
1871
+ // Option: stream pages
1872
+ const pageStream: Stream<ReadonlyArray<CloudantV1.DocsResultRow>> =
1873
+ pagination.pageStream(); // a new stream of the pages
1874
+ const destinationPageStream = new Writable({
1875
+ objectMode: true,
1876
+ write(page: Array<CloudantV1.DocsResultRow>, _, callback) {
1877
+ // Do something with page
1878
+ callback();
1879
+ },
1880
+ });
1881
+ (async () => {
1882
+ await pipeline(pageStream, destinationPageStream)
1883
+ .then(() => {
1884
+ console.log('Page stream is done');
1885
+ })
1886
+ .catch((err) => {
1887
+ console.log(err);
1888
+ });
1889
+ })();
1890
+ ```
1891
+
1892
+ </details>
1893
+
1894
+ <details>
1895
+ <summary>JavaScript:</summary>
1896
+
1897
+ ```js
1898
+ // Option: stream pages
1899
+ const pageStream = pagination.pageStream(); // a new stream of the pages
1900
+ const destinationPageStream = new Writable({
1901
+ objectMode: true,
1902
+ write(page, _, callback) {
1903
+ // Do something with page
1904
+ callback();
1905
+ },
1906
+ });
1907
+ (async () => {
1908
+ await pipeline(pageStream, destinationPageStream)
1909
+ .then(() => {
1910
+ console.log('Page stream is done');
1911
+ })
1912
+ .catch((err) => {
1913
+ console.log(err);
1914
+ });
1915
+ })();
1916
+ ```
1917
+
1918
+ </details>
1919
+
1920
+ ##### Stream rows
1921
+
1922
+ Streaming pages is ideal for lazy processing of rows
1923
+ and leveraging Node.js's built-in stream utilities.
1924
+
1925
+ <details open>
1926
+ <summary>TypeScript:</summary>
1927
+
1928
+ ```ts
1929
+ // Option: stream rows
1930
+ const rowStream: Stream<CloudantV1.DocsResultRow> = pagination.rowStream(); // a new stream of the rows
1931
+ const destinationRowStream = new Writable({
1932
+ objectMode: true,
1933
+ write(row: CloudantV1.DocsResultRow, _, callback) {
1934
+ // Do something with row
1935
+ callback();
1936
+ },
1937
+ });
1938
+ (async () => {
1939
+ await pipeline(rowStream, destinationRowStream)
1940
+ .then(() => {
1941
+ console.log('Row stream is done');
1942
+ })
1943
+ .catch((err) => {
1944
+ console.log(err);
1945
+ });
1946
+ })();
1947
+ ```
1948
+
1949
+ </details>
1950
+
1951
+ <details>
1952
+ <summary>JavaScript:</summary>
1953
+
1954
+ ```js
1955
+ // Option: stream rows
1956
+ const rowStream = pagination.rowStream(); // a new stream of the rows
1957
+ const destinationRowStream = new Writable({
1958
+ objectMode: true,
1959
+ write(row, _, callback) {
1960
+ // Do something with row
1961
+ callback();
1962
+ },
1963
+ });
1964
+ (async () => {
1965
+ await pipeline(rowStream, destinationRowStream)
1966
+ .then(() => {
1967
+ console.log('Row stream is done');
1968
+ })
1969
+ .catch((err) => {
1970
+ console.log(err);
1971
+ });
1972
+ })();
1973
+ ```
1974
+
1975
+ </details>
1976
+
1977
+ ##### Iterate pages
1978
+
1979
+ Iterating pages is ideal for using a for await...of statement to process a page at a time.
1980
+
1981
+ <details open>
1982
+ <summary>TypeScript:</summary>
1983
+
1984
+ ```ts
1985
+ // Option: iterate pages with for await...of statement
1986
+ (async () => {
1987
+ for await (const page of pagination.pages()) {
1988
+ // Do something with page
1989
+ }
1990
+ })();
1991
+ // Note: Alternatively to for await....of the iterator protocol functions and properties, like
1992
+ // `next()`, `done`, value`, can be used on the iterator returned from pages().
1993
+ // As `next()` returns with a Promise, use `await` or `.then()` on it.
1994
+ ```
1995
+
1996
+ </details>
1997
+
1998
+ <details>
1999
+ <summary>JavaScript:</summary>
2000
+
2001
+ ```js
2002
+ // Option: iterate pages with for await...of statement
2003
+ (async () => {
2004
+ for await (const page of pagination.pages()) {
2005
+ // Do something with page
2006
+ }
2007
+ })();
2008
+ // Note: Alternatively to for await....of the iterator protocol functions and properties, like
2009
+ // `next()`, `done`, value`, can be used on the iterator returned from pages().
2010
+ // As `next()` returns with a Promise, use `await` or `.then()` on it.
2011
+ ```
2012
+
2013
+ </details>
2014
+
2015
+ ##### Iterate rows
2016
+
2017
+ Iterating rows is ideal for using a for await...of statement to process a result row at a time.
2018
+
2019
+ <details open>
2020
+ <summary>TypeScript:</summary>
2021
+
2022
+ ```ts
2023
+ // Option: iterate rows with for await...of statement
2024
+ (async () => {
2025
+ for await (const row of pagination.rows()) {
2026
+ // Do something with row
2027
+ }
2028
+ })();
2029
+ // Note: Alternatively to for await....of the iterator protocol functions and properties:
2030
+ // `next()`, `done`, value`, can be also used on rows().
2031
+ // As `next(`)` returns with a Promise, make sure using `await` or `.then()` on it.
2032
+ ```
2033
+
2034
+ </details>
2035
+
2036
+ <details>
2037
+ <summary>JavaScript:</summary>
2038
+
2039
+ ```js
2040
+ // Option: iterate rows with for await...of statement
2041
+ (async () => {
2042
+ for await (const row of pagination.rows()) {
2043
+ // Do something with row
2044
+ }
2045
+ })();
2046
+ // Note: Alternatively to for await....of the iterator protocol functions and properties:
2047
+ // `next()`, `done`, value`, can be also used on rows().
2048
+ // As `next(`)` returns with a Promise, make sure using `await` or `.then()` on it.
2049
+ ```
2050
+
2051
+ </details>
2052
+
2053
+ ##### Pager
2054
+
2055
+ The pager style is similar to other [IBM Cloud SDKs](https://github.com/IBM/ibm-cloud-sdk-common?tab=readme-ov-file#pagination).
2056
+ Users familiar with that style of pagination may find using them preferable
2057
+ to the native language style iterators.
2058
+
2059
+ In the Cloudant SDKs these pagers are single use and traverse the complete set of pages once and only once.
2060
+ After exhaustion they cannot be re-used, simply create a new one from the pagination factory if needed.
2061
+
2062
+ Pagers are only valid for one of either page at a time or getting all results.
2063
+ For example, calling for the next page then calling for all results causes an error.
2064
+
2065
+ ###### Get each page from a pager
2066
+
2067
+ This is useful for calling to retrieve one page at a time, for example,
2068
+ in a user interface with a "next page" interaction.
2069
+
2070
+ If calling for the next page errors, it is valid to call for the next page again
2071
+ to continue paging.
2072
+
2073
+ <details open>
2074
+ <summary>TypeScript:</summary>
2075
+
2076
+ ```ts
2077
+ // Option: use pager next page
2078
+ // For retrieving one page at a time with a function call.
2079
+ const pager: Pager<CloudantV1.DocsResultRow> = pagination.pager();
2080
+ (async () => {
2081
+ if (pager.hasNext()) {
2082
+ const page: Array<CloudantV1.DocsResultRow> = await pager.getNext();
2083
+ // Do something with page
2084
+ }
2085
+ })();
2086
+ ```
2087
+
2088
+ </details>
2089
+
2090
+ <details>
2091
+ <summary>JavaScript:</summary>
2092
+
2093
+ ```js
2094
+ // Option: use pager next page
2095
+ // For retrieving one page at a time with a function call.
2096
+ const pager = pagination.pager();
2097
+ (async () => {
2098
+ if (pager.hasNext()) {
2099
+ const page = await pager.getNext();
2100
+ // Do something with page
2101
+ }
2102
+ })();
2103
+ ```
2104
+
2105
+ </details>
2106
+
2107
+ ###### Get all results from a pager
2108
+
2109
+ This is useful to retrieve all results in a single call.
2110
+ However, this approach requires sufficient memory for the entire collection of results.
2111
+ So although it may be convenient for small result sets generally prefer iterating pages
2112
+ or rows with the other paging styles, especially for large result sets.
2113
+
2114
+ If calling for all the results errors, then calling for all the results again restarts the pagination.
2115
+
2116
+ <details open>
2117
+ <summary>TypeScript:</summary>
2118
+
2119
+ ```ts
2120
+ // Option: use pager all results
2121
+ // For retrieving all result rows in a single list
2122
+ // Note: all result rows may be very large!
2123
+ // Preferably use streams/iterables instead of getAll for memory efficiency with large result sets.
2124
+ const allPager: Pager<CloudantV1.DocsResultRow> = pagination.pager();
2125
+ (async () => {
2126
+ const allRows: Array<CloudantV1.DocsResultRow> = await allPager.getAll();
2127
+ for (const row of allRows) {
2128
+ // Do something with row
2129
+ }
2130
+ })();
2131
+ ```
2132
+
2133
+ </details>
2134
+
2135
+ <details>
2136
+ <summary>JavaScript:</summary>
2137
+
2138
+ ```js
2139
+ // Option: use pager all results
2140
+ // For retrieving all result rows in a single list
2141
+ // Note: all result rows may be very large!
2142
+ // Preferably use streams/iterables instead of getAll for memory efficiency with large result sets.
2143
+ const allPager = pagination.pager();
2144
+ (async () => {
2145
+ const allRows = await allPager.getAll();
2146
+ for (const row of allRows) {
2147
+ // Do something with row
2148
+ }
2149
+ })();
2150
+ ```
2151
+
1578
2152
  </details>
1579
2153
 
1580
2154
  ## Questions
@@ -1590,7 +2164,7 @@ If you encounter an issue with the project, you are welcome to submit a
1590
2164
 
1591
2165
  Before you submit a bug report, search for
1592
2166
  [similar issues](https://github.com/IBM/cloudant-node-sdk/issues?q=is%3Aissue) and review the
1593
- [KNOWN_ISSUES file](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.4/KNOWN_ISSUES.md) to verify that your issue hasn't been reported yet.
2167
+ [KNOWN_ISSUES file](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/KNOWN_ISSUES.md) to verify that your issue hasn't been reported yet.
1594
2168
 
1595
2169
  Please consult the [security policy](https://github.com/IBM/cloudant-node-sdk/security/policy) before opening security related issues.
1596
2170
 
@@ -1620,8 +2194,8 @@ Find more open source projects on the [IBM GitHub](http://ibm.github.io/) page.
1620
2194
 
1621
2195
  ## Contributing
1622
2196
 
1623
- For more information, see [CONTRIBUTING](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.4/CONTRIBUTING.md).
2197
+ For more information, see [CONTRIBUTING](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/CONTRIBUTING.md).
1624
2198
 
1625
2199
  ## License
1626
2200
 
1627
- This SDK is released under the Apache 2.0 license. To read the full text of the license, see [LICENSE](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.4/LICENSE).
2201
+ This SDK is released under the Apache 2.0 license. To read the full text of the license, see [LICENSE](https://github.com/IBM/cloudant-node-sdk/tree/v0.12.6/LICENSE).