Skip to content

Commit b1da688

Browse files
committed
refactor: update docblocks
1 parent da9ffa4 commit b1da688

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/base_transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { RuntimeException } from '@poppinss/exception'
1111

1212
import { Maybe } from './maybe.ts'
1313
import { Item } from './resource/item.ts'
14-
import { Collection } from './resource/collection.ts'
1514
import { Paginator } from './paginator.ts'
15+
import { Collection } from './resource/collection.ts'
1616

1717
/**
1818
* Serves as the base for creating custom data transformers.

src/paginator.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,40 @@ export class Paginator<
6464
protected metaData: MetaData
6565
) {}
6666

67+
/**
68+
* Sets a new data property name for the paginated result
69+
*
70+
* @param dataProp - The new property name for the data array
71+
*
72+
* @example
73+
* ```ts
74+
* const paginator = new Paginator(collection, 'data', { page: 1 })
75+
* const newPaginator = paginator.setDataProp('users')
76+
* // Result will have 'users' instead of 'data' as the key
77+
* ```
78+
*/
6779
setDataProp<Value extends string>(
6880
dataProp: Value
6981
): Paginator<PaginatorCollection, Value, MetaData> {
7082
return new Paginator(this.collection, dataProp, this.metaData)
7183
}
7284

85+
/**
86+
* Updates the pagination metadata with new values
87+
*
88+
* @param metaData - New metadata object or a function that receives current metadata and returns new metadata
89+
*
90+
* @example
91+
* ```ts
92+
* const paginator = new Paginator(collection, 'data', { page: 1, total: 100 })
93+
*
94+
* // Set new metadata
95+
* const updated = paginator.setMetaData({ page: 2, total: 150, hasMore: true })
96+
*
97+
* // Update existing metadata
98+
* const incremented = paginator.setMetaData(meta => ({ ...meta, page: meta.page + 1 }))
99+
* ```
100+
*/
73101
setMetaData<Value extends Record<string, any>>(
74102
metaData: Value | ((data: MetaData) => Value)
75103
): Paginator<PaginatorCollection, DataProp, Value> {

src/serialize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
* file that was distributed with this source code.
88
*/
99

10+
import { RuntimeException } from '@poppinss/exception'
1011
import { Container, type ContainerResolver } from '@adonisjs/fold'
1112

1213
import { Item } from './resource/item.ts'
1314
import { Paginator } from './paginator.ts'
1415
import { serializeValues } from './utils.ts'
1516
import { Collection } from './resource/collection.ts'
1617
import type { ResourceDataTypes, SerializeFn } from './types.ts'
17-
import { RuntimeException } from '@poppinss/exception'
1818

1919
/**
2020
* Main serialization function that converts transformer data into plain JavaScript objects.

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import type { ContainerResolver } from '@adonisjs/fold'
1212

1313
import { debug } from './debug.ts'
1414
import { Item } from './resource/item.ts'
15+
import { Paginator } from './paginator.ts'
1516
import { Collection } from './resource/collection.ts'
1617
import type { JSONDataTypes, ResourceData } from './types.ts'
17-
import { Paginator } from './paginator.ts'
1818

1919
/**
2020
* Checks if value is an object excluding Arrays and null values

0 commit comments

Comments
 (0)