The transformer class used to transform each item
The maximum depth for nested resource resolution
The variant method name to use for transformation
class UserTransformer extends BaseTransformer<User> {
toObject() {
return {
id: this.resource.id,
name: this.resource.name
}
}
}
const paginator = UserTransformer.paginate(
users,
{ page: 1, perPage: 10, total: 100 }
)
const result = await serializer.serialize(paginator)
// Result: { data: [...], metadata: { page: 1, perPage: 10, total: 100 } }
Creates a new Paginator instance. This constructor is typically not called directly.
Use BaseTransformer.paginate() instead.
The transformer class used to transform each item
The maximum depth for nested resource resolution
The variant method name to use for transformation
class UserTransformer extends BaseTransformer<User> {
toObject() {
return {
id: this.resource.id,
name: this.resource.name
}
}
}
const paginator = UserTransformer.paginate(
users,
{ page: 1, perPage: 10, total: 100 }
)
const result = await serializer.serialize(paginator)
// Result: { data: [...], metadata: { page: 1, perPage: 10, total: 100 } }
The collection of transformed data to paginate
Pagination metadata (page, perPage, total, etc.)
Type identifier for the paginator instance, used for runtime type discrimination.
The collection of transformed data to paginate
Pagination metadata (page, perPage, total, etc.)
Specify the maximum depth of nested relationships to be resolved when serializing the paginated collection.
This is useful to prevent infinite recursion or to limit the amount of data fetched for deeply nested relationships. Relationships beyond this depth will be excluded from the serialized output.
Maximum depth level for nested transformations (valid values: 1, 2, 3, 4, 5, or 6)
Specify which transformer variant method to use for serialization.
Transformers can define multiple methods (variants) for different representations of the same data (e.g., toObject, toSummary, toDetailed). This method allows you to choose which variant to use for this paginated collection.
Name of the transformer variant method to use (must be a method name that
returns ResourceData or Promise
// Use default toObject variant
const users = UserTransformer.paginate(userData, { page: 1, total: 100 })
// Use custom toSummary variant for lighter payload
const userSummaries = UserTransformer.paginate(userData, { page: 1, total: 100 })
.useVariant('toSummary')
// Use detailed variant for admin view
const detailedUsers = UserTransformer.paginate(userData, { page: 1, total: 100 })
.useVariant('toDetailed')
Resolves the paginated data by combining the serialized collection with pagination metadata. This method is typically called internally by the serializer function.
Container resolver for dependency injection
Current depth level in the transformation tree
OptionalmaxDepth: number
Optional maximum depth override
Represents paginated data that combines a collection of transformed items with pagination metadata. This class is typically created using the
BaseTransformer.paginate()method.