@punks/backend-entity-manager 0.0.378 → 0.0.380
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/dist/cjs/index.js +49 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/serializer.d.ts +2 -0
- package/dist/cjs/types/utils/index.d.ts +1 -1
- package/dist/cjs/types/utils/validators.d.ts +9 -0
- package/dist/esm/index.js +48 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/serializer.d.ts +2 -0
- package/dist/esm/types/utils/index.d.ts +1 -1
- package/dist/esm/types/utils/validators.d.ts +9 -0
- package/dist/index.d.ts +13 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -272,13 +272,16 @@ class EntitySerializer {
|
|
|
272
272
|
for (const validator of column.validators ?? []) {
|
|
273
273
|
const result = validator.fn(entity);
|
|
274
274
|
if (!result.isValid) {
|
|
275
|
-
validationErrors
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
275
|
+
for (const error of result.validationErrors) {
|
|
276
|
+
validationErrors.push({
|
|
277
|
+
errorCode: error.errorCode,
|
|
278
|
+
column: {
|
|
279
|
+
name: column.name,
|
|
280
|
+
key: column.key,
|
|
281
|
+
value: error.value,
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
}
|
|
282
285
|
}
|
|
283
286
|
}
|
|
284
287
|
}
|
|
@@ -40721,6 +40724,43 @@ const fieldRequiredValidator = (item, selector) => {
|
|
|
40721
40724
|
validationErrors: value ? [] : [{ errorCode: "required" }],
|
|
40722
40725
|
};
|
|
40723
40726
|
};
|
|
40727
|
+
const fieldOptionValidator = (item, selector, { availableOptions, required, }) => {
|
|
40728
|
+
const value = selector(item);
|
|
40729
|
+
if (!value) {
|
|
40730
|
+
return {
|
|
40731
|
+
isValid: true,
|
|
40732
|
+
validationErrors: [],
|
|
40733
|
+
};
|
|
40734
|
+
}
|
|
40735
|
+
const errors = [];
|
|
40736
|
+
const isValidOption = availableOptions.includes(value);
|
|
40737
|
+
if (!isValidOption) {
|
|
40738
|
+
errors.push({ errorCode: "invalidOption" });
|
|
40739
|
+
}
|
|
40740
|
+
if (required && !value) {
|
|
40741
|
+
errors.push({ errorCode: "required" });
|
|
40742
|
+
}
|
|
40743
|
+
return {
|
|
40744
|
+
isValid: errors.length === 0,
|
|
40745
|
+
validationErrors: errors,
|
|
40746
|
+
};
|
|
40747
|
+
};
|
|
40748
|
+
const fieldOptionsValidator = (item, selector, { availableOptions, minSelected, maxSelected, }) => {
|
|
40749
|
+
const values = selector(item);
|
|
40750
|
+
const errors = [];
|
|
40751
|
+
const invalidOptions = values.filter((x) => !availableOptions.includes(x));
|
|
40752
|
+
invalidOptions.forEach((x) => errors.push({ errorCode: "invalidOption", value: x }));
|
|
40753
|
+
if (minSelected && values.length < minSelected) {
|
|
40754
|
+
errors.push({ errorCode: "minSelected" });
|
|
40755
|
+
}
|
|
40756
|
+
if (maxSelected && values.length > maxSelected) {
|
|
40757
|
+
errors.push({ errorCode: "maxSelected" });
|
|
40758
|
+
}
|
|
40759
|
+
return {
|
|
40760
|
+
isValid: errors.length === 0,
|
|
40761
|
+
validationErrors: errors,
|
|
40762
|
+
};
|
|
40763
|
+
};
|
|
40724
40764
|
|
|
40725
40765
|
const createClient$2 = (settings) => new clientSes.SESClient({
|
|
40726
40766
|
region: settings.region,
|
|
@@ -44834,6 +44874,8 @@ exports.buildProviderToken = buildProviderToken;
|
|
|
44834
44874
|
exports.buildRolesGuard = buildRolesGuard;
|
|
44835
44875
|
exports.createContainer = createContainer;
|
|
44836
44876
|
exports.createExpressFileResponse = createExpressFileResponse;
|
|
44877
|
+
exports.fieldOptionValidator = fieldOptionValidator;
|
|
44878
|
+
exports.fieldOptionsValidator = fieldOptionsValidator;
|
|
44837
44879
|
exports.fieldRequiredValidator = fieldRequiredValidator;
|
|
44838
44880
|
exports.getEntityManagerProviderToken = getEntityManagerProviderToken;
|
|
44839
44881
|
exports.getLocalizedText = getLocalizedText;
|