remult 0.25.6-exp.3 → 0.25.6-exp.5
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.
|
@@ -173,7 +173,18 @@ export class Filter {
|
|
|
173
173
|
__applyToConsumer(add) {
|
|
174
174
|
this.apply(add);
|
|
175
175
|
}
|
|
176
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Resolves an entity filter.
|
|
178
|
+
*
|
|
179
|
+
* This method takes a filter which can be either an instance of `EntityFilter`
|
|
180
|
+
* or a function that returns an instance of `EntityFilter` or a promise that
|
|
181
|
+
* resolves to an instance of `EntityFilter`. It then resolves the filter if it
|
|
182
|
+
* is a function and returns the resulting `EntityFilter`.
|
|
183
|
+
*
|
|
184
|
+
* @template entityType The type of the entity that the filter applies to.
|
|
185
|
+
* @param {EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>)} filter The filter to resolve.
|
|
186
|
+
* @returns {Promise<EntityFilter<entityType>>} The resolved entity filter.
|
|
187
|
+
*/
|
|
177
188
|
static async resolve(filter) {
|
|
178
189
|
if (typeof filter === 'function')
|
|
179
190
|
return await filter();
|
package/esm/src/validators.js
CHANGED
|
@@ -89,12 +89,12 @@ export function createValueValidator(validate, defaultMessage) {
|
|
|
89
89
|
}, defaultMessage);
|
|
90
90
|
}
|
|
91
91
|
export function createValueValidatorWithArgs(validate, defaultMessage) {
|
|
92
|
-
const result =
|
|
92
|
+
const result = createValidatorWithArgsInternal((_, e, args) => {
|
|
93
93
|
if (e.value === undefined || e.value === null)
|
|
94
94
|
return true;
|
|
95
95
|
return validate(e.value, args);
|
|
96
96
|
}, (_, e, args) => (typeof defaultMessage === 'function' && defaultMessage(args)) ||
|
|
97
|
-
defaultMessage);
|
|
97
|
+
defaultMessage, true);
|
|
98
98
|
return Object.assign((entity, e) => result(entity, e), {
|
|
99
99
|
get defaultMessage() {
|
|
100
100
|
return defaultMessage;
|
|
@@ -105,13 +105,21 @@ export function createValueValidatorWithArgs(validate, defaultMessage) {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
export function createValidatorWithArgs(validate, defaultMessage) {
|
|
108
|
+
return createValidatorWithArgsInternal(validate, defaultMessage);
|
|
109
|
+
}
|
|
110
|
+
function createValidatorWithArgsInternal(validate, defaultMessage, isValueValidator = false) {
|
|
108
111
|
const result = (args, message) => async (entity, e) => {
|
|
109
112
|
const valid = await validate(entity, e, args);
|
|
110
113
|
if (typeof valid === 'string')
|
|
111
114
|
e.error = valid;
|
|
112
115
|
else if (!valid)
|
|
113
|
-
e.error =
|
|
114
|
-
message
|
|
116
|
+
e.error = message
|
|
117
|
+
? typeof message === 'function'
|
|
118
|
+
? isValueValidator
|
|
119
|
+
? message(args)
|
|
120
|
+
: message(entity, e, args)
|
|
121
|
+
: message
|
|
122
|
+
: defaultMessage
|
|
115
123
|
? typeof defaultMessage === 'function'
|
|
116
124
|
? defaultMessage(entity, e, args)
|
|
117
125
|
: defaultMessage
|
package/package.json
CHANGED
|
@@ -122,6 +122,19 @@ export declare class Filter {
|
|
|
122
122
|
static fromEntityFilter<T>(entity: EntityMetadata<T>, whereItem: EntityFilter<T>): Filter;
|
|
123
123
|
constructor(apply: (add: FilterConsumer) => void);
|
|
124
124
|
__applyToConsumer(add: FilterConsumer): void;
|
|
125
|
+
/**
|
|
126
|
+
* Resolves an entity filter.
|
|
127
|
+
*
|
|
128
|
+
* This method takes a filter which can be either an instance of `EntityFilter`
|
|
129
|
+
* or a function that returns an instance of `EntityFilter` or a promise that
|
|
130
|
+
* resolves to an instance of `EntityFilter`. It then resolves the filter if it
|
|
131
|
+
* is a function and returns the resulting `EntityFilter`.
|
|
132
|
+
*
|
|
133
|
+
* @template entityType The type of the entity that the filter applies to.
|
|
134
|
+
* @param {EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>)} filter The filter to resolve.
|
|
135
|
+
* @returns {Promise<EntityFilter<entityType>>} The resolved entity filter.
|
|
136
|
+
*/
|
|
137
|
+
static resolve<entityType>(filter: EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>)): Promise<EntityFilter<entityType>>;
|
|
125
138
|
}
|
|
126
139
|
export interface FilterConsumer {
|
|
127
140
|
or(orElements: Filter[]): any;
|
|
@@ -181,7 +181,18 @@ var Filter = /** @class */ (function () {
|
|
|
181
181
|
Filter.prototype.__applyToConsumer = function (add) {
|
|
182
182
|
this.apply(add);
|
|
183
183
|
};
|
|
184
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Resolves an entity filter.
|
|
186
|
+
*
|
|
187
|
+
* This method takes a filter which can be either an instance of `EntityFilter`
|
|
188
|
+
* or a function that returns an instance of `EntityFilter` or a promise that
|
|
189
|
+
* resolves to an instance of `EntityFilter`. It then resolves the filter if it
|
|
190
|
+
* is a function and returns the resulting `EntityFilter`.
|
|
191
|
+
*
|
|
192
|
+
* @template entityType The type of the entity that the filter applies to.
|
|
193
|
+
* @param {EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>)} filter The filter to resolve.
|
|
194
|
+
* @returns {Promise<EntityFilter<entityType>>} The resolved entity filter.
|
|
195
|
+
*/
|
|
185
196
|
Filter.resolve = function (filter) {
|
|
186
197
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
187
198
|
return tslib_1.__generator(this, function (_a) {
|
package/src/validators.js
CHANGED
|
@@ -146,14 +146,14 @@ function createValueValidator(validate, defaultMessage) {
|
|
|
146
146
|
}
|
|
147
147
|
exports.createValueValidator = createValueValidator;
|
|
148
148
|
function createValueValidatorWithArgs(validate, defaultMessage) {
|
|
149
|
-
var result =
|
|
149
|
+
var result = createValidatorWithArgsInternal(function (_, e, args) {
|
|
150
150
|
if (e.value === undefined || e.value === null)
|
|
151
151
|
return true;
|
|
152
152
|
return validate(e.value, args);
|
|
153
153
|
}, function (_, e, args) {
|
|
154
154
|
return (typeof defaultMessage === 'function' && defaultMessage(args)) ||
|
|
155
155
|
defaultMessage;
|
|
156
|
-
});
|
|
156
|
+
}, true);
|
|
157
157
|
return Object.assign(function (entity, e) { return result(entity, e); }, {
|
|
158
158
|
get defaultMessage() {
|
|
159
159
|
return defaultMessage;
|
|
@@ -165,7 +165,12 @@ function createValueValidatorWithArgs(validate, defaultMessage) {
|
|
|
165
165
|
}
|
|
166
166
|
exports.createValueValidatorWithArgs = createValueValidatorWithArgs;
|
|
167
167
|
function createValidatorWithArgs(validate, defaultMessage) {
|
|
168
|
+
return createValidatorWithArgsInternal(validate, defaultMessage);
|
|
169
|
+
}
|
|
170
|
+
exports.createValidatorWithArgs = createValidatorWithArgs;
|
|
171
|
+
function createValidatorWithArgsInternal(validate, defaultMessage, isValueValidator) {
|
|
168
172
|
var _this = this;
|
|
173
|
+
if (isValueValidator === void 0) { isValueValidator = false; }
|
|
169
174
|
var result = function (args, message) {
|
|
170
175
|
return function (entity, e) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
171
176
|
var valid;
|
|
@@ -177,8 +182,13 @@ function createValidatorWithArgs(validate, defaultMessage) {
|
|
|
177
182
|
if (typeof valid === 'string')
|
|
178
183
|
e.error = valid;
|
|
179
184
|
else if (!valid)
|
|
180
|
-
e.error =
|
|
181
|
-
message
|
|
185
|
+
e.error = message
|
|
186
|
+
? typeof message === 'function'
|
|
187
|
+
? isValueValidator
|
|
188
|
+
? message(args)
|
|
189
|
+
: message(entity, e, args)
|
|
190
|
+
: message
|
|
191
|
+
: defaultMessage
|
|
182
192
|
? typeof defaultMessage === 'function'
|
|
183
193
|
? defaultMessage(entity, e, args)
|
|
184
194
|
: defaultMessage
|
|
@@ -197,4 +207,3 @@ function createValidatorWithArgs(validate, defaultMessage) {
|
|
|
197
207
|
},
|
|
198
208
|
});
|
|
199
209
|
}
|
|
200
|
-
exports.createValidatorWithArgs = createValidatorWithArgs;
|