---
title: "nuxt-backend/aggregate"
description: "Every export of nuxt-backend/aggregate, with its signature and where it is defined."
canonical_url: "https://nuxt-backend.dev/docs/reference/api/aggregate"
---
# nuxt-backend/aggregate

## Classes

### TableAggregate

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:390

Re-exports for the [Aggregate](https://www.convex.dev/components/aggregate) component, so consumers configure denormalized counts/sums from a
single import. Construct one `TableAggregate` per app-mounted aggregate
instance and keep it in sync with [Triggers](#triggers).

#### Extends

- `Aggregate`<`T`[`"Key"`], `GenericId`<`T`[`"TableName"`]>, `TableAggregateNamespace`<`T`>>

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-t">
        
      </a>
      
       <code>
        T
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        AnyTableAggregateType
      </code>
    </td>
  </tr>
</tbody>
</table>

#### Constructors

##### Constructor

```ts
new TableAggregate<T>(component, options): TableAggregate<T>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:392

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        component
      </code>
    </td>
    
    <td>
      <code>
        ComponentApi
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        options
      </code>
    </td>
    
    <td>
      { <code>
        sortKey
      </code>
      
      : (<code>
        d
      </code>
      
      ) => <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]; <code>
        sumValue?
      </code>
      
      : (<code>
        d
      </code>
      
      ) => <code>
        number
      </code>
      
      ; } & <code>
        undefined
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      > ? { <code>
        namespace?
      </code>
      
      : (<code>
        d
      </code>
      
      ) => <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >; } : { <code>
        namespace
      </code>
      
      : (<code>
        d
      </code>
      
      ) => <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >; }
    </td>
  </tr>
</tbody>
</table>

###### Returns

[`TableAggregate`](#tableaggregate)<`T`>

###### Overrides

```ts
Aggregate<T["Key"], GenericId<T["TableName"]>, TableAggregateNamespace<T>>.constructor
```

#### Methods

##### count()

```ts
count(ctx, ...opts): Promise<number>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:83

Counts items between the given bounds.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      ...<code>
        opts
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOpts
      </code>
      
      <{ <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`number`>

###### Inherited from

```ts
Aggregate.count
```

##### countBatch()

```ts
countBatch(
   ctx, 
   queries, 
   opts?
): Promise<number[]>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:90

Batch version of count() - counts items for multiple bounds in a single call.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        queries
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOptsBatch
      </code>
      
      <{ <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.stale?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`number`<span>



</span>

>

###### Inherited from

```ts
Aggregate.countBatch
```

##### sum()

```ts
sum(ctx, ...opts): Promise<number>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:98

Adds up the sumValue of items between the given bounds.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      ...<code>
        opts
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOpts
      </code>
      
      <{ <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`number`>

###### Inherited from

```ts
Aggregate.sum
```

##### sumBatch()

```ts
sumBatch(
   ctx, 
   queries, 
   opts?
): Promise<number[]>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:105

Batch version of sum() - sums items for multiple bounds in a single call.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        queries
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOptsBatch
      </code>
      
      <{ <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.stale?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`number`<span>



</span>

>

###### Inherited from

```ts
Aggregate.sumBatch
```

##### at()

```ts
at(
   ctx, 
   offset, 
   ...opts
): Promise<Item<T["Key"], Id<T["TableName"]>>>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:118

Returns the item at the given offset/index/rank in the order of key,
within the bounds. Zero-indexed, so at(0) is the smallest key within the
bounds.

If offset is negative, it counts from the end of the list, so at(-1) is the
item with the largest key within the bounds.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        offset
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      ...<code>
        opts
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOpts
      </code>
      
      <{ <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`Item`<`T`[`"Key"`], `Id`<`T`[`"TableName"`]>>>

###### Inherited from

```ts
Aggregate.at
```

##### atBatch()

```ts
atBatch(
   ctx, 
   queries, 
   opts?
): Promise<Item<T["Key"], Id<T["TableName"]>>[]>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:125

Batch version of at() - returns items at multiple offsets in a single call.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        queries
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOptsBatch
      </code>
      
      <{ <code>
        offset
      </code>
      
      : <code>
        number
      </code>
      
      ; <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.stale?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`Item`<`T`[`"Key"`], `Id`<`T`[`"TableName"`]>><span>



</span>

>

###### Inherited from

```ts
Aggregate.atBatch
```

##### indexOf()

```ts
indexOf(
   ctx, 
   key, 
   ...opts
): Promise<number>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:138

Returns the rank/offset/index of the given key, within the bounds.
Specifically, it returns the index of the first item with

- key >= the given key if `order` is "asc" (default)
- key <= the given key if `order` is "desc"

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        key
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      ...<code>
        opts
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOpts
      </code>
      
      <{ <code>
        id?
      </code>
      
      : <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>; <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; <code>
        order?
      </code>
      
      : <code>
        "asc"
      </code>
      
       | <code>
        "desc"
      </code>
      
      ; <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`number`>

###### Inherited from

```ts
Aggregate.indexOf
```

##### ~~offsetOf()~~

```ts
offsetOf(
   ctx, 
   key, 
   namespace, 
   id?, 
   bounds?, 
   stale?
): Promise<number>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:147

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        key
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        namespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        id?
      </code>
    </td>
    
    <td>
      <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bounds?
      </code>
    </td>
    
    <td>
      <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stale?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`number`>

###### Deprecated

Use `indexOf` instead.

###### Inherited from

```ts
Aggregate.offsetOf
```

##### ~~offsetUntil()~~

```ts
offsetUntil(
   ctx, 
   key, 
   namespace, 
   id?, 
   bounds?, 
   stale?
): Promise<number>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:151

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        key
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        namespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        id?
      </code>
    </td>
    
    <td>
      <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bounds?
      </code>
    </td>
    
    <td>
      <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stale?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`number`>

###### Deprecated

Use `indexOf` instead.

###### Inherited from

```ts
Aggregate.offsetUntil
```

##### min()

```ts
min(ctx, ...opts): Promise<Item<T["Key"], Id<T["TableName"]>> | null>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:155

Gets the minimum item within the given bounds.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      ...<code>
        opts
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOpts
      </code>
      
      <{ <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`Item`<`T`[`"Key"`], `Id`<`T`[`"TableName"`]>> | `null`>

###### Inherited from

```ts
Aggregate.min
```

##### max()

```ts
max(ctx, ...opts): Promise<Item<T["Key"], Id<T["TableName"]>> | null>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:162

Gets the maximum item within the given bounds.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      ...<code>
        opts
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOpts
      </code>
      
      <{ <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`Item`<`T`[`"Key"`], `Id`<`T`[`"TableName"`]>> | `null`>

###### Inherited from

```ts
Aggregate.max
```

##### random()

```ts
random(ctx, ...opts): Promise<Item<T["Key"], Id<T["TableName"]>> | null>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:169

Gets a uniformly random item within the given bounds.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      ...<code>
        opts
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOpts
      </code>
      
      <{ <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`Item`<`T`[`"Key"`], `Id`<`T`[`"TableName"`]>> | `null`>

###### Inherited from

```ts
Aggregate.random
```

##### paginate()

```ts
paginate(ctx, ...opts): Promise<{
  page: Item<T["Key"], Id<T["TableName"]>>[];
  cursor: string;
  isDone: boolean;
}>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:177

Get a page of items between the given bounds, with a cursor to paginate.
Use `iter` to iterate over all items within the bounds.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      ...<code>
        opts
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOpts
      </code>
      
      <{ <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; <code>
        cursor?
      </code>
      
      : <code>
        string
      </code>
      
      ; <code>
        order?
      </code>
      
      : <code>
        "asc"
      </code>
      
       | <code>
        "desc"
      </code>
      
      ; <code>
        pageSize?
      </code>
      
      : <code>
        number
      </code>
      
      ; <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<{
`page`: `Item`<`T`[`"Key"`], `Id`<`T`[`"TableName"`]>><span>



</span>

;
`cursor`: `string`;
`isDone`: `boolean`;
}>

###### Inherited from

```ts
Aggregate.paginate
```

##### iter()

```ts
iter(ctx, ...opts): AsyncGenerator<Item<T["Key"], Id<T["TableName"]>>, void, undefined>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:196

Example usage:

```ts
for await (const item of aggregate.iter(ctx, bounds)) {
  console.log(item);
}
```

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      ...<code>
        opts
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOpts
      </code>
      
      <{ <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        Id
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "TableName"
      </code>
      
      ]>>; <code>
        order?
      </code>
      
      : <code>
        "asc"
      </code>
      
       | <code>
        "desc"
      </code>
      
      ; <code>
        pageSize?
      </code>
      
      : <code>
        number
      </code>
      
      ; <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`AsyncGenerator`<`Item`<`T`[`"Key"`], `Id`<`T`[`"TableName"`]>>, `void`, `undefined`>

###### Inherited from

```ts
Aggregate.iter
```

##### _insert()

```ts
_insert(
   ctx, 
   namespace, 
   key, 
   id, 
   summand?, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:203

Write operations. See [DirectAggregate](https://github.com/get-convex/aggregate#readme) for docstrings.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        namespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        key
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        Id
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        summand?
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

###### Inherited from

```ts
Aggregate._insert
```

##### _delete()

```ts
_delete(
   ctx, 
   namespace, 
   key, 
   id, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:206

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        namespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        key
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        Id
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

###### Inherited from

```ts
Aggregate._delete
```

##### _replace()

```ts
_replace(
   ctx, 
   currentNamespace, 
   currentKey, 
   newNamespace, 
   newKey, 
   id, 
   summand?, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:209

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        currentNamespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        currentKey
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        newNamespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        newKey
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        Id
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        summand?
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

###### Inherited from

```ts
Aggregate._replace
```

##### _insertIfDoesNotExist()

```ts
_insertIfDoesNotExist(
   ctx, 
   namespace, 
   key, 
   id, 
   summand?, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:212

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        namespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        key
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        Id
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        summand?
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

###### Inherited from

```ts
Aggregate._insertIfDoesNotExist
```

##### _deleteIfExists()

```ts
_deleteIfExists(
   ctx, 
   namespace, 
   key, 
   id, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:215

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        namespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        key
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        Id
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

###### Inherited from

```ts
Aggregate._deleteIfExists
```

##### _replaceOrInsert()

```ts
_replaceOrInsert(
   ctx, 
   currentNamespace, 
   currentKey, 
   newNamespace, 
   newKey, 
   id, 
   summand?, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:218

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        currentNamespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        currentKey
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        newNamespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        newKey
      </code>
    </td>
    
    <td>
      <code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ]
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        Id
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        summand?
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

###### Inherited from

```ts
Aggregate._replaceOrInsert
```

##### clear()

```ts
clear(ctx, ...opts): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:233

(re-)initialize the data structure, removing all items if it exists.

Change the maxNodeSize if provided, otherwise keep it the same.
maxNodeSize is how you tune the data structure's width and depth.
Larger values can reduce write contention but increase read latency.
Default is 16.
Set rootLazy = false to eagerly compute aggregates on the root node, which
improves aggregation latency at the expense of making all writes contend
with each other, so it's only recommended for read-heavy workloads.
Default is true.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      ...<code>
        opts
      </code>
    </td>
    
    <td>
      <code>
        NamespacedOpts
      </code>
      
      <{ <code>
        maxNodeSize?
      </code>
      
      : <code>
        number
      </code>
      
      ; <code>
        rootLazy?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }, <code>
        TableAggregateNamespace
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

###### Inherited from

```ts
Aggregate.clear
```

##### makeRootLazy()

```ts
makeRootLazy(ctx, namespace): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:248

If rootLazy is false (the default is true but it can be set to false by
`clear`), the aggregates data structure writes to a single root node on
every insert/delete/replace, which can cause contention.

If your data structure has frequent writes, you can reduce contention by
calling makeRootLazy, which removes the frequent writes to the root node.
With a lazy root node, updates will only contend with other updates to the
same shard of the tree. The number of shards is determined by maxNodeSize,
so larger maxNodeSize can also help.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        namespace
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateNamespace
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

###### Inherited from

```ts
Aggregate.makeRootLazy
```

##### paginateNamespaces()

```ts
paginateNamespaces(
   ctx, 
   cursor?, 
   pageSize?, 
   stale?
): Promise<{
  page: TableAggregateNamespace<T>[];
  cursor: string;
  isDone: boolean;
}>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:249

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cursor?
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        pageSize?
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stale?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<{
`page`: `TableAggregateNamespace`<`T`><span>



</span>

;
`cursor`: `string`;
`isDone`: `boolean`;
}>

###### Inherited from

```ts
Aggregate.paginateNamespaces
```

##### iterNamespaces()

```ts
iterNamespaces(
   ctx, 
   pageSize?, 
   stale?
): AsyncGenerator<TableAggregateNamespace<T>, void, undefined>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:254

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        pageSize?
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stale?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`AsyncGenerator`<`TableAggregateNamespace`<`T`>, `void`, `undefined`>

###### Inherited from

```ts
Aggregate.iterNamespaces
```

##### clearAll()

```ts
clearAll(ctx, opts?): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:255

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        maxNodeSize?
      </code>
      
      : <code>
        number
      </code>
      
      ; <code>
        rootLazy?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.maxNodeSize?
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.rootLazy?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

###### Inherited from

```ts
Aggregate.clearAll
```

##### makeAllRootsLazy()

```ts
makeAllRootsLazy(ctx): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:259

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

###### Inherited from

```ts
Aggregate.makeAllRootsLazy
```

##### enqueueBatch()

```ts
enqueueBatch(ctx, operations): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:408

Enqueue a batch of writes, to be applied asynchronously by the batch
worker.

Equivalent to calling the individual write methods with `{ async: true }`,
except that the whole batch is sent to the component in a single call.
The operations are applied in the order they are given.

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        operations
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateOperation
      </code>
      
      <<code>
        T
      </code>
      
      ><span>
        
      </span>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

##### insert()

```ts
insert(
   ctx, 
   doc, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:410

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        doc
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateDocument
      </code>
      
      <<code>
        T
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

##### delete()

```ts
delete(
   ctx, 
   doc, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:413

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        doc
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateDocument
      </code>
      
      <<code>
        T
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

##### replace()

```ts
replace(
   ctx, 
   oldDoc, 
   newDoc, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:416

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        oldDoc
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateDocument
      </code>
      
      <<code>
        T
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        newDoc
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateDocument
      </code>
      
      <<code>
        T
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

##### insertIfDoesNotExist()

```ts
insertIfDoesNotExist(
   ctx, 
   doc, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:419

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        doc
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateDocument
      </code>
      
      <<code>
        T
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

##### deleteIfExists()

```ts
deleteIfExists(
   ctx, 
   doc, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:422

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        doc
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateDocument
      </code>
      
      <<code>
        T
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

##### replaceOrInsert()

```ts
replaceOrInsert(
   ctx, 
   oldDoc, 
   newDoc, 
   opts?
): Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:425

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        oldDoc
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateDocument
      </code>
      
      <<code>
        T
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        newDoc
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateDocument
      </code>
      
      <<code>
        T
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`void`>

##### indexOfDoc()

```ts
indexOfDoc(
   ctx, 
   doc, 
   opts?
): Promise<number>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:436

Returns the rank/offset/index of the given document, within the bounds.
This differs from `indexOf` in that it take the document rather than key.
Specifically, it returns the index of the first item with

- key >= the given doc's key if `order` is "asc" (default)
- key <= the given doc's key if `order` is "desc"

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        MutationCtx
      </code>
      
       | <code>
        ActionCtx
      </code>
      
       | <code>
        QueryCtx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        doc
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateDocument
      </code>
      
      <<code>
        T
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        id?
      </code>
      
      : <code>
        TableAggregateId
      </code>
      
      <<code>
        T
      </code>
      
      >; <code>
        bounds?
      </code>
      
      : <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        TableAggregateId
      </code>
      
      <<code>
        T
      </code>
      
      >>; <code>
        order?
      </code>
      
      : <code>
        "asc"
      </code>
      
       | <code>
        "desc"
      </code>
      
      ; <code>
        stale?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.id?
      </code>
    </td>
    
    <td>
      <code>
        TableAggregateId
      </code>
      
      <<code>
        T
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.bounds?
      </code>
    </td>
    
    <td>
      <code>
        Bounds
      </code>
      
      <<code>
        T
      </code>
      
      [<code>
        "Key"
      </code>
      
      ], <code>
        TableAggregateId
      </code>
      
      <<code>
        T
      </code>
      
      >>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.order?
      </code>
    </td>
    
    <td>
      <code>
        "asc"
      </code>
      
       | <code>
        "desc"
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.stale?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`Promise`<`number`>

##### trigger()

```ts
trigger<Ctx>(opts?): TableAggregateTrigger<Ctx, T>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:442

###### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-ctx">
        
      </a>
      
       <code>
        Ctx
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        MutationCtx
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`TableAggregateTrigger`<`Ctx`, `T`>

##### idempotentTrigger()

```ts
idempotentTrigger<Ctx>(opts?): TableAggregateTrigger<Ctx, T>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:445

###### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-ctx-1">
        
      </a>
      
       <code>
        Ctx
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        MutationCtx
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      { <code>
        async?
      </code>
      
      : <code>
        boolean
      </code>
      
      ; }
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts.async?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Returns

`TableAggregateTrigger`<`Ctx`, `T`>

---

### Triggers

Defined in: node_modules/convex-helpers/server/triggers.d.ts:43

Construct Triggers to register functions that run whenever a table changes.
Sample usage:

```text
import { mutation as rawMutation } from "./_generated/server";
import { DataModel } from "./_generated/dataModel";
import { Triggers } from "convex-helpers/server/triggers";
import { customCtx, customMutation } from "convex-helpers/server/customFunctions";

const triggers = new Triggers<DataModel>();
triggers.register("myTableName", async (ctx, change) => {
  console.log("Table changed", change);
});

// Use `mutation` to define all mutations, and the triggers will get called.
export const mutation = customMutation(rawMutation, customCtx(triggers.wrapDB));
```

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
    
    <th>
      Default type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-datamodel-4">
        
      </a>
      
       <code>
        DataModel
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        GenericDataModel
      </code>
    </td>
    
    <td>
      -
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-ctx-3">
        
      </a>
      
       <code>
        Ctx
      </code>
      
       <em>
        extends
      </em>
      
       { <code>
        db
      </code>
      
      : <code>
        GenericDatabaseWriter
      </code>
      
      <<code>
        DataModel
      </code>
      
      >; }
    </td>
    
    <td>
      <code>
        GenericMutationCtx
      </code>
      
      <<code>
        DataModel
      </code>
      
      >
    </td>
  </tr>
</tbody>
</table>

#### Constructors

##### Constructor

```ts
new Triggers<DataModel, Ctx>(): Triggers<DataModel, Ctx>;
```

###### Returns

[`Triggers`](#triggers)<`DataModel`, `Ctx`>

#### Properties

<table>
<thead>
  <tr>
    <th>
      Property
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="registered">
        
      </a>
      
       <code>
        registered
      </code>
    </td>
    
    <td>
      <code>
        { [TableName in string]?: Trigger<Ctx, DataModel, TableName>[] }
      </code>
    </td>
    
    <td>
      node_modules/convex-helpers/server/triggers.d.ts:46
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="wrapdb">
        
      </a>
      
       <code>
        wrapDB
      </code>
    </td>
    
    <td>
      <<code>
        C
      </code>
      
      >(<code>
        ctx
      </code>
      
      ) => <code>
        C
      </code>
    </td>
    
    <td>
      node_modules/convex-helpers/server/triggers.d.ts:50
    </td>
  </tr>
</tbody>
</table>

#### Methods

##### register()

```ts
register<TableName>(tableName, trigger): void;
```

Defined in: node_modules/convex-helpers/server/triggers.d.ts:49

###### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-tablename-3">
        
      </a>
      
       <code>
        TableName
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        string
      </code>
    </td>
  </tr>
</tbody>
</table>

###### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        tableName
      </code>
    </td>
    
    <td>
      <code>
        TableName
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        trigger
      </code>
    </td>
    
    <td>
      <code>
        Trigger
      </code>
      
      <<code>
        Ctx
      </code>
      
      , <code>
        DataModel
      </code>
      
      , <code>
        TableName
      </code>
      
      >
    </td>
  </tr>
</tbody>
</table>

###### Returns

`void`

## Type Aliases

### TableAggregateType

```ts
type TableAggregateType<K, DataModel, TableName, Namespace> = {
  Key: K;
  DataModel: DataModel;
  TableName: TableName;
  Namespace?: Namespace;
};
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:355

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
    
    <th>
      Default type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-k">
        
      </a>
      
       <code>
        K
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        Key
      </code>
    </td>
    
    <td>
      -
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-datamodel">
        
      </a>
      
       <code>
        DataModel
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        GenericDataModel
      </code>
    </td>
    
    <td>
      -
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-tablename">
        
      </a>
      
       <code>
        TableName
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        TableNamesInDataModel
      </code>
      
      <<code>
        DataModel
      </code>
      
      >
    </td>
    
    <td>
      -
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-namespace">
        
      </a>
      
       <code>
        Namespace
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        ConvexValue
      </code>
      
       | <code>
        undefined
      </code>
    </td>
    
    <td>
      <code>
        undefined
      </code>
    </td>
  </tr>
</tbody>
</table>

#### Properties

<table>
<thead>
  <tr>
    <th>
      Property
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="key">
        
      </a>
      
       <code>
        Key
      </code>
    </td>
    
    <td>
      <code>
        K
      </code>
    </td>
    
    <td>
      node_modules/@convex-dev/aggregate/dist/client/index.d.ts:356
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="datamodel">
        
      </a>
      
       <code>
        DataModel
      </code>
    </td>
    
    <td>
      <code>
        DataModel
      </code>
    </td>
    
    <td>
      node_modules/@convex-dev/aggregate/dist/client/index.d.ts:357
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="tablename">
        
      </a>
      
       <code>
        TableName
      </code>
    </td>
    
    <td>
      <code>
        TableName
      </code>
    </td>
    
    <td>
      node_modules/@convex-dev/aggregate/dist/client/index.d.ts:358
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="namespace">
        
      </a>
      
       <code>
        Namespace?
      </code>
    </td>
    
    <td>
      <code>
        Namespace
      </code>
    </td>
    
    <td>
      node_modules/@convex-dev/aggregate/dist/client/index.d.ts:359
    </td>
  </tr>
</tbody>
</table>

---

### Trigger

```ts
type Trigger<Ctx, DataModel, TableName> = (ctx, change) => Promise<void>;
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:449

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-ctx-2">
        
      </a>
      
       <code>
        Ctx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-datamodel-1">
        
      </a>
      
       <code>
        DataModel
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        GenericDataModel
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-tablename-1">
        
      </a>
      
       <code>
        TableName
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        TableNamesInDataModel
      </code>
      
      <<code>
        DataModel
      </code>
      
      >
    </td>
  </tr>
</tbody>
</table>

#### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ctx
      </code>
    </td>
    
    <td>
      <code>
        Ctx
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        change
      </code>
    </td>
    
    <td>
      <a href="#change">
        <code>
          Change
        </code>
      </a>
      
      <<code>
        DataModel
      </code>
      
      , <code>
        TableName
      </code>
      
      >
    </td>
  </tr>
</tbody>
</table>

#### Returns

`Promise`<`void`>

---

### Change

```ts
type Change<DataModel, TableName> = {
  id: GenericId<TableName>;
} & 
  | {
  operation: "insert";
  oldDoc: null;
  newDoc: DocumentByName<DataModel, TableName>;
}
  | {
  operation: "update";
  oldDoc: DocumentByName<DataModel, TableName>;
  newDoc: DocumentByName<DataModel, TableName>;
}
  | {
  operation: "delete";
  oldDoc: DocumentByName<DataModel, TableName>;
  newDoc: null;
};
```

Defined in: node_modules/@convex-dev/aggregate/dist/client/index.d.ts:450

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-datamodel-2">
        
      </a>
      
       <code>
        DataModel
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        GenericDataModel
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-tablename-2">
        
      </a>
      
       <code>
        TableName
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        TableNamesInDataModel
      </code>
      
      <<code>
        DataModel
      </code>
      
      >
    </td>
  </tr>
</tbody>
</table>

#### Type Declaration

<table>
<thead>
  <tr>
    <th>
      Name
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        GenericId
      </code>
      
      <<code>
        TableName
      </code>
      
      >
    </td>
    
    <td>
      node_modules/@convex-dev/aggregate/dist/client/index.d.ts:451
    </td>
  </tr>
</tbody>
</table>

## Functions

### customCtx()

```ts
function customCtx<InCtx, OutCtx, ExtraArgs>(modifyCtx): Customization<InCtx, Record<string, never>, OutCtx, Record<string, never>, ExtraArgs>;
```

Defined in: node_modules/convex-helpers/server/customFunctions.d.ts:114

A helper for defining a Customization when your mod doesn't need to add or remove
anything from args.

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
    
    <th>
      Default type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-inctx">
        
      </a>
      
       <code>
        InCtx
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        Record
      </code>
      
      <<code>
        string
      </code>
      
      , <code>
        any
      </code>
      
      >
    </td>
    
    <td>
      -
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-outctx">
        
      </a>
      
       <code>
        OutCtx
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        Record
      </code>
      
      <<code>
        string
      </code>
      
      , <code>
        any
      </code>
      
      >
    </td>
    
    <td>
      -
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-extraargs">
        
      </a>
      
       <code>
        ExtraArgs
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        Record
      </code>
      
      <<code>
        string
      </code>
      
      , <code>
        any
      </code>
      
      >
    </td>
    
    <td>
      <code>
        Record
      </code>
      
      <<code>
        string
      </code>
      
      , <code>
        any
      </code>
      
      >
    </td>
  </tr>
</tbody>
</table>

#### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        modifyCtx
      </code>
    </td>
    
    <td>
      (<code>
        original
      </code>
      
      , <code>
        extra
      </code>
      
      ) => <code>
        OutCtx
      </code>
      
       | <code>
        Promise
      </code>
      
      <<code>
        OutCtx
      </code>
      
      >
    </td>
    
    <td>
      A function that defines how to modify the ctx.
    </td>
  </tr>
</tbody>
</table>

#### Returns

`Customization`<`InCtx`, `Record`<`string`, `never`>, `OutCtx`, `Record`<`string`, `never`>, `ExtraArgs`>

A ctx delta to be applied to the original ctx.

---

### customMutation()

```ts
function customMutation<CustomArgsValidator, CustomCtx, CustomMadeArgs, Visibility, DataModel, ExtraArgs>(mutation, customization): CustomBuilder<"mutation", CustomArgsValidator, CustomCtx, CustomMadeArgs, GenericMutationCtx<DataModel>, Visibility, ExtraArgs>;
```

Defined in: node_modules/convex-helpers/server/customFunctions.d.ts:246

customMutation helps define custom behavior on top of `mutation`
or `internalMutation` by passing a function that modifies the ctx and args.

Example usage:

```js
const myMutationBuilder = customMutation(mutation, {
  args: { sessionId: v.id("sessions") },
  input: async (ctx, args) => {
    const user = await getUserOrNull(ctx);
    const session = await db.get(sessionId);
    const db = wrapDatabaseReader({ user }, ctx.db, rlsRules);
    return {
      ctx: { db, user, session },
      args: {},
      onSuccess: ({ result }) => {
        // Optional callback that runs after the function executes
        // Has access to resources created during input processing
        console.log(`User ${user.name} returned:`, result);
      }
    };
  },
});

// Using the custom builder
export const setSomeData = myMutationBuilder({
  args: { someArg: v.string() },
  handler: async (ctx, args) => {
    const { db, user, session, scheduler } = ctx;
    const { someArg } = args;
    // ...
  }
});
```

Simple usage only modifying ctx:

```js
const myUserMutation = customMutation(
  mutation,
  customCtx(async (ctx) => {
    return {
      // Throws an exception if the user isn't logged in
      user: await getUserByTokenIdentifier(ctx),
    };
  })
);

// Using it
export const setMyName = myUserMutation({
  args: { name: v.string() },
  handler: async (ctx, args) => {
    await ctx.db.patch(ctx.user._id, { name: args.name });
  },
});

@param mutation The mutation to be modified. Usually `mutation` or `internalMutation`
  from `_generated/server`.
@param customization The modifier to be applied to the mutation, changing ctx and args.
@returns A new mutation builder to define queries with modified ctx and args.

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| <a id="type-parameter-customargsvalidator"></a> `CustomArgsValidator` *extends* `PropertyValidators` | - |
| <a id="type-parameter-customctx"></a> `CustomCtx` *extends* `Record`\<`string`, `any`\> | - |
| <a id="type-parameter-custommadeargs"></a> `CustomMadeArgs` *extends* `Record`\<`string`, `any`\> | - |
| <a id="type-parameter-visibility"></a> `Visibility` *extends* `FunctionVisibility` | - |
| <a id="type-parameter-datamodel-3"></a> `DataModel` *extends* `GenericDataModel` | - |
| <a id="type-parameter-extraargs-1"></a> `ExtraArgs` *extends* `Record`\<`string`, `any`\> | `object` |

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `mutation` | `MutationBuilder`\<`DataModel`, `Visibility`\> |
| `customization` | `Customization`\<`GenericMutationCtx`\<`DataModel`\>, `CustomArgsValidator`, `CustomCtx`, `CustomMadeArgs`, `ExtraArgs`\> |

#### Returns

`CustomBuilder`\<`"mutation"`, `CustomArgsValidator`, `CustomCtx`, `CustomMadeArgs`, `GenericMutationCtx`\<`DataModel`\>, `Visibility`, `ExtraArgs`\>

***

### withTriggers()

```ts
function withTriggers<DataModel, Visibility>(rawMutation, triggers): CustomBuilder<"mutation", Record<string, never>, GenericMutationCtx<DataModel>, Record<string, never>, GenericMutationCtx<DataModel>, Visibility, Record<string, any>>;
```

Defined in: [src/convex/integrations/aggregate.ts](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/aggregate.ts)

Wrap a raw `mutation`/`internalMutation` builder so every write
automatically fires the registered [Triggers](#triggers) (e.g. to keep a
`TableAggregate` in sync) — no manual `insert`/`delete`/`replace` calls.

#### Type Parameters

<table>
<thead>
  <tr>
    <th>
      Type Parameter
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="type-parameter-datamodel-5">
        
      </a>
      
       <code>
        DataModel
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        GenericDataModel
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="type-parameter-visibility-1">
        
      </a>
      
       <code>
        Visibility
      </code>
      
       <em>
        extends
      </em>
      
       <code>
        FunctionVisibility
      </code>
    </td>
  </tr>
</tbody>
</table>

#### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        rawMutation
      </code>
    </td>
    
    <td>
      <code>
        MutationBuilder
      </code>
      
      <<code>
        DataModel
      </code>
      
      , <code>
        Visibility
      </code>
      
      >
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        triggers
      </code>
    </td>
    
    <td>
      <a href="#triggers">
        <code>
          Triggers
        </code>
      </a>
      
      <<code>
        DataModel
      </code>
      
      >
    </td>
  </tr>
</tbody>
</table>

#### Returns

`CustomBuilder`<`"mutation"`, `Record`<`string`, `never`>, `GenericMutationCtx`<`DataModel`>, `Record`<`string`, `never`>, `GenericMutationCtx`<`DataModel`>, `Visibility`, `Record`<`string`, `any`>>

#### Example

```ts
import { TableAggregate, Triggers, withTriggers } from 'nuxt-backend/aggregate'
import { components } from './_generated/api'
import { mutation as rawMutation } from './_generated/server'
import type { DataModel } from './_generated/dataModel'

export const messagesCount = new TableAggregate<{ Key: null, DataModel: DataModel, TableName: 'messages' }>(
  components.messagesCount,
  { sortKey: () => null },
)

const triggers = new Triggers<DataModel>()
triggers.register('messages', messagesCount.trigger())

export const mutation = withTriggers(rawMutation, triggers)
```


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
