@apia/validations 0.2.2 → 0.3.0

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/LICENSE.md CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) [year] [fullname]
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,28 +1,28 @@
1
- # Initiator
2
-
3
- Este package se creó con la única utilidad de copiarlo entero y pegarlo a la hora de crear un nuevo package.
4
-
5
- Este iniciador permite crear un paquete que compila typescript y puede ser importado desde otros packages.
6
-
7
- ## IMPORTANTE
8
-
9
- Los archivos **tsconfig.json** y **tsup.config.ts** no son archivos únicos sino symlinks a archivos de configuración comunes a todos los packages. En caso de que sea necesario modificar alguno de ellos **que en la gran mayoría de los casos no sería necesario**, es necesario eliminar el archivo a modificar y crear uno nuevo.
10
-
11
- ## Procedimiento
12
-
13
- - Copiar la carpeta initiator y pegarla con otro nombre dentro de packages.
14
- - Modificar el package.json:
15
- - Eliminar la línea ```private: true```.
16
- - Cambiar la ocurrencia `initiator` por el nombre del nuevo paquete.
17
- - Agregar los scripts convenientes: dev, build, etc.
18
- - Ejecutar el comando lerna bootstrap desde la carpeta raíz.
19
-
20
- Luego de ejecutar estos pasos, el package estaría listo para comenzar a usarse.
21
-
22
- Este package trae como dependencias por defecto theme-ui y react. Si se desea agregar más dependencias se debe ejecutar el comando ```lerna add --scope="@apia/packageName" dependencyName```. Ejemplo, si creamos un paquete con el nombre @apia/myPackage y queremos agregar lodash como dependencia, ejecutamos el comando ```lerna add --scope="@apia/myPackage" lodash```.
23
-
24
- **Importante 1**: Dado que estamos desarrollando packages, es importante determinar si las dependencias que vamos a agregar son de tipo dependency o de tipo peerDependency.
25
-
26
- **Importante 2**: lerna no permite instalar de a varias dependencias a la vez como lo hace npm, por lo tanto, si se desea agregar varias dependencias se debe ejecutar el comando anterior tantas veces como dependencias se quiera agregar.
27
-
1
+ # Initiator
2
+
3
+ Este package se creó con la única utilidad de copiarlo entero y pegarlo a la hora de crear un nuevo package.
4
+
5
+ Este iniciador permite crear un paquete que compila typescript y puede ser importado desde otros packages.
6
+
7
+ ## IMPORTANTE
8
+
9
+ Los archivos **tsconfig.json** y **tsup.config.ts** no son archivos únicos sino symlinks a archivos de configuración comunes a todos los packages. En caso de que sea necesario modificar alguno de ellos **que en la gran mayoría de los casos no sería necesario**, es necesario eliminar el archivo a modificar y crear uno nuevo.
10
+
11
+ ## Procedimiento
12
+
13
+ - Copiar la carpeta initiator y pegarla con otro nombre dentro de packages.
14
+ - Modificar el package.json:
15
+ - Eliminar la línea ```private: true```.
16
+ - Cambiar la ocurrencia `initiator` por el nombre del nuevo paquete.
17
+ - Agregar los scripts convenientes: dev, build, etc.
18
+ - Ejecutar el comando lerna bootstrap desde la carpeta raíz.
19
+
20
+ Luego de ejecutar estos pasos, el package estaría listo para comenzar a usarse.
21
+
22
+ Este package trae como dependencias por defecto theme-ui y react. Si se desea agregar más dependencias se debe ejecutar el comando ```lerna add --scope="@apia/packageName" dependencyName```. Ejemplo, si creamos un paquete con el nombre @apia/myPackage y queremos agregar lodash como dependencia, ejecutamos el comando ```lerna add --scope="@apia/myPackage" lodash```.
23
+
24
+ **Importante 1**: Dado que estamos desarrollando packages, es importante determinar si las dependencias que vamos a agregar son de tipo dependency o de tipo peerDependency.
25
+
26
+ **Importante 2**: lerna no permite instalar de a varias dependencias a la vez como lo hace npm, por lo tanto, si se desea agregar varias dependencias se debe ejecutar el comando anterior tantas veces como dependencias se quiera agregar.
27
+
28
28
  **Importante 3**: React y theme-ui vienen instalados como peerDependencies. En caso de no ser necesarios pueden ser removidos, pero en cualquier caso asegurarse de que estas dependencias no sean instaladas como dependencies puesto que esto causaría comportamientos indeseados en la aplicación.
package/cleanDist.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "cleanDist": 0.7200462826014478
3
+ }
package/dist/index.d.ts CHANGED
@@ -564,8 +564,9 @@ interface IUseFieldValue {
564
564
  }
565
565
  declare function useFieldValue<T = unknown>({ formName, name }: IUseFieldValue): T;
566
566
 
567
- declare function useValidationClass<T>({ customValidation, validationClass, validationFunction, validationRules, }: Pick<TDefaultFieldType<T>, 'validationClass' | 'validationFunction' | 'validationRules'> & {
567
+ declare function useValidationClass<T>({ customValidation, formName, name, validationClass, validationFunction, validationRules, }: Pick<TDefaultFieldType<T>, 'validationClass' | 'validationFunction' | 'validationRules' | 'name'> & {
568
568
  customValidation?: TValidationFunction<T>;
569
+ formName?: string;
569
570
  }): {
570
571
  actualValidationFunction: TValidationFunction<T>;
571
572
  actualValidationRules: {
package/dist/index.js CHANGED
@@ -866,18 +866,28 @@ var __spreadValues$a = (a, b) => {
866
866
  };
867
867
  function useValidationClass({
868
868
  customValidation,
869
+ formName,
870
+ name,
869
871
  validationClass,
870
872
  validationFunction,
871
873
  validationRules
872
874
  }) {
875
+ const { name: contextFormName } = React.useContext(FormContext);
873
876
  const classesValidationFunction = React.useMemo(
874
877
  () => validationClass !== void 0 ? classToValidationFunction(validationClass) : void 0,
875
878
  [validationClass]
876
879
  );
880
+ const initialValidationFunction = React.useMemo(
881
+ () => {
882
+ var _a;
883
+ return (_a = validationsStore.getFieldStore(formName != null ? formName : contextFormName, name)) == null ? void 0 : _a.validationFunction;
884
+ },
885
+ [contextFormName, formName, name]
886
+ );
877
887
  const actualValidationFunction = React.useCallback(
878
888
  (currentValue, parameterFormName) => {
879
- var _a;
880
- let result = (_a = validationFunction == null ? void 0 : validationFunction(currentValue, parameterFormName)) != null ? _a : true;
889
+ var _a, _b;
890
+ let result = (_b = (_a = initialValidationFunction == null ? void 0 : initialValidationFunction(currentValue, parameterFormName)) != null ? _a : validationFunction == null ? void 0 : validationFunction(currentValue, parameterFormName)) != null ? _b : true;
881
891
  if (typeof result === "string")
882
892
  return result;
883
893
  if (customValidation) {
@@ -889,7 +899,12 @@ function useValidationClass({
889
899
  return classesValidationFunction(currentValue, parameterFormName);
890
900
  return true;
891
901
  },
892
- [classesValidationFunction, customValidation, validationFunction]
902
+ [
903
+ classesValidationFunction,
904
+ customValidation,
905
+ initialValidationFunction,
906
+ validationFunction
907
+ ]
893
908
  );
894
909
  const actualValidationRules = React.useMemo(() => {
895
910
  return __spreadValues$a(__spreadValues$a({}, validationRules), validationClass !== void 0 ? classToValidate(validationClass) : {});
@@ -1150,6 +1165,8 @@ const Checkbox = React.forwardRef(
1150
1165
  ]);
1151
1166
  var _a2, _c;
1152
1167
  const { actualValidationFunction, actualValidationRules } = useValidationClass({
1168
+ formName,
1169
+ name,
1153
1170
  validationClass,
1154
1171
  validationFunction,
1155
1172
  validationRules
@@ -1274,6 +1291,8 @@ const DeletableInput = React.forwardRef(
1274
1291
  const { name: contextFormName } = React.useContext(FormContext);
1275
1292
  const formName = propsFormName != null ? propsFormName : contextFormName;
1276
1293
  const { actualValidationFunction, actualValidationRules } = useValidationClass({
1294
+ formName,
1295
+ name,
1277
1296
  validationClass,
1278
1297
  validationFunction,
1279
1298
  validationRules
@@ -1415,6 +1434,8 @@ const FileInput = React.memo(
1415
1434
  var _b2;
1416
1435
  const { name: formName } = useFormContext();
1417
1436
  const { actualValidationFunction, actualValidationRules } = useValidationClass({
1437
+ formName,
1438
+ name,
1418
1439
  customValidation(fileValue) {
1419
1440
  return fileValue !== null && fileValue !== void 0 ? true : lang("required");
1420
1441
  },
@@ -1546,6 +1567,8 @@ const Input = React.memo(
1546
1567
  const { name: contextFormName } = React.useContext(FormContext);
1547
1568
  const formName = propsFormName != null ? propsFormName : contextFormName;
1548
1569
  const { actualValidationFunction, actualValidationRules } = useValidationClass({
1570
+ formName,
1571
+ name,
1549
1572
  validationClass,
1550
1573
  validationFunction,
1551
1574
  validationRules
@@ -1691,6 +1714,8 @@ const NumberInputf = React.memo(
1691
1714
  const { name: contextFormName } = React.useContext(FormContext);
1692
1715
  const formName = propsFormName != null ? propsFormName : contextFormName;
1693
1716
  const { actualValidationFunction, actualValidationRules } = useValidationClass({
1717
+ formName,
1718
+ name,
1694
1719
  validationClass,
1695
1720
  validationFunction,
1696
1721
  validationRules
@@ -1832,6 +1857,8 @@ const Radio = React.forwardRef(
1832
1857
  "validationRules"
1833
1858
  ]);
1834
1859
  const { actualValidationFunction, actualValidationRules } = useValidationClass({
1860
+ formName,
1861
+ name,
1835
1862
  validationClass,
1836
1863
  validationFunction,
1837
1864
  validationRules
@@ -1954,6 +1981,8 @@ const Select = React.forwardRef(
1954
1981
  ]);
1955
1982
  var _a2, _b2, _d, _e;
1956
1983
  const { actualValidationFunction, actualValidationRules } = useValidationClass({
1984
+ formName,
1985
+ name,
1957
1986
  validationClass,
1958
1987
  validationFunction,
1959
1988
  validationRules
@@ -2071,6 +2100,8 @@ const Switchbox = React.forwardRef(
2071
2100
  ]);
2072
2101
  var _b2, _c;
2073
2102
  const { actualValidationFunction, actualValidationRules } = useValidationClass({
2103
+ formName,
2104
+ name,
2074
2105
  validationClass,
2075
2106
  validationFunction,
2076
2107
  validationRules
@@ -2181,6 +2212,8 @@ const Textarea = React.forwardRef(
2181
2212
  ]);
2182
2213
  var _b2, _c;
2183
2214
  const { actualValidationFunction, actualValidationRules } = useValidationClass({
2215
+ formName,
2216
+ name,
2184
2217
  validationClass,
2185
2218
  validationFunction,
2186
2219
  validationRules