ngx-material-entity 20.0.5 → 20.0.6
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/fesm2022/ngx-material-entity.mjs +156 -153
- package/fesm2022/ngx-material-entity.mjs.map +1 -1
- package/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -2204,7 +2204,7 @@ class ValidationUtilities {
|
|
|
2204
2204
|
static async getEntityValidationErrors(entity, injector, omit) {
|
|
2205
2205
|
const res = [];
|
|
2206
2206
|
for (const key of EntityUtilities.keysOf(entity, injector)) {
|
|
2207
|
-
const err = await this.getPropertyValidationError(entity, key, omit);
|
|
2207
|
+
const err = await this.getPropertyValidationError(entity, key, injector, omit);
|
|
2208
2208
|
if (err) {
|
|
2209
2209
|
res.push(err);
|
|
2210
2210
|
}
|
|
@@ -2231,177 +2231,180 @@ class ValidationUtilities {
|
|
|
2231
2231
|
* Validates the property on the given entity with the given key.
|
|
2232
2232
|
* @param entity - The entity on which the property to check is.
|
|
2233
2233
|
* @param key - The key of the property to validate.
|
|
2234
|
+
* @param injector - An angular environment injector.
|
|
2234
2235
|
* @param omit - What keys not to check. An empty value means no keys are omitted.
|
|
2235
2236
|
* @returns A validation error when the property is not valid, undefined otherwise.
|
|
2236
2237
|
* @throws When the type of the property is not known.
|
|
2237
2238
|
*/
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
}
|
|
2244
|
-
const metadata = EntityUtilities.getPropertyMetadata(entity, key, type);
|
|
2245
|
-
// istanbul ignore next
|
|
2246
|
-
if (metadata == undefined) {
|
|
2247
|
-
return undefined;
|
|
2248
|
-
}
|
|
2249
|
-
if (metadata.omitForCreate && omit === 'create') {
|
|
2250
|
-
return undefined;
|
|
2251
|
-
}
|
|
2252
|
-
if (metadata.omitForUpdate && omit === 'update') {
|
|
2253
|
-
return undefined;
|
|
2254
|
-
}
|
|
2255
|
-
if (type !== DecoratorTypes.HAS_MANY && metadata.required(entity) && (entity[key] == undefined || entity[key] === '')) {
|
|
2256
|
-
return {
|
|
2257
|
-
property: metadata.displayName,
|
|
2258
|
-
message: 'required'
|
|
2259
|
-
};
|
|
2260
|
-
}
|
|
2261
|
-
if (!metadata.required(entity) && (entity[key] == undefined || entity[key] === '')) {
|
|
2262
|
-
return undefined;
|
|
2263
|
-
}
|
|
2264
|
-
switch (type) {
|
|
2265
|
-
case DecoratorTypes.BOOLEAN_DROPDOWN: {
|
|
2266
|
-
// Because only valid values can be selected, this is always true when it has a value
|
|
2239
|
+
static async getPropertyValidationError(entity, key, injector, omit) {
|
|
2240
|
+
// eslint-disable-next-line sonar/cognitive-complexity
|
|
2241
|
+
return runInInjectionContext(injector, async () => {
|
|
2242
|
+
const type = EntityUtilities.getPropertyType(entity, key);
|
|
2243
|
+
if (type == undefined) {
|
|
2267
2244
|
return undefined;
|
|
2268
2245
|
}
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
const booleanMetadata = metadata;
|
|
2273
|
-
return this.getBooleanValidationError(entity, entityBoolean, booleanMetadata);
|
|
2274
|
-
}
|
|
2275
|
-
case DecoratorTypes.STRING_DROPDOWN: {
|
|
2276
|
-
// Because only valid values can be selected, this is always true when it has a value
|
|
2246
|
+
const metadata = EntityUtilities.getPropertyMetadata(entity, key, type);
|
|
2247
|
+
// istanbul ignore next
|
|
2248
|
+
if (metadata == undefined) {
|
|
2277
2249
|
return undefined;
|
|
2278
2250
|
}
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
const stringMetadata = metadata;
|
|
2282
|
-
return this.getStringValidationError(entityString, stringMetadata);
|
|
2283
|
-
}
|
|
2284
|
-
case DecoratorTypes.STRING_AUTOCOMPLETE: {
|
|
2285
|
-
const entityAutocompleteString = entity[key];
|
|
2286
|
-
// eslint-disable-next-line stylistic/max-len
|
|
2287
|
-
const stringAutocompleteMetadata = metadata;
|
|
2288
|
-
return this.getAutocompleteStringValidationError(entity, entityAutocompleteString, stringAutocompleteMetadata);
|
|
2251
|
+
if (metadata.omitForCreate && omit === 'create') {
|
|
2252
|
+
return undefined;
|
|
2289
2253
|
}
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
const textboxMetadata = metadata;
|
|
2293
|
-
return this.getTextboxValidationError(entityTextbox, textboxMetadata);
|
|
2254
|
+
if (metadata.omitForUpdate && omit === 'update') {
|
|
2255
|
+
return undefined;
|
|
2294
2256
|
}
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2257
|
+
if (type !== DecoratorTypes.HAS_MANY && metadata.required(entity) && (entity[key] == undefined || entity[key] === '')) {
|
|
2258
|
+
return {
|
|
2259
|
+
property: metadata.displayName,
|
|
2260
|
+
message: 'required'
|
|
2261
|
+
};
|
|
2300
2262
|
}
|
|
2301
|
-
|
|
2302
|
-
// Because only valid values can be selected, this is always true when it has a value
|
|
2263
|
+
if (!metadata.required(entity) && (entity[key] == undefined || entity[key] === '')) {
|
|
2303
2264
|
return undefined;
|
|
2304
2265
|
}
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2266
|
+
switch (type) {
|
|
2267
|
+
case DecoratorTypes.BOOLEAN_DROPDOWN: {
|
|
2268
|
+
// Because only valid values can be selected, this is always true when it has a value
|
|
2269
|
+
return undefined;
|
|
2270
|
+
}
|
|
2271
|
+
case DecoratorTypes.BOOLEAN_CHECKBOX:
|
|
2272
|
+
case DecoratorTypes.BOOLEAN_TOGGLE: {
|
|
2273
|
+
const entityBoolean = entity[key];
|
|
2274
|
+
const booleanMetadata = metadata;
|
|
2275
|
+
return this.getBooleanValidationError(entity, entityBoolean, booleanMetadata);
|
|
2276
|
+
}
|
|
2277
|
+
case DecoratorTypes.STRING_DROPDOWN: {
|
|
2278
|
+
// Because only valid values can be selected, this is always true when it has a value
|
|
2279
|
+
return undefined;
|
|
2280
|
+
}
|
|
2281
|
+
case DecoratorTypes.STRING: {
|
|
2282
|
+
const entityString = entity[key];
|
|
2283
|
+
const stringMetadata = metadata;
|
|
2284
|
+
return this.getStringValidationError(entityString, stringMetadata);
|
|
2285
|
+
}
|
|
2286
|
+
case DecoratorTypes.STRING_AUTOCOMPLETE: {
|
|
2287
|
+
const entityAutocompleteString = entity[key];
|
|
2288
|
+
// eslint-disable-next-line stylistic/max-len
|
|
2289
|
+
const stringAutocompleteMetadata = metadata;
|
|
2290
|
+
return this.getAutocompleteStringValidationError(entity, entityAutocompleteString, stringAutocompleteMetadata);
|
|
2291
|
+
}
|
|
2292
|
+
case DecoratorTypes.STRING_TEXTBOX: {
|
|
2293
|
+
const entityTextbox = entity[key];
|
|
2294
|
+
const textboxMetadata = metadata;
|
|
2295
|
+
return this.getTextboxValidationError(entityTextbox, textboxMetadata);
|
|
2296
|
+
}
|
|
2297
|
+
case DecoratorTypes.STRING_PASSWORD: {
|
|
2298
|
+
const entityPassword = entity[key];
|
|
2299
|
+
const passwordMetadata = metadata;
|
|
2300
|
+
const confirmPassword = ReflectUtilities.getMetadata(EntityUtilities.CONFIRM_PASSWORD_KEY, entity, key);
|
|
2301
|
+
return this.getPasswordValidationError(entityPassword, passwordMetadata, confirmPassword);
|
|
2302
|
+
}
|
|
2303
|
+
case DecoratorTypes.NUMBER_DROPDOWN: {
|
|
2304
|
+
// Because only valid values can be selected, this is always true when it has a value
|
|
2305
|
+
return undefined;
|
|
2306
|
+
}
|
|
2307
|
+
case DecoratorTypes.NUMBER:
|
|
2308
|
+
case DecoratorTypes.NUMBER_SLIDER: {
|
|
2309
|
+
const entityNumber = entity[key];
|
|
2310
|
+
const numberMetadata = metadata;
|
|
2311
|
+
return this.getNumberValidationError(entityNumber, numberMetadata);
|
|
2312
|
+
}
|
|
2313
|
+
case DecoratorTypes.OBJECT: {
|
|
2314
|
+
const entityObject = entity[key];
|
|
2315
|
+
for (const parameterKey in entityObject) {
|
|
2316
|
+
const value = entityObject[parameterKey];
|
|
2317
|
+
if (!metadata.omit.includes(parameterKey)
|
|
2318
|
+
&& !(!metadata.required(entity) && (value == undefined || value == ''))) {
|
|
2319
|
+
const err = await this.getPropertyValidationError(entityObject, parameterKey, injector, omit);
|
|
2320
|
+
if (err) {
|
|
2321
|
+
return {
|
|
2322
|
+
property: metadata.displayName,
|
|
2323
|
+
message: `${err.property} is invalid: ${err.message}`
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2323
2326
|
}
|
|
2324
2327
|
}
|
|
2328
|
+
break;
|
|
2325
2329
|
}
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
// Because only valid values can be selected, this is always true when it has a value
|
|
2330
|
-
return undefined;
|
|
2331
|
-
}
|
|
2332
|
-
case DecoratorTypes.ARRAY_STRING_AUTOCOMPLETE_CHIPS: {
|
|
2333
|
-
const stringAutocompleteArray = entity[key];
|
|
2334
|
-
// eslint-disable-next-line stylistic/max-len
|
|
2335
|
-
const stringAutocompleteArrayMetadata = metadata;
|
|
2336
|
-
// eslint-disable-next-line stylistic/max-len
|
|
2337
|
-
return await this.getArrayStringAutocompleteChipsValidationError(entity, stringAutocompleteArrayMetadata, stringAutocompleteArray);
|
|
2338
|
-
}
|
|
2339
|
-
case DecoratorTypes.ARRAY_STRING_DROPDOWN: {
|
|
2340
|
-
const stringDropdownArray = entity[key];
|
|
2341
|
-
// eslint-disable-next-line stylistic/max-len
|
|
2342
|
-
const stringDropdownArrayMetadata = metadata;
|
|
2343
|
-
return await this.getArrayStringDropdownValidationError(entity, stringDropdownArrayMetadata, stringDropdownArray);
|
|
2344
|
-
}
|
|
2345
|
-
case DecoratorTypes.ARRAY_STRING_CHIPS:
|
|
2346
|
-
case DecoratorTypes.ARRAY_DATE:
|
|
2347
|
-
case DecoratorTypes.ARRAY_DATE_TIME:
|
|
2348
|
-
case DecoratorTypes.ARRAY_DATE_RANGE:
|
|
2349
|
-
case DecoratorTypes.ARRAY:
|
|
2350
|
-
case DecoratorTypes.REFERENCES_MANY: {
|
|
2351
|
-
const entityArray = entity[key];
|
|
2352
|
-
// eslint-disable-next-line stylistic/max-len
|
|
2353
|
-
const arrayMetadata = metadata;
|
|
2354
|
-
if (arrayMetadata.required(entity) && !entityArray.length) {
|
|
2355
|
-
return {
|
|
2356
|
-
property: metadata.displayName,
|
|
2357
|
-
// eslint-disable-next-line sonar/no-duplicate-string
|
|
2358
|
-
message: 'no items in array'
|
|
2359
|
-
};
|
|
2330
|
+
case DecoratorTypes.OBJECT_DROPDOWN: {
|
|
2331
|
+
// Because only valid values can be selected, this is always true when it has a value
|
|
2332
|
+
return undefined;
|
|
2360
2333
|
}
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2334
|
+
case DecoratorTypes.ARRAY_STRING_AUTOCOMPLETE_CHIPS: {
|
|
2335
|
+
const stringAutocompleteArray = entity[key];
|
|
2336
|
+
// eslint-disable-next-line stylistic/max-len
|
|
2337
|
+
const stringAutocompleteArrayMetadata = metadata;
|
|
2338
|
+
// eslint-disable-next-line stylistic/max-len
|
|
2339
|
+
return await this.getArrayStringAutocompleteChipsValidationError(entity, stringAutocompleteArrayMetadata, stringAutocompleteArray);
|
|
2340
|
+
}
|
|
2341
|
+
case DecoratorTypes.ARRAY_STRING_DROPDOWN: {
|
|
2342
|
+
const stringDropdownArray = entity[key];
|
|
2343
|
+
// eslint-disable-next-line stylistic/max-len
|
|
2344
|
+
const stringDropdownArrayMetadata = metadata;
|
|
2345
|
+
return await this.getArrayStringDropdownValidationError(entity, stringDropdownArrayMetadata, stringDropdownArray);
|
|
2346
|
+
}
|
|
2347
|
+
case DecoratorTypes.ARRAY_STRING_CHIPS:
|
|
2348
|
+
case DecoratorTypes.ARRAY_DATE:
|
|
2349
|
+
case DecoratorTypes.ARRAY_DATE_TIME:
|
|
2350
|
+
case DecoratorTypes.ARRAY_DATE_RANGE:
|
|
2351
|
+
case DecoratorTypes.ARRAY:
|
|
2352
|
+
case DecoratorTypes.REFERENCES_MANY: {
|
|
2353
|
+
const entityArray = entity[key];
|
|
2354
|
+
// eslint-disable-next-line stylistic/max-len
|
|
2355
|
+
const arrayMetadata = metadata;
|
|
2356
|
+
if (arrayMetadata.required(entity) && !entityArray.length) {
|
|
2357
|
+
return {
|
|
2358
|
+
property: metadata.displayName,
|
|
2359
|
+
// eslint-disable-next-line sonar/no-duplicate-string
|
|
2360
|
+
message: 'no items in array'
|
|
2361
|
+
};
|
|
2362
|
+
}
|
|
2363
|
+
break;
|
|
2364
|
+
}
|
|
2365
|
+
case DecoratorTypes.DATE: {
|
|
2366
|
+
const entityDate = new Date(entity[key]);
|
|
2367
|
+
const dateMetadata = metadata;
|
|
2368
|
+
return this.getDateValidationError(entityDate, dateMetadata);
|
|
2369
|
+
}
|
|
2370
|
+
case DecoratorTypes.DATE_RANGE: {
|
|
2371
|
+
const entityDateRange = LodashUtilities.cloneDeep(entity[key]);
|
|
2372
|
+
const dateRangeMetadata = metadata;
|
|
2373
|
+
return this.getDateRangeValidationError(entity, entityDateRange, dateRangeMetadata);
|
|
2374
|
+
}
|
|
2375
|
+
case DecoratorTypes.DATE_TIME: {
|
|
2376
|
+
const entityDateTime = new Date(entity[key]);
|
|
2377
|
+
const dateTimeMetadata = metadata;
|
|
2378
|
+
const hasTime = ReflectUtilities.hasMetadata(EntityUtilities.TIME_KEY, entity, key);
|
|
2379
|
+
return this.getDateTimeValidationError(entityDateTime, dateTimeMetadata, hasTime);
|
|
2380
|
+
}
|
|
2381
|
+
case DecoratorTypes.FILE_DEFAULT:
|
|
2382
|
+
case DecoratorTypes.FILE_IMAGE: {
|
|
2383
|
+
const entityFile = entity[key];
|
|
2384
|
+
const entityFileMetadata = metadata;
|
|
2385
|
+
return this.getFileDataValidationError(entityFile, entityFileMetadata);
|
|
2386
|
+
}
|
|
2387
|
+
case DecoratorTypes.REFERENCES_ONE:
|
|
2388
|
+
case DecoratorTypes.HAS_MANY: {
|
|
2389
|
+
break;
|
|
2390
|
+
}
|
|
2391
|
+
case DecoratorTypes.CUSTOM: {
|
|
2392
|
+
// eslint-disable-next-line typescript/no-explicit-any, stylistic/max-len
|
|
2393
|
+
const customMetadata = metadata;
|
|
2394
|
+
if (!customMetadata.isValid(entity[key], omit)) {
|
|
2395
|
+
return {
|
|
2396
|
+
property: metadata.displayName,
|
|
2397
|
+
message: 'invalid'
|
|
2398
|
+
};
|
|
2399
|
+
}
|
|
2400
|
+
break;
|
|
2401
|
+
}
|
|
2402
|
+
default: {
|
|
2403
|
+
throw new Error(`Could not validate the input because the DecoratorType ${type} is not known`);
|
|
2397
2404
|
}
|
|
2398
|
-
break;
|
|
2399
|
-
}
|
|
2400
|
-
default: {
|
|
2401
|
-
throw new Error(`Could not validate the input because the DecoratorType ${type} is not known`);
|
|
2402
2405
|
}
|
|
2403
|
-
|
|
2404
|
-
|
|
2406
|
+
return undefined;
|
|
2407
|
+
});
|
|
2405
2408
|
}
|
|
2406
2409
|
static async getArrayStringAutocompleteChipsValidationError(entity, metadata, stringAutocompleteArray) {
|
|
2407
2410
|
if (metadata.required(entity) && !stringAutocompleteArray.length) {
|