@e22m4u/js-repository 0.0.32 → 0.0.34
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/package.json +1 -1
- package/src/adapter/adapter-loader.js +1 -1
- package/src/adapter/adapter-loader.spec.js +1 -1
- package/src/adapter/adapter.d.ts +11 -7
- package/src/adapter/builtin/memory-adapter.d.ts +11 -7
- package/src/adapter/decorator/data-sanitizing-decorator.js +1 -1
- package/src/adapter/decorator/data-validation-decorator.js +1 -1
- package/src/adapter/decorator/default-values-decorator.js +1 -1
- package/src/adapter/decorator/fields-filtering-decorator.js +1 -1
- package/src/adapter/decorator/inclusion-decorator.js +1 -1
- package/src/definition/model/model-data-sanitizer.js +2 -2
- package/src/definition/model/model-data-validator.js +1 -1
- package/src/definition/model/model-data-validator.spec.js +1 -1
- package/src/definition/model/model-definition-utils.js +1 -1
- package/src/definition/model/model-definition-utils.spec.js +1 -1
- package/src/filter/fields-clause-tool.d.ts +4 -4
- package/src/filter/fields-clause-tool.js +32 -21
- package/src/filter/fields-clause-tool.spec.js +479 -100
- package/src/filter/{filter.d.ts → filter-clause.d.ts} +10 -10
- package/src/filter/include-clause-tool.d.ts +7 -5
- package/src/filter/index.d.ts +1 -1
- package/src/filter/operator-clause-tool.js +1 -1
- package/src/filter/operator-clause-tool.spec.js +1 -1
- package/src/filter/order-clause-tool.d.ts +1 -1
- package/src/filter/order-clause-tool.js +20 -17
- package/src/filter/order-clause-tool.spec.js +621 -362
- package/src/filter/slice-clause-tool.js +1 -1
- package/src/filter/where-clause-tool.d.ts +1 -1
- package/src/relations/belongs-to-resolver.d.ts +3 -3
- package/src/relations/has-many-resolver.d.ts +4 -4
- package/src/relations/has-one-resolver.d.ts +4 -4
- package/src/relations/references-many-resolver.d.ts +2 -2
- package/src/repository/repository.d.ts +9 -9
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {ModelData} from '../types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Filter.
|
|
4
|
+
* Filter clause.
|
|
5
5
|
*/
|
|
6
|
-
export declare type
|
|
6
|
+
export declare type FilterClause = {
|
|
7
7
|
where?: WhereClause;
|
|
8
8
|
order?: OrderClause;
|
|
9
9
|
limit?: number;
|
|
@@ -13,9 +13,9 @@ export declare type Filter = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Item filter.
|
|
16
|
+
* Item filter clause.
|
|
17
17
|
*/
|
|
18
|
-
export declare type
|
|
18
|
+
export declare type ItemFilterClause = Pick<FilterClause, 'fields' | 'include'>;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Where clause.
|
|
@@ -45,20 +45,20 @@ export declare type ItemFilter = Pick<Filter, 'fields' | 'include'>;
|
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
47
|
export declare type WhereClause =
|
|
48
|
-
|
|
|
48
|
+
| PredicateClause
|
|
49
49
|
| PropertiesClause
|
|
50
50
|
| AndClause
|
|
51
51
|
| OrClause;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* Predicate clause.
|
|
55
55
|
*
|
|
56
56
|
* @example
|
|
57
57
|
* ```ts
|
|
58
58
|
* (value) => value.featured === true;
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
-
export type
|
|
61
|
+
export type PredicateClause = (value: ModelData) => boolean;
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Properties clause.
|
|
@@ -136,7 +136,7 @@ export declare type OperatorClause = {
|
|
|
136
136
|
* ```
|
|
137
137
|
*/
|
|
138
138
|
export interface AndClause {
|
|
139
|
-
and
|
|
139
|
+
and?: WhereClause[];
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/**
|
|
@@ -150,7 +150,7 @@ export interface AndClause {
|
|
|
150
150
|
* ```
|
|
151
151
|
*/
|
|
152
152
|
export interface OrClause {
|
|
153
|
-
or
|
|
153
|
+
or?: WhereClause[];
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
/**
|
|
@@ -331,5 +331,5 @@ export declare type NestedIncludeClause = {
|
|
|
331
331
|
*/
|
|
332
332
|
export declare type NormalizedIncludeClause = {
|
|
333
333
|
relation: string;
|
|
334
|
-
scope?:
|
|
334
|
+
scope?: FilterClause;
|
|
335
335
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {Filter} from './filter.js';
|
|
2
1
|
import {ModelData} from '../types.js';
|
|
3
|
-
import {IncludeClause} from './filter.js';
|
|
4
2
|
import {Service} from '@e22m4u/js-service';
|
|
5
|
-
import {
|
|
3
|
+
import {FilterClause} from './filter-clause.js';
|
|
4
|
+
import {IncludeClause} from './filter-clause.js';
|
|
5
|
+
import {NormalizedIncludeClause} from './filter-clause.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Include clause tool.
|
|
@@ -33,7 +33,7 @@ export declare class IncludeClauseTool extends Service {
|
|
|
33
33
|
*
|
|
34
34
|
* @param clause
|
|
35
35
|
*/
|
|
36
|
-
static validateScopeClause(clause:
|
|
36
|
+
static validateScopeClause(clause: FilterClause | undefined): void;
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Normalize include clause.
|
|
@@ -49,5 +49,7 @@ export declare class IncludeClauseTool extends Service {
|
|
|
49
49
|
*
|
|
50
50
|
* @param clause
|
|
51
51
|
*/
|
|
52
|
-
static normalizeScopeClause(
|
|
52
|
+
static normalizeScopeClause(
|
|
53
|
+
clause: FilterClause | undefined,
|
|
54
|
+
): FilterClause | undefined;
|
|
53
55
|
}
|
package/src/filter/index.d.ts
CHANGED
|
@@ -504,7 +504,7 @@ export class OperatorClauseTool extends Service {
|
|
|
504
504
|
const flags = clause.flags || undefined;
|
|
505
505
|
if (flags && typeof flags !== 'string')
|
|
506
506
|
throw new InvalidArgumentError(
|
|
507
|
-
'RegExp flags
|
|
507
|
+
'RegExp flags should be a String, but %v given.',
|
|
508
508
|
clause.flags,
|
|
509
509
|
);
|
|
510
510
|
if (!value || typeof value !== 'string') return false;
|
|
@@ -1049,7 +1049,7 @@ describe('OperatorClauseTool', function () {
|
|
|
1049
1049
|
const throwable = v => () =>
|
|
1050
1050
|
S.testRegexp({regexp: 'Val.+', flags: v}, 'val');
|
|
1051
1051
|
const error = v =>
|
|
1052
|
-
format('RegExp flags
|
|
1052
|
+
format('RegExp flags should be a String, but %s given.', v);
|
|
1053
1053
|
expect(throwable(10)).to.throw(error('10'));
|
|
1054
1054
|
expect(throwable(true)).to.throw(error('true'));
|
|
1055
1055
|
expect(throwable([])).to.throw(error('Array'));
|
|
@@ -13,14 +13,15 @@ export class OrderClauseTool extends Service {
|
|
|
13
13
|
* @param {string|string[]|undefined} clause
|
|
14
14
|
*/
|
|
15
15
|
sort(entities, clause) {
|
|
16
|
-
if (
|
|
17
|
-
if (
|
|
16
|
+
if (clause == null) return;
|
|
17
|
+
if (Array.isArray(clause) === false) clause = [clause];
|
|
18
|
+
if (!clause.length) return;
|
|
18
19
|
const mapping = [];
|
|
19
20
|
clause.forEach((key, index) => {
|
|
20
|
-
if (typeof key !== 'string')
|
|
21
|
+
if (!key || typeof key !== 'string')
|
|
21
22
|
throw new InvalidArgumentError(
|
|
22
|
-
'The provided option "order" should be a String ' +
|
|
23
|
-
'or an Array of String, but %v given.',
|
|
23
|
+
'The provided option "order" should be a non-empty String ' +
|
|
24
|
+
'or an Array of non-empty String, but %v given.',
|
|
24
25
|
key,
|
|
25
26
|
);
|
|
26
27
|
let reverse = 1;
|
|
@@ -40,14 +41,15 @@ export class OrderClauseTool extends Service {
|
|
|
40
41
|
* @param {string|string[]|undefined} clause
|
|
41
42
|
*/
|
|
42
43
|
static validateOrderClause(clause) {
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
if (clause == null) return;
|
|
45
|
+
if (Array.isArray(clause) === false) clause = [clause];
|
|
46
|
+
if (!clause.length) return;
|
|
47
|
+
clause.forEach(field => {
|
|
48
|
+
if (!field || typeof field !== 'string')
|
|
47
49
|
throw new InvalidArgumentError(
|
|
48
50
|
'The provided option "order" should be a non-empty String ' +
|
|
49
|
-
'or an Array of String, but %v given.',
|
|
50
|
-
|
|
51
|
+
'or an Array of non-empty String, but %v given.',
|
|
52
|
+
field,
|
|
51
53
|
);
|
|
52
54
|
});
|
|
53
55
|
}
|
|
@@ -59,14 +61,15 @@ export class OrderClauseTool extends Service {
|
|
|
59
61
|
* @returns {string[]|undefined}
|
|
60
62
|
*/
|
|
61
63
|
static normalizeOrderClause(clause) {
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
clause.
|
|
65
|
-
|
|
64
|
+
if (clause == null) return;
|
|
65
|
+
if (Array.isArray(clause) === false) clause = [clause];
|
|
66
|
+
if (!clause.length) return;
|
|
67
|
+
clause.forEach(field => {
|
|
68
|
+
if (!field || typeof field !== 'string')
|
|
66
69
|
throw new InvalidArgumentError(
|
|
67
70
|
'The provided option "order" should be a non-empty String ' +
|
|
68
|
-
'or an Array of String, but %v given.',
|
|
69
|
-
|
|
71
|
+
'or an Array of non-empty String, but %v given.',
|
|
72
|
+
field,
|
|
70
73
|
);
|
|
71
74
|
});
|
|
72
75
|
return clause;
|