@codenameryuu/adonis-lucid-filter 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +22 -35
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,18 +1,12 @@
1
1
  # @codenameryuu/adonis-lucid-filter
2
2
 
3
- > Works with Adonis JS V7
4
-
5
- [![npm-image]][npm-url] [![license-image]][license-url] [![typescript-image]][typescript-url]
6
-
7
- This addon adds the functionality to filter Lucid Models
8
-
9
- > Inspired by [EloquentFilter](https://github.com/Tucker-Eric/EloquentFilter)
3
+ This addon adds the functionality to filter Lucid Models Adonis JS 7. Inspired by [EloquentFilter](https://github.com/Tucker-Eric/EloquentFilter)
10
4
 
11
5
  ## Introduction
12
6
 
13
7
  Example, we want to return a list of users filtered by multiple parameters. When we navigate to:
14
8
 
15
- `/users?name=Tony&lastName=&companyId=2&industry=5`
9
+ `/users?name=Tony&lastName=&companyId=2&industry=5`
16
10
 
17
11
  `request.all()` or `request.qs()` will return:
18
12
 
@@ -27,7 +21,7 @@ Example, we want to return a list of users filtered by multiple parameters. When
27
21
 
28
22
  To filter by all those parameters we would need to do something like:
29
23
 
30
- ```ts
24
+ ```typescript
31
25
  import type { HttpContext } from '@adonisjs/core/http'
32
26
  import User from '#models/user'
33
27
 
@@ -52,7 +46,7 @@ export default class UsersController {
52
46
 
53
47
  To filter that same input with Lucid Filters:
54
48
 
55
- ```ts
49
+ ```typescript
56
50
  import type { HttpContext } from '@adonisjs/core/http'
57
51
  import User from '#models/user'
58
52
 
@@ -65,13 +59,13 @@ export default class UsersController {
65
59
 
66
60
  ## Installation
67
61
 
68
- - Install the package
62
+ * Install the package
69
63
 
70
64
  ```bash
71
65
  yarn add @codenameryuu/adonis-lucid-filter
72
66
  ```
73
67
 
74
- - Configure the package
68
+ * Configure the package
75
69
 
76
70
  ```bash
77
71
  node ace configure @codenameryuu/adonis-lucid-filter
@@ -79,9 +73,9 @@ node ace configure @codenameryuu/adonis-lucid-filter
79
73
 
80
74
  ## Usage
81
75
 
82
- - Register the provider and commands inside `adonisrc.ts` file.
76
+ * Register the provider and commands inside `adonisrc.ts` file.
83
77
 
84
- ```ts
78
+ ```typescript
85
79
  providers: [
86
80
  // ...
87
81
  () => import('@codenameryuu/adonis-lucid-filter/provider'),
@@ -108,13 +102,13 @@ Where `user` is the Lucid Model you are creating the filter for. This will creat
108
102
 
109
103
  Define the filter logic based on the camel cased input key passed to the `filter()` method.
110
104
 
111
- - Empty strings are ignored
112
- - `setup()` will be called regardless of input
113
- - `_id` is dropped from the end of the input to define the method so filtering `user_id` would use the `user()` method
114
- - Input without a corresponding filter method are ignored
115
- - The value of the key is injected into the method
116
- - All values are accessible through the `this.$input` a property
117
- - All QueryBuilder methods are accessible in `this.$query` object in the model filter class.
105
+ * Empty strings are ignored
106
+ * `setup()` will be called regardless of input
107
+ * `_id` is dropped from the end of the input to define the method so filtering `user_id` would use the `user()` method
108
+ * Input without a corresponding filter method are ignored
109
+ * The value of the key is injected into the method
110
+ * All values are accessible through the `this.$input` a property
111
+ * All QueryBuilder methods are accessible in `this.$query` object in the model filter class.
118
112
 
119
113
  To define methods for the following input:
120
114
 
@@ -128,7 +122,7 @@ To define methods for the following input:
128
122
 
129
123
  You would use the following methods:
130
124
 
131
- ```ts
125
+ ```typescript
132
126
  import { BaseModelFilter } from 'adonis-lucid-filter'
133
127
  import type { ModelQueryBuilderContract } from '@adonisjs/lucid/types/model'
134
128
  import User from '#models/user'
@@ -168,7 +162,7 @@ The `whitelistMethod()` methods can be used to dynamically blacklist methods.
168
162
 
169
163
  Example:
170
164
 
171
- ```ts
165
+ ```typescript
172
166
  setup($query) {
173
167
  this.whitelistMethod('secretMethod')
174
168
  this.$query.where('is_admin', true)
@@ -184,7 +178,7 @@ In order to call this method it would need to be whitelisted dynamically:
184
178
 
185
179
  #### Static properties
186
180
 
187
- ```ts
181
+ ```typescript
188
182
  export default class UserFilter extends BaseModelFilter {
189
183
  // Blacklisted methods
190
184
  static blacklist: string[] = []
@@ -202,7 +196,7 @@ export default class UserFilter extends BaseModelFilter {
202
196
 
203
197
  ### Applying The Filter To A Model
204
198
 
205
- ```ts
199
+ ```typescript
206
200
  import UserFilter from '#models/filters/user_filter'
207
201
  import { compose } from '@adonisjs/core/helpers'
208
202
  import { Filterable } from 'adonis-lucid-filter'
@@ -216,7 +210,7 @@ export default class User extends compose(BaseModel, Filterable) {
216
210
 
217
211
  This gives you access to the `filter()` method that accepts an object of input:
218
212
 
219
- ```ts
213
+ ```typescript
220
214
  import type { HttpContext } from '@adonisjs/core/http'
221
215
  import User from '#models/user'
222
216
 
@@ -239,7 +233,7 @@ export default class UsersController {
239
233
  You can define the filter dynamically by passing the filter to use as the second parameter of the filter() method.
240
234
  Defining a filter dynamically will take precedent over any other filters defined for the model.
241
235
 
242
- ```ts
236
+ ```typescript
243
237
  import type { HttpContext } from '@adonisjs/core/http'
244
238
  import AdminFilter from '#models/filters/admin_filter'
245
239
  import UserFilter from '#models/filters/user_filter'
@@ -256,7 +250,7 @@ export default class UsersController {
256
250
 
257
251
  For filtering relations of model may be use `.query().filter()` or scope `filtration` , example:
258
252
 
259
- ```ts
253
+ ```typescript
260
254
  import type { HttpContext } from '@adonisjs/core/http'
261
255
  import User from '#models/user'
262
256
 
@@ -284,10 +278,3 @@ export default class UserPostsController {
284
278
  Documentation by [Query Scopes](https://lucid.adonisjs.com/docs/model-query-scopes)
285
279
 
286
280
  **Note:** The relation model must be `Filterable` and `$filter` must be defined in it
287
-
288
- [npm-image]: https://img.shields.io/npm/v/adonis-lucid-filter?logo=npm&style=for-the-badge
289
- [npm-url]: https://www.npmjs.com/package/adonis-lucid-filter
290
- [license-image]: https://img.shields.io/npm/l/adonis-lucid-filter?style=for-the-badge&color=blueviolet
291
- [license-url]: https://github.com/lookinlab/adonis-lucid-filter/blob/develop/LICENSE.md
292
- [typescript-image]: https://img.shields.io/npm/types/adonis-lucid-filter?color=294E80&label=%20&logo=typescript&style=for-the-badge
293
- [typescript-url]: https://github.com/lookinlab
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codenameryuu/adonis-lucid-filter",
3
3
  "description": "Addon for filtering Adonis JS 7 Lucid ORM",
4
- "version": "2.6.0",
4
+ "version": "2.7.0",
5
5
  "author": "codenameryuu",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/codenameryuu/adonis-lucid-filter#readme",