@codenameryuu/adonis-lucid-filter 2.4.0 → 2.6.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 -33
- package/package.json +14 -24
- 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,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @codenameryuu/adonis-lucid-filter
|
|
2
2
|
|
|
3
|
-
> Works with
|
|
3
|
+
> Works with Adonis JS V7
|
|
4
4
|
|
|
5
5
|
[![npm-image]][npm-url] [![license-image]][license-url] [![typescript-image]][typescript-url]
|
|
6
6
|
|
|
@@ -8,21 +8,6 @@ This addon adds the functionality to filter Lucid Models
|
|
|
8
8
|
|
|
9
9
|
> Inspired by [EloquentFilter](https://github.com/Tucker-Eric/EloquentFilter)
|
|
10
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
11
|
## Introduction
|
|
27
12
|
|
|
28
13
|
Example, we want to return a list of users filtered by multiple parameters. When we navigate to:
|
|
@@ -80,43 +65,36 @@ export default class UsersController {
|
|
|
80
65
|
|
|
81
66
|
## Installation
|
|
82
67
|
|
|
83
|
-
|
|
68
|
+
- Install the package
|
|
84
69
|
|
|
85
70
|
```bash
|
|
86
|
-
|
|
87
|
-
npm i adonis-lucid-filter
|
|
88
|
-
|
|
89
|
-
# yarn
|
|
90
|
-
yarn add adonis-lucid-filter
|
|
91
|
-
|
|
92
|
-
# pnpm
|
|
93
|
-
pnpm add adonis-lucid-filter
|
|
71
|
+
yarn add @codenameryuu/adonis-lucid-filter
|
|
94
72
|
```
|
|
95
73
|
|
|
96
|
-
|
|
74
|
+
- Configure the package
|
|
97
75
|
|
|
98
76
|
```bash
|
|
99
|
-
node ace configure adonis-lucid-filter
|
|
77
|
+
node ace configure @codenameryuu/adonis-lucid-filter
|
|
100
78
|
```
|
|
101
79
|
|
|
102
80
|
## Usage
|
|
103
81
|
|
|
104
|
-
|
|
82
|
+
- Register the provider and commands inside `adonisrc.ts` file.
|
|
105
83
|
|
|
106
84
|
```ts
|
|
107
85
|
providers: [
|
|
108
86
|
// ...
|
|
109
|
-
() => import('adonis-lucid-filter/provider'),
|
|
87
|
+
() => import('@codenameryuu/adonis-lucid-filter/provider'),
|
|
110
88
|
],
|
|
111
89
|
commands: [
|
|
112
90
|
// ...
|
|
113
|
-
() => import('adonis-lucid-filter/commands')
|
|
91
|
+
() => import('@codenameryuu/adonis-lucid-filter/commands')
|
|
114
92
|
]
|
|
115
93
|
```
|
|
116
94
|
|
|
117
95
|
### Generating The Filter
|
|
118
96
|
|
|
119
|
-
> Only available if you have added
|
|
97
|
+
> Only available if you have added `@codenameryuu/adonis-lucid-filter/commands` in `commands` array in your `adonisrc.ts'
|
|
120
98
|
|
|
121
99
|
You can create a model filter with the following ace command:
|
|
122
100
|
|
|
@@ -276,7 +254,7 @@ export default class UsersController {
|
|
|
276
254
|
|
|
277
255
|
### Filtering relations
|
|
278
256
|
|
|
279
|
-
For filtering relations of model may be use `.query().filter()` or scope `filtration
|
|
257
|
+
For filtering relations of model may be use `.query().filter()` or scope `filtration` , example:
|
|
280
258
|
|
|
281
259
|
```ts
|
|
282
260
|
import type { HttpContext } from '@adonisjs/core/http'
|
package/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
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.6.0",
|
|
5
|
+
"author": "codenameryuu",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/codenameryuu/adonis-lucid-filter#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/codenameryuu/adonis-lucid-filter.git"
|
|
11
|
+
},
|
|
5
12
|
"engines": {
|
|
6
13
|
"node": ">=24.0.0"
|
|
7
14
|
},
|
|
8
|
-
"main": "./build/index.js",
|
|
9
15
|
"type": "module",
|
|
10
16
|
"files": [
|
|
11
17
|
"build",
|
|
@@ -24,18 +30,17 @@
|
|
|
24
30
|
"format": "prettier --write .",
|
|
25
31
|
"clean": "del-cli build",
|
|
26
32
|
"precompile": "npm run lint && npm run clean",
|
|
27
|
-
"postcompile": "npm run copy:stubs && npm run index:commands",
|
|
28
33
|
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
|
|
29
34
|
"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
35
|
"pretest": "npm run lint",
|
|
34
36
|
"test": "c8 npm run quick:test",
|
|
35
37
|
"typecheck": "tsc --noEmit",
|
|
36
38
|
"version": "npm run build",
|
|
37
39
|
"prepublishOnly": "npm run build",
|
|
38
|
-
"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"
|
|
39
44
|
},
|
|
40
45
|
"devDependencies": {
|
|
41
46
|
"@adonisjs/assembler": "^7.7.0",
|
|
@@ -59,31 +64,19 @@
|
|
|
59
64
|
"knex": "^3.1.0",
|
|
60
65
|
"lodash": "^4.17.23",
|
|
61
66
|
"luxon": "^3.4.4",
|
|
67
|
+
"np": "^11.0.2",
|
|
62
68
|
"prettier": "^3.8.1",
|
|
63
69
|
"reflect-metadata": "^0.2.2",
|
|
64
|
-
"sqlite3": "^5.1.7",
|
|
65
70
|
"ts-node": "^10.9.2",
|
|
66
71
|
"tsup": "^8.1.0",
|
|
72
|
+
"type-fest": "^4.21.0",
|
|
67
73
|
"typescript": "^5.5.3",
|
|
68
74
|
"youch": "^4.1.0"
|
|
69
75
|
},
|
|
70
|
-
"dependencies": {
|
|
71
|
-
"type-fest": "^4.21.0"
|
|
72
|
-
},
|
|
73
76
|
"peerDependencies": {
|
|
74
77
|
"@adonisjs/core": "^7.0.0",
|
|
75
78
|
"@adonisjs/lucid": "^22.0.0"
|
|
76
79
|
},
|
|
77
|
-
"author": "LookinGit",
|
|
78
|
-
"license": "MIT",
|
|
79
|
-
"homepage": "https://github.com/lookinlab/adonis-lucid-filter#readme",
|
|
80
|
-
"repository": {
|
|
81
|
-
"type": "git",
|
|
82
|
-
"url": "git+ssh://git@github.com/lookinlab/adonis-lucid-filter.git"
|
|
83
|
-
},
|
|
84
|
-
"bugs": {
|
|
85
|
-
"url": "https://github.com/lookinlab/adonis-lucid-filter/issues"
|
|
86
|
-
},
|
|
87
80
|
"keywords": [
|
|
88
81
|
"adonisjs",
|
|
89
82
|
"adonisjs-filter",
|
|
@@ -94,9 +87,6 @@
|
|
|
94
87
|
"adonis-filter",
|
|
95
88
|
"adonis-lucid-filter"
|
|
96
89
|
],
|
|
97
|
-
"eslintConfig": {
|
|
98
|
-
"extends": "@adonisjs/eslint-config/package"
|
|
99
|
-
},
|
|
100
90
|
"prettier": "@adonisjs/prettier-config",
|
|
101
91
|
"publishConfig": {
|
|
102
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
|
-
}
|