Skip to content

Commit 9c11bfa

Browse files
Boris AbramovBoris Abramov
authored andcommitted
Update documentation
1 parent 47a5dd0 commit 9c11bfa

2 files changed

Lines changed: 37 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
# Change Log
33
All notable changes to this project will be documented in this file.
44

5+
## [2.0.7] - 2025-08-05
6+
7+
### Added
8+
- Introduced updated method interfaces to align with new AdonisJS best practices (existing methods remain available for backward compatibility)
9+
- Code refactored
10+
- paginate() will now throw an error if called with anything other than an array of objects
11+
512
## [2.0.5] - 2025-07-19
613

714
### Added

README.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Description
66

7-
Provides a transformation layer between models and actual API endpont responses in JSON format.
7+
Provides a transformation layer between a model and the actual API endpoint response in JSON format.
88

99
## Setup
1010

@@ -20,35 +20,35 @@ Configure the package:
2020
node ace configure adonis-api-resources
2121
```
2222

23-
Generate a new resource (i.e. for a user):
23+
Generate a new resource (e.g., for a `User` model):
2424

2525
```sh
2626
node ace make:resource user
2727
```
2828

29-
Import your generated resource before using it, i.e. in a controller:
29+
Import the generated resource before using it, for example in a controller:
3030

3131
```typescript
3232
import UserResource from '#resources/user_resource'
3333
```
3434

35-
Remove old endpoint return declaration:
35+
Remove the old endpoint return declaration:
3636

3737
```typescript
3838
return user
3939
```
4040

41-
Use the your generated resource instead:
41+
Use the generated resource instead:
4242

4343
```typescript
44-
return new UserResource(user).refine()
44+
return new UserResource(user).remap()
4545
```
4646

47-
## redefine() and refine() - manually defined map
47+
## remap() - manually defined map
4848

49-
redefine() modifies a model or array of models according to your custom map defined in resource file. Used along with get() method, which indicates that data processing is done and provides the result. You can also use refine(), which is an alias of redefine().get(), see example below.
49+
`remap()` modifies a model or an array of models according to the custom map defined in the resource file.
5050

51-
Edit newly generated app/resources/user_resource.ts to create output you need. This example shows how you may output user's full name even if your implementation of user model has separate fields for the first and last names:
51+
Edit the newly generated `app/resources/user_resource.ts` file to produce the output you need. This example shows how you can output the user's full name, even if your `User` model has separate fields for the first and last names.
5252

5353
```typescript
5454
...
@@ -58,10 +58,10 @@ Edit newly generated app/resources/user_resource.ts to create output you need. T
5858
...
5959
```
6060

61-
You may also use arrays of models with resources:
61+
You can also use arrays of models with resources:
6262

6363
```typescript
64-
return new UserResource(users).refine()
64+
return new UserResource(users).remap()
6565
```
6666

6767
### Output examples
@@ -87,41 +87,42 @@ Array of models:
8787
]
8888
```
8989

90-
## paginate() and refinePaginate()
90+
## pick()
91+
92+
No map definition is needed if you only want to pick a few values from the object and leave the rest out.
9193

92-
In case you are dealing with not paginateable array you can still create pagination using this extension. refinePaginate() is an alias of redefine().paginate(), see examples below:
94+
Example:
9395

9496
```typescript
95-
return new UserResource(users).refinePaginate(page, limit)
96-
return new UserResource(users).redefine().paginate(page, limit)
97+
return new UserResource(users).pick('email', 'firstName', 'lastName')
9798
```
9899

99-
Arguments:
100+
## omit()
100101

101-
page - number of page to show (optional, default value: 1)<br />
102-
limit - items per page (optional, default value: 10)
102+
No map definition is needed if you only want to exclude a few values from the object.
103103

104-
## pick()
105-
106-
No map definition is needed, once you only want to pick a few values of the object and leave other values behind. Examples:
104+
Example:
107105

108106
```typescript
109-
return new UserResource(users).pick('firstName').get()
110-
return new UserResource(users).pick('firstName', 'lastName', 'email').paginate(1, 20)
107+
return new UserResource(users).omit('createdAt', 'updatedAt')
111108
```
112109

113-
## omit()
110+
## paginate()
111+
112+
If you are dealing with a non-paginated array, you can still create pagination using this extension.
114113

115-
No map definition is needed, once you only want to exclude a few values from the object. Examples:
114+
See examples below:
116115

117116
```typescript
118-
return new UserResource(users).omit('id').paginate()
119-
return new UserResource(users).omit('createdAt', 'updatedAt').get()
117+
return new UserResource(users).remap().paginate(page, limit)
118+
return new UserResource(users).pick('email', 'firstName', 'lastName').paginate(page)
119+
return new UserResource(users).omit('id', 'password').paginate()
120120
```
121121

122-
## get()
122+
### Arguments
123123

124-
get() finalizes data processing. While pick(), omit() and redefine() modify data, trailing get() or paginate() is needed to complete the response. This requirement is not applied to refine() and refinePaginate()
124+
- **page** — Number of the page to show (optional, default: 1)
125+
- **limit** — Items per page (optional, default: 10)
125126

126127
## Pagination support
127128

0 commit comments

Comments
 (0)