@e22m4u/js-repository 0.8.6 → 0.8.8
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/build-cjs.js +1 -1
- package/dist/cjs/index.cjs +560 -491
- package/package.json +8 -8
- package/src/adapter/adapter-loader.js +2 -5
- package/src/adapter/adapter-loader.spec.js +2 -2
- package/src/adapter/adapter-registry.spec.js +2 -2
- package/src/adapter/builtin/memory-adapter.js +5 -5
- package/src/adapter/builtin/memory-adapter.spec.js +12 -12
- package/src/adapter/decorator/data-sanitizing-decorator.js +1 -2
- package/src/adapter/decorator/default-values-decorator.js +1 -2
- package/src/adapter/decorator/fields-filtering-decorator.js +1 -2
- package/src/adapter/decorator/inclusion-decorator.js +1 -2
- package/src/adapter/decorator/property-uniqueness-decorator.js +1 -2
- package/src/adapter/decorator/required-property-decorator.js +1 -2
- package/src/database-schema.spec.js +3 -5
- package/src/definition/datasource/datasource-definition-validator.js +3 -3
- package/src/definition/datasource/datasource-definition-validator.spec.js +3 -6
- package/src/definition/definition-registry.js +4 -7
- package/src/definition/definition-registry.spec.js +4 -6
- package/src/definition/model/model-data-sanitizer.js +2 -4
- package/src/definition/model/model-definition-utils.js +12 -14
- package/src/definition/model/model-definition-utils.spec.js +12 -21
- package/src/definition/model/model-definition-validator.js +12 -12
- package/src/definition/model/model-definition-validator.spec.js +12 -15
- package/src/definition/model/properties/primary-keys-definition-validator.js +4 -4
- package/src/definition/model/properties/primary-keys-definition-validator.spec.js +8 -8
- package/src/definition/model/properties/properties-definition-validator.js +42 -43
- package/src/definition/model/properties/properties-definition-validator.spec.js +45 -45
- package/src/definition/model/properties/property-uniqueness-validator.js +7 -11
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +57 -60
- package/src/definition/model/properties/required-property-validator.js +1 -1
- package/src/definition/model/properties/required-property-validator.spec.js +1 -1
- package/src/definition/model/relations/relations-definition-validator.js +40 -42
- package/src/definition/model/relations/relations-definition-validator.spec.js +44 -45
- package/src/errors/invalid-operator-value-error.js +1 -1
- package/src/errors/invalid-operator-value-error.spec.js +1 -1
- package/src/filter/fields-clause-tool.js +95 -53
- package/src/filter/fields-clause-tool.spec.js +210 -387
- package/src/filter/include-clause-tool.js +9 -9
- package/src/filter/include-clause-tool.spec.js +4 -4
- package/src/filter/operator-clause-tool.js +20 -32
- package/src/filter/operator-clause-tool.spec.js +25 -49
- package/src/filter/order-clause-tool.js +55 -27
- package/src/filter/order-clause-tool.spec.js +151 -90
- package/src/filter/slice-clause-tool.js +5 -6
- package/src/filter/slice-clause-tool.spec.js +8 -24
- package/src/filter/where-clause-tool.js +18 -11
- package/src/filter/where-clause-tool.spec.js +27 -17
- package/src/relations/belongs-to-resolver.js +18 -30
- package/src/relations/belongs-to-resolver.spec.js +21 -44
- package/src/relations/has-many-resolver.js +28 -44
- package/src/relations/has-many-resolver.spec.js +44 -68
- package/src/relations/has-one-resolver.js +28 -44
- package/src/relations/has-one-resolver.spec.js +44 -68
- package/src/relations/references-many-resolver.js +8 -14
- package/src/relations/references-many-resolver.spec.js +12 -24
- package/src/repository/repository-registry.js +2 -2
- package/src/repository/repository.js +1 -1
- package/src/utils/exclude-object-keys.js +2 -2
- package/src/utils/exclude-object-keys.spec.js +2 -2
- package/src/utils/like-to-regexp.js +1 -2
- package/src/utils/like-to-regexp.spec.js +5 -5
- package/src/utils/model-name-to-model-key.js +1 -1
- package/src/utils/model-name-to-model-key.spec.js +7 -7
- package/src/utils/select-object-keys.js +6 -7
- package/src/utils/select-object-keys.spec.js +3 -6
|
@@ -16,44 +16,64 @@ export class FieldsClauseTool extends Service {
|
|
|
16
16
|
* @returns {object|object[]}
|
|
17
17
|
*/
|
|
18
18
|
filter(input, modelName, clause) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
// input
|
|
20
|
+
if (!input || typeof input !== 'object') {
|
|
21
|
+
throw new InvalidArgumentError(
|
|
22
|
+
'Parameter "input" must be an Object or an Array of Object, ' +
|
|
23
|
+
'but %v was given.',
|
|
24
|
+
input,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
// input[n]
|
|
28
|
+
const isArrayInput = Array.isArray(input);
|
|
29
|
+
if (isArrayInput) {
|
|
30
|
+
input.forEach((entity, index) => {
|
|
31
|
+
if (!entity || typeof entity !== 'object' || Array.isArray(entity)) {
|
|
32
|
+
throw new InvalidArgumentError(
|
|
33
|
+
'Element %d of the parameter "input" must be an Object, ' +
|
|
34
|
+
'but %v was given.',
|
|
35
|
+
index,
|
|
36
|
+
entity,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// modelName
|
|
31
42
|
if (!modelName || typeof modelName !== 'string') {
|
|
32
43
|
throw new InvalidArgumentError(
|
|
33
|
-
'
|
|
34
|
-
'a non-empty String, but %v was given.',
|
|
44
|
+
'Parameter "modelName" must be a non-empty String, but %v was given.',
|
|
35
45
|
modelName,
|
|
36
46
|
);
|
|
37
47
|
}
|
|
38
|
-
|
|
48
|
+
// clause
|
|
39
49
|
if (clause == null) {
|
|
40
50
|
return input;
|
|
41
51
|
}
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
44
|
-
|
|
52
|
+
const isArrayClause = Array.isArray(clause);
|
|
53
|
+
if (!clause || (typeof clause !== 'string' && !isArrayClause)) {
|
|
54
|
+
throw new InvalidArgumentError(
|
|
55
|
+
'Option "fields" must be a non-empty String or an Array ' +
|
|
56
|
+
'of non-empty String, but %v was given.',
|
|
57
|
+
clause,
|
|
58
|
+
);
|
|
45
59
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!
|
|
49
|
-
|
|
50
|
-
'The provided option "fields" should be a non-empty String ' +
|
|
51
|
-
'or an Array of non-empty String, but %v was given.',
|
|
52
|
-
field,
|
|
53
|
-
);
|
|
60
|
+
// clause[n]
|
|
61
|
+
if (isArrayClause) {
|
|
62
|
+
if (!clause.length) {
|
|
63
|
+
return input;
|
|
54
64
|
}
|
|
55
|
-
|
|
56
|
-
|
|
65
|
+
clause.forEach((field, index) => {
|
|
66
|
+
if (!field || typeof field !== 'string') {
|
|
67
|
+
throw new InvalidArgumentError(
|
|
68
|
+
'Element %d of the option "fields" must be a non-empty String, ' +
|
|
69
|
+
'but %v was given.',
|
|
70
|
+
index,
|
|
71
|
+
field,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const fields = isArrayClause ? clause.slice() : [clause];
|
|
57
77
|
const pkPropName =
|
|
58
78
|
this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
59
79
|
modelName,
|
|
@@ -62,8 +82,9 @@ export class FieldsClauseTool extends Service {
|
|
|
62
82
|
fields.push(pkPropName);
|
|
63
83
|
}
|
|
64
84
|
|
|
85
|
+
let entities = isArrayInput ? input : [input];
|
|
65
86
|
entities = entities.map(entity => selectObjectKeys(entity, fields));
|
|
66
|
-
return
|
|
87
|
+
return isArrayInput ? entities : entities[0];
|
|
67
88
|
}
|
|
68
89
|
|
|
69
90
|
/**
|
|
@@ -75,19 +96,28 @@ export class FieldsClauseTool extends Service {
|
|
|
75
96
|
if (clause == null) {
|
|
76
97
|
return;
|
|
77
98
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
// clause
|
|
100
|
+
const isArray = Array.isArray(clause);
|
|
101
|
+
if (!clause || (typeof clause !== 'string' && !isArray)) {
|
|
102
|
+
throw new InvalidArgumentError(
|
|
103
|
+
'Option "fields" must be a non-empty String or an Array ' +
|
|
104
|
+
'of non-empty String, but %v was given.',
|
|
105
|
+
clause,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
// clause[n]
|
|
109
|
+
if (isArray && clause.length > 0) {
|
|
110
|
+
clause.forEach((field, index) => {
|
|
111
|
+
if (!field || typeof field !== 'string') {
|
|
112
|
+
throw new InvalidArgumentError(
|
|
113
|
+
'Element %d of the option "fields" must be a non-empty String, ' +
|
|
114
|
+
'but %v was given.',
|
|
115
|
+
index,
|
|
116
|
+
field,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
81
120
|
}
|
|
82
|
-
fields.forEach(field => {
|
|
83
|
-
if (!field || typeof field !== 'string') {
|
|
84
|
-
throw new InvalidArgumentError(
|
|
85
|
-
'The provided option "fields" should be a non-empty String ' +
|
|
86
|
-
'or an Array of non-empty String, but %v was given.',
|
|
87
|
-
field,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
121
|
}
|
|
92
122
|
|
|
93
123
|
/**
|
|
@@ -100,19 +130,31 @@ export class FieldsClauseTool extends Service {
|
|
|
100
130
|
if (clause == null) {
|
|
101
131
|
return;
|
|
102
132
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
133
|
+
// clause
|
|
134
|
+
const isArray = Array.isArray(clause);
|
|
135
|
+
if (!clause || (typeof clause !== 'string' && !isArray)) {
|
|
136
|
+
throw new InvalidArgumentError(
|
|
137
|
+
'Option "fields" must be a non-empty String or an Array ' +
|
|
138
|
+
'of non-empty String, but %v was given.',
|
|
139
|
+
clause,
|
|
140
|
+
);
|
|
106
141
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
'or an Array of non-empty String, but %v was given.',
|
|
112
|
-
field,
|
|
113
|
-
);
|
|
142
|
+
// clause[n]
|
|
143
|
+
if (isArray) {
|
|
144
|
+
if (!clause.length) {
|
|
145
|
+
return;
|
|
114
146
|
}
|
|
115
|
-
|
|
116
|
-
|
|
147
|
+
clause.forEach((field, index) => {
|
|
148
|
+
if (!field || typeof field !== 'string') {
|
|
149
|
+
throw new InvalidArgumentError(
|
|
150
|
+
'Element %d of the option "fields" must be a non-empty String, ' +
|
|
151
|
+
'but %v was given.',
|
|
152
|
+
index,
|
|
153
|
+
field,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return isArray ? clause : [clause];
|
|
117
159
|
}
|
|
118
160
|
}
|