@codenameryuu/adonis-lucid-filter 2.7.0 → 2.9.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 -11
- package/build/commands/make_filter.js +31 -28
- package/build/configure.js +15 -0
- package/build/index.js +12 -111
- package/build/providers/lucid_filter_provider.js +19 -19
- package/build/src/base_model.js +93 -0
- package/build/src/bindings/model_query_builder.js +17 -8
- package/build/src/mixin.js +27 -0
- package/build/src/types/filter.js +9 -1
- package/build/src/types/querybuilder.js +9 -1
- package/build/stubs/main.js +11 -0
- package/package.json +7 -28
- package/build/chunk-V7FYZD4D.js +0 -15
- package/build/chunk-V7FYZD4D.js.map +0 -1
- package/build/chunk-WD7GE7Y7.js +0 -9
- package/build/chunk-WD7GE7Y7.js.map +0 -1
- package/build/chunk-XUS63JTZ.js +0 -18
- package/build/chunk-XUS63JTZ.js.map +0 -1
- package/build/commands/make_filter.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/providers/lucid_filter_provider.js.map +0 -1
- package/build/src/bindings/model_query_builder.js.map +0 -1
- package/build/src/types/filter.js.map +0 -1
- package/build/src/types/querybuilder.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ This addon adds the functionality to filter Lucid Models Adonis JS 7. Inspired b
|
|
|
6
6
|
|
|
7
7
|
Example, we want to return a list of users filtered by multiple parameters. When we navigate to:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
`/users?name=Tony&lastName=&companyId=2&industry=5`
|
|
10
10
|
|
|
11
11
|
`request.all()` or `request.qs()` will return:
|
|
12
12
|
|
|
@@ -59,13 +59,13 @@ export default class UsersController {
|
|
|
59
59
|
|
|
60
60
|
## Installation
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
- Install the package
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
65
|
yarn add @codenameryuu/adonis-lucid-filter
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
- Configure the package
|
|
69
69
|
|
|
70
70
|
```bash
|
|
71
71
|
node ace configure @codenameryuu/adonis-lucid-filter
|
|
@@ -73,7 +73,7 @@ node ace configure @codenameryuu/adonis-lucid-filter
|
|
|
73
73
|
|
|
74
74
|
## Usage
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
- Register the provider and commands inside `adonisrc.ts` file.
|
|
77
77
|
|
|
78
78
|
```typescript
|
|
79
79
|
providers: [
|
|
@@ -102,13 +102,13 @@ Where `user` is the Lucid Model you are creating the filter for. This will creat
|
|
|
102
102
|
|
|
103
103
|
Define the filter logic based on the camel cased input key passed to the `filter()` method.
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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.
|
|
112
112
|
|
|
113
113
|
To define methods for the following input:
|
|
114
114
|
|
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* Run command
|
|
15
|
-
*/
|
|
16
|
-
async run() {
|
|
17
|
-
const codemods = await this.createCodemods();
|
|
18
|
-
await codemods.makeUsingStub(stubsRoot, "make/filter/main.stub", {
|
|
19
|
-
name: this.name
|
|
20
|
-
});
|
|
21
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* adonis-lucid-filter
|
|
3
|
+
*
|
|
4
|
+
* (c) Lookin Anton <alf@lookinlab.ru>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
10
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
14
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
import { BaseCommand, args } from '@adonisjs/core/ace';
|
|
16
|
+
import { stubsRoot } from '../stubs/main.js';
|
|
17
|
+
export default class MakeFilter extends BaseCommand {
|
|
18
|
+
static commandName = 'make:filter';
|
|
19
|
+
static description = 'Make a new Lucid filter';
|
|
20
|
+
/**
|
|
21
|
+
* Run command
|
|
22
|
+
*/
|
|
23
|
+
async run() {
|
|
24
|
+
const codemods = await this.createCodemods();
|
|
25
|
+
await codemods.makeUsingStub(stubsRoot, 'make/filter/main.stub', {
|
|
26
|
+
name: this.name,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
__decorate([
|
|
31
|
+
args.string({ description: 'Name of the model file' })
|
|
32
|
+
], MakeFilter.prototype, "name", void 0);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* adonis-lucid-filter
|
|
3
|
+
*
|
|
4
|
+
* (c) Lookin Anton <alf@lookinlab.ru>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
export async function configure(command) {
|
|
10
|
+
const codemods = await command.createCodemods();
|
|
11
|
+
await codemods.updateRcFile((rcFile) => {
|
|
12
|
+
rcFile.addProvider('@codenameryuu/adonis-lucid-filter/provider');
|
|
13
|
+
rcFile.addCommand('@codenameryuu/adonis-lucid-filter/commands');
|
|
14
|
+
});
|
|
15
|
+
}
|
package/build/index.js
CHANGED
|
@@ -1,111 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
rcFile.addProvider("@codenameryuu/adonis-lucid-filter/provider");
|
|
14
|
-
rcFile.addCommand("@codenameryuu/adonis-lucid-filter/commands");
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/base_model.ts
|
|
19
|
-
import camelCase from "lodash/camelCase.js";
|
|
20
|
-
function StaticImplements() {
|
|
21
|
-
return (_t) => {
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
var BaseModelFilter = class {
|
|
25
|
-
constructor($query, $input) {
|
|
26
|
-
this.$query = $query;
|
|
27
|
-
this.$input = $input;
|
|
28
|
-
this.$input = BaseModelFilter.removeEmptyInput(this.$input);
|
|
29
|
-
this.$blacklist = this.constructor.blacklist;
|
|
30
|
-
}
|
|
31
|
-
handle() {
|
|
32
|
-
if (this.setup && typeof this.setup === "function") {
|
|
33
|
-
this.setup(this.$query);
|
|
34
|
-
}
|
|
35
|
-
this.$filterByInput();
|
|
36
|
-
return this.$query;
|
|
37
|
-
}
|
|
38
|
-
whitelistMethod(method) {
|
|
39
|
-
const index = this.$blacklist.indexOf(method);
|
|
40
|
-
const isBlacklisted = index !== -1;
|
|
41
|
-
if (isBlacklisted) this.$blacklist.splice(index, 1);
|
|
42
|
-
return isBlacklisted;
|
|
43
|
-
}
|
|
44
|
-
$filterByInput() {
|
|
45
|
-
for (const key in this.$input) {
|
|
46
|
-
const method = this.$getFilterMethod(key);
|
|
47
|
-
const keyName = key;
|
|
48
|
-
const value = this.$input[keyName];
|
|
49
|
-
if (this.$methodIsCallable(method)) {
|
|
50
|
-
;
|
|
51
|
-
this[method](value);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
$getFilterMethod(key) {
|
|
56
|
-
const methodName = this.constructor.dropId ? key.replace(/^(.*)(_id|Id)$/, "$1") : key;
|
|
57
|
-
return this.constructor.camelCase ? camelCase(methodName) : methodName;
|
|
58
|
-
}
|
|
59
|
-
static removeEmptyInput(input) {
|
|
60
|
-
const filteredInput = {};
|
|
61
|
-
for (const key in input) {
|
|
62
|
-
const keyName = key;
|
|
63
|
-
const value = input[keyName];
|
|
64
|
-
if (value !== "" && value !== null && value !== void 0) {
|
|
65
|
-
filteredInput[keyName] = value;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return filteredInput;
|
|
69
|
-
}
|
|
70
|
-
$methodIsCallable(method) {
|
|
71
|
-
const methodKey = method;
|
|
72
|
-
return !!this[methodKey] && typeof this[methodKey] === "function" && !this.$methodIsBlacklisted(method);
|
|
73
|
-
}
|
|
74
|
-
$methodIsBlacklisted(method) {
|
|
75
|
-
return this.$blacklist.includes(method);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
__publicField(BaseModelFilter, "blacklist", []);
|
|
79
|
-
__publicField(BaseModelFilter, "dropId", true);
|
|
80
|
-
__publicField(BaseModelFilter, "camelCase", true);
|
|
81
|
-
BaseModelFilter = __decorateClass([
|
|
82
|
-
StaticImplements()
|
|
83
|
-
], BaseModelFilter);
|
|
84
|
-
|
|
85
|
-
// src/mixin.ts
|
|
86
|
-
var Filterable = (superclass) => {
|
|
87
|
-
class FilterableModel extends superclass {
|
|
88
|
-
/**
|
|
89
|
-
* Filter method of filterable model
|
|
90
|
-
*/
|
|
91
|
-
static filter(input, filter) {
|
|
92
|
-
const Filter = filter || this.$filter();
|
|
93
|
-
return new Filter(this.query(), input).handle();
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Filtration scope of filterable model
|
|
97
|
-
*/
|
|
98
|
-
static filtration = function(query, input, filter) {
|
|
99
|
-
const Filter = filter || this.$filter();
|
|
100
|
-
return new Filter(query, input).handle();
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
return FilterableModel;
|
|
104
|
-
};
|
|
105
|
-
export {
|
|
106
|
-
BaseModelFilter,
|
|
107
|
-
Filterable,
|
|
108
|
-
configure,
|
|
109
|
-
stubsRoot
|
|
110
|
-
};
|
|
111
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
/*
|
|
2
|
+
* adonis-lucid-filter
|
|
3
|
+
*
|
|
4
|
+
* (c) Lookin Anton <alf@lookinlab.ru>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
export { configure } from './configure.js';
|
|
10
|
+
export { stubsRoot } from './stubs/main.js';
|
|
11
|
+
export { BaseModelFilter } from './src/base_model.js';
|
|
12
|
+
export { Filterable } from './src/mixin.js';
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
1
|
+
/*
|
|
2
|
+
* adonis-lucid-filter
|
|
3
|
+
*
|
|
4
|
+
* (c) Lookin Anton <alf@lookinlab.ru>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
import { extendModelQueryBuilder } from '../src/bindings/model_query_builder.js';
|
|
10
|
+
export default class LucidFilterProvider {
|
|
11
|
+
app;
|
|
12
|
+
constructor(app) {
|
|
13
|
+
this.app = app;
|
|
14
|
+
}
|
|
15
|
+
async boot() {
|
|
16
|
+
const { ModelQueryBuilder } = await this.app.import('@adonisjs/lucid/orm');
|
|
17
|
+
extendModelQueryBuilder(ModelQueryBuilder);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* adonis-lucid-filter
|
|
3
|
+
*
|
|
4
|
+
* (c) Lookin Anton <alf@lookinlab.ru>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
10
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
|
+
};
|
|
15
|
+
var BaseModelFilter_1;
|
|
16
|
+
import camelCase from 'lodash/camelCase.js';
|
|
17
|
+
function StaticImplements() {
|
|
18
|
+
return (_t) => { };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Class to filtering AdonisJS Lucid ORM
|
|
22
|
+
*
|
|
23
|
+
* @class BaseModelFilter
|
|
24
|
+
* @constructor
|
|
25
|
+
*/
|
|
26
|
+
let BaseModelFilter = class BaseModelFilter {
|
|
27
|
+
static { BaseModelFilter_1 = this; }
|
|
28
|
+
$query;
|
|
29
|
+
$input;
|
|
30
|
+
static blacklist = [];
|
|
31
|
+
static dropId = true;
|
|
32
|
+
static camelCase = true;
|
|
33
|
+
constructor($query, $input) {
|
|
34
|
+
this.$query = $query;
|
|
35
|
+
this.$input = $input;
|
|
36
|
+
this.$input = BaseModelFilter_1.removeEmptyInput(this.$input);
|
|
37
|
+
this.$blacklist = this.constructor.blacklist;
|
|
38
|
+
}
|
|
39
|
+
handle() {
|
|
40
|
+
if (this.setup && typeof this.setup === 'function') {
|
|
41
|
+
this.setup(this.$query);
|
|
42
|
+
}
|
|
43
|
+
this.$filterByInput();
|
|
44
|
+
return this.$query;
|
|
45
|
+
}
|
|
46
|
+
whitelistMethod(method) {
|
|
47
|
+
const index = this.$blacklist.indexOf(method);
|
|
48
|
+
const isBlacklisted = index !== -1;
|
|
49
|
+
if (isBlacklisted)
|
|
50
|
+
this.$blacklist.splice(index, 1);
|
|
51
|
+
return isBlacklisted;
|
|
52
|
+
}
|
|
53
|
+
$filterByInput() {
|
|
54
|
+
for (const key in this.$input) {
|
|
55
|
+
const method = this.$getFilterMethod(key);
|
|
56
|
+
const keyName = key;
|
|
57
|
+
const value = this.$input[keyName];
|
|
58
|
+
if (this.$methodIsCallable(method)) {
|
|
59
|
+
;
|
|
60
|
+
this[method](value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
$getFilterMethod(key) {
|
|
65
|
+
const methodName = this.constructor.dropId ? key.replace(/^(.*)(_id|Id)$/, '$1') : key;
|
|
66
|
+
return this.constructor.camelCase ? camelCase(methodName) : methodName;
|
|
67
|
+
}
|
|
68
|
+
static removeEmptyInput(input) {
|
|
69
|
+
const filteredInput = {};
|
|
70
|
+
for (const key in input) {
|
|
71
|
+
const keyName = key;
|
|
72
|
+
const value = input[keyName];
|
|
73
|
+
if (value !== '' && value !== null && value !== undefined) {
|
|
74
|
+
filteredInput[keyName] = value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return filteredInput;
|
|
78
|
+
}
|
|
79
|
+
$methodIsCallable(method) {
|
|
80
|
+
const methodKey = method;
|
|
81
|
+
return (!!this[methodKey] &&
|
|
82
|
+
typeof this[methodKey] === 'function' &&
|
|
83
|
+
!this.$methodIsBlacklisted(method));
|
|
84
|
+
}
|
|
85
|
+
$methodIsBlacklisted(method) {
|
|
86
|
+
return this.$blacklist.includes(method);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
BaseModelFilter = BaseModelFilter_1 = __decorate([
|
|
90
|
+
StaticImplements()
|
|
91
|
+
], BaseModelFilter);
|
|
92
|
+
export { BaseModelFilter };
|
|
93
|
+
export default BaseModelFilter;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/*
|
|
2
|
+
* adonis-lucid-filter
|
|
3
|
+
*
|
|
4
|
+
* (c) Lookin Anton <alf@lookinlab.ru>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Define filter method to ModelQueryBuilder
|
|
11
|
+
*/
|
|
12
|
+
export function extendModelQueryBuilder(builder) {
|
|
13
|
+
builder.macro('filter', function (input, filter) {
|
|
14
|
+
const Filter = filter || this.model.$filter();
|
|
15
|
+
return new Filter(this, input).handle();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* adonis-lucid-filter
|
|
3
|
+
*
|
|
4
|
+
* (c) Lookin Anton <alf@lookinlab.ru>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
export const Filterable = (superclass) => {
|
|
10
|
+
class FilterableModel extends superclass {
|
|
11
|
+
/**
|
|
12
|
+
* Filter method of filterable model
|
|
13
|
+
*/
|
|
14
|
+
static filter(input, filter) {
|
|
15
|
+
const Filter = filter || this.$filter();
|
|
16
|
+
return new Filter(this.query(), input).handle();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Filtration scope of filterable model
|
|
20
|
+
*/
|
|
21
|
+
static filtration = function (query, input, filter) {
|
|
22
|
+
const Filter = filter || this.$filter();
|
|
23
|
+
return new Filter(query, input).handle();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return FilterableModel;
|
|
27
|
+
};
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* adonis-lucid-filter
|
|
3
|
+
*
|
|
4
|
+
* (c) Lookin Anton <alf@lookinlab.ru>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* adonis-lucid-filter
|
|
3
|
+
*
|
|
4
|
+
* (c) Lookin Anton <alf@lookinlab.ru>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { dirname } from 'node:path';
|
|
11
|
+
export const stubsRoot = dirname(fileURLToPath(import.meta.url));
|
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.9.0",
|
|
5
5
|
"author": "codenameryuu",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/codenameryuu/adonis-lucid-filter#readme",
|
|
@@ -26,21 +26,15 @@
|
|
|
26
26
|
"./provider": "./build/providers/lucid_filter_provider.js"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"lint": "eslint .",
|
|
30
|
-
"format": "prettier --write .",
|
|
31
29
|
"clean": "del-cli build",
|
|
32
|
-
"precompile": "npm run lint && npm run clean",
|
|
33
|
-
"compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
|
|
34
|
-
"build": "npm run compile",
|
|
35
|
-
"pretest": "npm run lint",
|
|
36
|
-
"test": "c8 npm run quick:test",
|
|
37
30
|
"typecheck": "tsc --noEmit",
|
|
31
|
+
"lint": "eslint . --ext=.ts",
|
|
32
|
+
"format": "prettier --write .",
|
|
33
|
+
"prebuild": "npm run lint && npm run clean",
|
|
34
|
+
"build": "npm run clean && tsc",
|
|
35
|
+
"release": "release-it",
|
|
38
36
|
"version": "npm run build",
|
|
39
|
-
"prepublishOnly": "npm run build"
|
|
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"
|
|
37
|
+
"prepublishOnly": "npm run build"
|
|
44
38
|
},
|
|
45
39
|
"devDependencies": {
|
|
46
40
|
"@adonisjs/assembler": "^7.7.0",
|
|
@@ -107,20 +101,5 @@
|
|
|
107
101
|
"tests/**",
|
|
108
102
|
"bin/**"
|
|
109
103
|
]
|
|
110
|
-
},
|
|
111
|
-
"tsup": {
|
|
112
|
-
"entry": [
|
|
113
|
-
"./index.ts",
|
|
114
|
-
"./src/types/*.ts",
|
|
115
|
-
"./src/bindings/model_query_builder.ts",
|
|
116
|
-
"./commands/make_filter.ts",
|
|
117
|
-
"./providers/lucid_filter_provider.ts"
|
|
118
|
-
],
|
|
119
|
-
"outDir": "./build",
|
|
120
|
-
"clean": true,
|
|
121
|
-
"format": "esm",
|
|
122
|
-
"dts": false,
|
|
123
|
-
"sourcemap": true,
|
|
124
|
-
"target": "esnext"
|
|
125
104
|
}
|
|
126
105
|
}
|
package/build/chunk-V7FYZD4D.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// src/bindings/model_query_builder.ts
|
|
2
|
-
function extendModelQueryBuilder(builder) {
|
|
3
|
-
builder.macro(
|
|
4
|
-
"filter",
|
|
5
|
-
function(input, filter) {
|
|
6
|
-
const Filter = filter || this.model.$filter();
|
|
7
|
-
return new Filter(this, input).handle();
|
|
8
|
-
}
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
extendModelQueryBuilder
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=chunk-V7FYZD4D.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
package/build/chunk-WD7GE7Y7.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
package/build/chunk-XUS63JTZ.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
5
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
6
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
7
|
-
if (decorator = decorators[i])
|
|
8
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
9
|
-
if (kind && result) __defProp(target, key, result);
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
__decorateClass,
|
|
16
|
-
__publicField
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=chunk-XUS63JTZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|