@codenameryuu/adonis-lucid-filter 2.5.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.
- package/README.md +11 -24
- package/package.json +7 -14
- package/build/commands/commands.json +0 -1
- package/build/commands/main.d.ts +0 -4
- package/build/commands/main.js +0 -36
- package/build/make/filter/main.stub +0 -20
package/README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
# @codenameryuu/adonis-lucid-filter
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
|
@@ -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
|
-
```
|
|
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
|
-
```
|
|
49
|
+
```typescript
|
|
56
50
|
import type { HttpContext } from '@adonisjs/core/http'
|
|
57
51
|
import User from '#models/user'
|
|
58
52
|
|
|
@@ -81,7 +75,7 @@ node ace configure @codenameryuu/adonis-lucid-filter
|
|
|
81
75
|
|
|
82
76
|
* Register the provider and commands inside `adonisrc.ts` file.
|
|
83
77
|
|
|
84
|
-
```
|
|
78
|
+
```typescript
|
|
85
79
|
providers: [
|
|
86
80
|
// ...
|
|
87
81
|
() => import('@codenameryuu/adonis-lucid-filter/provider'),
|
|
@@ -128,7 +122,7 @@ To define methods for the following input:
|
|
|
128
122
|
|
|
129
123
|
You would use the following methods:
|
|
130
124
|
|
|
131
|
-
```
|
|
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
|
-
```
|
|
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
|
-
```
|
|
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
|
-
```
|
|
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
|
-
```
|
|
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
|
-
```
|
|
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
|
-
```
|
|
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.
|
|
4
|
+
"version": "2.7.0",
|
|
5
5
|
"author": "codenameryuu",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/codenameryuu/adonis-lucid-filter#readme",
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"engines": {
|
|
13
13
|
"node": ">=24.0.0"
|
|
14
14
|
},
|
|
15
|
-
"main": "./build/index.js",
|
|
16
15
|
"type": "module",
|
|
17
16
|
"files": [
|
|
18
17
|
"build",
|
|
@@ -31,18 +30,17 @@
|
|
|
31
30
|
"format": "prettier --write .",
|
|
32
31
|
"clean": "del-cli build",
|
|
33
32
|
"precompile": "npm run lint && npm run clean",
|
|
34
|
-
"postcompile": "npm run copy:stubs && npm run index:commands",
|
|
35
33
|
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
|
|
36
34
|
"build": "npm run compile",
|
|
37
|
-
"copy:stubs": "copyfiles \"stubs/**/**/*.stub\" --up=\"1\" build",
|
|
38
|
-
"index:commands": "adonis-kit index build/commands",
|
|
39
|
-
"quick:test": "NODE_DEBUG=\"adonis-lucid-filter\" node --enable-source-maps --loader=ts-node/esm bin/test.ts",
|
|
40
35
|
"pretest": "npm run lint",
|
|
41
36
|
"test": "c8 npm run quick:test",
|
|
42
37
|
"typecheck": "tsc --noEmit",
|
|
43
38
|
"version": "npm run build",
|
|
44
39
|
"prepublishOnly": "npm run build",
|
|
45
|
-
"release": "np"
|
|
40
|
+
"release": "np",
|
|
41
|
+
"quick:test": "NODE_DEBUG=\"adonis-lucid-filter\" node --enable-source-maps --loader=ts-node/esm bin/test.ts",
|
|
42
|
+
"copy:stubs": "copyfiles \"stubs/**/**/*.stub\" --up=\"1\" build",
|
|
43
|
+
"index:commands": "adonis-kit index build/commands"
|
|
46
44
|
},
|
|
47
45
|
"devDependencies": {
|
|
48
46
|
"@adonisjs/assembler": "^7.7.0",
|
|
@@ -66,17 +64,15 @@
|
|
|
66
64
|
"knex": "^3.1.0",
|
|
67
65
|
"lodash": "^4.17.23",
|
|
68
66
|
"luxon": "^3.4.4",
|
|
67
|
+
"np": "^11.0.2",
|
|
69
68
|
"prettier": "^3.8.1",
|
|
70
69
|
"reflect-metadata": "^0.2.2",
|
|
71
|
-
"sqlite3": "^5.1.7",
|
|
72
70
|
"ts-node": "^10.9.2",
|
|
73
71
|
"tsup": "^8.1.0",
|
|
72
|
+
"type-fest": "^4.21.0",
|
|
74
73
|
"typescript": "^5.5.3",
|
|
75
74
|
"youch": "^4.1.0"
|
|
76
75
|
},
|
|
77
|
-
"dependencies": {
|
|
78
|
-
"type-fest": "^4.21.0"
|
|
79
|
-
},
|
|
80
76
|
"peerDependencies": {
|
|
81
77
|
"@adonisjs/core": "^7.0.0",
|
|
82
78
|
"@adonisjs/lucid": "^22.0.0"
|
|
@@ -91,9 +87,6 @@
|
|
|
91
87
|
"adonis-filter",
|
|
92
88
|
"adonis-lucid-filter"
|
|
93
89
|
],
|
|
94
|
-
"eslintConfig": {
|
|
95
|
-
"extends": "@adonisjs/eslint-config/package"
|
|
96
|
-
},
|
|
97
90
|
"prettier": "@adonisjs/prettier-config",
|
|
98
91
|
"publishConfig": {
|
|
99
92
|
"access": "public",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"commands":[{"commandName":"make:filter","description":"Make a new Lucid filter","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the model file","type":"string"}],"options":{},"filePath":"make_filter.js"}],"version":1}
|
package/build/commands/main.d.ts
DELETED
package/build/commands/main.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* In-memory cache of commands after they have been loaded
|
|
5
|
-
*/
|
|
6
|
-
let commandsMetaData
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Reads the commands from the "./commands.json" file. Since, the commands.json
|
|
10
|
-
* file is generated automatically, we do not have to validate its contents
|
|
11
|
-
*/
|
|
12
|
-
export async function getMetaData() {
|
|
13
|
-
if (commandsMetaData) {
|
|
14
|
-
return commandsMetaData
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const commandsIndex = await readFile(new URL('./commands.json', import.meta.url), 'utf-8')
|
|
18
|
-
commandsMetaData = JSON.parse(commandsIndex).commands
|
|
19
|
-
|
|
20
|
-
return commandsMetaData
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Imports the command by lookingup its path from the commands
|
|
25
|
-
* metadata
|
|
26
|
-
*/
|
|
27
|
-
export async function getCommand(metaData) {
|
|
28
|
-
const commands = await getMetaData()
|
|
29
|
-
const command = commands.find(({ commandName }) => metaData.commandName === commandName)
|
|
30
|
-
if (!command) {
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const { default: commandConstructor } = await import(new URL(command.filePath, import.meta.url).href)
|
|
35
|
-
return commandConstructor
|
|
36
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{{#var entity = generators.createEntity(name)}}
|
|
2
|
-
{{#var modelName = generators.modelName(entity.name)}}
|
|
3
|
-
{{#var modelFileName = string(modelName).removeExtension().snakeCase().toString()}}
|
|
4
|
-
{{#var modelFilterName = string(modelName).removeSuffix('filter').pascalCase().suffix(string.pascalCase('filter')).toString()}}
|
|
5
|
-
{{#var modelFilterFileName = string(modelName).snakeCase().suffix('_filter').ext('.ts').toString()}}
|
|
6
|
-
{{{
|
|
7
|
-
exports({ to: app.modelsPath('filters', entity.path, modelFilterFileName) })
|
|
8
|
-
}}}
|
|
9
|
-
|
|
10
|
-
import { BaseModelFilter } from 'adonis-lucid-filter'
|
|
11
|
-
import type { ModelQueryBuilderContract } from '@adonisjs/lucid/types/model'
|
|
12
|
-
import {{ modelName }} from '#models/{{ modelFileName }}'
|
|
13
|
-
|
|
14
|
-
export default class {{ modelFilterName }} extends BaseModelFilter {
|
|
15
|
-
declare $query: ModelQueryBuilderContract<typeof {{ modelName }}>
|
|
16
|
-
|
|
17
|
-
name(value: string): void {
|
|
18
|
-
this.$query.where('name', value)
|
|
19
|
-
}
|
|
20
|
-
}
|