# Page and retry policies

> Pagination results and the retry and reconnect policies.

Source: https://docs.stxapp.io/sdks/typescript/reference/helpers/

{/* Generated from the TypeScript source by tools/gen-reference.mjs. Do not edit by hand. */}

## `Page`

### Constructor

```ts
new Page(items: T[], cursor: string | null)
```

| Parameter | Type | Description |
|---|---|---|
| `items` | `T[]` |  |
| `cursor` | `string \| null` |  |

### Properties

| Property | Type | Description |
|---|---|---|
| `cursor` | `string \| null` |  |
| `items` | `T[]` |  |
| `hasMore` | `boolean` | True when another page exists. |
| `length` | `number` |  |

### Methods

#### `[iterator]()`

{/* sdk:Page.[iterator] */}

```ts
[iterator](): Iterator<T>
```

Returns `Iterator<T>`.

#### `at()`

```ts
at(index: number): T | undefined
```

The item at `index`; negative counts from the end.

| Parameter | Type | Description |
|---|---|---|
| `index` | `number` |  |

Returns `T \| undefined`.

## `RetryPolicy`

How many times to try a call, and how long to wait between tries. The
default is 3 attempts, 500 ms initial backoff doubling to a 30 s cap, with
jitter. `new RetryPolicy({ maxAttempts: 1 })` (or `NO_RETRY`) turns
retries off.

### Constructor

```ts
new RetryPolicy(opts?: RetryPolicyOptions)
```

| Parameter | Type | Description |
|---|---|---|
| `opts` (optional) | `RetryPolicyOptions` |  |
| `opts.initialBackoffMs` (optional) | `number` | Milliseconds before the first retry. Default 500. |
| `opts.jitter` (optional) | `boolean` | Randomise each wait between 50% and 100% of its value. Default true. |
| `opts.maxAttempts` (optional) | `number` | Total attempts, including the first. Default 3. |
| `opts.maxBackoffMs` (optional) | `number` | Cap on any one wait, in milliseconds. Default 30000. |
| `opts.retryableExceptions` (optional) | `readonly ExceptionClass[]` | Exception classes eligible for a retry. |

### Properties

| Property | Type | Description |
|---|---|---|
| `initialBackoffMs` | `number` |  |
| `jitter` | `boolean` |  |
| `maxAttempts` | `number` |  |
| `maxBackoffMs` | `number` |  |
| `retryableExceptions` | `readonly ExceptionClass[]` |  |

### Methods

#### `computeBackoffMs()`

```ts
computeBackoffMs(attempt: number, exc: STXException): number
```

Milliseconds to wait after attempt `attempt` (1-based) failed.

| Parameter | Type | Description |
|---|---|---|
| `attempt` | `number` |  |
| `exc` | `STXException` |  |

Returns `number`.

#### `shouldRetry()`

```ts
shouldRetry(exc: STXException, attempt: number, idempotent: boolean): boolean
```

Whether to try again after `exc` ended attempt number `attempt`.

| Parameter | Type | Description |
|---|---|---|
| `exc` | `STXException` |  |
| `attempt` | `number` |  |
| `idempotent` | `boolean` |  |

Returns `boolean`.

## `ReconnectPolicy`

Backoff between reconnect attempts.

### Constructor

```ts
new ReconnectPolicy(opts?: ReconnectPolicyOptions)
```

| Parameter | Type | Description |
|---|---|---|
| `opts` (optional) | `ReconnectPolicyOptions` |  |
| `opts.initialBackoffMs` (optional) | `number` |  |
| `opts.jitter` (optional) | `boolean` |  |
| `opts.maxAttempts` (optional) | `number \| null` | `null` (the default) never gives up. |
| `opts.maxBackoffMs` (optional) | `number` |  |

### Properties

| Property | Type | Description |
|---|---|---|
| `initialBackoffMs` | `number` |  |
| `jitter` | `boolean` |  |
| `maxAttempts` | `number \| null` |  |
| `maxBackoffMs` | `number` |  |

### Methods

#### `delayMs()`

```ts
delayMs(attempt: number): number
```

| Parameter | Type | Description |
|---|---|---|
| `attempt` | `number` |  |

Returns `number`.
