@codenameryuu/adonis-lucid-filter 2.0.0 → 2.1.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.
- package/LICENSE.md +9 -9
- package/README.md +315 -312
- package/build/{chunk-FZT5JNRL.js → chunk-V7FYZD4D.js} +1 -1
- package/build/chunk-V7FYZD4D.js.map +1 -0
- package/build/{chunk-NBGNVIUM.js → chunk-WD7GE7Y7.js} +1 -1
- package/build/chunk-WD7GE7Y7.js.map +1 -0
- package/build/commands/make_filter.js +1 -1
- package/build/commands/make_filter.js.map +1 -1
- package/build/index.js +3 -3
- package/build/index.js.map +1 -1
- package/build/providers/lucid_filter_provider.js +1 -1
- package/build/providers/lucid_filter_provider.js.map +1 -1
- package/build/src/bindings/model_query_builder.js +1 -1
- package/package.json +134 -134
- package/build/chunk-FZT5JNRL.js.map +0 -1
- package/build/chunk-NBGNVIUM.js.map +0 -1
package/LICENSE.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# The MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Lookin Anton
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
# The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Lookin Anton
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,312 +1,315 @@
|
|
|
1
|
-
# Adonis Lucid Filter
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
| ^
|
|
18
|
-
| ^
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
- Docs [for
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
query.where(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
import
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
npm
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
yarn
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
pnpm
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
-
|
|
134
|
-
-
|
|
135
|
-
-
|
|
136
|
-
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
//
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
// Doing this would allow you to have a
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
[
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
[
|
|
312
|
-
[
|
|
1
|
+
# Adonis Lucid Filter
|
|
2
|
+
|
|
3
|
+
> Works with AdonisJS v6
|
|
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)
|
|
10
|
+
|
|
11
|
+
## Versions
|
|
12
|
+
|
|
13
|
+
> **Note**: Check before install :point_down:
|
|
14
|
+
|
|
15
|
+
| adonis-lucid-filter | @adonisjs/lucid |
|
|
16
|
+
| ------------------------------------ | --------------- |
|
|
17
|
+
| ^5.\*.\* | ^20.\*.\* |
|
|
18
|
+
| ^4.\*.\* | <=18.\*.\* |
|
|
19
|
+
| ^3.\*.\* (`@filterable()` decorator) | ^15.\*.\* |
|
|
20
|
+
| ^2.\*.\* | 14.\*.\* |
|
|
21
|
+
|
|
22
|
+
- Docs [for **Adonis v5**](https://github.com/lookinlab/adonis-lucid-filter/tree/v4)
|
|
23
|
+
- Docs [for **Adonis v4**](https://github.com/lookinlab/adonis-lucid-filter/tree/v1)
|
|
24
|
+
- Docs [for `@filterable()` decorator](https://github.com/lookinlab/adonis-lucid-filter/tree/v3)
|
|
25
|
+
|
|
26
|
+
## Introduction
|
|
27
|
+
|
|
28
|
+
Example, we want to return a list of users filtered by multiple parameters. When we navigate to:
|
|
29
|
+
|
|
30
|
+
`/users?name=Tony&lastName=&companyId=2&industry=5`
|
|
31
|
+
|
|
32
|
+
`request.all()` or `request.qs()` will return:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"name": "Tony",
|
|
37
|
+
"lastName": "",
|
|
38
|
+
"companyId": 2,
|
|
39
|
+
"industry": 5
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
To filter by all those parameters we would need to do something like:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import type { HttpContext } from '@adonisjs/core/http'
|
|
47
|
+
import User from '#models/user'
|
|
48
|
+
|
|
49
|
+
export default class UsersController {
|
|
50
|
+
async index({ request }: HttpContext): Promise<User[]> {
|
|
51
|
+
const { companyId, lastName, name, industry } = request.qs()
|
|
52
|
+
|
|
53
|
+
const query = User.query().where('company_id', +companyId)
|
|
54
|
+
|
|
55
|
+
if (lastName) {
|
|
56
|
+
query.where('last_name', 'LIKE', `%${lastName}%`)
|
|
57
|
+
}
|
|
58
|
+
if (name) {
|
|
59
|
+
query.where(function () {
|
|
60
|
+
this.where('first_name', 'LIKE', `%${name}%`).orWhere('last_name', 'LIKE', `%${name}%`)
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
return query.exec()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
To filter that same input with Lucid Filters:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import type { HttpContext } from '@adonisjs/core/http'
|
|
72
|
+
import User from '#models/user'
|
|
73
|
+
|
|
74
|
+
export default class UsersController {
|
|
75
|
+
async index({ request }: HttpContext): Promise<User[]> {
|
|
76
|
+
return User.filter(request.qs()).exec()
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Installation
|
|
82
|
+
|
|
83
|
+
Make sure to install it using `npm`, `yarn` or `pnpm`.
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# npm
|
|
87
|
+
npm i adonis-lucid-filter
|
|
88
|
+
|
|
89
|
+
# yarn
|
|
90
|
+
yarn add adonis-lucid-filter
|
|
91
|
+
|
|
92
|
+
# pnpm
|
|
93
|
+
pnpm add adonis-lucid-filter
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
After install call `configure`:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
node ace configure adonis-lucid-filter
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Usage
|
|
103
|
+
|
|
104
|
+
Make sure to register the provider and commands inside `adonisrc.ts` file.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
providers: [
|
|
108
|
+
// ...
|
|
109
|
+
() => import('adonis-lucid-filter/provider'),
|
|
110
|
+
],
|
|
111
|
+
commands: [
|
|
112
|
+
// ...
|
|
113
|
+
() => import('adonis-lucid-filter/commands')
|
|
114
|
+
]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Generating The Filter
|
|
118
|
+
|
|
119
|
+
> Only available if you have added `adonis-lucid-filter/commands` in `commands` array in your `adonisrc.ts'
|
|
120
|
+
|
|
121
|
+
You can create a model filter with the following ace command:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
node ace make:filter user
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Where `user` is the Lucid Model you are creating the filter for. This will create `app/models/filters/user_filter.js`
|
|
128
|
+
|
|
129
|
+
### Defining The Filter Logic
|
|
130
|
+
|
|
131
|
+
Define the filter logic based on the camel cased input key passed to the `filter()` method.
|
|
132
|
+
|
|
133
|
+
- Empty strings are ignored
|
|
134
|
+
- `setup()` will be called regardless of input
|
|
135
|
+
- `_id` is dropped from the end of the input to define the method so filtering `user_id` would use the `user()` method
|
|
136
|
+
- Input without a corresponding filter method are ignored
|
|
137
|
+
- The value of the key is injected into the method
|
|
138
|
+
- All values are accessible through the `this.$input` a property
|
|
139
|
+
- All QueryBuilder methods are accessible in `this.$query` object in the model filter class.
|
|
140
|
+
|
|
141
|
+
To define methods for the following input:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"companyId": 5,
|
|
146
|
+
"name": "Tony",
|
|
147
|
+
"mobilePhone": "888555"
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
You would use the following methods:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { BaseModelFilter } from 'adonis-lucid-filter'
|
|
155
|
+
import type { ModelQueryBuilderContract } from '@adonisjs/lucid/types/model'
|
|
156
|
+
import User from '#models/user'
|
|
157
|
+
|
|
158
|
+
export default class UserFilter extends BaseModelFilter {
|
|
159
|
+
declare $query: ModelQueryBuilderContract<typeof User>
|
|
160
|
+
|
|
161
|
+
static blacklist: string[] = ['secretMethod']
|
|
162
|
+
|
|
163
|
+
// This will filter 'companyId', 'company_id' OR 'company'
|
|
164
|
+
company(id: number) {
|
|
165
|
+
this.$query.where('company_id', id)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
name(name: string) {
|
|
169
|
+
this.$query.where((builder) => {
|
|
170
|
+
builder.where('first_name', 'LIKE', `%${name}%`).orWhere('last_name', 'LIKE', `%${name}%`)
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
mobilePhone(phone: string) {
|
|
175
|
+
this.$query.where('mobile_phone', 'LIKE', `${phone}%`)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
secretMethod(secretParameter: any) {
|
|
179
|
+
this.$query.where('some_column', true)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### Blacklist
|
|
185
|
+
|
|
186
|
+
Any methods defined in the `blacklist` array will not be called by the filter.
|
|
187
|
+
Those methods are normally used for internal filter logic.
|
|
188
|
+
|
|
189
|
+
The `whitelistMethod()` methods can be used to dynamically blacklist methods.
|
|
190
|
+
|
|
191
|
+
Example:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
setup($query) {
|
|
195
|
+
this.whitelistMethod('secretMethod')
|
|
196
|
+
this.$query.where('is_admin', true)
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
> `setup()` not may be async
|
|
201
|
+
|
|
202
|
+
> **Note:** All methods inside `setup()` will be called every time `filter()` is called on the model
|
|
203
|
+
|
|
204
|
+
In the example above `secretMethod()` will not be called, even if there is a `secret_method` key in the input object.
|
|
205
|
+
In order to call this method it would need to be whitelisted dynamically:
|
|
206
|
+
|
|
207
|
+
#### Static properties
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
export default class UserFilter extends BaseModelFilter {
|
|
211
|
+
// Blacklisted methods
|
|
212
|
+
static blacklist: string[] = []
|
|
213
|
+
|
|
214
|
+
// Dropped `_id` from the end of the input
|
|
215
|
+
// Doing this would allow you to have a `company()` filter method as well as a `companyId()` filter method.
|
|
216
|
+
static dropId: boolean = true
|
|
217
|
+
|
|
218
|
+
// Doing this would allow you to have a mobile_phone() filter method instead of mobilePhone().
|
|
219
|
+
// By default, mobilePhone() filter method can be called thanks to one of the following input key:
|
|
220
|
+
// mobile_phone, mobilePhone, mobile_phone_id, mobilePhoneId
|
|
221
|
+
static camelCase: boolean = true
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Applying The Filter To A Model
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import UserFilter from '#models/filters/user_filter'
|
|
229
|
+
import { compose } from '@adonisjs/core/helpers'
|
|
230
|
+
import { Filterable } from 'adonis-lucid-filter'
|
|
231
|
+
|
|
232
|
+
export default class User extends compose(BaseModel, Filterable) {
|
|
233
|
+
static $filter = () => UserFilter
|
|
234
|
+
|
|
235
|
+
// ...columns and props
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
This gives you access to the `filter()` method that accepts an object of input:
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
import type { HttpContext } from '@adonisjs/core/http'
|
|
243
|
+
import User from '#models/user'
|
|
244
|
+
|
|
245
|
+
export default class UsersController {
|
|
246
|
+
async index({ request }: HttpContext): Promise<User[]> {
|
|
247
|
+
return User.filter(request.qs()).exec()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// or with paginate method
|
|
251
|
+
|
|
252
|
+
async index({ request }: HttpContext): Promise<ModelPaginatorContract<User>> {
|
|
253
|
+
const { page = 1, ...input } = request.qs()
|
|
254
|
+
return User.filter(input).paginate(page, 15)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Dynamic Filters
|
|
260
|
+
|
|
261
|
+
You can define the filter dynamically by passing the filter to use as the second parameter of the filter() method.
|
|
262
|
+
Defining a filter dynamically will take precedent over any other filters defined for the model.
|
|
263
|
+
|
|
264
|
+
```ts
|
|
265
|
+
import type { HttpContext } from '@adonisjs/core/http'
|
|
266
|
+
import AdminFilter from '#models/filters/admin_filter'
|
|
267
|
+
import UserFilter from '#models/filters/user_filter'
|
|
268
|
+
|
|
269
|
+
export default class UsersController {
|
|
270
|
+
async index({ request, auth }: HttpContext): Promise<User[]> {
|
|
271
|
+
const filter = auth.user.isAdmin() ? AdminFilter : UserFilter
|
|
272
|
+
return User.filter(request.qs(), filter).exec()
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Filtering relations
|
|
278
|
+
|
|
279
|
+
For filtering relations of model may be use `.query().filter()` or scope `filtration`, example:
|
|
280
|
+
|
|
281
|
+
```ts
|
|
282
|
+
import type { HttpContext } from '@adonisjs/core/http'
|
|
283
|
+
import User from '#models/user'
|
|
284
|
+
|
|
285
|
+
export default class UserPostsController {
|
|
286
|
+
/**
|
|
287
|
+
* Get a list posts of user
|
|
288
|
+
* GET /users/:user_id/posts
|
|
289
|
+
*/
|
|
290
|
+
async index({ params, request }: HttpContext): Promise<Post[]> {
|
|
291
|
+
const user: User = await User.findOrFail(params.user_id)
|
|
292
|
+
|
|
293
|
+
return user
|
|
294
|
+
.related('posts')
|
|
295
|
+
.query()
|
|
296
|
+
.apply((scopes) => scopes.filtration(request.qs()))
|
|
297
|
+
.exec()
|
|
298
|
+
|
|
299
|
+
// or
|
|
300
|
+
|
|
301
|
+
return user.related('posts').query().filter(request.qs()).exec()
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Documentation by [Query Scopes](https://lucid.adonisjs.com/docs/model-query-scopes)
|
|
307
|
+
|
|
308
|
+
**Note:** The relation model must be `Filterable` and `$filter` must be defined in it
|
|
309
|
+
|
|
310
|
+
[npm-image]: https://img.shields.io/npm/v/adonis-lucid-filter?logo=npm&style=for-the-badge
|
|
311
|
+
[npm-url]: https://www.npmjs.com/package/adonis-lucid-filter
|
|
312
|
+
[license-image]: https://img.shields.io/npm/l/adonis-lucid-filter?style=for-the-badge&color=blueviolet
|
|
313
|
+
[license-url]: https://github.com/lookinlab/adonis-lucid-filter/blob/develop/LICENSE.md
|
|
314
|
+
[typescript-image]: https://img.shields.io/npm/types/adonis-lucid-filter?color=294E80&label=%20&logo=typescript&style=for-the-badge
|
|
315
|
+
[typescript-url]: https://github.com/lookinlab
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bindings/model_query_builder.ts"],"sourcesContent":["/*\n * adonis-lucid-filter\n *\n * (c) Lookin Anton <alf@lookinlab.ru>\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ModelQueryBuilder } from '@adonisjs/lucid/orm'\nimport type { LucidFilterContract } from '@codenameryuu/adonis-lucid-filter/types/filter'\n\n/**\n * Define filter method to ModelQueryBuilder\n */\nexport function extendModelQueryBuilder(builder: any) {\n builder.macro(\n 'filter',\n function (this: ModelQueryBuilder, input: any, filter?: LucidFilterContract) {\n const Filter = filter || (this.model as any).$filter()\n return new Filter(this, input).handle()\n }\n )\n}\n"],"mappings":";AAeO,SAAS,wBAAwB,SAAc;AACpD,UAAQ;AAAA,IACN;AAAA,IACA,SAAmC,OAAY,QAA8B;AAC3E,YAAM,SAAS,UAAW,KAAK,MAAc,QAAQ;AACrD,aAAO,IAAI,OAAO,MAAM,KAAK,EAAE,OAAO;AAAA,IACxC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../stubs/main.ts"],"sourcesContent":["/*\n * adonis-lucid-filter\n *\n * (c) Lookin Anton <alf@lookinlab.ru>\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { fileURLToPath } from 'node:url'\nimport { dirname } from 'node:path'\n\nexport const stubsRoot = dirname(fileURLToPath(import.meta.url))\n"],"mappings":";AASA,SAAS,qBAAqB;AAC9B,SAAS,eAAe;AAEjB,IAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../commands/make_filter.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"sources":["../../commands/make_filter.ts"],"sourcesContent":["/*\n * adonis-lucid-filter\n *\n * (c) Lookin Anton <alf@lookinlab.ru>\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { BaseCommand, args } from '@adonisjs/core/ace'\nimport { stubsRoot } from '../stubs/main.js'\n\nexport default class MakeFilter extends BaseCommand {\n static commandName = 'make:filter'\n static description = 'Make a new Lucid filter'\n\n /**\n * The name of the model file.\n */\n @args.string({ description: 'Name of the model file' })\n declare name: string\n\n /**\n * Run command\n */\n async run(): Promise<void> {\n const codemods = await this.createCodemods()\n\n await codemods.makeUsingStub(stubsRoot, 'make/filter/main.stub', {\n name: this.name,\n })\n }\n}\n"],"mappings":";;;;;;;;AASA,SAAS,aAAa,YAAY;AAGlC,IAAqB,aAArB,cAAwC,YAAY;AAAA,EAClD,OAAO,cAAc;AAAA,EACrB,OAAO,cAAc;AAAA;AAAA;AAAA;AAAA,EAWrB,MAAM,MAAqB;AACzB,UAAM,WAAW,MAAM,KAAK,eAAe;AAE3C,UAAM,SAAS,cAAc,WAAW,yBAAyB;AAAA,MAC/D,MAAM,KAAK;AAAA,IACb,CAAC;AAAA,EACH;AACF;AAZU;AAAA,EADP,KAAK,OAAO,EAAE,aAAa,yBAAyB,CAAC;AAAA,GAPnC,WAQX;","names":[]}
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
stubsRoot
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WD7GE7Y7.js";
|
|
4
4
|
import {
|
|
5
5
|
__decorateClass,
|
|
6
6
|
__publicField
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
async function configure(command) {
|
|
11
11
|
const codemods = await command.createCodemods();
|
|
12
12
|
await codemods.updateRcFile((rcFile) => {
|
|
13
|
-
rcFile.addProvider("adonis-lucid-filter/provider");
|
|
14
|
-
rcFile.addCommand("adonis-lucid-filter/commands");
|
|
13
|
+
rcFile.addProvider("@codenameryuu/adonis-lucid-filter/provider");
|
|
14
|
+
rcFile.addCommand("@codenameryuu/adonis-lucid-filter/commands");
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../configure.ts","../src/base_model.ts","../src/mixin.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"sources":["../configure.ts","../src/base_model.ts","../src/mixin.ts"],"sourcesContent":["/*\n * adonis-lucid-filter\n *\n * (c) Lookin Anton <alf@lookinlab.ru>\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type Configure from '@adonisjs/core/commands/configure'\n\nexport async function configure(command: Configure) {\n const codemods = await command.createCodemods()\n\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@codenameryuu/adonis-lucid-filter/provider')\n rcFile.addCommand('@codenameryuu/adonis-lucid-filter/commands')\n })\n}\n","/*\n * adonis-lucid-filter\n *\n * (c) Lookin Anton <alf@lookinlab.ru>\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport camelCase from 'lodash/camelCase.js'\nimport type { LucidFilter, LucidFilterContract } from './types/filter.js'\n\nfunction StaticImplements<T>() {\n return (_t: T) => {}\n}\n\n/**\n * Class to filtering AdonisJS Lucid ORM\n *\n * @class BaseModelFilter\n * @constructor\n */\n@StaticImplements<LucidFilterContract>()\nexport class BaseModelFilter implements LucidFilter {\n declare ['constructor']: typeof BaseModelFilter\n declare $blacklist: string[]\n\n static blacklist: string[] = []\n static dropId: boolean = true\n static camelCase: boolean = true\n\n setup?($query: any): void\n\n constructor(\n public $query: any,\n public $input: object\n ) {\n this.$input = BaseModelFilter.removeEmptyInput(this.$input)\n this.$blacklist = this.constructor.blacklist\n }\n\n handle(): any {\n if (this.setup && typeof this.setup === 'function') {\n this.setup(this.$query)\n }\n this.$filterByInput()\n\n return this.$query\n }\n\n whitelistMethod(method: string): boolean {\n const index = this.$blacklist.indexOf(method)\n\n const isBlacklisted = index !== -1\n if (isBlacklisted) this.$blacklist.splice(index, 1)\n\n return isBlacklisted\n }\n\n $filterByInput(): void {\n for (const key in this.$input) {\n const method = this.$getFilterMethod(key)\n\n const keyName = key as keyof typeof this.$input\n const value: unknown = this.$input[keyName]\n\n if (this.$methodIsCallable(method)) {\n ;(this[method as keyof this] as Function)(value)\n }\n }\n }\n\n $getFilterMethod(key: string): string {\n const methodName = this.constructor.dropId ? key.replace(/^(.*)(_id|Id)$/, '$1') : key\n return this.constructor.camelCase ? camelCase(methodName) : methodName\n }\n\n static removeEmptyInput(input: object): object {\n const filteredInput = {}\n\n for (const key in input) {\n const keyName = key as keyof typeof input\n const value = input[keyName]\n\n if (value !== '' && value !== null && value !== undefined) {\n filteredInput[keyName] = value\n }\n }\n return filteredInput\n }\n\n $methodIsCallable(method: string): boolean {\n const methodKey = method as keyof this\n\n return (\n !!this[methodKey] &&\n typeof this[methodKey] === 'function' &&\n !this.$methodIsBlacklisted(method)\n )\n }\n\n $methodIsBlacklisted(method: string): boolean {\n return this.$blacklist.includes(method)\n }\n}\nexport default BaseModelFilter\n","/*\n * adonis-lucid-filter\n *\n * (c) Lookin Anton <alf@lookinlab.ru>\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { NormalizeConstructor } from '@adonisjs/core/types/helpers'\nimport type { BaseModel } from '@adonisjs/lucid/orm'\nimport type {\n InputObject,\n LucidFilterContract,\n} from '@codenameryuu/adonis-lucid-filter/types/filter'\nimport type {\n ModelQueryBuilderContract,\n QueryScope,\n QueryScopeCallback,\n} from '@adonisjs/lucid/types/model'\n\nexport const Filterable = <Model extends NormalizeConstructor<typeof BaseModel>>(\n superclass: Model\n) => {\n class FilterableModel extends superclass {\n declare static $filter: () => LucidFilterContract\n\n /**\n * Filter method of filterable model\n */\n static filter<\n T extends typeof FilterableModel,\n Filter extends LucidFilterContract = ReturnType<T['$filter']>,\n >(\n this: T,\n input: InputObject<InstanceType<Filter>>,\n filter?: Filter\n ): ModelQueryBuilderContract<T> {\n const Filter = filter || this.$filter()\n return new Filter(this.query(), input).handle()\n }\n\n /**\n * Filtration scope of filterable model\n */\n static filtration = function (\n this: typeof FilterableModel,\n query,\n input,\n filter?: LucidFilterContract\n ) {\n const Filter = filter || this.$filter()\n return new Filter(query, input).handle()\n } as QueryScope<Model, QueryScopeCallback>\n }\n return FilterableModel\n}\n"],"mappings":";;;;;;;;;AAWA,eAAsB,UAAU,SAAoB;AAClD,QAAM,WAAW,MAAM,QAAQ,eAAe;AAE9C,QAAM,SAAS,aAAa,CAAC,WAAW;AACtC,WAAO,YAAY,4CAA4C;AAC/D,WAAO,WAAW,4CAA4C;AAAA,EAChE,CAAC;AACH;;;ACTA,OAAO,eAAe;AAGtB,SAAS,mBAAsB;AAC7B,SAAO,CAAC,OAAU;AAAA,EAAC;AACrB;AASO,IAAM,kBAAN,MAA6C;AAAA,EAUlD,YACS,QACA,QACP;AAFO;AACA;AAEP,SAAK,SAAS,gBAAgB,iBAAiB,KAAK,MAAM;AAC1D,SAAK,aAAa,KAAK,YAAY;AAAA,EACrC;AAAA,EAEA,SAAc;AACZ,QAAI,KAAK,SAAS,OAAO,KAAK,UAAU,YAAY;AAClD,WAAK,MAAM,KAAK,MAAM;AAAA,IACxB;AACA,SAAK,eAAe;AAEpB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,gBAAgB,QAAyB;AACvC,UAAM,QAAQ,KAAK,WAAW,QAAQ,MAAM;AAE5C,UAAM,gBAAgB,UAAU;AAChC,QAAI,cAAe,MAAK,WAAW,OAAO,OAAO,CAAC;AAElD,WAAO;AAAA,EACT;AAAA,EAEA,iBAAuB;AACrB,eAAW,OAAO,KAAK,QAAQ;AAC7B,YAAM,SAAS,KAAK,iBAAiB,GAAG;AAExC,YAAM,UAAU;AAChB,YAAM,QAAiB,KAAK,OAAO,OAAO;AAE1C,UAAI,KAAK,kBAAkB,MAAM,GAAG;AAClC;AAAC,QAAC,KAAK,MAAoB,EAAe,KAAK;AAAA,MACjD;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB,KAAqB;AACpC,UAAM,aAAa,KAAK,YAAY,SAAS,IAAI,QAAQ,kBAAkB,IAAI,IAAI;AACnF,WAAO,KAAK,YAAY,YAAY,UAAU,UAAU,IAAI;AAAA,EAC9D;AAAA,EAEA,OAAO,iBAAiB,OAAuB;AAC7C,UAAM,gBAAgB,CAAC;AAEvB,eAAW,OAAO,OAAO;AACvB,YAAM,UAAU;AAChB,YAAM,QAAQ,MAAM,OAAO;AAE3B,UAAI,UAAU,MAAM,UAAU,QAAQ,UAAU,QAAW;AACzD,sBAAc,OAAO,IAAI;AAAA,MAC3B;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,kBAAkB,QAAyB;AACzC,UAAM,YAAY;AAElB,WACE,CAAC,CAAC,KAAK,SAAS,KAChB,OAAO,KAAK,SAAS,MAAM,cAC3B,CAAC,KAAK,qBAAqB,MAAM;AAAA,EAErC;AAAA,EAEA,qBAAqB,QAAyB;AAC5C,WAAO,KAAK,WAAW,SAAS,MAAM;AAAA,EACxC;AACF;AA7EE,cAJW,iBAIJ,aAAsB,CAAC;AAC9B,cALW,iBAKJ,UAAkB;AACzB,cANW,iBAMJ,aAAqB;AANjB,kBAAN;AAAA,EADN,iBAAsC;AAAA,GAC1B;;;ACFN,IAAM,aAAa,CACxB,eACG;AAAA,EACH,MAAM,wBAAwB,WAAW;AAAA;AAAA;AAAA;AAAA,IAMvC,OAAO,OAKL,OACA,QAC8B;AAC9B,YAAM,SAAS,UAAU,KAAK,QAAQ;AACtC,aAAO,IAAI,OAAO,KAAK,MAAM,GAAG,KAAK,EAAE,OAAO;AAAA,IAChD;AAAA;AAAA;AAAA;AAAA,IAKA,OAAO,aAAa,SAElB,OACA,OACA,QACA;AACA,YAAM,SAAS,UAAU,KAAK,QAAQ;AACtC,aAAO,IAAI,OAAO,OAAO,KAAK,EAAE,OAAO;AAAA,IACzC;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../providers/lucid_filter_provider.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"sources":["../../providers/lucid_filter_provider.ts"],"sourcesContent":["/*\n * adonis-lucid-filter\n *\n * (c) Lookin Anton <alf@lookinlab.ru>\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/// <reference path=\"../src/types/querybuilder.ts\" />\n\nimport type { ApplicationService } from '@adonisjs/core/types'\nimport { extendModelQueryBuilder } from '../src/bindings/model_query_builder.js'\n\nexport default class LucidFilterProvider {\n constructor(protected app: ApplicationService) {}\n\n async boot() {\n const { ModelQueryBuilder } = await this.app.import('@adonisjs/lucid/orm')\n extendModelQueryBuilder(ModelQueryBuilder)\n }\n}\n"],"mappings":";;;;;;AAcA,IAAqB,sBAArB,MAAyC;AAAA,EACvC,YAAsB,KAAyB;AAAzB;AAAA,EAA0B;AAAA,EAEhD,MAAM,OAAO;AACX,UAAM,EAAE,kBAAkB,IAAI,MAAM,KAAK,IAAI,OAAO,qBAAqB;AACzE,4BAAwB,iBAAiB;AAAA,EAC3C;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@codenameryuu/adonis-lucid-filter",
|
|
3
|
-
"description": "Addon for filtering
|
|
4
|
-
"version": "2.
|
|
5
|
-
"engines": {
|
|
6
|
-
"node": ">=
|
|
7
|
-
},
|
|
8
|
-
"main": "./build/index.js",
|
|
9
|
-
"type": "module",
|
|
10
|
-
"files": [
|
|
11
|
-
"build",
|
|
12
|
-
"!build/bin",
|
|
13
|
-
"!build/tests"
|
|
14
|
-
],
|
|
15
|
-
"exports": {
|
|
16
|
-
".": "./build/index.js",
|
|
17
|
-
"./commands": "./build/commands/main.js",
|
|
18
|
-
"./types/*": "./build/src/types/*.js",
|
|
19
|
-
"./bindings": "./build/src/bindings/model_query_builder.js",
|
|
20
|
-
"./provider": "./build/providers/lucid_filter_provider.js"
|
|
21
|
-
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"lint": "eslint .",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"@adonisjs/
|
|
42
|
-
"@adonisjs/
|
|
43
|
-
"@adonisjs/
|
|
44
|
-
"@adonisjs/
|
|
45
|
-
"@adonisjs/
|
|
46
|
-
"@
|
|
47
|
-
"@japa/
|
|
48
|
-
"@japa/
|
|
49
|
-
"@japa/
|
|
50
|
-
"@japa/
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"reflect-metadata": "^0.2.2",
|
|
62
|
-
"sqlite3": "^5.1.7",
|
|
63
|
-
"ts-node": "^10.9.2",
|
|
64
|
-
"tsup": "^8.1.0",
|
|
65
|
-
"typescript": "^5.5.3"
|
|
66
|
-
},
|
|
67
|
-
"dependencies": {
|
|
68
|
-
"type-fest": "^4.21.0"
|
|
69
|
-
},
|
|
70
|
-
"peerDependencies": {
|
|
71
|
-
"@adonisjs/core": "^6.2.3",
|
|
72
|
-
"@adonisjs/lucid": "^21.1.0",
|
|
73
|
-
"lodash": "^4.17.21"
|
|
74
|
-
},
|
|
75
|
-
"author": "LookinGit",
|
|
76
|
-
"license": "MIT",
|
|
77
|
-
"homepage": "https://github.com/lookinlab/adonis-lucid-filter#readme",
|
|
78
|
-
"repository": {
|
|
79
|
-
"type": "git",
|
|
80
|
-
"url": "git+ssh://git@github.com/lookinlab/adonis-lucid-filter.git"
|
|
81
|
-
},
|
|
82
|
-
"bugs": {
|
|
83
|
-
"url": "https://github.com/lookinlab/adonis-lucid-filter/issues"
|
|
84
|
-
},
|
|
85
|
-
"keywords": [
|
|
86
|
-
"adonisjs",
|
|
87
|
-
"adonisjs-filter",
|
|
88
|
-
"adonisjs-lucid",
|
|
89
|
-
"adonisjs-lucid-filter",
|
|
90
|
-
"adonis",
|
|
91
|
-
"adonis-lucid",
|
|
92
|
-
"adonis-filter",
|
|
93
|
-
"adonis-lucid-filter"
|
|
94
|
-
],
|
|
95
|
-
"eslintConfig": {
|
|
96
|
-
"extends": "@adonisjs/eslint-config/package"
|
|
97
|
-
},
|
|
98
|
-
"prettier": "@adonisjs/prettier-config",
|
|
99
|
-
"publishConfig": {
|
|
100
|
-
"access": "public",
|
|
101
|
-
"tag": "latest"
|
|
102
|
-
},
|
|
103
|
-
"np": {
|
|
104
|
-
"message": "chore(release): %s",
|
|
105
|
-
"tag": "latest",
|
|
106
|
-
"branch": "master",
|
|
107
|
-
"anyBranch": false
|
|
108
|
-
},
|
|
109
|
-
"c8": {
|
|
110
|
-
"reporter": [
|
|
111
|
-
"text",
|
|
112
|
-
"html"
|
|
113
|
-
],
|
|
114
|
-
"exclude": [
|
|
115
|
-
"tests/**",
|
|
116
|
-
"bin/**"
|
|
117
|
-
]
|
|
118
|
-
},
|
|
119
|
-
"tsup": {
|
|
120
|
-
"entry": [
|
|
121
|
-
"./index.ts",
|
|
122
|
-
"./src/types/*.ts",
|
|
123
|
-
"./src/bindings/model_query_builder.ts",
|
|
124
|
-
"./commands/make_filter.ts",
|
|
125
|
-
"./providers/lucid_filter_provider.ts"
|
|
126
|
-
],
|
|
127
|
-
"outDir": "./build",
|
|
128
|
-
"clean": true,
|
|
129
|
-
"format": "esm",
|
|
130
|
-
"dts": false,
|
|
131
|
-
"sourcemap": true,
|
|
132
|
-
"target": "esnext"
|
|
133
|
-
}
|
|
134
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@codenameryuu/adonis-lucid-filter",
|
|
3
|
+
"description": "Addon for filtering Adonis JS 7 Lucid ORM",
|
|
4
|
+
"version": "2.1.0",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=24.x.x"
|
|
7
|
+
},
|
|
8
|
+
"main": "./build/index.js",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"files": [
|
|
11
|
+
"build",
|
|
12
|
+
"!build/bin",
|
|
13
|
+
"!build/tests"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./build/index.js",
|
|
17
|
+
"./commands": "./build/commands/main.js",
|
|
18
|
+
"./types/*": "./build/src/types/*.js",
|
|
19
|
+
"./bindings": "./build/src/bindings/model_query_builder.js",
|
|
20
|
+
"./provider": "./build/providers/lucid_filter_provider.js"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"lint": "eslint .",
|
|
24
|
+
"format": "prettier --write .",
|
|
25
|
+
"clean": "del-cli build",
|
|
26
|
+
"precompile": "npm run lint && npm run clean",
|
|
27
|
+
"postcompile": "npm run copy:stubs && npm run index:commands",
|
|
28
|
+
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
|
|
29
|
+
"build": "npm run compile",
|
|
30
|
+
"copy:stubs": "copyfiles \"stubs/**/**/*.stub\" --up=\"1\" build",
|
|
31
|
+
"index:commands": "adonis-kit index build/commands",
|
|
32
|
+
"quick:test": "NODE_DEBUG=\"adonis-lucid-filter\" node --enable-source-maps --loader=ts-node/esm bin/test.ts",
|
|
33
|
+
"pretest": "npm run lint",
|
|
34
|
+
"test": "c8 npm run quick:test",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"version": "npm run build",
|
|
37
|
+
"prepublishOnly": "npm run build",
|
|
38
|
+
"release": "np"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@adonisjs/assembler": "^7.7.0",
|
|
42
|
+
"@adonisjs/core": "^7.0.0",
|
|
43
|
+
"@adonisjs/eslint-config": "^1.3.0",
|
|
44
|
+
"@adonisjs/lucid": "^22.0.0",
|
|
45
|
+
"@adonisjs/prettier-config": "^1.3.0",
|
|
46
|
+
"@adonisjs/tsconfig": "^1.3.0",
|
|
47
|
+
"@japa/assert": "^2.1.0",
|
|
48
|
+
"@japa/expect-type": "^2.0.2",
|
|
49
|
+
"@japa/file-system": "^2.3.0",
|
|
50
|
+
"@japa/runner": "^3.1.4",
|
|
51
|
+
"@japa/snapshot": "^2.0.5",
|
|
52
|
+
"@swc/core": "^1.6.7",
|
|
53
|
+
"@types/lodash": "^4.17.6",
|
|
54
|
+
"c8": "^9.1.0",
|
|
55
|
+
"copyfiles": "^2.4.1",
|
|
56
|
+
"del-cli": "^5.1.0",
|
|
57
|
+
"eslint": "^8.57.0",
|
|
58
|
+
"knex": "^3.1.0",
|
|
59
|
+
"lodash": "^4.17.21",
|
|
60
|
+
"luxon": "^3.4.4",
|
|
61
|
+
"reflect-metadata": "^0.2.2",
|
|
62
|
+
"sqlite3": "^5.1.7",
|
|
63
|
+
"ts-node": "^10.9.2",
|
|
64
|
+
"tsup": "^8.1.0",
|
|
65
|
+
"typescript": "^5.5.3"
|
|
66
|
+
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"type-fest": "^4.21.0"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@adonisjs/core": "^6.2.3",
|
|
72
|
+
"@adonisjs/lucid": "^21.1.0",
|
|
73
|
+
"lodash": "^4.17.21"
|
|
74
|
+
},
|
|
75
|
+
"author": "LookinGit",
|
|
76
|
+
"license": "MIT",
|
|
77
|
+
"homepage": "https://github.com/lookinlab/adonis-lucid-filter#readme",
|
|
78
|
+
"repository": {
|
|
79
|
+
"type": "git",
|
|
80
|
+
"url": "git+ssh://git@github.com/lookinlab/adonis-lucid-filter.git"
|
|
81
|
+
},
|
|
82
|
+
"bugs": {
|
|
83
|
+
"url": "https://github.com/lookinlab/adonis-lucid-filter/issues"
|
|
84
|
+
},
|
|
85
|
+
"keywords": [
|
|
86
|
+
"adonisjs",
|
|
87
|
+
"adonisjs-filter",
|
|
88
|
+
"adonisjs-lucid",
|
|
89
|
+
"adonisjs-lucid-filter",
|
|
90
|
+
"adonis",
|
|
91
|
+
"adonis-lucid",
|
|
92
|
+
"adonis-filter",
|
|
93
|
+
"adonis-lucid-filter"
|
|
94
|
+
],
|
|
95
|
+
"eslintConfig": {
|
|
96
|
+
"extends": "@adonisjs/eslint-config/package"
|
|
97
|
+
},
|
|
98
|
+
"prettier": "@adonisjs/prettier-config",
|
|
99
|
+
"publishConfig": {
|
|
100
|
+
"access": "public",
|
|
101
|
+
"tag": "latest"
|
|
102
|
+
},
|
|
103
|
+
"np": {
|
|
104
|
+
"message": "chore(release): %s",
|
|
105
|
+
"tag": "latest",
|
|
106
|
+
"branch": "master",
|
|
107
|
+
"anyBranch": false
|
|
108
|
+
},
|
|
109
|
+
"c8": {
|
|
110
|
+
"reporter": [
|
|
111
|
+
"text",
|
|
112
|
+
"html"
|
|
113
|
+
],
|
|
114
|
+
"exclude": [
|
|
115
|
+
"tests/**",
|
|
116
|
+
"bin/**"
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
"tsup": {
|
|
120
|
+
"entry": [
|
|
121
|
+
"./index.ts",
|
|
122
|
+
"./src/types/*.ts",
|
|
123
|
+
"./src/bindings/model_query_builder.ts",
|
|
124
|
+
"./commands/make_filter.ts",
|
|
125
|
+
"./providers/lucid_filter_provider.ts"
|
|
126
|
+
],
|
|
127
|
+
"outDir": "./build",
|
|
128
|
+
"clean": true,
|
|
129
|
+
"format": "esm",
|
|
130
|
+
"dts": false,
|
|
131
|
+
"sourcemap": true,
|
|
132
|
+
"target": "esnext"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bindings/model_query_builder.ts"],"sourcesContent":["/*\r\n * adonis-lucid-filter\r\n *\r\n * (c) Lookin Anton <alf@lookinlab.ru>\r\n *\r\n * For the full copyright and license information, please view the LICENSE\r\n * file that was distributed with this source code.\r\n */\r\n\r\nimport type { ModelQueryBuilder } from '@adonisjs/lucid/orm'\r\nimport type { LucidFilterContract } from '@codenameryuu/adonis-lucid-filter/types/filter'\r\n\r\n/**\r\n * Define filter method to ModelQueryBuilder\r\n */\r\nexport function extendModelQueryBuilder(builder: any) {\r\n builder.macro(\r\n 'filter',\r\n function (this: ModelQueryBuilder, input: any, filter?: LucidFilterContract) {\r\n const Filter = filter || (this.model as any).$filter()\r\n return new Filter(this, input).handle()\r\n }\r\n )\r\n}\r\n"],"mappings":";AAeO,SAAS,wBAAwB,SAAc;AACpD,UAAQ;AAAA,IACN;AAAA,IACA,SAAmC,OAAY,QAA8B;AAC3E,YAAM,SAAS,UAAW,KAAK,MAAc,QAAQ;AACrD,aAAO,IAAI,OAAO,MAAM,KAAK,EAAE,OAAO;AAAA,IACxC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../stubs/main.ts"],"sourcesContent":["/*\r\n * adonis-lucid-filter\r\n *\r\n * (c) Lookin Anton <alf@lookinlab.ru>\r\n *\r\n * For the full copyright and license information, please view the LICENSE\r\n * file that was distributed with this source code.\r\n */\r\n\r\nimport { fileURLToPath } from 'node:url'\r\nimport { dirname } from 'node:path'\r\n\r\nexport const stubsRoot = dirname(fileURLToPath(import.meta.url))\r\n"],"mappings":";AASA,SAAS,qBAAqB;AAC9B,SAAS,eAAe;AAEjB,IAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;","names":[]}
|