@arsedizioni/ars-utils 22.6.82 → 22.6.85

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.
@@ -888,20 +888,21 @@ function isValidItalianFiscalCode(value) {
888
888
  * leave the map with a kind nobody produces.
889
889
  */
890
890
  /**
891
- * Earliest date {@link date} and {@link dateRange} accept: 1 January 1970.
891
+ * Earliest year {@link date} and {@link dateRange} accept: 1750.
892
892
  *
893
- * Everything this application stores — events, certificates, payments, communications — happened
894
- * after it, so an earlier value is always a typo (a two-digit year, a slipped keystroke) and never
895
- * real data. The floor is deliberately higher than the one of {@link sqlDate}, which only asks
896
- * what SQL Server can physically store.
893
+ * It is the floor of what the backend can store, and it is set that low on purpose: a birth date,
894
+ * the date of an old norm or the commissioning of an old machine are real data well before 1970.
895
+ * What it does catch is the 01/01/0001 or 01/01/0020 that a mistyped year produces, which SQL
896
+ * Server would reject with an error nobody can read.
897
897
  */
898
- const MIN_VALID_YEAR = 1970;
898
+ const MIN_VALID_YEAR = 1750;
899
899
  const ARS_VALIDATOR_MESSAGES = {
900
900
  required: 'Obbligatorio',
901
901
  guid: 'Ticket non riconosciuto',
902
902
  password: 'Password non sufficientemente robusta',
903
903
  notEmpty: 'Non può essere vuoto o contenere solo spazi.',
904
904
  notEqual: 'Deve essere diverso dall\'altro valore',
905
+ // Emitted by `SqlDateValidatorDirective`, which a `[formField]` on a ControlValueAccessor still reads.
905
906
  sqlDate: 'Data non valida',
906
907
  date: 'Data non valida',
907
908
  dateRange: 'Intervallo non valido',
@@ -1019,31 +1020,6 @@ function notEqual(path, other, config) {
1019
1020
  return isValid ? null : { kind: 'notEqual', message: config?.message ?? ARS_VALIDATOR_MESSAGES['notEqual'] };
1020
1021
  });
1021
1022
  }
1022
- /**
1023
- * Requires the value to be a date the backend can store: parseable, and after 1750.
1024
- *
1025
- * The signal-form counterpart of `SqlDateValidatorDirective`. The year floor is not arbitrary —
1026
- * it is what separates a real date from the 01/01/0001 that a mistyped year produces, which SQL
1027
- * Server rejects with an error nobody can read.
1028
- *
1029
- * @param path - Path of the field to validate.
1030
- * @param config - Optional message override and `when` condition.
1031
- * @returns void
1032
- */
1033
- function sqlDate(path, config) {
1034
- validate(path, ctx => {
1035
- if (config?.when && !config.when(ctx))
1036
- return null;
1037
- const input = ctx.value();
1038
- if (!input || input.length === 0)
1039
- return null;
1040
- const parsed = SystemUtils.parseDate(input);
1041
- const invalid = { kind: 'sqlDate', message: config?.message ?? ARS_VALIDATOR_MESSAGES['sqlDate'] };
1042
- if (!parsed)
1043
- return invalid;
1044
- return endOfDay(parsed).getFullYear() > 1750 ? null : invalid;
1045
- });
1046
- }
1047
1023
  /**
1048
1024
  * Requires the value to be a real date, as {@link SystemUtils.parseDate} understands one.
1049
1025
  *
@@ -1052,11 +1028,11 @@ function sqlDate(path, config) {
1052
1028
  * `parseDate` handles the shapes this codebase produces (ISO, `dd/MM/yyyy`, `yyyy-MM-dd`, and the
1053
1029
  * shorthand forms). Empty passes — saying "obbligatorio" is the job of `required()`.
1054
1030
  *
1055
- * A date earlier than {@link MIN_VALID_YEAR} (1 January 1970) is rejected: nothing this
1056
- * application stores predates it, so an earlier value is a typo rather than data.
1031
+ * A date earlier than {@link MIN_VALID_YEAR} (1750) is rejected: it is what the backend can
1032
+ * store, so an earlier value is a mistyped year rather than data.
1057
1033
  *
1058
- * Distinct from {@link sqlDate} on purpose: that one is about what the DATABASE can store (the
1059
- * 1750 floor), this one is about whether the value is a date at all. Pair them when both matter.
1034
+ * It is also the signal-form counterpart of `SqlDateValidatorDirective`: one rule for every date,
1035
+ * whether it is typed or picked.
1060
1036
  *
1061
1037
  * @param path - Path of the field to validate.
1062
1038
  * @param config - Optional message override and `when` condition.
@@ -1083,7 +1059,7 @@ function date(path, config) {
1083
1059
  * Written for the two inputs of a `mat-date-range-input`, whose start and end live in two
1084
1060
  * separate fields of the model. Each end is checked with the same rule as {@link date}, and the
1085
1061
  * ordering is checked only when BOTH ends are filled in — a half-open range ("from today
1086
- * onwards") is a legitimate filter, not an error. The 1 January 1970 floor of {@link date}
1062
+ * onwards") is a legitimate filter, not an error. The {@link MIN_VALID_YEAR} floor of {@link date}
1087
1063
  * applies to both ends.
1088
1064
  *
1089
1065
  * The rule is bound to BOTH paths, so the error appears on whichever end the user is looking at
@@ -1140,16 +1116,22 @@ function dateRange(from, to, config) {
1140
1116
  * comparison is made on the end of the day, so a date entered this morning does not become
1141
1117
  * invalid because the clock says 09:00.
1142
1118
  *
1119
+ * Like {@link notPast}, it accepts both the `Date` a Material datepicker writes into the model and
1120
+ * the text of a plain input. An empty value passes: saying "obbligatorio" is the job of
1121
+ * `required()`.
1122
+ *
1143
1123
  * @param path - Path of the field to validate.
1144
1124
  * @param config - Optional message override and `when` condition.
1145
1125
  * @returns void
1126
+ * @example
1127
+ * const f = form(this.model, p => { required(p.executionDate); notFuture(p.executionDate); });
1146
1128
  */
1147
1129
  function notFuture(path, config) {
1148
1130
  validate(path, ctx => {
1149
1131
  if (config?.when && !config.when(ctx))
1150
1132
  return null;
1151
1133
  const input = ctx.value();
1152
- if (!input || input.length === 0)
1134
+ if (input === undefined || input === null || input === '')
1153
1135
  return null;
1154
1136
  const parsed = SystemUtils.parseDate(input);
1155
1137
  const invalid = { kind: 'notFuture', message: config?.message ?? ARS_VALIDATOR_MESSAGES['notFuture'] };
@@ -1539,5 +1521,5 @@ class SignalsUtils {
1539
1521
  * Generated bundle index. Do not edit.
1540
1522
  */
1541
1523
 
1542
- export { ARS_VALIDATOR_MESSAGES, EmailsValidatorDirective, EqualsValidatorDirective, FileSizeValidatorDirective, GuidValidatorDirective, MIN_VALID_YEAR, MaxTermsValidatorDirective, NotEmptyValidatorDirective, NotEqualValidatorDirective, NotFutureValidatorDirective, PasswordValidatorDirective, SignalsUtils, SqlDateValidatorDirective, TimeValidatorDirective, UrlValidatorDirective, ValidIfDirective, ValidatorDirective, date, dateRange, emails, equals, fileSize, guid, italianFiscalCode, italianVat, maxTerms, notEmpty, notEqual, notFuture, notPast, otp, password, sqlDate, time, url, validIf };
1524
+ export { ARS_VALIDATOR_MESSAGES, EmailsValidatorDirective, EqualsValidatorDirective, FileSizeValidatorDirective, GuidValidatorDirective, MIN_VALID_YEAR, MaxTermsValidatorDirective, NotEmptyValidatorDirective, NotEqualValidatorDirective, NotFutureValidatorDirective, PasswordValidatorDirective, SignalsUtils, SqlDateValidatorDirective, TimeValidatorDirective, UrlValidatorDirective, ValidIfDirective, ValidatorDirective, date, dateRange, emails, equals, fileSize, guid, italianFiscalCode, italianVat, maxTerms, notEmpty, notEqual, notFuture, notPast, otp, password, time, url, validIf };
1543
1525
  //# sourceMappingURL=arsedizioni-ars-utils-core.validators.mjs.map